From 58cf509495b292ed8c8966b9cab2c7afa7119560 Mon Sep 17 00:00:00 2001 From: Jakob Hasse Date: Wed, 4 Mar 2020 15:26:34 +0800 Subject: [PATCH 01/60] NVS: Changed all new to new (nothrow) --- components/nvs_flash/src/nvs_api.cpp | 13 +++++- components/nvs_flash/src/nvs_encr.cpp | 10 +++-- .../nvs_flash/src/nvs_item_hash_list.cpp | 15 ++++--- .../nvs_flash/src/nvs_item_hash_list.hpp | 8 ++-- components/nvs_flash/src/nvs_ops.cpp | 8 +++- components/nvs_flash/src/nvs_page.cpp | 29 +++++++++--- components/nvs_flash/src/nvs_pagemanager.cpp | 6 ++- components/nvs_flash/src/nvs_storage.cpp | 44 ++++++++++++++----- components/nvs_flash/src/nvs_storage.hpp | 2 +- 9 files changed, 101 insertions(+), 34 deletions(-) diff --git a/components/nvs_flash/src/nvs_api.cpp b/components/nvs_flash/src/nvs_api.cpp index e993c9637..f6cf33d5e 100644 --- a/components/nvs_flash/src/nvs_api.cpp +++ b/components/nvs_flash/src/nvs_api.cpp @@ -105,7 +105,10 @@ extern "C" esp_err_t nvs_flash_init_custom(const char *partName, uint32_t baseSe nvs::Storage* new_storage = NULL; nvs::Storage* storage = lookup_storage_from_name(partName); if (storage == NULL) { - new_storage = new nvs::Storage((const char *)partName); + new_storage = new (std::nothrow) nvs::Storage((const char *)partName); + + if (!new_storage) return ESP_ERR_NO_MEM; + storage = new_storage; } @@ -127,6 +130,9 @@ extern "C" esp_err_t nvs_flash_secure_init_custom(const char *partName, uint32_t if(cfg) { auto encrMgr = EncrMgr::getInstance(); + + if (!encrMgr) return ESP_ERR_NO_MEM; + auto err = encrMgr->setSecurityContext(baseSector, sectorCount, cfg); if(err != ESP_OK) { return err; @@ -282,7 +288,10 @@ extern "C" esp_err_t nvs_open_from_partition(const char *part_name, const char* return err; } - HandleEntry *handle_entry = new HandleEntry(open_mode==NVS_READONLY, nsIndex, sHandle); + HandleEntry *handle_entry = new (std::nothrow) HandleEntry(open_mode==NVS_READONLY, nsIndex, sHandle); + + if (!handle_entry) return ESP_ERR_NO_MEM; + s_nvs_handles.push_back(handle_entry); *out_handle = handle_entry->mHandle; diff --git a/components/nvs_flash/src/nvs_encr.cpp b/components/nvs_flash/src/nvs_encr.cpp index 6f0b46cf9..c33a59547 100644 --- a/components/nvs_flash/src/nvs_encr.cpp +++ b/components/nvs_flash/src/nvs_encr.cpp @@ -27,8 +27,10 @@ namespace nvs { if(!isActive) { - instance = new EncrMgr(); - isActive = true; + instance = new (std::nothrow) EncrMgr(); + if (instance) { + isActive = true; + } } return instance; } @@ -62,7 +64,9 @@ namespace nvs uint8_t* eky = reinterpret_cast(cfg); - auto ctxt = new XtsCtxt(); + auto ctxt = new (std::nothrow) XtsCtxt(); + + if (!ctxt) return ESP_ERR_NO_MEM; ctxt->baseSector = baseSector; ctxt->sectorCount = sectorCount; diff --git a/components/nvs_flash/src/nvs_item_hash_list.cpp b/components/nvs_flash/src/nvs_item_hash_list.cpp index a6cfdac1e..7e1c1241a 100644 --- a/components/nvs_flash/src/nvs_item_hash_list.cpp +++ b/components/nvs_flash/src/nvs_item_hash_list.cpp @@ -20,7 +20,7 @@ namespace nvs HashList::HashList() { } - + void HashList::clear() { for (auto it = mBlockList.begin(); it != mBlockList.end();) { @@ -30,7 +30,7 @@ void HashList::clear() delete static_cast(tmp); } } - + HashList::~HashList() { clear(); @@ -42,7 +42,7 @@ HashList::HashListBlock::HashListBlock() "cache block size calculation incorrect"); } -void HashList::insert(const Item& item, size_t index) +esp_err_t HashList::insert(const Item& item, size_t index) { const uint32_t hash_24 = item.calculateCrc32WithoutValue() & 0xffffff; // add entry to the end of last block if possible @@ -50,14 +50,19 @@ void HashList::insert(const Item& item, size_t index) auto& block = mBlockList.back(); if (block.mCount < HashListBlock::ENTRY_COUNT) { block.mNodes[block.mCount++] = HashListNode(hash_24, index); - return; + return ESP_OK; } } // if the above failed, create a new block and add entry to it - HashListBlock* newBlock = new HashListBlock; + HashListBlock* newBlock = new (std::nothrow) HashListBlock; + + if (!newBlock) return ESP_ERR_NO_MEM; + mBlockList.push_back(newBlock); newBlock->mNodes[0] = HashListNode(hash_24, index); newBlock->mCount++; + + return ESP_OK; } void HashList::erase(size_t index, bool itemShouldExist) diff --git a/components/nvs_flash/src/nvs_item_hash_list.hpp b/components/nvs_flash/src/nvs_item_hash_list.hpp index e759cd818..ca21c92c1 100644 --- a/components/nvs_flash/src/nvs_item_hash_list.hpp +++ b/components/nvs_flash/src/nvs_item_hash_list.hpp @@ -27,16 +27,16 @@ class HashList public: HashList(); ~HashList(); - - void insert(const Item& item, size_t index); + + esp_err_t insert(const Item& item, size_t index); void erase(const size_t index, bool itemShouldExist=true); size_t find(size_t start, const Item& item); void clear(); - + private: HashList(const HashList& other); const HashList& operator= (const HashList& rhs); - + protected: struct HashListNode { diff --git a/components/nvs_flash/src/nvs_ops.cpp b/components/nvs_flash/src/nvs_ops.cpp index 1ee32befc..4dfcc9c11 100644 --- a/components/nvs_flash/src/nvs_ops.cpp +++ b/components/nvs_flash/src/nvs_ops.cpp @@ -26,6 +26,9 @@ esp_err_t nvs_flash_write(size_t destAddr, const void *srcAddr, size_t size) { if(EncrMgr::isEncrActive()) { auto encrMgr = EncrMgr::getInstance(); + + if (!encrMgr) return ESP_ERR_NO_MEM; + auto xtsCtxt = encrMgr->findXtsCtxtFromAddr(destAddr); if(xtsCtxt) { @@ -44,7 +47,7 @@ esp_err_t nvs_flash_write(size_t destAddr, const void *srcAddr, size_t size) { } esp_err_t nvs_flash_read(size_t srcAddr, void *destAddr, size_t size) { - + auto err = spi_flash_read(srcAddr, destAddr, size); if(err != ESP_OK) { @@ -53,6 +56,9 @@ esp_err_t nvs_flash_read(size_t srcAddr, void *destAddr, size_t size) { if(EncrMgr::isEncrActive()) { auto encrMgr = EncrMgr::getInstance(); + + if (!encrMgr) return ESP_ERR_NO_MEM; + auto xtsCtxt = encrMgr->findXtsCtxtFromAddr(srcAddr); if(xtsCtxt) { return encrMgr->decryptNvsData(static_cast(destAddr), diff --git a/components/nvs_flash/src/nvs_page.cpp b/components/nvs_flash/src/nvs_page.cpp index e0bda34c5..821668c18 100644 --- a/components/nvs_flash/src/nvs_page.cpp +++ b/components/nvs_flash/src/nvs_page.cpp @@ -49,7 +49,10 @@ esp_err_t Page::load(uint32_t sectorNumber) // check if the whole page is really empty // reading the whole page takes ~40 times less than erasing it const int BLOCK_SIZE = 128; - uint32_t* block = new uint32_t[BLOCK_SIZE]; + uint32_t* block = new (std::nothrow) uint32_t[BLOCK_SIZE]; + + if (!block) return ESP_ERR_NO_MEM; + for (uint32_t i = 0; i < SPI_FLASH_SEC_SIZE; i += 4 * BLOCK_SIZE) { rc = spi_flash_read(mBaseAddress + i, block, 4 * BLOCK_SIZE); if (rc != ESP_OK) { @@ -215,7 +218,11 @@ esp_err_t Page::writeItem(uint8_t nsIndex, ItemType datatype, const char* key, c // write first item size_t span = (totalSize + ENTRY_SIZE - 1) / ENTRY_SIZE; item = Item(nsIndex, datatype, span, key, chunkIdx); - mHashList.insert(item, mNextFreeEntry); + err = mHashList.insert(item, mNextFreeEntry); + + if (err != ESP_OK) { + return err; + } if (!isVariableLengthType(datatype)) { memcpy(item.data, data, dataSize); @@ -426,7 +433,11 @@ esp_err_t Page::copyItems(Page& other) return err; } - other.mHashList.insert(entry, other.mNextFreeEntry); + err = other.mHashList.insert(entry, other.mNextFreeEntry); + if (err != ESP_OK) { + return err; + } + err = other.writeEntry(entry); if (err != ESP_OK) { return err; @@ -549,7 +560,11 @@ esp_err_t Page::mLoadEntryTable() continue; } - mHashList.insert(item, i); + err = mHashList.insert(item, i); + if (err != ESP_OK) { + mState = PageState::INVALID; + return err; + } // search for potential duplicate item size_t duplicateIndex = mHashList.find(0, item); @@ -619,7 +634,11 @@ esp_err_t Page::mLoadEntryTable() assert(item.span > 0); - mHashList.insert(item, i); + err = mHashList.insert(item, i); + if (err != ESP_OK) { + mState = PageState::INVALID; + return err; + } size_t span = item.span; diff --git a/components/nvs_flash/src/nvs_pagemanager.cpp b/components/nvs_flash/src/nvs_pagemanager.cpp index 58d9e47f4..f33a24e97 100644 --- a/components/nvs_flash/src/nvs_pagemanager.cpp +++ b/components/nvs_flash/src/nvs_pagemanager.cpp @@ -21,7 +21,9 @@ esp_err_t PageManager::load(uint32_t baseSector, uint32_t sectorCount) mPageCount = sectorCount; mPageList.clear(); mFreePageList.clear(); - mPages.reset(new Page[sectorCount]); + mPages.reset(new (std::nothrow) Page[sectorCount]); + + if (!mPages) return ESP_ERR_NO_MEM; for (uint32_t i = 0; i < sectorCount; ++i) { auto err = mPages[i].load(baseSector + i); @@ -85,7 +87,7 @@ esp_err_t PageManager::load(uint32_t baseSector, uint32_t sectorCount) break; } } - } + } } // check if power went out while page was being freed diff --git a/components/nvs_flash/src/nvs_storage.cpp b/components/nvs_flash/src/nvs_storage.cpp index be92da072..7eae18feb 100644 --- a/components/nvs_flash/src/nvs_storage.cpp +++ b/components/nvs_flash/src/nvs_storage.cpp @@ -31,7 +31,7 @@ void Storage::clearNamespaces() mNamespaces.clearAndFreeNodes(); } -void Storage::populateBlobIndices(TBlobIndexList& blobIdxList) +esp_err_t Storage::populateBlobIndices(TBlobIndexList& blobIdxList) { for (auto it = mPageManager.begin(); it != mPageManager.end(); ++it) { Page& p = *it; @@ -43,7 +43,9 @@ void Storage::populateBlobIndices(TBlobIndexList& blobIdxList) * duplicate index at this point */ while (p.findItem(Page::NS_ANY, ItemType::BLOB_IDX, nullptr, itemIndex, item) == ESP_OK) { - BlobIndexNode* entry = new BlobIndexNode; + BlobIndexNode* entry = new (std::nothrow) BlobIndexNode; + + if (!entry) return ESP_ERR_NO_MEM; item.getKey(entry->key, sizeof(entry->key) - 1); entry->nsIndex = item.nsIndex; @@ -54,6 +56,8 @@ void Storage::populateBlobIndices(TBlobIndexList& blobIdxList) itemIndex += item.span; } } + + return ESP_OK; } void Storage::eraseOrphanDataBlobs(TBlobIndexList& blobIdxList) @@ -100,7 +104,13 @@ esp_err_t Storage::init(uint32_t baseSector, uint32_t sectorCount) size_t itemIndex = 0; Item item; while (p.findItem(Page::NS_INDEX, ItemType::U8, nullptr, itemIndex, item) == ESP_OK) { - NamespaceEntry* entry = new NamespaceEntry; + NamespaceEntry* entry = new (std::nothrow) NamespaceEntry; + + if (!entry) { + mState = StorageState::INVALID; + return ESP_ERR_NO_MEM; + } + item.getKey(entry->mName, sizeof(entry->mName) - 1); item.getValue(entry->mIndex); mNamespaces.push_back(entry); @@ -114,7 +124,11 @@ esp_err_t Storage::init(uint32_t baseSector, uint32_t sectorCount) // Populate list of multi-page index entries. TBlobIndexList blobIdxList; - populateBlobIndices(blobIdxList); + err = populateBlobIndices(blobIdxList); + if (err != ESP_OK) { + mState = StorageState::INVALID; + return ESP_ERR_NO_MEM; + } // Remove the entries for which there is no parent multi-page index. eraseOrphanDataBlobs(blobIdxList); @@ -182,7 +196,7 @@ esp_err_t Storage::writeMultiPageBlob(uint8_t nsIndex, const char* key, const vo return err; } else if(getCurrentPage().getVarDataTailroom() == tailroom) { /* We got the same page or we are not improving.*/ - return ESP_ERR_NVS_NOT_ENOUGH_SPACE; + return ESP_ERR_NVS_NOT_ENOUGH_SPACE; } else { continue; } @@ -203,7 +217,11 @@ esp_err_t Storage::writeMultiPageBlob(uint8_t nsIndex, const char* key, const vo if (err != ESP_OK) { break; } else { - UsedPageNode* node = new UsedPageNode(); + UsedPageNode* node = new (std::nothrow) UsedPageNode(); + if (!node) { + err = ESP_ERR_NO_MEM; + break; + } node->mPage = &page; usedPages.push_back(node); if (remainingSize || (tailroom - chunkSize) < Page::ENTRY_SIZE) { @@ -301,9 +319,9 @@ esp_err_t Storage::writeItem(uint8_t nsIndex, ItemType datatype, const char* key if (err != ESP_OK) { return err; } - + findPage = nullptr; - } else { + } else { /* Support for earlier versions where BLOBS were stored without index */ err = findItem(nsIndex, datatype, key, findPage, item); if (err != ESP_OK && err != ESP_ERR_NVS_NOT_FOUND) { @@ -381,6 +399,11 @@ esp_err_t Storage::createOrOpenNamespace(const char* nsName, bool canCreate, uin return ESP_ERR_NVS_NOT_ENOUGH_SPACE; } + NamespaceEntry* entry = new (std::nothrow) NamespaceEntry; + if (!entry) { + return ESP_ERR_NO_MEM; + } + auto err = writeItem(Page::NS_INDEX, ItemType::U8, nsName, &ns, sizeof(ns)); if (err != ESP_OK) { return err; @@ -388,7 +411,6 @@ esp_err_t Storage::createOrOpenNamespace(const char* nsName, bool canCreate, uin mNamespaceUsage.set(ns, true); nsIndex = ns; - NamespaceEntry* entry = new NamespaceEntry; entry->mIndex = ns; strncpy(entry->mName, nsName, sizeof(entry->mName) - 1); entry->mName[sizeof(entry->mName) - 1] = 0; @@ -456,14 +478,14 @@ esp_err_t Storage::readItem(uint8_t nsIndex, ItemType datatype, const char* key, if (err != ESP_ERR_NVS_NOT_FOUND) { return err; } // else check if the blob is stored with earlier version format without index - } + } auto err = findItem(nsIndex, datatype, key, findPage, item); if (err != ESP_OK) { return err; } return findPage->readItem(nsIndex, datatype, key, data, dataSize); - + } esp_err_t Storage::eraseMultiPageBlob(uint8_t nsIndex, const char* key, VerOffset chunkStart) diff --git a/components/nvs_flash/src/nvs_storage.hpp b/components/nvs_flash/src/nvs_storage.hpp index 3a79e705c..add5cca7c 100644 --- a/components/nvs_flash/src/nvs_storage.hpp +++ b/components/nvs_flash/src/nvs_storage.hpp @@ -128,7 +128,7 @@ protected: void clearNamespaces(); - void populateBlobIndices(TBlobIndexList&); + esp_err_t populateBlobIndices(TBlobIndexList&); void eraseOrphanDataBlobs(TBlobIndexList&); From 6ac7ceef9e56f454ee2fc67cd39776bb6c3089e0 Mon Sep 17 00:00:00 2001 From: liminyang Date: Wed, 17 Jun 2020 11:58:41 +0800 Subject: [PATCH 02/60] docs:perfect 128-bit UUID description The previous description is not easy for the reader to understand, some changees have been made to perfect it. Closes https://github.com/espressif/esp-idf/issues/5057 --- .../Gatt_Client_Example_Walkthrough.md | 723 ++++++++++++++++++ 1 file changed, 723 insertions(+) create mode 100644 examples/bluetooth/bluedroid/ble/gatt_client/tutorial/Gatt_Client_Example_Walkthrough.md diff --git a/examples/bluetooth/bluedroid/ble/gatt_client/tutorial/Gatt_Client_Example_Walkthrough.md b/examples/bluetooth/bluedroid/ble/gatt_client/tutorial/Gatt_Client_Example_Walkthrough.md new file mode 100644 index 000000000..26a639b8a --- /dev/null +++ b/examples/bluetooth/bluedroid/ble/gatt_client/tutorial/Gatt_Client_Example_Walkthrough.md @@ -0,0 +1,723 @@ +# Gatt Client Example Walkthrough + +## Introduction + +In this tutorial, the GATT client example code for the ESP32 is reviewed. The code implements a Bluetooth Low Energy (BLE) Generic Attribute (GATT) client, which scans for nearby peripheral servers and connects to a predefined service. The client then searches for available characteristics and subscribes to a known characteristic in order to receive notifications or indications. The example can register an Application Profile and initializes a sequence of events, which can be used to configure Generic Access Profile (GAP) parameters and to handle events such as scanning, connecting to peripherals and reading and writing characteristics. + +# Includes + +This example is located in the examples folder of the ESP-IDF under the [bluetooth/bluedroid/ble/gatt_client/main](../main). The [gattc_demo.c](../main/gattc_demo.c) file located in the main folder contains all the functionality that we are going to review. The header files contained in [gattc_demo.c](../main/gattc_demo.c) are: + +```c +#include +#include +#include +#include +#include "nvs.h" +#include "nvs_flash.h" +#include "controller.h" + +#include "bt.h" +#include "esp_gap_ble_api.h" +#include "esp_gattc_api.h" +#include "esp_gatt_defs.h" +#include "esp_bt_main.h" +#include "esp_gatt_common_api.h" +``` + +These `includes` are required for the FreeRTOS and underlaying system components to run, including the logging functionality and a library to store data in non-volatile flash memory. We are interested in `“bt.h”`, `“esp_bt_main.h”`, `"esp_gap_ble_api.h"` and `“esp_gattc_api.h”`, which expose the BLE APIs required to implement this example. + +* `bt.h`: configures the BT controller and VHCI from the host side. +* `esp_bt_main.h`: initializes and enables the Bluedroid stack. +* `esp_gap_ble_api.h`: implements the GAP configuration, such as advertising and connection parameters. +* `esp_gattc_api.h`: implements the GATT Client configuration, such as connecting to peripherals and searching for services. + +## Main Entry Point + +The program’s entry point is the app_main() function: + +```c +void app_main() +{ + // Initialize NVS. + esp_err_t ret = nvs_flash_init(); + if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { + ESP_ERROR_CHECK(nvs_flash_erase()); + ret = nvs_flash_init(); + } + ESP_ERROR_CHECK( ret ); + + esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); + ret = esp_bt_controller_init(&bt_cfg); + if (ret) { + ESP_LOGE(GATTC_TAG, "%s initialize controller failed, error code = %x\n", __func__, ret); + return; + } + + ret = esp_bt_controller_enable(ESP_BT_MODE_BLE); + if (ret) { + ESP_LOGE(GATTC_TAG, "%s enable controller failed, error code = %x\n", __func__, ret); + return; + } + + ret = esp_bluedroid_init(); + if (ret) { + ESP_LOGE(GATTC_TAG, "%s init bluetooth failed, error code = %x\n", __func__, ret); + return; + } + + ret = esp_bluedroid_enable(); + if (ret) { + ESP_LOGE(GATTC_TAG, "%s enable bluetooth failed, error code = %x\n", __func__, ret); + return; + } + + //register the callback function to the gap module + ret = esp_ble_gap_register_callback(esp_gap_cb); + if (ret){ + ESP_LOGE(GATTC_TAG, "%s gap register failed, error code = %x\n", __func__, ret); + return; + } + + //register the callback function to the gattc module + ret = esp_ble_gattc_register_callback(esp_gattc_cb); + if(ret){ + ESP_LOGE(GATTC_TAG, "%s gattc register failed, error code = %x\n", __func__, ret); + return; + } + + ret = esp_ble_gattc_app_register(PROFILE_A_APP_ID); + if (ret){ + ESP_LOGE(GATTC_TAG, "%s gattc app register failed, error code = %x\n", __func__, ret); + } + + esp_err_t local_mtu_ret = esp_ble_gatt_set_local_mtu(500); + if (local_mtu_ret){ + ESP_LOGE(GATTC_TAG, "set local MTU failed, error code = %x", local_mtu_ret); + } + +} +``` + +The main function starts by initializing the non-volatile storage library. This library allows to save key-value pairs in flash memory and is used by some components such as the Wi-Fi library to save the SSID and password: + +```c +esp_err_t ret = nvs_flash_init(); +if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { + ESP_ERROR_CHECK(nvs_flash_erase()); + ret = nvs_flash_init(); +} +ESP_ERROR_CHECK( ret ); +``` + +## BT Controller and Stack Initialization + +The main function also initializes the BT controller by first creating a BT controller configuration structure named `esp_bt_controller_config_t` with default settings generated by the `BT_CONTROLLER_INIT_CONFIG_DEFAULT()` macro. The BT controller implements the Host Controller Interface (HCI) on the controller side, the Link Layer (LL) and the Physical Layer (PHY). The BT Controller is invisible to the user applications and deals with the lower layers of the BLE stack. The controller configuration includes setting the BT controller stack size, priority and HCI baud rate. With the settings created, the BT controller is initialized and enabled with the `esp_bt_controller_init()` function: + +```c +esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT(); +ret = esp_bt_controller_init(&bt_cfg); +``` + +Next, the controller is enabled in BLE Mode. + +```c +ret = esp_bt_controller_enable(ESP_BT_MODE_BLE); +``` +>The controller should be enabled in `ESP_BT_MODE_BTDM`, if you want to use the dual mode (BLE + BT). + +There are four Bluetooth modes supported: + +1. `ESP_BT_MODE_IDLE`: Bluetooth not running +2. `ESP_BT_MODE_BLE`: BLE mode +3. `ESP_BT_MODE_CLASSIC_BT`: BT Classic mode +4. `ESP_BT_MODE_BTDM`: Dual mode (BLE + BT Classic) + +After the initialization of the BT controller, the Bluedroid stack, which includes the common definitions and APIs for both BT Classic and BLE, is initialized and enabled by using: + +```c +ret = esp_bluedroid_init(); +ret = esp_bluedroid_enable(); +``` +The main function ends by registering the GAP and GATT event handlers, as well as the Application Profile and set the maximum supported MTU size. + +```c + //register the callback function to the gap module + ret = esp_ble_gap_register_callback(esp_gap_cb); + + //register the callback function to the gattc module + ret = esp_ble_gattc_register_callback(esp_gattc_cb); + + ret = esp_ble_gattc_app_register(PROFILE_A_APP_ID); + + esp_err_t local_mtu_ret = esp_ble_gatt_set_local_mtu(500); + if (local_mtu_ret){ + ESP_LOGE(GATTC_TAG, "set local MTU failed, error code = %x", local_mtu_ret); + } +``` + +The GAP and GATT event handlers are the functions used to catch the events generated by the BLE stack and execute functions to configure parameters of the application. Moreover, the event handlers are also used to handle read and write events coming from the central. The GAP event handler takes care of scanning and connecting to servers and the GATT handler manages events that happen after the client has connected to a server, such as searching for services and writing and reading data. The GAP and GATT event handlers are registered by using: + +```c +esp_ble_gap_register_callback(); +esp_ble_gattc_register_callback(); +``` +The functions `esp_gap_cb()` and `esp_gattc_cb()` handle all the events generated by the BLE stack. + +## Application Profiles + +The Application Profiles are a way to group functionalities that are designed for one or more server applications. For example, you can have an Application Profile connected to the Heart Rate Sensors, and another one connected to the Temperature Sensors. Each Application Profile creates a GATT interface to connect to other devices. The Application Profiles in the code are instances of the `gattc_profile_inst` structure, which is defined as: + +```c +struct gattc_profile_inst { + esp_gattc_cb_t gattc_cb; + uint16_t gattc_if; + uint16_t app_id; + uint16_t conn_id; + uint16_t service_start_handle; + uint16_t service_end_handle; + uint16_t char_handle; + esp_bd_addr_t remote_bda; +}; +``` + +The Application Profile structure contains: + +* `gattc_cb`: GATT client callback function +* `gattc_if`: GATT client interface number for this profile +* `app_id`: Application Profile ID number +* `conn_id`: Connection ID +* `service_start_handle`: Service start handle +* `service_end_handle`: Service end handle +* `char_handle`: Char handle +* `remote_bda`: Remote device address connected to this client. + +In this example there is one Application Profile and its ID is defined as: + +```c +#define PROFILE_NUM 1 +#define PROFILE_A_APP_ID 0 +``` +The Application Profile are stored in the `gl_profile_tab` array, which is initialized as: + +```c +/* One gatt-based profile one app_id and one gattc_if, this array will store the gattc_if returned by ESP_GATTS_REG_EVT */ +static struct gattc_profile_inst gl_profile_tab[PROFILE_NUM] = { + [PROFILE_A_APP_ID] = {.gattc_cb = gattc_profile_event_handler, + .gattc_if = ESP_GATT_IF_NONE, /* Not get the gatt_if, so initial is ESP_GATT_IF_NONE */ + }, +}; +``` + +The initialization of the Application Profile table array includes defining the callback functions for each Profile. These are `gattc_profile_a_event_handler()` and `gattc_profile_a_event_handler()` respectively. In addition, the GATT interface is initialized to the default value of `ESP_GATT_IF_NONE`. Later on, when the Application Profile is registered, the BLE stack returns a GATT interface instance to use with that Application Profile. + +The profile registration triggers an `ESP_GATTC_REG_EVT` event, which is handled by the `esp_gattc_cb()` event handler. The handler takes the GATT interface returned by the event and stores it in the profile table: + +```c +static void esp_gattc_cb(esp_gattc_cb_event_t event, esp_gatt_if_t gattc_if, esp_ble_gattc_cb_param_t *param) +{ + ESP_LOGI(GATTC_TAG, "EVT %d, gattc if %d", event, gattc_if); + + /* If event is register event, store the gattc_if for each profile */ + if (event == ESP_GATTC_REG_EVT) { + if (param->reg.status == ESP_GATT_OK) { + gl_profile_tab[param->reg.app_id].gattc_if = gattc_if; + } else { + ESP_LOGI(GATTC_TAG, "reg app failed, app_id %04x, status %d", + param->reg.app_id, + param->reg.status); + return; + } + } +… +``` + +Finally, the callback function invokes the corresponding event handler for each profile in the `gl_profile_tab` table. + +```c +… +/* If the gattc_if equal to profile A, call profile A cb handler, + * so here call each profile's callback */ + do { + int idx; + for (idx = 0; idx < PROFILE_NUM; idx++) { + if (gattc_if == ESP_GATT_IF_NONE || /* ESP_GATT_IF_NONE, not specify a certain gatt_if, need to call every profile cb function */ + gattc_if == gl_profile_tab[idx].gattc_if) { + if (gl_profile_tab[idx].gattc_cb) { + gl_profile_tab[idx].gattc_cb(event, gattc_if, param); + } + } + } + } while (0); +} +``` +## Setting Scan Parameters + +The GATT client normally scans for nearby servers and tries connect to them, if interested. However, in order to perform the scanning, first the configuration parameters need to be set. This is done after the registration of the Application Profiles, because the registration, once completed, triggers an `ESP_GATTC_REG_EVT` event. The first time this event is triggered, the GATT event handler captures it and assigns a GATT interface to Profile A, then the event is forwarded to the GATT event handler of Profile A. One in this event handler, the event is used to call the `esp_ble_gap_set_scan_params()` function, which takes a `ble_scan_params` structure instance as parameter. This structure is defined as: + +```c +/// Ble scan parameters +typedef struct { + esp_ble_scan_type_t scan_type; /*!< Scan type */ + esp_ble_addr_type_t own_addr_type; /*!< Owner address type */ + esp_ble_scan_filter_t scan_filter_policy; /*!< Scan filter policy */ + uint16_t scan_interval; /*!< Scan interval. This is defined as the time interval from when the Controller started its last LE scan until it begins the subsequent LE scan.*/ + //Range: 0x0004 to 0x4000 + //Default: 0x0010 (10 ms) + //Time = N * 0.625 msec + //Time Range: 2.5 msec to 10.24 seconds + uint16_t scan_window; /*!< Scan window. The duration of the LE scan. LE_Scan_Window shall be less than or equal to LE_Scan_Interval*/ + //Range: 0x0004 to 0x4000 //Default: 0x0010 (10 ms) + //Time = N * 0.625 msec + //Time Range: 2.5 msec to 10240 msec +} esp_ble_scan_params_t; +``` +An it is initialized as: + +```c +static esp_ble_scan_params_t ble_scan_params = { + .scan_type = BLE_SCAN_TYPE_ACTIVE, + .own_addr_type = BLE_ADDR_TYPE_PUBLIC, + .scan_filter_policy = BLE_SCAN_FILTER_ALLOW_ALL, + .scan_interval = 0x50, + .scan_window = 0x30 +}; +``` + +The BLE scan parameters are configured so that the type of scanning is active (includes reading the scanning response), it is of public type, allows any advertising device to be read and has a scanning interval of 100 ms (1.25 ms * 0x50) and a scanning window of 60 ms (1.25 ms * 0x30). + +The scan values are set using the `esp_ble_gap_set_scan_params()` function: + +```c +case ESP_GATTC_REG_EVT: + ESP_LOGI(GATTC_TAG, "REG_EVT"); + esp_err_t scan_ret = esp_ble_gap_set_scan_params(&ble_scan_params); + if (scan_ret){ + ESP_LOGE(GATTC_TAG, "set scan params error, error code = %x", scan_ret); + } + break; +``` + +## Start Scanning + +Once the scanning parameters are set, an `ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT` event is triggered, which is handled by the GAP event handler `esp_gap_cb()`. This event is used to start the scanning of nearby GATT servers: + +```c + case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: { + //the unit of the duration is second + uint32_t duration = 30; + esp_ble_gap_start_scanning(duration); + break; + } +``` + +The scanning is started using the `esp_ble_gap_start_scanning()` function which takes a parameter representing the duration of the continuous scanning (in seconds). Once the scanning period is ended, an `ESP_GAP_SEARCH_INQ_CMPL_EVT` event is triggered. + +## Getting Scan Results + +The results of the scanning are displayed as soon as they arrive with the `ESP_GAP_BLE_SCAN_RESULT_EVT` event, which includes the following parameters: + +```c + /** + * @brief ESP_GAP_BLE_SCAN_RESULT_EVT + */ + struct ble_scan_result_evt_param { + esp_gap_search_evt_t search_evt; /*!< Search event type */ + esp_bd_addr_t bda; /*!< Bluetooth device address which has been searched */ + esp_bt_dev_type_t dev_type; /*!< Device type */ + esp_ble_addr_type_t ble_addr_type; /*!< Ble device address type */ + esp_ble_evt_type_t ble_evt_type; /*!< Ble scan result event type */ + int rssi; /*!< Searched device's RSSI */ + uint8_t ble_adv[ESP_BLE_ADV_DATA_LEN_MAX + ESP_BLE_SCAN_RSP_DATA_LEN_MAX]; /*!< Received EIR */ + int flag; /*!< Advertising data flag bit */ + int num_resps; /*!< Scan result number */ + uint8_t adv_data_len; /*!< Adv data length */ + uint8_t scan_rsp_len; /*!< Scan response length */ + } scan_rst; /*!< Event parameter of ESP_GAP_BLE_SCAN_RESULT_EVT */ +``` + +This event also includes a list of sub events as shown below: + +```c +/// Sub Event of ESP_GAP_BLE_SCAN_RESULT_EVT +typedef enum { + ESP_GAP_SEARCH_INQ_RES_EVT = 0, /*!< Inquiry result for a peer device. */ + ESP_GAP_SEARCH_INQ_CMPL_EVT = 1, /*!< Inquiry complete. */ + ESP_GAP_SEARCH_DISC_RES_EVT = 2, /*!< Discovery result for a peer device. */ + ESP_GAP_SEARCH_DISC_BLE_RES_EVT = 3, /*!< Discovery result for BLE GATT based service on a peer device. */ + ESP_GAP_SEARCH_DISC_CMPL_EVT = 4, /*!< Discovery complete. */ + ESP_GAP_SEARCH_DI_DISC_CMPL_EVT = 5, /*!< Discovery complete. */ + ESP_GAP_SEARCH_SEARCH_CANCEL_CMPL_EVT = 6, /*!< Search cancelled */ +} esp_gap_search_evt_t; +``` +We are interested in the `ESP_GAP_SEARCH_INQ_RES_EVT` event, which is called every time a new device is found. We are also interested in the `ESP_GAP_SEARCH_INQ_CMPL_EVT`, which is triggered when the duration of the scanning is completed and can be used to restart the scanning procedure: + +```c + case ESP_GAP_BLE_SCAN_RESULT_EVT: { + esp_ble_gap_cb_param_t *scan_result = (esp_ble_gap_cb_param_t *)param; + switch (scan_result->scan_rst.search_evt) { + case ESP_GAP_SEARCH_INQ_RES_EVT: + esp_log_buffer_hex(GATTC_TAG, scan_result->scan_rst.bda, 6); + ESP_LOGI(GATTC_TAG, "searched Adv Data Len %d, Scan Response Len %d", scan_result->scan_rst.adv_data_len, scan_result->scan_rst.scan_rsp_len); + adv_name = esp_ble_resolve_adv_data(scan_result->scan_rst.ble_adv, ESP_BLE_AD_TYPE_NAME_CMPL, &adv_name_len); + ESP_LOGI(GATTC_TAG, "searched Device Name Len %d", adv_name_len); + esp_log_buffer_char(GATTC_TAG, adv_name, adv_name_len); + ESP_LOGI(GATTC_TAG, "\n"); + if (adv_name != NULL) { + if (strlen(remote_device_name) == adv_name_len && strncmp((char *)adv_name, remote_device_name, adv_name_len) == 0) { + ESP_LOGI(GATTC_TAG, "searched device %s\n", remote_device_name); + if (connect == false) { + connect = true; + ESP_LOGI(GATTC_TAG, "connect to the remote device."); + esp_ble_gap_stop_scanning(); + esp_ble_gattc_open(gl_profile_tab[PROFILE_A_APP_ID].gattc_if, scan_result->scan_rst.bda, scan_result->scan_rst.ble_addr_type, true); + } + } + } + break; +``` + +First the device name is resolved and compared to the one defined in `remote_device_name`. If it equals to the device name of the GATT Server we are interested in, then the scanning is stopped. + + +## Connecting to A GATT Server + +Every time we receive a result from the `ESP_GAP_SEARCH_INQ_RES_EVT` event, the code first prints the address of the remote device: + +```c +case ESP_GAP_SEARCH_INQ_RES_EVT: + esp_log_buffer_hex(GATTC_TAG, scan_result->scan_rst.bda, 6); +``` + +The client then prints the advertised data length and the scan response length: + +```c +ESP_LOGI(GATTC_TAG, "searched Adv Data Len %d, Scan Response Len %d", scan_result->scan_rst.adv_data_len, scan_result->scan_rst.scan_rsp_len); +``` + +In order to get the device name, we use the `esp_ble_resolve_adv_data()` function, which takes the advertised data stored in `scan_result->scan_rst.ble_adv`, the type of advertising data and the length, in order to extract the value from the advertising packet frame. Then the device name is printed. + +```c +adv_name = esp_ble_resolve_adv_data(scan_result->scan_rst.ble_adv, ESP_BLE_AD_TYPE_NAME_CMPL, &adv_name_len); +ESP_LOGI(GATTC_TAG, "searched Device Name Len %d", adv_name_len); +esp_log_buffer_char(GATTC_TAG, adv_name, adv_name_len); +``` + +Finally if the remote device name is the same as we have defined above, the local device stops scanning and tries to open a connection to the remote device using the `esp_ble_gattc_open()` function. This function takes as parameters the Application Profile GATT interface, the remote server address and a boolean value. The boolean value is used to indicate if the connection is done directly or if it’s done in the background (auto-connection), at the moment this boolean value must be set to true in order to establish the connection. Notice that the client opens a virtual connection to the server. The virtual connection returns a connection ID. The virtual connection is the connection between the Application Profile and the remote server. Since many Application Profiles can run on one ESP32, there could be many virtual connection opened to the same remote server. There is also the physical connection which is the actual BLE link between the client and the server. Therefore, if the physical connection is disconnected with the `esp_ble_gap_disconnect()` function, all other virtual connections are closed as well. In this example, each Application Profile creates a virtual connection to the same server with the `esp_ble_gattc_open()` function, so when the close function is called, only that connection from the Application Profile is closed, while if the gap disconnect function is called, both connections will be closed. In addition, connect events are propagated to all profiles because it relates to the physical connection, while open events are propagated only to the profile that creates the virtual connection. + +## Configuring the MTU Size + +ATT_MTU is defined as the maximum size of any packet sent between a client and a server. When the client connects to the server, it informs the server which MTU size to use by exchanging MTU Request and Response protocol data units (PDUs). This is done after the opening of a connection. After opening the connection, an `ESP_GATTC_CONNECT_EVT` event is triggered: + +```c + case ESP_GATTC_CONNECT_EVT: + //p_data->connect.status always be ESP_GATT_OK + ESP_LOGI(GATTC_TAG, "ESP_GATTC_CONNECT_EVT conn_id %d, if %d, status %d", conn_id, gattc_if, p_data->connect.status); + conn_id = p_data->connect.conn_id; + gl_profile_tab[PROFILE_A_APP_ID].conn_id = p_data->connect.conn_id; + memcpy(gl_profile_tab[PROFILE_A_APP_ID].remote_bda, p_data->connect.remote_bda, sizeof(esp_bd_addr_t)); + ESP_LOGI(GATTC_TAG, "REMOTE BDA:"); + esp_log_buffer_hex(GATTC_TAG, gl_profile_tab[PROFILE_A_APP_ID].remote_bda, sizeof(esp_bd_addr_t)); + esp_err_t mtu_ret = esp_ble_gattc_send_mtu_req (gattc_if, conn_id); + if (mtu_ret){ + ESP_LOGE(GATTC_TAG, "config MTU error, error code = %x", mtu_ret); + } + break; +``` + +The connection ID and the address of the remote device (server) are stored in the Application Profile table and printed to the console: + +```c +conn_id = p_data->connect.conn_id; +gl_profile_tab[PROFILE_A_APP_ID].conn_id = p_data->connect.conn_id; +memcpy(gl_profile_tab[PROFILE_A_APP_ID].remote_bda, p_data->connect.remote_bda, + sizeof(esp_bd_addr_t)); +ESP_LOGI(GATTC_TAG, "REMOTE BDA:"); +esp_log_buffer_hex(GATTC_TAG, gl_profile_tab[PROFILE_A_APP_ID].remote_bda, + sizeof(esp_bd_addr_t)); +``` + +The typical MTU size for a Bluetooth 4.0 connection is 23 bytes. A client can change the size of MUT, using `esp_ble_gattc_send_mtu_req()` function, which takes the GATT interface and the connection ID. The size of the requested MTU is defined by `esp_ble_gatt_set_local_mtu()`. The server can then accept or reject the request. The ESP32 supports a MTU size of up to 517 bytes, which is defined by the `ESP_GATT_MAX_MTU_SIZE` in `esp_gattc_api.h`. In this example, the MTU size is set to 500 bytes. In case the configuration fails, the returned error is printed: + +```c +esp_err_t mtu_ret = esp_ble_gattc_send_mtu_req (gattc_if, conn_id); +if (mtu_ret){ + ESP_LOGE(GATTC_TAG, "config MTU error, error code = %x", mtu_ret); +} +break; +``` + +The connection opening also triggers an `ESP_GATTC_OPEN_EVT`, which is used to check that the opening of the connection was done successfully, otherwise print an error and exit. + +```c +case ESP_GATTC_OPEN_EVT: + if (param->open.status != ESP_GATT_OK){ + ESP_LOGE(GATTC_TAG, "open failed, status %d", p_data->open.status); + break; + } +ESP_LOGI(GATTC_TAG, "open success"); +``` + +When the MTU is exchanged, an `ESP_GATTC_CFG_MTU_EVT` is triggered, which in this example is used to print the new MTU size. + +```c +case ESP_GATTC_CFG_MTU_EVT: + if (param->cfg_mtu.status != ESP_GATT_OK){ + ESP_LOGE(GATTC_TAG,"config mtu failed, error status = %x", param->cfg_mtu.status); + } + ESP_LOGI(GATTC_TAG, "ESP_GATTC_CFG_MTU_EVT, Status %d, MTU %d, conn_id %d", param->cfg_mtu.status, param->cfg_mtu.mtu, param->cfg_mtu.conn_id); +… +``` + +## Discovering Services + +The MTU configuration event is also used to start discovering the services available in the server that the client just connected to. To discover the services, the function `esp_ble_gattc_search_service()` is used. The parameters of the function are the GATT interface, the Application Profile connection ID and the UUID of the service application that the client is interested in. The service we are looking for is defined as: + +```c +static esp_bt_uuid_t remote_filter_service_uuid = { + .len = ESP_UUID_LEN_16, + .uuid = {.uuid16 = REMOTE_SERVICE_UUID,}, +}; +``` +Where, + +```c +#define REMOTE_SERVICE_UUID 0x00FF +``` +If UUID of the service application the user is interested in is 128-bit, then there is one note below for the user which is relevant with the little-endian storage mode of the processor architecture. +The struct of UUID is defined as: + +```c +typedef struct { +#define ESP_UUID_LEN_16 2 +#define ESP_UUID_LEN_32 4 +#define ESP_UUID_LEN_128 16 + uint16_t len; /*!< UUID length, 16bit, 32bit or 128bit */ + union { + uint16_t uuid16; /*!< 16bit UUID */ + uint32_t uuid32; /*!< 32bit UUID */ + uint8_t uuid128[ESP_UUID_LEN_128]; /*!< 128bit UUID */ + } uuid; /*!< UUID */ +} __attribute__((packed)) esp_bt_uuid_t; +``` + +Note: In little-endian storage mode, you can define service UUID directly in the normal order if it's a 16-bit or a 32-bit UUID, but if service UUID is 128-bit, there is minor difference. For example, if the UUID of the service application that the user is interested in is 12345678-a1b2-c3d4-e5f6-9fafd205e457, `REMOTE_SERVICE_UUID` should be defined as {0x57,0xE4,0x05,0xD2,0xAF,0x9F,0xF6,0xE5,0xD4,0xC3,0xB2,0xA1,0x78,0x56,0x34,0x12}. + +The services are then discovered as follows: + +```c +esp_ble_gattc_search_service(gattc_if, param->cfg_mtu.conn_id, &remote_filter_service_uuid); + break; +``` + +The resulting service found, if there is any, will be returned from an `ESP_GATTC_SEARCH_RES_EVT`. For each service found, the event is triggered to print information about the service discovered, depending on the size of the UUID: + +```c + case ESP_GATTC_SEARCH_RES_EVT: { + esp_gatt_srvc_id_t *srvc_id = &p_data->search_res.srvc_id; + conn_id = p_data->search_res.conn_id; + if (srvc_id->id.uuid.len == ESP_UUID_LEN_16 && srvc_id->id.uuid.uuid.uuid16 == +REMOTE_SERVICE_UUID) { + get_server = true; + gl_profile_tab[PROFILE_A_APP_ID].service_start_handle = p_data->search_res.start_handle; + gl_profile_tab[PROFILE_A_APP_ID].service_end_handle = p_data->search_res.end_handle; + ESP_LOGI(GATTC_TAG, "UUID16: %x", srvc_id->id.uuid.uuid.uuid16); + } + break; +``` + +In case that the client finds the service that it is looking for, the flag get_server is set to true, and the start handle value and end handle value, which will be used later to get all the characteristics of that service, are saved. After all service results are returned, the search is completed and an `ESP_GATTC_SEARCH_CMPL_EVT` event is triggered. + +## Getting Characteristics + +This example implements getting characteristic data from a predefined service. The service that we want the characteristics from has an UUID of 0x00FF, and the characteristic we are interested in has an UUID of 0xFF01: + +```c +#define REMOTE_NOTIFY_CHAR_UUID 0xFF01 +``` +A service is defined using the `esp_gatt_srvc_id_t` structure as: + +```c +/** + * @brief Gatt id, include uuid and instance id + */ +typedef struct { + esp_bt_uuid_t uuid; /*!< UUID */ + uint8_t inst_id; /*!< Instance id */ +} __attribute__((packed)) esp_gatt_id_t; +``` + +In this example, we define the service that we want to get the characteristics from as: + +```c +static esp_gatt_srvc_id_t remote_service_id = { + .id = { + .uuid = { + .len = ESP_UUID_LEN_16, + .uuid = {.uuid16 = REMOTE_SERVICE_UUID,}, + }, + .inst_id = 0, + }, + .is_primary = true, +}; +``` + +Once defined, we can get the characteristics from that service using the `esp_ble_gattc_get_characteristic()` function, which is called in the `ESP_GATTC_SEARCH_CMPL_EVT` event after the search for services is completed and the client has found the service that it was looking for. + +```c +case ESP_GATTC_SEARCH_CMPL_EVT: + if (p_data->search_cmpl.status != ESP_GATT_OK){ + ESP_LOGE(GATTC_TAG, "search service failed, error status = %x", p_data->search_cmpl.status); + break; + } + conn_id = p_data->search_cmpl.conn_id; + if (get_server){ + uint16_t count = 0; + esp_gatt_status_t status = esp_ble_gattc_get_attr_count( gattc_if, + p_data->search_cmpl.conn_id,ESP_GATT_DB_CHARACTERISTIC, gl_profile_tab[PROFILE_A_APP_ID].service_start_handle, gl_profile_tab[PROFILE_A_APP_ID].service_end_handle, + INVALID_HANDLE, + &count); + if (status != ESP_GATT_OK){ + ESP_LOGE(GATTC_TAG, "esp_ble_gattc_get_attr_count error"); + } + + if (count > 0){ + char_elem_result = (esp_gattc_char_elem_t*)malloc + (sizeof(esp_gattc_char_elem_t) * count); + if (!char_elem_result){ + ESP_LOGE(GATTC_TAG, "gattc no mem"); + }else{ + status = esp_ble_gattc_get_char_by_uuid( gattc_if, + p_data->search_cmpl.conn_id, + gl_profile_tab[PROFILE_A_APP_ID].service_start_handle, + gl_profile_tab[PROFILE_A_APP_ID].service_end_handle, + remote_filter_char_uuid, + char_elem_result, + &count); + if (status != ESP_GATT_OK){ + ESP_LOGE(GATTC_TAG, "esp_ble_gattc_get_char_by_uuid error"); + } + + /* Every service have only one char in our 'ESP_GATTS_DEMO' demo, + so we used first 'char_elem_result' */ + if (count > 0 && (char_elem_result[0].properties + &ESP_GATT_CHAR_PROP_BIT_NOTIFY)){ + gl_profile_tab[PROFILE_A_APP_ID].char_handle = + char_elem_result[0].char_handle; + esp_ble_gattc_register_for_notify (gattc_if, + gl_profile_tab[PROFILE_A_APP_ID].remote_bda, + char_elem_result[0].char_handle); + } + } + /* free char_elem_result */ + free(char_elem_result); + }else{ + ESP_LOGE(GATTC_TAG, "no char found"); + } } + break; +``` + +`esp_ble_gattc_get_attr_count()` gets the attribute count with the given service or characteristic in the gattc cache. The parameters of `esp_ble_gattc_get_attr_count()` function are the GATT interface, the connection ID, the attribute type defined in `esp_gatt_db_attr_type_t`, the attribute start handle, the attribute end handle, the characteristic handle (this parameter is only valid when the type is set to `ESP_GATT_DB_DESCRIPTOR`.) and output the number of attribute has been found in the gattc cache with the given attribute type. Then we allocate a buffer to save the char information for `esp_ble_gattc_get_char_by_uuid()` function. The function finds the characteristic with the given characteristic UUID in the gattc cache. It just gets characteristic from local cache, instead of the remote devices. In a server, there might be more than one chars sharing the same UUID. However, in our gatt_server demo, every char has an unique UUID and that’s why we only use the first char in `char_elem_result`, which is the pointer to the characteristic of the service. Count initially stores the number of the characteristics that the client wants to find, and will be updated with the number of the characteristics that have been actually found in the gattc cache with `esp_ble_gattc_get_char_by_uuid`. + +## Registering for Notifications + +The client can register to receive notifications from the server every time the characteristic value changes. In this example, we want to register for notifications of the characteristic identified with an UUID of 0xff01. After getting all the characteristics, we check the properties of the received characteristic, then use the `esp_ble_gattc_register_for_notify()` function to register notifications. The function arguments are the GATT interface, the address of the remote server, and the handle we want to register for notifications. + +```c +… +/* Every service have only one char in our 'ESP_GATTS_DEMO' demo, so we used first 'char_elem_result' */ + if(count > 0 && (char_elem_result[0].properties & ESP_GATT_CHAR_PROP_BIT_NOTIFY)){ + gl_profile_tab[PROFILE_A_APP_ID].char_handle = char_elem_result[0].char_handle; + esp_ble_gattc_register_for_notify (gattc_if, gl_profile_tab[PROFILE_A_APP_ID].remote_bda, + char_elem_result[0].char_handle); + } +… +``` + +This procedure registers notifications to the BLE stack, and triggers an `ESP_GATTC_REG_FOR_NOTIFY_EVT`. This event is used to write to the server Client Configuration Descriptor: + +```c + case ESP_GATTC_REG_FOR_NOTIFY_EVT: { + ESP_LOGI(GATTC_TAG, "ESP_GATTC_REG_FOR_NOTIFY_EVT"); + if (p_data->reg_for_notify.status != ESP_GATT_OK){ + ESP_LOGE(GATTC_TAG, "REG FOR NOTIFY failed: error status = %d", p_data->reg_for_notify.status); + }else{ + uint16_t count = 0; + uint16_t notify_en = 1; + esp_gatt_status_t ret_status = esp_ble_gattc_get_attr_count( gattc_if, gl_profile_tab[PROFILE_A_APP_ID].conn_id, + ESP_GATT_DB_DESCRIPTOR, + gl_profile_tab[PROFILE_A_APP_ID].service_start_handle, + gl_profile_tab[PROFILE_A_APP_ID].service_end_handle, + gl_profile_tab[PROFILE_A_APP_ID].char_handle, &count); + if (ret_status != ESP_GATT_OK){ + ESP_LOGE(GATTC_TAG, "esp_ble_gattc_get_attr_count error"); + } + if (count > 0){ + descr_elem_result = malloc(sizeof(esp_gattc_descr_elem_t) * count); + if (!descr_elem_result){ + ESP_LOGE(GATTC_TAG, "malloc error, gattc no mem"); + }else{ + ret_status = esp_ble_gattc_get_descr_by_char_handle( + gattc_if, + gl_profile_tab[PROFILE_A_APP_ID].conn_id, + p_data->reg_for_notify.handle, + notify_descr_uuid, + descr_elem_result,&count); + + if (ret_status != ESP_GATT_OK){ + ESP_LOGE(GATTC_TAG, "esp_ble_gattc_get_descr_by_char_handle + error"); + } + + /* Every char has only one descriptor in our 'ESP_GATTS_DEMO' demo, so we used first 'descr_elem_result' */ + if (count > 0 && descr_elem_result[0].uuid.len == ESP_UUID_LEN_16 && descr_elem_result[0].uuid.uuid.uuid16 == ESP_GATT_UUID_CHAR_CLIENT_CONFIG){ + ret_status = esp_ble_gattc_write_char_descr( gattc_if, + gl_profile_tab[PROFILE_A_APP_ID].conn_id, + descr_elem_result[0].handle, + sizeof(notify_en), + (Uint8 *)¬ify_en, + ESP_GATT_WRITE_TYPE_RSP, + ESP_GATT_AUTH_REQ_NONE); + } + + if (ret_status != ESP_GATT_OK){ + ESP_LOGE(GATTC_TAG, "esp_ble_gattc_write_char_descr error"); + } + + /* free descr_elem_result */ + free(descr_elem_result); + } + } + else{ + ESP_LOGE(GATTC_TAG, "decsr not found"); + } + + } + break; + } +``` + +The event is used to first print the notification register status and the service and characteristic UUIDs of the just registered notifications. The client then writes to the Client Configuration Descriptor by using the `esp_ble_gattc_write_char_descr()` function. There are many characteristic descriptors defined in the Bluetooth specification. However, in this case we are interested in writing to the descriptor that deals with enabling notifications, which is the Client Configuration descriptor. In order to pass this descriptor as parameter, we first define it as: + +```c +static esp_gatt_id_t notify_descr_id = { + .uuid = { + .len = ESP_UUID_LEN_16, + .uuid = {.uuid16 = ESP_GATT_UUID_CHAR_CLIENT_CONFIG,}, + }, + .inst_id = 0, +}; +``` +Where `ESP_GATT_UUID_CHAR_CLIENT_CONFIG` is defined with the UUID to identify the Characteristic Client Configuration: + +```c +#define ESP_GATT_UUID_CHAR_CLIENT_CONFIG 0x2902 /* Client Characteristic Configuration */ +``` +The value to write is “1” to enable notifications. We also pass `ESP_GATT_WRITE_TYPE_RSP` to request that the server responds to the request of enabling notifications and `ESP_GATT_AUTH_REQ_NONE` to indicate that the Write request does not need authorization. + + + +## Conclusion + +We have reviewed the GATT Client example code for the ESP32. This example scans for nearby devices and searches for services and characteristics of servers of interest. When the server of interest is found, a connection is made with that server and a search for services is performed. Finally, the client looks for a specific characteristic in the services found, if found, gets the characteristic value and registers for notifications to that characteristic. This is done by registering one Application Profile and following a sequence of events to configure the GAP and GATT parameters required. + From 048fd8045020c6b3180c8cd96672eb7fe68494c6 Mon Sep 17 00:00:00 2001 From: Elvis Dukaj Date: Sun, 26 Apr 2020 13:42:54 +0200 Subject: [PATCH 03/60] ble_hid_device_demo: fix build if building with c++ Signed-off-by: Elvis Dukaj Signed-off-by: liminyang Merges https://github.com/espressif/esp-idf/pull/5191 --- examples/bluetooth/ble_hid_device_demo/main/hid_dev.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/bluetooth/ble_hid_device_demo/main/hid_dev.h b/examples/bluetooth/ble_hid_device_demo/main/hid_dev.h index 17b406b79..9954a8344 100644 --- a/examples/bluetooth/ble_hid_device_demo/main/hid_dev.h +++ b/examples/bluetooth/ble_hid_device_demo/main/hid_dev.h @@ -253,5 +253,9 @@ void hid_keyboard_build_report(uint8_t *buffer, keyboard_cmd_t cmd); void hid_mouse_build_report(uint8_t *buffer, mouse_cmd_t cmd); +#ifdef __cplusplus +} // extern "C" +#endif + #endif /* HID_DEV_H__ */ From 44887f5fde571018b9318188aadc8057cf529f29 Mon Sep 17 00:00:00 2001 From: fuzhibo Date: Sun, 28 Jun 2020 15:53:49 +0800 Subject: [PATCH 04/60] Driver(adc): Disable the synchronization operation function of ADC1 and DAC Closes IDF-1585 --- components/driver/rtc_module.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/components/driver/rtc_module.c b/components/driver/rtc_module.c index be428fc14..c5b515fc5 100644 --- a/components/driver/rtc_module.c +++ b/components/driver/rtc_module.c @@ -132,7 +132,7 @@ static const char TAG[] = "adc"; static inline void dac_output_set_enable(dac_channel_t channel, bool enable); static inline void adc1_hall_enable(bool enable); - +static inline void dac_rtc_sync_by_adc(bool enable); /*--------------------------------------------------------------- RTC IO @@ -1465,6 +1465,9 @@ esp_err_t adc1_config_channel_atten(adc1_channel_t channel, adc_atten_t atten) RTC_MODULE_CHECK(atten < ADC_ATTEN_MAX, "ADC Atten Err", ESP_ERR_INVALID_ARG); adc_gpio_init(ADC_UNIT_1, channel); adc_set_atten(ADC_UNIT_1, channel, atten); + /* Workaround: Disable the synchronization operation function of ADC1 and DAC. + If enabled(default), ADC RTC controller sampling will cause the DAC channel output voltage. */ + dac_rtc_sync_by_adc(false); return ESP_OK; } @@ -1806,12 +1809,25 @@ static inline void dac_output_set_enable(dac_channel_t channel, bool enable) RTCIO.pad_dac[channel-DAC_CHANNEL_1].xpd_dac = enable; } +/** + * Enable/disable the synchronization operation function of ADC1 and DAC. + * + * @note If enabled(default), ADC RTC controller sampling will cause the DAC channel output voltage. + * + * @param enable Enable or disable adc and dac synchronization function. + */ +static inline void dac_rtc_sync_by_adc(bool enable) +{ + SENS.sar_meas_ctrl2.sar1_dac_xpd_fsm = enable; +} + esp_err_t dac_output_enable(dac_channel_t channel) { RTC_MODULE_CHECK((channel >= DAC_CHANNEL_1) && (channel < DAC_CHANNEL_MAX), DAC_ERR_STR_CHANNEL_ERROR, ESP_ERR_INVALID_ARG); dac_rtc_pad_init(channel); portENTER_CRITICAL(&rtc_spinlock); dac_output_set_enable(channel, true); + dac_rtc_sync_by_adc(false); portEXIT_CRITICAL(&rtc_spinlock); return ESP_OK; From a3ef357b8da039a335eda9bae5d10990f845908b Mon Sep 17 00:00:00 2001 From: Marius Vikhammer Date: Tue, 7 Jul 2020 18:21:05 +0800 Subject: [PATCH 05/60] Docs: fix broken example README links --- examples/bluetooth/esp_ble_mesh/README.md | 2 +- examples/protocols/pppos_client/README.md | 2 +- examples/system/app_trace_to_host/README.md | 10 +++++----- examples/system/ota/otatool/README.md | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/examples/bluetooth/esp_ble_mesh/README.md b/examples/bluetooth/esp_ble_mesh/README.md index 50659c91e..6552c8428 100644 --- a/examples/bluetooth/esp_ble_mesh/README.md +++ b/examples/bluetooth/esp_ble_mesh/README.md @@ -1,6 +1,6 @@ # ESP-BLE-MESH Examples -[ESP-BLE-MESH]($IDF_PATH/components/bt/esp_ble_mesh/) is the official Bluetooth® Mesh stack of Espressif Systems. We will provide long-term support for new features, performance optimization, etc. +[ESP-BLE-MESH](../../../components/bt/esp_ble_mesh/) is the official Bluetooth® Mesh stack of Espressif Systems. We will provide long-term support for new features, performance optimization, etc. Please help note that breaking changes may be introduced into ESP-BLE-MESH on [minor IDF versions](https://docs.espressif.com/projects/esp-idf/en/latest/versions.html). diff --git a/examples/protocols/pppos_client/README.md b/examples/protocols/pppos_client/README.md index bcfb8e503..90a88ab5f 100644 --- a/examples/protocols/pppos_client/README.md +++ b/examples/protocols/pppos_client/README.md @@ -14,7 +14,7 @@ When PPP connection has been established, the IP packet flow from application si ### Hardware Required To run this example, you need an ESP32 dev board (e.g. ESP32-WROVER Kit) or ESP32 core board (e.g. ESP32-DevKitC). -For test purpose, you also need a cellular modem module. Here we take the [SIM800L](http://www.simcom.com/product/showproduct.php?lang=en&id=277) and [BG96](https://www.quectel.com/product/bg96.htm) as an example. +For test purpose, you also need a cellular modem module. Here we take the [SIM800L](https://www.simcom.com/product/SIM800.html) and [BG96](https://www.quectel.com/product/bg96.htm) as an example. You can also try other modules as long as they embedded PPP protocol. **Note:** Since SIM800L only support **2G** which will **not** work in some countries. And also keep in mind that in some other countries it will stop working soon (many remaining 2G networks will be switched off in the next 2-3 years). So you should **check with your local providers for further details** if you try this example with any 2G modules. diff --git a/examples/system/app_trace_to_host/README.md b/examples/system/app_trace_to_host/README.md index 1abb8bde6..012fab03b 100644 --- a/examples/system/app_trace_to_host/README.md +++ b/examples/system/app_trace_to_host/README.md @@ -13,7 +13,7 @@ For more description of [logging to host](https://docs.espressif.com/projects/es Debugging of time critical functions may not work as desired if log messages are sent through the UART port. Printing out the logs may considerably slow down tested function to the point where it will not operate as expected. -Let's consider a case we are testing implementation of [zero level crossing](https://en.wikipedia.org/wiki/Zero_crossing) detection for a 50 Hz signal with ESP32's ADC. +Let's consider a case we are testing implementation of [zero level crossing](https://en.wikipedia.org/wiki/Zero_crossing) detection for a 50 Hz signal with ESP32's ADC. We will start by checking if we can read ADC, what is the signal level and how many samples can be collected over 20 ms period by using a code snippet below: @@ -36,7 +36,7 @@ I (4319) example: Sample:4, Value:27 I (4319) example: Sample:5, Value:4095 ``` -As you see we were able to collect only five samples. This seems rather not adequate for zero crossing detection. +As you see we were able to collect only five samples. This seems rather not adequate for zero crossing detection. We can remove `ESP_LOGI()` line and sample much faster, but then will not be able to see the values. To see the values we would need to save them in the memory and print out later. @@ -46,7 +46,7 @@ Instead of saving samples to memory, a simple and compelling solution to this is esp_log_set_vprintf(esp_apptrace_vprintf); ``` -Once time critical messages are sent out, we can redirect `ESP_LOGx` back back to the UART by adding extra two lines of code. +Once time critical messages are sent out, we can redirect `ESP_LOGx` back back to the UART by adding extra two lines of code. ```c esp_log_set_vprintf(vprintf); @@ -176,7 +176,7 @@ This is the log we have been looking for, complete with timestamps as if printed ## Example Output -Check the full example code [app_trace_to_host](main/app_trace_to_host_test.c) that combines both tests above and runs them in a loop showing instantly the number of samples collected: +Check the full example code [app_trace_to_host](main/app_trace_to_host_example_main.c) that combines both tests above and runs them in a loop showing instantly the number of samples collected: ``` I (4289) example: Sampling ADC and sending data to the host... @@ -199,7 +199,7 @@ With this example code we have demonstrated powerful functionality of logging to ## Troubleshooting 1. I can not flash new firmware when OpenOCD is connected to ESP32. - * One likely cause would be that you set wrong SPI flash voltage when you start OpenOCD. Suppose you're working with an ESP32 board / module which has a 3.3V powered SPI flash, but you select + * One likely cause would be that you set wrong SPI flash voltage when you start OpenOCD. Suppose you're working with an ESP32 board / module which has a 3.3V powered SPI flash, but you select `board/esp32-wrover.cfg` configuration file when start OpenOCD. In this situation, you might not be able to flash ESP32 when OpenOCD is connected. So make sure what the working voltage of the SPI flash is. Currently, for 1.8V flash, we'd like to suggest using `board/esp32-wrover.cfg` and for 3.3V flash, using `board/esp-wroom-32.cfg`. For more information about it, please refer to [ESP32 Modules and Boards](https://docs.espressif.com/projects/esp-idf/en/latest/hw-reference/modules-and-boards.html) and [Set SPI Flash Voltage](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/jtag-debugging/tips-and-quirks.html#why-to-set-spi-flash-voltage-in-openocd-configuration). (For any technical queries, please open an [issue](https://github.com/espressif/esp-idf/issues) on GitHub. We will get back to you as soon as possible.) diff --git a/examples/system/ota/otatool/README.md b/examples/system/ota/otatool/README.md index c14e1cfb0..910aad59d 100644 --- a/examples/system/ota/otatool/README.md +++ b/examples/system/ota/otatool/README.md @@ -1,12 +1,12 @@ # OTA Tool Example -This example demonstrates common operations the OTA tool [otatool.py](../../../components/app_update/otatool.py) allows the user to perform: +This example demonstrates common operations the OTA tool [otatool.py](../../../../components/app_update/otatool.py) allows the user to perform: - reading, writing and erasing OTA partitions, - switching boot partitions, and - switching to factory partition. -Users taking a look at this example should focus on the contents of the python script [otatool_example.py](otatool_example.py). The script contains programmatic invocations of the tool [otatool.py](../../../components/app_update/otatool.py) in Python for the operations mentioned above; and can serve as a guide for users wanting to do the same in their applications. +Users taking a look at this example should focus on the contents of the python script [otatool_example.py](otatool_example.py). The script contains programmatic invocations of the tool [otatool.py](../../../../components/app_update/otatool.py) in Python for the operations mentioned above; and can serve as a guide for users wanting to do the same in their applications. The built application in this example outputs the currently running partition, whose output is used to verify if the tool switched OTA partitions succesfully. The built application binary is written to all OTA partitions at the start of the example to be able to determine the running @@ -40,7 +40,7 @@ or run it using python otatool_example.py ``` -The script searches for valid target devices connected to the host and performs the operations on the first one it finds. This could present problems if there +The script searches for valid target devices connected to the host and performs the operations on the first one it finds. This could present problems if there are multiple viable target devices attached to the host. To perform the operations on a specific device, specify the port it is attached to during script invocation: ```bash From 22926742be7eef5f289f75b8d187fc593d869710 Mon Sep 17 00:00:00 2001 From: Shubham Kulkarni Date: Mon, 30 Mar 2020 11:51:23 +0530 Subject: [PATCH 06/60] esp_http_client.c: In esp_http_client_read, add fix to return (-1) if esp_transport_read fails --- components/esp_http_client/esp_http_client.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/esp_http_client/esp_http_client.c b/components/esp_http_client/esp_http_client.c index 25c0d5d87..72f8cdf53 100644 --- a/components/esp_http_client/esp_http_client.c +++ b/components/esp_http_client/esp_http_client.c @@ -854,7 +854,11 @@ int esp_http_client_read(esp_http_client_handle_t client, char *buffer, int len) } ESP_LOG_LEVEL(sev, TAG, "esp_transport_read returned:%d and errno:%d ", rlen, errno); } - return ridx; + if (rlen < 0 && ridx == 0) { + return ESP_FAIL; + } else { + return ridx; + } } res_buffer->output_ptr = buffer + ridx; http_parser_execute(client->parser, client->parser_settings, res_buffer->data, rlen); From e84ad136b94805df8b7414c6dbdcc084f1e4efa9 Mon Sep 17 00:00:00 2001 From: Shubham Kulkarni Date: Mon, 30 Mar 2020 11:52:38 +0530 Subject: [PATCH 07/60] esp_https_ota.c: Add fix to return failure if (-1) is returned from esp_http_client_read Closes https://github.com/espressif/esp-idf/issues/4960 --- components/esp_https_ota/src/esp_https_ota.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/components/esp_https_ota/src/esp_https_ota.c b/components/esp_https_ota/src/esp_https_ota.c index 4bab1dcdb..98df98bbb 100644 --- a/components/esp_https_ota/src/esp_https_ota.c +++ b/components/esp_https_ota/src/esp_https_ota.c @@ -78,10 +78,7 @@ static esp_err_t _http_handle_response_code(esp_http_client_handle_t http_client * to clear the response buffer of http_client. */ int data_read = esp_http_client_read(http_client, upgrade_data_buf, DEFAULT_OTA_BUF_SIZE); - if (data_read < 0) { - ESP_LOGE(TAG, "Error: SSL data read error"); - return ESP_FAIL; - } else if (data_read == 0) { + if (data_read <= 0) { return ESP_OK; } } @@ -235,10 +232,10 @@ esp_err_t esp_https_ota_get_img_desc(esp_https_ota_handle_t https_ota_handle, es (handle->ota_upgrade_buf + bytes_read), data_read_size); /* - * As esp_http_client_read never returns negative error code, we rely on + * As esp_http_client_read doesn't return negative error code if select fails, we rely on * `errno` to check for underlying transport connectivity closure if any */ - if (errno == ENOTCONN || errno == ECONNRESET || errno == ECONNABORTED) { + if (errno == ENOTCONN || errno == ECONNRESET || errno == ECONNABORTED || data_read < 0) { ESP_LOGE(TAG, "Connection closed, errno = %d", errno); break; } @@ -294,7 +291,7 @@ esp_err_t esp_https_ota_perform(esp_https_ota_handle_t https_ota_handle) */ bool is_recv_complete = esp_https_ota_is_complete_data_received(https_ota_handle); /* - * As esp_http_client_read never returns negative error code, we rely on + * As esp_http_client_read doesn't return negative error code if select fails, we rely on * `errno` to check for underlying transport connectivity closure if any. * Incase the complete data has not been received but the server has sent * an ENOTCONN or ECONNRESET, failure is returned. We close with success @@ -309,6 +306,8 @@ esp_err_t esp_https_ota_perform(esp_https_ota_handle_t https_ota_handle) ESP_LOGI(TAG, "Connection closed"); } else if (data_read > 0) { return _ota_write(handle, (const void *)handle->ota_upgrade_buf, data_read); + } else { + return ESP_FAIL; } handle->state = ESP_HTTPS_OTA_SUCCESS; break; From b45e2699b2a9d0808db82e5c67a1d088b9d541c2 Mon Sep 17 00:00:00 2001 From: Shubham Kulkarni Date: Wed, 8 Jul 2020 10:02:07 +0530 Subject: [PATCH 08/60] Increase receive timeout in sdkconfig.ci to fix CI failures --- examples/system/ota/advanced_https_ota/sdkconfig.ci | 2 +- examples/system/ota/native_ota_example/sdkconfig.ci | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/system/ota/advanced_https_ota/sdkconfig.ci b/examples/system/ota/advanced_https_ota/sdkconfig.ci index 73f41c336..0a78f8da9 100644 --- a/examples/system/ota/advanced_https_ota/sdkconfig.ci +++ b/examples/system/ota/advanced_https_ota/sdkconfig.ci @@ -1,4 +1,4 @@ CONFIG_FIRMWARE_UPGRADE_URL="FROM_STDIN" CONFIG_EXAMPLE_SKIP_COMMON_NAME_CHECK=y CONFIG_EXAMPLE_SKIP_VERSION_CHECK=y -CONFIG_EXAMPLE_OTA_RECV_TIMEOUT=2000 +CONFIG_EXAMPLE_OTA_RECV_TIMEOUT=3000 diff --git a/examples/system/ota/native_ota_example/sdkconfig.ci b/examples/system/ota/native_ota_example/sdkconfig.ci index afb368a21..c734d00be 100644 --- a/examples/system/ota/native_ota_example/sdkconfig.ci +++ b/examples/system/ota/native_ota_example/sdkconfig.ci @@ -1,4 +1,4 @@ CONFIG_FIRMWARE_UPG_URL="FROM_STDIN" CONFIG_EXAMPLE_SKIP_COMMON_NAME_CHECK=y CONFIG_EXAMPLE_SKIP_VERSION_CHECK=y -CONFIG_EXAMPLE_OTA_RECV_TIMEOUT=2000 +CONFIG_EXAMPLE_OTA_RECV_TIMEOUT=3000 From 9eb66d49e4fd91d831bad7322651a641a45d3cb0 Mon Sep 17 00:00:00 2001 From: lly Date: Wed, 1 Jul 2020 20:02:26 +0800 Subject: [PATCH 09/60] ble_mesh: stack: Update send_ttl in btc when recv a msg Update send_ttl mainly for server models. When a server model receives a message, and the status is required to be replied by the application, we need to set send_ttl to the msg context. If send_ttl is not updated in btc, and the applcation does not set the TTL either, then the status will be replied with TTL=0, which may cause the client side (e.g. the phone App) failed to receive the status. Closes https://github.com/espressif/esp-idf/issues/5300 --- components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c | 2 ++ components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c | 2 ++ components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c | 1 + components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c | 2 ++ components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c | 2 ++ components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c | 2 ++ 6 files changed, 11 insertions(+) diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c index c87445407..c66f166ae 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c @@ -352,6 +352,7 @@ void bt_mesh_config_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, params.ctx.recv_op = ctx->recv_op; params.ctx.recv_dst = ctx->recv_dst; params.ctx.recv_rssi = ctx->recv_rssi; + params.ctx.send_ttl = ctx->send_ttl; cb_params.error_code = 0; cb_params.params = ¶ms; @@ -753,6 +754,7 @@ void bt_mesh_config_server_cb_evt_to_btc(u8_t evt_type, cb_params.ctx.recv_op = ctx->recv_op; cb_params.ctx.recv_dst = ctx->recv_dst; cb_params.ctx.recv_rssi = ctx->recv_rssi; + cb_params.ctx.send_ttl = ctx->send_ttl; if (val && len) { length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c index 4664a83d6..d555268ab 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c @@ -420,6 +420,7 @@ void bt_mesh_generic_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, params.ctx.recv_op = ctx->recv_op; params.ctx.recv_dst = ctx->recv_dst; params.ctx.recv_rssi = ctx->recv_rssi; + params.ctx.send_ttl = ctx->send_ttl; cb_params.error_code = 0; cb_params.params = ¶ms; @@ -744,6 +745,7 @@ void bt_mesh_generic_server_cb_evt_to_btc(u8_t evt_type, cb_params.ctx.recv_op = ctx->recv_op; cb_params.ctx.recv_dst = ctx->recv_dst; cb_params.ctx.recv_rssi = ctx->recv_rssi; + cb_params.ctx.send_ttl = ctx->send_ttl; if (val && len) { length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c index e3be0c34c..fd4125efb 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c @@ -286,6 +286,7 @@ void bt_mesh_health_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, params.ctx.recv_op = ctx->recv_op; params.ctx.recv_dst = ctx->recv_dst; params.ctx.recv_rssi = ctx->recv_rssi; + params.ctx.send_ttl = ctx->send_ttl; cb_params.error_code = 0; cb_params.params = ¶ms; diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c index 1adaac4f6..4a0a4bf9e 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c @@ -264,6 +264,7 @@ void bt_mesh_lighting_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, params.ctx.recv_op = ctx->recv_op; params.ctx.recv_dst = ctx->recv_dst; params.ctx.recv_rssi = ctx->recv_rssi; + params.ctx.send_ttl = ctx->send_ttl; cb_params.error_code = 0; cb_params.params = ¶ms; @@ -559,6 +560,7 @@ void bt_mesh_lighting_server_cb_evt_to_btc(u8_t evt_type, cb_params.ctx.recv_op = ctx->recv_op; cb_params.ctx.recv_dst = ctx->recv_dst; cb_params.ctx.recv_rssi = ctx->recv_rssi; + cb_params.ctx.send_ttl = ctx->send_ttl; if (val && len) { length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c index 682b4d70f..7b3b3d8d3 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c @@ -502,6 +502,7 @@ void bt_mesh_sensor_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, params.ctx.recv_op = ctx->recv_op; params.ctx.recv_dst = ctx->recv_dst; params.ctx.recv_rssi = ctx->recv_rssi; + params.ctx.send_ttl = ctx->send_ttl; cb_params.error_code = 0; cb_params.params = ¶ms; @@ -876,6 +877,7 @@ void bt_mesh_sensor_server_cb_evt_to_btc(u8_t evt_type, cb_params.ctx.recv_op = ctx->recv_op; cb_params.ctx.recv_dst = ctx->recv_dst; cb_params.ctx.recv_rssi = ctx->recv_rssi; + cb_params.ctx.send_ttl = ctx->send_ttl; if (val && len) { length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c index 68862ac38..66f1311a2 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c @@ -266,6 +266,7 @@ void bt_mesh_time_scene_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, params.ctx.recv_op = ctx->recv_op; params.ctx.recv_dst = ctx->recv_dst; params.ctx.recv_rssi = ctx->recv_rssi; + params.ctx.send_ttl = ctx->send_ttl; cb_params.error_code = 0; cb_params.params = ¶ms; @@ -463,6 +464,7 @@ void bt_mesh_time_scene_server_cb_evt_to_btc(u8_t evt_type, cb_params.ctx.recv_op = ctx->recv_op; cb_params.ctx.recv_dst = ctx->recv_dst; cb_params.ctx.recv_rssi = ctx->recv_rssi; + cb_params.ctx.send_ttl = ctx->send_ttl; if (val && len) { length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value); From 28c067337640eeee1d3748b78c2b946b81b6087e Mon Sep 17 00:00:00 2001 From: lly Date: Wed, 1 Jul 2020 20:10:35 +0800 Subject: [PATCH 10/60] ble_mesh: stack: Add two application macros for TTL --- components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h b/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h index 046e1e135..c9cc95432 100644 --- a/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h +++ b/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h @@ -61,6 +61,12 @@ typedef uint8_t esp_ble_mesh_octet8_t[ESP_BLE_MESH_OCTET8_LEN]; /*!< Invalid Company ID */ #define ESP_BLE_MESH_CID_NVAL 0xFFFF +/*!< Special TTL value to request using configured default TTL */ +#define ESP_BLE_MESH_TTL_DEFAULT 0xFF + +/*!< Maximum allowed TTL value */ +#define ESP_BLE_MESH_TTL_MAX 0x7F + #define ESP_BLE_MESH_ADDR_UNASSIGNED 0x0000 #define ESP_BLE_MESH_ADDR_ALL_NODES 0xFFFF #define ESP_BLE_MESH_ADDR_PROXIES 0xFFFC @@ -522,7 +528,7 @@ typedef struct { /** Force sending reliably by using segment acknowledgement */ uint8_t send_rel: 1; - /** TTL, or BLE_MESH_TTL_DEFAULT for default TTL. */ + /** TTL, or ESP_BLE_MESH_TTL_DEFAULT for default TTL. */ uint8_t send_ttl; /** Opcode of a received message. Not used for sending message. */ From 62fea80a0162944def958d482905ce18a0208b74 Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Tue, 28 Jul 2020 18:19:19 +0200 Subject: [PATCH 11/60] Tools: Close temporary file before invoking external tools accessing it --- tools/unit-test-app/idf_ext.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tools/unit-test-app/idf_ext.py b/tools/unit-test-app/idf_ext.py index 06b843f01..e7ce9b9d2 100644 --- a/tools/unit-test-app/idf_ext.py +++ b/tools/unit-test-app/idf_ext.py @@ -138,7 +138,7 @@ def add_action_extensions(base_functions, base_actions): set_config_build_variables("TEST_EXCLUDE_COMPONENTS","''") - with tempfile.NamedTemporaryFile() as sdkconfig_temp: + with tempfile.NamedTemporaryFile(delete=False) as sdkconfig_temp: # Use values from the combined defaults and the values from # config folder to build config sdkconfig_default = os.path.join(PROJECT_PATH, "sdkconfig.defaults") @@ -150,9 +150,7 @@ def add_action_extensions(base_functions, base_actions): with open(sdkconfig_config, "rb") as sdkconfig_config_file: sdkconfig_temp.write(b"\n") sdkconfig_temp.write(sdkconfig_config_file.read()) - - sdkconfig_temp.flush() - + try: try: args.define_cache_entry.append("SDKCONFIG_DEFAULTS=" + sdkconfig_temp.name) except AttributeError: @@ -160,6 +158,11 @@ def add_action_extensions(base_functions, base_actions): reconfigure = base_functions["reconfigure"] reconfigure(None, args) + finally: + try: + os.unlink(sdkconfig_temp.name) + except OSError: + pass else: if not config_name == "all-configs": print("unknown unit test app config for action '%s'" % ut_apply_config_name) From 2e89f963d799c1a80e5dc3e2ba48d36451ffa970 Mon Sep 17 00:00:00 2001 From: Hou Chen Yao Date: Wed, 5 Aug 2020 17:41:46 +0800 Subject: [PATCH 12/60] remove auto conn case because we do not support this anymore --- .../integration_test/TC_IT_WIFI_CONN.yml | 54 ------------------- 1 file changed, 54 deletions(-) diff --git a/components/idf_test/integration_test/TC_IT_WIFI_CONN.yml b/components/idf_test/integration_test/TC_IT_WIFI_CONN.yml index d62f31d14..3b49f8eb7 100644 --- a/components/idf_test/integration_test/TC_IT_WIFI_CONN.yml +++ b/components/idf_test/integration_test/TC_IT_WIFI_CONN.yml @@ -356,60 +356,6 @@ test cases: test point 1: interaction test point 2: Conn interact with other WiFi operation version: v1 (2016-8-15) -- CI ready: 'Yes' - ID: WIFI_CONN_0401 - SDK: |- - 8266_NonOS - 8266_RTOS - ESP32_IDF - Test App: SSC - allow fail: '' - auto test: 'Yes' - category: Function - cmd set: - - '' - - - SSC SSC1 sta -R -a 0 - - - R SSC1 C +AUTORECONN:OK - - - SSC SSC1 sta -R -a 2 - - - R SSC1 C +AUTORECONN:0 - - - SSC SSC1 reboot - - - '' - - - DELAY 15 - - - '' - - - SSC SSC1 sta -Q - - - R SSC1 C JAP:DISCONNECTED - - - SSC SSC1 sta -R -a 1 - - - R SSC1 C +AUTORECONN:OK - - - SSC SSC1 sta -R -a 2 - - - R SSC1 C +AUTORECONN:1 - - - SSC SSC1 reboot - - - R SSC1 C +JAP:CONNECTED - execution time: 0.0 - expected result: |- - 1.设置autoreconn,关闭 - 2.查询当前autoreconn状态是否关闭 - 3.重启系统,等待15s - 4.查询target1 未自动重连AP - 5.设置autoreconn,开启 - 6.查询当前autoreconn状态是否开启 - 7.系统重启后target1 自动重连AP - initial condition: STAM2 - level: Integration - module: WIFI MAC - steps: |- - 1.设置autoreconn,关闭 - 2.查询当前autoreconn状态是否关闭 - 3.重启系统,等待15s - 4.查询target1 未自动重连AP - 5.设置autoreconn,开启 - 6.查询当前autoreconn状态是否开启 - 7.系统重启后target1 自动重连AP - sub module: WIFI Connect - summary: auto reconnect test - test environment: SSC_T1_5 - test point 1: basic function - test point 2: power on auto reconnect test - version: v1 (2016-8-15) - CI ready: 'Yes' ID: WIFI_CONN_0501 SDK: |- From 52c089fba705037c0bdf45b01fdd1126a0a15991 Mon Sep 17 00:00:00 2001 From: Piyush Shah Date: Wed, 6 May 2020 20:14:52 +0530 Subject: [PATCH 13/60] protocomm_httpd: Restart security session if request is received on a new session This commit fixes a bug as well as changes a behaviour. Bugfix: During softap/httpd based provisioning, if a session was closed midway and a new one started, it would never proceed if the http server assigns same socket number to the new session (which happens almost always). Now, if a session is closed, using the http callbacks, the older session data is cleared so that a new one can be created. Behavioural change: If a client (mobile app particularly) does not use persistent http session i.e. all provisioning communication on the same socket, the provisioning may fail. Earlier, since the session context was not getting cleared, even if the client closed a session and continued on a new one, it would go through if the socket number assigned was same (which happens almost always). Ideally, from a security perspective, all communication related to secure provisioning must happen on the same socket, and so, this change is required. --- .../protocomm/src/transports/protocomm_httpd.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/components/protocomm/src/transports/protocomm_httpd.c b/components/protocomm/src/transports/protocomm_httpd.c index 1a20c4442..22be22c20 100644 --- a/components/protocomm/src/transports/protocomm_httpd.c +++ b/components/protocomm/src/transports/protocomm_httpd.c @@ -31,6 +31,17 @@ static uint32_t session_id = PROTOCOMM_NO_SESSION_ID; #define MAX_REQ_BODY_LEN 4096 +static void protocomm_httpd_session_close(void *ctx) +{ + if (pc_httpd->sec && pc_httpd->sec->close_transport_session) { + ESP_LOGW(TAG, "Closing session as socket %d was closed", session_id); + if (pc_httpd->sec->close_transport_session(session_id) != ESP_OK) { + ESP_LOGW(TAG, "Error closing session with ID: %d", session_id); + } + } + session_id = PROTOCOMM_NO_SESSION_ID; +} + static esp_err_t common_post_handler(httpd_req_t *req) { esp_err_t ret; @@ -42,6 +53,7 @@ static esp_err_t common_post_handler(httpd_req_t *req) int cur_session_id = httpd_req_to_sockfd(req); if (cur_session_id != session_id) { + ESP_LOGI(TAG, "Creating new session: %d", cur_session_id); /* Initialize new security session */ if (session_id != PROTOCOMM_NO_SESSION_ID) { ESP_LOGD(TAG, "Closing session with ID: %d", session_id); @@ -62,6 +74,8 @@ static esp_err_t common_post_handler(httpd_req_t *req) ret = ESP_FAIL; goto out; } + req->free_ctx = protocomm_httpd_session_close; + } session_id = cur_session_id; ESP_LOGD(TAG, "New session with ID: %d", cur_session_id); From fbdcfc8e4a8b3441b4deb783bb60450eebce3bfc Mon Sep 17 00:00:00 2001 From: Prasad Alatkar Date: Tue, 9 Jun 2020 23:16:11 +0530 Subject: [PATCH 14/60] BLE provisioning: Add check for valid ble read offset --- .../protocomm/src/transports/protocomm_ble.c | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/components/protocomm/src/transports/protocomm_ble.c b/components/protocomm/src/transports/protocomm_ble.c index 3b5161fdb..802439ea9 100644 --- a/components/protocomm/src/transports/protocomm_ble.c +++ b/components/protocomm/src/transports/protocomm_ble.c @@ -108,28 +108,39 @@ static void transport_simple_ble_read(esp_gatts_cb_event_t event, esp_gatt_if_t { static const uint8_t *read_buf = NULL; static uint16_t read_len = 0; + static uint16_t max_read_len = 0; esp_gatt_status_t status = ESP_OK; ESP_LOGD(TAG, "Inside read w/ session - %d on param %d %d", param->read.conn_id, param->read.handle, read_len); if (!read_len && !param->read.offset) { ESP_LOGD(TAG, "Reading attr value first time"); - status = esp_ble_gatts_get_attr_value(param->read.handle, &read_len, &read_buf); + status = esp_ble_gatts_get_attr_value(param->read.handle, &read_len, &read_buf); + max_read_len = read_len; + } else if ((read_len + param->read.offset) > max_read_len) { + status = ESP_GATT_INVALID_OFFSET; } else { ESP_LOGD(TAG, "Subsequent read request for attr value"); } esp_gatt_rsp_t gatt_rsp = {0}; - gatt_rsp.attr_value.len = MIN(read_len, (protoble_internal->gatt_mtu - 1)); gatt_rsp.attr_value.handle = param->read.handle; gatt_rsp.attr_value.offset = param->read.offset; - gatt_rsp.attr_value.auth_req = ESP_GATT_AUTH_REQ_NONE; - if (gatt_rsp.attr_value.len && read_buf) { - memcpy(gatt_rsp.attr_value.value, - read_buf + param->read.offset, - gatt_rsp.attr_value.len); + + if (status == ESP_GATT_OK) { + gatt_rsp.attr_value.len = MIN(read_len, (protoble_internal->gatt_mtu - 1)); + gatt_rsp.attr_value.auth_req = ESP_GATT_AUTH_REQ_NONE; + if (gatt_rsp.attr_value.len && read_buf) { + memcpy(gatt_rsp.attr_value.value, + read_buf + param->read.offset, + gatt_rsp.attr_value.len); + } + read_len -= gatt_rsp.attr_value.len; + } else { + read_len = 0; + max_read_len = 0; + read_buf = NULL; } - read_len -= gatt_rsp.attr_value.len; esp_err_t err = esp_ble_gatts_send_response(gatts_if, param->read.conn_id, param->read.trans_id, status, &gatt_rsp); if (err != ESP_OK) { From a293dfea7a37cb8586c1ab23b2e1913a1d71d685 Mon Sep 17 00:00:00 2001 From: houwenxiang Date: Tue, 14 Jul 2020 01:07:30 +0800 Subject: [PATCH 15/60] feature: support vfs uart set line endings with specified uart number release/v3.3 --- components/vfs/include/esp_vfs_dev.h | 38 +++++++++++++++++++ components/vfs/test/test_vfs_uart.c | 4 +- components/vfs/vfs_uart.c | 37 ++++++++++++++---- .../main/ble_mesh_console_main.c | 4 +- .../main/ble_mesh_console_main.c | 4 +- .../ble_mesh_wifi_coexist/main/main.c | 4 +- .../ethernet/iperf/main/iperf_example_main.c | 4 +- .../i2c_tools/main/i2ctools_example_main.c | 4 +- .../asio/chat_client/components/wifi_asio.cpp | 4 +- .../asio/chat_server/components/wifi_asio.cpp | 4 +- .../tcp_echo_server/components/wifi_asio.cpp | 4 +- .../udp_echo_server/components/wifi_asio.cpp | 4 +- .../protocols/asio/wifi_init/wifi_asio.cpp | 4 +- .../console/main/console_example_main.c | 4 +- .../main/advanced_https_ota_example.c | 4 +- .../main/native_ota_example.c | 4 +- .../main/simple_ota_example.c | 4 +- examples/wifi/iperf/main/iperf_example_main.c | 4 +- .../main/simple_sniffer_example_main.c | 4 +- 19 files changed, 102 insertions(+), 41 deletions(-) diff --git a/components/vfs/include/esp_vfs_dev.h b/components/vfs/include/esp_vfs_dev.h index b330b4c56..637f1449f 100644 --- a/components/vfs/include/esp_vfs_dev.h +++ b/components/vfs/include/esp_vfs_dev.h @@ -68,6 +68,44 @@ void esp_vfs_dev_uart_set_rx_line_endings(esp_line_endings_t mode); */ void esp_vfs_dev_uart_set_tx_line_endings(esp_line_endings_t mode); +/** + * @brief Set the line endings expected to be received on specified UART + * + * This specifies the conversion between line endings received on UART and + * newlines ('\n', LF) passed into stdin: + * + * - ESP_LINE_ENDINGS_CRLF: convert CRLF to LF + * - ESP_LINE_ENDINGS_CR: convert CR to LF + * - ESP_LINE_ENDINGS_LF: no modification + * + * @note this function is not thread safe w.r.t. reading from UART + * + * @param uart_num the UART number + * @param mode line endings to send to UART + * @return 0 if successed, or -1 + * when an error (specified by errno) have occurred. + */ +int esp_vfs_dev_uart_port_set_rx_line_endings(int uart_num, esp_line_endings_t mode); + +/** + * @brief Set the line endings to sent to specified UART + * + * This specifies the conversion between newlines ('\n', LF) on stdout and line + * endings sent over UART: + * + * - ESP_LINE_ENDINGS_CRLF: convert LF to CRLF + * - ESP_LINE_ENDINGS_CR: convert LF to CR + * - ESP_LINE_ENDINGS_LF: no modification + * + * @note this function is not thread safe w.r.t. writing to UART + * + * @param uart_num the UART number + * @param mode line endings to send to UART + * @return 0 if successed, or -1 + * when an error (specified by errno) have occurred. + */ +int esp_vfs_dev_uart_port_set_tx_line_endings(int uart_num, esp_line_endings_t mode); + /** * @brief set VFS to use simple functions for reading and writing UART * Read is non-blocking, write is busy waiting until TX FIFO has enough space. diff --git a/components/vfs/test/test_vfs_uart.c b/components/vfs/test/test_vfs_uart.c index 2e45d76bf..59a6ccf0e 100644 --- a/components/vfs/test/test_vfs_uart.c +++ b/components/vfs/test/test_vfs_uart.c @@ -77,8 +77,8 @@ TEST_CASE("can read from stdin", "[vfs]") TEST_CASE("CRs are removed from the stdin correctly", "[vfs]") { - esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CRLF); - esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); + esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF); + esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF); flush_stdin_stdout(); const char* send_str = "1234567890\n\r123\r\n4\n"; diff --git a/components/vfs/vfs_uart.c b/components/vfs/vfs_uart.c index ebff91a87..c6aa6f096 100644 --- a/components/vfs/vfs_uart.c +++ b/components/vfs/vfs_uart.c @@ -71,14 +71,15 @@ static fd_set *_writefds_orig = NULL; static fd_set *_errorfds_orig = NULL; // Newline conversion mode when transmitting -static esp_line_endings_t s_tx_mode = +static esp_line_endings_t s_tx_mode [UART_NUM] = { [0 ... UART_NUM-1] = #if CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF - ESP_LINE_ENDINGS_CRLF; + ESP_LINE_ENDINGS_CRLF #elif CONFIG_NEWLIB_STDOUT_LINE_ENDING_CR - ESP_LINE_ENDINGS_CR; + ESP_LINE_ENDINGS_CR #else - ESP_LINE_ENDINGS_LF; + ESP_LINE_ENDINGS_LF #endif + }; // Newline conversion mode when receiving static esp_line_endings_t s_rx_mode[UART_NUM] = { [0 ... UART_NUM-1] = @@ -172,9 +173,9 @@ static ssize_t uart_write(int fd, const void * data, size_t size) _lock_acquire_recursive(&s_uart_write_locks[fd]); for (size_t i = 0; i < size; i++) { int c = data_c[i]; - if (c == '\n' && s_tx_mode != ESP_LINE_ENDINGS_LF) { + if (c == '\n' && s_tx_mode[fd] != ESP_LINE_ENDINGS_LF) { s_uart_tx_func[fd](fd, '\r'); - if (s_tx_mode == ESP_LINE_ENDINGS_CR) { + if (s_tx_mode[fd] == ESP_LINE_ENDINGS_CR) { continue; } } @@ -927,7 +928,29 @@ void esp_vfs_dev_uart_set_rx_line_endings(esp_line_endings_t mode) void esp_vfs_dev_uart_set_tx_line_endings(esp_line_endings_t mode) { - s_tx_mode = mode; + for (int i = 0; i < UART_NUM; ++i) { + s_tx_mode[i] = mode; + } +} + +int esp_vfs_dev_uart_port_set_rx_line_endings(int uart_num, esp_line_endings_t mode) +{ + if (uart_num < 0 || uart_num >= UART_NUM) { + errno = EBADF; + return -1; + } + s_rx_mode[uart_num] = mode; + return 0; +} + +int esp_vfs_dev_uart_port_set_tx_line_endings(int uart_num, esp_line_endings_t mode) +{ + if (uart_num < 0 || uart_num >= UART_NUM) { + errno = EBADF; + return -1; + } + s_tx_mode[uart_num] = mode; + return 0; } void esp_vfs_dev_uart_use_nonblocking(int uart_num) diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_console_main.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_console_main.c index 3e961a4f2..f4bf0edc8 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_console_main.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_console_main.c @@ -58,9 +58,9 @@ static void initialize_console(void) setvbuf(stdout, NULL, _IONBF, 0); /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */ - esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR); + esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR); /* Move the caret to the beginning of the next line on '\n' */ - esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); + esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF); /* Install UART driver for interrupt-driven reads and writes */ ESP_ERROR_CHECK( uart_driver_install(CONFIG_CONSOLE_UART_NUM, diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_console_main.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_console_main.c index 357c93636..3401aa485 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_console_main.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_console_main.c @@ -61,9 +61,9 @@ static void initialize_console(void) setvbuf(stdout, NULL, _IONBF, 0); /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */ - esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR); + esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR); /* Move the caret to the beginning of the next line on '\n' */ - esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); + esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF); /* Install UART driver for interrupt-driven reads and writes */ ESP_ERROR_CHECK( uart_driver_install(CONFIG_CONSOLE_UART_NUM, diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/main/main.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/main/main.c index 774ef90f9..95a92f2f2 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/main/main.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_wifi_coexist/main/main.c @@ -751,9 +751,9 @@ static void initialize_console(void) setvbuf(stdout, NULL, _IONBF, 0); /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */ - esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR); + esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR); /* Move the caret to the beginning of the next line on '\n' */ - esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); + esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF); /* Install UART driver for interrupt-driven reads and writes */ ESP_ERROR_CHECK( uart_driver_install(CONFIG_CONSOLE_UART_NUM, diff --git a/examples/ethernet/iperf/main/iperf_example_main.c b/examples/ethernet/iperf/main/iperf_example_main.c index 479a192fb..7d1c46b7f 100644 --- a/examples/ethernet/iperf/main/iperf_example_main.c +++ b/examples/ethernet/iperf/main/iperf_example_main.c @@ -60,9 +60,9 @@ static void initialize_console() setvbuf(stdin, NULL, _IONBF, 0); /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */ - esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR); + esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR); /* Move the caret to the beginning of the next line on '\n' */ - esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); + esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF); /* Configure UART. Note that REF_TICK is used so that the baud rate remains * correct while APB frequency is changing in light sleep mode. diff --git a/examples/peripherals/i2c/i2c_tools/main/i2ctools_example_main.c b/examples/peripherals/i2c/i2c_tools/main/i2ctools_example_main.c index 7e24968a7..278b877ee 100644 --- a/examples/peripherals/i2c/i2c_tools/main/i2ctools_example_main.c +++ b/examples/peripherals/i2c/i2c_tools/main/i2ctools_example_main.c @@ -60,9 +60,9 @@ static void initialize_console() setvbuf(stdin, NULL, _IONBF, 0); /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */ - esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR); + esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR); /* Move the caret to the beginning of the next line on '\n' */ - esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); + esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF); /* Configure UART. Note that REF_TICK is used so that the baud rate remains * correct while APB frequency is changing in light sleep mode. diff --git a/examples/protocols/asio/chat_client/components/wifi_asio.cpp b/examples/protocols/asio/chat_client/components/wifi_asio.cpp index b90ce26ae..c8d6832a3 100644 --- a/examples/protocols/asio/chat_client/components/wifi_asio.cpp +++ b/examples/protocols/asio/chat_client/components/wifi_asio.cpp @@ -124,9 +124,9 @@ extern "C" void app_main() 256, 0, 0, NULL, 0) ); /* Tell VFS to use UART driver */ esp_vfs_dev_uart_use_driver(CONFIG_CONSOLE_UART_NUM); - esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR); + esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR); /* Move the caret to the beginning of the next line on '\n' */ - esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); + esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF); // wait till we receive IP, so asio realated code can be started xEventGroupWaitBits(wifi_event_group, WIFI_CONNECTED_BIT, 1, 1, portMAX_DELAY); diff --git a/examples/protocols/asio/chat_server/components/wifi_asio.cpp b/examples/protocols/asio/chat_server/components/wifi_asio.cpp index b90ce26ae..c8d6832a3 100644 --- a/examples/protocols/asio/chat_server/components/wifi_asio.cpp +++ b/examples/protocols/asio/chat_server/components/wifi_asio.cpp @@ -124,9 +124,9 @@ extern "C" void app_main() 256, 0, 0, NULL, 0) ); /* Tell VFS to use UART driver */ esp_vfs_dev_uart_use_driver(CONFIG_CONSOLE_UART_NUM); - esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR); + esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR); /* Move the caret to the beginning of the next line on '\n' */ - esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); + esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF); // wait till we receive IP, so asio realated code can be started xEventGroupWaitBits(wifi_event_group, WIFI_CONNECTED_BIT, 1, 1, portMAX_DELAY); diff --git a/examples/protocols/asio/tcp_echo_server/components/wifi_asio.cpp b/examples/protocols/asio/tcp_echo_server/components/wifi_asio.cpp index b90ce26ae..c8d6832a3 100644 --- a/examples/protocols/asio/tcp_echo_server/components/wifi_asio.cpp +++ b/examples/protocols/asio/tcp_echo_server/components/wifi_asio.cpp @@ -124,9 +124,9 @@ extern "C" void app_main() 256, 0, 0, NULL, 0) ); /* Tell VFS to use UART driver */ esp_vfs_dev_uart_use_driver(CONFIG_CONSOLE_UART_NUM); - esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR); + esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR); /* Move the caret to the beginning of the next line on '\n' */ - esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); + esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF); // wait till we receive IP, so asio realated code can be started xEventGroupWaitBits(wifi_event_group, WIFI_CONNECTED_BIT, 1, 1, portMAX_DELAY); diff --git a/examples/protocols/asio/udp_echo_server/components/wifi_asio.cpp b/examples/protocols/asio/udp_echo_server/components/wifi_asio.cpp index b90ce26ae..c8d6832a3 100644 --- a/examples/protocols/asio/udp_echo_server/components/wifi_asio.cpp +++ b/examples/protocols/asio/udp_echo_server/components/wifi_asio.cpp @@ -124,9 +124,9 @@ extern "C" void app_main() 256, 0, 0, NULL, 0) ); /* Tell VFS to use UART driver */ esp_vfs_dev_uart_use_driver(CONFIG_CONSOLE_UART_NUM); - esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR); + esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR); /* Move the caret to the beginning of the next line on '\n' */ - esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); + esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF); // wait till we receive IP, so asio realated code can be started xEventGroupWaitBits(wifi_event_group, WIFI_CONNECTED_BIT, 1, 1, portMAX_DELAY); diff --git a/examples/protocols/asio/wifi_init/wifi_asio.cpp b/examples/protocols/asio/wifi_init/wifi_asio.cpp index b90ce26ae..c8d6832a3 100644 --- a/examples/protocols/asio/wifi_init/wifi_asio.cpp +++ b/examples/protocols/asio/wifi_init/wifi_asio.cpp @@ -124,9 +124,9 @@ extern "C" void app_main() 256, 0, 0, NULL, 0) ); /* Tell VFS to use UART driver */ esp_vfs_dev_uart_use_driver(CONFIG_CONSOLE_UART_NUM); - esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR); + esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR); /* Move the caret to the beginning of the next line on '\n' */ - esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); + esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF); // wait till we receive IP, so asio realated code can be started xEventGroupWaitBits(wifi_event_group, WIFI_CONNECTED_BIT, 1, 1, portMAX_DELAY); diff --git a/examples/system/console/main/console_example_main.c b/examples/system/console/main/console_example_main.c index ba16a9e61..b5a156d98 100644 --- a/examples/system/console/main/console_example_main.c +++ b/examples/system/console/main/console_example_main.c @@ -63,9 +63,9 @@ static void initialize_console() setvbuf(stdin, NULL, _IONBF, 0); /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */ - esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR); + esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR); /* Move the caret to the beginning of the next line on '\n' */ - esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); + esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF); /* Configure UART. Note that REF_TICK is used so that the baud rate remains * correct while APB frequency is changing in light sleep mode. diff --git a/examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c b/examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c index 3ec256a4d..e4217e623 100644 --- a/examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c +++ b/examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c @@ -56,9 +56,9 @@ static esp_err_t example_configure_stdin_stdout(void) 256, 0, 0, NULL, 0) ); /* Tell VFS to use UART driver */ esp_vfs_dev_uart_use_driver(CONFIG_CONSOLE_UART_NUM); - esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR); + esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR); /* Move the caret to the beginning of the next line on '\n' */ - esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); + esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF); return ESP_OK; } #endif diff --git a/examples/system/ota/native_ota_example/main/native_ota_example.c b/examples/system/ota/native_ota_example/main/native_ota_example.c index 744e4ef21..2d8243e76 100644 --- a/examples/system/ota/native_ota_example/main/native_ota_example.c +++ b/examples/system/ota/native_ota_example/main/native_ota_example.c @@ -67,9 +67,9 @@ static esp_err_t example_configure_stdin_stdout(void) 256, 0, 0, NULL, 0) ); /* Tell VFS to use UART driver */ esp_vfs_dev_uart_use_driver(CONFIG_CONSOLE_UART_NUM); - esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR); + esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR); /* Move the caret to the beginning of the next line on '\n' */ - esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); + esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF); return ESP_OK; } #endif diff --git a/examples/system/ota/simple_ota_example/main/simple_ota_example.c b/examples/system/ota/simple_ota_example/main/simple_ota_example.c index c06d6297c..7d0c58328 100644 --- a/examples/system/ota/simple_ota_example/main/simple_ota_example.c +++ b/examples/system/ota/simple_ota_example/main/simple_ota_example.c @@ -56,9 +56,9 @@ static esp_err_t example_configure_stdin_stdout(void) 256, 0, 0, NULL, 0) ); /* Tell VFS to use UART driver */ esp_vfs_dev_uart_use_driver(CONFIG_CONSOLE_UART_NUM); - esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR); + esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR); /* Move the caret to the beginning of the next line on '\n' */ - esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); + esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF); return ESP_OK; } #endif diff --git a/examples/wifi/iperf/main/iperf_example_main.c b/examples/wifi/iperf/main/iperf_example_main.c index 50779b3e2..de44984e9 100644 --- a/examples/wifi/iperf/main/iperf_example_main.c +++ b/examples/wifi/iperf/main/iperf_example_main.c @@ -32,9 +32,9 @@ static void initialize_console() setvbuf(stdin, NULL, _IONBF, 0); /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */ - esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR); + esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR); /* Move the caret to the beginning of the next line on '\n' */ - esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); + esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF); /* Install UART driver for interrupt-driven reads and writes */ ESP_ERROR_CHECK( uart_driver_install(CONFIG_CONSOLE_UART_NUM, diff --git a/examples/wifi/simple_sniffer/main/simple_sniffer_example_main.c b/examples/wifi/simple_sniffer/main/simple_sniffer_example_main.c index fcd01d8b6..3865f1bea 100644 --- a/examples/wifi/simple_sniffer/main/simple_sniffer_example_main.c +++ b/examples/wifi/simple_sniffer/main/simple_sniffer_example_main.c @@ -79,9 +79,9 @@ static void initialize_console() setvbuf(stdin, NULL, _IONBF, 0); /* Minicom, screen, idf_monitor send CR when ENTER key is pressed */ - esp_vfs_dev_uart_set_rx_line_endings(ESP_LINE_ENDINGS_CR); + esp_vfs_dev_uart_port_set_rx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CR); /* Move the caret to the beginning of the next line on '\n' */ - esp_vfs_dev_uart_set_tx_line_endings(ESP_LINE_ENDINGS_CRLF); + esp_vfs_dev_uart_port_set_tx_line_endings(CONFIG_CONSOLE_UART_NUM, ESP_LINE_ENDINGS_CRLF); /* Install UART driver for interrupt-driven reads and writes */ ESP_ERROR_CHECK(uart_driver_install(CONFIG_CONSOLE_UART_NUM, From c2ead692aa6595dfad9d9297ed2a9667e733997b Mon Sep 17 00:00:00 2001 From: Chen Yi Qun Date: Wed, 12 Aug 2020 17:27:11 +0800 Subject: [PATCH 16/60] bugfix(ut): fix gpio output and input mode test(backport v3.3) --- components/driver/test/test_gpio.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/components/driver/test/test_gpio.c b/components/driver/test/test_gpio.c index 4b164da44..5c9b19929 100644 --- a/components/driver/test/test_gpio.c +++ b/components/driver/test/test_gpio.c @@ -417,7 +417,7 @@ TEST_CASE("GPIO io pull up/down function", "[gpio]") TEST_CASE("GPIO output and input mode test", "[gpio][test_env=UT_T1_GPIO]") { - //connect io18 and io5 + //connect io18 and io19 gpio_config_t output_io = init_io(GPIO_OUTPUT_IO); gpio_config_t input_io = init_io(GPIO_INPUT_IO); gpio_config(&output_io); @@ -456,18 +456,12 @@ TEST_CASE("GPIO output and input mode test", "[gpio][test_env=UT_T1_GPIO]") TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(GPIO_INPUT_IO), 0, "direction GPIO_MODE_OUTPUT set error, it can't output"); // GPIO_MODE_INPUT_OUTPUT mode - // output test - level = gpio_get_level(GPIO_INPUT_IO); gpio_set_direction(GPIO_OUTPUT_IO, GPIO_MODE_INPUT_OUTPUT); gpio_set_direction(GPIO_INPUT_IO, GPIO_MODE_INPUT); - gpio_set_level(GPIO_OUTPUT_IO, !level); - TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(GPIO_INPUT_IO), !level, "direction set error, it can't output"); - // input test - gpio_set_direction(GPIO_OUTPUT_IO, GPIO_MODE_OUTPUT); - gpio_set_direction(GPIO_INPUT_IO, GPIO_MODE_INPUT_OUTPUT); - level = gpio_get_level(GPIO_INPUT_IO); - gpio_set_level(GPIO_OUTPUT_IO, !level); - TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(GPIO_INPUT_IO), !level, "direction set error, it can't output"); + gpio_set_level(GPIO_OUTPUT_IO, 1); + TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(GPIO_OUTPUT_IO), 1, "direction set error, it can't output"); + gpio_set_level(GPIO_OUTPUT_IO, 0); + TEST_ASSERT_EQUAL_INT_MESSAGE(gpio_get_level(GPIO_OUTPUT_IO), 0, "direction set error, it can't output"); } TEST_CASE("GPIO repeate call service and isr has no memory leak test","[gpio][test_env=UT_T1_GPIO][timeout=90]") From c7f33524b469e75937f003d4c06336bf4694a043 Mon Sep 17 00:00:00 2001 From: houwenxiang Date: Mon, 13 Jul 2020 12:26:54 +0800 Subject: [PATCH 17/60] driver(I2S): Fix I2S reset issue for release/v3.3 `i2s_start` reseting I2S in incorrect order causeing the word-order error. --- components/driver/i2s.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/components/driver/i2s.c b/components/driver/i2s.c index 843539593..58deb4d2f 100644 --- a/components/driver/i2s.c +++ b/components/driver/i2s.c @@ -492,6 +492,15 @@ esp_err_t i2s_set_clk(i2s_port_t i2s_num, uint32_t rate, i2s_bits_per_sample_t b rate, real_rate, bits, clkmInteger, bck, (double)I2S_BASE_CLK / mclk, real_rate*bits*channel, 64, clkmDecimals); } + if (p_i2s_obj[i2s_num]->mode & I2S_MODE_TX) { + p_i2s_obj[i2s_num]->tx->curr_ptr = NULL; + p_i2s_obj[i2s_num]->tx->rw_pos = 0; + } + if (p_i2s_obj[i2s_num]->mode & I2S_MODE_RX) { + p_i2s_obj[i2s_num]->rx->curr_ptr = NULL; + p_i2s_obj[i2s_num]->rx->rw_pos = 0; + } + I2S[i2s_num]->sample_rate_conf.tx_bits_mod = bits; I2S[i2s_num]->sample_rate_conf.rx_bits_mod = bits; @@ -673,17 +682,16 @@ esp_err_t i2s_start(i2s_port_t i2s_num) I2S_CHECK((i2s_num < I2S_NUM_MAX), "i2s_num error", ESP_ERR_INVALID_ARG); //start DMA link I2S_ENTER_CRITICAL(); - i2s_reset_fifo(i2s_num); + I2S[i2s_num]->conf.tx_reset = 1; + I2S[i2s_num]->conf.tx_reset = 0; + I2S[i2s_num]->conf.rx_reset = 1; + I2S[i2s_num]->conf.rx_reset = 0; //reset dma I2S[i2s_num]->lc_conf.in_rst = 1; I2S[i2s_num]->lc_conf.in_rst = 0; I2S[i2s_num]->lc_conf.out_rst = 1; I2S[i2s_num]->lc_conf.out_rst = 0; - - I2S[i2s_num]->conf.tx_reset = 1; - I2S[i2s_num]->conf.tx_reset = 0; - I2S[i2s_num]->conf.rx_reset = 1; - I2S[i2s_num]->conf.rx_reset = 0; + i2s_reset_fifo(i2s_num); esp_intr_disable(p_i2s_obj[i2s_num]->i2s_isr_handle); I2S[i2s_num]->int_clr.val = 0xFFFFFFFF; @@ -898,7 +906,6 @@ static esp_err_t i2s_param_config(i2s_port_t i2s_num, const i2s_config_t *i2s_co adc_power_always_on(); } // configure I2S data port interface. - i2s_reset_fifo(i2s_num); //reset i2s I2S[i2s_num]->conf.tx_reset = 1; I2S[i2s_num]->conf.tx_reset = 0; @@ -910,6 +917,7 @@ static esp_err_t i2s_param_config(i2s_port_t i2s_num, const i2s_config_t *i2s_co I2S[i2s_num]->lc_conf.in_rst = 0; I2S[i2s_num]->lc_conf.out_rst = 1; I2S[i2s_num]->lc_conf.out_rst = 0; + i2s_reset_fifo(i2s_num); //Enable and configure DMA I2S[i2s_num]->lc_conf.check_owner = 0; From 9825d0004fafc66d5e9acc6ab5799c159f268dc5 Mon Sep 17 00:00:00 2001 From: dongyou Date: Thu, 20 Aug 2020 20:02:46 +0800 Subject: [PATCH 18/60] Add IRAM_ATTR wifi_bt_common_module_enable/disable() Deleted duplicated spinlock and counter. --- .../driver/include/driver/periph_ctrl.h | 23 +++++++++ components/driver/periph_ctrl.c | 23 +++++++++ components/esp32/phy_init.c | 50 +------------------ 3 files changed, 48 insertions(+), 48 deletions(-) diff --git a/components/driver/include/driver/periph_ctrl.h b/components/driver/include/driver/periph_ctrl.h index 9689a8cb2..1d010c0c2 100644 --- a/components/driver/include/driver/periph_ctrl.h +++ b/components/driver/include/driver/periph_ctrl.h @@ -62,6 +62,29 @@ void periph_module_disable(periph_module_t periph); */ void periph_module_reset(periph_module_t periph); +/** + * @brief enable wifi bt common module + * + * @note If wifi_bt_common_module_enable is called a number of times, + * wifi_bt_common_module_disable has to be called the same number of times + * in order to put the peripheral into disabled state. + * + * @return NULL + * + */ +void wifi_bt_common_module_enable(void); + +/** + * @brief disable wifi bt common module + * + * @note If wifi_bt_common_module_enable is called a number of times, + * wifi_bt_common_module_disable has to be called the same number of times + * in order to put the peripheral into disabled state. + * + * @return NULL + * + */ +void wifi_bt_common_module_disable(void); #ifdef __cplusplus } diff --git a/components/driver/periph_ctrl.c b/components/driver/periph_ctrl.c index e877aa9b2..9083ccf95 100644 --- a/components/driver/periph_ctrl.c +++ b/components/driver/periph_ctrl.c @@ -20,6 +20,7 @@ #include "driver/periph_ctrl.h" static portMUX_TYPE periph_spinlock = portMUX_INITIALIZER_UNLOCKED; +static uint8_t ref_counts = 0; /* Static functions to return register address & mask for clk_en / rst of each peripheral */ static uint32_t get_clk_en_mask(periph_module_t periph); @@ -257,4 +258,26 @@ static uint32_t get_rst_en_reg(periph_module_t periph) } } +IRAM_ATTR void wifi_bt_common_module_enable(void) +{ + portENTER_CRITICAL_SAFE(&periph_spinlock); + if (ref_counts == 0) { + DPORT_SET_PERI_REG_MASK(DPORT_WIFI_CLK_EN_REG,DPORT_WIFI_CLK_WIFI_BT_COMMON_M); + DPORT_CLEAR_PERI_REG_MASK(DPORT_CORE_RST_EN_REG,0); + } + + ref_counts++; + portEXIT_CRITICAL_SAFE(&periph_spinlock); +} +IRAM_ATTR void wifi_bt_common_module_disable(void) +{ + portENTER_CRITICAL_SAFE(&periph_spinlock); + ref_counts--; + if (ref_counts == 0) { + DPORT_CLEAR_PERI_REG_MASK(DPORT_WIFI_CLK_EN_REG,DPORT_WIFI_CLK_WIFI_BT_COMMON_M); + DPORT_SET_PERI_REG_MASK(DPORT_CORE_RST_EN_REG,0); + } + + portEXIT_CRITICAL_SAFE(&periph_spinlock); +} \ No newline at end of file diff --git a/components/esp32/phy_init.c b/components/esp32/phy_init.c index 5968fef50..15bdff74b 100644 --- a/components/esp32/phy_init.c +++ b/components/esp32/phy_init.c @@ -52,12 +52,6 @@ static uint32_t s_module_phy_rf_init = 0; /* Whether modem sleep is turned on */ static volatile bool s_is_phy_rf_en = false; -/* Whether WiFi/BT common clock enabled reference */ -static volatile int32_t s_common_clock_enable_ref = 0; - -/* PHY spinlock mux */ -static portMUX_TYPE s_phy_spin_lock = portMUX_INITIALIZER_UNLOCKED; - /* Bit mask of modules needing to enter modem sleep mode */ static uint32_t s_modem_sleep_module_enter = 0; @@ -121,56 +115,16 @@ static inline void phy_update_wifi_mac_time(bool en_clock_stopped, int64_t now) } } -IRAM_ATTR static inline void phy_spin_lock(void) -{ - if (xPortInIsrContext()) { - portENTER_CRITICAL_ISR(&s_phy_spin_lock); - } else { - portENTER_CRITICAL(&s_phy_spin_lock); - } -} - -IRAM_ATTR static inline void phy_spin_unlock(void) -{ - if (xPortInIsrContext()) { - portEXIT_CRITICAL_ISR(&s_phy_spin_lock); - } else { - portEXIT_CRITICAL(&s_phy_spin_lock); - } -} - IRAM_ATTR void esp_phy_common_clock_enable(void) { - phy_spin_lock(); - - if (s_common_clock_enable_ref == 0) { - // Enable WiFi/BT common clock - periph_module_enable(PERIPH_WIFI_BT_COMMON_MODULE); - } - - s_common_clock_enable_ref++; - phy_spin_unlock(); + wifi_bt_common_module_enable(); } IRAM_ATTR void esp_phy_common_clock_disable(void) { - phy_spin_lock(); - - if (s_common_clock_enable_ref > 0) { - s_common_clock_enable_ref --; - - if (s_common_clock_enable_ref == 0) { - // Disable WiFi/BT common clock - periph_module_disable(PERIPH_WIFI_BT_COMMON_MODULE); - } - } else { - abort(); - } - - phy_spin_unlock(); + wifi_bt_common_module_disable(); } - esp_err_t esp_phy_rf_init(const esp_phy_init_data_t* init_data, esp_phy_calibration_mode_t mode, esp_phy_calibration_data_t* calibration_data, phy_rf_module_t module) { From 85ca89ee4a8afdf6aace0186ded9804a3ea65033 Mon Sep 17 00:00:00 2001 From: zhangyanjiao Date: Wed, 8 Jul 2020 20:44:42 +0800 Subject: [PATCH 19/60] esp_wifi: Add API to get available internal heap size --- components/esp32/esp_adapter.c | 2 +- components/esp32/include/esp_system.h | 10 ++++++++++ components/esp32/system_api.c | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/components/esp32/esp_adapter.c b/components/esp32/esp_adapter.c index ce1d1846a..915666b3d 100644 --- a/components/esp32/esp_adapter.c +++ b/components/esp32/esp_adapter.c @@ -555,7 +555,7 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._task_get_max_priority = task_get_max_priority_wrapper, ._malloc = malloc, ._free = free, - ._get_free_heap_size = esp_get_free_heap_size, + ._get_free_heap_size = esp_get_free_internal_heap_size, ._rand = esp_random, ._dport_access_stall_other_cpu_start_wrap = esp_dport_access_stall_other_cpu_start_wrap, ._dport_access_stall_other_cpu_end_wrap = esp_dport_access_stall_other_cpu_end_wrap, diff --git a/components/esp32/include/esp_system.h b/components/esp32/include/esp_system.h index 1a51999d3..845ba6076 100644 --- a/components/esp32/include/esp_system.h +++ b/components/esp32/include/esp_system.h @@ -130,6 +130,16 @@ uint32_t system_get_time(void) __attribute__ ((deprecated)); */ uint32_t esp_get_free_heap_size(void); +/** + * @brief Get the size of available internal heap. + * + * Note that the returned value may be larger than the maximum contiguous block + * which can be allocated. + * + * @return Available internal heap size, in bytes. + */ +uint32_t esp_get_free_internal_heap_size(void); + /** @cond */ /** * @brief Get the size of available heap. diff --git a/components/esp32/system_api.c b/components/esp32/system_api.c index 0dc168378..9f830e9da 100644 --- a/components/esp32/system_api.c +++ b/components/esp32/system_api.c @@ -338,6 +338,11 @@ uint32_t esp_get_free_heap_size( void ) return heap_caps_get_free_size( MALLOC_CAP_DEFAULT ); } +uint32_t esp_get_free_internal_heap_size( void ) +{ + return heap_caps_get_free_size( MALLOC_CAP_8BIT | MALLOC_CAP_DMA | MALLOC_CAP_INTERNAL ); +} + uint32_t esp_get_minimum_free_heap_size( void ) { return heap_caps_get_minimum_free_size( MALLOC_CAP_DEFAULT ); From 09113e163b0462f6d348d62167848ad49de391c9 Mon Sep 17 00:00:00 2001 From: zhangyanjiao Date: Wed, 26 Aug 2020 10:39:23 +0800 Subject: [PATCH 20/60] esp wifi bugfix: 1. Fix TX DMA buffer issue 2. API esp_wifi_get_config add acquisition sta.listen_interval 3. Configure bandwidth and phy mode to store NVS 4. If AP's tsf has been restarted, STA will disconnect from AP. 5. Do not reset softAP's tsf except it restart 6. Fix the wifi regdomain update bug 7. Fix the bug for airkiss find hidden AP fail 8. Fix addba and first ampdu send bar 9. Fix WiFi fragment issue 10. Fix WiFi fragment issue --- components/esp32/include/esp_wifi_types.h | 1 + components/esp32/lib | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/components/esp32/include/esp_wifi_types.h b/components/esp32/include/esp_wifi_types.h index c838c3eef..f7786f5a0 100644 --- a/components/esp32/include/esp_wifi_types.h +++ b/components/esp32/include/esp_wifi_types.h @@ -93,6 +93,7 @@ typedef enum { WIFI_REASON_ASSOC_FAIL = 203, WIFI_REASON_HANDSHAKE_TIMEOUT = 204, WIFI_REASON_CONNECTION_FAIL = 205, + WIFI_REASON_AP_TSF_RESET = 206, } wifi_err_reason_t; typedef enum { diff --git a/components/esp32/lib b/components/esp32/lib index d615eeaad..d376d65d8 160000 --- a/components/esp32/lib +++ b/components/esp32/lib @@ -1 +1 @@ -Subproject commit d615eeaadf55960eee64f44ca53fe0d50813dda1 +Subproject commit d376d65d84f363418db58d8a78545b73ffb91de7 From 8fb47ab0c2e9e65d749cabd6f95e7e2e707e09ab Mon Sep 17 00:00:00 2001 From: weitianhua Date: Thu, 16 Jul 2020 14:47:11 +0800 Subject: [PATCH 21/60] Seperate BTA_JV_L2CAP for less bin size --- .../bt/bluedroid/bta/include/bta/bta_jv_api.h | 65 ++++++++++--------- components/bt/bluedroid/bta/jv/bta_jv_act.c | 39 ++++++----- components/bt/bluedroid/bta/jv/bta_jv_api.c | 2 + components/bt/bluedroid/bta/jv/bta_jv_main.c | 4 ++ .../bt/bluedroid/bta/jv/include/bta_jv_int.h | 20 +++++- .../common/include/common/bt_target.h | 28 +++++--- 6 files changed, 102 insertions(+), 56 deletions(-) diff --git a/components/bt/bluedroid/bta/include/bta/bta_jv_api.h b/components/bt/bluedroid/bta/include/bta/bta_jv_api.h index bf23aab4e..7cbf0405c 100644 --- a/components/bt/bluedroid/bta/include/bta/bta_jv_api.h +++ b/components/bt/bluedroid/bta/include/bta/bta_jv_api.h @@ -134,6 +134,7 @@ typedef UINT8 tBTA_JV_CONN_STATE; #define BTA_JV_DISCOVERY_COMP_EVT 8 /* SDP discovery complete */ #define BTA_JV_CREATE_RECORD_EVT 11 /* the result for BTA_JvCreateRecord */ /* events received by tBTA_JV_L2CAP_CBACK */ +#if BTA_JV_L2CAP_INCLUDED #define BTA_JV_L2CAP_OPEN_EVT 16 /* open status of L2CAP connection */ #define BTA_JV_L2CAP_CLOSE_EVT 17 /* L2CAP connection closed */ #define BTA_JV_L2CAP_START_EVT 18 /* L2CAP server started */ @@ -144,6 +145,7 @@ typedef UINT8 tBTA_JV_CONN_STATE; #define BTA_JV_L2CAP_RECEIVE_EVT 23 /* the result for BTA_JvL2capReceive*/ #define BTA_JV_L2CAP_WRITE_EVT 24 /* the result for BTA_JvL2capWrite*/ #define BTA_JV_L2CAP_WRITE_FIXED_EVT 25 /* the result for BTA_JvL2capWriteFixed */ +#endif /* BTA_JV_L2CAP_INCLUDED */ /* events received by tBTA_JV_RFCOMM_CBACK */ #define BTA_JV_RFCOMM_OPEN_EVT 26 /* open status of RFCOMM Client connection */ @@ -178,6 +180,7 @@ typedef struct { UINT32 handle; /* The SDP handle */ } tBTA_JV_CREATE_RECORD; +#if BTA_JV_L2CAP_INCLUDED /* data associated with BTA_JV_L2CAP_OPEN_EVT */ typedef struct { tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */ @@ -186,18 +189,6 @@ typedef struct { INT32 tx_mtu; /* The transmit MTU */ } tBTA_JV_L2CAP_OPEN; -/* data associated with BTA_JV_L2CAP_OPEN_EVT for LE sockets */ -typedef struct { - tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */ - UINT32 handle; /* The connection handle */ - BD_ADDR rem_bda; /* The peer address */ - INT32 tx_mtu; /* The transmit MTU */ - void **p_p_cback; /* set them for new socket */ - void **p_user_data;/* set them for new socket */ - -} tBTA_JV_L2CAP_LE_OPEN; - - /* data associated with BTA_JV_L2CAP_CLOSE_EVT */ typedef struct { tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */ @@ -255,6 +246,22 @@ typedef struct { BOOLEAN cong; /* congestion status */ } tBTA_JV_L2CAP_WRITE; +/* data associated with BTA_JV_L2CAP_OPEN_EVT for LE sockets */ +typedef struct { + tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */ + UINT32 handle; /* The connection handle */ + BD_ADDR rem_bda; /* The peer address */ + INT32 tx_mtu; /* The transmit MTU */ + void **p_p_cback; /* set them for new socket */ + void **p_user_data;/* set them for new socket */ + +} tBTA_JV_L2CAP_LE_OPEN; + +/*data associated with BTA_JV_L2CAP_DATA_IND_EVT if used for LE */ +typedef struct { + UINT32 handle; /* The connection handle */ + BT_HDR *p_buf; /* The incoming data */ +} tBTA_JV_LE_DATA_IND; /* data associated with BTA_JV_L2CAP_WRITE_FIXED_EVT */ typedef struct { @@ -265,6 +272,7 @@ typedef struct { UINT16 len; /* The length of the data written. */ BOOLEAN cong; /* congestion status */ } tBTA_JV_L2CAP_WRITE_FIXED; +#endif /* BTA_JV_L2CAP_INCLUDED */ /* data associated with BTA_JV_RFCOMM_OPEN_EVT */ typedef struct { @@ -272,6 +280,7 @@ typedef struct { UINT32 handle; /* The connection handle */ BD_ADDR rem_bda; /* The peer address */ } tBTA_JV_RFCOMM_OPEN; + /* data associated with BTA_JV_RFCOMM_SRV_OPEN_EVT */ typedef struct { tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */ @@ -280,7 +289,6 @@ typedef struct { BD_ADDR rem_bda; /* The peer address */ } tBTA_JV_RFCOMM_SRV_OPEN; - /* data associated with BTA_JV_RFCOMM_CLOSE_EVT */ typedef struct { tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */ @@ -304,19 +312,13 @@ typedef struct { UINT8 sec_id; /* security ID used by this client */ BOOLEAN use_co; /* TRUE to use co_rfc_data */ } tBTA_JV_RFCOMM_CL_INIT; + /*data associated with BTA_JV_L2CAP_DATA_IND_EVT & BTA_JV_RFCOMM_DATA_IND_EVT */ typedef struct { UINT32 handle; /* The connection handle */ BT_HDR *p_buf; /* The incoming data */ } tBTA_JV_DATA_IND; -/*data associated with BTA_JV_L2CAP_DATA_IND_EVT if used for LE */ -typedef struct { - UINT32 handle; /* The connection handle */ - BT_HDR *p_buf; /* The incoming data */ -} tBTA_JV_LE_DATA_IND; - - /* data associated with BTA_JV_RFCOMM_CONG_EVT */ typedef struct { tBTA_JV_STATUS status; /* Whether the operation succeeded or failed. */ @@ -365,6 +367,7 @@ typedef union { UINT8 scn; /* BTA_JV_GET_SCN_EVT */ UINT16 psm; /* BTA_JV_GET_PSM_EVT */ tBTA_JV_CREATE_RECORD create_rec; /* BTA_JV_CREATE_RECORD_EVT */ +#if BTA_JV_L2CAP_INCLUDED tBTA_JV_L2CAP_OPEN l2c_open; /* BTA_JV_L2CAP_OPEN_EVT */ tBTA_JV_L2CAP_CLOSE l2c_close; /* BTA_JV_L2CAP_CLOSE_EVT */ tBTA_JV_L2CAP_START l2c_start; /* BTA_JV_L2CAP_START_EVT */ @@ -372,6 +375,7 @@ typedef union { tBTA_JV_L2CAP_CONG l2c_cong; /* BTA_JV_L2CAP_CONG_EVT */ tBTA_JV_L2CAP_READ l2c_read; /* BTA_JV_L2CAP_READ_EVT */ tBTA_JV_L2CAP_WRITE l2c_write; /* BTA_JV_L2CAP_WRITE_EVT */ +#endif /* BTA_JV_L2CAP_INCLUDED */ tBTA_JV_RFCOMM_OPEN rfc_open; /* BTA_JV_RFCOMM_OPEN_EVT */ tBTA_JV_RFCOMM_SRV_OPEN rfc_srv_open; /* BTA_JV_RFCOMM_SRV_OPEN_EVT */ tBTA_JV_RFCOMM_CLOSE rfc_close; /* BTA_JV_RFCOMM_CLOSE_EVT */ @@ -382,9 +386,11 @@ typedef union { tBTA_JV_RFCOMM_WRITE rfc_write; /* BTA_JV_RFCOMM_WRITE_EVT */ tBTA_JV_DATA_IND data_ind; /* BTA_JV_L2CAP_DATA_IND_EVT BTA_JV_RFCOMM_DATA_IND_EVT */ - tBTA_JV_LE_DATA_IND le_data_ind; /* BTA_JV_L2CAP_LE_DATA_IND_EVT */ +#if BTA_JV_L2CAP_INCLUDED tBTA_JV_L2CAP_LE_OPEN l2c_le_open; /* BTA_JV_L2CAP_OPEN_EVT */ + tBTA_JV_LE_DATA_IND le_data_ind; /* BTA_JV_L2CAP_LE_DATA_IND_EVT */ tBTA_JV_L2CAP_WRITE_FIXED l2c_write_fixed; /* BTA_JV_L2CAP_WRITE_FIXED_EVT */ +#endif } tBTA_JV; /* JAVA DM Interface callback */ @@ -393,8 +399,10 @@ typedef void (tBTA_JV_DM_CBACK)(tBTA_JV_EVT event, tBTA_JV *p_data, void *user_d /* JAVA RFCOMM interface callback */ typedef void *(tBTA_JV_RFCOMM_CBACK)(tBTA_JV_EVT event, tBTA_JV *p_data, void *user_data); +#if BTA_JV_L2CAP_INCLUDED /* JAVA L2CAP interface callback */ typedef void (tBTA_JV_L2CAP_CBACK)(tBTA_JV_EVT event, tBTA_JV *p_data, void *user_Data); +#endif /* BTA_JV_L2CAP_INCLUDED */ /* JV configuration structure */ typedef struct { @@ -532,6 +540,7 @@ extern tBTA_JV_STATUS BTA_JvCreateRecordByUser(const char *name, UINT32 channel, *******************************************************************************/ extern tBTA_JV_STATUS BTA_JvDeleteRecord(UINT32 handle); +#if BTA_JV_L2CAP_INCLUDED /******************************************************************************* ** ** Function BTA_JvL2capConnectLE @@ -739,6 +748,7 @@ extern tBTA_JV_STATUS BTA_JvL2capWrite(UINT32 handle, UINT32 req_id, extern tBTA_JV_STATUS BTA_JvL2capWriteFixed(UINT16 channel, BD_ADDR *addr, UINT32 req_id, tBTA_JV_L2CAP_CBACK *p_cback, UINT8 *p_data, UINT16 len, void *user_data); +#endif /* BTA_JV_L2CAP_INCLUDED */ /******************************************************************************* ** @@ -786,9 +796,9 @@ extern tBTA_JV_STATUS BTA_JvRfcommClose(UINT32 handle, void *user_data); ** BTA_JV_FAILURE, otherwise. ** *******************************************************************************/ -extern tBTA_JV_STATUS BTA_JvRfcommStartServer(tBTA_SEC sec_mask, - tBTA_JV_ROLE role, UINT8 local_scn, UINT8 max_session, - tBTA_JV_RFCOMM_CBACK *p_cback, void *user_data); +extern tBTA_JV_STATUS BTA_JvRfcommStartServer(tBTA_SEC sec_mask, tBTA_JV_ROLE role, + UINT8 local_scn, UINT8 max_session, + tBTA_JV_RFCOMM_CBACK *p_cback, void *user_data); /******************************************************************************* ** @@ -815,8 +825,7 @@ extern tBTA_JV_STATUS BTA_JvRfcommStopServer(UINT32 handle, void *user_data); ** BTA_JV_FAILURE, otherwise. ** *******************************************************************************/ -extern tBTA_JV_STATUS BTA_JvRfcommRead(UINT32 handle, UINT32 req_id, - UINT8 *p_data, UINT16 len); +extern tBTA_JV_STATUS BTA_JvRfcommRead(UINT32 handle, UINT32 req_id, UINT8 *p_data, UINT16 len); /******************************************************************************* ** @@ -843,7 +852,6 @@ extern tBTA_JV_STATUS BTA_JvRfcommReady(UINT32 handle, UINT32 *p_data_size); ** BTA_JV_FAILURE, otherwise. ** *******************************************************************************/ -// extern tBTA_JV_STATUS BTA_JvRfcommWrite(UINT32 handle, UINT32 req_id); extern tBTA_JV_STATUS BTA_JvRfcommWrite(UINT32 handle, UINT32 req_id, int len, UINT8 *p_data); /******************************************************************************* @@ -865,8 +873,7 @@ extern tBTA_JV_STATUS BTA_JvRfcommWrite(UINT32 handle, UINT32 req_id, int len, U ** BTA_JV_CONN_CLOSE to remove in case of connection close! ** *******************************************************************************/ -extern tBTA_JV_STATUS BTA_JvSetPmProfile(UINT32 handle, tBTA_JV_PM_ID app_id, - tBTA_JV_CONN_STATE init_st); +extern tBTA_JV_STATUS BTA_JvSetPmProfile(UINT32 handle, tBTA_JV_PM_ID app_id, tBTA_JV_CONN_STATE init_st); /******************************************************************************* ** diff --git a/components/bt/bluedroid/bta/jv/bta_jv_act.c b/components/bt/bluedroid/bta/jv/bta_jv_act.c index ecef90b12..33132fe7f 100644 --- a/components/bt/bluedroid/bta/jv/bta_jv_act.c +++ b/components/bt/bluedroid/bta/jv/bta_jv_act.c @@ -48,6 +48,7 @@ #if (defined BTA_JV_INCLUDED && BTA_JV_INCLUDED == TRUE) +#if BTA_JV_L2CAP_INCLUDED /* one of these exists for each client */ struct fc_client { struct fc_client *next_all_list; @@ -92,11 +93,10 @@ static void __attribute__((unused)) fc_init(void) pthread_once(&fc_init_once, fc_init_work); } - static void fcchan_conn_chng_cbk(UINT16 chan, BD_ADDR bd_addr, BOOLEAN connected, UINT16 reason, tBT_TRANSPORT ); static void fcchan_data_cbk(UINT16 chan, BD_ADDR bd_addr, BT_HDR *p_buf); - +#endif /* BTA_JV_L2CAP_INCLUDED */ extern void uuid_to_string_legacy(bt_uuid_t *p_uuid, char *str); static inline void logu(const char *title, const uint8_t *p_uuid) @@ -112,8 +112,7 @@ static tBTA_JV_STATUS bta_jv_free_set_pm_profile_cb(UINT32 jv_handle); static void bta_jv_pm_conn_busy(tBTA_JV_PM_CB *p_cb); static void bta_jv_pm_conn_idle(tBTA_JV_PM_CB *p_cb); static void bta_jv_pm_state_change(tBTA_JV_PM_CB *p_cb, const tBTA_JV_CONN_STATE state); -tBTA_JV_STATUS bta_jv_set_pm_conn_state(tBTA_JV_PM_CB *p_cb, const tBTA_JV_CONN_STATE - new_st); +tBTA_JV_STATUS bta_jv_set_pm_conn_state(tBTA_JV_PM_CB *p_cb, const tBTA_JV_CONN_STATE new_st); /******************************************************************************* ** @@ -377,6 +376,7 @@ static tBTA_JV_STATUS bta_jv_free_rfc_cb(tBTA_JV_RFC_CB *p_cb, tBTA_JV_PCB *p_pc return status; } +#if BTA_JV_L2CAP_INCLUDED /******************************************************************************* ** ** Function bta_jv_free_l2c_cb @@ -402,6 +402,7 @@ tBTA_JV_STATUS bta_jv_free_l2c_cb(tBTA_JV_L2C_CB *p_cb) p_cb->p_cback = NULL; return status; } +#endif /* BTA_JV_L2CAP_INCLUDED */ /******************************************************************************* ** @@ -456,10 +457,9 @@ static tBTA_JV_STATUS bta_jv_free_set_pm_profile_cb(UINT32 jv_handle) } } - APPL_TRACE_API("%s(jv_handle: 0x%2x), idx: %d, " - "app_id: 0x%x", __func__, jv_handle, i, bta_jv_cb.pm_cb[i].app_id); - APPL_TRACE_API("%s, bd_counter = %d, " - "appid_counter = %d", __func__, bd_counter, appid_counter); + APPL_TRACE_API("%s(jv_handle: 0x%2x), idx: %d, app_id: 0x%x", __func__, jv_handle, i, bta_jv_cb.pm_cb[i].app_id); + APPL_TRACE_API("%s, bd_counter = %d, appid_counter = %d", __func__, bd_counter, appid_counter); + if (bd_counter > 1) { bta_jv_pm_conn_idle(&bta_jv_cb.pm_cb[i]); } @@ -478,14 +478,15 @@ static tBTA_JV_STATUS bta_jv_free_set_pm_profile_cb(UINT32 jv_handle) tBTA_JV_PCB *p_pcb = bta_jv_rfc_port_to_pcb(bta_jv_cb.rfc_cb[hi].rfc_hdl[si]); if (p_pcb) { if (NULL == p_pcb->p_pm_cb) { - APPL_TRACE_WARNING("%s(jv_handle:" - " 0x%x):port_handle: 0x%x, p_pm_cb: %d: no link to " - "pm_cb?", __func__, jv_handle, p_pcb->port_handle, i); + APPL_TRACE_WARNING("%s(jv_handle: 0x%x):port_handle: 0x%x, p_pm_cb: %d: no link to pm_cb?", + __func__, jv_handle, p_pcb->port_handle, i); } p_cb = &p_pcb->p_pm_cb; } } - } else { + } +#if BTA_JV_L2CAP_INCLUDED + else { if (jv_handle < BTA_JV_MAX_L2C_CONN) { tBTA_JV_L2C_CB *p_l2c_cb = &bta_jv_cb.l2c_cb[jv_handle]; if (NULL == p_l2c_cb->p_pm_cb) { @@ -495,6 +496,8 @@ static tBTA_JV_STATUS bta_jv_free_set_pm_profile_cb(UINT32 jv_handle) p_cb = &p_l2c_cb->p_pm_cb; } } +#endif /* BTA_JV_L2CAP_INCLUDED */ + if (p_cb) { *p_cb = NULL; status = BTA_JV_SUCCESS; @@ -537,7 +540,9 @@ static tBTA_JV_PM_CB *bta_jv_alloc_set_pm_profile_cb(UINT32 jv_handle, tBTA_JV_P break; } } - } else { + } +#if BTA_JV_L2CAP_INCLUDED + else { /* use jv handle for l2cap bd address retrieval */ for (j = 0; j < BTA_JV_MAX_L2C_CONN; j++) { if (jv_handle == bta_jv_cb.l2c_cb[j].handle) { @@ -552,6 +557,7 @@ static tBTA_JV_PM_CB *bta_jv_alloc_set_pm_profile_cb(UINT32 jv_handle, tBTA_JV_P } } } +#endif /* BTA_JV_L2CAP_INCLUDED */ APPL_TRACE_API("bta_jv_alloc_set_pm_profile_cb(handle 0x%2x, app_id %d): " "idx: %d, (BTA_JV_PM_MAX_NUM: %d), pp_cb: %p", jv_handle, app_id, i, BTA_JV_PM_MAX_NUM, (void *)pp_cb); @@ -634,7 +640,6 @@ BOOLEAN bta_jv_check_psm(UINT16 psm) } } return ret; - } /******************************************************************************* @@ -1092,6 +1097,7 @@ void bta_jv_delete_record(tBTA_JV_MSG *p_data) } } +#if BTA_JV_L2CAP_INCLUDED /******************************************************************************* ** ** Function bta_jv_l2cap_client_cback @@ -1517,6 +1523,7 @@ void bta_jv_l2cap_write_fixed(tBTA_JV_MSG *p_data) ls->p_cback(BTA_JV_L2CAP_WRITE_FIXED_EVT, (tBTA_JV *)&evt_data, ls->user_data); } +#endif /* BTA_JV_L2CAP_INCLUDED */ /******************************************************************************* ** @@ -2351,7 +2358,7 @@ static void bta_jv_pm_state_change(tBTA_JV_PM_CB *p_cb, const tBTA_JV_CONN_STATE } /**********************************************************************************************/ - +#if BTA_JV_L2CAP_INCLUDED static struct fc_channel *fcchan_get(uint16_t chan, char create) { struct fc_channel *t = fc_channels; @@ -2791,6 +2798,6 @@ extern void bta_jv_l2cap_close_fixed (tBTA_JV_MSG *p_data) fcclient_free(t); } } - +#endif /* BTA_JV_L2CAP_INCLUDED */ #endif ///defined BTA_JV_INCLUDED && BTA_JV_INCLUDED == TRUE diff --git a/components/bt/bluedroid/bta/jv/bta_jv_api.c b/components/bt/bluedroid/bta/jv/bta_jv_api.c index 5430d36bc..5cb5d8706 100644 --- a/components/bt/bluedroid/bta/jv/bta_jv_api.c +++ b/components/bt/bluedroid/bta/jv/bta_jv_api.c @@ -310,6 +310,7 @@ tBTA_JV_STATUS BTA_JvDeleteRecord(UINT32 handle) return (status); } +#if BTA_JV_L2CAP_INCLUDED /******************************************************************************* ** ** Function BTA_JvL2capConnectLE @@ -823,6 +824,7 @@ tBTA_JV_STATUS BTA_JvL2capWriteFixed(UINT16 channel, BD_ADDR *addr, UINT32 req_i return (status); } +#endif /* BTA_JV_L2CAP_INCLUDED */ /******************************************************************************* ** diff --git a/components/bt/bluedroid/bta/jv/bta_jv_main.c b/components/bt/bluedroid/bta/jv/bta_jv_main.c index 9523d6e89..ec13d73ba 100644 --- a/components/bt/bluedroid/bta/jv/bta_jv_main.c +++ b/components/bt/bluedroid/bta/jv/bta_jv_main.c @@ -52,12 +52,14 @@ const tBTA_JV_ACTION bta_jv_action[] = { bta_jv_start_discovery, /* BTA_JV_API_START_DISCOVERY_EVT */ bta_jv_create_record, /* BTA_JV_API_CREATE_RECORD_EVT */ bta_jv_delete_record, /* BTA_JV_API_DELETE_RECORD_EVT */ +#if BTA_JV_L2CAP_INCLUDED bta_jv_l2cap_connect, /* BTA_JV_API_L2CAP_CONNECT_EVT */ bta_jv_l2cap_close, /* BTA_JV_API_L2CAP_CLOSE_EVT */ bta_jv_l2cap_start_server, /* BTA_JV_API_L2CAP_START_SERVER_EVT */ bta_jv_l2cap_stop_server, /* BTA_JV_API_L2CAP_STOP_SERVER_EVT */ bta_jv_l2cap_read, /* BTA_JV_API_L2CAP_READ_EVT */ bta_jv_l2cap_write, /* BTA_JV_API_L2CAP_WRITE_EVT */ +#endif /* BTA_JV_L2CAP_INCLUDED */ bta_jv_rfcomm_connect, /* BTA_JV_API_RFCOMM_CONNECT_EVT */ bta_jv_rfcomm_close, /* BTA_JV_API_RFCOMM_CLOSE_EVT */ bta_jv_rfcomm_start_server, /* BTA_JV_API_RFCOMM_START_SERVER_EVT */ @@ -66,11 +68,13 @@ const tBTA_JV_ACTION bta_jv_action[] = { bta_jv_rfcomm_write, /* BTA_JV_API_RFCOMM_WRITE_EVT */ bta_jv_set_pm_profile, /* BTA_JV_API_SET_PM_PROFILE_EVT */ bta_jv_change_pm_state, /* BTA_JV_API_PM_STATE_CHANGE_EVT */ +#if BTA_JV_L2CAP_INCLUDED bta_jv_l2cap_connect_le, /* BTA_JV_API_L2CAP_CONNECT_LE_EVT */ bta_jv_l2cap_start_server_le, /* BTA_JV_API_L2CAP_START_SERVER_LE_EVT */ bta_jv_l2cap_stop_server_le, /* BTA_JV_API_L2CAP_STOP_SERVER_LE_EVT */ bta_jv_l2cap_write_fixed, /* BTA_JV_API_L2CAP_WRITE_FIXED_EVT */ bta_jv_l2cap_close_fixed, /* BTA_JV_API_L2CAP_CLOSE_FIXED_EVT */ +#endif /* BTA_JV_L2CAP_INCLUDED */ }; /******************************************************************************* diff --git a/components/bt/bluedroid/bta/jv/include/bta_jv_int.h b/components/bt/bluedroid/bta/jv/include/bta_jv_int.h index c25263314..a822de007 100644 --- a/components/bt/bluedroid/bta/jv/include/bta_jv_int.h +++ b/components/bt/bluedroid/bta/jv/include/bta_jv_int.h @@ -48,12 +48,14 @@ enum { BTA_JV_API_START_DISCOVERY_EVT, BTA_JV_API_CREATE_RECORD_EVT, BTA_JV_API_DELETE_RECORD_EVT, +#if BTA_JV_L2CAP_INCLUDED BTA_JV_API_L2CAP_CONNECT_EVT, BTA_JV_API_L2CAP_CLOSE_EVT, BTA_JV_API_L2CAP_START_SERVER_EVT, BTA_JV_API_L2CAP_STOP_SERVER_EVT, BTA_JV_API_L2CAP_READ_EVT, BTA_JV_API_L2CAP_WRITE_EVT, +#endif /* BTA_JV_L2CAP_INCLUDED */ BTA_JV_API_RFCOMM_CONNECT_EVT, BTA_JV_API_RFCOMM_CLOSE_EVT, BTA_JV_API_RFCOMM_START_SERVER_EVT, @@ -62,11 +64,13 @@ enum { BTA_JV_API_RFCOMM_WRITE_EVT, BTA_JV_API_SET_PM_PROFILE_EVT, BTA_JV_API_PM_STATE_CHANGE_EVT, +#if BTA_JV_L2CAP_INCLUDED BTA_JV_API_L2CAP_CONNECT_LE_EVT, BTA_JV_API_L2CAP_START_SERVER_LE_EVT, BTA_JV_API_L2CAP_STOP_SERVER_LE_EVT, BTA_JV_API_L2CAP_WRITE_FIXED_EVT, BTA_JV_API_L2CAP_CLOSE_FIXED_EVT, +#endif /* BTA_JV_L2CAP_INCLUDED */ BTA_JV_MAX_INT_EVT }; @@ -115,6 +119,8 @@ enum { BTA_JV_ST_SR_CLOSING } ; typedef UINT8 tBTA_JV_STATE; + +#if BTA_JV_L2CAP_INCLUDED #define BTA_JV_ST_CL_MAX BTA_JV_ST_CL_CLOSING /* JV L2CAP control block */ typedef struct { @@ -127,6 +133,7 @@ typedef struct { tBTA_JV_PM_CB *p_pm_cb; /* ptr to pm control block, NULL: unused */ void *user_data; /* user data for callback from higher layers */ } tBTA_JV_L2C_CB; +#endif /* BTA_JV_L2CAP_INCLUDED */ #define BTA_JV_RFC_HDL_MASK 0xFF #define BTA_JV_RFCOMM_MASK 0x80 @@ -156,6 +163,7 @@ typedef struct { int curr_sess; /* current sessions count*/ } tBTA_JV_RFC_CB; +#if BTA_JV_L2CAP_INCLUDED /* data type for BTA_JV_API_L2CAP_CONNECT_EVT & BTA_JV_API_L2CAP_CONNECT_LE_EVT */ typedef struct { BT_HDR hdr; @@ -233,6 +241,7 @@ typedef struct { UINT16 len; void *user_data; } tBTA_JV_API_L2CAP_WRITE_FIXED; +#endif /* BTA_JV_L2CAP_INCLUDED */ /* data type for BTA_JV_API_RFCOMM_CONNECT_EVT */ typedef struct { @@ -345,11 +354,14 @@ typedef union { tBTA_JV_API_FREE_CHANNEL free_channel; tBTA_JV_API_CREATE_RECORD create_record; tBTA_JV_API_ADD_ATTRIBUTE add_attr; +#if BTA_JV_L2CAP_INCLUDED tBTA_JV_API_L2CAP_CONNECT l2cap_connect; tBTA_JV_API_L2CAP_READ l2cap_read; tBTA_JV_API_L2CAP_WRITE l2cap_write; tBTA_JV_API_L2CAP_CLOSE l2cap_close; tBTA_JV_API_L2CAP_SERVER l2cap_server; + tBTA_JV_API_L2CAP_WRITE_FIXED l2cap_write_fixed; +#endif /* BTA_JV_L2CAP_INCLUDED */ tBTA_JV_API_RFCOMM_CONNECT rfcomm_connect; tBTA_JV_API_RFCOMM_READ rfcomm_read; tBTA_JV_API_RFCOMM_WRITE rfcomm_write; @@ -357,7 +369,6 @@ typedef union { tBTA_JV_API_PM_STATE_CHANGE change_pm_state; tBTA_JV_API_RFCOMM_CLOSE rfcomm_close; tBTA_JV_API_RFCOMM_SERVER rfcomm_server; - tBTA_JV_API_L2CAP_WRITE_FIXED l2cap_write_fixed; } tBTA_JV_MSG; /* JV control block */ @@ -368,7 +379,9 @@ typedef struct { UINT32 sdp_handle[BTA_JV_MAX_SDP_REC]; /* SDP records created */ UINT8 *p_sel_raw_data;/* the raw data of last service select */ tBTA_JV_DM_CBACK *p_dm_cback; +#if BTA_JV_L2CAP_INCLUDED tBTA_JV_L2C_CB l2c_cb[BTA_JV_MAX_L2C_CONN]; /* index is GAP handle (index) */ +#endif /* BTA_JV_L2CAP_INCLUDED */ tBTA_JV_RFC_CB rfc_cb[BTA_JV_MAX_RFC_CONN]; tBTA_JV_PCB port_cb[MAX_RFC_PORTS]; /* index of this array is the port_handle, */ @@ -407,12 +420,14 @@ extern void bta_jv_free_scn (tBTA_JV_MSG *p_data); extern void bta_jv_start_discovery (tBTA_JV_MSG *p_data); extern void bta_jv_create_record (tBTA_JV_MSG *p_data); extern void bta_jv_delete_record (tBTA_JV_MSG *p_data); +#if BTA_JV_L2CAP_INCLUDED extern void bta_jv_l2cap_connect (tBTA_JV_MSG *p_data); extern void bta_jv_l2cap_close (tBTA_JV_MSG *p_data); extern void bta_jv_l2cap_start_server (tBTA_JV_MSG *p_data); extern void bta_jv_l2cap_stop_server (tBTA_JV_MSG *p_data); extern void bta_jv_l2cap_read (tBTA_JV_MSG *p_data); extern void bta_jv_l2cap_write (tBTA_JV_MSG *p_data); +#endif /* BTA_JV_L2CAP_INCLUDED */ extern void bta_jv_rfcomm_connect (tBTA_JV_MSG *p_data); extern void bta_jv_rfcomm_close (tBTA_JV_MSG *p_data); extern void bta_jv_rfcomm_start_server (tBTA_JV_MSG *p_data); @@ -421,11 +436,12 @@ extern void bta_jv_rfcomm_read (tBTA_JV_MSG *p_data); extern void bta_jv_rfcomm_write (tBTA_JV_MSG *p_data); extern void bta_jv_set_pm_profile (tBTA_JV_MSG *p_data); extern void bta_jv_change_pm_state(tBTA_JV_MSG *p_data); +#if BTA_JV_L2CAP_INCLUDED extern void bta_jv_l2cap_connect_le (tBTA_JV_MSG *p_data); extern void bta_jv_l2cap_start_server_le (tBTA_JV_MSG *p_data); extern void bta_jv_l2cap_stop_server_le (tBTA_JV_MSG *p_data); extern void bta_jv_l2cap_write_fixed (tBTA_JV_MSG *p_data); extern void bta_jv_l2cap_close_fixed (tBTA_JV_MSG *p_data); - +#endif /* BTA_JV_L2CAP_INCLUDED */ #endif ///defined BTA_JV_INCLUDED && BTA_JV_INCLUDED == TRUE #endif /* BTA_JV_INT_H */ diff --git a/components/bt/bluedroid/common/include/common/bt_target.h b/components/bt/bluedroid/common/include/common/bt_target.h index 4504e0cd8..00b4c6072 100644 --- a/components/bt/bluedroid/common/include/common/bt_target.h +++ b/components/bt/bluedroid/common/include/common/bt_target.h @@ -96,6 +96,12 @@ #endif /* #if CONFIG_CLASSIC_BT_ENABLED */ +/* This is set to enable use of GAP L2CAP connections. */ +#if (VND_BT_JV_BTA_L2CAP == TRUE) +#define BTA_JV_L2CAP_INCLUDED TRUE +#define GAP_CONN_INCLUDED TRUE +#endif /* VND_BT_JV_BTA_L2CAP */ + #ifndef CLASSIC_BT_INCLUDED #define CLASSIC_BT_INCLUDED FALSE #endif /* CLASSIC_BT_INCLUDED */ @@ -293,6 +299,19 @@ #define BTA_SDP_INCLUDED FALSE #endif +/* This is set to enable use of GAP L2CAP connections. */ +#ifndef VND_BT_JV_BTA_L2CAP +#define VND_BT_JV_BTA_L2CAP FALSE +#endif + +#ifndef BTA_JV_L2CAP_INCLUDED +#define BTA_JV_L2CAP_INCLUDED FALSE +#endif + +#ifndef GAP_CONN_INCLUDED +#define GAP_CONN_INCLUDED FALSE +#endif + /****************************************************************************** ** ** Stack-layer components @@ -1710,15 +1729,6 @@ Range: 2 octets #define GAP_INCLUDED TRUE #endif -/* This is set to enable use of GAP L2CAP connections. */ -#ifndef GAP_CONN_INCLUDED -#if (GAP_INCLUDED == TRUE && CLASSIC_BT_INCLUDED == TRUE) -#define GAP_CONN_INCLUDED TRUE -#else -#define GAP_CONN_INCLUDED FALSE -#endif -#endif - /* This is set to enable posting event for data write */ #ifndef GAP_CONN_POST_EVT_INCLUDED #define GAP_CONN_POST_EVT_INCLUDED FALSE From 33546a0094567f87923c8b94adfc9d4588f2136c Mon Sep 17 00:00:00 2001 From: weitianhua Date: Thu, 16 Jul 2020 14:49:24 +0800 Subject: [PATCH 22/60] Fix tsk watchdog when running spp vfs demo --- .../bt_spp_vfs_acceptor/main/example_spp_vfs_acceptor_demo.c | 3 +++ .../bt_spp_vfs_initiator/main/example_spp_vfs_initiator_demo.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/examples/bluetooth/bt_spp_vfs_acceptor/main/example_spp_vfs_acceptor_demo.c b/examples/bluetooth/bt_spp_vfs_acceptor/main/example_spp_vfs_acceptor_demo.c index fdd75cc86..ab427407d 100644 --- a/examples/bluetooth/bt_spp_vfs_acceptor/main/example_spp_vfs_acceptor_demo.c +++ b/examples/bluetooth/bt_spp_vfs_acceptor/main/example_spp_vfs_acceptor_demo.c @@ -53,6 +53,9 @@ static void spp_read_handle(void * param) int size = 0; int fd = (int)param; do { + /* controll the log frequency, retry after 1s */ + vTaskDelay(1000 / portTICK_PERIOD_MS); + size = read (fd, spp_data, SPP_DATA_LEN); ESP_LOGI(SPP_TAG, "fd = %d data_len = %d", fd, size); if (size == -1) { diff --git a/examples/bluetooth/bt_spp_vfs_initiator/main/example_spp_vfs_initiator_demo.c b/examples/bluetooth/bt_spp_vfs_initiator/main/example_spp_vfs_initiator_demo.c index 4a2902553..5e26d9bee 100644 --- a/examples/bluetooth/bt_spp_vfs_initiator/main/example_spp_vfs_initiator_demo.c +++ b/examples/bluetooth/bt_spp_vfs_initiator/main/example_spp_vfs_initiator_demo.c @@ -61,6 +61,9 @@ static void spp_write_handle(void * param) int fd = (int)param; printf("%s %d %p\n", __func__,fd,param); do { + /* controll the log frequency, retry after 1s */ + vTaskDelay(1000 / portTICK_PERIOD_MS); + size = write (fd, spp_data, SPP_DATA_LEN); ESP_LOGI(SPP_TAG, "fd = %d data_len = %d",fd, size); if (size == -1) { From a194c415a8fc3e6eab80b0dc3419d27f1bd94562 Mon Sep 17 00:00:00 2001 From: lly Date: Thu, 2 Jul 2020 10:53:07 +0800 Subject: [PATCH 23/60] ble_mesh: stack: Update option of using DRAM/SPIRAM for memory allocation --- components/bt/Kconfig | 35 ++++++++++++++++--- .../mesh_common/include/mesh_common.h | 14 ++++---- .../bt/esp_ble_mesh/mesh_common/mesh_common.c | 31 ++++++++++++++++ 3 files changed, 67 insertions(+), 13 deletions(-) diff --git a/components/bt/Kconfig b/components/bt/Kconfig index 8c9d53657..647c23e9e 100644 --- a/components/bt/Kconfig +++ b/components/bt/Kconfig @@ -1738,12 +1738,37 @@ if BLE_MESH option in the Bluetooth Controller section in menuconfig, which is "Scan Duplicate By Device Address and Advertising Data". - config BLE_MESH_ALLOC_FROM_PSRAM_FIRST - bool "BLE Mesh will first allocate memory from PSRAM" - default n + choice BLE_MESH_MEM_ALLOC_MODE + prompt "Memory allocation strategy" + default BLE_MESH_MEM_ALLOC_MODE_INTERNAL help - When this option is enabled, BLE Mesh stack will try to allocate memory - from PSRAM firstly. This will save the internal RAM if PSRAM exists. + Allocation strategy for BLE Mesh stack, essentially provides ability to + allocate all required dynamic allocations from, + + - Internal DRAM memory only + - External SPIRAM memory only + - Either internal or external memory based on default malloc() + behavior in ESP-IDF + + Recommended mode here is always internal, since that is most preferred + from security perspective. But if application requirement does not allow + sufficient free internal memory then alternate mode can be selected. + + config BLE_MESH_MEM_ALLOC_MODE_INTERNAL + bool "Internal DRAM" + + config BLE_MESH_ALLOC_FROM_PSRAM_FIRST + bool "External SPIRAM" + depends on SPIRAM_SUPPORT + + config BLE_MESH_MEM_ALLOC_MODE_DEFAULT + bool "Default alloc mode" + depends on SPIRAM_SUPPORT + help + Enable this option to use the default memory allocation strategy when + external SPIRAM is enabled. See the SPIRAM options for more details. + + endchoice # BLE_MESH_MEM_ALLOC_MODE config BLE_MESH_FAST_PROV bool "Enable BLE Mesh Fast Provisioning" diff --git a/components/bt/esp_ble_mesh/mesh_common/include/mesh_common.h b/components/bt/esp_ble_mesh/mesh_common/include/mesh_common.h index ad968dd0e..f78a55776 100644 --- a/components/bt/esp_ble_mesh/mesh_common/include/mesh_common.h +++ b/components/bt/esp_ble_mesh/mesh_common/include/mesh_common.h @@ -22,6 +22,7 @@ #include #include +#include "esp_attr.h" #include "esp_heap_caps.h" #include "mesh_byteorder.h" @@ -34,14 +35,11 @@ extern "C" { #endif -#if CONFIG_BLE_MESH_ALLOC_FROM_PSRAM_FIRST -#define bt_mesh_malloc(size) heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL) -#define bt_mesh_calloc(size) heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL) -#else -#define bt_mesh_malloc(size) malloc((size)) -#define bt_mesh_calloc(size) calloc(1, (size)) -#endif /* CONFIG_BLE_MESH_ALLOC_FROM_PSRAM_FIRST */ -#define bt_mesh_free(p) free((p)) +IRAM_ATTR void *bt_mesh_malloc(size_t size); + +IRAM_ATTR void *bt_mesh_calloc(size_t size); + +IRAM_ATTR void bt_mesh_free(void *ptr); /** * @brief This function allocates memory to store outgoing message. diff --git a/components/bt/esp_ble_mesh/mesh_common/mesh_common.c b/components/bt/esp_ble_mesh/mesh_common/mesh_common.c index 8ab86266e..73a84e4a1 100644 --- a/components/bt/esp_ble_mesh/mesh_common/mesh_common.c +++ b/components/bt/esp_ble_mesh/mesh_common/mesh_common.c @@ -19,6 +19,37 @@ #include "client_common.h" #include "mesh_common.h" +IRAM_ATTR void *bt_mesh_malloc(size_t size) +{ +#ifdef CONFIG_BLE_MESH_MEM_ALLOC_MODE_INTERNAL + return heap_caps_malloc(size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +#elif CONFIG_BLE_MESH_ALLOC_FROM_PSRAM_FIRST + return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +#elif CONFIG_BLE_MESH_MEM_ALLOC_MODE_IRAM_8BIT + return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +#else + return malloc(size); +#endif +} + +IRAM_ATTR void *bt_mesh_calloc(size_t size) +{ +#ifdef CONFIG_BLE_MESH_MEM_ALLOC_MODE_INTERNAL + return heap_caps_calloc(1, size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +#elif CONFIG_BLE_MESH_ALLOC_FROM_PSRAM_FIRST + return heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +#elif CONFIG_BLE_MESH_MEM_ALLOC_MODE_IRAM_8BIT + return heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +#else + return calloc(1, size); +#endif +} + +IRAM_ATTR void bt_mesh_free(void *ptr) +{ + heap_caps_free(ptr); +} + struct net_buf_simple *bt_mesh_alloc_buf(u16_t size) { struct net_buf_simple *buf = NULL; From df8b2c5f3aa36e3f276147cfc0ed2f606f33ec16 Mon Sep 17 00:00:00 2001 From: lly Date: Fri, 3 Jul 2020 16:33:36 +0800 Subject: [PATCH 24/60] ble_mesh: stack: Make freertos static allocation visible --- components/bt/Kconfig | 28 ++++++ .../mesh_common/include/mesh_mutex.h | 2 +- .../bt/esp_ble_mesh/mesh_common/mesh_mutex.c | 22 +++-- components/bt/esp_ble_mesh/mesh_core/adv.c | 94 +++++++++++-------- 4 files changed, 98 insertions(+), 48 deletions(-) diff --git a/components/bt/Kconfig b/components/bt/Kconfig index 647c23e9e..882efb98e 100644 --- a/components/bt/Kconfig +++ b/components/bt/Kconfig @@ -1770,6 +1770,34 @@ if BLE_MESH endchoice # BLE_MESH_MEM_ALLOC_MODE + config BLE_MESH_FREERTOS_STATIC_ALLOC + bool "Enable FreeRTOS static allocation" + depends on SUPPORT_STATIC_ALLOCATION && SPIRAM_SUPPORT + default n + help + Enable this option to use FreeRTOS static allocation APIs for BLE Mesh, + which provides the ability to use different dynamic memory (i.e. SPIRAM) + for FreeRTOS objects. + If this option is disabled, the FreeRTOS static allocation APIs will not + be used, and internal DRAM will be allocated for FreeRTOS objects. + + choice BLE_MESH_FREERTOS_STATIC_ALLOC_MODE + prompt "Memory allocation for FreeRTOS objects" + depends on BLE_MESH_FREERTOS_STATIC_ALLOC + help + Choose the memory to be used for FreeRTOS objects. + + config BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL + bool "External SPIRAM" + depends on SPIRAM_SUPPORT + help + If enabled, BLE Mesh allocates dynamic memory from external SPIRAM for + FreeRTOS objects, i.e. mutex, queue, and task stack. External SPIRAM + can only be used for task stack when SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY + is enabled. See the SPIRAM options for more details. + + endchoice # BLE_MESH_FREERTOS_STATIC_ALLOC_MODE + config BLE_MESH_FAST_PROV bool "Enable BLE Mesh Fast Provisioning" select BLE_MESH_NODE diff --git a/components/bt/esp_ble_mesh/mesh_common/include/mesh_mutex.h b/components/bt/esp_ble_mesh/mesh_common/include/mesh_mutex.h index 488e010fa..faded20d3 100644 --- a/components/bt/esp_ble_mesh/mesh_common/include/mesh_mutex.h +++ b/components/bt/esp_ble_mesh/mesh_common/include/mesh_mutex.h @@ -25,7 +25,7 @@ extern "C" { typedef struct { SemaphoreHandle_t mutex; -#if CONFIG_SPIRAM_USE_MALLOC +#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC StaticQueue_t *buffer; #endif } bt_mesh_mutex_t; diff --git a/components/bt/esp_ble_mesh/mesh_common/mesh_mutex.c b/components/bt/esp_ble_mesh/mesh_common/mesh_mutex.c index 1bd6a2358..3f673209d 100644 --- a/components/bt/esp_ble_mesh/mesh_common/mesh_mutex.c +++ b/components/bt/esp_ble_mesh/mesh_common/mesh_mutex.c @@ -26,15 +26,19 @@ void bt_mesh_mutex_create(bt_mesh_mutex_t *mutex) return; } -#if CONFIG_SPIRAM_USE_MALLOC - mutex->buffer = heap_caps_calloc(1, sizeof(StaticQueue_t), MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM); - __ASSERT(mutex->buffer, "%s, Failed to create queue buffer", __func__); - mutex->mutex = xSemaphoreCreateMutexStatic(mutex->buffer); - __ASSERT(mutex->mutex, "%s, Failed to create static mutex", __func__); -#else - mutex->mutex = xSemaphoreCreateMutex(); - __ASSERT(mutex->mutex, "%s, Failed to create mutex", __func__); +#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC +#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL + mutex->buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +#elif CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_IRAM_8BIT + mutex->buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); #endif + __ASSERT(mutex->buffer, "Failed to create mutex buffer"); + mutex->mutex = xSemaphoreCreateMutexStatic(mutex->buffer); + __ASSERT(mutex->mutex, "Failed to create static mutex"); +#else /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */ + mutex->mutex = xSemaphoreCreateMutex(); + __ASSERT(mutex->mutex, "Failed to create mutex"); +#endif /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */ } void bt_mesh_mutex_free(bt_mesh_mutex_t *mutex) @@ -47,7 +51,7 @@ void bt_mesh_mutex_free(bt_mesh_mutex_t *mutex) if (mutex->mutex) { vSemaphoreDelete(mutex->mutex); mutex->mutex = NULL; -#if CONFIG_SPIRAM_USE_MALLOC +#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC heap_caps_free(mutex->buffer); mutex->buffer = NULL; #endif diff --git a/components/bt/esp_ble_mesh/mesh_core/adv.c b/components/bt/esp_ble_mesh/mesh_core/adv.c index 4e1d94849..7b10f9012 100644 --- a/components/bt/esp_ble_mesh/mesh_core/adv.c +++ b/components/bt/esp_ble_mesh/mesh_core/adv.c @@ -63,7 +63,7 @@ static struct bt_mesh_adv adv_pool[CONFIG_BLE_MESH_ADV_BUF_COUNT]; struct bt_mesh_queue { QueueHandle_t queue; -#if CONFIG_SPIRAM_USE_MALLOC +#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC StaticQueue_t *buffer; u8_t *storage; #endif @@ -121,7 +121,9 @@ static void bt_mesh_ble_adv_deinit(void); struct bt_mesh_adv_task { TaskHandle_t handle; -#if CONFIG_SPIRAM_USE_MALLOC +#if (CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && \ + CONFIG_SPIRAM_CACHE_WORKAROUND && \ + CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY) StaticTask_t *task; StackType_t *stack; #endif @@ -795,54 +797,68 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr, s8_t rssi, void bt_mesh_adv_init(void) { -#if !CONFIG_SPIRAM_USE_MALLOC +#if !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC xBleMeshQueue.queue = xQueueCreate(BLE_MESH_QUEUE_SIZE, sizeof(bt_mesh_msg_t)); - __ASSERT(xBleMeshQueue.queue, "%s, Failed to create queue", __func__); -#else - xBleMeshQueue.buffer = heap_caps_calloc(1, sizeof(StaticQueue_t), MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM); - __ASSERT(xBleMeshQueue.buffer, "%s, Failed to create queue buffer", __func__); - xBleMeshQueue.storage = heap_caps_calloc(1, (BLE_MESH_QUEUE_SIZE * sizeof(bt_mesh_msg_t)), MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM); - __ASSERT(xBleMeshQueue.storage, "%s, Failed to create queue storage", __func__); - xBleMeshQueue.queue = xQueueCreateStatic(BLE_MESH_QUEUE_SIZE, sizeof(bt_mesh_msg_t), (uint8_t*)xBleMeshQueue.storage, xBleMeshQueue.buffer); - __ASSERT(xBleMeshQueue.queue, "%s, Failed to create static queue", __func__); + __ASSERT(xBleMeshQueue.queue, "Failed to create queue"); +#else /* !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */ +#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL + xBleMeshQueue.buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +#elif CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_IRAM_8BIT + xBleMeshQueue.buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); #endif + __ASSERT(xBleMeshQueue.buffer, "Failed to create queue buffer"); +#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL + xBleMeshQueue.storage = heap_caps_calloc_prefer(1, (BLE_MESH_QUEUE_SIZE * sizeof(bt_mesh_msg_t)), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +#elif CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_IRAM_8BIT + xBleMeshQueue.storage = heap_caps_calloc_prefer(1, (BLE_MESH_QUEUE_SIZE * sizeof(bt_mesh_msg_t)), 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +#endif + __ASSERT(xBleMeshQueue.storage, "Failed to create queue storage"); + xBleMeshQueue.queue = xQueueCreateStatic(BLE_MESH_QUEUE_SIZE, sizeof(bt_mesh_msg_t), (uint8_t*)xBleMeshQueue.storage, xBleMeshQueue.buffer); + __ASSERT(xBleMeshQueue.queue, "Failed to create static queue"); +#endif /* !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */ #if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) -#if !CONFIG_SPIRAM_USE_MALLOC +#if !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC xBleMeshRelayQueue.queue = xQueueCreate(BLE_MESH_RELAY_QUEUE_SIZE, sizeof(bt_mesh_msg_t)); - __ASSERT(xBleMeshRelayQueue.queue, "%s, Failed to create relay queue", __func__); -#else - xBleMeshRelayQueue.buffer = heap_caps_calloc(1, sizeof(StaticQueue_t), MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM); - __ASSERT(xBleMeshRelayQueue.buffer, "%s, Failed to create relay queue buffer", __func__); - xBleMeshRelayQueue.storage = heap_caps_calloc(1, (BLE_MESH_RELAY_QUEUE_SIZE * sizeof(bt_mesh_msg_t)), MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM); - __ASSERT(xBleMeshRelayQueue.storage, "%s, Failed to create relay queue storage", __func__); - xBleMeshRelayQueue.queue = xQueueCreateStatic(BLE_MESH_RELAY_QUEUE_SIZE, sizeof(bt_mesh_msg_t), (uint8_t*)xBleMeshRelayQueue.storage, xBleMeshRelayQueue.buffer); - __ASSERT(xBleMeshRelayQueue.queue, "%s, Failed to create static relay queue", __func__); + __ASSERT(xBleMeshRelayQueue.queue, "Failed to create relay queue"); +#else /* !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */ +#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL + xBleMeshRelayQueue.buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +#elif CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_IRAM_8BIT + xBleMeshRelayQueue.buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); #endif + __ASSERT(xBleMeshRelayQueue.buffer, "Failed to create relay queue buffer"); +#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL + xBleMeshRelayQueue.storage = heap_caps_calloc_prefer(1, (BLE_MESH_RELAY_QUEUE_SIZE * sizeof(bt_mesh_msg_t)), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +#elif CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_IRAM_8BIT + xBleMeshRelayQueue.storage = heap_caps_calloc_prefer(1, (BLE_MESH_RELAY_QUEUE_SIZE * sizeof(bt_mesh_msg_t)), 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); +#endif + __ASSERT(xBleMeshRelayQueue.storage, "Failed to create relay queue storage"); + xBleMeshRelayQueue.queue = xQueueCreateStatic(BLE_MESH_RELAY_QUEUE_SIZE, sizeof(bt_mesh_msg_t), (uint8_t*)xBleMeshRelayQueue.storage, xBleMeshRelayQueue.buffer); + __ASSERT(xBleMeshRelayQueue.queue, "Failed to create static relay queue"); +#endif /* !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */ xBleMeshQueueSet = xQueueCreateSet(BLE_MESH_QUEUE_SET_SIZE); - __ASSERT(xBleMeshQueueSet, "%s, Failed to create queue set", __func__); + __ASSERT(xBleMeshQueueSet, "Failed to create queue set"); xQueueAddToSet(xBleMeshQueue.queue, xBleMeshQueueSet); xQueueAddToSet(xBleMeshRelayQueue.queue, xBleMeshQueueSet); #endif /* defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */ -#if !CONFIG_SPIRAM_USE_MALLOC - int ret = xTaskCreatePinnedToCore(adv_thread, "BLE_Mesh_ADV_Task", BLE_MESH_ADV_TASK_STACK_SIZE, NULL, - configMAX_PRIORITIES - 5, &adv_task.handle, BLE_MESH_ADV_TASK_CORE); - __ASSERT(ret == pdTRUE, "%s, Failed to create adv thread", __func__); -#else +#if (CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && \ + CONFIG_SPIRAM_CACHE_WORKAROUND && \ + CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY) adv_task.task = heap_caps_calloc(1, sizeof(StaticTask_t), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); - __ASSERT(adv_task.task, "%s, Failed to create adv thread task", __func__); -#if CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY - adv_task.stack = heap_caps_calloc(1, BLE_MESH_ADV_TASK_STACK_SIZE * sizeof(StackType_t), MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM); -#else - adv_task.stack = heap_caps_calloc(1, BLE_MESH_ADV_TASK_STACK_SIZE * sizeof(StackType_t), MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); -#endif - __ASSERT(adv_task.stack, "%s, Failed to create adv thread stack", __func__); + __ASSERT(adv_task.task, "Failed to create adv thread task"); + adv_task.stack = heap_caps_calloc_prefer(1, BLE_MESH_ADV_TASK_STACK_SIZE * sizeof(StackType_t), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + __ASSERT(adv_task.stack, "Failed to create adv thread stack"); adv_task.handle = xTaskCreateStaticPinnedToCore(adv_thread, "BLE_Mesh_ADV_Task", BLE_MESH_ADV_TASK_STACK_SIZE, NULL, configMAX_PRIORITIES - 5, adv_task.stack, adv_task.task, BLE_MESH_ADV_TASK_CORE); - __ASSERT(adv_task.handle, "%s, Failed to create static adv thread", __func__); -#endif + __ASSERT(adv_task.handle, "Failed to create static adv thread"); +#else /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && CONFIG_SPIRAM_CACHE_WORKAROUND && CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY */ + int ret = xTaskCreatePinnedToCore(adv_thread, "BLE_Mesh_ADV_Task", BLE_MESH_ADV_TASK_STACK_SIZE, NULL, + configMAX_PRIORITIES - 5, &adv_task.handle, BLE_MESH_ADV_TASK_CORE); + __ASSERT(ret == pdTRUE, "Failed to create adv thread"); +#endif /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && CONFIG_SPIRAM_CACHE_WORKAROUND && CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY */ } void bt_mesh_adv_deinit(void) @@ -853,7 +869,9 @@ void bt_mesh_adv_deinit(void) vTaskDelete(adv_task.handle); adv_task.handle = NULL; -#if CONFIG_SPIRAM_USE_MALLOC +#if (CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && \ + CONFIG_SPIRAM_CACHE_WORKAROUND && \ + CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY) heap_caps_free(adv_task.stack); adv_task.stack = NULL; heap_caps_free(adv_task.task); @@ -866,7 +884,7 @@ void bt_mesh_adv_deinit(void) vQueueDelete(xBleMeshRelayQueue.queue); xBleMeshRelayQueue.queue = NULL; -#if CONFIG_SPIRAM_USE_MALLOC +#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC heap_caps_free(xBleMeshRelayQueue.buffer); xBleMeshRelayQueue.buffer = NULL; heap_caps_free(xBleMeshRelayQueue.storage); @@ -882,7 +900,7 @@ void bt_mesh_adv_deinit(void) vQueueDelete(xBleMeshQueue.queue); xBleMeshQueue.queue = NULL; -#if CONFIG_SPIRAM_USE_MALLOC +#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC heap_caps_free(xBleMeshQueue.buffer); xBleMeshQueue.buffer = NULL; heap_caps_free(xBleMeshQueue.storage); From da068a639fa32f57a4a1d3454d058b6baa778bfb Mon Sep 17 00:00:00 2001 From: lly Date: Fri, 3 Jul 2020 16:56:46 +0800 Subject: [PATCH 25/60] ble_mesh: stack: Use macros for adv task name & prio --- .../bt/esp_ble_mesh/mesh_common/include/mesh_kernel.h | 3 +++ components/bt/esp_ble_mesh/mesh_core/adv.c | 8 ++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_common/include/mesh_kernel.h b/components/bt/esp_ble_mesh/mesh_common/include/mesh_kernel.h index 1a6baee71..eef953eb3 100644 --- a/components/bt/esp_ble_mesh/mesh_common/include/mesh_kernel.h +++ b/components/bt/esp_ble_mesh/mesh_common/include/mesh_kernel.h @@ -13,6 +13,7 @@ #include "freertos/queue.h" #include "freertos/semphr.h" +#include "sdkconfig.h" #include "mesh_types.h" #ifdef __cplusplus @@ -36,6 +37,8 @@ extern "C" { #endif #define BLE_MESH_ADV_TASK_STACK_SIZE 3072 +#define BLE_MESH_ADV_TASK_NAME "mesh_adv_task" +#define BLE_MESH_ADV_TASK_PRIO (configMAX_PRIORITIES - 5) /** * @brief Put the current thread to sleep. diff --git a/components/bt/esp_ble_mesh/mesh_core/adv.c b/components/bt/esp_ble_mesh/mesh_core/adv.c index 7b10f9012..e08494990 100644 --- a/components/bt/esp_ble_mesh/mesh_core/adv.c +++ b/components/bt/esp_ble_mesh/mesh_core/adv.c @@ -851,12 +851,12 @@ void bt_mesh_adv_init(void) __ASSERT(adv_task.task, "Failed to create adv thread task"); adv_task.stack = heap_caps_calloc_prefer(1, BLE_MESH_ADV_TASK_STACK_SIZE * sizeof(StackType_t), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); __ASSERT(adv_task.stack, "Failed to create adv thread stack"); - adv_task.handle = xTaskCreateStaticPinnedToCore(adv_thread, "BLE_Mesh_ADV_Task", BLE_MESH_ADV_TASK_STACK_SIZE, NULL, - configMAX_PRIORITIES - 5, adv_task.stack, adv_task.task, BLE_MESH_ADV_TASK_CORE); + adv_task.handle = xTaskCreateStaticPinnedToCore(adv_thread, BLE_MESH_ADV_TASK_NAME, BLE_MESH_ADV_TASK_STACK_SIZE, NULL, + BLE_MESH_ADV_TASK_PRIO, adv_task.stack, adv_task.task, BLE_MESH_ADV_TASK_CORE); __ASSERT(adv_task.handle, "Failed to create static adv thread"); #else /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && CONFIG_SPIRAM_CACHE_WORKAROUND && CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY */ - int ret = xTaskCreatePinnedToCore(adv_thread, "BLE_Mesh_ADV_Task", BLE_MESH_ADV_TASK_STACK_SIZE, NULL, - configMAX_PRIORITIES - 5, &adv_task.handle, BLE_MESH_ADV_TASK_CORE); + int ret = xTaskCreatePinnedToCore(adv_thread, BLE_MESH_ADV_TASK_NAME, BLE_MESH_ADV_TASK_STACK_SIZE, NULL, + BLE_MESH_ADV_TASK_PRIO, &adv_task.handle, BLE_MESH_ADV_TASK_CORE); __ASSERT(ret == pdTRUE, "Failed to create adv thread"); #endif /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && CONFIG_SPIRAM_CACHE_WORKAROUND && CONFIG_SPIRAM_ALLOW_STACK_EXTERNAL_MEMORY */ } From 2a6b0d68ce94158d3143b40fb846451a4aef4006 Mon Sep 17 00:00:00 2001 From: lly Date: Fri, 3 Jul 2020 18:23:46 +0800 Subject: [PATCH 26/60] ble_mesh: stack: Rename mesh adv queue and relay queue --- components/bt/esp_ble_mesh/mesh_core/adv.c | 174 ++++++++++----------- 1 file changed, 84 insertions(+), 90 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/adv.c b/components/bt/esp_ble_mesh/mesh_core/adv.c index e08494990..c43bbc2d9 100644 --- a/components/bt/esp_ble_mesh/mesh_core/adv.c +++ b/components/bt/esp_ble_mesh/mesh_core/adv.c @@ -27,25 +27,19 @@ #include "mesh_bearer_adapt.h" /* Convert from ms to 0.625ms units */ -#define ADV_SCAN_UNIT(_ms) ((_ms) * 8 / 5) +#define ADV_SCAN_UNIT(_ms) ((_ms) * 8 / 5) /* Convert from 0.625ms units to interval(ms) */ -#define ADV_SCAN_INT(val) ((val) * 5 / 8) +#define ADV_SCAN_INT(val) ((val) * 5 / 8) /* Window and Interval are equal for continuous scanning */ -#define MESH_SCAN_INTERVAL 0x20 -#define MESH_SCAN_WINDOW 0x20 +#define MESH_SCAN_INTERVAL 0x20 +#define MESH_SCAN_WINDOW 0x20 /* Pre-5.0 controllers enforce a minimum interval of 100ms * whereas 5.0+ controllers can go down to 20ms. */ -#define ADV_INT_DEFAULT_MS 100 -#define ADV_INT_FAST_MS 20 - -#if defined(CONFIG_BT_HOST_CRYPTO) -#define ADV_STACK_SIZE 1024 -#else -#define ADV_STACK_SIZE 768 -#endif +#define ADV_INT_DEFAULT_MS 100 +#define ADV_INT_FAST_MS 20 static const bt_mesh_addr_t *dev_addr; @@ -62,19 +56,19 @@ NET_BUF_POOL_DEFINE(adv_buf_pool, CONFIG_BLE_MESH_ADV_BUF_COUNT, static struct bt_mesh_adv adv_pool[CONFIG_BLE_MESH_ADV_BUF_COUNT]; struct bt_mesh_queue { - QueueHandle_t queue; + QueueHandle_t handle; #if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC StaticQueue_t *buffer; u8_t *storage; #endif }; -static struct bt_mesh_queue xBleMeshQueue; -/* We reserve one queue for bt_mesh_adv_update() */ +static struct bt_mesh_queue adv_queue; +/* We reserve one queue item for bt_mesh_adv_update() */ #if CONFIG_BLE_MESH_SUPPORT_BLE_ADV -#define BLE_MESH_QUEUE_SIZE (CONFIG_BLE_MESH_ADV_BUF_COUNT + CONFIG_BLE_MESH_BLE_ADV_BUF_COUNT + 1) +#define BLE_MESH_ADV_QUEUE_SIZE (CONFIG_BLE_MESH_ADV_BUF_COUNT + CONFIG_BLE_MESH_BLE_ADV_BUF_COUNT + 1) #else -#define BLE_MESH_QUEUE_SIZE (CONFIG_BLE_MESH_ADV_BUF_COUNT + 1) +#define BLE_MESH_ADV_QUEUE_SIZE (CONFIG_BLE_MESH_ADV_BUF_COUNT + 1) #endif #if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) @@ -83,11 +77,11 @@ NET_BUF_POOL_DEFINE(relay_adv_buf_pool, CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT, static struct bt_mesh_adv relay_adv_pool[CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT]; -static struct bt_mesh_queue xBleMeshRelayQueue; +static struct bt_mesh_queue relay_queue; #define BLE_MESH_RELAY_QUEUE_SIZE CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT -static QueueSetHandle_t xBleMeshQueueSet; -#define BLE_MESH_QUEUE_SET_SIZE (BLE_MESH_QUEUE_SIZE + BLE_MESH_RELAY_QUEUE_SIZE) +static QueueSetHandle_t mesh_queue_set; +#define BLE_MESH_QUEUE_SET_SIZE (BLE_MESH_ADV_QUEUE_SIZE + BLE_MESH_RELAY_QUEUE_SIZE) #define BLE_MESH_RELAY_TIME_INTERVAL K_SECONDS(6) #define BLE_MESH_MAX_TIME_INTERVAL 0xFFFFFFFF @@ -260,28 +254,28 @@ static void adv_thread(void *p) #if !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) #if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \ CONFIG_BLE_MESH_GATT_PROXY_SERVER - xQueueReceive(xBleMeshQueue.queue, &msg, K_NO_WAIT); + xQueueReceive(adv_queue.handle, &msg, K_NO_WAIT); while (!(*buf)) { s32_t timeout; BT_DBG("Mesh Proxy Advertising start"); timeout = bt_mesh_proxy_adv_start(); BT_DBG("Mesh Proxy Advertising up to %d ms", timeout); - xQueueReceive(xBleMeshQueue.queue, &msg, timeout); + xQueueReceive(adv_queue.handle, &msg, timeout); BT_DBG("Mesh Proxy Advertising stop"); bt_mesh_proxy_adv_stop(); } #else - xQueueReceive(xBleMeshQueue.queue, &msg, portMAX_DELAY); + xQueueReceive(adv_queue.handle, &msg, portMAX_DELAY); #endif /* (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_SERVER */ #else /* !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */ #if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \ CONFIG_BLE_MESH_GATT_PROXY_SERVER - handle = xQueueSelectFromSet(xBleMeshQueueSet, K_NO_WAIT); + handle = xQueueSelectFromSet(mesh_queue_set, K_NO_WAIT); if (handle) { - if (uxQueueMessagesWaiting(xBleMeshQueue.queue)) { - xQueueReceive(xBleMeshQueue.queue, &msg, K_NO_WAIT); - } else if (uxQueueMessagesWaiting(xBleMeshRelayQueue.queue)) { - xQueueReceive(xBleMeshRelayQueue.queue, &msg, K_NO_WAIT); + if (uxQueueMessagesWaiting(adv_queue.handle)) { + xQueueReceive(adv_queue.handle, &msg, K_NO_WAIT); + } else if (uxQueueMessagesWaiting(relay_queue.handle)) { + xQueueReceive(relay_queue.handle, &msg, K_NO_WAIT); } } else { while (!(*buf)) { @@ -289,25 +283,25 @@ static void adv_thread(void *p) BT_DBG("Mesh Proxy Advertising start"); timeout = bt_mesh_proxy_adv_start(); BT_DBG("Mesh Proxy Advertising up to %d ms", timeout); - handle = xQueueSelectFromSet(xBleMeshQueueSet, timeout); + handle = xQueueSelectFromSet(mesh_queue_set, timeout); BT_DBG("Mesh Proxy Advertising stop"); bt_mesh_proxy_adv_stop(); if (handle) { - if (uxQueueMessagesWaiting(xBleMeshQueue.queue)) { - xQueueReceive(xBleMeshQueue.queue, &msg, K_NO_WAIT); - } else if (uxQueueMessagesWaiting(xBleMeshRelayQueue.queue)) { - xQueueReceive(xBleMeshRelayQueue.queue, &msg, K_NO_WAIT); + if (uxQueueMessagesWaiting(adv_queue.handle)) { + xQueueReceive(adv_queue.handle, &msg, K_NO_WAIT); + } else if (uxQueueMessagesWaiting(relay_queue.handle)) { + xQueueReceive(relay_queue.handle, &msg, K_NO_WAIT); } } } } #else - handle = xQueueSelectFromSet(xBleMeshQueueSet, portMAX_DELAY); + handle = xQueueSelectFromSet(mesh_queue_set, portMAX_DELAY); if (handle) { - if (uxQueueMessagesWaiting(xBleMeshQueue.queue)) { - xQueueReceive(xBleMeshQueue.queue, &msg, K_NO_WAIT); - } else if (uxQueueMessagesWaiting(xBleMeshRelayQueue.queue)) { - xQueueReceive(xBleMeshRelayQueue.queue, &msg, K_NO_WAIT); + if (uxQueueMessagesWaiting(adv_queue.handle)) { + xQueueReceive(adv_queue.handle, &msg, K_NO_WAIT); + } else if (uxQueueMessagesWaiting(relay_queue.handle)) { + xQueueReceive(relay_queue.handle, &msg, K_NO_WAIT); } } #endif /* (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_SERVER */ @@ -448,18 +442,18 @@ static void bt_mesh_task_post(bt_mesh_msg_t *msg, uint32_t timeout, bool front) { BT_DBG("%s", __func__); - if (xBleMeshQueue.queue == NULL) { + if (adv_queue.handle == NULL) { BT_ERR("%s, Invalid queue", __func__); return; } if (front) { - if (xQueueSendToFront(xBleMeshQueue.queue, msg, timeout) != pdTRUE) { + if (xQueueSendToFront(adv_queue.handle, msg, timeout) != pdTRUE) { BT_ERR("%s, Failed to send item to queue front", __func__); bt_mesh_unref_buf(msg); } } else { - if (xQueueSend(xBleMeshQueue.queue, msg, timeout) != pdTRUE) { + if (xQueueSend(adv_queue.handle, msg, timeout) != pdTRUE) { BT_ERR("%s, Failed to send item to queue back", __func__); bt_mesh_unref_buf(msg); } @@ -532,12 +526,12 @@ static void ble_mesh_relay_task_post(bt_mesh_msg_t *msg, uint32_t timeout) BT_DBG("%s", __func__); - if (xBleMeshRelayQueue.queue == NULL) { + if (relay_queue.handle == NULL) { BT_ERR("%s, Invalid relay queue", __func__); return; } - if (xQueueSend(xBleMeshRelayQueue.queue, msg, timeout) == pdTRUE) { + if (xQueueSend(relay_queue.handle, msg, timeout) == pdTRUE) { return; } @@ -545,11 +539,11 @@ static void ble_mesh_relay_task_post(bt_mesh_msg_t *msg, uint32_t timeout) * If failed to send packet to the relay queue(queue is full), we will * remove the oldest packet in the queue and put the new one into it. */ - handle = xQueueSelectFromSet(xBleMeshQueueSet, K_NO_WAIT); - if (handle && uxQueueMessagesWaiting(xBleMeshRelayQueue.queue)) { + handle = xQueueSelectFromSet(mesh_queue_set, K_NO_WAIT); + if (handle && uxQueueMessagesWaiting(relay_queue.handle)) { BT_INFO("%s, Full queue, remove the oldest relay packet", __func__); /* Remove the oldest relay packet from queue */ - if (xQueueReceive(xBleMeshRelayQueue.queue, &old_msg, K_NO_WAIT) != pdTRUE) { + if (xQueueReceive(relay_queue.handle, &old_msg, K_NO_WAIT) != pdTRUE) { BT_ERR("%s, Failed to remove item from queue", __func__); bt_mesh_unref_buf(msg); return; @@ -557,7 +551,7 @@ static void ble_mesh_relay_task_post(bt_mesh_msg_t *msg, uint32_t timeout) /* Unref buf used for the oldest relay packet */ bt_mesh_unref_buf(&old_msg); /* Send the latest relay packet to queue */ - if (xQueueSend(xBleMeshRelayQueue.queue, msg, K_NO_WAIT) != pdTRUE) { + if (xQueueSend(relay_queue.handle, msg, K_NO_WAIT) != pdTRUE) { BT_ERR("%s, Failed to send item to relay queue", __func__); bt_mesh_unref_buf(msg); return; @@ -586,13 +580,13 @@ void bt_mesh_relay_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *c msg.src = src; msg.dst = dst; msg.timestamp = k_uptime_get_32(); - /* Use K_NO_WAIT here, if xBleMeshRelayQueue is full return immediately */ + /* Use K_NO_WAIT here, if relay_queue is full return immediately */ ble_mesh_relay_task_post(&msg, K_NO_WAIT); } u16_t bt_mesh_get_stored_relay_count(void) { - return (u16_t)uxQueueMessagesWaiting(xBleMeshRelayQueue.queue); + return (u16_t)uxQueueMessagesWaiting(relay_queue.handle); } #endif /* #if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */ @@ -798,50 +792,50 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr, s8_t rssi, void bt_mesh_adv_init(void) { #if !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC - xBleMeshQueue.queue = xQueueCreate(BLE_MESH_QUEUE_SIZE, sizeof(bt_mesh_msg_t)); - __ASSERT(xBleMeshQueue.queue, "Failed to create queue"); + adv_queue.handle = xQueueCreate(BLE_MESH_ADV_QUEUE_SIZE, sizeof(bt_mesh_msg_t)); + __ASSERT(adv_queue.handle, "Failed to create queue"); #else /* !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */ #if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL - xBleMeshQueue.buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + adv_queue.buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); #elif CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_IRAM_8BIT - xBleMeshQueue.buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + adv_queue.buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); #endif - __ASSERT(xBleMeshQueue.buffer, "Failed to create queue buffer"); + __ASSERT(adv_queue.buffer, "Failed to create queue buffer"); #if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL - xBleMeshQueue.storage = heap_caps_calloc_prefer(1, (BLE_MESH_QUEUE_SIZE * sizeof(bt_mesh_msg_t)), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + adv_queue.storage = heap_caps_calloc_prefer(1, (BLE_MESH_ADV_QUEUE_SIZE * sizeof(bt_mesh_msg_t)), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); #elif CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_IRAM_8BIT - xBleMeshQueue.storage = heap_caps_calloc_prefer(1, (BLE_MESH_QUEUE_SIZE * sizeof(bt_mesh_msg_t)), 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + adv_queue.storage = heap_caps_calloc_prefer(1, (BLE_MESH_ADV_QUEUE_SIZE * sizeof(bt_mesh_msg_t)), 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); #endif - __ASSERT(xBleMeshQueue.storage, "Failed to create queue storage"); - xBleMeshQueue.queue = xQueueCreateStatic(BLE_MESH_QUEUE_SIZE, sizeof(bt_mesh_msg_t), (uint8_t*)xBleMeshQueue.storage, xBleMeshQueue.buffer); - __ASSERT(xBleMeshQueue.queue, "Failed to create static queue"); + __ASSERT(adv_queue.storage, "Failed to create queue storage"); + adv_queue.handle = xQueueCreateStatic(BLE_MESH_ADV_QUEUE_SIZE, sizeof(bt_mesh_msg_t), (uint8_t*)adv_queue.storage, adv_queue.buffer); + __ASSERT(adv_queue.handle, "Failed to create static queue"); #endif /* !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */ #if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) #if !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC - xBleMeshRelayQueue.queue = xQueueCreate(BLE_MESH_RELAY_QUEUE_SIZE, sizeof(bt_mesh_msg_t)); - __ASSERT(xBleMeshRelayQueue.queue, "Failed to create relay queue"); + relay_queue.handle = xQueueCreate(BLE_MESH_RELAY_QUEUE_SIZE, sizeof(bt_mesh_msg_t)); + __ASSERT(relay_queue.handle, "Failed to create relay queue"); #else /* !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */ #if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL - xBleMeshRelayQueue.buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + relay_queue.buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); #elif CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_IRAM_8BIT - xBleMeshRelayQueue.buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + relay_queue.buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); #endif - __ASSERT(xBleMeshRelayQueue.buffer, "Failed to create relay queue buffer"); + __ASSERT(relay_queue.buffer, "Failed to create relay queue buffer"); #if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL - xBleMeshRelayQueue.storage = heap_caps_calloc_prefer(1, (BLE_MESH_RELAY_QUEUE_SIZE * sizeof(bt_mesh_msg_t)), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + relay_queue.storage = heap_caps_calloc_prefer(1, (BLE_MESH_RELAY_QUEUE_SIZE * sizeof(bt_mesh_msg_t)), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); #elif CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_IRAM_8BIT - xBleMeshRelayQueue.storage = heap_caps_calloc_prefer(1, (BLE_MESH_RELAY_QUEUE_SIZE * sizeof(bt_mesh_msg_t)), 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); + relay_queue.storage = heap_caps_calloc_prefer(1, (BLE_MESH_RELAY_QUEUE_SIZE * sizeof(bt_mesh_msg_t)), 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); #endif - __ASSERT(xBleMeshRelayQueue.storage, "Failed to create relay queue storage"); - xBleMeshRelayQueue.queue = xQueueCreateStatic(BLE_MESH_RELAY_QUEUE_SIZE, sizeof(bt_mesh_msg_t), (uint8_t*)xBleMeshRelayQueue.storage, xBleMeshRelayQueue.buffer); - __ASSERT(xBleMeshRelayQueue.queue, "Failed to create static relay queue"); + __ASSERT(relay_queue.storage, "Failed to create relay queue storage"); + relay_queue.handle = xQueueCreateStatic(BLE_MESH_RELAY_QUEUE_SIZE, sizeof(bt_mesh_msg_t), (uint8_t*)relay_queue.storage, relay_queue.buffer); + __ASSERT(relay_queue.handle, "Failed to create static relay queue"); #endif /* !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */ - xBleMeshQueueSet = xQueueCreateSet(BLE_MESH_QUEUE_SET_SIZE); - __ASSERT(xBleMeshQueueSet, "Failed to create queue set"); - xQueueAddToSet(xBleMeshQueue.queue, xBleMeshQueueSet); - xQueueAddToSet(xBleMeshRelayQueue.queue, xBleMeshQueueSet); + mesh_queue_set = xQueueCreateSet(BLE_MESH_QUEUE_SET_SIZE); + __ASSERT(mesh_queue_set, "Failed to create queue set"); + xQueueAddToSet(adv_queue.handle, mesh_queue_set); + xQueueAddToSet(relay_queue.handle, mesh_queue_set); #endif /* defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */ #if (CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && \ @@ -863,7 +857,7 @@ void bt_mesh_adv_init(void) void bt_mesh_adv_deinit(void) { - if (xBleMeshQueue.queue == NULL) { + if (adv_queue.handle == NULL) { return; } @@ -879,32 +873,32 @@ void bt_mesh_adv_deinit(void) #endif #if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) - xQueueRemoveFromSet(xBleMeshQueue.queue, xBleMeshQueueSet); - xQueueRemoveFromSet(xBleMeshRelayQueue.queue, xBleMeshQueueSet); + xQueueRemoveFromSet(adv_queue.handle, mesh_queue_set); + xQueueRemoveFromSet(relay_queue.handle, mesh_queue_set); - vQueueDelete(xBleMeshRelayQueue.queue); - xBleMeshRelayQueue.queue = NULL; + vQueueDelete(relay_queue.handle); + relay_queue.handle = NULL; #if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC - heap_caps_free(xBleMeshRelayQueue.buffer); - xBleMeshRelayQueue.buffer = NULL; - heap_caps_free(xBleMeshRelayQueue.storage); - xBleMeshRelayQueue.storage = NULL; + heap_caps_free(relay_queue.buffer); + relay_queue.buffer = NULL; + heap_caps_free(relay_queue.storage); + relay_queue.storage = NULL; #endif bt_mesh_unref_buf_from_pool(&relay_adv_buf_pool); memset(relay_adv_pool, 0, sizeof(relay_adv_pool)); - vQueueDelete(xBleMeshQueueSet); - xBleMeshQueueSet = NULL; + vQueueDelete(mesh_queue_set); + mesh_queue_set = NULL; #endif /* defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */ - vQueueDelete(xBleMeshQueue.queue); - xBleMeshQueue.queue = NULL; + vQueueDelete(adv_queue.handle); + adv_queue.handle = NULL; #if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC - heap_caps_free(xBleMeshQueue.buffer); - xBleMeshQueue.buffer = NULL; - heap_caps_free(xBleMeshQueue.storage); - xBleMeshQueue.storage = NULL; + heap_caps_free(adv_queue.buffer); + adv_queue.buffer = NULL; + heap_caps_free(adv_queue.storage); + adv_queue.storage = NULL; #endif bt_mesh_unref_buf_from_pool(&adv_buf_pool); From 78003e94373f702ba904aa4242d80993b30e2652 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 13 Aug 2020 11:18:03 +1000 Subject: [PATCH 27/60] docs: Fix toolchain URL generation for macos Didn't backport the new URL scheme when we updated the toolchain version. Have put a link on the server so in this case the "osx" toolchain URL remains valid. Closes https://github.com/espressif/esp-idf/issues/5720 --- docs/en/get-started-cmake/macos-setup.rst | 4 ++-- docs/en/get-started/macos-setup.rst | 4 ++-- docs/gen-toolchain-links.py | 2 +- docs/zh_CN/get-started-cmake/macos-setup.rst | 6 +++--- docs/zh_CN/get-started/macos-setup.rst | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/en/get-started-cmake/macos-setup.rst b/docs/en/get-started-cmake/macos-setup.rst index 75130d71a..3b023eb49 100644 --- a/docs/en/get-started-cmake/macos-setup.rst +++ b/docs/en/get-started-cmake/macos-setup.rst @@ -47,11 +47,11 @@ Toolchain Setup ESP32 toolchain for macOS is available for download from Espressif website: -|download_link_osx| +|download_link_macos| Download this file, then extract it in ``~/esp`` directory: -.. include:: /_build/inc/unpack-code-osx.inc +.. include:: /_build/inc/unpack-code-macos.inc .. _setup-macos-toolchain-add-it-to-path-cmake: diff --git a/docs/en/get-started/macos-setup.rst b/docs/en/get-started/macos-setup.rst index 7e1921a6c..b69ae1237 100644 --- a/docs/en/get-started/macos-setup.rst +++ b/docs/en/get-started/macos-setup.rst @@ -21,11 +21,11 @@ Toolchain Setup ESP32 toolchain for macOS is available for download from Espressif website: -|download_link_osx| +|download_link_macos| Download this file, then extract it in ``~/esp`` directory: -.. include:: /_build/inc/unpack-code-osx.inc +.. include:: /_build/inc/unpack-code-macos.inc .. _setup-macos-toolchain-add-it-to-path: diff --git a/docs/gen-toolchain-links.py b/docs/gen-toolchain-links.py index ea90f47c7..0a93d6306 100644 --- a/docs/gen-toolchain-links.py +++ b/docs/gen-toolchain-links.py @@ -51,7 +51,7 @@ def main(): platform_info = [["linux64", "tar.gz", "z", unpack_code_linux_macos], ["linux32", "tar.gz", "z", unpack_code_linux_macos], - ["osx", "tar.gz", "z", unpack_code_linux_macos], + ["macos", "tar.gz", "z", unpack_code_linux_macos], ["win32", "zip", None, None]] with open(os.path.join(out_dir, 'download-links.inc'), "w") as links_file: diff --git a/docs/zh_CN/get-started-cmake/macos-setup.rst b/docs/zh_CN/get-started-cmake/macos-setup.rst index 83536dbe3..6d0f72cf5 100644 --- a/docs/zh_CN/get-started-cmake/macos-setup.rst +++ b/docs/zh_CN/get-started-cmake/macos-setup.rst @@ -48,11 +48,11 @@ ESP-IDF 将使用 Mac OS 上默认安装的 Python 版本。 下载 MacOS 版本的 ESP32 工具链,请前往乐鑫官网: -|download_link_osx| +|download_link_macos| 完成下载后,请在 ``~/esp`` 目录下进行解压: -.. include:: /_build/inc/unpack-code-osx.inc +.. include:: /_build/inc/unpack-code-macos.inc .. _setup-macos-toolchain-add-it-to-path-cmake: @@ -92,4 +92,4 @@ ESP-IDF 将使用 Mac OS 上默认安装的 Python 版本。 .. _ninja: https://ninja-build.org/ .. _ccache: https://ccache.samba.org/ .. _homebrew: https://brew.sh/ -.. _MacPorts: https://www.macports.org/install.php \ No newline at end of file +.. _MacPorts: https://www.macports.org/install.php diff --git a/docs/zh_CN/get-started/macos-setup.rst b/docs/zh_CN/get-started/macos-setup.rst index 72596ead2..502b37cf9 100644 --- a/docs/zh_CN/get-started/macos-setup.rst +++ b/docs/zh_CN/get-started/macos-setup.rst @@ -23,11 +23,11 @@ Mac OS 版本的 ESP32 工具链可以从以下地址下载: -|download_link_osx| +|download_link_macos| 下载压缩文件之后,解压到 ``~/esp`` 目录中: -.. include:: /_build/inc/unpack-code-osx.inc +.. include:: /_build/inc/unpack-code-macos.inc .. _setup-macos-toolchain-add-it-to-path: From 95c7b26cdde5aff5663b6e25363bb5ddefda4954 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Thu, 27 Aug 2020 18:21:03 +1000 Subject: [PATCH 28/60] version: Update to v3.3.3 --- components/esp32/include/esp_idf_version.h | 2 +- make/version.mk | 2 +- tools/cmake/version.cmake | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/esp32/include/esp_idf_version.h b/components/esp32/include/esp_idf_version.h index 735abc78b..2f10beae6 100644 --- a/components/esp32/include/esp_idf_version.h +++ b/components/esp32/include/esp_idf_version.h @@ -23,7 +23,7 @@ extern "C" { /** Minor version number (x.X.x) */ #define ESP_IDF_VERSION_MINOR 3 /** Patch version number (x.x.X) */ -#define ESP_IDF_VERSION_PATCH 2 +#define ESP_IDF_VERSION_PATCH 3 /** * Macro to convert IDF version number into an integer diff --git a/make/version.mk b/make/version.mk index f429bfe20..716fff948 100644 --- a/make/version.mk +++ b/make/version.mk @@ -1,3 +1,3 @@ IDF_VERSION_MAJOR := 3 IDF_VERSION_MINOR := 3 -IDF_VERSION_PATCH := 2 +IDF_VERSION_PATCH := 3 diff --git a/tools/cmake/version.cmake b/tools/cmake/version.cmake index 3dab26aa3..3965eeb32 100644 --- a/tools/cmake/version.cmake +++ b/tools/cmake/version.cmake @@ -1,3 +1,3 @@ set(IDF_VERSION_MAJOR 3) set(IDF_VERSION_MINOR 3) -set(IDF_VERSION_PATCH 2) +set(IDF_VERSION_PATCH 3) From c1c4990f75a2011f2fb915b92710f2ee73db3cc0 Mon Sep 17 00:00:00 2001 From: lly Date: Sat, 4 Jul 2020 20:55:48 +0800 Subject: [PATCH 29/60] ble_mesh: stack: Add more checks about input prov bearers --- .../api/core/esp_ble_mesh_provisioning_api.c | 30 ++++++++++++ components/bt/esp_ble_mesh/mesh_core/main.c | 49 ++++++++++++++----- 2 files changed, 68 insertions(+), 11 deletions(-) diff --git a/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_provisioning_api.c b/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_provisioning_api.c index 9fbbd6b59..e0242de72 100644 --- a/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_provisioning_api.c +++ b/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_provisioning_api.c @@ -35,11 +35,29 @@ bool esp_ble_mesh_node_is_provisioned(void) return bt_mesh_is_provisioned(); } +static bool prov_bearers_valid(esp_ble_mesh_prov_bearer_t bearers) +{ + if ((!(bearers & (ESP_BLE_MESH_PROV_ADV | ESP_BLE_MESH_PROV_GATT))) || + (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) && + !IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) && + !(bearers & ESP_BLE_MESH_PROV_ADV)) || + (!IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) && + IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) && + !(bearers & ESP_BLE_MESH_PROV_GATT))) { + return false; + } + return true; +} + esp_err_t esp_ble_mesh_node_prov_enable(esp_ble_mesh_prov_bearer_t bearers) { btc_ble_mesh_prov_args_t arg = {0}; btc_msg_t msg = {0}; + if (prov_bearers_valid(bearers) == false) { + return ESP_ERR_INVALID_ARG; + } + ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; @@ -56,6 +74,10 @@ esp_err_t esp_ble_mesh_node_prov_disable(esp_ble_mesh_prov_bearer_t bearers) btc_ble_mesh_prov_args_t arg = {0}; btc_msg_t msg = {0}; + if (prov_bearers_valid(bearers) == false) { + return ESP_ERR_INVALID_ARG; + } + ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; @@ -232,6 +254,10 @@ esp_err_t esp_ble_mesh_provisioner_prov_enable(esp_ble_mesh_prov_bearer_t bearer btc_ble_mesh_prov_args_t arg = {0}; btc_msg_t msg = {0}; + if (prov_bearers_valid(bearers) == false) { + return ESP_ERR_INVALID_ARG; + } + ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; @@ -249,6 +275,10 @@ esp_err_t esp_ble_mesh_provisioner_prov_disable(esp_ble_mesh_prov_bearer_t beare btc_ble_mesh_prov_args_t arg = {0}; btc_msg_t msg = {0}; + if (prov_bearers_valid(bearers) == false) { + return ESP_ERR_INVALID_ARG; + } + ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; diff --git a/components/bt/esp_ble_mesh/mesh_core/main.c b/components/bt/esp_ble_mesh/mesh_core/main.c index 32a9c0939..bc583e75e 100644 --- a/components/bt/esp_ble_mesh/mesh_core/main.c +++ b/components/bt/esp_ble_mesh/mesh_core/main.c @@ -171,12 +171,32 @@ bool bt_mesh_is_provisioner_en(void) } } +static bool prov_bearers_valid(bt_mesh_prov_bearer_t bearers) +{ + if ((!(bearers & (BLE_MESH_PROV_ADV | BLE_MESH_PROV_GATT))) || + (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) && + !IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) && + !(bearers & BLE_MESH_PROV_ADV)) || + (!IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) && + IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) && + !(bearers & BLE_MESH_PROV_GATT))) { + BT_ERR("Invalid bearers 0x%02x", bearers); + return false; + } + return true; +} + int bt_mesh_prov_enable(bt_mesh_prov_bearer_t bearers) { if (bt_mesh_is_provisioned()) { + BT_WARN("%s, Already", __func__); return -EALREADY; } + if (prov_bearers_valid(bearers) == false) { + return -EINVAL; + } + bt_mesh_atomic_set_bit(bt_mesh.flags, BLE_MESH_NODE); if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { @@ -206,6 +226,10 @@ int bt_mesh_prov_disable(bt_mesh_prov_bearer_t bearers) return -EALREADY; } + if (prov_bearers_valid(bearers) == false) { + return -EINVAL; + } + bt_mesh_atomic_clear_bit(bt_mesh.flags, BLE_MESH_NODE); if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { @@ -509,13 +533,6 @@ int bt_mesh_provisioner_net_start(bt_mesh_prov_bearer_t bearers) } #endif - if ((IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) && - (bearers & BLE_MESH_PROV_ADV)) || - (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) && - (bearers & BLE_MESH_PROV_GATT))) { - bt_mesh_scan_enable(); - } - if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) && (bearers & BLE_MESH_PROV_GATT)) { bt_mesh_provisioner_pb_gatt_enable(); @@ -523,13 +540,15 @@ int bt_mesh_provisioner_net_start(bt_mesh_prov_bearer_t bearers) bt_mesh_atomic_set_bit(bt_mesh.flags, BLE_MESH_VALID_PROV); + if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) { + bt_mesh_friend_init(); + } + if (bt_mesh_beacon_get() == BLE_MESH_BEACON_ENABLED) { bt_mesh_beacon_enable(); } - if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) { - bt_mesh_friend_init(); - } + bt_mesh_scan_enable(); return 0; } @@ -543,6 +562,10 @@ int bt_mesh_provisioner_enable(bt_mesh_prov_bearer_t bearers) return -EALREADY; } + if (prov_bearers_valid(bearers) == false) { + return -EINVAL; + } + err = bt_mesh_provisioner_set_prov_info(); if (err) { BT_ERR("%s, Failed to set provisioning info", __func__); @@ -573,9 +596,13 @@ int bt_mesh_provisioner_disable(bt_mesh_prov_bearer_t bearers) return -EALREADY; } + if (prov_bearers_valid(bearers) == false) { + return -EINVAL; + } + enable = bt_mesh_provisioner_get_prov_bearer(); if (!(enable & bearers)) { - BT_ERR("%s, Bearers mismatch", __func__); + BT_ERR("Mismatch bearers 0x%02x", bearers); return -EINVAL; } From 43ffec0bd7422448b41f1d5eef62246edf409a2e Mon Sep 17 00:00:00 2001 From: lly Date: Mon, 6 Jul 2020 15:18:11 +0800 Subject: [PATCH 30/60] ble_mesh: example: Add result check during mesh init --- .../ble_mesh_node/onoff_client/main/main.c | 10 +++++--- .../ble_mesh_node/onoff_server/main/main.c | 12 ++++++--- .../ble_mesh_provisioner/main/main.c | 25 +++++++++++++------ 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_client/main/main.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_client/main/main.c index 69a3173f1..9b642cf81 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_client/main/main.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_client/main/main.c @@ -272,12 +272,16 @@ static esp_err_t ble_mesh_init(void) esp_ble_mesh_register_config_server_callback(example_ble_mesh_config_server_cb); err = esp_ble_mesh_init(&provision, &composition); - if (err) { - ESP_LOGE(TAG, "Initializing mesh failed (err %d)", err); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to initialize mesh stack (err %d)", err); return err; } - esp_ble_mesh_node_prov_enable(ESP_BLE_MESH_PROV_ADV | ESP_BLE_MESH_PROV_GATT); + err = esp_ble_mesh_node_prov_enable(ESP_BLE_MESH_PROV_ADV | ESP_BLE_MESH_PROV_GATT); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to enable mesh node (err %d)", err); + return err; + } ESP_LOGI(TAG, "BLE Mesh Node initialized"); diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_server/main/main.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_server/main/main.c index 70d98de01..da54a5e5c 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_server/main/main.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_server/main/main.c @@ -285,19 +285,23 @@ static void example_ble_mesh_config_server_cb(esp_ble_mesh_cfg_server_cb_event_t static esp_err_t ble_mesh_init(void) { - esp_err_t err; + esp_err_t err = ESP_OK; esp_ble_mesh_register_prov_callback(example_ble_mesh_provisioning_cb); esp_ble_mesh_register_config_server_callback(example_ble_mesh_config_server_cb); esp_ble_mesh_register_generic_server_callback(example_ble_mesh_generic_server_cb); err = esp_ble_mesh_init(&provision, &composition); - if (err) { - ESP_LOGE(TAG, "Initializing mesh failed (err %d)", err); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to initialize mesh stack (err %d)", err); return err; } - esp_ble_mesh_node_prov_enable(ESP_BLE_MESH_PROV_ADV | ESP_BLE_MESH_PROV_GATT); + err = esp_ble_mesh_node_prov_enable(ESP_BLE_MESH_PROV_ADV | ESP_BLE_MESH_PROV_GATT); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to enable mesh node (err %d)", err); + return err; + } ESP_LOGI(TAG, "BLE Mesh Node initialized"); diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_provisioner/main/main.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_provisioner/main/main.c index 674685d97..3e3765983 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_provisioner/main/main.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_provisioner/main/main.c @@ -584,7 +584,7 @@ static void example_ble_mesh_generic_client_cb(esp_ble_mesh_generic_client_cb_ev static esp_err_t ble_mesh_init(void) { uint8_t match[2] = {0xdd, 0xdd}; - esp_err_t err; + esp_err_t err = ESP_OK; prov_key.net_idx = ESP_BLE_MESH_KEY_PRIMARY; prov_key.app_idx = APP_KEY_IDX; @@ -594,18 +594,29 @@ static esp_err_t ble_mesh_init(void) esp_ble_mesh_register_config_client_callback(example_ble_mesh_config_client_cb); esp_ble_mesh_register_generic_client_callback(example_ble_mesh_generic_client_cb); - err = esp_ble_mesh_init(&provision, &composition); - if (err) { - ESP_LOGE(TAG, "Initializing mesh failed (err %d)", err); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to initialize mesh stack (err %d)", err); return err; } - esp_ble_mesh_provisioner_set_dev_uuid_match(match, sizeof(match), 0x0, false); + err = esp_ble_mesh_provisioner_set_dev_uuid_match(match, sizeof(match), 0x0, false); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to set matching device uuid (err %d)", err); + return err; + } - esp_ble_mesh_provisioner_prov_enable(ESP_BLE_MESH_PROV_ADV | ESP_BLE_MESH_PROV_GATT); + err = esp_ble_mesh_provisioner_prov_enable(ESP_BLE_MESH_PROV_ADV | ESP_BLE_MESH_PROV_GATT); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to enable mesh provisioner (err %d)", err); + return err; + } - esp_ble_mesh_provisioner_add_local_app_key(prov_key.app_key, prov_key.net_idx, prov_key.app_idx); + err = esp_ble_mesh_provisioner_add_local_app_key(prov_key.app_key, prov_key.net_idx, prov_key.app_idx); + if (err != ESP_OK) { + ESP_LOGE(TAG, "Failed to add local AppKey (err %d)", err); + return err; + } ESP_LOGI(TAG, "BLE Mesh Provisioner initialized"); From 55489bb41ab50fbff1f46d2365ddf6d6c378067d Mon Sep 17 00:00:00 2001 From: lly Date: Mon, 6 Jul 2020 11:41:01 +0800 Subject: [PATCH 31/60] ble_mesh: stack: Rework using dev flag to check scan status Different bluetooth host has different behaviors, so it's better to maintain a scan check mechanism of BLE Mesh itself. Fixes an issue when only PB-GATT is enabled for node, which will output a scan error log when the device is provisioned. --- components/bt/esp_ble_mesh/mesh_core/adv.c | 2 +- .../bluedroid_host/mesh_bearer_adapt.c | 50 +++++++------------ components/bt/esp_ble_mesh/mesh_core/main.c | 3 -- .../mesh_core/nimble_host/mesh_bearer_adapt.c | 43 +++++----------- 4 files changed, 31 insertions(+), 67 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/adv.c b/components/bt/esp_ble_mesh/mesh_core/adv.c index c43bbc2d9..15838c6d8 100644 --- a/components/bt/esp_ble_mesh/mesh_core/adv.c +++ b/components/bt/esp_ble_mesh/mesh_core/adv.c @@ -971,7 +971,7 @@ int bt_mesh_scan_with_wl_enable(void) BT_DBG("%s", __func__); err = bt_le_scan_start(&scan_param, bt_mesh_scan_cb); - if (err) { + if (err && err != -EALREADY) { BT_ERR("starting scan failed (err %d)", err); return err; } diff --git a/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c b/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c index a6c5f12c5..37afddaec 100644 --- a/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c +++ b/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c @@ -459,11 +459,10 @@ int bt_le_scan_start(const struct bt_mesh_scan_param *param, bt_mesh_scan_cb_t c { int err = 0; -#if BLE_MESH_DEV if (bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) { + BT_INFO("Scan is already started"); return -EALREADY; } -#endif if (!valid_scan_param(param)) { return -EINVAL; @@ -482,26 +481,24 @@ int bt_le_scan_start(const struct bt_mesh_scan_param *param, bt_mesh_scan_cb_t c return err; } -#if BLE_MESH_DEV bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING); -#endif - bt_mesh_scan_dev_found_cb = cb; - return err; + + return 0; } int bt_le_scan_stop(void) { -#if BLE_MESH_DEV - if (bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) { - bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING); - BLE_MESH_BTM_CHECK_STATUS(BTM_BleScan(false, 0, NULL, NULL, NULL)); + if (!bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) { + BT_INFO("Scan is already stopped"); + return -EALREADY; } -#else - BLE_MESH_BTM_CHECK_STATUS(BTM_BleScan(false, 0, NULL, NULL, NULL)); -#endif + BLE_MESH_BTM_CHECK_STATUS(BTM_BleScan(false, 0, NULL, NULL, NULL)); + + bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING); bt_mesh_scan_dev_found_cb = NULL; + return 0; } @@ -1198,13 +1195,10 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, u16_t service_uuid) return -ENOMEM; } -#if BLE_MESH_DEV - if (bt_mesh_atomic_test_and_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) { + if (bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) { BLE_MESH_BTM_CHECK_STATUS(BTM_BleScan(false, 0, NULL, NULL, NULL)); + bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING); } -#else - BLE_MESH_BTM_CHECK_STATUS(BTM_BleScan(false, 0, NULL, NULL, NULL)); -#endif /* BLE_MESH_DEV */ BT_DBG("%s, create conn with %s", __func__, bt_hex(addr->val, BLE_MESH_ADDR_LEN)); @@ -1608,30 +1602,20 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) break; case BTA_GATTC_EXEC_EVT: break; - case BTA_GATTC_OPEN_EVT: { + case BTA_GATTC_OPEN_EVT: BT_DBG("BTA_GATTC_OPEN_EVT"); - /** After current connection is established, provisioner can - * use BTA_DmBleScan() to re-enable scan. + /* After current connection is established, Provisioner can + * use BTM_BleScan() to re-enable scan. */ - tBTM_STATUS status; -#if BLE_MESH_DEV if (!bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) { - status = BTM_BleScan(true, 0, bt_mesh_scan_results_cb, NULL, NULL); + tBTM_STATUS status = BTM_BleScan(true, 0, bt_mesh_scan_results_cb, NULL, NULL); if (status != BTM_SUCCESS && status != BTM_CMD_STARTED) { - BT_ERR("%s, Invalid status %d", __func__, status); + BT_ERR("%s, Invalid scan status %d", __func__, status); break; } bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING); } -#else - status = BTM_BleScan(true, 0, bt_mesh_scan_results_cb, NULL, NULL); - if (status != BTM_SUCCESS && status != BTM_CMD_STARTED) { - BT_ERR("%s, Invalid status %d", __func__, status); - break; - } -#endif /* BLE_MESH_DEV */ break; - } case BTA_GATTC_CLOSE_EVT: BT_DBG("BTA_GATTC_CLOSE_EVT"); break; diff --git a/components/bt/esp_ble_mesh/mesh_core/main.c b/components/bt/esp_ble_mesh/mesh_core/main.c index bc583e75e..e536fa35e 100644 --- a/components/bt/esp_ble_mesh/mesh_core/main.c +++ b/components/bt/esp_ble_mesh/mesh_core/main.c @@ -81,9 +81,6 @@ int bt_mesh_provision(const u8_t net_key[16], u16_t net_idx, bt_mesh_store_iv(false); } - /* Add this to avoid "already active status" for bt_mesh_scan_enable() */ - bt_mesh_scan_disable(); - bt_mesh_net_start(); return 0; diff --git a/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c b/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c index 1b672aff8..0990c3f95 100644 --- a/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c +++ b/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c @@ -418,22 +418,14 @@ static int disc_cb(struct ble_gap_event *event, void *arg) } } } -#if BLE_MESH_DEV if (!bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) { rc = ble_gap_disc(BLE_OWN_ADDR_PUBLIC, BLE_HS_FOREVER, &scan_param, disc_cb, NULL); if (rc != 0) { - BT_ERR("%s, Invalid status %d", __func__, rc); + BT_ERR("%s, Invalid scan status %d", __func__, rc); break; } bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING); } -#else - rc = ble_gap_disc(BLE_OWN_ADDR_PUBLIC, BLE_HS_FOREVER, &scan_param, disc_cb, NULL); - if (rc != 0) { - BT_ERR("%s, Invalid status %d", __func__, rc); - break; - } -#endif /* BLE_MESH_DEV */ break; case BLE_GAP_EVENT_DISCONNECT: if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->disconnected != NULL) { @@ -937,11 +929,10 @@ int bt_le_scan_start(const struct bt_mesh_scan_param *param, bt_mesh_scan_cb_t c { int err; -#if BLE_MESH_DEV if (bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) { + BT_INFO("Scan is already started"); return -EALREADY; } -#endif #if BLE_MESH_DEV if (param->filter_dup) { @@ -956,26 +947,24 @@ int bt_le_scan_start(const struct bt_mesh_scan_param *param, bt_mesh_scan_cb_t c return err; } -#if BLE_MESH_DEV bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING); -#endif - bt_mesh_scan_dev_found_cb = cb; - return err; + + return 0; } int bt_le_scan_stop(void) { -#if BLE_MESH_DEV - if (bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) { - bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING); - ble_gap_disc_cancel(); + if (!bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) { + BT_INFO("Scan is already stopped"); + return -EALREADY; } -#else - ble_gap_disc_cancel(); -#endif + ble_gap_disc_cancel(); + + bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING); bt_mesh_scan_dev_found_cb = NULL; + return 0; } @@ -1419,19 +1408,13 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, u16_t service_uuid) return -ENOMEM; } -#if BLE_MESH_DEV - if (bt_mesh_atomic_test_and_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) { + if (bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) { rc = ble_gap_disc_cancel(); if (rc != 0) { return -1; } + bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING); } -#else - rc = ble_gap_disc_cancel(); - if (rc != 0) { - return -1; - } -#endif /* BLE_MESH_DEV */ BT_DBG("%s, create conn with %s", __func__, bt_hex(addr->val, BLE_MESH_ADDR_LEN)); From f6cc9afaa97b5f926d9457aff23f77ccb626ddb7 Mon Sep 17 00:00:00 2001 From: lly Date: Mon, 6 Jul 2020 20:46:14 +0800 Subject: [PATCH 32/60] ble_mesh: stack: Add proxy cfg pdu length check --- components/bt/esp_ble_mesh/mesh_core/proxy_client.c | 5 +++++ components/bt/esp_ble_mesh/mesh_core/proxy_server.c | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/components/bt/esp_ble_mesh/mesh_core/proxy_client.c b/components/bt/esp_ble_mesh/mesh_core/proxy_client.c index 215b443ce..e7870cd25 100644 --- a/components/bt/esp_ble_mesh/mesh_core/proxy_client.c +++ b/components/bt/esp_ble_mesh/mesh_core/proxy_client.c @@ -154,6 +154,11 @@ static void proxy_cfg(struct bt_mesh_proxy_server *server) u8_t opcode = 0U; int err = 0; + if (server->buf.len > 29) { + BT_ERR("Too large proxy cfg pdu (len %d)", server->buf.len); + return; + } + err = bt_mesh_net_decode(&server->buf, BLE_MESH_NET_IF_PROXY_CFG, &rx, &buf); if (err) { diff --git a/components/bt/esp_ble_mesh/mesh_core/proxy_server.c b/components/bt/esp_ble_mesh/mesh_core/proxy_server.c index 5f1ef084f..bf7f5145a 100644 --- a/components/bt/esp_ble_mesh/mesh_core/proxy_server.c +++ b/components/bt/esp_ble_mesh/mesh_core/proxy_server.c @@ -292,6 +292,11 @@ static void proxy_cfg(struct bt_mesh_proxy_client *client) u8_t opcode = 0U; int err = 0; + if (client->buf.len > 29) { + BT_ERR("Too large proxy cfg pdu (len %d)", client->buf.len); + return; + } + err = bt_mesh_net_decode(&client->buf, BLE_MESH_NET_IF_PROXY_CFG, &rx, &buf); if (err) { From 6ea6de8d42787831def5c2a02da25b4c203df0bf Mon Sep 17 00:00:00 2001 From: lly Date: Fri, 3 Jul 2020 20:00:36 +0800 Subject: [PATCH 33/60] ble_mesh: stack: Make proxy server & client functions clear --- .../bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c | 10 ++--- components/bt/esp_ble_mesh/mesh_core/adv.c | 28 ++++++------ components/bt/esp_ble_mesh/mesh_core/adv.h | 2 +- .../bt/esp_ble_mesh/mesh_core/cfg_srv.c | 6 +-- .../bt/esp_ble_mesh/mesh_core/fast_prov.c | 4 +- components/bt/esp_ble_mesh/mesh_core/main.c | 26 +++++------ components/bt/esp_ble_mesh/mesh_core/net.c | 19 ++++---- components/bt/esp_ble_mesh/mesh_core/prov.c | 4 +- .../esp_ble_mesh/mesh_core/provisioner_prov.c | 7 +-- .../esp_ble_mesh/mesh_core/provisioner_prov.h | 3 +- .../bt/esp_ble_mesh/mesh_core/proxy_client.c | 38 ++++++++-------- .../bt/esp_ble_mesh/mesh_core/proxy_client.h | 25 ++++++----- .../bt/esp_ble_mesh/mesh_core/proxy_server.c | 44 +++++++++---------- .../bt/esp_ble_mesh/mesh_core/proxy_server.h | 35 ++++++++------- .../bt/esp_ble_mesh/mesh_core/settings.c | 2 +- 15 files changed, 132 insertions(+), 121 deletions(-) diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c index 1535b6f44..048d112e1 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c @@ -1612,11 +1612,11 @@ void btc_ble_mesh_prov_call_handler(btc_msg_t *msg) break; case BTC_BLE_MESH_ACT_PROXY_GATT_ENABLE: act = ESP_BLE_MESH_NODE_PROXY_GATT_ENABLE_COMP_EVT; - param.node_proxy_gatt_enable_comp.err_code = bt_mesh_proxy_gatt_enable(); + param.node_proxy_gatt_enable_comp.err_code = bt_mesh_proxy_server_gatt_enable(); break; case BTC_BLE_MESH_ACT_PROXY_GATT_DISABLE: act = ESP_BLE_MESH_NODE_PROXY_GATT_DISABLE_COMP_EVT; - param.node_proxy_gatt_disable_comp.err_code = bt_mesh_proxy_gatt_disable(); + param.node_proxy_gatt_disable_comp.err_code = bt_mesh_proxy_server_gatt_disable(); break; #endif /* CONFIG_BLE_MESH_GATT_PROXY_SERVER */ #endif /* (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_SERVER */ @@ -1855,7 +1855,7 @@ void btc_ble_mesh_prov_call_handler(btc_msg_t *msg) param.proxy_client_set_filter_type_comp.conn_handle = arg->proxy_client_set_filter_type.conn_handle; param.proxy_client_set_filter_type_comp.net_idx = arg->proxy_client_set_filter_type.net_idx; param.proxy_client_set_filter_type_comp.err_code = - bt_mesh_proxy_client_send_cfg(arg->proxy_client_set_filter_type.conn_handle, + bt_mesh_proxy_client_cfg_send(arg->proxy_client_set_filter_type.conn_handle, arg->proxy_client_set_filter_type.net_idx, &pdu); break; } @@ -1869,7 +1869,7 @@ void btc_ble_mesh_prov_call_handler(btc_msg_t *msg) param.proxy_client_add_filter_addr_comp.conn_handle = arg->proxy_client_add_filter_addr.conn_handle; param.proxy_client_add_filter_addr_comp.net_idx = arg->proxy_client_add_filter_addr.net_idx; param.proxy_client_add_filter_addr_comp.err_code = - bt_mesh_proxy_client_send_cfg(arg->proxy_client_add_filter_addr.conn_handle, + bt_mesh_proxy_client_cfg_send(arg->proxy_client_add_filter_addr.conn_handle, arg->proxy_client_add_filter_addr.net_idx, &pdu); break; } @@ -1883,7 +1883,7 @@ void btc_ble_mesh_prov_call_handler(btc_msg_t *msg) param.proxy_client_remove_filter_addr_comp.conn_handle = arg->proxy_client_remove_filter_addr.conn_handle; param.proxy_client_remove_filter_addr_comp.net_idx = arg->proxy_client_remove_filter_addr.net_idx; param.proxy_client_remove_filter_addr_comp.err_code = - bt_mesh_proxy_client_send_cfg(arg->proxy_client_remove_filter_addr.conn_handle, + bt_mesh_proxy_client_cfg_send(arg->proxy_client_remove_filter_addr.conn_handle, arg->proxy_client_remove_filter_addr.net_idx, &pdu); break; } diff --git a/components/bt/esp_ble_mesh/mesh_core/adv.c b/components/bt/esp_ble_mesh/mesh_core/adv.c index 15838c6d8..2a393043e 100644 --- a/components/bt/esp_ble_mesh/mesh_core/adv.c +++ b/components/bt/esp_ble_mesh/mesh_core/adv.c @@ -258,11 +258,11 @@ static void adv_thread(void *p) while (!(*buf)) { s32_t timeout; BT_DBG("Mesh Proxy Advertising start"); - timeout = bt_mesh_proxy_adv_start(); + timeout = bt_mesh_proxy_server_adv_start(); BT_DBG("Mesh Proxy Advertising up to %d ms", timeout); xQueueReceive(adv_queue.handle, &msg, timeout); BT_DBG("Mesh Proxy Advertising stop"); - bt_mesh_proxy_adv_stop(); + bt_mesh_proxy_server_adv_stop(); } #else xQueueReceive(adv_queue.handle, &msg, portMAX_DELAY); @@ -281,11 +281,11 @@ static void adv_thread(void *p) while (!(*buf)) { s32_t timeout = 0; BT_DBG("Mesh Proxy Advertising start"); - timeout = bt_mesh_proxy_adv_start(); + timeout = bt_mesh_proxy_server_adv_start(); BT_DBG("Mesh Proxy Advertising up to %d ms", timeout); handle = xQueueSelectFromSet(mesh_queue_set, timeout); BT_DBG("Mesh Proxy Advertising stop"); - bt_mesh_proxy_adv_stop(); + bt_mesh_proxy_server_adv_stop(); if (handle) { if (uxQueueMessagesWaiting(adv_queue.handle)) { xQueueReceive(adv_queue.handle, &msg, K_NO_WAIT); @@ -590,14 +590,14 @@ u16_t bt_mesh_get_stored_relay_count(void) } #endif /* #if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */ -const bt_mesh_addr_t *bt_mesh_pba_get_addr(void) +const bt_mesh_addr_t *bt_mesh_get_unprov_dev_addr(void) { return dev_addr; } #if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \ CONFIG_BLE_MESH_GATT_PROXY_CLIENT -static bool bt_mesh_is_adv_flags_valid(struct net_buf_simple *buf) +static bool adv_flags_valid(struct net_buf_simple *buf) { u8_t flags = 0U; @@ -616,7 +616,7 @@ static bool bt_mesh_is_adv_flags_valid(struct net_buf_simple *buf) return true; } -static bool bt_mesh_is_adv_srv_uuid_valid(struct net_buf_simple *buf, u16_t *uuid) +static bool adv_service_uuid_valid(struct net_buf_simple *buf, u16_t *uuid) { if (buf->len != 2U) { BT_DBG("Length not match mesh service uuid"); @@ -649,7 +649,9 @@ static bool bt_mesh_is_adv_srv_uuid_valid(struct net_buf_simple *buf, u16_t *uui #define BLE_MESH_PROXY_SRV_DATA_LEN1 0x09 #define BLE_MESH_PROXY_SRV_DATA_LEN2 0x11 -static void bt_mesh_adv_srv_data_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr, u16_t uuid, s8_t rssi) +static void handle_adv_service_data(struct net_buf_simple *buf, + const bt_mesh_addr_t *addr, + u16_t uuid, s8_t rssi) { u16_t type = 0U; @@ -674,7 +676,7 @@ static void bt_mesh_adv_srv_data_recv(struct net_buf_simple *buf, const bt_mesh_ } BT_DBG("Start to handle Mesh Prov Service Data"); - bt_mesh_provisioner_prov_adv_ind_recv(buf, addr, rssi); + bt_mesh_provisioner_prov_adv_recv(buf, addr, rssi); } break; #endif @@ -687,7 +689,7 @@ static void bt_mesh_adv_srv_data_recv(struct net_buf_simple *buf, const bt_mesh_ } BT_DBG("Start to handle Mesh Proxy Service Data"); - bt_mesh_proxy_client_adv_ind_recv(buf, addr, rssi); + bt_mesh_proxy_client_gatt_adv_recv(buf, addr, rssi); break; #endif default: @@ -763,19 +765,19 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr, s8_t rssi, #if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \ CONFIG_BLE_MESH_GATT_PROXY_CLIENT case BLE_MESH_DATA_FLAGS: - if (!bt_mesh_is_adv_flags_valid(buf)) { + if (!adv_flags_valid(buf)) { BT_DBG("Adv Flags mismatch, ignore this adv pkt"); return; } break; case BLE_MESH_DATA_UUID16_ALL: - if (!bt_mesh_is_adv_srv_uuid_valid(buf, &uuid)) { + if (!adv_service_uuid_valid(buf, &uuid)) { BT_DBG("Adv Service UUID mismatch, ignore this adv pkt"); return; } break; case BLE_MESH_DATA_SVC_DATA16: - bt_mesh_adv_srv_data_recv(buf, addr, uuid, rssi); + handle_adv_service_data(buf, addr, uuid, rssi); break; #endif default: diff --git a/components/bt/esp_ble_mesh/mesh_core/adv.h b/components/bt/esp_ble_mesh/mesh_core/adv.h index e0ade0da3..47ede3bfb 100644 --- a/components/bt/esp_ble_mesh/mesh_core/adv.h +++ b/components/bt/esp_ble_mesh/mesh_core/adv.h @@ -78,7 +78,7 @@ void bt_mesh_unref_buf_from_pool(struct net_buf_pool *pool); void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, void *cb_data); -const bt_mesh_addr_t *bt_mesh_pba_get_addr(void); +const bt_mesh_addr_t *bt_mesh_get_unprov_dev_addr(void); struct net_buf *bt_mesh_relay_adv_create(enum bt_mesh_adv_type type, u8_t xmit, s32_t timeout); diff --git a/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c b/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c index 46b4a524e..6806daa4a 100644 --- a/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c +++ b/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c @@ -2211,7 +2211,7 @@ static void net_key_add(struct bt_mesh_model *model, if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) { sub->node_id = BLE_MESH_NODE_IDENTITY_STOPPED; - bt_mesh_proxy_beacon_send(sub); + bt_mesh_proxy_server_beacon_send(sub); bt_mesh_adv_update(); } else { sub->node_id = BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED; @@ -2472,9 +2472,9 @@ static void node_identity_set(struct bt_mesh_model *model, if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) { if (node_id) { - bt_mesh_proxy_identity_start(sub); + bt_mesh_proxy_server_identity_start(sub); } else { - bt_mesh_proxy_identity_stop(sub); + bt_mesh_proxy_server_identity_stop(sub); } bt_mesh_adv_update(); } diff --git a/components/bt/esp_ble_mesh/mesh_core/fast_prov.c b/components/bt/esp_ble_mesh/mesh_core/fast_prov.c index eb6437f92..cbb732658 100644 --- a/components/bt/esp_ble_mesh/mesh_core/fast_prov.c +++ b/components/bt/esp_ble_mesh/mesh_core/fast_prov.c @@ -165,7 +165,7 @@ u8_t bt_mesh_set_fast_prov_action(u8_t action) bt_mesh_beacon_disable(); } if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) { - bt_mesh_provisioner_pb_gatt_enable(); + bt_mesh_proxy_client_prov_enable(); } bt_mesh_provisioner_set_primary_elem_addr(bt_mesh_primary_addr()); bt_mesh_provisioner_set_prov_bearer(BLE_MESH_PROV_ADV, false); @@ -173,7 +173,7 @@ u8_t bt_mesh_set_fast_prov_action(u8_t action) bt_mesh_atomic_or(bt_mesh.flags, BIT(BLE_MESH_PROVISIONER) | BIT(BLE_MESH_VALID_PROV)); } else { if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) { - bt_mesh_provisioner_pb_gatt_disable(); + bt_mesh_proxy_client_prov_disable(); } if (bt_mesh_beacon_get() == BLE_MESH_BEACON_ENABLED) { bt_mesh_beacon_enable(); diff --git a/components/bt/esp_ble_mesh/mesh_core/main.c b/components/bt/esp_ble_mesh/mesh_core/main.c index e536fa35e..2a2b136b5 100644 --- a/components/bt/esp_ble_mesh/mesh_core/main.c +++ b/components/bt/esp_ble_mesh/mesh_core/main.c @@ -48,7 +48,7 @@ int bt_mesh_provision(const u8_t net_key[16], u16_t net_idx, } if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) { - if (bt_mesh_proxy_prov_disable(false) == 0) { + if (bt_mesh_proxy_server_prov_disable(false) == 0) { pb_gatt_enabled = true; } else { pb_gatt_enabled = false; @@ -62,7 +62,7 @@ int bt_mesh_provision(const u8_t net_key[16], u16_t net_idx, bt_mesh_atomic_clear_bit(bt_mesh.flags, BLE_MESH_VALID); if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) && pb_gatt_enabled) { - bt_mesh_proxy_prov_enable(); + bt_mesh_proxy_server_prov_enable(); } return err; @@ -114,7 +114,7 @@ void bt_mesh_node_reset(void) } if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) { - bt_mesh_proxy_gatt_disable(); + bt_mesh_proxy_server_gatt_disable(); } if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { @@ -210,7 +210,7 @@ int bt_mesh_prov_enable(bt_mesh_prov_bearer_t bearers) if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) && (bearers & BLE_MESH_PROV_GATT)) { - bt_mesh_proxy_prov_enable(); + bt_mesh_proxy_server_prov_enable(); bt_mesh_adv_update(); } @@ -241,7 +241,7 @@ int bt_mesh_prov_disable(bt_mesh_prov_bearer_t bearers) if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) && (bearers & BLE_MESH_PROV_GATT)) { - bt_mesh_proxy_prov_disable(true); + bt_mesh_proxy_server_prov_disable(true); } return 0; @@ -356,13 +356,13 @@ int bt_mesh_init(const struct bt_mesh_prov *prov, if ((IS_ENABLED(CONFIG_BLE_MESH_NODE) && IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) || IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) { - bt_mesh_proxy_init(); + bt_mesh_proxy_server_init(); } if ((IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) || IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)) { - bt_mesh_proxy_prov_client_init(); + bt_mesh_proxy_client_init(); } if (IS_ENABLED(CONFIG_BLE_MESH_PROV)) { @@ -427,13 +427,13 @@ int bt_mesh_deinit(struct bt_mesh_deinit_param *param) } if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) { - bt_mesh_proxy_prov_disable(true); + bt_mesh_proxy_server_prov_disable(true); } } if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en()) { if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) { - bt_mesh_provisioner_pb_gatt_disable(); + bt_mesh_proxy_client_prov_disable(); } bt_mesh_scan_disable(); @@ -463,13 +463,13 @@ int bt_mesh_deinit(struct bt_mesh_deinit_param *param) if ((IS_ENABLED(CONFIG_BLE_MESH_NODE) && IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) || IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) { - bt_mesh_proxy_deinit(); + bt_mesh_proxy_server_deinit(); } if ((IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) || IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)) { - bt_mesh_proxy_prov_client_deinit(); + bt_mesh_proxy_client_deinit(); } bt_mesh_gatt_deinit(); @@ -532,7 +532,7 @@ int bt_mesh_provisioner_net_start(bt_mesh_prov_bearer_t bearers) if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) && (bearers & BLE_MESH_PROV_GATT)) { - bt_mesh_provisioner_pb_gatt_enable(); + bt_mesh_proxy_client_prov_enable(); } bt_mesh_atomic_set_bit(bt_mesh.flags, BLE_MESH_VALID_PROV); @@ -608,7 +608,7 @@ int bt_mesh_provisioner_disable(bt_mesh_prov_bearer_t bearers) if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) && (enable & BLE_MESH_PROV_GATT) && (bearers & BLE_MESH_PROV_GATT)) { - bt_mesh_provisioner_pb_gatt_disable(); + bt_mesh_proxy_client_prov_disable(); #if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_REMOVE, BLE_MESH_EXCEP_INFO_MESH_PROV_ADV, NULL); diff --git a/components/bt/esp_ble_mesh/mesh_core/net.c b/components/bt/esp_ble_mesh/mesh_core/net.c index 548182e31..d9c109ccd 100644 --- a/components/bt/esp_ble_mesh/mesh_core/net.c +++ b/components/bt/esp_ble_mesh/mesh_core/net.c @@ -622,7 +622,7 @@ void bt_mesh_net_sec_update(struct bt_mesh_subnet *sub) if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) && bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_ENABLED) { - bt_mesh_proxy_beacon_send(sub); + bt_mesh_proxy_server_beacon_send(sub); } } @@ -808,7 +808,7 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf, } if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) && - bt_mesh_proxy_relay(&buf->b, dst) && + bt_mesh_proxy_server_relay(&buf->b, dst) && BLE_MESH_ADDR_IS_UNICAST(dst)) { send_cb_finalize(cb, cb_data); return 0; @@ -913,7 +913,7 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf, */ if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) && tx->ctx->send_ttl != 1U) { - if (bt_mesh_proxy_relay(&buf->b, tx->ctx->addr) && + if (bt_mesh_proxy_server_relay(&buf->b, tx->ctx->addr) && BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) { /* Notify completion if this only went * through the Mesh Proxy. @@ -925,9 +925,9 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf, } } -#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT - if (tx->ctx->send_ttl != 1U) { - if (bt_mesh_proxy_client_send(&buf->b, tx->ctx->addr)) { + if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT) && + tx->ctx->send_ttl != 1U) { + if (bt_mesh_proxy_client_relay(&buf->b, tx->ctx->addr)) { /* If Proxy Client succeeds to send messages with GATT bearer, * we can directly finish here. And if not, which means no * connection has been created with Proxy Client, here we will @@ -939,7 +939,6 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf, goto done; } } -#endif /* Deliver to local network interface if necessary */ if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned() && @@ -1284,7 +1283,7 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf, if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) && (bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_ENABLED || rx->net_if == BLE_MESH_NET_IF_LOCAL)) { - if (bt_mesh_proxy_relay(&buf->b, rx->ctx.recv_dst) && + if (bt_mesh_proxy_server_relay(&buf->b, rx->ctx.recv_dst) && BLE_MESH_ADDR_IS_UNICAST(rx->ctx.recv_dst)) { goto done; } @@ -1447,7 +1446,7 @@ void bt_mesh_net_recv(struct net_buf_simple *data, s8_t rssi, if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) && net_if == BLE_MESH_NET_IF_PROXY) { - bt_mesh_proxy_addr_add(data, rx.ctx.addr); + bt_mesh_proxy_server_addr_add(data, rx.ctx.addr); if (bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_DISABLED && !rx.local_match) { @@ -1516,7 +1515,7 @@ void bt_mesh_net_start(void) if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER) && bt_mesh_gatt_proxy_get() != BLE_MESH_GATT_PROXY_NOT_SUPPORTED) { - bt_mesh_proxy_gatt_enable(); + bt_mesh_proxy_server_gatt_enable(); bt_mesh_adv_update(); } diff --git a/components/bt/esp_ble_mesh/mesh_core/prov.c b/components/bt/esp_ble_mesh/mesh_core/prov.c index dcd990e29..cae80c1d1 100644 --- a/components/bt/esp_ble_mesh/mesh_core/prov.c +++ b/components/bt/esp_ble_mesh/mesh_core/prov.c @@ -242,7 +242,7 @@ static void reset_state(void) link.rx.prev_id = XACT_NVAL; #if defined(CONFIG_BLE_MESH_PB_GATT) - link.rx.buf = bt_mesh_proxy_get_buf(); + link.rx.buf = bt_mesh_proxy_server_get_buf(); #else net_buf_simple_reset(&rx_buf); link.rx.buf = &rx_buf; @@ -530,7 +530,7 @@ static int prov_send_gatt(struct net_buf_simple *msg) /* Changed by Espressif, add provisioning timeout timer operations. * When sending a provisioning PDU successfully, restart the 60s timer. */ - err = bt_mesh_proxy_send(link.conn, BLE_MESH_PROXY_PROV, msg); + err = bt_mesh_proxy_server_send(link.conn, BLE_MESH_PROXY_PROV, msg); if (err) { BT_ERR("%s, Failed to send provisioning PDU", __func__); return err; diff --git a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c index ec45b7afa..0e9550b53 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c @@ -1698,7 +1698,7 @@ static int prov_send_gatt(const u8_t idx, struct net_buf_simple *msg) return -ENOTCONN; } - err = bt_mesh_proxy_prov_client_send(link[idx].conn, BLE_MESH_PROXY_PROV, msg); + err = bt_mesh_proxy_client_send(link[idx].conn, BLE_MESH_PROXY_PROV, msg); if (err) { BT_ERR("%s, Failed to send PB-GATT pdu", __func__); return err; @@ -3453,7 +3453,7 @@ void bt_mesh_provisioner_unprov_beacon_recv(struct net_buf_simple *buf, s8_t rss return; } - addr = bt_mesh_pba_get_addr(); + addr = bt_mesh_get_unprov_dev_addr(); uuid = buf->data; net_buf_simple_pull(buf, 16); /* Mesh beacon uses big-endian to send beacon data */ @@ -3472,7 +3472,8 @@ void bt_mesh_provisioner_unprov_beacon_recv(struct net_buf_simple *buf, s8_t rss #endif /* CONFIG_BLE_MESH_PB_ADV */ } -void bt_mesh_provisioner_prov_adv_ind_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr, s8_t rssi) +void bt_mesh_provisioner_prov_adv_recv(struct net_buf_simple *buf, + const bt_mesh_addr_t *addr, s8_t rssi) { #if defined(CONFIG_BLE_MESH_PB_GATT) const u8_t *uuid = NULL; diff --git a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.h b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.h index 95eb46013..a09c342fe 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.h +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.h @@ -164,7 +164,8 @@ int bt_mesh_provisioner_prov_deinit(bool erase); */ void bt_mesh_provisioner_unprov_beacon_recv(struct net_buf_simple *buf, s8_t rssi); -void bt_mesh_provisioner_prov_adv_ind_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr, s8_t rssi); +void bt_mesh_provisioner_prov_adv_recv(struct net_buf_simple *buf, + const bt_mesh_addr_t *addr, s8_t rssi); /** * @brief This function gets the bt_mesh_prov pointer. diff --git a/components/bt/esp_ble_mesh/mesh_core/proxy_client.c b/components/bt/esp_ble_mesh/mesh_core/proxy_client.c index e7870cd25..7089da19c 100644 --- a/components/bt/esp_ble_mesh/mesh_core/proxy_client.c +++ b/components/bt/esp_ble_mesh/mesh_core/proxy_client.c @@ -373,8 +373,8 @@ static int proxy_segment_and_send(struct bt_mesh_conn *conn, u8_t type, return err; } -int bt_mesh_proxy_prov_client_send(struct bt_mesh_conn *conn, u8_t type, - struct net_buf_simple *msg) +int bt_mesh_proxy_client_send(struct bt_mesh_conn *conn, u8_t type, + struct net_buf_simple *msg) { struct bt_mesh_proxy_server *server = find_server(conn); @@ -491,7 +491,7 @@ static ssize_t prov_recv_ntf(struct bt_mesh_conn *conn, u8_t *data, u16_t len) return -EINVAL; } -int bt_mesh_provisioner_pb_gatt_enable(void) +int bt_mesh_proxy_client_prov_enable(void) { int i; @@ -506,7 +506,7 @@ int bt_mesh_provisioner_pb_gatt_enable(void) return 0; } -int bt_mesh_provisioner_pb_gatt_disable(void) +int bt_mesh_proxy_client_prov_disable(void) { int i; @@ -564,14 +564,14 @@ static ssize_t proxy_recv_ntf(struct bt_mesh_conn *conn, u8_t *data, u16_t len) } /** - * Currently proxy client doesn't need bt_mesh_proxy_client_enable() and - * bt_mesh_proxy_client_disable() functions, and once they are used, - * proxy client can be enabled to parse node_id_adv and net_id_adv in - * order to support proxy client role. + * Currently proxy client doesn't need bt_mesh_proxy_client_gatt_enable() + * and bt_mesh_proxy_client_gatt_disable() functions, and once they are + * used, proxy client can be enabled to parse node_id_adv and net_id_adv + * in order to support proxy client role. * And if gatt proxy is disabled, proxy client can stop handling these * two kinds of connectable advertising packets. */ -int bt_mesh_proxy_client_enable(void) +int bt_mesh_proxy_client_gatt_enable(void) { int i; @@ -593,7 +593,7 @@ int bt_mesh_proxy_client_enable(void) return 0; } -int bt_mesh_proxy_client_disable(void) +int bt_mesh_proxy_client_gatt_disable(void) { int i; @@ -650,7 +650,8 @@ static struct bt_mesh_subnet *bt_mesh_is_net_id_exist(const u8_t net_id[8]) return NULL; } -void bt_mesh_proxy_client_adv_ind_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr, s8_t rssi) +void bt_mesh_proxy_client_gatt_adv_recv(struct net_buf_simple *buf, + const bt_mesh_addr_t *addr, s8_t rssi) { bt_mesh_proxy_adv_ctx_t ctx = {0}; u8_t type = 0U; @@ -741,7 +742,7 @@ int bt_mesh_proxy_client_disconnect(u8_t conn_handle) return 0; } -bool bt_mesh_proxy_client_send(struct net_buf_simple *buf, u16_t dst) +bool bt_mesh_proxy_client_relay(struct net_buf_simple *buf, u16_t dst) { bool send = false; int err = 0; @@ -761,7 +762,7 @@ bool bt_mesh_proxy_client_send(struct net_buf_simple *buf, u16_t dst) net_buf_simple_init(&msg, 1); net_buf_simple_add_mem(&msg, buf->data, buf->len); - err = bt_mesh_proxy_prov_client_send(server->conn, BLE_MESH_PROXY_NET_PDU, &msg); + err = bt_mesh_proxy_client_send(server->conn, BLE_MESH_PROXY_NET_PDU, &msg); if (err) { BT_ERR("%s, Failed to send proxy net message (err %d)", __func__, err); } else { @@ -780,7 +781,7 @@ static int beacon_send(struct bt_mesh_conn *conn, struct bt_mesh_subnet *sub) net_buf_simple_init(&buf, 1); bt_mesh_beacon_create(sub, &buf); - return bt_mesh_proxy_prov_client_send(conn, BLE_MESH_PROXY_BEACON, &buf); + return bt_mesh_proxy_client_send(conn, BLE_MESH_PROXY_BEACON, &buf); } bool bt_mesh_proxy_client_beacon_send(struct bt_mesh_subnet *sub) @@ -922,7 +923,7 @@ static int send_proxy_cfg(struct bt_mesh_conn *conn, u16_t net_idx, struct bt_me return err; } - err = bt_mesh_proxy_prov_client_send(conn, BLE_MESH_PROXY_CONFIG, buf); + err = bt_mesh_proxy_client_send(conn, BLE_MESH_PROXY_CONFIG, buf); if (err) { BT_ERR("%s, Failed to send proxy cfg message (err %d)", __func__, err); } @@ -931,7 +932,8 @@ static int send_proxy_cfg(struct bt_mesh_conn *conn, u16_t net_idx, struct bt_me return err; } -int bt_mesh_proxy_client_send_cfg(u8_t conn_handle, u16_t net_idx, struct bt_mesh_proxy_cfg_pdu *pdu) +int bt_mesh_proxy_client_cfg_send(u8_t conn_handle, u16_t net_idx, + struct bt_mesh_proxy_cfg_pdu *pdu) { struct bt_mesh_conn *conn = NULL; @@ -962,7 +964,7 @@ int bt_mesh_proxy_client_send_cfg(u8_t conn_handle, u16_t net_idx, struct bt_mes } #endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */ -int bt_mesh_proxy_prov_client_init(void) +int bt_mesh_proxy_client_init(void) { int i; @@ -988,7 +990,7 @@ int bt_mesh_proxy_prov_client_init(void) return 0; } -int bt_mesh_proxy_prov_client_deinit(void) +int bt_mesh_proxy_client_deinit(void) { int i; diff --git a/components/bt/esp_ble_mesh/mesh_core/proxy_client.h b/components/bt/esp_ble_mesh/mesh_core/proxy_client.h index 5ca3ea703..521370be7 100644 --- a/components/bt/esp_ble_mesh/mesh_core/proxy_client.h +++ b/components/bt/esp_ble_mesh/mesh_core/proxy_client.h @@ -74,13 +74,14 @@ typedef struct { }; } bt_mesh_proxy_client_pdu_t; -int bt_mesh_proxy_prov_client_send(struct bt_mesh_conn *conn, u8_t type, struct net_buf_simple *msg); +int bt_mesh_proxy_client_send(struct bt_mesh_conn *conn, u8_t type, + struct net_buf_simple *msg); -int bt_mesh_provisioner_pb_gatt_enable(void); -int bt_mesh_provisioner_pb_gatt_disable(void); +int bt_mesh_proxy_client_prov_enable(void); +int bt_mesh_proxy_client_prov_disable(void); -int bt_mesh_proxy_client_enable(void); -int bt_mesh_proxy_client_disable(void); +int bt_mesh_proxy_client_gatt_enable(void); +int bt_mesh_proxy_client_gatt_disable(void); typedef void (*proxy_client_recv_adv_cb_t)(const bt_mesh_addr_t *addr, u8_t type, bt_mesh_proxy_adv_ctx_t *ctx, s8_t rssi); typedef void (*proxy_client_connect_cb_t)(const bt_mesh_addr_t *addr, u8_t conn_handle, u16_t net_idx); @@ -92,17 +93,21 @@ void bt_mesh_proxy_client_set_conn_cb(proxy_client_connect_cb_t cb); void bt_mesh_proxy_client_set_disconn_cb(proxy_client_disconnect_cb_t cb); void bt_mesh_proxy_client_set_filter_status_cb(proxy_client_recv_filter_status_cb_t cb); -void bt_mesh_proxy_client_adv_ind_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr, s8_t rssi); +void bt_mesh_proxy_client_gatt_adv_recv(struct net_buf_simple *buf, + const bt_mesh_addr_t *addr, s8_t rssi); int bt_mesh_proxy_client_connect(const u8_t addr[6], u8_t addr_type, u16_t net_idx); int bt_mesh_proxy_client_disconnect(u8_t conn_handle); bool bt_mesh_proxy_client_beacon_send(struct bt_mesh_subnet *sub); -bool bt_mesh_proxy_client_send(struct net_buf_simple *buf, u16_t dst); -int bt_mesh_proxy_client_send_cfg(u8_t conn_handle, u16_t net_idx, struct bt_mesh_proxy_cfg_pdu *pdu); -int bt_mesh_proxy_prov_client_init(void); -int bt_mesh_proxy_prov_client_deinit(void); +bool bt_mesh_proxy_client_relay(struct net_buf_simple *buf, u16_t dst); + +int bt_mesh_proxy_client_cfg_send(u8_t conn_handle, u16_t net_idx, + struct bt_mesh_proxy_cfg_pdu *pdu); + +int bt_mesh_proxy_client_init(void); +int bt_mesh_proxy_client_deinit(void); #ifdef __cplusplus } diff --git a/components/bt/esp_ble_mesh/mesh_core/proxy_server.c b/components/bt/esp_ble_mesh/mesh_core/proxy_server.c index bf7f5145a..bd0da41b4 100644 --- a/components/bt/esp_ble_mesh/mesh_core/proxy_server.c +++ b/components/bt/esp_ble_mesh/mesh_core/proxy_server.c @@ -370,7 +370,7 @@ static void proxy_send_beacons(struct k_work *work) } } -void bt_mesh_proxy_beacon_send(struct bt_mesh_subnet *sub) +void bt_mesh_proxy_server_beacon_send(struct bt_mesh_subnet *sub) { int i; @@ -378,7 +378,7 @@ void bt_mesh_proxy_beacon_send(struct bt_mesh_subnet *sub) /* NULL means we send on all subnets */ for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) { if (bt_mesh.sub[i].net_idx != BLE_MESH_KEY_UNUSED) { - bt_mesh_proxy_beacon_send(&bt_mesh.sub[i]); + bt_mesh_proxy_server_beacon_send(&bt_mesh.sub[i]); } } @@ -392,7 +392,7 @@ void bt_mesh_proxy_beacon_send(struct bt_mesh_subnet *sub) } } -void bt_mesh_proxy_identity_start(struct bt_mesh_subnet *sub) +void bt_mesh_proxy_server_identity_start(struct bt_mesh_subnet *sub) { sub->node_id = BLE_MESH_NODE_IDENTITY_RUNNING; sub->node_id_start = k_uptime_get_32(); @@ -401,7 +401,7 @@ void bt_mesh_proxy_identity_start(struct bt_mesh_subnet *sub) next_idx = sub - bt_mesh.sub; } -void bt_mesh_proxy_identity_stop(struct bt_mesh_subnet *sub) +void bt_mesh_proxy_server_identity_stop(struct bt_mesh_subnet *sub) { sub->node_id = BLE_MESH_NODE_IDENTITY_STOPPED; sub->node_id_start = 0U; @@ -428,7 +428,7 @@ int bt_mesh_proxy_identity_enable(void) continue; } - bt_mesh_proxy_identity_start(sub); + bt_mesh_proxy_server_identity_start(sub); count++; } @@ -624,7 +624,7 @@ static void proxy_disconnected(struct bt_mesh_conn *conn, u8_t reason) bt_mesh_adv_update(); } -struct net_buf_simple *bt_mesh_proxy_get_buf(void) +struct net_buf_simple *bt_mesh_proxy_server_get_buf(void) { struct net_buf_simple *buf = &clients[0].buf; @@ -697,7 +697,7 @@ static struct bt_mesh_gatt_attr prov_attrs[] = { struct bt_mesh_gatt_service prov_svc = BLE_MESH_GATT_SERVICE(prov_attrs); -int bt_mesh_proxy_prov_enable(void) +int bt_mesh_proxy_server_prov_enable(void) { int i; @@ -727,7 +727,7 @@ int bt_mesh_proxy_prov_enable(void) return 0; } -int bt_mesh_proxy_prov_disable(bool disconnect) +int bt_mesh_proxy_server_prov_disable(bool disconnect) { int i; @@ -832,7 +832,7 @@ static struct bt_mesh_gatt_attr proxy_attrs[] = { struct bt_mesh_gatt_service proxy_svc = BLE_MESH_GATT_SERVICE(proxy_attrs); -int bt_mesh_proxy_gatt_enable(void) +int bt_mesh_proxy_server_gatt_enable(void) { int i; @@ -860,7 +860,7 @@ int bt_mesh_proxy_gatt_enable(void) return 0; } -void bt_mesh_proxy_gatt_disconnect(void) +void bt_mesh_proxy_server_gatt_disconnect(void) { int i; @@ -877,7 +877,7 @@ void bt_mesh_proxy_gatt_disconnect(void) } } -int bt_mesh_proxy_gatt_disable(void) +int bt_mesh_proxy_server_gatt_disable(void) { BT_DBG("%s", __func__); @@ -891,7 +891,7 @@ int bt_mesh_proxy_gatt_disable(void) return -EBUSY; } - bt_mesh_proxy_gatt_disconnect(); + bt_mesh_proxy_server_gatt_disconnect(); bt_mesh_gatts_service_stop(&proxy_svc); gatt_svc = MESH_GATT_NONE; @@ -899,7 +899,7 @@ int bt_mesh_proxy_gatt_disable(void) return 0; } -void bt_mesh_proxy_addr_add(struct net_buf_simple *buf, u16_t addr) +void bt_mesh_proxy_server_addr_add(struct net_buf_simple *buf, u16_t addr) { struct bt_mesh_proxy_client *client = CONTAINER_OF(buf, struct bt_mesh_proxy_client, buf); @@ -945,7 +945,7 @@ static bool client_filter_match(struct bt_mesh_proxy_client *client, return false; } -bool bt_mesh_proxy_relay(struct net_buf_simple *buf, u16_t dst) +bool bt_mesh_proxy_server_relay(struct net_buf_simple *buf, u16_t dst) { bool relayed = false; int i; @@ -970,7 +970,7 @@ bool bt_mesh_proxy_relay(struct net_buf_simple *buf, u16_t dst) net_buf_simple_reserve(&msg, 1); net_buf_simple_add_mem(&msg, buf->data, buf->len); - bt_mesh_proxy_send(client->conn, BLE_MESH_PROXY_NET_PDU, &msg); + bt_mesh_proxy_server_send(client->conn, BLE_MESH_PROXY_NET_PDU, &msg); relayed = true; } @@ -1032,8 +1032,8 @@ static int proxy_segment_and_send(struct bt_mesh_conn *conn, u8_t type, return 0; } -int bt_mesh_proxy_send(struct bt_mesh_conn *conn, u8_t type, - struct net_buf_simple *msg) +int bt_mesh_proxy_server_send(struct bt_mesh_conn *conn, u8_t type, + struct net_buf_simple *msg) { struct bt_mesh_proxy_client *client = find_client(conn); @@ -1251,7 +1251,7 @@ static s32_t gatt_proxy_advertise(struct bt_mesh_subnet *sub) active, remaining); node_id_adv(sub); } else { - bt_mesh_proxy_identity_stop(sub); + bt_mesh_proxy_server_identity_stop(sub); BT_DBG("Node ID stopped"); } } @@ -1330,7 +1330,7 @@ static size_t gatt_prov_adv_create(struct bt_mesh_adv_data prov_sd[2]) } #endif /* CONFIG_BLE_MESH_PB_GATT */ -s32_t bt_mesh_proxy_adv_start(void) +s32_t bt_mesh_proxy_server_adv_start(void) { BT_DBG("%s", __func__); @@ -1374,7 +1374,7 @@ s32_t bt_mesh_proxy_adv_start(void) return K_FOREVER; } -void bt_mesh_proxy_adv_stop(void) +void bt_mesh_proxy_server_adv_stop(void) { int err = 0; @@ -1397,7 +1397,7 @@ static struct bt_mesh_conn_cb conn_callbacks = { .disconnected = proxy_disconnected, }; -int bt_mesh_proxy_init(void) +int bt_mesh_proxy_server_init(void) { int i; @@ -1425,7 +1425,7 @@ int bt_mesh_proxy_init(void) return bt_mesh_gatts_set_local_device_name(device_name); } -int bt_mesh_proxy_deinit(void) +int bt_mesh_proxy_server_deinit(void) { int i; diff --git a/components/bt/esp_ble_mesh/mesh_core/proxy_server.h b/components/bt/esp_ble_mesh/mesh_core/proxy_server.h index 724561f41..c8c277027 100644 --- a/components/bt/esp_ble_mesh/mesh_core/proxy_server.h +++ b/components/bt/esp_ble_mesh/mesh_core/proxy_server.h @@ -40,31 +40,32 @@ extern "C" { int bt_mesh_set_device_name(const char *name); -int bt_mesh_proxy_send(struct bt_mesh_conn *conn, u8_t type, - struct net_buf_simple *msg); +int bt_mesh_proxy_server_send(struct bt_mesh_conn *conn, u8_t type, + struct net_buf_simple *msg); -int bt_mesh_proxy_prov_enable(void); -int bt_mesh_proxy_prov_disable(bool disconnect); +int bt_mesh_proxy_server_prov_enable(void); +int bt_mesh_proxy_server_prov_disable(bool disconnect); -int bt_mesh_proxy_gatt_enable(void); -int bt_mesh_proxy_gatt_disable(void); -void bt_mesh_proxy_gatt_disconnect(void); +int bt_mesh_proxy_server_gatt_enable(void); +int bt_mesh_proxy_server_gatt_disable(void); -void bt_mesh_proxy_beacon_send(struct bt_mesh_subnet *sub); +void bt_mesh_proxy_server_gatt_disconnect(void); -struct net_buf_simple *bt_mesh_proxy_get_buf(void); +void bt_mesh_proxy_server_beacon_send(struct bt_mesh_subnet *sub); -s32_t bt_mesh_proxy_adv_start(void); -void bt_mesh_proxy_adv_stop(void); +struct net_buf_simple *bt_mesh_proxy_server_get_buf(void); -void bt_mesh_proxy_identity_start(struct bt_mesh_subnet *sub); -void bt_mesh_proxy_identity_stop(struct bt_mesh_subnet *sub); +s32_t bt_mesh_proxy_server_adv_start(void); +void bt_mesh_proxy_server_adv_stop(void); -bool bt_mesh_proxy_relay(struct net_buf_simple *buf, u16_t dst); -void bt_mesh_proxy_addr_add(struct net_buf_simple *buf, u16_t addr); +void bt_mesh_proxy_server_identity_start(struct bt_mesh_subnet *sub); +void bt_mesh_proxy_server_identity_stop(struct bt_mesh_subnet *sub); -int bt_mesh_proxy_init(void); -int bt_mesh_proxy_deinit(void); +bool bt_mesh_proxy_server_relay(struct net_buf_simple *buf, u16_t dst); +void bt_mesh_proxy_server_addr_add(struct net_buf_simple *buf, u16_t addr); + +int bt_mesh_proxy_server_init(void); +int bt_mesh_proxy_server_deinit(void); #ifdef __cplusplus } diff --git a/components/bt/esp_ble_mesh/mesh_core/settings.c b/components/bt/esp_ble_mesh/mesh_core/settings.c index ea15e02a9..f947db06c 100644 --- a/components/bt/esp_ble_mesh/mesh_core/settings.c +++ b/components/bt/esp_ble_mesh/mesh_core/settings.c @@ -1338,7 +1338,7 @@ int settings_core_commit(void) } if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) { - bt_mesh_proxy_prov_disable(true); + bt_mesh_proxy_server_prov_disable(true); } for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) { From ff1132d2e43d251e15cbcbe711ea2cf23b87f623 Mon Sep 17 00:00:00 2001 From: lly Date: Sat, 4 Jul 2020 18:35:08 +0800 Subject: [PATCH 34/60] ble_mesh: stack: Only keep func pointer for very common log Currently only keep func pointer for the followings: - Invalid parameter (mesh btc & mesh stack) - Out of memory (mesh btc & mesh stack) - Unknown act (mesh btc) - Invalid model user data (mesh stack) - BT_DBG("%s", __func__) (mesh btc & mesh stack) - A few other specific situations (buf ref debug, send status check) --- .../api/core/esp_ble_mesh_common_api.c | 4 +- .../esp_ble_mesh_local_data_operation_api.c | 8 +- .../api/core/esp_ble_mesh_networking_api.c | 46 +-- .../api/core/esp_ble_mesh_provisioning_api.c | 14 +- .../api/core/esp_ble_mesh_proxy_api.c | 15 +- .../esp_ble_mesh_local_data_operation_api.h | 8 +- .../include/esp_ble_mesh_networking_api.h | 29 +- .../include/esp_ble_mesh_provisioning_api.h | 18 +- .../api/core/include/esp_ble_mesh_proxy_api.h | 15 +- .../models/esp_ble_mesh_config_model_api.c | 4 +- .../models/esp_ble_mesh_generic_model_api.c | 4 +- .../models/esp_ble_mesh_health_model_api.c | 4 +- .../models/esp_ble_mesh_lighting_model_api.c | 4 +- .../models/esp_ble_mesh_sensor_model_api.c | 4 +- .../esp_ble_mesh_time_scene_model_api.c | 4 +- .../include/esp_ble_mesh_config_model_api.h | 8 +- .../include/esp_ble_mesh_generic_model_api.h | 8 +- .../include/esp_ble_mesh_health_model_api.h | 8 +- .../include/esp_ble_mesh_lighting_model_api.h | 8 +- .../include/esp_ble_mesh_sensor_model_api.h | 8 +- .../esp_ble_mesh_time_scene_model_api.h | 8 +- .../btc/btc_ble_mesh_config_model.c | 74 +++-- .../btc/btc_ble_mesh_generic_model.c | 87 +++-- .../btc/btc_ble_mesh_health_model.c | 62 ++-- .../btc/btc_ble_mesh_lighting_model.c | 69 ++-- .../bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c | 125 ++++---- .../btc/btc_ble_mesh_sensor_model.c | 107 +++---- .../btc/btc_ble_mesh_time_scene_model.c | 62 ++-- .../btc/include/btc_ble_mesh_config_model.h | 20 +- .../btc/include/btc_ble_mesh_generic_model.h | 20 +- .../btc/include/btc_ble_mesh_health_model.h | 16 +- .../btc/include/btc_ble_mesh_lighting_model.h | 20 +- .../btc/include/btc_ble_mesh_prov.h | 5 +- .../btc/include/btc_ble_mesh_sensor_model.h | 20 +- .../include/btc_ble_mesh_time_scene_model.h | 20 +- .../bt/esp_ble_mesh/mesh_common/mesh_buf.c | 10 +- .../bt/esp_ble_mesh/mesh_common/mesh_common.c | 4 +- .../bt/esp_ble_mesh/mesh_common/mesh_mutex.c | 8 +- .../bt/esp_ble_mesh/mesh_common/mesh_timer.c | 18 +- components/bt/esp_ble_mesh/mesh_core/access.c | 71 +++-- components/bt/esp_ble_mesh/mesh_core/access.h | 5 +- components/bt/esp_ble_mesh/mesh_core/adv.c | 72 ++--- components/bt/esp_ble_mesh/mesh_core/adv.h | 8 +- components/bt/esp_ble_mesh/mesh_core/beacon.c | 8 +- .../bluedroid_host/mesh_bearer_adapt.c | 127 ++++---- .../bt/esp_ble_mesh/mesh_core/cfg_cli.c | 12 +- .../bt/esp_ble_mesh/mesh_core/cfg_srv.c | 148 ++++----- components/bt/esp_ble_mesh/mesh_core/crypto.h | 2 +- .../bt/esp_ble_mesh/mesh_core/fast_prov.c | 8 +- components/bt/esp_ble_mesh/mesh_core/friend.c | 78 ++--- .../bt/esp_ble_mesh/mesh_core/health_cli.c | 12 +- .../bt/esp_ble_mesh/mesh_core/health_srv.c | 54 ++-- .../mesh_core/include/mesh_bearer_adapt.h | 19 +- .../esp_ble_mesh/mesh_core/local_operation.c | 4 +- components/bt/esp_ble_mesh/mesh_core/lpn.c | 8 +- components/bt/esp_ble_mesh/mesh_core/main.c | 8 +- components/bt/esp_ble_mesh/mesh_core/net.c | 40 +-- components/bt/esp_ble_mesh/mesh_core/net.h | 4 +- .../mesh_core/nimble_host/mesh_bearer_adapt.c | 69 ++-- components/bt/esp_ble_mesh/mesh_core/prov.c | 101 +++--- components/bt/esp_ble_mesh/mesh_core/prov.h | 3 +- .../esp_ble_mesh/mesh_core/provisioner_main.c | 138 ++++---- .../esp_ble_mesh/mesh_core/provisioner_main.h | 16 +- .../esp_ble_mesh/mesh_core/provisioner_prov.c | 244 ++++++++------- .../esp_ble_mesh/mesh_core/provisioner_prov.h | 8 +- .../bt/esp_ble_mesh/mesh_core/proxy_client.c | 65 ++-- .../bt/esp_ble_mesh/mesh_core/proxy_client.h | 12 +- .../bt/esp_ble_mesh/mesh_core/proxy_server.c | 26 +- .../bt/esp_ble_mesh/mesh_core/settings.c | 92 +++--- .../mesh_core/storage/settings_nvs.c | 40 +-- components/bt/esp_ble_mesh/mesh_core/test.c | 10 +- .../bt/esp_ble_mesh/mesh_core/transport.c | 72 ++--- .../mesh_models/client/client_common.c | 51 ++- .../mesh_models/client/generic_client.c | 118 +++---- .../client/include/client_common.h | 7 +- .../client/include/generic_client.h | 6 +- .../client/include/lighting_client.h | 6 +- .../client/include/sensor_client.h | 6 +- .../client/include/time_scene_client.h | 6 +- .../mesh_models/client/lighting_client.c | 164 +++++----- .../mesh_models/client/sensor_client.c | 74 ++--- .../mesh_models/client/time_scene_client.c | 90 +++--- .../mesh_models/server/device_property.c | 2 +- .../mesh_models/server/generic_server.c | 234 +++++++------- .../mesh_models/server/lighting_server.c | 296 +++++++++--------- .../mesh_models/server/sensor_server.c | 110 +++---- .../mesh_models/server/server_common.c | 22 +- .../mesh_models/server/state_binding.c | 50 +-- .../mesh_models/server/time_scene_server.c | 142 ++++----- 89 files changed, 1990 insertions(+), 1954 deletions(-) diff --git a/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_common_api.c b/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_common_api.c index 832e03dbb..09e453a2a 100644 --- a/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_common_api.c +++ b/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_common_api.c @@ -42,7 +42,7 @@ esp_err_t esp_ble_mesh_init(esp_ble_mesh_prov_t *prov, esp_ble_mesh_comp_t *comp // Create a semaphore if ((semaphore = xSemaphoreCreateCounting(1, 0)) == NULL) { - BT_ERR("%s, Failed to allocate memory for the semaphore", __func__); + BT_ERR("Failed to create semaphore"); return ESP_ERR_NO_MEM; } @@ -57,7 +57,7 @@ esp_err_t esp_ble_mesh_init(esp_ble_mesh_prov_t *prov, esp_ble_mesh_comp_t *comp if (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL) != BT_STATUS_SUCCESS) { vSemaphoreDelete(semaphore); - BT_ERR("%s, BLE Mesh initialise failed", __func__); + BT_ERR("Failed to start mesh init"); return ESP_FAIL; } diff --git a/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_local_data_operation_api.c b/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_local_data_operation_api.c index 943c91bff..568b07992 100644 --- a/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_local_data_operation_api.c +++ b/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_local_data_operation_api.c @@ -32,7 +32,8 @@ uint16_t esp_ble_mesh_get_primary_element_address(void) return btc_ble_mesh_get_primary_addr(); } -uint16_t *esp_ble_mesh_is_model_subscribed_to_group(esp_ble_mesh_model_t *model, uint16_t group_addr) +uint16_t *esp_ble_mesh_is_model_subscribed_to_group(esp_ble_mesh_model_t *model, + uint16_t group_addr) { if (model == NULL) { return NULL; @@ -54,7 +55,7 @@ uint8_t esp_ble_mesh_get_element_count(void) } esp_ble_mesh_model_t *esp_ble_mesh_find_vendor_model(const esp_ble_mesh_elem_t *element, - uint16_t company_id, uint16_t model_id) + uint16_t company_id, uint16_t model_id) { if (element == NULL) { return NULL; @@ -62,7 +63,8 @@ esp_ble_mesh_model_t *esp_ble_mesh_find_vendor_model(const esp_ble_mesh_elem_t * return btc_ble_mesh_model_find_vnd(element, company_id, model_id); } -esp_ble_mesh_model_t *esp_ble_mesh_find_sig_model(const esp_ble_mesh_elem_t *element, uint16_t model_id) +esp_ble_mesh_model_t *esp_ble_mesh_find_sig_model(const esp_ble_mesh_elem_t *element, + uint16_t model_id) { if (element == NULL) { return NULL; diff --git a/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_networking_api.c b/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_networking_api.c index cbfa0ad9a..f614798ca 100644 --- a/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_networking_api.c +++ b/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_networking_api.c @@ -23,12 +23,12 @@ #define ESP_BLE_MESH_TX_SDU_MAX ((CONFIG_BLE_MESH_ADV_BUF_COUNT - 3) * 12) static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model, - esp_ble_mesh_msg_ctx_t *ctx, - uint32_t opcode, - btc_ble_mesh_model_act_t act, - uint16_t length, uint8_t *data, - int32_t msg_timeout, bool need_rsp, - esp_ble_mesh_dev_role_t device_role) + esp_ble_mesh_msg_ctx_t *ctx, + uint32_t opcode, + btc_ble_mesh_model_act_t act, + uint16_t length, uint8_t *data, + int32_t msg_timeout, bool need_rsp, + esp_ble_mesh_dev_role_t device_role) { btc_ble_mesh_model_args_t arg = {0}; uint8_t op_len = 0, mic_len = 0; @@ -39,12 +39,12 @@ static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model, ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED); if (ctx && ctx->addr == ESP_BLE_MESH_ADDR_UNASSIGNED) { - BT_ERR("%s, Invalid destination address 0x0000", __func__); + BT_ERR("Invalid destination address 0x0000"); return ESP_ERR_INVALID_ARG; } if (device_role > ROLE_FAST_PROV) { - BT_ERR("%s, Invalid device role 0x%02x", __func__, device_role); + BT_ERR("Invalid device role 0x%02x", device_role); return ESP_ERR_INVALID_ARG; } @@ -63,7 +63,7 @@ static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model, if (act == BTC_BLE_MESH_ACT_MODEL_PUBLISH) { if (op_len + length > model->pub->msg->size) { - BT_ERR("%s, Model publication msg size %d is too small", __func__, model->pub->msg->size); + BT_ERR("Too small publication msg size %d", model->pub->msg->size); return ESP_ERR_INVALID_ARG; } } @@ -75,7 +75,7 @@ static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model, } if (op_len + length + mic_len > MIN(ESP_BLE_MESH_SDU_MAX_LEN, ESP_BLE_MESH_TX_SDU_MAX)) { - BT_ERR("%s, Data length %d is too large", __func__, length); + BT_ERR("Too large data length %d", length); return ESP_ERR_INVALID_ARG; } @@ -176,8 +176,9 @@ esp_err_t esp_ble_mesh_client_model_deinit(esp_ble_mesh_model_t *model) } esp_err_t esp_ble_mesh_server_model_send_msg(esp_ble_mesh_model_t *model, - esp_ble_mesh_msg_ctx_t *ctx, uint32_t opcode, - uint16_t length, uint8_t *data) + esp_ble_mesh_msg_ctx_t *ctx, + uint32_t opcode, + uint16_t length, uint8_t *data) { if (model == NULL || ctx == NULL || ctx->net_idx == ESP_BLE_MESH_KEY_UNUSED || @@ -190,9 +191,11 @@ esp_err_t esp_ble_mesh_server_model_send_msg(esp_ble_mesh_model_t *model, } esp_err_t esp_ble_mesh_client_model_send_msg(esp_ble_mesh_model_t *model, - esp_ble_mesh_msg_ctx_t *ctx, uint32_t opcode, - uint16_t length, uint8_t *data, int32_t msg_timeout, - bool need_rsp, esp_ble_mesh_dev_role_t device_role) + esp_ble_mesh_msg_ctx_t *ctx, + uint32_t opcode, + uint16_t length, uint8_t *data, + int32_t msg_timeout, bool need_rsp, + esp_ble_mesh_dev_role_t device_role) { if (model == NULL || ctx == NULL || ctx->net_idx == ESP_BLE_MESH_KEY_UNUSED || @@ -218,8 +221,8 @@ esp_err_t esp_ble_mesh_model_publish(esp_ble_mesh_model_t *model, uint32_t opcod } esp_err_t esp_ble_mesh_server_model_update_state(esp_ble_mesh_model_t *model, - esp_ble_mesh_server_state_type_t type, - esp_ble_mesh_server_state_value_t *value) + esp_ble_mesh_server_state_type_t type, + esp_ble_mesh_server_state_value_t *value) { btc_ble_mesh_model_args_t arg = {0}; btc_msg_t msg = {0}; @@ -294,7 +297,8 @@ uint16_t esp_ble_mesh_provisioner_get_node_index(const char *name) return bt_mesh_provisioner_get_node_index(name); } -esp_err_t esp_ble_mesh_provisioner_store_node_comp_data(uint16_t unicast_addr, uint8_t *data, uint16_t length) +esp_err_t esp_ble_mesh_provisioner_store_node_comp_data(uint16_t unicast_addr, + uint8_t *data, uint16_t length) { btc_ble_mesh_prov_args_t arg = {0}; btc_msg_t msg = {0}; @@ -396,7 +400,7 @@ esp_err_t esp_ble_mesh_provisioner_delete_node_with_addr(uint16_t unicast_addr) } esp_err_t esp_ble_mesh_provisioner_add_local_app_key(const uint8_t app_key[16], - uint16_t net_idx, uint16_t app_idx) + uint16_t net_idx, uint16_t app_idx) { btc_ble_mesh_prov_args_t arg = {0}; btc_msg_t msg = {0}; @@ -419,7 +423,7 @@ esp_err_t esp_ble_mesh_provisioner_add_local_app_key(const uint8_t app_key[16], } esp_err_t esp_ble_mesh_provisioner_update_local_app_key(const uint8_t app_key[16], - uint16_t net_idx, uint16_t app_idx) + uint16_t net_idx, uint16_t app_idx) { btc_ble_mesh_prov_args_t arg = {0}; btc_msg_t msg = {0}; @@ -447,7 +451,7 @@ const uint8_t *esp_ble_mesh_provisioner_get_local_app_key(uint16_t net_idx, uint } esp_err_t esp_ble_mesh_provisioner_bind_app_key_to_local_model(uint16_t element_addr, uint16_t app_idx, - uint16_t model_id, uint16_t company_id) + uint16_t model_id, uint16_t company_id) { btc_ble_mesh_prov_args_t arg = {0}; btc_msg_t msg = {0}; diff --git a/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_provisioning_api.c b/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_provisioning_api.c index e0242de72..c34b9a4f0 100644 --- a/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_provisioning_api.c +++ b/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_provisioning_api.c @@ -90,7 +90,7 @@ esp_err_t esp_ble_mesh_node_prov_disable(esp_ble_mesh_prov_bearer_t bearers) } esp_err_t esp_ble_mesh_node_set_oob_pub_key(uint8_t pub_key_x[32], uint8_t pub_key_y[32], - uint8_t private_key[32]) + uint8_t private_key[32]) { btc_ble_mesh_prov_args_t arg = {0}; btc_msg_t msg = {0}; @@ -179,7 +179,7 @@ esp_err_t esp_ble_mesh_set_unprovisioned_device_name(const char *name) #if (CONFIG_BLE_MESH_PROVISIONER) esp_err_t esp_ble_mesh_provisioner_read_oob_pub_key(uint8_t link_idx, uint8_t pub_key_x[32], - uint8_t pub_key_y[32]) + uint8_t pub_key_y[32]) { btc_ble_mesh_prov_args_t arg = {0}; btc_msg_t msg = {0}; @@ -292,7 +292,7 @@ esp_err_t esp_ble_mesh_provisioner_prov_disable(esp_ble_mesh_prov_bearer_t beare } esp_err_t esp_ble_mesh_provisioner_add_unprov_dev(esp_ble_mesh_unprov_dev_add_t *add_dev, - esp_ble_mesh_dev_add_flag_t flags) + esp_ble_mesh_dev_add_flag_t flags) { btc_ble_mesh_prov_args_t arg = {0}; btc_msg_t msg = {0}; @@ -318,8 +318,10 @@ esp_err_t esp_ble_mesh_provisioner_add_unprov_dev(esp_ble_mesh_unprov_dev_add_t } esp_err_t esp_ble_mesh_provisioner_prov_device_with_addr(const uint8_t uuid[16], - esp_ble_mesh_bd_addr_t addr, esp_ble_mesh_addr_type_t addr_type, - esp_ble_mesh_prov_bearer_t bearer, uint16_t oob_info, uint16_t unicast_addr) + esp_ble_mesh_bd_addr_t addr, + esp_ble_mesh_addr_type_t addr_type, + esp_ble_mesh_prov_bearer_t bearer, + uint16_t oob_info, uint16_t unicast_addr) { btc_ble_mesh_prov_args_t arg = {0}; btc_msg_t msg = {0}; @@ -377,7 +379,7 @@ esp_err_t esp_ble_mesh_provisioner_delete_dev(esp_ble_mesh_device_delete_t *del_ } esp_err_t esp_ble_mesh_provisioner_set_dev_uuid_match(const uint8_t *match_val, uint8_t match_len, - uint8_t offset, bool prov_after_match) + uint8_t offset, bool prov_after_match) { btc_ble_mesh_prov_args_t arg = {0}; btc_msg_t msg = {0}; diff --git a/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_proxy_api.c b/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_proxy_api.c index 31a3aa9ab..75d5519cd 100644 --- a/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_proxy_api.c +++ b/components/bt/esp_ble_mesh/api/core/esp_ble_mesh_proxy_api.c @@ -60,7 +60,8 @@ esp_err_t esp_ble_mesh_proxy_gatt_disable(void) } esp_err_t esp_ble_mesh_proxy_client_connect(esp_ble_mesh_bd_addr_t addr, - esp_ble_mesh_addr_type_t addr_type, uint16_t net_idx) + esp_ble_mesh_addr_type_t addr_type, + uint16_t net_idx) { btc_ble_mesh_prov_args_t arg = {0}; btc_msg_t msg = {0}; @@ -100,8 +101,8 @@ esp_err_t esp_ble_mesh_proxy_client_disconnect(uint8_t conn_handle) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } -esp_err_t esp_ble_mesh_proxy_client_set_filter_type(uint8_t conn_handle, - uint16_t net_idx, esp_ble_mesh_proxy_filter_type_t filter_type) +esp_err_t esp_ble_mesh_proxy_client_set_filter_type(uint8_t conn_handle, uint16_t net_idx, + esp_ble_mesh_proxy_filter_type_t filter_type) { btc_ble_mesh_prov_args_t arg = {0}; btc_msg_t msg = {0}; @@ -124,8 +125,8 @@ esp_err_t esp_ble_mesh_proxy_client_set_filter_type(uint8_t conn_handle, == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } -esp_err_t esp_ble_mesh_proxy_client_add_filter_addr(uint8_t conn_handle, - uint16_t net_idx, uint16_t *addr, uint16_t addr_num) +esp_err_t esp_ble_mesh_proxy_client_add_filter_addr(uint8_t conn_handle, uint16_t net_idx, + uint16_t *addr, uint16_t addr_num) { btc_ble_mesh_prov_args_t arg = {0}; btc_msg_t msg = {0}; @@ -149,8 +150,8 @@ esp_err_t esp_ble_mesh_proxy_client_add_filter_addr(uint8_t conn_handle, == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } -esp_err_t esp_ble_mesh_proxy_client_remove_filter_addr(uint8_t conn_handle, - uint16_t net_idx, uint16_t *addr, uint16_t addr_num) +esp_err_t esp_ble_mesh_proxy_client_remove_filter_addr(uint8_t conn_handle, uint16_t net_idx, + uint16_t *addr, uint16_t addr_num) { btc_ble_mesh_prov_args_t arg = {0}; btc_msg_t msg = {0}; diff --git a/components/bt/esp_ble_mesh/api/core/include/esp_ble_mesh_local_data_operation_api.h b/components/bt/esp_ble_mesh/api/core/include/esp_ble_mesh_local_data_operation_api.h index 0cd702e69..7dd4f7a54 100644 --- a/components/bt/esp_ble_mesh/api/core/include/esp_ble_mesh_local_data_operation_api.h +++ b/components/bt/esp_ble_mesh/api/core/include/esp_ble_mesh_local_data_operation_api.h @@ -55,7 +55,8 @@ uint16_t esp_ble_mesh_get_primary_element_address(void); * to 0x0000 in order to unsubscribe the model from the group. * */ -uint16_t *esp_ble_mesh_is_model_subscribed_to_group(esp_ble_mesh_model_t *model, uint16_t group_addr); +uint16_t *esp_ble_mesh_is_model_subscribed_to_group(esp_ble_mesh_model_t *model, + uint16_t group_addr); /** * @brief Find the BLE Mesh element pointer via the element address. @@ -87,7 +88,7 @@ uint8_t esp_ble_mesh_get_element_count(void); * */ esp_ble_mesh_model_t *esp_ble_mesh_find_vendor_model(const esp_ble_mesh_elem_t *element, - uint16_t company_id, uint16_t model_id); + uint16_t company_id, uint16_t model_id); /** * @brief Find the SIG model with the given element and Model id. @@ -98,7 +99,8 @@ esp_ble_mesh_model_t *esp_ble_mesh_find_vendor_model(const esp_ble_mesh_elem_t * * @return Pointer to the SIG Model on success, or NULL on failure which means the SIG Model is not found. * */ -esp_ble_mesh_model_t *esp_ble_mesh_find_sig_model(const esp_ble_mesh_elem_t *element, uint16_t model_id); +esp_ble_mesh_model_t *esp_ble_mesh_find_sig_model(const esp_ble_mesh_elem_t *element, + uint16_t model_id); /** * @brief Get the Composition data which has been registered. diff --git a/components/bt/esp_ble_mesh/api/core/include/esp_ble_mesh_networking_api.h b/components/bt/esp_ble_mesh/api/core/include/esp_ble_mesh_networking_api.h index 3a74a2575..86db8a1da 100644 --- a/components/bt/esp_ble_mesh/api/core/include/esp_ble_mesh_networking_api.h +++ b/components/bt/esp_ble_mesh/api/core/include/esp_ble_mesh_networking_api.h @@ -23,7 +23,7 @@ extern "C" { /** @brief: event, event code of user-defined model events; param, parameters of user-defined model events */ typedef void (* esp_ble_mesh_model_cb_t)(esp_ble_mesh_model_cb_event_t event, - esp_ble_mesh_model_cb_param_t *param); + esp_ble_mesh_model_cb_param_t *param); /** * @brief Register BLE Mesh callback for user-defined models' operations. @@ -104,8 +104,9 @@ esp_err_t esp_ble_mesh_client_model_deinit(esp_ble_mesh_model_t *model); * */ esp_err_t esp_ble_mesh_server_model_send_msg(esp_ble_mesh_model_t *model, - esp_ble_mesh_msg_ctx_t *ctx, uint32_t opcode, - uint16_t length, uint8_t *data); + esp_ble_mesh_msg_ctx_t *ctx, + uint32_t opcode, + uint16_t length, uint8_t *data); /** * @brief Send client model message (such as model get, set, etc). @@ -123,9 +124,11 @@ esp_err_t esp_ble_mesh_server_model_send_msg(esp_ble_mesh_model_t *model, * */ esp_err_t esp_ble_mesh_client_model_send_msg(esp_ble_mesh_model_t *model, - esp_ble_mesh_msg_ctx_t *ctx, uint32_t opcode, - uint16_t length, uint8_t *data, int32_t msg_timeout, - bool need_rsp, esp_ble_mesh_dev_role_t device_role); + esp_ble_mesh_msg_ctx_t *ctx, + uint32_t opcode, + uint16_t length, uint8_t *data, + int32_t msg_timeout, bool need_rsp, + esp_ble_mesh_dev_role_t device_role); /** * @brief Send a model publication message. @@ -166,8 +169,8 @@ esp_err_t esp_ble_mesh_model_publish(esp_ble_mesh_model_t *model, uint32_t opcod * */ esp_err_t esp_ble_mesh_server_model_update_state(esp_ble_mesh_model_t *model, - esp_ble_mesh_server_state_type_t type, - esp_ble_mesh_server_state_value_t *value); + esp_ble_mesh_server_state_type_t type, + esp_ble_mesh_server_state_value_t *value); /** * @brief Reset the provisioning procedure of the local BLE Mesh node. @@ -226,7 +229,8 @@ uint16_t esp_ble_mesh_provisioner_get_node_index(const char *name); * @return ESP_OK on success or error code otherwise. * */ -esp_err_t esp_ble_mesh_provisioner_store_node_comp_data(uint16_t unicast_addr, uint8_t *data, uint16_t length); +esp_err_t esp_ble_mesh_provisioner_store_node_comp_data(uint16_t unicast_addr, + uint8_t *data, uint16_t length); /** * @brief This function is called to get the provisioned node information @@ -329,7 +333,8 @@ esp_err_t esp_ble_mesh_provisioner_delete_node_with_addr(uint16_t unicast_addr); * @return ESP_OK on success or error code otherwise. * */ -esp_err_t esp_ble_mesh_provisioner_add_local_app_key(const uint8_t app_key[16], uint16_t net_idx, uint16_t app_idx); +esp_err_t esp_ble_mesh_provisioner_add_local_app_key(const uint8_t app_key[16], + uint16_t net_idx, uint16_t app_idx); /** * @brief This function is used to update a local AppKey for Provisioner. @@ -342,7 +347,7 @@ esp_err_t esp_ble_mesh_provisioner_add_local_app_key(const uint8_t app_key[16], * */ esp_err_t esp_ble_mesh_provisioner_update_local_app_key(const uint8_t app_key[16], - uint16_t net_idx, uint16_t app_idx); + uint16_t net_idx, uint16_t app_idx); /** * @brief This function is called by Provisioner to get the local app key value. @@ -370,7 +375,7 @@ const uint8_t *esp_ble_mesh_provisioner_get_local_app_key(uint16_t net_idx, uint * */ esp_err_t esp_ble_mesh_provisioner_bind_app_key_to_local_model(uint16_t element_addr, uint16_t app_idx, - uint16_t model_id, uint16_t company_id); + uint16_t model_id, uint16_t company_id); /** * @brief This function is called by Provisioner to add local network key. diff --git a/components/bt/esp_ble_mesh/api/core/include/esp_ble_mesh_provisioning_api.h b/components/bt/esp_ble_mesh/api/core/include/esp_ble_mesh_provisioning_api.h index 1df936390..194efcfb9 100644 --- a/components/bt/esp_ble_mesh/api/core/include/esp_ble_mesh_provisioning_api.h +++ b/components/bt/esp_ble_mesh/api/core/include/esp_ble_mesh_provisioning_api.h @@ -76,7 +76,7 @@ esp_err_t esp_ble_mesh_node_prov_disable(esp_ble_mesh_prov_bearer_t bearers); * @return ESP_OK on success or error code otherwise. */ esp_err_t esp_ble_mesh_node_set_oob_pub_key(uint8_t pub_key_x[32], uint8_t pub_key_y[32], - uint8_t private_key[32]); + uint8_t private_key[32]); /** * @brief Provide provisioning input OOB number. @@ -128,7 +128,7 @@ esp_err_t esp_ble_mesh_set_unprovisioned_device_name(const char *name); * @return ESP_OK on success or error code otherwise. */ esp_err_t esp_ble_mesh_provisioner_read_oob_pub_key(uint8_t link_idx, uint8_t pub_key_x[32], - uint8_t pub_key_y[32]); + uint8_t pub_key_y[32]); /** * @brief Provide provisioning input OOB string. @@ -232,7 +232,7 @@ esp_err_t esp_ble_mesh_provisioner_prov_disable(esp_ble_mesh_prov_bearer_t beare * */ esp_err_t esp_ble_mesh_provisioner_add_unprov_dev(esp_ble_mesh_unprov_dev_add_t *add_dev, - esp_ble_mesh_dev_add_flag_t flags); + esp_ble_mesh_dev_add_flag_t flags); /** @brief Provision an unprovisioned device with fixed unicast address. * @@ -257,8 +257,10 @@ esp_err_t esp_ble_mesh_provisioner_add_unprov_dev(esp_ble_mesh_unprov_dev_add_t * and "esp_ble_mesh_provisioner_prov_device_with_addr" by a Provisioner. */ esp_err_t esp_ble_mesh_provisioner_prov_device_with_addr(const uint8_t uuid[16], - esp_ble_mesh_bd_addr_t addr, esp_ble_mesh_addr_type_t addr_type, - esp_ble_mesh_prov_bearer_t bearer, uint16_t oob_info, uint16_t unicast_addr); + esp_ble_mesh_bd_addr_t addr, + esp_ble_mesh_addr_type_t addr_type, + esp_ble_mesh_prov_bearer_t bearer, + uint16_t oob_info, uint16_t unicast_addr); /** * @brief Delete device from queue, reset current provisioning link and reset the node. @@ -290,8 +292,8 @@ esp_err_t esp_ble_mesh_provisioner_delete_dev(esp_ble_mesh_device_delete_t *del_ * */ typedef void (*esp_ble_mesh_prov_adv_cb_t)(const esp_ble_mesh_bd_addr_t addr, const esp_ble_mesh_addr_type_t addr_type, - const uint8_t adv_type, const uint8_t *dev_uuid, - uint16_t oob_info, esp_ble_mesh_prov_bearer_t bearer); + const uint8_t adv_type, const uint8_t *dev_uuid, + uint16_t oob_info, esp_ble_mesh_prov_bearer_t bearer); /** * @brief This function is called by Provisioner to set the part of the device UUID @@ -307,7 +309,7 @@ typedef void (*esp_ble_mesh_prov_adv_cb_t)(const esp_ble_mesh_bd_addr_t addr, co * */ esp_err_t esp_ble_mesh_provisioner_set_dev_uuid_match(const uint8_t *match_val, uint8_t match_len, - uint8_t offset, bool prov_after_match); + uint8_t offset, bool prov_after_match); /** * @brief This function is called by Provisioner to set provisioning data information diff --git a/components/bt/esp_ble_mesh/api/core/include/esp_ble_mesh_proxy_api.h b/components/bt/esp_ble_mesh/api/core/include/esp_ble_mesh_proxy_api.h index 00537558c..6f6f4d0c1 100644 --- a/components/bt/esp_ble_mesh/api/core/include/esp_ble_mesh_proxy_api.h +++ b/components/bt/esp_ble_mesh/api/core/include/esp_ble_mesh_proxy_api.h @@ -65,7 +65,8 @@ esp_err_t esp_ble_mesh_proxy_gatt_disable(void); * */ esp_err_t esp_ble_mesh_proxy_client_connect(esp_ble_mesh_bd_addr_t addr, - esp_ble_mesh_addr_type_t addr_type, uint16_t net_idx); + esp_ble_mesh_addr_type_t addr_type, + uint16_t net_idx); /** * @brief Proxy Client terminates a connection with the Proxy Server. @@ -87,8 +88,8 @@ esp_err_t esp_ble_mesh_proxy_client_disconnect(uint8_t conn_handle); * @return ESP_OK on success or error code otherwise. * */ -esp_err_t esp_ble_mesh_proxy_client_set_filter_type(uint8_t conn_handle, - uint16_t net_idx, esp_ble_mesh_proxy_filter_type_t filter_type); +esp_err_t esp_ble_mesh_proxy_client_set_filter_type(uint8_t conn_handle, uint16_t net_idx, + esp_ble_mesh_proxy_filter_type_t filter_type); /** * @brief Proxy Client adds address to the Proxy Server filter list. @@ -101,8 +102,8 @@ esp_err_t esp_ble_mesh_proxy_client_set_filter_type(uint8_t conn_handle, * @return ESP_OK on success or error code otherwise. * */ -esp_err_t esp_ble_mesh_proxy_client_add_filter_addr(uint8_t conn_handle, - uint16_t net_idx, uint16_t *addr, uint16_t addr_num); +esp_err_t esp_ble_mesh_proxy_client_add_filter_addr(uint8_t conn_handle, uint16_t net_idx, + uint16_t *addr, uint16_t addr_num); /** * @brief Proxy Client removes address from the Proxy Server filter list. @@ -115,8 +116,8 @@ esp_err_t esp_ble_mesh_proxy_client_add_filter_addr(uint8_t conn_handle, * @return ESP_OK on success or error code otherwise. * */ -esp_err_t esp_ble_mesh_proxy_client_remove_filter_addr(uint8_t conn_handle, - uint16_t net_idx, uint16_t *addr, uint16_t addr_num); +esp_err_t esp_ble_mesh_proxy_client_remove_filter_addr(uint8_t conn_handle, uint16_t net_idx, + uint16_t *addr, uint16_t addr_num); #ifdef __cplusplus } diff --git a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_config_model_api.c b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_config_model_api.c index c41933984..e0807815c 100644 --- a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_config_model_api.c +++ b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_config_model_api.c @@ -53,7 +53,7 @@ static bool config_client_get_need_param(esp_ble_mesh_opcode_t opcode) } 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) + esp_ble_mesh_cfg_client_get_state_t *get_state) { btc_ble_mesh_config_client_args_t arg = {0}; btc_msg_t msg = {0}; @@ -78,7 +78,7 @@ esp_err_t esp_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_ } 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) + esp_ble_mesh_cfg_client_set_state_t *set_state) { btc_ble_mesh_config_client_args_t arg = {0}; btc_msg_t msg = {0}; diff --git a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_generic_model_api.c b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_generic_model_api.c index b93a1f97f..27a55cbb8 100644 --- a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_generic_model_api.c +++ b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_generic_model_api.c @@ -40,7 +40,7 @@ static bool generic_client_get_need_param(esp_ble_mesh_opcode_t opcode) } esp_err_t esp_ble_mesh_generic_client_get_state(esp_ble_mesh_client_common_param_t *params, - esp_ble_mesh_generic_client_get_state_t *get_state) + esp_ble_mesh_generic_client_get_state_t *get_state) { btc_ble_mesh_generic_client_args_t arg = {0}; btc_msg_t msg = {0}; @@ -66,7 +66,7 @@ esp_err_t esp_ble_mesh_generic_client_get_state(esp_ble_mesh_client_common_param } esp_err_t esp_ble_mesh_generic_client_set_state(esp_ble_mesh_client_common_param_t *params, - esp_ble_mesh_generic_client_set_state_t *set_state) + esp_ble_mesh_generic_client_set_state_t *set_state) { btc_ble_mesh_generic_client_args_t arg = {0}; btc_msg_t msg = {0}; diff --git a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_health_model_api.c b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_health_model_api.c index 7c3b666f6..dd6029411 100644 --- a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_health_model_api.c +++ b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_health_model_api.c @@ -34,7 +34,7 @@ esp_err_t esp_ble_mesh_register_health_server_callback(esp_ble_mesh_health_serve } esp_err_t esp_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_get_state_t *get_state) { btc_ble_mesh_health_client_args_t arg = {0}; btc_msg_t msg = {0}; @@ -60,7 +60,7 @@ esp_err_t esp_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param_ } esp_err_t esp_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_set_state_t *set_state) { btc_ble_mesh_health_client_args_t arg = {0}; btc_msg_t msg = {0}; diff --git a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_lighting_model_api.c b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_lighting_model_api.c index 127941b41..02262f8cf 100644 --- a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_lighting_model_api.c +++ b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_lighting_model_api.c @@ -27,7 +27,7 @@ esp_err_t esp_ble_mesh_register_light_client_callback(esp_ble_mesh_light_client_ } 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) + esp_ble_mesh_light_client_get_state_t *get_state) { btc_ble_mesh_lighting_client_args_t arg = {0}; btc_msg_t msg = {0}; @@ -53,7 +53,7 @@ esp_err_t esp_ble_mesh_light_client_get_state(esp_ble_mesh_client_common_param_t } 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) + esp_ble_mesh_light_client_set_state_t *set_state) { btc_ble_mesh_lighting_client_args_t arg = {0}; btc_msg_t msg = {0}; diff --git a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_sensor_model_api.c b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_sensor_model_api.c index 8bf77b385..45ee3863d 100644 --- a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_sensor_model_api.c +++ b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_sensor_model_api.c @@ -27,7 +27,7 @@ esp_err_t esp_ble_mesh_register_sensor_client_callback(esp_ble_mesh_sensor_clien } esp_err_t esp_ble_mesh_sensor_client_get_state(esp_ble_mesh_client_common_param_t *params, - esp_ble_mesh_sensor_client_get_state_t *get_state) + esp_ble_mesh_sensor_client_get_state_t *get_state) { btc_ble_mesh_sensor_client_args_t arg = {0}; btc_msg_t msg = {0}; @@ -52,7 +52,7 @@ esp_err_t esp_ble_mesh_sensor_client_get_state(esp_ble_mesh_client_common_param_ } esp_err_t esp_ble_mesh_sensor_client_set_state(esp_ble_mesh_client_common_param_t *params, - esp_ble_mesh_sensor_client_set_state_t *set_state) + esp_ble_mesh_sensor_client_set_state_t *set_state) { btc_ble_mesh_sensor_client_args_t arg = {0}; btc_msg_t msg = {0}; diff --git a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_time_scene_model_api.c b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_time_scene_model_api.c index bd71ea7cd..5df12d965 100644 --- a/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_time_scene_model_api.c +++ b/components/bt/esp_ble_mesh/api/models/esp_ble_mesh_time_scene_model_api.c @@ -27,7 +27,7 @@ esp_err_t esp_ble_mesh_register_time_scene_client_callback(esp_ble_mesh_time_sce } esp_err_t esp_ble_mesh_time_scene_client_get_state(esp_ble_mesh_client_common_param_t *params, - esp_ble_mesh_time_scene_client_get_state_t *get_state) + esp_ble_mesh_time_scene_client_get_state_t *get_state) { btc_ble_mesh_time_scene_client_args_t arg = {0}; btc_msg_t msg = {0}; @@ -53,7 +53,7 @@ esp_err_t esp_ble_mesh_time_scene_client_get_state(esp_ble_mesh_client_common_pa } esp_err_t esp_ble_mesh_time_scene_client_set_state(esp_ble_mesh_client_common_param_t *params, - esp_ble_mesh_time_scene_client_set_state_t *set_state) + esp_ble_mesh_time_scene_client_set_state_t *set_state) { btc_ble_mesh_time_scene_client_args_t arg = {0}; btc_msg_t msg = {0}; diff --git a/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_config_model_api.h b/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_config_model_api.h index 06d45e9bb..2d5c6d45a 100644 --- a/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_config_model_api.h +++ b/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_config_model_api.h @@ -756,7 +756,7 @@ typedef enum { * @param param: Pointer to callback parameter */ typedef void (* esp_ble_mesh_cfg_client_cb_t)(esp_ble_mesh_cfg_client_cb_event_t event, - esp_ble_mesh_cfg_client_cb_param_t *param); + esp_ble_mesh_cfg_client_cb_param_t *param); /** * @brief Configuration Server Model callback function type @@ -764,7 +764,7 @@ typedef void (* esp_ble_mesh_cfg_client_cb_t)(esp_ble_mesh_cfg_client_cb_event_t * @param param: Pointer to callback parameter */ typedef void (* esp_ble_mesh_cfg_server_cb_t)(esp_ble_mesh_cfg_server_cb_event_t event, - esp_ble_mesh_cfg_server_cb_param_t *param); + esp_ble_mesh_cfg_server_cb_param_t *param); /** * @brief Register BLE Mesh Config Client Model callback. @@ -800,7 +800,7 @@ esp_err_t esp_ble_mesh_register_config_server_callback(esp_ble_mesh_cfg_server_c * */ 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); + esp_ble_mesh_cfg_client_get_state_t *get_state); /** * @brief Set the value of the Configuration Server Model states using the Config Client Model set messages. @@ -816,7 +816,7 @@ esp_err_t esp_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_ * */ 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); + esp_ble_mesh_cfg_client_set_state_t *set_state); #ifdef __cplusplus } diff --git a/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_generic_model_api.h b/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_generic_model_api.h index e1758e179..db908edbb 100644 --- a/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_generic_model_api.h +++ b/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_generic_model_api.h @@ -483,7 +483,7 @@ typedef enum { * @param param: Pointer to callback parameter */ typedef void (* esp_ble_mesh_generic_client_cb_t)(esp_ble_mesh_generic_client_cb_event_t event, - esp_ble_mesh_generic_client_cb_param_t *param); + esp_ble_mesh_generic_client_cb_param_t *param); /** * @brief Register BLE Mesh Generic Client Model callback. @@ -509,7 +509,7 @@ esp_err_t esp_ble_mesh_register_generic_client_callback(esp_ble_mesh_generic_cli * */ esp_err_t esp_ble_mesh_generic_client_get_state(esp_ble_mesh_client_common_param_t *params, - esp_ble_mesh_generic_client_get_state_t *get_state); + esp_ble_mesh_generic_client_get_state_t *get_state); /** * @brief Set the value of Generic Server Model states using the Generic Client Model set messages. @@ -525,7 +525,7 @@ esp_err_t esp_ble_mesh_generic_client_get_state(esp_ble_mesh_client_common_param * */ esp_err_t esp_ble_mesh_generic_client_set_state(esp_ble_mesh_client_common_param_t *params, - esp_ble_mesh_generic_client_set_state_t *set_state); + esp_ble_mesh_generic_client_set_state_t *set_state); /** * @brief Generic Server Models related context. @@ -1285,7 +1285,7 @@ typedef enum { * @param param: Pointer to callback parameter */ typedef void (* esp_ble_mesh_generic_server_cb_t)(esp_ble_mesh_generic_server_cb_event_t event, - esp_ble_mesh_generic_server_cb_param_t *param); + esp_ble_mesh_generic_server_cb_param_t *param); /** * @brief Register BLE Mesh Generic Server Model callback. diff --git a/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_health_model_api.h b/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_health_model_api.h index e46ae79e3..69a642900 100644 --- a/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_health_model_api.h +++ b/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_health_model_api.h @@ -335,7 +335,7 @@ typedef enum { * @param param: Pointer to callback parameter */ typedef void (* esp_ble_mesh_health_client_cb_t)(esp_ble_mesh_health_client_cb_event_t event, - esp_ble_mesh_health_client_cb_param_t *param); + esp_ble_mesh_health_client_cb_param_t *param); /** * @brief Health Server Model callback function type @@ -343,7 +343,7 @@ typedef void (* esp_ble_mesh_health_client_cb_t)(esp_ble_mesh_health_client_cb_e * @param param: Pointer to callback parameter */ typedef void (* esp_ble_mesh_health_server_cb_t)(esp_ble_mesh_health_server_cb_event_t event, - esp_ble_mesh_health_server_cb_param_t *param); + esp_ble_mesh_health_server_cb_param_t *param); /** * @brief Register BLE Mesh Health Model callback, the callback will report Health Client & Server Model events. @@ -379,7 +379,7 @@ esp_err_t esp_ble_mesh_register_health_server_callback(esp_ble_mesh_health_serve * */ esp_err_t esp_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_get_state_t *get_state); /** * @brief This function is called to set the Health Server states using the Health Client Model set messages. @@ -395,7 +395,7 @@ esp_err_t esp_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param_ * */ esp_err_t esp_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_set_state_t *set_state); /** * @brief This function is called by the Health Server Model to update the context of its Health Current status. diff --git a/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_lighting_model_api.h b/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_lighting_model_api.h index 4180eb914..a0377ca06 100644 --- a/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_lighting_model_api.h +++ b/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_lighting_model_api.h @@ -539,7 +539,7 @@ typedef enum { * @param param: Pointer to callback parameter */ typedef void (* esp_ble_mesh_light_client_cb_t)(esp_ble_mesh_light_client_cb_event_t event, - esp_ble_mesh_light_client_cb_param_t *param); + esp_ble_mesh_light_client_cb_param_t *param); /** * @brief Register BLE Mesh Light Client Model callback. @@ -565,7 +565,7 @@ esp_err_t esp_ble_mesh_register_light_client_callback(esp_ble_mesh_light_client_ * */ 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); + esp_ble_mesh_light_client_get_state_t *get_state); /** * @brief Set the value of Light Server Model states using the Light Client Model set messages. @@ -581,7 +581,7 @@ esp_err_t esp_ble_mesh_light_client_get_state(esp_ble_mesh_client_common_param_t * */ 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); + esp_ble_mesh_light_client_set_state_t *set_state); /** * @brief Lighting Server Models related context. @@ -1663,7 +1663,7 @@ typedef enum { * @param param: Pointer to callback parameter */ typedef void (* esp_ble_mesh_lighting_server_cb_t)(esp_ble_mesh_lighting_server_cb_event_t event, - esp_ble_mesh_lighting_server_cb_param_t *param); + esp_ble_mesh_lighting_server_cb_param_t *param); /** * @brief Register BLE Mesh Lighting Server Model callback. diff --git a/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_sensor_model_api.h b/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_sensor_model_api.h index 5c43efe18..0c4343a8c 100644 --- a/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_sensor_model_api.h +++ b/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_sensor_model_api.h @@ -215,7 +215,7 @@ typedef enum { * @param param: Pointer to callback parameter */ typedef void (* esp_ble_mesh_sensor_client_cb_t)(esp_ble_mesh_sensor_client_cb_event_t event, - esp_ble_mesh_sensor_client_cb_param_t *param); + esp_ble_mesh_sensor_client_cb_param_t *param); /** * @brief Register BLE Mesh Sensor Client Model callback. @@ -241,7 +241,7 @@ esp_err_t esp_ble_mesh_register_sensor_client_callback(esp_ble_mesh_sensor_clien * */ esp_err_t esp_ble_mesh_sensor_client_get_state(esp_ble_mesh_client_common_param_t *params, - esp_ble_mesh_sensor_client_get_state_t *get_state); + esp_ble_mesh_sensor_client_get_state_t *get_state); /** * @brief Set the value of Sensor Server Model states using the Sensor Client Model set messages. @@ -257,7 +257,7 @@ esp_err_t esp_ble_mesh_sensor_client_get_state(esp_ble_mesh_client_common_param_ * */ esp_err_t esp_ble_mesh_sensor_client_set_state(esp_ble_mesh_client_common_param_t *params, - esp_ble_mesh_sensor_client_set_state_t *set_state); + esp_ble_mesh_sensor_client_set_state_t *set_state); /** * @brief Sensor Server Models related context. @@ -698,7 +698,7 @@ typedef enum { * @param param: Pointer to callback parameter */ typedef void (* esp_ble_mesh_sensor_server_cb_t)(esp_ble_mesh_sensor_server_cb_event_t event, - esp_ble_mesh_sensor_server_cb_param_t *param); + esp_ble_mesh_sensor_server_cb_param_t *param); /** * @brief Register BLE Mesh Sensor Server Model callback. diff --git a/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_time_scene_model_api.h b/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_time_scene_model_api.h index f6414b709..690cab718 100644 --- a/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_time_scene_model_api.h +++ b/components/bt/esp_ble_mesh/api/models/include/esp_ble_mesh_time_scene_model_api.h @@ -276,7 +276,7 @@ typedef enum { * @param param: Pointer to callback parameter */ typedef void (* esp_ble_mesh_time_scene_client_cb_t)(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_param_t *param); /** * @brief Register BLE Mesh Time Scene Client Model callback. @@ -301,7 +301,7 @@ esp_err_t esp_ble_mesh_register_time_scene_client_callback(esp_ble_mesh_time_sce * @return ESP_OK on success or error code otherwise. */ esp_err_t esp_ble_mesh_time_scene_client_get_state(esp_ble_mesh_client_common_param_t *params, - esp_ble_mesh_time_scene_client_get_state_t *get_state); + esp_ble_mesh_time_scene_client_get_state_t *get_state); /** * @brief Set the value of Time Scene Server Model states using the Time Scene Client Model set messages. @@ -316,7 +316,7 @@ esp_err_t esp_ble_mesh_time_scene_client_get_state(esp_ble_mesh_client_common_pa * @return ESP_OK on success or error code otherwise. */ esp_err_t esp_ble_mesh_time_scene_client_set_state(esp_ble_mesh_client_common_param_t *params, - esp_ble_mesh_time_scene_client_set_state_t *set_state); + esp_ble_mesh_time_scene_client_set_state_t *set_state); /** * @brief Time Scene Server Models related context. @@ -900,7 +900,7 @@ typedef enum { * @param param: Pointer to callback parameter */ typedef void (* esp_ble_mesh_time_scene_server_cb_t)(esp_ble_mesh_time_scene_server_cb_event_t event, - esp_ble_mesh_time_scene_server_cb_param_t *param); + esp_ble_mesh_time_scene_server_cb_param_t *param); /** * @brief Register BLE Mesh Time and Scenes Server Model callback. diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c index c66f166ae..c9c48e713 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c @@ -25,7 +25,7 @@ extern s32_t config_msg_timeout; /* 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_param_t *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); @@ -51,7 +51,7 @@ void btc_ble_mesh_config_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void memcpy(dst->cfg_client_get_state.params, src->cfg_client_get_state.params, sizeof(esp_ble_mesh_client_common_param_t)); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); break; } if (src->cfg_client_get_state.get_state) { @@ -60,7 +60,7 @@ void btc_ble_mesh_config_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void memcpy(dst->cfg_client_get_state.get_state, src->cfg_client_get_state.get_state, sizeof(esp_ble_mesh_cfg_client_get_state_t)); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } } break; @@ -71,7 +71,7 @@ void btc_ble_mesh_config_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void memcpy(dst->cfg_client_set_state.params, src->cfg_client_set_state.params, sizeof(esp_ble_mesh_client_common_param_t)); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); break; } if (src->cfg_client_set_state.set_state) { @@ -80,13 +80,13 @@ void btc_ble_mesh_config_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void memcpy(dst->cfg_client_set_state.set_state, src->cfg_client_set_state.set_state, sizeof(esp_ble_mesh_cfg_client_set_state_t)); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } } break; } default: - BT_DBG("%s, Unknown deep copy act %d", __func__, msg->act); + BT_DBG("%s, Unknown act %d", __func__, msg->act); break; } } @@ -138,7 +138,7 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des if (p_src_data->params) { p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); if (!p_dest_data->params) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } @@ -157,7 +157,7 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->status_cb.comp_data_status.composition_data->len; p_dest_data->status_cb.comp_data_status.composition_data = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.comp_data_status.composition_data) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.comp_data_status.composition_data, @@ -173,7 +173,7 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->status_cb.model_sub_list.sub_addr->len; p_dest_data->status_cb.model_sub_list.sub_addr = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.model_sub_list.sub_addr) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.model_sub_list.sub_addr, @@ -187,7 +187,7 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->status_cb.netkey_list.net_idx->len; p_dest_data->status_cb.netkey_list.net_idx = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.netkey_list.net_idx) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.netkey_list.net_idx, @@ -201,7 +201,7 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->status_cb.appkey_list.app_idx->len; p_dest_data->status_cb.appkey_list.app_idx = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.appkey_list.app_idx) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.appkey_list.app_idx, @@ -217,7 +217,7 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->status_cb.model_app_list.app_idx->len; p_dest_data->status_cb.model_app_list.app_idx = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.model_app_list.app_idx) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.model_app_list.app_idx, @@ -306,14 +306,14 @@ static void btc_ble_mesh_config_client_callback(esp_ble_mesh_cfg_client_cb_param 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_config_client_copy_req_data); + btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_cfg_client_cb_param_t), + btc_ble_mesh_config_client_copy_req_data); } 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) + struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + const u8_t *val, size_t len) { esp_ble_mesh_cfg_client_cb_param_t cb_params = {0}; esp_ble_mesh_client_common_param_t params = {0}; @@ -339,7 +339,7 @@ void bt_mesh_config_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, act = ESP_BLE_MESH_CFG_CLIENT_TIMEOUT_EVT; break; default: - BT_ERR("%s, Unknown config client event type %d", __func__, evt_type); + BT_ERR("Unknown Config client event type %d", evt_type); return; } @@ -366,18 +366,17 @@ void bt_mesh_config_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, return; } -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_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) { BT_ERR("%s, Invalid parameter", __func__); return; } - bt_mesh_config_client_cb_evt_to_btc(opcode, - BTC_BLE_MESH_EVT_CONFIG_CLIENT_PUBLISH, 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; } @@ -403,7 +402,7 @@ static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param case ESP_BLE_MESH_MODEL_OP_KEY_REFRESH_PHASE_GET: case ESP_BLE_MESH_MODEL_OP_LPN_POLLTIMEOUT_GET: if (get == NULL) { - BT_ERR("%s, Invalid config client get", __func__); + BT_ERR("Invalid Configuration Get"); return -EINVAL; } break; @@ -467,7 +466,7 @@ static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param case ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_GET: return bt_mesh_cfg_net_transmit_get(&ctx); default: - BT_ERR("%s, Invalid opcode 0x%x", __func__, params->opcode); + BT_ERR("Invalid Configuration Get opcode 0x%04x", params->opcode); return -EINVAL; } @@ -485,7 +484,7 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param } if (params->opcode != ESP_BLE_MESH_MODEL_OP_NODE_RESET && set == NULL) { - BT_ERR("%s, Invalid config client set", __func__); + BT_ERR("Invalid Configuration Set"); return -EINVAL; } @@ -613,7 +612,7 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param case ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_SET: return bt_mesh_cfg_net_transmit_set(&ctx, set->net_transmit_set.net_transmit); default: - BT_ERR("%s, Invalid opcode 0x%x", __func__, params->opcode); + BT_ERR("Invalid Configuration Set opcode 0x%04x", params->opcode); return -EINVAL; } @@ -639,7 +638,7 @@ void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg) 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)) { - BT_ERR("%s, Failed to set model role", __func__); + BT_ERR("Failed to set model role"); break; } cb.error_code = btc_ble_mesh_config_client_get_state(arg->cfg_client_get_state.params, @@ -654,7 +653,7 @@ void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg) 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)) { - BT_ERR("%s, Failed to set model role", __func__); + BT_ERR("Failed to set model role"); break; } cb.error_code = btc_ble_mesh_config_client_set_state(arg->cfg_client_set_state.params, @@ -686,7 +685,7 @@ void btc_ble_mesh_config_client_cb_handler(btc_msg_t *msg) if (msg->act < ESP_BLE_MESH_CFG_CLIENT_EVT_MAX) { btc_ble_mesh_config_client_cb_to_app(msg->act, param); } else { - BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act); + BT_ERR("%s, Unknown act %d", __func__, msg->act); } btc_ble_mesh_config_client_free_req_data(msg); @@ -696,7 +695,7 @@ void btc_ble_mesh_config_client_cb_handler(btc_msg_t *msg) /* 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_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); @@ -723,10 +722,9 @@ static void btc_ble_mesh_config_server_callback(esp_ble_mesh_cfg_server_cb_param btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_cfg_server_cb_param_t), NULL); } -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) +void bt_mesh_config_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + const u8_t *val, size_t len) { esp_ble_mesh_cfg_server_cb_param_t cb_params = {0}; size_t length = 0U; @@ -742,7 +740,7 @@ void bt_mesh_config_server_cb_evt_to_btc(u8_t evt_type, act = ESP_BLE_MESH_CFG_SERVER_STATE_CHANGE_EVT; break; default: - BT_ERR("%s, Unknown config server event type %d", __func__, evt_type); + BT_ERR("Unknown Config server event type %d", evt_type); return; } @@ -779,6 +777,6 @@ void btc_ble_mesh_config_server_cb_handler(btc_msg_t *msg) if (msg->act < ESP_BLE_MESH_CFG_SERVER_EVT_MAX) { btc_ble_mesh_config_server_cb_to_app(msg->act, param); } else { - BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act); + BT_ERR("%s, Unknown act %d", __func__, msg->act); } } diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c index d555268ab..4f267b3f6 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c @@ -22,7 +22,7 @@ /* 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_param_t *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); @@ -49,7 +49,7 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi memcpy(dst->generic_client_get_state.params, src->generic_client_get_state.params, sizeof(esp_ble_mesh_client_common_param_t)); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); break; } if (src->generic_client_get_state.get_state) { @@ -58,7 +58,7 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi memcpy(dst->generic_client_get_state.get_state, src->generic_client_get_state.get_state, sizeof(esp_ble_mesh_generic_client_get_state_t)); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } } break; @@ -78,7 +78,7 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi length = src->generic_client_set_state.set_state->user_property_set.property_value->len; dst->generic_client_set_state.set_state->user_property_set.property_value = bt_mesh_alloc_buf(length); if (!dst->generic_client_set_state.set_state->user_property_set.property_value) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(dst->generic_client_set_state.set_state->user_property_set.property_value, @@ -91,7 +91,7 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi length = src->generic_client_set_state.set_state->admin_property_set.property_value->len; dst->generic_client_set_state.set_state->admin_property_set.property_value = bt_mesh_alloc_buf(length); if (!dst->generic_client_set_state.set_state->admin_property_set.property_value) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(dst->generic_client_set_state.set_state->admin_property_set.property_value, @@ -103,12 +103,12 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi break; } } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } break; } default: - BT_DBG("%s, Unknown deep copy act %d", __func__, msg->act); + BT_DBG("%s, Unknown act %d", __func__, msg->act); break; } } @@ -172,7 +172,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de if (p_src_data->params) { p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); if (!p_dest_data->params) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } @@ -191,7 +191,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de length = p_src_data->status_cb.user_properties_status.property_ids->len; p_dest_data->status_cb.user_properties_status.property_ids = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.user_properties_status.property_ids) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.user_properties_status.property_ids, @@ -206,7 +206,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de length = p_src_data->status_cb.user_property_status.property_value->len; p_dest_data->status_cb.user_property_status.property_value = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.user_property_status.property_value) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.user_property_status.property_value, @@ -220,7 +220,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de length = p_src_data->status_cb.admin_properties_status.property_ids->len; p_dest_data->status_cb.admin_properties_status.property_ids = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.admin_properties_status.property_ids) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.admin_properties_status.property_ids, @@ -235,7 +235,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de length = p_src_data->status_cb.admin_property_status.property_value->len; p_dest_data->status_cb.admin_property_status.property_value = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.admin_property_status.property_value) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.admin_property_status.property_value, @@ -249,7 +249,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de length = p_src_data->status_cb.manufacturer_properties_status.property_ids->len; p_dest_data->status_cb.manufacturer_properties_status.property_ids = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.manufacturer_properties_status.property_ids) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.manufacturer_properties_status.property_ids, @@ -264,7 +264,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de length = p_src_data->status_cb.manufacturer_property_status.property_value->len; p_dest_data->status_cb.manufacturer_property_status.property_value = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.manufacturer_property_status.property_value) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.manufacturer_property_status.property_value, @@ -278,7 +278,7 @@ static void btc_ble_mesh_generic_client_copy_req_data(btc_msg_t *msg, void *p_de length = p_src_data->status_cb.client_properties_status.property_ids->len; p_dest_data->status_cb.client_properties_status.property_ids = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.client_properties_status.property_ids) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.client_properties_status.property_ids, @@ -374,14 +374,14 @@ static void btc_ble_mesh_generic_client_callback(esp_ble_mesh_generic_client_cb_ msg.pid = BTC_PID_GENERIC_CLIENT; msg.act = act; - btc_transfer_context(&msg, cb_params, - sizeof(esp_ble_mesh_generic_client_cb_param_t), btc_ble_mesh_generic_client_copy_req_data); + btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_generic_client_cb_param_t), + btc_ble_mesh_generic_client_copy_req_data); } 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) + struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + const u8_t *val, size_t len) { esp_ble_mesh_generic_client_cb_param_t cb_params = {0}; esp_ble_mesh_client_common_param_t params = {0}; @@ -407,7 +407,7 @@ void bt_mesh_generic_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, act = ESP_BLE_MESH_GENERIC_CLIENT_TIMEOUT_EVT; break; default: - BT_ERR("%s, Unknown generic client event type %d", __func__, evt_type); + BT_ERR("Unknown Generic client event type %d", evt_type); return; } @@ -434,18 +434,17 @@ void bt_mesh_generic_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, return; } -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 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) { BT_ERR("%s, Invalid parameter", __func__); return; } - bt_mesh_generic_client_cb_evt_to_btc(opcode, - BTC_BLE_MESH_EVT_GENERIC_CLIENT_PUBLISH, 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; } @@ -470,7 +469,7 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg) role_param.model = (struct bt_mesh_model *)params->model; role_param.role = params->msg_role; if (bt_mesh_set_client_model_role(&role_param)) { - BT_ERR("%s, Failed to set model role", __func__); + BT_ERR("Failed to set model role"); break; } common.opcode = params->opcode; @@ -496,7 +495,7 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg) role_param.model = (struct bt_mesh_model *)params->model; role_param.role = params->msg_role; if (bt_mesh_set_client_model_role(&role_param)) { - BT_ERR("%s, Failed to set model role", __func__); + BT_ERR("Failed to set model role"); break; } common.opcode = params->opcode; @@ -539,7 +538,7 @@ void btc_ble_mesh_generic_client_cb_handler(btc_msg_t *msg) if (msg->act < ESP_BLE_MESH_GENERIC_CLIENT_EVT_MAX) { btc_ble_mesh_generic_client_cb_to_app(msg->act, param); } else { - BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act); + BT_ERR("%s, Unknown act %d", __func__, msg->act); } btc_ble_mesh_generic_client_free_req_data(msg); @@ -548,9 +547,8 @@ void btc_ble_mesh_generic_client_cb_handler(btc_msg_t *msg) /* Generic Server Models related functions */ -static inline void btc_ble_mesh_generic_server_cb_to_app( - esp_ble_mesh_generic_server_cb_event_t event, - esp_ble_mesh_generic_server_cb_param_t *param) +static inline void btc_ble_mesh_generic_server_cb_to_app(esp_ble_mesh_generic_server_cb_event_t event, + esp_ble_mesh_generic_server_cb_param_t *param) { esp_ble_mesh_generic_server_cb_t btc_ble_mesh_cb = (esp_ble_mesh_generic_server_cb_t)btc_profile_cb_get(BTC_PID_GENERIC_SERVER); @@ -579,7 +577,7 @@ static void btc_ble_mesh_generic_server_copy_req_data(btc_msg_t *msg, void *p_de length = p_src_data->value.state_change.user_property_set.value->len; p_dest_data->value.state_change.user_property_set.value = bt_mesh_alloc_buf(length); if (p_dest_data->value.state_change.user_property_set.value == NULL) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->value.state_change.user_property_set.value, @@ -593,7 +591,7 @@ static void btc_ble_mesh_generic_server_copy_req_data(btc_msg_t *msg, void *p_de length = p_src_data->value.state_change.admin_property_set.value->len; p_dest_data->value.state_change.admin_property_set.value = bt_mesh_alloc_buf(length); if (p_dest_data->value.state_change.admin_property_set.value == NULL) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->value.state_change.admin_property_set.value, @@ -613,7 +611,7 @@ static void btc_ble_mesh_generic_server_copy_req_data(btc_msg_t *msg, void *p_de length = p_src_data->value.set.user_property.property_value->len; p_dest_data->value.set.user_property.property_value = bt_mesh_alloc_buf(length); if (p_dest_data->value.set.user_property.property_value == NULL) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->value.set.user_property.property_value, @@ -627,7 +625,7 @@ static void btc_ble_mesh_generic_server_copy_req_data(btc_msg_t *msg, void *p_de length = p_src_data->value.set.admin_property.property_value->len; p_dest_data->value.set.admin_property.property_value = bt_mesh_alloc_buf(length); if (p_dest_data->value.set.admin_property.property_value == NULL) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->value.set.admin_property.property_value, @@ -704,14 +702,13 @@ static void btc_ble_mesh_generic_server_callback(esp_ble_mesh_generic_server_cb_ msg.pid = BTC_PID_GENERIC_SERVER; msg.act = act; - btc_transfer_context(&msg, cb_params, - sizeof(esp_ble_mesh_generic_server_cb_param_t), btc_ble_mesh_generic_server_copy_req_data); + btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_generic_server_cb_param_t), + btc_ble_mesh_generic_server_copy_req_data); } -void bt_mesh_generic_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) +void bt_mesh_generic_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + const u8_t *val, size_t len) { esp_ble_mesh_generic_server_cb_param_t cb_params = {0}; size_t length = 0U; @@ -733,7 +730,7 @@ void bt_mesh_generic_server_cb_evt_to_btc(u8_t evt_type, act = ESP_BLE_MESH_GENERIC_SERVER_RECV_SET_MSG_EVT; break; default: - BT_ERR("%s, Unknown Generic Server event type", __func__); + BT_ERR("Unknown Generic Server event type %d", evt_type); return; } @@ -770,7 +767,7 @@ void btc_ble_mesh_generic_server_cb_handler(btc_msg_t *msg) if (msg->act < ESP_BLE_MESH_GENERIC_SERVER_EVT_MAX) { btc_ble_mesh_generic_server_cb_to_app(msg->act, param); } else { - BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act); + BT_ERR("%s, Unknown act %d", __func__, msg->act); } btc_ble_mesh_generic_server_free_req_data(msg); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c index fd4125efb..41aa9c9e5 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c @@ -26,7 +26,7 @@ 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_param_t *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); @@ -52,7 +52,7 @@ void btc_ble_mesh_health_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void memcpy(dst->health_client_get_state.params, src->health_client_get_state.params, sizeof(esp_ble_mesh_client_common_param_t)); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); break; } if (src->health_client_get_state.get_state) { @@ -61,7 +61,7 @@ void btc_ble_mesh_health_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void memcpy(dst->health_client_get_state.get_state, src->health_client_get_state.get_state, sizeof(esp_ble_mesh_health_client_get_state_t)); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } } break; @@ -75,12 +75,12 @@ void btc_ble_mesh_health_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void memcpy(dst->health_client_set_state.set_state, src->health_client_set_state.set_state, sizeof(esp_ble_mesh_health_client_set_state_t)); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } break; } default: - BT_DBG("%s, Unknown deep copy act %d", __func__, msg->act); + BT_DBG("%s, Unknown act %d", __func__, msg->act); break; } } @@ -132,7 +132,7 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des if (p_src_data->params) { p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); if (!p_dest_data->params) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } @@ -150,7 +150,7 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->status_cb.current_status.fault_array->len; p_dest_data->status_cb.current_status.fault_array = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.current_status.fault_array) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.current_status.fault_array, @@ -166,7 +166,7 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->status_cb.fault_status.fault_array->len; p_dest_data->status_cb.fault_status.fault_array = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.fault_status.fault_array) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.fault_status.fault_array, @@ -240,14 +240,14 @@ static void btc_ble_mesh_health_client_callback(esp_ble_mesh_health_client_cb_pa 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); + 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) + 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}; @@ -273,7 +273,7 @@ void bt_mesh_health_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, act = ESP_BLE_MESH_HEALTH_CLIENT_TIMEOUT_EVT; break; default: - BT_ERR("%s, Unknown health client event type %d", __func__, evt_type); + BT_ERR("Unknown Health client event type %d", evt_type); return; } @@ -300,18 +300,17 @@ void bt_mesh_health_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, 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) +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) { BT_ERR("%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); + bt_mesh_health_client_cb_evt_to_btc(opcode, BTC_BLE_MESH_EVT_HEALTH_CLIENT_PUBLISH, + model, ctx, buf->data, buf->len); return; } @@ -326,7 +325,7 @@ static int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param } if (params->opcode == ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET && get == NULL) { - BT_ERR("%s, Invalid health client get", __func__); + BT_ERR("Invalid Health Get"); return -EINVAL; } @@ -346,7 +345,7 @@ static int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET: return bt_mesh_health_fault_get(&ctx, get->fault_get.company_id); default: - BT_ERR("%s, Invalid opcode 0x%x", __func__, params->opcode); + BT_ERR("Invalid Health Get opcode 0x%04x", params->opcode); return -EINVAL; } @@ -389,7 +388,7 @@ static int btc_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR_UNACK: return bt_mesh_health_fault_clear(&ctx, set->fault_clear.company_id, false); default: - BT_ERR("%s, Invalid opcode 0x%x", __func__, params->opcode); + BT_ERR("Invalid Health Set opcode 0x%04x", params->opcode); return -EINVAL; } @@ -415,7 +414,7 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg) 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)) { - BT_ERR("%s, Failed to set model role", __func__); + BT_ERR("Failed to set model role"); break; } cb.error_code = btc_ble_mesh_health_client_get_state(arg->health_client_get_state.params, @@ -431,7 +430,7 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg) 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)) { - BT_ERR("%s, Failed to set model role", __func__); + BT_ERR("Failed to set model role"); break; } cb.error_code = btc_ble_mesh_health_client_set_state(arg->health_client_set_state.params, @@ -464,7 +463,7 @@ void btc_ble_mesh_health_client_cb_handler(btc_msg_t *msg) if (msg->act < ESP_BLE_MESH_HEALTH_CLIENT_EVT_MAX) { btc_ble_mesh_health_client_cb_to_app(msg->act, param); } else { - BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act); + BT_ERR("%s, Unknown act %d", __func__, msg->act); } btc_ble_mesh_health_client_free_req_data(msg); @@ -474,7 +473,7 @@ void btc_ble_mesh_health_client_cb_handler(btc_msg_t *msg) /* 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_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); @@ -558,8 +557,8 @@ static void btc_ble_mesh_health_server_callback(esp_ble_mesh_health_server_cb_pa msg.pid = BTC_PID_HEALTH_SERVER; msg.act = act; - btc_transfer_context(&msg, cb_params, - sizeof(esp_ble_mesh_health_server_cb_param_t), btc_ble_mesh_health_server_copy_req_data); + btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_health_server_cb_param_t), + btc_ble_mesh_health_server_copy_req_data); } void btc_ble_mesh_health_server_call_handler(btc_msg_t *msg) @@ -603,7 +602,7 @@ void btc_ble_mesh_health_server_cb_handler(btc_msg_t *msg) if (msg->act < ESP_BLE_MESH_HEALTH_SERVER_EVT_MAX) { btc_ble_mesh_health_server_cb_to_app(msg->act, param); } else { - BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act); + BT_ERR("%s, Unknown act %d", __func__, msg->act); } btc_ble_mesh_health_server_free_req_data(msg); @@ -620,7 +619,8 @@ void btc_ble_mesh_health_server_fault_clear(struct bt_mesh_model *model, u16_t c btc_ble_mesh_health_server_callback(¶m, ESP_BLE_MESH_HEALTH_SERVER_FAULT_CLEAR_EVT); } -void btc_ble_mesh_health_server_fault_test(struct bt_mesh_model *model, u8_t test_id, u16_t company_id) +void btc_ble_mesh_health_server_fault_test(struct bt_mesh_model *model, + u8_t test_id, u16_t company_id) { esp_ble_mesh_health_server_cb_param_t param = {0}; diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c index 4a0a4bf9e..3687d20fd 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c @@ -22,7 +22,7 @@ /* 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_param_t *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); @@ -48,7 +48,7 @@ void btc_ble_mesh_lighting_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, vo memcpy(dst->light_client_get_state.params, src->light_client_get_state.params, sizeof(esp_ble_mesh_client_common_param_t)); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); break; } if (src->light_client_get_state.get_state) { @@ -57,7 +57,7 @@ void btc_ble_mesh_lighting_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, vo memcpy(dst->light_client_get_state.get_state, src->light_client_get_state.get_state, sizeof(esp_ble_mesh_light_client_get_state_t)); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } } break; @@ -71,12 +71,12 @@ void btc_ble_mesh_lighting_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, vo memcpy(dst->light_client_set_state.set_state, src->light_client_set_state.set_state, sizeof(esp_ble_mesh_light_client_set_state_t)); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } break; } default: - BT_DBG("%s, Unknown deep copy act %d", __func__, msg->act); + BT_DBG("%s, Unknown act %d", __func__, msg->act); break; } } @@ -128,7 +128,7 @@ static void btc_ble_mesh_lighting_client_copy_req_data(btc_msg_t *msg, void *p_d if (p_src_data->params) { p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); if (!p_dest_data->params) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } @@ -148,7 +148,7 @@ static void btc_ble_mesh_lighting_client_copy_req_data(btc_msg_t *msg, void *p_d length = p_src_data->status_cb.lc_property_status.property_value->len; p_dest_data->status_cb.lc_property_status.property_value = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.lc_property_status.property_value) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.lc_property_status.property_value, @@ -218,14 +218,14 @@ static void btc_ble_mesh_lighting_client_callback(esp_ble_mesh_light_client_cb_p 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_lighting_client_copy_req_data); + btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_light_client_cb_param_t), + btc_ble_mesh_lighting_client_copy_req_data); } 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) + struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + const u8_t *val, size_t len) { esp_ble_mesh_light_client_cb_param_t cb_params = {0}; esp_ble_mesh_client_common_param_t params = {0}; @@ -251,7 +251,7 @@ void bt_mesh_lighting_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, act = ESP_BLE_MESH_LIGHT_CLIENT_TIMEOUT_EVT; break; default: - BT_ERR("%s, Unknown lighting client event type", __func__); + BT_ERR("Unknown Lighting client event type %d", evt_type); return; } @@ -278,18 +278,17 @@ void bt_mesh_lighting_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, return; } -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 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) { BT_ERR("%s, Invalid parameter", __func__); return; } - bt_mesh_lighting_client_cb_evt_to_btc(opcode, - BTC_BLE_MESH_EVT_LIGHTING_CLIENT_PUBLISH, 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; } @@ -314,7 +313,7 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg) role_param.model = (struct bt_mesh_model *)params->model; role_param.role = params->msg_role; if (bt_mesh_set_client_model_role(&role_param)) { - BT_ERR("%s, Failed to set model role", __func__); + BT_ERR("Failed to set model role"); break; } common.opcode = params->opcode; @@ -340,7 +339,7 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg) role_param.model = (struct bt_mesh_model *)params->model; role_param.role = params->msg_role; if (bt_mesh_set_client_model_role(&role_param)) { - BT_ERR("%s, Failed to set model role", __func__); + BT_ERR("Failed to set model role"); break; } common.opcode = params->opcode; @@ -383,7 +382,7 @@ void btc_ble_mesh_lighting_client_cb_handler(btc_msg_t *msg) if (msg->act < ESP_BLE_MESH_LIGHT_CLIENT_EVT_MAX) { btc_ble_mesh_lighting_client_cb_to_app(msg->act, param); } else { - BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act); + BT_ERR("%s, Unknown act %d", __func__, msg->act); } btc_ble_mesh_lighting_client_free_req_data(msg); @@ -392,9 +391,8 @@ void btc_ble_mesh_lighting_client_cb_handler(btc_msg_t *msg) /* Lighting Server Models related functions */ -static inline void btc_ble_mesh_lighting_server_cb_to_app( - esp_ble_mesh_lighting_server_cb_event_t event, - esp_ble_mesh_lighting_server_cb_param_t *param) +static inline void btc_ble_mesh_lighting_server_cb_to_app(esp_ble_mesh_lighting_server_cb_event_t event, + esp_ble_mesh_lighting_server_cb_param_t *param) { esp_ble_mesh_lighting_server_cb_t btc_ble_mesh_cb = (esp_ble_mesh_lighting_server_cb_t)btc_profile_cb_get(BTC_PID_LIGHTING_SERVER); @@ -422,7 +420,7 @@ static void btc_ble_mesh_lighting_server_copy_req_data(btc_msg_t *msg, void *p_d length = p_src_data->value.state_change.lc_property_set.property_value->len; p_dest_data->value.state_change.lc_property_set.property_value = bt_mesh_alloc_buf(length); if (p_dest_data->value.state_change.lc_property_set.property_value == NULL) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->value.state_change.lc_property_set.property_value, @@ -438,7 +436,7 @@ static void btc_ble_mesh_lighting_server_copy_req_data(btc_msg_t *msg, void *p_d length = p_src_data->value.set.lc_property.property_value->len; p_dest_data->value.set.lc_property.property_value = bt_mesh_alloc_buf(length); if (p_dest_data->value.set.lc_property.property_value == NULL) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->value.set.lc_property.property_value, @@ -453,7 +451,7 @@ static void btc_ble_mesh_lighting_server_copy_req_data(btc_msg_t *msg, void *p_d length = p_src_data->value.status.sensor_status.data->len; p_dest_data->value.status.sensor_status.data = bt_mesh_alloc_buf(length); if (p_dest_data->value.status.sensor_status.data == NULL) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->value.status.sensor_status.data, @@ -516,14 +514,13 @@ static void btc_ble_mesh_lighting_server_callback(esp_ble_mesh_lighting_server_c msg.pid = BTC_PID_LIGHTING_SERVER; msg.act = act; - btc_transfer_context( - &msg, cb_params, sizeof(esp_ble_mesh_lighting_server_cb_param_t), btc_ble_mesh_lighting_server_copy_req_data); + btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_lighting_server_cb_param_t), + btc_ble_mesh_lighting_server_copy_req_data); } -void bt_mesh_lighting_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) +void bt_mesh_lighting_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + const u8_t *val, size_t len) { esp_ble_mesh_lighting_server_cb_param_t cb_params = {0}; size_t length = 0U; @@ -548,7 +545,7 @@ void bt_mesh_lighting_server_cb_evt_to_btc(u8_t evt_type, act = ESP_BLE_MESH_LIGHTING_SERVER_RECV_STATUS_MSG_EVT; break; default: - BT_ERR("%s, Unknown Lighting Server event type", __func__); + BT_ERR("Unknown Lighting server event type %d", evt_type); return; } @@ -585,7 +582,7 @@ void btc_ble_mesh_lighting_server_cb_handler(btc_msg_t *msg) if (msg->act < ESP_BLE_MESH_LIGHTING_SERVER_EVT_MAX) { btc_ble_mesh_lighting_server_cb_to_app(msg->act, param); } else { - BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act); + BT_ERR("%s, Unknown act %d", __func__, msg->act); } btc_ble_mesh_lighting_server_free_req_data(msg); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c index 048d112e1..ab1aba587 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c @@ -51,7 +51,7 @@ #include "esp_ble_mesh_networking_api.h" 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_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); @@ -61,7 +61,7 @@ static inline void btc_ble_mesh_prov_cb_to_app(esp_ble_mesh_prov_cb_event_t even } 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_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); @@ -82,36 +82,33 @@ void btc_ble_mesh_prov_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) switch (msg->act) { case BTC_BLE_MESH_ACT_PROXY_CLIENT_ADD_FILTER_ADDR: - BT_DBG("%s, BTC_BLE_MESH_ACT_PROXY_CLIENT_ADD_FILTER_ADDR", __func__); dst->proxy_client_add_filter_addr.addr = (uint16_t *)bt_mesh_calloc(src->proxy_client_add_filter_addr.addr_num << 1); if (dst->proxy_client_add_filter_addr.addr) { memcpy(dst->proxy_client_add_filter_addr.addr, src->proxy_client_add_filter_addr.addr, src->proxy_client_add_filter_addr.addr_num << 1); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } break; case BTC_BLE_MESH_ACT_PROXY_CLIENT_REMOVE_FILTER_ADDR: - BT_DBG("%s, BTC_BLE_MESH_ACT_PROXY_CLIENT_REMOVE_FILTER_ADDR", __func__); dst->proxy_client_remove_filter_addr.addr = bt_mesh_calloc(src->proxy_client_remove_filter_addr.addr_num << 1); if (dst->proxy_client_remove_filter_addr.addr) { memcpy(dst->proxy_client_remove_filter_addr.addr, src->proxy_client_remove_filter_addr.addr, src->proxy_client_remove_filter_addr.addr_num << 1); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } break; case BTC_BLE_MESH_ACT_PROVISIONER_STORE_NODE_COMP_DATA: - BT_DBG("%s, BTC_BLE_MESH_ACT_PROVISIONER_STORE_NODE_COMP_DATA", __func__); dst->store_node_comp_data.data = bt_mesh_calloc(src->store_node_comp_data.length); if (dst->store_node_comp_data.data) { memcpy(dst->store_node_comp_data.data, src->store_node_comp_data.data, src->store_node_comp_data.length); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } break; default: - BT_DBG("%s, Unknown deep copy act %d", __func__, msg->act); + BT_DBG("%s, Unknown act %d", __func__, msg->act); break; } } @@ -161,35 +158,33 @@ void btc_ble_mesh_model_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) switch (msg->act) { case BTC_BLE_MESH_ACT_SERVER_MODEL_SEND: case BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND: { - BT_DBG("%s, BTC_BLE_MESH_ACT_MODEL_SEND, src->model_send.length = %d", __func__, src->model_send.length); dst->model_send.data = src->model_send.length ? (uint8_t *)bt_mesh_malloc(src->model_send.length) : NULL; dst->model_send.ctx = bt_mesh_malloc(sizeof(esp_ble_mesh_msg_ctx_t)); if (src->model_send.length) { if (dst->model_send.data) { memcpy(dst->model_send.data, src->model_send.data, src->model_send.length); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } } if (dst->model_send.ctx) { memcpy(dst->model_send.ctx, src->model_send.ctx, sizeof(esp_ble_mesh_msg_ctx_t)); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } break; } case BTC_BLE_MESH_ACT_SERVER_MODEL_UPDATE_STATE: - BT_DBG("%s, BTC_BLE_MESH_ACT_SERVER_MODEL_UPDATE_STATE", __func__); dst->model_update_state.value = bt_mesh_malloc(sizeof(esp_ble_mesh_server_state_value_t)); if (dst->model_update_state.value) { memcpy(dst->model_update_state.value, src->model_update_state.value, sizeof(esp_ble_mesh_server_state_value_t)); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } break; default: - BT_DBG("%s, Unknown deep copy act %d", __func__, msg->act); + BT_DBG("%s, Unknown act %d", __func__, msg->act); break; } } @@ -245,13 +240,13 @@ static void btc_ble_mesh_model_copy_req_data(btc_msg_t *msg, void *p_dest, void if (p_dest_data->model_operation.ctx) { memcpy(p_dest_data->model_operation.ctx, p_src_data->model_operation.ctx, sizeof(esp_ble_mesh_msg_ctx_t)); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } if (p_src_data->model_operation.length) { if (p_dest_data->model_operation.msg) { memcpy(p_dest_data->model_operation.msg, p_src_data->model_operation.msg, p_src_data->model_operation.length); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } } } @@ -264,13 +259,13 @@ static void btc_ble_mesh_model_copy_req_data(btc_msg_t *msg, void *p_dest, void if (p_dest_data->client_recv_publish_msg.ctx) { memcpy(p_dest_data->client_recv_publish_msg.ctx, p_src_data->client_recv_publish_msg.ctx, sizeof(esp_ble_mesh_msg_ctx_t)); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } if (p_src_data->client_recv_publish_msg.length) { if (p_dest_data->client_recv_publish_msg.msg) { memcpy(p_dest_data->client_recv_publish_msg.msg, p_src_data->client_recv_publish_msg.msg, p_src_data->client_recv_publish_msg.length); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } } } @@ -282,7 +277,7 @@ static void btc_ble_mesh_model_copy_req_data(btc_msg_t *msg, void *p_dest, void if (p_dest_data->model_send_comp.ctx) { memcpy(p_dest_data->model_send_comp.ctx, p_src_data->model_send_comp.ctx, sizeof(esp_ble_mesh_msg_ctx_t)); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } } break; @@ -293,7 +288,7 @@ static void btc_ble_mesh_model_copy_req_data(btc_msg_t *msg, void *p_dest, void if (p_dest_data->client_send_timeout.ctx) { memcpy(p_dest_data->client_send_timeout.ctx, p_src_data->client_send_timeout.ctx, sizeof(esp_ble_mesh_msg_ctx_t)); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } } break; @@ -366,17 +361,17 @@ static bt_status_t btc_ble_mesh_model_callback(esp_ble_mesh_model_cb_param_t *pa msg.pid = BTC_PID_MODEL; msg.act = act; - ret = btc_transfer_context(&msg, param, - sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_model_copy_req_data); + ret = btc_transfer_context(&msg, param, sizeof(esp_ble_mesh_model_cb_param_t), + btc_ble_mesh_model_copy_req_data); if (ret != BT_STATUS_SUCCESS) { - BT_ERR("%s, btc_transfer_context failed", __func__); + BT_ERR("btc_transfer_context failed"); } return ret; } 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) + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { esp_ble_mesh_model_cb_param_t mesh_param = {0}; @@ -391,8 +386,8 @@ static void btc_ble_mesh_server_model_op_cb(struct bt_mesh_model *model, } static void btc_ble_mesh_client_model_op_cb(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf) + struct bt_mesh_msg_ctx *ctx, + struct net_buf_simple *buf) { esp_ble_mesh_model_cb_param_t mesh_param = {0}; bt_mesh_client_node_t *node = NULL; @@ -455,7 +450,9 @@ static void btc_ble_mesh_client_model_timeout_cb(struct k_work *work) return; } -static void btc_ble_mesh_model_send_comp_cb(esp_ble_mesh_model_t *model, esp_ble_mesh_msg_ctx_t *ctx, u32_t opcode, int err) +static void btc_ble_mesh_model_send_comp_cb(esp_ble_mesh_model_t *model, + esp_ble_mesh_msg_ctx_t *ctx, + u32_t opcode, int err) { esp_ble_mesh_model_cb_param_t mesh_param = {0}; @@ -493,7 +490,8 @@ static int btc_ble_mesh_model_publish_update(struct bt_mesh_model *mod) } static void btc_ble_mesh_server_model_update_state_comp_cb(esp_ble_mesh_model_t *model, - esp_ble_mesh_server_state_type_t type, int err) + esp_ble_mesh_server_state_type_t type, + int err) { esp_ble_mesh_model_cb_param_t mesh_param = {0}; @@ -523,7 +521,7 @@ static bt_status_t btc_ble_mesh_prov_callback(esp_ble_mesh_prov_cb_param_t *para ret = btc_transfer_context(&msg, param, sizeof(esp_ble_mesh_prov_cb_param_t), NULL); if (ret != BT_STATUS_SUCCESS) { - BT_ERR("%s, btc_transfer_context failed", __func__); + BT_ERR("btc_transfer_context failed"); } return ret; } @@ -603,7 +601,8 @@ static void btc_ble_mesh_link_close_cb(bt_mesh_prov_bearer_t bearer) return; } -static void btc_ble_mesh_complete_cb(u16_t net_idx, const u8_t net_key[16], u16_t addr, u8_t flags, u32_t iv_index) +static void btc_ble_mesh_complete_cb(u16_t net_idx, const u8_t net_key[16], + u16_t addr, u8_t flags, u32_t iv_index) { esp_ble_mesh_prov_cb_param_t mesh_param = {0}; @@ -649,10 +648,10 @@ static void btc_ble_mesh_prov_set_complete_cb(esp_ble_mesh_prov_cb_param_t *para } #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, s8_t rssi) +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, + s8_t rssi) { esp_ble_mesh_prov_cb_param_t mesh_param = {0}; @@ -689,8 +688,8 @@ static int btc_ble_mesh_provisioner_prov_read_oob_pub_key_cb(u8_t link_idx) return (ret == BT_STATUS_SUCCESS) ? 0 : -1; } -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) +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}; bt_status_t ret = BT_STATUS_SUCCESS; @@ -706,8 +705,8 @@ static int btc_ble_mesh_provisioner_prov_input_cb(u8_t method, return (ret == BT_STATUS_SUCCESS) ? 0 : -1; } -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) +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}; bt_status_t ret = BT_STATUS_SUCCESS; @@ -753,10 +752,9 @@ static void btc_ble_mesh_provisioner_link_close_cb(bt_mesh_prov_bearer_t bearer, return; } -static void btc_ble_mesh_provisioner_prov_complete_cb( - u16_t node_idx, const u8_t device_uuid[16], - u16_t unicast_addr, u8_t element_num, - u16_t netkey_idx) +static void btc_ble_mesh_provisioner_prov_complete_cb(u16_t node_idx, const u8_t device_uuid[16], + u16_t unicast_addr, u8_t element_num, + u16_t netkey_idx) { esp_ble_mesh_prov_cb_param_t mesh_param = {0}; @@ -841,7 +839,7 @@ void btc_ble_mesh_friend_cb(bool establish, u16_t lpn_addr, u8_t reason) BT_DBG("%s", __func__); if (!BLE_MESH_ADDR_IS_UNICAST(lpn_addr)) { - BT_ERR("%s, Not a unicast address", __func__); + BT_ERR("Not a unicast lpn address 0x%04x", lpn_addr); return; } @@ -860,8 +858,8 @@ void btc_ble_mesh_friend_cb(bool establish, u16_t lpn_addr, u8_t reason) #endif /* CONFIG_BLE_MESH_FRIEND */ #if CONFIG_BLE_MESH_GATT_PROXY_CLIENT -static void btc_ble_mesh_proxy_client_adv_recv_cb(const bt_mesh_addr_t *addr, - u8_t type, bt_mesh_proxy_adv_ctx_t *ctx, s8_t rssi) +static void btc_ble_mesh_proxy_client_adv_recv_cb(const bt_mesh_addr_t *addr, u8_t type, + bt_mesh_proxy_adv_ctx_t *ctx, s8_t rssi) { esp_ble_mesh_prov_cb_param_t mesh_param = {0}; @@ -883,7 +881,7 @@ static void btc_ble_mesh_proxy_client_adv_recv_cb(const bt_mesh_addr_t *addr, } static void btc_ble_mesh_proxy_client_connect_cb(const bt_mesh_addr_t *addr, - u8_t conn_handle, u16_t net_idx) + u8_t conn_handle, u16_t net_idx) { esp_ble_mesh_prov_cb_param_t mesh_param = {0}; @@ -903,8 +901,8 @@ static void btc_ble_mesh_proxy_client_connect_cb(const bt_mesh_addr_t *addr, return; } -static void btc_ble_mesh_proxy_client_disconnect_cb(const bt_mesh_addr_t *addr, - u8_t conn_handle, u16_t net_idx, u8_t reason) +static void btc_ble_mesh_proxy_client_disconnect_cb(const bt_mesh_addr_t *addr, u8_t conn_handle, + u16_t net_idx, u8_t reason) { esp_ble_mesh_prov_cb_param_t mesh_param = {0}; @@ -925,8 +923,8 @@ static void btc_ble_mesh_proxy_client_disconnect_cb(const bt_mesh_addr_t *addr, return; } -static void btc_ble_mesh_proxy_client_filter_status_recv_cb(u8_t conn_handle, - u16_t src, u16_t net_idx, u8_t filter_type, u16_t list_size) +static void btc_ble_mesh_proxy_client_filter_status_recv_cb(u8_t conn_handle, u16_t src, u16_t net_idx, + u8_t filter_type, u16_t list_size) { esp_ble_mesh_prov_cb_param_t mesh_param = {0}; @@ -990,7 +988,7 @@ uint8_t btc_ble_mesh_elem_count(void) } esp_ble_mesh_model_t *btc_ble_mesh_model_find_vnd(const esp_ble_mesh_elem_t *elem, - uint16_t company, uint16_t id) + uint16_t company, uint16_t id) { return (esp_ble_mesh_model_t *)bt_mesh_model_find_vnd((struct bt_mesh_elem *)elem, company, id); } @@ -1432,7 +1430,7 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) model->op = (esp_ble_mesh_model_op_t *)time_setup_srv_op; if (model->pub) { /* Time Setup Server model does not support subscribing nor publishing. */ - BT_ERR("%s, Time Setup Server shall not support publication", __func__); + BT_ERR("Time Setup Server shall not support publication"); return; } break; @@ -1570,17 +1568,14 @@ void btc_ble_mesh_prov_call_handler(btc_msg_t *msg) } #if CONFIG_BLE_MESH_NODE case BTC_BLE_MESH_ACT_PROV_ENABLE: - BT_DBG("%s, BTC_BLE_MESH_ACT_PROV_ENABLE, bearers = %d", __func__, arg->node_prov_enable.bearers); act = ESP_BLE_MESH_NODE_PROV_ENABLE_COMP_EVT; param.node_prov_enable_comp.err_code = bt_mesh_prov_enable(arg->node_prov_enable.bearers); break; case BTC_BLE_MESH_ACT_PROV_DISABLE: - BT_DBG("%s, BTC_BLE_MESH_ACT_PROV_DISABLE, bearers = %d", __func__, arg->node_prov_disable.bearers); act = ESP_BLE_MESH_NODE_PROV_DISABLE_COMP_EVT; param.node_prov_disable_comp.err_code = bt_mesh_prov_disable(arg->node_prov_disable.bearers); break; case BTC_BLE_MESH_ACT_NODE_RESET: - BT_DBG("%s, BTC_BLE_MESH_ACT_NODE_RESET", __func__); bt_mesh_node_reset(); return; case BTC_BLE_MESH_ACT_SET_OOB_PUB_KEY: @@ -1937,7 +1932,7 @@ void btc_ble_mesh_prov_call_handler(btc_msg_t *msg) param.deinit_mesh_comp.err_code = bt_mesh_deinit((struct bt_mesh_deinit_param *)&arg->mesh_deinit.param); break; default: - BT_WARN("%s, Invalid msg->act %d", __func__, msg->act); + BT_WARN("%s, Unknown act %d", __func__, msg->act); return; } @@ -1964,7 +1959,7 @@ void btc_ble_mesh_prov_cb_handler(btc_msg_t *msg) if (msg->act < ESP_BLE_MESH_PROV_EVT_MAX) { btc_ble_mesh_prov_cb_to_app(msg->act, param); } else { - BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act); + BT_ERR("%s, Unknown act %d", __func__, msg->act); } } @@ -1987,7 +1982,7 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg) common.model = (struct bt_mesh_model *)(arg->model_publish.model); common.role = arg->model_publish.device_role; if (bt_mesh_set_client_model_role(&common)) { - BT_ERR("%s, Failed to set model role", __func__); + BT_ERR("Failed to set model role"); break; } } @@ -1999,7 +1994,7 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg) /* arg->model_send.length contains opcode & payload, plus extra 4-bytes TransMIC */ struct net_buf_simple *buf = bt_mesh_alloc_buf(arg->model_send.length + BLE_MESH_MIC_SHORT); if (!buf) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); break; } net_buf_simple_add_mem(buf, arg->model_send.data, arg->model_send.length); @@ -2017,7 +2012,7 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg) /* arg->model_send.length contains opcode & message, plus extra 4-bytes TransMIC */ struct net_buf_simple *buf = bt_mesh_alloc_buf(arg->model_send.length + BLE_MESH_MIC_SHORT); if (!buf) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); break; } net_buf_simple_add_mem(buf, arg->model_send.data, arg->model_send.length); @@ -2025,7 +2020,7 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg) common.model = (struct bt_mesh_model *)(arg->model_send.model); common.role = arg->model_send.device_role; if (bt_mesh_set_client_model_role(&common)) { - BT_ERR("%s, Failed to set model role", __func__); + BT_ERR("Failed to set model role"); break; } err = bt_mesh_client_send_msg((struct bt_mesh_model *)arg->model_send.model, @@ -2046,7 +2041,7 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg) arg->model_update_state.type, err); break; default: - BT_WARN("%s, Unknown msg->act %d", __func__, msg->act); + BT_WARN("%s, Unknown act %d", __func__, msg->act); break; } @@ -2068,7 +2063,7 @@ void btc_ble_mesh_model_cb_handler(btc_msg_t *msg) if (msg->act < ESP_BLE_MESH_MODEL_EVT_MAX) { btc_ble_mesh_model_cb_to_app(msg->act, param); } else { - BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act); + BT_ERR("%s, Unknown act %d", __func__, msg->act); } btc_ble_mesh_model_free_req_data(msg); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c index 7b3b3d8d3..98c906939 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c @@ -22,7 +22,7 @@ /* 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_param_t *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); @@ -58,7 +58,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void length = src->sensor_client_get_state.get_state->column_get.raw_value_x->len; dst->sensor_client_get_state.get_state->column_get.raw_value_x = bt_mesh_alloc_buf(length); if (!dst->sensor_client_get_state.get_state->column_get.raw_value_x) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(dst->sensor_client_get_state.get_state->column_get.raw_value_x, @@ -71,7 +71,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void length = src->sensor_client_get_state.get_state->series_get.raw_value_x1->len; dst->sensor_client_get_state.get_state->series_get.raw_value_x1 = bt_mesh_alloc_buf(length); if (!dst->sensor_client_get_state.get_state->series_get.raw_value_x1) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(dst->sensor_client_get_state.get_state->series_get.raw_value_x1, @@ -82,7 +82,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void length = src->sensor_client_get_state.get_state->series_get.raw_value_x2->len; dst->sensor_client_get_state.get_state->series_get.raw_value_x2 = bt_mesh_alloc_buf(length); if (!dst->sensor_client_get_state.get_state->series_get.raw_value_x2) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(dst->sensor_client_get_state.get_state->series_get.raw_value_x2, @@ -94,7 +94,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void break; } } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } break; } @@ -113,7 +113,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void length = src->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down->len; dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down = bt_mesh_alloc_buf(length); if (!dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down, @@ -124,7 +124,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void length = src->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up->len; dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up = bt_mesh_alloc_buf(length); if (!dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up, @@ -135,7 +135,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void length = src->sensor_client_set_state.set_state->cadence_set.fast_cadence_low->len; dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_low = bt_mesh_alloc_buf(length); if (!dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_low) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_low, @@ -146,7 +146,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void length = src->sensor_client_set_state.set_state->cadence_set.fast_cadence_high->len; dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_high = bt_mesh_alloc_buf(length); if (!dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_high) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_high, @@ -159,7 +159,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void length = src->sensor_client_set_state.set_state->setting_set.sensor_setting_raw->len; dst->sensor_client_set_state.set_state->setting_set.sensor_setting_raw = bt_mesh_alloc_buf(length); if (!dst->sensor_client_set_state.set_state->setting_set.sensor_setting_raw) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(dst->sensor_client_set_state.set_state->setting_set.sensor_setting_raw, @@ -171,12 +171,12 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void break; } } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } break; } default: - BT_DBG("%s, Unknown deep copy act %d", __func__, msg->act); + BT_DBG("%s, Unknown act %d", __func__, msg->act); break; } } @@ -256,7 +256,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des if (p_src_data->params) { p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); if (!p_dest_data->params) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } @@ -275,7 +275,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->status_cb.descriptor_status.descriptor->len; p_dest_data->status_cb.descriptor_status.descriptor = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.descriptor_status.descriptor) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.descriptor_status.descriptor, @@ -290,7 +290,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->status_cb.cadence_status.sensor_cadence_value->len; p_dest_data->status_cb.cadence_status.sensor_cadence_value = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.cadence_status.sensor_cadence_value) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.cadence_status.sensor_cadence_value, @@ -304,7 +304,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->status_cb.settings_status.sensor_setting_property_ids->len; p_dest_data->status_cb.settings_status.sensor_setting_property_ids = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.settings_status.sensor_setting_property_ids) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.settings_status.sensor_setting_property_ids, @@ -319,7 +319,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->status_cb.setting_status.sensor_setting_raw->len; p_dest_data->status_cb.setting_status.sensor_setting_raw = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.setting_status.sensor_setting_raw) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.setting_status.sensor_setting_raw, @@ -333,7 +333,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->status_cb.sensor_status.marshalled_sensor_data->len; p_dest_data->status_cb.sensor_status.marshalled_sensor_data = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.sensor_status.marshalled_sensor_data) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.sensor_status.marshalled_sensor_data, @@ -347,7 +347,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->status_cb.column_status.sensor_column_value->len; p_dest_data->status_cb.column_status.sensor_column_value = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.column_status.sensor_column_value) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.column_status.sensor_column_value, @@ -361,7 +361,7 @@ static void btc_ble_mesh_sensor_client_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->status_cb.series_status.sensor_series_value->len; p_dest_data->status_cb.series_status.sensor_series_value = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.series_status.sensor_series_value) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.series_status.sensor_series_value, @@ -456,14 +456,14 @@ static void btc_ble_mesh_sensor_client_callback(esp_ble_mesh_sensor_client_cb_pa msg.pid = BTC_PID_SENSOR_CLIENT; msg.act = act; - btc_transfer_context(&msg, cb_params, - sizeof(esp_ble_mesh_sensor_client_cb_param_t), btc_ble_mesh_sensor_client_copy_req_data); + btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_sensor_client_cb_param_t), + btc_ble_mesh_sensor_client_copy_req_data); } 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) + struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + const u8_t *val, size_t len) { esp_ble_mesh_sensor_client_cb_param_t cb_params = {0}; esp_ble_mesh_client_common_param_t params = {0}; @@ -489,7 +489,7 @@ void bt_mesh_sensor_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, act = ESP_BLE_MESH_SENSOR_CLIENT_TIMEOUT_EVT; break; default: - BT_ERR("%s, Unknown sensor client event type %d", __func__, evt_type); + BT_ERR("Unknown Sensor client event type %d", evt_type); return; } @@ -516,18 +516,17 @@ void bt_mesh_sensor_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, return; } -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 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) { BT_ERR("%s, Invalid parameter", __func__); return; } - bt_mesh_sensor_client_cb_evt_to_btc(opcode, - BTC_BLE_MESH_EVT_SENSOR_CLIENT_PUBLISH, 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; } @@ -552,7 +551,7 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg) role_param.model = (struct bt_mesh_model *)params->model; role_param.role = params->msg_role; if (bt_mesh_set_client_model_role(&role_param)) { - BT_ERR("%s, Failed to set model role", __func__); + BT_ERR("Failed to set model role"); break; } common.opcode = params->opcode; @@ -578,7 +577,7 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg) role_param.model = (struct bt_mesh_model *)params->model; role_param.role = params->msg_role; if (bt_mesh_set_client_model_role(&role_param)) { - BT_ERR("%s, Failed to set model role", __func__); + BT_ERR("Failed to set model role"); break; } common.opcode = params->opcode; @@ -621,7 +620,7 @@ void btc_ble_mesh_sensor_client_cb_handler(btc_msg_t *msg) if (msg->act < ESP_BLE_MESH_SENSOR_CLIENT_EVT_MAX) { btc_ble_mesh_sensor_client_cb_to_app(msg->act, param); } else { - BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act); + BT_ERR("%s, Unknown act %d", __func__, msg->act); } btc_ble_mesh_sensor_client_free_req_data(msg); @@ -630,9 +629,8 @@ void btc_ble_mesh_sensor_client_cb_handler(btc_msg_t *msg) /* Sensor Server Models related functions */ -static inline void btc_ble_mesh_sensor_server_cb_to_app( - esp_ble_mesh_sensor_server_cb_event_t event, - esp_ble_mesh_sensor_server_cb_param_t *param) +static inline void btc_ble_mesh_sensor_server_cb_to_app(esp_ble_mesh_sensor_server_cb_event_t event, + esp_ble_mesh_sensor_server_cb_param_t *param) { esp_ble_mesh_sensor_server_cb_t btc_ble_mesh_cb = (esp_ble_mesh_sensor_server_cb_t)btc_profile_cb_get(BTC_PID_SENSOR_SERVER); @@ -660,7 +658,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->value.state_change.sensor_cadence_set.trigger_delta_down->len; p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_down = bt_mesh_alloc_buf(length); if (p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_down == NULL) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_down, @@ -671,7 +669,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->value.state_change.sensor_cadence_set.trigger_delta_up->len; p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_up = bt_mesh_alloc_buf(length); if (p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_up == NULL) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_cadence_set.trigger_delta_up, @@ -682,7 +680,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->value.state_change.sensor_cadence_set.fast_cadence_low->len; p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_low = bt_mesh_alloc_buf(length); if (p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_low == NULL) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_low, @@ -693,7 +691,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->value.state_change.sensor_cadence_set.fast_cadence_high->len; p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_high = bt_mesh_alloc_buf(length); if (p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_high == NULL) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_cadence_set.fast_cadence_high, @@ -706,7 +704,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->value.state_change.sensor_setting_set.setting_value->len; p_dest_data->value.state_change.sensor_setting_set.setting_value = bt_mesh_alloc_buf(length); if (p_dest_data->value.state_change.sensor_setting_set.setting_value == NULL) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->value.state_change.sensor_setting_set.setting_value, @@ -721,7 +719,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->value.get.sensor_column.raw_value_x->len; p_dest_data->value.get.sensor_column.raw_value_x = bt_mesh_alloc_buf(length); if (p_dest_data->value.get.sensor_column.raw_value_x == NULL) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->value.get.sensor_column.raw_value_x, @@ -733,7 +731,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->value.get.sensor_series.raw_value->len; p_dest_data->value.get.sensor_series.raw_value = bt_mesh_alloc_buf(length); if (p_dest_data->value.get.sensor_series.raw_value == NULL) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->value.get.sensor_series.raw_value, @@ -749,7 +747,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->value.set.sensor_cadence.cadence->len; p_dest_data->value.set.sensor_cadence.cadence = bt_mesh_alloc_buf(length); if (p_dest_data->value.set.sensor_cadence.cadence == NULL) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->value.set.sensor_cadence.cadence, @@ -762,7 +760,7 @@ static void btc_ble_mesh_sensor_server_copy_req_data(btc_msg_t *msg, void *p_des length = p_src_data->value.set.sensor_setting.setting_raw->len; p_dest_data->value.set.sensor_setting.setting_raw = bt_mesh_alloc_buf(length); if (p_dest_data->value.set.sensor_setting.setting_raw == NULL) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->value.set.sensor_setting.setting_raw, @@ -836,14 +834,13 @@ static void btc_ble_mesh_sensor_server_callback(esp_ble_mesh_sensor_server_cb_pa msg.pid = BTC_PID_SENSOR_SERVER; msg.act = act; - btc_transfer_context( - &msg, cb_params, sizeof(esp_ble_mesh_sensor_server_cb_param_t), btc_ble_mesh_sensor_server_copy_req_data); + btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_sensor_server_cb_param_t), + btc_ble_mesh_sensor_server_copy_req_data); } -void bt_mesh_sensor_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) +void bt_mesh_sensor_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + const u8_t *val, size_t len) { esp_ble_mesh_sensor_server_cb_param_t cb_params = {0}; size_t length = 0U; @@ -865,7 +862,7 @@ void bt_mesh_sensor_server_cb_evt_to_btc(u8_t evt_type, act = ESP_BLE_MESH_SENSOR_SERVER_RECV_SET_MSG_EVT; break; default: - BT_ERR("%s, Unknown Sensor Server event type", __func__); + BT_ERR("Unknown Sensor server event type %d", evt_type); return; } @@ -902,7 +899,7 @@ void btc_ble_mesh_sensor_server_cb_handler(btc_msg_t *msg) if (msg->act < ESP_BLE_MESH_SENSOR_SERVER_EVT_MAX) { btc_ble_mesh_sensor_server_cb_to_app(msg->act, param); } else { - BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act); + BT_ERR("%s, Unknown act %d", __func__, msg->act); } btc_ble_mesh_sensor_server_free_req_data(msg); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c index 66f1311a2..ac3038446 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c @@ -22,7 +22,7 @@ /* 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_param_t *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); @@ -48,7 +48,7 @@ void btc_ble_mesh_time_scene_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, memcpy(dst->time_scene_client_get_state.params, src->time_scene_client_get_state.params, sizeof(esp_ble_mesh_client_common_param_t)); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); break; } if (src->time_scene_client_get_state.get_state) { @@ -57,7 +57,7 @@ void btc_ble_mesh_time_scene_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, memcpy(dst->time_scene_client_get_state.get_state, src->time_scene_client_get_state.get_state, sizeof(esp_ble_mesh_time_scene_client_get_state_t)); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } } break; @@ -71,12 +71,12 @@ void btc_ble_mesh_time_scene_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, memcpy(dst->time_scene_client_set_state.set_state, src->time_scene_client_set_state.set_state, sizeof(esp_ble_mesh_time_scene_client_set_state_t)); } else { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); } break; } default: - BT_DBG("%s, Unknown deep copy act %d", __func__, msg->act); + BT_DBG("%s, Unknown act %d", __func__, msg->act); break; } } @@ -128,7 +128,7 @@ static void btc_ble_mesh_time_scene_client_copy_req_data(btc_msg_t *msg, void *p if (p_src_data->params) { p_dest_data->params = bt_mesh_malloc(sizeof(esp_ble_mesh_client_common_param_t)); if (!p_dest_data->params) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } @@ -149,7 +149,7 @@ static void btc_ble_mesh_time_scene_client_copy_req_data(btc_msg_t *msg, void *p 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) { - BT_ERR("%s, Failed to allocate memory, act %d", __func__, msg->act); + BT_ERR("%s, Out of memory, act %d", __func__, msg->act); return; } net_buf_simple_add_mem(p_dest_data->status_cb.scene_register_status.scenes, @@ -220,14 +220,14 @@ static void btc_ble_mesh_time_scene_client_callback(esp_ble_mesh_time_scene_clie msg.pid = BTC_PID_TIME_SCENE_CLIENT; msg.act = act; - btc_transfer_context(&msg, cb_params, - sizeof(esp_ble_mesh_time_scene_client_cb_param_t), btc_ble_mesh_time_scene_client_copy_req_data); + btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_time_scene_client_cb_param_t), + btc_ble_mesh_time_scene_client_copy_req_data); } 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) + struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + const u8_t *val, size_t len) { esp_ble_mesh_time_scene_client_cb_param_t cb_params = {0}; esp_ble_mesh_client_common_param_t params = {0}; @@ -253,7 +253,7 @@ void bt_mesh_time_scene_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, act = ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT; break; default: - BT_ERR("%s, Unknown time scene client event type %d", __func__, evt_type); + BT_ERR("Unknown Time Scene client event type %d", evt_type); return; } @@ -280,18 +280,17 @@ void bt_mesh_time_scene_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, return; } -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 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) { BT_ERR("%s, Invalid parameter", __func__); return; } - bt_mesh_time_scene_client_cb_evt_to_btc(opcode, - BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_PUBLISH, 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; } @@ -316,7 +315,7 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg) role_param.model = (struct bt_mesh_model *)params->model; role_param.role = params->msg_role; if (bt_mesh_set_client_model_role(&role_param)) { - BT_ERR("%s, Failed to set model role", __func__); + BT_ERR("Failed to set model role"); break; } common.opcode = params->opcode; @@ -342,7 +341,7 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg) role_param.model = (struct bt_mesh_model *)params->model; role_param.role = params->msg_role; if (bt_mesh_set_client_model_role(&role_param)) { - BT_ERR("%s, Failed to set model role", __func__); + BT_ERR("Failed to set model role"); break; } common.opcode = params->opcode; @@ -385,7 +384,7 @@ void btc_ble_mesh_time_scene_client_cb_handler(btc_msg_t *msg) if (msg->act < ESP_BLE_MESH_TIME_SCENE_CLIENT_EVT_MAX) { btc_ble_mesh_time_scene_client_cb_to_app(msg->act, param); } else { - BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act); + BT_ERR("%s, Unknown act %d", __func__, msg->act); } btc_ble_mesh_time_scene_client_free_req_data(msg); @@ -394,9 +393,8 @@ void btc_ble_mesh_time_scene_client_cb_handler(btc_msg_t *msg) /* Time and Scenes Server Models related functions */ -static inline void btc_ble_mesh_time_scene_server_cb_to_app( - esp_ble_mesh_time_scene_server_cb_event_t event, - esp_ble_mesh_time_scene_server_cb_param_t *param) +static inline void btc_ble_mesh_time_scene_server_cb_to_app(esp_ble_mesh_time_scene_server_cb_event_t event, + esp_ble_mesh_time_scene_server_cb_param_t *param) { esp_ble_mesh_time_scene_server_cb_t btc_ble_mesh_cb = (esp_ble_mesh_time_scene_server_cb_t)btc_profile_cb_get(BTC_PID_TIME_SCENE_SERVER); @@ -420,14 +418,12 @@ static void btc_ble_mesh_time_scene_server_callback(esp_ble_mesh_time_scene_serv msg.pid = BTC_PID_TIME_SCENE_SERVER; msg.act = act; - btc_transfer_context( - &msg, cb_params, sizeof(esp_ble_mesh_time_scene_server_cb_param_t), NULL); + btc_transfer_context(&msg, cb_params, sizeof(esp_ble_mesh_time_scene_server_cb_param_t), NULL); } -void bt_mesh_time_scene_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) +void bt_mesh_time_scene_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + const u8_t *val, size_t len) { esp_ble_mesh_time_scene_server_cb_param_t cb_params = {0}; size_t length = 0U; @@ -452,7 +448,7 @@ void bt_mesh_time_scene_server_cb_evt_to_btc(u8_t evt_type, act = ESP_BLE_MESH_TIME_SCENE_SERVER_RECV_STATUS_MSG_EVT; break; default: - BT_ERR("%s, Unknown Time Scene Server event type", __func__); + BT_ERR("Unknown Time Scene server event type %d", evt_type); return; } @@ -489,7 +485,7 @@ void btc_ble_mesh_time_scene_server_cb_handler(btc_msg_t *msg) if (msg->act < ESP_BLE_MESH_TIME_SCENE_SERVER_EVT_MAX) { btc_ble_mesh_time_scene_server_cb_to_app(msg->act, param); } else { - BT_ERR("%s, Unknown msg->act = %d", __func__, msg->act); + BT_ERR("%s, Unknown act %d", __func__, msg->act); } return; diff --git a/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_config_model.h b/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_config_model.h index db37bec69..bee77fa74 100644 --- a/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_config_model.h +++ b/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_config_model.h @@ -53,15 +53,14 @@ void btc_ble_mesh_config_client_cb_handler(btc_msg_t *msg); void btc_ble_mesh_config_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src); -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_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 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); + struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + const u8_t *val, size_t len); void btc_ble_mesh_config_server_cb_handler(btc_msg_t *msg); @@ -70,10 +69,9 @@ typedef enum { 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); +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); #ifdef __cplusplus } diff --git a/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_generic_model.h b/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_generic_model.h index d87421dad..9840961b4 100644 --- a/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_generic_model.h +++ b/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_generic_model.h @@ -53,15 +53,14 @@ 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_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 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_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); + struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + const u8_t *val, size_t len); typedef enum { BTC_BLE_MESH_EVT_GENERIC_SERVER_STATE_CHANGE, @@ -70,10 +69,9 @@ typedef enum { BTC_BLE_MESH_EVT_GENERIC_SERVER_MAX, } btc_ble_mesh_generic_server_evt_t; -void bt_mesh_generic_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); +void bt_mesh_generic_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); void btc_ble_mesh_generic_server_cb_handler(btc_msg_t *msg); diff --git a/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_health_model.h b/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_health_model.h index 91a775511..bf12d051e 100644 --- a/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_health_model.h +++ b/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_health_model.h @@ -53,15 +53,14 @@ 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 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); + 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, @@ -82,7 +81,8 @@ void btc_ble_mesh_health_server_arg_deep_copy(btc_msg_t *msg, void *p_dest, void void btc_ble_mesh_health_server_fault_clear(struct bt_mesh_model *model, u16_t company_id); -void btc_ble_mesh_health_server_fault_test(struct bt_mesh_model *model, u8_t test_id, u16_t company_id); +void btc_ble_mesh_health_server_fault_test(struct bt_mesh_model *model, + u8_t test_id, u16_t company_id); void btc_ble_mesh_health_server_attention_on(struct bt_mesh_model *model, u8_t time); diff --git a/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_lighting_model.h b/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_lighting_model.h index 453f2ee2c..0173c15e4 100644 --- a/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_lighting_model.h +++ b/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_lighting_model.h @@ -53,15 +53,14 @@ void btc_ble_mesh_lighting_client_cb_handler(btc_msg_t *msg); void btc_ble_mesh_lighting_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src); -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 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); + struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + const u8_t *val, size_t len); typedef enum { BTC_BLE_MESH_EVT_LIGHTING_SERVER_STATE_CHANGE, @@ -71,10 +70,9 @@ typedef enum { BTC_BLE_MESH_EVT_LIGHTING_SERVER_MAX, } btc_ble_mesh_lighting_server_evt_t; -void bt_mesh_lighting_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); +void bt_mesh_lighting_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); void btc_ble_mesh_lighting_server_cb_handler(btc_msg_t *msg); diff --git a/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_prov.h b/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_prov.h index 0266317da..dffba81de 100644 --- a/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_prov.h +++ b/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_prov.h @@ -320,10 +320,9 @@ esp_ble_mesh_elem_t *btc_ble_mesh_elem_find(u16_t addr); uint8_t btc_ble_mesh_elem_count(void); esp_ble_mesh_model_t *btc_ble_mesh_model_find_vnd(const esp_ble_mesh_elem_t *elem, - uint16_t company, uint16_t id); + uint16_t company, uint16_t id); -esp_ble_mesh_model_t *btc_ble_mesh_model_find(const esp_ble_mesh_elem_t *elem, - uint16_t id); +esp_ble_mesh_model_t *btc_ble_mesh_model_find(const esp_ble_mesh_elem_t *elem, uint16_t id); const esp_ble_mesh_comp_t *btc_ble_mesh_comp_get(void); diff --git a/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_sensor_model.h b/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_sensor_model.h index 65a2af4f7..6e7e0659a 100644 --- a/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_sensor_model.h +++ b/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_sensor_model.h @@ -53,15 +53,14 @@ 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_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 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_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); + struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + const u8_t *val, size_t len); typedef enum { BTC_BLE_MESH_EVT_SENSOR_SERVER_STATE_CHANGE, @@ -70,10 +69,9 @@ typedef enum { BTC_BLE_MESH_EVT_SENSOR_SERVER_MAX, } btc_ble_mesh_sensor_server_evt_t; -void bt_mesh_sensor_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); +void bt_mesh_sensor_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); void btc_ble_mesh_sensor_server_cb_handler(btc_msg_t *msg); diff --git a/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_time_scene_model.h b/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_time_scene_model.h index 7db8764b5..c021aa52d 100644 --- a/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_time_scene_model.h +++ b/components/bt/esp_ble_mesh/btc/include/btc_ble_mesh_time_scene_model.h @@ -53,15 +53,14 @@ 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_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 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_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); + struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + const u8_t *val, size_t len); typedef enum { BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_STATE_CHANGE, @@ -71,10 +70,9 @@ typedef enum { BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_MAX, } btc_ble_mesh_time_scene_server_evt_t; -void bt_mesh_time_scene_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); +void bt_mesh_time_scene_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); void btc_ble_mesh_time_scene_server_cb_handler(btc_msg_t *msg); diff --git a/components/bt/esp_ble_mesh/mesh_common/mesh_buf.c b/components/bt/esp_ble_mesh/mesh_common/mesh_buf.c index 10a9e6566..21f3394d1 100644 --- a/components/bt/esp_ble_mesh/mesh_common/mesh_buf.c +++ b/components/bt/esp_ble_mesh/mesh_common/mesh_buf.c @@ -493,7 +493,7 @@ void net_buf_unref(struct net_buf *buf) pool->uninit_count++; #if defined(CONFIG_BLE_MESH_NET_BUF_POOL_USAGE) pool->avail_count++; - NET_BUF_DBG("%s, pool %p, avail_count %d, uninit_count %d", __func__, + NET_BUF_DBG("Unref, pool %p, avail_count %d, uninit_count %d", pool, pool->avail_count, pool->uninit_count); NET_BUF_ASSERT(pool->avail_count <= pool->buf_count); #endif @@ -546,7 +546,7 @@ struct net_buf *net_buf_alloc_len(struct net_buf_pool *pool, size_t size, NET_BUF_ASSERT(pool); - NET_BUF_DBG("%s, pool %p, uninit_count %d, buf_count %d", __func__, + NET_BUF_DBG("Alloc, pool %p, uninit_count %d, buf_count %d", pool, pool->uninit_count, pool->buf_count); /* We need to lock interrupts temporarily to prevent race conditions @@ -570,7 +570,7 @@ struct net_buf *net_buf_alloc_len(struct net_buf_pool *pool, size_t size, bt_mesh_buf_unlock(); - NET_BUF_ERR("%s, Failed to get free buffer", __func__); + NET_BUF_ERR("Out of free buffer, pool %p", pool); return NULL; success: @@ -579,11 +579,11 @@ success: if (size) { buf->__buf = data_alloc(buf, &size, timeout); if (!buf->__buf) { - NET_BUF_ERR("%s, Failed to allocate data", __func__); + NET_BUF_ERR("Out of data, buf %p", buf); return NULL; } } else { - NET_BUF_WARN("%s, Zero data size", __func__); + NET_BUF_WARN("Zero data size, buf %p", buf); buf->__buf = NULL; } diff --git a/components/bt/esp_ble_mesh/mesh_common/mesh_common.c b/components/bt/esp_ble_mesh/mesh_common/mesh_common.c index 73a84e4a1..369b73637 100644 --- a/components/bt/esp_ble_mesh/mesh_common/mesh_common.c +++ b/components/bt/esp_ble_mesh/mesh_common/mesh_common.c @@ -57,7 +57,7 @@ struct net_buf_simple *bt_mesh_alloc_buf(u16_t size) buf = (struct net_buf_simple *)bt_mesh_calloc(sizeof(struct net_buf_simple) + size); if (!buf) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return NULL; } @@ -83,7 +83,7 @@ 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__); + BT_DBG("Message is sent by a server model"); return NODE; } diff --git a/components/bt/esp_ble_mesh/mesh_common/mesh_mutex.c b/components/bt/esp_ble_mesh/mesh_common/mesh_mutex.c index 3f673209d..5cee41e4f 100644 --- a/components/bt/esp_ble_mesh/mesh_common/mesh_mutex.c +++ b/components/bt/esp_ble_mesh/mesh_common/mesh_mutex.c @@ -22,7 +22,7 @@ static bt_mesh_mutex_t atomic_lock; void bt_mesh_mutex_create(bt_mesh_mutex_t *mutex) { if (!mutex) { - BT_ERR("%s, Invalid mutex", __func__); + BT_ERR("Create, invalid mutex"); return; } @@ -44,7 +44,7 @@ void bt_mesh_mutex_create(bt_mesh_mutex_t *mutex) void bt_mesh_mutex_free(bt_mesh_mutex_t *mutex) { if (!mutex) { - BT_ERR("%s, Invalid mutex", __func__); + BT_ERR("Free, invalid mutex"); return; } @@ -61,7 +61,7 @@ void bt_mesh_mutex_free(bt_mesh_mutex_t *mutex) void bt_mesh_mutex_lock(bt_mesh_mutex_t *mutex) { if (!mutex) { - BT_ERR("%s, Invalid mutex", __func__); + BT_ERR("Lock, invalid mutex"); return; } @@ -73,7 +73,7 @@ void bt_mesh_mutex_lock(bt_mesh_mutex_t *mutex) void bt_mesh_mutex_unlock(bt_mesh_mutex_t *mutex) { if (!mutex) { - BT_ERR("%s, Invalid mutex", __func__); + BT_ERR("Unlock, invalid mutex"); return; } diff --git a/components/bt/esp_ble_mesh/mesh_common/mesh_timer.c b/components/bt/esp_ble_mesh/mesh_common/mesh_timer.c index 50fe7813e..0f7bcfe19 100644 --- a/components/bt/esp_ble_mesh/mesh_common/mesh_timer.c +++ b/components/bt/esp_ble_mesh/mesh_common/mesh_timer.c @@ -48,7 +48,7 @@ void bt_mesh_timer_init(void) bm_alarm_hash_map = hash_map_new(BLE_MESH_GENERAL_ALARM_HASH_MAP_SIZE, hash_function_pointer, NULL, (data_free_fn)osi_alarm_free, NULL); - __ASSERT(bm_alarm_hash_map, "%s, Failed to create hash map", __func__); + __ASSERT(bm_alarm_hash_map, "Failed to create hash map"); } void bt_mesh_timer_deinit(void) @@ -74,12 +74,12 @@ int k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler) if (!hash_map_has_key(bm_alarm_hash_map, (void *)work)) { alarm = osi_alarm_new("bt_mesh", (osi_alarm_callback_t)handler, (void *)&work->work, 0); if (alarm == NULL) { - BT_ERR("%s, Alarm not created", __func__); + BT_ERR("Alarm not created"); bt_mesh_alarm_unlock(); return -EIO; } if (!hash_map_set(bm_alarm_hash_map, work, (void *)alarm)) { - BT_ERR("%s, Alarm not set", __func__); + BT_ERR("Alarm not set"); bt_mesh_alarm_unlock(); return -EIO; } @@ -87,7 +87,7 @@ int k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler) alarm = hash_map_get(bm_alarm_hash_map, work); if (alarm == NULL) { - BT_ERR("%s, Alarm not found", __func__); + BT_ERR("Init, alarm not found"); bt_mesh_alarm_unlock(); return -ENODEV; } @@ -108,7 +108,7 @@ int k_delayed_work_submit(struct k_delayed_work *work, s32_t delay) bt_mesh_alarm_lock(); osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work); if (alarm == NULL) { - BT_WARN("%s, Alarm not found", __func__); + BT_WARN("Submit, alarm not found"); bt_mesh_alarm_unlock(); return -EINVAL; } @@ -130,7 +130,7 @@ int k_delayed_work_submit_periodic(struct k_delayed_work *work, s32_t period) bt_mesh_alarm_lock(); osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work); if (alarm == NULL) { - BT_WARN("%s, Alarm not found", __func__); + BT_WARN("Submit, alarm not found"); bt_mesh_alarm_unlock(); return -EINVAL; } @@ -152,7 +152,7 @@ int k_delayed_work_cancel(struct k_delayed_work *work) bt_mesh_alarm_lock(); osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work); if (alarm == NULL) { - BT_WARN("%s, Alarm not found", __func__); + BT_WARN("Cancel, alarm not found"); bt_mesh_alarm_unlock(); return -EINVAL; } @@ -173,7 +173,7 @@ int k_delayed_work_free(struct k_delayed_work *work) bt_mesh_alarm_lock(); osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, work); if (alarm == NULL) { - BT_WARN("%s, Alarm not found", __func__); + BT_WARN("Free, alarm not found"); bt_mesh_alarm_unlock(); return -EINVAL; } @@ -196,7 +196,7 @@ s32_t k_delayed_work_remaining_get(struct k_delayed_work *work) bt_mesh_alarm_lock(); osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work); if (alarm == NULL) { - BT_WARN("%s, Alarm not found", __func__); + BT_WARN("Get time, alarm not found"); bt_mesh_alarm_unlock(); return 0; } diff --git a/components/bt/esp_ble_mesh/mesh_core/access.c b/components/bt/esp_ble_mesh/mesh_core/access.c index 6ffeca8e5..07019c598 100644 --- a/components/bt/esp_ble_mesh/mesh_core/access.c +++ b/components/bt/esp_ble_mesh/mesh_core/access.c @@ -267,7 +267,7 @@ s32_t bt_mesh_model_pub_period_get(struct bt_mesh_model *mod) int period = 0; if (!mod->pub) { - BT_ERR("%s, Model has no publication support", __func__); + BT_ERR("Model has no publication support"); return 0; } @@ -289,7 +289,7 @@ s32_t bt_mesh_model_pub_period_get(struct bt_mesh_model *mod) period = K_MINUTES((mod->pub->period & BIT_MASK(6)) * 10U); break; default: - BT_ERR("%s, Unknown model publication period", __func__); + BT_ERR("Unknown model publication period"); return 0; } @@ -306,7 +306,7 @@ static s32_t next_period(struct bt_mesh_model *mod) u32_t elapsed = 0U, period = 0U; if (!pub) { - BT_ERR("%s, Model has no publication support", __func__); + BT_ERR("Model has no publication support"); return -ENOTSUP; } @@ -336,7 +336,7 @@ static void publish_sent(int err, void *user_data) BT_DBG("err %d", err); if (!mod->pub) { - BT_ERR("%s, Model has no publication support", __func__); + BT_ERR("Model has no publication support"); return; } @@ -377,7 +377,7 @@ static int publish_retransmit(struct bt_mesh_model *mod) { struct bt_mesh_model_pub *pub = mod->pub; if (!pub) { - BT_ERR("%s, Model has no publication support", __func__); + BT_ERR("Model has no publication support"); return -ENOTSUP; } @@ -399,13 +399,13 @@ static int publish_retransmit(struct bt_mesh_model *mod) key = bt_mesh_tx_appkey_get(pub->dev_role, pub->key); if (!key) { - BT_ERR("%s, AppKey 0x%03x not exists", __func__, pub->key); + BT_ERR("AppKey 0x%03x not exists", pub->key); return -EADDRNOTAVAIL; } tx.sub = bt_mesh_tx_netkey_get(pub->dev_role, key->net_idx); if (!tx.sub) { - BT_ERR("%s, Subnet 0x%04x not exists", __func__, key->net_idx); + BT_ERR("Subnet 0x%04x not exists", key->net_idx); return -EADDRNOTAVAIL; } @@ -414,7 +414,7 @@ static int publish_retransmit(struct bt_mesh_model *mod) sdu = bt_mesh_alloc_buf(pub->msg->len + BLE_MESH_MIC_SHORT); if (!sdu) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return -ENOMEM; } @@ -452,7 +452,7 @@ static void mod_publish(struct k_work *work) if (pub->count) { err = publish_retransmit(pub->mod); if (err) { - BT_ERR("%s, Failed to retransmit (err %d)", __func__, err); + BT_ERR("Failed to retransmit (err %d)", err); pub->count = 0U; @@ -486,7 +486,7 @@ static void mod_publish(struct k_work *work) err = bt_mesh_model_publish(pub->mod); if (err) { - BT_ERR("%s, Publishing failed (err %d)", __func__, err); + BT_ERR("Publishing failed (err %d)", err); } } @@ -500,12 +500,12 @@ struct bt_mesh_model *bt_mesh_model_get(bool vnd, u8_t elem_idx, u8_t mod_idx) struct bt_mesh_elem *elem = NULL; if (!dev_comp) { - BT_ERR("%s, dev_comp is not initialized", __func__); + BT_ERR("dev_comp not initialized"); return NULL; } if (elem_idx >= dev_comp->elem_count) { - BT_ERR("%s, Invalid element index %u", __func__, elem_idx); + BT_ERR("Invalid element index %u", elem_idx); return NULL; } @@ -513,14 +513,14 @@ struct bt_mesh_model *bt_mesh_model_get(bool vnd, u8_t elem_idx, u8_t mod_idx) if (vnd) { if (mod_idx >= elem->vnd_model_count) { - BT_ERR("%s, Invalid vendor model index %u", __func__, mod_idx); + BT_ERR("Invalid vendor model index %u", mod_idx); return NULL; } return &elem->vnd_models[mod_idx]; } else { if (mod_idx >= elem->model_count) { - BT_ERR("%s, Invalid SIG model index %u", __func__, mod_idx); + BT_ERR("Invalid SIG model index %u", mod_idx); return NULL; } @@ -776,7 +776,7 @@ static int get_opcode(struct net_buf_simple *buf, u32_t *opcode) case 0x00: case 0x01: if (buf->data[0] == 0x7f) { - BT_ERR("%s, Ignoring RFU OpCode", __func__); + BT_ERR("Ignoring RFU OpCode"); return -EINVAL; } @@ -784,7 +784,7 @@ static int get_opcode(struct net_buf_simple *buf, u32_t *opcode) return 0; case 0x02: if (buf->len < 2) { - BT_ERR("%s, Too short payload for 2-octet OpCode", __func__); + BT_ERR("Too short payload for 2-octet OpCode"); return -EINVAL; } @@ -792,7 +792,7 @@ static int get_opcode(struct net_buf_simple *buf, u32_t *opcode) return 0; case 0x03: if (buf->len < 3) { - BT_ERR("%s, Too short payload for 3-octet OpCode", __func__); + BT_ERR("Too short payload for 3-octet OpCode"); return -EINVAL; } @@ -838,7 +838,7 @@ void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf) BT_INFO("recv, len %u: %s", buf->len, bt_hex(buf->data, buf->len)); if (get_opcode(buf, &opcode) < 0) { - BT_WARN("%s, Unable to decode OpCode", __func__); + BT_WARN("Unable to decode OpCode"); return; } @@ -932,7 +932,7 @@ static bool ready_to_send(u8_t role, u16_t dst) return true; } else if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en() && role == PROVISIONER) { if (!bt_mesh_provisioner_check_msg_dst(dst)) { - BT_ERR("%s, Failed to find DST 0x%04x", __func__, dst); + BT_ERR("Failed to find DST 0x%04x", dst); return false; } return true; @@ -952,7 +952,7 @@ static int model_send(struct bt_mesh_model *model, role = bt_mesh_get_device_role(model, tx->ctx->srv_send); if (role == ROLE_NVAL) { - BT_ERR("%s, Failed to get model role", __func__); + BT_ERR("Failed to get model role"); return -EINVAL; } @@ -961,22 +961,22 @@ static int model_send(struct bt_mesh_model *model, BT_INFO("send, len %u: %s", msg->len, bt_hex(msg->data, msg->len)); if (!ready_to_send(role, tx->ctx->addr)) { - BT_ERR("%s, Not ready", __func__); + BT_ERR("Not ready to send"); return -EINVAL; } if (net_buf_simple_tailroom(msg) < BLE_MESH_MIC_SHORT) { - BT_ERR("%s, Not enough tailroom for TransMIC", __func__); + BT_ERR("Not enough tailroom for TransMIC"); return -EINVAL; } if (msg->len > MIN(BLE_MESH_TX_SDU_MAX, BLE_MESH_SDU_MAX_LEN) - BLE_MESH_MIC_SHORT) { - BT_ERR("%s, Too big message", __func__); + BT_ERR("Too big message (len %d)", msg->len); return -EMSGSIZE; } if (!implicit_bind && !model_has_key(model, tx->ctx->app_idx)) { - BT_ERR("%s, Model not bound to AppKey 0x%04x", __func__, tx->ctx->app_idx); + BT_ERR("Model not bound to AppKey 0x%04x", tx->ctx->app_idx); return -EINVAL; } @@ -993,13 +993,13 @@ int bt_mesh_model_send(struct bt_mesh_model *model, role = bt_mesh_get_device_role(model, ctx->srv_send); if (role == ROLE_NVAL) { - BT_ERR("%s, Failed to get model role", __func__); + BT_ERR("Failed to get model role"); return -EINVAL; } sub = bt_mesh_tx_netkey_get(role, ctx->net_idx); if (!sub) { - BT_ERR("%s, Failed to get subnet", __func__); + BT_ERR("Invalid NetKeyIndex 0x%04x", ctx->net_idx); return -EINVAL; } @@ -1035,28 +1035,28 @@ int bt_mesh_model_publish(struct bt_mesh_model *model) BT_DBG("%s", __func__); if (!pub || !pub->msg) { - BT_ERR("%s, Model has no publication support", __func__); + BT_ERR("Model has no publication support"); return -ENOTSUP; } if (pub->addr == BLE_MESH_ADDR_UNASSIGNED) { - BT_WARN("%s, Unassigned model publish address", __func__); + BT_WARN("Unassigned publish address"); return -EADDRNOTAVAIL; } key = bt_mesh_tx_appkey_get(pub->dev_role, pub->key); if (!key) { - BT_ERR("%s, AppKey 0x%03x not exists", __func__, pub->key); + BT_ERR("Invalid AppKeyIndex 0x%03x", pub->key); return -EADDRNOTAVAIL; } if (pub->msg->len + BLE_MESH_MIC_SHORT > MIN(BLE_MESH_TX_SDU_MAX, BLE_MESH_SDU_MAX_LEN)) { - BT_ERR("%s, Message does not fit maximum SDU size", __func__); + BT_ERR("Message does not fit maximum SDU size"); return -EMSGSIZE; } if (pub->count) { - BT_WARN("%s, Clearing publish retransmit timer", __func__); + BT_WARN("Clearing publish retransmit timer"); k_delayed_work_cancel(&pub->timer); } @@ -1071,7 +1071,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model) tx.sub = bt_mesh_tx_netkey_get(pub->dev_role, ctx.net_idx); if (!tx.sub) { - BT_ERR("%s, Subnet 0x%04x not exists", __func__, ctx.net_idx); + BT_ERR("Invalid NetKeyIndex 0x%04x", ctx.net_idx); return -EADDRNOTAVAIL; } @@ -1082,7 +1082,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model) sdu = bt_mesh_alloc_buf(pub->msg->len + BLE_MESH_MIC_SHORT); if (!sdu) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return -ENOMEM; } @@ -1098,7 +1098,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model) } struct bt_mesh_model *bt_mesh_model_find_vnd(struct bt_mesh_elem *elem, - u16_t company, u16_t id) + u16_t company, u16_t id) { int i; @@ -1112,8 +1112,7 @@ struct bt_mesh_model *bt_mesh_model_find_vnd(struct bt_mesh_elem *elem, return NULL; } -struct bt_mesh_model *bt_mesh_model_find(struct bt_mesh_elem *elem, - u16_t id) +struct bt_mesh_model *bt_mesh_model_find(struct bt_mesh_elem *elem, u16_t id) { int i; diff --git a/components/bt/esp_ble_mesh/mesh_core/access.h b/components/bt/esp_ble_mesh/mesh_core/access.h index 3e002686c..e74f8df73 100644 --- a/components/bt/esp_ble_mesh/mesh_core/access.h +++ b/components/bt/esp_ble_mesh/mesh_core/access.h @@ -30,9 +30,8 @@ u8_t bt_mesh_elem_count(void); struct bt_mesh_elem *bt_mesh_elem_find(u16_t addr); struct bt_mesh_model *bt_mesh_model_find_vnd(struct bt_mesh_elem *elem, - u16_t company, u16_t id); -struct bt_mesh_model *bt_mesh_model_find(struct bt_mesh_elem *elem, - u16_t id); + u16_t company, u16_t id); +struct bt_mesh_model *bt_mesh_model_find(struct bt_mesh_elem *elem, u16_t id); u16_t *bt_mesh_model_find_group(struct bt_mesh_model *mod, u16_t addr); diff --git a/components/bt/esp_ble_mesh/mesh_core/adv.c b/components/bt/esp_ble_mesh/mesh_core/adv.c index 2a393043e..60e1ea664 100644 --- a/components/bt/esp_ble_mesh/mesh_core/adv.c +++ b/components/bt/esp_ble_mesh/mesh_core/adv.c @@ -190,7 +190,7 @@ static inline int adv_send(struct net_buf *buf) struct ble_adv_tx *tx = cb_data; if (tx == NULL) { - BT_ERR("%s, Invalid adv user data", __func__); + BT_ERR("Invalid adv user data"); net_buf_unref(buf); return -EINVAL; } @@ -218,7 +218,7 @@ static inline int adv_send(struct net_buf *buf) net_buf_unref(buf); adv_send_start(duration, err, cb, cb_data); if (err) { - BT_ERR("%s, Advertising failed: err %d", __func__, err); + BT_ERR("Start advertising failed: err %d", err); return err; } @@ -229,7 +229,7 @@ static inline int adv_send(struct net_buf *buf) err = bt_le_adv_stop(); adv_send_end(err, cb, cb_data); if (err) { - BT_ERR("%s, Stop advertising failed: err %d", __func__, err); + BT_ERR("Stop advertising failed: err %d", err); return 0; } @@ -316,18 +316,18 @@ static void adv_thread(void *p) BLE_MESH_ADV(*buf)->busy = 0U; #if !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) if (adv_send(*buf)) { - BT_WARN("%s, Failed to send adv packet", __func__); + BT_WARN("Failed to send adv packet"); } #else /* !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */ if (msg.relay && ignore_relay_packet(msg.timestamp)) { /* If the interval between "current time - msg.timestamp" is bigger than * BLE_MESH_RELAY_TIME_INTERVAL, this relay packet will not be sent. */ - BT_INFO("%s, Ignore relay packet", __func__); + BT_INFO("Ignore relay packet"); net_buf_unref(*buf); } else { if (adv_send(*buf)) { - BT_WARN("%s, Failed to send adv packet", __func__); + BT_WARN("Failed to send adv packet"); } } #endif @@ -342,9 +342,9 @@ static void adv_thread(void *p) } struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool, - bt_mesh_adv_alloc_t get_id, - enum bt_mesh_adv_type type, - u8_t xmit, s32_t timeout) + bt_mesh_adv_alloc_t get_id, + enum bt_mesh_adv_type type, + u8_t xmit, s32_t timeout) { struct bt_mesh_adv *adv = NULL; struct net_buf *buf = NULL; @@ -359,8 +359,8 @@ struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool, return NULL; } - BT_DBG("%s, pool = %p, buf_count = %d, uinit_count = %d", __func__, - buf->pool, pool->buf_count, pool->uninit_count); + BT_DBG("pool %p, buf_count %d, uinit_count %d", + buf->pool, pool->buf_count, pool->uninit_count); adv = get_id(net_buf_id(buf)); BLE_MESH_ADV(buf) = adv; @@ -443,18 +443,18 @@ static void bt_mesh_task_post(bt_mesh_msg_t *msg, uint32_t timeout, bool front) BT_DBG("%s", __func__); if (adv_queue.handle == NULL) { - BT_ERR("%s, Invalid queue", __func__); + BT_ERR("Invalid adv queue"); return; } if (front) { if (xQueueSendToFront(adv_queue.handle, msg, timeout) != pdTRUE) { - BT_ERR("%s, Failed to send item to queue front", __func__); + BT_ERR("Failed to send item to adv queue front"); bt_mesh_unref_buf(msg); } } else { if (xQueueSend(adv_queue.handle, msg, timeout) != pdTRUE) { - BT_ERR("%s, Failed to send item to queue back", __func__); + BT_ERR("Failed to send item to adv queue back"); bt_mesh_unref_buf(msg); } } @@ -513,7 +513,7 @@ static struct bt_mesh_adv *relay_adv_alloc(int id) } struct net_buf *bt_mesh_relay_adv_create(enum bt_mesh_adv_type type, u8_t xmit, - s32_t timeout) + s32_t timeout) { return bt_mesh_adv_create_from_pool(&relay_adv_buf_pool, relay_adv_alloc, type, xmit, timeout); @@ -527,7 +527,7 @@ static void ble_mesh_relay_task_post(bt_mesh_msg_t *msg, uint32_t timeout) BT_DBG("%s", __func__); if (relay_queue.handle == NULL) { - BT_ERR("%s, Invalid relay queue", __func__); + BT_ERR("Invalid relay queue"); return; } @@ -541,10 +541,10 @@ static void ble_mesh_relay_task_post(bt_mesh_msg_t *msg, uint32_t timeout) */ handle = xQueueSelectFromSet(mesh_queue_set, K_NO_WAIT); if (handle && uxQueueMessagesWaiting(relay_queue.handle)) { - BT_INFO("%s, Full queue, remove the oldest relay packet", __func__); + BT_INFO("Full queue, remove the oldest relay packet"); /* Remove the oldest relay packet from queue */ if (xQueueReceive(relay_queue.handle, &old_msg, K_NO_WAIT) != pdTRUE) { - BT_ERR("%s, Failed to remove item from queue", __func__); + BT_ERR("Failed to remove item from queue"); bt_mesh_unref_buf(msg); return; } @@ -552,12 +552,12 @@ static void ble_mesh_relay_task_post(bt_mesh_msg_t *msg, uint32_t timeout) bt_mesh_unref_buf(&old_msg); /* Send the latest relay packet to queue */ if (xQueueSend(relay_queue.handle, msg, K_NO_WAIT) != pdTRUE) { - BT_ERR("%s, Failed to send item to relay queue", __func__); + BT_ERR("Failed to send item to relay queue"); bt_mesh_unref_buf(msg); return; } } else { - BT_WARN("%s, Empty queue, but failed to send the relay packet", __func__); + BT_WARN("Empty queue, but failed to send the relay packet"); bt_mesh_unref_buf(msg); } } @@ -602,7 +602,7 @@ static bool adv_flags_valid(struct net_buf_simple *buf) u8_t flags = 0U; if (buf->len != 1U) { - BT_DBG("%s, Unexpected flags length", __func__); + BT_DBG("Unexpected adv flags length %d", buf->len); return false; } @@ -662,7 +662,7 @@ static void handle_adv_service_data(struct net_buf_simple *buf, type = net_buf_simple_pull_le16(buf); if (type != uuid) { - BT_DBG("%s, Invalid Mesh Service Data UUID 0x%04x", __func__, type); + BT_DBG("Invalid Mesh Service Data UUID 0x%04x", type); return; } @@ -671,7 +671,7 @@ static void handle_adv_service_data(struct net_buf_simple *buf, case BLE_MESH_UUID_MESH_PROV_VAL: if (bt_mesh_is_provisioner_en()) { if (buf->len != BLE_MESH_PROV_SRV_DATA_LEN) { - BT_WARN("%s, Invalid Mesh Prov Service Data length %d", __func__, buf->len); + BT_WARN("Invalid Mesh Prov Service Data length %d", buf->len); return; } @@ -684,7 +684,7 @@ static void handle_adv_service_data(struct net_buf_simple *buf, case BLE_MESH_UUID_MESH_PROXY_VAL: if (buf->len != BLE_MESH_PROXY_SRV_DATA_LEN1 && buf->len != BLE_MESH_PROXY_SRV_DATA_LEN2) { - BT_WARN("%s, Invalid Mesh Proxy Service Data length %d", __func__, buf->len); + BT_WARN("Invalid Mesh Proxy Service Data length %d", buf->len); return; } @@ -710,7 +710,7 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr, s8_t rssi, return; } - BT_DBG("%s, len %u: %s", __func__, buf->len, bt_hex(buf->data, buf->len)); + BT_DBG("scan, len %u: %s", buf->len, bt_hex(buf->data, buf->len)); dev_addr = addr; @@ -1111,17 +1111,17 @@ int bt_mesh_start_ble_advertising(const struct bt_mesh_ble_adv_param *param, if (param->adv_type != BLE_MESH_ADV_DIRECT_IND && (param->interval < 0x20 || param->interval > 0x4000)) { - BT_ERR("%s, Invalid adv interval 0x%04x", __func__, param->interval); + BT_ERR("Invalid adv interval 0x%04x", param->interval); return -EINVAL; } if (param->adv_type > BLE_MESH_ADV_DIRECT_IND_LOW_DUTY) { - BT_ERR("%s, Invalid adv type 0x%02x", __func__, param->adv_type); + BT_ERR("Invalid adv type 0x%02x", param->adv_type); return -EINVAL; } if (param->own_addr_type > BLE_MESH_ADDR_RANDOM_ID) { - BT_ERR("%s, Invalid own addr type 0x%02x", __func__, param->own_addr_type); + BT_ERR("Invalid own addr type 0x%02x", param->own_addr_type); return -EINVAL; } @@ -1130,29 +1130,29 @@ int bt_mesh_start_ble_advertising(const struct bt_mesh_ble_adv_param *param, param->adv_type == BLE_MESH_ADV_DIRECT_IND || param->adv_type == BLE_MESH_ADV_DIRECT_IND_LOW_DUTY) && param->peer_addr_type > BLE_MESH_ADDR_RANDOM) { - BT_ERR("%s, Invalid peer addr type 0x%02x", __func__, param->peer_addr_type); + BT_ERR("Invalid peer addr type 0x%02x", param->peer_addr_type); return -EINVAL; } if (data && (data->adv_data_len > 31 || data->scan_rsp_data_len > 31)) { - BT_ERR("%s, Invalid adv data length, %d %d", __func__, - data->adv_data_len, data->scan_rsp_data_len); + BT_ERR("Invalid adv data length (adv %d, scan rsp %d)", + data->adv_data_len, data->scan_rsp_data_len); return -EINVAL; } if (param->priority > BLE_MESH_BLE_ADV_PRIO_HIGH) { - BT_ERR("%s, Invalid adv priority %d", __func__, param->priority); + BT_ERR("Invalid adv priority %d", param->priority); return -EINVAL; } if (param->duration < ADV_SCAN_INT(param->interval)) { - BT_ERR("%s, Too small duration %dms", __func__, param->duration); + BT_ERR("Too small duration %dms", param->duration); return -EINVAL; } buf = bt_mesh_ble_adv_create(BLE_MESH_ADV_BLE, 0U, K_NO_WAIT); if (!buf) { - BT_ERR("%s, Unable to allocate buffer", __func__); + BT_ERR("Unable to allocate buffer"); return -ENOBUFS; } @@ -1202,14 +1202,14 @@ int bt_mesh_stop_ble_advertising(u8_t index) bool unref = true; if (index >= ARRAY_SIZE(ble_adv_tx)) { - BT_ERR("%s, Invalid index %d", __func__, index); + BT_ERR("Invalid adv index %d", index); return -EINVAL; } tx = &ble_adv_tx[index]; if (tx->buf == NULL) { - BT_WARN("%s, Already stopped, index %d", __func__, index); + BT_WARN("Already stopped, index %d", index); return 0; } diff --git a/components/bt/esp_ble_mesh/mesh_core/adv.h b/components/bt/esp_ble_mesh/mesh_core/adv.h index 47ede3bfb..79f344e43 100644 --- a/components/bt/esp_ble_mesh/mesh_core/adv.h +++ b/components/bt/esp_ble_mesh/mesh_core/adv.h @@ -69,9 +69,9 @@ void bt_mesh_adv_buf_ref_debug(const char *func, struct net_buf *buf, u8_t ref_cmp, bt_mesh_buf_ref_flag_t flag); struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool, - bt_mesh_adv_alloc_t get_id, - enum bt_mesh_adv_type type, - u8_t xmit, s32_t timeout); + bt_mesh_adv_alloc_t get_id, + enum bt_mesh_adv_type type, + u8_t xmit, s32_t timeout); void bt_mesh_unref_buf_from_pool(struct net_buf_pool *pool); @@ -81,7 +81,7 @@ void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, const bt_mesh_addr_t *bt_mesh_get_unprov_dev_addr(void); struct net_buf *bt_mesh_relay_adv_create(enum bt_mesh_adv_type type, u8_t xmit, - s32_t timeout); + s32_t timeout); void bt_mesh_relay_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, void *cb_data, u16_t src, u16_t dst); diff --git a/components/bt/esp_ble_mesh/mesh_core/beacon.c b/components/bt/esp_ble_mesh/mesh_core/beacon.c index e7462d80a..1ae51acdf 100644 --- a/components/bt/esp_ble_mesh/mesh_core/beacon.c +++ b/components/bt/esp_ble_mesh/mesh_core/beacon.c @@ -177,7 +177,7 @@ static int secure_beacon_send(void) buf = bt_mesh_adv_create(BLE_MESH_ADV_BEACON, PROV_XMIT, K_NO_WAIT); if (!buf) { - BT_ERR("%s, Unable to allocate beacon buffer", __func__); + BT_ERR("Out of beacon buffer"); return -ENOBUFS; } @@ -213,7 +213,7 @@ static int unprovisioned_beacon_send(void) buf = bt_mesh_adv_create(BLE_MESH_ADV_BEACON, UNPROV_XMIT, K_NO_WAIT); if (!buf) { - BT_ERR("%s, Unable to allocate beacon buffer", __func__); + BT_ERR("Out of beacon buffer"); return -ENOBUFS; } @@ -341,7 +341,7 @@ static void secure_beacon_recv(struct net_buf_simple *buf) u8_t flags = 0U; if (buf->len < 21) { - BT_ERR("%s, Too short secure beacon (len %u)", __func__, buf->len); + BT_ERR("Too short secure beacon (len %u)", buf->len); return; } @@ -420,7 +420,7 @@ void bt_mesh_beacon_recv(struct net_buf_simple *buf, s8_t rssi) BT_DBG("%u bytes: %s", buf->len, bt_hex(buf->data, buf->len)); if (buf->len < 1) { - BT_ERR("%s, Too short beacon", __func__); + BT_ERR("Too short beacon"); return; } diff --git a/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c b/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c index 37afddaec..d6e09936e 100644 --- a/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c +++ b/components/bt/esp_ble_mesh/mesh_core/bluedroid_host/mesh_bearer_adapt.c @@ -130,7 +130,7 @@ void bt_mesh_hci_init(void) } static void bt_mesh_scan_results_change_2_bta(tBTM_INQ_RESULTS *p_inq, u8_t *p_eir, - tBTA_DM_SEARCH_CBACK *p_scan_cback) + tBTA_DM_SEARCH_CBACK *p_scan_cback) { tBTM_INQ_INFO *p_inq_info = NULL; tBTA_DM_SEARCH result = {0}; @@ -259,7 +259,8 @@ static bool valid_scan_param(const struct bt_mesh_scan_param *param) return true; } -static int start_le_scan(u8_t scan_type, u16_t interval, u16_t window, u8_t filter_dup, u8_t scan_fil_policy) +static int start_le_scan(u8_t scan_type, u16_t interval, u16_t window, + u8_t filter_dup, u8_t scan_fil_policy) { UINT8 addr_type_own = BLE_MESH_ADDR_PUBLIC; /* Currently only support Public Address */ tGATT_IF client_if = 0xFF; /* Default GATT interface id */ @@ -288,7 +289,7 @@ static void bt_mesh_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARC u8_t adv_type = 0U; s8_t rssi = 0; - BT_DBG("%s, event = %d", __func__, event); + BT_DBG("%s, event %d", __func__, event); if (event == BTA_DM_INQ_RES_EVT) { /* TODO: How to process scan response here? */ @@ -300,7 +301,7 @@ static void bt_mesh_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARC /* scan rsp len: p_data->inq_res.scan_rsp_len */ struct net_buf_simple *buf = bt_mesh_alloc_buf(p_data->inq_res.adv_data_len); if (!buf) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } net_buf_simple_add_mem(buf, p_data->inq_res.p_eir, p_data->inq_res.adv_data_len); @@ -310,9 +311,9 @@ static void bt_mesh_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARC } bt_mesh_free(buf); } else if (event == BTA_DM_INQ_CMPL_EVT) { - BT_INFO("%s, Scan completed, number of scan response %d", __func__, p_data->inq_cmpl.num_resps); + BT_INFO("Scan completed, number of scan response %d", p_data->inq_cmpl.num_resps); } else { - BT_WARN("%s, Unexpected event 0x%x", __func__, event); + BT_WARN("Unexpected scan result event %d", event); } } @@ -336,13 +337,13 @@ int bt_le_adv_start(const struct bt_mesh_adv_param *param, #endif if (!valid_adv_param(param)) { - BT_ERR("%s, Invalid adv parameters", __func__); + BT_ERR("Invalid adv parameters"); return -EINVAL; } err = set_adv_data(BLE_MESH_HCI_OP_SET_ADV_DATA, ad, ad_len); if (err) { - BT_ERR("%s, Failed to set adv data", __func__); + BT_ERR("Failed to set adv data"); return err; } @@ -358,7 +359,7 @@ int bt_le_adv_start(const struct bt_mesh_adv_param *param, if (sd && (param->options & BLE_MESH_ADV_OPT_CONNECTABLE)) { err = set_adv_data(BLE_MESH_HCI_OP_SET_SCAN_RSP_DATA, sd, sd_len); if (err) { - BT_ERR("%s, Failed to set scan rsp data", __func__); + BT_ERR("Failed to set scan rsp data"); return err; } } @@ -476,7 +477,8 @@ int bt_le_scan_start(const struct bt_mesh_scan_param *param, bt_mesh_scan_cb_t c } #endif - err = start_le_scan(param->type, param->interval, param->window, param->filter_dup, param->scan_fil_policy); + err = start_le_scan(param->type, param->interval, param->window, + param->filter_dup, param->scan_fil_policy); if (err) { return err; } @@ -536,7 +538,7 @@ static void bt_mesh_bta_gatts_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) u8_t buf[100] = {0}; u16_t len = 0; - BT_DBG("%s, read: handle = %d", __func__, p_data->req_data.p_data->read_req.handle); + BT_DBG("gatts read, handle %d", p_data->req_data.p_data->read_req.handle); if (attr != NULL && attr->read != NULL) { if ((len = attr->read(&bt_mesh_gatts_conn[index], attr, buf, 100, @@ -546,9 +548,9 @@ static void bt_mesh_bta_gatts_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) memcpy(&rsp.attr_value.value[0], buf, len); BTA_GATTS_SendRsp(p_data->req_data.conn_id, p_data->req_data.trans_id, p_data->req_data.status, &rsp); - BT_DBG("%s, Send gatts read response, handle = %x", __func__, attr->handle); + BT_DBG("Send gatts read rsp, handle %d", attr->handle); } else { - BT_WARN("%s, BLE Mesh gatts read failed", __func__); + BT_WARN("Mesh gatts read failed"); } } break; @@ -558,7 +560,7 @@ static void bt_mesh_bta_gatts_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) u8_t index = BLE_MESH_GATT_GET_CONN_ID(p_data->req_data.conn_id); u16_t len = 0; - BT_DBG("%s, write: handle = %d, len = %d, data = %s", __func__, p_data->req_data.p_data->write_req.handle, + BT_DBG("gatts write, handle %d, len %d, data %s", p_data->req_data.p_data->write_req.handle, p_data->req_data.p_data->write_req.len, bt_hex(p_data->req_data.p_data->write_req.value, p_data->req_data.p_data->write_req.len)); @@ -570,7 +572,7 @@ static void bt_mesh_bta_gatts_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) if (p_data->req_data.p_data->write_req.need_rsp) { BTA_GATTS_SendRsp(p_data->req_data.conn_id, p_data->req_data.trans_id, p_data->req_data.status, NULL); - BT_DBG("%s, send mesh write rsp, handle = %x", __func__, attr->handle); + BT_DBG("Send gatts write rsp, handle %d", attr->handle); } } } @@ -584,7 +586,7 @@ static void bt_mesh_bta_gatts_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) break; case BTA_GATTS_CREATE_EVT: svc_handle = p_data->create.service_id; - BT_DBG("%s, svc_handle = %d, future_mesh = %p", __func__, svc_handle, future_mesh); + BT_DBG("svc_handle %d, future_mesh %p", svc_handle, future_mesh); if (future_mesh != NULL) { future_ready(future_mesh, FUTURE_SUCCESS); } @@ -725,7 +727,8 @@ static struct bt_mesh_gatt_attr *bt_mesh_gatts_attr_next(const struct bt_mesh_ga return next; } -ssize_t bt_mesh_gatts_attr_read(struct bt_mesh_conn *conn, const struct bt_mesh_gatt_attr *attr, +ssize_t bt_mesh_gatts_attr_read(struct bt_mesh_conn *conn, + const struct bt_mesh_gatt_attr *attr, void *buf, u16_t buf_len, u16_t offset, const void *value, u16_t value_len) { @@ -751,8 +754,8 @@ struct gatts_incl { } __packed; ssize_t bt_mesh_gatts_attr_read_included(struct bt_mesh_conn *conn, - const struct bt_mesh_gatt_attr *attr, - void *buf, u16_t len, u16_t offset) + const struct bt_mesh_gatt_attr *attr, + void *buf, u16_t len, u16_t offset) { struct bt_mesh_gatt_attr *incl = attr->user_data; struct bt_mesh_uuid *uuid = incl->user_data; @@ -801,8 +804,8 @@ struct gatts_chrc { } __packed; ssize_t bt_mesh_gatts_attr_read_chrc(struct bt_mesh_conn *conn, - const struct bt_mesh_gatt_attr *attr, void *buf, - u16_t len, u16_t offset) + const struct bt_mesh_gatt_attr *attr, + void *buf, u16_t len, u16_t offset) { struct bt_mesh_gatt_char *chrc = attr->user_data; const struct bt_mesh_gatt_attr *next = NULL; @@ -819,7 +822,7 @@ ssize_t bt_mesh_gatts_attr_read_chrc(struct bt_mesh_conn *conn, */ next = bt_mesh_gatts_attr_next(attr); if (!next) { - BT_WARN("%s, No value for characteristic at 0x%04x", __func__, attr->handle); + BT_WARN("No value for characteristic, handle 0x%04x", attr->handle); pdu.value_handle = 0x0000; } else { pdu.value_handle = sys_cpu_to_le16(next->handle); @@ -851,7 +854,7 @@ static void bta_uuid_to_bt_mesh_uuid(tBT_UUID *bta_uuid, const struct bt_mesh_uu bta_uuid->len = LEN_UUID_128; memcpy(bta_uuid->uu.uuid128, BLE_MESH_UUID_128(uuid)->val, LEN_UUID_128); } else { - BT_ERR("%s, Invalid mesh uuid type = %d", __func__, uuid->type); + BT_ERR("Invalid mesh uuid type %d", uuid->type); } return; @@ -869,7 +872,7 @@ static int gatts_register(struct bt_mesh_gatt_service *svc) last = SYS_SLIST_PEEK_TAIL_CONTAINER(&bt_mesh_gatts_db, last, node); handle = last->attrs[last->attr_count - 1].handle; - BT_DBG("%s, handle = %d", __func__, handle); + BT_DBG("gatts register, handle %d", handle); ((void) handle); @@ -934,11 +937,12 @@ int bt_mesh_gatts_service_register(struct bt_mesh_gatt_service *svc) BTA_GATTS_CreateService(bt_mesh_gatts_if, &bta_uuid, 0, svc->attr_count, true); if (future_await(future_mesh) == FUTURE_FAIL) { - BT_ERR("%s, Failed to add primary service", __func__); + BT_ERR("Failed to add primary service"); return ESP_FAIL; } svc->attrs[i].handle = svc_handle; - BT_DBG("Add primary service: svc_uuid = %x, perm = %d, svc_handle = %d", bta_uuid.uu.uuid16, svc->attrs[i].perm, svc_handle); + BT_DBG("Add primary service, uuid 0x%04x, perm %d, handle %d", + bta_uuid.uu.uuid16, svc->attrs[i].perm, svc_handle); break; } case BLE_MESH_UUID_GATT_SECONDARY_VAL: { @@ -947,11 +951,12 @@ int bt_mesh_gatts_service_register(struct bt_mesh_gatt_service *svc) BTA_GATTS_CreateService(bt_mesh_gatts_if, &bta_uuid, 0, svc->attr_count, false); if (future_await(future_mesh) == FUTURE_FAIL) { - BT_ERR("%s, Failed to add secondary service", __func__); + BT_ERR("Failed to add secondary service"); return ESP_FAIL; } svc->attrs[i].handle = svc_handle; - BT_DBG("Add secondary service: svc_uuid = %x, perm = %d, svc_handle = %d", bta_uuid.uu.uuid16, svc->attrs[i].perm, svc_handle); + BT_DBG("Add secondary service, uuid 0x%04x, perm %d, handle %d", + bta_uuid.uu.uuid16, svc->attrs[i].perm, svc_handle); break; } case BLE_MESH_UUID_GATT_INCLUDE_VAL: { @@ -963,13 +968,14 @@ int bt_mesh_gatts_service_register(struct bt_mesh_gatt_service *svc) bta_uuid_to_bt_mesh_uuid(&bta_uuid, gatts_chrc->uuid); BTA_GATTS_AddCharacteristic(svc_handle, &bta_uuid, bt_mesh_perm_to_bta_perm(svc->attrs[i + 1].perm), gatts_chrc->properties, NULL, NULL); if (future_await(future_mesh) == FUTURE_FAIL) { - BT_ERR("%s, Failed to add characteristic", __func__); + BT_ERR("Failed to add characteristic"); return ESP_FAIL; } /* All the characteristic should have two handles: the declaration handle and the value handle */ svc->attrs[i].handle = char_handle - 1; svc->attrs[i + 1].handle = char_handle; - BT_DBG("Add characteristic: char_uuid = %x, char_handle = %d, perm = %d, char_pro = %d", BLE_MESH_UUID_16(gatts_chrc->uuid)->val, char_handle, svc->attrs[i + 1].perm, gatts_chrc->properties); + BT_DBG("Add characteristic, uuid 0x%04x, handle %d, perm %d, properties %d", + BLE_MESH_UUID_16(gatts_chrc->uuid)->val, char_handle, svc->attrs[i + 1].perm, gatts_chrc->properties); break; } case BLE_MESH_UUID_GATT_CEP_VAL: @@ -987,11 +993,12 @@ int bt_mesh_gatts_service_register(struct bt_mesh_gatt_service *svc) bta_uuid_to_bt_mesh_uuid(&bta_uuid, svc->attrs[i].uuid); BTA_GATTS_AddCharDescriptor(svc_handle, bt_mesh_perm_to_bta_perm(svc->attrs[i].perm), &bta_uuid, NULL, NULL); if (future_await(future_mesh) == FUTURE_FAIL) { - BT_ERR("%s, Failed to add descriptor", __func__); + BT_ERR("Failed to add descriptor"); return ESP_FAIL; } svc->attrs[i].handle = char_handle; - BT_DBG("Add descriptor: descr_uuid = %x, perm= %d, descr_handle = %d", BLE_MESH_UUID_16(svc->attrs[i].uuid)->val, svc->attrs[i].perm, char_handle); + BT_DBG("Add descriptor, uuid 0x%04x, perm %d, handle %d", + BLE_MESH_UUID_16(svc->attrs[i].uuid)->val, svc->attrs[i].perm, char_handle); break; } default: @@ -1035,7 +1042,8 @@ int bt_mesh_gatts_service_unregister(struct bt_mesh_gatt_service *svc) return 0; } -int bt_mesh_gatts_notify(struct bt_mesh_conn *conn, const struct bt_mesh_gatt_attr *attr, +int bt_mesh_gatts_notify(struct bt_mesh_conn *conn, + const struct bt_mesh_gatt_attr *attr, const void *data, u16_t len) { u16_t conn_id = BLE_MESH_GATT_CREATE_CONN_ID(bt_mesh_gatts_if, conn->handle); @@ -1083,7 +1091,7 @@ int bt_mesh_gatts_service_start(struct bt_mesh_gatt_service *svc) uuid = (struct bt_mesh_uuid *)svc->attrs[0].user_data; if (uuid && uuid->type == BLE_MESH_UUID_TYPE_16) { uuid_16 = (struct bt_mesh_uuid_16 *)uuid; - BT_DBG("%s, type 0x%02x, val 0x%04x", __func__, uuid_16->uuid.type, uuid_16->val); + BT_DBG("service start, type 0x%02x, val 0x%04x", uuid_16->uuid.type, uuid_16->val); if (uuid_16->val == BLE_MESH_UUID_MESH_PROXY_VAL) { BTA_GATTS_SendServiceChangeIndication(bt_mesh_gatts_if, bt_mesh_gatts_addr); } @@ -1138,7 +1146,7 @@ u16_t bt_mesh_gattc_get_service_uuid(struct bt_mesh_conn *conn) } } - BT_ERR("%s, Conn is not found", __func__); + BT_ERR("Conn %p not found", conn); return 0; } @@ -1159,21 +1167,21 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, u16_t service_uuid) if (!addr || !memcmp(addr->val, zero, BLE_MESH_ADDR_LEN) || (addr->type > BLE_ADDR_RANDOM)) { - BT_ERR("%s, Invalid remote address", __func__); + BT_ERR("Invalid remote address"); return -EINVAL; } if (service_uuid != BLE_MESH_UUID_MESH_PROV_VAL && service_uuid != BLE_MESH_UUID_MESH_PROXY_VAL) { - BT_ERR("%s, Invalid service uuid 0x%04x", __func__, service_uuid); + BT_ERR("Invalid service uuid 0x%04x", service_uuid); return -EINVAL; } /* Check if already creating connection with the device */ for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) { if (!memcmp(bt_mesh_gattc_info[i].addr.val, addr->val, BLE_MESH_ADDR_LEN)) { - BT_WARN("%s, Already create connection with %s", - __func__, bt_hex(addr->val, BLE_MESH_ADDR_LEN)); + BT_WARN("Already create connection with %s", + bt_hex(addr->val, BLE_MESH_ADDR_LEN)); return -EALREADY; } } @@ -1191,7 +1199,7 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, u16_t service_uuid) } if (i == ARRAY_SIZE(bt_mesh_gattc_info)) { - BT_WARN("%s, gattc info is full", __func__); + BT_WARN("gattc info is full"); return -ENOMEM; } @@ -1200,7 +1208,7 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, u16_t service_uuid) bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING); } - BT_DBG("%s, create conn with %s", __func__, bt_hex(addr->val, BLE_MESH_ADDR_LEN)); + BT_DBG("Create conn with %s", bt_hex(addr->val, BLE_MESH_ADDR_LEN)); /* Min_interval: 250ms * Max_interval: 250ms @@ -1241,7 +1249,8 @@ u16_t bt_mesh_gattc_get_mtu_info(struct bt_mesh_conn *conn) return 0; } -int bt_mesh_gattc_write_no_rsp(struct bt_mesh_conn *conn, const struct bt_mesh_gatt_attr *attr, +int bt_mesh_gattc_write_no_rsp(struct bt_mesh_conn *conn, + const struct bt_mesh_gatt_attr *attr, const void *data, u16_t len) { u16_t conn_id = 0U; @@ -1257,7 +1266,7 @@ int bt_mesh_gattc_write_no_rsp(struct bt_mesh_conn *conn, const struct bt_mesh_g } } - BT_ERR("%s, Conn is not found", __func__); + BT_ERR("Conn %p not found", conn); return -EEXIST; } @@ -1282,7 +1291,7 @@ void bt_mesh_gattc_disconnect(struct bt_mesh_conn *conn) } } - BT_ERR("%s, Conn is not found", __func__); + BT_ERR("Conn %p not found", conn); return; } @@ -1367,7 +1376,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) } if (conn == NULL) { - BT_ERR("%s, Conn handle is not found", __func__); + BT_ERR("Conn handle 0x%04x not found", handle); return; } @@ -1507,12 +1516,12 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) } if (conn == NULL) { - BT_ERR("%s, Conn handle is not found", __func__); + BT_ERR("Conn handle 0x%04x not found", handle); return; } if (bt_mesh_gattc_info[i].ccc_handle != p_data->write.handle) { - BT_WARN("%s, gattc ccc_handle is not matched", __func__); + BT_WARN("gattc ccc_handle not matched"); bt_mesh_gattc_disconnect(conn); return; } @@ -1521,7 +1530,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->prov_write_descr != NULL) { len = bt_mesh_gattc_conn_cb->prov_write_descr(&bt_mesh_gattc_info[i].addr, &bt_mesh_gattc_info[i].conn); if (len < 0) { - BT_ERR("%s, prov_write_descr failed", __func__); + BT_ERR("prov_write_descr failed"); bt_mesh_gattc_disconnect(conn); return; } @@ -1531,7 +1540,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->proxy_write_descr != NULL) { len = bt_mesh_gattc_conn_cb->proxy_write_descr(&bt_mesh_gattc_info[i].addr, &bt_mesh_gattc_info[i].conn); if (len < 0) { - BT_ERR("%s, proxy_write_descr failed", __func__); + BT_ERR("proxy_write_descr failed"); bt_mesh_gattc_disconnect(conn); return; } @@ -1559,14 +1568,14 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) } if (conn == NULL) { - BT_ERR("%s, Conn handle is not found", __func__); + BT_ERR("Conn handle 0x%04x not found", handle); return; } if (memcmp(bt_mesh_gattc_info[i].addr.val, p_data->notify.bda, BLE_MESH_ADDR_LEN) || bt_mesh_gattc_info[i].data_out_handle != p_data->notify.handle || p_data->notify.is_notify == false) { - BT_ERR("%s, Notification error", __func__); + BT_ERR("Notification error"); bt_mesh_gattc_disconnect(conn); return; } @@ -1576,7 +1585,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) len = bt_mesh_gattc_conn_cb->prov_notify(&bt_mesh_gattc_info[i].conn, p_data->notify.value, p_data->notify.len); if (len < 0) { - BT_ERR("%s, prov_notify failed", __func__); + BT_ERR("prov_notify failed"); bt_mesh_gattc_disconnect(conn); return; } @@ -1586,7 +1595,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) len = bt_mesh_gattc_conn_cb->proxy_notify(&bt_mesh_gattc_info[i].conn, p_data->notify.value, p_data->notify.len); if (len < 0) { - BT_ERR("%s, proxy_notify failed", __func__); + BT_ERR("proxy_notify failed"); bt_mesh_gattc_disconnect(conn); return; } @@ -1610,7 +1619,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) if (!bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) { tBTM_STATUS status = BTM_BleScan(true, 0, bt_mesh_scan_results_cb, NULL, NULL); if (status != BTM_SUCCESS && status != BTM_CMD_STARTED) { - BT_ERR("%s, Invalid scan status %d", __func__, status); + BT_ERR("Invalid scan status %d", status); break; } bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING); @@ -1623,7 +1632,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) BT_DBG("BTA_GATTC_CONNECT_EVT"); if (bt_mesh_gattc_if != p_data->connect.client_if) { - BT_ERR("%s, gattc_if & connect_if don't match", __func__); + BT_ERR("gattc_if & connect_if mismatch"); return; } @@ -1642,7 +1651,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) BT_DBG("BTA_GATTC_DISCONNECT_EVT"); if (bt_mesh_gattc_if != p_data->disconnect.client_if) { - BT_ERR("%s, gattc_if & disconnect_if don't match", __func__); + BT_ERR("gattc_if & disconnect_if mismatch"); return; } @@ -1801,7 +1810,7 @@ int bt_mesh_rand(void *buf, size_t len) memcpy(buf + i * sizeof(u32_t), &rand, sizeof(u32_t)); } - BT_DBG("%s, rand: %s", __func__, bt_hex(buf, len)); + BT_DBG("Rand %s", bt_hex(buf, len)); return 0; } @@ -2003,13 +2012,13 @@ int bt_mesh_update_exceptional_list(u8_t sub_code, u8_t type, void *info) if (type == BLE_MESH_EXCEP_INFO_MESH_LINK_ID) { if (!info) { - BT_ERR("%s, NULL Provisioning Link ID", __func__); + BT_ERR("Invalid Provisioning Link ID"); return -EINVAL; } sys_memcpy_swap(value, info, sizeof(u32_t)); } - BT_DBG("%s, %s type 0x%x", __func__, sub_code ? "Remove" : "Add", type); + BT_DBG("%s exceptional list, type 0x%02x", sub_code ? "Remove" : "Add", type); /* The parameter "device_info" can't be NULL in the API */ BLE_MESH_BTM_CHECK_STATUS(BTM_UpdateBleDuplicateExceptionalList(sub_code, type, value, NULL)); diff --git a/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c b/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c index 0390f4923..628d501d9 100644 --- a/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c +++ b/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c @@ -151,7 +151,7 @@ static void cfg_client_cancel(struct bt_mesh_model *model, 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); + BT_DBG("Unexpected Config Status 0x%04x", ctx->recv_op); } else { switch (node->opcode) { case OP_BEACON_GET: @@ -266,7 +266,7 @@ static void comp_data_status(struct bt_mesh_model *model, status.page = net_buf_simple_pull_u8(buf); status.comp_data = bt_mesh_alloc_buf(buf->len); if (!status.comp_data) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } @@ -515,7 +515,7 @@ static void mod_sub_list(struct bt_mesh_model *model, list.addr = bt_mesh_alloc_buf(buf->len); if (!list.addr) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } net_buf_simple_add_mem(list.addr, buf->data, buf->len); @@ -535,7 +535,7 @@ static void net_key_list(struct bt_mesh_model *model, list.net_idx = bt_mesh_alloc_buf(buf->len); if (!list.net_idx) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } net_buf_simple_add_mem(list.net_idx, buf->data, buf->len); @@ -557,7 +557,7 @@ static void app_key_list(struct bt_mesh_model *model, list.net_idx = net_buf_simple_pull_le16(buf); list.app_idx = bt_mesh_alloc_buf(buf->len); if (!list.app_idx) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } net_buf_simple_add_mem(list.app_idx, buf->data, buf->len); @@ -603,7 +603,7 @@ static void mod_app_list(struct bt_mesh_model *model, list.app_idx = bt_mesh_alloc_buf(buf->len); if (!list.app_idx) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } net_buf_simple_add_mem(list.app_idx, buf->data, buf->len); diff --git a/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c b/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c index 6806daa4a..d2ea61c33 100644 --- a/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c +++ b/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c @@ -50,7 +50,7 @@ static int comp_add_elem(struct net_buf_simple *buf, struct bt_mesh_elem *elem, if (net_buf_simple_tailroom(buf) < 4 + (elem->model_count * 2U) + (elem->vnd_model_count * 4U)) { - BT_ERR("%s, Too large device composition", __func__); + BT_ERR("Too large device composition"); return -E2BIG; } @@ -134,7 +134,7 @@ static void dev_comp_data_get(struct bt_mesh_model *model, sdu = bt_mesh_alloc_buf(MIN(BLE_MESH_TX_SDU_MAX, COMP_DATA_MAX_LEN)); if (!sdu) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } @@ -142,13 +142,13 @@ static void dev_comp_data_get(struct bt_mesh_model *model, net_buf_simple_add_u8(sdu, page); if (comp_get_page_0(sdu) < 0) { - BT_ERR("%s, Unable to get composition page 0", __func__); + BT_ERR("Unable to get composition page 0"); bt_mesh_free_buf(sdu); return; } if (bt_mesh_model_send(model, ctx, sdu, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Composition Data Status", __func__); + BT_ERR("Unable to send Config Composition Data Status"); } bt_mesh_free_buf(sdu); @@ -457,7 +457,7 @@ static void app_key_add(struct bt_mesh_model *model, key_idx_pack(&msg, key_net_idx, key_app_idx); if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config AppKey Status", __func__); + BT_ERR("Unable to send Config AppKey Status"); return; } @@ -492,7 +492,7 @@ static void app_key_update(struct bt_mesh_model *model, key_idx_pack(&msg, key_net_idx, key_app_idx); if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config AppKey Status", __func__); + BT_ERR("Unable to send Config AppKey Status"); } if (status == STATUS_SUCCESS) { @@ -577,7 +577,7 @@ send_status: key_idx_pack(&msg, key_net_idx, key_app_idx); if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config AppKey Status", __func__); + BT_ERR("Unable to send Config AppKey Status"); } if (status == STATUS_SUCCESS) { @@ -603,7 +603,7 @@ static void app_key_get(struct bt_mesh_model *model, get_idx = net_buf_simple_pull_le16(buf); if (get_idx > 0xfff) { - BT_ERR("%s, Invalid NetKeyIndex 0x%04x", __func__, get_idx); + BT_ERR("Invalid NetKeyIndex 0x%04x", get_idx); return; } @@ -647,7 +647,7 @@ static void app_key_get(struct bt_mesh_model *model, send_status: if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config AppKey List", __func__); + BT_ERR("Unable to send Config AppKey List"); } } @@ -665,7 +665,7 @@ static void beacon_get(struct bt_mesh_model *model, net_buf_simple_add_u8(&msg, bt_mesh_beacon_get()); if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Beacon Status", __func__); + BT_ERR("Unable to send Config Beacon Status"); } } @@ -705,7 +705,7 @@ static void beacon_set(struct bt_mesh_model *model, net_buf_simple_add_u8(&msg, bt_mesh_beacon_get()); if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Beacon Status", __func__); + BT_ERR("Unable to send Config Beacon Status"); } } @@ -723,7 +723,7 @@ static void default_ttl_get(struct bt_mesh_model *model, net_buf_simple_add_u8(&msg, bt_mesh_default_ttl_get()); if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Default TTL Status", __func__); + BT_ERR("Unable to send Config Default TTL Status"); } } @@ -757,7 +757,7 @@ static void default_ttl_set(struct bt_mesh_model *model, net_buf_simple_add_u8(&msg, bt_mesh_default_ttl_get()); if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Default TTL Status", __func__); + BT_ERR("Unable to send Config Default TTL Status"); } } @@ -770,7 +770,7 @@ static void send_gatt_proxy_status(struct bt_mesh_model *model, net_buf_simple_add_u8(&msg, bt_mesh_gatt_proxy_get()); if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config GATT Proxy Status", __func__); + BT_ERR("Unable to send Config GATT Proxy Status"); } } @@ -844,7 +844,7 @@ static void net_transmit_get(struct bt_mesh_model *model, net_buf_simple_add_u8(&msg, bt_mesh_net_transmit_get()); if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Network Transmit Status", __func__); + BT_ERR("Unable to send Config Network Transmit Status"); } } @@ -877,7 +877,7 @@ static void net_transmit_set(struct bt_mesh_model *model, net_buf_simple_add_u8(&msg, bt_mesh_net_transmit_get()); if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Network Transmit Status", __func__); + BT_ERR("Unable to send Config Network Transmit Status"); } } @@ -896,7 +896,7 @@ static void relay_get(struct bt_mesh_model *model, net_buf_simple_add_u8(&msg, bt_mesh_relay_retransmit_get()); if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Relay Status", __func__); + BT_ERR("Unable to send Config Relay Status"); } } @@ -947,7 +947,7 @@ static void relay_set(struct bt_mesh_model *model, net_buf_simple_add_u8(&msg, bt_mesh_relay_retransmit_get()); if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Relay Status", __func__); + BT_ERR("Unable to send Config Relay Status"); } } @@ -985,7 +985,7 @@ static void send_mod_pub_status(struct bt_mesh_model *cfg_mod, } if (bt_mesh_model_send(cfg_mod, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Model Publication Status", __func__); + BT_ERR("Unable to send Config Model Publication Status"); } } @@ -1001,7 +1001,7 @@ static void mod_pub_get(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) { - BT_ERR("%s, Prohibited element address 0x%04x", __func__, elem_addr); + BT_ERR("Prohibited element address 0x%04x", elem_addr); return; } @@ -1049,7 +1049,7 @@ static void mod_pub_set(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) { - BT_ERR("%s, Prohibited element address 0x%04x", __func__, elem_addr); + BT_ERR("Prohibited element address 0x%04x", elem_addr); return; } @@ -1060,7 +1060,7 @@ static void mod_pub_set(struct bt_mesh_model *model, pub_ttl = net_buf_simple_pull_u8(buf); if (pub_ttl > BLE_MESH_TTL_MAX && pub_ttl != BLE_MESH_TTL_DEFAULT) { - BT_ERR("%s, Invalid TTL value 0x%02x", __func__, pub_ttl); + BT_ERR("Invalid TTL value 0x%02x", pub_ttl); return; } @@ -1232,7 +1232,7 @@ static size_t mod_sub_list_clear(struct bt_mesh_model *mod) if (label_uuid) { va_del(label_uuid, NULL); } else { - BT_ERR("%s, Label UUID not found", __func__); + BT_ERR("Label UUID not found"); } } @@ -1253,7 +1253,7 @@ static void mod_pub_va_set(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) { - BT_ERR("%s, Prohibited element address 0x%04x", __func__, elem_addr); + BT_ERR("Prohibited element address 0x%04x", elem_addr); return; } @@ -1263,7 +1263,7 @@ static void mod_pub_va_set(struct bt_mesh_model *model, pub_app_idx &= BIT_MASK(12); pub_ttl = net_buf_simple_pull_u8(buf); if (pub_ttl > BLE_MESH_TTL_MAX && pub_ttl != BLE_MESH_TTL_DEFAULT) { - BT_ERR("%s, Invalid TTL value 0x%02x", __func__, pub_ttl); + BT_ERR("Invalid TTL value 0x%02x", pub_ttl); return; } @@ -1333,7 +1333,7 @@ static void mod_pub_va_set(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) { - BT_ERR("%s, Prohibited element address 0x%04x", __func__, elem_addr); + BT_ERR("Prohibited element address 0x%04x", elem_addr); return; } @@ -1393,7 +1393,7 @@ static void send_mod_sub_status(struct bt_mesh_model *model, } if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Model Subscription Status", __func__); + BT_ERR("Unable to send Config Model Subscription Status"); } } @@ -1411,7 +1411,7 @@ static void mod_sub_add(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) { - BT_ERR("%s, Prohibited element address 0x%04x", __func__, elem_addr); + BT_ERR("Prohibited element address 0x%04x", elem_addr); return; } @@ -1497,7 +1497,7 @@ static void mod_sub_del(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) { - BT_ERR("%s, Prohibited element address 0x%04x", __func__, elem_addr); + BT_ERR("Prohibited element address 0x%04x", elem_addr); return; } @@ -1572,7 +1572,7 @@ static void mod_sub_overwrite(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) { - BT_ERR("%s, Prohibited element address 0x%04x", __func__, elem_addr); + BT_ERR("Prohibited element address 0x%04x", elem_addr); return; } @@ -1641,7 +1641,7 @@ static void mod_sub_del_all(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) { - BT_ERR("%s, Prohibited element address 0x%04x", __func__, elem_addr); + BT_ERR("Prohibited element address 0x%04x", elem_addr); return; } @@ -1693,7 +1693,7 @@ static void mod_sub_get(struct bt_mesh_model *model, addr = net_buf_simple_pull_le16(buf); if (!BLE_MESH_ADDR_IS_UNICAST(addr)) { - BT_ERR("%s, Prohibited element address 0x%04x", __func__, addr); + BT_ERR("Prohibited element address 0x%04x", addr); return; } @@ -1732,7 +1732,7 @@ static void mod_sub_get(struct bt_mesh_model *model, send_list: if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Model Subscription List", __func__); + BT_ERR("Unable to send Config Model Subscription List"); } } @@ -1749,7 +1749,7 @@ static void mod_sub_get_vnd(struct bt_mesh_model *model, addr = net_buf_simple_pull_le16(buf); if (!BLE_MESH_ADDR_IS_UNICAST(addr)) { - BT_ERR("%s, Prohibited element address 0x%04x", __func__, addr); + BT_ERR("Prohibited element address 0x%04x", addr); return; } @@ -1792,7 +1792,7 @@ static void mod_sub_get_vnd(struct bt_mesh_model *model, send_list: if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Vendor Model Subscription List", __func__); + BT_ERR("Unable to send Config Vendor Model Subscription List"); } } @@ -1812,7 +1812,7 @@ static void mod_sub_va_add(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) { - BT_ERR("%s, Prohibited element address 0x%04x", __func__, elem_addr); + BT_ERR("Prohibited element address 0x%04x", elem_addr); return; } @@ -1889,7 +1889,7 @@ static void mod_sub_va_del(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) { - BT_ERR("%s, Prohibited element address 0x%04x", __func__, elem_addr); + BT_ERR("Prohibited element address 0x%04x", elem_addr); return; } @@ -1956,7 +1956,7 @@ static void mod_sub_va_overwrite(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) { - BT_ERR("%s, Prohibited element address 0x%04x", __func__, elem_addr); + BT_ERR("Prohibited element address 0x%04x", elem_addr); return; } @@ -2021,7 +2021,7 @@ static void mod_sub_va_add(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) { - BT_ERR("%s, Prohibited element address 0x%04x", __func__, elem_addr); + BT_ERR("Prohibited element address 0x%04x", elem_addr); return; } @@ -2062,7 +2062,7 @@ static void mod_sub_va_del(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) { - BT_ERR("%s, Prohibited element address 0x%04x", __func__, elem_addr); + BT_ERR("Prohibited element address 0x%04x", elem_addr); return; } @@ -2101,7 +2101,7 @@ static void mod_sub_va_overwrite(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) { - BT_ERR("%s, Prohibited element address 0x%04x", __func__, elem_addr); + BT_ERR("Prohibited element address 0x%04x", elem_addr); return; } @@ -2141,7 +2141,7 @@ static void send_net_key_status(struct bt_mesh_model *model, net_buf_simple_add_le16(&msg, idx); if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config NetKey Status", __func__); + BT_ERR("Unable to send Config NetKey Status"); } } @@ -2155,7 +2155,7 @@ static void net_key_add(struct bt_mesh_model *model, idx = net_buf_simple_pull_le16(buf); if (idx > 0xfff) { - BT_ERR("%s, Invalid NetKeyIndex 0x%04x", __func__, idx); + BT_ERR("Invalid NetKeyIndex 0x%04x", idx); return; } @@ -2236,7 +2236,7 @@ static void net_key_update(struct bt_mesh_model *model, idx = net_buf_simple_pull_le16(buf); if (idx > 0xfff) { - BT_ERR("%s, Invalid NetKeyIndex 0x%04x", __func__, idx); + BT_ERR("Invalid NetKeyIndex 0x%04x", idx); return; } @@ -2323,7 +2323,7 @@ static void net_key_del(struct bt_mesh_model *model, del_idx = net_buf_simple_pull_le16(buf); if (del_idx > 0xfff) { - BT_ERR("%s, Invalid NetKeyIndex 0x%04x", __func__, del_idx); + BT_ERR("Invalid NetKeyIndex 0x%04x", del_idx); return; } @@ -2392,7 +2392,7 @@ static void net_key_get(struct bt_mesh_model *model, } if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config NetKey List", __func__); + BT_ERR("Unable to send Config NetKey List"); } } @@ -2411,7 +2411,7 @@ static void node_identity_get(struct bt_mesh_model *model, idx = net_buf_simple_pull_le16(buf); if (idx > 0xfff) { - BT_ERR("%s, Invalid NetKeyIndex 0x%04x", __func__, idx); + BT_ERR("Invalid NetKeyIndex 0x%04x", idx); return; } @@ -2430,7 +2430,7 @@ static void node_identity_get(struct bt_mesh_model *model, net_buf_simple_add_u8(&msg, node_id); if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Node Identity Status", __func__); + BT_ERR("Unable to send Config Node Identity Status"); } } @@ -2449,13 +2449,13 @@ static void node_identity_set(struct bt_mesh_model *model, idx = net_buf_simple_pull_le16(buf); if (idx > 0xfff) { - BT_WARN("%s, Invalid NetKeyIndex 0x%04x", __func__, idx); + BT_WARN("Invalid NetKeyIndex 0x%04x", idx); return; } node_id = net_buf_simple_pull_u8(buf); if (node_id != 0x00 && node_id != 0x01) { - BT_WARN("%s, Invalid Node ID value 0x%02x", __func__, node_id); + BT_WARN("Invalid Node ID value 0x%02x", node_id); return; } @@ -2482,7 +2482,7 @@ static void node_identity_set(struct bt_mesh_model *model, } if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Node Identity Status", __func__); + BT_ERR("Unable to send Config Node Identity Status"); } } @@ -2517,7 +2517,7 @@ static void mod_app_bind(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) { - BT_ERR("%s, Prohibited element address 0x%04x", __func__, elem_addr); + BT_ERR("Prohibited element address 0x%04x", elem_addr); return; } @@ -2540,7 +2540,7 @@ static void mod_app_bind(struct bt_mesh_model *model, /* Configuration Server only allows device key based access */ if (model == mod) { - BT_ERR("%s, Client tried to bind AppKey to Configuration Model", __func__); + BT_ERR("Client tried to bind AppKey to Configuration Model"); status = STATUS_CANNOT_BIND; goto send_status; } @@ -2553,7 +2553,7 @@ send_status: mod_id); if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Model App Bind Status", __func__); + BT_ERR("Unable to send Config Model App Bind Status"); } if (status == STATUS_SUCCESS) { @@ -2580,7 +2580,7 @@ static void mod_app_unbind(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) { - BT_ERR("%s, Prohibited element address 0x%04x", __func__, elem_addr); + BT_ERR("Prohibited element address 0x%04x", elem_addr); return; } @@ -2609,7 +2609,7 @@ send_status: mod_id); if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Model App Unbind Status", __func__); + BT_ERR("Unable to send Config Model App Unbind Status"); } if (status == STATUS_SUCCESS) { @@ -2642,7 +2642,7 @@ static void mod_app_get(struct bt_mesh_model *model, elem_addr = net_buf_simple_pull_le16(buf); if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) { - BT_ERR("%s, Prohibited element address 0x%04x", __func__, elem_addr); + BT_ERR("Prohibited element address 0x%04x", elem_addr); return; } @@ -2693,7 +2693,7 @@ send_list: } if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Model Application List", __func__); + BT_ERR("Unable to send Config Model Application List"); } } @@ -2714,7 +2714,7 @@ static void node_reset(struct bt_mesh_model *model, * send it later. */ if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Node Reset Status", __func__); + BT_ERR("Unable to send Config Node Reset Status"); } if (IS_ENABLED(CONFIG_BLE_MESH_NODE)) { @@ -2732,7 +2732,7 @@ static void send_friend_status(struct bt_mesh_model *model, net_buf_simple_add_u8(&msg, cfg->frnd); if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Friend Status", __func__); + BT_ERR("Unable to send Config Friend Status"); } } @@ -2832,7 +2832,7 @@ send_rsp: net_buf_simple_add_le24(&msg, timeout); if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config LPN PollTimeout Status", __func__); + BT_ERR("Unable to send Config LPN PollTimeout Status"); } } @@ -2849,7 +2849,7 @@ static void send_krp_status(struct bt_mesh_model *model, net_buf_simple_add_u8(&msg, phase); if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Key Refresh Phase Status", __func__); + BT_ERR("Unable to send Config Key Refresh Phase Status"); } } @@ -2861,7 +2861,7 @@ static void krp_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, idx = net_buf_simple_pull_le16(buf); if (idx > 0xfff) { - BT_ERR("%s, Invalid NetKeyIndex 0x%04x", __func__, idx); + BT_ERR("Invalid NetKeyIndex 0x%04x", idx); return; } @@ -2887,7 +2887,7 @@ static void krp_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, phase = net_buf_simple_pull_u8(buf); if (idx > 0xfff) { - BT_ERR("%s, Invalid NetKeyIndex 0x%04x", __func__, idx); + BT_ERR("Invalid NetKeyIndex 0x%04x", idx); return; } @@ -2904,7 +2904,7 @@ static void krp_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, if (phase < BLE_MESH_KR_PHASE_2 || phase > BLE_MESH_KR_PHASE_3 || (sub->kr_phase == BLE_MESH_KR_NORMAL && phase == BLE_MESH_KR_PHASE_2)) { - BT_WARN("%s, Prohibited transition %u -> %u", __func__, sub->kr_phase, phase); + BT_WARN("Prohibited transition %u -> %u", sub->kr_phase, phase); return; } @@ -3007,7 +3007,7 @@ static void hb_pub_send_status(struct bt_mesh_model *model, send: if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Config Heartbeat Publication Status", __func__); + BT_ERR("Unable to send Config Heartbeat Publication Status"); } } @@ -3049,7 +3049,7 @@ static void heartbeat_pub_set(struct bt_mesh_model *model, } if (param->ttl > BLE_MESH_TTL_MAX && param->ttl != BLE_MESH_TTL_DEFAULT) { - BT_ERR("%s, Invalid TTL value 0x%02x", __func__, param->ttl); + BT_ERR("Invalid TTL value 0x%02x", param->ttl); return; } @@ -3057,7 +3057,7 @@ static void heartbeat_pub_set(struct bt_mesh_model *model, idx = sys_le16_to_cpu(param->net_idx); if (idx > 0xfff) { - BT_ERR("%s, Invalid NetKeyIndex 0x%04x", __func__, idx); + BT_ERR("Invalid NetKeyIndex 0x%04x", idx); return; } @@ -3146,7 +3146,7 @@ static void hb_sub_send_status(struct bt_mesh_model *model, 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__); + BT_ERR("Unable to send Config Heartbeat Subscription Status"); } } @@ -3305,8 +3305,8 @@ static void hb_publish(struct k_work *work) sub = bt_mesh_subnet_get(cfg->hb_pub.net_idx); if (!sub) { - BT_ERR("%s, No matching subnet for idx 0x%02x", - __func__, cfg->hb_pub.net_idx); + BT_ERR("No matching subnet for idx 0x%04x", + cfg->hb_pub.net_idx); cfg->hb_pub.dst = BLE_MESH_ADDR_UNASSIGNED; return; } @@ -3349,12 +3349,12 @@ int bt_mesh_cfg_srv_init(struct bt_mesh_model *model, bool primary) struct bt_mesh_cfg_srv *cfg = model->user_data; if (!cfg) { - BT_ERR("%s, No Configuration Server context provided", __func__); + BT_ERR("No Configuration Server context provided"); return -EINVAL; } if (!conf_is_valid(cfg)) { - BT_ERR("%s, Invalid values in configuration", __func__); + BT_ERR("Invalid values in configuration"); return -EINVAL; } @@ -3389,7 +3389,7 @@ int bt_mesh_cfg_srv_deinit(struct bt_mesh_model *model, bool primary) struct bt_mesh_cfg_srv *cfg = model->user_data; if (!cfg) { - BT_ERR("%s, No Configuration Server context provided", __func__); + BT_ERR("No Configuration Server context provided"); return -EINVAL; } diff --git a/components/bt/esp_ble_mesh/mesh_core/crypto.h b/components/bt/esp_ble_mesh/mesh_core/crypto.h index feed22613..147d85673 100644 --- a/components/bt/esp_ble_mesh/mesh_core/crypto.h +++ b/components/bt/esp_ble_mesh/mesh_core/crypto.h @@ -59,7 +59,7 @@ int bt_mesh_k4(const u8_t n[16], u8_t out[1]); int bt_mesh_id128(const u8_t n[16], const char *s, u8_t out[16]); static inline int bt_mesh_id_resolving_key(const u8_t net_key[16], - u8_t resolving_key[16]) + u8_t resolving_key[16]) { return bt_mesh_k1_str(net_key, 16, "smbt", "smbi", resolving_key); } diff --git a/components/bt/esp_ble_mesh/mesh_core/fast_prov.c b/components/bt/esp_ble_mesh/mesh_core/fast_prov.c index cbb732658..f7cb529ca 100644 --- a/components/bt/esp_ble_mesh/mesh_core/fast_prov.c +++ b/components/bt/esp_ble_mesh/mesh_core/fast_prov.c @@ -33,7 +33,7 @@ const u8_t *bt_mesh_fast_prov_dev_key_get(u16_t dst) { if (!BLE_MESH_ADDR_IS_UNICAST(dst)) { - BT_ERR("%s, Not a unicast address 0x%04x", __func__, dst); + BT_ERR("Invalid unicast address 0x%04x", dst); return NULL; } @@ -114,7 +114,7 @@ u8_t bt_mesh_fast_prov_net_key_add(const u8_t net_key[16]) err = bt_mesh_provisioner_local_net_key_add(net_key, &net_idx); if (err) { - BT_ERR("%s, Failed to add NetKey 0x%04x", __func__, net_idx); + BT_ERR("Invalid NetKeyIndex 0x%04x", net_idx); return 0x01; /* status: Add NetKey failed */ }; @@ -128,7 +128,7 @@ const u8_t *bt_mesh_fast_prov_net_key_get(u16_t net_idx) sub = bt_mesh_fast_prov_subnet_get(net_idx); if (!sub) { - BT_ERR("%s, NetKey Index 0x%03x not exists", __func__, net_idx); + BT_ERR("Invalid NetKeyIndex 0x%04x", net_idx); return NULL; } @@ -141,7 +141,7 @@ const u8_t *bt_mesh_get_fast_prov_app_key(u16_t net_idx, u16_t app_idx) key = bt_mesh_fast_prov_app_key_find(app_idx); if (!key) { - BT_ERR("%s, AppKey Index 0x%03x not exists", __func__, app_idx); + BT_ERR("Invalid AppKeyIndex 0x%04x", app_idx); return NULL; } diff --git a/components/bt/esp_ble_mesh/mesh_core/friend.c b/components/bt/esp_ble_mesh/mesh_core/friend.c index 0c714bc9b..0874142f3 100644 --- a/components/bt/esp_ble_mesh/mesh_core/friend.c +++ b/components/bt/esp_ble_mesh/mesh_core/friend.c @@ -254,7 +254,7 @@ int bt_mesh_friend_clear(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf) struct bt_mesh_ctl_friend_clear_confirm cfm = {0}; if (buf->len < sizeof(*msg)) { - BT_WARN("%s, Too short Friend Clear", __func__); + BT_WARN("Too short Friend Clear (len %d)", buf->len); return -EINVAL; } @@ -265,7 +265,7 @@ int bt_mesh_friend_clear(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf) frnd = bt_mesh_friend_find(rx->sub->net_idx, lpn_addr, false, false); if (!frnd) { - BT_WARN("%s, No matching LPN addr 0x%04x", __func__, lpn_addr); + BT_WARN("No matching LPN addr 0x%04x", lpn_addr); return 0; } @@ -276,8 +276,8 @@ int bt_mesh_friend_clear(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf) * 65536, is in the range 0 to 255 inclusive. */ if (lpn_counter - frnd->lpn_counter > 255) { - BT_WARN("%s, LPN Counter out of range (old %u new %u)", - __func__, frnd->lpn_counter, lpn_counter); + BT_WARN("LPN Counter out of range (old %u new %u)", + frnd->lpn_counter, lpn_counter); return 0; } @@ -305,7 +305,7 @@ static void friend_sub_add(struct bt_mesh_friend *frnd, u16_t addr) } } - BT_WARN("%s, No space in friend subscription list", __func__); + BT_WARN("No space in friend subscription list"); } static void friend_sub_rem(struct bt_mesh_friend *frnd, u16_t addr) @@ -588,7 +588,7 @@ static void enqueue_sub_cfm(struct bt_mesh_friend *frnd, u8_t xact) buf = encode_friend_ctl(frnd, TRANS_CTL_OP_FRIEND_SUB_CFM, &sdu); if (!buf) { - BT_ERR("%s, Unable to encode Subscription List Confirmation", __func__); + BT_ERR("Unable to encode Subscription List Confirmation"); return; } @@ -619,18 +619,18 @@ int bt_mesh_friend_sub_add(struct bt_mesh_net_rx *rx, u8_t xact = 0U; if (buf->len < BLE_MESH_FRIEND_SUB_MIN_LEN) { - BT_WARN("%s, Too short Friend Subscription Add", __func__); + BT_WARN("Too short Friend Subscription Add (len %d)", buf->len); return -EINVAL; } frnd = bt_mesh_friend_find(rx->sub->net_idx, rx->ctx.addr, true, true); if (!frnd) { - BT_WARN("%s, No matching LPN addr 0x%04x", __func__, rx->ctx.addr); + BT_WARN("No matching LPN addr 0x%04x", rx->ctx.addr); return 0; } if (frnd->pending_buf) { - BT_WARN("%s, Previous buffer not yet sent!", __func__); + BT_WARN("Previous buffer not yet sent!"); return 0; } @@ -654,18 +654,18 @@ int bt_mesh_friend_sub_rem(struct bt_mesh_net_rx *rx, u8_t xact = 0U; if (buf->len < BLE_MESH_FRIEND_SUB_MIN_LEN) { - BT_WARN("%s, Too short Friend Subscription Remove", __func__); + BT_WARN("Too short Friend Subscription Remove (len %d)", buf->len); return -EINVAL; } frnd = bt_mesh_friend_find(rx->sub->net_idx, rx->ctx.addr, true, true); if (!frnd) { - BT_WARN("%s, No matching LPN addr 0x%04x", __func__, rx->ctx.addr); + BT_WARN("No matching LPN addr 0x%04x", rx->ctx.addr); return 0; } if (frnd->pending_buf) { - BT_WARN("%s, Previous buffer not yet sent!", __func__); + BT_WARN("Previous buffer not yet sent!"); return 0; } @@ -694,7 +694,7 @@ static void enqueue_update(struct bt_mesh_friend *frnd, u8_t md) buf = encode_update(frnd, md); if (!buf) { - BT_ERR("%s, Unable to encode Friend Update", __func__); + BT_ERR("Unable to encode Friend Update"); return; } @@ -708,23 +708,23 @@ int bt_mesh_friend_poll(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf) struct bt_mesh_friend *frnd = NULL; if (buf->len < sizeof(*msg)) { - BT_WARN("%s, Too short Friend Poll", __func__); + BT_WARN("Too short Friend Poll (len %d)", buf->len); return -EINVAL; } frnd = bt_mesh_friend_find(rx->sub->net_idx, rx->ctx.addr, true, false); if (!frnd) { - BT_WARN("%s, No matching LPN addr 0x%04x", __func__, rx->ctx.addr); + BT_WARN("No matching LPN addr 0x%04x", rx->ctx.addr); return 0; } if (msg->fsn & ~1) { - BT_WARN("%s, Prohibited (non-zero) padding bits", __func__); + BT_WARN("Prohibited (non-zero) padding bits"); return -EINVAL; } if (frnd->pending_buf) { - BT_WARN("%s, Previous buffer not yet sent!", __func__); + BT_WARN("Previous buffer not yet sent!"); return 0; } @@ -856,27 +856,27 @@ int bt_mesh_friend_clear_cfm(struct bt_mesh_net_rx *rx, BT_DBG("%s", __func__); if (buf->len < sizeof(*msg)) { - BT_WARN("%s, Too short Friend Clear Confirm", __func__); + BT_WARN("Too short Friend Clear Confirm (len %d)", buf->len); return -EINVAL; } frnd = find_clear(rx->ctx.addr); if (!frnd) { - BT_WARN("%s, No pending clear procedure for 0x%02x", __func__, rx->ctx.addr); + BT_WARN("No pending clear procedure for 0x%02x", rx->ctx.addr); return 0; } lpn_addr = sys_be16_to_cpu(msg->lpn_addr); if (lpn_addr != frnd->lpn) { - BT_WARN("%s, LPN address mismatch (0x%04x != 0x%04x)", - __func__, lpn_addr, frnd->lpn); + BT_WARN("LPN address mismatch (0x%04x != 0x%04x)", + lpn_addr, frnd->lpn); return 0; } lpn_counter = sys_be16_to_cpu(msg->lpn_counter); if (lpn_counter != frnd->lpn_counter) { - BT_WARN("%s, LPN counter mismatch (0x%04x != 0x%04x)", - __func__, lpn_counter, frnd->lpn_counter); + BT_WARN("LPN counter mismatch (0x%04x != 0x%04x)", + lpn_counter, frnd->lpn_counter); return 0; } @@ -906,7 +906,7 @@ static void enqueue_offer(struct bt_mesh_friend *frnd, s8_t rssi) buf = encode_friend_ctl(frnd, TRANS_CTL_OP_FRIEND_OFFER, &sdu); if (!buf) { - BT_ERR("%s, Unable to encode Friend Offer", __func__); + BT_ERR("Unable to encode Friend Offer"); return; } @@ -964,47 +964,47 @@ int bt_mesh_friend_req(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf) int i; if (buf->len < sizeof(*msg)) { - BT_WARN("%s, Too short Friend Request", __func__); + BT_WARN("Too short Friend Request (len %d)", buf->len); return -EINVAL; } if (msg->recv_delay <= 0x09) { - BT_WARN("%s, Prohibited ReceiveDelay (0x%02x)", __func__, msg->recv_delay); + BT_WARN("Prohibited ReceiveDelay (0x%02x)", msg->recv_delay); return -EINVAL; } poll_to = sys_get_be24(msg->poll_to); if (poll_to <= 0x000009 || poll_to >= 0x34bc00) { - BT_WARN("%s, Prohibited PollTimeout (0x%06x)", __func__, poll_to); + BT_WARN("Prohibited PollTimeout (0x%06x)", poll_to); return -EINVAL; } if (msg->num_elem == 0x00) { - BT_WARN("%s, Prohibited NumElements value (0x00)", __func__); + BT_WARN("Prohibited NumElements value (0x00)"); return -EINVAL; } if (!BLE_MESH_ADDR_IS_UNICAST(rx->ctx.addr + msg->num_elem - 1)) { - BT_WARN("%s, LPN elements stretch outside of unicast range", __func__); + BT_WARN("LPN elements stretch outside of unicast range"); return -EINVAL; } if (!MIN_QUEUE_SIZE_LOG(msg->criteria)) { - BT_WARN("%s, Prohibited Minimum Queue Size in Friend Request", __func__); + BT_WARN("Prohibited Minimum Queue Size in Friend Request"); return -EINVAL; } if (CONFIG_BLE_MESH_FRIEND_QUEUE_SIZE < MIN_QUEUE_SIZE(msg->criteria)) { - BT_WARN("%s, We have a too small Friend Queue size (%u < %u)", - __func__, CONFIG_BLE_MESH_FRIEND_QUEUE_SIZE, + BT_WARN("We have a too small Friend Queue size (%u < %u)", + CONFIG_BLE_MESH_FRIEND_QUEUE_SIZE, MIN_QUEUE_SIZE(msg->criteria)); return 0; } frnd = bt_mesh_friend_find(rx->sub->net_idx, rx->ctx.addr, true, false); if (frnd) { - BT_WARN("%s, Existing LPN re-requesting Friendship", __func__); + BT_WARN("Existing LPN re-requesting Friendship"); friend_clear(frnd, BLE_MESH_FRIENDSHIP_TERMINATE_RECV_FRND_REQ); goto init_friend; } @@ -1018,7 +1018,7 @@ int bt_mesh_friend_req(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf) } if (!frnd) { - BT_WARN("%s, No free Friend contexts for new LPN", __func__); + BT_WARN("No free Friend contexts for new LPN"); return -ENOMEM; } @@ -1206,14 +1206,14 @@ static void friend_timeout(struct k_work *work) } if (frnd->established && !frnd->pending_req) { - BT_WARN("%s, Friendship lost with 0x%04x", __func__, frnd->lpn); + BT_WARN("Friendship lost with 0x%04x", frnd->lpn); friend_clear(frnd, BLE_MESH_FRIENDSHIP_TERMINATE_POLL_TIMEOUT); return; } frnd->last = (void *)sys_slist_get(&frnd->queue); if (!frnd->last) { - BT_WARN("%s, Friendship not established with 0x%04x", __func__, frnd->lpn); + BT_WARN("Friendship not established with 0x%04x", frnd->lpn); friend_clear(frnd, BLE_MESH_FRIENDSHIP_TERMINATE_ESTABLISH_FAIL); return; } @@ -1400,7 +1400,7 @@ static void friend_lpn_enqueue_rx(struct bt_mesh_friend *frnd, buf = create_friend_pdu(frnd, &info, sbuf); if (!buf) { - BT_ERR("%s, Failed to encode Friend buffer", __func__); + BT_ERR("Failed to encode Friend buffer"); return; } @@ -1437,7 +1437,7 @@ static void friend_lpn_enqueue_tx(struct bt_mesh_friend *frnd, buf = create_friend_pdu(frnd, &info, sbuf); if (!buf) { - BT_ERR("%s, Failed to encode Friend buffer", __func__); + BT_ERR("Failed to encode Friend buffer"); return; } @@ -1695,7 +1695,7 @@ void bt_mesh_friend_clear_incomplete(struct bt_mesh_subnet *sub, u16_t src, continue; } - BT_WARN("%s, Clearing incomplete segments for 0x%04x", __func__, src); + BT_WARN("Clearing incomplete segments for 0x%04x", src); purge_buffers(&seg->queue); seg->seg_count = 0U; diff --git a/components/bt/esp_ble_mesh/mesh_core/health_cli.c b/components/bt/esp_ble_mesh/mesh_core/health_cli.c index bceb45047..dbfbe4eef 100644 --- a/components/bt/esp_ble_mesh/mesh_core/health_cli.c +++ b/components/bt/esp_ble_mesh/mesh_core/health_cli.c @@ -106,7 +106,7 @@ static void health_client_cancel(struct bt_mesh_model *model, 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); + BT_DBG("Unexpected Health Status 0x%04x", ctx->recv_op); } else { switch (node->opcode) { case OP_HEALTH_FAULT_GET: @@ -160,7 +160,7 @@ static void health_fault_status(struct bt_mesh_model *model, status.cid = net_buf_simple_pull_le16(buf); status.fault_array = bt_mesh_alloc_buf(buf->len); if (!status.fault_array) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } @@ -428,7 +428,7 @@ void bt_mesh_health_cli_timeout_set(s32_t timeout) int bt_mesh_health_cli_set(struct bt_mesh_model *model) { if (!model || !model->user_data) { - BT_ERR("%s, No Health Client context for given model", __func__); + BT_ERR("No Health Client context for given model"); return -EINVAL; } @@ -451,14 +451,14 @@ int bt_mesh_health_cli_init(struct bt_mesh_model *model, bool primary) client = (bt_mesh_health_client_t *)model->user_data; if (!client) { - BT_ERR("%s, No Health Client context provided", __func__); + BT_ERR("No Health Client context provided"); return -EINVAL; } if (!client->internal_data) { internal = bt_mesh_calloc(sizeof(health_internal_data_t)); if (!internal) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return -ENOMEM; } @@ -493,7 +493,7 @@ int bt_mesh_health_cli_deinit(struct bt_mesh_model *model, bool primary) client = (bt_mesh_health_client_t *)model->user_data; if (!client) { - BT_ERR("%s, No Health Client context provided", __func__); + BT_ERR("No Health Client context provided"); return -EINVAL; } diff --git a/components/bt/esp_ble_mesh/mesh_core/health_srv.c b/components/bt/esp_ble_mesh/mesh_core/health_srv.c index ccf18b368..5ca88a9d9 100644 --- a/components/bt/esp_ble_mesh/mesh_core/health_srv.c +++ b/components/bt/esp_ble_mesh/mesh_core/health_srv.c @@ -96,7 +96,7 @@ static int health_send_fault_status(struct bt_mesh_model *model, msg = bt_mesh_alloc_buf(4 + ARRAY_SIZE(srv->test.reg_faults) + 4); if (!msg) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return -ENOMEM; } @@ -113,7 +113,7 @@ static int health_send_fault_status(struct bt_mesh_model *model, err = bt_mesh_model_send(model, ctx, msg, NULL, NULL); if (err) { - BT_ERR("%s, Failed to send Health Fault Status response", __func__); + BT_ERR("Failed to send Health Fault Status response"); } bt_mesh_free_buf(msg); @@ -128,13 +128,13 @@ static void health_fault_get(struct bt_mesh_model *model, u16_t company_id = 0U; if (!srv) { - BT_ERR("%s, No Health Server context provided", __func__); + BT_ERR("No Health Server context provided"); return; } company_id = net_buf_simple_pull_le16(buf); if (company_id != srv->test.company_id) { - BT_ERR("%s, Unknown Company ID 0x%04x", __func__, company_id); + BT_ERR("Unknown Company ID 0x%04x", company_id); return; } @@ -151,13 +151,13 @@ static void health_fault_clear(struct bt_mesh_model *model, u16_t company_id = 0U; if (!srv) { - BT_ERR("%s, No Health Server context provided", __func__); + BT_ERR("No Health Server context provided"); return; } company_id = net_buf_simple_pull_le16(buf); if (company_id != srv->test.company_id) { - BT_ERR("%s, Unknown Company ID 0x%04x", __func__, company_id); + BT_ERR("Unknown Company ID 0x%04x", company_id); return; } @@ -185,19 +185,19 @@ static void health_fault_test(struct bt_mesh_model *model, BT_DBG("%s", __func__); if (!srv) { - BT_ERR("%s, No Health Server context provided", __func__); + BT_ERR("No Health Server context provided"); return; } test_id = net_buf_simple_pull_u8(buf); if (health_is_test_id_exist(model, test_id) == false) { - BT_ERR("%s, Unknown Test ID 0x%02x", __func__, test_id); + BT_ERR("Unknown Test ID 0x%02x", test_id); return; } company_id = net_buf_simple_pull_le16(buf); if (company_id != srv->test.company_id) { - BT_ERR("%s, Unknown Company ID 0x%04x", __func__, company_id); + BT_ERR("Unknown Company ID 0x%04x", company_id); return; } @@ -222,7 +222,7 @@ static void send_attention_status(struct bt_mesh_model *model, u8_t time = 0U; if (!srv) { - BT_ERR("%s, No Health Server context provided", __func__); + BT_ERR("No Health Server context provided"); return; } @@ -233,7 +233,7 @@ static void send_attention_status(struct bt_mesh_model *model, net_buf_simple_add_u8(&msg, time); if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Health Attention Status", __func__); + BT_ERR("Unable to send Health Attention Status"); } } @@ -281,7 +281,7 @@ static void send_health_period_status(struct bt_mesh_model *model, net_buf_simple_add_u8(&msg, model->pub->period_div); if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) { - BT_ERR("%s, Unable to send Health Period Status", __func__); + BT_ERR("Unable to send Health Period Status"); } } @@ -302,7 +302,7 @@ static void health_set_period(struct bt_mesh_model *model, period = net_buf_simple_pull_u8(buf); if (period > 15) { - BT_WARN("%s, Prohibited period value %u", __func__, period); + BT_WARN("Prohibited period value %u", period); return; } @@ -345,12 +345,12 @@ static size_t health_get_current(struct bt_mesh_model *model, struct bt_mesh_health_srv *srv = model->user_data; if (!srv) { - BT_ERR("%s, No Health Server context provided", __func__); + BT_ERR("No Health Server context provided"); return 0; } if (msg->size < 4) { - BT_ERR("%s, Too small health publication msg size %d", __func__, msg->size); + BT_ERR("Too small health publication msg size %d", msg->size); return 0; } @@ -370,7 +370,7 @@ static int health_pub_update(struct bt_mesh_model *model) BT_DBG("%s", __func__); if (!pub || !pub->msg) { - BT_ERR("%s, Invalid health publication context", __func__); + BT_ERR("Invalid health publication context"); return -EINVAL; } @@ -390,12 +390,12 @@ int bt_mesh_fault_update(struct bt_mesh_elem *elem) model = bt_mesh_model_find(elem, BLE_MESH_MODEL_ID_HEALTH_SRV); if (!model) { - BT_ERR("%s, Health Server does not exist", __func__); + BT_ERR("Health Server not exists"); return -EINVAL; } if (!model->pub) { - BT_ERR("%s, Health Server has no publication support", __func__); + BT_ERR("Health Server has no publication support"); return -EINVAL; } @@ -419,7 +419,7 @@ static void attention_off(struct k_work *work) BT_DBG("%s", __func__); if (!srv) { - BT_ERR("%s, No Health Server context provided", __func__); + BT_ERR("No Health Server context provided"); return; } @@ -443,17 +443,17 @@ int bt_mesh_health_srv_init(struct bt_mesh_model *model, bool primary) return 0; } - BT_ERR("%s, No Health Server context provided", __func__); + BT_ERR("No Health Server context provided"); return -EINVAL; } if (srv->test.id_count == 0 || !srv->test.test_ids) { - BT_ERR("%s, No Health Test ID provided", __func__); + BT_ERR("No Health Test ID provided"); return -EINVAL; } if (!model->pub) { - BT_ERR("%s, Health Server has no publication support", __func__); + BT_ERR("Health Server has no publication support"); return -EINVAL; } @@ -484,17 +484,17 @@ int bt_mesh_health_srv_deinit(struct bt_mesh_model *model, bool primary) return 0; } - BT_ERR("%s, No Health Server context provided", __func__); + BT_ERR("No Health Server context provided"); return -EINVAL; } if (srv->test.id_count == 0 || !srv->test.test_ids) { - BT_ERR("%s, No Health Test ID provided", __func__); + BT_ERR("No Health Test ID provided"); return -EINVAL; } if (!model->pub) { - BT_ERR("%s, Health Server has no publication support", __func__); + BT_ERR("Health Server has no publication support"); return -EINVAL; } @@ -517,7 +517,7 @@ void bt_mesh_attention(struct bt_mesh_model *model, u8_t time) if (!model) { srv = health_srv; if (!srv) { - BT_WARN("%s, No Health Server context provided", __func__); + BT_WARN("No Health Server context provided"); return; } @@ -525,7 +525,7 @@ void bt_mesh_attention(struct bt_mesh_model *model, u8_t time) } else { srv = model->user_data; if (!srv) { - BT_WARN("%s, No Health Server context provided", __func__); + BT_WARN("No Health Server context provided"); return; } } diff --git a/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h b/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h index ea4ba202b..3a3e8ca67 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/mesh_bearer_adapt.h @@ -627,7 +627,7 @@ struct bt_mesh_gatt_attr { .uuid = BLE_MESH_UUID_GATT_CHRC, \ .perm = BLE_MESH_GATT_PERM_READ, \ .read = bt_mesh_gatts_attr_read_chrc, \ - .user_data = (&(struct bt_mesh_gatt_char) { .uuid = _uuid, \ + .user_data = (&(struct bt_mesh_gatt_char) { .uuid = _uuid, \ .properties = _props, }), \ } @@ -709,10 +709,11 @@ int bt_mesh_gatts_service_deregister(struct bt_mesh_gatt_service *svc); int bt_mesh_gatts_service_unregister(struct bt_mesh_gatt_service *svc); ssize_t bt_mesh_gatts_attr_read_included(struct bt_mesh_conn *conn, - const struct bt_mesh_gatt_attr *attr, - void *buf, u16_t len, u16_t offset); + const struct bt_mesh_gatt_attr *attr, + void *buf, u16_t len, u16_t offset); -ssize_t bt_mesh_gatts_attr_read(struct bt_mesh_conn *conn, const struct bt_mesh_gatt_attr *attr, +ssize_t bt_mesh_gatts_attr_read(struct bt_mesh_conn *conn, + const struct bt_mesh_gatt_attr *attr, void *buf, u16_t buf_len, u16_t offset, const void *value, u16_t value_len); @@ -721,10 +722,11 @@ ssize_t bt_mesh_gatts_attr_read_service(struct bt_mesh_conn *conn, void *buf, u16_t len, u16_t offset); ssize_t bt_mesh_gatts_attr_read_chrc(struct bt_mesh_conn *conn, - const struct bt_mesh_gatt_attr *attr, void *buf, - u16_t len, u16_t offset); + const struct bt_mesh_gatt_attr *attr, + void *buf, u16_t len, u16_t offset); -int bt_mesh_gatts_notify(struct bt_mesh_conn *conn, const struct bt_mesh_gatt_attr *attr, +int bt_mesh_gatts_notify(struct bt_mesh_conn *conn, + const struct bt_mesh_gatt_attr *attr, const void *data, u16_t len); u16_t bt_mesh_gatt_get_mtu(struct bt_mesh_conn *conn); @@ -750,7 +752,8 @@ void bt_mesh_gattc_exchange_mtu(u8_t index); u16_t bt_mesh_gattc_get_mtu_info(struct bt_mesh_conn *conn); -int bt_mesh_gattc_write_no_rsp(struct bt_mesh_conn *conn, const struct bt_mesh_gatt_attr *attr, +int bt_mesh_gattc_write_no_rsp(struct bt_mesh_conn *conn, + const struct bt_mesh_gatt_attr *attr, const void *data, u16_t len); void bt_mesh_gattc_disconnect(struct bt_mesh_conn *conn); diff --git a/components/bt/esp_ble_mesh/mesh_core/local_operation.c b/components/bt/esp_ble_mesh/mesh_core/local_operation.c index 9e2ab3f5e..e3c2c5051 100644 --- a/components/bt/esp_ble_mesh/mesh_core/local_operation.c +++ b/components/bt/esp_ble_mesh/mesh_core/local_operation.c @@ -23,13 +23,13 @@ static struct bt_mesh_model *find_model(u16_t elem_addr, u16_t cid, u16_t mod_id struct bt_mesh_elem *elem = NULL; if (!BLE_MESH_ADDR_IS_UNICAST(elem_addr)) { - BT_ERR("%s, Not a unicast address 0x%04x", __func__, elem_addr); + BT_ERR("Invalid unicast address 0x%04x", elem_addr); return NULL; } elem = bt_mesh_elem_find(elem_addr); if (elem == NULL) { - BT_ERR("%s, No element found, addr 0x%04x", __func__, elem_addr); + BT_ERR("No element found, addr 0x%04x", elem_addr); return NULL; } diff --git a/components/bt/esp_ble_mesh/mesh_core/lpn.c b/components/bt/esp_ble_mesh/mesh_core/lpn.c index 6aa5136e8..f398e7f7a 100644 --- a/components/bt/esp_ble_mesh/mesh_core/lpn.c +++ b/components/bt/esp_ble_mesh/mesh_core/lpn.c @@ -165,7 +165,7 @@ static void friend_clear_sent(int err, void *user_data) lpn->req_attempts++; if (err) { - BT_ERR("%s, Sending Friend Request failed (err %d)", __func__, err); + BT_ERR("Sending Friend Clear failed (err %d)", err); lpn_set_state(BLE_MESH_LPN_ENABLED); clear_friendship(false, lpn->disable); return; @@ -277,7 +277,7 @@ static void friend_req_sent(u16_t duration, int err, void *user_data) struct bt_mesh_lpn *lpn = &bt_mesh.lpn; if (err) { - BT_ERR("%s, Sending Friend Request failed (err %d)", __func__, err); + BT_ERR("Sending Friend Request failed (err %d)", err); if (IS_ENABLED(CONFIG_BLE_MESH_LPN_ESTABLISHMENT)) { bt_mesh_scan_enable(); @@ -339,7 +339,7 @@ static void req_sent(u16_t duration, int err, void *user_data) lpn->sent_req, duration, err, state2str(lpn->state)); if (err) { - BT_ERR("%s, Sending request failed (err %d)", __func__, err); + BT_ERR("Sending request failed (err %d)", err); lpn->sent_req = 0U; group_zero(lpn->pending); return; @@ -699,7 +699,7 @@ static bool sub_update(u8_t op) } if (added_count + g >= lpn->queue_size) { - BT_WARN("%s, Friend Queue Size exceeded", __func__); + BT_WARN("Friend Queue Size exceeded"); break; } diff --git a/components/bt/esp_ble_mesh/mesh_core/main.c b/components/bt/esp_ble_mesh/mesh_core/main.c index 2a2b136b5..119b17321 100644 --- a/components/bt/esp_ble_mesh/mesh_core/main.c +++ b/components/bt/esp_ble_mesh/mesh_core/main.c @@ -271,7 +271,7 @@ int bt_mesh_suspend(void) err = bt_mesh_scan_disable(); if (err) { bt_mesh_atomic_clear_bit(bt_mesh.flags, BLE_MESH_SUSPENDED); - BT_WARN("%s, Disabling scanning failed (err %d)", __func__, err); + BT_WARN("Disabling scanning failed (err %d)", err); return err; } @@ -312,7 +312,7 @@ int bt_mesh_resume(void) err = bt_mesh_scan_enable(); if (err) { - BT_WARN("%s, Re-enabling scanning failed (err %d)", __func__, err); + BT_WARN("Re-enabling scanning failed (err %d)", err); bt_mesh_atomic_set_bit(bt_mesh.flags, BLE_MESH_SUSPENDED); return err; } @@ -565,13 +565,13 @@ int bt_mesh_provisioner_enable(bt_mesh_prov_bearer_t bearers) err = bt_mesh_provisioner_set_prov_info(); if (err) { - BT_ERR("%s, Failed to set provisioning info", __func__); + BT_ERR("Failed to set provisioning info"); return err; } err = bt_mesh_provisioner_net_create(); if (err) { - BT_ERR("%s, Failed to create network", __func__); + BT_ERR("Failed to create network"); return err; } diff --git a/components/bt/esp_ble_mesh/mesh_core/net.c b/components/bt/esp_ble_mesh/mesh_core/net.c index d9c109ccd..64924f612 100644 --- a/components/bt/esp_ble_mesh/mesh_core/net.c +++ b/components/bt/esp_ble_mesh/mesh_core/net.c @@ -171,7 +171,7 @@ int bt_mesh_net_keys_create(struct bt_mesh_subnet_keys *keys, err = bt_mesh_k2(key, p, sizeof(p), &nid, keys->enc, keys->privacy); if (err) { - BT_ERR("%s, Unable to generate NID, EncKey & PrivacyKey", __func__); + BT_ERR("Unable to generate NID, EncKey & PrivacyKey"); return err; } @@ -184,7 +184,7 @@ int bt_mesh_net_keys_create(struct bt_mesh_subnet_keys *keys, err = bt_mesh_k3(key, keys->net_id); if (err) { - BT_ERR("%s, Unable to generate Net ID", __func__); + BT_ERR("Unable to generate Net ID"); return err; } @@ -193,7 +193,7 @@ int bt_mesh_net_keys_create(struct bt_mesh_subnet_keys *keys, #if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER) err = bt_mesh_identity_key(key, keys->identity); if (err) { - BT_ERR("%s, Unable to generate IdentityKey", __func__); + BT_ERR("Unable to generate IdentityKey"); return err; } @@ -202,7 +202,7 @@ int bt_mesh_net_keys_create(struct bt_mesh_subnet_keys *keys, err = bt_mesh_beacon_key(key, keys->beacon); if (err) { - BT_ERR("%s, Unable to generate beacon key", __func__); + BT_ERR("Unable to generate beacon key"); return err; } @@ -245,7 +245,7 @@ int friend_cred_set(struct friend_cred *cred, u8_t idx, const u8_t net_key[16]) err = bt_mesh_k2(net_key, p, sizeof(p), &cred->cred[idx].nid, cred->cred[idx].enc, cred->cred[idx].privacy); if (err) { - BT_ERR("%s, Unable to generate NID, EncKey & PrivacyKey", __func__); + BT_ERR("Unable to generate NID, EncKey & PrivacyKey"); return err; } @@ -597,7 +597,7 @@ void bt_mesh_iv_update_test(bool enable) bool bt_mesh_iv_update(void) { if (!bt_mesh_is_provisioned()) { - BT_ERR("%s, Not yet provisioned", __func__); + BT_ERR("Not yet provisioned"); return false; } @@ -778,13 +778,13 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf, err = bt_mesh_net_obfuscate(buf->data, BLE_MESH_NET_IVI_TX, priv); if (err) { - BT_ERR("%s, De-obfuscate failed (err %d)", __func__, err); + BT_ERR("De-obfuscate failed (err %d)", err); return err; } err = bt_mesh_net_decrypt(enc, &buf->b, BLE_MESH_NET_IVI_TX, false); if (err) { - BT_ERR("%s, Decrypt failed (err %d)", __func__, err); + BT_ERR("Decrypt failed (err %d)", err); return err; } @@ -797,13 +797,13 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf, 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); + BT_ERR("Encrypt failed (err %d)", err); return err; } err = bt_mesh_net_obfuscate(buf->data, BLE_MESH_NET_IVI_TX, priv); if (err) { - BT_ERR("%s, Obfuscate failed (err %d)", __func__, err); + BT_ERR("Obfuscate failed (err %d)", err); return err; } @@ -838,10 +838,10 @@ int bt_mesh_net_encode(struct bt_mesh_net_tx *tx, struct net_buf_simple *buf, int err = 0; if (ctl && net_buf_simple_tailroom(buf) < BLE_MESH_MIC_LONG) { - BT_ERR("%s, Insufficient MIC space for CTL PDU", __func__); + BT_ERR("Insufficient MIC space for CTL PDU"); return -EINVAL; } else if (net_buf_simple_tailroom(buf) < BLE_MESH_MIC_SHORT) { - BT_ERR("%s, Insufficient MIC space for PDU", __func__); + BT_ERR("Insufficient MIC space for PDU"); return -EINVAL; } @@ -989,8 +989,8 @@ static bool auth_match(struct bt_mesh_subnet_keys *keys, } struct bt_mesh_subnet *bt_mesh_subnet_find(const u8_t net_id[8], u8_t flags, - u32_t iv_index, const u8_t auth[8], - bool *new_key) + u32_t iv_index, const u8_t auth[8], + bool *new_key) { size_t subnet_size = 0U; int i; @@ -1115,7 +1115,7 @@ static bool net_find_and_decrypt(const u8_t *data, size_t data_len, for (i = 0; i < array_size; i++) { sub = bt_mesh_rx_netkey_get(i); if (!sub) { - BT_DBG("%s, NULL subnet", __func__); + BT_DBG("Subnet not found"); continue; } @@ -1238,7 +1238,7 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf, #endif if (!buf) { - BT_ERR("%s, Out of relay buffers", __func__); + BT_ERR("Out of relay buffers"); return; } @@ -1268,12 +1268,12 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf, * layer nonce includes the IVI. */ if (bt_mesh_net_encrypt(enc, &buf->b, BLE_MESH_NET_IVI_RX(rx), false)) { - BT_ERR("%s, Re-encrypting failed", __func__); + BT_ERR("Re-encrypting failed"); goto done; } if (bt_mesh_net_obfuscate(buf->data, BLE_MESH_NET_IVI_RX(rx), priv)) { - BT_ERR("%s, Re-obfuscating failed", __func__); + BT_ERR("Re-obfuscating failed"); goto done; } @@ -1354,12 +1354,12 @@ int bt_mesh_net_decode(struct net_buf_simple *data, enum bt_mesh_net_if net_if, if (net_if != BLE_MESH_NET_IF_PROXY_CFG && rx->ctx.recv_dst == BLE_MESH_ADDR_UNASSIGNED) { - BT_ERR("%s, Destination address is unassigned; dropping packet", __func__); + BT_ERR("Destination address is unassigned; dropping packet"); return -EBADMSG; } if (BLE_MESH_ADDR_IS_RFU(rx->ctx.recv_dst)) { - BT_ERR("%s, Destination address is RFU; dropping packet", __func__); + BT_ERR("Destination address is RFU; dropping packet"); return -EBADMSG; } diff --git a/components/bt/esp_ble_mesh/mesh_core/net.h b/components/bt/esp_ble_mesh/mesh_core/net.h index 2349403b6..52b8abab9 100644 --- a/components/bt/esp_ble_mesh/mesh_core/net.h +++ b/components/bt/esp_ble_mesh/mesh_core/net.h @@ -349,8 +349,8 @@ void bt_mesh_net_sec_update(struct bt_mesh_subnet *sub); struct bt_mesh_subnet *bt_mesh_subnet_get(u16_t net_idx); struct bt_mesh_subnet *bt_mesh_subnet_find(const u8_t net_id[8], u8_t flags, - u32_t iv_index, const u8_t auth[8], - bool *new_key); + u32_t iv_index, const u8_t auth[8], + bool *new_key); int bt_mesh_net_encode(struct bt_mesh_net_tx *tx, struct net_buf_simple *buf, bool proxy); diff --git a/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c b/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c index 0990c3f95..2cdb0a6d1 100644 --- a/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c +++ b/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c @@ -163,7 +163,7 @@ static int ble_on_subscribe(uint16_t conn_handle, conn = &bt_mesh_gattc_info[i].conn; if (bt_mesh_gattc_info[i].ccc_handle != attr->handle) { - BT_WARN("%s, gattc ccc_handle is not matched", __func__); + BT_WARN("gattc ccc_handle not matched"); bt_mesh_gattc_disconnect(conn); return 0; } @@ -172,7 +172,7 @@ static int ble_on_subscribe(uint16_t conn_handle, if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->prov_write_descr != NULL) { len = bt_mesh_gattc_conn_cb->prov_write_descr(&bt_mesh_gattc_info[i].addr, &bt_mesh_gattc_info[i].conn); if (len < 0) { - BT_ERR("%s, prov_write_descr failed", __func__); + BT_ERR("prov_write_descr failed"); bt_mesh_gattc_disconnect(conn); return 0; } @@ -182,7 +182,7 @@ static int ble_on_subscribe(uint16_t conn_handle, if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->proxy_write_descr != NULL) { len = bt_mesh_gattc_conn_cb->proxy_write_descr(&bt_mesh_gattc_info[i].addr, &bt_mesh_gattc_info[i].conn); if (len < 0) { - BT_ERR("%s, proxy_write_descr failed", __func__); + BT_ERR("proxy_write_descr failed"); bt_mesh_gattc_disconnect(conn); return 0; } @@ -341,7 +341,7 @@ static int svc_disced(uint16_t conn_handle, const struct ble_gatt_error *error, } if (i == ARRAY_SIZE(bt_mesh_gattc_info)) { - BT_ERR("%s, Conn handle is not found", __func__); + BT_ERR("Conn handle 0x%04x not found", conn_handle); return 0; } conn = &bt_mesh_gattc_info[i].conn; @@ -388,7 +388,7 @@ static int disc_cb(struct ble_gap_event *event, void *arg) struct net_buf_simple *buf = bt_mesh_alloc_buf(desc->length_data); if (!buf) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return 0; } net_buf_simple_add_mem(buf, desc->data, desc->length_data); @@ -421,7 +421,7 @@ static int disc_cb(struct ble_gap_event *event, void *arg) if (!bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) { rc = ble_gap_disc(BLE_OWN_ADDR_PUBLIC, BLE_HS_FOREVER, &scan_param, disc_cb, NULL); if (rc != 0) { - BT_ERR("%s, Invalid scan status %d", __func__, rc); + BT_ERR("Invalid scan status %d", rc); break; } bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING); @@ -505,7 +505,7 @@ static int disc_cb(struct ble_gap_event *event, void *arg) } if (i == ARRAY_SIZE(bt_mesh_gattc_info)) { - BT_ERR("%s, Conn handle is not found", __func__); + BT_ERR("Conn handle 0x%04x not found", event->notify_rx.conn_handle); return 0; } @@ -520,7 +520,7 @@ static int disc_cb(struct ble_gap_event *event, void *arg) if (memcmp(bt_mesh_gattc_info[i].addr.val, conn_desc.peer_id_addr.val, BLE_MESH_ADDR_LEN) || (bt_mesh_gattc_info[i].data_out_handle != event->notify_rx.attr_handle) || (event->notify_rx.indication != 0)) { - BT_ERR("%s, Notification error", __func__); + BT_ERR("Notification error"); bt_mesh_gattc_disconnect(conn); return 0; } @@ -533,7 +533,7 @@ static int disc_cb(struct ble_gap_event *event, void *arg) len = bt_mesh_gattc_conn_cb->prov_notify(&bt_mesh_gattc_info[i].conn, notif_data, notif_len); if (len < 0) { - BT_ERR("%s, prov_notify failed", __func__); + BT_ERR("prov_notify failed"); bt_mesh_gattc_disconnect(conn); return 0; } @@ -543,7 +543,7 @@ static int disc_cb(struct ble_gap_event *event, void *arg) len = bt_mesh_gattc_conn_cb->proxy_notify(&bt_mesh_gattc_info[i].conn, notif_data, notif_len); if (len < 0) { - BT_ERR("%s, proxy_notify failed", __func__); + BT_ERR("proxy_notify failed"); bt_mesh_gattc_disconnect(conn); return 0; } @@ -1059,7 +1059,8 @@ static struct bt_mesh_gatt_attr *bt_mesh_gatts_attr_next(const struct bt_mesh_ga return next; } -ssize_t bt_mesh_gatts_attr_read(struct bt_mesh_conn *conn, const struct bt_mesh_gatt_attr *attr, +ssize_t bt_mesh_gatts_attr_read(struct bt_mesh_conn *conn, + const struct bt_mesh_gatt_attr *attr, void *buf, u16_t buf_len, u16_t offset, const void *value, u16_t value_len) { @@ -1085,8 +1086,8 @@ struct gatts_incl { } __packed; ssize_t bt_mesh_gatts_attr_read_included(struct bt_mesh_conn *conn, - const struct bt_mesh_gatt_attr *attr, - void *buf, u16_t len, u16_t offset) + const struct bt_mesh_gatt_attr *attr, + void *buf, u16_t len, u16_t offset) { struct bt_mesh_gatt_attr *incl = attr->user_data; struct bt_mesh_uuid *uuid = incl->user_data; @@ -1135,8 +1136,8 @@ struct gatts_chrc { } __packed; ssize_t bt_mesh_gatts_attr_read_chrc(struct bt_mesh_conn *conn, - const struct bt_mesh_gatt_attr *attr, void *buf, - u16_t len, u16_t offset) + const struct bt_mesh_gatt_attr *attr, + void *buf, u16_t len, u16_t offset) { struct bt_mesh_gatt_char *chrc = attr->user_data; const struct bt_mesh_gatt_attr *next = NULL; @@ -1153,7 +1154,7 @@ ssize_t bt_mesh_gatts_attr_read_chrc(struct bt_mesh_conn *conn, */ next = bt_mesh_gatts_attr_next(attr); if (!next) { - BT_WARN("%s, No value for characteristic at 0x%04x", __func__, attr->handle); + BT_WARN("No value for characteristic, handle 0x%04x", attr->handle); pdu.value_handle = 0x0000; } else { pdu.value_handle = sys_cpu_to_le16(next->handle); @@ -1183,7 +1184,7 @@ static int gatts_register(struct bt_mesh_gatt_service *svc) last = SYS_SLIST_PEEK_TAIL_CONTAINER(&bt_mesh_gatts_db, last, node); handle = last->attrs[last->attr_count - 1].handle; - BT_DBG("%s, handle = %d", __func__, handle); + BT_DBG("gatts register, handle %d", handle); populate: sys_slist_append(&bt_mesh_gatts_db, &svc->node); @@ -1236,11 +1237,12 @@ int bt_mesh_gatts_disconnect(struct bt_mesh_conn *conn, u8_t reason) int bt_mesh_gatts_service_unregister(struct bt_mesh_gatt_service *svc) { assert(svc != NULL); - BT_ERR("%s, Unsupported for NimBLE host", __func__); + BT_ERR("Unsupported for NimBLE host"); return 0; } -int bt_mesh_gatts_notify(struct bt_mesh_conn *conn, const struct bt_mesh_gatt_attr *attr, +int bt_mesh_gatts_notify(struct bt_mesh_conn *conn, + const struct bt_mesh_gatt_attr *attr, const void *data, u16_t len) { struct os_mbuf *om; @@ -1372,21 +1374,21 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, u16_t service_uuid) if (!addr || !memcmp(addr->val, zero, BLE_MESH_ADDR_LEN) || (addr->type > BLE_ADDR_RANDOM)) { - BT_ERR("%s, Invalid remote address", __func__); + BT_ERR("Invalid remote address"); return -EINVAL; } if (service_uuid != BLE_MESH_UUID_MESH_PROV_VAL && service_uuid != BLE_MESH_UUID_MESH_PROXY_VAL) { - BT_ERR("%s, Invalid service uuid 0x%04x", __func__, service_uuid); + BT_ERR("Invalid service uuid 0x%04x", service_uuid); return -EINVAL; } /* Check if already creating connection with the device */ for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) { if (!memcmp(bt_mesh_gattc_info[i].addr.val, addr->val, BLE_MESH_ADDR_LEN)) { - BT_WARN("%s, Already create connection with %s", - __func__, bt_hex(addr->val, BLE_MESH_ADDR_LEN)); + BT_WARN("Already create connection with %s", + bt_hex(addr->val, BLE_MESH_ADDR_LEN)); return -EALREADY; } } @@ -1404,7 +1406,7 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, u16_t service_uuid) } if (i == ARRAY_SIZE(bt_mesh_gattc_info)) { - BT_WARN("%s, gattc info is full", __func__); + BT_WARN("gattc info is full"); return -ENOMEM; } @@ -1416,7 +1418,7 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, u16_t service_uuid) bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING); } - BT_DBG("%s, create conn with %s", __func__, bt_hex(addr->val, BLE_MESH_ADDR_LEN)); + BT_DBG("Create conn with %s", bt_hex(addr->val, BLE_MESH_ADDR_LEN)); /* Min_interval: 250ms * Max_interval: 250ms @@ -1486,7 +1488,8 @@ u16_t bt_mesh_gattc_get_mtu_info(struct bt_mesh_conn *conn) return 0; } -int bt_mesh_gattc_write_no_rsp(struct bt_mesh_conn *conn, const struct bt_mesh_gatt_attr *attr, +int bt_mesh_gattc_write_no_rsp(struct bt_mesh_conn *conn, + const struct bt_mesh_gatt_attr *attr, const void *data, u16_t len) { u16_t conn_id; @@ -1499,7 +1502,7 @@ int bt_mesh_gattc_write_no_rsp(struct bt_mesh_conn *conn, const struct bt_mesh_g } if (i == ARRAY_SIZE(bt_mesh_gattc_info)) { - BT_ERR("%s, Conn is not found", __func__); + BT_ERR("Conn %p not found", conn); /** Here we return 0 for prov_send() return value check in provisioner.c */ return 0; @@ -1542,7 +1545,7 @@ void bt_mesh_gattc_disconnect(struct bt_mesh_conn *conn) } if (i == ARRAY_SIZE(bt_mesh_gattc_info)) { - BT_ERR("%s, Conn is not found", __func__); + BT_ERR("Conn %p not found", conn); return; } ble_gap_terminate(bt_mesh_gattc_info[i].conn.handle, BLE_ERR_REM_USER_CONN_TERM); @@ -1582,7 +1585,7 @@ static int proxy_char_access_cb(uint16_t conn_handle, uint16_t attr_handle, u8_t index = BLE_MESH_GATT_GET_CONN_ID(conn_handle); u16_t len = 0; - BT_DBG("%s, write: handle = %d, len = %d, data = %s", __func__, attr_handle, + BT_DBG("write, handle %d, len %d, data %s", attr_handle, ctxt->om->om_len, bt_hex(ctxt->om->om_data, ctxt->om->om_len)); @@ -1594,7 +1597,7 @@ static int proxy_char_access_cb(uint16_t conn_handle, uint16_t attr_handle, } } } else if (ctxt->op == BLE_GATT_ACCESS_OP_READ_CHR || ctxt->op == BLE_GATT_ACCESS_OP_READ_DSC) { - BT_ERR("%s, Unhandled read request for chr and dsc: opcode - %d", __func__, ctxt->op); + BT_ERR("Unhandled read request for chr and dsc: opcode - %d", ctxt->op); } return 0; } @@ -1765,7 +1768,7 @@ int bt_mesh_rand(void *buf, size_t len) memcpy(buf + i * sizeof(u32_t), &rand, sizeof(u32_t)); } - BT_DBG("%s, rand: %s", __func__, bt_hex(buf, len)); + BT_DBG("Rand %s", bt_hex(buf, len)); return 0; } @@ -1798,7 +1801,7 @@ const u8_t *bt_mesh_pub_key_get(void) int rc = ble_sm_alg_gen_key_pair(bt_mesh_public_key, pri_key); if (rc != 0) { - BT_ERR("%s, Failed to generate the key pair", __func__); + BT_ERR("Failed to generate the key pair"); return NULL; } memcpy(bt_mesh_private_key, pri_key, 32); @@ -1971,7 +1974,7 @@ int bt_mesh_encrypt_be(const u8_t key[16], const u8_t plaintext[16], #if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) int bt_mesh_update_exceptional_list(u8_t sub_code, u8_t type, void *info) { - BT_ERR("%s, Unsupported for NimBLE host", __func__); + BT_ERR("Unsupported for NimBLE host"); return 0; } #endif diff --git a/components/bt/esp_ble_mesh/mesh_core/prov.c b/components/bt/esp_ble_mesh/mesh_core/prov.c index cae80c1d1..268f83d60 100644 --- a/components/bt/esp_ble_mesh/mesh_core/prov.c +++ b/components/bt/esp_ble_mesh/mesh_core/prov.c @@ -323,7 +323,7 @@ static struct net_buf *adv_buf_create(void) buf = bt_mesh_adv_create(BLE_MESH_ADV_PROV, PROV_XMIT, BUF_TIMEOUT); if (!buf) { - BT_ERR("%s, Out of provisioning buffers", __func__); + BT_ERR("Out of provisioning buffers"); return NULL; } @@ -447,7 +447,7 @@ static int prov_send_adv(struct net_buf_simple *msg) u8_t xact_id = 0U; s32_t timeout = PROTOCOL_TIMEOUT; - BT_DBG("%s, len %u: %s", __func__, msg->len, bt_hex(msg->data, msg->len)); + BT_DBG("len %u: %s", msg->len, bt_hex(msg->data, msg->len)); prov_clear_tx(); @@ -476,7 +476,7 @@ static int prov_send_adv(struct net_buf_simple *msg) buf = start; for (seg_id = 1U; msg->len > 0; seg_id++) { if (seg_id >= ARRAY_SIZE(link.tx.buf)) { - BT_ERR("%s, Too big message", __func__); + BT_ERR("Too big message (seg_id %d)", seg_id); free_segments(); return -E2BIG; } @@ -532,7 +532,7 @@ static int prov_send_gatt(struct net_buf_simple *msg) */ err = bt_mesh_proxy_server_send(link.conn, BLE_MESH_PROXY_PROV, msg); if (err) { - BT_ERR("%s, Failed to send provisioning PDU", __func__); + BT_ERR("Failed to send provisioning PDU"); return err; } @@ -617,7 +617,7 @@ static void prov_invite(const u8_t *data) memcpy(&link.conf_inputs[1], &buf.data[1], 11); if (prov_send(&buf)) { - BT_ERR("%s, Failed to send capabilities", __func__); + BT_ERR("Failed to send capabilities"); return; } @@ -795,13 +795,13 @@ static void prov_start(const u8_t *data) BT_INFO("Auth Size: 0x%02x", data[4]); if (data[0] != PROV_ALG_P256) { - BT_ERR("%s, Unknown algorithm 0x%02x", __func__, data[0]); + BT_ERR("Unknown algorithm 0x%02x", data[0]); prov_send_fail_msg(PROV_ERR_NVAL_FMT); return; } if (data[1] != prov->oob_pub_key) { - BT_ERR("%s, Invalid public key type: 0x%02x", __func__, data[1]); + BT_ERR("Invalid public key type: 0x%02x", data[1]); prov_send_fail_msg(PROV_ERR_NVAL_FMT); return; } @@ -820,9 +820,9 @@ static void prov_start(const u8_t *data) } if (prov_auth(data[2], data[3], data[4]) < 0) { - BT_ERR("%s, Invalid authentication method: 0x%02x; " + BT_ERR("Invalid authentication method: 0x%02x; " "action: 0x%02x; size: 0x%02x", - __func__, data[2], data[3], data[4]); + data[2], data[3], data[4]); prov_send_fail_msg(PROV_ERR_NVAL_FMT); } } @@ -836,7 +836,7 @@ static void send_confirm(void) BT_DBG("ConfInputs[128] %s", bt_hex(&link.conf_inputs[128], 17)); if (bt_mesh_prov_conf_salt(link.conf_inputs, link.conf_salt)) { - BT_ERR("%s, Unable to generate confirmation salt", __func__); + BT_ERR("Unable to generate confirmation salt"); prov_send_fail_msg(PROV_ERR_UNEXP_ERR); return; } @@ -844,7 +844,7 @@ static void send_confirm(void) BT_DBG("ConfirmationSalt: %s", bt_hex(link.conf_salt, 16)); if (bt_mesh_prov_conf_key(link.dhkey, link.conf_salt, link.conf_key)) { - BT_ERR("%s, Unable to generate confirmation key", __func__); + BT_ERR("Unable to generate confirmation key"); prov_send_fail_msg(PROV_ERR_UNEXP_ERR); return; } @@ -852,7 +852,7 @@ static void send_confirm(void) BT_DBG("ConfirmationKey: %s", bt_hex(link.conf_key, 16)); if (bt_mesh_rand(link.rand, 16)) { - BT_ERR("%s, Unable to generate random number", __func__); + BT_ERR("Unable to generate random number"); prov_send_fail_msg(PROV_ERR_UNEXP_ERR); return; } @@ -863,13 +863,13 @@ 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__); + BT_ERR("Unable to generate confirmation value"); prov_send_fail_msg(PROV_ERR_UNEXP_ERR); return; } if (prov_send(&cfm)) { - BT_ERR("%s, Unable to send Provisioning Confirm", __func__); + BT_ERR("Unable to send Provisioning Confirm"); return; } @@ -937,7 +937,7 @@ static void prov_dh_key_cb(const u8_t key[32], const u8_t idx) BT_DBG("%p", key); if (!key) { - BT_ERR("%s, DHKey generation failed", __func__); + BT_ERR("DHKey generation failed"); prov_send_fail_msg(PROV_ERR_UNEXP_ERR); return; } @@ -972,14 +972,14 @@ static void send_pub_key(void) 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__); + BT_ERR("Unable to generate DHKey"); 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__); + BT_ERR("No public key available"); prov_send_fail_msg(PROV_ERR_UNEXP_ERR); return; } @@ -1014,7 +1014,7 @@ static int bt_mesh_calc_dh_key(void) 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__); + BT_ERR("Unable to generate DHKey"); prov_send_fail_msg(PROV_ERR_UNEXP_ERR); return -EIO; } @@ -1059,7 +1059,7 @@ static void prov_pub_key(const u8_t *data) * (3) X = 0, Y = 0 */ if (!bt_mesh_check_public_key(data)) { - BT_ERR("%s, Invalid public key", __func__); + BT_ERR("Invalid public key"); prov_send_fail_msg(PROV_ERR_UNEXP_PDU); return; } @@ -1116,13 +1116,13 @@ static void prov_random(const u8_t *data) BT_DBG("Remote Random: %s", bt_hex(data, 16)); if (bt_mesh_prov_conf(link.conf_key, data, link.auth, conf_verify)) { - BT_ERR("%s, Unable to calculate confirmation verification", __func__); + BT_ERR("Unable to calculate confirmation verification"); prov_send_fail_msg(PROV_ERR_UNEXP_ERR); return; } if (memcmp(conf_verify, link.conf, 16)) { - BT_ERR("%s, Invalid confirmation value", __func__); + BT_ERR("Invalid confirmation value"); BT_DBG("Received: %s", bt_hex(link.conf, 16)); BT_DBG("Calculated: %s", bt_hex(conf_verify, 16)); prov_send_fail_msg(PROV_ERR_CFM_FAILED); @@ -1133,13 +1133,13 @@ static void prov_random(const u8_t *data) net_buf_simple_add_mem(&rnd, link.rand, 16); if (prov_send(&rnd)) { - BT_ERR("%s, Failed to send Provisioning Random", __func__); + BT_ERR("Failed to send Provisioning Random"); return; } if (bt_mesh_prov_salt(link.conf_salt, data, link.rand, link.prov_salt)) { - BT_ERR("%s, Failed to generate provisioning salt", __func__); + BT_ERR("Failed to generate provisioning salt"); prov_send_fail_msg(PROV_ERR_UNEXP_ERR); return; } @@ -1176,7 +1176,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__); + BT_ERR("Unable to generate session key"); prov_send_fail_msg(PROV_ERR_UNEXP_ERR); return; } @@ -1185,7 +1185,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__); + BT_ERR("Unable to generate session nonce"); prov_send_fail_msg(PROV_ERR_UNEXP_ERR); return; } @@ -1194,14 +1194,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__); + BT_ERR("Unable to decrypt provisioning data"); 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__); + BT_ERR("Unable to generate device key"); prov_send_fail_msg(PROV_ERR_UNEXP_ERR); return; } @@ -1328,7 +1328,7 @@ static void link_open(struct prov_rx *rx, struct net_buf_simple *buf) BT_DBG("len %u", buf->len); if (buf->len < 16) { - BT_ERR("%s, Too short bearer open message (len %u)", __func__, buf->len); + BT_ERR("Too short bearer open message (len %u)", buf->len); return; } @@ -1403,7 +1403,7 @@ static void gen_prov_ctl(struct prov_rx *rx, struct net_buf_simple *buf) link_close(rx, buf); break; default: - BT_ERR("%s, Unknown bearer opcode: 0x%02x", __func__, BEARER_CTL(rx->gpc)); + BT_ERR("Unknown bearer opcode: 0x%02x", BEARER_CTL(rx->gpc)); return; } } @@ -1415,7 +1415,7 @@ static void prov_msg_recv(void) BT_DBG("type 0x%02x len %u", type, link.rx.buf->len); if (!bt_mesh_fcs_check(link.rx.buf, link.rx.fcs)) { - BT_ERR("%s, Incorrect FCS", __func__); + BT_ERR("Incorrect FCS"); return; } @@ -1436,14 +1436,14 @@ static void prov_msg_recv(void) } if (type >= ARRAY_SIZE(prov_handlers)) { - BT_ERR("%s, Unknown provisioning PDU type 0x%02x", __func__, type); + BT_ERR("Unknown provisioning PDU type 0x%02x", type); 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); + BT_ERR("Invalid length %u for type 0x%02x", + link.rx.buf->len, type); prov_send_fail_msg(PROV_ERR_NVAL_FMT); return; } @@ -1475,7 +1475,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); + BT_ERR("Invalid segment index %u", seg); prov_send_fail_msg(PROV_ERR_NVAL_FMT); return; } else if (seg == link.rx.last_seg) { @@ -1484,8 +1484,8 @@ static void gen_prov_cont(struct prov_rx *rx, struct net_buf_simple *buf) expect_len = (link.rx.buf->len - 20U - ((link.rx.last_seg - 1) * 23U)); if (expect_len != buf->len) { - BT_ERR("%s, Incorrect last seg len: %u != %u", - __func__, expect_len, buf->len); + BT_ERR("Incorrect last seg len: %u != %u", + expect_len, buf->len); prov_send_fail_msg(PROV_ERR_NVAL_FMT); return; } @@ -1538,20 +1538,20 @@ static void gen_prov_start(struct prov_rx *rx, struct net_buf_simple *buf) START_LAST_SEG(rx->gpc), link.rx.buf->len, link.rx.fcs); if (link.rx.buf->len < 1) { - BT_ERR("%s, Ignoring zero-length provisioning PDU", __func__); + BT_ERR("Ignoring zero-length provisioning PDU"); 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); + BT_ERR("Too large provisioning PDU (%u bytes)", + link.rx.buf->len); prov_send_fail_msg(PROV_ERR_NVAL_FMT); 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__); + BT_ERR("Too small total length for multi-segment PDU"); prov_send_fail_msg(PROV_ERR_NVAL_FMT); return; } @@ -1580,7 +1580,7 @@ static const struct { static void gen_prov_recv(struct prov_rx *rx, struct net_buf_simple *buf) { if (buf->len < gen_prov[GPCF(rx->gpc)].min_len) { - BT_ERR("%s, Too short GPC message type %u", __func__, GPCF(rx->gpc)); + BT_ERR("Too short GPC message type %u", GPCF(rx->gpc)); return; } @@ -1647,12 +1647,12 @@ int bt_mesh_pb_gatt_recv(struct bt_mesh_conn *conn, struct net_buf_simple *buf) } if (type >= ARRAY_SIZE(prov_handlers)) { - BT_ERR("%s, Unknown provisioning PDU type 0x%02x", __func__, type); + BT_ERR("Unknown provisioning PDU type 0x%02x", type); return -EINVAL; } if (prov_handlers[type].len != buf->len) { - BT_ERR("%s, Invalid length %u for type 0x%02x", __func__, buf->len, type); + BT_ERR("Invalid length %u for type 0x%02x", buf->len, type); return -EINVAL; } @@ -1689,7 +1689,7 @@ int bt_mesh_pb_gatt_close(struct bt_mesh_conn *conn) BT_DBG("conn %p", conn); if (link.conn != conn) { - BT_ERR("%s, Not connected", __func__); + BT_ERR("Not connected"); return -ENOTCONN; } @@ -1739,23 +1739,23 @@ int bt_mesh_prov_init(const struct bt_mesh_prov *prov_info) const u8_t *key = NULL; if (!prov_info) { - BT_ERR("%s, No provisioning context provided", __func__); + BT_ERR("No provisioning context provided"); return -EINVAL; } if (prov_info->static_val_len > BLE_MESH_PROV_STATIC_OOB_MAX_LEN || prov_info->output_size > BLE_MESH_PROV_OUTPUT_OOB_MAX_LEN || prov_info->input_size > BLE_MESH_PROV_INPUT_OOB_MAX_LEN) { - BT_ERR("%s, Invalid auth oob length", __func__); + BT_ERR("Invalid authentication oob length"); return -EINVAL; } - __ASSERT(prov_info->uuid, "%s, Device UUID is not initialized", __func__); + __ASSERT(prov_info->uuid, "Device UUID not initialized"); /* Changed by Espressif. Use micro-ecc to generate public key now. */ key = bt_mesh_pub_key_get(); if (!key) { - BT_ERR("%s, Failed to generate public key", __func__); + BT_ERR("Failed to generate public key"); return -EIO; } @@ -1779,7 +1779,7 @@ int bt_mesh_prov_init(const struct bt_mesh_prov *prov_info) int bt_mesh_prov_deinit(void) { if (prov == NULL) { - BT_ERR("%s, No provisioning context provided", __func__); + BT_ERR("No provisioning context provided"); return -EINVAL; } @@ -1806,7 +1806,8 @@ int bt_mesh_prov_deinit(void) return 0; } -void bt_mesh_prov_complete(u16_t net_idx, const u8_t net_key[16], u16_t addr, u8_t flags, u32_t iv_index) +void bt_mesh_prov_complete(u16_t net_idx, const u8_t net_key[16], + u16_t addr, u8_t flags, u32_t iv_index) { if (prov->complete) { prov->complete(net_idx, net_key, addr, flags, iv_index); diff --git a/components/bt/esp_ble_mesh/mesh_core/prov.h b/components/bt/esp_ble_mesh/mesh_core/prov.h index a1872bd84..04466b6ba 100644 --- a/components/bt/esp_ble_mesh/mesh_core/prov.h +++ b/components/bt/esp_ble_mesh/mesh_core/prov.h @@ -32,7 +32,8 @@ const struct bt_mesh_prov *bt_mesh_prov_get(void); int bt_mesh_prov_init(const struct bt_mesh_prov *prov); int bt_mesh_prov_deinit(void); -void bt_mesh_prov_complete(u16_t net_idx, const u8_t net_key[16], u16_t addr, u8_t flags, u32_t iv_index); +void bt_mesh_prov_complete(u16_t net_idx, const u8_t net_key[16], + u16_t addr, u8_t flags, u32_t iv_index); void bt_mesh_prov_reset(void); #ifdef __cplusplus diff --git a/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c b/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c index ceb534ce7..469094c5a 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c @@ -79,7 +79,7 @@ int bt_mesh_provisioner_net_create(void) prov = bt_mesh_provisioner_get_prov_info(); if (!prov) { - BT_ERR("%s, NULL provisioning context", __func__); + BT_ERR("No provisioning context provided"); return -EINVAL; } @@ -99,20 +99,20 @@ int bt_mesh_provisioner_net_create(void) /* Generate the primary netkey */ if (bt_mesh_rand(p_key, 16)) { - BT_ERR("%s, Failed to generate Primary NetKey", __func__); + BT_ERR("Failed to generate Primary NetKey"); return -EIO; } sub = bt_mesh_calloc(sizeof(struct bt_mesh_subnet)); if (!sub) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return -ENOMEM; } sub->kr_flag = BLE_MESH_KEY_REFRESH(prov->flags); if (sub->kr_flag) { if (bt_mesh_net_keys_create(&sub->keys[1], p_key)) { - BT_ERR("%s, Failed to generate net-related keys", __func__); + BT_ERR("Failed to generate net-related keys"); bt_mesh_free(sub); return -EIO; } @@ -120,7 +120,7 @@ int bt_mesh_provisioner_net_create(void) } else { /* Currently provisioner only use keys[0] */ if (bt_mesh_net_keys_create(&sub->keys[0], p_key)) { - BT_ERR("%s, Failed to create net-related keys", __func__); + BT_ERR("Failed to create net-related keys"); bt_mesh_free(sub); return -EIO; } @@ -157,7 +157,7 @@ int bt_mesh_provisioner_net_create(void) } done: - BT_INFO("NetKey Index 0x%03x, NID 0x%02x", sub->net_idx, sub->keys[0].nid); + BT_INFO("NetKeyIndex 0x%03x, NID 0x%02x", sub->net_idx, sub->keys[0].nid); BT_INFO("NetKey %s", bt_hex(sub->keys[0].net, 16)); return 0; @@ -216,13 +216,13 @@ bool bt_mesh_provisioner_check_is_addr_dup(u16_t addr, u8_t elem_num, bool comp_ if (comp_with_own) { comp = bt_mesh_comp_get(); if (!comp) { - BT_ERR("NULL composition data"); + BT_ERR("Invalid composition data"); return true; } primary_addr = bt_mesh_provisioner_get_primary_elem_addr(); if (!BLE_MESH_ADDR_IS_UNICAST(primary_addr)) { - BT_ERR("%s, Not a unicast address 0x%04x", __func__, primary_addr); + BT_ERR("Invalid unicast address 0x%04x", primary_addr); return true; } } @@ -283,7 +283,7 @@ static int provisioner_store_node(struct bt_mesh_node *node, bool store, u16_t * if (mesh_nodes[i] == NULL) { mesh_nodes[i] = bt_mesh_calloc(sizeof(struct bt_mesh_node)); if (!mesh_nodes[i]) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); bt_mesh_provisioner_unlock(); return -ENOMEM; } @@ -318,9 +318,11 @@ int bt_mesh_provisioner_restore_node_info(struct bt_mesh_node *node) return provisioner_store_node(node, false, NULL); } -int bt_mesh_provisioner_provision(const bt_mesh_addr_t *addr, const u8_t uuid[16], u16_t oob_info, - u16_t unicast_addr, u8_t element_num, u16_t net_idx, u8_t flags, - u32_t iv_index, const u8_t dev_key[16], u16_t *index) +int bt_mesh_provisioner_provision(const bt_mesh_addr_t *addr, const u8_t uuid[16], + u16_t oob_info, u16_t unicast_addr, + u8_t element_num, u16_t net_idx, + u8_t flags, u32_t iv_index, + const u8_t dev_key[16], u16_t *index) { struct bt_mesh_node node = {0}; @@ -331,10 +333,10 @@ int bt_mesh_provisioner_provision(const bt_mesh_addr_t *addr, const u8_t uuid[16 return -EINVAL; } - BT_INFO("unicast_addr 0x%04x, elem_num %d, net_idx 0x%04x", - unicast_addr, element_num, net_idx); - BT_INFO("dev_uuid %s", bt_hex(uuid, 16)); - BT_INFO("dev_key %s", bt_hex(dev_key, 16)); + BT_INFO("Unicast addr 0x%04x, element num %d, NetKeyIndex 0x%04x", + unicast_addr, element_num, net_idx); + BT_INFO("UUID %s", bt_hex(uuid, 16)); + BT_INFO("DevKey %s", bt_hex(dev_key, 16)); memcpy(node.addr, addr->val, BLE_MESH_ADDR_LEN); node.addr_type = addr->type; @@ -404,7 +406,7 @@ static struct bt_mesh_node *provisioner_find_node_with_uuid(const u8_t uuid[16], BT_DBG("%s", __func__); if (uuid == NULL) { - BT_ERR("%s, Invalid device uuid", __func__); + BT_ERR("Invalid device uuid"); return NULL; } @@ -441,7 +443,7 @@ int bt_mesh_provisioner_remove_node(const u8_t uuid[16]) node = provisioner_find_node_with_uuid(uuid, &index); if (!node) { - BT_WARN("%s, Node not exists, uuid %s", __func__, bt_hex(uuid, 16)); + BT_WARN("Node not found, uuid %s", bt_hex(uuid, 16)); return -ENODEV; } @@ -457,7 +459,7 @@ static struct bt_mesh_node *provisioner_find_node_with_addr(u16_t addr, u16_t *i BT_DBG("%s", __func__); if (!BLE_MESH_ADDR_IS_UNICAST(addr)) { - BT_ERR("%s, Not a unicast address 0x%04x", __func__, addr); + BT_ERR("Invalid unicast address 0x%04x", addr); return NULL; } @@ -485,7 +487,7 @@ int bt_mesh_provisioner_restore_node_name(u16_t addr, const char *name) node = provisioner_find_node_with_addr(addr, NULL); if (node == NULL) { - BT_ERR("%s, Node not exists, addr 0x%04x", __func__, addr); + BT_ERR("Node not found, addr 0x%04x", addr); return -ENODEV; } @@ -512,7 +514,7 @@ int bt_mesh_provisioner_delete_node_with_uuid(const u8_t uuid[16]) node = provisioner_find_node_with_uuid(uuid, &index); if (!node) { - BT_WARN("%s, Node not exists, uuid %s", __func__, bt_hex(uuid, 16)); + BT_WARN("Node not found, uuid %s", bt_hex(uuid, 16)); return -ENODEV; } @@ -527,7 +529,7 @@ int bt_mesh_provisioner_delete_node_with_node_addr(u16_t unicast_addr) node = provisioner_find_node_with_addr(unicast_addr, &index); if (!node) { - BT_WARN("%s, Node not exists, addr 0x%04x", __func__, unicast_addr); + BT_WARN("Node not found, addr 0x%04x", unicast_addr); return -ENODEV; } @@ -672,24 +674,24 @@ static int store_node_comp_data(u16_t addr, const u8_t *data, u16_t length, bool struct bt_mesh_node *node = NULL; if (!BLE_MESH_ADDR_IS_UNICAST(addr)) { - BT_ERR("%s, Not a unicast address 0x%04x", __func__, addr); + BT_ERR("Invalid unicast address 0x%04x", addr); return -EINVAL; } if (data == NULL || (length % 2) || length < COMP_DATA_PAGE_0_MIN_LEN) { - BT_ERR("%s, Invalid composition data", __func__); + BT_ERR("Invalid composition data"); return -EINVAL; } node = provisioner_find_node_with_addr(addr, NULL); if (node == NULL) { - BT_ERR("%s, Node not exists, addr 0x%04x", __func__, addr); + BT_ERR("Node not found, addr 0x%04x", addr); return -ENODEV; } node->comp_data = bt_mesh_calloc(length); if (node->comp_data == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return -ENOMEM; } @@ -791,7 +793,7 @@ const u8_t *bt_mesh_provisioner_dev_key_get(u16_t dst) BT_DBG("%s", __func__); if (!BLE_MESH_ADDR_IS_UNICAST(dst)) { - BT_ERR("%s, Not a unicast address 0x%04x", __func__, dst); + BT_ERR("Invalid unicast address 0x%04x", dst); return NULL; } @@ -947,7 +949,8 @@ static int provisioner_check_net_key_full(void) return -ENOMEM; } -int bt_mesh_provisioner_local_app_key_add(const u8_t app_key[16], u16_t net_idx, u16_t *app_idx) +int bt_mesh_provisioner_local_app_key_add(const u8_t app_key[16], + u16_t net_idx, u16_t *app_idx) { struct bt_mesh_app_keys *keys = NULL; struct bt_mesh_app_key *key = NULL; @@ -955,7 +958,7 @@ int bt_mesh_provisioner_local_app_key_add(const u8_t app_key[16], u16_t net_idx, int add = -1; if (bt_mesh.p_app_idx_next >= 0x1000) { - BT_ERR("No AppKey Index available"); + BT_ERR("No AppKeyIndex available"); return -EIO; } @@ -966,19 +969,19 @@ int bt_mesh_provisioner_local_app_key_add(const u8_t app_key[16], u16_t net_idx, /* Check if the same application key already exists */ if (provisioner_check_app_key(app_key, app_idx)) { - BT_WARN("AppKey exists, AppKey Index updated"); + BT_WARN("AppKey exists, AppKeyIndex updated"); return 0; } /* Check if the net_idx exists */ if (provisioner_check_net_idx(net_idx, false)) { - BT_ERR("%s, NetKey Index 0x%03x not exists", __func__, net_idx); + BT_ERR("Invalid NetKeyIndex 0x%04x", net_idx); return -ENODEV; } /* Check if the same app_idx already exists */ if (provisioner_check_app_idx(*app_idx, true)) { - BT_ERR("%s, AppKey Index 0x%03x exists", __func__, *app_idx); + BT_ERR("Invalid AppKeyIndex 0x%04x", *app_idx); return -EEXIST; } @@ -999,13 +1002,13 @@ int bt_mesh_provisioner_local_app_key_add(const u8_t app_key[16], u16_t net_idx, key = bt_mesh_calloc(sizeof(struct bt_mesh_app_key)); if (!key) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return -ENOMEM; } keys = &key->keys[0]; if (bt_mesh_app_id(p_key, &keys->id)) { - BT_ERR("%s, Failed to generate AID", __func__); + BT_ERR("Failed to generate AID"); bt_mesh_free(key); return -EIO; } @@ -1020,7 +1023,7 @@ int bt_mesh_provisioner_local_app_key_add(const u8_t app_key[16], u16_t net_idx, if (provisioner_check_app_idx(key->app_idx, true)) { key->app_idx = (++bt_mesh.p_app_idx_next); if (key->app_idx >= 0x1000) { - BT_ERR("No AppKey Index available"); + BT_ERR("No AppKeyIndex available"); bt_mesh_free(key); return -EIO; } @@ -1042,13 +1045,14 @@ int bt_mesh_provisioner_local_app_key_add(const u8_t app_key[16], u16_t net_idx, return 0; } -int bt_mesh_provisioner_local_app_key_update(const u8_t app_key[16], u16_t net_idx, u16_t app_idx) +int bt_mesh_provisioner_local_app_key_update(const u8_t app_key[16], + u16_t net_idx, u16_t app_idx) { struct bt_mesh_app_keys *keys = NULL; struct bt_mesh_app_key *key = NULL; if (app_key == NULL) { - BT_ERR("%s, Invalid AppKey", __func__); + BT_ERR("Invalid AppKey"); return -EINVAL; } @@ -1056,19 +1060,19 @@ int bt_mesh_provisioner_local_app_key_update(const u8_t app_key[16], u16_t net_i /* Check if the net_idx exists */ if (provisioner_check_net_idx(net_idx, false)) { - BT_ERR("%s, NetKey Index 0x%03x not exists", __func__, net_idx); + BT_ERR("Invalid NetKeyIndex 0x%04x", net_idx); return -ENODEV; } key = bt_mesh_provisioner_app_key_find(app_idx); if (key == NULL) { - BT_ERR("%s, AppKey Index 0x%03x not exists", __func__, app_idx); + BT_ERR("Invalid AppKeyIndex 0x%04x", app_idx); return -ENODEV; } keys = &key->keys[0]; if (bt_mesh_app_id(app_key, &keys->id)) { - BT_ERR("%s, Failed to generate AID", __func__); + BT_ERR("Failed to generate AID"); return -EIO; } @@ -1093,12 +1097,12 @@ const u8_t *bt_mesh_provisioner_local_app_key_get(u16_t net_idx, u16_t app_idx) BT_DBG("%s", __func__); if (provisioner_check_net_idx(net_idx, false)) { - BT_ERR("%s, NetKey Index 0x%03x not exists", __func__, net_idx); + BT_ERR("Invalid NetKeyIndex 0x%04x", net_idx); return NULL; } if (provisioner_check_app_idx(app_idx, false)) { - BT_ERR("%s, AppKey Index 0x%03x not exists", __func__, app_idx); + BT_ERR("Invalid AppKeyIndex 0x%04x", app_idx); return NULL; } @@ -1182,12 +1186,12 @@ int bt_mesh_provisioner_local_app_key_delete(u16_t net_idx, u16_t app_idx) BT_DBG("%s", __func__); if (provisioner_check_net_idx(net_idx, false)) { - BT_ERR("%s, NetKey Index 0x%03x not exists", __func__, net_idx); + BT_ERR("Invalid NetKeyIndex 0x%04x", net_idx); return -ENODEV; } if (provisioner_check_app_idx(app_idx, false)) { - BT_ERR("%s, AppKey Index 0x%03x not exists", __func__, app_idx); + BT_ERR("Invalid AppKeyIndex 0x%04x", app_idx); return -ENODEV; } @@ -1219,7 +1223,7 @@ int bt_mesh_provisioner_local_net_key_add(const u8_t net_key[16], u16_t *net_idx int add = -1; if (bt_mesh.p_net_idx_next >= 0x1000) { - BT_ERR("No NetKey Index available"); + BT_ERR("No NetKeyIndex available"); return -EIO; } @@ -1230,13 +1234,13 @@ int bt_mesh_provisioner_local_net_key_add(const u8_t net_key[16], u16_t *net_idx /* Check if the same network key already exists */ if (provisioner_check_net_key(net_key, net_idx)) { - BT_WARN("NetKey exists, NetKey Index updated"); + BT_WARN("NetKey exists, NetKeyIndex updated"); return 0; } /* Check if the same net_idx already exists */ if (provisioner_check_net_idx(*net_idx, true)) { - BT_ERR("%s, NetKey Index 0x%03x exists", __func__, *net_idx); + BT_ERR("Invalid NetKeyIndex 0x%04x", *net_idx); return -EEXIST; } @@ -1257,12 +1261,12 @@ int bt_mesh_provisioner_local_net_key_add(const u8_t net_key[16], u16_t *net_idx sub = bt_mesh_calloc(sizeof(struct bt_mesh_subnet)); if (!sub) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return -ENOMEM; } if (bt_mesh_net_keys_create(&sub->keys[0], p_key)) { - BT_ERR("%s, Failed to generate NID", __func__); + BT_ERR("Failed to generate NID"); bt_mesh_free(sub); return -EIO; } @@ -1275,7 +1279,7 @@ int bt_mesh_provisioner_local_net_key_add(const u8_t net_key[16], u16_t *net_idx if (provisioner_check_net_idx(sub->net_idx, true)) { sub->net_idx = (++bt_mesh.p_net_idx_next); if (sub->net_idx >= 0x1000) { - BT_ERR("No NetKey Index available"); + BT_ERR("No NetKeyIndex available"); bt_mesh_free(sub); return -EIO; } @@ -1305,7 +1309,7 @@ int bt_mesh_provisioner_local_net_key_update(const u8_t net_key[16], u16_t net_i int err = 0; if (net_key == NULL) { - BT_ERR("%s, Invalid NetKey", __func__); + BT_ERR("Invalid NetKey"); return -EINVAL; } @@ -1313,13 +1317,13 @@ int bt_mesh_provisioner_local_net_key_update(const u8_t net_key[16], u16_t net_i sub = bt_mesh_provisioner_subnet_get(net_idx); if (sub == NULL) { - BT_ERR("%s, NetKey Index 0x%03x not exists", __func__, net_idx); + BT_ERR("Invalid NetKeyIndex 0x%04x", net_idx); return -ENODEV; } err = bt_mesh_net_keys_create(&sub->keys[0], net_key); if (err) { - BT_ERR("%s, Failed to generate NID", __func__); + BT_ERR("Failed to generate NID"); return -EIO; } @@ -1332,7 +1336,7 @@ int bt_mesh_provisioner_local_net_key_update(const u8_t net_key[16], u16_t net_i err = bt_mesh_net_beacon_update(sub); if (err) { - BT_ERR("%s, Failed to update secure beacon", __func__); + BT_ERR("Failed to update secure beacon"); return -EIO; } @@ -1351,7 +1355,7 @@ const u8_t *bt_mesh_provisioner_local_net_key_get(u16_t net_idx) BT_DBG("%s", __func__); if (provisioner_check_net_idx(net_idx, false)) { - BT_ERR("%s, NetKey Index 0x%03x not exists", __func__, net_idx); + BT_ERR("Invalid NetKeyIndex 0x%04x", net_idx); return NULL; } @@ -1376,7 +1380,7 @@ int bt_mesh_provisioner_local_net_key_delete(u16_t net_idx) BT_DBG("%s", __func__); if (provisioner_check_net_idx(net_idx, false)) { - BT_ERR("%s, NetKey Index 0x%03x not exists", __func__, net_idx); + BT_ERR("Invalid NetKeyIndex 0x%04x", net_idx); return -ENODEV; } @@ -1406,7 +1410,7 @@ int bt_mesh_provisioner_local_net_key_delete(u16_t net_idx) } int bt_mesh_provisioner_bind_local_model_app_idx(u16_t elem_addr, u16_t mod_id, - u16_t cid, u16_t app_idx) + u16_t cid, u16_t app_idx) { struct bt_mesh_model *model = NULL; struct bt_mesh_elem *elem = NULL; @@ -1414,7 +1418,7 @@ int bt_mesh_provisioner_bind_local_model_app_idx(u16_t elem_addr, u16_t mod_id, elem = bt_mesh_elem_find(elem_addr); if (!elem) { - BT_ERR("%s, No element found, addr 0x%04x", __func__, elem_addr); + BT_ERR("No element found, addr 0x%04x", elem_addr); return -ENODEV; } @@ -1424,12 +1428,12 @@ int bt_mesh_provisioner_bind_local_model_app_idx(u16_t elem_addr, u16_t mod_id, model = bt_mesh_model_find_vnd(elem, cid, mod_id); } if (!model) { - BT_ERR("%s, No model is found", __func__); + BT_ERR("No model found, model id 0x%04x, cid 0x%04x", mod_id, cid); return -ENODEV; } if (provisioner_check_app_idx(app_idx, false)) { - BT_ERR("%s, AppKey Index 0x%03x not exists", __func__, app_idx); + BT_ERR("Invalid AppKeyIndex 0x%04x", app_idx); return -ENODEV; } @@ -1464,7 +1468,7 @@ int bt_mesh_print_local_composition_data(void) comp = bt_mesh_comp_get(); if (!comp) { - BT_ERR("%s, NULL composition data", __func__); + BT_ERR("Invalid composition data"); return -EINVAL; } @@ -1502,33 +1506,33 @@ int bt_mesh_provisioner_store_node_info(struct bt_mesh_node *node) } if (!BLE_MESH_ADDR_IS_UNICAST(node->unicast_addr)) { - BT_ERR("%s, Not a unicast address 0x%04x", __func__, node->unicast_addr); + BT_ERR("Invalid unicast address 0x%04x", node->unicast_addr); return -EINVAL; } if (node->element_num == 0) { - BT_ERR("%s, Invalid element count %d", __func__, node->element_num); + BT_ERR("Invalid element count %d", node->element_num); return -EINVAL; } if (bt_mesh_provisioner_check_is_addr_dup(node->unicast_addr, node->element_num, true)) { - BT_ERR("%s, Unicast address 0x%04x is duplicated", __func__, node->unicast_addr); + BT_ERR("Duplicate unicast address 0x%04x", node->unicast_addr); return -EINVAL; } if (node->unicast_addr + node->element_num - 1 > 0x7FFF) { - BT_ERR("%s, Not enough unicast address for the node", __func__); + BT_ERR("Not enough unicast address for the node"); return -EIO; } if (bt_mesh_provisioner_net_key_get(node->net_idx) == NULL) { - BT_ERR("%s, Invalid NetKey Index 0x%03x", __func__, node->net_idx); + BT_ERR("Invalid NetKeyIndex 0x%04x", node->net_idx); return -EINVAL; } err = provisioner_store_node(node, true, NULL); if (err) { - BT_ERR("%s, Failed to store node info", __func__); + BT_ERR("Failed to store node info"); return err; } diff --git a/components/bt/esp_ble_mesh/mesh_core/provisioner_main.h b/components/bt/esp_ble_mesh/mesh_core/provisioner_main.h index f742bfcd9..332d1a541 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_main.h +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_main.h @@ -59,9 +59,11 @@ u16_t bt_mesh_provisioner_get_node_count(void); int bt_mesh_provisioner_restore_node_info(struct bt_mesh_node *node); -int bt_mesh_provisioner_provision(const bt_mesh_addr_t *addr, const u8_t uuid[16], u16_t oob_info, - u16_t unicast_addr, u8_t element_num, u16_t net_idx, u8_t flags, - u32_t iv_index, const u8_t dev_key[16], u16_t *index); +int bt_mesh_provisioner_provision(const bt_mesh_addr_t *addr, const u8_t uuid[16], + u16_t oob_info, u16_t unicast_addr, + u8_t element_num, u16_t net_idx, + u8_t flags, u32_t iv_index, + const u8_t dev_key[16], u16_t *index); int bt_mesh_provisioner_remove_node(const u8_t uuid[16]); @@ -101,9 +103,11 @@ const u8_t *bt_mesh_provisioner_dev_key_get(u16_t dst); struct bt_mesh_app_key *bt_mesh_provisioner_app_key_find(u16_t app_idx); -int bt_mesh_provisioner_local_app_key_add(const u8_t app_key[16], u16_t net_idx, u16_t *app_idx); +int bt_mesh_provisioner_local_app_key_add(const u8_t app_key[16], + u16_t net_idx, u16_t *app_idx); -int bt_mesh_provisioner_local_app_key_update(const u8_t app_key[16], u16_t net_idx, u16_t app_idx); +int bt_mesh_provisioner_local_app_key_update(const u8_t app_key[16], + u16_t net_idx, u16_t app_idx); const u8_t *bt_mesh_provisioner_local_app_key_get(u16_t net_idx, u16_t app_idx); @@ -119,7 +123,7 @@ int bt_mesh_provisioner_local_net_key_delete(u16_t net_idx); /* Provisioner bind local client model with proper appkey index */ int bt_mesh_provisioner_bind_local_model_app_idx(u16_t elem_addr, u16_t mod_id, - u16_t cid, u16_t app_idx); + u16_t cid, u16_t app_idx); /* Provisioner print own element information */ int bt_mesh_print_local_composition_data(void); diff --git a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c index 0e9550b53..0439a279a 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c @@ -447,7 +447,7 @@ void bt_mesh_provisioner_clear_link_info(const u8_t addr[6]) return; } - BT_DBG("%s, Clear device %s info", __func__, bt_hex(addr, BLE_MESH_ADDR_LEN)); + BT_DBG("Clear device info, addr %s", bt_hex(addr, BLE_MESH_ADDR_LEN)); for (i = CONFIG_BLE_MESH_PBA_SAME_TIME; i < BLE_MESH_PROV_SAME_TIME; i++) { if (!memcmp(link[i].addr.val, addr, BLE_MESH_ADDR_LEN)) { @@ -464,7 +464,7 @@ void bt_mesh_provisioner_clear_link_info(const u8_t addr[6]) } } - BT_WARN("Device address %s is not found", bt_hex(addr, BLE_MESH_ADDR_LEN)); + BT_WARN("Device not found, addr %s", bt_hex(addr, BLE_MESH_ADDR_LEN)); return; } #endif @@ -520,7 +520,7 @@ static int provisioner_dev_find(const bt_mesh_addr_t *addr, const u8_t uuid[16], } if (!uuid_match && !addr_match) { - BT_DBG("%s, Device does not exist in queue", __func__); + BT_DBG("Device not exists in queue"); return -ENODEV; } @@ -568,7 +568,7 @@ static bool is_unprov_dev_being_provision(const u8_t uuid[16]) if (link[i].connecting || bt_mesh_atomic_test_bit(link[i].flags, LINK_ACTIVE)) { #endif if (!memcmp(link[i].uuid, uuid, 16)) { - BT_DBG("%s, Device is being provisioned", __func__); + BT_DBG("Device is being provisioning"); return true; } } @@ -598,7 +598,7 @@ static int provisioner_check_unprov_dev_info(const u8_t uuid[16], bt_mesh_prov_b /* Check if the device uuid matches configured value */ if (is_unprov_dev_uuid_match(uuid) == false) { - BT_DBG("%s, Device uuid mismatch", __func__); + BT_DBG("Device uuid mismatch"); return -EIO; } @@ -685,7 +685,7 @@ static int provisioner_start_prov_pb_adv(const u8_t uuid[16], const bt_mesh_addr } } - BT_ERR("%s, No PB-ADV link is available", __func__); + BT_ERR("No PB-ADV link available"); bt_mesh_pb_adv_unlock(); return -ENOMEM; @@ -753,7 +753,7 @@ static int provisioner_start_prov_pb_gatt(const u8_t uuid[16], const bt_mesh_add } } - BT_ERR("%s, No PB-GATT link is available", __func__); + BT_ERR("No PB-GATT link available"); bt_mesh_pb_gatt_unlock(); return -ENOMEM; @@ -785,31 +785,31 @@ int bt_mesh_provisioner_add_unprov_dev(struct bt_mesh_unprov_dev_add *add_dev, u if ((add_dev->bearer & BLE_MESH_PROV_ADV) && (add_dev->bearer & BLE_MESH_PROV_GATT) && (flags & START_PROV_NOW)) { - BT_ERR("%s, Can not start PB-ADV & PB-GATT simultaneously", __func__); + BT_ERR("Can not start PB-ADV & PB-GATT simultaneously"); return -EINVAL; } if ((uuid_cmp == 0) && (flags & START_PROV_NOW)) { - BT_ERR("%s, Can not start provisioning with zero uuid", __func__); + BT_ERR("Can not start provisioning with zero uuid"); return -EINVAL; } if ((add_dev->bearer & BLE_MESH_PROV_GATT) && (flags & START_PROV_NOW) && ((addr_cmp == 0) || add_dev->addr_type > BLE_MESH_ADDR_RANDOM)) { - BT_ERR("%s, Invalid device address for PB-GATT", __func__); + BT_ERR("Invalid device address for PB-GATT"); return -EINVAL; } if (add_dev->bearer & BLE_MESH_PROV_GATT) { #if !CONFIG_BLE_MESH_PB_GATT - BT_ERR("%s, Not support PB-GATT", __func__); + BT_ERR("Not support PB-GATT"); return -EINVAL; #endif } if (add_dev->bearer & BLE_MESH_PROV_ADV) { #if !CONFIG_BLE_MESH_PB_ADV - BT_ERR("%s, Not support PB-ADV", __func__); + BT_ERR("Not support PB-ADV"); return -EINVAL; #endif } @@ -872,7 +872,7 @@ int bt_mesh_provisioner_add_unprov_dev(struct bt_mesh_unprov_dev_add *add_dev, u } } - BT_ERR("%s, Unprovisioned device queue is full", __func__); + BT_ERR("Unprovisioned device queue is full"); return -ENOMEM; start: @@ -920,32 +920,32 @@ int bt_mesh_provisioner_prov_device_with_addr(const u8_t uuid[16], const u8_t ad int err = 0; if (uuid == NULL) { - BT_ERR("%s, NULL device uuid", __func__); + BT_ERR("Invalid device uuid"); return -EINVAL; } if (bearer != BLE_MESH_PROV_ADV && bearer != BLE_MESH_PROV_GATT) { - BT_ERR("%s, Invalid provisioning bearer 0x%02x", __func__, bearer); + BT_ERR("Invalid provisioning bearer 0x%02x", bearer); return -EINVAL; } if (!IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) && bearer == BLE_MESH_PROV_ADV) { - BT_ERR("%s, Not support PB-ADV", __func__); + BT_ERR("Not support PB-ADV"); return -ENOTSUP; } if (!IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) && bearer == BLE_MESH_PROV_GATT) { - BT_ERR("%s, Not support PB-GATT", __func__); + BT_ERR("Not support PB-GATT"); return -ENOTSUP; } if (bearer == BLE_MESH_PROV_GATT && (addr == NULL || addr_type > BLE_MESH_ADDR_RANDOM)) { - BT_ERR("%s, Invalid device address info", __func__); + BT_ERR("Invalid device address info"); return -EINVAL; } if (!BLE_MESH_ADDR_IS_UNICAST(unicast_addr)) { - BT_ERR("%s, Invalid unicast address 0x%04x", __func__, unicast_addr); + BT_ERR("Invalid unicast address 0x%04x", unicast_addr); return -EINVAL; } @@ -1037,7 +1037,7 @@ int bt_mesh_provisioner_delete_device(struct bt_mesh_device_delete *del_dev) /* First: find if the device is in the device queue */ err = provisioner_dev_find(&del_addr, del_dev->uuid, &i); if (err) { - BT_DBG("%s, Device is not in the queue", __func__); + BT_DBG("Device not in queue"); } else { memset(&unprov_dev[i], 0x0, sizeof(struct unprov_dev_queue)); } @@ -1074,7 +1074,7 @@ int bt_mesh_provisioner_delete_device(struct bt_mesh_device_delete *del_dev) } int bt_mesh_provisioner_set_dev_uuid_match(u8_t offset, u8_t length, - const u8_t *match, bool prov_flag) + const u8_t *match, bool prov_flag) { if (length && (!match || (offset + length > 16))) { BT_ERR("%s, Invalid parameter", __func__); @@ -1115,7 +1115,7 @@ int bt_mesh_provisioner_set_prov_data_info(struct bt_mesh_prov_data_info *info) if (info->flag & NET_IDX_FLAG) { key = bt_mesh_provisioner_net_key_get(info->net_idx); if (!key) { - BT_ERR("%s, Failed to get NetKey", __func__); + BT_ERR("Failed to get NetKey"); return -EINVAL; } prov_ctx.curr_net_idx = info->net_idx; @@ -1138,14 +1138,14 @@ int bt_mesh_provisioner_set_prov_info(void) */ if (!BLE_MESH_ADDR_IS_UNICAST(prov->prov_unicast_addr) || !BLE_MESH_ADDR_IS_UNICAST(prov->prov_start_address)) { - BT_ERR("%s, Invalid address, own 0x%04x, start 0x%04x", - __func__, prov->prov_unicast_addr, prov->prov_start_address); + BT_ERR("Invalid address, own 0x%04x, start 0x%04x", + prov->prov_unicast_addr, prov->prov_start_address); return -EINVAL; } comp = bt_mesh_comp_get(); if (!comp) { - BT_ERR("%s, NULL composition data", __func__); + BT_ERR("Invalid composition data"); return -EINVAL; } @@ -1195,7 +1195,7 @@ int bt_mesh_provisioner_set_static_oob_value(const u8_t *value, u8_t length) /* Make sure Static OOB is not being used. */ for (i = 0; i < BLE_MESH_PROV_SAME_TIME; i++) { if (link[i].auth_method == AUTH_METHOD_STATIC) { - BT_ERR("%s, Static OOB is being used", __func__); + BT_ERR("Static OOB is being used"); return -EINVAL; } } @@ -1224,7 +1224,7 @@ int bt_mesh_provisioner_set_primary_elem_addr(u16_t addr) comp = bt_mesh_comp_get(); if (!comp) { - BT_ERR("NULL composition data"); + BT_ERR("Invalid composition data"); return -EINVAL; } @@ -1259,7 +1259,7 @@ int bt_mesh_test_provisioner_update_alloc_addr(u16_t unicast_addr, u16_t element u16_t max_addr = FAST_PROV_ENABLE() ? prov_ctx.fast_prov.unicast_addr_max : PROV_MAX_ADDR_TO_ASSIGN; if (unicast_addr + element_num > max_addr) { - BT_WARN("%s, Not enough unicast address to allocate", __func__); + BT_WARN("Not enough unicast address to allocate"); prov_ctx.curr_alloc_addr = BLE_MESH_ADDR_UNASSIGNED; } else { prov_ctx.curr_alloc_addr = unicast_addr + element_num; @@ -1293,17 +1293,17 @@ u16_t bt_mesh_provisioner_get_fast_prov_net_idx(void) u8_t bt_mesh_set_fast_prov_unicast_addr_range(u16_t min, u16_t max) { if (!BLE_MESH_ADDR_IS_UNICAST(min) || !BLE_MESH_ADDR_IS_UNICAST(max)) { - BT_ERR("%s, Not a unicast address", __func__); + BT_ERR("Invalid unicast address, min 0x%04x, max 0x%04x", min, max); return 0x01; /* status: not a unicast address */ } if (min > max) { - BT_ERR("%s, Min bigger than max", __func__); + BT_ERR("Unicast address min is bigger than max"); return 0x02; /* status: min is bigger than max */ } if (min <= prov_ctx.fast_prov.unicast_addr_max) { - BT_ERR("%s, Address overlap", __func__); + BT_ERR("Unicast address overlap"); return 0x03; /* status: address overlaps with current value */ } @@ -1620,7 +1620,7 @@ static int prov_send_adv(const u8_t idx, struct net_buf_simple *msg) u8_t xact_id = 0U; s32_t timeout = PROVISION_TIMEOUT; - BT_DBG("%s, len %u: %s", __func__, msg->len, bt_hex(msg->data, msg->len)); + BT_DBG("len %u: %s", msg->len, bt_hex(msg->data, msg->len)); prov_clear_tx(idx); @@ -1649,7 +1649,7 @@ static int prov_send_adv(const u8_t idx, struct net_buf_simple *msg) buf = start; for (seg_id = 1; msg->len > 0; seg_id++) { if (seg_id >= ARRAY_SIZE(link[idx].tx.buf)) { - BT_ERR("%s, Too big message", __func__); + BT_ERR("Too big message (seg_id %d)", seg_id); free_segments(idx); return -E2BIG; } @@ -1700,7 +1700,7 @@ static int prov_send_gatt(const u8_t idx, struct net_buf_simple *msg) err = bt_mesh_proxy_client_send(link[idx].conn, BLE_MESH_PROXY_PROV, msg); if (err) { - BT_ERR("%s, Failed to send PB-GATT pdu", __func__); + BT_ERR("Failed to send PB-GATT pdu"); return err; } @@ -1730,7 +1730,7 @@ static inline int prov_send(const u8_t idx, struct net_buf_simple *buf) } #endif - BT_ERR("%s, Invalid link index %d", __func__, idx); + BT_ERR("Invalid link index %d", idx); return -EINVAL; } @@ -1766,7 +1766,7 @@ static void send_invite(const u8_t idx) link[idx].conf_inputs[0] = prov->prov_attention; if (prov_send(idx, &buf)) { - BT_ERR("%s, Failed to send Provisioning Invite", __func__); + BT_ERR("Failed to send Provisioning Invite"); close_link(idx, CLOSE_REASON_FAILED); return; } @@ -1785,7 +1785,7 @@ static void prov_capabilities(const u8_t idx, const u8_t *data) element_num = data[0]; BT_INFO("Elements: 0x%02x", element_num); if (!element_num) { - BT_ERR("%s, Invalid element number", __func__); + BT_ERR("Invalid element number %d", element_num); goto fail; } link[idx].element_num = element_num; @@ -1793,14 +1793,14 @@ static void prov_capabilities(const u8_t idx, const u8_t *data) algorithms = sys_get_be16(&data[1]); BT_INFO("Algorithms: 0x%04x", algorithms); if (algorithms != BIT(PROV_ALG_P256)) { - BT_ERR("%s, Invalid algorithms", __func__); + BT_ERR("Invalid algorithms 0x%04x", algorithms); goto fail; } pub_key_oob = data[3]; BT_INFO("Public Key Type: 0x%02x", pub_key_oob); if (pub_key_oob > 0x01) { - BT_ERR("%s, Invalid public key type", __func__); + BT_ERR("Invalid public key type 0x%02x", pub_key_oob); goto fail; } pub_key_oob = ((prov->prov_pub_key_oob && @@ -1809,7 +1809,7 @@ static void prov_capabilities(const u8_t idx, const u8_t *data) static_oob = data[4]; BT_INFO("Static OOB Type: 0x%02x", static_oob); if (static_oob > 0x01) { - BT_ERR("%s, Invalid Static OOB type", __func__); + BT_ERR("Invalid Static OOB type 0x%02x", static_oob); goto fail; } static_oob = (prov_ctx.static_oob_len ? static_oob : 0x00); @@ -1817,14 +1817,14 @@ static void prov_capabilities(const u8_t idx, const u8_t *data) output_size = data[5]; BT_INFO("Output OOB Size: 0x%02x", output_size); if (output_size > 0x08) { - BT_ERR("%s, Invalid Output OOB size", __func__); + BT_ERR("Invalid Output OOB size %d", output_size); goto fail; } output_action = sys_get_be16(&data[6]); BT_INFO("Output OOB Action: 0x%04x", output_action); if (output_action > 0x1f) { - BT_ERR("%s, Invalid Output OOB action", __func__); + BT_ERR("Invalid Output OOB action 0x%04x", output_action); goto fail; } @@ -1839,14 +1839,14 @@ static void prov_capabilities(const u8_t idx, const u8_t *data) input_size = data[8]; BT_INFO("Input OOB Size: 0x%02x", input_size); if (input_size > 0x08) { - BT_ERR("%s, Invalid Input OOB size", __func__); + BT_ERR("Invalid Input OOB size %d", input_size); goto fail; } input_action = sys_get_be16(&data[9]); BT_INFO("Input OOB Action: 0x%04x", input_action); if (input_action > 0x0f) { - BT_ERR("%s, Invalid Input OOB action", __func__); + BT_ERR("Invalid Input OOB action 0x%04x", input_action); goto fail; } @@ -1897,7 +1897,7 @@ static void prov_capabilities(const u8_t idx, const u8_t *data) memcpy(&link[idx].conf_inputs[12], &buf.data[1], 5); if (prov_send(idx, &buf)) { - BT_ERR("%s, Failed to send Provisioning Start", __func__); + BT_ERR("Failed to send Provisioning Start"); goto fail; } @@ -1911,7 +1911,7 @@ static void prov_capabilities(const u8_t idx, const u8_t *data) */ if (pub_key_oob) { if (prov->prov_pub_key_oob_cb(idx)) { - BT_ERR("%s, Failed to notify input OOB Public Key", __func__); + BT_ERR("Failed to notify input OOB Public Key"); goto fail; } } @@ -1975,7 +1975,7 @@ static int prov_auth(const u8_t idx, u8_t method, u8_t action, u8_t size) link[idx].auth = (u8_t *)bt_mesh_calloc(PROV_AUTH_VAL_SIZE); if (!link[idx].auth) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); close_link(idx, CLOSE_REASON_FAILED); return -ENOMEM; } @@ -2064,25 +2064,25 @@ static void send_confirm(const u8_t idx) link[idx].conf_salt = (u8_t *)bt_mesh_calloc(PROV_CONF_SALT_SIZE); if (!link[idx].conf_salt) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); goto fail; } link[idx].conf_key = (u8_t *)bt_mesh_calloc(PROV_CONF_KEY_SIZE); if (!link[idx].conf_key) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); goto fail; } if (bt_mesh_prov_conf_salt(link[idx].conf_inputs, link[idx].conf_salt)) { - BT_ERR("%s, Failed to generate confirmation salt", __func__); + BT_ERR("Failed to generate confirmation salt"); goto fail; } BT_DBG("ConfirmationSalt: %s", bt_hex(link[idx].conf_salt, 16)); if (bt_mesh_prov_conf_key(link[idx].dhkey, link[idx].conf_salt, link[idx].conf_key)) { - BT_ERR("%s, Failed to generate confirmation key", __func__); + BT_ERR("Failed to generate confirmation key"); goto fail; } @@ -2094,7 +2094,7 @@ static void send_confirm(const u8_t idx) */ if (!(prov_ctx.rand_gen_done & BIT(0))) { if (bt_mesh_rand(prov_ctx.random, 16)) { - BT_ERR("%s, Failed to generate random number", __func__); + BT_ERR("Failed to generate random number"); goto fail; } link[idx].rand = prov_ctx.random; @@ -2110,12 +2110,12 @@ static void send_confirm(const u8_t idx) if (bt_mesh_prov_conf(link[idx].conf_key, link[idx].rand, link[idx].auth, net_buf_simple_add(&buf, 16))) { - BT_ERR("%s, Failed to generate confirmation value", __func__); + BT_ERR("Failed to generate confirmation value"); goto fail; } if (prov_send(idx, &buf)) { - BT_ERR("%s, Failed to send Provisioning Confirm", __func__); + BT_ERR("Failed to send Provisioning Confirm"); goto fail; } @@ -2140,7 +2140,7 @@ int bt_mesh_provisioner_set_oob_input_data(const u8_t idx, const u8_t *val, bool * input by provisioner is number or string. */ if (!link[idx].auth) { - BT_ERR("%s, Link auth is NULL", __func__); + BT_ERR("Invalid link auth"); return -EINVAL; } @@ -2159,7 +2159,8 @@ int bt_mesh_provisioner_set_oob_input_data(const u8_t idx, const u8_t *val, bool return 0; } -int bt_mesh_provisioner_set_oob_output_data(const u8_t idx, const u8_t *num, u8_t size, bool num_flag) +int bt_mesh_provisioner_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. @@ -2176,7 +2177,7 @@ int bt_mesh_provisioner_set_oob_output_data(const u8_t idx, const u8_t *num, u8_ } if (!link[idx].auth) { - BT_ERR("%s, link auth is NULL", __func__); + BT_ERR("Invalid link auth"); return -EINVAL; } @@ -2197,10 +2198,11 @@ int bt_mesh_provisioner_set_oob_output_data(const u8_t idx, const u8_t *num, u8_ return 0; } -int bt_mesh_provisioner_read_oob_pub_key(const u8_t idx, const u8_t pub_key_x[32], const u8_t pub_key_y[32]) +int bt_mesh_provisioner_read_oob_pub_key(const u8_t idx, const u8_t pub_key_x[32], + const u8_t pub_key_y[32]) { if (!link[idx].conf_inputs) { - BT_ERR("%s, Link conf_inputs is NULL", __func__); + BT_ERR("Invalid link conf_inputs"); return -EINVAL; } @@ -2222,13 +2224,13 @@ static void prov_dh_key_cb(const u8_t key[32], const u8_t idx) BT_DBG("%p", key); if (!key) { - BT_ERR("%s, Failed to generate DHKey", __func__); + BT_ERR("Failed to generate DHKey"); goto fail; } link[idx].dhkey = (u8_t *)bt_mesh_calloc(PROV_DH_KEY_SIZE); if (!link[idx].dhkey) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); goto fail; } sys_memcpy_swap(link[idx].dhkey, key, 32); @@ -2246,7 +2248,7 @@ static void prov_dh_key_cb(const u8_t key[32], const u8_t idx) */ if (prov_auth(idx, link[idx].auth_method, link[idx].auth_action, link[idx].auth_size) < 0) { - BT_ERR("%s, Failed to authenticate", __func__); + BT_ERR("Failed to authenticate"); goto fail; } if (link[idx].auth_method == AUTH_METHOD_OUTPUT || @@ -2275,7 +2277,7 @@ static void prov_gen_dh_key(const u8_t idx) sys_memcpy_swap(&pub_key[32], &link[idx].conf_inputs[113], 32); if (bt_mesh_dh_key_gen(pub_key, prov_dh_key_cb, idx)) { - BT_ERR("%s, Failed to generate DHKey", __func__); + BT_ERR("Failed to generate DHKey"); close_link(idx, CLOSE_REASON_FAILED); return; } @@ -2288,7 +2290,7 @@ static void send_pub_key(const u8_t idx, u8_t oob) key = bt_mesh_pub_key_get(); if (!key) { - BT_ERR("%s, No public key available", __func__); + BT_ERR("No public key available"); close_link(idx, CLOSE_REASON_FAILED); return; } @@ -2307,7 +2309,7 @@ static void send_pub_key(const u8_t idx, u8_t oob) memcpy(&link[idx].conf_inputs[17], &buf.data[1], 64); if (prov_send(idx, &buf)) { - BT_ERR("%s, Failed to send Provisioning Public Key", __func__); + BT_ERR("Failed to send Provisioning Public Key"); close_link(idx, CLOSE_REASON_FAILED); return; } @@ -2391,7 +2393,7 @@ static void prov_confirm(const u8_t idx, const u8_t *data) link[idx].conf = (u8_t *)bt_mesh_calloc(PROV_CONFIRM_SIZE); if (!link[idx].conf) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); close_link(idx, CLOSE_REASON_FAILED); return; } @@ -2410,7 +2412,7 @@ static void prov_confirm(const u8_t idx, const u8_t *data) net_buf_simple_add_mem(&buf, link[idx].rand, 16); if (prov_send(idx, &buf)) { - BT_ERR("%s, Failed to send Provisioning Random", __func__); + BT_ERR("Failed to send Provisioning Random"); close_link(idx, CLOSE_REASON_FAILED); return; } @@ -2432,14 +2434,14 @@ static void send_prov_data(const u8_t idx) err = bt_mesh_session_key(link[idx].dhkey, link[idx].prov_salt, session_key); if (err) { - BT_ERR("%s, Failed to generate session key", __func__); + BT_ERR("Failed to generate session key"); goto fail; } BT_DBG("SessionKey: %s", bt_hex(session_key, 16)); err = bt_mesh_prov_nonce(link[idx].dhkey, link[idx].prov_salt, nonce); if (err) { - BT_ERR("%s, Failed to generate session nonce", __func__); + BT_ERR("Failed to generate session nonce"); goto fail; } BT_DBG("Nonce: %s", bt_hex(nonce, 13)); @@ -2504,14 +2506,14 @@ static void send_prov_data(const u8_t idx) } else { /* If this device to be provisioned is a new device */ if (prov_ctx.curr_alloc_addr == BLE_MESH_ADDR_UNASSIGNED) { - BT_ERR("%s, No unicast address can be allocated", __func__); + BT_ERR("Not enough unicast address to be allocated"); goto fail; } alloc_addr = prov_ctx.curr_alloc_addr; } if (alloc_addr + link[idx].element_num - 1 > max_addr) { - BT_ERR("%s, Not enough unicast address for the device", __func__); + BT_ERR("Not enough unicast address for the device"); goto fail; } @@ -2520,7 +2522,7 @@ static void send_prov_data(const u8_t idx) * any unicast address of Provisioner. */ if (bt_mesh_provisioner_check_is_addr_dup(alloc_addr, link[idx].element_num, true)) { - BT_ERR("%s, Assigned address 0x%04x is duplicated", __func__, alloc_addr); + BT_ERR("Duplicate assigned address 0x%04x", alloc_addr); goto fail; } @@ -2532,12 +2534,12 @@ static void send_prov_data(const u8_t idx) err = bt_mesh_prov_encrypt(session_key, nonce, pdu, net_buf_simple_add(&buf, 33)); if (err) { - BT_ERR("%s, Failed to encrypt provisioning data", __func__); + BT_ERR("Failed to encrypt provisioning data"); goto fail; } if (prov_send(idx, &buf)) { - BT_ERR("%s, Failed to send Provisioning Data", __func__); + BT_ERR("Failed to send Provisioning Data"); goto fail; } @@ -2595,12 +2597,12 @@ static void prov_random(const u8_t idx, const u8_t *data) BT_DBG("Remote Random: %s", bt_hex(data, 16)); if (bt_mesh_prov_conf(link[idx].conf_key, data, link[idx].auth, conf_verify)) { - BT_ERR("%s, Failed to calculate confirmation verification", __func__); + BT_ERR("Failed to calculate confirmation verification"); goto fail; } if (memcmp(conf_verify, link[idx].conf, 16)) { - BT_ERR("%s, Invalid confirmation value", __func__); + BT_ERR("Invalid confirmation value"); BT_DBG("Received: %s", bt_hex(link[idx].conf, 16)); BT_DBG("Calculated: %s", bt_hex(conf_verify, 16)); goto fail; @@ -2620,13 +2622,13 @@ static void prov_random(const u8_t idx, const u8_t *data) */ link[idx].prov_salt = (u8_t *)bt_mesh_calloc(PROV_PROV_SALT_SIZE); if (!link[idx].prov_salt) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); goto fail; } if (bt_mesh_prov_salt(link[idx].conf_salt, link[idx].rand, data, link[idx].prov_salt)) { - BT_ERR("%s, Failed to generate ProvisioningSalt", __func__); + BT_ERR("Failed to generate ProvisioningSalt"); goto fail; } @@ -2655,7 +2657,7 @@ static void prov_complete(const u8_t idx, const u8_t *data) err = bt_mesh_dev_key(link[idx].dhkey, link[idx].prov_salt, device_key); if (err) { - BT_ERR("%s, Failed to generate device key", __func__); + BT_ERR("Failed to generate device key"); close_link(idx, CLOSE_REASON_FAILED); return; } @@ -2669,7 +2671,7 @@ static void prov_complete(const u8_t idx, const u8_t *data) link[idx].unicast_addr, link[idx].element_num, net_idx, link[idx].ki_flags, link[idx].iv_index, device_key, &index); if (err) { - BT_ERR("%s, Failed to store node info", __func__); + BT_ERR("Failed to store node info"); close_link(idx, CLOSE_REASON_FAILED); return; } @@ -2685,7 +2687,7 @@ static void prov_complete(const u8_t idx, const u8_t *data) memset(&unprov_dev[rm], 0, sizeof(struct unprov_dev_queue)); } } else if (err == -ENODEV) { - BT_DBG("Device is not found in queue"); + BT_DBG("Device not found in queue"); } else { BT_ERR("Failed to remove device from queue"); } @@ -2695,7 +2697,7 @@ static void prov_complete(const u8_t idx, const u8_t *data) static void prov_failed(const u8_t idx, const u8_t *data) { - BT_WARN("%s, Error 0x%02x", __func__, data[0]); + BT_WARN("Error 0x%02x", data[0]); close_link(idx, CLOSE_REASON_FAILED); } @@ -2738,7 +2740,7 @@ static void close_link(const u8_t idx, u8_t reason) } #endif - BT_ERR("%s, Invalid link index %d", __func__, idx); + BT_ERR("Invalid link idx %d", idx); return; } @@ -2816,19 +2818,19 @@ static void link_ack(const u8_t idx, struct prov_rx *rx, struct net_buf_simple * BT_DBG("len %u", buf->len); if (buf->len) { - BT_ERR("%s, Invalid Link ACK length", __func__); + BT_ERR("Invalid Link ACK length %d", buf->len); close_link(idx, CLOSE_REASON_FAILED); return; } if (link[idx].expect == PROV_CAPABILITIES) { - BT_INFO("%s, Link ACK is already received", __func__); + BT_INFO("Link ACK is already received"); return; } link[idx].conf_inputs = (u8_t *)bt_mesh_calloc(PROV_CONF_INPUTS_SIZE); if (!link[idx].conf_inputs) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); close_link(idx, CLOSE_REASON_FAILED); return; } @@ -2870,7 +2872,7 @@ static void gen_prov_ctl(const u8_t idx, struct prov_rx *rx, struct net_buf_simp break; default: - BT_ERR("%s, Unknown bearer opcode 0x%02x", __func__, BEARER_CTL(rx->gpc)); + BT_ERR("Unknown bearer opcode 0x%02x", BEARER_CTL(rx->gpc)); return; } } @@ -2886,22 +2888,22 @@ static void prov_msg_recv(const u8_t idx) * Provisioning PDU. If the check succeeds then check fcs. */ if (type != PROV_FAILED && type != link[idx].expect) { - BT_ERR("%s, Unexpected msg 0x%02x != 0x%02x", __func__, type, link[idx].expect); + BT_ERR("Unexpected msg 0x%02x != 0x%02x", type, link[idx].expect); goto fail; } if (type >= 0x0A) { - BT_ERR("%s, Unknown provisioning PDU type 0x%02x", __func__, type); + BT_ERR("Unknown provisioning PDU type 0x%02x", type); goto fail; } if (1 + prov_handlers[type].len != link[idx].rx.buf->len) { - BT_ERR("%s, Invalid length %u for type 0x%02x", __func__, link[idx].rx.buf->len, type); + BT_ERR("Invalid length %u for type 0x%02x", link[idx].rx.buf->len, type); goto fail; } if (!bt_mesh_fcs_check(link[idx].rx.buf, link[idx].rx.fcs)) { - BT_ERR("%s, Incorrect FCS", __func__); + BT_ERR("Incorrect FCS"); goto fail; } @@ -2924,7 +2926,7 @@ static void gen_prov_cont(const u8_t idx, struct prov_rx *rx, struct net_buf_sim BT_DBG("len %u, seg_index %u", buf->len, seg); if (!link[idx].rx.seg && link[idx].rx.prev_id == rx->xact_id) { - BT_INFO("%s, Resending ack", __func__); + BT_INFO("Resending ack"); gen_prov_ack_send(idx, rx->xact_id); return; } @@ -2936,7 +2938,7 @@ static void gen_prov_cont(const u8_t idx, struct prov_rx *rx, struct net_buf_sim } if (seg > link[idx].rx.last_seg) { - BT_ERR("%s, Invalid segment index %u", __func__, seg); + BT_ERR("Invalid segment index %u", seg); goto fail; } else if (seg == link[idx].rx.last_seg) { u8_t expect_len = 0U; @@ -2944,14 +2946,14 @@ static void gen_prov_cont(const u8_t idx, struct prov_rx *rx, struct net_buf_sim expect_len = (link[idx].rx.buf->len - 20 - (23 * (link[idx].rx.last_seg - 1))); if (expect_len != buf->len) { - BT_ERR("%s, Incorrect last seg len: %u != %u", - __func__, expect_len, buf->len); + BT_ERR("Incorrect last seg len: %u != %u", + expect_len, buf->len); goto fail; } } if (!(link[idx].rx.seg & BIT(seg))) { - BT_INFO("%s, Ignore already received segment", __func__); + BT_INFO("Ignore already received segment"); return; } @@ -3004,12 +3006,12 @@ static void gen_prov_ack(const u8_t idx, struct prov_rx *rx, struct net_buf_simp static void gen_prov_start(const u8_t idx, struct prov_rx *rx, struct net_buf_simple *buf) { if (link[idx].rx.seg) { - BT_INFO("%s, Get Start while there are unreceived segments", __func__); + BT_INFO("Get Start while there are unreceived segments"); return; } if (link[idx].rx.prev_id == rx->xact_id) { - BT_INFO("%s, Resending ack", __func__); + BT_INFO("Resending ack"); gen_prov_ack_send(idx, rx->xact_id); return; } @@ -3023,20 +3025,20 @@ static void gen_prov_start(const u8_t idx, struct prov_rx *rx, struct net_buf_si /* Provisioner can not receive zero-length provisioning pdu */ if (link[idx].rx.buf->len < 1) { - BT_ERR("%s, Ignoring zero-length provisioning PDU", __func__); + BT_ERR("Ignoring zero-length provisioning PDU"); close_link(idx, CLOSE_REASON_FAILED); return; } if (link[idx].rx.buf->len > link[idx].rx.buf->size) { - BT_ERR("%s, Too large provisioning PDU (%u bytes)", - __func__, link[idx].rx.buf->len); + BT_ERR("Too large provisioning PDU (%u bytes)", + link[idx].rx.buf->len); close_link(idx, CLOSE_REASON_FAILED); return; } if (START_LAST_SEG(rx->gpc) > 0 && link[idx].rx.buf->len <= 20) { - BT_ERR("%s, Too small total length for multi-segment PDU", __func__); + BT_ERR("Too small total length for multi-segment PDU"); close_link(idx, CLOSE_REASON_FAILED); return; } @@ -3065,7 +3067,7 @@ static const struct { static void gen_prov_recv(const u8_t idx, struct prov_rx *rx, struct net_buf_simple *buf) { if (buf->len < gen_prov[GPCF(rx->gpc)].min_len) { - BT_ERR("%s, Too short GPC message type %u", __func__, GPCF(rx->gpc)); + BT_ERR("Too short GPC message type %u", GPCF(rx->gpc)); close_link(idx, CLOSE_REASON_FAILED); return; } @@ -3110,12 +3112,12 @@ void bt_mesh_provisioner_pb_adv_recv(struct net_buf_simple *buf) rx.link_id = net_buf_simple_pull_be32(buf); if (find_link(rx.link_id, &idx) < 0) { - BT_DBG("%s, Data for unexpected link", __func__); + BT_DBG("Data for unexpected link"); return; } if (buf->len < 2) { - BT_ERR("%s, Too short provisioning packet (len %u)", __func__, buf->len); + BT_ERR("Too short provisioning packet (len %u)", buf->len); close_link(idx, CLOSE_REASON_FAILED); return; } @@ -3157,28 +3159,28 @@ int bt_mesh_provisioner_pb_gatt_recv(struct bt_mesh_conn *conn, struct net_buf_s BT_DBG("%u bytes: %s", buf->len, bt_hex(buf->data, buf->len)); if (!find_conn(conn, &idx)) { - BT_ERR("%s, Data for unexpected connection", __func__); + BT_ERR("Data for unexpected connection"); return -ENOTCONN; } if (buf->len < 1) { - BT_ERR("%s, Too short provisioning packet (len %u)", __func__, buf->len); + BT_ERR("Too short provisioning packet (len %u)", buf->len); goto fail; } type = net_buf_simple_pull_u8(buf); if (type != PROV_FAILED && type != link[idx].expect) { - BT_ERR("%s, Unexpected msg 0x%02x != 0x%02x", __func__, type, link[idx].expect); + BT_ERR("Unexpected msg 0x%02x != 0x%02x", type, link[idx].expect); goto fail; } if (type >= 0x0A) { - BT_ERR("%s, Unknown provisioning PDU type 0x%02x", __func__, type); + BT_ERR("Unknown provisioning PDU type 0x%02x", type); goto fail; } if (prov_handlers[type].len != buf->len) { - BT_ERR("%s, Invalid length %u for type 0x%02x", __func__, buf->len, type); + BT_ERR("Invalid length %u for type 0x%02x", buf->len, type); goto fail; } @@ -3208,7 +3210,7 @@ int bt_mesh_provisioner_set_prov_conn(const u8_t addr[6], struct bt_mesh_conn *c } } - BT_ERR("%s, Address %s is not found", __func__, bt_hex(addr, BLE_MESH_ADDR_LEN)); + BT_ERR("Addr %s not found", bt_hex(addr, BLE_MESH_ADDR_LEN)); return -ENOMEM; } @@ -3233,7 +3235,7 @@ int bt_mesh_provisioner_pb_gatt_open(struct bt_mesh_conn *conn, u8_t *addr) } if (i == BLE_MESH_PROV_SAME_TIME) { - BT_ERR("%s, Link is not found", __func__); + BT_ERR("Link not found"); return -ENOTCONN; } @@ -3260,7 +3262,7 @@ int bt_mesh_provisioner_pb_gatt_open(struct bt_mesh_conn *conn, u8_t *addr) link[idx].conf_inputs = (u8_t *)bt_mesh_calloc(PROV_CONF_INPUTS_SIZE); if (!link[idx].conf_inputs) { /* Disconnect this connection, clear corresponding informations */ - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); close_link(idx, CLOSE_REASON_FAILED); return -ENOMEM; } @@ -3276,7 +3278,7 @@ int bt_mesh_provisioner_pb_gatt_close(struct bt_mesh_conn *conn, u8_t reason) BT_DBG("conn %p", conn); if (!find_conn(conn, &idx)) { - BT_ERR("%s, Conn %p is not found", __func__, conn); + BT_ERR("Conn %p not found", conn); return -ENOTCONN; } @@ -3306,13 +3308,13 @@ int bt_mesh_provisioner_prov_init(const struct bt_mesh_prov *prov_info) int i; if (!prov_info) { - BT_ERR("%s, No provisioning context provided", __func__); + BT_ERR("No provisioning context provided"); return -EINVAL; } key = bt_mesh_pub_key_get(); if (!key) { - BT_ERR("%s, Failed to generate Public Key", __func__); + BT_ERR("Failed to generate Public Key"); return -EIO; } @@ -3360,7 +3362,7 @@ int bt_mesh_provisioner_prov_deinit(bool erase) int i; if (prov == NULL) { - BT_ERR("%s, No provisioning context provided", __func__); + BT_ERR("No provisioning context provided"); return -EINVAL; } @@ -3416,7 +3418,7 @@ static bool is_unprov_dev_info_callback_to_app(bt_mesh_prov_bearer_t bearer, BLE_MESH_ADV_NONCONN_IND : BLE_MESH_ADV_IND; if (provisioner_dev_find(addr, uuid, &index)) { - BT_DBG("%s, Device is not in queue, notify to upper layer", __func__); + BT_DBG("Device not in queue, notify to app layer"); if (notify_unprov_adv_pkt_cb) { notify_unprov_adv_pkt_cb(addr->val, addr->type, adv_type, uuid, oob_info, bearer, rssi); } @@ -3444,12 +3446,12 @@ void bt_mesh_provisioner_unprov_beacon_recv(struct net_buf_simple *buf, s8_t rss u16_t oob_info = 0U; if (!(prov_ctx.bearers & BLE_MESH_PROV_ADV)) { - BT_WARN("Provisioner not support PB-ADV bearer"); + BT_WARN("Not support PB-ADV bearer"); return; } if (buf->len != 0x12 && buf->len != 0x16) { - BT_ERR("%s, Invalid Unprovisioned Device Beacon length", __func__); + BT_ERR("Invalid Unprovisioned Device Beacon length %d", buf->len); return; } @@ -3480,7 +3482,7 @@ void bt_mesh_provisioner_prov_adv_recv(struct net_buf_simple *buf, u16_t oob_info = 0U; if (!(prov_ctx.bearers & BLE_MESH_PROV_GATT)) { - BT_WARN("Provisioner not support PB-GATT bearer"); + BT_WARN("Not support PB-GATT bearer"); return; } diff --git a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.h b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.h index a09c342fe..959717caf 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.h +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.h @@ -235,7 +235,7 @@ int bt_mesh_provisioner_delete_device(struct bt_mesh_device_delete *del_dev); * @return Zero - success, otherwise - fail */ int bt_mesh_provisioner_set_dev_uuid_match(u8_t offset, u8_t length, - const u8_t *match, bool prov_flag); + const u8_t *match, bool prov_flag); /** @brief Callback for provisioner receiving advertising packet from unprovisioned devices which are * not in the unprovisioned device queue. @@ -360,7 +360,8 @@ int bt_mesh_provisioner_set_oob_input_data(const u8_t idx, const u8_t *val, bool * * @return Zero - success, otherwise - fail */ -int bt_mesh_provisioner_set_oob_output_data(const u8_t idx, const u8_t *num, u8_t size, bool num_flag); +int bt_mesh_provisioner_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. @@ -371,7 +372,8 @@ int bt_mesh_provisioner_set_oob_output_data(const u8_t idx, const u8_t *num, u8_ * * @return Zero - success, otherwise - fail */ -int bt_mesh_provisioner_read_oob_pub_key(const u8_t idx, const u8_t pub_key_x[32], const u8_t pub_key_y[32]); +int bt_mesh_provisioner_read_oob_pub_key(const u8_t idx, const u8_t pub_key_x[32], + const u8_t pub_key_y[32]); /* The following APIs are for fast provisioning */ diff --git a/components/bt/esp_ble_mesh/mesh_core/proxy_client.c b/components/bt/esp_ble_mesh/mesh_core/proxy_client.c index 7089da19c..f5cfb88c6 100644 --- a/components/bt/esp_ble_mesh/mesh_core/proxy_client.c +++ b/components/bt/esp_ble_mesh/mesh_core/proxy_client.c @@ -80,7 +80,7 @@ static void proxy_sar_timeout(struct k_work *work) server = CONTAINER_OF(work, struct bt_mesh_proxy_server, sar_timer.work); if (!server || !server->conn) { - BT_ERR("%s, Invalid proxy server parameter", __func__); + BT_ERR("Invalid proxy server parameter"); return; } @@ -126,19 +126,19 @@ static void filter_status(struct bt_mesh_proxy_server *server, u16_t list_size = 0U; if (buf->len != 3) { - BT_ERR("%s, Invalid Proxy Filter Status length %d", __func__, buf->len); + BT_ERR("Invalid Proxy Filter Status length %d", buf->len); return; } filter_type = net_buf_simple_pull_u8(buf); if (filter_type > 0x01) { - BT_ERR("%s, Invalid filter type 0x%02x", __func__, filter_type); + BT_ERR("Invalid proxy filter type 0x%02x", filter_type); return; } list_size = net_buf_simple_pull_be16(buf); - BT_INFO("%s, filter_type 0x%02x list_size %d", __func__, filter_type, list_size); + BT_INFO("filter_type 0x%02x, list_size %d", filter_type, list_size); if (proxy_client_filter_status_recv_cb) { proxy_client_filter_status_recv_cb(server - servers, rx->ctx.addr, server->net_idx, filter_type, list_size); @@ -162,12 +162,12 @@ static void proxy_cfg(struct bt_mesh_proxy_server *server) err = bt_mesh_net_decode(&server->buf, BLE_MESH_NET_IF_PROXY_CFG, &rx, &buf); if (err) { - BT_ERR("%s, Failed to decode Proxy Configuration (err %d)", __func__, err); + BT_ERR("Failed to decode Proxy Configuration (err %d)", err); return; } if (!BLE_MESH_ADDR_IS_UNICAST(rx.ctx.addr)) { - BT_ERR("%s, Proxy Configuration from non-unicast addr 0x%04x", __func__, rx.ctx.addr); + BT_ERR("Proxy Configuration from non-unicast addr 0x%04x", rx.ctx.addr); return; } @@ -236,7 +236,7 @@ static ssize_t proxy_recv(struct bt_mesh_conn *conn, u16_t srvc_uuid = 0U; if (!server) { - BT_ERR("%s, No Proxy Server object found", __func__); + BT_ERR("No Proxy Server object found"); return -ENOTCONN; } @@ -247,7 +247,7 @@ static ssize_t proxy_recv(struct bt_mesh_conn *conn, srvc_uuid = bt_mesh_gattc_get_service_uuid(conn); if (!srvc_uuid) { - BT_ERR("%s, No service uuid found", __func__); + BT_ERR("No service uuid found"); return -ENOTCONN; } @@ -343,7 +343,7 @@ static int proxy_segment_and_send(struct bt_mesh_conn *conn, u8_t type, mtu = bt_mesh_gattc_get_mtu_info(conn); if (!mtu) { - BT_ERR("%s, Conn used to get mtu does not exist", __func__); + BT_ERR("Conn %p used to get mtu not exists", conn); return -ENOTCONN; } @@ -379,12 +379,12 @@ int bt_mesh_proxy_client_send(struct bt_mesh_conn *conn, u8_t type, struct bt_mesh_proxy_server *server = find_server(conn); if (!server) { - BT_ERR("$%s, No Proxy Server object found", __func__); + BT_ERR("No Proxy Server object found"); return -ENOTCONN; } if ((server->conn_type == PROV) != (type == BLE_MESH_PROXY_PROV)) { - BT_ERR("%s, Invalid PDU type for Proxy Server", __func__); + BT_ERR("Invalid PDU type for Proxy Server"); return -EINVAL; } @@ -400,7 +400,7 @@ static void proxy_connected(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn, int } if (!server) { - BT_ERR("%s, No free Proxy Server objects", __func__); + BT_ERR("No free Proxy Server objects"); /** Disconnect current connection, clear part of prov_link * information, like uuid, dev_addr, linking flag, etc. */ @@ -423,7 +423,7 @@ static void proxy_disconnected(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn, BT_DBG("conn %p, handle is %d, reason 0x%02x", conn, conn->handle, reason); if (!server) { - BT_ERR("%s, No Proxy Server object found", __func__); + BT_ERR("No Proxy Server object found"); return; } @@ -457,7 +457,7 @@ static ssize_t prov_write_ccc(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn) struct bt_mesh_proxy_server *server = find_server(conn); if (!server) { - BT_ERR("%s, No Proxy Server object found", __func__); + BT_ERR("No Proxy Server object found"); return -ENOTCONN; } @@ -465,7 +465,6 @@ static ssize_t prov_write_ccc(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn) server->conn_type = PROV; if (bt_mesh_provisioner_set_prov_conn(addr->val, server->conn)) { - BT_ERR("%s, bt_mesh_provisioner_set_prov_conn failed", __func__); bt_mesh_gattc_disconnect(server->conn); return -EIO; } @@ -480,7 +479,7 @@ static ssize_t prov_recv_ntf(struct bt_mesh_conn *conn, u8_t *data, u16_t len) struct bt_mesh_proxy_server *server = find_server(conn); if (!server) { - BT_ERR("%s, No Proxy Server object found", __func__); + BT_ERR("No Proxy Server object found"); return -ENOTCONN; } @@ -531,7 +530,7 @@ static ssize_t proxy_write_ccc(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn) struct bt_mesh_proxy_server *server = find_server(conn); if (!server) { - BT_ERR("%s, No Proxy Server object found", __func__); + BT_ERR("No Proxy Server object found"); return -ENOTCONN; } @@ -552,7 +551,7 @@ static ssize_t proxy_recv_ntf(struct bt_mesh_conn *conn, u8_t *data, u16_t len) struct bt_mesh_proxy_server *server = find_server(conn); if (!server) { - BT_ERR("%s, No Proxy Server object found", __func__); + BT_ERR("No Proxy Server object found"); return -ENOTCONN; } @@ -689,7 +688,7 @@ void bt_mesh_proxy_client_gatt_adv_recv(struct net_buf_simple *buf, */ return; default: - BT_DBG("%s, Unknown Mesh Proxy adv type 0x%02x", __func__, type); + BT_DBG("Unknown Mesh Proxy adv type 0x%02x", type); return; } @@ -734,7 +733,7 @@ int bt_mesh_proxy_client_disconnect(u8_t conn_handle) conn = servers[conn_handle].conn; if (!conn) { - BT_ERR("%s, Not connected, conn_handle %d", __func__, conn_handle); + BT_ERR("Not connected, conn handle %d", conn_handle); return -ENOTCONN; } @@ -764,7 +763,7 @@ bool bt_mesh_proxy_client_relay(struct net_buf_simple *buf, u16_t dst) err = bt_mesh_proxy_client_send(server->conn, BLE_MESH_PROXY_NET_PDU, &msg); if (err) { - BT_ERR("%s, Failed to send proxy net message (err %d)", __func__, err); + BT_ERR("Failed to send proxy network message (err %d)", err); } else { BT_INFO("%u bytes to dst 0x%04x", buf->len, dst); send = true; @@ -819,7 +818,7 @@ bool bt_mesh_proxy_client_beacon_send(struct bt_mesh_subnet *sub) if (servers[i].conn && servers[i].conn_type == PROXY) { err = beacon_send(servers[i].conn, sub); if (err) { - BT_ERR("%s, Failed to send proxy beacon message (err %d)", __func__, err); + BT_ERR("Failed to send proxy beacon message (err %d)", err); } else { send = true; } @@ -851,14 +850,14 @@ static int send_proxy_cfg(struct bt_mesh_conn *conn, u16_t net_idx, struct bt_me tx.sub = bt_mesh_provisioner_subnet_get(net_idx); } if (!tx.sub) { - BT_ERR("%s, Failed to find subnet", __func__); + BT_ERR("Invalid NetKeyIndex 0x%04x", net_idx); return -EIO; } switch (cfg->opcode) { case BLE_MESH_PROXY_CFG_FILTER_SET: if (cfg->set.filter_type > 0x01) { - BT_ERR("%s, Invalid filter type 0x%02x", __func__, cfg->set.filter_type); + BT_ERR("Invalid proxy filter type 0x%02x", cfg->set.filter_type); return -EINVAL; } @@ -866,7 +865,7 @@ static int send_proxy_cfg(struct bt_mesh_conn *conn, u16_t net_idx, struct bt_me break; case BLE_MESH_PROXY_CFG_FILTER_ADD: if (cfg->add.addr == NULL || cfg->add.addr_num == 0) { - BT_ERR("%s, Add address list is NULL", __func__); + BT_ERR("Empty proxy addr list to add"); return -EINVAL; } @@ -874,14 +873,14 @@ static int send_proxy_cfg(struct bt_mesh_conn *conn, u16_t net_idx, struct bt_me break; case BLE_MESH_PROXY_CFG_FILTER_REMOVE: if (cfg->remove.addr == NULL || cfg->remove.addr_num == 0) { - BT_ERR("%s, Remove address list is NULL", __func__); + BT_ERR("Empty proxy addr list to remove"); return -EINVAL; } alloc_len = sizeof(cfg->opcode) + (cfg->remove.addr_num << 1); break; default: - BT_ERR("%s, Unknown Proxy Configuration opcode 0x%02x", __func__, cfg->opcode); + BT_ERR("Unknown Proxy Configuration opcode 0x%02x", cfg->opcode); return -EINVAL; } @@ -914,18 +913,18 @@ static int send_proxy_cfg(struct bt_mesh_conn *conn, u16_t net_idx, struct bt_me break; } - BT_DBG("%s, len %u bytes: %s", __func__, buf->len, bt_hex(buf->data, buf->len)); + BT_DBG("len %u bytes: %s", buf->len, bt_hex(buf->data, buf->len)); err = bt_mesh_net_encode(&tx, buf, true); if (err) { - BT_ERR("%s, Encoding Proxy message failed (err %d)", __func__, err); + BT_ERR("Encoding proxy message failed (err %d)", err); bt_mesh_free_buf(buf); return err; } err = bt_mesh_proxy_client_send(conn, BLE_MESH_PROXY_CONFIG, buf); if (err) { - BT_ERR("%s, Failed to send proxy cfg message (err %d)", __func__, err); + BT_ERR("Failed to send proxy cfg message (err %d)", err); } bt_mesh_free_buf(buf); @@ -946,7 +945,7 @@ int bt_mesh_proxy_client_cfg_send(u8_t conn_handle, u16_t net_idx, conn = servers[conn_handle].conn; if (!conn) { - BT_ERR("%s, Not connected, conn_handle %d", __func__, conn_handle); + BT_ERR("Not connected, conn handle %d", conn_handle); return -ENOTCONN; } @@ -955,8 +954,8 @@ int bt_mesh_proxy_client_cfg_send(u8_t conn_handle, u16_t net_idx, * with the one added when creating proxy connection. */ if (servers[conn_handle].net_idx != net_idx) { - BT_ERR("%s, NetKey Index 0x%04x mismatch, expect 0x%04x", - __func__, net_idx, servers[conn_handle].net_idx); + BT_ERR("NetKeyIndex 0x%04x mismatch, expect 0x%04x", + net_idx, servers[conn_handle].net_idx); return -EIO; } diff --git a/components/bt/esp_ble_mesh/mesh_core/proxy_client.h b/components/bt/esp_ble_mesh/mesh_core/proxy_client.h index 521370be7..bbead7a91 100644 --- a/components/bt/esp_ble_mesh/mesh_core/proxy_client.h +++ b/components/bt/esp_ble_mesh/mesh_core/proxy_client.h @@ -83,10 +83,14 @@ int bt_mesh_proxy_client_prov_disable(void); int bt_mesh_proxy_client_gatt_enable(void); int bt_mesh_proxy_client_gatt_disable(void); -typedef void (*proxy_client_recv_adv_cb_t)(const bt_mesh_addr_t *addr, u8_t type, bt_mesh_proxy_adv_ctx_t *ctx, s8_t rssi); -typedef void (*proxy_client_connect_cb_t)(const bt_mesh_addr_t *addr, u8_t conn_handle, u16_t net_idx); -typedef void (*proxy_client_disconnect_cb_t)(const bt_mesh_addr_t *addr, u8_t conn_handle, u16_t net_idx, u8_t reason); -typedef void (*proxy_client_recv_filter_status_cb_t)(u8_t conn_handle, u16_t src, u16_t net_idx, u8_t filter_type, u16_t list_size); +typedef void (*proxy_client_recv_adv_cb_t)(const bt_mesh_addr_t *addr, u8_t type, + bt_mesh_proxy_adv_ctx_t *ctx, s8_t rssi); +typedef void (*proxy_client_connect_cb_t)(const bt_mesh_addr_t *addr, + u8_t conn_handle, u16_t net_idx); +typedef void (*proxy_client_disconnect_cb_t)(const bt_mesh_addr_t *addr, u8_t conn_handle, + u16_t net_idx, u8_t reason); +typedef void (*proxy_client_recv_filter_status_cb_t)(u8_t conn_handle, u16_t src, u16_t net_idx, + u8_t filter_type, u16_t list_size); void bt_mesh_proxy_client_set_adv_recv_cb(proxy_client_recv_adv_cb_t cb); void bt_mesh_proxy_client_set_conn_cb(proxy_client_connect_cb_t cb); diff --git a/components/bt/esp_ble_mesh/mesh_core/proxy_server.c b/components/bt/esp_ble_mesh/mesh_core/proxy_server.c index bd0da41b4..1527e0de4 100644 --- a/components/bt/esp_ble_mesh/mesh_core/proxy_server.c +++ b/components/bt/esp_ble_mesh/mesh_core/proxy_server.c @@ -119,7 +119,7 @@ int bt_mesh_set_device_name(const char *name) } if (strlen(name) > DEVICE_NAME_SIZE) { - BT_ERR("%s, Too long device name", __func__); + BT_ERR("Too long device name (len %d)", strlen(name)); return -EINVAL; } @@ -150,7 +150,7 @@ static void proxy_sar_timeout(struct k_work *work) client = CONTAINER_OF(work, struct bt_mesh_proxy_client, sar_timer.work); if (!client || !client->conn) { - BT_ERR("%s, Invalid proxy client parameter", __func__); + BT_ERR("Invalid proxy client parameter"); return; } @@ -176,7 +176,7 @@ static int filter_set(struct bt_mesh_proxy_client *client, } type = net_buf_simple_pull_u8(buf); - BT_DBG("type 0x%02x", type); + BT_INFO("Set filter type 0x%02x", type); switch (type) { case 0x00: @@ -214,9 +214,12 @@ static void filter_add(struct bt_mesh_proxy_client *client, u16_t addr) for (i = 0; i < ARRAY_SIZE(client->filter); i++) { if (client->filter[i] == BLE_MESH_ADDR_UNASSIGNED) { client->filter[i] = addr; + BT_INFO("Add filter addr 0x%04x", addr); return; } } + + BT_WARN("Proxy filter is full!"); } static void filter_remove(struct bt_mesh_proxy_client *client, u16_t addr) @@ -232,6 +235,7 @@ static void filter_remove(struct bt_mesh_proxy_client *client, u16_t addr) for (i = 0; i < ARRAY_SIZE(client->filter); i++) { if (client->filter[i] == addr) { client->filter[i] = BLE_MESH_ADDR_UNASSIGNED; + BT_INFO("Remove filter addr 0x%04x", addr); return; } } @@ -275,13 +279,13 @@ static void send_filter_status(struct bt_mesh_proxy_client *client, err = bt_mesh_net_encode(&tx, buf, true); if (err) { - BT_ERR("%s, Encoding Proxy cfg message failed (err %d)", __func__, err); + BT_ERR("Encoding proxy cfg message failed (err %d)", err); return; } err = proxy_segment_and_send(client->conn, BLE_MESH_PROXY_CONFIG, buf); if (err) { - BT_ERR("%s, Failed to send proxy cfg message (err %d)", __func__, err); + BT_ERR("Failed to send proxy cfg message (err %d)", err); } } @@ -300,7 +304,7 @@ static void proxy_cfg(struct bt_mesh_proxy_client *client) err = bt_mesh_net_decode(&client->buf, BLE_MESH_NET_IF_PROXY_CFG, &rx, &buf); if (err) { - BT_ERR("%s, Failed to decode Proxy Configuration (err %d)", __func__, err); + BT_ERR("Failed to decode Proxy Configuration (err %d)", err); return; } @@ -585,7 +589,7 @@ static void proxy_connected(struct bt_mesh_conn *conn, u8_t err) } if (!client) { - BT_ERR("%s, No free Proxy Client objects", __func__); + BT_ERR("No free Proxy Client objects"); return; } @@ -904,7 +908,7 @@ void bt_mesh_proxy_server_addr_add(struct net_buf_simple *buf, u16_t addr) struct bt_mesh_proxy_client *client = CONTAINER_OF(buf, struct bt_mesh_proxy_client, buf); - BT_INFO("filter_type %u addr 0x%04x", client->filter_type, addr); + BT_DBG("filter_type %u addr 0x%04x", client->filter_type, addr); if (client->filter_type == WHITELIST) { filter_add(client, addr); @@ -1038,12 +1042,12 @@ int bt_mesh_proxy_server_send(struct bt_mesh_conn *conn, u8_t type, struct bt_mesh_proxy_client *client = find_client(conn); if (!client) { - BT_ERR("%s, No Proxy Client found", __func__); + BT_ERR("No Proxy Client found"); return -ENOTCONN; } if ((client->filter_type == PROV) != (type == BLE_MESH_PROXY_PROV)) { - BT_ERR("%s, Invalid PDU type for Proxy Client", __func__); + BT_ERR("Invalid PDU type for Proxy Client"); return -EINVAL; } @@ -1386,7 +1390,7 @@ void bt_mesh_proxy_server_adv_stop(void) err = bt_le_adv_stop(); if (err) { - BT_ERR("%s, Failed to stop advertising (err %d)", __func__, err); + BT_ERR("Failed to stop advertising (err %d)", err); } else { proxy_adv_enabled = false; } diff --git a/components/bt/esp_ble_mesh/mesh_core/settings.c b/components/bt/esp_ble_mesh/mesh_core/settings.c index f947db06c..284f91d4c 100644 --- a/components/bt/esp_ble_mesh/mesh_core/settings.c +++ b/components/bt/esp_ble_mesh/mesh_core/settings.c @@ -357,7 +357,7 @@ static int rpl_set(const char *name) if (!entry) { entry = rpl_alloc(src); if (!entry) { - BT_ERR("%s, No space for a new RPL 0x%04x", __func__, src); + BT_ERR("No space for a new RPL 0x%04x", src); err = -ENOMEM; goto free; } @@ -414,7 +414,7 @@ static int net_key_set(const char *name) err = bt_mesh_load_core_settings(get, (u8_t *)&key, sizeof(key), &exist); if (err) { - BT_ERR("%s, Failed to load NetKey 0x%03x", __func__, net_idx); + BT_ERR("Failed to load NetKey 0x%03x", net_idx); goto free; } @@ -426,7 +426,7 @@ static int net_key_set(const char *name) if (!sub) { sub = subnet_alloc(net_idx); if (!sub) { - BT_ERR("%s, No space for a new subnet 0x%03x", __func__, net_idx); + BT_ERR("No space for a new subnet 0x%03x", net_idx); err = -ENOMEM; goto free; } @@ -438,7 +438,7 @@ static int net_key_set(const char *name) memcpy(sub->keys[0].net, &key.val[0], 16); memcpy(sub->keys[1].net, &key.val[1], 16); - BT_INFO("Restored NetKey Index 0x%03x", sub->net_idx); + BT_INFO("Restored NetKeyIndex 0x%03x", sub->net_idx); BT_INFO("Restored NetKey %s", bt_hex(sub->keys[0].net, 16)); } @@ -474,7 +474,7 @@ static int app_key_set(const char *name) err = bt_mesh_load_core_settings(get, (u8_t *)&key, sizeof(key), &exist); if (err) { - BT_ERR("%s, Failed to load AppKey 0x%03x", __func__, app_idx); + BT_ERR("Failed to load AppKey 0x%03x", app_idx); goto free; } @@ -484,7 +484,7 @@ static int app_key_set(const char *name) sub = bt_mesh_subnet_get(key.net_idx); if (!sub) { - BT_ERR("%s, Failed to find subnet 0x%03x", __func__, key.net_idx); + BT_ERR("Failed to find subnet 0x%03x", key.net_idx); err = -ENOENT; goto free; } @@ -493,7 +493,7 @@ static int app_key_set(const char *name) if (!app) { app = bt_mesh_app_key_alloc(app_idx); if (!app) { - BT_ERR("%s, No space for a new app key 0x%03x", __func__, app_idx); + BT_ERR("No space for a new appkey 0x%03x", app_idx); err = -ENOMEM; goto free; } @@ -507,7 +507,7 @@ static int app_key_set(const char *name) bt_mesh_app_id(app->keys[0].val, &app->keys[0].id); bt_mesh_app_id(app->keys[1].val, &app->keys[1].id); - BT_INFO("Restored AppKey Index 0x%03x, NetKey Index 0x%03x", + BT_INFO("Restored AppKeyIndex 0x%03x, NetKeyIndex 0x%03x", app->app_idx, app->net_idx); BT_INFO("Restored AppKey %s", bt_hex(app->keys[0].val, 16)); } @@ -527,13 +527,13 @@ static int hb_pub_set(const char *name) BT_DBG("%s", __func__); if (!hb_pub) { - BT_ERR("%s, NULL cfg hb pub", __func__); + BT_ERR("Invalid heartbeat pub"); return -EINVAL; } err = bt_mesh_load_core_settings(name, (u8_t *)&hb_val, sizeof(hb_val), &exist); if (err) { - BT_ERR("Failed to load heartbeat publication"); + BT_ERR("Failed to load heartbeat pub"); hb_pub->dst = BLE_MESH_ADDR_UNASSIGNED; hb_pub->count = 0U; hb_pub->ttl = 0U; @@ -572,7 +572,7 @@ static int cfg_set(const char *name) BT_DBG("%s", __func__); if (!cfg) { - BT_ERR("%s, NULL cfg", __func__); + BT_ERR("Invalid configuration"); stored_cfg.valid = false; return -EINVAL; } @@ -787,7 +787,7 @@ static int va_set(const char *name) lab = get_label(index); if (lab == NULL) { - BT_WARN("%s, Out of labels buffers", __func__); + BT_WARN("Out of labels buffers"); err = -ENOBUFS; goto free; } @@ -826,7 +826,7 @@ static int p_prov_set(const char *name) bt_mesh_provisioner_restore_prov_info(val.primary_addr, val.alloc_addr); - BT_INFO("Restored Primary Address 0x%04x, next address allocation 0x%04x", + BT_INFO("Restored Primary Address 0x%04x, next address alloc 0x%04x", val.primary_addr, val.alloc_addr); return 0; @@ -842,7 +842,7 @@ static int p_net_idx_set(const char *name) err = bt_mesh_load_core_settings(name, (u8_t *)&net_idx, sizeof(net_idx), &exist); if (err) { - BT_ERR("Failed to load next net_idx allocation"); + BT_ERR("Failed to load next NetKeyIndex alloc"); return 0; } @@ -852,7 +852,7 @@ static int p_net_idx_set(const char *name) bt_mesh.p_net_idx_next = net_idx; - BT_INFO("Restored next NetKey Index allocation 0x%03x", bt_mesh.p_net_idx_next); + BT_INFO("Restored next NetKeyIndex alloc 0x%03x", bt_mesh.p_net_idx_next); return 0; } @@ -867,7 +867,7 @@ static int p_app_idx_set(const char *name) err = bt_mesh_load_core_settings(name, (u8_t *)&app_idx, sizeof(app_idx), &exist); if (err) { - BT_ERR("Failed to load next app_idx allocation"); + BT_ERR("Failed to load next AppKeyIndex alloc"); return 0; } @@ -877,7 +877,7 @@ static int p_app_idx_set(const char *name) bt_mesh.p_app_idx_next = app_idx; - BT_INFO("Restored next AppKey Index allocation 0x%03x", bt_mesh.p_app_idx_next); + BT_INFO("Restored next AppKeyIndex alloc 0x%03x", bt_mesh.p_app_idx_next); return 0; } @@ -890,7 +890,7 @@ static struct bt_mesh_subnet *p_subnet_alloc(void) if (bt_mesh.p_sub[i] == NULL) { bt_mesh.p_sub[i] = bt_mesh_calloc(sizeof(struct bt_mesh_subnet)); if (!bt_mesh.p_sub[i]) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return NULL; } @@ -909,7 +909,7 @@ static struct bt_mesh_app_key *p_appkey_alloc(void) if (bt_mesh.p_app_keys[i] == NULL) { bt_mesh.p_app_keys[i] = bt_mesh_calloc(sizeof(struct bt_mesh_app_key)); if (!bt_mesh.p_app_keys[i]) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return NULL; } @@ -946,7 +946,7 @@ static int p_net_key_set(const char *name) err = bt_mesh_load_core_settings(get, (u8_t *)&key, sizeof(key), &exist); if (err) { - BT_ERR("%s, Failed to load NetKey 0x%03x", __func__, net_idx); + BT_ERR("Failed to load NetKey 0x%03x", net_idx); goto free; } @@ -958,7 +958,7 @@ static int p_net_key_set(const char *name) if (!sub) { sub = p_subnet_alloc(); if (!sub) { - BT_ERR("%s, No space for a new subnet 0x%03x", __func__, net_idx); + BT_ERR("No space for a new subnet 0x%03x", net_idx); err = -ENOMEM; goto free; } @@ -970,7 +970,7 @@ static int p_net_key_set(const char *name) memcpy(sub->keys[0].net, &key.val[0], 16); memcpy(sub->keys[1].net, &key.val[1], 16); - BT_INFO("Restored NetKey Index 0x%03x", sub->net_idx); + BT_INFO("Restored NetKeyIndex 0x%03x", sub->net_idx); BT_INFO("Restored NetKey %s", bt_hex(sub->keys[0].net, 16)); } @@ -1006,7 +1006,7 @@ static int p_app_key_set(const char *name) err = bt_mesh_load_core_settings(get, (u8_t *)&key, sizeof(key), &exist); if (err) { - BT_ERR("%s, Failed to load AppKey 0x%03x", __func__, app_idx); + BT_ERR("Failed to load AppKey 0x%03x", app_idx); goto free; } @@ -1016,7 +1016,7 @@ static int p_app_key_set(const char *name) sub = bt_mesh_provisioner_subnet_get(key.net_idx); if (!sub) { - BT_ERR("%s, Failed to find subnet 0x%03x", __func__, key.net_idx); + BT_ERR("Failed to find subnet 0x%03x", key.net_idx); err = -ENOENT; goto free; } @@ -1025,7 +1025,7 @@ static int p_app_key_set(const char *name) if (!app) { app = p_appkey_alloc(); if (!app) { - BT_ERR("%s, No space for a new app key 0x%03x", __func__, app_idx); + BT_ERR("No space for a new appkey 0x%03x", app_idx); err = -ENOMEM; goto free; } @@ -1039,7 +1039,7 @@ static int p_app_key_set(const char *name) bt_mesh_app_id(app->keys[0].val, &app->keys[0].id); bt_mesh_app_id(app->keys[1].val, &app->keys[1].id); - BT_INFO("Restored AppKey Index 0x%03x, NetKey Index 0x%03x", + BT_INFO("Restored AppKeyIndex 0x%03x, NetKeyIndex 0x%03x", app->app_idx, app->net_idx); BT_INFO("Restored AppKey %s", bt_hex(app->keys[0].val, 16)); } @@ -1158,7 +1158,7 @@ static int p_node_set(const char *name) for (i = 0; i < length / SETTINGS_ITEM_SIZE; i++) { u16_t addr = net_buf_simple_pull_le16(buf); if (!BLE_MESH_ADDR_IS_UNICAST(addr)) { - BT_ERR("%s, 0x%04x is not a unicast address", __func__, addr); + BT_ERR("Invalid unicast address 0x%04x", addr); continue; } @@ -1284,14 +1284,14 @@ static int subnet_init(struct bt_mesh_subnet *sub) err = bt_mesh_net_keys_create(&sub->keys[0], sub->keys[0].net); if (err) { - BT_ERR("%s, Unable to generate keys for subnet", __func__); + BT_ERR("Unable to generate keys for subnet"); return -EIO; } if (sub->kr_phase != BLE_MESH_KR_NORMAL) { err = bt_mesh_net_keys_create(&sub->keys[1], sub->keys[1].net); if (err) { - BT_ERR("%s, Unable to generate keys for subnet", __func__); + BT_ERR("Unable to generate keys for subnet"); (void)memset(&sub->keys[0], 0, sizeof(sub->keys[0])); return -EIO; } @@ -1350,7 +1350,7 @@ int settings_core_commit(void) err = subnet_init(sub); if (err) { - BT_ERR("%s, Failed to init subnet 0x%03x", __func__, sub->net_idx); + BT_ERR("Failed to init subnet 0x%03x", sub->net_idx); } } } @@ -1376,7 +1376,7 @@ int settings_core_commit(void) err = subnet_init(sub); if (err) { - BT_ERR("%s, Failed to init subnet 0x%03x", __func__, sub->net_idx); + BT_ERR("Failed to init subnet 0x%03x", sub->net_idx); } sub->node_id = BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED; } @@ -1688,7 +1688,7 @@ static void clear_app_key(u16_t app_idx) err = bt_mesh_remove_core_settings_item("mesh/appkey", app_idx); if (err) { - BT_ERR("%s, Failed to remove 0x%03x from mesh/appkey", __func__, app_idx); + BT_ERR("Failed to remove 0x%03x from mesh/appkey", app_idx); } return; @@ -1706,7 +1706,7 @@ static void clear_net_key(u16_t net_idx) err = bt_mesh_remove_core_settings_item("mesh/netkey", net_idx); if (err) { - BT_ERR("%s, Failed to remove 0x%03x from mesh/netkey", __func__, net_idx); + BT_ERR("Failed to remove 0x%03x from mesh/netkey", net_idx); } return; @@ -1729,7 +1729,7 @@ static void store_net_key(struct bt_mesh_subnet *sub) sprintf(name, "mesh/nk/%04x", sub->net_idx); err = bt_mesh_save_core_settings(name, (const u8_t *)&key, sizeof(key)); if (err) { - BT_ERR("%s, Failed to store NetKey 0x%03x", __func__, sub->net_idx); + BT_ERR("Failed to store NetKey 0x%03x", sub->net_idx); return; } @@ -1755,7 +1755,7 @@ static void store_app_key(struct bt_mesh_app_key *app) sprintf(name, "mesh/ak/%04x", app->app_idx); err = bt_mesh_save_core_settings(name, (const u8_t *)&key, sizeof(key)); if (err) { - BT_ERR("%s, Failed to store AppKey 0x%03x", __func__, app->app_idx); + BT_ERR("Failed to store AppKey 0x%03x", app->app_idx); return; } @@ -2317,7 +2317,7 @@ static void store_p_net_key(struct bt_mesh_subnet *sub) sprintf(name, "mesh/pnk/%04x", sub->net_idx); err = bt_mesh_save_core_settings(name, (const u8_t *)&key, sizeof(key)); if (err) { - BT_ERR("%s, Failed to store NetKey 0x%03x", __func__, sub->net_idx); + BT_ERR("Failed to store NetKey 0x%03x", sub->net_idx); return; } @@ -2341,7 +2341,7 @@ static void store_p_app_key(struct bt_mesh_app_key *app) sprintf(name, "mesh/pak/%04x", app->app_idx); err = bt_mesh_save_core_settings(name, (const u8_t *)&key, sizeof(key)); if (err) { - BT_ERR("%s, Failed to store AppKey 0x%03x", __func__, app->app_idx); + BT_ERR("Failed to store AppKey 0x%03x", app->app_idx); return; } @@ -2380,7 +2380,7 @@ void bt_mesh_clear_p_app_idx(void) void bt_mesh_store_p_subnet(struct bt_mesh_subnet *sub) { if (sub == NULL) { - BT_ERR("%s, Invalid subnet",__func__); + BT_ERR("Invalid subnet"); return; } @@ -2393,7 +2393,7 @@ void bt_mesh_store_p_subnet(struct bt_mesh_subnet *sub) void bt_mesh_store_p_app_key(struct bt_mesh_app_key *key) { if (key == NULL) { - BT_ERR("%s, Invalid AppKey",__func__); + BT_ERR("Invalid AppKey"); return; } @@ -2406,7 +2406,7 @@ void bt_mesh_store_p_app_key(struct bt_mesh_app_key *key) void bt_mesh_clear_p_subnet(struct bt_mesh_subnet *sub) { if (sub == NULL) { - BT_ERR("%s, Invalid subnet",__func__); + BT_ERR("Invalid subnet"); return; } @@ -2418,7 +2418,7 @@ void bt_mesh_clear_p_subnet(struct bt_mesh_subnet *sub) void bt_mesh_clear_p_app_key(struct bt_mesh_app_key *key) { if (key == NULL) { - BT_ERR("%s, Invalid AppKey",__func__); + BT_ERR("Invalid AppKey"); return; } @@ -2433,7 +2433,7 @@ void bt_mesh_clear_rpl_single(u16_t src) int err = 0; if (!BLE_MESH_ADDR_IS_UNICAST(src)) { - BT_ERR("%s, Invalid source address 0x%04x", __func__, src); + BT_ERR("Invalid src 0x%04x", src); return; } @@ -2453,7 +2453,7 @@ void bt_mesh_store_node_info(struct bt_mesh_node *node) int err = 0; if (node == NULL) { - BT_ERR("%s, Invalid node", __func__); + BT_ERR("Invalid node info"); return; } @@ -2507,7 +2507,7 @@ static void clear_node(u16_t addr) void bt_mesh_clear_node_info(u16_t unicast_addr) { if (!BLE_MESH_ADDR_IS_UNICAST(unicast_addr)) { - BT_ERR("%s, Invalid unicast address 0x%04x", __func__, unicast_addr); + BT_ERR("Invalid unicast address 0x%04x", unicast_addr); return; } @@ -2523,7 +2523,7 @@ void bt_mesh_store_node_name(struct bt_mesh_node *node) int err = 0; if (node == NULL) { - BT_ERR("%s, Invalid node", __func__); + BT_ERR("Invalid node info"); return; } @@ -2542,7 +2542,7 @@ void bt_mesh_store_node_comp_data(struct bt_mesh_node *node) int err = 0; if (!node || !node->comp_data || node->comp_length == 0U) { - BT_ERR("%s, Invalid node info", __func__); + BT_ERR("Invalid node info"); return; } diff --git a/components/bt/esp_ble_mesh/mesh_core/storage/settings_nvs.c b/components/bt/esp_ble_mesh/mesh_core/storage/settings_nvs.c index 400eac9ce..7ea6343a8 100644 --- a/components/bt/esp_ble_mesh/mesh_core/storage/settings_nvs.c +++ b/components/bt/esp_ble_mesh/mesh_core/storage/settings_nvs.c @@ -80,22 +80,22 @@ void bt_mesh_settings_foreach(void) err = nvs_open(ctx->nvs_name, NVS_READWRITE, &ctx->handle); #endif if (err != ESP_OK) { - BT_ERR("%s, Open nvs failed, name %s, err %d", __func__, ctx->nvs_name, err); + BT_ERR("Open nvs failed, name %s, err %d", ctx->nvs_name, err); continue; } if (ctx->settings_init && ctx->settings_init()) { - BT_ERR("%s, Init settings failed, name %s", __func__, ctx->nvs_name); + BT_ERR("Init settings failed, name %s", ctx->nvs_name); continue; } if (ctx->settings_load && ctx->settings_load()) { - BT_ERR("%s, Load settings failed, name %s", __func__, ctx->nvs_name); + BT_ERR("Load settings failed, name %s", ctx->nvs_name); continue; } if (ctx->settings_commit && ctx->settings_commit()) { - BT_ERR("%s, Commit settings failed, name %s", __func__, ctx->nvs_name); + BT_ERR("Commit settings failed, name %s", ctx->nvs_name); continue; } } @@ -109,7 +109,7 @@ void bt_mesh_settings_deforeach(void) struct settings_context *ctx = &settings_ctx[i]; if (ctx->settings_deinit && ctx->settings_deinit()) { - BT_ERR("%s, Deinit settings failed, name %s", __func__, ctx->nvs_name); + BT_ERR("Deinit settings failed, name %s", ctx->nvs_name); continue; } @@ -139,26 +139,26 @@ static int settings_save(nvs_handle handle, const char *key, const u8_t *val, si return -EINVAL; } - BT_DBG("%s, nvs %s, key %s", __func__, val ? "set" : "erase", key); + BT_DBG("nvs %s, key %s", val ? "set" : "erase", key); if (val) { err = nvs_set_blob(handle, key, val, len); } else { err = nvs_erase_key(handle, key); if (err == ESP_ERR_NVS_NOT_FOUND) { - BT_DBG("%s, %s does not exist", __func__, key); + BT_DBG("%s not exists", key); return 0; } } if (err != ESP_OK) { - BT_ERR("%s, Failed to %s %s data (err %d)", __func__, - val ? "set" : "erase", key, err); + BT_ERR("Failed to %s %s data (err %d)", + val ? "set" : "erase", key, err); return -EIO; } err = nvs_commit(handle); if (err != ESP_OK) { - BT_ERR("%s, Failed to commit settings (err %d)", __func__, err); + BT_ERR("Failed to commit settings (err %d)", err); return -EIO; } @@ -186,12 +186,12 @@ static int settings_load(nvs_handle handle, const char *key, err = nvs_get_blob(handle, key, buf, &buf_len); if (err != ESP_OK) { if (err == ESP_ERR_NVS_NOT_FOUND) { - BT_DBG("%s, Settings %s is not found", __func__, key); + BT_DBG("Settings %s not found", key); *exist = false; return 0; } - BT_ERR("%s, Failed to get %s data (err %d)", __func__, key, err); + BT_ERR("Failed to get %s data (err %d)", key, err); return -EIO; } @@ -220,7 +220,7 @@ static size_t settings_get_length(nvs_handle handle, const char *key) err = nvs_get_blob(handle, key, NULL, &len); if (err != ESP_OK) { if (err != ESP_ERR_NVS_NOT_FOUND) { - BT_ERR("%s, Failed to get %s length (err %d)", __func__, key, err); + BT_ERR("Failed to get %s length (err %d)", key, err); } return 0; } @@ -242,20 +242,20 @@ static struct net_buf_simple *settings_get_item(nvs_handle handle, const char *k length = settings_get_length(handle, key); if (!length) { - BT_DBG("%s, Empty %s", __func__, key); + BT_DBG("Empty %s", key); return NULL; } buf = bt_mesh_alloc_buf(length); if (!buf) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); /* TODO: in this case, erase all related settings? */ return NULL; } err = settings_load(handle, key, buf->data, length, &exist); if (err) { - BT_ERR("%s, Failed to load %s", __func__, key); + BT_ERR("Failed to load %s", key); /* TODO: in this case, erase all related settings? */ bt_mesh_free_buf(buf); return NULL; @@ -316,7 +316,7 @@ static int settings_add_item(nvs_handle handle, const char *key, const u16_t val /* Check if val already exists */ if (is_settings_item_exist(buf, val) == true) { - BT_DBG("%s, 0x%04x already exists", __func__, val); + BT_DBG("0x%04x already exists", val); bt_mesh_free_buf(buf); return 0; } @@ -325,7 +325,7 @@ static int settings_add_item(nvs_handle handle, const char *key, const u16_t val store = bt_mesh_alloc_buf(length); if (!store) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); bt_mesh_free_buf(buf); return -ENOMEM; } @@ -363,7 +363,7 @@ static int settings_remove_item(nvs_handle handle, const char *key, const u16_t /* Check if val does exist */ if (is_settings_item_exist(buf, val) == false) { - BT_DBG("%s, 0x%04x does not exist", __func__, val); + BT_DBG("0x%04x not exists", val); bt_mesh_free_buf(buf); return 0; } @@ -377,7 +377,7 @@ static int settings_remove_item(nvs_handle handle, const char *key, const u16_t store = bt_mesh_alloc_buf(length); if (!store) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); bt_mesh_free_buf(buf); return -ENOMEM; } diff --git a/components/bt/esp_ble_mesh/mesh_core/test.c b/components/bt/esp_ble_mesh/mesh_core/test.c index 616c20708..8f2323302 100644 --- a/components/bt/esp_ble_mesh/mesh_core/test.c +++ b/components/bt/esp_ble_mesh/mesh_core/test.c @@ -46,14 +46,14 @@ int bt_mesh_device_auto_enter_network(struct bt_mesh_device_network_info *info) err = bt_mesh_provision(info->net_key, info->net_idx, info->flags, info->iv_index, info->unicast_addr, info->dev_key); if (err) { - BT_ERR("%s, bt_mesh_provision() failed (err %d)", __func__, err); + BT_ERR("bt_mesh_provision() failed (err %d)", err); return err; } /* Adds application key to device */ sub = bt_mesh_subnet_get(info->net_idx); if (!sub) { - BT_ERR("%s, Failed to find subnet 0x%04x", __func__, info->net_idx); + BT_ERR("Invalid NetKeyIndex 0x%04x", info->net_idx); return -ENODEV; } @@ -64,14 +64,14 @@ int bt_mesh_device_auto_enter_network(struct bt_mesh_device_network_info *info) } } if (i == ARRAY_SIZE(bt_mesh.app_keys)) { - BT_ERR("%s, Failed to allocate memory, AppKeyIndex 0x%04x", __func__, info->app_idx); + BT_ERR("Failed to allocate AppKey, 0x%04x", info->app_idx); return -ENOMEM; } keys = sub->kr_flag ? &key->keys[1] : &key->keys[0]; if (bt_mesh_app_id(info->app_key, &keys->id)) { - BT_ERR("%s, Failed to calculate AID, AppKeyIndex 0x%04x", __func__, info->app_idx); + BT_ERR("Failed to calculate AID, 0x%04x", info->app_idx); return -EIO; } @@ -82,7 +82,7 @@ int bt_mesh_device_auto_enter_network(struct bt_mesh_device_network_info *info) /* Binds AppKey with all non-config models, adds group address to all these models */ comp = bt_mesh_comp_get(); if (!comp) { - BT_ERR("%s, Composition data is NULL", __func__); + BT_ERR("Invalid composition data"); return -ENODEV; } diff --git a/components/bt/esp_ble_mesh/mesh_core/transport.c b/components/bt/esp_ble_mesh/mesh_core/transport.c index 1ffbf9839..bcb0ac47c 100644 --- a/components/bt/esp_ble_mesh/mesh_core/transport.c +++ b/components/bt/esp_ble_mesh/mesh_core/transport.c @@ -194,7 +194,7 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu, buf = bt_mesh_adv_create(BLE_MESH_ADV_DATA, tx->xmit, BUF_TIMEOUT); if (!buf) { - BT_ERR("%s, Out of network buffers", __func__); + BT_ERR("Out of network buffers"); return -ENOBUFS; } @@ -398,7 +398,7 @@ static void seg_tx_send_unacked(struct seg_tx *tx) err = bt_mesh_net_resend(tx->sub, seg, tx->new_key, &seg_sent_cb, tx); if (err) { - BT_ERR("%s, Sending segment failed", __func__); + BT_ERR("Sending segment failed"); bt_mesh_tx_seg_unlock(); seg_tx_complete(tx, -EIO); return; @@ -428,12 +428,12 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu, net_tx->aszmic, sdu->len); if (sdu->len < 1) { - BT_ERR("%s, Zero-length SDU not allowed", __func__); + BT_ERR("Zero-length SDU not allowed"); return -EINVAL; } if (sdu->len > BLE_MESH_TX_SDU_MAX) { - BT_ERR("%s, Not enough segment buffers for length %u", __func__, sdu->len); + BT_ERR("Not enough segment buffers for length %u", sdu->len); return -EMSGSIZE; } @@ -445,7 +445,7 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu, } if (!tx) { - BT_ERR("%s, No multi-segment message contexts available", __func__); + BT_ERR("No multi-segment message contexts available"); return -EBUSY; } @@ -496,7 +496,7 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu, seg = bt_mesh_adv_create(BLE_MESH_ADV_DATA, net_tx->xmit, BUF_TIMEOUT); if (!seg) { - BT_ERR("%s, Out of segment buffers", __func__); + BT_ERR("Out of segment buffers"); seg_tx_reset(tx); return -ENOBUFS; } @@ -544,7 +544,7 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu, seg_o ? &seg_sent_cb : &first_sent_cb, tx); if (err) { - BT_ERR("%s, Sending segment failed", __func__); + BT_ERR("Sending segment failed"); seg_tx_reset(tx); return err; } @@ -593,7 +593,7 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg, int err = 0; if (net_buf_simple_tailroom(msg) < BLE_MESH_MIC_SHORT) { - BT_ERR("%s, Insufficient tailroom for Transport MIC", __func__); + BT_ERR("Insufficient tailroom for Transport MIC"); return -EINVAL; } @@ -607,7 +607,7 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg, 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__); + BT_ERR("Failed to get model role"); return -EINVAL; } @@ -636,7 +636,7 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg, tx->ctx->addr, bt_mesh.seq, BLE_MESH_NET_IVI_TX); if (err) { - BT_ERR("%s, Encrypt failed", __func__); + BT_ERR("Encrypt failed (err %d)", err); return err; } @@ -714,7 +714,7 @@ static bool is_replay(struct bt_mesh_net_rx *rx, struct bt_mesh_rpl **match) } } - BT_ERR("%s, RPL is full!", __func__); + BT_ERR("RPL is full!"); return true; } @@ -731,7 +731,7 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr, BT_DBG("len %u: %s", buf->len, bt_hex(buf->data, buf->len)); if (buf->len < 1 + APP_MIC_LEN(aszmic)) { - BT_ERR("%s, Too short SDU + MIC", __func__); + BT_ERR("Too short SDU + MIC (len %u)", buf->len); return -EINVAL; } @@ -755,7 +755,7 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr, */ sdu = bt_mesh_alloc_buf(CONFIG_BLE_MESH_RX_SDU_MAX - BLE_MESH_MIC_SHORT); if (!sdu) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return -ENOMEM; } @@ -767,7 +767,7 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr, dev_key = bt_mesh_rx_devkey_get(i, rx->ctx.addr); if (!dev_key) { - BT_DBG("%s, NULL Device Key", __func__); + BT_DBG("DevKey not found"); continue; } @@ -787,7 +787,7 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr, return 0; } - BT_WARN("%s, Unable to decrypt with DevKey", __func__); + BT_WARN("Unable to decrypt with DevKey"); bt_mesh_free_buf(sdu); return -ENODEV; } @@ -800,7 +800,7 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr, key = bt_mesh_rx_appkey_get(i); if (!key) { - BT_DBG("%s, NULL AppKey", __func__); + BT_DBG("AppKey not found"); continue; } @@ -839,7 +839,7 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr, } if (rx->local_match) { - BT_WARN("%s, No matching AppKey", __func__); + BT_WARN("No matching AppKey"); } bt_mesh_free_buf(sdu); return 0; @@ -885,7 +885,7 @@ static int trans_ack(struct bt_mesh_net_rx *rx, u8_t hdr, u8_t obo = 0U; if (buf->len < 6) { - BT_ERR("%s, Too short ack message", __func__); + BT_ERR("Too short ack message (len %u)", buf->len); return -EINVAL; } @@ -911,7 +911,7 @@ static int trans_ack(struct bt_mesh_net_rx *rx, u8_t hdr, } if (!BLE_MESH_ADDR_IS_UNICAST(tx->dst)) { - BT_WARN("%s, Received ack for segments to group", __func__); + BT_WARN("Received ack for segments to group"); return -EINVAL; } @@ -924,7 +924,7 @@ static int trans_ack(struct bt_mesh_net_rx *rx, u8_t hdr, } if (find_msb_set(ack) - 1 > tx->seg_n) { - BT_ERR("%s, Too large segment number in ack", __func__); + BT_ERR("Too large segment number in ack"); return -EINVAL; } @@ -958,7 +958,7 @@ static int trans_heartbeat(struct bt_mesh_net_rx *rx, u16_t feat = 0U; if (buf->len < 3) { - BT_ERR("%s, Too short heartbeat message", __func__); + BT_ERR("Too short heartbeat message (len %u)", buf->len); return -EINVAL; } @@ -1054,7 +1054,7 @@ static int trans_unseg(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx, BT_DBG("AFK %u AID 0x%02x", AKF(buf->data), AID(buf->data)); if (buf->len < 1) { - BT_ERR("%s, Too small unsegmented PDU", __func__); + BT_ERR("Too small unsegmented PDU"); return -EINVAL; } @@ -1111,7 +1111,7 @@ static int ctl_send_unseg(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data, buf = bt_mesh_adv_create(BLE_MESH_ADV_DATA, tx->xmit, BUF_TIMEOUT); if (!buf) { - BT_ERR("%s, Out of transport buffers", __func__); + BT_ERR("Out of transport buffers"); return -ENOBUFS; } @@ -1154,7 +1154,7 @@ static int ctl_send_seg(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data, } if (!tx_seg) { - BT_ERR("%s, No multi-segment message contexts available", __func__); + BT_ERR("No multi-segment message contexts available"); return -EBUSY; } @@ -1187,7 +1187,7 @@ static int ctl_send_seg(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data, seg = bt_mesh_adv_create(BLE_MESH_ADV_DATA, tx->xmit, BUF_TIMEOUT); if (!seg) { - BT_ERR("%s, Out of segment buffers", __func__); + BT_ERR("Out of segment buffers"); seg_tx_reset(tx_seg); return -ENOBUFS; } @@ -1212,7 +1212,7 @@ static int ctl_send_seg(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data, seg_o ? &seg_sent_cb : &first_sent_cb, tx_seg); if (err) { - BT_ERR("%s, Sending segment failed", __func__); + BT_ERR("Sending segment failed (err %d)", err); seg_tx_reset(tx_seg); return err; } @@ -1418,17 +1418,17 @@ static bool seg_rx_is_valid(struct seg_rx *rx, struct bt_mesh_net_rx *net_rx, const u8_t *hdr, u8_t seg_n) { if (rx->hdr != *hdr || rx->seg_n != seg_n) { - BT_ERR("%s, Invalid segment for ongoing session", __func__); + BT_ERR("Invalid segment for ongoing session"); return false; } if (rx->src != net_rx->ctx.addr || rx->dst != net_rx->ctx.recv_dst) { - BT_ERR("%s, Invalid source or destination for segment", __func__); + BT_ERR("Invalid source or destination for segment"); return false; } if (rx->ctl != net_rx->ctl) { - BT_ERR("%s, Inconsistent CTL in segment", __func__); + BT_ERR("Inconsistent CTL in segment"); return false; } @@ -1482,7 +1482,7 @@ static int trans_seg(struct net_buf_simple *buf, struct bt_mesh_net_rx *net_rx, int err = 0; if (buf->len < 5) { - BT_ERR("%s, Too short segmented message (len %u)", __func__, buf->len); + BT_ERR("Too short segmented message (len %u)", buf->len); return -EINVAL; } @@ -1506,7 +1506,7 @@ static int trans_seg(struct net_buf_simple *buf, struct bt_mesh_net_rx *net_rx, BT_DBG("SeqZero 0x%04x SegO %u SegN %u", seq_zero, seg_o, seg_n); if (seg_o > seg_n) { - BT_ERR("%s, SegO greater than SegN (%u > %u)", __func__, seg_o, seg_n); + BT_ERR("SegO greater than SegN (%u > %u)", seg_o, seg_n); return -EINVAL; } @@ -1571,7 +1571,7 @@ static int trans_seg(struct net_buf_simple *buf, struct bt_mesh_net_rx *net_rx, /* Bail out early if we're not ready to receive such a large SDU */ if (!sdu_len_is_ok(net_rx->ctl, seg_n)) { - BT_ERR("%s, Too big incoming SDU length", __func__); + BT_ERR("Too big incoming SDU length"); 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); @@ -1633,7 +1633,7 @@ found_rx: } } else { if (buf->len != seg_len(rx->ctl)) { - BT_ERR("%s, Incorrect segment size for message type", __func__); + BT_ERR("Incorrect segment size for message type"); return -EINVAL; } } @@ -1953,7 +1953,7 @@ int bt_mesh_app_key_get(const struct bt_mesh_subnet *subnet, u16_t app_idx, if (app_idx == BLE_MESH_KEY_DEV) { *key = bt_mesh_tx_devkey_get(role, dst); if (!*key) { - BT_ERR("%s, Failed to get Device Key", __func__); + BT_ERR("DevKey not found"); return -EINVAL; } @@ -1962,13 +1962,13 @@ int bt_mesh_app_key_get(const struct bt_mesh_subnet *subnet, u16_t app_idx, } if (!subnet) { - BT_ERR("%s, Invalid subnet", __func__); + BT_ERR("Invalid subnet"); return -EINVAL; } app_key = bt_mesh_tx_appkey_get(role, app_idx); if (!app_key) { - BT_ERR("%s, AppKey 0x%04x not exists", __func__, app_idx); + BT_ERR("Invalid AppKeyIndex 0x%04x", app_idx); return -ENOENT; } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/client_common.c b/components/bt/esp_ble_mesh/mesh_models/client/client_common.c index c976c2737..66e128d43 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/client_common.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/client_common.c @@ -48,10 +48,9 @@ static bt_mesh_client_node_t *bt_mesh_client_pick_node(sys_slist_t *list, u16_t return NULL; } -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) +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) { bt_mesh_client_internal_data_t *data = NULL; bt_mesh_client_user_data_t *cli = NULL; @@ -64,7 +63,7 @@ bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg( cli = (bt_mesh_client_user_data_t *)model->user_data; if (!cli) { - BT_ERR("%s, Clinet user_data is NULL", __func__); + BT_ERR("Invalid client user data"); return NULL; } @@ -73,7 +72,7 @@ bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg( * this message to the application layer. */ if (!BLE_MESH_ADDR_IS_UNICAST(ctx->recv_dst)) { - BT_DBG("Unexpected status message 0x%x", ctx->recv_op); + BT_DBG("Unexpected status message 0x%08x", ctx->recv_op); if (cli->publish_status && need_pub) { cli->publish_status(ctx->recv_op, model, ctx, buf); } @@ -87,12 +86,12 @@ bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg( */ data = (bt_mesh_client_internal_data_t *)cli->internal_data; if (!data) { - BT_ERR("%s, Client internal_data is NULL", __func__); + BT_ERR("Invalid client internal data"); return NULL; } if ((node = bt_mesh_client_pick_node(&data->queue, ctx->addr)) == NULL) { - BT_DBG("Unexpected status message 0x%x", ctx->recv_op); + BT_DBG("Unexpected status message 0x%08x", ctx->recv_op); if (cli->publish_status && need_pub) { cli->publish_status(ctx->recv_op, model, ctx, buf); } @@ -100,7 +99,7 @@ bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg( } if (node->op_pending != ctx->recv_op) { - BT_DBG("Unexpected status message 0x%x", ctx->recv_op); + BT_DBG("Unexpected status message 0x%08x", ctx->recv_op); if (cli->publish_status && need_pub) { cli->publish_status(ctx->recv_op, model, ctx, buf); } @@ -108,7 +107,7 @@ bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg( } if (k_delayed_work_remaining_get(&node->timer) == 0) { - BT_DBG("Unexpected status message 0x%x", ctx->recv_op); + BT_DBG("Unexpected status message 0x%08x", ctx->recv_op); if (cli->publish_status && need_pub) { cli->publish_status(ctx->recv_op, model, ctx, buf); } @@ -273,18 +272,18 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model, client = (bt_mesh_client_user_data_t *)model->user_data; if (!client) { - BT_ERR("%s, Invalid client user data", __func__); + BT_ERR("Invalid client user data"); return -EINVAL; } internal = (bt_mesh_client_internal_data_t *)client->internal_data; if (!internal) { - BT_ERR("%s, Invalid client internal data", __func__); + BT_ERR("Invalid client internal data"); return -EINVAL; } if (ctx->addr == BLE_MESH_ADDR_UNASSIGNED) { - BT_ERR("%s, Invalid DST 0x%04x", __func__, ctx->addr); + BT_ERR("Invalid DST 0x%04x", ctx->addr); return -EINVAL; } @@ -303,19 +302,19 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model, } if (!timer_handler) { - BT_ERR("%s, Invalid timeout handler", __func__); + BT_ERR("Invalid timeout handler"); return -EINVAL; } if (bt_mesh_client_check_node_in_list(&internal->queue, ctx->addr)) { - BT_ERR("%s, Busy sending message to DST 0x%04x", __func__, ctx->addr); + BT_ERR("Busy sending message to DST 0x%04x", ctx->addr); return -EBUSY; } /* Don't forget to free the node in the timeout (timer_handler) function. */ node = (bt_mesh_client_node_t *)bt_mesh_calloc(sizeof(bt_mesh_client_node_t)); if (!node) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return -ENOMEM; } @@ -331,7 +330,7 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model, node->timeout = bt_mesh_client_calc_timeout(ctx, msg, opcode, timeout ? timeout : CONFIG_BLE_MESH_CLIENT_MSG_TIMEOUT); if (k_delayed_work_init(&node->timer, timer_handler)) { - BT_ERR("%s, Failed to create a timer", __func__); + BT_ERR("Failed to create a timer"); bt_mesh_free(node); return -EIO; } @@ -389,20 +388,20 @@ int bt_mesh_client_init(struct bt_mesh_model *model) } if (!model->op) { - BT_ERR("%s, Client model op is NULL", __func__); + BT_ERR("Invalid vendor client model op"); return -EINVAL; } cli = model->user_data; if (!cli) { - BT_ERR("%s, Client user_data is NULL", __func__); + BT_ERR("Invalid vendor client user data"); return -EINVAL; } if (!cli->internal_data) { data = bt_mesh_calloc(sizeof(bt_mesh_client_internal_data_t)); if (!data) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return -ENOMEM; } @@ -431,7 +430,7 @@ int bt_mesh_client_deinit(struct bt_mesh_model *model) client = (bt_mesh_client_user_data_t *)model->user_data; if (!client) { - BT_ERR("%s, Client user_data is NULL", __func__); + BT_ERR("Invalid vendor client user data"); return -EINVAL; } @@ -455,19 +454,19 @@ int bt_mesh_client_free_node(bt_mesh_client_node_t *node) bt_mesh_client_user_data_t *client = NULL; if (!node || !node->ctx.model) { - BT_ERR("%s, Client model list item is NULL", __func__); + BT_ERR("Invalid client list item"); return -EINVAL; } client = (bt_mesh_client_user_data_t *)node->ctx.model->user_data; if (!client) { - BT_ERR("%s, Client model user data is NULL", __func__); + BT_ERR("Invalid client user data"); return -EINVAL; } internal = (bt_mesh_client_internal_data_t *)client->internal_data; if (!internal) { - BT_ERR("%s, Client model internal data is NULL", __func__); + BT_ERR("Invalid client internal data"); return -EINVAL; } @@ -526,7 +525,7 @@ int bt_mesh_set_client_model_role(bt_mesh_role_param_t *common) case PROVISIONER: /* if provisioner is not enabled, provisioner role can't be used to send messages */ if (!bt_mesh_is_provisioner_en()) { - BT_ERR("%s, Provisioner is disabled", __func__); + BT_ERR("Provisioner is disabled"); return -EINVAL; } client->msg_role = PROVISIONER; @@ -538,7 +537,7 @@ int bt_mesh_set_client_model_role(bt_mesh_role_param_t *common) break; #endif default: - BT_WARN("%s, Unknown model role %x", __func__, common->role); + BT_WARN("Unknown model role 0x%02x", common->role); return -EINVAL; } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c b/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c index 0aff82eb6..bee29cf45 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c @@ -20,9 +20,9 @@ #include "model_opcode.h" #include "generic_client.h" -/** The following are the macro definitions of generic client - * model messages length, and a message is composed of three - * parts: Opcode + msg_value + MIC +/* The followings are the macro definitions of Generic client + * model message length, and a message is composed of 3 parts: + * Opcode + Payload + MIC */ /* Generic onoff client messages length */ #define BLE_MESH_GEN_ONOFF_GET_MSG_LEN (2 + 0 + 4) @@ -171,7 +171,7 @@ static void generic_status(struct bt_mesh_model *model, u8_t evt = 0xFF; size_t len = 0U; - BT_DBG("%s, len %d, bytes %s", __func__, buf->len, bt_hex(buf->data, buf->len)); + BT_DBG("len %d, bytes %s", buf->len, bt_hex(buf->data, buf->len)); switch (ctx->recv_op) { case BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS: { @@ -182,7 +182,7 @@ static void generic_status(struct bt_mesh_model *model, } status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_onoff_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->present_onoff = net_buf_simple_pull_u8(buf); @@ -203,7 +203,7 @@ static void generic_status(struct bt_mesh_model *model, } status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_level_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->present_level = net_buf_simple_pull_le16(buf); @@ -224,7 +224,7 @@ static void generic_status(struct bt_mesh_model *model, } status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_def_trans_time_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->trans_time = net_buf_simple_pull_u8(buf); @@ -240,7 +240,7 @@ static void generic_status(struct bt_mesh_model *model, } status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_onpowerup_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->onpowerup = net_buf_simple_pull_u8(buf); @@ -256,7 +256,7 @@ static void generic_status(struct bt_mesh_model *model, } status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_power_level_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->present_power = net_buf_simple_pull_le16(buf); @@ -277,7 +277,7 @@ static void generic_status(struct bt_mesh_model *model, } status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_power_last_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->power = net_buf_simple_pull_le16(buf); @@ -293,7 +293,7 @@ static void generic_status(struct bt_mesh_model *model, } status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_power_default_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->power = net_buf_simple_pull_le16(buf); @@ -309,7 +309,7 @@ static void generic_status(struct bt_mesh_model *model, } status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_power_range_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->status_code = net_buf_simple_pull_u8(buf); @@ -327,7 +327,7 @@ static void generic_status(struct bt_mesh_model *model, } status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_battery_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } u32_t value = 0; @@ -349,7 +349,7 @@ static void generic_status(struct bt_mesh_model *model, } status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_loc_global_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->global_latitude = net_buf_simple_pull_le32(buf); @@ -367,7 +367,7 @@ static void generic_status(struct bt_mesh_model *model, } status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_loc_local_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->local_north = net_buf_simple_pull_le16(buf); @@ -383,12 +383,12 @@ static void generic_status(struct bt_mesh_model *model, struct bt_mesh_gen_user_properties_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_user_properties_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->user_property_ids = bt_mesh_alloc_buf(buf->len); if (!status->user_property_ids) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; } @@ -401,7 +401,7 @@ static void generic_status(struct bt_mesh_model *model, struct bt_mesh_gen_user_property_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_user_property_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->user_property_id = net_buf_simple_pull_le16(buf); @@ -410,7 +410,7 @@ static void generic_status(struct bt_mesh_model *model, status->user_access = net_buf_simple_pull_u8(buf); status->user_property_value = bt_mesh_alloc_buf(buf->len); if (!status->user_property_value) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; } @@ -424,12 +424,12 @@ static void generic_status(struct bt_mesh_model *model, struct bt_mesh_gen_admin_properties_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_admin_properties_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->admin_property_ids = bt_mesh_alloc_buf(buf->len); if (!status->admin_property_ids) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; } @@ -442,7 +442,7 @@ static void generic_status(struct bt_mesh_model *model, struct bt_mesh_gen_admin_property_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_admin_property_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->admin_property_id = net_buf_simple_pull_le16(buf); @@ -451,7 +451,7 @@ static void generic_status(struct bt_mesh_model *model, status->admin_user_access = net_buf_simple_pull_u8(buf); status->admin_property_value = bt_mesh_alloc_buf(buf->len); if (!status->admin_property_value) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; } @@ -465,12 +465,12 @@ static void generic_status(struct bt_mesh_model *model, struct bt_mesh_gen_manu_properties_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_manu_properties_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->manu_property_ids = bt_mesh_alloc_buf(buf->len); if (!status->manu_property_ids) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; } @@ -483,7 +483,7 @@ static void generic_status(struct bt_mesh_model *model, struct bt_mesh_gen_manu_property_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_manu_property_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->manu_property_id = net_buf_simple_pull_le16(buf); @@ -492,7 +492,7 @@ static void generic_status(struct bt_mesh_model *model, status->manu_user_access = net_buf_simple_pull_u8(buf); status->manu_property_value = bt_mesh_alloc_buf(buf->len); if (!status->manu_property_value) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; } @@ -506,12 +506,12 @@ static void generic_status(struct bt_mesh_model *model, struct bt_mesh_gen_client_properties_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_gen_client_properties_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->client_property_ids = bt_mesh_alloc_buf(buf->len); if (!status->client_property_ids) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; } @@ -521,7 +521,7 @@ static void generic_status(struct bt_mesh_model *model, break; } default: - BT_ERR("%s, Not a Generic Status message opcode", __func__); + BT_ERR("Invalid Generic Status opcode 0x%04x", ctx->recv_op); return; } @@ -532,7 +532,7 @@ static void generic_status(struct bt_mesh_model *model, node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true); if (!node) { - BT_DBG("Unexpected generic status message 0x%x", ctx->recv_op); + BT_DBG("Unexpected Generic Status 0x%04x", ctx->recv_op); } else { switch (node->opcode) { case BLE_MESH_MODEL_OP_GEN_ONOFF_GET: @@ -720,7 +720,7 @@ static int gen_get_state(bt_mesh_client_common_param_t *common, void *value) break; } default: - BT_DBG("This generic message should be sent with NULL get pointer"); + BT_DBG("No parameters for Generic Get 0x%04x", common->opcode); break; } } @@ -729,7 +729,7 @@ static int gen_get_state(bt_mesh_client_common_param_t *common, void *value) timeout_handler, common->msg_timeout, true, common->cb, common->cb_data); if (err) { - BT_ERR("%s, Failed to send Generic Get message (err %d)", __func__, err); + BT_ERR("Failed to send Generic Get message (err %d)", err); } return err; @@ -743,7 +743,7 @@ static int gen_set_state(bt_mesh_client_common_param_t *common, msg = bt_mesh_alloc_buf(value_len); if (!msg) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return -ENOMEM; } @@ -899,7 +899,7 @@ static int gen_set_state(bt_mesh_client_common_param_t *common, } default: - BT_ERR("%s, Not a Generic Client Set message opcode", __func__); + BT_ERR("Invalid Generic Set opcode 0x%04x", common->opcode); err = -EINVAL; goto end; } @@ -908,7 +908,7 @@ static int gen_set_state(bt_mesh_client_common_param_t *common, timeout_handler, common->msg_timeout, need_ack, common->cb, common->cb_data); if (err) { - BT_ERR("%s, Failed to send Generic Set message (err %d)", __func__, err); + BT_ERR("Failed to send Generic Set message (err %d)", err); } end: @@ -917,7 +917,8 @@ end: return err; } -int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *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; @@ -928,7 +929,7 @@ int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *common, void client = (bt_mesh_generic_client_t *)common->model->user_data; if (!client || !client->internal_data) { - BT_ERR("%s, Generic Client user data is NULL", __func__); + BT_ERR("Invalid Generic client data"); return -EINVAL; } @@ -950,37 +951,38 @@ int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *common, void break; case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET: if (!get) { - BT_ERR("%s, Generic user_property_get is NULL", __func__); + BT_ERR("Invalid Generic User Property Get"); return -EINVAL; } break; case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET: if (!get) { - BT_ERR("%s, Generic admin_property_get is NULL", __func__); + BT_ERR("Invalid Generic Admin Property Get"); return -EINVAL; } break; case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET: if (!get) { - BT_ERR("%s, Generic manu_property_get is NULL", __func__); + BT_ERR("Invalid Generic Manu Property Get"); return -EINVAL; } break; case BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET: if (!get) { - BT_ERR("%s, Generic client_properties_get is NULL", __func__); + BT_ERR("Invalid Generic Client Properties Get"); return -EINVAL; } break; default: - BT_ERR("%s, Not a Generic Client Get message opcode", __func__); + BT_ERR("Invalid Generic Get opcode 0x%04x", common->opcode); return -EINVAL; } return gen_get_state(common, get); } -int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *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 = 0U; @@ -993,7 +995,7 @@ int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void client = (bt_mesh_generic_client_t *)common->model->user_data; if (!client || !client->internal_data) { - BT_ERR("%s, Generic Client user data is NULL", __func__); + BT_ERR("Invalid Generic client data"); return -EINVAL; } @@ -1005,7 +1007,7 @@ int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void value = (struct bt_mesh_gen_onoff_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("%s, Invalid Generic OnOff Set transition time", __func__); + BT_ERR("Invalid Generic OnOff Set transition time"); return -EINVAL; } } @@ -1019,7 +1021,7 @@ int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void value = (struct bt_mesh_gen_level_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("%s, Invalid Generic Level Set transition time", __func__); + BT_ERR("Invalid Generic Level Set transition time"); return -EINVAL; } } @@ -1033,7 +1035,7 @@ int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void value = (struct bt_mesh_gen_delta_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("%s, Invalid Generic Delta Set transition time", __func__); + BT_ERR("Invalid Generic Delta Set transition time"); return -EINVAL; } } @@ -1047,7 +1049,7 @@ int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void value = (struct bt_mesh_gen_move_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("%s, Invalid Generic Move Set transition time", __func__); + BT_ERR("Invalid Generic Move Set transition time"); return -EINVAL; } } @@ -1059,7 +1061,7 @@ int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET_UNACK: { u8_t value = *(u8_t *)set; if ((value & 0x3F) > 0x3E) { - BT_ERR("%s, Invalid Generic Default Trans Time Set transition time", __func__); + BT_ERR("Invalid Generic Default Trans Time Set transition time"); return -EINVAL; } length = BLE_MESH_GEN_DEF_TRANS_TIME_SET_MSG_LEN; @@ -1077,7 +1079,7 @@ int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void value = (struct bt_mesh_gen_power_level_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("%s, Invalid Generic Power Level Set transition time", __func__); + BT_ERR("Invalid Generic Power Level Set transition time"); return -EINVAL; } } @@ -1095,7 +1097,7 @@ int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void struct bt_mesh_gen_power_range_set *value; value = (struct bt_mesh_gen_power_range_set *)set; if (value->range_min > value->range_max) { - BT_ERR("%s, Generic Power Level Set range min is greater than range max", __func__); + BT_ERR("Generic Power Level Set range min is greater than range max"); return -EINVAL; } length = BLE_MESH_GEN_POWER_RANGE_SET_MSG_LEN; @@ -1117,7 +1119,7 @@ int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void struct bt_mesh_gen_user_property_set *value; value = (struct bt_mesh_gen_user_property_set *)set; if (!value->user_property_value) { - BT_ERR("%s, Generic user_property_value is NULL", __func__); + BT_ERR("Invalid Generic User Property value"); return -EINVAL; } length = (1 + 2 + value->user_property_value->len + 4); @@ -1129,7 +1131,7 @@ int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void struct bt_mesh_gen_admin_property_set *value; value = (struct bt_mesh_gen_admin_property_set *)set; if (!value->admin_property_value) { - BT_ERR("%s, Generic admin_property_value is NULL", __func__); + BT_ERR("Invalid Generic Admin Property value"); return -EINVAL; } length = (1 + 2 + 1 + value->admin_property_value->len + 4); @@ -1141,7 +1143,7 @@ int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void length = BLE_MESH_GEN_MANU_PROPERTY_SET_MSG_LEN; break; default: - BT_ERR("%s, Not a Generic Client Set message opcode", __func__); + BT_ERR("Invalid Generic Set opcode 0x%04x", common->opcode); return -EINVAL; } @@ -1162,14 +1164,14 @@ static int generic_client_init(struct bt_mesh_model *model, bool primary) client = (bt_mesh_generic_client_t *)model->user_data; if (!client) { - BT_ERR("%s, Generic Client user_data is NULL", __func__); + BT_ERR("Invalid Generic client user data"); return -EINVAL; } if (!client->internal_data) { internal = bt_mesh_calloc(sizeof(generic_internal_data_t)); if (!internal) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return -ENOMEM; } @@ -1239,7 +1241,7 @@ static int generic_client_deinit(struct bt_mesh_model *model, bool primary) client = (bt_mesh_generic_client_t *)model->user_data; if (!client) { - BT_ERR("%s, Generic Client user_data is NULL", __func__); + BT_ERR("Invalid Generic client user data"); return -EINVAL; } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/include/client_common.h b/components/bt/esp_ble_mesh/mesh_models/client/include/client_common.h index a39bcb542..78e87a24e 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/include/client_common.h +++ b/components/bt/esp_ble_mesh/mesh_models/client/include/client_common.h @@ -100,10 +100,9 @@ int bt_mesh_client_deinit(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_client_recv_publish_msg( - struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *buf, bool need_pub); +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); int bt_mesh_client_send_msg(struct bt_mesh_model *model, u32_t opcode, diff --git a/components/bt/esp_ble_mesh/mesh_models/client/include/generic_client.h b/components/bt/esp_ble_mesh/mesh_models/client/include/generic_client.h index eeda99fc3..c0b9af97f 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/include/generic_client.h +++ b/components/bt/esp_ble_mesh/mesh_models/client/include/generic_client.h @@ -557,7 +557,8 @@ int bt_mesh_gen_property_cli_deinit(struct bt_mesh_model *model, bool primary); * * @return Zero-success, other-fail */ -int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *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. @@ -568,7 +569,8 @@ int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *common, void * * @return Zero-success, other-fail */ -int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void *set, void *status); +int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, + void *set, void *status); #ifdef __cplusplus } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/include/lighting_client.h b/components/bt/esp_ble_mesh/mesh_models/client/include/lighting_client.h index 7867f10ad..f623cfb8a 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/include/lighting_client.h +++ b/components/bt/esp_ble_mesh/mesh_models/client/include/lighting_client.h @@ -527,7 +527,8 @@ int bt_mesh_light_lc_cli_deinit(struct bt_mesh_model *model, bool primary); * * @return Zero-success, other-fail */ -int bt_mesh_light_client_get_state(bt_mesh_client_common_param_t *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. @@ -538,7 +539,8 @@ int bt_mesh_light_client_get_state(bt_mesh_client_common_param_t *common, void * * * @return Zero-success, other-fail */ -int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void *set, void *status); +int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, + void *set, void *status); #ifdef __cplusplus } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/include/sensor_client.h b/components/bt/esp_ble_mesh/mesh_models/client/include/sensor_client.h index 135eaf799..2f798c69f 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/include/sensor_client.h +++ b/components/bt/esp_ble_mesh/mesh_models/client/include/sensor_client.h @@ -162,7 +162,8 @@ int bt_mesh_sensor_cli_deinit(struct bt_mesh_model *model, bool primary); * * @return Zero-success, other-fail */ -int bt_mesh_sensor_client_get_state(bt_mesh_client_common_param_t *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. @@ -173,7 +174,8 @@ int bt_mesh_sensor_client_get_state(bt_mesh_client_common_param_t *common, void * * @return Zero-success, other-fail */ -int bt_mesh_sensor_client_set_state(bt_mesh_client_common_param_t *common, void *set, void *status); +int bt_mesh_sensor_client_set_state(bt_mesh_client_common_param_t *common, + void *set, void *status); #ifdef __cplusplus } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/include/time_scene_client.h b/components/bt/esp_ble_mesh/mesh_models/client/include/time_scene_client.h index 11a917f41..4d400776b 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/include/time_scene_client.h +++ b/components/bt/esp_ble_mesh/mesh_models/client/include/time_scene_client.h @@ -272,7 +272,8 @@ int bt_mesh_scheduler_cli_deinit(struct bt_mesh_model *model, bool primary); * * @return Zero-success, other-fail */ -int bt_mesh_time_scene_client_get_state(bt_mesh_client_common_param_t *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. @@ -283,7 +284,8 @@ int bt_mesh_time_scene_client_get_state(bt_mesh_client_common_param_t *common, v * * @return Zero-success, other-fail */ -int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *common, void *set, void *status); +int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *common, + void *set, void *status); #ifdef __cplusplus } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c b/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c index 5ab225ab5..77ed50621 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c @@ -20,9 +20,9 @@ #include "model_opcode.h" #include "lighting_client.h" -/** The following are the macro definitions of lighting client - * model messages length, and a message is composed of three - * parts: Opcode + msg_value + MIC +/* The followings are the macro definitions of Lighting client + * model message length, and a message is composed of 3 parts: + * Opcode + Payload + MIC */ /* Light lightness client messages length */ #define BLE_MESH_LIGHT_LIGHTNESS_GET_MSG_LEN (2 + 0 + 4) @@ -180,18 +180,18 @@ static void light_status(struct bt_mesh_model *model, u8_t evt = 0xFF; size_t len = 0U; - BT_DBG("%s, len %d, bytes %s", __func__, buf->len, bt_hex(buf->data, buf->len)); + BT_DBG("len %d, bytes %s", buf->len, bt_hex(buf->data, buf->len)); switch (ctx->recv_op) { case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS: { struct bt_mesh_light_lightness_status *status = NULL; if (buf->len != 2 && buf->len != 5) { - BT_ERR("%s, Invalid Light Lightness Status length %d", __func__, buf->len); + BT_ERR("Invalid Light Lightness Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_lightness_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->present_lightness = net_buf_simple_pull_le16(buf); @@ -207,12 +207,12 @@ static void light_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS: { struct bt_mesh_light_lightness_linear_status *status = NULL; if (buf->len != 2 && buf->len != 5) { - BT_ERR("%s, Invalid Light Lightness Linear Status length %d", __func__, buf->len); + BT_ERR("Invalid Light Lightness Linear Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_lightness_linear_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->present_lightness = net_buf_simple_pull_le16(buf); @@ -228,12 +228,12 @@ static void light_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_STATUS: { struct bt_mesh_light_lightness_last_status *status = NULL; if (buf->len != 2) { - BT_ERR("%s, Invalid Light Lightness Last Status length %d", __func__, buf->len); + BT_ERR("Invalid Light Lightness Last Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_lightness_last_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->lightness = net_buf_simple_pull_le16(buf); @@ -244,12 +244,12 @@ static void light_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_STATUS: { struct bt_mesh_light_lightness_default_status *status = NULL; if (buf->len != 2) { - BT_ERR("%s, Invalid Light Lightness Default Status length %d", __func__, buf->len); + BT_ERR("Invalid Light Lightness Default Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_lightness_default_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->lightness = net_buf_simple_pull_le16(buf); @@ -260,12 +260,12 @@ static void light_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS: { struct bt_mesh_light_lightness_range_status *status = NULL; if (buf->len != 5) { - BT_ERR("%s, Invalid Light Lightness Range Status length %d", __func__, buf->len); + BT_ERR("Invalid Light Lightness Range Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_lightness_range_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->status_code = net_buf_simple_pull_u8(buf); @@ -278,12 +278,12 @@ static void light_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_LIGHT_CTL_STATUS: { struct bt_mesh_light_ctl_status *status = NULL; if (buf->len != 4 && buf->len != 9) { - BT_ERR("%s, Invalid Light CTL Status length %d", __func__, buf->len); + BT_ERR("Invalid Light CTL Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_ctl_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->present_ctl_lightness = net_buf_simple_pull_le16(buf); @@ -301,12 +301,12 @@ static void light_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS: { struct bt_mesh_light_ctl_temperature_status *status = NULL; if (buf->len != 4 && buf->len != 9) { - BT_ERR("%s, Invalid Light CTL Temperature Status length %d", __func__, buf->len); + BT_ERR("Invalid Light CTL Temperature Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_ctl_temperature_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->present_ctl_temperature = net_buf_simple_pull_le16(buf); @@ -324,12 +324,12 @@ static void light_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS: { struct bt_mesh_light_ctl_temperature_range_status *status = NULL; if (buf->len != 5) { - BT_ERR("%s, Invalid Light CTL Temperature Range Status length %d", __func__, buf->len); + BT_ERR("Invalid Light CTL Temperature Range Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_ctl_temperature_range_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->status_code = net_buf_simple_pull_u8(buf); @@ -342,12 +342,12 @@ static void light_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS: { struct bt_mesh_light_ctl_default_status *status = NULL; if (buf->len != 6) { - BT_ERR("%s, Invalid Light CTL Default Status length %d", __func__, buf->len); + BT_ERR("Invalid Light CTL Default Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_ctl_default_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->lightness = net_buf_simple_pull_le16(buf); @@ -360,12 +360,12 @@ static void light_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_LIGHT_HSL_STATUS: { struct bt_mesh_light_hsl_status *status = NULL; if (buf->len != 6 && buf->len != 7) { - BT_ERR("%s, Invalid Light HSL Status length %d", __func__, buf->len); + BT_ERR("Invalid Light HSL Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_hsl_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->hsl_lightness = net_buf_simple_pull_le16(buf); @@ -382,12 +382,12 @@ static void light_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_LIGHT_HSL_TARGET_STATUS: { struct bt_mesh_light_hsl_target_status *status = NULL; if (buf->len != 6 && buf->len != 7) { - BT_ERR("%s, Invalid Light HSL Target Status length %d", __func__, buf->len); + BT_ERR("Invalid Light HSL Target Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_hsl_target_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->hsl_lightness_target = net_buf_simple_pull_le16(buf); @@ -404,12 +404,12 @@ static void light_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS: { struct bt_mesh_light_hsl_hue_status *status = NULL; if (buf->len != 2 && buf->len != 5) { - BT_ERR("%s, Invalid Light HSL Hue Status length %d", __func__, buf->len); + BT_ERR("Invalid Light HSL Hue Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_hsl_hue_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->present_hue = net_buf_simple_pull_le16(buf); @@ -425,12 +425,12 @@ static void light_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS: { struct bt_mesh_light_hsl_saturation_status *status = NULL; if (buf->len != 2 && buf->len != 5) { - BT_ERR("%s, Invalid Light HSL Saturation Status length %d", __func__, buf->len); + BT_ERR("Invalid Light HSL Saturation Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_hsl_saturation_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->present_saturation = net_buf_simple_pull_le16(buf); @@ -446,12 +446,12 @@ static void light_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_STATUS: { struct bt_mesh_light_hsl_default_status *status = NULL; if (buf->len != 6) { - BT_ERR("%s, Invalid Light HSL Default Status length %d", __func__, buf->len); + BT_ERR("Invalid Light HSL Default Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_hsl_default_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->lightness = net_buf_simple_pull_le16(buf); @@ -464,12 +464,12 @@ static void light_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_STATUS: { struct bt_mesh_light_hsl_range_status *status = NULL; if (buf->len != 9) { - BT_ERR("%s, Invalid Light HSL Range Status length %d", __func__, buf->len); + BT_ERR("Invalid Light HSL Range Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_hsl_range_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->status_code = net_buf_simple_pull_u8(buf); @@ -484,12 +484,12 @@ static void light_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_LIGHT_XYL_STATUS: { struct bt_mesh_light_xyl_status *status = NULL; if (buf->len != 6 && buf->len != 7) { - BT_ERR("%s, Invalid Light xyL Status length %d", __func__, buf->len); + BT_ERR("Invalid Light xyL Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_xyl_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->xyl_lightness = net_buf_simple_pull_le16(buf); @@ -506,12 +506,12 @@ static void light_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_LIGHT_XYL_TARGET_STATUS: { struct bt_mesh_light_xyl_target_status *status = NULL; if (buf->len != 6 && buf->len != 7) { - BT_ERR("%s, Invalid Light xyL Target Status length %d", __func__, buf->len); + BT_ERR("Invalid Light xyL Target Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_xyl_target_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->target_xyl_lightness = net_buf_simple_pull_le16(buf); @@ -528,12 +528,12 @@ static void light_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_STATUS: { struct bt_mesh_light_xyl_default_status *status = NULL; if (buf->len != 6) { - BT_ERR("%s, Invalid Light xyL Default Status length %d", __func__, buf->len); + BT_ERR("Invalid Light xyL Default Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_xyl_default_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->lightness = net_buf_simple_pull_le16(buf); @@ -546,12 +546,12 @@ static void light_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_STATUS: { struct bt_mesh_light_xyl_range_status *status = NULL; if (buf->len != 9) { - BT_ERR("%s, Invalid Light xyL Range Status length %d", __func__, buf->len); + BT_ERR("Invalid Light xyL Range Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_xyl_range_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->status_code = net_buf_simple_pull_u8(buf); @@ -566,12 +566,12 @@ static void light_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_LIGHT_LC_MODE_STATUS: { struct bt_mesh_light_lc_mode_status *status = NULL; if (buf->len != 1) { - BT_ERR("%s, Invalid Light LC Mode Status length %d", __func__, buf->len); + BT_ERR("Invalid Light LC Mode Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_lc_mode_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->mode = net_buf_simple_pull_u8(buf); @@ -582,12 +582,12 @@ static void light_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_LIGHT_LC_OM_STATUS: { struct bt_mesh_light_lc_om_status *status = NULL; if (buf->len != 1) { - BT_ERR("%s, Invalid Light LC OM Status length %d", __func__, buf->len); + BT_ERR("Invalid Light LC OM Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_lc_om_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->mode = net_buf_simple_pull_u8(buf); @@ -598,12 +598,12 @@ static void light_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS: { struct bt_mesh_light_lc_light_onoff_status *status = NULL; if (buf->len != 1 && buf->len != 3) { - BT_ERR("%s, Invalid Light LC Light OnOff Status length %d", __func__, buf->len); + BT_ERR("Invalid Light LC Light OnOff Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_light_lc_light_onoff_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->present_light_onoff = net_buf_simple_pull_u8(buf); @@ -620,13 +620,13 @@ static void light_status(struct bt_mesh_model *model, struct bt_mesh_light_lc_property_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_light_lc_property_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->light_lc_property_id = net_buf_simple_pull_le16(buf); status->light_lc_property_value = bt_mesh_alloc_buf(buf->len); if (!status->light_lc_property_value) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; } @@ -636,7 +636,7 @@ static void light_status(struct bt_mesh_model *model, break; } default: - BT_ERR("%s, Not a Lighting Status message opcode", __func__); + BT_ERR("Invalid Lighting Status opcode 0x%04x", ctx->recv_op); return; } @@ -647,7 +647,7 @@ static void light_status(struct bt_mesh_model *model, node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true); if (!node) { - BT_DBG("Unexpected light status message 0x%x", ctx->recv_op); + BT_DBG("Unexpected Lighting Status 0x%04x", ctx->recv_op); } else { switch (node->opcode) { case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_GET: @@ -785,7 +785,7 @@ static int light_get_state(bt_mesh_client_common_param_t *common, void *value) break; } default: - BT_DBG("This lighting message should be sent with NULL get pointer"); + BT_DBG("No parameters for Lighting Get 0x%04x", common->opcode); break; } } @@ -794,7 +794,7 @@ static int light_get_state(bt_mesh_client_common_param_t *common, void *value) timeout_handler, common->msg_timeout, true, common->cb, common->cb_data); if (err) { - BT_ERR("%s, Failed to send Lighting Client Get message (err %d)", __func__, err); + BT_ERR("Failed to send Lighting Get message (err %d)", err); } return err; @@ -808,7 +808,7 @@ static int light_set_state(bt_mesh_client_common_param_t *common, msg = bt_mesh_alloc_buf(value_len); if (!msg) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return -ENOMEM; } @@ -1023,7 +1023,7 @@ static int light_set_state(bt_mesh_client_common_param_t *common, break; } default: - BT_ERR("%s, Not a Lighting Client Set message opcode", __func__); + BT_ERR("Invalid Lighting Set opcode 0x%04x", common->opcode); err = -EINVAL; goto end; } @@ -1032,7 +1032,7 @@ static int light_set_state(bt_mesh_client_common_param_t *common, timeout_handler, common->msg_timeout, need_ack, common->cb, common->cb_data); if (err) { - BT_ERR("%s, Failed to send Lighting Client Set message (err %d)", __func__, err); + BT_ERR("Failed to send Lighting Set message (err %d)", err); } end: @@ -1041,7 +1041,8 @@ end: return err; } -int bt_mesh_light_client_get_state(bt_mesh_client_common_param_t *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; @@ -1052,7 +1053,7 @@ int bt_mesh_light_client_get_state(bt_mesh_client_common_param_t *common, void * client = (bt_mesh_light_client_t *)common->model->user_data; if (!client || !client->internal_data) { - BT_ERR("%s, Lighting Client user data is NULL", __func__); + BT_ERR("Invalid Lighting client data"); return -EINVAL; } @@ -1082,19 +1083,20 @@ int bt_mesh_light_client_get_state(bt_mesh_client_common_param_t *common, void * break; case BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET: if (!get) { - BT_ERR("%s, Lighting lc_property_get is NULL", __func__); + BT_ERR("Invalid Lighting LC Property Get"); return -EINVAL; } break; default: - BT_ERR("%s, Not a Lighting Client Get message opcode", __func__); + BT_ERR("Invalid Lighting Get opcode 0x%04x", common->opcode); return -EINVAL; } return light_get_state(common, get); } -int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *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 = 0U; @@ -1107,7 +1109,7 @@ int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void * client = (bt_mesh_light_client_t *)common->model->user_data; if (!client || !client->internal_data) { - BT_ERR("%s, Lighting Client user data is NULL", __func__); + BT_ERR("Invalid Lighting client data"); return -EINVAL; } @@ -1119,7 +1121,7 @@ int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void * value = (struct bt_mesh_light_lightness_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("%s, Invalid Light Lightness Set transition time", __func__); + BT_ERR("Invalid Light Lightness Set transition time"); return -EINVAL; } } @@ -1133,7 +1135,7 @@ int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void * value = (struct bt_mesh_light_lightness_linear_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("%s, Invalid Light Lightness Linear Set transition time", __func__); + BT_ERR("Invalid Light Lightness Linear Set transition time"); return -EINVAL; } } @@ -1151,7 +1153,7 @@ int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void * struct bt_mesh_light_lightness_range_set *value; value = (struct bt_mesh_light_lightness_range_set *)set; if (value->range_min > value->range_max) { - BT_ERR("%s, Light Lightness Range Set range min is greater than range max", __func__); + BT_ERR("Light Lightness Range Set range min is greater than range max"); return -EINVAL; } length = BLE_MESH_LIGHT_LIGHTNESS_RANGE_SET_MSG_LEN; @@ -1164,7 +1166,7 @@ int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void * value = (struct bt_mesh_light_ctl_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("%s, Invalid Light CTL Set transition time", __func__); + BT_ERR("Invalid Light CTL Set transition time"); return -EINVAL; } } @@ -1178,7 +1180,7 @@ int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void * value = (struct bt_mesh_light_ctl_temperature_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("%s, Invalid Light CTL Temperature Set transition time", __func__); + BT_ERR("Invalid Light CTL Temperature Set transition time"); return -EINVAL; } } @@ -1191,7 +1193,7 @@ int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void * struct bt_mesh_light_ctl_temperature_range_set *value; value = (struct bt_mesh_light_ctl_temperature_range_set *)set; if (value->range_min > value->range_max) { - BT_ERR("%s, Light CTL Temperature Range Set range min is greater than range max", __func__); + BT_ERR("Light CTL Temperature Range Set range min is greater than range max"); return -EINVAL; } length = BLE_MESH_LIGHT_CTL_TEMPERATURE_RANGE_SET_MSG_LEN; @@ -1209,7 +1211,7 @@ int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void * value = (struct bt_mesh_light_hsl_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("%s, Invalid Light HSL Set transition time", __func__); + BT_ERR("Invalid Light HSL Set transition time"); return -EINVAL; } } @@ -1223,7 +1225,7 @@ int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void * value = (struct bt_mesh_light_hsl_hue_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("%s, Invalid Light HSL Hue Set transition time", __func__); + BT_ERR("Invalid Light HSL Hue Set transition time"); return -EINVAL; } } @@ -1237,7 +1239,7 @@ int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void * value = (struct bt_mesh_light_hsl_saturation_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("%s, Invalid Light HSL Saturation Set transition time", __func__); + BT_ERR("Invalid Light HSL Saturation Set transition time"); return -EINVAL; } } @@ -1256,7 +1258,7 @@ int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void * value = (struct bt_mesh_light_hsl_range_set *)set; if (value->hue_range_min > value->hue_range_max || value->saturation_range_min > value->saturation_range_max) { - BT_ERR("%s, Light HSL Range Set range min is greater than range max", __func__); + BT_ERR("Light HSL Range Set range min is greater than range max"); return -EINVAL; } length = BLE_MESH_LIGHT_HSL_RANGE_SET_MSG_LEN; @@ -1269,7 +1271,7 @@ int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void * value = (struct bt_mesh_light_xyl_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("%s, Invalid Light xyL Set transition time", __func__); + BT_ERR("Invalid Light xyL Set transition time"); return -EINVAL; } } @@ -1288,7 +1290,7 @@ int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void * value = (struct bt_mesh_light_xyl_range_set *)set; if (value->xyl_x_range_min > value->xyl_x_range_max || value->xyl_y_range_min > value->xyl_y_range_max) { - BT_ERR("%s, Light xyL Range Set range min is greater than range max", __func__); + BT_ERR("Light xyL Range Set range min is greater than range max"); return -EINVAL; } length = BLE_MESH_LIGHT_XYL_RANGE_SET_MSG_LEN; @@ -1311,7 +1313,7 @@ int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void * value = (struct bt_mesh_light_lc_light_onoff_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("%s, Invalid Light LC Light OnOff Set transition time", __func__); + BT_ERR("Invalid Light LC Light OnOff Set transition time"); return -EINVAL; } } @@ -1324,14 +1326,14 @@ int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void * struct bt_mesh_light_lc_property_set *value; value = (struct bt_mesh_light_lc_property_set *)set; if (!value->light_lc_property_value) { - BT_ERR("%s, Lighting light_lc_property_value is NULL", __func__); + BT_ERR("Invalid Lighting Light LC Property value"); return -EINVAL; } length = (1 + 2 + value->light_lc_property_value->len + 4); break; } default: - BT_ERR("%s, Not a Lighting Client Set message opcode", __func__); + BT_ERR("Invalid Lighting Set opcode 0x%04x", common->opcode); return -EINVAL; } @@ -1352,14 +1354,14 @@ static int light_client_init(struct bt_mesh_model *model, bool primary) client = (bt_mesh_light_client_t *)model->user_data; if (!client) { - BT_ERR("%s, Lighting Client user_data is NULL", __func__); + BT_ERR("Invalid Lighting client user data"); return -EINVAL; } if (!client->internal_data) { internal = bt_mesh_calloc(sizeof(light_internal_data_t)); if (!internal) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return -ENOMEM; } @@ -1414,7 +1416,7 @@ static int light_client_deinit(struct bt_mesh_model *model, bool primary) client = (bt_mesh_light_client_t *)model->user_data; if (!client) { - BT_ERR("%s, Lighting Client user_data is NULL", __func__); + BT_ERR("Invalid Lighting client user data"); return -EINVAL; } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c b/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c index 18e1e389e..860c50a8b 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c @@ -20,9 +20,9 @@ #include "model_opcode.h" #include "sensor_client.h" -/** The following are the macro definitions of sensor client - * model messages length, and a message is composed of three - * parts: Opcode + msg_value + MIC +/* The followings are the macro definitions of Sensor client + * model message length, and a message is composed of 3 parts: + * Opcode + Payload + MIC */ /* Sensor client messages length */ #define BLE_MESH_SENSOR_DESCRIPTOR_GET_MSG_LEN (2 + 2 + 4) @@ -109,19 +109,19 @@ static void sensor_status(struct bt_mesh_model *model, u8_t evt = 0xFF; size_t len = 0U; - BT_DBG("%s, len %d, bytes %s", __func__, buf->len, bt_hex(buf->data, buf->len)); + BT_DBG("len %d, bytes %s", buf->len, bt_hex(buf->data, buf->len)); switch (ctx->recv_op) { case BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS: { struct bt_mesh_sensor_descriptor_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_sensor_descriptor_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->descriptor = bt_mesh_alloc_buf(buf->len); if (!status->descriptor) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; } @@ -134,13 +134,13 @@ static void sensor_status(struct bt_mesh_model *model, struct bt_mesh_sensor_cadence_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_sensor_cadence_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->property_id = net_buf_simple_pull_le16(buf); status->sensor_cadence_value = bt_mesh_alloc_buf(buf->len); if (!status->sensor_cadence_value) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; } @@ -153,13 +153,13 @@ static void sensor_status(struct bt_mesh_model *model, struct bt_mesh_sensor_settings_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_sensor_settings_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->sensor_property_id = net_buf_simple_pull_le16(buf); status->sensor_setting_property_ids = bt_mesh_alloc_buf(buf->len); if (!status->sensor_setting_property_ids) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; } @@ -172,7 +172,7 @@ static void sensor_status(struct bt_mesh_model *model, struct bt_mesh_sensor_setting_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_sensor_setting_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->sensor_property_id = net_buf_simple_pull_le16(buf); @@ -182,7 +182,7 @@ static void sensor_status(struct bt_mesh_model *model, status->sensor_setting_access = net_buf_simple_pull_u8(buf); status->sensor_setting_raw = bt_mesh_alloc_buf(buf->len); if (!status->sensor_setting_raw) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; } @@ -196,12 +196,12 @@ static void sensor_status(struct bt_mesh_model *model, struct bt_mesh_sensor_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_sensor_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->marshalled_sensor_data = bt_mesh_alloc_buf(buf->len); if (!status->marshalled_sensor_data) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; } @@ -214,13 +214,13 @@ static void sensor_status(struct bt_mesh_model *model, struct bt_mesh_sensor_column_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_sensor_column_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->property_id = net_buf_simple_pull_le16(buf); status->sensor_column_value = bt_mesh_alloc_buf(buf->len); if (!status->sensor_column_value) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; } @@ -233,13 +233,13 @@ static void sensor_status(struct bt_mesh_model *model, struct bt_mesh_sensor_series_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_sensor_series_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->property_id = net_buf_simple_pull_le16(buf); status->sensor_series_value = bt_mesh_alloc_buf(buf->len); if (!status->sensor_series_value) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; } @@ -249,7 +249,7 @@ static void sensor_status(struct bt_mesh_model *model, break; } default: - BT_ERR("%s, Not a Sensor Status message opcode", __func__); + BT_ERR("Invalid Sensor Status opcode 0x%04x", ctx->recv_op); return; } @@ -260,7 +260,7 @@ static void sensor_status(struct bt_mesh_model *model, node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true); if (!node) { - BT_DBG("Unexpected sensor status message 0x%x", ctx->recv_op); + BT_DBG("Unexpected Sensor Status 0x%04x", ctx->recv_op); } else { switch (node->opcode) { case BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET: @@ -360,7 +360,7 @@ static int sensor_act_state(bt_mesh_client_common_param_t *common, msg = bt_mesh_alloc_buf(value_len); if (!msg) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return -ENOMEM; } @@ -442,7 +442,7 @@ static int sensor_act_state(bt_mesh_client_common_param_t *common, break; } default: - BT_ERR("%s, Not a Sensor Client message opcode", __func__); + BT_ERR("Invalid Sensor client opcode 0x%04x", common->opcode); err = -EINVAL; goto end; } @@ -451,7 +451,7 @@ static int sensor_act_state(bt_mesh_client_common_param_t *common, timeout_handler, common->msg_timeout, need_ack, common->cb, common->cb_data); if (err) { - BT_ERR("%s, Failed to send Sensor Client message (err %d)", __func__, err); + BT_ERR("Failed to send Sensor client message (err %d)", err); } end: @@ -460,7 +460,8 @@ end: return err; } -int bt_mesh_sensor_client_get_state(bt_mesh_client_common_param_t *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 = 0U; @@ -472,7 +473,7 @@ int bt_mesh_sensor_client_get_state(bt_mesh_client_common_param_t *common, void client = (bt_mesh_sensor_client_t *)common->model->user_data; if (!client || !client->internal_data) { - BT_ERR("%s, Sensor Client user data is NULL", __func__); + BT_ERR("Invalid Sensor client data"); return -EINVAL; } @@ -496,7 +497,7 @@ int bt_mesh_sensor_client_get_state(bt_mesh_client_common_param_t *common, void struct bt_mesh_sensor_column_get *value; value = (struct bt_mesh_sensor_column_get *)get; if (!value->raw_value_x) { - BT_ERR("%s, Sensor column_get is NULL", __func__); + BT_ERR("Invalid Sensor Column Get"); return -EINVAL; } length = (2 + 2 + value->raw_value_x->len + 4); @@ -507,7 +508,7 @@ int bt_mesh_sensor_client_get_state(bt_mesh_client_common_param_t *common, void value = (struct bt_mesh_sensor_series_get *)get; if (value->op_en) { if (!value->raw_value_x1 || !value->raw_value_x2) { - BT_ERR("%s, Sensor series_get is NULL", __func__); + BT_ERR("Invalid Sensor Series Get"); return -EINVAL; } } @@ -518,14 +519,15 @@ int bt_mesh_sensor_client_get_state(bt_mesh_client_common_param_t *common, void break; } default: - BT_ERR("%s, Not a Sensor Client Get message opcode", __func__); + BT_ERR("Invalid Sensor Get opcode 0x%04x", common->opcode); return -EINVAL; } return sensor_act_state(common, get, length, true); } -int bt_mesh_sensor_client_set_state(bt_mesh_client_common_param_t *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 = 0U; @@ -538,7 +540,7 @@ int bt_mesh_sensor_client_set_state(bt_mesh_client_common_param_t *common, void client = (bt_mesh_sensor_client_t *)common->model->user_data; if (!client || !client->internal_data) { - BT_ERR("%s, Sensor Client user data is NULL", __func__); + BT_ERR("Invalid Sensor client data"); return -EINVAL; } @@ -550,7 +552,7 @@ int bt_mesh_sensor_client_set_state(bt_mesh_client_common_param_t *common, void value = (struct bt_mesh_sensor_cadence_set *)set; if (!value->status_trigger_delta_down || !value->status_trigger_delta_up || !value->fast_cadence_low || !value->fast_cadence_high) { - BT_ERR("%s, Sensor cadence_set is NULL", __func__); + BT_ERR("Invalid Sensor Cadence Set"); return -EINVAL; } length = value->status_trigger_delta_down->len + \ @@ -566,14 +568,14 @@ int bt_mesh_sensor_client_set_state(bt_mesh_client_common_param_t *common, void struct bt_mesh_sensor_setting_set *value; value = (struct bt_mesh_sensor_setting_set *)set; if (!value->sensor_setting_raw) { - BT_ERR("%s, Sensor setting_raw is NULL", __func__); + BT_ERR("Invalid Sensor Setting Raw value"); return -EINVAL; } length = (1 + 2 + 2 + value->sensor_setting_raw->len + 4); break; } default: - BT_ERR("%s, Not a Sensor Client Set message opcode", __func__); + BT_ERR("Invalid Sensor Set opcode 0x%04x", common->opcode); return -EINVAL; } @@ -594,14 +596,14 @@ int bt_mesh_sensor_cli_init(struct bt_mesh_model *model, bool primary) client = (bt_mesh_sensor_client_t *)model->user_data; if (!client) { - BT_ERR("%s, Sensor Client user_data is NULL", __func__); + BT_ERR("Invalid Sensor client user data"); return -EINVAL; } if (!client->internal_data) { internal = bt_mesh_calloc(sizeof(sensor_internal_data_t)); if (!internal) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return -ENOMEM; } @@ -631,7 +633,7 @@ int bt_mesh_sensor_cli_deinit(struct bt_mesh_model *model, bool primary) client = (bt_mesh_sensor_client_t *)model->user_data; if (!client) { - BT_ERR("%s, Sensor Client user_data is NULL", __func__); + BT_ERR("Invalid Sensor client user data"); return -EINVAL; } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c b/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c index 11162ae4f..9357cdbc7 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c @@ -20,9 +20,9 @@ #include "model_opcode.h" #include "time_scene_client.h" -/** The following are the macro definitions of time and client - * scene model messages length, and a message is composed of - * three parts: Opcode + msg_value + MIC +/* The followings are the macro definitions of Time Scene client + * model message length, and a message is composed of 3 parts: + * Opcode + Payload + MIC */ /* Time client messages length */ #define BLE_MESH_TIME_SET_MSG_LEN (1 + 10 + 4) @@ -125,18 +125,18 @@ static void time_scene_status(struct bt_mesh_model *model, u8_t evt = 0xFF; size_t len = 0U; - BT_DBG("%s, len %d, bytes %s", __func__, buf->len, bt_hex(buf->data, buf->len)); + BT_DBG("len %d, bytes %s", buf->len, bt_hex(buf->data, buf->len)); switch (ctx->recv_op) { case BLE_MESH_MODEL_OP_TIME_STATUS: { struct bt_mesh_time_status *status = NULL; if (buf->len != 5 && buf->len != 10) { - BT_ERR("%s, Invalid Time Status length %d", __func__, buf->len); + BT_ERR("Invalid Time Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_time_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } memcpy(status->tai_seconds, buf->data, 5); @@ -154,12 +154,12 @@ static void time_scene_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_TIME_ZONE_STATUS: { struct bt_mesh_time_zone_status *status = NULL; if (buf->len != 7) { - BT_ERR("%s, Invalid Time Zone Status length %d", __func__, buf->len); + BT_ERR("Invalid Time Zone Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_time_zone_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->time_zone_offset_curr = net_buf_simple_pull_u8(buf); @@ -173,12 +173,12 @@ static void time_scene_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_TAI_UTC_DELTA_STATUS: { struct bt_mesh_tai_utc_delta_status *status = NULL; if (buf->len != 9) { - BT_ERR("%s, Invalid TAI UTC Delta Status length %d", __func__, buf->len); + BT_ERR("Invalid TAI UTC Delta Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_tai_utc_delta_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } u16_t temp = net_buf_simple_pull_le16(buf); @@ -196,12 +196,12 @@ static void time_scene_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_TIME_ROLE_STATUS: { struct bt_mesh_time_role_status *status = NULL; if (buf->len != 1) { - BT_ERR("%s, Invalid Time Role Status length %d", __func__, buf->len); + BT_ERR("Invalid Time Role Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_time_role_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->time_role = net_buf_simple_pull_u8(buf); @@ -212,12 +212,12 @@ static void time_scene_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_SCENE_STATUS: { struct bt_mesh_scene_status *status = NULL; if (buf->len != 3 && buf->len != 6) { - BT_ERR("%s, Invalid Scene Status length %d", __func__, buf->len); + BT_ERR("Invalid Scene Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_scene_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->status_code = net_buf_simple_pull_u8(buf); @@ -235,14 +235,14 @@ static void time_scene_status(struct bt_mesh_model *model, struct bt_mesh_scene_register_status *status = NULL; status = bt_mesh_calloc(sizeof(struct bt_mesh_scene_register_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->status_code = net_buf_simple_pull_u8(buf); status->current_scene = net_buf_simple_pull_le16(buf); status->scenes = bt_mesh_alloc_buf(buf->len); if (!status->scenes) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); bt_mesh_free(status); return; } @@ -254,12 +254,12 @@ static void time_scene_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_SCHEDULER_STATUS: { struct bt_mesh_scheduler_status *status = NULL; if (buf->len != 2) { - BT_ERR("%s, Invalid Scheduler Status length %d", __func__, buf->len); + BT_ERR("Invalid Scheduler Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_scheduler_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } status->schedules = net_buf_simple_pull_le16(buf); @@ -270,12 +270,12 @@ static void time_scene_status(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_SCHEDULER_ACT_STATUS: { struct bt_mesh_scheduler_act_status *status = NULL; if (buf->len != 10) { - BT_ERR("%s, Invalid Scheduler Action Status length %d", __func__, buf->len); + BT_ERR("Invalid Scheduler Action Status length %d", buf->len); return; } status = bt_mesh_calloc(sizeof(struct bt_mesh_scheduler_act_status)); if (!status) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } memcpy(status, buf->data, offsetof(struct bt_mesh_scheduler_act_status, scene_number)); @@ -286,7 +286,7 @@ static void time_scene_status(struct bt_mesh_model *model, break; } default: - BT_ERR("%s, Not a Time Scene Status message opcode", __func__); + BT_ERR("Invalid Time Scene Status opcode 0x%04x", ctx->recv_op); return; } @@ -297,7 +297,7 @@ static void time_scene_status(struct bt_mesh_model *model, node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true); if (!node) { - BT_DBG("Unexpected time scene status message 0x%x", ctx->recv_op); + BT_DBG("Unexpected Time Scene Status 0x%04x", ctx->recv_op); } else { switch (node->opcode) { case BLE_MESH_MODEL_OP_TIME_GET: @@ -385,7 +385,7 @@ static int time_scene_get_state(bt_mesh_client_common_param_t *common, void *val break; } default: - BT_DBG("This time scene message should be sent with NULL get pointer"); + BT_DBG("No parameters for Time Scene Get 0x%04x", common->opcode); break; } } @@ -394,7 +394,7 @@ static int time_scene_get_state(bt_mesh_client_common_param_t *common, void *val timeout_handler, common->msg_timeout, true, common->cb, common->cb_data); if (err) { - BT_ERR("%s, Failed to send Time Scene Get message (err %d)", __func__, err); + BT_ERR("Failed to send Time Scene Get message (err %d)", err); } return err; @@ -408,7 +408,7 @@ static int time_scene_set_state(bt_mesh_client_common_param_t *common, msg = bt_mesh_alloc_buf(value_len); if (!msg) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return -ENOMEM; } @@ -480,7 +480,7 @@ static int time_scene_set_state(bt_mesh_client_common_param_t *common, break; } default: - BT_ERR("%s, Not a Time Scene Client set message opcode", __func__); + BT_ERR("Invalid Time Scene Set opcode 0x%04x", common->opcode); err = -EINVAL; goto end; } @@ -489,7 +489,7 @@ static int time_scene_set_state(bt_mesh_client_common_param_t *common, timeout_handler, common->msg_timeout, need_ack, common->cb, common->cb_data); if (err) { - BT_ERR("%s, Failed to send Time Scene Set message (err %d)", __func__, err); + BT_ERR("Failed to send Time Scene Set message (err %d)", err); } end: @@ -497,7 +497,8 @@ end: return err; } -int bt_mesh_time_scene_client_get_state(bt_mesh_client_common_param_t *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; @@ -508,7 +509,7 @@ int bt_mesh_time_scene_client_get_state(bt_mesh_client_common_param_t *common, v client = (bt_mesh_time_scene_client_t *)common->model->user_data; if (!client || !client->internal_data) { - BT_ERR("%s, Time Scene Client user data is NULL", __func__); + BT_ERR("Invalid Time Scene client data"); return -EINVAL; } @@ -523,19 +524,20 @@ int bt_mesh_time_scene_client_get_state(bt_mesh_client_common_param_t *common, v break; case BLE_MESH_MODEL_OP_SCHEDULER_ACT_GET: if (!get) { - BT_ERR("%s, Scheduler action index is NULL", __func__); + BT_ERR("Invalid Scheduler Action Get"); return -EINVAL; } break; default: - BT_ERR("%s, Not a Time Scene Client Get message opcode", __func__); + BT_ERR("Invalid Time Scene Get opcode 0x%04x", common->opcode); return -EINVAL; } return time_scene_get_state(common, get); } -int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *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 = 0U; @@ -548,7 +550,7 @@ int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *common, v client = (bt_mesh_time_scene_client_t *)common->model->user_data; if (!client || !client->internal_data) { - BT_ERR("%s, Time Scene Client user data is NULL", __func__); + BT_ERR("Invalid Time Scene client data"); return -EINVAL; } @@ -565,7 +567,7 @@ int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *common, v struct bt_mesh_tai_utc_delta_set *value; value = (struct bt_mesh_tai_utc_delta_set *)set; if (value->padding) { - BT_ERR("%s, Non-zero padding value is prohibited", __func__); + BT_ERR("Non-zero padding value is prohibited"); return -EINVAL; } need_ack = true; @@ -576,7 +578,7 @@ int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *common, v struct bt_mesh_time_role_set *value; value = (struct bt_mesh_time_role_set *)set; if (value->time_role > 0x03) { - BT_ERR("%s, Time role value is prohibited", __func__); + BT_ERR("Time role 0x%02x is prohibited", value->time_role); return -EINVAL; } need_ack = true; @@ -589,7 +591,7 @@ int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *common, v struct bt_mesh_scene_store *value; value = (struct bt_mesh_scene_store *)set; if (!value->scene_number) { - BT_ERR("%s, Scene store scene_number 0x0000 is prohibited", __func__); + BT_ERR("Scene Store scene number 0x0000 is prohibited"); return -EINVAL; } length = BLE_MESH_SCENE_STORE_MSG_LEN; @@ -601,12 +603,12 @@ int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *common, v struct bt_mesh_scene_recall *value; value = (struct bt_mesh_scene_recall *)set; if (!value->scene_number) { - BT_ERR("%s, Scene recall scene_number 0x0000 is prohibited", __func__); + BT_ERR("Scene Recall scene number 0x0000 is prohibited"); return -EINVAL; } if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("%s, Invalid Scene Recall transition time", __func__); + BT_ERR("Invalid Scene Recall transition time"); return -EINVAL; } } @@ -625,18 +627,18 @@ int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *common, v struct bt_mesh_scheduler_act_set *value; value = (struct bt_mesh_scheduler_act_set *)set; if (value->year > 0x64) { - BT_ERR("%s, Scheduler register year value is prohibited", __func__); + BT_ERR("Scheduler Register year 0x%02x is prohibited", value->year); return -EINVAL; } if (value->hour > 0x19) { - BT_ERR("%s, Scheduler register hour value is prohibited", __func__); + BT_ERR("Scheduler Register hour 0x%02x is prohibited", value->hour); return -EINVAL; } length = BLE_MESH_SCHEDULER_ACT_SET_MSG_LEN; break; } default: - BT_ERR("%s, Not a Time Scene Set message opcode", __func__); + BT_ERR("Invalid Time Scene Set opcode 0x%04x", common->opcode); return -EINVAL; } @@ -657,14 +659,14 @@ static int time_scene_client_init(struct bt_mesh_model *model, bool primary) client = (bt_mesh_time_scene_client_t *)model->user_data; if (!client) { - BT_ERR("%s, Time Scene Client user_data is NULL", __func__); + BT_ERR("Invalid Time Scene client user data"); return -EINVAL; } if (!client->internal_data) { internal = bt_mesh_calloc(sizeof(time_scene_internal_data_t)); if (!internal) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return -ENOMEM; } @@ -709,7 +711,7 @@ static int time_scene_client_deinit(struct bt_mesh_model *model, bool primary) client = (bt_mesh_time_scene_client_t *)model->user_data; if (!client) { - BT_ERR("%s, Time Scene Client user_data is NULL", __func__); + BT_ERR("Invalid Time Scene client user data"); return -EINVAL; } diff --git a/components/bt/esp_ble_mesh/mesh_models/server/device_property.c b/components/bt/esp_ble_mesh/mesh_models/server/device_property.c index 5ef9d3968..64741c462 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/device_property.c +++ b/components/bt/esp_ble_mesh/mesh_models/server/device_property.c @@ -138,7 +138,7 @@ static struct bt_mesh_dev_prop { u8_t bt_mesh_get_dev_prop_len(u16_t prop_id) { if (prop_id > BLE_MESH_TOTAL_LUMINOUS_ENERGY) { - BT_ERR("%s, Unknown Device Property ID 0x%04x", __func__, prop_id); + BT_ERR("Unknown Device Property ID 0x%04x", prop_id); return UINT8_MAX; } diff --git a/components/bt/esp_ble_mesh/mesh_models/server/generic_server.c b/components/bt/esp_ble_mesh/mesh_models/server/generic_server.c index f268030c2..6cbf85dc6 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/generic_server.c +++ b/components/bt/esp_ble_mesh/mesh_models/server/generic_server.c @@ -59,7 +59,7 @@ static void send_gen_onoff_status(struct bt_mesh_model *model, if (publish == false) { msg = bt_mesh_alloc_buf(length + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } } else { @@ -93,7 +93,7 @@ static void gen_onoff_get(struct bt_mesh_model *model, struct bt_mesh_gen_onoff_srv *srv = model->user_data; if (srv == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -111,7 +111,7 @@ static void gen_onoff_get(struct bt_mesh_model *model, void gen_onoff_publish(struct bt_mesh_model *model) { if (model->user_data == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -129,13 +129,13 @@ static void gen_onoff_set(struct bt_mesh_model *model, s64_t now = 0; if (srv == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } onoff = net_buf_simple_pull_u8(buf); if (onoff > BLE_MESH_STATE_ON) { - BT_ERR("%s, Invalid OnOff value 0x%02x", __func__, onoff); + BT_ERR("Invalid OnOff value 0x%02x", onoff); return; } tid = net_buf_simple_pull_u8(buf); @@ -231,7 +231,7 @@ static void send_gen_level_status(struct bt_mesh_model *model, if (publish == false) { msg = bt_mesh_alloc_buf(length + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } } else { @@ -274,7 +274,7 @@ static void gen_level_get(struct bt_mesh_model *model, struct bt_mesh_gen_level_srv *srv = model->user_data; if (srv == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -292,7 +292,7 @@ static void gen_level_get(struct bt_mesh_model *model, void gen_level_publish(struct bt_mesh_model *model) { if (model->user_data == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -311,7 +311,7 @@ static void gen_level_set(struct bt_mesh_model *model, s64_t now = 0; if (srv == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -407,7 +407,7 @@ static void gen_delta_set(struct bt_mesh_model *model, s64_t now = 0; if (srv == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -529,7 +529,7 @@ static void gen_move_set(struct bt_mesh_model *model, s64_t now = 0; if (srv == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -660,7 +660,7 @@ static void send_gen_def_trans_time_status(struct bt_mesh_model *model, if (publish == false) { msg = bt_mesh_alloc_buf(length + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } } else { @@ -689,7 +689,7 @@ static void gen_def_trans_time_get(struct bt_mesh_model *model, struct bt_mesh_gen_def_trans_time_srv *srv = model->user_data; if (srv == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -712,13 +712,13 @@ static void gen_def_trans_time_set(struct bt_mesh_model *model, u8_t trans_time = 0U; if (srv == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } trans_time = net_buf_simple_pull_u8(buf); if ((trans_time & 0x3F) == 0x3F) { - BT_WARN("%s, Invalid Transaction Number of Steps 0x3F", __func__); + BT_WARN("Invalid Transaction Number of Steps 0x3f"); return; } @@ -766,7 +766,7 @@ static void send_gen_onpowerup_status(struct bt_mesh_model *model, if (publish == false) { msg = bt_mesh_alloc_buf(length + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } } else { @@ -789,7 +789,7 @@ static void send_gen_onpowerup_status(struct bt_mesh_model *model, break; } default: - BT_ERR("%s, Invalid Generic Power OnOff Server 0x%04x", __func__, model->id); + BT_ERR("Invalid Generic Power OnOff Server 0x%04x", model->id); if (publish == false) { bt_mesh_free_buf(msg); } @@ -812,7 +812,7 @@ static void gen_onpowerup_get(struct bt_mesh_model *model, struct bt_mesh_gen_power_onoff_srv *srv = model->user_data; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -831,7 +831,7 @@ static void gen_onpowerup_get(struct bt_mesh_model *model, void gen_onpowerup_publish(struct bt_mesh_model *model) { if (model->user_data == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -839,7 +839,7 @@ void gen_onpowerup_publish(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV: { struct bt_mesh_gen_power_onoff_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Generic Power OnOff Server state", __func__); + BT_ERR("Invalid Generic Power OnOff Server state"); return; } break; @@ -847,13 +847,13 @@ void gen_onpowerup_publish(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV: { struct bt_mesh_gen_power_onoff_setup_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Generic Power OnOff Setup Server state", __func__); + BT_ERR("Invalid Generic Power OnOff Setup Server state"); return; } break; } default: - BT_ERR("%s, Invalid Generic Power OnOff Server 0x%04x", __func__, model->id); + BT_ERR("Invalid Generic Power OnOff Server 0x%04x", model->id); return; } @@ -869,13 +869,13 @@ static void gen_onpowerup_set(struct bt_mesh_model *model, u8_t onpowerup = 0U; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } onpowerup = net_buf_simple_pull_u8(buf); if (onpowerup > BLE_MESH_STATE_RESTORE) { - BT_WARN("%s, Invalid OnPowerUp value 0x%02x", __func__, onpowerup); + BT_WARN("Invalid OnPowerUp value 0x%02x", onpowerup); return; } @@ -923,7 +923,7 @@ static void send_gen_power_level_status(struct bt_mesh_model *model, if (publish == false) { msg = bt_mesh_alloc_buf(length + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } } else { @@ -973,7 +973,7 @@ static void send_gen_power_level_status(struct bt_mesh_model *model, } break; default: - BT_WARN("%s, Unknown Generic Power status opcode 0x%04x", __func__, opcode); + BT_WARN("Unknown Generic Power status opcode 0x%04x", opcode); if (publish == false) { bt_mesh_free_buf(msg); } @@ -997,7 +997,7 @@ static void gen_power_level_get(struct bt_mesh_model *model, u16_t opcode = 0U; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1022,7 +1022,7 @@ static void gen_power_level_get(struct bt_mesh_model *model, opcode = BLE_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS; break; default: - BT_WARN("%s, Unknown Generic Power Get opcode 0x%04x", __func__, ctx->recv_op); + BT_WARN("Unknown Generic Power Get opcode 0x%04x", ctx->recv_op); return; } @@ -1033,7 +1033,7 @@ static void gen_power_level_get(struct bt_mesh_model *model, void gen_power_level_publish(struct bt_mesh_model *model, u16_t opcode) { if (model->user_data == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1041,7 +1041,7 @@ void gen_power_level_publish(struct bt_mesh_model *model, u16_t opcode) case BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV: { struct bt_mesh_gen_power_level_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Generic Power Level Server state", __func__); + BT_ERR("Invalid Generic Power Level Server state"); return; } break; @@ -1049,13 +1049,13 @@ void gen_power_level_publish(struct bt_mesh_model *model, u16_t opcode) case ESP_BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV: { struct bt_mesh_gen_power_level_setup_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Generic Power Level Setup Server state", __func__); + BT_ERR("Invalid Generic Power Level Setup Server state"); return; } break; } default: - BT_ERR("%s, Invalid Generic Power Level Server 0x%04x", __func__, model->id); + BT_ERR("Invalid Generic Power Level Server 0x%04x", model->id); return; } @@ -1074,7 +1074,7 @@ static void gen_power_level_set(struct bt_mesh_model *model, s64_t now = 0; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1182,7 +1182,7 @@ static void gen_power_default_set(struct bt_mesh_model *model, u16_t power = 0U; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1232,7 +1232,7 @@ static void gen_power_range_set(struct bt_mesh_model *model, u16_t range_min = 0U, range_max = 0U; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1240,8 +1240,8 @@ static void gen_power_range_set(struct bt_mesh_model *model, range_max = net_buf_simple_pull_le16(buf); if (range_min > range_max) { - BT_ERR("%s, Range Min 0x%04x is greater than Range Max 0x%04x", - __func__, range_min, range_max); + BT_ERR("Range min 0x%04x is greater than range max 0x%04x", + range_min, range_max); return; } @@ -1296,7 +1296,7 @@ static void gen_battery_get(struct bt_mesh_model *model, NET_BUF_SIMPLE_DEFINE(msg, 2 + 8 + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (srv == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1331,7 +1331,7 @@ static void send_gen_location_status(struct bt_mesh_model *model, if (publish == false) { msg = bt_mesh_alloc_buf(length + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } } else { @@ -1374,7 +1374,7 @@ static void send_gen_location_status(struct bt_mesh_model *model, } break; default: - BT_WARN("%s, Unknown Generic Location status opcode 0x%04x", __func__, opcode); + BT_WARN("Unknown Generic Location status opcode 0x%04x", opcode); if (publish == false) { bt_mesh_free_buf(msg); } @@ -1398,7 +1398,7 @@ static void gen_location_get(struct bt_mesh_model *model, u16_t opcode = 0U; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1417,7 +1417,7 @@ static void gen_location_get(struct bt_mesh_model *model, opcode = BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS; break; default: - BT_WARN("%s, Unknown Generic Location Get opcode 0x%04x", __func__, ctx->recv_op); + BT_WARN("Unknown Generic Location Get opcode 0x%04x", ctx->recv_op); return; } @@ -1434,7 +1434,7 @@ static void gen_location_set(struct bt_mesh_model *model, u16_t opcode = 0U; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1526,7 +1526,7 @@ static void gen_location_set(struct bt_mesh_model *model, break; } default: - BT_WARN("%s, Unknown Generic Location Set opcode 0x%04x", __func__, ctx->recv_op); + BT_WARN("Unknown Generic Location Set opcode 0x%04x", ctx->recv_op); return; } @@ -1540,8 +1540,8 @@ static void gen_location_set(struct bt_mesh_model *model, } /* Generic User Property Server message handlers */ -struct bt_mesh_generic_property *gen_get_user_property(struct bt_mesh_model *model, - u16_t property_id) +static struct bt_mesh_generic_property *gen_get_user_property(struct bt_mesh_model *model, + u16_t property_id) { struct bt_mesh_gen_user_prop_srv *srv = model->user_data; int i; @@ -1564,13 +1564,13 @@ static void send_gen_user_prop_status(struct bt_mesh_model *model, u16_t length = 0U; if (property_id == BLE_MESH_INVALID_DEVICE_PROPERTY_ID) { - BT_ERR("%s, Invalid User Property ID 0x%04x", __func__, property_id); + BT_ERR("Invalid User Property ID 0x%04x", property_id); return; } property = gen_get_user_property(model, property_id); if (property == NULL) { - BT_WARN("%s, User property 0x%04x not exist", __func__, property_id); + BT_WARN("User property 0x%04x not exists", property_id); length = sizeof(property_id); } else { length = sizeof(property->id) + sizeof(property->user_access) + property->val->len; @@ -1579,7 +1579,7 @@ static void send_gen_user_prop_status(struct bt_mesh_model *model, if (publish == false) { msg = bt_mesh_alloc_buf(1 + length + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } } else { @@ -1622,7 +1622,7 @@ static void gen_user_prop_get(struct bt_mesh_model *model, struct bt_mesh_gen_user_prop_srv *srv = model->user_data; if (srv == NULL || srv->property_count == 0U || srv->properties == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1651,7 +1651,7 @@ static void gen_user_prop_get(struct bt_mesh_model *model, u8_t i; msg = bt_mesh_alloc_buf(1 + srv->property_count * 2 + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } bt_mesh_model_msg_init(msg, BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS); @@ -1671,7 +1671,7 @@ static void gen_user_prop_get(struct bt_mesh_model *model, return; } default: - BT_WARN("%s, Unknown Generic User Property Get opcode 0x%04x", __func__, ctx->recv_op); + BT_WARN("Unknown Generic User Property Get opcode 0x%04x", ctx->recv_op); return; } } @@ -1686,7 +1686,7 @@ static void gen_user_prop_set(struct bt_mesh_model *model, u8_t expect_len = 0U; if (srv == NULL || srv->property_count == 0U || srv->properties == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1720,8 +1720,8 @@ static void gen_user_prop_set(struct bt_mesh_model *model, */ expect_len = bt_mesh_get_dev_prop_len(property_id); if (buf->len != expect_len) { - BT_ERR("%s, Invalid User Property length, ID 0x%04x, expect %d, actual %d", - __func__, property_id, expect_len, buf->len); + BT_ERR("Invalid User Property 0x%04x length, expect %d, actual %d", + property_id, expect_len, buf->len); return; } @@ -1744,8 +1744,8 @@ static void gen_user_prop_set(struct bt_mesh_model *model, } /* Generic Admin Property Server message handlers */ -struct bt_mesh_generic_property *gen_get_admin_property(struct bt_mesh_model *model, - u16_t property_id) +static struct bt_mesh_generic_property *gen_get_admin_property(struct bt_mesh_model *model, + u16_t property_id) { struct bt_mesh_gen_admin_prop_srv *srv = model->user_data; int i; @@ -1768,13 +1768,13 @@ static void send_gen_admin_prop_status(struct bt_mesh_model *model, u16_t length = 0U; if (property_id == BLE_MESH_INVALID_DEVICE_PROPERTY_ID) { - BT_ERR("%s, Invalid User Property ID 0x%04x", __func__, property_id); + BT_ERR("Invalid Admin Property ID 0x%04x", property_id); return; } property = gen_get_admin_property(model, property_id); if (property == NULL) { - BT_WARN("%s, Admin property 0x%04x not exist", __func__, property_id); + BT_WARN("Admin property 0x%04x not exists", property_id); length = sizeof(property_id); } else { length = sizeof(property->id) + sizeof(property->admin_access) + property->val->len; @@ -1783,7 +1783,7 @@ static void send_gen_admin_prop_status(struct bt_mesh_model *model, if (publish == false) { msg = bt_mesh_alloc_buf(1 + length + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } } else { @@ -1821,7 +1821,7 @@ static void gen_admin_prop_get(struct bt_mesh_model *model, struct bt_mesh_gen_admin_prop_srv *srv = model->user_data; if (srv == NULL || srv->property_count == 0U || srv->properties == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1846,7 +1846,7 @@ static void gen_admin_prop_get(struct bt_mesh_model *model, u8_t i = 0U; msg = bt_mesh_alloc_buf(1 + srv->property_count * 2 + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } bt_mesh_model_msg_init(msg, BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS); @@ -1863,7 +1863,7 @@ static void gen_admin_prop_get(struct bt_mesh_model *model, return; } default: - BT_WARN("%s, Unknown Generic Admin Property Get opcode 0x%04x", __func__, ctx->recv_op); + BT_WARN("Unknown Generic Admin Property Get opcode 0x%04x", ctx->recv_op); return; } } @@ -1878,14 +1878,14 @@ static void gen_admin_prop_set(struct bt_mesh_model *model, u8_t access = 0U; if (srv == NULL || srv->property_count == 0U || srv->properties == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } property_id = net_buf_simple_pull_le16(buf); access = net_buf_simple_pull_u8(buf); if (access > ADMIN_ACCESS_READ_WRITE) { - BT_ERR("%s, Invalid Admin Access 0x%02x", __func__, access); + BT_ERR("Invalid Admin Access 0x%02x", access); return; } @@ -1932,8 +1932,8 @@ static void gen_admin_prop_set(struct bt_mesh_model *model, } /* Generic Manufacturer Property Server message handlers */ -struct bt_mesh_generic_property *gen_get_manu_property(struct bt_mesh_model *model, - u16_t property_id) +static struct bt_mesh_generic_property *gen_get_manu_property(struct bt_mesh_model *model, + u16_t property_id) { struct bt_mesh_gen_manu_prop_srv *srv = model->user_data; int i; @@ -1956,13 +1956,13 @@ static void send_gen_manu_prop_status(struct bt_mesh_model *model, u16_t length = 0U; if (property_id == BLE_MESH_INVALID_DEVICE_PROPERTY_ID) { - BT_ERR("%s, Invalid User Property ID 0x%04x", __func__, property_id); + BT_ERR("Invalid Manu Property ID 0x%04x", property_id); return; } property = gen_get_manu_property(model, property_id); if (property == NULL) { - BT_WARN("%s, Manufacturer property 0x%04x not exist", __func__, property_id); + BT_WARN("Manu property 0x%04x not exists", property_id); length = sizeof(property_id); } else { length = sizeof(property->id) + sizeof(property->manu_access) + property->val->len; @@ -1971,7 +1971,7 @@ static void send_gen_manu_prop_status(struct bt_mesh_model *model, if (publish == false) { msg = bt_mesh_alloc_buf(1 + length + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } } else { @@ -2006,7 +2006,7 @@ static void gen_manu_prop_get(struct bt_mesh_model *model, struct bt_mesh_gen_manu_prop_srv *srv = model->user_data; if (srv == NULL || srv->property_count == 0U || srv->properties == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -2031,7 +2031,7 @@ static void gen_manu_prop_get(struct bt_mesh_model *model, u8_t i = 0U; msg = bt_mesh_alloc_buf(1 + srv->property_count * 2 + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } bt_mesh_model_msg_init(msg, BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS); @@ -2048,7 +2048,7 @@ static void gen_manu_prop_get(struct bt_mesh_model *model, return; } default: - BT_WARN("%s, Unknown Generic Manufacturer Property Get opcode 0x%04x", __func__, ctx->recv_op); + BT_WARN("Unknown Generic Manu Property Get opcode 0x%04x", ctx->recv_op); return; } } @@ -2063,14 +2063,14 @@ static void gen_manu_prop_set(struct bt_mesh_model *model, u8_t access = 0U; if (srv == NULL || srv->property_count == 0U || srv->properties == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } property_id = net_buf_simple_pull_le16(buf); access = net_buf_simple_pull_u8(buf); if (access > MANU_ACCESS_READ) { - BT_ERR("%s, Invalid Manufacturer Access 0x%02x", __func__, access); + BT_ERR("Invalid Manu Access 0x%02x", access); return; } @@ -2153,7 +2153,7 @@ static void gen_client_prop_get(struct bt_mesh_model *model, int i, index = 0; if (srv == NULL || srv->id_count == 0U || srv->property_ids == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -2184,7 +2184,7 @@ static void gen_client_prop_get(struct bt_mesh_model *model, sdu = bt_mesh_alloc_buf(MIN(BLE_MESH_TX_SDU_MAX, BLE_MESH_SERVER_RSP_MAX_LEN)); if (sdu == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } @@ -2336,7 +2336,7 @@ static inline int property_id_compare(const void *p1, const void *p2) static int generic_server_init(struct bt_mesh_model *model) { if (model->user_data == NULL) { - BT_ERR("%s, No Generic Server context provided, model_id 0x%04x", __func__, model->id); + BT_ERR("Invalid Generic Server user data, model id 0x%04x", model->id); return -EINVAL; } @@ -2367,7 +2367,7 @@ static int generic_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV: { struct bt_mesh_gen_power_onoff_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Generic OnPowerUp State", __func__); + BT_ERR("Invalid Generic OnPowerUp State"); return -EINVAL; } srv->model = model; @@ -2376,7 +2376,7 @@ static int generic_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV: { struct bt_mesh_gen_power_onoff_setup_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Generic OnPowerUp State", __func__); + BT_ERR("Invalid Generic OnPowerUp State"); return -EINVAL; } srv->model = model; @@ -2385,7 +2385,7 @@ static int generic_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV: { struct bt_mesh_gen_power_level_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Generic Power Level State", __func__); + BT_ERR("Invalid Generic Power Level State"); return -EINVAL; } if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) { @@ -2398,7 +2398,7 @@ static int generic_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV: { struct bt_mesh_gen_power_level_setup_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Generic Power Level State", __func__); + BT_ERR("Invalid Generic Power Level State"); return -EINVAL; } srv->model = model; @@ -2412,7 +2412,7 @@ static int generic_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_GEN_LOCATION_SRV: { struct bt_mesh_gen_location_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Generic Location State", __func__); + BT_ERR("Invalid Generic Location State"); return -EINVAL; } srv->model = model; @@ -2421,7 +2421,7 @@ static int generic_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_GEN_LOCATION_SETUP_SRV: { struct bt_mesh_gen_location_setup_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Generic Location State", __func__); + BT_ERR("Invalid Generic Location State"); return -EINVAL; } srv->model = model; @@ -2430,7 +2430,7 @@ static int generic_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_GEN_USER_PROP_SRV: { struct bt_mesh_gen_user_prop_srv *srv = model->user_data; if (srv->property_count == 0U || srv->properties == NULL) { - BT_ERR("%s, NULL Generic User Property State", __func__); + BT_ERR("Invalid Generic User Property State"); return -EINVAL; } srv->model = model; @@ -2439,7 +2439,7 @@ static int generic_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV: { struct bt_mesh_gen_admin_prop_srv *srv = model->user_data; if (srv->property_count == 0U || srv->properties == NULL) { - BT_ERR("%s, NULL Generic Admin Property State", __func__); + BT_ERR("Invalid Generic Admin Property State"); return -EINVAL; } srv->model = model; @@ -2448,7 +2448,7 @@ static int generic_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV: { struct bt_mesh_gen_manu_prop_srv *srv = model->user_data; if (srv->property_count == 0U || srv->properties == NULL) { - BT_ERR("%s, NULL Generic Manufacturer Property State", __func__); + BT_ERR("Invalid Generic Manufacturer Property State"); return -EINVAL; } srv->model = model; @@ -2457,7 +2457,7 @@ static int generic_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV: { struct bt_mesh_gen_client_prop_srv *srv = model->user_data; if (srv->id_count == 0U || srv->property_ids == NULL) { - BT_ERR("%s, NULL Generic Client Property State", __func__); + BT_ERR("Invalid Generic Client Property State"); return -EINVAL; } /* Quick sort the Client Property IDs in ascending order */ @@ -2466,7 +2466,7 @@ static int generic_server_init(struct bt_mesh_model *model) break; } default: - BT_WARN("%s, Unknown Generic Server Model, model_id 0x%04x", __func__, model->id); + BT_WARN("Unknown Generic Server, model id 0x%04x", model->id); return -EINVAL; } @@ -2478,7 +2478,7 @@ static int generic_server_init(struct bt_mesh_model *model) int bt_mesh_gen_onoff_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic OnOff Server has no publication support", __func__); + BT_ERR("Generic OnOff Server has no publication support"); return -EINVAL; } @@ -2488,7 +2488,7 @@ int bt_mesh_gen_onoff_srv_init(struct bt_mesh_model *model, bool primary) int bt_mesh_gen_level_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic Level Server has no publication support", __func__); + BT_ERR("Generic Level Server has no publication support"); return -EINVAL; } @@ -2498,7 +2498,7 @@ int bt_mesh_gen_level_srv_init(struct bt_mesh_model *model, bool primary) int bt_mesh_gen_def_trans_time_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic Default Trans Time Server has no publication support", __func__); + BT_ERR("Generic Default Trans Time Server has no publication support"); return -EINVAL; } @@ -2508,7 +2508,7 @@ int bt_mesh_gen_def_trans_time_srv_init(struct bt_mesh_model *model, bool primar int bt_mesh_gen_power_onoff_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic Power OnOff Server has no publication support", __func__); + BT_ERR("Generic Power OnOff Server has no publication support"); return -EINVAL; } @@ -2517,7 +2517,7 @@ int bt_mesh_gen_power_onoff_srv_init(struct bt_mesh_model *model, bool primary) */ struct bt_mesh_elem *element = bt_mesh_model_elem(model); if (bt_mesh_model_find(element, BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV) == NULL) { - BT_WARN("%s, Generic Power OnOff Setup Server is not present", __func__); + BT_WARN("Generic Power OnOff Setup Server not present"); /* Just give a warning here, continue with the initialization */ } return generic_server_init(model); @@ -2531,7 +2531,7 @@ int bt_mesh_gen_power_onoff_setup_srv_init(struct bt_mesh_model *model, bool pri int bt_mesh_gen_power_level_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic Power Level Server has no publication support", __func__); + BT_ERR("Generic Power Level Server has no publication support"); return -EINVAL; } @@ -2540,7 +2540,7 @@ int bt_mesh_gen_power_level_srv_init(struct bt_mesh_model *model, bool primary) */ struct bt_mesh_elem *element = bt_mesh_model_elem(model); if (bt_mesh_model_find(element, BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV) == NULL) { - BT_WARN("%s, Generic Power Level Setup Server is not present", __func__); + BT_WARN("Generic Power Level Setup Server not present"); /* Just give a warning here, continue with the initialization */ } return generic_server_init(model); @@ -2554,7 +2554,7 @@ int bt_mesh_gen_power_level_setup_srv_init(struct bt_mesh_model *model, bool pri int bt_mesh_gen_battery_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic Battery Server has no publication support", __func__); + BT_ERR("Generic Battery Server has no publication support"); return -EINVAL; } @@ -2564,7 +2564,7 @@ int bt_mesh_gen_battery_srv_init(struct bt_mesh_model *model, bool primary) int bt_mesh_gen_location_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic Location Server has no publication support", __func__); + BT_ERR("Generic Location Server has no publication support"); return -EINVAL; } @@ -2578,7 +2578,7 @@ int bt_mesh_gen_location_setup_srv_init(struct bt_mesh_model *model, bool primar */ struct bt_mesh_elem *element = bt_mesh_model_elem(model); if (bt_mesh_model_find(element, BLE_MESH_MODEL_ID_GEN_LOCATION_SETUP_SRV) == NULL) { - BT_WARN("%s, Generic Location Setup Server is not present", __func__); + BT_WARN("Generic Location Setup Server not present"); /* Just give a warning here, continue with the initialization */ } return generic_server_init(model); @@ -2587,7 +2587,7 @@ int bt_mesh_gen_location_setup_srv_init(struct bt_mesh_model *model, bool primar int bt_mesh_gen_user_prop_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic User Property has no publication support", __func__); + BT_ERR("Generic User Property Server has no publication support"); return -EINVAL; } @@ -2597,7 +2597,7 @@ int bt_mesh_gen_user_prop_srv_init(struct bt_mesh_model *model, bool primary) int bt_mesh_gen_admin_prop_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic Admin Property has no publication support", __func__); + BT_ERR("Generic Admin Property Server has no publication support"); return -EINVAL; } @@ -2607,7 +2607,7 @@ int bt_mesh_gen_admin_prop_srv_init(struct bt_mesh_model *model, bool primary) int bt_mesh_gen_manu_prop_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic Manufacturer Property has no publication support", __func__); + BT_ERR("Generic Manufacturer Property Server has no publication support"); return -EINVAL; } @@ -2617,7 +2617,7 @@ int bt_mesh_gen_manu_prop_srv_init(struct bt_mesh_model *model, bool primary) int bt_mesh_gen_client_prop_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic Client Property has no publication support", __func__); + BT_ERR("Generic Client Property Server has no publication support"); return -EINVAL; } @@ -2627,7 +2627,7 @@ int bt_mesh_gen_client_prop_srv_init(struct bt_mesh_model *model, bool primary) static int generic_server_deinit(struct bt_mesh_model *model) { if (model->user_data == NULL) { - BT_ERR("%s, No Generic Server context provided, model_id 0x%04x", __func__, model->id); + BT_ERR("Invalid Generic Server user data, model id 0x%04x", model->id); return -EINVAL; } @@ -2651,7 +2651,7 @@ static int generic_server_deinit(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV: { struct bt_mesh_gen_power_level_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Generic Power Level State", __func__); + BT_ERR("Invalid Generic Power Level State"); return -EINVAL; } if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) { @@ -2661,7 +2661,7 @@ static int generic_server_deinit(struct bt_mesh_model *model) break; } default: - BT_WARN("%s, Unknown Generic Server Model, model_id 0x%04x", __func__, model->id); + BT_WARN("Unknown Generic Server, model id 0x%04x", model->id); return -EINVAL; } @@ -2673,7 +2673,7 @@ static int generic_server_deinit(struct bt_mesh_model *model) int bt_mesh_gen_onoff_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic OnOff Server has no publication support", __func__); + BT_ERR("Generic OnOff Server has no publication support"); return -EINVAL; } @@ -2683,7 +2683,7 @@ int bt_mesh_gen_onoff_srv_deinit(struct bt_mesh_model *model, bool primary) int bt_mesh_gen_level_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic Level Server has no publication support", __func__); + BT_ERR("Generic Level Server has no publication support"); return -EINVAL; } @@ -2693,7 +2693,7 @@ int bt_mesh_gen_level_srv_deinit(struct bt_mesh_model *model, bool primary) int bt_mesh_gen_def_trans_time_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic Default Trans Time Server has no publication support", __func__); + BT_ERR("Generic Default Trans Time Server has no publication support"); return -EINVAL; } @@ -2703,7 +2703,7 @@ int bt_mesh_gen_def_trans_time_srv_deinit(struct bt_mesh_model *model, bool prim int bt_mesh_gen_power_onoff_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic Power OnOff Server has no publication support", __func__); + BT_ERR("Generic Power OnOff Server has no publication support"); return -EINVAL; } @@ -2718,7 +2718,7 @@ int bt_mesh_gen_power_onoff_setup_srv_deinit(struct bt_mesh_model *model, bool p int bt_mesh_gen_power_level_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic Power Level Server has no publication support", __func__); + BT_ERR("Generic Power Level Server has no publication support"); return -EINVAL; } @@ -2733,7 +2733,7 @@ int bt_mesh_gen_power_level_setup_srv_deinit(struct bt_mesh_model *model, bool p int bt_mesh_gen_battery_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic Battery Server has no publication support", __func__); + BT_ERR("Generic Battery Server has no publication support"); return -EINVAL; } @@ -2743,7 +2743,7 @@ int bt_mesh_gen_battery_srv_deinit(struct bt_mesh_model *model, bool primary) int bt_mesh_gen_location_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic Location Server has no publication support", __func__); + BT_ERR("Generic Location Server has no publication support"); return -EINVAL; } @@ -2758,7 +2758,7 @@ int bt_mesh_gen_location_setup_srv_deinit(struct bt_mesh_model *model, bool prim int bt_mesh_gen_user_prop_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic User Property has no publication support", __func__); + BT_ERR("Generic User Property Server has no publication support"); return -EINVAL; } @@ -2768,7 +2768,7 @@ int bt_mesh_gen_user_prop_srv_deinit(struct bt_mesh_model *model, bool primary) int bt_mesh_gen_admin_prop_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic Admin Property has no publication support", __func__); + BT_ERR("Generic Admin Property Server has no publication support"); return -EINVAL; } @@ -2778,7 +2778,7 @@ int bt_mesh_gen_admin_prop_srv_deinit(struct bt_mesh_model *model, bool primary) int bt_mesh_gen_manu_prop_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic Manufacturer Property has no publication support", __func__); + BT_ERR("Generic Manufacturer Property Server has no publication support"); return -EINVAL; } @@ -2788,7 +2788,7 @@ int bt_mesh_gen_manu_prop_srv_deinit(struct bt_mesh_model *model, bool primary) int bt_mesh_gen_client_prop_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Generic Client Property has no publication support", __func__); + BT_ERR("Generic Client Property Server has no publication support"); return -EINVAL; } diff --git a/components/bt/esp_ble_mesh/mesh_models/server/lighting_server.c b/components/bt/esp_ble_mesh/mesh_models/server/lighting_server.c index e3d6e51e9..f09224c7b 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/lighting_server.c +++ b/components/bt/esp_ble_mesh/mesh_models/server/lighting_server.c @@ -59,7 +59,7 @@ static void send_light_lightness_status(struct bt_mesh_model *model, if (publish == false) { msg = bt_mesh_alloc_buf(length + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } } else { @@ -119,7 +119,7 @@ static void send_light_lightness_status(struct bt_mesh_model *model, } break; default: - BT_WARN("%s, Unknown Light Lightness status opcode 0x%04x", __func__, opcode); + BT_WARN("Unknown Light Lightness status opcode 0x%04x", opcode); if (publish == false) { bt_mesh_free_buf(msg); } @@ -143,7 +143,7 @@ static void light_lightness_get(struct bt_mesh_model *model, u16_t opcode = 0U; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -171,7 +171,7 @@ static void light_lightness_get(struct bt_mesh_model *model, opcode = BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS; break; default: - BT_WARN("%s, Unknown Light Lightness Get opcode 0x%04x", __func__, ctx->recv_op); + BT_WARN("Unknown Light Lightness Get opcode 0x%04x", ctx->recv_op); return; } @@ -182,7 +182,7 @@ static void light_lightness_get(struct bt_mesh_model *model, void light_lightness_publish(struct bt_mesh_model *model, u16_t opcode) { if (model->user_data == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -190,7 +190,7 @@ void light_lightness_publish(struct bt_mesh_model *model, u16_t opcode) case BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV: { struct bt_mesh_light_lightness_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light Lightness Server state", __func__); + BT_ERR("Invalid Light Lightness Server state"); return; } break; @@ -198,13 +198,13 @@ void light_lightness_publish(struct bt_mesh_model *model, u16_t opcode) case BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV: { struct bt_mesh_light_lightness_setup_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light Lightness Setup Server state", __func__); + BT_ERR("Invalid Light Lightness Setup Server state"); return; } break; } default: - BT_ERR("%s, Invalid Light Lightness Server Model 0x%04x", __func__, model->id); + BT_ERR("Invalid Light Lightness Server model 0x%04x", model->id); return; } @@ -223,7 +223,7 @@ static void light_lightness_set(struct bt_mesh_model *model, s64_t now = 0; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -335,7 +335,7 @@ static void light_lightness_linear_set(struct bt_mesh_model *model, s64_t now = 0; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -428,7 +428,7 @@ static void light_lightness_default_set(struct bt_mesh_model *model, u16_t lightness = 0U; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -470,7 +470,7 @@ static void light_lightness_range_set(struct bt_mesh_model *model, u16_t range_min = 0U, range_max = 0U; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -478,8 +478,8 @@ static void light_lightness_range_set(struct bt_mesh_model *model, range_max = net_buf_simple_pull_le16(buf); if (range_min > range_max) { - BT_ERR("%s, Range Min 0x%04x is greater than Range Max 0x%04x", - __func__, range_min, range_max); + BT_ERR("Range min 0x%04x is greater than range max 0x%04x", + range_min, range_max); return; } @@ -556,7 +556,7 @@ static void send_light_ctl_status(struct bt_mesh_model *model, if (publish == false) { msg = bt_mesh_alloc_buf(length + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } } else { @@ -620,7 +620,7 @@ static void send_light_ctl_status(struct bt_mesh_model *model, break; } default: - BT_WARN("%s, Unknown Light CTL status opcode 0x%04x", __func__, opcode); + BT_WARN("Unknown Light CTL status opcode 0x%04x", opcode); if (publish == false) { bt_mesh_free_buf(msg); } @@ -644,7 +644,7 @@ static void light_ctl_get(struct bt_mesh_model *model, u16_t opcode = 0U; if (model->user_data == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -652,7 +652,7 @@ static void light_ctl_get(struct bt_mesh_model *model, case BLE_MESH_MODEL_ID_LIGHT_CTL_SRV: { struct bt_mesh_light_ctl_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light CTL Server state", __func__); + BT_ERR("Invalid Light CTL Server state"); return; } rsp_ctrl = &srv->rsp_ctrl; @@ -661,14 +661,14 @@ static void light_ctl_get(struct bt_mesh_model *model, case BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV: { struct bt_mesh_light_ctl_temp_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light CTL Temperature Server state", __func__); + BT_ERR("Invalid Light CTL Temperature Server state"); return; } rsp_ctrl = &srv->rsp_ctrl; break; } default: - BT_ERR("%s, Invalid Light CTL Server Model 0x%04x", __func__, model->id); + BT_ERR("Invalid Light CTL Server model 0x%04x", model->id); return; } @@ -693,7 +693,7 @@ static void light_ctl_get(struct bt_mesh_model *model, opcode = BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS; break; default: - BT_WARN("%s, Unknown Light CTL Get opcode 0x%04x", __func__, ctx->recv_op); + BT_WARN("Unknown Light CTL Get opcode 0x%04x", ctx->recv_op); return; } @@ -704,7 +704,7 @@ static void light_ctl_get(struct bt_mesh_model *model, void light_ctl_publish(struct bt_mesh_model *model, u16_t opcode) { if (model->user_data == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -712,7 +712,7 @@ void light_ctl_publish(struct bt_mesh_model *model, u16_t opcode) case BLE_MESH_MODEL_ID_LIGHT_CTL_SRV: { struct bt_mesh_light_ctl_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light CTL Server state", __func__); + BT_ERR("Invalid Light CTL Server state"); return; } break; @@ -720,7 +720,7 @@ void light_ctl_publish(struct bt_mesh_model *model, u16_t opcode) case BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV: { struct bt_mesh_light_ctl_temp_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light CTL Temperature Server state", __func__); + BT_ERR("Invalid Light CTL Temperature Server state"); return; } break; @@ -728,13 +728,13 @@ void light_ctl_publish(struct bt_mesh_model *model, u16_t opcode) case BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV: { struct bt_mesh_light_ctl_setup_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light CTL Setup Server state", __func__); + BT_ERR("Invalid Light CTL Setup Server state"); return; } break; } default: - BT_ERR("%s, Invalid Light CTL Server Model 0x%04x", __func__, model->id); + BT_ERR("Invalid Light CTL Server model 0x%04x", model->id); return; } @@ -754,7 +754,7 @@ static void light_ctl_set(struct bt_mesh_model *model, s64_t now = 0; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -764,7 +764,7 @@ static void light_ctl_set(struct bt_mesh_model *model, tid = net_buf_simple_pull_u8(buf); if (temperature < BLE_MESH_TEMPERATURE_MIN || temperature > BLE_MESH_TEMPERATURE_MAX) { - BT_ERR("%s, Invalid temperature 0x%04x", __func__, temperature); + BT_ERR("Invalid temperature 0x%04x", temperature); return; } @@ -870,7 +870,7 @@ static void light_ctl_default_set(struct bt_mesh_model *model, s16_t delta_uv = 0; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -879,7 +879,7 @@ static void light_ctl_default_set(struct bt_mesh_model *model, delta_uv = (s16_t) net_buf_simple_pull_le16(buf); if (temperature < BLE_MESH_TEMPERATURE_MIN || temperature > BLE_MESH_TEMPERATURE_MAX) { - BT_ERR("%s, Invalid temperature 0x%04x", __func__, temperature); + BT_ERR("Invalid temperature 0x%04x", temperature); return; } @@ -933,7 +933,7 @@ static void light_ctl_temp_range_set(struct bt_mesh_model *model, u16_t min = 0U, max = 0U; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -944,8 +944,8 @@ static void light_ctl_temp_range_set(struct bt_mesh_model *model, if (min > max || min < BLE_MESH_TEMPERATURE_MIN || (min != BLE_MESH_TEMPERATURE_UNKNOWN && min > BLE_MESH_TEMPERATURE_MAX) || max < BLE_MESH_TEMPERATURE_MIN || (max != BLE_MESH_TEMPERATURE_UNKNOWN && max > BLE_MESH_TEMPERATURE_MAX)) { - BT_ERR("%s, Invalid parameter, range Min 0x%04x, range max 0x%04x", - __func__, min, max); + BT_ERR("Invalid parameter, range min 0x%04x, range max 0x%04x", + min, max); return; } @@ -1003,7 +1003,7 @@ static void light_ctl_temp_set(struct bt_mesh_model *model, s64_t now = 0; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1012,7 +1012,7 @@ static void light_ctl_temp_set(struct bt_mesh_model *model, tid = net_buf_simple_pull_u8(buf); if (temperature < BLE_MESH_TEMPERATURE_MIN || temperature > BLE_MESH_TEMPERATURE_MAX) { - BT_ERR("%s, Invalid temperature 0x%04x", __func__, temperature); + BT_ERR("Invalid temperature 0x%04x", temperature); return; } @@ -1121,7 +1121,7 @@ static void send_light_hsl_status(struct bt_mesh_model *model, if (publish == false) { msg = bt_mesh_alloc_buf(length + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } } else { @@ -1206,7 +1206,7 @@ static void send_light_hsl_status(struct bt_mesh_model *model, break; } default: - BT_WARN("%s, Unknown Light HSL status opcode 0x%04x", __func__, opcode); + BT_WARN("Unknown Light HSL status opcode 0x%04x", opcode); if (publish == false) { bt_mesh_free_buf(msg); } @@ -1230,7 +1230,7 @@ static void light_hsl_get(struct bt_mesh_model *model, u16_t opcode = 0U; if (model->user_data == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1238,7 +1238,7 @@ static void light_hsl_get(struct bt_mesh_model *model, case BLE_MESH_MODEL_ID_LIGHT_HSL_SRV: { struct bt_mesh_light_hsl_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light HSL Server state", __func__); + BT_ERR("Invalid Light HSL Server state"); return; } rsp_ctrl = &srv->rsp_ctrl; @@ -1247,7 +1247,7 @@ static void light_hsl_get(struct bt_mesh_model *model, case BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV: { struct bt_mesh_light_hsl_hue_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light HSL Hue Server state", __func__); + BT_ERR("Invalid Light HSL Hue Server state"); return; } rsp_ctrl = &srv->rsp_ctrl; @@ -1256,14 +1256,14 @@ static void light_hsl_get(struct bt_mesh_model *model, case BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV: { struct bt_mesh_light_hsl_sat_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light HSL Saturation Server state", __func__); + BT_ERR("Invalid Light HSL Saturation Server state"); return; } rsp_ctrl = &srv->rsp_ctrl; break; } default: - BT_ERR("%s, Invalid Light HSL Server Model 0x%04x", __func__, model->id); + BT_ERR("Invalid Light HSL Server model 0x%04x", model->id); return; } @@ -1294,7 +1294,7 @@ static void light_hsl_get(struct bt_mesh_model *model, opcode = BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS; break; default: - BT_WARN("%s, Unknown Light HSL Get opcode 0x%04x", __func__, ctx->recv_op); + BT_WARN("Unknown Light HSL Get opcode 0x%04x", ctx->recv_op); return; } @@ -1305,7 +1305,7 @@ static void light_hsl_get(struct bt_mesh_model *model, void light_hsl_publish(struct bt_mesh_model *model, u16_t opcode) { if (model->user_data == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1313,7 +1313,7 @@ void light_hsl_publish(struct bt_mesh_model *model, u16_t opcode) case BLE_MESH_MODEL_ID_LIGHT_HSL_SRV: { struct bt_mesh_light_hsl_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light HSL Server state", __func__); + BT_ERR("Invalid Light HSL Server state"); return; } break; @@ -1321,7 +1321,7 @@ void light_hsl_publish(struct bt_mesh_model *model, u16_t opcode) case BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV: { struct bt_mesh_light_hsl_hue_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light HSL Hue Server state", __func__); + BT_ERR("Invalid Light HSL Hue Server state"); return; } break; @@ -1329,7 +1329,7 @@ void light_hsl_publish(struct bt_mesh_model *model, u16_t opcode) case BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV: { struct bt_mesh_light_hsl_sat_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light HSL Saturation Server state", __func__); + BT_ERR("Invalid Light HSL Saturation Server state"); return; } break; @@ -1337,13 +1337,13 @@ void light_hsl_publish(struct bt_mesh_model *model, u16_t opcode) case BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV: { struct bt_mesh_light_hsl_setup_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light HSL Setup Server state", __func__); + BT_ERR("Invalid Light HSL Setup Server state"); return; } break; } default: - BT_ERR("%s, Invalid Light HSL Server Model 0x%04x", __func__, model->id); + BT_ERR("Invalid Light HSL Server model 0x%04x", model->id); return; } @@ -1362,7 +1362,7 @@ static void light_hsl_set(struct bt_mesh_model *model, s64_t now = 0; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1477,7 +1477,7 @@ static void light_hsl_default_set(struct bt_mesh_model *model, u16_t lightness = 0U, hue = 0U, saturation = 0U; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1537,7 +1537,7 @@ static void light_hsl_range_set(struct bt_mesh_model *model, u16_t hue_min = 0U, hue_max = 0U, saturation_min = 0U, saturation_max = 0U; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1547,14 +1547,14 @@ static void light_hsl_range_set(struct bt_mesh_model *model, saturation_max = net_buf_simple_pull_le16(buf); if (hue_min > hue_max) { - BT_ERR("%s, Invalid parameter, Hue min 0x%04x, Hue max 0x%04x", - __func__, hue_min, hue_max); + BT_ERR("Invalid parameter, hue min 0x%04x, hue max 0x%04x", + hue_min, hue_max); return; } if (saturation_min > saturation_max) { - BT_ERR("%s, Invalid parameter, Saturation min 0x%04x, Saturation max 0x%04x", - __func__, hue_min, hue_max); + BT_ERR("Invalid parameter, saturation min 0x%04x, saturation max 0x%04x", + saturation_min, saturation_max); return; } @@ -1605,7 +1605,7 @@ static void light_hsl_hue_set(struct bt_mesh_model *model, s64_t now = 0; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1706,7 +1706,7 @@ static void light_hsl_sat_set(struct bt_mesh_model *model, s64_t now = 0; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1813,7 +1813,7 @@ static void send_light_xyl_status(struct bt_mesh_model *model, if (publish == false) { msg = bt_mesh_alloc_buf(length + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } } else { @@ -1878,7 +1878,7 @@ static void send_light_xyl_status(struct bt_mesh_model *model, } break; default: - BT_WARN("%s, Unknown Light xyL status opcode 0x%04x", __func__, opcode); + BT_WARN("Unknown Light xyL status opcode 0x%04x", opcode); if (publish == false) { bt_mesh_free_buf(msg); } @@ -1902,7 +1902,7 @@ static void light_xyl_get(struct bt_mesh_model *model, u16_t opcode = 0U; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1927,7 +1927,7 @@ static void light_xyl_get(struct bt_mesh_model *model, opcode = BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_STATUS; break; default: - BT_WARN("%s, Unknown Light xyL Get opcode 0x%04x", __func__, ctx->recv_op); + BT_WARN("Unknown Light xyL Get opcode 0x%04x", ctx->recv_op); return; } @@ -1938,7 +1938,7 @@ static void light_xyl_get(struct bt_mesh_model *model, void light_xyl_publish(struct bt_mesh_model *model, u16_t opcode) { if (model->user_data == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1946,7 +1946,7 @@ void light_xyl_publish(struct bt_mesh_model *model, u16_t opcode) case BLE_MESH_MODEL_ID_LIGHT_XYL_SRV: { struct bt_mesh_light_xyl_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light xyL Server state", __func__); + BT_ERR("Invalid Light xyL Server state"); return; } break; @@ -1954,13 +1954,13 @@ void light_xyl_publish(struct bt_mesh_model *model, u16_t opcode) case BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV: { struct bt_mesh_light_xyl_setup_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light xyL Setup Server state", __func__); + BT_ERR("Invalid Light xyL Setup Server state"); return; } break; } default: - BT_ERR("%s, Invalid Light xyL Server Model 0x%04x", __func__, model->id); + BT_ERR("Invalid Light xyL Server model 0x%04x", model->id); return; } @@ -1979,7 +1979,7 @@ static void light_xyl_set(struct bt_mesh_model *model, s64_t now = 0; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -2094,7 +2094,7 @@ static void light_xyl_default_set(struct bt_mesh_model *model, u16_t lightness = 0U, x = 0U, y = 0U; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -2154,7 +2154,7 @@ static void light_xyl_range_set(struct bt_mesh_model *model, u16_t x_min = 0U, x_max = 0U, y_min = 0U, y_max = 0U; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -2164,14 +2164,14 @@ static void light_xyl_range_set(struct bt_mesh_model *model, y_max = net_buf_simple_pull_le16(buf); if (x_min > x_max) { - BT_ERR("%s, Invalid parameter, xyL x min 0x%04x, xyL x max 0x%04x", - __func__, x_min, x_max); + BT_ERR("Invalid parameter, x min 0x%04x, x max 0x%04x", + x_min, x_max); return; } if (y_min > y_max) { - BT_ERR("%s, Invalid parameter, xyL y min 0x%04x, xyL y max 0x%04x", - __func__, y_min, y_max); + BT_ERR("Invalid parameter, y min 0x%04x, y max 0x%04x", + y_min, y_max); return; } @@ -2228,7 +2228,7 @@ static void send_light_lc_status(struct bt_mesh_model *model, if (publish == false) { msg = bt_mesh_alloc_buf(length + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } } else { @@ -2255,7 +2255,7 @@ static void send_light_lc_status(struct bt_mesh_model *model, } break; default: - BT_WARN("%s, Unknown Light LC status opcode 0x%04x", __func__, opcode); + BT_WARN("Unknown Light LC status opcode 0x%04x", opcode); if (publish == false) { bt_mesh_free_buf(msg); } @@ -2279,7 +2279,7 @@ static void light_lc_get(struct bt_mesh_model *model, u16_t opcode = 0U; if (srv == NULL || srv->lc == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -2301,7 +2301,7 @@ static void light_lc_get(struct bt_mesh_model *model, opcode = BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS; break; default: - BT_WARN("%s, Unknown Light LC Get opcode 0x%04x", __func__, ctx->recv_op); + BT_WARN("Unknown Light LC Get opcode 0x%04x", ctx->recv_op); return; } @@ -2314,7 +2314,7 @@ void light_lc_publish(struct bt_mesh_model *model, u16_t opcode) struct bt_mesh_light_lc_srv *srv = model->user_data; if (srv == NULL || srv->lc == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -2330,13 +2330,13 @@ static void light_lc_mode_set(struct bt_mesh_model *model, u8_t mode = 0U; if (srv == NULL || srv->lc == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } mode = net_buf_simple_pull_u8(buf); if (mode > BLE_MESH_STATE_ON) { - BT_ERR("%s, Invalid LC Mode 0x%02x", __func__, mode); + BT_ERR("Invalid LC Mode 0x%02x", mode); return; } @@ -2374,13 +2374,13 @@ static void light_lc_om_set(struct bt_mesh_model *model, u8_t om = 0U; if (srv == NULL || srv->lc == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } om = net_buf_simple_pull_u8(buf); if (om > BLE_MESH_STATE_ON) { - BT_ERR("%s, Invalid LC Occupancy Mode 0x%02x", __func__, om); + BT_ERR("Invalid LC Occupancy Mode 0x%02x", om); return; } @@ -2421,7 +2421,7 @@ static void light_lc_light_onoff_set(struct bt_mesh_model *model, s64_t now = 0; if (srv == NULL || srv->lc == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -2537,7 +2537,7 @@ static void light_lc_sensor_status(struct bt_mesh_model *model, u8_t length = 0U; if (srv == NULL || srv->lc == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -2565,7 +2565,7 @@ static void light_lc_sensor_status(struct bt_mesh_model *model, switch (prop_id) { case BLE_MESH_MOTION_SENSED: { if (length != BLE_MESH_MOTION_SENSED_LEN || length != buf->len) { - BT_WARN("%s, Invalid Motion Sensed Property length", __func__); + BT_WARN("Invalid Motion Sensed Property length %d", length); return; } u8_t val = net_buf_simple_pull_u8(buf); @@ -2580,7 +2580,7 @@ static void light_lc_sensor_status(struct bt_mesh_model *model, } case BLE_MESH_PEOPLE_COUNT: { if (length != BLE_MESH_PEOPLE_COUNT_LEN || length != buf->len) { - BT_WARN("%s, Invalid Motion Sensed Property length", __func__); + BT_WARN("Invalid Motion Sensed Property length %d", length); return; } u16_t val = net_buf_simple_pull_le16(buf); @@ -2595,7 +2595,7 @@ static void light_lc_sensor_status(struct bt_mesh_model *model, } case BLE_MESH_PRESENCE_DETECTED: { if (length != BLE_MESH_PRESENCE_DETECTED_LEN || length != buf->len) { - BT_WARN("%s, Invalid Motion Sensed Property length", __func__); + BT_WARN("Invalid Motion Sensed Property length %d", length); return; } u8_t val = net_buf_simple_pull_u8(buf); @@ -2610,7 +2610,7 @@ static void light_lc_sensor_status(struct bt_mesh_model *model, } case BLE_MESH_TIME_SINCE_MOTION_SENSED: { if (length != BLE_MESH_TIME_SINCE_MOTION_SENSED_LEN || length != buf->len) { - BT_WARN("%s, Invalid Motion Sensed Property length", __func__); + BT_WARN("Invalid Motion Sensed Property length %d", length); return; } u16_t val = net_buf_simple_pull_le16(buf); @@ -2632,7 +2632,7 @@ static void light_lc_sensor_status(struct bt_mesh_model *model, * Here we just check if the length is larger than 3. */ if (buf->len < 3) { - BT_WARN("%s, Invalid Motion Sensed Property length", __func__); + BT_WARN("Invalid Motion Sensed Property length %d", buf->len); return; } u16_t lsb = net_buf_simple_pull_le16(buf); @@ -2734,14 +2734,14 @@ static void send_light_lc_prop_status(struct bt_mesh_model *model, prop_val = get_light_lc_prop_val(model, prop_id); if (prop_val == NULL) { - BT_ERR("%s, Failed to get Light LC Property value", __func__); + BT_ERR("Failed to get Light LC Property value"); return; } if (publish == false) { msg = bt_mesh_alloc_buf(length + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } } else { @@ -2772,13 +2772,13 @@ static void light_lc_prop_get(struct bt_mesh_model *model, u16_t prop_id = 0U; if (srv == NULL || srv->lc == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } prop_id = net_buf_simple_pull_le16(buf); if (prop_id < 0x002B || prop_id > 0x003C) { - BT_ERR("%s, Invalid Light LC Property ID 0x%04x", __func__, prop_id); + BT_ERR("Invalid Light LC Property ID 0x%04x", prop_id); return; } @@ -2805,13 +2805,13 @@ static void light_lc_prop_set(struct bt_mesh_model *model, u16_t prop_id = 0U; if (srv == NULL || srv->lc == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } prop_id = net_buf_simple_pull_le16(buf); if (prop_id < 0x002B || prop_id > 0x003C) { - BT_ERR("%s, Invalid Light LC Property ID 0x%04x", __func__, prop_id); + BT_ERR("Invalid Light LC Property ID 0x%04x", prop_id); return; } @@ -2827,14 +2827,14 @@ static void light_lc_prop_set(struct bt_mesh_model *model, expect_len = bt_mesh_get_dev_prop_len(prop_id); if (buf->len != expect_len) { - BT_ERR("%s, Invalid Light LC Property length, ID 0x%04x, expect %d, actual %d", - __func__, prop_id, expect_len, buf->len); + BT_ERR("Invalid Light LC Property 0x%04x length, expect %d, actual %d", + prop_id, expect_len, buf->len); return; } prop_val = get_light_lc_prop_val(model, prop_id); if (prop_val == NULL) { - BT_ERR("%s, Failed to get Light LC Property value", __func__); + BT_ERR("Failed to get Light LC Property value"); return; } @@ -2989,7 +2989,7 @@ const struct bt_mesh_model_op light_lc_setup_srv_op[] = { static int light_server_init(struct bt_mesh_model *model) { if (model->user_data == NULL) { - BT_ERR("%s, No Light Server context provided, model_id 0x%04x", __func__, model->id); + BT_ERR("Invalid Lighting Server user data, model id 0x%04x", model->id); return -EINVAL; } @@ -2997,7 +2997,7 @@ static int light_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV: { struct bt_mesh_light_lightness_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Light Lightness State", __func__); + BT_ERR("Invalid Light Lightness State"); return -EINVAL; } if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) { @@ -3012,7 +3012,7 @@ static int light_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV: { struct bt_mesh_light_lightness_setup_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Light Lightness State", __func__); + BT_ERR("Invalid Light Lightness State"); return -EINVAL; } srv->model = model; @@ -3021,7 +3021,7 @@ static int light_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_LIGHT_CTL_SRV: { struct bt_mesh_light_ctl_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Light CTL State", __func__); + BT_ERR("Invalid Light CTL State"); return -EINVAL; } if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) { @@ -3034,7 +3034,7 @@ static int light_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV: { struct bt_mesh_light_ctl_setup_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Light CTL State", __func__); + BT_ERR("Invalid Light CTL State"); return -EINVAL; } srv->model = model; @@ -3043,7 +3043,7 @@ static int light_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV: { struct bt_mesh_light_ctl_temp_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Light CTL State", __func__); + BT_ERR("Invalid Light CTL State"); return -EINVAL; } if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) { @@ -3056,7 +3056,7 @@ static int light_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_LIGHT_HSL_SRV: { struct bt_mesh_light_hsl_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Light HSL State", __func__); + BT_ERR("Invalid Light HSL State"); return -EINVAL; } if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) { @@ -3069,7 +3069,7 @@ static int light_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV: { struct bt_mesh_light_hsl_setup_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Light HSL State", __func__); + BT_ERR("Invalid Light HSL State"); return -EINVAL; } srv->model = model; @@ -3078,7 +3078,7 @@ static int light_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV: { struct bt_mesh_light_hsl_hue_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Light HSL State", __func__); + BT_ERR("Invalid Light HSL State"); return -EINVAL; } if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) { @@ -3091,7 +3091,7 @@ static int light_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV: { struct bt_mesh_light_hsl_sat_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Light HSL State", __func__); + BT_ERR("Invalid Light HSL State"); return -EINVAL; } if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) { @@ -3104,7 +3104,7 @@ static int light_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_LIGHT_XYL_SRV: { struct bt_mesh_light_xyl_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Light xyL State", __func__); + BT_ERR("Invalid Light xyL State"); return -EINVAL; } if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) { @@ -3117,7 +3117,7 @@ static int light_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV: { struct bt_mesh_light_xyl_setup_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Light xyL State", __func__); + BT_ERR("Invalid Light xyL State"); return -EINVAL; } srv->model = model; @@ -3126,7 +3126,7 @@ static int light_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_LIGHT_LC_SRV: { struct bt_mesh_light_lc_srv *srv = model->user_data; if (srv->lc == NULL) { - BT_ERR("%s, NULL Light LC State", __func__); + BT_ERR("Invalid Light LC State"); return -EINVAL; } if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) { @@ -3139,14 +3139,14 @@ static int light_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV: { struct bt_mesh_light_lc_setup_srv *srv = model->user_data; if (srv->lc == NULL) { - BT_ERR("%s, NULL Light LC State", __func__); + BT_ERR("Invalid Light LC State"); return -EINVAL; } srv->model = model; break; } default: - BT_WARN("%s, Unknown Light Server Model, model_id 0x%04x", __func__, model->id); + BT_WARN("Unknown Light Server, model id 0x%04x", model->id); return -EINVAL; } @@ -3158,7 +3158,7 @@ static int light_server_init(struct bt_mesh_model *model) int bt_mesh_light_lightness_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Light Lightness Server has no publication support", __func__); + BT_ERR("Light Lightness Server has no publication support"); return -EINVAL; } @@ -3167,7 +3167,7 @@ int bt_mesh_light_lightness_srv_init(struct bt_mesh_model *model, bool primary) */ struct bt_mesh_elem *element = bt_mesh_model_elem(model); if (bt_mesh_model_find(element, BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV) == NULL) { - BT_WARN("%s, Light Lightness Setup Server is not present", __func__); + BT_WARN("Light Lightness Setup Server not present"); /* Just give a warning here, continue with the initialization */ } return light_server_init(model); @@ -3181,7 +3181,7 @@ int bt_mesh_light_lightness_setup_srv_init(struct bt_mesh_model *model, bool pri int bt_mesh_light_ctl_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Light CTL Server has no publication support", __func__); + BT_ERR("Light CTL Server has no publication support"); return -EINVAL; } @@ -3195,11 +3195,11 @@ int bt_mesh_light_ctl_srv_init(struct bt_mesh_model *model, bool primary) */ struct bt_mesh_elem *element = bt_mesh_model_elem(model); if (bt_mesh_model_find(element, BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV) == NULL) { - BT_WARN("%s, Light CTL Setup Server is not present", __func__); + BT_WARN("Light CTL Setup Server not present"); /* Just give a warning here, continue with the initialization */ } if (bt_mesh_elem_count() < 2) { - BT_WARN("%s, Light CTL Server requires two elements", __func__); + BT_WARN("Light CTL Server requires two elements"); /* Just give a warning here, continue with the initialization */ } return light_server_init(model); @@ -3213,7 +3213,7 @@ int bt_mesh_light_ctl_setup_srv_init(struct bt_mesh_model *model, bool primary) int bt_mesh_light_ctl_temp_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Light CTL Temperature Server has no publication support", __func__); + BT_ERR("Light CTL Temperature Server has no publication support"); return -EINVAL; } @@ -3223,7 +3223,7 @@ int bt_mesh_light_ctl_temp_srv_init(struct bt_mesh_model *model, bool primary) int bt_mesh_light_hsl_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Light HSL Server has no publication support", __func__); + BT_ERR("Light HSL Server has no publication support"); return -EINVAL; } @@ -3238,11 +3238,11 @@ int bt_mesh_light_hsl_srv_init(struct bt_mesh_model *model, bool primary) */ struct bt_mesh_elem *element = bt_mesh_model_elem(model); if (bt_mesh_model_find(element, BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV) == NULL) { - BT_WARN("%s, Light HSL Setup Server is not present", __func__); + BT_WARN("Light HSL Setup Server not present"); /* Just give a warning here, continue with the initialization */ } if (bt_mesh_elem_count() < 3) { - BT_WARN("%s, Light HSL Server requires three elements", __func__); + BT_WARN("Light HSL Server requires three elements"); /* Just give a warning here, continue with the initialization */ } return light_server_init(model); @@ -3256,7 +3256,7 @@ int bt_mesh_light_hsl_setup_srv_init(struct bt_mesh_model *model, bool primary) int bt_mesh_light_hsl_hue_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Light HSL Hue Server has no publication support", __func__); + BT_ERR("Light HSL Hue Server has no publication support"); return -EINVAL; } @@ -3266,7 +3266,7 @@ int bt_mesh_light_hsl_hue_srv_init(struct bt_mesh_model *model, bool primary) int bt_mesh_light_hsl_sat_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Light HSL Saturation Server has no publication support", __func__); + BT_ERR("Light HSL Saturation Server has no publication support"); return -EINVAL; } @@ -3276,7 +3276,7 @@ int bt_mesh_light_hsl_sat_srv_init(struct bt_mesh_model *model, bool primary) int bt_mesh_light_xyl_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Light xyL Server has no publication support", __func__); + BT_ERR("Light xyL Server has no publication support"); return -EINVAL; } @@ -3286,7 +3286,7 @@ int bt_mesh_light_xyl_srv_init(struct bt_mesh_model *model, bool primary) */ struct bt_mesh_elem *element = bt_mesh_model_elem(model); if (bt_mesh_model_find(element, BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV) == NULL) { - BT_WARN("%s, Light xyL Setup Server is not present", __func__); + BT_WARN("Light xyL Setup Server not present"); /* Just give a warning here, continue with the initialization */ } return light_server_init(model); @@ -3300,7 +3300,7 @@ int bt_mesh_light_xyl_setup_srv_init(struct bt_mesh_model *model, bool primary) int bt_mesh_light_lc_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Light LC Server has no publication support", __func__); + BT_ERR("Light LC Server has no publication support"); return -EINVAL; } @@ -3310,7 +3310,7 @@ int bt_mesh_light_lc_srv_init(struct bt_mesh_model *model, bool primary) int bt_mesh_light_lc_setup_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Light LC Setup Server has no publication support", __func__); + BT_ERR("Light LC Setup Server has no publication support"); return -EINVAL; } @@ -3320,7 +3320,7 @@ int bt_mesh_light_lc_setup_srv_init(struct bt_mesh_model *model, bool primary) */ struct bt_mesh_elem *element = bt_mesh_model_elem(model); if (bt_mesh_model_find(element, BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV) == NULL) { - BT_WARN("%s, Light LC Setup Server is not present", __func__); + BT_WARN("Light LC Setup Server not present"); /* Just give a warning here, continue with the initialization */ } return light_server_init(model); @@ -3329,7 +3329,7 @@ int bt_mesh_light_lc_setup_srv_init(struct bt_mesh_model *model, bool primary) static int light_server_deinit(struct bt_mesh_model *model) { if (model->user_data == NULL) { - BT_ERR("%s, No Light Server context provided, model_id 0x%04x", __func__, model->id); + BT_ERR("Invalid Lighting Server user data, model id 0x%04x", model->id); return -EINVAL; } @@ -3337,7 +3337,7 @@ static int light_server_deinit(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV: { struct bt_mesh_light_lightness_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Light Lightness State", __func__); + BT_ERR("Invalid Light Lightness State"); return -EINVAL; } if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) { @@ -3351,7 +3351,7 @@ static int light_server_deinit(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_LIGHT_CTL_SRV: { struct bt_mesh_light_ctl_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Light CTL State", __func__); + BT_ERR("Invalid Light CTL State"); return -EINVAL; } if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) { @@ -3363,7 +3363,7 @@ static int light_server_deinit(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV: { struct bt_mesh_light_ctl_temp_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Light CTL State", __func__); + BT_ERR("Invalid Light CTL State"); return -EINVAL; } if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) { @@ -3375,7 +3375,7 @@ static int light_server_deinit(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_LIGHT_HSL_SRV: { struct bt_mesh_light_hsl_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Light HSL State", __func__); + BT_ERR("Invalid Light HSL State"); return -EINVAL; } if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) { @@ -3387,7 +3387,7 @@ static int light_server_deinit(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV: { struct bt_mesh_light_hsl_hue_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Light HSL State", __func__); + BT_ERR("Invalid Light HSL State"); return -EINVAL; } if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) { @@ -3399,7 +3399,7 @@ static int light_server_deinit(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV: { struct bt_mesh_light_hsl_sat_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Light HSL State", __func__); + BT_ERR("Invalid Light HSL State"); return -EINVAL; } if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) { @@ -3411,7 +3411,7 @@ static int light_server_deinit(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_LIGHT_XYL_SRV: { struct bt_mesh_light_xyl_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Light xyL State", __func__); + BT_ERR("Invalid Light xyL State"); return -EINVAL; } if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) { @@ -3423,7 +3423,7 @@ static int light_server_deinit(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_LIGHT_LC_SRV: { struct bt_mesh_light_lc_srv *srv = model->user_data; if (srv->lc == NULL) { - BT_ERR("%s, NULL Light LC State", __func__); + BT_ERR("Invalid Light LC State"); return -EINVAL; } if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_AUTO_RSP) { @@ -3433,7 +3433,7 @@ static int light_server_deinit(struct bt_mesh_model *model) break; } default: - BT_WARN("%s, Unknown Light Server Model, model_id 0x%04x", __func__, model->id); + BT_WARN("Unknown Light Server, model id 0x%04x", model->id); return -EINVAL; } @@ -3445,7 +3445,7 @@ static int light_server_deinit(struct bt_mesh_model *model) int bt_mesh_light_lightness_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Light Lightness Server has no publication support", __func__); + BT_ERR("Light Lightness Server has no publication support"); return -EINVAL; } @@ -3460,7 +3460,7 @@ int bt_mesh_light_lightness_setup_srv_deinit(struct bt_mesh_model *model, bool p int bt_mesh_light_ctl_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Light CTL Server has no publication support", __func__); + BT_ERR("Light CTL Server has no publication support"); return -EINVAL; } @@ -3475,7 +3475,7 @@ int bt_mesh_light_ctl_setup_srv_deinit(struct bt_mesh_model *model, bool primary int bt_mesh_light_ctl_temp_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Light CTL Temperature Server has no publication support", __func__); + BT_ERR("Light CTL Temperature Server has no publication support"); return -EINVAL; } @@ -3485,7 +3485,7 @@ int bt_mesh_light_ctl_temp_srv_deinit(struct bt_mesh_model *model, bool primary) int bt_mesh_light_hsl_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Light HSL Server has no publication support", __func__); + BT_ERR("Light HSL Server has no publication support"); return -EINVAL; } @@ -3500,7 +3500,7 @@ int bt_mesh_light_hsl_setup_srv_deinit(struct bt_mesh_model *model, bool primary int bt_mesh_light_hsl_hue_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Light HSL Hue Server has no publication support", __func__); + BT_ERR("Light HSL Hue Server has no publication support"); return -EINVAL; } @@ -3510,7 +3510,7 @@ int bt_mesh_light_hsl_hue_srv_deinit(struct bt_mesh_model *model, bool primary) int bt_mesh_light_hsl_sat_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Light HSL Saturation Server has no publication support", __func__); + BT_ERR("Light HSL Saturation Server has no publication support"); return -EINVAL; } @@ -3520,7 +3520,7 @@ int bt_mesh_light_hsl_sat_srv_deinit(struct bt_mesh_model *model, bool primary) int bt_mesh_light_xyl_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Light xyL Server has no publication support", __func__); + BT_ERR("Light xyL Server has no publication support"); return -EINVAL; } @@ -3535,7 +3535,7 @@ int bt_mesh_light_xyl_setup_srv_deinit(struct bt_mesh_model *model, bool primary int bt_mesh_light_lc_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Light LC Server has no publication support", __func__); + BT_ERR("Light LC Server has no publication support"); return -EINVAL; } @@ -3545,7 +3545,7 @@ int bt_mesh_light_lc_srv_deinit(struct bt_mesh_model *model, bool primary) int bt_mesh_light_lc_setup_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Light LC Setup Server has no publication support", __func__); + BT_ERR("Light LC Setup Server has no publication support"); return -EINVAL; } diff --git a/components/bt/esp_ble_mesh/mesh_models/server/sensor_server.c b/components/bt/esp_ble_mesh/mesh_models/server/sensor_server.c index 4975f1903..6fa8254bd 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/sensor_server.c +++ b/components/bt/esp_ble_mesh/mesh_models/server/sensor_server.c @@ -39,7 +39,7 @@ static void send_sensor_descriptor_status(struct bt_mesh_model *model, msg = bt_mesh_alloc_buf(MIN(BLE_MESH_TX_SDU_MAX, BLE_MESH_SERVER_RSP_MAX_LEN)); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } @@ -84,7 +84,7 @@ static void send_sensor_descriptor_status(struct bt_mesh_model *model, } } if (i == srv->state_count) { - BT_WARN("%s, Sensor Property ID 0x%04x does not exist", __func__, prop_id); + BT_WARN("Sensor Property ID 0x%04x not exists", prop_id); net_buf_simple_add_le16(msg, prop_id); } } @@ -106,7 +106,7 @@ static void send_sensor_data_status(struct bt_mesh_model *model, msg = bt_mesh_alloc_buf(MIN(BLE_MESH_TX_SDU_MAX, BLE_MESH_SERVER_RSP_MAX_LEN)); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } @@ -171,7 +171,7 @@ static void send_sensor_data_status(struct bt_mesh_model *model, } } if (i == srv->state_count) { - BT_WARN("%s, Sensor Property ID 0x%04x does not exist", __func__, prop_id); + BT_WARN("Sensor Property ID 0x%04x not exists", prop_id); u8_t mpid = (SENSOR_DATA_ZERO_LEN << 1) | SENSOR_DATA_FORMAT_B; net_buf_simple_add_u8(msg, mpid); net_buf_simple_add_le16(msg, prop_id); @@ -222,14 +222,14 @@ static void send_sensor_cadence_status(struct bt_mesh_model *model, } } if (i == srv->state_count) { - BT_WARN("%s, Sensor Property ID 0x%04x does not exist", __func__, prop_id); + BT_WARN("Sensor Property ID 0x%04x not exists", prop_id); length = SENSOR_PROPERTY_ID_LEN; } if (publish == false) { msg = bt_mesh_alloc_buf(1 + length + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } } else { @@ -297,7 +297,7 @@ static void send_sensor_settings_status(struct bt_mesh_model *model, msg = bt_mesh_alloc_buf(MIN(BLE_MESH_TX_SDU_MAX, BLE_MESH_SERVER_RSP_MAX_LEN)); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } @@ -325,7 +325,7 @@ static void send_sensor_settings_status(struct bt_mesh_model *model, } } if (i == srv->state_count) { - BT_WARN("%s, Sensor Property ID 0x%04x does not exist", __func__, prop_id); + BT_WARN("Sensor Property ID 0x%04x not exists", prop_id); } BLE_MESH_CHECK_SEND_STATUS(bt_mesh_model_send(model, ctx, msg, NULL, NULL)); @@ -334,7 +334,7 @@ static void send_sensor_settings_status(struct bt_mesh_model *model, } static struct sensor_setting *find_sensor_setting(struct bt_mesh_model *model, - u16_t prop_id, u16_t set_prop_id) + u16_t prop_id, u16_t set_prop_id) { struct bt_mesh_sensor_setup_srv *srv = model->user_data; struct bt_mesh_sensor_state *state = NULL; @@ -377,14 +377,14 @@ static void send_sensor_setting_status(struct bt_mesh_model *model, * an unknown Sensor Setting Property ID field, the Sensor Setting Access * field and the Sensor Setting Raw field shall be omitted. */ - BT_WARN("%s, Sensor Setting not found, 0x%04x, 0x%04x", __func__, prop_id, set_prop_id); + BT_WARN("Sensor Setting not found, 0x%04x, 0x%04x", prop_id, set_prop_id); length = SENSOR_PROPERTY_ID_LEN + SENSOR_SETTING_PROPERTY_ID_LEN; } if (publish == false) { msg = bt_mesh_alloc_buf(1 + length + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } } else { @@ -463,13 +463,13 @@ static void send_sensor_column_status(struct bt_mesh_model *model, } } if (i == srv->state_count) { - BT_WARN("%s, Sensor Property ID 0x%04x does not exist", __func__, prop_id); + BT_WARN("Sensor Property ID 0x%04x not exists", prop_id); length = SENSOR_PROPERTY_ID_LEN; } msg = bt_mesh_alloc_buf(1 + length + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } @@ -537,13 +537,13 @@ static void send_sensor_series_status(struct bt_mesh_model *model, } } if (i == srv->state_count) { - BT_WARN("%s, Sensor Property ID 0x%04x does not exist", __func__, prop_id); + BT_WARN("Sensor Property ID 0x%04x not exists", prop_id); length = SENSOR_PROPERTY_ID_LEN; } msg = bt_mesh_alloc_buf(1 + length + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } @@ -585,7 +585,7 @@ static void sensor_get(struct bt_mesh_model *model, u16_t prop_id = INVALID_SENSOR_PROPERTY_ID; if (model->user_data == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -596,7 +596,7 @@ static void sensor_get(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_SENSOR_SERIES_GET: { struct bt_mesh_sensor_srv *srv = model->user_data; if (srv->state_count == 0U || srv->states == NULL) { - BT_ERR("%s, Invalid Sensor Server state", __func__); + BT_ERR("Invalid Sensor Server state"); return; } if (ctx->recv_op == BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET || @@ -605,7 +605,7 @@ static void sensor_get(struct bt_mesh_model *model, if (buf->len) { prop_id = net_buf_simple_pull_le16(buf); if (prop_id == INVALID_SENSOR_PROPERTY_ID) { - BT_ERR("%s, Prohibited Sensor Property ID 0x0000", __func__); + BT_ERR("Prohibited Sensor Property ID 0x0000"); return; } } @@ -635,7 +635,7 @@ static void sensor_get(struct bt_mesh_model *model, } else { prop_id = net_buf_simple_pull_le16(buf); if (prop_id == INVALID_SENSOR_PROPERTY_ID) { - BT_ERR("%s, Prohibited Sensor Property ID 0x0000", __func__); + BT_ERR("Prohibited Sensor Property ID 0x0000"); return; } if (ctx->recv_op == BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET) { @@ -669,14 +669,14 @@ static void sensor_get(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_SENSOR_SETTING_GET: { struct bt_mesh_sensor_setup_srv *srv = model->user_data; if (srv->state_count == 0U || srv->states == NULL) { - BT_ERR("%s, Invalid Sensor Setup Server state", __func__); + BT_ERR("Invalid Sensor Setup Server state"); return; } if (ctx->recv_op == BLE_MESH_MODEL_OP_SENSOR_CADENCE_GET || ctx->recv_op == BLE_MESH_MODEL_OP_SENSOR_SETTINGS_GET) { prop_id = net_buf_simple_pull_le16(buf); if (prop_id == INVALID_SENSOR_PROPERTY_ID) { - BT_ERR("%s, Prohibited Sensor Property ID 0x0000", __func__); + BT_ERR("Prohibited Sensor Property ID 0x0000"); return; } if (ctx->recv_op == BLE_MESH_MODEL_OP_SENSOR_CADENCE_GET) { @@ -703,12 +703,12 @@ static void sensor_get(struct bt_mesh_model *model, } else { prop_id = net_buf_simple_pull_le16(buf); if (prop_id == INVALID_SENSOR_PROPERTY_ID) { - BT_ERR("%s, Prohibited Sensor Property ID 0x0000", __func__); + BT_ERR("Prohibited Sensor Property ID 0x0000"); return; } set_prop_id = net_buf_simple_pull_le16(buf); if (set_prop_id == INVALID_SENSOR_PROPERTY_ID) { - BT_ERR("%s, Prohibited Sensor Setting Property ID 0x0000", __func__); + BT_ERR("Prohibited Sensor Setting Property ID 0x0000"); return; } @@ -726,7 +726,7 @@ static void sensor_get(struct bt_mesh_model *model, return; } default: - BT_WARN("%s, Unknown Sensor Get opcode 0x%04x", __func__, ctx->recv_op); + BT_WARN("Unknown Sensor Get opcode 0x%04x", ctx->recv_op); return; } } @@ -745,13 +745,13 @@ static void sensor_cadence_set(struct bt_mesh_model *model, int i; if (srv == NULL || srv->state_count == 0U || srv->states == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } prop_id = net_buf_simple_pull_le16(buf); if (prop_id == INVALID_SENSOR_PROPERTY_ID) { - BT_ERR("%s, Prohibited Sensor Property ID 0x0000", __func__); + BT_ERR("Prohibited Sensor Property ID 0x0000"); return; } @@ -792,7 +792,7 @@ static void sensor_cadence_set(struct bt_mesh_model *model, val = net_buf_simple_pull_u8(buf); divisor = val & BIT_MASK(7); if (divisor > SENSOR_PERIOD_DIVISOR_MAX_VALUE) { - BT_ERR("%s, Prohibited Fast Cadence Period Divisor 0x%02x", __func__, divisor); + BT_ERR("Prohibited Fast Cadence Period Divisor 0x%02x", divisor); return; } state->cadence->period_divisor = divisor; @@ -804,8 +804,8 @@ static void sensor_cadence_set(struct bt_mesh_model *model, trigger_len = SENSOR_STATUS_TRIGGER_UINT16_LEN; } if (buf->len < (trigger_len << 1) + SENSOR_STATUS_MIN_INTERVAL_LEN) { - BT_ERR("%s, Invalid Sensor Cadence Set length %d, trigger type %d", - __func__, buf->len + 3, state->cadence->trigger_type); + BT_ERR("Invalid Sensor Cadence Set length %d, trigger type %d", + buf->len + 3, state->cadence->trigger_type); return; } @@ -823,13 +823,13 @@ static void sensor_cadence_set(struct bt_mesh_model *model, /* The valid range for the Status Min Interval is 0–26 and other values are Prohibited. */ val = net_buf_simple_pull_u8(buf); if (val > SENSOR_STATUS_MIN_INTERVAL_MAX) { - BT_ERR("%s, Invalid Status Min Interval %d", __func__, val); + BT_ERR("Invalid Status Min Interval %d", val); return; } state->cadence->min_interval = val; if (buf->len % 2) { - BT_ERR("%s, Different length of Fast Cadence Low & High, length %d", __func__, buf->len); + BT_ERR("Different length of Fast Cadence Low & High, length %d", buf->len); return; } if (buf->len) { @@ -866,7 +866,7 @@ static void sensor_cadence_set(struct bt_mesh_model *model, element = bt_mesh_model_elem(model); sensor_model = bt_mesh_model_find(element, BLE_MESH_MODEL_ID_SENSOR_SRV); if (sensor_model == NULL) { - BT_WARN("%s, Sensor Server Model does not exist in the element", __func__); + BT_WARN("Sensor Server model not exists in the element"); return; } @@ -885,13 +885,13 @@ static void update_sensor_periodic_pub(struct bt_mesh_model *model, u16_t prop_i int i; if (model->id != BLE_MESH_MODEL_ID_SENSOR_SRV) { - BT_ERR("%s, Not a Sensor Server Model", __func__); + BT_ERR("Invalid Sensor Server model 0x%04x", model->id); return; } srv = (struct bt_mesh_sensor_srv *)model->user_data; if (srv == NULL || srv->state_count == 0U || srv->states == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -903,12 +903,12 @@ static void update_sensor_periodic_pub(struct bt_mesh_model *model, u16_t prop_i } } if (i == srv->state_count) { - BT_ERR("%s, Sensor Property ID 0x%04x does not exist", __func__, prop_id); + BT_ERR("Sensor Property ID 0x%04x not exists", prop_id); return; } if (state->cadence == NULL) { - BT_WARN("%s, Sensor Cadence state does not exist", __func__); + BT_WARN("Sensor Cadence state not exists"); return; } @@ -930,19 +930,19 @@ static void sensor_setting_set(struct bt_mesh_model *model, u16_t prop_id = 0U, set_prop_id = 0U; if (srv == NULL || srv->state_count == 0U || srv->states == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } prop_id = net_buf_simple_pull_le16(buf); if (prop_id == INVALID_SENSOR_PROPERTY_ID) { - BT_ERR("%s, Prohibited Sensor Property ID 0x0000", __func__); + BT_ERR("Prohibited Sensor Property ID 0x0000"); return; } set_prop_id = net_buf_simple_pull_le16(buf); if (set_prop_id == INVALID_SENSOR_PROPERTY_ID) { - BT_ERR("%s, Prohibited Sensor Setting Property ID 0x0000", __func__); + BT_ERR("Prohibited Sensor Setting Property ID 0x0000"); return; } @@ -1015,13 +1015,13 @@ static int check_sensor_server_init(struct bt_mesh_sensor_state *state_start, for (i = 0; i < state_count; i++) { state = &state_start[i]; if (state->sensor_property_id == INVALID_SENSOR_PROPERTY_ID) { - BT_ERR("%s, Invalid Sensor Property ID 0x%04x", __func__, state->sensor_property_id); + BT_ERR("Invalid Sensor Property ID 0x%04x", state->sensor_property_id); return -EINVAL; } /* Check if the same Sensor Property ID exists */ for (int k = i + 1; k < state_count; k++) { if (state->sensor_property_id == state_start[k].sensor_property_id) { - BT_ERR("%s, Same Sensor Property ID 0x%04x exists", __func__, state->sensor_property_id); + BT_ERR("Same Sensor Property ID 0x%04x exists", state->sensor_property_id); return -EINVAL; } } @@ -1029,13 +1029,13 @@ static int check_sensor_server_init(struct bt_mesh_sensor_state *state_start, for (j = 0; j < state->setting_count; j++) { setting = &state->settings[j]; if (setting->property_id == INVALID_SENSOR_SETTING_PROPERTY_ID || setting->raw == NULL) { - BT_ERR("%s, Invalid Sensor Setting state", __func__); + BT_ERR("Invalid Sensor Setting state"); return -EINVAL; } /* Check if the same Sensor Setting Property ID exists */ for (int k = j + 1; k < state->setting_count; k++) { if (setting->property_id == state->settings[k].property_id) { - BT_ERR("%s, Same Sensor Setting Property ID 0x%04x exists", __func__, setting->property_id); + BT_ERR("Same Sensor Setting Property ID 0x%04x exists", setting->property_id); return -EINVAL; } } @@ -1046,12 +1046,12 @@ static int check_sensor_server_init(struct bt_mesh_sensor_state *state_start, state->cadence->trigger_delta_up == NULL || state->cadence->fast_cadence_low == NULL || state->cadence->fast_cadence_high == NULL) { - BT_ERR("%s, Invalid Sensor Cadence state", __func__); + BT_ERR("Invalid Sensor Cadence state"); return -EINVAL; } } if (state->sensor_data.raw_value == NULL) { - BT_ERR("%s, Invalid Sensor Data state", __func__); + BT_ERR("Invalid Sensor Data state"); return -EINVAL; } } @@ -1062,7 +1062,7 @@ static int check_sensor_server_init(struct bt_mesh_sensor_state *state_start, static int sensor_server_init(struct bt_mesh_model *model) { if (model->user_data == NULL) { - BT_ERR("%s, No Sensor Server context provided, model_id 0x%04x", __func__, model->id); + BT_ERR("Invalid Sensor Server user data, model id 0x%04x", model->id); return -EINVAL; } @@ -1070,7 +1070,7 @@ static int sensor_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_SENSOR_SRV: { struct bt_mesh_sensor_srv *srv = model->user_data; if (srv->state_count == 0U || srv->states == NULL) { - BT_ERR("%s, Invalid Sensor state, model_id 0x%04x", __func__, model->id); + BT_ERR("Invalid Sensor state, model id 0x%04x", model->id); return -EINVAL; } if (check_sensor_server_init(srv->states, srv->state_count)) { @@ -1082,7 +1082,7 @@ static int sensor_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_SENSOR_SETUP_SRV: { struct bt_mesh_sensor_setup_srv *srv = model->user_data; if (srv->state_count == 0U || srv->states == NULL) { - BT_ERR("%s, Invalid Sensor state, model_id 0x%04x", __func__, model->id); + BT_ERR("Invalid Sensor state, model id 0x%04x", model->id); return -EINVAL; } if (check_sensor_server_init(srv->states, srv->state_count)) { @@ -1092,7 +1092,7 @@ static int sensor_server_init(struct bt_mesh_model *model) break; } default: - BT_WARN("%s, Unknown Sensor Server Model, model_id 0x%04x", __func__, model->id); + BT_WARN("Unknown Sensor Server, model id 0x%04x", model->id); return -EINVAL; } @@ -1102,7 +1102,7 @@ static int sensor_server_init(struct bt_mesh_model *model) int bt_mesh_sensor_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Sensor Server has no publication support", __func__); + BT_ERR("Sensor Server has no publication support"); return -EINVAL; } @@ -1111,7 +1111,7 @@ int bt_mesh_sensor_srv_init(struct bt_mesh_model *model, bool primary) */ struct bt_mesh_elem *element = bt_mesh_model_elem(model); if (bt_mesh_model_find(element, BLE_MESH_MODEL_ID_SENSOR_SETUP_SRV) == NULL) { - BT_WARN("%s, Sensor Setup Server is not present", __func__); + BT_WARN("Sensor Setup Server not present"); /* Just give a warning here, continue with the initialization */ } return sensor_server_init(model); @@ -1120,7 +1120,7 @@ int bt_mesh_sensor_srv_init(struct bt_mesh_model *model, bool primary) int bt_mesh_sensor_setup_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Sensor Setup Server has no publication support", __func__); + BT_ERR("Sensor Setup Server has no publication support"); return -EINVAL; } @@ -1130,7 +1130,7 @@ int bt_mesh_sensor_setup_srv_init(struct bt_mesh_model *model, bool primary) static int sensor_server_deinit(struct bt_mesh_model *model) { if (model->user_data == NULL) { - BT_ERR("%s, No Sensor Server context provided, model_id 0x%04x", __func__, model->id); + BT_ERR("Invalid Sensor Server user, model id 0x%04x", model->id); return -EINVAL; } @@ -1140,7 +1140,7 @@ static int sensor_server_deinit(struct bt_mesh_model *model) int bt_mesh_sensor_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Sensor Server has no publication support", __func__); + BT_ERR("Sensor Server has no publication support"); return -EINVAL; } @@ -1150,7 +1150,7 @@ int bt_mesh_sensor_srv_deinit(struct bt_mesh_model *model, bool primary) int bt_mesh_sensor_setup_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Sensor Setup Server has no publication support", __func__); + BT_ERR("Sensor Setup Server has no publication support"); return -EINVAL; } diff --git a/components/bt/esp_ble_mesh/mesh_models/server/server_common.c b/components/bt/esp_ble_mesh/mesh_models/server/server_common.c index ee698e2d7..b1efe926f 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/server_common.c +++ b/components/bt/esp_ble_mesh/mesh_models/server/server_common.c @@ -73,13 +73,13 @@ int bt_mesh_get_light_lc_trans_time(struct bt_mesh_model *model, u8_t *trans_tim } if (model->id != BLE_MESH_MODEL_ID_LIGHT_LC_SRV) { - BT_ERR("%s, Not a Light LC Server", __func__); + BT_ERR("Invalid a Light LC Server 0x%04x", model->id); return -EINVAL; } srv = (struct bt_mesh_light_lc_srv *)model->user_data; if (srv == NULL) { - BT_ERR("%s, Invalid Light LC Server user_data", __func__); + BT_ERR("Invalid Light LC Server user data"); return -EINVAL; } @@ -130,7 +130,7 @@ int bt_mesh_server_get_optional(struct bt_mesh_model *model, } if (buf->len != 0x00 && buf->len != 0x02) { - BT_ERR("%s, Invalid optional message length %d", __func__, buf->len); + BT_ERR("Invalid optional message length %d", buf->len); return -EINVAL; } @@ -152,7 +152,7 @@ int bt_mesh_server_get_optional(struct bt_mesh_model *model, * its appropriate transition times defined by the Light LC Property states. */ if (bt_mesh_get_light_lc_trans_time(model, trans_time)) { - BT_ERR("%s, Failed to get Light LC transition time", __func__); + BT_ERR("Failed to get Light LC transition time"); return -EIO; } } else { @@ -166,7 +166,7 @@ int bt_mesh_server_get_optional(struct bt_mesh_model *model, /* Optional fields are available */ *trans_time = net_buf_simple_pull_u8(buf); if ((*trans_time & 0x3F) == 0x3F) { - BT_ERR("%s, Invalid Transaction Number of Steps 0x3F", __func__); + BT_ERR("Invalid Transaction Number of Steps 0x3f"); return -EINVAL; } @@ -183,16 +183,16 @@ void bt_mesh_server_alloc_ctx(struct k_work *work) * bt_mesh_msg_ctx" info to the application layer after a certain delay. * Here we use the allocated heap memory to store the "struct bt_mesh_msg_ctx". */ - __ASSERT(work, "%s, Invalid parameter", __func__); + __ASSERT(work, "Invalid parameter"); if (!work->_reserved) { work->_reserved = bt_mesh_calloc(sizeof(struct bt_mesh_msg_ctx)); - __ASSERT(work->_reserved, "%s, Failed to allocate memory", __func__); + __ASSERT(work->_reserved, "Out of memory"); } } void bt_mesh_server_free_ctx(struct k_work *work) { - __ASSERT(work, "%s, Invalid parameter", __func__); + __ASSERT(work, "Invalid parameter"); if (work->_reserved) { bt_mesh_free(work->_reserved); work->_reserved = NULL; @@ -243,14 +243,14 @@ struct net_buf_simple *bt_mesh_server_get_pub_msg(struct bt_mesh_model *model, u if (model->pub == NULL || model->pub->msg == NULL || model->pub->addr == BLE_MESH_ADDR_UNASSIGNED) { - BT_DBG("%s, Model 0x%04x has no publication support", __func__, model->id); + BT_DBG("No publication support, model id 0x%04x", model->id); return NULL; } buf = model->pub->msg; if (buf->size < msg_len) { - BT_ERR("%s, Too small publication msg size %d, model 0x%04x", - __func__, buf->size, model->id); + BT_ERR("Too small publication msg size %d, model id 0x%04x", + buf->size, model->id); return NULL; } diff --git a/components/bt/esp_ble_mesh/mesh_models/server/state_binding.c b/components/bt/esp_ble_mesh/mesh_models/server/state_binding.c index 9aef2081c..f54fcf3e7 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/state_binding.c +++ b/components/bt/esp_ble_mesh/mesh_models/server/state_binding.c @@ -104,7 +104,7 @@ int bt_mesh_update_binding_state(struct bt_mesh_model *model, switch (type) { case GENERIC_ONOFF_STATE: { if (model->id != BLE_MESH_MODEL_ID_GEN_ONOFF_SRV) { - BT_ERR("%s, Not a Generic OnOff Server Model, id 0x%04x", __func__, model->id); + BT_ERR("Invalid Generic OnOff Server, model id 0x%04x", model->id); return -EINVAL; } @@ -116,7 +116,7 @@ int bt_mesh_update_binding_state(struct bt_mesh_model *model, } case GENERIC_LEVEL_STATE: { if (model->id != BLE_MESH_MODEL_ID_GEN_LEVEL_SRV) { - BT_ERR("%s, Not a Generic Level Server Model, id 0x%04x", __func__, model->id); + BT_ERR("Invalid Generic Level Server, model id 0x%04x", model->id); return -EINVAL; } @@ -128,13 +128,13 @@ int bt_mesh_update_binding_state(struct bt_mesh_model *model, } case GENERIC_ONPOWERUP_STATE: { if (model->id != BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV) { - BT_ERR("%s, Not a Generic Power OnOff Server Model, id 0x%04x", __func__, model->id); + BT_ERR("Invalid Generic Power OnOff Server, model id 0x%04x", model->id); return -EINVAL; } struct bt_mesh_gen_power_onoff_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Generic Power OnOff Server state", __func__); + BT_ERR("Invalid Generic Power OnOff Server state"); return -EINVAL; } @@ -144,13 +144,13 @@ int bt_mesh_update_binding_state(struct bt_mesh_model *model, } case GENERIC_POWER_ACTUAL_STATE: { if (model->id != BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV) { - BT_ERR("%s, Not a Generic Power Level Server Model, id 0x%04x", __func__, model->id); + BT_ERR("Invalid Generic Power Level Server, model id 0x%04x", model->id); return -EINVAL; } struct bt_mesh_gen_power_level_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Generic Power Level Server state", __func__); + BT_ERR("Invalid Generic Power Level Server state"); return -EINVAL; } @@ -170,13 +170,13 @@ int bt_mesh_update_binding_state(struct bt_mesh_model *model, } case LIGHT_LIGHTNESS_ACTUAL_STATE: { if (model->id != BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV) { - BT_ERR("%s, Not a Light Lightness Server Model, id 0x%04x", __func__, model->id); + BT_ERR("Invalid Light Lightness Server, model id 0x%04x", model->id); return -EINVAL; } struct bt_mesh_light_lightness_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light Lightness Server state", __func__); + BT_ERR("Invalid Light Lightness Server state"); return -EINVAL; } @@ -196,13 +196,13 @@ int bt_mesh_update_binding_state(struct bt_mesh_model *model, } case LIGHT_LIGHTNESS_LINEAR_STATE: { if (model->id != BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV) { - BT_ERR("%s, Not a Light Lightness Server Model, id 0x%04x", __func__, model->id); + BT_ERR("Invalid Light Lightness Server, model id 0x%04x", model->id); return -EINVAL; } struct bt_mesh_light_lightness_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light Lightness Server state", __func__); + BT_ERR("Invalid Light Lightness Server state"); return -EINVAL; } @@ -213,13 +213,13 @@ int bt_mesh_update_binding_state(struct bt_mesh_model *model, } case LIGHT_CTL_LIGHTNESS_STATE: { if (model->id != BLE_MESH_MODEL_ID_LIGHT_CTL_SRV) { - BT_ERR("%s, Not a Light CTL Server Model, id 0x%04x", __func__, model->id); + BT_ERR("Invalid Light CTL Server, model id 0x%04x", model->id); return -EINVAL; } struct bt_mesh_light_ctl_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light CTL Server state", __func__); + BT_ERR("Invalid Light CTL Server state"); return -EINVAL; } @@ -230,13 +230,13 @@ int bt_mesh_update_binding_state(struct bt_mesh_model *model, } case LIGHT_CTL_TEMP_DELTA_UV_STATE: { if (model->id != BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV) { - BT_ERR("%s, Not a Light CTL Temperature Server Model, id 0x%04x", __func__, model->id); + BT_ERR("Invalid Light CTL Temperature Server, model id 0x%04x", model->id); return -EINVAL; } struct bt_mesh_light_ctl_temp_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light CTL Temperature Server state", __func__); + BT_ERR("Invalid Light CTL Temperature Server state"); return -EINVAL; } @@ -248,13 +248,13 @@ int bt_mesh_update_binding_state(struct bt_mesh_model *model, } case LIGHT_HSL_LIGHTNESS_STATE: { if (model->id != BLE_MESH_MODEL_ID_LIGHT_HSL_SRV) { - BT_ERR("%s, Not a Light HSL Server Model, id 0x%04x", __func__, model->id); + BT_ERR("Invalid Light HSL Server, model id 0x%04x", model->id); return -EINVAL; } struct bt_mesh_light_hsl_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light HSL Server state", __func__); + BT_ERR("Invalid Light HSL Server state"); return -EINVAL; } @@ -265,13 +265,13 @@ int bt_mesh_update_binding_state(struct bt_mesh_model *model, } case LIGHT_HSL_HUE_STATE: { if (model->id != BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV) { - BT_ERR("%s, Not a Light HSL Hue Server Model, id 0x%04x", __func__, model->id); + BT_ERR("Invalid Light HSL Hue Server, model id 0x%04x", model->id); return -EINVAL; } struct bt_mesh_light_hsl_hue_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light HSL Hue Server state", __func__); + BT_ERR("Invalid Light HSL Hue Server state"); return -EINVAL; } @@ -282,13 +282,13 @@ int bt_mesh_update_binding_state(struct bt_mesh_model *model, } case LIGHT_HSL_SATURATION_STATE: { if (model->id != BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV) { - BT_ERR("%s, Not a Light HSL Saturation Server Model, id 0x%04x", __func__, model->id); + BT_ERR("Invalid Light HSL Saturation Server, model id 0x%04x", model->id); return -EINVAL; } struct bt_mesh_light_hsl_sat_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light HSL Saturation Server state", __func__); + BT_ERR("Invalid Light HSL Saturation Server state"); return -EINVAL; } @@ -299,13 +299,13 @@ int bt_mesh_update_binding_state(struct bt_mesh_model *model, } case LIGHT_XYL_LIGHTNESS_STATE: { if (model->id != BLE_MESH_MODEL_ID_LIGHT_XYL_SRV) { - BT_ERR("%s, Not a Light xyL Server Model, id 0x%04x", __func__, model->id); + BT_ERR("Invalid Light xyL Server, model id 0x%04x", model->id); return -EINVAL; } struct bt_mesh_light_xyl_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Light xyL Server state", __func__); + BT_ERR("Invalid Light xyL Server state"); return -EINVAL; } @@ -316,13 +316,13 @@ int bt_mesh_update_binding_state(struct bt_mesh_model *model, } case LIGHT_LC_LIGHT_ONOFF_STATE: { if (model->id != BLE_MESH_MODEL_ID_LIGHT_LC_SRV) { - BT_ERR("%s, Not a Light LC Server Model, id 0x%04x", __func__, model->id); + BT_ERR("Invalid Light LC Server, model id 0x%04x", model->id); return -EINVAL; } struct bt_mesh_light_lc_srv *srv = model->user_data; if (srv->lc == NULL) { - BT_ERR("%s, Invalid Light LC Server state", __func__); + BT_ERR("Invalid Light LC Server state"); return -EINVAL; } @@ -332,7 +332,7 @@ int bt_mesh_update_binding_state(struct bt_mesh_model *model, break; } default: - BT_WARN("%s, Unknown binding state type 0x%02x", __func__, type); + BT_WARN("Unknown binding state type 0x%02x", type); return -EINVAL; } diff --git a/components/bt/esp_ble_mesh/mesh_models/server/time_scene_server.c b/components/bt/esp_ble_mesh/mesh_models/server/time_scene_server.c index 0a1f3432a..447f3a218 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/time_scene_server.c +++ b/components/bt/esp_ble_mesh/mesh_models/server/time_scene_server.c @@ -64,7 +64,7 @@ static void send_time_status(struct bt_mesh_model *model, if (publish == false) { msg = bt_mesh_alloc_buf(length + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } } else { @@ -138,7 +138,7 @@ static void send_time_status(struct bt_mesh_model *model, break; } default: - BT_WARN("%s, Unknown Time status opcode 0x%04x", __func__, opcode); + BT_WARN("Unknown Time status opcode 0x%04x", opcode); if (publish == false) { bt_mesh_free_buf(msg); } @@ -164,7 +164,7 @@ static void time_get(struct bt_mesh_model *model, u8_t prev_ttl = 0U; if (model->user_data == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -172,7 +172,7 @@ static void time_get(struct bt_mesh_model *model, case BLE_MESH_MODEL_ID_TIME_SRV: { struct bt_mesh_time_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Time Server state", __func__); + BT_ERR("Invalid Time Server state"); return; } rsp_ctrl = &srv->rsp_ctrl; @@ -181,14 +181,14 @@ static void time_get(struct bt_mesh_model *model, case BLE_MESH_MODEL_ID_TIME_SETUP_SRV: { struct bt_mesh_time_setup_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Time Setup Server state", __func__); + BT_ERR("Invalid Time Setup Server state"); return; } rsp_ctrl = &srv->rsp_ctrl; break; } default: - BT_ERR("%s, Invalid Time Server 0x%04x", __func__, model->id); + BT_ERR("Invalid Time Server, model id 0x%04x", model->id); return; } @@ -207,7 +207,7 @@ static void time_get(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_TIME_STATUS: { struct bt_mesh_time_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, Invalid Time Server state", __func__); + BT_ERR("Invalid Time Server state"); return; } if (srv->state->time_role != TIME_RELAY && @@ -224,7 +224,7 @@ static void time_get(struct bt_mesh_model *model, net_buf_simple_pull(buf, TAI_SECONDS_LEN); if (memcmp(status.time_status.tai_seconds, zero, TAI_SECONDS_LEN)) { if (buf->len != TAI_SECONDS_LEN) { - BT_ERR("%s, Invalid Time Status length %d", __func__, buf->len + TAI_SECONDS_LEN); + BT_ERR("Invalid Time Status length %d", buf->len + TAI_SECONDS_LEN); return; } status.time_status.subsecond = net_buf_simple_pull_u8(buf); @@ -247,7 +247,7 @@ static void time_get(struct bt_mesh_model *model, */ if (memcmp(srv->state->time.tai_seconds, zero, TAI_SECONDS_LEN)) { if (buf->len != TAI_SECONDS_LEN) { - BT_ERR("%s, Invalid Time Status length %d", __func__, buf->len + TAI_SECONDS_LEN); + BT_ERR("Invalid Time Status length %d", buf->len + TAI_SECONDS_LEN); return; } srv->state->time.subsecond = net_buf_simple_pull_u8(buf); @@ -294,7 +294,7 @@ static void time_get(struct bt_mesh_model *model, opcode = BLE_MESH_MODEL_OP_TIME_ROLE_STATUS; break; default: - BT_WARN("%s, Unknown Time Get opcode 0x%04x", __func__, ctx->recv_op); + BT_WARN("Unknown Time Get opcode 0x%04x", ctx->recv_op); return; } @@ -312,7 +312,7 @@ static void time_set(struct bt_mesh_model *model, u8_t role = 0U; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -360,7 +360,7 @@ static void time_set(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_TAI_UTC_DELTA_SET: val = net_buf_simple_pull_le16(buf); if ((val >> 15) & BIT(0)) { - BT_ERR("%s, Invalid Padding value 1", __func__); + BT_ERR("Invalid Padding value 1"); return; } if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) { @@ -380,7 +380,7 @@ static void time_set(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_TIME_ROLE_SET: role = net_buf_simple_pull_u8(buf); if (role > TIME_CLINET) { - BT_ERR("%s, Invalid Time Role 0x%02x", __func__, role); + BT_ERR("Invalid Time Role 0x%02x", role); return; } if (srv->rsp_ctrl.set_auto_rsp == BLE_MESH_SERVER_RSP_BY_APP) { @@ -395,7 +395,7 @@ static void time_set(struct bt_mesh_model *model, opcode = BLE_MESH_MODEL_OP_TIME_ROLE_STATUS; break; default: - BT_ERR("%s, Unknown Time Set opcode 0x%04x", __func__, ctx->recv_op); + BT_ERR("Unknown Time Set opcode 0x%04x", ctx->recv_op); return; } @@ -442,7 +442,7 @@ static void send_scene_status(struct bt_mesh_model *model, if (publish == false) { msg = bt_mesh_alloc_buf(length + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } } else { @@ -504,7 +504,7 @@ static void send_scene_register_status(struct bt_mesh_model *model, if (publish == false) { msg = bt_mesh_alloc_buf(MIN(BLE_MESH_TX_SDU_MAX, BLE_MESH_SERVER_RSP_MAX_LEN)); if (msg == NULL) { - BT_ERR("%s, Failed to allocate memory", __func__); + BT_ERR("%s, Out of memory", __func__); return; } } else { @@ -548,7 +548,7 @@ static void scene_get(struct bt_mesh_model *model, struct bt_mesh_scene_srv *srv = model->user_data; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -571,7 +571,7 @@ static void scene_get(struct bt_mesh_model *model, send_scene_register_status(model, ctx, SCENE_SUCCESS, false); return; default: - BT_WARN("%s, Unknown Scene Get opcode 0x%04x", __func__, ctx->recv_op); + BT_WARN("Unknown Scene Get opcode 0x%04x", ctx->recv_op); return; } } @@ -581,7 +581,7 @@ void scene_publish(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, u16 struct bt_mesh_scene_srv *srv = model->user_data; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -602,13 +602,13 @@ static void scene_recall(struct bt_mesh_model *model, int i; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } scene_number = net_buf_simple_pull_le16(buf); if (scene_number == INVALID_SCENE_NUMBER) { - BT_ERR("%s, Invalid Scene Number 0x0000", __func__); + BT_ERR("Invalid Scene Number 0x0000"); return; } tid = net_buf_simple_pull_u8(buf); @@ -637,7 +637,7 @@ static void scene_recall(struct bt_mesh_model *model, } } if (i == srv->state->scene_count) { - BT_WARN("%s, Scene Number 0x%04x not exist", __func__, scene_number); + BT_WARN("Scene Number 0x%04x not exists", scene_number); srv->state->status_code = SCENE_NOT_FOUND; if (ctx->recv_op == BLE_MESH_MODEL_OP_SCENE_RECALL) { send_scene_status(model, ctx, false); @@ -731,13 +731,13 @@ static void scene_action(struct bt_mesh_model *model, int i; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } scene_number = net_buf_simple_pull_le16(buf); if (scene_number == INVALID_SCENE_NUMBER) { - BT_ERR("%s, Invalid Scene number 0x0000", __func__); + BT_ERR("Invalid Scene number 0x0000"); return; } @@ -763,7 +763,7 @@ static void scene_action(struct bt_mesh_model *model, } /* Try to find a unset entry if no matching Scene Number is found */ if (i == srv->state->scene_count) { - BT_DBG("%s, No matching Scene Number 0x%04x found", __func__, scene_number); + BT_DBG("No matching Scene Number 0x%04x found", scene_number); for (i = 0; i < srv->state->scene_count; i++) { scene = &srv->state->scenes[i]; if (scene->scene_number == INVALID_SCENE_NUMBER) { @@ -774,7 +774,7 @@ static void scene_action(struct bt_mesh_model *model, } } if (i == srv->state->scene_count) { - BT_WARN("%s, Scene Register full", __func__); + BT_WARN("Scene Register is full!"); srv->state->status_code = SCENE_REG_FULL; /* Get the Scene Number of the currently active scene */ for (i = 0; i < srv->state->scene_count; i++) { @@ -826,7 +826,7 @@ static void scene_action(struct bt_mesh_model *model, } } if (i == srv->state->scene_count) { - BT_WARN("%s, Scene Number 0x%04x not exist", __func__, scene_number); + BT_WARN("Scene Number 0x%04x not exists", scene_number); /** * When a Scene Server receives a Scene Delete message with the Scene * Number value that does not match a Scene Number stored within the @@ -881,13 +881,13 @@ static void scene_action(struct bt_mesh_model *model, scene_model = bt_mesh_model_find(bt_mesh_model_elem(model), BLE_MESH_MODEL_ID_SCENE_SRV); if (scene_model == NULL) { - BT_ERR("%s, Scene Server is not present in the element", __func__); + BT_ERR("Scene Server not present in the element"); break; } scene_srv = scene_model->user_data; if (scene_srv == NULL || scene_srv->state == NULL) { - BT_ERR("%s, Invalid Scene Server parameter", __func__); + BT_ERR("Invalid Scene Server user data"); break; } @@ -896,7 +896,7 @@ static void scene_action(struct bt_mesh_model *model, * Add this in case the Scene Setup Server is extending the Scene * Server in another element. */ - BT_WARN("%s, Different Scene state in Scene Server & Scene Setup Server", __func__); + BT_WARN("Different Scene state in Scene Server & Scene Setup Server"); break; } @@ -912,7 +912,7 @@ static void scene_action(struct bt_mesh_model *model, break; } default: - BT_ERR("%s, Unknown Scene setup action opcode 0x%04x", __func__, ctx->recv_op); + BT_ERR("Unknown Scene setup action opcode 0x%04x", ctx->recv_op); return; } @@ -979,7 +979,7 @@ static void send_scheduler_act_status(struct bt_mesh_model *model, break; } default: - BT_ERR("%s, Invalid Scheduler Server 0x%04x", __func__, model->id); + BT_ERR("Invalid Scheduler Server, model id 0x%04x", model->id); return; } @@ -995,7 +995,7 @@ static void scheduler_get(struct bt_mesh_model *model, NET_BUF_SIMPLE_DEFINE(msg, 2 + 2 + BLE_MESH_SERVER_TRANS_MIC_SIZE); if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1015,7 +1015,7 @@ static void scheduler_get(struct bt_mesh_model *model, case BLE_MESH_MODEL_OP_SCHEDULER_ACT_GET: { u8_t index = net_buf_simple_pull_u8(buf); if (index > SCHEDULE_ENTRY_MAX_INDEX) { - BT_ERR("%s, Invalid Scheduler Register Entry index 0x%02x", __func__, index); + BT_ERR("Invalid Scheduler Register Entry index 0x%02x", index); return; } @@ -1032,7 +1032,7 @@ static void scheduler_get(struct bt_mesh_model *model, return; } default: - BT_WARN("%s, Unknown Scheduler Get opcode 0x%04x", __func__, ctx->recv_op); + BT_WARN("Unknown Scheduler Get opcode 0x%04x", ctx->recv_op); return; } } @@ -1058,7 +1058,7 @@ static void scheduler_act_set(struct bt_mesh_model *model, u64_t value = 0U; if (srv == NULL || srv->state == NULL) { - BT_ERR("%s, Invalid model user_data", __func__); + BT_ERR("%s, Invalid model user data", __func__); return; } @@ -1077,22 +1077,22 @@ static void scheduler_act_set(struct bt_mesh_model *model, trans_time = (value >> 56) & BIT_MASK(8); if (index > SCHEDULE_ENTRY_MAX_INDEX) { - BT_ERR("%s, Invalid Scheduler Register Entry index 0x%02x", __func__, index); + BT_ERR("Invalid Scheduler Register Entry index 0x%02x", index); return; } if (year > SCHEDULE_YEAR_ANY_YEAR) { - BT_ERR("%s, Invalid Scheduler Register year 0x%02x", __func__, year); + BT_ERR("Invalid Scheduler Register year 0x%02x", year); return; } if (hour > SCHEDULE_HOUR_ONCE_A_DAY) { - BT_ERR("%s, Invalid Scheduler Register hour 0x%02x", __func__, hour); + BT_ERR("Invalid Scheduler Register hour 0x%02x", hour); return; } if (action > SCHEDULE_ACT_SCENE_RECALL && action != SCHEDULE_ACT_NO_ACTION) { - BT_ERR("%s, Invalid Scheduler Register action 0x%02x", __func__, action); + BT_ERR("Invalid Scheduler Register action 0x%02x", action); return; } @@ -1210,13 +1210,13 @@ static int check_scene_server_init(struct bt_mesh_scenes_state *state) int i; if (state->scene_count == 0U || state->scenes == NULL) { - BT_ERR("%s, Invalid Scene state", __func__); + BT_ERR("Invalid Scene state"); return -EINVAL; } for (i = 0; i < state->scene_count; i++) { if (state->scenes[i].scene_value == NULL) { - BT_ERR("%s, Invalid Scene value, index %d", __func__, i); + BT_ERR("Invalid Scene value, index %d", i); return -EINVAL; } } @@ -1227,7 +1227,7 @@ static int check_scene_server_init(struct bt_mesh_scenes_state *state) static int time_scene_server_init(struct bt_mesh_model *model) { if (model->user_data == NULL) { - BT_ERR("%s, No Time Scene Server context provided, model_id 0x%04x", __func__, model->id); + BT_ERR("Invalid Time Scene Server user data, model id 0x%04x", model->id); return -EINVAL; } @@ -1235,7 +1235,7 @@ static int time_scene_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_TIME_SRV: { struct bt_mesh_time_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Time State", __func__); + BT_ERR("Invalid Time State"); return -EINVAL; } srv->model = model; @@ -1244,7 +1244,7 @@ static int time_scene_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_TIME_SETUP_SRV: { struct bt_mesh_time_setup_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Time State", __func__); + BT_ERR("Invalid Time State"); return -EINVAL; } srv->model = model; @@ -1253,7 +1253,7 @@ static int time_scene_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_SCENE_SRV: { struct bt_mesh_scene_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Scene State", __func__); + BT_ERR("Invalid Scene State"); return -EINVAL; } if (check_scene_server_init(srv->state)) { @@ -1269,7 +1269,7 @@ static int time_scene_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_SCENE_SETUP_SRV: { struct bt_mesh_scene_setup_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Scene State", __func__); + BT_ERR("Invalid Scene State"); return -EINVAL; } if (check_scene_server_init(srv->state)) { @@ -1281,11 +1281,11 @@ static int time_scene_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_SCHEDULER_SRV: { struct bt_mesh_scheduler_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Scheduler State", __func__); + BT_ERR("Invalid Scheduler State"); return -EINVAL; } if (srv->state->schedule_count == 0U || srv->state->schedules == NULL) { - BT_ERR("%s, NULL Register Schedule", __func__); + BT_ERR("Invalid Register Schedule"); return -EINVAL; } srv->model = model; @@ -1294,18 +1294,18 @@ static int time_scene_server_init(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_SCHEDULER_SETUP_SRV: { struct bt_mesh_scheduler_setup_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Scheduler State", __func__); + BT_ERR("Invalid Scheduler State"); return -EINVAL; } if (srv->state->schedule_count == 0U || srv->state->schedules == NULL) { - BT_ERR("%s, NULL Register Schedule", __func__); + BT_ERR("Invalid Register Schedule"); return -EINVAL; } srv->model = model; break; } default: - BT_WARN("%s, Unknown Time Scene Server Model, model_id 0x%04x", __func__, model->id); + BT_WARN("Unknown Time Scene Server, model id 0x%04x", model->id); return -EINVAL; } @@ -1317,7 +1317,7 @@ static int time_scene_server_init(struct bt_mesh_model *model) int bt_mesh_time_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Time Server has no publication support", __func__); + BT_ERR("Time Server has no publication support"); return -EINVAL; } @@ -1327,7 +1327,7 @@ int bt_mesh_time_srv_init(struct bt_mesh_model *model, bool primary) */ struct bt_mesh_elem *element = bt_mesh_model_elem(model); if (bt_mesh_model_find(element, BLE_MESH_MODEL_ID_TIME_SETUP_SRV) == NULL) { - BT_WARN("%s, Time Setup Server is not present", __func__); + BT_WARN("Time Setup Server not present"); /* Just give a warning here, continue with the initialization */ } return time_scene_server_init(model); @@ -1337,7 +1337,7 @@ int bt_mesh_time_setup_srv_init(struct bt_mesh_model *model, bool primary) { /* This model does not support subscribing nor publishing */ if (model->pub) { - BT_ERR("%s, Time Setup Server shall not support publication", __func__); + BT_ERR("Time Setup Server shall not support publication"); return -EINVAL; } @@ -1347,13 +1347,13 @@ int bt_mesh_time_setup_srv_init(struct bt_mesh_model *model, bool primary) int bt_mesh_scene_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Scene Server has no publication support", __func__); + BT_ERR("Scene Server has no publication support"); return -EINVAL; } /* The model may be present only on the Primary element of a node. */ if (primary == false) { - BT_WARN("%s, Scene Server is not on the Primary element", __func__); + BT_WARN("Scene Server not on the Primary element"); /* Just give a warning here, continue with the initialization */ } /** @@ -1362,7 +1362,7 @@ int bt_mesh_scene_srv_init(struct bt_mesh_model *model, bool primary) */ struct bt_mesh_elem *element = bt_mesh_model_elem(model); if (bt_mesh_model_find(element, BLE_MESH_MODEL_ID_SCENE_SETUP_SRV) == NULL) { - BT_WARN("%s, Scene Setup Server is not present", __func__); + BT_WARN("Scene Setup Server not present"); /* Just give a warning here, continue with the initialization */ } return time_scene_server_init(model); @@ -1372,7 +1372,7 @@ int bt_mesh_scene_setup_srv_init(struct bt_mesh_model *model, bool primary) { /* The model may be present only on the Primary element of a node. */ if (primary == false) { - BT_WARN("%s, Scene Setup Server is not on the Primary element", __func__); + BT_WARN("Scene Setup Server not on the Primary element"); /* Just give a warning here, continue with the initialization */ } return time_scene_server_init(model); @@ -1381,13 +1381,13 @@ int bt_mesh_scene_setup_srv_init(struct bt_mesh_model *model, bool primary) int bt_mesh_scheduler_srv_init(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Scheduler Server has no publication support", __func__); + BT_ERR("Scheduler Server has no publication support"); return -EINVAL; } /* The model may be present only on the Primary element of a node. */ if (primary == false) { - BT_WARN("%s, Scheduler Server is not on the Primary element", __func__); + BT_WARN("Scheduler Server not on the Primary element"); /* Just give a warning here, continue with the initialization */ } /** @@ -1397,11 +1397,11 @@ int bt_mesh_scheduler_srv_init(struct bt_mesh_model *model, bool primary) */ struct bt_mesh_elem *element = bt_mesh_model_elem(model); if (bt_mesh_model_find(element, BLE_MESH_MODEL_ID_SCHEDULER_SETUP_SRV) == NULL) { - BT_WARN("%s, Scheduler Setup Server is not present", __func__); + BT_WARN("Scheduler Setup Server not present"); /* Just give a warning here, continue with the initialization */ } if (bt_mesh_model_find(element, BLE_MESH_MODEL_ID_TIME_SRV) == NULL) { - BT_WARN("%s, Time Server is not present", __func__); + BT_WARN("Time Server not present"); /* Just give a warning here, continue with the initialization */ } return time_scene_server_init(model); @@ -1411,7 +1411,7 @@ int bt_mesh_scheduler_setup_srv_init(struct bt_mesh_model *model, bool primary) { /* The model may be present only on the Primary element of a node. */ if (primary == false) { - BT_WARN("%s, Scheduler Setup Server is not on the Primary element", __func__); + BT_WARN("Scheduler Setup Server not on the Primary element"); /* Just give a warning here, continue with the initialization */ } return time_scene_server_init(model); @@ -1420,7 +1420,7 @@ int bt_mesh_scheduler_setup_srv_init(struct bt_mesh_model *model, bool primary) static int time_scene_server_deinit(struct bt_mesh_model *model) { if (model->user_data == NULL) { - BT_ERR("%s, No Time Scene Server context provided, model_id 0x%04x", __func__, model->id); + BT_ERR("Invalid Time Scene Server user data, model id 0x%04x", model->id); return -EINVAL; } @@ -1428,7 +1428,7 @@ static int time_scene_server_deinit(struct bt_mesh_model *model) case BLE_MESH_MODEL_ID_SCENE_SRV: { struct bt_mesh_scene_srv *srv = model->user_data; if (srv->state == NULL) { - BT_ERR("%s, NULL Scene State", __func__); + BT_ERR("Invalid Scene State"); return -EINVAL; } if (check_scene_server_init(srv->state)) { @@ -1441,7 +1441,7 @@ static int time_scene_server_deinit(struct bt_mesh_model *model) break; } default: - BT_WARN("%s, Unknown Time Scene Server Model, model_id 0x%04x", __func__, model->id); + BT_WARN("Unknown Time Scene Server, model id 0x%04x", model->id); return -EINVAL; } @@ -1453,7 +1453,7 @@ static int time_scene_server_deinit(struct bt_mesh_model *model) int bt_mesh_time_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Time Server has no publication support", __func__); + BT_ERR("Time Server has no publication support"); return -EINVAL; } @@ -1463,7 +1463,7 @@ int bt_mesh_time_srv_deinit(struct bt_mesh_model *model, bool primary) int bt_mesh_time_setup_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub) { - BT_ERR("%s, Time Setup Server shall not support publication", __func__); + BT_ERR("Time Setup Server shall not support publication"); return -EINVAL; } @@ -1473,7 +1473,7 @@ int bt_mesh_time_setup_srv_deinit(struct bt_mesh_model *model, bool primary) int bt_mesh_scene_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Scene Server has no publication support", __func__); + BT_ERR("Scene Server has no publication support"); return -EINVAL; } @@ -1488,7 +1488,7 @@ int bt_mesh_scene_setup_srv_deinit(struct bt_mesh_model *model, bool primary) int bt_mesh_scheduler_srv_deinit(struct bt_mesh_model *model, bool primary) { if (model->pub == NULL) { - BT_ERR("%s, Scheduler Server has no publication support", __func__); + BT_ERR("Scheduler Server has no publication support"); return -EINVAL; } From c7cb56b507b48bea0e600b3d839ef0b60cc7fc8f Mon Sep 17 00:00:00 2001 From: lly Date: Mon, 6 Jul 2020 19:17:11 +0800 Subject: [PATCH 35/60] ble_mesh: ci: Enable friend & low power in build check --- .../ble_mesh_node/onoff_server/sdkconfig.ci.bluedroid | 3 ++- .../ble_mesh_node/onoff_server/sdkconfig.ci.nimble | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_server/sdkconfig.ci.bluedroid b/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_server/sdkconfig.ci.bluedroid index 9b3d74764..1bc4d6b03 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_server/sdkconfig.ci.bluedroid +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_server/sdkconfig.ci.bluedroid @@ -10,4 +10,5 @@ CONFIG_BTU_TASK_STACK_SIZE=4512 CONFIG_BLE_MESH=y CONFIG_BLE_MESH_NODE=y -CONFIG_BLE_MESH_PB_GATT=y \ No newline at end of file +CONFIG_BLE_MESH_PB_GATT=y +CONFIG_BLE_MESH_FRIEND=y diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_server/sdkconfig.ci.nimble b/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_server/sdkconfig.ci.nimble index 9cb2c2db2..a13bf4aea 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_server/sdkconfig.ci.nimble +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_server/sdkconfig.ci.nimble @@ -10,3 +10,4 @@ CONFIG_NIMBLE_ENABLED=y CONFIG_BLE_MESH=y CONFIG_BLE_MESH_NODE=y CONFIG_BLE_MESH_PB_GATT=y +CONFIG_BLE_MESH_LOW_POWER=y From 726c74ff39b1c288bf75908eb812c05f10488768 Mon Sep 17 00:00:00 2001 From: lly Date: Thu, 16 Jul 2020 14:53:34 +0800 Subject: [PATCH 36/60] ble_mesh: stack: Fix recv health current status incorrectly --- .../bt/esp_ble_mesh/mesh_core/health_cli.c | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/health_cli.c b/components/bt/esp_ble_mesh/mesh_core/health_cli.c index dbfbe4eef..5ff4f0c77 100644 --- a/components/bt/esp_ble_mesh/mesh_core/health_cli.c +++ b/components/bt/esp_ble_mesh/mesh_core/health_cli.c @@ -141,6 +141,11 @@ static void health_client_cancel(struct bt_mesh_model *model, bt_mesh_free_buf(val->fault_array); break; } + case OP_HEALTH_CURRENT_STATUS: { + struct bt_mesh_health_current_status *val = status; + bt_mesh_free_buf(val->fault_array); + break; + } default: break; } @@ -173,27 +178,23 @@ static void health_current_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { - bt_mesh_client_node_t *node = NULL; - u8_t test_id = 0U; - u16_t cid = 0U; + struct bt_mesh_health_current_status status = {0}; 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, bt_hex(buf->data, buf->len)); - /* Health current status is a publish message, sent to the user directly. */ - if (!(node = bt_mesh_is_client_recv_publish_msg(model, ctx, buf, true))) { + status.test_id = net_buf_simple_pull_u8(buf); + status.cid = net_buf_simple_pull_le16(buf); + status.fault_array = bt_mesh_alloc_buf(buf->len); + if (!status.fault_array) { + BT_ERR("%s, Out of memory", __func__); return; } - test_id = net_buf_simple_pull_u8(buf); - cid = net_buf_simple_pull_le16(buf); + net_buf_simple_add_mem(status.fault_array, buf->data, buf->len); - BT_DBG("Test ID 0x%02x Company ID 0x%04x Fault Count %u", - test_id, cid, buf->len); - - ((void) test_id); - ((void) cid); + health_client_cancel(model, ctx, &status, sizeof(struct bt_mesh_health_current_status)); } static void health_period_status(struct bt_mesh_model *model, From f11e347e2e0636d412fde012e6256ff974ee9b52 Mon Sep 17 00:00:00 2001 From: lly Date: Sun, 28 Jun 2020 15:28:22 +0800 Subject: [PATCH 37/60] ble_mesh: stack: Update client model msg send --- .../btc/btc_ble_mesh_config_model.c | 138 ++-- .../btc/btc_ble_mesh_health_model.c | 66 +- .../bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c | 19 +- .../bt/esp_ble_mesh/mesh_core/cfg_cli.c | 721 ++++++------------ .../bt/esp_ble_mesh/mesh_core/health_cli.c | 102 +-- .../esp_ble_mesh/mesh_core/include/cfg_cli.h | 149 ++-- .../mesh_core/include/health_cli.h | 16 +- .../mesh_models/client/client_common.c | 42 +- .../mesh_models/client/generic_client.c | 8 +- .../client/include/client_common.h | 10 +- .../mesh_models/client/lighting_client.c | 8 +- .../mesh_models/client/sensor_client.c | 4 +- .../mesh_models/client/time_scene_client.c | 8 +- 13 files changed, 498 insertions(+), 793 deletions(-) diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c index c9c48e713..1d18f4fb6 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c @@ -20,8 +20,6 @@ #include "cfg_cli.h" #include "esp_ble_mesh_config_model_api.h" -extern s32_t config_msg_timeout; - /* 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, @@ -383,7 +381,7 @@ void btc_ble_mesh_config_client_publish_callback(u32_t opcode, struct bt_mesh_mo 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) { - struct bt_mesh_msg_ctx ctx = {0}; + bt_mesh_client_common_param_t param = {0}; if (params == NULL) { BT_ERR("%s, Invalid parameter", __func__); @@ -410,63 +408,64 @@ static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param break; } - ctx.net_idx = params->ctx.net_idx; - ctx.app_idx = BLE_MESH_KEY_DEV; - ctx.addr = params->ctx.addr; - ctx.send_rel = params->ctx.send_rel; - ctx.send_ttl = params->ctx.send_ttl; + param.opcode = params->opcode; + param.model = (struct bt_mesh_model *)params->model; + param.ctx.net_idx = params->ctx.net_idx; + param.ctx.app_idx = BLE_MESH_KEY_DEV; + param.ctx.addr = params->ctx.addr; + param.ctx.send_rel = params->ctx.send_rel; + param.ctx.send_ttl = params->ctx.send_ttl; + param.msg_timeout = params->msg_timeout; - config_msg_timeout = params->msg_timeout; - - switch (params->opcode) { + switch (param.opcode) { case ESP_BLE_MESH_MODEL_OP_BEACON_GET: - return bt_mesh_cfg_beacon_get(&ctx); + return bt_mesh_cfg_beacon_get(¶m); case ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_GET: - return bt_mesh_cfg_ttl_get(&ctx); + return bt_mesh_cfg_ttl_get(¶m); case ESP_BLE_MESH_MODEL_OP_FRIEND_GET: - return bt_mesh_cfg_friend_get(&ctx); + return bt_mesh_cfg_friend_get(¶m); case ESP_BLE_MESH_MODEL_OP_GATT_PROXY_GET: - return bt_mesh_cfg_gatt_proxy_get(&ctx); + return bt_mesh_cfg_gatt_proxy_get(¶m); case ESP_BLE_MESH_MODEL_OP_RELAY_GET: - return bt_mesh_cfg_relay_get(&ctx); + return bt_mesh_cfg_relay_get(¶m); case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_GET: - return bt_mesh_cfg_mod_pub_get(&ctx, get->model_pub_get.element_addr, + return bt_mesh_cfg_mod_pub_get(¶m, 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 bt_mesh_cfg_hb_pub_get(&ctx); + return bt_mesh_cfg_hb_pub_get(¶m); case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_SUB_GET: - return bt_mesh_cfg_hb_sub_get(&ctx); + return bt_mesh_cfg_hb_sub_get(¶m); case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET: - return bt_mesh_cfg_comp_data_get(&ctx, get->comp_data_get.page); + return bt_mesh_cfg_comp_data_get(¶m, get->comp_data_get.page); case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET: - return bt_mesh_cfg_mod_sub_get(&ctx, get->sig_model_sub_get.element_addr, + return bt_mesh_cfg_mod_sub_get(¶m, 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 bt_mesh_cfg_mod_sub_get_vnd(&ctx, get->vnd_model_sub_get.element_addr, + return bt_mesh_cfg_mod_sub_get_vnd(¶m, 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 bt_mesh_cfg_net_key_get(&ctx); + return bt_mesh_cfg_net_key_get(¶m); case ESP_BLE_MESH_MODEL_OP_APP_KEY_GET: - return bt_mesh_cfg_app_key_get(&ctx, get->app_key_get.net_idx); + return bt_mesh_cfg_app_key_get(¶m, get->app_key_get.net_idx); case ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_GET: - return bt_mesh_cfg_node_identity_get(&ctx, get->node_identity_get.net_idx); + return bt_mesh_cfg_node_identity_get(¶m, get->node_identity_get.net_idx); case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET: - return bt_mesh_cfg_mod_app_get(&ctx, get->sig_model_app_get.element_addr, + return bt_mesh_cfg_mod_app_get(¶m, 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 bt_mesh_cfg_mod_app_get_vnd(&ctx, get->vnd_model_app_get.element_addr, + return bt_mesh_cfg_mod_app_get_vnd(¶m, 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 bt_mesh_cfg_kr_phase_get(&ctx, get->kr_phase_get.net_idx); + return bt_mesh_cfg_kr_phase_get(¶m, get->kr_phase_get.net_idx); case ESP_BLE_MESH_MODEL_OP_LPN_POLLTIMEOUT_GET: - return bt_mesh_cfg_lpn_timeout_get(&ctx, get->lpn_pollto_get.lpn_addr); + return bt_mesh_cfg_lpn_timeout_get(¶m, get->lpn_pollto_get.lpn_addr); case ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_GET: - return bt_mesh_cfg_net_transmit_get(&ctx); + return bt_mesh_cfg_net_transmit_get(¶m); default: - BT_ERR("Invalid Configuration Get opcode 0x%04x", params->opcode); + BT_ERR("Invalid Configuration Get opcode 0x%04x", param.opcode); return -EINVAL; } @@ -476,7 +475,7 @@ static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param 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) { - struct bt_mesh_msg_ctx ctx = {0}; + bt_mesh_client_common_param_t param = {0}; if (params == NULL) { BT_ERR("%s, Invalid parameter", __func__); @@ -488,35 +487,36 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param return -EINVAL; } - ctx.net_idx = params->ctx.net_idx; - ctx.app_idx = BLE_MESH_KEY_DEV; - ctx.addr = params->ctx.addr; - ctx.send_rel = params->ctx.send_rel; - ctx.send_ttl = params->ctx.send_ttl; + param.opcode = params->opcode; + param.model = (struct bt_mesh_model *)params->model; + param.ctx.net_idx = params->ctx.net_idx; + param.ctx.app_idx = BLE_MESH_KEY_DEV; + param.ctx.addr = params->ctx.addr; + param.ctx.send_rel = params->ctx.send_rel; + param.ctx.send_ttl = params->ctx.send_ttl; + param.msg_timeout = params->msg_timeout; - config_msg_timeout = params->msg_timeout; - - switch (params->opcode) { + switch (param.opcode) { case ESP_BLE_MESH_MODEL_OP_BEACON_SET: - return bt_mesh_cfg_beacon_set(&ctx, set->beacon_set.beacon); + return bt_mesh_cfg_beacon_set(¶m, set->beacon_set.beacon); case ESP_BLE_MESH_MODEL_OP_DEFAULT_TTL_SET: - return bt_mesh_cfg_ttl_set(&ctx, set->default_ttl_set.ttl); + return bt_mesh_cfg_ttl_set(¶m, set->default_ttl_set.ttl); case ESP_BLE_MESH_MODEL_OP_FRIEND_SET: - return bt_mesh_cfg_friend_set(&ctx, set->friend_set.friend_state); + return bt_mesh_cfg_friend_set(¶m, set->friend_set.friend_state); case ESP_BLE_MESH_MODEL_OP_GATT_PROXY_SET: - return bt_mesh_cfg_gatt_proxy_set(&ctx, set->gatt_proxy_set.gatt_proxy); + return bt_mesh_cfg_gatt_proxy_set(¶m, set->gatt_proxy_set.gatt_proxy); case ESP_BLE_MESH_MODEL_OP_RELAY_SET: - return bt_mesh_cfg_relay_set(&ctx, set->relay_set.relay, + return bt_mesh_cfg_relay_set(¶m, set->relay_set.relay, set->relay_set.relay_retransmit); case ESP_BLE_MESH_MODEL_OP_NET_KEY_ADD: - return bt_mesh_cfg_net_key_add(&ctx, set->net_key_add.net_idx, + return bt_mesh_cfg_net_key_add(¶m, set->net_key_add.net_idx, &set->net_key_add.net_key[0]); case ESP_BLE_MESH_MODEL_OP_APP_KEY_ADD: - return bt_mesh_cfg_app_key_add(&ctx, set->app_key_add.net_idx, + return bt_mesh_cfg_app_key_add(¶m, 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 bt_mesh_cfg_mod_app_bind(&ctx, set->model_app_bind.element_addr, + return bt_mesh_cfg_mod_app_bind(¶m, 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); @@ -529,46 +529,46 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param .period = set->model_pub_set.publish_period, .transmit = set->model_pub_set.publish_retransmit, }; - return bt_mesh_cfg_mod_pub_set(&ctx, set->model_pub_set.element_addr, + return bt_mesh_cfg_mod_pub_set(¶m, 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 bt_mesh_cfg_mod_sub_add(&ctx, set->model_sub_add.element_addr, + return bt_mesh_cfg_mod_sub_add(¶m, 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 bt_mesh_cfg_mod_sub_del(&ctx, set->model_sub_delete.element_addr, + return bt_mesh_cfg_mod_sub_del(¶m, 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 bt_mesh_cfg_mod_sub_overwrite(&ctx, set->model_sub_overwrite.element_addr, + return bt_mesh_cfg_mod_sub_overwrite(¶m, 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 bt_mesh_cfg_mod_sub_va_add(&ctx, set->model_sub_va_add.element_addr, + return bt_mesh_cfg_mod_sub_va_add(¶m, 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 bt_mesh_cfg_mod_sub_va_overwrite(&ctx, set->model_sub_va_overwrite.element_addr, + return bt_mesh_cfg_mod_sub_va_overwrite(¶m, 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 bt_mesh_cfg_mod_sub_va_del(&ctx, set->model_sub_va_delete.element_addr, + return bt_mesh_cfg_mod_sub_va_del(¶m, 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 bt_mesh_cfg_hb_sub_set(&ctx, (struct bt_mesh_cfg_hb_sub *)&set->heartbeat_sub_set); + return bt_mesh_cfg_hb_sub_set(¶m, (struct bt_mesh_cfg_hb_sub *)&set->heartbeat_sub_set); case ESP_BLE_MESH_MODEL_OP_HEARTBEAT_PUB_SET: - return bt_mesh_cfg_hb_pub_set(&ctx, (const struct bt_mesh_cfg_hb_pub *)&set->heartbeat_pub_set); + return bt_mesh_cfg_hb_pub_set(¶m, (struct bt_mesh_cfg_hb_pub *)&set->heartbeat_pub_set); case ESP_BLE_MESH_MODEL_OP_NODE_RESET: - return bt_mesh_cfg_node_reset(&ctx); + return bt_mesh_cfg_node_reset(¶m); case ESP_BLE_MESH_MODEL_OP_MODEL_PUB_VIRTUAL_ADDR_SET: { struct bt_mesh_cfg_mod_pub model_pub = { .app_idx = set->model_pub_va_set.publish_app_idx, @@ -577,42 +577,42 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param .period = set->model_pub_va_set.publish_period, .transmit = set->model_pub_va_set.publish_retransmit, }; - return bt_mesh_cfg_mod_pub_va_set(&ctx, set->model_pub_va_set.element_addr, + return bt_mesh_cfg_mod_pub_va_set(¶m, 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 bt_mesh_cfg_mod_sub_del_all(&ctx, set->model_sub_delete_all.element_addr, + return bt_mesh_cfg_mod_sub_del_all(¶m, 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 bt_mesh_cfg_net_key_update(&ctx, set->net_key_update.net_idx, + return bt_mesh_cfg_net_key_update(¶m, set->net_key_update.net_idx, set->net_key_update.net_key); case ESP_BLE_MESH_MODEL_OP_NET_KEY_DELETE: - return bt_mesh_cfg_net_key_delete(&ctx, set->net_key_delete.net_idx); + return bt_mesh_cfg_net_key_delete(¶m, set->net_key_delete.net_idx); case ESP_BLE_MESH_MODEL_OP_APP_KEY_UPDATE: - return bt_mesh_cfg_app_key_update(&ctx, set->app_key_update.net_idx, + return bt_mesh_cfg_app_key_update(¶m, 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 bt_mesh_cfg_app_key_delete(&ctx, set->app_key_delete.net_idx, + return bt_mesh_cfg_app_key_delete(¶m, set->app_key_delete.net_idx, set->app_key_delete.app_idx); case ESP_BLE_MESH_MODEL_OP_NODE_IDENTITY_SET: - return bt_mesh_cfg_node_identity_set(&ctx, set->node_identity_set.net_idx, + return bt_mesh_cfg_node_identity_set(¶m, set->node_identity_set.net_idx, set->node_identity_set.identity); case ESP_BLE_MESH_MODEL_OP_MODEL_APP_UNBIND: - return bt_mesh_cfg_mod_app_unbind(&ctx, set->model_app_unbind.element_addr, + return bt_mesh_cfg_mod_app_unbind(¶m, 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 bt_mesh_cfg_kr_phase_set(&ctx, set->kr_phase_set.net_idx, + return bt_mesh_cfg_kr_phase_set(¶m, set->kr_phase_set.net_idx, set->kr_phase_set.transition); case ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_SET: - return bt_mesh_cfg_net_transmit_set(&ctx, set->net_transmit_set.net_transmit); + return bt_mesh_cfg_net_transmit_set(¶m, set->net_transmit_set.net_transmit); default: - BT_ERR("Invalid Configuration Set opcode 0x%04x", params->opcode); + BT_ERR("Invalid Configuration Set opcode 0x%04x", param.opcode); return -EINVAL; } diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c index 41aa9c9e5..240f318aa 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c @@ -21,8 +21,6 @@ #include "health_cli.h" #include "esp_ble_mesh_health_model_api.h" -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, @@ -317,7 +315,7 @@ void btc_ble_mesh_health_publish_callback(u32_t opcode, struct bt_mesh_model *mo 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) { - struct bt_mesh_msg_ctx ctx = {0}; + bt_mesh_client_common_param_t param = {0}; if (params == NULL) { BT_ERR("%s, Invalid parameter", __func__); @@ -329,23 +327,24 @@ static int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param 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; + param.opcode = params->opcode; + param.model = (struct bt_mesh_model *)params->model; + param.ctx.net_idx = params->ctx.net_idx; + param.ctx.app_idx = params->ctx.app_idx; + param.ctx.addr = params->ctx.addr; + param.ctx.send_rel = params->ctx.send_rel; + param.ctx.send_ttl = params->ctx.send_ttl; + param.msg_timeout = params->msg_timeout; - health_msg_timeout = params->msg_timeout; - - switch (params->opcode) { + switch (param.opcode) { case ESP_BLE_MESH_MODEL_OP_ATTENTION_GET: - return bt_mesh_health_attention_get(&ctx); + return bt_mesh_health_attention_get(¶m); case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_GET: - return bt_mesh_health_period_get(&ctx); + return bt_mesh_health_period_get(¶m); case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET: - return bt_mesh_health_fault_get(&ctx, get->fault_get.company_id); + return bt_mesh_health_fault_get(¶m, get->fault_get.company_id); default: - BT_ERR("Invalid Health Get opcode 0x%04x", params->opcode); + BT_ERR("Invalid Health Get opcode 0x%04x", param.opcode); return -EINVAL; } @@ -355,40 +354,41 @@ static int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param 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) { - struct bt_mesh_msg_ctx ctx = {0}; + bt_mesh_client_common_param_t param = {0}; if (params == NULL || set == NULL) { BT_ERR("%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; + param.opcode = params->opcode; + param.model = (struct bt_mesh_model *)params->model; + param.ctx.net_idx = params->ctx.net_idx; + param.ctx.app_idx = params->ctx.app_idx; + param.ctx.addr = params->ctx.addr; + param.ctx.send_rel = params->ctx.send_rel; + param.ctx.send_ttl = params->ctx.send_ttl; + param.msg_timeout = params->msg_timeout; - health_msg_timeout = params->msg_timeout; - - switch (params->opcode) { + switch (param.opcode) { case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET: - return bt_mesh_health_attention_set(&ctx, set->attention_set.attention, true); + return bt_mesh_health_attention_set(¶m, set->attention_set.attention, true); case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET_UNACK: - return bt_mesh_health_attention_set(&ctx, set->attention_set.attention, false); + return bt_mesh_health_attention_set(¶m, set->attention_set.attention, false); case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET: - return bt_mesh_health_period_set(&ctx, set->period_set.fast_period_divisor, true); + return bt_mesh_health_period_set(¶m, set->period_set.fast_period_divisor, true); case ESP_BLE_MESH_MODEL_OP_HEALTH_PERIOD_SET_UNACK: - return bt_mesh_health_period_set(&ctx, set->period_set.fast_period_divisor, false); + return bt_mesh_health_period_set(¶m, set->period_set.fast_period_divisor, false); case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST: - return bt_mesh_health_fault_test(&ctx, set->fault_test.company_id, set->fault_test.test_id, true); + return bt_mesh_health_fault_test(¶m, set->fault_test.company_id, set->fault_test.test_id, true); case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST_UNACK: - return bt_mesh_health_fault_test(&ctx, set->fault_test.company_id, set->fault_test.test_id, false); + return bt_mesh_health_fault_test(¶m, set->fault_test.company_id, set->fault_test.test_id, false); case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR: - return bt_mesh_health_fault_clear(&ctx, set->fault_clear.company_id, true); + return bt_mesh_health_fault_clear(¶m, set->fault_clear.company_id, true); case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR_UNACK: - return bt_mesh_health_fault_clear(&ctx, set->fault_clear.company_id, false); + return bt_mesh_health_fault_clear(¶m, set->fault_clear.company_id, false); default: - BT_ERR("Invalid Health Set opcode 0x%04x", params->opcode); + BT_ERR("Invalid Health Set opcode 0x%04x", param.opcode); return -EINVAL; } diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c index ab1aba587..87026a62e 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c @@ -2016,18 +2016,25 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg) 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_client_model_role(&common)) { BT_ERR("Failed to set model role"); break; } - err = bt_mesh_client_send_msg((struct bt_mesh_model *)arg->model_send.model, - arg->model_send.opcode, - (struct bt_mesh_msg_ctx *)arg->model_send.ctx, buf, - btc_ble_mesh_client_model_timeout_cb, arg->model_send.msg_timeout, - arg->model_send.need_rsp, NULL, NULL); + bt_mesh_client_common_param_t param = { + .opcode = arg->model_send.opcode, + .model = (struct bt_mesh_model *)arg->model_send.model, + .ctx.net_idx = arg->model_send.ctx->net_idx, + .ctx.app_idx = arg->model_send.ctx->app_idx, + .ctx.addr = arg->model_send.ctx->addr, + .ctx.send_rel = arg->model_send.ctx->send_rel, + .ctx.send_ttl = arg->model_send.ctx->send_ttl, + .ctx.srv_send = false, + .msg_timeout = arg->model_send.msg_timeout, + }; + err = bt_mesh_client_send_msg(¶m, buf, arg->model_send.need_rsp, + btc_ble_mesh_client_model_timeout_cb); bt_mesh_free_buf(buf); btc_ble_mesh_model_send_comp_cb(arg->model_send.model, arg->model_send.ctx, arg->model_send.opcode, err); diff --git a/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c b/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c index 628d501d9..4e0c9f1dc 100644 --- a/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c +++ b/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c @@ -20,9 +20,6 @@ #include "mesh_common.h" #include "cfg_cli.h" -/* 2 byte dummy opcode for getting compile time buffer sizes. */ -#define DUMMY_2_BYTE_OP BLE_MESH_MODEL_OP_2(0xff, 0xff) - s32_t config_msg_timeout; static bt_mesh_config_client_t *cli; @@ -681,37 +678,14 @@ const struct bt_mesh_model_op bt_mesh_cfg_cli_op[] = { BLE_MESH_MODEL_OP_END, }; -int bt_mesh_cfg_comp_data_get(struct bt_mesh_msg_ctx *ctx, u8_t page) +static int send_msg_with_none(bt_mesh_client_common_param_t *param, u32_t op) { - BLE_MESH_MODEL_BUF_DEFINE(msg, OP_DEV_COMP_DATA_GET, 1); - int err = 0; - - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - bt_mesh_model_msg_init(&msg, OP_DEV_COMP_DATA_GET); - net_buf_simple_add_u8(&msg, page); - - err = bt_mesh_client_send_msg(cli->model, OP_DEV_COMP_DATA_GET, ctx, - &msg, timeout_handler, config_msg_timeout, - true, NULL, NULL); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; -} - -static int get_state_u8(struct bt_mesh_msg_ctx *ctx, u32_t op) -{ - BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 0); + BLE_MESH_MODEL_BUF_DEFINE(msg, op, 0); int err = 0; bt_mesh_model_msg_init(&msg, op); - err = bt_mesh_client_send_msg(cli->model, op, ctx, &msg, timeout_handler, - config_msg_timeout, true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -719,16 +693,15 @@ static int get_state_u8(struct bt_mesh_msg_ctx *ctx, u32_t op) return err; } -static int set_state_u8(struct bt_mesh_msg_ctx *ctx, u32_t op, u8_t new_val) +static int send_msg_with_u8(bt_mesh_client_common_param_t *param, u32_t op, u8_t val) { - BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 1); + BLE_MESH_MODEL_BUF_DEFINE(msg, op, 1); int err = 0; bt_mesh_model_msg_init(&msg, op); - net_buf_simple_add_u8(&msg, new_val); + net_buf_simple_add_u8(&msg, val); - err = bt_mesh_client_send_msg(cli->model, op, ctx, &msg, timeout_handler, - config_msg_timeout, true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -736,84 +709,15 @@ static int set_state_u8(struct bt_mesh_msg_ctx *ctx, u32_t op, u8_t new_val) return err; } -int bt_mesh_cfg_beacon_get(struct bt_mesh_msg_ctx *ctx) +static int send_msg_with_le16(bt_mesh_client_common_param_t *param, u32_t op, u16_t val) { - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return get_state_u8(ctx, OP_BEACON_GET); -} - -int bt_mesh_cfg_beacon_set(struct bt_mesh_msg_ctx *ctx, u8_t val) -{ - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return set_state_u8(ctx, OP_BEACON_SET, val); -} - -int bt_mesh_cfg_ttl_get(struct bt_mesh_msg_ctx *ctx) -{ - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return get_state_u8(ctx, OP_DEFAULT_TTL_GET); -} - -int bt_mesh_cfg_ttl_set(struct bt_mesh_msg_ctx *ctx, u8_t val) -{ - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return set_state_u8(ctx, OP_DEFAULT_TTL_SET, val); -} - -int bt_mesh_cfg_friend_get(struct bt_mesh_msg_ctx *ctx) -{ - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return get_state_u8(ctx, OP_FRIEND_GET); -} - -int bt_mesh_cfg_friend_set(struct bt_mesh_msg_ctx *ctx, u8_t val) -{ - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return set_state_u8(ctx, OP_FRIEND_SET, val); -} - -int bt_mesh_cfg_gatt_proxy_get(struct bt_mesh_msg_ctx *ctx) -{ - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return get_state_u8(ctx, OP_GATT_PROXY_GET); -} - -int bt_mesh_cfg_gatt_proxy_set(struct bt_mesh_msg_ctx *ctx, u8_t val) -{ - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return set_state_u8(ctx, OP_GATT_PROXY_SET, val); -} - -int bt_mesh_cfg_relay_get(struct bt_mesh_msg_ctx *ctx) -{ - BLE_MESH_MODEL_BUF_DEFINE(msg, OP_RELAY_GET, 0); + BLE_MESH_MODEL_BUF_DEFINE(msg, op, 2); int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } + bt_mesh_model_msg_init(&msg, op); + net_buf_simple_add_le16(&msg, val); - bt_mesh_model_msg_init(&msg, OP_RELAY_GET); - - err = bt_mesh_client_send_msg(cli->model, OP_RELAY_GET, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -821,23 +725,71 @@ int bt_mesh_cfg_relay_get(struct bt_mesh_msg_ctx *ctx) return err; } -int bt_mesh_cfg_relay_set(struct bt_mesh_msg_ctx *ctx, u8_t new_relay, - u8_t new_transmit) +int bt_mesh_cfg_comp_data_get(bt_mesh_client_common_param_t *param, u8_t page) +{ + return send_msg_with_u8(param, OP_DEV_COMP_DATA_GET, page); +} + +int bt_mesh_cfg_beacon_get(bt_mesh_client_common_param_t *param) +{ + return send_msg_with_none(param, OP_BEACON_GET); +} + +int bt_mesh_cfg_beacon_set(bt_mesh_client_common_param_t *param, u8_t val) +{ + if (val > 0x01) { + BT_ERR("Invalid beacon state 0x%02x", val); + return -EINVAL; + } + return send_msg_with_u8(param, OP_BEACON_SET, val); +} + +int bt_mesh_cfg_ttl_get(bt_mesh_client_common_param_t *param) +{ + return send_msg_with_none(param, OP_DEFAULT_TTL_GET); +} + +int bt_mesh_cfg_ttl_set(bt_mesh_client_common_param_t *param, u8_t val) +{ + return send_msg_with_u8(param, OP_DEFAULT_TTL_SET, val); +} + +int bt_mesh_cfg_friend_get(bt_mesh_client_common_param_t *param) +{ + return send_msg_with_none(param, OP_FRIEND_GET); +} + +int bt_mesh_cfg_friend_set(bt_mesh_client_common_param_t *param, u8_t val) +{ + return send_msg_with_u8(param, OP_FRIEND_SET, val); +} + +int bt_mesh_cfg_gatt_proxy_get(bt_mesh_client_common_param_t *param) +{ + return send_msg_with_none(param, OP_GATT_PROXY_GET); +} + +int bt_mesh_cfg_gatt_proxy_set(bt_mesh_client_common_param_t *param, u8_t val) +{ + return send_msg_with_u8(param, OP_GATT_PROXY_SET, val); +} + +int bt_mesh_cfg_relay_get(bt_mesh_client_common_param_t *param) +{ + return send_msg_with_none(param, OP_RELAY_GET); +} + +int bt_mesh_cfg_relay_set(bt_mesh_client_common_param_t *param, + u8_t relay, u8_t retransmit) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_RELAY_SET, 2); int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - bt_mesh_model_msg_init(&msg, OP_RELAY_SET); - net_buf_simple_add_u8(&msg, new_relay); - net_buf_simple_add_u8(&msg, new_transmit); + net_buf_simple_add_u8(&msg, relay); + net_buf_simple_add_u8(&msg, retransmit); - err = bt_mesh_client_send_msg(cli->model, OP_RELAY_SET, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -845,23 +797,22 @@ int bt_mesh_cfg_relay_set(struct bt_mesh_msg_ctx *ctx, u8_t new_relay, return err; } -int bt_mesh_cfg_net_key_add(struct bt_mesh_msg_ctx *ctx, u16_t key_net_idx, - const u8_t net_key[16]) +int bt_mesh_cfg_net_key_add(bt_mesh_client_common_param_t *param, + u16_t net_idx, const u8_t net_key[16]) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_ADD, 18); int err = 0; - if (!ctx || !ctx->addr || !net_key) { + if (!net_key) { + BT_ERR("Invalid NetKey"); return -EINVAL; } bt_mesh_model_msg_init(&msg, OP_NET_KEY_ADD); - net_buf_simple_add_le16(&msg, key_net_idx); + net_buf_simple_add_le16(&msg, net_idx); net_buf_simple_add_mem(&msg, net_key, 16); - err = bt_mesh_client_send_msg(cli->model, OP_NET_KEY_ADD, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -869,23 +820,23 @@ int bt_mesh_cfg_net_key_add(struct bt_mesh_msg_ctx *ctx, u16_t key_net_idx, return err; } -int bt_mesh_cfg_app_key_add(struct bt_mesh_msg_ctx *ctx, u16_t key_net_idx, - u16_t key_app_idx, const u8_t app_key[16]) +int bt_mesh_cfg_app_key_add(bt_mesh_client_common_param_t *param, + u16_t net_idx, u16_t app_idx, + const u8_t app_key[16]) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_ADD, 19); int err = 0; - if (!ctx || !ctx->addr || !app_key) { + if (!app_key) { + BT_ERR("Invalid AppKey"); return -EINVAL; } bt_mesh_model_msg_init(&msg, OP_APP_KEY_ADD); - key_idx_pack(&msg, key_net_idx, key_app_idx); + key_idx_pack(&msg, net_idx, app_idx); net_buf_simple_add_mem(&msg, app_key, 16); - err = bt_mesh_client_send_msg(cli->model, OP_APP_KEY_ADD, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -893,27 +844,22 @@ int bt_mesh_cfg_app_key_add(struct bt_mesh_msg_ctx *ctx, u16_t key_net_idx, return err; } -int bt_mesh_cfg_mod_app_bind(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_app_idx, u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_app_bind(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t app_idx, + u16_t mod_id, u16_t cid) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_APP_BIND, 8); int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - bt_mesh_model_msg_init(&msg, OP_MOD_APP_BIND); net_buf_simple_add_le16(&msg, elem_addr); - net_buf_simple_add_le16(&msg, mod_app_idx); + net_buf_simple_add_le16(&msg, app_idx); if (cid != BLE_MESH_CID_NVAL) { net_buf_simple_add_le16(&msg, cid); } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(cli->model, OP_MOD_APP_BIND, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -921,10 +867,11 @@ int bt_mesh_cfg_mod_app_bind(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, return err; } -static int mod_sub(u32_t op, struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t sub_addr, u16_t mod_id, u16_t cid) +static int mod_sub(bt_mesh_client_common_param_t *param, u32_t op, + u16_t elem_addr, u16_t sub_addr, + u16_t mod_id, u16_t cid) { - BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 8); + BLE_MESH_MODEL_BUF_DEFINE(msg, op, 8); int err = 0; bt_mesh_model_msg_init(&msg, op); @@ -935,8 +882,7 @@ static int mod_sub(u32_t op, struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(cli->model, op, ctx, &msg, timeout_handler, - config_msg_timeout, true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -944,41 +890,40 @@ static int mod_sub(u32_t op, struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, return err; } -int bt_mesh_cfg_mod_sub_add(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t sub_addr, u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_sub_add(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t sub_addr, + u16_t mod_id, u16_t cid) { - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return mod_sub(OP_MOD_SUB_ADD, ctx, elem_addr, sub_addr, mod_id, cid); + return mod_sub(param, OP_MOD_SUB_ADD, elem_addr, sub_addr, mod_id, cid); } -int bt_mesh_cfg_mod_sub_del(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t sub_addr, u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_sub_del(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t sub_addr, + u16_t mod_id, u16_t cid) { - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return mod_sub(OP_MOD_SUB_DEL, ctx, elem_addr, sub_addr, mod_id, cid); + return mod_sub(param, OP_MOD_SUB_DEL, elem_addr, sub_addr, mod_id, cid); } -int bt_mesh_cfg_mod_sub_overwrite(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t sub_addr, u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_sub_overwrite(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t sub_addr, + u16_t mod_id, u16_t cid) { - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return mod_sub(OP_MOD_SUB_OVERWRITE, ctx, elem_addr, sub_addr, mod_id, cid); + return mod_sub(param, OP_MOD_SUB_OVERWRITE, elem_addr, sub_addr, mod_id, cid); } -static int mod_sub_va(u32_t op, struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - const u8_t label[16], u16_t mod_id, u16_t cid) +static int mod_sub_va(bt_mesh_client_common_param_t *param, u32_t op, + u16_t elem_addr, const u8_t label[16], + u16_t mod_id, u16_t cid) { - BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 22); + BLE_MESH_MODEL_BUF_DEFINE(msg, op, 22); int err = 0; - BT_DBG("net_idx 0x%04x addr 0x%04x elem_addr 0x%04x label %s", - ctx->net_idx, ctx->addr, elem_addr, label); + if (!label) { + BT_ERR("Invalid label uuid"); + return -EINVAL; + } + + BT_DBG("elem_addr 0x%04x label %s", elem_addr, bt_hex(label, 16)); BT_DBG("mod_id 0x%04x cid 0x%04x", mod_id, cid); bt_mesh_model_msg_init(&msg, op); @@ -989,8 +934,7 @@ static int mod_sub_va(u32_t op, struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(cli->model, op, ctx, &msg, timeout_handler, - config_msg_timeout, true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -998,43 +942,33 @@ static int mod_sub_va(u32_t op, struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, return err; } -int bt_mesh_cfg_mod_sub_va_add(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - const u8_t label[16], u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_sub_va_add(bt_mesh_client_common_param_t *param, + u16_t elem_addr, const u8_t label[16], + u16_t mod_id, u16_t cid) { - if (!ctx || !ctx->addr || !label) { - return -EINVAL; - } - return mod_sub_va(OP_MOD_SUB_VA_ADD, ctx, elem_addr, label, mod_id, cid); + return mod_sub_va(param, OP_MOD_SUB_VA_ADD, elem_addr, label, mod_id, cid); } -int bt_mesh_cfg_mod_sub_va_del(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - const u8_t label[16], u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_sub_va_del(bt_mesh_client_common_param_t *param, + u16_t elem_addr, const u8_t label[16], + u16_t mod_id, u16_t cid) { - if (!ctx || !ctx->addr || !label) { - return -EINVAL; - } - return mod_sub_va(OP_MOD_SUB_VA_DEL, ctx, elem_addr, label, mod_id, cid); + return mod_sub_va(param, OP_MOD_SUB_VA_DEL, elem_addr, label, mod_id, cid); } -int bt_mesh_cfg_mod_sub_va_overwrite(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - const u8_t label[16], u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_sub_va_overwrite(bt_mesh_client_common_param_t *param, + u16_t elem_addr, const u8_t label[16], + u16_t mod_id, u16_t cid) { - if (!ctx || !ctx->addr || !label) { - return -EINVAL; - } - return mod_sub_va(OP_MOD_SUB_VA_OVERWRITE, ctx, elem_addr, label, mod_id, cid); + return mod_sub_va(param, OP_MOD_SUB_VA_OVERWRITE, elem_addr, label, mod_id, cid); } -int bt_mesh_cfg_mod_pub_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_pub_get(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, u16_t cid) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_PUB_GET, 6); int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - bt_mesh_model_msg_init(&msg, OP_MOD_PUB_GET); net_buf_simple_add_le16(&msg, elem_addr); if (cid != BLE_MESH_CID_NVAL) { @@ -1042,9 +976,7 @@ int bt_mesh_cfg_mod_pub_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(cli->model, OP_MOD_PUB_GET, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1052,14 +984,15 @@ int bt_mesh_cfg_mod_pub_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, return err; } -int bt_mesh_cfg_mod_pub_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid, +int bt_mesh_cfg_mod_pub_set(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, u16_t cid, struct bt_mesh_cfg_mod_pub *pub) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_PUB_SET, 13); int err = 0; - if (!ctx || !ctx->addr || !pub) { + if (!pub) { + BT_ERR("Invalid model pub set"); return -EINVAL; } @@ -1075,9 +1008,7 @@ int bt_mesh_cfg_mod_pub_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(cli->model, OP_MOD_PUB_SET, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1085,13 +1016,14 @@ int bt_mesh_cfg_mod_pub_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, return err; } -int bt_mesh_cfg_hb_sub_set(struct bt_mesh_msg_ctx *ctx, +int bt_mesh_cfg_hb_sub_set(bt_mesh_client_common_param_t *param, struct bt_mesh_cfg_hb_sub *sub) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_SUB_SET, 5); int err = 0; - if (!ctx || !ctx->addr || !sub) { + if (!sub) { + BT_ERR("Invalid heartbeat sub set"); return -EINVAL; } @@ -1100,9 +1032,7 @@ int bt_mesh_cfg_hb_sub_set(struct bt_mesh_msg_ctx *ctx, net_buf_simple_add_le16(&msg, sub->dst); net_buf_simple_add_u8(&msg, sub->period); - err = bt_mesh_client_send_msg(cli->model, OP_HEARTBEAT_SUB_SET, ctx, - &msg, timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1110,34 +1040,19 @@ int bt_mesh_cfg_hb_sub_set(struct bt_mesh_msg_ctx *ctx, return err; } -int bt_mesh_cfg_hb_sub_get(struct bt_mesh_msg_ctx *ctx) +int bt_mesh_cfg_hb_sub_get(bt_mesh_client_common_param_t *param) { - BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_SUB_GET, 0); - int err = 0; - - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - bt_mesh_model_msg_init(&msg, OP_HEARTBEAT_SUB_GET); - - err = bt_mesh_client_send_msg(cli->model, OP_HEARTBEAT_SUB_GET, ctx, - &msg, timeout_handler, config_msg_timeout, - true, NULL, NULL); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return send_msg_with_none(param, OP_HEARTBEAT_SUB_GET); } -int bt_mesh_cfg_hb_pub_set(struct bt_mesh_msg_ctx *ctx, - const struct bt_mesh_cfg_hb_pub *pub) +int bt_mesh_cfg_hb_pub_set(bt_mesh_client_common_param_t *param, + struct bt_mesh_cfg_hb_pub *pub) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_PUB_SET, 9); int err = 0; - if (!ctx || !ctx->addr || !pub) { + if (!pub) { + BT_ERR("Invalid heartbeat pub set"); return -EINVAL; } @@ -1149,9 +1064,7 @@ int bt_mesh_cfg_hb_pub_set(struct bt_mesh_msg_ctx *ctx, net_buf_simple_add_le16(&msg, pub->feat); net_buf_simple_add_le16(&msg, pub->net_idx); - err = bt_mesh_client_send_msg(cli->model, OP_HEARTBEAT_PUB_SET, ctx, - &msg, timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1159,56 +1072,26 @@ int bt_mesh_cfg_hb_pub_set(struct bt_mesh_msg_ctx *ctx, return err; } -int bt_mesh_cfg_hb_pub_get(struct bt_mesh_msg_ctx *ctx) +int bt_mesh_cfg_hb_pub_get(bt_mesh_client_common_param_t *param) { - BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_PUB_GET, 0); - int err = 0; - - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - bt_mesh_model_msg_init(&msg, OP_HEARTBEAT_PUB_GET); - - err = bt_mesh_client_send_msg(cli->model, OP_HEARTBEAT_PUB_GET, ctx, - &msg, timeout_handler, config_msg_timeout, - true, NULL, NULL); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return send_msg_with_none(param, OP_HEARTBEAT_PUB_GET); } -int bt_mesh_cfg_node_reset(struct bt_mesh_msg_ctx *ctx) +int bt_mesh_cfg_node_reset(bt_mesh_client_common_param_t *param) { - BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NODE_RESET, 0); - int err = 0; - - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - bt_mesh_model_msg_init(&msg, OP_NODE_RESET); - - err = bt_mesh_client_send_msg(cli->model, OP_NODE_RESET, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return send_msg_with_none(param, OP_NODE_RESET); } -int bt_mesh_cfg_mod_pub_va_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid, const u8_t label[16], +int bt_mesh_cfg_mod_pub_va_set(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, + u16_t cid, const u8_t label[16], struct bt_mesh_cfg_mod_pub *pub) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_PUB_VA_SET, 27); int err = 0; - if (!ctx || !ctx->addr || !label || !pub) { + if (!label || !pub) { + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } @@ -1224,9 +1107,7 @@ int bt_mesh_cfg_mod_pub_va_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(cli->model, OP_MOD_PUB_VA_SET, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1234,16 +1115,12 @@ int bt_mesh_cfg_mod_pub_va_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, return err; } -int bt_mesh_cfg_mod_sub_del_all(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_sub_del_all(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, u16_t cid) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_SUB_DEL_ALL, 6); int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - bt_mesh_model_msg_init(&msg, OP_MOD_SUB_DEL_ALL); net_buf_simple_add_le16(&msg, elem_addr); if (cid != BLE_MESH_CID_NVAL) { @@ -1251,9 +1128,7 @@ int bt_mesh_cfg_mod_sub_del_all(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(cli->model, OP_MOD_SUB_DEL_ALL, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1261,10 +1136,10 @@ int bt_mesh_cfg_mod_sub_del_all(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, return err; } -static int mod_sub_get(u32_t op, struct bt_mesh_msg_ctx *ctx, +static int mod_sub_get(bt_mesh_client_common_param_t *param, u32_t op, u16_t elem_addr, u16_t mod_id, u16_t cid) { - BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 6); + BLE_MESH_MODEL_BUF_DEFINE(msg, op, 6); int err = 0; bt_mesh_model_msg_init(&msg, op); @@ -1274,8 +1149,7 @@ static int mod_sub_get(u32_t op, struct bt_mesh_msg_ctx *ctx, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(cli->model, op, ctx, &msg, timeout_handler, - config_msg_timeout, true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1283,30 +1157,30 @@ static int mod_sub_get(u32_t op, struct bt_mesh_msg_ctx *ctx, return err; } -int bt_mesh_cfg_mod_sub_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, u16_t mod_id) +int bt_mesh_cfg_mod_sub_get(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id) { - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return mod_sub_get(OP_MOD_SUB_GET, ctx, elem_addr, mod_id, BLE_MESH_CID_NVAL); + return mod_sub_get(param, OP_MOD_SUB_GET, elem_addr, mod_id, BLE_MESH_CID_NVAL); } -int bt_mesh_cfg_mod_sub_get_vnd(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_sub_get_vnd(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, u16_t cid) { - if (!ctx || !ctx->addr || cid == BLE_MESH_CID_NVAL) { + if (cid == BLE_MESH_CID_NVAL) { + BT_ERR("Invalid company id"); return -EINVAL; } - return mod_sub_get(OP_MOD_SUB_GET_VND, ctx, elem_addr, mod_id, cid); + return mod_sub_get(param, OP_MOD_SUB_GET_VND, elem_addr, mod_id, cid); } -int bt_mesh_cfg_net_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, - const u8_t net_key[16]) +int bt_mesh_cfg_net_key_update(bt_mesh_client_common_param_t *param, + u16_t net_idx, const u8_t net_key[16]) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_UPDATE, 18); int err = 0; - if (!ctx || !ctx->addr || !net_key) { + if (!net_key) { + BT_ERR("Invalid NetKey"); return -EINVAL; } @@ -1314,9 +1188,7 @@ int bt_mesh_cfg_net_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, net_buf_simple_add_le16(&msg, net_idx); net_buf_simple_add_mem(&msg, net_key, 16); - err = bt_mesh_client_send_msg(cli->model, OP_NET_KEY_UPDATE, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1324,56 +1196,25 @@ int bt_mesh_cfg_net_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, return err; } -int bt_mesh_cfg_net_key_delete(struct bt_mesh_msg_ctx *ctx, u16_t net_idx) +int bt_mesh_cfg_net_key_delete(bt_mesh_client_common_param_t *param, u16_t net_idx) { - BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_DEL, 2); - int err = 0; - - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - bt_mesh_model_msg_init(&msg, OP_NET_KEY_DEL); - net_buf_simple_add_le16(&msg, net_idx); - - err = bt_mesh_client_send_msg(cli->model, OP_NET_KEY_DEL, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return send_msg_with_le16(param, OP_NET_KEY_DEL, net_idx); } -int bt_mesh_cfg_net_key_get(struct bt_mesh_msg_ctx *ctx) +int bt_mesh_cfg_net_key_get(bt_mesh_client_common_param_t *param) { - BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_GET, 0); - int err = 0; - - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - bt_mesh_model_msg_init(&msg, OP_NET_KEY_GET); - - err = bt_mesh_client_send_msg(cli->model, OP_NET_KEY_GET, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return send_msg_with_none(param, OP_NET_KEY_GET); } -int bt_mesh_cfg_app_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, - u16_t app_idx, const u8_t app_key[16]) +int bt_mesh_cfg_app_key_update(bt_mesh_client_common_param_t *param, + u16_t net_idx, u16_t app_idx, + const u8_t app_key[16]) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_UPDATE, 19); int err = 0; - if (!ctx || !ctx->addr || !app_key) { + if (!app_key) { + BT_ERR("Invalid AppKey"); return -EINVAL; } @@ -1381,9 +1222,7 @@ int bt_mesh_cfg_app_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, key_idx_pack(&msg, net_idx, app_idx); net_buf_simple_add_mem(&msg, app_key, 16); - err = bt_mesh_client_send_msg(cli->model, OP_APP_KEY_UPDATE, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1391,21 +1230,16 @@ int bt_mesh_cfg_app_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, return err; } -int bt_mesh_cfg_app_key_delete(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, u16_t app_idx) +int bt_mesh_cfg_app_key_delete(bt_mesh_client_common_param_t *param, + u16_t net_idx, u16_t app_idx) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_DEL, 3); int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - bt_mesh_model_msg_init(&msg, OP_APP_KEY_DEL); key_idx_pack(&msg, net_idx, app_idx); - err = bt_mesh_client_send_msg(cli->model, OP_APP_KEY_DEL, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1413,21 +1247,32 @@ int bt_mesh_cfg_app_key_delete(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, u16_t return err; } -int bt_mesh_cfg_app_key_get(struct bt_mesh_msg_ctx *ctx, u16_t net_idx) +int bt_mesh_cfg_app_key_get(bt_mesh_client_common_param_t *param, u16_t net_idx) { - BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_GET, 2); + return send_msg_with_le16(param, OP_APP_KEY_GET, net_idx); +} + +int bt_mesh_cfg_node_identity_get(bt_mesh_client_common_param_t *param, u16_t net_idx) +{ + return send_msg_with_le16(param, OP_NODE_IDENTITY_GET, net_idx); +} + +int bt_mesh_cfg_node_identity_set(bt_mesh_client_common_param_t *param, + u16_t net_idx, u8_t identity) +{ + BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NODE_IDENTITY_SET, 3); int err = 0; - if (!ctx || !ctx->addr) { + if (identity > 0x02) { + BT_ERR("Invalid node identity 0x%02x", identity); return -EINVAL; } - bt_mesh_model_msg_init(&msg, OP_APP_KEY_GET); + bt_mesh_model_msg_init(&msg, OP_NODE_IDENTITY_SET); net_buf_simple_add_le16(&msg, net_idx); + net_buf_simple_add_u8(&msg, identity); - err = bt_mesh_client_send_msg(cli->model, OP_APP_KEY_GET, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1435,53 +1280,13 @@ int bt_mesh_cfg_app_key_get(struct bt_mesh_msg_ctx *ctx, u16_t net_idx) return err; } -static int node_identity_op(u32_t op, struct bt_mesh_msg_ctx *ctx, - u16_t net_idx, u8_t identity) -{ - BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 3); - int err = 0; - - bt_mesh_model_msg_init(&msg, op); - net_buf_simple_add_le16(&msg, net_idx); - if (op == OP_NODE_IDENTITY_SET) { - net_buf_simple_add_u8(&msg, identity); - } - - err = bt_mesh_client_send_msg(cli->model, op, ctx, &msg, timeout_handler, - config_msg_timeout, true, NULL, NULL); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; -} - -int bt_mesh_cfg_node_identity_get(struct bt_mesh_msg_ctx *ctx, u16_t net_idx) -{ - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return node_identity_op(OP_NODE_IDENTITY_GET, ctx, net_idx, 0xFF); -} - -int bt_mesh_cfg_node_identity_set(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, u8_t identity) -{ - if (!ctx || !ctx->addr || identity > 0x01) { - return -EINVAL; - } - return node_identity_op(OP_NODE_IDENTITY_SET, ctx, net_idx, identity); -} - -int bt_mesh_cfg_mod_app_unbind(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t app_idx, u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_app_unbind(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t app_idx, + u16_t mod_id, u16_t cid) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_APP_UNBIND, 8); int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - bt_mesh_model_msg_init(&msg, OP_MOD_APP_UNBIND); net_buf_simple_add_le16(&msg, elem_addr); net_buf_simple_add_le16(&msg, app_idx); @@ -1490,9 +1295,7 @@ int bt_mesh_cfg_mod_app_unbind(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(cli->model, OP_MOD_APP_UNBIND, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1500,10 +1303,10 @@ int bt_mesh_cfg_mod_app_unbind(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, return err; } -static int mod_app_get(u32_t op, struct bt_mesh_msg_ctx *ctx, +static int mod_app_get(bt_mesh_client_common_param_t *param, u32_t op, u16_t elem_addr, u16_t mod_id, u16_t cid) { - BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 6); + BLE_MESH_MODEL_BUF_DEFINE(msg, op, 6); int err = 0; bt_mesh_model_msg_init(&msg, op); @@ -1513,8 +1316,7 @@ static int mod_app_get(u32_t op, struct bt_mesh_msg_ctx *ctx, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(cli->model, op, ctx, &msg, timeout_handler, - config_msg_timeout, true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1522,37 +1324,43 @@ static int mod_app_get(u32_t op, struct bt_mesh_msg_ctx *ctx, return err; } -int bt_mesh_cfg_mod_app_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, u16_t mod_id) +int bt_mesh_cfg_mod_app_get(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id) { - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return mod_app_get(OP_SIG_MOD_APP_GET, ctx, elem_addr, mod_id, BLE_MESH_CID_NVAL); + return mod_app_get(param, OP_SIG_MOD_APP_GET, elem_addr, mod_id, BLE_MESH_CID_NVAL); } -int bt_mesh_cfg_mod_app_get_vnd(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid) +int bt_mesh_cfg_mod_app_get_vnd(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, u16_t cid) { - if (!ctx || !ctx->addr || cid == BLE_MESH_CID_NVAL) { + if (cid == BLE_MESH_CID_NVAL) { + BT_ERR("Invalid company id"); return -EINVAL; } - return mod_app_get(OP_VND_MOD_APP_GET, ctx, elem_addr, mod_id, cid); + return mod_app_get(param, OP_VND_MOD_APP_GET, elem_addr, mod_id, cid); } -static int kr_phase_op(u32_t op, struct bt_mesh_msg_ctx *ctx, - u16_t net_idx, u8_t transition) +int bt_mesh_cfg_kr_phase_get(bt_mesh_client_common_param_t *param, u16_t net_idx) { - BLE_MESH_MODEL_BUF_DEFINE(msg, DUMMY_2_BYTE_OP, 3); + return send_msg_with_le16(param, OP_KRP_GET, net_idx); +} + +int bt_mesh_cfg_kr_phase_set(bt_mesh_client_common_param_t *param, + u16_t net_idx, u8_t transition) +{ + BLE_MESH_MODEL_BUF_DEFINE(msg, OP_KRP_SET, 3); int err = 0; - bt_mesh_model_msg_init(&msg, op); + if (transition > 0x03) { + BT_ERR("Invalid kr phase transition 0x%02x", transition); + return -EINVAL; + } + + bt_mesh_model_msg_init(&msg, OP_KRP_SET); net_buf_simple_add_le16(&msg, net_idx); - if (op == OP_KRP_SET) { - net_buf_simple_add_u8(&msg, transition); - } + net_buf_simple_add_u8(&msg, transition); - err = bt_mesh_client_send_msg(cli->model, op, ctx, &msg, timeout_handler, - config_msg_timeout, true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -1560,58 +1368,19 @@ static int kr_phase_op(u32_t op, struct bt_mesh_msg_ctx *ctx, return err; } -int bt_mesh_cfg_kr_phase_get(struct bt_mesh_msg_ctx *ctx, u16_t net_idx) +int bt_mesh_cfg_lpn_timeout_get(bt_mesh_client_common_param_t *param, u16_t lpn_addr) { - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return kr_phase_op(OP_KRP_GET, ctx, net_idx, 0xFF); + return send_msg_with_le16(param, OP_LPN_TIMEOUT_GET, lpn_addr); } -int bt_mesh_cfg_kr_phase_set(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, u8_t transition) +int bt_mesh_cfg_net_transmit_get(bt_mesh_client_common_param_t *param) { - if (!ctx || !ctx->addr || transition > 0x03) { - return -EINVAL; - } - return kr_phase_op(OP_KRP_SET, ctx, net_idx, transition);; + return send_msg_with_none(param, OP_NET_TRANSMIT_GET); } -int bt_mesh_cfg_lpn_timeout_get(struct bt_mesh_msg_ctx *ctx, u16_t lpn_addr) +int bt_mesh_cfg_net_transmit_set(bt_mesh_client_common_param_t *param, u8_t transmit) { - BLE_MESH_MODEL_BUF_DEFINE(msg, OP_LPN_TIMEOUT_GET, 2); - int err = 0; - - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - bt_mesh_model_msg_init(&msg, OP_LPN_TIMEOUT_GET); - net_buf_simple_add_le16(&msg, lpn_addr); - - err = bt_mesh_client_send_msg(cli->model, OP_LPN_TIMEOUT_GET, ctx, &msg, - timeout_handler, config_msg_timeout, - true, NULL, NULL); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; -} - -int bt_mesh_cfg_net_transmit_get(struct bt_mesh_msg_ctx *ctx) -{ - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return get_state_u8(ctx, OP_NET_TRANSMIT_GET); -} - -int bt_mesh_cfg_net_transmit_set(struct bt_mesh_msg_ctx *ctx, u8_t transmit) -{ - if (!ctx || !ctx->addr) { - return -EINVAL; - } - return set_state_u8(ctx, OP_NET_TRANSMIT_SET, transmit); + return send_msg_with_u8(param, OP_NET_TRANSMIT_SET, transmit); } s32_t bt_mesh_cfg_cli_timeout_get(void) diff --git a/components/bt/esp_ble_mesh/mesh_core/health_cli.c b/components/bt/esp_ble_mesh/mesh_core/health_cli.c index 5ff4f0c77..acf56eef2 100644 --- a/components/bt/esp_ble_mesh/mesh_core/health_cli.c +++ b/components/bt/esp_ble_mesh/mesh_core/health_cli.c @@ -235,20 +235,14 @@ const struct bt_mesh_model_op bt_mesh_health_cli_op[] = { BLE_MESH_MODEL_OP_END, }; -int bt_mesh_health_attention_get(struct bt_mesh_msg_ctx *ctx) +int bt_mesh_health_attention_get(bt_mesh_client_common_param_t *param) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_ATTENTION_GET, 0); int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - bt_mesh_model_msg_init(&msg, OP_ATTENTION_GET); - err = bt_mesh_client_send_msg(health_cli->model, OP_ATTENTION_GET, ctx, - &msg, timeout_handler, health_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -256,28 +250,16 @@ int bt_mesh_health_attention_get(struct bt_mesh_msg_ctx *ctx) return err; } -int bt_mesh_health_attention_set(struct bt_mesh_msg_ctx *ctx, +int bt_mesh_health_attention_set(bt_mesh_client_common_param_t *param, u8_t attention, bool need_ack) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_ATTENTION_SET, 1); - u32_t opcode = 0U; int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - if (need_ack) { - opcode = OP_ATTENTION_SET; - } else { - opcode = OP_ATTENTION_SET_UNREL; - } - bt_mesh_model_msg_init(&msg, opcode); + bt_mesh_model_msg_init(&msg, need_ack ? OP_ATTENTION_SET : OP_ATTENTION_SET_UNREL); net_buf_simple_add_u8(&msg, attention); - err = bt_mesh_client_send_msg(health_cli->model, opcode, ctx, &msg, - timeout_handler, health_msg_timeout, - need_ack, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, need_ack, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -285,20 +267,14 @@ int bt_mesh_health_attention_set(struct bt_mesh_msg_ctx *ctx, return err; } -int bt_mesh_health_period_get(struct bt_mesh_msg_ctx *ctx) +int bt_mesh_health_period_get(bt_mesh_client_common_param_t *param) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_PERIOD_GET, 0); int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - bt_mesh_model_msg_init(&msg, OP_HEALTH_PERIOD_GET); - err = bt_mesh_client_send_msg(health_cli->model, OP_HEALTH_PERIOD_GET, - ctx, &msg, timeout_handler, health_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -306,28 +282,16 @@ int bt_mesh_health_period_get(struct bt_mesh_msg_ctx *ctx) return err; } -int bt_mesh_health_period_set(struct bt_mesh_msg_ctx *ctx, +int bt_mesh_health_period_set(bt_mesh_client_common_param_t *param, u8_t divisor, bool need_ack) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_PERIOD_SET, 1); - u32_t opcode = 0U; int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - if (need_ack) { - opcode = OP_HEALTH_PERIOD_SET; - } else { - opcode = OP_HEALTH_PERIOD_SET_UNREL; - } - bt_mesh_model_msg_init(&msg, opcode); + bt_mesh_model_msg_init(&msg, need_ack ? OP_HEALTH_PERIOD_SET : OP_HEALTH_PERIOD_SET_UNREL); net_buf_simple_add_u8(&msg, divisor); - err = bt_mesh_client_send_msg(health_cli->model, opcode, ctx, &msg, - timeout_handler, health_msg_timeout, - need_ack, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, need_ack, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -335,29 +299,17 @@ int bt_mesh_health_period_set(struct bt_mesh_msg_ctx *ctx, return err; } -int bt_mesh_health_fault_test(struct bt_mesh_msg_ctx *ctx, +int bt_mesh_health_fault_test(bt_mesh_client_common_param_t *param, u16_t cid, u8_t test_id, bool need_ack) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_FAULT_TEST, 3); - u32_t opcode = 0U; int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - if (need_ack) { - opcode = OP_HEALTH_FAULT_TEST; - } else { - opcode = OP_HEALTH_FAULT_TEST_UNREL; - } - bt_mesh_model_msg_init(&msg, opcode); + bt_mesh_model_msg_init(&msg, need_ack ? OP_HEALTH_FAULT_TEST : OP_HEALTH_FAULT_TEST_UNREL); net_buf_simple_add_u8(&msg, test_id); net_buf_simple_add_le16(&msg, cid); - err = bt_mesh_client_send_msg(health_cli->model, opcode, ctx, &msg, - timeout_handler, health_msg_timeout, - need_ack, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, need_ack, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -365,28 +317,16 @@ int bt_mesh_health_fault_test(struct bt_mesh_msg_ctx *ctx, return err; } -int bt_mesh_health_fault_clear(struct bt_mesh_msg_ctx *ctx, +int bt_mesh_health_fault_clear(bt_mesh_client_common_param_t *param, u16_t cid, bool need_ack) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_FAULT_CLEAR, 2); - u32_t opcode = 0U; int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - - if (need_ack) { - opcode = OP_HEALTH_FAULT_CLEAR; - } else { - opcode = OP_HEALTH_FAULT_CLEAR_UNREL; - } - bt_mesh_model_msg_init(&msg, opcode); + bt_mesh_model_msg_init(&msg, need_ack ? OP_HEALTH_FAULT_CLEAR : OP_HEALTH_FAULT_CLEAR_UNREL); net_buf_simple_add_le16(&msg, cid); - err = bt_mesh_client_send_msg(health_cli->model, opcode, ctx, &msg, - timeout_handler, health_msg_timeout, - need_ack, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, need_ack, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } @@ -394,21 +334,15 @@ int bt_mesh_health_fault_clear(struct bt_mesh_msg_ctx *ctx, return err; } -int bt_mesh_health_fault_get(struct bt_mesh_msg_ctx *ctx, u16_t cid) +int bt_mesh_health_fault_get(bt_mesh_client_common_param_t *param, u16_t cid) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_FAULT_GET, 2); int err = 0; - if (!ctx || !ctx->addr) { - return -EINVAL; - } - bt_mesh_model_msg_init(&msg, OP_HEALTH_FAULT_GET); net_buf_simple_add_le16(&msg, cid); - err = bt_mesh_client_send_msg(health_cli->model, OP_HEALTH_FAULT_GET, ctx, - &msg, timeout_handler, health_msg_timeout, - true, NULL, NULL); + err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); if (err) { BT_ERR("%s, send failed (err %d)", __func__, err); } diff --git a/components/bt/esp_ble_mesh/mesh_core/include/cfg_cli.h b/components/bt/esp_ble_mesh/mesh_core/include/cfg_cli.h index 873d98985..c33a7d977 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/cfg_cli.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/cfg_cli.h @@ -34,36 +34,39 @@ extern const struct bt_mesh_model_op bt_mesh_cfg_cli_op[]; BLE_MESH_MODEL(BLE_MESH_MODEL_ID_CFG_CLI, \ bt_mesh_cfg_cli_op, NULL, cli_data) -int bt_mesh_cfg_comp_data_get(struct bt_mesh_msg_ctx *ctx, u8_t page); +int bt_mesh_cfg_comp_data_get(bt_mesh_client_common_param_t *param, u8_t page); -int bt_mesh_cfg_beacon_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_cfg_beacon_get(bt_mesh_client_common_param_t *param); -int bt_mesh_cfg_beacon_set(struct bt_mesh_msg_ctx *ctx, u8_t val); +int bt_mesh_cfg_beacon_set(bt_mesh_client_common_param_t *param, u8_t val); -int bt_mesh_cfg_ttl_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_cfg_ttl_get(bt_mesh_client_common_param_t *param); -int bt_mesh_cfg_ttl_set(struct bt_mesh_msg_ctx *ctx, u8_t val); +int bt_mesh_cfg_ttl_set(bt_mesh_client_common_param_t *param, u8_t val); -int bt_mesh_cfg_friend_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_cfg_friend_get(bt_mesh_client_common_param_t *param); -int bt_mesh_cfg_friend_set(struct bt_mesh_msg_ctx *ctx, u8_t val); +int bt_mesh_cfg_friend_set(bt_mesh_client_common_param_t *param, u8_t val); -int bt_mesh_cfg_gatt_proxy_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_cfg_gatt_proxy_get(bt_mesh_client_common_param_t *param); -int bt_mesh_cfg_gatt_proxy_set(struct bt_mesh_msg_ctx *ctx, u8_t val); +int bt_mesh_cfg_gatt_proxy_set(bt_mesh_client_common_param_t *param, u8_t val); -int bt_mesh_cfg_relay_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_cfg_relay_get(bt_mesh_client_common_param_t *param); -int bt_mesh_cfg_relay_set(struct bt_mesh_msg_ctx *ctx, u8_t new_relay, u8_t new_transmit); +int bt_mesh_cfg_relay_set(bt_mesh_client_common_param_t *param, + u8_t relay, u8_t retransmit); -int bt_mesh_cfg_net_key_add(struct bt_mesh_msg_ctx *ctx, u16_t key_net_idx, - const u8_t net_key[16]); +int bt_mesh_cfg_net_key_add(bt_mesh_client_common_param_t *param, + u16_t net_idx, const u8_t net_key[16]); -int bt_mesh_cfg_app_key_add(struct bt_mesh_msg_ctx *ctx, u16_t key_net_idx, - u16_t key_app_idx, const u8_t app_key[16]); +int bt_mesh_cfg_app_key_add(bt_mesh_client_common_param_t *param, + u16_t net_idx, u16_t app_idx, + const u8_t app_key[16]); -int bt_mesh_cfg_mod_app_bind(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_app_idx, u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_app_bind(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t app_idx, + u16_t mod_id, u16_t cid); struct bt_mesh_cfg_mod_pub { u16_t addr; @@ -74,30 +77,36 @@ struct bt_mesh_cfg_mod_pub { u8_t transmit; }; -int bt_mesh_cfg_mod_pub_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_pub_get(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, u16_t cid); -int bt_mesh_cfg_mod_pub_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid, +int bt_mesh_cfg_mod_pub_set(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, u16_t cid, struct bt_mesh_cfg_mod_pub *pub); -int bt_mesh_cfg_mod_sub_add(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t sub_addr, u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_sub_add(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t sub_addr, + u16_t mod_id, u16_t cid); -int bt_mesh_cfg_mod_sub_del(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t sub_addr, u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_sub_del(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t sub_addr, + u16_t mod_id, u16_t cid); -int bt_mesh_cfg_mod_sub_overwrite(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t sub_addr, u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_sub_overwrite(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t sub_addr, + u16_t mod_id, u16_t cid); -int bt_mesh_cfg_mod_sub_va_add(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - const u8_t label[16], u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_sub_va_add(bt_mesh_client_common_param_t *param, + u16_t elem_addr, const u8_t label[16], + u16_t mod_id, u16_t cid); -int bt_mesh_cfg_mod_sub_va_del(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - const u8_t label[16], u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_sub_va_del(bt_mesh_client_common_param_t *param, + u16_t elem_addr, const u8_t label[16], + u16_t mod_id, u16_t cid); -int bt_mesh_cfg_mod_sub_va_overwrite(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - const u8_t label[16], u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_sub_va_overwrite(bt_mesh_client_common_param_t *param, + u16_t elem_addr, const u8_t label[16], + u16_t mod_id, u16_t cid); struct bt_mesh_cfg_hb_sub { u16_t src; @@ -105,10 +114,10 @@ struct bt_mesh_cfg_hb_sub { u8_t period; }; -int bt_mesh_cfg_hb_sub_set(struct bt_mesh_msg_ctx *ctx, +int bt_mesh_cfg_hb_sub_set(bt_mesh_client_common_param_t *param, struct bt_mesh_cfg_hb_sub *sub); -int bt_mesh_cfg_hb_sub_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_cfg_hb_sub_get(bt_mesh_client_common_param_t *param); struct bt_mesh_cfg_hb_pub { u16_t dst; @@ -119,12 +128,12 @@ struct bt_mesh_cfg_hb_pub { u16_t net_idx; }; -int bt_mesh_cfg_hb_pub_set(struct bt_mesh_msg_ctx *ctx, - const struct bt_mesh_cfg_hb_pub *pub); +int bt_mesh_cfg_hb_pub_set(bt_mesh_client_common_param_t *param, + struct bt_mesh_cfg_hb_pub *pub); -int bt_mesh_cfg_hb_pub_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_cfg_hb_pub_get(bt_mesh_client_common_param_t *param); -int bt_mesh_cfg_node_reset(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_cfg_node_reset(bt_mesh_client_common_param_t *param); s32_t bt_mesh_cfg_cli_timeout_get(void); void bt_mesh_cfg_cli_timeout_set(s32_t timeout); @@ -244,53 +253,61 @@ struct bt_mesh_cfg_lpn_pollto_status { s32_t timeout; }; -int bt_mesh_cfg_mod_pub_va_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid, const u8_t label[16], +int bt_mesh_cfg_mod_pub_va_set(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, + u16_t cid, const u8_t label[16], struct bt_mesh_cfg_mod_pub *pub); -int bt_mesh_cfg_mod_sub_del_all(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_sub_del_all(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, u16_t cid); -int bt_mesh_cfg_mod_sub_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, u16_t mod_id); +int bt_mesh_cfg_mod_sub_get(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id); -int bt_mesh_cfg_mod_sub_get_vnd(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_sub_get_vnd(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, u16_t cid); -int bt_mesh_cfg_net_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, - const u8_t net_key[16]); +int bt_mesh_cfg_net_key_update(bt_mesh_client_common_param_t *param, + u16_t net_idx, const u8_t net_key[16]); -int bt_mesh_cfg_net_key_delete(struct bt_mesh_msg_ctx *ctx, u16_t net_idx); +int bt_mesh_cfg_net_key_delete(bt_mesh_client_common_param_t *param, u16_t net_idx); -int bt_mesh_cfg_net_key_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_cfg_net_key_get(bt_mesh_client_common_param_t *param); -int bt_mesh_cfg_app_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, - u16_t app_idx, const u8_t app_key[16]); +int bt_mesh_cfg_app_key_update(bt_mesh_client_common_param_t *param, + u16_t net_idx, u16_t app_idx, + const u8_t app_key[16]); -int bt_mesh_cfg_app_key_delete(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, u16_t app_idx); +int bt_mesh_cfg_app_key_delete(bt_mesh_client_common_param_t *param, + u16_t net_idx, u16_t app_idx); -int bt_mesh_cfg_app_key_get(struct bt_mesh_msg_ctx *ctx, u16_t net_idx); +int bt_mesh_cfg_app_key_get(bt_mesh_client_common_param_t *param, u16_t net_idx); -int bt_mesh_cfg_node_identity_get(struct bt_mesh_msg_ctx *ctx, u16_t net_idx); +int bt_mesh_cfg_node_identity_get(bt_mesh_client_common_param_t *param, u16_t net_idx); -int bt_mesh_cfg_node_identity_set(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, u8_t identity); +int bt_mesh_cfg_node_identity_set(bt_mesh_client_common_param_t *param, + u16_t net_idx, u8_t identity); -int bt_mesh_cfg_mod_app_unbind(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t app_idx, u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_app_unbind(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t app_idx, + u16_t mod_id, u16_t cid); -int bt_mesh_cfg_mod_app_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, u16_t mod_id); +int bt_mesh_cfg_mod_app_get(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id); -int bt_mesh_cfg_mod_app_get_vnd(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, - u16_t mod_id, u16_t cid); +int bt_mesh_cfg_mod_app_get_vnd(bt_mesh_client_common_param_t *param, + u16_t elem_addr, u16_t mod_id, u16_t cid); -int bt_mesh_cfg_kr_phase_get(struct bt_mesh_msg_ctx *ctx, u16_t net_idx); +int bt_mesh_cfg_kr_phase_get(bt_mesh_client_common_param_t *param, u16_t net_idx); -int bt_mesh_cfg_kr_phase_set(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, u8_t transition); +int bt_mesh_cfg_kr_phase_set(bt_mesh_client_common_param_t *param, + u16_t net_idx, u8_t transition); -int bt_mesh_cfg_lpn_timeout_get(struct bt_mesh_msg_ctx *ctx, u16_t lpn_addr); +int bt_mesh_cfg_lpn_timeout_get(bt_mesh_client_common_param_t *param, u16_t lpn_addr); -int bt_mesh_cfg_net_transmit_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_cfg_net_transmit_get(bt_mesh_client_common_param_t *param); -int bt_mesh_cfg_net_transmit_set(struct bt_mesh_msg_ctx *ctx, u8_t transmit); +int bt_mesh_cfg_net_transmit_set(bt_mesh_client_common_param_t *param, u8_t transmit); #ifdef __cplusplus } diff --git a/components/bt/esp_ble_mesh/mesh_core/include/health_cli.h b/components/bt/esp_ble_mesh/mesh_core/include/health_cli.h index 52982eced..8d38cf3d3 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/health_cli.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/health_cli.h @@ -36,22 +36,22 @@ extern const struct bt_mesh_model_op bt_mesh_health_cli_op[]; int bt_mesh_health_cli_set(struct bt_mesh_model *model); -int bt_mesh_health_fault_get(struct bt_mesh_msg_ctx *ctx, u16_t cid); +int bt_mesh_health_fault_get(bt_mesh_client_common_param_t *param, u16_t cid); -int bt_mesh_health_fault_clear(struct bt_mesh_msg_ctx *ctx, u16_t cid, - bool need_ack); +int bt_mesh_health_fault_clear(bt_mesh_client_common_param_t *param, + u16_t cid, bool need_ack); -int bt_mesh_health_fault_test(struct bt_mesh_msg_ctx *ctx, +int bt_mesh_health_fault_test(bt_mesh_client_common_param_t *param, u16_t cid, u8_t test_id, bool need_ack); -int bt_mesh_health_period_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_health_period_get(bt_mesh_client_common_param_t *param); -int bt_mesh_health_period_set(struct bt_mesh_msg_ctx *ctx, +int bt_mesh_health_period_set(bt_mesh_client_common_param_t *param, u8_t divisor, bool need_ack); -int bt_mesh_health_attention_get(struct bt_mesh_msg_ctx *ctx); +int bt_mesh_health_attention_get(bt_mesh_client_common_param_t *param); -int bt_mesh_health_attention_set(struct bt_mesh_msg_ctx *ctx, +int bt_mesh_health_attention_set(bt_mesh_client_common_param_t *param, u8_t attention, bool need_ack); s32_t bt_mesh_health_cli_timeout_get(void); diff --git a/components/bt/esp_ble_mesh/mesh_models/client/client_common.c b/components/bt/esp_ble_mesh/mesh_models/client/client_common.c index 66e128d43..658c3c4a8 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/client_common.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/client_common.c @@ -251,26 +251,21 @@ static const struct bt_mesh_send_cb send_cb = { .end = NULL, }; -int bt_mesh_client_send_msg(struct bt_mesh_model *model, - u32_t opcode, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *msg, - k_work_handler_t timer_handler, - s32_t timeout, bool need_ack, - const struct bt_mesh_send_cb *cb, - void *cb_data) +int bt_mesh_client_send_msg(bt_mesh_client_common_param_t *param, + struct net_buf_simple *msg, bool need_ack, + k_work_handler_t timer_handler) { bt_mesh_client_internal_data_t *internal = NULL; bt_mesh_client_user_data_t *client = NULL; bt_mesh_client_node_t *node = NULL; int err = 0; - if (!model || !ctx || !msg) { + if (!param || !param->model || !msg) { BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } - client = (bt_mesh_client_user_data_t *)model->user_data; + client = (bt_mesh_client_user_data_t *)param->model->user_data; if (!client) { BT_ERR("Invalid client user data"); return -EINVAL; @@ -282,23 +277,23 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model, return -EINVAL; } - if (ctx->addr == BLE_MESH_ADDR_UNASSIGNED) { - BT_ERR("Invalid DST 0x%04x", ctx->addr); + if (param->ctx.addr == BLE_MESH_ADDR_UNASSIGNED) { + BT_ERR("Invalid DST 0x%04x", param->ctx.addr); return -EINVAL; } if (!need_ack) { /* If this is an unack message, send it directly. */ - return bt_mesh_model_send(model, ctx, msg, cb, cb_data); + return bt_mesh_model_send(param->model, ¶m->ctx, msg, param->cb, param->cb_data); } - if (!BLE_MESH_ADDR_IS_UNICAST(ctx->addr)) { + if (!BLE_MESH_ADDR_IS_UNICAST(param->ctx.addr)) { /* If an acknowledged message is not sent to a unicast address, * for example to a group/virtual address, then all the * corresponding responses will be treated as publish messages. * And no timeout will be used for the message. */ - return bt_mesh_model_send(model, ctx, msg, cb, cb_data); + return bt_mesh_model_send(param->model, ¶m->ctx, msg, param->cb, param->cb_data); } if (!timer_handler) { @@ -306,8 +301,8 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model, return -EINVAL; } - if (bt_mesh_client_check_node_in_list(&internal->queue, ctx->addr)) { - BT_ERR("Busy sending message to DST 0x%04x", ctx->addr); + if (bt_mesh_client_check_node_in_list(&internal->queue, param->ctx.addr)) { + BT_ERR("Busy sending message to DST 0x%04x", param->ctx.addr); return -EBUSY; } @@ -318,16 +313,17 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model, return -ENOMEM; } - memcpy(&node->ctx, ctx, sizeof(struct bt_mesh_msg_ctx)); - node->ctx.model = model; - node->opcode = opcode; - node->op_pending = bt_mesh_client_get_status_op(client->op_pair, client->op_pair_size, opcode); + memcpy(&node->ctx, ¶m->ctx, sizeof(struct bt_mesh_msg_ctx)); + node->ctx.model = param->model; + node->opcode = param->opcode; + node->op_pending = bt_mesh_client_get_status_op(client->op_pair, client->op_pair_size, param->opcode); if (node->op_pending == 0U) { BT_ERR("Not found the status opcode in op_pair list"); bt_mesh_free(node); return -EINVAL; } - node->timeout = bt_mesh_client_calc_timeout(ctx, msg, opcode, timeout ? timeout : CONFIG_BLE_MESH_CLIENT_MSG_TIMEOUT); + node->timeout = bt_mesh_client_calc_timeout(¶m->ctx, msg, param->opcode, + param->msg_timeout ? param->msg_timeout : CONFIG_BLE_MESH_CLIENT_MSG_TIMEOUT); if (k_delayed_work_init(&node->timer, timer_handler)) { BT_ERR("Failed to create a timer"); @@ -343,7 +339,7 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model, * Due to the higher priority of adv_thread (than btc task), we need to * send the packet after the list item "node" is initialized properly. */ - err = bt_mesh_model_send(model, ctx, msg, &send_cb, node); + err = bt_mesh_model_send(param->model, ¶m->ctx, msg, &send_cb, node); if (err) { BT_ERR("Failed to send client message 0x%08x", node->opcode); k_delayed_work_free(&node->timer); diff --git a/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c b/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c index bee29cf45..99d13c791 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c @@ -725,9 +725,7 @@ static int gen_get_state(bt_mesh_client_common_param_t *common, void *value) } } - err = bt_mesh_client_send_msg(common->model, common->opcode, &common->ctx, &msg, - timeout_handler, common->msg_timeout, true, - common->cb, common->cb_data); + err = bt_mesh_client_send_msg(common, &msg, true, timeout_handler); if (err) { BT_ERR("Failed to send Generic Get message (err %d)", err); } @@ -904,9 +902,7 @@ static int gen_set_state(bt_mesh_client_common_param_t *common, goto end; } - err = bt_mesh_client_send_msg(common->model, common->opcode, &common->ctx, msg, - timeout_handler, common->msg_timeout, need_ack, - common->cb, common->cb_data); + err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler); if (err) { BT_ERR("Failed to send Generic Set message (err %d)", err); } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/include/client_common.h b/components/bt/esp_ble_mesh/mesh_models/client/include/client_common.h index 78e87a24e..c6fc89234 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/include/client_common.h +++ b/components/bt/esp_ble_mesh/mesh_models/client/include/client_common.h @@ -104,13 +104,9 @@ bt_mesh_client_node_t *bt_mesh_is_client_recv_publish_msg(struct bt_mesh_model * struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf, bool need_pub); -int bt_mesh_client_send_msg(struct bt_mesh_model *model, - u32_t opcode, - struct bt_mesh_msg_ctx *ctx, - struct net_buf_simple *msg, - k_work_handler_t timer_handler, - s32_t timeout, bool need_ack, - const struct bt_mesh_send_cb *cb, void *cb_data); +int bt_mesh_client_send_msg(bt_mesh_client_common_param_t *param, + struct net_buf_simple *msg, bool need_ack, + k_work_handler_t timer_handler); int bt_mesh_client_free_node(bt_mesh_client_node_t *node); diff --git a/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c b/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c index 77ed50621..18e5072e1 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c @@ -790,9 +790,7 @@ static int light_get_state(bt_mesh_client_common_param_t *common, void *value) } } - err = bt_mesh_client_send_msg(common->model, common->opcode, &common->ctx, &msg, - timeout_handler, common->msg_timeout, true, - common->cb, common->cb_data); + err = bt_mesh_client_send_msg(common, &msg, true, timeout_handler); if (err) { BT_ERR("Failed to send Lighting Get message (err %d)", err); } @@ -1028,9 +1026,7 @@ static int light_set_state(bt_mesh_client_common_param_t *common, goto end; } - err = bt_mesh_client_send_msg(common->model, common->opcode, &common->ctx, msg, - timeout_handler, common->msg_timeout, need_ack, - common->cb, common->cb_data); + err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler); if (err) { BT_ERR("Failed to send Lighting Set message (err %d)", err); } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c b/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c index 860c50a8b..34a597d85 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c @@ -447,9 +447,7 @@ static int sensor_act_state(bt_mesh_client_common_param_t *common, goto end; } - err = bt_mesh_client_send_msg(common->model, common->opcode, &common->ctx, msg, - timeout_handler, common->msg_timeout, need_ack, - common->cb, common->cb_data); + err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler); if (err) { BT_ERR("Failed to send Sensor client message (err %d)", err); } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c b/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c index 9357cdbc7..b39ed24ff 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c @@ -390,9 +390,7 @@ static int time_scene_get_state(bt_mesh_client_common_param_t *common, void *val } } - err = bt_mesh_client_send_msg(common->model, common->opcode, &common->ctx, &msg, - timeout_handler, common->msg_timeout, true, - common->cb, common->cb_data); + err = bt_mesh_client_send_msg(common, &msg, true, timeout_handler); if (err) { BT_ERR("Failed to send Time Scene Get message (err %d)", err); } @@ -485,9 +483,7 @@ static int time_scene_set_state(bt_mesh_client_common_param_t *common, goto end; } - err = bt_mesh_client_send_msg(common->model, common->opcode, &common->ctx, msg, - timeout_handler, common->msg_timeout, need_ack, - common->cb, common->cb_data); + err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler); if (err) { BT_ERR("Failed to send Time Scene Set message (err %d)", err); } From 7cb6b85ec9cc2401f5511865026f0580074571e9 Mon Sep 17 00:00:00 2001 From: lly Date: Sun, 28 Jun 2020 15:56:34 +0800 Subject: [PATCH 38/60] ble_mesh: stack: Remove some not used variables & functions --- .../bt/esp_ble_mesh/mesh_core/cfg_cli.c | 20 +---------- .../bt/esp_ble_mesh/mesh_core/health_cli.c | 35 ------------------- .../esp_ble_mesh/mesh_core/include/cfg_cli.h | 3 -- .../mesh_core/include/health_cli.h | 5 --- 4 files changed, 1 insertion(+), 62 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c b/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c index 4e0c9f1dc..cd4bdde6a 100644 --- a/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c +++ b/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c @@ -20,10 +20,6 @@ #include "mesh_common.h" #include "cfg_cli.h" -s32_t config_msg_timeout; - -static bt_mesh_config_client_t *cli; - static const bt_mesh_client_op_pair_t cfg_op_pair[] = { { OP_BEACON_GET, OP_BEACON_STATUS }, { OP_BEACON_SET, OP_BEACON_STATUS }, @@ -1383,16 +1379,6 @@ int bt_mesh_cfg_net_transmit_set(bt_mesh_client_common_param_t *param, u8_t tran return send_msg_with_u8(param, OP_NET_TRANSMIT_SET, transmit); } -s32_t bt_mesh_cfg_cli_timeout_get(void) -{ - return config_msg_timeout; -} - -void bt_mesh_cfg_cli_timeout_set(s32_t timeout) -{ - config_msg_timeout = timeout; -} - int bt_mesh_cfg_cli_init(struct bt_mesh_model *model, bool primary) { config_internal_data_t *internal = NULL; @@ -1433,8 +1419,6 @@ int bt_mesh_cfg_cli_init(struct bt_mesh_model *model, bool primary) bt_mesh_client_clear_list(client->internal_data); } - cli = client; - /* Configuration Model security is device-key based */ model->keys[0] = BLE_MESH_KEY_DEV; @@ -1469,11 +1453,9 @@ int bt_mesh_cfg_cli_deinit(struct bt_mesh_model *model, bool primary) /* Free the allocated internal data */ bt_mesh_free(client->internal_data); - cli->internal_data = NULL; + client->internal_data = NULL; } - client = NULL; - bt_mesh_cfg_client_mutex_free(); return 0; diff --git a/components/bt/esp_ble_mesh/mesh_core/health_cli.c b/components/bt/esp_ble_mesh/mesh_core/health_cli.c index acf56eef2..1c8475154 100644 --- a/components/bt/esp_ble_mesh/mesh_core/health_cli.c +++ b/components/bt/esp_ble_mesh/mesh_core/health_cli.c @@ -18,10 +18,6 @@ #include "mesh_common.h" #include "health_cli.h" -s32_t health_msg_timeout; - -static bt_mesh_health_client_t *health_cli; - static const bt_mesh_client_op_pair_t health_op_pair[] = { { OP_HEALTH_FAULT_GET, OP_HEALTH_FAULT_STATUS }, { OP_HEALTH_FAULT_CLEAR, OP_HEALTH_FAULT_STATUS }, @@ -350,28 +346,6 @@ int bt_mesh_health_fault_get(bt_mesh_client_common_param_t *param, u16_t cid) return err; } -s32_t bt_mesh_health_cli_timeout_get(void) -{ - return health_msg_timeout; -} - -void bt_mesh_health_cli_timeout_set(s32_t timeout) -{ - health_msg_timeout = timeout; -} - -int bt_mesh_health_cli_set(struct bt_mesh_model *model) -{ - if (!model || !model->user_data) { - BT_ERR("No Health Client context for given model"); - return -EINVAL; - } - - health_cli = model->user_data; - - return 0; -} - int bt_mesh_health_cli_init(struct bt_mesh_model *model, bool primary) { health_internal_data_t *internal = NULL; @@ -409,11 +383,6 @@ int bt_mesh_health_cli_init(struct bt_mesh_model *model, bool primary) bt_mesh_health_client_mutex_new(); - /* Set the default health client pointer */ - if (!health_cli) { - health_cli = client; - } - return 0; } @@ -443,9 +412,5 @@ int bt_mesh_health_cli_deinit(struct bt_mesh_model *model, bool primary) bt_mesh_health_client_mutex_free(); - if (health_cli) { - health_cli = NULL; - } - return 0; } diff --git a/components/bt/esp_ble_mesh/mesh_core/include/cfg_cli.h b/components/bt/esp_ble_mesh/mesh_core/include/cfg_cli.h index c33a7d977..e04b7b3ad 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/cfg_cli.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/cfg_cli.h @@ -135,9 +135,6 @@ int bt_mesh_cfg_hb_pub_get(bt_mesh_client_common_param_t *param); int bt_mesh_cfg_node_reset(bt_mesh_client_common_param_t *param); -s32_t bt_mesh_cfg_cli_timeout_get(void); -void bt_mesh_cfg_cli_timeout_set(s32_t timeout); - /* Configuration Client Status Message Context */ struct bt_mesh_cfg_comp_data_status { diff --git a/components/bt/esp_ble_mesh/mesh_core/include/health_cli.h b/components/bt/esp_ble_mesh/mesh_core/include/health_cli.h index 8d38cf3d3..6bb7a4285 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/health_cli.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/health_cli.h @@ -34,8 +34,6 @@ extern const struct bt_mesh_model_op bt_mesh_health_cli_op[]; BLE_MESH_MODEL(BLE_MESH_MODEL_ID_HEALTH_CLI, \ bt_mesh_health_cli_op, NULL, cli_data) -int bt_mesh_health_cli_set(struct bt_mesh_model *model); - int bt_mesh_health_fault_get(bt_mesh_client_common_param_t *param, u16_t cid); int bt_mesh_health_fault_clear(bt_mesh_client_common_param_t *param, @@ -54,9 +52,6 @@ int bt_mesh_health_attention_get(bt_mesh_client_common_param_t *param); int bt_mesh_health_attention_set(bt_mesh_client_common_param_t *param, u8_t attention, bool need_ack); -s32_t bt_mesh_health_cli_timeout_get(void); -void bt_mesh_health_cli_timeout_set(s32_t timeout); - /* Health Client Status Message Context */ struct bt_mesh_health_current_status { From 9aa33c344a19c1ed57b5626e930237cdf5176a48 Mon Sep 17 00:00:00 2001 From: lly Date: Sun, 28 Jun 2020 16:18:24 +0800 Subject: [PATCH 39/60] ble_mesh: stack: Remove some not used client parameters --- .../bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c | 4 ++++ .../bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c | 10 ++++++---- .../bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c | 4 ++++ .../bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c | 10 ++++++---- .../bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c | 10 ++++++---- .../esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c | 10 ++++++---- .../esp_ble_mesh/mesh_models/client/generic_client.c | 6 ++---- .../mesh_models/client/include/generic_client.h | 8 ++------ .../mesh_models/client/include/lighting_client.h | 8 ++------ .../mesh_models/client/include/sensor_client.h | 8 ++------ .../mesh_models/client/include/time_scene_client.h | 8 ++------ .../esp_ble_mesh/mesh_models/client/lighting_client.c | 6 ++---- .../bt/esp_ble_mesh/mesh_models/client/sensor_client.c | 6 ++---- .../mesh_models/client/time_scene_client.c | 6 ++---- 14 files changed, 48 insertions(+), 56 deletions(-) diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c index 1d18f4fb6..c8807a353 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c @@ -635,12 +635,14 @@ void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg) 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)) { BT_ERR("Failed to set model role"); break; } + cb.error_code = btc_ble_mesh_config_client_get_state(arg->cfg_client_get_state.params, arg->cfg_client_get_state.get_state); if (cb.error_code) { @@ -650,12 +652,14 @@ void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg) } 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)) { BT_ERR("Failed to set model role"); break; } + cb.error_code = btc_ble_mesh_config_client_set_state(arg->cfg_client_set_state.params, arg->cfg_client_set_state.set_state); if (cb.error_code) { diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c index 4f267b3f6..7b813fc09 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c @@ -466,12 +466,14 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg) switch (msg->act) { case BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE: { 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_client_model_role(&role_param)) { BT_ERR("Failed to set model role"); break; } + common.opcode = params->opcode; common.model = (struct bt_mesh_model *)params->model; common.ctx.net_idx = params->ctx.net_idx; @@ -482,8 +484,7 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg) common.msg_timeout = params->msg_timeout; 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); + cb.error_code = bt_mesh_generic_client_get_state(&common, arg->generic_client_get_state.get_state); if (cb.error_code) { /* If send failed, callback error_code to app layer immediately */ btc_ble_mesh_generic_client_callback(&cb, ESP_BLE_MESH_GENERIC_CLIENT_GET_STATE_EVT); @@ -492,12 +493,14 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg) } case BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE: { 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_client_model_role(&role_param)) { BT_ERR("Failed to set model role"); break; } + common.opcode = params->opcode; common.model = (struct bt_mesh_model *)params->model; common.ctx.net_idx = params->ctx.net_idx; @@ -508,8 +511,7 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg) common.msg_timeout = params->msg_timeout; 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); + cb.error_code = bt_mesh_generic_client_set_state(&common, arg->generic_client_set_state.set_state); if (cb.error_code) { /* If send failed, callback error_code to app layer immediately */ btc_ble_mesh_generic_client_callback(&cb, ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c index 240f318aa..c956be5b0 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c @@ -411,12 +411,14 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg) 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)) { BT_ERR("Failed to set model role"); break; } + cb.error_code = btc_ble_mesh_health_client_get_state(arg->health_client_get_state.params, arg->health_client_get_state.get_state); if (cb.error_code) { @@ -427,12 +429,14 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg) } 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)) { BT_ERR("Failed to set model role"); break; } + cb.error_code = btc_ble_mesh_health_client_set_state(arg->health_client_set_state.params, arg->health_client_set_state.set_state); if (cb.error_code) { diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c index 3687d20fd..89e576ebf 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c @@ -310,12 +310,14 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg) switch (msg->act) { 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_client_model_role(&role_param)) { BT_ERR("Failed to set model role"); break; } + common.opcode = params->opcode; common.model = (struct bt_mesh_model *)params->model; common.ctx.net_idx = params->ctx.net_idx; @@ -326,8 +328,7 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg) common.msg_timeout = params->msg_timeout; 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); + cb.error_code = bt_mesh_light_client_get_state(&common, arg->light_client_get_state.get_state); if (cb.error_code) { /* If send failed, callback error_code to app layer immediately */ btc_ble_mesh_lighting_client_callback(&cb, ESP_BLE_MESH_LIGHT_CLIENT_GET_STATE_EVT); @@ -336,12 +337,14 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg) } 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_client_model_role(&role_param)) { BT_ERR("Failed to set model role"); break; } + common.opcode = params->opcode; common.model = (struct bt_mesh_model *)params->model; common.ctx.net_idx = params->ctx.net_idx; @@ -352,8 +355,7 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg) common.msg_timeout = params->msg_timeout; 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); + cb.error_code = bt_mesh_light_client_set_state(&common, arg->light_client_set_state.set_state); if (cb.error_code) { /* If send failed, callback error_code to app layer immediately */ btc_ble_mesh_lighting_client_callback(&cb, ESP_BLE_MESH_LIGHT_CLIENT_SET_STATE_EVT); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c index 98c906939..100de9833 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c @@ -548,12 +548,14 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg) switch (msg->act) { case BTC_BLE_MESH_ACT_SENSOR_CLIENT_GET_STATE: { 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_client_model_role(&role_param)) { BT_ERR("Failed to set model role"); break; } + common.opcode = params->opcode; common.model = (struct bt_mesh_model *)params->model; common.ctx.net_idx = params->ctx.net_idx; @@ -564,8 +566,7 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg) common.msg_timeout = params->msg_timeout; 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); + cb.error_code = bt_mesh_sensor_client_get_state(&common, arg->sensor_client_get_state.get_state); if (cb.error_code) { /* If send failed, callback error_code to app layer immediately */ btc_ble_mesh_sensor_client_callback(&cb, ESP_BLE_MESH_SENSOR_CLIENT_GET_STATE_EVT); @@ -574,12 +575,14 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg) } case BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE: { 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_client_model_role(&role_param)) { BT_ERR("Failed to set model role"); break; } + common.opcode = params->opcode; common.model = (struct bt_mesh_model *)params->model; common.ctx.net_idx = params->ctx.net_idx; @@ -590,8 +593,7 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg) common.msg_timeout = params->msg_timeout; 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); + cb.error_code = bt_mesh_sensor_client_set_state(&common, arg->sensor_client_set_state.set_state); if (cb.error_code) { /* If send failed, callback error_code to app layer immediately */ btc_ble_mesh_sensor_client_callback(&cb, ESP_BLE_MESH_SENSOR_CLIENT_SET_STATE_EVT); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c index ac3038446..ce3318cc8 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c @@ -312,12 +312,14 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg) switch (msg->act) { case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_GET_STATE: { 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_client_model_role(&role_param)) { BT_ERR("Failed to set model role"); break; } + common.opcode = params->opcode; common.model = (struct bt_mesh_model *)params->model; common.ctx.net_idx = params->ctx.net_idx; @@ -328,8 +330,7 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg) common.msg_timeout = params->msg_timeout; 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); + cb.error_code = bt_mesh_time_scene_client_get_state(&common, arg->time_scene_client_get_state.get_state); if (cb.error_code) { /* If send failed, callback error_code to app layer immediately */ btc_ble_mesh_time_scene_client_callback(&cb, ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT); @@ -338,12 +339,14 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg) } case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_SET_STATE: { 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_client_model_role(&role_param)) { BT_ERR("Failed to set model role"); break; } + common.opcode = params->opcode; common.model = (struct bt_mesh_model *)params->model; common.ctx.net_idx = params->ctx.net_idx; @@ -354,8 +357,7 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg) common.msg_timeout = params->msg_timeout; 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); + cb.error_code = bt_mesh_time_scene_client_set_state(&common, arg->time_scene_client_set_state.set_state); if (cb.error_code) { /* If send failed, callback error_code to app layer immediately */ btc_ble_mesh_time_scene_client_callback(&cb, ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT); diff --git a/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c b/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c index 99d13c791..6f11f6004 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c @@ -913,8 +913,7 @@ end: return err; } -int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *common, - void *get, void *status) +int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *common, void *get) { bt_mesh_generic_client_t *client = NULL; @@ -977,8 +976,7 @@ int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *common, return gen_get_state(common, get); } -int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, - void *set, void *status) +int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void *set) { bt_mesh_generic_client_t *client = NULL; u16_t length = 0U; diff --git a/components/bt/esp_ble_mesh/mesh_models/client/include/generic_client.h b/components/bt/esp_ble_mesh/mesh_models/client/include/generic_client.h index c0b9af97f..53bea9743 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/include/generic_client.h +++ b/components/bt/esp_ble_mesh/mesh_models/client/include/generic_client.h @@ -553,24 +553,20 @@ int bt_mesh_gen_property_cli_deinit(struct bt_mesh_model *model, bool primary); * * @param[in] common: Message common information structure * @param[in] get: Pointer of generic get message value - * @param[out] status: Pointer of generic status message value * * @return Zero-success, other-fail */ -int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *common, - void *get, void *status); +int bt_mesh_generic_client_get_state(bt_mesh_client_common_param_t *common, void *get); /** * @brief This function is called to set generic states. * * @param[in] common: Message common information structure * @param[in] set: Pointer of generic set message value - * @param[out] status: Pointer of generic status message value * * @return Zero-success, other-fail */ -int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, - void *set, void *status); +int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void *set); #ifdef __cplusplus } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/include/lighting_client.h b/components/bt/esp_ble_mesh/mesh_models/client/include/lighting_client.h index f623cfb8a..7a7e62c30 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/include/lighting_client.h +++ b/components/bt/esp_ble_mesh/mesh_models/client/include/lighting_client.h @@ -523,24 +523,20 @@ int bt_mesh_light_lc_cli_deinit(struct bt_mesh_model *model, bool primary); * * @param[in] common: Message common information structure * @param[in] get: Pointer of light get message value - * @param[out] status: Pointer of light status message value * * @return Zero-success, other-fail */ -int bt_mesh_light_client_get_state(bt_mesh_client_common_param_t *common, - void *get, void *status); +int bt_mesh_light_client_get_state(bt_mesh_client_common_param_t *common, void *get); /** * @brief This function is called to set light states. * * @param[in] common: Message common information structure * @param[in] set: Pointer of light set message value - * @param[out] status: Pointer of light status message value * * @return Zero-success, other-fail */ -int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, - void *set, void *status); +int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void *set); #ifdef __cplusplus } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/include/sensor_client.h b/components/bt/esp_ble_mesh/mesh_models/client/include/sensor_client.h index 2f798c69f..47448547f 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/include/sensor_client.h +++ b/components/bt/esp_ble_mesh/mesh_models/client/include/sensor_client.h @@ -158,24 +158,20 @@ int bt_mesh_sensor_cli_deinit(struct bt_mesh_model *model, bool primary); * * @param[in] common: Message common information structure * @param[in] get: Pointer of sensor get message value - * @param[out] status: Pointer of sensor status message value * * @return Zero-success, other-fail */ -int bt_mesh_sensor_client_get_state(bt_mesh_client_common_param_t *common, - void *get, void *status); +int bt_mesh_sensor_client_get_state(bt_mesh_client_common_param_t *common, void *get); /** * @brief This function is called to set sensor states. * * @param[in] common: Message common information structure * @param[in] set: Pointer of sensor set message value - * @param[out] status: Pointer of sensor status message value * * @return Zero-success, other-fail */ -int bt_mesh_sensor_client_set_state(bt_mesh_client_common_param_t *common, - void *set, void *status); +int bt_mesh_sensor_client_set_state(bt_mesh_client_common_param_t *common, void *set); #ifdef __cplusplus } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/include/time_scene_client.h b/components/bt/esp_ble_mesh/mesh_models/client/include/time_scene_client.h index 4d400776b..ee741c530 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/include/time_scene_client.h +++ b/components/bt/esp_ble_mesh/mesh_models/client/include/time_scene_client.h @@ -268,24 +268,20 @@ int bt_mesh_scheduler_cli_deinit(struct bt_mesh_model *model, bool primary); * * @param[in] common: Message common information structure * @param[in] get: Pointer of time scene get message value - * @param[out] status: Pointer of time scene status message value * * @return Zero-success, other-fail */ -int bt_mesh_time_scene_client_get_state(bt_mesh_client_common_param_t *common, - void *get, void *status); +int bt_mesh_time_scene_client_get_state(bt_mesh_client_common_param_t *common, void *get); /** * @brief This function is called to set scene states. * * @param[in] common: Message common information structure * @param[in] set: Pointer of time scene set message value - * @param[out] status: Pointer of time scene status message value * * @return Zero-success, other-fail */ -int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *common, - void *set, void *status); +int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *common, void *set); #ifdef __cplusplus } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c b/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c index 18e5072e1..f89161de5 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c @@ -1037,8 +1037,7 @@ end: return err; } -int bt_mesh_light_client_get_state(bt_mesh_client_common_param_t *common, - void *get, void *status) +int bt_mesh_light_client_get_state(bt_mesh_client_common_param_t *common, void *get) { bt_mesh_light_client_t *client = NULL; @@ -1091,8 +1090,7 @@ int bt_mesh_light_client_get_state(bt_mesh_client_common_param_t *common, return light_get_state(common, get); } -int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, - void *set, void *status) +int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void *set) { bt_mesh_light_client_t *client = NULL; u16_t length = 0U; diff --git a/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c b/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c index 34a597d85..9ef7694e5 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c @@ -458,8 +458,7 @@ end: return err; } -int bt_mesh_sensor_client_get_state(bt_mesh_client_common_param_t *common, - void *get, void *status) +int bt_mesh_sensor_client_get_state(bt_mesh_client_common_param_t *common, void *get) { bt_mesh_sensor_client_t *client = NULL; u16_t length = 0U; @@ -524,8 +523,7 @@ int bt_mesh_sensor_client_get_state(bt_mesh_client_common_param_t *common, return sensor_act_state(common, get, length, true); } -int bt_mesh_sensor_client_set_state(bt_mesh_client_common_param_t *common, - void *set, void *status) +int bt_mesh_sensor_client_set_state(bt_mesh_client_common_param_t *common, void *set) { bt_mesh_sensor_client_t *client = NULL; u16_t length = 0U; diff --git a/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c b/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c index b39ed24ff..8d416ba03 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c @@ -493,8 +493,7 @@ end: return err; } -int bt_mesh_time_scene_client_get_state(bt_mesh_client_common_param_t *common, - void *get, void *status) +int bt_mesh_time_scene_client_get_state(bt_mesh_client_common_param_t *common, void *get) { bt_mesh_time_scene_client_t *client = NULL; @@ -532,8 +531,7 @@ int bt_mesh_time_scene_client_get_state(bt_mesh_client_common_param_t *common, return time_scene_get_state(common, get); } -int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *common, - void *set, void *status) +int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *common, void *set) { bt_mesh_time_scene_client_t *client = NULL; u16_t length = 0U; From 90e2bbe3303a12d366f1df0e5b53e492ae2d0481 Mon Sep 17 00:00:00 2001 From: lly Date: Sun, 28 Jun 2020 16:53:02 +0800 Subject: [PATCH 40/60] ble_mesh: stack: Move client role set to the msg function --- .../btc/btc_ble_mesh_config_model.c | 19 +------- .../btc/btc_ble_mesh_generic_model.c | 19 +------- .../btc/btc_ble_mesh_health_model.c | 19 +------- .../btc/btc_ble_mesh_lighting_model.c | 19 +------- .../bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c | 18 +++----- .../btc/btc_ble_mesh_sensor_model.c | 19 +------- .../btc/btc_ble_mesh_time_scene_model.c | 19 +------- .../mesh_models/client/client_common.c | 46 +++++++------------ .../client/include/client_common.h | 13 ++---- 9 files changed, 40 insertions(+), 151 deletions(-) diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c index c8807a353..8e34d47fc 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c @@ -416,6 +416,7 @@ static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param param.ctx.send_rel = params->ctx.send_rel; param.ctx.send_ttl = params->ctx.send_ttl; param.msg_timeout = params->msg_timeout; + param.msg_role = params->msg_role; switch (param.opcode) { case ESP_BLE_MESH_MODEL_OP_BEACON_GET: @@ -495,6 +496,7 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param param.ctx.send_rel = params->ctx.send_rel; param.ctx.send_ttl = params->ctx.send_ttl; param.msg_timeout = params->msg_timeout; + param.msg_role = params->msg_role; switch (param.opcode) { case ESP_BLE_MESH_MODEL_OP_BEACON_SET: @@ -623,7 +625,6 @@ 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) { BT_ERR("%s, Invalid parameter", __func__); @@ -635,14 +636,6 @@ void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg) 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)) { - BT_ERR("Failed to set model role"); - break; - } - cb.error_code = btc_ble_mesh_config_client_get_state(arg->cfg_client_get_state.params, arg->cfg_client_get_state.get_state); if (cb.error_code) { @@ -652,14 +645,6 @@ void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg) } 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)) { - BT_ERR("Failed to set model role"); - break; - } - cb.error_code = btc_ble_mesh_config_client_set_state(arg->cfg_client_set_state.params, arg->cfg_client_set_state.set_state); if (cb.error_code) { diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c index 7b813fc09..ec959964a 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c @@ -454,7 +454,6 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg) btc_ble_mesh_generic_client_args_t *arg = NULL; 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) { BT_ERR("%s, Invalid parameter", __func__); @@ -466,14 +465,6 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg) switch (msg->act) { case BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE: { 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_client_model_role(&role_param)) { - BT_ERR("Failed to set model role"); - break; - } - common.opcode = params->opcode; common.model = (struct bt_mesh_model *)params->model; common.ctx.net_idx = params->ctx.net_idx; @@ -482,6 +473,7 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg) common.ctx.send_rel = params->ctx.send_rel; common.ctx.send_ttl = params->ctx.send_ttl; common.msg_timeout = params->msg_timeout; + common.msg_role = params->msg_role; cb.params = arg->generic_client_get_state.params; cb.error_code = bt_mesh_generic_client_get_state(&common, arg->generic_client_get_state.get_state); @@ -493,14 +485,6 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg) } case BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE: { 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_client_model_role(&role_param)) { - BT_ERR("Failed to set model role"); - break; - } - common.opcode = params->opcode; common.model = (struct bt_mesh_model *)params->model; common.ctx.net_idx = params->ctx.net_idx; @@ -509,6 +493,7 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg) common.ctx.send_rel = params->ctx.send_rel; common.ctx.send_ttl = params->ctx.send_ttl; common.msg_timeout = params->msg_timeout; + common.msg_role = params->msg_role; cb.params = arg->generic_client_set_state.params; cb.error_code = bt_mesh_generic_client_set_state(&common, arg->generic_client_set_state.set_state); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c index c956be5b0..9ed378906 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c @@ -335,6 +335,7 @@ static int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param param.ctx.send_rel = params->ctx.send_rel; param.ctx.send_ttl = params->ctx.send_ttl; param.msg_timeout = params->msg_timeout; + param.msg_role = params->msg_role; switch (param.opcode) { case ESP_BLE_MESH_MODEL_OP_ATTENTION_GET: @@ -369,6 +370,7 @@ static int btc_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param param.ctx.send_rel = params->ctx.send_rel; param.ctx.send_ttl = params->ctx.send_ttl; param.msg_timeout = params->msg_timeout; + param.msg_role = params->msg_role; switch (param.opcode) { case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET: @@ -399,7 +401,6 @@ 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) { BT_ERR("%s, Invalid parameter", __func__); @@ -411,14 +412,6 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg) 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)) { - BT_ERR("Failed to set model role"); - break; - } - cb.error_code = btc_ble_mesh_health_client_get_state(arg->health_client_get_state.params, arg->health_client_get_state.get_state); if (cb.error_code) { @@ -429,14 +422,6 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg) } 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)) { - BT_ERR("Failed to set model role"); - break; - } - cb.error_code = btc_ble_mesh_health_client_set_state(arg->health_client_set_state.params, arg->health_client_set_state.set_state); if (cb.error_code) { diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c index 89e576ebf..013b661c8 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c @@ -298,7 +298,6 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg) 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) { BT_ERR("%s, Invalid parameter", __func__); @@ -310,14 +309,6 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg) switch (msg->act) { 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_client_model_role(&role_param)) { - BT_ERR("Failed to set model role"); - break; - } - common.opcode = params->opcode; common.model = (struct bt_mesh_model *)params->model; common.ctx.net_idx = params->ctx.net_idx; @@ -326,6 +317,7 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg) common.ctx.send_rel = params->ctx.send_rel; common.ctx.send_ttl = params->ctx.send_ttl; common.msg_timeout = params->msg_timeout; + common.msg_role = params->msg_role; cb.params = arg->light_client_get_state.params; cb.error_code = bt_mesh_light_client_get_state(&common, arg->light_client_get_state.get_state); @@ -337,14 +329,6 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg) } 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_client_model_role(&role_param)) { - BT_ERR("Failed to set model role"); - break; - } - common.opcode = params->opcode; common.model = (struct bt_mesh_model *)params->model; common.ctx.net_idx = params->ctx.net_idx; @@ -353,6 +337,7 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg) common.ctx.send_rel = params->ctx.send_rel; common.ctx.send_ttl = params->ctx.send_ttl; common.msg_timeout = params->msg_timeout; + common.msg_role = params->msg_role; cb.params = arg->light_client_set_state.params; cb.error_code = bt_mesh_light_client_set_state(&common, arg->light_client_set_state.set_state); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c index 87026a62e..d0b2517bf 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c @@ -1978,11 +1978,11 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg) switch (msg->act) { case BTC_BLE_MESH_ACT_MODEL_PUBLISH: { if (arg->model_publish.device_role == PROVISIONER) { - 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_client_model_role(&common)) { - BT_ERR("Failed to set model role"); + /* Currently Provisioner only supports client model */ + err = bt_mesh_set_client_model_role((struct bt_mesh_model *)arg->model_publish.model, + arg->model_publish.device_role); + if (err) { + BT_ERR("Failed to set client role"); break; } } @@ -2008,7 +2008,6 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg) break; } case BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND: { - bt_mesh_role_param_t common = {0}; /* arg->model_send.length contains opcode & message, plus extra 4-bytes TransMIC */ struct net_buf_simple *buf = bt_mesh_alloc_buf(arg->model_send.length + BLE_MESH_MIC_SHORT); if (!buf) { @@ -2016,12 +2015,6 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg) break; } net_buf_simple_add_mem(buf, arg->model_send.data, arg->model_send.length); - common.model = (struct bt_mesh_model *)(arg->model_send.model); - common.role = arg->model_send.device_role; - if (bt_mesh_set_client_model_role(&common)) { - BT_ERR("Failed to set model role"); - break; - } bt_mesh_client_common_param_t param = { .opcode = arg->model_send.opcode, .model = (struct bt_mesh_model *)arg->model_send.model, @@ -2032,6 +2025,7 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg) .ctx.send_ttl = arg->model_send.ctx->send_ttl, .ctx.srv_send = false, .msg_timeout = arg->model_send.msg_timeout, + .msg_role = arg->model_send.device_role, }; err = bt_mesh_client_send_msg(¶m, buf, arg->model_send.need_rsp, btc_ble_mesh_client_model_timeout_cb); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c index 100de9833..af05ac4f5 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c @@ -536,7 +536,6 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg) btc_ble_mesh_sensor_client_args_t *arg = NULL; 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) { BT_ERR("%s, Invalid parameter", __func__); @@ -548,14 +547,6 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg) switch (msg->act) { case BTC_BLE_MESH_ACT_SENSOR_CLIENT_GET_STATE: { 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_client_model_role(&role_param)) { - BT_ERR("Failed to set model role"); - break; - } - common.opcode = params->opcode; common.model = (struct bt_mesh_model *)params->model; common.ctx.net_idx = params->ctx.net_idx; @@ -564,6 +555,7 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg) common.ctx.send_rel = params->ctx.send_rel; common.ctx.send_ttl = params->ctx.send_ttl; common.msg_timeout = params->msg_timeout; + common.msg_role = params->msg_role; cb.params = arg->sensor_client_get_state.params; cb.error_code = bt_mesh_sensor_client_get_state(&common, arg->sensor_client_get_state.get_state); @@ -575,14 +567,6 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg) } case BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE: { 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_client_model_role(&role_param)) { - BT_ERR("Failed to set model role"); - break; - } - common.opcode = params->opcode; common.model = (struct bt_mesh_model *)params->model; common.ctx.net_idx = params->ctx.net_idx; @@ -591,6 +575,7 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg) common.ctx.send_rel = params->ctx.send_rel; common.ctx.send_ttl = params->ctx.send_ttl; common.msg_timeout = params->msg_timeout; + common.msg_role = params->msg_role; cb.params = arg->sensor_client_set_state.params; cb.error_code = bt_mesh_sensor_client_set_state(&common, arg->sensor_client_set_state.set_state); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c index ce3318cc8..1609a4591 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c @@ -300,7 +300,6 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg) esp_ble_mesh_client_common_param_t *params = NULL; 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) { BT_ERR("%s, Invalid parameter", __func__); @@ -312,14 +311,6 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg) switch (msg->act) { case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_GET_STATE: { 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_client_model_role(&role_param)) { - BT_ERR("Failed to set model role"); - break; - } - common.opcode = params->opcode; common.model = (struct bt_mesh_model *)params->model; common.ctx.net_idx = params->ctx.net_idx; @@ -328,6 +319,7 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg) common.ctx.send_rel = params->ctx.send_rel; common.ctx.send_ttl = params->ctx.send_ttl; common.msg_timeout = params->msg_timeout; + common.msg_role = params->msg_role; cb.params = arg->time_scene_client_get_state.params; cb.error_code = bt_mesh_time_scene_client_get_state(&common, arg->time_scene_client_get_state.get_state); @@ -339,14 +331,6 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg) } case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_SET_STATE: { 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_client_model_role(&role_param)) { - BT_ERR("Failed to set model role"); - break; - } - common.opcode = params->opcode; common.model = (struct bt_mesh_model *)params->model; common.ctx.net_idx = params->ctx.net_idx; @@ -355,6 +339,7 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg) common.ctx.send_rel = params->ctx.send_rel; common.ctx.send_ttl = params->ctx.send_ttl; common.msg_timeout = params->msg_timeout; + common.msg_role = params->msg_role; cb.params = arg->time_scene_client_set_state.params; cb.error_code = bt_mesh_time_scene_client_set_state(&common, arg->time_scene_client_set_state.set_state); diff --git a/components/bt/esp_ble_mesh/mesh_models/client/client_common.c b/components/bt/esp_ble_mesh/mesh_models/client/client_common.c index 658c3c4a8..20ee9cbb3 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/client_common.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/client_common.c @@ -282,6 +282,11 @@ int bt_mesh_client_send_msg(bt_mesh_client_common_param_t *param, return -EINVAL; } + if (bt_mesh_set_client_model_role(param->model, param->msg_role)) { + BT_ERR("Failed to set client role"); + return -EIO; + } + if (!need_ack) { /* If this is an unack message, send it directly. */ return bt_mesh_model_send(param->model, ¶m->ctx, msg, param->cb, param->cb_data); @@ -499,43 +504,26 @@ int bt_mesh_client_clear_list(void *data) return 0; } -int bt_mesh_set_client_model_role(bt_mesh_role_param_t *common) +int bt_mesh_set_client_model_role(struct bt_mesh_model *model, u8_t role) { bt_mesh_client_user_data_t *client = NULL; - if (!common || !common->model || !common->model->user_data) { - BT_ERR("%s, Invalid parameter", __func__); + if (!model) { + BT_ERR("Invalid client model"); return -EINVAL; } - client = (bt_mesh_client_user_data_t *)common->model->user_data; - - switch (common->role) { -#if CONFIG_BLE_MESH_NODE - case NODE: - /* no matter if provisioner is enabled/disabled , node role can be used to send messages */ - client->msg_role = NODE; - break; -#endif -#if CONFIG_BLE_MESH_PROVISIONER - case PROVISIONER: - /* if provisioner is not enabled, provisioner role can't be used to send messages */ - if (!bt_mesh_is_provisioner_en()) { - BT_ERR("Provisioner is disabled"); - return -EINVAL; - } - client->msg_role = PROVISIONER; - break; -#endif -#if CONFIG_BLE_MESH_FAST_PROV - case FAST_PROV: - client->msg_role = FAST_PROV; - break; -#endif - default: - BT_WARN("Unknown model role 0x%02x", common->role); + client = (bt_mesh_client_user_data_t *)model->user_data; + if (!client) { + BT_ERR("Invalid client user data"); return -EINVAL; } + if (role >= ROLE_NVAL) { + BT_ERR("Invalid client role 0x%02x", role); + return -EINVAL; + } + + client->msg_role = role; return 0; } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/include/client_common.h b/components/bt/esp_ble_mesh/mesh_models/client/include/client_common.h index c6fc89234..9883efe20 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/include/client_common.h +++ b/components/bt/esp_ble_mesh/mesh_models/client/include/client_common.h @@ -79,6 +79,7 @@ typedef struct { 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 */ + u8_t msg_role; /* Role (Node/Provisioner) of the device */ const struct bt_mesh_send_cb *cb; /* User defined callback function */ void *cb_data; /* User defined callback value */ } bt_mesh_client_common_param_t; @@ -112,19 +113,15 @@ int bt_mesh_client_free_node(bt_mesh_client_node_t *node); int bt_mesh_client_clear_list(void *data); -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; - /** - * @brief This function copies node_index for stack internal use. + * @brief Set role of the client model for internal use. * - * @param[in] common: Pointer to the bt_mesh_role_param_t structure + * @param[in] model: Pointer to the client model + * @param[in] role: Role of the device * * @return Zero - success, otherwise - fail */ -int bt_mesh_set_client_model_role(bt_mesh_role_param_t *common); +int bt_mesh_set_client_model_role(struct bt_mesh_model *model, u8_t role); #ifdef __cplusplus } From 8ae06fde5ffa82a003963ef282e21ac8911dcd95 Mon Sep 17 00:00:00 2001 From: lly Date: Sun, 28 Jun 2020 17:03:17 +0800 Subject: [PATCH 41/60] ble_mesh: stack: Fix no events for some error conditions --- components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c index d0b2517bf..f2bf7f780 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c @@ -1983,6 +1983,7 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg) arg->model_publish.device_role); if (err) { BT_ERR("Failed to set client role"); + btc_ble_mesh_model_publish_comp_cb(arg->model_publish.model, err); break; } } @@ -1995,10 +1996,14 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg) struct net_buf_simple *buf = bt_mesh_alloc_buf(arg->model_send.length + BLE_MESH_MIC_SHORT); if (!buf) { BT_ERR("%s, Out of memory", __func__); + btc_ble_mesh_model_send_comp_cb(arg->model_send.model, arg->model_send.ctx, + arg->model_send.opcode, -ENOMEM); break; } + net_buf_simple_add_mem(buf, arg->model_send.data, arg->model_send.length); arg->model_send.ctx->srv_send = true; + 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); @@ -2012,8 +2017,11 @@ void btc_ble_mesh_model_call_handler(btc_msg_t *msg) struct net_buf_simple *buf = bt_mesh_alloc_buf(arg->model_send.length + BLE_MESH_MIC_SHORT); if (!buf) { BT_ERR("%s, Out of memory", __func__); + btc_ble_mesh_model_send_comp_cb(arg->model_send.model, arg->model_send.ctx, + arg->model_send.opcode, -ENOMEM); break; } + net_buf_simple_add_mem(buf, arg->model_send.data, arg->model_send.length); bt_mesh_client_common_param_t param = { .opcode = arg->model_send.opcode, From d5e9fc092c913d4073f619a8043c2b08978c8bc9 Mon Sep 17 00:00:00 2001 From: lly Date: Wed, 8 Jul 2020 09:35:31 +0800 Subject: [PATCH 42/60] ble_mesh: stack: Check client msg result in common func --- .../bt/esp_ble_mesh/mesh_core/cfg_cli.c | 184 +++--------------- .../bt/esp_ble_mesh/mesh_core/health_cli.c | 56 +----- .../mesh_models/client/client_common.c | 22 +-- .../mesh_models/client/generic_client.c | 12 +- .../mesh_models/client/lighting_client.c | 12 +- .../mesh_models/client/sensor_client.c | 4 - .../mesh_models/client/time_scene_client.c | 11 +- 7 files changed, 44 insertions(+), 257 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c b/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c index cd4bdde6a..6168051b8 100644 --- a/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c +++ b/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c @@ -677,48 +677,30 @@ const struct bt_mesh_model_op bt_mesh_cfg_cli_op[] = { static int send_msg_with_none(bt_mesh_client_common_param_t *param, u32_t op) { BLE_MESH_MODEL_BUF_DEFINE(msg, op, 0); - int err = 0; bt_mesh_model_msg_init(&msg, op); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } static int send_msg_with_u8(bt_mesh_client_common_param_t *param, u32_t op, u8_t val) { BLE_MESH_MODEL_BUF_DEFINE(msg, op, 1); - int err = 0; bt_mesh_model_msg_init(&msg, op); net_buf_simple_add_u8(&msg, val); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } static int send_msg_with_le16(bt_mesh_client_common_param_t *param, u32_t op, u16_t val) { BLE_MESH_MODEL_BUF_DEFINE(msg, op, 2); - int err = 0; bt_mesh_model_msg_init(&msg, op); net_buf_simple_add_le16(&msg, val); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } int bt_mesh_cfg_comp_data_get(bt_mesh_client_common_param_t *param, u8_t page) @@ -779,25 +761,18 @@ int bt_mesh_cfg_relay_set(bt_mesh_client_common_param_t *param, u8_t relay, u8_t retransmit) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_RELAY_SET, 2); - int err = 0; bt_mesh_model_msg_init(&msg, OP_RELAY_SET); net_buf_simple_add_u8(&msg, relay); net_buf_simple_add_u8(&msg, retransmit); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } int bt_mesh_cfg_net_key_add(bt_mesh_client_common_param_t *param, u16_t net_idx, const u8_t net_key[16]) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_ADD, 18); - int err = 0; if (!net_key) { BT_ERR("Invalid NetKey"); @@ -808,12 +783,7 @@ int bt_mesh_cfg_net_key_add(bt_mesh_client_common_param_t *param, net_buf_simple_add_le16(&msg, net_idx); net_buf_simple_add_mem(&msg, net_key, 16); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } int bt_mesh_cfg_app_key_add(bt_mesh_client_common_param_t *param, @@ -821,7 +791,6 @@ int bt_mesh_cfg_app_key_add(bt_mesh_client_common_param_t *param, const u8_t app_key[16]) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_ADD, 19); - int err = 0; if (!app_key) { BT_ERR("Invalid AppKey"); @@ -832,12 +801,7 @@ int bt_mesh_cfg_app_key_add(bt_mesh_client_common_param_t *param, key_idx_pack(&msg, net_idx, app_idx); net_buf_simple_add_mem(&msg, app_key, 16); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } int bt_mesh_cfg_mod_app_bind(bt_mesh_client_common_param_t *param, @@ -845,7 +809,6 @@ int bt_mesh_cfg_mod_app_bind(bt_mesh_client_common_param_t *param, u16_t mod_id, u16_t cid) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_APP_BIND, 8); - int err = 0; bt_mesh_model_msg_init(&msg, OP_MOD_APP_BIND); net_buf_simple_add_le16(&msg, elem_addr); @@ -855,12 +818,7 @@ int bt_mesh_cfg_mod_app_bind(bt_mesh_client_common_param_t *param, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } static int mod_sub(bt_mesh_client_common_param_t *param, u32_t op, @@ -868,7 +826,6 @@ static int mod_sub(bt_mesh_client_common_param_t *param, u32_t op, u16_t mod_id, u16_t cid) { BLE_MESH_MODEL_BUF_DEFINE(msg, op, 8); - int err = 0; bt_mesh_model_msg_init(&msg, op); net_buf_simple_add_le16(&msg, elem_addr); @@ -878,12 +835,7 @@ static int mod_sub(bt_mesh_client_common_param_t *param, u32_t op, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } int bt_mesh_cfg_mod_sub_add(bt_mesh_client_common_param_t *param, @@ -912,7 +864,6 @@ static int mod_sub_va(bt_mesh_client_common_param_t *param, u32_t op, u16_t mod_id, u16_t cid) { BLE_MESH_MODEL_BUF_DEFINE(msg, op, 22); - int err = 0; if (!label) { BT_ERR("Invalid label uuid"); @@ -930,12 +881,7 @@ static int mod_sub_va(bt_mesh_client_common_param_t *param, u32_t op, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } int bt_mesh_cfg_mod_sub_va_add(bt_mesh_client_common_param_t *param, @@ -963,7 +909,6 @@ int bt_mesh_cfg_mod_pub_get(bt_mesh_client_common_param_t *param, u16_t elem_addr, u16_t mod_id, u16_t cid) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_PUB_GET, 6); - int err = 0; bt_mesh_model_msg_init(&msg, OP_MOD_PUB_GET); net_buf_simple_add_le16(&msg, elem_addr); @@ -972,12 +917,7 @@ int bt_mesh_cfg_mod_pub_get(bt_mesh_client_common_param_t *param, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } int bt_mesh_cfg_mod_pub_set(bt_mesh_client_common_param_t *param, @@ -985,7 +925,6 @@ int bt_mesh_cfg_mod_pub_set(bt_mesh_client_common_param_t *param, struct bt_mesh_cfg_mod_pub *pub) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_PUB_SET, 13); - int err = 0; if (!pub) { BT_ERR("Invalid model pub set"); @@ -1004,19 +943,13 @@ int bt_mesh_cfg_mod_pub_set(bt_mesh_client_common_param_t *param, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } int bt_mesh_cfg_hb_sub_set(bt_mesh_client_common_param_t *param, struct bt_mesh_cfg_hb_sub *sub) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_SUB_SET, 5); - int err = 0; if (!sub) { BT_ERR("Invalid heartbeat sub set"); @@ -1028,12 +961,7 @@ int bt_mesh_cfg_hb_sub_set(bt_mesh_client_common_param_t *param, net_buf_simple_add_le16(&msg, sub->dst); net_buf_simple_add_u8(&msg, sub->period); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } int bt_mesh_cfg_hb_sub_get(bt_mesh_client_common_param_t *param) @@ -1045,7 +973,6 @@ int bt_mesh_cfg_hb_pub_set(bt_mesh_client_common_param_t *param, struct bt_mesh_cfg_hb_pub *pub) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEARTBEAT_PUB_SET, 9); - int err = 0; if (!pub) { BT_ERR("Invalid heartbeat pub set"); @@ -1060,12 +987,7 @@ int bt_mesh_cfg_hb_pub_set(bt_mesh_client_common_param_t *param, net_buf_simple_add_le16(&msg, pub->feat); net_buf_simple_add_le16(&msg, pub->net_idx); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } int bt_mesh_cfg_hb_pub_get(bt_mesh_client_common_param_t *param) @@ -1084,7 +1006,6 @@ int bt_mesh_cfg_mod_pub_va_set(bt_mesh_client_common_param_t *param, struct bt_mesh_cfg_mod_pub *pub) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_PUB_VA_SET, 27); - int err = 0; if (!label || !pub) { BT_ERR("%s, Invalid parameter", __func__); @@ -1103,19 +1024,13 @@ int bt_mesh_cfg_mod_pub_va_set(bt_mesh_client_common_param_t *param, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } int bt_mesh_cfg_mod_sub_del_all(bt_mesh_client_common_param_t *param, u16_t elem_addr, u16_t mod_id, u16_t cid) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_SUB_DEL_ALL, 6); - int err = 0; bt_mesh_model_msg_init(&msg, OP_MOD_SUB_DEL_ALL); net_buf_simple_add_le16(&msg, elem_addr); @@ -1124,19 +1039,13 @@ int bt_mesh_cfg_mod_sub_del_all(bt_mesh_client_common_param_t *param, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } static int mod_sub_get(bt_mesh_client_common_param_t *param, u32_t op, u16_t elem_addr, u16_t mod_id, u16_t cid) { BLE_MESH_MODEL_BUF_DEFINE(msg, op, 6); - int err = 0; bt_mesh_model_msg_init(&msg, op); net_buf_simple_add_le16(&msg, elem_addr); @@ -1145,12 +1054,7 @@ static int mod_sub_get(bt_mesh_client_common_param_t *param, u32_t op, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } int bt_mesh_cfg_mod_sub_get(bt_mesh_client_common_param_t *param, @@ -1173,7 +1077,6 @@ int bt_mesh_cfg_net_key_update(bt_mesh_client_common_param_t *param, u16_t net_idx, const u8_t net_key[16]) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NET_KEY_UPDATE, 18); - int err = 0; if (!net_key) { BT_ERR("Invalid NetKey"); @@ -1184,12 +1087,7 @@ int bt_mesh_cfg_net_key_update(bt_mesh_client_common_param_t *param, net_buf_simple_add_le16(&msg, net_idx); net_buf_simple_add_mem(&msg, net_key, 16); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } int bt_mesh_cfg_net_key_delete(bt_mesh_client_common_param_t *param, u16_t net_idx) @@ -1207,7 +1105,6 @@ int bt_mesh_cfg_app_key_update(bt_mesh_client_common_param_t *param, const u8_t app_key[16]) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_UPDATE, 19); - int err = 0; if (!app_key) { BT_ERR("Invalid AppKey"); @@ -1218,29 +1115,18 @@ int bt_mesh_cfg_app_key_update(bt_mesh_client_common_param_t *param, key_idx_pack(&msg, net_idx, app_idx); net_buf_simple_add_mem(&msg, app_key, 16); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } int bt_mesh_cfg_app_key_delete(bt_mesh_client_common_param_t *param, u16_t net_idx, u16_t app_idx) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_APP_KEY_DEL, 3); - int err = 0; bt_mesh_model_msg_init(&msg, OP_APP_KEY_DEL); key_idx_pack(&msg, net_idx, app_idx); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } int bt_mesh_cfg_app_key_get(bt_mesh_client_common_param_t *param, u16_t net_idx) @@ -1257,7 +1143,6 @@ int bt_mesh_cfg_node_identity_set(bt_mesh_client_common_param_t *param, u16_t net_idx, u8_t identity) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_NODE_IDENTITY_SET, 3); - int err = 0; if (identity > 0x02) { BT_ERR("Invalid node identity 0x%02x", identity); @@ -1268,12 +1153,7 @@ int bt_mesh_cfg_node_identity_set(bt_mesh_client_common_param_t *param, net_buf_simple_add_le16(&msg, net_idx); net_buf_simple_add_u8(&msg, identity); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } int bt_mesh_cfg_mod_app_unbind(bt_mesh_client_common_param_t *param, @@ -1281,7 +1161,6 @@ int bt_mesh_cfg_mod_app_unbind(bt_mesh_client_common_param_t *param, u16_t mod_id, u16_t cid) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_MOD_APP_UNBIND, 8); - int err = 0; bt_mesh_model_msg_init(&msg, OP_MOD_APP_UNBIND); net_buf_simple_add_le16(&msg, elem_addr); @@ -1291,19 +1170,13 @@ int bt_mesh_cfg_mod_app_unbind(bt_mesh_client_common_param_t *param, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } static int mod_app_get(bt_mesh_client_common_param_t *param, u32_t op, u16_t elem_addr, u16_t mod_id, u16_t cid) { BLE_MESH_MODEL_BUF_DEFINE(msg, op, 6); - int err = 0; bt_mesh_model_msg_init(&msg, op); net_buf_simple_add_le16(&msg, elem_addr); @@ -1312,12 +1185,7 @@ static int mod_app_get(bt_mesh_client_common_param_t *param, u32_t op, } net_buf_simple_add_le16(&msg, mod_id); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } int bt_mesh_cfg_mod_app_get(bt_mesh_client_common_param_t *param, @@ -1345,7 +1213,6 @@ int bt_mesh_cfg_kr_phase_set(bt_mesh_client_common_param_t *param, u16_t net_idx, u8_t transition) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_KRP_SET, 3); - int err = 0; if (transition > 0x03) { BT_ERR("Invalid kr phase transition 0x%02x", transition); @@ -1356,12 +1223,7 @@ int bt_mesh_cfg_kr_phase_set(bt_mesh_client_common_param_t *param, net_buf_simple_add_le16(&msg, net_idx); net_buf_simple_add_u8(&msg, transition); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } int bt_mesh_cfg_lpn_timeout_get(bt_mesh_client_common_param_t *param, u16_t lpn_addr) diff --git a/components/bt/esp_ble_mesh/mesh_core/health_cli.c b/components/bt/esp_ble_mesh/mesh_core/health_cli.c index 1c8475154..68f8e828e 100644 --- a/components/bt/esp_ble_mesh/mesh_core/health_cli.c +++ b/components/bt/esp_ble_mesh/mesh_core/health_cli.c @@ -234,116 +234,74 @@ const struct bt_mesh_model_op bt_mesh_health_cli_op[] = { int bt_mesh_health_attention_get(bt_mesh_client_common_param_t *param) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_ATTENTION_GET, 0); - int err = 0; bt_mesh_model_msg_init(&msg, OP_ATTENTION_GET); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } int bt_mesh_health_attention_set(bt_mesh_client_common_param_t *param, u8_t attention, bool need_ack) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_ATTENTION_SET, 1); - int err = 0; bt_mesh_model_msg_init(&msg, need_ack ? OP_ATTENTION_SET : OP_ATTENTION_SET_UNREL); net_buf_simple_add_u8(&msg, attention); - err = bt_mesh_client_send_msg(param, &msg, need_ack, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, need_ack, timeout_handler); } int bt_mesh_health_period_get(bt_mesh_client_common_param_t *param) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_PERIOD_GET, 0); - int err = 0; bt_mesh_model_msg_init(&msg, OP_HEALTH_PERIOD_GET); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } int bt_mesh_health_period_set(bt_mesh_client_common_param_t *param, u8_t divisor, bool need_ack) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_PERIOD_SET, 1); - int err = 0; bt_mesh_model_msg_init(&msg, need_ack ? OP_HEALTH_PERIOD_SET : OP_HEALTH_PERIOD_SET_UNREL); net_buf_simple_add_u8(&msg, divisor); - err = bt_mesh_client_send_msg(param, &msg, need_ack, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, need_ack, timeout_handler); } int bt_mesh_health_fault_test(bt_mesh_client_common_param_t *param, u16_t cid, u8_t test_id, bool need_ack) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_FAULT_TEST, 3); - int err = 0; bt_mesh_model_msg_init(&msg, need_ack ? OP_HEALTH_FAULT_TEST : OP_HEALTH_FAULT_TEST_UNREL); net_buf_simple_add_u8(&msg, test_id); net_buf_simple_add_le16(&msg, cid); - err = bt_mesh_client_send_msg(param, &msg, need_ack, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, need_ack, timeout_handler); } int bt_mesh_health_fault_clear(bt_mesh_client_common_param_t *param, u16_t cid, bool need_ack) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_FAULT_CLEAR, 2); - int err = 0; bt_mesh_model_msg_init(&msg, need_ack ? OP_HEALTH_FAULT_CLEAR : OP_HEALTH_FAULT_CLEAR_UNREL); net_buf_simple_add_le16(&msg, cid); - err = bt_mesh_client_send_msg(param, &msg, need_ack, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, need_ack, timeout_handler); } int bt_mesh_health_fault_get(bt_mesh_client_common_param_t *param, u16_t cid) { BLE_MESH_MODEL_BUF_DEFINE(msg, OP_HEALTH_FAULT_GET, 2); - int err = 0; bt_mesh_model_msg_init(&msg, OP_HEALTH_FAULT_GET); net_buf_simple_add_le16(&msg, cid); - err = bt_mesh_client_send_msg(param, &msg, true, timeout_handler); - if (err) { - BT_ERR("%s, send failed (err %d)", __func__, err); - } - - return err; + return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } int bt_mesh_health_cli_init(struct bt_mesh_model *model, bool primary) diff --git a/components/bt/esp_ble_mesh/mesh_models/client/client_common.c b/components/bt/esp_ble_mesh/mesh_models/client/client_common.c index 20ee9cbb3..857028628 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/client_common.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/client_common.c @@ -287,18 +287,18 @@ int bt_mesh_client_send_msg(bt_mesh_client_common_param_t *param, return -EIO; } - if (!need_ack) { - /* If this is an unack message, send it directly. */ - return bt_mesh_model_send(param->model, ¶m->ctx, msg, param->cb, param->cb_data); - } - - if (!BLE_MESH_ADDR_IS_UNICAST(param->ctx.addr)) { - /* If an acknowledged message is not sent to a unicast address, - * for example to a group/virtual address, then all the - * corresponding responses will be treated as publish messages. - * And no timeout will be used for the message. + if (need_ack == false || !BLE_MESH_ADDR_IS_UNICAST(param->ctx.addr)) { + /* 1. If this is an unacknowledged message, send it directly. + * 2. If this is an acknowledged message, but the destination + * is not a unicast address, e.g. a group/virtual address, + * then all the corresponding responses will be treated as + * publish messages, and no timeout will be used. */ - return bt_mesh_model_send(param->model, ¶m->ctx, msg, param->cb, param->cb_data); + err = bt_mesh_model_send(param->model, ¶m->ctx, msg, param->cb, param->cb_data); + if (err) { + BT_ERR("Failed to send client message 0x%08x", param->opcode); + } + return err; } if (!timer_handler) { diff --git a/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c b/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c index 6f11f6004..62a1ea626 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c @@ -689,7 +689,6 @@ const struct bt_mesh_model_op gen_property_cli_op[] = { 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 = 0; bt_mesh_model_msg_init(&msg, common->opcode); @@ -725,12 +724,7 @@ static int gen_get_state(bt_mesh_client_common_param_t *common, void *value) } } - err = bt_mesh_client_send_msg(common, &msg, true, timeout_handler); - if (err) { - BT_ERR("Failed to send Generic Get message (err %d)", err); - } - - return err; + return bt_mesh_client_send_msg(common, &msg, true, timeout_handler); } static int gen_set_state(bt_mesh_client_common_param_t *common, @@ -903,13 +897,9 @@ static int gen_set_state(bt_mesh_client_common_param_t *common, } err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler); - if (err) { - BT_ERR("Failed to send Generic Set message (err %d)", err); - } end: bt_mesh_free_buf(msg); - return err; } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c b/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c index f89161de5..45454afbf 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c @@ -772,7 +772,6 @@ const struct bt_mesh_model_op light_lc_cli_op[] = { 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 = 0; bt_mesh_model_msg_init(&msg, common->opcode); @@ -790,12 +789,7 @@ static int light_get_state(bt_mesh_client_common_param_t *common, void *value) } } - err = bt_mesh_client_send_msg(common, &msg, true, timeout_handler); - if (err) { - BT_ERR("Failed to send Lighting Get message (err %d)", err); - } - - return err; + return bt_mesh_client_send_msg(common, &msg, true, timeout_handler); } static int light_set_state(bt_mesh_client_common_param_t *common, @@ -1027,13 +1021,9 @@ static int light_set_state(bt_mesh_client_common_param_t *common, } err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler); - if (err) { - BT_ERR("Failed to send Lighting Set message (err %d)", err); - } end: bt_mesh_free_buf(msg); - return err; } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c b/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c index 9ef7694e5..c003c0183 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c @@ -448,13 +448,9 @@ static int sensor_act_state(bt_mesh_client_common_param_t *common, } err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler); - if (err) { - BT_ERR("Failed to send Sensor client message (err %d)", err); - } end: bt_mesh_free_buf(msg); - return err; } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c b/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c index 8d416ba03..201d8b51f 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c @@ -372,7 +372,6 @@ const struct bt_mesh_model_op scheduler_cli_op[] = { 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 = 0; bt_mesh_model_msg_init(&msg, common->opcode); @@ -390,12 +389,7 @@ static int time_scene_get_state(bt_mesh_client_common_param_t *common, void *val } } - err = bt_mesh_client_send_msg(common, &msg, true, timeout_handler); - if (err) { - BT_ERR("Failed to send Time Scene Get message (err %d)", err); - } - - return err; + return bt_mesh_client_send_msg(common, &msg, true, timeout_handler); } static int time_scene_set_state(bt_mesh_client_common_param_t *common, @@ -484,9 +478,6 @@ static int time_scene_set_state(bt_mesh_client_common_param_t *common, } err = bt_mesh_client_send_msg(common, msg, need_ack, timeout_handler); - if (err) { - BT_ERR("Failed to send Time Scene Set message (err %d)", err); - } end: bt_mesh_free_buf(msg); From 8a19d03a1c10284cde0eb2c66149a47917847174 Mon Sep 17 00:00:00 2001 From: lly Date: Thu, 16 Jul 2020 15:20:45 +0800 Subject: [PATCH 43/60] ble_mesh: stack: Rename cfg & health client status recv func --- .../bt/esp_ble_mesh/mesh_core/cfg_cli.c | 42 +++++++++---------- .../bt/esp_ble_mesh/mesh_core/health_cli.c | 14 +++---- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c b/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c index 6168051b8..4da7b8b23 100644 --- a/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c +++ b/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c @@ -123,9 +123,9 @@ static void timeout_handler(struct k_work *work) return; } -static void cfg_client_cancel(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - void *status, size_t len) +static void cfg_client_recv_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + void *status, size_t len) { bt_mesh_client_node_t *node = NULL; struct net_buf_simple buf = {0}; @@ -265,7 +265,7 @@ static void comp_data_status(struct bt_mesh_model *model, net_buf_simple_add_mem(status.comp_data, buf->data, buf->len); - cfg_client_cancel(model, ctx, &status, sizeof(struct bt_mesh_cfg_comp_data_status)); + cfg_client_recv_status(model, ctx, &status, sizeof(struct bt_mesh_cfg_comp_data_status)); } static void state_status_u8(struct bt_mesh_model *model, @@ -280,7 +280,7 @@ static void state_status_u8(struct bt_mesh_model *model, status = net_buf_simple_pull_u8(buf); - cfg_client_cancel(model, ctx, &status, sizeof(u8_t)); + cfg_client_recv_status(model, ctx, &status, sizeof(u8_t)); } static void beacon_status(struct bt_mesh_model *model, @@ -324,7 +324,7 @@ static void relay_status(struct bt_mesh_model *model, status.relay = net_buf_simple_pull_u8(buf); status.retransmit = net_buf_simple_pull_u8(buf); - cfg_client_cancel(model, ctx, &status, sizeof(struct bt_mesh_cfg_relay_status)); + cfg_client_recv_status(model, ctx, &status, sizeof(struct bt_mesh_cfg_relay_status)); } static void net_key_status(struct bt_mesh_model *model, @@ -340,7 +340,7 @@ static void net_key_status(struct bt_mesh_model *model, status.status = net_buf_simple_pull_u8(buf); status.net_idx = net_buf_simple_pull_le16(buf) & 0xfff; - cfg_client_cancel(model, ctx, &status, sizeof(struct bt_mesh_cfg_netkey_status)); + cfg_client_recv_status(model, ctx, &status, sizeof(struct bt_mesh_cfg_netkey_status)); } static void app_key_status(struct bt_mesh_model *model, @@ -356,7 +356,7 @@ static void app_key_status(struct bt_mesh_model *model, status.status = net_buf_simple_pull_u8(buf); key_idx_unpack(buf, &status.net_idx, &status.app_idx); - cfg_client_cancel(model, ctx, &status, sizeof(struct bt_mesh_cfg_appkey_status)); + cfg_client_recv_status(model, ctx, &status, sizeof(struct bt_mesh_cfg_appkey_status)); } static void mod_app_status(struct bt_mesh_model *model, @@ -379,7 +379,7 @@ static void mod_app_status(struct bt_mesh_model *model, } status.mod_id = net_buf_simple_pull_le16(buf); - cfg_client_cancel(model, ctx, &status, sizeof(struct bt_mesh_cfg_mod_app_status)); + cfg_client_recv_status(model, ctx, &status, sizeof(struct bt_mesh_cfg_mod_app_status)); } static void mod_pub_status(struct bt_mesh_model *model, @@ -408,7 +408,7 @@ static void mod_pub_status(struct bt_mesh_model *model, } status.mod_id = net_buf_simple_pull_le16(buf); - cfg_client_cancel(model, ctx, &status, sizeof(struct bt_mesh_cfg_mod_pub_status)); + cfg_client_recv_status(model, ctx, &status, sizeof(struct bt_mesh_cfg_mod_pub_status)); } static void mod_sub_status(struct bt_mesh_model *model, @@ -431,7 +431,7 @@ static void mod_sub_status(struct bt_mesh_model *model, } status.mod_id = net_buf_simple_pull_le16(buf); - cfg_client_cancel(model, ctx, &status, sizeof(struct bt_mesh_cfg_mod_sub_status)); + cfg_client_recv_status(model, ctx, &status, sizeof(struct bt_mesh_cfg_mod_sub_status)); } static void hb_sub_status(struct bt_mesh_model *model, @@ -452,7 +452,7 @@ static void hb_sub_status(struct bt_mesh_model *model, status.min = net_buf_simple_pull_u8(buf); status.max = net_buf_simple_pull_u8(buf); - cfg_client_cancel(model, ctx, &status, sizeof(struct bt_mesh_cfg_hb_sub_status)); + cfg_client_recv_status(model, ctx, &status, sizeof(struct bt_mesh_cfg_hb_sub_status)); } static void hb_pub_status(struct bt_mesh_model *model, @@ -473,7 +473,7 @@ static void hb_pub_status(struct bt_mesh_model *model, status.feat = net_buf_simple_pull_u8(buf); status.net_idx = net_buf_simple_pull_u8(buf); - cfg_client_cancel(model, ctx, &status, sizeof(struct bt_mesh_cfg_hb_sub_status)); + cfg_client_recv_status(model, ctx, &status, sizeof(struct bt_mesh_cfg_hb_sub_status)); } static void node_reset_status(struct bt_mesh_model *model, @@ -484,7 +484,7 @@ static void node_reset_status(struct bt_mesh_model *model, ctx->net_idx, ctx->app_idx, ctx->addr, buf->len, bt_hex(buf->data, buf->len)); - cfg_client_cancel(model, ctx, NULL, 0); + cfg_client_recv_status(model, ctx, NULL, 0); } static void mod_sub_list(struct bt_mesh_model *model, @@ -513,7 +513,7 @@ static void mod_sub_list(struct bt_mesh_model *model, } net_buf_simple_add_mem(list.addr, buf->data, buf->len); - cfg_client_cancel(model, ctx, &list, sizeof(struct bt_mesh_cfg_mod_sub_list)); + cfg_client_recv_status(model, ctx, &list, sizeof(struct bt_mesh_cfg_mod_sub_list)); } static void net_key_list(struct bt_mesh_model *model, @@ -533,7 +533,7 @@ static void net_key_list(struct bt_mesh_model *model, } net_buf_simple_add_mem(list.net_idx, buf->data, buf->len); - cfg_client_cancel(model, ctx, &list, sizeof(struct bt_mesh_cfg_net_key_list)); + cfg_client_recv_status(model, ctx, &list, sizeof(struct bt_mesh_cfg_net_key_list)); } static void app_key_list(struct bt_mesh_model *model, @@ -555,7 +555,7 @@ static void app_key_list(struct bt_mesh_model *model, } net_buf_simple_add_mem(list.app_idx, buf->data, buf->len); - cfg_client_cancel(model, ctx, &list, sizeof(struct bt_mesh_cfg_app_key_list)); + cfg_client_recv_status(model, ctx, &list, sizeof(struct bt_mesh_cfg_app_key_list)); } static void node_id_status(struct bt_mesh_model *model, @@ -572,7 +572,7 @@ static void node_id_status(struct bt_mesh_model *model, status.net_idx = net_buf_simple_pull_le16(buf); status.identity = net_buf_simple_pull_u8(buf); - cfg_client_cancel(model, ctx, &status, sizeof(struct bt_mesh_cfg_node_id_status)); + cfg_client_recv_status(model, ctx, &status, sizeof(struct bt_mesh_cfg_node_id_status)); } static void mod_app_list(struct bt_mesh_model *model, @@ -601,7 +601,7 @@ static void mod_app_list(struct bt_mesh_model *model, } net_buf_simple_add_mem(list.app_idx, buf->data, buf->len); - cfg_client_cancel(model, ctx, &list, sizeof(struct bt_mesh_cfg_mod_app_list)); + cfg_client_recv_status(model, ctx, &list, sizeof(struct bt_mesh_cfg_mod_app_list)); } static void kr_phase_status(struct bt_mesh_model *model, @@ -618,7 +618,7 @@ static void kr_phase_status(struct bt_mesh_model *model, status.net_idx = net_buf_simple_pull_le16(buf); status.phase = net_buf_simple_pull_u8(buf); - cfg_client_cancel(model, ctx, &status, sizeof(struct bt_mesh_cfg_key_refresh_status)); + cfg_client_recv_status(model, ctx, &status, sizeof(struct bt_mesh_cfg_key_refresh_status)); } static void lpn_pollto_status(struct bt_mesh_model *model, @@ -636,7 +636,7 @@ static void lpn_pollto_status(struct bt_mesh_model *model, status.timeout |= net_buf_simple_pull_u8(buf) << 8; status.timeout |= net_buf_simple_pull_u8(buf) << 16; - cfg_client_cancel(model, ctx, &status, sizeof(struct bt_mesh_cfg_lpn_pollto_status)); + cfg_client_recv_status(model, ctx, &status, sizeof(struct bt_mesh_cfg_lpn_pollto_status)); } static void net_trans_status(struct bt_mesh_model *model, diff --git a/components/bt/esp_ble_mesh/mesh_core/health_cli.c b/components/bt/esp_ble_mesh/mesh_core/health_cli.c index 68f8e828e..58a4acc44 100644 --- a/components/bt/esp_ble_mesh/mesh_core/health_cli.c +++ b/components/bt/esp_ble_mesh/mesh_core/health_cli.c @@ -81,9 +81,9 @@ static void timeout_handler(struct k_work *work) return; } -static void health_client_cancel(struct bt_mesh_model *model, - struct bt_mesh_msg_ctx *ctx, - void *status, size_t len) +static void health_client_recv_status(struct bt_mesh_model *model, + struct bt_mesh_msg_ctx *ctx, + void *status, size_t len) { bt_mesh_client_node_t *node = NULL; struct net_buf_simple buf = {0}; @@ -167,7 +167,7 @@ static void health_fault_status(struct bt_mesh_model *model, net_buf_simple_add_mem(status.fault_array, buf->data, buf->len); - health_client_cancel(model, ctx, &status, sizeof(struct bt_mesh_health_fault_status)); + health_client_recv_status(model, ctx, &status, sizeof(struct bt_mesh_health_fault_status)); } static void health_current_status(struct bt_mesh_model *model, @@ -190,7 +190,7 @@ static void health_current_status(struct bt_mesh_model *model, net_buf_simple_add_mem(status.fault_array, buf->data, buf->len); - health_client_cancel(model, ctx, &status, sizeof(struct bt_mesh_health_current_status)); + health_client_recv_status(model, ctx, &status, sizeof(struct bt_mesh_health_current_status)); } static void health_period_status(struct bt_mesh_model *model, @@ -205,7 +205,7 @@ static void health_period_status(struct bt_mesh_model *model, status = net_buf_simple_pull_u8(buf); - health_client_cancel(model, ctx, &status, sizeof(u8_t)); + health_client_recv_status(model, ctx, &status, sizeof(u8_t)); } static void health_attention_status(struct bt_mesh_model *model, @@ -220,7 +220,7 @@ static void health_attention_status(struct bt_mesh_model *model, status = net_buf_simple_pull_u8(buf); - health_client_cancel(model, ctx, &status, sizeof(u8_t)); + health_client_recv_status(model, ctx, &status, sizeof(u8_t)); } const struct bt_mesh_model_op bt_mesh_health_cli_op[] = { From 31060cf42b77c6eeadd2ca91c2f475745c36d93f Mon Sep 17 00:00:00 2001 From: lly Date: Thu, 16 Jul 2020 15:40:48 +0800 Subject: [PATCH 44/60] ble_mesh: stack: Client model related code clean --- .../bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c | 8 ++------ .../bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c | 8 ++------ .../bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c | 4 +--- .../bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c | 8 ++------ .../bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c | 8 ++------ .../bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c | 8 ++------ components/bt/esp_ble_mesh/mesh_core/cfg_cli.c | 3 +-- components/bt/esp_ble_mesh/mesh_core/health_cli.c | 3 +-- 8 files changed, 13 insertions(+), 37 deletions(-) diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c index 8e34d47fc..170ed4ff1 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_config_model.c @@ -315,7 +315,6 @@ void bt_mesh_config_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, { esp_ble_mesh_cfg_client_cb_param_t cb_params = {0}; esp_ble_mesh_client_common_param_t params = {0}; - size_t length = 0U; uint8_t act = 0U; if (!model || !ctx) { @@ -356,8 +355,7 @@ void bt_mesh_config_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, cb_params.params = ¶ms; if (val && len) { - length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb); - memcpy(&cb_params.status_cb, val, length); + memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb))); } btc_ble_mesh_config_client_callback(&cb_params, act); @@ -716,7 +714,6 @@ void bt_mesh_config_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model *mo const u8_t *val, size_t len) { esp_ble_mesh_cfg_server_cb_param_t cb_params = {0}; - size_t length = 0U; uint8_t act = 0U; if (!model || !ctx) { @@ -744,8 +741,7 @@ void bt_mesh_config_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model *mo cb_params.ctx.send_ttl = ctx->send_ttl; if (val && len) { - length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value); - memcpy(&cb_params.value, val, length); + memcpy(&cb_params.value, val, MIN(len, sizeof(cb_params.value))); } btc_ble_mesh_config_server_callback(&cb_params, act); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c index ec959964a..15b729a5a 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_generic_model.c @@ -385,7 +385,6 @@ void bt_mesh_generic_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, { esp_ble_mesh_generic_client_cb_param_t cb_params = {0}; esp_ble_mesh_client_common_param_t params = {0}; - size_t length = 0U; uint8_t act = 0U; if (!model || !ctx) { @@ -426,8 +425,7 @@ void bt_mesh_generic_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, cb_params.params = ¶ms; if (val && len) { - length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb); - memcpy(&cb_params.status_cb, val, length); + memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb))); } btc_ble_mesh_generic_client_callback(&cb_params, act); @@ -698,7 +696,6 @@ void bt_mesh_generic_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model *m const u8_t *val, size_t len) { esp_ble_mesh_generic_server_cb_param_t cb_params = {0}; - size_t length = 0U; uint8_t act = 0U; if (model == NULL || ctx == NULL) { @@ -732,8 +729,7 @@ void bt_mesh_generic_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model *m cb_params.ctx.send_ttl = ctx->send_ttl; if (val && len) { - length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value); - memcpy(&cb_params.value, val, length); + memcpy(&cb_params.value, val, MIN(len, sizeof(cb_params.value))); } btc_ble_mesh_generic_server_callback(&cb_params, act); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c index 9ed378906..9e401446c 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_health_model.c @@ -249,7 +249,6 @@ void bt_mesh_health_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, { esp_ble_mesh_health_client_cb_param_t cb_params = {0}; esp_ble_mesh_client_common_param_t params = {0}; - size_t length = 0U; uint8_t act = 0U; if (!model || !ctx) { @@ -290,8 +289,7 @@ void bt_mesh_health_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, cb_params.params = ¶ms; if (val && len) { - length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb); - memcpy(&cb_params.status_cb, val, length); + memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb))); } btc_ble_mesh_health_client_callback(&cb_params, act); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c index 013b661c8..bd3480805 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_lighting_model.c @@ -229,7 +229,6 @@ void bt_mesh_lighting_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, { esp_ble_mesh_light_client_cb_param_t cb_params = {0}; esp_ble_mesh_client_common_param_t params = {0}; - size_t length = 0U; uint8_t act = 0U; if (!model || !ctx) { @@ -270,8 +269,7 @@ void bt_mesh_lighting_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, cb_params.params = ¶ms; if (val && len) { - length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb); - memcpy(&cb_params.status_cb, val, length); + memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb))); } btc_ble_mesh_lighting_client_callback(&cb_params, act); @@ -510,7 +508,6 @@ void bt_mesh_lighting_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model * const u8_t *val, size_t len) { esp_ble_mesh_lighting_server_cb_param_t cb_params = {0}; - size_t length = 0U; uint8_t act = 0U; if (model == NULL || ctx == NULL) { @@ -547,8 +544,7 @@ void bt_mesh_lighting_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model * cb_params.ctx.send_ttl = ctx->send_ttl; if (val && len) { - length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value); - memcpy(&cb_params.value, val, length); + memcpy(&cb_params.value, val, MIN(len, sizeof(cb_params.value))); } btc_ble_mesh_lighting_server_callback(&cb_params, act); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c index af05ac4f5..048d9ddb6 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_sensor_model.c @@ -467,7 +467,6 @@ void bt_mesh_sensor_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, { esp_ble_mesh_sensor_client_cb_param_t cb_params = {0}; esp_ble_mesh_client_common_param_t params = {0}; - size_t length = 0U; uint8_t act = 0U; if (!model || !ctx) { @@ -508,8 +507,7 @@ void bt_mesh_sensor_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, cb_params.params = ¶ms; if (val && len) { - length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb); - memcpy(&cb_params.status_cb, val, length); + memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb))); } btc_ble_mesh_sensor_client_callback(&cb_params, act); @@ -830,7 +828,6 @@ void bt_mesh_sensor_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model *mo const u8_t *val, size_t len) { esp_ble_mesh_sensor_server_cb_param_t cb_params = {0}; - size_t length = 0U; uint8_t act = 0U; if (model == NULL || ctx == NULL) { @@ -864,8 +861,7 @@ void bt_mesh_sensor_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model *mo cb_params.ctx.send_ttl = ctx->send_ttl; if (val && len) { - length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value); - memcpy(&cb_params.value, val, length); + memcpy(&cb_params.value, val, MIN(len, sizeof(cb_params.value))); } btc_ble_mesh_sensor_server_callback(&cb_params, act); diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c index 1609a4591..8fd1b4810 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_time_scene_model.c @@ -231,7 +231,6 @@ void bt_mesh_time_scene_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, { esp_ble_mesh_time_scene_client_cb_param_t cb_params = {0}; esp_ble_mesh_client_common_param_t params = {0}; - size_t length = 0U; uint8_t act = 0U; if (!model || !ctx) { @@ -272,8 +271,7 @@ void bt_mesh_time_scene_client_cb_evt_to_btc(u32_t opcode, u8_t evt_type, cb_params.params = ¶ms; if (val && len) { - length = (len <= sizeof(cb_params.status_cb)) ? len : sizeof(cb_params.status_cb); - memcpy(&cb_params.status_cb, val, length); + memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb))); } btc_ble_mesh_time_scene_client_callback(&cb_params, act); @@ -413,7 +411,6 @@ void bt_mesh_time_scene_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model const u8_t *val, size_t len) { esp_ble_mesh_time_scene_server_cb_param_t cb_params = {0}; - size_t length = 0U; uint8_t act = 0U; if (model == NULL || ctx == NULL) { @@ -450,8 +447,7 @@ void bt_mesh_time_scene_server_cb_evt_to_btc(u8_t evt_type, struct bt_mesh_model cb_params.ctx.send_ttl = ctx->send_ttl; if (val && len) { - length = (len <= sizeof(cb_params.value)) ? len : sizeof(cb_params.value); - memcpy(&cb_params.value, val, length); + memcpy(&cb_params.value, val, MIN(len, sizeof(cb_params.value))); } btc_ble_mesh_time_scene_server_callback(&cb_params, act); diff --git a/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c b/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c index 4da7b8b23..61bcc541d 100644 --- a/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c +++ b/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c @@ -214,8 +214,7 @@ static void cfg_client_recv_status(struct bt_mesh_model *model, switch (ctx->recv_op) { case OP_DEV_COMP_DATA_STATUS: { - struct bt_mesh_cfg_comp_data_status *val; - val = (struct bt_mesh_cfg_comp_data_status *)status; + struct bt_mesh_cfg_comp_data_status *val = status; bt_mesh_free_buf(val->comp_data); break; } diff --git a/components/bt/esp_ble_mesh/mesh_core/health_cli.c b/components/bt/esp_ble_mesh/mesh_core/health_cli.c index 58a4acc44..2af6dbad2 100644 --- a/components/bt/esp_ble_mesh/mesh_core/health_cli.c +++ b/components/bt/esp_ble_mesh/mesh_core/health_cli.c @@ -132,8 +132,7 @@ static void health_client_recv_status(struct bt_mesh_model *model, switch (ctx->recv_op) { case OP_HEALTH_FAULT_STATUS: { - struct bt_mesh_health_fault_status *val; - val = (struct bt_mesh_health_fault_status *)status; + struct bt_mesh_health_fault_status *val = status; bt_mesh_free_buf(val->fault_array); break; } From 5725cb93420c196eb1907477db2feb148a8da801 Mon Sep 17 00:00:00 2001 From: Carlos Sobrinho Date: Mon, 17 Aug 2020 14:32:08 -0700 Subject: [PATCH 45/60] Fix compilation warnings about portmacro being already define. --- .../esp_ble_mesh/components/button/include/iot_button.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/bluetooth/esp_ble_mesh/components/button/include/iot_button.h b/examples/bluetooth/esp_ble_mesh/components/button/include/iot_button.h index 0a8564d68..76333c100 100644 --- a/examples/bluetooth/esp_ble_mesh/components/button/include/iot_button.h +++ b/examples/bluetooth/esp_ble_mesh/components/button/include/iot_button.h @@ -19,7 +19,7 @@ extern "C" { #endif #include "driver/gpio.h" -#include "freertos/portmacro.h" +#include "freertos/FreeRTOS.h" typedef void (* button_cb)(void*); typedef void* button_handle_t; From f8bf6b1f91321c123630c10de3fc4118e8b6d06c Mon Sep 17 00:00:00 2001 From: lly Date: Tue, 18 Aug 2020 16:46:10 +0800 Subject: [PATCH 46/60] ble_mesh: example: Remove some useless included header files --- .../esp_ble_mesh/ble_mesh_node/onoff_client/main/board.c | 2 +- .../ble_mesh_sensor_model/sensor_client/main/board.c | 1 - .../ble_mesh_vendor_model/vendor_client/main/board.c | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_client/main/board.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_client/main/board.c index ce8f599af..ff0c2a65d 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_client/main/board.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_node/onoff_client/main/board.c @@ -9,7 +9,7 @@ #include -#include "driver/uart.h" +#include "driver/gpio.h" #include "esp_log.h" #include "iot_button.h" diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_sensor_model/sensor_client/main/board.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_sensor_model/sensor_client/main/board.c index 8bc2e44e5..0921ca2c5 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_sensor_model/sensor_client/main/board.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_sensor_model/sensor_client/main/board.c @@ -9,7 +9,6 @@ #include #include "esp_log.h" -#include "driver/uart.h" #include "iot_button.h" #include "esp_ble_mesh_sensor_model_api.h" diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_vendor_model/vendor_client/main/board.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_vendor_model/vendor_client/main/board.c index 0937ae7d7..5e57bcf01 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_vendor_model/vendor_client/main/board.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_vendor_model/vendor_client/main/board.c @@ -9,7 +9,6 @@ #include #include "esp_log.h" -#include "driver/uart.h" #include "iot_button.h" #define TAG "BOARD" From 6552aef2e7f9406a9e7696cc117cd161b8c7750b Mon Sep 17 00:00:00 2001 From: "Michael (XIAO Xufeng)" Date: Wed, 15 Jul 2020 22:15:00 +0800 Subject: [PATCH 47/60] driver test: disable the spi master performance test when psram is used --- components/driver/test/test_spi_master.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/components/driver/test/test_spi_master.c b/components/driver/test/test_spi_master.c index d2542c062..0a6e9f2b0 100644 --- a/components/driver/test/test_spi_master.c +++ b/components/driver/test/test_spi_master.c @@ -937,7 +937,9 @@ TEST_CASE("spi_speed","[spi]") for (int i = 0; i < TEST_TIMES; i++) { ESP_LOGI(TAG, "%d", t_flight_sorted[i]); } +#ifndef CONFIG_SPIRAM_SUPPORT TEST_PERFORMANCE_LESS_THAN(SPI_PER_TRANS_NO_POLLING, "%d us", t_flight_sorted[(TEST_TIMES+1)/2]); +#endif //acquire the bus to send polling transactions faster ret = spi_device_acquire_bus(spi, portMAX_DELAY); @@ -952,7 +954,9 @@ TEST_CASE("spi_speed","[spi]") for (int i = 0; i < TEST_TIMES; i++) { ESP_LOGI(TAG, "%d", t_flight_sorted[i]); } +#ifndef CONFIG_SPIRAM_SUPPORT TEST_PERFORMANCE_LESS_THAN(SPI_PER_TRANS_POLLING, "%d us", t_flight_sorted[(TEST_TIMES+1)/2]); +#endif //release the bus spi_device_release_bus(spi); @@ -970,7 +974,9 @@ TEST_CASE("spi_speed","[spi]") for (int i = 0; i < TEST_TIMES; i++) { ESP_LOGI(TAG, "%d", t_flight_sorted[i]); } +#ifndef CONFIG_SPIRAM_SUPPORT TEST_PERFORMANCE_LESS_THAN( SPI_PER_TRANS_NO_POLLING_NO_DMA, "%d us", t_flight_sorted[(TEST_TIMES+1)/2]); +#endif //acquire the bus to send polling transactions faster ret = spi_device_acquire_bus(spi, portMAX_DELAY); @@ -984,7 +990,9 @@ TEST_CASE("spi_speed","[spi]") for (int i = 0; i < TEST_TIMES; i++) { ESP_LOGI(TAG, "%d", t_flight_sorted[i]); } +#ifndef CONFIG_SPIRAM_SUPPORT TEST_PERFORMANCE_LESS_THAN(SPI_PER_TRANS_POLLING_NO_DMA, "%d us", t_flight_sorted[(TEST_TIMES+1)/2]); +#endif //release the bus spi_device_release_bus(spi); From 2ad0565e3a5e1414b9fa2878d4a136bfba4bb9b3 Mon Sep 17 00:00:00 2001 From: Mahavir Jain Date: Mon, 3 Aug 2020 15:57:58 +0530 Subject: [PATCH 48/60] mbedtls: update to mbedtls release v2.16.7 For detailed release notes, please refer to: https://github.com/ARMmbed/mbedtls/releases/tag/mbedtls-2.16.7 --- components/mbedtls/mbedtls | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/mbedtls/mbedtls b/components/mbedtls/mbedtls index 9ef92c551..90f46c8b1 160000 --- a/components/mbedtls/mbedtls +++ b/components/mbedtls/mbedtls @@ -1 +1 @@ -Subproject commit 9ef92c551eb8d92677034c3ec8078a8076febf41 +Subproject commit 90f46c8b17bc1219a82d4ddf81520d40c5ac5ebf From 073542063caabfb35973a6da3360886474b54942 Mon Sep 17 00:00:00 2001 From: lly Date: Fri, 4 Sep 2020 11:44:59 +0800 Subject: [PATCH 49/60] ble_mesh: example: Fix sensor data wrong iteration --- .../ble_mesh_sensor_model/sensor_client/main/main.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/bluetooth/esp_ble_mesh/ble_mesh_sensor_model/sensor_client/main/main.c b/examples/bluetooth/esp_ble_mesh/ble_mesh_sensor_model/sensor_client/main/main.c index dbf1515f1..fe40bac9b 100644 --- a/examples/bluetooth/esp_ble_mesh/ble_mesh_sensor_model/sensor_client/main/main.c +++ b/examples/bluetooth/esp_ble_mesh/ble_mesh_sensor_model/sensor_client/main/main.c @@ -563,10 +563,11 @@ static void example_ble_mesh_sensor_client_cb(esp_ble_mesh_sensor_client_cb_even if (data_len != ESP_BLE_MESH_SENSOR_DATA_ZERO_LEN) { ESP_LOG_BUFFER_HEX("Sensor Data", data + mpid_len, data_len + 1); length += mpid_len + data_len + 1; + data += mpid_len + data_len + 1; } else { length += mpid_len; + data += mpid_len; } - data += length; } } break; From 93ad53c09d696e5edaff4d57229cfe542a4de5c9 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 29 May 2020 21:52:48 +0200 Subject: [PATCH 50/60] spi_flash: don't call vTaskDelay in non-os context Fixes regression in core dump, when a crash happens in interrupt context. --- components/spi_flash/flash_ops.c | 24 +++++++++++++++----- components/spi_flash/include/esp_spi_flash.h | 5 ++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/components/spi_flash/flash_ops.c b/components/spi_flash/flash_ops.c index b535e8008..420399269 100644 --- a/components/spi_flash/flash_ops.c +++ b/components/spi_flash/flash_ops.c @@ -71,6 +71,7 @@ static spi_flash_counters_t s_flash_stats; static esp_err_t spi_flash_translate_rc(esp_rom_spiflash_result_t rc); static bool is_safe_write_address(size_t addr, size_t size); +static void spi_flash_os_yield(void); const DRAM_ATTR spi_flash_guard_funcs_t g_flash_guard_default_ops = { .start = spi_flash_disable_interrupts_caches_and_other_cpu, @@ -78,18 +79,20 @@ const DRAM_ATTR spi_flash_guard_funcs_t g_flash_guard_default_ops = { .op_lock = spi_flash_op_lock, .op_unlock = spi_flash_op_unlock, #if !CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ALLOWED - .is_safe_write_address = is_safe_write_address + .is_safe_write_address = is_safe_write_address, #endif + .yield = spi_flash_os_yield, }; const DRAM_ATTR spi_flash_guard_funcs_t g_flash_guard_no_os_ops = { .start = spi_flash_disable_interrupts_caches_and_other_cpu_no_os, .end = spi_flash_enable_interrupts_caches_no_os, - .op_lock = 0, - .op_unlock = 0, + .op_lock = NULL, + .op_unlock = NULL, #if !CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ALLOWED - .is_safe_write_address = 0 + .is_safe_write_address = NULL, #endif + .yield = NULL, }; static const spi_flash_guard_funcs_t *s_flash_guard_ops; @@ -184,6 +187,13 @@ static inline void IRAM_ATTR spi_flash_guard_op_unlock() } } +static void IRAM_ATTR spi_flash_os_yield(void) +{ +#ifdef CONFIG_SPI_FLASH_YIELD_DURING_ERASE + vTaskDelay(CONFIG_SPI_FLASH_ERASE_YIELD_TICKS); +#endif +} + static esp_rom_spiflash_result_t IRAM_ATTR spi_flash_unlock() { static bool unlocked = false; @@ -246,8 +256,10 @@ esp_err_t IRAM_ATTR spi_flash_erase_range(uint32_t start_addr, uint32_t size) /* For example when dt_ms = 15 and CONFIG_SPI_FLASH_ERASE_YIELD_DURATION_MS = 20. * In this case we need to call vTaskDelay because * the duration of this command + the next command probably will exceed more than 20. - */ - vTaskDelay(CONFIG_SPI_FLASH_ERASE_YIELD_TICKS); + */ + if (s_flash_guard_ops && s_flash_guard_ops->yield) { + s_flash_guard_ops->yield(); + } } #endif } diff --git a/components/spi_flash/include/esp_spi_flash.h b/components/spi_flash/include/esp_spi_flash.h index 254e40895..ddcbbf620 100644 --- a/components/spi_flash/include/esp_spi_flash.h +++ b/components/spi_flash/include/esp_spi_flash.h @@ -317,6 +317,10 @@ typedef void (*spi_flash_op_unlock_func_t)(void); * @brief Function to protect SPI flash critical regions corruption. */ typedef bool (*spi_flash_is_safe_write_address_t)(size_t addr, size_t size); +/** + * @brief Function to yield to the OS during erase operation. + */ +typedef void (*spi_flash_os_yield_t)(void); /** * Structure holding SPI flash access critical sections management functions. @@ -357,6 +361,7 @@ typedef struct { #if !CONFIG_SPI_FLASH_WRITING_DANGEROUS_REGIONS_ALLOWED spi_flash_is_safe_write_address_t is_safe_write_address; /**< checks flash write addresses.*/ #endif + spi_flash_os_yield_t yield; /**< yield to the OS during flash erase */ } spi_flash_guard_funcs_t; /** From a571bc0d0a8b282221f89277dcdccbd1467c5e92 Mon Sep 17 00:00:00 2001 From: ronghulin Date: Mon, 7 Sep 2020 11:43:04 +0800 Subject: [PATCH 51/60] bugfix: fix some wifi bugs 1. add sta connect again ap sent disconnect event 2. add set/get inactive time api 3. fix connect hidden AP doesn't update information 4. add rf test long short support --- components/esp32/include/esp_wifi.h | 33 +++++++++++++++++++++++++++++ components/esp32/lib | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/components/esp32/include/esp_wifi.h b/components/esp32/include/esp_wifi.h index e82c05911..f920c57bc 100644 --- a/components/esp32/include/esp_wifi.h +++ b/components/esp32/include/esp_wifi.h @@ -1111,6 +1111,39 @@ esp_err_t esp_wifi_set_ant(const wifi_ant_config_t *config); */ esp_err_t esp_wifi_get_ant(wifi_ant_config_t *config); +/** + * @brief Set the inactive time of the ESP32 STA or AP + * + * @attention 1. For Station, If the station does not receive a beacon frame from the connected SoftAP during the inactive time, + * disconnect from SoftAP. Default 6s. + * @attention 2. For SoftAP, If the softAP doesn't receive any data from the connected STA during inactive time, + * the softAP will force deauth the STA. Default is 300s. + * @attention 3. The inactive time configuration is not stored into flash + * + * @param ifx interface to be configured. + * @param sec Inactive time. Unit seconds. + * + * @return + * - ESP_OK: succeed + * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init + * - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start + * - ESP_ERR_WIFI_ARG: invalid argument, For Station, if sec is less than 3. For SoftAP, if sec is less than 10. + */ +esp_err_t esp_wifi_set_inactive_time(wifi_interface_t ifx, uint16_t sec); + +/** + * @brief Get inactive time of specified interface + * + * @param ifx Interface to be configured. + * @param sec Inactive time. Unit seconds. + * + * @return + * - ESP_OK: succeed + * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init + * - ESP_ERR_WIFI_ARG: invalid argument + */ +esp_err_t esp_wifi_get_inactive_time(wifi_interface_t ifx, uint16_t *sec); + #ifdef __cplusplus } #endif diff --git a/components/esp32/lib b/components/esp32/lib index d376d65d8..aa15b130d 160000 --- a/components/esp32/lib +++ b/components/esp32/lib @@ -1 +1 @@ -Subproject commit d376d65d84f363418db58d8a78545b73ffb91de7 +Subproject commit aa15b130d5162c16a76f3a23dc6d985bd1447e8d From d79e95e6e038fca23dabde1ae6001414983dc0e8 Mon Sep 17 00:00:00 2001 From: lly Date: Wed, 19 Aug 2020 17:56:13 +0800 Subject: [PATCH 52/60] ble_mesh: nimble: Fix updating ccc handle with wrong value --- .../mesh_core/nimble_host/mesh_bearer_adapt.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c b/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c index 2cdb0a6d1..6d1e06c6a 100644 --- a/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c +++ b/components/bt/esp_ble_mesh/mesh_core/nimble_host/mesh_bearer_adapt.c @@ -207,7 +207,10 @@ static int dsc_disced(uint16_t conn_handle, const struct ble_gatt_error *error, switch (error->status) { case 0: - bt_mesh_gattc_info[i].ccc_handle = dsc->handle; + if (bt_mesh_gattc_info[i].ccc_handle == 0 && dsc && + BLE_UUID16(&dsc->uuid)->value == BLE_MESH_UUID_GATT_CCC_VAL) { + bt_mesh_gattc_info[i].ccc_handle = dsc->handle; + } break; case BLE_HS_EDONE: @@ -291,7 +294,8 @@ static int chr_disced(uint16_t conn_handle, const struct ble_gatt_error *error, break; } } - ble_gattc_disc_all_dscs(conn_handle, bt_mesh_gattc_info[j].data_out_handle, 0xffff, dsc_disced, (void *)j); + ble_gattc_disc_all_dscs(conn_handle, bt_mesh_gattc_info[j].data_out_handle, bt_mesh_gattc_info[j].end_handle, + dsc_disced, (void *)j); } else { ble_gattc_disc_all_chrs(conn_handle, bt_mesh_gattc_info[j].start_handle, bt_mesh_gattc_info[j].end_handle, chr_disced, (void *)j); From 1090c12acdb29c74074fbb72c10263420fb924ab Mon Sep 17 00:00:00 2001 From: lly Date: Fri, 21 Aug 2020 15:15:06 +0800 Subject: [PATCH 53/60] ble_mesh: stack: Avoid using assert in mesh stack --- components/bt/esp_ble_mesh/mesh_core/access.c | 7 ++----- components/bt/esp_ble_mesh/mesh_core/friend.c | 10 ++++++++-- components/bt/esp_ble_mesh/mesh_core/lpn.c | 2 +- components/bt/esp_ble_mesh/mesh_core/proxy_server.c | 10 ++++++++-- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/access.c b/components/bt/esp_ble_mesh/mesh_core/access.c index 07019c598..3b30bcaa5 100644 --- a/components/bt/esp_ble_mesh/mesh_core/access.c +++ b/components/bt/esp_ble_mesh/mesh_core/access.c @@ -447,7 +447,7 @@ static void mod_publish(struct k_work *work) BT_DBG("%s", __func__); period_ms = bt_mesh_model_pub_period_get(pub->mod); - BT_INFO("period %u ms", period_ms); + BT_INFO("Publish period %u ms", period_ms); if (pub->count) { err = publish_retransmit(pub->mod); @@ -469,14 +469,11 @@ static void mod_publish(struct k_work *work) return; } - __ASSERT_NO_MSG(pub->update != NULL); - /* 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. */ - err = pub->update(pub->mod); - if (err) { + if (pub->update && pub->update(pub->mod)) { /* Cancel this publish attempt. */ BT_ERR("Update failed, skipping publish (err %d)", err); pub->period_start = k_uptime_get_32(); diff --git a/components/bt/esp_ble_mesh/mesh_core/friend.c b/components/bt/esp_ble_mesh/mesh_core/friend.c index 0874142f3..b9955709a 100644 --- a/components/bt/esp_ble_mesh/mesh_core/friend.c +++ b/components/bt/esp_ble_mesh/mesh_core/friend.c @@ -559,7 +559,10 @@ static struct net_buf *encode_update(struct bt_mesh_friend *frnd, u8_t md) NET_BUF_SIMPLE_DEFINE(sdu, 1 + sizeof(*upd)); struct bt_mesh_subnet *sub = friend_subnet_get(frnd->net_idx); - __ASSERT_NO_MSG(sub != NULL); + if (!sub) { + BT_ERR("Friend subnet 0x%04x not found", frnd->net_idx); + return NULL; + } BT_DBG("lpn 0x%04x md 0x%02x", frnd->lpn, md); @@ -1194,7 +1197,10 @@ static void friend_timeout(struct k_work *work) .end = buf_send_end, }; - __ASSERT_NO_MSG(frnd->pending_buf == 0U); + if (frnd->pending_buf != 0U) { + BT_ERR("Previous buffer not yet sent!"); + return; + } BT_DBG("lpn 0x%04x send_last %u last %p", frnd->lpn, frnd->send_last, frnd->last); diff --git a/components/bt/esp_ble_mesh/mesh_core/lpn.c b/components/bt/esp_ble_mesh/mesh_core/lpn.c index f398e7f7a..5ee570046 100644 --- a/components/bt/esp_ble_mesh/mesh_core/lpn.c +++ b/components/bt/esp_ble_mesh/mesh_core/lpn.c @@ -834,7 +834,7 @@ static void lpn_timeout(struct k_work *work) update_timeout(lpn); break; default: - __ASSERT(0, "Unhandled LPN state"); + BT_ERR("Unhandled LPN state"); break; } } diff --git a/components/bt/esp_ble_mesh/mesh_core/proxy_server.c b/components/bt/esp_ble_mesh/mesh_core/proxy_server.c index 1527e0de4..a47710205 100644 --- a/components/bt/esp_ble_mesh/mesh_core/proxy_server.c +++ b/components/bt/esp_ble_mesh/mesh_core/proxy_server.c @@ -660,7 +660,10 @@ static ssize_t prov_ccc_write(struct bt_mesh_conn *conn, /* If a connection exists there must be a client */ client = find_client(conn); - __ASSERT(client, "No client for connection"); + if (!client) { + BT_ERR("No client for connection %p", conn); + return 0; + } if (client->filter_type == NONE) { client->filter_type = PROV; @@ -795,7 +798,10 @@ static ssize_t proxy_ccc_write(struct bt_mesh_conn *conn, /* If a connection exists there must be a client */ client = find_client(conn); - __ASSERT(client, "No client for connection"); + if (!client) { + BT_ERR("No client for connection %p", conn); + return 0; + } if (client->filter_type == NONE) { client->filter_type = WHITELIST; From 9b70ddbb7762c6868f82410a46f66900815ff694 Mon Sep 17 00:00:00 2001 From: lly Date: Tue, 7 Jul 2020 18:25:29 +0800 Subject: [PATCH 54/60] ble_mesh: stack: Use model callback for operations [Zephyr] - Previously when a model is initialized or deinitialized, in the access layer, we need to check the model id with the ids in the table in order to find the proper model operation function. - Currently all the operation functions of each model will be set during the mesh initialization. When the model is found, we can directly use the corresponding callback for different operations. - Currently only init/deinit operations are registered, later we will add more operations. --- .../bt/esp_ble_mesh/api/esp_ble_mesh_defs.h | 18 +- .../bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c | 348 +++++++++++------- components/bt/esp_ble_mesh/mesh_core/access.c | 261 ++----------- components/bt/esp_ble_mesh/mesh_core/access.h | 4 - .../bt/esp_ble_mesh/mesh_core/cfg_cli.c | 27 +- .../bt/esp_ble_mesh/mesh_core/cfg_srv.c | 19 +- .../bt/esp_ble_mesh/mesh_core/foundation.h | 12 - .../bt/esp_ble_mesh/mesh_core/health_cli.c | 19 +- .../bt/esp_ble_mesh/mesh_core/health_srv.c | 23 +- .../esp_ble_mesh/mesh_core/include/cfg_cli.h | 5 +- .../esp_ble_mesh/mesh_core/include/cfg_srv.h | 5 +- .../mesh_core/include/health_cli.h | 5 +- .../mesh_core/include/health_srv.h | 5 +- .../mesh_core/include/mesh_access.h | 118 +++++- components/bt/esp_ble_mesh/mesh_core/main.c | 2 + .../mesh_models/client/client_common.c | 31 +- .../mesh_models/client/generic_client.c | 113 +----- .../client/include/generic_client.h | 213 ++--------- .../client/include/lighting_client.h | 133 +------ .../client/include/sensor_client.h | 29 +- .../client/include/time_scene_client.h | 81 +--- .../mesh_models/client/lighting_client.c | 77 +--- .../mesh_models/client/sensor_client.c | 23 +- .../mesh_models/client/time_scene_client.c | 53 +-- .../mesh_models/server/generic_server.c | 156 +++++--- .../server/include/generic_server.h | 30 -- .../server/include/lighting_server.h | 28 -- .../server/include/sensor_server.h | 6 - .../server/include/time_scene_server.h | 14 - .../mesh_models/server/lighting_server.c | 143 +++++-- .../mesh_models/server/sensor_server.c | 22 +- .../mesh_models/server/time_scene_server.c | 74 ++-- 32 files changed, 864 insertions(+), 1233 deletions(-) diff --git a/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h b/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h index c9cc95432..5e5b9d4e1 100644 --- a/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h +++ b/components/bt/esp_ble_mesh/api/esp_ble_mesh_defs.h @@ -271,7 +271,7 @@ typedef enum { #define ESP_BLE_MESH_MODEL_OP_2(b0, b1) (((b0) << 8) | (b1)) #define ESP_BLE_MESH_MODEL_OP_3(b0, cid) ((((b0) << 16) | 0xC00000) | (cid)) -/*!< This macro is associated with BLE_MESH_MODEL in mesh_access.h */ +/*!< This macro is associated with BLE_MESH_MODEL_CB in mesh_access.h */ #define ESP_BLE_MESH_SIG_MODEL(_id, _op, _pub, _user_data) \ { \ .model_id = (_id), \ @@ -284,7 +284,7 @@ typedef enum { .user_data = _user_data, \ } -/*!< This macro is associated with BLE_MESH_MODEL_VND in mesh_access.h */ +/*!< This macro is associated with BLE_MESH_MODEL_VND_CB in mesh_access.h */ #define ESP_BLE_MESH_VENDOR_MODEL(_company, _id, _op, _pub, _user_data) \ { \ .vnd.company_id = (_company), \ @@ -461,6 +461,17 @@ typedef struct { */ #define ESP_BLE_MESH_MODEL_OP_END {0, 0, 0} +/** Abstraction that describes a model callback structure. + * This structure is associated with struct bt_mesh_model_cb in mesh_access.h. + */ +typedef struct { + /** Callback used during model initialization. Initialized by the stack. */ + esp_ble_mesh_cb_t init_cb; + + /** Callback used during model deinitialization. Initialized by the stack. */ + esp_ble_mesh_cb_t deinit_cb; +} esp_ble_mesh_model_cbs_t; + /** Abstraction that describes a Mesh Model instance. * This structure is associated with struct bt_mesh_model in mesh_access.h */ @@ -494,6 +505,9 @@ struct esp_ble_mesh_model { /** Model operation context */ esp_ble_mesh_model_op_t *op; + /** Model callback structure */ + esp_ble_mesh_model_cbs_t *cb; + /** Model-specific user data */ void *user_data; }; diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c index f2bf7f780..e61118c6b 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c @@ -1006,74 +1006,115 @@ const esp_ble_mesh_comp_t *btc_ble_mesh_comp_get(void) /* Configuration Models */ extern const struct bt_mesh_model_op bt_mesh_cfg_srv_op[]; extern const struct bt_mesh_model_op bt_mesh_cfg_cli_op[]; +extern const struct bt_mesh_model_cb bt_mesh_cfg_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_cfg_cli_cb; /* Health Models */ extern const struct bt_mesh_model_op bt_mesh_health_srv_op[]; extern const struct bt_mesh_model_op bt_mesh_health_cli_op[]; +extern const struct bt_mesh_model_cb bt_mesh_health_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_health_cli_cb; /* Generic Client Models */ -extern const struct bt_mesh_model_op gen_onoff_cli_op[]; -extern const struct bt_mesh_model_op gen_level_cli_op[]; -extern const struct bt_mesh_model_op gen_def_trans_time_cli_op[]; -extern const struct bt_mesh_model_op gen_power_onoff_cli_op[]; -extern const struct bt_mesh_model_op gen_power_level_cli_op[]; -extern const struct bt_mesh_model_op gen_battery_cli_op[]; -extern const struct bt_mesh_model_op gen_location_cli_op[]; -extern const struct bt_mesh_model_op gen_property_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_onoff_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_level_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_def_trans_time_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_power_onoff_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_power_level_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_battery_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_location_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_property_cli_op[]; +extern const struct bt_mesh_model_cb bt_mesh_generic_client_cb; /* Lighting Client Models */ -extern const struct bt_mesh_model_op light_lightness_cli_op[]; -extern const struct bt_mesh_model_op light_ctl_cli_op[]; -extern const struct bt_mesh_model_op light_hsl_cli_op[]; -extern const struct bt_mesh_model_op light_xyl_cli_op[]; -extern const struct bt_mesh_model_op light_lc_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_lightness_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_ctl_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_hsl_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_xyl_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_lc_cli_op[]; +extern const struct bt_mesh_model_cb bt_mesh_lighting_client_cb; /* Sensor Client Models */ -extern const struct bt_mesh_model_op sensor_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_sensor_cli_op[]; +extern const struct bt_mesh_model_cb bt_mesh_sensor_client_cb; /* Time and Scenes Client Models */ -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[]; +extern const struct bt_mesh_model_op bt_mesh_time_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_scene_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_scheduler_cli_op[]; +extern const struct bt_mesh_model_cb bt_mesh_time_scene_client_cb; /* Generic Server Models */ -extern const struct bt_mesh_model_op gen_onoff_srv_op[]; -extern const struct bt_mesh_model_op gen_level_srv_op[]; -extern const struct bt_mesh_model_op gen_def_trans_time_srv_op[]; -extern const struct bt_mesh_model_op gen_power_onoff_srv_op[]; -extern const struct bt_mesh_model_op gen_power_onoff_setup_srv_op[]; -extern const struct bt_mesh_model_op gen_power_level_srv_op[]; -extern const struct bt_mesh_model_op gen_power_level_setup_srv_op[]; -extern const struct bt_mesh_model_op gen_battery_srv_op[]; -extern const struct bt_mesh_model_op gen_location_srv_op[]; -extern const struct bt_mesh_model_op gen_location_setup_srv_op[]; -extern const struct bt_mesh_model_op gen_user_prop_srv_op[]; -extern const struct bt_mesh_model_op gen_admin_prop_srv_op[]; -extern const struct bt_mesh_model_op gen_manu_prop_srv_op[]; -extern const struct bt_mesh_model_op gen_client_prop_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_onoff_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_level_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_def_trans_time_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_power_onoff_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_power_onoff_setup_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_power_level_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_power_level_setup_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_battery_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_location_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_location_setup_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_user_prop_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_admin_prop_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_manu_prop_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_client_prop_srv_op[]; +extern const struct bt_mesh_model_cb bt_mesh_gen_onoff_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_gen_level_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_gen_def_trans_time_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_gen_power_onoff_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_gen_power_onoff_setup_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_gen_power_level_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_gen_power_level_setup_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_gen_battery_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_gen_location_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_gen_location_setup_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_gen_user_prop_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_gen_admin_prop_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_gen_manu_prop_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_gen_client_prop_srv_cb; /* Lighting Server Models */ -extern const struct bt_mesh_model_op light_lightness_srv_op[]; -extern const struct bt_mesh_model_op light_lightness_setup_srv_op[]; -extern const struct bt_mesh_model_op light_ctl_srv_op[]; -extern const struct bt_mesh_model_op light_ctl_setup_srv_op[]; -extern const struct bt_mesh_model_op light_ctl_temp_srv_op[]; -extern const struct bt_mesh_model_op light_hsl_srv_op[]; -extern const struct bt_mesh_model_op light_hsl_hue_srv_op[]; -extern const struct bt_mesh_model_op light_hsl_sat_srv_op[]; -extern const struct bt_mesh_model_op light_hsl_setup_srv_op[]; -extern const struct bt_mesh_model_op light_xyl_srv_op[]; -extern const struct bt_mesh_model_op light_xyl_setup_srv_op[]; -extern const struct bt_mesh_model_op light_lc_srv_op[]; -extern const struct bt_mesh_model_op light_lc_setup_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_lightness_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_lightness_setup_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_ctl_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_ctl_setup_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_ctl_temp_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_hsl_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_hsl_hue_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_hsl_sat_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_hsl_setup_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_xyl_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_xyl_setup_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_lc_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_lc_setup_srv_op[]; +extern const struct bt_mesh_model_cb bt_mesh_light_lightness_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_light_lightness_setup_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_light_ctl_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_light_ctl_setup_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_light_ctl_temp_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_light_hsl_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_light_hsl_hue_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_light_hsl_sat_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_light_hsl_setup_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_light_xyl_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_light_xyl_setup_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_light_lc_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_light_lc_setup_srv_cb; /* Time and Scenes Server Models */ -extern const struct bt_mesh_model_op time_srv_op[]; -extern const struct bt_mesh_model_op time_setup_srv_op[]; -extern const struct bt_mesh_model_op scene_srv_op[]; -extern const struct bt_mesh_model_op scene_setup_srv_op[]; -extern const struct bt_mesh_model_op scheduler_srv_op[]; -extern const struct bt_mesh_model_op scheduler_setup_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_time_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_time_setup_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_scene_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_scene_setup_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_scheduler_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_scheduler_setup_srv_op[]; +extern const struct bt_mesh_model_cb bt_mesh_time_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_time_setup_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_scene_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_scene_setup_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_scheduler_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_scheduler_setup_srv_cb; /* Sensor Server Models */ -extern const struct bt_mesh_model_op sensor_srv_op[]; -extern const struct bt_mesh_model_op sensor_setup_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_sensor_srv_op[]; +extern const struct bt_mesh_model_op bt_mesh_sensor_setup_srv_op[]; +extern const struct bt_mesh_model_cb bt_mesh_sensor_srv_cb; +extern const struct bt_mesh_model_cb bt_mesh_sensor_setup_srv_cb; -static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) +static void btc_ble_mesh_model_op_set(esp_ble_mesh_model_t *model) { - esp_ble_mesh_model_op_t *op = NULL; - if (!model) { BT_ERR("%s, Invalid parameter", __func__); return; @@ -1082,13 +1123,14 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) /* For SIG client and server models, model->op will be NULL and initialized here. * For vendor models whose opcode is 3 bytes, model->op will be initialized here. */ - if ((model->op != NULL) && (model->op->opcode >= 0x10000)) { - goto add_model_op; + if (model->op && BLE_MESH_MODEL_OP_LEN(model->op->opcode) == 3) { + goto set_vnd_op; } switch (model->model_id) { case BLE_MESH_MODEL_ID_CFG_SRV: { model->op = (esp_ble_mesh_model_op_t *)bt_mesh_cfg_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_cfg_srv_cb; struct bt_mesh_cfg_srv *srv = (struct bt_mesh_cfg_srv *)model->user_data; if (srv) { srv->hb_sub.func = btc_ble_mesh_heartbeat_msg_recv_cb; @@ -1097,6 +1139,7 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) } case BLE_MESH_MODEL_ID_CFG_CLI: { model->op = (esp_ble_mesh_model_op_t *)bt_mesh_cfg_cli_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_cfg_cli_cb; bt_mesh_config_client_t *cli = (bt_mesh_config_client_t *)model->user_data; if (cli != NULL) { cli->publish_status = btc_ble_mesh_config_client_publish_callback; @@ -1105,6 +1148,7 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) } case BLE_MESH_MODEL_ID_HEALTH_SRV: { model->op = (esp_ble_mesh_model_op_t *)bt_mesh_health_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_health_srv_cb; struct bt_mesh_health_srv *srv = (struct bt_mesh_health_srv *)model->user_data; if (srv) { srv->cb.fault_clear = btc_ble_mesh_health_server_fault_clear; @@ -1116,6 +1160,7 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) } case BLE_MESH_MODEL_ID_HEALTH_CLI: { model->op = (esp_ble_mesh_model_op_t *)bt_mesh_health_cli_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_health_cli_cb; bt_mesh_health_client_t *cli = (bt_mesh_health_client_t *)model->user_data; if (cli != NULL) { cli->publish_status = btc_ble_mesh_health_publish_callback; @@ -1123,7 +1168,8 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) break; } case BLE_MESH_MODEL_ID_GEN_ONOFF_CLI: { - model->op = ((esp_ble_mesh_model_op_t *)gen_onoff_cli_op); + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_onoff_cli_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_generic_client_cb; bt_mesh_gen_onoff_client_t *cli = (bt_mesh_gen_onoff_client_t *)model->user_data; if (cli != NULL) { cli->publish_status = btc_ble_mesh_generic_client_publish_callback; @@ -1131,7 +1177,8 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) break; } case BLE_MESH_MODEL_ID_GEN_LEVEL_CLI: { - model->op = ((esp_ble_mesh_model_op_t *)gen_level_cli_op); + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_level_cli_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_generic_client_cb; bt_mesh_gen_level_client_t *cli = (bt_mesh_gen_level_client_t *)model->user_data; if (cli != NULL) { cli->publish_status = btc_ble_mesh_generic_client_publish_callback; @@ -1139,7 +1186,8 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) 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); + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_def_trans_time_cli_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_generic_client_cb; 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_ble_mesh_generic_client_publish_callback; @@ -1147,7 +1195,8 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) break; } case BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI: { - model->op = ((esp_ble_mesh_model_op_t *)gen_power_onoff_cli_op); + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_power_onoff_cli_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_generic_client_cb; 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_ble_mesh_generic_client_publish_callback; @@ -1155,7 +1204,8 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) break; } case BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI: { - model->op = ((esp_ble_mesh_model_op_t *)gen_power_level_cli_op); + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_power_level_cli_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_generic_client_cb; 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_ble_mesh_generic_client_publish_callback; @@ -1163,7 +1213,8 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) break; } case BLE_MESH_MODEL_ID_GEN_BATTERY_CLI: { - model->op = ((esp_ble_mesh_model_op_t *)gen_battery_cli_op); + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_battery_cli_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_generic_client_cb; bt_mesh_gen_battery_client_t *cli = (bt_mesh_gen_battery_client_t *)model->user_data; if (cli != NULL) { cli->publish_status = btc_ble_mesh_generic_client_publish_callback; @@ -1171,7 +1222,8 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) break; } case BLE_MESH_MODEL_ID_GEN_LOCATION_CLI: { - model->op = ((esp_ble_mesh_model_op_t *)gen_location_cli_op); + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_location_cli_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_generic_client_cb; bt_mesh_gen_location_client_t *cli = (bt_mesh_gen_location_client_t *)model->user_data; if (cli != NULL) { cli->publish_status = btc_ble_mesh_generic_client_publish_callback; @@ -1179,7 +1231,8 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) break; } case BLE_MESH_MODEL_ID_GEN_PROP_CLI: { - model->op = ((esp_ble_mesh_model_op_t *)gen_property_cli_op); + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_property_cli_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_generic_client_cb; bt_mesh_gen_property_client_t *cli = (bt_mesh_gen_property_client_t *)model->user_data; if (cli != NULL) { cli->publish_status = btc_ble_mesh_generic_client_publish_callback; @@ -1187,7 +1240,8 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) break; } case BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI: { - model->op = ((esp_ble_mesh_model_op_t *)light_lightness_cli_op); + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_lightness_cli_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_lighting_client_cb; bt_mesh_light_lightness_client_t *cli = (bt_mesh_light_lightness_client_t *)model->user_data; if (cli != NULL) { cli->publish_status = btc_ble_mesh_lighting_client_publish_callback; @@ -1195,7 +1249,8 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) break; } case BLE_MESH_MODEL_ID_LIGHT_CTL_CLI: { - model->op = ((esp_ble_mesh_model_op_t *)light_ctl_cli_op); + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_ctl_cli_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_lighting_client_cb; bt_mesh_light_ctl_client_t *cli = (bt_mesh_light_ctl_client_t *)model->user_data; if (cli != NULL) { cli->publish_status = btc_ble_mesh_lighting_client_publish_callback; @@ -1203,7 +1258,8 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) break; } case BLE_MESH_MODEL_ID_LIGHT_HSL_CLI: { - model->op = ((esp_ble_mesh_model_op_t *)light_hsl_cli_op); + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_hsl_cli_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_lighting_client_cb; bt_mesh_light_hsl_client_t *cli = (bt_mesh_light_hsl_client_t *)model->user_data; if (cli != NULL) { cli->publish_status = btc_ble_mesh_lighting_client_publish_callback; @@ -1211,7 +1267,8 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) break; } case BLE_MESH_MODEL_ID_LIGHT_XYL_CLI: { - model->op = ((esp_ble_mesh_model_op_t *)light_xyl_cli_op); + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_xyl_cli_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_lighting_client_cb; bt_mesh_light_xyl_client_t *cli = (bt_mesh_light_xyl_client_t *)model->user_data; if (cli != NULL) { cli->publish_status = btc_ble_mesh_lighting_client_publish_callback; @@ -1219,7 +1276,8 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) break; } case BLE_MESH_MODEL_ID_LIGHT_LC_CLI: { - model->op = ((esp_ble_mesh_model_op_t *)light_lc_cli_op); + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_lc_cli_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_lighting_client_cb; bt_mesh_light_lc_client_t *cli = (bt_mesh_light_lc_client_t *)model->user_data; if (cli != NULL) { cli->publish_status = btc_ble_mesh_lighting_client_publish_callback; @@ -1227,7 +1285,8 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) break; } case BLE_MESH_MODEL_ID_SENSOR_CLI: { - model->op = ((esp_ble_mesh_model_op_t *)sensor_cli_op); + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_sensor_cli_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_sensor_client_cb; bt_mesh_sensor_client_t *cli = (bt_mesh_sensor_client_t *)model->user_data; if (cli != NULL) { cli->publish_status = btc_ble_mesh_sensor_client_publish_callback; @@ -1235,7 +1294,8 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) break; } case BLE_MESH_MODEL_ID_TIME_CLI: { - model->op = ((esp_ble_mesh_model_op_t *)time_cli_op); + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_time_cli_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_time_scene_client_cb; bt_mesh_time_client_t *cli = (bt_mesh_time_client_t *)model->user_data; if (cli != NULL) { cli->publish_status = btc_ble_mesh_time_scene_client_publish_callback; @@ -1243,7 +1303,8 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) break; } case BLE_MESH_MODEL_ID_SCENE_CLI: { - model->op = ((esp_ble_mesh_model_op_t *)scene_cli_op); + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_scene_cli_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_time_scene_client_cb; bt_mesh_scene_client_t *cli = (bt_mesh_scene_client_t *)model->user_data; if (cli != NULL) { cli->publish_status = btc_ble_mesh_time_scene_client_publish_callback; @@ -1251,7 +1312,8 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) break; } case BLE_MESH_MODEL_ID_SCHEDULER_CLI: { - model->op = ((esp_ble_mesh_model_op_t *)scheduler_cli_op); + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_scheduler_cli_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_time_scene_client_cb; bt_mesh_scheduler_client_t *cli = (bt_mesh_scheduler_client_t *)model->user_data; if (cli != NULL) { cli->publish_status = btc_ble_mesh_time_scene_client_publish_callback; @@ -1259,175 +1321,204 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) break; } case BLE_MESH_MODEL_ID_GEN_ONOFF_SRV: - model->op = (esp_ble_mesh_model_op_t *)gen_onoff_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_onoff_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_onoff_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_GEN_LEVEL_SRV: - model->op = (esp_ble_mesh_model_op_t *)gen_level_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_level_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_level_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV: - model->op = (esp_ble_mesh_model_op_t *)gen_def_trans_time_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_def_trans_time_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_def_trans_time_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV: - model->op = (esp_ble_mesh_model_op_t *)gen_power_onoff_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_power_onoff_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_power_onoff_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV: - model->op = (esp_ble_mesh_model_op_t *)gen_power_onoff_setup_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_power_onoff_setup_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_power_onoff_setup_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV: - model->op = (esp_ble_mesh_model_op_t *)gen_power_level_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_power_level_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_power_level_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV: - model->op = (esp_ble_mesh_model_op_t *)gen_power_level_setup_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_power_level_setup_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_power_level_setup_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_GEN_BATTERY_SRV: - model->op = (esp_ble_mesh_model_op_t *)gen_battery_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_battery_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_battery_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_GEN_LOCATION_SRV: - model->op = (esp_ble_mesh_model_op_t *)gen_location_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_location_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_location_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_GEN_USER_PROP_SRV: - model->op = (esp_ble_mesh_model_op_t *)gen_user_prop_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_user_prop_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_user_prop_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV: - model->op = (esp_ble_mesh_model_op_t *)gen_admin_prop_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_admin_prop_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_admin_prop_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV: - model->op = (esp_ble_mesh_model_op_t *)gen_manu_prop_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_manu_prop_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_manu_prop_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV: - model->op = (esp_ble_mesh_model_op_t *)gen_client_prop_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_client_prop_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_client_prop_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_GEN_LOCATION_SETUP_SRV: - model->op = (esp_ble_mesh_model_op_t *)gen_location_setup_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_gen_location_setup_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_gen_location_setup_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV: - model->op = (esp_ble_mesh_model_op_t *)light_lightness_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_lightness_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_lightness_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV: - model->op = (esp_ble_mesh_model_op_t *)light_lightness_setup_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_lightness_setup_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_lightness_setup_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_LIGHT_CTL_SRV: - model->op = (esp_ble_mesh_model_op_t *)light_ctl_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_ctl_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_ctl_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV: - model->op = (esp_ble_mesh_model_op_t *)light_ctl_setup_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_ctl_setup_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_ctl_setup_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV: - model->op = (esp_ble_mesh_model_op_t *)light_ctl_temp_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_ctl_temp_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_ctl_temp_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_LIGHT_HSL_SRV: - model->op = (esp_ble_mesh_model_op_t *)light_hsl_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_hsl_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_hsl_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV: - model->op = (esp_ble_mesh_model_op_t *)light_hsl_hue_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_hsl_hue_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_hsl_hue_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV: - model->op = (esp_ble_mesh_model_op_t *)light_hsl_sat_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_hsl_sat_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_hsl_sat_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV: - model->op = (esp_ble_mesh_model_op_t *)light_hsl_setup_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_hsl_setup_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_hsl_setup_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_LIGHT_XYL_SRV: - model->op = (esp_ble_mesh_model_op_t *)light_xyl_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_xyl_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_xyl_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV: - model->op = (esp_ble_mesh_model_op_t *)light_xyl_setup_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_xyl_setup_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_xyl_setup_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_LIGHT_LC_SRV: - model->op = (esp_ble_mesh_model_op_t *)light_lc_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_lc_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_lc_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV: - model->op = (esp_ble_mesh_model_op_t *)light_lc_setup_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_light_lc_setup_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_light_lc_setup_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_TIME_SRV: - model->op = (esp_ble_mesh_model_op_t *)time_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_time_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_time_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_TIME_SETUP_SRV: - model->op = (esp_ble_mesh_model_op_t *)time_setup_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_time_setup_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_time_setup_srv_cb; if (model->pub) { /* Time Setup Server model does not support subscribing nor publishing. */ BT_ERR("Time Setup Server shall not support publication"); @@ -1435,51 +1526,57 @@ static void btc_ble_mesh_model_op_add(esp_ble_mesh_model_t *model) } break; case BLE_MESH_MODEL_ID_SCENE_SRV: - model->op = (esp_ble_mesh_model_op_t *)scene_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_scene_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_scene_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_SCENE_SETUP_SRV: - model->op = (esp_ble_mesh_model_op_t *)scene_setup_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_scene_setup_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_scene_setup_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_SCHEDULER_SRV: - model->op = (esp_ble_mesh_model_op_t *)scheduler_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_scheduler_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_scheduler_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_SCHEDULER_SETUP_SRV: - model->op = (esp_ble_mesh_model_op_t *)scheduler_setup_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_scheduler_setup_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_scheduler_setup_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_SENSOR_SRV: - model->op = (esp_ble_mesh_model_op_t *)sensor_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_sensor_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_sensor_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; case BLE_MESH_MODEL_ID_SENSOR_SETUP_SRV: - model->op = (esp_ble_mesh_model_op_t *)sensor_setup_srv_op; + model->op = (esp_ble_mesh_model_op_t *)bt_mesh_sensor_setup_srv_op; + model->cb = (esp_ble_mesh_model_cbs_t *)&bt_mesh_sensor_setup_srv_cb; if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } break; default: - goto add_model_op; + goto set_vnd_op; } return; -add_model_op: +set_vnd_op: if (model->pub) { model->pub->update = (esp_ble_mesh_cb_t)btc_ble_mesh_model_publish_update; } - op = model->op; + esp_ble_mesh_model_op_t *op = model->op; while (op != NULL && op->opcode != 0) { op->param_cb = (esp_ble_mesh_cb_t)btc_ble_mesh_server_model_op_cb; op++; @@ -1502,30 +1599,27 @@ void btc_ble_mesh_prov_call_handler(btc_msg_t *msg) switch (msg->act) { case BTC_BLE_MESH_ACT_MESH_INIT: { - int err_code = 0; for (int i = 0; i < arg->mesh_init.comp->element_count; i++) { esp_ble_mesh_elem_t *elem = &arg->mesh_init.comp->elements[i]; - /* For SIG models */ + for (int j = 0; j < elem->sig_model_count; j++) { esp_ble_mesh_model_t *sig_model = &elem->sig_models[j]; - /* 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_ble_mesh_prov_register_complete_cb(err_code); + if (sig_model->op && BLE_MESH_MODEL_OP_LEN(sig_model->op->opcode) == 3) { + /* Opcode of SIG model must be 1 or 2 bytes. */ + btc_ble_mesh_prov_register_complete_cb(-EINVAL); return; } - btc_ble_mesh_model_op_add(sig_model); + btc_ble_mesh_model_op_set(sig_model); } - /* For vendor models */ + for (int k = 0; k < elem->vnd_model_count; k++) { esp_ble_mesh_model_t *vnd_model = &elem->vnd_models[k]; - /* The opcode of vendor model should be 3 bytes. */ - if (vnd_model && vnd_model->op && vnd_model->op->opcode < 0x10000) { - err_code = -EINVAL; - btc_ble_mesh_prov_register_complete_cb(err_code); + if (vnd_model->op && BLE_MESH_MODEL_OP_LEN(vnd_model->op->opcode) < 3) { + /* Opcode of vendor model must be 3 bytes. */ + btc_ble_mesh_prov_register_complete_cb(-EINVAL); return; } - btc_ble_mesh_model_op_add(vnd_model); + btc_ble_mesh_model_op_set(vnd_model); } } #if CONFIG_BLE_MESH_NODE @@ -1559,8 +1653,8 @@ void btc_ble_mesh_prov_call_handler(btc_msg_t *msg) bt_mesh_proxy_client_set_disconn_cb(btc_ble_mesh_proxy_client_disconnect_cb); bt_mesh_proxy_client_set_filter_status_cb(btc_ble_mesh_proxy_client_filter_status_recv_cb); #endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */ - err_code = bt_mesh_init((struct bt_mesh_prov *)arg->mesh_init.prov, - (struct bt_mesh_comp *)arg->mesh_init.comp); + int 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_ble_mesh_prov_register_complete_cb(err_code); diff --git a/components/bt/esp_ble_mesh/mesh_core/access.c b/components/bt/esp_ble_mesh/mesh_core/access.c index 07019c598..6303d1e26 100644 --- a/components/bt/esp_ble_mesh/mesh_core/access.c +++ b/components/bt/esp_ble_mesh/mesh_core/access.c @@ -22,221 +22,11 @@ #include "fast_prov.h" #include "provisioner_main.h" -#include "generic_client.h" -#include "sensor_client.h" -#include "time_scene_client.h" -#include "lighting_client.h" - -#include "generic_server.h" -#include "sensor_server.h" -#include "time_scene_server.h" -#include "lighting_server.h" - #define BLE_MESH_SDU_MAX_LEN 384 static const struct bt_mesh_comp *dev_comp; static u16_t dev_primary_addr; -static const struct { - const u16_t id; - int (*const init)(struct bt_mesh_model *model, bool primary); -} model_init[] = { - { BLE_MESH_MODEL_ID_CFG_SRV, bt_mesh_cfg_srv_init }, - { BLE_MESH_MODEL_ID_HEALTH_SRV, bt_mesh_health_srv_init }, -#if defined(CONFIG_BLE_MESH_CFG_CLI) - { BLE_MESH_MODEL_ID_CFG_CLI, bt_mesh_cfg_cli_init }, -#endif -#if defined(CONFIG_BLE_MESH_HEALTH_CLI) - { BLE_MESH_MODEL_ID_HEALTH_CLI, bt_mesh_health_cli_init }, -#endif -#if defined(CONFIG_BLE_MESH_GENERIC_ONOFF_CLI) - { BLE_MESH_MODEL_ID_GEN_ONOFF_CLI, bt_mesh_gen_onoff_cli_init }, -#endif -#if defined(CONFIG_BLE_MESH_GENERIC_LEVEL_CLI) - { BLE_MESH_MODEL_ID_GEN_LEVEL_CLI, bt_mesh_gen_level_cli_init }, -#endif -#if defined(CONFIG_BLE_MESH_GENERIC_DEF_TRANS_TIME_CLI) - { BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI, bt_mesh_gen_def_trans_time_cli_init }, -#endif -#if defined(CONFIG_BLE_MESH_GENERIC_POWER_ONOFF_CLI) - { BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI, bt_mesh_gen_pwr_onoff_cli_init }, -#endif -#if defined(CONFIG_BLE_MESH_GENERIC_POWER_LEVEL_CLI) - { BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI, bt_mesh_gen_pwr_level_cli_init }, -#endif -#if defined(CONFIG_BLE_MESH_GENERIC_BATTERY_CLI) - { BLE_MESH_MODEL_ID_GEN_BATTERY_CLI, bt_mesh_gen_battery_cli_init }, -#endif -#if defined(CONFIG_BLE_MESH_GENERIC_LOCATION_CLI) - { BLE_MESH_MODEL_ID_GEN_LOCATION_CLI, bt_mesh_gen_location_cli_init }, -#endif -#if defined(CONFIG_BLE_MESH_GENERIC_PROPERTY_CLI) - { BLE_MESH_MODEL_ID_GEN_PROP_CLI, bt_mesh_gen_property_cli_init }, -#endif -#if defined(CONFIG_BLE_MESH_SENSOR_CLI) - { BLE_MESH_MODEL_ID_SENSOR_CLI, bt_mesh_sensor_cli_init }, -#endif -#if defined(CONFIG_BLE_MESH_TIME_CLI) - { BLE_MESH_MODEL_ID_TIME_CLI, bt_mesh_time_cli_init }, -#endif -#if defined(CONFIG_BLE_MESH_SCENE_CLI) - { BLE_MESH_MODEL_ID_SCENE_CLI, bt_mesh_scene_cli_init }, -#endif -#if defined(CONFIG_BLE_MESH_SCHEDULER_CLI) - { BLE_MESH_MODEL_ID_SCHEDULER_CLI, bt_mesh_scheduler_cli_init }, -#endif -#if defined(CONFIG_BLE_MESH_LIGHT_LIGHTNESS_CLI) - { BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI, bt_mesh_light_lightness_cli_init }, -#endif -#if defined(CONFIG_BLE_MESH_LIGHT_CTL_CLI) - { BLE_MESH_MODEL_ID_LIGHT_CTL_CLI, bt_mesh_light_ctl_cli_init }, -#endif -#if defined(CONFIG_BLE_MESH_LIGHT_HSL_CLI) - { BLE_MESH_MODEL_ID_LIGHT_HSL_CLI, bt_mesh_light_hsl_cli_init }, -#endif -#if defined(CONFIG_BLE_MESH_LIGHT_XYL_CLI) - { BLE_MESH_MODEL_ID_LIGHT_XYL_CLI, bt_mesh_light_xyl_cli_init }, -#endif -#if defined(CONFIG_BLE_MESH_LIGHT_LC_CLI) - { BLE_MESH_MODEL_ID_LIGHT_LC_CLI, bt_mesh_light_lc_cli_init }, -#endif - { BLE_MESH_MODEL_ID_GEN_ONOFF_SRV, bt_mesh_gen_onoff_srv_init }, - { BLE_MESH_MODEL_ID_GEN_LEVEL_SRV, bt_mesh_gen_level_srv_init }, - { BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV, bt_mesh_gen_def_trans_time_srv_init }, - { BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV, bt_mesh_gen_power_onoff_srv_init }, - { BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV, bt_mesh_gen_power_onoff_setup_srv_init }, - { BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV, bt_mesh_gen_power_level_srv_init }, - { BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV, bt_mesh_gen_power_level_setup_srv_init }, - { BLE_MESH_MODEL_ID_GEN_BATTERY_SRV, bt_mesh_gen_battery_srv_init }, - { BLE_MESH_MODEL_ID_GEN_LOCATION_SRV, bt_mesh_gen_location_srv_init }, - { BLE_MESH_MODEL_ID_GEN_LOCATION_SETUP_SRV, bt_mesh_gen_location_setup_srv_init }, - { BLE_MESH_MODEL_ID_GEN_USER_PROP_SRV, bt_mesh_gen_user_prop_srv_init }, - { BLE_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV, bt_mesh_gen_admin_prop_srv_init }, - { BLE_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV, bt_mesh_gen_manu_prop_srv_init }, - { BLE_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV, bt_mesh_gen_client_prop_srv_init }, - { BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV, bt_mesh_light_lightness_srv_init }, - { BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV, bt_mesh_light_lightness_setup_srv_init }, - { BLE_MESH_MODEL_ID_LIGHT_CTL_SRV, bt_mesh_light_ctl_srv_init }, - { BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV, bt_mesh_light_ctl_setup_srv_init }, - { BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV, bt_mesh_light_ctl_temp_srv_init }, - { BLE_MESH_MODEL_ID_LIGHT_HSL_SRV, bt_mesh_light_hsl_srv_init }, - { BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV, bt_mesh_light_hsl_hue_srv_init }, - { BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV, bt_mesh_light_hsl_sat_srv_init }, - { BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV, bt_mesh_light_hsl_setup_srv_init }, - { BLE_MESH_MODEL_ID_LIGHT_XYL_SRV, bt_mesh_light_xyl_srv_init }, - { BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV, bt_mesh_light_xyl_setup_srv_init }, - { BLE_MESH_MODEL_ID_LIGHT_LC_SRV, bt_mesh_light_lc_srv_init }, - { BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV, bt_mesh_light_lc_setup_srv_init }, - { BLE_MESH_MODEL_ID_TIME_SRV, bt_mesh_time_srv_init }, - { BLE_MESH_MODEL_ID_TIME_SETUP_SRV, bt_mesh_time_setup_srv_init }, - { BLE_MESH_MODEL_ID_SCENE_SRV, bt_mesh_scene_srv_init }, - { BLE_MESH_MODEL_ID_SCENE_SETUP_SRV, bt_mesh_scene_setup_srv_init }, - { BLE_MESH_MODEL_ID_SCHEDULER_SRV, bt_mesh_scheduler_srv_init }, - { BLE_MESH_MODEL_ID_SCHEDULER_SETUP_SRV, bt_mesh_scheduler_setup_srv_init }, - { BLE_MESH_MODEL_ID_SENSOR_SRV, bt_mesh_sensor_srv_init }, - { BLE_MESH_MODEL_ID_SENSOR_SETUP_SRV, bt_mesh_sensor_setup_srv_init }, -}; - -static const struct { - const u16_t id; - int (*const deinit)(struct bt_mesh_model *model, bool primary); -} model_deinit[] = { - { BLE_MESH_MODEL_ID_CFG_SRV, bt_mesh_cfg_srv_deinit }, - { BLE_MESH_MODEL_ID_HEALTH_SRV, bt_mesh_health_srv_deinit }, -#if defined(CONFIG_BLE_MESH_CFG_CLI) - { BLE_MESH_MODEL_ID_CFG_CLI, bt_mesh_cfg_cli_deinit }, -#endif -#if defined(CONFIG_BLE_MESH_HEALTH_CLI) - { BLE_MESH_MODEL_ID_HEALTH_CLI, bt_mesh_health_cli_deinit }, -#endif -#if defined(CONFIG_BLE_MESH_GENERIC_ONOFF_CLI) - { BLE_MESH_MODEL_ID_GEN_ONOFF_CLI, bt_mesh_gen_onoff_cli_deinit }, -#endif -#if defined(CONFIG_BLE_MESH_GENERIC_LEVEL_CLI) - { BLE_MESH_MODEL_ID_GEN_LEVEL_CLI, bt_mesh_gen_level_cli_deinit }, -#endif -#if defined(CONFIG_BLE_MESH_GENERIC_DEF_TRANS_TIME_CLI) - { BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI, bt_mesh_gen_def_trans_time_cli_deinit }, -#endif -#if defined(CONFIG_BLE_MESH_GENERIC_POWER_ONOFF_CLI) - { BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI, bt_mesh_gen_pwr_onoff_cli_deinit }, -#endif -#if defined(CONFIG_BLE_MESH_GENERIC_POWER_LEVEL_CLI) - { BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI, bt_mesh_gen_pwr_level_cli_deinit }, -#endif -#if defined(CONFIG_BLE_MESH_GENERIC_BATTERY_CLI) - { BLE_MESH_MODEL_ID_GEN_BATTERY_CLI, bt_mesh_gen_battery_cli_deinit }, -#endif -#if defined(CONFIG_BLE_MESH_GENERIC_LOCATION_CLI) - { BLE_MESH_MODEL_ID_GEN_LOCATION_CLI, bt_mesh_gen_location_cli_deinit }, -#endif -#if defined(CONFIG_BLE_MESH_GENERIC_PROPERTY_CLI) - { BLE_MESH_MODEL_ID_GEN_PROP_CLI, bt_mesh_gen_property_cli_deinit }, -#endif -#if defined(CONFIG_BLE_MESH_SENSOR_CLI) - { BLE_MESH_MODEL_ID_SENSOR_CLI, bt_mesh_sensor_cli_deinit }, -#endif -#if defined(CONFIG_BLE_MESH_TIME_CLI) - { BLE_MESH_MODEL_ID_TIME_CLI, bt_mesh_time_cli_deinit }, -#endif -#if defined(CONFIG_BLE_MESH_SCENE_CLI) - { BLE_MESH_MODEL_ID_SCENE_CLI, bt_mesh_scene_cli_deinit }, -#endif -#if defined(CONFIG_BLE_MESH_SCHEDULER_CLI) - { BLE_MESH_MODEL_ID_SCHEDULER_CLI, bt_mesh_scheduler_cli_deinit }, -#endif -#if defined(CONFIG_BLE_MESH_LIGHT_LIGHTNESS_CLI) - { BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI, bt_mesh_light_lightness_cli_deinit }, -#endif -#if defined(CONFIG_BLE_MESH_LIGHT_CTL_CLI) - { BLE_MESH_MODEL_ID_LIGHT_CTL_CLI, bt_mesh_light_ctl_cli_deinit }, -#endif -#if defined(CONFIG_BLE_MESH_LIGHT_HSL_CLI) - { BLE_MESH_MODEL_ID_LIGHT_HSL_CLI, bt_mesh_light_hsl_cli_deinit }, -#endif -#if defined(CONFIG_BLE_MESH_LIGHT_XYL_CLI) - { BLE_MESH_MODEL_ID_LIGHT_XYL_CLI, bt_mesh_light_xyl_cli_deinit }, -#endif -#if defined(CONFIG_BLE_MESH_LIGHT_LC_CLI) - { BLE_MESH_MODEL_ID_LIGHT_LC_CLI, bt_mesh_light_lc_cli_deinit }, -#endif - { BLE_MESH_MODEL_ID_GEN_ONOFF_SRV, bt_mesh_gen_onoff_srv_deinit }, - { BLE_MESH_MODEL_ID_GEN_LEVEL_SRV, bt_mesh_gen_level_srv_deinit }, - { BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV, bt_mesh_gen_def_trans_time_srv_deinit }, - { BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV, bt_mesh_gen_power_onoff_srv_deinit }, - { BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV, bt_mesh_gen_power_onoff_setup_srv_deinit }, - { BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV, bt_mesh_gen_power_level_srv_deinit }, - { BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV, bt_mesh_gen_power_level_setup_srv_deinit }, - { BLE_MESH_MODEL_ID_GEN_BATTERY_SRV, bt_mesh_gen_battery_srv_deinit }, - { BLE_MESH_MODEL_ID_GEN_LOCATION_SRV, bt_mesh_gen_location_srv_deinit }, - { BLE_MESH_MODEL_ID_GEN_LOCATION_SETUP_SRV, bt_mesh_gen_location_setup_srv_deinit }, - { BLE_MESH_MODEL_ID_GEN_USER_PROP_SRV, bt_mesh_gen_user_prop_srv_deinit }, - { BLE_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV, bt_mesh_gen_admin_prop_srv_deinit }, - { BLE_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV, bt_mesh_gen_manu_prop_srv_deinit }, - { BLE_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV, bt_mesh_gen_client_prop_srv_deinit }, - { BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV, bt_mesh_light_lightness_srv_deinit }, - { BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV, bt_mesh_light_lightness_setup_srv_deinit }, - { BLE_MESH_MODEL_ID_LIGHT_CTL_SRV, bt_mesh_light_ctl_srv_deinit }, - { BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV, bt_mesh_light_ctl_setup_srv_deinit }, - { BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV, bt_mesh_light_ctl_temp_srv_deinit }, - { BLE_MESH_MODEL_ID_LIGHT_HSL_SRV, bt_mesh_light_hsl_srv_deinit }, - { BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV, bt_mesh_light_hsl_hue_srv_deinit }, - { BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV, bt_mesh_light_hsl_sat_srv_deinit }, - { BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV, bt_mesh_light_hsl_setup_srv_deinit }, - { BLE_MESH_MODEL_ID_LIGHT_XYL_SRV, bt_mesh_light_xyl_srv_deinit }, - { BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV, bt_mesh_light_xyl_setup_srv_deinit }, - { BLE_MESH_MODEL_ID_LIGHT_LC_SRV, bt_mesh_light_lc_srv_deinit }, - { BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV, bt_mesh_light_lc_setup_srv_deinit }, - { BLE_MESH_MODEL_ID_TIME_SRV, bt_mesh_time_srv_deinit }, - { BLE_MESH_MODEL_ID_TIME_SETUP_SRV, bt_mesh_time_setup_srv_deinit }, - { BLE_MESH_MODEL_ID_SCENE_SRV, bt_mesh_scene_srv_deinit }, - { BLE_MESH_MODEL_ID_SCENE_SETUP_SRV, bt_mesh_scene_setup_srv_deinit }, - { BLE_MESH_MODEL_ID_SCHEDULER_SRV, bt_mesh_scheduler_srv_deinit }, - { BLE_MESH_MODEL_ID_SCHEDULER_SETUP_SRV, bt_mesh_scheduler_setup_srv_deinit }, - { BLE_MESH_MODEL_ID_SENSOR_SRV, bt_mesh_sensor_srv_deinit }, - { BLE_MESH_MODEL_ID_SENSOR_SETUP_SRV, bt_mesh_sensor_setup_srv_deinit }, -}; - void bt_mesh_model_foreach(void (*func)(struct bt_mesh_model *mod, struct bt_mesh_elem *elem, bool vnd, bool primary, @@ -531,8 +321,19 @@ struct bt_mesh_model *bt_mesh_model_get(bool vnd, u8_t elem_idx, u8_t mod_idx) static void mod_init(struct bt_mesh_model *mod, struct bt_mesh_elem *elem, bool vnd, bool primary, void *user_data) { + int *err = user_data; int i; + if (!user_data) { + BT_ERR("Invalid model init user data"); + return; + } + + if (*err) { + BT_ERR("Model init failed (err %d)", *err); + return; + } + mod->elem = elem; if (mod->pub) { @@ -556,18 +357,27 @@ static void mod_init(struct bt_mesh_model *mod, struct bt_mesh_elem *elem, return; } - for (i = 0; i < ARRAY_SIZE(model_init); i++) { - if (model_init[i].id == mod->id) { - model_init[i].init(mod, primary); - } + if (mod->cb && mod->cb->init) { + *err = mod->cb->init(mod); } } static void mod_deinit(struct bt_mesh_model *mod, struct bt_mesh_elem *elem, bool vnd, bool primary, void *user_data) { + int *err = user_data; int i; + if (!user_data) { + BT_ERR("Invalid model deinit user data"); + return; + } + + if (*err) { + BT_ERR("Model deinit failed (err %d)", *err); + return; + } + mod->elem = NULL; if (mod->pub) { @@ -587,15 +397,15 @@ static void mod_deinit(struct bt_mesh_model *mod, struct bt_mesh_elem *elem, return; } - for (i = 0; i < ARRAY_SIZE(model_deinit); i++) { - if (model_deinit[i].id == mod->id) { - model_deinit[i].deinit(mod, primary); - } + if (mod->cb && mod->cb->deinit) { + *err = mod->cb->deinit(mod); } } int bt_mesh_comp_register(const struct bt_mesh_comp *comp) { + int err = 0; + /* There must be at least one element */ if (!comp->elem_count) { return -EINVAL; @@ -603,23 +413,24 @@ int bt_mesh_comp_register(const struct bt_mesh_comp *comp) dev_comp = comp; - bt_mesh_model_foreach(mod_init, NULL); + bt_mesh_model_foreach(mod_init, &err); - return 0; + return err; } int bt_mesh_comp_deregister(void) { + int err = 0; + if (dev_comp == NULL) { return -EINVAL; } - bt_mesh_model_foreach(mod_deinit, NULL); + bt_mesh_model_foreach(mod_deinit, &err); - dev_primary_addr = BLE_MESH_ADDR_UNASSIGNED; dev_comp = NULL; - return 0; + return err; } void bt_mesh_comp_provision(u16_t addr) @@ -645,8 +456,6 @@ void bt_mesh_comp_unprovision(void) BT_DBG("%s", __func__); dev_primary_addr = BLE_MESH_ADDR_UNASSIGNED; - - bt_mesh_model_foreach(mod_init, NULL); } u16_t bt_mesh_primary_addr(void) @@ -668,7 +477,7 @@ u16_t *bt_mesh_model_find_group(struct bt_mesh_model *mod, u16_t addr) } static struct bt_mesh_model *bt_mesh_elem_find_group(struct bt_mesh_elem *elem, - u16_t group_addr) + u16_t group_addr) { struct bt_mesh_model *model = NULL; u16_t *match = NULL; diff --git a/components/bt/esp_ble_mesh/mesh_core/access.h b/components/bt/esp_ble_mesh/mesh_core/access.h index e74f8df73..c5615af54 100644 --- a/components/bt/esp_ble_mesh/mesh_core/access.h +++ b/components/bt/esp_ble_mesh/mesh_core/access.h @@ -29,10 +29,6 @@ u8_t bt_mesh_elem_count(void); /* Find local element based on unicast or group address */ struct bt_mesh_elem *bt_mesh_elem_find(u16_t addr); -struct bt_mesh_model *bt_mesh_model_find_vnd(struct bt_mesh_elem *elem, - u16_t company, u16_t id); -struct bt_mesh_model *bt_mesh_model_find(struct bt_mesh_elem *elem, u16_t id); - u16_t *bt_mesh_model_find_group(struct bt_mesh_model *mod, u16_t addr); bool bt_mesh_fixed_group_match(u16_t addr); diff --git a/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c b/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c index 61bcc541d..16c2f6d90 100644 --- a/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c +++ b/components/bt/esp_ble_mesh/mesh_core/cfg_cli.c @@ -1240,20 +1240,18 @@ int bt_mesh_cfg_net_transmit_set(bt_mesh_client_common_param_t *param, u8_t tran return send_msg_with_u8(param, OP_NET_TRANSMIT_SET, transmit); } -int bt_mesh_cfg_cli_init(struct bt_mesh_model *model, bool primary) +static int cfg_cli_init(struct bt_mesh_model *model) { config_internal_data_t *internal = NULL; bt_mesh_config_client_t *client = NULL; - BT_DBG("primary %u", primary); - - if (!primary) { - BT_ERR("Configuration Client only allowed in primary element"); + if (!model) { + BT_ERR("Invalid Configuration Client model"); return -EINVAL; } - if (!model) { - BT_ERR("Configuration Client model is NULL"); + if (!bt_mesh_model_in_primary(model)) { + BT_ERR("Configuration Client only allowed in primary element"); return -EINVAL; } @@ -1288,17 +1286,17 @@ int bt_mesh_cfg_cli_init(struct bt_mesh_model *model, bool primary) return 0; } -int bt_mesh_cfg_cli_deinit(struct bt_mesh_model *model, bool primary) +static int cfg_cli_deinit(struct bt_mesh_model *model) { bt_mesh_config_client_t *client = NULL; - if (!primary) { - BT_ERR("Configuration Client only allowed in primary element"); + if (!model) { + BT_ERR("Invalid Configuration Client model"); return -EINVAL; } - if (!model) { - BT_ERR("Configuration Client model is NULL"); + if (!bt_mesh_model_in_primary(model)) { + BT_ERR("Configuration Client only allowed in primary element"); return -EINVAL; } @@ -1321,3 +1319,8 @@ int bt_mesh_cfg_cli_deinit(struct bt_mesh_model *model, bool primary) return 0; } + +const struct bt_mesh_model_cb bt_mesh_cfg_cli_cb = { + .init = cfg_cli_init, + .deinit = cfg_cli_deinit, +}; diff --git a/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c b/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c index d2ea61c33..e5db4550f 100644 --- a/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c +++ b/components/bt/esp_ble_mesh/mesh_core/cfg_srv.c @@ -3344,10 +3344,15 @@ static bool conf_is_valid(struct bt_mesh_cfg_srv *cfg) return true; } -int bt_mesh_cfg_srv_init(struct bt_mesh_model *model, bool primary) +static int cfg_srv_init(struct bt_mesh_model *model) { struct bt_mesh_cfg_srv *cfg = model->user_data; + if (!bt_mesh_model_in_primary(model)) { + BT_ERR("Configuration Server only allowed in primary element"); + return -EINVAL; + } + if (!cfg) { BT_ERR("No Configuration Server context provided"); return -EINVAL; @@ -3384,10 +3389,15 @@ int bt_mesh_cfg_srv_init(struct bt_mesh_model *model, bool primary) return 0; } -int bt_mesh_cfg_srv_deinit(struct bt_mesh_model *model, bool primary) +static int cfg_srv_deinit(struct bt_mesh_model *model) { struct bt_mesh_cfg_srv *cfg = model->user_data; + if (!bt_mesh_model_in_primary(model)) { + BT_ERR("Configuration Server only allowed in primary element"); + return -EINVAL; + } + if (!cfg) { BT_ERR("No Configuration Server context provided"); return -EINVAL; @@ -3403,6 +3413,11 @@ int bt_mesh_cfg_srv_deinit(struct bt_mesh_model *model, bool primary) return 0; } +const struct bt_mesh_model_cb bt_mesh_cfg_srv_cb = { + .init = cfg_srv_init, + .deinit = cfg_srv_deinit, +}; + static void mod_reset(struct bt_mesh_model *mod, struct bt_mesh_elem *elem, bool vnd, bool primary, void *user_data) { diff --git a/components/bt/esp_ble_mesh/mesh_core/foundation.h b/components/bt/esp_ble_mesh/mesh_core/foundation.h index 76634079e..abac4a6be 100644 --- a/components/bt/esp_ble_mesh/mesh_core/foundation.h +++ b/components/bt/esp_ble_mesh/mesh_core/foundation.h @@ -132,18 +132,6 @@ struct label { bt_mesh_atomic_t flags[1]; }; -int bt_mesh_cfg_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_health_srv_init(struct bt_mesh_model *model, bool primary); - -int bt_mesh_cfg_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_health_srv_deinit(struct bt_mesh_model *model, bool primary); - -int bt_mesh_cfg_cli_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_health_cli_init(struct bt_mesh_model *model, bool primary); - -int bt_mesh_cfg_cli_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_health_cli_deinit(struct bt_mesh_model *model, bool primary); - void bt_mesh_cfg_reset(void); void bt_mesh_heartbeat(u16_t src, u16_t dst, u8_t hops, u16_t feat); diff --git a/components/bt/esp_ble_mesh/mesh_core/health_cli.c b/components/bt/esp_ble_mesh/mesh_core/health_cli.c index 2af6dbad2..07c0c0cc3 100644 --- a/components/bt/esp_ble_mesh/mesh_core/health_cli.c +++ b/components/bt/esp_ble_mesh/mesh_core/health_cli.c @@ -303,18 +303,18 @@ int bt_mesh_health_fault_get(bt_mesh_client_common_param_t *param, u16_t cid) return bt_mesh_client_send_msg(param, &msg, true, timeout_handler); } -int bt_mesh_health_cli_init(struct bt_mesh_model *model, bool primary) +static int health_cli_init(struct bt_mesh_model *model) { health_internal_data_t *internal = NULL; bt_mesh_health_client_t *client = NULL; - BT_DBG("primary %u", primary); - if (!model) { - BT_ERR("%s, Invalid parameter", __func__); + BT_ERR("Invalid Health Client model"); return -EINVAL; } + BT_DBG("primary %u", bt_mesh_model_in_primary(model)); + client = (bt_mesh_health_client_t *)model->user_data; if (!client) { BT_ERR("No Health Client context provided"); @@ -343,15 +343,17 @@ int bt_mesh_health_cli_init(struct bt_mesh_model *model, bool primary) return 0; } -int bt_mesh_health_cli_deinit(struct bt_mesh_model *model, bool primary) +static int health_cli_deinit(struct bt_mesh_model *model) { bt_mesh_health_client_t *client = NULL; if (!model) { - BT_ERR("%s, Invalid parameter", __func__); + BT_ERR("Invalid Health Client model"); return -EINVAL; } + BT_DBG("primary %u", bt_mesh_model_in_primary(model)); + client = (bt_mesh_health_client_t *)model->user_data; if (!client) { BT_ERR("No Health Client context provided"); @@ -371,3 +373,8 @@ int bt_mesh_health_cli_deinit(struct bt_mesh_model *model, bool primary) return 0; } + +const struct bt_mesh_model_cb bt_mesh_health_cli_cb = { + .init = health_cli_init, + .deinit = health_cli_deinit, +}; diff --git a/components/bt/esp_ble_mesh/mesh_core/health_srv.c b/components/bt/esp_ble_mesh/mesh_core/health_srv.c index 5ca88a9d9..e37ff6943 100644 --- a/components/bt/esp_ble_mesh/mesh_core/health_srv.c +++ b/components/bt/esp_ble_mesh/mesh_core/health_srv.c @@ -429,7 +429,7 @@ static void attention_off(struct k_work *work) srv->attn_timer_start = false; } -int bt_mesh_health_srv_init(struct bt_mesh_model *model, bool primary) +static int health_srv_init(struct bt_mesh_model *model) { struct bt_mesh_health_srv *srv = model->user_data; @@ -438,11 +438,6 @@ int bt_mesh_health_srv_init(struct bt_mesh_model *model, bool primary) */ if (!srv) { - if (!primary) { - /* If Health Server is in the secondary element with NULL user_data. */ - return 0; - } - BT_ERR("No Health Server context provided"); return -EINVAL; } @@ -467,23 +462,18 @@ int bt_mesh_health_srv_init(struct bt_mesh_model *model, bool primary) memset(srv->test.curr_faults, HEALTH_NO_FAULT, ARRAY_SIZE(srv->test.curr_faults)); memset(srv->test.reg_faults, HEALTH_NO_FAULT, ARRAY_SIZE(srv->test.reg_faults)); - if (primary) { + if (bt_mesh_model_in_primary(model)) { health_srv = srv; } return 0; } -int bt_mesh_health_srv_deinit(struct bt_mesh_model *model, bool primary) +static int health_srv_deinit(struct bt_mesh_model *model) { struct bt_mesh_health_srv *srv = model->user_data; if (!srv) { - if (!primary) { - /* If Health Server is in the secondary element with NULL user_data. */ - return 0; - } - BT_ERR("No Health Server context provided"); return -EINVAL; } @@ -503,13 +493,18 @@ int bt_mesh_health_srv_deinit(struct bt_mesh_model *model, bool primary) k_delayed_work_free(&srv->attn_timer); - if (primary) { + if (bt_mesh_model_in_primary(model)) { health_srv = NULL; } return 0; } +const struct bt_mesh_model_cb bt_mesh_health_srv_cb = { + .init = health_srv_init, + .deinit = health_srv_deinit, +}; + void bt_mesh_attention(struct bt_mesh_model *model, u8_t time) { struct bt_mesh_health_srv *srv = NULL; diff --git a/components/bt/esp_ble_mesh/mesh_core/include/cfg_cli.h b/components/bt/esp_ble_mesh/mesh_core/include/cfg_cli.h index e04b7b3ad..2294a58f9 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/cfg_cli.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/cfg_cli.h @@ -29,10 +29,11 @@ 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[]; +extern const struct bt_mesh_model_cb bt_mesh_cfg_cli_cb; #define BLE_MESH_MODEL_CFG_CLI(cli_data) \ - BLE_MESH_MODEL(BLE_MESH_MODEL_ID_CFG_CLI, \ - bt_mesh_cfg_cli_op, NULL, cli_data) + BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_CFG_CLI, \ + bt_mesh_cfg_cli_op, NULL, cli_data, &bt_mesh_cfg_cli_cb) int bt_mesh_cfg_comp_data_get(bt_mesh_client_common_param_t *param, u8_t page); diff --git a/components/bt/esp_ble_mesh/mesh_core/include/cfg_srv.h b/components/bt/esp_ble_mesh/mesh_core/include/cfg_srv.h index fe9843239..0af076e9e 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/cfg_srv.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/cfg_srv.h @@ -63,10 +63,11 @@ struct bt_mesh_cfg_srv { }; extern const struct bt_mesh_model_op bt_mesh_cfg_srv_op[]; +extern const struct bt_mesh_model_cb bt_mesh_cfg_srv_cb; #define BLE_MESH_MODEL_CFG_SRV(srv_data) \ - BLE_MESH_MODEL(BLE_MESH_MODEL_ID_CFG_SRV, \ - bt_mesh_cfg_srv_op, NULL, srv_data) + BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_CFG_SRV, \ + bt_mesh_cfg_srv_op, NULL, srv_data, &bt_mesh_cfg_srv_cb) typedef union { struct { diff --git a/components/bt/esp_ble_mesh/mesh_core/include/health_cli.h b/components/bt/esp_ble_mesh/mesh_core/include/health_cli.h index 6bb7a4285..359b3878b 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/health_cli.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/health_cli.h @@ -29,10 +29,11 @@ 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[]; +extern const struct bt_mesh_model_cb bt_mesh_health_cli_cb; #define BLE_MESH_MODEL_HEALTH_CLI(cli_data) \ - BLE_MESH_MODEL(BLE_MESH_MODEL_ID_HEALTH_CLI, \ - bt_mesh_health_cli_op, NULL, cli_data) + BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_HEALTH_CLI, \ + bt_mesh_health_cli_op, NULL, cli_data, &bt_mesh_health_cli_cb) int bt_mesh_health_fault_get(bt_mesh_client_common_param_t *param, u16_t cid); diff --git a/components/bt/esp_ble_mesh/mesh_core/include/health_srv.h b/components/bt/esp_ble_mesh/mesh_core/include/health_srv.h index 02a21e295..8255993f8 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/health_srv.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/health_srv.h @@ -75,6 +75,7 @@ struct bt_mesh_health_srv { }; extern const struct bt_mesh_model_op bt_mesh_health_srv_op[]; +extern const struct bt_mesh_model_cb bt_mesh_health_srv_cb; /** @def BLE_MESH_MODEL_HEALTH_SRV * @@ -89,8 +90,8 @@ extern const struct bt_mesh_model_op bt_mesh_health_srv_op[]; * @return New mesh model instance. */ #define BLE_MESH_MODEL_HEALTH_SRV(srv, pub) \ - BLE_MESH_MODEL(BLE_MESH_MODEL_ID_HEALTH_SRV, \ - bt_mesh_health_srv_op, pub, srv) + BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_HEALTH_SRV, \ + bt_mesh_health_srv_op, pub, srv, &bt_mesh_health_srv_cb) int bt_mesh_fault_update(struct bt_mesh_elem *elem); diff --git a/components/bt/esp_ble_mesh/mesh_core/include/mesh_access.h b/components/bt/esp_ble_mesh/mesh_core/include/mesh_access.h index dd3985a8d..31a8bbfb5 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/mesh_access.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/mesh_access.h @@ -190,12 +190,12 @@ struct bt_mesh_model_op { { BLE_MESH_MODEL_OP_END }) /** Helper to define an empty model array */ -#define BLE_MESH_MODEL_NONE ((struct bt_mesh_model []){}) +#define BLE_MESH_MODEL_NONE ((struct bt_mesh_model []){}) /** Length of a short Mesh MIC. */ -#define BLE_MESH_MIC_SHORT 4 +#define BLE_MESH_MIC_SHORT 4 /** Length of a long Mesh MIC. */ -#define BLE_MESH_MIC_LONG 8 +#define BLE_MESH_MIC_LONG 8 /** @def BLE_MESH_MODEL_OP_LEN * @@ -240,31 +240,54 @@ struct bt_mesh_model_op { * @param _payload_len Length of the model message payload. */ #define BLE_MESH_MODEL_BUF_DEFINE(_buf, _op, _payload_len) \ - NET_BUF_SIMPLE_DEFINE(_buf, BLE_MESH_MODEL_BUF_LEN(_op, (_payload_len))) + NET_BUF_SIMPLE_DEFINE(_buf, BLE_MESH_MODEL_BUF_LEN((_op), (_payload_len))) -#define BLE_MESH_MODEL(_id, _op, _pub, _user_data) \ +/** @def BLE_MESH_MODEL_CB + * + * @brief Composition data SIG model entry with callback functions. + * + * @param _id Model ID. + * @param _op Array of model opcode handlers. + * @param _pub Model publish parameters. + * @param _user_data User data for the model. + * @param _cb Callback structure, or NULL to keep no callbacks. + */ +#define BLE_MESH_MODEL_CB(_id, _op, _pub, _user_data, _cb) \ { \ .id = (_id), \ - .op = _op, \ + .op = (_op), \ .keys = { [0 ... (CONFIG_BLE_MESH_MODEL_KEY_COUNT - 1)] = \ BLE_MESH_KEY_UNUSED }, \ - .pub = _pub, \ + .pub = (_pub), \ .groups = { [0 ... (CONFIG_BLE_MESH_MODEL_GROUP_COUNT - 1)] = \ BLE_MESH_ADDR_UNASSIGNED }, \ - .user_data = _user_data, \ + .user_data = (_user_data), \ + .cb = (_cb), \ } -#define BLE_MESH_MODEL_VND(_company, _id, _op, _pub, _user_data) \ +/** @def BLE_MESH_MODEL_VND_CB + * + * @brief Composition data vendor model entry with callback functions. + * + * @param _company Company ID. + * @param _id Model ID. + * @param _op Array of model opcode handlers. + * @param _pub Model publish parameters. + * @param _user_data User data for the model. + * @param _cb Callback structure, or NULL to keep no callbacks. + */ +#define BLE_MESH_MODEL_VND_CB(_company, _id, _op, _pub, _user_data, _cb) \ { \ .vnd.company = (_company), \ .vnd.id = (_id), \ - .op = _op, \ - .pub = _pub, \ + .op = (_op), \ + .pub = (_pub), \ .keys = { [0 ... (CONFIG_BLE_MESH_MODEL_KEY_COUNT - 1)] = \ BLE_MESH_KEY_UNUSED }, \ .groups = { [0 ... (CONFIG_BLE_MESH_MODEL_GROUP_COUNT - 1)] = \ BLE_MESH_ADDR_UNASSIGNED }, \ - .user_data = _user_data, \ + .user_data = (_user_data), \ + .cb = (_cb), \ } /** @def BLE_MESH_TRANSMIT @@ -278,7 +301,7 @@ struct bt_mesh_model_op { * @return Mesh transmit value that can be used e.g. for the default * values of the configuration model data. */ -#define BLE_MESH_TRANSMIT(count, int_ms) ((count) | (((int_ms / 10) - 1) << 3)) +#define BLE_MESH_TRANSMIT(count, int_ms) ((count) | ((((int_ms) / 10) - 1) << 3)) /** @def BLE_MESH_TRANSMIT_COUNT * @@ -311,7 +334,7 @@ struct bt_mesh_model_op { * @return Mesh transmit value that can be used e.g. for the default * values of the configuration model data. */ -#define BLE_MESH_PUB_TRANSMIT(count, int_ms) BLE_MESH_TRANSMIT(count, (int_ms) / 5) +#define BLE_MESH_PUB_TRANSMIT(count, int_ms) BLE_MESH_TRANSMIT((count), (int_ms) / 5) /** @def BLE_MESH_PUB_TRANSMIT_COUNT * @@ -400,6 +423,36 @@ struct bt_mesh_model_pub { .msg = &bt_mesh_pub_msg_##_name, \ } +/** Model callback functions. */ +struct bt_mesh_model_cb { + /** @brief Model init callback. + * + * Called on every model instance during mesh initialization. + * + * If any of the model init callbacks return an error, the mesh + * subsystem initialization will be aborted, and the error will + * be returned to the caller of @ref bt_mesh_init. + * + * @param model Model to be initialized. + * + * @return 0 on success, error otherwise. + */ + int (*const init)(struct bt_mesh_model *model); + + /** @brief Model deinit callback. + * + * Called on every model instance during mesh deinitialization. + * All model data is deleted, and the model should clear its state. + * + * If any of the model deinit callbacks return an error, the mesh + * subsystem deinitialization will be aborted, and the error will + * be returned to the caller of @ref bt_mesh_deinit. + * + * @param model Model to be de-initialized. + */ + int (*const deinit)(struct bt_mesh_model *model); +}; + /** Abstraction that describes a Mesh Model instance */ struct bt_mesh_model { union { @@ -427,8 +480,12 @@ struct bt_mesh_model { /* Subscription List (group or virtual addresses) */ u16_t groups[CONFIG_BLE_MESH_MODEL_GROUP_COUNT]; + /** Opcode handler list */ const struct bt_mesh_model_op *const op; + /** Model callback structure. */ + const struct bt_mesh_model_cb *const cb; + /* Model-specific user data */ void *user_data; }; @@ -488,6 +545,39 @@ int bt_mesh_model_publish(struct bt_mesh_model *model); */ struct bt_mesh_elem *bt_mesh_model_elem(struct bt_mesh_model *mod); +/** @brief Find a SIG model. + * + * @param elem Element to search for the model in. + * @param id Model ID of the model. + * + * @return A pointer to the Mesh model matching the given parameters, or NULL + * if no SIG model with the given ID exists in the given element. + */ +struct bt_mesh_model *bt_mesh_model_find(struct bt_mesh_elem *elem, u16_t id); + +/** @brief Find a vendor model. + * + * @param elem Element to search for the model in. + * @param company Company ID of the model. + * @param id Model ID of the model. + * + * @return A pointer to the Mesh model matching the given parameters, or NULL + * if no vendor model with the given ID exists in the given element. + */ +struct bt_mesh_model *bt_mesh_model_find_vnd(struct bt_mesh_elem *elem, + u16_t company, u16_t id); + +/** @brief Get whether the model is in the primary element of the device. + * + * @param mod Mesh model. + * + * @return true if the model is on the primary element, false otherwise. + */ +static inline bool bt_mesh_model_in_primary(const struct bt_mesh_model *mod) +{ + return (mod->elem_idx == 0); +} + /** Node Composition */ struct bt_mesh_comp { u16_t cid; diff --git a/components/bt/esp_ble_mesh/mesh_core/main.c b/components/bt/esp_ble_mesh/mesh_core/main.c index 119b17321..5b7066d7b 100644 --- a/components/bt/esp_ble_mesh/mesh_core/main.c +++ b/components/bt/esp_ble_mesh/mesh_core/main.c @@ -496,6 +496,8 @@ int bt_mesh_deinit(struct bt_mesh_deinit_param *param) return err; } + bt_mesh_comp_unprovision(); + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { if (param->erase) { bt_mesh_clear_role(); diff --git a/components/bt/esp_ble_mesh/mesh_models/client/client_common.c b/components/bt/esp_ble_mesh/mesh_models/client/client_common.c index 857028628..b61c5579c 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/client_common.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/client_common.c @@ -142,7 +142,7 @@ static bool bt_mesh_client_check_node_in_list(sys_slist_t *list, u16_t tx_dst) } static u32_t bt_mesh_client_get_status_op(const bt_mesh_client_op_pair_t *op_pair, - int size, u32_t opcode) + int size, u32_t opcode) { if (!op_pair || size == 0) { return 0; @@ -381,25 +381,20 @@ void bt_mesh_client_model_unlock(void) int bt_mesh_client_init(struct bt_mesh_model *model) { bt_mesh_client_internal_data_t *data = NULL; - bt_mesh_client_user_data_t *cli = NULL; + bt_mesh_client_user_data_t *client = NULL; - if (!model) { - BT_ERR("%s, Invalid parameter", __func__); + if (!model || !model->op) { + BT_ERR("Invalid vendor client model"); return -EINVAL; } - if (!model->op) { - BT_ERR("Invalid vendor client model op"); + client = (bt_mesh_client_user_data_t *)model->user_data; + if (!client) { + BT_ERR("No vendor client context provided"); return -EINVAL; } - cli = model->user_data; - if (!cli) { - BT_ERR("Invalid vendor client user data"); - return -EINVAL; - } - - if (!cli->internal_data) { + if (!client->internal_data) { data = bt_mesh_calloc(sizeof(bt_mesh_client_internal_data_t)); if (!data) { BT_ERR("%s, Out of memory", __func__); @@ -409,10 +404,10 @@ int bt_mesh_client_init(struct bt_mesh_model *model) /* Init the client data queue */ sys_slist_init(&data->queue); - cli->model = model; - cli->internal_data = data; + client->model = model; + client->internal_data = data; } else { - bt_mesh_client_clear_list(cli->internal_data); + bt_mesh_client_clear_list(client->internal_data); } bt_mesh_client_model_mutex_new(); @@ -425,13 +420,13 @@ int bt_mesh_client_deinit(struct bt_mesh_model *model) bt_mesh_client_user_data_t *client = NULL; if (!model) { - BT_ERR("%s, Invalid parameter", __func__); + BT_ERR("Invalid vendor client model"); return -EINVAL; } client = (bt_mesh_client_user_data_t *)model->user_data; if (!client) { - BT_ERR("Invalid vendor client user data"); + BT_ERR("No vendor client context provided"); return -EINVAL; } diff --git a/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c b/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c index 62a1ea626..91542536c 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/generic_client.c @@ -636,27 +636,27 @@ static void generic_status(struct bt_mesh_model *model, return; } -const struct bt_mesh_model_op gen_onoff_cli_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_onoff_cli_op[] = { { BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS, 1, generic_status }, BLE_MESH_MODEL_OP_END, }; -const struct bt_mesh_model_op gen_level_cli_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_level_cli_op[] = { { BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS, 2, generic_status }, BLE_MESH_MODEL_OP_END, }; -const struct bt_mesh_model_op gen_def_trans_time_cli_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_def_trans_time_cli_op[] = { { BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS, 1, generic_status }, BLE_MESH_MODEL_OP_END, }; -const struct bt_mesh_model_op gen_power_onoff_cli_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_power_onoff_cli_op[] = { { BLE_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS, 1, generic_status }, BLE_MESH_MODEL_OP_END, }; -const struct bt_mesh_model_op gen_power_level_cli_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_power_level_cli_op[] = { { BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS, 2, generic_status }, { BLE_MESH_MODEL_OP_GEN_POWER_LAST_STATUS, 2, generic_status }, { BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS, 2, generic_status }, @@ -664,18 +664,18 @@ const struct bt_mesh_model_op gen_power_level_cli_op[] = { BLE_MESH_MODEL_OP_END, }; -const struct bt_mesh_model_op gen_battery_cli_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_battery_cli_op[] = { { BLE_MESH_MODEL_OP_GEN_BATTERY_STATUS, 8, generic_status }, BLE_MESH_MODEL_OP_END, }; -const struct bt_mesh_model_op gen_location_cli_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_location_cli_op[] = { { BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS, 10, generic_status }, { BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS, 9, generic_status }, BLE_MESH_MODEL_OP_END, }; -const struct bt_mesh_model_op gen_property_cli_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_property_cli_op[] = { { BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS, 2, generic_status }, { BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS, 2, generic_status }, { BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS, 2, generic_status }, @@ -1134,21 +1134,19 @@ int bt_mesh_generic_client_set_state(bt_mesh_client_common_param_t *common, void return gen_set_state(common, set, length, need_ack); } -static int generic_client_init(struct bt_mesh_model *model, bool primary) +static int generic_client_init(struct bt_mesh_model *model) { generic_internal_data_t *internal = NULL; bt_mesh_generic_client_t *client = NULL; - BT_DBG("primary %u", primary); - if (!model) { - BT_ERR("%s, Invalid parameter", __func__); + BT_ERR("Invalid Generic client model"); return -EINVAL; } client = (bt_mesh_generic_client_t *)model->user_data; if (!client) { - BT_ERR("Invalid Generic client user data"); + BT_ERR("No Generic client context provided"); return -EINVAL; } @@ -1174,58 +1172,18 @@ static int generic_client_init(struct bt_mesh_model *model, bool primary) return 0; } -int bt_mesh_gen_onoff_cli_init(struct bt_mesh_model *model, bool primary) -{ - return generic_client_init(model, primary); -} - -int bt_mesh_gen_level_cli_init(struct bt_mesh_model *model, bool primary) -{ - return generic_client_init(model, primary); -} - -int bt_mesh_gen_def_trans_time_cli_init(struct bt_mesh_model *model, bool primary) -{ - return generic_client_init(model, primary); -} - -int bt_mesh_gen_pwr_onoff_cli_init(struct bt_mesh_model *model, bool primary) -{ - return generic_client_init(model, primary); -} - -int bt_mesh_gen_pwr_level_cli_init(struct bt_mesh_model *model, bool primary) -{ - return generic_client_init(model, primary); -} - -int bt_mesh_gen_battery_cli_init(struct bt_mesh_model *model, bool primary) -{ - return generic_client_init(model, primary); -} - -int bt_mesh_gen_location_cli_init(struct bt_mesh_model *model, bool primary) -{ - return generic_client_init(model, primary); -} - -int bt_mesh_gen_property_cli_init(struct bt_mesh_model *model, bool primary) -{ - return generic_client_init(model, primary); -} - -static int generic_client_deinit(struct bt_mesh_model *model, bool primary) +static int generic_client_deinit(struct bt_mesh_model *model) { bt_mesh_generic_client_t *client = NULL; if (!model) { - BT_ERR("%s, Invalid parameter", __func__); + BT_ERR("Invalid Generic client model"); return -EINVAL; } client = (bt_mesh_generic_client_t *)model->user_data; if (!client) { - BT_ERR("Invalid Generic client user data"); + BT_ERR("No Generic client context provided"); return -EINVAL; } @@ -1243,42 +1201,7 @@ static int generic_client_deinit(struct bt_mesh_model *model, bool primary) return 0; } -int bt_mesh_gen_onoff_cli_deinit(struct bt_mesh_model *model, bool primary) -{ - return generic_client_deinit(model, primary); -} - -int bt_mesh_gen_level_cli_deinit(struct bt_mesh_model *model, bool primary) -{ - return generic_client_deinit(model, primary); -} - -int bt_mesh_gen_def_trans_time_cli_deinit(struct bt_mesh_model *model, bool primary) -{ - return generic_client_deinit(model, primary); -} - -int bt_mesh_gen_pwr_onoff_cli_deinit(struct bt_mesh_model *model, bool primary) -{ - return generic_client_deinit(model, primary); -} - -int bt_mesh_gen_pwr_level_cli_deinit(struct bt_mesh_model *model, bool primary) -{ - return generic_client_deinit(model, primary); -} - -int bt_mesh_gen_battery_cli_deinit(struct bt_mesh_model *model, bool primary) -{ - return generic_client_deinit(model, primary); -} - -int bt_mesh_gen_location_cli_deinit(struct bt_mesh_model *model, bool primary) -{ - return generic_client_deinit(model, primary); -} - -int bt_mesh_gen_property_cli_deinit(struct bt_mesh_model *model, bool primary) -{ - return generic_client_deinit(model, primary); -} +const struct bt_mesh_model_cb bt_mesh_generic_client_cb = { + .init = generic_client_init, + .deinit = generic_client_deinit, +}; diff --git a/components/bt/esp_ble_mesh/mesh_models/client/include/generic_client.h b/components/bt/esp_ble_mesh/mesh_models/client/include/generic_client.h index 53bea9743..b9619ac1c 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/include/generic_client.h +++ b/components/bt/esp_ble_mesh/mesh_models/client/include/generic_client.h @@ -29,8 +29,11 @@ extern "C" { typedef bt_mesh_client_user_data_t bt_mesh_generic_client_t; typedef bt_mesh_client_internal_data_t generic_internal_data_t; +/* Generic Client Model Callback */ +extern const struct bt_mesh_model_cb bt_mesh_generic_client_cb; + /* Generic OnOff Client Model Context */ -extern const struct bt_mesh_model_op gen_onoff_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_onoff_cli_op[]; /** @def BLE_MESH_MODEL_GEN_ONOFF_CLI * @@ -43,8 +46,8 @@ extern const struct bt_mesh_model_op gen_onoff_cli_op[]; * @return New generic onoff client model instance. */ #define BLE_MESH_MODEL_GEN_ONOFF_CLI(cli_pub, cli_data) \ - BLE_MESH_MODEL(BLE_MESH_MODEL_ID_GEN_ONOFF_CLI, \ - gen_onoff_cli_op, cli_pub, cli_data) + BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_ONOFF_CLI, \ + bt_mesh_gen_onoff_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb) typedef bt_mesh_client_user_data_t bt_mesh_gen_onoff_client_t; @@ -64,7 +67,7 @@ struct bt_mesh_gen_onoff_set { }; /* Generic Level Client Model Context */ -extern const struct bt_mesh_model_op gen_level_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_level_cli_op[]; /** @def BLE_MESH_MODEL_GEN_LEVEL_CLI * @@ -77,8 +80,8 @@ extern const struct bt_mesh_model_op gen_level_cli_op[]; * @return New generic level client model instance. */ #define BLE_MESH_MODEL_GEN_LEVEL_CLI(cli_pub, cli_data) \ - BLE_MESH_MODEL(BLE_MESH_MODEL_ID_GEN_LEVEL_CLI, \ - gen_level_cli_op, cli_pub, cli_data) + BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_LEVEL_CLI, \ + bt_mesh_gen_level_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb) typedef bt_mesh_client_user_data_t bt_mesh_gen_level_client_t; @@ -114,7 +117,7 @@ struct bt_mesh_gen_move_set { }; /* Generic Default Transition Time Client Model Context */ -extern const struct bt_mesh_model_op gen_def_trans_time_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_def_trans_time_cli_op[]; /** @def BLE_MESH_MODEL_GEN_DEF_TRANS_TIME_CLI * @@ -128,8 +131,8 @@ extern const struct bt_mesh_model_op gen_def_trans_time_cli_op[]; * @return New generic default transition time client model instance. */ #define BLE_MESH_MODEL_GEN_DEF_TRANS_TIME_CLI(cli_pub, cli_data) \ - BLE_MESH_MODEL(BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI, \ - gen_def_trans_time_cli_op, cli_pub, cli_data) + BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI, \ + bt_mesh_gen_def_trans_time_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb) typedef bt_mesh_client_user_data_t bt_mesh_gen_def_trans_time_client_t; @@ -142,7 +145,7 @@ struct bt_mesh_gen_def_trans_time_status { }; /* Generic Power OnOff Client Model Context */ -extern const struct bt_mesh_model_op gen_power_onoff_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_power_onoff_cli_op[]; /** @def BLE_MESH_MODEL_GEN_POWER_ONOFF_CLI * @@ -155,8 +158,8 @@ extern const struct bt_mesh_model_op gen_power_onoff_cli_op[]; * @return New generic power onoff client model instance. */ #define BLE_MESH_MODEL_GEN_POWER_ONOFF_CLI(cli_pub, cli_data) \ - BLE_MESH_MODEL(BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI, \ - gen_power_onoff_cli_op, cli_pub, cli_data) + BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI, \ + bt_mesh_gen_power_onoff_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb) typedef bt_mesh_client_user_data_t bt_mesh_gen_power_onoff_client_t; @@ -169,7 +172,7 @@ struct bt_mesh_gen_onpowerup_status { }; /* Generic Power Level Client Model Context */ -extern const struct bt_mesh_model_op gen_power_level_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_power_level_cli_op[]; /** @def BLE_MESH_MODEL_GEN_POWER_LEVEL_CLI * @@ -182,8 +185,8 @@ extern const struct bt_mesh_model_op gen_power_level_cli_op[]; * @return New generic power level client model instance. */ #define BLE_MESH_MODEL_GEN_POWER_LEVEL_CLI(cli_pub, cli_data) \ - BLE_MESH_MODEL(BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI, \ - gen_power_level_cli_op, cli_pub, cli_data) + BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI, \ + bt_mesh_gen_power_level_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb) typedef bt_mesh_client_user_data_t bt_mesh_gen_power_level_client_t; @@ -226,7 +229,7 @@ struct bt_mesh_gen_power_range_set { }; /* Generic Battery Client Model Context */ -extern const struct bt_mesh_model_op gen_battery_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_battery_cli_op[]; /** @def BLE_MESH_MODEL_GEN_BATTERY_CLI * @@ -239,8 +242,8 @@ extern const struct bt_mesh_model_op gen_battery_cli_op[]; * @return New generic battery client model instance. */ #define BLE_MESH_MODEL_GEN_BATTERY_CLI(cli_pub, cli_data) \ - BLE_MESH_MODEL(BLE_MESH_MODEL_ID_GEN_BATTERY_CLI, \ - gen_battery_cli_op, cli_pub, cli_data) + BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_BATTERY_CLI, \ + bt_mesh_gen_battery_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb) typedef bt_mesh_client_user_data_t bt_mesh_gen_battery_client_t; @@ -252,7 +255,7 @@ struct bt_mesh_gen_battery_status { }; /* Generic Location Client Model Context */ -extern const struct bt_mesh_model_op gen_location_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_location_cli_op[]; /** @def BLE_MESH_MODEL_GEN_LOCATION_CLI * @@ -265,8 +268,8 @@ extern const struct bt_mesh_model_op gen_location_cli_op[]; * @return New generic location client model instance. */ #define BLE_MESH_MODEL_GEN_LOCATION_CLI(cli_pub, cli_data) \ - BLE_MESH_MODEL(BLE_MESH_MODEL_ID_GEN_LOCATION_CLI, \ - gen_location_cli_op, cli_pub, cli_data) + BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_LOCATION_CLI, \ + bt_mesh_gen_location_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb) typedef bt_mesh_client_user_data_t bt_mesh_gen_location_client_t; @@ -299,7 +302,7 @@ struct bt_mesh_gen_loc_local_set { }; /* Generic Property Client Model Context */ -extern const struct bt_mesh_model_op gen_property_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_gen_property_cli_op[]; /** @def BLE_MESH_MODEL_GEN_LOCATION_CLI * @@ -312,8 +315,8 @@ extern const struct bt_mesh_model_op gen_property_cli_op[]; * @return New generic location client model instance. */ #define BLE_MESH_MODEL_GEN_PROPERTY_CLI(cli_pub, cli_data) \ - BLE_MESH_MODEL(BLE_MESH_MODEL_ID_GEN_PROP_CLI, \ - gen_property_cli_op, cli_pub, cli_data) + BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_GEN_PROP_CLI, \ + bt_mesh_gen_property_cli_op, cli_pub, cli_data, &bt_mesh_generic_client_cb) typedef bt_mesh_client_user_data_t bt_mesh_gen_property_client_t; @@ -386,168 +389,6 @@ struct bt_mesh_gen_client_properties_get { u16_t client_property_id; /* A starting Client Property ID present within an element */ }; -/** - * @brief This function is called to initialize generic onoff client model user_data. - * - * @param[in] model: Pointer to generic onoff client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_gen_onoff_cli_init(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to initialize generic level client model user_data. - * - * @param[in] model: Pointer to generic level client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_gen_level_cli_init(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to initialize generic default transition time - * client model user_data. - * - * @param[in] model: Pointer to generic default transition time client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_gen_def_trans_time_cli_init(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to initialize generic power onoff client model user_data. - * - * @param[in] model: Pointer to generic power onoff client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_gen_pwr_onoff_cli_init(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to initialize generic power level client model user_data. - * - * @param[in] model: Pointer to generic power level client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_gen_pwr_level_cli_init(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to initialize generic battery client model user_data. - * - * @param[in] model: Pointer to generic battery client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_gen_battery_cli_init(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to initialize generic location client model user_data. - * - * @param[in] model: Pointer to generic location client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_gen_location_cli_init(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to initialize generic property client model user_data. - * - * @param[in] model: Pointer to generic property client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_gen_property_cli_init(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to de-initialize generic onoff client model user_data. - * - * @param[in] model: Pointer to generic onoff client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_gen_onoff_cli_deinit(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to de-initialize generic level client model user_data. - * - * @param[in] model: Pointer to generic level client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_gen_level_cli_deinit(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to de-initialize generic default transition time - * client model user_data. - * - * @param[in] model: Pointer to generic default transition time client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_gen_def_trans_time_cli_deinit(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to de-initialize generic power onoff client model user_data. - * - * @param[in] model: Pointer to generic power onoff client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_gen_pwr_onoff_cli_deinit(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to de-initialize generic power level client model user_data. - * - * @param[in] model: Pointer to generic power level client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_gen_pwr_level_cli_deinit(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to de-initialize generic battery client model user_data. - * - * @param[in] model: Pointer to generic battery client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_gen_battery_cli_deinit(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to de-initialize generic location client model user_data. - * - * @param[in] model: Pointer to generic location client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_gen_location_cli_deinit(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to de-initialize generic property client model user_data. - * - * @param[in] model: Pointer to generic property client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_gen_property_cli_deinit(struct bt_mesh_model *model, bool primary); - /** * @brief This function is called to get generic states. * diff --git a/components/bt/esp_ble_mesh/mesh_models/client/include/lighting_client.h b/components/bt/esp_ble_mesh/mesh_models/client/include/lighting_client.h index 7a7e62c30..5f1f8a86c 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/include/lighting_client.h +++ b/components/bt/esp_ble_mesh/mesh_models/client/include/lighting_client.h @@ -29,8 +29,11 @@ extern "C" { typedef bt_mesh_client_user_data_t bt_mesh_light_client_t; typedef bt_mesh_client_internal_data_t light_internal_data_t; +/* Lighting Client Model Callback */ +extern const struct bt_mesh_model_cb bt_mesh_lighting_client_cb; + /* Light Lightness Client Model Context */ -extern const struct bt_mesh_model_op light_lightness_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_lightness_cli_op[]; /** @def BLE_MESH_MODEL_LIGHT_LIGHTNESS_CLI * @@ -43,8 +46,8 @@ extern const struct bt_mesh_model_op light_lightness_cli_op[]; * @return New light lightness client model instance. */ #define BLE_MESH_MODEL_LIGHT_LIGHTNESS_CLI(cli_pub, cli_data) \ - BLE_MESH_MODEL(BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI, \ - light_lightness_cli_op, cli_pub, cli_data) + BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI, \ + bt_mesh_light_lightness_cli_op, cli_pub, cli_data, &bt_mesh_lighting_client_cb) typedef bt_mesh_client_user_data_t bt_mesh_light_lightness_client_t; @@ -102,7 +105,7 @@ struct bt_mesh_light_lightness_range_set { }; /* Light CTL Client Model Context */ -extern const struct bt_mesh_model_op light_ctl_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_ctl_cli_op[]; /** @def BLE_MESH_MODEL_LIGHT_CTL_CLI * @@ -115,8 +118,8 @@ extern const struct bt_mesh_model_op light_ctl_cli_op[]; * @return New light CTL client model instance. */ #define BLE_MESH_MODEL_LIGHT_CTL_CLI(cli_pub, cli_data) \ - BLE_MESH_MODEL(BLE_MESH_MODEL_ID_LIGHT_CTL_CLI, \ - light_ctl_cli_op, cli_pub, cli_data) + BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_LIGHT_CTL_CLI, \ + bt_mesh_light_ctl_cli_op, cli_pub, cli_data, &bt_mesh_lighting_client_cb) typedef bt_mesh_client_user_data_t bt_mesh_light_ctl_client_t; @@ -181,7 +184,7 @@ struct bt_mesh_light_ctl_default_set { }; /* Light HSL Client Model Context */ -extern const struct bt_mesh_model_op light_hsl_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_hsl_cli_op[]; /** @def BLE_MESH_MODEL_LIGHT_HSL_CLI * @@ -194,8 +197,8 @@ extern const struct bt_mesh_model_op light_hsl_cli_op[]; * @return New light HSL client model instance. */ #define BLE_MESH_MODEL_LIGHT_HSL_CLI(cli_pub, cli_data) \ - BLE_MESH_MODEL(BLE_MESH_MODEL_ID_LIGHT_HSL_CLI, \ - light_hsl_cli_op, cli_pub, cli_data) + BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_LIGHT_HSL_CLI, \ + bt_mesh_light_hsl_cli_op, cli_pub, cli_data, &bt_mesh_lighting_client_cb) typedef bt_mesh_client_user_data_t bt_mesh_light_hsl_client_t; @@ -283,7 +286,7 @@ struct bt_mesh_light_hsl_range_set { }; /* Light xyL Client Model Context */ -extern const struct bt_mesh_model_op light_xyl_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_xyl_cli_op[]; /** @def BLE_MESH_MODEL_LIGHT_XYL_CLI * @@ -296,8 +299,8 @@ extern const struct bt_mesh_model_op light_xyl_cli_op[]; * @return New light xyL client model instance. */ #define BLE_MESH_MODEL_LIGHT_XYL_CLI(cli_pub, cli_data) \ - BLE_MESH_MODEL(BLE_MESH_MODEL_ID_LIGHT_XYL_CLI, \ - light_xyl_cli_op, cli_pub, cli_data) + BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_LIGHT_XYL_CLI, \ + bt_mesh_light_xyl_cli_op, cli_pub, cli_data, &bt_mesh_lighting_client_cb) typedef bt_mesh_client_user_data_t bt_mesh_light_xyl_client_t; @@ -355,7 +358,7 @@ struct bt_mesh_light_xyl_range_set { }; /* Light LC Client Model Context */ -extern const struct bt_mesh_model_op light_lc_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_light_lc_cli_op[]; /** @def BLE_MESH_MODEL_LIGHT_LC_CLI * @@ -368,8 +371,8 @@ extern const struct bt_mesh_model_op light_lc_cli_op[]; * @return New light lc client model instance. */ #define BLE_MESH_MODEL_LIGHT_LC_CLI(cli_pub, cli_data) \ - BLE_MESH_MODEL(BLE_MESH_MODEL_ID_LIGHT_LC_CLI, \ - light_lc_cli_op, cli_pub, cli_data) + BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_LIGHT_LC_CLI, \ + bt_mesh_light_lc_cli_op, cli_pub, cli_data, &bt_mesh_lighting_client_cb) typedef bt_mesh_client_user_data_t bt_mesh_light_lc_client_t; @@ -418,106 +421,6 @@ struct bt_mesh_light_lc_property_set { struct net_buf_simple *light_lc_property_value; /* Raw value for the Light LC Property */ }; -/** - * @brief This function is called to initialize light lightness client model user_data. - * - * @param[in] model: Pointer to light lightness client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_light_lightness_cli_init(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to initialize light ctl client model user_data. - * - * @param[in] model: Pointer to light ctl client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_light_ctl_cli_init(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to initialize light hsl client model user_data. - * - * @param[in] model: Pointer to light hsl client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_light_hsl_cli_init(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to initialize light xyl client model user_data. - * - * @param[in] model: Pointer to light xyl client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_light_xyl_cli_init(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to initialize light lc client model user_data. - * - * @param[in] model: Pointer to light lc client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_light_lc_cli_init(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to de-initialize light lightness client model user_data. - * - * @param[in] model: Pointer to light lightness client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_light_lightness_cli_deinit(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to de-initialize light ctl client model user_data. - * - * @param[in] model: Pointer to light ctl client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_light_ctl_cli_deinit(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to de-initialize light hsl client model user_data. - * - * @param[in] model: Pointer to light hsl client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_light_hsl_cli_deinit(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to de-initialize light xyl client model user_data. - * - * @param[in] model: Pointer to light xyl client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_light_xyl_cli_deinit(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to de-initialize light lc client model user_data. - * - * @param[in] model: Pointer to light lc client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_light_lc_cli_deinit(struct bt_mesh_model *model, bool primary); - /** * @brief This function is called to get light states. * diff --git a/components/bt/esp_ble_mesh/mesh_models/client/include/sensor_client.h b/components/bt/esp_ble_mesh/mesh_models/client/include/sensor_client.h index 47448547f..70fb3989d 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/include/sensor_client.h +++ b/components/bt/esp_ble_mesh/mesh_models/client/include/sensor_client.h @@ -25,8 +25,11 @@ extern "C" { #endif +/* Sensor Client Model Callback */ +extern const struct bt_mesh_model_cb bt_mesh_sensor_client_cb; + /* Sensor Client Model Context */ -extern const struct bt_mesh_model_op sensor_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_sensor_cli_op[]; /** @def BLE_MESH_MODEL_SENSOR_CLI * @@ -39,8 +42,8 @@ extern const struct bt_mesh_model_op sensor_cli_op[]; * @return New sensor client model instance. */ #define BLE_MESH_MODEL_SENSOR_CLI(cli_pub, cli_data) \ - BLE_MESH_MODEL(BLE_MESH_MODEL_ID_SENSOR_CLI, \ - sensor_cli_op, cli_pub, cli_data) + BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_SENSOR_CLI, \ + bt_mesh_sensor_cli_op, cli_pub, cli_data, &bt_mesh_sensor_client_cb) typedef bt_mesh_client_user_data_t bt_mesh_sensor_client_t; typedef bt_mesh_client_internal_data_t sensor_internal_data_t; @@ -133,26 +136,6 @@ struct bt_mesh_sensor_series_get { struct net_buf_simple *raw_value_x2; /* Raw value identifying a ending column (C.1) */ }; -/** - * @brief This function is called to initialize sensor client model user_data. - * - * @param[in] model: Pointer to sensor client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_sensor_cli_init(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to de-initialize sensor client model user_data. - * - * @param[in] model: Pointer to sensor client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_sensor_cli_deinit(struct bt_mesh_model *model, bool primary); - /** * @brief This function is called to get sensor states. * diff --git a/components/bt/esp_ble_mesh/mesh_models/client/include/time_scene_client.h b/components/bt/esp_ble_mesh/mesh_models/client/include/time_scene_client.h index ee741c530..78cce2cbb 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/include/time_scene_client.h +++ b/components/bt/esp_ble_mesh/mesh_models/client/include/time_scene_client.h @@ -29,8 +29,11 @@ extern "C" { 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 Scene Client Model Callback */ +extern const struct bt_mesh_model_cb bt_mesh_time_scene_client_cb; + /* Time Client Model Context */ -extern const struct bt_mesh_model_op time_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_time_cli_op[]; /** @def BLE_MESH_MODEL_TIME_CLI * @@ -43,8 +46,8 @@ extern const struct bt_mesh_model_op time_cli_op[]; * @return New time client model instance. */ #define BLE_MESH_MODEL_TIME_CLI(cli_pub, cli_data) \ - BLE_MESH_MODEL(BLE_MESH_MODEL_ID_TIME_CLI, \ - time_cli_op, cli_pub, cli_data) + BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_TIME_CLI, \ + bt_mesh_time_cli_op, cli_pub, cli_data, &bt_mesh_time_scene_client_cb) typedef bt_mesh_client_user_data_t bt_mesh_time_client_t; @@ -100,7 +103,7 @@ struct bt_mesh_time_role_set { }; /* Scene Client Model Context */ -extern const struct bt_mesh_model_op scene_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_scene_cli_op[]; /** @def BLE_MESH_MODEL_SCENE_CLI * @@ -113,8 +116,8 @@ extern const struct bt_mesh_model_op scene_cli_op[]; * @return New scene client model instance. */ #define BLE_MESH_MODEL_SCENE_CLI(cli_pub, cli_data) \ - BLE_MESH_MODEL(BLE_MESH_MODEL_ID_SCENE_CLI, \ - scene_cli_op, cli_pub, cli_data) + BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_SCENE_CLI, \ + bt_mesh_scene_cli_op, cli_pub, cli_data, &bt_mesh_time_scene_client_cb) typedef bt_mesh_client_user_data_t bt_mesh_scene_client_t; @@ -149,7 +152,7 @@ struct bt_mesh_scene_delete { }; /* Scheduler Client Model Context */ -extern const struct bt_mesh_model_op scheduler_cli_op[]; +extern const struct bt_mesh_model_op bt_mesh_scheduler_cli_op[]; /** @def BLE_MESH_MODEL_SCHEDULER_CLI * @@ -162,8 +165,8 @@ extern const struct bt_mesh_model_op scheduler_cli_op[]; * @return New scheduler client model instance. */ #define BLE_MESH_MODEL_SCHEDULER_CLI(cli_pub, cli_data) \ - BLE_MESH_MODEL(BLE_MESH_MODEL_ID_SCHEDULER_CLI, \ - scheduler_cli_op, cli_pub, cli_data) + BLE_MESH_MODEL_CB(BLE_MESH_MODEL_ID_SCHEDULER_CLI, \ + bt_mesh_scheduler_cli_op, cli_pub, cli_data, &bt_mesh_time_scene_client_cb) typedef bt_mesh_client_user_data_t bt_mesh_scheduler_client_t; @@ -203,66 +206,6 @@ struct bt_mesh_scheduler_act_set { u16_t scene_number; /* Transition time for this action */ }; -/** - * @brief This function is called to initialize time client model user_data. - * - * @param[in] model: Pointer to time client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_time_cli_init(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to initialize scene client model user_data. - * - * @param[in] model: Pointer to scene client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_scene_cli_init(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to initialize scheduler client model user_data. - * - * @param[in] model: Pointer to scheduler client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_scheduler_cli_init(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to de-initialize time client model user_data. - * - * @param[in] model: Pointer to time client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_time_cli_deinit(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to de-initialize scene client model user_data. - * - * @param[in] model: Pointer to scene client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_scene_cli_deinit(struct bt_mesh_model *model, bool primary); - -/** - * @brief This function is called to de-initialize scheduler client model user_data. - * - * @param[in] model: Pointer to scheduler client model - * @param[in] primary: Whether belongs to primary element - * - * @return Zero-success, other-fail - */ -int bt_mesh_scheduler_cli_deinit(struct bt_mesh_model *model, bool primary); - /** * @brief This function is called to get scene states. * diff --git a/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c b/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c index 45454afbf..eaf96b01a 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/lighting_client.c @@ -726,7 +726,7 @@ static void light_status(struct bt_mesh_model *model, return; } -const struct bt_mesh_model_op light_lightness_cli_op[] = { +const struct bt_mesh_model_op bt_mesh_light_lightness_cli_op[] = { { BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS, 2, light_status }, { BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS, 2, light_status }, { BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_STATUS, 2, light_status }, @@ -735,7 +735,7 @@ const struct bt_mesh_model_op light_lightness_cli_op[] = { BLE_MESH_MODEL_OP_END, }; -const struct bt_mesh_model_op light_ctl_cli_op[] = { +const struct bt_mesh_model_op bt_mesh_light_ctl_cli_op[] = { { BLE_MESH_MODEL_OP_LIGHT_CTL_STATUS, 4, light_status }, { BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS, 4, light_status }, { BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS, 5, light_status }, @@ -743,7 +743,7 @@ const struct bt_mesh_model_op light_ctl_cli_op[] = { BLE_MESH_MODEL_OP_END, }; -const struct bt_mesh_model_op light_hsl_cli_op[] = { +const struct bt_mesh_model_op bt_mesh_light_hsl_cli_op[] = { { BLE_MESH_MODEL_OP_LIGHT_HSL_STATUS, 6, light_status }, { BLE_MESH_MODEL_OP_LIGHT_HSL_TARGET_STATUS, 6, light_status }, { BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS, 2, light_status }, @@ -753,7 +753,7 @@ const struct bt_mesh_model_op light_hsl_cli_op[] = { BLE_MESH_MODEL_OP_END, }; -const struct bt_mesh_model_op light_xyl_cli_op[] = { +const struct bt_mesh_model_op bt_mesh_light_xyl_cli_op[] = { { BLE_MESH_MODEL_OP_LIGHT_XYL_STATUS, 6, light_status }, { BLE_MESH_MODEL_OP_LIGHT_XYL_TARGET_STATUS, 6, light_status }, { BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_STATUS, 6, light_status }, @@ -761,7 +761,7 @@ const struct bt_mesh_model_op light_xyl_cli_op[] = { BLE_MESH_MODEL_OP_END, }; -const struct bt_mesh_model_op light_lc_cli_op[] = { +const struct bt_mesh_model_op bt_mesh_light_lc_cli_op[] = { { BLE_MESH_MODEL_OP_LIGHT_LC_MODE_STATUS, 1, light_status }, { BLE_MESH_MODEL_OP_LIGHT_LC_OM_STATUS, 1, light_status }, { BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS, 1, light_status }, @@ -1324,21 +1324,19 @@ int bt_mesh_light_client_set_state(bt_mesh_client_common_param_t *common, void * return light_set_state(common, set, length, need_ack); } -static int light_client_init(struct bt_mesh_model *model, bool primary) +static int lighting_client_init(struct bt_mesh_model *model) { light_internal_data_t *internal = NULL; bt_mesh_light_client_t *client = NULL; - BT_DBG("primary %u", primary); - if (!model) { - BT_ERR("%s, Invalid parameter", __func__); + BT_ERR("Invalid Lighting client model"); return -EINVAL; } client = (bt_mesh_light_client_t *)model->user_data; if (!client) { - BT_ERR("Invalid Lighting client user data"); + BT_ERR("No Lighting client context provided"); return -EINVAL; } @@ -1364,43 +1362,18 @@ static int light_client_init(struct bt_mesh_model *model, bool primary) return 0; } -int bt_mesh_light_lightness_cli_init(struct bt_mesh_model *model, bool primary) -{ - return light_client_init(model, primary); -} - -int bt_mesh_light_ctl_cli_init(struct bt_mesh_model *model, bool primary) -{ - return light_client_init(model, primary); -} - -int bt_mesh_light_hsl_cli_init(struct bt_mesh_model *model, bool primary) -{ - return light_client_init(model, primary); -} - -int bt_mesh_light_xyl_cli_init(struct bt_mesh_model *model, bool primary) -{ - return light_client_init(model, primary); -} - -int bt_mesh_light_lc_cli_init(struct bt_mesh_model *model, bool primary) -{ - return light_client_init(model, primary); -} - -static int light_client_deinit(struct bt_mesh_model *model, bool primary) +static int lighting_client_deinit(struct bt_mesh_model *model) { bt_mesh_light_client_t *client = NULL; if (!model) { - BT_ERR("%s, Invalid parameter", __func__); + BT_ERR("Invalid Lighting client model"); return -EINVAL; } client = (bt_mesh_light_client_t *)model->user_data; if (!client) { - BT_ERR("Invalid Lighting client user data"); + BT_ERR("No Lighting client context provided"); return -EINVAL; } @@ -1418,27 +1391,7 @@ static int light_client_deinit(struct bt_mesh_model *model, bool primary) return 0; } -int bt_mesh_light_lightness_cli_deinit(struct bt_mesh_model *model, bool primary) -{ - return light_client_deinit(model, primary); -} - -int bt_mesh_light_ctl_cli_deinit(struct bt_mesh_model *model, bool primary) -{ - return light_client_deinit(model, primary); -} - -int bt_mesh_light_hsl_cli_deinit(struct bt_mesh_model *model, bool primary) -{ - return light_client_deinit(model, primary); -} - -int bt_mesh_light_xyl_cli_deinit(struct bt_mesh_model *model, bool primary) -{ - return light_client_deinit(model, primary); -} - -int bt_mesh_light_lc_cli_deinit(struct bt_mesh_model *model, bool primary) -{ - return light_client_deinit(model, primary); -} \ No newline at end of file +const struct bt_mesh_model_cb bt_mesh_lighting_client_cb = { + .init = lighting_client_init, + .deinit = lighting_client_deinit, +}; diff --git a/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c b/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c index c003c0183..47ee42e2c 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/sensor_client.c @@ -341,7 +341,7 @@ static void sensor_status(struct bt_mesh_model *model, return; } -const struct bt_mesh_model_op sensor_cli_op[] = { +const struct bt_mesh_model_op bt_mesh_sensor_cli_op[] = { { BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS, 0, sensor_status }, { BLE_MESH_MODEL_OP_SENSOR_CADENCE_STATUS, 2, sensor_status }, { BLE_MESH_MODEL_OP_SENSOR_SETTINGS_STATUS, 2, sensor_status }, @@ -574,21 +574,19 @@ int bt_mesh_sensor_client_set_state(bt_mesh_client_common_param_t *common, void return sensor_act_state(common, set, length, need_ack); } -int bt_mesh_sensor_cli_init(struct bt_mesh_model *model, bool primary) +static int sensor_client_init(struct bt_mesh_model *model) { sensor_internal_data_t *internal = NULL; bt_mesh_sensor_client_t *client = NULL; - BT_DBG("primary %u", primary); - if (!model) { - BT_ERR("%s, Invalid parameter", __func__); + BT_ERR("Invalid Sensor client model"); return -EINVAL; } client = (bt_mesh_sensor_client_t *)model->user_data; if (!client) { - BT_ERR("Invalid Sensor client user data"); + BT_ERR("No Sensor client context provided"); return -EINVAL; } @@ -614,18 +612,18 @@ int bt_mesh_sensor_cli_init(struct bt_mesh_model *model, bool primary) return 0; } -int bt_mesh_sensor_cli_deinit(struct bt_mesh_model *model, bool primary) +static int sensor_client_deinit(struct bt_mesh_model *model) { bt_mesh_sensor_client_t *client = NULL; if (!model) { - BT_ERR("%s, Invalid parameter", __func__); + BT_ERR("Invalid Sensor client model"); return -EINVAL; } client = (bt_mesh_sensor_client_t *)model->user_data; if (!client) { - BT_ERR("Invalid Sensor client user data"); + BT_ERR("No Sensor client context provided"); return -EINVAL; } @@ -641,4 +639,9 @@ int bt_mesh_sensor_cli_deinit(struct bt_mesh_model *model, bool primary) bt_mesh_sensor_client_mutex_free(); return 0; -} \ No newline at end of file +} + +const struct bt_mesh_model_cb bt_mesh_sensor_client_cb = { + .init = sensor_client_init, + .deinit = sensor_client_deinit, +}; diff --git a/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c b/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c index 201d8b51f..d99a685fc 100644 --- a/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c +++ b/components/bt/esp_ble_mesh/mesh_models/client/time_scene_client.c @@ -349,7 +349,7 @@ static void time_scene_status(struct bt_mesh_model *model, return; } -const struct bt_mesh_model_op time_cli_op[] = { +const struct bt_mesh_model_op bt_mesh_time_cli_op[] = { { BLE_MESH_MODEL_OP_TIME_STATUS, 5, time_scene_status }, { BLE_MESH_MODEL_OP_TIME_ZONE_STATUS, 7, time_scene_status }, { BLE_MESH_MODEL_OP_TAI_UTC_DELTA_STATUS, 9, time_scene_status }, @@ -357,13 +357,13 @@ const struct bt_mesh_model_op time_cli_op[] = { BLE_MESH_MODEL_OP_END, }; -const struct bt_mesh_model_op scene_cli_op[] = { +const struct bt_mesh_model_op bt_mesh_scene_cli_op[] = { { BLE_MESH_MODEL_OP_SCENE_STATUS, 3, time_scene_status }, { BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS, 3, time_scene_status }, BLE_MESH_MODEL_OP_END, }; -const struct bt_mesh_model_op scheduler_cli_op[] = { +const struct bt_mesh_model_op bt_mesh_scheduler_cli_op[] = { { BLE_MESH_MODEL_OP_SCHEDULER_STATUS, 2, time_scene_status }, { BLE_MESH_MODEL_OP_SCHEDULER_ACT_STATUS, 10, time_scene_status }, BLE_MESH_MODEL_OP_END, @@ -630,21 +630,19 @@ int bt_mesh_time_scene_client_set_state(bt_mesh_client_common_param_t *common, v return time_scene_set_state(common, set, length, need_ack); } -static int time_scene_client_init(struct bt_mesh_model *model, bool primary) +static int time_scene_client_init(struct bt_mesh_model *model) { time_scene_internal_data_t *internal = NULL; bt_mesh_time_scene_client_t *client = NULL; - BT_DBG("primary %u", primary); - if (!model) { - BT_ERR("%s, Invalid parameter", __func__); + BT_ERR("Invalid Time Scene client model"); return -EINVAL; } client = (bt_mesh_time_scene_client_t *)model->user_data; if (!client) { - BT_ERR("Invalid Time Scene client user data"); + BT_ERR("No Time Scene client context provided"); return -EINVAL; } @@ -670,33 +668,18 @@ static int time_scene_client_init(struct bt_mesh_model *model, bool primary) return 0; } -int bt_mesh_time_cli_init(struct bt_mesh_model *model, bool primary) -{ - return time_scene_client_init(model, primary); -} - -int bt_mesh_scene_cli_init(struct bt_mesh_model *model, bool primary) -{ - return time_scene_client_init(model, primary); -} - -int bt_mesh_scheduler_cli_init(struct bt_mesh_model *model, bool primary) -{ - return time_scene_client_init(model, primary); -} - -static int time_scene_client_deinit(struct bt_mesh_model *model, bool primary) +static int time_scene_client_deinit(struct bt_mesh_model *model) { bt_mesh_time_scene_client_t *client = NULL; if (!model) { - BT_ERR("%s, Invalid parameter", __func__); + BT_ERR("Invalid Time Scene client model"); return -EINVAL; } client = (bt_mesh_time_scene_client_t *)model->user_data; if (!client) { - BT_ERR("Invalid Time Scene client user data"); + BT_ERR("No Time Scene client context provided"); return -EINVAL; } @@ -714,17 +697,7 @@ static int time_scene_client_deinit(struct bt_mesh_model *model, bool primary) return 0; } -int bt_mesh_time_cli_deinit(struct bt_mesh_model *model, bool primary) -{ - return time_scene_client_deinit(model, primary); -} - -int bt_mesh_scene_cli_deinit(struct bt_mesh_model *model, bool primary) -{ - return time_scene_client_deinit(model, primary); -} - -int bt_mesh_scheduler_cli_deinit(struct bt_mesh_model *model, bool primary) -{ - return time_scene_client_deinit(model, primary); -} \ No newline at end of file +const struct bt_mesh_model_cb bt_mesh_time_scene_client_cb = { + .init = time_scene_client_init, + .deinit = time_scene_client_deinit, +}; diff --git a/components/bt/esp_ble_mesh/mesh_models/server/generic_server.c b/components/bt/esp_ble_mesh/mesh_models/server/generic_server.c index 6cbf85dc6..3de3a1545 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/generic_server.c +++ b/components/bt/esp_ble_mesh/mesh_models/server/generic_server.c @@ -2207,7 +2207,7 @@ static void gen_client_prop_get(struct bt_mesh_model *model, /* message handlers (End) */ /* Mapping of message handlers for Generic OnOff Server (0x1000) */ -const struct bt_mesh_model_op gen_onoff_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_onoff_srv_op[] = { { BLE_MESH_MODEL_OP_GEN_ONOFF_GET, 0, gen_onoff_get }, { BLE_MESH_MODEL_OP_GEN_ONOFF_SET, 2, gen_onoff_set }, { BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK, 2, gen_onoff_set }, @@ -2215,7 +2215,7 @@ const struct bt_mesh_model_op gen_onoff_srv_op[] = { }; /* Mapping of message handlers for Generic Level Server (0x1002) */ -const struct bt_mesh_model_op gen_level_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_level_srv_op[] = { { BLE_MESH_MODEL_OP_GEN_LEVEL_GET, 0, gen_level_get }, { BLE_MESH_MODEL_OP_GEN_LEVEL_SET, 3, gen_level_set }, { BLE_MESH_MODEL_OP_GEN_LEVEL_SET_UNACK, 3, gen_level_set }, @@ -2227,7 +2227,7 @@ const struct bt_mesh_model_op gen_level_srv_op[] = { }; /* Mapping of message handlers for Generic Default TT Server (0x1004) */ -const struct bt_mesh_model_op gen_def_trans_time_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_def_trans_time_srv_op[] = { { BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_GET, 0, gen_def_trans_time_get }, { BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET, 1, gen_def_trans_time_set }, { BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET_UNACK, 1, gen_def_trans_time_set }, @@ -2235,20 +2235,20 @@ const struct bt_mesh_model_op gen_def_trans_time_srv_op[] = { }; /* Mapping of message handlers for Generic Power OnOff Server (0x1006) */ -const struct bt_mesh_model_op gen_power_onoff_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_power_onoff_srv_op[] = { { BLE_MESH_MODEL_OP_GEN_ONPOWERUP_GET, 0, gen_onpowerup_get }, BLE_MESH_MODEL_OP_END, }; /* Mapping of message handlers for Generic Power OnOff Setup Server (0x1007) */ -const struct bt_mesh_model_op gen_power_onoff_setup_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_power_onoff_setup_srv_op[] = { { BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET, 1, gen_onpowerup_set }, { BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET_UNACK, 1, gen_onpowerup_set }, BLE_MESH_MODEL_OP_END, }; /* Mapping of message handlers for Generic Power Level Server (0x1009) */ -const struct bt_mesh_model_op gen_power_level_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_power_level_srv_op[] = { { BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_GET, 0, gen_power_level_get }, { BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET, 3, gen_power_level_set }, { BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET_UNACK, 3, gen_power_level_set }, @@ -2259,7 +2259,7 @@ const struct bt_mesh_model_op gen_power_level_srv_op[] = { }; /* Mapping of message handlers for Generic Power Level Setup Server (0x100A) */ -const struct bt_mesh_model_op gen_power_level_setup_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_power_level_setup_srv_op[] = { { BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET, 2, gen_power_default_set }, { BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET_UNACK, 2, gen_power_default_set }, { BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET, 4, gen_power_range_set }, @@ -2268,20 +2268,20 @@ const struct bt_mesh_model_op gen_power_level_setup_srv_op[] = { }; /* Mapping of message handlers for Generic Battery Server (0x100C) */ -const struct bt_mesh_model_op gen_battery_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_battery_srv_op[] = { { BLE_MESH_MODEL_OP_GEN_BATTERY_GET, 0, gen_battery_get }, BLE_MESH_MODEL_OP_END, }; /* Mapping of message handlers for Generic Location Server (0x100E) */ -const struct bt_mesh_model_op gen_location_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_location_srv_op[] = { { BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_GET, 0, gen_location_get }, { BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_GET, 0, gen_location_get }, BLE_MESH_MODEL_OP_END, }; /* Mapping of message handlers for Generic Location Setup Server (0x100F) */ -const struct bt_mesh_model_op gen_location_setup_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_location_setup_srv_op[] = { { BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET, 10, gen_location_set }, { BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET_UNACK, 10, gen_location_set }, { BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET, 9, gen_location_set }, @@ -2290,7 +2290,7 @@ const struct bt_mesh_model_op gen_location_setup_srv_op[] = { }; /* Mapping of message handlers for Generic User Property Server (0x1013) */ -const struct bt_mesh_model_op gen_user_prop_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_user_prop_srv_op[] = { { BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET, 0, gen_user_prop_get }, { BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET, 2, gen_user_prop_get }, { BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET, 3, gen_user_prop_set }, @@ -2299,7 +2299,7 @@ const struct bt_mesh_model_op gen_user_prop_srv_op[] = { }; /* Mapping of message handlers for Generic Admin Property Server (0x1011) */ -const struct bt_mesh_model_op gen_admin_prop_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_admin_prop_srv_op[] = { { BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET, 0, gen_admin_prop_get }, { BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET, 2, gen_admin_prop_get }, { BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET, 4, gen_admin_prop_set }, @@ -2308,7 +2308,7 @@ const struct bt_mesh_model_op gen_admin_prop_srv_op[] = { }; /* Mapping of message handlers for Generic Manufacturer Property Server (0x1012) */ -const struct bt_mesh_model_op gen_manu_prop_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_manu_prop_srv_op[] = { { BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_GET, 0, gen_manu_prop_get }, { BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET, 2, gen_manu_prop_get }, { BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET, 3, gen_manu_prop_set }, @@ -2317,7 +2317,7 @@ const struct bt_mesh_model_op gen_manu_prop_srv_op[] = { }; /* Mapping of message handlers for Generic Client Property Server (0x1014) */ -const struct bt_mesh_model_op gen_client_prop_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_gen_client_prop_srv_op[] = { { BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET, 2, gen_client_prop_get }, BLE_MESH_MODEL_OP_END, }; @@ -2475,7 +2475,7 @@ static int generic_server_init(struct bt_mesh_model *model) return 0; } -int bt_mesh_gen_onoff_srv_init(struct bt_mesh_model *model, bool primary) +static int gen_onoff_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic OnOff Server has no publication support"); @@ -2485,7 +2485,7 @@ int bt_mesh_gen_onoff_srv_init(struct bt_mesh_model *model, bool primary) return generic_server_init(model); } -int bt_mesh_gen_level_srv_init(struct bt_mesh_model *model, bool primary) +static int gen_level_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic Level Server has no publication support"); @@ -2495,7 +2495,7 @@ int bt_mesh_gen_level_srv_init(struct bt_mesh_model *model, bool primary) return generic_server_init(model); } -int bt_mesh_gen_def_trans_time_srv_init(struct bt_mesh_model *model, bool primary) +static int gen_def_trans_time_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic Default Trans Time Server has no publication support"); @@ -2505,7 +2505,7 @@ int bt_mesh_gen_def_trans_time_srv_init(struct bt_mesh_model *model, bool primar return generic_server_init(model); } -int bt_mesh_gen_power_onoff_srv_init(struct bt_mesh_model *model, bool primary) +static int gen_power_onoff_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic Power OnOff Server has no publication support"); @@ -2523,12 +2523,12 @@ int bt_mesh_gen_power_onoff_srv_init(struct bt_mesh_model *model, bool primary) return generic_server_init(model); } -int bt_mesh_gen_power_onoff_setup_srv_init(struct bt_mesh_model *model, bool primary) +static int gen_power_onoff_setup_srv_init(struct bt_mesh_model *model) { return generic_server_init(model); } -int bt_mesh_gen_power_level_srv_init(struct bt_mesh_model *model, bool primary) +static int gen_power_level_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic Power Level Server has no publication support"); @@ -2546,12 +2546,12 @@ int bt_mesh_gen_power_level_srv_init(struct bt_mesh_model *model, bool primary) return generic_server_init(model); } -int bt_mesh_gen_power_level_setup_srv_init(struct bt_mesh_model *model, bool primary) +static int gen_power_level_setup_srv_init(struct bt_mesh_model *model) { return generic_server_init(model); } -int bt_mesh_gen_battery_srv_init(struct bt_mesh_model *model, bool primary) +static int gen_battery_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic Battery Server has no publication support"); @@ -2561,7 +2561,7 @@ int bt_mesh_gen_battery_srv_init(struct bt_mesh_model *model, bool primary) return generic_server_init(model); } -int bt_mesh_gen_location_srv_init(struct bt_mesh_model *model, bool primary) +static int gen_location_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic Location Server has no publication support"); @@ -2571,7 +2571,7 @@ int bt_mesh_gen_location_srv_init(struct bt_mesh_model *model, bool primary) return generic_server_init(model); } -int bt_mesh_gen_location_setup_srv_init(struct bt_mesh_model *model, bool primary) +static int gen_location_setup_srv_init(struct bt_mesh_model *model) { /* When this model is present on an Element, the corresponding Generic * Location Setup Server model shall also be present. @@ -2584,7 +2584,7 @@ int bt_mesh_gen_location_setup_srv_init(struct bt_mesh_model *model, bool primar return generic_server_init(model); } -int bt_mesh_gen_user_prop_srv_init(struct bt_mesh_model *model, bool primary) +static int gen_user_prop_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic User Property Server has no publication support"); @@ -2594,7 +2594,7 @@ int bt_mesh_gen_user_prop_srv_init(struct bt_mesh_model *model, bool primary) return generic_server_init(model); } -int bt_mesh_gen_admin_prop_srv_init(struct bt_mesh_model *model, bool primary) +static int gen_admin_prop_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic Admin Property Server has no publication support"); @@ -2604,7 +2604,7 @@ int bt_mesh_gen_admin_prop_srv_init(struct bt_mesh_model *model, bool primary) return generic_server_init(model); } -int bt_mesh_gen_manu_prop_srv_init(struct bt_mesh_model *model, bool primary) +static int gen_manu_prop_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic Manufacturer Property Server has no publication support"); @@ -2614,7 +2614,7 @@ int bt_mesh_gen_manu_prop_srv_init(struct bt_mesh_model *model, bool primary) return generic_server_init(model); } -int bt_mesh_gen_client_prop_srv_init(struct bt_mesh_model *model, bool primary) +static int gen_client_prop_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic Client Property Server has no publication support"); @@ -2670,7 +2670,7 @@ static int generic_server_deinit(struct bt_mesh_model *model) return 0; } -int bt_mesh_gen_onoff_srv_deinit(struct bt_mesh_model *model, bool primary) +static int gen_onoff_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic OnOff Server has no publication support"); @@ -2680,7 +2680,7 @@ int bt_mesh_gen_onoff_srv_deinit(struct bt_mesh_model *model, bool primary) return generic_server_deinit(model); } -int bt_mesh_gen_level_srv_deinit(struct bt_mesh_model *model, bool primary) +static int gen_level_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic Level Server has no publication support"); @@ -2690,7 +2690,7 @@ int bt_mesh_gen_level_srv_deinit(struct bt_mesh_model *model, bool primary) return generic_server_deinit(model); } -int bt_mesh_gen_def_trans_time_srv_deinit(struct bt_mesh_model *model, bool primary) +static int gen_def_trans_time_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic Default Trans Time Server has no publication support"); @@ -2700,7 +2700,7 @@ int bt_mesh_gen_def_trans_time_srv_deinit(struct bt_mesh_model *model, bool prim return generic_server_deinit(model); } -int bt_mesh_gen_power_onoff_srv_deinit(struct bt_mesh_model *model, bool primary) +static int gen_power_onoff_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic Power OnOff Server has no publication support"); @@ -2710,12 +2710,12 @@ int bt_mesh_gen_power_onoff_srv_deinit(struct bt_mesh_model *model, bool primary return generic_server_deinit(model); } -int bt_mesh_gen_power_onoff_setup_srv_deinit(struct bt_mesh_model *model, bool primary) +static int gen_power_onoff_setup_srv_deinit(struct bt_mesh_model *model) { return generic_server_deinit(model); } -int bt_mesh_gen_power_level_srv_deinit(struct bt_mesh_model *model, bool primary) +static int gen_power_level_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic Power Level Server has no publication support"); @@ -2725,12 +2725,12 @@ int bt_mesh_gen_power_level_srv_deinit(struct bt_mesh_model *model, bool primary return generic_server_deinit(model); } -int bt_mesh_gen_power_level_setup_srv_deinit(struct bt_mesh_model *model, bool primary) +static int gen_power_level_setup_srv_deinit(struct bt_mesh_model *model) { return generic_server_deinit(model); } -int bt_mesh_gen_battery_srv_deinit(struct bt_mesh_model *model, bool primary) +static int gen_battery_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic Battery Server has no publication support"); @@ -2740,7 +2740,7 @@ int bt_mesh_gen_battery_srv_deinit(struct bt_mesh_model *model, bool primary) return generic_server_deinit(model); } -int bt_mesh_gen_location_srv_deinit(struct bt_mesh_model *model, bool primary) +static int gen_location_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic Location Server has no publication support"); @@ -2750,12 +2750,12 @@ int bt_mesh_gen_location_srv_deinit(struct bt_mesh_model *model, bool primary) return generic_server_deinit(model); } -int bt_mesh_gen_location_setup_srv_deinit(struct bt_mesh_model *model, bool primary) +static int gen_location_setup_srv_deinit(struct bt_mesh_model *model) { return generic_server_deinit(model); } -int bt_mesh_gen_user_prop_srv_deinit(struct bt_mesh_model *model, bool primary) +static int gen_user_prop_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic User Property Server has no publication support"); @@ -2765,7 +2765,7 @@ int bt_mesh_gen_user_prop_srv_deinit(struct bt_mesh_model *model, bool primary) return generic_server_deinit(model); } -int bt_mesh_gen_admin_prop_srv_deinit(struct bt_mesh_model *model, bool primary) +static int gen_admin_prop_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic Admin Property Server has no publication support"); @@ -2775,7 +2775,7 @@ int bt_mesh_gen_admin_prop_srv_deinit(struct bt_mesh_model *model, bool primary) return generic_server_deinit(model); } -int bt_mesh_gen_manu_prop_srv_deinit(struct bt_mesh_model *model, bool primary) +static int gen_manu_prop_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic Manufacturer Property Server has no publication support"); @@ -2785,7 +2785,7 @@ int bt_mesh_gen_manu_prop_srv_deinit(struct bt_mesh_model *model, bool primary) return generic_server_deinit(model); } -int bt_mesh_gen_client_prop_srv_deinit(struct bt_mesh_model *model, bool primary) +static int gen_client_prop_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Generic Client Property Server has no publication support"); @@ -2793,4 +2793,74 @@ int bt_mesh_gen_client_prop_srv_deinit(struct bt_mesh_model *model, bool primary } return generic_server_deinit(model); -} \ No newline at end of file +} + +const struct bt_mesh_model_cb bt_mesh_gen_onoff_srv_cb = { + .init = gen_onoff_srv_init, + .deinit = gen_onoff_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_gen_level_srv_cb = { + .init = gen_level_srv_init, + .deinit = gen_level_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_gen_def_trans_time_srv_cb = { + .init = gen_def_trans_time_srv_init, + .deinit = gen_def_trans_time_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_gen_power_onoff_srv_cb = { + .init = gen_power_onoff_srv_init, + .deinit = gen_power_onoff_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_gen_power_onoff_setup_srv_cb = { + .init = gen_power_onoff_setup_srv_init, + .deinit = gen_power_onoff_setup_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_gen_power_level_srv_cb = { + .init = gen_power_level_srv_init, + .deinit = gen_power_level_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_gen_power_level_setup_srv_cb = { + .init = gen_power_level_setup_srv_init, + .deinit = gen_power_level_setup_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_gen_battery_srv_cb = { + .init = gen_battery_srv_init, + .deinit = gen_battery_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_gen_location_srv_cb = { + .init = gen_location_srv_init, + .deinit = gen_location_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_gen_location_setup_srv_cb = { + .init = gen_location_setup_srv_init, + .deinit = gen_location_setup_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_gen_user_prop_srv_cb = { + .init = gen_user_prop_srv_init, + .deinit = gen_user_prop_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_gen_admin_prop_srv_cb = { + .init = gen_admin_prop_srv_init, + .deinit = gen_admin_prop_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_gen_manu_prop_srv_cb = { + .init = gen_manu_prop_srv_init, + .deinit = gen_manu_prop_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_gen_client_prop_srv_cb = { + .init = gen_client_prop_srv_init, + .deinit = gen_client_prop_srv_deinit, +}; diff --git a/components/bt/esp_ble_mesh/mesh_models/server/include/generic_server.h b/components/bt/esp_ble_mesh/mesh_models/server/include/generic_server.h index 241f1112a..6ca0805be 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/include/generic_server.h +++ b/components/bt/esp_ble_mesh/mesh_models/server/include/generic_server.h @@ -360,36 +360,6 @@ void gen_level_publish(struct bt_mesh_model *model); void gen_onpowerup_publish(struct bt_mesh_model *model); void gen_power_level_publish(struct bt_mesh_model *model, u16_t opcode); -int bt_mesh_gen_onoff_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_level_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_def_trans_time_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_power_onoff_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_power_onoff_setup_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_power_level_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_power_level_setup_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_battery_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_location_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_location_setup_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_user_prop_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_admin_prop_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_manu_prop_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_client_prop_srv_init(struct bt_mesh_model *model, bool primary); - -int bt_mesh_gen_onoff_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_level_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_def_trans_time_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_power_onoff_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_power_onoff_setup_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_power_level_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_power_level_setup_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_battery_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_location_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_location_setup_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_user_prop_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_admin_prop_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_manu_prop_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_gen_client_prop_srv_deinit(struct bt_mesh_model *model, bool primary); - #ifdef __cplusplus } #endif diff --git a/components/bt/esp_ble_mesh/mesh_models/server/include/lighting_server.h b/components/bt/esp_ble_mesh/mesh_models/server/include/lighting_server.h index 34195dd0d..7f5bc348c 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/include/lighting_server.h +++ b/components/bt/esp_ble_mesh/mesh_models/server/include/lighting_server.h @@ -503,34 +503,6 @@ void light_hsl_publish(struct bt_mesh_model *model, u16_t opcode); void light_xyl_publish(struct bt_mesh_model *model, u16_t opcode); void light_lc_publish(struct bt_mesh_model *model, u16_t opcode); -int bt_mesh_light_lightness_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_lightness_setup_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_ctl_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_ctl_setup_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_ctl_temp_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_hsl_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_hsl_setup_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_hsl_hue_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_hsl_sat_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_xyl_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_xyl_setup_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_lc_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_lc_setup_srv_init(struct bt_mesh_model *model, bool primary); - -int bt_mesh_light_lightness_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_lightness_setup_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_ctl_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_ctl_setup_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_ctl_temp_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_hsl_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_hsl_setup_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_hsl_hue_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_hsl_sat_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_xyl_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_xyl_setup_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_lc_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_light_lc_setup_srv_deinit(struct bt_mesh_model *model, bool primary); - #ifdef __cplusplus } #endif diff --git a/components/bt/esp_ble_mesh/mesh_models/server/include/sensor_server.h b/components/bt/esp_ble_mesh/mesh_models/server/include/sensor_server.h index 8d7d6fe06..ca75d7d80 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/include/sensor_server.h +++ b/components/bt/esp_ble_mesh/mesh_models/server/include/sensor_server.h @@ -247,12 +247,6 @@ typedef union { } sensor_setting_set; } bt_mesh_sensor_server_recv_set_msg_t; -int bt_mesh_sensor_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_sensor_setup_srv_init(struct bt_mesh_model *model, bool primary); - -int bt_mesh_sensor_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_sensor_setup_srv_deinit(struct bt_mesh_model *model, bool primary); - #ifdef __cplusplus } #endif diff --git a/components/bt/esp_ble_mesh/mesh_models/server/include/time_scene_server.h b/components/bt/esp_ble_mesh/mesh_models/server/include/time_scene_server.h index dcd3efd71..6280bd76c 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/include/time_scene_server.h +++ b/components/bt/esp_ble_mesh/mesh_models/server/include/time_scene_server.h @@ -385,20 +385,6 @@ void bt_mesh_time_scene_server_unlock(void); void scene_publish(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, u16_t opcode); -int bt_mesh_time_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_time_setup_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_scene_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_scene_setup_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_scheduler_srv_init(struct bt_mesh_model *model, bool primary); -int bt_mesh_scheduler_setup_srv_init(struct bt_mesh_model *model, bool primary); - -int bt_mesh_time_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_time_setup_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_scene_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_scene_setup_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_scheduler_srv_deinit(struct bt_mesh_model *model, bool primary); -int bt_mesh_scheduler_setup_srv_deinit(struct bt_mesh_model *model, bool primary); - #ifdef __cplusplus } #endif diff --git a/components/bt/esp_ble_mesh/mesh_models/server/lighting_server.c b/components/bt/esp_ble_mesh/mesh_models/server/lighting_server.c index f09224c7b..a974c244d 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/lighting_server.c +++ b/components/bt/esp_ble_mesh/mesh_models/server/lighting_server.c @@ -2858,7 +2858,7 @@ static void light_lc_prop_set(struct bt_mesh_model *model, /* message handlers (End) */ /* Mapping of message handlers for Light Lightness Server (0x1300) */ -const struct bt_mesh_model_op light_lightness_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_light_lightness_srv_op[] = { { BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_GET, 0, light_lightness_get }, { BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET, 3, light_lightness_set }, { BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET_UNACK, 3, light_lightness_set }, @@ -2872,7 +2872,7 @@ const struct bt_mesh_model_op light_lightness_srv_op[] = { }; /* Mapping of message handlers for Light Lightness Setup Server (0x1301) */ -const struct bt_mesh_model_op light_lightness_setup_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_light_lightness_setup_srv_op[] = { { BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET, 2, light_lightness_default_set }, { BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET_UNACK, 2, light_lightness_default_set }, { BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET, 4, light_lightness_range_set }, @@ -2881,7 +2881,7 @@ const struct bt_mesh_model_op light_lightness_setup_srv_op[] = { }; /* Mapping of message handlers for Light CTL Server (0x1303) */ -const struct bt_mesh_model_op light_ctl_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_light_ctl_srv_op[] = { { BLE_MESH_MODEL_OP_LIGHT_CTL_GET, 0, light_ctl_get }, { BLE_MESH_MODEL_OP_LIGHT_CTL_SET, 7, light_ctl_set }, { BLE_MESH_MODEL_OP_LIGHT_CTL_SET_UNACK, 7, light_ctl_set }, @@ -2891,7 +2891,7 @@ const struct bt_mesh_model_op light_ctl_srv_op[] = { }; /* Mapping of message handlers for Light CTL Setup Server (0x1304) */ -const struct bt_mesh_model_op light_ctl_setup_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_light_ctl_setup_srv_op[] = { { BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET, 6, light_ctl_default_set }, { BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET_UNACK, 6, light_ctl_default_set }, { BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET, 4, light_ctl_temp_range_set }, @@ -2900,7 +2900,7 @@ const struct bt_mesh_model_op light_ctl_setup_srv_op[] = { }; /* Mapping of message handlers for Light CTL Temperature Server (0x1306) */ -const struct bt_mesh_model_op light_ctl_temp_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_light_ctl_temp_srv_op[] = { { BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_GET, 0, light_ctl_get }, { BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET, 5, light_ctl_temp_set }, { BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET_UNACK, 5, light_ctl_temp_set }, @@ -2908,7 +2908,7 @@ const struct bt_mesh_model_op light_ctl_temp_srv_op[] = { }; /* Mapping of message handlers for Light HSL Server (0x1307) */ -const struct bt_mesh_model_op light_hsl_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_light_hsl_srv_op[] = { { BLE_MESH_MODEL_OP_LIGHT_HSL_GET, 0, light_hsl_get }, { BLE_MESH_MODEL_OP_LIGHT_HSL_SET, 7, light_hsl_set }, { BLE_MESH_MODEL_OP_LIGHT_HSL_SET_UNACK, 7, light_hsl_set }, @@ -2919,7 +2919,7 @@ const struct bt_mesh_model_op light_hsl_srv_op[] = { }; /* Mapping of message handlers for Light HSL Setup Server (0x1308) */ -const struct bt_mesh_model_op light_hsl_setup_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_light_hsl_setup_srv_op[] = { { BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET, 6, light_hsl_default_set }, { BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET_UNACK, 6, light_hsl_default_set }, { BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET, 8, light_hsl_range_set }, @@ -2928,7 +2928,7 @@ const struct bt_mesh_model_op light_hsl_setup_srv_op[] = { }; /* Mapping of message handlers for Light HSL Hue Server (0x130A) */ -const struct bt_mesh_model_op light_hsl_hue_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_light_hsl_hue_srv_op[] = { { BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_GET, 0, light_hsl_get }, { BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET, 3, light_hsl_hue_set }, { BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET_UNACK, 3, light_hsl_hue_set }, @@ -2936,7 +2936,7 @@ const struct bt_mesh_model_op light_hsl_hue_srv_op[] = { }; /* Mapping of message handlers for Light HSL Saturation Server (0x130B) */ -const struct bt_mesh_model_op light_hsl_sat_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_light_hsl_sat_srv_op[] = { { BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_GET, 0, light_hsl_get }, { BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET, 3, light_hsl_sat_set }, { BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET_UNACK, 3, light_hsl_sat_set }, @@ -2944,7 +2944,7 @@ const struct bt_mesh_model_op light_hsl_sat_srv_op[] = { }; /* Mapping of message handlers for Light xyL Server (0x130C) */ -const struct bt_mesh_model_op light_xyl_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_light_xyl_srv_op[] = { { BLE_MESH_MODEL_OP_LIGHT_XYL_GET, 0, light_xyl_get }, { BLE_MESH_MODEL_OP_LIGHT_XYL_SET, 7, light_xyl_set }, { BLE_MESH_MODEL_OP_LIGHT_XYL_SET_UNACK, 7, light_xyl_set }, @@ -2955,7 +2955,7 @@ const struct bt_mesh_model_op light_xyl_srv_op[] = { }; /* Mapping of message handlers for Light xyL Setup Server (0x130D) */ -const struct bt_mesh_model_op light_xyl_setup_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_light_xyl_setup_srv_op[] = { { BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET, 6, light_xyl_default_set }, { BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET_UNACK, 6, light_xyl_default_set }, { BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET, 8, light_xyl_range_set }, @@ -2964,7 +2964,7 @@ const struct bt_mesh_model_op light_xyl_setup_srv_op[] = { }; /* Mapping of message handlers for Light LC Server (0x130F) */ -const struct bt_mesh_model_op light_lc_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_light_lc_srv_op[] = { { BLE_MESH_MODEL_OP_LIGHT_LC_MODE_GET, 0, light_lc_get }, { BLE_MESH_MODEL_OP_LIGHT_LC_MODE_SET, 1, light_lc_mode_set }, { BLE_MESH_MODEL_OP_LIGHT_LC_MODE_SET_UNACK, 1, light_lc_mode_set }, @@ -2979,7 +2979,7 @@ const struct bt_mesh_model_op light_lc_srv_op[] = { }; /* Mapping of message handlers for Light LC Setup Server (0x1310) */ -const struct bt_mesh_model_op light_lc_setup_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_light_lc_setup_srv_op[] = { { BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET, 2, light_lc_prop_get }, { BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET, 3, light_lc_prop_set }, { BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK, 3, light_lc_prop_set }, @@ -3155,7 +3155,7 @@ static int light_server_init(struct bt_mesh_model *model) return 0; } -int bt_mesh_light_lightness_srv_init(struct bt_mesh_model *model, bool primary) +static int light_lightness_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Light Lightness Server has no publication support"); @@ -3173,12 +3173,12 @@ int bt_mesh_light_lightness_srv_init(struct bt_mesh_model *model, bool primary) return light_server_init(model); } -int bt_mesh_light_lightness_setup_srv_init(struct bt_mesh_model *model, bool primary) +static int light_lightness_setup_srv_init(struct bt_mesh_model *model) { return light_server_init(model); } -int bt_mesh_light_ctl_srv_init(struct bt_mesh_model *model, bool primary) +static int light_ctl_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Light CTL Server has no publication support"); @@ -3205,12 +3205,12 @@ int bt_mesh_light_ctl_srv_init(struct bt_mesh_model *model, bool primary) return light_server_init(model); } -int bt_mesh_light_ctl_setup_srv_init(struct bt_mesh_model *model, bool primary) +static int light_ctl_setup_srv_init(struct bt_mesh_model *model) { return light_server_init(model); } -int bt_mesh_light_ctl_temp_srv_init(struct bt_mesh_model *model, bool primary) +static int light_ctl_temp_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Light CTL Temperature Server has no publication support"); @@ -3220,7 +3220,7 @@ int bt_mesh_light_ctl_temp_srv_init(struct bt_mesh_model *model, bool primary) return light_server_init(model); } -int bt_mesh_light_hsl_srv_init(struct bt_mesh_model *model, bool primary) +static int light_hsl_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Light HSL Server has no publication support"); @@ -3248,12 +3248,12 @@ int bt_mesh_light_hsl_srv_init(struct bt_mesh_model *model, bool primary) return light_server_init(model); } -int bt_mesh_light_hsl_setup_srv_init(struct bt_mesh_model *model, bool primary) +static int light_hsl_setup_srv_init(struct bt_mesh_model *model) { return light_server_init(model); } -int bt_mesh_light_hsl_hue_srv_init(struct bt_mesh_model *model, bool primary) +static int light_hsl_hue_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Light HSL Hue Server has no publication support"); @@ -3263,7 +3263,7 @@ int bt_mesh_light_hsl_hue_srv_init(struct bt_mesh_model *model, bool primary) return light_server_init(model); } -int bt_mesh_light_hsl_sat_srv_init(struct bt_mesh_model *model, bool primary) +static int light_hsl_sat_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Light HSL Saturation Server has no publication support"); @@ -3273,7 +3273,7 @@ int bt_mesh_light_hsl_sat_srv_init(struct bt_mesh_model *model, bool primary) return light_server_init(model); } -int bt_mesh_light_xyl_srv_init(struct bt_mesh_model *model, bool primary) +static int light_xyl_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Light xyL Server has no publication support"); @@ -3292,12 +3292,12 @@ int bt_mesh_light_xyl_srv_init(struct bt_mesh_model *model, bool primary) return light_server_init(model); } -int bt_mesh_light_xyl_setup_srv_init(struct bt_mesh_model *model, bool primary) +static int light_xyl_setup_srv_init(struct bt_mesh_model *model) { return light_server_init(model); } -int bt_mesh_light_lc_srv_init(struct bt_mesh_model *model, bool primary) +static int light_lc_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Light LC Server has no publication support"); @@ -3307,7 +3307,7 @@ int bt_mesh_light_lc_srv_init(struct bt_mesh_model *model, bool primary) return light_server_init(model); } -int bt_mesh_light_lc_setup_srv_init(struct bt_mesh_model *model, bool primary) +static int light_lc_setup_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Light LC Setup Server has no publication support"); @@ -3442,7 +3442,7 @@ static int light_server_deinit(struct bt_mesh_model *model) return 0; } -int bt_mesh_light_lightness_srv_deinit(struct bt_mesh_model *model, bool primary) +static int light_lightness_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Light Lightness Server has no publication support"); @@ -3452,12 +3452,12 @@ int bt_mesh_light_lightness_srv_deinit(struct bt_mesh_model *model, bool primary return light_server_deinit(model); } -int bt_mesh_light_lightness_setup_srv_deinit(struct bt_mesh_model *model, bool primary) +static int light_lightness_setup_srv_deinit(struct bt_mesh_model *model) { return light_server_deinit(model); } -int bt_mesh_light_ctl_srv_deinit(struct bt_mesh_model *model, bool primary) +static int light_ctl_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Light CTL Server has no publication support"); @@ -3467,12 +3467,12 @@ int bt_mesh_light_ctl_srv_deinit(struct bt_mesh_model *model, bool primary) return light_server_deinit(model); } -int bt_mesh_light_ctl_setup_srv_deinit(struct bt_mesh_model *model, bool primary) +static int light_ctl_setup_srv_deinit(struct bt_mesh_model *model) { return light_server_deinit(model); } -int bt_mesh_light_ctl_temp_srv_deinit(struct bt_mesh_model *model, bool primary) +static int light_ctl_temp_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Light CTL Temperature Server has no publication support"); @@ -3482,7 +3482,7 @@ int bt_mesh_light_ctl_temp_srv_deinit(struct bt_mesh_model *model, bool primary) return light_server_deinit(model); } -int bt_mesh_light_hsl_srv_deinit(struct bt_mesh_model *model, bool primary) +static int light_hsl_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Light HSL Server has no publication support"); @@ -3492,12 +3492,12 @@ int bt_mesh_light_hsl_srv_deinit(struct bt_mesh_model *model, bool primary) return light_server_deinit(model); } -int bt_mesh_light_hsl_setup_srv_deinit(struct bt_mesh_model *model, bool primary) +static int light_hsl_setup_srv_deinit(struct bt_mesh_model *model) { return light_server_deinit(model); } -int bt_mesh_light_hsl_hue_srv_deinit(struct bt_mesh_model *model, bool primary) +static int light_hsl_hue_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Light HSL Hue Server has no publication support"); @@ -3507,7 +3507,7 @@ int bt_mesh_light_hsl_hue_srv_deinit(struct bt_mesh_model *model, bool primary) return light_server_deinit(model); } -int bt_mesh_light_hsl_sat_srv_deinit(struct bt_mesh_model *model, bool primary) +static int light_hsl_sat_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Light HSL Saturation Server has no publication support"); @@ -3517,7 +3517,7 @@ int bt_mesh_light_hsl_sat_srv_deinit(struct bt_mesh_model *model, bool primary) return light_server_deinit(model); } -int bt_mesh_light_xyl_srv_deinit(struct bt_mesh_model *model, bool primary) +static int light_xyl_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Light xyL Server has no publication support"); @@ -3527,12 +3527,12 @@ int bt_mesh_light_xyl_srv_deinit(struct bt_mesh_model *model, bool primary) return light_server_deinit(model); } -int bt_mesh_light_xyl_setup_srv_deinit(struct bt_mesh_model *model, bool primary) +static int light_xyl_setup_srv_deinit(struct bt_mesh_model *model) { return light_server_deinit(model); } -int bt_mesh_light_lc_srv_deinit(struct bt_mesh_model *model, bool primary) +static int light_lc_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Light LC Server has no publication support"); @@ -3542,7 +3542,7 @@ int bt_mesh_light_lc_srv_deinit(struct bt_mesh_model *model, bool primary) return light_server_deinit(model); } -int bt_mesh_light_lc_setup_srv_deinit(struct bt_mesh_model *model, bool primary) +static int light_lc_setup_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Light LC Setup Server has no publication support"); @@ -3551,3 +3551,68 @@ int bt_mesh_light_lc_setup_srv_deinit(struct bt_mesh_model *model, bool primary) return light_server_deinit(model); } + +const struct bt_mesh_model_cb bt_mesh_light_lightness_srv_cb = { + .init = light_lightness_srv_init, + .deinit = light_lightness_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_light_lightness_setup_srv_cb = { + .init = light_lightness_setup_srv_init, + .deinit = light_lightness_setup_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_light_ctl_srv_cb = { + .init = light_ctl_srv_init, + .deinit = light_ctl_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_light_ctl_setup_srv_cb = { + .init = light_ctl_setup_srv_init, + .deinit = light_ctl_setup_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_light_ctl_temp_srv_cb = { + .init = light_ctl_temp_srv_init, + .deinit = light_ctl_temp_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_light_hsl_srv_cb = { + .init = light_hsl_srv_init, + .deinit = light_hsl_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_light_hsl_setup_srv_cb = { + .init = light_hsl_setup_srv_init, + .deinit = light_hsl_setup_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_light_hsl_hue_srv_cb = { + .init = light_hsl_hue_srv_init, + .deinit = light_hsl_hue_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_light_hsl_sat_srv_cb = { + .init = light_hsl_sat_srv_init, + .deinit = light_hsl_sat_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_light_xyl_srv_cb = { + .init = light_xyl_srv_init, + .deinit = light_xyl_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_light_xyl_setup_srv_cb = { + .init = light_xyl_setup_srv_init, + .deinit = light_xyl_setup_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_light_lc_srv_cb = { + .init = light_lc_srv_init, + .deinit = light_lc_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_light_lc_setup_srv_cb = { + .init = light_lc_setup_srv_init, + .deinit = light_lc_setup_srv_deinit, +}; diff --git a/components/bt/esp_ble_mesh/mesh_models/server/sensor_server.c b/components/bt/esp_ble_mesh/mesh_models/server/sensor_server.c index 6fa8254bd..2cdccb8ca 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/sensor_server.c +++ b/components/bt/esp_ble_mesh/mesh_models/server/sensor_server.c @@ -985,7 +985,7 @@ static void sensor_setting_set(struct bt_mesh_model *model, /* message handlers (End) */ /* Mapping of message handlers for Sensor Server (0x1100) */ -const struct bt_mesh_model_op sensor_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_sensor_srv_op[] = { { BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET, 0, sensor_get }, { BLE_MESH_MODEL_OP_SENSOR_GET, 0, sensor_get }, { BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET, 2, sensor_get }, @@ -994,7 +994,7 @@ const struct bt_mesh_model_op sensor_srv_op[] = { }; /* Mapping of message handlers for Sensor Setup Server (0x1101) */ -const struct bt_mesh_model_op sensor_setup_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_sensor_setup_srv_op[] = { { BLE_MESH_MODEL_OP_SENSOR_CADENCE_GET, 2, sensor_get }, { BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET, 4, sensor_cadence_set }, { BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK, 4, sensor_cadence_set }, @@ -1099,7 +1099,7 @@ static int sensor_server_init(struct bt_mesh_model *model) return 0; } -int bt_mesh_sensor_srv_init(struct bt_mesh_model *model, bool primary) +static int sensor_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Sensor Server has no publication support"); @@ -1117,7 +1117,7 @@ int bt_mesh_sensor_srv_init(struct bt_mesh_model *model, bool primary) return sensor_server_init(model); } -int bt_mesh_sensor_setup_srv_init(struct bt_mesh_model *model, bool primary) +static int sensor_setup_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Sensor Setup Server has no publication support"); @@ -1137,7 +1137,7 @@ static int sensor_server_deinit(struct bt_mesh_model *model) return 0; } -int bt_mesh_sensor_srv_deinit(struct bt_mesh_model *model, bool primary) +static int sensor_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Sensor Server has no publication support"); @@ -1147,7 +1147,7 @@ int bt_mesh_sensor_srv_deinit(struct bt_mesh_model *model, bool primary) return sensor_server_deinit(model); } -int bt_mesh_sensor_setup_srv_deinit(struct bt_mesh_model *model, bool primary) +static int sensor_setup_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Sensor Setup Server has no publication support"); @@ -1156,3 +1156,13 @@ int bt_mesh_sensor_setup_srv_deinit(struct bt_mesh_model *model, bool primary) return sensor_server_deinit(model); } + +const struct bt_mesh_model_cb bt_mesh_sensor_srv_cb = { + .init = sensor_srv_init, + .deinit = sensor_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_sensor_setup_srv_cb = { + .init = sensor_setup_srv_init, + .deinit = sensor_setup_srv_deinit, +}; diff --git a/components/bt/esp_ble_mesh/mesh_models/server/time_scene_server.c b/components/bt/esp_ble_mesh/mesh_models/server/time_scene_server.c index 447f3a218..ad382b7cb 100644 --- a/components/bt/esp_ble_mesh/mesh_models/server/time_scene_server.c +++ b/components/bt/esp_ble_mesh/mesh_models/server/time_scene_server.c @@ -1155,7 +1155,7 @@ static void scheduler_act_set(struct bt_mesh_model *model, /* message handlers (End) */ /* Mapping of message handlers for Time Server (0x1200) */ -const struct bt_mesh_model_op time_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_time_srv_op[] = { { BLE_MESH_MODEL_OP_TIME_GET, 0, time_get }, { BLE_MESH_MODEL_OP_TIME_STATUS, 5, time_get }, { BLE_MESH_MODEL_OP_TIME_ZONE_GET, 0, time_get }, @@ -1164,7 +1164,7 @@ const struct bt_mesh_model_op time_srv_op[] = { }; /* Mapping of message handlers for Time Setup Server (0x1201) */ -const struct bt_mesh_model_op time_setup_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_time_setup_srv_op[] = { { BLE_MESH_MODEL_OP_TIME_SET, 10, time_set }, { BLE_MESH_MODEL_OP_TIME_ZONE_SET, 6, time_set }, { BLE_MESH_MODEL_OP_TAI_UTC_DELTA_SET, 7, time_set }, @@ -1174,7 +1174,7 @@ const struct bt_mesh_model_op time_setup_srv_op[] = { }; /* Mapping of message handlers for Scene Server (0x1203) */ -const struct bt_mesh_model_op scene_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_scene_srv_op[] = { { BLE_MESH_MODEL_OP_SCENE_GET, 0, scene_get }, { BLE_MESH_MODEL_OP_SCENE_RECALL, 3, scene_recall }, { BLE_MESH_MODEL_OP_SCENE_RECALL_UNACK, 3, scene_recall }, @@ -1183,7 +1183,7 @@ const struct bt_mesh_model_op scene_srv_op[] = { }; /* Mapping of message handlers for Scene Setup Server (0x1204) */ -const struct bt_mesh_model_op scene_setup_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_scene_setup_srv_op[] = { { BLE_MESH_MODEL_OP_SCENE_STORE, 2, scene_action }, { BLE_MESH_MODEL_OP_SCENE_STORE_UNACK, 2, scene_action }, { BLE_MESH_MODEL_OP_SCENE_DELETE, 2, scene_action }, @@ -1192,14 +1192,14 @@ const struct bt_mesh_model_op scene_setup_srv_op[] = { }; /* Mapping of message handlers for Scheduler Server (0x1206) */ -const struct bt_mesh_model_op scheduler_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_scheduler_srv_op[] = { { BLE_MESH_MODEL_OP_SCHEDULER_GET, 0, scheduler_get }, { BLE_MESH_MODEL_OP_SCHEDULER_ACT_GET, 1, scheduler_get }, BLE_MESH_MODEL_OP_END, }; /* Mapping of message handlers for Scheduler Setup Server (0x1207) */ -const struct bt_mesh_model_op scheduler_setup_srv_op[] = { +const struct bt_mesh_model_op bt_mesh_scheduler_setup_srv_op[] = { { BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET, 10, scheduler_act_set }, { BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET_UNACK, 10, scheduler_act_set }, BLE_MESH_MODEL_OP_END, @@ -1314,7 +1314,7 @@ static int time_scene_server_init(struct bt_mesh_model *model) return 0; } -int bt_mesh_time_srv_init(struct bt_mesh_model *model, bool primary) +static int time_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Time Server has no publication support"); @@ -1333,7 +1333,7 @@ int bt_mesh_time_srv_init(struct bt_mesh_model *model, bool primary) return time_scene_server_init(model); } -int bt_mesh_time_setup_srv_init(struct bt_mesh_model *model, bool primary) +static int time_setup_srv_init(struct bt_mesh_model *model) { /* This model does not support subscribing nor publishing */ if (model->pub) { @@ -1344,7 +1344,7 @@ int bt_mesh_time_setup_srv_init(struct bt_mesh_model *model, bool primary) return time_scene_server_init(model); } -int bt_mesh_scene_srv_init(struct bt_mesh_model *model, bool primary) +static int scene_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Scene Server has no publication support"); @@ -1352,7 +1352,7 @@ int bt_mesh_scene_srv_init(struct bt_mesh_model *model, bool primary) } /* The model may be present only on the Primary element of a node. */ - if (primary == false) { + if (!bt_mesh_model_in_primary(model)) { BT_WARN("Scene Server not on the Primary element"); /* Just give a warning here, continue with the initialization */ } @@ -1368,17 +1368,17 @@ int bt_mesh_scene_srv_init(struct bt_mesh_model *model, bool primary) return time_scene_server_init(model); } -int bt_mesh_scene_setup_srv_init(struct bt_mesh_model *model, bool primary) +static int scene_setup_srv_init(struct bt_mesh_model *model) { /* The model may be present only on the Primary element of a node. */ - if (primary == false) { + if (!bt_mesh_model_in_primary(model)) { BT_WARN("Scene Setup Server not on the Primary element"); /* Just give a warning here, continue with the initialization */ } return time_scene_server_init(model); } -int bt_mesh_scheduler_srv_init(struct bt_mesh_model *model, bool primary) +static int scheduler_srv_init(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Scheduler Server has no publication support"); @@ -1386,7 +1386,7 @@ int bt_mesh_scheduler_srv_init(struct bt_mesh_model *model, bool primary) } /* The model may be present only on the Primary element of a node. */ - if (primary == false) { + if (!bt_mesh_model_in_primary(model)) { BT_WARN("Scheduler Server not on the Primary element"); /* Just give a warning here, continue with the initialization */ } @@ -1407,10 +1407,10 @@ int bt_mesh_scheduler_srv_init(struct bt_mesh_model *model, bool primary) return time_scene_server_init(model); } -int bt_mesh_scheduler_setup_srv_init(struct bt_mesh_model *model, bool primary) +static int scheduler_setup_srv_init(struct bt_mesh_model *model) { /* The model may be present only on the Primary element of a node. */ - if (primary == false) { + if (!bt_mesh_model_in_primary(model)) { BT_WARN("Scheduler Setup Server not on the Primary element"); /* Just give a warning here, continue with the initialization */ } @@ -1450,7 +1450,7 @@ static int time_scene_server_deinit(struct bt_mesh_model *model) return 0; } -int bt_mesh_time_srv_deinit(struct bt_mesh_model *model, bool primary) +static int time_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Time Server has no publication support"); @@ -1460,7 +1460,7 @@ int bt_mesh_time_srv_deinit(struct bt_mesh_model *model, bool primary) return time_scene_server_deinit(model); } -int bt_mesh_time_setup_srv_deinit(struct bt_mesh_model *model, bool primary) +static int time_setup_srv_deinit(struct bt_mesh_model *model) { if (model->pub) { BT_ERR("Time Setup Server shall not support publication"); @@ -1470,7 +1470,7 @@ int bt_mesh_time_setup_srv_deinit(struct bt_mesh_model *model, bool primary) return time_scene_server_deinit(model); } -int bt_mesh_scene_srv_deinit(struct bt_mesh_model *model, bool primary) +static int scene_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Scene Server has no publication support"); @@ -1480,12 +1480,12 @@ int bt_mesh_scene_srv_deinit(struct bt_mesh_model *model, bool primary) return time_scene_server_deinit(model); } -int bt_mesh_scene_setup_srv_deinit(struct bt_mesh_model *model, bool primary) +static int scene_setup_srv_deinit(struct bt_mesh_model *model) { return time_scene_server_deinit(model); } -int bt_mesh_scheduler_srv_deinit(struct bt_mesh_model *model, bool primary) +static int scheduler_srv_deinit(struct bt_mesh_model *model) { if (model->pub == NULL) { BT_ERR("Scheduler Server has no publication support"); @@ -1495,7 +1495,37 @@ int bt_mesh_scheduler_srv_deinit(struct bt_mesh_model *model, bool primary) return time_scene_server_deinit(model); } -int bt_mesh_scheduler_setup_srv_deinit(struct bt_mesh_model *model, bool primary) +static int scheduler_setup_srv_deinit(struct bt_mesh_model *model) { return time_scene_server_deinit(model); } + +const struct bt_mesh_model_cb bt_mesh_time_srv_cb = { + .init = time_srv_init, + .deinit = time_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_time_setup_srv_cb = { + .init = time_setup_srv_init, + .deinit = time_setup_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_scene_srv_cb = { + .init = scene_srv_init, + .deinit = scene_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_scene_setup_srv_cb = { + .init = scene_setup_srv_init, + .deinit = scene_setup_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_scheduler_srv_cb = { + .init = scheduler_srv_init, + .deinit = scheduler_srv_deinit, +}; + +const struct bt_mesh_model_cb bt_mesh_scheduler_setup_srv_cb = { + .init = scheduler_setup_srv_init, + .deinit = scheduler_setup_srv_deinit, +}; From cccdd13937be0865ce7dc0debbd1f9be035ee583 Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Wed, 9 Sep 2020 10:11:29 +0200 Subject: [PATCH 55/60] ulp: fix ULP assembler version detection for localized systems --- components/ulp/cmake/CMakeLists.txt | 4 ++-- components/ulp/component_ulp_common.mk | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/components/ulp/cmake/CMakeLists.txt b/components/ulp/cmake/CMakeLists.txt index 49654e84f..e105a267b 100644 --- a/components/ulp/cmake/CMakeLists.txt +++ b/components/ulp/cmake/CMakeLists.txt @@ -11,7 +11,7 @@ execute_process( OUTPUT_VARIABLE as_output ERROR_QUIET) -string(REGEX MATCH "GNU assembler \\(GNU Binutils\\) (${version_pattern})" as_version ${as_output}) +string(REGEX MATCH "\\(GNU Binutils\\) (${version_pattern})" as_version ${as_output}) set(as_version ${CMAKE_MATCH_1}) message(STATUS "Building ULP app ${ULP_APP_NAME}") @@ -100,4 +100,4 @@ add_custom_target(build ${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME}.h WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) -target_link_libraries(${ULP_APP_NAME} -T${CMAKE_CURRENT_BINARY_DIR}/${ULP_LD_SCRIPT} -Map=${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME}.map) \ No newline at end of file +target_link_libraries(${ULP_APP_NAME} -T${CMAKE_CURRENT_BINARY_DIR}/${ULP_LD_SCRIPT} -Map=${CMAKE_CURRENT_BINARY_DIR}/${ULP_APP_NAME}.map) diff --git a/components/ulp/component_ulp_common.mk b/components/ulp/component_ulp_common.mk index a4174d1e1..cf6292998 100644 --- a/components/ulp/component_ulp_common.mk +++ b/components/ulp/component_ulp_common.mk @@ -26,7 +26,10 @@ ULP_PREPROCESSOR_ARGS := \ # Check the assembler version include $(IDF_PATH)/components/ulp/toolchain_ulp_version.mk -ULP_AS_VER := $(shell $(ULP_AS) --version | sed -E -n 's|GNU assembler \(GNU Binutils\) ([a-z0-9\.-]+)|\1|gp') +# $(ULP_AS) --version output might be localized, for example the first line could be +# "Ensamblador (GNU Binutils) 2.28.51-esp-20191205 de GNU" instead of +# "GNU assembler (GNU Binutils) 2.28.51-esp-20191205". +ULP_AS_VER := $(shell $(ULP_AS) --version | sed -E -n 's/.+ \(GNU Binutils\) ([a-z0-9\.-]+)( .*)?/\1/gp') $(info Building ULP app $(ULP_APP_NAME)) $(info ULP assembler version: $(ULP_AS_VER)) From 518e1da6374715a3d981cac5925949575cb03bd9 Mon Sep 17 00:00:00 2001 From: Roland Dobai Date: Wed, 9 Sep 2020 12:59:07 +0200 Subject: [PATCH 56/60] tools: Fix Python 3 incompatibility for building with Eclipse on Windows --- tools/windows/eclipse_make.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/windows/eclipse_make.py b/tools/windows/eclipse_make.py index 76f510c0b..4f877ccf8 100644 --- a/tools/windows/eclipse_make.py +++ b/tools/windows/eclipse_make.py @@ -20,7 +20,7 @@ def check_path(path): pass paths[path] = path # cache as failed, replace with success if it works try: - winpath = subprocess.check_output(["cygpath", "-w", path]).strip() + winpath = subprocess.check_output(["cygpath", "-w", path]).decode().strip() except subprocess.CalledProcessError: return path # something went wrong running cygpath, assume this is not a path! if not os.path.exists(winpath): From 34f30a878edadf3183e2cae5ce0a7af78f030b9e Mon Sep 17 00:00:00 2001 From: lly Date: Mon, 17 Aug 2020 20:11:17 +0800 Subject: [PATCH 57/60] ble_mesh: stack: Using the latest iv_index for provisioning Provisioner should always uses the latest IV Index for provisioning. For example, if the current IV Index is 0x00000001, but prov->iv_index is still initialized with 0x00000000, and if Provisioner uses prov-> iv_index for provisioning, this will cause the Provisioner failing to control the node. So here bt_mesh.iv_index is used instead of prov->iv_index. --- .../mesh_core/include/mesh_main.h | 8 --- components/bt/esp_ble_mesh/mesh_core/main.c | 67 +++++++++---------- .../esp_ble_mesh/mesh_core/provisioner_main.c | 5 -- .../esp_ble_mesh/mesh_core/provisioner_prov.c | 19 +++--- .../esp_ble_mesh/mesh_core/provisioner_prov.h | 6 +- .../bt/esp_ble_mesh/mesh_core/settings.c | 11 +-- 6 files changed, 47 insertions(+), 69 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h b/components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h index 35d38a9c7..a5b1256d9 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h @@ -383,14 +383,6 @@ int bt_mesh_prov_input_string(const char *str); */ int bt_mesh_prov_input_number(u32_t num); -/** @brief Enable Provisioner corresponding functionalities, e.g. scan, etc. - * - * @param bearers Bit-wise OR of provisioning bearers. - * - * @return Zero on success or (negative) error code otherwise. - */ -int bt_mesh_provisioner_net_start(bt_mesh_prov_bearer_t bearers); - /** @brief Enable specific provisioning bearers * * Enable one or more provisioning bearers. diff --git a/components/bt/esp_ble_mesh/mesh_core/main.c b/components/bt/esp_ble_mesh/mesh_core/main.c index 5b7066d7b..9f55a2612 100644 --- a/components/bt/esp_ble_mesh/mesh_core/main.c +++ b/components/bt/esp_ble_mesh/mesh_core/main.c @@ -514,10 +514,41 @@ int bt_mesh_deinit(struct bt_mesh_deinit_param *param) } #if defined(CONFIG_BLE_MESH_PROVISIONER) -int bt_mesh_provisioner_net_start(bt_mesh_prov_bearer_t bearers) +int bt_mesh_provisioner_enable(bt_mesh_prov_bearer_t bearers) { + int err = 0; + + if (bt_mesh_is_provisioner_en()) { + BT_WARN("%s, Already", __func__); + return -EALREADY; + } + + if (prov_bearers_valid(bearers) == false) { + return -EINVAL; + } + + err = bt_mesh_provisioner_net_create(); + if (err) { + BT_ERR("Failed to create network"); + return err; + } + + err = bt_mesh_provisioner_init_prov_info(); + if (err) { + BT_ERR("Failed to init prov info"); + return err; + } + bt_mesh_provisioner_set_prov_bearer(bearers, false); + bt_mesh_comp_provision(bt_mesh_provisioner_get_primary_elem_addr()); + + bt_mesh_atomic_set_bit(bt_mesh.flags, BLE_MESH_PROVISIONER); + + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { + bt_mesh_store_role(); + } + #if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) if (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) && (bearers & BLE_MESH_PROV_ADV)) { @@ -552,40 +583,6 @@ int bt_mesh_provisioner_net_start(bt_mesh_prov_bearer_t bearers) return 0; } -int bt_mesh_provisioner_enable(bt_mesh_prov_bearer_t bearers) -{ - int err = 0; - - if (bt_mesh_is_provisioner_en()) { - BT_WARN("%s, Already", __func__); - return -EALREADY; - } - - if (prov_bearers_valid(bearers) == false) { - return -EINVAL; - } - - err = bt_mesh_provisioner_set_prov_info(); - if (err) { - BT_ERR("Failed to set provisioning info"); - return err; - } - - err = bt_mesh_provisioner_net_create(); - if (err) { - BT_ERR("Failed to create network"); - return err; - } - - bt_mesh_atomic_set_bit(bt_mesh.flags, BLE_MESH_PROVISIONER); - - if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { - bt_mesh_store_role(); - } - - return bt_mesh_provisioner_net_start(bearers); -} - int bt_mesh_provisioner_disable(bt_mesh_prov_bearer_t bearers) { bt_mesh_prov_bearer_t enable = 0U; diff --git a/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c b/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c index 469094c5a..416fbd3f8 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_main.c @@ -83,11 +83,6 @@ int bt_mesh_provisioner_net_create(void) return -EINVAL; } - /* If the device only acts as a Provisioner, need to initialize - * each element's address. - */ - bt_mesh_comp_provision(bt_mesh_provisioner_get_primary_elem_addr()); - if (bt_mesh.p_sub[0]) { /* Provisioner is already enabled (enable -> disable -> enable), * or Provisioner is restored from flash. diff --git a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c index 0439a279a..18497ae0b 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.c @@ -237,7 +237,7 @@ struct bt_mesh_prov_ctx { u16_t curr_net_idx; /* Current flags going to be used in provisioning data */ - u16_t curr_flags; + u8_t curr_flags; /* Current iv_index going to be used in provisioning data */ u16_t curr_iv_index; @@ -1128,10 +1128,8 @@ int bt_mesh_provisioner_set_prov_data_info(struct bt_mesh_prov_data_info *info) return 0; } -int bt_mesh_provisioner_set_prov_info(void) +int bt_mesh_provisioner_init_prov_info(void) { - const struct bt_mesh_comp *comp = NULL; - if (prov_ctx.primary_addr == BLE_MESH_ADDR_UNASSIGNED) { /* If unicast address of primary element of Provisioner has not been set * before, then the following initialization procedure will be used. @@ -1143,7 +1141,7 @@ int bt_mesh_provisioner_set_prov_info(void) return -EINVAL; } - comp = bt_mesh_comp_get(); + const struct bt_mesh_comp *comp = bt_mesh_comp_get(); if (!comp) { BT_ERR("Invalid composition data"); return -EINVAL; @@ -1156,15 +1154,19 @@ int bt_mesh_provisioner_set_prov_info(void) } else { prov_ctx.curr_alloc_addr = prov->prov_start_address; } + + /* Update primary element address with the initialized value here. */ prov_ctx.primary_addr = prov->prov_unicast_addr; if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_prov_info(prov_ctx.primary_addr, prov_ctx.curr_alloc_addr); } } + prov_ctx.curr_net_idx = BLE_MESH_KEY_PRIMARY; - prov_ctx.curr_flags = prov->flags; - prov_ctx.curr_iv_index = prov->iv_index; + struct bt_mesh_subnet *sub = bt_mesh_provisioner_subnet_get(BLE_MESH_KEY_PRIMARY); + prov_ctx.curr_flags = bt_mesh_net_flags(sub); + prov_ctx.curr_iv_index = bt_mesh.iv_index; return 0; } @@ -1241,7 +1243,8 @@ int bt_mesh_provisioner_set_primary_elem_addr(u16_t addr) if (addr + comp->elem_count > prov_ctx.curr_alloc_addr) { prov_ctx.curr_alloc_addr = addr + comp->elem_count; } - BT_INFO("Provisioner primary address updated, old 0x%04x, new 0x%04x", prov_ctx.primary_addr, addr); + + BT_INFO("Primary address updated, old 0x%04x, new 0x%04x", prov_ctx.primary_addr, addr); prov_ctx.primary_addr = addr; if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { diff --git a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.h b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.h index 959717caf..04c961e9f 100644 --- a/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.h +++ b/components/bt/esp_ble_mesh/mesh_core/provisioner_prov.h @@ -277,12 +277,12 @@ int bt_mesh_provisioner_adv_pkt_cb_register(unprov_adv_pkt_cb_t cb); int bt_mesh_provisioner_set_prov_data_info(struct bt_mesh_prov_data_info *info); /** - * @brief This function sets the provisioning information needed by Provisioner, - * including unicast address, IV Index, etc. + * @brief This function initializes the provisioning information needed by Provisioner, + * including NetKey Index, flags, IV Index, etc. * * @return Zero - success, otherwise - fail */ -int bt_mesh_provisioner_set_prov_info(void); +int bt_mesh_provisioner_init_prov_info(void); /** * @brief This function sets the provisioning bearer type used by Provisioner. diff --git a/components/bt/esp_ble_mesh/mesh_core/settings.c b/components/bt/esp_ble_mesh/mesh_core/settings.c index 284f91d4c..97893b66a 100644 --- a/components/bt/esp_ble_mesh/mesh_core/settings.c +++ b/components/bt/esp_ble_mesh/mesh_core/settings.c @@ -249,7 +249,7 @@ static int iv_set(const char *name) bt_mesh_atomic_set_bit_to(bt_mesh.flags, BLE_MESH_IVU_IN_PROGRESS, iv.iv_update); bt_mesh.ivu_duration = iv.iv_duration; - BT_INFO("Restored IV Index 0x%04x (IV Update Flag %u) duration %u hours", + BT_INFO("Restored IV Index 0x%08x (IV Update Flag %u) duration %u hours", iv.iv_index, iv.iv_update, iv.iv_duration); return 0; @@ -1365,8 +1365,6 @@ int settings_core_commit(void) BT_INFO("p_sub[0]->net_idx 0x%03x", bt_mesh.p_sub[0]->net_idx); - bt_mesh_comp_provision(bt_mesh_provisioner_get_primary_elem_addr()); - for (i = 0; i < ARRAY_SIZE(bt_mesh.p_sub); i++) { sub = bt_mesh.p_sub[i]; @@ -1378,7 +1376,6 @@ int settings_core_commit(void) if (err) { BT_ERR("Failed to init subnet 0x%03x", sub->net_idx); } - sub->node_id = BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED; } } #endif /* CONFIG_BLE_MESH_PROVISIONER */ @@ -1417,12 +1414,6 @@ int settings_core_commit(void) } #endif /* CONFIG_BLE_MESH_NODE */ -#if defined(CONFIG_BLE_MESH_PROVISIONER) - if (bt_mesh_is_provisioner()) { - bt_mesh_provisioner_net_start(BLE_MESH_PROV_ADV | BLE_MESH_PROV_GATT); - } -#endif /* CONFIG_BLE_MESH_PROVISIONER */ - return 0; } From 4f11ecebbc0d4ecbef54a17813f5d762a7d32b27 Mon Sep 17 00:00:00 2001 From: Sergei Silnov Date: Fri, 11 Sep 2020 16:14:15 +0200 Subject: [PATCH 58/60] ci: Use git mirror for docker image --- .gitlab-ci.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 660af0705..f3144f7ad 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -363,7 +363,11 @@ build_docker: DOCKER_TMP_IMAGE_NAME: "idf_tmp_image" before_script: [] script: - - export DOCKER_BUILD_ARGS="--build-arg IDF_CLONE_URL=${CI_REPOSITORY_URL} --build-arg IDF_CLONE_BRANCH_OR_TAG=${CI_COMMIT_REF_NAME} --build-arg IDF_CHECKOUT_REF=${CI_COMMIT_TAG:-$CI_COMMIT_SHA}" + - export LOCAL_CI_REPOSITORY_URL=$CI_REPOSITORY_URL + - if [ -n "$LOCAL_GITLAB_HTTPS_HOST" ]; then export LOCAL_CI_REPOSITORY_URL="https://gitlab-ci-token:${CI_JOB_TOKEN}@${LOCAL_GITLAB_HTTPS_HOST}/${CI_PROJECT_PATH}"; fi + - echo "Using repository at $LOCAL_CI_REPOSITORY_URL" + - export DOCKER_BUILD_ARGS="--build-arg IDF_CLONE_URL=${LOCAL_CI_REPOSITORY_URL} --build-arg IDF_CLONE_BRANCH_OR_TAG=${CI_COMMIT_REF_NAME} --build-arg IDF_CHECKOUT_REF=${CI_COMMIT_TAG:-$CI_COMMIT_SHA}" + # Build - docker build --tag ${DOCKER_TMP_IMAGE_NAME} ${DOCKER_BUILD_ARGS} tools/docker/ # We can't mount $PWD/examples/get-started/blink into the container, see https://gitlab.com/gitlab-org/gitlab-ce/issues/41227. From a7e1c144e2e319906c5b5c9fb3f57f87dc542f03 Mon Sep 17 00:00:00 2001 From: Jakob Hasse Date: Thu, 21 May 2020 14:21:41 +0800 Subject: [PATCH 59/60] Add missing regex_error stub Closes IDFGH-3153 * avoids linker error --- components/cxx/cxx_exception_stubs.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/components/cxx/cxx_exception_stubs.cpp b/components/cxx/cxx_exception_stubs.cpp index f09f946dd..7a1898484 100644 --- a/components/cxx/cxx_exception_stubs.cpp +++ b/components/cxx/cxx_exception_stubs.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -36,6 +37,12 @@ extern "C" void __cxx_fatal_exception_int(int i) abort(); } +extern "C" void __cxx_fatal_exception_regex_error_type(std::regex_constants::error_type error) +{ + printf("%s Regex error (%u)\n", FATAL_EXCEPTION, error); + abort(); +} + #if !GCC_NOT_5_2_0 void std::__throw_bad_exception(void) __attribute__((alias("__cxx_fatal_exception"))); void std::__throw_bad_alloc(void) __attribute__((alias("__cxx_fatal_exception"))); @@ -55,6 +62,7 @@ void std::__throw_ios_failure(const char*) __attribute__((alias("__cxx_fatal_exc void std::__throw_system_error(int) __attribute__((alias("__cxx_fatal_exception_int"))); void std::__throw_bad_function_call(void) __attribute__((alias("__cxx_fatal_exception"))); void std::__throw_future_error(int) __attribute__((alias("__cxx_fatal_exception_int"))); +void std::__throw_regex_error(std::regex_constants::error_type) __attribute__((alias("__cxx_fatal_exception_regex_error_type"))); #endif /* The following definitions are needed because libstdc++ is also compiled with From 1f32a8d95ed190edfe68507a4575ef6ba2bfd0e8 Mon Sep 17 00:00:00 2001 From: lly Date: Tue, 15 Sep 2020 20:05:58 +0800 Subject: [PATCH 60/60] ble_mesh: stack: Check if mesh stack initialized before init vendor client --- components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c | 5 +++++ components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h | 6 ++++++ components/bt/esp_ble_mesh/mesh_core/main.c | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c index e61118c6b..a085b8078 100644 --- a/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c +++ b/components/bt/esp_ble_mesh/btc/btc_ble_mesh_prov.c @@ -948,6 +948,11 @@ static void btc_ble_mesh_proxy_client_filter_status_recv_cb(u8_t conn_handle, u1 int btc_ble_mesh_client_model_init(esp_ble_mesh_model_t *model) { + if (!bt_mesh_is_initialized()) { + BT_ERR("Mesh stack is not initialized!"); + return -EINVAL; + } + __ASSERT(model && model->op, "%s, Invalid parameter", __func__); esp_ble_mesh_model_op_t *op = model->op; while (op != NULL && op->opcode != 0) { diff --git a/components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h b/components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h index a5b1256d9..c18ce9155 100644 --- a/components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h +++ b/components/bt/esp_ble_mesh/mesh_core/include/mesh_main.h @@ -446,6 +446,12 @@ int bt_mesh_provisioner_disable(bt_mesh_prov_bearer_t bearers); BLE_MESH_FEAT_FRIEND | \ BLE_MESH_FEAT_LOW_POWER) +/** @brief Check if the mesh stack is initialized. + * + * @return true - yes, false - no. + */ +bool bt_mesh_is_initialized(void); + /** @brief Initialize Mesh support * * After calling this API, the node will not automatically advertise as diff --git a/components/bt/esp_ble_mesh/mesh_core/main.c b/components/bt/esp_ble_mesh/mesh_core/main.c index 9f55a2612..727edea92 100644 --- a/components/bt/esp_ble_mesh/mesh_core/main.c +++ b/components/bt/esp_ble_mesh/mesh_core/main.c @@ -31,6 +31,11 @@ static bool mesh_init = false; +bool bt_mesh_is_initialized(void) +{ + return mesh_init; +} + int bt_mesh_provision(const u8_t net_key[16], u16_t net_idx, u8_t flags, u32_t iv_index, u16_t addr, const u8_t dev_key[16])