diff --git a/components/bt/CMakeLists.txt b/components/bt/CMakeLists.txt index 70eb157e4b..4b34598538 100644 --- a/components/bt/CMakeLists.txt +++ b/components/bt/CMakeLists.txt @@ -272,6 +272,80 @@ if(CONFIG_BT_ENABLED) endif() endif() +if (CONFIG_BLE_MESH) + list(APPEND COMPONENT_ADD_INCLUDEDIRS + "bluedroid/osi/include" + "ble_mesh/mesh_core" + "ble_mesh/mesh_core/include" + "ble_mesh/mesh_core/settings/include" + "ble_mesh/btc/include" + "ble_mesh/mesh_models/include" + "ble_mesh/api/core/include" + "ble_mesh/api/models/include" + "ble_mesh/api") + + list(APPEND COMPONENT_SRCS + "ble_mesh/api/core/esp_ble_mesh_common_api.c" + "ble_mesh/api/core/esp_ble_mesh_local_data_operation_api.c" + "ble_mesh/api/core/esp_ble_mesh_low_power_api.c" + "ble_mesh/api/core/esp_ble_mesh_networking_api.c" + "ble_mesh/api/core/esp_ble_mesh_provisioning_api.c" + "ble_mesh/api/core/esp_ble_mesh_proxy_api.c" + "ble_mesh/api/models/esp_ble_mesh_config_model_api.c" + "ble_mesh/api/models/esp_ble_mesh_generic_model_api.c" + "ble_mesh/api/models/esp_ble_mesh_health_model_api.c" + "ble_mesh/api/models/esp_ble_mesh_lighting_model_api.c" + "ble_mesh/api/models/esp_ble_mesh_sensor_model_api.c" + "ble_mesh/api/models/esp_ble_mesh_time_scene_model_api.c" + "ble_mesh/btc/btc_ble_mesh_config_model.c" + "ble_mesh/btc/btc_ble_mesh_generic_model.c" + "ble_mesh/btc/btc_ble_mesh_health_model.c" + "ble_mesh/btc/btc_ble_mesh_lighting_model.c" + "ble_mesh/btc/btc_ble_mesh_prov.c" + "ble_mesh/btc/btc_ble_mesh_sensor_model.c" + "ble_mesh/btc/btc_ble_mesh_time_scene_model.c" + "ble_mesh/mesh_core/settings/settings_act.c" + "ble_mesh/mesh_core/settings/settings_base64.c" + "ble_mesh/mesh_core/settings/settings_fcb.c" + "ble_mesh/mesh_core/settings/settings_init.c" + "ble_mesh/mesh_core/settings/settings_line.c" + "ble_mesh/mesh_core/settings/settings_store.c" + "ble_mesh/mesh_core/access.c" + "ble_mesh/mesh_core/adv.c" + "ble_mesh/mesh_core/beacon.c" + "ble_mesh/mesh_core/cfg_cli.c" + "ble_mesh/mesh_core/cfg_srv.c" + "ble_mesh/mesh_core/crypto.c" + "ble_mesh/mesh_core/friend.c" + "ble_mesh/mesh_core/health_cli.c" + "ble_mesh/mesh_core/health_srv.c" + "ble_mesh/mesh_core/lpn.c" + "ble_mesh/mesh_core/mesh_aes_encrypt.c" + "ble_mesh/mesh_core/mesh_atomic.c" + "ble_mesh/mesh_core/mesh_bearer_adapt.c" + "ble_mesh/mesh_core/mesh_buf.c" + "ble_mesh/mesh_core/mesh_hci.c" + "ble_mesh/mesh_core/mesh_kernel.c" + "ble_mesh/mesh_core/mesh_main.c" + "ble_mesh/mesh_core/mesh_util.c" + "ble_mesh/mesh_core/net.c" + "ble_mesh/mesh_core/prov.c" + "ble_mesh/mesh_core/provisioner_beacon.c" + "ble_mesh/mesh_core/provisioner_main.c" + "ble_mesh/mesh_core/provisioner_prov.c" + "ble_mesh/mesh_core/provisioner_proxy.c" + "ble_mesh/mesh_core/proxy.c" + "ble_mesh/mesh_core/settings.c" + "ble_mesh/mesh_core/test.c" + "ble_mesh/mesh_core/transport.c" + "ble_mesh/mesh_models/generic_client.c" + "ble_mesh/mesh_models/lighting_client.c" + "ble_mesh/mesh_models/mesh_common.c" + "ble_mesh/mesh_models/model_common.c" + "ble_mesh/mesh_models/sensor_client.c" + "ble_mesh/mesh_models/time_scene_client.c") +endif() + # requirements can't depend on config set(COMPONENT_PRIV_REQUIRES nvs_flash) diff --git a/components/bt/Kconfig b/components/bt/Kconfig index 56eef04233..30e4ae4ad8 100644 --- a/components/bt/Kconfig +++ b/components/bt/Kconfig @@ -1270,794 +1270,757 @@ menu Bluetooth endmenu -# Kconfig - Bluetooth Mesh configuration options - -# -# Copyright (c) 2017 Intel Corporation -# -# SPDX-License-Identifier: Apache-2.0 -# - -menuconfig BT_MESH - bool "Bluetooth Mesh support" - select TINYCRYPT - select TINYCRYPT_AES - select TINYCRYPT_AES_CMAC - help - This option enables Bluetooth Mesh support. The specific - features that are available may depend on other features - that have been enabled in the stack, such as GATT support. - -if BT_MESH - -comment "Note: If using Duplicate Scan, set Scan Duplicate Type to 0x2" -config BT_MESH_USE_DUPLICATE_SCAN - bool "Support Duplicate Scan in BLE Mesh" - select BLE_SCAN_DUPLICATE - select BLE_MESH_SCAN_DUPLICATE_EN - default y - help - Enable this option to allow using specific duplicate scan filter - in BLE Mesh, Scan Duplicate Type must be set to 0x02. - make menuconfig -> Component config -> Bluetooth -> Bluetooth - controller -> Scan Duplicate Type -> Scan Duplicate By Device - Address And Advertising Data. - -config BT_MESH_FAST_PROV - bool "Enable BLE Mesh Fast Provisioning" - select BT_MESH_NODE - select BT_MESH_PROVISIONER - select BT_MESH_PB_ADV - default n - help - Enable this option to allow BLE Mesh fast provisioning solution - to be used. - -config BT_MESH_NODE - bool "Support for BLE Mesh Node" - help - Enable the device to be provisioned into a node - -config BT_MESH_PROVISIONER - bool "Support for BLE Mesh Provisioner" - help - Enable the device to be a provisioner - -if BT_MESH_PROVISIONER - -config BT_MESH_UNPROV_DEV_ADD - int "Maximum number of unprovisioned devices that can be added to device queue" - default 20 - range 1 100 - help - This option specifies how may unprovisioned devices can be added to device queue - for provisioning. - -config BT_MESH_MAX_STORED_NODES - int "Maximum number of nodes whose information can be stored" - default 20 - range 1 1000 - help - This option specifies the maximum number of nodes whose information can be - stored by a provisioner in its upper layer. - -config BT_MESH_MAX_PROV_NODES - int "Maximum number of devices that can be provisioned by provisioner" - default 20 - range 1 100 - help - This option specifies how many devices can be provisioned by - provisioner. - -if BT_MESH_PB_ADV -config BT_MESH_PBA_SAME_TIME - int "Maximum number of PB-ADV running at the same time by provisioner" - default 10 - range 1 30 - help - This option specifies how many devices can be provisioned at the same - time using PB-ADV. -endif # BT_MESH_PB_ADV - -if BT_MESH_PB_GATT -config BT_MESH_PBG_SAME_TIME - int "Maximum number of PB-GATT running at the same time by provisioner" - default 4 - range 1 5 - help - This option specifies how many devices can be provisioned at the same - time using PB-GATT. -endif # BT_MESH_PB_GATT - -config BT_MESH_PROVISIONER_SUBNET_COUNT - int "Maximum number of mesh subnets that can be created by provisioner" - default 3 - range 1 4096 - help - This option specifies how many subnets per network a provisioner can create - -config BT_MESH_PROVISIONER_APP_KEY_COUNT - int "Maximum number of application keys that can be owned by provisioner" - default 9 - range 1 4096 - help - This option specifies how many application keys the provisioner - can have. - -endif # BT_MESH_PROVISIONER - -# Virtual option enabled whenever Generic Provisioning layer is needed -config BT_MESH_PROV - bool - -config BT_MESH_PB_ADV - bool "Provisioning support using the advertising bearer (PB-ADV)" - select BT_MESH_PROV - default y - help - Enable this option to allow the device to be provisioned over - the advertising bearer. - -config BT_MESH_PB_GATT - bool "Provisioning support using GATT (PB-GATT)" - select BT_MESH_PROXY - select BT_MESH_PROV - help - Enable this option to allow the device to be provisioned over GATT. - -# Virtual option enabled whenever any Proxy protocol is needed -config BT_MESH_PROXY - bool - -config BT_MESH_GATT_PROXY - bool "GATT Proxy Service" - select BT_MESH_PROXY - help - This option enables support for Mesh GATT Proxy Service, - i.e. the ability to act as a proxy between a Mesh GATT Client - and a Mesh network. - -config BT_MESH_NODE_ID_TIMEOUT - int "Node Identity advertising timeout" - depends on BT_MESH_GATT_PROXY - range 1 60 - default 60 - help - This option determines for how long the local node advertises - using Node Identity. The given value is in seconds. The specification - limits this to 60 seconds and lists it as the recommended value as well. - So leaving the default value is the safest option. - -if BT_MESH_PROXY - -config BT_MESH_PROXY_FILTER_SIZE - int "Maximum number of filter entries per Proxy Client" - default 1 - default 3 if BT_MESH_GATT_PROXY - range 1 32767 - help - This option specifies how many Proxy Filter entries the local - node supports. - -endif # BT_MESH_PROXY - -config NET_BUF_POOL_USAGE - bool "net buffer pool usage" - select BT_MESH_PROV - default n - help - Enable this macro to use the mesh buffer pool usage - -config BT_MESH_SETTINGS - bool "Store Bluetooth Mesh key and configuration persistently" - default n - help - When selected, the Bluetooth stack will take care of storing/restoring the - Bluetooth state(e.g. pairing keys) and configuration persistently in flash. - -if BT_MESH_SETTINGS -config BT_MESH_STORE_TIMEOUT - int "Delay (in seconds) before storing anything persistently" - range 0 1000000 - default 2 - help - This value defines in seconds how soon any pending changes - are actually written into persistent storage (flash) after - a change occurs. - -config BT_MESH_SEQ_STORE_RATE - int "How often the sequence number gets updated in storage" - range 0 1000000 - default 128 - help - This value defines how often the local sequence number gets - updated in persistent storage (i.e. flash). e.g. a value of 100 - means that the sequence number will be stored to flash on every - 100th increment. If the node sends messages very frequently a - higher value makes more sense, whereas if the node sends - infrequently a value as low as 0 (update storage for every - increment) can make sense. When the stack gets initialized it - will add sequence number to the last stored one, so that it starts - off with a value that's guaranteed to be larger than the last - one used before power off. - -config BT_MESH_RPL_STORE_TIMEOUT - int "Minimum frequency that the RPL gets updated in storage" - range 0 1000000 - default 5 - help - This value defines in seconds how soon the RPL gets written to - persistent storage after a change occurs. If the node receives - messages frequently, then a large value is recommended. If the - node receives messages rarely, then the value can be as low as - 0 (which means the PRL is written into the storage immediately). - Note that if the node operates in a security-sensitive case, and - there is a risk of sudden power-off, then a value of 0 is strongly - recommended. Otherwise, a power loss before RPL being written into - the storage may introduce message replay attacks and system security - will be in a vulnerable state. - -config SETTINGS_FCB - bool "Settings used fcb mode" - default y - help - Use FCB as a settings storage back-end. -endif # if BT_MESH_SETTINGS - -config BT_MESH_SELF_TEST - bool "Perform self-tests" - help - This option adds extra self-tests which are run every time - mesh networking is initialized. - -config BT_MESH_IV_UPDATE_TEST - bool "Test the IV Update Procedure" - help - This option removes the 96 hour limit of the IV Update - Procedure and lets the state to be changed at any time. - -config BT_MESH_SUBNET_COUNT - int "Maximum number of mesh subnets per network" - default 1 - range 1 4096 - help - This option specifies how many subnets a Mesh network can - have at the same time. - -config BT_MESH_APP_KEY_COUNT - int "Maximum number of application keys per network" - default 1 - range 1 4096 - help - This option specifies how many application keys the device can - store per network. - -config BT_MESH_MODEL_KEY_COUNT - int "Maximum number of application keys per model" - default 1 - range 1 4096 - help - This option specifies the maximum number of application keys to which - each model can be bound. - -config BT_MESH_MODEL_GROUP_COUNT - int "Maximum number of group address subscriptions per model" - default 1 - range 1 4096 - help - This option specifies the maximum number of addresses to which - each model can be subscribed. - -config BT_MESH_LABEL_COUNT - int "Maximum number of Label UUIDs used for Virtual Addresses" - default 1 - range 0 4096 - help - This option specifies how many Label UUIDs can be stored. - -config BT_MESH_CRPL - int "Maximum capacity of the replay protection list" - default 10 - range 2 65535 - help - This options specifies the maximum capacity of the replay - protection list. It is similar to Network message - cache size, but has a different purpose. - -config BT_MESH_MSG_CACHE_SIZE - int "Network message cache size" - default 10 - range 2 65535 - help - Number of messages that are cached for the network. This helps - prevent unnecessary decryption operations and unnecessary - relays. This option is similar to Replay protection list, - but has a different purpose. - -config BT_MESH_ADV_BUF_COUNT - int "Number of advertising buffers" - default 60 - range 6 256 - help - Number of advertising buffers available. The transport layer - reserves ADV_BUF_COUNT - 3 buffers for outgoing segments. The - maximum outgoing SDU size is 12 times this value (out of which - 4 or 8 bytes are used for the Transport Layer MIC). For - example, 5 segments means the maximum SDU size is 60 bytes, - which leaves 56 bytes for application layer data using a - 4-byte MIC, or 52 bytes using an 8-byte MIC. - -config BT_MESH_TX_SEG_MSG_COUNT - int "Maximum number of simultaneous outgoing segmented messages" - default 1 - range 1 BT_MESH_ADV_BUF_COUNT - help - Maximum number of simultaneous outgoing multi-segment and/or - reliable messages. - -config BT_MESH_RX_SEG_MSG_COUNT - int "Maximum number of simultaneous incoming segmented messages" - default 1 - range 1 255 - help - Maximum number of simultaneous incoming multi-segment and/or - reliable messages. - -config BT_MESH_RX_SDU_MAX - int "Maximum incoming Upper Transport Access PDU length" - default 384 - range 36 384 - help - Maximum incoming Upper Transport Access PDU length. Leave this - to the default value, unless you really need to optimize memory - usage. - -config BT_MESH_RELAY - bool "Relay support" - help - Support for acting as a Mesh Relay Node. - -config BT_MESH_LOW_POWER - bool "Support for Low Power features" - help - Enable this option to operate as a Low Power Node. - -if BT_MESH_LOW_POWER - -config BT_MESH_LPN_ESTABLISHMENT - bool "Perform Friendship establishment using low power" - default y - help - Perform the Friendship establishment using low power with - the help of a reduced scan duty cycle. The downside of this - is that the node may miss out on messages intended for it - until it has successfully set up Friendship with a Friend - node. - -config BT_MESH_LPN_AUTO - bool "Automatically start looking for Friend nodes once provisioned" - default y - help - Once provisioned, automatically enable LPN functionality and start - looking for Friend nodes. If this option is disabled LPN mode - needs to be manually enabled by calling bt_mesh_lpn_set(true). - -config BT_MESH_LPN_AUTO_TIMEOUT - int "Time from last received message before going to LPN mode" - default 15 - range 0 3600 - depends on BT_MESH_LPN_AUTO - help - Time in seconds from the last received message, that the node - waits out before starting to look for Friend nodes. - -config BT_MESH_LPN_RETRY_TIMEOUT - int "Retry timeout for Friend requests" - default 8 - range 1 3600 - help - Time in seconds between Friend Requests, if a previous Friend - Request did not yield any acceptable Friend Offers. - -config BT_MESH_LPN_RSSI_FACTOR - int "RSSIFactor, used in Friend Offer Delay calculation" - range 0 3 - default 0 - help - The contribution of the RSSI, measured by the Friend node, used - in Friend Offer Delay calculations. 0 = 1, 1 = 1.5, 2 = 2, 3 = 2.5. - -config BT_MESH_LPN_RECV_WIN_FACTOR - int "ReceiveWindowFactor, used in Friend Offer Delay calculation" - range 0 3 - default 0 - help - The contribution of the supported Receive Window used in - Friend Offer Delay calculations. 0 = 1, 1 = 1.5, 2 = 2, 3 = 2.5. - -config BT_MESH_LPN_MIN_QUEUE_SIZE - int "Minimum size of the acceptable friend queue (MinQueueSizeLog)" - range 1 7 - default 1 - help - The MinQueueSizeLog field is defined as log_2(N), where N is - the minimum number of maximum size Lower Transport PDUs that - the Friend node can store in its Friend Queue. As an example, - MinQueueSizeLog value 1 gives N = 2, and value 7 gives N = 128. - -config BT_MESH_LPN_RECV_DELAY - int "Receive delay requested by the local node" - range 10 255 - default 100 - help - The ReceiveDelay is the time between the Low Power node - sending a request and listening for a response. This delay - allows the Friend node time to prepare the response. The value - is in units of milliseconds. - -config BT_MESH_LPN_POLL_TIMEOUT - int "The value of the PollTimeout timer" - range 10 244735 - default 300 - help - PollTimeout timer is used to measure time between two - consecutive requests sent by a Low Power node. If no - requests are received by the Friend node before the - PollTimeout timer expires, then the friendship is considered - terminated. The value is in units of 100 milliseconds, so e.g. - a value of 300 means 30 seconds. - -config BT_MESH_LPN_INIT_POLL_TIMEOUT - int "The starting value of the PollTimeout timer" - range 10 BT_MESH_LPN_POLL_TIMEOUT - default BT_MESH_LPN_POLL_TIMEOUT - help - The initial value of the PollTimeout timer when Friendship - is to be established for the first time. After this, the timeout - gradually grows toward the actual PollTimeout, doubling - in value for each iteration. The value is in units of 100 - milliseconds, so e.g. a value of 300 means 30 seconds. - -config BT_MESH_LPN_SCAN_LATENCY - int "Latency for enabling scanning" - range 0 50 - default 10 - help - Latency (in milliseconds) is the time it takes to enable scanning. In - practice, it means how much time in advance of the Receive Window, - the request to enable scanning is made. - -config BT_MESH_LPN_GROUPS - int "Number of groups the LPN can subscribe to" - range 0 16384 - default 8 - help - Maximum number of groups to which the LPN can subscribe. -endif # BT_MESH_LOW_POWER - -config BT_MESH_FRIEND - bool "Support for acting as a Friend Node" - help - Enable this option to be able to act as a Friend Node. - -if BT_MESH_FRIEND - -config BT_MESH_FRIEND_RECV_WIN - int "Friend Receive Window" - range 1 255 - default 255 - help - Receive Window in milliseconds supported by the Friend node. - -config BT_MESH_FRIEND_QUEUE_SIZE - int "Minimum number of buffers supported per Friend Queue" - range 2 65536 - default 16 - help - Minimum number of buffers available to be stored for each - local Friend Queue. - -config BT_MESH_FRIEND_SUB_LIST_SIZE - int "Friend Subscription List Size" - range 0 1023 - default 3 - help - Size of the Subscription List that can be supported by a - Friend node for a Low Power node. - -config BT_MESH_FRIEND_LPN_COUNT - int "Number of supported LPN nodes" - range 1 1000 - default 2 - help - Number of Low Power Nodes with which a Friend can have Friendship - simultaneously. - -config BT_MESH_FRIEND_SEG_RX - int "Number of incomplete segment lists per LPN" - range 1 1000 - default 1 - help - Number of incomplete segment lists tracked for each Friends' LPN. - In other words, this determines from how many elements can segmented - messages destined for the Friend queue be received simultaneously. - -endif # BT_MESH_FRIEND - -config BT_MESH_NO_LOG - bool "Disable BT MESH debug logs (minimize bin size)" - depends on BT_MESH - default n - help - Select this to save the rodata code size - -menu "BT DEBUG LOG LEVEL" - depends on BT_MESH && !BT_MESH_NO_LOG - -choice BT_MESH_STACK_INITIAL_TRACE_LEVEL - prompt "BT_MESH_STACK" - default BT_MESH_TRACE_LEVEL_WARNING - depends on BT_MESH && !BT_MESH_NO_LOG - help - Define BT trace level for bt mesh stack - -config BT_MESH_TRACE_LEVEL_NONE - bool "NONE" -config BT_MESH_TRACE_LEVEL_ERROR - bool "ERROR" -config BT_MESH_TRACE_LEVEL_WARNING - bool "WARNING" -config BT_MESH_TRACE_LEVEL_INFO - bool "INFO" -config BT_MESH_TRACE_LEVEL_DEBUG - bool "DEBUG" -config BT_MESH_TRACE_LEVEL_VERBOSE - bool "VERBOSE" -endchoice - -config BT_MESH_STACK_INITIAL_TRACE_LEVEL - int - depends on BT_MESH - default 0 if BT_MESH_TRACE_LEVEL_NONE - default 1 if BT_MESH_TRACE_LEVEL_ERROR - default 2 if BT_MESH_TRACE_LEVEL_WARNING - default 3 if BT_MESH_TRACE_LEVEL_INFO - default 4 if BT_MESH_TRACE_LEVEL_DEBUG - default 5 if BT_MESH_TRACE_LEVEL_VERBOSE - default 2 - -endmenu #BT NET NUFFER DEBUG LOG LEVEL - -menu "BT NET NUFFER DEBUG LOG LEVEL" - depends on BT_MESH && !BT_MESH_NO_LOG - -choice BT_MESH_NET_BUF_INITIAL_TRACE_LEVEL - prompt "BT_MESH_STACK" - default BT_MESH_NET_BUF_TRACE_LEVEL_WARNING - depends on BT_MESH && !BT_MESH_NO_LOG - help - Define BT trace level for bt mesh network buffer alloc debug - -config BT_MESH_NET_BUF_TRACE_LEVEL_NONE - bool "NONE" -config BT_MESH_NET_BUF_TRACE_LEVEL_ERROR - bool "ERROR" -config BT_MESH_NET_BUF_TRACE_LEVEL_WARNING - bool "WARNING" -config BT_MESH_NET_BUF_TRACE_LEVEL_INFO - bool "INFO" -config BT_MESH_NET_BUF_TRACE_LEVEL_DEBUG - bool "DEBUG" -config BT_MESH_NET_BUF_TRACE_LEVEL_VERBOSE - bool "VERBOSE" -endchoice - -config BT_MESH_NET_BUF_INITIAL_TRACE_LEVEL - int - depends on BT_MESH - default 0 if BT_MESH_NET_BUF_TRACE_LEVEL_NONE - default 1 if BT_MESH_NET_BUF_TRACE_LEVEL_ERROR - default 2 if BT_MESH_NET_BUF_TRACE_LEVEL_WARNING - default 3 if BT_MESH_NET_BUF_TRACE_LEVEL_INFO - default 4 if BT_MESH_NET_BUF_TRACE_LEVEL_DEBUG - default 5 if BT_MESH_NET_BUF_TRACE_LEVEL_VERBOSE - default 2 - -endmenu #BT DEBUG NET BUF LOG LEVEL - -config BT_MESH_IRQ_LOCK - bool "Used the IRQ lock instead of task lock" - help - To improve the real-time requirements of bt controller in BLE Mesh, task lock is used to replace IRQ lock. - -config BT_MESH_CLIENT_MSG_TIMEOUT - int "Timeout(ms) for client message response" - range 100 1200000 - default 4000 - help - Timeout value used by the node to get response to the sent message. - -config BT_MESH_CFG_CLI - bool "Support for Configuration Client Model" - help - Enable support for Configuration client model. - -config BT_MESH_HEALTH_CLI - bool "Support for Health Client Model" - help - Enable support for Health client model. - -config BT_MESH_GENERIC_ONOFF_CLI - bool "Support for Generic OnOff Client Model" - help - Enable support for Generic OnOff client model. - -config BT_MESH_GENERIC_LEVEL_CLI - bool "Support for Generic Level Client Model" - help - Enable support for Generic Level client model. - -config BT_MESH_GENERIC_DEF_TRANS_TIME_CLI - bool "Support for Generic Default Transition Time Client Model" - help - Enable support for Generic Default Transition Time client model. - -config BT_MESH_GENERIC_POWER_ONOFF_CLI - bool "Support for Generic Power Onoff Client Model" - help - Enable support for Generic Power Onoff client model. - -config BT_MESH_GENERIC_POWER_LEVEL_CLI - bool "Support for Generic Power Level Client Model" - help - Enable support for Generic Power Level client model. - -config BT_MESH_GENERIC_BATTERY_CLI - bool "Support for Generic Battery Client Model" - help - Enable support for Generic Battery client model. - -config BT_MESH_GENERIC_LOCATION_CLI - bool "Support for Generic Location Client Model" - help - Enable support for Generic Location client model. - -config BT_MESH_GENERIC_PROPERTY_CLI - bool "Support for Generic Property Client Model" - help - Enable support for Generic Property client model. - -config BT_MESH_SENSOR_CLI - bool "Support for Sensor Client Model" - help - Enable support for Sensor client model. - -config BT_MESH_TIME_CLI - bool "Support for Time Client Model" - help - Enable support for Time client model. - -config BT_MESH_SCENE_CLI - bool "Support for Scene Client Model" - help - Enable support for Scene client model. - -config BT_MESH_SCHEDULER_CLI - bool "Support for Scheduler Client Model" - help - Enable support for Scheduler client model. - -config BT_MESH_LIGHT_LIGHTNESS_CLI - bool "Support for Light Lightness Client Model" - help - Enable support for Light Lightness client model. - -config BT_MESH_LIGHT_CTL_CLI - bool "Support for Light CTL Client Model" - help - Enable support for Light CTL client model. - -config BT_MESH_LIGHT_HSL_CLI - bool "Support for Light HSL Client Model" - help - Enable support for Light HSL client model. - -config BT_MESH_LIGHT_XYL_CLI - bool "Support for Light XYL Client Model" - help - Enable support for Light XYL client model. - -config BT_MESH_LIGHT_LC_CLI - bool "Support for Light LC Client Model" - help - Enable support for Light LC client model. - -config BT_MESH_SHELL - bool "Enable Bluetooth Mesh shell" - select CONSOLE_SHELL - depends on BT_MESH_CFG_CLI - depends on BT_MESH_HEALTH_CLI - help - Activate shell module that provides Bluetooth Mesh commands to - the console. - - - -config BT_MESH_DEBUG - bool "Enable debug logs" - depends on BT_DEBUG - help - Use this option to enable debug logs for the Bluetooth - Mesh functionality. - -if BT_MESH_DEBUG - -config BT_MESH_DEBUG_NET - bool "Network layer debug" - help - Use this option to enable Network layer debug logs for the - Bluetooth Mesh functionality. - -config BT_MESH_DEBUG_TRANS - bool "Transport layer debug" - help - Use this option to enable Transport layer debug logs for the - Bluetooth Mesh functionality. - -config BT_MESH_DEBUG_BEACON - bool "Beacon debug" - help - Use this option to enable Beacon-related debug logs for the - Bluetooth Mesh functionality. - -config BT_MESH_DEBUG_CRYPTO - bool "Crypto debug" - help - Use this option to enable cryptographic debug logs for the - Bluetooth Mesh functionality. - -config BT_MESH_DEBUG_PROV - bool "Provisioning debug" - help - Use this option to enable Provisioning debug logs for the - Bluetooth Mesh functionality. - -config BT_MESH_DEBUG_ACCESS - bool "Access layer debug" - help - Use this option to enable Access layer and device composition - related debug logs for Bluetooth Mesh. - -config BT_MESH_DEBUG_MODEL - bool "Foundation model debug" - help - Use this option to enable debug logs for the Foundation - Models. - -config BT_MESH_DEBUG_ADV - bool "Advertising debug" - help - Use this option to enable advertising debug logs for - the Bluetooth Mesh functionality. - -config BT_MESH_DEBUG_LOW_POWER - bool "Low Power debug" - help - Use this option to enable Low Power debug logs for the - Bluetooth Mesh functionality. - -config BT_MESH_DEBUG_FRIEND - bool "Friend debug" - help - Use this option to enable Friend debug logs for the - Bluetooth Mesh functionality. - -config BT_MESH_DEBUG_PROXY - bool "Proxy debug" - depends on BT_MESH_PROXY - help - Use this option to enable Proxy protocol debug logs. - -endif # BT_MESH_DEBUG - -endif # BT_MESH +menuconfig BLE_MESH + bool "BLE Mesh Support" + help + This option enables BLE Mesh support. The specific features that are + available may depend on other features that have been enabled in the + stack, such as Bluetooth Support, Bluedroid Support & GATT support. + +if BLE_MESH + + config BLE_MESH_USE_DUPLICATE_SCAN + bool "Support Duplicate Scan in BLE Mesh" + select BLE_SCAN_DUPLICATE + select BLE_MESH_SCAN_DUPLICATE_EN + default y + help + Enable this option to allow using specific duplicate scan filter + in BLE Mesh, and Scan Duplicate Type must be set to 0x02. + + config BLE_MESH_FAST_PROV + bool "Enable BLE Mesh Fast Provisioning" + select BLE_MESH_NODE + select BLE_MESH_PROVISIONER + select BLE_MESH_PB_ADV + default n + help + Enable this option to allow BLE Mesh fast provisioning solution to be used. + + config BLE_MESH_NODE + bool "Support for BLE Mesh Node" + help + Enable the device to be provisioned into a node. + + config BLE_MESH_PROVISIONER + bool "Support for BLE Mesh Provisioner" + help + Enable the device to be a provisioner. + + if BLE_MESH_PROVISIONER + + config BLE_MESH_WAIT_FOR_PROV_MAX_DEV_NUM + int "Maximum number of unprovisioned devices that can be added to device queue" + default 20 + range 1 100 + help + This option specifies how may unprovisioned devices can be added to device + queue for provisioning. + + config BLE_MESH_MAX_STORED_NODES + int "Maximum number of nodes whose information can be stored" + default 20 + range 1 1000 + help + This option specifies the maximum number of nodes whose information can be + stored by a provisioner in its upper layer. + + config BLE_MESH_MAX_PROV_NODES + int "Maximum number of devices that can be provisioned by provisioner" + default 20 + range 1 100 + help + This option specifies how many devices can be provisioned by provisioner. + + if BLE_MESH_PB_ADV + config BLE_MESH_PBA_SAME_TIME + int "Maximum number of PB-ADV running at the same time by provisioner" + default 10 + range 1 30 + help + This option specifies how many devices can be provisioned at the same + time using PB-ADV. + endif # BLE_MESH_PB_ADV + + if BLE_MESH_PB_GATT + config BLE_MESH_PBG_SAME_TIME + int "Maximum number of PB-GATT running at the same time by provisioner" + default 4 + range 1 5 + help + This option specifies how many devices can be provisioned at the same + time using PB-GATT. + endif # BLE_MESH_PB_GATT + + config BLE_MESH_PROVISIONER_SUBNET_COUNT + int "Maximum number of mesh subnets that can be created by provisioner" + default 3 + range 1 4096 + help + This option specifies how many subnets per network a provisioner can create. + + config BLE_MESH_PROVISIONER_APP_KEY_COUNT + int "Maximum number of application keys that can be owned by provisioner" + default 9 + range 1 4096 + help + This option specifies how many application keys the provisioner can have. + + endif # BLE_MESH_PROVISIONER + + # Virtual option enabled whenever Generic Provisioning layer is needed + config BLE_MESH_PROV + bool "BLE Mesh Provisioning support" + default y + help + Enable this option to support BLE Mesh Provisioning functionality. For + BLE Mesh, this option should be always enabled. + + config BLE_MESH_PB_ADV + bool "Provisioning support using the advertising bearer (PB-ADV)" + select BLE_MESH_PROV + default y + help + Enable this option to allow the device to be provisioned over the + advertising bearer. + + config BLE_MESH_PB_GATT + bool "Provisioning support using GATT (PB-GATT)" + select BLE_MESH_PROXY + select BLE_MESH_PROV + help + Enable this option to allow the device to be provisioned over GATT. + + # Virtual option enabled whenever any Proxy protocol is needed + config BLE_MESH_PROXY + bool "BLE Mesh Proxy protocol support" + default y + help + Enable this option to support BLE Mesh Proxy protocol used by PB-GATT + and other proxy pdu transmission. + + config BLE_MESH_GATT_PROXY + bool "BLE Mesh GATT Proxy Service" + select BLE_MESH_PROXY + help + This option enables support for Mesh GATT Proxy Service, i.e. the + ability to act as a proxy between a Mesh GATT Client and a Mesh network. + + config BLE_MESH_NODE_ID_TIMEOUT + int "Node Identity advertising timeout" + depends on BLE_MESH_GATT_PROXY + range 1 60 + default 60 + help + This option determines for how long the local node advertises using + Node Identity. The given value is in seconds. The specification limits + this to 60 seconds and lists it as the recommended value as well. + So leaving the default value is the safest option. + + if BLE_MESH_PROXY + + config BLE_MESH_PROXY_FILTER_SIZE + int "Maximum number of filter entries per Proxy Client" + default 1 + default 3 if BLE_MESH_GATT_PROXY + range 1 32767 + help + This option specifies how many Proxy Filter entries the local node supports. + + endif # BLE_MESH_PROXY + + config BLE_MESH_NET_BUF_POOL_USAGE + bool "BLE Mesh net buffer pool usage tracking" + default y + help + Enable BLE Mesh net buffer pool tracking. + + config BLE_MESH_SETTINGS + bool "Store BLE Mesh Node configuration persistently" + default n + help + When selected, the BLE Mesh stack will take care of storing/restoring the + BLE Mesh configuration persistently in flash. Currently this only supports + storing BLE Mesh node configuration. + + if BLE_MESH_SETTINGS + config BLE_MESH_STORE_TIMEOUT + int "Delay (in seconds) before storing anything persistently" + range 0 1000000 + default 2 + help + This value defines in seconds how soon any pending changes are actually + written into persistent storage (flash) after a change occurs. + + config BLE_MESH_SEQ_STORE_RATE + int "How often the sequence number gets updated in storage" + range 0 1000000 + default 128 + help + This value defines how often the local sequence number gets updated in + persistent storage (i.e. flash). e.g. a value of 100 means that the + sequence number will be stored to flash on every 100th increment. + If the node sends messages very frequently a higher value makes more + sense, whereas if the node sends infrequently a value as low as 0 + (update storage for every increment) can make sense. When the stack + gets initialized it will add sequence number to the last stored one, + so that it starts off with a value that's guaranteed to be larger than + the last one used before power off. + + config BLE_MESH_RPL_STORE_TIMEOUT + int "Minimum frequency that the RPL gets updated in storage" + range 0 1000000 + default 5 + help + This value defines in seconds how soon the RPL gets written to persistent + storage after a change occurs. If the node receives messages frequently, + then a large value is recommended. If the node receives messages rarely, + then the value can be as low as 0 (which means the PRL is written into the + storage immediately). + Note that if the node operates in a security-sensitive case, and there is + a risk of sudden power-off, then a value of 0 is strongly recommended. + Otherwise, a power loss before RPL being written into the storage may + introduce message replay attacks and system security will be in a + vulnerable state. + endif # if BLE_MESH_SETTINGS + + config BLE_MESH_SUBNET_COUNT + int "Maximum number of mesh subnets per network" + default 1 + range 1 4096 + help + This option specifies how many subnets a Mesh network can have at the same time. + + config BLE_MESH_APP_KEY_COUNT + int "Maximum number of application keys per network" + default 1 + range 1 4096 + help + This option specifies how many application keys the device can store per network. + + config BLE_MESH_MODEL_KEY_COUNT + int "Maximum number of application keys per model" + default 1 + range 1 4096 + help + This option specifies the maximum number of application keys to which each model + can be bound. + + config BLE_MESH_MODEL_GROUP_COUNT + int "Maximum number of group address subscriptions per model" + default 1 + range 1 4096 + help + This option specifies the maximum number of addresses to which each model can + be subscribed. + + config BLE_MESH_LABEL_COUNT + int "Maximum number of Label UUIDs used for Virtual Addresses" + default 1 + range 0 4096 + help + This option specifies how many Label UUIDs can be stored. + + config BLE_MESH_CRPL + int "Maximum capacity of the replay protection list" + default 10 + range 2 65535 + help + This options specifies the maximum capacity of the replay protection list. + It is similar to Network message cache size, but has a different purpose. + + config BLE_MESH_MSG_CACHE_SIZE + int "Network message cache size" + default 10 + range 2 65535 + help + Number of messages that are cached for the network. This helps prevent + unnecessary decryption operations and unnecessary relays. This option + is similar to Replay protection list, but has a different purpose. + + config BLE_MESH_ADV_BUF_COUNT + int "Number of advertising buffers" + default 60 + range 6 256 + help + Number of advertising buffers available. The transport layer reserves + ADV_BUF_COUNT - 3 buffers for outgoing segments. The maximum outgoing + SDU size is 12 times this value (out of which 4 or 8 bytes are used + for the Transport Layer MIC). For example, 5 segments means the maximum + SDU size is 60 bytes, which leaves 56 bytes for application layer data + using a 4-byte MIC, or 52 bytes using an 8-byte MIC. + + config BLE_MESH_TX_SEG_MSG_COUNT + int "Maximum number of simultaneous outgoing segmented messages" + default 1 + range 1 BLE_MESH_ADV_BUF_COUNT + help + Maximum number of simultaneous outgoing multi-segment and/or reliable messages. + + config BLE_MESH_RX_SEG_MSG_COUNT + int "Maximum number of simultaneous incoming segmented messages" + default 1 + range 1 255 + help + Maximum number of simultaneous incoming multi-segment and/or reliable messages. + + config BLE_MESH_RX_SDU_MAX + int "Maximum incoming Upper Transport Access PDU length" + default 384 + range 36 384 + help + Maximum incoming Upper Transport Access PDU length. Leave this to the default + value, unless you really need to optimize memory usage. + + config BLE_MESH_RELAY + bool "Relay support" + help + Support for acting as a Mesh Relay Node. + + config BLE_MESH_LOW_POWER + bool "Support for Low Power features" + help + Enable this option to operate as a Low Power Node. + + if BLE_MESH_LOW_POWER + + config BLE_MESH_LPN_ESTABLISHMENT + bool "Perform Friendship establishment using low power" + default y + help + Perform the Friendship establishment using low power with the help of a + reduced scan duty cycle. The downside of this is that the node may miss + out on messages intended for it until it has successfully set up Friendship + with a Friend node. + + config BLE_MESH_LPN_AUTO + bool "Automatically start looking for Friend nodes once provisioned" + default y + help + Once provisioned, automatically enable LPN functionality and start looking + for Friend nodes. If this option is disabled LPN mode needs to be manually + enabled by calling bt_mesh_lpn_set(true). + + config BLE_MESH_LPN_AUTO_TIMEOUT + int "Time from last received message before going to LPN mode" + default 15 + range 0 3600 + depends on BLE_MESH_LPN_AUTO + help + Time in seconds from the last received message, that the node waits out + before starting to look for Friend nodes. + + config BLE_MESH_LPN_RETRY_TIMEOUT + int "Retry timeout for Friend requests" + default 8 + range 1 3600 + help + Time in seconds between Friend Requests, if a previous Friend Request did + not yield any acceptable Friend Offers. + + config BLE_MESH_LPN_RSSI_FACTOR + int "RSSIFactor, used in Friend Offer Delay calculation" + range 0 3 + default 0 + help + The contribution of the RSSI, measured by the Friend node, used in Friend + Offer Delay calculations. 0 = 1, 1 = 1.5, 2 = 2, 3 = 2.5. + + config BLE_MESH_LPN_RECV_WIN_FACTOR + int "ReceiveWindowFactor, used in Friend Offer Delay calculation" + range 0 3 + default 0 + help + The contribution of the supported Receive Window used in Friend Offer + Delay calculations. 0 = 1, 1 = 1.5, 2 = 2, 3 = 2.5. + + config BLE_MESH_LPN_MIN_QUEUE_SIZE + int "Minimum size of the acceptable friend queue (MinQueueSizeLog)" + range 1 7 + default 1 + help + The MinQueueSizeLog field is defined as log_2(N), where N is the minimum + number of maximum size Lower Transport PDUs that the Friend node can store + in its Friend Queue. As an example, MinQueueSizeLog value 1 gives N = 2, + and value 7 gives N = 128. + + config BLE_MESH_LPN_RECV_DELAY + int "Receive delay requested by the local node" + range 10 255 + default 100 + help + The ReceiveDelay is the time between the Low Power node sending a + request and listening for a response. This delay allows the Friend + node time to prepare the response. The value is in units of milliseconds. + + config BLE_MESH_LPN_POLL_TIMEOUT + int "The value of the PollTimeout timer" + range 10 244735 + default 300 + help + PollTimeout timer is used to measure time between two consecutive + requests sent by a Low Power node. If no requests are received + the Friend node before the PollTimeout timer expires, then the + friendship is considered terminated. The value is in units of 100 + milliseconds, so e.g. a value of 300 means 30 seconds. + + config BLE_MESH_LPN_INIT_POLL_TIMEOUT + int "The starting value of the PollTimeout timer" + range 10 BLE_MESH_LPN_POLL_TIMEOUT + default BLE_MESH_LPN_POLL_TIMEOUT + help + The initial value of the PollTimeout timer when Friendship is to be + established for the first time. After this, the timeout gradually + grows toward the actual PollTimeout, doubling in value for each iteration. + The value is in units of 100 milliseconds, so e.g. a value of 300 means + 30 seconds. + + config BLE_MESH_LPN_SCAN_LATENCY + int "Latency for enabling scanning" + range 0 50 + default 10 + help + Latency (in milliseconds) is the time it takes to enable scanning. In + practice, it means how much time in advance of the Receive Window, the + request to enable scanning is made. + + config BLE_MESH_LPN_GROUPS + int "Number of groups the LPN can subscribe to" + range 0 16384 + default 8 + help + Maximum number of groups to which the LPN can subscribe. + endif # BLE_MESH_LOW_POWER + + config BLE_MESH_FRIEND + bool "Support for acting as a Friend Node" + help + Enable this option to be able to act as a Friend Node. + + if BLE_MESH_FRIEND + + config BLE_MESH_FRIEND_RECV_WIN + int "Friend Receive Window" + range 1 255 + default 255 + help + Receive Window in milliseconds supported by the Friend node. + + config BLE_MESH_FRIEND_QUEUE_SIZE + int "Minimum number of buffers supported per Friend Queue" + range 2 65536 + default 16 + help + Minimum number of buffers available to be stored for each local Friend Queue. + + config BLE_MESH_FRIEND_SUB_LIST_SIZE + int "Friend Subscription List Size" + range 0 1023 + default 3 + help + Size of the Subscription List that can be supported by a Friend node for a + Low Power node. + + config BLE_MESH_FRIEND_LPN_COUNT + int "Number of supported LPN nodes" + range 1 1000 + default 2 + help + Number of Low Power Nodes with which a Friend can have Friendship simultaneously. + + config BLE_MESH_FRIEND_SEG_RX + int "Number of incomplete segment lists per LPN" + range 1 1000 + default 1 + help + Number of incomplete segment lists tracked for each Friends' LPN. + In other words, this determines from how many elements can segmented + messages destined for the Friend queue be received simultaneously. + + endif # BLE_MESH_FRIEND + + config BLE_MESH_NO_LOG + bool "Disable BLE Mesh debug logs (minimize bin size)" + depends on BLE_MESH + default n + help + Select this to save the BLE Mesh related rodata code size. + + menu "BLE Mesh STACK DEBUG LOG LEVEL" + depends on BLE_MESH && !BLE_MESH_NO_LOG + + choice BLE_MESH_STACK_TRACE_LEVEL + prompt "BLE_MESH_STACK" + default BLE_MESH_TRACE_LEVEL_WARNING + depends on BLE_MESH && !BLE_MESH_NO_LOG + help + Define BLE Mesh trace level for BLE Mesh stack. + + config BLE_MESH_TRACE_LEVEL_NONE + bool "NONE" + config BLE_MESH_TRACE_LEVEL_ERROR + bool "ERROR" + config BLE_MESH_TRACE_LEVEL_WARNING + bool "WARNING" + config BLE_MESH_TRACE_LEVEL_INFO + bool "INFO" + config BLE_MESH_TRACE_LEVEL_DEBUG + bool "DEBUG" + config BLE_MESH_TRACE_LEVEL_VERBOSE + bool "VERBOSE" + endchoice + + config BLE_MESH_STACK_TRACE_LEVEL + int + depends on BLE_MESH + default 0 if BLE_MESH_TRACE_LEVEL_NONE + default 1 if BLE_MESH_TRACE_LEVEL_ERROR + default 2 if BLE_MESH_TRACE_LEVEL_WARNING + default 3 if BLE_MESH_TRACE_LEVEL_INFO + default 4 if BLE_MESH_TRACE_LEVEL_DEBUG + default 5 if BLE_MESH_TRACE_LEVEL_VERBOSE + default 2 + + endmenu #BLE Mesh DEBUG LOG LEVEL + + menu "BLE Mesh NET BUF DEBUG LOG LEVEL" + depends on BLE_MESH && !BLE_MESH_NO_LOG + + choice BLE_MESH_NET_BUF_TRACE_LEVEL + prompt "BLE_MESH_NET_BUF" + default BLE_MESH_NET_BUF_TRACE_LEVEL_WARNING + depends on BLE_MESH && !BLE_MESH_NO_LOG + help + Define BLE Mesh trace level for BLE Mesh net buffer. + + config BLE_MESH_NET_BUF_TRACE_LEVEL_NONE + bool "NONE" + config BLE_MESH_NET_BUF_TRACE_LEVEL_ERROR + bool "ERROR" + config BLE_MESH_NET_BUF_TRACE_LEVEL_WARNING + bool "WARNING" + config BLE_MESH_NET_BUF_TRACE_LEVEL_INFO + bool "INFO" + config BLE_MESH_NET_BUF_TRACE_LEVEL_DEBUG + bool "DEBUG" + config BLE_MESH_NET_BUF_TRACE_LEVEL_VERBOSE + bool "VERBOSE" + endchoice + + config BLE_MESH_NET_BUF_TRACE_LEVEL + int + depends on BLE_MESH + default 0 if BLE_MESH_NET_BUF_TRACE_LEVEL_NONE + default 1 if BLE_MESH_NET_BUF_TRACE_LEVEL_ERROR + default 2 if BLE_MESH_NET_BUF_TRACE_LEVEL_WARNING + default 3 if BLE_MESH_NET_BUF_TRACE_LEVEL_INFO + default 4 if BLE_MESH_NET_BUF_TRACE_LEVEL_DEBUG + default 5 if BLE_MESH_NET_BUF_TRACE_LEVEL_VERBOSE + default 2 + + endmenu #BLE Mesh NET BUF DEBUG LOG LEVEL + + config BLE_MESH_IRQ_LOCK + bool "Used the IRQ lock instead of task lock" + help + To improve the real-time requirements of bt controller in BLE Mesh, + task lock is used to replace IRQ lock. + + config BLE_MESH_CLIENT_MSG_TIMEOUT + int "Timeout(ms) for client message response" + range 100 1200000 + default 4000 + help + Timeout value used by the node to get response of the acknowledged + message which is sent by the client model. + + menu "Support for BLE Mesh Client Models" + + config BLE_MESH_CFG_CLI + bool "Configuration Client Model" + help + Enable support for Configuration client model. + + config BLE_MESH_HEALTH_CLI + bool "Health Client Model" + help + Enable support for Health client model. + + config BLE_MESH_GENERIC_ONOFF_CLI + bool "Generic OnOff Client Model" + help + Enable support for Generic OnOff client model. + + config BLE_MESH_GENERIC_LEVEL_CLI + bool "Generic Level Client Model" + help + Enable support for Generic Level client model. + + config BLE_MESH_GENERIC_DEF_TRANS_TIME_CLI + bool "Generic Default Transition Time Client Model" + help + Enable support for Generic Default Transition Time client model. + + config BLE_MESH_GENERIC_POWER_ONOFF_CLI + bool "Generic Power Onoff Client Model" + help + Enable support for Generic Power Onoff client model. + + config BLE_MESH_GENERIC_POWER_LEVEL_CLI + bool "Generic Power Level Client Model" + help + Enable support for Generic Power Level client model. + + config BLE_MESH_GENERIC_BATTERY_CLI + bool "Generic Battery Client Model" + help + Enable support for Generic Battery client model. + + config BLE_MESH_GENERIC_LOCATION_CLI + bool "Generic Location Client Model" + help + Enable support for Generic Location client model. + + config BLE_MESH_GENERIC_PROPERTY_CLI + bool "Generic Property Client Model" + help + Enable support for Generic Property client model. + + config BLE_MESH_SENSOR_CLI + bool "Sensor Client Model" + help + Enable support for Sensor client model. + + config BLE_MESH_TIME_CLI + bool "Time Client Model" + help + Enable support for Time client model. + + config BLE_MESH_SCENE_CLI + bool "Scene Client Model" + help + Enable support for Scene client model. + + config BLE_MESH_SCHEDULER_CLI + bool "Scheduler Client Model" + help + Enable support for Scheduler client model. + + config BLE_MESH_LIGHT_LIGHTNESS_CLI + bool "Light Lightness Client Model" + help + Enable support for Light Lightness client model. + + config BLE_MESH_LIGHT_CTL_CLI + bool "Light CTL Client Model" + help + Enable support for Light CTL client model. + + config BLE_MESH_LIGHT_HSL_CLI + bool "Light HSL Client Model" + help + Enable support for Light HSL client model. + + config BLE_MESH_LIGHT_XYL_CLI + bool "Light XYL Client Model" + help + Enable support for Light XYL client model. + + config BLE_MESH_LIGHT_LC_CLI + bool "Light LC Client Model" + help + Enable support for Light LC client model. + + endmenu + + config BLE_MESH_IV_UPDATE_TEST + bool "Test the IV Update Procedure" + default n + help + This option removes the 96 hour limit of the IV Update Procedure and + lets the state to be changed at any time. + + menu "BLE Mesh specific test option" + + config BLE_MESH_SELF_TEST + bool "Perform BLE Mesh self-tests" + default n + help + This option adds extra self-tests which are run every time BLE Mesh + networking is initialized. + + config BLE_MESH_SHELL + bool "Enable BLE Mesh shell" + default n + help + Activate shell module that provides BLE Mesh commands to the console. + + config BLE_MESH_DEBUG + bool "Enable BLE Mesh debug logs" + default n + help + Enable debug logs for the BLE Mesh functionality. + + if BLE_MESH_DEBUG + + config BLE_MESH_DEBUG_NET + bool "Network layer debug" + help + Enable Network layer debug logs for the BLE Mesh functionality. + + config BLE_MESH_DEBUG_TRANS + bool "Transport layer debug" + help + Enable Transport layer debug logs for the BLE Mesh functionality. + + config BLE_MESH_DEBUG_BEACON + bool "Beacon debug" + help + Enable Beacon-related debug logs for the BLE Mesh functionality. + + config BLE_MESH_DEBUG_CRYPTO + bool "Crypto debug" + help + Enable cryptographic debug logs for the BLE Mesh functionality. + + config BLE_MESH_DEBUG_PROV + bool "Provisioning debug" + help + Enable Provisioning debug logs for the BLE Mesh functionality. + + config BLE_MESH_DEBUG_ACCESS + bool "Access layer debug" + help + Enable Access layer debug logs for the BLE Mesh functionality. + + config BLE_MESH_DEBUG_MODEL + bool "Foundation model debug" + help + Enable Foundation Models debug logs for the BLE Mesh functionality. + + config BLE_MESH_DEBUG_ADV + bool "Advertising debug" + help + Enable advertising debug logs for the BLE Mesh functionality. + + config BLE_MESH_DEBUG_LOW_POWER + bool "Low Power debug" + help + Enable Low Power debug logs for the BLE Mesh functionality. + + config BLE_MESH_DEBUG_FRIEND + bool "Friend debug" + help + Enable Friend debug logs for the BLE Mesh functionality. + + config BLE_MESH_DEBUG_PROXY + bool "Proxy debug" + depends on BLE_MESH_PROXY + help + Enable Proxy protocol debug logs for the BLE Mesh functionality. + + endif # BLE_MESH_DEBUG + + endmenu + +endif # BLE_MESH diff --git a/components/bt/ble_mesh/api/core/esp_ble_mesh_common_api.c b/components/bt/ble_mesh/api/core/esp_ble_mesh_common_api.c index 33019c6e60..4172ef0c7d 100644 --- a/components/bt/ble_mesh/api/core/esp_ble_mesh_common_api.c +++ b/components/bt/ble_mesh/api/core/esp_ble_mesh_common_api.c @@ -12,66 +12,59 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include -#include +#include #include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/queue.h" #include "freertos/semphr.h" #include "btc/btc_task.h" #include "btc/btc_manage.h" -#include "osi/allocator.h" -#include "esp_bt_defs.h" #include "esp_err.h" +#include "esp_bt_defs.h" #include "esp_bt_main.h" -#include "sdkconfig.h" #include "btc_ble_mesh_prov.h" - -#include "mesh.h" -#include "mesh_buf.h" -#include "transport.h" -#include "esp_ble_mesh_common_api.h" - -#if CONFIG_BT_MESH +#include "esp_ble_mesh_defs.h" esp_err_t esp_ble_mesh_init(esp_ble_mesh_prov_t *prov, esp_ble_mesh_comp_t *comp) { - btc_msg_t msg; btc_ble_mesh_prov_args_t arg = {0}; - xSemaphoreHandle semaphore = NULL; + SemaphoreHandle_t semaphore = NULL; + btc_msg_t msg = {0}; + + if (prov == NULL || comp == NULL) { + return ESP_ERR_INVALID_ARG; + } ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); // Create a semaphore if ((semaphore = xSemaphoreCreateCounting(1, 0)) == NULL) { - LOG_ERROR("%s, unable to allocate memory for the semaphore.", __func__); + LOG_ERROR("%s, Failed to allocate memory for the semaphore", __func__); return ESP_ERR_NO_MEM; } + arg.mesh_init.prov = prov; + arg.mesh_init.comp = comp; + /* Transport semaphore pointer to BTC layer, and will give the semaphore in the BTC task */ + arg.mesh_init.semaphore = semaphore; + msg.sig = BTC_SIG_API_CALL; msg.pid = BTC_PID_PROV; - msg.act = BTC_BLE_MESH_ACT_APP_REGISTER; - arg.mesh_reg.prov = prov; - arg.mesh_reg.comp = comp; - // semaphore pointer transport to BTC layer, we will give the semaphore in the BTC task. - arg.mesh_reg.semaphore = semaphore; + msg.act = BTC_BLE_MESH_ACT_MESH_INIT; if (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL) != BT_STATUS_SUCCESS) { vSemaphoreDelete(semaphore); - LOG_ERROR("BLE Mesh initialise failed"); + LOG_ERROR("%s, BLE Mesh initialise failed", __func__); return ESP_FAIL; } - // Take the Semaphore, wait to BLE Mesh init finish. + /* Take the Semaphore, wait BLE Mesh initialization to finish. */ xSemaphoreTake(semaphore, portMAX_DELAY); - // Don't forget to delete the semaphore at the end. + /* Don't forget to delete the semaphore at the end. */ vSemaphoreDelete(semaphore); + return ESP_OK; } -#endif /* #if CONFIG_BT_MESH */ - diff --git a/components/bt/ble_mesh/api/core/esp_ble_mesh_local_data_operation_api.c b/components/bt/ble_mesh/api/core/esp_ble_mesh_local_data_operation_api.c index d036f303f7..0997a96d3e 100644 --- a/components/bt/ble_mesh/api/core/esp_ble_mesh_local_data_operation_api.c +++ b/components/bt/ble_mesh/api/core/esp_ble_mesh_local_data_operation_api.c @@ -12,31 +12,23 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include #include "btc/btc_task.h" #include "btc/btc_manage.h" -#include "osi/allocator.h" -#include "esp_bt_defs.h" #include "esp_err.h" +#include "esp_bt_defs.h" #include "esp_bt_main.h" -#include "sdkconfig.h" #include "btc_ble_mesh_prov.h" - -#include "mesh.h" -#include "mesh_buf.h" -#include "transport.h" #include "esp_ble_mesh_defs.h" -#if CONFIG_BT_MESH - int32_t esp_ble_mesh_get_model_publish_period(esp_ble_mesh_model_t *model) { if (model == NULL) { - return -EINVAL; + return 0; } return btc_ble_mesh_model_pub_period_get(model); } @@ -86,5 +78,3 @@ const esp_ble_mesh_comp_t *esp_ble_mesh_get_composition_data(void) return btc_ble_mesh_comp_get(); } -#endif /* #if CONFIG_BT_MESH */ - diff --git a/components/bt/ble_mesh/api/core/esp_ble_mesh_low_power_api.c b/components/bt/ble_mesh/api/core/esp_ble_mesh_low_power_api.c index 14158ec4d5..6d3745ca6e 100644 --- a/components/bt/ble_mesh/api/core/esp_ble_mesh_low_power_api.c +++ b/components/bt/ble_mesh/api/core/esp_ble_mesh_low_power_api.c @@ -12,26 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include -#include +#include #include "btc/btc_task.h" #include "btc/btc_manage.h" -#include "osi/allocator.h" -#include "esp_bt_defs.h" #include "esp_err.h" +#include "esp_bt_defs.h" #include "esp_bt_main.h" -#include "sdkconfig.h" #include "btc_ble_mesh_prov.h" - -#include "mesh.h" -#include "mesh_buf.h" -#include "transport.h" #include "esp_ble_mesh_defs.h" -#if CONFIG_BT_MESH - -#endif /* #if CONFIG_BT_MESH */ - diff --git a/components/bt/ble_mesh/api/core/esp_ble_mesh_networking_api.c b/components/bt/ble_mesh/api/core/esp_ble_mesh_networking_api.c index f3ad8df547..9e920dd113 100644 --- a/components/bt/ble_mesh/api/core/esp_ble_mesh_networking_api.c +++ b/components/bt/ble_mesh/api/core/esp_ble_mesh_networking_api.c @@ -12,28 +12,20 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include #include "btc/btc_task.h" #include "btc/btc_manage.h" -#include "osi/allocator.h" -#include "esp_bt_defs.h" #include "esp_err.h" +#include "esp_bt_defs.h" #include "esp_bt_main.h" -#include "sdkconfig.h" #include "btc_ble_mesh_prov.h" - -#include "mesh.h" -#include "mesh_buf.h" -#include "transport.h" -#include "provisioner_main.h" -#include "esp_ble_mesh_defs.h" #include "esp_ble_mesh_networking_api.h" -#if CONFIG_BT_MESH +#define ESP_BLE_MESH_TX_SDU_MAX ((CONFIG_BLE_MESH_ADV_BUF_COUNT - 3) * 12) static esp_err_t ble_mesh_send_msg(esp_ble_mesh_model_t *model, esp_ble_mesh_msg_ctx_t *ctx, @@ -43,11 +35,11 @@ static esp_err_t ble_mesh_send_msg(esp_ble_mesh_model_t *model, int32_t msg_timeout, bool need_rsp, esp_ble_mesh_dev_role_t device_role) { - btc_msg_t msg; - btc_ble_mesh_model_args_t arg; - esp_err_t status; + btc_ble_mesh_model_args_t arg = {0}; uint8_t op_len = 0, mic_len = 0; uint8_t *msg_data = NULL; + btc_msg_t msg = {0}; + esp_err_t status; ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); @@ -70,7 +62,7 @@ static esp_err_t ble_mesh_send_msg(esp_ble_mesh_model_t *model, if (act == BTC_BLE_MESH_ACT_MODEL_PUBLISH) { if (op_len + length > model->pub->msg->size) { - LOG_ERROR("%s: model->pub->msg->size %d is too small", __func__, model->pub->msg->size); + LOG_ERROR("%s, Model publication msg size %d is too small", __func__, model->pub->msg->size); return ESP_ERR_INVALID_ARG; } } @@ -81,8 +73,8 @@ static esp_err_t ble_mesh_send_msg(esp_ble_mesh_model_t *model, mic_len = ctx->send_rel ? 8 : 4; } - if (op_len + length + mic_len > MIN(ESP_BLE_MESH_SDU_MAX_LEN, BT_MESH_TX_SDU_MAX)) { - LOG_ERROR("%s: The data length %d is too large", __func__, length); + if (op_len + length + mic_len > MIN(ESP_BLE_MESH_SDU_MAX_LEN, ESP_BLE_MESH_TX_SDU_MAX)) { + LOG_ERROR("%s, Data length %d is too large", __func__, length); return ESP_ERR_INVALID_ARG; } @@ -148,19 +140,23 @@ esp_err_t esp_ble_mesh_model_msg_opcode_init(uint8_t *data, uint32_t opcode) if (opcode < 0x10000) { /* 2-byte OpCode, big endian */ val = sys_cpu_to_be16 (opcode); - memcpy (data, &val, 2); + memcpy(data, &val, 2); return ESP_OK; } /* 3-byte OpCode, note that little endian for the least 2 bytes(Company ID) of opcode */ data[0] = (opcode >> 16) & 0xff; val = sys_cpu_to_le16(opcode & 0xffff); - memcpy (&data[1], &val, 2); + memcpy(&data[1], &val, 2); + return ESP_OK; } -int esp_ble_mesh_client_model_init(esp_ble_mesh_model_t *model) +esp_err_t esp_ble_mesh_client_model_init(esp_ble_mesh_model_t *model) { + if (model == NULL) { + return ESP_ERR_INVALID_ARG; + } return btc_ble_mesh_client_init(model); } @@ -200,7 +196,7 @@ esp_err_t esp_ble_mesh_model_publish(esp_ble_mesh_model_t *model, uint32_t opcod esp_err_t esp_ble_mesh_node_local_reset(void) { - btc_msg_t msg; + btc_msg_t msg = {0}; ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); @@ -211,17 +207,17 @@ esp_err_t esp_ble_mesh_node_local_reset(void) return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } -#if (CONFIG_BT_MESH_PROVISIONER) +#if (CONFIG_BLE_MESH_PROVISIONER) esp_err_t esp_ble_mesh_provisioner_set_node_name(int index, const char *name) { + btc_ble_mesh_prov_args_t arg = {0}; + btc_msg_t msg = {0}; + if (!name || (strlen(name) > ESP_BLE_MESH_NODE_NAME_MAX_LEN)) { return ESP_ERR_INVALID_ARG; } - btc_msg_t msg; - btc_ble_mesh_prov_args_t arg; - ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; @@ -252,8 +248,8 @@ int esp_ble_mesh_provisioner_get_node_index(const char *name) 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) { - btc_msg_t msg; - btc_ble_mesh_prov_args_t arg; + btc_ble_mesh_prov_args_t arg = {0}; + btc_msg_t msg = {0}; ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); @@ -280,13 +276,13 @@ 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) { + btc_ble_mesh_prov_args_t arg = {0}; + btc_msg_t msg = {0}; + if (!ESP_BLE_MESH_ADDR_IS_UNICAST(element_addr)) { return ESP_ERR_INVALID_ARG; } - btc_msg_t msg; - btc_ble_mesh_prov_args_t arg; - ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; @@ -303,13 +299,13 @@ esp_err_t esp_ble_mesh_provisioner_bind_app_key_to_local_model(uint16_t element_ esp_err_t esp_ble_mesh_provisioner_add_local_net_key(const uint8_t net_key[16], uint16_t net_idx) { + btc_ble_mesh_prov_args_t arg = {0}; + btc_msg_t msg = {0}; + if (net_idx == ESP_BLE_MESH_KEY_PRIMARY) { return ESP_ERR_INVALID_ARG; } - btc_msg_t msg; - btc_ble_mesh_prov_args_t arg; - ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; @@ -331,14 +327,12 @@ const uint8_t *esp_ble_mesh_provisioner_get_local_net_key(uint16_t net_idx) return bt_mesh_provisioner_local_net_key_get(net_idx); } -#endif /* CONFIG_BT_MESH_PROVISIONER */ +#endif /* CONFIG_BLE_MESH_PROVISIONER */ -#if (CONFIG_BT_MESH_FAST_PROV) +#if (CONFIG_BLE_MESH_FAST_PROV) const uint8_t *esp_ble_mesh_get_fast_prov_app_key(uint16_t net_idx, uint16_t app_idx) { return bt_mesh_get_fast_prov_app_key(net_idx, app_idx); } -#endif /* CONFIG_BT_MESH_FAST_PROV */ - -#endif /* #if CONFIG_BT_MESH */ +#endif /* CONFIG_BLE_MESH_FAST_PROV */ diff --git a/components/bt/ble_mesh/api/core/esp_ble_mesh_provisioning_api.c b/components/bt/ble_mesh/api/core/esp_ble_mesh_provisioning_api.c index 42b8f55c4d..855bcf188f 100644 --- a/components/bt/ble_mesh/api/core/esp_ble_mesh_provisioning_api.c +++ b/components/bt/ble_mesh/api/core/esp_ble_mesh_provisioning_api.c @@ -12,30 +12,19 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include -#include +#include #include "btc/btc_task.h" #include "btc/btc_manage.h" -#include "osi/allocator.h" -#include "esp_bt_defs.h" #include "esp_err.h" +#include "esp_bt_defs.h" #include "esp_bt_main.h" -#include "sdkconfig.h" #include "btc_ble_mesh_prov.h" - -#include "mesh.h" -#include "mesh_buf.h" -#include "transport.h" -#include "provisioner_prov.h" -#include "esp_ble_mesh_defs.h" #include "esp_ble_mesh_provisioning_api.h" -#if CONFIG_BT_MESH - -#define MAX_PROV_LINK_IDX (CONFIG_BT_MESH_PBA_SAME_TIME + CONFIG_BT_MESH_PBG_SAME_TIME) +#define MAX_PROV_LINK_IDX (CONFIG_BLE_MESH_PBA_SAME_TIME + CONFIG_BLE_MESH_PBG_SAME_TIME) #define MAX_OOB_INPUT_NUM 0x5F5E0FF /* Decimal: 99999999 */ esp_err_t esp_ble_mesh_register_prov_callback(esp_ble_mesh_prov_cb_t callback) @@ -52,15 +41,15 @@ bool esp_ble_mesh_node_is_provisioned(void) esp_err_t esp_ble_mesh_node_prov_enable(esp_ble_mesh_prov_bearer_t bearers) { - btc_msg_t msg; - btc_ble_mesh_prov_args_t arg; + btc_ble_mesh_prov_args_t arg = {0}; + btc_msg_t msg = {0}; ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; msg.pid = BTC_PID_PROV; msg.act = BTC_BLE_MESH_ACT_PROV_ENABLE; - arg.mesh_prov_enable.bearers = bearers; + arg.node_prov_enable.bearers = bearers; return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); @@ -68,15 +57,15 @@ esp_err_t esp_ble_mesh_node_prov_enable(esp_ble_mesh_prov_bearer_t bearers) esp_err_t esp_ble_mesh_node_prov_disable(esp_ble_mesh_prov_bearer_t bearers) { - btc_msg_t msg; - btc_ble_mesh_prov_args_t arg; + btc_ble_mesh_prov_args_t arg = {0}; + btc_msg_t msg = {0}; ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; msg.pid = BTC_PID_PROV; msg.act = BTC_BLE_MESH_ACT_PROV_DISABLE; - arg.mesh_prov_disable.bearers = bearers; + arg.node_prov_disable.bearers = bearers; return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); @@ -85,8 +74,8 @@ 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]) { - btc_msg_t msg; - btc_ble_mesh_prov_args_t arg; + btc_ble_mesh_prov_args_t arg = {0}; + btc_msg_t msg = {0}; if (!pub_key_x || !pub_key_y || !private_key) { return ESP_ERR_INVALID_ARG; @@ -108,8 +97,8 @@ esp_err_t esp_ble_mesh_node_set_oob_pub_key(uint8_t pub_key_x[32], uint8_t pub_k esp_err_t esp_ble_mesh_node_input_number(uint32_t number) { - btc_msg_t msg; - btc_ble_mesh_prov_args_t arg; + btc_ble_mesh_prov_args_t arg = {0}; + btc_msg_t msg = {0}; if (number > MAX_OOB_INPUT_NUM) { return ESP_ERR_INVALID_ARG; @@ -120,7 +109,7 @@ esp_err_t esp_ble_mesh_node_input_number(uint32_t number) msg.sig = BTC_SIG_API_CALL; msg.pid = BTC_PID_PROV; msg.act = BTC_BLE_MESH_ACT_INPUT_NUMBER; - arg.input_num.number = number; + arg.input_number.number = number; return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); @@ -128,8 +117,8 @@ esp_err_t esp_ble_mesh_node_input_number(uint32_t number) esp_err_t esp_ble_mesh_node_input_string(const char *string) { - btc_msg_t msg; - btc_ble_mesh_prov_args_t arg; + btc_ble_mesh_prov_args_t arg = {0}; + btc_msg_t msg = {0}; if (!string) { return ESP_ERR_INVALID_ARG; @@ -140,8 +129,8 @@ esp_err_t esp_ble_mesh_node_input_string(const char *string) msg.sig = BTC_SIG_API_CALL; msg.pid = BTC_PID_PROV; msg.act = BTC_BLE_MESH_ACT_INPUT_STRING; - memset(arg.input_str.string, 0, sizeof(arg.input_str.string)); - strncpy(arg.input_str.string, string, strlen(string)); + memset(arg.input_string.string, 0, sizeof(arg.input_string.string)); + strncpy(arg.input_string.string, string, strlen(string)); return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); @@ -149,13 +138,13 @@ esp_err_t esp_ble_mesh_node_input_string(const char *string) esp_err_t esp_ble_mesh_set_unprovisioned_device_name(const char *name) { + btc_ble_mesh_prov_args_t arg = {0}; + btc_msg_t msg = {0}; + if (!name || strlen(name) > ESP_BLE_MESH_DEVICE_NAME_MAX_LEN) { return ESP_ERR_INVALID_ARG; } - btc_msg_t msg; - btc_ble_mesh_prov_args_t arg; - ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; @@ -168,12 +157,12 @@ esp_err_t esp_ble_mesh_set_unprovisioned_device_name(const char *name) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } -#if (CONFIG_BT_MESH_PROVISIONER) +#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]) { - btc_msg_t msg; - btc_ble_mesh_prov_args_t arg; + btc_ble_mesh_prov_args_t arg = {0}; + btc_msg_t msg = {0}; if (!pub_key_x || !pub_key_y || link_idx >= MAX_PROV_LINK_IDX) { return ESP_ERR_INVALID_ARG; @@ -195,8 +184,8 @@ esp_err_t esp_ble_mesh_provisioner_read_oob_pub_key(uint8_t link_idx, uint8_t pu esp_err_t esp_ble_mesh_provisioner_input_string(const char *string, uint8_t link_idx) { - btc_msg_t msg; - btc_ble_mesh_prov_args_t arg; + btc_ble_mesh_prov_args_t arg = {0}; + btc_msg_t msg = {0}; if (!string || link_idx >= MAX_PROV_LINK_IDX) { return ESP_ERR_INVALID_ARG; @@ -218,8 +207,8 @@ esp_err_t esp_ble_mesh_provisioner_input_string(const char *string, uint8_t link esp_err_t esp_ble_mesh_provisioner_input_number(uint32_t number, uint8_t link_idx) { - btc_msg_t msg; - btc_ble_mesh_prov_args_t arg; + btc_ble_mesh_prov_args_t arg = {0}; + btc_msg_t msg = {0}; if (number > MAX_OOB_INPUT_NUM || link_idx >= MAX_PROV_LINK_IDX) { return ESP_ERR_INVALID_ARG; @@ -240,8 +229,8 @@ esp_err_t esp_ble_mesh_provisioner_input_number(uint32_t number, uint8_t link_id esp_err_t esp_ble_mesh_provisioner_prov_enable(esp_ble_mesh_prov_bearer_t bearers) { - btc_msg_t msg; - btc_ble_mesh_prov_args_t arg; + btc_ble_mesh_prov_args_t arg = {0}; + btc_msg_t msg = {0}; ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); @@ -257,8 +246,8 @@ esp_err_t esp_ble_mesh_provisioner_prov_enable(esp_ble_mesh_prov_bearer_t bearer esp_err_t esp_ble_mesh_provisioner_prov_disable(esp_ble_mesh_prov_bearer_t bearers) { - btc_msg_t msg; - btc_ble_mesh_prov_args_t arg; + btc_ble_mesh_prov_args_t arg = {0}; + btc_msg_t msg = {0}; ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); @@ -275,8 +264,8 @@ 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) { - btc_msg_t msg; - btc_ble_mesh_prov_args_t arg; + btc_ble_mesh_prov_args_t arg = {0}; + btc_msg_t msg = {0}; if (add_dev == NULL) { return ESP_ERR_INVALID_ARG; @@ -300,9 +289,9 @@ esp_err_t esp_ble_mesh_provisioner_add_unprov_dev(esp_ble_mesh_unprov_dev_add_t esp_err_t esp_ble_mesh_provisioner_delete_dev(esp_ble_mesh_device_delete_t *del_dev) { - btc_msg_t msg; - btc_ble_mesh_prov_args_t arg; uint8_t val = DEL_DEV_ADDR_FLAG | DEL_DEV_UUID_FLAG; + btc_ble_mesh_prov_args_t arg = {0}; + btc_msg_t msg = {0}; if (del_dev == NULL || (__builtin_popcount(del_dev->flag & val) != 1)) { return ESP_ERR_INVALID_ARG; @@ -328,8 +317,8 @@ 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) { - btc_msg_t msg; - btc_ble_mesh_prov_args_t arg; + btc_ble_mesh_prov_args_t arg = {0}; + btc_msg_t msg = {0}; ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); @@ -349,9 +338,9 @@ esp_err_t esp_ble_mesh_provisioner_set_dev_uuid_match(const uint8_t *match_val, esp_err_t esp_ble_mesh_provisioner_set_prov_data_info(esp_ble_mesh_prov_data_info_t *prov_data_info) { - btc_msg_t msg; - btc_ble_mesh_prov_args_t arg; uint8_t val = PROV_DATA_NET_IDX_FLAG | PROV_DATA_FLAGS_FLAG | PROV_DATA_IV_INDEX_FLAG; + btc_ble_mesh_prov_args_t arg = {0}; + btc_msg_t msg = {0}; if (prov_data_info == NULL || (__builtin_popcount(prov_data_info->flag & val) != 1)) { return ESP_ERR_INVALID_ARG; @@ -375,16 +364,16 @@ esp_err_t esp_ble_mesh_provisioner_set_prov_data_info(esp_ble_mesh_prov_data_inf == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } -#endif /* CONFIG_BT_MESH_PROVISIONER */ +#endif /* CONFIG_BLE_MESH_PROVISIONER */ /* The following APIs are for fast provisioning */ -#if (CONFIG_BT_MESH_FAST_PROV) +#if (CONFIG_BLE_MESH_FAST_PROV) esp_err_t esp_ble_mesh_set_fast_prov_info(esp_ble_mesh_fast_prov_info_t *fast_prov_info) { - btc_msg_t msg; - btc_ble_mesh_prov_args_t arg; + btc_ble_mesh_prov_args_t arg = {0}; + btc_msg_t msg = {0}; if (fast_prov_info == NULL) { return ESP_ERR_INVALID_ARG; @@ -412,8 +401,8 @@ esp_err_t esp_ble_mesh_set_fast_prov_info(esp_ble_mesh_fast_prov_info_t *fast_pr esp_err_t esp_ble_mesh_set_fast_prov_action(esp_ble_mesh_fast_prov_action_t action) { - btc_msg_t msg; - btc_ble_mesh_prov_args_t arg; + btc_ble_mesh_prov_args_t arg = {0}; + btc_msg_t msg = {0}; if (action >= FAST_PROV_ACT_MAX) { return ESP_ERR_INVALID_ARG; @@ -430,7 +419,5 @@ esp_err_t esp_ble_mesh_set_fast_prov_action(esp_ble_mesh_fast_prov_action_t acti == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } -#endif /* CONFIG_BT_MESH_FAST_PROV */ - -#endif /* #if CONFIG_BT_MESH */ +#endif /* CONFIG_BLE_MESH_FAST_PROV */ diff --git a/components/bt/ble_mesh/api/core/esp_ble_mesh_proxy_api.c b/components/bt/ble_mesh/api/core/esp_ble_mesh_proxy_api.c index 3684a11a67..0605e97a6b 100644 --- a/components/bt/ble_mesh/api/core/esp_ble_mesh_proxy_api.c +++ b/components/bt/ble_mesh/api/core/esp_ble_mesh_proxy_api.c @@ -12,29 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include -#include +#include #include "btc/btc_task.h" #include "btc/btc_manage.h" -#include "osi/allocator.h" -#include "esp_bt_defs.h" #include "esp_err.h" +#include "esp_bt_defs.h" #include "esp_bt_main.h" -#include "sdkconfig.h" #include "btc_ble_mesh_prov.h" - -#include "mesh.h" -#include "mesh_buf.h" -#include "transport.h" - -#if CONFIG_BT_MESH +#include "esp_ble_mesh_defs.h" esp_err_t esp_ble_mesh_proxy_identity_enable(void) { - btc_msg_t msg; + btc_msg_t msg = {0}; ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); @@ -47,7 +39,7 @@ esp_err_t esp_ble_mesh_proxy_identity_enable(void) esp_err_t esp_ble_mesh_proxy_gatt_enable(void) { - btc_msg_t msg; + btc_msg_t msg = {0}; ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); @@ -60,7 +52,7 @@ esp_err_t esp_ble_mesh_proxy_gatt_enable(void) esp_err_t esp_ble_mesh_proxy_gatt_disable(void) { - btc_msg_t msg; + btc_msg_t msg = {0}; ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); @@ -71,5 +63,3 @@ esp_err_t esp_ble_mesh_proxy_gatt_disable(void) return (btc_transfer_context(&msg, NULL, 0, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } -#endif /* #if CONFIG_BT_MESH */ - diff --git a/components/bt/ble_mesh/api/core/include/esp_ble_mesh_common_api.h b/components/bt/ble_mesh/api/core/include/esp_ble_mesh_common_api.h index 00a183e2cf..68eb7154c1 100644 --- a/components/bt/ble_mesh/api/core/include/esp_ble_mesh_common_api.h +++ b/components/bt/ble_mesh/api/core/include/esp_ble_mesh_common_api.h @@ -17,8 +17,6 @@ #include "esp_ble_mesh_defs.h" -#if CONFIG_BT_MESH - /** * @brief Initialize BLE Mesh module. * This API initializes provisioning capabilities and composition data information. @@ -34,6 +32,4 @@ */ esp_err_t esp_ble_mesh_init(esp_ble_mesh_prov_t *prov, esp_ble_mesh_comp_t *comp); -#endif /* #if CONFIG_BT_MESH */ #endif /* _ESP_BLE_MESH_COMMON_API_H_ */ - diff --git a/components/bt/ble_mesh/api/core/include/esp_ble_mesh_local_data_operation_api.h b/components/bt/ble_mesh/api/core/include/esp_ble_mesh_local_data_operation_api.h index e060ce2ccc..ef735702a8 100644 --- a/components/bt/ble_mesh/api/core/include/esp_ble_mesh_local_data_operation_api.h +++ b/components/bt/ble_mesh/api/core/include/esp_ble_mesh_local_data_operation_api.h @@ -17,8 +17,6 @@ #include "esp_ble_mesh_defs.h" -#if CONFIG_BT_MESH - /** * @brief Get the model publish period, the unit is ms. * @@ -112,6 +110,4 @@ esp_ble_mesh_model_t *esp_ble_mesh_find_sig_model(esp_ble_mesh_elem_t *element, */ const esp_ble_mesh_comp_t *esp_ble_mesh_get_composition_data(void); -#endif /* #if CONFIG_BT_MESH */ #endif /* _ESP_BLE_MESH_LOCAL_DATA_OPERATION_API_H_ */ - diff --git a/components/bt/ble_mesh/api/core/include/esp_ble_mesh_low_power_api.h b/components/bt/ble_mesh/api/core/include/esp_ble_mesh_low_power_api.h index 485298bfe3..7a203d50cc 100644 --- a/components/bt/ble_mesh/api/core/include/esp_ble_mesh_low_power_api.h +++ b/components/bt/ble_mesh/api/core/include/esp_ble_mesh_low_power_api.h @@ -17,8 +17,4 @@ #include "esp_ble_mesh_defs.h" -#if CONFIG_BT_MESH - -#endif /* #if CONFIG_BT_MESH */ #endif /* _ESP_BLE_MESH_LOW_POWER_API_H_ */ - diff --git a/components/bt/ble_mesh/api/core/include/esp_ble_mesh_networking_api.h b/components/bt/ble_mesh/api/core/include/esp_ble_mesh_networking_api.h index 5b8ee9d0bc..f44f88e60f 100644 --- a/components/bt/ble_mesh/api/core/include/esp_ble_mesh_networking_api.h +++ b/components/bt/ble_mesh/api/core/include/esp_ble_mesh_networking_api.h @@ -17,8 +17,6 @@ #include "esp_ble_mesh_defs.h" -#if CONFIG_BT_MESH - /** @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); @@ -150,7 +148,7 @@ esp_err_t esp_ble_mesh_model_publish(esp_ble_mesh_model_t *model, uint32_t opcod */ esp_err_t esp_ble_mesh_node_local_reset(void); -#if defined(CONFIG_BT_MESH_PROVISIONER) +#if defined(CONFIG_BLE_MESH_PROVISIONER) /** * @brief This function is called to set the node (provisioned device) name. * @@ -256,7 +254,7 @@ esp_err_t esp_ble_mesh_provisioner_add_local_net_key(const uint8_t net_key[16], */ const uint8_t *esp_ble_mesh_provisioner_get_local_net_key(uint16_t net_idx); -#endif /* #if CONFIG_BT_MESH_PROVISIONER */ +#endif /* #if CONFIG_BLE_MESH_PROVISIONER */ /** * @brief This function is called to get fast provisioning application key. @@ -269,6 +267,4 @@ const uint8_t *esp_ble_mesh_provisioner_get_local_net_key(uint16_t net_idx); */ const uint8_t *esp_ble_mesh_get_fast_prov_app_key(uint16_t net_idx, uint16_t app_idx); -#endif /* #if CONFIG_BT_MESH */ #endif /* _ESP_BLE_MESH_NETWORKING_API_H_ */ - diff --git a/components/bt/ble_mesh/api/core/include/esp_ble_mesh_provisioning_api.h b/components/bt/ble_mesh/api/core/include/esp_ble_mesh_provisioning_api.h index df3bb19357..1d8fba0574 100644 --- a/components/bt/ble_mesh/api/core/include/esp_ble_mesh_provisioning_api.h +++ b/components/bt/ble_mesh/api/core/include/esp_ble_mesh_provisioning_api.h @@ -17,8 +17,6 @@ #include "esp_ble_mesh_defs.h" -#if CONFIG_BT_MESH - /** @brief: event, event code of provisioning events; param, parameters of provisioning events */ typedef void (* esp_ble_mesh_prov_cb_t)(esp_ble_mesh_prov_cb_event_t event, esp_ble_mesh_prov_cb_param_t *param); @@ -118,7 +116,7 @@ esp_err_t esp_ble_mesh_node_input_string(const char *string); */ esp_err_t esp_ble_mesh_set_unprovisioned_device_name(const char *name); -#if defined(CONFIG_BT_MESH_PROVISIONER) +#if defined(CONFIG_BLE_MESH_PROVISIONER) /** * @brief Provisioner inputs unprovisioned device's oob public key. @@ -296,7 +294,7 @@ esp_err_t esp_ble_mesh_provisioner_set_dev_uuid_match(const uint8_t *match_val, */ esp_err_t esp_ble_mesh_provisioner_set_prov_data_info(esp_ble_mesh_prov_data_info_t *prov_data_info); -#endif /* #if CONFIG_BT_MESH_PROVISIONER */ +#endif /* #if CONFIG_BLE_MESH_PROVISIONER */ /** * @brief This function is called to set provisioning data information before starting @@ -319,6 +317,4 @@ esp_err_t esp_ble_mesh_set_fast_prov_info(esp_ble_mesh_fast_prov_info_t *fast_pr */ esp_err_t esp_ble_mesh_set_fast_prov_action(esp_ble_mesh_fast_prov_action_t action); -#endif /* #if CONFIG_BT_MESH */ #endif /* _ESP_BLE_MESH_PROVISIONING_API_H_ */ - diff --git a/components/bt/ble_mesh/api/esp_ble_mesh_defs.h b/components/bt/ble_mesh/api/esp_ble_mesh_defs.h index 05e7c1b933..db4442afef 100644 --- a/components/bt/ble_mesh/api/esp_ble_mesh_defs.h +++ b/components/bt/ble_mesh/api/esp_ble_mesh_defs.h @@ -19,16 +19,17 @@ #include "esp_bt_defs.h" -#include "mesh.h" -#include "proxy.h" -#include "include/proxy.h" +#include "mesh_proxy.h" #include "mesh_access.h" #include "mesh_main.h" -#include "foundation.h" -#include "model_op.h" -#include "common.h" -#if CONFIG_BT_MESH +#include "mesh.h" +#include "proxy.h" +#include "foundation.h" +#include "provisioner_main.h" + +#include "model_opcode.h" +#include "mesh_common.h" #ifndef MIN #define MIN(x, y) (((x) < (y)) ? (x) : (y)) @@ -50,118 +51,118 @@ typedef uint8_t esp_ble_mesh_octet16_t[ESP_BLE_MESH_OCTET16_LEN]; #define ESP_BLE_MESH_OCTET8_LEN 8 typedef uint8_t esp_ble_mesh_octet8_t[ESP_BLE_MESH_OCTET8_LEN]; -#define ESP_BLE_MESH_ADDR_UNASSIGNED BT_MESH_ADDR_UNASSIGNED -#define ESP_BLE_MESH_ADDR_ALL_NODES BT_MESH_ADDR_ALL_NODES -#define ESP_BLE_MESH_ADDR_PROXIES BT_MESH_ADDR_PROXIES -#define ESP_BLE_MESH_ADDR_FRIENDS BT_MESH_ADDR_FRIENDS -#define ESP_BLE_MESH_ADDR_RELAYS BT_MESH_ADDR_RELAYS +#define ESP_BLE_MESH_ADDR_UNASSIGNED BLE_MESH_ADDR_UNASSIGNED +#define ESP_BLE_MESH_ADDR_ALL_NODES BLE_MESH_ADDR_ALL_NODES +#define ESP_BLE_MESH_ADDR_PROXIES BLE_MESH_ADDR_PROXIES +#define ESP_BLE_MESH_ADDR_FRIENDS BLE_MESH_ADDR_FRIENDS +#define ESP_BLE_MESH_ADDR_RELAYS BLE_MESH_ADDR_RELAYS -#define ESP_BLE_MESH_KEY_UNUSED BT_MESH_KEY_UNUSED -#define ESP_BLE_MESH_KEY_DEV BT_MESH_KEY_DEV +#define ESP_BLE_MESH_KEY_UNUSED BLE_MESH_KEY_UNUSED +#define ESP_BLE_MESH_KEY_DEV BLE_MESH_KEY_DEV -#define ESP_BLE_MESH_KEY_PRIMARY BT_MESH_KEY_PRIMARY -#define ESP_BLE_MESH_KEY_ANY BT_MESH_KEY_ANY +#define ESP_BLE_MESH_KEY_PRIMARY BLE_MESH_KEY_PRIMARY +#define ESP_BLE_MESH_KEY_ANY BLE_MESH_KEY_ANY /*!< Primary Network Key index */ -#define ESP_BLE_MESH_NET_PRIMARY BT_MESH_NET_PRIMARY +#define ESP_BLE_MESH_NET_PRIMARY BLE_MESH_NET_PRIMARY /*!< Relay state value */ -#define ESP_BLE_MESH_RELAY_DISABLED BT_MESH_RELAY_DISABLED -#define ESP_BLE_MESH_RELAY_ENABLED BT_MESH_RELAY_ENABLED -#define ESP_BLE_MESH_RELAY_NOT_SUPPORTED BT_MESH_RELAY_NOT_SUPPORTED +#define ESP_BLE_MESH_RELAY_DISABLED BLE_MESH_RELAY_DISABLED +#define ESP_BLE_MESH_RELAY_ENABLED BLE_MESH_RELAY_ENABLED +#define ESP_BLE_MESH_RELAY_NOT_SUPPORTED BLE_MESH_RELAY_NOT_SUPPORTED /*!< Beacon state value */ -#define ESP_BLE_MESH_BEACON_DISABLED BT_MESH_BEACON_DISABLED -#define ESP_BLE_MESH_BEACON_ENABLED BT_MESH_BEACON_ENABLED +#define ESP_BLE_MESH_BEACON_DISABLED BLE_MESH_BEACON_DISABLED +#define ESP_BLE_MESH_BEACON_ENABLED BLE_MESH_BEACON_ENABLED /*!< GATT Proxy state value */ -#define ESP_BLE_MESH_GATT_PROXY_DISABLED BT_MESH_GATT_PROXY_DISABLED -#define ESP_BLE_MESH_GATT_PROXY_ENABLED BT_MESH_GATT_PROXY_ENABLED -#define ESP_BLE_MESH_GATT_PROXY_NOT_SUPPORTED BT_MESH_GATT_PROXY_NOT_SUPPORTED +#define ESP_BLE_MESH_GATT_PROXY_DISABLED BLE_MESH_GATT_PROXY_DISABLED +#define ESP_BLE_MESH_GATT_PROXY_ENABLED BLE_MESH_GATT_PROXY_ENABLED +#define ESP_BLE_MESH_GATT_PROXY_NOT_SUPPORTED BLE_MESH_GATT_PROXY_NOT_SUPPORTED /*!< Friend state value */ -#define ESP_BLE_MESH_FRIEND_DISABLED BT_MESH_FRIEND_DISABLED -#define ESP_BLE_MESH_FRIEND_ENABLED BT_MESH_FRIEND_ENABLED -#define ESP_BLE_MESH_FRIEND_NOT_SUPPORTED BT_MESH_FRIEND_NOT_SUPPORTED +#define ESP_BLE_MESH_FRIEND_DISABLED BLE_MESH_FRIEND_DISABLED +#define ESP_BLE_MESH_FRIEND_ENABLED BLE_MESH_FRIEND_ENABLED +#define ESP_BLE_MESH_FRIEND_NOT_SUPPORTED BLE_MESH_FRIEND_NOT_SUPPORTED /*!< Node identity state value */ -#define ESP_BLE_MESH_NODE_IDENTITY_STOPPED BT_MESH_NODE_IDENTITY_STOPPED -#define ESP_BLE_MESH_NODE_IDENTITY_RUNNING BT_MESH_NODE_IDENTITY_RUNNING -#define ESP_BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED BT_MESH_NODE_IDENTITY_NOT_SUPPORTED +#define ESP_BLE_MESH_NODE_IDENTITY_STOPPED BLE_MESH_NODE_IDENTITY_STOPPED +#define ESP_BLE_MESH_NODE_IDENTITY_RUNNING BLE_MESH_NODE_IDENTITY_RUNNING +#define ESP_BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED /*!< Supported features */ -#define ESP_BLE_MESH_FEATURE_RELAY BT_MESH_FEAT_RELAY -#define ESP_BLE_MESH_FEATURE_PROXY BT_MESH_FEAT_PROXY -#define ESP_BLE_MESH_FEATURE_FRIEND BT_MESH_FEAT_FRIEND -#define ESP_BLE_MESH_FEATURE_LOW_POWER BT_MESH_FEAT_LOW_POWER -#define ESP_BLE_MESH_FEATURE_ALL_SUPPORTED BT_MESH_FEAT_SUPPORTED +#define ESP_BLE_MESH_FEATURE_RELAY BLE_MESH_FEAT_RELAY +#define ESP_BLE_MESH_FEATURE_PROXY BLE_MESH_FEAT_PROXY +#define ESP_BLE_MESH_FEATURE_FRIEND BLE_MESH_FEAT_FRIEND +#define ESP_BLE_MESH_FEATURE_LOW_POWER BLE_MESH_FEAT_LOW_POWER +#define ESP_BLE_MESH_FEATURE_ALL_SUPPORTED BLE_MESH_FEAT_SUPPORTED -#define ESP_BLE_MESH_ADDR_IS_UNICAST(addr) BT_MESH_ADDR_IS_UNICAST(addr) -#define ESP_BLE_MESH_ADDR_IS_GROUP(addr) BT_MESH_ADDR_IS_GROUP(addr) -#define ESP_BLE_MESH_ADDR_IS_VIRTUAL(addr) BT_MESH_ADDR_IS_VIRTUAL(addr) -#define ESP_BLE_MESH_ADDR_IS_RFU(addr) BT_MESH_ADDR_IS_RFU(addr) +#define ESP_BLE_MESH_ADDR_IS_UNICAST(addr) BLE_MESH_ADDR_IS_UNICAST(addr) +#define ESP_BLE_MESH_ADDR_IS_GROUP(addr) BLE_MESH_ADDR_IS_GROUP(addr) +#define ESP_BLE_MESH_ADDR_IS_VIRTUAL(addr) BLE_MESH_ADDR_IS_VIRTUAL(addr) +#define ESP_BLE_MESH_ADDR_IS_RFU(addr) BLE_MESH_ADDR_IS_RFU(addr) #define ESP_BLE_MESH_INVALID_NODE_INDEX (-1) /*!< Foundation Models */ -#define ESP_BLE_MESH_MODEL_ID_CONFIG_SRV BT_MESH_MODEL_ID_CFG_SRV -#define ESP_BLE_MESH_MODEL_ID_CONFIG_CLI BT_MESH_MODEL_ID_CFG_CLI -#define ESP_BLE_MESH_MODEL_ID_HEALTH_SRV BT_MESH_MODEL_ID_HEALTH_SRV -#define ESP_BLE_MESH_MODEL_ID_HEALTH_CLI BT_MESH_MODEL_ID_HEALTH_CLI +#define ESP_BLE_MESH_MODEL_ID_CONFIG_SRV BLE_MESH_MODEL_ID_CFG_SRV +#define ESP_BLE_MESH_MODEL_ID_CONFIG_CLI BLE_MESH_MODEL_ID_CFG_CLI +#define ESP_BLE_MESH_MODEL_ID_HEALTH_SRV BLE_MESH_MODEL_ID_HEALTH_SRV +#define ESP_BLE_MESH_MODEL_ID_HEALTH_CLI BLE_MESH_MODEL_ID_HEALTH_CLI /*!< Models from the Mesh Model Specification */ -#define ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_SRV BT_MESH_MODEL_ID_GEN_ONOFF_SRV -#define ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_CLI BT_MESH_MODEL_ID_GEN_ONOFF_CLI -#define ESP_BLE_MESH_MODEL_ID_GEN_LEVEL_SRV BT_MESH_MODEL_ID_GEN_LEVEL_SRV -#define ESP_BLE_MESH_MODEL_ID_GEN_LEVEL_CLI BT_MESH_MODEL_ID_GEN_LEVEL_CLI -#define ESP_BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV BT_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV -#define ESP_BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI BT_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI -#define ESP_BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV BT_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV -#define ESP_BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV BT_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV -#define ESP_BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI BT_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI -#define ESP_BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV BT_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV -#define ESP_BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV BT_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV -#define ESP_BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI BT_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI -#define ESP_BLE_MESH_MODEL_ID_GEN_BATTERY_SRV BT_MESH_MODEL_ID_GEN_BATTERY_SRV -#define ESP_BLE_MESH_MODEL_ID_GEN_BATTERY_CLI BT_MESH_MODEL_ID_GEN_BATTERY_CLI -#define ESP_BLE_MESH_MODEL_ID_GEN_LOCATION_SRV BT_MESH_MODEL_ID_GEN_LOCATION_SRV -#define ESP_BLE_MESH_MODEL_ID_GEN_LOCATION_SETUP_SRV BT_MESH_MODEL_ID_GEN_LOCATION_SETUPSRV -#define ESP_BLE_MESH_MODEL_ID_GEN_LOCATION_CLI BT_MESH_MODEL_ID_GEN_LOCATION_CLI -#define ESP_BLE_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV BT_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV -#define ESP_BLE_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV BT_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV -#define ESP_BLE_MESH_MODEL_ID_GEN_USER_PROP_SRV BT_MESH_MODEL_ID_GEN_USER_PROP_SRV -#define ESP_BLE_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV BT_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV -#define ESP_BLE_MESH_MODEL_ID_GEN_PROP_CLI BT_MESH_MODEL_ID_GEN_PROP_CLI -#define ESP_BLE_MESH_MODEL_ID_SENSOR_SRV BT_MESH_MODEL_ID_SENSOR_SRV -#define ESP_BLE_MESH_MODEL_ID_SENSOR_SETUP_SRV BT_MESH_MODEL_ID_SENSOR_SETUP_SRV -#define ESP_BLE_MESH_MODEL_ID_SENSOR_CLI BT_MESH_MODEL_ID_SENSOR_CLI -#define ESP_BLE_MESH_MODEL_ID_TIME_SRV BT_MESH_MODEL_ID_TIME_SRV -#define ESP_BLE_MESH_MODEL_ID_TIME_SETUP_SRV BT_MESH_MODEL_ID_TIME_SETUP_SRV -#define ESP_BLE_MESH_MODEL_ID_TIME_CLI BT_MESH_MODEL_ID_TIME_CLI -#define ESP_BLE_MESH_MODEL_ID_SCENE_SRV BT_MESH_MODEL_ID_SCENE_SRV -#define ESP_BLE_MESH_MODEL_ID_SCENE_SETUP_SRV BT_MESH_MODEL_ID_SCENE_SETUP_SRV -#define ESP_BLE_MESH_MODEL_ID_SCENE_CLI BT_MESH_MODEL_ID_SCENE_CLI -#define ESP_BLE_MESH_MODEL_ID_SCHEDULER_SRV BT_MESH_MODEL_ID_SCHEDULER_SRV -#define ESP_BLE_MESH_MODEL_ID_SCHEDULER_SETUP_SRV BT_MESH_MODEL_ID_SCHEDULER_SETUP_SRV -#define ESP_BLE_MESH_MODEL_ID_SCHEDULER_CLI BT_MESH_MODEL_ID_SCHEDULER_CLI -#define ESP_BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV -#define ESP_BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV -#define ESP_BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI -#define ESP_BLE_MESH_MODEL_ID_LIGHT_CTL_SRV BT_MESH_MODEL_ID_LIGHT_CTL_SRV -#define ESP_BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV BT_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV -#define ESP_BLE_MESH_MODEL_ID_LIGHT_CTL_CLI BT_MESH_MODEL_ID_LIGHT_CTL_CLI -#define ESP_BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV BT_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV -#define ESP_BLE_MESH_MODEL_ID_LIGHT_HSL_SRV BT_MESH_MODEL_ID_LIGHT_HSL_SRV -#define ESP_BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV BT_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV -#define ESP_BLE_MESH_MODEL_ID_LIGHT_HSL_CLI BT_MESH_MODEL_ID_LIGHT_HSL_CLI -#define ESP_BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV BT_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV -#define ESP_BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV BT_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV -#define ESP_BLE_MESH_MODEL_ID_LIGHT_XYL_SRV BT_MESH_MODEL_ID_LIGHT_XYL_SRV -#define ESP_BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV BT_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV -#define ESP_BLE_MESH_MODEL_ID_LIGHT_XYL_CLI BT_MESH_MODEL_ID_LIGHT_XYL_CLI -#define ESP_BLE_MESH_MODEL_ID_LIGHT_LC_SRV BT_MESH_MODEL_ID_LIGHT_LC_SRV -#define ESP_BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV BT_MESH_MODEL_ID_LIGHT_LC_SETUPSRV -#define ESP_BLE_MESH_MODEL_ID_LIGHT_LC_CLI BT_MESH_MODEL_ID_LIGHT_LC_CLI +#define ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_SRV BLE_MESH_MODEL_ID_GEN_ONOFF_SRV +#define ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_CLI BLE_MESH_MODEL_ID_GEN_ONOFF_CLI +#define ESP_BLE_MESH_MODEL_ID_GEN_LEVEL_SRV BLE_MESH_MODEL_ID_GEN_LEVEL_SRV +#define ESP_BLE_MESH_MODEL_ID_GEN_LEVEL_CLI BLE_MESH_MODEL_ID_GEN_LEVEL_CLI +#define ESP_BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV +#define ESP_BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI +#define ESP_BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV +#define ESP_BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV +#define ESP_BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI +#define ESP_BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV +#define ESP_BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV +#define ESP_BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI +#define ESP_BLE_MESH_MODEL_ID_GEN_BATTERY_SRV BLE_MESH_MODEL_ID_GEN_BATTERY_SRV +#define ESP_BLE_MESH_MODEL_ID_GEN_BATTERY_CLI BLE_MESH_MODEL_ID_GEN_BATTERY_CLI +#define ESP_BLE_MESH_MODEL_ID_GEN_LOCATION_SRV BLE_MESH_MODEL_ID_GEN_LOCATION_SRV +#define ESP_BLE_MESH_MODEL_ID_GEN_LOCATION_SETUP_SRV BLE_MESH_MODEL_ID_GEN_LOCATION_SETUPSRV +#define ESP_BLE_MESH_MODEL_ID_GEN_LOCATION_CLI BLE_MESH_MODEL_ID_GEN_LOCATION_CLI +#define ESP_BLE_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV BLE_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV +#define ESP_BLE_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV BLE_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV +#define ESP_BLE_MESH_MODEL_ID_GEN_USER_PROP_SRV BLE_MESH_MODEL_ID_GEN_USER_PROP_SRV +#define ESP_BLE_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV BLE_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV +#define ESP_BLE_MESH_MODEL_ID_GEN_PROP_CLI BLE_MESH_MODEL_ID_GEN_PROP_CLI +#define ESP_BLE_MESH_MODEL_ID_SENSOR_SRV BLE_MESH_MODEL_ID_SENSOR_SRV +#define ESP_BLE_MESH_MODEL_ID_SENSOR_SETUP_SRV BLE_MESH_MODEL_ID_SENSOR_SETUP_SRV +#define ESP_BLE_MESH_MODEL_ID_SENSOR_CLI BLE_MESH_MODEL_ID_SENSOR_CLI +#define ESP_BLE_MESH_MODEL_ID_TIME_SRV BLE_MESH_MODEL_ID_TIME_SRV +#define ESP_BLE_MESH_MODEL_ID_TIME_SETUP_SRV BLE_MESH_MODEL_ID_TIME_SETUP_SRV +#define ESP_BLE_MESH_MODEL_ID_TIME_CLI BLE_MESH_MODEL_ID_TIME_CLI +#define ESP_BLE_MESH_MODEL_ID_SCENE_SRV BLE_MESH_MODEL_ID_SCENE_SRV +#define ESP_BLE_MESH_MODEL_ID_SCENE_SETUP_SRV BLE_MESH_MODEL_ID_SCENE_SETUP_SRV +#define ESP_BLE_MESH_MODEL_ID_SCENE_CLI BLE_MESH_MODEL_ID_SCENE_CLI +#define ESP_BLE_MESH_MODEL_ID_SCHEDULER_SRV BLE_MESH_MODEL_ID_SCHEDULER_SRV +#define ESP_BLE_MESH_MODEL_ID_SCHEDULER_SETUP_SRV BLE_MESH_MODEL_ID_SCHEDULER_SETUP_SRV +#define ESP_BLE_MESH_MODEL_ID_SCHEDULER_CLI BLE_MESH_MODEL_ID_SCHEDULER_CLI +#define ESP_BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV +#define ESP_BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV +#define ESP_BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI +#define ESP_BLE_MESH_MODEL_ID_LIGHT_CTL_SRV BLE_MESH_MODEL_ID_LIGHT_CTL_SRV +#define ESP_BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV +#define ESP_BLE_MESH_MODEL_ID_LIGHT_CTL_CLI BLE_MESH_MODEL_ID_LIGHT_CTL_CLI +#define ESP_BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV +#define ESP_BLE_MESH_MODEL_ID_LIGHT_HSL_SRV BLE_MESH_MODEL_ID_LIGHT_HSL_SRV +#define ESP_BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV +#define ESP_BLE_MESH_MODEL_ID_LIGHT_HSL_CLI BLE_MESH_MODEL_ID_LIGHT_HSL_CLI +#define ESP_BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV +#define ESP_BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV +#define ESP_BLE_MESH_MODEL_ID_LIGHT_XYL_SRV BLE_MESH_MODEL_ID_LIGHT_XYL_SRV +#define ESP_BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV +#define ESP_BLE_MESH_MODEL_ID_LIGHT_XYL_CLI BLE_MESH_MODEL_ID_LIGHT_XYL_CLI +#define ESP_BLE_MESH_MODEL_ID_LIGHT_LC_SRV BLE_MESH_MODEL_ID_LIGHT_LC_SRV +#define ESP_BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV BLE_MESH_MODEL_ID_LIGHT_LC_SETUPSRV +#define ESP_BLE_MESH_MODEL_ID_LIGHT_LC_CLI BLE_MESH_MODEL_ID_LIGHT_LC_CLI /*!< The following opcodes will only be used in the esp_ble_mesh_config_client_get_state function. */ typedef uint32_t esp_ble_mesh_opcode_config_client_get_t; /*!< esp_ble_mesh_opcode_config_client_get_t belongs to esp_ble_mesh_opcode_t, @@ -302,269 +303,269 @@ typedef uint32_t esp_ble_mesh_generic_message_opcode_t; /*!< esp_ble_mesh_ge this typedef is only used to locate the opcodes used by functions esp_ble_mesh_generic_client_get_state & esp_ble_mesh_generic_client_set_state */ /*!< Generic OnOff Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_GET BT_MESH_MODEL_OP_GEN_ONOFF_GET -#define ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET BT_MESH_MODEL_OP_GEN_ONOFF_SET -#define ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK BT_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS BT_MESH_MODEL_OP_GEN_ONOFF_STATUS +#define ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_GET BLE_MESH_MODEL_OP_GEN_ONOFF_GET +#define ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET BLE_MESH_MODEL_OP_GEN_ONOFF_SET +#define ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS /*!< Generic Level Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_GEN_LEVEL_GET BT_MESH_MODEL_OP_GEN_LEVEL_GET -#define ESP_BLE_MESH_MODEL_OP_GEN_LEVEL_SET BT_MESH_MODEL_OP_GEN_LEVEL_SET -#define ESP_BLE_MESH_MODEL_OP_GEN_LEVEL_SET_UNACK BT_MESH_MODEL_OP_GEN_LEVEL_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS BT_MESH_MODEL_OP_GEN_LEVEL_STATUS -#define ESP_BLE_MESH_MODEL_OP_GEN_DELTA_SET BT_MESH_MODEL_OP_GEN_DELTA_SET -#define ESP_BLE_MESH_MODEL_OP_GEN_DELTA_SET_UNACK BT_MESH_MODEL_OP_GEN_DELTA_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_GEN_MOVE_SET BT_MESH_MODEL_OP_GEN_MOVE_SET -#define ESP_BLE_MESH_MODEL_OP_GEN_MOVE_SET_UNACK BT_MESH_MODEL_OP_GEN_MOVE_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_GEN_LEVEL_GET BLE_MESH_MODEL_OP_GEN_LEVEL_GET +#define ESP_BLE_MESH_MODEL_OP_GEN_LEVEL_SET BLE_MESH_MODEL_OP_GEN_LEVEL_SET +#define ESP_BLE_MESH_MODEL_OP_GEN_LEVEL_SET_UNACK BLE_MESH_MODEL_OP_GEN_LEVEL_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS +#define ESP_BLE_MESH_MODEL_OP_GEN_DELTA_SET BLE_MESH_MODEL_OP_GEN_DELTA_SET +#define ESP_BLE_MESH_MODEL_OP_GEN_DELTA_SET_UNACK BLE_MESH_MODEL_OP_GEN_DELTA_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_GEN_MOVE_SET BLE_MESH_MODEL_OP_GEN_MOVE_SET +#define ESP_BLE_MESH_MODEL_OP_GEN_MOVE_SET_UNACK BLE_MESH_MODEL_OP_GEN_MOVE_SET_UNACK /*!< Generic Default Transition Time Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_GET BT_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_GET -#define ESP_BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET BT_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET -#define ESP_BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET_UNACK BT_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS BT_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS +#define ESP_BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_GET BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_GET +#define ESP_BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET +#define ESP_BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET_UNACK BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS /*!< Generic Power OnOff Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_GEN_ONPOWERUP_GET BT_MESH_MODEL_OP_GEN_ONPOWERUP_GET -#define ESP_BLE_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS BT_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS +#define ESP_BLE_MESH_MODEL_OP_GEN_ONPOWERUP_GET BLE_MESH_MODEL_OP_GEN_ONPOWERUP_GET +#define ESP_BLE_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS BLE_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS /*!< Generic Power OnOff Setup Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET BT_MESH_MODEL_OP_GEN_ONPOWERUP_SET -#define ESP_BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET_UNACK BT_MESH_MODEL_OP_GEN_ONPOWERUP_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET +#define ESP_BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET_UNACK BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET_UNACK /*!< Generic Power Level Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_GET BT_MESH_MODEL_OP_GEN_POWER_LEVEL_GET -#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET BT_MESH_MODEL_OP_GEN_POWER_LEVEL_SET -#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET_UNACK BT_MESH_MODEL_OP_GEN_POWER_LEVEL_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS BT_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS -#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_LAST_GET BT_MESH_MODEL_OP_GEN_POWER_LAST_GET -#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_LAST_STATUS BT_MESH_MODEL_OP_GEN_POWER_LAST_STATUS -#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_GET BT_MESH_MODEL_OP_GEN_POWER_DEFAULT_GET -#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS BT_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS -#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_RANGE_GET BT_MESH_MODEL_OP_GEN_POWER_RANGE_GET -#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS BT_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS +#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_GET BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_GET +#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET +#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET_UNACK BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS +#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_LAST_GET BLE_MESH_MODEL_OP_GEN_POWER_LAST_GET +#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_LAST_STATUS BLE_MESH_MODEL_OP_GEN_POWER_LAST_STATUS +#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_GET BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_GET +#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS +#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_RANGE_GET BLE_MESH_MODEL_OP_GEN_POWER_RANGE_GET +#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS BLE_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS /*!< Generic Power Level Setup Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET BT_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET -#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET_UNACK BT_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET BT_MESH_MODEL_OP_GEN_POWER_RANGE_SET -#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET_UNACK BT_MESH_MODEL_OP_GEN_POWER_RANGE_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET +#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET_UNACK BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET +#define ESP_BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET_UNACK BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET_UNACK /*!< Generic Battery Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_GEN_BATTERY_GET BT_MESH_MODEL_OP_GEN_BATTERY_GET -#define ESP_BLE_MESH_MODEL_OP_GEN_BATTERY_STATUS BT_MESH_MODEL_OP_GEN_BATTERY_STATUS +#define ESP_BLE_MESH_MODEL_OP_GEN_BATTERY_GET BLE_MESH_MODEL_OP_GEN_BATTERY_GET +#define ESP_BLE_MESH_MODEL_OP_GEN_BATTERY_STATUS BLE_MESH_MODEL_OP_GEN_BATTERY_STATUS /*!< Generic Location Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_GET BT_MESH_MODEL_OP_GEN_LOC_GLOBAL_GET -#define ESP_BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS BT_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS -#define ESP_BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_GET BT_MESH_MODEL_OP_GEN_LOC_LOCAL_GET -#define ESP_BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS BT_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS +#define ESP_BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_GET BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_GET +#define ESP_BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS +#define ESP_BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_GET BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_GET +#define ESP_BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS /*!< Generic Location Setup Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET BT_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET -#define ESP_BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET_UNACK BT_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET BT_MESH_MODEL_OP_GEN_LOC_LOCAL_SET -#define ESP_BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET_UNACK BT_MESH_MODEL_OP_GEN_LOC_LOCAL_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET +#define ESP_BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET_UNACK BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET +#define ESP_BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET_UNACK BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET_UNACK /*!< Generic Manufacturer Property Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTIES_GET BT_MESH_MODEL_OP_GEN_MANU_PROPERTIES_GET -#define ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTIES_STATUS BT_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS -#define ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTY_GET BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET -#define ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTY_SET BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET -#define ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTY_SET_UNACK BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTY_STATUS BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS +#define ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTIES_GET BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_GET +#define ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTIES_STATUS BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS +#define ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTY_GET BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET +#define ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTY_SET BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET +#define ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTY_SET_UNACK BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_GEN_MANUFACTURER_PROPERTY_STATUS BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS /*!< Generic Admin Property Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET -#define ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS -#define ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET -#define ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET -#define ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS +#define ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET +#define ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS +#define ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET +#define ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET +#define ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS /*!< Generic User Property Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET BT_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET -#define ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS BT_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS -#define ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET BT_MESH_MODEL_OP_GEN_USER_PROPERTY_GET -#define ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET BT_MESH_MODEL_OP_GEN_USER_PROPERTY_SET -#define ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK BT_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS BT_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS +#define ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET +#define ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS +#define ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET +#define ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET +#define ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS /*!< Generic Client Property Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET BT_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET -#define ESP_BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS BT_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS +#define ESP_BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET +#define ESP_BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS typedef uint32_t esp_ble_mesh_sensor_message_opcode_t; /*!< esp_ble_mesh_sensor_message_opcode_t belongs to esp_ble_mesh_opcode_t, this typedef is only used to locate the opcodes used by functions esp_ble_mesh_sensor_client_get_state & esp_ble_mesh_sensor_client_set_state */ /*!< Sensor Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET BT_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET -#define ESP_BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS BT_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS -#define ESP_BLE_MESH_MODEL_OP_SENSOR_GET BT_MESH_MODEL_OP_SENSOR_GET -#define ESP_BLE_MESH_MODEL_OP_SENSOR_STATUS BT_MESH_MODEL_OP_SENSOR_STATUS -#define ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET BT_MESH_MODEL_OP_SENSOR_COLUMN_GET -#define ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_STATUS BT_MESH_MODEL_OP_SENSOR_COLUMN_STATUS -#define ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_GET BT_MESH_MODEL_OP_SENSOR_SERIES_GET -#define ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_STATUS BT_MESH_MODEL_OP_SENSOR_SERIES_STATUS +#define ESP_BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET +#define ESP_BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS +#define ESP_BLE_MESH_MODEL_OP_SENSOR_GET BLE_MESH_MODEL_OP_SENSOR_GET +#define ESP_BLE_MESH_MODEL_OP_SENSOR_STATUS BLE_MESH_MODEL_OP_SENSOR_STATUS +#define ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET +#define ESP_BLE_MESH_MODEL_OP_SENSOR_COLUMN_STATUS BLE_MESH_MODEL_OP_SENSOR_COLUMN_STATUS +#define ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_GET BLE_MESH_MODEL_OP_SENSOR_SERIES_GET +#define ESP_BLE_MESH_MODEL_OP_SENSOR_SERIES_STATUS BLE_MESH_MODEL_OP_SENSOR_SERIES_STATUS /*!< Sensor Setup Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_GET BT_MESH_MODEL_OP_SENSOR_CADENCE_GET -#define ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET BT_MESH_MODEL_OP_SENSOR_CADENCE_SET -#define ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK BT_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_STATUS BT_MESH_MODEL_OP_SENSOR_CADENCE_STATUS -#define ESP_BLE_MESH_MODEL_OP_SENSOR_SETTINGS_GET BT_MESH_MODEL_OP_SENSOR_SETTINGS_GET -#define ESP_BLE_MESH_MODEL_OP_SENSOR_SETTINGS_STATUS BT_MESH_MODEL_OP_SENSOR_SETTINGS_STATUS -#define ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_GET BT_MESH_MODEL_OP_SENSOR_SETTING_GET -#define ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET BT_MESH_MODEL_OP_SENSOR_SETTING_SET -#define ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK BT_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_STATUS BT_MESH_MODEL_OP_SENSOR_SETTING_STATUS +#define ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_GET BLE_MESH_MODEL_OP_SENSOR_CADENCE_GET +#define ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET +#define ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_SENSOR_CADENCE_STATUS BLE_MESH_MODEL_OP_SENSOR_CADENCE_STATUS +#define ESP_BLE_MESH_MODEL_OP_SENSOR_SETTINGS_GET BLE_MESH_MODEL_OP_SENSOR_SETTINGS_GET +#define ESP_BLE_MESH_MODEL_OP_SENSOR_SETTINGS_STATUS BLE_MESH_MODEL_OP_SENSOR_SETTINGS_STATUS +#define ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_GET BLE_MESH_MODEL_OP_SENSOR_SETTING_GET +#define ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET BLE_MESH_MODEL_OP_SENSOR_SETTING_SET +#define ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK BLE_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_SENSOR_SETTING_STATUS BLE_MESH_MODEL_OP_SENSOR_SETTING_STATUS typedef uint32_t esp_ble_mesh_time_scene_message_opcode_t; /*!< esp_ble_mesh_time_scene_message_opcode_t belongs to esp_ble_mesh_opcode_t, this typedef is only used to locate the opcodes used by functions esp_ble_mesh_time_scene_client_get_state & esp_ble_mesh_time_scene_client_set_state */ /*!< Time Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_TIME_GET BT_MESH_MODEL_OP_TIME_GET -#define ESP_BLE_MESH_MODEL_OP_TIME_SET BT_MESH_MODEL_OP_TIME_SET -#define ESP_BLE_MESH_MODEL_OP_TIME_STATUS BT_MESH_MODEL_OP_TIME_STATUS -#define ESP_BLE_MESH_MODEL_OP_TIME_ROLE_GET BT_MESH_MODEL_OP_TIME_ROLE_GET -#define ESP_BLE_MESH_MODEL_OP_TIME_ROLE_SET BT_MESH_MODEL_OP_TIME_ROLE_SET -#define ESP_BLE_MESH_MODEL_OP_TIME_ROLE_STATUS BT_MESH_MODEL_OP_TIME_ROLE_STATUS -#define ESP_BLE_MESH_MODEL_OP_TIME_ZONE_GET BT_MESH_MODEL_OP_TIME_ZONE_GET -#define ESP_BLE_MESH_MODEL_OP_TIME_ZONE_SET BT_MESH_MODEL_OP_TIME_ZONE_SET -#define ESP_BLE_MESH_MODEL_OP_TIME_ZONE_STATUS BT_MESH_MODEL_OP_TIME_ZONE_STATUS -#define ESP_BLE_MESH_MODEL_OP_TAI_UTC_DELTA_GET BT_MESH_MODEL_OP_TAI_UTC_DELTA_GET -#define ESP_BLE_MESH_MODEL_OP_TAI_UTC_DELTA_SET BT_MESH_MODEL_OP_TAI_UTC_DELTA_SET -#define ESP_BLE_MESH_MODEL_OP_TAI_UTC_DELTA_STATUS BT_MESH_MODEL_OP_TAI_UTC_DELTA_STATUS +#define ESP_BLE_MESH_MODEL_OP_TIME_GET BLE_MESH_MODEL_OP_TIME_GET +#define ESP_BLE_MESH_MODEL_OP_TIME_SET BLE_MESH_MODEL_OP_TIME_SET +#define ESP_BLE_MESH_MODEL_OP_TIME_STATUS BLE_MESH_MODEL_OP_TIME_STATUS +#define ESP_BLE_MESH_MODEL_OP_TIME_ROLE_GET BLE_MESH_MODEL_OP_TIME_ROLE_GET +#define ESP_BLE_MESH_MODEL_OP_TIME_ROLE_SET BLE_MESH_MODEL_OP_TIME_ROLE_SET +#define ESP_BLE_MESH_MODEL_OP_TIME_ROLE_STATUS BLE_MESH_MODEL_OP_TIME_ROLE_STATUS +#define ESP_BLE_MESH_MODEL_OP_TIME_ZONE_GET BLE_MESH_MODEL_OP_TIME_ZONE_GET +#define ESP_BLE_MESH_MODEL_OP_TIME_ZONE_SET BLE_MESH_MODEL_OP_TIME_ZONE_SET +#define ESP_BLE_MESH_MODEL_OP_TIME_ZONE_STATUS BLE_MESH_MODEL_OP_TIME_ZONE_STATUS +#define ESP_BLE_MESH_MODEL_OP_TAI_UTC_DELTA_GET BLE_MESH_MODEL_OP_TAI_UTC_DELTA_GET +#define ESP_BLE_MESH_MODEL_OP_TAI_UTC_DELTA_SET BLE_MESH_MODEL_OP_TAI_UTC_DELTA_SET +#define ESP_BLE_MESH_MODEL_OP_TAI_UTC_DELTA_STATUS BLE_MESH_MODEL_OP_TAI_UTC_DELTA_STATUS /*!< Scene Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_SCENE_GET BT_MESH_MODEL_OP_SCENE_GET -#define ESP_BLE_MESH_MODEL_OP_SCENE_RECALL BT_MESH_MODEL_OP_SCENE_RECALL -#define ESP_BLE_MESH_MODEL_OP_SCENE_RECALL_UNACK BT_MESH_MODEL_OP_SCENE_RECALL_UNACK -#define ESP_BLE_MESH_MODEL_OP_SCENE_STATUS BT_MESH_MODEL_OP_SCENE_STATUS -#define ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_GET BT_MESH_MODEL_OP_SCENE_REGISTER_GET -#define ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS BT_MESH_MODEL_OP_SCENE_REGISTER_STATUS +#define ESP_BLE_MESH_MODEL_OP_SCENE_GET BLE_MESH_MODEL_OP_SCENE_GET +#define ESP_BLE_MESH_MODEL_OP_SCENE_RECALL BLE_MESH_MODEL_OP_SCENE_RECALL +#define ESP_BLE_MESH_MODEL_OP_SCENE_RECALL_UNACK BLE_MESH_MODEL_OP_SCENE_RECALL_UNACK +#define ESP_BLE_MESH_MODEL_OP_SCENE_STATUS BLE_MESH_MODEL_OP_SCENE_STATUS +#define ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_GET BLE_MESH_MODEL_OP_SCENE_REGISTER_GET +#define ESP_BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS /*!< Scene Setup Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_SCENE_STORE BT_MESH_MODEL_OP_SCENE_STORE -#define ESP_BLE_MESH_MODEL_OP_SCENE_STORE_UNACK BT_MESH_MODEL_OP_SCENE_STORE_UNACK -#define ESP_BLE_MESH_MODEL_OP_SCENE_DELETE BT_MESH_MODEL_OP_SCENE_DELETE -#define ESP_BLE_MESH_MODEL_OP_SCENE_DELETE_UNACK BT_MESH_MODEL_OP_SCENE_DELETE_UNACK +#define ESP_BLE_MESH_MODEL_OP_SCENE_STORE BLE_MESH_MODEL_OP_SCENE_STORE +#define ESP_BLE_MESH_MODEL_OP_SCENE_STORE_UNACK BLE_MESH_MODEL_OP_SCENE_STORE_UNACK +#define ESP_BLE_MESH_MODEL_OP_SCENE_DELETE BLE_MESH_MODEL_OP_SCENE_DELETE +#define ESP_BLE_MESH_MODEL_OP_SCENE_DELETE_UNACK BLE_MESH_MODEL_OP_SCENE_DELETE_UNACK /*!< Scheduler Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_SCHEDULER_ACT_GET BT_MESH_MODEL_OP_SCHEDULER_ACT_GET -#define ESP_BLE_MESH_MODEL_OP_SCHEDULER_ACT_STATUS BT_MESH_MODEL_OP_SCHEDULER_ACT_STATUS -#define ESP_BLE_MESH_MODEL_OP_SCHEDULER_GET BT_MESH_MODEL_OP_SCHEDULER_GET -#define ESP_BLE_MESH_MODEL_OP_SCHEDULER_STATUS BT_MESH_MODEL_OP_SCHEDULER_STATUS +#define ESP_BLE_MESH_MODEL_OP_SCHEDULER_ACT_GET BLE_MESH_MODEL_OP_SCHEDULER_ACT_GET +#define ESP_BLE_MESH_MODEL_OP_SCHEDULER_ACT_STATUS BLE_MESH_MODEL_OP_SCHEDULER_ACT_STATUS +#define ESP_BLE_MESH_MODEL_OP_SCHEDULER_GET BLE_MESH_MODEL_OP_SCHEDULER_GET +#define ESP_BLE_MESH_MODEL_OP_SCHEDULER_STATUS BLE_MESH_MODEL_OP_SCHEDULER_STATUS /*!< Scheduler Setup Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET BT_MESH_MODEL_OP_SCHEDULER_ACT_SET -#define ESP_BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET_UNACK BT_MESH_MODEL_OP_SCHEDULER_ACT_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET +#define ESP_BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET_UNACK BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET_UNACK typedef uint32_t esp_ble_mesh_light_message_opcode_t; /*!< esp_ble_mesh_light_message_opcode_t belongs to esp_ble_mesh_opcode_t, this typedef is only used to locate the opcodes used by functions esp_ble_mesh_light_client_get_state & esp_ble_mesh_light_client_set_state */ /*!< Light Lightness Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_GET BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET_UNACK BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_GET BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET_UNACK BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_GET BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_STATUS BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_STATUS -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_GET BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_STATUS BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_STATUS -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_GET BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_GET BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET_UNACK BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_GET BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET_UNACK BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_GET BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_STATUS BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_GET BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_STATUS BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_GET BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS /*!< Light Lightness Setup Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET_UNACK BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET_UNACK BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET_UNACK BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET_UNACK BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET_UNACK /*!< Light CTL Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_GET BT_MESH_MODEL_OP_LIGHT_CTL_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_SET BT_MESH_MODEL_OP_LIGHT_CTL_SET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_SET_UNACK BT_MESH_MODEL_OP_LIGHT_CTL_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_STATUS BT_MESH_MODEL_OP_LIGHT_CTL_STATUS -#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_GET BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_GET BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS -#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET_UNACK BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS -#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_GET BT_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS BT_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_GET BLE_MESH_MODEL_OP_LIGHT_CTL_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_SET BLE_MESH_MODEL_OP_LIGHT_CTL_SET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_SET_UNACK BLE_MESH_MODEL_OP_LIGHT_CTL_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_STATUS BLE_MESH_MODEL_OP_LIGHT_CTL_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_GET BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_GET BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET_UNACK BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_GET BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS /*!< Light CTL Setup Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET BT_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET_UNACK BT_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET_UNACK BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET_UNACK BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET_UNACK BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET_UNACK /*!< Light HSL Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_GET BT_MESH_MODEL_OP_LIGHT_HSL_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_GET BT_MESH_MODEL_OP_LIGHT_HSL_HUE_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET BT_MESH_MODEL_OP_LIGHT_HSL_HUE_SET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET_UNACK BT_MESH_MODEL_OP_LIGHT_HSL_HUE_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS BT_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_GET BT_MESH_MODEL_OP_LIGHT_HSL_SATURATION_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET BT_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET_UNACK BT_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS BT_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_SET BT_MESH_MODEL_OP_LIGHT_HSL_SET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_SET_UNACK BT_MESH_MODEL_OP_LIGHT_HSL_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_STATUS BT_MESH_MODEL_OP_LIGHT_HSL_STATUS -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_TARGET_GET BT_MESH_MODEL_OP_LIGHT_HSL_TARGET_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_TARGET_STATUS BT_MESH_MODEL_OP_LIGHT_HSL_TARGET_STATUS -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_GET BT_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_STATUS BT_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_STATUS -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_GET BT_MESH_MODEL_OP_LIGHT_HSL_RANGE_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_STATUS BT_MESH_MODEL_OP_LIGHT_HSL_RANGE_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_GET BLE_MESH_MODEL_OP_LIGHT_HSL_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_GET BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET_UNACK BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_GET BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET_UNACK BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_SET BLE_MESH_MODEL_OP_LIGHT_HSL_SET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_SET_UNACK BLE_MESH_MODEL_OP_LIGHT_HSL_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_STATUS BLE_MESH_MODEL_OP_LIGHT_HSL_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_TARGET_GET BLE_MESH_MODEL_OP_LIGHT_HSL_TARGET_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_TARGET_STATUS BLE_MESH_MODEL_OP_LIGHT_HSL_TARGET_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_GET BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_STATUS BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_GET BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_STATUS BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_STATUS /*!< Light HSL Setup Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET BT_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET_UNACK BT_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET BT_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET_UNACK BT_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET_UNACK /* Model spec is wrong */ +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET_UNACK BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET_UNACK BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET_UNACK /* Model spec is wrong */ /*!< Light xyL Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_GET BT_MESH_MODEL_OP_LIGHT_XYL_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_SET BT_MESH_MODEL_OP_LIGHT_XYL_SET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_SET_UNACK BT_MESH_MODEL_OP_LIGHT_XYL_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_STATUS BT_MESH_MODEL_OP_LIGHT_XYL_STATUS -#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_TARGET_GET BT_MESH_MODEL_OP_LIGHT_XYL_TARGET_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_TARGET_STATUS BT_MESH_MODEL_OP_LIGHT_XYL_TARGET_STATUS -#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_GET BT_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_STATUS BT_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_STATUS -#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_GET BT_MESH_MODEL_OP_LIGHT_XYL_RANGE_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_STATUS BT_MESH_MODEL_OP_LIGHT_XYL_RANGE_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_GET BLE_MESH_MODEL_OP_LIGHT_XYL_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_SET BLE_MESH_MODEL_OP_LIGHT_XYL_SET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_SET_UNACK BLE_MESH_MODEL_OP_LIGHT_XYL_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_STATUS BLE_MESH_MODEL_OP_LIGHT_XYL_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_TARGET_GET BLE_MESH_MODEL_OP_LIGHT_XYL_TARGET_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_TARGET_STATUS BLE_MESH_MODEL_OP_LIGHT_XYL_TARGET_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_GET BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_STATUS BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_GET BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_STATUS BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_STATUS /*!< Light xyL Setup Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET BT_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET_UNACK BT_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET BT_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET_UNACK BT_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET_UNACK BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET_UNACK BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET_UNACK /*!< Light Control Message Opcode */ -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_MODE_GET BT_MESH_MODEL_OP_LIGHT_LC_MODE_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_MODE_SET BT_MESH_MODEL_OP_LIGHT_LC_MODE_SET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_MODE_SET_UNACK BT_MESH_MODEL_OP_LIGHT_LC_MODE_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_MODE_STATUS BT_MESH_MODEL_OP_LIGHT_LC_MODE_STATUS -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_OM_GET BT_MESH_MODEL_OP_LIGHT_LC_OM_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_OM_SET BT_MESH_MODEL_OP_LIGHT_LC_OM_SET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_OM_SET_UNACK BT_MESH_MODEL_OP_LIGHT_LC_OM_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_OM_STATUS BT_MESH_MODEL_OP_LIGHT_LC_OM_STATUS -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_GET BT_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET BT_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET_UNACK BT_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS BT_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK -#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_MODE_GET BLE_MESH_MODEL_OP_LIGHT_LC_MODE_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_MODE_SET BLE_MESH_MODEL_OP_LIGHT_LC_MODE_SET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_MODE_SET_UNACK BLE_MESH_MODEL_OP_LIGHT_LC_MODE_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_MODE_STATUS BLE_MESH_MODEL_OP_LIGHT_LC_MODE_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_OM_GET BLE_MESH_MODEL_OP_LIGHT_LC_OM_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_OM_SET BLE_MESH_MODEL_OP_LIGHT_LC_OM_SET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_OM_SET_UNACK BLE_MESH_MODEL_OP_LIGHT_LC_OM_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_OM_STATUS BLE_MESH_MODEL_OP_LIGHT_LC_OM_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_GET BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET_UNACK BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK +#define ESP_BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS typedef uint32_t esp_ble_mesh_opcode_t; /*!< End of defines of esp_ble_mesh_opcode_t */ @@ -611,7 +612,7 @@ typedef uint8_t esp_ble_mesh_model_status_t; /*!< This typedef is only used t * @return BLE Mesh transmit value that can be used e.g. for the default * values of the Configuration Model data. */ -#define ESP_BLE_MESH_TRANSMIT(count, int_ms) BT_MESH_TRANSMIT(count, int_ms) +#define ESP_BLE_MESH_TRANSMIT(count, int_ms) BLE_MESH_TRANSMIT(count, int_ms) /** @def ESP_BLE_MESH_GET_TRANSMIT_COUNT * @@ -621,7 +622,7 @@ typedef uint8_t esp_ble_mesh_model_status_t; /*!< This typedef is only used t * * @return Transmission count (actual transmissions equal to N + 1). */ -#define ESP_BLE_MESH_GET_TRANSMIT_COUNT(transmit) BT_MESH_TRANSMIT_COUNT(transmit) +#define ESP_BLE_MESH_GET_TRANSMIT_COUNT(transmit) BLE_MESH_TRANSMIT_COUNT(transmit) /** @def ESP_BLE_MESH_GET_TRANSMIT_INTERVAL * @@ -631,7 +632,7 @@ typedef uint8_t esp_ble_mesh_model_status_t; /*!< This typedef is only used t * * @return Transmission interval in milliseconds. */ -#define ESP_BLE_MESH_GET_TRANSMIT_INTERVAL(transmit) BT_MESH_TRANSMIT_INT(transmit) +#define ESP_BLE_MESH_GET_TRANSMIT_INTERVAL(transmit) BLE_MESH_TRANSMIT_INT(transmit) /** @def ESP_BLE_MESH_PUBLISH_TRANSMIT * @@ -644,7 +645,7 @@ typedef uint8_t esp_ble_mesh_model_status_t; /*!< This typedef is only used t * @return BLE Mesh transmit value that can be used e.g. for the default * values of the Configuration Model data. */ -#define ESP_BLE_MESH_PUBLISH_TRANSMIT(count, int_ms) BT_MESH_PUB_TRANSMIT(count, int_ms) +#define ESP_BLE_MESH_PUBLISH_TRANSMIT(count, int_ms) BLE_MESH_PUB_TRANSMIT(count, int_ms) /** @def ESP_BLE_MESH_GET_PUBLISH_TRANSMIT_COUNT * @@ -654,7 +655,7 @@ typedef uint8_t esp_ble_mesh_model_status_t; /*!< This typedef is only used t * * @return Retransmission count (actual transmissions equal to N + 1). */ -#define ESP_BLE_MESH_GET_PUBLISH_TRANSMIT_COUNT(transmit) BT_MESH_PUB_TRANSMIT_COUNT(transmit) +#define ESP_BLE_MESH_GET_PUBLISH_TRANSMIT_COUNT(transmit) BLE_MESH_PUB_TRANSMIT_COUNT(transmit) /** @def ESP_BLE_MESH_GET_PUBLISH_TRANSMIT_INTERVAL * @@ -664,7 +665,7 @@ typedef uint8_t esp_ble_mesh_model_status_t; /*!< This typedef is only used t * * @return Transmission interval in milliseconds. */ -#define ESP_BLE_MESH_GET_PUBLISH_TRANSMIT_INTERVAL(transmit) BT_MESH_PUB_TRANSMIT_INT(transmit) +#define ESP_BLE_MESH_GET_PUBLISH_TRANSMIT_INTERVAL(transmit) BLE_MESH_PUB_TRANSMIT_INT(transmit) /* esp_ble_mesh_cb_t is not needed to be initialized by users (set with 0 and will be initialized internally) */ typedef uint32_t esp_ble_mesh_cb_t; @@ -713,35 +714,35 @@ typedef enum { ESP_BLE_MESH_PROV_GATT = BIT(1), } esp_ble_mesh_prov_bearer_t; -#define ESP_BLE_MESH_MODEL_OP_1(b0) BT_MESH_MODEL_OP_1(b0) -#define ESP_BLE_MESH_MODEL_OP_2(b0, b1) BT_MESH_MODEL_OP_2(b0, b1) -#define ESP_BLE_MESH_MODEL_OP_3(b0, cid) BT_MESH_MODEL_OP_3(b0, cid) +#define ESP_BLE_MESH_MODEL_OP_1(b0) BLE_MESH_MODEL_OP_1(b0) +#define ESP_BLE_MESH_MODEL_OP_2(b0, b1) BLE_MESH_MODEL_OP_2(b0, b1) +#define ESP_BLE_MESH_MODEL_OP_3(b0, cid) BLE_MESH_MODEL_OP_3(b0, cid) -/*!< This macro is associated with BT_MESH_MODEL in mesh_access.h */ -#define ESP_BLE_MESH_SIG_MODEL(_id, _op, _pub, _user_data) \ -{ \ - .model_id = (_id), \ - .op = _op, \ - .keys = { [0 ... (CONFIG_BT_MESH_MODEL_KEY_COUNT - 1)] = \ - ESP_BLE_MESH_KEY_UNUSED }, \ - .pub = _pub, \ - .groups = { [0 ... (CONFIG_BT_MESH_MODEL_GROUP_COUNT - 1)] = \ - ESP_BLE_MESH_ADDR_UNASSIGNED }, \ - .user_data = _user_data, \ +/*!< This macro is associated with BLE_MESH_MODEL in mesh_access.h */ +#define ESP_BLE_MESH_SIG_MODEL(_id, _op, _pub, _user_data) \ +{ \ + .model_id = (_id), \ + .op = _op, \ + .keys = { [0 ... (CONFIG_BLE_MESH_MODEL_KEY_COUNT - 1)] = \ + ESP_BLE_MESH_KEY_UNUSED }, \ + .pub = _pub, \ + .groups = { [0 ... (CONFIG_BLE_MESH_MODEL_GROUP_COUNT - 1)] = \ + ESP_BLE_MESH_ADDR_UNASSIGNED }, \ + .user_data = _user_data, \ } -/*!< This macro is associated with BT_MESH_MODEL_VND in mesh_access.h */ -#define ESP_BLE_MESH_VENDOR_MODEL(_company, _id, _op, _pub, _user_data) \ -{ \ - .vnd.company_id = (_company), \ - .vnd.model_id = (_id), \ - .op = _op, \ - .pub = _pub, \ - .keys = { [0 ... (CONFIG_BT_MESH_MODEL_KEY_COUNT - 1)] = \ - ESP_BLE_MESH_KEY_UNUSED }, \ - .groups = { [0 ... (CONFIG_BT_MESH_MODEL_GROUP_COUNT - 1)] = \ - ESP_BLE_MESH_ADDR_UNASSIGNED }, \ - .user_data = _user_data, \ +/*!< This macro is associated with BLE_MESH_MODEL_VND in mesh_access.h */ +#define ESP_BLE_MESH_VENDOR_MODEL(_company, _id, _op, _pub, _user_data) \ +{ \ + .vnd.company_id = (_company), \ + .vnd.model_id = (_id), \ + .op = _op, \ + .pub = _pub, \ + .keys = { [0 ... (CONFIG_BLE_MESH_MODEL_KEY_COUNT - 1)] = \ + ESP_BLE_MESH_KEY_UNUSED }, \ + .groups = { [0 ... (CONFIG_BLE_MESH_MODEL_GROUP_COUNT - 1)] = \ + ESP_BLE_MESH_ADDR_UNASSIGNED }, \ + .user_data = _user_data, \ } /** @brief Helper to define a BLE Mesh element within an array. @@ -749,7 +750,7 @@ typedef enum { * In case the element has no SIG or Vendor models, the helper * macro ESP_BLE_MESH_MODEL_NONE can be given instead. * - * @note This macro is associated with BT_MESH_ELEM in mesh_access.h + * @note This macro is associated with BLE_MESH_ELEM in mesh_access.h * * @param _loc Location Descriptor. * @param _mods Array of SIG models. @@ -864,10 +865,10 @@ struct esp_ble_mesh_model { esp_ble_mesh_model_pub_t *const pub; /* AppKey List */ - uint16_t keys[CONFIG_BT_MESH_MODEL_KEY_COUNT]; + uint16_t keys[CONFIG_BLE_MESH_MODEL_KEY_COUNT]; /* Subscription List (group or virtual addresses) */ - uint16_t groups[CONFIG_BT_MESH_MODEL_GROUP_COUNT]; + uint16_t groups[CONFIG_BLE_MESH_MODEL_GROUP_COUNT]; /* Model operation context */ esp_ble_mesh_model_op_t *op; @@ -882,7 +883,7 @@ struct esp_ble_mesh_model { }; /** Helper to define an empty model array. - * This structure is associated with BT_MESH_MODEL_NONE in mesh_access.h + * This structure is associated with BLE_MESH_MODEL_NONE in mesh_access.h */ #define ESP_BLE_MESH_MODEL_NONE ((esp_ble_mesh_model_t []){}) @@ -905,7 +906,7 @@ typedef struct { /** Force sending reliably by using segment acknowledgement */ uint8_t send_rel: 1; - /** TTL, or BT_MESH_TTL_DEFAULT for default TTL. */ + /** TTL, or BLE_MESH_TTL_DEFAULT for default TTL. */ uint8_t send_ttl; /** Opcode of a received message. Not used for sending message. */ @@ -925,7 +926,7 @@ typedef struct { * This structure is associated with bt_mesh_prov in mesh_access.h */ typedef struct { -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE /** The UUID that is used when advertising as an unprovisioned device */ const uint8_t *uuid; @@ -958,8 +959,8 @@ typedef struct { esp_ble_mesh_cb_t link_close_cb; esp_ble_mesh_cb_t complete_cb; esp_ble_mesh_cb_t reset_cb; -#endif /* CONFIG_BT_MESH_NODE */ -#ifdef CONFIG_BT_MESH_PROVISIONER +#endif /* CONFIG_BLE_MESH_NODE */ +#ifdef CONFIG_BLE_MESH_PROVISIONER /* Provisioner device UUID */ const uint8_t *prov_uuid; @@ -1000,7 +1001,7 @@ typedef struct { esp_ble_mesh_cb_t provisioner_link_open; esp_ble_mesh_cb_t provisioner_link_close; esp_ble_mesh_cb_t provisioner_prov_comp; -#endif /* CONFIG_BT_MESH_PROVISIONER */ +#endif /* CONFIG_BLE_MESH_PROVISIONER */ } esp_ble_mesh_prov_t; /** Node Composition @@ -1106,7 +1107,7 @@ typedef enum { ESP_BLE_MESH_NODE_PROXY_IDENTITY_ENABLE_COMP_EVT, /*!< Enable BLE Mesh Proxy Identity advertising completion event */ ESP_BLE_MESH_NODE_PROXY_GATT_ENABLE_COMP_EVT, /*!< Enable BLE Mesh GATT Proxy Service completion event */ ESP_BLE_MESH_NODE_PROXY_GATT_DISABLE_COMP_EVT, /*!< Disable BLE Mesh GATT Proxy Service completion event */ -#if (CONFIG_BT_MESH_PROVISIONER) +#if (CONFIG_BLE_MESH_PROVISIONER) ESP_BLE_MESH_PROVISIONER_PROV_ENABLE_COMP_EVT, /*!< Provisioner enable provisioning functionality completion event */ ESP_BLE_MESH_PROVISIONER_PROV_DISABLE_COMP_EVT, /*!< Provisioner disable provisioning functionality completion event */ ESP_BLE_MESH_PROVISIONER_RECV_UNPROV_ADV_PKT_EVT, /*!< Provisioner receives unprovisioned device beacon event */ @@ -1127,7 +1128,7 @@ typedef enum { ESP_BLE_MESH_PROVISIONER_ADD_LOCAL_APP_KEY_COMP_EVT, /*!< Provisioner add local app key completion event */ ESP_BLE_MESH_PROVISIONER_BIND_APP_KEY_TO_MODEL_COMP_EVT, /*!< Provisioner bind local model with local app key completion event */ ESP_BLE_MESH_PROVISIONER_ADD_LOCAL_NET_KEY_COMP_EVT, /*!< Provisioner add local network key completion event */ -#endif /* CONFIG_BT_MESH_PROVISIONER */ +#endif /* CONFIG_BLE_MESH_PROVISIONER */ ESP_BLE_MESH_SET_FAST_PROV_INFO_COMP_EVT, /* !< Set fast provisioning information (e.g. unicast address range, net_idx, etc.) completion event */ ESP_BLE_MESH_SET_FAST_PROV_ACTION_COMP_EVT, /* !< Set fast provisioning action completion event */ ESP_BLE_MESH_PROV_EVT_MAX, @@ -1251,7 +1252,7 @@ typedef union { struct ble_mesh_proxy_gatt_disable_comp_param { int err_code; } node_proxy_gatt_disable_comp; -#if (CONFIG_BT_MESH_PROVISIONER) +#if (CONFIG_BLE_MESH_PROVISIONER) /** * @brief ESP_BLE_MESH_PROVISIONER_RECV_UNPROV_ADV_PKT_EVT */ @@ -1395,8 +1396,8 @@ typedef union { int err_code; uint16_t net_idx; } provisioner_add_net_key_comp; -#endif /* CONFIG_BT_MESH_PROVISIONER */ -#if (CONFIG_BT_MESH_FAST_PROV) +#endif /* CONFIG_BLE_MESH_PROVISIONER */ +#if (CONFIG_BLE_MESH_FAST_PROV) struct ble_mesh_set_fast_prov_info_comp_param { uint8_t status_unicast; uint8_t status_net_idx; @@ -1405,7 +1406,7 @@ typedef union { struct ble_mesh_set_fast_prov_action_comp_param { uint8_t status_action; } set_fast_prov_action_comp; -#endif /* CONFIG_BT_MESH_FAST_PROV */ +#endif /* CONFIG_BLE_MESH_FAST_PROV */ } esp_ble_mesh_prov_cb_param_t; typedef union { @@ -1476,5 +1477,4 @@ typedef struct { uint8_t msg_role; /*!< Role of the device (Node/Provisioner) that is going to send messages */ } esp_ble_mesh_client_t; -#endif /* #if CONFIG_BT_MESH */ #endif /* _ESP_BLE_MESH_DEFS_H_ */ diff --git a/components/bt/ble_mesh/api/models/esp_ble_mesh_config_model_api.c b/components/bt/ble_mesh/api/models/esp_ble_mesh_config_model_api.c index 7a6b395951..67694eef4e 100644 --- a/components/bt/ble_mesh/api/models/esp_ble_mesh_config_model_api.c +++ b/components/bt/ble_mesh/api/models/esp_ble_mesh_config_model_api.c @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include "btc/btc_task.h" #include "btc/btc_manage.h" @@ -20,7 +20,7 @@ #include "esp_bt_defs.h" #include "esp_bt_main.h" -#include "btc_ble_mesh_config_client.h" +#include "btc_ble_mesh_config_model.h" #include "esp_ble_mesh_config_model_api.h" esp_err_t esp_ble_mesh_register_config_client_callback(esp_ble_mesh_cfg_client_cb_t callback) @@ -40,13 +40,13 @@ 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) { + btc_ble_mesh_cfg_client_args_t arg = {0}; + btc_msg_t msg = {0}; + if (!params || !params->model || !params->ctx.addr || !get_state) { return ESP_ERR_INVALID_ARG; } - btc_msg_t msg; - btc_ble_mesh_cfg_client_args_t arg; - ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; @@ -62,13 +62,13 @@ 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) { + btc_ble_mesh_cfg_client_args_t arg = {0}; + btc_msg_t msg = {0}; + if (!params || !params->model || !params->ctx.addr || !set_state) { return ESP_ERR_INVALID_ARG; } - btc_msg_t msg; - btc_ble_mesh_cfg_client_args_t arg; - ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; diff --git a/components/bt/ble_mesh/api/models/esp_ble_mesh_generic_model_api.c b/components/bt/ble_mesh/api/models/esp_ble_mesh_generic_model_api.c index ca7b55ebf8..82f6ff5850 100644 --- a/components/bt/ble_mesh/api/models/esp_ble_mesh_generic_model_api.c +++ b/components/bt/ble_mesh/api/models/esp_ble_mesh_generic_model_api.c @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include "btc/btc_task.h" #include "btc/btc_manage.h" @@ -20,7 +20,7 @@ #include "esp_bt_defs.h" #include "esp_bt_main.h" -#include "btc_ble_mesh_generic_client.h" +#include "btc_ble_mesh_generic_model.h" #include "esp_ble_mesh_generic_model_api.h" esp_err_t esp_ble_mesh_register_generic_client_callback(esp_ble_mesh_generic_client_cb_t callback) @@ -33,13 +33,13 @@ 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) { + btc_ble_mesh_generic_client_args_t arg = {0}; + btc_msg_t msg = {0}; + if (!params || !params->model || !params->ctx.addr || !get_state) { return ESP_ERR_INVALID_ARG; } - btc_msg_t msg; - btc_ble_mesh_generic_client_args_t arg; - ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; @@ -55,13 +55,13 @@ 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) { + btc_ble_mesh_generic_client_args_t arg = {0}; + btc_msg_t msg = {0}; + if (!params || !params->model || !params->ctx.addr || !set_state) { return ESP_ERR_INVALID_ARG; } - btc_msg_t msg; - btc_ble_mesh_generic_client_args_t arg; - ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; diff --git a/components/bt/ble_mesh/api/models/esp_ble_mesh_health_model_api.c b/components/bt/ble_mesh/api/models/esp_ble_mesh_health_model_api.c index 4b59c54660..e7df777dc0 100644 --- a/components/bt/ble_mesh/api/models/esp_ble_mesh_health_model_api.c +++ b/components/bt/ble_mesh/api/models/esp_ble_mesh_health_model_api.c @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include "btc/btc_task.h" #include "btc/btc_manage.h" @@ -20,7 +20,7 @@ #include "esp_bt_defs.h" #include "esp_bt_main.h" -#include "btc_ble_mesh_health.h" +#include "btc_ble_mesh_health_model.h" #include "esp_ble_mesh_health_model_api.h" esp_err_t esp_ble_mesh_register_health_client_callback(esp_ble_mesh_health_client_cb_t callback) @@ -40,13 +40,13 @@ 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) { + btc_ble_mesh_health_client_args_t arg = {0}; + btc_msg_t msg = {0}; + if (!params || !params->model || !params->ctx.addr || !get_state) { return ESP_ERR_INVALID_ARG; } - btc_msg_t msg; - btc_ble_mesh_health_client_args_t arg; - ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; @@ -62,13 +62,13 @@ 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) { + btc_ble_mesh_health_client_args_t arg = {0}; + btc_msg_t msg = {0}; + if (!params || !params->model || !params->ctx.addr || !set_state) { return ESP_ERR_INVALID_ARG; } - btc_msg_t msg; - btc_ble_mesh_health_client_args_t arg; - ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; @@ -84,7 +84,7 @@ esp_err_t esp_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param_ esp_err_t esp_ble_mesh_health_server_fault_update(esp_ble_mesh_elem_t *element) { btc_ble_mesh_health_server_args_t arg = {0}; - btc_msg_t msg; + btc_msg_t msg = {0}; ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); diff --git a/components/bt/ble_mesh/api/models/esp_ble_mesh_lighting_model_api.c b/components/bt/ble_mesh/api/models/esp_ble_mesh_lighting_model_api.c index 82591cb96f..eea415d618 100644 --- a/components/bt/ble_mesh/api/models/esp_ble_mesh_lighting_model_api.c +++ b/components/bt/ble_mesh/api/models/esp_ble_mesh_lighting_model_api.c @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include "btc/btc_task.h" #include "btc/btc_manage.h" @@ -20,7 +20,7 @@ #include "esp_bt_defs.h" #include "esp_bt_main.h" -#include "btc_ble_mesh_light_client.h" +#include "btc_ble_mesh_lighting_model.h" #include "esp_ble_mesh_lighting_model_api.h" esp_err_t esp_ble_mesh_register_light_client_callback(esp_ble_mesh_light_client_cb_t callback) @@ -33,13 +33,13 @@ 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) { + btc_ble_mesh_light_client_args_t arg = {0}; + btc_msg_t msg = {0}; + if (!params || !params->model || !params->ctx.addr || !get_state) { return ESP_ERR_INVALID_ARG; } - btc_msg_t msg; - btc_ble_mesh_light_client_args_t arg; - ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; @@ -55,13 +55,13 @@ 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) { + btc_ble_mesh_light_client_args_t arg = {0}; + btc_msg_t msg = {0}; + if (!params || !params->model || !params->ctx.addr || !set_state) { return ESP_ERR_INVALID_ARG; } - btc_msg_t msg; - btc_ble_mesh_light_client_args_t arg; - ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; diff --git a/components/bt/ble_mesh/api/models/esp_ble_mesh_sensor_model_api.c b/components/bt/ble_mesh/api/models/esp_ble_mesh_sensor_model_api.c index f967adca4b..41072d227f 100644 --- a/components/bt/ble_mesh/api/models/esp_ble_mesh_sensor_model_api.c +++ b/components/bt/ble_mesh/api/models/esp_ble_mesh_sensor_model_api.c @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include "btc/btc_task.h" #include "btc/btc_manage.h" @@ -20,7 +20,7 @@ #include "esp_bt_defs.h" #include "esp_bt_main.h" -#include "btc_ble_mesh_sensor_client.h" +#include "btc_ble_mesh_sensor_model.h" #include "esp_ble_mesh_sensor_model_api.h" esp_err_t esp_ble_mesh_register_sensor_client_callback(esp_ble_mesh_sensor_client_cb_t callback) @@ -33,13 +33,13 @@ 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) { + btc_ble_mesh_sensor_client_args_t arg = {0}; + btc_msg_t msg = {0}; + if (!params || !params->model || !params->ctx.addr || !get_state) { return ESP_ERR_INVALID_ARG; } - btc_msg_t msg; - btc_ble_mesh_sensor_client_args_t arg; - ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; @@ -55,13 +55,13 @@ 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) { + btc_ble_mesh_sensor_client_args_t arg = {0}; + btc_msg_t msg = {0}; + if (!params || !params->model || !params->ctx.addr || !set_state) { return ESP_ERR_INVALID_ARG; } - btc_msg_t msg; - btc_ble_mesh_sensor_client_args_t arg; - ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; diff --git a/components/bt/ble_mesh/api/models/esp_ble_mesh_time_scene_model_api.c b/components/bt/ble_mesh/api/models/esp_ble_mesh_time_scene_model_api.c index 264fa0e1d9..13823b9787 100644 --- a/components/bt/ble_mesh/api/models/esp_ble_mesh_time_scene_model_api.c +++ b/components/bt/ble_mesh/api/models/esp_ble_mesh_time_scene_model_api.c @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include +#include #include "btc/btc_task.h" #include "btc/btc_manage.h" @@ -20,7 +20,7 @@ #include "esp_bt_defs.h" #include "esp_bt_main.h" -#include "btc_ble_mesh_time_scene_client.h" +#include "btc_ble_mesh_time_scene_model.h" #include "esp_ble_mesh_time_scene_model_api.h" esp_err_t esp_ble_mesh_register_time_scene_client_callback(esp_ble_mesh_time_scene_client_cb_t callback) @@ -33,13 +33,13 @@ 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) { + btc_ble_mesh_time_scene_client_args_t arg = {0}; + btc_msg_t msg = {0}; + if (!params || !params->model || !params->ctx.addr || !get_state) { return ESP_ERR_INVALID_ARG; } - btc_msg_t msg; - btc_ble_mesh_time_scene_client_args_t arg; - ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; @@ -55,13 +55,13 @@ 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) { + btc_ble_mesh_time_scene_client_args_t arg = {0}; + btc_msg_t msg = {0}; + if (!params || !params->model || !params->ctx.addr || !set_state) { return ESP_ERR_INVALID_ARG; } - btc_msg_t msg; - btc_ble_mesh_time_scene_client_args_t arg; - ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); msg.sig = BTC_SIG_API_CALL; diff --git a/components/bt/ble_mesh/api/models/include/esp_ble_mesh_lighting_model_api.h b/components/bt/ble_mesh/api/models/include/esp_ble_mesh_lighting_model_api.h index e0f849e8f6..ab119a48bc 100644 --- a/components/bt/ble_mesh/api/models/include/esp_ble_mesh_lighting_model_api.h +++ b/components/bt/ble_mesh/api/models/include/esp_ble_mesh_lighting_model_api.h @@ -19,7 +19,7 @@ #ifndef _ESP_BLE_MESH_LIGHTING_MODEL_API_H_ #define _ESP_BLE_MESH_LIGHTING_MODEL_API_H_ -#include "light_client.h" +#include "lighting_client.h" #include "esp_ble_mesh_defs.h" /** @def ESP_BLE_MESH_MODEL_LIGHT_LIGHTNESS_CLI diff --git a/components/bt/ble_mesh/btc/btc_ble_mesh_config_client.c b/components/bt/ble_mesh/btc/btc_ble_mesh_config_model.c similarity index 92% rename from components/bt/ble_mesh/btc/btc_ble_mesh_config_client.c rename to components/bt/ble_mesh/btc/btc_ble_mesh_config_model.c index 3d82c2d725..52a05c9492 100644 --- a/components/bt/ble_mesh/btc/btc_ble_mesh_config_client.c +++ b/components/bt/ble_mesh/btc/btc_ble_mesh_config_model.c @@ -19,8 +19,8 @@ #include "osi/allocator.h" #include "cfg_cli.h" -#include "common.h" -#include "btc_ble_mesh_config_client.h" +#include "mesh_common.h" +#include "btc_ble_mesh_config_model.h" #include "esp_ble_mesh_config_model_api.h" #define CID_NVAL 0xffff @@ -51,7 +51,7 @@ void btc_ble_mesh_cfg_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p btc_ble_mesh_cfg_client_args_t *src = (btc_ble_mesh_cfg_client_args_t *)p_src; if (!msg || !dst || !src) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -65,7 +65,7 @@ void btc_ble_mesh_cfg_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p 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 { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } break; } @@ -78,12 +78,12 @@ void btc_ble_mesh_cfg_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p 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 { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } break; } default: - LOG_DEBUG("%s Unhandled deep copy %d", __func__, msg->act); + LOG_DEBUG("%s, Unknown deep copy act %d", __func__, msg->act); break; } } @@ -96,7 +96,7 @@ static void btc_ble_mesh_cfg_client_copy_req_data(btc_msg_t *msg, void *p_dest, u16_t length; if (!msg || !p_src_data || !p_dest_data) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -113,7 +113,7 @@ static void btc_ble_mesh_cfg_client_copy_req_data(btc_msg_t *msg, void *p_dest, 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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.comp_data_status.composition_data, 0); @@ -130,7 +130,7 @@ static void btc_ble_mesh_cfg_client_copy_req_data(btc_msg_t *msg, void *p_dest, 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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.model_sub_list.sub_addr, 0); @@ -145,7 +145,7 @@ static void btc_ble_mesh_cfg_client_copy_req_data(btc_msg_t *msg, void *p_dest, 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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.netkey_list.net_idx, 0); @@ -160,7 +160,7 @@ static void btc_ble_mesh_cfg_client_copy_req_data(btc_msg_t *msg, void *p_dest, 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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.appkey_list.app_idx, 0); @@ -177,7 +177,7 @@ static void btc_ble_mesh_cfg_client_copy_req_data(btc_msg_t *msg, void *p_dest, 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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.model_app_list.app_idx, 0); @@ -196,7 +196,7 @@ static void btc_ble_mesh_cfg_client_copy_req_data(btc_msg_t *msg, void *p_dest, if (p_dest_data->params) { memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t)); } else { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } } break; @@ -211,7 +211,7 @@ static void btc_ble_mesh_cfg_client_free_req_data(btc_msg_t *msg) u32_t opcode; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -267,7 +267,7 @@ void btc_ble_mesh_cfg_client_arg_deep_free(btc_msg_t *msg) btc_ble_mesh_cfg_client_args_t *arg = NULL; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -317,12 +317,12 @@ void bt_mesh_callback_config_status_to_btc(u32_t opcode, u8_t evt_type, 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}; + esp_ble_mesh_client_common_param_t params = {0}; size_t length; uint8_t act; if (!model || !ctx) { - LOG_ERROR("%s: invalid parameter", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -340,7 +340,7 @@ void bt_mesh_callback_config_status_to_btc(u32_t opcode, u8_t evt_type, act = ESP_BLE_MESH_CFG_CLIENT_TIMEOUT_EVT; break; default: - LOG_ERROR("%s: unknown config status event type", __func__); + LOG_ERROR("%s, Unknown config client event type %d", __func__, evt_type); return; } @@ -369,7 +369,7 @@ void btc_mesh_cfg_client_publish_callback(u32_t opcode, struct bt_mesh_model *mo struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { if (!model || !ctx || !buf) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -383,7 +383,7 @@ void btc_mesh_cfg_client_call_handler(btc_msg_t *msg) bt_mesh_role_param_t role_param = {0}; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -394,8 +394,8 @@ void btc_mesh_cfg_client_call_handler(btc_msg_t *msg) cfg_client_cb.params = arg->cfg_client_get_state.params; role_param.model = (struct bt_mesh_model *)cfg_client_cb.params->model; role_param.role = cfg_client_cb.params->msg_role; - if (bt_mesh_copy_msg_role(&role_param)) { - LOG_ERROR("%s: copy msg_role fail", __func__); + if (bt_mesh_set_model_role(&role_param)) { + LOG_ERROR("%s, Failed to set model role", __func__); return; } btc_ble_mesh_config_client_get_state(arg->cfg_client_get_state.params, @@ -410,8 +410,8 @@ void btc_mesh_cfg_client_call_handler(btc_msg_t *msg) cfg_client_cb.params = arg->cfg_client_set_state.params; role_param.model = (struct bt_mesh_model *)cfg_client_cb.params->model; role_param.role = cfg_client_cb.params->msg_role; - if (bt_mesh_copy_msg_role(&role_param)) { - LOG_ERROR("%s: copy msg_role fail", __func__); + if (bt_mesh_set_model_role(&role_param)) { + LOG_ERROR("%s, Failed to set model role", __func__); return; } btc_ble_mesh_config_client_set_state(arg->cfg_client_set_state.params, @@ -434,7 +434,7 @@ void btc_mesh_cfg_client_cb_handler(btc_msg_t *msg) esp_ble_mesh_cfg_client_cb_param_t *param = NULL; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -443,7 +443,7 @@ void btc_mesh_cfg_client_cb_handler(btc_msg_t *msg) if (msg->act < ESP_BLE_MESH_CFG_CLIENT_EVT_MAX) { btc_ble_mesh_cfg_client_cb_to_app(msg->act, param); } else { - LOG_ERROR("%s, unknown msg->act = %d", __func__, msg->act); + LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act); } btc_ble_mesh_cfg_client_free_req_data(msg); @@ -456,12 +456,12 @@ int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_t *par struct bt_mesh_msg_ctx ctx = {0}; if (!params || !cfg_client_cb) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return -EINVAL; } ctx.net_idx = params->ctx.net_idx; - ctx.app_idx = BT_MESH_KEY_DEV; + 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; @@ -516,7 +516,7 @@ int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_t *par case ESP_BLE_MESH_MODEL_OP_NETWORK_TRANSMIT_GET: return (cfg_client_cb->error_code = bt_mesh_cfg_net_transmit_get(&ctx)); default: - BT_WARN("%s, invalid opcode 0x%x", __func__, params->opcode); + BT_WARN("%s, Invalid opcode 0x%x", __func__, params->opcode); return (cfg_client_cb->error_code = -EINVAL); } @@ -530,12 +530,12 @@ int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_t *par struct bt_mesh_msg_ctx ctx = {0}; if (!params || !set_state || !cfg_client_cb) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return -EINVAL; } ctx.net_idx = params->ctx.net_idx; - ctx.app_idx = BT_MESH_KEY_DEV; + 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; @@ -653,7 +653,7 @@ int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_t *par return (cfg_client_cb->error_code = bt_mesh_cfg_net_transmit_set(&ctx, set_state->net_transmit_set.net_transmit)); default: - BT_WARN("%s, invalid opcode 0x%x", __func__, params->opcode); + BT_WARN("%s, Invalid opcode 0x%x", __func__, params->opcode); return (cfg_client_cb->error_code = -EINVAL); } @@ -682,7 +682,7 @@ void bt_mesh_callback_cfg_server_event_to_btc(u8_t evt_type, struct bt_mesh_mode uint8_t act; if (!model || !ctx) { - LOG_ERROR("%s: invalid parameter", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -691,7 +691,7 @@ void bt_mesh_callback_cfg_server_event_to_btc(u8_t evt_type, struct bt_mesh_mode act = ESP_BLE_MESH_CFG_SERVER_RECV_MSG_EVT; break; default: - LOG_ERROR("%s: unknown config sever event type", __func__); + LOG_ERROR("%s, Unknown config server event type %d", __func__, evt_type); return; } @@ -716,7 +716,7 @@ void btc_mesh_cfg_server_cb_handler(btc_msg_t *msg) esp_ble_mesh_cfg_server_cb_param_t *param = NULL; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -725,6 +725,6 @@ void btc_mesh_cfg_server_cb_handler(btc_msg_t *msg) if (msg->act < ESP_BLE_MESH_CFG_SERVER_EVT_MAX) { btc_ble_mesh_cfg_server_cb_to_app(msg->act, param); } else { - LOG_ERROR("%s, unknown msg->act = %d", __func__, msg->act); + LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act); } } diff --git a/components/bt/ble_mesh/btc/btc_ble_mesh_generic_client.c b/components/bt/ble_mesh/btc/btc_ble_mesh_generic_model.c similarity index 91% rename from components/bt/ble_mesh/btc/btc_ble_mesh_generic_client.c rename to components/bt/ble_mesh/btc/btc_ble_mesh_generic_model.c index 07b2d44db1..cbc8b51114 100644 --- a/components/bt/ble_mesh/btc/btc_ble_mesh_generic_client.c +++ b/components/bt/ble_mesh/btc/btc_ble_mesh_generic_model.c @@ -19,7 +19,7 @@ #include "osi/allocator.h" #include "cfg_cli.h" -#include "btc_ble_mesh_generic_client.h" +#include "btc_ble_mesh_generic_model.h" #include "esp_ble_mesh_generic_model_api.h" static inline void btc_ble_mesh_cb_to_app(esp_ble_mesh_generic_client_cb_event_t event, @@ -39,7 +39,7 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi u16_t length; if (!msg || !dst || !src) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -53,7 +53,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 { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } break; } @@ -73,7 +73,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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(dst->generic_client_set_state.set_state->user_property_set.property_value, 0); @@ -87,7 +87,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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(dst->generic_client_set_state.set_state->admin_property_set.property_value, 0); @@ -100,12 +100,12 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi break; } } else { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } break; } default: - LOG_DEBUG("%s Unhandled deep copy %d", __func__, msg->act); + LOG_DEBUG("%s, Unknown deep copy act %d", __func__, msg->act); break; } } @@ -118,7 +118,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src u16_t length; if (!msg || !p_src_data || !p_dest_data) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -135,7 +135,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src 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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.user_properties_status.property_ids, 0); @@ -151,7 +151,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src 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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.user_property_status.property_value, 0); @@ -166,7 +166,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src 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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.admin_properties_status.property_ids, 0); @@ -182,7 +182,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src 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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.admin_property_status.property_value, 0); @@ -197,7 +197,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src 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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.manufacturer_properties_status.property_ids, 0); @@ -213,7 +213,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src 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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.manufacturer_property_status.property_value, 0); @@ -228,7 +228,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src 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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.client_properties_status.property_ids, 0); @@ -247,7 +247,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src if (p_dest_data->params) { memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t)); } else { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } } break; @@ -262,7 +262,7 @@ static void btc_ble_mesh_free_req_data(btc_msg_t *msg) u32_t opcode; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -326,7 +326,7 @@ void btc_ble_mesh_generic_client_arg_deep_free(btc_msg_t *msg) u32_t opcode = 0; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -389,12 +389,12 @@ void bt_mesh_callback_generic_status_to_btc(u32_t opcode, u8_t evt_type, 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}; - size_t length; + esp_ble_mesh_client_common_param_t params = {0}; + size_t length; uint8_t act; if (!model || !ctx) { - LOG_ERROR("%s: invalid parameter", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -412,7 +412,7 @@ void bt_mesh_callback_generic_status_to_btc(u32_t opcode, u8_t evt_type, act = ESP_BLE_MESH_GENERIC_CLIENT_TIMEOUT_EVT; break; default: - LOG_ERROR("%s: unknown generic status event type", __func__); + LOG_ERROR("%s, Unknown generic client event type %d", __func__, evt_type); return; } @@ -440,7 +440,7 @@ void btc_mesh_generic_client_publish_callback(u32_t opcode, struct bt_mesh_model struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { if (!model || !ctx || !buf) { - LOG_ERROR("%s: invalid parameter", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -456,7 +456,7 @@ void btc_mesh_generic_client_call_handler(btc_msg_t *msg) bt_mesh_role_param_t role_param = {0}; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -467,8 +467,8 @@ void btc_mesh_generic_client_call_handler(btc_msg_t *msg) params = arg->generic_client_get_state.params; role_param.model = (struct bt_mesh_model *)params->model; role_param.role = params->msg_role; - if (bt_mesh_copy_msg_role(&role_param)) { - LOG_ERROR("%s: copy msg_role fail", __func__); + if (bt_mesh_set_model_role(&role_param)) { + LOG_ERROR("%s, Failed to set model role", __func__); return; } common.opcode = params->opcode; @@ -496,8 +496,8 @@ void btc_mesh_generic_client_call_handler(btc_msg_t *msg) params = arg->generic_client_set_state.params; role_param.model = (struct bt_mesh_model *)params->model; role_param.role = params->msg_role; - if (bt_mesh_copy_msg_role(&role_param)) { - LOG_ERROR("%s: copy msg_role fail", __func__); + if (bt_mesh_set_model_role(&role_param)) { + LOG_ERROR("%s, Failed to set model role", __func__); return; } common.opcode = params->opcode; @@ -533,7 +533,7 @@ void btc_mesh_generic_client_cb_handler(btc_msg_t *msg) esp_ble_mesh_generic_client_cb_param_t *param = NULL; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -542,7 +542,7 @@ void btc_mesh_generic_client_cb_handler(btc_msg_t *msg) if (msg->act < ESP_BLE_MESH_GENERIC_CLIENT_EVT_MAX) { btc_ble_mesh_cb_to_app(msg->act, param); } else { - LOG_ERROR("%s, unknown msg->act = %d", __func__, msg->act); + LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act); } btc_ble_mesh_free_req_data(msg); diff --git a/components/bt/ble_mesh/btc/btc_ble_mesh_health.c b/components/bt/ble_mesh/btc/btc_ble_mesh_health_model.c similarity index 90% rename from components/bt/ble_mesh/btc/btc_ble_mesh_health.c rename to components/bt/ble_mesh/btc/btc_ble_mesh_health_model.c index 7f4e75e439..1684c2deaf 100644 --- a/components/bt/ble_mesh/btc/btc_ble_mesh_health.c +++ b/components/bt/ble_mesh/btc/btc_ble_mesh_health_model.c @@ -21,8 +21,9 @@ #include "health_srv.h" #include "health_cli.h" -#include "common.h" -#include "btc_ble_mesh_health.h" +#include "mesh_common.h" + +#include "btc_ble_mesh_health_model.h" #include "esp_ble_mesh_defs.h" extern s32_t health_msg_timeout; @@ -51,7 +52,7 @@ void btc_ble_mesh_health_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void btc_ble_mesh_health_client_args_t *src = (btc_ble_mesh_health_client_args_t *)p_src; if (!msg || !dst || !src) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -65,7 +66,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 { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } break; } @@ -78,12 +79,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 { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } break; } default: - LOG_DEBUG("%s Unhandled deep copy %d", __func__, msg->act); + LOG_DEBUG("%s, Unknown deep copy act %d", __func__, msg->act); break; } } @@ -93,7 +94,7 @@ static void btc_ble_mesh_health_client_arg_deep_free(btc_msg_t *msg) btc_ble_mesh_health_client_args_t *arg = NULL; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -126,7 +127,7 @@ static void btc_ble_mesh_health_client_arg_deep_free(btc_msg_t *msg) void btc_ble_mesh_health_server_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) { if (!msg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -141,7 +142,7 @@ void btc_ble_mesh_health_server_arg_deep_copy(btc_msg_t *msg, void *p_dest, void static void btc_ble_mesh_health_server_arg_deep_free(btc_msg_t *msg) { if (!msg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -161,7 +162,7 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des u16_t length; if (!msg || !p_src_data || !p_dest_data) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -177,7 +178,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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.current_status.fault_array, 0); @@ -194,7 +195,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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.fault_status.fault_array, 0); @@ -213,7 +214,7 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des if (p_dest_data->params) { memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t)); } else { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } } break; @@ -228,7 +229,7 @@ static void btc_ble_mesh_health_client_free_req_data(btc_msg_t *msg) u32_t opcode; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -267,7 +268,7 @@ static void btc_ble_mesh_health_client_free_req_data(btc_msg_t *msg) static void btc_ble_mesh_health_server_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src) { if (!msg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -282,7 +283,7 @@ static void btc_ble_mesh_health_server_copy_req_data(btc_msg_t *msg, void *p_des static void btc_ble_mesh_health_server_free_req_data(btc_msg_t *msg) { if (!msg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -329,7 +330,7 @@ int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param_t *par struct bt_mesh_msg_ctx ctx = {0}; if (!params || !client_cb) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return -EINVAL; } @@ -363,7 +364,7 @@ int btc_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param_t *par struct bt_mesh_msg_ctx ctx = {0}; if (!params || !set_state || !client_cb) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return -EINVAL; } @@ -401,7 +402,7 @@ int btc_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param_t *par return (client_cb->error_code = bt_mesh_health_fault_clear(&ctx, set_state->fault_clear.company_id, false)); default: - BT_WARN("%s, invalid opcode 0x%x", __func__, params->opcode); + BT_WARN("%s, Invalid opcode 0x%x", __func__, params->opcode); return (client_cb->error_code = -EINVAL); } @@ -414,12 +415,12 @@ void bt_mesh_callback_health_status_to_btc(u32_t opcode, u8_t evt_type, const u8_t *val, u16_t len) { esp_ble_mesh_health_client_cb_param_t cb_params = {0}; - esp_ble_mesh_client_common_param_t params = {0}; - size_t length; + esp_ble_mesh_client_common_param_t params = {0}; + size_t length; uint8_t act; if (!model || !ctx) { - LOG_ERROR("%s: invalid parameter", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -437,7 +438,7 @@ void bt_mesh_callback_health_status_to_btc(u32_t opcode, u8_t evt_type, act = ESP_BLE_MESH_HEALTH_CLIENT_TIMEOUT_EVT; break; default: - LOG_ERROR("%s: unknown health status event type", __func__); + LOG_ERROR("%s, Unknown health client event type %d", __func__, evt_type); return; } @@ -465,7 +466,7 @@ void btc_mesh_health_publish_callback(u32_t opcode, struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { if (!model || !ctx || !buf) { - LOG_ERROR("%s: invalid parameter", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -479,7 +480,7 @@ void btc_mesh_health_client_call_handler(btc_msg_t *msg) bt_mesh_role_param_t role_param = {0}; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -490,8 +491,8 @@ void btc_mesh_health_client_call_handler(btc_msg_t *msg) health_client_cb.params = arg->health_client_get_state.params; role_param.model = (struct bt_mesh_model *)health_client_cb.params->model; role_param.role = health_client_cb.params->msg_role; - if (bt_mesh_copy_msg_role(&role_param)) { - LOG_ERROR("%s: copy msg_role fail", __func__); + if (bt_mesh_set_model_role(&role_param)) { + LOG_ERROR("%s, Failed to set model role", __func__); return; } btc_ble_mesh_health_client_get_state(arg->health_client_get_state.params, @@ -507,8 +508,8 @@ void btc_mesh_health_client_call_handler(btc_msg_t *msg) health_client_cb.params = arg->health_client_set_state.params; role_param.model = (struct bt_mesh_model *)health_client_cb.params->model; role_param.role = health_client_cb.params->msg_role; - if (bt_mesh_copy_msg_role(&role_param)) { - LOG_ERROR("%s: copy msg_role fail", __func__); + if (bt_mesh_set_model_role(&role_param)) { + LOG_ERROR("%s, Failed to set model role", __func__); return; } btc_ble_mesh_health_client_set_state(arg->health_client_set_state.params, @@ -533,7 +534,7 @@ void btc_mesh_health_client_cb_handler(btc_msg_t *msg) esp_ble_mesh_health_client_cb_param_t *param = NULL; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -542,7 +543,7 @@ void btc_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 { - LOG_ERROR("%s, unknown msg->act = %d", __func__, msg->act); + LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act); } btc_ble_mesh_health_client_free_req_data(msg); @@ -554,7 +555,7 @@ void btc_mesh_health_server_call_handler(btc_msg_t *msg) btc_ble_mesh_health_server_args_t *arg = NULL; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -577,7 +578,7 @@ void btc_mesh_health_server_cb_handler(btc_msg_t *msg) esp_ble_mesh_health_server_cb_param_t *param = NULL; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -586,7 +587,7 @@ void btc_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 { - LOG_ERROR("%s, unknown msg->act = %d", __func__, msg->act); + LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act); } btc_ble_mesh_health_server_free_req_data(msg); diff --git a/components/bt/ble_mesh/btc/btc_ble_mesh_light_client.c b/components/bt/ble_mesh/btc/btc_ble_mesh_lighting_model.c similarity index 90% rename from components/bt/ble_mesh/btc/btc_ble_mesh_light_client.c rename to components/bt/ble_mesh/btc/btc_ble_mesh_lighting_model.c index b5c88d729e..39b4830316 100644 --- a/components/bt/ble_mesh/btc/btc_ble_mesh_light_client.c +++ b/components/bt/ble_mesh/btc/btc_ble_mesh_lighting_model.c @@ -18,8 +18,8 @@ #include "btc/btc_manage.h" #include "osi/allocator.h" -#include "light_client.h" -#include "btc_ble_mesh_light_client.h" +#include "lighting_client.h" +#include "btc_ble_mesh_lighting_model.h" #include "esp_ble_mesh_lighting_model_api.h" static inline void btc_ble_mesh_cb_to_app(esp_ble_mesh_light_client_cb_event_t event, @@ -37,7 +37,7 @@ void btc_ble_mesh_light_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void btc_ble_mesh_light_client_args_t *src = (btc_ble_mesh_light_client_args_t *)p_src; if (!msg || !dst || !src) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -51,7 +51,7 @@ void btc_ble_mesh_light_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void 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 { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } break; } @@ -64,12 +64,12 @@ void btc_ble_mesh_light_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void 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 { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } break; } default: - LOG_DEBUG("%s Unhandled deep copy %d", __func__, msg->act); + LOG_DEBUG("%s, Unknown deep copy act %d", __func__, msg->act); break; } } @@ -82,7 +82,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src u16_t length; if (!msg || !p_src_data || !p_dest_data) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -100,7 +100,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src 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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.lc_property_status.property_value, 0); @@ -119,7 +119,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src if (p_dest_data->params) { memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t)); } else { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } } break; @@ -134,7 +134,7 @@ static void btc_ble_mesh_free_req_data(btc_msg_t *msg) u32_t opcode; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -171,7 +171,7 @@ void btc_ble_mesh_light_client_arg_deep_free(btc_msg_t *msg) btc_ble_mesh_light_client_args_t *arg = NULL; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -221,12 +221,12 @@ void bt_mesh_callback_light_status_to_btc(u32_t opcode, u8_t evt_type, 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}; - size_t length; + esp_ble_mesh_client_common_param_t params = {0}; + size_t length; uint8_t act; if (!model || !ctx) { - LOG_ERROR("%s: invalid parameter", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -244,7 +244,7 @@ void bt_mesh_callback_light_status_to_btc(u32_t opcode, u8_t evt_type, act = ESP_BLE_MESH_LIGHT_CLIENT_TIMEOUT_EVT; break; default: - LOG_ERROR("%s: unknown light status event type", __func__); + LOG_ERROR("%s, Unknown lighting client event type", __func__); return; } @@ -272,7 +272,7 @@ void btc_mesh_light_client_publish_callback(u32_t opcode, struct bt_mesh_model * struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { if (!model || !ctx || !buf) { - LOG_ERROR("%s: invalid parameter", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -288,7 +288,7 @@ void btc_mesh_light_client_call_handler(btc_msg_t *msg) bt_mesh_role_param_t role_param = {0}; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -299,8 +299,8 @@ void btc_mesh_light_client_call_handler(btc_msg_t *msg) 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_copy_msg_role(&role_param)) { - LOG_ERROR("%s: copy msg_role fail", __func__); + if (bt_mesh_set_model_role(&role_param)) { + LOG_ERROR("%s, Failed to set model role", __func__); return; } common.opcode = params->opcode; @@ -328,8 +328,8 @@ void btc_mesh_light_client_call_handler(btc_msg_t *msg) 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_copy_msg_role(&role_param)) { - LOG_ERROR("%s: copy msg_role fail", __func__); + if (bt_mesh_set_model_role(&role_param)) { + LOG_ERROR("%s, Failed to set model role", __func__); return; } common.opcode = params->opcode; @@ -365,7 +365,7 @@ void btc_mesh_light_client_cb_handler(btc_msg_t *msg) esp_ble_mesh_light_client_cb_param_t *param = NULL; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -374,7 +374,7 @@ void btc_mesh_light_client_cb_handler(btc_msg_t *msg) if (msg->act < ESP_BLE_MESH_LIGHT_CLIENT_EVT_MAX) { btc_ble_mesh_cb_to_app(msg->act, param); } else { - LOG_ERROR("%s, unknown msg->act = %d", __func__, msg->act); + LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act); } btc_ble_mesh_free_req_data(msg); diff --git a/components/bt/ble_mesh/btc/btc_ble_mesh_prov.c b/components/bt/ble_mesh/btc/btc_ble_mesh_prov.c index b5db26ad08..9def1f83c7 100644 --- a/components/bt/ble_mesh/btc/btc_ble_mesh_prov.c +++ b/components/bt/ble_mesh/btc/btc_ble_mesh_prov.c @@ -22,44 +22,43 @@ #include "btc/btc_manage.h" #include "osi/allocator.h" -#include "btc_ble_mesh_prov.h" #include "sdkconfig.h" -#include "mesh.h" #include "mesh_util.h" #include "mesh_main.h" #include "mesh_access.h" +#include "mesh_proxy.h" +#include "cfg_cli.h" +#include "health_cli.h" + +#include "mesh.h" #include "access.h" #include "transport.h" #include "proxy.h" #include "prov.h" -#include "include/proxy.h" - -#include "cfg_cli.h" -#include "health_cli.h" -#include "generic_client.h" -#include "light_client.h" -#include "sensor_client.h" -#include "time_scene_client.h" #include "provisioner_prov.h" #include "provisioner_main.h" -#include "bt_mesh_client_common.h" -#include "btc_ble_mesh_config_client.h" -#include "btc_ble_mesh_health.h" -#include "btc_ble_mesh_generic_client.h" -#include "btc_ble_mesh_time_scene_client.h" -#include "btc_ble_mesh_sensor_client.h" -#include "btc_ble_mesh_light_client.h" +#include "generic_client.h" +#include "lighting_client.h" +#include "sensor_client.h" +#include "time_scene_client.h" +#include "model_common.h" + +#include "btc_ble_mesh_prov.h" +#include "btc_ble_mesh_config_model.h" +#include "btc_ble_mesh_health_model.h" +#include "btc_ble_mesh_generic_model.h" +#include "btc_ble_mesh_time_scene_model.h" +#include "btc_ble_mesh_sensor_model.h" +#include "btc_ble_mesh_lighting_model.h" #include "esp_ble_mesh_defs.h" #include "esp_ble_mesh_common_api.h" #include "esp_ble_mesh_provisioning_api.h" #include "esp_ble_mesh_networking_api.h" -#if CONFIG_BT_MESH - #define BLE_MESH_MAX_DATA_SIZE 379 void btc_ble_mesh_prov_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) @@ -68,7 +67,7 @@ void btc_ble_mesh_prov_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) btc_ble_mesh_model_args_t *src = (btc_ble_mesh_model_args_t *)p_src; if (!msg || !dst || !src) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -82,19 +81,18 @@ void btc_ble_mesh_prov_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) if (dst->model_send.data) { memcpy(dst->model_send.data, src->model_send.data, src->model_send.length); } else { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate 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 { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } - LOG_DEBUG("dst->model_send.data = %s", bt_hex(dst->model_send.data, src->model_send.length)); break; } default: - LOG_DEBUG("%s Unhandled deep copy %d", __func__, msg->act); + LOG_DEBUG("%s, Unknown deep copy act %d", __func__, msg->act); break; } } @@ -104,7 +102,7 @@ void btc_ble_mesh_prov_arg_deep_free(btc_msg_t *msg) btc_ble_mesh_model_args_t *arg = NULL; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -133,7 +131,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src esp_ble_mesh_model_cb_param_t *p_src_data = (esp_ble_mesh_model_cb_param_t *)p_src; if (!msg || !p_src_data || !p_dest_data) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -145,13 +143,13 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src 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 { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate 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 { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } } } @@ -164,13 +162,13 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src 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 { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate 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 { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } } } @@ -182,7 +180,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src 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 { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } } break; @@ -193,7 +191,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src 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 { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } } break; @@ -208,7 +206,7 @@ static void btc_ble_mesh_free_req_data(btc_msg_t *msg) esp_ble_mesh_model_cb_param_t *arg = NULL; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -274,10 +272,10 @@ 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) { + esp_ble_mesh_model_cb_param_t mesh_param = {0}; btc_msg_t msg = {0}; bt_status_t ret; - esp_ble_mesh_model_cb_param_t mesh_param = {0}; mesh_param.model_operation.opcode = mesh_opcode; mesh_param.model_operation.model = (esp_ble_mesh_model_t *)model; mesh_param.model_operation.ctx = (esp_ble_mesh_msg_ctx_t *)ctx; @@ -291,7 +289,7 @@ static void btc_ble_mesh_server_model_op_cb(struct bt_mesh_model *model, sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_copy_req_data); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); } return; } @@ -300,20 +298,24 @@ 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) { - btc_msg_t msg = {0}; - bt_status_t ret; esp_ble_mesh_model_cb_param_t mesh_param = {0}; - bt_mesh_client_common_t *client_op = NULL; + bt_mesh_client_common_t *client_param = NULL; bt_mesh_internal_data_t *data = NULL; bt_mesh_client_node_t *node = NULL; + btc_msg_t msg = {0}; + bt_status_t ret; if (!model || !model->user_data || !ctx || !buf) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } - client_op = (bt_mesh_client_common_t *)model->user_data; - data = (bt_mesh_internal_data_t *)client_op->internal_data; + client_param = (bt_mesh_client_common_t *)model->user_data; + data = (bt_mesh_internal_data_t *)client_param->internal_data; + if (!data) { + LOG_ERROR("%s, Client internal_data is NULL", __func__); + return; + } node = bt_mesh_is_model_message_publish(model, ctx, buf, false); if (node == NULL) { @@ -342,21 +344,22 @@ static void btc_ble_mesh_client_model_op_cb(struct bt_mesh_model *model, sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_copy_req_data); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s, btc_transfer_context failed", __func__); } 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) { + esp_ble_mesh_model_cb_param_t mesh_param = {0}; btc_msg_t msg = {0}; bt_status_t ret; - esp_ble_mesh_model_cb_param_t mesh_param = {0}; mesh_param.model_send_comp.err_code = err; mesh_param.model_send_comp.opcode = opcode; mesh_param.model_send_comp.model = model; mesh_param.model_send_comp.ctx = ctx; + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_MODEL; msg.act = ESP_BLE_MESH_MODEL_SEND_COMP_EVT; @@ -364,19 +367,20 @@ static void btc_ble_mesh_model_send_comp_cb(esp_ble_mesh_model_t *model, esp_ble sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_copy_req_data); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); } return; } static void btc_ble_mesh_model_publish_comp_cb(esp_ble_mesh_model_t *model, int err) { + esp_ble_mesh_model_cb_param_t mesh_param = {0}; btc_msg_t msg = {0}; bt_status_t ret; - esp_ble_mesh_model_cb_param_t mesh_param = {0}; mesh_param.model_publish_comp.err_code = err; mesh_param.model_publish_comp.model = model; + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_MODEL; msg.act = ESP_BLE_MESH_MODEL_PUBLISH_COMP_EVT; @@ -384,12 +388,12 @@ static void btc_ble_mesh_model_publish_comp_cb(esp_ble_mesh_model_t *model, int sizeof(esp_ble_mesh_model_cb_param_t), NULL); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); } return; } -#if defined(CONFIG_BT_MESH_NODE) +#if defined(CONFIG_BLE_MESH_NODE) static void btc_oob_pub_key_cb(void) { btc_msg_t msg = {0}; @@ -401,18 +405,19 @@ static void btc_oob_pub_key_cb(void) msg.act = ESP_BLE_MESH_NODE_PROV_OOB_PUB_KEY_EVT; if (btc_transfer_context(&msg, NULL, 0, NULL) != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); } - return; } static int btc_output_number_cb(bt_mesh_output_action_t act, u32_t num) { - LOG_DEBUG("%s", __func__); + esp_ble_mesh_prov_cb_param_t mesh_param = {0}; btc_msg_t msg = {0}; bt_status_t ret; - esp_ble_mesh_prov_cb_param_t mesh_param = {0}; + + LOG_DEBUG("%s", __func__); + mesh_param.node_prov_output_num.action = (esp_ble_mesh_output_action_t)act; mesh_param.node_prov_output_num.number = num; @@ -423,19 +428,20 @@ static int btc_output_number_cb(bt_mesh_output_action_t act, u32_t num) sizeof(esp_ble_mesh_prov_cb_param_t), NULL); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); return -1; } - return 0; } static int btc_output_string_cb(const char *str) { - LOG_DEBUG("%s", __func__); + esp_ble_mesh_prov_cb_param_t mesh_param = {0}; btc_msg_t msg = {0}; bt_status_t ret; - esp_ble_mesh_prov_cb_param_t mesh_param = {0}; + + LOG_DEBUG("%s", __func__); + strncpy(mesh_param.node_prov_output_str.string, str, strlen(str)); msg.sig = BTC_SIG_API_CB; @@ -445,19 +451,20 @@ static int btc_output_string_cb(const char *str) sizeof(esp_ble_mesh_prov_cb_param_t), NULL); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); return -1; } - return 0; } static int btc_input_cb(bt_mesh_input_action_t act, u8_t size) { - LOG_DEBUG("%s", __func__); + esp_ble_mesh_prov_cb_param_t mesh_param = {0}; btc_msg_t msg = {0}; bt_status_t ret; - esp_ble_mesh_prov_cb_param_t mesh_param = {0}; + + LOG_DEBUG("%s", __func__); + mesh_param.node_prov_input.action = (esp_ble_mesh_input_action_t)act; mesh_param.node_prov_input.size = size; @@ -468,19 +475,20 @@ static int btc_input_cb(bt_mesh_input_action_t act, u8_t size) sizeof(esp_ble_mesh_prov_cb_param_t), NULL); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); return -1; } - return 0; } static void btc_link_open_cb(bt_mesh_prov_bearer_t bearer) { - LOG_DEBUG("%s", __func__); + esp_ble_mesh_prov_cb_param_t mesh_param = {0}; btc_msg_t msg = {0}; bt_status_t ret; - esp_ble_mesh_prov_cb_param_t mesh_param = {0}; + + LOG_DEBUG("%s", __func__); + mesh_param.node_prov_link_open.bearer = (esp_ble_mesh_prov_bearer_t)bearer; msg.sig = BTC_SIG_API_CB; @@ -490,18 +498,19 @@ static void btc_link_open_cb(bt_mesh_prov_bearer_t bearer) sizeof(esp_ble_mesh_prov_cb_param_t), NULL); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); } - return; } static void btc_link_close_cb(bt_mesh_prov_bearer_t bearer) { - LOG_DEBUG("%s", __func__); + esp_ble_mesh_prov_cb_param_t mesh_param = {0}; btc_msg_t msg = {0}; bt_status_t ret; - esp_ble_mesh_prov_cb_param_t mesh_param = {0}; + + LOG_DEBUG("%s", __func__); + mesh_param.node_prov_link_close.bearer = (esp_ble_mesh_prov_bearer_t)bearer; msg.sig = BTC_SIG_API_CB; @@ -511,23 +520,24 @@ static void btc_link_close_cb(bt_mesh_prov_bearer_t bearer) sizeof(esp_ble_mesh_prov_cb_param_t), NULL); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); } - return; } static void btc_complete_cb(u16_t net_idx, u16_t addr, u8_t flags, u32_t iv_index) { - LOG_DEBUG("%s", __func__); + esp_ble_mesh_prov_cb_param_t mesh_param = {0}; btc_msg_t msg = {0}; bt_status_t ret; - esp_ble_mesh_prov_cb_param_t mesh_param = {0}; + LOG_DEBUG("%s", __func__); + mesh_param.node_prov_complete.net_idx = net_idx; mesh_param.node_prov_complete.addr = addr; mesh_param.node_prov_complete.flags = flags; mesh_param.node_prov_complete.iv_index = iv_index; + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_PROV; msg.act = ESP_BLE_MESH_NODE_PROV_COMPLETE_EVT; @@ -535,9 +545,8 @@ static void btc_complete_cb(u16_t net_idx, u16_t addr, u8_t flags, u32_t iv_inde sizeof(esp_ble_mesh_prov_cb_param_t), NULL); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); } - return; } @@ -554,21 +563,22 @@ static void btc_reset_cb(void) ret = btc_transfer_context(&msg, NULL, 0, NULL); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); } - return; } -#endif /* defined(CONFIG_BT_MESH_NODE) */ +#endif /* defined(CONFIG_BLE_MESH_NODE) */ static void btc_prov_register_complete_cb(int err_code) { - LOG_DEBUG("%s", __func__); + esp_ble_mesh_prov_cb_param_t mesh_param = {0}; btc_msg_t msg = {0}; bt_status_t ret; - esp_ble_mesh_prov_cb_param_t mesh_param = {0}; + LOG_DEBUG("%s", __func__); + mesh_param.prov_register_comp.err_code = err_code; + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_PROV; msg.act = ESP_BLE_MESH_PROV_REGISTER_COMP_EVT; @@ -576,28 +586,37 @@ static void btc_prov_register_complete_cb(int err_code) sizeof(esp_ble_mesh_prov_cb_param_t), NULL); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); } - return; } static void btc_client_model_timeout_cb(struct k_work *work) { - bt_mesh_client_node_t *node = CONTAINER_OF(work, - bt_mesh_client_node_t, - timer.work); - __ASSERT(node, "unknown mesh client node."); + esp_ble_mesh_model_cb_param_t mesh_param = {0}; + bt_mesh_client_common_t *client_param = NULL; + bt_mesh_internal_data_t *data = NULL; + bt_mesh_client_node_t *node = NULL; btc_msg_t msg = {0}; bt_status_t ret; - bt_mesh_internal_data_t *data = NULL; - bt_mesh_client_common_t *client_op = node->ctx.model->user_data; - data = (bt_mesh_internal_data_t *)client_op->internal_data; - __ASSERT(client_op && data, "Invalid client user data or internal data."); - esp_ble_mesh_model_cb_param_t mesh_param = {0}; + + node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work); + if (!node || !node->ctx.model || !node->ctx.model->user_data) { + LOG_ERROR("%s, Invalid parameter", __func__); + return; + } + + client_param = (bt_mesh_client_common_t *)node->ctx.model->user_data; + data = (bt_mesh_internal_data_t *)client_param->internal_data; + if (!data) { + LOG_ERROR("%s, Client internal_data is NULL", __func__); + return; + } + mesh_param.client_send_timeout.opcode = node->opcode; mesh_param.client_send_timeout.model = (esp_ble_mesh_model_t *)node->ctx.model; - mesh_param.client_send_timeout.ctx = (esp_ble_mesh_msg_ctx_t *)&node->ctx; + mesh_param.client_send_timeout.ctx = (esp_ble_mesh_msg_ctx_t *)&node->ctx; + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_MODEL; msg.act = ESP_BLE_MESH_CLIENT_MODEL_SEND_TIMEOUT_EVT; @@ -605,7 +624,7 @@ static void btc_client_model_timeout_cb(struct k_work *work) sizeof(esp_ble_mesh_model_cb_param_t), btc_ble_mesh_copy_req_data); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); } // Don't forget to release the node at the end. bt_mesh_client_free_node(&data->queue, node); @@ -614,12 +633,14 @@ static void btc_client_model_timeout_cb(struct k_work *work) static int btc_model_publish_update(struct bt_mesh_model *mod) { - LOG_DEBUG("%s", __func__); + esp_ble_mesh_model_cb_param_t mesh_param = {0}; btc_msg_t msg = {0}; bt_status_t ret; - esp_ble_mesh_model_cb_param_t mesh_param = {0}; + LOG_DEBUG("%s", __func__); + mesh_param.model_publish_update.model = (esp_ble_mesh_model_t *)mod; + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_MODEL; msg.act = ESP_BLE_MESH_MODEL_PUBLISH_UPDATE_EVT; @@ -627,19 +648,19 @@ static int btc_model_publish_update(struct bt_mesh_model *mod) sizeof(esp_ble_mesh_model_cb_param_t), NULL); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); return -1; } - return 0; } static void btc_prov_set_complete_cb(esp_ble_mesh_prov_cb_param_t *param, uint8_t act) { - LOG_DEBUG("%s", __func__); btc_msg_t msg = {0}; bt_status_t ret; + LOG_DEBUG("%s", __func__); + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_PROV; msg.act = act; @@ -647,13 +668,12 @@ static void btc_prov_set_complete_cb(esp_ble_mesh_prov_cb_param_t *param, uint8_ sizeof(esp_ble_mesh_prov_cb_param_t), NULL); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); } - return; } -#if (CONFIG_BT_MESH_PROVISIONER) +#if (CONFIG_BLE_MESH_PROVISIONER) static void btc_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) @@ -678,9 +698,8 @@ static void btc_provisioner_recv_unprov_adv_pkt_cb(const u8_t addr[6], const u8_ sizeof(esp_ble_mesh_prov_cb_param_t), NULL); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); } - return; } @@ -701,10 +720,9 @@ static int btc_provisioner_prov_read_oob_pub_key_cb(u8_t link_idx) sizeof(esp_ble_mesh_prov_cb_param_t), NULL); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); return -1; } - return 0; } @@ -728,10 +746,9 @@ static int btc_provisioner_prov_input_cb(u8_t method, bt_mesh_output_action_t ac sizeof(esp_ble_mesh_prov_cb_param_t), NULL); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); return -1; } - return 0; } @@ -747,7 +764,7 @@ static int btc_provisioner_prov_output_cb(u8_t method, bt_mesh_input_action_t ac mesh_param.provisioner_prov_output.action = (esp_ble_mesh_input_action_t)act; mesh_param.provisioner_prov_output.size = size; mesh_param.provisioner_prov_output.link_idx = link_idx; - if (act == BT_MESH_ENTER_STRING) { + if (act == BLE_MESH_ENTER_STRING) { strncpy(mesh_param.provisioner_prov_output.string, (char *)data, size); } else { mesh_param.provisioner_prov_output.number = sys_get_le32((u8_t *)data); @@ -760,10 +777,9 @@ static int btc_provisioner_prov_output_cb(u8_t method, bt_mesh_input_action_t ac sizeof(esp_ble_mesh_prov_cb_param_t), NULL); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); return -1; } - return 0; } @@ -784,9 +800,8 @@ static void btc_provisioner_link_open_cb(bt_mesh_prov_bearer_t bearer) sizeof(esp_ble_mesh_prov_cb_param_t), NULL); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); } - return; } @@ -808,9 +823,8 @@ static void btc_provisioner_link_close_cb(bt_mesh_prov_bearer_t bearer, u8_t rea sizeof(esp_ble_mesh_prov_cb_param_t), NULL); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); } - return; } @@ -818,16 +832,18 @@ static void btc_provisioner_prov_complete_cb(int node_idx, const u8_t device_uui u16_t unicast_addr, u8_t element_num, u16_t netkey_idx) { - LOG_DEBUG("%s", __func__); + esp_ble_mesh_prov_cb_param_t mesh_param = {0}; btc_msg_t msg = {0}; bt_status_t ret; - esp_ble_mesh_prov_cb_param_t mesh_param = {0}; + LOG_DEBUG("%s", __func__); + mesh_param.provisioner_prov_complete.node_idx = node_idx; mesh_param.provisioner_prov_complete.unicast_addr = unicast_addr; mesh_param.provisioner_prov_complete.element_num = element_num; mesh_param.provisioner_prov_complete.netkey_idx = netkey_idx; memcpy(mesh_param.provisioner_prov_complete.device_uuid, device_uuid, sizeof(esp_ble_mesh_octet16_t)); + msg.sig = BTC_SIG_API_CB; msg.pid = BTC_PID_PROV; msg.act = ESP_BLE_MESH_PROVISIONER_PROV_COMPLETE_EVT; @@ -835,16 +851,15 @@ static void btc_provisioner_prov_complete_cb(int node_idx, const u8_t device_uui sizeof(esp_ble_mesh_prov_cb_param_t), NULL); if (ret != BT_STATUS_SUCCESS) { - LOG_ERROR("%s btc_transfer_context failed\n", __func__); + LOG_ERROR("%s btc_transfer_context failed", __func__); } - return; } -#endif /* CONFIG_BT_MESH_PROVISIONER */ +#endif /* CONFIG_BLE_MESH_PROVISIONER */ int btc_ble_mesh_client_init(esp_ble_mesh_model_t *model) { - __ASSERT(model && model->op, "The client model or operation is invalid(NULL)."); + __ASSERT(model && model->op, "%s, Invalid parameter", __func__); 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_client_model_op_cb; @@ -884,8 +899,7 @@ esp_ble_mesh_model_t *btc_ble_mesh_model_find_vnd(esp_ble_mesh_elem_t *elem, return (esp_ble_mesh_model_t *)bt_mesh_model_find_vnd((struct bt_mesh_elem *)elem, company, id); } -esp_ble_mesh_model_t *btc_ble_mesh_model_find(esp_ble_mesh_elem_t *elem, - u16_t id) +esp_ble_mesh_model_t *btc_ble_mesh_model_find(esp_ble_mesh_elem_t *elem, u16_t id) { return (esp_ble_mesh_model_t *)bt_mesh_model_find((struct bt_mesh_elem *)elem, id); } @@ -895,11 +909,13 @@ const esp_ble_mesh_comp_t *btc_ble_mesh_comp_get(void) return (const esp_ble_mesh_comp_t *)bt_mesh_comp_get(); } +/* 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[]; +/* 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[]; -// For Generic Client +/* 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[]; @@ -908,15 +924,15 @@ 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[]; -// For Light Lightness CLient +/* 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[]; -// For Sensor Client +/* Sensor Client Models */ extern const struct bt_mesh_model_op sensor_cli_op[]; -// For Time Scene Client +/* 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[]; @@ -924,23 +940,25 @@ extern const struct bt_mesh_model_op scheduler_cli_op[]; static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model) { esp_ble_mesh_model_op_t *op = NULL; - esp_ble_mesh_model_pub_t *pub = NULL; if (!model) { + LOG_ERROR("%s, Invalid parameter", __func__); return; } - /* The vendor model opcode is 3 bytes. */ + /* 1. For SIG client models, model->op will be NULL and initialized here. + * 2. The vendor model opcode is 3 bytes. + */ if ((model->op != NULL) && (model->op->opcode >= 0x10000)) { goto add_model_op; } switch (model->model_id) { - case BT_MESH_MODEL_ID_CFG_SRV: { + case BLE_MESH_MODEL_ID_CFG_SRV: { model->op = (esp_ble_mesh_model_op_t *)bt_mesh_cfg_srv_op; break; } - case BT_MESH_MODEL_ID_CFG_CLI: { + case BLE_MESH_MODEL_ID_CFG_CLI: { model->op = (esp_ble_mesh_model_op_t *)bt_mesh_cfg_cli_op; bt_mesh_config_client_t *cli = (bt_mesh_config_client_t *)model->user_data; if (cli != NULL) { @@ -948,11 +966,11 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model) } break; } - case BT_MESH_MODEL_ID_HEALTH_SRV: { + case BLE_MESH_MODEL_ID_HEALTH_SRV: { model->op = (esp_ble_mesh_model_op_t *)bt_mesh_health_srv_op; break; } - case BT_MESH_MODEL_ID_HEALTH_CLI: { + case BLE_MESH_MODEL_ID_HEALTH_CLI: { model->op = (esp_ble_mesh_model_op_t *)bt_mesh_health_cli_op; bt_mesh_health_client_t *cli = (bt_mesh_health_client_t *)model->user_data; if (cli != NULL) { @@ -960,7 +978,7 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model) } break; } - case BT_MESH_MODEL_ID_GEN_ONOFF_CLI: { + case BLE_MESH_MODEL_ID_GEN_ONOFF_CLI: { model->op = ((esp_ble_mesh_model_op_t *)gen_onoff_cli_op); bt_mesh_gen_onoff_cli_t *cli = (bt_mesh_gen_onoff_cli_t *)model->user_data; if (cli != NULL) { @@ -968,7 +986,7 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model) } break; } - case BT_MESH_MODEL_ID_GEN_LEVEL_CLI: { + case BLE_MESH_MODEL_ID_GEN_LEVEL_CLI: { model->op = ((esp_ble_mesh_model_op_t *)gen_level_cli_op); bt_mesh_gen_level_cli_t *cli = (bt_mesh_gen_level_cli_t *)model->user_data; if (cli != NULL) { @@ -976,7 +994,7 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model) } break; } - case BT_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI: { + case BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI: { model->op = ((esp_ble_mesh_model_op_t *)gen_def_trans_time_cli_op); bt_mesh_gen_def_trans_time_cli_t *cli = (bt_mesh_gen_def_trans_time_cli_t *)model->user_data; if (cli != NULL) { @@ -984,7 +1002,7 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model) } break; } - case BT_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI: { + case BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI: { model->op = ((esp_ble_mesh_model_op_t *)gen_power_onoff_cli_op); bt_mesh_gen_power_onoff_cli_t *cli = (bt_mesh_gen_power_onoff_cli_t *)model->user_data; if (cli != NULL) { @@ -992,7 +1010,7 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model) } break; } - case BT_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI: { + case BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI: { model->op = ((esp_ble_mesh_model_op_t *)gen_power_level_cli_op); bt_mesh_gen_power_level_cli_t *cli = (bt_mesh_gen_power_level_cli_t *)model->user_data; if (cli != NULL) { @@ -1000,7 +1018,7 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model) } break; } - case BT_MESH_MODEL_ID_GEN_BATTERY_CLI: { + case BLE_MESH_MODEL_ID_GEN_BATTERY_CLI: { model->op = ((esp_ble_mesh_model_op_t *)gen_battery_cli_op); bt_mesh_gen_battery_cli_t *cli = (bt_mesh_gen_battery_cli_t *)model->user_data; if (cli != NULL) { @@ -1008,7 +1026,7 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model) } break; } - case BT_MESH_MODEL_ID_GEN_LOCATION_CLI: { + case BLE_MESH_MODEL_ID_GEN_LOCATION_CLI: { model->op = ((esp_ble_mesh_model_op_t *)gen_location_cli_op); bt_mesh_gen_location_cli_t *cli = (bt_mesh_gen_location_cli_t *)model->user_data; if (cli != NULL) { @@ -1016,7 +1034,7 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model) } break; } - case BT_MESH_MODEL_ID_GEN_PROP_CLI: { + case BLE_MESH_MODEL_ID_GEN_PROP_CLI: { model->op = ((esp_ble_mesh_model_op_t *)gen_property_cli_op); bt_mesh_gen_property_cli_t *cli = (bt_mesh_gen_property_cli_t *)model->user_data; if (cli != NULL) { @@ -1024,7 +1042,7 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model) } break; } - case BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI: { + case BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI: { model->op = ((esp_ble_mesh_model_op_t *)light_lightness_cli_op); bt_mesh_light_lightness_cli_t *cli = (bt_mesh_light_lightness_cli_t *)model->user_data; if (cli != NULL) { @@ -1032,7 +1050,7 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model) } break; } - case BT_MESH_MODEL_ID_LIGHT_CTL_CLI: { + case BLE_MESH_MODEL_ID_LIGHT_CTL_CLI: { model->op = ((esp_ble_mesh_model_op_t *)light_ctl_cli_op); bt_mesh_light_ctl_cli_t *cli = (bt_mesh_light_ctl_cli_t *)model->user_data; if (cli != NULL) { @@ -1040,7 +1058,7 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model) } break; } - case BT_MESH_MODEL_ID_LIGHT_HSL_CLI: { + case BLE_MESH_MODEL_ID_LIGHT_HSL_CLI: { model->op = ((esp_ble_mesh_model_op_t *)light_hsl_cli_op); bt_mesh_light_hsl_cli_t *cli = (bt_mesh_light_hsl_cli_t *)model->user_data; if (cli != NULL) { @@ -1048,7 +1066,7 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model) } break; } - case BT_MESH_MODEL_ID_LIGHT_XYL_CLI: { + case BLE_MESH_MODEL_ID_LIGHT_XYL_CLI: { model->op = ((esp_ble_mesh_model_op_t *)light_xyl_cli_op); bt_mesh_light_xyl_cli_t *cli = (bt_mesh_light_xyl_cli_t *)model->user_data; if (cli != NULL) { @@ -1056,7 +1074,7 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model) } break; } - case BT_MESH_MODEL_ID_LIGHT_LC_CLI: { + case BLE_MESH_MODEL_ID_LIGHT_LC_CLI: { model->op = ((esp_ble_mesh_model_op_t *)light_lc_cli_op); bt_mesh_light_lc_cli_t *cli = (bt_mesh_light_lc_cli_t *)model->user_data; if (cli != NULL) { @@ -1064,7 +1082,7 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model) } break; } - case BT_MESH_MODEL_ID_SENSOR_CLI: { + case BLE_MESH_MODEL_ID_SENSOR_CLI: { model->op = ((esp_ble_mesh_model_op_t *)sensor_cli_op); bt_mesh_sensor_client_t *cli = (bt_mesh_sensor_client_t *)model->user_data; if (cli != NULL) { @@ -1072,7 +1090,7 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model) } break; } - case BT_MESH_MODEL_ID_TIME_CLI: { + case BLE_MESH_MODEL_ID_TIME_CLI: { model->op = ((esp_ble_mesh_model_op_t *)time_cli_op); bt_mesh_time_scene_client_t *cli = (bt_mesh_time_scene_client_t *)model->user_data; if (cli != NULL) { @@ -1080,7 +1098,7 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model) } break; } - case BT_MESH_MODEL_ID_SCENE_CLI: { + case BLE_MESH_MODEL_ID_SCENE_CLI: { model->op = ((esp_ble_mesh_model_op_t *)scene_cli_op); bt_mesh_time_scene_client_t *cli = (bt_mesh_time_scene_client_t *)model->user_data; if (cli != NULL) { @@ -1088,7 +1106,7 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model) } break; } - case BT_MESH_MODEL_ID_SCHEDULER_CLI: { + case BLE_MESH_MODEL_ID_SCHEDULER_CLI: { model->op = ((esp_ble_mesh_model_op_t *)scheduler_cli_op); bt_mesh_time_scene_client_t *cli = (bt_mesh_time_scene_client_t *)model->user_data; if (cli != NULL) { @@ -1099,107 +1117,97 @@ static void btc_mesh_model_op_add(esp_ble_mesh_model_t *model) default: { goto add_model_op; } - } - return; add_model_op: - op = model->op; - pub = model->pub; - if (pub != NULL) { - pub->update = (esp_ble_mesh_cb_t)btc_model_publish_update; + if (model->pub) { + model->pub->update = (esp_ble_mesh_cb_t)btc_model_publish_update; } + op = model->op; while (op != NULL && op->opcode != 0) { - // if (op->min_len > BLE_MESH_MAX_DATA_SIZE || op->param_cb != 0) { - // --op; - // LOG_ERROR("%s, Invalid model operation min_len = %d, or param callbak = 0x%x, the last valid opcode = 0x%x", - // __func__, op->min_len, op->param_cb, op->opcode); - // return; - // } op->param_cb = (esp_ble_mesh_cb_t)btc_ble_mesh_server_model_op_cb; op++; } - return; - } void btc_mesh_prov_call_handler(btc_msg_t *msg) { - btc_ble_mesh_prov_args_t *arg = NULL; esp_ble_mesh_prov_cb_param_t param = {0}; + btc_ble_mesh_prov_args_t *arg = NULL; uint8_t act; if (!msg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } arg = (btc_ble_mesh_prov_args_t *)(msg->arg); switch (msg->act) { - case BTC_BLE_MESH_ACT_APP_REGISTER: { + case BTC_BLE_MESH_ACT_MESH_INIT: { int err_code; - for (int i = 0; i < arg->mesh_reg.comp->element_count; i++) { - esp_ble_mesh_elem_t *elem = &arg->mesh_reg.comp->elements[i]; + 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 *models = &elem->sig_models[j]; + esp_ble_mesh_model_t *sig_model = &elem->sig_models[j]; /* The opcode of sig model should be 1 or 2 bytes. */ - if ((models != NULL) && (models->op != NULL) && (models->op->opcode >= 0x10000)) { + if (sig_model && sig_model->op && (sig_model->op->opcode >= 0x10000)) { err_code = -EINVAL; btc_prov_register_complete_cb(err_code); return; } - btc_mesh_model_op_add(models); + btc_mesh_model_op_add(sig_model); } - + /* For vendor models */ for (int k = 0; k < elem->vnd_model_count; k++) { - esp_ble_mesh_model_t *vnd_models = &elem->vnd_models[k]; + esp_ble_mesh_model_t *vnd_model = &elem->vnd_models[k]; /* The opcode of vendor model should be 3 bytes. */ - if (vnd_models->op->opcode < 0x10000) { + if (vnd_model && vnd_model->op && vnd_model->op->opcode < 0x10000) { err_code = -EINVAL; btc_prov_register_complete_cb(err_code); return; } - btc_mesh_model_op_add(vnd_models); + btc_mesh_model_op_add(vnd_model); } } -#if CONFIG_BT_MESH_NODE - arg->mesh_reg.prov->oob_pub_key_cb = (esp_ble_mesh_cb_t)btc_oob_pub_key_cb; - arg->mesh_reg.prov->output_num_cb = (esp_ble_mesh_cb_t)btc_output_number_cb; - arg->mesh_reg.prov->output_str_cb = (esp_ble_mesh_cb_t)btc_output_string_cb; - arg->mesh_reg.prov->input_cb = (esp_ble_mesh_cb_t)btc_input_cb; - arg->mesh_reg.prov->link_open_cb = (esp_ble_mesh_cb_t)btc_link_open_cb; - arg->mesh_reg.prov->link_close_cb = (esp_ble_mesh_cb_t)btc_link_close_cb; - arg->mesh_reg.prov->complete_cb = (esp_ble_mesh_cb_t)btc_complete_cb; - arg->mesh_reg.prov->reset_cb = (esp_ble_mesh_cb_t)btc_reset_cb; -#endif /* CONFIG_BT_MESH_NODE */ -#if (CONFIG_BT_MESH_PROVISIONER) - arg->mesh_reg.prov->provisioner_prov_read_oob_pub_key = (esp_ble_mesh_cb_t)btc_provisioner_prov_read_oob_pub_key_cb; - arg->mesh_reg.prov->provisioner_prov_input = (esp_ble_mesh_cb_t)btc_provisioner_prov_input_cb; - arg->mesh_reg.prov->provisioner_prov_output = (esp_ble_mesh_cb_t)btc_provisioner_prov_output_cb; - arg->mesh_reg.prov->provisioner_link_open = (esp_ble_mesh_cb_t)btc_provisioner_link_open_cb; - arg->mesh_reg.prov->provisioner_link_close = (esp_ble_mesh_cb_t)btc_provisioner_link_close_cb; - arg->mesh_reg.prov->provisioner_prov_comp = (esp_ble_mesh_cb_t)btc_provisioner_prov_complete_cb; +#if CONFIG_BLE_MESH_NODE + arg->mesh_init.prov->oob_pub_key_cb = (esp_ble_mesh_cb_t)btc_oob_pub_key_cb; + arg->mesh_init.prov->output_num_cb = (esp_ble_mesh_cb_t)btc_output_number_cb; + arg->mesh_init.prov->output_str_cb = (esp_ble_mesh_cb_t)btc_output_string_cb; + arg->mesh_init.prov->input_cb = (esp_ble_mesh_cb_t)btc_input_cb; + arg->mesh_init.prov->link_open_cb = (esp_ble_mesh_cb_t)btc_link_open_cb; + arg->mesh_init.prov->link_close_cb = (esp_ble_mesh_cb_t)btc_link_close_cb; + arg->mesh_init.prov->complete_cb = (esp_ble_mesh_cb_t)btc_complete_cb; + arg->mesh_init.prov->reset_cb = (esp_ble_mesh_cb_t)btc_reset_cb; +#endif /* CONFIG_BLE_MESH_NODE */ +#if (CONFIG_BLE_MESH_PROVISIONER) + arg->mesh_init.prov->provisioner_prov_read_oob_pub_key = (esp_ble_mesh_cb_t)btc_provisioner_prov_read_oob_pub_key_cb; + arg->mesh_init.prov->provisioner_prov_input = (esp_ble_mesh_cb_t)btc_provisioner_prov_input_cb; + arg->mesh_init.prov->provisioner_prov_output = (esp_ble_mesh_cb_t)btc_provisioner_prov_output_cb; + arg->mesh_init.prov->provisioner_link_open = (esp_ble_mesh_cb_t)btc_provisioner_link_open_cb; + arg->mesh_init.prov->provisioner_link_close = (esp_ble_mesh_cb_t)btc_provisioner_link_close_cb; + arg->mesh_init.prov->provisioner_prov_comp = (esp_ble_mesh_cb_t)btc_provisioner_prov_complete_cb; bt_mesh_prov_adv_pkt_cb_register(btc_provisioner_recv_unprov_adv_pkt_cb); -#endif /* CONFIG_BT_MESH_PROVISIONER */ - err_code = bt_mesh_init((struct bt_mesh_prov *)arg->mesh_reg.prov, - (struct bt_mesh_comp *)arg->mesh_reg.comp); - // Don't forget to give the semaphore when ble mesh init finish. - xSemaphoreGive(arg->mesh_reg.semaphore); +#endif /* CONFIG_BLE_MESH_PROVISIONER */ + err_code = bt_mesh_init((struct bt_mesh_prov *)arg->mesh_init.prov, + (struct bt_mesh_comp *)arg->mesh_init.comp); + /* Give the semaphore when BLE Mesh initialization is finished. */ + xSemaphoreGive(arg->mesh_init.semaphore); btc_prov_register_complete_cb(err_code); return; } -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE case BTC_BLE_MESH_ACT_PROV_ENABLE: - LOG_DEBUG("%s, BTC_BLE_MESH_ACT_PROV_ENABLE, bearers = %d", __func__, arg->mesh_prov_enable.bearers); + LOG_DEBUG("%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->mesh_prov_enable.bearers); + param.node_prov_enable_comp.err_code = bt_mesh_prov_enable(arg->node_prov_enable.bearers); break; case BTC_BLE_MESH_ACT_PROV_DISABLE: - LOG_DEBUG("%s, BTC_BLE_MESH_ACT_PROV_DISABLE, bearers = %d", __func__, arg->mesh_prov_disable.bearers); + LOG_DEBUG("%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->mesh_prov_disable.bearers); + param.node_prov_disable_comp.err_code = bt_mesh_prov_disable(arg->node_prov_disable.bearers); break; case BTC_BLE_MESH_ACT_NODE_RESET: LOG_DEBUG("%s, BTC_BLE_MESH_ACT_NODE_RESET", __func__); @@ -1214,16 +1222,17 @@ void btc_mesh_prov_call_handler(btc_msg_t *msg) break; case BTC_BLE_MESH_ACT_INPUT_NUMBER: act = ESP_BLE_MESH_NODE_PROV_INPUT_NUMBER_COMP_EVT; - param.node_prov_input_num_comp.err_code = bt_mesh_input_number(arg->input_num.number); + param.node_prov_input_num_comp.err_code = bt_mesh_input_number(arg->input_number.number); break; case BTC_BLE_MESH_ACT_INPUT_STRING: act = ESP_BLE_MESH_NODE_PROV_INPUT_STRING_COMP_EVT; - param.node_prov_input_str_comp.err_code = bt_mesh_input_string(arg->input_str.string); + param.node_prov_input_str_comp.err_code = bt_mesh_input_string(arg->input_string.string); break; case BTC_BLE_MESH_ACT_SET_DEVICE_NAME: act = ESP_BLE_MESH_NODE_SET_UNPROV_DEV_NAME_COMP_EVT; param.node_set_unprov_dev_name_comp.err_code = bt_mesh_set_device_name(arg->set_device_name.name); break; +#if defined(CONFIG_BLE_MESH_GATT_PROXY) case BTC_BLE_MESH_ACT_PROXY_IDENTITY_ENABLE: act = ESP_BLE_MESH_NODE_PROXY_IDENTITY_ENABLE_COMP_EVT; param.node_proxy_identity_enable_comp.err_code = bt_mesh_proxy_identity_enable(); @@ -1236,8 +1245,9 @@ void btc_mesh_prov_call_handler(btc_msg_t *msg) act = ESP_BLE_MESH_NODE_PROXY_GATT_DISABLE_COMP_EVT; param.node_proxy_gatt_disable_comp.err_code = bt_mesh_proxy_gatt_disable(); break; -#endif /* CONFIG_BT_MESH_NODE */ -#if (CONFIG_BT_MESH_PROVISIONER) +#endif /* CONFIG_BLE_MESH_GATT_PROXY */ +#endif /* CONFIG_BLE_MESH_NODE */ +#if (CONFIG_BLE_MESH_PROVISIONER) case BTC_BLE_MESH_ACT_PROVISIONER_READ_OOB_PUB_KEY: act = ESP_BLE_MESH_PROVISIONER_PROV_READ_OOB_PUB_KEY_COMP_EVT; param.provisioner_prov_read_oob_pub_key_comp.err_code = @@ -1365,8 +1375,8 @@ void btc_mesh_prov_call_handler(btc_msg_t *msg) } break; } -#endif /* CONFIG_BT_MESH_PROVISIONER */ -#if (CONFIG_BT_MESH_FAST_PROV) +#endif /* CONFIG_BLE_MESH_PROVISIONER */ +#if (CONFIG_BLE_MESH_FAST_PROV) case BTC_BLE_MESH_ACT_SET_FAST_PROV_INFO: act = ESP_BLE_MESH_SET_FAST_PROV_INFO_COMP_EVT; param.set_fast_prov_info_comp.status_unicast = @@ -1386,7 +1396,7 @@ void btc_mesh_prov_call_handler(btc_msg_t *msg) param.set_fast_prov_action_comp.status_action = bt_mesh_set_fast_prov_action(arg->set_fast_prov_action.action); break; -#endif /* (CONFIG_BT_MESH_FAST_PROV) */ +#endif /* (CONFIG_BLE_MESH_FAST_PROV) */ default: LOG_WARN("%s, Invalid msg->act %d", __func__, msg->act); return; @@ -1401,7 +1411,7 @@ void btc_mesh_model_call_handler(btc_msg_t *msg) btc_ble_mesh_model_args_t *arg = NULL; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -1413,8 +1423,8 @@ void btc_mesh_model_call_handler(btc_msg_t *msg) bt_mesh_role_param_t common = {0}; common.model = (struct bt_mesh_model *)(arg->model_publish.model); common.role = arg->model_publish.device_role; - if (bt_mesh_copy_msg_role(&common)) { - LOG_ERROR("%s: copy msg_role fail", __func__); + if (bt_mesh_set_model_role(&common)) { + LOG_ERROR("%s, Failed to set model role", __func__); return; } } @@ -1423,7 +1433,7 @@ void btc_mesh_model_call_handler(btc_msg_t *msg) break; } case BTC_BLE_MESH_ACT_SERVER_MODEL_SEND: { - struct net_buf_simple *msg = NET_BUF_SIMPLE(MIN(BT_MESH_TX_SDU_MAX, ESP_BLE_MESH_SDU_MAX_LEN)); + struct net_buf_simple *msg = NET_BUF_SIMPLE(MIN(BLE_MESH_TX_SDU_MAX, ESP_BLE_MESH_SDU_MAX_LEN)); net_buf_simple_init(msg, 0); net_buf_simple_add_mem(msg, arg->model_send.data, arg->model_send.length); arg->model_send.ctx->srv_send = true; @@ -1435,15 +1445,15 @@ void btc_mesh_model_call_handler(btc_msg_t *msg) break; } case BTC_BLE_MESH_ACT_CLIENT_MODEL_SEND: { - struct net_buf_simple *msg = NET_BUF_SIMPLE(MIN(BT_MESH_TX_SDU_MAX, ESP_BLE_MESH_SDU_MAX_LEN)); + struct net_buf_simple *msg = NET_BUF_SIMPLE(MIN(BLE_MESH_TX_SDU_MAX, ESP_BLE_MESH_SDU_MAX_LEN)); bt_mesh_role_param_t common = {0}; net_buf_simple_init(msg, 0); net_buf_simple_add_mem(msg, 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_copy_msg_role(&common)) { - LOG_ERROR("%s: copy msg_role fail", __func__); + if (bt_mesh_set_model_role(&common)) { + LOG_ERROR("%s, Failed to set model role", __func__); return; } int err = bt_mesh_client_send_msg((struct bt_mesh_model *)arg->model_send.model, @@ -1456,7 +1466,7 @@ void btc_mesh_model_call_handler(btc_msg_t *msg) break; } default: - LOG_WARN("%s, Invalid msg->act %d", __func__, msg->act); + LOG_WARN("%s, Unknown msg->act %d", __func__, msg->act); break; } @@ -1468,7 +1478,7 @@ void btc_mesh_model_cb_handler(btc_msg_t *msg) esp_ble_mesh_model_cb_param_t *param = NULL; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -1477,7 +1487,7 @@ void btc_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 { - LOG_ERROR("%s, unknown msg->act = %d", __func__, msg->act); + LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act); } btc_ble_mesh_free_req_data(msg); @@ -1488,7 +1498,7 @@ void btc_mesh_prov_cb_handler(btc_msg_t *msg) esp_ble_mesh_prov_cb_param_t *param = NULL; if (!msg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -1497,8 +1507,6 @@ void btc_mesh_prov_cb_handler(btc_msg_t *msg) if (msg->act < ESP_BLE_MESH_PROV_EVT_MAX) { btc_ble_mesh_cb_to_app(msg->act, param); } else { - LOG_ERROR("%s, unknown msg->act = %d", __func__, msg->act); + LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act); } } - -#endif /* #if CONFIG_BT_MESH */ diff --git a/components/bt/ble_mesh/btc/btc_ble_mesh_sensor_client.c b/components/bt/ble_mesh/btc/btc_ble_mesh_sensor_model.c similarity index 91% rename from components/bt/ble_mesh/btc/btc_ble_mesh_sensor_client.c rename to components/bt/ble_mesh/btc/btc_ble_mesh_sensor_model.c index 448b5d0e89..76c16671b4 100644 --- a/components/bt/ble_mesh/btc/btc_ble_mesh_sensor_client.c +++ b/components/bt/ble_mesh/btc/btc_ble_mesh_sensor_model.c @@ -19,7 +19,7 @@ #include "osi/allocator.h" #include "sensor_client.h" -#include "btc_ble_mesh_sensor_client.h" +#include "btc_ble_mesh_sensor_model.h" #include "esp_ble_mesh_sensor_model_api.h" static inline void btc_ble_mesh_cb_to_app(esp_ble_mesh_sensor_client_cb_event_t event, @@ -39,7 +39,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void u16_t length; if (!msg || !dst || !src) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -60,7 +60,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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(dst->sensor_client_get_state.get_state->column_get.raw_value_x, 0); @@ -74,7 +74,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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(dst->sensor_client_get_state.get_state->series_get.raw_value_x1, 0); @@ -86,7 +86,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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(dst->sensor_client_get_state.get_state->series_get.raw_value_x2, 0); @@ -99,7 +99,7 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void break; } } else { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } break; } @@ -119,7 +119,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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_down, 0); @@ -131,7 +131,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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(dst->sensor_client_set_state.set_state->cadence_set.status_trigger_delta_up, 0); @@ -143,7 +143,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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_low, 0); @@ -155,7 +155,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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(dst->sensor_client_set_state.set_state->cadence_set.fast_cadence_high, 0); @@ -169,7 +169,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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(dst->sensor_client_set_state.set_state->setting_set.sensor_setting_raw, 0); @@ -182,12 +182,12 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void break; } } else { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } break; } default: - LOG_DEBUG("%s Unhandled deep copy %d", __func__, msg->act); + LOG_DEBUG("%s, Unknown deep copy act %d", __func__, msg->act); break; } } @@ -200,7 +200,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src u16_t length; if (!msg || !p_src_data || !p_dest_data) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -217,7 +217,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src 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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.descriptor_status.descriptor, 0); @@ -233,7 +233,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src 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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.cadence_status.sensor_cadence_value, 0); @@ -248,7 +248,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src 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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.settings_status.sensor_setting_property_ids, 0); @@ -264,7 +264,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src 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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.setting_status.sensor_setting_raw, 0); @@ -279,7 +279,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src 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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.sensor_status.marshalled_sensor_data, 0); @@ -294,7 +294,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src 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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.column_status.sensor_column_value, 0); @@ -309,7 +309,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src 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) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.series_status.sensor_series_value, 0); @@ -328,7 +328,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src if (p_dest_data->params) { memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t)); } else { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } } break; @@ -343,7 +343,7 @@ static void btc_ble_mesh_free_req_data(btc_msg_t *msg) u32_t opcode; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -406,7 +406,7 @@ void btc_ble_mesh_sensor_client_arg_deep_free(btc_msg_t *msg) u32_t opcode = 0; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -486,12 +486,12 @@ void bt_mesh_callback_sensor_status_to_btc(u32_t opcode, u8_t evt_type, 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}; - size_t length; + esp_ble_mesh_client_common_param_t params = {0}; + size_t length; uint8_t act; if (!model || !ctx) { - LOG_ERROR("%s: invalid parameter", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -509,7 +509,7 @@ void bt_mesh_callback_sensor_status_to_btc(u32_t opcode, u8_t evt_type, act = ESP_BLE_MESH_SENSOR_CLIENT_TIMEOUT_EVT; break; default: - LOG_ERROR("%s: unknown sensor status event type", __func__); + LOG_ERROR("%s, Unknown sensor client event type %d", __func__, evt_type); return; } @@ -537,7 +537,7 @@ void btc_mesh_sensor_client_publish_callback(u32_t opcode, struct bt_mesh_model struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { if (!model || !ctx || !buf) { - LOG_ERROR("%s: invalid parameter", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -553,7 +553,7 @@ void btc_mesh_sensor_client_call_handler(btc_msg_t *msg) bt_mesh_role_param_t role_param = {0}; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -564,8 +564,8 @@ void btc_mesh_sensor_client_call_handler(btc_msg_t *msg) params = arg->sensor_client_get_state.params; role_param.model = (struct bt_mesh_model *)params->model; role_param.role = params->msg_role; - if (bt_mesh_copy_msg_role(&role_param)) { - LOG_ERROR("%s: copy msg_role fail", __func__); + if (bt_mesh_set_model_role(&role_param)) { + LOG_ERROR("%s, Failed to set model role", __func__); return; } common.opcode = params->opcode; @@ -593,8 +593,8 @@ void btc_mesh_sensor_client_call_handler(btc_msg_t *msg) params = arg->sensor_client_set_state.params; role_param.model = (struct bt_mesh_model *)params->model; role_param.role = params->msg_role; - if (bt_mesh_copy_msg_role(&role_param)) { - LOG_ERROR("%s: copy msg_role fail", __func__); + if (bt_mesh_set_model_role(&role_param)) { + LOG_ERROR("%s, Failed to set model role", __func__); return; } common.opcode = params->opcode; @@ -630,7 +630,7 @@ void btc_mesh_sensor_client_cb_handler(btc_msg_t *msg) esp_ble_mesh_sensor_client_cb_param_t *param = NULL; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -639,7 +639,7 @@ void btc_mesh_sensor_client_cb_handler(btc_msg_t *msg) if (msg->act < ESP_BLE_MESH_SENSOR_CLIENT_EVT_MAX) { btc_ble_mesh_cb_to_app(msg->act, param); } else { - LOG_ERROR("%s, unknown msg->act = %d", __func__, msg->act); + LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act); } btc_ble_mesh_free_req_data(msg); diff --git a/components/bt/ble_mesh/btc/btc_ble_mesh_time_scene_client.c b/components/bt/ble_mesh/btc/btc_ble_mesh_time_scene_model.c similarity index 90% rename from components/bt/ble_mesh/btc/btc_ble_mesh_time_scene_client.c rename to components/bt/ble_mesh/btc/btc_ble_mesh_time_scene_model.c index 48d03cb38a..ee6430689c 100644 --- a/components/bt/ble_mesh/btc/btc_ble_mesh_time_scene_client.c +++ b/components/bt/ble_mesh/btc/btc_ble_mesh_time_scene_model.c @@ -19,7 +19,7 @@ #include "osi/allocator.h" #include "time_scene_client.h" -#include "btc_ble_mesh_time_scene_client.h" +#include "btc_ble_mesh_time_scene_model.h" #include "esp_ble_mesh_time_scene_model_api.h" static inline void btc_ble_mesh_cb_to_app(esp_ble_mesh_time_scene_client_cb_event_t event, @@ -37,7 +37,7 @@ void btc_ble_mesh_time_scene_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, btc_ble_mesh_time_scene_client_args_t *src = (btc_ble_mesh_time_scene_client_args_t *)p_src; if (!msg || !dst || !src) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -51,7 +51,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 { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } break; } @@ -64,12 +64,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 { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } break; } default: - LOG_DEBUG("%s Unhandled deep copy %d", __func__, msg->act); + LOG_DEBUG("%s, Unknown deep copy act %d", __func__, msg->act); break; } } @@ -82,7 +82,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src u16_t length; if (!msg || !p_src_data || !p_dest_data) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -101,7 +101,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src length = p_src_data->status_cb.scene_register_status.scenes->len; p_dest_data->status_cb.scene_register_status.scenes = bt_mesh_alloc_buf(length); if (!p_dest_data->status_cb.scene_register_status.scenes) { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); return; } net_buf_simple_init(p_dest_data->status_cb.scene_register_status.scenes, 0); @@ -120,7 +120,7 @@ static void btc_ble_mesh_copy_req_data(btc_msg_t *msg, void *p_dest, void *p_src if (p_dest_data->params) { memcpy(p_dest_data->params, p_src_data->params, sizeof(esp_ble_mesh_client_common_param_t)); } else { - LOG_ERROR("%s %d no mem", __func__, msg->act); + LOG_ERROR("%s, Failed to allocate memory, act %d", __func__, msg->act); } } break; @@ -135,7 +135,7 @@ static void btc_ble_mesh_free_req_data(btc_msg_t *msg) u32_t opcode; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -173,7 +173,7 @@ void btc_ble_mesh_time_scene_client_arg_deep_free(btc_msg_t *msg) btc_ble_mesh_time_scene_client_args_t *arg = NULL; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -223,12 +223,12 @@ void bt_mesh_callback_time_scene_status_to_btc(u32_t opcode, u8_t evt_type, 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}; - size_t length; + esp_ble_mesh_client_common_param_t params = {0}; + size_t length; uint8_t act; if (!model || !ctx) { - LOG_ERROR("%s: invalid parameter", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -246,7 +246,7 @@ void bt_mesh_callback_time_scene_status_to_btc(u32_t opcode, u8_t evt_type, act = ESP_BLE_MESH_TIME_SCENE_CLIENT_TIMEOUT_EVT; break; default: - LOG_ERROR("%s: unknown time scene status event type", __func__); + LOG_ERROR("%s, Unknown time scene client event type %d", __func__, evt_type); return; } @@ -274,7 +274,7 @@ void btc_mesh_time_scene_client_publish_callback(u32_t opcode, struct bt_mesh_mo struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { if (!model || !ctx || !buf) { - LOG_ERROR("%s: invalid parameter", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -290,7 +290,7 @@ void btc_mesh_time_scene_client_call_handler(btc_msg_t *msg) bt_mesh_role_param_t role_param = {0}; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -301,8 +301,8 @@ void btc_mesh_time_scene_client_call_handler(btc_msg_t *msg) params = arg->time_scene_client_get_state.params; role_param.model = (struct bt_mesh_model *)params->model; role_param.role = params->msg_role; - if (bt_mesh_copy_msg_role(&role_param)) { - LOG_ERROR("%s: copy msg_role fail", __func__); + if (bt_mesh_set_model_role(&role_param)) { + LOG_ERROR("%s, Failed to set model role", __func__); return; } common.opcode = params->opcode; @@ -330,8 +330,8 @@ void btc_mesh_time_scene_client_call_handler(btc_msg_t *msg) params = arg->time_scene_client_set_state.params; role_param.model = (struct bt_mesh_model *)params->model; role_param.role = params->msg_role; - if (bt_mesh_copy_msg_role(&role_param)) { - LOG_ERROR("%s: copy msg_role fail", __func__); + if (bt_mesh_set_model_role(&role_param)) { + LOG_ERROR("%s, Failed to set model role", __func__); return; } common.opcode = params->opcode; @@ -367,7 +367,7 @@ void btc_mesh_time_scene_client_cb_handler(btc_msg_t *msg) esp_ble_mesh_time_scene_client_cb_param_t *param = NULL; if (!msg || !msg->arg) { - LOG_ERROR("%s: parameter is NULL", __func__); + LOG_ERROR("%s, Invalid parameter", __func__); return; } @@ -376,7 +376,7 @@ void btc_mesh_time_scene_client_cb_handler(btc_msg_t *msg) if (msg->act < ESP_BLE_MESH_TIME_SCENE_CLIENT_EVT_MAX) { btc_ble_mesh_cb_to_app(msg->act, param); } else { - LOG_ERROR("%s, unknown msg->act = %d", __func__, msg->act); + LOG_ERROR("%s, Unknown msg->act = %d", __func__, msg->act); } btc_ble_mesh_free_req_data(msg); diff --git a/components/bt/ble_mesh/btc/include/btc_ble_mesh_config_client.h b/components/bt/ble_mesh/btc/include/btc_ble_mesh_config_model.h similarity index 95% rename from components/bt/ble_mesh/btc/include/btc_ble_mesh_config_client.h rename to components/bt/ble_mesh/btc/include/btc_ble_mesh_config_model.h index bb45221efd..6744b96120 100644 --- a/components/bt/ble_mesh/btc/include/btc_ble_mesh_config_client.h +++ b/components/bt/ble_mesh/btc/include/btc_ble_mesh_config_model.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef _BTC_BLE_MESH_CONFIG_CLIENT_H_ -#define _BTC_BLE_MESH_CONFIG_CLIENT_H_ +#ifndef _BTC_BLE_MESH_CONFIG_MODEL_H_ +#define _BTC_BLE_MESH_CONFIG_MODEL_H_ #include #include "btc/btc_task.h" @@ -61,4 +61,4 @@ void bt_mesh_callback_cfg_server_event_to_btc(u8_t evt_type, struct bt_mesh_mode struct bt_mesh_msg_ctx *ctx, const u8_t *val, size_t len); -#endif /* _BTC_BLE_MESH_CONFIG_CLIENT_H_ */ +#endif /* _BTC_BLE_MESH_CONFIG_MODEL_H_ */ diff --git a/components/bt/ble_mesh/btc/include/btc_ble_mesh_generic_client.h b/components/bt/ble_mesh/btc/include/btc_ble_mesh_generic_model.h similarity index 93% rename from components/bt/ble_mesh/btc/include/btc_ble_mesh_generic_client.h rename to components/bt/ble_mesh/btc/include/btc_ble_mesh_generic_model.h index f2b8a3c217..480003141d 100644 --- a/components/bt/ble_mesh/btc/include/btc_ble_mesh_generic_client.h +++ b/components/bt/ble_mesh/btc/include/btc_ble_mesh_generic_model.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef _BTC_BLE_MESH_GENERIC_CLIENT_H_ -#define _BTC_BLE_MESH_GENERIC_CLIENT_H_ +#ifndef _BTC_BLE_MESH_GENERIC_MODEL_H_ +#define _BTC_BLE_MESH_GENERIC_MODEL_H_ #include #include "btc/btc_task.h" @@ -48,4 +48,5 @@ void bt_mesh_callback_generic_status_to_btc(u32_t opcode, u8_t evt_type, struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, const u8_t *val, size_t len); -#endif /* _BTC_BLE_MESH_GENERIC_CLIENT_H_ */ + +#endif /* _BTC_BLE_MESH_GENERIC_MODEL_H_ */ diff --git a/components/bt/ble_mesh/btc/include/btc_ble_mesh_health.h b/components/bt/ble_mesh/btc/include/btc_ble_mesh_health_model.h similarity index 95% rename from components/bt/ble_mesh/btc/include/btc_ble_mesh_health.h rename to components/bt/ble_mesh/btc/include/btc_ble_mesh_health_model.h index 41010b935e..859624dba2 100644 --- a/components/bt/ble_mesh/btc/include/btc_ble_mesh_health.h +++ b/components/bt/ble_mesh/btc/include/btc_ble_mesh_health_model.h @@ -12,12 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef _BTC_BLE_MESH_HEALTH_H_ -#define _BTC_BLE_MESH_HEALTH_H_ +#ifndef _BTC_BLE_MESH_HEALTH_MODEL_H_ +#define _BTC_BLE_MESH_HEALTH_MODEL_H_ #include #include "btc/btc_task.h" -#include "esp_ble_mesh_defs.h" #include "esp_ble_mesh_health_model_api.h" typedef enum { @@ -76,4 +75,4 @@ void bt_mesh_callback_health_status_to_btc(u32_t opcode, u8_t evt_type, struct bt_mesh_msg_ctx *ctx, const u8_t *val, u16_t len); -#endif /* _BTC_BLE_MESH_HEALTH_H_ */ +#endif /* _BTC_BLE_MESH_HEALTH_MODEL_H_ */ diff --git a/components/bt/ble_mesh/btc/include/btc_ble_mesh_light_client.h b/components/bt/ble_mesh/btc/include/btc_ble_mesh_lighting_model.h similarity index 93% rename from components/bt/ble_mesh/btc/include/btc_ble_mesh_light_client.h rename to components/bt/ble_mesh/btc/include/btc_ble_mesh_lighting_model.h index 7b07991796..8a3088f32d 100644 --- a/components/bt/ble_mesh/btc/include/btc_ble_mesh_light_client.h +++ b/components/bt/ble_mesh/btc/include/btc_ble_mesh_lighting_model.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef _BTC_BLE_MESH_LIGHT_CLIENT_H_ -#define _BTC_BLE_MESH_LIGHT_CLIENT_H_ +#ifndef _BTC_BLE_MESH_LIGHTING_MODEL_H_ +#define _BTC_BLE_MESH_LIGHTING_MODEL_H_ #include #include "btc/btc_task.h" @@ -49,5 +49,5 @@ void bt_mesh_callback_light_status_to_btc(u32_t opcode, u8_t evt_type, struct bt_mesh_msg_ctx *ctx, const u8_t *val, size_t len); -#endif /* _BTC_BLE_MESH_LIGHT_CLIENT_H_ */ +#endif /* _BTC_BLE_MESH_LIGHTING_MODEL_H_ */ diff --git a/components/bt/ble_mesh/btc/include/btc_ble_mesh_prov.h b/components/bt/ble_mesh/btc/include/btc_ble_mesh_prov.h index c0b9b5646d..3ffceaa42f 100644 --- a/components/bt/ble_mesh/btc/include/btc_ble_mesh_prov.h +++ b/components/bt/ble_mesh/btc/include/btc_ble_mesh_prov.h @@ -26,12 +26,11 @@ #include "mesh_access.h" #include "mesh_buf.h" #include "mesh_main.h" +#include "provisioner_prov.h" #include "esp_ble_mesh_defs.h" -#if CONFIG_BT_MESH - typedef enum { - BTC_BLE_MESH_ACT_APP_REGISTER = 0, + BTC_BLE_MESH_ACT_MESH_INIT = 0, BTC_BLE_MESH_ACT_PROV_ENABLE, BTC_BLE_MESH_ACT_PROV_DISABLE, BTC_BLE_MESH_ACT_NODE_RESET, @@ -42,7 +41,7 @@ typedef enum { BTC_BLE_MESH_ACT_PROXY_IDENTITY_ENABLE, BTC_BLE_MESH_ACT_PROXY_GATT_ENABLE, BTC_BLE_MESH_ACT_PROXY_GATT_DISABLE, -#if (CONFIG_BT_MESH_PROVISIONER) +#if (CONFIG_BLE_MESH_PROVISIONER) BTC_BLE_MESH_ACT_PROVISIONER_READ_OOB_PUB_KEY, BTC_BLE_MESH_ACT_PROVISIONER_INPUT_STR, BTC_BLE_MESH_ACT_PROVISIONER_INPUT_NUM, @@ -56,7 +55,7 @@ typedef enum { BTC_BLE_MESH_ACT_PROVISIONER_SET_LOCAL_APP_KEY, BTC_BLE_MESH_ACT_PROVISIONER_BIND_LOCAL_MOD_APP, BTC_BLE_MESH_ACT_PROVISIONER_ADD_LOCAL_NET_KEY, -#endif /* CONFIG_BT_MESH_PROVISIONER */ +#endif /* CONFIG_BLE_MESH_PROVISIONER */ BTC_BLE_MESH_ACT_SET_FAST_PROV_INFO, BTC_BLE_MESH_ACT_SET_FAST_PROV_ACTION, } btc_ble_mesh_prov_act_t; @@ -68,33 +67,32 @@ typedef enum { } btc_ble_mesh_model_act_t; typedef union { - struct ble_mesh_reg_args { + struct ble_mesh_init_args { esp_ble_mesh_prov_t *prov; esp_ble_mesh_comp_t *comp; - xSemaphoreHandle semaphore; - uint8_t mesh_if; - } mesh_reg; - struct ble_mesh_prov_enable_args { + SemaphoreHandle_t semaphore; + } mesh_init; + struct ble_mesh_node_prov_enable_args { esp_ble_mesh_prov_bearer_t bearers; - } mesh_prov_enable; - struct ble_mesh_prov_disable_args { + } node_prov_enable; + struct ble_mesh_node_prov_disable_args { esp_ble_mesh_prov_bearer_t bearers; - } mesh_prov_disable; + } node_prov_disable; struct ble_mesh_set_oob_pub_key_args { uint8_t pub_key_x[32]; uint8_t pub_key_y[32]; uint8_t private_key[32]; } set_oob_pub_key; - struct ble_mesh_input_num_args { + struct ble_mesh_node_input_num_args { uint32_t number; - } input_num; - struct ble_mesh_input_str_args { + } input_number; + struct ble_mesh_node_input_str_args { char string[8]; - } input_str; + } input_string; struct ble_mesh_set_device_name_args { char name[ESP_BLE_MESH_DEVICE_NAME_MAX_LEN]; } set_device_name; -#if (CONFIG_BT_MESH_PROVISIONER) +#if (CONFIG_BLE_MESH_PROVISIONER) struct ble_mesh_provisioner_read_oob_pub_key_args { uint8_t link_idx; uint8_t pub_key_x[32]; @@ -149,8 +147,8 @@ typedef union { uint8_t net_key[16]; uint16_t net_idx; } add_local_net_key; -#endif /* CONFIG_BT_MESH_PROVISIONER */ -#if (CONFIG_BT_MESH_FAST_PROV) +#endif /* CONFIG_BLE_MESH_PROVISIONER */ +#if (CONFIG_BLE_MESH_FAST_PROV) struct ble_mesh_set_fast_prov_info_args { uint16_t unicast_min; uint16_t unicast_max; @@ -164,7 +162,7 @@ typedef union { struct ble_mesh_set_fast_prov_action_args { uint8_t action; } set_fast_prov_action; -#endif /* CONFIG_BT_MESH_FAST_PROV */ +#endif /* CONFIG_BLE_MESH_FAST_PROV */ } btc_ble_mesh_prov_args_t; typedef union { @@ -216,5 +214,3 @@ void btc_mesh_prov_call_handler(btc_msg_t *msg); void btc_mesh_prov_cb_handler(btc_msg_t *msg); #endif /* _BTC_BLE_MESH_PROV_H_ */ -#endif /* #if CONFIG_BT_MESH */ - diff --git a/components/bt/ble_mesh/btc/include/btc_ble_mesh_sensor_client.h b/components/bt/ble_mesh/btc/include/btc_ble_mesh_sensor_model.h similarity index 93% rename from components/bt/ble_mesh/btc/include/btc_ble_mesh_sensor_client.h rename to components/bt/ble_mesh/btc/include/btc_ble_mesh_sensor_model.h index af0524ec6f..6bd97355e8 100644 --- a/components/bt/ble_mesh/btc/include/btc_ble_mesh_sensor_client.h +++ b/components/bt/ble_mesh/btc/include/btc_ble_mesh_sensor_model.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef _BTC_BLE_MESH_SENSOR_CLIENT_H_ -#define _BTC_BLE_MESH_SENSOR_CLIENT_H_ +#ifndef _BTC_BLE_MESH_SENSOR_MODEL_H_ +#define _BTC_BLE_MESH_SENSOR_MODEL_H_ #include #include "btc/btc_task.h" @@ -49,5 +49,5 @@ void bt_mesh_callback_sensor_status_to_btc(u32_t opcode, u8_t evt_type, struct bt_mesh_msg_ctx *ctx, const u8_t *val, size_t len); -#endif /* _BTC_BLE_MESH_SENSOR_CLIENT_H_ */ +#endif /* _BTC_BLE_MESH_SENSOR_MODEL_H_ */ diff --git a/components/bt/ble_mesh/btc/include/btc_ble_mesh_time_scene_client.h b/components/bt/ble_mesh/btc/include/btc_ble_mesh_time_scene_model.h similarity index 93% rename from components/bt/ble_mesh/btc/include/btc_ble_mesh_time_scene_client.h rename to components/bt/ble_mesh/btc/include/btc_ble_mesh_time_scene_model.h index aaf793a8bf..1778fa2347 100644 --- a/components/bt/ble_mesh/btc/include/btc_ble_mesh_time_scene_client.h +++ b/components/bt/ble_mesh/btc/include/btc_ble_mesh_time_scene_model.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef _BTC_BLE_MESH_TIME_SCENE_CLIENT_H_ -#define _BTC_BLE_MESH_TIME_SCENE_CLIENT_H_ +#ifndef _BTC_BLE_MESH_TIME_SCENE_MODEL_H_ +#define _BTC_BLE_MESH_TIME_SCENE_MODEL_H_ #include #include "btc/btc_task.h" @@ -49,5 +49,5 @@ void bt_mesh_callback_time_scene_status_to_btc(u32_t opcode, u8_t evt_type, struct bt_mesh_msg_ctx *ctx, const u8_t *val, size_t len); -#endif /* _BTC_BLE_MESH_TIME_SCENE_CLIENT_H_ */ +#endif /* _BTC_BLE_MESH_TIME_SCENE_MODEL_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/Kconfig b/components/bt/ble_mesh/mesh_core/Kconfig deleted file mode 100644 index b6175ead7c..0000000000 --- a/components/bt/ble_mesh/mesh_core/Kconfig +++ /dev/null @@ -1,459 +0,0 @@ -# Kconfig - Bluetooth Mesh configuration options - -# -# Copyright (c) 2017 Intel Corporation -# -# SPDX-License-Identifier: Apache-2.0 -# - -menuconfig BT_MESH - bool "Bluetooth Mesh support" - select TINYCRYPT - select TINYCRYPT_AES - select TINYCRYPT_AES_CMAC - help - This option enables Bluetooth Mesh support. The specific - features that are available may depend on other features - that have been enabled in the stack, such as GATT support. - -if BT_MESH - -# Virtual option enabled whenever Generic Provisioning layer is needed -config BT_MESH_PROV - bool - -config BT_MESH_PB_ADV - bool "Provisioning support using the advertising bearer (PB-ADV)" - select BT_MESH_PROV - default y - help - Enable this option to allow the device to be provisioned over - the advertising bearer. - -if BT_CONN - -# Virtual option enabled whenever any Proxy protocol is needed -config BT_MESH_PROXY - bool - -config BT_MESH_PB_GATT - bool "Provisioning support using GATT (PB-GATT)" - select BT_MESH_PROXY - select BT_MESH_PROV - help - Enable this option to allow the device to be provisioned over - GATT. - -config BT_MESH_GATT_PROXY - bool "GATT Proxy Service" - select BT_MESH_PROXY - help - This option enables support for the Mesh GATT Proxy Service, - i.e. the ability to act as a proxy between a Mesh GATT Client - and a Mesh network. - -config BT_MESH_NODE_ID_TIMEOUT - int "Node Identity advertising timeout" - depends on BT_MESH_GATT_PROXY - range 1 60 - default 60 - help - This option determines for how long the local node advertises - using Node Identity. The given value is in seconds. The - specification limits this to 60 seconds, and implies that to - be the appropriate value as well, so just leaving this as the - default is the safest option. - -if BT_MESH_PROXY - -config BT_MESH_PROXY_FILTER_SIZE - int "Maximum number of filter entries per Proxy Client" - default 1 - default 3 if BT_MESH_GATT_PROXY - range 1 32767 - help - This option specifies how many Proxy Filter entries the local - node supports. - -endif # BT_MESH_PROXY - -endif # BT_CONN - -config BT_MESH_SELF_TEST - bool "Perform self-tests" - help - This option adds extra self-tests which are run every time - mesh networking is initialized. - -config BT_MESH_IV_UPDATE_TEST - bool "Test the IV Update Procedure" - help - This option removes the 96 hour limit of the IV Update - Procedure and lets the state be changed at any time. - -config BT_MESH_SUBNET_COUNT - int "Maximum number of mesh subnets per network" - default 1 - range 1 4096 - help - This option specifies how many subnets a Mesh network can - participate in at the same time. - -config BT_MESH_APP_KEY_COUNT - int "Maximum number of application keys per network" - default 1 - range 1 4096 - help - This option specifies how many application keys the device can - store per network. - -config BT_MESH_MODEL_KEY_COUNT - int "Maximum number of application keys per model" - default 1 - range 1 4096 - help - This option specifies how many application keys each model can - at most be bound to. - -config BT_MESH_MODEL_GROUP_COUNT - int "Maximum number of group address subscriptions per model" - default 1 - range 1 4096 - help - This option specifies how many group addresses each model can - at most be subscribed to. - -config BT_MESH_LABEL_COUNT - int "Maximum number of Label UUIDs used for Virtual Addresses" - default 1 - range 0 4096 - help - This option specifies how many Label UUIDs can be stored. - -config BT_MESH_CRPL - int "Maximum capacity of the replay protection list" - default 10 - range 2 65535 - help - This options specifies the maximum capacity of the replay - protection list. This option is similar to the network message - cache size, but has a different purpose. - -config BT_MESH_MSG_CACHE_SIZE - int "Network message cache size" - default 10 - range 2 65535 - help - Number of messages that are cached for the network. This helps - prevent unnecessary decryption operations and unnecessary - relays. This option is similar to the replay protection list, - but has a different purpose. - -config BT_MESH_ADV_BUF_COUNT - int "Number of advertising buffers" - default 6 - range 6 256 - help - Number of advertising buffers available. The transport layer - reserves ADV_BUF_COUNT - 3 buffers for outgoing segments. The - maximum outgoing SDU size is 12 times this number (out of which - 4 or 8 bytes is used for the Transport Layer MIC). For - example, 5 segments means the maximum SDU size is 60 bytes, - which leaves 56 bytes for application layer data using a - 4-byte MIC and 52 bytes using an 8-byte MIC. - -config BT_MESH_TX_SEG_MSG_COUNT - int "Maximum number of simultaneous outgoing segmented messages" - default 1 - range 1 BT_MESH_ADV_BUF_COUNT - help - Maximum number of simultaneous outgoing multi-segment and/or - reliable messages. - -config BT_MESH_RX_SEG_MSG_COUNT - int "Maximum number of simultaneous incoming segmented messages" - default 1 - range 1 255 - help - Maximum number of simultaneous incoming multi-segment and/or - reliable messages. - -config BT_MESH_RX_SDU_MAX - int "Maximum incoming Upper Transport Access PDU length" - default 384 - range 36 384 - help - Maximum incoming Upper Transport Access PDU length. Leave this - to the default value, unless you really need to optimize memory - usage. - -config BT_MESH_RELAY - bool "Relay support" - help - Support for acting as a Mesh Relay Node. - -config BT_MESH_LOW_POWER - bool "Support for Low Power features" - help - Enable this option to be able to act as a Low Power Node. - -if BT_MESH_LOW_POWER - -config BT_MESH_LPN_ESTABLISHMENT - bool "Perform Friendship establishment using low power" - default y - help - Perform the Friendship establishment using low power, with - the help of a reduced scan duty cycle. The downside of this - is that the node may miss out on messages intended for it - until it has successfully set up Friendship with a Friend - node. - -config BT_MESH_LPN_AUTO - bool "Automatically start looking for Friend nodes once provisioned" - default y - help - Automatically enable LPN functionality once provisioned and start - looking for Friend nodes. If this option is disabled LPN mode - needs to be manually enabled by calling bt_mesh_lpn_set(true). - -config BT_MESH_LPN_AUTO_TIMEOUT - int "Time from last received message before going to LPN mode" - default 15 - range 0 3600 - depends on BT_MESH_LPN_AUTO - help - Time in seconds from the last received message, that the node - will wait before starting to look for Friend nodes. - -config BT_MESH_LPN_RETRY_TIMEOUT - int "Retry timeout for Friend requests" - default 8 - range 1 3600 - help - Time in seconds between Friend Requests, if a previous Friend - Request did not receive any acceptable Friend Offers. - -config BT_MESH_LPN_RSSI_FACTOR - int "RSSIFactor, used in the Friend Offer Delay calculation" - range 0 3 - default 0 - help - The contribution of the RSSI measured by the Friend node used - in Friend Offer Delay calculations. 0 = 1, 1 = 1.5, 2 = 2, 3 = 2.5. - -config BT_MESH_LPN_RECV_WIN_FACTOR - int "ReceiveWindowFactor, used in the Friend Offer Delay calculation" - range 0 3 - default 0 - help - The contribution of the supported Receive Window used in - Friend Offer Delay calculations. 0 = 1, 1 = 1.5, 2 = 2, 3 = 2.5. - -config BT_MESH_LPN_MIN_QUEUE_SIZE - int "Minimum size of acceptable friend queue (MinQueueSizeLog)" - range 1 7 - default 1 - help - The MinQueueSizeLog field is defined as log_2(N), where N is - the minimum number of maximum size Lower Transport PDUs that - the Friend node can store in its Friend Queue. As an example, - MinQueueSizeLog value 1 gives N = 2, and value 7 gives N = 128. - -config BT_MESH_LPN_RECV_DELAY - int "Receive delay requested by the local node" - range 10 255 - default 100 - help - The ReceiveDelay is the time between the Low Power node - sending a request and listening for a response. This delay - allows the Friend node time to prepare the response. The value - is in units of milliseconds. - -config BT_MESH_LPN_POLL_TIMEOUT - int "The value of the PollTimeout timer" - range 10 244735 - default 300 - help - PollTimeout timer is used to measure time between two - consecutive requests sent by the Low Power node. If no - requests are received by the Friend node before the - PollTimeout timer expires, then the friendship is considered - terminated. The value is in units of 100 milliseconds, so e.g. - a value of 300 means 30 seconds. - -config BT_MESH_LPN_INIT_POLL_TIMEOUT - int "The starting value of the PollTimeout timer" - range 10 BT_MESH_LPN_POLL_TIMEOUT - default BT_MESH_LPN_POLL_TIMEOUT - help - The initial value of the PollTimeout timer when Friendship - gets established for the first time. After this the timeout - will gradually grow toward the actual PollTimeout, doubling - in value for each iteration. The value is in units of 100 - milliseconds, so e.g. a value of 300 means 30 seconds. - -config BT_MESH_LPN_SCAN_LATENCY - int "Latency for enabling scanning" - range 0 50 - default 10 - help - Latency in milliseconds that it takes to enable scanning. This - is in practice how much time in advance before the Receive Window - that scanning is requested to be enabled. - -config BT_MESH_LPN_GROUPS - int "Number of groups the LPN can subscribe to" - range 0 16384 - default 8 - help - Maximum number of groups that the LPN can subscribe to. -endif # BT_MESH_LOW_POWER - -config BT_MESH_FRIEND - bool "Support for acting as a Friend Node" - help - Enable this option to be able to act as a Friend Node. - -if BT_MESH_FRIEND - -config BT_MESH_FRIEND_RECV_WIN - int "Friend Receive Window" - range 1 255 - default 255 - help - Receive Window in milliseconds supported by the Friend node. - -config BT_MESH_FRIEND_QUEUE_SIZE - int "Minimum number of buffers supported per Friend Queue" - range 2 65536 - default 16 - help - Minimum number of buffers available to be stored for each - local Friend Queue. - -config BT_MESH_FRIEND_SUB_LIST_SIZE - int "Friend Subscription List Size" - range 0 1023 - default 3 - help - Size of the Subscription List that can be supported by a - Friend node for a Low Power node. - -config BT_MESH_FRIEND_LPN_COUNT - int "Number of supported LPN nodes" - range 1 1000 - default 2 - help - Number of Low Power Nodes the Friend can have a Friendship - with simultaneously. - -config BT_MESH_FRIEND_SEG_RX - int "Number of incomplete segment lists per LPN" - range 1 1000 - default 1 - help - Number of incomplete segment lists that we track for each LPN - that we are Friends for. In other words, this determines how - many elements we can simultaneously be receiving segmented - messages from when the messages are going into the Friend queue. - -endif # BT_MESH_FRIEND - -config BT_MESH_CFG_CLI - bool "Support for Configuration Client Model" - help - Enable support for the configuration client model. - -config BT_MESH_HEALTH_CLI - bool "Support for Health Client Model" - help - Enable support for the health client model. - -config BT_MESH_SHELL - bool "Enable Bluetooth Mesh shell" - select CONSOLE_SHELL - depends on BT_MESH_CFG_CLI - depends on BT_MESH_HEALTH_CLI - help - Activate shell module that provides Bluetooth Mesh commands to - the console. - -config BT_MESH_DEBUG - bool "Enable debug logs" - depends on BT_DEBUG - help - Use this option to enable debug logs for the Bluetooth - Mesh functionality. - -if BT_MESH_DEBUG - -config BT_MESH_DEBUG_NET - bool "Network layer debug" - help - Use this option to enable Network layer debug logs for the - Bluetooth Mesh functionality. - -config BT_MESH_DEBUG_TRANS - bool "Transport layer debug" - help - Use this option to enable Transport layer debug logs for the - Bluetooth Mesh functionality. - -config BT_MESH_DEBUG_BEACON - bool "Beacon debug" - help - Use this option to enable Beacon-related debug logs for the - Bluetooth Mesh functionality. - -config BT_MESH_DEBUG_CRYPTO - bool "Crypto debug" - help - Use this option to enable cryptographic debug logs for the - Bluetooth Mesh functionality. - -config BT_MESH_DEBUG_PROV - bool "Provisioning debug" - help - Use this option to enable Provisioning debug logs for the - Bluetooth Mesh functionality. - -config BT_MESH_DEBUG_ACCESS - bool "Access layer debug" - help - Use this option to enable Access layer and device composition - related debug logs for Bluetooth Mesh. - -config BT_MESH_DEBUG_MODEL - bool "Foundation model debug" - help - Use this option to enable debug logs for the Foundation - Models. - -config BT_MESH_DEBUG_ADV - bool "Advertising debug" - help - Use this option to enable advertising debug logs for - the Bluetooth Mesh functionality. - -config BT_MESH_DEBUG_LOW_POWER - bool "Low Power debug" - help - Use this option to enable Low Power debug logs for the - Bluetooth Mesh functionality. - -config BT_MESH_DEBUG_FRIEND - bool "Friend debug" - help - Use this option to enable Friend debug logs for the - Bluetooth Mesh functionality. - -config BT_MESH_DEBUG_PROXY - bool "Proxy debug" - depends on BT_MESH_PROXY - help - Use this option to enable Proxy protocol debug logs. - -endif # BT_MESH_DEBUG - -endif # BT_MESH diff --git a/components/bt/ble_mesh/mesh_core/access.c b/components/bt/ble_mesh/mesh_core/access.c index ca64b05106..191c6d3413 100644 --- a/components/bt/ble_mesh/mesh_core/access.c +++ b/components/bt/ble_mesh/mesh_core/access.c @@ -6,19 +6,20 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#include "errno.h" -#include "mesh_util.h" +#include +#include +#include -#include "mesh_buf.h" #include "sdkconfig.h" -#if CONFIG_BT_MESH +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_ACCESS) + +#include "mesh_util.h" +#include "mesh_buf.h" #include "mesh_trace.h" #include "mesh_kernel.h" #include "mesh_access.h" #include "mesh_main.h" -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_ACCESS) - #include "mesh.h" #include "adv.h" #include "net.h" @@ -27,16 +28,14 @@ #include "access.h" #include "foundation.h" +#include "mesh_common.h" #include "generic_client.h" #include "sensor_client.h" #include "time_scene_client.h" -#include "light_client.h" +#include "lighting_client.h" +#include "provisioner_main.h" -#include "common.h" - -#define CODE_UNREACHABLE BT_ERR("The op_code not defined."); - -#define BT_MESH_SDU_MAX_LEN 384 +#define BLE_MESH_SDU_MAX_LEN 384 static const struct bt_mesh_comp *dev_comp; static u16_t dev_primary_addr; @@ -45,64 +44,64 @@ static const struct { const u16_t id; int (*const init)(struct bt_mesh_model *model, bool primary); } model_init[] = { - { BT_MESH_MODEL_ID_CFG_SRV, bt_mesh_cfg_srv_init }, - { BT_MESH_MODEL_ID_HEALTH_SRV, bt_mesh_health_srv_init }, -#if defined(CONFIG_BT_MESH_CFG_CLI) - { BT_MESH_MODEL_ID_CFG_CLI, bt_mesh_cfg_cli_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_BT_MESH_HEALTH_CLI) - { BT_MESH_MODEL_ID_HEALTH_CLI, bt_mesh_health_cli_init }, +#if defined(CONFIG_BLE_MESH_HEALTH_CLI) + { BLE_MESH_MODEL_ID_HEALTH_CLI, bt_mesh_health_cli_init }, #endif -#if defined(CONFIG_BT_MESH_GENERIC_ONOFF_CLI) - { BT_MESH_MODEL_ID_GEN_ONOFF_CLI, bt_mesh_gen_onoff_cli_init }, +#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_BT_MESH_GENERIC_LEVEL_CLI) - { BT_MESH_MODEL_ID_GEN_LEVEL_CLI, bt_mesh_gen_level_cli_init }, +#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_BT_MESH_GENERIC_DEF_TRANS_TIME_CLI) - { BT_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI, bt_mesh_gen_def_trans_time_cli_init }, +#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_BT_MESH_GENERIC_POWER_ONOFF_CLI) - { BT_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI, bt_mesh_gen_pwr_onoff_cli_init }, +#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_BT_MESH_GENERIC_POWER_LEVEL_CLI) - { BT_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI, bt_mesh_gen_pwr_level_cli_init }, +#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_BT_MESH_GENERIC_BATTERY_CLI) - { BT_MESH_MODEL_ID_GEN_BATTERY_CLI, bt_mesh_gen_battery_cli_init }, +#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_BT_MESH_GENERIC_LOCATION_CLI) - { BT_MESH_MODEL_ID_GEN_LOCATION_CLI, bt_mesh_gen_location_cli_init }, +#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_BT_MESH_GENERIC_PROPERTY_CLI) - { BT_MESH_MODEL_ID_GEN_PROP_CLI, bt_mesh_gen_property_cli_init }, +#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_BT_MESH_SENSOR_CLI) - { BT_MESH_MODEL_ID_SENSOR_CLI, bt_mesh_sensor_cli_init }, +#if defined(CONFIG_BLE_MESH_SENSOR_CLI) + { BLE_MESH_MODEL_ID_SENSOR_CLI, bt_mesh_sensor_cli_init }, #endif -#if defined(CONFIG_BT_MESH_TIME_CLI) - { BT_MESH_MODEL_ID_TIME_CLI, bt_mesh_time_cli_init }, +#if defined(CONFIG_BLE_MESH_TIME_CLI) + { BLE_MESH_MODEL_ID_TIME_CLI, bt_mesh_time_cli_init }, #endif -#if defined(CONFIG_BT_MESH_SCENE_CLI) - { BT_MESH_MODEL_ID_SCENE_CLI, bt_mesh_scene_cli_init }, +#if defined(CONFIG_BLE_MESH_SCENE_CLI) + { BLE_MESH_MODEL_ID_SCENE_CLI, bt_mesh_scene_cli_init }, #endif -#if defined(CONFIG_BT_MESH_SCHEDULER_CLI) - { BT_MESH_MODEL_ID_SCHEDULER_CLI, bt_mesh_scheduler_cli_init }, +#if defined(CONFIG_BLE_MESH_SCHEDULER_CLI) + { BLE_MESH_MODEL_ID_SCHEDULER_CLI, bt_mesh_scheduler_cli_init }, #endif -#if defined(CONFIG_BT_MESH_LIGHT_LIGHTNESS_CLI) - { BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI, bt_mesh_light_lightness_cli_init }, +#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_BT_MESH_LIGHT_CTL_CLI) - { BT_MESH_MODEL_ID_LIGHT_CTL_CLI, bt_mesh_light_ctl_cli_init }, +#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_BT_MESH_LIGHT_HSL_CLI) - { BT_MESH_MODEL_ID_LIGHT_HSL_CLI, bt_mesh_light_hsl_cli_init }, +#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_BT_MESH_LIGHT_XYL_CLI) - { BT_MESH_MODEL_ID_LIGHT_XYL_CLI, bt_mesh_light_xyl_cli_init }, +#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_BT_MESH_LIGHT_LC_CLI) - { BT_MESH_MODEL_ID_LIGHT_LC_CLI, bt_mesh_light_lc_cli_init }, +#if defined(CONFIG_BLE_MESH_LIGHT_LC_CLI) + { BLE_MESH_MODEL_ID_LIGHT_LC_CLI, bt_mesh_light_lc_cli_init }, #endif }; @@ -136,7 +135,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("%s, Model has no publication support", __func__); return 0; } @@ -158,7 +157,8 @@ s32_t bt_mesh_model_pub_period_get(struct bt_mesh_model *mod) period = K_MINUTES((mod->pub->period & BIT_MASK(6)) * 10); break; default: - CODE_UNREACHABLE; + BT_ERR("%s, Unknown model publication period", __func__); + return 0; } return period >> mod->pub->period_div; @@ -170,7 +170,7 @@ static s32_t next_period(struct bt_mesh_model *mod) u32_t elapsed, period; if (!pub) { - BT_ERR("%s, model has no publication support", __func__); + BT_ERR("%s, Model has no publication support", __func__); return -ENOTSUP; } @@ -184,7 +184,7 @@ static s32_t next_period(struct bt_mesh_model *mod) BT_DBG("Publishing took %ums", elapsed); if (elapsed > period) { - BT_WARN("Publication sending took longer than the period"); + BT_WARN("%s, Publication sending took longer than the period", __func__); /* Return smallest positive number since 0 means disabled */ return K_MSEC(1); } @@ -200,12 +200,12 @@ 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("%s, Model has no publication support", __func__); return; } if (mod->pub->count) { - delay = BT_MESH_PUB_TRANSMIT_INT(mod->pub->retransmit); + delay = BLE_MESH_PUB_TRANSMIT_INT(mod->pub->retransmit); } else { delay = next_period(mod); } @@ -225,7 +225,7 @@ static int publish_retransmit(struct bt_mesh_model *mod) struct net_buf_simple *sdu = NULL; struct bt_mesh_model_pub *pub = mod->pub; if (!pub) { - BT_ERR("%s, model has no publication support", __func__); + BT_ERR("%s, Model has no publication support", __func__); return -ENOTSUP; } struct bt_mesh_app_key *key; @@ -245,6 +245,7 @@ static int publish_retransmit(struct bt_mesh_model *mod) key = bt_mesh_app_key_find(pub->key); if (!key) { + BT_ERR("%s, Failed to find AppKey", __func__); return -EADDRNOTAVAIL; } @@ -253,7 +254,7 @@ static int publish_retransmit(struct bt_mesh_model *mod) ctx.net_idx = key->net_idx; ctx.app_idx = key->app_idx; - sdu = bt_mesh_alloc_buf(min(BT_MESH_TX_SDU_MAX, BT_MESH_SDU_MAX_LEN)); + sdu = bt_mesh_alloc_buf(MIN(BLE_MESH_TX_SDU_MAX, BLE_MESH_SDU_MAX_LEN)); if (!sdu) { BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; @@ -286,7 +287,7 @@ static void mod_publish(struct k_work *work) if (pub->count) { err = publish_retransmit(pub->mod); if (err) { - BT_ERR("Failed to retransmit (err %d)", err); + BT_ERR("%s, Failed to retransmit (err %d)", __func__, err); pub->count = 0; @@ -313,13 +314,13 @@ static void mod_publish(struct k_work *work) */ err = pub->update(pub->mod); if (err) { - BT_ERR("Failed to update publication message"); + BT_ERR("%s, Failed to update publication message", __func__); return; } err = bt_mesh_model_publish(pub->mod); if (err) { - BT_ERR("Publishing failed (err %d)", err); + BT_ERR("%s, Publishing failed (err %d)", __func__, err); } if (pub->count) { @@ -341,7 +342,7 @@ static void mod_init(struct bt_mesh_model *mod, struct bt_mesh_elem *elem, } for (i = 0; i < ARRAY_SIZE(mod->keys); i++) { - mod->keys[i] = BT_MESH_KEY_UNUSED; + mod->keys[i] = BLE_MESH_KEY_UNUSED; } mod->flags = 0; @@ -414,7 +415,7 @@ void bt_mesh_comp_unprovision(void) { BT_DBG("mesh unprovision complete, %s", __func__); - dev_primary_addr = BT_MESH_ADDR_UNASSIGNED; + dev_primary_addr = BLE_MESH_ADDR_UNASSIGNED; bt_mesh_model_foreach(mod_init, NULL); } @@ -429,7 +430,7 @@ struct bt_mesh_model *bt_mesh_model_get(bool vnd, u8_t elem_idx, u8_t mod_idx) struct bt_mesh_elem *elem; if (elem_idx >= dev_comp->elem_count) { - BT_ERR("Invalid element index %u", elem_idx); + BT_ERR("%s, Invalid element index %u", __func__, elem_idx); return NULL; } @@ -437,14 +438,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("Invalid vendor model index %u", mod_idx); + BT_ERR("%s, Invalid vendor model index %u", __func__, mod_idx); return NULL; } return &elem->vnd_models[mod_idx]; } else { if (mod_idx >= elem->model_count) { - BT_ERR("Invalid SIG model index %u", mod_idx); + BT_ERR("%s, Invalid SIG model index %u", __func__, mod_idx); return NULL; } @@ -452,7 +453,6 @@ struct bt_mesh_model *bt_mesh_model_get(bool vnd, u8_t elem_idx, u8_t mod_idx) } } - u16_t *bt_mesh_model_find_group(struct bt_mesh_model *mod, u16_t addr) { int i; @@ -501,8 +501,8 @@ struct bt_mesh_elem *bt_mesh_elem_find(u16_t addr) for (i = 0; i < dev_comp->elem_count; i++) { struct bt_mesh_elem *elem = &dev_comp->elem[i]; - if (BT_MESH_ADDR_IS_GROUP(addr) || - BT_MESH_ADDR_IS_VIRTUAL(addr)) { + if (BLE_MESH_ADDR_IS_GROUP(addr) || + BLE_MESH_ADDR_IS_VIRTUAL(addr)) { if (bt_mesh_elem_find_group(elem, addr)) { return elem; } @@ -565,7 +565,7 @@ static int get_opcode(struct net_buf_simple *buf, u32_t *opcode) case 0x00: case 0x01: if (buf->data[0] == 0x7f) { - BT_ERR("Ignoring RFU OpCode"); + BT_ERR("%s, Ignoring RFU OpCode", __func__); return -EINVAL; } @@ -573,7 +573,7 @@ static int get_opcode(struct net_buf_simple *buf, u32_t *opcode) return 0; case 0x02: if (buf->len < 2) { - BT_ERR("Too short payload for 2-octet OpCode"); + BT_ERR("%s, Too short payload for 2-octet OpCode", __func__); return -EINVAL; } @@ -581,7 +581,7 @@ static int get_opcode(struct net_buf_simple *buf, u32_t *opcode) return 0; case 0x03: if (buf->len < 3) { - BT_ERR("Too short payload for 3-octet OpCode"); + BT_ERR("%s, Too short payload for 3-octet OpCode", __func__); return -EINVAL; } @@ -590,23 +590,21 @@ static int get_opcode(struct net_buf_simple *buf, u32_t *opcode) return 0; } - /* Change by Espressif, we don't support the CODE_UNREACHABLE macro in ESP-IDF architecture */ - return 0xffff; - //CODE_UNREACHABLE; + return -EINVAL; } bool bt_mesh_fixed_group_match(u16_t addr) { /* Check for fixed group addresses */ switch (addr) { - case BT_MESH_ADDR_ALL_NODES: + case BLE_MESH_ADDR_ALL_NODES: return true; - case BT_MESH_ADDR_PROXIES: - return (bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED); - case BT_MESH_ADDR_FRIENDS: - return (bt_mesh_friend_get() == BT_MESH_FRIEND_ENABLED); - case BT_MESH_ADDR_RELAYS: - return (bt_mesh_relay_get() == BT_MESH_RELAY_ENABLED); + case BLE_MESH_ADDR_PROXIES: + return (bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_ENABLED); + case BLE_MESH_ADDR_FRIENDS: + return (bt_mesh_friend_get() == BLE_MESH_FRIEND_ENABLED); + case BLE_MESH_ADDR_RELAYS: + return (bt_mesh_relay_get() == BLE_MESH_RELAY_ENABLED); default: return false; } @@ -627,7 +625,7 @@ void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf) BT_DBG("len %u: %s", buf->len, bt_hex(buf->data, buf->len)); if (get_opcode(buf, &opcode) < 0) { - BT_WARN("Unable to decode OpCode"); + BT_WARN("%s, Unable to decode OpCode", __func__); return; } @@ -637,12 +635,12 @@ void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf) for (i = 0; i < dev_comp->elem_count; i++) { struct bt_mesh_elem *elem = &dev_comp->elem[i]; - if (BT_MESH_ADDR_IS_UNICAST(rx->dst)) { + if (BLE_MESH_ADDR_IS_UNICAST(rx->dst)) { if (elem->addr != rx->dst) { continue; } - } else if (BT_MESH_ADDR_IS_GROUP(rx->dst) || - BT_MESH_ADDR_IS_VIRTUAL(rx->dst)) { + } else if (BLE_MESH_ADDR_IS_GROUP(rx->dst) || + BLE_MESH_ADDR_IS_VIRTUAL(rx->dst)) { if (!bt_mesh_elem_find_group(elem, rx->dst)) { continue; } @@ -667,8 +665,7 @@ void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf) struct net_buf_simple_state state; if (buf->len < op->min_len) { - BT_ERR("Too short message for OpCode 0x%08x", - opcode); + BT_ERR("%s, Too short message for OpCode 0x%08x", __func__, opcode); continue; } @@ -699,7 +696,7 @@ void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf) op->func(model, &rx->ctx, buf); net_buf_simple_restore(buf, &state); } else { - BT_DBG("No OpCode 0x%08x for elem %d", opcode, i); + BT_DBG("No OpCode 0x%08x for element %d", opcode, i); } } } @@ -737,16 +734,16 @@ static int model_send(struct bt_mesh_model *model, bool check = false; u8_t role; - role = bt_mesh_get_msg_role(model, tx->ctx->srv_send); + role = bt_mesh_get_model_role(model, tx->ctx->srv_send); if (role == ROLE_NVAL) { - BT_ERR("%s: get role fail", __func__); + BT_ERR("%s, Failed to get model role", __func__); return -EINVAL; } -#if CONFIG_BT_MESH_NODE && !CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER if (role == NODE) { if (!bt_mesh_is_provisioned()) { - BT_ERR("%s: Local node is not yet provisioned", __func__); + BT_ERR("%s, Local node is not yet provisioned", __func__); return -EAGAIN; } if (!bt_mesh_is_provisioner_en()) { @@ -755,10 +752,10 @@ static int model_send(struct bt_mesh_model *model, } #endif -#if !CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (role == PROVISIONER) { if (!provisioner_check_msg_dst_addr(tx->ctx->addr)) { - BT_ERR("%s: check msg dst_addr fail", __func__); + BT_ERR("%s, Failed to check DST", __func__); return -EINVAL; } if (bt_mesh_is_provisioner_en()) { @@ -767,10 +764,10 @@ static int model_send(struct bt_mesh_model *model, } #endif -#if CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (role == PROVISIONER) { if (!provisioner_check_msg_dst_addr(tx->ctx->addr)) { - BT_ERR("%s: check msg dst_addr fail", __func__); + BT_ERR("%s, Failed to check DST", __func__); return -EINVAL; } if (bt_mesh_is_provisioner_en()) { @@ -778,7 +775,7 @@ static int model_send(struct bt_mesh_model *model, } } else { if (!bt_mesh_is_provisioned()) { - BT_ERR("Local node is not yet provisioned"); + BT_ERR("%s, Local node is not yet provisioned", __func__); return -EAGAIN; } check = true; @@ -786,22 +783,22 @@ static int model_send(struct bt_mesh_model *model, #endif if (!check) { - BT_ERR("%s: check fail", __func__); + BT_ERR("%s, fail", __func__); return -EINVAL; } if (net_buf_simple_tailroom(msg) < 4) { - BT_ERR("Not enough tailroom for TransMIC"); + BT_ERR("%s, Not enough tailroom for TransMIC", __func__); return -EINVAL; } - if (msg->len > min(BT_MESH_TX_SDU_MAX, BT_MESH_SDU_MAX_LEN) - 4) { - BT_ERR("The message is too long"); + if (msg->len > MIN(BLE_MESH_TX_SDU_MAX, BLE_MESH_SDU_MAX_LEN) - 4) { + BT_ERR("%s, The message is too long", __func__); return -EMSGSIZE; } if (!implicit_bind && !model_has_key(model, tx->ctx->app_idx)) { - BT_ERR("Model not bound to AppKey 0x%04x", tx->ctx->app_idx); + BT_ERR("%s, Model not bound to AppKey 0x%04x", __func__, tx->ctx->app_idx); return -EINVAL; } @@ -816,13 +813,13 @@ int bt_mesh_model_send(struct bt_mesh_model *model, struct bt_mesh_subnet *sub = NULL; u8_t role; - role = bt_mesh_get_msg_role(model, ctx->srv_send); + role = bt_mesh_get_model_role(model, ctx->srv_send); if (role == ROLE_NVAL) { - BT_ERR("%s: get role fail", __func__); + BT_ERR("%s, Failed to get model role", __func__); return -EINVAL; } -#if CONFIG_BT_MESH_NODE && !CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER if (role == NODE) { if (!bt_mesh_is_provisioner_en()) { sub = bt_mesh_subnet_get(ctx->net_idx); @@ -830,7 +827,7 @@ int bt_mesh_model_send(struct bt_mesh_model *model, } #endif -#if !CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (role == PROVISIONER) { if (bt_mesh_is_provisioner_en()) { sub = provisioner_subnet_get(ctx->net_idx); @@ -838,7 +835,7 @@ int bt_mesh_model_send(struct bt_mesh_model *model, } #endif -#if CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (role == NODE) { sub = bt_mesh_subnet_get(ctx->net_idx); } else if (role == PROVISIONER) { @@ -846,14 +843,14 @@ int bt_mesh_model_send(struct bt_mesh_model *model, sub = provisioner_subnet_get(ctx->net_idx); } } else if (role == FAST_PROV) { -#if CONFIG_BT_MESH_FAST_PROV +#if CONFIG_BLE_MESH_FAST_PROV sub = get_fast_prov_subnet(ctx->net_idx); #endif } #endif if (!sub) { - BT_ERR("%s: get sub fail", __func__); + BT_ERR("%s, Failed to get subnet", __func__); return -EINVAL; } @@ -887,15 +884,16 @@ int bt_mesh_model_publish(struct bt_mesh_model *model) BT_DBG("%s", __func__); if (!pub) { - BT_ERR("%s, model has no publication support", __func__); + BT_ERR("%s, Model has no publication support", __func__); return -ENOTSUP; } - if (pub->addr == BT_MESH_ADDR_UNASSIGNED) { + if (pub->addr == BLE_MESH_ADDR_UNASSIGNED) { + BT_WARN("%s, Unassigned model publish address", __func__); return -EADDRNOTAVAIL; } -#if CONFIG_BT_MESH_NODE && !CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER if (pub->dev_role == NODE) { if (bt_mesh_is_provisioned()) { key = bt_mesh_app_key_find(pub->key); @@ -903,7 +901,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model) } #endif -#if !CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (pub->dev_role == PROVISIONER) { if (bt_mesh_is_provisioner_en()) { key = provisioner_app_key_find(pub->key); @@ -911,7 +909,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model) } #endif -#if CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (pub->dev_role == NODE) { if (bt_mesh_is_provisioned()) { key = bt_mesh_app_key_find(pub->key); @@ -924,21 +922,21 @@ int bt_mesh_model_publish(struct bt_mesh_model *model) #endif if (!key) { - BT_ERR("%s: get app key fail", __func__); + BT_ERR("%s, Failed to get AppKey", __func__); return -EADDRNOTAVAIL; } - if (pub->msg->len + 4 > min(BT_MESH_TX_SDU_MAX, BT_MESH_SDU_MAX_LEN)) { - BT_ERR("Message does not fit maximum SDU size"); + if (pub->msg->len + 4 > MIN(BLE_MESH_TX_SDU_MAX, BLE_MESH_SDU_MAX_LEN)) { + BT_ERR("%s, Message does not fit maximum SDU size", __func__); return -EMSGSIZE; } if (pub->count) { - BT_WARN("Clearing publish retransmit timer"); + BT_WARN("%s, Clearing publish retransmit timer", __func__); k_delayed_work_cancel(&pub->timer); } - sdu = bt_mesh_alloc_buf(min(BT_MESH_TX_SDU_MAX, BT_MESH_SDU_MAX_LEN)); + sdu = bt_mesh_alloc_buf(MIN(BLE_MESH_TX_SDU_MAX, BLE_MESH_SDU_MAX_LEN)); if (!sdu) { BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; @@ -955,7 +953,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model) tx.friend_cred = pub->cred; -#if CONFIG_BT_MESH_NODE && !CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER if (pub->dev_role == NODE) { if (bt_mesh_is_provisioned()) { tx.sub = bt_mesh_subnet_get(ctx.net_idx); @@ -963,7 +961,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model) } #endif -#if !CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (pub->dev_role == PROVISIONER) { if (bt_mesh_is_provisioner_en()) { tx.sub = provisioner_subnet_get(ctx.net_idx); @@ -971,7 +969,7 @@ int bt_mesh_model_publish(struct bt_mesh_model *model) } #endif -#if CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (pub->dev_role == NODE) { if (bt_mesh_is_provisioned()) { tx.sub = bt_mesh_subnet_get(ctx.net_idx); @@ -984,15 +982,15 @@ int bt_mesh_model_publish(struct bt_mesh_model *model) #endif if (!tx.sub) { - BT_ERR("%s: Failed to get subnet", __func__); + BT_ERR("%s, Failed to get subnet", __func__); bt_mesh_free_buf(sdu); return -EADDRNOTAVAIL; } - pub->count = BT_MESH_PUB_TRANSMIT_COUNT(pub->retransmit); + pub->count = BLE_MESH_PUB_TRANSMIT_COUNT(pub->retransmit); BT_DBG("Publish Retransmit Count %u Interval %ums", pub->count, - BT_MESH_PUB_TRANSMIT_INT(pub->retransmit)); + BLE_MESH_PUB_TRANSMIT_INT(pub->retransmit)); err = model_send(model, &tx, true, sdu, &pub_sent_cb, model); if (err) { @@ -1036,4 +1034,3 @@ const struct bt_mesh_comp *bt_mesh_comp_get(void) { return dev_comp; } -#endif /* CONFIG_BT_MESH */ diff --git a/components/bt/ble_mesh/mesh_core/access.h b/components/bt/ble_mesh/mesh_core/access.h index 3a45e49b71..4e38116a86 100644 --- a/components/bt/ble_mesh/mesh_core/access.h +++ b/components/bt/ble_mesh/mesh_core/access.h @@ -13,13 +13,11 @@ #include "mesh_buf.h" #include "net.h" -#if CONFIG_BT_MESH - /* bt_mesh_model.flags */ enum { - BT_MESH_MOD_BIND_PENDING = BIT(0), - BT_MESH_MOD_SUB_PENDING = BIT(1), - BT_MESH_MOD_PUB_PENDING = BIT(2), + BLE_MESH_MOD_BIND_PENDING = BIT(0), + BLE_MESH_MOD_SUB_PENDING = BIT(1), + BLE_MESH_MOD_PUB_PENDING = BIT(2), }; void bt_mesh_elem_register(struct bt_mesh_elem *elem, u8_t count); @@ -58,5 +56,5 @@ const struct bt_mesh_comp *bt_mesh_comp_get(void); void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf); int bt_mesh_comp_register(const struct bt_mesh_comp *comp); -#endif /* #if CONFIG_BT_MESH */ -#endif /* #ifndef _ACCESS_H_ */ + +#endif /* _ACCESS_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/adv.c b/components/bt/ble_mesh/mesh_core/adv.c index b0414e16f1..a912701908 100644 --- a/components/bt/ble_mesh/mesh_core/adv.c +++ b/components/bt/ble_mesh/mesh_core/adv.c @@ -7,46 +7,35 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "freertos/xtensa_api.h" -#include "freertos/FreeRTOSConfig.h" #include "freertos/FreeRTOS.h" #include "freertos/queue.h" #include "freertos/task.h" -#include "sdkconfig.h" - -#if CONFIG_BT_MESH #include "osi/thread.h" +#include "sdkconfig.h" +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_ADV) #include "mesh_util.h" - #include "mesh_buf.h" -#include "mesh.h" #include "mesh_bearer_adapt.h" -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_ADV) #include "mesh_trace.h" +#include "mesh_hci.h" +#include "mesh.h" #include "adv.h" #include "foundation.h" #include "net.h" #include "beacon.h" #include "prov.h" #include "proxy.h" -#include "mesh_hci.h" -#include "sdkconfig.h" #include "provisioner_prov.h" #include "provisioner_proxy.h" #include "provisioner_beacon.h" -#define BT_DATA_MESH_PROV 0x29 /* Mesh Provisioning PDU */ -#define BT_DATA_MESH_MESSAGE 0x2a /* Mesh Networking PDU */ -#define BT_DATA_MESH_BEACON 0x2b /* Mesh Beacon */ - - /* Window and Interval are equal for continuous scanning */ -#define MESH_SCAN_INTERVAL 0x20//0x10 /*Change the scan interval to 20ms here just to reduce the packet loss rate */ -#define MESH_SCAN_WINDOW 0x20//0x10 /*Change the scan window to 20ms here just to reduce the packet loss rate */ +#define BLE_MESH_SCAN_INTERVAL 0x20 /*Change the scan interval to 20ms here just to reduce the packet loss rate */ +#define BLE_MESH_SCAN_WINDOW 0x20 /*Change the scan window to 20ms here just to reduce the packet loss rate */ /* Convert from ms to 0.625ms units */ #define ADV_INT(_ms) ((_ms) * 8 / 5) @@ -67,18 +56,18 @@ #endif static xQueueHandle xBleMeshQueue = 0; -static const bt_addr_le_t *dev_addr; +static const bt_mesh_addr_t *dev_addr; static const u8_t adv_type[] = { - [BT_MESH_ADV_PROV] = BT_DATA_MESH_PROV, - [BT_MESH_ADV_DATA] = BT_DATA_MESH_MESSAGE, - [BT_MESH_ADV_BEACON] = BT_DATA_MESH_BEACON, + [BLE_MESH_ADV_PROV] = BLE_MESH_DATA_MESH_PROV, + [BLE_MESH_ADV_DATA] = BLE_MESH_DATA_MESH_MESSAGE, + [BLE_MESH_ADV_BEACON] = BLE_MESH_DATA_MESH_BEACON, }; -NET_BUF_POOL_DEFINE(adv_buf_pool, CONFIG_BT_MESH_ADV_BUF_COUNT + 3 * CONFIG_BT_MESH_PBA_SAME_TIME, - BT_MESH_ADV_DATA_SIZE, BT_MESH_ADV_USER_DATA_SIZE, NULL); +NET_BUF_POOL_DEFINE(adv_buf_pool, CONFIG_BLE_MESH_ADV_BUF_COUNT + 3 * CONFIG_BLE_MESH_PBA_SAME_TIME, + BLE_MESH_ADV_DATA_SIZE, BLE_MESH_ADV_USER_DATA_SIZE, NULL); -static struct bt_mesh_adv adv_pool[CONFIG_BT_MESH_ADV_BUF_COUNT + 3 * CONFIG_BT_MESH_PBA_SAME_TIME]; +static struct bt_mesh_adv adv_pool[CONFIG_BLE_MESH_ADV_BUF_COUNT + 3 * CONFIG_BLE_MESH_PBA_SAME_TIME]; static struct bt_mesh_adv *adv_alloc(int id) { @@ -104,37 +93,36 @@ static inline void adv_send_end(int err, const struct bt_mesh_send_cb *cb, static inline int adv_send(struct net_buf *buf) { - const s32_t adv_int_min = ((bt_dev.hci_version >= BT_HCI_VERSION_5_0) ? + const s32_t adv_int_min = ((bt_mesh_dev.hci_version >= BLE_MESH_HCI_VERSION_5_0) ? ADV_INT_FAST : ADV_INT_DEFAULT); - const struct bt_mesh_send_cb *cb = BT_MESH_ADV(buf)->cb; - void *cb_data = BT_MESH_ADV(buf)->cb_data; - struct bt_le_adv_param param; + const struct bt_mesh_send_cb *cb = BLE_MESH_ADV(buf)->cb; + void *cb_data = BLE_MESH_ADV(buf)->cb_data; + struct bt_mesh_adv_param param = {0}; + struct bt_mesh_adv_data ad = {0}; u16_t duration, adv_int; - struct bt_data ad; int err; - adv_int = max(adv_int_min, BT_MESH_ADV(buf)->adv_int); - duration = (BT_MESH_ADV(buf)->count + 1) * (adv_int + 10); + adv_int = MAX(adv_int_min, BLE_MESH_ADV(buf)->adv_int); + duration = (BLE_MESH_ADV(buf)->count + 1) * (adv_int + 10); - BT_DBG("type %u len %u: %s", BT_MESH_ADV(buf)->type, + BT_DBG("type %u len %u: %s", BLE_MESH_ADV(buf)->type, buf->len, bt_hex(buf->data, buf->len)); BT_DBG("count %u interval %ums duration %ums", - BT_MESH_ADV(buf)->count + 1, adv_int, duration); + BLE_MESH_ADV(buf)->count + 1, adv_int, duration); - ad.type = adv_type[BT_MESH_ADV(buf)->type]; + ad.type = adv_type[BLE_MESH_ADV(buf)->type]; ad.data_len = buf->len; ad.data = buf->data; param.options = 0; param.interval_min = ADV_INT(adv_int); param.interval_max = param.interval_min; - param.own_addr = NULL; err = bt_le_adv_start(¶m, &ad, 1, NULL, 0); net_buf_unref(buf); adv_send_start(duration, err, cb, cb_data); if (err) { - BT_ERR("Advertising failed: err %d", err); + BT_ERR("%s, Failed to start advertising, err %d", __func__, err); return err; } @@ -145,7 +133,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("Stopping advertising failed: err %d", err); + BT_ERR("%s, Faile to stop advertising, err %d", __func__, err); /* If start adv successfully but stop failed, we think the data has been sent successfully */ return 0; } @@ -158,23 +146,26 @@ static inline int adv_send(struct net_buf *buf) * FreeRTOS task implementation to use on ESP-IDF */ static void adv_thread(void *p) { - BT_DBG("started"); + struct net_buf **buf = NULL; + bt_mesh_msg_t msg = {0}; int status; - struct net_buf **buf; - ble_mesh_msg_t msg = {0}; + + BT_DBG("ADV thread starts"); + buf = (struct net_buf **)(&msg.arg); while (1) { *buf = NULL; -#if CONFIG_BT_MESH_NODE - if (IS_ENABLED(CONFIG_BT_MESH_PROXY)) { +#if CONFIG_BLE_MESH_NODE + if (IS_ENABLED(CONFIG_BLE_MESH_PROXY)) { xQueueReceive(xBleMeshQueue, &msg, K_NO_WAIT); while (!(*buf)) { s32_t timeout; - BT_DBG("========"); + BT_DBG("Proxy advertising start"); timeout = bt_mesh_proxy_adv_start(); - BT_DBG("=========Proxy Advertising up to %d ms", timeout); + BT_DBG("Proxy Advertising up to %d ms", timeout); xQueueReceive(xBleMeshQueue, &msg, timeout); + BT_DBG("Proxy advertising stop"); bt_mesh_proxy_adv_stop(); } } else { @@ -189,16 +180,15 @@ static void adv_thread(void *p) } /* busy == 0 means this was canceled */ - if (BT_MESH_ADV(*buf)->busy) { - BT_MESH_ADV(*buf)->busy = 0; + if (BLE_MESH_ADV(*buf)->busy) { + BLE_MESH_ADV(*buf)->busy = 0; /*TODO: Currently we check status of adv_send, which has changed the original * code of Zephyr, we need to find a better way in the future * */ status = adv_send(*buf); if (status) { - status = xQueueSendToFront(xBleMeshQueue, &msg, K_NO_WAIT); - if (status) { - BT_ERR("adv_send, xQueueSendToFront failed, status=0x%x", status); + if (xQueueSendToFront(xBleMeshQueue, &msg, K_NO_WAIT) != pdTRUE) { + BT_ERR("%s, xQueueSendToFront failed", __func__); } } } @@ -210,11 +200,10 @@ static void adv_thread(void *p) void bt_mesh_adv_update(void) { + bt_mesh_msg_t msg = {0}; BT_DBG("%s", __func__); - ble_mesh_msg_t msg = {0}; msg.arg = NULL; - // Change by Espressif, should used the QueueSend in the ESP-IDF architecture. - ble_mesh_task_post(&msg, 0); + bt_mesh_task_post(&msg, 0); } struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool, @@ -233,16 +222,17 @@ struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool, BT_DBG("%s, pool_id = %p, buf_count = %d, uinit_count = %d", __func__, buf->pool_id, pool->buf_count, pool->uninit_count); + // adv = get_id(pool->buf_count - pool->uninit_count); /* Change by Espressif. Use buf->index to get corresponding adv_pool */ adv = get_id(buf->index); - BT_MESH_ADV(buf) = adv; + BLE_MESH_ADV(buf) = adv; memset(adv, 0, sizeof(*adv)); - adv->type = type; - adv->count = xmit_count; - adv->adv_int = xmit_int; + adv->type = type; + adv->count = xmit_count; + adv->adv_int = xmit_int; return buf; } @@ -254,48 +244,44 @@ struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, u8_t xmit_count, xmit_count, xmit_int, timeout); } -void ble_mesh_task_post(ble_mesh_msg_t *msg, uint32_t timeout) +void bt_mesh_task_post(bt_mesh_msg_t *msg, uint32_t timeout) { BT_DBG("%s", __func__); if (xQueueSend(xBleMeshQueue, msg, timeout) != pdTRUE) { - BT_ERR("Ble Mesh Post failed\n"); - return; + BT_ERR("%s, Failed to post msg to queue", __func__); } } void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb, void *cb_data) { - ble_mesh_msg_t msg = {0}; - struct net_buf *send_buf = NULL; - BT_DBG("type 0x%02x len %u: %s", BT_MESH_ADV(buf)->type, buf->len, - bt_hex(buf->data, buf->len)); + bt_mesh_msg_t msg = {0}; - BT_MESH_ADV(buf)->cb = cb; - BT_MESH_ADV(buf)->cb_data = cb_data; - BT_MESH_ADV(buf)->busy = 1; - send_buf = net_buf_ref(buf); - msg.arg = (void *)send_buf; - //net_buf_put(NULL, net_buf_ref(buf)); + BT_DBG("type 0x%02x len %u: %s", BLE_MESH_ADV(buf)->type, buf->len, + bt_hex(buf->data, buf->len)); + + BLE_MESH_ADV(buf)->cb = cb; + BLE_MESH_ADV(buf)->cb_data = cb_data; + BLE_MESH_ADV(buf)->busy = 1; + + msg.arg = (void *)net_buf_ref(buf); /* Change by Espressif. The ESP-IDF should used the QueueSend to sent the msg. */ - ble_mesh_task_post(&msg, portMAX_DELAY); - /* Deleted the net_buf_put function, we don't used it in the ESP-IDF architecture */ - //net_buf_put(NULL, net_buf_ref(buf)); + bt_mesh_task_post(&msg, portMAX_DELAY); } -const bt_addr_le_t *bt_mesh_pba_get_addr(void) +const bt_mesh_addr_t *bt_mesh_pba_get_addr(void) { return dev_addr; } -static void bt_mesh_scan_cb(const bt_addr_le_t *addr, s8_t rssi, +static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr, s8_t rssi, u8_t adv_type, struct net_buf_simple *buf) { -#if CONFIG_BT_MESH_PROVISIONER && CONFIG_BT_MESH_PB_GATT +#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT u16_t uuid = 0; #endif - if (adv_type != BT_LE_ADV_NONCONN_IND && adv_type != BT_LE_ADV_IND) { + if (adv_type != BLE_MESH_ADV_NONCONN_IND && adv_type != BLE_MESH_ADV_IND) { return; } @@ -326,8 +312,8 @@ static void bt_mesh_scan_cb(const bt_addr_le_t *addr, s8_t rssi, #if 0 /* TODO: Check with BLE Mesh BQB test cases */ - if ((type == BT_DATA_MESH_PROV || type == BT_DATA_MESH_MESSAGE || - type == BT_DATA_MESH_BEACON) && (adv_type != BT_LE_ADV_NONCONN_IND)) { + if ((type == BLE_MESH_DATA_MESH_PROV || type == BLE_MESH_DATA_MESH_MESSAGE || + type == BLE_MESH_DATA_MESH_BEACON) && (adv_type != BLE_MESH_ADV_NONCONN_IND)) { BT_DBG("%s, ignore BLE Mesh packet (type 0x%02x) with adv_type 0x%02x", __func__, type, adv_type); return; @@ -335,37 +321,37 @@ static void bt_mesh_scan_cb(const bt_addr_le_t *addr, s8_t rssi, #endif switch (type) { - case BT_DATA_MESH_MESSAGE: - bt_mesh_net_recv(buf, rssi, BT_MESH_NET_IF_ADV); + case BLE_MESH_DATA_MESH_MESSAGE: + bt_mesh_net_recv(buf, rssi, BLE_MESH_NET_IF_ADV); break; -#if CONFIG_BT_MESH_PB_ADV - case BT_DATA_MESH_PROV: -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_PB_ADV + case BLE_MESH_DATA_MESH_PROV: +#if CONFIG_BLE_MESH_NODE if (!bt_mesh_is_provisioner_en()) { bt_mesh_pb_adv_recv(buf); } #endif -#if CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_PROVISIONER if (bt_mesh_is_provisioner_en()) { provisioner_pb_adv_recv(buf); } #endif break; -#endif /* CONFIG_BT_MESH_PB_ADV */ - case BT_DATA_MESH_BEACON: -#if CONFIG_BT_MESH_NODE +#endif /* CONFIG_BLE_MESH_PB_ADV */ + case BLE_MESH_DATA_MESH_BEACON: +#if CONFIG_BLE_MESH_NODE if (!bt_mesh_is_provisioner_en()) { bt_mesh_beacon_recv(buf); } #endif -#if CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_PROVISIONER if (bt_mesh_is_provisioner_en()) { provisioner_beacon_recv(buf); } #endif break; -#if CONFIG_BT_MESH_PROVISIONER && CONFIG_BT_MESH_PB_GATT - case BT_DATA_FLAGS: +#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT + case BLE_MESH_DATA_FLAGS: if (bt_mesh_is_provisioner_en()) { if (!provisioner_flags_match(buf)) { BT_DBG("Flags mismatch, ignore this adv pkt"); @@ -373,7 +359,7 @@ static void bt_mesh_scan_cb(const bt_addr_le_t *addr, s8_t rssi, } } break; - case BT_DATA_SERVICE_UUID: + case BLE_MESH_DATA_UUID16_ALL: if (bt_mesh_is_provisioner_en()) { uuid = provisioner_srv_uuid_recv(buf); if (!uuid) { @@ -382,12 +368,12 @@ static void bt_mesh_scan_cb(const bt_addr_le_t *addr, s8_t rssi, } } break; - case BT_DATA_SERVICE_DATA: + case BLE_MESH_DATA_SVC_DATA16: if (bt_mesh_is_provisioner_en()) { provisioner_srv_data_recv(buf, addr, uuid); } break; -#endif /* CONFIG_BT_MESH_PROVISIONER && CONFIG_BT_MESH_PB_GATT */ +#endif /* CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT */ default: break; } @@ -402,18 +388,18 @@ static void bt_mesh_scan_cb(const bt_addr_le_t *addr, s8_t rssi, void bt_mesh_adv_init(void) { /* Change by Espressif, we should used the FreeRTOS create task method to use task */ - xBleMeshQueue = xQueueCreate(150, sizeof(ble_mesh_msg_t)); - xTaskCreatePinnedToCore(adv_thread, "BLE_Mesh_Adv_task", 2048, NULL, + xBleMeshQueue = xQueueCreate(150, sizeof(bt_mesh_msg_t)); + xTaskCreatePinnedToCore(adv_thread, "BLE_Mesh_ADV_Task", 3072, NULL, configMAX_PRIORITIES - 7, NULL, TASK_PINNED_TO_CORE); } int bt_mesh_scan_enable(void) { - struct bt_le_scan_param scan_param = { - .type = BT_HCI_LE_SCAN_PASSIVE, - .filter_dup = BT_HCI_LE_SCAN_FILTER_DUP_DISABLE, - .interval = MESH_SCAN_INTERVAL, - .window = MESH_SCAN_WINDOW + struct bt_mesh_scan_param scan_param = { + .type = BLE_MESH_SCAN_PASSIVE, + .filter_dup = BLE_MESH_SCAN_FILTER_DUP_DISABLE, + .interval = BLE_MESH_SCAN_INTERVAL, + .window = BLE_MESH_SCAN_WINDOW }; BT_DBG("%s", __func__); @@ -421,14 +407,14 @@ int bt_mesh_scan_enable(void) return bt_le_scan_start(&scan_param, bt_mesh_scan_cb); } -#if defined(CONFIG_BT_MESH_USE_DUPLICATE_SCAN) +#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) int bt_mesh_duplicate_scan_enable(void) { - struct bt_le_scan_param scan_param = { - .type = BT_HCI_LE_SCAN_PASSIVE, - .filter_dup = BT_HCI_LE_SCAN_FILTER_DUP_ENABLE, - .interval = MESH_SCAN_INTERVAL, - .window = MESH_SCAN_WINDOW + struct bt_mesh_scan_param scan_param = { + .type = BLE_MESH_SCAN_PASSIVE, + .filter_dup = BLE_MESH_SCAN_FILTER_DUP_ENABLE, + .interval = BLE_MESH_SCAN_INTERVAL, + .window = BLE_MESH_SCAN_WINDOW }; BT_DBG("%s", __func__); @@ -443,5 +429,3 @@ int bt_mesh_scan_disable(void) return bt_le_scan_stop(); } - -#endif /* #if CONFIG_BT_MESH */ diff --git a/components/bt/ble_mesh/mesh_core/adv.h b/components/bt/ble_mesh/mesh_core/adv.h index 512b90b5f1..c57c5e958c 100644 --- a/components/bt/ble_mesh/mesh_core/adv.h +++ b/components/bt/ble_mesh/mesh_core/adv.h @@ -7,28 +7,31 @@ * SPDX-License-Identifier: Apache-2.0 */ +#ifndef _ADV_H_ +#define _ADV_H_ + #include "mesh_bearer_adapt.h" /* Maximum advertising data payload for a single data type */ -#define BT_MESH_ADV_DATA_SIZE 29 +#define BLE_MESH_ADV_DATA_SIZE 29 /* The user data is a pointer (4 bytes) to struct bt_mesh_adv */ -#define BT_MESH_ADV_USER_DATA_SIZE 4 +#define BLE_MESH_ADV_USER_DATA_SIZE 4 -#define BT_MESH_ADV(buf) (*(struct bt_mesh_adv **)net_buf_user_data(buf)) +#define BLE_MESH_ADV(buf) (*(struct bt_mesh_adv **)net_buf_user_data(buf)) -typedef struct ble_mesh_msg { +typedef struct bt_mesh_msg { uint8_t sig; //event signal uint8_t aid; //application id uint8_t pid; //profile id uint8_t act; //profile action, defined in seprerate header files void *arg; //param for btc function or function param -} ble_mesh_msg_t; +} bt_mesh_msg_t; enum bt_mesh_adv_type { - BT_MESH_ADV_PROV, - BT_MESH_ADV_DATA, - BT_MESH_ADV_BEACON, + BLE_MESH_ADV_PROV, + BLE_MESH_ADV_DATA, + BLE_MESH_ADV_BEACON, }; typedef void (*bt_mesh_adv_func_t)(struct net_buf *buf, u16_t duration, @@ -38,10 +41,10 @@ struct bt_mesh_adv { const struct bt_mesh_send_cb *cb; void *cb_data; - u8_t type: 2, - busy: 1; - u8_t count: 3, - adv_int: 5; + u8_t type: 2, + busy: 1; + u8_t count: 3, + adv_int: 5; union { /* Address, used e.g. for Friend Queue messages */ u16_t addr; @@ -68,7 +71,7 @@ struct net_buf *bt_mesh_adv_create_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_addr_le_t *bt_mesh_pba_get_addr(void); +const bt_mesh_addr_t *bt_mesh_pba_get_addr(void); void bt_mesh_adv_update(void); @@ -80,5 +83,6 @@ int bt_mesh_duplicate_scan_enable(void); int bt_mesh_scan_disable(void); -void ble_mesh_task_post(ble_mesh_msg_t *msg, uint32_t timeout); +void bt_mesh_task_post(bt_mesh_msg_t *msg, uint32_t timeout); +#endif /* _ADV_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/beacon.c b/components/bt/ble_mesh/mesh_core/beacon.c index 68ec03e350..d57fab2626 100644 --- a/components/bt/ble_mesh/mesh_core/beacon.c +++ b/components/bt/ble_mesh/mesh_core/beacon.c @@ -7,37 +7,32 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include #include +#include + +#include "sdkconfig.h" +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_BEACON) #include "mesh_util.h" - #include "mesh_buf.h" -#include "sdkconfig.h" #include "mesh_main.h" - -#if CONFIG_BT_MESH - -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_BEACON) #include "mesh_trace.h" -#include "adv.h" #include "mesh.h" +#include "adv.h" #include "net.h" #include "prov.h" #include "crypto.h" #include "beacon.h" #include "foundation.h" -#include "provisioner_prov.h" +#if CONFIG_BLE_MESH_NODE -#if CONFIG_BT_MESH_NODE - -#if defined(CONFIG_BT_MESH_FAST_PROV) +#if defined(CONFIG_BLE_MESH_FAST_PROV) #define UNPROVISIONED_INTERVAL K_SECONDS(3) #else #define UNPROVISIONED_INTERVAL K_SECONDS(5) -#endif /* CONFIG_BT_MESH_FAST_PROV */ +#endif /* CONFIG_BLE_MESH_FAST_PROV */ #define PROVISIONED_INTERVAL K_SECONDS(10) #define BEACON_TYPE_UNPROVISIONED 0x00 @@ -60,7 +55,7 @@ static struct bt_mesh_subnet *cache_check(u8_t data[21]) for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) { struct bt_mesh_subnet *sub = &bt_mesh.sub[i]; - if (sub->net_idx == BT_MESH_KEY_UNUSED) { + if (sub->net_idx == BLE_MESH_KEY_UNUSED) { continue; } @@ -134,7 +129,7 @@ static int secure_beacon_send(void) struct net_buf *buf; u32_t time_diff; - if (sub->net_idx == BT_MESH_KEY_UNUSED) { + if (sub->net_idx == BLE_MESH_KEY_UNUSED) { continue; } @@ -144,10 +139,10 @@ static int secure_beacon_send(void) continue; } - buf = bt_mesh_adv_create(BT_MESH_ADV_BEACON, PROV_XMIT_COUNT, + buf = bt_mesh_adv_create(BLE_MESH_ADV_BEACON, PROV_XMIT_COUNT, PROV_XMIT_INT, K_NO_WAIT); if (!buf) { - BT_ERR("Unable to allocate beacon buffer"); + BT_ERR("%s, Unable to allocate beacon buffer", __func__); return -ENOBUFS; } @@ -162,21 +157,18 @@ static int secure_beacon_send(void) static int unprovisioned_beacon_send(void) { -#if defined(CONFIG_BT_MESH_PB_ADV) - struct net_buf *buf; - struct bt_mesh_adv *adv; +#if defined(CONFIG_BLE_MESH_PB_ADV) + struct net_buf *buf = NULL; + BT_DBG("%s", __func__); - buf = bt_mesh_adv_create(BT_MESH_ADV_BEACON, UNPROV_XMIT_COUNT, + buf = bt_mesh_adv_create(BLE_MESH_ADV_BEACON, UNPROV_XMIT_COUNT, UNPROV_XMIT_INT, K_NO_WAIT); if (!buf) { - BT_ERR("Unable to allocate beacon buffer"); + BT_ERR("%s, Unable to allocate beacon buffer", __func__); return -ENOBUFS; } - // Change by Espressif, added the following code for the debug used. - adv = BT_MESH_ADV(buf); - BT_DBG("%s, adv->type = %d, adv->count = %d, adv->adv_int = %d", __func__, - adv->type, adv->count, adv->adv_int); + net_buf_add_u8(buf, BEACON_TYPE_UNPROVISIONED); net_buf_add_mem(buf, bt_mesh_prov_get_uuid(), 16); @@ -186,7 +178,7 @@ static int unprovisioned_beacon_send(void) bt_mesh_adv_send(buf, NULL, NULL); net_buf_unref(buf); -#endif /* CONFIG_BT_MESH_PB_ADV */ +#endif /* CONFIG_BLE_MESH_PB_ADV */ return 0; } @@ -207,7 +199,7 @@ static void update_beacon_observation(void) for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) { struct bt_mesh_subnet *sub = &bt_mesh.sub[i]; - if (sub->net_idx == BT_MESH_KEY_UNUSED) { + if (sub->net_idx == BLE_MESH_KEY_UNUSED) { continue; } @@ -219,7 +211,7 @@ static void update_beacon_observation(void) static void beacon_send(struct k_work *work) { /* Don't send anything if there is an active provisioning link */ - if (IS_ENABLED(CONFIG_BT_MESH_PROV) && bt_prov_active()) { + if (IS_ENABLED(CONFIG_BLE_MESH_PROV) && bt_prov_active()) { k_delayed_work_submit(&beacon_timer, UNPROVISIONED_INTERVAL); return; } @@ -231,16 +223,14 @@ static void beacon_send(struct k_work *work) secure_beacon_send(); /* Only resubmit if beaconing is still enabled */ - if (bt_mesh_beacon_get() == BT_MESH_BEACON_ENABLED || + if (bt_mesh_beacon_get() == BLE_MESH_BEACON_ENABLED || bt_mesh.ivu_initiator) { - k_delayed_work_submit(&beacon_timer, - PROVISIONED_INTERVAL); + k_delayed_work_submit(&beacon_timer, PROVISIONED_INTERVAL); } } else { unprovisioned_beacon_send(); k_delayed_work_submit(&beacon_timer, UNPROVISIONED_INTERVAL); } - } static void secure_beacon_recv(struct net_buf_simple *buf) @@ -252,7 +242,7 @@ static void secure_beacon_recv(struct net_buf_simple *buf) u8_t flags; if (buf->len < 21) { - BT_ERR("Too short secure beacon (len %u)", buf->len); + BT_ERR("%s, Too short secure beacon (len %u)", __func__, buf->len); return; } @@ -271,8 +261,7 @@ static void secure_beacon_recv(struct net_buf_simple *buf) iv_index = net_buf_simple_pull_be32(buf); auth = buf->data; - BT_DBG("flags 0x%02x id %s iv_index 0x%08x", - flags, bt_hex(net_id, 8), iv_index); + BT_DBG("flags 0x%02x id %s iv_index 0x%08x", flags, bt_hex(net_id, 8), iv_index); sub = bt_mesh_subnet_find(net_id, flags, iv_index, auth, &new_key); if (!sub) { @@ -280,7 +269,7 @@ static void secure_beacon_recv(struct net_buf_simple *buf) return; } - if (sub->kr_phase == BT_MESH_KR_PHASE_2 && !new_key) { + if (sub->kr_phase == BLE_MESH_KR_PHASE_2 && !new_key) { BT_WARN("Ignoring Phase 2 KR Update secured using old key"); return; } @@ -288,8 +277,8 @@ static void secure_beacon_recv(struct net_buf_simple *buf) cache_add(data, sub); /* If there is NetKey0, accept initiation only from it */ - if (bt_mesh_subnet_get(BT_MESH_KEY_PRIMARY) && - sub->net_idx != BT_MESH_KEY_PRIMARY) { + if (bt_mesh_subnet_get(BLE_MESH_KEY_PRIMARY) && + sub->net_idx != BLE_MESH_KEY_PRIMARY) { BT_WARN("Ignoring secure beacon on non-primary subnet"); goto update_stats; } @@ -298,13 +287,13 @@ static void secure_beacon_recv(struct net_buf_simple *buf) sub->net_idx, iv_index, bt_mesh.iv_index); if (bt_mesh.ivu_initiator && - bt_mesh.iv_update == BT_MESH_IV_UPDATE(flags)) { + bt_mesh.iv_update == BLE_MESH_IV_UPDATE(flags)) { bt_mesh_beacon_ivu_initiator(false); } - iv_change = bt_mesh_net_iv_update(iv_index, BT_MESH_IV_UPDATE(flags)); + iv_change = bt_mesh_net_iv_update(iv_index, BLE_MESH_IV_UPDATE(flags)); - kr_change = bt_mesh_kr_update(sub, BT_MESH_KEY_REFRESH(flags), new_key); + kr_change = bt_mesh_kr_update(sub, BLE_MESH_KEY_REFRESH(flags), new_key); if (kr_change) { bt_mesh_net_beacon_update(sub); } @@ -318,7 +307,7 @@ static void secure_beacon_recv(struct net_buf_simple *buf) } update_stats: - if (bt_mesh_beacon_get() == BT_MESH_BEACON_ENABLED && + if (bt_mesh_beacon_get() == BLE_MESH_BEACON_ENABLED && sub->beacons_cur < 0xff) { sub->beacons_cur++; } @@ -331,7 +320,7 @@ void bt_mesh_beacon_recv(struct net_buf_simple *buf) BT_DBG("%u bytes: %s", buf->len, bt_hex(buf->data, buf->len)); if (buf->len < 1) { - BT_ERR("Too short beacon"); + BT_ERR("%s, Too short beacon", __func__); return; } @@ -344,7 +333,7 @@ void bt_mesh_beacon_recv(struct net_buf_simple *buf) secure_beacon_recv(buf); break; default: - BT_WARN("Unknown beacon type 0x%02x", type); + BT_DBG("Unknown beacon type 0x%02x", type); break; } } @@ -360,7 +349,7 @@ void bt_mesh_beacon_ivu_initiator(bool enable) if (enable) { k_work_submit(&beacon_timer.work); - } else if (bt_mesh_beacon_get() == BT_MESH_BEACON_DISABLED) { + } else if (bt_mesh_beacon_get() == BLE_MESH_BEACON_DISABLED) { k_delayed_work_cancel(&beacon_timer); } } @@ -377,7 +366,7 @@ void bt_mesh_beacon_enable(void) for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) { struct bt_mesh_subnet *sub = &bt_mesh.sub[i]; - if (sub->net_idx == BT_MESH_KEY_UNUSED) { + if (sub->net_idx == BLE_MESH_KEY_UNUSED) { continue; } @@ -397,6 +386,4 @@ void bt_mesh_beacon_disable(void) } } -#endif /* CONFIG_BT_MESH_NODE */ - -#endif /* #if CONFIG_BT_MESH */ \ No newline at end of file +#endif /* CONFIG_BLE_MESH_NODE */ diff --git a/components/bt/ble_mesh/mesh_core/beacon.h b/components/bt/ble_mesh/mesh_core/beacon.h index 76b8b49d65..366d9d752f 100644 --- a/components/bt/ble_mesh/mesh_core/beacon.h +++ b/components/bt/ble_mesh/mesh_core/beacon.h @@ -6,7 +6,11 @@ * SPDX-License-Identifier: Apache-2.0 */ +#ifndef _BEACON_H_ +#define _BEACON_H_ + void bt_mesh_beacon_enable(void); + void bt_mesh_beacon_disable(void); void bt_mesh_beacon_ivu_initiator(bool enable); @@ -17,3 +21,5 @@ void bt_mesh_beacon_create(struct bt_mesh_subnet *sub, struct net_buf_simple *buf); void bt_mesh_beacon_init(void); + +#endif /* _BEACON_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/cfg_cli.c b/components/bt/ble_mesh/mesh_core/cfg_cli.c index 0387cc101f..6709a5183e 100644 --- a/components/bt/ble_mesh/mesh_core/cfg_cli.c +++ b/components/bt/ble_mesh/mesh_core/cfg_cli.c @@ -10,22 +10,21 @@ #include #include #include + +#include "osi/allocator.h" +#include "sdkconfig.h" +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_MODEL) + #include "mesh_types.h" #include "mesh_util.h" #include "mesh_kernel.h" - -#include "mesh.h" -#include "sdkconfig.h" -#include "osi/allocator.h" - -#if CONFIG_BT_MESH - -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_MODEL) #include "mesh_trace.h" #include "cfg_cli.h" + +#include "mesh.h" #include "foundation.h" -#include "common.h" -#include "btc_ble_mesh_config_client.h" +#include "mesh_common.h" +#include "btc_ble_mesh_config_model.h" #define CID_NVAL 0xffff @@ -85,27 +84,27 @@ static const bt_mesh_client_op_pair_t cfg_op_pair[] = { static void timeout_handler(struct k_work *work) { - bt_mesh_config_client_t *client = NULL; - config_internal_data_t *internal = NULL; - bt_mesh_client_node_t *node = NULL; + config_internal_data_t *internal = NULL; + bt_mesh_config_client_t *client = NULL; + bt_mesh_client_node_t *node = NULL; BT_WARN("Receive configuration status message timeout"); node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work); if (!node || !node->ctx.model) { - BT_ERR("%s: node parameter is NULL", __func__); + BT_ERR("%s, Invalid parameter", __func__); return; } client = (bt_mesh_config_client_t *)node->ctx.model->user_data; if (!client) { - BT_ERR("%s: model user_data is NULL", __func__); + BT_ERR("%s, Config Client user_data is NULL", __func__); return; } internal = (config_internal_data_t *)client->internal_data; if (!internal) { - BT_ERR("%s: internal_data is NULL", __func__); + BT_ERR("%s, Config Client internal_data is NULL", __func__); return; } @@ -122,18 +121,18 @@ static void cfg_client_cancel(struct bt_mesh_model *model, void *status, size_t len) { config_internal_data_t *data = NULL; - bt_mesh_client_node_t *node = NULL; + bt_mesh_client_node_t *node = NULL; struct net_buf_simple buf = {0}; u8_t evt_type = 0xFF; if (!model || !ctx) { - BT_ERR("%s: invalid parameter", __func__); + BT_ERR("%s, Invalid parameter", __func__); return; } data = (config_internal_data_t *)cli->internal_data; if (!data) { - BT_ERR("%s: config client internal_data is NULL", __func__); + BT_ERR("%s, Config Client internal_data is NULL", __func__); return; } @@ -253,7 +252,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: allocate memory for comp_data fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } @@ -504,7 +503,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, Failed to allocate memory", __func__); return; } net_buf_simple_init(list.addr, 0); @@ -525,7 +524,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, Failed to allocate memory", __func__); return; } net_buf_simple_init(list.net_idx, 0); @@ -548,7 +547,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, Failed to allocate memory", __func__); return; } net_buf_simple_init(list.app_idx, 0); @@ -595,7 +594,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, Failed to allocate memory", __func__); return; } net_buf_simple_init(list.app_idx, 0); @@ -671,7 +670,7 @@ const struct bt_mesh_model_op bt_mesh_cfg_cli_op[] = { { OP_KRP_STATUS, 4, kr_phase_status }, { OP_LPN_TIMEOUT_STATUS, 5, lpn_pollto_status }, { OP_NET_TRANSMIT_STATUS, 1, net_trans_status }, - BT_MESH_MODEL_OP_END, + BLE_MESH_MODEL_OP_END, }; int bt_mesh_cfg_comp_data_get(struct bt_mesh_msg_ctx *ctx, u8_t page) @@ -690,7 +689,7 @@ int bt_mesh_cfg_comp_data_get(struct bt_mesh_msg_ctx *ctx, u8_t page) msg, timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -706,7 +705,7 @@ static int get_state_u8(struct bt_mesh_msg_ctx *ctx, u32_t op) 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); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -723,7 +722,7 @@ static int set_state_u8(struct bt_mesh_msg_ctx *ctx, u32_t op, u8_t new_val) 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); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -808,7 +807,7 @@ int bt_mesh_cfg_relay_get(struct bt_mesh_msg_ctx *ctx) timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -832,7 +831,7 @@ int bt_mesh_cfg_relay_set(struct bt_mesh_msg_ctx *ctx, u8_t new_relay, timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -856,7 +855,7 @@ int bt_mesh_cfg_net_key_add(struct bt_mesh_msg_ctx *ctx, u16_t key_net_idx, timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -880,7 +879,7 @@ int bt_mesh_cfg_app_key_add(struct bt_mesh_msg_ctx *ctx, u16_t key_net_idx, timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -908,7 +907,7 @@ int bt_mesh_cfg_mod_app_bind(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -931,7 +930,7 @@ static int mod_sub(u32_t op, struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, 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); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -985,7 +984,7 @@ static int mod_sub_va(u32_t op, struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, 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); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1039,7 +1038,7 @@ int bt_mesh_cfg_mod_pub_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1072,7 +1071,7 @@ int bt_mesh_cfg_mod_pub_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1097,7 +1096,7 @@ int bt_mesh_cfg_hb_sub_set(struct bt_mesh_msg_ctx *ctx, msg, timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1118,7 +1117,7 @@ int bt_mesh_cfg_hb_sub_get(struct bt_mesh_msg_ctx *ctx) msg, timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1146,7 +1145,7 @@ int bt_mesh_cfg_hb_pub_set(struct bt_mesh_msg_ctx *ctx, msg, timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1167,7 +1166,7 @@ int bt_mesh_cfg_hb_pub_get(struct bt_mesh_msg_ctx *ctx) msg, timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1188,7 +1187,7 @@ int bt_mesh_cfg_node_reset(struct bt_mesh_msg_ctx *ctx) timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1221,7 +1220,7 @@ int bt_mesh_cfg_mod_pub_va_set(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1248,7 +1247,7 @@ int bt_mesh_cfg_mod_sub_del_all(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1270,7 +1269,7 @@ static int mod_sub_get(u32_t op, struct bt_mesh_msg_ctx *ctx, 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); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1311,7 +1310,7 @@ int bt_mesh_cfg_net_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1333,7 +1332,7 @@ int bt_mesh_cfg_net_key_delete(struct bt_mesh_msg_ctx *ctx, u16_t net_idx) timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1354,7 +1353,7 @@ int bt_mesh_cfg_net_key_get(struct bt_mesh_msg_ctx *ctx) timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1378,7 +1377,7 @@ int bt_mesh_cfg_app_key_update(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1400,7 +1399,7 @@ int bt_mesh_cfg_app_key_delete(struct bt_mesh_msg_ctx *ctx, u16_t net_idx, u16_t timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1422,7 +1421,7 @@ int bt_mesh_cfg_app_key_get(struct bt_mesh_msg_ctx *ctx, u16_t net_idx) timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1443,7 +1442,7 @@ static int node_identity_op(u32_t op, struct bt_mesh_msg_ctx *ctx, 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); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1487,7 +1486,7 @@ int bt_mesh_cfg_mod_app_unbind(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1509,7 +1508,7 @@ static int mod_app_get(u32_t op, struct bt_mesh_msg_ctx *ctx, 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); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1547,7 +1546,7 @@ static int kr_phase_op(u32_t op, struct bt_mesh_msg_ctx *ctx, 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); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1585,7 +1584,7 @@ int bt_mesh_cfg_lpn_timeout_get(struct bt_mesh_msg_ctx *ctx, u16_t lpn_addr) timeout_handler, config_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -1619,8 +1618,8 @@ void bt_mesh_cfg_cli_timeout_set(s32_t timeout) int bt_mesh_cfg_cli_init(struct bt_mesh_model *model, bool primary) { - bt_mesh_config_client_t *client = NULL; - config_internal_data_t *internal = NULL; + config_internal_data_t *internal = NULL; + bt_mesh_config_client_t *client = NULL; BT_DBG("primary %u", primary); @@ -1649,17 +1648,15 @@ int bt_mesh_cfg_cli_init(struct bt_mesh_model *model, bool primary) sys_slist_init(&internal->queue); - client->model = model; - client->op_pair_size = ARRAY_SIZE(cfg_op_pair); - client->op_pair = cfg_op_pair; + client->model = model; + client->op_pair_size = ARRAY_SIZE(cfg_op_pair); + client->op_pair = cfg_op_pair; client->internal_data = internal; cli = client; /* Configuration Model security is device-key based */ - model->keys[0] = BT_MESH_KEY_DEV; + model->keys[0] = BLE_MESH_KEY_DEV; return 0; } - -#endif /* #if CONFIG_BT_MESH */ diff --git a/components/bt/ble_mesh/mesh_core/cfg_srv.c b/components/bt/ble_mesh/mesh_core/cfg_srv.c index 5b585af1b2..8fa689aaeb 100644 --- a/components/bt/ble_mesh/mesh_core/cfg_srv.c +++ b/components/bt/ble_mesh/mesh_core/cfg_srv.c @@ -10,17 +10,17 @@ #include #include #include + +#include "sdkconfig.h" +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_MODEL) + #include "mesh_types.h" #include "mesh_util.h" -#include "sdkconfig.h" #include "mesh_main.h" - -#if CONFIG_BT_MESH - -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_MODEL) #include "mesh_trace.h" - #include "cfg_srv.h" +#include "settings.h" + #include "mesh.h" #include "adv.h" #include "net.h" @@ -32,11 +32,11 @@ #include "proxy.h" #include "foundation.h" #include "friend.h" -#include "settings.h" -#include "common.h" -#include "btc_ble_mesh_config_client.h" -#define DEFAULT_TTL 7 +#include "mesh_common.h" +#include "btc_ble_mesh_config_model.h" + +#define DEFAULT_TTL 7 /* Maximum message length is 384 in BLE Mesh. Here for composition data, * due to 1 octet opcode and 4 octets TransMIC, 379 octets can be used to @@ -50,7 +50,7 @@ static struct label { u16_t ref; u16_t addr; u8_t uuid[16]; -} labels[CONFIG_BT_MESH_LABEL_COUNT]; +} labels[CONFIG_BLE_MESH_LABEL_COUNT]; static void hb_send(struct bt_mesh_model *model) { @@ -62,7 +62,7 @@ static void hb_send(struct bt_mesh_model *model) } hb; struct bt_mesh_msg_ctx ctx = { .net_idx = cfg->hb_pub.net_idx, - .app_idx = BT_MESH_KEY_UNUSED, + .app_idx = BLE_MESH_KEY_UNUSED, .addr = cfg->hb_pub.dst, .send_ttl = cfg->hb_pub.ttl, }; @@ -75,21 +75,21 @@ static void hb_send(struct bt_mesh_model *model) hb.init_ttl = cfg->hb_pub.ttl; - if (bt_mesh_relay_get() == BT_MESH_RELAY_ENABLED) { - feat |= BT_MESH_FEAT_RELAY; + if (bt_mesh_relay_get() == BLE_MESH_RELAY_ENABLED) { + feat |= BLE_MESH_FEAT_RELAY; } - if (bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED) { - feat |= BT_MESH_FEAT_PROXY; + if (bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_ENABLED) { + feat |= BLE_MESH_FEAT_PROXY; } - if (bt_mesh_friend_get() == BT_MESH_FRIEND_ENABLED) { - feat |= BT_MESH_FEAT_FRIEND; + if (bt_mesh_friend_get() == BLE_MESH_FRIEND_ENABLED) { + feat |= BLE_MESH_FEAT_FRIEND; } -#if defined(CONFIG_BT_MESH_LOW_POWER) - if (bt_mesh.lpn.state != BT_MESH_LPN_DISABLED) { - feat |= BT_MESH_FEAT_LOW_POWER; +#if defined(CONFIG_BLE_MESH_LOW_POWER) + if (bt_mesh.lpn.state != BLE_MESH_LPN_DISABLED) { + feat |= BLE_MESH_FEAT_LOW_POWER; } #endif @@ -109,7 +109,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 * 2) + (elem->vnd_model_count * 2)) { - BT_ERR("Too large device composition"); + BT_ERR("%s, Too large device composition", __func__); return -E2BIG; } @@ -140,26 +140,26 @@ static int comp_get_page_0(struct net_buf_simple *buf) comp = bt_mesh_comp_get(); - if (IS_ENABLED(CONFIG_BT_MESH_RELAY)) { - feat |= BT_MESH_FEAT_RELAY; + if (IS_ENABLED(CONFIG_BLE_MESH_RELAY)) { + feat |= BLE_MESH_FEAT_RELAY; } - if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) { - feat |= BT_MESH_FEAT_PROXY; + if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY)) { + feat |= BLE_MESH_FEAT_PROXY; } - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { - feat |= BT_MESH_FEAT_FRIEND; + if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) { + feat |= BLE_MESH_FEAT_FRIEND; } - if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) { - feat |= BT_MESH_FEAT_LOW_POWER; + if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER)) { + feat |= BLE_MESH_FEAT_LOW_POWER; } net_buf_simple_add_le16(buf, comp->cid); net_buf_simple_add_le16(buf, comp->pid); net_buf_simple_add_le16(buf, comp->vid); - net_buf_simple_add_le16(buf, CONFIG_BT_MESH_CRPL); + net_buf_simple_add_le16(buf, CONFIG_BLE_MESH_CRPL); net_buf_simple_add_le16(buf, feat); for (i = 0; i < comp->elem_count; i++) { @@ -191,7 +191,7 @@ static void dev_comp_data_get(struct bt_mesh_model *model, page = 0; } - sdu = bt_mesh_alloc_buf(min(BT_MESH_TX_SDU_MAX, COMP_DATA_MAX_LEN)); + 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__); return; @@ -201,13 +201,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("Unable to get composition page 0"); + BT_ERR("%s, Unable to get composition page 0", __func__); bt_mesh_free_buf(sdu); return; } if (bt_mesh_model_send(model, ctx, sdu, NULL, NULL)) { - BT_ERR("Unable to send Device Composition Status response"); + BT_ERR("%s, Unable to send Config Composition Data Status", __func__); } bt_mesh_free_buf(sdu); @@ -233,8 +233,7 @@ static struct bt_mesh_model *get_model(struct bt_mesh_elem *elem, company = net_buf_simple_pull_le16(buf); id = net_buf_simple_pull_le16(buf); - BT_DBG("Company 0x%04x ID 0x%04x addr 0x%04x", company, id, - elem->addr); + BT_DBG("Company 0x%04x ID 0x%04x addr 0x%04x", company, id, elem->addr); *vnd = true; @@ -249,7 +248,7 @@ static bool app_key_is_valid(u16_t app_idx) for (i = 0; i < ARRAY_SIZE(bt_mesh.app_keys); i++) { struct bt_mesh_app_key *key = &bt_mesh.app_keys[i]; - if (key->net_idx != BT_MESH_KEY_UNUSED && + if (key->net_idx != BLE_MESH_KEY_UNUSED && key->app_idx == app_idx) { return true; } @@ -266,7 +265,7 @@ static u8_t _mod_pub_set(struct bt_mesh_model *model, u16_t pub_addr, return STATUS_NVAL_PUB_PARAM; } - if (!IS_ENABLED(CONFIG_BT_MESH_LOW_POWER) && cred_flag) { + if (!IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER) && cred_flag) { return STATUS_FEAT_NOT_SUPP; } @@ -274,8 +273,8 @@ static u8_t _mod_pub_set(struct bt_mesh_model *model, u16_t pub_addr, return STATUS_NVAL_PUB_PARAM; } - if (pub_addr == BT_MESH_ADDR_UNASSIGNED) { - model->pub->addr = BT_MESH_ADDR_UNASSIGNED; + if (pub_addr == BLE_MESH_ADDR_UNASSIGNED) { + model->pub->addr = BLE_MESH_ADDR_UNASSIGNED; model->pub->key = 0; model->pub->cred = 0; model->pub->ttl = 0; @@ -287,7 +286,7 @@ static u8_t _mod_pub_set(struct bt_mesh_model *model, u16_t pub_addr, k_delayed_work_cancel(&model->pub->timer); } - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_mod_pub(model); } @@ -318,7 +317,7 @@ static u8_t _mod_pub_set(struct bt_mesh_model *model, u16_t pub_addr, } } - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_mod_pub(model); } @@ -343,10 +342,10 @@ static u8_t mod_bind(struct bt_mesh_model *model, u16_t key_idx) } for (i = 0; i < ARRAY_SIZE(model->keys); i++) { - if (model->keys[i] == BT_MESH_KEY_UNUSED) { + if (model->keys[i] == BLE_MESH_KEY_UNUSED) { model->keys[i] = key_idx; - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_mod_bind(model); } @@ -372,14 +371,14 @@ static u8_t mod_unbind(struct bt_mesh_model *model, u16_t key_idx) continue; } - model->keys[i] = BT_MESH_KEY_UNUSED; + model->keys[i] = BLE_MESH_KEY_UNUSED; - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_mod_bind(model); } if (model->pub && model->pub->key == key_idx) { - _mod_pub_set(model, BT_MESH_ADDR_UNASSIGNED, + _mod_pub_set(model, BLE_MESH_ADDR_UNASSIGNED, 0, 0, 0, 0, 0); } @@ -396,7 +395,7 @@ struct bt_mesh_app_key *bt_mesh_app_key_alloc(u16_t app_idx) for (i = 0; i < ARRAY_SIZE(bt_mesh.app_keys); i++) { struct bt_mesh_app_key *key = &bt_mesh.app_keys[i]; - if (key->net_idx == BT_MESH_KEY_UNUSED) { + if (key->net_idx == BLE_MESH_KEY_UNUSED) { return key; } } @@ -436,7 +435,7 @@ static u8_t app_key_set(u16_t net_idx, u16_t app_idx, const u8_t val[16], * when the AppKey Update message on a valid AppKeyIndex when * the AppKey value is different. */ - if (sub->kr_phase != BT_MESH_KR_PHASE_1) { + if (sub->kr_phase != BLE_MESH_KR_PHASE_1) { return STATUS_CANNOT_UPDATE; } @@ -485,7 +484,7 @@ static u8_t app_key_set(u16_t net_idx, u16_t app_idx, const u8_t val[16], key->app_idx = app_idx; memcpy(keys->val, val, 16); - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { BT_DBG("Storing AppKey persistently"); bt_mesh_store_app_key(key); } @@ -514,11 +513,11 @@ 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("Unable to send App Key Status response"); + BT_ERR("%s, Unable to send Config AppKey Status", __func__); return; } -#if defined(CONFIG_BT_MESH_FAST_PROV) +#if defined(CONFIG_BLE_MESH_FAST_PROV) bt_mesh_callback_cfg_server_event_to_btc(0x0, model, ctx, (u8_t *)&key_app_idx, sizeof(u16_t)); #endif @@ -545,7 +544,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("Unable to send App Key Status response"); + BT_ERR("%s, Unable to send Config AppKey Status", __func__); } } @@ -561,11 +560,11 @@ void bt_mesh_app_key_del(struct bt_mesh_app_key *key) { bt_mesh_model_foreach(_mod_unbind, &key->app_idx); - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_clear_app_key(key); } - key->net_idx = BT_MESH_KEY_UNUSED; + key->net_idx = BLE_MESH_KEY_UNUSED; memset(key->keys, 0, sizeof(key->keys)); } @@ -612,7 +611,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("Unable to send App Key Status response"); + BT_ERR("%s, Unable to send Config AppKey Status", __func__); } } @@ -625,13 +624,13 @@ static void app_key_get(struct bt_mesh_model *model, { struct net_buf_simple *msg = NET_BUF_SIMPLE(2 + 3 + 4 + - IDX_LEN(CONFIG_BT_MESH_APP_KEY_COUNT)); + IDX_LEN(CONFIG_BLE_MESH_APP_KEY_COUNT)); u16_t get_idx, i, prev; u8_t status; get_idx = net_buf_simple_pull_le16(buf); if (get_idx > 0xfff) { - BT_ERR("Invalid NetKeyIndex 0x%04x", get_idx); + BT_ERR("%s, Invalid NetKeyIndex 0x%04x", __func__, get_idx); return; } @@ -652,7 +651,7 @@ static void app_key_get(struct bt_mesh_model *model, goto send_status; } - prev = BT_MESH_KEY_UNUSED; + prev = BLE_MESH_KEY_UNUSED; for (i = 0; i < ARRAY_SIZE(bt_mesh.app_keys); i++) { struct bt_mesh_app_key *key = &bt_mesh.app_keys[i]; @@ -660,22 +659,22 @@ static void app_key_get(struct bt_mesh_model *model, continue; } - if (prev == BT_MESH_KEY_UNUSED) { + if (prev == BLE_MESH_KEY_UNUSED) { prev = key->app_idx; continue; } key_idx_pack(msg, prev, key->app_idx); - prev = BT_MESH_KEY_UNUSED; + prev = BLE_MESH_KEY_UNUSED; } - if (prev != BT_MESH_KEY_UNUSED) { + if (prev != BLE_MESH_KEY_UNUSED) { net_buf_simple_add_le16(msg, prev); } send_status: if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { - BT_ERR("Unable to send AppKey List"); + BT_ERR("%s, Unable to send Config AppKey List", __func__); } } @@ -694,7 +693,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("Unable to send Config Beacon Status response"); + BT_ERR("%s, Unable to send Config Beacon Status", __func__); } } @@ -715,8 +714,8 @@ static void beacon_set(struct bt_mesh_model *model, } else if (buf->data[0] == 0x00 || buf->data[0] == 0x01) { if (buf->data[0] != cfg->beacon) { cfg->beacon = buf->data[0]; -#if CONFIG_BT_MESH_NODE - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { +#if CONFIG_BLE_MESH_NODE + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_cfg(); } @@ -736,7 +735,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("Unable to send Config Beacon Status response"); + BT_ERR("%s, Unable to send Config Beacon Status", __func__); } } @@ -755,7 +754,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("Unable to send Default TTL Status response"); + BT_ERR("%s, Unable to send Config Default TTL Status", __func__); } } @@ -773,11 +772,11 @@ static void default_ttl_set(struct bt_mesh_model *model, if (!cfg) { BT_WARN("No Configuration Server context available"); - } else if (buf->data[0] <= BT_MESH_TTL_MAX && buf->data[0] != 0x01) { + } else if (buf->data[0] <= BLE_MESH_TTL_MAX && buf->data[0] != 0x01) { if (cfg->default_ttl != buf->data[0]) { cfg->default_ttl = buf->data[0]; - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_cfg(); } } @@ -790,7 +789,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("Unable to send Default TTL Status response"); + BT_ERR("%s, Unable to send Config Default TTL Status", __func__); } } @@ -804,7 +803,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("Unable to send GATT Proxy Status"); + BT_ERR("%s, Unable to send Config GATT Proxy Status", __func__); } } @@ -835,8 +834,8 @@ static void gatt_proxy_set(struct bt_mesh_model *model, return; } - if (!IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY) || - bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_NOT_SUPPORTED) { + if (!IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) || + bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_NOT_SUPPORTED) { goto send_status; } @@ -853,11 +852,11 @@ static void gatt_proxy_set(struct bt_mesh_model *model, cfg->gatt_proxy = buf->data[0]; - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_cfg(); } - if (cfg->gatt_proxy == BT_MESH_GATT_PROXY_DISABLED) { + if (cfg->gatt_proxy == BLE_MESH_GATT_PROXY_DISABLED) { int i; /* Section 4.2.11.1: "When the GATT Proxy state is set to @@ -867,8 +866,8 @@ static void gatt_proxy_set(struct bt_mesh_model *model, for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) { struct bt_mesh_subnet *sub = &bt_mesh.sub[i]; - if (sub->net_idx != BT_MESH_KEY_UNUSED) { -#if CONFIG_BT_MESH_NODE + if (sub->net_idx != BLE_MESH_KEY_UNUSED) { +#if CONFIG_BLE_MESH_NODE bt_mesh_proxy_identity_stop(sub); #endif } @@ -878,7 +877,7 @@ static void gatt_proxy_set(struct bt_mesh_model *model, * to GATT Proxy state 0x00 the GATT Bearer Server shall * disconnect all GATT Bearer Clients. */ -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE bt_mesh_proxy_gatt_disconnect(); #endif } @@ -886,7 +885,7 @@ static void gatt_proxy_set(struct bt_mesh_model *model, bt_mesh_adv_update(); sub = bt_mesh_subnet_get(cfg->hb_pub.net_idx); - if ((cfg->hb_pub.feat & BT_MESH_FEAT_PROXY) && sub) { + if ((cfg->hb_pub.feat & BLE_MESH_FEAT_PROXY) && sub) { hb_send(model); } @@ -909,7 +908,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("Unable to send Config Network Transmit Status"); + BT_ERR("%s, Unable to send Config Network Transmit Status", __func__); } } @@ -926,15 +925,15 @@ static void net_transmit_set(struct bt_mesh_model *model, bt_hex(buf->data, buf->len)); BT_DBG("Transmit 0x%02x (count %u interval %ums)", buf->data[0], - BT_MESH_TRANSMIT_COUNT(buf->data[0]), - BT_MESH_TRANSMIT_INT(buf->data[0])); + BLE_MESH_TRANSMIT_COUNT(buf->data[0]), + BLE_MESH_TRANSMIT_INT(buf->data[0])); if (!cfg) { BT_WARN("No Configuration Server context available"); } else { cfg->net_transmit = buf->data[0]; - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_cfg(); } } @@ -943,7 +942,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("Unable to send Network Transmit Status"); + BT_ERR("%s, Unable to send Config Network Transmit Status", __func__); } } @@ -963,7 +962,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("Unable to send Config Relay Status response"); + BT_ERR("%s, Unable to send Config Relay Status", __func__); } } @@ -985,14 +984,14 @@ static void relay_set(struct bt_mesh_model *model, struct bt_mesh_subnet *sub; bool change; - if (cfg->relay == BT_MESH_RELAY_NOT_SUPPORTED) { + if (cfg->relay == BLE_MESH_RELAY_NOT_SUPPORTED) { change = false; } else { change = (cfg->relay != buf->data[0]); cfg->relay = buf->data[0]; cfg->relay_retransmit = buf->data[1]; - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_cfg(); } } @@ -1000,11 +999,11 @@ static void relay_set(struct bt_mesh_model *model, BT_DBG("Relay 0x%02x (%s) xmit 0x%02x (count %u interval %u)", cfg->relay, change ? "changed" : "not changed", cfg->relay_retransmit, - BT_MESH_TRANSMIT_COUNT(cfg->relay_retransmit), - BT_MESH_TRANSMIT_INT(cfg->relay_retransmit)); + BLE_MESH_TRANSMIT_COUNT(cfg->relay_retransmit), + BLE_MESH_TRANSMIT_INT(cfg->relay_retransmit)); sub = bt_mesh_subnet_get(cfg->hb_pub.net_idx); - if ((cfg->hb_pub.feat & BT_MESH_FEAT_RELAY) && sub && change) { + if ((cfg->hb_pub.feat & BLE_MESH_FEAT_RELAY) && sub && change) { hb_send(model); } } else { @@ -1017,7 +1016,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("Unable to send Relay Status response"); + BT_ERR("%s, Unable to send Config Relay Status", __func__); } } @@ -1056,7 +1055,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("Unable to send Model Publication Status"); + BT_ERR("%s, Unable to send Config Model Publication Status", __func__); } } @@ -1120,8 +1119,8 @@ static void mod_pub_set(struct bt_mesh_model *model, pub_app_idx &= BIT_MASK(12); pub_ttl = net_buf_simple_pull_u8(buf); - if (pub_ttl > BT_MESH_TTL_MAX && pub_ttl != BT_MESH_TTL_DEFAULT) { - BT_ERR("Invalid TTL value 0x%02x", pub_ttl); + if (pub_ttl > BLE_MESH_TTL_MAX && pub_ttl != BLE_MESH_TTL_DEFAULT) { + BT_ERR("%s, Invalid TTL value 0x%02x", __func__, pub_ttl); return; } @@ -1134,8 +1133,8 @@ static void mod_pub_set(struct bt_mesh_model *model, BT_DBG("pub_app_idx 0x%03x, pub_ttl %u pub_period 0x%02x", pub_app_idx, pub_ttl, pub_period); BT_DBG("retransmit 0x%02x (count %u interval %ums)", retransmit, - BT_MESH_PUB_TRANSMIT_COUNT(retransmit), - BT_MESH_PUB_TRANSMIT_INT(retransmit)); + BLE_MESH_PUB_TRANSMIT_COUNT(retransmit), + BLE_MESH_PUB_TRANSMIT_INT(retransmit)); elem = bt_mesh_elem_find(elem_addr); if (!elem) { @@ -1159,7 +1158,7 @@ send_status: status, mod_id); } -#if CONFIG_BT_MESH_LABEL_COUNT > 0 +#if CONFIG_BLE_MESH_LABEL_COUNT > 0 static u8_t va_add(u8_t *label_uuid, u16_t *addr) { struct label *free_slot = NULL; @@ -1209,7 +1208,7 @@ static u8_t va_del(u8_t *label_uuid, u16_t *addr) } if (addr) { - *addr = BT_MESH_ADDR_UNASSIGNED; + *addr = BLE_MESH_ADDR_UNASSIGNED; } return STATUS_CANNOT_REMOVE; @@ -1222,13 +1221,13 @@ static void mod_sub_list_clear(struct bt_mesh_model *mod) /* Unref stored labels related to this model */ for (i = 0; i < ARRAY_SIZE(mod->groups); i++) { - if (!BT_MESH_ADDR_IS_VIRTUAL(mod->groups[i])) { + if (!BLE_MESH_ADDR_IS_VIRTUAL(mod->groups[i])) { continue; } label_uuid = bt_mesh_label_uuid_get(mod->groups[i]); if (!label_uuid) { - BT_ERR("Label UUID not found"); + BT_ERR("%s, Label UUID is not found", __func__); continue; } @@ -1259,8 +1258,8 @@ static void mod_pub_va_set(struct bt_mesh_model *model, cred_flag = ((pub_app_idx >> 12) & BIT_MASK(1)); pub_app_idx &= BIT_MASK(12); pub_ttl = net_buf_simple_pull_u8(buf); - if (pub_ttl > BT_MESH_TTL_MAX && pub_ttl != BT_MESH_TTL_DEFAULT) { - BT_ERR("Invalid TTL value 0x%02x", pub_ttl); + if (pub_ttl > BLE_MESH_TTL_MAX && pub_ttl != BLE_MESH_TTL_DEFAULT) { + BT_ERR("%s, Invalid TTL value 0x%02x", __func__, pub_ttl); return; } @@ -1273,8 +1272,8 @@ static void mod_pub_va_set(struct bt_mesh_model *model, BT_DBG("pub_app_idx 0x%03x, pub_ttl %u pub_period 0x%02x", pub_app_idx, pub_ttl, pub_period); BT_DBG("retransmit 0x%02x (count %u interval %ums)", retransmit, - BT_MESH_PUB_TRANSMIT_COUNT(retransmit), - BT_MESH_PUB_TRANSMIT_INT(retransmit)); + BLE_MESH_PUB_TRANSMIT_COUNT(retransmit), + BLE_MESH_PUB_TRANSMIT_INT(retransmit)); elem = bt_mesh_elem_find(elem_addr); if (!elem) { @@ -1351,7 +1350,7 @@ send_status: send_mod_pub_status(model, ctx, elem_addr, pub_addr, vnd, mod, status, mod_id); } -#endif /* CONFIG_BT_MESH_LABEL_COUNT > 0 */ +#endif /* CONFIG_BLE_MESH_LABEL_COUNT > 0 */ static void send_mod_sub_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, u8_t status, @@ -1377,7 +1376,7 @@ static void send_mod_sub_status(struct bt_mesh_model *model, } if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { - BT_ERR("Unable to send Model Subscription Status"); + BT_ERR("%s, Unable to send Config Model Subscription Status", __func__); } } @@ -1414,7 +1413,7 @@ static void mod_sub_add(struct bt_mesh_model *model, goto send_status; } - if (!BT_MESH_ADDR_IS_GROUP(sub_addr)) { + if (!BLE_MESH_ADDR_IS_GROUP(sub_addr)) { status = STATUS_INVALID_ADDRESS; goto send_status; } @@ -1426,7 +1425,7 @@ static void mod_sub_add(struct bt_mesh_model *model, } for (i = 0; i < ARRAY_SIZE(mod->groups); i++) { - if (mod->groups[i] == BT_MESH_ADDR_UNASSIGNED) { + if (mod->groups[i] == BLE_MESH_ADDR_UNASSIGNED) { mod->groups[i] = sub_addr; break; } @@ -1437,11 +1436,11 @@ static void mod_sub_add(struct bt_mesh_model *model, } else { status = STATUS_SUCCESS; - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_mod_sub(mod); } - if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) { + if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER)) { bt_mesh_lpn_group_add(sub_addr); } } @@ -1484,7 +1483,7 @@ static void mod_sub_del(struct bt_mesh_model *model, goto send_status; } - if (!BT_MESH_ADDR_IS_GROUP(sub_addr)) { + if (!BLE_MESH_ADDR_IS_GROUP(sub_addr)) { status = STATUS_INVALID_ADDRESS; goto send_status; } @@ -1494,15 +1493,15 @@ static void mod_sub_del(struct bt_mesh_model *model, */ status = STATUS_SUCCESS; - if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) { + if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER)) { bt_mesh_lpn_group_del(&sub_addr, 1); } match = bt_mesh_model_find_group(mod, sub_addr); if (match) { - *match = BT_MESH_ADDR_UNASSIGNED; + *match = BLE_MESH_ADDR_UNASSIGNED; - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_mod_sub(mod); } } @@ -1544,12 +1543,12 @@ static void mod_sub_overwrite(struct bt_mesh_model *model, goto send_status; } - if (!BT_MESH_ADDR_IS_GROUP(sub_addr)) { + if (!BLE_MESH_ADDR_IS_GROUP(sub_addr)) { status = STATUS_INVALID_ADDRESS; goto send_status; } - if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) { + if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER)) { bt_mesh_lpn_group_del(mod->groups, ARRAY_SIZE(mod->groups)); } @@ -1559,11 +1558,11 @@ static void mod_sub_overwrite(struct bt_mesh_model *model, mod->groups[0] = sub_addr; status = STATUS_SUCCESS; - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_mod_sub(mod); } - if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) { + if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER)) { bt_mesh_lpn_group_add(sub_addr); } } else { @@ -1607,13 +1606,13 @@ static void mod_sub_del_all(struct bt_mesh_model *model, goto send_status; } - if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) { + if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER)) { bt_mesh_lpn_group_del(mod->groups, ARRAY_SIZE(mod->groups)); } mod_sub_list_clear(mod); - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_mod_sub(mod); } @@ -1621,7 +1620,7 @@ static void mod_sub_del_all(struct bt_mesh_model *model, send_status: send_mod_sub_status(model, ctx, status, elem_addr, - BT_MESH_ADDR_UNASSIGNED, mod_id, vnd); + BLE_MESH_ADDR_UNASSIGNED, mod_id, vnd); } static void mod_sub_get(struct bt_mesh_model *model, @@ -1629,8 +1628,7 @@ static void mod_sub_get(struct bt_mesh_model *model, struct net_buf_simple *buf) { struct net_buf_simple *msg = - NET_BUF_SIMPLE(2 + 5 + 4 + - CONFIG_BT_MESH_MODEL_GROUP_COUNT * 2); + NET_BUF_SIMPLE(2 + 5 + 4 + CONFIG_BLE_MESH_MODEL_GROUP_COUNT * 2); struct bt_mesh_model *mod; struct bt_mesh_elem *elem; u16_t addr, id; @@ -1665,14 +1663,14 @@ static void mod_sub_get(struct bt_mesh_model *model, net_buf_simple_add_le16(msg, id); for (i = 0; i < ARRAY_SIZE(mod->groups); i++) { - if (mod->groups[i] != BT_MESH_ADDR_UNASSIGNED) { + if (mod->groups[i] != BLE_MESH_ADDR_UNASSIGNED) { net_buf_simple_add_le16(msg, mod->groups[i]); } } send_list: if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { - BT_ERR("Unable to send Model Subscription List"); + BT_ERR("%s, Unable to send Config Model Subscription List", __func__); } } @@ -1682,7 +1680,7 @@ static void mod_sub_get_vnd(struct bt_mesh_model *model, { struct net_buf_simple *msg = NET_BUF_SIMPLE(2 + 7 + 4 + - CONFIG_BT_MESH_MODEL_GROUP_COUNT * 2); + CONFIG_BLE_MESH_MODEL_GROUP_COUNT * 2); struct bt_mesh_model *mod; struct bt_mesh_elem *elem; u16_t company, addr, id; @@ -1721,18 +1719,18 @@ static void mod_sub_get_vnd(struct bt_mesh_model *model, net_buf_simple_add_le16(msg, id); for (i = 0; i < ARRAY_SIZE(mod->groups); i++) { - if (mod->groups[i] != BT_MESH_ADDR_UNASSIGNED) { + if (mod->groups[i] != BLE_MESH_ADDR_UNASSIGNED) { net_buf_simple_add_le16(msg, mod->groups[i]); } } send_list: if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { - BT_ERR("Unable to send Vendor Model Subscription List"); + BT_ERR("%s, Unable to send Config Vendor Model Subscription List", __func__); } } -#if CONFIG_BT_MESH_LABEL_COUNT > 0 +#if CONFIG_BLE_MESH_LABEL_COUNT > 0 static void mod_sub_va_add(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) @@ -1757,14 +1755,14 @@ static void mod_sub_va_add(struct bt_mesh_model *model, if (!elem) { mod = NULL; vnd = (buf->len == 4); - sub_addr = BT_MESH_ADDR_UNASSIGNED; + sub_addr = BLE_MESH_ADDR_UNASSIGNED; status = STATUS_INVALID_ADDRESS; goto send_status; } mod = get_model(elem, buf, &vnd); if (!mod) { - sub_addr = BT_MESH_ADDR_UNASSIGNED; + sub_addr = BLE_MESH_ADDR_UNASSIGNED; status = STATUS_INVALID_MODEL; goto send_status; } @@ -1781,7 +1779,7 @@ static void mod_sub_va_add(struct bt_mesh_model *model, } for (i = 0; i < ARRAY_SIZE(mod->groups); i++) { - if (mod->groups[i] == BT_MESH_ADDR_UNASSIGNED) { + if (mod->groups[i] == BLE_MESH_ADDR_UNASSIGNED) { mod->groups[i] = sub_addr; break; } @@ -1790,11 +1788,11 @@ static void mod_sub_va_add(struct bt_mesh_model *model, if (i == ARRAY_SIZE(mod->groups)) { status = STATUS_INSUFF_RESOURCES; } else { - if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) { + if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER)) { bt_mesh_lpn_group_add(sub_addr); } - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_mod_sub(mod); } @@ -1831,32 +1829,32 @@ static void mod_sub_va_del(struct bt_mesh_model *model, if (!elem) { mod = NULL; vnd = (buf->len == 4); - sub_addr = BT_MESH_ADDR_UNASSIGNED; + sub_addr = BLE_MESH_ADDR_UNASSIGNED; status = STATUS_INVALID_ADDRESS; goto send_status; } mod = get_model(elem, buf, &vnd); if (!mod) { - sub_addr = BT_MESH_ADDR_UNASSIGNED; + sub_addr = BLE_MESH_ADDR_UNASSIGNED; status = STATUS_INVALID_MODEL; goto send_status; } status = va_del(label_uuid, &sub_addr); - if (sub_addr == BT_MESH_ADDR_UNASSIGNED) { + if (sub_addr == BLE_MESH_ADDR_UNASSIGNED) { goto send_status; } - if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) { + if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER)) { bt_mesh_lpn_group_del(&sub_addr, 1); } match = bt_mesh_model_find_group(mod, sub_addr); if (match) { - *match = BT_MESH_ADDR_UNASSIGNED; + *match = BLE_MESH_ADDR_UNASSIGNED; - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_mod_sub(mod); } @@ -1874,7 +1872,7 @@ static void mod_sub_va_overwrite(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { - u16_t elem_addr, sub_addr = BT_MESH_ADDR_UNASSIGNED; + u16_t elem_addr, sub_addr = BLE_MESH_ADDR_UNASSIGNED; struct bt_mesh_model *mod; struct bt_mesh_elem *elem; u8_t *label_uuid; @@ -1904,7 +1902,7 @@ static void mod_sub_va_overwrite(struct bt_mesh_model *model, goto send_status; } - if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) { + if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER)) { bt_mesh_lpn_group_del(mod->groups, ARRAY_SIZE(mod->groups)); } @@ -1915,11 +1913,11 @@ static void mod_sub_va_overwrite(struct bt_mesh_model *model, if (status == STATUS_SUCCESS) { mod->groups[0] = sub_addr; - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_mod_sub(mod); } - if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) { + if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER)) { bt_mesh_lpn_group_add(sub_addr); } } @@ -1966,7 +1964,7 @@ static void mod_sub_va_add(struct bt_mesh_model *model, send_status: send_mod_sub_status(model, ctx, status, elem_addr, - BT_MESH_ADDR_UNASSIGNED, mod_id, vnd); + BLE_MESH_ADDR_UNASSIGNED, mod_id, vnd); } static void mod_sub_va_del(struct bt_mesh_model *model, @@ -2000,7 +1998,7 @@ static void mod_sub_va_del(struct bt_mesh_model *model, send_status: send_mod_sub_status(model, ctx, status, elem_addr, - BT_MESH_ADDR_UNASSIGNED, mod_id, vnd); + BLE_MESH_ADDR_UNASSIGNED, mod_id, vnd); } static void mod_sub_va_overwrite(struct bt_mesh_model *model, @@ -2034,9 +2032,9 @@ static void mod_sub_va_overwrite(struct bt_mesh_model *model, send_status: send_mod_sub_status(model, ctx, status, elem_addr, - BT_MESH_ADDR_UNASSIGNED, mod_id, vnd); + BLE_MESH_ADDR_UNASSIGNED, mod_id, vnd); } -#endif /* CONFIG_BT_MESH_LABEL_COUNT > 0 */ +#endif /* CONFIG_BLE_MESH_LABEL_COUNT > 0 */ static void send_net_key_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, @@ -2051,7 +2049,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("Unable to send NetKey Status"); + BT_ERR("%s, Unable to send Config NetKey Status", __func__); } } @@ -2065,7 +2063,7 @@ static void net_key_add(struct bt_mesh_model *model, idx = net_buf_simple_pull_le16(buf); if (idx > 0xfff) { - BT_ERR("Invalid NetKeyIndex 0x%04x", idx); + BT_ERR("%s, Invalid NetKeyIndex 0x%04x", __func__, idx); return; } @@ -2076,7 +2074,7 @@ static void net_key_add(struct bt_mesh_model *model, int i; for (sub = NULL, i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) { - if (bt_mesh.sub[i].net_idx == BT_MESH_KEY_UNUSED) { + if (bt_mesh.sub[i].net_idx == BLE_MESH_KEY_UNUSED) { sub = &bt_mesh.sub[i]; break; } @@ -2111,7 +2109,7 @@ static void net_key_add(struct bt_mesh_model *model, sub->net_idx = idx; - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { BT_DBG("Storing NetKey persistently"); bt_mesh_store_subnet(sub); } @@ -2119,14 +2117,14 @@ static void net_key_add(struct bt_mesh_model *model, /* Make sure we have valid beacon data to be sent */ bt_mesh_net_beacon_update(sub); - if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) { - sub->node_id = BT_MESH_NODE_IDENTITY_STOPPED; -#if CONFIG_BT_MESH_NODE + if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY)) { + sub->node_id = BLE_MESH_NODE_IDENTITY_STOPPED; +#if CONFIG_BLE_MESH_NODE bt_mesh_proxy_beacon_send(sub); #endif bt_mesh_adv_update(); } else { - sub->node_id = BT_MESH_NODE_IDENTITY_NOT_SUPPORTED; + sub->node_id = BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED; } send_net_key_status(model, ctx, idx, STATUS_SUCCESS); @@ -2142,7 +2140,7 @@ static void net_key_update(struct bt_mesh_model *model, idx = net_buf_simple_pull_le16(buf); if (idx > 0xfff) { - BT_ERR("Invalid NetKeyIndex 0x%04x", idx); + BT_ERR("%s, Invalid NetKeyIndex 0x%04x", __func__, idx); return; } @@ -2161,26 +2159,26 @@ static void net_key_update(struct bt_mesh_model *model, * error when the node is in Phase 2, or Phase 3. */ switch (sub->kr_phase) { - case BT_MESH_KR_NORMAL: + case BLE_MESH_KR_NORMAL: if (!memcmp(buf->data, sub->keys[0].net, 16)) { return; } break; - case BT_MESH_KR_PHASE_1: + case BLE_MESH_KR_PHASE_1: if (!memcmp(buf->data, sub->keys[1].net, 16)) { send_net_key_status(model, ctx, idx, STATUS_SUCCESS); return; } /* fall through */ - case BT_MESH_KR_PHASE_2: - case BT_MESH_KR_PHASE_3: + case BLE_MESH_KR_PHASE_2: + case BLE_MESH_KR_PHASE_3: send_net_key_status(model, ctx, idx, STATUS_CANNOT_UPDATE); return; } err = bt_mesh_net_keys_create(&sub->keys[1], buf->data); - if (!err && (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER) || - IS_ENABLED(CONFIG_BT_MESH_FRIEND))) { + if (!err && (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER) || + IS_ENABLED(CONFIG_BLE_MESH_FRIEND))) { err = friend_cred_update(sub); } @@ -2189,9 +2187,9 @@ static void net_key_update(struct bt_mesh_model *model, return; } - sub->kr_phase = BT_MESH_KR_PHASE_1; + sub->kr_phase = BLE_MESH_KR_PHASE_1; - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { BT_DBG("Storing NetKey persistently"); bt_mesh_store_subnet(sub); } @@ -2205,7 +2203,7 @@ static void hb_pub_disable(struct bt_mesh_cfg_srv *cfg) { BT_DBG("%s", __func__); - cfg->hb_pub.dst = BT_MESH_ADDR_UNASSIGNED; + cfg->hb_pub.dst = BLE_MESH_ADDR_UNASSIGNED; cfg->hb_pub.count = 0; cfg->hb_pub.ttl = 0; cfg->hb_pub.period = 0; @@ -2223,7 +2221,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("Invalid NetKeyIndex 0x%04x", del_idx); + BT_ERR("%s, Invalid NetKeyIndex 0x%04x", __func__, del_idx); return; } @@ -2258,34 +2256,34 @@ static void net_key_get(struct bt_mesh_model *model, struct net_buf_simple *buf) { struct net_buf_simple *msg = - NET_BUF_SIMPLE(2 + 4 + IDX_LEN(CONFIG_BT_MESH_SUBNET_COUNT)); + NET_BUF_SIMPLE(2 + 4 + IDX_LEN(CONFIG_BLE_MESH_SUBNET_COUNT)); u16_t prev, i; bt_mesh_model_msg_init(msg, OP_NET_KEY_LIST); - prev = BT_MESH_KEY_UNUSED; + prev = BLE_MESH_KEY_UNUSED; for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) { struct bt_mesh_subnet *sub = &bt_mesh.sub[i]; - if (sub->net_idx == BT_MESH_KEY_UNUSED) { + if (sub->net_idx == BLE_MESH_KEY_UNUSED) { continue; } - if (prev == BT_MESH_KEY_UNUSED) { + if (prev == BLE_MESH_KEY_UNUSED) { prev = sub->net_idx; continue; } key_idx_pack(msg, prev, sub->net_idx); - prev = BT_MESH_KEY_UNUSED; + prev = BLE_MESH_KEY_UNUSED; } - if (prev != BT_MESH_KEY_UNUSED) { + if (prev != BLE_MESH_KEY_UNUSED) { net_buf_simple_add_le16(msg, prev); } if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { - BT_ERR("Unable to send NetKey List"); + BT_ERR("%s, Unable to send Config NetKey List", __func__); } } @@ -2305,7 +2303,7 @@ static void node_identity_get(struct bt_mesh_model *model, idx = net_buf_simple_pull_le16(buf); if (idx > 0xfff) { - BT_ERR("Invalid NetKeyIndex 0x%04x", idx); + BT_ERR("%s, Invalid NetKeyIndex 0x%04x", __func__, idx); return; } @@ -2324,7 +2322,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("Unable to send Node Identity Status"); + BT_ERR("%s, Unable to send Config Node Identity Status", __func__); } } @@ -2344,13 +2342,13 @@ static void node_identity_set(struct bt_mesh_model *model, idx = net_buf_simple_pull_le16(buf); if (idx > 0xfff) { - BT_WARN("Invalid NetKeyIndex 0x%04x", idx); + BT_WARN("%s, Invalid NetKeyIndex 0x%04x", __func__, idx); return; } node_id = net_buf_simple_pull_u8(buf); if (node_id != 0x00 && node_id != 0x01) { - BT_WARN("Invalid Node ID value 0x%02x", node_id); + BT_WARN("%s, Invalid Node ID value 0x%02x", __func__, node_id); return; } @@ -2369,9 +2367,9 @@ static void node_identity_set(struct bt_mesh_model *model, * 0x00, the Node Identity state for all subnets shall be set * to 0x00 and shall not be changed." */ - if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY) && - bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED) { -#if CONFIG_BT_MESH_NODE + if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) && + bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_ENABLED) { +#if CONFIG_BLE_MESH_NODE if (node_id) { bt_mesh_proxy_identity_start(sub); } else { @@ -2385,7 +2383,7 @@ static void node_identity_set(struct bt_mesh_model *model, } if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { - BT_ERR("Unable to send Node Identity Status"); + BT_ERR("%s, Unable to send Config Node Identity Status", __func__); } } @@ -2438,7 +2436,7 @@ static void mod_app_bind(struct bt_mesh_model *model, /* Configuration Server only allows device key based access */ if (model == mod) { - BT_ERR("Client tried to bind AppKey to Configuration Model"); + BT_ERR("%s, Tried to bind AppKey with Configuration Model", __func__); status = STATUS_CANNOT_BIND; goto send_status; } @@ -2451,7 +2449,7 @@ send_status: mod_id); if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { - BT_ERR("Unable to send Model App Bind Status response"); + BT_ERR("%s, Unable to send Config Model App Bind Status", __func__); } } @@ -2492,11 +2490,11 @@ send_status: mod_id); if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { - BT_ERR("Unable to send Model App Unbind Status response"); + BT_ERR("%s, Unable to send Config Model App Unbind Status", __func__); } } -#define KEY_LIST_LEN (CONFIG_BT_MESH_MODEL_KEY_COUNT * 2) +#define KEY_LIST_LEN (CONFIG_BLE_MESH_MODEL_KEY_COUNT * 2) static void mod_app_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, @@ -2550,14 +2548,14 @@ send_list: int i; for (i = 0; i < ARRAY_SIZE(mod->keys); i++) { - if (mod->keys[i] != BT_MESH_KEY_UNUSED) { + if (mod->keys[i] != BLE_MESH_KEY_UNUSED) { net_buf_simple_add_le16(msg, mod->keys[i]); } } } if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { - BT_ERR("Unable to send Model Application List message"); + BT_ERR("%s, Unable to send Config Model Application List", __func__); } } @@ -2579,10 +2577,10 @@ static void node_reset(struct bt_mesh_model *model, * send it later. */ if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { - BT_ERR("Unable to send Node Reset Status"); + BT_ERR("%s, Unable to send Config Node Reset Status", __func__); } -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE bt_mesh_reset(); #endif } @@ -2598,7 +2596,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("Unable to send Friend Status"); + BT_ERR("%s, Unable to send Config Friend Status", __func__); } } @@ -2640,20 +2638,20 @@ static void friend_set(struct bt_mesh_model *model, goto send_status; } - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { + if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) { cfg->frnd = buf->data[0]; - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_cfg(); } - if (cfg->frnd == BT_MESH_FRIEND_DISABLED) { - bt_mesh_friend_clear_net_idx(BT_MESH_KEY_ANY); + if (cfg->frnd == BLE_MESH_FRIEND_DISABLED) { + bt_mesh_friend_clear_net_idx(BLE_MESH_KEY_ANY); } } sub = bt_mesh_subnet_get(cfg->hb_pub.net_idx); - if ((cfg->hb_pub.feat & BT_MESH_FEAT_FRIEND) && sub) { + if ((cfg->hb_pub.feat & BLE_MESH_FEAT_FRIEND) && sub) { hb_send(model); } @@ -2676,7 +2674,7 @@ static void lpn_timeout_get(struct bt_mesh_model *model, BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x lpn_addr 0x%02x", ctx->net_idx, ctx->app_idx, ctx->addr, lpn_addr); - if (!BT_MESH_ADDR_IS_UNICAST(lpn_addr)) { + if (!BLE_MESH_ADDR_IS_UNICAST(lpn_addr)) { BT_WARN("Invalid LPNAddress; ignoring msg"); return; } @@ -2689,7 +2687,7 @@ static void lpn_timeout_get(struct bt_mesh_model *model, goto send_rsp; } - frnd = bt_mesh_friend_find(BT_MESH_KEY_ANY, lpn_addr, true, true); + frnd = bt_mesh_friend_find(BLE_MESH_KEY_ANY, lpn_addr, true, true); if (!frnd) { timeout = 0; goto send_rsp; @@ -2703,7 +2701,7 @@ send_rsp: net_buf_simple_add_u8(msg, timeout >> 16); if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { - BT_ERR("Unable to send LPN PollTimeout Status"); + BT_ERR("%s, Unable to send Config LPN PollTimeout Status", __func__); } } @@ -2721,7 +2719,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("Unable to send Key Refresh State Status"); + BT_ERR("%s, Unable to send Config Key Refresh Phase Status", __func__); } } @@ -2733,7 +2731,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("Invalid NetKeyIndex 0x%04x", idx); + BT_ERR("%s, Invalid NetKeyIndex 0x%04x", __func__, idx); return; } @@ -2743,8 +2741,7 @@ static void krp_get(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, if (!sub) { send_krp_status(model, ctx, idx, 0x00, STATUS_INVALID_NETKEY); } else { - send_krp_status(model, ctx, idx, sub->kr_phase, - STATUS_SUCCESS); + send_krp_status(model, ctx, idx, sub->kr_phase, STATUS_SUCCESS); } } @@ -2759,7 +2756,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("Invalid NetKeyIndex 0x%04x", idx); + BT_ERR("%s, Invalid NetKeyIndex 0x%04x", __func__, idx); return; } @@ -2773,27 +2770,27 @@ static void krp_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, BT_DBG("%u -> %u", sub->kr_phase, phase); - if (phase < BT_MESH_KR_PHASE_2 || phase > BT_MESH_KR_PHASE_3 || - (sub->kr_phase == BT_MESH_KR_NORMAL && - phase == BT_MESH_KR_PHASE_2)) { - BT_WARN("Prohibited transition %u -> %u", sub->kr_phase, phase); + 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); return; } - if (sub->kr_phase == BT_MESH_KR_PHASE_1 && - phase == BT_MESH_KR_PHASE_2) { - sub->kr_phase = BT_MESH_KR_PHASE_2; + if (sub->kr_phase == BLE_MESH_KR_PHASE_1 && + phase == BLE_MESH_KR_PHASE_2) { + sub->kr_phase = BLE_MESH_KR_PHASE_2; sub->kr_flag = 1; bt_mesh_net_beacon_update(sub); - } else if ((sub->kr_phase == BT_MESH_KR_PHASE_1 || - sub->kr_phase == BT_MESH_KR_PHASE_2) && - phase == BT_MESH_KR_PHASE_3) { + } else if ((sub->kr_phase == BLE_MESH_KR_PHASE_1 || + sub->kr_phase == BLE_MESH_KR_PHASE_2) && + phase == BLE_MESH_KR_PHASE_3) { bt_mesh_net_revoke_keys(sub); - if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER) || - IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { + if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER) || + IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) { friend_cred_refresh(ctx->net_idx); } - sub->kr_phase = BT_MESH_KR_NORMAL; + sub->kr_phase = BLE_MESH_KR_NORMAL; sub->kr_flag = 0; bt_mesh_net_beacon_update(sub); } @@ -2874,7 +2871,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("Unable to send Heartbeat Publication Status"); + BT_ERR("%s, Unable to send Config Heartbeat Publication Status", __func__); } } @@ -2900,7 +2897,7 @@ static void heartbeat_pub_set(struct bt_mesh_model *model, dst = sys_le16_to_cpu(param->dst); /* All address types are valid, except for virtual ones */ - if (BT_MESH_ADDR_IS_VIRTUAL(dst)) { + if (BLE_MESH_ADDR_IS_VIRTUAL(dst)) { status = STATUS_INVALID_ADDRESS; goto failed; } @@ -2915,8 +2912,8 @@ static void heartbeat_pub_set(struct bt_mesh_model *model, goto failed; } - if (param->ttl > BT_MESH_TTL_MAX && param->ttl != BT_MESH_TTL_DEFAULT) { - BT_ERR("Invalid TTL value 0x%02x", param->ttl); + if (param->ttl > BLE_MESH_TTL_MAX && param->ttl != BLE_MESH_TTL_DEFAULT) { + BT_ERR("%s, Invalid TTL value 0x%02x", __func__, param->ttl); return; } @@ -2924,7 +2921,7 @@ static void heartbeat_pub_set(struct bt_mesh_model *model, idx = sys_le16_to_cpu(param->net_idx); if (idx > 0xfff) { - BT_ERR("Invalid NetKeyIndex 0x%04x", idx); + BT_ERR("%s, Invalid NetKeyIndex 0x%04x", __func__, idx); return; } @@ -2938,7 +2935,7 @@ static void heartbeat_pub_set(struct bt_mesh_model *model, cfg->hb_pub.feat = feat; cfg->hb_pub.net_idx = idx; - if (dst == BT_MESH_ADDR_UNASSIGNED) { + if (dst == BLE_MESH_ADDR_UNASSIGNED) { hb_pub_disable(cfg); } else { /* 2^(n-1) */ @@ -2961,7 +2958,7 @@ static void heartbeat_pub_set(struct bt_mesh_model *model, #endif } - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_hb_pub(); } @@ -2971,7 +2968,7 @@ static void heartbeat_pub_set(struct bt_mesh_model *model, * as possible after the Heartbeat Publication Period state * has been configured for periodic publishing. */ - if (dst != BT_MESH_ADDR_UNASSIGNED) { + if (dst != BLE_MESH_ADDR_UNASSIGNED) { if (param->period_log && param->count_log) { k_work_submit(&cfg->hb_pub.timer.work); } else { @@ -3010,8 +3007,8 @@ static void hb_sub_send_status(struct bt_mesh_model *model, net_buf_simple_add_le16(msg, cfg->hb_sub.src); net_buf_simple_add_le16(msg, cfg->hb_sub.dst); - if (cfg->hb_sub.src == BT_MESH_ADDR_UNASSIGNED || - cfg->hb_sub.dst == BT_MESH_ADDR_UNASSIGNED) { + if (cfg->hb_sub.src == BLE_MESH_ADDR_UNASSIGNED || + cfg->hb_sub.dst == BLE_MESH_ADDR_UNASSIGNED) { memset(net_buf_simple_add(msg, 4), 0, 4); } else { net_buf_simple_add_u8(msg, hb_log(period)); @@ -3021,7 +3018,7 @@ static void hb_sub_send_status(struct bt_mesh_model *model, } if (bt_mesh_model_send(model, ctx, msg, NULL, NULL)) { - BT_ERR("Unable to send Heartbeat Subscription Status"); + BT_ERR("%s, Unable to send Config Heartbeat Subscription Status", __func__); } } @@ -3052,14 +3049,14 @@ static void heartbeat_sub_set(struct bt_mesh_model *model, BT_DBG("sub_src 0x%04x sub_dst 0x%04x period 0x%02x", sub_src, sub_dst, sub_period); - if (sub_src != BT_MESH_ADDR_UNASSIGNED && - !BT_MESH_ADDR_IS_UNICAST(sub_src)) { + if (sub_src != BLE_MESH_ADDR_UNASSIGNED && + !BLE_MESH_ADDR_IS_UNICAST(sub_src)) { BT_WARN("Prohibited source address"); return; } - if (BT_MESH_ADDR_IS_VIRTUAL(sub_dst) || BT_MESH_ADDR_IS_RFU(sub_dst) || - (BT_MESH_ADDR_IS_UNICAST(sub_dst) && + if (BLE_MESH_ADDR_IS_VIRTUAL(sub_dst) || BLE_MESH_ADDR_IS_RFU(sub_dst) || + (BLE_MESH_ADDR_IS_UNICAST(sub_dst) && sub_dst != bt_mesh_primary_addr())) { BT_WARN("Prohibited destination address"); return; @@ -3070,22 +3067,22 @@ static void heartbeat_sub_set(struct bt_mesh_model *model, return; } - if (sub_src == BT_MESH_ADDR_UNASSIGNED || - sub_dst == BT_MESH_ADDR_UNASSIGNED || + if (sub_src == BLE_MESH_ADDR_UNASSIGNED || + sub_dst == BLE_MESH_ADDR_UNASSIGNED || sub_period == 0x00) { /* Setting the same addresses with zero period should retain * the addresses according to MESH/NODE/CFG/HBS/BV-02-C. */ if (cfg->hb_sub.src != sub_src || cfg->hb_sub.dst != sub_dst) { - cfg->hb_sub.src = BT_MESH_ADDR_UNASSIGNED; - cfg->hb_sub.dst = BT_MESH_ADDR_UNASSIGNED; + cfg->hb_sub.src = BLE_MESH_ADDR_UNASSIGNED; + cfg->hb_sub.dst = BLE_MESH_ADDR_UNASSIGNED; } period_ms = 0; } else { cfg->hb_sub.src = sub_src; cfg->hb_sub.dst = sub_dst; - cfg->hb_sub.min_hops = BT_MESH_TTL_MAX; + cfg->hb_sub.min_hops = BLE_MESH_TTL_MAX; cfg->hb_sub.max_hops = 0; cfg->hb_sub.count = 0; period_ms = hb_pwr2(sub_period, 1) * 1000; @@ -3153,7 +3150,7 @@ const struct bt_mesh_model_op bt_mesh_cfg_srv_op[] = { { OP_HEARTBEAT_PUB_SET, 9, heartbeat_pub_set }, { OP_HEARTBEAT_SUB_GET, 0, heartbeat_sub_get }, { OP_HEARTBEAT_SUB_SET, 5, heartbeat_sub_set }, - BT_MESH_MODEL_OP_END, + BLE_MESH_MODEL_OP_END, }; static void hb_publish(struct k_work *work) @@ -3169,9 +3166,8 @@ static void hb_publish(struct k_work *work) sub = bt_mesh_subnet_get(cfg->hb_pub.net_idx); if (!sub) { - BT_ERR("No matching subnet for idx 0x%02x", - cfg->hb_pub.net_idx); - cfg->hb_pub.dst = BT_MESH_ADDR_UNASSIGNED; + BT_ERR("%s, No matching subnet for idx 0x%02x", __func__, cfg->hb_pub.net_idx); + cfg->hb_pub.dst = BLE_MESH_ADDR_UNASSIGNED; return; } @@ -3201,7 +3197,7 @@ static bool conf_is_valid(struct bt_mesh_cfg_srv *cfg) return false; } - if (cfg->default_ttl > BT_MESH_TTL_MAX) { + if (cfg->default_ttl > BLE_MESH_TTL_MAX) { return false; } @@ -3213,31 +3209,33 @@ 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("No Configuration Server context provided"); + BT_ERR("%s, No Configuration Server context provided", __func__); return -EINVAL; } - BT_DBG("%s, net_transmit = %d, relay = %d, relay_retransmit = %d, beacon = %d, gatt_proxy = %d, frnd = %d, default_ttl = %d", - __func__, cfg->net_transmit, cfg->relay, cfg->relay_retransmit, cfg->beacon, cfg->gatt_proxy, cfg->frnd, cfg->default_ttl); + BT_DBG("%s, net_transmit = %d, relay = %d, relay_retransmit = %d", + __func__, cfg->net_transmit, cfg->relay, cfg->relay_retransmit); + BT_DBG("%s, beacon = %d, gatt_proxy = %d, frnd = %d, default_ttl = %d", + __func__, cfg->beacon, cfg->gatt_proxy, cfg->frnd, cfg->default_ttl); if (!conf_is_valid(cfg)) { - BT_ERR("Invalid values in configuration"); + BT_ERR("%s, Invalid values in configuration", __func__); return -EINVAL; } /* Configuration Model security is device-key based */ - model->keys[0] = BT_MESH_KEY_DEV; + model->keys[0] = BLE_MESH_KEY_DEV; - if (!IS_ENABLED(CONFIG_BT_MESH_RELAY)) { - cfg->relay = BT_MESH_RELAY_NOT_SUPPORTED; + if (!IS_ENABLED(CONFIG_BLE_MESH_RELAY)) { + cfg->relay = BLE_MESH_RELAY_NOT_SUPPORTED; } - if (!IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { - cfg->frnd = BT_MESH_FRIEND_NOT_SUPPORTED; + if (!IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) { + cfg->frnd = BLE_MESH_FRIEND_NOT_SUPPORTED; } - if (!IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) { - cfg->gatt_proxy = BT_MESH_GATT_PROXY_NOT_SUPPORTED; + if (!IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY)) { + cfg->gatt_proxy = BLE_MESH_GATT_PROXY_NOT_SUPPORTED; } k_delayed_work_init(&cfg->hb_pub.timer, hb_publish); @@ -3261,7 +3259,7 @@ static void mod_reset(struct bt_mesh_model *mod, struct bt_mesh_elem *elem, mod_sub_list_clear(mod); - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_mod_sub(mod); } } @@ -3275,10 +3273,10 @@ void bt_mesh_cfg_reset(void) return; } - bt_mesh_set_hb_sub_dst(BT_MESH_ADDR_UNASSIGNED); + bt_mesh_set_hb_sub_dst(BLE_MESH_ADDR_UNASSIGNED); - cfg->hb_sub.src = BT_MESH_ADDR_UNASSIGNED; - cfg->hb_sub.dst = BT_MESH_ADDR_UNASSIGNED; + cfg->hb_sub.src = BLE_MESH_ADDR_UNASSIGNED; + cfg->hb_sub.dst = BLE_MESH_ADDR_UNASSIGNED; cfg->hb_sub.expiry = 0; /* Delete all net keys, which also takes care of all app keys which @@ -3287,7 +3285,7 @@ void bt_mesh_cfg_reset(void) for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) { struct bt_mesh_subnet *sub = &bt_mesh.sub[i]; - if (sub->net_idx != BT_MESH_KEY_UNUSED) { + if (sub->net_idx != BLE_MESH_KEY_UNUSED) { bt_mesh_subnet_del(sub); } } @@ -3316,8 +3314,8 @@ void bt_mesh_heartbeat(u16_t src, u16_t dst, u8_t hops, u16_t feat) return; } - cfg->hb_sub.min_hops = min(cfg->hb_sub.min_hops, hops); - cfg->hb_sub.max_hops = max(cfg->hb_sub.max_hops, hops); + cfg->hb_sub.min_hops = MIN(cfg->hb_sub.min_hops, hops); + cfg->hb_sub.max_hops = MAX(cfg->hb_sub.max_hops, hops); if (cfg->hb_sub.count < 0xffff) { cfg->hb_sub.count++; @@ -3347,7 +3345,7 @@ u8_t bt_mesh_relay_get(void) return conf->relay; } - return BT_MESH_RELAY_NOT_SUPPORTED; + return BLE_MESH_RELAY_NOT_SUPPORTED; } u8_t bt_mesh_friend_get(void) @@ -3357,7 +3355,7 @@ u8_t bt_mesh_friend_get(void) return conf->frnd; } - return BT_MESH_FRIEND_NOT_SUPPORTED; + return BLE_MESH_FRIEND_NOT_SUPPORTED; } u8_t bt_mesh_relay_retransmit_get(void) @@ -3375,7 +3373,7 @@ u8_t bt_mesh_beacon_get(void) return conf->beacon; } - return BT_MESH_BEACON_DISABLED; + return BLE_MESH_BEACON_DISABLED; } u8_t bt_mesh_gatt_proxy_get(void) @@ -3384,7 +3382,7 @@ u8_t bt_mesh_gatt_proxy_get(void) return conf->gatt_proxy; } - return BT_MESH_GATT_PROXY_NOT_SUPPORTED; + return BLE_MESH_GATT_PROXY_NOT_SUPPORTED; } u8_t bt_mesh_default_ttl_get(void) @@ -3436,7 +3434,7 @@ void bt_mesh_subnet_del(struct bt_mesh_subnet *sub) if (conf && conf->hb_pub.net_idx == sub->net_idx) { hb_pub_disable(conf); - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_hb_pub(); } } @@ -3450,16 +3448,14 @@ void bt_mesh_subnet_del(struct bt_mesh_subnet *sub) } } - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { + if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) { bt_mesh_friend_clear_net_idx(sub->net_idx); } - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_clear_subnet(sub); } memset(sub, 0, sizeof(*sub)); - sub->net_idx = BT_MESH_KEY_UNUSED; + sub->net_idx = BLE_MESH_KEY_UNUSED; } - -#endif /* #if CONFIG_BT_MESH */ diff --git a/components/bt/ble_mesh/mesh_core/crypto.c b/components/bt/ble_mesh/mesh_core/crypto.c index a0b1cb2493..99ebbf7716 100644 --- a/components/bt/ble_mesh/mesh_core/crypto.c +++ b/components/bt/ble_mesh/mesh_core/crypto.c @@ -10,22 +10,21 @@ #include #include #include + +#include "sdkconfig.h" +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_CRYPTO) + #include "mesh_types.h" #include "mesh_util.h" -#include "sdkconfig.h" #include "mesh_buf.h" - -#if CONFIG_BT_MESH - -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_CRYPTO) #include "mesh_trace.h" - -#include "mesh.h" -#include "crypto.h" #include "mesh_bearer_adapt.h" #include "mesh_aes_encrypt.h" -#define NET_MIC_LEN(pdu) (((pdu)[1] & 0x80) ? 8 : 4) +#include "mesh.h" +#include "crypto.h" + +#define NET_MIC_LEN(pdu) (((pdu)[1] & 0x80) ? 8 : 4) #define APP_MIC_LEN(aszmic) ((aszmic) ? 8 : 4) int bt_mesh_aes_cmac(const u8_t key[16], struct bt_mesh_sg *sg, @@ -216,7 +215,7 @@ static int bt_mesh_ccm_decrypt(const u8_t key[16], u8_t nonce[13], memcpy(pmsg + 1, nonce, 13); sys_put_be16(0x0000, pmsg + 14); - err = bt_encrypt_be(key, pmsg, cmic); + err = bt_mesh_encrypt_be(key, pmsg, cmic); if (err) { return err; } @@ -231,7 +230,7 @@ static int bt_mesh_ccm_decrypt(const u8_t key[16], u8_t nonce[13], memcpy(pmsg + 1, nonce, 13); sys_put_be16(msg_len, pmsg + 14); - err = bt_encrypt_be(key, pmsg, Xn); + err = bt_mesh_encrypt_be(key, pmsg, Xn); if (err) { return err; } @@ -255,7 +254,7 @@ static int bt_mesh_ccm_decrypt(const u8_t key[16], u8_t nonce[13], aad_len -= 16; i = 0; - err = bt_encrypt_be(key, pmsg, Xn); + err = bt_mesh_encrypt_be(key, pmsg, Xn); if (err) { return err; } @@ -269,7 +268,7 @@ static int bt_mesh_ccm_decrypt(const u8_t key[16], u8_t nonce[13], pmsg[i] = Xn[i]; } - err = bt_encrypt_be(key, pmsg, Xn); + err = bt_mesh_encrypt_be(key, pmsg, Xn); if (err) { return err; } @@ -288,7 +287,7 @@ static int bt_mesh_ccm_decrypt(const u8_t key[16], u8_t nonce[13], memcpy(pmsg + 1, nonce, 13); sys_put_be16(j + 1, pmsg + 14); - err = bt_encrypt_be(key, pmsg, cmsg); + err = bt_mesh_encrypt_be(key, pmsg, cmsg); if (err) { return err; } @@ -309,7 +308,7 @@ static int bt_mesh_ccm_decrypt(const u8_t key[16], u8_t nonce[13], pmsg[i] = Xn[i] ^ 0x00; } - err = bt_encrypt_be(key, pmsg, Xn); + err = bt_mesh_encrypt_be(key, pmsg, Xn); if (err) { return err; } @@ -324,7 +323,7 @@ static int bt_mesh_ccm_decrypt(const u8_t key[16], u8_t nonce[13], memcpy(pmsg + 1, nonce, 13); sys_put_be16(j + 1, pmsg + 14); - err = bt_encrypt_be(key, pmsg, cmsg); + err = bt_mesh_encrypt_be(key, pmsg, cmsg); if (err) { return err; } @@ -341,7 +340,7 @@ static int bt_mesh_ccm_decrypt(const u8_t key[16], u8_t nonce[13], pmsg[i] = Xn[i] ^ msg[i]; } - err = bt_encrypt_be(key, pmsg, Xn); + err = bt_mesh_encrypt_be(key, pmsg, Xn); if (err) { return err; } @@ -380,7 +379,7 @@ static int bt_mesh_ccm_encrypt(const u8_t key[16], u8_t nonce[13], memcpy(pmsg + 1, nonce, 13); sys_put_be16(0x0000, pmsg + 14); - err = bt_encrypt_be(key, pmsg, cmic); + err = bt_mesh_encrypt_be(key, pmsg, cmic); if (err) { return err; } @@ -395,7 +394,7 @@ static int bt_mesh_ccm_encrypt(const u8_t key[16], u8_t nonce[13], memcpy(pmsg + 1, nonce, 13); sys_put_be16(msg_len, pmsg + 14); - err = bt_encrypt_be(key, pmsg, Xn); + err = bt_mesh_encrypt_be(key, pmsg, Xn); if (err) { return err; } @@ -419,7 +418,7 @@ static int bt_mesh_ccm_encrypt(const u8_t key[16], u8_t nonce[13], aad_len -= 16; i = 0; - err = bt_encrypt_be(key, pmsg, Xn); + err = bt_mesh_encrypt_be(key, pmsg, Xn); if (err) { return err; } @@ -433,7 +432,7 @@ static int bt_mesh_ccm_encrypt(const u8_t key[16], u8_t nonce[13], pmsg[i] = Xn[i]; } - err = bt_encrypt_be(key, pmsg, Xn); + err = bt_mesh_encrypt_be(key, pmsg, Xn); if (err) { return err; } @@ -455,7 +454,7 @@ static int bt_mesh_ccm_encrypt(const u8_t key[16], u8_t nonce[13], pmsg[i] = Xn[i] ^ 0x00; } - err = bt_encrypt_be(key, pmsg, Xn); + err = bt_mesh_encrypt_be(key, pmsg, Xn); if (err) { return err; } @@ -470,7 +469,7 @@ static int bt_mesh_ccm_encrypt(const u8_t key[16], u8_t nonce[13], memcpy(pmsg + 1, nonce, 13); sys_put_be16(j + 1, pmsg + 14); - err = bt_encrypt_be(key, pmsg, cmsg); + err = bt_mesh_encrypt_be(key, pmsg, cmsg); if (err) { return err; } @@ -486,7 +485,7 @@ static int bt_mesh_ccm_encrypt(const u8_t key[16], u8_t nonce[13], pmsg[i] = Xn[i] ^ msg[(j * 16) + i]; } - err = bt_encrypt_be(key, pmsg, Xn); + err = bt_mesh_encrypt_be(key, pmsg, Xn); if (err) { return err; } @@ -496,7 +495,7 @@ static int bt_mesh_ccm_encrypt(const u8_t key[16], u8_t nonce[13], memcpy(pmsg + 1, nonce, 13); sys_put_be16(j + 1, pmsg + 14); - err = bt_encrypt_be(key, pmsg, cmsg); + err = bt_mesh_encrypt_be(key, pmsg, cmsg); if (err) { return err; } @@ -515,7 +514,7 @@ static int bt_mesh_ccm_encrypt(const u8_t key[16], u8_t nonce[13], return 0; } -#if defined(CONFIG_BT_MESH_PROXY) +#if defined(CONFIG_BLE_MESH_PROXY) static void create_proxy_nonce(u8_t nonce[13], const u8_t *pdu, u32_t iv_index) { @@ -583,7 +582,7 @@ int bt_mesh_net_obfuscate(u8_t *pdu, u32_t iv_index, BT_DBG("PrivacyRandom %s", bt_hex(priv_rand, 16)); - err = bt_encrypt_be(privacy_key, priv_rand, tmp); + err = bt_mesh_encrypt_be(privacy_key, priv_rand, tmp); if (err) { return err; } @@ -606,7 +605,7 @@ int bt_mesh_net_encrypt(const u8_t key[16], struct net_buf_simple *buf, mic_len); BT_DBG("PDU (len %u) %s", buf->len, bt_hex(buf->data, buf->len)); -#if defined(CONFIG_BT_MESH_PROXY) +#if defined(CONFIG_BLE_MESH_PROXY) if (proxy) { create_proxy_nonce(nonce, buf->data, iv_index); } else { @@ -637,7 +636,7 @@ int bt_mesh_net_decrypt(const u8_t key[16], struct net_buf_simple *buf, BT_DBG("iv_index %u, key %s mic_len %u", iv_index, bt_hex(key, 16), mic_len); -#if defined(CONFIG_BT_MESH_PROXY) +#if defined(CONFIG_BLE_MESH_PROXY) if (proxy) { create_proxy_nonce(nonce, buf->data, iv_index); } else { @@ -844,7 +843,7 @@ int bt_mesh_prov_decrypt(const u8_t key[16], u8_t nonce[13], return bt_mesh_ccm_decrypt(key, nonce, data, 25, NULL, 0, out, 8); } -#if CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_PROVISIONER int bt_mesh_prov_encrypt(const u8_t key[16], u8_t nonce[13], const u8_t data[25], u8_t out[33]) { @@ -876,5 +875,3 @@ int bt_mesh_beacon_auth(const u8_t beacon_key[16], u8_t flags, return err; } - -#endif /* #if CONFIG_BT_MESH */ \ No newline at end of file diff --git a/components/bt/ble_mesh/mesh_core/crypto.h b/components/bt/ble_mesh/mesh_core/crypto.h index 314872e327..3351aed376 100644 --- a/components/bt/ble_mesh/mesh_core/crypto.h +++ b/components/bt/ble_mesh/mesh_core/crypto.h @@ -7,6 +7,9 @@ * SPDX-License-Identifier: Apache-2.0 */ +#ifndef _CRYPTO_H_ +#define _CRYPTO_H_ + #include "mesh_types.h" #include @@ -36,10 +39,10 @@ static inline bool bt_mesh_s1(const char *m, u8_t salt[16]) int bt_mesh_k1(const u8_t *ikm, size_t ikm_len, const u8_t salt[16], const char *info, u8_t okm[16]); -#define bt_mesh_k1_str(ikm, ikm_len, salt_str, info, okm) \ -({ \ - const u8_t salt[16] = salt_str; \ - bt_mesh_k1(ikm, ikm_len, salt, info, okm); \ +#define bt_mesh_k1_str(ikm, ikm_len, salt_str, info, okm) \ +({ \ + const u8_t salt[16] = salt_str; \ + bt_mesh_k1(ikm, ikm_len, salt, info, okm); \ }) int bt_mesh_k2(const u8_t n[16], const u8_t *p, size_t p_len, @@ -157,7 +160,9 @@ int bt_mesh_prov_conf(const u8_t conf_key[16], const u8_t rand[16], int bt_mesh_prov_decrypt(const u8_t key[16], u8_t nonce[13], const u8_t data[25 + 8], u8_t out[25]); -#if CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_PROVISIONER int bt_mesh_prov_encrypt(const u8_t key[16], u8_t nonce[13], const u8_t data[25], u8_t out[33]); #endif + +#endif /* _CRYPTO_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/dlist.c b/components/bt/ble_mesh/mesh_core/dlist.c deleted file mode 100644 index e690a0c291..0000000000 --- a/components/bt/ble_mesh/mesh_core/dlist.c +++ /dev/null @@ -1,319 +0,0 @@ -/* - * Copyright (c) 2017 Intel Corporation - * Additional Copyright (c) 2018 Espressif Systems (Shanghai) PTE LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "dlist.h" -#include "sdkconfig.h" - -#if CONFIG_BT_MESH - -static sys_dlist_t test_list; - -struct container_node { - sys_dnode_t node; - int unused; -}; - -static struct container_node test_node_1; -static struct container_node test_node_2; -static struct container_node test_node_3; -static struct container_node test_node_4; - -static inline bool verify_emptyness(sys_dlist_t *list) -{ - sys_dnode_t *node; - sys_dnode_t *s_node; - struct container_node *cnode; - struct container_node *s_cnode; - int count; - - if (!sys_dlist_is_empty(list)) { - return false; - } - - if (sys_dlist_peek_head(list)) { - return false; - } - - if (sys_dlist_peek_tail(list)) { - return false; - } - - count = 0; - SYS_DLIST_FOR_EACH_NODE(list, node) { - count++; - } - - if (count) { - return false; - } - - SYS_DLIST_FOR_EACH_NODE_SAFE(list, node, s_node) { - count++; - } - - if (count) { - return false; - } - - count = 0; - SYS_DLIST_FOR_EACH_CONTAINER(list, cnode, node) { - count++; - } - - if (count) { - return false; - } - - count = 0; - SYS_DLIST_FOR_EACH_CONTAINER_SAFE(list, cnode, s_cnode, node) { - count++; - } - - if (count) { - return false; - } - - return true; -} - -static inline bool verify_content_amount(sys_dlist_t *list, int amount) -{ - sys_dnode_t *node; - sys_dnode_t *s_node; - struct container_node *cnode; - struct container_node *s_cnode; - int count; - - if (sys_dlist_is_empty(list)) { - return false; - } - - if (!sys_dlist_peek_head(list)) { - return false; - } - - if (!sys_dlist_peek_tail(list)) { - return false; - } - - count = 0; - SYS_DLIST_FOR_EACH_NODE(list, node) { - count++; - } - - if (count != amount) { - return false; - } - - count = 0; - SYS_DLIST_FOR_EACH_NODE_SAFE(list, node, s_node) { - count++; - } - - if (count != amount) { - return false; - } - - count = 0; - SYS_DLIST_FOR_EACH_CONTAINER(list, cnode, node) { - count++; - } - - if (count != amount) { - return false; - } - - count = 0; - SYS_DLIST_FOR_EACH_CONTAINER_SAFE(list, cnode, s_cnode, node) { - count++; - } - - if (count != amount) { - return false; - } - - return true; -} - -static inline bool verify_tail_head(sys_dlist_t *list, - sys_dnode_t *head, - sys_dnode_t *tail, - bool same) -{ - if (sys_dlist_peek_head(list) != head) { - return false; - } - - if (sys_dlist_peek_tail(list) != tail) { - return false; - } - - if (same) { - if (sys_dlist_peek_head(list) != sys_dlist_peek_tail(list)) { - return false; - } - } else { - if (sys_dlist_peek_head(list) == sys_dlist_peek_tail(list)) { - return false; - } - } - - return true; -} - -void dlist_test(void) -{ - sys_dlist_init(&test_list); - - //zassert_true((verify_emptyness(&test_list)), "test_list should be empty"); - - /* Appending node 1 */ - sys_dlist_append(&test_list, &test_node_1.node); - //zassert_true((verify_content_amount(&test_list, 1)), - // "test_list has wrong content"); - - //zassert_true((verify_tail_head(&test_list, &test_node_1.node, - // &test_node_1.node, true)), - // "test_list head/tail are wrong"); - - /* Finding and removing node 1 */ - sys_dlist_remove(&test_node_1.node); - //zassert_true((verify_emptyness(&test_list)), - // "test_list should be empty"); - - /* Prepending node 1 */ - sys_dlist_prepend(&test_list, &test_node_1.node); - //zassert_true((verify_content_amount(&test_list, 1)), - // "test_list has wrong content"); - - //zassert_true((verify_tail_head(&test_list, &test_node_1.node, - // &test_node_1.node, true)), - // "test_list head/tail are wrong"); - - /* Removing node 1 */ - sys_dlist_remove(&test_node_1.node); - //zassert_true((verify_emptyness(&test_list)), - // "test_list should be empty"); - - /* Appending node 1 */ - sys_dlist_append(&test_list, &test_node_1.node); - /* Prepending node 2 */ - sys_dlist_prepend(&test_list, &test_node_2.node); - - //zassert_true((verify_content_amount(&test_list, 2)), - // "test_list has wrong content"); - - //zassert_true((verify_tail_head(&test_list, &test_node_2.node, - // &test_node_1.node, false)), - // "test_list head/tail are wrong"); - - /* Appending node 3 */ - sys_dlist_append(&test_list, &test_node_3.node); - - //zassert_true((verify_content_amount(&test_list, 3)), - // "test_list has wrong content"); - - //zassert_true((verify_tail_head(&test_list, &test_node_2.node, - // &test_node_3.node, false)), - // "test_list head/tail are wrong"); - - //zassert_true((sys_dlist_peek_next(&test_list, &test_node_2.node) == - // &test_node_1.node), - // "test_list node links are wrong"); - - /* Inserting node 4 after node 2 */ - sys_dlist_insert_after(&test_list, &test_node_2.node, - &test_node_4.node); - - //zassert_true((verify_tail_head(&test_list, &test_node_2.node, - // &test_node_3.node, false)), - // "test_list head/tail are wrong"); - - //zassert_true((sys_dlist_peek_next(&test_list, &test_node_2.node) == - // &test_node_4.node), - // "test_list node links are wrong"); - - /* Finding and removing node 1 */ - sys_dlist_remove(&test_node_1.node); - //zassert_true((verify_content_amount(&test_list, 3)), - // "test_list has wrong content"); - - //zassert_true((verify_tail_head(&test_list, &test_node_2.node, - // &test_node_3.node, false)), - // "test_list head/tail are wrong"); - - /* Removing node 3 */ - sys_dlist_remove(&test_node_3.node); - //zassert_true((verify_content_amount(&test_list, 2)), - // "test_list has wrong content"); - - //zassert_true((verify_tail_head(&test_list, &test_node_2.node, - // &test_node_4.node, false)), - // "test_list head/tail are wrong"); - - /* Removing node 4 */ - sys_dlist_remove(&test_node_4.node); - //zassert_true((verify_content_amount(&test_list, 1)), - // "test_list has wrong content"); - - //zassert_true((verify_tail_head(&test_list, &test_node_2.node, - // &test_node_2.node, true)), - // "test_list head/tail are wrong"); - - /* Removing node 2 */ - sys_dlist_remove(&test_node_2.node); - //zassert_true((verify_emptyness(&test_list)), - // "test_list should be empty"); - - /* test iterator from a node */ - struct data_node { - sys_dnode_t node; - int data; - } data_node[6] = { - { .data = 0 }, - { .data = 1 }, - { .data = 2 }, - { .data = 3 }, - { .data = 4 }, - { .data = 5 }, - }; - sys_dnode_t *node = NULL; - int ii; - - sys_dlist_init(&test_list); - - for (ii = 0; ii < 6; ii++) { - sys_dlist_append(&test_list, &data_node[ii].node); - } - - ii = 0; - SYS_DLIST_ITERATE_FROM_NODE(&test_list, node) { - ii++; - if (((struct data_node *)node)->data == 2) { - break; - } - } - //zassert_equal(ii, 3, ""); - - ii = 0; - SYS_DLIST_ITERATE_FROM_NODE(&test_list, node) { - ii++; - if (((struct data_node *)node)->data == 3) { - break; - } - } - //zassert_equal(ii, 1, ""); - - ii = 0; - SYS_DLIST_ITERATE_FROM_NODE(&test_list, node) { - ii++; - } - //zassert_equal(ii, 2, ""); -} - -#endif /* #if CONFIG_BT_MESH */ - diff --git a/components/bt/ble_mesh/mesh_core/foundation.h b/components/bt/ble_mesh/mesh_core/foundation.h index de90b71a4c..ce1120765d 100644 --- a/components/bt/ble_mesh/mesh_core/foundation.h +++ b/components/bt/ble_mesh/mesh_core/foundation.h @@ -7,95 +7,96 @@ */ #ifndef _FOUNDATION_H_ #define _FOUNDATION_H_ + #include "mesh_access.h" #include "net.h" -#define OP_APP_KEY_ADD BT_MESH_MODEL_OP_1(0x00) -#define OP_APP_KEY_UPDATE BT_MESH_MODEL_OP_1(0x01) -#define OP_DEV_COMP_DATA_STATUS BT_MESH_MODEL_OP_1(0x02) -#define OP_MOD_PUB_SET BT_MESH_MODEL_OP_1(0x03) -#define OP_HEALTH_CURRENT_STATUS BT_MESH_MODEL_OP_1(0x04) -#define OP_HEALTH_FAULT_STATUS BT_MESH_MODEL_OP_1(0x05) -#define OP_HEARTBEAT_PUB_STATUS BT_MESH_MODEL_OP_1(0x06) -#define OP_APP_KEY_DEL BT_MESH_MODEL_OP_2(0x80, 0x00) -#define OP_APP_KEY_GET BT_MESH_MODEL_OP_2(0x80, 0x01) -#define OP_APP_KEY_LIST BT_MESH_MODEL_OP_2(0x80, 0x02) -#define OP_APP_KEY_STATUS BT_MESH_MODEL_OP_2(0x80, 0x03) -#define OP_ATTENTION_GET BT_MESH_MODEL_OP_2(0x80, 0x04) -#define OP_ATTENTION_SET BT_MESH_MODEL_OP_2(0x80, 0x05) -#define OP_ATTENTION_SET_UNREL BT_MESH_MODEL_OP_2(0x80, 0x06) -#define OP_ATTENTION_STATUS BT_MESH_MODEL_OP_2(0x80, 0x07) -#define OP_DEV_COMP_DATA_GET BT_MESH_MODEL_OP_2(0x80, 0x08) -#define OP_BEACON_GET BT_MESH_MODEL_OP_2(0x80, 0x09) -#define OP_BEACON_SET BT_MESH_MODEL_OP_2(0x80, 0x0a) -#define OP_BEACON_STATUS BT_MESH_MODEL_OP_2(0x80, 0x0b) -#define OP_DEFAULT_TTL_GET BT_MESH_MODEL_OP_2(0x80, 0x0c) -#define OP_DEFAULT_TTL_SET BT_MESH_MODEL_OP_2(0x80, 0x0d) -#define OP_DEFAULT_TTL_STATUS BT_MESH_MODEL_OP_2(0x80, 0x0e) -#define OP_FRIEND_GET BT_MESH_MODEL_OP_2(0x80, 0x0f) -#define OP_FRIEND_SET BT_MESH_MODEL_OP_2(0x80, 0x10) -#define OP_FRIEND_STATUS BT_MESH_MODEL_OP_2(0x80, 0x11) -#define OP_GATT_PROXY_GET BT_MESH_MODEL_OP_2(0x80, 0x12) -#define OP_GATT_PROXY_SET BT_MESH_MODEL_OP_2(0x80, 0x13) -#define OP_GATT_PROXY_STATUS BT_MESH_MODEL_OP_2(0x80, 0x14) -#define OP_KRP_GET BT_MESH_MODEL_OP_2(0x80, 0x15) -#define OP_KRP_SET BT_MESH_MODEL_OP_2(0x80, 0x16) -#define OP_KRP_STATUS BT_MESH_MODEL_OP_2(0x80, 0x17) -#define OP_MOD_PUB_GET BT_MESH_MODEL_OP_2(0x80, 0x18) -#define OP_MOD_PUB_STATUS BT_MESH_MODEL_OP_2(0x80, 0x19) -#define OP_MOD_PUB_VA_SET BT_MESH_MODEL_OP_2(0x80, 0x1a) -#define OP_MOD_SUB_ADD BT_MESH_MODEL_OP_2(0x80, 0x1b) -#define OP_MOD_SUB_DEL BT_MESH_MODEL_OP_2(0x80, 0x1c) -#define OP_MOD_SUB_DEL_ALL BT_MESH_MODEL_OP_2(0x80, 0x1d) -#define OP_MOD_SUB_OVERWRITE BT_MESH_MODEL_OP_2(0x80, 0x1e) -#define OP_MOD_SUB_STATUS BT_MESH_MODEL_OP_2(0x80, 0x1f) -#define OP_MOD_SUB_VA_ADD BT_MESH_MODEL_OP_2(0x80, 0x20) -#define OP_MOD_SUB_VA_DEL BT_MESH_MODEL_OP_2(0x80, 0x21) -#define OP_MOD_SUB_VA_OVERWRITE BT_MESH_MODEL_OP_2(0x80, 0x22) -#define OP_NET_TRANSMIT_GET BT_MESH_MODEL_OP_2(0x80, 0x23) -#define OP_NET_TRANSMIT_SET BT_MESH_MODEL_OP_2(0x80, 0x24) -#define OP_NET_TRANSMIT_STATUS BT_MESH_MODEL_OP_2(0x80, 0x25) -#define OP_RELAY_GET BT_MESH_MODEL_OP_2(0x80, 0x26) -#define OP_RELAY_SET BT_MESH_MODEL_OP_2(0x80, 0x27) -#define OP_RELAY_STATUS BT_MESH_MODEL_OP_2(0x80, 0x28) -#define OP_MOD_SUB_GET BT_MESH_MODEL_OP_2(0x80, 0x29) -#define OP_MOD_SUB_LIST BT_MESH_MODEL_OP_2(0x80, 0x2a) -#define OP_MOD_SUB_GET_VND BT_MESH_MODEL_OP_2(0x80, 0x2b) -#define OP_MOD_SUB_LIST_VND BT_MESH_MODEL_OP_2(0x80, 0x2c) -#define OP_LPN_TIMEOUT_GET BT_MESH_MODEL_OP_2(0x80, 0x2d) -#define OP_LPN_TIMEOUT_STATUS BT_MESH_MODEL_OP_2(0x80, 0x2e) -#define OP_HEALTH_FAULT_CLEAR BT_MESH_MODEL_OP_2(0x80, 0x2f) -#define OP_HEALTH_FAULT_CLEAR_UNREL BT_MESH_MODEL_OP_2(0x80, 0x30) -#define OP_HEALTH_FAULT_GET BT_MESH_MODEL_OP_2(0x80, 0x31) -#define OP_HEALTH_FAULT_TEST BT_MESH_MODEL_OP_2(0x80, 0x32) -#define OP_HEALTH_FAULT_TEST_UNREL BT_MESH_MODEL_OP_2(0x80, 0x33) -#define OP_HEALTH_PERIOD_GET BT_MESH_MODEL_OP_2(0x80, 0x34) -#define OP_HEALTH_PERIOD_SET BT_MESH_MODEL_OP_2(0x80, 0x35) -#define OP_HEALTH_PERIOD_SET_UNREL BT_MESH_MODEL_OP_2(0x80, 0x36) -#define OP_HEALTH_PERIOD_STATUS BT_MESH_MODEL_OP_2(0x80, 0x37) -#define OP_HEARTBEAT_PUB_GET BT_MESH_MODEL_OP_2(0x80, 0x38) -#define OP_HEARTBEAT_PUB_SET BT_MESH_MODEL_OP_2(0x80, 0x39) -#define OP_HEARTBEAT_SUB_GET BT_MESH_MODEL_OP_2(0x80, 0x3a) -#define OP_HEARTBEAT_SUB_SET BT_MESH_MODEL_OP_2(0x80, 0x3b) -#define OP_HEARTBEAT_SUB_STATUS BT_MESH_MODEL_OP_2(0x80, 0x3c) -#define OP_MOD_APP_BIND BT_MESH_MODEL_OP_2(0x80, 0x3d) -#define OP_MOD_APP_STATUS BT_MESH_MODEL_OP_2(0x80, 0x3e) -#define OP_MOD_APP_UNBIND BT_MESH_MODEL_OP_2(0x80, 0x3f) -#define OP_NET_KEY_ADD BT_MESH_MODEL_OP_2(0x80, 0x40) -#define OP_NET_KEY_DEL BT_MESH_MODEL_OP_2(0x80, 0x41) -#define OP_NET_KEY_GET BT_MESH_MODEL_OP_2(0x80, 0x42) -#define OP_NET_KEY_LIST BT_MESH_MODEL_OP_2(0x80, 0x43) -#define OP_NET_KEY_STATUS BT_MESH_MODEL_OP_2(0x80, 0x44) -#define OP_NET_KEY_UPDATE BT_MESH_MODEL_OP_2(0x80, 0x45) -#define OP_NODE_IDENTITY_GET BT_MESH_MODEL_OP_2(0x80, 0x46) -#define OP_NODE_IDENTITY_SET BT_MESH_MODEL_OP_2(0x80, 0x47) -#define OP_NODE_IDENTITY_STATUS BT_MESH_MODEL_OP_2(0x80, 0x48) -#define OP_NODE_RESET BT_MESH_MODEL_OP_2(0x80, 0x49) -#define OP_NODE_RESET_STATUS BT_MESH_MODEL_OP_2(0x80, 0x4a) -#define OP_SIG_MOD_APP_GET BT_MESH_MODEL_OP_2(0x80, 0x4b) -#define OP_SIG_MOD_APP_LIST BT_MESH_MODEL_OP_2(0x80, 0x4c) -#define OP_VND_MOD_APP_GET BT_MESH_MODEL_OP_2(0x80, 0x4d) -#define OP_VND_MOD_APP_LIST BT_MESH_MODEL_OP_2(0x80, 0x4e) +#define OP_APP_KEY_ADD BLE_MESH_MODEL_OP_1(0x00) +#define OP_APP_KEY_UPDATE BLE_MESH_MODEL_OP_1(0x01) +#define OP_DEV_COMP_DATA_STATUS BLE_MESH_MODEL_OP_1(0x02) +#define OP_MOD_PUB_SET BLE_MESH_MODEL_OP_1(0x03) +#define OP_HEALTH_CURRENT_STATUS BLE_MESH_MODEL_OP_1(0x04) +#define OP_HEALTH_FAULT_STATUS BLE_MESH_MODEL_OP_1(0x05) +#define OP_HEARTBEAT_PUB_STATUS BLE_MESH_MODEL_OP_1(0x06) +#define OP_APP_KEY_DEL BLE_MESH_MODEL_OP_2(0x80, 0x00) +#define OP_APP_KEY_GET BLE_MESH_MODEL_OP_2(0x80, 0x01) +#define OP_APP_KEY_LIST BLE_MESH_MODEL_OP_2(0x80, 0x02) +#define OP_APP_KEY_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x03) +#define OP_ATTENTION_GET BLE_MESH_MODEL_OP_2(0x80, 0x04) +#define OP_ATTENTION_SET BLE_MESH_MODEL_OP_2(0x80, 0x05) +#define OP_ATTENTION_SET_UNREL BLE_MESH_MODEL_OP_2(0x80, 0x06) +#define OP_ATTENTION_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x07) +#define OP_DEV_COMP_DATA_GET BLE_MESH_MODEL_OP_2(0x80, 0x08) +#define OP_BEACON_GET BLE_MESH_MODEL_OP_2(0x80, 0x09) +#define OP_BEACON_SET BLE_MESH_MODEL_OP_2(0x80, 0x0a) +#define OP_BEACON_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x0b) +#define OP_DEFAULT_TTL_GET BLE_MESH_MODEL_OP_2(0x80, 0x0c) +#define OP_DEFAULT_TTL_SET BLE_MESH_MODEL_OP_2(0x80, 0x0d) +#define OP_DEFAULT_TTL_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x0e) +#define OP_FRIEND_GET BLE_MESH_MODEL_OP_2(0x80, 0x0f) +#define OP_FRIEND_SET BLE_MESH_MODEL_OP_2(0x80, 0x10) +#define OP_FRIEND_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x11) +#define OP_GATT_PROXY_GET BLE_MESH_MODEL_OP_2(0x80, 0x12) +#define OP_GATT_PROXY_SET BLE_MESH_MODEL_OP_2(0x80, 0x13) +#define OP_GATT_PROXY_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x14) +#define OP_KRP_GET BLE_MESH_MODEL_OP_2(0x80, 0x15) +#define OP_KRP_SET BLE_MESH_MODEL_OP_2(0x80, 0x16) +#define OP_KRP_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x17) +#define OP_MOD_PUB_GET BLE_MESH_MODEL_OP_2(0x80, 0x18) +#define OP_MOD_PUB_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x19) +#define OP_MOD_PUB_VA_SET BLE_MESH_MODEL_OP_2(0x80, 0x1a) +#define OP_MOD_SUB_ADD BLE_MESH_MODEL_OP_2(0x80, 0x1b) +#define OP_MOD_SUB_DEL BLE_MESH_MODEL_OP_2(0x80, 0x1c) +#define OP_MOD_SUB_DEL_ALL BLE_MESH_MODEL_OP_2(0x80, 0x1d) +#define OP_MOD_SUB_OVERWRITE BLE_MESH_MODEL_OP_2(0x80, 0x1e) +#define OP_MOD_SUB_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x1f) +#define OP_MOD_SUB_VA_ADD BLE_MESH_MODEL_OP_2(0x80, 0x20) +#define OP_MOD_SUB_VA_DEL BLE_MESH_MODEL_OP_2(0x80, 0x21) +#define OP_MOD_SUB_VA_OVERWRITE BLE_MESH_MODEL_OP_2(0x80, 0x22) +#define OP_NET_TRANSMIT_GET BLE_MESH_MODEL_OP_2(0x80, 0x23) +#define OP_NET_TRANSMIT_SET BLE_MESH_MODEL_OP_2(0x80, 0x24) +#define OP_NET_TRANSMIT_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x25) +#define OP_RELAY_GET BLE_MESH_MODEL_OP_2(0x80, 0x26) +#define OP_RELAY_SET BLE_MESH_MODEL_OP_2(0x80, 0x27) +#define OP_RELAY_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x28) +#define OP_MOD_SUB_GET BLE_MESH_MODEL_OP_2(0x80, 0x29) +#define OP_MOD_SUB_LIST BLE_MESH_MODEL_OP_2(0x80, 0x2a) +#define OP_MOD_SUB_GET_VND BLE_MESH_MODEL_OP_2(0x80, 0x2b) +#define OP_MOD_SUB_LIST_VND BLE_MESH_MODEL_OP_2(0x80, 0x2c) +#define OP_LPN_TIMEOUT_GET BLE_MESH_MODEL_OP_2(0x80, 0x2d) +#define OP_LPN_TIMEOUT_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x2e) +#define OP_HEALTH_FAULT_CLEAR BLE_MESH_MODEL_OP_2(0x80, 0x2f) +#define OP_HEALTH_FAULT_CLEAR_UNREL BLE_MESH_MODEL_OP_2(0x80, 0x30) +#define OP_HEALTH_FAULT_GET BLE_MESH_MODEL_OP_2(0x80, 0x31) +#define OP_HEALTH_FAULT_TEST BLE_MESH_MODEL_OP_2(0x80, 0x32) +#define OP_HEALTH_FAULT_TEST_UNREL BLE_MESH_MODEL_OP_2(0x80, 0x33) +#define OP_HEALTH_PERIOD_GET BLE_MESH_MODEL_OP_2(0x80, 0x34) +#define OP_HEALTH_PERIOD_SET BLE_MESH_MODEL_OP_2(0x80, 0x35) +#define OP_HEALTH_PERIOD_SET_UNREL BLE_MESH_MODEL_OP_2(0x80, 0x36) +#define OP_HEALTH_PERIOD_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x37) +#define OP_HEARTBEAT_PUB_GET BLE_MESH_MODEL_OP_2(0x80, 0x38) +#define OP_HEARTBEAT_PUB_SET BLE_MESH_MODEL_OP_2(0x80, 0x39) +#define OP_HEARTBEAT_SUB_GET BLE_MESH_MODEL_OP_2(0x80, 0x3a) +#define OP_HEARTBEAT_SUB_SET BLE_MESH_MODEL_OP_2(0x80, 0x3b) +#define OP_HEARTBEAT_SUB_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x3c) +#define OP_MOD_APP_BIND BLE_MESH_MODEL_OP_2(0x80, 0x3d) +#define OP_MOD_APP_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x3e) +#define OP_MOD_APP_UNBIND BLE_MESH_MODEL_OP_2(0x80, 0x3f) +#define OP_NET_KEY_ADD BLE_MESH_MODEL_OP_2(0x80, 0x40) +#define OP_NET_KEY_DEL BLE_MESH_MODEL_OP_2(0x80, 0x41) +#define OP_NET_KEY_GET BLE_MESH_MODEL_OP_2(0x80, 0x42) +#define OP_NET_KEY_LIST BLE_MESH_MODEL_OP_2(0x80, 0x43) +#define OP_NET_KEY_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x44) +#define OP_NET_KEY_UPDATE BLE_MESH_MODEL_OP_2(0x80, 0x45) +#define OP_NODE_IDENTITY_GET BLE_MESH_MODEL_OP_2(0x80, 0x46) +#define OP_NODE_IDENTITY_SET BLE_MESH_MODEL_OP_2(0x80, 0x47) +#define OP_NODE_IDENTITY_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x48) +#define OP_NODE_RESET BLE_MESH_MODEL_OP_2(0x80, 0x49) +#define OP_NODE_RESET_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x4a) +#define OP_SIG_MOD_APP_GET BLE_MESH_MODEL_OP_2(0x80, 0x4b) +#define OP_SIG_MOD_APP_LIST BLE_MESH_MODEL_OP_2(0x80, 0x4c) +#define OP_VND_MOD_APP_GET BLE_MESH_MODEL_OP_2(0x80, 0x4d) +#define OP_VND_MOD_APP_LIST BLE_MESH_MODEL_OP_2(0x80, 0x4e) #define STATUS_SUCCESS 0x00 #define STATUS_INVALID_ADDRESS 0x01 @@ -162,4 +163,4 @@ static inline void key_idx_unpack(struct net_buf_simple *buf, net_buf_simple_pull(buf, 3); } -#endif /* #ifndef _FOUNDATION_H_ */ +#endif /* _FOUNDATION_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/friend.c b/components/bt/ble_mesh/mesh_core/friend.c index f7f26754a4..ec8db9d943 100644 --- a/components/bt/ble_mesh/mesh_core/friend.c +++ b/components/bt/ble_mesh/mesh_core/friend.c @@ -9,39 +9,39 @@ #include #include -#include "mesh_buf.h" #include "sdkconfig.h" -#if CONFIG_BT_MESH +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_FRIEND) + +#include "mesh_buf.h" #include "mesh_util.h" #include "mesh_main.h" -#ifdef CONFIG_BT_MESH_FRIEND -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_FRIEND) #include "mesh_trace.h" +#include "mesh.h" #include "crypto.h" #include "adv.h" -#include "mesh.h" #include "net.h" #include "transport.h" #include "access.h" #include "foundation.h" #include "friend.h" -#define FRIEND_BUF_SIZE (BT_MESH_ADV_DATA_SIZE - BT_MESH_NET_HDR_LEN) +#ifdef CONFIG_BLE_MESH_FRIEND + +#define FRIEND_BUF_SIZE (BLE_MESH_ADV_DATA_SIZE - BLE_MESH_NET_HDR_LEN) /* We reserve one extra buffer for each friendship, since we need to be able * to resend the last sent PDU, which sits separately outside of the queue. */ -#define FRIEND_BUF_COUNT ((CONFIG_BT_MESH_FRIEND_QUEUE_SIZE + 1) * \ - CONFIG_BT_MESH_FRIEND_LPN_COUNT) +#define FRIEND_BUF_COUNT ((CONFIG_BLE_MESH_FRIEND_QUEUE_SIZE + 1) * \ + CONFIG_BLE_MESH_FRIEND_LPN_COUNT) -#define FRIEND_ADV(buf) CONTAINER_OF(BT_MESH_ADV(buf), \ - struct friend_adv, adv) +#define FRIEND_ADV(buf) CONTAINER_OF(BLE_MESH_ADV(buf), struct friend_adv, adv) /* PDUs from Friend to the LPN should only be transmitted once with the * smallest possible interval (20ms). */ -#define FRIEND_XMIT BT_MESH_TRANSMIT(0, 20) +#define FRIEND_XMIT BLE_MESH_TRANSMIT(0, 20) struct friend_pdu_info { u16_t src; @@ -56,7 +56,7 @@ struct friend_pdu_info { }; NET_BUF_POOL_DEFINE(friend_buf_pool, FRIEND_BUF_COUNT, - BT_MESH_ADV_DATA_SIZE, BT_MESH_ADV_USER_DATA_SIZE, NULL); + BLE_MESH_ADV_DATA_SIZE, BLE_MESH_ADV_USER_DATA_SIZE, NULL); static struct friend_adv { struct bt_mesh_adv adv; @@ -83,7 +83,7 @@ static void discard_buffer(void) buf = net_buf_slist_get(&frnd->queue); __ASSERT_NO_MSG(buf != NULL); - BT_WARN("Discarding buffer %p for LPN 0x%04x", buf, frnd->lpn); + BT_WARN("%s, Discarding buffer %p for LPN 0x%04x", __func__, buf, frnd->lpn); net_buf_unref(buf); } @@ -95,16 +95,16 @@ static struct net_buf *friend_buf_alloc(u16_t src) do { buf = bt_mesh_adv_create_from_pool(&friend_buf_pool, adv_alloc, - BT_MESH_ADV_DATA, - BT_MESH_TRANSMIT_COUNT(FRIEND_XMIT), - BT_MESH_TRANSMIT_INT(FRIEND_XMIT), + BLE_MESH_ADV_DATA, + BLE_MESH_TRANSMIT_COUNT(FRIEND_XMIT), + BLE_MESH_TRANSMIT_INT(FRIEND_XMIT), K_NO_WAIT); if (!buf) { discard_buffer(); } } while (!buf); - BT_MESH_ADV(buf)->addr = src; + BLE_MESH_ADV(buf)->addr = src; FRIEND_ADV(buf)->seq_auth = TRANS_SEQ_AUTH_NVAL; BT_DBG("allocated buf %p", buf); @@ -114,7 +114,7 @@ static struct net_buf *friend_buf_alloc(u16_t src) static bool is_lpn_unicast(struct bt_mesh_friend *frnd, u16_t addr) { - if (frnd->lpn == BT_MESH_ADDR_UNASSIGNED) { + if (frnd->lpn == BLE_MESH_ADDR_UNASSIGNED) { return false; } @@ -139,7 +139,7 @@ struct bt_mesh_friend *bt_mesh_friend_find(u16_t net_idx, u16_t lpn_addr, continue; } - if (net_idx != BT_MESH_KEY_ANY && frnd->net_idx != net_idx) { + if (net_idx != BLE_MESH_KEY_ANY && frnd->net_idx != net_idx) { continue; } @@ -158,8 +158,8 @@ struct bt_mesh_friend *bt_mesh_friend_find(u16_t net_idx, u16_t lpn_addr, */ static s32_t recv_delay(struct bt_mesh_friend *frnd) { -#if CONFIG_BT_MESH_FRIEND_RECV_WIN > 50 - return (s32_t)frnd->recv_delay + (CONFIG_BT_MESH_FRIEND_RECV_WIN / 5); +#if CONFIG_BLE_MESH_FRIEND_RECV_WIN > 50 + return (s32_t)frnd->recv_delay + (CONFIG_BLE_MESH_FRIEND_RECV_WIN / 5); #else return frnd->recv_delay; #endif @@ -178,7 +178,7 @@ static void friend_clear(struct bt_mesh_friend *frnd) if (frnd->last) { /* Cancel the sending if necessary */ if (frnd->pending_buf) { - BT_MESH_ADV(frnd->last)->busy = 0; + BLE_MESH_ADV(frnd->last)->busy = 0; } net_buf_unref(frnd->last); @@ -215,11 +215,11 @@ void bt_mesh_friend_clear_net_idx(u16_t net_idx) for (i = 0; i < ARRAY_SIZE(bt_mesh.frnd); i++) { struct bt_mesh_friend *frnd = &bt_mesh.frnd[i]; - if (frnd->net_idx == BT_MESH_KEY_UNUSED) { + if (frnd->net_idx == BLE_MESH_KEY_UNUSED) { continue; } - if (net_idx == BT_MESH_KEY_ANY || frnd->net_idx == net_idx) { + if (net_idx == BLE_MESH_KEY_ANY || frnd->net_idx == net_idx) { friend_clear(frnd); } } @@ -234,11 +234,11 @@ void bt_mesh_friend_sec_update(u16_t net_idx) for (i = 0; i < ARRAY_SIZE(bt_mesh.frnd); i++) { struct bt_mesh_friend *frnd = &bt_mesh.frnd[i]; - if (frnd->net_idx == BT_MESH_KEY_UNUSED) { + if (frnd->net_idx == BLE_MESH_KEY_UNUSED) { continue; } - if (net_idx == BT_MESH_KEY_ANY || frnd->net_idx == net_idx) { + if (net_idx == BLE_MESH_KEY_ANY || frnd->net_idx == net_idx) { frnd->sec_update = 1; } } @@ -258,7 +258,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; if (buf->len < sizeof(*msg)) { - BT_WARN("Too short Friend Clear"); + BT_WARN("%s, Too short Friend Clear", __func__); return -EINVAL; } @@ -269,7 +269,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("No matching LPN addr 0x%04x", lpn_addr); + BT_WARN("%s, No matching LPN addr 0x%04x", __func__, lpn_addr); return 0; } @@ -280,12 +280,12 @@ 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("LPN Counter out of range (old %u new %u)", - frnd->lpn_counter, lpn_counter); + BT_WARN("%s, LPN Counter out of range (old %u new %u)", + __func__, frnd->lpn_counter, lpn_counter); return 0; } - tx.ctx->send_ttl = BT_MESH_TTL_MAX; + tx.ctx->send_ttl = BLE_MESH_TTL_MAX; cfm.lpn_addr = msg->lpn_addr; cfm.lpn_counter = msg->lpn_counter; @@ -303,13 +303,13 @@ static void friend_sub_add(struct bt_mesh_friend *frnd, u16_t addr) int i; for (i = 0; i < ARRAY_SIZE(frnd->sub_list); i++) { - if (frnd->sub_list[i] == BT_MESH_ADDR_UNASSIGNED) { + if (frnd->sub_list[i] == BLE_MESH_ADDR_UNASSIGNED) { frnd->sub_list[i] = addr; return; } } - BT_WARN("No space in friend subscription list"); + BT_WARN("%s, No space in friend subscription list", __func__); } static void friend_sub_rem(struct bt_mesh_friend *frnd, u16_t addr) @@ -318,7 +318,7 @@ static void friend_sub_rem(struct bt_mesh_friend *frnd, u16_t addr) for (i = 0; i < ARRAY_SIZE(frnd->sub_list); i++) { if (frnd->sub_list[i] == addr) { - frnd->sub_list[i] = BT_MESH_ADDR_UNASSIGNED; + frnd->sub_list[i] = BLE_MESH_ADDR_UNASSIGNED; return; } } @@ -345,7 +345,7 @@ static struct net_buf *create_friend_pdu(struct bt_mesh_friend *frnd, nid = sub->keys[sub->kr_flag].nid; } else { if (friend_cred_get(sub, frnd->lpn, &nid, &enc, &priv)) { - BT_ERR("friend_cred_get failed"); + BT_ERR("%s, friend_cred_get failed", __func__); goto failed; } } @@ -370,12 +370,12 @@ static struct net_buf *create_friend_pdu(struct bt_mesh_friend *frnd, * layer nonce includes the IVI. */ if (bt_mesh_net_encrypt(enc, &buf->b, info->iv_index, false)) { - BT_ERR("Re-encrypting failed"); + BT_ERR("%s, Re-encrypting failed", __func__); goto failed; } if (bt_mesh_net_obfuscate(buf->data, info->iv_index, priv)) { - BT_ERR("Re-obfuscating failed"); + BT_ERR("%s, Re-obfuscating failed", __func__); goto failed; } @@ -408,7 +408,7 @@ static struct net_buf *encode_friend_ctl(struct bt_mesh_friend *frnd, info.seq[1] = seq >> 8; info.seq[2] = seq; - info.iv_index = BT_MESH_NET_IVI_TX; + info.iv_index = BLE_MESH_NET_IVI_TX; return create_friend_pdu(frnd, &info, sdu); } @@ -448,7 +448,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("Unable to encode Subscription List Confirmation"); + BT_ERR("%s, Unable to encode Subscription List Confirmation", __func__); return; } @@ -474,19 +474,19 @@ int bt_mesh_friend_sub_add(struct bt_mesh_net_rx *rx, struct bt_mesh_friend *frnd; u8_t xact; - if (buf->len < BT_MESH_FRIEND_SUB_MIN_LEN) { - BT_WARN("Too short Friend Subscription Add"); + if (buf->len < BLE_MESH_FRIEND_SUB_MIN_LEN) { + BT_WARN("%s, Too short Friend Subscription Add", __func__); return -EINVAL; } frnd = bt_mesh_friend_find(rx->sub->net_idx, rx->ctx.addr, true, true); if (!frnd) { - BT_WARN("No matching LPN addr 0x%04x", rx->ctx.addr); + BT_WARN("%s, No matching LPN addr 0x%04x", __func__, rx->ctx.addr); return 0; } if (frnd->pending_buf) { - BT_WARN("Previous buffer not yet sent!"); + BT_WARN("%s, Previous buffer not yet sent!", __func__); return 0; } @@ -509,19 +509,19 @@ int bt_mesh_friend_sub_rem(struct bt_mesh_net_rx *rx, struct bt_mesh_friend *frnd; u8_t xact; - if (buf->len < BT_MESH_FRIEND_SUB_MIN_LEN) { - BT_WARN("Too short Friend Subscription Remove"); + if (buf->len < BLE_MESH_FRIEND_SUB_MIN_LEN) { + BT_WARN("%s, Too short Friend Subscription Remove", __func__); return -EINVAL; } frnd = bt_mesh_friend_find(rx->sub->net_idx, rx->ctx.addr, true, true); if (!frnd) { - BT_WARN("No matching LPN addr 0x%04x", rx->ctx.addr); + BT_WARN("%s, No matching LPN addr 0x%04x", __func__, rx->ctx.addr); return 0; } if (frnd->pending_buf) { - BT_WARN("Previous buffer not yet sent!"); + BT_WARN("%s, Previous buffer not yet sent!", __func__); return 0; } @@ -550,7 +550,7 @@ static void enqueue_update(struct bt_mesh_friend *frnd, u8_t md) buf = encode_update(frnd, md); if (!buf) { - BT_ERR("Unable to encode Friend Update"); + BT_ERR("%s, Unable to encode Friend Update", __func__); return; } @@ -564,23 +564,23 @@ int bt_mesh_friend_poll(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf) struct bt_mesh_friend *frnd; if (buf->len < sizeof(*msg)) { - BT_WARN("Too short Friend Poll"); + BT_WARN("%s, Too short Friend Poll", __func__); return -EINVAL; } frnd = bt_mesh_friend_find(rx->sub->net_idx, rx->ctx.addr, true, false); if (!frnd) { - BT_WARN("No matching LPN addr 0x%04x", rx->ctx.addr); + BT_WARN("%s, No matching LPN addr 0x%04x", __func__, rx->ctx.addr); return 0; } if (msg->fsn & ~1) { - BT_WARN("Prohibited (non-zero) padding bits"); + BT_WARN("%s, Prohibited (non-zero) padding bits", __func__); return -EINVAL; } if (frnd->pending_buf) { - BT_WARN("Previous buffer not yet sent"); + BT_WARN("%s, Previous buffer not yet sent!", __func__); return 0; } @@ -645,9 +645,9 @@ static void send_friend_clear(struct bt_mesh_friend *frnd) { struct bt_mesh_msg_ctx ctx = { .net_idx = frnd->net_idx, - .app_idx = BT_MESH_KEY_UNUSED, + .app_idx = BLE_MESH_KEY_UNUSED, .addr = frnd->clear.frnd, - .send_ttl = BT_MESH_TTL_MAX, + .send_ttl = BLE_MESH_TTL_MAX, }; struct bt_mesh_net_tx tx = { .sub = &bt_mesh.sub[0], @@ -677,7 +677,7 @@ static void clear_timeout(struct k_work *work) duration = k_uptime_get_32() - frnd->clear.start; if (duration > 2 * frnd->poll_to) { BT_DBG("Clear Procedure timer expired"); - frnd->clear.frnd = BT_MESH_ADDR_UNASSIGNED; + frnd->clear.frnd = BLE_MESH_ADDR_UNASSIGNED; return; } @@ -704,32 +704,32 @@ int bt_mesh_friend_clear_cfm(struct bt_mesh_net_rx *rx, BT_DBG("%s", __func__); if (buf->len < sizeof(*msg)) { - BT_WARN("Too short Friend Clear Confirm"); + BT_WARN("%s, Too short Friend Clear Confirm", __func__); return -EINVAL; } frnd = find_clear(rx->ctx.addr); if (!frnd) { - BT_WARN("No pending clear procedure for 0x%02x", rx->ctx.addr); + BT_WARN("%s, No pending clear procedure for 0x%02x", __func__, rx->ctx.addr); return 0; } lpn_addr = sys_be16_to_cpu(msg->lpn_addr); if (lpn_addr != frnd->lpn) { - BT_WARN("LPN address mismatch (0x%04x != 0x%04x)", - lpn_addr, frnd->lpn); + BT_WARN("%s, LPN address mismatch (0x%04x != 0x%04x)", + __func__, lpn_addr, frnd->lpn); return 0; } lpn_counter = sys_be16_to_cpu(msg->lpn_counter); if (lpn_counter != frnd->lpn_counter) { - BT_WARN("LPN counter mismatch (0x%04x != 0x%04x)", - lpn_counter, frnd->lpn_counter); + BT_WARN("%s, LPN counter mismatch (0x%04x != 0x%04x)", + __func__, lpn_counter, frnd->lpn_counter); return 0; } k_delayed_work_cancel(&frnd->clear.timer); - frnd->clear.frnd = BT_MESH_ADDR_UNASSIGNED; + frnd->clear.frnd = BLE_MESH_ADDR_UNASSIGNED; return 0; } @@ -746,15 +746,15 @@ static void enqueue_offer(struct bt_mesh_friend *frnd, s8_t rssi) off = net_buf_simple_add(sdu, sizeof(*off)); - off->recv_win = CONFIG_BT_MESH_FRIEND_RECV_WIN, - off->queue_size = CONFIG_BT_MESH_FRIEND_QUEUE_SIZE, + off->recv_win = CONFIG_BLE_MESH_FRIEND_RECV_WIN, + off->queue_size = CONFIG_BLE_MESH_FRIEND_QUEUE_SIZE, off->sub_list_size = ARRAY_SIZE(frnd->sub_list), off->rssi = rssi, off->frnd_counter = sys_cpu_to_be16(frnd->counter); buf = encode_friend_ctl(frnd, TRANS_CTL_OP_FRIEND_OFFER, sdu); if (!buf) { - BT_ERR("Unable to encode Friend Offer"); + BT_ERR("%s, Unable to encode Friend Offer", __func__); return; } @@ -768,7 +768,7 @@ static void enqueue_offer(struct bt_mesh_friend *frnd, s8_t rssi) frnd->send_last = 1; } -#define RECV_WIN CONFIG_BT_MESH_FRIEND_RECV_WIN +#define RECV_WIN CONFIG_BLE_MESH_FRIEND_RECV_WIN #define RSSI_FACT(crit) (((crit) >> 5) & (u8_t)BIT_MASK(2)) #define RECV_WIN_FACT(crit) (((crit) >> 3) & (u8_t)BIT_MASK(2)) #define MIN_QUEUE_SIZE_LOG(crit) ((crit) & (u8_t)BIT_MASK(3)) @@ -808,12 +808,12 @@ 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("Too short Friend Request"); + BT_WARN("%s, Too short Friend Request", __func__); return -EINVAL; } if (msg->recv_delay <= 0x09) { - BT_WARN("Prohibited ReceiveDelay (0x%02x)", msg->recv_delay); + BT_WARN("%s, Prohibited ReceiveDelay (0x%02x)", __func__, msg->recv_delay); return -EINVAL; } @@ -822,35 +822,35 @@ int bt_mesh_friend_req(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf) ((u32_t)msg->poll_to[2])); if (poll_to <= 0x000009 || poll_to >= 0x34bc00) { - BT_WARN("Prohibited PollTimeout (0x%06x)", poll_to); + BT_WARN("%s, Prohibited PollTimeout (0x%06x)", __func__, poll_to); return -EINVAL; } if (msg->num_elem == 0x00) { - BT_WARN("Prohibited NumElements value (0x00)"); + BT_WARN("%s, Prohibited NumElements value (0x00)", __func__); return -EINVAL; } - if (!BT_MESH_ADDR_IS_UNICAST(rx->ctx.addr + msg->num_elem - 1)) { - BT_WARN("LPN elements stretch outside of unicast range"); + if (!BLE_MESH_ADDR_IS_UNICAST(rx->ctx.addr + msg->num_elem - 1)) { + BT_WARN("%s, LPN elements stretch outside of unicast range", __func__); return -EINVAL; } if (!MIN_QUEUE_SIZE_LOG(msg->criteria)) { - BT_WARN("Prohibited Minimum Queue Size in Friend Request"); + BT_WARN("%s, Prohibited Minimum Queue Size in Friend Request", __func__); return -EINVAL; } - if (CONFIG_BT_MESH_FRIEND_QUEUE_SIZE < MIN_QUEUE_SIZE(msg->criteria)) { - BT_WARN("We have a too small Friend Queue size (%u < %u)", - CONFIG_BT_MESH_FRIEND_QUEUE_SIZE, + 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, 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("Existing LPN re-requesting Friendship"); + BT_WARN("%s, Existing LPN re-requesting Friendship", __func__); friend_clear(frnd); goto init_friend; } @@ -864,7 +864,7 @@ int bt_mesh_friend_req(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf) } if (!frnd) { - BT_WARN("No free Friend contexts for new LPN"); + BT_WARN("%s, No free Friend contexts for new LPN", __func__); return -ENOMEM; } @@ -880,7 +880,7 @@ init_friend: BT_DBG("LPN 0x%04x rssi %d recv_delay %u poll_to %ums", frnd->lpn, rx->rssi, frnd->recv_delay, frnd->poll_to); - if (BT_MESH_ADDR_IS_UNICAST(frnd->clear.frnd) && + if (BLE_MESH_ADDR_IS_UNICAST(frnd->clear.frnd) && !bt_mesh_elem_find(frnd->clear.frnd)) { clear_procedure_start(frnd); } @@ -906,7 +906,7 @@ static struct bt_mesh_friend_seg *get_seg(struct bt_mesh_friend *frnd, struct bt_mesh_friend_seg *seg = &frnd->seg[i]; struct net_buf *buf = (void *)sys_slist_peek_head(&seg->queue); - if (buf && BT_MESH_ADV(buf)->addr == src && + if (buf && BLE_MESH_ADV(buf)->addr == src && FRIEND_ADV(buf)->seq_auth == *seq_auth) { return seg; } @@ -928,7 +928,7 @@ static void enqueue_friend_pdu(struct bt_mesh_friend *frnd, BT_DBG("type %u", type); - if (type == BT_MESH_FRIEND_PDU_SINGLE) { + if (type == BLE_MESH_FRIEND_PDU_SINGLE) { if (frnd->sec_update) { enqueue_update(frnd, 1); } @@ -938,17 +938,17 @@ static void enqueue_friend_pdu(struct bt_mesh_friend *frnd, } adv = FRIEND_ADV(buf); - seg = get_seg(frnd, BT_MESH_ADV(buf)->addr, &adv->seq_auth); + seg = get_seg(frnd, BLE_MESH_ADV(buf)->addr, &adv->seq_auth); if (!seg) { - BT_ERR("No free friend segment RX contexts for 0x%04x", - BT_MESH_ADV(buf)->addr); + BT_ERR("%s, No free friend segment RX contexts for 0x%04x", + __func__, BLE_MESH_ADV(buf)->addr); net_buf_unref(buf); return; } net_buf_slist_put(&seg->queue, buf); - if (type == BT_MESH_FRIEND_PDU_COMPLETE) { + if (type == BLE_MESH_FRIEND_PDU_COMPLETE) { if (frnd->sec_update) { enqueue_update(frnd, 1); } @@ -988,7 +988,7 @@ static void buf_send_end(int err, void *user_data) BT_DBG("err %d", err); if (frnd->pending_req) { - BT_WARN("Another request before previous completed sending"); + BT_WARN("%s, Another request before previous completed sending", __func__); return; } @@ -1023,14 +1023,14 @@ static void friend_timeout(struct k_work *work) } if (frnd->established && !frnd->pending_req) { - BT_WARN("Friendship lost with 0x%04x", frnd->lpn); + BT_WARN("%s, Friendship lost with 0x%04x", __func__, frnd->lpn); friend_clear(frnd); return; } frnd->last = net_buf_slist_get(&frnd->queue); if (!frnd->last) { - BT_WARN("Friendship not established with 0x%04x", frnd->lpn); + BT_WARN("%s, Friendship is not established with 0x%04x", __func__, frnd->lpn); friend_clear(frnd); return; } @@ -1053,7 +1053,7 @@ int bt_mesh_friend_init(void) struct bt_mesh_friend *frnd = &bt_mesh.frnd[i]; int j; - frnd->net_idx = BT_MESH_KEY_UNUSED; + frnd->net_idx = BLE_MESH_KEY_UNUSED; sys_slist_init(&frnd->queue); @@ -1079,7 +1079,7 @@ static void friend_purge_old_ack(struct bt_mesh_friend *frnd, u64_t *seq_auth, cur != NULL; prev = cur, cur = sys_slist_peek_next(cur)) { struct net_buf *buf = (void *)cur; - if (BT_MESH_ADV(buf)->addr == src && + if (BLE_MESH_ADV(buf)->addr == src && FRIEND_ADV(buf)->seq_auth == *seq_auth) { BT_DBG("Removing old ack from Friend Queue"); @@ -1104,14 +1104,14 @@ static void friend_lpn_enqueue_rx(struct bt_mesh_friend *frnd, BT_DBG("LPN 0x%04x queue_size %u", frnd->lpn, frnd->queue_size); - if (type == BT_MESH_FRIEND_PDU_SINGLE && seq_auth) { + if (type == BLE_MESH_FRIEND_PDU_SINGLE && seq_auth) { friend_purge_old_ack(frnd, seq_auth, rx->ctx.addr); } info.src = rx->ctx.addr; info.dst = rx->dst; - if (rx->net_if == BT_MESH_NET_IF_LOCAL) { + if (rx->net_if == BLE_MESH_NET_IF_LOCAL) { info.ttl = rx->ctx.recv_ttl; } else { info.ttl = rx->ctx.recv_ttl - 1; @@ -1123,11 +1123,11 @@ static void friend_lpn_enqueue_rx(struct bt_mesh_friend *frnd, info.seq[1] = (rx->seq >> 8); info.seq[2] = rx->seq; - info.iv_index = BT_MESH_NET_IVI_RX(rx); + info.iv_index = BLE_MESH_NET_IVI_RX(rx); buf = create_friend_pdu(frnd, &info, sbuf); if (!buf) { - BT_ERR("Failed to encode Friend buffer"); + BT_ERR("%s, Failed to encode Friend buffer", __func__); return; } @@ -1152,7 +1152,7 @@ static void friend_lpn_enqueue_tx(struct bt_mesh_friend *frnd, BT_DBG("LPN 0x%04x", frnd->lpn); - if (type == BT_MESH_FRIEND_PDU_SINGLE && seq_auth) { + if (type == BLE_MESH_FRIEND_PDU_SINGLE && seq_auth) { friend_purge_old_ack(frnd, seq_auth, tx->src); } @@ -1160,18 +1160,18 @@ static void friend_lpn_enqueue_tx(struct bt_mesh_friend *frnd, info.dst = tx->ctx->addr; info.ttl = tx->ctx->send_ttl; - info.ctl = (tx->ctx->app_idx == BT_MESH_KEY_UNUSED); + info.ctl = (tx->ctx->app_idx == BLE_MESH_KEY_UNUSED); seq = bt_mesh_next_seq(); info.seq[0] = seq >> 16; info.seq[1] = seq >> 8; info.seq[2] = seq; - info.iv_index = BT_MESH_NET_IVI_TX; + info.iv_index = BLE_MESH_NET_IVI_TX; buf = create_friend_pdu(frnd, &info, sbuf); if (!buf) { - BT_ERR("Failed to encode Friend buffer"); + BT_ERR("%s, Failed to encode Friend buffer", __func__); return; } @@ -1197,7 +1197,7 @@ static bool friend_lpn_matches(struct bt_mesh_friend *frnd, u16_t net_idx, return false; } - if (BT_MESH_ADDR_IS_UNICAST(addr)) { + if (BLE_MESH_ADDR_IS_UNICAST(addr)) { return is_lpn_unicast(frnd, addr); } @@ -1236,8 +1236,8 @@ void bt_mesh_friend_enqueue_rx(struct bt_mesh_net_rx *rx, int i; if (!rx->friend_match || - (rx->ctx.recv_ttl <= 1 && rx->net_if != BT_MESH_NET_IF_LOCAL) || - bt_mesh_friend_get() != BT_MESH_FRIEND_ENABLED) { + (rx->ctx.recv_ttl <= 1 && rx->net_if != BLE_MESH_NET_IF_LOCAL) || + bt_mesh_friend_get() != BLE_MESH_FRIEND_ENABLED) { return; } @@ -1261,7 +1261,7 @@ bool bt_mesh_friend_enqueue_tx(struct bt_mesh_net_tx *tx, int i; if (!bt_mesh_friend_match(tx->sub->net_idx, tx->ctx->addr) || - bt_mesh_friend_get() != BT_MESH_FRIEND_ENABLED) { + bt_mesh_friend_get() != BLE_MESH_FRIEND_ENABLED) { return matched; } @@ -1304,7 +1304,7 @@ void bt_mesh_friend_clear_incomplete(struct bt_mesh_subnet *sub, u16_t src, continue; } - if (BT_MESH_ADV(buf)->addr != src) { + if (BLE_MESH_ADV(buf)->addr != src) { continue; } @@ -1312,7 +1312,7 @@ void bt_mesh_friend_clear_incomplete(struct bt_mesh_subnet *sub, u16_t src, continue; } - BT_WARN("Clearing incomplete segments for 0x%04x", src); + BT_WARN("%s, Clearing incomplete segments for 0x%04x", __func__, src); while (!sys_slist_is_empty(&seg->queue)) { net_buf_unref(net_buf_slist_get(&seg->queue)); @@ -1320,5 +1320,5 @@ void bt_mesh_friend_clear_incomplete(struct bt_mesh_subnet *sub, u16_t src, } } } -#endif /* CONFIG_BT_MESH_FRIEND */ -#endif /* #if CONFIG_BT_MESH */ \ No newline at end of file + +#endif /* CONFIG_BLE_MESH_FRIEND */ diff --git a/components/bt/ble_mesh/mesh_core/friend.h b/components/bt/ble_mesh/mesh_core/friend.h index 946e88af6b..51b37c04af 100644 --- a/components/bt/ble_mesh/mesh_core/friend.h +++ b/components/bt/ble_mesh/mesh_core/friend.h @@ -6,10 +6,13 @@ * SPDX-License-Identifier: Apache-2.0 */ +#ifndef _FRIEND_H_ +#define _FRIEND_H_ + enum bt_mesh_friend_pdu_type { - BT_MESH_FRIEND_PDU_SINGLE, - BT_MESH_FRIEND_PDU_PARTIAL, - BT_MESH_FRIEND_PDU_COMPLETE, + BLE_MESH_FRIEND_PDU_SINGLE, + BLE_MESH_FRIEND_PDU_PARTIAL, + BLE_MESH_FRIEND_PDU_COMPLETE, }; bool bt_mesh_friend_match(u16_t net_idx, u16_t addr); @@ -32,13 +35,20 @@ void bt_mesh_friend_sec_update(u16_t net_idx); void bt_mesh_friend_clear_net_idx(u16_t net_idx); int bt_mesh_friend_poll(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf); + int bt_mesh_friend_req(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf); + int bt_mesh_friend_clear(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf); + int bt_mesh_friend_clear_cfm(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf); + int bt_mesh_friend_sub_add(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf); + int bt_mesh_friend_sub_rem(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf); int bt_mesh_friend_init(void); + +#endif /* _FRIEND_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/health_cli.c b/components/bt/ble_mesh/mesh_core/health_cli.c index 76be86122a..44da8f5e3d 100644 --- a/components/bt/ble_mesh/mesh_core/health_cli.c +++ b/components/bt/ble_mesh/mesh_core/health_cli.c @@ -11,19 +11,18 @@ #include #include +#include "osi/allocator.h" +#include "sdkconfig.h" +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_MODEL) + #include "mesh_types.h" #include "mesh_util.h" -#include "sdkconfig.h" -#include "osi/allocator.h" - -#if CONFIG_BT_MESH - -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_MODEL) #include "mesh_trace.h" #include "health_cli.h" + #include "foundation.h" -#include "common.h" -#include "btc_ble_mesh_health.h" +#include "mesh_common.h" +#include "btc_ble_mesh_health_model.h" s32_t health_msg_timeout; @@ -41,27 +40,27 @@ static const bt_mesh_client_op_pair_t health_op_pair[] = { static void timeout_handler(struct k_work *work) { - bt_mesh_health_client_t *client = NULL; - health_internal_data_t *internal = NULL; - bt_mesh_client_node_t *node = NULL; + health_internal_data_t *internal = NULL; + bt_mesh_health_client_t *client = NULL; + bt_mesh_client_node_t *node = NULL; BT_WARN("Receive health status message timeout"); node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work); if (!node || !node->ctx.model) { - BT_ERR("%s: node parameter is NULL", __func__); + BT_ERR("%s, Invalid parameter", __func__); return; } client = (bt_mesh_health_client_t *)node->ctx.model->user_data; if (!client) { - BT_ERR("%s: model user_data is NULL", __func__); + BT_ERR("%s, Health Client user_data is NULL", __func__); return; } internal = (health_internal_data_t *)client->internal_data; if (!internal) { - BT_ERR("%s: internal_data is NULL", __func__); + BT_ERR("%s, Health Client internal_data is NULL", __func__); return; } @@ -78,18 +77,18 @@ static void health_client_cancel(struct bt_mesh_model *model, void *status, size_t len) { health_internal_data_t *data = NULL; - bt_mesh_client_node_t *node = NULL; + bt_mesh_client_node_t *node = NULL; struct net_buf_simple buf = {0}; u8_t evt_type = 0xFF; if (!model || !ctx || !status || !len) { - BT_ERR("%s: invalid parameter", __func__); + BT_ERR("%s, Invalid parameter", __func__); return; } data = (health_internal_data_t *)health_cli->internal_data; if (!data) { - BT_ERR("%s: health client internal_data is NULL", __func__); + BT_ERR("%s, Health Client internal_data is NULL", __func__); return; } @@ -145,10 +144,10 @@ static void health_fault_status(struct bt_mesh_model *model, bt_hex(buf->data, buf->len)); status.test_id = net_buf_simple_pull_u8(buf); - status.cid = net_buf_simple_pull_le16(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: allocate memory for fault_array fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } @@ -163,7 +162,7 @@ static void health_current_status(struct bt_mesh_model *model, struct net_buf_simple *buf) { bt_mesh_client_node_t *node = NULL; - u8_t test_id; + u8_t test_id; u16_t cid; BT_DBG("net_idx 0x%04x app_idx 0x%04x src 0x%04x len %u: %s", @@ -176,7 +175,7 @@ static void health_current_status(struct bt_mesh_model *model, } test_id = net_buf_simple_pull_u8(buf); - cid = net_buf_simple_pull_le16(buf); + cid = net_buf_simple_pull_le16(buf); BT_DBG("Test ID 0x%02x Company ID 0x%04x Fault Count %u", test_id, cid, buf->len); @@ -217,7 +216,7 @@ const struct bt_mesh_model_op bt_mesh_health_cli_op[] = { { OP_HEALTH_CURRENT_STATUS, 3, health_current_status }, { OP_HEALTH_PERIOD_STATUS, 1, health_period_status }, { OP_ATTENTION_STATUS, 1, health_attention_status }, - BT_MESH_MODEL_OP_END, + BLE_MESH_MODEL_OP_END, }; int bt_mesh_health_attention_get(struct bt_mesh_msg_ctx *ctx) @@ -235,7 +234,7 @@ int bt_mesh_health_attention_get(struct bt_mesh_msg_ctx *ctx) msg, timeout_handler, health_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -246,7 +245,7 @@ int bt_mesh_health_attention_set(struct bt_mesh_msg_ctx *ctx, { struct net_buf_simple *msg = NET_BUF_SIMPLE(2 + 1 + 4); u32_t opcode; - int err; + int err; if (!ctx || !ctx->addr) { return -EINVAL; @@ -264,7 +263,7 @@ int bt_mesh_health_attention_set(struct bt_mesh_msg_ctx *ctx, timeout_handler, health_msg_timeout, need_ack, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -285,7 +284,7 @@ int bt_mesh_health_period_get(struct bt_mesh_msg_ctx *ctx) ctx, msg, timeout_handler, health_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -296,7 +295,7 @@ int bt_mesh_health_period_set(struct bt_mesh_msg_ctx *ctx, { struct net_buf_simple *msg = NET_BUF_SIMPLE(2 + 1 + 4); u32_t opcode; - int err; + int err; if (!ctx || !ctx->addr) { return -EINVAL; @@ -314,7 +313,7 @@ int bt_mesh_health_period_set(struct bt_mesh_msg_ctx *ctx, timeout_handler, health_msg_timeout, need_ack, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -325,7 +324,7 @@ int bt_mesh_health_fault_test(struct bt_mesh_msg_ctx *ctx, { struct net_buf_simple *msg = NET_BUF_SIMPLE(2 + 3 + 4); u32_t opcode; - int err; + int err; if (!ctx || !ctx->addr) { return -EINVAL; @@ -344,7 +343,7 @@ int bt_mesh_health_fault_test(struct bt_mesh_msg_ctx *ctx, timeout_handler, health_msg_timeout, need_ack, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -355,7 +354,7 @@ int bt_mesh_health_fault_clear(struct bt_mesh_msg_ctx *ctx, { struct net_buf_simple *msg = NET_BUF_SIMPLE(2 + 2 + 4); u32_t opcode; - int err; + int err; if (!ctx || !ctx->addr) { return -EINVAL; @@ -373,7 +372,7 @@ int bt_mesh_health_fault_clear(struct bt_mesh_msg_ctx *ctx, timeout_handler, health_msg_timeout, need_ack, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -395,7 +394,7 @@ int bt_mesh_health_fault_get(struct bt_mesh_msg_ctx *ctx, u16_t cid) msg, timeout_handler, health_msg_timeout, true, NULL, NULL); if (err) { - BT_ERR("%s: send failed (err %d)", __func__, err); + BT_ERR("%s, send failed (err %d)", __func__, err); } return err; @@ -414,7 +413,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("No Health Client context for given model"); + BT_ERR("%s, No Health Client context for given model", __func__); return -EINVAL; } @@ -425,34 +424,34 @@ int bt_mesh_health_cli_set(struct bt_mesh_model *model) int bt_mesh_health_cli_init(struct bt_mesh_model *model, bool primary) { - bt_mesh_health_client_t *client = NULL; - health_internal_data_t *internal = NULL; + health_internal_data_t *internal = NULL; + bt_mesh_health_client_t *client = NULL; BT_DBG("primary %u", primary); if (!model) { - BT_ERR("Health Client model is NULL"); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } client = (bt_mesh_health_client_t *)model->user_data; if (!client) { - BT_ERR("No Health Client context provided"); + BT_ERR("%s, No Health Client context provided", __func__); return -EINVAL; } /* TODO: call osi_free() when deinit function is invoked*/ internal = osi_calloc(sizeof(health_internal_data_t)); if (!internal) { - BT_ERR("Allocate memory for Health Client internal data fail"); + BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; } sys_slist_init(&internal->queue); - client->model = model; - client->op_pair_size = ARRAY_SIZE(health_op_pair); - client->op_pair = health_op_pair; + client->model = model; + client->op_pair_size = ARRAY_SIZE(health_op_pair); + client->op_pair = health_op_pair; client->internal_data = internal; /* Set the default health client pointer */ @@ -462,5 +461,3 @@ int bt_mesh_health_cli_init(struct bt_mesh_model *model, bool primary) return 0; } - -#endif /* #if CONFIG_BT_MESH */ diff --git a/components/bt/ble_mesh/mesh_core/health_srv.c b/components/bt/ble_mesh/mesh_core/health_srv.c index ecfad39b1f..f997b19cee 100644 --- a/components/bt/ble_mesh/mesh_core/health_srv.c +++ b/components/bt/ble_mesh/mesh_core/health_srv.c @@ -10,22 +10,22 @@ #include #include #include + +#include "sdkconfig.h" +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_MODEL) + #include "mesh_types.h" #include "mesh_util.h" -#include "sdkconfig.h" -#if CONFIG_BT_MESH - -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_MODEL) #include "mesh_trace.h" - #include "health_srv.h" + #include "mesh.h" #include "adv.h" #include "net.h" #include "transport.h" #include "access.h" #include "foundation.h" -#include "common.h" +#include "mesh_common.h" #define HEALTH_TEST_STANDARD 0x00 @@ -38,11 +38,11 @@ /* Health Server context of the primary element */ struct bt_mesh_health_srv *health_srv; -static void health_get_registered(struct bt_mesh_model *mod, +static void health_get_registered(struct bt_mesh_model *model, u16_t company_id, struct net_buf_simple *msg) { - struct bt_mesh_health_srv *srv = mod->user_data; + struct bt_mesh_health_srv *srv = model->user_data; u8_t *test_id; BT_DBG("Company ID 0x%04x", company_id); @@ -61,11 +61,11 @@ static void health_get_registered(struct bt_mesh_model *mod, u8_t fault_count = net_buf_simple_tailroom(msg) - 4; int err; - err = srv->cb->fault_get_reg(mod, company_id, test_id, + err = srv->cb->fault_get_reg(model, company_id, test_id, net_buf_simple_tail(msg), &fault_count); if (err) { - BT_ERR("Failed to get faults (err %d)", err); + BT_ERR("%s, Failed to get faults (err %d)", __func__, err); *test_id = HEALTH_TEST_STANDARD; } else { net_buf_simple_add(msg, fault_count); @@ -76,10 +76,10 @@ static void health_get_registered(struct bt_mesh_model *mod, } } -static size_t health_get_current(struct bt_mesh_model *mod, +static size_t health_get_current(struct bt_mesh_model *model, struct net_buf_simple *msg) { - struct bt_mesh_health_srv *srv = mod->user_data; + struct bt_mesh_health_srv *srv = model->user_data; const struct bt_mesh_comp *comp; u8_t *test_id, *company_ptr; u16_t company_id; @@ -99,11 +99,11 @@ static size_t health_get_current(struct bt_mesh_model *mod, if (srv->cb && srv->cb->fault_get_cur) { fault_count = net_buf_simple_tailroom(msg); - err = srv->cb->fault_get_cur(mod, test_id, &company_id, + err = srv->cb->fault_get_cur(model, test_id, &company_id, net_buf_simple_tail(msg), &fault_count); if (err) { - BT_ERR("Failed to get faults (err %d)", err); + BT_ERR("%s, Failed to get faults (err %d)", __func__, err); sys_put_le16(comp->cid, company_ptr); *test_id = HEALTH_TEST_STANDARD; fault_count = 0; @@ -132,7 +132,7 @@ static void health_fault_get(struct bt_mesh_model *model, BT_DBG("company_id 0x%04x", company_id); - sdu = bt_mesh_alloc_buf(min(BT_MESH_TX_SDU_MAX, HEALTH_FAULT_MAX_LEN)); + sdu = bt_mesh_alloc_buf(MIN(BLE_MESH_TX_SDU_MAX, HEALTH_FAULT_MAX_LEN)); if (!sdu) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -141,7 +141,7 @@ static void health_fault_get(struct bt_mesh_model *model, health_get_registered(model, company_id, sdu); if (bt_mesh_model_send(model, ctx, sdu, NULL, NULL)) { - BT_ERR("Unable to send Health Current Status response"); + BT_ERR("%s, Unable to send Health Current Status", __func__); } bt_mesh_free_buf(sdu); @@ -190,7 +190,7 @@ static void health_fault_clear(struct bt_mesh_model *model, srv->cb->fault_clear(model, company_id); } - sdu = bt_mesh_alloc_buf(min(BT_MESH_TX_SDU_MAX, HEALTH_FAULT_MAX_LEN)); + sdu = bt_mesh_alloc_buf(MIN(BLE_MESH_TX_SDU_MAX, HEALTH_FAULT_MAX_LEN)); if (!sdu) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -199,7 +199,7 @@ static void health_fault_clear(struct bt_mesh_model *model, health_get_registered(model, company_id, sdu); if (bt_mesh_model_send(model, ctx, sdu, NULL, NULL)) { - BT_ERR("Unable to send Health Current Status response"); + BT_ERR("%s, Unable to send Health Current Status", __func__); } bt_mesh_free_buf(sdu); @@ -260,7 +260,7 @@ static void health_fault_test(struct bt_mesh_model *model, } } - sdu = bt_mesh_alloc_buf(min(BT_MESH_TX_SDU_MAX, HEALTH_FAULT_MAX_LEN)); + sdu = bt_mesh_alloc_buf(MIN(BLE_MESH_TX_SDU_MAX, HEALTH_FAULT_MAX_LEN)); if (!sdu) { BT_ERR("%s, Failed to allocate memory", __func__); return; @@ -269,7 +269,7 @@ static void health_fault_test(struct bt_mesh_model *model, health_get_registered(model, company_id, sdu); if (bt_mesh_model_send(model, ctx, sdu, NULL, NULL)) { - BT_ERR("Unable to send Health Current Status response"); + BT_ERR("%s, Unable to send Health Current Status", __func__); } bt_mesh_free_buf(sdu); @@ -297,7 +297,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("Unable to send Attention Status"); + BT_ERR("%s, Unable to send Health Attention Status", __func__); } } @@ -345,7 +345,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("Unable to send Health Period Status"); + BT_ERR("%s, Unable to send Health Period Status", __func__); } } @@ -366,7 +366,7 @@ static void health_period_set_unrel(struct bt_mesh_model *model, period = net_buf_simple_pull_u8(buf); if (period > 15) { - BT_WARN("Prohibited period value %u", period); + BT_WARN("%s, Prohibited period value %u", __func__, period); return; } @@ -387,28 +387,28 @@ static void health_period_set(struct bt_mesh_model *model, } const struct bt_mesh_model_op bt_mesh_health_srv_op[] = { - { OP_HEALTH_FAULT_GET, 2, health_fault_get }, - { OP_HEALTH_FAULT_CLEAR, 2, health_fault_clear }, - { OP_HEALTH_FAULT_CLEAR_UNREL, 2, health_fault_clear_unrel }, - { OP_HEALTH_FAULT_TEST, 3, health_fault_test }, - { OP_HEALTH_FAULT_TEST_UNREL, 3, health_fault_test_unrel }, - { OP_HEALTH_PERIOD_GET, 0, health_period_get }, - { OP_HEALTH_PERIOD_SET, 1, health_period_set }, - { OP_HEALTH_PERIOD_SET_UNREL, 1, health_period_set_unrel }, - { OP_ATTENTION_GET, 0, attention_get }, - { OP_ATTENTION_SET, 1, attention_set }, - { OP_ATTENTION_SET_UNREL, 1, attention_set_unrel }, - BT_MESH_MODEL_OP_END, + { OP_HEALTH_FAULT_GET, 2, health_fault_get }, + { OP_HEALTH_FAULT_CLEAR, 2, health_fault_clear }, + { OP_HEALTH_FAULT_CLEAR_UNREL, 2, health_fault_clear_unrel }, + { OP_HEALTH_FAULT_TEST, 3, health_fault_test }, + { OP_HEALTH_FAULT_TEST_UNREL, 3, health_fault_test_unrel }, + { OP_HEALTH_PERIOD_GET, 0, health_period_get }, + { OP_HEALTH_PERIOD_SET, 1, health_period_set }, + { OP_HEALTH_PERIOD_SET_UNREL, 1, health_period_set_unrel }, + { OP_ATTENTION_GET, 0, attention_get }, + { OP_ATTENTION_SET, 1, attention_set }, + { OP_ATTENTION_SET_UNREL, 1, attention_set_unrel }, + BLE_MESH_MODEL_OP_END, }; -static int health_pub_update(struct bt_mesh_model *mod) +static int health_pub_update(struct bt_mesh_model *model) { - struct bt_mesh_model_pub *pub = mod->pub; + struct bt_mesh_model_pub *pub = model->pub; size_t count; BT_DBG("%s", __func__); - count = health_get_current(mod, pub->msg); + count = health_get_current(model, pub->msg); if (!count) { pub->period_div = 0; } @@ -418,14 +418,14 @@ static int health_pub_update(struct bt_mesh_model *mod) int bt_mesh_fault_update(struct bt_mesh_elem *elem) { - struct bt_mesh_model *mod; + struct bt_mesh_model *model; - mod = bt_mesh_model_find(elem, BT_MESH_MODEL_ID_HEALTH_SRV); - if (!mod) { + model = bt_mesh_model_find(elem, BLE_MESH_MODEL_ID_HEALTH_SRV); + if (!model) { return -EINVAL; } - return bt_mesh_model_publish(mod); + return bt_mesh_model_publish(model); } static void attention_off(struct k_work *work) @@ -508,5 +508,3 @@ void bt_mesh_attention(struct bt_mesh_model *model, u8_t time) } } } - -#endif /* #if CONFIG_BT_MESH */ diff --git a/components/bt/ble_mesh/mesh_core/include/cfg_cli.h b/components/bt/ble_mesh/mesh_core/include/cfg_cli.h index fd31837c54..b001d84b8a 100644 --- a/components/bt/ble_mesh/mesh_core/include/cfg_cli.h +++ b/components/bt/ble_mesh/mesh_core/include/cfg_cli.h @@ -8,12 +8,12 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#ifndef __BT_MESH_CFG_CLI_H -#define __BT_MESH_CFG_CLI_H +#ifndef _BLE_MESH_CFG_CLI_H_ +#define _BLE_MESH_CFG_CLI_H_ #include "mesh_access.h" #include "mesh_kernel.h" -#include "bt_mesh_client_common.h" +#include "model_common.h" /** * @brief Bluetooth Mesh @@ -28,9 +28,9 @@ typedef bt_mesh_internal_data_t config_internal_data_t; extern const struct bt_mesh_model_op bt_mesh_cfg_cli_op[]; -#define BT_MESH_MODEL_CFG_CLI(cli_data) \ - BT_MESH_MODEL(BT_MESH_MODEL_ID_CFG_CLI, \ - bt_mesh_cfg_cli_op, NULL, cli_data) +#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) int bt_mesh_cfg_comp_data_get(struct bt_mesh_msg_ctx *ctx, u8_t page); @@ -64,12 +64,12 @@ 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); struct bt_mesh_cfg_mod_pub { - u16_t addr; - u16_t app_idx; - bool cred_flag; - u8_t ttl; - u8_t period; - u8_t transmit; + u16_t addr; + u16_t app_idx; + bool cred_flag; + u8_t ttl; + u8_t period; + u8_t transmit; }; int bt_mesh_cfg_mod_pub_get(struct bt_mesh_msg_ctx *ctx, u16_t elem_addr, @@ -294,4 +294,4 @@ int bt_mesh_cfg_net_transmit_set(struct bt_mesh_msg_ctx *ctx, u8_t transmit); * @} */ -#endif /* __BT_MESH_CFG_CLI_H */ +#endif /* __BLE_MESH_CFG_CLI_H */ diff --git a/components/bt/ble_mesh/mesh_core/include/cfg_srv.h b/components/bt/ble_mesh/mesh_core/include/cfg_srv.h index 633d7a78f0..d5f77e7b01 100644 --- a/components/bt/ble_mesh/mesh_core/include/cfg_srv.h +++ b/components/bt/ble_mesh/mesh_core/include/cfg_srv.h @@ -7,8 +7,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#ifndef __BT_MESH_CFG_SRV_H -#define __BT_MESH_CFG_SRV_H +#ifndef _BLE_MESH_CFG_SRV_H_ +#define _BLE_MESH_CFG_SRV_H_ #include "mesh_access.h" #include "mesh_kernel.h" @@ -61,12 +61,12 @@ struct bt_mesh_cfg_srv { extern const struct bt_mesh_model_op bt_mesh_cfg_srv_op[]; -#define BT_MESH_MODEL_CFG_SRV(srv_data) \ - BT_MESH_MODEL(BT_MESH_MODEL_ID_CFG_SRV, \ - bt_mesh_cfg_srv_op, NULL, srv_data) +#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) /** * @} */ -#endif /* __BT_MESH_CFG_SRV_H */ +#endif /* __BLE_MESH_CFG_SRV_H */ diff --git a/components/bt/ble_mesh/mesh_core/include/dlist.h b/components/bt/ble_mesh/mesh_core/include/dlist.h deleted file mode 100644 index 11d93ca54c..0000000000 --- a/components/bt/ble_mesh/mesh_core/include/dlist.h +++ /dev/null @@ -1,495 +0,0 @@ -/* - * Copyright (c) 2013-2015 Wind River Systems, Inc. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @file - * @brief Doubly-linked list implementation - * - * Doubly-linked list implementation using inline macros/functions. - * This API is not thread safe, and thus if a list is used across threads, - * calls to functions must be protected with synchronization primitives. - * - * The lists are expected to be initialized such that both the head and tail - * pointers point to the list itself. Initializing the lists in such a fashion - * simplifies the adding and removing of nodes to/from the list. - */ - -#ifndef _misc_dlist__h_ -#define _misc_dlist__h_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct _dnode { - union { - struct _dnode *head; /* ptr to head of list (sys_dlist_t) */ - struct _dnode *next; /* ptr to next node (sys_dnode_t) */ - }; - union { - struct _dnode *tail; /* ptr to tail of list (sys_dlist_t) */ - struct _dnode *prev; /* ptr to previous node (sys_dnode_t) */ - }; -}; - -typedef struct _dnode sys_dlist_t; -typedef struct _dnode sys_dnode_t; - -/** - * @brief Provide the primitive to iterate on a list - * Note: the loop is unsafe and thus __dn should not be removed - * - * User _MUST_ add the loop statement curly braces enclosing its own code: - * - * SYS_DLIST_FOR_EACH_NODE(l, n) { - * - * } - * - * This and other SYS_DLIST_*() macros are not thread safe. - * - * @param __dl A pointer on a sys_dlist_t to iterate on - * @param __dn A sys_dnode_t pointer to peek each node of the list - */ -#define SYS_DLIST_FOR_EACH_NODE(__dl, __dn) \ - for (__dn = sys_dlist_peek_head(__dl); __dn; \ - __dn = sys_dlist_peek_next(__dl, __dn)) - -/** - * @brief Provide the primitive to iterate on a list, from a node in the list - * Note: the loop is unsafe and thus __dn should not be removed - * - * User _MUST_ add the loop statement curly braces enclosing its own code: - * - * SYS_DLIST_ITERATE_FROM_NODE(l, n) { - * - * } - * - * Like SYS_DLIST_FOR_EACH_NODE(), but __dn already contains a node in the list - * where to start searching for the next entry from. If NULL, it starts from - * the head. - * - * This and other SYS_DLIST_*() macros are not thread safe. - * - * @param __dl A pointer on a sys_dlist_t to iterate on - * @param __dn A sys_dnode_t pointer to peek each node of the list; - * it contains the starting node, or NULL to start from the head - */ -#define SYS_DLIST_ITERATE_FROM_NODE(__dl, __dn) \ - for (__dn = __dn ? sys_dlist_peek_next_no_check(__dl, __dn) \ - : sys_dlist_peek_head(__dl); \ - __dn; \ - __dn = sys_dlist_peek_next(__dl, __dn)) - -/** - * @brief Provide the primitive to safely iterate on a list - * Note: __dn can be removed, it will not break the loop. - * - * User _MUST_ add the loop statement curly braces enclosing its own code: - * - * SYS_DLIST_FOR_EACH_NODE_SAFE(l, n, s) { - * - * } - * - * This and other SYS_DLIST_*() macros are not thread safe. - * - * @param __dl A pointer on a sys_dlist_t to iterate on - * @param __dn A sys_dnode_t pointer to peek each node of the list - * @param __dns A sys_dnode_t pointer for the loop to run safely - */ -#define SYS_DLIST_FOR_EACH_NODE_SAFE(__dl, __dn, __dns) \ - for (__dn = sys_dlist_peek_head(__dl), \ - __dns = sys_dlist_peek_next(__dl, __dn); \ - __dn; __dn = __dns, \ - __dns = sys_dlist_peek_next(__dl, __dn)) - -/* - * @brief Provide the primitive to resolve the container of a list node - * Note: it is safe to use with NULL pointer nodes - * - * @param __dn A pointer on a sys_dnode_t to get its container - * @param __cn Container struct type pointer - * @param __n The field name of sys_dnode_t within the container struct - */ -#define SYS_DLIST_CONTAINER(__dn, __cn, __n) \ - (__dn ? CONTAINER_OF(__dn, __typeof__(*__cn), __n) : NULL) -/* - * @brief Provide the primitive to peek container of the list head - * - * @param __dl A pointer on a sys_dlist_t to peek - * @param __cn Container struct type pointer - * @param __n The field name of sys_dnode_t within the container struct - */ -#define SYS_DLIST_PEEK_HEAD_CONTAINER(__dl, __cn, __n) \ - SYS_DLIST_CONTAINER(sys_dlist_peek_head(__dl), __cn, __n) - -/* - * @brief Provide the primitive to peek the next container - * - * @param __dl A pointer on a sys_dlist_t to peek - * @param __cn Container struct type pointer - * @param __n The field name of sys_dnode_t within the container struct - */ -#define SYS_DLIST_PEEK_NEXT_CONTAINER(__dl, __cn, __n) \ - ((__cn) ? SYS_DLIST_CONTAINER(sys_dlist_peek_next(__dl, &(__cn->__n)), \ - __cn, __n) : NULL) - -/** - * @brief Provide the primitive to iterate on a list under a container - * Note: the loop is unsafe and thus __cn should not be detached - * - * User _MUST_ add the loop statement curly braces enclosing its own code: - * - * SYS_DLIST_FOR_EACH_CONTAINER(l, c, n) { - * - * } - * - * @param __dl A pointer on a sys_dlist_t to iterate on - * @param __cn A pointer to peek each entry of the list - * @param __n The field name of sys_dnode_t within the container struct - */ -#define SYS_DLIST_FOR_EACH_CONTAINER(__dl, __cn, __n) \ - for (__cn = SYS_DLIST_PEEK_HEAD_CONTAINER(__dl, __cn, __n); __cn; \ - __cn = SYS_DLIST_PEEK_NEXT_CONTAINER(__dl, __cn, __n)) - -/** - * @brief Provide the primitive to safely iterate on a list under a container - * Note: __cn can be detached, it will not break the loop. - * - * User _MUST_ add the loop statement curly braces enclosing its own code: - * - * SYS_DLIST_FOR_EACH_CONTAINER_SAFE(l, c, cn, n) { - * - * } - * - * @param __dl A pointer on a sys_dlist_t to iterate on - * @param __cn A pointer to peek each entry of the list - * @param __cns A pointer for the loop to run safely - * @param __n The field name of sys_dnode_t within the container struct - */ -#define SYS_DLIST_FOR_EACH_CONTAINER_SAFE(__dl, __cn, __cns, __n) \ - for (__cn = SYS_DLIST_PEEK_HEAD_CONTAINER(__dl, __cn, __n), \ - __cns = SYS_DLIST_PEEK_NEXT_CONTAINER(__dl, __cn, __n); __cn; \ - __cn = __cns, \ - __cns = SYS_DLIST_PEEK_NEXT_CONTAINER(__dl, __cn, __n)) - -/** - * @brief initialize list - * - * @param list the doubly-linked list - * - * @return N/A - */ - -static inline void sys_dlist_init(sys_dlist_t *list) -{ - list->head = (sys_dnode_t *)list; - list->tail = (sys_dnode_t *)list; -} - -#define SYS_DLIST_STATIC_INIT(ptr_to_list) {{(ptr_to_list)}, {(ptr_to_list)}} - -/** - * @brief check if a node is the list's head - * - * @param list the doubly-linked list to operate on - * @param node the node to check - * - * @return 1 if node is the head, 0 otherwise - */ - -static inline int sys_dlist_is_head(sys_dlist_t *list, sys_dnode_t *node) -{ - return list->head == node; -} - -/** - * @brief check if a node is the list's tail - * - * @param list the doubly-linked list to operate on - * @param node the node to check - * - * @return 1 if node is the tail, 0 otherwise - */ - -static inline int sys_dlist_is_tail(sys_dlist_t *list, sys_dnode_t *node) -{ - return list->tail == node; -} - -/** - * @brief check if the list is empty - * - * @param list the doubly-linked list to operate on - * - * @return 1 if empty, 0 otherwise - */ - -static inline int sys_dlist_is_empty(sys_dlist_t *list) -{ - return list->head == list; -} - -/** - * @brief check if more than one node present - * - * This and other sys_dlist_*() functions are not thread safe. - * - * @param list the doubly-linked list to operate on - * - * @return 1 if multiple nodes, 0 otherwise - */ - -static inline int sys_dlist_has_multiple_nodes(sys_dlist_t *list) -{ - return list->head != list->tail; -} - -/** - * @brief get a reference to the head item in the list - * - * @param list the doubly-linked list to operate on - * - * @return a pointer to the head element, NULL if list is empty - */ - -static inline sys_dnode_t *sys_dlist_peek_head(sys_dlist_t *list) -{ - return sys_dlist_is_empty(list) ? NULL : list->head; -} - -/** - * @brief get a reference to the head item in the list - * - * The list must be known to be non-empty. - * - * @param list the doubly-linked list to operate on - * - * @return a pointer to the head element - */ - -static inline sys_dnode_t *sys_dlist_peek_head_not_empty(sys_dlist_t *list) -{ - return list->head; -} - -/** - * @brief get a reference to the next item in the list, node is not NULL - * - * Faster than sys_dlist_peek_next() if node is known not to be NULL. - * - * @param list the doubly-linked list to operate on - * @param node the node from which to get the next element in the list - * - * @return a pointer to the next element from a node, NULL if node is the tail - */ - -static inline sys_dnode_t *sys_dlist_peek_next_no_check(sys_dlist_t *list, - sys_dnode_t *node) -{ - return (node == list->tail) ? NULL : node->next; -} - -/** - * @brief get a reference to the next item in the list - * - * @param list the doubly-linked list to operate on - * @param node the node from which to get the next element in the list - * - * @return a pointer to the next element from a node, NULL if node is the tail - * or NULL (when node comes from reading the head of an empty list). - */ - -static inline sys_dnode_t *sys_dlist_peek_next(sys_dlist_t *list, - sys_dnode_t *node) -{ - return node ? sys_dlist_peek_next_no_check(list, node) : NULL; -} - -/** - * @brief get a reference to the tail item in the list - * - * @param list the doubly-linked list to operate on - * - * @return a pointer to the tail element, NULL if list is empty - */ - -static inline sys_dnode_t *sys_dlist_peek_tail(sys_dlist_t *list) -{ - return sys_dlist_is_empty(list) ? NULL : list->tail; -} - -/** - * @brief add node to tail of list - * - * This and other sys_dlist_*() functions are not thread safe. - * - * @param list the doubly-linked list to operate on - * @param node the element to append - * - * @return N/A - */ - -static inline void sys_dlist_append(sys_dlist_t *list, sys_dnode_t *node) -{ - node->next = list; - node->prev = list->tail; - - list->tail->next = node; - list->tail = node; -} - -/** - * @brief add node to head of list - * - * This and other sys_dlist_*() functions are not thread safe. - * - * @param list the doubly-linked list to operate on - * @param node the element to append - * - * @return N/A - */ - -static inline void sys_dlist_prepend(sys_dlist_t *list, sys_dnode_t *node) -{ - node->next = list->head; - node->prev = list; - - list->head->prev = node; - list->head = node; -} - -/** - * @brief insert node after a node - * - * Insert a node after a specified node in a list. - * This and other sys_dlist_*() functions are not thread safe. - * - * @param list the doubly-linked list to operate on - * @param insert_point the insert point in the list: if NULL, insert at head - * @param node the element to append - * - * @return N/A - */ - -static inline void sys_dlist_insert_after(sys_dlist_t *list, - sys_dnode_t *insert_point, sys_dnode_t *node) -{ - if (!insert_point) { - sys_dlist_prepend(list, node); - } else { - node->next = insert_point->next; - node->prev = insert_point; - insert_point->next->prev = node; - insert_point->next = node; - } -} - -/** - * @brief insert node before a node - * - * Insert a node before a specified node in a list. - * This and other sys_dlist_*() functions are not thread safe. - * - * @param list the doubly-linked list to operate on - * @param insert_point the insert point in the list: if NULL, insert at tail - * @param node the element to insert - * - * @return N/A - */ - -static inline void sys_dlist_insert_before(sys_dlist_t *list, - sys_dnode_t *insert_point, sys_dnode_t *node) -{ - if (!insert_point) { - sys_dlist_append(list, node); - } else { - node->prev = insert_point->prev; - node->next = insert_point; - insert_point->prev->next = node; - insert_point->prev = node; - } -} - -/** - * @brief insert node at position - * - * Insert a node in a location depending on a external condition. The cond() - * function checks if the node is to be inserted _before_ the current node - * against which it is checked. - * This and other sys_dlist_*() functions are not thread safe. - * - * @param list the doubly-linked list to operate on - * @param node the element to insert - * @param cond a function that determines if the current node is the correct - * insert point - * @param data parameter to cond() - * - * @return N/A - */ - -static inline void sys_dlist_insert_at(sys_dlist_t *list, sys_dnode_t *node, - int (*cond)(sys_dnode_t *, void *), void *data) -{ - if (sys_dlist_is_empty(list)) { - sys_dlist_append(list, node); - } else { - sys_dnode_t *pos = sys_dlist_peek_head(list); - - while (pos && !cond(pos, data)) { - pos = sys_dlist_peek_next(list, pos); - } - sys_dlist_insert_before(list, pos, node); - } -} - -/** - * @brief remove a specific node from a list - * - * The list is implicit from the node. The node must be part of a list. - * This and other sys_dlist_*() functions are not thread safe. - * - * @param node the node to remove - * - * @return N/A - */ - -static inline void sys_dlist_remove(sys_dnode_t *node) -{ - node->prev->next = node->next; - node->next->prev = node->prev; -} - -/** - * @brief get the first node in a list - * - * This and other sys_dlist_*() functions are not thread safe. - * - * @param list the doubly-linked list to operate on - * - * @return the first node in the list, NULL if list is empty - */ - -static inline sys_dnode_t *sys_dlist_get(sys_dlist_t *list) -{ - sys_dnode_t *node; - - if (sys_dlist_is_empty(list)) { - return NULL; - } - - node = list->head; - sys_dlist_remove(node); - return node; -} - -#ifdef __cplusplus -} -#endif - -#endif /* _misc_dlist__h_ */ - diff --git a/components/bt/ble_mesh/mesh_core/include/health_cli.h b/components/bt/ble_mesh/mesh_core/include/health_cli.h index 5451343da2..9d7230ebac 100644 --- a/components/bt/ble_mesh/mesh_core/include/health_cli.h +++ b/components/bt/ble_mesh/mesh_core/include/health_cli.h @@ -8,12 +8,12 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#ifndef __BT_MESH_HEALTH_CLI_H -#define __BT_MESH_HEALTH_CLI_H +#ifndef _BLE_MESH_HEALTH_CLI_H_ +#define _BLE_MESH_HEALTH_CLI_H_ #include "mesh_access.h" #include "mesh_kernel.h" -#include "bt_mesh_client_common.h" +#include "model_common.h" /** * @brief Bluetooth Mesh @@ -30,9 +30,9 @@ typedef bt_mesh_internal_data_t health_client_internal_data_t; extern const struct bt_mesh_model_op bt_mesh_health_cli_op[]; -#define BT_MESH_MODEL_HEALTH_CLI(cli_data) \ - BT_MESH_MODEL(BT_MESH_MODEL_ID_HEALTH_CLI, \ - bt_mesh_health_cli_op, NULL, cli_data) +#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) int bt_mesh_health_cli_set(struct bt_mesh_model *model); @@ -75,4 +75,4 @@ struct bt_mesh_health_fault_status { * @} */ -#endif /* __BT_MESH_HEALTH_CLI_H */ +#endif /* __BLE_MESH_HEALTH_CLI_H */ diff --git a/components/bt/ble_mesh/mesh_core/include/health_srv.h b/components/bt/ble_mesh/mesh_core/include/health_srv.h index 7e7255c003..e310b29b51 100644 --- a/components/bt/ble_mesh/mesh_core/include/health_srv.h +++ b/components/bt/ble_mesh/mesh_core/include/health_srv.h @@ -7,8 +7,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#ifndef __BT_MESH_HEALTH_SRV_H -#define __BT_MESH_HEALTH_SRV_H +#ifndef _BLE_MESH_HEALTH_SRV_H_ +#define _BLE_MESH_HEALTH_SRV_H_ #include "mesh_access.h" #include "mesh_kernel.h" @@ -45,7 +45,7 @@ struct bt_mesh_health_srv_cb { void (*attn_off)(struct bt_mesh_model *model); }; -/** @def BT_MESH_HEALTH_FAULT_MSG +/** @def BLE_MESH_HEALTH_FAULT_MSG * * A helper to define a health fault message. * @@ -53,8 +53,8 @@ struct bt_mesh_health_srv_cb { * * @return a New net_buf_simple of the needed size. */ -#define BT_MESH_HEALTH_FAULT_MSG(max_faults) \ - NET_BUF_SIMPLE(1 + 3 + (max_faults)) +#define BLE_MESH_HEALTH_FAULT_MSG(max_faults) \ + NET_BUF_SIMPLE(1 + 3 + (max_faults)) /** Mesh Health Server Model Context */ struct bt_mesh_health_srv { @@ -67,11 +67,9 @@ struct bt_mesh_health_srv { struct k_delayed_work attn_timer; }; -int bt_mesh_fault_update(struct bt_mesh_elem *elem); - extern const struct bt_mesh_model_op bt_mesh_health_srv_op[]; -/** @def BT_MESH_MODEL_HEALTH_SRV +/** @def BLE_MESH_MODEL_HEALTH_SRV * * Define a new health server model. Note that this API needs to be * repeated for each element which the application wants to have a @@ -83,12 +81,14 @@ extern const struct bt_mesh_model_op bt_mesh_health_srv_op[]; * * @return New mesh model instance. */ -#define BT_MESH_MODEL_HEALTH_SRV(srv, pub) \ - BT_MESH_MODEL(BT_MESH_MODEL_ID_HEALTH_SRV, \ - bt_mesh_health_srv_op, pub, srv) +#define BLE_MESH_MODEL_HEALTH_SRV(srv, pub) \ + BLE_MESH_MODEL(BLE_MESH_MODEL_ID_HEALTH_SRV, \ + bt_mesh_health_srv_op, pub, srv) + +int bt_mesh_fault_update(struct bt_mesh_elem *elem); /** * @} */ -#endif /* __BT_MESH_HEALTH_SRV_H */ +#endif /* __BLE_MESH_HEALTH_SRV_H */ diff --git a/components/bt/ble_mesh/mesh_core/include/mesh_access.h b/components/bt/ble_mesh/mesh_core/include/mesh_access.h index c8353026da..ee202c9df0 100644 --- a/components/bt/ble_mesh/mesh_core/include/mesh_access.h +++ b/components/bt/ble_mesh/mesh_core/include/mesh_access.h @@ -8,15 +8,14 @@ * * SPDX-License-Identifier: Apache-2.0 */ +#ifndef _BLE_MESH_ACCESS_H_ +#define _BLE_MESH_ACCESS_H_ #include #include "mesh_types.h" #include "mesh_util.h" #include "mesh_buf.h" #include "sdkconfig.h" -#if CONFIG_BT_MESH -#ifndef __BT_MESH_ACCESS_H -#define __BT_MESH_ACCESS_H /** * @brief Bluetooth Mesh Access Layer @@ -25,26 +24,26 @@ * @{ */ -#define BT_MESH_ADDR_UNASSIGNED 0x0000 -#define BT_MESH_ADDR_ALL_NODES 0xffff -#define BT_MESH_ADDR_PROXIES 0xfffc -#define BT_MESH_ADDR_FRIENDS 0xfffd -#define BT_MESH_ADDR_RELAYS 0xfffe +#define BLE_MESH_ADDR_UNASSIGNED 0x0000 +#define BLE_MESH_ADDR_ALL_NODES 0xffff +#define BLE_MESH_ADDR_PROXIES 0xfffc +#define BLE_MESH_ADDR_FRIENDS 0xfffd +#define BLE_MESH_ADDR_RELAYS 0xfffe -#define BT_MESH_KEY_UNUSED 0xffff -#define BT_MESH_KEY_DEV 0xfffe +#define BLE_MESH_KEY_UNUSED 0xffff +#define BLE_MESH_KEY_DEV 0xfffe /** Helper to define a mesh element within an array. * * In case the element has no SIG or Vendor models the helper - * macro BT_MESH_MODEL_NONE can be given instead. + * macro BLE_MESH_MODEL_NONE can be given instead. * * @param _loc Location Descriptor. * @param _mods Array of models. * @param _vnd_mods Array of vendor models. */ -#define BT_MESH_ELEM(_loc, _mods, _vnd_mods) \ -{ \ +#define BLE_MESH_ELEM(_loc, _mods, _vnd_mods) \ +{ \ .loc = (_loc), \ .model_count = ARRAY_SIZE(_mods), \ .models = (_mods), \ @@ -68,64 +67,64 @@ struct bt_mesh_elem { }; /* Foundation Models */ -#define BT_MESH_MODEL_ID_CFG_SRV 0x0000 -#define BT_MESH_MODEL_ID_CFG_CLI 0x0001 -#define BT_MESH_MODEL_ID_HEALTH_SRV 0x0002 -#define BT_MESH_MODEL_ID_HEALTH_CLI 0x0003 +#define BLE_MESH_MODEL_ID_CFG_SRV 0x0000 +#define BLE_MESH_MODEL_ID_CFG_CLI 0x0001 +#define BLE_MESH_MODEL_ID_HEALTH_SRV 0x0002 +#define BLE_MESH_MODEL_ID_HEALTH_CLI 0x0003 /* Models from the Mesh Model Specification */ -#define BT_MESH_MODEL_ID_GEN_ONOFF_SRV 0x1000 -#define BT_MESH_MODEL_ID_GEN_ONOFF_CLI 0x1001 -#define BT_MESH_MODEL_ID_GEN_LEVEL_SRV 0x1002 -#define BT_MESH_MODEL_ID_GEN_LEVEL_CLI 0x1003 -#define BT_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV 0x1004 -#define BT_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI 0x1005 -#define BT_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV 0x1006 -#define BT_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV 0x1007 -#define BT_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI 0x1008 -#define BT_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV 0x1009 -#define BT_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV 0x100a -#define BT_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI 0x100b -#define BT_MESH_MODEL_ID_GEN_BATTERY_SRV 0x100c -#define BT_MESH_MODEL_ID_GEN_BATTERY_CLI 0x100d -#define BT_MESH_MODEL_ID_GEN_LOCATION_SRV 0x100e -#define BT_MESH_MODEL_ID_GEN_LOCATION_SETUPSRV 0x100f -#define BT_MESH_MODEL_ID_GEN_LOCATION_CLI 0x1010 -#define BT_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV 0x1011 -#define BT_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV 0x1012 -#define BT_MESH_MODEL_ID_GEN_USER_PROP_SRV 0x1013 -#define BT_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV 0x1014 -#define BT_MESH_MODEL_ID_GEN_PROP_CLI 0x1015 -#define BT_MESH_MODEL_ID_SENSOR_SRV 0x1100 -#define BT_MESH_MODEL_ID_SENSOR_SETUP_SRV 0x1101 -#define BT_MESH_MODEL_ID_SENSOR_CLI 0x1102 -#define BT_MESH_MODEL_ID_TIME_SRV 0x1200 -#define BT_MESH_MODEL_ID_TIME_SETUP_SRV 0x1201 -#define BT_MESH_MODEL_ID_TIME_CLI 0x1202 -#define BT_MESH_MODEL_ID_SCENE_SRV 0x1203 -#define BT_MESH_MODEL_ID_SCENE_SETUP_SRV 0x1204 -#define BT_MESH_MODEL_ID_SCENE_CLI 0x1205 -#define BT_MESH_MODEL_ID_SCHEDULER_SRV 0x1206 -#define BT_MESH_MODEL_ID_SCHEDULER_SETUP_SRV 0x1207 -#define BT_MESH_MODEL_ID_SCHEDULER_CLI 0x1208 -#define BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV 0x1300 -#define BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV 0x1301 -#define BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI 0x1302 -#define BT_MESH_MODEL_ID_LIGHT_CTL_SRV 0x1303 -#define BT_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV 0x1304 -#define BT_MESH_MODEL_ID_LIGHT_CTL_CLI 0x1305 -#define BT_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV 0x1306 -#define BT_MESH_MODEL_ID_LIGHT_HSL_SRV 0x1307 -#define BT_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV 0x1308 -#define BT_MESH_MODEL_ID_LIGHT_HSL_CLI 0x1309 -#define BT_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV 0x130a -#define BT_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV 0x130b -#define BT_MESH_MODEL_ID_LIGHT_XYL_SRV 0x130c -#define BT_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV 0x130d -#define BT_MESH_MODEL_ID_LIGHT_XYL_CLI 0x130e -#define BT_MESH_MODEL_ID_LIGHT_LC_SRV 0x130f -#define BT_MESH_MODEL_ID_LIGHT_LC_SETUPSRV 0x1310 -#define BT_MESH_MODEL_ID_LIGHT_LC_CLI 0x1311 +#define BLE_MESH_MODEL_ID_GEN_ONOFF_SRV 0x1000 +#define BLE_MESH_MODEL_ID_GEN_ONOFF_CLI 0x1001 +#define BLE_MESH_MODEL_ID_GEN_LEVEL_SRV 0x1002 +#define BLE_MESH_MODEL_ID_GEN_LEVEL_CLI 0x1003 +#define BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_SRV 0x1004 +#define BLE_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI 0x1005 +#define BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SRV 0x1006 +#define BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_SETUP_SRV 0x1007 +#define BLE_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI 0x1008 +#define BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SRV 0x1009 +#define BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_SETUP_SRV 0x100a +#define BLE_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI 0x100b +#define BLE_MESH_MODEL_ID_GEN_BATTERY_SRV 0x100c +#define BLE_MESH_MODEL_ID_GEN_BATTERY_CLI 0x100d +#define BLE_MESH_MODEL_ID_GEN_LOCATION_SRV 0x100e +#define BLE_MESH_MODEL_ID_GEN_LOCATION_SETUPSRV 0x100f +#define BLE_MESH_MODEL_ID_GEN_LOCATION_CLI 0x1010 +#define BLE_MESH_MODEL_ID_GEN_ADMIN_PROP_SRV 0x1011 +#define BLE_MESH_MODEL_ID_GEN_MANUFACTURER_PROP_SRV 0x1012 +#define BLE_MESH_MODEL_ID_GEN_USER_PROP_SRV 0x1013 +#define BLE_MESH_MODEL_ID_GEN_CLIENT_PROP_SRV 0x1014 +#define BLE_MESH_MODEL_ID_GEN_PROP_CLI 0x1015 +#define BLE_MESH_MODEL_ID_SENSOR_SRV 0x1100 +#define BLE_MESH_MODEL_ID_SENSOR_SETUP_SRV 0x1101 +#define BLE_MESH_MODEL_ID_SENSOR_CLI 0x1102 +#define BLE_MESH_MODEL_ID_TIME_SRV 0x1200 +#define BLE_MESH_MODEL_ID_TIME_SETUP_SRV 0x1201 +#define BLE_MESH_MODEL_ID_TIME_CLI 0x1202 +#define BLE_MESH_MODEL_ID_SCENE_SRV 0x1203 +#define BLE_MESH_MODEL_ID_SCENE_SETUP_SRV 0x1204 +#define BLE_MESH_MODEL_ID_SCENE_CLI 0x1205 +#define BLE_MESH_MODEL_ID_SCHEDULER_SRV 0x1206 +#define BLE_MESH_MODEL_ID_SCHEDULER_SETUP_SRV 0x1207 +#define BLE_MESH_MODEL_ID_SCHEDULER_CLI 0x1208 +#define BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SRV 0x1300 +#define BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_SETUP_SRV 0x1301 +#define BLE_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI 0x1302 +#define BLE_MESH_MODEL_ID_LIGHT_CTL_SRV 0x1303 +#define BLE_MESH_MODEL_ID_LIGHT_CTL_SETUP_SRV 0x1304 +#define BLE_MESH_MODEL_ID_LIGHT_CTL_CLI 0x1305 +#define BLE_MESH_MODEL_ID_LIGHT_CTL_TEMP_SRV 0x1306 +#define BLE_MESH_MODEL_ID_LIGHT_HSL_SRV 0x1307 +#define BLE_MESH_MODEL_ID_LIGHT_HSL_SETUP_SRV 0x1308 +#define BLE_MESH_MODEL_ID_LIGHT_HSL_CLI 0x1309 +#define BLE_MESH_MODEL_ID_LIGHT_HSL_HUE_SRV 0x130a +#define BLE_MESH_MODEL_ID_LIGHT_HSL_SAT_SRV 0x130b +#define BLE_MESH_MODEL_ID_LIGHT_XYL_SRV 0x130c +#define BLE_MESH_MODEL_ID_LIGHT_XYL_SETUP_SRV 0x130d +#define BLE_MESH_MODEL_ID_LIGHT_XYL_CLI 0x130e +#define BLE_MESH_MODEL_ID_LIGHT_LC_SRV 0x130f +#define BLE_MESH_MODEL_ID_LIGHT_LC_SETUPSRV 0x1310 +#define BLE_MESH_MODEL_ID_LIGHT_LC_CLI 0x1311 /** Message sending context. */ struct bt_mesh_msg_ctx { @@ -144,7 +143,7 @@ struct bt_mesh_msg_ctx { /** Force sending reliably by using segment acknowledgement */ u8_t send_rel: 1; - /** TTL, or BT_MESH_TTL_DEFAULT for default TTL. */ + /** TTL, or BLE_MESH_TTL_DEFAULT for default TTL. */ u8_t send_ttl; /** Change by Espressif, opcode of a received message. @@ -164,7 +163,7 @@ struct bt_mesh_msg_ctx { }; struct bt_mesh_model_op { - /* OpCode encoded using the BT_MESH_MODEL_OP_* macros */ + /* OpCode encoded using the BLE_MESH_MODEL_OP_* macros */ const u32_t opcode; /* Minimum required message length */ @@ -176,43 +175,43 @@ struct bt_mesh_model_op { struct net_buf_simple *buf); }; -#define BT_MESH_MODEL_OP_1(b0) (b0) -#define BT_MESH_MODEL_OP_2(b0, b1) (((b0) << 8) | (b1)) -#define BT_MESH_MODEL_OP_3(b0, cid) ((((b0) << 16) | 0xc00000) | (cid)) +#define BLE_MESH_MODEL_OP_1(b0) (b0) +#define BLE_MESH_MODEL_OP_2(b0, b1) (((b0) << 8) | (b1)) +#define BLE_MESH_MODEL_OP_3(b0, cid) ((((b0) << 16) | 0xc00000) | (cid)) -#define BT_MESH_MODEL_OP_END { 0, 0, NULL } -#define BT_MESH_MODEL_NO_OPS ((struct bt_mesh_model_op []) \ - { BT_MESH_MODEL_OP_END }) +#define BLE_MESH_MODEL_OP_END { 0, 0, NULL } +#define BLE_MESH_MODEL_NO_OPS ((struct bt_mesh_model_op []) \ + { BLE_MESH_MODEL_OP_END }) /** Helper to define an empty model array */ -#define BT_MESH_MODEL_NONE ((struct bt_mesh_model []){}) +#define BLE_MESH_MODEL_NONE ((struct bt_mesh_model []){}) -#define BT_MESH_MODEL(_id, _op, _pub, _user_data) \ -{ \ - .id = (_id), \ - .op = _op, \ - .keys = { [0 ... (CONFIG_BT_MESH_MODEL_KEY_COUNT - 1)] = \ - BT_MESH_KEY_UNUSED }, \ - .pub = _pub, \ - .groups = { [0 ... (CONFIG_BT_MESH_MODEL_GROUP_COUNT - 1)] = \ - BT_MESH_ADDR_UNASSIGNED }, \ - .user_data = _user_data, \ +#define BLE_MESH_MODEL(_id, _op, _pub, _user_data) \ +{ \ + .id = (_id), \ + .op = _op, \ + .keys = { [0 ... (CONFIG_BLE_MESH_MODEL_KEY_COUNT - 1)] = \ + BLE_MESH_KEY_UNUSED }, \ + .pub = _pub, \ + .groups = { [0 ... (CONFIG_BLE_MESH_MODEL_GROUP_COUNT - 1)] = \ + BLE_MESH_ADDR_UNASSIGNED }, \ + .user_data = _user_data, \ } -#define BT_MESH_MODEL_VND(_company, _id, _op, _pub, _user_data) \ -{ \ - .vnd.company = (_company), \ - .vnd.id = (_id), \ - .op = _op, \ - .pub = _pub, \ - .keys = { [0 ... (CONFIG_BT_MESH_MODEL_KEY_COUNT - 1)] = \ - BT_MESH_KEY_UNUSED }, \ - .groups = { [0 ... (CONFIG_BT_MESH_MODEL_GROUP_COUNT - 1)] = \ - BT_MESH_ADDR_UNASSIGNED }, \ - .user_data = _user_data, \ +#define BLE_MESH_MODEL_VND(_company, _id, _op, _pub, _user_data) \ +{ \ + .vnd.company = (_company), \ + .vnd.id = (_id), \ + .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, \ } -/** @def BT_MESH_TRANSMIT +/** @def BLE_MESH_TRANSMIT * * @brief Encode transmission count & interval steps. * @@ -223,9 +222,9 @@ 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 BT_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 BT_MESH_TRANSMIT_COUNT +/** @def BLE_MESH_TRANSMIT_COUNT * * @brief Decode transmit count from a transmit value. * @@ -233,9 +232,9 @@ struct bt_mesh_model_op { * * @return Transmission count (actual transmissions is N + 1). */ -#define BT_MESH_TRANSMIT_COUNT(transmit) (((transmit) & (u8_t)BIT_MASK(3))) +#define BLE_MESH_TRANSMIT_COUNT(transmit) (((transmit) & (u8_t)BIT_MASK(3))) -/** @def BT_MESH_TRANSMIT_INT +/** @def BLE_MESH_TRANSMIT_INT * * @brief Decode transmit interval from a transmit value. * @@ -243,9 +242,9 @@ struct bt_mesh_model_op { * * @return Transmission interval in milliseconds. */ -#define BT_MESH_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 10) +#define BLE_MESH_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 10) -/** @def BT_MESH_PUB_TRANSMIT +/** @def BLE_MESH_PUB_TRANSMIT * * @brief Encode Publish Retransmit count & interval steps. * @@ -256,10 +255,9 @@ 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 BT_MESH_PUB_TRANSMIT(count, int_ms) BT_MESH_TRANSMIT(count, \ - (int_ms) / 5) +#define BLE_MESH_PUB_TRANSMIT(count, int_ms) BLE_MESH_TRANSMIT(count, (int_ms) / 5) -/** @def BT_MESH_PUB_TRANSMIT_COUNT +/** @def BLE_MESH_PUB_TRANSMIT_COUNT * * @brief Decode Pubhlish Retransmit count from a given value. * @@ -267,9 +265,9 @@ struct bt_mesh_model_op { * * @return Retransmission count (actual transmissions is N + 1). */ -#define BT_MESH_PUB_TRANSMIT_COUNT(transmit) BT_MESH_TRANSMIT_COUNT(transmit) +#define BLE_MESH_PUB_TRANSMIT_COUNT(transmit) BLE_MESH_TRANSMIT_COUNT(transmit) -/** @def BT_MESH_PUB_TRANSMIT_INT +/** @def BLE_MESH_PUB_TRANSMIT_INT * * @brief Decode Publish Retransmit interval from a given value. * @@ -277,7 +275,7 @@ struct bt_mesh_model_op { * * @return Transmission interval in milliseconds. */ -#define BT_MESH_PUB_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 50) +#define BLE_MESH_PUB_TRANSMIT_INT(transmit) ((((transmit) >> 3) + 1) * 50) /** Model publication context. */ struct bt_mesh_model_pub { @@ -336,22 +334,6 @@ struct bt_mesh_model_pub { struct k_delayed_work timer; }; -/** @def BT_MESH_MODEL_PUB_DEFINE - * - * Define a model publication context. - * - * @param _name Variable name given to the context. - * @param _update Optional message update callback (may be NULL). - * @param _msg_len Length of the publication message. - */ -#define BT_MESH_MODEL_PUB_DEFINE(_name, _update, _msg_len) \ - NET_BUF_SIMPLE_DEFINE_STATIC(bt_mesh_pub_msg_##_name, _msg_len); \ - static struct bt_mesh_model_pub _name = { \ - .update = _update, \ - .msg = &bt_mesh_pub_msg_##_name, \ - } - - /** Abstraction that describes a Mesh Model instance */ struct bt_mesh_model { union { @@ -369,10 +351,10 @@ struct bt_mesh_model { struct bt_mesh_model_pub *const pub; /* AppKey List */ - u16_t keys[CONFIG_BT_MESH_MODEL_KEY_COUNT]; + u16_t keys[CONFIG_BLE_MESH_MODEL_KEY_COUNT]; /* Subscription List (group or virtual addresses) */ - u16_t groups[CONFIG_BT_MESH_MODEL_GROUP_COUNT]; + u16_t groups[CONFIG_BLE_MESH_MODEL_GROUP_COUNT]; const struct bt_mesh_model_op *const op; @@ -393,10 +375,10 @@ struct bt_mesh_send_cb { void bt_mesh_model_msg_init(struct net_buf_simple *msg, u32_t opcode); /** Special TTL value to request using configured default TTL */ -#define BT_MESH_TTL_DEFAULT 0xff +#define BLE_MESH_TTL_DEFAULT 0xff /** Maximum allowed TTL value */ -#define BT_MESH_TTL_MAX 0x7f +#define BLE_MESH_TTL_MAX 0x7f /** * @brief Send an Access Layer message. @@ -445,5 +427,4 @@ struct bt_mesh_comp { * @} */ -#endif /* __BT_MESH_ACCESS_H */ -#endif /* #if CONFIG_BT_MESH */ +#endif /* __BLE_MESH_ACCESS_H */ diff --git a/components/bt/ble_mesh/mesh_core/include/mesh_aes_encrypt.h b/components/bt/ble_mesh/mesh_core/include/mesh_aes_encrypt.h index 70408c4389..afaa6b27dd 100644 --- a/components/bt/ble_mesh/mesh_core/include/mesh_aes_encrypt.h +++ b/components/bt/ble_mesh/mesh_core/include/mesh_aes_encrypt.h @@ -46,8 +46,8 @@ * 2) call tc_aes_encrypt/decrypt to process the data. */ -#ifndef __TC_AES_H__ -#define __TC_AES_H__ +#ifndef _BLE_MESH_AES_ENCRYPT_H_ +#define _BLE_MESH_AES_ENCRYPT_H_ #include #include @@ -59,16 +59,16 @@ extern "C" { #define Nb (4) /* number of columns (32-bit words) comprising the state */ #define Nk (4) /* number of 32-bit words comprising the key */ #define Nr (10) /* number of rounds */ -#define TC_AES_BLOCK_SIZE (Nb*Nk) -#define TC_AES_KEY_SIZE (Nb*Nk) +#define TC_AES_BLOCK_SIZE (Nb*Nk) +#define TC_AES_KEY_SIZE (Nb*Nk) -#define TC_CRYPTO_SUCCESS 1 -#define TC_CRYPTO_FAIL 0 +#define TC_CRYPTO_SUCCESS 1 +#define TC_CRYPTO_FAIL 0 -#define TC_ZERO_BYTE 0x00 +#define TC_ZERO_BYTE 0x00 /* padding for last message block */ -#define TC_CMAC_PADDING 0x80 +#define TC_CMAC_PADDING 0x80 typedef struct tc_aes_key_sched_struct { unsigned int words[Nb * (Nr + 1)]; @@ -94,7 +94,6 @@ typedef struct tc_cmac_struct { uint64_t countdown; } *TCCmacState_t; - /** * @brief Set AES-128 encryption key * Uses key k to initialize s @@ -169,4 +168,4 @@ int tc_cmac_erase(TCCmacState_t s); } #endif -#endif /* __TC_AES_H__ */ +#endif /* _BLE_MESH_AES_ENCRYPT_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/include/mesh_atomic.h b/components/bt/ble_mesh/mesh_core/include/mesh_atomic.h index fcb7041397..a192949361 100644 --- a/components/bt/ble_mesh/mesh_core/include/mesh_atomic.h +++ b/components/bt/ble_mesh/mesh_core/include/mesh_atomic.h @@ -6,15 +6,16 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef __ATOMIC_H__ -#define __ATOMIC_H__ +#ifndef _BLE_MESH_ATOMIC_H_ +#define _BLE_MESH_ATOMIC_H_ + +#include "mesh_types.h" #ifdef __cplusplus extern "C" { #endif -typedef int atomic_t; -typedef atomic_t atomic_val_t; +typedef bt_mesh_atomic_t bt_mesh_atomic_val_t; /** * @defgroup atomic_apis Atomic Services APIs @@ -22,72 +23,6 @@ typedef atomic_t atomic_val_t; * @{ */ -/** - * @brief Atomic compare-and-set. - * - * This routine performs an atomic compare-and-set on @a target. If the current - * value of @a target equals @a old_value, @a target is set to @a new_value. - * If the current value of @a target does not equal @a old_value, @a target - * is left unchanged. - * - * @param target Address of atomic variable. - * @param old_value Original value to compare against. - * @param new_value New value to store. - * @return 1 if @a new_value is written, 0 otherwise. - */ -#ifdef CONFIG_ATOMIC_OPERATIONS_BUILTIN -static inline int atomic_cas(atomic_t *target, atomic_val_t old_value, - atomic_val_t new_value) -{ - return __atomic_compare_exchange_n(target, &old_value, new_value, - 0, __ATOMIC_SEQ_CST, - __ATOMIC_SEQ_CST); -} -#else -extern int atomic_cas(atomic_t *target, atomic_val_t old_value, - atomic_val_t new_value); -#endif - -/** - * - * @brief Atomic addition. - * - * This routine performs an atomic addition on @a target. - * - * @param target Address of atomic variable. - * @param value Value to add. - * - * @return Previous value of @a target. - */ -#ifdef CONFIG_ATOMIC_OPERATIONS_BUILTIN -static inline atomic_val_t atomic_add(atomic_t *target, atomic_val_t value) -{ - return __atomic_fetch_add(target, value, __ATOMIC_SEQ_CST); -} -#else -extern atomic_val_t atomic_add(atomic_t *target, atomic_val_t value); -#endif - -/** - * - * @brief Atomic subtraction. - * - * This routine performs an atomic subtraction on @a target. - * - * @param target Address of atomic variable. - * @param value Value to subtract. - * - * @return Previous value of @a target. - */ -#ifdef CONFIG_ATOMIC_OPERATIONS_BUILTIN -static inline atomic_val_t atomic_sub(atomic_t *target, atomic_val_t value) -{ - return __atomic_fetch_sub(target, value, __ATOMIC_SEQ_CST); -} -#else -extern atomic_val_t atomic_sub(atomic_t *target, atomic_val_t value); -#endif - /** * * @brief Atomic increment. @@ -99,12 +34,12 @@ extern atomic_val_t atomic_sub(atomic_t *target, atomic_val_t value); * @return Previous value of @a target. */ #ifdef CONFIG_ATOMIC_OPERATIONS_BUILTIN -static inline atomic_val_t atomic_inc(atomic_t *target) +static inline bt_mesh_atomic_val_t bt_mesh_atomic_inc(bt_mesh_atomic_t *target) { - return atomic_add(target, 1); + return bt_mesh_atomic_add(target, 1); } #else -extern atomic_val_t atomic_inc(atomic_t *target); +extern bt_mesh_atomic_val_t bt_mesh_atomic_inc(bt_mesh_atomic_t *target); #endif /** @@ -118,12 +53,12 @@ extern atomic_val_t atomic_inc(atomic_t *target); * @return Previous value of @a target. */ #ifdef CONFIG_ATOMIC_OPERATIONS_BUILTIN -static inline atomic_val_t atomic_dec(atomic_t *target) +static inline bt_mesh_atomic_val_t bt_mesh_atomic_dec(bt_mesh_atomic_t *target) { - return atomic_sub(target, 1); + return bt_mesh_atomic_sub(target, 1); } #else -extern atomic_val_t atomic_dec(atomic_t *target); +extern bt_mesh_atomic_val_t bt_mesh_atomic_dec(bt_mesh_atomic_t *target); #endif /** @@ -137,12 +72,12 @@ extern atomic_val_t atomic_dec(atomic_t *target); * @return Value of @a target. */ #ifdef CONFIG_ATOMIC_OPERATIONS_BUILTIN -static inline atomic_val_t atomic_get(const atomic_t *target) +static inline bt_mesh_atomic_val_t bt_mesh_atomic_get(const bt_mesh_atomic_t *target) { return __atomic_load_n(target, __ATOMIC_SEQ_CST); } #else -extern atomic_val_t atomic_get(const atomic_t *target); +extern bt_mesh_atomic_val_t bt_mesh_atomic_get(const bt_mesh_atomic_t *target); #endif /** @@ -158,7 +93,7 @@ extern atomic_val_t atomic_get(const atomic_t *target); * @return Previous value of @a target. */ #ifdef CONFIG_ATOMIC_OPERATIONS_BUILTIN -static inline atomic_val_t atomic_set(atomic_t *target, atomic_val_t value) +static inline bt_mesh_atomic_val_t bt_mesh_atomic_set(bt_mesh_atomic_t *target, bt_mesh_atomic_val_t value) { /* This builtin, as described by Intel, is not a traditional * test-and-set operation, but rather an atomic exchange operation. It @@ -167,27 +102,7 @@ static inline atomic_val_t atomic_set(atomic_t *target, atomic_val_t value) return __atomic_exchange_n(target, value, __ATOMIC_SEQ_CST); } #else -extern atomic_val_t atomic_set(atomic_t *target, atomic_val_t value); -#endif - -/** - * - * @brief Atomic clear. - * - * This routine atomically sets @a target to zero and returns its previous - * value. (Hence, it is equivalent to atomic_set(target, 0).) - * - * @param target Address of atomic variable. - * - * @return Previous value of @a target. - */ -#ifdef CONFIG_ATOMIC_OPERATIONS_BUILTIN -static inline atomic_val_t atomic_clear(atomic_t *target) -{ - return atomic_set(target, 0); -} -#else -extern atomic_val_t atomic_clear(atomic_t *target); +extern bt_mesh_atomic_val_t bt_mesh_atomic_set(bt_mesh_atomic_t *target, bt_mesh_atomic_val_t value); #endif /** @@ -203,33 +118,12 @@ extern atomic_val_t atomic_clear(atomic_t *target); * @return Previous value of @a target. */ #ifdef CONFIG_ATOMIC_OPERATIONS_BUILTIN -static inline atomic_val_t atomic_or(atomic_t *target, atomic_val_t value) +static inline bt_mesh_atomic_val_t bt_mesh_atomic_or(bt_mesh_atomic_t *target, bt_mesh_atomic_val_t value) { return __atomic_fetch_or(target, value, __ATOMIC_SEQ_CST); } #else -extern atomic_val_t atomic_or(atomic_t *target, atomic_val_t value); -#endif - -/** - * - * @brief Atomic bitwise exclusive OR (XOR). - * - * This routine atomically sets @a target to the bitwise exclusive OR (XOR) of - * @a target and @a value. - * - * @param target Address of atomic variable. - * @param value Value to XOR - * - * @return Previous value of @a target. - */ -#ifdef CONFIG_ATOMIC_OPERATIONS_BUILTIN -static inline atomic_val_t atomic_xor(atomic_t *target, atomic_val_t value) -{ - return __atomic_fetch_xor(target, value, __ATOMIC_SEQ_CST); -} -#else -extern atomic_val_t atomic_xor(atomic_t *target, atomic_val_t value); +extern bt_mesh_atomic_val_t bt_mesh_atomic_or(bt_mesh_atomic_t *target, bt_mesh_atomic_val_t value); #endif /** @@ -245,53 +139,21 @@ extern atomic_val_t atomic_xor(atomic_t *target, atomic_val_t value); * @return Previous value of @a target. */ #ifdef CONFIG_ATOMIC_OPERATIONS_BUILTIN -static inline atomic_val_t atomic_and(atomic_t *target, atomic_val_t value) +static inline bt_mesh_atomic_val_t bt_mesh_atomic_and(bt_mesh_atomic_t *target, bt_mesh_atomic_val_t value) { return __atomic_fetch_and(target, value, __ATOMIC_SEQ_CST); } #else -extern atomic_val_t atomic_and(atomic_t *target, atomic_val_t value); +extern bt_mesh_atomic_val_t bt_mesh_atomic_and(bt_mesh_atomic_t *target, bt_mesh_atomic_val_t value); #endif -/** - * - * @brief Atomic bitwise NAND. - * - * This routine atomically sets @a target to the bitwise NAND of @a target - * and @a value. (This operation is equivalent to target = ~(target & value).) - * - * @param target Address of atomic variable. - * @param value Value to NAND. - * - * @return Previous value of @a target. - */ -#ifdef CONFIG_ATOMIC_OPERATIONS_BUILTIN -static inline atomic_val_t atomic_nand(atomic_t *target, atomic_val_t value) -{ - return __atomic_fetch_nand(target, value, __ATOMIC_SEQ_CST); -} -#else -extern atomic_val_t atomic_nand(atomic_t *target, atomic_val_t value); -#endif - - -/** - * @brief Initialize an atomic variable. - * - * This macro can be used to initialize an atomic variable. For example, - * @code atomic_t my_var = ATOMIC_INIT(75); @endcode - * - * @param i Value to assign to atomic variable. - */ -#define ATOMIC_INIT(i) (i) - /** * @cond INTERNAL_HIDDEN */ -#define ATOMIC_BITS (sizeof(atomic_val_t) * 8) -#define ATOMIC_MASK(bit) (1 << ((bit) & (ATOMIC_BITS - 1))) -#define ATOMIC_ELEM(addr, bit) ((addr) + ((bit) / ATOMIC_BITS)) +#define BLE_MESH_ATOMIC_BITS (sizeof(bt_mesh_atomic_val_t) * 8) +#define BLE_MESH_ATOMIC_MASK(bit) (1 << ((bit) & (BLE_MESH_ATOMIC_BITS - 1))) +#define BLE_MESH_ATOMIC_ELEM(addr, bit) ((addr) + ((bit) / BLE_MESH_ATOMIC_BITS)) /** * INTERNAL_HIDDEN @endcond @@ -310,8 +172,8 @@ extern atomic_val_t atomic_nand(atomic_t *target, atomic_val_t value); * @param name Name of array of atomic variables. * @param num_bits Number of bits needed. */ -#define ATOMIC_DEFINE(name, num_bits) \ - atomic_t name[1 + ((num_bits) - 1) / ATOMIC_BITS] +#define BLE_MESH_ATOMIC_DEFINE(name, num_bits) \ + bt_mesh_atomic_t name[1 + ((num_bits) - 1) / BLE_MESH_ATOMIC_BITS] /** * @brief Atomically test a bit. @@ -324,11 +186,11 @@ extern atomic_val_t atomic_nand(atomic_t *target, atomic_val_t value); * * @return 1 if the bit was set, 0 if it wasn't. */ -static inline int atomic_test_bit(const atomic_t *target, int bit) +static inline int bt_mesh_atomic_test_bit(const bt_mesh_atomic_t *target, int bit) { - atomic_val_t val = atomic_get(ATOMIC_ELEM(target, bit)); + bt_mesh_atomic_val_t val = bt_mesh_atomic_get(BLE_MESH_ATOMIC_ELEM(target, bit)); - return (1 & (val >> (bit & (ATOMIC_BITS - 1)))); + return (1 & (val >> (bit & (BLE_MESH_ATOMIC_BITS - 1)))); } /** @@ -342,12 +204,12 @@ static inline int atomic_test_bit(const atomic_t *target, int bit) * * @return 1 if the bit was set, 0 if it wasn't. */ -static inline int atomic_test_and_clear_bit(atomic_t *target, int bit) +static inline int bt_mesh_atomic_test_and_clear_bit(bt_mesh_atomic_t *target, int bit) { - atomic_val_t mask = ATOMIC_MASK(bit); - atomic_val_t old; + bt_mesh_atomic_val_t mask = BLE_MESH_ATOMIC_MASK(bit); + bt_mesh_atomic_val_t old; - old = atomic_and(ATOMIC_ELEM(target, bit), ~mask); + old = bt_mesh_atomic_and(BLE_MESH_ATOMIC_ELEM(target, bit), ~mask); return (old & mask) != 0; } @@ -363,12 +225,12 @@ static inline int atomic_test_and_clear_bit(atomic_t *target, int bit) * * @return 1 if the bit was set, 0 if it wasn't. */ -static inline int atomic_test_and_set_bit(atomic_t *target, int bit) +static inline int bt_mesh_atomic_test_and_set_bit(bt_mesh_atomic_t *target, int bit) { - atomic_val_t mask = ATOMIC_MASK(bit); - atomic_val_t old; + bt_mesh_atomic_val_t mask = BLE_MESH_ATOMIC_MASK(bit); + bt_mesh_atomic_val_t old; - old = atomic_or(ATOMIC_ELEM(target, bit), mask); + old = bt_mesh_atomic_or(BLE_MESH_ATOMIC_ELEM(target, bit), mask); return (old & mask) != 0; } @@ -384,11 +246,11 @@ static inline int atomic_test_and_set_bit(atomic_t *target, int bit) * * @return N/A */ -static inline void atomic_clear_bit(atomic_t *target, int bit) +static inline void bt_mesh_atomic_clear_bit(bt_mesh_atomic_t *target, int bit) { - atomic_val_t mask = ATOMIC_MASK(bit); + bt_mesh_atomic_val_t mask = BLE_MESH_ATOMIC_MASK(bit); - atomic_and(ATOMIC_ELEM(target, bit), ~mask); + bt_mesh_atomic_and(BLE_MESH_ATOMIC_ELEM(target, bit), ~mask); } /** @@ -402,11 +264,11 @@ static inline void atomic_clear_bit(atomic_t *target, int bit) * * @return N/A */ -static inline void atomic_set_bit(atomic_t *target, int bit) +static inline void bt_mesh_atomic_set_bit(bt_mesh_atomic_t *target, int bit) { - atomic_val_t mask = ATOMIC_MASK(bit); + bt_mesh_atomic_val_t mask = BLE_MESH_ATOMIC_MASK(bit); - atomic_or(ATOMIC_ELEM(target, bit), mask); + bt_mesh_atomic_or(BLE_MESH_ATOMIC_ELEM(target, bit), mask); } /** @@ -417,4 +279,4 @@ static inline void atomic_set_bit(atomic_t *target, int bit) } #endif -#endif /* __ATOMIC_H__ */ +#endif /* _BLE_MESH_ATOMIC_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/include/mesh_bearer_adapt.h b/components/bt/ble_mesh/mesh_core/include/mesh_bearer_adapt.h index 1c54a372a8..8b61c7231b 100644 --- a/components/bt/ble_mesh/mesh_core/include/mesh_bearer_adapt.h +++ b/components/bt/ble_mesh/mesh_core/include/mesh_bearer_adapt.h @@ -6,102 +6,130 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef _MESH_BEARER_ADRPT_H_ -#define _MESH_BEARER_ADRPT_H_ +#ifndef _BLE_MESH_BEARER_ADRPT_H_ +#define _BLE_MESH_BEARER_ADRPT_H_ #include #include "mesh_types.h" +#include "mesh_util.h" #include "mesh_buf.h" -#include "mesh_bt_uuid.h" +#include "mesh_uuid.h" + +/* BD ADDR types */ +#define BLE_MESH_ADDR_PUBLIC 0x00 +#define BLE_MESH_ADDR_RANDOM 0x01 +#define BLE_MESH_ADDR_PUBLIC_ID 0x02 +#define BLE_MESH_ADDR_RANDOM_ID 0x03 + +/* BD ADDR length */ +#define BLE_MESH_ADDR_LEN 0x06 /* Advertising types */ -#define BT_LE_ADV_IND 0x00 -#define BT_LE_ADV_DIRECT_IND 0x01 -#define BT_LE_ADV_SCAN_IND 0x02 -#define BT_LE_ADV_NONCONN_IND 0x03 -#define BT_LE_ADV_DIRECT_IND_LOW_DUTY 0x04 -/* Needed in advertising reports when getting info about */ -#define BT_LE_ADV_SCAN_RSP 0x04 +#define BLE_MESH_ADV_IND 0x00 +#define BLE_MESH_ADV_DIRECT_IND 0x01 +#define BLE_MESH_ADV_SCAN_IND 0x02 +#define BLE_MESH_ADV_NONCONN_IND 0x03 +#define BLE_MESH_ADV_DIRECT_IND_LOW_DUTY 0x04 -#define BT_HCI_LE_SCAN_PASSIVE 0x00 -#define BT_HCI_LE_SCAN_ACTIVE 0x01 +/* advertising channel map */ +#define BLE_MESH_ADV_CHNL_37 BIT(0) +#define BLE_MESH_ADV_CHNL_38 BIT(1) +#define BLE_MESH_ADV_CHNL_39 BIT(2) -#define BT_HCI_LE_SCAN_DISABLE 0x00 -#define BT_HCI_LE_SCAN_ENABLE 0x01 +/* Advertising filter policy */ +#define BLE_MESH_AP_SCAN_CONN_ALL 0x00 +#define BLE_MESH_AP_SCAN_WL_CONN_ALL 0x01 +#define BLE_MESH_AP_SCAN_ALL_CONN_WL 0x02 +#define BLE_MESH_AP_SCAN_CONN_WL 0x03 -#define BT_HCI_LE_SCAN_FILTER_DUP_DISABLE 0x00 -#define BT_HCI_LE_SCAN_FILTER_DUP_ENABLE 0x01 +/* Scan types */ +#define BLE_MESH_SCAN_PASSIVE 0x00 +#define BLE_MESH_SCAN_ACTIVE 0x01 + +/* Scan operation */ +#define BLE_MESH_SCAN_DISABLE 0x00 +#define BLE_MESH_SCAN_ENABLE 0x01 + +/* Scan duplicate operation */ +#define BLE_MESH_SCAN_FILTER_DUP_DISABLE 0x00 +#define BLE_MESH_SCAN_FILTER_DUP_ENABLE 0x01 + +/* Scan filter policy */ +#define BLE_MESH_SP_ADV_ALL 0x00 +#define BLE_MESH_SP_ADV_WL 0x01 +#define BLE_MESH_SP_ADV_ALL_RPA_DIR_ADV 0x02 +#define BLE_MESH_SP_ADV_WL_RPA_DIR_ADV 0x03 /* Error codes for Error response PDU */ -#define BT_ATT_ERR_INVALID_HANDLE 0x01 -#define BT_ATT_ERR_READ_NOT_PERMITTED 0x02 -#define BT_ATT_ERR_WRITE_NOT_PERMITTED 0x03 -#define BT_ATT_ERR_INVALID_PDU 0x04 -#define BT_ATT_ERR_AUTHENTICATION 0x05 -#define BT_ATT_ERR_NOT_SUPPORTED 0x06 -#define BT_ATT_ERR_INVALID_OFFSET 0x07 -#define BT_ATT_ERR_AUTHORIZATION 0x08 -#define BT_ATT_ERR_PREPARE_QUEUE_FULL 0x09 -#define BT_ATT_ERR_ATTRIBUTE_NOT_FOUND 0x0a -#define BT_ATT_ERR_ATTRIBUTE_NOT_LONG 0x0b -#define BT_ATT_ERR_ENCRYPTION_KEY_SIZE 0x0c -#define BT_ATT_ERR_INVALID_ATTRIBUTE_LEN 0x0d -#define BT_ATT_ERR_UNLIKELY 0x0e -#define BT_ATT_ERR_INSUFFICIENT_ENCRYPTION 0x0f -#define BT_ATT_ERR_UNSUPPORTED_GROUP_TYPE 0x10 -#define BT_ATT_ERR_INSUFFICIENT_RESOURCES 0x11 +#define BLE_MESH_ATT_ERR_INVALID_HANDLE 0x01 +#define BLE_MESH_ATT_ERR_READ_NOT_PERMITTED 0x02 +#define BLE_MESH_ATT_ERR_WRITE_NOT_PERMITTED 0x03 +#define BLE_MESH_ATT_ERR_INVALID_PDU 0x04 +#define BLE_MESH_ATT_ERR_AUTHENTICATION 0x05 +#define BLE_MESH_ATT_ERR_NOT_SUPPORTED 0x06 +#define BLE_MESH_ATT_ERR_INVALID_OFFSET 0x07 +#define BLE_MESH_ATT_ERR_AUTHORIZATION 0x08 +#define BLE_MESH_ATT_ERR_PREPARE_QUEUE_FULL 0x09 +#define BLE_MESH_ATT_ERR_ATTRIBUTE_NOT_FOUND 0x0a +#define BLE_MESH_ATT_ERR_ATTRIBUTE_NOT_LONG 0x0b +#define BLE_MESH_ATT_ERR_ENCRYPTION_KEY_SIZE 0x0c +#define BLE_MESH_ATT_ERR_INVALID_ATTRIBUTE_LEN 0x0d +#define BLE_MESH_ATT_ERR_UNLIKELY 0x0e +#define BLE_MESH_ATT_ERR_INSUFFICIENT_ENCRYPTION 0x0f +#define BLE_MESH_ATT_ERR_UNSUPPORTED_GROUP_TYPE 0x10 +#define BLE_MESH_ATT_ERR_INSUFFICIENT_RESOURCES 0x11 /* Common Profile Error Codes (from CSS) */ -#define BT_ATT_ERR_WRITE_REQ_REJECTED 0xfc -#define BT_ATT_ERR_CCC_IMPROPER_CONF 0xfd -#define BT_ATT_ERR_PROCEDURE_IN_PROGRESS 0xfe -#define BT_ATT_ERR_OUT_OF_RANGE 0xff +#define BLE_MESH_ATT_ERR_WRITE_REQ_REJECTED 0xfc +#define BLE_MESH_ATT_ERR_CCC_IMPROPER_CONF 0xfd +#define BLE_MESH_ATT_ERR_PROCEDURE_IN_PROGRESS 0xfe +#define BLE_MESH_ATT_ERR_OUT_OF_RANGE 0xff /* EIR/AD data type definitions */ -#define BT_DATA_FLAGS 0x01 /* AD flags */ -#define BT_DATA_UUID16_SOME 0x02 /* 16-bit UUID, more available */ -#define BT_DATA_UUID16_ALL 0x03 /* 16-bit UUID, all listed */ -#define BT_DATA_UUID32_SOME 0x04 /* 32-bit UUID, more available */ -#define BT_DATA_UUID32_ALL 0x05 /* 32-bit UUID, all listed */ -#define BT_DATA_UUID128_SOME 0x06 /* 128-bit UUID, more available */ -#define BT_DATA_UUID128_ALL 0x07 /* 128-bit UUID, all listed */ -#define BT_DATA_NAME_SHORTENED 0x08 /* Shortened name */ -#define BT_DATA_NAME_COMPLETE 0x09 /* Complete name */ -#define BT_DATA_TX_POWER 0x0a /* Tx Power */ -#define BT_DATA_SOLICIT16 0x14 /* Solicit UUIDs, 16-bit */ -#define BT_DATA_SOLICIT128 0x15 /* Solicit UUIDs, 128-bit */ -#define BT_DATA_SVC_DATA16 0x16 /* Service data, 16-bit UUID */ -#define BT_DATA_GAP_APPEARANCE 0x19 /* GAP appearance */ -#define BT_DATA_SOLICIT32 0x1f /* Solicit UUIDs, 32-bit */ -#define BT_DATA_SVC_DATA32 0x20 /* Service data, 32-bit UUID */ -#define BT_DATA_SVC_DATA128 0x21 /* Service data, 128-bit UUID */ -#define BT_DATA_MESH_PROV 0x29 /* Mesh Provisioning PDU */ -#define BT_DATA_MESH_MESSAGE 0x2a /* Mesh Networking PDU */ -#define BT_DATA_MESH_BEACON 0x2b /* Mesh Beacon */ +#define BLE_MESH_DATA_FLAGS 0x01 /* AD flags */ +#define BLE_MESH_DATA_UUID16_SOME 0x02 /* 16-bit UUID, more available */ +#define BLE_MESH_DATA_UUID16_ALL 0x03 /* 16-bit UUID, all listed */ +#define BLE_MESH_DATA_UUID32_SOME 0x04 /* 32-bit UUID, more available */ +#define BLE_MESH_DATA_UUID32_ALL 0x05 /* 32-bit UUID, all listed */ +#define BLE_MESH_DATA_UUID128_SOME 0x06 /* 128-bit UUID, more available */ +#define BLE_MESH_DATA_UUID128_ALL 0x07 /* 128-bit UUID, all listed */ +#define BLE_MESH_DATA_NAME_SHORTENED 0x08 /* Shortened name */ +#define BLE_MESH_DATA_NAME_COMPLETE 0x09 /* Complete name */ +#define BLE_MESH_DATA_TX_POWER 0x0a /* Tx Power */ +#define BLE_MESH_DATA_SOLICIT16 0x14 /* Solicit UUIDs, 16-bit */ +#define BLE_MESH_DATA_SOLICIT128 0x15 /* Solicit UUIDs, 128-bit */ +#define BLE_MESH_DATA_SVC_DATA16 0x16 /* Service data, 16-bit UUID */ +#define BLE_MESH_DATA_GAP_APPEARANCE 0x19 /* GAP appearance */ +#define BLE_MESH_DATA_SOLICIT32 0x1f /* Solicit UUIDs, 32-bit */ +#define BLE_MESH_DATA_SVC_DATA32 0x20 /* Service data, 32-bit UUID */ +#define BLE_MESH_DATA_SVC_DATA128 0x21 /* Service data, 128-bit UUID */ +#define BLE_MESH_DATA_MESH_PROV 0x29 /* Mesh Provisioning PDU */ +#define BLE_MESH_DATA_MESH_MESSAGE 0x2a /* Mesh Networking PDU */ +#define BLE_MESH_DATA_MESH_BEACON 0x2b /* Mesh Beacon */ -#define BT_DATA_MANUFACTURER_DATA 0xff /* Manufacturer Specific Data */ +#define BLE_MESH_DATA_MANUFACTURER_DATA 0xff /* Manufacturer Specific Data */ -#define BT_LE_AD_LIMITED 0x01 /* Limited Discoverable */ -#define BT_LE_AD_GENERAL 0x02 /* General Discoverable */ -#define BT_LE_AD_NO_BREDR 0x04 /* BR/EDR not supported */ +#define BLE_MESH_AD_LIMITED 0x01 /* Limited Discoverable */ +#define BLE_MESH_AD_GENERAL 0x02 /* General Discoverable */ +#define BLE_MESH_AD_NO_BREDR 0x04 /* BR/EDR not supported */ /* Client Characteristic Configuration Values */ -/** @def BT_GATT_CCC_NOTIFY +/** @def BLE_MESH_GATT_CCC_NOTIFY * @brief Client Characteristic Configuration Notification. * * If set, changes to Characteristic Value shall be notified. */ -#define BT_GATT_CCC_NOTIFY 0x0001 -/** @def BT_GATT_CCC_INDICATE +#define BLE_MESH_GATT_CCC_NOTIFY 0x0001 + +/** @def BLE_MESH_GATT_CCC_INDICATE * @brief Client Characteristic Configuration Indication. * * If set, changes to Characteristic Value shall be indicated. */ -#define BT_GATT_CCC_INDICATE 0x0002 +#define BLE_MESH_GATT_CCC_INDICATE 0x0002 - -/** @def BT_GATT_ERR +/** @def BLE_MESH_GATT_ERR * @brief Construct error return value for attribute read and write callbacks. * * @param _att_err ATT error code @@ -109,218 +137,191 @@ * @return Appropriate error code for the attribute callbacks. * */ -#define BT_GATT_ERR(_att_err) (-(_att_err)) +#define BLE_MESH_GATT_ERR(_att_err) (-(_att_err)) enum { - BT_GATT_ITER_STOP = 0, - BT_GATT_ITER_CONTINUE, + BLE_MESH_GATT_ITER_STOP = 0, + BLE_MESH_GATT_ITER_CONTINUE, }; /* GATT attribute permission bit field values */ enum { /** No operations supported, e.g. for notify-only */ - BT_GATT_PERM_NONE = 0, + BLE_MESH_GATT_PERM_NONE = 0, /** Attribute read permission. */ - BT_GATT_PERM_READ = BIT(0), + BLE_MESH_GATT_PERM_READ = BIT(0), /** Attribute write permission. */ - BT_GATT_PERM_WRITE = BIT(1), + BLE_MESH_GATT_PERM_WRITE = BIT(1), /** Attribute read permission with encryption. * * If set, requires encryption for read access. */ - BT_GATT_PERM_READ_ENCRYPT = BIT(2), + BLE_MESH_GATT_PERM_READ_ENCRYPT = BIT(2), /** Attribute write permission with encryption. * * If set, requires encryption for write access. */ - BT_GATT_PERM_WRITE_ENCRYPT = BIT(3), + BLE_MESH_GATT_PERM_WRITE_ENCRYPT = BIT(3), /** Attribute read permission with authentication. * * If set, requires encryption using authenticated link-key for read * access. */ - BT_GATT_PERM_READ_AUTHEN = BIT(4), + BLE_MESH_GATT_PERM_READ_AUTHEN = BIT(4), /** Attribute write permission with authentication. * * If set, requires encryption using authenticated link-key for write * access. */ - BT_GATT_PERM_WRITE_AUTHEN = BIT(5), + BLE_MESH_GATT_PERM_WRITE_AUTHEN = BIT(5), /** Attribute prepare write permission. * * If set, allows prepare writes with use of BT_GATT_WRITE_FLAG_PREPARE * passed to write callback. */ - BT_GATT_PERM_PREPARE_WRITE = BIT(6), + BLE_MESH_GATT_PERM_PREPARE_WRITE = BIT(6), }; /** Advertising options */ enum { /** Convenience value when no options are specified. */ - BT_LE_ADV_OPT_NONE = 0, + BLE_MESH_ADV_OPT_NONE = 0, /** Advertise as connectable. Type of advertising is determined by * providing SCAN_RSP data and/or enabling local privacy support. */ - BT_LE_ADV_OPT_CONNECTABLE = BIT(0), + BLE_MESH_ADV_OPT_CONNECTABLE = BIT(0), /** Don't try to resume connectable advertising after a connection. * This option is only meaningful when used together with - * BT_LE_ADV_OPT_CONNECTABLE. If set the advertising will be stopped + * BLE_MESH_ADV_OPT_CONNECTABLE. If set the advertising will be stopped * when bt_le_adv_stop() is called or when an incoming (slave) * connection happens. If this option is not set the stack will * take care of keeping advertising enabled even as connections * occur. */ - BT_LE_ADV_OPT_ONE_TIME = BIT(1), + BLE_MESH_ADV_OPT_ONE_TIME = BIT(1), }; /* Defined GAP timers */ -#define BT_GAP_SCAN_FAST_INTERVAL 0x0060 /* 60 ms */ -#define BT_GAP_SCAN_FAST_WINDOW 0x0030 /* 30 ms */ -#define BT_GAP_SCAN_SLOW_INTERVAL_1 0x0800 /* 1.28 s */ -#define BT_GAP_SCAN_SLOW_WINDOW_1 0x0012 /* 11.25 ms */ -#define BT_GAP_SCAN_SLOW_INTERVAL_2 0x1000 /* 2.56 s */ -#define BT_GAP_SCAN_SLOW_WINDOW_2 0x0012 /* 11.25 ms */ -#define BT_GAP_ADV_FAST_INT_MIN_0 0x0020 /* 20 ms */ -#define BT_GAP_ADV_FAST_INT_MAX_0 0x0020 /* 20 ms */ -#define BT_GAP_ADV_FAST_INT_MIN_1 0x0030 /* 30 ms */ -#define BT_GAP_ADV_FAST_INT_MAX_1 0x0060 /* 60 ms */ -#define BT_GAP_ADV_FAST_INT_MIN_2 0x00a0 /* 100 ms */ -#define BT_GAP_ADV_FAST_INT_MAX_2 0x00f0 /* 150 ms */ -#define BT_GAP_ADV_SLOW_INT_MIN 0x0320 //0x0640 /* 1 s */ -#define BT_GAP_ADV_SLOW_INT_MAX 0x0320 //0x0780 /* 1.2 s */ -#define BT_GAP_INIT_CONN_INT_MIN 0x0018 /* 30 ms */ -#define BT_GAP_INIT_CONN_INT_MAX 0x0028 /* 50 ms */ - - +#define BLE_MESH_GAP_SCAN_FAST_INTERVAL 0x0060 /* 60 ms */ +#define BLE_MESH_GAP_SCAN_FAST_WINDOW 0x0030 /* 30 ms */ +#define BLE_MESH_GAP_SCAN_SLOW_INTERVAL_1 0x0800 /* 1.28 s */ +#define BLE_MESH_GAP_SCAN_SLOW_WINDOW_1 0x0012 /* 11.25 ms */ +#define BLE_MESH_GAP_SCAN_SLOW_INTERVAL_2 0x1000 /* 2.56 s */ +#define BLE_MESH_GAP_SCAN_SLOW_WINDOW_2 0x0012 /* 11.25 ms */ +#define BLE_MESH_GAP_ADV_FAST_INT_MIN_0 0x0020 /* 20 ms */ +#define BLE_MESH_GAP_ADV_FAST_INT_MAX_0 0x0020 /* 20 ms */ +#define BLE_MESH_GAP_ADV_FAST_INT_MIN_1 0x0030 /* 30 ms */ +#define BLE_MESH_GAP_ADV_FAST_INT_MAX_1 0x0060 /* 60 ms */ +#define BLE_MESH_GAP_ADV_FAST_INT_MIN_2 0x00a0 /* 100 ms */ +#define BLE_MESH_GAP_ADV_FAST_INT_MAX_2 0x00f0 /* 150 ms */ +#define BLE_MESH_GAP_ADV_SLOW_INT_MIN 0x0320 /* 500 ms */ +#define BLE_MESH_GAP_ADV_SLOW_INT_MAX 0x0320 /* 500 ms */ +#define BLE_MESH_GAP_INIT_CONN_INT_MIN 0x0018 /* 30 ms */ +#define BLE_MESH_GAP_INIT_CONN_INT_MAX 0x0028 /* 50 ms */ /* Characteristic Properties Bit field values */ -/** @def BT_GATT_CHRC_BROADCAST +/** @def BLE_MESH_GATT_CHRC_BROADCAST * @brief Characteristic broadcast property. * * If set, permits broadcasts of the Characteristic Value using Server * Characteristic Configuration Descriptor. */ -#define BT_GATT_CHRC_BROADCAST 0x01 -/** @def BT_GATT_CHRC_READ +#define BLE_MESH_GATT_CHRC_BROADCAST 0x01 + +/** @def BLE_MESH_GATT_CHRC_READ * @brief Characteristic read property. * * If set, permits reads of the Characteristic Value. */ -#define BT_GATT_CHRC_READ 0x02 -/** @def BT_GATT_CHRC_WRITE_WITHOUT_RESP +#define BLE_MESH_GATT_CHRC_READ 0x02 + +/** @def BLE_MESH_GATT_CHRC_WRITE_WITHOUT_RESP * @brief Characteristic write without response property. * * If set, permits write of the Characteristic Value without response. */ -#define BT_GATT_CHRC_WRITE_WITHOUT_RESP 0x04 -/** @def BT_GATT_CHRC_WRITE +#define BLE_MESH_GATT_CHRC_WRITE_WITHOUT_RESP 0x04 + +/** @def BLE_MESH_GATT_CHRC_WRITE * @brief Characteristic write with response property. * * If set, permits write of the Characteristic Value with response. */ -#define BT_GATT_CHRC_WRITE 0x08 -/** @def BT_GATT_CHRC_NOTIFY +#define BLE_MESH_GATT_CHRC_WRITE 0x08 + +/** @def BLE_MESH_GATT_CHRC_NOTIFY * @brief Characteristic notify property. * * If set, permits notifications of a Characteristic Value without * acknowledgment. */ -#define BT_GATT_CHRC_NOTIFY 0x10 -/** @def BT_GATT_CHRC_INDICATE +#define BLE_MESH_GATT_CHRC_NOTIFY 0x10 + +/** @def BLE_MESH_GATT_CHRC_INDICATE * @brief Characteristic indicate property. * * If set, permits indications of a Characteristic Value with acknowledgment. */ -#define BT_GATT_CHRC_INDICATE 0x20 -/** @def BT_GATT_CHRC_AUTH +#define BLE_MESH_GATT_CHRC_INDICATE 0x20 + +/** @def BLE_MESH_GATT_CHRC_AUTH * @brief Characteristic Authenticated Signed Writes property. * * If set, permits signed writes to the Characteristic Value. */ -#define BT_GATT_CHRC_AUTH 0x40 -/** @def BT_GATT_CHRC_EXT_PROP +#define BLE_MESH_GATT_CHRC_AUTH 0x40 + +/** @def BLE_MESH_GATT_CHRC_EXT_PROP * @brief Characteristic Extended Properties property. * * If set, additional characteristic properties are defined in the * Characteristic Extended Properties Descriptor. */ -#define BT_GATT_CHRC_EXT_PROP 0x80 - +#define BLE_MESH_GATT_CHRC_EXT_PROP 0x80 /** @brief Characteristic Attribute Value. */ -struct bt_gatt_chrc { +struct bt_mesh_gatt_char { /** Characteristic UUID. */ - const struct bt_uuid *uuid; + const struct bt_mesh_uuid *uuid; /** Characteristic properties. */ - u8_t properties; + u8_t properties; }; /** @brief GATT Service structure */ -struct bt_gatt_service { +struct bt_mesh_gatt_service { /** Service Attributes */ - struct bt_gatt_attr *attrs; + struct bt_mesh_gatt_attr *attrs; /** Service Attribute count */ - u16_t attr_count; - sys_snode_t node; + u16_t attr_count; + sys_snode_t node; }; -/* - * Copyright (c) 2015 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ -typedef enum __packed { - BT_CONN_DISCONNECTED, - BT_CONN_CONNECT_SCAN, - BT_CONN_CONNECT, - BT_CONN_CONNECTED, - BT_CONN_DISCONNECT, -} bt_conn_state_t; - -/** Security level. */ -typedef enum __packed { - /** Only for BR/EDR special cases, like SDP */ - BT_SECURITY_NONE, - /** No encryption and no authentication. */ - BT_SECURITY_LOW, - /** Encryption and no authentication (no MITM). */ - BT_SECURITY_MEDIUM, - /** Encryption and authentication (MITM). */ - BT_SECURITY_HIGH, - /** Authenticated Secure Connections */ - BT_SECURITY_FIPS, -} bt_security_t; - -struct ecb_param { +struct bt_mesh_ecb_param { u8_t key[16]; u8_t clear_text[16]; u8_t cipher_text[16]; } __packed; typedef struct { - u8_t val[6]; -} bt_addr_t; - -typedef struct { - u8_t type; - bt_addr_t a; -} bt_addr_le_t; + u8_t type; + u8_t val[6]; +} bt_mesh_addr_t; /** Description of different data types that can be encoded into * advertising data. Used to form arrays that are passed to the * bt_le_adv_start() function. */ -struct bt_data { +struct bt_mesh_adv_data { u8_t type; u8_t data_len; const u8_t *data; @@ -328,34 +329,35 @@ struct bt_data { /** @brief Helper to declare elements of bt_data arrays * - * This macro is mainly for creating an array of struct bt_data - * elements which is then passed to bt_le_adv_start(). + * This macro is mainly for creating an array of struct + * bt_mesh_adv_data elements which is then passed to + * bt_le_adv_start(). * * @param _type Type of advertising data field * @param _data Pointer to the data field payload * @param _data_len Number of bytes behind the _data pointer */ -#define BT_DATA(_type, _data, _data_len) \ - { \ - .type = (_type), \ - .data_len = (_data_len), \ - .data = (const u8_t *)(_data), \ +#define BLE_MESH_ADV_DATA(_type, _data, _data_len) \ + { \ + .type = (_type), \ + .data_len = (_data_len), \ + .data = (const u8_t *)(_data), \ } /** @brief Helper to declare elements of bt_data arrays * - * This macro is mainly for creating an array of struct bt_data + * This macro is mainly for creating an array of struct bt_mesh_adv_data * elements which is then passed to bt_le_adv_start(). * * @param _type Type of advertising data field * @param _bytes Variable number of single-byte parameters */ -#define BT_DATA_BYTES(_type, _bytes...) \ - BT_DATA(_type, ((u8_t []) { _bytes }), \ +#define BLE_MESH_ADV_DATA_BYTES(_type, _bytes...) \ + BLE_MESH_ADV_DATA(_type, ((u8_t []) { _bytes }), \ sizeof((u8_t []) { _bytes })) -/** LE Advertising Parameters. */ -struct bt_le_adv_param { +/* BLE Mesh Advertising Parameters */ +struct bt_mesh_adv_param { /** Bit-field of advertising options */ u8_t options; @@ -364,21 +366,15 @@ struct bt_le_adv_param { /** Maximum Advertising Interval (N * 0.625) */ u16_t interval_max; - - /** Optional predefined (random) own address. Currently - * the only permitted use of this is for NRPA with - * non-connectable advertising. - */ - const bt_addr_t *own_addr; }; -/** LE scan parameters */ -struct bt_le_scan_param { - /** Scan type (BT_HCI_LE_SCAN_ACTIVE or BT_HCI_LE_SCAN_PASSIVE) */ +/* BLE Mesh scan parameters */ +struct bt_mesh_scan_param { + /** Scan type (BLE_MESH_SCAN_ACTIVE or BLE_MESH_SCAN_PASSIVE) */ u8_t type; - /** Duplicate filtering (BT_HCI_LE_SCAN_FILTER_DUP_ENABLE or - * BT_HCI_LE_SCAN_FILTER_DUP_DISABLE) + /** Duplicate filtering (BLE_MESH_SCAN_FILTER_DUP_ENABLE or + * BLE_MESH_SCAN_FILTER_DUP_DISABLE) */ u8_t filter_dup; @@ -389,43 +385,12 @@ struct bt_le_scan_param { u16_t window; }; -/** Connection parameters for LE connections */ -struct bt_le_conn_param { - u16_t interval_min; - u16_t interval_max; - u16_t latency; - u16_t timeout; +struct bt_mesh_conn { + u16_t handle; + bt_mesh_atomic_t ref; }; -struct bt_conn { - u16_t handle; - u8_t type; - u8_t role; - - /* Connection error or reason for disconnect */ - u8_t err; - - bt_conn_state_t state; - - u16_t rx_len; - struct net_buf *rx; - - /* Sent but not acknowledged TX packets */ - sys_slist_t tx_pending; - /* Acknowledged but not yet notified TX packets */ - struct k_fifo tx_notify; - - /* Queue for outgoing ACL data */ - struct k_fifo tx_queue; - - /* Active L2CAP channels */ - sys_slist_t channels; - - atomic_t ref; -}; - - -/** @typedef bt_le_scan_cb_t +/** @typedef bt_mesh_scan_cb_t * @brief Callback type for reporting LE scan results. * * A function of this type is given to the bt_le_scan_start() function @@ -436,29 +401,29 @@ struct bt_conn { * @param adv_type Type of advertising response from advertiser. * @param data Buffer containing advertiser data. */ -typedef void bt_le_scan_cb_t(const bt_addr_le_t *addr, s8_t rssi, - u8_t adv_type, struct net_buf_simple *buf); +typedef void bt_mesh_scan_cb_t(const bt_mesh_addr_t *addr, s8_t rssi, + u8_t adv_type, struct net_buf_simple *buf); -/* @typedef bt_dh_key_cb_t +/* @typedef bt_mesh_dh_key_cb_t * @brief Callback type for DH Key calculation. * * Used to notify of the calculated DH Key. * * @param key The DH Key, or NULL in case of failure. */ -typedef void (*bt_dh_key_cb_t)(const u8_t key[32]); +typedef void (*bt_mesh_dh_key_cb_t)(const u8_t key[32]); -/** @typedef bt_gatt_attr_func_t +/** @typedef bt_mesh_gatt_attr_func_t * @brief Attribute iterator callback. * * @param attr Attribute found. * @param user_data Data given. * - * @return BT_GATT_ITER_CONTINUE if should continue to the next attribute - * or BT_GATT_ITER_STOP to stop. + * @return BLE_MESH_GATT_ITER_CONTINUE if should continue to the next attribute + * or BLE_MESH_GATT_ITER_STOP to stop. */ -typedef u8_t (*bt_gatt_attr_func_t)(const struct bt_gatt_attr *attr, - void *user_data); +typedef u8_t (*bt_mesh_gatt_attr_func_t)(const struct bt_mesh_gatt_attr *attr, + void *user_data); /** @brief Connection callback structure. * @@ -470,7 +435,7 @@ typedef u8_t (*bt_gatt_attr_func_t)(const struct bt_gatt_attr *attr, * an instance, it may be set to NULL and will as a consequence not be * used for that instance. */ -struct bt_conn_cb { +struct bt_mesh_conn_cb { /** @brief A new connection has been established. * * This callback notifies the application of a new connection. @@ -480,7 +445,7 @@ struct bt_conn_cb { * @param conn New connection object. * @param err HCI error. Zero for success, non-zero otherwise. */ - void (*connected)(struct bt_conn *conn, u8_t err); + void (*connected)(struct bt_mesh_conn *conn, u8_t err); /** @brief A connection has been disconnected. * @@ -490,109 +455,29 @@ struct bt_conn_cb { * @param conn Connection object. * @param reason HCI reason for the disconnection. */ - void (*disconnected)(struct bt_conn *conn, u8_t reason); - - /** @brief LE connection parameter update request. - * - * This callback notifies the application that a remote device - * is requesting to update the connection parameters. The - * application accepts the parameters by returning true, or - * rejects them by returning false. Before accepting, the - * application may also adjust the parameters to better suit - * its needs. - * - * It is recommended for an application to have just one of these - * callbacks for simplicity. However, if an application registers - * multiple it needs to manage the potentially different - * requirements for each callback. Each callback gets the - * parameters as returned by previous callbacks, i.e. they are not - * necessarily the same ones as the remote originally sent. - * - * @param conn Connection object. - * @param param Proposed connection parameters. - * - * @return true to accept the parameters, or false to reject them. - */ - bool (*le_param_req)(struct bt_conn *conn, - struct bt_le_conn_param *param); - - /** @brief The parameters for an LE connection have been updated. - * - * This callback notifies the application that the connection - * parameters for an LE connection have been updated. - * - * @param conn Connection object. - * @param interval Connection interval. - * @param latency Connection latency. - * @param timeout Connection supervision timeout. - */ - void (*le_param_updated)(struct bt_conn *conn, u16_t interval, - u16_t latency, u16_t timeout); -#if defined(CONFIG_BT_SMP) - /** @brief Remote Identity Address has been resolved. - * - * This callback notifies the application that a remote - * Identity Address has been resolved - * - * @param conn Connection object. - * @param rpa Resolvable Private Address. - * @param identity Identity Address. - */ - void (*identity_resolved)(struct bt_conn *conn, - const bt_addr_le_t *rpa, - const bt_addr_le_t *identity); -#endif /* CONFIG_BT_SMP */ -#if defined(CONFIG_BT_SMP) || defined(CONFIG_BT_BREDR) - /** @brief The security level of a connection has changed. - * - * This callback notifies the application that the security level - * of a connection has changed. - * - * @param conn Connection object. - * @param level New security level of the connection. - */ - void (*security_changed)(struct bt_conn *conn, bt_security_t level); -#endif /* defined(CONFIG_BT_SMP) || defined(CONFIG_BT_BREDR) */ - struct bt_conn_cb *_next; + void (*disconnected)(struct bt_mesh_conn *conn, u8_t reason); }; -#if CONFIG_BT_MESH_PROVISIONER -struct bt_prov_conn_cb { - void (*connected)(const u8_t addr[6], struct bt_conn *conn, int id); +#if CONFIG_BLE_MESH_PROVISIONER +struct bt_mesh_prov_conn_cb { + void (*connected)(const u8_t addr[6], struct bt_mesh_conn *conn, int id); - void (*disconnected)(struct bt_conn *conn, u8_t reason); + void (*disconnected)(struct bt_mesh_conn *conn, u8_t reason); - ssize_t (*prov_write_descr)(struct bt_conn *conn, u8_t *addr); + ssize_t (*prov_write_descr)(struct bt_mesh_conn *conn, u8_t *addr); - ssize_t (*prov_notify)(struct bt_conn *conn, u8_t *data, u16_t len); + ssize_t (*prov_notify)(struct bt_mesh_conn *conn, u8_t *data, u16_t len); - ssize_t (*proxy_write_descr)(struct bt_conn *conn); + ssize_t (*proxy_write_descr)(struct bt_mesh_conn *conn); - ssize_t (*proxy_notify)(struct bt_conn *conn, u8_t *data, u16_t len); - - bool (*le_param_req)(struct bt_conn *conn, struct bt_le_conn_param *param); - - void (*le_param_updated)(struct bt_conn *conn, u16_t interval, - u16_t latency, u16_t timeout); - -#if defined(CONFIG_BT_SMP) - void (*identity_resolved)(struct bt_conn *conn, - const bt_addr_le_t *rpa, - const bt_addr_le_t *identity); -#endif /* CONFIG_BT_SMP */ - -#if defined(CONFIG_BT_SMP) || defined(CONFIG_BT_BREDR) - void (*security_changed)(struct bt_conn *conn, bt_security_t level); -#endif /* defined(CONFIG_BT_SMP) || defined(CONFIG_BT_BREDR) */ - - struct bt_conn_cb *_next; + ssize_t (*proxy_notify)(struct bt_mesh_conn *conn, u8_t *data, u16_t len); }; -#endif /* CONFIG_BT_MESH_PROVISIONER */ +#endif /* CONFIG_BLE_MESH_PROVISIONER */ /** @brief GATT Attribute structure. */ -struct bt_gatt_attr { +struct bt_mesh_gatt_attr { /** Attribute UUID */ - const struct bt_uuid *uuid; + const struct bt_mesh_uuid *uuid; /** Attribute read callback * @@ -603,12 +488,12 @@ struct bt_gatt_attr { * @param offset Offset to start reading from * * @return Number fo bytes read, or in case of an error - * BT_GATT_ERR() with a specific ATT error code. + * BLE_MESH_GATT_ERR() with a specific ATT error code. */ - ssize_t (*read)(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - void *buf, u16_t len, - u16_t offset); + ssize_t (*read)(struct bt_mesh_conn *conn, + const struct bt_mesh_gatt_attr *attr, + void *buf, u16_t len, + u16_t offset); /** Attribute write callback * @@ -620,68 +505,67 @@ struct bt_gatt_attr { * @param flags Flags (BT_GATT_WRITE_*) * * @return Number of bytes written, or in case of an error - * BT_GATT_ERR() with a specific ATT error code. + * BLE_MESH_GATT_ERR() with a specific ATT error code. */ - ssize_t (*write)(struct bt_conn *conn, - const struct bt_gatt_attr *attr, - const void *buf, u16_t len, - u16_t offset, u8_t flags); + ssize_t (*write)(struct bt_mesh_conn *conn, + const struct bt_mesh_gatt_attr *attr, + const void *buf, u16_t len, + u16_t offset, u8_t flags); /** Attribute user data */ - void *user_data; + void *user_data; /** Attribute handle */ - u16_t handle; + u16_t handle; /** Attribute permissions */ - u8_t perm; + u8_t perm; }; -/** @def BT_GATT_PRIMARY_SERVICE +/** @def BLE_MESH_GATT_PRIMARY_SERVICE * @brief Primary Service Declaration Macro. * * Helper macro to declare a primary service attribute. * * @param _service Service attribute value. */ -#define BT_GATT_PRIMARY_SERVICE(_service) \ -{ \ - .uuid = BT_UUID_GATT_PRIMARY, \ - .perm = BT_GATT_PERM_READ, \ - .read = bt_mesh_gatts_attr_read_service, \ - .user_data = _service, \ +#define BLE_MESH_GATT_PRIMARY_SERVICE(_service) \ +{ \ + .uuid = BLE_MESH_UUID_GATT_PRIMARY, \ + .perm = BLE_MESH_GATT_PERM_READ, \ + .read = bt_mesh_gatts_attr_read_service, \ + .user_data = _service, \ } -/** @def BT_GATT_SECONDARY_SERVICE +/** @def BLE_MESH_GATT_SECONDARY_SERVICE * @brief Secondary Service Declaration Macro. * * Helper macro to declare a secondary service attribute. * * @param _service Service attribute value. */ -#define BT_GATT_SECONDARY_SERVICE(_service) \ -{ \ - .uuid = BT_UUID_GATT_SECONDARY, \ - .perm = BT_GATT_PERM_READ, \ - .read = bt_mesh_gatts_attr_read_service, \ - .user_data = _service, \ +#define BLE_MESH_GATT_SECONDARY_SERVICE(_service) \ +{ \ + .uuid = BLE_MESH_UUID_GATT_SECONDARY, \ + .perm = BLE_MESH_GATT_PERM_READ, \ + .read = bt_mesh_gatts_attr_read_service, \ + .user_data = _service, \ } -/** @def BT_GATT_INCLUDE_SERVICE +/** @def BLE_MESH_GATT_INCLUDE_SERVICE * @brief Include Service Declaration Macro. * * Helper macro to declare database internal include service attribute. * * @param _service_incl the first service attribute of service to include */ -#define BT_GATT_INCLUDE_SERVICE(_service_incl) \ -{ \ - .uuid = BT_UUID_GATT_INCLUDE, \ - .perm = BT_GATT_PERM_READ, \ - .read = bt_mesh_gatts_attr_read_included, \ - .user_data = _service_incl, \ +#define BLE_MESH_GATT_INCLUDE_SERVICE(_service_incl) \ +{ \ + .uuid = BLE_MESH_UUID_GATT_INCLUDE, \ + .perm = BLE_MESH_GATT_PERM_READ, \ + .read = bt_mesh_gatts_attr_read_included, \ + .user_data = _service_incl, \ } - -/** @def BT_GATT_CHARACTERISTIC +/** @def BLE_MESH_GATT_CHARACTERISTIC * @brief Characteristic Declaration Macro. * * Helper macro to declare a characteristic attribute. @@ -689,16 +573,16 @@ struct bt_gatt_attr { * @param _uuid Characteristic attribute uuid. * @param _props Characteristic attribute properties. */ -#define BT_GATT_CHARACTERISTIC(_uuid, _props) \ -{ \ - .uuid = BT_UUID_GATT_CHRC, \ - .perm = BT_GATT_PERM_READ, \ - .read = bt_mesh_gatts_attr_read_chrc, \ - .user_data = (&(struct bt_gatt_chrc) { .uuid = _uuid, \ - .properties = _props, }),\ +#define BLE_MESH_GATT_CHARACTERISTIC(_uuid, _props) \ +{ \ + .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, \ + .properties = _props, }), \ } -/** @def BT_GATT_DESCRIPTOR +/** @def BLE_MESH_GATT_DESCRIPTOR * @brief Descriptor Declaration Macro. * * Helper macro to declare a descriptor attribute. @@ -709,108 +593,93 @@ struct bt_gatt_attr { * @param _write Descriptor attribute write callback. * @param _value Descriptor attribute value. */ -#define BT_GATT_DESCRIPTOR(_uuid, _perm, _read, _write, _value) \ -{ \ - .uuid = _uuid, \ - .perm = _perm, \ - .read = _read, \ - .write = _write, \ - .user_data = _value, \ +#define BLE_MESH_GATT_DESCRIPTOR(_uuid, _perm, _read, _write, _value) \ +{ \ + .uuid = _uuid, \ + .perm = _perm, \ + .read = _read, \ + .write = _write, \ + .user_data = _value, \ } -/** @def BT_GATT_SERVICE +/** @def BLE_MESH_GATT_SERVICE * @brief Service Structure Declaration Macro. * * Helper macro to declare a service structure. * * @param _attrs Service attributes. */ -#define BT_GATT_SERVICE(_attrs) \ -{ \ - .attrs = _attrs, \ - .attr_count = ARRAY_SIZE(_attrs), \ +#define BLE_MESH_GATT_SERVICE(_attrs) \ +{ \ + .attrs = _attrs, \ + .attr_count = ARRAY_SIZE(_attrs), \ } -/* @brief Container for public key callback */ -struct bt_pub_key_cb { - /** @brief Callback type for Public Key generation. - * - * Used to notify of the local public key or that the local key is not - * available (either because of a failure to read it or because it is - * being regenerated). - * - * @param key The local public key, or NULL in case of no key. - */ - void (*func)(const u8_t key[64]); - - struct bt_pub_key_cb *_next; -}; - -int bt_le_adv_start(const struct bt_le_adv_param *param, - const struct bt_data *ad, size_t ad_len, - const struct bt_data *sd, size_t sd_len); +int bt_le_adv_start(const struct bt_mesh_adv_param *param, + const struct bt_mesh_adv_data *ad, size_t ad_len, + const struct bt_mesh_adv_data *sd, size_t sd_len); int bt_le_adv_stop(void); -int bt_le_scan_start(const struct bt_le_scan_param *param, bt_le_scan_cb_t cb); +int bt_le_scan_start(const struct bt_mesh_scan_param *param, bt_mesh_scan_cb_t cb); int bt_le_scan_stop(void); -void bt_mesh_gatts_conn_cb_register(struct bt_conn_cb *cb); +void bt_mesh_gatts_conn_cb_register(struct bt_mesh_conn_cb *cb); -int bt_mesh_gatts_disconnect(struct bt_conn *conn, u8_t reason); +int bt_mesh_gatts_disconnect(struct bt_mesh_conn *conn, u8_t reason); -int bt_mesh_gatts_service_register(struct bt_gatt_service *svc); +int bt_mesh_gatts_service_register(struct bt_mesh_gatt_service *svc); -int bt_mesh_gatts_service_unregister(struct bt_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_conn *conn, - const struct bt_gatt_attr *attr, +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); -ssize_t bt_mesh_gatts_attr_read(struct bt_conn *conn, const struct bt_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); -ssize_t bt_mesh_gatts_attr_read_service(struct bt_conn *conn, - const struct bt_gatt_attr *attr, +ssize_t bt_mesh_gatts_attr_read_service(struct bt_mesh_conn *conn, + const struct bt_mesh_gatt_attr *attr, void *buf, u16_t len, u16_t offset); -ssize_t bt_mesh_gatts_attr_read_chrc(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, +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); -int bt_mesh_gatts_notify(struct bt_conn *conn, const struct bt_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_conn *conn); +u16_t bt_mesh_gatt_get_mtu(struct bt_mesh_conn *conn); /** APIs added by Espressif */ -int bt_mesh_gatts_service_stop(struct bt_gatt_service *svc); -int bt_mesh_gatts_service_start(struct bt_gatt_service *svc); +int bt_mesh_gatts_service_stop(struct bt_mesh_gatt_service *svc); +int bt_mesh_gatts_service_start(struct bt_mesh_gatt_service *svc); -#if CONFIG_BT_MESH_PROVISIONER -void bt_mesh_gattc_conn_cb_register(struct bt_prov_conn_cb *cb); +#if CONFIG_BLE_MESH_PROVISIONER +void bt_mesh_gattc_conn_cb_register(struct bt_mesh_prov_conn_cb *cb); -u16_t bt_mesh_gattc_get_service_uuid(struct bt_conn *conn); +u16_t bt_mesh_gattc_get_service_uuid(struct bt_mesh_conn *conn); -int bt_mesh_gattc_conn_create(const bt_addr_le_t *addr, u16_t service_uuid); +int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, u16_t service_uuid); -void bt_gattc_conn_close(struct bt_conn *conn); +void bt_gattc_conn_close(struct bt_mesh_conn *conn); void bt_mesh_gattc_exchange_mtu(u8_t index); -u16_t bt_mesh_gattc_get_mtu_info(struct bt_conn *conn); +u16_t bt_mesh_gattc_get_mtu_info(struct bt_mesh_conn *conn); -int bt_mesh_gattc_write_no_rsp(struct bt_conn *conn, const struct bt_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_conn *conn); -#endif /* CONFIG_BT_MESH_PROVISIONER */ +void bt_mesh_gattc_disconnect(struct bt_mesh_conn *conn); +#endif /* CONFIG_BLE_MESH_PROVISIONER */ -struct bt_conn *bt_mesh_conn_ref(struct bt_conn *conn); +struct bt_mesh_conn *bt_mesh_conn_ref(struct bt_mesh_conn *conn); -void bt_mesh_conn_unref(struct bt_conn *conn); +void bt_mesh_conn_unref(struct bt_mesh_conn *conn); void bt_mesh_gatt_init(void); @@ -824,38 +693,38 @@ const u8_t *bt_mesh_pub_key_get(void); bool bt_mesh_check_public_key(const uint8_t key[64]); -int bt_mesh_dh_key_gen(const u8_t remote_pk[64], bt_dh_key_cb_t cb); +int bt_mesh_dh_key_gen(const u8_t remote_pk[64], bt_mesh_dh_key_cb_t cb); -int bt_encrypt_le(const u8_t key[16], const u8_t plaintext[16], +int bt_mesh_encrypt_le(const u8_t key[16], const u8_t plaintext[16], u8_t enc_data[16]); -int bt_encrypt_be(const u8_t key[16], const u8_t plaintext[16], +int bt_mesh_encrypt_be(const u8_t key[16], const u8_t plaintext[16], u8_t enc_data[16]); enum { - BT_MESH_EXCEP_LIST_ADD = 0, - BT_MESH_EXCEP_LIST_REMOVE, - BT_MESH_EXCEP_LIST_CLEAN, + BLE_MESH_EXCEP_LIST_ADD = 0, + BLE_MESH_EXCEP_LIST_REMOVE, + BLE_MESH_EXCEP_LIST_CLEAN, }; enum { - BT_MESH_EXCEP_INFO_ADV_ADDR = 0, - BT_MESH_EXCEP_INFO_MESH_LINK_ID, - BT_MESH_EXCEP_INFO_MESH_BEACON, - BT_MESH_EXCEP_INFO_MESH_PROV_ADV, - BT_MESH_EXCEP_INFO_MESH_PROXY_ADV, + BLE_MESH_EXCEP_INFO_ADV_ADDR = 0, + BLE_MESH_EXCEP_INFO_MESH_LINK_ID, + BLE_MESH_EXCEP_INFO_MESH_BEACON, + BLE_MESH_EXCEP_INFO_MESH_PROV_ADV, + BLE_MESH_EXCEP_INFO_MESH_PROXY_ADV, }; enum { - BT_MESH_EXCEP_CLEAN_ADDR_LIST = BIT(0), - BT_MESH_EXCEP_CLEAN_MESH_LINK_ID_LIST = BIT(1), - BT_MESH_EXCEP_CLEAN_MESH_BEACON_LIST = BIT(2), - BT_MESH_EXCEP_CLEAN_MESH_PROV_ADV_LIST = BIT(3), - BT_MESH_EXCEP_CLEAN_MESH_PROXY_ADV_LIST = BIT(4), - BT_MESH_EXCEP_CLEAN_ALL_LIST = 0xFFFF, + BLE_MESH_EXCEP_CLEAN_ADDR_LIST = BIT(0), + BLE_MESH_EXCEP_CLEAN_MESH_LINK_ID_LIST = BIT(1), + BLE_MESH_EXCEP_CLEAN_MESH_BEACON_LIST = BIT(2), + BLE_MESH_EXCEP_CLEAN_MESH_PROV_ADV_LIST = BIT(3), + BLE_MESH_EXCEP_CLEAN_MESH_PROXY_ADV_LIST = BIT(4), + BLE_MESH_EXCEP_CLEAN_ALL_LIST = 0xFFFF, }; int bt_mesh_update_exceptional_list(u8_t sub_code, u8_t type, void *info); -#endif /* #ifndef __MESH_BEARER_ADRPT_H__ */ +#endif /* _BLE_MESH_BEARER_ADRPT_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/include/mesh_bt_uuid.h b/components/bt/ble_mesh/mesh_core/include/mesh_bt_uuid.h deleted file mode 100644 index 80f52023fc..0000000000 --- a/components/bt/ble_mesh/mesh_core/include/mesh_bt_uuid.h +++ /dev/null @@ -1,580 +0,0 @@ -/** @file - * @brief Bluetooth UUID handling - */ - -/* - * Copyright (c) 2015-2016 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ -#ifndef __BT_UUID_H -#define __BT_UUID_H - -/** - * @brief UUIDs - * @defgroup bt_uuid UUIDs - * @ingroup bluetooth - * @{ - */ - -#include "mesh_util.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** @brief Bluetooth UUID types */ -enum { - BT_UUID_TYPE_16, - BT_UUID_TYPE_32, - BT_UUID_TYPE_128, -}; - -/** @brief This is a 'tentative' type and should be used as a pointer only */ -struct bt_uuid { - u8_t type; -}; - -struct bt_uuid_16 { - struct bt_uuid uuid; - u16_t val; -}; - -struct bt_uuid_32 { - struct bt_uuid uuid; - u32_t val; -}; - -struct bt_uuid_128 { - struct bt_uuid uuid; - u8_t val[16]; -}; - -#define BT_UUID_INIT_16(value) \ -{ \ - .uuid.type = BT_UUID_TYPE_16, \ - .val = (value), \ -} - -#define BT_UUID_INIT_32(value) \ -{ \ - .uuid.type = BT_UUID_TYPE_32, \ - .val = (value), \ -} - -#define BT_UUID_INIT_128(value...) \ -{ \ - .uuid.type = BT_UUID_TYPE_128, \ - .val = { value }, \ -} - -#define BT_UUID_DECLARE_16(value) \ - ((struct bt_uuid *) (&(struct bt_uuid_16) BT_UUID_INIT_16(value))) -#define BT_UUID_DECLARE_32(value) \ - ((struct bt_uuid *) (&(struct bt_uuid_32) BT_UUID_INIT_32(value))) -#define BT_UUID_DECLARE_128(value...) \ - ((struct bt_uuid *) (&(struct bt_uuid_128) BT_UUID_INIT_128(value))) - -#define BT_UUID_16(__u) CONTAINER_OF(__u, struct bt_uuid_16, uuid) -#define BT_UUID_32(__u) CONTAINER_OF(__u, struct bt_uuid_32, uuid) -#define BT_UUID_128(__u) CONTAINER_OF(__u, struct bt_uuid_128, uuid) - -/** @def BT_UUID_GAP - * @brief Generic Access - */ -#define BT_UUID_GAP BT_UUID_DECLARE_16(0x1800) -#define BT_UUID_GAP_VAL 0x1800 -/** @def BT_UUID_GATT - * @brief Generic Attribute - */ -#define BT_UUID_GATT BT_UUID_DECLARE_16(0x1801) -#define BT_UUID_GATT_VAL 0x1801 -/** @def BT_UUID_CTS - * @brief Current Time Service - */ -#define BT_UUID_CTS BT_UUID_DECLARE_16(0x1805) -#define BT_UUID_CTS_VAL 0x1805 -/** @def BT_UUID_DIS - * @brief Device Information Service - */ -#define BT_UUID_DIS BT_UUID_DECLARE_16(0x180a) -#define BT_UUID_DIS_VAL 0x180a -/** @def BT_UUID_HRS - * @brief Heart Rate Service - */ -#define BT_UUID_HRS BT_UUID_DECLARE_16(0x180d) -#define BT_UUID_HRS_VAL 0x180d -/** @def BT_UUID_BAS - * @brief Battery Service - */ -#define BT_UUID_BAS BT_UUID_DECLARE_16(0x180f) -#define BT_UUID_BAS_VAL 0x180f -/** @def BT_UUID_HIDS - * @brief HID Service - */ -#define BT_UUID_HIDS BT_UUID_DECLARE_16(0x1812) -#define BT_UUID_HIDS_VAL 0x1812 -/** @def BT_UUID_CSC - * @brief Cycling Speed and Cadence Service - */ -#define BT_UUID_CSC BT_UUID_DECLARE_16(0x1816) -#define BT_UUID_CSC_VAL 0x1816 -/** @def BT_UUID_ESS - * @brief Environmental Sensing Service - */ -#define BT_UUID_ESS BT_UUID_DECLARE_16(0x181a) -#define BT_UUID_ESS_VAL 0x181a -/** @def BT_UUID_IPSS - * @brief IP Support Service - */ -#define BT_UUID_IPSS BT_UUID_DECLARE_16(0x1820) -#define BT_UUID_IPSS_VAL 0x1820 -/** @def BT_UUID_MESH_PROV - * @brief Mesh Provisioning Service - */ -#define BT_UUID_MESH_PROV BT_UUID_DECLARE_16(0x1827) -#define BT_UUID_MESH_PROV_VAL 0x1827 -/** @def BT_UUID_MESH_PROXY - * @brief Mesh Proxy Service - */ -#define BT_UUID_MESH_PROXY BT_UUID_DECLARE_16(0x1828) -#define BT_UUID_MESH_PROXY_VAL 0x1828 -/** @def BT_UUID_GATT_PRIMARY - * @brief GATT Primary Service - */ -#define BT_UUID_GATT_PRIMARY BT_UUID_DECLARE_16(0x2800) -#define BT_UUID_GATT_PRIMARY_VAL 0x2800 -/** @def BT_UUID_GATT_SECONDARY - * @brief GATT Secondary Service - */ -#define BT_UUID_GATT_SECONDARY BT_UUID_DECLARE_16(0x2801) -#define BT_UUID_GATT_SECONDARY_VAL 0x2801 -/** @def BT_UUID_GATT_INCLUDE - * @brief GATT Include Service - */ -#define BT_UUID_GATT_INCLUDE BT_UUID_DECLARE_16(0x2802) -#define BT_UUID_GATT_INCLUDE_VAL 0x2802 -/** @def BT_UUID_GATT_CHRC - * @brief GATT Characteristic - */ -#define BT_UUID_GATT_CHRC BT_UUID_DECLARE_16(0x2803) -#define BT_UUID_GATT_CHRC_VAL 0x2803 -/** @def BT_UUID_GATT_CEP - * @brief GATT Characteristic Extended Properties - */ -#define BT_UUID_GATT_CEP BT_UUID_DECLARE_16(0x2900) -#define BT_UUID_GATT_CEP_VAL 0x2900 -/** @def BT_UUID_GATT_CUD - * @brief GATT Characteristic User Description - */ -#define BT_UUID_GATT_CUD BT_UUID_DECLARE_16(0x2901) -#define BT_UUID_GATT_CUD_VAL 0x2901 -/** @def BT_UUID_GATT_CCC - * @brief GATT Client Characteristic Configuration - */ -#define BT_UUID_GATT_CCC BT_UUID_DECLARE_16(0x2902) -#define BT_UUID_GATT_CCC_VAL 0x2902 -/** @def BT_UUID_GATT_SCC - * @brief GATT Server Characteristic Configuration - */ -#define BT_UUID_GATT_SCC BT_UUID_DECLARE_16(0x2903) -#define BT_UUID_GATT_SCC_VAL 0x2903 -/** @def BT_UUID_GATT_CPF - * @brief GATT Characteristic Presentation Format - */ -#define BT_UUID_GATT_CPF BT_UUID_DECLARE_16(0x2904) -#define BT_UUID_GATT_CPF_VAL 0x2904 -/** @def BT_UUID_VALID_RANGE - * @brief Valid Range Descriptor - */ -#define BT_UUID_VALID_RANGE BT_UUID_DECLARE_16(0x2906) -#define BT_UUID_VALID_RANGE_VAL 0x2906 -/** @def BT_UUID_HIDS_EXT_REPORT - * @brief HID External Report Descriptor - */ -#define BT_UUID_HIDS_EXT_REPORT BT_UUID_DECLARE_16(0x2907) -#define BT_UUID_HIDS_EXT_REPORT_VAL 0x2907 -/** @def BT_UUID_HIDS_REPORT_REF - * @brief HID Report Reference Descriptor - */ -#define BT_UUID_HIDS_REPORT_REF BT_UUID_DECLARE_16(0x2908) -#define BT_UUID_HIDS_REPORT_REF_VAL 0x2908 -/** @def BT_UUID_ES_CONFIGURATION - * @brief Environmental Sensing Configuration Descriptor - */ -#define BT_UUID_ES_CONFIGURATION BT_UUID_DECLARE_16(0x290b) -#define BT_UUID_ES_CONFIGURATION_VAL 0x290b -/** @def BT_UUID_ES_MEASUREMENT - * @brief Environmental Sensing Measurement Descriptor - */ -#define BT_UUID_ES_MEASUREMENT BT_UUID_DECLARE_16(0x290c) -#define BT_UUID_ES_MEASUREMENT_VAL 0x290c -/** @def BT_UUID_ES_TRIGGER_SETTING - * @brief Environmental Sensing Trigger Setting Descriptor - */ -#define BT_UUID_ES_TRIGGER_SETTING BT_UUID_DECLARE_16(0x290d) -#define BT_UUID_ES_TRIGGER_SETTING_VAL 0x290d -/** @def BT_UUID_GAP_DEVICE_NAME - * @brief GAP Characteristic Device Name - */ -#define BT_UUID_GAP_DEVICE_NAME BT_UUID_DECLARE_16(0x2a00) -#define BT_UUID_GAP_DEVICE_NAME_VAL 0x2a00 -/** @def BT_UUID_GAP_APPEARANCE - * @brief GAP Characteristic Appearance - */ -#define BT_UUID_GAP_APPEARANCE BT_UUID_DECLARE_16(0x2a01) -#define BT_UUID_GAP_APPEARANCE_VAL 0x2a01 -/** @def BT_UUID_GAP_PPCP - * @brief GAP Characteristic Peripheral Preferred Connection Parameters - */ -#define BT_UUID_GAP_PPCP BT_UUID_DECLARE_16(0x2a04) -#define BT_UUID_GAP_PPCP_VAL 0x2a04 -/** @def BT_UUID_GATT_SC - * @brief GATT Characteristic Service Changed - */ -#define BT_UUID_GATT_SC BT_UUID_DECLARE_16(0x2a05) -#define BT_UUID_GATT_SC_VAL 0x2a05 -/** @def BT_UUID_BAS_BATTERY_LEVEL - * @brief BAS Characteristic Battery Level - */ -#define BT_UUID_BAS_BATTERY_LEVEL BT_UUID_DECLARE_16(0x2a19) -#define BT_UUID_BAS_BATTERY_LEVEL_VAL 0x2a19 -/** @def BT_UUID_DIS_SYSTEM_ID - * @brief DIS Characteristic System ID - */ -#define BT_UUID_DIS_SYSTEM_ID BT_UUID_DECLARE_16(0x2a23) -#define BT_UUID_DIS_SYSTEM_ID_VAL 0x2a23 -/** @def BT_UUID_DIS_MODEL_NUMBER - * @brief DIS Characteristic Model Number String - */ -#define BT_UUID_DIS_MODEL_NUMBER BT_UUID_DECLARE_16(0x2a24) -#define BT_UUID_DIS_MODEL_NUMBER_VAL 0x2a24 -/** @def BT_UUID_DIS_SERIAL_NUMBER - * @brief DIS Characteristic Serial Number String - */ -#define BT_UUID_DIS_SERIAL_NUMBER BT_UUID_DECLARE_16(0x2a25) -#define BT_UUID_DIS_SERIAL_NUMBER_VAL 0x2a25 -/** @def BT_UUID_DIS_FIRMWARE_REVISION - * @brief DIS Characteristic Firmware Revision String - */ -#define BT_UUID_DIS_FIRMWARE_REVISION BT_UUID_DECLARE_16(0x2a26) -#define BT_UUID_DIS_FIRMWARE_REVISION_VAL 0x2a26 -/** @def BT_UUID_DIS_HARDWARE_REVISION - * @brief DIS Characteristic Hardware Revision String - */ -#define BT_UUID_DIS_HARDWARE_REVISION BT_UUID_DECLARE_16(0x2a27) -#define BT_UUID_DIS_HARDWARE_REVISION_VAL 0x2a27 -/** @def BT_UUID_DIS_SOFTWARE_REVISION - * @brief DIS Characteristic Software Revision String - */ -#define BT_UUID_DIS_SOFTWARE_REVISION BT_UUID_DECLARE_16(0x2a28) -#define BT_UUID_DIS_SOFTWARE_REVISION_VAL 0x2a28 -/** @def BT_UUID_DIS_MANUFACTURER_NAME - * @brief DIS Characteristic Manufacturer Name String - */ -#define BT_UUID_DIS_MANUFACTURER_NAME BT_UUID_DECLARE_16(0x2a29) -#define BT_UUID_DIS_MANUFACTURER_NAME_VAL 0x2a29 -/** @def BT_UUID_DIS_PNP_ID - * @brief DIS Characteristic PnP ID - */ -#define BT_UUID_DIS_PNP_ID BT_UUID_DECLARE_16(0x2a50) -#define BT_UUID_DIS_PNP_ID_VAL 0x2a50 -/** @def BT_UUID_CTS_CURRENT_TIME - * @brief CTS Characteristic Current Time - */ -#define BT_UUID_CTS_CURRENT_TIME BT_UUID_DECLARE_16(0x2a2b) -#define BT_UUID_CTS_CURRENT_TIME_VAL 0x2a2b -/** @def BT_UUID_MAGN_DECLINATION - * @brief Magnetic Declination Characteristic - */ -#define BT_UUID_MAGN_DECLINATION BT_UUID_DECLARE_16(0x2a2c) -#define BT_UUID_MAGN_DECLINATION_VAL 0x2a2c -/** @def BT_UUID_HRS_MEASUREMENT - * @brief HRS Characteristic Measurement Interval - */ -#define BT_UUID_HRS_MEASUREMENT BT_UUID_DECLARE_16(0x2a37) -#define BT_UUID_HRS_MEASUREMENT_VAL 0x2a37 -/** @def BT_UUID_HRS_BODY_SENSOR - * @brief HRS Characteristic Body Sensor Location - */ -#define BT_UUID_HRS_BODY_SENSOR BT_UUID_DECLARE_16(0x2a38) -#define BT_UUID_HRS_BODY_SENSOR_VAL 0x2a38 -/** @def BT_UUID_HRS_CONTROL_POINT - * @brief HRS Characteristic Control Point - */ -#define BT_UUID_HRS_CONTROL_POINT BT_UUID_DECLARE_16(0x2a39) -#define BT_UUID_HRS_CONTROL_POINT_VAL 0x2a39 -/** @def BT_UUID_HIDS_INFO - * @brief HID Information Characteristic - */ -#define BT_UUID_HIDS_INFO BT_UUID_DECLARE_16(0x2a4a) -#define BT_UUID_HIDS_INFO_VAL 0x2a4a -/** @def BT_UUID_HIDS_REPORT_MAP - * @brief HID Report Map Characteristic - */ -#define BT_UUID_HIDS_REPORT_MAP BT_UUID_DECLARE_16(0x2a4b) -#define BT_UUID_HIDS_REPORT_MAP_VAL 0x2a4b -/** @def BT_UUID_HIDS_CTRL_POINT - * @brief HID Control Point Characteristic - */ -#define BT_UUID_HIDS_CTRL_POINT BT_UUID_DECLARE_16(0x2a4c) -#define BT_UUID_HIDS_CTRL_POINT_VAL 0x2a4c -/** @def BT_UUID_HIDS_REPORT - * @brief HID Report Characteristic - */ -#define BT_UUID_HIDS_REPORT BT_UUID_DECLARE_16(0x2a4d) -#define BT_UUID_HIDS_REPORT_VAL 0x2a4d -/** @def BT_UUID_CSC_MEASUREMENT - * @brief CSC Measurement Characteristic - */ -#define BT_UUID_CSC_MEASUREMENT BT_UUID_DECLARE_16(0x2a5b) -#define BT_UUID_CSC_MEASUREMENT_VAL 0x2a5b -/** @def BT_UUID_CSC_FEATURE - * @brief CSC Feature Characteristic - */ -#define BT_UUID_CSC_FEATURE BT_UUID_DECLARE_16(0x2a5c) -#define BT_UUID_CSC_FEATURE_VAL 0x2a5c -/** @def BT_UUID_SENSOR_LOCATION - * @brief Sensor Location Characteristic - */ -#define BT_UUID_SENSOR_LOCATION BT_UUID_DECLARE_16(0x2a5d) -#define BT_UUID_SENSOR_LOCATION_VAL 0x2a5d -/** @def BT_UUID_SC_CONTROL_POINT - * @brief SC Control Point Characteristic - */ -#define BT_UUID_SC_CONTROL_POINT BT_UUID_DECLARE_16(0x2a55) -#define BT_UUID_SC_CONTROL_POINT_VAl 0x2a55 -/** @def BT_UUID_ELEVATION - * @brief Elevation Characteristic - */ -#define BT_UUID_ELEVATION BT_UUID_DECLARE_16(0x2a6c) -#define BT_UUID_ELEVATION_VAL 0x2a6c -/** @def BT_UUID_PRESSURE - * @brief Pressure Characteristic - */ -#define BT_UUID_PRESSURE BT_UUID_DECLARE_16(0x2a6d) -#define BT_UUID_PRESSURE_VAL 0x2a6d -/** @def BT_UUID_TEMPERATURE - * @brief Temperature Characteristic - */ -#define BT_UUID_TEMPERATURE BT_UUID_DECLARE_16(0x2a6e) -#define BT_UUID_TEMPERATURE_VAL 0x2a6e -/** @def BT_UUID_HUMIDITY - * @brief Humidity Characteristic - */ -#define BT_UUID_HUMIDITY BT_UUID_DECLARE_16(0x2a6f) -#define BT_UUID_HUMIDITY_VAL 0x2a6f -/** @def BT_UUID_TRUE_WIND_SPEED - * @brief True Wind Speed Characteristic - */ -#define BT_UUID_TRUE_WIND_SPEED BT_UUID_DECLARE_16(0x2a70) -#define BT_UUID_TRUE_WIND_SPEED_VAL 0x2a70 -/** @def BT_UUID_TRUE_WIND_DIR - * @brief True Wind Direction Characteristic - */ -#define BT_UUID_TRUE_WIND_DIR BT_UUID_DECLARE_16(0x2a71) -#define BT_UUID_TRUE_WIND_DIR_VAL 0x2a71 -/** @def BT_UUID_APPARENT_WIND_SPEED - * @brief Apparent Wind Speed Characteristic - */ -#define BT_UUID_APPARENT_WIND_SPEED BT_UUID_DECLARE_16(0x2a72) -#define BT_UUID_APPARENT_WIND_SPEED_VAL 0x2a72 -/** @def BT_UUID_APPARENT_WIND_DIR - * @brief Apparent Wind Direction Characteristic - */ -#define BT_UUID_APPARENT_WIND_DIR BT_UUID_DECLARE_16(0x2a73) -#define BT_UUID_APPARENT_WIND_DIR_VAL 0x2a73 -/** @def BT_UUID_GUST_FACTOR - * @brief Gust Factor Characteristic - */ -#define BT_UUID_GUST_FACTOR BT_UUID_DECLARE_16(0x2a74) -#define BT_UUID_GUST_FACTOR_VAL 0x2a74 -/** @def BT_UUID_POLLEN_CONCENTRATION - * @brief Pollen Concentration Characteristic - */ -#define BT_UUID_POLLEN_CONCENTRATION BT_UUID_DECLARE_16(0x2a75) -#define BT_UUID_POLLEN_CONCENTRATION_VAL 0x2a75 -/** @def BT_UUID_UV_INDEX - * @brief UV Index Characteristic - */ -#define BT_UUID_UV_INDEX BT_UUID_DECLARE_16(0x2a76) -#define BT_UUID_UV_INDEX_VAL 0x2a76 -/** @def BT_UUID_IRRADIANCE - * @brief Irradiance Characteristic - */ -#define BT_UUID_IRRADIANCE BT_UUID_DECLARE_16(0x2a77) -#define BT_UUID_IRRADIANCE_VAL 0x2a77 -/** @def BT_UUID_RAINFALL - * @brief Rainfall Characteristic - */ -#define BT_UUID_RAINFALL BT_UUID_DECLARE_16(0x2a78) -#define BT_UUID_RAINFALL_VAL 0x2a78 -/** @def BT_UUID_WIND_CHILL - * @brief Wind Chill Characteristic - */ -#define BT_UUID_WIND_CHILL BT_UUID_DECLARE_16(0x2a79) -#define BT_UUID_WIND_CHILL_VAL 0x2a79 -/** @def BT_UUID_HEAT_INDEX - * @brief Heat Index Characteristic - */ -#define BT_UUID_HEAT_INDEX BT_UUID_DECLARE_16(0x2a7a) -#define BT_UUID_HEAT_INDEX_VAL 0x2a7a -/** @def BT_UUID_DEW_POINT - * @brief Dew Point Characteristic - */ -#define BT_UUID_DEW_POINT BT_UUID_DECLARE_16(0x2a7b) -#define BT_UUID_DEW_POINT_VAL 0x2a7b -/** @def BT_UUID_DESC_VALUE_CHANGED - * @brief Descriptor Value Changed Characteristic - */ -#define BT_UUID_DESC_VALUE_CHANGED BT_UUID_DECLARE_16(0x2a7d) -#define BT_UUID_DESC_VALUE_CHANGED_VAL 0x2a7d -/** @def BT_UUID_MAGN_FLUX_DENSITY_2D - * @brief Magnetic Flux Density - 2D Characteristic - */ -#define BT_UUID_MAGN_FLUX_DENSITY_2D BT_UUID_DECLARE_16(0x2aa0) -#define BT_UUID_MAGN_FLUX_DENSITY_2D_VAL 0x2aa0 -/** @def BT_UUID_MAGN_FLUX_DENSITY_3D - * @brief Magnetic Flux Density - 3D Characteristic - */ -#define BT_UUID_MAGN_FLUX_DENSITY_3D BT_UUID_DECLARE_16(0x2aa1) -#define BT_UUID_MAGN_FLUX_DENSITY_3D_VAL 0x2aa1 -/** @def BT_UUID_BAR_PRESSURE_TREND - * @brief Barometric Pressure Trend Characteristic - */ -#define BT_UUID_BAR_PRESSURE_TREND BT_UUID_DECLARE_16(0x2aa3) -#define BT_UUID_BAR_PRESSURE_TREND_VAL 0x2aa3 -/** @def BT_UUID_MESH_PROV_DATA_IN - * @brief Mesh Provisioning Data In - */ -#define BT_UUID_MESH_PROV_DATA_IN BT_UUID_DECLARE_16(0x2adb) -#define BT_UUID_MESH_PROV_DATA_IN_VAL 0x2adb -/** @def BT_UUID_MESH_PROV_DATA_OUT - * @brief Mesh Provisioning Data Out - */ -#define BT_UUID_MESH_PROV_DATA_OUT BT_UUID_DECLARE_16(0x2adc) -#define BT_UUID_MESH_PROV_DATA_OUT_VAL 0x2adc -/** @def BT_UUID_MESH_PROXY_DATA_IN - * @brief Mesh Proxy Data In - */ -#define BT_UUID_MESH_PROXY_DATA_IN BT_UUID_DECLARE_16(0x2add) -#define BT_UUID_MESH_PROXY_DATA_IN_VAL 0x2add -/** @def BT_UUID_MESH_PROXY_DATA_OUT - * @brief Mesh Proxy Data Out - */ -#define BT_UUID_MESH_PROXY_DATA_OUT BT_UUID_DECLARE_16(0x2ade) -#define BT_UUID_MESH_PROXY_DATA_OUT_VAL 0x2ade - -/* - * Protocol UUIDs - */ -#define BT_UUID_SDP BT_UUID_DECLARE_16(0x0001) -#define BT_UUID_SDP_VAL 0x0001 -#define BT_UUID_UDP BT_UUID_DECLARE_16(0x0002) -#define BT_UUID_UDP_VAL 0x0002 -#define BT_UUID_RFCOMM BT_UUID_DECLARE_16(0x0003) -#define BT_UUID_RFCOMM_VAL 0x0003 -#define BT_UUID_TCP BT_UUID_DECLARE_16(0x0004) -#define BT_UUID_TCP_VAL 0x0004 -#define BT_UUID_TCS_BIN BT_UUID_DECLARE_16(0x0005) -#define BT_UUID_TCS_BIN_VAL 0x0005 -#define BT_UUID_TCS_AT BT_UUID_DECLARE_16(0x0006) -#define BT_UUID_TCS_AT_VAL 0x0006 -#define BT_UUID_ATT BT_UUID_DECLARE_16(0x0007) -#define BT_UUID_ATT_VAL 0x0007 -#define BT_UUID_OBEX BT_UUID_DECLARE_16(0x0008) -#define BT_UUID_OBEX_VAL 0x0008 -#define BT_UUID_IP BT_UUID_DECLARE_16(0x0009) -#define BT_UUID_IP_VAL 0x0009 -#define BT_UUID_FTP BT_UUID_DECLARE_16(0x000a) -#define BT_UUID_FTP_VAL 0x000a -#define BT_UUID_HTTP BT_UUID_DECLARE_16(0x000c) -#define BT_UUID_HTTP_VAL 0x000c -#define BT_UUID_BNEP BT_UUID_DECLARE_16(0x000f) -#define BT_UUID_BNEP_VAL 0x000f -#define BT_UUID_UPNP BT_UUID_DECLARE_16(0x0010) -#define BT_UUID_UPNP_VAL 0x0010 -#define BT_UUID_HIDP BT_UUID_DECLARE_16(0x0011) -#define BT_UUID_HIDP_VAL 0x0011 -#define BT_UUID_HCRP_CTRL BT_UUID_DECLARE_16(0x0012) -#define BT_UUID_HCRP_CTRL_VAL 0x0012 -#define BT_UUID_HCRP_DATA BT_UUID_DECLARE_16(0x0014) -#define BT_UUID_HCRP_DATA_VAL 0x0014 -#define BT_UUID_HCRP_NOTE BT_UUID_DECLARE_16(0x0016) -#define BT_UUID_HCRP_NOTE_VAL 0x0016 -#define BT_UUID_AVCTP BT_UUID_DECLARE_16(0x0017) -#define BT_UUID_AVCTP_VAL 0x0017 -#define BT_UUID_AVDTP BT_UUID_DECLARE_16(0x0019) -#define BT_UUID_AVDTP_VAL 0x0019 -#define BT_UUID_CMTP BT_UUID_DECLARE_16(0x001b) -#define BT_UUID_CMTP_VAL 0x001b -#define BT_UUID_UDI BT_UUID_DECLARE_16(0x001d) -#define BT_UUID_UDI_VAL 0x001d -#define BT_UUID_MCAP_CTRL BT_UUID_DECLARE_16(0x001e) -#define BT_UUID_MCAP_CTRL_VAL 0x001e -#define BT_UUID_MCAP_DATA BT_UUID_DECLARE_16(0x001f) -#define BT_UUID_MCAP_DATA_VAL 0x001f -#define BT_UUID_L2CAP BT_UUID_DECLARE_16(0x0100) -#define BT_UUID_L2CAP_VAL 0x0100 - - -/** @brief Compare Bluetooth UUIDs. - * - * Compares 2 Bluetooth UUIDs, if the types are different both UUIDs are - * first converted to 128 bits format before comparing. - * - * @param u1 First Bluetooth UUID to compare - * @param u2 Second Bluetooth UUID to compare - * - * @return negative value if @a u1 < @a u2, 0 if @a u1 == @a u2, else positive - */ -int bt_uuid_cmp(const struct bt_uuid *u1, const struct bt_uuid *u2); - -#if defined(CONFIG_BT_DEBUG) -/** @brief Convert Bluetooth UUID to string. - * - * Converts Bluetooth UUID to string. UUID has to be in 16 bits or 128 bits - * format. - * - * @param uuid Bluetooth UUID - * @param str pointer where to put converted string - * @param len length of str - * - * @return N/A - */ -void bt_uuid_to_str(const struct bt_uuid *uuid, char *str, size_t len); - -/** @brief Convert Bluetooth UUID to string in place. - * - * Converts Bluetooth UUID to string in place. UUID has to be in 16 bits or - * 128 bits format. - * - * @param uuid Bluetooth UUID - * - * @return String representation of the UUID given - */ -const char *bt_uuid_str(const struct bt_uuid *uuid); -#else -static inline void bt_uuid_to_str(const struct bt_uuid *uuid, char *str, - size_t len) -{ - if (len > 0) { - str[0] = '\0'; - } -} - -static inline const char *bt_uuid_str(const struct bt_uuid *uuid) -{ - return ""; -} -#endif /* CONFIG_BT_DEBUG */ - -#ifdef __cplusplus -} -#endif - -/** - * @} - */ - -#endif /* __BT_UUID_H */ diff --git a/components/bt/ble_mesh/mesh_core/include/mesh_buf.h b/components/bt/ble_mesh/mesh_core/include/mesh_buf.h index 4dbb83316c..aeb521b70d 100644 --- a/components/bt/ble_mesh/mesh_core/include/mesh_buf.h +++ b/components/bt/ble_mesh/mesh_core/include/mesh_buf.h @@ -8,8 +8,8 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#ifndef __NET_BUF_H -#define __NET_BUF_H +#ifndef _BLE_MESH_BUF_H_ +#define _BLE_MESH_BUF_H_ #include #include "sys/cdefs.h" @@ -22,14 +22,13 @@ extern "C" { #endif - /* Unaligned access */ -#define UNALIGNED_GET(p) \ +#define UNALIGNED_GET(p) \ __extension__ ({ \ - struct __attribute__((__packed__)) { \ - __typeof__(*(p)) __v; \ - } *__p = (__typeof__(__p)) (p); \ - __p->__v; \ + struct __attribute__((__packed__)) { \ + __typeof__(*(p)) __v; \ + } *__p = (__typeof__(__p)) (p); \ + __p->__v; \ }) /** @@ -57,12 +56,12 @@ __extension__ ({ \ * * @return Pointer to stack-allocated net_buf_simple object. */ -#define NET_BUF_SIMPLE(_size) \ - ((struct net_buf_simple *)(&(struct { \ - struct net_buf_simple buf; \ - u8_t data[_size] __net_buf_align; \ - }) { \ - .buf.size = _size, \ +#define NET_BUF_SIMPLE(_size) \ + ((struct net_buf_simple *)(&(struct { \ + struct net_buf_simple buf; \ + u8_t data[_size] __net_buf_align; \ + }) { \ + .buf.size = _size, \ })) /** @brief Simple network buffer representation. @@ -94,24 +93,6 @@ struct net_buf_simple { u8_t __buf[0] __net_buf_align; }; -/** @def NET_BUF_SIMPLE_DEFINE_STATIC - * @brief Define a static net_buf_simple variable. - * - * This is a helper macro which is used to define a static net_buf_simple - * object. - * - * @param _name Name of the net_buf_simple object. - * @param _size Maximum data storage for the buffer. - */ -#define NET_BUF_SIMPLE_DEFINE_STATIC(_name, _size) \ - static __noinit u8_t net_buf_data_##_name[_size]; \ - static struct net_buf_simple _name = { \ - .data = net_buf_data_##_name, \ - .len = 0, \ - .size = _size, \ - .__buf = net_buf_data_##_name, \ - } - /** @brief Initialize a net_buf_simple object. * * This needs to be called after creating a net_buf_simple object e.g. using @@ -484,9 +465,6 @@ struct net_buf { }; struct net_buf_pool { - /** LIFO to place the buffer into when free */ - struct k_lifo free; - /** Number of buffers in pool */ const u16_t buf_count; @@ -499,7 +477,7 @@ struct net_buf_pool { /** Size of the user data associated with each buffer. */ const u16_t user_data_size; -#if defined(CONFIG_NET_BUF_POOL_USAGE) +#if defined(CONFIG_BLE_MESH_NET_BUF_POOL_USAGE) /** Amount of available buffers in the pool. */ s16_t avail_count; @@ -508,7 +486,7 @@ struct net_buf_pool { /** Name of the pool. Used when printing pool information. */ const char *name; -#endif /* CONFIG_NET_BUF_POOL_USAGE */ +#endif /* CONFIG_BLE_MESH_NET_BUF_POOL_USAGE */ /** Optional destroy callback when buffer is freed. */ void (*const destroy)(struct net_buf *buf); @@ -517,34 +495,32 @@ struct net_buf_pool { struct net_buf *const __bufs; }; -#if defined(CONFIG_NET_BUF_POOL_USAGE) -#define NET_BUF_POOL_INITIALIZER(_pool, _bufs, _count, _size, _ud_size, \ - _destroy) \ - { \ - .free = _K_LIFO_INITIALIZER(_pool.free), \ - .__bufs = (struct net_buf *)_bufs, \ - .buf_count = _count, \ - .uninit_count = _count, \ - .avail_count = _count, \ - .pool_size = sizeof(_net_buf_##_pool), \ - .buf_size = _size, \ - .user_data_size = _ud_size, \ - .destroy = _destroy, \ - .name = STRINGIFY(_pool), \ +#if defined(CONFIG_BLE_MESH_NET_BUF_POOL_USAGE) +#define NET_BUF_POOL_INITIALIZER(_pool, _bufs, _count, _size, _ud_size, \ + _destroy) \ + { \ + .__bufs = (struct net_buf *)_bufs, \ + .buf_count = _count, \ + .uninit_count = _count, \ + .avail_count = _count, \ + .pool_size = sizeof(_net_buf_##_pool), \ + .buf_size = _size, \ + .user_data_size = _ud_size, \ + .destroy = _destroy, \ + .name = STRINGIFY(_pool), \ } #else -#define NET_BUF_POOL_INITIALIZER(_pool, _bufs, _count, _size, _ud_size, \ - _destroy) \ - { \ - .free = _K_LIFO_INITIALIZER(_pool.free), \ - .__bufs = (struct net_buf *)_bufs, \ - .buf_count = _count, \ - .uninit_count = _count, \ - .buf_size = _size, \ - .user_data_size = _ud_size, \ - .destroy = _destroy, \ +#define NET_BUF_POOL_INITIALIZER(_pool, _bufs, _count, _size, _ud_size, \ + _destroy) \ + { \ + .__bufs = (struct net_buf *)_bufs, \ + .buf_count = _count, \ + .uninit_count = _count, \ + .buf_size = _size, \ + .user_data_size = _ud_size, \ + .destroy = _destroy, \ } -#endif /* CONFIG_NET_BUF_POOL_USAGE */ +#endif /* CONFIG_BLE_MESH_NET_BUF_POOL_USAGE */ /** @def NET_BUF_POOL_DEFINE * @brief Define a new pool for buffers @@ -578,30 +554,6 @@ struct net_buf_pool { NET_BUF_POOL_INITIALIZER(_name, _net_buf_##_name, \ _count, _size, _ud_size, _destroy) - -/** - * @brief Looks up a pool based on its ID. - * - * @param id Pool ID (e.g. from buf->pool_id). - * - * @return Pointer to pool. - */ -struct net_buf_pool *net_buf_pool_get(int id); - -/** - * @brief Get a zero-based index for a buffer. - * - * This function will translate a buffer into a zero-based index, - * based on its placement in its buffer pool. This can be useful if you - * want to associate an external array of meta-data contexts with the - * buffers of a pool. - * - * @param buf Network buffer. - * - * @return Zero-based index for the buffer. - */ -int net_buf_id(struct net_buf *buf); - /** * @brief Allocate a new buffer from a pool. * @@ -615,53 +567,15 @@ int net_buf_id(struct net_buf *buf); * * @return New buffer or NULL if out of buffers. */ -#if defined(CONFIG_NET_BUF_LOG) +#if defined(CONFIG_BLE_MESH_NET_BUF_LOG) struct net_buf *net_buf_alloc_debug(struct net_buf_pool *pool, s32_t timeout, const char *func, int line); #define net_buf_alloc(_pool, _timeout) \ - net_buf_alloc_debug(_pool, _timeout, __func__, __LINE__) + net_buf_alloc_debug(_pool, _timeout, __func__, __LINE__) #else struct net_buf *net_buf_alloc(struct net_buf_pool *pool, s32_t timeout); #endif -/** - * @brief Get a buffer from a FIFO. - * - * Get buffer from a FIFO. - * - * @param fifo Which FIFO to take the buffer from. - * @param timeout Affects the action taken should the FIFO be empty. - * If K_NO_WAIT, then return immediately. If K_FOREVER, then wait as - * long as necessary. Otherwise, wait up to the specified number of - * milliseconds before timing out. - * - * @return New buffer or NULL if the FIFO is empty. - */ -#if defined(CONFIG_NET_BUF_LOG) -struct net_buf *net_buf_get_debug(struct k_fifo *fifo, s32_t timeout, - const char *func, int line); -#define net_buf_get(_fifo, _timeout) \ - net_buf_get_debug(_fifo, _timeout, __func__, __LINE__) -#else -struct net_buf *net_buf_get(struct k_fifo *fifo, s32_t timeout); -#endif - -/** - * @brief Destroy buffer from custom destroy callback - * - * This helper is only intended to be used from custom destroy callbacks. - * If no custom destroy callback is given to NET_BUF_POOL_DEFINE() then - * there is no need to use this API. - * - * @param buf Buffer to destroy. - */ -static inline void net_buf_destroy(struct net_buf *buf) -{ - //struct net_buf_pool *pool = net_buf_pool_get(buf->pool_id); - // TODO: should replace the following funcion in our system - //k_lifo_put(&pool->free, buf); -} - /** * @brief Reset buffer * @@ -707,18 +621,6 @@ void net_buf_slist_put(sys_slist_t *list, struct net_buf *buf); */ struct net_buf *net_buf_slist_get(sys_slist_t *list); -/** - * @brief Put a buffer into a FIFO - * - * Put a buffer to the end of a FIFO. If the buffer contains follow-up - * fragments this function will take care of inserting them as well - * into the FIFO. - * - * @param fifo Which FIFO to put the buffer to. - * @param buf Buffer. - */ -void net_buf_put(struct k_fifo *fifo, struct net_buf *buf); - /** * @brief Decrements the reference count of a buffer. * @@ -727,10 +629,10 @@ void net_buf_put(struct k_fifo *fifo, struct net_buf *buf); * * @param buf A valid pointer on a buffer */ -#if defined(CONFIG_NET_BUF_LOG) +#if defined(CONFIG_BLE_MESH_NET_BUF_LOG) void net_buf_unref_debug(struct net_buf *buf, const char *func, int line); #define net_buf_unref(_buf) \ - net_buf_unref_debug(_buf, __func__, __LINE__) + net_buf_unref_debug(_buf, __func__, __LINE__) #else void net_buf_unref(struct net_buf *buf); #endif @@ -744,21 +646,6 @@ void net_buf_unref(struct net_buf *buf); */ struct net_buf *net_buf_ref(struct net_buf *buf); -/** - * @brief Duplicate buffer - * - * Duplicate given buffer including any data and headers currently stored. - * - * @param buf A valid pointer on a buffer - * @param timeout Affects the action taken should the pool be empty. - * If K_NO_WAIT, then return immediately. If K_FOREVER, then - * wait as long as necessary. Otherwise, wait up to the specified - * number of milliseconds before timing out. - * - * @return Duplicated buffer or NULL if out of buffers. - */ -struct net_buf *net_buf_clone(struct net_buf *buf, s32_t timeout); - /** * @brief Get a pointer to the user data of a buffer. * @@ -798,8 +685,7 @@ static inline void *net_buf_user_data(struct net_buf *buf) * * @return The original tail of the buffer. */ -#define net_buf_add_mem(buf, mem, len) net_buf_simple_add_mem(&(buf)->b, \ - mem, len) +#define net_buf_add_mem(buf, mem, len) net_buf_simple_add_mem(&(buf)->b, mem, len) /** * @def net_buf_add_u8 @@ -1019,90 +905,6 @@ static inline void *net_buf_user_data(struct net_buf *buf) */ #define net_buf_headroom(buf) net_buf_simple_headroom(&(buf)->b) -/** - * @def net_buf_tail - * @brief Get the tail pointer for a buffer. - * - * Get a pointer to the end of the data in a buffer. - * - * @param buf Buffer. - * - * @return Tail pointer for the buffer. - */ -#define net_buf_tail(buf) net_buf_simple_tail(&(buf)->b) - -/** @brief Find the last fragment in the fragment list. - * - * @return Pointer to last fragment in the list. - */ -struct net_buf *net_buf_frag_last(struct net_buf *frags); - -/** @brief Insert a new fragment to a chain of bufs. - * - * Insert a new fragment into the buffer fragments list after the parent. - * - * Note: This function takes ownership of the fragment reference so the - * caller is not required to unref. - * - * @param parent Parent buffer/fragment. - * @param frag Fragment to insert. - */ -void net_buf_frag_insert(struct net_buf *parent, struct net_buf *frag); - -/** @brief Add a new fragment to the end of a chain of bufs. - * - * Append a new fragment into the buffer fragments list. - * - * Note: This function takes ownership of the fragment reference so the - * caller is not required to unref. - * - * @param head Head of the fragment chain. - * @param frag Fragment to add. - * - * @return New head of the fragment chain. Either head (if head - * was non-NULL) or frag (if head was NULL). - */ -struct net_buf *net_buf_frag_add(struct net_buf *head, struct net_buf *frag); - -/** @brief Delete existing fragment from a chain of bufs. - * - * @param parent Parent buffer/fragment, or NULL if there is no parent. - * @param frag Fragment to delete. - * - * @return Pointer to the buffer following the fragment, or NULL if it - * had no further fragments. - */ -#if defined(CONFIG_NET_BUF_LOG) -struct net_buf *net_buf_frag_del_debug(struct net_buf *parent, - struct net_buf *frag, - const char *func, int line); -#define net_buf_frag_del(_parent, _frag) \ - net_buf_frag_del_debug(_parent, _frag, __func__, __LINE__) -#else -struct net_buf *net_buf_frag_del(struct net_buf *parent, struct net_buf *frag); -#endif - -/** @brief Calculate amount of bytes stored in fragments. - * - * Calculates the total amount of data stored in the given buffer and the - * fragments linked to it. - * - * @param buf Buffer to start off with. - * - * @return Number of bytes in the buffer and its fragments. - */ -static inline size_t net_buf_frags_len(struct net_buf *buf) -{ - size_t bytes = 0; - - while (buf) { - bytes += buf->len; - buf = buf->frags; - } - - return bytes; -} - /** * @} */ @@ -1111,8 +913,5 @@ static inline size_t net_buf_frags_len(struct net_buf *buf) } #endif - - - -#endif /* __NET_BUF_H */ +#endif /* _BLE_MESH_BUF_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/dlist.h b/components/bt/ble_mesh/mesh_core/include/mesh_dlist.h similarity index 99% rename from components/bt/ble_mesh/mesh_core/dlist.h rename to components/bt/ble_mesh/mesh_core/include/mesh_dlist.h index 0ad75a0d52..31eef746ec 100644 --- a/components/bt/ble_mesh/mesh_core/dlist.h +++ b/components/bt/ble_mesh/mesh_core/include/mesh_dlist.h @@ -17,8 +17,8 @@ * simplifies the adding and removing of nodes to/from the list. */ -#ifndef _misc_dlist__h_ -#define _misc_dlist__h_ +#ifndef _BLE_MESH_DLIST_H_ +#define _BLE_MESH_DLIST_H_ #include #include "mesh_util.h" @@ -27,6 +27,7 @@ extern "C" { #endif + struct _dnode { union { struct _dnode *head; /* ptr to head of list (sys_dlist_t) */ @@ -492,5 +493,4 @@ static inline sys_dnode_t *sys_dlist_get(sys_dlist_t *list) } #endif -#endif /* _misc_dlist__h_ */ - +#endif /* _BLE_MESH_DLIST_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/include/mesh_hci.h b/components/bt/ble_mesh/mesh_core/include/mesh_hci.h index 7e16eef3ff..1c3e093e0b 100644 --- a/components/bt/ble_mesh/mesh_core/include/mesh_hci.h +++ b/components/bt/ble_mesh/mesh_core/include/mesh_hci.h @@ -4,236 +4,131 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#ifndef __MESH_HCI_H -#define __MESH_HCI_H +#ifndef _BLE_MESH_HCI_H_ +#define _BLE_MESH_HCI_H_ #include "mesh_kernel.h" #include "mesh_bearer_adapt.h" #include "mesh_atomic.h" - #ifdef __cplusplus extern "C" { #endif - /* Porting form zephyr/subsys/bluetooth/host/hci_core.h */ -#if defined(CONFIG_BT_BREDR) -#define LMP_FEAT_PAGES_COUNT 3 -#else -#define LMP_FEAT_PAGES_COUNT 1 -#endif +#define BLE_MESH_LMP_FEAT_PAGES_COUNT 1 -/* bt_dev flags: the flags defined here represent BT controller state */ +/* bt_mesh_dev flags: the flags defined here represent BT controller state */ enum { - BT_DEV_ENABLE, - BT_DEV_READY, - BT_DEV_ID_STATIC_RANDOM, - BT_DEV_HAS_PUB_KEY, - BT_DEV_PUB_KEY_BUSY, + BLE_MESH_DEV_ENABLE, + BLE_MESH_DEV_READY, + BLE_MESH_DEV_ID_STATIC_RANDOM, + BLE_MESH_DEV_HAS_PUB_KEY, + BLE_MESH_DEV_PUB_KEY_BUSY, - BT_DEV_ADVERTISING, - BT_DEV_KEEP_ADVERTISING, - BT_DEV_SCANNING, - BT_DEV_EXPLICIT_SCAN, - BT_DEV_ACTIVE_SCAN, - BT_DEV_SCAN_FILTER_DUP, + BLE_MESH_DEV_ADVERTISING, + BLE_MESH_DEV_KEEP_ADVERTISING, + BLE_MESH_DEV_SCANNING, + BLE_MESH_DEV_EXPLICIT_SCAN, + BLE_MESH_DEV_ACTIVE_SCAN, + BLE_MESH_DEV_SCAN_FILTER_DUP, - BT_DEV_RPA_VALID, + BLE_MESH_DEV_RPA_VALID, - BT_DEV_ID_PENDING, - -#if defined(CONFIG_BT_BREDR) - BT_DEV_ISCAN, - BT_DEV_PSCAN, - BT_DEV_INQUIRY, -#endif /* CONFIG_BT_BREDR */ + BLE_MESH_DEV_ID_PENDING, /* Total number of flags - must be at the end of the enum */ - BT_DEV_NUM_FLAGS, + BLE_MESH_DEV_NUM_FLAGS, }; -struct bt_dev_le { +struct bt_mesh_dev_le { /* LE features */ - u8_t features[8]; + u8_t features[8]; + /* LE states */ - u64_t states; - -#if defined(CONFIG_BT_CONN) - /* Controller buffer information */ - u16_t mtu; - struct k_sem pkts; -#endif /* CONFIG_BT_CONN */ - -#if defined(CONFIG_BT_SMP) - /* Size of the the controller resolving list */ - u8_t rl_size; - /* Number of entries in the resolving list. rl_entries > rl_size - * means that host-side resolving is used. - */ - u8_t rl_entries; -#endif /* CONFIG_BT_SMP */ + u64_t states; }; -#if defined(CONFIG_BT_BREDR) -struct bt_dev_br { - /* Max controller's acceptable ACL packet length */ - u16_t mtu; - struct k_sem pkts; - u16_t esco_pkt_type; -}; -#endif - -/* The theoretical max for these is 8 and 64, but there's no point - * in allocating the full memory if we only support a small subset. - * These values must be updated whenever the host implementation is - * extended beyond the current values. - */ -#define BT_DEV_VS_FEAT_MAX 1 -#define BT_DEV_VS_CMDS_MAX 2 - /* State tracking for the local Bluetooth controller */ -struct bt_dev { - /* Local Identity Address */ - bt_addr_le_t id_addr; - - /* Current local Random Address */ - bt_addr_le_t random_addr; +struct bt_mesh_dev { + /* Flags indicate which functionality is enabled */ + BLE_MESH_ATOMIC_DEFINE(flags, BLE_MESH_DEV_NUM_FLAGS); /* Controller version & manufacturer information */ - u8_t hci_version; - u8_t lmp_version; - u16_t hci_revision; - u16_t lmp_subversion; - u16_t manufacturer; + u8_t hci_version; + u8_t lmp_version; + u16_t hci_revision; + u16_t lmp_subversion; + u16_t manufacturer; /* LMP features (pages 0, 1, 2) */ - u8_t features[LMP_FEAT_PAGES_COUNT][8]; - - /* Supported commands */ - u8_t supported_commands[64]; - -#if defined(CONFIG_BT_HCI_VS_EXT) - /* Vendor HCI support */ - u8_t vs_features[BT_DEV_VS_FEAT_MAX]; - u8_t vs_commands[BT_DEV_VS_CMDS_MAX]; -#endif - -#if 0 - struct k_work init; -#endif /* if 0 */ - ATOMIC_DEFINE(flags, BT_DEV_NUM_FLAGS); + u8_t features[BLE_MESH_LMP_FEAT_PAGES_COUNT][8]; /* LE controller specific features */ - struct bt_dev_le le; - -#if defined(CONFIG_BT_BREDR) - /* BR/EDR controller specific features */ - struct bt_dev_br br; -#endif - -#if 0 - /* Number of commands controller can accept */ - struct k_sem ncmd_sem; - - /* Last sent HCI command */ - struct net_buf *sent_cmd; -#endif /* if 0 */ - -#if !defined(CONFIG_BT_RECV_IS_RX_THREAD) - /* Queue for incoming HCI events & ACL data */ - struct k_fifo rx_queue; -#endif - -#if 0 - - /* Queue for high priority HCI events which may unlock waiters - * in other threads. Such events include Number of Completed - * Packets, as well as the Command Complete/Status events. - */ - struct k_fifo rx_prio_queue; - - /* Queue for outgoing HCI commands */ - struct k_fifo cmd_tx_queue; - - /* Registered HCI driver */ - const struct bt_hci_driver *drv; -#endif /* #if 0 */ -#if defined(CONFIG_BT_PRIVACY) - /* Local Identity Resolving Key */ - u8_t irk[16]; - - /* Work used for RPA rotation */ - struct k_delayed_work rpa_update; -#endif + struct bt_mesh_dev_le le; }; -/* Added by Espressif */ -extern struct bt_dev bt_dev; - -void mesh_hci_init(void); - - /*Porting from zephyr/subsys/bluetooth/host/hci_core.h */ /* HCI version from Assigned Numbers */ -#define BT_HCI_VERSION_1_0B 0 -#define BT_HCI_VERSION_1_1 1 -#define BT_HCI_VERSION_1_2 2 -#define BT_HCI_VERSION_2_0 3 -#define BT_HCI_VERSION_2_1 4 -#define BT_HCI_VERSION_3_0 5 -#define BT_HCI_VERSION_4_0 6 -#define BT_HCI_VERSION_4_1 7 -#define BT_HCI_VERSION_4_2 8 -#define BT_HCI_VERSION_5_0 9 +#define BLE_MESH_HCI_VERSION_1_0B 0 +#define BLE_MESH_HCI_VERSION_1_1 1 +#define BLE_MESH_HCI_VERSION_1_2 2 +#define BLE_MESH_HCI_VERSION_2_0 3 +#define BLE_MESH_HCI_VERSION_2_1 4 +#define BLE_MESH_HCI_VERSION_3_0 5 +#define BLE_MESH_HCI_VERSION_4_0 6 +#define BLE_MESH_HCI_VERSION_4_1 7 +#define BLE_MESH_HCI_VERSION_4_2 8 +#define BLE_MESH_HCI_VERSION_5_0 9 /* OpCode Group Fields */ -#define BT_OGF_LINK_CTRL 0x01 -#define BT_OGF_BASEBAND 0x03 -#define BT_OGF_INFO 0x04 -#define BT_OGF_STATUS 0x05 -#define BT_OGF_LE 0x08 -#define BT_OGF_VS 0x3f +#define BLE_MESH_OGF_LINK_CTRL 0x01 +#define BLE_MESH_OGF_BASEBAND 0x03 +#define BLE_MESH_OGF_INFO 0x04 +#define BLE_MESH_OGF_STATUS 0x05 +#define BLE_MESH_OGF_LE 0x08 +#define BLE_MESH_OGF_VS 0x3f /* Construct OpCode from OGF and OCF */ -#define BT_OP(ogf, ocf) ((ocf) | ((ogf) << 10)) +#define BLE_MESH_OP(ogf, ocf) ((ocf) | ((ogf) << 10)) /* Obtain OGF from OpCode */ -#define BT_OGF(opcode) (((opcode) >> 10) & BIT_MASK(6)) -/* Obtain OCF from OpCode */ -#define BT_OCF(opcode) ((opcode) & BIT_MASK(10)) +#define BLE_MESH_OGF(opcode) (((opcode) >> 10) & BIT_MASK(6)) -#define BT_HCI_OP_LE_SET_ADV_PARAM BT_OP(BT_OGF_LE, 0x0006) -struct bt_hci_cp_le_set_adv_param { +/* Obtain OCF from OpCode */ +#define BLE_MESH_OCF(opcode) ((opcode) & BIT_MASK(10)) + +#define BLE_MESH_HCI_OP_SET_ADV_PARAM BLE_MESH_OP(BLE_MESH_OGF_LE, 0x0006) +struct bt_mesh_hci_cp_set_adv_param { u16_t min_interval; u16_t max_interval; u8_t type; u8_t own_addr_type; - bt_addr_le_t direct_addr; + bt_mesh_addr_t direct_addr; u8_t channel_map; u8_t filter_policy; } __packed; -#define BT_HCI_OP_LE_SET_ADV_DATA BT_OP(BT_OGF_LE, 0x0008) -struct bt_hci_cp_le_set_adv_data { +#define BLE_MESH_HCI_OP_SET_ADV_DATA BLE_MESH_OP(BLE_MESH_OGF_LE, 0x0008) +struct bt_mesh_hci_cp_set_adv_data { u8_t len; u8_t data[31]; } __packed; -#define BT_HCI_OP_LE_SET_SCAN_RSP_DATA BT_OP(BT_OGF_LE, 0x0009) -struct bt_hci_cp_le_set_scan_rsp_data { +#define BLE_MESH_HCI_OP_SET_SCAN_RSP_DATA BLE_MESH_OP(BLE_MESH_OGF_LE, 0x0009) +struct bt_mesh_hci_cp_set_scan_rsp_data { u8_t len; u8_t data[31]; } __packed; +/* Added by Espressif */ +extern struct bt_mesh_dev bt_mesh_dev; + +void bt_mesh_hci_init(void); #ifdef __cplusplus } #endif -#endif /* __MESH_HCI_H */ - - - - +#endif /* _BLE_MESH_HCI_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/include/mesh_kernel.h b/components/bt/ble_mesh/mesh_core/include/mesh_kernel.h index efa8d79b5f..785b8b8dfb 100644 --- a/components/bt/ble_mesh/mesh_core/include/mesh_kernel.h +++ b/components/bt/ble_mesh/mesh_core/include/mesh_kernel.h @@ -5,43 +5,33 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef _MESH_KERNEL_ -#define _MESH_KERNEL_ -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "../../../bluedroid/osi/include/osi/mutex.h" +#ifndef _BLE_MESH_KERNEL_H_ +#define _BLE_MESH_KERNEL_H_ + +#include "osi/mutex.h" #include "mesh_types.h" #include "mesh_slist.h" -#include "dlist.h" #include "mesh_atomic.h" - -typedef int atomic_t; -typedef atomic_t atomic_val_t; +#include "mesh_dlist.h" /* number of nsec per usec */ -#define NSEC_PER_USEC 1000 +#define NSEC_PER_USEC 1000 /* number of microseconds per millisecond */ -#define USEC_PER_MSEC 1000 +#define USEC_PER_MSEC 1000 /* number of milliseconds per second */ -#define MSEC_PER_SEC 1000 +#define MSEC_PER_SEC 1000 /* number of microseconds per second */ -#define USEC_PER_SEC ((USEC_PER_MSEC) * (MSEC_PER_SEC)) +#define USEC_PER_SEC ((USEC_PER_MSEC) * (MSEC_PER_SEC)) /* number of nanoseconds per second */ -#define NSEC_PER_SEC ((NSEC_PER_USEC) * (USEC_PER_MSEC) * (MSEC_PER_SEC)) - -#define ATOMIC_MASK(bit) (1 << ((bit) & (ATOMIC_BITS - 1))) -#define ATOMIC_ELEM(addr, bit) ((addr) + ((bit) / ATOMIC_BITS)) +#define NSEC_PER_SEC ((NSEC_PER_USEC) * (USEC_PER_MSEC) * (MSEC_PER_SEC)) /* timeout is not in use */ -#define _INACTIVE (-1) +#define _INACTIVE (-1) -/** - * @} end defgroup stack_apis - */ struct k_work; /** @@ -57,50 +47,19 @@ struct k_work; */ typedef void (*k_work_handler_t)(struct k_work *work); - typedef sys_dlist_t _wait_q_t; struct k_work { - void *_reserved; /* Used by k_queue implementation. */ + void *_reserved; k_work_handler_t handler; - atomic_t flags[1]; int index; }; -#define _K_WORK_INITIALIZER(work_handler) \ - { \ - ._reserved = NULL, \ - .handler = work_handler, \ - .flags = { 0 } \ - } - -struct _timeout; - -typedef void (*_timeout_func_t)(struct _timeout *t); - -struct _timeout { - sys_dnode_t node; - //struct k_thread *thread; - sys_dlist_t *wait_q; - s32_t delta_ticks_from_prev; - _timeout_func_t func; -}; - -/** - * @brief Define an array of atomic variables. - * - * This macro defines an array of atomic variables containing at least - * @a num_bits bits. - * - * @note - * If used from file scope, the bits of the array are initialized to zero; - * if used from within a function, the bits are left uninitialized. - * - * @param name Name of array of atomic variables. - * @param num_bits Number of bits needed. - */ -#define ATOMIC_DEFINE(name, num_bits) \ - atomic_t name[1 + ((num_bits) - 1) / ATOMIC_BITS] +#define _K_WORK_INITIALIZER(work_handler) \ +{ \ + ._reserved = NULL, \ + .handler = work_handler, \ +} /** * @brief Generate null timeout delay. @@ -110,7 +69,7 @@ struct _timeout { * * @return Timeout delay value. */ -#define K_NO_WAIT 0 +#define K_NO_WAIT 0 /** * @brief Generate timeout delay from milliseconds. @@ -122,7 +81,7 @@ struct _timeout { * * @return Timeout delay value. */ -#define K_MSEC(ms) (ms) +#define K_MSEC(ms) (ms) /** * @brief Generate timeout delay from seconds. @@ -134,7 +93,7 @@ struct _timeout { * * @return Timeout delay value. */ -#define K_SECONDS(s) K_MSEC((s) * MSEC_PER_SEC) +#define K_SECONDS(s) K_MSEC((s) * MSEC_PER_SEC) /** * @brief Generate timeout delay from minutes. @@ -146,7 +105,7 @@ struct _timeout { * * @return Timeout delay value. */ -#define K_MINUTES(m) K_SECONDS((m) * 60) +#define K_MINUTES(m) K_SECONDS((m) * 60) /** * @brief Generate timeout delay from hours. @@ -158,7 +117,7 @@ struct _timeout { * * @return Timeout delay value. */ -#define K_HOURS(h) K_MINUTES((h) * 60) +#define K_HOURS(h) K_MINUTES((h) * 60) /** * @brief Generate infinite timeout delay. @@ -168,8 +127,7 @@ struct _timeout { * * @return Timeout delay value. */ -#define K_FOREVER (-1) - +#define K_FOREVER (-1) /** * @brief Get system uptime (32-bit version). @@ -186,114 +144,10 @@ struct _timeout { */ u32_t k_uptime_get_32(void); -struct k_sem { - osi_mutex_t mutex; -}; - -struct k_queue { - sys_slist_t data_q; - union { - _wait_q_t wait_q; - // TODO: The following not used now, delete it temporarily. - //_POLL_EVENT; - }; - // TODO: The following not used now, delete it temporarily. - //_OBJECT_TRACING_NEXT_PTR(k_queue); -}; - -struct k_work_q { - struct k_queue queue; -}; - - - -/** - * @cond INTERNAL_HIDDEN - */ - -struct k_fifo { - struct k_queue _queue; -}; - -struct k_lifo { - struct k_queue _queue; -}; - struct k_delayed_work { struct k_work work; - struct _timeout timeout; - struct k_work_q *work_q; }; -#define _K_QUEUE_INITIALIZER(obj) \ - { \ - .wait_q = SYS_DLIST_STATIC_INIT(&obj.wait_q), \ - .data_q = SYS_SLIST_STATIC_INIT(&obj.data_q), \ - } - - -#define _K_FIFO_INITIALIZER(obj) \ - { \ - ._queue = _K_QUEUE_INITIALIZER(obj._queue) \ - } - -#define _K_LIFO_INITIALIZER(obj) \ - { \ - ._queue = _K_QUEUE_INITIALIZER(obj._queue) \ - } - - -/** - * @brief Statically define and initialize a fifo. - * - * The fifo can be accessed outside the module where it is defined using: - * - * @code extern struct k_fifo ; @endcode - * - * @param name Name of the fifo. - */ -#define K_FIFO_DEFINE(name) \ - struct k_fifo name \ - __in_section(_k_queue, static, name) = \ - _K_FIFO_INITIALIZER(name) - - -/* initialize the timeouts part of k_thread when enabled in the kernel */ - -static inline void _init_timeout(struct _timeout *t, _timeout_func_t func) -{ - /* - * Must be initialized here and when dequeueing a timeout so that code - * not dealing with timeouts does not have to handle this, such as when - * waiting forever on a semaphore. - */ - t->delta_ticks_from_prev = _INACTIVE; - - /* - * Must be initialized here so that k_wakeup can - * verify the thread is not on a wait queue before aborting a timeout. - */ - t->wait_q = NULL; - - /* - * Function must be initialized before being potentially called. - */ - t->func = func; - - /* - * These are initialized when enqueing on the timeout queue: - * - * thread->timeout.node.next - * thread->timeout.node.prev - */ -} - -unsigned int irq_lock(void); - -void irq_unlock(unsigned int key); - -void mesh_k_init(void); - /** * @brief Submit a delayed work item to the system workqueue. * @@ -326,8 +180,7 @@ void mesh_k_init(void); * @retval -EINVAL Work item is being processed or has completed its work. * @retval -EADDRINUSE Work item is pending on a different workqueue. */ -int k_delayed_work_submit(struct k_delayed_work *work, - s32_t delay); +int k_delayed_work_submit(struct k_delayed_work *work, s32_t delay); /** * @brief Get time remaining before a delayed work gets scheduled. @@ -365,13 +218,9 @@ s32_t k_delayed_work_remaining_get(struct k_delayed_work *work); */ static inline void k_work_submit(struct k_work *work) { - // TODO: - if (work != NULL) { + if (work && work->handler) { work->handler(work); } - - return; - //k_work_submit_to_queue(&k_sys_work_q, work); } /** @@ -417,56 +266,10 @@ s64_t k_uptime_get(void); */ void k_sleep(s32_t duration); -/** - * @brief Give a semaphore. - * - * This routine gives @a sem, unless the semaphore is already at its maximum - * permitted count. - * - * @note Can be called by ISRs. - * - * @param sem Address of the semaphore. - * - * @return N/A - */ -void k_sem_give(struct k_sem *sem); +unsigned int bt_mesh_irq_lock(void); +void bt_mesh_irq_unlock(unsigned int key); -/** - * @brief Initialize a semaphore. - * - * This routine initializes a semaphore object, prior to its first use. - * - * @param sem Address of the semaphore. - * @param initial_count Initial semaphore count. - * @param limit Maximum permitted semaphore count. - * - * @return N/A - */ -void k_sem_init(struct k_sem *sem, unsigned int initial_count, - unsigned int limit); +void bt_mesh_k_init(void); -/** - * @brief Take a semaphore. - * - * This routine takes @a sem. - * - * @note Can be called by ISRs, but @a timeout must be set to K_NO_WAIT. - * - * @param sem Address of the semaphore. - * @param timeout Waiting period to take the semaphore (in milliseconds), - * or one of the special values K_NO_WAIT and K_FOREVER. - * - * @note When porting code from the nanokernel legacy API to the new API, be - * careful with the return value of this function. The return value is the - * reverse of the one of nano_sem_take family of APIs: 0 means success, and - * non-zero means failure, while the nano_sem_take family returns 1 for success - * and 0 for failure. - * - * @retval 0 Semaphore taken. - * @retval -EBUSY Returned without waiting. - * @retval -EAGAIN Waiting period timed out. - */ -int k_sem_take(struct k_sem *sem, s32_t timeout); - -#endif /* #ifndef _MESH_KERNEL_ */ +#endif /* _BLE_MESH_KERNEL_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/include/mesh_main.h b/components/bt/ble_mesh/mesh_core/include/mesh_main.h index ae84da6b11..f0ad314da0 100644 --- a/components/bt/ble_mesh/mesh_core/include/mesh_main.h +++ b/components/bt/ble_mesh/mesh_core/include/mesh_main.h @@ -8,12 +8,11 @@ * * SPDX-License-Identifier: Apache-2.0 */ -#ifndef __BT_MESH_MAIN_H -#define __BT_MESH_MAIN_H +#ifndef _BLE_MESH_MAIN_H_ +#define _BLE_MESH_MAIN_H_ #include "mesh_util.h" #include "mesh_access.h" -#if CONFIG_BT_MESH /** * @brief Bluetooth Mesh Provisioning @@ -23,30 +22,30 @@ */ typedef enum { - BT_MESH_NO_OUTPUT = 0, - BT_MESH_BLINK = BIT(0), - BT_MESH_BEEP = BIT(1), - BT_MESH_VIBRATE = BIT(2), - BT_MESH_DISPLAY_NUMBER = BIT(3), - BT_MESH_DISPLAY_STRING = BIT(4), + BLE_MESH_NO_OUTPUT = 0, + BLE_MESH_BLINK = BIT(0), + BLE_MESH_BEEP = BIT(1), + BLE_MESH_VIBRATE = BIT(2), + BLE_MESH_DISPLAY_NUMBER = BIT(3), + BLE_MESH_DISPLAY_STRING = BIT(4), } bt_mesh_output_action_t; typedef enum { - BT_MESH_NO_INPUT = 0, - BT_MESH_PUSH = BIT(0), - BT_MESH_TWIST = BIT(1), - BT_MESH_ENTER_NUMBER = BIT(2), - BT_MESH_ENTER_STRING = BIT(3), + BLE_MESH_NO_INPUT = 0, + BLE_MESH_PUSH = BIT(0), + BLE_MESH_TWIST = BIT(1), + BLE_MESH_ENTER_NUMBER = BIT(2), + BLE_MESH_ENTER_STRING = BIT(3), } bt_mesh_input_action_t; typedef enum { - BT_MESH_PROV_ADV = BIT(0), - BT_MESH_PROV_GATT = BIT(1), + BLE_MESH_PROV_ADV = BIT(0), + BLE_MESH_PROV_GATT = BIT(1), } bt_mesh_prov_bearer_t; /** Provisioning properties & capabilities. */ struct bt_mesh_prov { -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE /** The UUID that's used when advertising as unprovisioned */ const u8_t *uuid; @@ -154,9 +153,9 @@ struct bt_mesh_prov { * unprovisioned advertising on one or more provisioning bearers. */ void (*reset)(void); -#endif /* CONFIG_BT_MESH_NODE */ +#endif /* CONFIG_BLE_MESH_NODE */ -#if CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_PROVISIONER /* Provisioner device uuid */ const u8_t *prov_uuid; @@ -274,13 +273,13 @@ struct bt_mesh_prov { u16_t unicast_addr, u8_t element_num, u16_t netkey_idx); -#endif /* CONFIG_BT_MESH_PROVISIONER */ +#endif /* CONFIG_BLE_MESH_PROVISIONER */ }; /** @brief Provide provisioning input OOB string. * * This is intended to be called after the bt_mesh_prov input callback - * has been called with BT_MESH_ENTER_STRING as the action. + * has been called with BLE_MESH_ENTER_STRING as the action. * * @param str String. * @@ -291,7 +290,7 @@ int bt_mesh_input_string(const char *str); /** @brief Provide provisioning input OOB number. * * This is intended to be called after the bt_mesh_prov input callback - * has been called with BT_MESH_ENTER_NUMBER as the action. + * has been called with BLE_MESH_ENTER_NUMBER as the action. * * @param num Number. * @@ -327,7 +326,7 @@ bool bt_mesh_is_provisioner_en(void); /* The following API is for fast provisioning */ -#if CONFIG_BT_MESH_FAST_PROV +#if CONFIG_BLE_MESH_FAST_PROV /** @brief Change the device action * @@ -338,14 +337,14 @@ bool bt_mesh_is_provisioner_en(void); */ u8_t bt_mesh_set_fast_prov_action(u8_t action); -#endif /* CONFIG_BT_MESH_FAST_PROV */ +#endif /* CONFIG_BLE_MESH_FAST_PROV */ -#if CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_PROVISIONER /** @brief Provide provisioning input OOB string. * * This is intended to be called after the bt_mesh_prov input callback - * has been called with BT_MESH_ENTER_STRING as the action. + * has been called with BLE_MESH_ENTER_STRING as the action. * * @param str String. * @@ -356,7 +355,7 @@ int bt_mesh_prov_input_string(const char *str); /** @brief Provide provisioning input OOB number. * * This is intended to be called after the bt_mesh_prov input callback - * has been called with BT_MESH_ENTER_NUMBER as the action. + * has been called with BLE_MESH_ENTER_NUMBER as the action. * * @param num Number. * @@ -384,7 +383,7 @@ int bt_mesh_provisioner_enable(bt_mesh_prov_bearer_t bearers); */ int bt_mesh_provisioner_disable(bt_mesh_prov_bearer_t bearers); -#endif /* CONFIG_BT_MESH_PROVISIONER */ +#endif /* CONFIG_BLE_MESH_PROVISIONER */ /** * @} @@ -398,36 +397,36 @@ int bt_mesh_provisioner_disable(bt_mesh_prov_bearer_t bearers); */ /* Primary Network Key index */ -#define BT_MESH_NET_PRIMARY 0x000 +#define BLE_MESH_NET_PRIMARY 0x000 -#define BT_MESH_RELAY_DISABLED 0x00 -#define BT_MESH_RELAY_ENABLED 0x01 -#define BT_MESH_RELAY_NOT_SUPPORTED 0x02 +#define BLE_MESH_RELAY_DISABLED 0x00 +#define BLE_MESH_RELAY_ENABLED 0x01 +#define BLE_MESH_RELAY_NOT_SUPPORTED 0x02 -#define BT_MESH_BEACON_DISABLED 0x00 -#define BT_MESH_BEACON_ENABLED 0x01 +#define BLE_MESH_BEACON_DISABLED 0x00 +#define BLE_MESH_BEACON_ENABLED 0x01 -#define BT_MESH_GATT_PROXY_DISABLED 0x00 -#define BT_MESH_GATT_PROXY_ENABLED 0x01 -#define BT_MESH_GATT_PROXY_NOT_SUPPORTED 0x02 +#define BLE_MESH_GATT_PROXY_DISABLED 0x00 +#define BLE_MESH_GATT_PROXY_ENABLED 0x01 +#define BLE_MESH_GATT_PROXY_NOT_SUPPORTED 0x02 -#define BT_MESH_FRIEND_DISABLED 0x00 -#define BT_MESH_FRIEND_ENABLED 0x01 -#define BT_MESH_FRIEND_NOT_SUPPORTED 0x02 +#define BLE_MESH_FRIEND_DISABLED 0x00 +#define BLE_MESH_FRIEND_ENABLED 0x01 +#define BLE_MESH_FRIEND_NOT_SUPPORTED 0x02 -#define BT_MESH_NODE_IDENTITY_STOPPED 0x00 -#define BT_MESH_NODE_IDENTITY_RUNNING 0x01 -#define BT_MESH_NODE_IDENTITY_NOT_SUPPORTED 0x02 +#define BLE_MESH_NODE_IDENTITY_STOPPED 0x00 +#define BLE_MESH_NODE_IDENTITY_RUNNING 0x01 +#define BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED 0x02 /* Features */ -#define BT_MESH_FEAT_RELAY BIT(0) -#define BT_MESH_FEAT_PROXY BIT(1) -#define BT_MESH_FEAT_FRIEND BIT(2) -#define BT_MESH_FEAT_LOW_POWER BIT(3) -#define BT_MESH_FEAT_SUPPORTED (BT_MESH_FEAT_RELAY | \ - BT_MESH_FEAT_PROXY | \ - BT_MESH_FEAT_FRIEND | \ - BT_MESH_FEAT_LOW_POWER) +#define BLE_MESH_FEAT_RELAY BIT(0) +#define BLE_MESH_FEAT_PROXY BIT(1) +#define BLE_MESH_FEAT_FRIEND BIT(2) +#define BLE_MESH_FEAT_LOW_POWER BIT(3) +#define BLE_MESH_FEAT_SUPPORTED (BLE_MESH_FEAT_RELAY | \ + BLE_MESH_FEAT_PROXY | \ + BLE_MESH_FEAT_FRIEND | \ + BLE_MESH_FEAT_LOW_POWER) /** @brief Initialize Mesh support * @@ -530,5 +529,4 @@ void bt_mesh_lpn_set_cb(void (*cb)(u16_t friend_addr, bool established)); * @} */ -#endif /* __BT_MESH_MAIN_H */ -#endif /* #if CONFIG_BT_MESH */ +#endif /* _BLE_MESH_MAIN_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/include/proxy.h b/components/bt/ble_mesh/mesh_core/include/mesh_proxy.h similarity index 87% rename from components/bt/ble_mesh/mesh_core/include/proxy.h rename to components/bt/ble_mesh/mesh_core/include/mesh_proxy.h index be4ba259b4..0b14d9e184 100644 --- a/components/bt/ble_mesh/mesh_core/include/proxy.h +++ b/components/bt/ble_mesh/mesh_core/include/mesh_proxy.h @@ -8,8 +8,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef __BT_MESH_PROXY_H -#define __BT_MESH_PROXY_H +#ifndef _BLE_MESH_PROXY_H_ +#define _BLE_MESH_PROXY_H_ #include /** @@ -34,4 +34,4 @@ int bt_mesh_proxy_identity_enable(void); * @} */ -#endif /* __BT_MESH_PROXY_H */ +#endif /* _BLE_MESH_PROXY_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/include/mesh_slist.h b/components/bt/ble_mesh/mesh_core/include/mesh_slist.h index f1bab90cd6..4ddf427e6a 100644 --- a/components/bt/ble_mesh/mesh_core/include/mesh_slist.h +++ b/components/bt/ble_mesh/mesh_core/include/mesh_slist.h @@ -14,8 +14,8 @@ * calls to functions must be protected with synchronization primitives. */ -#ifndef __SLIST_H__ -#define __SLIST_H__ +#ifndef _BLE_MESH_SLIST_H_ +#define _BLE_MESH_SLIST_H_ #include #include @@ -25,7 +25,6 @@ extern "C" { #endif - struct _snode { struct _snode *next; }; @@ -54,8 +53,8 @@ typedef struct _slist sys_slist_t; * @param __sl A pointer on a sys_slist_t to iterate on * @param __sn A sys_snode_t pointer to peek each node of the list */ -#define SYS_SLIST_FOR_EACH_NODE(__sl, __sn) \ - for (__sn = sys_slist_peek_head(__sl); __sn; \ +#define SYS_SLIST_FOR_EACH_NODE(__sl, __sn) \ + for (__sn = sys_slist_peek_head(__sl); __sn; \ __sn = sys_slist_peek_next(__sn)) /** @@ -79,9 +78,9 @@ typedef struct _slist sys_slist_t; * it contains the starting node, or NULL to start from the head */ #define SYS_SLIST_ITERATE_FROM_NODE(__sl, __sn) \ - for (__sn = __sn ? sys_slist_peek_next_no_check(__sn) \ - : sys_slist_peek_head(__sl); \ - __sn; \ + for (__sn = __sn ? sys_slist_peek_next_no_check(__sn) \ + : sys_slist_peek_head(__sl); \ + __sn; \ __sn = sys_slist_peek_next(__sn)) /** @@ -100,10 +99,10 @@ typedef struct _slist sys_slist_t; * @param __sn A sys_snode_t pointer to peek each node of the list * @param __sns A sys_snode_t pointer for the loop to run safely */ -#define SYS_SLIST_FOR_EACH_NODE_SAFE(__sl, __sn, __sns) \ +#define SYS_SLIST_FOR_EACH_NODE_SAFE(__sl, __sn, __sns) \ for (__sn = sys_slist_peek_head(__sl), \ __sns = sys_slist_peek_next(__sn); \ - __sn; __sn = __sns, \ + __sn; __sn = __sns, \ __sns = sys_slist_peek_next(__sn)) /* @@ -114,8 +113,8 @@ typedef struct _slist sys_slist_t; * @param __cn Container struct type pointer * @param __n The field name of sys_node_t within the container struct */ -#define SYS_SLIST_CONTAINER(__ln, __cn, __n) \ - ((__ln) ? CONTAINER_OF((__ln), __typeof__(*(__cn)), __n) : NULL) +#define SYS_SLIST_CONTAINER(__ln, __cn, __n) \ + ((__ln) ? CONTAINER_OF((__ln), __typeof__(*(__cn)), __n) : NULL) /* * @brief Provide the primitive to peek container of the list head * @@ -123,8 +122,8 @@ typedef struct _slist sys_slist_t; * @param __cn Container struct type pointer * @param __n The field name of sys_node_t within the container struct */ -#define SYS_SLIST_PEEK_HEAD_CONTAINER(__sl, __cn, __n) \ - SYS_SLIST_CONTAINER(sys_slist_peek_head(__sl), __cn, __n) +#define SYS_SLIST_PEEK_HEAD_CONTAINER(__sl, __cn, __n) \ + SYS_SLIST_CONTAINER(sys_slist_peek_head(__sl), __cn, __n) /* * @brief Provide the primitive to peek container of the list tail @@ -133,8 +132,8 @@ typedef struct _slist sys_slist_t; * @param __cn Container struct type pointer * @param __n The field name of sys_node_t within the container struct */ -#define SYS_SLIST_PEEK_TAIL_CONTAINER(__sl, __cn, __n) \ - SYS_SLIST_CONTAINER(sys_slist_peek_tail(__sl), __cn, __n) +#define SYS_SLIST_PEEK_TAIL_CONTAINER(__sl, __cn, __n) \ + SYS_SLIST_CONTAINER(sys_slist_peek_tail(__sl), __cn, __n) /* * @brief Provide the primitive to peek the next container @@ -143,9 +142,9 @@ typedef struct _slist sys_slist_t; * @param __n The field name of sys_node_t within the container struct */ -#define SYS_SLIST_PEEK_NEXT_CONTAINER(__cn, __n) \ - ((__cn) ? SYS_SLIST_CONTAINER(sys_slist_peek_next(&((__cn)->__n)), \ - __cn, __n) : NULL) +#define SYS_SLIST_PEEK_NEXT_CONTAINER(__cn, __n) \ + ((__cn) ? SYS_SLIST_CONTAINER(sys_slist_peek_next(&((__cn)->__n)), \ + __cn, __n) : NULL) /** * @brief Provide the primitive to iterate on a list under a container @@ -161,8 +160,8 @@ typedef struct _slist sys_slist_t; * @param __cn A pointer to peek each entry of the list * @param __n The field name of sys_node_t within the container struct */ -#define SYS_SLIST_FOR_EACH_CONTAINER(__sl, __cn, __n) \ - for (__cn = SYS_SLIST_PEEK_HEAD_CONTAINER(__sl, __cn, __n); __cn; \ +#define SYS_SLIST_FOR_EACH_CONTAINER(__sl, __cn, __n) \ + for (__cn = SYS_SLIST_PEEK_HEAD_CONTAINER(__sl, __cn, __n); __cn; \ __cn = SYS_SLIST_PEEK_NEXT_CONTAINER(__cn, __n)) /** @@ -181,7 +180,7 @@ typedef struct _slist sys_slist_t; * @param __n The field name of sys_node_t within the container struct */ #define SYS_SLIST_FOR_EACH_CONTAINER_SAFE(__sl, __cn, __cns, __n) \ - for (__cn = SYS_SLIST_PEEK_HEAD_CONTAINER(__sl, __cn, __n), \ + for (__cn = SYS_SLIST_PEEK_HEAD_CONTAINER(__sl, __cn, __n), \ __cns = SYS_SLIST_PEEK_NEXT_CONTAINER(__cn, __n); __cn; \ __cn = __cns, __cns = SYS_SLIST_PEEK_NEXT_CONTAINER(__cn, __n)) @@ -461,10 +460,9 @@ static inline bool sys_slist_find_and_remove(sys_slist_t *list, return false; } - #ifdef __cplusplus } #endif -#endif /* __SLIST_H__ */ +#endif /* _BLE_MESH_SLIST_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/include/mesh_trace.h b/components/bt/ble_mesh/mesh_core/include/mesh_trace.h index a498863323..325c807f93 100644 --- a/components/bt/ble_mesh/mesh_core/include/mesh_trace.h +++ b/components/bt/ble_mesh/mesh_core/include/mesh_trace.h @@ -6,6 +6,9 @@ * SPDX-License-Identifier: Apache-2.0 */ +#ifndef _BLE_MESH_TRACE_H_ +#define _BLE_MESH_TRACE_H_ + #include "esp_log.h" #include "sdkconfig.h" @@ -30,85 +33,99 @@ #define LOG_LEVEL_VERBOSE 5 #endif /*LOG_LEVEL_VERBOSE */ -#ifdef CONFIG_BT_MESH_STACK_INITIAL_TRACE_LEVEL -#define MESH_LOG_LEVEL CONFIG_BT_MESH_STACK_INITIAL_TRACE_LEVEL +#ifdef CONFIG_BLE_MESH_STACK_TRACE_LEVEL +#define MESH_LOG_LEVEL CONFIG_BLE_MESH_STACK_TRACE_LEVEL #else -#define MESH_LOG_LEVEL LOG_LEVEL_WARN +#define MESH_LOG_LEVEL LOG_LEVEL_WARN #endif -#ifdef CONFIG_BT_MESH_NET_BUF_TRACE_LEVEL -#define NET_BUF_LOG_LEVEL CONFIG_BT_MESH_NET_BUF_TRACE_LEVEL +#ifdef CONFIG_BLE_MESH_NET_BUF_TRACE_LEVEL +#define NET_BUF_LOG_LEVEL CONFIG_BLE_MESH_NET_BUF_TRACE_LEVEL #else -#define NET_BUF_LOG_LEVEL LOG_LEVEL_WARN +#define NET_BUF_LOG_LEVEL LOG_LEVEL_WARN #endif - #define MESH_TRACE_TAG "BLE_MESH" #if (LOG_LOCAL_LEVEL >= 4) -#define BT_MESH_LOG_LOCAL_LEVEL_MAPPING (LOG_LOCAL_LEVEL + 1) +#define BLE_MESH_LOG_LOCAL_LEVEL_MAPPING (LOG_LOCAL_LEVEL + 1) #else -#define BT_MESH_LOG_LOCAL_LEVEL_MAPPING LOG_LOCAL_LEVEL +#define BLE_MESH_LOG_LOCAL_LEVEL_MAPPING LOG_LOCAL_LEVEL #endif #ifndef MAX #define MAX(a, b) ((a) > (b) ? (a) : (b)) #endif /* MAX(a, b) */ -#define BT_MESH_LOG_LEVEL_CHECK(LAYER, LEVEL) (MAX(LAYER##_LOG_LEVEL, BT_MESH_LOG_LOCAL_LEVEL_MAPPING) >= LOG_LEVEL_##LEVEL) -#define BT_MESH_PRINT_E(tag, format, ...) {esp_log_write(ESP_LOG_ERROR, tag, LOG_FORMAT(E, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } -#define BT_MESH_PRINT_W(tag, format, ...) {esp_log_write(ESP_LOG_WARN, tag, LOG_FORMAT(W, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } -#define BT_MESH_PRINT_I(tag, format, ...) {esp_log_write(ESP_LOG_INFO, tag, LOG_FORMAT(I, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } -#define BT_MESH_PRINT_D(tag, format, ...) {esp_log_write(ESP_LOG_DEBUG, tag, LOG_FORMAT(D, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } -#define BT_MESH_PRINT_V(tag, format, ...) {esp_log_write(ESP_LOG_VERBOSE, tag, LOG_FORMAT(V, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } +#define BLE_MESH_LOG_LEVEL_CHECK(LAYER, LEVEL) (MAX(LAYER##_LOG_LEVEL, BLE_MESH_LOG_LOCAL_LEVEL_MAPPING) >= LOG_LEVEL_##LEVEL) -#ifndef __ASSERT_NO_MSG -#define __ASSERT_NO_MSG(x) do { if (!(x)) BT_MESH_PRINT_E(MESH_TRACE_TAG, "bt mesh error %s %u\n", __FILE__, __LINE__); } while (0) +#define BLE_MESH_PRINT_E(tag, format, ...) {esp_log_write(ESP_LOG_ERROR, tag, LOG_FORMAT(E, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } +#define BLE_MESH_PRINT_W(tag, format, ...) {esp_log_write(ESP_LOG_WARN, tag, LOG_FORMAT(W, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } +#define BLE_MESH_PRINT_I(tag, format, ...) {esp_log_write(ESP_LOG_INFO, tag, LOG_FORMAT(I, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } +#define BLE_MESH_PRINT_D(tag, format, ...) {esp_log_write(ESP_LOG_DEBUG, tag, LOG_FORMAT(D, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } +#define BLE_MESH_PRINT_V(tag, format, ...) {esp_log_write(ESP_LOG_VERBOSE, tag, LOG_FORMAT(V, format), esp_log_timestamp(), tag, ##__VA_ARGS__); } + +#define printk ets_printf + +#define _STRINGIFY(x) #x +#define STRINGIFY(s) _STRINGIFY(s) + +#ifndef __ASSERT +#define __ASSERT(test, fmt, ...) \ + do { \ + if (!(test)) { \ + printk("ASSERTION FAIL [%s] @ %s:%d:\n\t", \ + _STRINGIFY(test), \ + __FILE__, \ + __LINE__); \ + printk(fmt, ##__VA_ARGS__); \ + for (;;); \ + } \ + } while ((0)) #endif -#if !CONFIG_BT_MESH_NO_LOG -#define BT_ERR(fmt, args...) do {if ((MESH_LOG_LEVEL >= LOG_LEVEL_ERROR) && BT_MESH_LOG_LEVEL_CHECK(MESH, ERROR)) BT_MESH_PRINT_E(MESH_TRACE_TAG, fmt, ## args);} while(0) -#define BT_WARN(fmt, args...) do {if ((MESH_LOG_LEVEL >= LOG_LEVEL_WARN) && BT_MESH_LOG_LEVEL_CHECK(MESH, WARN)) BT_MESH_PRINT_W(MESH_TRACE_TAG, fmt, ## args);} while(0) -#define BT_INFO(fmt, args...) do {if ((MESH_LOG_LEVEL >= LOG_LEVEL_INFO) && BT_MESH_LOG_LEVEL_CHECK(MESH, INFO)) BT_MESH_PRINT_I(MESH_TRACE_TAG, fmt, ## args);} while(0) -#define BT_DBG(fmt, args...) do {if ((MESH_LOG_LEVEL >= LOG_LEVEL_DEBUG) && BT_MESH_LOG_LEVEL_CHECK(MESH, DEBUG)) BT_MESH_PRINT_D(MESH_TRACE_TAG, fmt, ## args);} while(0) -#else /* #if !CONFIG_BT_STACK_NO_LOG */ +#ifndef __ASSERT_NO_MSG +#define __ASSERT_NO_MSG(x) do { if (!(x)) BLE_MESH_PRINT_E(MESH_TRACE_TAG, "error %s %u", __FILE__, __LINE__); } while (0) +#endif + +#if !CONFIG_BLE_MESH_NO_LOG +#define BT_ERR(fmt, args...) do {if ((MESH_LOG_LEVEL >= LOG_LEVEL_ERROR) && BLE_MESH_LOG_LEVEL_CHECK(MESH, ERROR)) BLE_MESH_PRINT_E(MESH_TRACE_TAG, fmt, ## args);} while(0) +#define BT_WARN(fmt, args...) do {if ((MESH_LOG_LEVEL >= LOG_LEVEL_WARN) && BLE_MESH_LOG_LEVEL_CHECK(MESH, WARN)) BLE_MESH_PRINT_W(MESH_TRACE_TAG, fmt, ## args);} while(0) +#define BT_INFO(fmt, args...) do {if ((MESH_LOG_LEVEL >= LOG_LEVEL_INFO) && BLE_MESH_LOG_LEVEL_CHECK(MESH, INFO)) BLE_MESH_PRINT_I(MESH_TRACE_TAG, fmt, ## args);} while(0) +#define BT_DBG(fmt, args...) do {if ((MESH_LOG_LEVEL >= LOG_LEVEL_DEBUG) && BLE_MESH_LOG_LEVEL_CHECK(MESH, DEBUG)) BLE_MESH_PRINT_D(MESH_TRACE_TAG, fmt, ## args);} while(0) +#else #define BT_ERR(fmt, args...) #define BT_WARN(fmt, args...) #define BT_INFO(fmt, args...) #define BT_DBG(fmt, args...) -#endif /* #if !CONFIG_BT_STACK_NO_LOG */ +#endif -#if defined(CONFIG_NET_BUF_LOG) && (!CONFIG_BT_MESH_NO_LOG) -#define NET_BUF_DBG(fmt, ...) do {if ((MESH_LOG_LEVEL >= LOG_LEVEL_ERROR) && BT_MESH_LOG_LEVEL_CHECK(NET_BUF, DEBUG)) BT_MESH_PRINT_D(MESH_TRACE_TAG, fmt, ## args);} while(0) -#define NET_BUF_ERR(fmt, ...) do {if ((MESH_LOG_LEVEL >= LOG_LEVEL_ERROR) && BT_MESH_LOG_LEVEL_CHECK(NET_BUF, ERROR)) BT_MESH_PRINT_E(MESH_TRACE_TAG, fmt, ## args);} while(0) -#define NET_BUF_WARN(fmt, ...) do {if ((MESH_LOG_LEVEL >= LOG_LEVEL_ERROR) && BT_MESH_LOG_LEVEL_CHECK(NET_BUF, WARN)) BT_MESH_PRINT_W(MESH_TRACE_TAG, fmt, ## args);} while(0) -#define NET_BUF_INFO(fmt, ...) do {if ((MESH_LOG_LEVEL >= LOG_LEVEL_ERROR) && BT_MESH_LOG_LEVEL_CHECK(NET_BUF, INFO)) BT_MESH_PRINT_I(MESH_TRACE_TAG, fmt, ## args);} while(0) -#define NET_BUF_ASSERT(cond) do { if (!(cond)) { \ - NET_BUF_ERR("assert: '" #cond "' failed"); \ - } } while (0) +#if defined(CONFIG_BLE_MESH_NET_BUF_LOG) && (!CONFIG_BLE_MESH_NO_LOG) +#define NET_BUF_ERR(fmt, args...) do {if ((NET_BUF_LOG_LEVEL >= LOG_LEVEL_ERROR) && BLE_MESH_LOG_LEVEL_CHECK(NET_BUF, ERROR)) BLE_MESH_PRINT_E(MESH_TRACE_TAG, fmt, ## args);} while(0) +#define NET_BUF_WARN(fmt, args...) do {if ((NET_BUF_LOG_LEVEL >= LOG_LEVEL_WARN) && BLE_MESH_LOG_LEVEL_CHECK(NET_BUF, WARN)) BLE_MESH_PRINT_W(MESH_TRACE_TAG, fmt, ## args);} while(0) +#define NET_BUF_INFO(fmt, args...) do {if ((NET_BUF_LOG_LEVEL >= LOG_LEVEL_INFO) && BLE_MESH_LOG_LEVEL_CHECK(NET_BUF, INFO)) BLE_MESH_PRINT_I(MESH_TRACE_TAG, fmt, ## args);} while(0) +#define NET_BUF_DBG(fmt, args...) do {if ((NET_BUF_LOG_LEVEL >= LOG_LEVEL_DEBUG) && BLE_MESH_LOG_LEVEL_CHECK(NET_BUF, DEBUG)) BLE_MESH_PRINT_D(MESH_TRACE_TAG, fmt, ## args);} while(0) +#define NET_BUF_ASSERT(cond) __ASSERT_NO_MSG(cond) #else -#define NET_BUF_DBG(fmt, ...) -#define NET_BUF_ERR(fmt, ...) -#define NET_BUF_WARN(fmt, ...) -#define NET_BUF_INFO(fmt, ...) +#define NET_BUF_ERR(fmt, args...) +#define NET_BUF_WARN(fmt, args...) +#define NET_BUF_INFO(fmt, args...) +#define NET_BUF_DBG(fmt, args...) #define NET_BUF_ASSERT(cond) -#endif /* CONFIG_NET_BUF_LOG */ +#endif -#if defined(CONFIG_NET_BUF_SIMPLE_LOG) && (!CONFIG_BT_MESH_NO_LOG) -#define NET_BUF_SIMPLE_DBG(fmt, ...) do {if (MESH_LOG_LEVEL >= LOG_LEVEL_DEBUG) esp_log_write(ESP_LOG_ERROR, MESH_TRACE_TAG, LOG_FORMAT(D, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__);} while(0) -#define NET_BUF_SIMPLE_ERR(fmt, ...) do {if (MESH_LOG_LEVEL >= LOG_LEVEL_ERROR) esp_log_write(ESP_LOG_ERROR, MESH_TRACE_TAG, LOG_FORMAT(E, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__);} while(0) -#define NET_BUF_SIMPLE_WARN(fmt, ...) do {if (MESH_LOG_LEVEL >= LOG_LEVEL_WARN) esp_log_write(ESP_LOG_ERROR, MESH_TRACE_TAG, LOG_FORMAT(W, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__);} while(0) -#define NET_BUF_SIMPLE_INFO(fmt, ...) do {if (MESH_LOG_LEVEL >= LOG_LEVEL_INFO) esp_log_write(ESP_LOG_ERROR, MESH_TRACE_TAG, LOG_FORMAT(I, format), esp_log_timestamp(), "BT_LOG", ##__VA_ARGS__);} while(0) -#define NET_BUF_SIMPLE_ASSERT(cond) assert(cond != NULL) -#else /* CONFIG_NET_BUF_SIMPLE_LOG */ -#define NET_BUF_SIMPLE_DBG(fmt, ...) -#define NET_BUF_SIMPLE_ERR(fmt, ...) -#define NET_BUF_SIMPLE_WARN(fmt, ...) -#define NET_BUF_SIMPLE_INFO(fmt, ...) +#if defined(CONFIG_BLE_MESH_NET_BUF_SIMPLE_LOG) && (!CONFIG_BLE_MESH_NO_LOG) +#define NET_BUF_SIMPLE_ERR(fmt, args...) do {if ((NET_BUF_LOG_LEVEL >= LOG_LEVEL_ERROR) && BLE_MESH_LOG_LEVEL_CHECK(NET_BUF, ERROR)) BLE_MESH_PRINT_E(MESH_TRACE_TAG, fmt, ## args);} while(0) +#define NET_BUF_SIMPLE_WARN(fmt, args...) do {if ((NET_BUF_LOG_LEVEL >= LOG_LEVEL_WARN) && BLE_MESH_LOG_LEVEL_CHECK(NET_BUF, WARN)) BLE_MESH_PRINT_W(MESH_TRACE_TAG, fmt, ## args);} while(0) +#define NET_BUF_SIMPLE_INFO(fmt, args...) do {if ((NET_BUF_LOG_LEVEL >= LOG_LEVEL_INFO) && BLE_MESH_LOG_LEVEL_CHECK(NET_BUF, INFO)) BLE_MESH_PRINT_I(MESH_TRACE_TAG, fmt, ## args);} while(0) +#define NET_BUF_SIMPLE_DBG(fmt, args...) do {if ((NET_BUF_LOG_LEVEL >= LOG_LEVEL_DEBUG) && BLE_MESH_LOG_LEVEL_CHECK(NET_BUF, DEBUG)) BLE_MESH_PRINT_D(MESH_TRACE_TAG, fmt, ## args);} while(0) +#define NET_BUF_SIMPLE_ASSERT(cond) __ASSERT_NO_MSG(cond) +#else +#define NET_BUF_SIMPLE_ERR(fmt, args...) +#define NET_BUF_SIMPLE_WARN(fmt, args...) +#define NET_BUF_SIMPLE_INFO(fmt, args...) +#define NET_BUF_SIMPLE_DBG(fmt, args...) #define NET_BUF_SIMPLE_ASSERT(cond) +#endif -#endif /* CONFIG_NET_BUF_SIMPLE_LOG */ - - -#define printk ets_printf - +#endif /* _BLE_MESH_TRACE_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/include/mesh_types.h b/components/bt/ble_mesh/mesh_core/include/mesh_types.h index a3ddf774d2..66df1ec75e 100644 --- a/components/bt/ble_mesh/mesh_core/include/mesh_types.h +++ b/components/bt/ble_mesh/mesh_core/include/mesh_types.h @@ -5,10 +5,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef __Z_TYPES_H__ -#define __Z_TYPES_H__ +#ifndef _BLE_MESH_TYPES_H_ +#define _BLE_MESH_TYPES_H_ #include +#include #ifdef __cplusplus extern "C" { @@ -24,17 +25,22 @@ typedef unsigned short u16_t; typedef unsigned int u32_t; typedef unsigned long long u64_t; -typedef int atomic_t; +typedef int bt_mesh_atomic_t; #ifndef bool #define bool int8_t -#define false 0 ///< XOS definition of 'false' -#define true 1 ///< XOS definition of 'true' +#endif + +#ifndef false +#define false 0 +#endif + +#ifndef true +#define true 1 #endif #ifdef __cplusplus } #endif -#endif /* __Z_TYPES_H__ */ - +#endif /* _BLE_MESH_TYPES_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/include/mesh_util.h b/components/bt/ble_mesh/mesh_core/include/mesh_util.h index a15f23d2b0..8258e2c691 100644 --- a/components/bt/ble_mesh/mesh_core/include/mesh_util.h +++ b/components/bt/ble_mesh/mesh_core/include/mesh_util.h @@ -11,20 +11,18 @@ * Misc utilities usable by the kernel and application code. */ -#ifndef _UTIL__H_ -#define _UTIL__H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef _ASMLANGUAGE +#ifndef _BLE_MESH_UTIL_H_ +#define _BLE_MESH_UTIL_H_ #include #include "mesh_types.h" #include "mesh_trace.h" #include "soc/soc.h" +#ifdef __cplusplus +extern "C" { +#endif + /* Helper to pass a int as a pointer or vice-versa. * Those are available for 32 bits architectures: */ @@ -39,15 +37,15 @@ extern "C" { /* Evaluates to 0 if array is an array; compile error if not array (e.g. * pointer) */ -#define IS_ARRAY(array) \ - ZERO_OR_COMPILE_ERROR( \ - !__builtin_types_compatible_p(__typeof__(array), \ +#define IS_ARRAY(array) \ + ZERO_OR_COMPILE_ERROR( \ + !__builtin_types_compatible_p(__typeof__(array), \ __typeof__(&(array)[0]))) /* Evaluates to number of elements in an array; compile error if not * an array (e.g. pointer) */ -#define ARRAY_SIZE(array) \ +#define ARRAY_SIZE(array) \ ((unsigned long) (IS_ARRAY(array) + \ (sizeof(array) / sizeof((array)[0])))) @@ -61,8 +59,8 @@ extern "C" { ((type *)(((char *)(ptr)) - offsetof(type, field))) /* round "x" up/down to next multiple of "align" (which must be a power of 2) */ -#define ROUND_UP(x, align) \ - (((unsigned long)(x) + ((unsigned long)align - 1)) & \ +#define ROUND_UP(x, align) \ + (((unsigned long)(x) + ((unsigned long)align - 1)) & \ ~((unsigned long)align - 1)) #define ROUND_DOWN(x, align) ((unsigned long)(x) & ~((unsigned long)align - 1)) @@ -70,19 +68,27 @@ extern "C" { (((numerator) + ((divider) - 1)) / (divider)) /* Internal helpers only used by the sys_* APIs further below */ +#ifndef __bswap_16 #define __bswap_16(x) ((u16_t) ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))) -#define __bswap_32(x) ((u32_t) ((((x) >> 24) & 0xff) | \ - (((x) >> 8) & 0xff00) | \ - (((x) & 0xff00) << 8) | \ +#endif + +#ifndef __bswap_32 +#define __bswap_32(x) ((u32_t) ((((x) >> 24) & 0xff) | \ + (((x) >> 8) & 0xff00) | \ + (((x) & 0xff00) << 8) | \ (((x) & 0xff) << 24))) -#define __bswap_64(x) ((u64_t) ((((x) >> 56) & 0xff) | \ - (((x) >> 40) & 0xff00) | \ - (((x) >> 24) & 0xff0000) | \ - (((x) >> 8) & 0xff000000) | \ - (((x) & 0xff000000) << 8) | \ - (((x) & 0xff0000) << 24) | \ - (((x) & 0xff00) << 40) | \ +#endif + +#ifndef __bswap_64 +#define __bswap_64(x) ((u64_t) ((((x) >> 56) & 0xff) | \ + (((x) >> 40) & 0xff00) | \ + (((x) >> 24) & 0xff0000) | \ + (((x) >> 8) & 0xff000000) | \ + (((x) & 0xff000000) << 8) | \ + (((x) & 0xff0000) << 24) | \ + (((x) & 0xff00) << 40) | \ (((x) & 0xff) << 56))) +#endif #define sys_le16_to_cpu(val) (val) #define sys_cpu_to_le16(val) (val) @@ -97,63 +103,21 @@ extern "C" { #define sys_be64_to_cpu(val) __bswap_64(val) #define sys_cpu_to_be64(val) __bswap_64(val) - - -#ifdef INLINED -#define INLINE inline -#else -#define INLINE +#ifndef MAX +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) #endif -#define NOINIT - -#ifndef max -#define max(a, b) (((a) > (b)) ? (a) : (b)) +#ifndef MIN +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif -#ifndef min -#define min(a, b) (((a) < (b)) ? (a) : (b)) -#endif - -static inline int is_power_of_two(unsigned int x) -{ - return (x != 0) && !(x & (x - 1)); -} - -static inline s64_t arithmetic_shift_right(s64_t value, u8_t shift) -{ - s64_t sign_ext; - - if (shift == 0) { - return value; - } - - /* extract sign bit */ - sign_ext = (value >> 63) & 1; - - /* make all bits of sign_ext be the same as the value's sign bit */ - sign_ext = -sign_ext; - - /* shift value and fill opened bit positions with sign bit */ - return (value >> shift) | (sign_ext << (64 - shift)); -} - -#endif /* !_ASMLANGUAGE */ - -/* KB, MB, GB */ -#define KB(x) ((x) << 10) -#define MB(x) (KB(x) << 10) -#define GB(x) (MB(x) << 10) - -/* KHZ, MHZ */ -#define KHZ(x) ((x) * 1000) -#define MHZ(x) (KHZ(x) * 1000) - #ifndef BIT -#define BIT(n) (1UL << (n)) +#define BIT(n) (1UL << (n)) #endif +#ifndef BIT_MASK #define BIT_MASK(n) (BIT(n) - 1) +#endif /** * @brief Check for macro definition in compiler-visible expressions @@ -207,126 +171,14 @@ static inline s64_t arithmetic_shift_right(s64_t value, u8_t shift) */ #define _IS_ENABLED3(ignore_this, val, ...) val -/** - * Macros for doing code-generation with the preprocessor. - * - * Generally it is better to generate code with the preprocessor than - * to copy-paste code or to generate code with the build system / - * python script's etc. - * - * http://stackoverflow.com/a/12540675 - */ -#define UTIL_EMPTY(...) -#define UTIL_DEFER(...) __VA_ARGS__ UTIL_EMPTY() -#define UTIL_OBSTRUCT(...) __VA_ARGS__ UTIL_DEFER(UTIL_EMPTY)() -#define UTIL_EXPAND(...) __VA_ARGS__ - -#define UTIL_EVAL(...) UTIL_EVAL1(UTIL_EVAL1(UTIL_EVAL1(__VA_ARGS__))) -#define UTIL_EVAL1(...) UTIL_EVAL2(UTIL_EVAL2(UTIL_EVAL2(__VA_ARGS__))) -#define UTIL_EVAL2(...) UTIL_EVAL3(UTIL_EVAL3(UTIL_EVAL3(__VA_ARGS__))) -#define UTIL_EVAL3(...) UTIL_EVAL4(UTIL_EVAL4(UTIL_EVAL4(__VA_ARGS__))) -#define UTIL_EVAL4(...) UTIL_EVAL5(UTIL_EVAL5(UTIL_EVAL5(__VA_ARGS__))) -#define UTIL_EVAL5(...) __VA_ARGS__ - -#define UTIL_CAT(a, ...) UTIL_PRIMITIVE_CAT(a, __VA_ARGS__) -#define UTIL_PRIMITIVE_CAT(a, ...) a##__VA_ARGS__ - -#define UTIL_INC(x) UTIL_PRIMITIVE_CAT(UTIL_INC_, x) -#define UTIL_INC_0 1 -#define UTIL_INC_1 2 -#define UTIL_INC_2 3 -#define UTIL_INC_3 4 -#define UTIL_INC_4 5 -#define UTIL_INC_5 6 -#define UTIL_INC_6 7 -#define UTIL_INC_7 8 -#define UTIL_INC_8 9 -#define UTIL_INC_9 10 -#define UTIL_INC_10 11 -#define UTIL_INC_11 12 -#define UTIL_INC_12 13 -#define UTIL_INC_13 14 -#define UTIL_INC_14 15 -#define UTIL_INC_15 16 -#define UTIL_INC_16 17 -#define UTIL_INC_17 18 -#define UTIL_INC_18 19 -#define UTIL_INC_19 19 - -#define UTIL_DEC(x) UTIL_PRIMITIVE_CAT(UTIL_DEC_, x) -#define UTIL_DEC_0 0 -#define UTIL_DEC_1 0 -#define UTIL_DEC_2 1 -#define UTIL_DEC_3 2 -#define UTIL_DEC_4 3 -#define UTIL_DEC_5 4 -#define UTIL_DEC_6 5 -#define UTIL_DEC_7 6 -#define UTIL_DEC_8 7 -#define UTIL_DEC_9 8 -#define UTIL_DEC_10 9 -#define UTIL_DEC_11 10 -#define UTIL_DEC_12 11 -#define UTIL_DEC_13 12 -#define UTIL_DEC_14 13 -#define UTIL_DEC_15 14 -#define UTIL_DEC_16 15 -#define UTIL_DEC_17 16 -#define UTIL_DEC_18 17 -#define UTIL_DEC_19 18 - -#define UTIL_CHECK_N(x, n, ...) n -#define UTIL_CHECK(...) UTIL_CHECK_N(__VA_ARGS__, 0,) - -#define UTIL_NOT(x) UTIL_CHECK(UTIL_PRIMITIVE_CAT(UTIL_NOT_, x)) -#define UTIL_NOT_0 ~, 1, - -#define UTIL_COMPL(b) UTIL_PRIMITIVE_CAT(UTIL_COMPL_, b) -#define UTIL_COMPL_0 1 -#define UTIL_COMPL_1 0 - -#define UTIL_BOOL(x) UTIL_COMPL(UTIL_NOT(x)) - -#define UTIL_IIF(c) UTIL_PRIMITIVE_CAT(UTIL_IIF_, c) -#define UTIL_IIF_0(t, ...) __VA_ARGS__ -#define UTIL_IIF_1(t, ...) t - -#define UTIL_IF(c) UTIL_IIF(UTIL_BOOL(c)) - -#define UTIL_EAT(...) -#define UTIL_EXPAND(...) __VA_ARGS__ -#define UTIL_WHEN(c) UTIL_IF(c)(UTIL_EXPAND, UTIL_EAT) - -#define UTIL_REPEAT(count, macro, ...) \ - UTIL_WHEN(count) \ - ( \ - UTIL_OBSTRUCT(UTIL_REPEAT_INDIRECT) () \ - ( \ - UTIL_DEC(count), macro, __VA_ARGS__ \ - ) \ - UTIL_OBSTRUCT(macro) \ - ( \ - UTIL_DEC(count), __VA_ARGS__ \ - ) \ - ) -#define UTIL_REPEAT_INDIRECT() UTIL_REPEAT - -#define _STRINGIFY(x) #x -#define STRINGIFY(s) _STRINGIFY(s) - /* ESP Toolchain doesn't support section */ #define ___in_section(a, b, c) #define __in_section(a, b, c) ___in_section(a, b, c) #define __in_section_unique(seg) ___in_section(seg, __FILE__, __COUNTER__) - -/* ESP Toolchain doesn't support section */ -#define __noinit - #define popcount(x) __builtin_popcount(x) - /** * * @brief find most significant bit set in a 32-bit word @@ -368,45 +220,6 @@ static inline unsigned int find_lsb_set(u32_t op) } #endif -#define __ASSERT(test, fmt, ...) \ - do { \ - if (!(test)) { \ - printk("ASSERTION FAIL [%s] @ %s:%d:\n\t", \ - _STRINGIFY(test), \ - __FILE__, \ - __LINE__); \ - printk(fmt, ##__VA_ARGS__); \ - for (;;) \ - ; /* spin thread */ \ - } \ - } while ((0)) - -/** - * Generates a sequence of code. - * Useful for generating code like; - * - * NRF_PWM0, NRF_PWM1, NRF_PWM2, - * - * @arg LEN: The length of the sequence. Must be defined and less than - * 20. - * - * @arg F(i, F_ARG): A macro function that accepts two arguments. - * F is called repeatedly, the first argument - * is the index in the sequence, and the second argument is the third - * argument given to UTIL_LISTIFY. - * - * Example: - * - * \#define FOO(i, _) NRF_PWM ## i , - * { UTIL_LISTIFY(PWM_COUNT, FOO) } - * // The above two lines will generate the below: - * { NRF_PWM0 , NRF_PWM1 , } - * - * @note Calling UTIL_LISTIFY with undefined arguments has undefined - * behaviour. - */ -#define UTIL_LISTIFY(LEN, F, F_ARG) UTIL_EVAL(UTIL_REPEAT(LEN, F, F_ARG)) - /** * @brief Put a 16-bit integer as big-endian to arbitrary location. * @@ -557,7 +370,6 @@ static inline u64_t sys_get_le64(const u8_t src[8]) return ((u64_t)sys_get_le32(&src[4]) << 32) | sys_get_le32(&src[0]); } - const char *bt_hex(const void *buf, size_t len); void mem_rcopy(u8_t *dst, u8_t const *src, u16_t len); @@ -621,9 +433,8 @@ static inline void sys_mem_swap(void *buf, size_t length) } } - #ifdef __cplusplus } #endif -#endif /* _UTIL__H_ */ +#endif /* _BLE_MESH_UTIL_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/include/mesh_uuid.h b/components/bt/ble_mesh/mesh_core/include/mesh_uuid.h new file mode 100644 index 0000000000..de03df5c32 --- /dev/null +++ b/components/bt/ble_mesh/mesh_core/include/mesh_uuid.h @@ -0,0 +1,530 @@ +/** @file + * @brief Bluetooth UUID handling + */ + +/* + * Copyright (c) 2015-2016 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef _BLE_MESH_UUID_H_ +#define _BLE_MESH_UUID_H_ + +/** + * @brief UUIDs + * @defgroup bt_uuid UUIDs + * @ingroup bluetooth + * @{ + */ + +#include "mesh_util.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @brief Bluetooth UUID types */ +enum { + BLE_MESH_UUID_TYPE_16, + BLE_MESH_UUID_TYPE_32, + BLE_MESH_UUID_TYPE_128, +}; + +/** @brief This is a 'tentative' type and should be used as a pointer only */ +struct bt_mesh_uuid { + u8_t type; +}; + +struct bt_mesh_uuid_16 { + struct bt_mesh_uuid uuid; + u16_t val; +}; + +struct bt_mesh_uuid_32 { + struct bt_mesh_uuid uuid; + u32_t val; +}; + +struct bt_mesh_uuid_128 { + struct bt_mesh_uuid uuid; + u8_t val[16]; +}; + +#define BLE_MESH_UUID_INIT_16(value) \ +{ \ + .uuid.type = BLE_MESH_UUID_TYPE_16, \ + .val = (value), \ +} + +#define BLE_MESH_UUID_INIT_32(value) \ +{ \ + .uuid.type = BLE_MESH_UUID_TYPE_32, \ + .val = (value), \ +} + +#define BLE_MESH_UUID_INIT_128(value...) \ +{ \ + .uuid.type = BLE_MESH_UUID_TYPE_128, \ + .val = { value }, \ +} + +#define BLE_MESH_UUID_DECLARE_16(value) \ + ((struct bt_mesh_uuid *) (&(struct bt_mesh_uuid_16) BLE_MESH_UUID_INIT_16(value))) + +#define BLE_MESH_UUID_DECLARE_32(value) \ + ((struct bt_mesh_uuid *) (&(struct bt_mesh_uuid_32) BLE_MESH_UUID_INIT_32(value))) + +#define BLE_MESH_UUID_DECLARE_128(value...) \ + ((struct bt_mesh_uuid *) (&(struct bt_mesh_uuid_128) BLE_MESH_UUID_INIT_128(value))) + +#define BLE_MESH_UUID_16(__u) CONTAINER_OF(__u, struct bt_mesh_uuid_16, uuid) +#define BLE_MESH_UUID_32(__u) CONTAINER_OF(__u, struct bt_mesh_uuid_32, uuid) +#define BLE_MESH_UUID_128(__u) CONTAINER_OF(__u, struct bt_mesh_uuid_128, uuid) + +/** @def BLE_MESH_UUID_GAP + * @brief Generic Access + */ +#define BLE_MESH_UUID_GAP BLE_MESH_UUID_DECLARE_16(0x1800) +#define BLE_MESH_UUID_GAP_VAL 0x1800 +/** @def BLE_MESH_UUID_GATT + * @brief Generic Attribute + */ +#define BLE_MESH_UUID_GATT BLE_MESH_UUID_DECLARE_16(0x1801) +#define BLE_MESH_UUID_GATT_VAL 0x1801 +/** @def BLE_MESH_UUID_CTS + * @brief Current Time Service + */ +#define BLE_MESH_UUID_CTS BLE_MESH_UUID_DECLARE_16(0x1805) +#define BLE_MESH_UUID_CTS_VAL 0x1805 +/** @def BLE_MESH_UUID_DIS + * @brief Device Information Service + */ +#define BLE_MESH_UUID_DIS BLE_MESH_UUID_DECLARE_16(0x180a) +#define BLE_MESH_UUID_DIS_VAL 0x180a +/** @def BLE_MESH_UUID_HRS + * @brief Heart Rate Service + */ +#define BLE_MESH_UUID_HRS BLE_MESH_UUID_DECLARE_16(0x180d) +#define BLE_MESH_UUID_HRS_VAL 0x180d +/** @def BLE_MESH_UUID_BAS + * @brief Battery Service + */ +#define BLE_MESH_UUID_BAS BLE_MESH_UUID_DECLARE_16(0x180f) +#define BLE_MESH_UUID_BAS_VAL 0x180f +/** @def BLE_MESH_UUID_HIDS + * @brief HID Service + */ +#define BLE_MESH_UUID_HIDS BLE_MESH_UUID_DECLARE_16(0x1812) +#define BLE_MESH_UUID_HIDS_VAL 0x1812 +/** @def BLE_MESH_UUID_CSC + * @brief Cycling Speed and Cadence Service + */ +#define BLE_MESH_UUID_CSC BLE_MESH_UUID_DECLARE_16(0x1816) +#define BLE_MESH_UUID_CSC_VAL 0x1816 +/** @def BLE_MESH_UUID_ESS + * @brief Environmental Sensing Service + */ +#define BLE_MESH_UUID_ESS BLE_MESH_UUID_DECLARE_16(0x181a) +#define BLE_MESH_UUID_ESS_VAL 0x181a +/** @def BLE_MESH_UUID_IPSS + * @brief IP Support Service + */ +#define BLE_MESH_UUID_IPSS BLE_MESH_UUID_DECLARE_16(0x1820) +#define BLE_MESH_UUID_IPSS_VAL 0x1820 +/** @def BLE_MESH_UUID_MESH_PROV + * @brief Mesh Provisioning Service + */ +#define BLE_MESH_UUID_MESH_PROV BLE_MESH_UUID_DECLARE_16(0x1827) +#define BLE_MESH_UUID_MESH_PROV_VAL 0x1827 +/** @def BLE_MESH_UUID_MESH_PROXY + * @brief Mesh Proxy Service + */ +#define BLE_MESH_UUID_MESH_PROXY BLE_MESH_UUID_DECLARE_16(0x1828) +#define BLE_MESH_UUID_MESH_PROXY_VAL 0x1828 +/** @def BLE_MESH_UUID_GATT_PRIMARY + * @brief GATT Primary Service + */ +#define BLE_MESH_UUID_GATT_PRIMARY BLE_MESH_UUID_DECLARE_16(0x2800) +#define BLE_MESH_UUID_GATT_PRIMARY_VAL 0x2800 +/** @def BLE_MESH_UUID_GATT_SECONDARY + * @brief GATT Secondary Service + */ +#define BLE_MESH_UUID_GATT_SECONDARY BLE_MESH_UUID_DECLARE_16(0x2801) +#define BLE_MESH_UUID_GATT_SECONDARY_VAL 0x2801 +/** @def BLE_MESH_UUID_GATT_INCLUDE + * @brief GATT Include Service + */ +#define BLE_MESH_UUID_GATT_INCLUDE BLE_MESH_UUID_DECLARE_16(0x2802) +#define BLE_MESH_UUID_GATT_INCLUDE_VAL 0x2802 +/** @def BLE_MESH_UUID_GATT_CHRC + * @brief GATT Characteristic + */ +#define BLE_MESH_UUID_GATT_CHRC BLE_MESH_UUID_DECLARE_16(0x2803) +#define BLE_MESH_UUID_GATT_CHRC_VAL 0x2803 +/** @def BLE_MESH_UUID_GATT_CEP + * @brief GATT Characteristic Extended Properties + */ +#define BLE_MESH_UUID_GATT_CEP BLE_MESH_UUID_DECLARE_16(0x2900) +#define BLE_MESH_UUID_GATT_CEP_VAL 0x2900 +/** @def BLE_MESH_UUID_GATT_CUD + * @brief GATT Characteristic User Description + */ +#define BLE_MESH_UUID_GATT_CUD BLE_MESH_UUID_DECLARE_16(0x2901) +#define BLE_MESH_UUID_GATT_CUD_VAL 0x2901 +/** @def BLE_MESH_UUID_GATT_CCC + * @brief GATT Client Characteristic Configuration + */ +#define BLE_MESH_UUID_GATT_CCC BLE_MESH_UUID_DECLARE_16(0x2902) +#define BLE_MESH_UUID_GATT_CCC_VAL 0x2902 +/** @def BLE_MESH_UUID_GATT_SCC + * @brief GATT Server Characteristic Configuration + */ +#define BLE_MESH_UUID_GATT_SCC BLE_MESH_UUID_DECLARE_16(0x2903) +#define BLE_MESH_UUID_GATT_SCC_VAL 0x2903 +/** @def BLE_MESH_UUID_GATT_CPF + * @brief GATT Characteristic Presentation Format + */ +#define BLE_MESH_UUID_GATT_CPF BLE_MESH_UUID_DECLARE_16(0x2904) +#define BLE_MESH_UUID_GATT_CPF_VAL 0x2904 +/** @def BLE_MESH_UUID_VALID_RANGE + * @brief Valid Range Descriptor + */ +#define BLE_MESH_UUID_VALID_RANGE BLE_MESH_UUID_DECLARE_16(0x2906) +#define BLE_MESH_UUID_VALID_RANGE_VAL 0x2906 +/** @def BLE_MESH_UUID_HIDS_EXT_REPORT + * @brief HID External Report Descriptor + */ +#define BLE_MESH_UUID_HIDS_EXT_REPORT BLE_MESH_UUID_DECLARE_16(0x2907) +#define BLE_MESH_UUID_HIDS_EXT_REPORT_VAL 0x2907 +/** @def BLE_MESH_UUID_HIDS_REPORT_REF + * @brief HID Report Reference Descriptor + */ +#define BLE_MESH_UUID_HIDS_REPORT_REF BLE_MESH_UUID_DECLARE_16(0x2908) +#define BLE_MESH_UUID_HIDS_REPORT_REF_VAL 0x2908 +/** @def BLE_MESH_UUID_ES_CONFIGURATION + * @brief Environmental Sensing Configuration Descriptor + */ +#define BLE_MESH_UUID_ES_CONFIGURATION BLE_MESH_UUID_DECLARE_16(0x290b) +#define BLE_MESH_UUID_ES_CONFIGURATION_VAL 0x290b +/** @def BLE_MESH_UUID_ES_MEASUREMENT + * @brief Environmental Sensing Measurement Descriptor + */ +#define BLE_MESH_UUID_ES_MEASUREMENT BLE_MESH_UUID_DECLARE_16(0x290c) +#define BLE_MESH_UUID_ES_MEASUREMENT_VAL 0x290c +/** @def BLE_MESH_UUID_ES_TRIGGER_SETTING + * @brief Environmental Sensing Trigger Setting Descriptor + */ +#define BLE_MESH_UUID_ES_TRIGGER_SETTING BLE_MESH_UUID_DECLARE_16(0x290d) +#define BLE_MESH_UUID_ES_TRIGGER_SETTING_VAL 0x290d +/** @def BLE_MESH_UUID_GAP_DEVICE_NAME + * @brief GAP Characteristic Device Name + */ +#define BLE_MESH_UUID_GAP_DEVICE_NAME BLE_MESH_UUID_DECLARE_16(0x2a00) +#define BLE_MESH_UUID_GAP_DEVICE_NAME_VAL 0x2a00 +/** @def BLE_MESH_UUID_GAP_APPEARANCE + * @brief GAP Characteristic Appearance + */ +#define BLE_MESH_UUID_GAP_APPEARANCE BLE_MESH_UUID_DECLARE_16(0x2a01) +#define BLE_MESH_UUID_GAP_APPEARANCE_VAL 0x2a01 +/** @def BLE_MESH_UUID_GAP_PPCP + * @brief GAP Characteristic Peripheral Preferred Connection Parameters + */ +#define BLE_MESH_UUID_GAP_PPCP BLE_MESH_UUID_DECLARE_16(0x2a04) +#define BLE_MESH_UUID_GAP_PPCP_VAL 0x2a04 +/** @def BLE_MESH_UUID_GATT_SC + * @brief GATT Characteristic Service Changed + */ +#define BLE_MESH_UUID_GATT_SC BLE_MESH_UUID_DECLARE_16(0x2a05) +#define BLE_MESH_UUID_GATT_SC_VAL 0x2a05 +/** @def BLE_MESH_UUID_BAS_BATTERY_LEVEL + * @brief BAS Characteristic Battery Level + */ +#define BLE_MESH_UUID_BAS_BATTERY_LEVEL BLE_MESH_UUID_DECLARE_16(0x2a19) +#define BLE_MESH_UUID_BAS_BATTERY_LEVEL_VAL 0x2a19 +/** @def BLE_MESH_UUID_DIS_SYSTEM_ID + * @brief DIS Characteristic System ID + */ +#define BLE_MESH_UUID_DIS_SYSTEM_ID BLE_MESH_UUID_DECLARE_16(0x2a23) +#define BLE_MESH_UUID_DIS_SYSTEM_ID_VAL 0x2a23 +/** @def BLE_MESH_UUID_DIS_MODEL_NUMBER + * @brief DIS Characteristic Model Number String + */ +#define BLE_MESH_UUID_DIS_MODEL_NUMBER BLE_MESH_UUID_DECLARE_16(0x2a24) +#define BLE_MESH_UUID_DIS_MODEL_NUMBER_VAL 0x2a24 +/** @def BLE_MESH_UUID_DIS_SERIAL_NUMBER + * @brief DIS Characteristic Serial Number String + */ +#define BLE_MESH_UUID_DIS_SERIAL_NUMBER BLE_MESH_UUID_DECLARE_16(0x2a25) +#define BLE_MESH_UUID_DIS_SERIAL_NUMBER_VAL 0x2a25 +/** @def BLE_MESH_UUID_DIS_FIRMWARE_REVISION + * @brief DIS Characteristic Firmware Revision String + */ +#define BLE_MESH_UUID_DIS_FIRMWARE_REVISION BLE_MESH_UUID_DECLARE_16(0x2a26) +#define BLE_MESH_UUID_DIS_FIRMWARE_REVISION_VAL 0x2a26 +/** @def BLE_MESH_UUID_DIS_HARDWARE_REVISION + * @brief DIS Characteristic Hardware Revision String + */ +#define BLE_MESH_UUID_DIS_HARDWARE_REVISION BLE_MESH_UUID_DECLARE_16(0x2a27) +#define BLE_MESH_UUID_DIS_HARDWARE_REVISION_VAL 0x2a27 +/** @def BLE_MESH_UUID_DIS_SOFTWARE_REVISION + * @brief DIS Characteristic Software Revision String + */ +#define BLE_MESH_UUID_DIS_SOFTWARE_REVISION BLE_MESH_UUID_DECLARE_16(0x2a28) +#define BLE_MESH_UUID_DIS_SOFTWARE_REVISION_VAL 0x2a28 +/** @def BLE_MESH_UUID_DIS_MANUFACTURER_NAME + * @brief DIS Characteristic Manufacturer Name String + */ +#define BLE_MESH_UUID_DIS_MANUFACTURER_NAME BLE_MESH_UUID_DECLARE_16(0x2a29) +#define BLE_MESH_UUID_DIS_MANUFACTURER_NAME_VAL 0x2a29 +/** @def BLE_MESH_UUID_DIS_PNP_ID + * @brief DIS Characteristic PnP ID + */ +#define BLE_MESH_UUID_DIS_PNP_ID BLE_MESH_UUID_DECLARE_16(0x2a50) +#define BLE_MESH_UUID_DIS_PNP_ID_VAL 0x2a50 +/** @def BLE_MESH_UUID_CTS_CURRENT_TIME + * @brief CTS Characteristic Current Time + */ +#define BLE_MESH_UUID_CTS_CURRENT_TIME BLE_MESH_UUID_DECLARE_16(0x2a2b) +#define BLE_MESH_UUID_CTS_CURRENT_TIME_VAL 0x2a2b +/** @def BLE_MESH_UUID_MAGN_DECLINATION + * @brief Magnetic Declination Characteristic + */ +#define BLE_MESH_UUID_MAGN_DECLINATION BLE_MESH_UUID_DECLARE_16(0x2a2c) +#define BLE_MESH_UUID_MAGN_DECLINATION_VAL 0x2a2c +/** @def BLE_MESH_UUID_HRS_MEASUREMENT + * @brief HRS Characteristic Measurement Interval + */ +#define BLE_MESH_UUID_HRS_MEASUREMENT BLE_MESH_UUID_DECLARE_16(0x2a37) +#define BLE_MESH_UUID_HRS_MEASUREMENT_VAL 0x2a37 +/** @def BLE_MESH_UUID_HRS_BODY_SENSOR + * @brief HRS Characteristic Body Sensor Location + */ +#define BLE_MESH_UUID_HRS_BODY_SENSOR BLE_MESH_UUID_DECLARE_16(0x2a38) +#define BLE_MESH_UUID_HRS_BODY_SENSOR_VAL 0x2a38 +/** @def BLE_MESH_UUID_HRS_CONTROL_POINT + * @brief HRS Characteristic Control Point + */ +#define BLE_MESH_UUID_HRS_CONTROL_POINT BLE_MESH_UUID_DECLARE_16(0x2a39) +#define BLE_MESH_UUID_HRS_CONTROL_POINT_VAL 0x2a39 +/** @def BLE_MESH_UUID_HIDS_INFO + * @brief HID Information Characteristic + */ +#define BLE_MESH_UUID_HIDS_INFO BLE_MESH_UUID_DECLARE_16(0x2a4a) +#define BLE_MESH_UUID_HIDS_INFO_VAL 0x2a4a +/** @def BLE_MESH_UUID_HIDS_REPORT_MAP + * @brief HID Report Map Characteristic + */ +#define BLE_MESH_UUID_HIDS_REPORT_MAP BLE_MESH_UUID_DECLARE_16(0x2a4b) +#define BLE_MESH_UUID_HIDS_REPORT_MAP_VAL 0x2a4b +/** @def BLE_MESH_UUID_HIDS_CTRL_POINT + * @brief HID Control Point Characteristic + */ +#define BLE_MESH_UUID_HIDS_CTRL_POINT BLE_MESH_UUID_DECLARE_16(0x2a4c) +#define BLE_MESH_UUID_HIDS_CTRL_POINT_VAL 0x2a4c +/** @def BLE_MESH_UUID_HIDS_REPORT + * @brief HID Report Characteristic + */ +#define BLE_MESH_UUID_HIDS_REPORT BLE_MESH_UUID_DECLARE_16(0x2a4d) +#define BLE_MESH_UUID_HIDS_REPORT_VAL 0x2a4d +/** @def BLE_MESH_UUID_CSC_MEASUREMENT + * @brief CSC Measurement Characteristic + */ +#define BLE_MESH_UUID_CSC_MEASUREMENT BLE_MESH_UUID_DECLARE_16(0x2a5b) +#define BLE_MESH_UUID_CSC_MEASUREMENT_VAL 0x2a5b +/** @def BLE_MESH_UUID_CSC_FEATURE + * @brief CSC Feature Characteristic + */ +#define BLE_MESH_UUID_CSC_FEATURE BLE_MESH_UUID_DECLARE_16(0x2a5c) +#define BLE_MESH_UUID_CSC_FEATURE_VAL 0x2a5c +/** @def BLE_MESH_UUID_SENSOR_LOCATION + * @brief Sensor Location Characteristic + */ +#define BLE_MESH_UUID_SENSOR_LOCATION BLE_MESH_UUID_DECLARE_16(0x2a5d) +#define BLE_MESH_UUID_SENSOR_LOCATION_VAL 0x2a5d +/** @def BLE_MESH_UUID_SC_CONTROL_POINT + * @brief SC Control Point Characteristic + */ +#define BLE_MESH_UUID_SC_CONTROL_POINT BLE_MESH_UUID_DECLARE_16(0x2a55) +#define BLE_MESH_UUID_SC_CONTROL_POINT_VAl 0x2a55 +/** @def BLE_MESH_UUID_ELEVATION + * @brief Elevation Characteristic + */ +#define BLE_MESH_UUID_ELEVATION BLE_MESH_UUID_DECLARE_16(0x2a6c) +#define BLE_MESH_UUID_ELEVATION_VAL 0x2a6c +/** @def BLE_MESH_UUID_PRESSURE + * @brief Pressure Characteristic + */ +#define BLE_MESH_UUID_PRESSURE BLE_MESH_UUID_DECLARE_16(0x2a6d) +#define BLE_MESH_UUID_PRESSURE_VAL 0x2a6d +/** @def BLE_MESH_UUID_TEMPERATURE + * @brief Temperature Characteristic + */ +#define BLE_MESH_UUID_TEMPERATURE BLE_MESH_UUID_DECLARE_16(0x2a6e) +#define BLE_MESH_UUID_TEMPERATURE_VAL 0x2a6e +/** @def BLE_MESH_UUID_HUMIDITY + * @brief Humidity Characteristic + */ +#define BLE_MESH_UUID_HUMIDITY BLE_MESH_UUID_DECLARE_16(0x2a6f) +#define BLE_MESH_UUID_HUMIDITY_VAL 0x2a6f +/** @def BLE_MESH_UUID_TRUE_WIND_SPEED + * @brief True Wind Speed Characteristic + */ +#define BLE_MESH_UUID_TRUE_WIND_SPEED BLE_MESH_UUID_DECLARE_16(0x2a70) +#define BLE_MESH_UUID_TRUE_WIND_SPEED_VAL 0x2a70 +/** @def BLE_MESH_UUID_TRUE_WIND_DIR + * @brief True Wind Direction Characteristic + */ +#define BLE_MESH_UUID_TRUE_WIND_DIR BLE_MESH_UUID_DECLARE_16(0x2a71) +#define BLE_MESH_UUID_TRUE_WIND_DIR_VAL 0x2a71 +/** @def BLE_MESH_UUID_APPARENT_WIND_SPEED + * @brief Apparent Wind Speed Characteristic + */ +#define BLE_MESH_UUID_APPARENT_WIND_SPEED BLE_MESH_UUID_DECLARE_16(0x2a72) +#define BLE_MESH_UUID_APPARENT_WIND_SPEED_VAL 0x2a72 +/** @def BLE_MESH_UUID_APPARENT_WIND_DIR + * @brief Apparent Wind Direction Characteristic + */ +#define BLE_MESH_UUID_APPARENT_WIND_DIR BLE_MESH_UUID_DECLARE_16(0x2a73) +#define BLE_MESH_UUID_APPARENT_WIND_DIR_VAL 0x2a73 +/** @def BLE_MESH_UUID_GUST_FACTOR + * @brief Gust Factor Characteristic + */ +#define BLE_MESH_UUID_GUST_FACTOR BLE_MESH_UUID_DECLARE_16(0x2a74) +#define BLE_MESH_UUID_GUST_FACTOR_VAL 0x2a74 +/** @def BLE_MESH_UUID_POLLEN_CONCENTRATION + * @brief Pollen Concentration Characteristic + */ +#define BLE_MESH_UUID_POLLEN_CONCENTRATION BLE_MESH_UUID_DECLARE_16(0x2a75) +#define BLE_MESH_UUID_POLLEN_CONCENTRATION_VAL 0x2a75 +/** @def BLE_MESH_UUID_UV_INDEX + * @brief UV Index Characteristic + */ +#define BLE_MESH_UUID_UV_INDEX BLE_MESH_UUID_DECLARE_16(0x2a76) +#define BLE_MESH_UUID_UV_INDEX_VAL 0x2a76 +/** @def BLE_MESH_UUID_IRRADIANCE + * @brief Irradiance Characteristic + */ +#define BLE_MESH_UUID_IRRADIANCE BLE_MESH_UUID_DECLARE_16(0x2a77) +#define BLE_MESH_UUID_IRRADIANCE_VAL 0x2a77 +/** @def BLE_MESH_UUID_RAINFALL + * @brief Rainfall Characteristic + */ +#define BLE_MESH_UUID_RAINFALL BLE_MESH_UUID_DECLARE_16(0x2a78) +#define BLE_MESH_UUID_RAINFALL_VAL 0x2a78 +/** @def BLE_MESH_UUID_WIND_CHILL + * @brief Wind Chill Characteristic + */ +#define BLE_MESH_UUID_WIND_CHILL BLE_MESH_UUID_DECLARE_16(0x2a79) +#define BLE_MESH_UUID_WIND_CHILL_VAL 0x2a79 +/** @def BLE_MESH_UUID_HEAT_INDEX + * @brief Heat Index Characteristic + */ +#define BLE_MESH_UUID_HEAT_INDEX BLE_MESH_UUID_DECLARE_16(0x2a7a) +#define BLE_MESH_UUID_HEAT_INDEX_VAL 0x2a7a +/** @def BLE_MESH_UUID_DEW_POINT + * @brief Dew Point Characteristic + */ +#define BLE_MESH_UUID_DEW_POINT BLE_MESH_UUID_DECLARE_16(0x2a7b) +#define BLE_MESH_UUID_DEW_POINT_VAL 0x2a7b +/** @def BLE_MESH_UUID_DESC_VALUE_CHANGED + * @brief Descriptor Value Changed Characteristic + */ +#define BLE_MESH_UUID_DESC_VALUE_CHANGED BLE_MESH_UUID_DECLARE_16(0x2a7d) +#define BLE_MESH_UUID_DESC_VALUE_CHANGED_VAL 0x2a7d +/** @def BLE_MESH_UUID_MAGN_FLUX_DENSITY_2D + * @brief Magnetic Flux Density - 2D Characteristic + */ +#define BLE_MESH_UUID_MAGN_FLUX_DENSITY_2D BLE_MESH_UUID_DECLARE_16(0x2aa0) +#define BLE_MESH_UUID_MAGN_FLUX_DENSITY_2D_VAL 0x2aa0 +/** @def BLE_MESH_UUID_MAGN_FLUX_DENSITY_3D + * @brief Magnetic Flux Density - 3D Characteristic + */ +#define BLE_MESH_UUID_MAGN_FLUX_DENSITY_3D BLE_MESH_UUID_DECLARE_16(0x2aa1) +#define BLE_MESH_UUID_MAGN_FLUX_DENSITY_3D_VAL 0x2aa1 +/** @def BLE_MESH_UUID_BAR_PRESSURE_TREND + * @brief Barometric Pressure Trend Characteristic + */ +#define BLE_MESH_UUID_BAR_PRESSURE_TREND BLE_MESH_UUID_DECLARE_16(0x2aa3) +#define BLE_MESH_UUID_BAR_PRESSURE_TREND_VAL 0x2aa3 +/** @def BLE_MESH_UUID_MESH_PROV_DATA_IN + * @brief Mesh Provisioning Data In + */ +#define BLE_MESH_UUID_MESH_PROV_DATA_IN BLE_MESH_UUID_DECLARE_16(0x2adb) +#define BLE_MESH_UUID_MESH_PROV_DATA_IN_VAL 0x2adb +/** @def BLE_MESH_UUID_MESH_PROV_DATA_OUT + * @brief Mesh Provisioning Data Out + */ +#define BLE_MESH_UUID_MESH_PROV_DATA_OUT BLE_MESH_UUID_DECLARE_16(0x2adc) +#define BLE_MESH_UUID_MESH_PROV_DATA_OUT_VAL 0x2adc +/** @def BLE_MESH_UUID_MESH_PROXY_DATA_IN + * @brief Mesh Proxy Data In + */ +#define BLE_MESH_UUID_MESH_PROXY_DATA_IN BLE_MESH_UUID_DECLARE_16(0x2add) +#define BLE_MESH_UUID_MESH_PROXY_DATA_IN_VAL 0x2add +/** @def BLE_MESH_UUID_MESH_PROXY_DATA_OUT + * @brief Mesh Proxy Data Out + */ +#define BLE_MESH_UUID_MESH_PROXY_DATA_OUT BLE_MESH_UUID_DECLARE_16(0x2ade) +#define BLE_MESH_UUID_MESH_PROXY_DATA_OUT_VAL 0x2ade + +/* + * Protocol UUIDs + */ +#define BLE_MESH_UUID_SDP BLE_MESH_UUID_DECLARE_16(0x0001) +#define BLE_MESH_UUID_SDP_VAL 0x0001 +#define BLE_MESH_UUID_UDP BLE_MESH_UUID_DECLARE_16(0x0002) +#define BLE_MESH_UUID_UDP_VAL 0x0002 +#define BLE_MESH_UUID_RFCOMM BLE_MESH_UUID_DECLARE_16(0x0003) +#define BLE_MESH_UUID_RFCOMM_VAL 0x0003 +#define BLE_MESH_UUID_TCP BLE_MESH_UUID_DECLARE_16(0x0004) +#define BLE_MESH_UUID_TCP_VAL 0x0004 +#define BLE_MESH_UUID_TCS_BIN BLE_MESH_UUID_DECLARE_16(0x0005) +#define BLE_MESH_UUID_TCS_BIN_VAL 0x0005 +#define BLE_MESH_UUID_TCS_AT BLE_MESH_UUID_DECLARE_16(0x0006) +#define BLE_MESH_UUID_TCS_AT_VAL 0x0006 +#define BLE_MESH_UUID_ATT BLE_MESH_UUID_DECLARE_16(0x0007) +#define BLE_MESH_UUID_ATT_VAL 0x0007 +#define BLE_MESH_UUID_OBEX BLE_MESH_UUID_DECLARE_16(0x0008) +#define BLE_MESH_UUID_OBEX_VAL 0x0008 +#define BLE_MESH_UUID_IP BLE_MESH_UUID_DECLARE_16(0x0009) +#define BLE_MESH_UUID_IP_VAL 0x0009 +#define BLE_MESH_UUID_FTP BLE_MESH_UUID_DECLARE_16(0x000a) +#define BLE_MESH_UUID_FTP_VAL 0x000a +#define BLE_MESH_UUID_HTTP BLE_MESH_UUID_DECLARE_16(0x000c) +#define BLE_MESH_UUID_HTTP_VAL 0x000c +#define BLE_MESH_UUID_BNEP BLE_MESH_UUID_DECLARE_16(0x000f) +#define BLE_MESH_UUID_BNEP_VAL 0x000f +#define BLE_MESH_UUID_UPNP BLE_MESH_UUID_DECLARE_16(0x0010) +#define BLE_MESH_UUID_UPNP_VAL 0x0010 +#define BLE_MESH_UUID_HIDP BLE_MESH_UUID_DECLARE_16(0x0011) +#define BLE_MESH_UUID_HIDP_VAL 0x0011 +#define BLE_MESH_UUID_HCRP_CTRL BLE_MESH_UUID_DECLARE_16(0x0012) +#define BLE_MESH_UUID_HCRP_CTRL_VAL 0x0012 +#define BLE_MESH_UUID_HCRP_DATA BLE_MESH_UUID_DECLARE_16(0x0014) +#define BLE_MESH_UUID_HCRP_DATA_VAL 0x0014 +#define BLE_MESH_UUID_HCRP_NOTE BLE_MESH_UUID_DECLARE_16(0x0016) +#define BLE_MESH_UUID_HCRP_NOTE_VAL 0x0016 +#define BLE_MESH_UUID_AVCTP BLE_MESH_UUID_DECLARE_16(0x0017) +#define BLE_MESH_UUID_AVCTP_VAL 0x0017 +#define BLE_MESH_UUID_AVDTP BLE_MESH_UUID_DECLARE_16(0x0019) +#define BLE_MESH_UUID_AVDTP_VAL 0x0019 +#define BLE_MESH_UUID_CMTP BLE_MESH_UUID_DECLARE_16(0x001b) +#define BLE_MESH_UUID_CMTP_VAL 0x001b +#define BLE_MESH_UUID_UDI BLE_MESH_UUID_DECLARE_16(0x001d) +#define BLE_MESH_UUID_UDI_VAL 0x001d +#define BLE_MESH_UUID_MCAP_CTRL BLE_MESH_UUID_DECLARE_16(0x001e) +#define BLE_MESH_UUID_MCAP_CTRL_VAL 0x001e +#define BLE_MESH_UUID_MCAP_DATA BLE_MESH_UUID_DECLARE_16(0x001f) +#define BLE_MESH_UUID_MCAP_DATA_VAL 0x001f +#define BLE_MESH_UUID_L2CAP BLE_MESH_UUID_DECLARE_16(0x0100) +#define BLE_MESH_UUID_L2CAP_VAL 0x0100 + +#ifdef __cplusplus +} +#endif + +/** + * @} + */ + +#endif /* _BLE_MESH_UUID_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/include/settings.h b/components/bt/ble_mesh/mesh_core/include/settings.h deleted file mode 100644 index a4377aa9c5..0000000000 --- a/components/bt/ble_mesh/mesh_core/include/settings.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2018 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef _SETTINGS_H_ -#define _SETTINGS_H_ - -#include "sdkconfig.h" - -#include "net.h" -#include "mesh_access.h" -#include "mesh_bearer_adapt.h" - -struct bt_settings_handler { - const char *name; - int (*set)(int argc, char **argv, char *val); - int (*commit)(void); - int (*export)(int (*func)(const char *name, char *val)); -}; - -#define BT_SETTINGS_DEFINE(_name, _set, _commit, _export) \ - const struct bt_settings_handler _name __aligned(4) \ - __in_section(_bt_settings, static, _name) = { \ - .name = STRINGIFY(_name), \ - .set = _set, \ - .commit = _commit, \ - .export = _export, \ - } - -/* Max settings key length (with all components) */ -#define BT_SETTINGS_KEY_MAX 36 - -/* Base64-encoded string buffer size of in_size bytes */ -#define BT_SETTINGS_SIZE(in_size) ((((((in_size) - 1) / 3) * 4) + 4) + 1) - -/* Helpers for keys containing a bdaddr */ -void bt_settings_encode_key(char *path, size_t path_size, const char *subsys, - bt_addr_le_t *addr, const char *key); -int bt_settings_decode_key(char *key, bt_addr_le_t *addr); - -void bt_mesh_store_net(void); -void bt_mesh_store_iv(void); -void bt_mesh_store_seq(void); -void bt_mesh_store_rpl(struct bt_mesh_rpl *rpl); -void bt_mesh_store_subnet(struct bt_mesh_subnet *sub); -void bt_mesh_store_app_key(struct bt_mesh_app_key *key); -void bt_mesh_store_hb_pub(void); -void bt_mesh_store_cfg(void); -void bt_mesh_store_mod_bind(struct bt_mesh_model *mod); -void bt_mesh_store_mod_sub(struct bt_mesh_model *mod); -void bt_mesh_store_mod_pub(struct bt_mesh_model *mod); - -void bt_mesh_clear_net(void); -void bt_mesh_clear_subnet(struct bt_mesh_subnet *sub); -void bt_mesh_clear_app_key(struct bt_mesh_app_key *key); -void bt_mesh_clear_rpl(void); - -int bt_mesh_settings_init(void); - -#endif /* _SETTINGS_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/lpn.c b/components/bt/ble_mesh/mesh_core/lpn.c index 8c492135f7..36a8e9126c 100644 --- a/components/bt/ble_mesh/mesh_core/lpn.c +++ b/components/bt/ble_mesh/mesh_core/lpn.c @@ -9,17 +9,16 @@ #include #include -#include "mesh_buf.h" #include "sdkconfig.h" -#if CONFIG_BT_MESH +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_LOW_POWER) + +#include "mesh_buf.h" #include "mesh_kernel.h" -#ifdef CONFIG_BT_MESH_LOW_POWER -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_LOW_POWER) #include "mesh_trace.h" +#include "mesh.h" #include "crypto.h" #include "adv.h" -#include "mesh.h" #include "net.h" #include "transport.h" #include "access.h" @@ -27,120 +26,121 @@ #include "foundation.h" #include "lpn.h" -#if defined(CONFIG_BT_MESH_LPN_AUTO) -#define LPN_AUTO_TIMEOUT K_SECONDS(CONFIG_BT_MESH_LPN_AUTO_TIMEOUT) +#ifdef CONFIG_BLE_MESH_LOW_POWER + +#if defined(CONFIG_BLE_MESH_LPN_AUTO) +#define LPN_AUTO_TIMEOUT K_SECONDS(CONFIG_BLE_MESH_LPN_AUTO_TIMEOUT) #else -#define LPN_AUTO_TIMEOUT 0 +#define LPN_AUTO_TIMEOUT 0 #endif -#define LPN_RECV_DELAY CONFIG_BT_MESH_LPN_RECV_DELAY -#define SCAN_LATENCY min(CONFIG_BT_MESH_LPN_SCAN_LATENCY, \ - LPN_RECV_DELAY) +#define LPN_RECV_DELAY CONFIG_BLE_MESH_LPN_RECV_DELAY +#define SCAN_LATENCY MIN(CONFIG_BLE_MESH_LPN_SCAN_LATENCY, LPN_RECV_DELAY) -#define FRIEND_REQ_RETRY_TIMEOUT K_SECONDS(CONFIG_BT_MESH_LPN_RETRY_TIMEOUT) +#define FRIEND_REQ_RETRY_TIMEOUT K_SECONDS(CONFIG_BLE_MESH_LPN_RETRY_TIMEOUT) -#define FRIEND_REQ_WAIT K_MSEC(100) -#define FRIEND_REQ_SCAN K_SECONDS(1) -#define FRIEND_REQ_TIMEOUT (FRIEND_REQ_WAIT + FRIEND_REQ_SCAN) +#define FRIEND_REQ_WAIT K_MSEC(100) +#define FRIEND_REQ_SCAN K_SECONDS(1) +#define FRIEND_REQ_TIMEOUT (FRIEND_REQ_WAIT + FRIEND_REQ_SCAN) -#define POLL_RETRY_TIMEOUT K_MSEC(100) +#define POLL_RETRY_TIMEOUT K_MSEC(100) -#define REQ_RETRY_DURATION(lpn) (4 * (LPN_RECV_DELAY + (lpn)->adv_duration + \ - (lpn)->recv_win + POLL_RETRY_TIMEOUT)) +#define REQ_RETRY_DURATION(lpn) (4 * (LPN_RECV_DELAY + (lpn)->adv_duration + \ + (lpn)->recv_win + POLL_RETRY_TIMEOUT)) -#define POLL_TIMEOUT_INIT (CONFIG_BT_MESH_LPN_INIT_POLL_TIMEOUT * 100) -#define POLL_TIMEOUT_MAX(lpn) ((CONFIG_BT_MESH_LPN_POLL_TIMEOUT * 100) - \ - REQ_RETRY_DURATION(lpn)) +#define POLL_TIMEOUT_INIT (CONFIG_BLE_MESH_LPN_INIT_POLL_TIMEOUT * 100) +#define POLL_TIMEOUT_MAX(lpn) ((CONFIG_BLE_MESH_LPN_POLL_TIMEOUT * 100) - \ + REQ_RETRY_DURATION(lpn)) /* Update 4 to 20 for BQB test case MESH/NODE/FRND/LPM/BI-02-C */ -#define REQ_ATTEMPTS(lpn) (POLL_TIMEOUT_MAX(lpn) < K_SECONDS(3) ? 2 : 4) +#define REQ_ATTEMPTS(lpn) (POLL_TIMEOUT_MAX(lpn) < K_SECONDS(3) ? 2 : 4) -#define CLEAR_ATTEMPTS 2 +#define CLEAR_ATTEMPTS 2 -#define LPN_CRITERIA ((CONFIG_BT_MESH_LPN_MIN_QUEUE_SIZE) | \ - (CONFIG_BT_MESH_LPN_RSSI_FACTOR << 3) | \ - (CONFIG_BT_MESH_LPN_RECV_WIN_FACTOR << 5)) +#define LPN_CRITERIA ((CONFIG_BLE_MESH_LPN_MIN_QUEUE_SIZE) | \ + (CONFIG_BLE_MESH_LPN_RSSI_FACTOR << 3) | \ + (CONFIG_BLE_MESH_LPN_RECV_WIN_FACTOR << 5)) -#define POLL_TO(to) { (u8_t)((to) >> 16), (u8_t)((to) >> 8), (u8_t)(to) } -#define LPN_POLL_TO POLL_TO(CONFIG_BT_MESH_LPN_POLL_TIMEOUT) +#define POLL_TO(to) { (u8_t)((to) >> 16), (u8_t)((to) >> 8), (u8_t)(to) } +#define LPN_POLL_TO POLL_TO(CONFIG_BLE_MESH_LPN_POLL_TIMEOUT) /* 2 transmissions, 20ms interval */ -#define POLL_XMIT BT_MESH_TRANSMIT(1, 20) +#define POLL_XMIT BLE_MESH_TRANSMIT(1, 20) static void (*lpn_cb)(u16_t friend_addr, bool established); -#if defined(CONFIG_BT_MESH_DEBUG_LOW_POWER) +#if defined(CONFIG_BLE_MESH_DEBUG_LOW_POWER) static const char *state2str(int state) { switch (state) { - case BT_MESH_LPN_DISABLED: + case BLE_MESH_LPN_DISABLED: return "disabled"; - case BT_MESH_LPN_CLEAR: + case BLE_MESH_LPN_CLEAR: return "clear"; - case BT_MESH_LPN_TIMER: + case BLE_MESH_LPN_TIMER: return "timer"; - case BT_MESH_LPN_ENABLED: + case BLE_MESH_LPN_ENABLED: return "enabled"; - case BT_MESH_LPN_REQ_WAIT: + case BLE_MESH_LPN_REQ_WAIT: return "req wait"; - case BT_MESH_LPN_WAIT_OFFER: + case BLE_MESH_LPN_WAIT_OFFER: return "wait offer"; - case BT_MESH_LPN_ESTABLISHED: + case BLE_MESH_LPN_ESTABLISHED: return "established"; - case BT_MESH_LPN_RECV_DELAY: + case BLE_MESH_LPN_RECV_DELAY: return "recv delay"; - case BT_MESH_LPN_WAIT_UPDATE: + case BLE_MESH_LPN_WAIT_UPDATE: return "wait update"; default: return "(unknown)"; } } -#endif /* CONFIG_BT_MESH_DEBUG_LPN */ +#endif /* CONFIG_BLE_MESH_DEBUG_LPN */ static inline void lpn_set_state(int state) { -#if defined(CONFIG_BT_MESH_DEBUG_LOW_POWER) +#if defined(CONFIG_BLE_MESH_DEBUG_LOW_POWER) BT_DBG("%s -> %s", state2str(bt_mesh.lpn.state), state2str(state)); #endif bt_mesh.lpn.state = state; } -static inline void group_zero(atomic_t *target) +static inline void group_zero(bt_mesh_atomic_t *target) { -#if CONFIG_BT_MESH_LPN_GROUPS > 32 +#if CONFIG_BLE_MESH_LPN_GROUPS > 32 int i; for (i = 0; i < ARRAY_SIZE(bt_mesh.lpn.added); i++) { - atomic_set(&target[i], 0); + bt_mesh_atomic_set(&target[i], 0); } #else - atomic_set(target, 0); + bt_mesh_atomic_set(target, 0); #endif } -static inline void group_set(atomic_t *target, atomic_t *source) +static inline void group_set(bt_mesh_atomic_t *target, bt_mesh_atomic_t *source) { -#if CONFIG_BT_MESH_LPN_GROUPS > 32 +#if CONFIG_BLE_MESH_LPN_GROUPS > 32 int i; for (i = 0; i < ARRAY_SIZE(bt_mesh.lpn.added); i++) { - atomic_or(&target[i], atomic_get(&source[i])); + bt_mesh_atomic_or(&target[i], bt_mesh_atomic_get(&source[i])); } #else - atomic_or(target, atomic_get(source)); + bt_mesh_atomic_or(target, bt_mesh_atomic_get(source)); #endif } -static inline void group_clear(atomic_t *target, atomic_t *source) +static inline void group_clear(bt_mesh_atomic_t *target, bt_mesh_atomic_t *source) { -#if CONFIG_BT_MESH_LPN_GROUPS > 32 +#if CONFIG_BLE_MESH_LPN_GROUPS > 32 int i; for (i = 0; i < ARRAY_SIZE(bt_mesh.lpn.added); i++) { - atomic_and(&target[i], ~atomic_get(&source[i])); + bt_mesh_atomic_and(&target[i], ~bt_mesh_atomic_get(&source[i])); } #else - atomic_and(target, ~atomic_get(source)); + bt_mesh_atomic_and(target, ~bt_mesh_atomic_get(source)); #endif } @@ -158,13 +158,13 @@ static void friend_clear_sent(int err, void *user_data) lpn->req_attempts++; if (err) { - BT_ERR("Sending Friend Request failed (err %d)", err); - lpn_set_state(BT_MESH_LPN_ENABLED); + BT_ERR("%s, Failed to send Friend Request (err %d)", __func__, err); + lpn_set_state(BLE_MESH_LPN_ENABLED); clear_friendship(false, lpn->disable); return; } - lpn_set_state(BT_MESH_LPN_CLEAR); + lpn_set_state(BLE_MESH_LPN_CLEAR); k_delayed_work_submit(&lpn->timer, FRIEND_REQ_TIMEOUT); } @@ -175,10 +175,10 @@ static const struct bt_mesh_send_cb clear_sent_cb = { static int send_friend_clear(void) { struct bt_mesh_msg_ctx ctx = { - .net_idx = bt_mesh.sub[0].net_idx, - .app_idx = BT_MESH_KEY_UNUSED, - .addr = bt_mesh.lpn.frnd, - .send_ttl = 0, + .net_idx = bt_mesh.sub[0].net_idx, + .app_idx = BLE_MESH_KEY_UNUSED, + .addr = bt_mesh.lpn.frnd, + .send_ttl = 0, }; struct bt_mesh_net_tx tx = { .sub = &bt_mesh.sub[0], @@ -217,16 +217,16 @@ static void clear_friendship(bool force, bool disable) friend_cred_del(bt_mesh.sub[0].net_idx, lpn->frnd); if (lpn->clear_success) { - lpn->old_friend = BT_MESH_ADDR_UNASSIGNED; + lpn->old_friend = BLE_MESH_ADDR_UNASSIGNED; } else { lpn->old_friend = lpn->frnd; } - if (lpn_cb && lpn->frnd != BT_MESH_ADDR_UNASSIGNED) { + if (lpn_cb && lpn->frnd != BLE_MESH_ADDR_UNASSIGNED) { lpn_cb(lpn->frnd, false); } - lpn->frnd = BT_MESH_ADDR_UNASSIGNED; + lpn->frnd = BLE_MESH_ADDR_UNASSIGNED; lpn->fsn = 0; lpn->req_attempts = 0; lpn->recv_win = 0; @@ -247,11 +247,11 @@ static void clear_friendship(bool force, bool disable) lpn->groups_changed = 1; if (disable) { - lpn_set_state(BT_MESH_LPN_DISABLED); + lpn_set_state(BLE_MESH_LPN_DISABLED); return; } - lpn_set_state(BT_MESH_LPN_ENABLED); + lpn_set_state(BLE_MESH_LPN_ENABLED); k_delayed_work_submit(&lpn->timer, FRIEND_REQ_RETRY_TIMEOUT); } @@ -260,19 +260,19 @@ 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("Sending Friend Request failed (err %d)", err); + BT_ERR("%s, Failed to send Friend Request (err %d)", __func__, err); return; } lpn->adv_duration = duration; - if (IS_ENABLED(CONFIG_BT_MESH_LPN_ESTABLISHMENT)) { + if (IS_ENABLED(CONFIG_BLE_MESH_LPN_ESTABLISHMENT)) { k_delayed_work_submit(&lpn->timer, FRIEND_REQ_WAIT); - lpn_set_state(BT_MESH_LPN_REQ_WAIT); + lpn_set_state(BLE_MESH_LPN_REQ_WAIT); } else { k_delayed_work_submit(&lpn->timer, duration + FRIEND_REQ_TIMEOUT); - lpn_set_state(BT_MESH_LPN_WAIT_OFFER); + lpn_set_state(BLE_MESH_LPN_WAIT_OFFER); } } @@ -285,14 +285,14 @@ static int send_friend_req(struct bt_mesh_lpn *lpn) const struct bt_mesh_comp *comp = bt_mesh_comp_get(); struct bt_mesh_msg_ctx ctx = { .net_idx = bt_mesh.sub[0].net_idx, - .app_idx = BT_MESH_KEY_UNUSED, - .addr = BT_MESH_ADDR_FRIENDS, + .app_idx = BLE_MESH_KEY_UNUSED, + .addr = BLE_MESH_ADDR_FRIENDS, .send_ttl = 0, }; struct bt_mesh_net_tx tx = { - .sub = &bt_mesh.sub[0], - .ctx = &ctx, - .src = bt_mesh_primary_addr(), + .sub = &bt_mesh.sub[0], + .ctx = &ctx, + .src = bt_mesh_primary_addr(), .xmit = POLL_XMIT, }; struct bt_mesh_ctl_friend_req req = { @@ -314,13 +314,13 @@ static void req_sent(u16_t duration, int err, void *user_data) { struct bt_mesh_lpn *lpn = &bt_mesh.lpn; -#if defined(CONFIG_BT_MESH_DEBUG_LOW_POWER) +#if defined(CONFIG_BLE_MESH_DEBUG_LOW_POWER) BT_DBG("req 0x%02x duration %u err %d state %s", lpn->sent_req, duration, err, state2str(lpn->state)); #endif if (err) { - BT_ERR("Sending request failed (err %d)", err); + BT_ERR("%s, Failed to send request (err %d)", __func__, err); lpn->sent_req = 0; group_zero(lpn->pending); return; @@ -329,18 +329,17 @@ static void req_sent(u16_t duration, int err, void *user_data) lpn->req_attempts++; lpn->adv_duration = duration; - if (lpn->established || IS_ENABLED(CONFIG_BT_MESH_LPN_ESTABLISHMENT)) { - lpn_set_state(BT_MESH_LPN_RECV_DELAY); + if (lpn->established || IS_ENABLED(CONFIG_BLE_MESH_LPN_ESTABLISHMENT)) { + lpn_set_state(BLE_MESH_LPN_RECV_DELAY); /* We start scanning a bit early to elimitate risk of missing * response data due to HCI and other latencies. */ k_delayed_work_submit(&lpn->timer, LPN_RECV_DELAY - SCAN_LATENCY); } else { - lpn_set_state(BT_MESH_LPN_OFFER_RECV); + lpn_set_state(BLE_MESH_LPN_OFFER_RECV); k_delayed_work_submit(&lpn->timer, - LPN_RECV_DELAY + duration + - lpn->recv_win); + LPN_RECV_DELAY + duration + lpn->recv_win); } } @@ -351,10 +350,10 @@ static const struct bt_mesh_send_cb req_sent_cb = { static int send_friend_poll(void) { struct bt_mesh_msg_ctx ctx = { - .net_idx = bt_mesh.sub[0].net_idx, - .app_idx = BT_MESH_KEY_UNUSED, - .addr = bt_mesh.lpn.frnd, - .send_ttl = 0, + .net_idx = bt_mesh.sub[0].net_idx, + .app_idx = BLE_MESH_KEY_UNUSED, + .addr = bt_mesh.lpn.frnd, + .send_ttl = 0, }; struct bt_mesh_net_tx tx = { .sub = &bt_mesh.sub[0], @@ -389,7 +388,7 @@ static int send_friend_poll(void) void bt_mesh_lpn_disable(bool force) { - if (bt_mesh.lpn.state == BT_MESH_LPN_DISABLED) { + if (bt_mesh.lpn.state == BLE_MESH_LPN_DISABLED) { return; } @@ -401,38 +400,38 @@ int bt_mesh_lpn_set(bool enable) struct bt_mesh_lpn *lpn = &bt_mesh.lpn; if (enable) { - if (lpn->state != BT_MESH_LPN_DISABLED) { + if (lpn->state != BLE_MESH_LPN_DISABLED) { return 0; } } else { - if (lpn->state == BT_MESH_LPN_DISABLED) { + if (lpn->state == BLE_MESH_LPN_DISABLED) { return 0; } } if (!bt_mesh_is_provisioned()) { if (enable) { - lpn_set_state(BT_MESH_LPN_ENABLED); + lpn_set_state(BLE_MESH_LPN_ENABLED); } else { - lpn_set_state(BT_MESH_LPN_DISABLED); + lpn_set_state(BLE_MESH_LPN_DISABLED); } return 0; } if (enable) { - lpn_set_state(BT_MESH_LPN_ENABLED); + lpn_set_state(BLE_MESH_LPN_ENABLED); - if (IS_ENABLED(CONFIG_BT_MESH_LPN_ESTABLISHMENT)) { + if (IS_ENABLED(CONFIG_BLE_MESH_LPN_ESTABLISHMENT)) { bt_mesh_scan_disable(); } send_friend_req(lpn); } else { - if (IS_ENABLED(CONFIG_BT_MESH_LPN_AUTO) && - lpn->state == BT_MESH_LPN_TIMER) { + if (IS_ENABLED(CONFIG_BLE_MESH_LPN_AUTO) && + lpn->state == BLE_MESH_LPN_TIMER) { k_delayed_work_cancel(&lpn->timer); - lpn_set_state(BT_MESH_LPN_DISABLED); + lpn_set_state(BLE_MESH_LPN_DISABLED); } else { bt_mesh_lpn_disable(false); } @@ -451,7 +450,7 @@ static void friend_response_received(struct bt_mesh_lpn *lpn) k_delayed_work_cancel(&lpn->timer); bt_mesh_scan_disable(); - lpn_set_state(BT_MESH_LPN_ESTABLISHED); + lpn_set_state(BLE_MESH_LPN_ESTABLISHED); lpn->req_attempts = 0; lpn->sent_req = 0; } @@ -460,14 +459,14 @@ void bt_mesh_lpn_msg_received(struct bt_mesh_net_rx *rx) { struct bt_mesh_lpn *lpn = &bt_mesh.lpn; - if (lpn->state == BT_MESH_LPN_TIMER) { + if (lpn->state == BLE_MESH_LPN_TIMER) { BT_DBG("Restarting establishment timer"); k_delayed_work_submit(&lpn->timer, LPN_AUTO_TIMEOUT); return; } if (lpn->sent_req != TRANS_CTL_OP_FRIEND_POLL) { - BT_WARN("Unexpected message withouth a preceding Poll"); + BT_WARN("%s, Unexpected message withouth a preceding Poll", __func__); return; } @@ -489,17 +488,17 @@ int bt_mesh_lpn_friend_offer(struct bt_mesh_net_rx *rx, int err; if (buf->len < sizeof(*msg)) { - BT_WARN("Too short Friend Offer"); + BT_WARN("%s, Too short Friend Offer", __func__); return -EINVAL; } - if (lpn->state != BT_MESH_LPN_WAIT_OFFER) { - BT_WARN("Ignoring unexpected Friend Offer"); + if (lpn->state != BLE_MESH_LPN_WAIT_OFFER) { + BT_WARN("%s, Ignoring unexpected Friend Offer", __func__); return 0; } if (!msg->recv_win) { - BT_WARN("Prohibited ReceiveWindow value"); + BT_WARN("%s, Prohibited ReceiveWindow value", __func__); return -EINVAL; } @@ -513,7 +512,7 @@ int bt_mesh_lpn_friend_offer(struct bt_mesh_net_rx *rx, cred = friend_cred_create(sub, lpn->frnd, lpn->counter, frnd_counter); if (!cred) { - lpn->frnd = BT_MESH_ADDR_UNASSIGNED; + lpn->frnd = BLE_MESH_ADDR_UNASSIGNED; return -ENOMEM; } @@ -527,7 +526,7 @@ int bt_mesh_lpn_friend_offer(struct bt_mesh_net_rx *rx, err = send_friend_poll(); if (err) { friend_cred_clear(cred); - lpn->frnd = BT_MESH_ADDR_UNASSIGNED; + lpn->frnd = BLE_MESH_ADDR_UNASSIGNED; lpn->recv_win = 0; lpn->queue_size = 0; return err; @@ -546,12 +545,12 @@ int bt_mesh_lpn_friend_clear_cfm(struct bt_mesh_net_rx *rx, u16_t addr, counter; if (buf->len < sizeof(*msg)) { - BT_WARN("Too short Friend Clear Confirm"); + BT_WARN("%s, Too short Friend Clear Confirm", __func__); return -EINVAL; } - if (lpn->state != BT_MESH_LPN_CLEAR) { - BT_WARN("Ignoring unexpected Friend Clear Confirm"); + if (lpn->state != BLE_MESH_LPN_CLEAR) { + BT_WARN("%s, Ignoring unexpected Friend Clear Confirm", __func__); return 0; } @@ -561,7 +560,7 @@ int bt_mesh_lpn_friend_clear_cfm(struct bt_mesh_net_rx *rx, BT_DBG("LPNAddress 0x%04x LPNCounter 0x%04x", addr, counter); if (addr != bt_mesh_primary_addr() || counter != lpn->counter) { - BT_WARN("Invalid parameters in Friend Clear Confirm"); + BT_WARN("%s, Invalid parameters in Friend Clear Confirm", __func__); return 0; } @@ -579,17 +578,17 @@ static void lpn_group_add(u16_t group) for (i = 0; i < ARRAY_SIZE(lpn->groups); i++) { if (lpn->groups[i] == group) { - atomic_clear_bit(lpn->to_remove, i); + bt_mesh_atomic_clear_bit(lpn->to_remove, i); return; } - if (!free_slot && lpn->groups[i] == BT_MESH_ADDR_UNASSIGNED) { + if (!free_slot && lpn->groups[i] == BLE_MESH_ADDR_UNASSIGNED) { free_slot = &lpn->groups[i]; } } if (!free_slot) { - BT_WARN("Friend Subscription List exceeded!"); + BT_WARN("%s, Friend Subscription List exceeded!", __func__); return; } @@ -604,27 +603,27 @@ static void lpn_group_del(u16_t group) for (i = 0; i < ARRAY_SIZE(lpn->groups); i++) { if (lpn->groups[i] == group) { - if (atomic_test_bit(lpn->added, i) || - atomic_test_bit(lpn->pending, i)) { - atomic_set_bit(lpn->to_remove, i); + if (bt_mesh_atomic_test_bit(lpn->added, i) || + bt_mesh_atomic_test_bit(lpn->pending, i)) { + bt_mesh_atomic_set_bit(lpn->to_remove, i); lpn->groups_changed = 1; } else { - lpn->groups[i] = BT_MESH_ADDR_UNASSIGNED; + lpn->groups[i] = BLE_MESH_ADDR_UNASSIGNED; } } } } -static inline int group_popcount(atomic_t *target) +static inline int group_popcount(bt_mesh_atomic_t *target) { -#if CONFIG_BT_MESH_LPN_GROUPS > 32 +#if CONFIG_BLE_MESH_LPN_GROUPS > 32 int i, count = 0; for (i = 0; i < ARRAY_SIZE(bt_mesh.lpn.added); i++) { - count += popcount(atomic_get(&target[i])); + count += popcount(bt_mesh_atomic_get(&target[i])); } #else - return popcount(atomic_get(target)); + return popcount(bt_mesh_atomic_get(target)); #endif } @@ -633,10 +632,10 @@ static bool sub_update(u8_t op) struct bt_mesh_lpn *lpn = &bt_mesh.lpn; int added_count = group_popcount(lpn->added); struct bt_mesh_msg_ctx ctx = { - .net_idx = bt_mesh.sub[0].net_idx, - .app_idx = BT_MESH_KEY_UNUSED, - .addr = lpn->frnd, - .send_ttl = 0, + .net_idx = bt_mesh.sub[0].net_idx, + .app_idx = BLE_MESH_KEY_UNUSED, + .addr = lpn->frnd, + .send_ttl = 0, }; struct bt_mesh_net_tx tx = { .sub = &bt_mesh.sub[0], @@ -655,27 +654,27 @@ static bool sub_update(u8_t op) } for (i = 0, g = 0; i < ARRAY_SIZE(lpn->groups); i++) { - if (lpn->groups[i] == BT_MESH_ADDR_UNASSIGNED) { + if (lpn->groups[i] == BLE_MESH_ADDR_UNASSIGNED) { continue; } if (op == TRANS_CTL_OP_FRIEND_SUB_ADD) { - if (atomic_test_bit(lpn->added, i)) { + if (bt_mesh_atomic_test_bit(lpn->added, i)) { continue; } } else { - if (!atomic_test_bit(lpn->to_remove, i)) { + if (!bt_mesh_atomic_test_bit(lpn->to_remove, i)) { continue; } } if (added_count + g >= lpn->queue_size) { - BT_WARN("Friend Queue Size exceeded"); + BT_WARN("%s, Friend Queue Size exceeded", __func__); break; } req.addr_list[g++] = sys_cpu_to_be16(lpn->groups[i]); - atomic_set_bit(lpn->pending, i); + bt_mesh_atomic_set_bit(lpn->pending, i); if (g == ARRAY_SIZE(req.addr_list)) { break; @@ -703,24 +702,24 @@ static bool sub_update(u8_t op) static void update_timeout(struct bt_mesh_lpn *lpn) { if (lpn->established) { - BT_WARN("No response from Friend during ReceiveWindow"); + BT_WARN("%s, No response from Friend during ReceiveWindow", __func__); bt_mesh_scan_disable(); - lpn_set_state(BT_MESH_LPN_ESTABLISHED); + lpn_set_state(BLE_MESH_LPN_ESTABLISHED); k_delayed_work_submit(&lpn->timer, POLL_RETRY_TIMEOUT); } else { - if (IS_ENABLED(CONFIG_BT_MESH_LPN_ESTABLISHMENT)) { + if (IS_ENABLED(CONFIG_BLE_MESH_LPN_ESTABLISHMENT)) { bt_mesh_scan_disable(); } if (lpn->req_attempts < 6) { - BT_WARN("Retrying first Friend Poll"); + BT_WARN("%s, Retrying first Friend Poll", __func__); lpn->sent_req = 0; if (send_friend_poll() == 0) { return; } } - BT_ERR("Timed out waiting for first Friend Update"); + BT_ERR("%s, Timed out waiting for first Friend Update", __func__); clear_friendship(false, false); } } @@ -729,47 +728,47 @@ static void lpn_timeout(struct k_work *work) { struct bt_mesh_lpn *lpn = &bt_mesh.lpn; -#if defined(CONFIG_BT_MESH_DEBUG_LOW_POWER) +#if defined(CONFIG_BLE_MESH_DEBUG_LOW_POWER) BT_DBG("state: %s", state2str(lpn->state)); #endif switch (lpn->state) { - case BT_MESH_LPN_DISABLED: + case BLE_MESH_LPN_DISABLED: break; - case BT_MESH_LPN_CLEAR: + case BLE_MESH_LPN_CLEAR: clear_friendship(false, bt_mesh.lpn.disable); break; - case BT_MESH_LPN_TIMER: + case BLE_MESH_LPN_TIMER: BT_DBG("Starting to look for Friend nodes"); - lpn_set_state(BT_MESH_LPN_ENABLED); - if (IS_ENABLED(CONFIG_BT_MESH_LPN_ESTABLISHMENT)) { + lpn_set_state(BLE_MESH_LPN_ENABLED); + if (IS_ENABLED(CONFIG_BLE_MESH_LPN_ESTABLISHMENT)) { bt_mesh_scan_disable(); } /* fall through */ - case BT_MESH_LPN_ENABLED: + case BLE_MESH_LPN_ENABLED: send_friend_req(lpn); break; - case BT_MESH_LPN_REQ_WAIT: + case BLE_MESH_LPN_REQ_WAIT: bt_mesh_scan_enable(); k_delayed_work_submit(&lpn->timer, lpn->adv_duration + FRIEND_REQ_SCAN); - lpn_set_state(BT_MESH_LPN_WAIT_OFFER); + lpn_set_state(BLE_MESH_LPN_WAIT_OFFER); break; - case BT_MESH_LPN_WAIT_OFFER: - BT_WARN("No acceptable Friend Offers received"); - if (IS_ENABLED(CONFIG_BT_MESH_LPN_ESTABLISHMENT)) { + case BLE_MESH_LPN_WAIT_OFFER: + BT_WARN("%s, No acceptable Friend Offers received", __func__); + if (IS_ENABLED(CONFIG_BLE_MESH_LPN_ESTABLISHMENT)) { bt_mesh_scan_disable(); } lpn->counter++; - lpn_set_state(BT_MESH_LPN_ENABLED); + lpn_set_state(BLE_MESH_LPN_ENABLED); k_delayed_work_submit(&lpn->timer, FRIEND_REQ_RETRY_TIMEOUT); break; - case BT_MESH_LPN_OFFER_RECV: - BT_WARN("No Friend Update received after the first Friend Poll"); + case BLE_MESH_LPN_OFFER_RECV: + BT_WARN("%s, No Friend Update received after the first Friend Poll", __func__); lpn->sent_req = 0; send_friend_poll(); break; - case BT_MESH_LPN_ESTABLISHED: + case BLE_MESH_LPN_ESTABLISHED: if (lpn->req_attempts < REQ_ATTEMPTS(lpn)) { u8_t req = lpn->sent_req; @@ -784,19 +783,19 @@ static void lpn_timeout(struct k_work *work) break; } - BT_ERR("No response from Friend after %u retries", - lpn->req_attempts); + BT_ERR("%s, No response from Friend after %u retries", + __func__, lpn->req_attempts); lpn->req_attempts = 0; clear_friendship(false, false); break; - case BT_MESH_LPN_RECV_DELAY: + case BLE_MESH_LPN_RECV_DELAY: k_delayed_work_submit(&lpn->timer, lpn->adv_duration + SCAN_LATENCY + lpn->recv_win); bt_mesh_scan_enable(); - lpn_set_state(BT_MESH_LPN_WAIT_UPDATE); + lpn_set_state(BLE_MESH_LPN_WAIT_UPDATE); break; - case BT_MESH_LPN_WAIT_UPDATE: + case BLE_MESH_LPN_WAIT_UPDATE: update_timeout(lpn); break; default: @@ -823,7 +822,7 @@ void bt_mesh_lpn_group_del(u16_t *groups, size_t group_count) int i; for (i = 0; i < group_count; i++) { - if (groups[i] != BT_MESH_ADDR_UNASSIGNED) { + if (groups[i] != BLE_MESH_ADDR_UNASSIGNED) { BT_DBG("group 0x%04x", groups[i]); lpn_group_del(groups[i]); } @@ -840,12 +839,12 @@ static s32_t poll_timeout(struct bt_mesh_lpn *lpn) { /* If we're waiting for segment acks keep polling at high freq */ if (bt_mesh_tx_in_progress()) { - return min(POLL_TIMEOUT_MAX(lpn), K_SECONDS(1)); + return MIN(POLL_TIMEOUT_MAX(lpn), K_SECONDS(1)); } if (lpn->poll_timeout < POLL_TIMEOUT_MAX(lpn)) { lpn->poll_timeout *= 2; - lpn->poll_timeout = min(lpn->poll_timeout, + lpn->poll_timeout = MIN(lpn->poll_timeout, POLL_TIMEOUT_MAX(lpn)); } @@ -861,20 +860,20 @@ int bt_mesh_lpn_friend_sub_cfm(struct bt_mesh_net_rx *rx, struct bt_mesh_lpn *lpn = &bt_mesh.lpn; if (buf->len < sizeof(*msg)) { - BT_WARN("Too short Friend Subscription Confirm"); + BT_WARN("%s, Too short Friend Subscription Confirm", __func__); return -EINVAL; } BT_DBG("xact 0x%02x", msg->xact); if (!lpn->sent_req) { - BT_WARN("No pending subscription list message"); + BT_WARN("%s, No pending subscription list message", __func__); return 0; } if (msg->xact != lpn->xact_pending) { - BT_WARN("Transaction mismatch (0x%02x != 0x%02x)", - msg->xact, lpn->xact_pending); + BT_WARN("%s, Transaction mismatch (0x%02x != 0x%02x)", + __func__, msg->xact, lpn->xact_pending); return 0; } @@ -887,13 +886,13 @@ int bt_mesh_lpn_friend_sub_cfm(struct bt_mesh_net_rx *rx, group_clear(lpn->added, lpn->pending); for (i = 0; i < ARRAY_SIZE(lpn->groups); i++) { - if (atomic_test_and_clear_bit(lpn->pending, i) && - atomic_test_and_clear_bit(lpn->to_remove, i)) { - lpn->groups[i] = BT_MESH_ADDR_UNASSIGNED; + if (bt_mesh_atomic_test_and_clear_bit(lpn->pending, i) && + bt_mesh_atomic_test_and_clear_bit(lpn->to_remove, i)) { + lpn->groups[i] = BLE_MESH_ADDR_UNASSIGNED; } } } else { - BT_WARN("Unexpected Friend Subscription Confirm"); + BT_WARN("%s, Unexpected Friend Subscription Confirm", __func__); return 0; } @@ -928,22 +927,22 @@ int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx, u32_t iv_index; if (buf->len < sizeof(*msg)) { - BT_WARN("Too short Friend Update"); + BT_WARN("%s, Too short Friend Update", __func__); return -EINVAL; } if (lpn->sent_req != TRANS_CTL_OP_FRIEND_POLL) { - BT_WARN("Unexpected friend update"); + BT_WARN("%s, Unexpected friend update", __func__); return 0; } - if (sub->kr_phase == BT_MESH_KR_PHASE_2 && !rx->new_key) { - BT_WARN("Ignoring Phase 2 KR Update secured using old key"); + if (sub->kr_phase == BLE_MESH_KR_PHASE_2 && !rx->new_key) { + BT_WARN("%s, Ignoring Phase 2 KR Update secured using old key", __func__); return 0; } if (bt_mesh.ivu_initiator && - bt_mesh.iv_update == BT_MESH_IV_UPDATE(msg->flags)) { + bt_mesh.iv_update == BLE_MESH_IV_UPDATE(msg->flags)) { bt_mesh_beacon_ivu_initiator(false); } @@ -954,7 +953,7 @@ int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx, * Credentials) were used for this message. */ if (!rx->friend_cred) { - BT_WARN("Friend Update with wrong credentials"); + BT_WARN("%s, Friend Update with wrong credentials", __func__); return -EINVAL; } @@ -967,7 +966,7 @@ int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx, } /* Set initial poll timeout */ - lpn->poll_timeout = min(POLL_TIMEOUT_MAX(lpn), + lpn->poll_timeout = MIN(POLL_TIMEOUT_MAX(lpn), POLL_TIMEOUT_INIT); } @@ -978,12 +977,12 @@ int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx, BT_DBG("flags 0x%02x iv_index 0x%08x md %u", msg->flags, iv_index, msg->md); - if (bt_mesh_kr_update(sub, BT_MESH_KEY_REFRESH(msg->flags), + if (bt_mesh_kr_update(sub, BLE_MESH_KEY_REFRESH(msg->flags), rx->new_key)) { bt_mesh_net_beacon_update(sub); } - bt_mesh_net_iv_update(iv_index, BT_MESH_IV_UPDATE(msg->flags)); + bt_mesh_net_iv_update(iv_index, BLE_MESH_IV_UPDATE(msg->flags)); if (lpn->groups_changed) { sub_update(TRANS_CTL_OP_FRIEND_SUB_ADD); @@ -1030,8 +1029,8 @@ int bt_mesh_lpn_init(void) k_delayed_work_init(&lpn->timer, lpn_timeout); - if (lpn->state == BT_MESH_LPN_ENABLED) { - if (IS_ENABLED(CONFIG_BT_MESH_LPN_ESTABLISHMENT)) { + if (lpn->state == BLE_MESH_LPN_ENABLED) { + if (IS_ENABLED(CONFIG_BLE_MESH_LPN_ESTABLISHMENT)) { bt_mesh_scan_disable(); } else { bt_mesh_scan_enable(); @@ -1041,14 +1040,14 @@ int bt_mesh_lpn_init(void) } else { bt_mesh_scan_enable(); - if (IS_ENABLED(CONFIG_BT_MESH_LPN_AUTO)) { + if (IS_ENABLED(CONFIG_BLE_MESH_LPN_AUTO)) { BT_DBG("Waiting %u ms for messages", LPN_AUTO_TIMEOUT); - lpn_set_state(BT_MESH_LPN_TIMER); + lpn_set_state(BLE_MESH_LPN_TIMER); k_delayed_work_submit(&lpn->timer, LPN_AUTO_TIMEOUT); } } return 0; } -#endif /* CONFIG_BT_MESH_LOW_POWER */ -#endif /* #if CONFIG_BT_MESH */ \ No newline at end of file + +#endif /* CONFIG_BLE_MESH_LOW_POWER */ diff --git a/components/bt/ble_mesh/mesh_core/lpn.h b/components/bt/ble_mesh/mesh_core/lpn.h index 6dc6dd960f..07bca99904 100644 --- a/components/bt/ble_mesh/mesh_core/lpn.h +++ b/components/bt/ble_mesh/mesh_core/lpn.h @@ -6,18 +6,24 @@ * SPDX-License-Identifier: Apache-2.0 */ +#ifndef _LPN_H_ +#define _LPN_H_ + int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf); + int bt_mesh_lpn_friend_offer(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf); + int bt_mesh_lpn_friend_clear_cfm(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf); + int bt_mesh_lpn_friend_sub_cfm(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf); static inline bool bt_mesh_lpn_established(void) { -#if defined(CONFIG_BT_MESH_LOW_POWER) +#if defined(CONFIG_BLE_MESH_LOW_POWER) return bt_mesh.lpn.established; #else return false; @@ -26,7 +32,7 @@ static inline bool bt_mesh_lpn_established(void) static inline bool bt_mesh_lpn_match(u16_t addr) { -#if defined(CONFIG_BT_MESH_LOW_POWER) +#if defined(CONFIG_BLE_MESH_LOW_POWER) if (bt_mesh_lpn_established()) { return (addr == bt_mesh.lpn.frnd); } @@ -36,8 +42,8 @@ static inline bool bt_mesh_lpn_match(u16_t addr) static inline bool bt_mesh_lpn_waiting_update(void) { -#if defined(CONFIG_BT_MESH_LOW_POWER) - return (bt_mesh.lpn.state == BT_MESH_LPN_WAIT_UPDATE); +#if defined(CONFIG_BLE_MESH_LOW_POWER) + return (bt_mesh.lpn.state == BLE_MESH_LPN_WAIT_UPDATE); #else return false; #endif @@ -45,8 +51,8 @@ static inline bool bt_mesh_lpn_waiting_update(void) static inline bool bt_mesh_lpn_timer(void) { -#if defined(CONFIG_BT_MESH_LPN_AUTO) - return (bt_mesh.lpn.state == BT_MESH_LPN_TIMER); +#if defined(CONFIG_BLE_MESH_LPN_AUTO) + return (bt_mesh.lpn.state == BLE_MESH_LPN_TIMER); #else return false; #endif @@ -55,8 +61,11 @@ static inline bool bt_mesh_lpn_timer(void) void bt_mesh_lpn_msg_received(struct bt_mesh_net_rx *rx); void bt_mesh_lpn_group_add(u16_t group); + void bt_mesh_lpn_group_del(u16_t *groups, size_t group_count); void bt_mesh_lpn_disable(bool force); int bt_mesh_lpn_init(void); + +#endif /* _LPN_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/mesh.h b/components/bt/ble_mesh/mesh_core/mesh.h index b8ca726566..9adc1f0c8b 100644 --- a/components/bt/ble_mesh/mesh_core/mesh.h +++ b/components/bt/ble_mesh/mesh_core/mesh.h @@ -6,14 +6,19 @@ * SPDX-License-Identifier: Apache-2.0 */ -#define BT_MESH_KEY_PRIMARY 0x0000 -#define BT_MESH_KEY_ANY 0xffff +#ifndef _MESH_H_ +#define _MESH_H_ -#define BT_MESH_ADDR_IS_UNICAST(addr) ((addr) && (addr) < 0x8000) -#define BT_MESH_ADDR_IS_GROUP(addr) ((addr) >= 0xc000 && (addr) <= 0xff00) -#define BT_MESH_ADDR_IS_VIRTUAL(addr) ((addr) >= 0x8000 && (addr) < 0xc000) -#define BT_MESH_ADDR_IS_RFU(addr) ((addr) >= 0xff00 && (addr) <= 0xfffb) +#define BLE_MESH_KEY_PRIMARY 0x0000 +#define BLE_MESH_KEY_ANY 0xffff + +#define BLE_MESH_ADDR_IS_UNICAST(addr) ((addr) && (addr) < 0x8000) +#define BLE_MESH_ADDR_IS_GROUP(addr) ((addr) >= 0xc000 && (addr) <= 0xff00) +#define BLE_MESH_ADDR_IS_VIRTUAL(addr) ((addr) >= 0x8000 && (addr) < 0xc000) +#define BLE_MESH_ADDR_IS_RFU(addr) ((addr) >= 0xff00 && (addr) <= 0xfffb) struct bt_mesh_net; bool bt_mesh_is_provisioned(void); + +#endif /* _MESH_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/mesh_aes_encrypt.c b/components/bt/ble_mesh/mesh_core/mesh_aes_encrypt.c index db1d8b8489..2d1842cc4b 100644 --- a/components/bt/ble_mesh/mesh_core/mesh_aes_encrypt.c +++ b/components/bt/ble_mesh/mesh_core/mesh_aes_encrypt.c @@ -34,8 +34,6 @@ #include "mesh_util.h" #include "sdkconfig.h" -#if CONFIG_BT_MESH - /* max number of calls until change the key (2^48).*/ const static uint64_t MAX_CALLS = ((uint64_t)1 << 48); @@ -67,7 +65,6 @@ const static uint64_t MAX_CALLS = ((uint64_t)1 << 48); */ const unsigned char gf_wrap = 0x87; - static const uint8_t sbox[256] = { 0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, 0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, 0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, @@ -98,8 +95,8 @@ static inline unsigned int rotword(unsigned int a) return (((a) >> 24) | ((a) << 8)); } -#define subbyte(a, o)(sbox[((a) >> (o))&0xff] << (o)) -#define subword(a)(subbyte(a, 24)|subbyte(a, 16)|subbyte(a, 8)|subbyte(a, 0)) +#define subbyte(a, o) (sbox[((a) >> (o))&0xff] << (o)) +#define subword(a) (subbyte(a, 24)|subbyte(a, 16)|subbyte(a, 8)|subbyte(a, 0)) int tc_aes128_set_encrypt_key(TCAesKeySched_t s, const uint8_t *k) { @@ -410,6 +407,3 @@ int tc_cmac_erase(TCCmacState_t s) return TC_CRYPTO_SUCCESS; } - -#endif /* #if CONFIG_BT_MESH */ - diff --git a/components/bt/ble_mesh/mesh_core/mesh_atomic.c b/components/bt/ble_mesh/mesh_core/mesh_atomic.c index a268a792b1..ce73638053 100644 --- a/components/bt/ble_mesh/mesh_core/mesh_atomic.c +++ b/components/bt/ble_mesh/mesh_core/mesh_atomic.c @@ -22,7 +22,7 @@ #include "mesh_kernel.h" #include "sdkconfig.h" -#if CONFIG_BT_MESH +#ifndef CONFIG_ATOMIC_OPERATIONS_BUILTIN /** * @@ -36,7 +36,7 @@ * * @return The value read from */ -atomic_val_t atomic_get(const atomic_t *target) +bt_mesh_atomic_val_t bt_mesh_atomic_get(const bt_mesh_atomic_t *target) { return *target; } @@ -53,17 +53,17 @@ atomic_val_t atomic_get(const atomic_t *target) * * @return The previous value from */ -atomic_val_t atomic_set(atomic_t *target, atomic_val_t value) +bt_mesh_atomic_val_t bt_mesh_atomic_set(bt_mesh_atomic_t *target, bt_mesh_atomic_val_t value) { unsigned int key; - atomic_val_t ret; + bt_mesh_atomic_val_t ret; - key = irq_lock(); + key = bt_mesh_irq_lock(); ret = *target; *target = value; - irq_unlock(key); + bt_mesh_irq_unlock(key); return ret; } @@ -81,17 +81,17 @@ atomic_val_t atomic_set(atomic_t *target, atomic_val_t value) * * @return The previous value from */ -atomic_val_t atomic_or(atomic_t *target, atomic_val_t value) +bt_mesh_atomic_val_t bt_mesh_atomic_or(bt_mesh_atomic_t *target, bt_mesh_atomic_val_t value) { unsigned int key; - atomic_val_t ret; + bt_mesh_atomic_val_t ret; - key = irq_lock(); + key = bt_mesh_irq_lock(); ret = *target; *target |= value; - irq_unlock(key); + bt_mesh_irq_unlock(key); return ret; } @@ -109,17 +109,17 @@ atomic_val_t atomic_or(atomic_t *target, atomic_val_t value) * * @return The previous value from */ -atomic_val_t atomic_and(atomic_t *target, atomic_val_t value) +bt_mesh_atomic_val_t bt_mesh_atomic_and(bt_mesh_atomic_t *target, bt_mesh_atomic_val_t value) { unsigned int key; - atomic_val_t ret; + bt_mesh_atomic_val_t ret; - key = irq_lock(); + key = bt_mesh_irq_lock(); ret = *target; *target &= value; - irq_unlock(key); + bt_mesh_irq_unlock(key); return ret; } @@ -135,17 +135,17 @@ atomic_val_t atomic_and(atomic_t *target, atomic_val_t value) * * @return The value from prior to the decrement */ -atomic_val_t atomic_dec(atomic_t *target) +bt_mesh_atomic_val_t bt_mesh_atomic_dec(bt_mesh_atomic_t *target) { unsigned int key; - atomic_val_t ret; + bt_mesh_atomic_val_t ret; - key = irq_lock(); + key = bt_mesh_irq_lock(); ret = *target; (*target)--; - irq_unlock(key); + bt_mesh_irq_unlock(key); return ret; } @@ -161,20 +161,19 @@ atomic_val_t atomic_dec(atomic_t *target) * * @return The value from before the increment */ -atomic_val_t atomic_inc(atomic_t *target) +bt_mesh_atomic_val_t bt_mesh_atomic_inc(bt_mesh_atomic_t *target) { unsigned int key; - atomic_val_t ret; + bt_mesh_atomic_val_t ret; - key = irq_lock(); + key = bt_mesh_irq_lock(); ret = *target; (*target)++; - irq_unlock(key); + bt_mesh_irq_unlock(key); return ret; } -#endif /* #if CONFIG_BT_MESH */ - +#endif /* #ifndef CONFIG_ATOMIC_OPERATIONS_BUILTIN */ diff --git a/components/bt/ble_mesh/mesh_core/mesh_bearer_adapt.c b/components/bt/ble_mesh/mesh_core/mesh_bearer_adapt.c index 73c6d7d3f5..5e5ffb1175 100644 --- a/components/bt/ble_mesh/mesh_core/mesh_bearer_adapt.c +++ b/components/bt/ble_mesh/mesh_core/mesh_bearer_adapt.c @@ -8,55 +8,46 @@ #include -#include "mesh_bearer_adapt.h" -#include "mesh_trace.h" +#include "sdkconfig.h" #include "bta/bta_api.h" #include "bta/bta_gatt_api.h" #include "bta/bta_gatt_common.h" +#include "bta_gattc_int.h" #include "stack/btm_ble_api.h" #include "p_256_ecc_pp.h" - #include "stack/hcimsgs.h" #include "osi/future.h" -#include "include/mesh_buf.h" #include "osi/allocator.h" -#include "include/mesh_atomic.h" -#include "include/mesh_hci.h" #include "mbedtls/aes.h" -#include "mesh_aes_encrypt.h" -#include "sdkconfig.h" -#if CONFIG_BT_MESH -#include "bta/bta_api.h" -#include -#include "include/mesh_buf.h" -#include "osi/allocator.h" -#include "include/mesh_atomic.h" -#include "bta_gattc_int.h" +#include "mesh_hci.h" +#include "mesh_aes_encrypt.h" +#include "mesh_bearer_adapt.h" +#include "mesh_trace.h" +#include "mesh_buf.h" +#include "mesh_atomic.h" + #include "provisioner_prov.h" -#include "common.h" +#include "mesh_common.h" #define BLE_MESH_BTM_CHECK_STATUS(func) do { \ tBTM_STATUS __status = (func); \ if ((__status != BTM_SUCCESS) && (__status != BTM_CMD_STARTED)) { \ - BT_ERR("%s, invalid status %d", __func__, __status); \ + BT_ERR("%s, Invalid status %d", __func__, __status); \ return -1; \ } \ } while(0); -#define BT_MESH_GATT_GET_CONN_ID(conn_id) (((u16_t)(conn_id)) >> 8) -#define BT_MESH_GATT_CREATE_CONN_ID(gatt_if, conn_id) ((u16_t)((((u8_t)(conn_id)) << 8) | ((u8_t)(gatt_if)))) +#define BLE_MESH_GATT_GET_CONN_ID(conn_id) (((u16_t)(conn_id)) >> 8) +#define BLE_MESH_GATT_CREATE_CONN_ID(gatt_if, conn_id) ((u16_t)((((u8_t)(conn_id)) << 8) | ((u8_t)(gatt_if)))) #define CONFIG_BT_MAX_CONN CONFIG_BT_ACL_CONNECTIONS -/* We don't need to manage the BT_DEV_ADVERTISING flags in the version of bluedriod, +/* We don't need to manage the BLE_MESH_DEV_ADVERTISING flags in the version of bluedriod, * it will manage it in the BTM layer. */ -#define BT_DEV 0 - -/* Global Variables */ -extern struct bt_dev bt_dev; +#define BLE_MESH_DEV 0 /* P-256 Variables */ static u8_t bt_mesh_public_key[64]; @@ -68,29 +59,29 @@ static BT_OCTET32 bt_mesh_private_key = { }; /* Scan related functions */ -static bt_le_scan_cb_t *bt_mesh_scan_dev_found_cb; +static bt_mesh_scan_cb_t *bt_mesh_scan_dev_found_cb; static void bt_mesh_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data); -#if defined(CONFIG_BT_MESH_NODE) && CONFIG_BT_MESH_NODE +#if defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE /* the gatt database list to save the attribute table */ static sys_slist_t bt_mesh_gatts_db; /* Static Variables */ -static struct bt_conn bt_mesh_gatts_conn[CONFIG_BT_MAX_CONN]; -static struct bt_conn_cb *bt_mesh_gatts_conn_cb; +static struct bt_mesh_conn bt_mesh_gatts_conn[CONFIG_BT_MAX_CONN]; +static struct bt_mesh_conn_cb *bt_mesh_gatts_conn_cb; static tBTA_GATTS_IF bt_mesh_gatts_if; static u16_t svc_handle, char_handle; static future_t *future_mesh; /* Static Functions */ -static struct bt_gatt_attr *bt_mesh_gatts_find_attr_by_handle(u16_t handle); -#endif /* defined(CONFIG_BT_MESH_NODE) && CONFIG_BT_MESH_NODE */ +static struct bt_mesh_gatt_attr *bt_mesh_gatts_find_attr_by_handle(u16_t handle); +#endif /* defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE */ -#if defined(CONFIG_BT_MESH_PROVISIONER) && CONFIG_BT_MESH_PROVISIONER -#define BT_MESH_GATTC_APP_UUID_BYTE 0x97 +#if defined(CONFIG_BLE_MESH_PROVISIONER) && CONFIG_BLE_MESH_PROVISIONER +#define BLE_MESH_GATTC_APP_UUID_BYTE 0x97 static struct gattc_prov_info { /* Service to be found depends on the type of adv pkt received */ - struct bt_conn conn; + struct bt_mesh_conn conn; BD_ADDR addr; u8_t addr_type; u16_t service_uuid; @@ -102,14 +93,15 @@ static struct gattc_prov_info { u16_t data_out_handle; /* Data Out Characteristic attribute handle */ u16_t ccc_handle; /* Data Out Characteristic CCC attribute handle */ } bt_mesh_gattc_info[CONFIG_BT_MAX_CONN]; -static struct bt_prov_conn_cb *bt_mesh_gattc_conn_cb; +static struct bt_mesh_prov_conn_cb *bt_mesh_gattc_conn_cb; static tBTA_GATTC_IF bt_mesh_gattc_if; -#endif /* defined(CONFIG_BT_MESH_PROVISIONER) && CONFIG_BT_MESH_PROVISIONER */ +#endif /* defined(CONFIG_BLE_MESH_PROVISIONER) && CONFIG_BLE_MESH_PROVISIONER */ -static void ble_mesh_scan_results_change_2_bta(tBTM_INQ_RESULTS *p_inq, u8_t *p_eir, tBTA_DM_SEARCH_CBACK *p_scan_cback) +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 result; tBTM_INQ_INFO *p_inq_info; + tBTA_DM_SEARCH result; bdcpy(result.inq_res.bd_addr, p_inq->remote_bd_addr); result.inq_res.rssi = p_inq->rssi; @@ -143,23 +135,16 @@ static void ble_mesh_scan_results_change_2_bta(tBTM_INQ_RESULTS *p_inq, u8_t *p_ } } -static void ble_mesh_scan_results_cb(tBTM_INQ_RESULTS *p_inq, u8_t *p_eir) +static void bt_mesh_scan_results_cb(tBTM_INQ_RESULTS *p_inq, u8_t *p_eir) { - ble_mesh_scan_results_change_2_bta(p_inq, p_eir, bt_mesh_scan_result_callback); + bt_mesh_scan_results_change_2_bta(p_inq, p_eir, bt_mesh_scan_result_callback); } -static bool valid_adv_param(const struct bt_le_adv_param *param) +static bool valid_adv_param(const struct bt_mesh_adv_param *param) { - if (!(param->options & BT_LE_ADV_OPT_CONNECTABLE)) { - /* - * BT Core 4.2 [Vol 2, Part E, 7.8.5] - * The Advertising_Interval_Min and Advertising_Interval_Max - * shall not be set to less than 0x00A0 (100 ms) if the - * Advertising_Type is set to ADV_SCAN_IND or ADV_NONCONN_IND. - */ -#if BT_DEV - /**TODO: Need to optimize controller to make it supports 20ms interval */ - if (bt_dev.hci_version < BT_HCI_VERSION_5_0 && + if (!(param->options & BLE_MESH_ADV_OPT_CONNECTABLE)) { +#if BLE_MESH_DEV + if (bt_mesh_dev.hci_version < BLE_MESH_HCI_VERSION_5_0 && param->interval_min < 0x00a0) { return false; } @@ -174,73 +159,56 @@ static bool valid_adv_param(const struct bt_le_adv_param *param) return true; } -static int set_ad(u16_t hci_op, const struct bt_data *ad, size_t ad_len) +static int set_adv_data(u16_t hci_op, const struct bt_mesh_adv_data *ad, size_t ad_len) { - struct bt_hci_cp_le_set_adv_data set_data_param; - struct bt_hci_cp_le_set_adv_data *set_data = &set_data_param; + struct bt_mesh_hci_cp_set_adv_data param = {0}; int i; -#if 0 - struct net_buf *buf; - buf = bt_hci_cmd_create(hci_op, sizeof(*set_data)); - if (!buf) { - return -ENOBUFS; + if (ad == NULL || ad_len == 0) { + return 0; } -#endif - - memset(set_data, 0, sizeof(*set_data)); for (i = 0; i < ad_len; i++) { /* Check if ad fit in the remaining buffer */ - if (set_data->len + ad[i].data_len + 2 > 31) { -#if 0 - net_buf_unref(buf); -#endif + if (param.len + ad[i].data_len + 2 > 31) { return -EINVAL; } - set_data->data[set_data->len++] = ad[i].data_len + 1; - set_data->data[set_data->len++] = ad[i].type; + param.data[param.len++] = ad[i].data_len + 1; + param.data[param.len++] = ad[i].type; - memcpy(&set_data->data[set_data->len], ad[i].data, ad[i].data_len); - set_data->len += ad[i].data_len; + memcpy(¶m.data[param.len], ad[i].data, ad[i].data_len); + param.len += ad[i].data_len; } - /* Set adv data and scan rsp data, TODO: how to process null adv data? - * Do we need to set adv data every time even though the adv data is not changed? - */ - -#if 0 - return bt_hci_cmd_send_sync(hci_op, buf, NULL); -#else - if (hci_op == BT_HCI_OP_LE_SET_ADV_DATA) { - BLE_MESH_BTM_CHECK_STATUS(BTM_BleWriteAdvDataRaw(set_data->data, set_data->len)); - } else if (hci_op == BT_HCI_OP_LE_SET_SCAN_RSP_DATA) { - BLE_MESH_BTM_CHECK_STATUS(BTM_BleWriteScanRspRaw(set_data->data, set_data->len)); + /* Set adv data and scan rsp data. */ + if (hci_op == BLE_MESH_HCI_OP_SET_ADV_DATA) { + BLE_MESH_BTM_CHECK_STATUS(BTM_BleWriteAdvDataRaw(param.data, param.len)); + } else if (hci_op == BLE_MESH_HCI_OP_SET_SCAN_RSP_DATA) { + BLE_MESH_BTM_CHECK_STATUS(BTM_BleWriteScanRspRaw(param.data, param.len)); } + return 0; -#endif /* #if 0 */ } static void start_adv_completed_cb(u8_t status) { - /**TODO: It is too late to wait for completed event*/ -#if 0 +#if BLE_MESH_DEV if (!status) { - atomic_set_bit(bt_dev.flags, BT_DEV_ADVERTISING); + bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING); } #endif } -static bool valid_le_scan_param(const struct bt_le_scan_param *param) +static bool valid_scan_param(const struct bt_mesh_scan_param *param) { - if (param->type != BT_HCI_LE_SCAN_PASSIVE && - param->type != BT_HCI_LE_SCAN_ACTIVE) { + if (param->type != BLE_MESH_SCAN_PASSIVE && + param->type != BLE_MESH_SCAN_ACTIVE) { return false; } - if (param->filter_dup != BT_HCI_LE_SCAN_FILTER_DUP_DISABLE && - param->filter_dup != BT_HCI_LE_SCAN_FILTER_DUP_ENABLE) { + if (param->filter_dup != BLE_MESH_SCAN_FILTER_DUP_DISABLE && + param->filter_dup != BLE_MESH_SCAN_FILTER_DUP_ENABLE) { return false; } @@ -261,110 +229,44 @@ static bool valid_le_scan_param(const struct bt_le_scan_param *param) static int start_le_scan(u8_t scan_type, u16_t interval, u16_t window, u8_t filter_dup) { - int err = 0; + UINT8 scan_fil_policy = BLE_MESH_SP_ADV_ALL; /* No whitelist for BLE Mesh */ + UINT8 addr_type_own = BLE_MESH_ADDR_PUBLIC; /* Currently only support Public Address */ + tGATT_IF client_if = 0xFF; /* Default GATT interface id */ -#if 0 - struct bt_hci_cp_le_set_scan_param set_param; - struct net_buf *buf; - memset(&set_param, 0, sizeof(set_param)); + BLE_MESH_BTM_CHECK_STATUS( + BTM_BleSetScanFilterParams(client_if, interval, window, scan_type, addr_type_own, + filter_dup, scan_fil_policy, NULL)); - set_param.scan_type = scan_type; - /* for the rest parameters apply default values according to - * spec 4.2, vol2, part E, 7.8.10 - */ - set_param.interval = sys_cpu_to_le16(interval); - set_param.window = sys_cpu_to_le16(window); - set_param.filter_policy = 0x00; -#endif - - /* TODO: Currently support only RPA and set only once before scan */ -#if 0 - if (IS_ENABLED(CONFIG_BT_PRIVACY)) { - err = le_set_private_addr(); - if (err) { - return err; - } - - if (BT_FEAT_LE_PRIVACY(bt_dev.le.features)) { - set_param.addr_type = BT_HCI_OWN_ADDR_RPA_OR_RANDOM; - } else { - set_param.addr_type = BT_ADDR_LE_RANDOM; - } - } else { - set_param.addr_type = bt_dev.id_addr.type; - - /* Use NRPA unless identity has been explicitly requested - * (through Kconfig), or if there is no advertising ongoing. - */ - if (!IS_ENABLED(CONFIG_BT_SCAN_WITH_IDENTITY) && - scan_type == BT_HCI_LE_SCAN_ACTIVE && - !atomic_test_bit(bt_dev.flags, BT_DEV_ADVERTISING)) { - err = le_set_private_addr(); - if (err) { - return err; - } - - set_param.addr_type = BT_ADDR_LE_RANDOM; - } - } -#endif - -#if 0 - buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_SCAN_PARAM, sizeof(set_param)); - if (!buf) { - return -ENOBUFS; - } - - net_buf_add_mem(buf, &set_param, sizeof(set_param)); - - bt_hci_cmd_send(BT_HCI_OP_LE_SET_SCAN_PARAM, buf); - - err = set_le_scan_enable(BT_HCI_LE_SCAN_ENABLE); - if (err) { - return err; - } -#else - tGATT_IF client_if = 0xFF; //default GATT interface id - UINT8 scan_fil_policy = 0x00; //No white-list for mesh - UINT8 addr_type_own = 0x0; //TODO: currently support only RPA - - /*TODO: Need to process scan_param_setup_cback - * Need to add menuconfig for duplicate scan*/ - BTM_BleSetScanFilterParams(client_if, interval, window, scan_type, addr_type_own, - filter_dup, scan_fil_policy, NULL); - - /*TODO: Need to process p_start_stop_scan_cb to check if start successfully */ /* BLE Mesh scan permanently, so no duration of scan here */ - BLE_MESH_BTM_CHECK_STATUS(BTM_BleScan(true, 0, ble_mesh_scan_results_cb, NULL, NULL)); -#endif /* #if 0 */ + BLE_MESH_BTM_CHECK_STATUS(BTM_BleScan(true, 0, bt_mesh_scan_results_cb, NULL, NULL)); -#if BT_DEV - if (scan_type == BT_HCI_LE_SCAN_ACTIVE) { - atomic_set_bit(bt_dev.flags, BT_DEV_ACTIVE_SCAN); +#if BLE_MESH_DEV + if (scan_type == BLE_MESH_SCAN_ACTIVE) { + bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ACTIVE_SCAN); } else { - atomic_clear_bit(bt_dev.flags, BT_DEV_ACTIVE_SCAN); + bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ACTIVE_SCAN); } #endif - return err; + return 0; } static void bt_mesh_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data) { - bt_addr_le_t addr; - UINT8 rssi; + bt_mesh_addr_t addr = {0}; UINT8 adv_type; + UINT8 rssi; BT_DBG("%s, event = %d", __func__, event); if (event == BTA_DM_INQ_RES_EVT) { - /* TODO: How to process scan_rsp here? */ + /* TODO: How to process scan response here? */ addr.type = p_data->inq_res.ble_addr_type; - memcpy(addr.a.val, p_data->inq_res.bd_addr, BD_ADDR_LEN); + memcpy(addr.val, p_data->inq_res.bd_addr, BLE_MESH_ADDR_LEN); rssi = p_data->inq_res.rssi; adv_type = p_data->inq_res.ble_evt_type; - //scan rsp len: p_data->inq_res.scan_rsp_len + /* 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__); @@ -384,101 +286,33 @@ static void bt_mesh_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARC } } -int bt_le_scan_update(bool fast_scan) -{ -#if BT_DEV - if (atomic_test_bit(bt_dev.flags, BT_DEV_EXPLICIT_SCAN)) { - return 0; - } -#endif /* #if BT_DEV */ - -#if BT_DEV - if (atomic_test_bit(bt_dev.flags, BT_DEV_SCANNING)) { -#else /* #if BT_DEV */ - if (1) { -#endif /* #if BT_DEV */ -#if 0 - int err = set_le_scan_enable(BT_HCI_LE_SCAN_DISABLE); - if (err) { - return err; - } -#else /* #if 0 */ - /* TODO: need to process stop_scan_cb */ -#if BT_DEV - atomic_clear_bit(bt_dev.flags, BT_DEV_SCANNING); -#endif - BLE_MESH_BTM_CHECK_STATUS(BTM_BleScan(false, 0, NULL, NULL, NULL)); -#endif /* #if 0 */ - } - - /* We don't need to stay pasive scan for central device */ -#if 0 - if (IS_ENABLED(CONFIG_BT_CENTRAL)) { - u16_t interval, window; - struct bt_conn *conn; - - conn = bt_conn_lookup_state_le(NULL, BT_CONN_CONNECT_SCAN); - if (!conn) { - return 0; - } - - atomic_set_bit(bt_dev.flags, BT_DEV_SCAN_FILTER_DUP); - - bt_mesh_conn_unref(conn); - - if (fast_scan) { - interval = BT_GAP_SCAN_FAST_INTERVAL; - window = BT_GAP_SCAN_FAST_WINDOW; - } else { - interval = BT_GAP_SCAN_SLOW_INTERVAL_1; - window = BT_GAP_SCAN_SLOW_WINDOW_1; - } - - return start_le_scan(BT_HCI_LE_SCAN_PASSIVE, interval, window); - } -#endif /* #if 0 */ - - return 0; -} - /* APIs functions */ -int bt_le_adv_start(const struct bt_le_adv_param *param, - const struct bt_data *ad, size_t ad_len, - const struct bt_data *sd, size_t sd_len) +int bt_le_adv_start(const struct bt_mesh_adv_param *param, + const struct bt_mesh_adv_data *ad, size_t ad_len, + const struct bt_mesh_adv_data *sd, size_t sd_len) { - /** TODO: - *- Need to support 20ms interval in 4.2 - *- Need to check adv start HCI event - *- Random address check, currently we set privacy only once in application - *- Process ADV_OPT_ONE_TIME - **/ - UINT16 adv_int_min; - UINT16 adv_int_max; - tBLE_ADDR_TYPE addr_type_own; - UINT8 adv_type; - tBTM_BLE_ADV_CHNL_MAP chnl_map; - tBTM_BLE_AFP adv_fil_pol; - tBLE_BD_ADDR p_dir_bda; tBTA_START_ADV_CMPL_CBACK *p_start_adv_cb; + tBTM_BLE_ADV_CHNL_MAP channel_map; + tBLE_ADDR_TYPE addr_type_own; + tBLE_BD_ADDR p_dir_bda = {0}; + tBTM_BLE_AFP adv_fil_pol; + UINT8 adv_type; + int err; - struct bt_hci_cp_le_set_adv_param set_param; - int err = 0; +#if BLE_MESH_DEV + if (bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING)) { + return -EALREADY; + } +#endif if (!valid_adv_param(param)) { + BT_ERR("%s, Invalid adv parameters", __func__); return -EINVAL; } -#if BT_DEV -#if 0 - /**TODO: We cancel this check temporarily*/ - if (atomic_test_bit(bt_dev.flags, BT_DEV_ADVERTISING)) { - return -EALREADY; - } -#endif /* #if 0 */ -#endif /* #if BT_DEV */ - - err = set_ad(BT_HCI_OP_LE_SET_ADV_DATA, ad, ad_len); + 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__); return err; } @@ -488,248 +322,100 @@ int bt_le_adv_start(const struct bt_le_adv_param *param, * * If sd was not provided but we enable connectable undirected * advertising sd needs to be cleared from values set by previous calls. - * Clearing sd is done by calling set_ad() with NULL data and zero len. + * Clearing sd is done by calling set_adv_data() with NULL data and zero len. * So following condition check is unusual but correct. */ - if (sd || (param->options & BT_LE_ADV_OPT_CONNECTABLE)) { - err = set_ad(BT_HCI_OP_LE_SET_SCAN_RSP_DATA, sd, sd_len); + 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__); return err; } } - memset(&set_param, 0, sizeof(set_param)); - - set_param.min_interval = sys_cpu_to_le16(param->interval_min); - set_param.max_interval = sys_cpu_to_le16(param->interval_max); - set_param.channel_map = 0x07; - - /** TODO: Currently we support only RPA address */ -#if 0 - if (param->options & BT_LE_ADV_OPT_CONNECTABLE) { - if (IS_ENABLED(CONFIG_BT_PRIVACY)) { - err = le_set_private_addr(); - if (err) { - return err; - } - - if (BT_FEAT_LE_PRIVACY(bt_dev.le.features)) { - set_param.own_addr_type = - BT_HCI_OWN_ADDR_RPA_OR_RANDOM; - } else { - set_param.own_addr_type = BT_ADDR_LE_RANDOM; - } - } else { - /* - * If Static Random address is used as Identity - * address we need to restore it before advertising - * is enabled. Otherwise NRPA used for active scan - * could be used for advertising. - */ - if (atomic_test_bit(bt_dev.flags, - BT_DEV_ID_STATIC_RANDOM)) { - set_random_address(&bt_dev.id_addr.a); - } - - set_param.own_addr_type = bt_dev.id_addr.type; - } - - set_param.type = BT_LE_ADV_IND; - } else { - if (param->own_addr) { - /* Only NRPA is allowed */ - if (!BT_ADDR_IS_NRPA(param->own_addr)) { - return -EINVAL; - } - - err = set_random_address(param->own_addr); - } else { - err = le_set_private_addr(); - } - - if (err) { - return err; - } - - set_param.own_addr_type = BT_ADDR_LE_RANDOM; - - if (sd) { - set_param.type = BT_LE_ADV_SCAN_IND; - } else { - set_param.type = BT_LE_ADV_NONCONN_IND; - } - } -#else /* #if 0 */ - /* TODO: Has been simplified here, currently support only RPA addr */ - set_param.own_addr_type = 0x0; //BT_ADDR_LE_RANDOM - if (param->options & BT_LE_ADV_OPT_CONNECTABLE) { - set_param.type = 0x00; //ADV_TYPE_IND; + if (param->options & BLE_MESH_ADV_OPT_CONNECTABLE) { + adv_type = BLE_MESH_ADV_IND; } else if (sd != NULL) { - set_param.type = 0x02; //ADV_TYPE_SCAN_IND; + adv_type = BLE_MESH_ADV_SCAN_IND; } else { - set_param.type = 0x03; //ADV_TYPE_NONCONN_IND; + adv_type = BLE_MESH_ADV_NONCONN_IND; } -#endif /* #if 0 */ - -#if 0 - buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_ADV_PARAM, sizeof(set_param)); - if (!buf) { - return -ENOBUFS; - } - - net_buf_add_mem(buf, &set_param, sizeof(set_param)); - - err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_SET_ADV_PARAM, buf, NULL); - if (err) { - return err; - } - - err = set_advertise_enable(true); - if (err) { - return err; - } -#else /* #if 0 */ - addr_type_own = set_param.own_addr_type; - /* Set adv parameters */ - adv_int_min = param->interval_min; - adv_int_max = param->interval_max; - adv_type = set_param.type; - chnl_map = BTA_BLE_ADV_CHNL_37 | BTA_BLE_ADV_CHNL_38 | BTA_BLE_ADV_CHNL_39; - adv_fil_pol = AP_SCAN_CONN_ALL; - memset(&p_dir_bda, 0, sizeof(p_dir_bda)); + addr_type_own = BLE_MESH_ADDR_PUBLIC; /* Currently only support Public Address */ + channel_map = BLE_MESH_ADV_CHNL_37 | BLE_MESH_ADV_CHNL_38 | BLE_MESH_ADV_CHNL_39; + adv_fil_pol = BLE_MESH_AP_SCAN_CONN_ALL; p_start_adv_cb = start_adv_completed_cb; - /* TODO: We need to add a check function, to make sure adv start successfully and then set bit - * So currently we call BTM_BleSetAdvParamsStartAdv instead of BTA_DmSetBleAdvParamsAll - */ -#if 1 /* Check if we can start adv using BTM_BleSetAdvParamsStartAdvCheck */ - BLE_MESH_BTM_CHECK_STATUS(BTM_BleSetAdvParamsAll(adv_int_min, adv_int_max, adv_type, - addr_type_own, &p_dir_bda, - chnl_map, adv_fil_pol, p_start_adv_cb)); + BLE_MESH_BTM_CHECK_STATUS( + BTM_BleSetAdvParamsAll(param->interval_min, param->interval_max, adv_type, + addr_type_own, &p_dir_bda, + channel_map, adv_fil_pol, p_start_adv_cb)); BLE_MESH_BTM_CHECK_STATUS(BTM_BleStartAdv()); -#if BT_DEV - atomic_set_bit(bt_dev.flags, BT_DEV_ADVERTISING); -#endif /* #if BT_DEV */ -#else /* #if 1 */ - status = BTM_BleSetAdvParamsStartAdv (adv_int_min, adv_int_max, adv_type, addr_type_own, &p_dir_bda, chnl_map, adv_fil_pol, p_start_adv_cb); - if (!status) { - atomic_set_bit(bt_dev.flags, BT_DEV_ADVERTISING); - } -#endif /* #if 1 */ -#endif /* #if 0 */ - /** TODO: To implement BT_LE_ADV_OPT_ONE_TIME */ -#if BT_DEV - if (!(param->options & BT_LE_ADV_OPT_ONE_TIME)) { - atomic_set_bit(bt_dev.flags, BT_DEV_KEEP_ADVERTISING); - } -#endif /* #if BT_DEV */ +#if BLE_MESH_DEV + bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING); - return err; + if (!(param->options & BLE_MESH_ADV_OPT_ONE_TIME)) { + bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_KEEP_ADVERTISING); + } +#endif + + return 0; } int bt_le_adv_stop(void) { - int err = 0; UINT8 status; - /* Make sure advertising is not re-enabled later even if it's not - * currently enabled (i.e. BT_DEV_ADVERTISING is not set). - */ -#if BT_DEV - atomic_clear_bit(bt_dev.flags, BT_DEV_KEEP_ADVERTISING); - -#if 0 - /**TODO: We cancel this check temporarily*/ - if (!atomic_test_bit(bt_dev.flags, BT_DEV_ADVERTISING)) { +#if BLE_MESH_DEV + bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_KEEP_ADVERTISING); + if (!bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING)) { return 0; } -#endif /* #if 0 */ -#endif /* #if BT_DEV */ +#endif -#if 0 - err = set_advertise_enable(false); - if (err) { - return err; - } -#else - /*TODO: We need to add a check function, to make sure adv start successfully and then set bit - * So currently we use BTM_BleBroadcast instead of BTA_DmBleBroadcast*/ status = BTM_BleBroadcast(false, NULL); if ((status != BTM_SUCCESS) && (status != BTM_CMD_STARTED)) { - BT_ERR("%s, invalid status %d", __func__, status); -#if BT_DEV - atomic_clear_bit(bt_dev.flags, BT_DEV_ADVERTISING); -#endif + BT_ERR("%s, Invalid status %d", __func__, status); return -1; } -#endif /* #if 0 */ -#if 0 - /* TODO: Currently support RPA only */ - if (!IS_ENABLED(CONFIG_BT_PRIVACY)) { - /* If active scan is ongoing set NRPA */ - if (atomic_test_bit(bt_dev.flags, BT_DEV_SCANNING) && - atomic_test_bit(bt_dev.flags, BT_DEV_ACTIVE_SCAN)) { - le_set_private_addr(); - } - } +#if BLE_MESH_DEV + bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING); #endif - return err; + return 0; } -int bt_le_scan_start(const struct bt_le_scan_param *param, bt_le_scan_cb_t cb) +int bt_le_scan_start(const struct bt_mesh_scan_param *param, bt_mesh_scan_cb_t cb) { - /* TODO: - * Do we need to use duplicate mode for mesh scan? - */ - int err = 0; + int err; - /* Check that the parameters have valid values */ - if (!valid_le_scan_param(param)) { - return -EINVAL; - } - - /* Return if active scan is already enabled */ -#if BT_DEV - if (atomic_test_and_set_bit(bt_dev.flags, BT_DEV_EXPLICIT_SCAN)) { +#if BLE_MESH_DEV + if (bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) { return -EALREADY; } #endif - /* TODO: Currently we use bluedroid APIs, which will stop scan automatically - * while setting parameters. - */ -#if 0 - if (atomic_test_bit(bt_dev.flags, BT_DEV_SCANNING)) { - err = set_le_scan_enable(BT_HCI_LE_SCAN_DISABLE); - if (err) { - atomic_clear_bit(bt_dev.flags, BT_DEV_EXPLICIT_SCAN); - return err; - } + if (!valid_scan_param(param)) { + return -EINVAL; } -#endif -#if BT_DEV +#if BLE_MESH_DEV if (param->filter_dup) { - atomic_set_bit(bt_dev.flags, BT_DEV_SCAN_FILTER_DUP); + bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCAN_FILTER_DUP); } else { - atomic_clear_bit(bt_dev.flags, BT_DEV_SCAN_FILTER_DUP); + bt_mesh_atomic_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCAN_FILTER_DUP); } #endif err = start_le_scan(param->type, param->interval, param->window, param->filter_dup); if (err) { -#if BT_DEV - atomic_clear_bit(bt_dev.flags, BT_DEV_EXPLICIT_SCAN); -#endif return err; } -#if BT_DEV - atomic_set_bit(bt_dev.flags, BT_DEV_SCANNING); +#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; @@ -738,19 +424,20 @@ int bt_le_scan_start(const struct bt_le_scan_param *param, bt_le_scan_cb_t cb) int bt_le_scan_stop(void) { - /* Return if active scanning is already disabled */ -#if BT_DEV - if (!atomic_test_and_clear_bit(bt_dev.flags, BT_DEV_EXPLICIT_SCAN)) { - return -EALREADY; +#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)); } +#else + BLE_MESH_BTM_CHECK_STATUS(BTM_BleScan(false, 0, NULL, NULL, NULL)); #endif bt_mesh_scan_dev_found_cb = NULL; - - return bt_le_scan_update(false); + return 0; } -#if defined(CONFIG_BT_MESH_NODE) && CONFIG_BT_MESH_NODE +#if defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE static void bt_mesh_bta_gatts_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) { switch (event) { @@ -760,43 +447,47 @@ static void bt_mesh_bta_gatts_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) } break; case BTA_GATTS_READ_EVT: { + struct bt_mesh_gatt_attr *attr = bt_mesh_gatts_find_attr_by_handle(p_data->req_data.p_data->read_req.handle); + u8_t index = BLE_MESH_GATT_GET_CONN_ID(p_data->req_data.conn_id); + tBTA_GATTS_RSP rsp; u8_t buf[100] = {0}; u16_t len = 0; - tBTA_GATTS_RSP rsp; + BT_DBG("%s, read: handle = %d", __func__, p_data->req_data.p_data->read_req.handle); - u8_t index = BT_MESH_GATT_GET_CONN_ID(p_data->req_data.conn_id); - struct bt_gatt_attr *mesh_attr = bt_mesh_gatts_find_attr_by_handle(p_data->req_data.p_data->read_req.handle); - if (mesh_attr != NULL && mesh_attr->read != NULL) { - if ((len = mesh_attr->read(&bt_mesh_gatts_conn[index], mesh_attr, buf, 100, - p_data->req_data.p_data->read_req.offset)) > 0) { + + if (attr != NULL && attr->read != NULL) { + if ((len = attr->read(&bt_mesh_gatts_conn[index], attr, buf, 100, + p_data->req_data.p_data->read_req.offset)) > 0) { rsp.attr_value.handle = p_data->req_data.p_data->read_req.handle; rsp.attr_value.len = len; 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 mesh read rsp, handle = %x", __func__, mesh_attr->handle); + BT_DBG("%s, Send gatts read response, handle = %x", __func__, attr->handle); } else { - BT_WARN("%s, read perm Invalid", __func__); + BT_WARN("%s, BLE Mesh gatts read failed", __func__); } } break; } case BTA_GATTS_WRITE_EVT: { + struct bt_mesh_gatt_attr *attr = bt_mesh_gatts_find_attr_by_handle(p_data->req_data.p_data->write_req.handle); + 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, 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)); - u8_t index = BT_MESH_GATT_GET_CONN_ID(p_data->req_data.conn_id); - struct bt_gatt_attr *mesh_attr = bt_mesh_gatts_find_attr_by_handle(p_data->req_data.p_data->write_req.handle); - if (mesh_attr != NULL && mesh_attr->write != NULL) { - if ((len = mesh_attr->write(&bt_mesh_gatts_conn[index], mesh_attr, - p_data->req_data.p_data->write_req.value, - p_data->req_data.p_data->write_req.len, - p_data->req_data.p_data->write_req.offset, 0)) > 0) { + + if (attr != NULL && attr->write != NULL) { + if ((len = attr->write(&bt_mesh_gatts_conn[index], attr, + p_data->req_data.p_data->write_req.value, + p_data->req_data.p_data->write_req.len, + p_data->req_data.p_data->write_req.offset, 0)) > 0) { 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__, mesh_attr->handle); + BT_DBG("%s, send mesh write rsp, handle = %x", __func__, attr->handle); } } } @@ -808,14 +499,13 @@ static void bt_mesh_bta_gatts_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) break; case BTA_GATTS_CONF_EVT: break; - case BTA_GATTS_CREATE_EVT: { + 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); if (future_mesh != NULL) { future_ready(future_mesh, FUTURE_SUCCESS); } break; - } case BTA_GATTS_ADD_INCL_SRVC_EVT: svc_handle = p_data->add_result.attr_id; if (future_mesh != NULL) { @@ -841,12 +531,14 @@ static void bt_mesh_bta_gatts_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) case BTA_GATTS_STOP_EVT: break; case BTA_GATTS_CONNECT_EVT: - /*Adv disabled*/ - // atomic_clear_bit(bt_dev.flags, BT_DEV_ADVERTISING); +#if BLE_MESH_DEV + /* When connection is created, advertising will be stopped automatically. */ + bt_mesh_atomic_test_and_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING); +#endif if (bt_mesh_gatts_conn_cb != NULL && bt_mesh_gatts_conn_cb->connected != NULL) { - u8_t index = BT_MESH_GATT_GET_CONN_ID(p_data->conn.conn_id); + u8_t index = BLE_MESH_GATT_GET_CONN_ID(p_data->conn.conn_id); if (index < CONFIG_BT_MAX_CONN) { - bt_mesh_gatts_conn[index].handle = BT_MESH_GATT_GET_CONN_ID(p_data->conn.conn_id); + bt_mesh_gatts_conn[index].handle = BLE_MESH_GATT_GET_CONN_ID(p_data->conn.conn_id); (bt_mesh_gatts_conn_cb->connected)(&bt_mesh_gatts_conn[index], 0); } /* Send GATT service change indication */ @@ -854,12 +546,13 @@ static void bt_mesh_bta_gatts_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) } break; case BTA_GATTS_DISCONNECT_EVT: - /*Adv disabled*/ - // atomic_clear_bit(bt_dev.flags, BT_DEV_ADVERTISING); +#if BLE_MESH_DEV + bt_mesh_atomic_test_and_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_ADVERTISING); +#endif if (bt_mesh_gatts_conn_cb != NULL && bt_mesh_gatts_conn_cb->disconnected != NULL) { - u8_t index = BT_MESH_GATT_GET_CONN_ID(p_data->conn.conn_id); + u8_t index = BLE_MESH_GATT_GET_CONN_ID(p_data->conn.conn_id); if (index < CONFIG_BT_MAX_CONN) { - bt_mesh_gatts_conn[index].handle = BT_MESH_GATT_GET_CONN_ID(p_data->conn.conn_id); + bt_mesh_gatts_conn[index].handle = BLE_MESH_GATT_GET_CONN_ID(p_data->conn.conn_id); (bt_mesh_gatts_conn_cb->disconnected)(&bt_mesh_gatts_conn[index], p_data->conn.reason); } } @@ -871,15 +564,16 @@ static void bt_mesh_bta_gatts_cb(tBTA_GATTS_EVT event, tBTA_GATTS *p_data) } } -void bt_mesh_gatts_conn_cb_register(struct bt_conn_cb *cb) +void bt_mesh_gatts_conn_cb_register(struct bt_mesh_conn_cb *cb) { bt_mesh_gatts_conn_cb = cb; } -static struct bt_gatt_attr *bt_mesh_gatts_find_attr_by_handle(u16_t handle) +static struct bt_mesh_gatt_attr *bt_mesh_gatts_find_attr_by_handle(u16_t handle) { - struct bt_gatt_service *svc; - struct bt_gatt_attr *attr = NULL; + struct bt_mesh_gatt_service *svc = NULL; + struct bt_mesh_gatt_attr *attr = NULL; + SYS_SLIST_FOR_EACH_CONTAINER(&bt_mesh_gatts_db, svc, node) { int i; @@ -896,15 +590,15 @@ static struct bt_gatt_attr *bt_mesh_gatts_find_attr_by_handle(u16_t handle) } static void bt_mesh_gatts_foreach_attr(u16_t start_handle, u16_t end_handle, - bt_gatt_attr_func_t func, void *user_data) + bt_mesh_gatt_attr_func_t func, void *user_data) { - struct bt_gatt_service *svc; + struct bt_mesh_gatt_service *svc = NULL; SYS_SLIST_FOR_EACH_CONTAINER(&bt_mesh_gatts_db, svc, node) { int i; for (i = 0; i < svc->attr_count; i++) { - struct bt_gatt_attr *attr = &svc->attrs[i]; + struct bt_mesh_gatt_attr *attr = &svc->attrs[i]; /* Check if attribute handle is within range */ if (attr->handle < start_handle || @@ -912,42 +606,42 @@ static void bt_mesh_gatts_foreach_attr(u16_t start_handle, u16_t end_handle, continue; } - if (func(attr, user_data) == BT_GATT_ITER_STOP) { + if (func(attr, user_data) == BLE_MESH_GATT_ITER_STOP) { return; } } } } -static u8_t find_next(const struct bt_gatt_attr *attr, void *user_data) +static u8_t find_next(const struct bt_mesh_gatt_attr *attr, void *user_data) { - struct bt_gatt_attr **next = user_data; + struct bt_mesh_gatt_attr **next = user_data; - *next = (struct bt_gatt_attr *)attr; + *next = (struct bt_mesh_gatt_attr *)attr; - return BT_GATT_ITER_STOP; + return BLE_MESH_GATT_ITER_STOP; } -static struct bt_gatt_attr *bt_mesh_gatts_attr_next(const struct bt_gatt_attr *attr) +static struct bt_mesh_gatt_attr *bt_mesh_gatts_attr_next(const struct bt_mesh_gatt_attr *attr) { - struct bt_gatt_attr *next = NULL; + struct bt_mesh_gatt_attr *next = NULL; bt_mesh_gatts_foreach_attr(attr->handle + 1, attr->handle + 1, find_next, &next); return next; } -ssize_t bt_mesh_gatts_attr_read(struct bt_conn *conn, const struct bt_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) { u16_t len; if (offset > value_len) { - return BT_GATT_ERR(BT_ATT_ERR_INVALID_OFFSET); + return BLE_MESH_GATT_ERR(BLE_MESH_ATT_ERR_INVALID_OFFSET); } - len = min(buf_len, value_len - offset); + len = MIN(buf_len, value_len - offset); BT_DBG("handle 0x%04x offset %u length %u", attr->handle, offset, len); @@ -962,53 +656,49 @@ struct gatts_incl { u16_t uuid16; } __packed; -ssize_t bt_mesh_gatts_attr_read_included(struct bt_conn *conn, - const struct bt_gatt_attr *attr, +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) { - struct bt_gatt_attr *incl = attr->user_data; - struct bt_uuid *uuid = incl->user_data; - struct gatts_incl pdu; + struct bt_mesh_gatt_attr *incl = attr->user_data; + struct bt_mesh_uuid *uuid = incl->user_data; + struct gatts_incl pdu = {0}; u8_t value_len; - /* first attr points to the start handle */ + /* First attr points to the start handle */ pdu.start_handle = sys_cpu_to_le16(incl->handle); value_len = sizeof(pdu.start_handle) + sizeof(pdu.end_handle); /* * Core 4.2, Vol 3, Part G, 3.2, - * The Service UUID shall only be present when the UUID is a - * 16-bit Bluetooth UUID. + * The Service UUID shall only be present when the UUID is a 16-bit Bluetooth UUID. */ - if (uuid->type == BT_UUID_TYPE_16) { - pdu.uuid16 = sys_cpu_to_le16(BT_UUID_16(uuid)->val); + if (uuid->type == BLE_MESH_UUID_TYPE_16) { + pdu.uuid16 = sys_cpu_to_le16(BLE_MESH_UUID_16(uuid)->val); value_len += sizeof(pdu.uuid16); } - /* Lookup for service end handle */ - //bt_mesh_gatts_foreach_attr(incl->handle + 1, 0xffff, get_service_handles, &pdu); - return bt_mesh_gatts_attr_read(conn, attr, buf, len, offset, &pdu, value_len); } -ssize_t bt_mesh_gatts_attr_read_service(struct bt_conn *conn, - const struct bt_gatt_attr *attr, +ssize_t bt_mesh_gatts_attr_read_service(struct bt_mesh_conn *conn, + const struct bt_mesh_gatt_attr *attr, void *buf, u16_t len, u16_t offset) { - struct bt_uuid *uuid = attr->user_data; + struct bt_mesh_uuid *uuid = attr->user_data; - if (uuid->type == BT_UUID_TYPE_16) { - u16_t uuid16 = sys_cpu_to_le16(BT_UUID_16(uuid)->val); + if (uuid->type == BLE_MESH_UUID_TYPE_16) { + u16_t uuid16 = sys_cpu_to_le16(BLE_MESH_UUID_16(uuid)->val); return bt_mesh_gatts_attr_read(conn, attr, buf, len, offset, &uuid16, 2); } return bt_mesh_gatts_attr_read(conn, attr, buf, len, offset, - BT_UUID_128(uuid)->val, 16); + BLE_MESH_UUID_128(uuid)->val, 16); } struct gatts_chrc { - u8_t properties; + u8_t properties; u16_t value_handle; union { u16_t uuid16; @@ -1016,13 +706,13 @@ struct gatts_chrc { }; } __packed; -ssize_t bt_mesh_gatts_attr_read_chrc(struct bt_conn *conn, - const struct bt_gatt_attr *attr, void *buf, +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) { - struct bt_gatt_chrc *chrc = attr->user_data; - struct gatts_chrc pdu; - const struct bt_gatt_attr *next; + struct bt_mesh_gatt_char *chrc = attr->user_data; + const struct bt_mesh_gatt_attr *next = NULL; + struct gatts_chrc pdu = {0}; u8_t value_len; pdu.properties = chrc->properties; @@ -1035,37 +725,37 @@ ssize_t bt_mesh_gatts_attr_read_chrc(struct bt_conn *conn, */ next = bt_mesh_gatts_attr_next(attr); if (!next) { - BT_WARN("No value for characteristic at 0x%04x", attr->handle); + BT_WARN("%s, No value for characteristic at 0x%04x", __func__, attr->handle); pdu.value_handle = 0x0000; } else { pdu.value_handle = sys_cpu_to_le16(next->handle); } value_len = sizeof(pdu.properties) + sizeof(pdu.value_handle); - if (chrc->uuid->type == BT_UUID_TYPE_16) { - pdu.uuid16 = sys_cpu_to_le16(BT_UUID_16(chrc->uuid)->val); + if (chrc->uuid->type == BLE_MESH_UUID_TYPE_16) { + pdu.uuid16 = sys_cpu_to_le16(BLE_MESH_UUID_16(chrc->uuid)->val); value_len += 2; } else { - memcpy(pdu.uuid, BT_UUID_128(chrc->uuid)->val, 16); + memcpy(pdu.uuid, BLE_MESH_UUID_128(chrc->uuid)->val, 16); value_len += 16; } return bt_mesh_gatts_attr_read(conn, attr, buf, len, offset, &pdu, value_len); } -static void bta_uuid_to_mesh_uuid(tBT_UUID *bta_uuid, const struct bt_uuid *uuid) +static void bta_uuid_to_bt_mesh_uuid(tBT_UUID *bta_uuid, const struct bt_mesh_uuid *uuid) { assert(uuid != NULL && bta_uuid != NULL); - if (uuid->type == BT_UUID_TYPE_16) { + if (uuid->type == BLE_MESH_UUID_TYPE_16) { bta_uuid->len = LEN_UUID_16; - bta_uuid->uu.uuid16 = BT_UUID_16(uuid)->val; - } else if (uuid->type == BT_UUID_TYPE_32) { + bta_uuid->uu.uuid16 = BLE_MESH_UUID_16(uuid)->val; + } else if (uuid->type == BLE_MESH_UUID_TYPE_32) { bta_uuid->len = LEN_UUID_32; - bta_uuid->uu.uuid32 = BT_UUID_32(uuid)->val; - } else if (uuid->type == BT_UUID_TYPE_128) { + bta_uuid->uu.uuid32 = BLE_MESH_UUID_32(uuid)->val; + } else if (uuid->type == BLE_MESH_UUID_TYPE_128) { bta_uuid->len = LEN_UUID_128; - memcpy(bta_uuid->uu.uuid128, BT_UUID_128(uuid)->val, 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); } @@ -1073,12 +763,10 @@ static void bta_uuid_to_mesh_uuid(tBT_UUID *bta_uuid, const struct bt_uuid *uui return; } -static int gatts_register(struct bt_gatt_service *svc) +static int gatts_register(struct bt_mesh_gatt_service *svc) { - struct bt_gatt_service *last; + struct bt_mesh_gatt_service *last; u16_t handle; - //struct bt_gatt_attr *attrs = svc->attrs; - //u16_t count = svc->attr_count; if (sys_slist_is_empty(&bt_mesh_gatts_db)) { handle = 0; @@ -1090,134 +778,114 @@ static int gatts_register(struct bt_gatt_service *svc) BT_DBG("%s, handle = %d", __func__, handle); populate: -#if 0 - /* Populate the handles and append them to the list */ - for (; attrs && count; attrs++, count--) { - if (!attrs->handle) { - /* Allocate handle if not set already */ - attrs->handle = ++handle; - } else if (attrs->handle > handle) { - /* Use existing handle if valid */ - handle = attrs->handle; - } else { - /* Service has conflicting handles */ - BT_ERR("Unable to register handle 0x%04x", - attrs->handle); - return -EINVAL; - } - - BT_DBG("attr %p handle 0x%04x uuid %s perm 0x%02x", - attrs, attrs->handle, bt_uuid_str(attrs->uuid), - attrs->perm); - } -#endif sys_slist_append(&bt_mesh_gatts_db, &svc->node); return 0; } -static tBTA_GATT_PERM mesh_perm_to_bta_perm(u8_t perm) +static tBTA_GATT_PERM bt_mesh_perm_to_bta_perm(u8_t perm) { tBTA_GATT_PERM bta_perm = 0; - if ((perm & BT_GATT_PERM_READ) == BT_GATT_PERM_READ) { + + if ((perm & BLE_MESH_GATT_PERM_READ) == BLE_MESH_GATT_PERM_READ) { bta_perm |= BTA_GATT_PERM_READ; } - if ((perm & BT_GATT_PERM_WRITE) == BT_GATT_PERM_WRITE) { + if ((perm & BLE_MESH_GATT_PERM_WRITE) == BLE_MESH_GATT_PERM_WRITE) { bta_perm |= BTA_GATT_PERM_WRITE; } - if ((perm & BT_GATT_PERM_READ_ENCRYPT) == BT_GATT_PERM_READ_ENCRYPT) { + if ((perm & BLE_MESH_GATT_PERM_READ_ENCRYPT) == BLE_MESH_GATT_PERM_READ_ENCRYPT) { bta_perm |= BTA_GATT_PERM_READ_ENCRYPTED; } - if ((perm & BT_GATT_PERM_WRITE_ENCRYPT) == BT_GATT_PERM_WRITE_ENCRYPT) { + if ((perm & BLE_MESH_GATT_PERM_WRITE_ENCRYPT) == BLE_MESH_GATT_PERM_WRITE_ENCRYPT) { bta_perm |= BTA_GATT_PERM_WRITE_ENCRYPTED; } - if ((perm & BT_GATT_PERM_READ_AUTHEN) == BT_GATT_PERM_READ_AUTHEN) { + if ((perm & BLE_MESH_GATT_PERM_READ_AUTHEN) == BLE_MESH_GATT_PERM_READ_AUTHEN) { bta_perm |= BTA_GATT_PERM_READ_ENC_MITM; } - if ((perm & BT_GATT_PERM_WRITE_AUTHEN) == BT_GATT_PERM_WRITE_AUTHEN) { + if ((perm & BLE_MESH_GATT_PERM_WRITE_AUTHEN) == BLE_MESH_GATT_PERM_WRITE_AUTHEN) { bta_perm |= BTA_GATT_PERM_WRITE_ENC_MITM; } return bta_perm; } -int bt_mesh_gatts_service_register(struct bt_gatt_service *svc) +int bt_mesh_gatts_service_register(struct bt_mesh_gatt_service *svc) { - assert(svc != NULL); tBT_UUID bta_uuid = {0}; + assert(svc != NULL); + for (int i = 0; i < svc->attr_count; i++) { - if (svc->attrs[i].uuid->type == BT_UUID_TYPE_16) { - switch (BT_UUID_16(svc->attrs[i].uuid)->val) { - case BT_UUID_GATT_PRIMARY_VAL: { + if (svc->attrs[i].uuid->type == BLE_MESH_UUID_TYPE_16) { + switch (BLE_MESH_UUID_16(svc->attrs[i].uuid)->val) { + case BLE_MESH_UUID_GATT_PRIMARY_VAL: { future_mesh = future_new(); - bta_uuid_to_mesh_uuid(&bta_uuid, (struct bt_uuid *)svc->attrs[i].user_data); + bta_uuid_to_bt_mesh_uuid(&bta_uuid, (struct bt_mesh_uuid *)svc->attrs[i].user_data); BTA_GATTS_CreateService(bt_mesh_gatts_if, &bta_uuid, 0, svc->attr_count, true); if (future_await(future_mesh) == FUTURE_FAIL) { - BT_ERR("add primary service failed."); + BT_ERR("%s, Failed to add primary service", __func__); return ESP_FAIL; } svc->attrs[i].handle = svc_handle; - BT_DBG("############## create service ############"); - BT_DBG("add pri service: svc_uuid = %x, perm = %d, svc_handle = %d", bta_uuid.uu.uuid16, svc->attrs[i].perm, 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); break; } - case BT_UUID_GATT_SECONDARY_VAL: { + case BLE_MESH_UUID_GATT_SECONDARY_VAL: { future_mesh = future_new(); - bta_uuid_to_mesh_uuid(&bta_uuid, (struct bt_uuid *)svc->attrs[i].user_data); + bta_uuid_to_bt_mesh_uuid(&bta_uuid, (struct bt_mesh_uuid *)svc->attrs[i].user_data); BTA_GATTS_CreateService(bt_mesh_gatts_if, &bta_uuid, 0, svc->attr_count, false); if (future_await(future_mesh) == FUTURE_FAIL) { - BT_ERR("add secondary service failed."); + BT_ERR("%s, Failed to add secondary service", __func__); return ESP_FAIL; } svc->attrs[i].handle = svc_handle; - BT_DBG("add sec service: svc_uuid = %x, perm = %d, svc_handle = %d", bta_uuid.uu.uuid16, svc->attrs[i].perm, 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); break; } - case BT_UUID_GATT_INCLUDE_VAL: { + case BLE_MESH_UUID_GATT_INCLUDE_VAL: { break; } - case BT_UUID_GATT_CHRC_VAL: { + case BLE_MESH_UUID_GATT_CHRC_VAL: { future_mesh = future_new(); - struct bt_gatt_chrc *gatts_chrc = (struct bt_gatt_chrc *)svc->attrs[i].user_data; - bta_uuid_to_mesh_uuid(&bta_uuid, gatts_chrc->uuid); - BTA_GATTS_AddCharacteristic(svc_handle, &bta_uuid, mesh_perm_to_bta_perm(svc->attrs[i + 1].perm), gatts_chrc->properties, NULL, NULL); + struct bt_mesh_gatt_char *gatts_chrc = (struct bt_mesh_gatt_char *)svc->attrs[i].user_data; + 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("Add characristic failed."); + BT_ERR("%s, Failed to add characristic", __func__); return ESP_FAIL; } /* All the characristic should have two handle: the declaration handle and the value handle */ svc->attrs[i].handle = char_handle - 1; svc->attrs[i + 1].handle = char_handle; - BT_DBG("add char: char_uuid = %x, char_handle = %d, perm = %d, char_pro = %d", BT_UUID_16(gatts_chrc->uuid)->val, char_handle, svc->attrs[i + 1].perm, gatts_chrc->properties); + 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); break; } - case BT_UUID_GATT_CEP_VAL: - case BT_UUID_GATT_CUD_VAL: - case BT_UUID_GATT_CCC_VAL: - case BT_UUID_GATT_SCC_VAL: - case BT_UUID_GATT_CPF_VAL: - case BT_UUID_VALID_RANGE_VAL: - case BT_UUID_HIDS_EXT_REPORT_VAL: - case BT_UUID_HIDS_REPORT_REF_VAL: - case BT_UUID_ES_CONFIGURATION_VAL: - case BT_UUID_ES_MEASUREMENT_VAL: - case BT_UUID_ES_TRIGGER_SETTING_VAL: { + case BLE_MESH_UUID_GATT_CEP_VAL: + case BLE_MESH_UUID_GATT_CUD_VAL: + case BLE_MESH_UUID_GATT_CCC_VAL: + case BLE_MESH_UUID_GATT_SCC_VAL: + case BLE_MESH_UUID_GATT_CPF_VAL: + case BLE_MESH_UUID_VALID_RANGE_VAL: + case BLE_MESH_UUID_HIDS_EXT_REPORT_VAL: + case BLE_MESH_UUID_HIDS_REPORT_REF_VAL: + case BLE_MESH_UUID_ES_CONFIGURATION_VAL: + case BLE_MESH_UUID_ES_MEASUREMENT_VAL: + case BLE_MESH_UUID_ES_TRIGGER_SETTING_VAL: { future_mesh = future_new(); - bta_uuid_to_mesh_uuid(&bta_uuid, svc->attrs[i].uuid); - BTA_GATTS_AddCharDescriptor(svc_handle, mesh_perm_to_bta_perm(svc->attrs[i].perm), &bta_uuid, NULL, NULL); + 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("add primary service failed."); + BT_ERR("%s, Failed to add descriptor", __func__); return ESP_FAIL; } svc->attrs[i].handle = char_handle; - BT_DBG("add descr: descr_uuid = %x, perm= %d, descr_handle = %d", BT_UUID_16(svc->attrs[i].uuid)->val, svc->attrs[i].perm, 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); break; } default: @@ -1227,27 +895,22 @@ int bt_mesh_gatts_service_register(struct bt_gatt_service *svc) } if (svc_handle != 0) { - /* TODO: Currently we start service according to function like - * bt_mesh_proxy_gatt_enable, etc - */ - //BTA_GATTS_StartService(svc_handle, BTA_GATT_TRANSPORT_LE); svc_handle = 0; } - // Still should regitster to the adapt bt_mesh_gatts_db. gatts_register(svc); return 0; } -int bt_mesh_gatts_disconnect(struct bt_conn *conn, u8_t reason) +int bt_mesh_gatts_disconnect(struct bt_mesh_conn *conn, u8_t reason) { UNUSED(reason); - u16_t conn_id = BT_MESH_GATT_CREATE_CONN_ID(bt_mesh_gatts_if, conn->handle); + u16_t conn_id = BLE_MESH_GATT_CREATE_CONN_ID(bt_mesh_gatts_if, conn->handle); BTA_GATTS_Close(conn_id); return 0; } -int bt_mesh_gatts_service_unregister(struct bt_gatt_service *svc) +int bt_mesh_gatts_service_unregister(struct bt_mesh_gatt_service *svc) { assert(svc != NULL); @@ -1255,24 +918,24 @@ int bt_mesh_gatts_service_unregister(struct bt_gatt_service *svc) return 0; } -int bt_mesh_gatts_notify(struct bt_conn *conn, const struct bt_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 = BT_MESH_GATT_CREATE_CONN_ID(bt_mesh_gatts_if, conn->handle); + u16_t conn_id = BLE_MESH_GATT_CREATE_CONN_ID(bt_mesh_gatts_if, conn->handle); BTA_GATTS_HandleValueIndication(conn_id, attr->handle, len, (u8_t *)data, false); return 0; } -u16_t bt_mesh_gatt_get_mtu(struct bt_conn *conn) +u16_t bt_mesh_gatt_get_mtu(struct bt_mesh_conn *conn) { return BTA_GATT_GetLocalMTU(); } /* APIs added by Espressif */ -int bt_mesh_gatts_service_stop(struct bt_gatt_service *svc) +int bt_mesh_gatts_service_stop(struct bt_mesh_gatt_service *svc) { if (!svc) { - BT_ERR("%s, svc should not be NULL", __func__); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } @@ -1282,10 +945,10 @@ int bt_mesh_gatts_service_stop(struct bt_gatt_service *svc) return 0; } -int bt_mesh_gatts_service_start(struct bt_gatt_service *svc) +int bt_mesh_gatts_service_start(struct bt_mesh_gatt_service *svc) { if (!svc) { - BT_ERR("%s, svc should not be NULL", __func__); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } @@ -1294,15 +957,15 @@ int bt_mesh_gatts_service_start(struct bt_gatt_service *svc) BTA_GATTS_StartService(svc->attrs[0].handle, BTA_GATT_TRANSPORT_LE); return 0; } -#endif /* defined(CONFIG_BT_MESH_NODE) && CONFIG_BT_MESH_NODE */ +#endif /* defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE */ -#if defined(CONFIG_BT_MESH_PROVISIONER) && CONFIG_BT_MESH_PROVISIONER -void bt_mesh_gattc_conn_cb_register(struct bt_prov_conn_cb *cb) +#if defined(CONFIG_BLE_MESH_PROVISIONER) && CONFIG_BLE_MESH_PROVISIONER +void bt_mesh_gattc_conn_cb_register(struct bt_mesh_prov_conn_cb *cb) { bt_mesh_gattc_conn_cb = cb; } -u16_t bt_mesh_gattc_get_service_uuid(struct bt_conn *conn) +u16_t bt_mesh_gattc_get_service_uuid(struct bt_mesh_conn *conn) { int i; @@ -1329,28 +992,28 @@ u16_t bt_mesh_gattc_get_service_uuid(struct bt_conn *conn) * 6. Set the Notification bit of CCC */ -int bt_mesh_gattc_conn_create(const bt_addr_le_t *addr, u16_t service_uuid) +int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, u16_t service_uuid) { u8_t zero[6] = {0}; int i; - if (!addr || !memcmp(addr->a.val, zero, BD_ADDR_LEN) || + if (!addr || !memcmp(addr->val, zero, BLE_MESH_ADDR_LEN) || (addr->type > BLE_ADDR_RANDOM)) { - BT_ERR("%s: invalid address", __func__); + BT_ERR("%s, Invalid remote address", __func__); return -EINVAL; } - if (service_uuid != BT_UUID_MESH_PROV_VAL && - service_uuid != BT_UUID_MESH_PROXY_VAL) { - BT_ERR("%s: invalid service uuid 0x%04x", __func__, service_uuid); + 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); 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, addr->a.val, BD_ADDR_LEN)) { - BT_WARN("%s, Already create conn with %s", - __func__, bt_hex(addr->a.val, BD_ADDR_LEN)); + if (!memcmp(bt_mesh_gattc_info[i].addr, addr->val, BLE_MESH_ADDR_LEN)) { + BT_WARN("%s, Already create connection with %s", + __func__, bt_hex(addr->val, BLE_MESH_ADDR_LEN)); return -EALREADY; } } @@ -1359,7 +1022,7 @@ int bt_mesh_gattc_conn_create(const bt_addr_le_t *addr, u16_t service_uuid) for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) { if ((bt_mesh_gattc_info[i].conn.handle == 0xFFFF) && (bt_mesh_gattc_info[i].service_uuid == 0x0000)) { - memcpy(bt_mesh_gattc_info[i].addr, addr->a.val, BD_ADDR_LEN); + memcpy(bt_mesh_gattc_info[i].addr, addr->val, BLE_MESH_ADDR_LEN); bt_mesh_gattc_info[i].addr_type = addr->type; /* Service to be found after exhanging mtu size */ bt_mesh_gattc_info[i].service_uuid = service_uuid; @@ -1372,15 +1035,15 @@ int bt_mesh_gattc_conn_create(const bt_addr_le_t *addr, u16_t service_uuid) return -ENOMEM; } -#if BT_DEV - if (atomic_test_and_clear_bit(bt_dev.flags, BT_DEV_EXPLICIT_SCAN)) { - BTM_BleScan(false, 0, NULL, NULL, NULL); +#if BLE_MESH_DEV + if (bt_mesh_atomic_test_and_clear_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING)) { + BLE_MESH_BTM_CHECK_STATUS(BTM_BleScan(false, 0, NULL, NULL, NULL)); } #else - BTM_BleScan(false, 0, NULL, NULL, NULL); -#endif /* BT_DEV */ + 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->a.val, BD_ADDR_LEN)); + BT_DBG("%s, create conn with %s", __func__, bt_hex(addr->val, BLE_MESH_ADDR_LEN)); /* Min_interval: 250ms * Max_interval: 250ms @@ -1406,12 +1069,12 @@ void bt_mesh_gattc_exchange_mtu(u8_t index) */ u16_t conn_id; - conn_id = BT_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[index].conn.handle); + conn_id = BLE_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[index].conn.handle); BTA_GATTC_ConfigureMTU(conn_id); } -u16_t bt_mesh_gattc_get_mtu_info(struct bt_conn *conn) +u16_t bt_mesh_gattc_get_mtu_info(struct bt_mesh_conn *conn) { int i; @@ -1424,11 +1087,11 @@ u16_t bt_mesh_gattc_get_mtu_info(struct bt_conn *conn) return 0; } -int bt_mesh_gattc_write_no_rsp(struct bt_conn *conn, const struct bt_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) { - int i; u16_t conn_id; + int i; for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) { if (conn == &bt_mesh_gattc_info[i].conn) { @@ -1437,13 +1100,13 @@ int bt_mesh_gattc_write_no_rsp(struct bt_conn *conn, const struct bt_gatt_attr * } if (i == ARRAY_SIZE(bt_mesh_gattc_info)) { - BT_ERR("No conn found"); + BT_ERR("%s, Conn is not found", __func__); /** Here we return 0 for prov_send() return value check in provisioner.c */ return 0; } - conn_id = BT_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[i].conn.handle); + conn_id = BLE_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[i].conn.handle); BTA_GATTC_WriteCharValue(conn_id, bt_mesh_gattc_info[i].data_in_handle, BTA_GATTC_TYPE_WRITE_NO_RSP, len, @@ -1452,7 +1115,7 @@ int bt_mesh_gattc_write_no_rsp(struct bt_conn *conn, const struct bt_gatt_attr * return 0; } -void bt_mesh_gattc_disconnect(struct bt_conn *conn) +void bt_mesh_gattc_disconnect(struct bt_mesh_conn *conn) { /** Disconnect * Clear proper proxy server information @@ -1462,8 +1125,8 @@ void bt_mesh_gattc_disconnect(struct bt_conn *conn) * when proxy_disconnected callback comes, the proxy server * information and prov_link information should be cleared. */ - int i; u16_t conn_id; + int i; for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) { if (conn == &bt_mesh_gattc_info[i].conn) { @@ -1472,11 +1135,11 @@ void bt_mesh_gattc_disconnect(struct bt_conn *conn) } if (i == ARRAY_SIZE(bt_mesh_gattc_info)) { - BT_ERR("No conn found"); + BT_ERR("%s, Conn is not found", __func__); return; } - conn_id = BT_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[i].conn.handle); + conn_id = BLE_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[i].conn.handle); BTA_GATTC_Close(conn_id); } @@ -1490,7 +1153,7 @@ void bt_mesh_gattc_disconnect(struct bt_conn *conn) */ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) { - struct bt_conn *conn = NULL; + struct bt_mesh_conn *conn = NULL; u16_t handle = 0; ssize_t len = 0; int i = 0; @@ -1498,7 +1161,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) switch (event) { case BTA_GATTC_REG_EVT: if (p_data->reg_oper.status == BTA_GATT_OK) { - u8_t uuid[16] = { [0 ... 15] = BT_MESH_GATTC_APP_UUID_BYTE }; + u8_t uuid[16] = { [0 ... 15] = BLE_MESH_GATTC_APP_UUID_BYTE }; BT_DBG("BTA_GATTC_REG_EVT"); @@ -1513,7 +1176,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) if (p_data->cfg_mtu.status == BTA_GATT_OK) { BT_DBG("BTA_GATTC_CFG_MTU_EVT, cfg_mtu is %d", p_data->cfg_mtu.mtu); - handle = BT_MESH_GATT_GET_CONN_ID(p_data->cfg_mtu.conn_id); + handle = BLE_MESH_GATT_GET_CONN_ID(p_data->cfg_mtu.conn_id); for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) { if (bt_mesh_gattc_info[i].conn.handle == handle) { @@ -1530,7 +1193,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) tBT_UUID service_uuid; u16_t conn_id; - conn_id = BT_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[i].conn.handle); + conn_id = BLE_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[i].conn.handle); service_uuid.len = sizeof(bt_mesh_gattc_info[i].service_uuid); service_uuid.uu.uuid16 = bt_mesh_gattc_info[i].service_uuid; @@ -1543,7 +1206,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) case BTA_GATTC_SEARCH_RES_EVT: { BT_DBG("BTA_GATTC_SEARCH_RES_EVT"); - handle = BT_MESH_GATT_GET_CONN_ID(p_data->srvc_res.conn_id); + handle = BLE_MESH_GATT_GET_CONN_ID(p_data->srvc_res.conn_id); for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) { if (bt_mesh_gattc_info[i].conn.handle == handle) { @@ -1564,7 +1227,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) if (p_data->search_cmpl.status == BTA_GATT_OK) { BT_DBG("BTA_GATTC_SEARCH_CMPL_EVT"); - handle = BT_MESH_GATT_GET_CONN_ID(p_data->search_cmpl.conn_id); + handle = BLE_MESH_GATT_GET_CONN_ID(p_data->search_cmpl.conn_id); for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) { if (bt_mesh_gattc_info[i].conn.handle == handle) { @@ -1573,7 +1236,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) } if (i == ARRAY_SIZE(bt_mesh_gattc_info)) { - BT_ERR("BTA_GATTC_SEARCH_CMPL_EVT: conn_id not found"); + BT_ERR("%s, Conn handle is not found", __func__); return; } @@ -1592,11 +1255,11 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) tBT_UUID char_uuid; btgatt_db_element_t *result = NULL; tBTA_GATT_STATUS status; - u16_t notify_en = BT_GATT_CCC_NOTIFY; + u16_t notify_en = BLE_MESH_GATT_CCC_NOTIFY; tBTA_GATT_UNFMT write; /* Get the characteristic num within Mesh Provisioning/Proxy Service */ - conn_id = BT_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[i].conn.handle); + conn_id = BLE_MESH_GATT_CREATE_CONN_ID(bt_mesh_gattc_if, bt_mesh_gattc_info[i].conn.handle); BTA_GATTC_GetDBSizeByType(conn_id, BTGATT_DB_CHARACTERISTIC, bt_mesh_gattc_info[i].start_handle, bt_mesh_gattc_info[i].end_handle, BTA_GATTC_INVALID_HANDLE, &count); if (count != 2) { @@ -1610,10 +1273,10 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) * Second: find Mesh Provisioning/Proxy Data Out Characteristic */ char_uuid.len = 2; - if (bt_mesh_gattc_info[i].service_uuid == BT_UUID_MESH_PROV_VAL) { - char_uuid.uu.uuid16 = BT_UUID_MESH_PROV_DATA_IN_VAL + j; - } else if (bt_mesh_gattc_info[i].service_uuid == BT_UUID_MESH_PROXY_VAL) { - char_uuid.uu.uuid16 = BT_UUID_MESH_PROXY_DATA_IN_VAL + j; + if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROV_VAL) { + char_uuid.uu.uuid16 = BLE_MESH_UUID_MESH_PROV_DATA_IN_VAL + j; + } else if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROXY_VAL) { + char_uuid.uu.uuid16 = BLE_MESH_UUID_MESH_PROXY_DATA_IN_VAL + j; } BTA_GATTC_GetCharByUUID(conn_id, bt_mesh_gattc_info[i].start_handle, @@ -1631,14 +1294,14 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) } if (!j) { - if (!(result[0].properties & BT_GATT_CHRC_WRITE_WITHOUT_RESP)) { + if (!(result[0].properties & BLE_MESH_GATT_CHRC_WRITE_WITHOUT_RESP)) { osi_free(result); bt_mesh_gattc_disconnect(conn); return; } bt_mesh_gattc_info[i].data_in_handle = result[0].attribute_handle; } else { - if (!(result[0].properties & BT_GATT_CHRC_NOTIFY)) { + if (!(result[0].properties & BLE_MESH_GATT_CHRC_NOTIFY)) { osi_free(result); bt_mesh_gattc_disconnect(conn); return; @@ -1669,7 +1332,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) /* Get CCC of Mesh Provisioning/Proxy Data Out Characteristic */ char_uuid.len = 2; - char_uuid.uu.uuid16 = BT_UUID_GATT_CCC_VAL; + char_uuid.uu.uuid16 = BLE_MESH_UUID_GATT_CCC_VAL; BTA_GATTC_GetDescrByCharHandle(conn_id, bt_mesh_gattc_info[i].data_out_handle, char_uuid, &result, &num); @@ -1705,7 +1368,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) if (p_data->write.status == BTA_GATT_OK) { BT_DBG("BTA_GATTC_WRITE_DESCR_EVT"); - handle = BT_MESH_GATT_GET_CONN_ID(p_data->write.conn_id); + handle = BLE_MESH_GATT_GET_CONN_ID(p_data->write.conn_id); for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) { if (bt_mesh_gattc_info[i].conn.handle == handle) { @@ -1714,33 +1377,33 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) } if (i == ARRAY_SIZE(bt_mesh_gattc_info)) { - BT_ERR("BTA_GATTC_WRITE_DESCR_EVT: conn_id not found"); + BT_ERR("%s, Conn handle is not found", __func__); return; } conn = &bt_mesh_gattc_info[i].conn; if (bt_mesh_gattc_info[i].ccc_handle != p_data->write.handle) { - BT_WARN("BTA_GATTC_WRITE_DESCR_EVT: ccc_handle not match"); + BT_WARN("%s, gattc ccc_handle is not matched", __func__); bt_mesh_gattc_disconnect(conn); return; } - if (bt_mesh_gattc_info[i].service_uuid == BT_UUID_MESH_PROV_VAL) { + if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROV_VAL) { if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->prov_write_descr != NULL) { len = bt_mesh_gattc_conn_cb->prov_write_descr(&bt_mesh_gattc_info[i].conn, bt_mesh_gattc_info[i].addr); if (len < 0) { - BT_ERR("prov_write_descr fail"); + BT_ERR("%s, prov_write_descr failed", __func__); bt_mesh_gattc_disconnect(conn); return; } bt_mesh_gattc_info[i].wr_desc_done = true; } - } else if (bt_mesh_gattc_info[i].service_uuid == BT_UUID_MESH_PROXY_VAL) { + } else if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROXY_VAL) { 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].conn); if (len < 0) { - BT_ERR("proxy_write_descr fail"); + BT_ERR("%s, proxy_write_descr failed", __func__); bt_mesh_gattc_disconnect(conn); return; } @@ -1752,7 +1415,7 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) case BTA_GATTC_NOTIF_EVT: { BT_DBG("BTA_GATTC_NOTIF_EVT"); - handle = BT_MESH_GATT_GET_CONN_ID(p_data->notify.conn_id); + handle = BLE_MESH_GATT_GET_CONN_ID(p_data->notify.conn_id); for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) { if (bt_mesh_gattc_info[i].conn.handle == handle) { @@ -1761,36 +1424,36 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) } if (i == ARRAY_SIZE(bt_mesh_gattc_info)) { - BT_ERR("BTA_GATTC_WRITE_DESCR_EVT: conn_id not found"); + BT_ERR("%s, Conn handle is not found", __func__); return; } conn = &bt_mesh_gattc_info[i].conn; - if (memcmp(bt_mesh_gattc_info[i].addr, p_data->notify.bda, BD_ADDR_LEN) || + if (memcmp(bt_mesh_gattc_info[i].addr, 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("Notification error"); + BT_ERR("%s, Notification error", __func__); bt_mesh_gattc_disconnect(conn); return; } - if (bt_mesh_gattc_info[i].service_uuid == BT_UUID_MESH_PROV_VAL) { + if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROV_VAL) { if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->prov_notify != NULL) { len = bt_mesh_gattc_conn_cb->prov_notify(&bt_mesh_gattc_info[i].conn, p_data->notify.value, p_data->notify.len); if (len < 0) { - BT_ERR("Receive prov_notify fail"); + BT_ERR("%s, prov_notify failed", __func__); bt_mesh_gattc_disconnect(conn); return; } } - } else if (bt_mesh_gattc_info[i].service_uuid == BT_UUID_MESH_PROXY_VAL) { + } else if (bt_mesh_gattc_info[i].service_uuid == BLE_MESH_UUID_MESH_PROXY_VAL) { if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->proxy_notify != NULL) { 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("Receive proxy_notify fail"); + BT_ERR("%s, proxy_notify failed", __func__); bt_mesh_gattc_disconnect(conn); return; } @@ -1812,21 +1475,22 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) * use BTA_DmBleScan() to re-enable scan. */ tBTM_STATUS status; -#if BT_DEV - if (!atomic_test_and_set_bit(bt_dev.flags, BT_DEV_EXPLICIT_SCAN)) { - status = BTM_BleScan(true, 0, ble_mesh_scan_results_cb, NULL, NULL); +#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); if (status != BTM_SUCCESS && status != BTM_CMD_STARTED) { - BT_ERR("%s, invalid status %d", __func__, status); + BT_ERR("%s, Invalid status %d", __func__, status); break; } + bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_SCANNING); } #else - status = BTM_BleScan(true, 0, ble_mesh_scan_results_cb, NULL, NULL); + 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 status %d", __func__, status); break; } -#endif /* BT_DEV */ +#endif /* BLE_MESH_DEV */ break; } case BTA_GATTC_CLOSE_EVT: @@ -1836,14 +1500,14 @@ 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("bt_mesh_gattc_if & connect_if don't match"); + BT_ERR("%s, gattc_if & connect_if don't match", __func__); return; } if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->connected != NULL) { for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) { - if (!memcmp(bt_mesh_gattc_info[i].addr, p_data->connect.remote_bda, BD_ADDR_LEN)) { - bt_mesh_gattc_info[i].conn.handle = BT_MESH_GATT_GET_CONN_ID(p_data->connect.conn_id); + if (!memcmp(bt_mesh_gattc_info[i].addr, p_data->connect.remote_bda, BLE_MESH_ADDR_LEN)) { + bt_mesh_gattc_info[i].conn.handle = BLE_MESH_GATT_GET_CONN_ID(p_data->connect.conn_id); (bt_mesh_gattc_conn_cb->connected)(bt_mesh_gattc_info[i].addr, &bt_mesh_gattc_info[i].conn, i); break; } @@ -1855,15 +1519,15 @@ 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("bt_mesh_gattc_if & disconnect_if don't match"); + BT_ERR("%s, gattc_if & disconnect_if don't match", __func__); return; } - handle = BT_MESH_GATT_GET_CONN_ID(p_data->disconnect.conn_id); + handle = BLE_MESH_GATT_GET_CONN_ID(p_data->disconnect.conn_id); if (bt_mesh_gattc_conn_cb != NULL && bt_mesh_gattc_conn_cb->disconnected != NULL) { for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) { - if (!memcmp(bt_mesh_gattc_info[i].addr, p_data->disconnect.remote_bda, BD_ADDR_LEN)) { + if (!memcmp(bt_mesh_gattc_info[i].addr, p_data->disconnect.remote_bda, BLE_MESH_ADDR_LEN)) { if (bt_mesh_gattc_info[i].conn.handle == handle) { (bt_mesh_gattc_conn_cb->disconnected)(&bt_mesh_gattc_info[i].conn, p_data->disconnect.reason); if (!bt_mesh_gattc_info[i].wr_desc_done) { @@ -1900,22 +1564,22 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data) break; } } -#endif /* defined(CONFIG_BT_MESH_PROVISIONER) && CONFIG_BT_MESH_PROVISIONER */ +#endif /* defined(CONFIG_BLE_MESH_PROVISIONER) && CONFIG_BLE_MESH_PROVISIONER */ -struct bt_conn *bt_mesh_conn_ref(struct bt_conn *conn) +struct bt_mesh_conn *bt_mesh_conn_ref(struct bt_mesh_conn *conn) { - atomic_inc(&conn->ref); + bt_mesh_atomic_inc(&conn->ref); - BT_DBG("handle %u ref %u", conn->handle, atomic_get(&conn->ref)); + BT_DBG("handle %u ref %u", conn->handle, bt_mesh_atomic_get(&conn->ref)); return conn; } -void bt_mesh_conn_unref(struct bt_conn *conn) +void bt_mesh_conn_unref(struct bt_mesh_conn *conn) { - atomic_dec(&conn->ref); + bt_mesh_atomic_dec(&conn->ref); - BT_DBG("handle %u ref %u", conn->handle, atomic_get(&conn->ref)); + BT_DBG("handle %u ref %u", conn->handle, bt_mesh_atomic_get(&conn->ref)); } void bt_mesh_gatt_init(void) @@ -1924,19 +1588,19 @@ void bt_mesh_gatt_init(void) BTA_GATT_SetLocalMTU(GATT_DEF_BLE_MTU_SIZE); -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE /* Fill our internal UUID with a fixed pattern 0x96 for the ble mesh */ memset(&app_uuid.uu.uuid128, 0x96, LEN_UUID_128); BTA_GATTS_AppRegister(&app_uuid, bt_mesh_bta_gatts_cb); #endif -#if CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_PROVISIONER for (int i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) { bt_mesh_gattc_info[i].conn.handle = 0xFFFF; bt_mesh_gattc_info[i].mtu = GATT_DEF_BLE_MTU_SIZE; /* Default MTU_SIZE 23 */ bt_mesh_gattc_info[i].wr_desc_done = false; } - memset(&app_uuid.uu.uuid128, BT_MESH_GATTC_APP_UUID_BYTE, LEN_UUID_128); + memset(&app_uuid.uu.uuid128, BLE_MESH_GATTC_APP_UUID_BYTE, LEN_UUID_128); BTA_GATTC_AppRegister(&app_uuid, bt_mesh_bta_gattc_cb); #endif } @@ -1950,14 +1614,14 @@ void bt_mesh_adapt_init(void) int bt_mesh_rand(void *buf, size_t len) { - if (!len) { + int i; + + if (buf == NULL || len == 0) { + BT_ERR("%s, Invalid parameter", __func__); return -EAGAIN; } - // Reset the buf value to the fixed value. - memset(buf, 0x55, len); - - for (int i = 0; i < (int)(len / sizeof(u32_t)); i++) { + for (i = 0; i < (int)(len / sizeof(u32_t)); i++) { u32_t rand = esp_random(); memcpy(buf + i * sizeof(u32_t), &rand, sizeof(u32_t)); } @@ -1976,7 +1640,7 @@ const u8_t *bt_mesh_pub_key_get(void) Point public_key; BT_OCTET32 pri_key; #if 1 - if (atomic_test_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY)) { + if (bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_HAS_PUB_KEY)) { return bt_mesh_public_key; } #else @@ -1986,7 +1650,7 @@ const u8_t *bt_mesh_pub_key_get(void) * at the same time, this may cause invalid confirmation value. */ if (bt_mesh_rand(bt_mesh_private_key, 32)) { - BT_ERR("Unable to generate bt_mesh_private_key"); + BT_ERR("%s, Unable to generate bt_mesh_private_key", __func__); return NULL; } #endif @@ -1996,7 +1660,7 @@ const u8_t *bt_mesh_pub_key_get(void) memcpy(bt_mesh_public_key, public_key.x, BT_OCTET32_LEN); memcpy(bt_mesh_public_key + BT_OCTET32_LEN, public_key.y, BT_OCTET32_LEN); - atomic_set_bit(bt_dev.flags, BT_DEV_HAS_PUB_KEY); + bt_mesh_atomic_set_bit(bt_mesh_dev.flags, BLE_MESH_DEV_HAS_PUB_KEY); BT_DBG("gen the bt_mesh_public_key:%s", bt_hex(bt_mesh_public_key, sizeof(bt_mesh_public_key))); return bt_mesh_public_key; @@ -2015,7 +1679,7 @@ bool bt_mesh_check_public_key(const u8_t key[64]) return ECC_CheckPointIsInElliCur_P256((Point *)&check); } -int bt_mesh_dh_key_gen(const u8_t remote_pk[64], bt_dh_key_cb_t cb) +int bt_mesh_dh_key_gen(const u8_t remote_pk[64], bt_mesh_dh_key_cb_t cb) { BT_OCTET32 private_key; Point peer_publ_key; @@ -2045,10 +1709,11 @@ int bt_mesh_dh_key_gen(const u8_t remote_pk[64], bt_dh_key_cb_t cb) return 0; } +#if CONFIG_MBEDTLS_HARDWARE_AES static void ecb_encrypt(u8_t const *const key_le, u8_t const *const clear_text_le, u8_t *const cipher_text_le, u8_t *const cipher_text_be) { - struct ecb_param ecb; + struct bt_mesh_ecb_param ecb; mbedtls_aes_context aes_ctx = {0}; aes_ctx.key_bytes = 16; @@ -2070,7 +1735,7 @@ static void ecb_encrypt(u8_t const *const key_le, u8_t const *const clear_text_l static void ecb_encrypt_be(u8_t const *const key_be, u8_t const *const clear_text_be, u8_t *const cipher_text_be) { - struct ecb_param ecb; + struct bt_mesh_ecb_param ecb; mbedtls_aes_context aes_ctx = {0}; aes_ctx.key_bytes = 16; @@ -2080,9 +1745,10 @@ static void ecb_encrypt_be(u8_t const *const key_be, u8_t const *const clear_tex memcpy(cipher_text_be, &ecb.cipher_text[0], sizeof(ecb.cipher_text)); } +#endif /* CONFIG_MBEDTLS_HARDWARE_AES */ -int bt_encrypt_le(const u8_t key[16], const u8_t plaintext[16], - u8_t enc_data[16]) +int bt_mesh_encrypt_le(const u8_t key[16], const u8_t plaintext[16], + u8_t enc_data[16]) { #if CONFIG_MBEDTLS_HARDWARE_AES BT_DBG("key %s plaintext %s", bt_hex(key, 16), bt_hex(plaintext, 16)); @@ -2117,8 +1783,8 @@ int bt_encrypt_le(const u8_t key[16], const u8_t plaintext[16], #endif /* CONFIG_MBEDTLS_HARDWARE_AES */ } -int bt_encrypt_be(const u8_t key[16], const u8_t plaintext[16], - u8_t enc_data[16]) +int bt_mesh_encrypt_be(const u8_t key[16], const u8_t plaintext[16], + u8_t enc_data[16]) { #if CONFIG_MBEDTLS_HARDWARE_AES BT_DBG("key %s plaintext %s", bt_hex(key, 16), bt_hex(plaintext, 16)); @@ -2147,18 +1813,18 @@ int bt_encrypt_be(const u8_t key[16], const u8_t plaintext[16], #endif /* CONFIG_MBEDTLS_HARDWARE_AES */ } -#if defined(CONFIG_BT_MESH_USE_DUPLICATE_SCAN) +#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) int bt_mesh_update_exceptional_list(u8_t sub_code, u8_t type, void *info) { BD_ADDR value = {0}; - if ((sub_code > BT_MESH_EXCEP_LIST_CLEAN) || - (type > BT_MESH_EXCEP_INFO_MESH_PROXY_ADV)) { + if ((sub_code > BLE_MESH_EXCEP_LIST_CLEAN) || + (type > BLE_MESH_EXCEP_INFO_MESH_PROXY_ADV)) { BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } - if (type == BT_MESH_EXCEP_INFO_MESH_LINK_ID) { + if (type == BLE_MESH_EXCEP_INFO_MESH_LINK_ID) { if (!info) { BT_ERR("%s, NULL Provisioning Link ID", __func__); return -EINVAL; @@ -2174,6 +1840,3 @@ int bt_mesh_update_exceptional_list(u8_t sub_code, u8_t type, void *info) return 0; } #endif - -#endif /* #if CONFIG_BT_MESH */ - diff --git a/components/bt/ble_mesh/mesh_core/mesh_buf.c b/components/bt/ble_mesh/mesh_core/mesh_buf.c index fe74fc0799..87458af1bf 100644 --- a/components/bt/ble_mesh/mesh_core/mesh_buf.c +++ b/components/bt/ble_mesh/mesh_core/mesh_buf.c @@ -7,32 +7,20 @@ #include +#include "sdkconfig.h" + #include "mesh_buf.h" #include "mesh_trace.h" -#include "esp_bt_defs.h" -#include "sdkconfig.h" -#if CONFIG_BT_MESH /* Helpers to access the storage array, since we don't have access to its * type at this point anymore. */ -#define BUF_SIZE(pool) (sizeof(struct net_buf) + \ - ROUND_UP(pool->buf_size, 4) + \ - ROUND_UP(pool->user_data_size, 4)) +#define BUF_SIZE(pool) (sizeof(struct net_buf) + \ + ROUND_UP(pool->buf_size, 4) + \ + ROUND_UP(pool->user_data_size, 4)) + #define UNINIT_BUF(pool, n) (struct net_buf *)(((u8_t *)(pool->__bufs)) + \ - ((n) * BUF_SIZE(pool))) - -/* Linker-defined symbol bound to the static pool structs */ -struct net_buf_pool *net_buf_pool_get(int id) -{ - return (struct net_buf_pool *)id; -} - -//static int pool_id(struct net_buf_pool *pool) -//{ -// BT_DBG("%s, the pool id = %p", __func__, pool); -// return (int)&pool[pool->buf_count - pool->uninit_count - 1]; -//} + ((n) * BUF_SIZE(pool))) static inline struct net_buf *pool_get_uninit(struct net_buf_pool *pool, u16_t uninit_count) @@ -43,8 +31,9 @@ static inline struct net_buf *pool_get_uninit(struct net_buf_pool *pool, buf->pool_id = pool; buf->size = pool->buf_size; - BT_DBG("%s, pool_id = %p, uninit_count = %d, pool->buf_count = %d, buf = %p, buf->size = %d, pool = %p", - __func__, buf->pool_id, uninit_count, pool->buf_count, buf, buf->size, pool); + + NET_BUF_DBG("%s, pool_id = %p, uninit_count = %d, pool->buf_count = %d, buf = %p, buf->size = %d, pool = %p", + __func__, buf->pool_id, uninit_count, pool->buf_count, buf, buf->size, pool); return buf; } @@ -222,8 +211,8 @@ void net_buf_reset(struct net_buf *buf) NET_BUF_ASSERT(buf->flags == 0); NET_BUF_ASSERT(buf->frags == NULL); - buf->len = 0; - buf->data = buf->__buf; + buf->len = 0; + buf->data = buf->__buf; } void net_buf_reserve(struct net_buf *buf, size_t reserve) @@ -247,9 +236,9 @@ void net_buf_slist_put(sys_slist_t *list, struct net_buf *buf) tail->flags |= NET_BUF_FRAGS; } - key = irq_lock(); + key = bt_mesh_irq_lock(); sys_slist_append_list(list, &buf->node, &tail->node); - irq_unlock(key); + bt_mesh_irq_unlock(key); } struct net_buf *net_buf_slist_get(sys_slist_t *list) @@ -259,9 +248,9 @@ struct net_buf *net_buf_slist_get(sys_slist_t *list) NET_BUF_ASSERT(list); - key = irq_lock(); + key = bt_mesh_irq_lock(); buf = (void *)sys_slist_get(list); - irq_unlock(key); + bt_mesh_irq_unlock(key); if (!buf) { return NULL; @@ -269,9 +258,9 @@ struct net_buf *net_buf_slist_get(sys_slist_t *list) /* Get any fragments belonging to this buffer */ for (frag = buf; (frag->flags & NET_BUF_FRAGS); frag = frag->frags) { - key = irq_lock(); + key = bt_mesh_irq_lock(); frag->frags = (void *)sys_slist_get(list); - irq_unlock(key); + bt_mesh_irq_unlock(key); NET_BUF_ASSERT(frag->frags); @@ -285,23 +274,6 @@ struct net_buf *net_buf_slist_get(sys_slist_t *list) return buf; } -void net_buf_put(struct k_fifo *fifo, struct net_buf *buf) -{ - struct net_buf *tail; - - //NET_BUF_ASSERT(fifo); - //NET_BUF_ASSERT(buf); - - //ble_mesh_msg_t msg = {0}; - - //ble_mesh_task_post(ble_mesh_msg_t *msg, 0); - for (tail = buf; tail->frags; tail = tail->frags) { - tail->flags |= NET_BUF_FRAGS; - } - - //k_fifo_put_list(fifo, buf, tail); -} - struct net_buf *net_buf_ref(struct net_buf *buf) { NET_BUF_ASSERT(buf); @@ -312,83 +284,7 @@ struct net_buf *net_buf_ref(struct net_buf *buf) return buf; } -struct net_buf *net_buf_clone(struct net_buf *buf, s32_t timeout) -{ - struct net_buf_pool *pool; - struct net_buf *clone; - - NET_BUF_ASSERT(buf); - - pool = buf->pool_id;//net_buf_pool_get(buf->pool_id); - - clone = net_buf_alloc(pool, timeout); - if (!clone) { - return NULL; - } - - net_buf_reserve(clone, net_buf_headroom(buf)); - - /* TODO: Add reference to the original buffer instead of copying it. */ - memcpy(net_buf_add(clone, buf->len), buf->data, buf->len); - - return clone; -} - -struct net_buf *net_buf_frag_last(struct net_buf *buf) -{ - NET_BUF_ASSERT(buf); - - while (buf->frags) { - buf = buf->frags; - } - - return buf; -} - -void net_buf_frag_insert(struct net_buf *parent, struct net_buf *frag) -{ - NET_BUF_ASSERT(parent); - NET_BUF_ASSERT(frag); - - if (parent->frags) { - net_buf_frag_last(frag)->frags = parent->frags; - } - /* Take ownership of the fragment reference */ - parent->frags = frag; -} - -#if defined(CONFIG_NET_BUF_LOG) -struct net_buf *net_buf_frag_del_debug(struct net_buf *parent, - struct net_buf *frag, - const char *func, int line) -#else -struct net_buf *net_buf_frag_del(struct net_buf *parent, struct net_buf *frag) -#endif -{ - struct net_buf *next_frag; - - NET_BUF_ASSERT(frag); - - if (parent) { - NET_BUF_ASSERT(parent->frags); - NET_BUF_ASSERT(parent->frags == frag); - parent->frags = frag->frags; - } - - next_frag = frag->frags; - - frag->frags = NULL; - -#if defined(CONFIG_NET_BUF_LOG) - net_buf_unref_debug(frag, func, line); -#else - net_buf_unref(frag); -#endif - - return next_frag; -} - -#if defined(CONFIG_NET_BUF_LOG) +#if defined(CONFIG_BLE_MESH_NET_BUF_LOG) void net_buf_unref_debug(struct net_buf *buf, const char *func, int line) #else void net_buf_unref(struct net_buf *buf) @@ -400,7 +296,7 @@ void net_buf_unref(struct net_buf *buf) struct net_buf *frags = buf->frags; struct net_buf_pool *pool; -#if defined(CONFIG_NET_BUF_LOG) +#if defined(CONFIG_BLE_MESH_NET_BUF_LOG) if (!buf->ref) { NET_BUF_ERR("%s():%d: buf %p double free", func, line, buf); @@ -417,26 +313,24 @@ void net_buf_unref(struct net_buf *buf) buf->frags = NULL; - pool = buf->pool_id;//net_buf_pool_get(buf->pool_id); + pool = buf->pool_id; pool->uninit_count++; -#if defined(CONFIG_NET_BUF_POOL_USAGE) +#if defined(CONFIG_BLE_MESH_NET_BUF_POOL_USAGE) pool->avail_count++; - BT_DBG("%s, pool->avail_count = %d, pool->uninit_count = %d", __func__, - pool->avail_count, pool->uninit_count); + NET_BUF_DBG("%s, pool->avail_count = %d, pool->uninit_count = %d", __func__, + pool->avail_count, pool->uninit_count); NET_BUF_ASSERT(pool->avail_count <= pool->buf_count); #endif if (pool->destroy) { pool->destroy(buf); - } else { - net_buf_destroy(buf); } buf = frags; } } -#if defined(CONFIG_NET_BUF_LOG) +#if defined(CONFIG_BLE_MESH_NET_BUF_LOG) struct net_buf *net_buf_alloc_debug(struct net_buf_pool *pool, s32_t timeout, const char *func, int line) #else @@ -450,12 +344,12 @@ struct net_buf *net_buf_alloc(struct net_buf_pool *pool, s32_t timeout) NET_BUF_ASSERT(pool); NET_BUF_DBG("%s():%d: pool %p timeout %d", func, line, pool, timeout); - BT_DBG("%s, pool = %p , pool->uninit_count= %d, buf_count = %d", __func__, - pool, pool->uninit_count, pool->buf_count); + NET_BUF_DBG("%s, pool = %p , pool->uninit_count= %d, buf_count = %d", __func__, + pool, pool->uninit_count, pool->buf_count); /* We need to lock interrupts temporarily to prevent race conditions * when accessing pool->uninit_count. */ - key = irq_lock(); + key = bt_mesh_irq_lock(); /* If there are uninitialized buffers we're guaranteed to succeed * with the allocation one way or another. @@ -468,28 +362,9 @@ struct net_buf *net_buf_alloc(struct net_buf_pool *pool, s32_t timeout) goto success; } } - // u16_t uninit_count; - - /* If this is not the first access to the pool, we can - * be opportunistic and try to fetch a previously used - * buffer from the LIFO with K_NO_WAIT. - */ - //if (pool->uninit_count < pool->buf_count) { - // buf = &pool->__bufs[pool->buf_count - pool->uninit_count]; - //if (buf) { - // irq_unlock(key); - // goto success; - //} - //} - - // uninit_count = pool->uninit_count--; - // irq_unlock(key); - - // buf = pool_get_uninit(pool, uninit_count); - // goto success; } - irq_unlock(key); + bt_mesh_irq_unlock(key); if (!buf) { BT_ERR("%s():Failed to get free buffer", __func__); @@ -498,7 +373,7 @@ struct net_buf *net_buf_alloc(struct net_buf_pool *pool, s32_t timeout) success: NET_BUF_DBG("allocated buf %p", buf); - irq_unlock(key); + bt_mesh_irq_unlock(key); buf->ref = 1; buf->index = pool->buf_count - i; @@ -507,22 +382,10 @@ success: net_buf_reset(buf); pool->uninit_count--; -#if defined(CONFIG_NET_BUF_POOL_USAGE) +#if defined(CONFIG_BLE_MESH_NET_BUF_POOL_USAGE) pool->avail_count--; NET_BUF_ASSERT(pool->avail_count >= 0); #endif return buf; } - -int net_buf_id(struct net_buf *buf) -{ - struct net_buf_pool *pool = buf->pool_id;//net_buf_pool_get(buf->pool_id); - u8_t *pool_start = (u8_t *)pool->__bufs; - u8_t *buf_ptr = (u8_t *)buf; - - return (buf_ptr - pool_start) / BUF_SIZE(pool); -} - -#endif /* #if CONFIG_BT_MESH */ - diff --git a/components/bt/ble_mesh/mesh_core/mesh_hci.c b/components/bt/ble_mesh/mesh_core/mesh_hci.c index 3ba3bd3116..691bf201d5 100644 --- a/components/bt/ble_mesh/mesh_core/mesh_hci.c +++ b/components/bt/ble_mesh/mesh_core/mesh_hci.c @@ -6,53 +6,39 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include "mesh_hci.h" -#include "stack/bt_types.h" -#include "device/controller.h" #include "sdkconfig.h" -#if CONFIG_BT_MESH +#include "stack/bt_types.h" +#include "device/controller.h" -struct bt_dev bt_dev; +#include "mesh_hci.h" -void mesh_hci_init(void) +struct bt_mesh_dev bt_mesh_dev; + +void bt_mesh_hci_init(void) { const uint8_t *features = controller_get_interface()->get_features_ble()->as_array; if (features != NULL) { - // We just copy the ble feature here, we don't care the classic bt feature in the ble mesh system. - memcpy(bt_dev.features[0], features, 8); + memcpy(bt_mesh_dev.features[0], features, 8); + memcpy(bt_mesh_dev.le.features, features, 8); } /**TODO: We support 20ms non-connectable adv interval, but not hci 5.0, so we need to add another flag * to indicate if we support 20ms adv interval * */ #ifdef CONFIG_HCI_5_0_VERSION - bt_dev.hci_version = BT_HCI_VERSION_5_0; + bt_mesh_dev.hci_version = BLE_MESH_HCI_VERSION_5_0; #else - bt_dev.hci_version = controller_get_interface()->get_bt_version()->hci_version; + bt_mesh_dev.hci_version = controller_get_interface()->get_bt_version()->hci_version; #endif - bt_dev.lmp_version = controller_get_interface()->get_bt_version()->lmp_version; - bt_dev.hci_revision = controller_get_interface()->get_bt_version()->hci_revision; - bt_dev.lmp_subversion = controller_get_interface()->get_bt_version()->lmp_subversion; - bt_dev.manufacturer = controller_get_interface()->get_bt_version()->manufacturer; - // Still to copy the features to the ble features struct. - memcpy(bt_dev.le.features, features, 8); + bt_mesh_dev.lmp_version = controller_get_interface()->get_bt_version()->lmp_version; + bt_mesh_dev.hci_revision = controller_get_interface()->get_bt_version()->hci_revision; + bt_mesh_dev.lmp_subversion = controller_get_interface()->get_bt_version()->lmp_subversion; + bt_mesh_dev.manufacturer = controller_get_interface()->get_bt_version()->manufacturer; const uint8_t *p = controller_get_interface()->get_ble_supported_states(); uint64_t states_fh = 0, states_sh = 0; - // We don't have the STREAM_TO_UINT64 macro, so we should used stream to u32 two times add then put them together. STREAM_TO_UINT32(states_fh, p); STREAM_TO_UINT32(states_sh, p); - bt_dev.le.states = (states_sh << 32) | states_fh; - -#if defined(CONFIG_BT_CONN) - bt_dev.le.mtu = controller_get_interface()->get_acl_data_size_ble(); -#endif /* CONFIG_BT_CONN */ - -#if defined(CONFIG_BT_SMP) - bt_dev.le.rl_size = controller_get_interface()->get_ble_resolving_list_max_size(); -#endif /* #if defined(CONFIG_BT_SMP) */ - + bt_mesh_dev.le.states = (states_sh << 32) | states_fh; } - -#endif /* #if CONFIG_BT_MESH */ diff --git a/components/bt/ble_mesh/mesh_core/mesh_kernel.c b/components/bt/ble_mesh/mesh_core/mesh_kernel.c index c01a4d2615..eaa4492259 100644 --- a/components/bt/ble_mesh/mesh_core/mesh_kernel.c +++ b/components/bt/ble_mesh/mesh_core/mesh_kernel.c @@ -6,27 +6,29 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include #include -#include "mesh_kernel.h" -#include "esp_timer.h" -#include "osi/hash_map.h" -#include "osi/alarm.h" -#include "common/bt_trace.h" -#include "common/bt_defs.h" -#include "osi/hash_functions.h" -#include "mesh_trace.h" #include "sdkconfig.h" -#if CONFIG_BT_MESH +#include "osi/hash_map.h" +#include "osi/alarm.h" +#include "osi/hash_functions.h" + +#include "common/bt_trace.h" +#include "common/bt_defs.h" + +#include "esp_timer.h" + +#include "mesh_kernel.h" +#include "mesh_trace.h" + #include "provisioner_prov.h" -static osi_mutex_t ble_mesh_alarm_lock; -static osi_mutex_t mesh_irq_lock; -static hash_map_t *ble_mesh_alarm_hash_map; -static const size_t BLE_MESH_GENERAL_ALARM_HASH_MAP_SIZE = 20 + CONFIG_BT_MESH_PBA_SAME_TIME + \ - CONFIG_BT_MESH_PBG_SAME_TIME; +static osi_mutex_t bm_alarm_lock; +static osi_mutex_t bm_irq_lock; +static hash_map_t *bm_alarm_hash_map; +static const size_t BLE_MESH_GENERAL_ALARM_HASH_MAP_SIZE = 20 + CONFIG_BLE_MESH_PBA_SAME_TIME + \ + CONFIG_BLE_MESH_PBG_SAME_TIME; typedef struct alarm_t { /* timer id point to here */ @@ -36,7 +38,7 @@ typedef struct alarm_t { int64_t deadline_us; } osi_alarm_t; -static void ble_mesh_alarm_cb(void *data) +static void bt_mesh_alarm_cb(void *data) { assert(data != NULL); struct k_delayed_work *work = (struct k_delayed_work *)data; @@ -44,27 +46,27 @@ static void ble_mesh_alarm_cb(void *data) return; } -unsigned int irq_lock(void) +unsigned int bt_mesh_irq_lock(void) { -#if defined(CONFIG_BT_MESH_IRQ_LOCK) && CONFIG_BT_MESH_IRQ_LOCK +#if defined(CONFIG_BLE_MESH_IRQ_LOCK) && CONFIG_BLE_MESH_IRQ_LOCK unsigned int key = XTOS_SET_INTLEVEL(XCHAL_EXCM_LEVEL); return key; -#else /* !CONFIG_BT_MESH_IRQ_LOCK */ +#else /* Change by Espressif. In BLE Mesh, in order to improve the real-time * requirements of bt controller, we use task lock to replace IRQ lock. */ - osi_mutex_lock(&mesh_irq_lock, OSI_MUTEX_MAX_TIMEOUT); + osi_mutex_lock(&bm_irq_lock, OSI_MUTEX_MAX_TIMEOUT); return 0; -#endif /*#if (CONFIG_BT_MESH_IRQ_LOCK) */ +#endif } -void irq_unlock(unsigned int key) +void bt_mesh_irq_unlock(unsigned int key) { -#if defined(CONFIG_BT_MESH_IRQ_LOCK) && CONFIG_BT_MESH_IRQ_LOCK +#if defined(CONFIG_BLE_MESH_IRQ_LOCK) && CONFIG_BLE_MESH_IRQ_LOCK XTOS_RESTORE_INTLEVEL(key); -#else /* !CONFIG_BT_MESH_IRQ_LOCK */ - osi_mutex_unlock(&mesh_irq_lock); -#endif /*#if (CONFIG_BT_MESH_IRQ_LOCK) && CONFIG_BT_MESH_IRQ_LOCK */ +#else + osi_mutex_unlock(&bm_irq_lock); +#endif } s64_t k_uptime_get(void) @@ -89,40 +91,38 @@ void k_sleep(s32_t duration) return; } -void mesh_k_init(void) +void bt_mesh_k_init(void) { - osi_mutex_new(&ble_mesh_alarm_lock); - osi_mutex_new(&mesh_irq_lock); - ble_mesh_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(ble_mesh_alarm_hash_map != NULL); + osi_mutex_new(&bm_alarm_lock); + osi_mutex_new(&bm_irq_lock); + 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 != NULL); } void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler) { - assert(work != NULL && ble_mesh_alarm_hash_map != NULL); - - k_work_init(&work->work, handler); - _init_timeout(&work->timeout, NULL); - work->work_q = NULL; - osi_alarm_t *alarm = NULL; - // Get the alarm for the timer list entry. - osi_mutex_lock(&ble_mesh_alarm_lock, OSI_MUTEX_MAX_TIMEOUT); - if (!hash_map_has_key(ble_mesh_alarm_hash_map, (void *)work)) { - alarm = osi_alarm_new("ble_mesh", ble_mesh_alarm_cb, (void *)work, 0); + assert(work != NULL && bm_alarm_hash_map != NULL); + + k_work_init(&work->work, handler); + + osi_mutex_lock(&bm_alarm_lock, OSI_MUTEX_MAX_TIMEOUT); + if (!hash_map_has_key(bm_alarm_hash_map, (void *)work)) { + alarm = osi_alarm_new("bt_mesh", bt_mesh_alarm_cb, (void *)work, 0); if (alarm == NULL) { LOG_ERROR("%s, Unable to create alarm", __func__); return; } - if (!hash_map_set(ble_mesh_alarm_hash_map, work, (void *)alarm)) { - LOG_ERROR("%s Unable to add the work timer to the mesh alarm hash map.", __func__); + if (!hash_map_set(bm_alarm_hash_map, work, (void *)alarm)) { + LOG_ERROR("%s Unable to add the timer to hash map.", __func__); } } - osi_mutex_unlock(&ble_mesh_alarm_lock); + osi_mutex_unlock(&bm_alarm_lock); - alarm = hash_map_get(ble_mesh_alarm_hash_map, work); + alarm = hash_map_get(bm_alarm_hash_map, work); if (alarm == NULL) { LOG_WARN("%s, Unable to find expected alarm in hash map", __func__); return; @@ -136,9 +136,9 @@ void k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler) int k_delayed_work_submit(struct k_delayed_work *work, s32_t delay) { - assert(work != NULL); + assert(work != NULL && bm_alarm_hash_map != NULL); - osi_alarm_t *alarm = hash_map_get(ble_mesh_alarm_hash_map, (void *)work); + osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work); if (alarm == NULL) { LOG_WARN("%s, Unable to find expected alarm in hash map", __func__); return -EINVAL; @@ -152,10 +152,9 @@ int k_delayed_work_submit(struct k_delayed_work *work, int k_delayed_work_cancel(struct k_delayed_work *work) { - assert(work != NULL); + assert(work != NULL && bm_alarm_hash_map != NULL); - // Check if the work have been store in the ble_mesh timer list or not. - osi_alarm_t *alarm = hash_map_get(ble_mesh_alarm_hash_map, (void *)work); + osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work); if (alarm == NULL) { LOG_WARN("%s, Unable to find expected alarm in hash map", __func__); return -EINVAL; @@ -168,24 +167,23 @@ int k_delayed_work_cancel(struct k_delayed_work *work) int k_delayed_work_free(struct k_delayed_work *work) { - assert(work != NULL); + assert(work != NULL && bm_alarm_hash_map != NULL); - // Get the alarm for the timer list entry. - osi_alarm_t *alarm = hash_map_get(ble_mesh_alarm_hash_map, work); + osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, work); if (alarm == NULL) { LOG_WARN("%s Unable to find expected alarm in hash map", __func__); return -EINVAL; } - hash_map_erase(ble_mesh_alarm_hash_map, work); + hash_map_erase(bm_alarm_hash_map, work); return 0; } s32_t k_delayed_work_remaining_get(struct k_delayed_work *work) { - assert(work != NULL); + assert(work != NULL && bm_alarm_hash_map != NULL); - osi_alarm_t *alarm = hash_map_get(ble_mesh_alarm_hash_map, (void *)work); + osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work); if (alarm == NULL) { LOG_WARN("%s Unable to find expected alarm in hash map", __func__); return 0; @@ -205,35 +203,3 @@ s32_t k_delayed_work_remaining_get(struct k_delayed_work *work) return remain_time; } - -void k_sem_give(struct k_sem *sem) -{ - assert(sem != NULL); - osi_mutex_unlock(sem->mutex); - return; -} - -void k_sem_init(struct k_sem *sem, unsigned int initial_count, - unsigned int limit) -{ - assert(sem != NULL); - - UNUSED(initial_count); - UNUSED(limit); - - sem->mutex = xSemaphoreCreateBinary(); - if (sem->mutex == NULL) { - LOG_WARN("%s, the mutex alloc fail", __func__); - return; - } - - return; -} - -int k_sem_take(struct k_sem *sem, s32_t timeout) -{ - assert(sem != NULL); - return osi_mutex_lock(sem->mutex, timeout); -} - -#endif /* #if CONFIG_BT_MESH */ diff --git a/components/bt/ble_mesh/mesh_core/mesh_main.c b/components/bt/ble_mesh/mesh_core/mesh_main.c index 9ce7a630b4..75a4718095 100644 --- a/components/bt/ble_mesh/mesh_core/mesh_main.c +++ b/components/bt/ble_mesh/mesh_core/mesh_main.c @@ -11,14 +11,15 @@ #include #include -#include "mesh_buf.h" #include "sdkconfig.h" +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG) -#if CONFIG_BT_MESH -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG) +#include "mesh_buf.h" #include "mesh_trace.h" - #include "mesh_main.h" +#include "mesh_hci.h" + +#include "mesh.h" #include "adv.h" #include "prov.h" #include "net.h" @@ -29,8 +30,6 @@ #include "access.h" #include "foundation.h" #include "proxy.h" -#include "mesh.h" -#include "mesh_hci.h" #include "settings.h" #include "provisioner_prov.h" #include "provisioner_proxy.h" @@ -42,7 +41,7 @@ static volatile bool provisioner_en; #define ACTION_SUSPEND 0x02 #define ACTION_EXIT 0x03 -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE int bt_mesh_provision(const u8_t net_key[16], u16_t net_idx, u8_t flags, u32_t iv_index, u32_t seq, @@ -55,13 +54,13 @@ int bt_mesh_provision(const u8_t net_key[16], u16_t net_idx, net_idx, flags, iv_index); BT_DBG("Device key: %s", bt_hex(dev_key, 16)); - if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT)) { + if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) { bt_mesh_proxy_prov_disable(); } err = bt_mesh_net_create(net_idx, flags, net_key, iv_index); if (err) { - if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT)) { + if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) { bt_mesh_proxy_prov_enable(); } @@ -74,13 +73,13 @@ int bt_mesh_provision(const u8_t net_key[16], u16_t net_idx, memcpy(bt_mesh.dev_key, dev_key, 16); - if (bt_mesh_beacon_get() == BT_MESH_BEACON_ENABLED) { + if (bt_mesh_beacon_get() == BLE_MESH_BEACON_ENABLED) { bt_mesh_beacon_enable(); } else { bt_mesh_beacon_disable(); } - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { BT_DBG("Storing network information persistently"); bt_mesh_store_net(); bt_mesh_store_subnet(&bt_mesh.sub[0]); @@ -88,8 +87,8 @@ int bt_mesh_provision(const u8_t net_key[16], u16_t net_idx, } BT_DBG("%s, gatt_proxy = %d", __func__, bt_mesh_gatt_proxy_get()); - if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY) && - bt_mesh_gatt_proxy_get() != BT_MESH_GATT_PROXY_NOT_SUPPORTED) { + if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) && + bt_mesh_gatt_proxy_get() != BLE_MESH_GATT_PROXY_NOT_SUPPORTED) { bt_mesh_proxy_gatt_enable(); bt_mesh_adv_update(); } @@ -97,28 +96,28 @@ int bt_mesh_provision(const u8_t net_key[16], u16_t net_idx, /* Add this to avoid "already active status" for bt_mesh_scan_enable() */ bt_mesh_scan_disable(); -#if defined(CONFIG_BT_MESH_USE_DUPLICATE_SCAN) +#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) /* Add Mesh beacon type (Secure Network Beacon) to the exceptional list */ - bt_mesh_update_exceptional_list(BT_MESH_EXCEP_LIST_ADD, - BT_MESH_EXCEP_INFO_MESH_BEACON, NULL); + bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD, + BLE_MESH_EXCEP_INFO_MESH_BEACON, NULL); #endif - if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) { + if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER)) { /* TODO: Enable duplicate scan in Low Power Mode */ bt_mesh_lpn_init(); } else { -#if defined(CONFIG_BT_MESH_USE_DUPLICATE_SCAN) +#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) bt_mesh_duplicate_scan_enable(); #else bt_mesh_scan_enable(); #endif } - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { + if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) { bt_mesh_friend_init(); } - if (IS_ENABLED(CONFIG_BT_MESH_PROV)) { + if (IS_ENABLED(CONFIG_BLE_MESH_PROV)) { bt_mesh_prov_complete(net_idx, addr, flags, iv_index); } @@ -128,7 +127,7 @@ int bt_mesh_provision(const u8_t net_key[16], u16_t net_idx, void bt_mesh_reset(void) { if (!bt_mesh.valid) { - BT_WARN("%s: not provisioned", __func__); + BT_WARN("%s, Not provisioned", __func__); return; } @@ -149,20 +148,20 @@ void bt_mesh_reset(void) bt_mesh_rx_reset(); bt_mesh_tx_reset(); - if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) { + if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER)) { bt_mesh_lpn_disable(true); } - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { - bt_mesh_friend_clear_net_idx(BT_MESH_KEY_ANY); + if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) { + bt_mesh_friend_clear_net_idx(BLE_MESH_KEY_ANY); } - if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) { + if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY)) { bt_mesh_proxy_gatt_disable(); } -#if defined(CONFIG_BT_MESH_SETTINGS) - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { +#if defined(CONFIG_BLE_MESH_SETTINGS) + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_clear_net(); } #endif @@ -173,7 +172,7 @@ void bt_mesh_reset(void) bt_mesh_scan_disable(); bt_mesh_beacon_disable(); - if (IS_ENABLED(CONFIG_BT_MESH_PROV)) { + if (IS_ENABLED(CONFIG_BLE_MESH_PROV)) { bt_mesh_prov_reset(); } } @@ -189,10 +188,10 @@ int bt_mesh_prov_enable(bt_mesh_prov_bearer_t bearers) return -EALREADY; } - if (IS_ENABLED(CONFIG_BT_MESH_PB_ADV) && - (bearers & BT_MESH_PROV_ADV)) { + if (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) && + (bearers & BLE_MESH_PROV_ADV)) { /* Make sure the scanning is for provisioning invitations */ -#if defined(CONFIG_BT_MESH_USE_DUPLICATE_SCAN) +#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) bt_mesh_duplicate_scan_enable(); #else bt_mesh_scan_enable(); @@ -201,8 +200,8 @@ int bt_mesh_prov_enable(bt_mesh_prov_bearer_t bearers) bt_mesh_beacon_enable(); } - if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) && - (bearers & BT_MESH_PROV_GATT)) { + if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) && + (bearers & BLE_MESH_PROV_GATT)) { bt_mesh_proxy_prov_enable(); bt_mesh_adv_update(); } @@ -218,14 +217,14 @@ int bt_mesh_prov_disable(bt_mesh_prov_bearer_t bearers) return -EALREADY; } - if (IS_ENABLED(CONFIG_BT_MESH_PB_ADV) && - (bearers & BT_MESH_PROV_ADV)) { + if (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) && + (bearers & BLE_MESH_PROV_ADV)) { bt_mesh_beacon_disable(); bt_mesh_scan_disable(); } - if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) && - (bearers & BT_MESH_PROV_GATT)) { + if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) && + (bearers & BLE_MESH_PROV_GATT)) { bt_mesh_proxy_prov_disable(); bt_mesh_adv_update(); } @@ -233,62 +232,62 @@ int bt_mesh_prov_disable(bt_mesh_prov_bearer_t bearers) return 0; } -#endif /* CONFIG_BT_MESH_NODE */ +#endif /* CONFIG_BLE_MESH_NODE */ bool bt_mesh_is_provisioner_en(void) { return provisioner_en; } -#if CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_PROVISIONER int bt_mesh_provisioner_enable(bt_mesh_prov_bearer_t bearers) { int err; if (bt_mesh_is_provisioner_en()) { - BT_ERR("Provisioner already enabled"); + BT_WARN("%s, Provisioner is already enabled", __func__); return -EALREADY; } err = provisioner_upper_init(); if (err) { - BT_ERR("%s: provisioner_upper_init fail", __func__); + BT_ERR("%s, provisioner_upper_init fail", __func__); return err; } -#if defined(CONFIG_BT_MESH_USE_DUPLICATE_SCAN) - if (IS_ENABLED(CONFIG_BT_MESH_PB_ADV) && - (bearers & BT_MESH_PROV_ADV)) { - bt_mesh_update_exceptional_list(BT_MESH_EXCEP_LIST_ADD, - BT_MESH_EXCEP_INFO_MESH_BEACON, NULL); +#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) + if (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) && + (bearers & BLE_MESH_PROV_ADV)) { + bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD, + BLE_MESH_EXCEP_INFO_MESH_BEACON, NULL); } - if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) && - (bearers & BT_MESH_PROV_GATT)) { - bt_mesh_update_exceptional_list(BT_MESH_EXCEP_LIST_ADD, - BT_MESH_EXCEP_INFO_MESH_PROV_ADV, NULL); + if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) && + (bearers & BLE_MESH_PROV_GATT)) { + bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD, + BLE_MESH_EXCEP_INFO_MESH_PROV_ADV, NULL); } - if (IS_ENABLED(CONFIG_BT_MESH_PROXY)) { - bt_mesh_update_exceptional_list(BT_MESH_EXCEP_LIST_ADD, - BT_MESH_EXCEP_INFO_MESH_PROXY_ADV, NULL); + if (IS_ENABLED(CONFIG_BLE_MESH_PROXY)) { + bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD, + BLE_MESH_EXCEP_INFO_MESH_PROXY_ADV, NULL); } #endif - if ((IS_ENABLED(CONFIG_BT_MESH_PB_ADV) && - (bearers & BT_MESH_PROV_ADV)) || - (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) && - (bearers & BT_MESH_PROV_GATT))) { -#if defined(CONFIG_BT_MESH_USE_DUPLICATE_SCAN) + 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))) { +#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) bt_mesh_duplicate_scan_enable(); #else bt_mesh_scan_enable(); #endif } - if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) && - (bearers & BT_MESH_PROV_GATT)) { + if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) && + (bearers & BLE_MESH_PROV_GATT)) { provisioner_pb_gatt_enable(); } @@ -300,19 +299,19 @@ int bt_mesh_provisioner_enable(bt_mesh_prov_bearer_t bearers) int bt_mesh_provisioner_disable(bt_mesh_prov_bearer_t bearers) { if (!bt_mesh_is_provisioner_en()) { - BT_ERR("Provisioner already disabled"); + BT_WARN("%s, Provisioner is already disabled", __func__); return -EALREADY; } - if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) && - (bearers & BT_MESH_PROV_GATT)) { + if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) && + (bearers & BLE_MESH_PROV_GATT)) { provisioner_pb_gatt_disable(); } - if ((IS_ENABLED(CONFIG_BT_MESH_PB_ADV) && - (bearers & BT_MESH_PROV_ADV)) && - (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) && - (bearers & BT_MESH_PROV_GATT))) { + 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_disable(); } @@ -321,11 +320,11 @@ int bt_mesh_provisioner_disable(bt_mesh_prov_bearer_t bearers) return 0; } -#endif /* CONFIG_BT_MESH_PROVISIONER */ +#endif /* CONFIG_BLE_MESH_PROVISIONER */ /* The following API is for fast provisioning */ -#if CONFIG_BT_MESH_FAST_PROV +#if CONFIG_BLE_MESH_FAST_PROV u8_t bt_mesh_set_fast_prov_action(u8_t action) { @@ -335,7 +334,7 @@ u8_t bt_mesh_set_fast_prov_action(u8_t action) if ((!provisioner_en && (action == ACTION_SUSPEND || action == ACTION_EXIT)) || (provisioner_en && (action == ACTION_ENTER))) { - BT_WARN("%s: action is already done", __func__); + BT_WARN("%s, Action is already done", __func__); return 0x0; } @@ -346,29 +345,29 @@ u8_t bt_mesh_set_fast_prov_action(u8_t action) * here. The node needs to send some status messages to the phone * while it is connected. */ - if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) { + if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY)) { bt_mesh_proxy_gatt_disable(); } #endif - if (bt_mesh_beacon_get() == BT_MESH_BEACON_ENABLED) { + if (bt_mesh_beacon_get() == BLE_MESH_BEACON_ENABLED) { bt_mesh_beacon_disable(); } - if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT)) { + if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) { provisioner_pb_gatt_enable(); } provisioner_set_fast_prov_flag(true); provisioner_en = true; } else { - if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT)) { + if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) { provisioner_pb_gatt_disable(); } - if (bt_mesh_beacon_get() == BT_MESH_BEACON_ENABLED) { + if (bt_mesh_beacon_get() == BLE_MESH_BEACON_ENABLED) { bt_mesh_beacon_enable(); } #if 0 /* Mesh Proxy GATT will be re-enabled on application layer */ - if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY) && - bt_mesh_gatt_proxy_get() != BT_MESH_GATT_PROXY_NOT_SUPPORTED) { + if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) && + bt_mesh_gatt_proxy_get() != BLE_MESH_GATT_PROXY_NOT_SUPPORTED) { bt_mesh_proxy_gatt_enable(); bt_mesh_adv_update(); } @@ -384,22 +383,16 @@ u8_t bt_mesh_set_fast_prov_action(u8_t action) return 0x0; } -#endif /* CONFIG_BT_MESH_FAST_PROV */ +#endif /* CONFIG_BLE_MESH_FAST_PROV */ int bt_mesh_init(const struct bt_mesh_prov *prov, const struct bt_mesh_comp *comp) { int err; - //err = bt_mesh_test(); - //if (err) { - // return err; - //} + bt_mesh_k_init(); - // The mesh kernel should be initialized first. - mesh_k_init(); - - mesh_hci_init(); + bt_mesh_hci_init(); bt_mesh_adapt_init(); @@ -414,29 +407,29 @@ int bt_mesh_init(const struct bt_mesh_prov *prov, /** Register service in the init function, * then start it according to bt_mesh_proxy_gatt_enable */ -#if CONFIG_BT_MESH_NODE - extern struct bt_gatt_service proxy_svc; - if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) { +#if CONFIG_BLE_MESH_NODE + extern struct bt_mesh_gatt_service proxy_svc; + if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY)) { bt_mesh_gatts_service_register(&proxy_svc); } /** Register service in the init function, * then start it according to bt_mesh_proxy_prov_enable */ - extern struct bt_gatt_service prov_svc; - if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT)) { + extern struct bt_mesh_gatt_service prov_svc; + if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) { bt_mesh_gatts_service_register(&prov_svc); } #endif - if (IS_ENABLED(CONFIG_BT_MESH_PROV)) { -#if CONFIG_BT_MESH_NODE + if (IS_ENABLED(CONFIG_BLE_MESH_PROV)) { +#if CONFIG_BLE_MESH_NODE err = bt_mesh_prov_init(prov); if (err) { return err; } #endif -#if CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_PROVISIONER err = provisioner_prov_init(prov); if (err) { return err; @@ -446,27 +439,29 @@ int bt_mesh_init(const struct bt_mesh_prov *prov, bt_mesh_net_init(); bt_mesh_trans_init(); -#if CONFIG_BT_MESH_NODE + +#if CONFIG_BLE_MESH_NODE /* Changed by Espressif, add random delay (0 ~ 3s) */ -#if defined(CONFIG_BT_MESH_FAST_PROV) +#if defined(CONFIG_BLE_MESH_FAST_PROV) u32_t delay = 0; bt_mesh_rand(&delay, sizeof(u32_t)); vTaskDelay((delay % 3000) / portTICK_PERIOD_MS); #endif bt_mesh_beacon_init(); #endif + bt_mesh_adv_init(); - if (IS_ENABLED(CONFIG_BT_MESH_PROXY)) { -#if CONFIG_BT_MESH_NODE + if (IS_ENABLED(CONFIG_BLE_MESH_PROXY)) { +#if CONFIG_BLE_MESH_NODE bt_mesh_proxy_init(); #endif -#if CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_PROVISIONER provisioner_proxy_init(); #endif } -#if !CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER /* If node & provisioner are both enabled and the * device starts as a node, it must finish provisioning */ err = provisioner_upper_init(); @@ -475,13 +470,11 @@ int bt_mesh_init(const struct bt_mesh_prov *prov, } #endif -#if defined(CONFIG_BT_MESH_SETTINGS) - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { +#if defined(CONFIG_BLE_MESH_SETTINGS) + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_settings_init(); } #endif return 0; } - -#endif /* #if CONFIG_BT_MESH */ diff --git a/components/bt/ble_mesh/mesh_core/mesh_slist.c b/components/bt/ble_mesh/mesh_core/mesh_slist.c deleted file mode 100644 index d80fddfc8b..0000000000 --- a/components/bt/ble_mesh/mesh_core/mesh_slist.c +++ /dev/null @@ -1,317 +0,0 @@ -/* - * Copyright (c) 2016 Intel Corporation - * Additional Copyright (c) 2018 Espressif Systems (Shanghai) PTE LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "mesh_slist.h" -#include "sdkconfig.h" -#if CONFIG_BT_MESH - -static sys_slist_t test_list; - -struct container_node { - sys_snode_t node; - int unused; -}; - -static struct container_node test_node_1; -static struct container_node test_node_2; -static struct container_node test_node_3; -static struct container_node test_node_4; - -static inline bool verify_emptyness(sys_slist_t *list) -{ - sys_snode_t *node; - sys_snode_t *s_node; - struct container_node *cnode; - struct container_node *s_cnode; - int count; - - if (!sys_slist_is_empty(list)) { - return false; - } - - if (sys_slist_peek_head(list)) { - return false; - } - - if (sys_slist_peek_tail(list)) { - return false; - } - - count = 0; - SYS_SLIST_FOR_EACH_NODE(list, node) { - count++; - } - - if (count) { - return false; - } - - SYS_SLIST_FOR_EACH_NODE_SAFE(list, node, s_node) { - count++; - } - - if (count) { - return false; - } - - count = 0; - SYS_SLIST_FOR_EACH_CONTAINER(list, cnode, node) { - count++; - } - - if (count) { - return false; - } - - count = 0; - SYS_SLIST_FOR_EACH_CONTAINER_SAFE(list, cnode, s_cnode, node) { - count++; - } - - if (count) { - return false; - } - - return true; -} - -static inline bool verify_content_amount(sys_slist_t *list, int amount) -{ - sys_snode_t *node; - sys_snode_t *s_node; - struct container_node *cnode; - struct container_node *s_cnode; - int count; - - if (sys_slist_is_empty(list)) { - return false; - } - - if (!sys_slist_peek_head(list)) { - return false; - } - - if (!sys_slist_peek_tail(list)) { - return false; - } - - count = 0; - SYS_SLIST_FOR_EACH_NODE(list, node) { - count++; - } - - if (count != amount) { - return false; - } - - count = 0; - SYS_SLIST_FOR_EACH_NODE_SAFE(list, node, s_node) { - count++; - } - - if (count != amount) { - return false; - } - - count = 0; - SYS_SLIST_FOR_EACH_CONTAINER(list, cnode, node) { - count++; - } - - if (count != amount) { - return false; - } - - count = 0; - SYS_SLIST_FOR_EACH_CONTAINER_SAFE(list, cnode, s_cnode, node) { - count++; - } - - if (count != amount) { - return false; - } - - return true; -} - -static inline bool verify_tail_head(sys_slist_t *list, - sys_snode_t *head, - sys_snode_t *tail, - bool same) -{ - if (sys_slist_peek_head(list) != head) { - return false; - } - - if (sys_slist_peek_tail(list) != tail) { - return false; - } - - if (same) { - if (sys_slist_peek_head(list) != sys_slist_peek_tail(list)) { - return false; - } - } else { - if (sys_slist_peek_head(list) == sys_slist_peek_tail(list)) { - return false; - } - } - - return true; -} - -void slist_test(void) -{ - sys_slist_init(&test_list); - - //zassert_true((verify_emptyness(&test_list)), "test_list should be empty"); - - /* Appending node 1 */ - sys_slist_append(&test_list, &test_node_1.node); - //zassert_true((verify_content_amount(&test_list, 1)), - // "test_list has wrong content"); - - //zassert_true((verify_tail_head(&test_list, &test_node_1.node, - // &test_node_1.node, true)), - // "test_list head/tail are wrong"); - - /* Finding and removing node 1 */ - sys_slist_find_and_remove(&test_list, &test_node_1.node); - //zassert_true((verify_emptyness(&test_list)), - // "test_list should be empty"); - - /* Prepending node 1 */ - sys_slist_prepend(&test_list, &test_node_1.node); - //zassert_true((verify_content_amount(&test_list, 1)), - // "test_list has wrong content"); - - //zassert_true((verify_tail_head(&test_list, &test_node_1.node, - // &test_node_1.node, true)), - // "test_list head/tail are wrong"); - - /* Removing node 1 */ - sys_slist_remove(&test_list, NULL, &test_node_1.node); - //zassert_true((verify_emptyness(&test_list)), - // "test_list should be empty"); - - /* Appending node 1 */ - sys_slist_append(&test_list, &test_node_1.node); - /* Prepending node 2 */ - sys_slist_prepend(&test_list, &test_node_2.node); - - //zassert_true((verify_content_amount(&test_list, 2)), - // "test_list has wrong content"); - - //zassert_true((verify_tail_head(&test_list, &test_node_2.node, - // &test_node_1.node, false)), - // "test_list head/tail are wrong"); - - /* Appending node 3 */ - sys_slist_append(&test_list, &test_node_3.node); - - //zassert_true((verify_content_amount(&test_list, 3)), - // "test_list has wrong content"); - - //zassert_true((verify_tail_head(&test_list, &test_node_2.node, - // &test_node_3.node, false)), - // "test_list head/tail are wrong"); - - //zassert_true((sys_slist_peek_next(&test_node_2.node) == - // &test_node_1.node), - // "test_list node links are wrong"); - - /* Inserting node 4 after node 2 */ - sys_slist_insert(&test_list, &test_node_2.node, &test_node_4.node); - - //zassert_true((verify_tail_head(&test_list, &test_node_2.node, - // &test_node_3.node, false)), - // "test_list head/tail are wrong"); - - //zassert_true((sys_slist_peek_next(&test_node_2.node) == - // &test_node_4.node), - // "test_list node links are wrong"); - - /* Finding and removing node 1 */ - sys_slist_find_and_remove(&test_list, &test_node_1.node); - //zassert_true((verify_content_amount(&test_list, 3)), - // "test_list has wrong content"); - - //zassert_true((verify_tail_head(&test_list, &test_node_2.node, - // &test_node_3.node, false)), - // "test_list head/tail are wrong"); - - /* Removing node 3 */ - sys_slist_remove(&test_list, &test_node_4.node, &test_node_3.node); - //zassert_true((verify_content_amount(&test_list, 2)), - // "test_list has wrong content"); - - //zassert_true((verify_tail_head(&test_list, &test_node_2.node, - // &test_node_4.node, false)), - // "test_list head/tail are wrong"); - - /* Removing node 4 */ - sys_slist_remove(&test_list, &test_node_2.node, &test_node_4.node); - //zassert_true((verify_content_amount(&test_list, 1)), - // "test_list has wrong content"); - - //zassert_true((verify_tail_head(&test_list, &test_node_2.node, - // &test_node_2.node, true)), - // "test_list head/tail are wrong"); - - /* Removing node 2 */ - sys_slist_remove(&test_list, NULL, &test_node_2.node); - //zassert_true((verify_emptyness(&test_list)), - // "test_list should be empty"); - - /* test iterator from a node */ - struct data_node { - sys_snode_t node; - int data; - } data_node[6] = { - { .data = 0 }, - { .data = 1 }, - { .data = 2 }, - { .data = 3 }, - { .data = 4 }, - { .data = 5 }, - }; - sys_snode_t *node = NULL; - int ii; - - sys_slist_init(&test_list); - - for (ii = 0; ii < 6; ii++) { - sys_slist_append(&test_list, &data_node[ii].node); - } - - ii = 0; - SYS_SLIST_ITERATE_FROM_NODE(&test_list, node) { - ii++; - if (((struct data_node *)node)->data == 2) { - break; - } - } - //zassert_equal(ii, 3, ""); - - ii = 0; - SYS_SLIST_ITERATE_FROM_NODE(&test_list, node) { - ii++; - if (((struct data_node *)node)->data == 3) { - break; - } - } - //zassert_equal(ii, 1, ""); - - ii = 0; - SYS_SLIST_ITERATE_FROM_NODE(&test_list, node) { - ii++; - } - //zassert_equal(ii, 2, ""); -} - -#endif /* #if CONFIG_BT_MESH */ - diff --git a/components/bt/ble_mesh/mesh_core/mesh_util.c b/components/bt/ble_mesh/mesh_core/mesh_util.c index e95676575b..4650bb2603 100644 --- a/components/bt/ble_mesh/mesh_core/mesh_util.c +++ b/components/bt/ble_mesh/mesh_core/mesh_util.c @@ -8,7 +8,6 @@ #include #include "sdkconfig.h" -#if CONFIG_BT_MESH #include "mesh_util.h" #include "mesh_kernel.h" #include "mesh_aes_encrypt.h" @@ -25,12 +24,12 @@ const char *bt_hex(const void *buf, size_t len) char *str; int i; - mask = irq_lock(); + mask = bt_mesh_irq_lock(); str = hexbufs[curbuf++]; curbuf %= ARRAY_SIZE(hexbufs); - irq_unlock(mask); + bt_mesh_irq_unlock(mask); - len = min(len, (sizeof(hexbufs[0]) - 1) / 2); + len = MIN(len, (sizeof(hexbufs[0]) - 1) / 2); for (i = 0; i < len; i++) { str[i * 2] = hex[b[i] >> 4]; @@ -85,5 +84,3 @@ int _compare(const uint8_t *a, const uint8_t *b, size_t size) } return result; } - -#endif /* #if CONFIG_BT_MESH */ diff --git a/components/bt/ble_mesh/mesh_core/net.c b/components/bt/ble_mesh/mesh_core/net.c index f58a8c816d..cc0ba7ece1 100644 --- a/components/bt/ble_mesh/mesh_core/net.c +++ b/components/bt/ble_mesh/mesh_core/net.c @@ -10,20 +10,18 @@ #include #include #include -#include "mesh_util.h" -#include "mesh_buf.h" #include "sdkconfig.h" -#if CONFIG_BT_MESH +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_NET) +#include "mesh_util.h" +#include "mesh_buf.h" #include "mesh_main.h" - -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_NET) #include "mesh_trace.h" +#include "mesh.h" #include "crypto.h" #include "adv.h" -#include "mesh.h" #include "net.h" #include "lpn.h" #include "friend.h" @@ -34,8 +32,7 @@ #include "beacon.h" #include "settings.h" #include "prov.h" - -#include "common.h" +#include "provisioner_main.h" /* Minimum valid Mesh Network PDU length. The Network headers * themselves take up 9 bytes. After that there is a minumum of 1 byte @@ -43,55 +40,55 @@ * PDUs must use a 64-bit (8 byte) NetMIC, whereas CTL=0 PDUs have at least * a 32-bit (4 byte) NetMIC and AppMIC giving again a total of 8 bytes. */ -#define BT_MESH_NET_MIN_PDU_LEN (BT_MESH_NET_HDR_LEN + 1 + 8) +#define BLE_MESH_NET_MIN_PDU_LEN (BLE_MESH_NET_HDR_LEN + 1 + 8) /* Seq limit after IV Update is triggered */ -#define IV_UPDATE_SEQ_LIMIT 8000000 +#define IV_UPDATE_SEQ_LIMIT 8000000 -#if defined(CONFIG_BT_MESH_IV_UPDATE_TEST) +#if defined(CONFIG_BLE_MESH_IV_UPDATE_TEST) /* Small test timeout for IV Update Procedure testing */ -#define IV_UPDATE_TIMEOUT K_SECONDS(120) +#define IV_UPDATE_TIMEOUT K_SECONDS(120) #else /* Maximum time to stay in IV Update mode (96 < time < 144) */ -#define IV_UPDATE_TIMEOUT K_HOURS(120) -#endif /* CONFIG_BT_MESH_IV_UPDATE_TEST */ +#define IV_UPDATE_TIMEOUT K_HOURS(120) +#endif /* CONFIG_BLE_MESH_IV_UPDATE_TEST */ #define IVI(pdu) ((pdu)[0] >> 7) #define NID(pdu) ((pdu)[0] & 0x7f) #define CTL(pdu) ((pdu)[1] >> 7) #define TTL(pdu) ((pdu)[1] & 0x7f) #define SEQ(pdu) (((u32_t)(pdu)[2] << 16) | \ - ((u32_t)(pdu)[3] << 8) | (u32_t)(pdu)[4]); + ((u32_t)(pdu)[3] << 8) | (u32_t)(pdu)[4]); #define SRC(pdu) (sys_get_be16(&(pdu)[5])) #define DST(pdu) (sys_get_be16(&(pdu)[7])) /* Determine how many friendship credentials are needed */ -#if defined(CONFIG_BT_MESH_FRIEND) -#define FRIEND_CRED_COUNT CONFIG_BT_MESH_FRIEND_LPN_COUNT -#elif defined(CONFIG_BT_MESH_LOW_POWER) -#define FRIEND_CRED_COUNT CONFIG_BT_MESH_SUBNET_COUNT +#if defined(CONFIG_BLE_MESH_FRIEND) +#define FRIEND_CRED_COUNT CONFIG_BLE_MESH_FRIEND_LPN_COUNT +#elif defined(CONFIG_BLE_MESH_LOW_POWER) +#define FRIEND_CRED_COUNT CONFIG_BLE_MESH_SUBNET_COUNT #else -#define FRIEND_CRED_COUNT 0 +#define FRIEND_CRED_COUNT 0 #endif #if FRIEND_CRED_COUNT > 0 static struct friend_cred friend_cred[FRIEND_CRED_COUNT]; #endif -static u64_t msg_cache[CONFIG_BT_MESH_MSG_CACHE_SIZE]; +static u64_t msg_cache[CONFIG_BLE_MESH_MSG_CACHE_SIZE]; static u16_t msg_cache_next; /* Singleton network context (the implementation only supports one) */ struct bt_mesh_net bt_mesh = { .local_queue = SYS_SLIST_STATIC_INIT(&bt_mesh.local_queue), .sub = { - [0 ... (CONFIG_BT_MESH_SUBNET_COUNT - 1)] = { - .net_idx = BT_MESH_KEY_UNUSED, + [0 ... (CONFIG_BLE_MESH_SUBNET_COUNT - 1)] = { + .net_idx = BLE_MESH_KEY_UNUSED, } }, .app_keys = { - [0 ... (CONFIG_BT_MESH_APP_KEY_COUNT - 1)] = { - .net_idx = BT_MESH_KEY_UNUSED, + [0 ... (CONFIG_BLE_MESH_APP_KEY_COUNT - 1)] = { + .net_idx = BLE_MESH_KEY_UNUSED, } }, }; @@ -124,7 +121,7 @@ static u64_t msg_hash(struct bt_mesh_net_rx *rx, struct net_buf_simple *pdu) u32_t hash1, hash2; /* Three least significant bytes of IVI + first byte of SEQ */ - hash1 = (BT_MESH_NET_IVI_RX(rx) << 8) | pdu->data[2]; + hash1 = (BLE_MESH_NET_IVI_RX(rx) << 8) | pdu->data[2]; /* Two last bytes of SEQ + SRC */ memcpy(&hash2, &pdu->data[3], 4); @@ -155,7 +152,7 @@ struct bt_mesh_subnet *bt_mesh_subnet_get(u16_t net_idx) { int i; - if (net_idx == BT_MESH_KEY_ANY) { + if (net_idx == BLE_MESH_KEY_ANY) { return &bt_mesh.sub[0]; } @@ -177,7 +174,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("Unable to generate NID, EncKey & PrivacyKey"); + BT_ERR("%s, Unable to generate NID, EncKey & PrivacyKey", __func__); return err; } @@ -190,16 +187,16 @@ int bt_mesh_net_keys_create(struct bt_mesh_subnet_keys *keys, err = bt_mesh_k3(key, keys->net_id); if (err) { - BT_ERR("Unable to generate Net ID"); + BT_ERR("%s, Unable to generate Net ID", __func__); return err; } BT_DBG("NetID %s", bt_hex(keys->net_id, 8)); -#if defined(CONFIG_BT_MESH_GATT_PROXY) +#if defined(CONFIG_BLE_MESH_GATT_PROXY) err = bt_mesh_identity_key(key, keys->identity); if (err) { - BT_ERR("Unable to generate IdentityKey"); + BT_ERR("%s, Unable to generate IdentityKey", __func__); return err; } @@ -208,7 +205,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("Unable to generate beacon key"); + BT_ERR("%s, Unable to generate beacon key", __func__); return err; } @@ -217,15 +214,14 @@ int bt_mesh_net_keys_create(struct bt_mesh_subnet_keys *keys, return 0; } -#if (defined(CONFIG_BT_MESH_LOW_POWER) || \ - defined(CONFIG_BT_MESH_FRIEND)) +#if (defined(CONFIG_BLE_MESH_LOW_POWER) || defined(CONFIG_BLE_MESH_FRIEND)) int friend_cred_set(struct friend_cred *cred, u8_t idx, const u8_t net_key[16]) { u16_t lpn_addr, frnd_addr; int err; u8_t p[9]; -#if defined(CONFIG_BT_MESH_LOW_POWER) +#if defined(CONFIG_BLE_MESH_LOW_POWER) if (cred->addr == bt_mesh.lpn.frnd) { lpn_addr = bt_mesh_primary_addr(); frnd_addr = cred->addr; @@ -251,7 +247,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("Unable to generate NID, EncKey & PrivacyKey"); + BT_ERR("%s, Unable to generate NID, EncKey & PrivacyKey", __func__); return err; } @@ -269,7 +265,7 @@ void friend_cred_refresh(u16_t net_idx) for (i = 0; i < ARRAY_SIZE(friend_cred); i++) { struct friend_cred *cred = &friend_cred[i]; - if (cred->addr != BT_MESH_ADDR_UNASSIGNED && + if (cred->addr != BLE_MESH_ADDR_UNASSIGNED && cred->net_idx == net_idx) { memcpy(&cred->cred[0], &cred->cred[1], sizeof(cred->cred[0])); @@ -286,7 +282,7 @@ int friend_cred_update(struct bt_mesh_subnet *sub) for (i = 0; i < ARRAY_SIZE(friend_cred); i++) { struct friend_cred *cred = &friend_cred[i]; - if (cred->addr == BT_MESH_ADDR_UNASSIGNED || + if (cred->addr == BLE_MESH_ADDR_UNASSIGNED || cred->net_idx != sub->net_idx) { continue; } @@ -309,7 +305,7 @@ struct friend_cred *friend_cred_create(struct bt_mesh_subnet *sub, u16_t addr, BT_DBG("net_idx 0x%04x addr 0x%04x", sub->net_idx, addr); for (cred = NULL, i = 0; i < ARRAY_SIZE(friend_cred); i++) { - if ((friend_cred[i].addr == BT_MESH_ADDR_UNASSIGNED) || + if ((friend_cred[i].addr == BLE_MESH_ADDR_UNASSIGNED) || (friend_cred[i].addr == addr && friend_cred[i].net_idx == sub->net_idx)) { cred = &friend_cred[i]; @@ -346,8 +342,8 @@ struct friend_cred *friend_cred_create(struct bt_mesh_subnet *sub, u16_t addr, void friend_cred_clear(struct friend_cred *cred) { - cred->net_idx = BT_MESH_KEY_UNUSED; - cred->addr = BT_MESH_ADDR_UNASSIGNED; + cred->net_idx = BLE_MESH_KEY_UNUSED; + cred->addr = BLE_MESH_ADDR_UNASSIGNED; cred->lpn_counter = 0; cred->frnd_counter = 0; memset(cred->cred, 0, sizeof(cred->cred)); @@ -383,7 +379,7 @@ int friend_cred_get(struct bt_mesh_subnet *sub, u16_t addr, u8_t *nid, continue; } - if (addr != BT_MESH_ADDR_UNASSIGNED && cred->addr != addr) { + if (addr != BLE_MESH_ADDR_UNASSIGNED && cred->addr != addr) { continue; } @@ -417,11 +413,11 @@ u8_t bt_mesh_net_flags(struct bt_mesh_subnet *sub) u8_t flags = 0x00; if (sub && sub->kr_flag) { - flags |= BT_MESH_NET_FLAG_KR; + flags |= BLE_MESH_NET_FLAG_KR; } if (bt_mesh.iv_update) { - flags |= BT_MESH_NET_FLAG_IVU; + flags |= BLE_MESH_NET_FLAG_IVU; } return flags; @@ -465,14 +461,14 @@ int bt_mesh_net_create(u16_t idx, u8_t flags, const u8_t key[16], sub = &bt_mesh.sub[0]; - sub->kr_flag = BT_MESH_KEY_REFRESH(flags); + sub->kr_flag = BLE_MESH_KEY_REFRESH(flags); if (sub->kr_flag) { err = bt_mesh_net_keys_create(&sub->keys[1], key); if (err) { return -EIO; } - sub->kr_phase = BT_MESH_KR_PHASE_2; + sub->kr_phase = BLE_MESH_KR_PHASE_2; } else { err = bt_mesh_net_keys_create(&sub->keys[0], key); if (err) { @@ -483,15 +479,15 @@ int bt_mesh_net_create(u16_t idx, u8_t flags, const u8_t key[16], bt_mesh.valid = 1; sub->net_idx = idx; - if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) { - sub->node_id = BT_MESH_NODE_IDENTITY_RUNNING; + if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY)) { + sub->node_id = BLE_MESH_NODE_IDENTITY_RUNNING; sub->node_id_start = k_uptime_get_32(); } else { - sub->node_id = BT_MESH_NODE_IDENTITY_NOT_SUPPORTED; + sub->node_id = BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED; } bt_mesh.iv_index = iv_index; - bt_mesh.iv_update = BT_MESH_IV_UPDATE(flags); + bt_mesh.iv_update = BLE_MESH_IV_UPDATE(flags); /* Set initial IV Update procedure state time-stamp */ bt_mesh.last_update = k_uptime_get(); @@ -524,7 +520,7 @@ void bt_mesh_net_revoke_keys(struct bt_mesh_subnet *sub) bool bt_mesh_kr_update(struct bt_mesh_subnet *sub, u8_t new_kr, bool new_key) { - if (new_kr != sub->kr_flag && sub->kr_phase == BT_MESH_KR_NORMAL) { + if (new_kr != sub->kr_flag && sub->kr_phase == BLE_MESH_KR_NORMAL) { BT_WARN("KR change in normal operation. Is it a case of blacklisting?"); return false; } @@ -532,14 +528,14 @@ bool bt_mesh_kr_update(struct bt_mesh_subnet *sub, u8_t new_kr, bool new_key) sub->kr_flag = new_kr; if (sub->kr_flag) { - if (sub->kr_phase == BT_MESH_KR_PHASE_1) { + if (sub->kr_phase == BLE_MESH_KR_PHASE_1) { BT_DBG("Phase 1 -> Phase 2"); - sub->kr_phase = BT_MESH_KR_PHASE_2; + sub->kr_phase = BLE_MESH_KR_PHASE_2; return true; } } else { switch (sub->kr_phase) { - case BT_MESH_KR_PHASE_1: + case BLE_MESH_KR_PHASE_1: if (!new_key) { /* Ignore */ break; @@ -551,14 +547,14 @@ bool bt_mesh_kr_update(struct bt_mesh_subnet *sub, u8_t new_kr, bool new_key) * * Intentional fall-through. */ - case BT_MESH_KR_PHASE_2: + case BLE_MESH_KR_PHASE_2: BT_DBG("KR Phase 0x%02x -> Normal", sub->kr_phase); bt_mesh_net_revoke_keys(sub); - if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER) || - IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { + if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER) || + IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) { friend_cred_refresh(sub->net_idx); } - sub->kr_phase = BT_MESH_KR_NORMAL; + sub->kr_phase = BLE_MESH_KR_NORMAL; return true; } } @@ -586,7 +582,7 @@ void bt_mesh_rpl_reset(void) } } -#if defined(CONFIG_BT_MESH_IV_UPDATE_TEST) +#if defined(CONFIG_BLE_MESH_IV_UPDATE_TEST) void bt_mesh_iv_update_test(bool enable) { bt_mesh.ivu_test = enable; @@ -595,7 +591,7 @@ void bt_mesh_iv_update_test(bool enable) bool bt_mesh_iv_update(void) { if (!bt_mesh_is_provisioned()) { - BT_ERR("Not yet provisioned"); + BT_ERR("%s, Not yet provisioned", __func__); return false; } @@ -609,18 +605,18 @@ bool bt_mesh_iv_update(void) return bt_mesh.iv_update; } -#endif /* CONFIG_BT_MESH_IV_UPDATE_TEST */ +#endif /* CONFIG_BLE_MESH_IV_UPDATE_TEST */ /* Used for sending immediate beacons to Friend queues and GATT clients */ void bt_mesh_net_sec_update(struct bt_mesh_subnet *sub) { - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { - bt_mesh_friend_sec_update(sub ? sub->net_idx : BT_MESH_KEY_ANY); + if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) { + bt_mesh_friend_sec_update(sub ? sub->net_idx : BLE_MESH_KEY_ANY); } - if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY) && - bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED) { -#if CONFIG_BT_MESH_NODE + if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) && + bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_ENABLED) { +#if CONFIG_BLE_MESH_NODE bt_mesh_proxy_beacon_send(sub); #endif } @@ -685,7 +681,7 @@ bool bt_mesh_net_iv_update(u32_t iv_index, bool iv_update) } } - if (!IS_ENABLED(CONFIG_BT_MESH_IV_UPDATE_TEST) || !bt_mesh.ivu_test) { + if (!IS_ENABLED(CONFIG_BLE_MESH_IV_UPDATE_TEST) || !bt_mesh.ivu_test) { s64_t delta = k_uptime_get() - bt_mesh.last_update; if (delta < K_HOURS(96)) { @@ -718,7 +714,7 @@ do_update: bt_mesh.seq = 0; k_delayed_work_cancel(&bt_mesh.ivu_complete); - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_seq(); } @@ -728,12 +724,12 @@ do_update: bt_mesh.last_update = k_uptime_get(); for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) { - if (bt_mesh.sub[i].net_idx != BT_MESH_KEY_UNUSED) { + if (bt_mesh.sub[i].net_idx != BLE_MESH_KEY_UNUSED) { bt_mesh_net_beacon_update(&bt_mesh.sub[i]); } } - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { bt_mesh_store_iv(); } @@ -765,15 +761,15 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf, enc = sub->keys[new_key].enc; priv = sub->keys[new_key].privacy; - err = bt_mesh_net_obfuscate(buf->data, BT_MESH_NET_IVI_TX, priv); + err = bt_mesh_net_obfuscate(buf->data, BLE_MESH_NET_IVI_TX, priv); if (err) { - BT_ERR("deobfuscate failed (err %d)", err); + BT_ERR("%s, De-obfuscate failed (err %d)", __func__, err); return err; } - err = bt_mesh_net_decrypt(enc, &buf->b, BT_MESH_NET_IVI_TX, false); + err = bt_mesh_net_decrypt(enc, &buf->b, BLE_MESH_NET_IVI_TX, false); if (err) { - BT_ERR("decrypt failed (err %d)", err); + BT_ERR("%s, Decrypt failed (err %d)", __func__, err); return err; } @@ -783,22 +779,22 @@ int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf, buf->data[3] = seq >> 8; buf->data[4] = seq; - err = bt_mesh_net_encrypt(enc, &buf->b, BT_MESH_NET_IVI_TX, false); + err = bt_mesh_net_encrypt(enc, &buf->b, BLE_MESH_NET_IVI_TX, false); if (err) { - BT_ERR("encrypt failed (err %d)", err); + BT_ERR("%s, Encrypt failed (err %d)", __func__, err); return err; } - err = bt_mesh_net_obfuscate(buf->data, BT_MESH_NET_IVI_TX, priv); + err = bt_mesh_net_obfuscate(buf->data, BLE_MESH_NET_IVI_TX, priv); if (err) { - BT_ERR("obfuscate failed (err %d)", err); + BT_ERR("%s, Obfuscate failed (err %d)", __func__, err); return err; } bt_mesh_adv_send(buf, cb, cb_data); if (!bt_mesh.iv_update && bt_mesh.seq > IV_UPDATE_SEQ_LIMIT) { -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE bt_mesh_beacon_ivu_initiator(true); #endif bt_mesh_net_iv_update(bt_mesh.iv_index + 1, true); @@ -814,7 +810,7 @@ static void bt_mesh_net_local(struct k_work *work) while ((buf = net_buf_slist_get(&bt_mesh.local_queue))) { BT_DBG("len %u: %s", buf->len, bt_hex(buf->data, buf->len)); - bt_mesh_net_recv(&buf->b, 0, BT_MESH_NET_IF_LOCAL); + bt_mesh_net_recv(&buf->b, 0, BLE_MESH_NET_IF_LOCAL); net_buf_unref(buf); } } @@ -822,7 +818,7 @@ static void bt_mesh_net_local(struct k_work *work) int bt_mesh_net_encode(struct bt_mesh_net_tx *tx, struct net_buf_simple *buf, bool proxy) { - const bool ctl = (tx->ctx->app_idx == BT_MESH_KEY_UNUSED); + const bool ctl = (tx->ctx->app_idx == BLE_MESH_KEY_UNUSED); u32_t seq_val; u8_t nid; const u8_t *enc, *priv; @@ -830,10 +826,10 @@ int bt_mesh_net_encode(struct bt_mesh_net_tx *tx, struct net_buf_simple *buf, int err; if (ctl && net_buf_simple_tailroom(buf) < 8) { - BT_ERR("Insufficient MIC space for CTL PDU"); + BT_ERR("%s, Insufficient MIC space for CTL PDU", __func__); return -EINVAL; } else if (net_buf_simple_tailroom(buf) < 4) { - BT_ERR("Insufficient MIC space for PDU"); + BT_ERR("%s, Insufficient MIC space for PDU", __func__); return -EINVAL; } @@ -855,8 +851,8 @@ int bt_mesh_net_encode(struct bt_mesh_net_tx *tx, struct net_buf_simple *buf, net_buf_simple_push_u8(buf, tx->ctx->send_ttl); } - if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER) && tx->friend_cred) { - if (friend_cred_get(tx->sub, BT_MESH_ADDR_UNASSIGNED, + if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER) && tx->friend_cred) { + if (friend_cred_get(tx->sub, BLE_MESH_ADDR_UNASSIGNED, &nid, &enc, &priv)) { BT_WARN("Falling back to master credentials"); @@ -873,14 +869,14 @@ int bt_mesh_net_encode(struct bt_mesh_net_tx *tx, struct net_buf_simple *buf, priv = tx->sub->keys[tx->sub->kr_flag].privacy; } - net_buf_simple_push_u8(buf, (nid | (BT_MESH_NET_IVI_TX & 1) << 7)); + net_buf_simple_push_u8(buf, (nid | (BLE_MESH_NET_IVI_TX & 1) << 7)); - err = bt_mesh_net_encrypt(enc, buf, BT_MESH_NET_IVI_TX, proxy); + err = bt_mesh_net_encrypt(enc, buf, BLE_MESH_NET_IVI_TX, proxy); if (err) { return err; } - return bt_mesh_net_obfuscate(buf->data, BT_MESH_NET_IVI_TX, priv); + return bt_mesh_net_obfuscate(buf->data, BLE_MESH_NET_IVI_TX, priv); } int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf, @@ -894,7 +890,7 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf, BT_DBG("Payload len %u: %s", buf->len, bt_hex(buf->data, buf->len)); BT_DBG("Seq 0x%06x", bt_mesh.seq); - if (tx->ctx->send_ttl == BT_MESH_TTL_DEFAULT) { + if (tx->ctx->send_ttl == BLE_MESH_TTL_DEFAULT) { tx->ctx->send_ttl = bt_mesh_default_ttl_get(); } @@ -907,12 +903,12 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf, * "The output filter of the interface connected to advertising or * GATT bearers shall drop all messages with TTL value set to 1." */ -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE if (bt_mesh_is_provisioned()) { - if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY) && + if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) && tx->ctx->send_ttl != 1) { if (bt_mesh_proxy_relay(&buf->b, tx->ctx->addr) && - BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) { + BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) { /* Notify completion if this only went * through the Mesh Proxy. */ @@ -989,7 +985,7 @@ struct bt_mesh_subnet *bt_mesh_subnet_find(const u8_t net_id[8], u8_t flags, for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) { struct bt_mesh_subnet *sub = &bt_mesh.sub[i]; - if (sub->net_idx == BT_MESH_KEY_UNUSED) { + if (sub->net_idx == BLE_MESH_KEY_UNUSED) { continue; } @@ -998,7 +994,7 @@ struct bt_mesh_subnet *bt_mesh_subnet_find(const u8_t net_id[8], u8_t flags, return sub; } - if (sub->kr_phase == BT_MESH_KR_NORMAL) { + if (sub->kr_phase == BLE_MESH_KR_NORMAL) { continue; } @@ -1024,7 +1020,7 @@ static int net_decrypt(struct bt_mesh_subnet *sub, const u8_t *enc, net_buf_simple_init(buf, 0); memcpy(net_buf_simple_add(buf, data_len), data, data_len); - if (bt_mesh_net_obfuscate(buf->data, BT_MESH_NET_IVI_RX(rx), priv)) { + if (bt_mesh_net_obfuscate(buf->data, BLE_MESH_NET_IVI_RX(rx), priv)) { return -ENOENT; } @@ -1033,34 +1029,33 @@ static int net_decrypt(struct bt_mesh_subnet *sub, const u8_t *enc, * to be filtered here. So when a device is re-provisioned, the related * msg_cache should be cleared. Will do it later. */ - if (rx->net_if == BT_MESH_NET_IF_ADV && msg_cache_match(rx, buf)) { + if (rx->net_if == BLE_MESH_NET_IF_ADV && msg_cache_match(rx, buf)) { BT_WARN("Duplicate found in Network Message Cache"); return -EALREADY; } rx->ctx.addr = SRC(buf->data); - if (!BT_MESH_ADDR_IS_UNICAST(rx->ctx.addr)) { + if (!BLE_MESH_ADDR_IS_UNICAST(rx->ctx.addr)) { BT_WARN("Ignoring non-unicast src addr 0x%04x", rx->ctx.addr); return -EINVAL; } BT_DBG("src 0x%04x", rx->ctx.addr); -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE if (bt_mesh_is_provisioned()) { - if (IS_ENABLED(CONFIG_BT_MESH_PROXY) && - rx->net_if == BT_MESH_NET_IF_PROXY_CFG) { - return bt_mesh_net_decrypt(enc, buf, BT_MESH_NET_IVI_RX(rx), + if (IS_ENABLED(CONFIG_BLE_MESH_PROXY) && + rx->net_if == BLE_MESH_NET_IF_PROXY_CFG) { + return bt_mesh_net_decrypt(enc, buf, BLE_MESH_NET_IVI_RX(rx), true); } } #endif - return bt_mesh_net_decrypt(enc, buf, BT_MESH_NET_IVI_RX(rx), false); + return bt_mesh_net_decrypt(enc, buf, BLE_MESH_NET_IVI_RX(rx), false); } -#if (defined(CONFIG_BT_MESH_LOW_POWER) || \ - defined(CONFIG_BT_MESH_FRIEND)) +#if (defined(CONFIG_BLE_MESH_LOW_POWER) || defined(CONFIG_BLE_MESH_FRIEND)) static int friend_decrypt(struct bt_mesh_subnet *sub, const u8_t *data, size_t data_len, struct bt_mesh_net_rx *rx, struct net_buf_simple *buf) @@ -1082,7 +1077,7 @@ static int friend_decrypt(struct bt_mesh_subnet *sub, const u8_t *data, return 0; } - if (sub->kr_phase == BT_MESH_KR_NORMAL) { + if (sub->kr_phase == BLE_MESH_KR_NORMAL) { continue; } @@ -1108,19 +1103,19 @@ static bool net_find_and_decrypt(const u8_t *data, size_t data_len, BT_DBG("%s", __func__); -#if CONFIG_BT_MESH_NODE && !CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER if (!bt_mesh_is_provisioner_en()) { array_size = ARRAY_SIZE(bt_mesh.sub); } #endif -#if !CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (bt_mesh_is_provisioner_en()) { array_size = ARRAY_SIZE(bt_mesh.p_sub); } #endif -#if CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER array_size = ARRAY_SIZE(bt_mesh.sub); if (bt_mesh_is_provisioner_en()) { array_size += ARRAY_SIZE(bt_mesh.p_sub); @@ -1128,24 +1123,24 @@ static bool net_find_and_decrypt(const u8_t *data, size_t data_len, #endif if (!array_size) { - BT_ERR("%s: Get sub array_size fail", __func__); + BT_ERR("%s, Unable to get subnet size", __func__); return false; } for (i = 0; i < array_size; i++) { -#if CONFIG_BT_MESH_NODE && !CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER if (!bt_mesh_is_provisioner_en()) { sub = &bt_mesh.sub[i]; } #endif -#if !CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (bt_mesh_is_provisioner_en()) { sub = bt_mesh.p_sub[i]; } #endif -#if CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (i < ARRAY_SIZE(bt_mesh.sub)) { sub = &bt_mesh.sub[i]; } else { @@ -1154,18 +1149,17 @@ static bool net_find_and_decrypt(const u8_t *data, size_t data_len, #endif if (!sub) { - BT_DBG("%s: get NULL sub", __func__); + BT_DBG("%s, NULL subnet", __func__); continue; } - if (sub->net_idx == BT_MESH_KEY_UNUSED) { + if (sub->net_idx == BLE_MESH_KEY_UNUSED) { continue; } -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE if (bt_mesh_is_provisioned()) { -#if (defined(CONFIG_BT_MESH_LOW_POWER) || \ - defined(CONFIG_BT_MESH_FRIEND)) +#if (defined(CONFIG_BLE_MESH_LOW_POWER) || defined(CONFIG_BLE_MESH_FRIEND)) if (!friend_decrypt(sub, data, data_len, rx, buf)) { rx->friend_cred = 1; rx->ctx.net_idx = sub->net_idx; @@ -1174,7 +1168,7 @@ static bool net_find_and_decrypt(const u8_t *data, size_t data_len, } #endif } -#endif /* CONFIG_BT_MESH_NODE */ +#endif /* CONFIG_BLE_MESH_NODE */ if (NID(data) == sub->keys[0].nid && !net_decrypt(sub, sub->keys[0].enc, sub->keys[0].privacy, @@ -1184,7 +1178,7 @@ static bool net_find_and_decrypt(const u8_t *data, size_t data_len, return true; } - if (sub->kr_phase == BT_MESH_KR_NORMAL) { + if (sub->kr_phase == BLE_MESH_KR_NORMAL) { continue; } @@ -1206,17 +1200,17 @@ static bool net_find_and_decrypt(const u8_t *data, size_t data_len, * get sent to the advertising bearer. If the packet came in through GATT, * then it should only be relayed if the GATT Proxy state is enabled. */ -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE static bool relay_to_adv(enum bt_mesh_net_if net_if) { switch (net_if) { - case BT_MESH_NET_IF_LOCAL: + case BLE_MESH_NET_IF_LOCAL: return true; - case BT_MESH_NET_IF_ADV: - return (bt_mesh_relay_get() == BT_MESH_RELAY_ENABLED); - case BT_MESH_NET_IF_PROXY: - return (bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED); + case BLE_MESH_NET_IF_ADV: + return (bt_mesh_relay_get() == BLE_MESH_RELAY_ENABLED); + case BLE_MESH_NET_IF_PROXY: + return (bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_ENABLED); default: return false; } @@ -1229,7 +1223,7 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf, struct net_buf *buf; u8_t nid, transmit; - if (rx->net_if == BT_MESH_NET_IF_LOCAL) { + if (rx->net_if == BLE_MESH_NET_IF_LOCAL) { /* Locally originated PDUs with TTL=1 will only be delivered * to local elements as per Mesh Profile 1.0 section 3.4.5.2: * "The output filter of the interface connected to @@ -1245,9 +1239,9 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf, } } - if (rx->net_if == BT_MESH_NET_IF_ADV && - bt_mesh_relay_get() != BT_MESH_RELAY_ENABLED && - bt_mesh_gatt_proxy_get() != BT_MESH_GATT_PROXY_ENABLED) { + if (rx->net_if == BLE_MESH_NET_IF_ADV && + bt_mesh_relay_get() != BLE_MESH_RELAY_ENABLED && + bt_mesh_gatt_proxy_get() != BLE_MESH_GATT_PROXY_ENABLED) { return; } @@ -1257,22 +1251,22 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf, * Anything else (like GATT to adv, or locally originated packets) * use the Network Transmit state. */ - if (rx->net_if == BT_MESH_NET_IF_ADV) { + if (rx->net_if == BLE_MESH_NET_IF_ADV) { transmit = bt_mesh_relay_retransmit_get(); } else { transmit = bt_mesh_net_transmit_get(); } - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, - BT_MESH_TRANSMIT_COUNT(transmit), - BT_MESH_TRANSMIT_INT(transmit), K_NO_WAIT); + buf = bt_mesh_adv_create(BLE_MESH_ADV_DATA, + BLE_MESH_TRANSMIT_COUNT(transmit), + BLE_MESH_TRANSMIT_INT(transmit), K_NO_WAIT); if (!buf) { - BT_ERR("Out of relay buffers"); + BT_ERR("%s, Out of relay buffers", __func__); return; } /* Only decrement TTL for non-locally originated packets */ - if (rx->net_if != BT_MESH_NET_IF_LOCAL) { + if (rx->net_if != BLE_MESH_NET_IF_LOCAL) { /* Leave CTL bit intact */ sbuf->data[1] &= 0x80; sbuf->data[1] |= rx->ctx.recv_ttl - 1; @@ -1296,24 +1290,24 @@ static void bt_mesh_net_relay(struct net_buf_simple *sbuf, * the normal TX IVI (which may be different) since the transport * layer nonce includes the IVI. */ - if (bt_mesh_net_encrypt(enc, &buf->b, BT_MESH_NET_IVI_RX(rx), false)) { - BT_ERR("Re-encrypting failed"); + if (bt_mesh_net_encrypt(enc, &buf->b, BLE_MESH_NET_IVI_RX(rx), false)) { + BT_ERR("%s, Re-encrypting failed", __func__); goto done; } - if (bt_mesh_net_obfuscate(buf->data, BT_MESH_NET_IVI_RX(rx), priv)) { - BT_ERR("Re-obfuscating failed"); + if (bt_mesh_net_obfuscate(buf->data, BLE_MESH_NET_IVI_RX(rx), priv)) { + BT_ERR("%s, Re-obfuscating failed", __func__); goto done; } /* Sending to GATT bearer should only occur if GATT Proxy * is enabled or the message originates from a local node. */ - if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY) && - (bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED || - rx->net_if == BT_MESH_NET_IF_LOCAL)) { + if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) && + (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->dst) && - BT_MESH_ADDR_IS_UNICAST(rx->dst)) { + BLE_MESH_ADDR_IS_UNICAST(rx->dst)) { goto done; } } @@ -1326,18 +1320,18 @@ done: net_buf_unref(buf); } -#endif /* CONFIG_BT_MESH_NODE */ +#endif /* CONFIG_BLE_MESH_NODE */ int bt_mesh_net_decode(struct net_buf_simple *data, enum bt_mesh_net_if net_if, struct bt_mesh_net_rx *rx, struct net_buf_simple *buf) { - if (data->len < BT_MESH_NET_MIN_PDU_LEN) { + if (data->len < BLE_MESH_NET_MIN_PDU_LEN) { BT_WARN("Dropping a too short mesh packet (len %u)", data->len); BT_WARN("%s", bt_hex(data->data, data->len)); return -EINVAL; } - if (net_if == BT_MESH_NET_IF_ADV && check_dup(data)) { + if (net_if == BLE_MESH_NET_IF_ADV && check_dup(data)) { return -EINVAL; } @@ -1351,7 +1345,7 @@ int bt_mesh_net_decode(struct net_buf_simple *data, enum bt_mesh_net_if net_if, } /* Initialize AppIdx to a reasonable value */ - rx->ctx.app_idx = BT_MESH_KEY_UNUSED; + rx->ctx.app_idx = BLE_MESH_KEY_UNUSED; rx->ctx.recv_ttl = TTL(buf->data); @@ -1359,7 +1353,7 @@ int bt_mesh_net_decode(struct net_buf_simple *data, enum bt_mesh_net_if net_if, if (rx->ctx.recv_ttl == 0) { rx->ctx.send_ttl = 0; } else { - rx->ctx.send_ttl = BT_MESH_TTL_DEFAULT; + rx->ctx.send_ttl = BLE_MESH_TTL_DEFAULT; } rx->ctl = CTL(buf->data); @@ -1368,18 +1362,18 @@ int bt_mesh_net_decode(struct net_buf_simple *data, enum bt_mesh_net_if net_if, BT_DBG("Decryption successful. Payload len %u", buf->len); - if (net_if != BT_MESH_NET_IF_PROXY_CFG && - rx->dst == BT_MESH_ADDR_UNASSIGNED) { - BT_ERR("Destination address is unassigned; dropping packet"); + if (net_if != BLE_MESH_NET_IF_PROXY_CFG && + rx->dst == BLE_MESH_ADDR_UNASSIGNED) { + BT_ERR("%s, Destination address is unassigned; dropping packet", __func__); return -EBADMSG; } - if (BT_MESH_ADDR_IS_RFU(rx->dst)) { - BT_ERR("Destination address is RFU; dropping packet"); + if (BLE_MESH_ADDR_IS_RFU(rx->dst)) { + BT_ERR("%s, Destination address is RFU; dropping packet", __func__); return -EBADMSG; } - if (net_if != BT_MESH_NET_IF_LOCAL && bt_mesh_elem_find(rx->ctx.addr)) { + if (net_if != BLE_MESH_NET_IF_LOCAL && bt_mesh_elem_find(rx->ctx.addr)) { BT_DBG("Dropping locally originated packet"); return -EBADMSG; } @@ -1400,7 +1394,7 @@ void bt_mesh_net_recv(struct net_buf_simple *data, s8_t rssi, BT_DBG("rssi %d net_if %u", rssi, net_if); -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE if (!bt_mesh_is_provisioner_en()) { if (!bt_mesh_is_provisioned()) { return; @@ -1408,9 +1402,9 @@ void bt_mesh_net_recv(struct net_buf_simple *data, s8_t rssi, } #endif -#if !CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (!bt_mesh_is_provisioner_en()) { - BT_WARN("%s: provisioner disabled", __func__); + BT_WARN("%s, Provisioner is disabled", __func__); return; } if (!provisioner_get_prov_node_count()) { @@ -1425,10 +1419,10 @@ void bt_mesh_net_recv(struct net_buf_simple *data, s8_t rssi, /* Save the state so the buffer can later be relayed */ net_buf_simple_save(buf, &state); -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE if (bt_mesh_is_provisioned()) { - if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY) && - net_if == BT_MESH_NET_IF_PROXY) { + if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) && + net_if == BLE_MESH_NET_IF_PROXY) { bt_mesh_proxy_addr_add(data, rx.ctx.addr); } } @@ -1442,9 +1436,9 @@ void bt_mesh_net_recv(struct net_buf_simple *data, s8_t rssi, /* Relay if this is a group/virtual address, or if the destination * is neither a local element nor an Friend's LPN. */ -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE if (bt_mesh_is_provisioned()) { - if (!BT_MESH_ADDR_IS_UNICAST(rx.dst) || + if (!BLE_MESH_ADDR_IS_UNICAST(rx.dst) || (!rx.local_match && !rx.friend_match)) { net_buf_simple_restore(buf, &state); bt_mesh_net_relay(buf, &rx); @@ -1457,49 +1451,49 @@ static void ivu_complete(struct k_work *work) { BT_DBG("%s", __func__); -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE bt_mesh_beacon_ivu_initiator(true); #endif bt_mesh_net_iv_update(bt_mesh.iv_index, false); } -#if defined(CONFIG_BT_MESH_NODE) +#if defined(CONFIG_BLE_MESH_NODE) void bt_mesh_net_start(void) { - if (bt_mesh_beacon_get() == BT_MESH_BEACON_ENABLED) { + if (bt_mesh_beacon_get() == BLE_MESH_BEACON_ENABLED) { bt_mesh_beacon_enable(); } else { bt_mesh_beacon_disable(); } - if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY) && - bt_mesh_gatt_proxy_get() != BT_MESH_GATT_PROXY_NOT_SUPPORTED) { + if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY) && + bt_mesh_gatt_proxy_get() != BLE_MESH_GATT_PROXY_NOT_SUPPORTED) { bt_mesh_proxy_gatt_enable(); bt_mesh_adv_update(); } -#if defined(CONFIG_BT_MESH_USE_DUPLICATE_SCAN) +#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) /* Add Mesh beacon type (Secure Network Beacon) to the exceptional list */ - bt_mesh_update_exceptional_list(BT_MESH_EXCEP_LIST_ADD, - BT_MESH_EXCEP_INFO_MESH_BEACON, NULL); + bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD, + BLE_MESH_EXCEP_INFO_MESH_BEACON, NULL); #endif - if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER)) { + if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER)) { /* TODO: Enable duplicate scan in Low Power Mode */ bt_mesh_lpn_init(); } else { -#if defined(CONFIG_BT_MESH_USE_DUPLICATE_SCAN) +#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) bt_mesh_duplicate_scan_enable(); #else bt_mesh_scan_enable(); #endif } - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { + if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) { bt_mesh_friend_init(); } - if (IS_ENABLED(CONFIG_BT_MESH_PROV)) { + if (IS_ENABLED(CONFIG_BLE_MESH_PROV)) { u16_t net_idx = bt_mesh.sub[0].net_idx; u16_t addr = bt_mesh_primary_addr(); u8_t flags = (bt_mesh.iv_update << 1) | bt_mesh.sub[0].kr_flag; @@ -1516,5 +1510,3 @@ void bt_mesh_net_init(void) k_work_init(&bt_mesh.local_work, bt_mesh_net_local); } - -#endif /* #if CONFIG_BT_MESH */ diff --git a/components/bt/ble_mesh/mesh_core/net.h b/components/bt/ble_mesh/mesh_core/net.h index 897f3775e9..9bedf9fcf6 100644 --- a/components/bt/ble_mesh/mesh_core/net.h +++ b/components/bt/ble_mesh/mesh_core/net.h @@ -9,33 +9,34 @@ #ifndef _NET_H_ #define _NET_H_ + #include "mesh_util.h" #include "mesh_kernel.h" #include "mesh_access.h" -#define BT_MESH_NET_FLAG_KR BIT(0) -#define BT_MESH_NET_FLAG_IVU BIT(1) +#define BLE_MESH_NET_FLAG_KR BIT(0) +#define BLE_MESH_NET_FLAG_IVU BIT(1) -#define BT_MESH_KR_NORMAL 0x00 -#define BT_MESH_KR_PHASE_1 0x01 -#define BT_MESH_KR_PHASE_2 0x02 -#define BT_MESH_KR_PHASE_3 0x03 +#define BLE_MESH_KR_NORMAL 0x00 +#define BLE_MESH_KR_PHASE_1 0x01 +#define BLE_MESH_KR_PHASE_2 0x02 +#define BLE_MESH_KR_PHASE_3 0x03 -#define BT_MESH_IV_UPDATE(flags) ((flags >> 1) & 0x01) -#define BT_MESH_KEY_REFRESH(flags) (flags & 0x01) +#define BLE_MESH_IV_UPDATE(flags) ((flags >> 1) & 0x01) +#define BLE_MESH_KEY_REFRESH(flags) (flags & 0x01) /* Special time-stamp to indicate that we don't know when the last IV * Update happened. */ -#define BT_MESH_NET_IVU_UNKNOWN -1 +#define BLE_MESH_NET_IVU_UNKNOWN -1 -#if defined(CONFIG_BT_MESH_IV_UPDATE_TEST) +#if defined(CONFIG_BLE_MESH_IV_UPDATE_TEST) /* Small test timeout for IV Update Procedure testing */ -#define BT_MESH_NET_IVU_TIMEOUT K_SECONDS(120) +#define BLE_MESH_NET_IVU_TIMEOUT K_SECONDS(120) #else /* Maximum time to stay in IV Update mode (96 < time < 144) */ -#define BT_MESH_NET_IVU_TIMEOUT K_HOURS(120) -#endif /* CONFIG_BT_MESH_IV_UPDATE_TEST */ +#define BLE_MESH_NET_IVU_TIMEOUT K_HOURS(120) +#endif /* CONFIG_BLE_MESH_IV_UPDATE_TEST */ struct bt_mesh_app_key { u16_t net_idx; @@ -73,7 +74,7 @@ struct bt_mesh_subnet { u8_t nid; /* NID */ u8_t enc[16]; /* EncKey */ u8_t net_id[8]; /* Network ID */ -#if defined(CONFIG_BT_MESH_GATT_PROXY) +#if defined(CONFIG_BLE_MESH_GATT_PROXY) u8_t identity[16]; /* IdentityKey */ #endif u8_t privacy[16]; /* PrivacyKey */ @@ -84,15 +85,15 @@ struct bt_mesh_subnet { struct bt_mesh_rpl { u16_t src; bool old_iv; -#if defined(CONFIG_BT_MESH_SETTINGS) +#if defined(CONFIG_BLE_MESH_SETTINGS) bool store; #endif u32_t seq; }; -#if defined(CONFIG_BT_MESH_FRIEND) -#define FRIEND_SEG_RX CONFIG_BT_MESH_FRIEND_SEG_RX -#define FRIEND_SUB_LIST_SIZE CONFIG_BT_MESH_FRIEND_SUB_LIST_SIZE +#if defined(CONFIG_BLE_MESH_FRIEND) +#define FRIEND_SEG_RX CONFIG_BLE_MESH_FRIEND_SEG_RX +#define FRIEND_SUB_LIST_SIZE CONFIG_BLE_MESH_FRIEND_SUB_LIST_SIZE #else #define FRIEND_SEG_RX 0 #define FRIEND_SUB_LIST_SIZE 0 @@ -137,8 +138,8 @@ struct bt_mesh_friend { } clear; }; -#if defined(CONFIG_BT_MESH_LOW_POWER) -#define LPN_GROUPS CONFIG_BT_MESH_LOW_POWER +#if defined(CONFIG_BLE_MESH_LOW_POWER) +#define LPN_GROUPS CONFIG_BLE_MESH_LOW_POWER #else #define LPN_GROUPS 0 #endif @@ -146,16 +147,16 @@ struct bt_mesh_friend { /* Low Power Node state */ struct bt_mesh_lpn { enum __packed { - BT_MESH_LPN_DISABLED, /* LPN feature is disabled */ - BT_MESH_LPN_CLEAR, /* Clear in progress */ - BT_MESH_LPN_TIMER, /* Waiting for auto timer expiry */ - BT_MESH_LPN_ENABLED, /* LPN enabled, but no Friend */ - BT_MESH_LPN_REQ_WAIT, /* Wait before scanning for offers */ - BT_MESH_LPN_WAIT_OFFER, /* Friend Req sent */ - BT_MESH_LPN_ESTABLISHED, /* Friendship established */ - BT_MESH_LPN_RECV_DELAY, /* Poll sent, waiting ReceiveDelay */ - BT_MESH_LPN_WAIT_UPDATE, /* Waiting for Update or message */ - BT_MESH_LPN_OFFER_RECV, /* Friend offer received */ + BLE_MESH_LPN_DISABLED, /* LPN feature is disabled */ + BLE_MESH_LPN_CLEAR, /* Clear in progress */ + BLE_MESH_LPN_TIMER, /* Waiting for auto timer expiry */ + BLE_MESH_LPN_ENABLED, /* LPN enabled, but no Friend */ + BLE_MESH_LPN_REQ_WAIT, /* Wait before scanning for offers */ + BLE_MESH_LPN_WAIT_OFFER, /* Friend Req sent */ + BLE_MESH_LPN_ESTABLISHED, /* Friendship established */ + BLE_MESH_LPN_RECV_DELAY, /* Poll sent, waiting ReceiveDelay */ + BLE_MESH_LPN_WAIT_UPDATE, /* Waiting for Update or message */ + BLE_MESH_LPN_OFFER_RECV, /* Friend offer received */ } state; /* Transaction Number (used for subscription list) */ @@ -201,24 +202,24 @@ struct bt_mesh_lpn { u16_t groups[LPN_GROUPS]; /* Bit fields for tracking which groups the Friend knows about */ - ATOMIC_DEFINE(added, LPN_GROUPS); - ATOMIC_DEFINE(pending, LPN_GROUPS); - ATOMIC_DEFINE(to_remove, LPN_GROUPS); + BLE_MESH_ATOMIC_DEFINE(added, LPN_GROUPS); + BLE_MESH_ATOMIC_DEFINE(pending, LPN_GROUPS); + BLE_MESH_ATOMIC_DEFINE(to_remove, LPN_GROUPS); }; /* bt_mesh_net.flags, mainly used for pending storage actions */ enum { - BT_MESH_RPL_PENDING, - BT_MESH_KEYS_PENDING, - BT_MESH_NET_PENDING, - BT_MESH_IV_PENDING, - BT_MESH_SEQ_PENDING, - BT_MESH_HB_PUB_PENDING, - BT_MESH_CFG_PENDING, - BT_MESH_MOD_PENDING, + BLE_MESH_RPL_PENDING, + BLE_MESH_KEYS_PENDING, + BLE_MESH_NET_PENDING, + BLE_MESH_IV_PENDING, + BLE_MESH_SEQ_PENDING, + BLE_MESH_HB_PUB_PENDING, + BLE_MESH_CFG_PENDING, + BLE_MESH_MOD_PENDING, /* Don't touch - intentionally last */ - BT_MESH_FLAG_COUNT, + BLE_MESH_FLAG_COUNT, }; struct bt_mesh_net { @@ -232,18 +233,18 @@ struct bt_mesh_net { s64_t last_update; /* Time since last IV Update change */ - ATOMIC_DEFINE(flags, BT_MESH_FLAG_COUNT); + BLE_MESH_ATOMIC_DEFINE(flags, BLE_MESH_FLAG_COUNT); /* Local network interface */ struct k_work local_work; sys_slist_t local_queue; -#if defined(CONFIG_BT_MESH_FRIEND) +#if defined(CONFIG_BLE_MESH_FRIEND) /* Friend state, unique for each LPN that we're Friends for */ - struct bt_mesh_friend frnd[CONFIG_BT_MESH_FRIEND_LPN_COUNT]; + struct bt_mesh_friend frnd[CONFIG_BLE_MESH_FRIEND_LPN_COUNT]; #endif -#if defined(CONFIG_BT_MESH_LOW_POWER) +#if defined(CONFIG_BLE_MESH_LOW_POWER) struct bt_mesh_lpn lpn; /* Low Power Node state */ #endif @@ -252,22 +253,22 @@ struct bt_mesh_net { u8_t dev_key[16]; - struct bt_mesh_app_key app_keys[CONFIG_BT_MESH_APP_KEY_COUNT]; + struct bt_mesh_app_key app_keys[CONFIG_BLE_MESH_APP_KEY_COUNT]; - struct bt_mesh_subnet sub[CONFIG_BT_MESH_SUBNET_COUNT]; + struct bt_mesh_subnet sub[CONFIG_BLE_MESH_SUBNET_COUNT]; - struct bt_mesh_rpl rpl[CONFIG_BT_MESH_CRPL]; + struct bt_mesh_rpl rpl[CONFIG_BLE_MESH_CRPL]; -#if CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_PROVISIONER /* Provisioner and node share arguments from 'iv_index' to 'local_queue' + 'ivu_complete' */ /* Application keys stored by provisioner */ - struct bt_mesh_app_key *p_app_keys[CONFIG_BT_MESH_PROVISIONER_APP_KEY_COUNT]; + struct bt_mesh_app_key *p_app_keys[CONFIG_BLE_MESH_PROVISIONER_APP_KEY_COUNT]; /* Next app_idx can be assigned */ u16_t p_app_idx_next; /* Network keys stored by provisioner */ - struct bt_mesh_subnet *p_sub[CONFIG_BT_MESH_PROVISIONER_SUBNET_COUNT]; + struct bt_mesh_subnet *p_sub[CONFIG_BLE_MESH_PROVISIONER_SUBNET_COUNT]; /* Next net_idx can be assigned */ u16_t p_net_idx_next; #endif @@ -275,10 +276,10 @@ struct bt_mesh_net { /* Network interface */ enum bt_mesh_net_if { - BT_MESH_NET_IF_ADV, - BT_MESH_NET_IF_LOCAL, - BT_MESH_NET_IF_PROXY, - BT_MESH_NET_IF_PROXY_CFG, + BLE_MESH_NET_IF_ADV, + BLE_MESH_NET_IF_LOCAL, + BLE_MESH_NET_IF_PROXY, + BLE_MESH_NET_IF_PROXY_CFG, }; /* Decoding context for Network/Transport data */ @@ -310,10 +311,10 @@ struct bt_mesh_net_tx { extern struct bt_mesh_net bt_mesh; -#define BT_MESH_NET_IVI_TX (bt_mesh.iv_index - bt_mesh.iv_update) -#define BT_MESH_NET_IVI_RX(rx) (bt_mesh.iv_index - (rx)->old_iv) +#define BLE_MESH_NET_IVI_TX (bt_mesh.iv_index - bt_mesh.iv_update) +#define BLE_MESH_NET_IVI_RX(rx) (bt_mesh.iv_index - (rx)->old_iv) -#define BT_MESH_NET_HDR_LEN 9 +#define BLE_MESH_NET_HDR_LEN 9 int bt_mesh_net_keys_create(struct bt_mesh_subnet_keys *keys, const u8_t key[16]); @@ -388,4 +389,4 @@ struct friend_cred *friend_cred_create(struct bt_mesh_subnet *sub, u16_t addr, void friend_cred_clear(struct friend_cred *cred); int friend_cred_del(u16_t net_idx, u16_t addr); -#endif /* #ifndef _NET_H_ */ +#endif /* _NET_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/prov.c b/components/bt/ble_mesh/mesh_core/prov.c index d0dd7f5a3a..5640fe98cf 100644 --- a/components/bt/ble_mesh/mesh_core/prov.c +++ b/components/bt/ble_mesh/mesh_core/prov.c @@ -9,15 +9,12 @@ #include #include -#include "mesh_util.h" - #include "sdkconfig.h" -#if CONFIG_BT_MESH +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_PROV) +#include "mesh_util.h" #include "mesh_main.h" -#include "mesh_bt_uuid.h" - -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_PROV) +#include "mesh_uuid.h" #include "mesh_trace.h" #include "crypto.h" @@ -29,7 +26,7 @@ #include "proxy.h" #include "prov.h" -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE /* 3 transmissions, 20ms interval */ #define PROV_XMIT_COUNT 2 @@ -115,9 +112,9 @@ enum { }; struct prov_link { - ATOMIC_DEFINE(flags, NUM_FLAGS); -#if defined(CONFIG_BT_MESH_PB_GATT) - struct bt_conn *conn; /* GATT connection */ + BLE_MESH_ATOMIC_DEFINE(flags, NUM_FLAGS); +#if defined(CONFIG_BLE_MESH_PB_GATT) + struct bt_mesh_conn *conn; /* GATT connection */ #endif u8_t dhkey[32]; /* Calculated DHKey */ u8_t expect; /* Next expected PDU */ @@ -137,7 +134,7 @@ struct prov_link { u8_t conf_inputs[145]; /* ConfirmationInputs */ u8_t prov_salt[16]; /* Provisioning Salt */ -#if defined(CONFIG_BT_MESH_PB_ADV) +#if defined(CONFIG_BLE_MESH_PB_ADV) u32_t id; /* Link ID */ struct { @@ -176,15 +173,15 @@ struct prov_rx { #define RETRANSMIT_TIMEOUT K_MSEC(500) #define BUF_TIMEOUT K_MSEC(400) -#if defined(CONFIG_BT_MESH_FAST_PROV) +#if defined(CONFIG_BLE_MESH_FAST_PROV) #define TRANSACTION_TIMEOUT K_SECONDS(3) #define PROVISION_TIMEOUT K_SECONDS(6) #else #define TRANSACTION_TIMEOUT K_SECONDS(30) #define PROVISION_TIMEOUT K_SECONDS(60) -#endif /* CONFIG_BT_MESH_FAST_PROV */ +#endif /* CONFIG_BLE_MESH_FAST_PROV */ -#if defined(CONFIG_BT_MESH_PB_GATT) +#if defined(CONFIG_BLE_MESH_PB_GATT) #define PROV_BUF_HEADROOM 5 #else #define PROV_BUF_HEADROOM 0 @@ -199,7 +196,7 @@ static const struct bt_mesh_prov *prov; static void close_link(u8_t err, u8_t reason); -#if defined(CONFIG_BT_MESH_PB_ADV) +#if defined(CONFIG_BLE_MESH_PB_ADV) static void buf_sent(int err, void *user_data) { if (!link.tx.buf[0]) { @@ -226,7 +223,7 @@ static void free_segments(void) link.tx.buf[i] = NULL; /* Mark as canceled */ - BT_MESH_ADV(buf)->busy = 0; + BLE_MESH_ADV(buf)->busy = 0; /** Change by Espressif. Add this to avoid buf->ref is 2 which will * cause lack of buf. */ @@ -255,18 +252,18 @@ static void reset_link(void) bt_mesh_attention(NULL, 0); } - if (atomic_test_and_clear_bit(link.flags, TIMEOUT_START)) { + if (bt_mesh_atomic_test_and_clear_bit(link.flags, TIMEOUT_START)) { k_delayed_work_cancel(&link.timeout); } if (prov->link_close) { - prov->link_close(BT_MESH_PROV_ADV); + prov->link_close(BLE_MESH_PROV_ADV); } -#if defined(CONFIG_BT_MESH_USE_DUPLICATE_SCAN) +#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) /* Remove the link id from exceptional list */ - bt_mesh_update_exceptional_list(BT_MESH_EXCEP_LIST_REMOVE, - BT_MESH_EXCEP_INFO_MESH_LINK_ID, &link.id); + bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_REMOVE, + BLE_MESH_EXCEP_INFO_MESH_LINK_ID, &link.id); #endif /* Clear everything except the retransmit delayed work config */ @@ -275,10 +272,10 @@ static void reset_link(void) link.rx.prev_id = XACT_NVAL; if (bt_mesh_pub_key_get()) { - atomic_set_bit(link.flags, LOCAL_PUB_KEY); + bt_mesh_atomic_set_bit(link.flags, LOCAL_PUB_KEY); } -#if defined(CONFIG_BT_MESH_PB_GATT) +#if defined(CONFIG_BLE_MESH_PB_GATT) link.rx.buf = bt_mesh_proxy_get_buf(); #else net_buf_simple_init(rx_buf, 0); @@ -290,10 +287,10 @@ static struct net_buf *adv_buf_create(void) { struct net_buf *buf; - buf = bt_mesh_adv_create(BT_MESH_ADV_PROV, PROV_XMIT_COUNT, + buf = bt_mesh_adv_create(BLE_MESH_ADV_PROV, PROV_XMIT_COUNT, PROV_XMIT_INT, BUF_TIMEOUT); if (!buf) { - BT_ERR("Out of provisioning buffers"); + BT_ERR("%s, Out of provisioning buffers", __func__); return NULL; } @@ -438,7 +435,7 @@ static int prov_send_adv(struct net_buf_simple *msg) /* Change by Espressif, get message type */ type = msg->data[0]; - seg_len = min(msg->len, START_PAYLOAD_MAX); + seg_len = MIN(msg->len, START_PAYLOAD_MAX); BT_DBG("seg 0 len %u: %s", seg_len, bt_hex(msg->data, seg_len)); net_buf_add_mem(start, msg->data, seg_len); net_buf_simple_pull(msg, seg_len); @@ -446,7 +443,7 @@ static int prov_send_adv(struct net_buf_simple *msg) buf = start; for (seg_id = 1; msg->len > 0; seg_id++) { if (seg_id >= ARRAY_SIZE(link.tx.buf)) { - BT_ERR("Too big message"); + BT_ERR("%s, Too big message", __func__); free_segments(); return -E2BIG; } @@ -459,7 +456,7 @@ static int prov_send_adv(struct net_buf_simple *msg) link.tx.buf[seg_id] = buf; - seg_len = min(msg->len, CONT_PAYLOAD_MAX); + seg_len = MIN(msg->len, CONT_PAYLOAD_MAX); BT_DBG("seg_id %u len %u: %s", seg_id, seg_len, bt_hex(msg->data, seg_len)); @@ -476,11 +473,11 @@ static int prov_send_adv(struct net_buf_simple *msg) /* Change by Espressif, add provisioning timeout timer operations. * When sending a provisioning PDU successfully, restart the 60s timer. */ - if (atomic_test_and_clear_bit(link.flags, TIMEOUT_START)) { + if (bt_mesh_atomic_test_and_clear_bit(link.flags, TIMEOUT_START)) { k_delayed_work_cancel(&link.timeout); } if (type != PROV_COMPLETE && type != PROV_FAILED) { - if (!atomic_test_and_set_bit(link.flags, TIMEOUT_START)) { + if (!bt_mesh_atomic_test_and_set_bit(link.flags, TIMEOUT_START)) { k_delayed_work_submit(&link.timeout, PROVISION_TIMEOUT); } } @@ -488,9 +485,9 @@ static int prov_send_adv(struct net_buf_simple *msg) return 0; } -#endif /* CONFIG_BT_MESH_PB_ADV */ +#endif /* CONFIG_BLE_MESH_PB_ADV */ -#if defined(CONFIG_BT_MESH_PB_GATT) +#if defined(CONFIG_BLE_MESH_PB_GATT) static int prov_send_gatt(struct net_buf_simple *msg) { int err = 0; @@ -502,33 +499,33 @@ static int prov_send_gatt(struct net_buf_simple *msg) /* Change by Espressif, add provisioning timeout timer operations. * When sending a provisioning PDU successfully, restart the 60s timer. */ - err = bt_mesh_proxy_send(link.conn, BT_MESH_PROXY_PROV, msg); + err = bt_mesh_proxy_send(link.conn, BLE_MESH_PROXY_PROV, msg); if (err) { - BT_ERR("%s: fail to send provisioning PDU", __func__); + BT_ERR("%s, Failed to send provisioning PDU", __func__); return err; } - if (atomic_test_and_clear_bit(link.flags, TIMEOUT_START)) { + if (bt_mesh_atomic_test_and_clear_bit(link.flags, TIMEOUT_START)) { k_delayed_work_cancel(&link.timeout); } if (msg->data[1] != PROV_COMPLETE && msg->data[1] != PROV_FAILED) { - if (!atomic_test_and_set_bit(link.flags, TIMEOUT_START)) { + if (!bt_mesh_atomic_test_and_set_bit(link.flags, TIMEOUT_START)) { k_delayed_work_submit(&link.timeout, PROVISION_TIMEOUT); } } return 0; } -#endif /* CONFIG_BT_MESH_PB_GATT */ +#endif /* CONFIG_BLE_MESH_PB_GATT */ static inline int prov_send(struct net_buf_simple *buf) { -#if defined(CONFIG_BT_MESH_PB_GATT) +#if defined(CONFIG_BLE_MESH_PB_GATT) if (link.conn) { return prov_send_gatt(buf); } #endif -#if defined(CONFIG_BT_MESH_PB_ADV) +#if defined(CONFIG_BLE_MESH_PB_ADV) return prov_send_adv(buf); #else return 0; @@ -591,7 +588,7 @@ static void prov_invite(const u8_t *data) memcpy(&link.conf_inputs[1], &buf->data[1], 11); if (prov_send(buf)) { - BT_ERR("Failed to send capabilities"); + BT_ERR("%s, Failed to send capabilities", __func__); close_link(PROV_ERR_RESOURCES, CLOSE_REASON_FAILED); return; } @@ -625,17 +622,17 @@ static bt_mesh_output_action_t output_action(u8_t action) { switch (action) { case OUTPUT_OOB_BLINK: - return BT_MESH_BLINK; + return BLE_MESH_BLINK; case OUTPUT_OOB_BEEP: - return BT_MESH_BEEP; + return BLE_MESH_BEEP; case OUTPUT_OOB_VIBRATE: - return BT_MESH_VIBRATE; + return BLE_MESH_VIBRATE; case OUTPUT_OOB_NUMBER: - return BT_MESH_DISPLAY_NUMBER; + return BLE_MESH_DISPLAY_NUMBER; case OUTPUT_OOB_STRING: - return BT_MESH_DISPLAY_STRING; + return BLE_MESH_DISPLAY_STRING; default: - return BT_MESH_NO_OUTPUT; + return BLE_MESH_NO_OUTPUT; } } @@ -643,15 +640,15 @@ static bt_mesh_input_action_t input_action(u8_t action) { switch (action) { case INPUT_OOB_PUSH: - return BT_MESH_PUSH; + return BLE_MESH_PUSH; case INPUT_OOB_TWIST: - return BT_MESH_TWIST; + return BLE_MESH_TWIST; case INPUT_OOB_NUMBER: - return BT_MESH_ENTER_NUMBER; + return BLE_MESH_ENTER_NUMBER; case INPUT_OOB_STRING: - return BT_MESH_ENTER_STRING; + return BLE_MESH_ENTER_STRING; default: - return BT_MESH_NO_INPUT; + return BLE_MESH_NO_INPUT; } } @@ -692,7 +689,7 @@ static int prov_auth(u8_t method, u8_t action, u8_t size) return -EINVAL; } - if (output == BT_MESH_DISPLAY_STRING) { + if (output == BLE_MESH_DISPLAY_STRING) { unsigned char str[9]; u8_t i; @@ -742,10 +739,10 @@ static int prov_auth(u8_t method, u8_t action, u8_t size) return -EINVAL; } - if (input == BT_MESH_ENTER_STRING) { - atomic_set_bit(link.flags, WAIT_STRING); + if (input == BLE_MESH_ENTER_STRING) { + bt_mesh_atomic_set_bit(link.flags, WAIT_STRING); } else { - atomic_set_bit(link.flags, WAIT_NUMBER); + bt_mesh_atomic_set_bit(link.flags, WAIT_NUMBER); } return prov->input(input, size); @@ -764,13 +761,13 @@ static void prov_start(const u8_t *data) BT_DBG("Auth Size: 0x%02x", data[4]); if (data[0] != PROV_ALG_P256) { - BT_ERR("Unknown algorithm 0x%02x", data[0]); + BT_ERR("%s, Unknown algorithm 0x%02x", __func__, data[0]); prov_send_fail_msg(PROV_ERR_NVAL_FMT); return; } if (data[1] > 0x01) { - BT_ERR("Invalid public key value: 0x%02x", data[1]); + BT_ERR("%s, Invalid public key value: 0x%02x", __func__, data[1]); prov_send_fail_msg(PROV_ERR_NVAL_FMT); return; } @@ -789,9 +786,9 @@ static void prov_start(const u8_t *data) } if (prov_auth(data[2], data[3], data[4]) < 0) { - BT_ERR("Invalid authentication method: 0x%02x; " - "action: 0x%02x; size: 0x%02x", data[2], data[3], - data[4]); + BT_ERR("%s, Invalid authentication method: 0x%02x; " + "action: 0x%02x; size: 0x%02x", + __func__, data[2], data[3], data[4]); prov_send_fail_msg(PROV_ERR_NVAL_FMT); } } @@ -805,7 +802,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("Unable to generate confirmation salt"); + BT_ERR("%s, Unable to generate confirmation salt", __func__); close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED); return; } @@ -813,7 +810,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("Unable to generate confirmation key"); + BT_ERR("%s, Unable to generate confirmation key", __func__); close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED); return; } @@ -821,7 +818,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("Unable to generate random number"); + BT_ERR("%s, Unable to generate random number", __func__); close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED); return; } @@ -832,13 +829,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("Unable to generate confirmation value"); + BT_ERR("%s, Unable to generate confirmation value", __func__); close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED); return; } if (prov_send(cfm)) { - BT_ERR("Failed to send Provisioning Confirm"); + BT_ERR("%s, Unable to send Provisioning Confirm", __func__); close_link(PROV_ERR_RESOURCES, CLOSE_REASON_FAILED); return; } @@ -858,7 +855,7 @@ int bt_mesh_input_number(u32_t num) { BT_DBG("%u", num); - if (!atomic_test_and_clear_bit(link.flags, WAIT_NUMBER)) { + if (!bt_mesh_atomic_test_and_clear_bit(link.flags, WAIT_NUMBER)) { return -EINVAL; } @@ -866,11 +863,11 @@ int bt_mesh_input_number(u32_t num) send_input_complete(); - if (!atomic_test_bit(link.flags, HAVE_DHKEY)) { + if (!bt_mesh_atomic_test_bit(link.flags, HAVE_DHKEY)) { return 0; } - if (atomic_test_and_clear_bit(link.flags, SEND_CONFIRM)) { + if (bt_mesh_atomic_test_and_clear_bit(link.flags, SEND_CONFIRM)) { send_confirm(); } @@ -881,7 +878,7 @@ int bt_mesh_input_string(const char *str) { BT_DBG("%s", str); - if (!atomic_test_and_clear_bit(link.flags, WAIT_STRING)) { + if (!bt_mesh_atomic_test_and_clear_bit(link.flags, WAIT_STRING)) { return -EINVAL; } @@ -889,11 +886,11 @@ int bt_mesh_input_string(const char *str) send_input_complete(); - if (!atomic_test_bit(link.flags, HAVE_DHKEY)) { + if (!bt_mesh_atomic_test_bit(link.flags, HAVE_DHKEY)) { return 0; } - if (atomic_test_and_clear_bit(link.flags, SEND_CONFIRM)) { + if (bt_mesh_atomic_test_and_clear_bit(link.flags, SEND_CONFIRM)) { send_confirm(); } @@ -905,7 +902,7 @@ static void prov_dh_key_cb(const u8_t key[32]) BT_DBG("%p", key); if (!key) { - BT_ERR("DHKey generation failed"); + BT_ERR("%s, DHKey generation failed", __func__); close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED); return; } @@ -914,14 +911,14 @@ static void prov_dh_key_cb(const u8_t key[32]) BT_DBG("DHkey: %s", bt_hex(link.dhkey, 32)); - atomic_set_bit(link.flags, HAVE_DHKEY); + bt_mesh_atomic_set_bit(link.flags, HAVE_DHKEY); - if (atomic_test_bit(link.flags, WAIT_NUMBER) || - atomic_test_bit(link.flags, WAIT_STRING)) { + if (bt_mesh_atomic_test_bit(link.flags, WAIT_NUMBER) || + bt_mesh_atomic_test_bit(link.flags, WAIT_STRING)) { return; } - if (atomic_test_and_clear_bit(link.flags, SEND_CONFIRM)) { + if (bt_mesh_atomic_test_and_clear_bit(link.flags, SEND_CONFIRM)) { send_confirm(); } } @@ -933,7 +930,7 @@ static void send_pub_key(void) key = bt_mesh_pub_key_get(); if (!key) { - BT_ERR("No public key available"); + BT_ERR("%s, No public key available", __func__); close_link(PROV_ERR_RESOURCES, CLOSE_REASON_FAILED); return; } @@ -958,7 +955,7 @@ 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)) { - BT_ERR("Failed to generate DHKey"); + BT_ERR("%s, Unable to generate DHKey", __func__); close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED); return; } @@ -978,7 +975,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)) { - BT_ERR("%s, Failed to generate DHKey", __func__); + BT_ERR("%s, Unable to generate DHKey", __func__); close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED); return -EIO; } @@ -990,7 +987,7 @@ int bt_mesh_set_oob_pub_key(const u8_t pub_key_x[32], const u8_t pub_key_y[32], const u8_t pri_key[32]) { if (!pub_key_x || !pub_key_y || !pri_key) { - BT_ERR("%s, invalid argument", __func__); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } @@ -1002,10 +999,10 @@ int bt_mesh_set_oob_pub_key(const u8_t pub_key_x[32], const u8_t pub_key_y[32], sys_memcpy_swap(&link.conf_inputs[81] + 32, pub_key_y, 32); bt_mesh_set_private_key(pri_key); - atomic_set_bit(link.flags, OOB_PUB_KEY); + bt_mesh_atomic_set_bit(link.flags, OOB_PUB_KEY); /* If remote public key is not got, just return */ - if (!atomic_test_bit(link.flags, REMOTE_PUB_KEY)) { + if (!bt_mesh_atomic_test_bit(link.flags, REMOTE_PUB_KEY)) { return 0; } @@ -1023,26 +1020,26 @@ 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("%s, Invalid public key", __func__); prov_send_fail_msg(PROV_ERR_UNEXP_PDU); return; } memcpy(&link.conf_inputs[17], data, 64); - atomic_set_bit(link.flags, REMOTE_PUB_KEY); - /* TODO: Change by Espressif. - Temporary modification. Generating publish keys is not supported by the controller now */ + bt_mesh_atomic_set_bit(link.flags, REMOTE_PUB_KEY); + #if 0 - if (!atomic_test_bit(link.flags, LOCAL_PUB_KEY)) { + if (!bt_mesh_atomic_test_bit(link.flags, LOCAL_PUB_KEY)) { /* Clear retransmit timer */ -#if defined(CONFIG_BT_MESH_PB_ADV) +#if defined(CONFIG_BLE_MESH_PB_ADV) prov_clear_tx(); #endif - atomic_set_bit(link.flags, REMOTE_PUB_KEY); + bt_mesh_atomic_set_bit(link.flags, REMOTE_PUB_KEY); BT_WARN("Waiting for a local public key"); return; } -#endif /* #if 0 */ +#endif + if (!link.oob_pk_flag) { send_pub_key(); } else { @@ -1050,25 +1047,6 @@ static void prov_pub_key(const u8_t *data) } } -#if 0 -/* Change by Espressif, currently mask this function */ -static void pub_key_ready(const u8_t *pkey) -{ - if (!pkey) { - BT_WARN("Public key not available"); - return; - } - - BT_DBG("Local public key ready"); - - atomic_set_bit(link.flags, LOCAL_PUB_KEY); - - if (atomic_test_and_clear_bit(link.flags, REMOTE_PUB_KEY)) { - send_pub_key(); - } -} -#endif - static void prov_input_complete(const u8_t *data) { BT_DBG("%s", __func__); @@ -1080,13 +1058,13 @@ static void prov_confirm(const u8_t *data) memcpy(link.conf, data, 16); - if (!atomic_test_bit(link.flags, HAVE_DHKEY)) { -#if defined(CONFIG_BT_MESH_PB_ADV) + if (!bt_mesh_atomic_test_bit(link.flags, HAVE_DHKEY)) { +#if defined(CONFIG_BLE_MESH_PB_ADV) prov_clear_tx(); #endif - atomic_set_bit(link.flags, SEND_CONFIRM); + bt_mesh_atomic_set_bit(link.flags, SEND_CONFIRM); /* If using OOB public key and it has already got, calculates dhkey */ - if (link.oob_pk_flag && atomic_test_bit(link.flags, OOB_PUB_KEY)) { + if (link.oob_pk_flag && bt_mesh_atomic_test_bit(link.flags, OOB_PUB_KEY)) { bt_mesh_calc_dh_key(); } } else { @@ -1102,13 +1080,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("Unable to calculate confirmation verification"); + BT_ERR("%s, Unable to calculate confirmation verification", __func__); close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED); return; } if (memcmp(conf_verify, link.conf, 16)) { - BT_ERR("Invalid confirmation value"); + BT_ERR("%s, Invalid confirmation value", __func__); BT_DBG("Received: %s", bt_hex(link.conf, 16)); BT_DBG("Calculated: %s", bt_hex(conf_verify, 16)); close_link(PROV_ERR_CFM_FAILED, CLOSE_REASON_FAILED); @@ -1119,14 +1097,14 @@ static void prov_random(const u8_t *data) net_buf_simple_add_mem(rnd, link.rand, 16); if (prov_send(rnd)) { - BT_ERR("Failed to send Provisioning Random"); + BT_ERR("%s, Failed to send Provisioning Random", __func__); close_link(PROV_ERR_RESOURCES, CLOSE_REASON_FAILED); return; } if (bt_mesh_prov_salt(link.conf_salt, data, link.rand, link.prov_salt)) { - BT_ERR("Failed to generate provisioning salt"); + BT_ERR("%s, Failed to generate provisioning salt", __func__); close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED); return; } @@ -1153,7 +1131,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("Unable to generate session key"); + BT_ERR("%s, Unable to generate session key", __func__); close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED); return; } @@ -1162,7 +1140,7 @@ static void prov_data(const u8_t *data) err = bt_mesh_prov_nonce(link.dhkey, link.prov_salt, nonce); if (err) { - BT_ERR("Unable to generate session nonce"); + BT_ERR("%s, Unable to generate session nonce", __func__); close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED); return; } @@ -1171,14 +1149,14 @@ static void prov_data(const u8_t *data) err = bt_mesh_prov_decrypt(session_key, nonce, data, pdu); if (err) { - BT_ERR("Unable to decrypt provisioning data"); + BT_ERR("%s, Unable to decrypt provisioning data", __func__); close_link(PROV_ERR_DECRYPT, CLOSE_REASON_FAILED); return; } err = bt_mesh_dev_key(link.dhkey, link.prov_salt, dev_key); if (err) { - BT_ERR("Unable to generate device key"); + BT_ERR("%s, Unable to generate device key", __func__); close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_FAILED); return; } @@ -1230,14 +1208,14 @@ static const struct { static void close_link(u8_t err, u8_t reason) { -#if defined(CONFIG_BT_MESH_PB_GATT) +#if defined(CONFIG_BLE_MESH_PB_GATT) if (link.conn) { bt_mesh_pb_gatt_close(link.conn); return; } #endif -#if defined(CONFIG_BT_MESH_PB_ADV) +#if defined(CONFIG_BLE_MESH_PB_ADV) if (err) { prov_send_fail_msg(err); } @@ -1246,7 +1224,7 @@ static void close_link(u8_t err, u8_t reason) bearer_ctl_send(LINK_CLOSE, &reason, sizeof(reason)); #endif - atomic_clear_bit(link.flags, LINK_ACTIVE); + bt_mesh_atomic_clear_bit(link.flags, LINK_ACTIVE); /* Disable Attention Timer if it was set before */ if (link.conf_inputs[0]) { @@ -1262,14 +1240,14 @@ static void prov_timeout(struct k_work *work) close_link(PROV_ERR_UNEXP_ERR, CLOSE_REASON_TIMEOUT); } -#if defined(CONFIG_BT_MESH_PB_ADV) +#if defined(CONFIG_BLE_MESH_PB_ADV) static void prov_retransmit(struct k_work *work) { int i; BT_DBG("%s", __func__); - if (!atomic_test_bit(link.flags, LINK_ACTIVE)) { + if (!bt_mesh_atomic_test_bit(link.flags, LINK_ACTIVE)) { BT_WARN("Link not active"); return; } @@ -1287,7 +1265,7 @@ static void prov_retransmit(struct k_work *work) break; } - if (BT_MESH_ADV(buf)->busy) { + if (BLE_MESH_ADV(buf)->busy) { continue; } @@ -1307,11 +1285,11 @@ 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("Too short bearer open message (len %u)", buf->len); + BT_ERR("%s, Too short bearer open message (len %u)", __func__, buf->len); return; } - if (atomic_test_bit(link.flags, LINK_ACTIVE)) { + if (bt_mesh_atomic_test_bit(link.flags, LINK_ACTIVE)) { BT_WARN("Ignoring bearer open: link already active"); return; } @@ -1322,17 +1300,17 @@ static void link_open(struct prov_rx *rx, struct net_buf_simple *buf) } if (prov->link_open) { - prov->link_open(BT_MESH_PROV_ADV); + prov->link_open(BLE_MESH_PROV_ADV); } link.id = rx->link_id; - atomic_set_bit(link.flags, LINK_ACTIVE); + bt_mesh_atomic_set_bit(link.flags, LINK_ACTIVE); net_buf_simple_init(link.rx.buf, 0); -#if defined(CONFIG_BT_MESH_USE_DUPLICATE_SCAN) +#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) /* Add the link id into exceptional list */ - bt_mesh_update_exceptional_list(BT_MESH_EXCEP_LIST_ADD, - BT_MESH_EXCEP_INFO_MESH_LINK_ID, &link.id); + bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD, + BLE_MESH_EXCEP_INFO_MESH_LINK_ID, &link.id); #endif bearer_ctl_send(LINK_ACK, NULL, 0); @@ -1361,21 +1339,21 @@ static void gen_prov_ctl(struct prov_rx *rx, struct net_buf_simple *buf) link_open(rx, buf); break; case LINK_ACK: - if (!atomic_test_bit(link.flags, LINK_ACTIVE)) { + if (!bt_mesh_atomic_test_bit(link.flags, LINK_ACTIVE)) { return; } link_ack(rx, buf); break; case LINK_CLOSE: - if (!atomic_test_bit(link.flags, LINK_ACTIVE)) { + if (!bt_mesh_atomic_test_bit(link.flags, LINK_ACTIVE)) { return; } link_close(rx, buf); break; default: - BT_ERR("Unknown bearer opcode: 0x%02x", BEARER_CTL(rx->gpc)); + BT_ERR("%s, Unknown bearer opcode 0x%02x", __func__, BEARER_CTL(rx->gpc)); return; } } @@ -1387,7 +1365,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("Incorrect FCS"); + BT_ERR("%s, Incorrect FCS", __func__); return; } @@ -1402,14 +1380,14 @@ static void prov_msg_recv(void) } if (type >= ARRAY_SIZE(prov_handlers)) { - BT_ERR("Unknown provisioning PDU type 0x%02x", type); + BT_ERR("%s, Unknown provisioning PDU type 0x%02x", __func__, type); close_link(PROV_ERR_NVAL_PDU, CLOSE_REASON_FAILED); return; } if (1 + prov_handlers[type].len != link.rx.buf->len) { - BT_ERR("Invalid length %u for type 0x%02x", - link.rx.buf->len, type); + BT_ERR("%s, Invalid length %u for type 0x%02x", + __func__, link.rx.buf->len, type); close_link(PROV_ERR_NVAL_FMT, CLOSE_REASON_FAILED); return; } @@ -1417,10 +1395,10 @@ static void prov_msg_recv(void) /* Change by Espressif, add provisioning timeout timer operations. * When received a provisioning PDU, restart the 60s timer. */ - if (atomic_test_and_clear_bit(link.flags, TIMEOUT_START)) { + if (bt_mesh_atomic_test_and_clear_bit(link.flags, TIMEOUT_START)) { k_delayed_work_cancel(&link.timeout); } - if (!atomic_test_and_set_bit(link.flags, TIMEOUT_START)) { + if (!bt_mesh_atomic_test_and_set_bit(link.flags, TIMEOUT_START)) { k_delayed_work_submit(&link.timeout, PROVISION_TIMEOUT); } @@ -1446,7 +1424,7 @@ static void gen_prov_cont(struct prov_rx *rx, struct net_buf_simple *buf) } if (seg > link.rx.last_seg) { - BT_ERR("Invalid segment index %u", seg); + BT_ERR("%s, Invalid segment index %u", __func__, seg); close_link(PROV_ERR_NVAL_FMT, CLOSE_REASON_FAILED); return; } else if (seg == link.rx.last_seg) { @@ -1455,8 +1433,8 @@ static void gen_prov_cont(struct prov_rx *rx, struct net_buf_simple *buf) expect_len = (link.rx.buf->len - 20 - (23 * (link.rx.last_seg - 1))); if (expect_len != buf->len) { - BT_ERR("Incorrect last seg len: %u != %u", - expect_len, buf->len); + BT_ERR("%s, Incorrect last seg len: %u != %u", + __func__, expect_len, buf->len); close_link(PROV_ERR_NVAL_FMT, CLOSE_REASON_FAILED); return; } @@ -1509,20 +1487,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("Ignoring zero-length provisioning PDU"); + BT_ERR("%s, Ignoring zero-length provisioning PDU", __func__); close_link(PROV_ERR_NVAL_FMT, CLOSE_REASON_FAILED); return; } if (link.rx.buf->len > link.rx.buf->size) { - BT_ERR("Too large provisioning PDU (%u bytes)", - link.rx.buf->len); + BT_ERR("%s, Too large provisioning PDU (%u bytes)", + __func__, link.rx.buf->len); close_link(PROV_ERR_NVAL_FMT, CLOSE_REASON_FAILED); return; } if (START_LAST_SEG(rx->gpc) > 0 && link.rx.buf->len <= 20) { - BT_ERR("Too small total length for multi-segment PDU"); + BT_ERR("%s, Too small total length for multi-segment PDU", __func__); close_link(PROV_ERR_NVAL_FMT, CLOSE_REASON_FAILED); return; } @@ -1551,11 +1529,11 @@ 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("Too short GPC message type %u", GPCF(rx->gpc)); + BT_ERR("%s, Too short GPC message type %u", __func__, GPCF(rx->gpc)); return; } - if (!atomic_test_bit(link.flags, LINK_ACTIVE) && + if (!bt_mesh_atomic_test_bit(link.flags, LINK_ACTIVE) && gen_prov[GPCF(rx->gpc)].require_link) { BT_DBG("Ignoring message that requires active link"); return; @@ -1584,17 +1562,17 @@ void bt_mesh_pb_adv_recv(struct net_buf_simple *buf) BT_DBG("link_id 0x%08x xact_id %u", rx.link_id, rx.xact_id); - if (atomic_test_bit(link.flags, LINK_ACTIVE) && link.id != rx.link_id) { + if (bt_mesh_atomic_test_bit(link.flags, LINK_ACTIVE) && link.id != rx.link_id) { BT_DBG("Ignoring mesh beacon for unknown link"); return; } gen_prov_recv(&rx, buf); } -#endif /* CONFIG_BT_MESH_PB_ADV */ +#endif /* CONFIG_BLE_MESH_PB_ADV */ -#if defined(CONFIG_BT_MESH_PB_GATT) -int bt_mesh_pb_gatt_recv(struct bt_conn *conn, struct net_buf_simple *buf) +#if defined(CONFIG_BLE_MESH_PB_GATT) +int bt_mesh_pb_gatt_recv(struct bt_mesh_conn *conn, struct net_buf_simple *buf) { u8_t type; @@ -1618,22 +1596,22 @@ int bt_mesh_pb_gatt_recv(struct bt_conn *conn, struct net_buf_simple *buf) } if (type >= ARRAY_SIZE(prov_handlers)) { - BT_ERR("Unknown provisioning PDU type 0x%02x", type); + BT_ERR("%s, Unknown provisioning PDU type 0x%02x", __func__, type); return -EINVAL; } if (prov_handlers[type].len != buf->len) { - BT_ERR("Invalid length %u for type 0x%02x", buf->len, type); + BT_ERR("%s, Invalid length %u for type 0x%02x", __func__, buf->len, type); return -EINVAL; } /* Change by Espressif, add provisioning timeout timer operations. * When received a provisioning PDU, restart the 60s timer. */ - if (atomic_test_and_clear_bit(link.flags, TIMEOUT_START)) { + if (bt_mesh_atomic_test_and_clear_bit(link.flags, TIMEOUT_START)) { k_delayed_work_cancel(&link.timeout); } - if (!atomic_test_and_set_bit(link.flags, TIMEOUT_START)) { + if (!bt_mesh_atomic_test_and_set_bit(link.flags, TIMEOUT_START)) { k_delayed_work_submit(&link.timeout, PROVISION_TIMEOUT); } @@ -1642,11 +1620,11 @@ int bt_mesh_pb_gatt_recv(struct bt_conn *conn, struct net_buf_simple *buf) return 0; } -int bt_mesh_pb_gatt_open(struct bt_conn *conn) +int bt_mesh_pb_gatt_open(struct bt_mesh_conn *conn) { BT_DBG("conn %p", conn); - if (atomic_test_and_set_bit(link.flags, LINK_ACTIVE)) { + if (bt_mesh_atomic_test_and_set_bit(link.flags, LINK_ACTIVE)) { return -EBUSY; } @@ -1654,18 +1632,18 @@ int bt_mesh_pb_gatt_open(struct bt_conn *conn) link.expect = PROV_INVITE; if (prov->link_open) { - prov->link_open(BT_MESH_PROV_GATT); + prov->link_open(BLE_MESH_PROV_GATT); } return 0; } -int bt_mesh_pb_gatt_close(struct bt_conn *conn) +int bt_mesh_pb_gatt_close(struct bt_mesh_conn *conn) { BT_DBG("conn %p", conn); if (link.conn != conn) { - BT_ERR("Not connected"); + BT_ERR("%s, Not connected", __func__); return -ENOTCONN; } @@ -1675,17 +1653,17 @@ int bt_mesh_pb_gatt_close(struct bt_conn *conn) } if (prov->link_close) { - prov->link_close(BT_MESH_PROV_GATT); + prov->link_close(BLE_MESH_PROV_GATT); } // Should reset the atomic flag after disconneted bt_mesh_conn_unref(link.conn); /* Change by Espressif, use offsetof when clear link */ -#if defined(CONFIG_BT_MESH_PB_ADV) +#if defined(CONFIG_BLE_MESH_PB_ADV) memset(&link, 0, offsetof(struct prov_link, tx.retransmit)); link.rx.prev_id = XACT_NVAL; -#if defined(CONFIG_BT_MESH_PB_GATT) +#if defined(CONFIG_BLE_MESH_PB_GATT) link.rx.buf = bt_mesh_proxy_get_buf(); #else net_buf_simple_init(rx_buf, 0); @@ -1693,15 +1671,15 @@ int bt_mesh_pb_gatt_close(struct bt_conn *conn) #endif #else memset(&link, 0, offsetof(struct prov_link, timeout)); -#endif /* CONFIG_BT_MESH_PB_ADV */ +#endif /* CONFIG_BLE_MESH_PB_ADV */ if (bt_mesh_pub_key_get()) { - atomic_set_bit(link.flags, LOCAL_PUB_KEY); + bt_mesh_atomic_set_bit(link.flags, LOCAL_PUB_KEY); } return 0; } -#endif /* CONFIG_BT_MESH_PB_GATT */ +#endif /* CONFIG_BLE_MESH_PB_GATT */ const u8_t *bt_mesh_prov_get_uuid(void) { @@ -1710,7 +1688,7 @@ const u8_t *bt_mesh_prov_get_uuid(void) bool bt_prov_active(void) { - return atomic_test_bit(link.flags, LINK_ACTIVE); + return bt_mesh_atomic_test_bit(link.flags, LINK_ACTIVE); } int bt_mesh_prov_init(const struct bt_mesh_prov *prov_info) @@ -1718,37 +1696,31 @@ int bt_mesh_prov_init(const struct bt_mesh_prov *prov_info) const u8_t *key = NULL; if (!prov_info) { - BT_ERR("No provisioning context provided"); + BT_ERR("%s, No provisioning context provided", __func__); return -EINVAL; } /* Change 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("%s, Failed to generate public key", __func__); return -EIO; } prov = prov_info; -#if defined(CONFIG_BT_MESH_PB_ADV) +#if defined(CONFIG_BLE_MESH_PB_ADV) k_delayed_work_init(&link.tx.retransmit, prov_retransmit); link.rx.prev_id = XACT_NVAL; -#if defined(CONFIG_BT_MESH_PB_GATT) +#if defined(CONFIG_BLE_MESH_PB_GATT) link.rx.buf = bt_mesh_proxy_get_buf(); #else net_buf_simple_init(rx_buf, 0); link.rx.buf = rx_buf; #endif -#endif /* CONFIG_BT_MESH_PB_ADV */ - - if (IS_ENABLED(CONFIG_BT_DEBUG)) { - struct bt_uuid_128 uuid = { .uuid.type = BT_UUID_TYPE_128 }; - memcpy(uuid.val, prov->uuid, 16); - BT_INFO("Device UUID: %s", bt_uuid_str(&uuid.uuid)); - } +#endif /* CONFIG_BLE_MESH_PB_ADV */ /* Change by Espressif, add provisioning timeout timer init */ k_delayed_work_init(&link.timeout, prov_timeout); @@ -1770,6 +1742,4 @@ void bt_mesh_prov_reset(void) } } -#endif /* CONFIG_BT_MESH_NODE */ - -#endif /* #if CONFIG_BT_MESH */ +#endif /* CONFIG_BLE_MESH_NODE */ diff --git a/components/bt/ble_mesh/mesh_core/prov.h b/components/bt/ble_mesh/mesh_core/prov.h index 83915d8653..ec7f1b7200 100644 --- a/components/bt/ble_mesh/mesh_core/prov.h +++ b/components/bt/ble_mesh/mesh_core/prov.h @@ -17,17 +17,19 @@ void bt_mesh_pb_adv_recv(struct net_buf_simple *buf); bool bt_prov_active(void); -int bt_mesh_pb_gatt_open(struct bt_conn *conn); -int bt_mesh_pb_gatt_close(struct bt_conn *conn); -int bt_mesh_pb_gatt_recv(struct bt_conn *conn, struct net_buf_simple *buf); +int bt_mesh_pb_gatt_open(struct bt_mesh_conn *conn); +int bt_mesh_pb_gatt_close(struct bt_mesh_conn *conn); +int bt_mesh_pb_gatt_recv(struct bt_mesh_conn *conn, struct net_buf_simple *buf); int bt_mesh_set_oob_pub_key(const u8_t pub_key_x[32], const u8_t pub_key_y[32], const u8_t pri_key[32]); + const u8_t *bt_mesh_prov_get_uuid(void); int bt_mesh_prov_init(const struct bt_mesh_prov *prov); void bt_mesh_prov_complete(u16_t net_idx, u16_t addr, u8_t flags, u32_t iv_index); + void bt_mesh_prov_reset(void); -#endif /* #ifndef _PROV_H_ */ +#endif /* _PROV_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/provisioner_beacon.c b/components/bt/ble_mesh/mesh_core/provisioner_beacon.c index 24700099c5..dfe4e39fa0 100644 --- a/components/bt/ble_mesh/mesh_core/provisioner_beacon.c +++ b/components/bt/ble_mesh/mesh_core/provisioner_beacon.c @@ -15,15 +15,12 @@ #include #include -#include "mesh_util.h" - -#include "mesh_buf.h" #include "sdkconfig.h" +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_BEACON) + +#include "mesh_util.h" +#include "mesh_buf.h" #include "mesh_main.h" - -#if CONFIG_BT_MESH - -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_BEACON) #include "mesh_trace.h" #include "adv.h" @@ -33,17 +30,16 @@ #include "crypto.h" #include "beacon.h" #include "foundation.h" - #include "provisioner_prov.h" #define BEACON_TYPE_UNPROVISIONED 0x00 #define BEACON_TYPE_SECURE 0x01 -#if CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_PROVISIONER static void provisioner_secure_beacon_recv(struct net_buf_simple *buf) { - // TODO: Provisioner receive and handle Secure Beacon + // TODO: Provisioner receive and handle Secure Network Beacon } void provisioner_beacon_recv(struct net_buf_simple *buf) @@ -53,7 +49,7 @@ void provisioner_beacon_recv(struct net_buf_simple *buf) BT_DBG("%u bytes: %s", buf->len, bt_hex(buf->data, buf->len)); if (buf->len < 1) { - BT_ERR("Too short beacon"); + BT_ERR("%s, Too short beacon", __func__); return; } @@ -67,11 +63,9 @@ void provisioner_beacon_recv(struct net_buf_simple *buf) provisioner_secure_beacon_recv(buf); break; default: - BT_WARN("%s, Unknown beacon type 0x%02x", __func__, type); + BT_DBG("%s, Unknown beacon type 0x%02x", __func__, type); break; } } -#endif /* CONFIG_BT_MESH_PROVISIONER */ - -#endif /* #if CONFIG_BT_MESH */ \ No newline at end of file +#endif /* CONFIG_BLE_MESH_PROVISIONER */ diff --git a/components/bt/ble_mesh/mesh_core/provisioner_main.c b/components/bt/ble_mesh/mesh_core/provisioner_main.c index 45a0d74856..4fbff9ea2b 100644 --- a/components/bt/ble_mesh/mesh_core/provisioner_main.c +++ b/components/bt/ble_mesh/mesh_core/provisioner_main.c @@ -18,13 +18,12 @@ #include "sdkconfig.h" #include "osi/allocator.h" -#if CONFIG_BT_MESH -#include "mesh.h" #include "mesh_util.h" #include "mesh_main.h" #include "mesh_trace.h" #include "mesh_bearer_adapt.h" +#include "mesh.h" #include "crypto.h" #include "adv.h" #include "net.h" @@ -34,12 +33,12 @@ #include "provisioner_proxy.h" #include "provisioner_main.h" -#if CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_PROVISIONER static const struct bt_mesh_prov *prov; static const struct bt_mesh_comp *comp; -static struct bt_mesh_node_t *mesh_nodes[CONFIG_BT_MESH_MAX_STORED_NODES]; +static struct bt_mesh_node_t *mesh_nodes[CONFIG_BLE_MESH_MAX_STORED_NODES]; static u32_t mesh_node_count; static bool prov_upper_init = false; @@ -51,18 +50,18 @@ static int provisioner_index_check(int node_index) BT_DBG("%s", __func__); if (node_index < 0) { - BT_ERR("%s: Invalid node index %d", __func__, node_index); + BT_ERR("%s, Invalid node index %d", __func__, node_index); return -EINVAL; } if (node_index >= ARRAY_SIZE(mesh_nodes)) { - BT_ERR("%s: Too big node index", __func__); + BT_ERR("%s, Too big node index", __func__); return -EINVAL; } node = mesh_nodes[node_index]; if (!node) { - BT_ERR("%s: Node is not found", __func__); + BT_ERR("%s, Node is not found", __func__); return -EINVAL; } @@ -120,15 +119,15 @@ int provisioner_node_reset(int node_index) struct bt_mesh_rpl *rpl = NULL; int i; - BT_DBG("%s: reset node %d", __func__, node_index); + BT_DBG("%s, reset node %d", __func__, node_index); if (!mesh_node_count) { - BT_ERR("%s: Node queue is empty", __func__); + BT_ERR("%s, Node queue is empty", __func__); return -ENODEV; } if (provisioner_index_check(node_index)) { - BT_ERR("%s: Failed to check node index", __func__); + BT_ERR("%s, Failed to check node index", __func__); return -EINVAL; } @@ -185,13 +184,13 @@ int provisioner_upper_init(void) comp = bt_mesh_comp_get(); if (!comp) { - BT_ERR("%s: NULL composition data", __func__); + BT_ERR("%s, NULL composition data", __func__); return -EINVAL; } prov = provisioner_get_prov_info(); if (!prov) { - BT_ERR("%s: NULL provisioning context", __func__); + BT_ERR("%s, NULL provisioning context", __func__); return -EINVAL; } @@ -201,35 +200,35 @@ int provisioner_upper_init(void) /* Generate the primary netkey */ if (bt_mesh_rand(p_key, 16)) { - BT_ERR("%s: Failed to generate Primary NetKey", __func__); + BT_ERR("%s, Failed to generate Primary NetKey", __func__); return -EIO; } sub = osi_calloc(sizeof(struct bt_mesh_subnet)); if (!sub) { - BT_ERR("%s: Failed to allocate memory", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; } - sub->kr_flag = BT_MESH_KEY_REFRESH(prov->flags); + 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("%s, Failed to generate net-related keys", __func__); osi_free(sub); return -EIO; } - sub->kr_phase = BT_MESH_KR_PHASE_2; + sub->kr_phase = BLE_MESH_KR_PHASE_2; } 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("%s, Failed to create net-related keys", __func__); osi_free(sub); return -EIO; } - sub->kr_phase = BT_MESH_KR_NORMAL; + sub->kr_phase = BLE_MESH_KR_NORMAL; } - sub->net_idx = BT_MESH_KEY_PRIMARY; - sub->node_id = BT_MESH_NODE_IDENTITY_NOT_SUPPORTED; + sub->net_idx = BLE_MESH_KEY_PRIMARY; + sub->node_id = BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED; bt_mesh.p_sub[0] = sub; @@ -240,7 +239,7 @@ int provisioner_upper_init(void) /* In this function, we use the values of struct bt_mesh_prov which has been initialized in the application layer */ bt_mesh.iv_index = prov->iv_index; - bt_mesh.iv_update = BT_MESH_IV_UPDATE(prov->flags); + bt_mesh.iv_update = BLE_MESH_IV_UPDATE(prov->flags); /* Set initial IV Update procedure state time-stamp */ bt_mesh.last_update = k_uptime_get(); @@ -289,7 +288,7 @@ struct bt_mesh_subnet *provisioner_subnet_get(u16_t net_idx) BT_DBG("%s", __func__); - if (net_idx == BT_MESH_KEY_ANY) { + if (net_idx == BLE_MESH_KEY_ANY) { return bt_mesh.p_sub[0]; } @@ -311,7 +310,7 @@ bool provisioner_check_msg_dst_addr(u16_t dst_addr) BT_DBG("%s", __func__); - if (!BT_MESH_ADDR_IS_UNICAST(dst_addr)) { + if (!BLE_MESH_ADDR_IS_UNICAST(dst_addr)) { return true; } @@ -337,8 +336,8 @@ const u8_t *provisioner_get_device_key(u16_t dst_addr) BT_DBG("%s", __func__); - if (!BT_MESH_ADDR_IS_UNICAST(dst_addr)) { - BT_ERR("%s: Not a unicast address 0x%04x", __func__, dst_addr); + if (!BLE_MESH_ADDR_IS_UNICAST(dst_addr)) { + BT_ERR("%s, Not a unicast address 0x%04x", __func__, dst_addr); return NULL; } @@ -364,7 +363,7 @@ struct bt_mesh_app_key *provisioner_app_key_find(u16_t app_idx) if (!key) { continue; } - if (key->net_idx != BT_MESH_KEY_UNUSED && + if (key->net_idx != BLE_MESH_KEY_UNUSED && key->app_idx == app_idx) { return key; } @@ -423,7 +422,7 @@ int bt_mesh_provisioner_store_node_info(struct bt_mesh_node_t *node_info) int i; if (!node_info) { - BT_ERR("%s: Invalid parameter", __func__); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } @@ -431,18 +430,18 @@ int bt_mesh_provisioner_store_node_info(struct bt_mesh_node_t *node_info) for (i = 0; i < ARRAY_SIZE(mesh_nodes); i++) { node = mesh_nodes[i]; if (node && !memcmp(node->dev_uuid, node_info->dev_uuid, 16)) { - BT_WARN("%s: Node info already exists", __func__); + BT_WARN("%s, Node info already exists", __func__); return -EEXIST; } } - /* 0 ~ (CONFIG_BT_MESH_MAX_PROV_NODES-1) are left for self-provisioned nodes */ - for (i = CONFIG_BT_MESH_MAX_PROV_NODES; i < ARRAY_SIZE(mesh_nodes); i++) { + /* 0 ~ (CONFIG_BLE_MESH_MAX_PROV_NODES-1) are left for self-provisioned nodes */ + for (i = CONFIG_BLE_MESH_MAX_PROV_NODES; i < ARRAY_SIZE(mesh_nodes); i++) { node = mesh_nodes[i]; if (!node) { node = osi_calloc(sizeof(struct bt_mesh_node_t)); if (!node) { - BT_ERR("%s: Failed to allocate memory", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; } memcpy(node, node_info, sizeof(struct bt_mesh_node_t)); @@ -452,7 +451,7 @@ int bt_mesh_provisioner_store_node_info(struct bt_mesh_node_t *node_info) } } - BT_ERR("%s: Node info is full", __func__); + BT_ERR("%s, Node info is full", __func__); return -ENOMEM; } @@ -462,13 +461,13 @@ int bt_mesh_provisioner_get_all_node_unicast_addr(struct net_buf_simple *buf) int i; if (!buf) { - BT_ERR("%s: Invalid parameter", __func__); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } for (i = 0; i < ARRAY_SIZE(mesh_nodes); i++) { node = mesh_nodes[i]; - if (!node || !BT_MESH_ADDR_IS_UNICAST(node->unicast_addr)) { + if (!node || !BLE_MESH_ADDR_IS_UNICAST(node->unicast_addr)) { continue; } net_buf_simple_add_le16(buf, node->unicast_addr); @@ -485,12 +484,12 @@ int bt_mesh_provisioner_set_node_name(int node_index, const char *name) BT_DBG("%s", __func__); if (!name) { - BT_ERR("%s: Invalid parameter", __func__); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } if (provisioner_index_check(node_index)) { - BT_ERR("%s: Failed to check node index", __func__); + BT_ERR("%s, Failed to check node index", __func__); return -EINVAL; } @@ -506,7 +505,7 @@ int bt_mesh_provisioner_set_node_name(int node_index, const char *name) continue; } if (!strncmp(mesh_nodes[i]->node_name, name, length)) { - BT_WARN("%s: Name %s already exists", __func__, name); + BT_WARN("%s, Name %s already exists", __func__, name); return -EEXIST; } } @@ -521,7 +520,7 @@ const char *bt_mesh_provisioner_get_node_name(int node_index) BT_DBG("%s", __func__); if (provisioner_index_check(node_index)) { - BT_ERR("%s: Failed to check node index", __func__); + BT_ERR("%s, Failed to check node index", __func__); return NULL; } @@ -563,8 +562,8 @@ struct bt_mesh_node_t *bt_mesh_provisioner_get_node_info(u16_t unicast_addr) BT_DBG("%s", __func__); - if (!BT_MESH_ADDR_IS_UNICAST(unicast_addr)) { - BT_ERR("%s: Not a unicast address 0x%04x", __func__, unicast_addr); + if (!BLE_MESH_ADDR_IS_UNICAST(unicast_addr)) { + BT_ERR("%s, Not a unicast address 0x%04x", __func__, unicast_addr); return NULL; } @@ -724,42 +723,42 @@ 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("%s: No AppKey Index available", __func__); + BT_ERR("%s, No AppKey Index available", __func__); return -EIO; } if (!app_idx || (*app_idx != 0xFFFF && *app_idx >= 0x1000)) { - BT_ERR("%s: Invalid parameter", __func__); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } /* Check if the same application key already exists */ if (provisioner_check_app_key(app_key, app_idx)) { - BT_WARN("%s: AppKey already exists, AppKey Index updated", __func__); + BT_WARN("%s, AppKey already exists, AppKey Index updated", __func__); return 0; } /* Check if the net_idx exists */ if (provisioner_check_net_idx(net_idx, false)) { - BT_ERR("%s: NetKey Index does not exist", __func__); + BT_ERR("%s, NetKey Index does not exist", __func__); return -ENODEV; } /* Check if the same app_idx already exists */ if (provisioner_check_app_idx(*app_idx, true)) { - BT_ERR("%s: AppKey Index already exists", __func__); + BT_ERR("%s, AppKey Index already exists", __func__); return -EEXIST; } add = provisioner_check_app_key_full(); if (add < 0) { - BT_ERR("%s: AppKey queue is full", __func__); + BT_ERR("%s, AppKey queue is full", __func__); return -ENOMEM; } if (!app_key) { if (bt_mesh_rand(p_key, 16)) { - BT_ERR("%s: Failed to generate AppKey", __func__); + BT_ERR("%s, Failed to generate AppKey", __func__); return -EIO; } } else { @@ -768,13 +767,13 @@ int bt_mesh_provisioner_local_app_key_add(const u8_t app_key[16], u16_t net_idx, key = osi_calloc(sizeof(struct bt_mesh_app_key)); if (!key) { - BT_ERR("%s: Failed to allocate memory", __func__); + BT_ERR("%s, Failed to allocate 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("%s, Failed to generate AID", __func__); osi_free(key); return -EIO; } @@ -789,7 +788,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("%s: No AppKey Index available", __func__); + BT_ERR("%s, No AppKey Index available", __func__); osi_free(key); return -EIO; } @@ -814,12 +813,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 does not exist", __func__); + BT_ERR("%s, NetKey Index does not exist", __func__); return NULL; } if (provisioner_check_app_idx(app_idx, false)) { - BT_ERR("%s: AppKey Index does not exist", __func__); + BT_ERR("%s, AppKey Index does not exist", __func__); return NULL; } @@ -845,12 +844,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 does not exist", __func__); + BT_ERR("%s, NetKey Index does not exist", __func__); return -ENODEV; } if (provisioner_check_app_idx(app_idx, false)) { - BT_ERR("%s: AppKey Index does not exist", __func__); + BT_ERR("%s, AppKey Index does not exist", __func__); return -ENODEV; } @@ -875,36 +874,36 @@ 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("%s: No NetKey Index available", __func__); + BT_ERR("%s, No NetKey Index available", __func__); return -EIO; } if (!net_idx || (*net_idx != 0xFFFF && *net_idx >= 0x1000)) { - BT_ERR("%s: Invalid parameter", __func__); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } /* Check if the same network key already exists */ if (provisioner_check_net_key(net_key, net_idx)) { - BT_WARN("%s: NetKey already exists, NetKey Index updated", __func__); + BT_WARN("%s, NetKey already exists, NetKey Index updated", __func__); return 0; } /* Check if the same net_idx already exists */ if (provisioner_check_net_idx(*net_idx, true)) { - BT_ERR("%s: NetKey Index already exists", __func__); + BT_ERR("%s, NetKey Index already exists", __func__); return -EEXIST; } add = provisioner_check_net_key_full(); if (add < 0) { - BT_ERR("%s: NetKey queue is full", __func__); + BT_ERR("%s, NetKey queue is full", __func__); return -ENOMEM; } if (!net_key) { if (bt_mesh_rand(p_key, 16)) { - BT_ERR("%s: Failed to generate NetKey", __func__); + BT_ERR("%s, Failed to generate NetKey", __func__); return -EIO; } } else { @@ -913,12 +912,12 @@ int bt_mesh_provisioner_local_net_key_add(const u8_t net_key[16], u16_t *net_idx sub = osi_calloc(sizeof(struct bt_mesh_subnet)); if (!sub) { - BT_ERR("%s: Failed to allocate memory", __func__); + BT_ERR("%s, Failed to allocate 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("%s, Failed to generate NID", __func__); osi_free(sub); return -EIO; } @@ -931,7 +930,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("%s: No NetKey Index available", __func__); + BT_ERR("%s, No NetKey Index available", __func__); osi_free(sub); return -EIO; } @@ -941,9 +940,9 @@ int bt_mesh_provisioner_local_net_key_add(const u8_t net_key[16], u16_t *net_idx } *net_idx = sub->net_idx; } - sub->kr_phase = BT_MESH_KR_NORMAL; + sub->kr_phase = BLE_MESH_KR_NORMAL; sub->kr_flag = false; - sub->node_id = BT_MESH_NODE_IDENTITY_NOT_SUPPORTED; + sub->node_id = BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED; bt_mesh.p_sub[add] = sub; @@ -958,7 +957,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 does not exist", __func__); + BT_ERR("%s, NetKey Index does not exist", __func__); return NULL; } @@ -983,7 +982,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 does not exist", __func__); + BT_ERR("%s, NetKey Index does not exist", __func__); return -ENODEV; } @@ -1003,7 +1002,7 @@ int bt_mesh_provisioner_local_net_key_delete(u16_t net_idx) int bt_mesh_provisioner_get_own_unicast_addr(u16_t *addr, u8_t *elem_num) { if (!addr || !elem_num || !prov || !comp) { - BT_ERR("%s: Invalid parameter", __func__); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } @@ -1021,7 +1020,7 @@ int bt_mesh_provisioner_bind_local_model_app_idx(u16_t elem_addr, u16_t mod_id, int i; if (!comp) { - BT_ERR("%s: NULL composition data", __func__); + BT_ERR("%s, NULL composition data", __func__); return -EINVAL; } @@ -1032,7 +1031,7 @@ int bt_mesh_provisioner_bind_local_model_app_idx(u16_t elem_addr, u16_t mod_id, } } if (i == comp->elem_count) { - BT_ERR("%s: No element is found", __func__); + BT_ERR("%s, No element is found", __func__); return -ENODEV; } @@ -1042,30 +1041,30 @@ 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("%s, No model is found", __func__); return -ENODEV; } if (provisioner_check_app_idx(app_idx, false)) { - BT_ERR("%s: AppKey Index does not exist", __func__); + BT_ERR("%s, AppKey Index does not exist", __func__); return -ENODEV; } for (i = 0; i < ARRAY_SIZE(model->keys); i++) { if (model->keys[i] == app_idx) { - BT_WARN("%s: AppKey Index is already binded with model", __func__); + BT_WARN("%s, AppKey Index is already binded with model", __func__); return 0; } } for (i = 0; i < ARRAY_SIZE(model->keys); i++) { - if (model->keys[i] == BT_MESH_KEY_UNUSED) { + if (model->keys[i] == BLE_MESH_KEY_UNUSED) { model->keys[i] = app_idx; return 0; } } - BT_ERR("%s: Model AppKey queue is full", __func__); + BT_ERR("%s, Model AppKey queue is full", __func__); return -ENOMEM; } @@ -1077,12 +1076,12 @@ int bt_mesh_provisioner_bind_local_app_net_idx(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 does not exist", __func__); + BT_ERR("%s, NetKey Index does not exist", __func__); return -ENODEV; } if (provisioner_check_app_idx(app_idx, false)) { - BT_ERR("%s: AppKey Index does not exist", __func__); + BT_ERR("%s, AppKey Index does not exist", __func__); return -ENODEV; } @@ -1105,7 +1104,7 @@ int bt_mesh_provisioner_print_local_element_info(void) int i, j; if (!comp) { - BT_ERR("%s: NULL composition data", __func__); + BT_ERR("%s, NULL composition data", __func__); return -EINVAL; } @@ -1130,11 +1129,11 @@ int bt_mesh_provisioner_print_local_element_info(void) return 0; } -#endif /* CONFIG_BT_MESH_PROVISIONER */ +#endif /* CONFIG_BLE_MESH_PROVISIONER */ /* The following APIs are for fast provisioning */ -#if CONFIG_BT_MESH_FAST_PROV +#if CONFIG_BLE_MESH_FAST_PROV const u8_t *get_fast_prov_device_key(u16_t addr) { @@ -1142,8 +1141,8 @@ const u8_t *get_fast_prov_device_key(u16_t addr) BT_DBG("%s", __func__); - if (!BT_MESH_ADDR_IS_UNICAST(addr)) { - BT_ERR("%s: Not a unicast address 0x%04x", __func__, addr); + if (!BLE_MESH_ADDR_IS_UNICAST(addr)) { + BT_ERR("%s, Not a unicast address 0x%04x", __func__, addr); return NULL; } @@ -1214,7 +1213,7 @@ u8_t bt_mesh_set_fast_prov_net_idx(u16_t net_idx) sub = get_fast_prov_subnet(net_idx); if (sub) { - key = BT_MESH_KEY_REFRESH(sub->kr_flag) ? &sub->keys[1] : &sub->keys[0]; + key = BLE_MESH_KEY_REFRESH(sub->kr_flag) ? &sub->keys[1] : &sub->keys[0]; return provisioner_set_fast_prov_net_idx(key->net, net_idx); } @@ -1251,7 +1250,7 @@ const u8_t *bt_mesh_get_fast_prov_net_key(u16_t net_idx) sub = get_fast_prov_subnet(net_idx); if (!sub) { - BT_ERR("%s: Failed to get subnet", __func__); + BT_ERR("%s, Failed to get subnet", __func__); return NULL; } @@ -1264,13 +1263,11 @@ const u8_t *bt_mesh_get_fast_prov_app_key(u16_t net_idx, u16_t app_idx) key = get_fast_prov_app_key(net_idx, app_idx); if (!key) { - BT_ERR("%s: Failed to get AppKey", __func__); + BT_ERR("%s, Failed to get AppKey", __func__); return NULL; } return (key->updated ? key->keys[1].val : key->keys[0].val); } -#endif /* CONFIG_BT_MESH_FAST_PROV */ - -#endif /* CONFIG_BT_MESH */ \ No newline at end of file +#endif /* CONFIG_BLE_MESH_FAST_PROV */ diff --git a/components/bt/ble_mesh/mesh_core/provisioner_main.h b/components/bt/ble_mesh/mesh_core/provisioner_main.h index d7fb7faeb6..a4b6a38c84 100644 --- a/components/bt/ble_mesh/mesh_core/provisioner_main.h +++ b/components/bt/ble_mesh/mesh_core/provisioner_main.h @@ -22,7 +22,7 @@ #define MESH_NAME_SIZE 31 -#if CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_PROVISIONER /* Each node information stored by provisioner */ struct bt_mesh_node_t { @@ -105,11 +105,11 @@ int bt_mesh_provisioner_bind_local_app_net_idx(u16_t net_idx, u16_t app_idx); /* Provisioner print own element information */ int bt_mesh_provisioner_print_local_element_info(void); -#endif /* CONFIG_BT_MESH_PROVISIONER */ +#endif /* CONFIG_BLE_MESH_PROVISIONER */ /* The following APIs are for fast provisioning */ -#if CONFIG_BT_MESH_FAST_PROV +#if CONFIG_BLE_MESH_FAST_PROV const u8_t *get_fast_prov_device_key(u16_t dst_addr); @@ -125,6 +125,6 @@ const u8_t *bt_mesh_get_fast_prov_net_key(u16_t net_idx); const u8_t *bt_mesh_get_fast_prov_app_key(u16_t net_idx, u16_t app_idx); -#endif /* CONFIG_BT_MESH_FAST_PROV */ +#endif /* CONFIG_BLE_MESH_FAST_PROV */ #endif /* _PROVISIONER_MAIN_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/provisioner_prov.c b/components/bt/ble_mesh/mesh_core/provisioner_prov.c index 2d165c7d32..4569c02440 100644 --- a/components/bt/ble_mesh/mesh_core/provisioner_prov.c +++ b/components/bt/ble_mesh/mesh_core/provisioner_prov.c @@ -19,25 +19,24 @@ #include "sdkconfig.h" #include "osi/allocator.h" -#if CONFIG_BT_MESH -#include "mesh.h" #include "mesh_main.h" #include "mesh_trace.h" #include "crypto.h" #include "adv.h" +#include "mesh.h" #include "provisioner_prov.h" #include "provisioner_proxy.h" #include "provisioner_main.h" -#if CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_PROVISIONER #define CONFIG_BT_MAX_CONN CONFIG_BT_ACL_CONNECTIONS /* Service data length has minus 1 type length & 2 uuid length*/ -#define BT_MESH_PROV_SRV_DATA_LEN 0x12 -#define BT_MESH_PROXY_SRV_DATA_LEN1 0x09 -#define BT_MESH_PROXY_SRV_DATA_LEN2 0x11 +#define BLE_MESH_PROV_SRV_DATA_LEN 0x12 +#define BLE_MESH_PROXY_SRV_DATA_LEN1 0x09 +#define BLE_MESH_PROXY_SRV_DATA_LEN2 0x11 /* 3 transmissions, 20ms interval */ #define PROV_XMIT_COUNT 2 @@ -138,7 +137,7 @@ enum { * |<----------------------Total Link---------------------->| */ struct prov_link { - ATOMIC_DEFINE(flags, NUM_FLAGS); + BLE_MESH_ATOMIC_DEFINE(flags, NUM_FLAGS); u8_t uuid[16]; /* check if device is being provisioned*/ u16_t oob_info; /* oob info of this device */ u8_t element_num; /* element num of device */ @@ -148,10 +147,10 @@ struct prov_link { u8_t auth_action; /* choosed authentication action */ u8_t auth_size; /* choosed authentication size */ u16_t unicast_addr; /* unicast address assigned for device */ - bt_addr_le_t addr; /* Device address */ -#if defined(CONFIG_BT_MESH_PB_GATT) + bt_mesh_addr_t addr; /* Device address */ +#if defined(CONFIG_BLE_MESH_PB_GATT) bool connecting; /* start connecting with device */ - struct bt_conn *conn; /* GATT connection */ + struct bt_mesh_conn *conn; /* GATT connection */ #endif u8_t expect; /* Next expected PDU */ @@ -167,7 +166,7 @@ struct prov_link { u8_t *prov_salt; /* Provisioning Salt */ -#if defined(CONFIG_BT_MESH_PB_ADV) +#if defined(CONFIG_BLE_MESH_PB_ADV) bool linking; /* Linking is being establishing */ u16_t link_close; /* Link close been sent flag */ u32_t link_id; /* Link ID */ @@ -211,7 +210,7 @@ struct prov_rx { u8_t gpc; }; -#define BT_MESH_ALREADY_PROV_NUM (CONFIG_BT_MESH_MAX_PROV_NODES + 10) +#define BLE_MESH_ALREADY_PROV_NUM (CONFIG_BLE_MESH_MAX_PROV_NODES + 10) struct prov_ctx_t { /* If provisioning random have been generated, set BIT0 to 1 */ @@ -266,12 +265,12 @@ struct prov_ctx_t { u8_t uuid[16]; /* device uuid */ u8_t element_num; /* element number of the deleted node */ u16_t unicast_addr; /* Primary unicast address of the deleted node */ - } already_prov[BT_MESH_ALREADY_PROV_NUM]; + } already_prov[BLE_MESH_ALREADY_PROV_NUM]; }; struct prov_node_info { bool provisioned; /* device provisioned flag */ - bt_addr_le_t addr; /* device address */ + bt_mesh_addr_t addr; /* device address */ u8_t uuid[16]; /* node uuid */ u16_t oob_info; /* oob info contained in adv pkt */ u8_t element_num; /* element contained in this node */ @@ -282,13 +281,13 @@ struct prov_node_info { }; struct unprov_dev_queue { - bt_addr_le_t addr; + bt_mesh_addr_t addr; u8_t uuid[16]; u16_t oob_info; u8_t bearer; u8_t flags; -} __packed unprov_dev[CONFIG_BT_MESH_UNPROV_DEV_ADD] = { - [0 ... (CONFIG_BT_MESH_UNPROV_DEV_ADD - 1)] = { +} __packed unprov_dev[CONFIG_BLE_MESH_WAIT_FOR_PROV_MAX_DEV_NUM] = { + [0 ... (CONFIG_BLE_MESH_WAIT_FOR_PROV_MAX_DEV_NUM - 1)] = { .addr.type = 0xff, .bearer = 0, .flags = false, @@ -299,15 +298,15 @@ static unprov_adv_pkt_cb_t notify_unprov_adv_pkt_cb; #define RETRANSMIT_TIMEOUT K_MSEC(500) #define BUF_TIMEOUT K_MSEC(400) -#if defined(CONFIG_BT_MESH_FAST_PROV) +#if defined(CONFIG_BLE_MESH_FAST_PROV) #define TRANSACTION_TIMEOUT K_SECONDS(3) #define PROVISION_TIMEOUT K_SECONDS(6) #else #define TRANSACTION_TIMEOUT K_SECONDS(30) #define PROVISION_TIMEOUT K_SECONDS(60) -#endif /* CONFIG_BT_MESH_FAST_PROV */ +#endif /* CONFIG_BLE_MESH_FAST_PROV */ -#if defined(CONFIG_BT_MESH_PB_GATT) +#if defined(CONFIG_BLE_MESH_PB_GATT) #define PROV_BUF_HEADROOM 5 #else #define PROV_BUF_HEADROOM 0 @@ -316,17 +315,17 @@ static unprov_adv_pkt_cb_t notify_unprov_adv_pkt_cb; #define PROV_BUF(len) NET_BUF_SIMPLE(PROV_BUF_HEADROOM + len) /* Number of devices can be provisioned at the same time using PB-GATT + PB-ADV */ -#define BT_MESH_PROV_SAME_TIME (CONFIG_BT_MESH_PBA_SAME_TIME + CONFIG_BT_MESH_PBG_SAME_TIME) +#define BLE_MESH_PROV_SAME_TIME (CONFIG_BLE_MESH_PBA_SAME_TIME + CONFIG_BLE_MESH_PBG_SAME_TIME) -static struct prov_link link[BT_MESH_PROV_SAME_TIME]; +static struct prov_link link[BLE_MESH_PROV_SAME_TIME]; static const struct bt_mesh_prov *prov; static struct prov_ctx_t prov_ctx; -static struct prov_node_info prov_nodes[CONFIG_BT_MESH_MAX_PROV_NODES]; +static struct prov_node_info prov_nodes[CONFIG_BLE_MESH_MAX_PROV_NODES]; -#if defined(CONFIG_BT_MESH_PB_ADV) +#if defined(CONFIG_BLE_MESH_PB_ADV) static void send_link_open(void); #endif @@ -336,12 +335,12 @@ static void send_pub_key(u8_t oob); static void close_link(int i, u8_t reason); -#if defined(CONFIG_BT_MESH_PB_ADV) +#if defined(CONFIG_BLE_MESH_PB_ADV) #define ADV_BUF_SIZE 65 static struct adv_buf_t { struct net_buf_simple buf; u8_t adv_buf_data[ADV_BUF_SIZE]; -} adv_buf[CONFIG_BT_MESH_PBA_SAME_TIME]; +} adv_buf[CONFIG_BLE_MESH_PBA_SAME_TIME]; #endif #define PROV_FREE_MEM(id, member) \ @@ -388,30 +387,30 @@ void provisioner_pbg_count_inc(void) void provisioner_clear_link_conn_info(u8_t addr[6]) { -#if defined(CONFIG_BT_MESH_PB_GATT) +#if defined(CONFIG_BLE_MESH_PB_GATT) if (!addr) { BT_ERR("%s, Invalid parameter", __func__); return; } - BT_DBG("%s, Clear device %s info", __func__, bt_hex(addr, BD_ADDR_LEN)); + BT_DBG("%s, Clear device %s info", __func__, bt_hex(addr, BLE_MESH_ADDR_LEN)); - for (int i = CONFIG_BT_MESH_PBA_SAME_TIME; i < BT_MESH_PROV_SAME_TIME; i++) { - if (!memcmp(link[i].addr.a.val, addr, BD_ADDR_LEN)) { + for (int 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)) { link[i].connecting = false; link[i].conn = NULL; link[i].oob_info = 0x0; memset(link[i].uuid, 0, 16); - memset(&link[i].addr, 0, sizeof(bt_addr_le_t)); - atomic_test_and_clear_bit(link[i].flags, LINK_ACTIVE); - if (atomic_test_and_clear_bit(link[i].flags, TIMEOUT_START)) { + memset(&link[i].addr, 0, sizeof(bt_mesh_addr_t)); + bt_mesh_atomic_test_and_clear_bit(link[i].flags, LINK_ACTIVE); + if (bt_mesh_atomic_test_and_clear_bit(link[i].flags, TIMEOUT_START)) { k_delayed_work_cancel(&link[i].timeout); } return; } } - BT_WARN("%s, Address %s is not found", __func__, bt_hex(addr, BD_ADDR_LEN)); + BT_WARN("%s, Address %s is not found", __func__, bt_hex(addr, BLE_MESH_ADDR_LEN)); return; #endif } @@ -438,7 +437,7 @@ int provisioner_prov_reset_all_nodes(void) return 0; } -static int provisioner_dev_find(const bt_addr_le_t *addr, const u8_t uuid[16], int *index) +static int provisioner_dev_find(const bt_mesh_addr_t *addr, const u8_t uuid[16], int *index) { bool uuid_match = false; bool addr_match = false; @@ -446,7 +445,7 @@ static int provisioner_dev_find(const bt_addr_le_t *addr, const u8_t uuid[16], i int i = 0, j = 0, comp = 0; if (addr) { - comp = memcmp(addr->a.val, zero, BD_ADDR_LEN); + comp = memcmp(addr->val, zero, BLE_MESH_ADDR_LEN); } if ((!uuid && (!addr || (comp == 0) || (addr->type > BLE_ADDR_RANDOM))) || !index) { @@ -468,7 +467,7 @@ static int provisioner_dev_find(const bt_addr_le_t *addr, const u8_t uuid[16], i if (addr && comp && (addr->type <= BLE_ADDR_RANDOM)) { for (j = 0; j < ARRAY_SIZE(unprov_dev); j++) { - if (!memcmp(unprov_dev[j].addr.a.val, addr->a.val, BD_ADDR_LEN) && + if (!memcmp(unprov_dev[j].addr.val, addr->val, BLE_MESH_ADDR_LEN) && unprov_dev[j].addr.type == addr->type) { addr_match = true; break; @@ -487,7 +486,7 @@ static int provisioner_dev_find(const bt_addr_le_t *addr, const u8_t uuid[16], i * will be decided by uuid element. */ unprov_dev[i].addr.type = unprov_dev[j].addr.type; - memcpy(unprov_dev[i].addr.a.val, unprov_dev[j].addr.a.val, BD_ADDR_LEN); + memcpy(unprov_dev[i].addr.val, unprov_dev[j].addr.val, BLE_MESH_ADDR_LEN); unprov_dev[i].bearer |= unprov_dev[j].bearer; memset(&unprov_dev[j], 0x0, sizeof(struct unprov_dev_queue)); } @@ -528,11 +527,11 @@ static int provisioner_check_device_uuid(const u8_t uuid[16]) * receive the connectable prov adv pkt from this device. * Here we check both PB-GATT and PB-ADV link status. */ - for (i = 0; i < BT_MESH_PROV_SAME_TIME; i++) { -#if defined(CONFIG_BT_MESH_PB_GATT) - if (link[i].connecting || atomic_test_bit(link[i].flags, LINK_ACTIVE)) { + for (i = 0; i < BLE_MESH_PROV_SAME_TIME; i++) { +#if defined(CONFIG_BLE_MESH_PB_GATT) + if (link[i].connecting || bt_mesh_atomic_test_bit(link[i].flags, LINK_ACTIVE)) { #else - if (link[i].linking || atomic_test_bit(link[i].flags, LINK_ACTIVE)) { + if (link[i].linking || 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__); @@ -572,27 +571,27 @@ static int provisioner_check_device_uuid(const u8_t uuid[16]) } static int provisioner_start_prov_device(bt_mesh_prov_bearer_t bearer, const u8_t uuid[16], - const bt_addr_le_t *addr, u16_t oob_info) + const bt_mesh_addr_t *addr, u16_t oob_info) { u8_t zero[6] = {0}; int addr_cmp, i; - if ((bearer != BT_MESH_PROV_ADV && bearer != BT_MESH_PROV_GATT) || !uuid || !addr) { + if ((bearer != BLE_MESH_PROV_ADV && bearer != BLE_MESH_PROV_GATT) || !uuid || !addr) { BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } - addr_cmp = memcmp(addr->a.val, zero, BD_ADDR_LEN); + addr_cmp = memcmp(addr->val, zero, BLE_MESH_ADDR_LEN); - if (bearer == BT_MESH_PROV_ADV) { -#if defined(CONFIG_BT_MESH_PB_ADV) - for (i = 0; i < CONFIG_BT_MESH_PBA_SAME_TIME; i++) { - if (!atomic_test_bit(link[i].flags, LINK_ACTIVE) && !link[i].linking) { + if (bearer == BLE_MESH_PROV_ADV) { +#if defined(CONFIG_BLE_MESH_PB_ADV) + for (i = 0; i < CONFIG_BLE_MESH_PBA_SAME_TIME; i++) { + if (!bt_mesh_atomic_test_bit(link[i].flags, LINK_ACTIVE) && !link[i].linking) { memcpy(link[i].uuid, uuid, 16); link[i].oob_info = oob_info; if (addr_cmp && (addr->type <= BLE_ADDR_RANDOM)) { link[i].addr.type = addr->type; - memcpy(link[i].addr.a.val, addr->a.val, BD_ADDR_LEN); + memcpy(link[i].addr.val, addr->val, BLE_MESH_ADDR_LEN); } prov_set_pb_index(i); send_link_open(); @@ -606,26 +605,26 @@ static int provisioner_start_prov_device(bt_mesh_prov_bearer_t bearer, const u8_ */ link[i].linking = true; if (prov->prov_link_open) { - prov->prov_link_open(BT_MESH_PROV_ADV); + prov->prov_link_open(BLE_MESH_PROV_ADV); } return 0; } } #endif } else { -#if defined(CONFIG_BT_MESH_PB_GATT) - for (i = CONFIG_BT_MESH_PBA_SAME_TIME; i < BT_MESH_PROV_SAME_TIME; i++) { - if (!atomic_test_bit(link[i].flags, LINK_ACTIVE) && !link[i].connecting) { +#if defined(CONFIG_BLE_MESH_PB_GATT) + for (i = CONFIG_BLE_MESH_PBA_SAME_TIME; i < BLE_MESH_PROV_SAME_TIME; i++) { + if (!bt_mesh_atomic_test_bit(link[i].flags, LINK_ACTIVE) && !link[i].connecting) { memcpy(link[i].uuid, uuid, 16); link[i].oob_info = oob_info; if (addr_cmp && (addr->type <= BLE_ADDR_RANDOM)) { link[i].addr.type = addr->type; - memcpy(link[i].addr.a.val, addr->a.val, BD_ADDR_LEN); + memcpy(link[i].addr.val, addr->val, BLE_MESH_ADDR_LEN); } - if (bt_mesh_gattc_conn_create(&link[i].addr, BT_UUID_MESH_PROV_VAL)) { + if (bt_mesh_gattc_conn_create(&link[i].addr, BLE_MESH_UUID_MESH_PROV_VAL)) { memset(link[i].uuid, 0, 16); link[i].oob_info = 0x0; - memset(&link[i].addr, 0, sizeof(bt_addr_le_t)); + memset(&link[i].addr, 0, sizeof(bt_mesh_addr_t)); return -EIO; } /* If creating connection successfully, set connecting flag to 1 */ @@ -636,13 +635,13 @@ static int provisioner_start_prov_device(bt_mesh_prov_bearer_t bearer, const u8_ #endif } - BT_ERR("%s, no link is available", __func__); + BT_ERR("%s, No link is available", __func__); return -ENOMEM; } int bt_mesh_provisioner_add_unprov_dev(struct bt_mesh_unprov_dev_add *add_dev, u8_t flags) { - bt_addr_le_t add_addr = {0}; + bt_mesh_addr_t add_addr = {0}; u8_t zero[16] = {0}; int addr_cmp = 0, uuid_cmp = 0; int i, err = 0; @@ -652,7 +651,7 @@ int bt_mesh_provisioner_add_unprov_dev(struct bt_mesh_unprov_dev_add *add_dev, u return -EINVAL; } - addr_cmp = memcmp(add_dev->addr, zero, BD_ADDR_LEN); + addr_cmp = memcmp(add_dev->addr, zero, BLE_MESH_ADDR_LEN); uuid_cmp = memcmp(add_dev->uuid, zero, 16); if (add_dev->bearer == 0x0 || ((uuid_cmp == 0) && @@ -661,7 +660,7 @@ int bt_mesh_provisioner_add_unprov_dev(struct bt_mesh_unprov_dev_add *add_dev, u return -EINVAL; } - if ((add_dev->bearer & BT_MESH_PROV_ADV) && (add_dev->bearer & BT_MESH_PROV_GATT) && + 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 simultaneouly", __func__); return -EINVAL; @@ -672,28 +671,28 @@ int bt_mesh_provisioner_add_unprov_dev(struct bt_mesh_unprov_dev_add *add_dev, u return -EINVAL; } - if ((add_dev->bearer & BT_MESH_PROV_GATT) && (flags & START_PROV_NOW) && + if ((add_dev->bearer & BLE_MESH_PROV_GATT) && (flags & START_PROV_NOW) && ((addr_cmp == 0) || add_dev->addr_type > BLE_ADDR_RANDOM)) { BT_ERR("%s, Invalid device address for PB-GATT", __func__); return -EINVAL; } - if (add_dev->bearer & BT_MESH_PROV_GATT) { -#if !CONFIG_BT_MESH_PB_GATT + if (add_dev->bearer & BLE_MESH_PROV_GATT) { +#if !CONFIG_BLE_MESH_PB_GATT BT_ERR("%s, Not support PB-GATT", __func__); return -EINVAL; #endif } - if (add_dev->bearer & BT_MESH_PROV_ADV) { -#if !CONFIG_BT_MESH_PB_ADV + if (add_dev->bearer & BLE_MESH_PROV_ADV) { +#if !CONFIG_BLE_MESH_PB_ADV BT_ERR("%s, Not support PB-ADV", __func__); return -EINVAL; #endif } add_addr.type = add_dev->addr_type; - memcpy(add_addr.a.val, add_dev->addr, BD_ADDR_LEN); + memcpy(add_addr.val, add_dev->addr, BLE_MESH_ADDR_LEN); err = provisioner_dev_find(&add_addr, add_dev->uuid, &i); if (err == -EINVAL) { @@ -715,7 +714,7 @@ int bt_mesh_provisioner_add_unprov_dev(struct bt_mesh_unprov_dev_add *add_dev, u } if (addr_cmp && (add_dev->addr_type <= BLE_ADDR_RANDOM)) { unprov_dev[i].addr.type = add_dev->addr_type; - memcpy(unprov_dev[i].addr.a.val, add_dev->addr, BD_ADDR_LEN); + memcpy(unprov_dev[i].addr.val, add_dev->addr, BLE_MESH_ADDR_LEN); } if (uuid_cmp) { memcpy(unprov_dev[i].uuid, add_dev->uuid, 16); @@ -731,7 +730,7 @@ int bt_mesh_provisioner_add_unprov_dev(struct bt_mesh_unprov_dev_add *add_dev, u memset(&unprov_dev[i], 0, sizeof(struct unprov_dev_queue)); if (addr_cmp && (add_dev->addr_type <= BLE_ADDR_RANDOM)) { unprov_dev[i].addr.type = add_dev->addr_type; - memcpy(unprov_dev[i].addr.a.val, add_dev->addr, BD_ADDR_LEN); + memcpy(unprov_dev[i].addr.val, add_dev->addr, BLE_MESH_ADDR_LEN); } if (uuid_cmp) { memcpy(unprov_dev[i].uuid, add_dev->uuid, 16); @@ -761,24 +760,24 @@ start: return err; } - if (add_dev->bearer & BT_MESH_PROV_ADV) { -#if defined(CONFIG_BT_MESH_PB_ADV) - if (prov_ctx.pba_count == CONFIG_BT_MESH_PBA_SAME_TIME) { + if (add_dev->bearer & BLE_MESH_PROV_ADV) { +#if defined(CONFIG_BLE_MESH_PB_ADV) + if (prov_ctx.pba_count == CONFIG_BLE_MESH_PBA_SAME_TIME) { BT_WARN("%s, Current PB-ADV links reach max limit", __func__); return -EIO; } - if ((err = provisioner_start_prov_device(BT_MESH_PROV_ADV, + if ((err = provisioner_start_prov_device(BLE_MESH_PROV_ADV, add_dev->uuid, &add_addr, add_dev->oob_info))) { return err; } #endif - } else if (add_dev->bearer & BT_MESH_PROV_GATT) { -#if defined(CONFIG_BT_MESH_PB_GATT) - if (prov_ctx.pbg_count == CONFIG_BT_MESH_PBG_SAME_TIME) { + } else if (add_dev->bearer & BLE_MESH_PROV_GATT) { +#if defined(CONFIG_BLE_MESH_PB_GATT) + if (prov_ctx.pbg_count == CONFIG_BLE_MESH_PBG_SAME_TIME) { BT_WARN("%s, Current PB-GATT links reach max limit", __func__); return -EIO; } - if ((err = provisioner_start_prov_device(BT_MESH_PROV_GATT, + if ((err = provisioner_start_prov_device(BLE_MESH_PROV_GATT, add_dev->uuid, &add_addr, add_dev->oob_info))) { return err; } @@ -798,7 +797,7 @@ int bt_mesh_provisioner_delete_device(struct bt_mesh_device_delete *del_dev) * remove from device queue. config _node_reset can be added in function * provisioner_node_reset() in provisioner_main.c. */ - bt_addr_le_t del_addr = {0}; + bt_mesh_addr_t del_addr = {0}; u8_t zero[16] = {0}; int addr_cmp = 0, uuid_cmp = 0; bool addr_match = false; @@ -810,7 +809,7 @@ int bt_mesh_provisioner_delete_device(struct bt_mesh_device_delete *del_dev) return -EINVAL; } - addr_cmp = memcmp(del_dev->addr, zero, BD_ADDR_LEN); + addr_cmp = memcmp(del_dev->addr, zero, BLE_MESH_ADDR_LEN); uuid_cmp = memcmp(del_dev->uuid, zero, 16); if ((uuid_cmp == 0) && ((addr_cmp == 0) || del_dev->addr_type > BLE_ADDR_RANDOM)) { @@ -819,7 +818,7 @@ int bt_mesh_provisioner_delete_device(struct bt_mesh_device_delete *del_dev) } del_addr.type = del_dev->addr_type; - memcpy(del_addr.a.val, del_dev->addr, BD_ADDR_LEN); + memcpy(del_addr.val, del_dev->addr, BLE_MESH_ADDR_LEN); /* First: find if the device is in the device queue */ err = provisioner_dev_find(&del_addr, del_dev->uuid, &i); @@ -832,7 +831,7 @@ int bt_mesh_provisioner_delete_device(struct bt_mesh_device_delete *del_dev) /* Second: find if the device is being provisioned */ for (i = 0; i < ARRAY_SIZE(link); i++) { if (addr_cmp && (del_dev->addr_type <= BLE_ADDR_RANDOM)) { - if (!memcmp(link[i].addr.a.val, del_dev->addr, BD_ADDR_LEN) && + if (!memcmp(link[i].addr.val, del_dev->addr, BLE_MESH_ADDR_LEN) && link[i].addr.type == del_dev->addr_type) { addr_match = true; } @@ -851,7 +850,7 @@ int bt_mesh_provisioner_delete_device(struct bt_mesh_device_delete *del_dev) /* Third: find if the device is been provisioned */ for (i = 0; i < ARRAY_SIZE(prov_nodes); i++) { if (addr_cmp && (del_dev->addr_type <= BLE_ADDR_RANDOM)) { - if (!memcmp(prov_nodes[i].addr.a.val, del_dev->addr, BD_ADDR_LEN) && + if (!memcmp(prov_nodes[i].addr.val, del_dev->addr, BLE_MESH_ADDR_LEN) && prov_nodes[i].addr.type == del_dev->addr_type) { addr_match = true; } @@ -962,7 +961,7 @@ u16_t provisioner_get_fast_prov_net_idx(void) u8_t bt_mesh_set_fast_prov_unicast_addr_range(u16_t min, u16_t max) { - if (!BT_MESH_ADDR_IS_UNICAST(min) || !BT_MESH_ADDR_IS_UNICAST(max)) { + if (!BLE_MESH_ADDR_IS_UNICAST(min) || !BLE_MESH_ADDR_IS_UNICAST(max)) { BT_ERR("%s, Not a unicast address", __func__); return 0x01; /* status: not a unicast address */ } @@ -992,7 +991,7 @@ void bt_mesh_set_fast_prov_flags_iv_index(u8_t flags, u32_t iv_index) fast_prov.iv_index = iv_index; } -#if defined(CONFIG_BT_MESH_PB_ADV) +#if defined(CONFIG_BLE_MESH_PB_ADV) static struct net_buf_simple *bt_mesh_pba_get_buf(int id) { struct net_buf_simple *buf = &(adv_buf[id].buf); @@ -1001,7 +1000,7 @@ static struct net_buf_simple *bt_mesh_pba_get_buf(int id) return buf; } -#endif /* CONFIG_BT_MESH_PB_ADV */ +#endif /* CONFIG_BLE_MESH_PB_ADV */ static void prov_memory_free(int i) { @@ -1014,7 +1013,7 @@ static void prov_memory_free(int i) PROV_FREE_MEM(i, prov_salt); } -#if defined(CONFIG_BT_MESH_PB_ADV) +#if defined(CONFIG_BLE_MESH_PB_ADV) static void buf_sent(int err, void *user_data) { int i = (int)user_data; @@ -1043,7 +1042,7 @@ static void free_segments(int id) link[id].tx.buf[i] = NULL; /* Mark as canceled */ - BT_MESH_ADV(buf)->busy = 0; + BLE_MESH_ADV(buf)->busy = 0; /** Change by Espressif. Add this to avoid buf->ref is 2 which will * cause lack of buf. */ @@ -1067,20 +1066,20 @@ static void reset_link(int i, u8_t reason) { prov_clear_tx(i); - if (atomic_test_and_clear_bit(link[i].flags, TIMEOUT_START)) { + if (bt_mesh_atomic_test_and_clear_bit(link[i].flags, TIMEOUT_START)) { k_delayed_work_cancel(&link[i].timeout); } if (prov->prov_link_close) { - prov->prov_link_close(BT_MESH_PROV_ADV, reason); + prov->prov_link_close(BLE_MESH_PROV_ADV, reason); } prov_memory_free(i); -#if defined(CONFIG_BT_MESH_USE_DUPLICATE_SCAN) +#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) /* Remove the link id from exceptional list */ - bt_mesh_update_exceptional_list(BT_MESH_EXCEP_LIST_REMOVE, - BT_MESH_EXCEP_INFO_MESH_LINK_ID, &link[i].link_id); + bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_REMOVE, + BLE_MESH_EXCEP_INFO_MESH_LINK_ID, &link[i].link_id); #endif /* Clear everything except the retransmit delayed work config */ @@ -1090,7 +1089,7 @@ static void reset_link(int i, u8_t reason) link[i].rx.prev_id = XACT_NVAL; if (bt_mesh_pub_key_get()) { - atomic_set_bit(link[i].flags, LOCAL_PUB_KEY); + bt_mesh_atomic_set_bit(link[i].flags, LOCAL_PUB_KEY); } link[i].rx.buf = bt_mesh_pba_get_buf(i); @@ -1104,7 +1103,7 @@ static struct net_buf *adv_buf_create(void) { struct net_buf *buf; - buf = bt_mesh_adv_create(BT_MESH_ADV_PROV, PROV_XMIT_COUNT, + buf = bt_mesh_adv_create(BLE_MESH_ADV_PROV, PROV_XMIT_COUNT, PROV_XMIT_INT, BUF_TIMEOUT); if (!buf) { BT_ERR("Out of provisioning buffers"); @@ -1224,29 +1223,29 @@ static void send_link_open(void) */ bt_mesh_rand(&link[i].link_id, sizeof(u32_t)); while (1) { - for (j = 0; j < CONFIG_BT_MESH_PBA_SAME_TIME; j++) { - if (atomic_test_bit(link[j].flags, LINK_ACTIVE) || link[j].linking) { + for (j = 0; j < CONFIG_BLE_MESH_PBA_SAME_TIME; j++) { + if (bt_mesh_atomic_test_bit(link[j].flags, LINK_ACTIVE) || link[j].linking) { if (link[i].link_id == link[j].link_id) { bt_mesh_rand(&link[i].link_id, sizeof(u32_t)); break; } } } - if (j == CONFIG_BT_MESH_PBA_SAME_TIME) { + if (j == CONFIG_BLE_MESH_PBA_SAME_TIME) { break; } } -#if defined(CONFIG_BT_MESH_USE_DUPLICATE_SCAN) +#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN) /* Add the link id into exceptional list */ - bt_mesh_update_exceptional_list(BT_MESH_EXCEP_LIST_ADD, - BT_MESH_EXCEP_INFO_MESH_LINK_ID, &link[i].link_id); + bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_ADD, + BLE_MESH_EXCEP_INFO_MESH_LINK_ID, &link[i].link_id); #endif bearer_ctl_send(i, LINK_OPEN, link[i].uuid, 16); /* Set LINK_ACTIVE just to be in compatibility with current Zephyr code */ - atomic_set_bit(link[i].flags, LINK_ACTIVE); + bt_mesh_atomic_set_bit(link[i].flags, LINK_ACTIVE); prov_ctx.pba_count++; } @@ -1299,7 +1298,7 @@ static int prov_send_adv(struct net_buf_simple *msg) link[i].tx.buf[0] = start; - seg_len = min(msg->len, START_PAYLOAD_MAX); + seg_len = MIN(msg->len, START_PAYLOAD_MAX); BT_DBG("seg 0 len %u: %s", seg_len, bt_hex(msg->data, seg_len)); net_buf_add_mem(start, msg->data, seg_len); net_buf_simple_pull(msg, seg_len); @@ -1320,7 +1319,7 @@ static int prov_send_adv(struct net_buf_simple *msg) link[i].tx.buf[seg_id] = buf; - seg_len = min(msg->len, CONT_PAYLOAD_MAX); + seg_len = MIN(msg->len, CONT_PAYLOAD_MAX); BT_DBG("seg_id %u len %u: %s", seg_id, seg_len, bt_hex(msg->data, seg_len)); @@ -1334,15 +1333,15 @@ static int prov_send_adv(struct net_buf_simple *msg) send_reliable(i); - if (!atomic_test_and_set_bit(link[i].flags, TIMEOUT_START)) { + if (!bt_mesh_atomic_test_and_set_bit(link[i].flags, TIMEOUT_START)) { k_delayed_work_submit(&link[i].timeout, PROVISION_TIMEOUT); } return 0; } -#endif /* CONFIG_BT_MESH_PB_ADV */ +#endif /* CONFIG_BLE_MESH_PB_ADV */ -#if defined(CONFIG_BT_MESH_PB_GATT) +#if defined(CONFIG_BLE_MESH_PB_GATT) static int prov_send_gatt(struct net_buf_simple *msg) { int i = prov_get_pb_index(); @@ -1352,33 +1351,33 @@ static int prov_send_gatt(struct net_buf_simple *msg) return -ENOTCONN; } - err = provisioner_proxy_send(link[i].conn, BT_MESH_PROXY_PROV, msg); + err = provisioner_proxy_send(link[i].conn, BLE_MESH_PROXY_PROV, msg); if (err) { BT_ERR("%s, Failed to send PB-GATT pdu", __func__); return err; } - if (!atomic_test_and_set_bit(link[i].flags, TIMEOUT_START)) { + if (!bt_mesh_atomic_test_and_set_bit(link[i].flags, TIMEOUT_START)) { k_delayed_work_submit(&link[i].timeout, PROVISION_TIMEOUT); } return 0; } -#endif /* CONFIG_BT_MESH_PB_GATT */ +#endif /* CONFIG_BLE_MESH_PB_GATT */ static inline int prov_send(struct net_buf_simple *buf) { int i = prov_get_pb_index(); - if (i < CONFIG_BT_MESH_PBA_SAME_TIME) { -#if defined(CONFIG_BT_MESH_PB_ADV) + if (i < CONFIG_BLE_MESH_PBA_SAME_TIME) { +#if defined(CONFIG_BLE_MESH_PB_ADV) return prov_send_adv(buf); #else return -EINVAL; #endif - } else if (i >= CONFIG_BT_MESH_PBA_SAME_TIME && - i < BT_MESH_PROV_SAME_TIME) { -#if defined(CONFIG_BT_MESH_PB_GATT) + } else if (i >= CONFIG_BLE_MESH_PBA_SAME_TIME && + i < BLE_MESH_PROV_SAME_TIME) { +#if defined(CONFIG_BLE_MESH_PB_GATT) return prov_send_gatt(buf); #else return -EINVAL; @@ -1508,7 +1507,7 @@ static void prov_capabilities(const u8_t *data) } /* Make sure received pdu is ok and cancel the timeout timer */ - if (atomic_test_and_clear_bit(link[i].flags, TIMEOUT_START)) { + if (bt_mesh_atomic_test_and_clear_bit(link[i].flags, TIMEOUT_START)) { k_delayed_work_cancel(&link[i].timeout); } @@ -1576,12 +1575,12 @@ static void prov_capabilities(const u8_t *data) /** If using PB-ADV, need to listen for transaction ack, * after ack is received, provisioner can send public key. */ -#if defined(CONFIG_BT_MESH_PB_ADV) - if (i < CONFIG_BT_MESH_PBA_SAME_TIME) { +#if defined(CONFIG_BLE_MESH_PB_ADV) + if (i < CONFIG_BLE_MESH_PBA_SAME_TIME) { link[i].expect_ack_for = PROV_START; return; } -#endif /* CONFIG_BT_MESH_PB_ADV */ +#endif /* CONFIG_BLE_MESH_PB_ADV */ send_pub_key(pub_key_oob); return; @@ -1595,17 +1594,17 @@ static bt_mesh_output_action_t output_action(u8_t action) { switch (action) { case OUTPUT_OOB_BLINK: - return BT_MESH_BLINK; + return BLE_MESH_BLINK; case OUTPUT_OOB_BEEP: - return BT_MESH_BEEP; + return BLE_MESH_BEEP; case OUTPUT_OOB_VIBRATE: - return BT_MESH_VIBRATE; + return BLE_MESH_VIBRATE; case OUTPUT_OOB_NUMBER: - return BT_MESH_DISPLAY_NUMBER; + return BLE_MESH_DISPLAY_NUMBER; case OUTPUT_OOB_STRING: - return BT_MESH_DISPLAY_STRING; + return BLE_MESH_DISPLAY_STRING; default: - return BT_MESH_NO_OUTPUT; + return BLE_MESH_NO_OUTPUT; } } @@ -1613,15 +1612,15 @@ static bt_mesh_input_action_t input_action(u8_t action) { switch (action) { case INPUT_OOB_PUSH: - return BT_MESH_PUSH; + return BLE_MESH_PUSH; case INPUT_OOB_TWIST: - return BT_MESH_TWIST; + return BLE_MESH_TWIST; case INPUT_OOB_NUMBER: - return BT_MESH_ENTER_NUMBER; + return BLE_MESH_ENTER_NUMBER; case INPUT_OOB_STRING: - return BT_MESH_ENTER_STRING; + return BLE_MESH_ENTER_STRING; default: - return BT_MESH_NO_INPUT; + return BLE_MESH_NO_INPUT; } } @@ -1673,7 +1672,7 @@ static int prov_auth(u8_t method, u8_t action, u8_t size) /* Provisioner ouputs number/string and wait for device's Provisioning Input Complete PDU */ link[i].expect = PROV_INPUT_COMPLETE; - if (input == BT_MESH_ENTER_STRING) { + if (input == BLE_MESH_ENTER_STRING) { unsigned char str[9]; u8_t j; @@ -1859,9 +1858,9 @@ int bt_mesh_prov_read_oob_pub_key(u8_t link_idx, u8_t pub_key_x[32], u8_t pub_ke sys_memcpy_swap(&link[link_idx].conf_inputs[81], pub_key_x, 32); sys_memcpy_swap(&link[link_idx].conf_inputs[81] + 32, pub_key_y, 32); - atomic_set_bit(link[link_idx].flags, REMOTE_PUB_KEY); + bt_mesh_atomic_set_bit(link[link_idx].flags, REMOTE_PUB_KEY); - if (atomic_test_and_clear_bit(link[link_idx].flags, WAIT_GEN_DHKEY)) { + if (bt_mesh_atomic_test_and_clear_bit(link[link_idx].flags, WAIT_GEN_DHKEY)) { prov_gen_dh_key(link_idx); } @@ -1888,7 +1887,7 @@ static void prov_dh_key_cb(const u8_t key[32]) BT_DBG("DHkey: %s", bt_hex(link[i].dhkey, 32)); - atomic_set_bit(link[i].flags, HAVE_DHKEY); + bt_mesh_atomic_set_bit(link[i].flags, HAVE_DHKEY); /** After dhkey is generated, if auth_method is No OOB or * Static OOB, provisioner can start to send confirmation. @@ -1949,7 +1948,7 @@ static void send_pub_key(u8_t oob) BT_DBG("Local Public Key: %s", bt_hex(key, 64)); - atomic_set_bit(link[i].flags, LOCAL_PUB_KEY); + bt_mesh_atomic_set_bit(link[i].flags, LOCAL_PUB_KEY); prov_buf_init(buf, PROV_PUB_KEY); @@ -1974,20 +1973,20 @@ static void send_pub_key(u8_t oob) * wait for transactiona ack for public key then send * provisioning confirm pdu. */ -#if defined(CONFIG_BT_MESH_PB_ADV) - if (i < CONFIG_BT_MESH_PBA_SAME_TIME) { +#if defined(CONFIG_BLE_MESH_PB_ADV) + if (i < CONFIG_BLE_MESH_PBA_SAME_TIME) { link[i].expect_ack_for = PROV_PUB_KEY; return; } -#endif /* CONFIG_BT_MESH_PB_ADV */ +#endif /* CONFIG_BLE_MESH_PB_ADV */ /* If remote public key has been read, then start to generate DHkey, * otherwise wait for device oob public key. */ - if (atomic_test_bit(link[i].flags, REMOTE_PUB_KEY)) { + if (bt_mesh_atomic_test_bit(link[i].flags, REMOTE_PUB_KEY)) { prov_gen_dh_key(i); } else { - atomic_set_bit(link[i].flags, WAIT_GEN_DHKEY); + bt_mesh_atomic_set_bit(link[i].flags, WAIT_GEN_DHKEY); } } } @@ -1999,18 +1998,18 @@ static void prov_pub_key(const u8_t *data) BT_DBG("Remote Public Key: %s", bt_hex(data, 64)); /* Make sure received pdu is ok and cancel the timeout timer */ - if (atomic_test_and_clear_bit(link[i].flags, TIMEOUT_START)) { + if (bt_mesh_atomic_test_and_clear_bit(link[i].flags, TIMEOUT_START)) { k_delayed_work_cancel(&link[i].timeout); } memcpy(&link[i].conf_inputs[81], data, 64); - if (!atomic_test_bit(link[i].flags, LOCAL_PUB_KEY)) { + if (!bt_mesh_atomic_test_bit(link[i].flags, LOCAL_PUB_KEY)) { /* Clear retransmit timer */ -#if defined(CONFIG_BT_MESH_PB_ADV) +#if defined(CONFIG_BLE_MESH_PB_ADV) prov_clear_tx(i); #endif - atomic_set_bit(link[i].flags, REMOTE_PUB_KEY); + bt_mesh_atomic_set_bit(link[i].flags, REMOTE_PUB_KEY); BT_WARN("%s, Waiting for local public key", __func__); return; } @@ -2023,7 +2022,7 @@ static void prov_input_complete(const u8_t *data) int i = prov_get_pb_index(); /* Make sure received pdu is ok and cancel the timeout timer */ - if (atomic_test_and_clear_bit(link[i].flags, TIMEOUT_START)) { + if (bt_mesh_atomic_test_and_clear_bit(link[i].flags, TIMEOUT_START)) { k_delayed_work_cancel(&link[i].timeout); } @@ -2043,7 +2042,7 @@ static void prov_confirm(const u8_t *data) BT_DBG("Remote Confirm: %s", bt_hex(data, 16)); /* Make sure received pdu is ok and cancel the timeout timer */ - if (atomic_test_and_clear_bit(link[i].flags, TIMEOUT_START)) { + if (bt_mesh_atomic_test_and_clear_bit(link[i].flags, TIMEOUT_START)) { k_delayed_work_cancel(&link[i].timeout); } @@ -2056,11 +2055,11 @@ static void prov_confirm(const u8_t *data) memcpy(link[i].conf, data, 16); - if (!atomic_test_bit(link[i].flags, HAVE_DHKEY)) { -#if defined(CONFIG_BT_MESH_PB_ADV) + if (!bt_mesh_atomic_test_bit(link[i].flags, HAVE_DHKEY)) { +#if defined(CONFIG_BLE_MESH_PB_ADV) prov_clear_tx(i); #endif - atomic_set_bit(link[i].flags, SEND_CONFIRM); + bt_mesh_atomic_set_bit(link[i].flags, SEND_CONFIRM); } prov_buf_init(buf, PROV_RANDOM); @@ -2142,7 +2141,7 @@ static void send_prov_data(void) */ /* Check if this device is a re-provisioned device */ - for (j = 0; j < BT_MESH_ALREADY_PROV_NUM; j++) { + for (j = 0; j < BLE_MESH_ALREADY_PROV_NUM; j++) { if (!memcmp(link[i].uuid, prov_ctx.already_prov[j].uuid, 16)) { if (link[i].element_num <= prov_ctx.already_prov[j].element_num) { already_flag = true; @@ -2198,7 +2197,7 @@ static void send_prov_data(void) * sent successfully, update the current_addr in prov_ctx struct. */ if (!already_flag) { - for (j = 0; j < BT_MESH_ALREADY_PROV_NUM; j++) { + for (j = 0; j < BLE_MESH_ALREADY_PROV_NUM; j++) { if (!prov_ctx.already_prov[j].element_num) { memcpy(prov_ctx.already_prov[j].uuid, link[i].uuid, 16); prov_ctx.already_prov[j].element_num = link[i].element_num; @@ -2256,7 +2255,7 @@ static void prov_random(const u8_t *data) } /*Verify received confirm is ok and cancel the timeout timer */ - if (atomic_test_and_clear_bit(link[i].flags, TIMEOUT_START)) { + if (bt_mesh_atomic_test_and_clear_bit(link[i].flags, TIMEOUT_START)) { k_delayed_work_cancel(&link[i].timeout); } @@ -2296,7 +2295,7 @@ static void prov_complete(const u8_t *data) int err, rm = 0; /* Make sure received pdu is ok and cancel the timeout timer */ - if (atomic_test_and_clear_bit(link[i].flags, TIMEOUT_START)) { + if (bt_mesh_atomic_test_and_clear_bit(link[i].flags, TIMEOUT_START)) { k_delayed_work_cancel(&link[i].timeout); } @@ -2325,7 +2324,7 @@ static void prov_complete(const u8_t *data) prov_nodes[j].flags = link[i].ki_flags; prov_nodes[j].iv_index = link[i].iv_index; prov_nodes[j].addr.type = link[i].addr.type; - memcpy(prov_nodes[j].addr.a.val, link[i].addr.a.val, BD_ADDR_LEN); + memcpy(prov_nodes[j].addr.val, link[i].addr.val, BLE_MESH_ADDR_LEN); memcpy(prov_nodes[j].uuid, link[i].uuid, 16); break; } @@ -2395,13 +2394,13 @@ static const struct { static void close_link(int i, u8_t reason) { - if (i < CONFIG_BT_MESH_PBA_SAME_TIME) { -#if defined(CONFIG_BT_MESH_PB_ADV) + if (i < CONFIG_BLE_MESH_PBA_SAME_TIME) { +#if defined(CONFIG_BLE_MESH_PB_ADV) bearer_ctl_send(i, LINK_CLOSE, &reason, sizeof(reason)); #endif - } else if (i >= CONFIG_BT_MESH_PBA_SAME_TIME && - i < BT_MESH_PROV_SAME_TIME) { -#if defined(CONFIG_BT_MESH_PB_GATT) + } else if (i >= CONFIG_BLE_MESH_PBA_SAME_TIME && + i < BLE_MESH_PROV_SAME_TIME) { +#if defined(CONFIG_BLE_MESH_PB_GATT) if (link[i].conn) { bt_mesh_gattc_disconnect(link[i].conn); } @@ -2420,14 +2419,14 @@ static void prov_timeout(struct k_work *work) close_link(i, CLOSE_REASON_TIMEOUT); } -#if defined(CONFIG_BT_MESH_PB_ADV) +#if defined(CONFIG_BLE_MESH_PB_ADV) static void prov_retransmit(struct k_work *work) { int id = work->index; BT_DBG("%s", __func__); - if (!atomic_test_bit(link[id].flags, LINK_ACTIVE)) { + if (!bt_mesh_atomic_test_bit(link[id].flags, LINK_ACTIVE)) { BT_WARN("%s, Link is not active", __func__); return; } @@ -2453,7 +2452,7 @@ static void prov_retransmit(struct k_work *work) break; } - if (BT_MESH_ADV(buf)->busy) { + if (BLE_MESH_ADV(buf)->busy) { continue; } @@ -2521,14 +2520,14 @@ static void gen_prov_ctl(struct prov_rx *rx, struct net_buf_simple *buf) break; case LINK_ACK: - if (!atomic_test_bit(link[i].flags, LINK_ACTIVE)) { + if (!bt_mesh_atomic_test_bit(link[i].flags, LINK_ACTIVE)) { return; } link_ack(rx, buf); break; case LINK_CLOSE: - if (!atomic_test_bit(link[i].flags, LINK_ACTIVE)) { + if (!bt_mesh_atomic_test_bit(link[i].flags, LINK_ACTIVE)) { return; } link_close(rx, buf); @@ -2749,7 +2748,7 @@ static void gen_prov_recv(struct prov_rx *rx, struct net_buf_simple *buf) * And if so, we shall not check LINK_ACTIVE status in the * function find_link(). */ - if (!atomic_test_bit(link[i].flags, LINK_ACTIVE) && + if (!bt_mesh_atomic_test_bit(link[i].flags, LINK_ACTIVE) && gen_prov[GPCF(rx->gpc)].require_link) { BT_DBG("Ignoring message that requires active link"); return; @@ -2762,9 +2761,9 @@ static int find_link(u32_t link_id, bool set) { int i; - /* link for PB-ADV is from 0 to CONFIG_BT_MESH_PBA_SAME_TIME */ - for (i = 0; i < CONFIG_BT_MESH_PBA_SAME_TIME; i++) { - if (atomic_test_bit(link[i].flags, LINK_ACTIVE)) { + /* link for PB-ADV is from 0 to CONFIG_BLE_MESH_PBA_SAME_TIME */ + for (i = 0; i < CONFIG_BLE_MESH_PBA_SAME_TIME; i++) { + if (bt_mesh_atomic_test_bit(link[i].flags, LINK_ACTIVE)) { if (link[i].link_id == link_id) { if (set) { prov_set_pb_index(i); @@ -2803,16 +2802,16 @@ void provisioner_pb_adv_recv(struct net_buf_simple *buf) gen_prov_recv(&rx, buf); } -#endif /* CONFIG_BT_MESH_PB_ADV */ +#endif /* CONFIG_BLE_MESH_PB_ADV */ -#if defined(CONFIG_BT_MESH_PB_GATT) -static struct bt_conn *find_conn(struct bt_conn *conn, bool set) +#if defined(CONFIG_BLE_MESH_PB_GATT) +static struct bt_mesh_conn *find_conn(struct bt_mesh_conn *conn, bool set) { int i; - /* link for PB-GATT is from CONFIG_BT_MESH_PBA_SAME_TIME to BT_MESH_PROV_SAME_TIME */ - for (i = CONFIG_BT_MESH_PBA_SAME_TIME; i < BT_MESH_PROV_SAME_TIME; i++) { - if (atomic_test_bit(link[i].flags, LINK_ACTIVE)) { + /* link for PB-GATT is from CONFIG_BLE_MESH_PBA_SAME_TIME to BLE_MESH_PROV_SAME_TIME */ + for (i = CONFIG_BLE_MESH_PBA_SAME_TIME; i < BLE_MESH_PROV_SAME_TIME; i++) { + if (bt_mesh_atomic_test_bit(link[i].flags, LINK_ACTIVE)) { if (link[i].conn == conn) { if (set) { prov_set_pb_index(i); @@ -2825,7 +2824,7 @@ static struct bt_conn *find_conn(struct bt_conn *conn, bool set) return NULL; } -int provisioner_pb_gatt_recv(struct bt_conn *conn, struct net_buf_simple *buf) +int provisioner_pb_gatt_recv(struct bt_mesh_conn *conn, struct net_buf_simple *buf) { u8_t type; int i; @@ -2870,25 +2869,25 @@ fail: return -EINVAL; } -int provisioner_set_prov_conn(const u8_t addr[6], struct bt_conn *conn) +int provisioner_set_prov_conn(const u8_t addr[6], struct bt_mesh_conn *conn) { if (!addr || !conn) { BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } - for (int i = CONFIG_BT_MESH_PBA_SAME_TIME; i < BT_MESH_PROV_SAME_TIME; i++) { - if (!memcmp(link[i].addr.a.val, addr, BD_ADDR_LEN)) { + for (int 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)) { link[i].conn = bt_mesh_conn_ref(conn); return 0; } } - BT_ERR("%s, Address %s is not found", __func__, bt_hex(addr, BD_ADDR_LEN)); + BT_ERR("%s, Address %s is not found", __func__, bt_hex(addr, BLE_MESH_ADDR_LEN)); return -ENOMEM; } -int provisioner_pb_gatt_open(struct bt_conn *conn, u8_t *addr) +int provisioner_pb_gatt_open(struct bt_mesh_conn *conn, u8_t *addr) { int i, id = 0; @@ -2901,22 +2900,22 @@ int provisioner_pb_gatt_open(struct bt_conn *conn, u8_t *addr) * procedures are completed, we just check if this conn already * exists in the proxy servers array. */ - for (i = CONFIG_BT_MESH_PBA_SAME_TIME; i < BT_MESH_PROV_SAME_TIME; i++) { + for (i = CONFIG_BLE_MESH_PBA_SAME_TIME; i < BLE_MESH_PROV_SAME_TIME; i++) { if (link[i].conn == conn) { id = i; break; } } - if (i == BT_MESH_PROV_SAME_TIME) { + if (i == BLE_MESH_PROV_SAME_TIME) { BT_ERR("%s, Link is not found", __func__); return -ENOTCONN; } prov_set_pb_index(id); - for (i = 0; i < CONFIG_BT_MESH_PBA_SAME_TIME; i++) { - if (atomic_test_bit(link[i].flags, LINK_ACTIVE)) { + for (i = 0; i < CONFIG_BLE_MESH_PBA_SAME_TIME; i++) { + if (bt_mesh_atomic_test_bit(link[i].flags, LINK_ACTIVE)) { if (!memcmp(link[i].uuid, link[id].uuid, 16)) { BT_WARN("%s, Provision using PB-GATT & PB-ADV same time", __func__); close_link(id, CLOSE_REASON_FAILED); @@ -2925,12 +2924,12 @@ int provisioner_pb_gatt_open(struct bt_conn *conn, u8_t *addr) } } - atomic_set_bit(link[id].flags, LINK_ACTIVE); + bt_mesh_atomic_set_bit(link[id].flags, LINK_ACTIVE); link[id].conn = bt_mesh_conn_ref(conn); /* May use lcd to indicate starting provisioning each device */ if (prov->prov_link_open) { - prov->prov_link_open(BT_MESH_PROV_GATT); + prov->prov_link_open(BLE_MESH_PROV_GATT); } link[id].conf_inputs = (u8_t *)osi_calloc(PROV_CONF_INPUTS_SIZE); @@ -2946,7 +2945,7 @@ int provisioner_pb_gatt_open(struct bt_conn *conn, u8_t *addr) return 0; } -int provisioner_pb_gatt_close(struct bt_conn *conn, u8_t reason) +int provisioner_pb_gatt_close(struct bt_mesh_conn *conn, u8_t reason) { int i; @@ -2959,12 +2958,12 @@ int provisioner_pb_gatt_close(struct bt_conn *conn, u8_t reason) i = prov_get_pb_index(); - if (atomic_test_and_clear_bit(link[i].flags, TIMEOUT_START)) { + if (bt_mesh_atomic_test_and_clear_bit(link[i].flags, TIMEOUT_START)) { k_delayed_work_cancel(&link[i].timeout); } if (prov->prov_link_close) { - prov->prov_link_close(BT_MESH_PROV_GATT, reason); + prov->prov_link_close(BLE_MESH_PROV_GATT, reason); } prov_memory_free(i); @@ -2972,12 +2971,12 @@ int provisioner_pb_gatt_close(struct bt_conn *conn, u8_t reason) memset(&link[i], 0, offsetof(struct prov_link, timeout)); if (bt_mesh_pub_key_get()) { - atomic_set_bit(link[i].flags, LOCAL_PUB_KEY); + bt_mesh_atomic_set_bit(link[i].flags, LOCAL_PUB_KEY); } return 0; } -#endif /* CONFIG_BT_MESH_PB_GATT */ +#endif /* CONFIG_BLE_MESH_PB_GATT */ int provisioner_prov_init(const struct bt_mesh_prov *prov_info) { @@ -2989,7 +2988,7 @@ int provisioner_prov_init(const struct bt_mesh_prov *prov_info) return -EINVAL; } - if (CONFIG_BT_MESH_PBG_SAME_TIME > CONFIG_BT_MAX_CONN) { + if (CONFIG_BLE_MESH_PBG_SAME_TIME > CONFIG_BT_MAX_CONN) { BT_ERR("%s, PB-GATT same time exceeds max connection", __func__); return -EINVAL; } @@ -3002,8 +3001,8 @@ int provisioner_prov_init(const struct bt_mesh_prov *prov_info) prov = prov_info; -#if defined(CONFIG_BT_MESH_PB_ADV) - for (i = 0; i < CONFIG_BT_MESH_PBA_SAME_TIME; i++) { +#if defined(CONFIG_BLE_MESH_PB_ADV) + for (i = 0; i < CONFIG_BLE_MESH_PBA_SAME_TIME; i++) { adv_buf[i].buf.size = ADV_BUF_SIZE; link[i].pending_ack = XACT_NVAL; k_delayed_work_init(&link[i].tx.retransmit, prov_retransmit); @@ -3013,7 +3012,7 @@ int provisioner_prov_init(const struct bt_mesh_prov *prov_info) } #endif - for (i = 0; i < BT_MESH_PROV_SAME_TIME; i++) { + for (i = 0; i < BLE_MESH_PROV_SAME_TIME; i++) { k_delayed_work_init(&link[i].timeout, prov_timeout); link[i].timeout.work.index = i; } @@ -3021,7 +3020,7 @@ int provisioner_prov_init(const struct bt_mesh_prov *prov_info) /* for PB-GATT, use servers[] array in proxy_provisioner.c */ prov_ctx.current_addr = prov->prov_start_address; - prov_ctx.curr_net_idx = BT_MESH_KEY_PRIMARY; + prov_ctx.curr_net_idx = BLE_MESH_KEY_PRIMARY; prov_ctx.curr_flags = prov->flags; prov_ctx.curr_iv_index = prov->iv_index; @@ -3029,29 +3028,29 @@ int provisioner_prov_init(const struct bt_mesh_prov *prov_info) } static int provisioner_notify_unprov_adv_pkt(bt_mesh_prov_bearer_t bearer, const u8_t uuid[16], - const bt_addr_le_t *addr, u16_t oob_info) + const bt_mesh_addr_t *addr, u16_t oob_info) { u8_t adv_type; int index; - if ((bearer != BT_MESH_PROV_ADV && bearer != BT_MESH_PROV_GATT) || !uuid || !addr) { + if ((bearer != BLE_MESH_PROV_ADV && bearer != BLE_MESH_PROV_GATT) || !uuid || !addr) { BT_ERR("%s, invalid parameter", __func__); return -EINVAL; } - adv_type = (bearer == BT_MESH_PROV_ADV) ? BT_LE_ADV_NONCONN_IND : BT_LE_ADV_IND; + adv_type = (bearer == BLE_MESH_PROV_ADV) ? BLE_MESH_ADV_NONCONN_IND : BLE_MESH_ADV_IND; if (prov_ctx.prov_after_match == false) { if (provisioner_dev_find(addr, uuid, &index)) { BT_DBG("%s, Device is not found, notify to upper layer", __func__); if (notify_unprov_adv_pkt_cb) { - notify_unprov_adv_pkt_cb(addr->a.val, addr->type, adv_type, uuid, oob_info, bearer); + notify_unprov_adv_pkt_cb(addr->val, addr->type, adv_type, uuid, oob_info, bearer); } return -EALREADY; } if (!(unprov_dev[index].bearer & bearer)) { - BT_DBG("%s, Not support PB-%s", __func__, (bearer == BT_MESH_PROV_ADV) ? "ADV" : "GATT"); + BT_DBG("%s, Not support PB-%s", __func__, (bearer == BLE_MESH_PROV_ADV) ? "ADV" : "GATT"); return -EIO; } } @@ -3061,8 +3060,8 @@ static int provisioner_notify_unprov_adv_pkt(bt_mesh_prov_bearer_t bearer, const void provisioner_unprov_beacon_recv(struct net_buf_simple *buf) { -#if defined(CONFIG_BT_MESH_PB_ADV) - const bt_addr_le_t *addr = NULL; +#if defined(CONFIG_BLE_MESH_PB_ADV) + const bt_mesh_addr_t *addr = NULL; u8_t *uuid = NULL; u16_t oob_info; @@ -3071,7 +3070,7 @@ void provisioner_unprov_beacon_recv(struct net_buf_simple *buf) return; } - if (prov_ctx.pba_count == CONFIG_BT_MESH_PBA_SAME_TIME) { + if (prov_ctx.pba_count == CONFIG_BLE_MESH_PBA_SAME_TIME) { BT_DBG("Current PB-ADV devices reach max limit"); return; } @@ -3087,12 +3086,12 @@ void provisioner_unprov_beacon_recv(struct net_buf_simple *buf) } if (provisioner_notify_unprov_adv_pkt( - BT_MESH_PROV_ADV, uuid, addr, oob_info)) { + BLE_MESH_PROV_ADV, uuid, addr, oob_info)) { return; } - provisioner_start_prov_device(BT_MESH_PROV_ADV, uuid, addr, oob_info); -#endif /* CONFIG_BT_MESH_PB_ADV */ + provisioner_start_prov_device(BLE_MESH_PROV_ADV, uuid, addr, oob_info); +#endif /* CONFIG_BLE_MESH_PB_ADV */ } bool provisioner_flags_match(struct net_buf_simple *buf) @@ -3126,16 +3125,16 @@ u16_t provisioner_srv_uuid_recv(struct net_buf_simple *buf) BT_DBG("Received adv pkt with service UUID: %d", uuid); - if ((uuid != BT_UUID_MESH_PROV_VAL) && (uuid != BT_UUID_MESH_PROXY_VAL)) { + if ((uuid != BLE_MESH_UUID_MESH_PROV_VAL) && (uuid != BLE_MESH_UUID_MESH_PROXY_VAL)) { return false; } return uuid; } -static void provisioner_prov_srv_data_recv(struct net_buf_simple *buf, const bt_addr_le_t *addr); +static void provisioner_prov_srv_data_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr); -void provisioner_srv_data_recv(struct net_buf_simple *buf, const bt_addr_le_t *addr, u16_t uuid) +void provisioner_srv_data_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr, u16_t uuid) { u16_t uuid_type; @@ -3151,17 +3150,17 @@ void provisioner_srv_data_recv(struct net_buf_simple *buf, const bt_addr_le_t *a } switch (uuid) { - case BT_UUID_MESH_PROV_VAL: - if (buf->len != BT_MESH_PROV_SRV_DATA_LEN) { + case BLE_MESH_UUID_MESH_PROV_VAL: + if (buf->len != BLE_MESH_PROV_SRV_DATA_LEN) { BT_WARN("%s, Invalid Mesh Prov Service Data length %d", __func__, buf->len); return; } BT_DBG("Start to deal with Mesh Prov Service Data"); provisioner_prov_srv_data_recv(buf, addr); break; - case BT_UUID_MESH_PROXY_VAL: - if (buf->len != BT_MESH_PROXY_SRV_DATA_LEN1 && - buf->len != BT_MESH_PROXY_SRV_DATA_LEN2) { + 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_ERR("%s, Invalid Mesh Proxy Service Data length %d", __func__, buf->len); return; } @@ -3173,13 +3172,13 @@ void provisioner_srv_data_recv(struct net_buf_simple *buf, const bt_addr_le_t *a } } -static void provisioner_prov_srv_data_recv(struct net_buf_simple *buf, const bt_addr_le_t *addr) +static void provisioner_prov_srv_data_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr) { -#if defined(CONFIG_BT_MESH_PB_GATT) +#if defined(CONFIG_BLE_MESH_PB_GATT) u8_t *uuid = NULL; u16_t oob_info; - if (prov_ctx.pbg_count == CONFIG_BT_MESH_PBG_SAME_TIME) { + if (prov_ctx.pbg_count == CONFIG_BLE_MESH_PBG_SAME_TIME) { BT_DBG("Current PB-GATT devices reach max limit"); return; } @@ -3194,7 +3193,7 @@ static void provisioner_prov_srv_data_recv(struct net_buf_simple *buf, const bt_ } if (provisioner_notify_unprov_adv_pkt( - BT_MESH_PROV_GATT, uuid, addr, oob_info)) { + BLE_MESH_PROV_GATT, uuid, addr, oob_info)) { return; } @@ -3210,10 +3209,8 @@ static void provisioner_prov_srv_data_recv(struct net_buf_simple *buf, const bt_ * Use connecting flag to prevent if two devices's adv pkts are both received, * the previous one info will be replaced by the second one. */ - provisioner_start_prov_device(BT_MESH_PROV_GATT, uuid, addr, oob_info); -#endif /* CONFIG_BT_MESH_PB_GATT */ + provisioner_start_prov_device(BLE_MESH_PROV_GATT, uuid, addr, oob_info); +#endif /* CONFIG_BLE_MESH_PB_GATT */ } -#endif /* CONFIG_BT_MESH_PROVISIONER */ - -#endif /* CONFIG_BT_MESH */ \ No newline at end of file +#endif /* CONFIG_BLE_MESH_PROVISIONER */ diff --git a/components/bt/ble_mesh/mesh_core/provisioner_prov.h b/components/bt/ble_mesh/mesh_core/provisioner_prov.h index d0867b059d..cf6d7867c6 100644 --- a/components/bt/ble_mesh/mesh_core/provisioner_prov.h +++ b/components/bt/ble_mesh/mesh_core/provisioner_prov.h @@ -18,24 +18,20 @@ #include "mesh_bearer_adapt.h" #include "mesh_main.h" -#if !CONFIG_BT_MESH_PROVISIONER +#if !CONFIG_BLE_MESH_PROVISIONER -#define CONFIG_BT_MESH_PBA_SAME_TIME 0 -#define CONFIG_BT_MESH_PBG_SAME_TIME 0 +#define CONFIG_BLE_MESH_PBA_SAME_TIME 0 +#define CONFIG_BLE_MESH_PBG_SAME_TIME 0 #else -#if !defined(CONFIG_BT_MESH_PB_ADV) -#define CONFIG_BT_MESH_PBA_SAME_TIME 0 -#endif /* !CONFIG_BT_MESH_PB_ADV */ +#if !defined(CONFIG_BLE_MESH_PB_ADV) +#define CONFIG_BLE_MESH_PBA_SAME_TIME 0 +#endif /* !CONFIG_BLE_MESH_PB_ADV */ -#if !defined(CONFIG_BT_MESH_PB_GATT) -#define CONFIG_BT_MESH_PBG_SAME_TIME 0 -#endif /* !CONFIG_BT_MESH_PB_GATT */ - -#define BT_DATA_FLAGS 0x01 -#define BT_DATA_SERVICE_UUID 0x03 -#define BT_DATA_SERVICE_DATA 0X16 +#if !defined(CONFIG_BLE_MESH_PB_GATT) +#define CONFIG_BLE_MESH_PBG_SAME_TIME 0 +#endif /* !CONFIG_BLE_MESH_PB_GATT */ #define RM_AFTER_PROV BIT(0) #define START_PROV_NOW BIT(1) @@ -111,7 +107,7 @@ void provisioner_pb_adv_recv(struct net_buf_simple *buf); * * @return Zero - success, otherwise - fail */ -int provisioner_set_prov_conn(const u8_t addr[6], struct bt_conn *conn); +int provisioner_set_prov_conn(const u8_t addr[6], struct bt_mesh_conn *conn); /** * @brief This function sends provisioning invite to start @@ -122,7 +118,7 @@ int provisioner_set_prov_conn(const u8_t addr[6], struct bt_conn *conn); * * @return Zero - success, otherwise - fail */ -int provisioner_pb_gatt_open(struct bt_conn *conn, u8_t *addr); +int provisioner_pb_gatt_open(struct bt_mesh_conn *conn, u8_t *addr); /** * @brief This function resets the used information when @@ -133,7 +129,7 @@ int provisioner_pb_gatt_open(struct bt_conn *conn, u8_t *addr); * * @return Zero - success, otherwise - fail */ -int provisioner_pb_gatt_close(struct bt_conn *conn, u8_t reason); +int provisioner_pb_gatt_close(struct bt_mesh_conn *conn, u8_t reason); /** * @brief This function handles the received PB-GATT provision @@ -144,7 +140,7 @@ int provisioner_pb_gatt_close(struct bt_conn *conn, u8_t reason); * * @return Zero - success, otherwise - fail */ -int provisioner_pb_gatt_recv(struct bt_conn *conn, struct net_buf_simple *buf); +int provisioner_pb_gatt_recv(struct bt_mesh_conn *conn, struct net_buf_simple *buf); /** * @brief This function initializes provisioner's PB-GATT and PB-ADV @@ -197,7 +193,7 @@ u16_t provisioner_srv_uuid_recv(struct net_buf_simple *buf); * * @return None */ -void provisioner_srv_data_recv(struct net_buf_simple *buf, const bt_addr_le_t *addr, u16_t uuid); +void provisioner_srv_data_recv(struct net_buf_simple *buf, const bt_mesh_addr_t *addr, u16_t uuid); /** * @brief This function gets the bt_mesh_prov pointer. @@ -376,6 +372,6 @@ u8_t bt_mesh_set_fast_prov_unicast_addr_range(u16_t min, u16_t max); */ void bt_mesh_set_fast_prov_flags_iv_index(u8_t flags, u32_t iv_index); -#endif /* CONFIG_BT_MESH_PROVISIONER */ +#endif /* CONFIG_BLE_MESH_PROVISIONER */ -#endif /* #ifndef _PROVISIONER_PROV_H_ */ +#endif /* _PROVISIONER_PROV_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/provisioner_proxy.c b/components/bt/ble_mesh/mesh_core/provisioner_proxy.c index d1b553cc87..2a190c314e 100644 --- a/components/bt/ble_mesh/mesh_core/provisioner_proxy.c +++ b/components/bt/ble_mesh/mesh_core/provisioner_proxy.c @@ -17,7 +17,6 @@ #include "sdkconfig.h" -#if CONFIG_BT_MESH #include "mesh_bearer_adapt.h" #include "mesh_trace.h" @@ -28,41 +27,41 @@ #include "provisioner_proxy.h" #include "provisioner_beacon.h" -#if CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_PROVISIONER -#define PDU_TYPE(data) (data[0] & BIT_MASK(6)) -#define PDU_SAR(data) (data[0] >> 6) +#define PDU_TYPE(data) (data[0] & BIT_MASK(6)) +#define PDU_SAR(data) (data[0] >> 6) -#define SAR_COMPLETE 0x00 -#define SAR_FIRST 0x01 -#define SAR_CONT 0x02 -#define SAR_LAST 0x03 +#define SAR_COMPLETE 0x00 +#define SAR_FIRST 0x01 +#define SAR_CONT 0x02 +#define SAR_LAST 0x03 -#define CFG_FILTER_SET 0x00 -#define CFG_FILTER_ADD 0x01 -#define CFG_FILTER_REMOVE 0x02 -#define CFG_FILTER_STATUS 0x03 +#define CFG_FILTER_SET 0x00 +#define CFG_FILTER_ADD 0x01 +#define CFG_FILTER_REMOVE 0x02 +#define CFG_FILTER_STATUS 0x03 -#define PDU_HDR(sar, type) (sar << 6 | (type & BIT_MASK(6))) +#define PDU_HDR(sar, type) (sar << 6 | (type & BIT_MASK(6))) -#define SERVER_BUF_SIZE 68 +#define SERVER_BUF_SIZE 68 -#define ID_TYPE_NET 0x00 -#define ID_TYPE_NODE 0x01 +#define ID_TYPE_NET 0x00 +#define ID_TYPE_NODE 0x01 -#define NODE_ID_LEN 19 -#define NET_ID_LEN 11 +#define NODE_ID_LEN 19 +#define NET_ID_LEN 11 -#define CLOSE_REASON_PROXY 0xFF +#define CLOSE_REASON_PROXY 0xFF -#define CONFIG_BT_MAX_CONN CONFIG_BT_ACL_CONNECTIONS +#define CONFIG_BT_MAX_CONN CONFIG_BT_ACL_CONNECTIONS static int conn_count; static struct bt_mesh_proxy_server { - struct bt_conn *conn; + struct bt_mesh_conn *conn; /* Provisioner can use filter to double check the dst within mesh messages */ - u16_t filter[CONFIG_BT_MESH_PROXY_FILTER_SIZE]; + u16_t filter[CONFIG_BLE_MESH_PROXY_FILTER_SIZE]; enum __packed { NONE, WHITELIST, @@ -74,7 +73,7 @@ static struct bt_mesh_proxy_server { u8_t server_buf_data[SERVER_BUF_SIZE]; } servers[CONFIG_BT_MAX_CONN]; -static struct bt_mesh_proxy_server *find_server(struct bt_conn *conn) +static struct bt_mesh_proxy_server *find_server(struct bt_mesh_conn *conn) { int i; @@ -127,15 +126,15 @@ static void proxy_cfg(struct bt_mesh_proxy_server *server) /** In order to deal with proxy configuration messages, provisioner should * do sth. like create mesh network after each device is provisioned. */ - err = bt_mesh_net_decode(&server->buf, BT_MESH_NET_IF_PROXY_CFG, + err = bt_mesh_net_decode(&server->buf, BLE_MESH_NET_IF_PROXY_CFG, &rx, buf); if (err) { - BT_ERR("Failed to decode Proxy Configuration (err %d)", err); + BT_ERR("%s, Failed to decode Proxy Configuration (err %d)", __func__, err); return; } /* Remove network headers */ - net_buf_simple_pull(buf, BT_MESH_NET_HDR_LEN); + net_buf_simple_pull(buf, BLE_MESH_NET_HDR_LEN); BT_DBG("%u bytes: %s", buf->len, bt_hex(buf->data, buf->len)); @@ -158,22 +157,22 @@ static void proxy_cfg(struct bt_mesh_proxy_server *server) static void proxy_complete_pdu(struct bt_mesh_proxy_server *server) { switch (server->msg_type) { -#if defined(CONFIG_BT_MESH_GATT_PROXY) - case BT_MESH_PROXY_NET_PDU: +#if defined(CONFIG_BLE_MESH_GATT_PROXY) + case BLE_MESH_PROXY_NET_PDU: BT_DBG("Mesh Network PDU"); - bt_mesh_net_recv(&server->buf, 0, BT_MESH_NET_IF_PROXY); + bt_mesh_net_recv(&server->buf, 0, BLE_MESH_NET_IF_PROXY); break; - case BT_MESH_PROXY_BEACON: + case BLE_MESH_PROXY_BEACON: BT_DBG("Mesh Beacon PDU"); provisioner_beacon_recv(&server->buf); break; - case BT_MESH_PROXY_CONFIG: + case BLE_MESH_PROXY_CONFIG: BT_DBG("Mesh Configuration PDU"); proxy_cfg(server); break; #endif -#if defined(CONFIG_BT_MESH_PB_GATT) - case BT_MESH_PROXY_PROV: +#if defined(CONFIG_BLE_MESH_PB_GATT) + case BLE_MESH_PROXY_PROV: BT_DBG("Mesh Provisioning PDU"); provisioner_pb_gatt_recv(server->conn, &server->buf); break; @@ -186,10 +185,10 @@ static void proxy_complete_pdu(struct bt_mesh_proxy_server *server) net_buf_simple_init(&server->buf, 0); } -#define ATTR_IS_PROV(uuid) (uuid == BT_UUID_MESH_PROV_VAL) +#define ATTR_IS_PROV(uuid) (uuid == BLE_MESH_UUID_MESH_PROV_VAL) -static ssize_t proxy_recv(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, +static ssize_t proxy_recv(struct bt_mesh_conn *conn, + const struct bt_mesh_gatt_attr *attr, const void *buf, u16_t len, u16_t offset, u8_t flags) { struct bt_mesh_proxy_server *server = find_server(conn); @@ -207,11 +206,11 @@ static ssize_t proxy_recv(struct bt_conn *conn, srvc_uuid = bt_mesh_gattc_get_service_uuid(conn); if (!srvc_uuid) { - BT_ERR("No service uuid found"); + BT_ERR("%s, No service uuid found", __func__); return -ENOTCONN; } - if (ATTR_IS_PROV(srvc_uuid) != (PDU_TYPE(data) == BT_MESH_PROXY_PROV)) { + if (ATTR_IS_PROV(srvc_uuid) != (PDU_TYPE(data) == BLE_MESH_PROXY_PROV)) { BT_WARN("Proxy PDU type doesn't match GATT service uuid"); return -EINVAL; } @@ -276,7 +275,7 @@ static ssize_t proxy_recv(struct bt_conn *conn, return len; } -static void proxy_prov_connected(const u8_t addr[6], struct bt_conn *conn, int id) +static void proxy_prov_connected(const u8_t addr[6], struct bt_mesh_conn *conn, int id) { struct bt_mesh_proxy_server *server = NULL; @@ -287,7 +286,7 @@ static void proxy_prov_connected(const u8_t addr[6], struct bt_conn *conn, int i } if (!server) { - BT_ERR("No matching Proxy Client objects"); + BT_ERR("%s, No matching Proxy Client objects", __func__); /** Disconnect current connection, clear part of prov_link * information, like uuid, dev_addr, linking flag, etc. */ @@ -300,9 +299,9 @@ static void proxy_prov_connected(const u8_t addr[6], struct bt_conn *conn, int i memset(server->filter, 0, sizeof(server->filter)); net_buf_simple_init(&server->buf, 0); -#if defined(CONFIG_BT_MESH_PB_GATT) +#if defined(CONFIG_BLE_MESH_PB_GATT) if (provisioner_set_prov_conn(addr, server->conn)) { - BT_ERR("%s: Fail to set prov_conn", __func__); + BT_ERR("%s, provisioner_set_prov_conn failed", __func__); bt_mesh_gattc_disconnect(server->conn); return; } @@ -311,7 +310,7 @@ static void proxy_prov_connected(const u8_t addr[6], struct bt_conn *conn, int i bt_mesh_gattc_exchange_mtu(id); } -static void proxy_prov_disconnected(struct bt_conn *conn, u8_t reason) +static void proxy_prov_disconnected(struct bt_mesh_conn *conn, u8_t reason) { struct bt_mesh_proxy_server *server = NULL; int i; @@ -325,7 +324,7 @@ static void proxy_prov_disconnected(struct bt_conn *conn, u8_t reason) for (i = 0; i < ARRAY_SIZE(servers); i++) { server = &servers[i]; if (server->conn == conn) { - if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) && + if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) && server->filter_type == PROV) { provisioner_pb_gatt_close(conn, reason); } @@ -335,15 +334,15 @@ static void proxy_prov_disconnected(struct bt_conn *conn, u8_t reason) } } -#if defined(CONFIG_BT_MESH_PB_GATT) -static ssize_t prov_write_ccc_descr(struct bt_conn *conn, u8_t *addr) +#if defined(CONFIG_BLE_MESH_PB_GATT) +static ssize_t prov_write_ccc_descr(struct bt_mesh_conn *conn, u8_t *addr) { struct bt_mesh_proxy_server *server; server = find_server(conn); if (!server) { - BT_ERR("No Proxy Server found"); + BT_ERR("%s, No Proxy Server found", __func__); return -ENOTCONN; } @@ -355,14 +354,14 @@ static ssize_t prov_write_ccc_descr(struct bt_conn *conn, u8_t *addr) return -EINVAL; } -static ssize_t prov_notification(struct bt_conn *conn, u8_t *data, u16_t len) +static ssize_t prov_notification(struct bt_mesh_conn *conn, u8_t *data, u16_t len) { struct bt_mesh_proxy_server *server; server = find_server(conn); if (!server) { - BT_ERR("No Proxy Server found"); + BT_ERR("%s, No Proxy Server found", __func__); return -ENOTCONN; } @@ -406,17 +405,17 @@ int provisioner_pb_gatt_disable(void) return 0; } -#endif /* CONFIG_BT_MESH_PB_GATT */ +#endif /* CONFIG_BLE_MESH_PB_GATT */ -#if defined(CONFIG_BT_MESH_GATT_PROXY) -static ssize_t proxy_write_ccc_descr(struct bt_conn *conn) +#if defined(CONFIG_BLE_MESH_GATT_PROXY) +static ssize_t proxy_write_ccc_descr(struct bt_mesh_conn *conn) { struct bt_mesh_proxy_server *server; server = find_server(conn); if (!server) { - BT_ERR("No Proxy Server found"); + BT_ERR("%s, No Proxy Server found", __func__); return -ENOTCONN; } @@ -428,7 +427,7 @@ static ssize_t proxy_write_ccc_descr(struct bt_conn *conn) return -EINVAL; } -static ssize_t proxy_notification(struct bt_conn *conn, u8_t *data, u16_t len) +static ssize_t proxy_notification(struct bt_mesh_conn *conn, u8_t *data, u16_t len) { return proxy_recv(conn, NULL, data, len, 0, 0); } @@ -491,30 +490,35 @@ int bt_mesh_provisioner_proxy_disable(void) return 0; } -#endif /* CONFIG_BT_MESH_GATT_PROXY */ +#endif /* CONFIG_BLE_MESH_GATT_PROXY */ -static int proxy_send(struct bt_conn *conn, const void *data, u16_t len) +static int proxy_send(struct bt_mesh_conn *conn, const void *data, u16_t len) { BT_DBG("%u bytes: %s", len, bt_hex(data, len)); -#if defined(CONFIG_BT_MESH_GATT_PROXY) || defined(CONFIG_BT_MESH_PB_GATT) +#if defined(CONFIG_BLE_MESH_GATT_PROXY) || defined(CONFIG_BLE_MESH_PB_GATT) return bt_mesh_gattc_write_no_rsp(conn, NULL, data, len); #endif return 0; } -static int proxy_prov_segment_and_send(struct bt_conn *conn, u8_t type, +static int proxy_prov_segment_and_send(struct bt_mesh_conn *conn, u8_t type, struct net_buf_simple *msg) { u16_t mtu; + if (conn == NULL) { + BT_ERR("%s, Invalid parameter", __func__); + return -EINVAL; + } + BT_DBG("conn %p type 0x%02x len %u: %s", conn, type, msg->len, bt_hex(msg->data, msg->len)); mtu = bt_mesh_gattc_get_mtu_info(conn); if (!mtu) { - BT_ERR("Conn used to get mtu does not exist"); + BT_ERR("%s, Conn used to get mtu does not exist", __func__); return -ENOTCONN; } @@ -544,35 +548,35 @@ static int proxy_prov_segment_and_send(struct bt_conn *conn, u8_t type, return 0; } -int provisioner_proxy_send(struct bt_conn *conn, u8_t type, +int provisioner_proxy_send(struct bt_mesh_conn *conn, u8_t type, struct net_buf_simple *msg) { struct bt_mesh_proxy_server *server = find_server(conn); if (!server) { - BT_ERR("No Proxy Server found"); + BT_ERR("$%s, No Proxy Server found", __func__); return -ENOTCONN; } - if ((server->filter_type == PROV) != (type == BT_MESH_PROXY_PROV)) { - BT_ERR("Invalid PDU type for Proxy Client"); + if ((server->filter_type == PROV) != (type == BLE_MESH_PROXY_PROV)) { + BT_ERR("%s, Invalid PDU type for Proxy Client", __func__); return -EINVAL; } return proxy_prov_segment_and_send(conn, type, msg); } -static struct bt_prov_conn_cb conn_callbacks = { - .connected = proxy_prov_connected, - .disconnected = proxy_prov_disconnected, -#if defined(CONFIG_BT_MESH_PB_GATT) - .prov_write_descr = prov_write_ccc_descr, - .prov_notify = prov_notification, -#endif /* CONFIG_BT_MESH_PB_GATT */ -#if defined(CONFIG_BT_MESH_GATT_PROXY) +static struct bt_mesh_prov_conn_cb conn_callbacks = { + .connected = proxy_prov_connected, + .disconnected = proxy_prov_disconnected, +#if defined(CONFIG_BLE_MESH_PB_GATT) + .prov_write_descr = prov_write_ccc_descr, + .prov_notify = prov_notification, +#endif /* CONFIG_BLE_MESH_PB_GATT */ +#if defined(CONFIG_BLE_MESH_GATT_PROXY) .proxy_write_descr = proxy_write_ccc_descr, - .proxy_notify = proxy_notification, -#endif /* CONFIG_BT_MESH_GATT_PROXY */ + .proxy_notify = proxy_notification, +#endif /* CONFIG_BLE_MESH_GATT_PROXY */ }; void provisioner_proxy_srv_data_recv(struct net_buf_simple *buf) @@ -581,7 +585,7 @@ void provisioner_proxy_srv_data_recv(struct net_buf_simple *buf) * don't support this function, and if realized later, proxy * client need to check if there is server structure left * before create connection with a server. - * check conn_count & CONFIG_BT_MESH_PBG_SAME_TIME + * check conn_count & CONFIG_BLE_MESH_PBG_SAME_TIME */ } @@ -592,7 +596,7 @@ int provisioner_proxy_init(void) /* Initialize the server receive buffers */ for (i = 0; i < ARRAY_SIZE(servers); i++) { struct bt_mesh_proxy_server *server = &servers[i]; - server->conn = NULL; + server->conn = NULL; server->buf.size = SERVER_BUF_SIZE; } @@ -601,6 +605,4 @@ int provisioner_proxy_init(void) return 0; } -#endif /* CONFIG_BT_MESH_PROVISIONER */ - -#endif /* CONFIG_BT_MESH */ \ No newline at end of file +#endif /* CONFIG_BLE_MESH_PROVISIONER */ diff --git a/components/bt/ble_mesh/mesh_core/provisioner_proxy.h b/components/bt/ble_mesh/mesh_core/provisioner_proxy.h index 474382918a..5da92f433b 100644 --- a/components/bt/ble_mesh/mesh_core/provisioner_proxy.h +++ b/components/bt/ble_mesh/mesh_core/provisioner_proxy.h @@ -17,10 +17,10 @@ #include "mesh_buf.h" -#define BT_MESH_PROXY_NET_PDU 0x00 -#define BT_MESH_PROXY_BEACON 0x01 -#define BT_MESH_PROXY_CONFIG 0x02 -#define BT_MESH_PROXY_PROV 0x03 +#define BLE_MESH_PROXY_NET_PDU 0x00 +#define BLE_MESH_PROXY_BEACON 0x01 +#define BLE_MESH_PROXY_CONFIG 0x02 +#define BLE_MESH_PROXY_PROV 0x03 /** * @brief This function is called to send proxy protocol messages. @@ -31,7 +31,7 @@ * * @return Zero-success, other-fail */ -int provisioner_proxy_send(struct bt_conn *conn, u8_t type, struct net_buf_simple *msg); +int provisioner_proxy_send(struct bt_mesh_conn *conn, u8_t type, struct net_buf_simple *msg); /** * @brief This function is called to parse received node identity and net diff --git a/components/bt/ble_mesh/mesh_core/proxy.c b/components/bt/ble_mesh/mesh_core/proxy.c index ded6941f5d..4c632468ff 100644 --- a/components/bt/ble_mesh/mesh_core/proxy.c +++ b/components/bt/ble_mesh/mesh_core/proxy.c @@ -9,14 +9,12 @@ #include #include +#include "sdkconfig.h" +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_PROXY) + #include "mesh_buf.h" #include "mesh_util.h" -#include "sdkconfig.h" -#if CONFIG_BT_MESH - #include "mesh_bearer_adapt.h" - -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_PROXY) #include "mesh_trace.h" #include "mesh.h" @@ -28,7 +26,7 @@ #include "access.h" #include "proxy.h" -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE #define PDU_TYPE(data) (data[0] & BIT_MASK(6)) #define PDU_SAR(data) (data[0] >> 6) @@ -49,26 +47,26 @@ #define CLIENT_BUF_SIZE 68 -static const struct bt_le_adv_param slow_adv_param = { - .options = (BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_ONE_TIME), - .interval_min = BT_GAP_ADV_SLOW_INT_MIN, - .interval_max = BT_GAP_ADV_SLOW_INT_MAX, +static const struct bt_mesh_adv_param slow_adv_param = { + .options = (BLE_MESH_ADV_OPT_CONNECTABLE | BLE_MESH_ADV_OPT_ONE_TIME), + .interval_min = BLE_MESH_GAP_ADV_SLOW_INT_MIN, + .interval_max = BLE_MESH_GAP_ADV_SLOW_INT_MAX, }; -static const struct bt_le_adv_param fast_adv_param = { - .options = (BT_LE_ADV_OPT_CONNECTABLE | BT_LE_ADV_OPT_ONE_TIME), - .interval_min = BT_GAP_ADV_FAST_INT_MIN_0, - .interval_max = BT_GAP_ADV_FAST_INT_MAX_0, +static const struct bt_mesh_adv_param fast_adv_param = { + .options = (BLE_MESH_ADV_OPT_CONNECTABLE | BLE_MESH_ADV_OPT_ONE_TIME), + .interval_min = BLE_MESH_GAP_ADV_FAST_INT_MIN_0, + .interval_max = BLE_MESH_GAP_ADV_FAST_INT_MAX_0, }; static bool proxy_adv_enabled; -#if defined(CONFIG_BT_MESH_GATT_PROXY) +#if defined(CONFIG_BLE_MESH_GATT_PROXY) static void proxy_send_beacons(struct k_work *work); static u16_t proxy_ccc_val; #endif -#if defined(CONFIG_BT_MESH_PB_GATT) +#if defined(CONFIG_BLE_MESH_PB_GATT) static u16_t prov_ccc_val; static bool prov_fast_adv; #endif @@ -82,10 +80,10 @@ enum { static struct bt_mesh_proxy_client { /* Proxy Server: 20s timeout for each segmented proxy pdu */ - ATOMIC_DEFINE(flags, NUM_FLAGS); + BLE_MESH_ATOMIC_DEFINE(flags, NUM_FLAGS); struct k_delayed_work sar_timer; - struct bt_conn *conn; - u16_t filter[CONFIG_BT_MESH_PROXY_FILTER_SIZE]; + struct bt_mesh_conn *conn; + u16_t filter[CONFIG_BLE_MESH_PROXY_FILTER_SIZE]; enum __packed { NONE, WHITELIST, @@ -93,14 +91,14 @@ static struct bt_mesh_proxy_client { PROV, } filter_type; u8_t msg_type; -#if defined(CONFIG_BT_MESH_GATT_PROXY) +#if defined(CONFIG_BLE_MESH_GATT_PROXY) struct k_work send_beacons; #endif struct net_buf_simple buf; u8_t buf_data[CLIENT_BUF_SIZE]; } clients[CONFIG_BT_MAX_CONN] = { [0 ... (CONFIG_BT_MAX_CONN - 1)] = { -#if defined(CONFIG_BT_MESH_GATT_PROXY) +#if defined(CONFIG_BLE_MESH_GATT_PROXY) .send_beacons = _K_WORK_INITIALIZER(proxy_send_beacons), #endif .buf.size = CLIENT_BUF_SIZE, @@ -119,12 +117,12 @@ static char device_name[DEVICE_NAME_SIZE] = "ESP-BLE-MESH"; int bt_mesh_set_device_name(const char *name) { if (!name) { - BT_ERR("%s: name is NULL", __func__); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } if (strlen(name) > DEVICE_NAME_SIZE) { - BT_ERR("%s: too long name", __func__); + BT_ERR("%s, Too long device name", __func__); return -EINVAL; } @@ -134,7 +132,7 @@ int bt_mesh_set_device_name(const char *name) return 0; } -static struct bt_mesh_proxy_client *find_client(struct bt_conn *conn) +static struct bt_mesh_proxy_client *find_client(struct bt_mesh_conn *conn) { int i; @@ -147,11 +145,11 @@ static struct bt_mesh_proxy_client *find_client(struct bt_conn *conn) return NULL; } -#if defined(CONFIG_BT_MESH_GATT_PROXY) +#if defined(CONFIG_BLE_MESH_GATT_PROXY) /* Next subnet in queue to be advertised */ static int next_idx; -static int proxy_segment_and_send(struct bt_conn *conn, u8_t type, +static int proxy_segment_and_send(struct bt_mesh_conn *conn, u8_t type, struct net_buf_simple *msg); static int filter_set(struct bt_mesh_proxy_client *client, @@ -190,7 +188,7 @@ static void filter_add(struct bt_mesh_proxy_client *client, u16_t addr) BT_DBG("addr 0x%04x", addr); - if (addr == BT_MESH_ADDR_UNASSIGNED) { + if (addr == BLE_MESH_ADDR_UNASSIGNED) { return; } @@ -201,7 +199,7 @@ 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] == BT_MESH_ADDR_UNASSIGNED) { + if (client->filter[i] == BLE_MESH_ADDR_UNASSIGNED) { client->filter[i] = addr; return; } @@ -214,13 +212,13 @@ static void filter_remove(struct bt_mesh_proxy_client *client, u16_t addr) BT_DBG("addr 0x%04x", addr); - if (addr == BT_MESH_ADDR_UNASSIGNED) { + if (addr == BLE_MESH_ADDR_UNASSIGNED) { return; } for (i = 0; i < ARRAY_SIZE(client->filter); i++) { if (client->filter[i] == addr) { - client->filter[i] = BT_MESH_ADDR_UNASSIGNED; + client->filter[i] = BLE_MESH_ADDR_UNASSIGNED; return; } } @@ -239,7 +237,7 @@ static void send_filter_status(struct bt_mesh_proxy_client *client, int i, err; /* Configuration messages always have dst unassigned */ - tx.ctx->addr = BT_MESH_ADDR_UNASSIGNED; + tx.ctx->addr = BLE_MESH_ADDR_UNASSIGNED; net_buf_simple_init(buf, 10); @@ -252,7 +250,7 @@ static void send_filter_status(struct bt_mesh_proxy_client *client, } for (filter_size = 0, i = 0; i < ARRAY_SIZE(client->filter); i++) { - if (client->filter[i] != BT_MESH_ADDR_UNASSIGNED) { + if (client->filter[i] != BLE_MESH_ADDR_UNASSIGNED) { filter_size++; } } @@ -263,13 +261,13 @@ static void send_filter_status(struct bt_mesh_proxy_client *client, err = bt_mesh_net_encode(&tx, buf, true); if (err) { - BT_ERR("Encoding Proxy cfg message failed (err %d)", err); + BT_ERR("%s, Failed to encode Proxy Configuration (err %d)", __func__, err); return; } - err = proxy_segment_and_send(client->conn, BT_MESH_PROXY_CONFIG, buf); + err = proxy_segment_and_send(client->conn, BLE_MESH_PROXY_CONFIG, buf); if (err) { - BT_ERR("Failed to send proxy cfg message (err %d)", err); + BT_ERR("%s, Failed to send Proxy Configuration (err %d)", __func__, err); } } @@ -280,15 +278,15 @@ static void proxy_cfg(struct bt_mesh_proxy_client *client) u8_t opcode; int err; - err = bt_mesh_net_decode(&client->buf, BT_MESH_NET_IF_PROXY_CFG, + err = bt_mesh_net_decode(&client->buf, BLE_MESH_NET_IF_PROXY_CFG, &rx, buf); if (err) { - BT_ERR("Failed to decode Proxy Configuration (err %d)", err); + BT_ERR("%s, Failed to decode Proxy Configuration (err %d)", __func__, err); return; } /* Remove network headers */ - net_buf_simple_pull(buf, BT_MESH_NET_HDR_LEN); + net_buf_simple_pull(buf, BLE_MESH_NET_HDR_LEN); BT_DBG("%u bytes: %s", buf->len, bt_hex(buf->data, buf->len)); @@ -327,14 +325,14 @@ static void proxy_cfg(struct bt_mesh_proxy_client *client) } } -static int beacon_send(struct bt_conn *conn, struct bt_mesh_subnet *sub) +static int beacon_send(struct bt_mesh_conn *conn, struct bt_mesh_subnet *sub) { struct net_buf_simple *buf = NET_BUF_SIMPLE(23); net_buf_simple_init(buf, 1); bt_mesh_beacon_create(sub, buf); - return proxy_segment_and_send(conn, BT_MESH_PROXY_BEACON, buf); + return proxy_segment_and_send(conn, BLE_MESH_PROXY_BEACON, buf); } static void proxy_send_beacons(struct k_work *work) @@ -347,7 +345,7 @@ static void proxy_send_beacons(struct k_work *work) for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) { struct bt_mesh_subnet *sub = &bt_mesh.sub[i]; - if (sub->net_idx != BT_MESH_KEY_UNUSED) { + if (sub->net_idx != BLE_MESH_KEY_UNUSED) { beacon_send(client->conn, sub); } } @@ -360,7 +358,7 @@ void bt_mesh_proxy_beacon_send(struct bt_mesh_subnet *sub) if (!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 != BT_MESH_KEY_UNUSED) { + if (bt_mesh.sub[i].net_idx != BLE_MESH_KEY_UNUSED) { bt_mesh_proxy_beacon_send(&bt_mesh.sub[i]); } } @@ -377,7 +375,7 @@ void bt_mesh_proxy_beacon_send(struct bt_mesh_subnet *sub) void bt_mesh_proxy_identity_start(struct bt_mesh_subnet *sub) { - sub->node_id = BT_MESH_NODE_IDENTITY_RUNNING; + sub->node_id = BLE_MESH_NODE_IDENTITY_RUNNING; sub->node_id_start = k_uptime_get_32(); /* Prioritize the recently enabled subnet */ @@ -386,7 +384,7 @@ void bt_mesh_proxy_identity_start(struct bt_mesh_subnet *sub) void bt_mesh_proxy_identity_stop(struct bt_mesh_subnet *sub) { - sub->node_id = BT_MESH_NODE_IDENTITY_STOPPED; + sub->node_id = BLE_MESH_NODE_IDENTITY_STOPPED; sub->node_id_start = 0; } @@ -403,11 +401,11 @@ int bt_mesh_proxy_identity_enable(void) for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) { struct bt_mesh_subnet *sub = &bt_mesh.sub[i]; - if (sub->net_idx == BT_MESH_KEY_UNUSED) { + if (sub->net_idx == BLE_MESH_KEY_UNUSED) { continue; } - if (sub->node_id == BT_MESH_NODE_IDENTITY_NOT_SUPPORTED) { + if (sub->node_id == BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED) { continue; } @@ -432,11 +430,11 @@ static void proxy_recv_timeout(struct k_work *work) client = CONTAINER_OF(work, struct bt_mesh_proxy_client, sar_timer.work); if (!client || !client->conn) { - BT_ERR("%s, Client parameter is NULL", __func__); + BT_ERR("%s, Invalid proxy client parameter", __func__); return; } - atomic_clear_bit(client->flags, SAR_TIMER_START); + bt_mesh_atomic_clear_bit(client->flags, SAR_TIMER_START); net_buf_simple_init(&client->buf, 0); bt_mesh_gatts_disconnect(client->conn, 0x13); } @@ -444,22 +442,22 @@ static void proxy_recv_timeout(struct k_work *work) static void proxy_complete_pdu(struct bt_mesh_proxy_client *client) { switch (client->msg_type) { -#if defined(CONFIG_BT_MESH_GATT_PROXY) - case BT_MESH_PROXY_NET_PDU: +#if defined(CONFIG_BLE_MESH_GATT_PROXY) + case BLE_MESH_PROXY_NET_PDU: BT_DBG("Mesh Network PDU"); - bt_mesh_net_recv(&client->buf, 0, BT_MESH_NET_IF_PROXY); + bt_mesh_net_recv(&client->buf, 0, BLE_MESH_NET_IF_PROXY); break; - case BT_MESH_PROXY_BEACON: + case BLE_MESH_PROXY_BEACON: BT_DBG("Mesh Beacon PDU"); bt_mesh_beacon_recv(&client->buf); break; - case BT_MESH_PROXY_CONFIG: + case BLE_MESH_PROXY_CONFIG: BT_DBG("Mesh Configuration PDU"); proxy_cfg(client); break; #endif -#if defined(CONFIG_BT_MESH_PB_GATT) - case BT_MESH_PROXY_PROV: +#if defined(CONFIG_BLE_MESH_PB_GATT) + case BLE_MESH_PROXY_PROV: BT_DBG("Mesh Provisioning PDU"); bt_mesh_pb_gatt_recv(client->conn, &client->buf); break; @@ -474,8 +472,8 @@ static void proxy_complete_pdu(struct bt_mesh_proxy_client *client) #define ATTR_IS_PROV(attr) (attr->user_data != NULL) -static ssize_t proxy_recv(struct bt_conn *conn, - const struct bt_gatt_attr *attr, const void *buf, +static ssize_t proxy_recv(struct bt_mesh_conn *conn, + const struct bt_mesh_gatt_attr *attr, const void *buf, u16_t len, u16_t offset, u8_t flags) { struct bt_mesh_proxy_client *client = find_client(conn); @@ -490,7 +488,7 @@ static ssize_t proxy_recv(struct bt_conn *conn, return -EINVAL; } - if (ATTR_IS_PROV(attr) != (PDU_TYPE(data) == BT_MESH_PROXY_PROV)) { + if (ATTR_IS_PROV(attr) != (PDU_TYPE(data) == BLE_MESH_PROXY_PROV)) { BT_WARN("Proxy PDU type doesn't match GATT service"); return -EINVAL; } @@ -518,7 +516,7 @@ static ssize_t proxy_recv(struct bt_conn *conn, return -EINVAL; } - if (!atomic_test_and_set_bit(client->flags, SAR_TIMER_START)) { + if (!bt_mesh_atomic_test_and_set_bit(client->flags, SAR_TIMER_START)) { k_delayed_work_submit(&client->sar_timer, PROXY_SAR_TRANS_TIMEOUT); } @@ -551,7 +549,7 @@ static ssize_t proxy_recv(struct bt_conn *conn, return -EINVAL; } - if (atomic_test_and_clear_bit(client->flags, SAR_TIMER_START)) { + if (bt_mesh_atomic_test_and_clear_bit(client->flags, SAR_TIMER_START)) { k_delayed_work_cancel(&client->sar_timer); } @@ -565,7 +563,7 @@ static ssize_t proxy_recv(struct bt_conn *conn, static int conn_count; -static void proxy_connected(struct bt_conn *conn, u8_t err) +static void proxy_connected(struct bt_mesh_conn *conn, u8_t err) { struct bt_mesh_proxy_client *client; int i; @@ -590,7 +588,7 @@ static void proxy_connected(struct bt_conn *conn, u8_t err) } if (!client) { - BT_ERR("No free Proxy Client objects"); + BT_ERR("%s, No free Proxy Client objects", __func__); return; } @@ -600,7 +598,7 @@ static void proxy_connected(struct bt_conn *conn, u8_t err) net_buf_simple_init(&client->buf, 0); } -static void proxy_disconnected(struct bt_conn *conn, u8_t reason) +static void proxy_disconnected(struct bt_mesh_conn *conn, u8_t reason) { int i; @@ -612,12 +610,12 @@ static void proxy_disconnected(struct bt_conn *conn, u8_t reason) struct bt_mesh_proxy_client *client = &clients[i]; if (client->conn == conn) { - if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT) && + if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) && client->filter_type == PROV) { bt_mesh_pb_gatt_close(conn); } - if (atomic_test_and_clear_bit(client->flags, SAR_TIMER_START)) { + if (bt_mesh_atomic_test_and_clear_bit(client->flags, SAR_TIMER_START)) { k_delayed_work_cancel(&client->sar_timer); } // Should reset the atomic flag after disconneted @@ -639,9 +637,9 @@ struct net_buf_simple *bt_mesh_proxy_get_buf(void) return buf; } -#if defined(CONFIG_BT_MESH_PB_GATT) -static ssize_t prov_ccc_write(struct bt_conn *conn, - const struct bt_gatt_attr *attr, +#if defined(CONFIG_BLE_MESH_PB_GATT) +static ssize_t prov_ccc_write(struct bt_mesh_conn *conn, + const struct bt_mesh_gatt_attr *attr, const void *buf, u16_t len, u16_t offset, u8_t flags) { @@ -651,11 +649,11 @@ static ssize_t prov_ccc_write(struct bt_conn *conn, BT_DBG("len %u: %s", len, bt_hex(buf, len)); if (len != sizeof(*value)) { - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); + return BLE_MESH_GATT_ERR(BLE_MESH_ATT_ERR_INVALID_ATTRIBUTE_LEN); } *value = sys_get_le16(buf); - if (*value != BT_GATT_CCC_NOTIFY) { + if (*value != BLE_MESH_GATT_CCC_NOTIFY) { BT_WARN("Client wrote 0x%04x instead enabling notify", *value); return len; } @@ -672,8 +670,8 @@ static ssize_t prov_ccc_write(struct bt_conn *conn, return len; } -static ssize_t prov_ccc_read(struct bt_conn *conn, - const struct bt_gatt_attr *attr, +static ssize_t prov_ccc_read(struct bt_mesh_conn *conn, + const struct bt_mesh_gatt_attr *attr, void *buf, u16_t len, u16_t offset) { u16_t *value = attr->user_data; @@ -683,25 +681,25 @@ static ssize_t prov_ccc_read(struct bt_conn *conn, } /* Mesh Provisioning Service Declaration */ -static struct bt_gatt_attr prov_attrs[] = { - BT_GATT_PRIMARY_SERVICE(BT_UUID_MESH_PROV), +static struct bt_mesh_gatt_attr prov_attrs[] = { + BLE_MESH_GATT_PRIMARY_SERVICE(BLE_MESH_UUID_MESH_PROV), - BT_GATT_CHARACTERISTIC(BT_UUID_MESH_PROV_DATA_IN, - BT_GATT_CHRC_WRITE_WITHOUT_RESP), - BT_GATT_DESCRIPTOR(BT_UUID_MESH_PROV_DATA_IN, BT_GATT_PERM_WRITE, + BLE_MESH_GATT_CHARACTERISTIC(BLE_MESH_UUID_MESH_PROV_DATA_IN, + BLE_MESH_GATT_CHRC_WRITE_WITHOUT_RESP), + BLE_MESH_GATT_DESCRIPTOR(BLE_MESH_UUID_MESH_PROV_DATA_IN, BLE_MESH_GATT_PERM_WRITE, NULL, proxy_recv, (void *)1), - BT_GATT_CHARACTERISTIC(BT_UUID_MESH_PROV_DATA_OUT, - BT_GATT_CHRC_NOTIFY), - BT_GATT_DESCRIPTOR(BT_UUID_MESH_PROV_DATA_OUT, BT_GATT_PERM_NONE, + BLE_MESH_GATT_CHARACTERISTIC(BLE_MESH_UUID_MESH_PROV_DATA_OUT, + BLE_MESH_GATT_CHRC_NOTIFY), + BLE_MESH_GATT_DESCRIPTOR(BLE_MESH_UUID_MESH_PROV_DATA_OUT, BLE_MESH_GATT_PERM_NONE, NULL, NULL, NULL), /* Add custom CCC as clients need to be tracked individually */ - BT_GATT_DESCRIPTOR(BT_UUID_GATT_CCC, - BT_GATT_PERM_WRITE | BT_GATT_PERM_READ, + BLE_MESH_GATT_DESCRIPTOR(BLE_MESH_UUID_GATT_CCC, + BLE_MESH_GATT_PERM_WRITE | BLE_MESH_GATT_PERM_READ, prov_ccc_read, prov_ccc_write, &prov_ccc_val), }; -struct bt_gatt_service prov_svc = BT_GATT_SERVICE(prov_attrs); +struct bt_mesh_gatt_service prov_svc = BLE_MESH_GATT_SERVICE(prov_attrs); int bt_mesh_proxy_prov_enable(void) { @@ -709,10 +707,8 @@ int bt_mesh_proxy_prov_enable(void) BT_DBG("%s", __func__); - /**TODO: Change by Espressif. We should not register service here, otherwise will - * block btu task, so currently just start it. Need to further check*/ bt_mesh_gatts_service_start(&prov_svc); - //bt_mesh_gatts_service_register(&prov_svc); + gatt_svc = MESH_GATT_PROV; prov_fast_adv = true; @@ -732,10 +728,8 @@ int bt_mesh_proxy_prov_disable(void) BT_DBG("%s", __func__); - /**TODO: Change by Espressif. Please refer to bt_mesh_proxy_prov_enable for - * more info */ bt_mesh_gatts_service_stop(&prov_svc); - //bt_mesh_gatts_service_unregister(&prov_svc); + gatt_svc = MESH_GATT_NONE; for (i = 0; i < ARRAY_SIZE(clients); i++) { @@ -750,11 +744,11 @@ int bt_mesh_proxy_prov_disable(void) return 0; } -#endif /* CONFIG_BT_MESH_PB_GATT */ +#endif /* CONFIG_BLE_MESH_PB_GATT */ -#if defined(CONFIG_BT_MESH_GATT_PROXY) -static ssize_t proxy_ccc_write(struct bt_conn *conn, - const struct bt_gatt_attr *attr, +#if defined(CONFIG_BLE_MESH_GATT_PROXY) +static ssize_t proxy_ccc_write(struct bt_mesh_conn *conn, + const struct bt_mesh_gatt_attr *attr, const void *buf, u16_t len, u16_t offset, u8_t flags) { @@ -764,11 +758,11 @@ static ssize_t proxy_ccc_write(struct bt_conn *conn, BT_DBG("len %u: %s", len, bt_hex(buf, len)); if (len != sizeof(value)) { - return BT_GATT_ERR(BT_ATT_ERR_INVALID_ATTRIBUTE_LEN); + return BLE_MESH_GATT_ERR(BLE_MESH_ATT_ERR_INVALID_ATTRIBUTE_LEN); } value = sys_get_le16(buf); - if (value != BT_GATT_CCC_NOTIFY) { + if (value != BLE_MESH_GATT_CCC_NOTIFY) { BT_WARN("Client wrote 0x%04x instead enabling notify", value); return len; } @@ -785,8 +779,8 @@ static ssize_t proxy_ccc_write(struct bt_conn *conn, return len; } -static ssize_t proxy_ccc_read(struct bt_conn *conn, - const struct bt_gatt_attr *attr, +static ssize_t proxy_ccc_read(struct bt_mesh_conn *conn, + const struct bt_mesh_gatt_attr *attr, void *buf, u16_t len, u16_t offset) { u16_t *value = attr->user_data; @@ -796,25 +790,25 @@ static ssize_t proxy_ccc_read(struct bt_conn *conn, } /* Mesh Proxy Service Declaration */ -static struct bt_gatt_attr proxy_attrs[] = { - BT_GATT_PRIMARY_SERVICE(BT_UUID_MESH_PROXY), +static struct bt_mesh_gatt_attr proxy_attrs[] = { + BLE_MESH_GATT_PRIMARY_SERVICE(BLE_MESH_UUID_MESH_PROXY), - BT_GATT_CHARACTERISTIC(BT_UUID_MESH_PROXY_DATA_IN, - BT_GATT_CHRC_WRITE_WITHOUT_RESP), - BT_GATT_DESCRIPTOR(BT_UUID_MESH_PROXY_DATA_IN, BT_GATT_PERM_WRITE, + BLE_MESH_GATT_CHARACTERISTIC(BLE_MESH_UUID_MESH_PROXY_DATA_IN, + BLE_MESH_GATT_CHRC_WRITE_WITHOUT_RESP), + BLE_MESH_GATT_DESCRIPTOR(BLE_MESH_UUID_MESH_PROXY_DATA_IN, BLE_MESH_GATT_PERM_WRITE, NULL, proxy_recv, NULL), - BT_GATT_CHARACTERISTIC(BT_UUID_MESH_PROXY_DATA_OUT, - BT_GATT_CHRC_NOTIFY), - BT_GATT_DESCRIPTOR(BT_UUID_MESH_PROXY_DATA_OUT, BT_GATT_PERM_NONE, + BLE_MESH_GATT_CHARACTERISTIC(BLE_MESH_UUID_MESH_PROXY_DATA_OUT, + BLE_MESH_GATT_CHRC_NOTIFY), + BLE_MESH_GATT_DESCRIPTOR(BLE_MESH_UUID_MESH_PROXY_DATA_OUT, BLE_MESH_GATT_PERM_NONE, NULL, NULL, NULL), /* Add custom CCC as clients need to be tracked individually */ - BT_GATT_DESCRIPTOR(BT_UUID_GATT_CCC, - BT_GATT_PERM_READ | BT_GATT_PERM_WRITE, + BLE_MESH_GATT_DESCRIPTOR(BLE_MESH_UUID_GATT_CCC, + BLE_MESH_GATT_PERM_READ | BLE_MESH_GATT_PERM_WRITE, proxy_ccc_read, proxy_ccc_write, &proxy_ccc_val), }; -struct bt_gatt_service proxy_svc = BT_GATT_SERVICE(proxy_attrs); +struct bt_mesh_gatt_service proxy_svc = BLE_MESH_GATT_SERVICE(proxy_attrs); int bt_mesh_proxy_gatt_enable(void) { @@ -822,10 +816,8 @@ int bt_mesh_proxy_gatt_enable(void) BT_DBG("%s", __func__); - /**TODO: We should not register service here, otherwise will - * block btu task, so currently just start it. Need to further check*/ bt_mesh_gatts_service_start(&proxy_svc); - //bt_mesh_gatts_service_register(&proxy_svc); + gatt_svc = MESH_GATT_PROXY; for (i = 0; i < ARRAY_SIZE(clients); i++) { @@ -850,7 +842,6 @@ void bt_mesh_proxy_gatt_disconnect(void) client->filter_type == BLACKLIST)) { client->filter_type = NONE; bt_mesh_gatts_disconnect(client->conn, 0x13); - //BT_HCI_ERR_REMOTE_USER_TERM_CONN); } } } @@ -861,10 +852,8 @@ int bt_mesh_proxy_gatt_disable(void) bt_mesh_proxy_gatt_disconnect(); - /**TODO: please refer to comment of bt_mesh_proxy_gatt_enable, - * We not de-register, but only stop service*/ bt_mesh_gatts_service_stop(&proxy_svc); - //bt_mesh_gatts_service_unregister(&proxy_svc); + gatt_svc = MESH_GATT_NONE; return 0; @@ -939,26 +928,26 @@ bool bt_mesh_proxy_relay(struct net_buf_simple *buf, u16_t dst) net_buf_simple_init(msg, 1); net_buf_simple_add_mem(msg, buf->data, buf->len); - bt_mesh_proxy_send(client->conn, BT_MESH_PROXY_NET_PDU, msg); + bt_mesh_proxy_send(client->conn, BLE_MESH_PROXY_NET_PDU, msg); relayed = true; } return relayed; } -#endif /* CONFIG_BT_MESH_GATT_PROXY */ +#endif /* CONFIG_BLE_MESH_GATT_PROXY */ -static int proxy_send(struct bt_conn *conn, const void *data, u16_t len) +static int proxy_send(struct bt_mesh_conn *conn, const void *data, u16_t len) { BT_DBG("%u bytes: %s", len, bt_hex(data, len)); -#if defined(CONFIG_BT_MESH_GATT_PROXY) +#if defined(CONFIG_BLE_MESH_GATT_PROXY) if (gatt_svc == MESH_GATT_PROXY) { return bt_mesh_gatts_notify(conn, &proxy_attrs[4], data, len); } #endif -#if defined(CONFIG_BT_MESH_PB_GATT) +#if defined(CONFIG_BLE_MESH_PB_GATT) if (gatt_svc == MESH_GATT_PROV) { return bt_mesh_gatts_notify(conn, &prov_attrs[4], data, len); } @@ -967,7 +956,7 @@ static int proxy_send(struct bt_conn *conn, const void *data, u16_t len) return 0; } -static int proxy_segment_and_send(struct bt_conn *conn, u8_t type, +static int proxy_segment_and_send(struct bt_mesh_conn *conn, u8_t type, struct net_buf_simple *msg) { u16_t mtu; @@ -1001,40 +990,40 @@ static int proxy_segment_and_send(struct bt_conn *conn, u8_t type, return 0; } -int bt_mesh_proxy_send(struct bt_conn *conn, u8_t type, +int bt_mesh_proxy_send(struct bt_mesh_conn *conn, u8_t type, struct net_buf_simple *msg) { struct bt_mesh_proxy_client *client = find_client(conn); if (!client) { - BT_ERR("No Proxy Client found"); + BT_ERR("%s, No Proxy Client found", __func__); return -ENOTCONN; } - if ((client->filter_type == PROV) != (type == BT_MESH_PROXY_PROV)) { - BT_ERR("Invalid PDU type for Proxy Client"); + if ((client->filter_type == PROV) != (type == BLE_MESH_PROXY_PROV)) { + BT_ERR("%s, Invalid PDU type for Proxy Client", __func__); return -EINVAL; } return proxy_segment_and_send(conn, type, msg); } -#if defined(CONFIG_BT_MESH_PB_GATT) +#if defined(CONFIG_BLE_MESH_PB_GATT) static u8_t prov_svc_data[20] = { 0x27, 0x18, }; -static const struct bt_data prov_ad[] = { - BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), - BT_DATA_BYTES(BT_DATA_UUID16_ALL, 0x27, 0x18), - BT_DATA(BT_DATA_SVC_DATA16, prov_svc_data, sizeof(prov_svc_data)), +static const struct bt_mesh_adv_data prov_ad[] = { + BLE_MESH_ADV_DATA_BYTES(BLE_MESH_DATA_FLAGS, (BLE_MESH_AD_GENERAL | BLE_MESH_AD_NO_BREDR)), + BLE_MESH_ADV_DATA_BYTES(BLE_MESH_DATA_UUID16_ALL, 0x27, 0x18), + BLE_MESH_ADV_DATA(BLE_MESH_DATA_SVC_DATA16, prov_svc_data, sizeof(prov_svc_data)), }; -static const struct bt_data prov_sd[] = { - BT_DATA(BT_DATA_NAME_COMPLETE, device_name, +static const struct bt_mesh_adv_data prov_sd[] = { + BLE_MESH_ADV_DATA(BLE_MESH_DATA_NAME_COMPLETE, device_name, (sizeof(device_name) - 1)), }; #endif /* PB_GATT */ -#if defined(CONFIG_BT_MESH_GATT_PROXY) +#if defined(CONFIG_BLE_MESH_GATT_PROXY) #define ID_TYPE_NET 0x00 #define ID_TYPE_NODE 0x01 @@ -1042,20 +1031,20 @@ static const struct bt_data prov_sd[] = { #define NODE_ID_LEN 19 #define NET_ID_LEN 11 -#define NODE_ID_TIMEOUT K_SECONDS(CONFIG_BT_MESH_NODE_ID_TIMEOUT) +#define NODE_ID_TIMEOUT K_SECONDS(CONFIG_BLE_MESH_NODE_ID_TIMEOUT) static u8_t proxy_svc_data[NODE_ID_LEN] = { 0x28, 0x18, }; -static const struct bt_data node_id_ad[] = { - BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), - BT_DATA_BYTES(BT_DATA_UUID16_ALL, 0x28, 0x18), - BT_DATA(BT_DATA_SVC_DATA16, proxy_svc_data, NODE_ID_LEN), +static const struct bt_mesh_adv_data node_id_ad[] = { + BLE_MESH_ADV_DATA_BYTES(BLE_MESH_DATA_FLAGS, (BLE_MESH_AD_GENERAL | BLE_MESH_AD_NO_BREDR)), + BLE_MESH_ADV_DATA_BYTES(BLE_MESH_DATA_UUID16_ALL, 0x28, 0x18), + BLE_MESH_ADV_DATA(BLE_MESH_DATA_SVC_DATA16, proxy_svc_data, NODE_ID_LEN), }; -static const struct bt_data net_id_ad[] = { - BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)), - BT_DATA_BYTES(BT_DATA_UUID16_ALL, 0x28, 0x18), - BT_DATA(BT_DATA_SVC_DATA16, proxy_svc_data, NET_ID_LEN), +static const struct bt_mesh_adv_data net_id_ad[] = { + BLE_MESH_ADV_DATA_BYTES(BLE_MESH_DATA_FLAGS, (BLE_MESH_AD_GENERAL | BLE_MESH_AD_NO_BREDR)), + BLE_MESH_ADV_DATA_BYTES(BLE_MESH_DATA_UUID16_ALL, 0x28, 0x18), + BLE_MESH_ADV_DATA(BLE_MESH_DATA_SVC_DATA16, proxy_svc_data, NET_ID_LEN), }; static int node_id_adv(struct bt_mesh_subnet *sub) @@ -1076,7 +1065,7 @@ static int node_id_adv(struct bt_mesh_subnet *sub) memcpy(tmp + 6, proxy_svc_data + 11, 8); sys_put_be16(bt_mesh_primary_addr(), tmp + 14); - err = bt_encrypt_be(sub->keys[sub->kr_flag].identity, tmp, tmp); + err = bt_mesh_encrypt_be(sub->keys[sub->kr_flag].identity, tmp, tmp); if (err) { return err; } @@ -1122,12 +1111,12 @@ static int net_id_adv(struct bt_mesh_subnet *sub) static bool advertise_subnet(struct bt_mesh_subnet *sub) { - if (sub->net_idx == BT_MESH_KEY_UNUSED) { + if (sub->net_idx == BLE_MESH_KEY_UNUSED) { return false; } - return (sub->node_id == BT_MESH_NODE_IDENTITY_RUNNING || - bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED); + return (sub->node_id == BLE_MESH_NODE_IDENTITY_RUNNING || + bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_ENABLED); } static struct bt_mesh_subnet *next_sub(void) @@ -1179,7 +1168,7 @@ static s32_t gatt_proxy_advertise(struct bt_mesh_subnet *sub) return remaining; } - if (sub->node_id == BT_MESH_NODE_IDENTITY_RUNNING) { + if (sub->node_id == BLE_MESH_NODE_IDENTITY_RUNNING) { u32_t active = k_uptime_get_32() - sub->node_id_start; if (active < NODE_ID_TIMEOUT) { @@ -1193,8 +1182,8 @@ static s32_t gatt_proxy_advertise(struct bt_mesh_subnet *sub) } } - if (sub->node_id == BT_MESH_NODE_IDENTITY_STOPPED) { - if (bt_mesh_gatt_proxy_get() == BT_MESH_GATT_PROXY_ENABLED) { + if (sub->node_id == BLE_MESH_NODE_IDENTITY_STOPPED) { + if (bt_mesh_gatt_proxy_get() == BLE_MESH_GATT_PROXY_ENABLED) { net_id_adv(sub); } else { return gatt_proxy_advertise(next_sub()); @@ -1211,8 +1200,8 @@ static s32_t gatt_proxy_advertise(struct bt_mesh_subnet *sub) * 6 slices, but make sure that a slice is at least one * second long (to avoid excessive rotation). */ - max_timeout = NODE_ID_TIMEOUT / max(subnet_count, 6); - max_timeout = max(max_timeout, K_SECONDS(1)); + max_timeout = NODE_ID_TIMEOUT / MAX(subnet_count, 6); + max_timeout = MAX(max_timeout, K_SECONDS(1)); if (remaining > max_timeout || remaining < 0) { remaining = max_timeout; @@ -1234,9 +1223,9 @@ s32_t bt_mesh_proxy_adv_start(void) return K_FOREVER; } -#if defined(CONFIG_BT_MESH_PB_GATT) +#if defined(CONFIG_BLE_MESH_PB_GATT) if (!bt_mesh_is_provisioned()) { - const struct bt_le_adv_param *param; + const struct bt_mesh_adv_param *param; if (prov_fast_adv) { param = &fast_adv_param; @@ -1257,7 +1246,7 @@ s32_t bt_mesh_proxy_adv_start(void) } #endif /* PB_GATT */ -#if defined(CONFIG_BT_MESH_GATT_PROXY) +#if defined(CONFIG_BLE_MESH_GATT_PROXY) if (bt_mesh_is_provisioned()) { return gatt_proxy_advertise(next_sub()); } @@ -1278,13 +1267,13 @@ void bt_mesh_proxy_adv_stop(void) err = bt_le_adv_stop(); if (err) { - BT_ERR("Failed to stop advertising (err %d)", err); + BT_ERR("%s, Stop advertising failed (err %d)", __func__, err); } else { proxy_adv_enabled = false; } } -static struct bt_conn_cb conn_callbacks = { +static struct bt_mesh_conn_cb conn_callbacks = { .connected = proxy_connected, .disconnected = proxy_disconnected, }; @@ -1297,9 +1286,9 @@ int bt_mesh_proxy_init(void) } bt_mesh_gatts_conn_cb_register(&conn_callbacks); -#if defined(CONFIG_BT_MESH_PB_GATT) +#if defined(CONFIG_BLE_MESH_PB_GATT) if (!bt_mesh_prov_get_uuid()) { - BT_ERR("%s: prov->uuid not initialized", __func__); + BT_ERR("%s, UUID is not initialized", __func__); return -EINVAL; } memcpy(prov_svc_data + 2, bt_mesh_prov_get_uuid(), 16); @@ -1308,6 +1297,4 @@ int bt_mesh_proxy_init(void) return 0; } -#endif /* CONFIG_BT_MESH_NODE */ - -#endif /* #if CONFIG_BT_MESH */ +#endif /* CONFIG_BLE_MESH_NODE */ diff --git a/components/bt/ble_mesh/mesh_core/proxy.h b/components/bt/ble_mesh/mesh_core/proxy.h index fcf496d1f1..1e91736c8c 100644 --- a/components/bt/ble_mesh/mesh_core/proxy.h +++ b/components/bt/ble_mesh/mesh_core/proxy.h @@ -7,23 +7,23 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef __PROXY_H__ -#define __PROXY_H__ +#ifndef _PROXY_H_ +#define _PROXY_H_ #include "net.h" #include "mesh_buf.h" #include "mesh_bearer_adapt.h" -#define BT_MESH_PROXY_NET_PDU 0x00 -#define BT_MESH_PROXY_BEACON 0x01 -#define BT_MESH_PROXY_CONFIG 0x02 -#define BT_MESH_PROXY_PROV 0x03 +#define BLE_MESH_PROXY_NET_PDU 0x00 +#define BLE_MESH_PROXY_BEACON 0x01 +#define BLE_MESH_PROXY_CONFIG 0x02 +#define BLE_MESH_PROXY_PROV 0x03 #define DEVICE_NAME_SIZE 29 int bt_mesh_set_device_name(const char *name); -int bt_mesh_proxy_send(struct bt_conn *conn, u8_t type, +int bt_mesh_proxy_send(struct bt_mesh_conn *conn, u8_t type, struct net_buf_simple *msg); int bt_mesh_proxy_prov_enable(void); @@ -44,8 +44,9 @@ void bt_mesh_proxy_identity_start(struct bt_mesh_subnet *sub); void bt_mesh_proxy_identity_stop(struct bt_mesh_subnet *sub); 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); int bt_mesh_proxy_init(void); -#endif /* __PROXY_H__ */ +#endif /* _PROXY_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/settings.c b/components/bt/ble_mesh/mesh_core/settings.c index 3114915f01..8521cc5b74 100644 --- a/components/bt/ble_mesh/mesh_core/settings.c +++ b/components/bt/ble_mesh/mesh_core/settings.c @@ -9,17 +9,14 @@ #include #include "sdkconfig.h" +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_SETTINGS) -#include "base64.h" #include "mesh_types.h" #include "mesh_util.h" #include "mesh_access.h" #include "mesh_main.h" - #include "mesh_buf.h" #include "mesh_kernel.h" - -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_SETTINGS) #include "mesh_trace.h" #include "mesh.h" @@ -30,10 +27,11 @@ #include "foundation.h" #include "proxy.h" #include "cfg_srv.h" -#include "settings.h" -#include "settings/include/settings.h" -#if CONFIG_BT_MESH_SETTINGS +#include "settings_base64.h" +#include "settings_act.h" + +#if CONFIG_BLE_MESH_SETTINGS /* Tracking of what storage changes are pending for App and Net Keys. We * track this in a separate array here instead of within the respective * bt_mesh_app_key and bt_mesh_subnet structs themselves, since once a key @@ -44,7 +42,7 @@ static struct key_update { valid: 1, /* 1 if this entry is valid, 0 if not */ app_key: 1, /* 1 if this is an AppKey, 0 if a NetKey */ clear: 1; /* 1 if key needs clearing, 0 if storing */ -} key_updates[CONFIG_BT_MESH_APP_KEY_COUNT + CONFIG_BT_MESH_SUBNET_COUNT]; +} key_updates[CONFIG_BLE_MESH_APP_KEY_COUNT + CONFIG_BLE_MESH_SUBNET_COUNT]; static struct k_delayed_work pending_store; @@ -140,12 +138,12 @@ static int net_set(int argc, char **argv, char *val) len = sizeof(net); err = settings_bytes_from_str(val, &net, &len); if (err) { - BT_ERR("Failed to decode value %s (err %d)", val, err); + BT_ERR("%s, Failed to decode value %s (err %d)", __func__, val, err); return err; } if (len != sizeof(net)) { - BT_ERR("Unexpected value length (%d != %zu)", len, sizeof(net)); + BT_ERR("%s, Unexpected value length (%d != %zu)", __func__, len, sizeof(net)); return -EINVAL; } @@ -174,12 +172,12 @@ static int iv_set(int argc, char **argv, char *val) len = sizeof(iv); err = settings_bytes_from_str(val, &iv, &len); if (err) { - BT_ERR("Failed to decode value %s (err %d)", val, err); + BT_ERR("%s, Failed to decode value %s (err %d)", __func__, val, err); return err; } if (len != sizeof(iv)) { - BT_ERR("Unexpected value length (%d != %zu)", len, sizeof(iv)); + BT_ERR("%s, Unexpected value length (%d != %zu)", __func__, len, sizeof(iv)); return -EINVAL; } @@ -207,25 +205,25 @@ static int seq_set(int argc, char **argv, char *val) len = sizeof(seq); err = settings_bytes_from_str(val, &seq, &len); if (err) { - BT_ERR("Failed to decode value %s (err %d)", val, err); + BT_ERR("%s, Failed to decode value %s (err %d)", __func__, val, err); return err; } if (len != sizeof(seq)) { - BT_ERR("Unexpected value length (%d != %zu)", len, sizeof(seq)); + BT_ERR("%s, Unexpected value length (%d != %zu)", __func__, len, sizeof(seq)); return -EINVAL; } bt_mesh.seq = ((u32_t)seq.val[0] | ((u32_t)seq.val[1] << 8) | ((u32_t)seq.val[2] << 16)); - if (CONFIG_BT_MESH_SEQ_STORE_RATE > 0) { + if (CONFIG_BLE_MESH_SEQ_STORE_RATE > 0) { /* Make sure we have a large enough sequence number. We * subtract 1 so that the first transmission causes a write * to the settings storage. */ - bt_mesh.seq += (CONFIG_BT_MESH_SEQ_STORE_RATE - - (bt_mesh.seq % CONFIG_BT_MESH_SEQ_STORE_RATE)); + bt_mesh.seq += (CONFIG_BLE_MESH_SEQ_STORE_RATE - + (bt_mesh.seq % CONFIG_BLE_MESH_SEQ_STORE_RATE)); bt_mesh.seq--; } @@ -269,7 +267,7 @@ static int rpl_set(int argc, char **argv, char *val) u16_t src; if (argc < 1) { - BT_ERR("Invalid argc (%d)", argc); + BT_ERR("%s, Invalid argc (%d)", __func__, argc); return -ENOENT; } @@ -291,7 +289,7 @@ static int rpl_set(int argc, char **argv, char *val) if (!entry) { entry = rpl_alloc(src); if (!entry) { - BT_ERR("Unable to allocate RPL entry for 0x%04x", src); + BT_ERR("%s, Unable to allocate RPL entry for 0x%04x", __func__, src); return -ENOMEM; } } @@ -299,12 +297,12 @@ static int rpl_set(int argc, char **argv, char *val) len = sizeof(rpl); err = settings_bytes_from_str(val, &rpl, &len); if (err) { - BT_ERR("Failed to decode value %s (err %d)", val, err); + BT_ERR("%s, Failed to decode value %s (err %d)", __func__, val, err); return err; } if (len != sizeof(rpl)) { - BT_ERR("Unexpected value length (%d != %zu)", len, sizeof(rpl)); + BT_ERR("%s, Unexpected value length (%d != %zu)", __func__, len, sizeof(rpl)); return -EINVAL; } @@ -331,25 +329,24 @@ static int net_key_set(int argc, char **argv, char *val) if (!val) { if (!sub) { - BT_ERR("No subnet with NetKeyIndex 0x%03x", net_idx); + BT_ERR("%s, No subnet with NetKeyIndex 0x%03x", __func__, net_idx); return -ENOENT; } BT_DBG("Deleting NetKeyIndex 0x%03x", net_idx); - //TODO: Should update the zephyr code v1.12.0 of the cfg_srv.c implementation. - //bt_mesh_subnet_del(sub); + bt_mesh_subnet_del(sub); return 0; } len = sizeof(key); err = settings_bytes_from_str(val, &key, &len); if (err) { - BT_ERR("Failed to decode value %s (err %d)", val, err); + BT_ERR("%s, Failed to decode value %s (err %d)", __func__, val, err); return err; } if (len != sizeof(key)) { - BT_ERR("Unexpected value length (%d != %zu)", len, sizeof(key)); + BT_ERR("%s, Unexpected value length (%d != %zu)", __func__, len, sizeof(key)); return -EINVAL; } @@ -365,14 +362,14 @@ static int net_key_set(int argc, char **argv, char *val) } for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) { - if (bt_mesh.sub[i].net_idx == BT_MESH_KEY_UNUSED) { + if (bt_mesh.sub[i].net_idx == BLE_MESH_KEY_UNUSED) { sub = &bt_mesh.sub[i]; break; } } if (!sub) { - BT_ERR("No space to allocate a new subnet"); + BT_ERR("%s, No space to allocate a new subnet", __func__); return -ENOMEM; } @@ -404,8 +401,7 @@ static int app_key_set(int argc, char **argv, char *val) app = bt_mesh_app_key_find(app_idx); if (app) { - //TODO: Should update the zephyr code v1.12.0 of the cfg_srv.c implementation. - //bt_mesh_app_key_del(app); + bt_mesh_app_key_del(app); } return 0; @@ -414,18 +410,18 @@ static int app_key_set(int argc, char **argv, char *val) len = sizeof(key); err = settings_bytes_from_str(val, &key, &len); if (err) { - BT_ERR("Failed to decode value %s (err %d)", val, err); + BT_ERR("%s, Failed to decode value %s (err %d)", __func__, val, err); return err; } if (len != sizeof(key)) { - BT_ERR("Unexpected value length (%d != %zu)", len, sizeof(key)); + BT_ERR("%s, Unexpected value length (%d != %zu)", __func__, len, sizeof(key)); return -EINVAL; } sub = bt_mesh_subnet_get(key.net_idx); if (!sub) { - BT_ERR("Failed to find subnet 0x%03x", key.net_idx); + BT_ERR("%s, Failed to find subnet 0x%03x", __func__, key.net_idx); return -ENOENT; } @@ -435,7 +431,7 @@ static int app_key_set(int argc, char **argv, char *val) } if (!app) { - BT_ERR("No space for a new app key"); + BT_ERR("%s, No space for a new app key", __func__); return -ENOMEM; } @@ -466,7 +462,7 @@ static int hb_pub_set(int argc, char **argv, char *val) } if (!val) { - pub->dst = BT_MESH_ADDR_UNASSIGNED; + pub->dst = BLE_MESH_ADDR_UNASSIGNED; pub->count = 0; pub->ttl = 0; pub->period = 0; @@ -479,13 +475,12 @@ static int hb_pub_set(int argc, char **argv, char *val) len = sizeof(hb_val); err = settings_bytes_from_str(val, &hb_val, &len); if (err) { - BT_ERR("Failed to decode value %s (err %d)", val, err); + BT_ERR("%s, Failed to decode value %s (err %d)", __func__, val, err); return err; } if (len != sizeof(hb_val)) { - BT_ERR("Unexpected value length (%d != %zu)", len, - sizeof(hb_val)); + BT_ERR("%s, Unexpected value length (%d != %zu)", __func__, len, sizeof(hb_val)); return -EINVAL; } @@ -526,12 +521,12 @@ static int cfg_set(int argc, char **argv, char *val) len = sizeof(stored_cfg.cfg); err = settings_bytes_from_str(val, &stored_cfg.cfg, &len); if (err) { - BT_ERR("Failed to decode value %s (err %d)", val, err); + BT_ERR("%s, Failed to decode value %s (err %d)", __func__, val, err); return err; } if (len != sizeof(stored_cfg.cfg)) { - BT_ERR("Unexpected value length (%d != %zu)", len, + BT_ERR("%s, Unexpected value length (%d != %zu)", __func__, len, sizeof(stored_cfg.cfg)); return -EINVAL; } @@ -548,7 +543,7 @@ static int mod_set_bind(struct bt_mesh_model *mod, char *val) /* Start with empty array regardless of cleared or set value */ for (i = 0; i < ARRAY_SIZE(mod->keys); i++) { - mod->keys[i] = BT_MESH_KEY_UNUSED; + mod->keys[i] = BLE_MESH_KEY_UNUSED; } if (!val) { @@ -559,7 +554,7 @@ static int mod_set_bind(struct bt_mesh_model *mod, char *val) len = sizeof(mod->keys); err = settings_bytes_from_str(val, mod->keys, &len); if (err) { - BT_ERR("Failed to decode value %s (err %d)", val, err); + BT_ERR("%s, Failed to decode value %s (err %d)", __func__, val, err); return -EINVAL; } @@ -582,7 +577,7 @@ static int mod_set_sub(struct bt_mesh_model *mod, char *val) len = sizeof(mod->groups); err = settings_bytes_from_str(val, mod->groups, &len); if (err) { - BT_ERR("Failed to decode value %s (err %d)", val, err); + BT_ERR("%s, Failed to decode value %s (err %d)", __func__, val, err); return -EINVAL; } @@ -602,7 +597,7 @@ static int mod_set_pub(struct bt_mesh_model *mod, char *val) } if (!val) { - mod->pub->addr = BT_MESH_ADDR_UNASSIGNED; + mod->pub->addr = BLE_MESH_ADDR_UNASSIGNED; mod->pub->key = 0; mod->pub->cred = 0; mod->pub->ttl = 0; @@ -617,12 +612,12 @@ static int mod_set_pub(struct bt_mesh_model *mod, char *val) len = sizeof(pub); err = settings_bytes_from_str(val, &pub, &len); if (err) { - BT_ERR("Failed to decode value %s (err %d)", val, err); + BT_ERR("%s, Failed to decode value %s (err %d)", __func__, val, err); return -EINVAL; } if (len != sizeof(pub)) { - BT_ERR("Invalid length for model publication"); + BT_ERR("%s, Invalid length for model publication", __func__); return -EINVAL; } @@ -647,7 +642,7 @@ static int mod_set(bool vnd, int argc, char **argv, char *val) u16_t mod_key; if (argc < 2) { - BT_ERR("Too small argc (%d)", argc); + BT_ERR("%s, Too small argc (%d)", __func__, argc); return -ENOENT; } @@ -660,8 +655,8 @@ static int mod_set(bool vnd, int argc, char **argv, char *val) mod = bt_mesh_model_get(vnd, elem_idx, mod_idx); if (!mod) { - BT_ERR("Failed to get model for elem_idx %u mod_idx %u", - elem_idx, mod_idx); + BT_ERR("%s, Failed to get model for elem_idx %u mod_idx %u", + __func__, elem_idx, mod_idx); return -ENOENT; } @@ -695,16 +690,16 @@ const struct mesh_setting { const char *name; int (*func)(int argc, char **argv, char *val); } settings[] = { - { "Net", net_set }, - { "IV", iv_set }, - { "Seq", seq_set }, - { "RPL", rpl_set }, - { "NetKey", net_key_set }, - { "AppKey", app_key_set }, - { "HBPub", hb_pub_set }, - { "Cfg", cfg_set }, - { "s", sig_mod_set }, - { "v", vnd_mod_set }, + { "net", net_set }, + { "iv", iv_set }, + { "seq", seq_set }, + { "rpl", rpl_set }, + { "nk", net_key_set }, + { "ak", app_key_set }, + { "hp", hb_pub_set }, + { "cfg", cfg_set }, + { "s", sig_mod_set }, + { "v", vnd_mod_set }, }; static int mesh_set(int argc, char **argv, char *val) @@ -712,7 +707,7 @@ static int mesh_set(int argc, char **argv, char *val) int i; if (argc < 1) { - BT_ERR("Insufficient number of arguments"); + BT_ERR("%s, Insufficient number of arguments", __func__); return -EINVAL; } @@ -738,23 +733,23 @@ 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("Unable to generate keys for subnet"); + BT_ERR("%s, Unable to generate keys for subnet", __func__); return -EIO; } - if (sub->kr_phase != BT_MESH_KR_NORMAL) { + 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("Unable to generate keys for subnet"); + BT_ERR("%s, Unable to generate keys for subnet", __func__); memset(&sub->keys[0], 0, sizeof(sub->keys[0])); return -EIO; } } - if (IS_ENABLED(CONFIG_BT_MESH_GATT_PROXY)) { - sub->node_id = BT_MESH_NODE_IDENTITY_STOPPED; + if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY)) { + sub->node_id = BLE_MESH_NODE_IDENTITY_STOPPED; } else { - sub->node_id = BT_MESH_NODE_IDENTITY_NOT_SUPPORTED; + sub->node_id = BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED; } /* Make sure we have valid beacon data to be sent */ @@ -767,7 +762,7 @@ static void commit_mod(struct bt_mesh_model *mod, struct bt_mesh_elem *elem, bool vnd, bool primary, void *user_data) { if (mod->pub && mod->pub->update && - mod->pub->addr != BT_MESH_ADDR_UNASSIGNED) { + mod->pub->addr != BLE_MESH_ADDR_UNASSIGNED) { s32_t ms = bt_mesh_model_pub_period_get(mod); if (ms) { BT_DBG("Starting publish timer (period %u ms)", ms); @@ -784,13 +779,13 @@ static int mesh_commit(void) BT_DBG("sub[0].net_idx 0x%03x", bt_mesh.sub[0].net_idx); - if (bt_mesh.sub[0].net_idx == BT_MESH_KEY_UNUSED) { + if (bt_mesh.sub[0].net_idx == BLE_MESH_KEY_UNUSED) { /* Nothing to do since we're not yet provisioned */ return 0; } - if (IS_ENABLED(CONFIG_BT_MESH_PB_GATT)) { -#if defined(CONFIG_BT_MESH_NODE) + if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) { +#if defined(CONFIG_BLE_MESH_NODE) bt_mesh_proxy_prov_disable(); #endif } @@ -799,29 +794,28 @@ static int mesh_commit(void) struct bt_mesh_subnet *sub = &bt_mesh.sub[i]; int err; - if (sub->net_idx == BT_MESH_KEY_UNUSED) { + if (sub->net_idx == BLE_MESH_KEY_UNUSED) { continue; } err = subnet_init(sub); if (err) { - BT_ERR("Failed to init subnet 0x%03x", sub->net_idx); + BT_ERR("%s, Failed to init subnet 0x%03x", __func__, sub->net_idx); } } /* Set initial IV Update procedure state time-stamp */ - bt_mesh.last_update = BT_MESH_NET_IVU_UNKNOWN; + bt_mesh.last_update = BLE_MESH_NET_IVU_UNKNOWN; /* Set a timer to transition back to normal mode */ if (bt_mesh.iv_update) { - k_delayed_work_submit(&bt_mesh.ivu_complete, - BT_MESH_NET_IVU_TIMEOUT); + k_delayed_work_submit(&bt_mesh.ivu_complete, BLE_MESH_NET_IVU_TIMEOUT); } bt_mesh_model_foreach(commit_mod, NULL); hb_pub = bt_mesh_hb_pub_get(); - if (hb_pub && hb_pub->dst != BT_MESH_ADDR_UNASSIGNED && + if (hb_pub && hb_pub->dst != BLE_MESH_ADDR_UNASSIGNED && hb_pub->count && hb_pub->period) { BT_DBG("Starting heartbeat publication"); k_work_submit(&hb_pub->timer.work); @@ -840,59 +834,60 @@ static int mesh_commit(void) bt_mesh.valid = 1; -#if defined(CONFIG_BT_MESH_NODE) +#if defined(CONFIG_BLE_MESH_NODE) bt_mesh_net_start(); #endif return 0; } -//BT_SETTINGS_DEFINE(mesh, mesh_set, mesh_commit, NULL); static struct settings_handler mesh = { - .name = "bt_mesh", + .name = "mesh", .h_set = mesh_set, .h_commit = mesh_commit, - .h_export = NULL, }; static void schedule_store(int flag) { s32_t timeout; - atomic_set_bit(bt_mesh.flags, flag); + bt_mesh_atomic_set_bit(bt_mesh.flags, flag); - if (atomic_test_bit(bt_mesh.flags, BT_MESH_NET_PENDING) || - atomic_test_bit(bt_mesh.flags, BT_MESH_IV_PENDING) || - atomic_test_bit(bt_mesh.flags, BT_MESH_SEQ_PENDING)) { + if (bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_NET_PENDING) || + bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_IV_PENDING) || + bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_SEQ_PENDING)) { timeout = K_NO_WAIT; - } else if (atomic_test_bit(bt_mesh.flags, BT_MESH_RPL_PENDING) && - (CONFIG_BT_MESH_RPL_STORE_TIMEOUT < - CONFIG_BT_MESH_STORE_TIMEOUT)) { - timeout = K_SECONDS(CONFIG_BT_MESH_RPL_STORE_TIMEOUT); + } else if (bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_RPL_PENDING) && + (CONFIG_BLE_MESH_RPL_STORE_TIMEOUT < CONFIG_BLE_MESH_STORE_TIMEOUT)) { + timeout = K_SECONDS(CONFIG_BLE_MESH_RPL_STORE_TIMEOUT); } else { - timeout = K_SECONDS(CONFIG_BT_MESH_STORE_TIMEOUT); + timeout = K_SECONDS(CONFIG_BLE_MESH_STORE_TIMEOUT); } BT_DBG("Waiting %d seconds", timeout / MSEC_PER_SEC); - k_delayed_work_submit(&pending_store, timeout); + if (timeout) { + k_delayed_work_submit(&pending_store, timeout); + } else { + k_work_submit(&pending_store.work); + } } static void clear_iv(void) { BT_DBG("Clearing IV"); - settings_save_one("bt_mesh/IV", NULL); + settings_save_one("mesh/iv", NULL); } static void clear_net(void) { BT_DBG("Clearing Network"); - settings_save_one("bt_mesh/Net", NULL); + settings_save_one("mesh/net", NULL); } static void store_pending_net(void) { - char buf[BT_SETTINGS_SIZE(sizeof(struct net_val))]; + char buf[BASE64_ENCODE_SIZE(sizeof(struct net_val))]; struct net_val net; char *str; @@ -904,22 +899,22 @@ static void store_pending_net(void) str = settings_str_from_bytes(&net, sizeof(net), buf, sizeof(buf)); if (!str) { - BT_ERR("Unable to encode Network as value"); + BT_ERR("%s, Unable to encode Network as value", __func__); return; } BT_DBG("Saving Network as value %s", str); - settings_save_one("bt_mesh/Net", str); + settings_save_one("mesh/net", str); } void bt_mesh_store_net(void) { - schedule_store(BT_MESH_NET_PENDING); + schedule_store(BLE_MESH_NET_PENDING); } static void store_pending_iv(void) { - char buf[BT_SETTINGS_SIZE(sizeof(struct iv_val))]; + char buf[BASE64_ENCODE_SIZE(sizeof(struct iv_val))]; struct iv_val iv; char *str; @@ -928,24 +923,24 @@ static void store_pending_iv(void) str = settings_str_from_bytes(&iv, sizeof(iv), buf, sizeof(buf)); if (!str) { - BT_ERR("Unable to encode IV as value"); + BT_ERR("%s, Unable to encode IV as value", __func__); return; } BT_DBG("Saving IV as value %s", str); - settings_save_one("bt_mesh/IV", str); + settings_save_one("mesh/iv", str); } void bt_mesh_store_iv(void) { - schedule_store(BT_MESH_IV_PENDING); + schedule_store(BLE_MESH_IV_PENDING); /* Always update Seq whenever IV changes */ - schedule_store(BT_MESH_SEQ_PENDING); + schedule_store(BLE_MESH_SEQ_PENDING); } static void store_pending_seq(void) { - char buf[BT_SETTINGS_SIZE(sizeof(struct seq_val))]; + char buf[BASE64_ENCODE_SIZE(sizeof(struct seq_val))]; struct seq_val seq; char *str; @@ -955,27 +950,27 @@ static void store_pending_seq(void) str = settings_str_from_bytes(&seq, sizeof(seq), buf, sizeof(buf)); if (!str) { - BT_ERR("Unable to encode Seq as value"); + BT_ERR("%s, Unable to encode Seq as value", __func__); return; } BT_DBG("Saving Seq as value %s", str); - settings_save_one("bt_mesh/Seq", str); + settings_save_one("mesh/seq", str); } void bt_mesh_store_seq(void) { - if (CONFIG_BT_MESH_SEQ_STORE_RATE && - (bt_mesh.seq % CONFIG_BT_MESH_SEQ_STORE_RATE)) { + if (CONFIG_BLE_MESH_SEQ_STORE_RATE && + (bt_mesh.seq % CONFIG_BLE_MESH_SEQ_STORE_RATE)) { return; } - schedule_store(BT_MESH_SEQ_PENDING); + schedule_store(BLE_MESH_SEQ_PENDING); } static void store_rpl(struct bt_mesh_rpl *entry) { - char buf[BT_SETTINGS_SIZE(sizeof(struct rpl_val))]; + char buf[BASE64_ENCODE_SIZE(sizeof(struct rpl_val))]; struct rpl_val rpl; char path[18]; char *str; @@ -988,11 +983,11 @@ static void store_rpl(struct bt_mesh_rpl *entry) str = settings_str_from_bytes(&rpl, sizeof(rpl), buf, sizeof(buf)); if (!str) { - BT_ERR("Unable to encode RPL as value"); + BT_ERR("%s, Unable to encode RPL as value", __func__); return; } - snprintf(path, sizeof(path), "bt_mesh/RPL/%x", entry->src); + snprintf(path, sizeof(path), "mesh/rpl/%x", entry->src); BT_DBG("Saving RPL %s as value %s", path, str); settings_save_one(path, str); @@ -1002,7 +997,7 @@ static void clear_rpl(void) { int i; - BT_DBG(""); + BT_DBG("%s", __func__); for (i = 0; i < ARRAY_SIZE(bt_mesh.rpl); i++) { struct bt_mesh_rpl *rpl = &bt_mesh.rpl[i]; @@ -1012,7 +1007,7 @@ static void clear_rpl(void) continue; } - snprintf(path, sizeof(path), "bt_mesh/RPL/%x", rpl->src); + snprintf(path, sizeof(path), "mesh/rpl/%x", rpl->src); settings_save_one(path, NULL); memset(rpl, 0, sizeof(*rpl)); @@ -1023,7 +1018,7 @@ static void store_pending_rpl(void) { int i; - BT_DBG(""); + BT_DBG("%s", __func__); for (i = 0; i < ARRAY_SIZE(bt_mesh.rpl); i++) { struct bt_mesh_rpl *rpl = &bt_mesh.rpl[i]; @@ -1037,7 +1032,7 @@ static void store_pending_rpl(void) static void store_pending_hb_pub(void) { - char buf[BT_SETTINGS_SIZE(sizeof(struct hb_pub_val))]; + char buf[BASE64_ENCODE_SIZE(sizeof(struct hb_pub_val))]; struct bt_mesh_hb_pub *pub = bt_mesh_hb_pub_get(); struct hb_pub_val val; char *str; @@ -1046,7 +1041,7 @@ static void store_pending_hb_pub(void) return; } - if (pub->dst == BT_MESH_ADDR_UNASSIGNED) { + if (pub->dst == BLE_MESH_ADDR_UNASSIGNED) { str = NULL; } else { val.indefinite = (pub->count = 0xffff); @@ -1059,19 +1054,18 @@ static void store_pending_hb_pub(void) str = settings_str_from_bytes(&val, sizeof(val), buf, sizeof(buf)); if (!str) { - BT_ERR("Unable to encode hb pub as value"); + BT_ERR("%s, Unable to encode hb pub as value", __func__); return; } } - BT_DBG("Saving Heartbeat Publication as value %s", - str ? str : "(null)"); - settings_save_one("bt_mesh/HBPub", str); + BT_DBG("Saving Heartbeat Publication as value %s", str ? str : "(null)"); + settings_save_one("mesh/hp", str); } static void store_pending_cfg(void) { - char buf[BT_SETTINGS_SIZE(sizeof(struct cfg_val))]; + char buf[BASE64_ENCODE_SIZE(sizeof(struct cfg_val))]; struct bt_mesh_cfg_srv *cfg = bt_mesh_cfg_get(); struct cfg_val val; char *str; @@ -1090,18 +1084,18 @@ static void store_pending_cfg(void) str = settings_str_from_bytes(&val, sizeof(val), buf, sizeof(buf)); if (!str) { - BT_ERR("Unable to encode configuration as value"); + BT_ERR("%s, Unable to encode configuration as value", __func__); return; } BT_DBG("Saving configuration as value %s", str); - settings_save_one("bt_mesh/Cfg", str); + settings_save_one("mesh/cfg", str); } static void clear_cfg(void) { BT_DBG("Clearing configuration"); - settings_save_one("bt_mesh/Cfg", NULL); + settings_save_one("mesh/cfg", NULL); } static void clear_app_key(u16_t app_idx) @@ -1110,7 +1104,7 @@ static void clear_app_key(u16_t app_idx) BT_DBG("AppKeyIndex 0x%03x", app_idx); - snprintf(path, sizeof(path), "bt_mesh/AppKey/%x", app_idx); + snprintf(path, sizeof(path), "mesh/ak/%x", app_idx); settings_save_one(path, NULL); } @@ -1120,13 +1114,13 @@ static void clear_net_key(u16_t net_idx) BT_DBG("NetKeyIndex 0x%03x", net_idx); - snprintf(path, sizeof(path), "bt_mesh/NetKey/%x", net_idx); + snprintf(path, sizeof(path), "mesh/nk/%x", net_idx); settings_save_one(path, NULL); } static void store_net_key(struct bt_mesh_subnet *sub) { - char buf[BT_SETTINGS_SIZE(sizeof(struct net_key_val))]; + char buf[BASE64_ENCODE_SIZE(sizeof(struct net_key_val))]; struct net_key_val key; char path[20]; char *str; @@ -1141,11 +1135,11 @@ static void store_net_key(struct bt_mesh_subnet *sub) str = settings_str_from_bytes(&key, sizeof(key), buf, sizeof(buf)); if (!str) { - BT_ERR("Unable to encode NetKey as value"); + BT_ERR("%s, Unable to encode NetKey as value", __func__); return; } - snprintf(path, sizeof(path), "bt_mesh/NetKey/%x", sub->net_idx); + snprintf(path, sizeof(path), "mesh/nk/%x", sub->net_idx); BT_DBG("Saving NetKey %s as value %s", path, str); settings_save_one(path, str); @@ -1153,7 +1147,7 @@ static void store_net_key(struct bt_mesh_subnet *sub) static void store_app_key(struct bt_mesh_app_key *app) { - char buf[BT_SETTINGS_SIZE(sizeof(struct app_key_val))]; + char buf[BASE64_ENCODE_SIZE(sizeof(struct app_key_val))]; struct app_key_val key; char path[20]; char *str; @@ -1165,11 +1159,11 @@ static void store_app_key(struct bt_mesh_app_key *app) str = settings_str_from_bytes(&key, sizeof(key), buf, sizeof(buf)); if (!str) { - BT_ERR("Unable to encode AppKey as value"); + BT_ERR("%s, Unable to encode AppKey as value", __func__); return; } - snprintf(path, sizeof(path), "bt_mesh/AppKey/%x", app->app_idx); + snprintf(path, sizeof(path), "mesh/ak/%x", app->app_idx); BT_DBG("Saving AppKey %s as value %s", path, str); settings_save_one(path, str); @@ -1224,26 +1218,25 @@ static void store_pending_keys(void) static void encode_mod_path(struct bt_mesh_model *mod, bool vnd, const char *key, char *path, size_t path_len) { - // TODO: u16_t mod_key = (((u16_t)mod->element_idx << 8) | mod->model_idx); if (vnd) { - snprintf(path, path_len, "bt_mesh/v/%x/%s", mod_key, key); + snprintf(path, path_len, "mesh/v/%x/%s", mod_key, key); } else { - snprintf(path, path_len, "bt_mesh/s/%x/%s", mod_key, key); + snprintf(path, path_len, "mesh/s/%x/%s", mod_key, key); } } static void store_pending_mod_bind(struct bt_mesh_model *mod, bool vnd) { - u16_t keys[CONFIG_BT_MESH_MODEL_KEY_COUNT]; - char buf[BT_SETTINGS_SIZE(sizeof(keys))]; + u16_t keys[CONFIG_BLE_MESH_MODEL_KEY_COUNT]; + char buf[BASE64_ENCODE_SIZE(sizeof(keys))]; char path[20]; int i, count; char *val; for (i = 0, count = 0; i < ARRAY_SIZE(mod->keys); i++) { - if (mod->keys[i] != BT_MESH_KEY_UNUSED) { + if (mod->keys[i] != BLE_MESH_KEY_UNUSED) { keys[count++] = mod->keys[i]; } } @@ -1252,7 +1245,7 @@ static void store_pending_mod_bind(struct bt_mesh_model *mod, bool vnd) val = settings_str_from_bytes(keys, count * sizeof(keys[0]), buf, sizeof(buf)); if (!val) { - BT_ERR("Unable to encode model bindings as value"); + BT_ERR("%s, Unable to encode model bindings as value", __func__); return; } } else { @@ -1267,14 +1260,14 @@ static void store_pending_mod_bind(struct bt_mesh_model *mod, bool vnd) static void store_pending_mod_sub(struct bt_mesh_model *mod, bool vnd) { - u16_t groups[CONFIG_BT_MESH_MODEL_GROUP_COUNT]; - char buf[BT_SETTINGS_SIZE(sizeof(groups))]; + u16_t groups[CONFIG_BLE_MESH_MODEL_GROUP_COUNT]; + char buf[BASE64_ENCODE_SIZE(sizeof(groups))]; char path[20]; int i, count; char *val; for (i = 0, count = 0; i < ARRAY_SIZE(mod->groups); i++) { - if (mod->groups[i] != BT_MESH_ADDR_UNASSIGNED) { + if (mod->groups[i] != BLE_MESH_ADDR_UNASSIGNED) { groups[count++] = mod->groups[i]; } } @@ -1283,7 +1276,7 @@ static void store_pending_mod_sub(struct bt_mesh_model *mod, bool vnd) val = settings_str_from_bytes(groups, count * sizeof(groups[0]), buf, sizeof(buf)); if (!val) { - BT_ERR("Unable to encode model subscription as value"); + BT_ERR("%s, Unable to encode model subscription as value", __func__); return; } } else { @@ -1298,12 +1291,12 @@ static void store_pending_mod_sub(struct bt_mesh_model *mod, bool vnd) static void store_pending_mod_pub(struct bt_mesh_model *mod, bool vnd) { - char buf[BT_SETTINGS_SIZE(sizeof(struct mod_pub_val))]; + char buf[BASE64_ENCODE_SIZE(sizeof(struct mod_pub_val))]; struct mod_pub_val pub; char path[20]; char *val; - if (!mod->pub || mod->pub->addr == BT_MESH_ADDR_UNASSIGNED) { + if (!mod->pub || mod->pub->addr == BLE_MESH_ADDR_UNASSIGNED) { val = NULL; } else { pub.addr = mod->pub->addr; @@ -1317,7 +1310,7 @@ static void store_pending_mod_pub(struct bt_mesh_model *mod, bool vnd) val = settings_str_from_bytes(&pub, sizeof(pub), buf, sizeof(buf)); if (!val) { - BT_ERR("Unable to encode model publication as value"); + BT_ERR("%s, Unable to encode model publication as value", __func__); return; } } @@ -1336,27 +1329,27 @@ static void store_pending_mod(struct bt_mesh_model *mod, return; } - if (mod->flags & BT_MESH_MOD_BIND_PENDING) { - mod->flags &= ~BT_MESH_MOD_BIND_PENDING; + if (mod->flags & BLE_MESH_MOD_BIND_PENDING) { + mod->flags &= ~BLE_MESH_MOD_BIND_PENDING; store_pending_mod_bind(mod, vnd); } - if (mod->flags & BT_MESH_MOD_SUB_PENDING) { - mod->flags &= ~BT_MESH_MOD_SUB_PENDING; + if (mod->flags & BLE_MESH_MOD_SUB_PENDING) { + mod->flags &= ~BLE_MESH_MOD_SUB_PENDING; store_pending_mod_sub(mod, vnd); } - if (mod->flags & BT_MESH_MOD_PUB_PENDING) { - mod->flags &= ~BT_MESH_MOD_PUB_PENDING; + if (mod->flags & BLE_MESH_MOD_PUB_PENDING) { + mod->flags &= ~BLE_MESH_MOD_PUB_PENDING; store_pending_mod_pub(mod, vnd); } } static void store_pending(struct k_work *work) { - BT_DBG(""); + BT_DBG("%s", __func__); - if (atomic_test_and_clear_bit(bt_mesh.flags, BT_MESH_RPL_PENDING)) { + if (bt_mesh_atomic_test_and_clear_bit(bt_mesh.flags, BLE_MESH_RPL_PENDING)) { if (bt_mesh.valid) { store_pending_rpl(); } else { @@ -1364,11 +1357,11 @@ static void store_pending(struct k_work *work) } } - if (atomic_test_and_clear_bit(bt_mesh.flags, BT_MESH_KEYS_PENDING)) { + if (bt_mesh_atomic_test_and_clear_bit(bt_mesh.flags, BLE_MESH_KEYS_PENDING)) { store_pending_keys(); } - if (atomic_test_and_clear_bit(bt_mesh.flags, BT_MESH_NET_PENDING)) { + if (bt_mesh_atomic_test_and_clear_bit(bt_mesh.flags, BLE_MESH_NET_PENDING)) { if (bt_mesh.valid) { store_pending_net(); } else { @@ -1376,7 +1369,7 @@ static void store_pending(struct k_work *work) } } - if (atomic_test_and_clear_bit(bt_mesh.flags, BT_MESH_IV_PENDING)) { + if (bt_mesh_atomic_test_and_clear_bit(bt_mesh.flags, BLE_MESH_IV_PENDING)) { if (bt_mesh.valid) { store_pending_iv(); } else { @@ -1384,15 +1377,15 @@ static void store_pending(struct k_work *work) } } - if (atomic_test_and_clear_bit(bt_mesh.flags, BT_MESH_SEQ_PENDING)) { + if (bt_mesh_atomic_test_and_clear_bit(bt_mesh.flags, BLE_MESH_SEQ_PENDING)) { store_pending_seq(); } - if (atomic_test_and_clear_bit(bt_mesh.flags, BT_MESH_HB_PUB_PENDING)) { + if (bt_mesh_atomic_test_and_clear_bit(bt_mesh.flags, BLE_MESH_HB_PUB_PENDING)) { store_pending_hb_pub(); } - if (atomic_test_and_clear_bit(bt_mesh.flags, BT_MESH_CFG_PENDING)) { + if (bt_mesh_atomic_test_and_clear_bit(bt_mesh.flags, BLE_MESH_CFG_PENDING)) { if (bt_mesh.valid) { store_pending_cfg(); } else { @@ -1400,7 +1393,7 @@ static void store_pending(struct k_work *work) } } - if (atomic_test_and_clear_bit(bt_mesh.flags, BT_MESH_MOD_PENDING)) { + if (bt_mesh_atomic_test_and_clear_bit(bt_mesh.flags, BLE_MESH_MOD_PENDING)) { bt_mesh_model_foreach(store_pending_mod, NULL); } } @@ -1408,7 +1401,7 @@ static void store_pending(struct k_work *work) void bt_mesh_store_rpl(struct bt_mesh_rpl *entry) { entry->store = true; - schedule_store(BT_MESH_RPL_PENDING); + schedule_store(BLE_MESH_RPL_PENDING); } static struct key_update *key_update_find(bool app_key, u16_t key_idx, @@ -1449,7 +1442,7 @@ void bt_mesh_store_subnet(struct bt_mesh_subnet *sub) update = key_update_find(false, sub->net_idx, &free_slot); if (update) { update->clear = 0; - schedule_store(BT_MESH_KEYS_PENDING); + schedule_store(BLE_MESH_KEYS_PENDING); return; } @@ -1463,7 +1456,7 @@ void bt_mesh_store_subnet(struct bt_mesh_subnet *sub) free_slot->app_key = 0; free_slot->clear = 0; - schedule_store(BT_MESH_KEYS_PENDING); + schedule_store(BLE_MESH_KEYS_PENDING); } void bt_mesh_store_app_key(struct bt_mesh_app_key *key) @@ -1475,7 +1468,7 @@ void bt_mesh_store_app_key(struct bt_mesh_app_key *key) update = key_update_find(true, key->app_idx, &free_slot); if (update) { update->clear = 0; - schedule_store(BT_MESH_KEYS_PENDING); + schedule_store(BLE_MESH_KEYS_PENDING); return; } @@ -1489,24 +1482,24 @@ void bt_mesh_store_app_key(struct bt_mesh_app_key *key) free_slot->app_key = 1; free_slot->clear = 0; - schedule_store(BT_MESH_KEYS_PENDING); + schedule_store(BLE_MESH_KEYS_PENDING); } void bt_mesh_store_hb_pub(void) { - schedule_store(BT_MESH_HB_PUB_PENDING); + schedule_store(BLE_MESH_HB_PUB_PENDING); } void bt_mesh_store_cfg(void) { - schedule_store(BT_MESH_CFG_PENDING); + schedule_store(BLE_MESH_CFG_PENDING); } void bt_mesh_clear_net(void) { - schedule_store(BT_MESH_NET_PENDING); - schedule_store(BT_MESH_IV_PENDING); - schedule_store(BT_MESH_CFG_PENDING); + schedule_store(BLE_MESH_NET_PENDING); + schedule_store(BLE_MESH_IV_PENDING); + schedule_store(BLE_MESH_CFG_PENDING); } void bt_mesh_clear_subnet(struct bt_mesh_subnet *sub) @@ -1518,7 +1511,7 @@ void bt_mesh_clear_subnet(struct bt_mesh_subnet *sub) update = key_update_find(false, sub->net_idx, &free_slot); if (update) { update->clear = 1; - schedule_store(BT_MESH_KEYS_PENDING); + schedule_store(BLE_MESH_KEYS_PENDING); return; } @@ -1532,7 +1525,7 @@ void bt_mesh_clear_subnet(struct bt_mesh_subnet *sub) free_slot->app_key = 0; free_slot->clear = 1; - schedule_store(BT_MESH_KEYS_PENDING); + schedule_store(BLE_MESH_KEYS_PENDING); } void bt_mesh_clear_app_key(struct bt_mesh_app_key *key) @@ -1544,7 +1537,7 @@ void bt_mesh_clear_app_key(struct bt_mesh_app_key *key) update = key_update_find(true, key->app_idx, &free_slot); if (update) { update->clear = 1; - schedule_store(BT_MESH_KEYS_PENDING); + schedule_store(BLE_MESH_KEYS_PENDING); return; } @@ -1558,59 +1551,59 @@ void bt_mesh_clear_app_key(struct bt_mesh_app_key *key) free_slot->app_key = 1; free_slot->clear = 1; - schedule_store(BT_MESH_KEYS_PENDING); + schedule_store(BLE_MESH_KEYS_PENDING); } void bt_mesh_clear_rpl(void) { - schedule_store(BT_MESH_RPL_PENDING); + schedule_store(BLE_MESH_RPL_PENDING); } void bt_mesh_store_mod_bind(struct bt_mesh_model *mod) { - mod->flags |= BT_MESH_MOD_BIND_PENDING; - schedule_store(BT_MESH_MOD_PENDING); + mod->flags |= BLE_MESH_MOD_BIND_PENDING; + schedule_store(BLE_MESH_MOD_PENDING); } void bt_mesh_store_mod_sub(struct bt_mesh_model *mod) { - mod->flags |= BT_MESH_MOD_SUB_PENDING; - schedule_store(BT_MESH_MOD_PENDING); + mod->flags |= BLE_MESH_MOD_SUB_PENDING; + schedule_store(BLE_MESH_MOD_PENDING); } void bt_mesh_store_mod_pub(struct bt_mesh_model *mod) { - mod->flags |= BT_MESH_MOD_PUB_PENDING; - schedule_store(BT_MESH_MOD_PENDING); + mod->flags |= BLE_MESH_MOD_PUB_PENDING; + schedule_store(BLE_MESH_MOD_PENDING); } int bt_mesh_settings_init(void) { - k_delayed_work_init(&pending_store, store_pending); - int err; - BT_DBG(""); + BT_DBG("%s", __func__); + + k_delayed_work_init(&pending_store, store_pending); err = settings_subsys_init(); if (err) { - BT_ERR("settings_subsys_init failed (err %d)", err); + BT_ERR("%s, Failed to init settings (err %d)", __func__, err); return err; } err = settings_register(&mesh); if (err) { - BT_ERR("settings_register failed (err %d)", err); + BT_ERR("%s, Failed to register settings (err %d)", __func__, err); return err; } err = settings_load(); if (err) { - BT_ERR("settings load failed (err %d)", err); + BT_ERR("%s, Failed to load settings (err %d)", __func__, err); return err; } return 0; } -#endif /* CONFIG_BT_MESH_SETTINGS */ +#endif /* CONFIG_BLE_MESH_SETTINGS */ diff --git a/components/bt/ble_mesh/mesh_core/settings.h b/components/bt/ble_mesh/mesh_core/settings.h new file mode 100644 index 0000000000..5b0be18103 --- /dev/null +++ b/components/bt/ble_mesh/mesh_core/settings.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2018 Intel Corporation + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef _SETTINGS_H_ +#define _SETTINGS_H_ + +#include "sdkconfig.h" + +#include "net.h" +#include "mesh_access.h" +#include "mesh_bearer_adapt.h" + +void bt_mesh_store_net(void); +void bt_mesh_store_iv(void); +void bt_mesh_store_seq(void); +void bt_mesh_store_rpl(struct bt_mesh_rpl *rpl); +void bt_mesh_store_subnet(struct bt_mesh_subnet *sub); +void bt_mesh_store_app_key(struct bt_mesh_app_key *key); +void bt_mesh_store_hb_pub(void); +void bt_mesh_store_cfg(void); +void bt_mesh_store_mod_bind(struct bt_mesh_model *mod); +void bt_mesh_store_mod_sub(struct bt_mesh_model *mod); +void bt_mesh_store_mod_pub(struct bt_mesh_model *mod); + +void bt_mesh_clear_net(void); +void bt_mesh_clear_subnet(struct bt_mesh_subnet *sub); +void bt_mesh_clear_app_key(struct bt_mesh_app_key *key); +void bt_mesh_clear_rpl(void); + +int bt_mesh_settings_init(void); + +#endif /* _SETTINGS_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/settings/include/fcb.h b/components/bt/ble_mesh/mesh_core/settings/include/fcb.h deleted file mode 100644 index a016d1dce9..0000000000 --- a/components/bt/ble_mesh/mesh_core/settings/include/fcb.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2017 Nordic Semiconductor ASA - * Copyright (c) 2015 Runtime Inc - * - * SPDX-License-Identifier: Apache-2.0 - */ -#ifndef __FCB_H_ -#define __FCB_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/* - * Flash circular buffer. - */ -#include -#include -#include "mesh_types.h" - - -#define FCB_MAX_LEN (CHAR_MAX | CHAR_MAX << 7) /* Max length of element */ - -/* - * Entry location is pointer to area (within fcb->f_sectors), and offset - * within that area. - */ -struct fcb_entry { - struct flash_sector *fe_sector; /* ptr to sector */ - /* within fcb->f_sectors */ - u32_t fe_elem_off; /* start of entry */ - u32_t fe_data_off; /* start of data */ - u16_t fe_data_len; /* size of data area */ -}; - -/* - * Helper macro for calculate the data offset related to - * the fcb flash_area start offset. - */ -#define FCB_ENTRY_FA_DATA_OFF(entry) (entry.fe_sector->fs_off +\ - entry.fe_data_off) - -struct fcb_entry_ctx { - struct fcb_entry loc; - const struct flash_area *fap; -}; - -struct fcb { - /* Caller of fcb_init fills this in */ - u32_t f_magic; /* As placed on the disk */ - u8_t f_version; /* Current version number of the data */ - u8_t f_sector_cnt; /* Number of elements in sector array */ - u8_t f_scratch_cnt; /* How many sectors should be kept empty */ - struct flash_sector *f_sectors; /* Array of sectors, */ - /* must be contiguous */ - - /* Flash circular buffer internal state */ - //struct k_mutex f_mtx; /* Locking for accessing the FCB data */ - struct flash_sector *f_oldest; - struct fcb_entry f_active; - u16_t f_active_id; - u8_t f_align; /* writes to flash have to aligned to this */ - - const struct flash_area *fap; /* Flash area used by the fcb instance */ - /* This can be transfer to FCB user */ -}; - -/* - * Error codes. - */ -#define FCB_OK 0 -#define FCB_ERR_ARGS -1 -#define FCB_ERR_FLASH -2 -#define FCB_ERR_NOVAR -3 -#define FCB_ERR_NOSPACE -4 -#define FCB_ERR_NOMEM -5 -#define FCB_ERR_CRC -6 -#define FCB_ERR_MAGIC -7 - -int fcb_init(int f_area_id, struct fcb *fcb); - -/* - * fcb_append() appends an entry to circular buffer. When writing the - * contents for the entry, use loc->fl_area and loc->fl_data_off with - * flash_area_write(). When you're finished, call fcb_append_finish() with - * loc as argument. - */ -int fcb_append(struct fcb *fcb, u16_t len, struct fcb_entry *loc); -int fcb_append_finish(struct fcb *fcb, struct fcb_entry *append_loc); - -/* - * Walk over all log entries in FCB, or entries in a given flash_area. - * cb gets called for every entry. If cb wants to stop the walk, it should - * return non-zero value. - * - * Entry data can be read using flash_area_read(), using - * loc->fe_area, loc->fe_data_off, and loc->fe_data_len as arguments. - */ -typedef int (*fcb_walk_cb)(struct fcb_entry_ctx *loc_ctx, void *arg); -int fcb_walk(struct fcb *fcb, struct flash_sector *sector, fcb_walk_cb cb, - void *cb_arg); -int fcb_getnext(struct fcb *fcb, struct fcb_entry *loc); - -/* - * Erases the data from oldest sector. - */ -int fcb_rotate(struct fcb *fcb); - -/* - * Start using the scratch block. - */ -int fcb_append_to_scratch(struct fcb *fcb); - -/* - * How many sectors are unused. - */ -int fcb_free_sector_cnt(struct fcb *fcb); - -/* - * Whether FCB has any data. - */ -int fcb_is_empty(struct fcb *fcb); - -/* - * Element at offset *entries* from last position (backwards). - */ -int fcb_offset_last_n(struct fcb *fcb, u8_t entries, - struct fcb_entry *last_n_entry); - -/* - * Clears FCB passed to it - */ -int fcb_clear(struct fcb *fcb); - -int fcb_flash_read(const struct fcb *fcb, const struct flash_sector *sector, - off_t off, void *dst, size_t len); -int fcb_flash_write(const struct fcb *fcb, const struct flash_sector *sector, - off_t off, const void *src, size_t len); - -#ifdef __cplusplus -} -#endif - -#endif /* __FCB_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/settings/include/settings.h b/components/bt/ble_mesh/mesh_core/settings/include/settings.h deleted file mode 100644 index 5ffe6bff7b..0000000000 --- a/components/bt/ble_mesh/mesh_core/settings/include/settings.h +++ /dev/null @@ -1,271 +0,0 @@ -/* - * Copyright (c) 2018 Nordic Semiconductor ASA - * Copyright (c) 2015 Runtime Inc - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef __SETTINGS_H_ -#define __SETTINGS_H_ - -#include - -#include "mesh_util.h" -#include "mesh_slist.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @defgroup settings Settings subsystem - * @{ - */ - -#define SETTINGS_MAX_DIR_DEPTH 8 /* max depth of settings tree */ -#define SETTINGS_MAX_NAME_LEN (8 * SETTINGS_MAX_DIR_DEPTH) -#define SETTINGS_MAX_VAL_LEN 256 -#define SETTINGS_NAME_SEPARATOR "/" - -/* pleace for settings additions: - * up to 7 separators, '=', '\0' - */ -#define SETTINGS_EXTRA_LEN ((SETTINGS_MAX_DIR_DEPTH - 1) + 2) - -#define SETTINGS_NMGR_OP 0 - -/** - * Type of settings value. - */ -enum settings_type { - SETTINGS_NONE = 0, - SETTINGS_INT8, - SETTINGS_INT16, - SETTINGS_INT32, - SETTINGS_INT64, - SETTINGS_STRING, - SETTINGS_BYTES, - SETTINGS_FLOAT, - SETTINGS_DOUBLE, - SETTINGS_BOOL, -} __attribute__((__packed__)); - -/** - * Parameter to commit handler describing where data is going to. - */ -enum settings_export_tgt { - SETTINGS_EXPORT_PERSIST, /* Value is to be persisted. */ - SETTINGS_EXPORT_SHOW /* Value is to be displayed. */ -}; - -/** - * @struct settings_handler - * Config handlers for subtree implement a set of handler functions. - * These are registered using a call to settings_register(). - * - * @param settings_handler::node Linked list node info for module internal usage. - * - * @param settings_handler::name Name of subtree. - * - * @param settings_handler::h_get Get values handler of settings items - * identified by keyword names.Parameters: - * - argc - count of item in argv. - * - argv - array of pointers to keyword names. - * - val - buffer for a value. - * - val_len_max - size of that buffer. - * - * @param settings_handler::h_set Sey value handler of settings items - * identified by keyword names. Parameters: - * - argc - count of item in argv, argv - array of pointers to keyword names. - * - val- pointer to value to be set. - * - * @param settings_handler::h_commit This handler gets called after settings - * has been loaded in full. User might use it to apply setting to - * the application. - * - * @param settings_handler::h_export This gets called to dump all current - * settings items. - * This happens when settings_save() tries to save the settings. Parameters: - * - tgt: indicates where data is going to. - * - Export_function: the pointer to the internal function which appends - * a single key-value pair to persisted settings. Don't store duplicated - * value. The name is subtree/key string, val is the string with - * value. - * - * @remarks The User might limit a implementations of handler to serving only - * one keyword at one call - what will impose limit to get/set values using full - * subtree/key name. - */ -struct settings_handler { - sys_snode_t node; - char *name; - char *(*h_get)(int argc, char **argv, char *val, int val_len_max); - int (*h_set)(int argc, char **argv, char *val); - int (*h_commit)(void); - int (*h_export)(int (*export_func)(const char *name, char *val), - enum settings_export_tgt tgt); -}; - -/** - * Initialization of settings and backend - * - * Can be called at application startup. - * In case the backend is NFFS Remember to call it after FS was mounted. - * For FCB backend it can be called without such a restriction. - * - * @return 0 on success, non-zero on failure. - */ -int settings_subsys_init(void); - -/** - * Register a handler for settings items. - * - * @param cf Structure containing registration info. - * - * @return 0 on success, non-zero on failure. - */ -int settings_register(struct settings_handler *cf); - -/** - * Load serialized items from registered persistence sources. Handlers for - * serialized item subtrees registered earlier will be called for encountered - * values. - * - * @return 0 on success, non-zero on failure. - */ -int settings_load(void); - -/** - * Save currently running serialized items. All serialized items which are different - * from currently persisted values will be saved. - * - * @return 0 on success, non-zero on failure. - */ -int settings_save(void); - -/** - * Write a single serialized value to persisted storage (if it has - * changed value). - * - * @param name Name/key of the settings item. - * @param var Value of the settings item. - * - * @return 0 on success, non-zero on failure. - */ -int settings_save_one(const char *name, char *var); - -/** - * Set settings item identified by @p name to be value @p val_str. - * This finds the settings handler for this subtree and calls it's - * set handler. - * - * @param name Name/key of the settings item. - * @param val_str Value of the settings item. - * - * @return 0 on success, non-zero on failure. - */ -int settings_set_value(char *name, char *val_str); - -/** - * Get value of settings item identified by @p name. - * This calls the settings handler h_get for the subtree. - * - * Configuration handler can copy the string to @p buf, the maximum - * number of bytes it will copy is limited by @p buf_len. - * - * @param name Name/key of the settings item. - * - * @param buf buffer for value of the settings item. - * If value is not string, the value will be filled in *buf. - * - * @param buf_len size of buf. - * - * @return value will be pointer to beginning of the buf, - * except for string it will pointer to beginning of string source. - */ -char *settings_get_value(char *name, char *buf, int buf_len); - -/** - * Call commit for all settings handler. This should apply all - * settings which has been set, but not applied yet. - * - * @param name Name of the settings subtree, or NULL to commit everything. - * - * @return 0 on success, non-zero on failure. - */ -int settings_commit(char *name); - -/** - * Convenience routine for converting value passed as a string to native - * data type. - * - * @param val_str Value of the settings item as string. - * @param type Type of the value to convert to. - * @param vp Pointer to variable to fill with the decoded value. - * @param maxlen the vp buffer size. - * - * @return 0 on success, non-zero on failure. - */ -int settings_value_from_str(char *val_str, enum settings_type type, void *vp, - int maxlen); - -/** - * Convenience routine for converting byte array passed as a base64 - * encoded string. - * - * @param val_str Value of the settings item as string. - * @param vp Pointer to variable to fill with the decoded value. - * @param len Size of that variable. On return the number of bytes in the array. - * - * @return 0 on success, non-zero on failure. - */ -int settings_bytes_from_str(char *val_str, void *vp, int *len); - -/** - * Convenience routine for converting native data type to a string. - * - * @param type Type of the value to convert from. - * @param vp Pointer to variable to convert. - * @param buf Buffer where string value will be stored. - * @param buf_len Size of the buffer. - * - * @return 0 on success, non-zero on failure. - */ -char *settings_str_from_value(enum settings_type type, void *vp, char *buf, - int buf_len); -#define SETTINGS_STR_FROM_BYTES_LEN(len) (((len) * 4 / 3) + 4) - -/** - * Convenience routine for converting byte array into a base64 - * encoded string. - * - * @param vp Pointer to variable to convert. - * @param vp_len Number of bytes to convert. - * @param buf Buffer where string value will be stored. - * @param buf_len Size of the buffer. - * - * @return 0 on success, non-zero on failure. - */ -char *settings_str_from_bytes(void *vp, int vp_len, char *buf, int buf_len); - -#define SETTINGS_VALUE_SET(str, type, val) \ - settings_value_from_str((str), (type), &(val), sizeof(val)) - -/** - * @} settings - */ - -/* - * Config storage - */ -struct settings_store_itf; -struct settings_store { - sys_snode_t cs_next; - const struct settings_store_itf *cs_itf; -}; - -#ifdef __cplusplus -} -#endif - -#endif /* __SETTINGS_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/settings/include/settings_act.h b/components/bt/ble_mesh/mesh_core/settings/include/settings_act.h new file mode 100644 index 0000000000..babe3a72d6 --- /dev/null +++ b/components/bt/ble_mesh/mesh_core/settings/include/settings_act.h @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2018 Nordic Semiconductor ASA + * Copyright (c) 2015 Runtime Inc + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef _BLE_MESH_SETTINGS_H_ +#define _BLE_MESH_SETTINGS_H_ + +#include + +#include "mesh_util.h" +#include "mesh_slist.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define SETTINGS_MAX_DIR_DEPTH 8 /* max depth of settings tree */ +#define SETTINGS_MAX_NAME_LEN (8 * SETTINGS_MAX_DIR_DEPTH) +#define SETTINGS_MAX_VAL_LEN 256 +#define SETTINGS_NAME_SEPARATOR "/" + +/* pleace for settings additions: + * up to 7 separators, '=', '\0' + */ +#define SETTINGS_EXTRA_LEN ((SETTINGS_MAX_DIR_DEPTH - 1) + 2) + +/** + * @struct settings_handler + * Config handlers for subtree implement a set of handler functions. + * These are registered using a call to settings_register(). + * + * @param settings_handler::node Linked list node info for module internal usage. + * + * @param settings_handler::name Name of subtree. + * + * @param settings_handler::h_set Sey value handler of settings items + * identified by keyword names. Parameters: + * - argc - count of item in argv, argv - array of pointers to keyword names. + * - val- pointer to value to be set. + * + * @param settings_handler::h_commit This handler gets called after settings + * has been loaded in full. User might use it to apply setting to + * the application. + * + * @remarks The User might limit a implementations of handler to serving only + * one keyword at one call - what will impose limit to get/set values using full + * subtree/key name. + */ +struct settings_handler { + sys_snode_t node; + char *name; + int (*h_set)(int argc, char **argv, char *val); + int (*h_commit)(void); +}; + +/** + * Initialization of settings and backend + * + * Can be called at application startup. + * In case the backend is NFFS Remember to call it after FS was mounted. + * For FCB backend it can be called without such a restriction. + * + * @return 0 on success, non-zero on failure. + */ +int settings_subsys_init(void); + +/** + * Register a handler for settings items. + * + * @param cf Structure containing registration info. + * + * @return 0 on success, non-zero on failure. + */ +int settings_register(struct settings_handler *cf); + +/** + * Load serialized items from registered persistence sources. Handlers for + * serialized item subtrees registered earlier will be called for encountered + * values. + * + * @return 0 on success, non-zero on failure. + */ +int settings_load(void); + +/** + * Write a single serialized value to persisted storage (if it has + * changed value). + * + * @param name Name/key of the settings item. + * @param var Value of the settings item. + * + * @return 0 on success, non-zero on failure. + */ +int settings_save_one(const char *name, char *var); + +/** + * Set settings item identified by @p name to be value @p val_str. + * This finds the settings handler for this subtree and calls it's + * set handler. + * + * @param name Name/key of the settings item. + * @param val_str Value of the settings item. + * + * @return 0 on success, non-zero on failure. + */ +int settings_set_value(char *name, char *val_str); + +/** + * Call commit for all settings handler. This should apply all + * settings which has been set, but not applied yet. + * + * @return 0 on success, non-zero on failure. + */ +int settings_commit(void); + +/** + * Convenience routine for converting byte array passed as a base64 + * encoded string. + * + * @param val_str Value of the settings item as string. + * @param vp Pointer to variable to fill with the decoded value. + * @param len Size of that variable. On return the number of bytes in the array. + * + * @return 0 on success, non-zero on failure. + */ +int settings_bytes_from_str(char *val_str, void *vp, int *len); + +/** + * Convenience routine for converting byte array into a base64 + * encoded string. + * + * @param vp Pointer to variable to convert. + * @param vp_len Number of bytes to convert. + * @param buf Buffer where string value will be stored. + * @param buf_len Size of the buffer. + * + * @return 0 on success, non-zero on failure. + */ +char *settings_str_from_bytes(void *vp, int vp_len, char *buf, int buf_len); + +struct settings_store_itf; +struct settings_store { + sys_snode_t cs_next; + const struct settings_store_itf *cs_itf; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* _BLE_MESH_SETTINGS_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/include/base64.h b/components/bt/ble_mesh/mesh_core/settings/include/settings_base64.h similarity index 92% rename from components/bt/ble_mesh/mesh_core/include/base64.h rename to components/bt/ble_mesh/mesh_core/settings/include/settings_base64.h index 76ded32875..31c41e694a 100644 --- a/components/bt/ble_mesh/mesh_core/include/base64.h +++ b/components/bt/ble_mesh/mesh_core/settings/include/settings_base64.h @@ -21,8 +21,8 @@ * - Removed mbedtls_ prefixes * - Reworked coding style */ -#ifndef __BASE64_H__ -#define __BASE64_H__ +#ifndef _BLE_MESH_BASE64_H_ +#define _BLE_MESH_BASE64_H_ #include #include "mesh_types.h" @@ -31,6 +31,9 @@ extern "C" { #endif +/* Base64-encoded string buffer size of in_size bytes */ +#define BASE64_ENCODE_SIZE(in_size) ((((((in_size) - 1) / 3) * 4) + 4) + 1) + /** * @brief Encode a buffer into base64 format * @@ -76,4 +79,4 @@ int base64_decode(u8_t *dst, size_t dlen, size_t *olen, const u8_t *src, } #endif -#endif /* __BASE64_H__ */ +#endif /* _BLE_MESH_BASE64_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/settings/include/settings_fcb.h b/components/bt/ble_mesh/mesh_core/settings/include/settings_fcb.h index 2ae1228288..07858cea6e 100644 --- a/components/bt/ble_mesh/mesh_core/settings/include/settings_fcb.h +++ b/components/bt/ble_mesh/mesh_core/settings/include/settings_fcb.h @@ -5,11 +5,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef __SETTINGS_FCB_H_ -#define __SETTINGS_FCB_H_ +#ifndef _BLE_MESH_SETTINGS_FCB_H_ +#define _BLE_MESH_SETTINGS_FCB_H_ #include "nvs.h" -#include "include/settings.h" #ifdef __cplusplus extern "C" { @@ -17,7 +16,6 @@ extern "C" { struct settings_fcb { struct settings_store cf_store; - const char *file_name; nvs_handle handle; }; @@ -27,13 +25,10 @@ struct settings_dup_check_arg { int is_dup; }; -extern int settings_fcb_src(struct settings_fcb *cf); -extern int settings_fcb_dst(struct settings_fcb *cf); - int csi_load_check(struct settings_dup_check_arg *cdca); #ifdef __cplusplus } #endif -#endif /* __SETTINGS_FCB_H_ */ +#endif /* _BLE_MESH_SETTINGS_FCB_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/settings/include/settings_file.h b/components/bt/ble_mesh/mesh_core/settings/include/settings_file.h deleted file mode 100644 index a41ca143fa..0000000000 --- a/components/bt/ble_mesh/mesh_core/settings/include/settings_file.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2018 Nordic Semiconductor ASA - * Copyright (c) 2015 Runtime Inc - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef __SETTINGS_FILE_H_ -#define __SETTINGS_FILE_H_ - -#include "settings/settings.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define SETTINGS_FILE_NAME_MAX 32 /* max length for settings filename */ - -struct settings_file { - struct settings_store cf_store; - const char *cf_name; /* filename */ - int cf_maxlines; /* max # of lines before compressing */ - int cf_lines; /* private */ -}; - -/* register file to be source of settings */ -int settings_file_src(struct settings_file *cf); - -/* settings saves go to a file */ -int settings_file_dst(struct settings_file *cf); - -#ifdef __cplusplus -} -#endif - -#endif /* __SETTINGS_FILE_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/settings/include/settings_priv.h b/components/bt/ble_mesh/mesh_core/settings/include/settings_priv.h index 875066d4aa..dcc54abc35 100644 --- a/components/bt/ble_mesh/mesh_core/settings/include/settings_priv.h +++ b/components/bt/ble_mesh/mesh_core/settings/include/settings_priv.h @@ -5,46 +5,27 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef __SETTINGS_PRIV_H_ -#define __SETTINGS_PRIV_H_ +#ifndef _BLE_MESH_SETTINGS_PRIV_H_ +#define _BLE_MESH_SETTINGS_PRIV_H_ #ifdef __cplusplus extern "C" { #endif -int settings_cli_register(void); -int settings_nmgr_register(void); - -struct mgmt_cbuf; -int settings_cbor_line(struct mgmt_cbuf *cb, char *name, int nlen, char *value, - int vlen); - int settings_line_parse(char *buf, char **namep, char **valp); int settings_line_make(char *dst, int dlen, const char *name, const char *val); -int settings_line_make2(char *dst, int dlen, const char *name, - const char *value); -/* - * API for config storage. - */ typedef void (*load_cb)(char *name, char *val, void *cb_arg); struct settings_store_itf { int (*csi_load)(struct settings_store *cs, load_cb cb, void *cb_arg); - int (*csi_save_start)(struct settings_store *cs); - int (*csi_save)(struct settings_store *cs, const char *name, - const char *value); - int (*csi_save_end)(struct settings_store *cs); + int (*csi_save)(struct settings_store *cs, const char *name, const char *value); }; void settings_src_register(struct settings_store *cs); void settings_dst_register(struct settings_store *cs); -extern sys_slist_t settings_load_srcs; -extern sys_slist_t settings_handlers; -extern struct settings_store *settings_save_dst; - #ifdef __cplusplus } #endif -#endif /* __SETTINGS_PRIV_H_ */ +#endif /* _BLE_MESH_SETTINGS_PRIV_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/settings/settings.c b/components/bt/ble_mesh/mesh_core/settings/settings.c deleted file mode 100644 index 382b55d235..0000000000 --- a/components/bt/ble_mesh/mesh_core/settings/settings.c +++ /dev/null @@ -1,396 +0,0 @@ -/* - * Copyright (c) 2018 Nordic Semiconductor ASA - * Copyright (c) 2015 Runtime Inc - * - * SPDX-License-Identifier: Apache-2.0 - */ -#include -#include -#include -#include -#include - -#include "sdkconfig.h" - -#include "mesh_types.h" -#include "base64.h" -#include "settings/include/settings.h" -#include "settings/include/settings_priv.h" - -#if CONFIG_BT_MESH_SETTINGS - -/* mbedtls-base64 lib encodes data to null-terminated string */ -#define BASE64_ENCODE_SIZE(in_size) ((((((in_size) - 1) / 3) * 4) + 4) + 1) - -sys_slist_t settings_handlers; - -static u8_t settings_cmd_inited; - -void settings_store_init(void); -static void s64_to_dec(char *ptr, int buf_len, s64_t value, int base); -static s64_t dec_to_s64(char *p_str, char **e_ptr); - -void settings_init(void) -{ - if (!settings_cmd_inited) { - sys_slist_init(&settings_handlers); - settings_store_init(); - - settings_cmd_inited = 1; - } -} - -int settings_register(struct settings_handler *handler) -{ - sys_slist_prepend(&settings_handlers, &handler->node); - return 0; -} - -/* - * Find settings_handler based on name. - */ -struct settings_handler *settings_handler_lookup(char *name) -{ - struct settings_handler *ch; - - SYS_SLIST_FOR_EACH_CONTAINER(&settings_handlers, ch, node) { - BT_DBG("%s, name = %s, ch->name = %s", __func__, name, ch->name); - if (!strcmp(name, ch->name)) { - return ch; - } - } - return NULL; -} - -/* - * Separate string into argv array. - */ -int settings_parse_name(char *name, int *name_argc, char *name_argv[]) -{ - int i = 0; - - while (name) { - name_argv[i++] = name; - - while (1) { - if (*name == '\0') { - name = NULL; - break; - } - - if (*name == *SETTINGS_NAME_SEPARATOR) { - *name = '\0'; - name++; - break; - } - name++; - } - } - - *name_argc = i; - - return 0; -} - -static struct settings_handler *settings_parse_and_lookup(char *name, - int *name_argc, - char *name_argv[]) -{ - int rc; - - rc = settings_parse_name(name, name_argc, name_argv); - if (rc) { - BT_ERR("settings_parse_name fail"); - return NULL; - } - return settings_handler_lookup(name_argv[0]); -} - -int settings_value_from_str(char *val_str, enum settings_type type, void *vp, - int maxlen) -{ - s32_t val; - s64_t val64; - char *eptr; - - if (!val_str) { - goto err; - } - switch (type) { - case SETTINGS_INT8: - case SETTINGS_INT16: - case SETTINGS_INT32: - case SETTINGS_BOOL: - val = strtol(val_str, &eptr, 0); - if (*eptr != '\0') { - goto err; - } - if (type == SETTINGS_BOOL) { - if (val < 0 || val > 1) { - goto err; - } - *(bool *)vp = val; - } else if (type == SETTINGS_INT8) { - if (val < INT8_MIN || val > UINT8_MAX) { - goto err; - } - *(int8_t *)vp = val; - } else if (type == SETTINGS_INT16) { - if (val < INT16_MIN || val > UINT16_MAX) { - goto err; - } - *(int16_t *)vp = val; - } else if (type == SETTINGS_INT32) { - *(s32_t *)vp = val; - } - break; - case SETTINGS_INT64: - val64 = dec_to_s64(val_str, &eptr); - if (*eptr != '\0') { - goto err; - } - *(s64_t *)vp = val64; - break; - case SETTINGS_STRING: - val = strlen(val_str); - if (val + 1 > maxlen) { - goto err; - } - strcpy(vp, val_str); - break; - default: - goto err; - } - return 0; -err: - return -EINVAL; -} - -int settings_bytes_from_str(char *val_str, void *vp, int *len) -{ - int err; - size_t rc; - - err = base64_decode(vp, *len, &rc, (const u8_t *)val_str, strlen(val_str)); - - if (err) { - return -1; - } - - *len = rc; - return 0; -} - -char *settings_str_from_value(enum settings_type type, void *vp, char *buf, - int buf_len) -{ - s32_t val; - - if (type == SETTINGS_STRING) { - return vp; - } - switch (type) { - case SETTINGS_INT8: - case SETTINGS_INT16: - case SETTINGS_INT32: - case SETTINGS_BOOL: - if (type == SETTINGS_BOOL) { - val = *(bool *)vp; - } else if (type == SETTINGS_INT8) { - val = *(int8_t *)vp; - } else if (type == SETTINGS_INT16) { - val = *(int16_t *)vp; - } else { - val = *(s32_t *)vp; - } - snprintf(buf, buf_len, "%ld", (long)val); - return buf; - case SETTINGS_INT64: - s64_to_dec(buf, buf_len, *(s64_t *)vp, 10); - return buf; - default: - return NULL; - } -} - -static void u64_to_dec(char *ptr, int buf_len, u64_t value, int base) -{ - u64_t t = 0, res = 0; - u64_t tmp = value; - int count = 0; - - if (ptr == NULL) { - return; - } - - if (tmp == 0) { - count++; - } - - while (tmp > 0) { - tmp = tmp / base; - count++; - } - - ptr += count; - - *ptr = '\0'; - - do { - res = value - base * (t = value / base); - if (res < 10) { - *--ptr = '0' + res; - } else if ((res >= 10) && (res < 16)) { - *--ptr = 'A' - 10 + res; - } - value = t; - } while (value != 0); -} - -static void s64_to_dec(char *ptr, int buf_len, s64_t value, int base) -{ - u64_t val64; - - if (ptr == NULL || buf_len < 1) { - return; - } - - if (value < 0) { - *ptr = '-'; - ptr++; - buf_len--; - val64 = value * (-1); - } else { - val64 = value; - } - - u64_to_dec(ptr, buf_len, val64, base); -} - -static s64_t dec_to_s64(char *p_str, char **e_ptr) -{ - u64_t val = 0, prev_val = 0; - bool neg = false; - int digit; - - if (*p_str == '-') { - neg = true; - p_str++; - } else if (*p_str == '+') { - p_str++; - } - - while (1) { - if (*p_str >= '0' && *p_str <= '9') { - digit = *p_str - '0'; - } else { - break; - } - - val *= 10; - val += digit; - - /* this is only a fuse */ - if (val < prev_val) { - break; - } - - prev_val = val; - p_str++; - } - - if (e_ptr != 0) { - *e_ptr = p_str; - } - - if (neg) { - return -val; - } else { - return val; - } -} - -char *settings_str_from_bytes(void *vp, int vp_len, char *buf, int buf_len) -{ - if (BASE64_ENCODE_SIZE(vp_len) > buf_len) { - return NULL; - } - - size_t enc_len; - - base64_encode((u8_t *)buf, buf_len, &enc_len, vp, vp_len); - - return buf; -} - -int settings_set_value(char *name, char *val_str) -{ - int name_argc; - char *name_argv[SETTINGS_MAX_DIR_DEPTH]; - struct settings_handler *ch; - - ch = settings_parse_and_lookup(name, &name_argc, name_argv); - if (!ch) { - BT_ERR("settings_parse_and_lookup fail."); - return -EINVAL; - } - - return ch->h_set(name_argc - 1, &name_argv[1], val_str); -} - -/* - * Get value in printable string form. If value is not string, the value - * will be filled in *buf. - * Return value will be pointer to beginning of that buffer, - * except for string it will pointer to beginning of string. - */ -char *settings_get_value(char *name, char *buf, int buf_len) -{ - int name_argc; - char *name_argv[SETTINGS_MAX_DIR_DEPTH]; - struct settings_handler *ch; - - ch = settings_parse_and_lookup(name, &name_argc, name_argv); - if (!ch) { - return NULL; - } - - if (!ch->h_get) { - return NULL; - } - return ch->h_get(name_argc - 1, &name_argv[1], buf, buf_len); -} - -int settings_commit(char *name) -{ - int name_argc; - char *name_argv[SETTINGS_MAX_DIR_DEPTH]; - struct settings_handler *ch; - int rc; - int rc2; - - if (name) { - ch = settings_parse_and_lookup(name, &name_argc, name_argv); - if (!ch) { - return -EINVAL; - } - if (ch->h_commit) { - return ch->h_commit(); - } else { - return 0; - } - } else { - rc = 0; - SYS_SLIST_FOR_EACH_CONTAINER(&settings_handlers, ch, node) { - if (ch->h_commit) { - rc2 = ch->h_commit(); - if (!rc) { - rc = rc2; - } - } - } - return rc; - } -} - -#endif /* CONFIG_BT_MESH_SETTINGS */ diff --git a/components/bt/ble_mesh/mesh_core/settings/settings_act.c b/components/bt/ble_mesh/mesh_core/settings/settings_act.c new file mode 100644 index 0000000000..688a7c6707 --- /dev/null +++ b/components/bt/ble_mesh/mesh_core/settings/settings_act.c @@ -0,0 +1,155 @@ +/* + * Copyright (c) 2018 Nordic Semiconductor ASA + * Copyright (c) 2015 Runtime Inc + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include +#include +#include +#include + +#include "sdkconfig.h" + +#include "mesh_types.h" + +#include "settings_base64.h" +#include "settings_act.h" +#include "settings_priv.h" + +#if CONFIG_BLE_MESH_SETTINGS + +static sys_slist_t settings_handlers; + +extern void settings_store_init(void); + +void settings_init(void) +{ + sys_slist_init(&settings_handlers); + settings_store_init(); +} + +int settings_register(struct settings_handler *handler) +{ + sys_slist_prepend(&settings_handlers, &handler->node); + return 0; +} + +/* Find settings_handler based on name. */ +static struct settings_handler *settings_handler_lookup(char *name) +{ + struct settings_handler *ch; + + SYS_SLIST_FOR_EACH_CONTAINER(&settings_handlers, ch, node) { + BT_DBG("%s, name = %s, ch->name = %s", __func__, name, ch->name); + if (!strcmp(name, ch->name)) { + return ch; + } + } + return NULL; +} + +/* Separate string into argv array. */ +static int settings_parse_name(char *name, int *name_argc, char *name_argv[]) +{ + int i = 0; + + while (name) { + name_argv[i++] = name; + + while (1) { + if (*name == '\0') { + name = NULL; + break; + } + + if (*name == *SETTINGS_NAME_SEPARATOR) { + *name = '\0'; + name++; + break; + } + name++; + } + } + + *name_argc = i; + + return 0; +} + +static struct settings_handler *settings_parse_and_lookup(char *name, + int *name_argc, char *name_argv[]) +{ + int rc; + + rc = settings_parse_name(name, name_argc, name_argv); + if (rc) { + BT_ERR("%s, Failed to parse settings name", __func__); + return NULL; + } + return settings_handler_lookup(name_argv[0]); +} + +int settings_bytes_from_str(char *val_str, void *vp, int *len) +{ + size_t rc; + int err; + + err = base64_decode(vp, *len, &rc, (const u8_t *)val_str, strlen(val_str)); + + if (err) { + return -1; + } + + *len = rc; + return 0; +} + +char *settings_str_from_bytes(void *vp, int vp_len, char *buf, int buf_len) +{ + size_t enc_len; + + if (BASE64_ENCODE_SIZE(vp_len) > buf_len) { + return NULL; + } + + base64_encode((u8_t *)buf, buf_len, &enc_len, vp, vp_len); + + return buf; +} + +int settings_set_value(char *name, char *val_str) +{ + char *name_argv[SETTINGS_MAX_DIR_DEPTH]; + struct settings_handler *ch; + int name_argc; + + ch = settings_parse_and_lookup(name, &name_argc, name_argv); + if (!ch) { + BT_ERR("%s, Failed to parse & lookup settings", __func__); + return -EINVAL; + } + + return ch->h_set(name_argc - 1, &name_argv[1], val_str); +} + +int settings_commit(void) +{ + struct settings_handler *ch; + int rc2 = 0; + int rc = 0; + + SYS_SLIST_FOR_EACH_CONTAINER(&settings_handlers, ch, node) { + if (ch->h_commit) { + rc2 = ch->h_commit(); + if (!rc) { + rc = rc2; + } + } + } + + return rc; +} + +#endif /* CONFIG_BLE_MESH_SETTINGS */ diff --git a/components/bt/ble_mesh/mesh_core/base64.c b/components/bt/ble_mesh/mesh_core/settings/settings_base64.c similarity index 96% rename from components/bt/ble_mesh/mesh_core/base64.c rename to components/bt/ble_mesh/mesh_core/settings/settings_base64.c index 83748f56b2..95a4459e2b 100644 --- a/components/bt/ble_mesh/mesh_core/base64.c +++ b/components/bt/ble_mesh/mesh_core/settings/settings_base64.c @@ -24,7 +24,8 @@ #include #include -#include + +#include "settings_base64.h" static const u8_t base64_enc_map[64] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', @@ -54,14 +55,11 @@ static const u8_t base64_dec_map[128] = { #define BASE64_SIZE_T_MAX ((size_t) -1) /* SIZE_T_MAX is not standard */ -/* - * Encode a buffer into base64 format - */ -int base64_encode(u8_t *dst, size_t dlen, size_t *olen, const u8_t *src, - size_t slen) +/* Encode a buffer into base64 format */ +int base64_encode(u8_t *dst, size_t dlen, size_t *olen, const u8_t *src, size_t slen) { - size_t i, n; int C1, C2, C3; + size_t i, n; u8_t *p; if (slen == 0) { @@ -118,11 +116,8 @@ int base64_encode(u8_t *dst, size_t dlen, size_t *olen, const u8_t *src, return 0; } -/* - * Decode a base64-formatted buffer - */ -int base64_decode(u8_t *dst, size_t dlen, size_t *olen, const u8_t *src, - size_t slen) +/* Decode a base64-formatted buffer */ +int base64_decode(u8_t *dst, size_t dlen, size_t *olen, const u8_t *src, size_t slen) { size_t i, n; u32_t j, x; diff --git a/components/bt/ble_mesh/mesh_core/settings/settings_fcb.c b/components/bt/ble_mesh/mesh_core/settings/settings_fcb.c index 0f965f5857..221731b348 100644 --- a/components/bt/ble_mesh/mesh_core/settings/settings_fcb.c +++ b/components/bt/ble_mesh/mesh_core/settings/settings_fcb.c @@ -5,35 +5,32 @@ * SPDX-License-Identifier: Apache-2.0 */ -#include #include +#include #include "sdkconfig.h" #include "nvs.h" -#include "settings/include/settings.h" -#include "settings/include/settings_fcb.h" -#include "settings/include/settings_priv.h" +#include "settings_act.h" +#include "settings_fcb.h" +#include "settings_priv.h" -#if CONFIG_BT_MESH_SETTINGS +#if CONFIG_BLE_MESH_SETTINGS -#define SETTINGS_FCB_VERS 1 -#define KEY_BUF_LEN_MAX 1024 +#define KEY_BUF_LEN_MAX 1024 -static int buf_len = 0; -static const char *BLE_MESH_FCB_NVS_KEY = "fcb_nvs_key"; -static const char *BLE_MESH_FCB_FILE_NAME = "fcb_nvs_file"; +static const char *BLE_MESH_FCB_FILE_NAME = "bt_mesh_nvs"; +static const char *BLE_MESH_FCB_NVS_KEY = "bt_mesh_key"; static char key_buf[KEY_BUF_LEN_MAX]; +static int buf_len; struct settings_fcb_load_cb_arg { load_cb cb; void *cb_arg; }; -static int settings_fcb_load(struct settings_store *cs, load_cb cb, - void *cb_arg); -static int settings_fcb_save(struct settings_store *cs, const char *name, - const char *value); +static int settings_fcb_load(struct settings_store *cs, load_cb cb, void *cb_arg); +static int settings_fcb_save(struct settings_store *cs, const char *name, const char *value); static struct settings_store_itf settings_fcb_itf = { .csi_load = settings_fcb_load, @@ -42,13 +39,13 @@ static struct settings_store_itf settings_fcb_itf = { int settings_fcb_src(struct settings_fcb *cf) { - cf->file_name = BLE_MESH_FCB_FILE_NAME; if (nvs_open(BLE_MESH_FCB_FILE_NAME, NVS_READWRITE, &cf->handle) != ESP_OK) { + BT_ERR("%s, Failed to open ble mesh nvs", __func__); return -1; } + cf->cf_store.cs_itf = &settings_fcb_itf; settings_src_register(&cf->cf_store); - return 0; } @@ -56,31 +53,27 @@ int settings_fcb_dst(struct settings_fcb *cf) { cf->cf_store.cs_itf = &settings_fcb_itf; settings_dst_register(&cf->cf_store); - return 0; } static int settings_fcb_load_cb(struct settings_fcb *cf, void *arg) { + char buf[SETTINGS_MAX_NAME_LEN + SETTINGS_MAX_VAL_LEN + SETTINGS_EXTRA_LEN]; struct settings_fcb_load_cb_arg *argp; - char buf[SETTINGS_MAX_NAME_LEN + SETTINGS_MAX_VAL_LEN + - SETTINGS_EXTRA_LEN]; + char *cp_start = key_buf; char *name_str; char *val_str; - int rc = 0; - size_t len = KEY_BUF_LEN_MAX; - char *cp_start = NULL; + size_t len; + int rc; argp = (struct settings_fcb_load_cb_arg *)arg; rc = nvs_get_blob(cf->handle, BLE_MESH_FCB_NVS_KEY, NULL, (size_t *)&buf_len); rc = nvs_get_blob(cf->handle, BLE_MESH_FCB_NVS_KEY, key_buf, (size_t *)&buf_len); - if (rc) { return 0; } - cp_start = key_buf; while (cp_start != NULL && *cp_start != '\0') { len = strlen(cp_start); if (len >= sizeof(buf)) { @@ -89,20 +82,22 @@ static int settings_fcb_load_cb(struct settings_fcb *cf, void *arg) memcpy(buf, cp_start, len); buf[len] = '\0'; - rc = settings_line_parse(buf, &name_str, &val_str); + rc = settings_line_parse(buf, &name_str, &val_str); if (rc) { return 0; } + BT_DBG("name_str = %s, val_str = %s", name_str, val_str); + argp->cb(name_str, val_str, argp->cb_arg); cp_start += (len + 1); } + return 0; } -static int settings_fcb_load(struct settings_store *cs, load_cb cb, - void *cb_arg) +static int settings_fcb_load(struct settings_store *cs, load_cb cb, void *cb_arg) { struct settings_fcb *cf = (struct settings_fcb *)cs; struct settings_fcb_load_cb_arg arg; @@ -120,11 +115,10 @@ static int settings_fcb_load(struct settings_store *cs, load_cb cb, static char *settings_link_buf(char *buf) { + int len = strlen(buf); - int blen = strlen(buf); - - memcpy(&key_buf[buf_len], buf, blen); - buf_len += blen; + memcpy(&key_buf[buf_len], buf, len); + buf_len += len; key_buf[buf_len++] = '\0'; @@ -134,9 +128,8 @@ static char *settings_link_buf(char *buf) static int settings_fcb_save(struct settings_store *cs, const char *name, const char *value) { + char buf[SETTINGS_MAX_NAME_LEN + SETTINGS_MAX_VAL_LEN + SETTINGS_EXTRA_LEN]; struct settings_fcb *cf = (struct settings_fcb *)cs; - char buf[SETTINGS_MAX_NAME_LEN + SETTINGS_MAX_VAL_LEN + - SETTINGS_EXTRA_LEN]; int len; if (!name) { @@ -148,17 +141,15 @@ static int settings_fcb_save(struct settings_store *cs, const char *name, return -EINVAL; } - settings_link_buf(buf); - return nvs_set_blob(cf->handle, BLE_MESH_FCB_NVS_KEY, (void *)key_buf, buf_len); + return nvs_set_blob(cf->handle, BLE_MESH_FCB_NVS_KEY, + (void *)settings_link_buf(buf), buf_len); } int csi_load_check(struct settings_dup_check_arg *cdca) { - char *cp_start = NULL; - cp_start = key_buf; + char buf[SETTINGS_MAX_NAME_LEN + SETTINGS_MAX_VAL_LEN + SETTINGS_EXTRA_LEN]; + char *cp_start = key_buf; size_t len = 0; - char buf[SETTINGS_MAX_NAME_LEN + SETTINGS_MAX_VAL_LEN + - SETTINGS_EXTRA_LEN]; char *name_str; char *val_str; int rc = 0; @@ -195,4 +186,4 @@ int csi_load_check(struct settings_dup_check_arg *cdca) return 0; } -#endif /* CONFIG_BT_MESH_SETTINGS */ +#endif /* CONFIG_BLE_MESH_SETTINGS */ diff --git a/components/bt/ble_mesh/mesh_core/settings/settings_file.c b/components/bt/ble_mesh/mesh_core/settings/settings_file.c deleted file mode 100644 index db8e1027e1..0000000000 --- a/components/bt/ble_mesh/mesh_core/settings/settings_file.c +++ /dev/null @@ -1,303 +0,0 @@ -/* - * Copyright (c) 2018 Nordic Semiconductor ASA - * Copyright (c) 2015 Runtime Inc - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include -#include - -#ifdef CONFIG_SETTINGS_FS - -#include "settings/include/settings.h" -#include "settings/include/settings_file.h" -#include "settings/include/settings_priv.h" - -static int settings_file_load(struct settings_store *cs, load_cb cb, - void *cb_arg); -static int settings_file_save(struct settings_store *cs, const char *name, - const char *value); - -static struct settings_store_itf settings_file_itf = { - .csi_load = settings_file_load, - .csi_save = settings_file_save, -}; - -/* - * Register a file to be a source of configuration. - */ -int settings_file_src(struct settings_file *cf) -{ - if (!cf->cf_name) { - return -EINVAL; - } - cf->cf_store.cs_itf = &settings_file_itf; - settings_src_register(&cf->cf_store); - - return 0; -} - -int settings_file_dst(struct settings_file *cf) -{ - if (!cf->cf_name) { - return -EINVAL; - } - cf->cf_store.cs_itf = &settings_file_itf; - settings_dst_register(&cf->cf_store); - - return 0; -} - -int settings_getnext_line(struct fs_file_t *file, char *buf, int blen, - off_t *loc) -{ - int rc; - char *end; - - rc = fs_seek(file, *loc, FS_SEEK_SET); - if (rc < 0) { - *loc = 0; - return -1; - } - - rc = fs_read(file, buf, blen); - if (rc <= 0) { - *loc = 0; - return -1; - } - - if (rc == blen) { - rc--; - } - buf[rc] = '\0'; - - end = strchr(buf, '\n'); - if (end) { - *end = '\0'; - } else { - end = strchr(buf, '\0'); - } - blen = end - buf; - *loc += (blen + 1); - return blen; -} - -/* - * Called to load configuration items. cb must be called for every configuration - * item found. - */ -static int settings_file_load(struct settings_store *cs, load_cb cb, - void *cb_arg) -{ - struct settings_file *cf = (struct settings_file *)cs; - struct fs_file_t file; - off_t loc; - char tmpbuf[SETTINGS_MAX_NAME_LEN + SETTINGS_MAX_VAL_LEN + - SETTINGS_EXTRA_LEN]; - char *name_str; - char *val_str; - int rc; - int lines; - - rc = fs_open(&file, cf->cf_name); - if (rc != 0) { - return -EINVAL; - } - - loc = 0; - lines = 0; - while (1) { - rc = settings_getnext_line(&file, tmpbuf, sizeof(tmpbuf), &loc); - if (loc == 0) { - break; - } - if (rc < 0) { - continue; - } - rc = settings_line_parse(tmpbuf, &name_str, &val_str); - if (rc != 0) { - continue; - } - lines++; - cb(name_str, val_str, cb_arg); - } - rc = fs_close(&file); - cf->cf_lines = lines; - - return rc; -} - -static void settings_tmpfile(char *dst, const char *src, char *pfx) -{ - int len; - int pfx_len; - - len = strlen(src); - pfx_len = strlen(pfx); - if (len + pfx_len >= SETTINGS_FILE_NAME_MAX) { - len = SETTINGS_FILE_NAME_MAX - pfx_len - 1; - } - memcpy(dst, src, len); - memcpy(dst + len, pfx, pfx_len); - dst[len + pfx_len] = '\0'; -} - -static int settings_file_create_or_replace(struct fs_file_t *zfp, - const char *file_name) -{ - struct fs_dirent entry; - - if (fs_stat(file_name, &entry) == 0) { - if (entry.type == FS_DIR_ENTRY_FILE) { - if (fs_unlink(file_name)) { - return -EIO; - } - } else { - return -EISDIR; - } - } - - return fs_open(zfp, file_name); -} -/* - * Try to compress configuration file by keeping unique names only. - */ -void settings_file_compress(struct settings_file *cf) -{ - int rc; - struct fs_file_t rf; - struct fs_file_t wf; - char tmp_file[SETTINGS_FILE_NAME_MAX]; - char buf1[SETTINGS_MAX_NAME_LEN + SETTINGS_MAX_VAL_LEN + - SETTINGS_EXTRA_LEN]; - char buf2[SETTINGS_MAX_NAME_LEN + SETTINGS_MAX_VAL_LEN + - SETTINGS_EXTRA_LEN]; - off_t loc1, loc2; - char *name1, *val1; - char *name2, *val2; - int copy; - int len, len2; - int lines; - - if (fs_open(&rf, cf->cf_name) != 0) { - return; - } - - settings_tmpfile(tmp_file, cf->cf_name, ".cmp"); - - if (settings_file_create_or_replace(&wf, tmp_file)) { - fs_close(&rf); - return; - } - - loc1 = 0; - lines = 0; - while (1) { - len = settings_getnext_line(&rf, buf1, sizeof(buf1), &loc1); - if (loc1 == 0 || len < 0) { - break; - } - rc = settings_line_parse(buf1, &name1, &val1); - if (rc) { - continue; - } - loc2 = loc1; - copy = 1; - while ((len2 = settings_getnext_line(&rf, buf2, sizeof(buf2), - &loc2)) > 0) { - rc = settings_line_parse(buf2, &name2, &val2); - if (rc) { - continue; - } - if (!strcmp(name1, name2)) { - copy = 0; - break; - } - } - if (!copy) { - continue; - } - - /* - * Can't find one. Must copy. - */ - len = settings_line_make(buf2, sizeof(buf2), name1, val1); - if (len < 0 || len + 2 > sizeof(buf2)) { - continue; - } - buf2[len++] = '\n'; - if (fs_write(&wf, buf2, len) != len) { - ARG_UNUSED(fs_close(&rf)); - ARG_UNUSED(fs_close(&wf)); - return; - } - lines++; - } - - len = fs_close(&wf); - len2 = fs_close(&rf); - if (len == 0 && len2 == 0 && fs_unlink(cf->cf_name) == 0) { - ARG_UNUSED(fs_rename(tmp_file, cf->cf_name)); - cf->cf_lines = lines; - /* - * XXX at settings_file_load(), look for .cmp if actual file does not - * exist. - */ - } -} - -/* - * Called to save configuration. - */ -static int settings_file_save(struct settings_store *cs, const char *name, - const char *value) -{ - struct settings_file *cf = (struct settings_file *)cs; - struct fs_file_t file; - char buf[SETTINGS_MAX_NAME_LEN + SETTINGS_MAX_VAL_LEN + - SETTINGS_EXTRA_LEN]; - int len; - int rc2; - int rc; - - if (!name) { - return -EINVAL; - } - - if (cf->cf_maxlines && (cf->cf_lines + 1 >= cf->cf_maxlines)) { - /* - * Compress before config file size exceeds - * the max number of lines. - */ - settings_file_compress(cf); - } - len = settings_line_make(buf, sizeof(buf), name, value); - if (len < 0 || len + 2 > sizeof(buf)) { - return -EINVAL; - } - buf[len++] = '\n'; - - /* - * Open the file to add this one value. - */ - rc = fs_open(&file, cf->cf_name); - if (rc == 0) { - rc = fs_seek(&file, 0, FS_SEEK_END); - if (rc == 0) { - rc2 = fs_write(&file, buf, len); - if (rc2 == len) { - cf->cf_lines++; - } - } - - rc2 = fs_close(&file); - if (rc == 0) { - rc = rc2; - } - } - - return rc; -} - -#endif /* #ifdef CONFIG_SETTINGS_FS */ diff --git a/components/bt/ble_mesh/mesh_core/settings/settings_init.c b/components/bt/ble_mesh/mesh_core/settings/settings_init.c index 8d2ece4b49..a3744306b5 100644 --- a/components/bt/ble_mesh/mesh_core/settings/settings_init.c +++ b/components/bt/ble_mesh/mesh_core/settings/settings_init.c @@ -9,80 +9,39 @@ #include #include #include - #include #include #include "sdkconfig.h" -#include "settings/include/settings.h" +#include "settings_act.h" +#include "settings_fcb.h" -#if CONFIG_BT_MESH_SETTINGS +#if CONFIG_BLE_MESH_SETTINGS -void settings_init(void); +extern void settings_init(void); +extern int settings_fcb_src(struct settings_fcb *cf); +extern int settings_fcb_dst(struct settings_fcb *cf); -#ifdef CONFIG_SETTINGS_FS -#include +static struct settings_fcb config_init_settings_fcb; -static struct settings_file config_init_settings_file = { - .cf_name = CONFIG_SETTINGS_FS_FILE, - .cf_maxlines = CONFIG_SETTINGS_FS_MAX_LINES -}; - -static void settings_init_fs(void) +static int settings_init_fcb(void) { int rc; - rc = settings_file_src(&config_init_settings_file); - if (rc) { - BT_ERR("%s, settings file srouce fail.", __func__); - return; - } - - rc = settings_file_dst(&config_init_settings_file); - if (rc) { - BT_ERR("%s, settings file dst fail.", __func__); - return; - } -} - -#elif defined(CONFIG_SETTINGS_FCB) -#include "settings/include/fcb.h" -#include "settings/include/settings_fcb.h" - -static struct settings_fcb config_init_settings_fcb = { - -}; - -static void settings_init_fcb(void) -{ - int rc; rc = settings_fcb_src(&config_init_settings_fcb); - - if (rc != 0) { - rc = settings_fcb_src(&config_init_settings_fcb); + if (rc) { + return rc; } rc = settings_fcb_dst(&config_init_settings_fcb); - + return rc; } -#endif - int settings_subsys_init(void) { settings_init(); - -#ifdef CONFIG_SETTINGS_FS - settings_init_fs(); /* func rises kernel panic once error */ - - /* - * Must be called after root FS has been initialized. - */ - return fs_mkdir(CONFIG_SETTINGS_FS_DIR); -#elif defined(CONFIG_SETTINGS_FCB) - settings_init_fcb(); /* func rises kernel panic once error */ + settings_init_fcb(); return 0; -#endif } -#endif /* CONFIG_BT_MESH_SETTINGS */ +#endif /* CONFIG_BLE_MESH_SETTINGS */ diff --git a/components/bt/ble_mesh/mesh_core/settings/settings_line.c b/components/bt/ble_mesh/mesh_core/settings/settings_line.c index 66d3bc67b7..a080df7fea 100644 --- a/components/bt/ble_mesh/mesh_core/settings/settings_line.c +++ b/components/bt/ble_mesh/mesh_core/settings/settings_line.c @@ -9,10 +9,10 @@ #include "sdkconfig.h" -#include "settings/include/settings.h" -#include "settings/include/settings_priv.h" +#include "settings_act.h" +#include "settings_priv.h" -#if CONFIG_BT_MESH_SETTINGS +#if CONFIG_BLE_MESH_SETTINGS static inline int isspace(int c) { @@ -96,4 +96,4 @@ int settings_line_make(char *dst, int dlen, const char *name, const char *value) return off; } -#endif /* CONFIG_BT_MESH_SETTINGS */ +#endif /* CONFIG_BLE_MESH_SETTINGS */ diff --git a/components/bt/ble_mesh/mesh_core/settings/settings_store.c b/components/bt/ble_mesh/mesh_core/settings/settings_store.c index 1f4c64267b..46f0e4f463 100644 --- a/components/bt/ble_mesh/mesh_core/settings/settings_store.c +++ b/components/bt/ble_mesh/mesh_core/settings/settings_store.c @@ -15,20 +15,19 @@ #include "mesh_util.h" #include "mesh_types.h" -#include "settings/include/settings.h" -#include "settings/include/settings_priv.h" -#include "settings/include/settings_fcb.h" +#include "settings_act.h" +#include "settings_priv.h" +#include "settings_fcb.h" -#if CONFIG_BT_MESH_SETTINGS +#if CONFIG_BLE_MESH_SETTINGS -sys_slist_t settings_load_srcs; -struct settings_store *settings_save_dst; +static struct settings_store *settings_save_dst; +static sys_slist_t settings_load_srcs; void settings_src_register(struct settings_store *cs) { - sys_snode_t *prev, *cur; - - prev = NULL; + sys_snode_t *prev = NULL; + sys_snode_t *cur = NULL; SYS_SLIST_FOR_EACH_NODE(&settings_load_srcs, cur) { prev = cur; @@ -45,25 +44,17 @@ void settings_dst_register(struct settings_store *cs) static void settings_load_cb(char *name, char *val, void *cb_arg) { int rc = settings_set_value(name, val); - __ASSERT(rc == 0, "set-value operation failure\n"); - (void)rc; + __ASSERT(rc == 0, "%s, Failed to load setting value", __func__); } int settings_load(void) { struct settings_store *cs; - /* - * for every config store - * load config - * apply config - * commit all - */ - SYS_SLIST_FOR_EACH_CONTAINER(&settings_load_srcs, cs, cs_next) { cs->cs_itf->csi_load(cs, settings_load_cb, NULL); } - return settings_commit(NULL); + return settings_commit(); } /* @@ -71,63 +62,29 @@ int settings_load(void) */ int settings_save_one(const char *name, char *value) { - struct settings_store *cs; struct settings_dup_check_arg cdca; + struct settings_store *cs; cs = settings_save_dst; if (!cs) { return -ENOENT; } - /* - * Check if we're writing the same value again. - */ + /* Check if we're writing the same value again. */ cdca.name = name; cdca.val = value; cdca.is_dup = 0; csi_load_check(&cdca); - //cs->cs_itf->csi_load(cs, settings_dup_check_cb, &cdca); + if (cdca.is_dup == 1) { return 0; } return cs->cs_itf->csi_save(cs, name, value); } -int settings_save(void) -{ - struct settings_store *cs; - struct settings_handler *ch; - int rc; - int rc2; - - cs = settings_save_dst; - if (!cs) { - return -ENOENT; - } - - if (cs->cs_itf->csi_save_start) { - cs->cs_itf->csi_save_start(cs); - } - rc = 0; - - SYS_SLIST_FOR_EACH_CONTAINER(&settings_handlers, ch, node) { - if (ch->h_export) { - rc2 = ch->h_export(settings_save_one, - SETTINGS_EXPORT_PERSIST); - if (!rc) { - rc = rc2; - } - } - } - if (cs->cs_itf->csi_save_end) { - cs->cs_itf->csi_save_end(cs); - } - return rc; -} - void settings_store_init(void) { sys_slist_init(&settings_load_srcs); } -#endif /* CONFIG_BT_MESH_SETTINGS */ +#endif /* CONFIG_BLE_MESH_SETTINGS */ diff --git a/components/bt/ble_mesh/mesh_core/test.c b/components/bt/ble_mesh/mesh_core/test.c index 1a20427dad..05004a539c 100644 --- a/components/bt/ble_mesh/mesh_core/test.c +++ b/components/bt/ble_mesh/mesh_core/test.c @@ -11,6 +11,8 @@ #include #include "mesh_trace.h" +#include "mesh_main.h" +#include "mesh_access.h" #include "mesh.h" #include "test.h" @@ -18,16 +20,14 @@ #include "net.h" #include "foundation.h" #include "access.h" -#include "mesh_main.h" -#include "mesh_access.h" -#if defined(CONFIG_BT_MESH_SELF_TEST) +#if defined(CONFIG_BLE_MESH_SELF_TEST) int bt_mesh_test(void) { return 0; } -#endif /* #if defined(CONFIG_BT_MESH_SELF_TEST) */ +#endif /* #if defined(CONFIG_BLE_MESH_SELF_TEST) */ int bt_mesh_device_auto_enter_network(struct bt_mesh_device_network_info *info) { @@ -40,8 +40,8 @@ int bt_mesh_device_auto_enter_network(struct bt_mesh_device_network_info *info) int i, j, k; int err; - if (info == NULL || !BT_MESH_ADDR_IS_UNICAST(info->unicast_addr) || - !BT_MESH_ADDR_IS_GROUP(info->group_addr)) { + if (info == NULL || !BLE_MESH_ADDR_IS_UNICAST(info->unicast_addr) || + !BLE_MESH_ADDR_IS_GROUP(info->group_addr)) { return -EINVAL; } @@ -49,32 +49,32 @@ 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, 0, info->unicast_addr, info->dev_key); if (err) { - BT_ERR("%s: bt_mesh_provision() fail, err %d", __func__, err); + BT_ERR("%s, bt_mesh_provision() failed (err %d)", __func__, 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("%s, Failed to find subnet 0x%04x", __func__, info->net_idx); return -ENODEV; } for (i = 0; i < ARRAY_SIZE(bt_mesh.app_keys); i++) { key = &bt_mesh.app_keys[i]; - if (key->net_idx == BT_MESH_KEY_UNUSED) { + if (key->net_idx == BLE_MESH_KEY_UNUSED) { break; } } if (i == ARRAY_SIZE(bt_mesh.app_keys)) { - BT_ERR("%s: Failed to allocate app_key, app_idx 0x%04x", __func__, info->app_idx); + BT_ERR("%s, Failed to allocate memory, AppKeyIndex 0x%04x", __func__, 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, app_idx 0x%04x", __func__, info->app_idx); + BT_ERR("%s, Failed to calculate AID, AppKeyIndex 0x%04x", __func__, info->app_idx); return -EIO; } @@ -85,7 +85,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("%s, Composition data is NULL", __func__); return -ENODEV; } @@ -93,18 +93,18 @@ int bt_mesh_device_auto_enter_network(struct bt_mesh_device_network_info *info) elem = &comp->elem[i]; for (j = 0; j < elem->model_count; j++) { model = &elem->models[j]; - if (model->id == BT_MESH_MODEL_ID_CFG_SRV || - model->id == BT_MESH_MODEL_ID_CFG_CLI) { + if (model->id == BLE_MESH_MODEL_ID_CFG_SRV || + model->id == BLE_MESH_MODEL_ID_CFG_CLI) { continue; } for (k = 0; k < ARRAY_SIZE(model->keys); k++) { - if (model->keys[k] == BT_MESH_KEY_UNUSED) { + if (model->keys[k] == BLE_MESH_KEY_UNUSED) { model->keys[k] = info->app_idx; break; } } for (k = 0; k < ARRAY_SIZE(model->groups); k++) { - if (model->groups[k] == BT_MESH_ADDR_UNASSIGNED) { + if (model->groups[k] == BLE_MESH_ADDR_UNASSIGNED) { model->groups[k] = info->group_addr; break; } @@ -113,13 +113,13 @@ int bt_mesh_device_auto_enter_network(struct bt_mesh_device_network_info *info) for (j = 0; j < elem->vnd_model_count; j++) { model = &elem->vnd_models[j]; for (k = 0; k < ARRAY_SIZE(model->keys); k++) { - if (model->keys[k] == BT_MESH_KEY_UNUSED) { + if (model->keys[k] == BLE_MESH_KEY_UNUSED) { model->keys[k] = info->app_idx; break; } } for (k = 0; k < ARRAY_SIZE(model->groups); k++) { - if (model->groups[k] == BT_MESH_ADDR_UNASSIGNED) { + if (model->groups[k] == BLE_MESH_ADDR_UNASSIGNED) { model->groups[k] = info->group_addr; break; } diff --git a/components/bt/ble_mesh/mesh_core/test.h b/components/bt/ble_mesh/mesh_core/test.h index 74a59441bb..60e3d0d8f1 100644 --- a/components/bt/ble_mesh/mesh_core/test.h +++ b/components/bt/ble_mesh/mesh_core/test.h @@ -7,8 +7,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -#ifndef _BLE_MESH_TEST_H -#define _BLE_MESH_TEST_H +#ifndef _BLE_MESH_TEST_H_ +#define _BLE_MESH_TEST_H_ #include #include @@ -17,7 +17,7 @@ #include "mesh_buf.h" #include "sdkconfig.h" -#if defined(CONFIG_BT_MESH_SELF_TEST) +#if defined(CONFIG_BLE_MESH_SELF_TEST) int bt_mesh_test(void); #else static inline int bt_mesh_test(void) @@ -40,4 +40,4 @@ struct bt_mesh_device_network_info { int bt_mesh_device_auto_enter_network(struct bt_mesh_device_network_info *info); -#endif /* _BLE_MESH_TEST_H */ +#endif /* _BLE_MESH_TEST_H_ */ diff --git a/components/bt/ble_mesh/mesh_core/transport.c b/components/bt/ble_mesh/mesh_core/transport.c index 6b81f40628..2d3228d0aa 100644 --- a/components/bt/ble_mesh/mesh_core/transport.c +++ b/components/bt/ble_mesh/mesh_core/transport.c @@ -9,30 +9,28 @@ #include #include + +#include "sdkconfig.h" +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BLE_MESH_DEBUG_TRANS) + #include "mesh_types.h" #include "mesh_util.h" - #include "mesh_buf.h" -#include "sdkconfig.h" -#include "settings.h" - -#if CONFIG_BT_MESH - -#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_MESH_DEBUG_TRANS) #include "mesh_trace.h" #include "mesh_main.h" +#include "settings.h" +#include "mesh.h" #include "crypto.h" #include "adv.h" -#include "mesh.h" #include "net.h" #include "lpn.h" #include "friend.h" #include "access.h" #include "foundation.h" #include "transport.h" - -#include "common.h" +#include "model_common.h" +#include "provisioner_main.h" #define AID_MASK ((u8_t)(BIT_MASK(6))) @@ -61,7 +59,7 @@ static struct seg_tx { struct bt_mesh_subnet *sub; - struct net_buf *seg[BT_MESH_TX_SEG_COUNT]; + struct net_buf *seg[BLE_MESH_TX_SEG_COUNT]; u64_t seq_auth; u16_t dst; u8_t seg_n: 5, /* Last segment index */ @@ -70,7 +68,7 @@ static struct seg_tx { const struct bt_mesh_send_cb *cb; void *cb_data; struct k_delayed_work retransmit; /* Retransmit timer */ -} seg_tx[CONFIG_BT_MESH_TX_SEG_MSG_COUNT]; +} seg_tx[CONFIG_BLE_MESH_TX_SEG_MSG_COUNT]; static struct seg_rx { struct bt_mesh_subnet *sub; @@ -87,14 +85,14 @@ static struct seg_rx { u32_t last; struct k_delayed_work ack; struct net_buf_simple buf; - u8_t buf_data[CONFIG_BT_MESH_RX_SDU_MAX]; -} seg_rx[CONFIG_BT_MESH_RX_SEG_MSG_COUNT] = { - [0 ... (CONFIG_BT_MESH_RX_SEG_MSG_COUNT - 1)] = { - .buf.size = CONFIG_BT_MESH_RX_SDU_MAX, + u8_t buf_data[CONFIG_BLE_MESH_RX_SDU_MAX]; +} seg_rx[CONFIG_BLE_MESH_RX_SEG_MSG_COUNT] = { + [0 ... (CONFIG_BLE_MESH_RX_SEG_MSG_COUNT - 1)] = { + .buf.size = CONFIG_BLE_MESH_RX_SDU_MAX, }, }; -static u16_t hb_sub_dst = BT_MESH_ADDR_UNASSIGNED; +static u16_t hb_sub_dst = BLE_MESH_ADDR_UNASSIGNED; void bt_mesh_set_hb_sub_dst(u16_t addr) { @@ -109,17 +107,17 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu, BT_DBG("src 0x%04x dst 0x%04x app_idx 0x%04x sdu_len %u", tx->src, tx->ctx->addr, tx->ctx->app_idx, sdu->len); - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, - BT_MESH_TRANSMIT_COUNT(tx->xmit), - BT_MESH_TRANSMIT_INT(tx->xmit), BUF_TIMEOUT); + buf = bt_mesh_adv_create(BLE_MESH_ADV_DATA, + BLE_MESH_TRANSMIT_COUNT(tx->xmit), + BLE_MESH_TRANSMIT_INT(tx->xmit), BUF_TIMEOUT); if (!buf) { - BT_ERR("Out of network buffers"); + BT_ERR("%s, Out of network buffers", __func__); return -ENOBUFS; } - net_buf_reserve(buf, BT_MESH_NET_HDR_LEN); + net_buf_reserve(buf, BLE_MESH_NET_HDR_LEN); - if (tx->ctx->app_idx == BT_MESH_KEY_DEV) { + if (tx->ctx->app_idx == BLE_MESH_KEY_DEV) { net_buf_add_u8(buf, UNSEG_HDR(0, 0)); } else { net_buf_add_u8(buf, UNSEG_HDR(1, tx->aid)); @@ -127,12 +125,12 @@ static int send_unseg(struct bt_mesh_net_tx *tx, struct net_buf_simple *sdu, net_buf_add_mem(buf, sdu->data, sdu->len); -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE if (bt_mesh_is_provisioned()) { - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { - if (bt_mesh_friend_enqueue_tx(tx, BT_MESH_FRIEND_PDU_SINGLE, + if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) { + if (bt_mesh_friend_enqueue_tx(tx, BLE_MESH_FRIEND_PDU_SINGLE, NULL, &buf->b) && - BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) { + BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) { /* PDUs for a specific Friend should only go * out through the Friend Queue. */ @@ -169,7 +167,7 @@ static void seg_tx_reset(struct seg_tx *tx) tx->cb_data = NULL; tx->seq_auth = 0; tx->sub = NULL; - tx->dst = BT_MESH_ADDR_UNASSIGNED; + tx->dst = BLE_MESH_ADDR_UNASSIGNED; if (!tx->nack_count) { return; @@ -249,13 +247,13 @@ static void seg_tx_send_unacked(struct seg_tx *tx) continue; } - if (BT_MESH_ADV(seg)->busy) { + if (BLE_MESH_ADV(seg)->busy) { BT_DBG("Skipping segment that's still advertising"); continue; } - if (!(BT_MESH_ADV(seg)->seg.attempts--)) { - BT_ERR("Ran out of retransmit attempts"); + if (!(BLE_MESH_ADV(seg)->seg.attempts--)) { + BT_ERR("%s, Ran out of retransmit attempts", __func__); seg_tx_complete(tx, -ETIMEDOUT); return; } @@ -265,7 +263,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("Sending segment failed"); + BT_ERR("%s, Send segment failed", __func__); seg_tx_complete(tx, -EIO); return; } @@ -292,12 +290,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("Zero-length SDU not allowed"); + BT_ERR("%s, Zero-length SDU not allowed", __func__); return -EINVAL; } - if (sdu->len > BT_MESH_TX_SDU_MAX) { - BT_ERR("Not enough segment buffers for length %u", sdu->len); + if (sdu->len > BLE_MESH_TX_SDU_MAX) { + BT_ERR("%s, Not enough segment buffers for length %u", __func__, sdu->len); return -EMSGSIZE; } @@ -309,11 +307,11 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu, } if (!tx) { - BT_ERR("No multi-segment message contexts available"); + BT_ERR("%s, No multi-segment message contexts available", __func__); return -EBUSY; } - if (net_tx->ctx->app_idx == BT_MESH_KEY_DEV) { + if (net_tx->ctx->app_idx == BLE_MESH_KEY_DEV) { seg_hdr = SEG_HDR(0, 0); } else { seg_hdr = SEG_HDR(1, net_tx->aid); @@ -323,7 +321,7 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu, tx->dst = net_tx->ctx->addr; tx->seg_n = (sdu->len - 1) / 12; tx->nack_count = tx->seg_n + 1; - tx->seq_auth = SEQ_AUTH(BT_MESH_NET_IVI_TX, bt_mesh.seq); + tx->seq_auth = SEQ_AUTH(BLE_MESH_NET_IVI_TX, bt_mesh.seq); tx->sub = net_tx->sub; tx->new_key = net_tx->sub->kr_flag; tx->cb = cb; @@ -338,19 +336,19 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu, u16_t len; int err; - seg = bt_mesh_adv_create(BT_MESH_ADV_DATA, - BT_MESH_TRANSMIT_COUNT(net_tx->xmit), - BT_MESH_TRANSMIT_INT(net_tx->xmit), + seg = bt_mesh_adv_create(BLE_MESH_ADV_DATA, + BLE_MESH_TRANSMIT_COUNT(net_tx->xmit), + BLE_MESH_TRANSMIT_INT(net_tx->xmit), BUF_TIMEOUT); if (!seg) { - BT_ERR("Out of segment buffers"); + BT_ERR("%s, Out of segment buffers", __func__); seg_tx_reset(tx); return -ENOBUFS; } - BT_MESH_ADV(seg)->seg.attempts = SEG_RETRANSMIT_ATTEMPTS; + BLE_MESH_ADV(seg)->seg.attempts = SEG_RETRANSMIT_ATTEMPTS; - net_buf_reserve(seg, BT_MESH_NET_HDR_LEN); + net_buf_reserve(seg, BLE_MESH_NET_HDR_LEN); net_buf_add_u8(seg, seg_hdr); net_buf_add_u8(seg, (net_tx->aszmic << 7) | seq_zero >> 6); @@ -358,27 +356,27 @@ static int send_seg(struct bt_mesh_net_tx *net_tx, struct net_buf_simple *sdu, (seg_o >> 3))); net_buf_add_u8(seg, ((seg_o & 0x07) << 5) | tx->seg_n); - len = min(sdu->len, 12); + len = MIN(sdu->len, 12); net_buf_add_mem(seg, sdu->data, len); net_buf_simple_pull(sdu, len); tx->seg[seg_o] = net_buf_ref(seg); -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE if (bt_mesh_is_provisioned()) { - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { + if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) { enum bt_mesh_friend_pdu_type type; if (seg_o == tx->seg_n) { - type = BT_MESH_FRIEND_PDU_COMPLETE; + type = BLE_MESH_FRIEND_PDU_COMPLETE; } else { - type = BT_MESH_FRIEND_PDU_PARTIAL; + type = BLE_MESH_FRIEND_PDU_PARTIAL; } if (bt_mesh_friend_enqueue_tx(net_tx, type, &tx->seq_auth, &seg->b) && - BT_MESH_ADDR_IS_UNICAST(net_tx->ctx->addr)) { + BLE_MESH_ADDR_IS_UNICAST(net_tx->ctx->addr)) { /* PDUs for a specific Friend should only go * out through the Friend Queue. */ @@ -395,13 +393,13 @@ 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("Sending segment failed"); + BT_ERR("%s, Sending segment failed", __func__); seg_tx_reset(tx); return err; } } -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE if (bt_mesh_is_provisioned()) { if (bt_mesh_lpn_established()) { bt_mesh_lpn_poll(); @@ -419,7 +417,7 @@ struct bt_mesh_app_key *bt_mesh_app_key_find(u16_t app_idx) for (i = 0; i < ARRAY_SIZE(bt_mesh.app_keys); i++) { struct bt_mesh_app_key *key = &bt_mesh.app_keys[i]; - if (key->net_idx != BT_MESH_KEY_UNUSED && + if (key->net_idx != BLE_MESH_KEY_UNUSED && key->app_idx == app_idx) { return key; } @@ -436,7 +434,7 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg, int err; if (net_buf_simple_tailroom(msg) < 4) { - BT_ERR("Insufficient tailroom for Transport MIC"); + BT_ERR("%s, Insufficient tailroom for Transport MIC", __func__); return -EINVAL; } @@ -448,14 +446,14 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg, tx->ctx->app_idx, tx->ctx->addr); BT_DBG("len %u: %s", msg->len, bt_hex(msg->data, msg->len)); - role = bt_mesh_get_msg_role(tx->ctx->model, tx->ctx->srv_send); + role = bt_mesh_get_model_role(tx->ctx->model, tx->ctx->srv_send); if (role == ROLE_NVAL) { - BT_ERR("%s: Failed to get role", __func__); + BT_ERR("%s, Failed to get model role", __func__); return -EINVAL; } - if (tx->ctx->app_idx == BT_MESH_KEY_DEV) { -#if CONFIG_BT_MESH_NODE && !CONFIG_BT_MESH_PROVISIONER + if (tx->ctx->app_idx == BLE_MESH_KEY_DEV) { +#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER if (role == NODE) { if (!bt_mesh_is_provisioner_en()) { key = bt_mesh.dev_key; @@ -463,7 +461,7 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg, } #endif -#if !CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (role == PROVISIONER) { if (bt_mesh_is_provisioner_en()) { key = provisioner_get_device_key(tx->ctx->addr); @@ -471,7 +469,7 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg, } #endif -#if CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (role == NODE) { key = bt_mesh.dev_key; } else if (role == PROVISIONER) { @@ -479,14 +477,14 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg, key = provisioner_get_device_key(tx->ctx->addr); } } else if (role == FAST_PROV) { -#if CONFIG_BT_MESH_FAST_PROV +#if CONFIG_BLE_MESH_FAST_PROV key = get_fast_prov_device_key(tx->ctx->addr); #endif } #endif if (!key) { - BT_ERR("%s: Failed to get device key", __func__); + BT_ERR("%s, Failed to get Device Key", __func__); return -EINVAL; } @@ -494,7 +492,7 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg, } else { struct bt_mesh_app_key *app_key = NULL; -#if CONFIG_BT_MESH_NODE && !CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER if (role == NODE) { if (!bt_mesh_is_provisioner_en()) { app_key = bt_mesh_app_key_find(tx->ctx->app_idx); @@ -502,7 +500,7 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg, } #endif -#if !CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (role == PROVISIONER) { if (bt_mesh_is_provisioner_en()) { app_key = provisioner_app_key_find(tx->ctx->app_idx); @@ -510,7 +508,7 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg, } #endif -#if CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (role == NODE) { app_key = bt_mesh_app_key_find(tx->ctx->app_idx); } else if (role == PROVISIONER) { @@ -518,18 +516,18 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg, app_key = provisioner_app_key_find(tx->ctx->app_idx); } } else if (role == FAST_PROV) { -#if CONFIG_BT_MESH_FAST_PROV +#if CONFIG_BLE_MESH_FAST_PROV app_key = get_fast_prov_app_key(tx->ctx->net_idx, tx->ctx->app_idx); #endif } #endif if (!app_key) { - BT_ERR("%s: Failed to get app key", __func__); + BT_ERR("%s, Failed to get AppKey", __func__); return -EINVAL; } - if (tx->sub->kr_phase == BT_MESH_KR_PHASE_2 && + if (tx->sub->kr_phase == BLE_MESH_KR_PHASE_2 && app_key->updated) { key = app_key->keys[1].val; tx->aid = app_key->keys[1].id; @@ -545,16 +543,16 @@ int bt_mesh_trans_send(struct bt_mesh_net_tx *tx, struct net_buf_simple *msg, tx->aszmic = 1; } - if (BT_MESH_ADDR_IS_VIRTUAL(tx->ctx->addr)) { + if (BLE_MESH_ADDR_IS_VIRTUAL(tx->ctx->addr)) { ad = bt_mesh_label_uuid_get(tx->ctx->addr); } else { ad = NULL; } - err = bt_mesh_app_encrypt(key, tx->ctx->app_idx == BT_MESH_KEY_DEV, + err = bt_mesh_app_encrypt(key, tx->ctx->app_idx == BLE_MESH_KEY_DEV, tx->aszmic, msg, ad, tx->src, tx->ctx->addr, bt_mesh.seq, - BT_MESH_NET_IVI_TX); + BLE_MESH_NET_IVI_TX); if (err) { return err; } @@ -599,7 +597,7 @@ static bool is_replay(struct bt_mesh_net_rx *rx) rpl->src = rx->ctx.addr; rpl->seq = rx->seq; rpl->old_iv = rx->old_iv; - if (IS_ENABLED(CONFIG_BT_MESH_SETTINGS)) { + if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) { BT_DBG("Store rpl"); bt_mesh_store_rpl(rpl); } @@ -633,7 +631,7 @@ static bool is_replay(struct bt_mesh_net_rx *rx) } } - BT_ERR("RPL is full!"); + BT_ERR("%s, RPL is full!", __func__); return true; } @@ -641,7 +639,7 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr, u8_t aszmic, struct net_buf_simple *buf) { struct net_buf_simple *sdu = - NET_BUF_SIMPLE(CONFIG_BT_MESH_RX_SDU_MAX - 4); + NET_BUF_SIMPLE(CONFIG_BLE_MESH_RX_SDU_MAX - 4); u32_t array_size = 0; u8_t *ad; u16_t i; @@ -651,16 +649,16 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr, u8_t aszmic, BT_DBG("len %u: %s", buf->len, bt_hex(buf->data, buf->len)); if (buf->len < 1 + APP_MIC_LEN(aszmic)) { - BT_ERR("Too short SDU + MIC"); + BT_ERR("%s, Too short SDU + MIC", __func__); return -EINVAL; } - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND) && !rx->local_match) { + if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND) && !rx->local_match) { BT_DBG("Ignoring PDU for LPN 0x%04x of this Friend", rx->dst); return 0; } - if (BT_MESH_ADDR_IS_VIRTUAL(rx->dst)) { + if (BLE_MESH_ADDR_IS_VIRTUAL(rx->dst)) { ad = bt_mesh_label_uuid_get(rx->dst); } else { ad = NULL; @@ -670,19 +668,19 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr, u8_t aszmic, buf->len -= APP_MIC_LEN(aszmic); if (!AKF(&hdr)) { -#if CONFIG_BT_MESH_NODE && !CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER if (!bt_mesh_is_provisioner_en()) { array_size = 1; } #endif -#if !CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (bt_mesh_is_provisioner_en()) { array_size = 1; } #endif -#if CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER array_size = 1; if (bt_mesh_is_provisioner_en()) { array_size += 1; @@ -692,19 +690,19 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr, u8_t aszmic, for (i = 0; i < array_size; i++) { const u8_t *dev_key = NULL; -#if CONFIG_BT_MESH_NODE && !CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER if (!bt_mesh_is_provisioner_en()) { dev_key = bt_mesh.dev_key; } #endif -#if !CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (bt_mesh_is_provisioner_en()) { dev_key = provisioner_get_device_key(rx->ctx.addr); } #endif -#if CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (i < 1) { dev_key = bt_mesh.dev_key; } else { @@ -713,19 +711,19 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr, u8_t aszmic, #endif if (!dev_key) { - BT_DBG("%s: NULL DevKey", __func__); + BT_DBG("%s, NULL Device Key", __func__); continue; } net_buf_simple_init(sdu, 0); err = bt_mesh_app_decrypt(dev_key, true, aszmic, buf, sdu, ad, rx->ctx.addr, rx->dst, - seq, BT_MESH_NET_IVI_RX(rx)); + seq, BLE_MESH_NET_IVI_RX(rx)); if (err) { continue; } - rx->ctx.app_idx = BT_MESH_KEY_DEV; + rx->ctx.app_idx = BLE_MESH_KEY_DEV; bt_mesh_model_recv(rx, sdu); return 0; } @@ -734,19 +732,19 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr, u8_t aszmic, return -ENODEV; } -#if CONFIG_BT_MESH_NODE && !CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER if (!bt_mesh_is_provisioner_en()) { array_size = ARRAY_SIZE(bt_mesh.app_keys); } #endif -#if !CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (bt_mesh_is_provisioner_en()) { array_size = ARRAY_SIZE(bt_mesh.p_app_keys); } #endif -#if CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER array_size = ARRAY_SIZE(bt_mesh.app_keys); if (bt_mesh_is_provisioner_en()) { array_size += ARRAY_SIZE(bt_mesh.p_app_keys); @@ -757,19 +755,19 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr, u8_t aszmic, struct bt_mesh_app_key *key = NULL; struct bt_mesh_app_keys *keys = NULL; -#if CONFIG_BT_MESH_NODE && !CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER if (!bt_mesh_is_provisioner_en()) { key = &bt_mesh.app_keys[i]; } #endif -#if !CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if !CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (bt_mesh_is_provisioner_en()) { key = bt_mesh.p_app_keys[i]; } #endif -#if CONFIG_BT_MESH_NODE && CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER if (i < ARRAY_SIZE(bt_mesh.app_keys)) { key = &bt_mesh.app_keys[i]; } else { @@ -778,7 +776,7 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr, u8_t aszmic, #endif if (!key) { - BT_DBG("%s: NULL AppKey", __func__); + BT_DBG("%s, NULL AppKey", __func__); continue; } @@ -801,7 +799,7 @@ static int sdu_recv(struct bt_mesh_net_rx *rx, u32_t seq, u8_t hdr, u8_t aszmic, net_buf_simple_init(sdu, 0); err = bt_mesh_app_decrypt(keys->val, false, aszmic, buf, sdu, ad, rx->ctx.addr, rx->dst, - seq, BT_MESH_NET_IVI_RX(rx)); + seq, BLE_MESH_NET_IVI_RX(rx)); if (err) { BT_DBG("Unable to decrypt with AppKey 0x%03x", key->app_idx); continue; @@ -858,7 +856,7 @@ static int trans_ack(struct bt_mesh_net_rx *rx, u8_t hdr, u8_t obo; if (buf->len < 6) { - BT_ERR("Too short ack message"); + BT_ERR("%s, Too short ack message", __func__); return -EINVAL; } @@ -866,10 +864,10 @@ static int trans_ack(struct bt_mesh_net_rx *rx, u8_t hdr, obo = seq_zero >> 15; seq_zero = (seq_zero >> 2) & 0x1fff; - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND) && rx->friend_match) { + if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND) && rx->friend_match) { BT_DBG("Ack for LPN 0x%04x of this Friend", rx->dst); /* Best effort - as there is not enough info for true SeqAuth */ - *seq_auth = SEQ_AUTH(BT_MESH_NET_IVI_RX(rx), seq_zero); + *seq_auth = SEQ_AUTH(BLE_MESH_NET_IVI_RX(rx), seq_zero); return 0; } @@ -892,7 +890,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("Too large segment number in ack"); + BT_ERR("%s, Too large segment number in ack", __func__); return -EINVAL; } @@ -926,7 +924,7 @@ static int trans_heartbeat(struct bt_mesh_net_rx *rx, u16_t feat; if (buf->len < 3) { - BT_ERR("Too short heartbeat message"); + BT_ERR("%s, Too short heartbeat message", __func__); return -EINVAL; } @@ -968,9 +966,9 @@ static int ctl_recv(struct bt_mesh_net_rx *rx, u8_t hdr, return 0; } -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE if (bt_mesh_is_provisioned()) { - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND) && !bt_mesh_lpn_established()) { + if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND) && !bt_mesh_lpn_established()) { switch (ctl_op) { case TRANS_CTL_OP_FRIEND_POLL: return bt_mesh_friend_poll(rx, buf); @@ -987,7 +985,7 @@ static int ctl_recv(struct bt_mesh_net_rx *rx, u8_t hdr, } } -#if defined(CONFIG_BT_MESH_LOW_POWER) +#if defined(CONFIG_BLE_MESH_LOW_POWER) if (ctl_op == TRANS_CTL_OP_FRIEND_OFFER) { return bt_mesh_lpn_friend_offer(rx, buf); } @@ -1009,9 +1007,9 @@ static int ctl_recv(struct bt_mesh_net_rx *rx, u8_t hdr, return bt_mesh_lpn_friend_sub_cfm(rx, buf); } } -#endif /* CONFIG_BT_MESH_LOW_POWER */ +#endif /* CONFIG_BLE_MESH_LOW_POWER */ } -#endif /* CONFIG_BT_MESH_NODE */ +#endif /* CONFIG_BLE_MESH_NODE */ BT_WARN("Unhandled TransOpCode 0x%02x", ctl_op); @@ -1026,7 +1024,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("Too small unsegmented PDU"); + BT_ERR("%s, Too small unsegmented PDU", __func__); return -EINVAL; } @@ -1065,7 +1063,7 @@ static inline s32_t ack_timeout(struct seg_rx *rx) /* Make sure we don't send more frequently than the duration for * each packet (default is 300ms). */ - return max(to, K_MSEC(400)); + return MAX(to, K_MSEC(400)); } int bt_mesh_ctl_send(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data, @@ -1078,24 +1076,24 @@ int bt_mesh_ctl_send(struct bt_mesh_net_tx *tx, u8_t ctl_op, void *data, tx->ctx->addr, tx->ctx->send_ttl, ctl_op); BT_DBG("len %u: %s", data_len, bt_hex(data, data_len)); - buf = bt_mesh_adv_create(BT_MESH_ADV_DATA, - BT_MESH_TRANSMIT_COUNT(tx->xmit), - BT_MESH_TRANSMIT_INT(tx->xmit), BUF_TIMEOUT); + buf = bt_mesh_adv_create(BLE_MESH_ADV_DATA, + BLE_MESH_TRANSMIT_COUNT(tx->xmit), + BLE_MESH_TRANSMIT_INT(tx->xmit), BUF_TIMEOUT); if (!buf) { - BT_ERR("Out of transport buffers"); + BT_ERR("%s, Out of transport buffers", __func__); return -ENOBUFS; } - net_buf_reserve(buf, BT_MESH_NET_HDR_LEN); + net_buf_reserve(buf, BLE_MESH_NET_HDR_LEN); net_buf_add_u8(buf, TRANS_CTL_HDR(ctl_op, 0)); net_buf_add_mem(buf, data, data_len); - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { - if (bt_mesh_friend_enqueue_tx(tx, BT_MESH_FRIEND_PDU_SINGLE, + if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) { + if (bt_mesh_friend_enqueue_tx(tx, BLE_MESH_FRIEND_PDU_SINGLE, seq_auth, &buf->b) && - BT_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) { + BLE_MESH_ADDR_IS_UNICAST(tx->ctx->addr)) { /* PDUs for a specific Friend should only go * out through the Friend Queue. */ @@ -1112,7 +1110,7 @@ static int send_ack(struct bt_mesh_subnet *sub, u16_t src, u16_t dst, { struct bt_mesh_msg_ctx ctx = { .net_idx = sub->net_idx, - .app_idx = BT_MESH_KEY_UNUSED, + .app_idx = BLE_MESH_KEY_UNUSED, .addr = dst, .send_ttl = ttl, }; @@ -1135,7 +1133,7 @@ static int send_ack(struct bt_mesh_subnet *sub, u16_t src, u16_t dst, /* This can happen if the segmented message was destined for a group * or a virtual address. */ - if (!BT_MESH_ADDR_IS_UNICAST(src)) { + if (!BLE_MESH_ADDR_IS_UNICAST(src)) { BT_WARN("Not sending ACK for non-unicast address"); return 0; } @@ -1153,7 +1151,7 @@ static void seg_rx_reset(struct seg_rx *rx) k_delayed_work_cancel(&rx->ack); - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND) && rx->obo && + if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND) && rx->obo && rx->block != BLOCK_COMPLETE(rx->seg_n)) { BT_WARN("Clearing incomplete buffers from Friend queue"); bt_mesh_friend_clear_incomplete(rx->sub, rx->src, rx->dst, @@ -1199,7 +1197,7 @@ static inline u8_t seg_len(bool ctl) static inline bool sdu_len_is_ok(bool ctl, u8_t seg_n) { - return ((seg_n * seg_len(ctl) + 1) <= CONFIG_BT_MESH_RX_SDU_MAX); + return ((seg_n * seg_len(ctl) + 1) <= CONFIG_BLE_MESH_RX_SDU_MAX); } static struct seg_rx *seg_rx_find(struct bt_mesh_net_rx *net_rx, @@ -1239,17 +1237,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("Invalid segment for ongoing session"); + BT_ERR("%s, Invalid segment for ongoing session", __func__); return false; } if (rx->src != net_rx->ctx.addr || rx->dst != net_rx->dst) { - BT_ERR("Invalid source or destination for segment"); + BT_ERR("%s, Invalid source or destination for segment", __func__); return false; } if (rx->ctl != net_rx->ctl) { - BT_ERR("Inconsistent CTL in segment"); + BT_ERR("%s, Inconsistent CTL in segment", __func__); return false; } @@ -1301,7 +1299,7 @@ static int trans_seg(struct net_buf_simple *buf, struct bt_mesh_net_rx *net_rx, int err; if (buf->len < 5) { - BT_ERR("Too short segmented message (len %u)", buf->len); + BT_ERR("%s, Too short segmented message (len %u)", __func__, buf->len); return -EINVAL; } @@ -1319,7 +1317,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("SegO greater than SegN (%u > %u)", seg_o, seg_n); + BT_ERR("%s, SegO is greater than SegN (%u > %u)", __func__, seg_o, seg_n); return -EINVAL; } @@ -1336,7 +1334,7 @@ static int trans_seg(struct net_buf_simple *buf, struct bt_mesh_net_rx *net_rx, * Mentioned delta shall be >= 0, if it is not then seq_auth will * be broken and it will be verified by the code below. */ - *seq_auth = SEQ_AUTH(BT_MESH_NET_IVI_RX(net_rx), + *seq_auth = SEQ_AUTH(BLE_MESH_NET_IVI_RX(net_rx), (net_rx->seq - ((((net_rx->seq & BIT_MASK(14)) - seq_zero)) & BIT_MASK(13)))); @@ -1377,7 +1375,7 @@ static int trans_seg(struct net_buf_simple *buf, struct bt_mesh_net_rx *net_rx, /* Leave early, if such a large SDU cannot be received */ if (!sdu_len_is_ok(net_rx->ctl, seg_n)) { - BT_ERR("Too big incoming SDU length"); + BT_ERR("%s, Too big incoming SDU length", __func__); send_ack(net_rx->sub, net_rx->dst, net_rx->ctx.addr, net_rx->ctx.send_ttl, seq_auth, 0, net_rx->friend_match); @@ -1413,7 +1411,7 @@ found_rx: BT_DBG("Target len %u * %u + %u = %u", seg_n, seg_len(rx->ctl), buf->len, rx->buf.len); - if (rx->buf.len > CONFIG_BT_MESH_RX_SDU_MAX) { + if (rx->buf.len > CONFIG_BLE_MESH_RX_SDU_MAX) { BT_ERR("Too large SDU len"); send_ack(net_rx->sub, net_rx->dst, net_rx->ctx.addr, net_rx->ctx.send_ttl, seq_auth, 0, rx->obo); @@ -1422,7 +1420,7 @@ found_rx: } } else { if (buf->len != seg_len(rx->ctl)) { - BT_ERR("Incorrect segment size for message type"); + BT_ERR("%s, Incorrect segment size for message type", __func__); return -EINVAL; } } @@ -1444,7 +1442,7 @@ found_rx: rx->block |= BIT(seg_o); if (rx->block != BLOCK_COMPLETE(seg_n)) { - *pdu_type = BT_MESH_FRIEND_PDU_PARTIAL; + *pdu_type = BLE_MESH_FRIEND_PDU_PARTIAL; return 0; } @@ -1458,7 +1456,7 @@ found_rx: return -EINVAL; } - *pdu_type = BT_MESH_FRIEND_PDU_COMPLETE; + *pdu_type = BLE_MESH_FRIEND_PDU_COMPLETE; k_delayed_work_cancel(&rx->ack); send_ack(net_rx->sub, net_rx->dst, net_rx->ctx.addr, @@ -1478,11 +1476,11 @@ found_rx: int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx) { u64_t seq_auth = TRANS_SEQ_AUTH_NVAL; - enum bt_mesh_friend_pdu_type pdu_type = BT_MESH_FRIEND_PDU_SINGLE; + enum bt_mesh_friend_pdu_type pdu_type = BLE_MESH_FRIEND_PDU_SINGLE; struct net_buf_simple_state state; int err; - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND)) { + if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) { rx->friend_match = bt_mesh_friend_match(rx->sub->net_idx, rx->dst); } else { @@ -1493,7 +1491,7 @@ int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx) rx->ctx.addr, rx->dst, rx->seq, rx->friend_match); /* Remove network headers */ - net_buf_simple_pull(buf, BT_MESH_NET_HDR_LEN); + net_buf_simple_pull(buf, BLE_MESH_NET_HDR_LEN); BT_DBG("Payload %s", bt_hex(buf->data, buf->len)); @@ -1501,10 +1499,10 @@ int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx) * the Friend is requested to send them. The messages must * also be encrypted using the Friend Credentials. */ -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE if (bt_mesh_is_provisioned()) { - if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER) && - bt_mesh_lpn_established() && rx->net_if == BT_MESH_NET_IF_ADV && + if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER) && + bt_mesh_lpn_established() && rx->net_if == BLE_MESH_NET_IF_ADV && (!bt_mesh_lpn_waiting_update() || !rx->friend_cred)) { BT_WARN("Ignoring unexpected message in Low Power mode"); return -EAGAIN; @@ -1545,9 +1543,9 @@ int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx) * the Transport OpCode was invalid. In this case, the PDU should be * ignored completely, as per MESH/NODE/FRND/LPN/BI-02-C. */ -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE if (bt_mesh_is_provisioned()) { - if (IS_ENABLED(CONFIG_BT_MESH_LOW_POWER) && err != -ENOENT && + if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER) && err != -ENOENT && (bt_mesh_lpn_timer() || (bt_mesh_lpn_established() && bt_mesh_lpn_waiting_update()))) { bt_mesh_lpn_msg_received(rx); @@ -1557,9 +1555,9 @@ int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx) net_buf_simple_restore(buf, &state); -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE if (bt_mesh_is_provisioned()) { - if (IS_ENABLED(CONFIG_BT_MESH_FRIEND) && rx->friend_match && !err) { + if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND) && rx->friend_match && !err) { if (seq_auth == TRANS_SEQ_AUTH_NVAL) { bt_mesh_friend_enqueue_rx(rx, pdu_type, NULL, buf); } else { @@ -1580,8 +1578,8 @@ void bt_mesh_rx_reset(void) for (i = 0; i < ARRAY_SIZE(seg_rx); i++) { seg_rx_reset(&seg_rx[i]); - seg_rx[i].src = BT_MESH_ADDR_UNASSIGNED; - seg_rx[i].dst = BT_MESH_ADDR_UNASSIGNED; + seg_rx[i].src = BLE_MESH_ADDR_UNASSIGNED; + seg_rx[i].dst = BLE_MESH_ADDR_UNASSIGNED; } } @@ -1614,5 +1612,3 @@ void bt_mesh_rpl_clear(void) BT_DBG("%s", __func__); memset(bt_mesh.rpl, 0, sizeof(bt_mesh.rpl)); } - -#endif /* #if CONFIG_BT_MESH */ diff --git a/components/bt/ble_mesh/mesh_core/transport.h b/components/bt/ble_mesh/mesh_core/transport.h index f44ade772d..628344f5fd 100644 --- a/components/bt/ble_mesh/mesh_core/transport.h +++ b/components/bt/ble_mesh/mesh_core/transport.h @@ -7,26 +7,29 @@ * SPDX-License-Identifier: Apache-2.0 */ -#define TRANS_SEQ_AUTH_NVAL 0xffffffffffffffff +#ifndef _TRANSPORT_H_ +#define _TRANSPORT_H_ -#define BT_MESH_TX_SEG_COUNT (CONFIG_BT_MESH_ADV_BUF_COUNT - 3) -#define BT_MESH_TX_SDU_MAX (BT_MESH_TX_SEG_COUNT * 12) +#define TRANS_SEQ_AUTH_NVAL 0xffffffffffffffff -#define TRANS_CTL_OP_MASK ((u8_t)BIT_MASK(7)) -#define TRANS_CTL_OP(data) ((data)[0] & TRANS_CTL_OP_MASK) -#define TRANS_CTL_HDR(op, seg) ((op & TRANS_CTL_OP_MASK) | (seg << 7)) +#define BLE_MESH_TX_SEG_COUNT (CONFIG_BLE_MESH_ADV_BUF_COUNT - 3) +#define BLE_MESH_TX_SDU_MAX (BLE_MESH_TX_SEG_COUNT * 12) -#define TRANS_CTL_OP_ACK 0x00 -#define TRANS_CTL_OP_FRIEND_POLL 0x01 -#define TRANS_CTL_OP_FRIEND_UPDATE 0x02 -#define TRANS_CTL_OP_FRIEND_REQ 0x03 -#define TRANS_CTL_OP_FRIEND_OFFER 0x04 -#define TRANS_CTL_OP_FRIEND_CLEAR 0x05 -#define TRANS_CTL_OP_FRIEND_CLEAR_CFM 0x06 -#define TRANS_CTL_OP_FRIEND_SUB_ADD 0x07 -#define TRANS_CTL_OP_FRIEND_SUB_REM 0x08 -#define TRANS_CTL_OP_FRIEND_SUB_CFM 0x09 -#define TRANS_CTL_OP_HEARTBEAT 0x0a +#define TRANS_CTL_OP_MASK ((u8_t)BIT_MASK(7)) +#define TRANS_CTL_OP(data) ((data)[0] & TRANS_CTL_OP_MASK) +#define TRANS_CTL_HDR(op, seg) ((op & TRANS_CTL_OP_MASK) | (seg << 7)) + +#define TRANS_CTL_OP_ACK 0x00 +#define TRANS_CTL_OP_FRIEND_POLL 0x01 +#define TRANS_CTL_OP_FRIEND_UPDATE 0x02 +#define TRANS_CTL_OP_FRIEND_REQ 0x03 +#define TRANS_CTL_OP_FRIEND_OFFER 0x04 +#define TRANS_CTL_OP_FRIEND_CLEAR 0x05 +#define TRANS_CTL_OP_FRIEND_CLEAR_CFM 0x06 +#define TRANS_CTL_OP_FRIEND_SUB_ADD 0x07 +#define TRANS_CTL_OP_FRIEND_SUB_REM 0x08 +#define TRANS_CTL_OP_FRIEND_SUB_CFM 0x09 +#define TRANS_CTL_OP_HEARTBEAT 0x0a struct bt_mesh_ctl_friend_poll { u8_t fsn; @@ -65,7 +68,7 @@ struct bt_mesh_ctl_friend_clear_confirm { u16_t lpn_counter; } __packed; -#define BT_MESH_FRIEND_SUB_MIN_LEN (1 + 2) +#define BLE_MESH_FRIEND_SUB_MIN_LEN (1 + 2) struct bt_mesh_ctl_friend_sub { u8_t xact; u16_t addr_list[5]; @@ -96,3 +99,5 @@ int bt_mesh_trans_recv(struct net_buf_simple *buf, struct bt_mesh_net_rx *rx); void bt_mesh_trans_init(void); void bt_mesh_rpl_clear(void); + +#endif /* _TRANSPORT_H_ */ diff --git a/components/bt/ble_mesh/mesh_models/common.c b/components/bt/ble_mesh/mesh_models/common.c deleted file mode 100644 index 709a7da953..0000000000 --- a/components/bt/ble_mesh/mesh_models/common.c +++ /dev/null @@ -1,110 +0,0 @@ -// Copyright 2017-2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include -#include - -#include "osi/allocator.h" -#include "errno.h" - -#include "mesh_types.h" -#include "mesh_kernel.h" -#include "mesh_buf.h" -#include "mesh_trace.h" -#include "common.h" -#include "bt_mesh_client_common.h" - -struct net_buf_simple *bt_mesh_alloc_buf(u16_t size) -{ - struct net_buf_simple *buf; - - buf = (struct net_buf_simple *)osi_calloc(sizeof(struct net_buf_simple) + size); - if (!buf) { - BT_ERR("%s: Failed to allocate memory", __func__); - return NULL; - } - - /* buf->data will be initialized in net_buf_simple_init() */ - buf->len = 0; - buf->size = size; - - return buf; -} - -void bt_mesh_free_buf(struct net_buf_simple *buf) -{ - if (buf) { - osi_free(buf); - } -} - -int bt_mesh_copy_msg_role(bt_mesh_role_param_t *common) -{ - bt_mesh_client_common_t *client = NULL; - - if (!common || !common->model || !common->model->user_data) { - BT_ERR("%s: invalid parameter", __func__); - return -EINVAL; - } - - client = (bt_mesh_client_common_t *)common->model->user_data; - - switch (common->role) { -#if CONFIG_BT_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_BT_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_WARN("%s: send provisioner msg with provisioner disabled", __func__); - return -EINVAL; - } - client->msg_role = PROVISIONER; - break; -#endif -#if CONFIG_BT_MESH_FAST_PROV - case FAST_PROV: - client->msg_role = FAST_PROV; - break; -#endif - default: - BT_WARN("%s: role mismatch", __func__); - return -EINVAL; - } - - return 0; -} - -u8_t bt_mesh_get_msg_role(struct bt_mesh_model *model, bool srv_send) -{ - bt_mesh_client_common_t *client = NULL; - - if (srv_send) { - BT_DBG("%s: msg sent by a server model", __func__); - return NODE; - } - - if (!model || !model->user_data) { - BT_ERR("%s: invalid parameter", __func__); - return ROLE_NVAL; - } - - client = (bt_mesh_client_common_t *)model->user_data; - - return client->msg_role; -} \ No newline at end of file diff --git a/components/bt/ble_mesh/mesh_models/generic_client.c b/components/bt/ble_mesh/mesh_models/generic_client.c index ce6ab135af..cc5ebdb63c 100644 --- a/components/bt/ble_mesh/mesh_models/generic_client.c +++ b/components/bt/ble_mesh/mesh_models/generic_client.c @@ -17,132 +17,131 @@ #include #include "osi/allocator.h" +#include "sdkconfig.h" #include "mesh_types.h" #include "mesh_kernel.h" #include "mesh_trace.h" -#include "mesh.h" -#include "model_op.h" -#include "common.h" +#include "mesh.h" +#include "model_opcode.h" +#include "mesh_common.h" #include "generic_client.h" -#include "sdkconfig.h" - -#include "btc_ble_mesh_generic_client.h" +#include "btc_ble_mesh_generic_model.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 */ /* Generic onoff client messages length */ -#define BT_MESH_GEN_ONOFF_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_GEN_ONOFF_SET_MSG_LEN (2 + 4 + 4) +#define BLE_MESH_GEN_ONOFF_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_GEN_ONOFF_SET_MSG_LEN (2 + 4 + 4) /* Generic level client messages length */ -#define BT_MESH_GEN_LEVEL_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_GEN_LEVEL_SET_MSG_LEN (2 + 5 + 4) -#define BT_MESH_GEN_DELTA_SET_MSG_LEN (2 + 7 + 4) -#define BT_MESH_GEN_MOVE_SET_MSG_LEN (2 + 5 + 4) +#define BLE_MESH_GEN_LEVEL_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_GEN_LEVEL_SET_MSG_LEN (2 + 5 + 4) +#define BLE_MESH_GEN_DELTA_SET_MSG_LEN (2 + 7 + 4) +#define BLE_MESH_GEN_MOVE_SET_MSG_LEN (2 + 5 + 4) /* Generic default transition time client messages length */ -#define BT_MESH_GEN_DEF_TRANS_TIME_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_GEN_DEF_TRANS_TIME_SET_MSG_LEN (2 + 1 + 4) +#define BLE_MESH_GEN_DEF_TRANS_TIME_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_GEN_DEF_TRANS_TIME_SET_MSG_LEN (2 + 1 + 4) /* Generic power onoff client messages length */ -#define BT_MESH_GEN_ONPOWERUP_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_GEN_ONPOWERUP_SET_MSG_LEN (2 + 1 + 4) +#define BLE_MESH_GEN_ONPOWERUP_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_GEN_ONPOWERUP_SET_MSG_LEN (2 + 1 + 4) /* Generic power level client messages length */ -#define BT_MESH_GEN_POWER_LEVEL_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_GEN_POWER_LEVEL_SET_MSG_LEN (2 + 5 + 4) -#define BT_MESH_GEN_POWER_LAST_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_GEN_POWER_DEFAULT_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_GEN_POWER_DEFAULT_SET_MSG_LEN (2 + 2 + 4) -#define BT_MESH_GEN_POWER_RANGE_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_GEN_POWER_RANGE_SET_MSG_LEN (2 + 4 + 4) +#define BLE_MESH_GEN_POWER_LEVEL_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_GEN_POWER_LEVEL_SET_MSG_LEN (2 + 5 + 4) +#define BLE_MESH_GEN_POWER_LAST_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_GEN_POWER_DEFAULT_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_GEN_POWER_DEFAULT_SET_MSG_LEN (2 + 2 + 4) +#define BLE_MESH_GEN_POWER_RANGE_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_GEN_POWER_RANGE_SET_MSG_LEN (2 + 4 + 4) /* Generic battery client messages length */ -#define BT_MESH_GEN_BATTERY_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_GEN_BATTERY_GET_MSG_LEN (2 + 0 + 4) /* Generic location client messages length */ -#define BT_MESH_GEN_LOC_GLOBAL_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_GEN_LOC_GLOBAL_SET_MSG_LEN (1 + 10 + 4) -#define BT_MESH_GEN_LOC_LOCAL_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_GEN_LOC_LOCAL_SET_MSG_LEN (2 + 9 + 4) +#define BLE_MESH_GEN_LOC_GLOBAL_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_GEN_LOC_GLOBAL_SET_MSG_LEN (1 + 10 + 4) +#define BLE_MESH_GEN_LOC_LOCAL_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_GEN_LOC_LOCAL_SET_MSG_LEN (2 + 9 + 4) /* Generic property client messages length */ -#define BT_MESH_GEN_USER_PROPERTIES_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_GEN_USER_PROPERTY_GET_MSG_LEN (2 + 2 + 4) -#define BT_MESH_GEN_USER_PROPERTY_SET_MSG_LEN /* variable */ -#define BT_MESH_GEN_ADMIN_PROPERTIES_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_GEN_ADMIN_PROPERTY_GET_MSG_LEN (2 + 2 + 4) -#define BT_MESH_GEN_ADMIN_PROPERTY_SET_MSG_LEN /* variable */ -#define BT_MESH_GEN_MANU_PROPERTIES_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_GEN_MANU_PROPERTY_GET_MSG_LEN (2 + 2 + 4) -#define BT_MESH_GEN_MANU_PROPERTY_SET_MSG_LEN (1 + 3 + 4) -#define BT_MESH_GEN_CLINET_PROPERTIES_GET_MSG_LEN (1 + 2 + 4) +#define BLE_MESH_GEN_USER_PROPERTIES_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_GEN_USER_PROPERTY_GET_MSG_LEN (2 + 2 + 4) +#define BLE_MESH_GEN_USER_PROPERTY_SET_MSG_LEN /* variable */ +#define BLE_MESH_GEN_ADMIN_PROPERTIES_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_GEN_ADMIN_PROPERTY_GET_MSG_LEN (2 + 2 + 4) +#define BLE_MESH_GEN_ADMIN_PROPERTY_SET_MSG_LEN /* variable */ +#define BLE_MESH_GEN_MANU_PROPERTIES_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_GEN_MANU_PROPERTY_GET_MSG_LEN (2 + 2 + 4) +#define BLE_MESH_GEN_MANU_PROPERTY_SET_MSG_LEN (1 + 3 + 4) +#define BLE_MESH_GEN_CLINET_PROPERTIES_GET_MSG_LEN (1 + 2 + 4) -#define BT_MESH_GEN_GET_STATE_MSG_LEN (2 + 2 + 4) +#define BLE_MESH_GEN_GET_STATE_MSG_LEN (2 + 2 + 4) static const bt_mesh_client_op_pair_t gen_op_pair[] = { - { BT_MESH_MODEL_OP_GEN_ONOFF_GET, BT_MESH_MODEL_OP_GEN_ONOFF_STATUS }, - { BT_MESH_MODEL_OP_GEN_ONOFF_SET, BT_MESH_MODEL_OP_GEN_ONOFF_STATUS }, - { BT_MESH_MODEL_OP_GEN_LEVEL_GET, BT_MESH_MODEL_OP_GEN_LEVEL_STATUS }, - { BT_MESH_MODEL_OP_GEN_LEVEL_SET, BT_MESH_MODEL_OP_GEN_LEVEL_STATUS }, - { BT_MESH_MODEL_OP_GEN_DELTA_SET, BT_MESH_MODEL_OP_GEN_LEVEL_STATUS }, - { BT_MESH_MODEL_OP_GEN_MOVE_SET, BT_MESH_MODEL_OP_GEN_LEVEL_STATUS }, - { BT_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_GET, BT_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS }, - { BT_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET, BT_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS }, - { BT_MESH_MODEL_OP_GEN_ONPOWERUP_GET, BT_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS }, - { BT_MESH_MODEL_OP_GEN_ONPOWERUP_SET, BT_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS }, - { BT_MESH_MODEL_OP_GEN_POWER_LEVEL_GET, BT_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS }, - { BT_MESH_MODEL_OP_GEN_POWER_LEVEL_SET, BT_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS }, - { BT_MESH_MODEL_OP_GEN_POWER_LAST_GET, BT_MESH_MODEL_OP_GEN_POWER_LAST_STATUS }, - { BT_MESH_MODEL_OP_GEN_POWER_DEFAULT_GET, BT_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS }, - { BT_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET, BT_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS }, - { BT_MESH_MODEL_OP_GEN_POWER_RANGE_GET, BT_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS }, - { BT_MESH_MODEL_OP_GEN_POWER_RANGE_SET, BT_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS }, - { BT_MESH_MODEL_OP_GEN_BATTERY_GET, BT_MESH_MODEL_OP_GEN_BATTERY_STATUS }, - { BT_MESH_MODEL_OP_GEN_LOC_GLOBAL_GET, BT_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS }, - { BT_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET, BT_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS }, - { BT_MESH_MODEL_OP_GEN_LOC_LOCAL_GET, BT_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS }, - { BT_MESH_MODEL_OP_GEN_LOC_LOCAL_SET, BT_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS }, - { BT_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET, BT_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS }, - { BT_MESH_MODEL_OP_GEN_USER_PROPERTY_GET, BT_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS }, - { BT_MESH_MODEL_OP_GEN_USER_PROPERTY_SET, BT_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS }, - { BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET, BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS }, - { BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET, BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS }, - { BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET, BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS }, - { BT_MESH_MODEL_OP_GEN_MANU_PROPERTIES_GET, BT_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS }, - { BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET, BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS }, - { BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET, BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS }, - { BT_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET, BT_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS }, + { BLE_MESH_MODEL_OP_GEN_ONOFF_GET, BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS }, + { BLE_MESH_MODEL_OP_GEN_ONOFF_SET, BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS }, + { BLE_MESH_MODEL_OP_GEN_LEVEL_GET, BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS }, + { BLE_MESH_MODEL_OP_GEN_LEVEL_SET, BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS }, + { BLE_MESH_MODEL_OP_GEN_DELTA_SET, BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS }, + { BLE_MESH_MODEL_OP_GEN_MOVE_SET, BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS }, + { BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_GET, BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS }, + { BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET, BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS }, + { BLE_MESH_MODEL_OP_GEN_ONPOWERUP_GET, BLE_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS }, + { BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET, BLE_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS }, + { BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_GET, BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS }, + { BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET, BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS }, + { BLE_MESH_MODEL_OP_GEN_POWER_LAST_GET, BLE_MESH_MODEL_OP_GEN_POWER_LAST_STATUS }, + { BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_GET, BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS }, + { BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET, BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS }, + { BLE_MESH_MODEL_OP_GEN_POWER_RANGE_GET, BLE_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS }, + { BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET, BLE_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS }, + { BLE_MESH_MODEL_OP_GEN_BATTERY_GET, BLE_MESH_MODEL_OP_GEN_BATTERY_STATUS }, + { BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_GET, BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS }, + { BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET, BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS }, + { BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_GET, BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS }, + { BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET, BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS }, + { BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET, BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS }, + { BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET, BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS }, + { BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET, BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS }, + { BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET, BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS }, + { BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET, BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS }, + { BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET, BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS }, + { BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_GET, BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS }, + { BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET, BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS }, + { BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET, BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS }, + { BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET, BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS }, }; static void timeout_handler(struct k_work *work) { - bt_mesh_generic_client_t *client = NULL; - generic_internal_data_t *internal = NULL; - bt_mesh_client_node_t *node = NULL; + generic_internal_data_t *internal = NULL; + bt_mesh_generic_client_t *client = NULL; + bt_mesh_client_node_t *node = NULL; BT_WARN("Receive generic status message timeout"); node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work); if (!node || !node->ctx.model) { - BT_ERR("%s: node parameter is NULL", __func__); + BT_ERR("%s, Invalid parameter", __func__); return; } client = (bt_mesh_generic_client_t *)node->ctx.model->user_data; if (!client) { - BT_ERR("%s: model user_data is NULL", __func__); + BT_ERR("%s, Generic Client user_data is NULL", __func__); return; } internal = (generic_internal_data_t *)client->internal_data; if (!internal) { - BT_ERR("%s: internal_data is NULL", __func__); + BT_ERR("%s, Generic Client internal_data is NULL", __func__); return; } @@ -158,82 +157,82 @@ static void generic_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { - bt_mesh_generic_client_t *client = NULL; - generic_internal_data_t *internal = NULL; - bt_mesh_client_node_t *node = NULL; + generic_internal_data_t *internal = NULL; + bt_mesh_generic_client_t *client = NULL; + bt_mesh_client_node_t *node = NULL; u8_t *val = NULL; u8_t evt = 0xFF; u32_t rsp = 0; size_t len = 0; - BT_DBG("%s: len %d, bytes %s", __func__, buf->len, bt_hex(buf->data, buf->len)); + BT_DBG("%s, len %d, bytes %s", __func__, buf->len, bt_hex(buf->data, buf->len)); client = (bt_mesh_generic_client_t *)model->user_data; if (!client) { - BT_ERR("%s: model user_data is NULL", __func__); + BT_ERR("%s, Generic Client user_data is NULL", __func__); return; } internal = (generic_internal_data_t *)client->internal_data; if (!internal) { - BT_ERR("%s: model internal_data is NULL", __func__); + BT_ERR("%s, Generic Client internal_data is NULL", __func__); return; } rsp = ctx->recv_op; switch (rsp) { - case BT_MESH_MODEL_OP_GEN_ONOFF_STATUS: { + case BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS: { struct bt_mesh_gen_onoff_status *status = NULL; if (buf->len != 1 && buf->len != 3) { - BT_ERR("Wrong Generic OnOff status length %d", buf->len); + BT_ERR("Invalid Generic OnOff Status length %d", buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_gen_onoff_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->present_onoff = net_buf_simple_pull_u8(buf); if (buf->len) { - status->op_en = true; + status->op_en = true; status->target_onoff = net_buf_simple_pull_u8(buf); - status->remain_time = net_buf_simple_pull_u8(buf); + status->remain_time = net_buf_simple_pull_u8(buf); } val = (u8_t *)status; len = sizeof(struct bt_mesh_gen_onoff_status); break; } - case BT_MESH_MODEL_OP_GEN_LEVEL_STATUS: { + case BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS: { struct bt_mesh_gen_level_status *status = NULL; if (buf->len != 2 && buf->len != 5) { - BT_ERR("Wrong Generic level status length %d", buf->len); + BT_ERR("Invalid Generic Level Status length %d", buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_gen_level_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->present_level = net_buf_simple_pull_le16(buf); if (buf->len) { - status->op_en = true; + status->op_en = true; status->target_level = net_buf_simple_pull_le16(buf); - status->remain_time = net_buf_simple_pull_u8(buf); + status->remain_time = net_buf_simple_pull_u8(buf); } val = (u8_t *)status; len = sizeof(struct bt_mesh_gen_level_status); break; } - case BT_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS: { + case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS: { struct bt_mesh_gen_def_trans_time_status *status = NULL; if (buf->len != 1) { - BT_ERR("Wrong Generic default transition time status length %d", buf->len); + BT_ERR("Invalid Generic Default Trans Time Status length %d", buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_gen_def_trans_time_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->trans_time = net_buf_simple_pull_u8(buf); @@ -241,15 +240,15 @@ static void generic_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_gen_def_trans_time_status); break; } - case BT_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS: { + case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS: { struct bt_mesh_gen_onpowerup_status *status = NULL; if (buf->len != 1) { - BT_ERR("Wrong Generic OnPowerUp status length %d", buf->len); + BT_ERR("Invalid Generic OnPowerUp Status length %d", buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_gen_onpowerup_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->onpowerup = net_buf_simple_pull_u8(buf); @@ -257,36 +256,36 @@ static void generic_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_gen_onpowerup_status); break; } - case BT_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS: { + case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS: { struct bt_mesh_gen_power_level_status *status = NULL; if (buf->len != 2 && buf->len != 5) { - BT_ERR("Wrong Generic power level status length %d", buf->len); + BT_ERR("Invalid Generic Power Level Status length %d", buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_gen_power_level_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->present_power = net_buf_simple_pull_le16(buf); if (buf->len) { - status->op_en = true; + status->op_en = true; status->target_power = net_buf_simple_pull_le16(buf); - status->remain_time = net_buf_simple_pull_u8(buf); + status->remain_time = net_buf_simple_pull_u8(buf); } val = (u8_t *)status; len = sizeof(struct bt_mesh_gen_power_level_status); break; } - case BT_MESH_MODEL_OP_GEN_POWER_LAST_STATUS: { + case BLE_MESH_MODEL_OP_GEN_POWER_LAST_STATUS: { struct bt_mesh_gen_power_last_status *status = NULL; if (buf->len != 2) { - BT_ERR("Wrong Generic power last status length %d", buf->len); + BT_ERR("Invalid Generic Power Last Status length %d", buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_gen_power_last_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->power = net_buf_simple_pull_le16(buf); @@ -294,15 +293,15 @@ static void generic_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_gen_power_last_status); break; } - case BT_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS: { + case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS: { struct bt_mesh_gen_power_default_status *status = NULL; if (buf->len != 2) { - BT_ERR("Wrong Generic power default status length %d", buf->len); + BT_ERR("Invalid Generic Power Default Status length %d", buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_gen_power_default_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->power = net_buf_simple_pull_le16(buf); @@ -310,94 +309,94 @@ static void generic_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_gen_power_default_status); break; } - case BT_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS: { + case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS: { struct bt_mesh_gen_power_range_status *status = NULL; if (buf->len != 5) { - BT_ERR("Wrong Generic power range status length %d", buf->len); + BT_ERR("Invalid Generic Power Range Status length %d", buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_gen_power_range_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->status_code = net_buf_simple_pull_u8(buf); - status->range_min = net_buf_simple_pull_le16(buf); - status->range_max = net_buf_simple_pull_le16(buf); + status->range_min = net_buf_simple_pull_le16(buf); + status->range_max = net_buf_simple_pull_le16(buf); val = (u8_t *)status; len = sizeof(struct bt_mesh_gen_power_range_status); break; } - case BT_MESH_MODEL_OP_GEN_BATTERY_STATUS: { + case BLE_MESH_MODEL_OP_GEN_BATTERY_STATUS: { struct bt_mesh_gen_battery_status *status = NULL; if (buf->len != 8) { - BT_ERR("Wrong Generic battery status length %d", buf->len); + BT_ERR("Invalid Generic Battery Status length %d", buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_gen_battery_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } u32_t value = 0; value = net_buf_simple_pull_le32(buf); - status->battery_level = (u8_t)value; + status->battery_level = (u8_t)value; status->time_to_discharge = (value >> 8); value = net_buf_simple_pull_le32(buf); - status->time_to_charge = (value & 0xffffff); - status->flags = (u8_t)(value >> 24); + status->time_to_charge = (value & 0xffffff); + status->flags = (u8_t)(value >> 24); val = (u8_t *)status; len = sizeof(struct bt_mesh_gen_battery_status); break; } - case BT_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS: { + case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS: { struct bt_mesh_gen_loc_global_status *status = NULL; if (buf->len != 10) { - BT_ERR("Wrong Generic location global status length %d", buf->len); + BT_ERR("Invalid Generic Location Global Status length %d", buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_gen_loc_global_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } - status->global_latitude = net_buf_simple_pull_le32(buf); + status->global_latitude = net_buf_simple_pull_le32(buf); status->global_longitude = net_buf_simple_pull_le32(buf); - status->global_altitude = net_buf_simple_pull_le16(buf); + status->global_altitude = net_buf_simple_pull_le16(buf); val = (u8_t *)status; len = sizeof(struct bt_mesh_gen_loc_global_status); break; } - case BT_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS: { + case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS: { struct bt_mesh_gen_loc_local_status *status = NULL; if (buf->len != 9) { - BT_ERR("Wrong Generic location local status length %d", buf->len); + BT_ERR("Invalid Generic Location Local Status length %d", buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_gen_loc_local_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } - status->local_north = net_buf_simple_pull_le16(buf); - status->local_east = net_buf_simple_pull_le16(buf); + status->local_north = net_buf_simple_pull_le16(buf); + status->local_east = net_buf_simple_pull_le16(buf); status->local_altitude = net_buf_simple_pull_le16(buf); - status->floor_number = net_buf_simple_pull_u8(buf); - status->uncertainty = net_buf_simple_pull_le16(buf); + status->floor_number = net_buf_simple_pull_u8(buf); + status->uncertainty = net_buf_simple_pull_le16(buf); val = (u8_t *)status; len = sizeof(struct bt_mesh_gen_loc_local_status); break; } - case BT_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS: { + case BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS: { struct bt_mesh_gen_user_properties_status *status = NULL; status = osi_calloc(sizeof(struct bt_mesh_gen_user_properties_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->user_property_ids = bt_mesh_alloc_buf(buf->len); if (!status->user_property_ids) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); osi_free(status); return; } @@ -407,20 +406,20 @@ static void generic_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_gen_user_properties_status); break; } - case BT_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS: { + case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS: { struct bt_mesh_gen_user_property_status *status = NULL; status = osi_calloc(sizeof(struct bt_mesh_gen_user_property_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->user_property_id = net_buf_simple_pull_le16(buf); if (buf->len) { - status->op_en = true; + status->op_en = true; 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: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); osi_free(status); return; } @@ -431,16 +430,16 @@ static void generic_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_gen_user_property_status); break; } - case BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS: { + case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS: { struct bt_mesh_gen_admin_properties_status *status = NULL; status = osi_calloc(sizeof(struct bt_mesh_gen_admin_properties_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->admin_property_ids = bt_mesh_alloc_buf(buf->len); if (!status->admin_property_ids) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); osi_free(status); return; } @@ -450,20 +449,20 @@ static void generic_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_gen_admin_properties_status); break; } - case BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS: { + case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS: { struct bt_mesh_gen_admin_property_status *status = NULL; status = osi_calloc(sizeof(struct bt_mesh_gen_admin_property_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->admin_property_id = net_buf_simple_pull_le16(buf); if (buf->len) { - status->op_en = true; + status->op_en = true; 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: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); osi_free(status); return; } @@ -474,16 +473,16 @@ static void generic_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_gen_admin_property_status); break; } - case BT_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS: { + case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS: { struct bt_mesh_gen_manu_properties_status *status = NULL; status = osi_calloc(sizeof(struct bt_mesh_gen_manu_properties_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->manu_property_ids = bt_mesh_alloc_buf(buf->len); if (!status->manu_property_ids) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); osi_free(status); return; } @@ -493,20 +492,20 @@ static void generic_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_gen_manu_properties_status); break; } - case BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS: { + case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS: { struct bt_mesh_gen_manu_property_status *status = NULL; status = osi_calloc(sizeof(struct bt_mesh_gen_manu_property_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->manu_property_id = net_buf_simple_pull_le16(buf); if (buf->len) { - status->op_en = true; + status->op_en = true; 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: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); osi_free(status); return; } @@ -517,16 +516,16 @@ static void generic_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_gen_manu_property_status); break; } - case BT_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS: { + case BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS: { struct bt_mesh_gen_client_properties_status *status = NULL; status = osi_calloc(sizeof(struct bt_mesh_gen_client_properties_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->client_property_ids = bt_mesh_alloc_buf(buf->len); if (!status->client_property_ids) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); osi_free(status); return; } @@ -537,7 +536,7 @@ static void generic_status(struct bt_mesh_model *model, break; } default: - BT_ERR("Not a generic status message opcode"); + BT_ERR("%s, Not a Generic Status message opcode", __func__); return; } @@ -548,40 +547,40 @@ static void generic_status(struct bt_mesh_model *model, BT_DBG("Unexpected generic status message 0x%x", rsp); } else { switch (node->opcode) { - case BT_MESH_MODEL_OP_GEN_ONOFF_GET: - case BT_MESH_MODEL_OP_GEN_LEVEL_GET: - case BT_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_GET: - case BT_MESH_MODEL_OP_GEN_ONPOWERUP_GET: - case BT_MESH_MODEL_OP_GEN_POWER_LEVEL_GET: - case BT_MESH_MODEL_OP_GEN_POWER_LAST_GET: - case BT_MESH_MODEL_OP_GEN_POWER_DEFAULT_GET: - case BT_MESH_MODEL_OP_GEN_POWER_RANGE_GET: - case BT_MESH_MODEL_OP_GEN_BATTERY_GET: - case BT_MESH_MODEL_OP_GEN_LOC_GLOBAL_GET: - case BT_MESH_MODEL_OP_GEN_LOC_LOCAL_GET: - case BT_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET: - case BT_MESH_MODEL_OP_GEN_USER_PROPERTY_GET: - case BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET: - case BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET: - case BT_MESH_MODEL_OP_GEN_MANU_PROPERTIES_GET: - case BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET: - case BT_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET: + case BLE_MESH_MODEL_OP_GEN_ONOFF_GET: + case BLE_MESH_MODEL_OP_GEN_LEVEL_GET: + case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_GET: + case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_GET: + case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_GET: + case BLE_MESH_MODEL_OP_GEN_POWER_LAST_GET: + case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_GET: + case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_GET: + case BLE_MESH_MODEL_OP_GEN_BATTERY_GET: + case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_GET: + case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_GET: + case BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET: + case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET: + case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET: + case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET: + case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_GET: + case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET: + case BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET: evt = 0x00; break; - case BT_MESH_MODEL_OP_GEN_ONOFF_SET: - case BT_MESH_MODEL_OP_GEN_LEVEL_SET: - case BT_MESH_MODEL_OP_GEN_DELTA_SET: - case BT_MESH_MODEL_OP_GEN_MOVE_SET: - case BT_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET: - case BT_MESH_MODEL_OP_GEN_ONPOWERUP_SET: - case BT_MESH_MODEL_OP_GEN_POWER_LEVEL_SET: - case BT_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET: - case BT_MESH_MODEL_OP_GEN_POWER_RANGE_SET: - case BT_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET: - case BT_MESH_MODEL_OP_GEN_LOC_LOCAL_SET: - case BT_MESH_MODEL_OP_GEN_USER_PROPERTY_SET: - case BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET: - case BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET: + case BLE_MESH_MODEL_OP_GEN_ONOFF_SET: + case BLE_MESH_MODEL_OP_GEN_LEVEL_SET: + case BLE_MESH_MODEL_OP_GEN_DELTA_SET: + case BLE_MESH_MODEL_OP_GEN_MOVE_SET: + case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET: + case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET: + case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET: + case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET: + case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET: + case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET: + case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET: + case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET: + case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET: + case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET: evt = 0x01; break; default: @@ -594,43 +593,43 @@ static void generic_status(struct bt_mesh_model *model, } switch (rsp) { - case BT_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS: { + case BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS: { struct bt_mesh_gen_user_properties_status *status; status = (struct bt_mesh_gen_user_properties_status *)val; bt_mesh_free_buf(status->user_property_ids); break; } - case BT_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS: { + case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS: { struct bt_mesh_gen_user_property_status *status; status = (struct bt_mesh_gen_user_property_status *)val; bt_mesh_free_buf(status->user_property_value); break; } - case BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS: { + case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS: { struct bt_mesh_gen_admin_properties_status *status; status = (struct bt_mesh_gen_admin_properties_status *)val; bt_mesh_free_buf(status->admin_property_ids); break; } - case BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS: { + case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS: { struct bt_mesh_gen_admin_property_status *status; status = (struct bt_mesh_gen_admin_property_status *)val; bt_mesh_free_buf(status->admin_property_value); break; } - case BT_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS: { + case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS: { struct bt_mesh_gen_manu_properties_status *status; status = (struct bt_mesh_gen_manu_properties_status *)val; bt_mesh_free_buf(status->manu_property_ids); break; } - case BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS: { + case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS: { struct bt_mesh_gen_manu_property_status *status; status = (struct bt_mesh_gen_manu_property_status *)val; bt_mesh_free_buf(status->manu_property_value); break; } - case BT_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS: { + case BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS: { struct bt_mesh_gen_client_properties_status *status; status = (struct bt_mesh_gen_client_properties_status *)val; bt_mesh_free_buf(status->client_property_ids); @@ -646,83 +645,83 @@ static void generic_status(struct bt_mesh_model *model, } const struct bt_mesh_model_op gen_onoff_cli_op[] = { - { BT_MESH_MODEL_OP_GEN_ONOFF_STATUS, 1, generic_status }, - BT_MESH_MODEL_OP_END, + { 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[] = { - { BT_MESH_MODEL_OP_GEN_LEVEL_STATUS, 2, generic_status }, - BT_MESH_MODEL_OP_END, + { 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[] = { - { BT_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS, 1, generic_status }, - BT_MESH_MODEL_OP_END, + { 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[] = { - { BT_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS, 1, generic_status }, - BT_MESH_MODEL_OP_END, + { 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[] = { - { BT_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS, 2, generic_status }, - { BT_MESH_MODEL_OP_GEN_POWER_LAST_STATUS, 2, generic_status }, - { BT_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS, 2, generic_status }, - { BT_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS, 5, generic_status }, - BT_MESH_MODEL_OP_END, + { 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 }, + { BLE_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS, 5, generic_status }, + BLE_MESH_MODEL_OP_END, }; const struct bt_mesh_model_op gen_battery_cli_op[] = { - { BT_MESH_MODEL_OP_GEN_BATTERY_STATUS, 8, generic_status }, - BT_MESH_MODEL_OP_END, + { 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[] = { - { BT_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS, 10, generic_status }, - { BT_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS, 9, generic_status }, - BT_MESH_MODEL_OP_END, + { 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[] = { - { BT_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS, 2, generic_status }, - { BT_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS, 2, generic_status }, - { BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS, 2, generic_status }, - { BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS, 2, generic_status }, - { BT_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS, 2, generic_status }, - { BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS, 2, generic_status }, - { BT_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS, 2, generic_status }, - BT_MESH_MODEL_OP_END, + { 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 }, + { BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS, 2, generic_status }, + { BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS, 2, generic_status }, + { BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS, 2, generic_status }, + { BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS, 2, generic_status }, + BLE_MESH_MODEL_OP_END, }; static int gen_get_state(struct bt_mesh_common_param *common, void *value) { - struct net_buf_simple *msg = NET_BUF_SIMPLE(BT_MESH_GEN_GET_STATE_MSG_LEN); + struct net_buf_simple *msg = NET_BUF_SIMPLE(BLE_MESH_GEN_GET_STATE_MSG_LEN); int err; bt_mesh_model_msg_init(msg, common->opcode); if (value) { switch (common->opcode) { - case BT_MESH_MODEL_OP_GEN_USER_PROPERTY_GET: { + case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET: { struct bt_mesh_gen_user_property_get *get; get = (struct bt_mesh_gen_user_property_get *)value; net_buf_simple_add_le16(msg, get->user_property_id); break; } - case BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET: { + case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET: { struct bt_mesh_gen_admin_property_get *get; get = (struct bt_mesh_gen_admin_property_get *)value; net_buf_simple_add_le16(msg, get->admin_property_id); break; } - case BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET: { + case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET: { struct bt_mesh_gen_manu_property_get *get; get = (struct bt_mesh_gen_manu_property_get *)value; net_buf_simple_add_le16(msg, get->manu_property_id); break; } - case BT_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET: { + case BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET: { struct bt_mesh_gen_client_properties_get *get; get = (struct bt_mesh_gen_client_properties_get *)value; net_buf_simple_add_le16(msg, get->client_property_id); @@ -738,7 +737,7 @@ static int gen_get_state(struct bt_mesh_common_param *common, void *value) timeout_handler, common->msg_timeout, true, common->cb, common->cb_data); if (err) { - BT_ERR("Generic get message send failed (err %d)", err); + BT_ERR("%s, Failed to send Generic Get message (err %d)", __func__, err); } return err; @@ -752,15 +751,15 @@ static int gen_set_state(struct bt_mesh_common_param *common, msg = bt_mesh_alloc_buf(value_len); if (!msg) { - BT_ERR("Generic set allocate memory fail"); + BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; } bt_mesh_model_msg_init(msg, common->opcode); switch (common->opcode) { - case BT_MESH_MODEL_OP_GEN_ONOFF_SET: - case BT_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_ONOFF_SET: + case BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK: { struct bt_mesh_gen_onoff_set *set; set = (struct bt_mesh_gen_onoff_set *)value; net_buf_simple_add_u8(msg, set->onoff); @@ -772,8 +771,8 @@ static int gen_set_state(struct bt_mesh_common_param *common, break; } - case BT_MESH_MODEL_OP_GEN_LEVEL_SET: - case BT_MESH_MODEL_OP_GEN_LEVEL_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_LEVEL_SET: + case BLE_MESH_MODEL_OP_GEN_LEVEL_SET_UNACK: { struct bt_mesh_gen_level_set *set; set = (struct bt_mesh_gen_level_set *)value; net_buf_simple_add_le16(msg, set->level); @@ -785,8 +784,8 @@ static int gen_set_state(struct bt_mesh_common_param *common, break; } - case BT_MESH_MODEL_OP_GEN_DELTA_SET: - case BT_MESH_MODEL_OP_GEN_DELTA_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_DELTA_SET: + case BLE_MESH_MODEL_OP_GEN_DELTA_SET_UNACK: { struct bt_mesh_gen_delta_set *set; set = (struct bt_mesh_gen_delta_set *)value; net_buf_simple_add_le32(msg, set->level); @@ -798,8 +797,8 @@ static int gen_set_state(struct bt_mesh_common_param *common, break; } - case BT_MESH_MODEL_OP_GEN_MOVE_SET: - case BT_MESH_MODEL_OP_GEN_MOVE_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_MOVE_SET: + case BLE_MESH_MODEL_OP_GEN_MOVE_SET_UNACK: { struct bt_mesh_gen_move_set *set; set = (struct bt_mesh_gen_move_set *)value; net_buf_simple_add_le16(msg, set->delta_level); @@ -811,24 +810,24 @@ static int gen_set_state(struct bt_mesh_common_param *common, break; } - case BT_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET: - case BT_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET: + case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET_UNACK: { struct bt_mesh_gen_def_trans_time_set *set; set = (struct bt_mesh_gen_def_trans_time_set *)value; net_buf_simple_add_u8(msg, set->trans_time); break; } - case BT_MESH_MODEL_OP_GEN_ONPOWERUP_SET: - case BT_MESH_MODEL_OP_GEN_ONPOWERUP_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET: + case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET_UNACK: { struct bt_mesh_gen_onpowerup_set *set; set = (struct bt_mesh_gen_onpowerup_set *)value; net_buf_simple_add_u8(msg, set->onpowerup); break; } - case BT_MESH_MODEL_OP_GEN_POWER_LEVEL_SET: - case BT_MESH_MODEL_OP_GEN_POWER_LEVEL_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET: + case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET_UNACK: { struct bt_mesh_gen_power_level_set *set; set = (struct bt_mesh_gen_power_level_set *)value; net_buf_simple_add_le16(msg, set->power); @@ -840,16 +839,16 @@ static int gen_set_state(struct bt_mesh_common_param *common, break; } - case BT_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET: - case BT_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET: + case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET_UNACK: { struct bt_mesh_gen_power_default_set *set; set = (struct bt_mesh_gen_power_default_set *)value; net_buf_simple_add_le16(msg, set->power); break; } - case BT_MESH_MODEL_OP_GEN_POWER_RANGE_SET: - case BT_MESH_MODEL_OP_GEN_POWER_RANGE_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET: + case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET_UNACK: { struct bt_mesh_gen_power_range_set *set; set = (struct bt_mesh_gen_power_range_set *)value; net_buf_simple_add_le16(msg, set->range_min); @@ -857,8 +856,8 @@ static int gen_set_state(struct bt_mesh_common_param *common, break; } - case BT_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET: - case BT_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET: + case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET_UNACK: { struct bt_mesh_gen_loc_global_set *set; set = (struct bt_mesh_gen_loc_global_set *)value; net_buf_simple_add_le32(msg, set->global_latitude); @@ -867,8 +866,8 @@ static int gen_set_state(struct bt_mesh_common_param *common, break; } - case BT_MESH_MODEL_OP_GEN_LOC_LOCAL_SET: - case BT_MESH_MODEL_OP_GEN_LOC_LOCAL_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET: + case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET_UNACK: { struct bt_mesh_gen_loc_local_set *set; set = (struct bt_mesh_gen_loc_local_set *)value; net_buf_simple_add_le16(msg, set->local_north); @@ -879,8 +878,8 @@ static int gen_set_state(struct bt_mesh_common_param *common, break; } - case BT_MESH_MODEL_OP_GEN_USER_PROPERTY_SET: - case BT_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET: + case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK: { struct bt_mesh_gen_user_property_set *set; set = (struct bt_mesh_gen_user_property_set *)value; net_buf_simple_add_le16(msg, set->user_property_id); @@ -888,8 +887,8 @@ static int gen_set_state(struct bt_mesh_common_param *common, break; } - case BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET: - case BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET: + case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK: { struct bt_mesh_gen_admin_property_set *set; set = (struct bt_mesh_gen_admin_property_set *)value; net_buf_simple_add_le16(msg, set->admin_property_id); @@ -898,8 +897,8 @@ static int gen_set_state(struct bt_mesh_common_param *common, break; } - case BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET: - case BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET: + case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET_UNACK: { struct bt_mesh_gen_manu_property_set *set; set = (struct bt_mesh_gen_manu_property_set *)value; net_buf_simple_add_le16(msg, set->manu_property_id); @@ -908,7 +907,7 @@ static int gen_set_state(struct bt_mesh_common_param *common, } default: - BT_ERR("Not a generic client model set message opcode"); + BT_ERR("%s, Not a Generic Client Set message opcode", __func__); err = -EINVAL; goto end; } @@ -917,7 +916,7 @@ static int gen_set_state(struct bt_mesh_common_param *common, timeout_handler, common->msg_timeout, need_ack, common->cb, common->cb_data); if (err) { - BT_ERR("Generic set message send failed (err %d)", err); + BT_ERR("%s, Failed to send Generic Set message (err %d)", __func__, err); } end: @@ -931,58 +930,58 @@ int bt_mesh_generic_client_get_state(struct bt_mesh_common_param *common, void * bt_mesh_generic_client_t *client = NULL; if (!common || !common->model) { - BT_ERR("%s: common parameter is NULL", __func__); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } client = (bt_mesh_generic_client_t *)common->model->user_data; if (!client || !client->internal_data) { - BT_ERR("%s: client parameter is NULL", __func__); + BT_ERR("%s, Generic Client user data is NULL", __func__); return -EINVAL; } switch (common->opcode) { - case BT_MESH_MODEL_OP_GEN_ONOFF_GET: - case BT_MESH_MODEL_OP_GEN_LEVEL_GET: - case BT_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_GET: - case BT_MESH_MODEL_OP_GEN_ONPOWERUP_GET: - case BT_MESH_MODEL_OP_GEN_POWER_LEVEL_GET: - case BT_MESH_MODEL_OP_GEN_POWER_LAST_GET: - case BT_MESH_MODEL_OP_GEN_POWER_DEFAULT_GET: - case BT_MESH_MODEL_OP_GEN_POWER_RANGE_GET: - case BT_MESH_MODEL_OP_GEN_BATTERY_GET: - case BT_MESH_MODEL_OP_GEN_LOC_GLOBAL_GET: - case BT_MESH_MODEL_OP_GEN_LOC_LOCAL_GET: - case BT_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET: - case BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET: - case BT_MESH_MODEL_OP_GEN_MANU_PROPERTIES_GET: + case BLE_MESH_MODEL_OP_GEN_ONOFF_GET: + case BLE_MESH_MODEL_OP_GEN_LEVEL_GET: + case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_GET: + case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_GET: + case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_GET: + case BLE_MESH_MODEL_OP_GEN_POWER_LAST_GET: + case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_GET: + case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_GET: + case BLE_MESH_MODEL_OP_GEN_BATTERY_GET: + case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_GET: + case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_GET: + case BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET: + case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET: + case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_GET: break; - case BT_MESH_MODEL_OP_GEN_USER_PROPERTY_GET: + case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET: if (!get) { - BT_ERR("Generic user_property_get is NULL"); + BT_ERR("%s, Generic user_property_get is NULL", __func__); return -EINVAL; } break; - case BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET: + case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET: if (!get) { - BT_ERR("Generic admin_property_get is NULL"); + BT_ERR("%s, Generic admin_property_get is NULL", __func__); return -EINVAL; } break; - case BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET: + case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET: if (!get) { - BT_ERR("Generic manu_property_get is NULL"); + BT_ERR("%s, Generic manu_property_get is NULL", __func__); return -EINVAL; } break; - case BT_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET: + case BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET: if (!get) { - BT_ERR("Generic client_properties_get is NULL"); + BT_ERR("%s, Generic client_properties_get is NULL", __func__); return -EINVAL; } break; default: - BT_ERR("Not a generic get message opcode"); + BT_ERR("%s, Not a Generic Client Get message opcode", __func__); return -EINVAL; } @@ -996,161 +995,161 @@ int bt_mesh_generic_client_set_state(struct bt_mesh_common_param *common, void * bool need_ack = false; if (!common || !common->model || !set) { - BT_ERR("%s: common parameter is NULL", __func__); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } client = (bt_mesh_generic_client_t *)common->model->user_data; if (!client || !client->internal_data) { - BT_ERR("%s: client parameter is NULL", __func__); + BT_ERR("%s, Generic Client user data is NULL", __func__); return -EINVAL; } switch (common->opcode) { - case BT_MESH_MODEL_OP_GEN_ONOFF_SET: + case BLE_MESH_MODEL_OP_GEN_ONOFF_SET: need_ack = true; - case BT_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK: { struct bt_mesh_gen_onoff_set *value; value = (struct bt_mesh_gen_onoff_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("Generic onoff set transition time is bigger than 0x3E"); + BT_ERR("%s, Invalid Generic OnOff Set transition time", __func__); return -EINVAL; } } - length = BT_MESH_GEN_ONOFF_SET_MSG_LEN; + length = BLE_MESH_GEN_ONOFF_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_GEN_LEVEL_SET: + case BLE_MESH_MODEL_OP_GEN_LEVEL_SET: need_ack = true; - case BT_MESH_MODEL_OP_GEN_LEVEL_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_LEVEL_SET_UNACK: { struct bt_mesh_gen_level_set *value; value = (struct bt_mesh_gen_level_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("Generic level set transition time is bigger than 0x3E"); + BT_ERR("%s, Invalid Generic Level Set transition time", __func__); return -EINVAL; } } - length = BT_MESH_GEN_LEVEL_SET_MSG_LEN; + length = BLE_MESH_GEN_LEVEL_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_GEN_DELTA_SET: + case BLE_MESH_MODEL_OP_GEN_DELTA_SET: need_ack = true; - case BT_MESH_MODEL_OP_GEN_DELTA_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_DELTA_SET_UNACK: { struct bt_mesh_gen_delta_set *value; value = (struct bt_mesh_gen_delta_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("Generic delta set transition time is bigger than 0x3E"); + BT_ERR("%s, Invalid Generic Delta Set transition time", __func__); return -EINVAL; } } - length = BT_MESH_GEN_DELTA_SET_MSG_LEN; + length = BLE_MESH_GEN_DELTA_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_GEN_MOVE_SET: + case BLE_MESH_MODEL_OP_GEN_MOVE_SET: need_ack = true; - case BT_MESH_MODEL_OP_GEN_MOVE_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_MOVE_SET_UNACK: { struct bt_mesh_gen_move_set *value; value = (struct bt_mesh_gen_move_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("Generic move set transition time is bigger than 0x3E"); + BT_ERR("%s, Invalid Generic Move Set transition time", __func__); return -EINVAL; } } - length = BT_MESH_GEN_MOVE_SET_MSG_LEN; + length = BLE_MESH_GEN_MOVE_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET: + case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET: need_ack = true; - case BT_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET_UNACK: { u8_t value = *(u8_t *)set; if ((value & 0x3F) > 0x3E) { - BT_ERR("Generic default transition time set transition time is bigger than 0x3E"); + BT_ERR("%s, Invalid Generic Default Trans Time Set transition time", __func__); return -EINVAL; } - length = BT_MESH_GEN_DEF_TRANS_TIME_SET_MSG_LEN; + length = BLE_MESH_GEN_DEF_TRANS_TIME_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_GEN_ONPOWERUP_SET: + case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET: need_ack = true; - case BT_MESH_MODEL_OP_GEN_ONPOWERUP_SET_UNACK: - length = BT_MESH_GEN_ONPOWERUP_SET_MSG_LEN; + case BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET_UNACK: + length = BLE_MESH_GEN_ONPOWERUP_SET_MSG_LEN; break; - case BT_MESH_MODEL_OP_GEN_POWER_LEVEL_SET: + case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET: need_ack = true; - case BT_MESH_MODEL_OP_GEN_POWER_LEVEL_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET_UNACK: { struct bt_mesh_gen_power_level_set *value; value = (struct bt_mesh_gen_power_level_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("Generic power level set transition time is bigger than 0x3E"); + BT_ERR("%s, Invalid Generic Power Level Set transition time", __func__); return -EINVAL; } } - length = BT_MESH_GEN_POWER_LEVEL_SET_MSG_LEN; + length = BLE_MESH_GEN_POWER_LEVEL_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET: + case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET: need_ack = true; - case BT_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET_UNACK: - length = BT_MESH_GEN_POWER_DEFAULT_SET_MSG_LEN; + case BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET_UNACK: + length = BLE_MESH_GEN_POWER_DEFAULT_SET_MSG_LEN; break; - case BT_MESH_MODEL_OP_GEN_POWER_RANGE_SET: + case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET: need_ack = true; - case BT_MESH_MODEL_OP_GEN_POWER_RANGE_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET_UNACK: { 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("Generic power level set range min is greater than range max"); + BT_ERR("%s, Generic Power Level Set range min is greater than range max", __func__); return -EINVAL; } - length = BT_MESH_GEN_POWER_RANGE_SET_MSG_LEN; + length = BLE_MESH_GEN_POWER_RANGE_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET: + case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET: need_ack = true; - case BT_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET_UNACK: - length = BT_MESH_GEN_LOC_GLOBAL_SET_MSG_LEN; + case BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET_UNACK: + length = BLE_MESH_GEN_LOC_GLOBAL_SET_MSG_LEN; break; - case BT_MESH_MODEL_OP_GEN_LOC_LOCAL_SET: + case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET: need_ack = true; - case BT_MESH_MODEL_OP_GEN_LOC_LOCAL_SET_UNACK: - length = BT_MESH_GEN_LOC_LOCAL_SET_MSG_LEN; + case BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET_UNACK: + length = BLE_MESH_GEN_LOC_LOCAL_SET_MSG_LEN; break; - case BT_MESH_MODEL_OP_GEN_USER_PROPERTY_SET: + case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET: need_ack = true; - case BT_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK: { struct bt_mesh_gen_user_property_set *value; value = (struct bt_mesh_gen_user_property_set *)set; if (!value->user_property_value) { - BT_ERR("Generic user_property_value is NULL"); + BT_ERR("%s, Generic user_property_value is NULL", __func__); return -EINVAL; } length = (1 + 2 + value->user_property_value->len + 4); break; } - case BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET: + case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET: need_ack = true; - case BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK: { + case BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK: { struct bt_mesh_gen_admin_property_set *value; value = (struct bt_mesh_gen_admin_property_set *)set; if (!value->admin_property_value) { - BT_ERR("Generic admin_property_value is NULL"); + BT_ERR("%s, Generic admin_property_value is NULL", __func__); return -EINVAL; } length = (1 + 2 + 1 + value->admin_property_value->len + 4); break; } - case BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET: + case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET: need_ack = true; - case BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET_UNACK: - length = BT_MESH_GEN_MANU_PROPERTY_SET_MSG_LEN; + case BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET_UNACK: + length = BLE_MESH_GEN_MANU_PROPERTY_SET_MSG_LEN; break; default: - BT_ERR("Not a generic set message opcode"); + BT_ERR("%s, Not a Generic Client Set message opcode", __func__); return -EINVAL; } @@ -1159,34 +1158,34 @@ int bt_mesh_generic_client_set_state(struct bt_mesh_common_param *common, void * static int generic_client_init(struct bt_mesh_model *model, bool primary) { - bt_mesh_generic_client_t *client = NULL; - generic_internal_data_t *internal = NULL; + generic_internal_data_t *internal = NULL; + bt_mesh_generic_client_t *client = NULL; BT_DBG("primary %u", primary); if (!model) { - BT_ERR("Generic client model is NULL"); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } client = (bt_mesh_generic_client_t *)model->user_data; if (!client) { - BT_ERR("Generic client model user_data is NULL"); + BT_ERR("%s, Generic Client user_data is NULL", __func__); return -EINVAL; } /* TODO: call osi_free() when deinit function is invoked*/ internal = osi_calloc(sizeof(generic_internal_data_t)); if (!internal) { - BT_ERR("Allocate memory for generic onoff internal data fail"); + BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; } sys_slist_init(&internal->queue); - client->model = model; - client->op_pair_size = ARRAY_SIZE(gen_op_pair); - client->op_pair = gen_op_pair; + client->model = model; + client->op_pair_size = ARRAY_SIZE(gen_op_pair); + client->op_pair = gen_op_pair; client->internal_data = internal; return 0; diff --git a/components/bt/ble_mesh/mesh_models/include/common.h b/components/bt/ble_mesh/mesh_models/include/common.h deleted file mode 100644 index b3518c00ab..0000000000 --- a/components/bt/ble_mesh/mesh_models/include/common.h +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright 2017-2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -/** @file - * @brief Bluetooth Mesh Model Common APIs. - */ - -#ifndef __BT_MESH_COMMON_H -#define __BT_MESH_COMMON_H - -#include "../../../bluedroid/osi/include/osi/allocator.h" -#include "mesh_access.h" -#include "mesh_kernel.h" -#include "mesh_main.h" -#include "provisioner_main.h" - -struct bt_mesh_common_param { - u32_t opcode; /* Message opcode */ - struct bt_mesh_model *model; /* Pointer to cli structure */ - struct bt_mesh_msg_ctx ctx; /* Message context */ - s32_t msg_timeout; /* Time to get response messages */ - const struct bt_mesh_send_cb *cb; /* User defined callback function */ - void *cb_data; /* Data as parameter of the cb function */ -}; - -enum { - NODE = 0, - PROVISIONER, - FAST_PROV, -}; - -#define ROLE_NVAL 0xFF - -typedef struct bt_mesh_role_param { - 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 allocates memory to store outgoing message. - * - * @param[in] size: Length of memory allocated to store message value - * - * @return NULL-fail, pointer of a net_buf_simple structure-success - */ -struct net_buf_simple *bt_mesh_alloc_buf(u16_t size); - -/** - * @brief This function releases the memory allocated for the outgoing message. - * - * @param[in] buf: Pointer to the net_buf_simple structure to be freed - * - * @return none - */ -void bt_mesh_free_buf(struct net_buf_simple *buf); - -/** - * @brief This function copies node_index for stack internal use. - * - * @param[in] common: Pointer to the struct bt_mesh_role_param structure - * - * @return Zero - success, otherwise - fail - */ -int bt_mesh_copy_msg_role(bt_mesh_role_param_t *common); - -/** - * @brief This function gets msg role for stack internal use. - * - * @param[in] model: Pointer to the model structure - * @param[in] srv_send: Indicate if the message is sent by a server model - * - * @return 0 - Node, 1 - Provisioner - */ -u8_t bt_mesh_get_msg_role(struct bt_mesh_model *model, bool srv_send); - -#endif /* __BT_MESH_COMMON_H */ \ No newline at end of file diff --git a/components/bt/ble_mesh/mesh_models/include/generic_client.h b/components/bt/ble_mesh/mesh_models/include/generic_client.h index 8e55f567a3..3f272cb952 100644 --- a/components/bt/ble_mesh/mesh_models/include/generic_client.h +++ b/components/bt/ble_mesh/mesh_models/include/generic_client.h @@ -16,13 +16,13 @@ * @brief Bluetooth Mesh Generic Client Model APIs. */ -#ifndef __BT_MESH_GENERIC_CLI_H -#define __BT_MESH_GENERIC_CLI_H +#ifndef _GENERIC_CLIENT_H_ +#define _GENERIC_CLIENT_H_ #include "mesh_access.h" #include "mesh_kernel.h" -#include "common.h" -#include "bt_mesh_client_common.h" + +#include "model_common.h" /* Generic client model common structure */ typedef bt_mesh_client_common_t bt_mesh_generic_client_t; @@ -31,7 +31,7 @@ typedef bt_mesh_internal_data_t generic_internal_data_t; /* Generic OnOff Client Model Context */ extern const struct bt_mesh_model_op gen_onoff_cli_op[]; -/** @def BT_MESH_MODEL_GEN_ONOFF_CLI +/** @def BLE_MESH_MODEL_GEN_ONOFF_CLI * * Define a new generic onoff client model. Note that this API * needs to be repeated for each element which the application @@ -41,8 +41,8 @@ extern const struct bt_mesh_model_op gen_onoff_cli_op[]; * * @return New generic onoff client model instance. */ -#define BT_MESH_MODEL_GEN_ONOFF_CLI(cli_pub, cli_data) \ - BT_MESH_MODEL(BT_MESH_MODEL_ID_GEN_ONOFF_CLI, \ +#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) typedef bt_mesh_client_common_t bt_mesh_gen_onoff_cli_t; @@ -65,7 +65,7 @@ struct bt_mesh_gen_onoff_set { /* Generic Level Client Model Context */ extern const struct bt_mesh_model_op gen_level_cli_op[]; -/** @def BT_MESH_MODEL_GEN_LEVEL_CLI +/** @def BLE_MESH_MODEL_GEN_LEVEL_CLI * * Define a new generic level client model. Note that this API * needs to be repeated for each element which the application @@ -75,8 +75,8 @@ extern const struct bt_mesh_model_op gen_level_cli_op[]; * * @return New generic level client model instance. */ -#define BT_MESH_MODEL_GEN_LEVEL_CLI(cli_pub, cli_data) \ - BT_MESH_MODEL(BT_MESH_MODEL_ID_GEN_LEVEL_CLI, \ +#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) typedef bt_mesh_client_common_t bt_mesh_gen_level_cli_t; @@ -115,7 +115,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[]; -/** @def BT_MESH_MODEL_GEN_DEF_TRANS_TIME_CLI +/** @def BLE_MESH_MODEL_GEN_DEF_TRANS_TIME_CLI * * Define a new generic default transition time client model. Note * that this API needs to be repeated for each element that the @@ -126,8 +126,8 @@ extern const struct bt_mesh_model_op gen_def_trans_time_cli_op[]; * * @return New generic default transition time client model instance. */ -#define BT_MESH_MODEL_GEN_DEF_TRANS_TIME_CLI(cli_pub, cli_data) \ - BT_MESH_MODEL(BT_MESH_MODEL_ID_GEN_DEF_TRANS_TIME_CLI, \ +#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) typedef bt_mesh_client_common_t bt_mesh_gen_def_trans_time_cli_t; @@ -143,7 +143,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[]; -/** @def BT_MESH_MODEL_GEN_POWER_ONOFF_CLI +/** @def BLE_MESH_MODEL_GEN_POWER_ONOFF_CLI * * Define a new generic power onoff client model. Note that this API * needs to be repeated for each element which the application wants @@ -153,8 +153,8 @@ extern const struct bt_mesh_model_op gen_power_onoff_cli_op[]; * * @return New generic power onoff client model instance. */ -#define BT_MESH_MODEL_GEN_POWER_ONOFF_CLI(cli_pub, cli_data) \ - BT_MESH_MODEL(BT_MESH_MODEL_ID_GEN_POWER_ONOFF_CLI, \ +#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) typedef bt_mesh_client_common_t bt_mesh_gen_power_onoff_cli_t; @@ -170,7 +170,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[]; -/** @def BT_MESH_MODEL_GEN_POWER_LEVEL_CLI +/** @def BLE_MESH_MODEL_GEN_POWER_LEVEL_CLI * * Define a new generic power level client model. Note that this API * needs to be repeated for each element which the application wants @@ -180,8 +180,8 @@ extern const struct bt_mesh_model_op gen_power_level_cli_op[]; * * @return New generic power level client model instance. */ -#define BT_MESH_MODEL_GEN_POWER_LEVEL_CLI(cli_pub, cli_data) \ - BT_MESH_MODEL(BT_MESH_MODEL_ID_GEN_POWER_LEVEL_CLI, \ +#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) typedef bt_mesh_client_common_t bt_mesh_gen_power_level_cli_t; @@ -227,7 +227,7 @@ struct bt_mesh_gen_power_range_set { /* Generic Battery Client Model Context */ extern const struct bt_mesh_model_op gen_battery_cli_op[]; -/** @def BT_MESH_MODEL_GEN_BATTERY_CLI +/** @def BLE_MESH_MODEL_GEN_BATTERY_CLI * * Define a new generic battery client model. Note that this API * needs to be repeated for each element which the application @@ -237,8 +237,8 @@ extern const struct bt_mesh_model_op gen_battery_cli_op[]; * * @return New generic battery client model instance. */ -#define BT_MESH_MODEL_GEN_BATTERY_CLI(cli_pub, cli_data) \ - BT_MESH_MODEL(BT_MESH_MODEL_ID_GEN_BATTERY_CLI, \ +#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) typedef bt_mesh_client_common_t bt_mesh_gen_battery_cli_t; @@ -253,7 +253,7 @@ struct bt_mesh_gen_battery_status { /* Generic Location Client Model Context */ extern const struct bt_mesh_model_op gen_location_cli_op[]; -/** @def BT_MESH_MODEL_GEN_LOCATION_CLI +/** @def BLE_MESH_MODEL_GEN_LOCATION_CLI * * Define a new generic location client model. Note that this API * needs to be repeated for each element which the application @@ -263,8 +263,8 @@ extern const struct bt_mesh_model_op gen_location_cli_op[]; * * @return New generic location client model instance. */ -#define BT_MESH_MODEL_GEN_LOCATION_CLI(cli_pub, cli_data) \ - BT_MESH_MODEL(BT_MESH_MODEL_ID_GEN_LOCATION_CLI, \ +#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) typedef bt_mesh_client_common_t bt_mesh_gen_location_cli_t; @@ -300,7 +300,7 @@ struct bt_mesh_gen_loc_local_set { /* Generic Property Client Model Context */ extern const struct bt_mesh_model_op gen_property_cli_op[]; -/** @def BT_MESH_MODEL_GEN_LOCATION_CLI +/** @def BLE_MESH_MODEL_GEN_LOCATION_CLI * * Define a new generic location client model. Note that this API * needs to be repeated for each element which the application @@ -310,8 +310,8 @@ extern const struct bt_mesh_model_op gen_property_cli_op[]; * * @return New generic location client model instance. */ -#define BT_MESH_MODEL_GEN_PROPERTY_CLI(cli_pub, cli_data) \ - BT_MESH_MODEL(BT_MESH_MODEL_ID_GEN_PROP_CLI, \ +#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) typedef bt_mesh_client_common_t bt_mesh_gen_property_cli_t; @@ -488,4 +488,4 @@ int bt_mesh_generic_client_get_state(struct bt_mesh_common_param *common, void * */ int bt_mesh_generic_client_set_state(struct bt_mesh_common_param *common, void *set, void *status); -#endif /* __BT_MESH_GENERIC_CLI_H */ +#endif /* _GENERIC_CLIENT_H_ */ diff --git a/components/bt/ble_mesh/mesh_models/include/light_client.h b/components/bt/ble_mesh/mesh_models/include/lighting_client.h similarity index 95% rename from components/bt/ble_mesh/mesh_models/include/light_client.h rename to components/bt/ble_mesh/mesh_models/include/lighting_client.h index 1accc1e84f..5b6b92a5ae 100644 --- a/components/bt/ble_mesh/mesh_models/include/light_client.h +++ b/components/bt/ble_mesh/mesh_models/include/lighting_client.h @@ -16,13 +16,13 @@ * @brief Bluetooth Mesh Lighting Client Model APIs. */ -#ifndef __BT_MESH_LIGHTING_CLI_H -#define __BT_MESH_LIGHTING_CLI_H +#ifndef _LIGHTING_CLIENT_H_ +#define _LIGHTING_CLIENT_H_ #include "mesh_access.h" #include "mesh_kernel.h" -#include "common.h" -#include "bt_mesh_client_common.h" + +#include "model_common.h" /* Light client model common structure */ typedef bt_mesh_client_common_t bt_mesh_light_client_t; @@ -31,7 +31,7 @@ typedef bt_mesh_internal_data_t light_internal_data_t; /* Light Lightness Client Model Context */ extern const struct bt_mesh_model_op light_lightness_cli_op[]; -/** @def BT_MESH_MODEL_LIGHT_LIGHTNESS_CLI +/** @def BLE_MESH_MODEL_LIGHT_LIGHTNESS_CLI * * Define a new light lightness client model. Note that this API * needs to be repeated for each element which the application @@ -41,8 +41,8 @@ extern const struct bt_mesh_model_op light_lightness_cli_op[]; * * @return New light lightness client model instance. */ -#define BT_MESH_MODEL_LIGHT_LIGHTNESS_CLI(cli_pub, cli_data) \ - BT_MESH_MODEL(BT_MESH_MODEL_ID_LIGHT_LIGHTNESS_CLI, \ +#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) typedef bt_mesh_client_common_t bt_mesh_light_lightness_cli_t; @@ -103,7 +103,7 @@ struct bt_mesh_light_lightness_range_set { /* Light CTL Client Model Context */ extern const struct bt_mesh_model_op light_ctl_cli_op[]; -/** @def BT_MESH_MODEL_LIGHT_CTL_CLI +/** @def BLE_MESH_MODEL_LIGHT_CTL_CLI * * Define a new light CTL client model. Note that this API needs * to be repeated for each element which the application wants to @@ -113,8 +113,8 @@ extern const struct bt_mesh_model_op light_ctl_cli_op[]; * * @return New light CTL client model instance. */ -#define BT_MESH_MODEL_LIGHT_CTL_CLI(cli_pub, cli_data) \ - BT_MESH_MODEL(BT_MESH_MODEL_ID_LIGHT_CTL_CLI, \ +#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) typedef bt_mesh_client_common_t bt_mesh_light_ctl_cli_t; @@ -182,7 +182,7 @@ struct bt_mesh_light_ctl_default_set { /* Light HSL Client Model Context */ extern const struct bt_mesh_model_op light_hsl_cli_op[]; -/** @def BT_MESH_MODEL_LIGHT_HSL_CLI +/** @def BLE_MESH_MODEL_LIGHT_HSL_CLI * * Define a new light HSL client model. Note that this API needs * to be repeated for each element which the application wants to @@ -192,8 +192,8 @@ extern const struct bt_mesh_model_op light_hsl_cli_op[]; * * @return New light HSL client model instance. */ -#define BT_MESH_MODEL_LIGHT_HSL_CLI(cli_pub, cli_data) \ - BT_MESH_MODEL(BT_MESH_MODEL_ID_LIGHT_HSL_CLI, \ +#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) typedef bt_mesh_client_common_t bt_mesh_light_hsl_cli_t; @@ -284,7 +284,7 @@ struct bt_mesh_light_hsl_range_set { /* Light xyL Client Model Context */ extern const struct bt_mesh_model_op light_xyl_cli_op[]; -/** @def BT_MESH_MODEL_LIGHT_XYL_CLI +/** @def BLE_MESH_MODEL_LIGHT_XYL_CLI * * Define a new light xyL client model. Note that this API needs * to be repeated for each element which the application wants @@ -294,8 +294,8 @@ extern const struct bt_mesh_model_op light_xyl_cli_op[]; * * @return New light xyL client model instance. */ -#define BT_MESH_MODEL_LIGHT_XYL_CLI(cli_pub, cli_data) \ - BT_MESH_MODEL(BT_MESH_MODEL_ID_LIGHT_XYL_CLI, \ +#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) typedef bt_mesh_client_common_t bt_mesh_light_xyl_cli_t; @@ -356,7 +356,7 @@ struct bt_mesh_light_xyl_range_set { /* Light LC Client Model Context */ extern const struct bt_mesh_model_op light_lc_cli_op[]; -/** @def BT_MESH_MODEL_LIGHT_LC_CLI +/** @def BLE_MESH_MODEL_LIGHT_LC_CLI * * Define a new light lc client model. Note that this API needs * to be repeated for each element which the application wants @@ -366,8 +366,8 @@ extern const struct bt_mesh_model_op light_lc_cli_op[]; * * @return New light lc client model instance. */ -#define BT_MESH_MODEL_LIGHT_LC_CLI(cli_pub, cli_data) \ - BT_MESH_MODEL(BT_MESH_MODEL_ID_LIGHT_LC_CLI, \ +#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) typedef bt_mesh_client_common_t bt_mesh_light_lc_cli_t; @@ -489,4 +489,4 @@ int bt_mesh_light_client_get_state(struct bt_mesh_common_param *common, void *ge */ int bt_mesh_light_client_set_state(struct bt_mesh_common_param *common, void *set, void *status); -#endif /* __BT_MESH_LIGHTING_CLI_H */ +#endif /* _LIGHTING_CLIENT_H_ */ diff --git a/components/bt/ble_mesh/mesh_models/include/mesh_common.h b/components/bt/ble_mesh/mesh_models/include/mesh_common.h new file mode 100644 index 0000000000..2a116be01e --- /dev/null +++ b/components/bt/ble_mesh/mesh_models/include/mesh_common.h @@ -0,0 +1,46 @@ +// Copyright 2017-2018 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +/** @file + * @brief Bluetooth Mesh Model Common APIs. + */ + +#ifndef _MESH_COMMON_H_ +#define _MESH_COMMON_H_ + +#include "osi/allocator.h" + +#include "mesh_types.h" +#include "mesh_buf.h" +#include "mesh_trace.h" + +/** + * @brief This function allocates memory to store outgoing message. + * + * @param[in] size: Length of memory allocated to store message value + * + * @return NULL-fail, pointer of a net_buf_simple structure-success + */ +struct net_buf_simple *bt_mesh_alloc_buf(u16_t size); + +/** + * @brief This function releases the memory allocated for the outgoing message. + * + * @param[in] buf: Pointer to the net_buf_simple structure to be freed + * + * @return none + */ +void bt_mesh_free_buf(struct net_buf_simple *buf); + +#endif /* _MESH_COMMON_H_ */ \ No newline at end of file diff --git a/components/bt/ble_mesh/mesh_models/include/bt_mesh_client_common.h b/components/bt/ble_mesh/mesh_models/include/model_common.h similarity index 71% rename from components/bt/ble_mesh/mesh_models/include/bt_mesh_client_common.h rename to components/bt/ble_mesh/mesh_models/include/model_common.h index cd68fa9892..fd9cc6dfda 100644 --- a/components/bt/ble_mesh/mesh_models/include/bt_mesh_client_common.h +++ b/components/bt/ble_mesh/mesh_models/include/model_common.h @@ -12,8 +12,8 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef _BT_MESH_CLIENT_COMMON_H_ -#define _BT_MESH_CLIENT_COMMON_H_ +#ifndef _MODEL_COMMON_H_ +#define _MODEL_COMMON_H_ #include "mesh_access.h" @@ -88,5 +88,46 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model, int bt_mesh_client_free_node(sys_slist_t *queue, bt_mesh_client_node_t *node); -#endif /* _BT_MESH_CLIENT_COMMON_H_ */ +enum { + NODE = 0, + PROVISIONER, + FAST_PROV, +}; + +#define ROLE_NVAL 0xFF + +struct bt_mesh_common_param { + u32_t opcode; /* Message opcode */ + struct bt_mesh_model *model; /* Pointer to cli structure */ + struct bt_mesh_msg_ctx ctx; /* Message context */ + s32_t msg_timeout; /* Time to get response messages */ + const struct bt_mesh_send_cb *cb; /* User defined callback function */ + void *cb_data; /* Data as parameter of the cb function */ +}; + +typedef struct bt_mesh_role_param { + 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. + * + * @param[in] common: Pointer to the struct bt_mesh_role_param structure + * + * @return Zero - success, otherwise - fail + */ +int bt_mesh_set_model_role(bt_mesh_role_param_t *common); + +/** + * @brief This function gets msg role for stack internal use. + * + * @param[in] model: Pointer to the model structure + * @param[in] srv_send: Indicate if the message is sent by a server model + * + * @return 0 - Node, 1 - Provisioner + */ +u8_t bt_mesh_get_model_role(struct bt_mesh_model *model, bool srv_send); + +#endif /* _MODEL_COMMON_H_ */ diff --git a/components/bt/ble_mesh/mesh_models/include/model_op.h b/components/bt/ble_mesh/mesh_models/include/model_op.h deleted file mode 100644 index 7eb9650b88..0000000000 --- a/components/bt/ble_mesh/mesh_models/include/model_op.h +++ /dev/null @@ -1,276 +0,0 @@ -// Copyright 2017-2018 Espressif Systems (Shanghai) PTE LTD -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at - -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef __BT_MESH_MODEL_OP_H_ -#define __BT_MESH_MODEL_OP_H_ - -#include "mesh_main.h" - -/* Generic OnOff Message Opcode */ -#define BT_MESH_MODEL_OP_GEN_ONOFF_GET BT_MESH_MODEL_OP_2(0x82, 0x01) -#define BT_MESH_MODEL_OP_GEN_ONOFF_SET BT_MESH_MODEL_OP_2(0x82, 0x02) -#define BT_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x03) -#define BT_MESH_MODEL_OP_GEN_ONOFF_STATUS BT_MESH_MODEL_OP_2(0x82, 0x04) - -/* Generic Level Message Opcode */ -#define BT_MESH_MODEL_OP_GEN_LEVEL_GET BT_MESH_MODEL_OP_2(0x82, 0x05) -#define BT_MESH_MODEL_OP_GEN_LEVEL_SET BT_MESH_MODEL_OP_2(0x82, 0x06) -#define BT_MESH_MODEL_OP_GEN_LEVEL_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x07) -#define BT_MESH_MODEL_OP_GEN_LEVEL_STATUS BT_MESH_MODEL_OP_2(0x82, 0x08) -#define BT_MESH_MODEL_OP_GEN_DELTA_SET BT_MESH_MODEL_OP_2(0x82, 0x09) -#define BT_MESH_MODEL_OP_GEN_DELTA_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x0A) -#define BT_MESH_MODEL_OP_GEN_MOVE_SET BT_MESH_MODEL_OP_2(0x82, 0x0B) -#define BT_MESH_MODEL_OP_GEN_MOVE_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x0C) - -/* Generic Default Transition Time Message Opcode*/ -#define BT_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_GET BT_MESH_MODEL_OP_2(0x82, 0x0D) -#define BT_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET BT_MESH_MODEL_OP_2(0x82, 0x0E) -#define BT_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x0F) -#define BT_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS BT_MESH_MODEL_OP_2(0x82, 0x10) - -/* Generic Power OnOff Message Opcode*/ -#define BT_MESH_MODEL_OP_GEN_ONPOWERUP_GET BT_MESH_MODEL_OP_2(0x82, 0x11) -#define BT_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS BT_MESH_MODEL_OP_2(0x82, 0x12) - -/* Generic Power OnOff Setup Message Opcode */ -#define BT_MESH_MODEL_OP_GEN_ONPOWERUP_SET BT_MESH_MODEL_OP_2(0x82, 0x13) -#define BT_MESH_MODEL_OP_GEN_ONPOWERUP_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x14) - -/* Generic Power Level Message Opcode */ -#define BT_MESH_MODEL_OP_GEN_POWER_LEVEL_GET BT_MESH_MODEL_OP_2(0x82, 0x15) -#define BT_MESH_MODEL_OP_GEN_POWER_LEVEL_SET BT_MESH_MODEL_OP_2(0x82, 0x16) -#define BT_MESH_MODEL_OP_GEN_POWER_LEVEL_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x17) -#define BT_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS BT_MESH_MODEL_OP_2(0x82, 0x18) -#define BT_MESH_MODEL_OP_GEN_POWER_LAST_GET BT_MESH_MODEL_OP_2(0x82, 0x19) -#define BT_MESH_MODEL_OP_GEN_POWER_LAST_STATUS BT_MESH_MODEL_OP_2(0x82, 0x1A) -#define BT_MESH_MODEL_OP_GEN_POWER_DEFAULT_GET BT_MESH_MODEL_OP_2(0x82, 0x1B) -#define BT_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS BT_MESH_MODEL_OP_2(0x82, 0x1C) -#define BT_MESH_MODEL_OP_GEN_POWER_RANGE_GET BT_MESH_MODEL_OP_2(0x82, 0x1D) -#define BT_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS BT_MESH_MODEL_OP_2(0x82, 0x1E) - -/* Generic Power Level Setup Message Opcode */ -#define BT_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET BT_MESH_MODEL_OP_2(0x82, 0x1F) -#define BT_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x20) -#define BT_MESH_MODEL_OP_GEN_POWER_RANGE_SET BT_MESH_MODEL_OP_2(0x82, 0x21) -#define BT_MESH_MODEL_OP_GEN_POWER_RANGE_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x22) - -/* Generic Battery Message Opcode */ -#define BT_MESH_MODEL_OP_GEN_BATTERY_GET BT_MESH_MODEL_OP_2(0x82, 0x23) -#define BT_MESH_MODEL_OP_GEN_BATTERY_STATUS BT_MESH_MODEL_OP_2(0x82, 0x24) - -/* Generic Location Message Opcode */ -#define BT_MESH_MODEL_OP_GEN_LOC_GLOBAL_GET BT_MESH_MODEL_OP_2(0x82, 0x25) -#define BT_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS BT_MESH_MODEL_OP_1(0x40) -#define BT_MESH_MODEL_OP_GEN_LOC_LOCAL_GET BT_MESH_MODEL_OP_2(0x82, 0x26) -#define BT_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS BT_MESH_MODEL_OP_2(0x82, 0x27) - -/* Generic Location Setup Message Opcode */ -#define BT_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET BT_MESH_MODEL_OP_1(0x41) -#define BT_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET_UNACK BT_MESH_MODEL_OP_1(0x42) -#define BT_MESH_MODEL_OP_GEN_LOC_LOCAL_SET BT_MESH_MODEL_OP_2(0x82, 0x28) -#define BT_MESH_MODEL_OP_GEN_LOC_LOCAL_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x29) - -/* Generic Manufacturer Property Message Opcode */ -#define BT_MESH_MODEL_OP_GEN_MANU_PROPERTIES_GET BT_MESH_MODEL_OP_2(0x82, 0x2A) -#define BT_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS BT_MESH_MODEL_OP_1(0x43) -#define BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET BT_MESH_MODEL_OP_2(0x82, 0x2B) -#define BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET BT_MESH_MODEL_OP_1(0x44) -#define BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET_UNACK BT_MESH_MODEL_OP_1(0x45) -#define BT_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS BT_MESH_MODEL_OP_1(0x46) - -/* Generic Admin Property Message Opcode */ -#define BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET BT_MESH_MODEL_OP_2(0x82, 0x2C) -#define BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS BT_MESH_MODEL_OP_1(0x47) -#define BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET BT_MESH_MODEL_OP_2(0x82, 0x2D) -#define BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET BT_MESH_MODEL_OP_1(0x48) -#define BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK BT_MESH_MODEL_OP_1(0x49) -#define BT_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS BT_MESH_MODEL_OP_1(0x4A) - -/* Generic User Property Message Opcode */ -#define BT_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET BT_MESH_MODEL_OP_2(0x82, 0x2E) -#define BT_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS BT_MESH_MODEL_OP_1(0x4B) -#define BT_MESH_MODEL_OP_GEN_USER_PROPERTY_GET BT_MESH_MODEL_OP_2(0x82, 0x2F) -#define BT_MESH_MODEL_OP_GEN_USER_PROPERTY_SET BT_MESH_MODEL_OP_1(0x4C) -#define BT_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK BT_MESH_MODEL_OP_1(0x4D) -#define BT_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS BT_MESH_MODEL_OP_1(0x4E) - -/* Generic Client Property Message Opcode */ -#define BT_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET BT_MESH_MODEL_OP_1(0x4F) -#define BT_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS BT_MESH_MODEL_OP_1(0x50) - -/* Sensor Message Opcode */ -#define BT_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET BT_MESH_MODEL_OP_2(0x82, 0x30) -#define BT_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS BT_MESH_MODEL_OP_1(0x51) -#define BT_MESH_MODEL_OP_SENSOR_GET BT_MESH_MODEL_OP_2(0x82, 0x31) -#define BT_MESH_MODEL_OP_SENSOR_STATUS BT_MESH_MODEL_OP_1(0x52) -#define BT_MESH_MODEL_OP_SENSOR_COLUMN_GET BT_MESH_MODEL_OP_2(0x82, 0x32) -#define BT_MESH_MODEL_OP_SENSOR_COLUMN_STATUS BT_MESH_MODEL_OP_1(0x53) -#define BT_MESH_MODEL_OP_SENSOR_SERIES_GET BT_MESH_MODEL_OP_2(0x82, 0x33) -#define BT_MESH_MODEL_OP_SENSOR_SERIES_STATUS BT_MESH_MODEL_OP_1(0x54) - -/* Sensor Setup Message Opcode */ -#define BT_MESH_MODEL_OP_SENSOR_CADENCE_GET BT_MESH_MODEL_OP_2(0x82, 0x34) -#define BT_MESH_MODEL_OP_SENSOR_CADENCE_SET BT_MESH_MODEL_OP_1(0x55) -#define BT_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK BT_MESH_MODEL_OP_1(0x56) -#define BT_MESH_MODEL_OP_SENSOR_CADENCE_STATUS BT_MESH_MODEL_OP_1(0x57) -#define BT_MESH_MODEL_OP_SENSOR_SETTINGS_GET BT_MESH_MODEL_OP_2(0x82, 0x35) -#define BT_MESH_MODEL_OP_SENSOR_SETTINGS_STATUS BT_MESH_MODEL_OP_1(0x58) -#define BT_MESH_MODEL_OP_SENSOR_SETTING_GET BT_MESH_MODEL_OP_2(0x82, 0x36) -#define BT_MESH_MODEL_OP_SENSOR_SETTING_SET BT_MESH_MODEL_OP_1(0x59) -#define BT_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK BT_MESH_MODEL_OP_1(0x5A) -#define BT_MESH_MODEL_OP_SENSOR_SETTING_STATUS BT_MESH_MODEL_OP_1(0x5B) - -/* Time Message Opcode */ -#define BT_MESH_MODEL_OP_TIME_GET BT_MESH_MODEL_OP_2(0x82, 0x37) -#define BT_MESH_MODEL_OP_TIME_SET BT_MESH_MODEL_OP_1(0x5C) -#define BT_MESH_MODEL_OP_TIME_STATUS BT_MESH_MODEL_OP_1(0x5D) -#define BT_MESH_MODEL_OP_TIME_ROLE_GET BT_MESH_MODEL_OP_2(0x82, 0x38) -#define BT_MESH_MODEL_OP_TIME_ROLE_SET BT_MESH_MODEL_OP_2(0x82, 0x39) -#define BT_MESH_MODEL_OP_TIME_ROLE_STATUS BT_MESH_MODEL_OP_2(0x82, 0x3A) -#define BT_MESH_MODEL_OP_TIME_ZONE_GET BT_MESH_MODEL_OP_2(0x82, 0x3B) -#define BT_MESH_MODEL_OP_TIME_ZONE_SET BT_MESH_MODEL_OP_2(0x82, 0x3C) -#define BT_MESH_MODEL_OP_TIME_ZONE_STATUS BT_MESH_MODEL_OP_2(0x82, 0x3D) -#define BT_MESH_MODEL_OP_TAI_UTC_DELTA_GET BT_MESH_MODEL_OP_2(0x82, 0x3E) -#define BT_MESH_MODEL_OP_TAI_UTC_DELTA_SET BT_MESH_MODEL_OP_2(0x82, 0x3F) -#define BT_MESH_MODEL_OP_TAI_UTC_DELTA_STATUS BT_MESH_MODEL_OP_2(0x82, 0x40) - -/* Scene Message Opcode */ -#define BT_MESH_MODEL_OP_SCENE_GET BT_MESH_MODEL_OP_2(0x82, 0x41) -#define BT_MESH_MODEL_OP_SCENE_RECALL BT_MESH_MODEL_OP_2(0x82, 0x42) -#define BT_MESH_MODEL_OP_SCENE_RECALL_UNACK BT_MESH_MODEL_OP_2(0x82, 0x43) -#define BT_MESH_MODEL_OP_SCENE_STATUS BT_MESH_MODEL_OP_1(0x5E) -#define BT_MESH_MODEL_OP_SCENE_REGISTER_GET BT_MESH_MODEL_OP_2(0x82, 0x44) -#define BT_MESH_MODEL_OP_SCENE_REGISTER_STATUS BT_MESH_MODEL_OP_2(0x82, 0x45) - -/* Scene Setup Message Opcode */ -#define BT_MESH_MODEL_OP_SCENE_STORE BT_MESH_MODEL_OP_2(0x82, 0x46) -#define BT_MESH_MODEL_OP_SCENE_STORE_UNACK BT_MESH_MODEL_OP_2(0x82, 0x47) -#define BT_MESH_MODEL_OP_SCENE_DELETE BT_MESH_MODEL_OP_2(0x82, 0x9E) -#define BT_MESH_MODEL_OP_SCENE_DELETE_UNACK BT_MESH_MODEL_OP_2(0x82, 0x9F) - -/* Scheduler Message Opcode */ -#define BT_MESH_MODEL_OP_SCHEDULER_ACT_GET BT_MESH_MODEL_OP_2(0x82, 0x48) -#define BT_MESH_MODEL_OP_SCHEDULER_ACT_STATUS BT_MESH_MODEL_OP_1(0x5F) -#define BT_MESH_MODEL_OP_SCHEDULER_GET BT_MESH_MODEL_OP_2(0x82, 0x49) -#define BT_MESH_MODEL_OP_SCHEDULER_STATUS BT_MESH_MODEL_OP_2(0x82, 0x4A) - -/* Scheduler Setup Message Opcode */ -#define BT_MESH_MODEL_OP_SCHEDULER_ACT_SET BT_MESH_MODEL_OP_1(0x60) -#define BT_MESH_MODEL_OP_SCHEDULER_ACT_SET_UNACK BT_MESH_MODEL_OP_1(0x61) - -/* Light Lightness Message Opcode */ -#define BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_GET BT_MESH_MODEL_OP_2(0x82, 0x4B) -#define BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET BT_MESH_MODEL_OP_2(0x82, 0x4C) -#define BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x4D) -#define BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS BT_MESH_MODEL_OP_2(0x82, 0x4E) -#define BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_GET BT_MESH_MODEL_OP_2(0x82, 0x4F) -#define BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET BT_MESH_MODEL_OP_2(0x82, 0x50) -#define BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x51) -#define BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS BT_MESH_MODEL_OP_2(0x82, 0x52) -#define BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_GET BT_MESH_MODEL_OP_2(0x82, 0x53) -#define BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_STATUS BT_MESH_MODEL_OP_2(0x82, 0x54) -#define BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_GET BT_MESH_MODEL_OP_2(0x82, 0x55) -#define BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_STATUS BT_MESH_MODEL_OP_2(0x82, 0x56) -#define BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_GET BT_MESH_MODEL_OP_2(0x82, 0x57) -#define BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS BT_MESH_MODEL_OP_2(0x82, 0x58) - -/* Light Lightness Setup Message Opcode */ -#define BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET BT_MESH_MODEL_OP_2(0x82, 0x59) -#define BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x5A) -#define BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET BT_MESH_MODEL_OP_2(0x82, 0x5B) -#define BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x5C) - -/* Light CTL Message Opcode */ -#define BT_MESH_MODEL_OP_LIGHT_CTL_GET BT_MESH_MODEL_OP_2(0x82, 0x5D) -#define BT_MESH_MODEL_OP_LIGHT_CTL_SET BT_MESH_MODEL_OP_2(0x82, 0x5E) -#define BT_MESH_MODEL_OP_LIGHT_CTL_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x5F) -#define BT_MESH_MODEL_OP_LIGHT_CTL_STATUS BT_MESH_MODEL_OP_2(0x82, 0x60) -#define BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_GET BT_MESH_MODEL_OP_2(0x82, 0x61) -#define BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_GET BT_MESH_MODEL_OP_2(0x82, 0x62) -#define BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS BT_MESH_MODEL_OP_2(0x82, 0x63) -#define BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET BT_MESH_MODEL_OP_2(0x82, 0x64) -#define BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x65) -#define BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS BT_MESH_MODEL_OP_2(0x82, 0x66) -#define BT_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_GET BT_MESH_MODEL_OP_2(0x82, 0x67) -#define BT_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS BT_MESH_MODEL_OP_2(0x82, 0x68) - -/* Light CTL Setup Message Opcode */ -#define BT_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET BT_MESH_MODEL_OP_2(0x82, 0x69) -#define BT_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x6A) -#define BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET BT_MESH_MODEL_OP_2(0x82, 0x6B) -#define BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x6C) - -/* Light HSL Message Opcode */ -#define BT_MESH_MODEL_OP_LIGHT_HSL_GET BT_MESH_MODEL_OP_2(0x82, 0x6D) -#define BT_MESH_MODEL_OP_LIGHT_HSL_HUE_GET BT_MESH_MODEL_OP_2(0x82, 0x6E) -#define BT_MESH_MODEL_OP_LIGHT_HSL_HUE_SET BT_MESH_MODEL_OP_2(0x82, 0x6F) -#define BT_MESH_MODEL_OP_LIGHT_HSL_HUE_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x70) -#define BT_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS BT_MESH_MODEL_OP_2(0x82, 0x71) -#define BT_MESH_MODEL_OP_LIGHT_HSL_SATURATION_GET BT_MESH_MODEL_OP_2(0x82, 0x72) -#define BT_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET BT_MESH_MODEL_OP_2(0x82, 0x73) -#define BT_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x74) -#define BT_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS BT_MESH_MODEL_OP_2(0x82, 0x75) -#define BT_MESH_MODEL_OP_LIGHT_HSL_SET BT_MESH_MODEL_OP_2(0x82, 0x76) -#define BT_MESH_MODEL_OP_LIGHT_HSL_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x77) -#define BT_MESH_MODEL_OP_LIGHT_HSL_STATUS BT_MESH_MODEL_OP_2(0x82, 0x78) -#define BT_MESH_MODEL_OP_LIGHT_HSL_TARGET_GET BT_MESH_MODEL_OP_2(0x82, 0x79) -#define BT_MESH_MODEL_OP_LIGHT_HSL_TARGET_STATUS BT_MESH_MODEL_OP_2(0x82, 0x7A) -#define BT_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_GET BT_MESH_MODEL_OP_2(0x82, 0x7B) -#define BT_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_STATUS BT_MESH_MODEL_OP_2(0x82, 0x7C) -#define BT_MESH_MODEL_OP_LIGHT_HSL_RANGE_GET BT_MESH_MODEL_OP_2(0x82, 0x7D) -#define BT_MESH_MODEL_OP_LIGHT_HSL_RANGE_STATUS BT_MESH_MODEL_OP_2(0x82, 0x7E) - -/* Light HSL Setup Message Opcode */ -#define BT_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET BT_MESH_MODEL_OP_2(0x82, 0x7F) -#define BT_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x80) -#define BT_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET BT_MESH_MODEL_OP_2(0x82, 0x81) -#define BT_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x82) /* Model spec is wrong */ - -/* Light xyL Message Opcode */ -#define BT_MESH_MODEL_OP_LIGHT_XYL_GET BT_MESH_MODEL_OP_2(0x82, 0x83) -#define BT_MESH_MODEL_OP_LIGHT_XYL_SET BT_MESH_MODEL_OP_2(0x82, 0x84) -#define BT_MESH_MODEL_OP_LIGHT_XYL_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x85) -#define BT_MESH_MODEL_OP_LIGHT_XYL_STATUS BT_MESH_MODEL_OP_2(0x82, 0x86) -#define BT_MESH_MODEL_OP_LIGHT_XYL_TARGET_GET BT_MESH_MODEL_OP_2(0x82, 0x87) -#define BT_MESH_MODEL_OP_LIGHT_XYL_TARGET_STATUS BT_MESH_MODEL_OP_2(0x82, 0x88) -#define BT_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_GET BT_MESH_MODEL_OP_2(0x82, 0x89) -#define BT_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_STATUS BT_MESH_MODEL_OP_2(0x82, 0x8A) -#define BT_MESH_MODEL_OP_LIGHT_XYL_RANGE_GET BT_MESH_MODEL_OP_2(0x82, 0x8B) -#define BT_MESH_MODEL_OP_LIGHT_XYL_RANGE_STATUS BT_MESH_MODEL_OP_2(0x82, 0x8C) - -/* Light xyL Setup Message Opcode */ -#define BT_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET BT_MESH_MODEL_OP_2(0x82, 0x8D) -#define BT_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x8E) -#define BT_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET BT_MESH_MODEL_OP_2(0x82, 0x8F) -#define BT_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x90) - -/* Light Control Message Opcode */ -#define BT_MESH_MODEL_OP_LIGHT_LC_MODE_GET BT_MESH_MODEL_OP_2(0x82, 0x91) -#define BT_MESH_MODEL_OP_LIGHT_LC_MODE_SET BT_MESH_MODEL_OP_2(0x82, 0x92) -#define BT_MESH_MODEL_OP_LIGHT_LC_MODE_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x93) -#define BT_MESH_MODEL_OP_LIGHT_LC_MODE_STATUS BT_MESH_MODEL_OP_2(0x82, 0x94) -#define BT_MESH_MODEL_OP_LIGHT_LC_OM_GET BT_MESH_MODEL_OP_2(0x82, 0x95) -#define BT_MESH_MODEL_OP_LIGHT_LC_OM_SET BT_MESH_MODEL_OP_2(0x82, 0x96) -#define BT_MESH_MODEL_OP_LIGHT_LC_OM_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x97) -#define BT_MESH_MODEL_OP_LIGHT_LC_OM_STATUS BT_MESH_MODEL_OP_2(0x82, 0x98) -#define BT_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_GET BT_MESH_MODEL_OP_2(0x82, 0x99) -#define BT_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET BT_MESH_MODEL_OP_2(0x82, 0x9A) -#define BT_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET_UNACK BT_MESH_MODEL_OP_2(0x82, 0x9B) -#define BT_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS BT_MESH_MODEL_OP_2(0x82, 0x9C) -#define BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET BT_MESH_MODEL_OP_2(0x82, 0x9D) -#define BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET BT_MESH_MODEL_OP_1(0x62) -#define BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK BT_MESH_MODEL_OP_1(0x63) -#define BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS BT_MESH_MODEL_OP_1(0x64) - -#endif /* __BT_MESH_MODEL_OP_H_ */ diff --git a/components/bt/ble_mesh/mesh_models/include/model_opcode.h b/components/bt/ble_mesh/mesh_models/include/model_opcode.h new file mode 100644 index 0000000000..01929d5cfe --- /dev/null +++ b/components/bt/ble_mesh/mesh_models/include/model_opcode.h @@ -0,0 +1,276 @@ +// Copyright 2017-2018 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef _MODEL_OPCODE_H_ +#define _MODEL_OPCODE_H_ + +#include "mesh_main.h" + +/* Generic OnOff Message Opcode */ +#define BLE_MESH_MODEL_OP_GEN_ONOFF_GET BLE_MESH_MODEL_OP_2(0x82, 0x01) +#define BLE_MESH_MODEL_OP_GEN_ONOFF_SET BLE_MESH_MODEL_OP_2(0x82, 0x02) +#define BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x03) +#define BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x04) + +/* Generic Level Message Opcode */ +#define BLE_MESH_MODEL_OP_GEN_LEVEL_GET BLE_MESH_MODEL_OP_2(0x82, 0x05) +#define BLE_MESH_MODEL_OP_GEN_LEVEL_SET BLE_MESH_MODEL_OP_2(0x82, 0x06) +#define BLE_MESH_MODEL_OP_GEN_LEVEL_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x07) +#define BLE_MESH_MODEL_OP_GEN_LEVEL_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x08) +#define BLE_MESH_MODEL_OP_GEN_DELTA_SET BLE_MESH_MODEL_OP_2(0x82, 0x09) +#define BLE_MESH_MODEL_OP_GEN_DELTA_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x0A) +#define BLE_MESH_MODEL_OP_GEN_MOVE_SET BLE_MESH_MODEL_OP_2(0x82, 0x0B) +#define BLE_MESH_MODEL_OP_GEN_MOVE_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x0C) + +/* Generic Default Transition Time Message Opcode*/ +#define BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_GET BLE_MESH_MODEL_OP_2(0x82, 0x0D) +#define BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET BLE_MESH_MODEL_OP_2(0x82, 0x0E) +#define BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x0F) +#define BLE_MESH_MODEL_OP_GEN_DEF_TRANS_TIME_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x10) + +/* Generic Power OnOff Message Opcode*/ +#define BLE_MESH_MODEL_OP_GEN_ONPOWERUP_GET BLE_MESH_MODEL_OP_2(0x82, 0x11) +#define BLE_MESH_MODEL_OP_GEN_ONPOWERUP_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x12) + +/* Generic Power OnOff Setup Message Opcode */ +#define BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET BLE_MESH_MODEL_OP_2(0x82, 0x13) +#define BLE_MESH_MODEL_OP_GEN_ONPOWERUP_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x14) + +/* Generic Power Level Message Opcode */ +#define BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_GET BLE_MESH_MODEL_OP_2(0x82, 0x15) +#define BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET BLE_MESH_MODEL_OP_2(0x82, 0x16) +#define BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x17) +#define BLE_MESH_MODEL_OP_GEN_POWER_LEVEL_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x18) +#define BLE_MESH_MODEL_OP_GEN_POWER_LAST_GET BLE_MESH_MODEL_OP_2(0x82, 0x19) +#define BLE_MESH_MODEL_OP_GEN_POWER_LAST_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x1A) +#define BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_GET BLE_MESH_MODEL_OP_2(0x82, 0x1B) +#define BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x1C) +#define BLE_MESH_MODEL_OP_GEN_POWER_RANGE_GET BLE_MESH_MODEL_OP_2(0x82, 0x1D) +#define BLE_MESH_MODEL_OP_GEN_POWER_RANGE_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x1E) + +/* Generic Power Level Setup Message Opcode */ +#define BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET BLE_MESH_MODEL_OP_2(0x82, 0x1F) +#define BLE_MESH_MODEL_OP_GEN_POWER_DEFAULT_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x20) +#define BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET BLE_MESH_MODEL_OP_2(0x82, 0x21) +#define BLE_MESH_MODEL_OP_GEN_POWER_RANGE_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x22) + +/* Generic Battery Message Opcode */ +#define BLE_MESH_MODEL_OP_GEN_BATTERY_GET BLE_MESH_MODEL_OP_2(0x82, 0x23) +#define BLE_MESH_MODEL_OP_GEN_BATTERY_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x24) + +/* Generic Location Message Opcode */ +#define BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_GET BLE_MESH_MODEL_OP_2(0x82, 0x25) +#define BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_STATUS BLE_MESH_MODEL_OP_1(0x40) +#define BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_GET BLE_MESH_MODEL_OP_2(0x82, 0x26) +#define BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x27) + +/* Generic Location Setup Message Opcode */ +#define BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET BLE_MESH_MODEL_OP_1(0x41) +#define BLE_MESH_MODEL_OP_GEN_LOC_GLOBAL_SET_UNACK BLE_MESH_MODEL_OP_1(0x42) +#define BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET BLE_MESH_MODEL_OP_2(0x82, 0x28) +#define BLE_MESH_MODEL_OP_GEN_LOC_LOCAL_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x29) + +/* Generic Manufacturer Property Message Opcode */ +#define BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_GET BLE_MESH_MODEL_OP_2(0x82, 0x2A) +#define BLE_MESH_MODEL_OP_GEN_MANU_PROPERTIES_STATUS BLE_MESH_MODEL_OP_1(0x43) +#define BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_GET BLE_MESH_MODEL_OP_2(0x82, 0x2B) +#define BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET BLE_MESH_MODEL_OP_1(0x44) +#define BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_SET_UNACK BLE_MESH_MODEL_OP_1(0x45) +#define BLE_MESH_MODEL_OP_GEN_MANU_PROPERTY_STATUS BLE_MESH_MODEL_OP_1(0x46) + +/* Generic Admin Property Message Opcode */ +#define BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_GET BLE_MESH_MODEL_OP_2(0x82, 0x2C) +#define BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTIES_STATUS BLE_MESH_MODEL_OP_1(0x47) +#define BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_GET BLE_MESH_MODEL_OP_2(0x82, 0x2D) +#define BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET BLE_MESH_MODEL_OP_1(0x48) +#define BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_SET_UNACK BLE_MESH_MODEL_OP_1(0x49) +#define BLE_MESH_MODEL_OP_GEN_ADMIN_PROPERTY_STATUS BLE_MESH_MODEL_OP_1(0x4A) + +/* Generic User Property Message Opcode */ +#define BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_GET BLE_MESH_MODEL_OP_2(0x82, 0x2E) +#define BLE_MESH_MODEL_OP_GEN_USER_PROPERTIES_STATUS BLE_MESH_MODEL_OP_1(0x4B) +#define BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_GET BLE_MESH_MODEL_OP_2(0x82, 0x2F) +#define BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET BLE_MESH_MODEL_OP_1(0x4C) +#define BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_SET_UNACK BLE_MESH_MODEL_OP_1(0x4D) +#define BLE_MESH_MODEL_OP_GEN_USER_PROPERTY_STATUS BLE_MESH_MODEL_OP_1(0x4E) + +/* Generic Client Property Message Opcode */ +#define BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_GET BLE_MESH_MODEL_OP_1(0x4F) +#define BLE_MESH_MODEL_OP_GEN_CLIENT_PROPERTIES_STATUS BLE_MESH_MODEL_OP_1(0x50) + +/* Sensor Message Opcode */ +#define BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET BLE_MESH_MODEL_OP_2(0x82, 0x30) +#define BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS BLE_MESH_MODEL_OP_1(0x51) +#define BLE_MESH_MODEL_OP_SENSOR_GET BLE_MESH_MODEL_OP_2(0x82, 0x31) +#define BLE_MESH_MODEL_OP_SENSOR_STATUS BLE_MESH_MODEL_OP_1(0x52) +#define BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET BLE_MESH_MODEL_OP_2(0x82, 0x32) +#define BLE_MESH_MODEL_OP_SENSOR_COLUMN_STATUS BLE_MESH_MODEL_OP_1(0x53) +#define BLE_MESH_MODEL_OP_SENSOR_SERIES_GET BLE_MESH_MODEL_OP_2(0x82, 0x33) +#define BLE_MESH_MODEL_OP_SENSOR_SERIES_STATUS BLE_MESH_MODEL_OP_1(0x54) + +/* Sensor Setup Message Opcode */ +#define BLE_MESH_MODEL_OP_SENSOR_CADENCE_GET BLE_MESH_MODEL_OP_2(0x82, 0x34) +#define BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET BLE_MESH_MODEL_OP_1(0x55) +#define BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK BLE_MESH_MODEL_OP_1(0x56) +#define BLE_MESH_MODEL_OP_SENSOR_CADENCE_STATUS BLE_MESH_MODEL_OP_1(0x57) +#define BLE_MESH_MODEL_OP_SENSOR_SETTINGS_GET BLE_MESH_MODEL_OP_2(0x82, 0x35) +#define BLE_MESH_MODEL_OP_SENSOR_SETTINGS_STATUS BLE_MESH_MODEL_OP_1(0x58) +#define BLE_MESH_MODEL_OP_SENSOR_SETTING_GET BLE_MESH_MODEL_OP_2(0x82, 0x36) +#define BLE_MESH_MODEL_OP_SENSOR_SETTING_SET BLE_MESH_MODEL_OP_1(0x59) +#define BLE_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK BLE_MESH_MODEL_OP_1(0x5A) +#define BLE_MESH_MODEL_OP_SENSOR_SETTING_STATUS BLE_MESH_MODEL_OP_1(0x5B) + +/* Time Message Opcode */ +#define BLE_MESH_MODEL_OP_TIME_GET BLE_MESH_MODEL_OP_2(0x82, 0x37) +#define BLE_MESH_MODEL_OP_TIME_SET BLE_MESH_MODEL_OP_1(0x5C) +#define BLE_MESH_MODEL_OP_TIME_STATUS BLE_MESH_MODEL_OP_1(0x5D) +#define BLE_MESH_MODEL_OP_TIME_ROLE_GET BLE_MESH_MODEL_OP_2(0x82, 0x38) +#define BLE_MESH_MODEL_OP_TIME_ROLE_SET BLE_MESH_MODEL_OP_2(0x82, 0x39) +#define BLE_MESH_MODEL_OP_TIME_ROLE_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x3A) +#define BLE_MESH_MODEL_OP_TIME_ZONE_GET BLE_MESH_MODEL_OP_2(0x82, 0x3B) +#define BLE_MESH_MODEL_OP_TIME_ZONE_SET BLE_MESH_MODEL_OP_2(0x82, 0x3C) +#define BLE_MESH_MODEL_OP_TIME_ZONE_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x3D) +#define BLE_MESH_MODEL_OP_TAI_UTC_DELTA_GET BLE_MESH_MODEL_OP_2(0x82, 0x3E) +#define BLE_MESH_MODEL_OP_TAI_UTC_DELTA_SET BLE_MESH_MODEL_OP_2(0x82, 0x3F) +#define BLE_MESH_MODEL_OP_TAI_UTC_DELTA_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x40) + +/* Scene Message Opcode */ +#define BLE_MESH_MODEL_OP_SCENE_GET BLE_MESH_MODEL_OP_2(0x82, 0x41) +#define BLE_MESH_MODEL_OP_SCENE_RECALL BLE_MESH_MODEL_OP_2(0x82, 0x42) +#define BLE_MESH_MODEL_OP_SCENE_RECALL_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x43) +#define BLE_MESH_MODEL_OP_SCENE_STATUS BLE_MESH_MODEL_OP_1(0x5E) +#define BLE_MESH_MODEL_OP_SCENE_REGISTER_GET BLE_MESH_MODEL_OP_2(0x82, 0x44) +#define BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x45) + +/* Scene Setup Message Opcode */ +#define BLE_MESH_MODEL_OP_SCENE_STORE BLE_MESH_MODEL_OP_2(0x82, 0x46) +#define BLE_MESH_MODEL_OP_SCENE_STORE_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x47) +#define BLE_MESH_MODEL_OP_SCENE_DELETE BLE_MESH_MODEL_OP_2(0x82, 0x9E) +#define BLE_MESH_MODEL_OP_SCENE_DELETE_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x9F) + +/* Scheduler Message Opcode */ +#define BLE_MESH_MODEL_OP_SCHEDULER_ACT_GET BLE_MESH_MODEL_OP_2(0x82, 0x48) +#define BLE_MESH_MODEL_OP_SCHEDULER_ACT_STATUS BLE_MESH_MODEL_OP_1(0x5F) +#define BLE_MESH_MODEL_OP_SCHEDULER_GET BLE_MESH_MODEL_OP_2(0x82, 0x49) +#define BLE_MESH_MODEL_OP_SCHEDULER_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x4A) + +/* Scheduler Setup Message Opcode */ +#define BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET BLE_MESH_MODEL_OP_1(0x60) +#define BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET_UNACK BLE_MESH_MODEL_OP_1(0x61) + +/* Light Lightness Message Opcode */ +#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_GET BLE_MESH_MODEL_OP_2(0x82, 0x4B) +#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET BLE_MESH_MODEL_OP_2(0x82, 0x4C) +#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x4D) +#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x4E) +#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_GET BLE_MESH_MODEL_OP_2(0x82, 0x4F) +#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET BLE_MESH_MODEL_OP_2(0x82, 0x50) +#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x51) +#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x52) +#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_GET BLE_MESH_MODEL_OP_2(0x82, 0x53) +#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x54) +#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_GET BLE_MESH_MODEL_OP_2(0x82, 0x55) +#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x56) +#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_GET BLE_MESH_MODEL_OP_2(0x82, 0x57) +#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x58) + +/* Light Lightness Setup Message Opcode */ +#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET BLE_MESH_MODEL_OP_2(0x82, 0x59) +#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x5A) +#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET BLE_MESH_MODEL_OP_2(0x82, 0x5B) +#define BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x5C) + +/* Light CTL Message Opcode */ +#define BLE_MESH_MODEL_OP_LIGHT_CTL_GET BLE_MESH_MODEL_OP_2(0x82, 0x5D) +#define BLE_MESH_MODEL_OP_LIGHT_CTL_SET BLE_MESH_MODEL_OP_2(0x82, 0x5E) +#define BLE_MESH_MODEL_OP_LIGHT_CTL_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x5F) +#define BLE_MESH_MODEL_OP_LIGHT_CTL_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x60) +#define BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_GET BLE_MESH_MODEL_OP_2(0x82, 0x61) +#define BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_GET BLE_MESH_MODEL_OP_2(0x82, 0x62) +#define BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x63) +#define BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET BLE_MESH_MODEL_OP_2(0x82, 0x64) +#define BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x65) +#define BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x66) +#define BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_GET BLE_MESH_MODEL_OP_2(0x82, 0x67) +#define BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x68) + +/* Light CTL Setup Message Opcode */ +#define BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET BLE_MESH_MODEL_OP_2(0x82, 0x69) +#define BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x6A) +#define BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET BLE_MESH_MODEL_OP_2(0x82, 0x6B) +#define BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x6C) + +/* Light HSL Message Opcode */ +#define BLE_MESH_MODEL_OP_LIGHT_HSL_GET BLE_MESH_MODEL_OP_2(0x82, 0x6D) +#define BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_GET BLE_MESH_MODEL_OP_2(0x82, 0x6E) +#define BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET BLE_MESH_MODEL_OP_2(0x82, 0x6F) +#define BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x70) +#define BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x71) +#define BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_GET BLE_MESH_MODEL_OP_2(0x82, 0x72) +#define BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET BLE_MESH_MODEL_OP_2(0x82, 0x73) +#define BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x74) +#define BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x75) +#define BLE_MESH_MODEL_OP_LIGHT_HSL_SET BLE_MESH_MODEL_OP_2(0x82, 0x76) +#define BLE_MESH_MODEL_OP_LIGHT_HSL_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x77) +#define BLE_MESH_MODEL_OP_LIGHT_HSL_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x78) +#define BLE_MESH_MODEL_OP_LIGHT_HSL_TARGET_GET BLE_MESH_MODEL_OP_2(0x82, 0x79) +#define BLE_MESH_MODEL_OP_LIGHT_HSL_TARGET_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x7A) +#define BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_GET BLE_MESH_MODEL_OP_2(0x82, 0x7B) +#define BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x7C) +#define BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_GET BLE_MESH_MODEL_OP_2(0x82, 0x7D) +#define BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x7E) + +/* Light HSL Setup Message Opcode */ +#define BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET BLE_MESH_MODEL_OP_2(0x82, 0x7F) +#define BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x80) +#define BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET BLE_MESH_MODEL_OP_2(0x82, 0x81) +#define BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x82) /* Model spec is wrong */ + +/* Light xyL Message Opcode */ +#define BLE_MESH_MODEL_OP_LIGHT_XYL_GET BLE_MESH_MODEL_OP_2(0x82, 0x83) +#define BLE_MESH_MODEL_OP_LIGHT_XYL_SET BLE_MESH_MODEL_OP_2(0x82, 0x84) +#define BLE_MESH_MODEL_OP_LIGHT_XYL_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x85) +#define BLE_MESH_MODEL_OP_LIGHT_XYL_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x86) +#define BLE_MESH_MODEL_OP_LIGHT_XYL_TARGET_GET BLE_MESH_MODEL_OP_2(0x82, 0x87) +#define BLE_MESH_MODEL_OP_LIGHT_XYL_TARGET_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x88) +#define BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_GET BLE_MESH_MODEL_OP_2(0x82, 0x89) +#define BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x8A) +#define BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_GET BLE_MESH_MODEL_OP_2(0x82, 0x8B) +#define BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x8C) + +/* Light xyL Setup Message Opcode */ +#define BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET BLE_MESH_MODEL_OP_2(0x82, 0x8D) +#define BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x8E) +#define BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET BLE_MESH_MODEL_OP_2(0x82, 0x8F) +#define BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x90) + +/* Light Control Message Opcode */ +#define BLE_MESH_MODEL_OP_LIGHT_LC_MODE_GET BLE_MESH_MODEL_OP_2(0x82, 0x91) +#define BLE_MESH_MODEL_OP_LIGHT_LC_MODE_SET BLE_MESH_MODEL_OP_2(0x82, 0x92) +#define BLE_MESH_MODEL_OP_LIGHT_LC_MODE_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x93) +#define BLE_MESH_MODEL_OP_LIGHT_LC_MODE_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x94) +#define BLE_MESH_MODEL_OP_LIGHT_LC_OM_GET BLE_MESH_MODEL_OP_2(0x82, 0x95) +#define BLE_MESH_MODEL_OP_LIGHT_LC_OM_SET BLE_MESH_MODEL_OP_2(0x82, 0x96) +#define BLE_MESH_MODEL_OP_LIGHT_LC_OM_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x97) +#define BLE_MESH_MODEL_OP_LIGHT_LC_OM_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x98) +#define BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_GET BLE_MESH_MODEL_OP_2(0x82, 0x99) +#define BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET BLE_MESH_MODEL_OP_2(0x82, 0x9A) +#define BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET_UNACK BLE_MESH_MODEL_OP_2(0x82, 0x9B) +#define BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS BLE_MESH_MODEL_OP_2(0x82, 0x9C) +#define BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET BLE_MESH_MODEL_OP_2(0x82, 0x9D) +#define BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET BLE_MESH_MODEL_OP_1(0x62) +#define BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK BLE_MESH_MODEL_OP_1(0x63) +#define BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS BLE_MESH_MODEL_OP_1(0x64) + +#endif /* _MODEL_OPCODE_H_ */ diff --git a/components/bt/ble_mesh/mesh_models/include/sensor_client.h b/components/bt/ble_mesh/mesh_models/include/sensor_client.h index ebfd015c3a..2b259a8953 100644 --- a/components/bt/ble_mesh/mesh_models/include/sensor_client.h +++ b/components/bt/ble_mesh/mesh_models/include/sensor_client.h @@ -16,18 +16,18 @@ * @brief Bluetooth Mesh Sensor Client Model APIs. */ -#ifndef __BT_MESH_SENSOR_CLI_H -#define __BT_MESH_SENSOR_CLI_H +#ifndef _SENSOR_CLIENT_H_ +#define _SENSOR_CLIENT_H_ #include "mesh_access.h" #include "mesh_kernel.h" -#include "common.h" -#include "bt_mesh_client_common.h" + +#include "model_common.h" /* Sensor Client Model Context */ extern const struct bt_mesh_model_op sensor_cli_op[]; -/** @def BT_MESH_MODEL_SENSOR_CLI +/** @def BLE_MESH_MODEL_SENSOR_CLI * * Define a new sensor client model. Note that this API needs to * be repeated for each element which the application wants to @@ -37,8 +37,8 @@ extern const struct bt_mesh_model_op sensor_cli_op[]; * * @return New sensor client model instance. */ -#define BT_MESH_MODEL_SENSOR_CLI(cli_pub, cli_data) \ - BT_MESH_MODEL(BT_MESH_MODEL_ID_SENSOR_CLI, \ +#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) typedef bt_mesh_client_common_t bt_mesh_sensor_client_t; @@ -164,4 +164,4 @@ int bt_mesh_sensor_client_get_state(struct bt_mesh_common_param *common, void *g */ int bt_mesh_sensor_client_set_state(struct bt_mesh_common_param *common, void *set, void *status); -#endif /* __BT_MESH_SENSOR_CLI_H */ +#endif /* _SENSOR_CLIENT_H_ */ diff --git a/components/bt/ble_mesh/mesh_models/include/time_scene_client.h b/components/bt/ble_mesh/mesh_models/include/time_scene_client.h index 99ac6fa969..baa0d4abc0 100644 --- a/components/bt/ble_mesh/mesh_models/include/time_scene_client.h +++ b/components/bt/ble_mesh/mesh_models/include/time_scene_client.h @@ -16,13 +16,13 @@ * @brief Bluetooth Mesh Time and Scene Client Model APIs. */ -#ifndef __BT_MESH_TIME_SCENE_CLI_H -#define __BT_MESH_TIME_SCENE_CLI_H +#ifndef _TIME_SCENE_CLIENT_H_ +#define _TIME_SCENE_CLIENT_H_ #include "mesh_access.h" #include "mesh_kernel.h" -#include "common.h" -#include "bt_mesh_client_common.h" + +#include "model_common.h" /* Time scene client model common structure */ typedef bt_mesh_client_common_t bt_mesh_time_scene_client_t; @@ -31,7 +31,7 @@ typedef bt_mesh_internal_data_t time_scene_internal_data_t; /* Time Client Model Context */ extern const struct bt_mesh_model_op time_cli_op[]; -/** @def BT_MESH_MODEL_TIME_CLI +/** @def BLE_MESH_MODEL_TIME_CLI * * Define a new time client model. Note that this API needs to * be repeated for each element which the application wants to @@ -41,8 +41,8 @@ extern const struct bt_mesh_model_op time_cli_op[]; * * @return New time client model instance. */ -#define BT_MESH_MODEL_TIME_CLI(cli_pub, cli_data) \ - BT_MESH_MODEL(BT_MESH_MODEL_ID_TIME_CLI, \ +#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) typedef bt_mesh_client_common_t bt_mesh_time_cli_t; @@ -101,7 +101,7 @@ struct bt_mesh_time_role_set { /* Scene Client Model Context */ extern const struct bt_mesh_model_op scene_cli_op[]; -/** @def BT_MESH_MODEL_SCENE_CLI +/** @def BLE_MESH_MODEL_SCENE_CLI * * Define a new scene client model. Note that this API needs to * be repeated for each element which the application wants to @@ -111,8 +111,8 @@ extern const struct bt_mesh_model_op scene_cli_op[]; * * @return New scene client model instance. */ -#define BT_MESH_MODEL_SCENE_CLI(cli_pub, cli_data) \ - BT_MESH_MODEL(BT_MESH_MODEL_ID_SCENE_CLI, \ +#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) typedef bt_mesh_client_common_t bt_mesh_scene_cli_t; @@ -150,7 +150,7 @@ struct bt_mesh_scene_delete { /* Scheduler Client Model Context */ extern const struct bt_mesh_model_op scheduler_cli_op[]; -/** @def BT_MESH_MODEL_SCHEDULER_CLI +/** @def BLE_MESH_MODEL_SCHEDULER_CLI * * Define a new scheduler client model. Note that this API needs to * be repeated for each element which the application wants to @@ -160,8 +160,8 @@ extern const struct bt_mesh_model_op scheduler_cli_op[]; * * @return New scheduler client model instance. */ -#define BT_MESH_MODEL_SCHEDULER_CLI(cli_pub, cli_data) \ - BT_MESH_MODEL(BT_MESH_MODEL_ID_SCHEDULER_CLI, \ +#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) typedef bt_mesh_client_common_t bt_mesh_scheduler_cli_t; @@ -254,4 +254,4 @@ int bt_mesh_time_scene_client_get_state(struct bt_mesh_common_param *common, voi */ int bt_mesh_time_scene_client_set_state(struct bt_mesh_common_param *common, void *set, void *status); -#endif /* __BT_MESH_TIME_SCENE_CLI_H */ +#endif /* _TIME_SCENE_CLIENT_H_ */ diff --git a/components/bt/ble_mesh/mesh_models/light_client.c b/components/bt/ble_mesh/mesh_models/lighting_client.c similarity index 52% rename from components/bt/ble_mesh/mesh_models/light_client.c rename to components/bt/ble_mesh/mesh_models/lighting_client.c index 48fe51a682..87374e1e1e 100644 --- a/components/bt/ble_mesh/mesh_models/light_client.c +++ b/components/bt/ble_mesh/mesh_models/lighting_client.c @@ -17,141 +17,140 @@ #include #include "osi/allocator.h" +#include "sdkconfig.h" #include "mesh_types.h" #include "mesh_kernel.h" #include "mesh_trace.h" + #include "mesh.h" +#include "model_opcode.h" +#include "mesh_common.h" +#include "lighting_client.h" -#include "model_op.h" -#include "common.h" -#include "light_client.h" - -#include "sdkconfig.h" - -#include "btc_ble_mesh_light_client.h" +#include "btc_ble_mesh_lighting_model.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 */ /* Light lightness client messages length */ -#define BT_MESH_LIGHT_LIGHTNESS_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_LIGHT_LIGHTNESS_SET_MSG_LEN (2 + 5 + 4) -#define BT_MESH_LIGHT_LIGHTNESS_LINEAR_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_LIGHT_LIGHTNESS_LINEAR_SET_MSG_LEN (2 + 5 + 4) -#define BT_MESH_LIGHT_LIGHTNESS_LAST_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_LIGHT_LIGHTNESS_DEFAULT_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_LIGHT_LIGHTNESS_DEFAULT_SET_MSG_LEN (2 + 2 + 4) -#define BT_MESH_LIGHT_LIGHTNESS_RANGE_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_LIGHT_LIGHTNESS_RANGE_SET_MSG_LEN (2 + 4 + 4) +#define BLE_MESH_LIGHT_LIGHTNESS_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_LIGHT_LIGHTNESS_SET_MSG_LEN (2 + 5 + 4) +#define BLE_MESH_LIGHT_LIGHTNESS_LINEAR_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_LIGHT_LIGHTNESS_LINEAR_SET_MSG_LEN (2 + 5 + 4) +#define BLE_MESH_LIGHT_LIGHTNESS_LAST_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_LIGHT_LIGHTNESS_DEFAULT_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_LIGHT_LIGHTNESS_DEFAULT_SET_MSG_LEN (2 + 2 + 4) +#define BLE_MESH_LIGHT_LIGHTNESS_RANGE_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_LIGHT_LIGHTNESS_RANGE_SET_MSG_LEN (2 + 4 + 4) /* Light CTL client messages length */ -#define BT_MESH_LIGHT_CTL_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_LIGHT_CTL_SET_MSG_LEN (2 + 9 + 4) -#define BT_MESH_LIGHT_CTL_TEMPERATURE_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_LIGHT_CTL_TEMPERATURE_SET_MSG_LEN (2 + 7 + 4) -#define BT_MESH_LIGHT_CTL_TEMPERATURE_RANGE_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_LIGHT_CTL_TEMPERATURE_RANGE_SET_MSG_LEN (2 + 4 + 4) -#define BT_MESH_LIGHT_CTL_DEFAULT_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_LIGHT_CTL_DEFAULT_SET_MSG_LEN (2 + 6 + 4) +#define BLE_MESH_LIGHT_CTL_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_LIGHT_CTL_SET_MSG_LEN (2 + 9 + 4) +#define BLE_MESH_LIGHT_CTL_TEMPERATURE_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_LIGHT_CTL_TEMPERATURE_SET_MSG_LEN (2 + 7 + 4) +#define BLE_MESH_LIGHT_CTL_TEMPERATURE_RANGE_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_LIGHT_CTL_TEMPERATURE_RANGE_SET_MSG_LEN (2 + 4 + 4) +#define BLE_MESH_LIGHT_CTL_DEFAULT_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_LIGHT_CTL_DEFAULT_SET_MSG_LEN (2 + 6 + 4) /* Light HSL client messages length */ -#define BT_MESH_LIGHT_HSL_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_LIGHT_HSL_SET_MSG_LEN (2 + 9 + 4) -#define BT_MESH_LIGHT_HSL_TARGET_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_LIGHT_HSL_HUE_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_LIGHT_HSL_HUE_SET_MSG_LEN (2 + 5 + 4) -#define BT_MESH_LIGHT_HSL_SATURATION_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_LIGHT_HSL_SATURATION_SET_MSG_LEN (2 + 5 + 4) -#define BT_MESH_LIGHT_HSL_DEFAULT_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_LIGHT_HSL_DEFAULT_SET_MSG_LEN (2 + 6 + 4) -#define BT_MESH_LIGHT_HSL_RANGE_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_LIGHT_HSL_RANGE_SET_MSG_LEN (2 + 8 + 4) +#define BLE_MESH_LIGHT_HSL_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_LIGHT_HSL_SET_MSG_LEN (2 + 9 + 4) +#define BLE_MESH_LIGHT_HSL_TARGET_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_LIGHT_HSL_HUE_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_LIGHT_HSL_HUE_SET_MSG_LEN (2 + 5 + 4) +#define BLE_MESH_LIGHT_HSL_SATURATION_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_LIGHT_HSL_SATURATION_SET_MSG_LEN (2 + 5 + 4) +#define BLE_MESH_LIGHT_HSL_DEFAULT_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_LIGHT_HSL_DEFAULT_SET_MSG_LEN (2 + 6 + 4) +#define BLE_MESH_LIGHT_HSL_RANGE_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_LIGHT_HSL_RANGE_SET_MSG_LEN (2 + 8 + 4) /* Light xyL client messages length */ -#define BT_MESH_LIGHT_XYL_SET_MSG_LEN (2 + 9 + 4) -#define BT_MESH_LIGHT_XYL_DEFAULT_SET_MSG_LEN (2 + 6 + 4) -#define BT_MESH_LIGHT_XYL_RANGE_SET_MSG_LEN (2 + 8 + 4) +#define BLE_MESH_LIGHT_XYL_SET_MSG_LEN (2 + 9 + 4) +#define BLE_MESH_LIGHT_XYL_DEFAULT_SET_MSG_LEN (2 + 6 + 4) +#define BLE_MESH_LIGHT_XYL_RANGE_SET_MSG_LEN (2 + 8 + 4) /* Light LC client messages length */ -#define BT_MESH_LIGHT_LC_MODE_SET_MSG_LEN (2 + 1 + 4) -#define BT_MESH_LIGHT_LC_OM_SET_MSG_LEN (2 + 1 + 4) -#define BT_MESH_LIGHT_LC_LIGHT_ONOFF_SET_MSG_LEN (2 + 4 + 4) -#define BT_MESH_LIGHT_LC_PROPERTY_GET_MSG_LEN (2 + 2 + 4) -#define BT_MESH_LIGHT_LC_PROPERTY_SET_MSG_LEN /* variable */ +#define BLE_MESH_LIGHT_LC_MODE_SET_MSG_LEN (2 + 1 + 4) +#define BLE_MESH_LIGHT_LC_OM_SET_MSG_LEN (2 + 1 + 4) +#define BLE_MESH_LIGHT_LC_LIGHT_ONOFF_SET_MSG_LEN (2 + 4 + 4) +#define BLE_MESH_LIGHT_LC_PROPERTY_GET_MSG_LEN (2 + 2 + 4) +#define BLE_MESH_LIGHT_LC_PROPERTY_SET_MSG_LEN /* variable */ -#define BT_MESH_LIGHT_GET_STATE_MSG_LEN (2 + 2 + 4) +#define BLE_MESH_LIGHT_GET_STATE_MSG_LEN (2 + 2 + 4) static const bt_mesh_client_op_pair_t light_op_pair[] = { - { BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_GET, BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET, BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_GET, BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET, BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_GET, BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_GET, BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET, BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_GET, BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET, BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_CTL_GET, BT_MESH_MODEL_OP_LIGHT_CTL_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_CTL_SET, BT_MESH_MODEL_OP_LIGHT_CTL_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_GET, BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET, BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_GET, BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET, BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_GET, BT_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET, BT_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_HSL_GET, BT_MESH_MODEL_OP_LIGHT_HSL_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_HSL_SET, BT_MESH_MODEL_OP_LIGHT_HSL_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_HSL_TARGET_GET, BT_MESH_MODEL_OP_LIGHT_HSL_TARGET_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_HSL_HUE_GET, BT_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_HSL_HUE_SET, BT_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_HSL_SATURATION_GET, BT_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET, BT_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_GET, BT_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET, BT_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_HSL_RANGE_GET, BT_MESH_MODEL_OP_LIGHT_HSL_RANGE_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET, BT_MESH_MODEL_OP_LIGHT_HSL_RANGE_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_XYL_GET, BT_MESH_MODEL_OP_LIGHT_XYL_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_XYL_SET, BT_MESH_MODEL_OP_LIGHT_XYL_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_XYL_TARGET_GET, BT_MESH_MODEL_OP_LIGHT_XYL_TARGET_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_GET, BT_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET, BT_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_XYL_RANGE_GET, BT_MESH_MODEL_OP_LIGHT_XYL_RANGE_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET, BT_MESH_MODEL_OP_LIGHT_XYL_RANGE_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_LC_MODE_GET, BT_MESH_MODEL_OP_LIGHT_LC_MODE_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_LC_MODE_SET, BT_MESH_MODEL_OP_LIGHT_LC_MODE_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_LC_OM_GET, BT_MESH_MODEL_OP_LIGHT_LC_OM_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_LC_OM_SET, BT_MESH_MODEL_OP_LIGHT_LC_OM_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_GET, BT_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET, BT_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET, BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS }, - { BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET, BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_GET, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_GET, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_GET, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_GET, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_GET, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET, BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_CTL_GET, BLE_MESH_MODEL_OP_LIGHT_CTL_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_CTL_SET, BLE_MESH_MODEL_OP_LIGHT_CTL_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_GET, BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET, BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_GET, BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET, BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_GET, BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET, BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_HSL_GET, BLE_MESH_MODEL_OP_LIGHT_HSL_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_HSL_SET, BLE_MESH_MODEL_OP_LIGHT_HSL_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_HSL_TARGET_GET, BLE_MESH_MODEL_OP_LIGHT_HSL_TARGET_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_GET, BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET, BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_GET, BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET, BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_GET, BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET, BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_GET, BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET, BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_XYL_GET, BLE_MESH_MODEL_OP_LIGHT_XYL_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_XYL_SET, BLE_MESH_MODEL_OP_LIGHT_XYL_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_XYL_TARGET_GET, BLE_MESH_MODEL_OP_LIGHT_XYL_TARGET_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_GET, BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET, BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_GET, BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET, BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_LC_MODE_GET, BLE_MESH_MODEL_OP_LIGHT_LC_MODE_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_LC_MODE_SET, BLE_MESH_MODEL_OP_LIGHT_LC_MODE_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_LC_OM_GET, BLE_MESH_MODEL_OP_LIGHT_LC_OM_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_LC_OM_SET, BLE_MESH_MODEL_OP_LIGHT_LC_OM_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_GET, BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET, BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET, BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS }, + { BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET, BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS }, }; static void timeout_handler(struct k_work *work) { - bt_mesh_light_client_t *client = NULL; - light_internal_data_t *internal = NULL; - bt_mesh_client_node_t *node = NULL; + light_internal_data_t *internal = NULL; + bt_mesh_light_client_t *client = NULL; + bt_mesh_client_node_t *node = NULL; BT_WARN("Receive light status message timeout"); node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work); if (!node || !node->ctx.model) { - BT_ERR("%s: node parameter is NULL", __func__); + BT_ERR("%s, Invalid parameter", __func__); return; } client = (bt_mesh_light_client_t *)node->ctx.model->user_data; if (!client) { - BT_ERR("%s: model user_data is NULL", __func__); + BT_ERR("%s, Lighting Client user_data is NULL", __func__); return; } internal = (light_internal_data_t *)client->internal_data; if (!internal) { - BT_ERR("%s: internal_data is NULL", __func__); + BT_ERR("%s, Lighting Client internal_data is NULL", __func__); return; } @@ -167,82 +166,82 @@ static void light_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { - bt_mesh_light_client_t *client = NULL; - light_internal_data_t *internal = NULL; - bt_mesh_client_node_t *node = NULL; + light_internal_data_t *internal = NULL; + bt_mesh_light_client_t *client = NULL; + bt_mesh_client_node_t *node = NULL; u8_t *val = NULL; u8_t evt = 0xFF; u32_t rsp = 0; size_t len = 0; - BT_DBG("%s: len %d, bytes %s", __func__, buf->len, bt_hex(buf->data, buf->len)); + BT_DBG("%s, len %d, bytes %s", __func__, buf->len, bt_hex(buf->data, buf->len)); client = (bt_mesh_light_client_t *)model->user_data; if (!client) { - BT_ERR("%s: model user_data is NULL", __func__); + BT_ERR("%s, Lighting Client user_data is NULL", __func__); return; } internal = (light_internal_data_t *)client->internal_data; if (!internal) { - BT_ERR("%s: model internal_data is NULL", __func__); + BT_ERR("%s, Lighting Client internal_data is NULL", __func__); return; } rsp = ctx->recv_op; switch (rsp) { - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS: { + 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("Wrong Light lightness status length %d", buf->len); + BT_ERR("%s, Invalid Light Lightness Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_lightness_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } - status->present_lightness = net_buf_simple_pull_le16(buf); + status->present_lightness = net_buf_simple_pull_le16(buf); if (buf->len) { - status->op_en = true; + status->op_en = true; status->target_lightness = net_buf_simple_pull_le16(buf); - status->remain_time = net_buf_simple_pull_u8(buf); + status->remain_time = net_buf_simple_pull_u8(buf); } val = (u8_t *)status; len = sizeof(struct bt_mesh_light_lightness_status); break; } - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS: { + 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("Wrong Light lightness status length %d", buf->len); + BT_ERR("%s, Invalid Light Lightness Linear Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_lightness_linear_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } - status->present_lightness = net_buf_simple_pull_le16(buf); + status->present_lightness = net_buf_simple_pull_le16(buf); if (buf->len) { - status->op_en = true; + status->op_en = true; status->target_lightness = net_buf_simple_pull_le16(buf); - status->remain_time = net_buf_simple_pull_u8(buf); + status->remain_time = net_buf_simple_pull_u8(buf); } val = (u8_t *)status; len = sizeof(struct bt_mesh_light_lightness_linear_status); break; } - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_STATUS: { + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_STATUS: { struct bt_mesh_light_lightness_last_status *status = NULL; if (buf->len != 2) { - BT_ERR("Wrong Light last status length %d", buf->len); + BT_ERR("%s, Invalid Light Lightness Last Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_lightness_last_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->lightness = net_buf_simple_pull_le16(buf); @@ -250,15 +249,15 @@ static void light_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_light_lightness_last_status); break; } - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_STATUS: { + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_STATUS: { struct bt_mesh_light_lightness_default_status *status = NULL; if (buf->len != 2) { - BT_ERR("Wrong Light default status length %d", buf->len); + BT_ERR("%s, Invalid Light Lightness Default Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_lightness_default_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->lightness = net_buf_simple_pull_le16(buf); @@ -266,239 +265,239 @@ static void light_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_light_lightness_default_status); break; } - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS: { + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS: { struct bt_mesh_light_lightness_range_status *status = NULL; if (buf->len != 5) { - BT_ERR("Wrong Light last status length %d", buf->len); + BT_ERR("%s, Invalid Light Lightness Range Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_lightness_range_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->status_code = net_buf_simple_pull_u8(buf); - status->range_min = net_buf_simple_pull_le16(buf); - status->range_max = net_buf_simple_pull_le16(buf); + status->range_min = net_buf_simple_pull_le16(buf); + status->range_max = net_buf_simple_pull_le16(buf); val = (u8_t *)status; len = sizeof(struct bt_mesh_light_lightness_range_status); break; } - case BT_MESH_MODEL_OP_LIGHT_CTL_STATUS: { + 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("Wrong Light CTL status length %d", buf->len); + BT_ERR("%s, Invalid Light CTL Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_ctl_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } - status->present_ctl_lightness = net_buf_simple_pull_le16(buf); - status->present_ctl_temperature = net_buf_simple_pull_le16(buf); + status->present_ctl_lightness = net_buf_simple_pull_le16(buf); + status->present_ctl_temperature = net_buf_simple_pull_le16(buf); if (buf->len) { - status->op_en = true; - status->target_ctl_lightness = net_buf_simple_pull_le16(buf); + status->op_en = true; + status->target_ctl_lightness = net_buf_simple_pull_le16(buf); status->target_ctl_temperature = net_buf_simple_pull_le16(buf); - status->remain_time = net_buf_simple_pull_u8(buf); + status->remain_time = net_buf_simple_pull_u8(buf); } val = (u8_t *)status; len = sizeof(struct bt_mesh_light_ctl_status); break; } - case BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS: { + 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("Wrong Light CTL temperature status length %d", buf->len); + BT_ERR("%s, Invalid Light CTL Temperature Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_ctl_temperature_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->present_ctl_temperature = net_buf_simple_pull_le16(buf); - status->present_ctl_delta_uv = net_buf_simple_pull_le16(buf); + status->present_ctl_delta_uv = net_buf_simple_pull_le16(buf); if (buf->len) { - status->op_en = true; + status->op_en = true; status->target_ctl_temperature = net_buf_simple_pull_le16(buf); - status->target_ctl_delta_uv = net_buf_simple_pull_le16(buf); - status->remain_time = net_buf_simple_pull_u8(buf); + status->target_ctl_delta_uv = net_buf_simple_pull_le16(buf); + status->remain_time = net_buf_simple_pull_u8(buf); } val = (u8_t *)status; len = sizeof(struct bt_mesh_light_ctl_temperature_status); break; } - case BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS: { + 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("Wrong Light CTL temperature range status length %d", buf->len); + BT_ERR("%s, Invalid Light CTL Temperature Range Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_ctl_temperature_range_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->status_code = net_buf_simple_pull_u8(buf); - status->range_min = net_buf_simple_pull_le16(buf); - status->range_max = net_buf_simple_pull_le16(buf); + status->range_min = net_buf_simple_pull_le16(buf); + status->range_max = net_buf_simple_pull_le16(buf); val = (u8_t *)status; len = sizeof(struct bt_mesh_light_ctl_temperature_range_status); break; } - case BT_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS: { + case BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS: { struct bt_mesh_light_ctl_default_status *status = NULL; if (buf->len != 6) { - BT_ERR("Wrong Light CTL default status length %d", buf->len); + BT_ERR("%s, Invalid Light CTL Default Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_ctl_default_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } - status->lightness = net_buf_simple_pull_le16(buf); + status->lightness = net_buf_simple_pull_le16(buf); status->temperature = net_buf_simple_pull_le16(buf); - status->delta_uv = net_buf_simple_pull_le16(buf); + status->delta_uv = net_buf_simple_pull_le16(buf); val = (u8_t *)status; len = sizeof(struct bt_mesh_light_ctl_default_status); break; } - case BT_MESH_MODEL_OP_LIGHT_HSL_STATUS: { + 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("Wrong Light HSL status length %d", buf->len); + BT_ERR("%s, Invalid Light HSL Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_hsl_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } - status->hsl_lightness = net_buf_simple_pull_le16(buf); - status->hsl_hue = net_buf_simple_pull_le16(buf); + status->hsl_lightness = net_buf_simple_pull_le16(buf); + status->hsl_hue = net_buf_simple_pull_le16(buf); status->hsl_saturation = net_buf_simple_pull_le16(buf); if (buf->len) { - status->op_en = true; + status->op_en = true; status->remain_time = net_buf_simple_pull_u8(buf); } val = (u8_t *)status; len = sizeof(struct bt_mesh_light_hsl_status); break; } - case BT_MESH_MODEL_OP_LIGHT_HSL_TARGET_STATUS: { + 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("Wrong Light HSL target status length %d", buf->len); + BT_ERR("%s, Invalid Light HSL Target Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_hsl_target_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } - status->hsl_lightness_target = net_buf_simple_pull_le16(buf); - status->hsl_hue_target = net_buf_simple_pull_le16(buf); + status->hsl_lightness_target = net_buf_simple_pull_le16(buf); + status->hsl_hue_target = net_buf_simple_pull_le16(buf); status->hsl_saturation_target = net_buf_simple_pull_le16(buf); if (buf->len) { - status->op_en = true; + status->op_en = true; status->remain_time = net_buf_simple_pull_u8(buf); } val = (u8_t *)status; len = sizeof(struct bt_mesh_light_hsl_target_status); break; } - case BT_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS: { + 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("Wrong Light HSL Hue status length %d", buf->len); + BT_ERR("%s, Invalid Light HSL Hue Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_hsl_hue_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->present_hue = net_buf_simple_pull_le16(buf); if (buf->len) { - status->op_en = true; - status->target_hue = net_buf_simple_pull_le16(buf); + status->op_en = true; + status->target_hue = net_buf_simple_pull_le16(buf); status->remain_time = net_buf_simple_pull_u8(buf); } val = (u8_t *)status; len = sizeof(struct bt_mesh_light_hsl_hue_status); break; } - case BT_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS: { + 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("Wrong Light HSL saturation status length %d", buf->len); + BT_ERR("%s, Invalid Light HSL Saturation Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_hsl_saturation_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->present_saturation = net_buf_simple_pull_le16(buf); if (buf->len) { - status->op_en = true; + status->op_en = true; status->target_saturation = net_buf_simple_pull_le16(buf); - status->remain_time = net_buf_simple_pull_u8(buf); + status->remain_time = net_buf_simple_pull_u8(buf); } val = (u8_t *)status; len = sizeof(struct bt_mesh_light_hsl_saturation_status); break; } - case BT_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_STATUS: { + case BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_STATUS: { struct bt_mesh_light_hsl_default_status *status = NULL; if (buf->len != 6) { - BT_ERR("Wrong Light HSL default status length %d", buf->len); + BT_ERR("%s, Invalid Light HSL Default Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_hsl_default_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } - status->lightness = net_buf_simple_pull_le16(buf); - status->hue = net_buf_simple_pull_le16(buf); + status->lightness = net_buf_simple_pull_le16(buf); + status->hue = net_buf_simple_pull_le16(buf); status->saturation = net_buf_simple_pull_le16(buf); val = (u8_t *)status; len = sizeof(struct bt_mesh_light_hsl_default_status); break; } - case BT_MESH_MODEL_OP_LIGHT_HSL_RANGE_STATUS: { + case BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_STATUS: { struct bt_mesh_light_hsl_range_status *status = NULL; if (buf->len != 9) { - BT_ERR("Wrong Light HSL range status length %d", buf->len); + BT_ERR("%s, Invalid Light HSL Range Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_hsl_range_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } - status->status_code = net_buf_simple_pull_u8(buf); - status->hue_range_min = net_buf_simple_pull_le16(buf); - status->hue_range_max = net_buf_simple_pull_le16(buf); + status->status_code = net_buf_simple_pull_u8(buf); + status->hue_range_min = net_buf_simple_pull_le16(buf); + status->hue_range_max = net_buf_simple_pull_le16(buf); status->saturation_range_min = net_buf_simple_pull_le16(buf); status->saturation_range_max = net_buf_simple_pull_le16(buf); val = (u8_t *)status; len = sizeof(struct bt_mesh_light_hsl_range_status); break; } - case BT_MESH_MODEL_OP_LIGHT_XYL_STATUS: { + 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("Wrong Light xyL status length %d", buf->len); + BT_ERR("%s, Invalid Light xyL Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_xyl_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->xyl_lightness = net_buf_simple_pull_le16(buf); @@ -512,15 +511,15 @@ static void light_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_light_xyl_status); break; } - case BT_MESH_MODEL_OP_LIGHT_XYL_TARGET_STATUS: { + 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("Wrong Light xyL Target status length %d", buf->len); + BT_ERR("%s, Invalid Light xyL Target Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_xyl_target_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->target_xyl_lightness = net_buf_simple_pull_le16(buf); @@ -534,15 +533,15 @@ static void light_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_light_xyl_target_status); break; } - case BT_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_STATUS: { + case BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_STATUS: { struct bt_mesh_light_xyl_default_status *status = NULL; if (buf->len != 6) { - BT_ERR("Wrong Light xyL Default status length %d", buf->len); + BT_ERR("%s, Invalid Light xyL Default Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_xyl_default_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->lightness = net_buf_simple_pull_le16(buf); @@ -552,15 +551,15 @@ static void light_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_light_xyl_default_status); break; } - case BT_MESH_MODEL_OP_LIGHT_XYL_RANGE_STATUS: { + case BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_STATUS: { struct bt_mesh_light_xyl_range_status *status = NULL; if (buf->len != 9) { - BT_ERR("Wrong Light xyL Range status length %d", buf->len); + BT_ERR("%s, Invalid Light xyL Range Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_xyl_range_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->status_code = net_buf_simple_pull_u8(buf); @@ -572,15 +571,15 @@ static void light_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_light_xyl_range_status); break; } - case BT_MESH_MODEL_OP_LIGHT_LC_MODE_STATUS: { + case BLE_MESH_MODEL_OP_LIGHT_LC_MODE_STATUS: { struct bt_mesh_light_lc_mode_status *status = NULL; if (buf->len != 1) { - BT_ERR("Wrong Light LC Mode status length %d", buf->len); + BT_ERR("%s, Invalid Light LC Mode Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_lc_mode_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->mode = net_buf_simple_pull_u8(buf); @@ -588,15 +587,15 @@ static void light_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_light_lc_mode_status); break; } - case BT_MESH_MODEL_OP_LIGHT_LC_OM_STATUS: { + case BLE_MESH_MODEL_OP_LIGHT_LC_OM_STATUS: { struct bt_mesh_light_lc_om_status *status = NULL; if (buf->len != 1) { - BT_ERR("Wrong Light LC OM status length %d", buf->len); + BT_ERR("%s, Invalid Light LC OM Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_lc_om_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->mode = net_buf_simple_pull_u8(buf); @@ -604,15 +603,15 @@ static void light_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_light_lc_om_status); break; } - case BT_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS: { + 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("Wrong Light LC Light OnOff status length %d", buf->len); + BT_ERR("%s, Invalid Light LC Light OnOff Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_light_lc_light_onoff_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->present_light_onoff = net_buf_simple_pull_u8(buf); @@ -625,17 +624,17 @@ static void light_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_light_lc_light_onoff_status); break; } - case BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS: { + case BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS: { struct bt_mesh_light_lc_property_status *status = NULL; status = osi_calloc(sizeof(struct bt_mesh_light_lc_property_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate 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: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); osi_free(status); return; } @@ -646,7 +645,7 @@ static void light_status(struct bt_mesh_model *model, break; } default: - BT_ERR("Not a lighting status message opcode"); + BT_ERR("%s, Not a Lighting Status message opcode", __func__); return; } @@ -657,51 +656,51 @@ static void light_status(struct bt_mesh_model *model, BT_DBG("Unexpected light status message 0x%x", rsp); } else { switch (node->opcode) { - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_GET: - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_GET: - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_GET: - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_GET: - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_GET: - case BT_MESH_MODEL_OP_LIGHT_CTL_GET: - case BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_GET: - case BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_GET: - case BT_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_GET: - case BT_MESH_MODEL_OP_LIGHT_HSL_GET: - case BT_MESH_MODEL_OP_LIGHT_HSL_TARGET_GET: - case BT_MESH_MODEL_OP_LIGHT_HSL_HUE_GET: - case BT_MESH_MODEL_OP_LIGHT_HSL_SATURATION_GET: - case BT_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_GET: - case BT_MESH_MODEL_OP_LIGHT_HSL_RANGE_GET: - case BT_MESH_MODEL_OP_LIGHT_XYL_GET: - case BT_MESH_MODEL_OP_LIGHT_XYL_TARGET_GET: - case BT_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_GET: - case BT_MESH_MODEL_OP_LIGHT_XYL_RANGE_GET: - case BT_MESH_MODEL_OP_LIGHT_LC_MODE_GET: - case BT_MESH_MODEL_OP_LIGHT_LC_OM_GET: - case BT_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_GET: - case BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_GET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_GET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_GET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_GET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_GET: + case BLE_MESH_MODEL_OP_LIGHT_CTL_GET: + case BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_GET: + case BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_GET: + case BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_GET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_GET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_TARGET_GET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_GET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_GET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_GET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_GET: + case BLE_MESH_MODEL_OP_LIGHT_XYL_GET: + case BLE_MESH_MODEL_OP_LIGHT_XYL_TARGET_GET: + case BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_GET: + case BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_GET: + case BLE_MESH_MODEL_OP_LIGHT_LC_MODE_GET: + case BLE_MESH_MODEL_OP_LIGHT_LC_OM_GET: + case BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_GET: + case BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET: evt = 0x00; break; - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET: - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET: - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET: - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET: - case BT_MESH_MODEL_OP_LIGHT_CTL_SET: - case BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET: - case BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET: - case BT_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET: - case BT_MESH_MODEL_OP_LIGHT_HSL_SET: - case BT_MESH_MODEL_OP_LIGHT_HSL_HUE_SET: - case BT_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET: - case BT_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET: - case BT_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET: - case BT_MESH_MODEL_OP_LIGHT_XYL_SET: - case BT_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET: - case BT_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET: - case BT_MESH_MODEL_OP_LIGHT_LC_MODE_SET: - case BT_MESH_MODEL_OP_LIGHT_LC_OM_SET: - case BT_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET: - case BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET: + case BLE_MESH_MODEL_OP_LIGHT_CTL_SET: + case BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET: + case BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET: + case BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_SET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET: + case BLE_MESH_MODEL_OP_LIGHT_XYL_SET: + case BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET: + case BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET: + case BLE_MESH_MODEL_OP_LIGHT_LC_MODE_SET: + case BLE_MESH_MODEL_OP_LIGHT_LC_OM_SET: + case BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET: + case BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET: evt = 0x01; break; default: @@ -714,7 +713,7 @@ static void light_status(struct bt_mesh_model *model, } switch (rsp) { - case BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS: { + case BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS: { struct bt_mesh_light_lc_property_status *status; status = (struct bt_mesh_light_lc_property_status *)val; bt_mesh_free_buf(status->light_lc_property_value); @@ -730,58 +729,58 @@ static void light_status(struct bt_mesh_model *model, } const struct bt_mesh_model_op light_lightness_cli_op[] = { - { BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_STATUS, 2, light_status }, - { BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_STATUS, 2, light_status }, - { BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_STATUS, 2, light_status }, - { BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_STATUS, 2, light_status }, - { BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS, 5, light_status }, - BT_MESH_MODEL_OP_END, + { 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 }, + { BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_STATUS, 2, light_status }, + { BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_STATUS, 5, light_status }, + BLE_MESH_MODEL_OP_END, }; const struct bt_mesh_model_op light_ctl_cli_op[] = { - { BT_MESH_MODEL_OP_LIGHT_CTL_STATUS, 4, light_status }, - { BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_STATUS, 4, light_status }, - { BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_STATUS, 5, light_status }, - { BT_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS, 6, light_status }, - BT_MESH_MODEL_OP_END, + { 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 }, + { BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_STATUS, 6, light_status }, + BLE_MESH_MODEL_OP_END, }; const struct bt_mesh_model_op light_hsl_cli_op[] = { - { BT_MESH_MODEL_OP_LIGHT_HSL_STATUS, 6, light_status }, - { BT_MESH_MODEL_OP_LIGHT_HSL_TARGET_STATUS, 6, light_status }, - { BT_MESH_MODEL_OP_LIGHT_HSL_HUE_STATUS, 2, light_status }, - { BT_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS, 2, light_status }, - { BT_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_STATUS, 6, light_status }, - { BT_MESH_MODEL_OP_LIGHT_HSL_RANGE_STATUS, 9, light_status }, - BT_MESH_MODEL_OP_END, + { 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 }, + { BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_STATUS, 2, light_status }, + { BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_STATUS, 6, light_status }, + { BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_STATUS, 9, light_status }, + BLE_MESH_MODEL_OP_END, }; const struct bt_mesh_model_op light_xyl_cli_op[] = { - { BT_MESH_MODEL_OP_LIGHT_XYL_STATUS, 6, light_status }, - { BT_MESH_MODEL_OP_LIGHT_XYL_TARGET_STATUS, 6, light_status }, - { BT_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_STATUS, 6, light_status }, - { BT_MESH_MODEL_OP_LIGHT_XYL_RANGE_STATUS, 9, light_status }, - BT_MESH_MODEL_OP_END, + { 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 }, + { BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_STATUS, 9, light_status }, + BLE_MESH_MODEL_OP_END, }; const struct bt_mesh_model_op light_lc_cli_op[] = { - { BT_MESH_MODEL_OP_LIGHT_LC_MODE_STATUS, 1, light_status }, - { BT_MESH_MODEL_OP_LIGHT_LC_OM_STATUS, 1, light_status }, - { BT_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_STATUS, 1, light_status }, - { BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS, 2, light_status }, - BT_MESH_MODEL_OP_END, + { 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 }, + { BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_STATUS, 2, light_status }, + BLE_MESH_MODEL_OP_END, }; static int light_get_state(struct bt_mesh_common_param *common, void *value) { - struct net_buf_simple *msg = NET_BUF_SIMPLE(BT_MESH_LIGHT_GET_STATE_MSG_LEN); + struct net_buf_simple *msg = NET_BUF_SIMPLE(BLE_MESH_LIGHT_GET_STATE_MSG_LEN); int err; bt_mesh_model_msg_init(msg, common->opcode); if (value) { switch (common->opcode) { - case BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET: { + case BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET: { struct bt_mesh_light_lc_property_get *get; get = (struct bt_mesh_light_lc_property_get *)value; net_buf_simple_add_le16(msg, get->light_lc_property_id); @@ -797,7 +796,7 @@ static int light_get_state(struct bt_mesh_common_param *common, void *value) timeout_handler, common->msg_timeout, true, common->cb, common->cb_data); if (err) { - BT_ERR("Light get message send failed (err %d)", err); + BT_ERR("%s, Failed to send Lighting Client Get message (err %d)", __func__, err); } return err; @@ -811,15 +810,15 @@ static int light_set_state(struct bt_mesh_common_param *common, msg = bt_mesh_alloc_buf(value_len); if (!msg) { - BT_ERR("Light set allocate memory fail"); + BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; } bt_mesh_model_msg_init(msg, common->opcode); switch (common->opcode) { - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET: - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET_UNACK: { struct bt_mesh_light_lightness_set *set; set = (struct bt_mesh_light_lightness_set *)value; net_buf_simple_add_le16(msg, set->lightness); @@ -830,8 +829,8 @@ static int light_set_state(struct bt_mesh_common_param *common, } break; } - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET: - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET_UNACK: { struct bt_mesh_light_lightness_linear_set *set; set = (struct bt_mesh_light_lightness_linear_set *)value; net_buf_simple_add_le16(msg, set->lightness); @@ -842,23 +841,23 @@ static int light_set_state(struct bt_mesh_common_param *common, } break; } - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET: - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET_UNACK: { struct bt_mesh_light_lightness_default_set *set; set = (struct bt_mesh_light_lightness_default_set *)value; net_buf_simple_add_le16(msg, set->lightness); break; } - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET: - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET_UNACK: { struct bt_mesh_light_lightness_range_set *set; set = (struct bt_mesh_light_lightness_range_set *)value; net_buf_simple_add_le16(msg, set->range_min); net_buf_simple_add_le16(msg, set->range_max); break; } - case BT_MESH_MODEL_OP_LIGHT_CTL_SET: - case BT_MESH_MODEL_OP_LIGHT_CTL_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_CTL_SET: + case BLE_MESH_MODEL_OP_LIGHT_CTL_SET_UNACK: { struct bt_mesh_light_ctl_set *set; set = (struct bt_mesh_light_ctl_set *)value; net_buf_simple_add_le16(msg, set->ctl_lightness); @@ -871,8 +870,8 @@ static int light_set_state(struct bt_mesh_common_param *common, } break; } - case BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET: - case BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET: + case BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET_UNACK: { struct bt_mesh_light_ctl_temperature_set *set; set = (struct bt_mesh_light_ctl_temperature_set *)value; net_buf_simple_add_le16(msg, set->ctl_temperature); @@ -884,16 +883,16 @@ static int light_set_state(struct bt_mesh_common_param *common, } break; } - case BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET: - case BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET: + case BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET_UNACK: { struct bt_mesh_light_ctl_temperature_range_set *set; set = (struct bt_mesh_light_ctl_temperature_range_set *)value; net_buf_simple_add_le16(msg, set->range_min); net_buf_simple_add_le16(msg, set->range_max); break; } - case BT_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET: - case BT_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET: + case BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET_UNACK: { struct bt_mesh_light_ctl_default_set *set; set = (struct bt_mesh_light_ctl_default_set *)value; net_buf_simple_add_le16(msg, set->lightness); @@ -901,8 +900,8 @@ static int light_set_state(struct bt_mesh_common_param *common, net_buf_simple_add_le16(msg, set->delta_uv); break; } - case BT_MESH_MODEL_OP_LIGHT_HSL_SET: - case BT_MESH_MODEL_OP_LIGHT_HSL_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_HSL_SET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_SET_UNACK: { struct bt_mesh_light_hsl_set *set; set = (struct bt_mesh_light_hsl_set *)value; net_buf_simple_add_le16(msg, set->hsl_lightness); @@ -915,8 +914,8 @@ static int light_set_state(struct bt_mesh_common_param *common, } break; } - case BT_MESH_MODEL_OP_LIGHT_HSL_HUE_SET: - case BT_MESH_MODEL_OP_LIGHT_HSL_HUE_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET_UNACK: { struct bt_mesh_light_hsl_hue_set *set; set = (struct bt_mesh_light_hsl_hue_set *)value; net_buf_simple_add_le16(msg, set->hue); @@ -927,8 +926,8 @@ static int light_set_state(struct bt_mesh_common_param *common, } break; } - case BT_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET: - case BT_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET_UNACK: { struct bt_mesh_light_hsl_saturation_set *set; set = (struct bt_mesh_light_hsl_saturation_set *)value; net_buf_simple_add_le16(msg, set->saturation); @@ -939,8 +938,8 @@ static int light_set_state(struct bt_mesh_common_param *common, } break; } - case BT_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET: - case BT_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET_UNACK: { struct bt_mesh_light_hsl_default_set *set; set = (struct bt_mesh_light_hsl_default_set *)value; net_buf_simple_add_le16(msg, set->lightness); @@ -948,8 +947,8 @@ static int light_set_state(struct bt_mesh_common_param *common, net_buf_simple_add_le16(msg, set->saturation); break; } - case BT_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET: - case BT_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET_UNACK: { struct bt_mesh_light_hsl_range_set *set; set = (struct bt_mesh_light_hsl_range_set *)value; net_buf_simple_add_le16(msg, set->hue_range_min); @@ -958,8 +957,8 @@ static int light_set_state(struct bt_mesh_common_param *common, net_buf_simple_add_le16(msg, set->saturation_range_max); break; } - case BT_MESH_MODEL_OP_LIGHT_XYL_SET: - case BT_MESH_MODEL_OP_LIGHT_XYL_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_XYL_SET: + case BLE_MESH_MODEL_OP_LIGHT_XYL_SET_UNACK: { struct bt_mesh_light_xyl_set *set; set = (struct bt_mesh_light_xyl_set *)value; net_buf_simple_add_le16(msg, set->xyl_lightness); @@ -972,8 +971,8 @@ static int light_set_state(struct bt_mesh_common_param *common, } break; } - case BT_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET: - case BT_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET: + case BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET_UNACK: { struct bt_mesh_light_xyl_default_set *set; set = (struct bt_mesh_light_xyl_default_set *)value; net_buf_simple_add_le16(msg, set->lightness); @@ -981,8 +980,8 @@ static int light_set_state(struct bt_mesh_common_param *common, net_buf_simple_add_le16(msg, set->xyl_y); break; } - case BT_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET: - case BT_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET: + case BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET_UNACK: { struct bt_mesh_light_xyl_range_set *set; set = (struct bt_mesh_light_xyl_range_set *)value; net_buf_simple_add_le16(msg, set->xyl_x_range_min); @@ -991,22 +990,22 @@ static int light_set_state(struct bt_mesh_common_param *common, net_buf_simple_add_le16(msg, set->xyl_y_range_max); break; } - case BT_MESH_MODEL_OP_LIGHT_LC_MODE_SET: - case BT_MESH_MODEL_OP_LIGHT_LC_MODE_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_LC_MODE_SET: + case BLE_MESH_MODEL_OP_LIGHT_LC_MODE_SET_UNACK: { struct bt_mesh_light_lc_mode_set *set; set = (struct bt_mesh_light_lc_mode_set *)value; net_buf_simple_add_u8(msg, set->mode); break; } - case BT_MESH_MODEL_OP_LIGHT_LC_OM_SET: - case BT_MESH_MODEL_OP_LIGHT_LC_OM_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_LC_OM_SET: + case BLE_MESH_MODEL_OP_LIGHT_LC_OM_SET_UNACK: { struct bt_mesh_light_lc_om_set *set; set = (struct bt_mesh_light_lc_om_set *)value; net_buf_simple_add_u8(msg, set->mode); break; } - case BT_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET: - case BT_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET: + case BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET_UNACK: { struct bt_mesh_light_lc_light_onoff_set *set; set = (struct bt_mesh_light_lc_light_onoff_set *)value; net_buf_simple_add_u8(msg, set->light_onoff); @@ -1017,8 +1016,8 @@ static int light_set_state(struct bt_mesh_common_param *common, } break; } - case BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET: - case BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET: + case BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK: { struct bt_mesh_light_lc_property_set *set; set = (struct bt_mesh_light_lc_property_set *)value; net_buf_simple_add_le16(msg, set->light_lc_property_id); @@ -1026,7 +1025,7 @@ static int light_set_state(struct bt_mesh_common_param *common, break; } default: - BT_ERR("Not a lighting client model set message opcode"); + BT_ERR("%s, Not a Lighting Client Set message opcode", __func__); err = -EINVAL; goto end; } @@ -1035,7 +1034,7 @@ static int light_set_state(struct bt_mesh_common_param *common, timeout_handler, common->msg_timeout, need_ack, common->cb, common->cb_data); if (err) { - BT_ERR("Light set message send failed (err %d)", err); + BT_ERR("%s, Failed to send Lighting Client Set message (err %d)", __func__, err); } end: @@ -1049,48 +1048,48 @@ int bt_mesh_light_client_get_state(struct bt_mesh_common_param *common, void *ge bt_mesh_light_client_t *client = NULL; if (!common || !common->model) { - BT_ERR("%s: common parameter is NULL", __func__); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } client = (bt_mesh_light_client_t *)common->model->user_data; if (!client || !client->internal_data) { - BT_ERR("%s: client parameter is NULL", __func__); + BT_ERR("%s, Lighting Client user data is NULL", __func__); return -EINVAL; } switch (common->opcode) { - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_GET: - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_GET: - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_GET: - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_GET: - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_GET: - case BT_MESH_MODEL_OP_LIGHT_CTL_GET: - case BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_GET: - case BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_GET: - case BT_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_GET: - case BT_MESH_MODEL_OP_LIGHT_HSL_GET: - case BT_MESH_MODEL_OP_LIGHT_HSL_TARGET_GET: - case BT_MESH_MODEL_OP_LIGHT_HSL_HUE_GET: - case BT_MESH_MODEL_OP_LIGHT_HSL_SATURATION_GET: - case BT_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_GET: - case BT_MESH_MODEL_OP_LIGHT_HSL_RANGE_GET: - case BT_MESH_MODEL_OP_LIGHT_XYL_GET: - case BT_MESH_MODEL_OP_LIGHT_XYL_TARGET_GET: - case BT_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_GET: - case BT_MESH_MODEL_OP_LIGHT_XYL_RANGE_GET: - case BT_MESH_MODEL_OP_LIGHT_LC_MODE_GET: - case BT_MESH_MODEL_OP_LIGHT_LC_OM_GET: - case BT_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_GET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_GET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_GET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LAST_GET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_GET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_GET: + case BLE_MESH_MODEL_OP_LIGHT_CTL_GET: + case BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_GET: + case BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_GET: + case BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_GET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_GET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_TARGET_GET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_GET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_GET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_GET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_GET: + case BLE_MESH_MODEL_OP_LIGHT_XYL_GET: + case BLE_MESH_MODEL_OP_LIGHT_XYL_TARGET_GET: + case BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_GET: + case BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_GET: + case BLE_MESH_MODEL_OP_LIGHT_LC_MODE_GET: + case BLE_MESH_MODEL_OP_LIGHT_LC_OM_GET: + case BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_GET: break; - case BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET: + case BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_GET: if (!get) { - BT_ERR("Lighting lc_property_get is NULL"); + BT_ERR("%s, Lighting lc_property_get is NULL", __func__); return -EINVAL; } break; default: - BT_ERR("Not a lighting get message opcode"); + BT_ERR("%s, Not a Lighting Client Get message opcode", __func__); return -EINVAL; } @@ -1104,237 +1103,237 @@ int bt_mesh_light_client_set_state(struct bt_mesh_common_param *common, void *se bool need_ack = false; if (!common || !common->model || !set) { - BT_ERR("%s: common parameter is NULL", __func__); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } client = (bt_mesh_light_client_t *)common->model->user_data; if (!client || !client->internal_data) { - BT_ERR("%s: client parameter is NULL", __func__); + BT_ERR("%s, Lighting Client user data is NULL", __func__); return -EINVAL; } switch (common->opcode) { - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET: need_ack = true; - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_SET_UNACK: { struct bt_mesh_light_lightness_set *value; value = (struct bt_mesh_light_lightness_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("Light lightness set transition time is bigger than 0x3E"); + BT_ERR("%s, Invalid Light Lightness Set transition time", __func__); return -EINVAL; } } - length = BT_MESH_LIGHT_LIGHTNESS_SET_MSG_LEN; + length = BLE_MESH_LIGHT_LIGHTNESS_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET: need_ack = true; - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_LINEAR_SET_UNACK: { struct bt_mesh_light_lightness_linear_set *value; value = (struct bt_mesh_light_lightness_linear_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("Light lightness linear set transition time is bigger than 0x3E"); + BT_ERR("%s, Invalid Light Lightness Linear Set transition time", __func__); return -EINVAL; } } - length = BT_MESH_LIGHT_LIGHTNESS_LINEAR_SET_MSG_LEN; + length = BLE_MESH_LIGHT_LIGHTNESS_LINEAR_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET: need_ack = true; - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET_UNACK: - length = BT_MESH_LIGHT_LIGHTNESS_DEFAULT_SET_MSG_LEN; + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_DEFAULT_SET_UNACK: + length = BLE_MESH_LIGHT_LIGHTNESS_DEFAULT_SET_MSG_LEN; break; - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET: + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET: need_ack = true; - case BT_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_LIGHTNESS_RANGE_SET_UNACK: { 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("Light lightness range set range min is greater than range max"); + BT_ERR("%s, Light Lightness Range Set range min is greater than range max", __func__); return -EINVAL; } - length = BT_MESH_LIGHT_LIGHTNESS_RANGE_SET_MSG_LEN; + length = BLE_MESH_LIGHT_LIGHTNESS_RANGE_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_LIGHT_CTL_SET: + case BLE_MESH_MODEL_OP_LIGHT_CTL_SET: need_ack = true; - case BT_MESH_MODEL_OP_LIGHT_CTL_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_CTL_SET_UNACK: { struct bt_mesh_light_ctl_set *value; value = (struct bt_mesh_light_ctl_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("Light ctl set transition time is bigger than 0x3E"); + BT_ERR("%s, Invalid Light CTL Set transition time", __func__); return -EINVAL; } } - length = BT_MESH_LIGHT_CTL_SET_MSG_LEN; + length = BLE_MESH_LIGHT_CTL_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET: + case BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET: need_ack = true; - case BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_SET_UNACK: { struct bt_mesh_light_ctl_temperature_set *value; value = (struct bt_mesh_light_ctl_temperature_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("Light ctl temperature set transition time is bigger than 0x3E"); + BT_ERR("%s, Invalid Light CTL Temperature Set transition time", __func__); return -EINVAL; } } - length = BT_MESH_LIGHT_CTL_TEMPERATURE_SET_MSG_LEN; + length = BLE_MESH_LIGHT_CTL_TEMPERATURE_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET: + case BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET: need_ack = true; - case BT_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_CTL_TEMPERATURE_RANGE_SET_UNACK: { 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("Light ctl temperature range set range min is greater than range max"); + BT_ERR("%s, Light CTL Temperature Range Set range min is greater than range max", __func__); return -EINVAL; } - length = BT_MESH_LIGHT_CTL_TEMPERATURE_RANGE_SET_MSG_LEN; + length = BLE_MESH_LIGHT_CTL_TEMPERATURE_RANGE_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET: + case BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET: need_ack = true; - case BT_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET_UNACK: - length = BT_MESH_LIGHT_CTL_DEFAULT_SET_MSG_LEN; + case BLE_MESH_MODEL_OP_LIGHT_CTL_DEFAULT_SET_UNACK: + length = BLE_MESH_LIGHT_CTL_DEFAULT_SET_MSG_LEN; break; - case BT_MESH_MODEL_OP_LIGHT_HSL_SET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_SET: need_ack = true; - case BT_MESH_MODEL_OP_LIGHT_HSL_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_HSL_SET_UNACK: { struct bt_mesh_light_hsl_set *value; value = (struct bt_mesh_light_hsl_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("Light hsl set transition time is bigger than 0x3E"); + BT_ERR("%s, Invalid Light HSL Set transition time", __func__); return -EINVAL; } } - length = BT_MESH_LIGHT_HSL_SET_MSG_LEN; + length = BLE_MESH_LIGHT_HSL_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_LIGHT_HSL_HUE_SET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET: need_ack = true; - case BT_MESH_MODEL_OP_LIGHT_HSL_HUE_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_HSL_HUE_SET_UNACK: { struct bt_mesh_light_hsl_hue_set *value; value = (struct bt_mesh_light_hsl_hue_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("Light hsl hue set transition time is bigger than 0x3E"); + BT_ERR("%s, Invalid Light HSL Hue Set transition time", __func__); return -EINVAL; } } - length = BT_MESH_LIGHT_HSL_HUE_SET_MSG_LEN; + length = BLE_MESH_LIGHT_HSL_HUE_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET: need_ack = true; - case BT_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_HSL_SATURATION_SET_UNACK: { struct bt_mesh_light_hsl_saturation_set *value; value = (struct bt_mesh_light_hsl_saturation_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("Light hsl saturation set transition time is bigger than 0x3E"); + BT_ERR("%s, Invalid Light HSL Saturation Set transition time", __func__); return -EINVAL; } } - length = BT_MESH_LIGHT_HSL_SATURATION_SET_MSG_LEN; + length = BLE_MESH_LIGHT_HSL_SATURATION_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET: need_ack = true; - case BT_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET_UNACK: - length = BT_MESH_LIGHT_HSL_DEFAULT_SET_MSG_LEN; + case BLE_MESH_MODEL_OP_LIGHT_HSL_DEFAULT_SET_UNACK: + length = BLE_MESH_LIGHT_HSL_DEFAULT_SET_MSG_LEN; break; - case BT_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET: + case BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET: need_ack = true; - case BT_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_HSL_RANGE_SET_UNACK: { struct bt_mesh_light_hsl_range_set *value; 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("Light hsl range set range min is greater than range max"); + BT_ERR("%s, Light HSL Range Set range min is greater than range max", __func__); return -EINVAL; } - length = BT_MESH_LIGHT_HSL_RANGE_SET_MSG_LEN; + length = BLE_MESH_LIGHT_HSL_RANGE_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_LIGHT_XYL_SET: + case BLE_MESH_MODEL_OP_LIGHT_XYL_SET: need_ack = true; - case BT_MESH_MODEL_OP_LIGHT_XYL_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_XYL_SET_UNACK: { struct bt_mesh_light_xyl_set *value; value = (struct bt_mesh_light_xyl_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("Light xyl set transition time is bigger than 0x3E"); + BT_ERR("%s, Invalid Light xyL Set transition time", __func__); return -EINVAL; } } - length = BT_MESH_LIGHT_XYL_SET_MSG_LEN; + length = BLE_MESH_LIGHT_XYL_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET: + case BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET: need_ack = true; - case BT_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET_UNACK: - length = BT_MESH_LIGHT_XYL_DEFAULT_SET_MSG_LEN; + case BLE_MESH_MODEL_OP_LIGHT_XYL_DEFAULT_SET_UNACK: + length = BLE_MESH_LIGHT_XYL_DEFAULT_SET_MSG_LEN; break; - case BT_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET: + case BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET: need_ack = true; - case BT_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_XYL_RANGE_SET_UNACK: { struct bt_mesh_light_xyl_range_set *value; 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("Light xyl range set range min is greater than range max"); + BT_ERR("%s, Light xyL Range Set range min is greater than range max", __func__); return -EINVAL; } - length = BT_MESH_LIGHT_XYL_RANGE_SET_MSG_LEN; + length = BLE_MESH_LIGHT_XYL_RANGE_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_LIGHT_LC_MODE_SET: + case BLE_MESH_MODEL_OP_LIGHT_LC_MODE_SET: need_ack = true; - case BT_MESH_MODEL_OP_LIGHT_LC_MODE_SET_UNACK: - length = BT_MESH_LIGHT_LC_MODE_SET_MSG_LEN; + case BLE_MESH_MODEL_OP_LIGHT_LC_MODE_SET_UNACK: + length = BLE_MESH_LIGHT_LC_MODE_SET_MSG_LEN; break; - case BT_MESH_MODEL_OP_LIGHT_LC_OM_SET: + case BLE_MESH_MODEL_OP_LIGHT_LC_OM_SET: need_ack = true; - case BT_MESH_MODEL_OP_LIGHT_LC_OM_SET_UNACK: - length = BT_MESH_LIGHT_LC_OM_SET_MSG_LEN; + case BLE_MESH_MODEL_OP_LIGHT_LC_OM_SET_UNACK: + length = BLE_MESH_LIGHT_LC_OM_SET_MSG_LEN; break; - case BT_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET: + case BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET: need_ack = true; - case BT_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_LC_LIGHT_ONOFF_SET_UNACK: { struct bt_mesh_light_lc_light_onoff_set *value; value = (struct bt_mesh_light_lc_light_onoff_set *)set; if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("Light lc light onoff set transition time is bigger than 0x3E"); + BT_ERR("%s, Invalid Light LC Light OnOff Set transition time", __func__); return -EINVAL; } } - length = BT_MESH_LIGHT_LC_LIGHT_ONOFF_SET_MSG_LEN; + length = BLE_MESH_LIGHT_LC_LIGHT_ONOFF_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET: + case BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET: need_ack = true; - case BT_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK: { + case BLE_MESH_MODEL_OP_LIGHT_LC_PROPERTY_SET_UNACK: { 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("Lighting light_lc_property_value is NULL"); + BT_ERR("%s, Lighting light_lc_property_value is NULL", __func__); return -EINVAL; } length = (1 + 2 + value->light_lc_property_value->len + 4); break; } default: - BT_ERR("Not a lighting set message opcode"); + BT_ERR("%s, Not a Lighting Client Set message opcode", __func__); return -EINVAL; } @@ -1343,34 +1342,34 @@ int bt_mesh_light_client_set_state(struct bt_mesh_common_param *common, void *se static int light_client_init(struct bt_mesh_model *model, bool primary) { - bt_mesh_light_client_t *client = NULL; - light_internal_data_t *internal = NULL; + light_internal_data_t *internal = NULL; + bt_mesh_light_client_t *client = NULL; BT_DBG("primary %u", primary); if (!model) { - BT_ERR("Light client model is NULL"); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } client = (bt_mesh_light_client_t *)model->user_data; if (!client) { - BT_ERR("Light client model user_data is NULL"); + BT_ERR("%s, Lighting Client user_data is NULL", __func__); return -EINVAL; } /* TODO: call osi_free() when deinit function is invoked*/ internal = osi_calloc(sizeof(light_internal_data_t)); if (!internal) { - BT_ERR("Allocate memory for generic onoff internal data fail"); + BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; } sys_slist_init(&internal->queue); - client->model = model; - client->op_pair_size = ARRAY_SIZE(light_op_pair); - client->op_pair = light_op_pair; + client->model = model; + client->op_pair_size = ARRAY_SIZE(light_op_pair); + client->op_pair = light_op_pair; client->internal_data = internal; return 0; diff --git a/components/bt/ble_mesh/mesh_models/mesh_common.c b/components/bt/ble_mesh/mesh_models/mesh_common.c new file mode 100644 index 0000000000..4cc11e0e2d --- /dev/null +++ b/components/bt/ble_mesh/mesh_models/mesh_common.c @@ -0,0 +1,42 @@ +// Copyright 2017-2018 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include + +#include "mesh_common.h" + +struct net_buf_simple *bt_mesh_alloc_buf(u16_t size) +{ + struct net_buf_simple *buf; + + buf = (struct net_buf_simple *)osi_calloc(sizeof(struct net_buf_simple) + size); + if (!buf) { + BT_ERR("%s, Failed to allocate memory", __func__); + return NULL; + } + + /* buf->data will be initialized in net_buf_simple_init() */ + buf->len = 0; + buf->size = size; + + return buf; +} + +void bt_mesh_free_buf(struct net_buf_simple *buf) +{ + if (buf) { + osi_free(buf); + } +} diff --git a/components/bt/ble_mesh/mesh_models/bt_mesh_client_common.c b/components/bt/ble_mesh/mesh_models/model_common.c similarity index 73% rename from components/bt/ble_mesh/mesh_models/bt_mesh_client_common.c rename to components/bt/ble_mesh/mesh_models/model_common.c index aecc17e464..c904543de5 100644 --- a/components/bt/ble_mesh/mesh_models/bt_mesh_client_common.c +++ b/components/bt/ble_mesh/mesh_models/model_common.c @@ -12,33 +12,37 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "bt_mesh_client_common.h" +#include +#include + +#include "osi/allocator.h" + #include "mesh_access.h" #include "mesh_buf.h" -#include "mesh.h" #include "mesh_slist.h" -#include "errno.h" -#include "osi/allocator.h" -#include +#include "mesh_main.h" + +#include "mesh.h" +#include "model_common.h" bt_mesh_client_node_t *bt_mesh_is_model_message_publish(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf, bool need_pub) { - bt_mesh_client_common_t *cli = NULL; - bt_mesh_client_node_t *node = NULL; bt_mesh_internal_data_t *data = NULL; + bt_mesh_client_common_t *cli = NULL; + bt_mesh_client_node_t *node = NULL; u32_t rsp; if (!model || !ctx || !buf) { - BT_ERR("%s: invalid parameters", __func__); + BT_ERR("%s, Invalid parameter", __func__); return NULL; } cli = (bt_mesh_client_common_t *)model->user_data; if (!cli) { - BT_ERR("%s: model user_data is NULL", __func__); + BT_ERR("%s, Clinet user_data is NULL", __func__); return NULL; } @@ -48,7 +52,7 @@ bt_mesh_client_node_t *bt_mesh_is_model_message_publish(struct bt_mesh_model *mo * the address may be a group/virtual address, and we push * this message to the application layer. */ - if (!BT_MESH_ADDR_IS_UNICAST(ctx->recv_dst)) { + if (!BLE_MESH_ADDR_IS_UNICAST(ctx->recv_dst)) { BT_DBG("Unexpected status message 0x%x", rsp); if (cli->publish_status && need_pub) { cli->publish_status(rsp, model, ctx, buf); @@ -63,7 +67,7 @@ bt_mesh_client_node_t *bt_mesh_is_model_message_publish(struct bt_mesh_model *mo */ data = (bt_mesh_internal_data_t *)cli->internal_data; if (!data) { - BT_ERR("%s: internal_data is NULL", __func__); + BT_ERR("%s, Client internal_data is NULL", __func__); return NULL; } @@ -168,13 +172,13 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model, const struct bt_mesh_send_cb *cb, void *cb_data) { - bt_mesh_client_common_t *cli = NULL; bt_mesh_internal_data_t *internal = NULL; - bt_mesh_client_node_t *node = NULL; + bt_mesh_client_common_t *cli = NULL; + bt_mesh_client_node_t *node = NULL; int err; if (!model || !ctx || !msg) { - BT_ERR("%s: invalid parameters", __func__); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } @@ -195,14 +199,14 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model, /* Don't forget to free the node in the timeout (timer_handler) function. */ node = (bt_mesh_client_node_t *)osi_calloc(sizeof(bt_mesh_client_node_t)); if (!node) { - BT_ERR("%s: Failed to allocate memory", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; } memcpy(&node->ctx, ctx, sizeof(struct bt_mesh_msg_ctx)); node->ctx.model = model; - node->opcode = opcode; + node->opcode = opcode; if ((node->op_pending = bt_mesh_client_get_status_op(cli->op_pair, cli->op_pair_size, opcode)) == 0) { - BT_WARN("%s, Didn't find the status opcode in the op_pair list.", __func__); + BT_ERR("%s, Not found the status opcode in the op_pair list", __func__); osi_free(node); return -EINVAL; } @@ -211,7 +215,7 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model, } else { sys_slist_append(&internal->queue, &node->client_node); k_delayed_work_init(&node->timer, timer_handler); - k_delayed_work_submit(&node->timer, timeout ? timeout : CONFIG_BT_MESH_CLIENT_MSG_TIMEOUT); + k_delayed_work_submit(&node->timer, timeout ? timeout : CONFIG_BLE_MESH_CLIENT_MSG_TIMEOUT); } } @@ -220,36 +224,36 @@ int bt_mesh_client_send_msg(struct bt_mesh_model *model, int bt_mesh_client_init(struct bt_mesh_model *model) { - bt_mesh_client_common_t *cli = NULL; bt_mesh_internal_data_t *data = NULL; + bt_mesh_client_common_t *cli = NULL; if (!model) { - BT_ERR("Client model is NULL"); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } if (!model->op) { - BT_ERR("Client model op is NULL"); + BT_ERR("%s, Client model op is NULL", __func__); return -EINVAL; } cli = model->user_data; if (!cli) { - BT_ERR("Client model user_data is NULL"); + BT_ERR("%s, Client user_data is NULL", __func__); return -EINVAL; } /* TODO: call osi_free() when deinit function is invoked */ data = osi_calloc(sizeof(bt_mesh_internal_data_t)); if (!data) { - BT_ERR("Allocate memory for client internal data fail"); + BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; } /* Init the client data queue */ sys_slist_init(&data->queue); - cli->model = model; + cli->model = model; cli->internal_data = data; return 0; @@ -270,3 +274,63 @@ int bt_mesh_client_free_node(sys_slist_t *queue, bt_mesh_client_node_t *node) return 0; } + +int bt_mesh_set_model_role(bt_mesh_role_param_t *common) +{ + bt_mesh_client_common_t *client = NULL; + + if (!common || !common->model || !common->model->user_data) { + BT_ERR("%s, Invalid parameter", __func__); + return -EINVAL; + } + + client = (bt_mesh_client_common_t *)common->model->user_data; + + 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("%s, Provisioner is disabled", __func__); + 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("%s, Unknown model role %x", __func__, common->role); + return -EINVAL; + } + + return 0; +} + +u8_t bt_mesh_get_model_role(struct bt_mesh_model *model, bool srv_send) +{ + bt_mesh_client_common_t *client = NULL; + + if (srv_send) { + BT_DBG("%s, Message is sent by a server model", __func__); + return NODE; + } + + if (!model || !model->user_data) { + BT_ERR("%s, Invalid parameter", __func__); + return ROLE_NVAL; + } + + client = (bt_mesh_client_common_t *)model->user_data; + + return client->msg_role; +} diff --git a/components/bt/ble_mesh/mesh_models/sensor_client.c b/components/bt/ble_mesh/mesh_models/sensor_client.c index 4bd7a25ae4..a2f777d41f 100644 --- a/components/bt/ble_mesh/mesh_models/sensor_client.c +++ b/components/bt/ble_mesh/mesh_models/sensor_client.c @@ -17,70 +17,69 @@ #include #include "osi/allocator.h" +#include "sdkconfig.h" #include "mesh_types.h" #include "mesh_kernel.h" #include "mesh_trace.h" -#include "mesh.h" -#include "model_op.h" -#include "common.h" +#include "mesh.h" +#include "model_opcode.h" +#include "mesh_common.h" #include "sensor_client.h" -#include "sdkconfig.h" - -#include "btc_ble_mesh_sensor_client.h" +#include "btc_ble_mesh_sensor_model.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 */ /* Sensor client messages length */ -#define BT_MESH_SENSOR_DESCRIPTOR_GET_MSG_LEN (2 + 2 + 4) -#define BT_MESH_SENSOR_CADENCE_GET_MSG_LEN (2 + 2 + 4) -#define BT_MESH_SENSOR_CADENCE_SET_MSG_LEN /* variable */ -#define BT_MESH_SENSOR_SETTINGS_GET_MSG_LEN (2 + 2 + 4) -#define BT_MESH_SENSOR_SETTING_GET_MSG_LEN (2 + 4 + 4) -#define BT_MESH_SENSOR_SETTING_SET_MSG_LEN /* variable */ -#define BT_MESH_SENSOR_GET_MSG_LEN (2 + 2 + 4) -#define BT_MESH_SENSOR_COLUMN_GET_MSG_LEN /* variable */ -#define BT_MESH_SENSOR_SERIES_GET_MSG_LEN /* variable */ +#define BLE_MESH_SENSOR_DESCRIPTOR_GET_MSG_LEN (2 + 2 + 4) +#define BLE_MESH_SENSOR_CADENCE_GET_MSG_LEN (2 + 2 + 4) +#define BLE_MESH_SENSOR_CADENCE_SET_MSG_LEN /* variable */ +#define BLE_MESH_SENSOR_SETTINGS_GET_MSG_LEN (2 + 2 + 4) +#define BLE_MESH_SENSOR_SETTING_GET_MSG_LEN (2 + 4 + 4) +#define BLE_MESH_SENSOR_SETTING_SET_MSG_LEN /* variable */ +#define BLE_MESH_SENSOR_GET_MSG_LEN (2 + 2 + 4) +#define BLE_MESH_SENSOR_COLUMN_GET_MSG_LEN /* variable */ +#define BLE_MESH_SENSOR_SERIES_GET_MSG_LEN /* variable */ static const bt_mesh_client_op_pair_t sensor_op_pair[] = { - { BT_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET, BT_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS }, - { BT_MESH_MODEL_OP_SENSOR_CADENCE_GET, BT_MESH_MODEL_OP_SENSOR_CADENCE_STATUS }, - { BT_MESH_MODEL_OP_SENSOR_CADENCE_SET, BT_MESH_MODEL_OP_SENSOR_CADENCE_STATUS }, - { BT_MESH_MODEL_OP_SENSOR_SETTINGS_GET, BT_MESH_MODEL_OP_SENSOR_SETTINGS_STATUS }, - { BT_MESH_MODEL_OP_SENSOR_SETTING_GET, BT_MESH_MODEL_OP_SENSOR_SETTING_STATUS }, - { BT_MESH_MODEL_OP_SENSOR_SETTING_SET, BT_MESH_MODEL_OP_SENSOR_SETTING_STATUS }, - { BT_MESH_MODEL_OP_SENSOR_GET, BT_MESH_MODEL_OP_SENSOR_STATUS }, - { BT_MESH_MODEL_OP_SENSOR_COLUMN_GET, BT_MESH_MODEL_OP_SENSOR_COLUMN_STATUS }, - { BT_MESH_MODEL_OP_SENSOR_SERIES_GET, BT_MESH_MODEL_OP_SENSOR_SERIES_STATUS }, + { BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET, BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS }, + { BLE_MESH_MODEL_OP_SENSOR_CADENCE_GET, BLE_MESH_MODEL_OP_SENSOR_CADENCE_STATUS }, + { BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET, BLE_MESH_MODEL_OP_SENSOR_CADENCE_STATUS }, + { BLE_MESH_MODEL_OP_SENSOR_SETTINGS_GET, BLE_MESH_MODEL_OP_SENSOR_SETTINGS_STATUS }, + { BLE_MESH_MODEL_OP_SENSOR_SETTING_GET, BLE_MESH_MODEL_OP_SENSOR_SETTING_STATUS }, + { BLE_MESH_MODEL_OP_SENSOR_SETTING_SET, BLE_MESH_MODEL_OP_SENSOR_SETTING_STATUS }, + { BLE_MESH_MODEL_OP_SENSOR_GET, BLE_MESH_MODEL_OP_SENSOR_STATUS }, + { BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET, BLE_MESH_MODEL_OP_SENSOR_COLUMN_STATUS }, + { BLE_MESH_MODEL_OP_SENSOR_SERIES_GET, BLE_MESH_MODEL_OP_SENSOR_SERIES_STATUS }, }; static void timeout_handler(struct k_work *work) { - bt_mesh_sensor_client_t *client = NULL; - sensor_internal_data_t *internal = NULL; - bt_mesh_client_node_t *node = NULL; + sensor_internal_data_t *internal = NULL; + bt_mesh_sensor_client_t *client = NULL; + bt_mesh_client_node_t *node = NULL; BT_WARN("Receive sensor status message timeout"); node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work); if (!node || !node->ctx.model) { - BT_ERR("%s: node parameter is NULL", __func__); + BT_ERR("%s, Invalid parameter", __func__); return; } client = (bt_mesh_sensor_client_t *)node->ctx.model->user_data; if (!client) { - BT_ERR("%s: model user_data is NULL", __func__); + BT_ERR("%s, Sensor Client user_data is NULL", __func__); return; } internal = (sensor_internal_data_t *)client->internal_data; if (!internal) { - BT_ERR("%s: internal_data is NULL", __func__); + BT_ERR("%s, Sensor Client internal_data is NULL", __func__); return; } @@ -96,40 +95,40 @@ static void sensor_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { - bt_mesh_sensor_client_t *client = NULL; - sensor_internal_data_t *internal = NULL; - bt_mesh_client_node_t *node = NULL; + sensor_internal_data_t *internal = NULL; + bt_mesh_sensor_client_t *client = NULL; + bt_mesh_client_node_t *node = NULL; u8_t *val = NULL; u8_t evt = 0xFF; u32_t rsp = 0; size_t len = 0; - BT_DBG("%s: len %d, bytes %s", __func__, buf->len, bt_hex(buf->data, buf->len)); + BT_DBG("%s, len %d, bytes %s", __func__, buf->len, bt_hex(buf->data, buf->len)); client = (bt_mesh_sensor_client_t *)model->user_data; if (!client) { - BT_ERR("%s: model user_data is NULL", __func__); + BT_ERR("%s, Sensor Client user_data is NULL", __func__); return; } internal = (sensor_internal_data_t *)client->internal_data; if (!internal) { - BT_ERR("%s: model internal_data is NULL", __func__); + BT_ERR("%s, Sensor Client internal_data is NULL", __func__); return; } rsp = ctx->recv_op; switch (rsp) { - case BT_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS: { + case BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS: { struct bt_mesh_sensor_descriptor_status *status = NULL; status = osi_calloc(sizeof(struct bt_mesh_sensor_descriptor_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->descriptor = bt_mesh_alloc_buf(buf->len); if (!status->descriptor) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); osi_free(status); return; } @@ -139,17 +138,17 @@ static void sensor_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_sensor_descriptor_status); break; } - case BT_MESH_MODEL_OP_SENSOR_CADENCE_STATUS: { + case BLE_MESH_MODEL_OP_SENSOR_CADENCE_STATUS: { struct bt_mesh_sensor_cadence_status *status = NULL; status = osi_calloc(sizeof(struct bt_mesh_sensor_cadence_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate 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: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); osi_free(status); return; } @@ -159,17 +158,17 @@ static void sensor_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_sensor_cadence_status); break; } - case BT_MESH_MODEL_OP_SENSOR_SETTINGS_STATUS: { + case BLE_MESH_MODEL_OP_SENSOR_SETTINGS_STATUS: { struct bt_mesh_sensor_settings_status *status = NULL; status = osi_calloc(sizeof(struct bt_mesh_sensor_settings_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate 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: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); osi_free(status); return; } @@ -179,21 +178,21 @@ static void sensor_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_sensor_settings_status); break; } - case BT_MESH_MODEL_OP_SENSOR_SETTING_STATUS: { + case BLE_MESH_MODEL_OP_SENSOR_SETTING_STATUS: { struct bt_mesh_sensor_setting_status *status = NULL; status = osi_calloc(sizeof(struct bt_mesh_sensor_setting_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } - status->sensor_property_id = net_buf_simple_pull_le16(buf); + status->sensor_property_id = net_buf_simple_pull_le16(buf); status->sensor_setting_property_id = net_buf_simple_pull_le16(buf); if (buf->len) { - status->op_en = true; + status->op_en = true; 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: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); osi_free(status); return; } @@ -204,16 +203,16 @@ static void sensor_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_sensor_setting_status); break; } - case BT_MESH_MODEL_OP_SENSOR_STATUS: { + case BLE_MESH_MODEL_OP_SENSOR_STATUS: { struct bt_mesh_sensor_status *status = NULL; status = osi_calloc(sizeof(struct bt_mesh_sensor_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->marshalled_sensor_data = bt_mesh_alloc_buf(buf->len); if (!status->marshalled_sensor_data) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); osi_free(status); return; } @@ -223,17 +222,17 @@ static void sensor_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_sensor_status); break; } - case BT_MESH_MODEL_OP_SENSOR_COLUMN_STATUS: { + case BLE_MESH_MODEL_OP_SENSOR_COLUMN_STATUS: { struct bt_mesh_sensor_column_status *status = NULL; status = osi_calloc(sizeof(struct bt_mesh_sensor_column_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate 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: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); osi_free(status); return; } @@ -243,17 +242,17 @@ static void sensor_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_sensor_column_status); break; } - case BT_MESH_MODEL_OP_SENSOR_SERIES_STATUS: { + case BLE_MESH_MODEL_OP_SENSOR_SERIES_STATUS: { struct bt_mesh_sensor_series_status *status = NULL; status = osi_calloc(sizeof(struct bt_mesh_sensor_series_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate 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: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); osi_free(status); return; } @@ -264,7 +263,7 @@ static void sensor_status(struct bt_mesh_model *model, break; } default: - BT_ERR("Not a sensor status message opcode"); + BT_ERR("%s, Not a Sensor Status message opcode", __func__); return; } @@ -275,17 +274,17 @@ static void sensor_status(struct bt_mesh_model *model, BT_DBG("Unexpected sensor status message 0x%x", rsp); } else { switch (node->opcode) { - case BT_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET: - case BT_MESH_MODEL_OP_SENSOR_CADENCE_GET: - case BT_MESH_MODEL_OP_SENSOR_SETTINGS_GET: - case BT_MESH_MODEL_OP_SENSOR_SETTING_GET: - case BT_MESH_MODEL_OP_SENSOR_GET: - case BT_MESH_MODEL_OP_SENSOR_COLUMN_GET: - case BT_MESH_MODEL_OP_SENSOR_SERIES_GET: + case BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET: + case BLE_MESH_MODEL_OP_SENSOR_CADENCE_GET: + case BLE_MESH_MODEL_OP_SENSOR_SETTINGS_GET: + case BLE_MESH_MODEL_OP_SENSOR_SETTING_GET: + case BLE_MESH_MODEL_OP_SENSOR_GET: + case BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET: + case BLE_MESH_MODEL_OP_SENSOR_SERIES_GET: evt = 0x00; break; - case BT_MESH_MODEL_OP_SENSOR_CADENCE_SET: - case BT_MESH_MODEL_OP_SENSOR_SETTING_SET: + case BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET: + case BLE_MESH_MODEL_OP_SENSOR_SETTING_SET: evt = 0x01; break; default: @@ -298,43 +297,43 @@ static void sensor_status(struct bt_mesh_model *model, } switch (rsp) { - case BT_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS: { + case BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS: { struct bt_mesh_sensor_descriptor_status *status; status = (struct bt_mesh_sensor_descriptor_status *)val; bt_mesh_free_buf(status->descriptor); break; } - case BT_MESH_MODEL_OP_SENSOR_CADENCE_STATUS: { + case BLE_MESH_MODEL_OP_SENSOR_CADENCE_STATUS: { struct bt_mesh_sensor_cadence_status *status; status = (struct bt_mesh_sensor_cadence_status *)val; bt_mesh_free_buf(status->sensor_cadence_value); break; } - case BT_MESH_MODEL_OP_SENSOR_SETTINGS_STATUS: { + case BLE_MESH_MODEL_OP_SENSOR_SETTINGS_STATUS: { struct bt_mesh_sensor_settings_status *status; status = (struct bt_mesh_sensor_settings_status *)val; bt_mesh_free_buf(status->sensor_setting_property_ids); break; } - case BT_MESH_MODEL_OP_SENSOR_SETTING_STATUS: { + case BLE_MESH_MODEL_OP_SENSOR_SETTING_STATUS: { struct bt_mesh_sensor_setting_status *status; status = (struct bt_mesh_sensor_setting_status *)val; bt_mesh_free_buf(status->sensor_setting_raw); break; } - case BT_MESH_MODEL_OP_SENSOR_STATUS: { + case BLE_MESH_MODEL_OP_SENSOR_STATUS: { struct bt_mesh_sensor_status *status; status = (struct bt_mesh_sensor_status *)val; bt_mesh_free_buf(status->marshalled_sensor_data); break; } - case BT_MESH_MODEL_OP_SENSOR_COLUMN_STATUS: { + case BLE_MESH_MODEL_OP_SENSOR_COLUMN_STATUS: { struct bt_mesh_sensor_column_status *status; status = (struct bt_mesh_sensor_column_status *)val; bt_mesh_free_buf(status->sensor_column_value); break; } - case BT_MESH_MODEL_OP_SENSOR_SERIES_STATUS: { + case BLE_MESH_MODEL_OP_SENSOR_SERIES_STATUS: { struct bt_mesh_sensor_series_status *status; status = (struct bt_mesh_sensor_series_status *)val; bt_mesh_free_buf(status->sensor_series_value); @@ -350,14 +349,14 @@ static void sensor_status(struct bt_mesh_model *model, } const struct bt_mesh_model_op sensor_cli_op[] = { - { BT_MESH_MODEL_OP_SENSOR_DESCRIPTOR_STATUS, 0, sensor_status }, - { BT_MESH_MODEL_OP_SENSOR_CADENCE_STATUS, 2, sensor_status }, - { BT_MESH_MODEL_OP_SENSOR_SETTINGS_STATUS, 2, sensor_status }, - { BT_MESH_MODEL_OP_SENSOR_SETTING_STATUS, 4, sensor_status }, - { BT_MESH_MODEL_OP_SENSOR_STATUS, 0, sensor_status }, - { BT_MESH_MODEL_OP_SENSOR_COLUMN_STATUS, 2, sensor_status }, - { BT_MESH_MODEL_OP_SENSOR_SERIES_STATUS, 2, sensor_status }, - BT_MESH_MODEL_OP_END, + { 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 }, + { BLE_MESH_MODEL_OP_SENSOR_SETTING_STATUS, 4, sensor_status }, + { BLE_MESH_MODEL_OP_SENSOR_STATUS, 0, sensor_status }, + { BLE_MESH_MODEL_OP_SENSOR_COLUMN_STATUS, 2, sensor_status }, + { BLE_MESH_MODEL_OP_SENSOR_SERIES_STATUS, 2, sensor_status }, + BLE_MESH_MODEL_OP_END, }; static int sensor_act_state(struct bt_mesh_common_param *common, @@ -368,14 +367,14 @@ static int sensor_act_state(struct bt_mesh_common_param *common, msg = bt_mesh_alloc_buf(value_len); if (!msg) { - BT_ERR("Sensor allocate memory fail"); + BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; } bt_mesh_model_msg_init(msg, common->opcode); switch (common->opcode) { - case BT_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET: { + case BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET: { struct bt_mesh_sensor_descriptor_get *act; act = (struct bt_mesh_sensor_descriptor_get *)value; if (act->op_en) { @@ -383,14 +382,14 @@ static int sensor_act_state(struct bt_mesh_common_param *common, } break; } - case BT_MESH_MODEL_OP_SENSOR_CADENCE_GET: { + case BLE_MESH_MODEL_OP_SENSOR_CADENCE_GET: { struct bt_mesh_sensor_cadence_get *act; act = (struct bt_mesh_sensor_cadence_get *)value; net_buf_simple_add_le16(msg, act->property_id); break; } - case BT_MESH_MODEL_OP_SENSOR_CADENCE_SET: - case BT_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK: { + case BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET: + case BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK: { struct bt_mesh_sensor_cadence_set *act; act = (struct bt_mesh_sensor_cadence_set *)value; net_buf_simple_add_le16(msg, act->property_id); @@ -402,21 +401,21 @@ static int sensor_act_state(struct bt_mesh_common_param *common, net_buf_simple_add_mem(msg, act->fast_cadence_high->data, act->fast_cadence_high->len); break; } - case BT_MESH_MODEL_OP_SENSOR_SETTINGS_GET: { + case BLE_MESH_MODEL_OP_SENSOR_SETTINGS_GET: { struct bt_mesh_sensor_settings_get *act; act = (struct bt_mesh_sensor_settings_get *)value; net_buf_simple_add_le16(msg, act->sensor_property_id); break; } - case BT_MESH_MODEL_OP_SENSOR_SETTING_GET: { + case BLE_MESH_MODEL_OP_SENSOR_SETTING_GET: { struct bt_mesh_sensor_setting_get *act; act = (struct bt_mesh_sensor_setting_get *)value; net_buf_simple_add_le16(msg, act->sensor_property_id); net_buf_simple_add_le16(msg, act->sensor_setting_property_id); break; } - case BT_MESH_MODEL_OP_SENSOR_SETTING_SET: - case BT_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK: { + case BLE_MESH_MODEL_OP_SENSOR_SETTING_SET: + case BLE_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK: { struct bt_mesh_sensor_setting_set *act; act = (struct bt_mesh_sensor_setting_set *)value; net_buf_simple_add_le16(msg, act->sensor_property_id); @@ -424,7 +423,7 @@ static int sensor_act_state(struct bt_mesh_common_param *common, net_buf_simple_add_mem(msg, act->sensor_setting_raw->data, act->sensor_setting_raw->len); break; } - case BT_MESH_MODEL_OP_SENSOR_GET: { + case BLE_MESH_MODEL_OP_SENSOR_GET: { struct bt_mesh_sensor_get *act; act = (struct bt_mesh_sensor_get *)value; if (act->op_en) { @@ -432,14 +431,14 @@ static int sensor_act_state(struct bt_mesh_common_param *common, } break; } - case BT_MESH_MODEL_OP_SENSOR_COLUMN_GET: { + case BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET: { struct bt_mesh_sensor_column_get *act; act = (struct bt_mesh_sensor_column_get *)value; net_buf_simple_add_le16(msg, act->property_id); net_buf_simple_add_mem(msg, act->raw_value_x->data, act->raw_value_x->len); break; } - case BT_MESH_MODEL_OP_SENSOR_SERIES_GET: { + case BLE_MESH_MODEL_OP_SENSOR_SERIES_GET: { struct bt_mesh_sensor_series_get *act; act = (struct bt_mesh_sensor_series_get *)value; net_buf_simple_add_le16(msg, act->property_id); @@ -450,7 +449,7 @@ static int sensor_act_state(struct bt_mesh_common_param *common, break; } default: - BT_ERR("Not a sensor client model message opcode"); + BT_ERR("%s, Not a Sensor Client message opcode", __func__); err = -EINVAL; goto end; } @@ -459,7 +458,7 @@ static int sensor_act_state(struct bt_mesh_common_param *common, timeout_handler, common->msg_timeout, need_ack, common->cb, common->cb_data); if (err) { - BT_ERR("Sensor message send failed (err %d)", err); + BT_ERR("%s, Failed to send Sensor Client message (err %d)", __func__, err); } end: @@ -474,48 +473,48 @@ int bt_mesh_sensor_client_get_state(struct bt_mesh_common_param *common, void *g u16_t length = 0; if (!common || !common->model || !get) { - BT_ERR("%s: common parameter is NULL", __func__); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } client = (bt_mesh_sensor_client_t *)common->model->user_data; if (!client || !client->internal_data) { - BT_ERR("%s: client parameter is NULL", __func__); + BT_ERR("%s, Sensor Client user data is NULL", __func__); return -EINVAL; } switch (common->opcode) { - case BT_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET: - length = BT_MESH_SENSOR_DESCRIPTOR_GET_MSG_LEN; + case BLE_MESH_MODEL_OP_SENSOR_DESCRIPTOR_GET: + length = BLE_MESH_SENSOR_DESCRIPTOR_GET_MSG_LEN; break; - case BT_MESH_MODEL_OP_SENSOR_CADENCE_GET: - length = BT_MESH_SENSOR_CADENCE_GET_MSG_LEN; + case BLE_MESH_MODEL_OP_SENSOR_CADENCE_GET: + length = BLE_MESH_SENSOR_CADENCE_GET_MSG_LEN; break; - case BT_MESH_MODEL_OP_SENSOR_SETTINGS_GET: - length = BT_MESH_SENSOR_SETTINGS_GET_MSG_LEN; + case BLE_MESH_MODEL_OP_SENSOR_SETTINGS_GET: + length = BLE_MESH_SENSOR_SETTINGS_GET_MSG_LEN; break; - case BT_MESH_MODEL_OP_SENSOR_SETTING_GET: - length = BT_MESH_SENSOR_SETTING_GET_MSG_LEN; + case BLE_MESH_MODEL_OP_SENSOR_SETTING_GET: + length = BLE_MESH_SENSOR_SETTING_GET_MSG_LEN; break; - case BT_MESH_MODEL_OP_SENSOR_GET: - length = BT_MESH_SENSOR_GET_MSG_LEN; + case BLE_MESH_MODEL_OP_SENSOR_GET: + length = BLE_MESH_SENSOR_GET_MSG_LEN; break; - case BT_MESH_MODEL_OP_SENSOR_COLUMN_GET: { + case BLE_MESH_MODEL_OP_SENSOR_COLUMN_GET: { struct bt_mesh_sensor_column_get *value; value = (struct bt_mesh_sensor_column_get *)get; if (!value->raw_value_x) { - BT_ERR("Sensor column get is NULL"); + BT_ERR("%s, Sensor column_get is NULL", __func__); return -EINVAL; } length = (2 + 2 + value->raw_value_x->len + 4); break; } - case BT_MESH_MODEL_OP_SENSOR_SERIES_GET: { + case BLE_MESH_MODEL_OP_SENSOR_SERIES_GET: { struct bt_mesh_sensor_series_get *value; value = (struct bt_mesh_sensor_series_get *)get; if (value->op_en) { if (!value->raw_value_x1 || !value->raw_value_x2) { - BT_ERR("Sensor series get parameter is NULL"); + BT_ERR("%s, Sensor series_get is NULL", __func__); return -EINVAL; } } @@ -526,7 +525,7 @@ int bt_mesh_sensor_client_get_state(struct bt_mesh_common_param *common, void *g break; } default: - BT_ERR("Not a sensor get message opcode"); + BT_ERR("%s, Not a Sensor Client Get message opcode", __func__); return -EINVAL; } @@ -536,29 +535,29 @@ int bt_mesh_sensor_client_get_state(struct bt_mesh_common_param *common, void *g int bt_mesh_sensor_client_set_state(struct bt_mesh_common_param *common, void *set, void *status) { bt_mesh_sensor_client_t *client = NULL; - u16_t length = 0; - bool need_ack = false; + u16_t length = 0; + bool need_ack = false; if (!common || !common->model || !set) { - BT_ERR("%s: common parameter is NULL", __func__); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } client = (bt_mesh_sensor_client_t *)common->model->user_data; if (!client || !client->internal_data) { - BT_ERR("%s: client parameter is NULL", __func__); + BT_ERR("%s, Sensor Client user data is NULL", __func__); return -EINVAL; } switch (common->opcode) { - case BT_MESH_MODEL_OP_SENSOR_CADENCE_SET: + case BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET: need_ack = true; - case BT_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK: { + case BLE_MESH_MODEL_OP_SENSOR_CADENCE_SET_UNACK: { struct bt_mesh_sensor_cadence_set *value; 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("Sensor cadence set parameter is NULL"); + BT_ERR("%s, Sensor cadence_set is NULL", __func__); return -EINVAL; } length = value->status_trigger_delta_down->len + \ @@ -568,20 +567,20 @@ int bt_mesh_sensor_client_set_state(struct bt_mesh_common_param *common, void *s length += (1 + 2 + 1 + 1 + 4); break; } - case BT_MESH_MODEL_OP_SENSOR_SETTING_SET: + case BLE_MESH_MODEL_OP_SENSOR_SETTING_SET: need_ack = true; - case BT_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK: { + case BLE_MESH_MODEL_OP_SENSOR_SETTING_SET_UNACK: { struct bt_mesh_sensor_setting_set *value; value = (struct bt_mesh_sensor_setting_set *)set; if (!value->sensor_setting_raw) { - BT_ERR("Sensor_setting_raw is NULL"); + BT_ERR("%s, Sensor setting_raw is NULL", __func__); return -EINVAL; } length = (1 + 2 + 2 + value->sensor_setting_raw->len + 4); break; } default: - BT_ERR("Not a sensor set message opcode"); + BT_ERR("%s, Not a Sensor Client Set message opcode", __func__); return -EINVAL; } @@ -590,34 +589,34 @@ int bt_mesh_sensor_client_set_state(struct bt_mesh_common_param *common, void *s int bt_mesh_sensor_cli_init(struct bt_mesh_model *model, bool primary) { - bt_mesh_sensor_client_t *client = NULL; - sensor_internal_data_t *internal = NULL; + sensor_internal_data_t *internal = NULL; + bt_mesh_sensor_client_t *client = NULL; BT_DBG("primary %u", primary); if (!model) { - BT_ERR("Sensor client model is NULL"); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } client = (bt_mesh_sensor_client_t *)model->user_data; if (!client) { - BT_ERR("Sensor client model user_data is NULL"); + BT_ERR("%s, Sensor Client user_data is NULL", __func__); return -EINVAL; } /* TODO: call osi_free() when deinit function is invoked*/ internal = osi_calloc(sizeof(sensor_internal_data_t)); if (!internal) { - BT_ERR("Allocate memory for sensor internal data fail"); + BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; } sys_slist_init(&internal->queue); - client->model = model; - client->op_pair_size = ARRAY_SIZE(sensor_op_pair); - client->op_pair = sensor_op_pair; + client->model = model; + client->op_pair_size = ARRAY_SIZE(sensor_op_pair); + client->op_pair = sensor_op_pair; client->internal_data = internal; return 0; diff --git a/components/bt/ble_mesh/mesh_models/time_scene_client.c b/components/bt/ble_mesh/mesh_models/time_scene_client.c index 29c7fbea92..b04619987a 100644 --- a/components/bt/ble_mesh/mesh_models/time_scene_client.c +++ b/components/bt/ble_mesh/mesh_models/time_scene_client.c @@ -17,86 +17,85 @@ #include #include "osi/allocator.h" +#include "sdkconfig.h" #include "mesh_types.h" #include "mesh_kernel.h" #include "mesh_trace.h" -#include "mesh.h" -#include "model_op.h" -#include "common.h" +#include "mesh.h" +#include "model_opcode.h" +#include "mesh_common.h" #include "time_scene_client.h" -#include "sdkconfig.h" - -#include "btc_ble_mesh_time_scene_client.h" +#include "btc_ble_mesh_time_scene_model.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 */ /* Time client messages length */ -#define BT_MESH_TIME_SET_MSG_LEN (1 + 10 + 4) -#define BT_MESH_TIME_ZONE_SET_MSG_LEN (2 + 6 + 4) -#define BT_MESH_TAI_UTC_DELTA_SET_MSG_LEN (2 + 7 + 4) -#define BT_MESH_TIME_ROLE_SET_MSG_LEN (2 + 1 + 4) +#define BLE_MESH_TIME_SET_MSG_LEN (1 + 10 + 4) +#define BLE_MESH_TIME_ZONE_SET_MSG_LEN (2 + 6 + 4) +#define BLE_MESH_TAI_UTC_DELTA_SET_MSG_LEN (2 + 7 + 4) +#define BLE_MESH_TIME_ROLE_SET_MSG_LEN (2 + 1 + 4) /* Scene client messages length */ -#define BT_MESH_SCENE_STORE_MSG_LEN (2 + 2 + 4) -#define BT_MESH_SCENE_RECALL_MSG_LEN (2 + 5 + 4) -#define BT_MESH_SCENE_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_SCENE_REGISTER_GET_MSG_LEN (2 + 0 + 4) -#define BT_MESH_SCENE_DELETE_MSG_LEN (2 + 2 + 4) +#define BLE_MESH_SCENE_STORE_MSG_LEN (2 + 2 + 4) +#define BLE_MESH_SCENE_RECALL_MSG_LEN (2 + 5 + 4) +#define BLE_MESH_SCENE_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_SCENE_REGISTER_GET_MSG_LEN (2 + 0 + 4) +#define BLE_MESH_SCENE_DELETE_MSG_LEN (2 + 2 + 4) /* Scheduler client messages length */ -#define BT_MESH_SCHEDULER_ACT_GET_MSG_LEN (2 + 1 + 4) -#define BT_MESH_SCHEDULER_ACT_SET_MSG_LEN (1 + 10 + 4) +#define BLE_MESH_SCHEDULER_ACT_GET_MSG_LEN (2 + 1 + 4) +#define BLE_MESH_SCHEDULER_ACT_SET_MSG_LEN (1 + 10 + 4) -#define BT_MESH_SCENE_GET_STATE_MSG_LEN (2 + 1 + 4) -#define BT_MESH_SCENE_ACT_STATE_MSG_LEN (2 + 2 + 4) +#define BLE_MESH_SCENE_GET_STATE_MSG_LEN (2 + 1 + 4) +#define BLE_MESH_SCENE_ACT_STATE_MSG_LEN (2 + 2 + 4) static const bt_mesh_client_op_pair_t time_scene_op_pair[] = { - { BT_MESH_MODEL_OP_TIME_GET, BT_MESH_MODEL_OP_TIME_STATUS }, - { BT_MESH_MODEL_OP_TIME_SET, BT_MESH_MODEL_OP_TIME_STATUS }, - { BT_MESH_MODEL_OP_TIME_ZONE_GET, BT_MESH_MODEL_OP_TIME_ZONE_STATUS }, - { BT_MESH_MODEL_OP_TIME_ZONE_SET, BT_MESH_MODEL_OP_TIME_ZONE_STATUS }, - { BT_MESH_MODEL_OP_TAI_UTC_DELTA_GET, BT_MESH_MODEL_OP_TAI_UTC_DELTA_STATUS }, - { BT_MESH_MODEL_OP_TAI_UTC_DELTA_SET, BT_MESH_MODEL_OP_TAI_UTC_DELTA_STATUS }, - { BT_MESH_MODEL_OP_TIME_ROLE_GET, BT_MESH_MODEL_OP_TIME_ROLE_STATUS }, - { BT_MESH_MODEL_OP_TIME_ROLE_SET, BT_MESH_MODEL_OP_TIME_ROLE_STATUS }, - { BT_MESH_MODEL_OP_SCENE_STORE, BT_MESH_MODEL_OP_SCENE_REGISTER_STATUS }, - { BT_MESH_MODEL_OP_SCENE_RECALL, BT_MESH_MODEL_OP_SCENE_STATUS }, - { BT_MESH_MODEL_OP_SCENE_GET, BT_MESH_MODEL_OP_SCENE_STATUS }, - { BT_MESH_MODEL_OP_SCENE_REGISTER_GET, BT_MESH_MODEL_OP_SCENE_REGISTER_STATUS }, - { BT_MESH_MODEL_OP_SCENE_DELETE, BT_MESH_MODEL_OP_SCENE_REGISTER_STATUS }, - { BT_MESH_MODEL_OP_SCHEDULER_GET, BT_MESH_MODEL_OP_SCHEDULER_STATUS }, - { BT_MESH_MODEL_OP_SCHEDULER_ACT_GET, BT_MESH_MODEL_OP_SCHEDULER_ACT_STATUS }, - { BT_MESH_MODEL_OP_SCHEDULER_ACT_SET, BT_MESH_MODEL_OP_SCHEDULER_ACT_STATUS }, + { BLE_MESH_MODEL_OP_TIME_GET, BLE_MESH_MODEL_OP_TIME_STATUS }, + { BLE_MESH_MODEL_OP_TIME_SET, BLE_MESH_MODEL_OP_TIME_STATUS }, + { BLE_MESH_MODEL_OP_TIME_ZONE_GET, BLE_MESH_MODEL_OP_TIME_ZONE_STATUS }, + { BLE_MESH_MODEL_OP_TIME_ZONE_SET, BLE_MESH_MODEL_OP_TIME_ZONE_STATUS }, + { BLE_MESH_MODEL_OP_TAI_UTC_DELTA_GET, BLE_MESH_MODEL_OP_TAI_UTC_DELTA_STATUS }, + { BLE_MESH_MODEL_OP_TAI_UTC_DELTA_SET, BLE_MESH_MODEL_OP_TAI_UTC_DELTA_STATUS }, + { BLE_MESH_MODEL_OP_TIME_ROLE_GET, BLE_MESH_MODEL_OP_TIME_ROLE_STATUS }, + { BLE_MESH_MODEL_OP_TIME_ROLE_SET, BLE_MESH_MODEL_OP_TIME_ROLE_STATUS }, + { BLE_MESH_MODEL_OP_SCENE_STORE, BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS }, + { BLE_MESH_MODEL_OP_SCENE_RECALL, BLE_MESH_MODEL_OP_SCENE_STATUS }, + { BLE_MESH_MODEL_OP_SCENE_GET, BLE_MESH_MODEL_OP_SCENE_STATUS }, + { BLE_MESH_MODEL_OP_SCENE_REGISTER_GET, BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS }, + { BLE_MESH_MODEL_OP_SCENE_DELETE, BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS }, + { BLE_MESH_MODEL_OP_SCHEDULER_GET, BLE_MESH_MODEL_OP_SCHEDULER_STATUS }, + { BLE_MESH_MODEL_OP_SCHEDULER_ACT_GET, BLE_MESH_MODEL_OP_SCHEDULER_ACT_STATUS }, + { BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET, BLE_MESH_MODEL_OP_SCHEDULER_ACT_STATUS }, }; static void timeout_handler(struct k_work *work) { - bt_mesh_time_scene_client_t *client = NULL; - time_scene_internal_data_t *internal = NULL; - bt_mesh_client_node_t *node = NULL; + time_scene_internal_data_t *internal = NULL; + bt_mesh_time_scene_client_t *client = NULL; + bt_mesh_client_node_t *node = NULL; BT_WARN("Receive time scene status message timeout"); node = CONTAINER_OF(work, bt_mesh_client_node_t, timer.work); if (!node || !node->ctx.model) { - BT_ERR("%s: node parameter is NULL", __func__); + BT_ERR("%s, Invalid parameter", __func__); return; } client = (bt_mesh_time_scene_client_t *)node->ctx.model->user_data; if (!client) { - BT_ERR("%s: model user_data is NULL", __func__); + BT_ERR("%s, Time Scene Client user_data is NULL", __func__); return; } internal = (time_scene_internal_data_t *)client->internal_data; if (!internal) { - BT_ERR("%s: internal_data is NULL", __func__); + BT_ERR("%s, Time Scene Client internal_data is NULL", __func__); return; } @@ -112,39 +111,39 @@ static void time_scene_status(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx, struct net_buf_simple *buf) { - bt_mesh_time_scene_client_t *client = NULL; - time_scene_internal_data_t *internal = NULL; - bt_mesh_client_node_t *node = NULL; + time_scene_internal_data_t *internal = NULL; + bt_mesh_time_scene_client_t *client = NULL; + bt_mesh_client_node_t *node = NULL; u8_t *val = NULL; u8_t evt = 0xFF; u32_t rsp = 0; size_t len = 0; - BT_DBG("%s: len %d, bytes %s", __func__, buf->len, bt_hex(buf->data, buf->len)); + BT_DBG("%s, len %d, bytes %s", __func__, buf->len, bt_hex(buf->data, buf->len)); client = (bt_mesh_time_scene_client_t *)model->user_data; if (!client) { - BT_ERR("%s: model user_data is NULL", __func__); + BT_ERR("%s, Time Scene Client user_data is NULL", __func__); return; } internal = (time_scene_internal_data_t *)client->internal_data; if (!internal) { - BT_ERR("%s: model internal_data is NULL", __func__); + BT_ERR("%s, Time Scene Client internal_data is NULL", __func__); return; } rsp = ctx->recv_op; switch (rsp) { - case BT_MESH_MODEL_OP_TIME_STATUS: { + case BLE_MESH_MODEL_OP_TIME_STATUS: { struct bt_mesh_time_status *status = NULL; if (buf->len != 5 && buf->len != 10) { - BT_ERR("Wrong Time status length %d", buf->len); + BT_ERR("%s, Invalid Time Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_time_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } memcpy(status->tai_seconds, buf->data, 5); @@ -159,15 +158,15 @@ static void time_scene_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_time_status); break; } - case BT_MESH_MODEL_OP_TIME_ZONE_STATUS: { + case BLE_MESH_MODEL_OP_TIME_ZONE_STATUS: { struct bt_mesh_time_zone_status *status = NULL; if (buf->len != 7) { - BT_ERR("Wrong Time zone status length %d", buf->len); + BT_ERR("%s, Invalid Time Zone Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_time_zone_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->time_zone_offset_curr = net_buf_simple_pull_u8(buf); @@ -178,15 +177,15 @@ static void time_scene_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_time_zone_status); break; } - case BT_MESH_MODEL_OP_TAI_UTC_DELTA_STATUS: { + case BLE_MESH_MODEL_OP_TAI_UTC_DELTA_STATUS: { struct bt_mesh_tai_utc_delta_status *status = NULL; if (buf->len != 9) { - BT_ERR("Wrong TAI UTC delta status length %d", buf->len); + BT_ERR("%s, Invalid TAI UTC Delta Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_tai_utc_delta_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } u16_t temp = net_buf_simple_pull_le16(buf); @@ -201,15 +200,15 @@ static void time_scene_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_tai_utc_delta_status); break; } - case BT_MESH_MODEL_OP_TIME_ROLE_STATUS: { + case BLE_MESH_MODEL_OP_TIME_ROLE_STATUS: { struct bt_mesh_time_role_status *status = NULL; if (buf->len != 1) { - BT_ERR("Wrong Time role status length %d", buf->len); + BT_ERR("%s, Invalid Time Role Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_time_role_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->time_role = net_buf_simple_pull_u8(buf); @@ -217,40 +216,40 @@ static void time_scene_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_time_role_status); break; } - case BT_MESH_MODEL_OP_SCENE_STATUS: { + case BLE_MESH_MODEL_OP_SCENE_STATUS: { struct bt_mesh_scene_status *status = NULL; if (buf->len != 3 && buf->len != 6) { - BT_ERR("Wrong Scene status length %d", buf->len); + BT_ERR("%s, Invalid Scene Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_scene_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } - status->status_code = net_buf_simple_pull_u8(buf); + status->status_code = net_buf_simple_pull_u8(buf); status->current_scene = net_buf_simple_pull_le16(buf); if (buf->len) { - status->op_en = true; + status->op_en = true; status->target_scene = net_buf_simple_pull_le16(buf); - status->remain_time = net_buf_simple_pull_u8(buf); + status->remain_time = net_buf_simple_pull_u8(buf); } val = (u8_t *)status; len = sizeof(struct bt_mesh_scene_status); break; } - case BT_MESH_MODEL_OP_SCENE_REGISTER_STATUS: { + case BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS: { struct bt_mesh_scene_register_status *status = NULL; status = osi_calloc(sizeof(struct bt_mesh_scene_register_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } - status->status_code = net_buf_simple_pull_u8(buf); + 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: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); osi_free(status); return; } @@ -260,15 +259,15 @@ static void time_scene_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_scene_register_status); break; } - case BT_MESH_MODEL_OP_SCHEDULER_STATUS: { + case BLE_MESH_MODEL_OP_SCHEDULER_STATUS: { struct bt_mesh_scheduler_status *status = NULL; if (buf->len != 2) { - BT_ERR("Wrong Scheduler status length %d", buf->len); + BT_ERR("%s, Invalid Scheduler Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_scheduler_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } status->schedules = net_buf_simple_pull_le16(buf); @@ -276,15 +275,15 @@ static void time_scene_status(struct bt_mesh_model *model, len = sizeof(struct bt_mesh_scheduler_status); break; } - case BT_MESH_MODEL_OP_SCHEDULER_ACT_STATUS: { + case BLE_MESH_MODEL_OP_SCHEDULER_ACT_STATUS: { struct bt_mesh_scheduler_act_status *status = NULL; if (buf->len != 10) { - BT_ERR("Wrong Scheduler action status length %d", buf->len); + BT_ERR("%s, Invalid Scheduler Action Status length %d", __func__, buf->len); return; } status = osi_calloc(sizeof(struct bt_mesh_scheduler_act_status)); if (!status) { - BT_ERR("%s: allocate memory fail", __func__); + BT_ERR("%s, Failed to allocate memory", __func__); return; } memcpy(status, buf->data, offsetof(struct bt_mesh_scheduler_act_status, scene_number)); @@ -295,35 +294,35 @@ static void time_scene_status(struct bt_mesh_model *model, break; } default: - BT_ERR("Not a time scene status message opcode"); + BT_ERR("%s, Not a Time Scene Status message opcode", __func__); return; } buf->data = val; - buf->len = len; + buf->len = len; node = bt_mesh_is_model_message_publish(model, ctx, buf, true); if (!node) { BT_DBG("Unexpected time scene status message 0x%x", rsp); } else { switch (node->opcode) { - case BT_MESH_MODEL_OP_TIME_GET: - case BT_MESH_MODEL_OP_TIME_ZONE_GET: - case BT_MESH_MODEL_OP_TAI_UTC_DELTA_GET: - case BT_MESH_MODEL_OP_TIME_ROLE_GET: - case BT_MESH_MODEL_OP_SCENE_GET: - case BT_MESH_MODEL_OP_SCENE_REGISTER_GET: - case BT_MESH_MODEL_OP_SCHEDULER_GET: - case BT_MESH_MODEL_OP_SCHEDULER_ACT_GET: + case BLE_MESH_MODEL_OP_TIME_GET: + case BLE_MESH_MODEL_OP_TIME_ZONE_GET: + case BLE_MESH_MODEL_OP_TAI_UTC_DELTA_GET: + case BLE_MESH_MODEL_OP_TIME_ROLE_GET: + case BLE_MESH_MODEL_OP_SCENE_GET: + case BLE_MESH_MODEL_OP_SCENE_REGISTER_GET: + case BLE_MESH_MODEL_OP_SCHEDULER_GET: + case BLE_MESH_MODEL_OP_SCHEDULER_ACT_GET: evt = 0x00; break; - case BT_MESH_MODEL_OP_TIME_SET: - case BT_MESH_MODEL_OP_TIME_ZONE_SET: - case BT_MESH_MODEL_OP_TAI_UTC_DELTA_SET: - case BT_MESH_MODEL_OP_TIME_ROLE_SET: - case BT_MESH_MODEL_OP_SCENE_STORE: - case BT_MESH_MODEL_OP_SCENE_RECALL: - case BT_MESH_MODEL_OP_SCENE_DELETE: - case BT_MESH_MODEL_OP_SCHEDULER_ACT_SET: + case BLE_MESH_MODEL_OP_TIME_SET: + case BLE_MESH_MODEL_OP_TIME_ZONE_SET: + case BLE_MESH_MODEL_OP_TAI_UTC_DELTA_SET: + case BLE_MESH_MODEL_OP_TIME_ROLE_SET: + case BLE_MESH_MODEL_OP_SCENE_STORE: + case BLE_MESH_MODEL_OP_SCENE_RECALL: + case BLE_MESH_MODEL_OP_SCENE_DELETE: + case BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET: evt = 0x01; break; default: @@ -336,7 +335,7 @@ static void time_scene_status(struct bt_mesh_model *model, } switch (rsp) { - case BT_MESH_MODEL_OP_SCENE_REGISTER_STATUS: { + case BLE_MESH_MODEL_OP_SCENE_REGISTER_STATUS: { struct bt_mesh_scene_register_status *status; status = (struct bt_mesh_scene_register_status *)val; bt_mesh_free_buf(status->scenes); @@ -352,35 +351,35 @@ static void time_scene_status(struct bt_mesh_model *model, } const struct bt_mesh_model_op time_cli_op[] = { - { BT_MESH_MODEL_OP_TIME_STATUS, 5, time_scene_status }, - { BT_MESH_MODEL_OP_TIME_ZONE_STATUS, 7, time_scene_status }, - { BT_MESH_MODEL_OP_TAI_UTC_DELTA_STATUS, 9, time_scene_status }, - { BT_MESH_MODEL_OP_TIME_ROLE_STATUS, 1, time_scene_status }, - BT_MESH_MODEL_OP_END, + { 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 }, + { BLE_MESH_MODEL_OP_TIME_ROLE_STATUS, 1, time_scene_status }, + BLE_MESH_MODEL_OP_END, }; const struct bt_mesh_model_op scene_cli_op[] = { - { BT_MESH_MODEL_OP_SCENE_STATUS, 3, time_scene_status }, - { BT_MESH_MODEL_OP_SCENE_REGISTER_STATUS, 3, time_scene_status }, - BT_MESH_MODEL_OP_END, + { 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[] = { - { BT_MESH_MODEL_OP_SCHEDULER_STATUS, 2, time_scene_status }, - { BT_MESH_MODEL_OP_SCHEDULER_ACT_STATUS, 10, time_scene_status }, - BT_MESH_MODEL_OP_END, + { 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, }; static int time_scene_get_state(struct bt_mesh_common_param *common, void *value) { - struct net_buf_simple *msg = NET_BUF_SIMPLE(BT_MESH_SCENE_GET_STATE_MSG_LEN); + struct net_buf_simple *msg = NET_BUF_SIMPLE(BLE_MESH_SCENE_GET_STATE_MSG_LEN); int err; bt_mesh_model_msg_init(msg, common->opcode); if (value) { switch (common->opcode) { - case BT_MESH_MODEL_OP_SCHEDULER_ACT_GET: { + case BLE_MESH_MODEL_OP_SCHEDULER_ACT_GET: { struct bt_mesh_scheduler_act_get *get; get = (struct bt_mesh_scheduler_act_get *)value; net_buf_simple_add_u8(msg, get->index); @@ -396,7 +395,7 @@ static int time_scene_get_state(struct bt_mesh_common_param *common, void *value timeout_handler, common->msg_timeout, true, common->cb, common->cb_data); if (err) { - BT_ERR("Time scene get message send failed (err %d)", err); + BT_ERR("%s, Failed to send Time Scene Get message (err %d)", __func__, err); } return err; @@ -410,14 +409,14 @@ static int time_scene_set_state(struct bt_mesh_common_param *common, msg = bt_mesh_alloc_buf(value_len); if (!msg) { - BT_ERR("Time scene allocate memory fail"); + BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; } bt_mesh_model_msg_init(msg, common->opcode); switch (common->opcode) { - case BT_MESH_MODEL_OP_TIME_SET: { + case BLE_MESH_MODEL_OP_TIME_SET: { struct bt_mesh_time_set *set; set = (struct bt_mesh_time_set *)value; net_buf_simple_add_mem(msg, set->tai_seconds, 5); @@ -427,35 +426,35 @@ static int time_scene_set_state(struct bt_mesh_common_param *common, net_buf_simple_add_u8(msg, set->time_zone_offset); break; } - case BT_MESH_MODEL_OP_TIME_ZONE_SET: { + case BLE_MESH_MODEL_OP_TIME_ZONE_SET: { struct bt_mesh_time_zone_set *set; set = (struct bt_mesh_time_zone_set *)value; net_buf_simple_add_u8(msg, set->time_zone_offset_new); net_buf_simple_add_mem(msg, set->tai_zone_change, 5); break; } - case BT_MESH_MODEL_OP_TAI_UTC_DELTA_SET: { + case BLE_MESH_MODEL_OP_TAI_UTC_DELTA_SET: { struct bt_mesh_tai_utc_delta_set *set; set = (struct bt_mesh_tai_utc_delta_set *)value; net_buf_simple_add_le16(msg, set->padding << 15 | set->tai_utc_delta_new); net_buf_simple_add_mem(msg, set->tai_delta_change, 5); break; } - case BT_MESH_MODEL_OP_TIME_ROLE_SET: { + case BLE_MESH_MODEL_OP_TIME_ROLE_SET: { struct bt_mesh_time_role_set *set; set = (struct bt_mesh_time_role_set *)value; net_buf_simple_add_u8(msg, set->time_role); break; } - case BT_MESH_MODEL_OP_SCENE_STORE: - case BT_MESH_MODEL_OP_SCENE_STORE_UNACK: { + case BLE_MESH_MODEL_OP_SCENE_STORE: + case BLE_MESH_MODEL_OP_SCENE_STORE_UNACK: { struct bt_mesh_scene_store *set; set = (struct bt_mesh_scene_store *)value; net_buf_simple_add_le16(msg, set->scene_number); break; } - case BT_MESH_MODEL_OP_SCENE_RECALL: - case BT_MESH_MODEL_OP_SCENE_RECALL_UNACK: { + case BLE_MESH_MODEL_OP_SCENE_RECALL: + case BLE_MESH_MODEL_OP_SCENE_RECALL_UNACK: { struct bt_mesh_scene_recall *set; set = (struct bt_mesh_scene_recall *)value; net_buf_simple_add_le16(msg, set->scene_number); @@ -466,15 +465,15 @@ static int time_scene_set_state(struct bt_mesh_common_param *common, } break; } - case BT_MESH_MODEL_OP_SCENE_DELETE: - case BT_MESH_MODEL_OP_SCENE_DELETE_UNACK: { + case BLE_MESH_MODEL_OP_SCENE_DELETE: + case BLE_MESH_MODEL_OP_SCENE_DELETE_UNACK: { struct bt_mesh_scene_delete *set; set = (struct bt_mesh_scene_delete *)value; net_buf_simple_add_le16(msg, set->scene_number); break; } - case BT_MESH_MODEL_OP_SCHEDULER_ACT_SET: - case BT_MESH_MODEL_OP_SCHEDULER_ACT_SET_UNACK: { + case BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET: + case BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET_UNACK: { struct bt_mesh_scheduler_act_set *set; set = (struct bt_mesh_scheduler_act_set *)value; net_buf_simple_add_mem(msg, set, offsetof(struct bt_mesh_scheduler_act_set, scene_number)); @@ -482,7 +481,7 @@ static int time_scene_set_state(struct bt_mesh_common_param *common, break; } default: - BT_ERR("Not a generic client model set message opcode"); + BT_ERR("%s, Not a Time Scene Client set message opcode", __func__); err = -EINVAL; goto end; } @@ -491,7 +490,7 @@ static int time_scene_set_state(struct bt_mesh_common_param *common, timeout_handler, common->msg_timeout, need_ack, common->cb, common->cb_data); if (err) { - BT_ERR("Time scene set message send failed (err %d)", err); + BT_ERR("%s, Failed to send Time Scene Set message (err %d)", __func__, err); } end: @@ -504,33 +503,33 @@ int bt_mesh_time_scene_client_get_state(struct bt_mesh_common_param *common, voi bt_mesh_time_scene_client_t *client = NULL; if (!common || !common->model) { - BT_ERR("%s: common parameter is NULL", __func__); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } client = (bt_mesh_time_scene_client_t *)common->model->user_data; if (!client || !client->internal_data) { - BT_ERR("%s: client parameter is NULL", __func__); + BT_ERR("%s, Time Scene Client user data is NULL", __func__); return -EINVAL; } switch (common->opcode) { - case BT_MESH_MODEL_OP_TIME_GET: - case BT_MESH_MODEL_OP_TIME_ZONE_GET: - case BT_MESH_MODEL_OP_TAI_UTC_DELTA_GET: - case BT_MESH_MODEL_OP_TIME_ROLE_GET: - case BT_MESH_MODEL_OP_SCENE_GET: - case BT_MESH_MODEL_OP_SCENE_REGISTER_GET: - case BT_MESH_MODEL_OP_SCHEDULER_GET: + case BLE_MESH_MODEL_OP_TIME_GET: + case BLE_MESH_MODEL_OP_TIME_ZONE_GET: + case BLE_MESH_MODEL_OP_TAI_UTC_DELTA_GET: + case BLE_MESH_MODEL_OP_TIME_ROLE_GET: + case BLE_MESH_MODEL_OP_SCENE_GET: + case BLE_MESH_MODEL_OP_SCENE_REGISTER_GET: + case BLE_MESH_MODEL_OP_SCHEDULER_GET: break; - case BT_MESH_MODEL_OP_SCHEDULER_ACT_GET: + case BLE_MESH_MODEL_OP_SCHEDULER_ACT_GET: if (!get) { - BT_ERR("Scheduler action index is NULL"); + BT_ERR("%s, Scheduler action index is NULL", __func__); return -EINVAL; } break; default: - BT_ERR("Not a time scene get message opcode"); + BT_ERR("%s, Not a Time Scene Client Get message opcode", __func__); return -EINVAL; } @@ -540,105 +539,105 @@ int bt_mesh_time_scene_client_get_state(struct bt_mesh_common_param *common, voi int bt_mesh_time_scene_client_set_state(struct bt_mesh_common_param *common, void *set, void *status) { bt_mesh_time_scene_client_t *client = NULL; - u16_t length = 0; - bool need_ack = false; + u16_t length = 0; + bool need_ack = false; if (!common || !common->model || !set) { - BT_ERR("%s: common parameter is NULL", __func__); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } client = (bt_mesh_time_scene_client_t *)common->model->user_data; if (!client || !client->internal_data) { - BT_ERR("%s: client parameter is NULL", __func__); + BT_ERR("%s, Time Scene Client user data is NULL", __func__); return -EINVAL; } switch (common->opcode) { - case BT_MESH_MODEL_OP_TIME_SET: + case BLE_MESH_MODEL_OP_TIME_SET: need_ack = true; - length = BT_MESH_TIME_SET_MSG_LEN; + length = BLE_MESH_TIME_SET_MSG_LEN; break; - case BT_MESH_MODEL_OP_TIME_ZONE_SET: + case BLE_MESH_MODEL_OP_TIME_ZONE_SET: need_ack = true; - length = BT_MESH_TIME_ZONE_SET_MSG_LEN; + length = BLE_MESH_TIME_ZONE_SET_MSG_LEN; break; - case BT_MESH_MODEL_OP_TAI_UTC_DELTA_SET: { + case BLE_MESH_MODEL_OP_TAI_UTC_DELTA_SET: { struct bt_mesh_tai_utc_delta_set *value; value = (struct bt_mesh_tai_utc_delta_set *)set; if (value->padding) { - BT_ERR("Non-zero padding value is prohibited"); + BT_ERR("%s, Non-zero padding value is prohibited", __func__); return -EINVAL; } need_ack = true; - length = BT_MESH_TAI_UTC_DELTA_SET_MSG_LEN; + length = BLE_MESH_TAI_UTC_DELTA_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_TIME_ROLE_SET: { + case BLE_MESH_MODEL_OP_TIME_ROLE_SET: { struct bt_mesh_time_role_set *value; value = (struct bt_mesh_time_role_set *)set; if (value->time_role > 0x03) { - BT_ERR("Time role value is prohibited"); + BT_ERR("%s, Time role value is prohibited", __func__); return -EINVAL; } need_ack = true; - length = BT_MESH_TIME_ROLE_SET_MSG_LEN; + length = BLE_MESH_TIME_ROLE_SET_MSG_LEN; break; } - case BT_MESH_MODEL_OP_SCENE_STORE: + case BLE_MESH_MODEL_OP_SCENE_STORE: need_ack = true; - case BT_MESH_MODEL_OP_SCENE_STORE_UNACK: { + case BLE_MESH_MODEL_OP_SCENE_STORE_UNACK: { struct bt_mesh_scene_store *value; value = (struct bt_mesh_scene_store *)set; if (!value->scene_number) { - BT_ERR("Scene store scene_number 0x0000 is prohibited"); + BT_ERR("%s, Scene store scene_number 0x0000 is prohibited", __func__); return -EINVAL; } - length = BT_MESH_SCENE_STORE_MSG_LEN; + length = BLE_MESH_SCENE_STORE_MSG_LEN; break; } - case BT_MESH_MODEL_OP_SCENE_RECALL: + case BLE_MESH_MODEL_OP_SCENE_RECALL: need_ack = true; - case BT_MESH_MODEL_OP_SCENE_RECALL_UNACK: { + case BLE_MESH_MODEL_OP_SCENE_RECALL_UNACK: { struct bt_mesh_scene_recall *value; value = (struct bt_mesh_scene_recall *)set; if (!value->scene_number) { - BT_ERR("Scene recall scene_number 0x0000 is prohibited"); + BT_ERR("%s, Scene recall scene_number 0x0000 is prohibited", __func__); return -EINVAL; } if (value->op_en) { if ((value->trans_time & 0x3F) > 0x3E) { - BT_ERR("Scene recall transition time is bigger than 0x3E"); + BT_ERR("%s, Invalid Scene Recall transition time", __func__); return -EINVAL; } } - length = BT_MESH_SCENE_RECALL_MSG_LEN; + length = BLE_MESH_SCENE_RECALL_MSG_LEN; break; } - case BT_MESH_MODEL_OP_SCENE_DELETE: + case BLE_MESH_MODEL_OP_SCENE_DELETE: need_ack = true; - case BT_MESH_MODEL_OP_SCENE_DELETE_UNACK: { - length = BT_MESH_SCENE_DELETE_MSG_LEN; + case BLE_MESH_MODEL_OP_SCENE_DELETE_UNACK: { + length = BLE_MESH_SCENE_DELETE_MSG_LEN; break; } - case BT_MESH_MODEL_OP_SCHEDULER_ACT_SET: + case BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET: need_ack = true; - case BT_MESH_MODEL_OP_SCHEDULER_ACT_SET_UNACK: { + case BLE_MESH_MODEL_OP_SCHEDULER_ACT_SET_UNACK: { struct bt_mesh_scheduler_act_set *value; value = (struct bt_mesh_scheduler_act_set *)set; if (value->year > 0x64) { - BT_ERR("Scheduler register year value is prohibited"); + BT_ERR("%s, Scheduler register year value is prohibited", __func__); return -EINVAL; } if (value->hour > 0x19) { - BT_ERR("Scheduler register hour value is prohibited"); + BT_ERR("%s, Scheduler register hour value is prohibited", __func__); return -EINVAL; } - length = BT_MESH_SCHEDULER_ACT_SET_MSG_LEN; + length = BLE_MESH_SCHEDULER_ACT_SET_MSG_LEN; break; } default: - BT_ERR("Not a time scene set message opcode"); + BT_ERR("%s, Not a Time Scene Set message opcode", __func__); return -EINVAL; } @@ -647,34 +646,34 @@ int bt_mesh_time_scene_client_set_state(struct bt_mesh_common_param *common, voi static int time_scene_client_init(struct bt_mesh_model *model, bool primary) { - bt_mesh_time_scene_client_t *client = NULL; - time_scene_internal_data_t *internal = NULL; + time_scene_internal_data_t *internal = NULL; + bt_mesh_time_scene_client_t *client = NULL; BT_DBG("primary %u", primary); if (!model) { - BT_ERR("Time scene client model is NULL"); + BT_ERR("%s, Invalid parameter", __func__); return -EINVAL; } client = (bt_mesh_time_scene_client_t *)model->user_data; if (!client) { - BT_ERR("Time scene client model user_data is NULL"); + BT_ERR("%s, Time Scene Client user_data is NULL", __func__); return -EINVAL; } /* TODO: call osi_free() when deinit function is invoked*/ internal = osi_calloc(sizeof(time_scene_internal_data_t)); if (!internal) { - BT_ERR("Allocate memory for time scene internal data fail"); + BT_ERR("%s, Failed to allocate memory", __func__); return -ENOMEM; } sys_slist_init(&internal->queue); - client->model = model; - client->op_pair_size = ARRAY_SIZE(time_scene_op_pair); - client->op_pair = time_scene_op_pair; + client->model = model; + client->op_pair_size = ARRAY_SIZE(time_scene_op_pair); + client->op_pair = time_scene_op_pair; client->internal_data = internal; return 0; diff --git a/components/bt/bluedroid/btc/core/btc_task.c b/components/bt/bluedroid/btc/core/btc_task.c index 97c5436d06..a32e9a881e 100644 --- a/components/bt/bluedroid/btc/core/btc_task.c +++ b/components/bt/bluedroid/btc/core/btc_task.c @@ -46,15 +46,15 @@ #include "btc_hf_client.h" #endif /* #if BTC_HF_CLIENT_INCLUDED */ #endif /* #if CONFIG_CLASSIC_BT_ENABLED */ -#if CONFIG_BT_MESH +#if CONFIG_BLE_MESH #include "btc_ble_mesh_prov.h" -#include "btc_ble_mesh_health.h" -#include "btc_ble_mesh_config_client.h" -#include "btc_ble_mesh_generic_client.h" -#include "btc_ble_mesh_light_client.h" -#include "btc_ble_mesh_sensor_client.h" -#include "btc_ble_mesh_time_scene_client.h" -#endif /* CONFIG_BT_MESH */ +#include "btc_ble_mesh_health_model.h" +#include "btc_ble_mesh_config_model.h" +#include "btc_ble_mesh_generic_model.h" +#include "btc_ble_mesh_lighting_model.h" +#include "btc_ble_mesh_sensor_model.h" +#include "btc_ble_mesh_time_scene_model.h" +#endif /* #if CONFIG_BLE_MESH */ static xTaskHandle xBtcTaskHandle = NULL; static xQueueHandle xBtcQueue = 0; @@ -96,7 +96,7 @@ static btc_func_t profile_tab[BTC_PID_NUM] = { #endif /* #if BTC_HF_CLIENT_INCLUDED */ #endif /* #if CONFIG_CLASSIC_BT_ENABLED */ -#if CONFIG_BT_MESH +#if CONFIG_BLE_MESH [BTC_PID_PROV] = {btc_mesh_prov_call_handler, btc_mesh_prov_cb_handler}, [BTC_PID_MODEL] = {btc_mesh_model_call_handler, btc_mesh_model_cb_handler}, [BTC_PID_HEALTH_CLIENT] = {btc_mesh_health_client_call_handler, btc_mesh_health_client_cb_handler}, @@ -107,7 +107,7 @@ static btc_func_t profile_tab[BTC_PID_NUM] = { [BTC_PID_LIGHT_CLIENT] = {btc_mesh_light_client_call_handler, btc_mesh_light_client_cb_handler}, [BTC_PID_SENSOR_CLIENT] = {btc_mesh_sensor_client_call_handler, btc_mesh_sensor_client_cb_handler}, [BTC_PID_TIME_SCENE_CLIENT] = {btc_mesh_time_scene_client_call_handler, btc_mesh_time_scene_client_cb_handler}, -#endif /* #if CONFIG_BT_MESH */ +#endif /* #if CONFIG_BLE_MESH */ }; /***************************************************************************** diff --git a/components/bt/bluedroid/btc/include/btc/btc_task.h b/components/bt/bluedroid/btc/include/btc/btc_task.h index 20c507cea3..dd15e23136 100644 --- a/components/bt/bluedroid/btc/include/btc/btc_task.h +++ b/components/bt/bluedroid/btc/include/btc/btc_task.h @@ -63,7 +63,7 @@ typedef enum { BTC_PID_HF_CLIENT, #endif /* BTC_HF_CLIENT_INCLUDED */ #endif /* CONFIG_CLASSIC_BT_ENABLED */ -#if CONFIG_BT_MESH +#if CONFIG_BLE_MESH BTC_PID_PROV, BTC_PID_MODEL, BTC_PID_HEALTH_CLIENT, @@ -74,7 +74,7 @@ typedef enum { BTC_PID_LIGHT_CLIENT, BTC_PID_SENSOR_CLIENT, BTC_PID_TIME_SCENE_CLIENT, -#endif /* #if CONFIG_BT_MESH */ +#endif /* #if CONFIG_BLE_MESH */ BTC_PID_NUM, } btc_pid_t; //btc profile id diff --git a/components/bt/component.mk b/components/bt/component.mk index e6a8345f84..e1ac7af05c 100644 --- a/components/bt/component.mk +++ b/components/bt/component.mk @@ -73,7 +73,7 @@ COMPONENT_PRIV_INCLUDEDIRS += bluedroid/bta/include \ COMPONENT_ADD_INCLUDEDIRS += bluedroid/api/include/api \ bluedroid/osi/include \ -ifdef CONFIG_BT_MESH +ifdef CONFIG_BLE_MESH COMPONENT_ADD_INCLUDEDIRS += ble_mesh/mesh_core \ ble_mesh/mesh_core/include \ ble_mesh/mesh_core/settings/include \ @@ -131,7 +131,7 @@ COMPONENT_SRCDIRS += bluedroid/bta/dm \ bluedroid/api \ bluedroid -ifdef CONFIG_BT_MESH +ifdef CONFIG_BLE_MESH COMPONENT_SRCDIRS += ble_mesh/mesh_core \ ble_mesh/mesh_core/settings \ ble_mesh/btc \ diff --git a/components/bt/test/test_ble_mesh_prov.c b/components/bt/test/test_ble_mesh_prov.c index 9db16a097c..937f074c05 100644 --- a/components/bt/test/test_ble_mesh_prov.c +++ b/components/bt/test/test_ble_mesh_prov.c @@ -167,7 +167,7 @@ static int ble_mesh_init(void) return err; } - esp_ble_mesh_node_prov_enable(BT_MESH_PROV_ADV | BT_MESH_PROV_GATT); + esp_ble_mesh_node_prov_enable(BLE_MESH_PROV_ADV | BLE_MESH_PROV_GATT); ESP_LOGI(TAG, "Mesh initialized\n"); diff --git a/components/bt/test/test_client_api.c b/components/bt/test/test_client_api.c index 10b3fbce38..15fe22c26a 100644 --- a/components/bt/test/test_client_api.c +++ b/components/bt/test/test_client_api.c @@ -183,7 +183,7 @@ static int ble_mesh_init(void) return err; } - esp_ble_mesh_node_prov_enable(BT_MESH_PROV_ADV | BT_MESH_PROV_GATT); + esp_ble_mesh_node_prov_enable(BLE_MESH_PROV_ADV | BLE_MESH_PROV_GATT); ESP_LOGI(TAG, "Mesh initialized\n"); diff --git a/examples/bluetooth/ble_mesh/ble_mesh_client_model/CMakeLists.txt b/examples/bluetooth/ble_mesh/ble_mesh_client_model/CMakeLists.txt new file mode 100644 index 0000000000..f384288f31 --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_client_model/CMakeLists.txt @@ -0,0 +1,6 @@ +# The following lines of boilerplate have to be in your project's CMakeLists +# in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(ble_mesh_client_model) diff --git a/examples/bluetooth/ble_mesh/ble_mesh_client_model/main/CMakeLists.txt b/examples/bluetooth/ble_mesh/ble_mesh_client_model/main/CMakeLists.txt new file mode 100644 index 0000000000..1eb2d87ed2 --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_client_model/main/CMakeLists.txt @@ -0,0 +1,6 @@ +set(COMPONENT_SRCS "ble_mesh_demo_main.c" + "board.c") + +set(COMPONENT_ADD_INCLUDEDIRS ".") + +register_component() diff --git a/examples/bluetooth/ble_mesh/ble_mesh_client_model/main/Kconfig.projbuild b/examples/bluetooth/ble_mesh/ble_mesh_client_model/main/Kconfig.projbuild index acca212403..3960a1a670 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_client_model/main/Kconfig.projbuild +++ b/examples/bluetooth/ble_mesh/ble_mesh_client_model/main/Kconfig.projbuild @@ -1,24 +1,28 @@ - menu "Example Configuration" -choice ESP32_BOARD - prompt "Board selection for BLE Mesh" - default ESP_WROOM_32_BOARD - help - Select this option to choose the board for BLE Mesh. The default is ESP32-WROOM-32 + choice ESP32_BOARD + prompt "Board selection for BLE Mesh" + default ESP_WROOM_32_BOARD + help + Select this option to choose the board for BLE Mesh. The default is ESP32-WROOM-32 -config ESP_WROOM_32_BOARD - bool "ESP32-WROOM-32" + config ESP_WROOM_32_BOARD + bool "ESP32-WROOM-32" -config ESP_WROVER_BOARD - bool "ESP32-WROVER" + config ESP_WROVER_BOARD + bool "ESP32-WROVER" + endchoice -endchoice + config HCI_5_0_VERSION + bool "Support sending 20ms non-connectable advertising packets" + default y + help + It is a temporary solution and needs further modifications. -config HCI_5_0_VERSION - bool "This option facilitates sending with 20ms non-connectable interval even if the controller is not HCI 5.0" - default y - help - It is a temporary solution and needs further modifications + config PATCH_FOR_SILICONLAB_APP_1_1_0 + bool "Fix bug of Silicon Lab Android App v1.1.0 when reconnection will cause sequence number to recount from 0" + default y + help + It is an ad hoc solution and needs further modifications. endmenu diff --git a/examples/bluetooth/ble_mesh/ble_mesh_client_model/main/ble_mesh_demo_main.c b/examples/bluetooth/ble_mesh/ble_mesh_client_model/main/ble_mesh_demo_main.c index 10155067f7..4969701469 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_client_model/main/ble_mesh_demo_main.c +++ b/examples/bluetooth/ble_mesh/ble_mesh_client_model/main/ble_mesh_demo_main.c @@ -48,12 +48,12 @@ static esp_ble_mesh_client_t onoff_client; static esp_ble_mesh_cfg_srv_t config_server = { .relay = ESP_BLE_MESH_RELAY_DISABLED, .beacon = ESP_BLE_MESH_BEACON_ENABLED, -#if defined(CONFIG_BT_MESH_FRIEND) +#if defined(CONFIG_BLE_MESH_FRIEND) .friend_state = ESP_BLE_MESH_FRIEND_ENABLED, #else .friend_state = ESP_BLE_MESH_FRIEND_NOT_SUPPORTED, #endif -#if defined(CONFIG_BT_MESH_GATT_PROXY) +#if defined(CONFIG_BLE_MESH_GATT_PROXY) .gatt_proxy = ESP_BLE_MESH_GATT_PROXY_ENABLED, #else .gatt_proxy = ESP_BLE_MESH_GATT_PROXY_NOT_SUPPORTED, diff --git a/examples/bluetooth/ble_mesh/ble_mesh_client_model/sdkconfig.defaults b/examples/bluetooth/ble_mesh/ble_mesh_client_model/sdkconfig.defaults index 1020655d5a..c10b1b3265 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_client_model/sdkconfig.defaults +++ b/examples/bluetooth/ble_mesh/ble_mesh_client_model/sdkconfig.defaults @@ -8,33 +8,31 @@ CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_GATTS_ENABLE=y CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL=y -CONFIG_BT_MESH=y -CONFIG_BT_MESH_USE_DUPLICATE_SCAN=y -CONFIG_BT_MESH_NODE=y -CONFIG_BT_MESH_PROV=y -CONFIG_NET_BUF_POOL_USAGE=y -CONFIG_BT_MESH_PROXY=y -CONFIG_BT_MESH_PB_GATT=y -CONFIG_BT_MESH_GATT_PROXY=y -CONFIG_BT_MESH_NODE_ID_TIMEOUT=60 -CONFIG_BT_MESH_PROXY_FILTER_SIZE=1 -CONFIG_BT_MESH_SELF_TEST= -CONFIG_BT_MESH_IV_UPDATE_TEST= -CONFIG_BT_MESH_SUBNET_COUNT=1 -CONFIG_BT_MESH_APP_KEY_COUNT=1 -CONFIG_BT_MESH_MODEL_KEY_COUNT=1 -CONFIG_BT_MESH_MODEL_GROUP_COUNT=1 -CONFIG_BT_MESH_LABEL_COUNT=1 -CONFIG_BT_MESH_CRPL=10 -CONFIG_BT_MESH_MSG_CACHE_SIZE=10 -CONFIG_BT_MESH_ADV_BUF_COUNT=20 -CONFIG_BT_MESH_TX_SEG_MSG_COUNT=6 -CONFIG_BT_MESH_RX_SEG_MSG_COUNT=1 -CONFIG_BT_MESH_RX_SDU_MAX=384 -CONFIG_BT_MESH_RELAY=y -CONFIG_BT_MESH_LOW_POWER= -CONFIG_BT_MESH_FRIEND= -CONFIG_BT_MESH_CFG_CLI= -CONFIG_BT_MESH_HEALTH_CLI= -CONFIG_BT_MESH_GENERIC_ONOFF_CLI=y +CONFIG_BLE_MESH=y +CONFIG_BLE_MESH_USE_DUPLICATE_SCAN=y +CONFIG_BLE_MESH_NODE=y +CONFIG_BLE_MESH_PROV=y +CONFIG_BLE_MESH_NET_BUF_POOL_USAGE=y +CONFIG_BLE_MESH_PROXY=y +CONFIG_BLE_MESH_PB_GATT=y +CONFIG_BLE_MESH_GATT_PROXY=y +CONFIG_BLE_MESH_NODE_ID_TIMEOUT=60 +CONFIG_BLE_MESH_PROXY_FILTER_SIZE=1 +CONFIG_BLE_MESH_IV_UPDATE_TEST= +CONFIG_BLE_MESH_SUBNET_COUNT=1 +CONFIG_BLE_MESH_APP_KEY_COUNT=1 +CONFIG_BLE_MESH_MODEL_KEY_COUNT=1 +CONFIG_BLE_MESH_MODEL_GROUP_COUNT=1 +CONFIG_BLE_MESH_LABEL_COUNT=1 +CONFIG_BLE_MESH_CRPL=10 +CONFIG_BLE_MESH_MSG_CACHE_SIZE=10 +CONFIG_BLE_MESH_ADV_BUF_COUNT=20 +CONFIG_BLE_MESH_TX_SEG_MSG_COUNT=6 +CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=1 +CONFIG_BLE_MESH_RX_SDU_MAX=384 +CONFIG_BLE_MESH_RELAY=y +CONFIG_BLE_MESH_LOW_POWER= +CONFIG_BLE_MESH_FRIEND= +CONFIG_BLE_MESH_CFG_CLI= +CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y CONFIG_BTU_TASK_STACK_SIZE=4512 \ No newline at end of file diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/CMakeLists.txt b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/CMakeLists.txt new file mode 100644 index 0000000000..74361e558c --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/CMakeLists.txt @@ -0,0 +1,6 @@ +# The following lines of boilerplate have to be in your project's CMakeLists +# in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(ble_mesh_console_node) diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/CMakeLists.txt b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/CMakeLists.txt new file mode 100644 index 0000000000..2275f9a4e0 --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/CMakeLists.txt @@ -0,0 +1,12 @@ +set(COMPONENT_SRCS "ble_mesh_adapter.c" + "ble_mesh_cfg_srv_model.c" + "ble_mesh_console_lib.c" + "ble_mesh_console_main.c" + "ble_mesh_console_system.c" + "ble_mesh_register_node_cmd.c" + "ble_mesh_register_server_cmd.c" + "register_bluetooth.c") + +set(COMPONENT_ADD_INCLUDEDIRS ".") + +register_component() diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_adapter.c b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_adapter.c index 47622b9d1d..4123756b8c 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_adapter.c +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_adapter.c @@ -28,7 +28,7 @@ esp_ble_mesh_model_t *ble_mesh_get_model(uint16_t model_id) case ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_SRV: model = &gen_onoff_srv_models[1]; break; -#if (CONFIG_BT_MESH_GENERIC_ONOFF_CLI) +#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI) case ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_CLI: model = &gen_onoff_cli_models[1]; break; @@ -57,7 +57,7 @@ esp_ble_mesh_comp_t *ble_mesh_get_component(uint16_t model_id) case ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_SRV: comp = &gen_onoff_srv_comp; break; -#if (CONFIG_BT_MESH_GENERIC_ONOFF_CLI) +#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI) case ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_CLI: comp = &gen_onoff_cli_comp; break; diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_cfg_srv_model.c b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_cfg_srv_model.c index 695ce2faa0..1bc88cdf22 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_cfg_srv_model.c +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_cfg_srv_model.c @@ -16,13 +16,13 @@ uint8_t dev_uuid[16] = {0xdd, 0xdd}; -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE esp_ble_mesh_prov_t prov = { .uuid = dev_uuid, }; -#endif //CONFIG_BT_MESH_NODE +#endif //CONFIG_BLE_MESH_NODE -#if CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_PROVISIONER esp_ble_mesh_prov_t prov = { .prov_uuid = dev_uuid, .prov_unicast_addr = 0x0001, @@ -38,7 +38,7 @@ esp_ble_mesh_prov_t prov = { .flags = 0x00, .iv_index = 0x00, }; -#endif //CONFIG_BT_MESH_PROVISIONER +#endif //CONFIG_BLE_MESH_PROVISIONER esp_ble_mesh_model_pub_t model_pub_config = { .msg = NET_BUF_SIMPLE(2 + 1), @@ -52,21 +52,21 @@ esp_ble_mesh_model_pub_t vendor_model_pub_config; esp_ble_mesh_cfg_srv_t cfg_srv = { .relay = ESP_BLE_MESH_RELAY_ENABLED, .beacon = ESP_BLE_MESH_BEACON_ENABLED, -#if defined(CONFIG_BT_MESH_FRIEND) - .friend_state = BT_MESH_FRIEND_ENABLED, +#if defined(CONFIG_BLE_MESH_FRIEND) + .friend_state = ESP_BLE_MESH_FRIEND_ENABLED, #else - .friend_state = BT_MESH_FRIEND_NOT_SUPPORTED, + .friend_state = ESP_BLE_MESH_FRIEND_NOT_SUPPORTED, #endif -#if defined(CONFIG_BT_MESH_GATT_PROXY) - .gatt_proxy = BT_MESH_GATT_PROXY_ENABLED, +#if defined(CONFIG_BLE_MESH_GATT_PROXY) + .gatt_proxy = ESP_BLE_MESH_GATT_PROXY_ENABLED, #else - .gatt_proxy = BT_MESH_GATT_PROXY_NOT_SUPPORTED, + .gatt_proxy = ESP_BLE_MESH_GATT_PROXY_NOT_SUPPORTED, #endif .default_ttl = 7, /* 3 transmissions with 20ms interval */ .net_transmit = ESP_BLE_MESH_TRANSMIT(2, 20), - .relay_retransmit = BT_MESH_TRANSMIT(0, 20), + .relay_retransmit = ESP_BLE_MESH_TRANSMIT(0, 20), }; esp_ble_mesh_model_t config_server_models[] = { @@ -123,7 +123,7 @@ esp_ble_mesh_comp_t gen_onoff_srv_comp = { }; // config generic onoff client -#if (CONFIG_BT_MESH_GENERIC_ONOFF_CLI) +#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI) esp_ble_mesh_client_t gen_onoff_cli; @@ -142,7 +142,7 @@ esp_ble_mesh_comp_t gen_onoff_cli_comp = { .elements = gen_onoff_cli_elements, .element_count = ARRAY_SIZE(gen_onoff_cli_elements), }; -#endif //CONFIG_BT_MESH_GENERIC_ONOFF_CLI +#endif //CONFIG_BLE_MESH_GENERIC_ONOFF_CLI //CONFIG VENDOR MODEL TEST PERFORMANCE #define ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_SRV 0x2000 diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_cfg_srv_model.h b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_cfg_srv_model.h index 72f012506f..f0cb0041fe 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_cfg_srv_model.h +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_cfg_srv_model.h @@ -18,9 +18,9 @@ #include "esp_ble_mesh_defs.h" #include "esp_ble_mesh_config_model_api.h" -#if (CONFIG_BT_MESH_GENERIC_ONOFF_CLI) +#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI) #include "esp_ble_mesh_generic_model_api.h" -#endif //CONFIG_BT_MESH_GENERIC_ONOFF_CLI +#endif //CONFIG_BLE_MESH_GENERIC_ONOFF_CLI #define NODE_MAX_GROUP_CONFIG 3 #define CID_ESP 0x02C4 @@ -66,7 +66,7 @@ extern esp_ble_mesh_elem_t gen_onoff_srv_elements[]; extern esp_ble_mesh_comp_t gen_onoff_srv_comp; // config generic onoff client -#if (CONFIG_BT_MESH_GENERIC_ONOFF_CLI) +#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI) extern esp_ble_mesh_client_t gen_onoff_cli; @@ -75,7 +75,7 @@ extern esp_ble_mesh_model_t gen_onoff_cli_models[]; extern esp_ble_mesh_elem_t gen_onoff_cli_elements[]; extern esp_ble_mesh_comp_t gen_onoff_cli_comp; -#endif //CONFIG_BT_MESH_GENERIC_ONOFF_CLI +#endif //CONFIG_BLE_MESH_GENERIC_ONOFF_CLI //CONFIG VENDOR MODEL TEST PERFORMANCE #define ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_SRV 0x2000 diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_console_decl.h b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_console_decl.h index bf10edb741..22ab3a7f59 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_console_decl.h +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_console_decl.h @@ -22,7 +22,7 @@ void ble_mesh_register_mesh_node(); // Register mesh config server and generic server operation cmd void ble_mesh_register_server(); -#if (CONFIG_BT_MESH_CFG_CLI) +#if (CONFIG_BLE_MESH_CFG_CLI) // Register mesh config client operation cmd void ble_mesh_register_configuration_client_model(); #endif diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_console_system.c b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_console_system.c index ebb7d83e29..cc8805dbf2 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_console_system.c +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_console_system.c @@ -24,6 +24,10 @@ #include "ble_mesh_console_decl.h" +#if CONFIG_IDF_CMAKE +#define CONFIG_ESPTOOLPY_PORT "Which is choosen by Users for CMake" +#endif + static void register_free(); static void register_restart(); static void register_make(); diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_register_node_cmd.c b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_register_node_cmd.c index cf181a6ccb..da08884e35 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_register_node_cmd.c +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/main/ble_mesh_register_node_cmd.c @@ -178,7 +178,7 @@ void ble_mesh_model_cb(esp_ble_mesh_model_cb_event_t event, esp_ble_mesh_model_c switch (event) { case ESP_BLE_MESH_MODEL_OPERATION_EVT: if (param->model_operation.model != NULL && param->model_operation.model->op != NULL) { - if (param->model_operation.opcode == BT_MESH_MODEL_OP_GEN_ONOFF_GET) { + if (param->model_operation.opcode == ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_GET) { ESP_LOGI(TAG, "Node:GetStatus,Success"); ble_mesh_node_get_state(status); esp_ble_mesh_server_model_send_msg(param->model_operation.model, param->model_operation.ctx, ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS, diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/sdkconfig.defaults b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/sdkconfig.defaults index 39361b6b4a..87e0bf5bb4 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/sdkconfig.defaults +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_node/sdkconfig.defaults @@ -11,30 +11,29 @@ CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_GATTS_ENABLE=y CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL=y -CONFIG_BT_MESH=y -CONFIG_BT_MESH_USE_DUPLICATE_SCAN=y -CONFIG_BT_MESH_NODE=y -CONFIG_BT_MESH_PROV=y -CONFIG_NET_BUF_POOL_USAGE=y -CONFIG_BT_MESH_PROXY=y -CONFIG_BT_MESH_PB_GATT=y -CONFIG_BT_MESH_GATT_PROXY=y -CONFIG_BT_MESH_NODE_ID_TIMEOUT=60 -CONFIG_BT_MESH_PROXY_FILTER_SIZE=1 -CONFIG_BT_MESH_SUBNET_COUNT=1 -CONFIG_BT_MESH_APP_KEY_COUNT=1 -CONFIG_BT_MESH_MODEL_KEY_COUNT=1 -CONFIG_BT_MESH_MODEL_GROUP_COUNT=1 -CONFIG_BT_MESH_LABEL_COUNT=1 -CONFIG_BT_MESH_CRPL=10 -CONFIG_BT_MESH_MSG_CACHE_SIZE=10 -CONFIG_BT_MESH_ADV_BUF_COUNT=20 -CONFIG_BT_MESH_TX_SEG_MSG_COUNT=6 -CONFIG_BT_MESH_RX_SEG_MSG_COUNT=1 -CONFIG_BT_MESH_RX_SDU_MAX=384 -CONFIG_BT_MESH_RELAY=y -CONFIG_BT_MESH_LOW_POWER= -CONFIG_BT_MESH_FRIEND= -CONFIG_BT_MESH_CFG_CLI=y -CONFIG_BT_MESH_HEALTH_CLI=y +CONFIG_BLE_MESH=y +CONFIG_BLE_MESH_USE_DUPLICATE_SCAN=y +CONFIG_BLE_MESH_NODE=y +CONFIG_BLE_MESH_PROV=y +CONFIG_BLE_MESH_NET_BUF_POOL_USAGE=y +CONFIG_BLE_MESH_PROXY=y +CONFIG_BLE_MESH_PB_GATT=y +CONFIG_BLE_MESH_GATT_PROXY=y +CONFIG_BLE_MESH_NODE_ID_TIMEOUT=60 +CONFIG_BLE_MESH_PROXY_FILTER_SIZE=1 +CONFIG_BLE_MESH_SUBNET_COUNT=1 +CONFIG_BLE_MESH_APP_KEY_COUNT=1 +CONFIG_BLE_MESH_MODEL_KEY_COUNT=1 +CONFIG_BLE_MESH_MODEL_GROUP_COUNT=1 +CONFIG_BLE_MESH_LABEL_COUNT=1 +CONFIG_BLE_MESH_CRPL=10 +CONFIG_BLE_MESH_MSG_CACHE_SIZE=10 +CONFIG_BLE_MESH_ADV_BUF_COUNT=20 +CONFIG_BLE_MESH_TX_SEG_MSG_COUNT=6 +CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=1 +CONFIG_BLE_MESH_RX_SDU_MAX=384 +CONFIG_BLE_MESH_RELAY=y +CONFIG_BLE_MESH_LOW_POWER= +CONFIG_BLE_MESH_FRIEND= +CONFIG_BLE_MESH_CFG_CLI=y CONFIG_BTU_TASK_STACK_SIZE=4512 \ No newline at end of file diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/CMakeLists.txt b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/CMakeLists.txt new file mode 100644 index 0000000000..6ce28d7d57 --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/CMakeLists.txt @@ -0,0 +1,6 @@ +# The following lines of boilerplate have to be in your project's CMakeLists +# in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(ble_mesh_console_provisioner) diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/CMakeLists.txt b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/CMakeLists.txt new file mode 100644 index 0000000000..339b93fc95 --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/CMakeLists.txt @@ -0,0 +1,15 @@ +set(COMPONENT_SRCS "ble_mesh_adapter.c" + "ble_mesh_cfg_srv_model.c" + "ble_mesh_console_lib.c" + "ble_mesh_console_main.c" + "ble_mesh_console_system.c" + "ble_mesh_reg_cfg_client_cmd.c" + "ble_mesh_reg_gen_onoff_client_cmd.c" + "ble_mesh_reg_test_perf_client_cmd.c" + "ble_mesh_register_node_cmd.c" + "ble_mesh_register_provisioner_cmd.c" + "register_bluetooth.c") + +set(COMPONENT_ADD_INCLUDEDIRS ".") + +register_component() diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_adapter.c b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_adapter.c index a7a55d605f..5f668718f3 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_adapter.c +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_adapter.c @@ -23,7 +23,7 @@ esp_ble_mesh_model_t *ble_mesh_get_model(uint16_t model_id) case ESP_BLE_MESH_MODEL_ID_CONFIG_SRV: model = config_server_models; break; -#if (CONFIG_BT_MESH_CFG_CLI) +#if (CONFIG_BLE_MESH_CFG_CLI) case ESP_BLE_MESH_MODEL_ID_CONFIG_CLI: model = &gen_onoff_cli_models[1]; break; @@ -31,7 +31,7 @@ esp_ble_mesh_model_t *ble_mesh_get_model(uint16_t model_id) case ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_SRV: model = &gen_onoff_srv_models[1]; break; -#if (CONFIG_BT_MESH_GENERIC_ONOFF_CLI) +#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI) case ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_CLI: model = &gen_onoff_cli_models[2]; break; @@ -61,7 +61,7 @@ esp_ble_mesh_comp_t *ble_mesh_get_component(uint16_t model_id) case ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_SRV: comp = &gen_onoff_srv_comp; break; -#if (CONFIG_BT_MESH_GENERIC_ONOFF_CLI) +#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI) case ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_CLI: comp = &gen_onoff_cli_comp; break; diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_cfg_srv_model.c b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_cfg_srv_model.c index a0128e46f7..a56c3647f1 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_cfg_srv_model.c +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_cfg_srv_model.c @@ -16,13 +16,13 @@ uint8_t dev_uuid[16] = {0xdd, 0xdd}; -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE esp_ble_mesh_prov_t prov = { .uuid = dev_uuid, }; -#endif //CONFIG_BT_MESH_NODE +#endif //CONFIG_BLE_MESH_NODE -#if CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_PROVISIONER esp_ble_mesh_prov_t prov = { .prov_uuid = dev_uuid, .prov_unicast_addr = 0x0001, @@ -35,7 +35,7 @@ esp_ble_mesh_prov_t prov = { .flags = 0x00, .iv_index = 0x00, }; -#endif //CONFIG_BT_MESH_PROVISIONER +#endif //CONFIG_BLE_MESH_PROVISIONER esp_ble_mesh_model_pub_t model_pub_config = { .msg = NET_BUF_SIMPLE(2 + 1), @@ -48,21 +48,21 @@ esp_ble_mesh_model_pub_t vendor_model_pub_config; esp_ble_mesh_cfg_srv_t cfg_srv = { .relay = ESP_BLE_MESH_RELAY_ENABLED, .beacon = ESP_BLE_MESH_BEACON_ENABLED, -#if defined(CONFIG_BT_MESH_FRIEND) - .friend_state = BT_MESH_FRIEND_ENABLED, +#if defined(CONFIG_BLE_MESH_FRIEND) + .friend_state = ESP_BLE_MESH_FRIEND_ENABLED, #else - .friend_state = BT_MESH_FRIEND_NOT_SUPPORTED, + .friend_state = ESP_BLE_MESH_FRIEND_NOT_SUPPORTED, #endif -#if defined(CONFIG_BT_MESH_GATT_PROXY) - .gatt_proxy = BT_MESH_GATT_PROXY_ENABLED, +#if defined(CONFIG_BLE_MESH_GATT_PROXY) + .gatt_proxy = ESP_BLE_MESH_GATT_PROXY_ENABLED, #else - .gatt_proxy = BT_MESH_GATT_PROXY_NOT_SUPPORTED, + .gatt_proxy = ESP_BLE_MESH_GATT_PROXY_NOT_SUPPORTED, #endif .default_ttl = 7, /* 3 transmissions with 20ms interval */ .net_transmit = ESP_BLE_MESH_TRANSMIT(2, 20), - .relay_retransmit = BT_MESH_TRANSMIT(0, 20), + .relay_retransmit = ESP_BLE_MESH_TRANSMIT(0, 20), }; esp_ble_mesh_model_t config_server_models[] = { @@ -119,7 +119,7 @@ esp_ble_mesh_comp_t gen_onoff_srv_comp = { }; // config generic onoff client -#if (CONFIG_BT_MESH_GENERIC_ONOFF_CLI) +#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI) esp_ble_mesh_client_t gen_onoff_cli; @@ -138,7 +138,7 @@ esp_ble_mesh_comp_t gen_onoff_cli_comp = { .elements = gen_onoff_cli_elements, .element_count = ARRAY_SIZE(gen_onoff_cli_elements), }; -#endif //CONFIG_BT_MESH_GENERIC_ONOFF_CLI +#endif //CONFIG_BLE_MESH_GENERIC_ONOFF_CLI //CONFIG VENDOR MODEL TEST PERFORMANCE #define ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_SRV 0x2000 diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_cfg_srv_model.h b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_cfg_srv_model.h index 72f012506f..f0cb0041fe 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_cfg_srv_model.h +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_cfg_srv_model.h @@ -18,9 +18,9 @@ #include "esp_ble_mesh_defs.h" #include "esp_ble_mesh_config_model_api.h" -#if (CONFIG_BT_MESH_GENERIC_ONOFF_CLI) +#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI) #include "esp_ble_mesh_generic_model_api.h" -#endif //CONFIG_BT_MESH_GENERIC_ONOFF_CLI +#endif //CONFIG_BLE_MESH_GENERIC_ONOFF_CLI #define NODE_MAX_GROUP_CONFIG 3 #define CID_ESP 0x02C4 @@ -66,7 +66,7 @@ extern esp_ble_mesh_elem_t gen_onoff_srv_elements[]; extern esp_ble_mesh_comp_t gen_onoff_srv_comp; // config generic onoff client -#if (CONFIG_BT_MESH_GENERIC_ONOFF_CLI) +#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI) extern esp_ble_mesh_client_t gen_onoff_cli; @@ -75,7 +75,7 @@ extern esp_ble_mesh_model_t gen_onoff_cli_models[]; extern esp_ble_mesh_elem_t gen_onoff_cli_elements[]; extern esp_ble_mesh_comp_t gen_onoff_cli_comp; -#endif //CONFIG_BT_MESH_GENERIC_ONOFF_CLI +#endif //CONFIG_BLE_MESH_GENERIC_ONOFF_CLI //CONFIG VENDOR MODEL TEST PERFORMANCE #define ESP_BLE_MESH_VND_MODEL_ID_TEST_PERF_SRV 0x2000 diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_console_decl.h b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_console_decl.h index f9a2ce408d..90e52a61d9 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_console_decl.h +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_console_decl.h @@ -22,17 +22,17 @@ void ble_mesh_register_mesh_node(); // Register Test Perf client cmd void ble_mesh_register_mesh_test_performance_client(); -#if (CONFIG_BT_MESH_CFG_CLI) +#if (CONFIG_BLE_MESH_CFG_CLI) // Register mesh config client operation cmd void ble_mesh_register_configuration_client_model(); #endif -#if (CONFIG_BT_MESH_GENERIC_ONOFF_CLI) +#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI) // Register mesh client operation cmd void ble_mesh_register_gen_onoff_client(); #endif -#if CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_PROVISIONER // Regitster mesh provisioner cmd void ble_mesh_register_mesh_provisioner(); #endif diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_console_main.c b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_console_main.c index 9298c95e24..f7c4eacf6b 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_console_main.c +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_console_main.c @@ -156,13 +156,13 @@ void app_main(void) register_bluetooth(); ble_mesh_register_mesh_node(); ble_mesh_register_mesh_test_performance_client(); -#if (CONFIG_BT_MESH_GENERIC_ONOFF_CLI) +#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI) ble_mesh_register_gen_onoff_client(); #endif -#if (CONFIG_BT_MESH_PROVISIONER) +#if (CONFIG_BLE_MESH_PROVISIONER) ble_mesh_register_mesh_provisioner(); #endif -#if (CONFIG_BT_MESH_CFG_CLI) +#if (CONFIG_BLE_MESH_CFG_CLI) ble_mesh_register_configuration_client_model(); #endif diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_console_system.c b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_console_system.c index 693c865faf..d3dc6c12f9 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_console_system.c +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_console_system.c @@ -20,6 +20,10 @@ #include "ble_mesh_console_decl.h" +#if CONFIG_IDF_CMAKE +#define CONFIG_ESPTOOLPY_PORT "Which is choosen by Users for CMake" +#endif + static void register_free(); static void register_restart(); static void register_make(); diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_reg_cfg_client_cmd.c b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_reg_cfg_client_cmd.c index ba2c630d94..fd2852de82 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_reg_cfg_client_cmd.c +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_reg_cfg_client_cmd.c @@ -15,7 +15,7 @@ #include "esp_ble_mesh_networking_api.h" #include "ble_mesh_adapter.h" -#if (CONFIG_BT_MESH_CFG_CLI) +#if (CONFIG_BLE_MESH_CFG_CLI) typedef struct { struct arg_str *action_type; struct arg_str *set_state; diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_reg_gen_onoff_client_cmd.c b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_reg_gen_onoff_client_cmd.c index 210e81c60f..70a28162f7 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_reg_gen_onoff_client_cmd.c +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_reg_gen_onoff_client_cmd.c @@ -15,7 +15,7 @@ #include "esp_timer.h" #include "ble_mesh_adapter.h" -#if (CONFIG_BT_MESH_GENERIC_ONOFF_CLI) +#if (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI) typedef struct { struct arg_str *action_type; struct arg_int *op_en; diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_register_node_cmd.c b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_register_node_cmd.c index dbefe685f3..57e89605c9 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_register_node_cmd.c +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_register_node_cmd.c @@ -140,7 +140,7 @@ void ble_mesh_prov_cb(esp_ble_mesh_prov_cb_event_t event, esp_ble_mesh_prov_cb_p case ESP_BLE_MESH_NODE_PROXY_GATT_DISABLE_COMP_EVT: ble_mesh_callback_check_err_code(param->node_proxy_gatt_disable_comp.err_code, "Node:DisProxyGatt"); break; -#if (CONFIG_BT_MESH_PROVISIONER) +#if (CONFIG_BLE_MESH_PROVISIONER) case ESP_BLE_MESH_PROVISIONER_RECV_UNPROV_ADV_PKT_EVT: ESP_LOGI(TAG, "Provisioner recv unprovisioned device beacon:"); ESP_LOG_BUFFER_HEX("Device UUID %s", param->provisioner_recv_unprov_adv_pkt.dev_uuid, 16); @@ -209,12 +209,12 @@ void ble_mesh_model_cb(esp_ble_mesh_model_cb_event_t event, esp_ble_mesh_model_c if (param->model_operation.opcode == ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_GET) { ESP_LOGI(TAG, "Node:GetStatus,OK"); ble_mesh_node_get_state(status); - result = esp_ble_mesh_server_model_send_msg(param->model_operation.model, param->model_operation.ctx, BT_MESH_MODEL_OP_GEN_ONOFF_STATUS, + result = esp_ble_mesh_server_model_send_msg(param->model_operation.model, param->model_operation.ctx, ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS, sizeof(status), &status); } else if (param->model_operation.opcode == ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET) { ble_mesh_node_set_state(param->model_operation.msg[0]); ESP_LOGI(TAG, "Node:SetAck,OK,%d,%d", param->model_operation.msg[0], param->model_operation.ctx->recv_ttl); - result = esp_ble_mesh_server_model_send_msg(param->model_operation.model, param->model_operation.ctx, BT_MESH_MODEL_OP_GEN_ONOFF_STATUS, + result = esp_ble_mesh_server_model_send_msg(param->model_operation.model, param->model_operation.ctx, ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_STATUS, sizeof(status), param->model_operation.msg); } else if (param->model_operation.opcode == ESP_BLE_MESH_MODEL_OP_GEN_ONOFF_SET_UNACK) { ble_mesh_node_set_state(param->model_operation.msg[0]); @@ -315,7 +315,7 @@ static int ble_mesh_load_oob(int argc, char **argv) } //parsing prov -#if CONFIG_BT_MESH_NODE +#if CONFIG_BLE_MESH_NODE prov.uuid = dev_uuid; memcpy(dev_uuid, esp_bt_dev_get_address(), 6); if (oob.static_val->count != 0) { @@ -334,7 +334,7 @@ static int ble_mesh_load_oob(int argc, char **argv) arg_int_to_value(oob.input_actions, prov.input_actions, "input actions"); #endif -#if CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_PROVISIONER if (oob.static_val->count != 0) { static_val = malloc(oob.static_val_len->ival[0] + 1); if (static_val == NULL) { diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_register_provisioner_cmd.c b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_register_provisioner_cmd.c index 83454b8997..c5a2d3ad1b 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_register_provisioner_cmd.c +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/main/ble_mesh_register_provisioner_cmd.c @@ -23,7 +23,7 @@ #include "ble_mesh_adapter.h" #include "ble_mesh_console_decl.h" -#if CONFIG_BT_MESH_PROVISIONER +#if CONFIG_BLE_MESH_PROVISIONER typedef struct { struct arg_int *bearer; diff --git a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/sdkconfig.defaults b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/sdkconfig.defaults index 146915e24d..d9b602b567 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/sdkconfig.defaults +++ b/examples/bluetooth/ble_mesh/ble_mesh_console/ble_mesh_provisioner/sdkconfig.defaults @@ -6,24 +6,23 @@ CONFIG_SCAN_DUPLICATE_TYPE=2 CONFIG_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 -CONFIG_BT_MESH=y -CONFIG_BT_MESH_USE_DUPLICATE_SCAN=y -CONFIG_BT_MESH_PROV=y -CONFIG_BT_MESH_PROVISIONER=y -CONFIG_BT_MESH_UNPROV_DEV_ADD=20 -CONFIG_BT_MESH_MAX_PROV_NODES=20 -CONFIG_BT_MESH_PBA_SAME_TIME=10 -CONFIG_BT_MESH_PBG_SAME_TIME=4 -CONFIG_BT_MESH_PROVISIONER_SUBNET_COUNT=3 -CONFIG_BT_MESH_PROVISIONER_APP_KEY_COUNT=9 -CONFIG_BT_MESH_PB_ADV=y -CONFIG_NET_BUF_POOL_USAGE=y -CONFIG_BT_MESH_PB_GATT=y -CONFIG_BT_MESH_GATT_PROXY=y -CONFIG_BT_MESH_RELAY=y -CONFIG_BT_MESH_LOW_POWER= -CONFIG_BT_MESH_FRIEND= +CONFIG_BLE_MESH=y +CONFIG_BLE_MESH_USE_DUPLICATE_SCAN=y +CONFIG_BLE_MESH_PROV=y +CONFIG_BLE_MESH_PROVISIONER=y +CONFIG_BLE_MESH_WAIT_FOR_PROV_MAX_DEV_NUM=20 +CONFIG_BLE_MESH_MAX_PROV_NODES=20 +CONFIG_BLE_MESH_PBA_SAME_TIME=10 +CONFIG_BLE_MESH_PBG_SAME_TIME=4 +CONFIG_BLE_MESH_PROVISIONER_SUBNET_COUNT=3 +CONFIG_BLE_MESH_PROVISIONER_APP_KEY_COUNT=9 +CONFIG_BLE_MESH_PB_ADV=y +CONFIG_BLE_MESH_NET_BUF_POOL_USAGE=y +CONFIG_BLE_MESH_PB_GATT=y +CONFIG_BLE_MESH_GATT_PROXY=y +CONFIG_BLE_MESH_RELAY=y +CONFIG_BLE_MESH_LOW_POWER= +CONFIG_BLE_MESH_FRIEND= CONFIG_BTU_TASK_STACK_SIZE=4512 -CONFIG_BT_MESH_CFG_CLI=y -CONFIG_BT_MESH_HEALTH_CLI=y -CONFIG_BT_MESH_GENERIC_ONOFF_CLI=y \ No newline at end of file +CONFIG_BLE_MESH_CFG_CLI=y +CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y \ No newline at end of file diff --git a/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/CMakeLists.txt b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/CMakeLists.txt new file mode 100644 index 0000000000..df96eec280 --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/CMakeLists.txt @@ -0,0 +1,8 @@ +# The following lines of boilerplate have to be in your project's CMakeLists +# in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(ble_mesh_fast_prov_client) diff --git a/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/Makefile b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/Makefile index e708482506..06bba88878 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/Makefile +++ b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/Makefile @@ -3,10 +3,10 @@ # project subdirectory. # -PROJECT_NAME := bt_mesh_fast_prov_client +PROJECT_NAME := ble_mesh_fast_prov_client COMPONENT_ADD_INCLUDEDIRS := components/include -EXTRA_COMPONENT_DIRS := $(IDF_PATH)/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model +EXTRA_COMPONENT_DIRS := $(IDF_PATH)/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components include $(IDF_PATH)/make/project.mk diff --git a/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/main/CMakeLists.txt b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/main/CMakeLists.txt new file mode 100644 index 0000000000..3d3bc6f9a5 --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/main/CMakeLists.txt @@ -0,0 +1,5 @@ +set(COMPONENT_SRCS "ble_mesh_demo_main.c") + +set(COMPONENT_ADD_INCLUDEDIRS ".") + +register_component() diff --git a/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/main/Kconfig.projbuild b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/main/Kconfig.projbuild index ec54d3eb77..eb3de7ae00 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/main/Kconfig.projbuild +++ b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/main/Kconfig.projbuild @@ -1,9 +1,9 @@ -menu "Example 'BLE Mesh' Config" +menu "Example Configuration" -config HCI_5_0_VERSION - bool "If you need to send 20ms non-connectable advertising packets and the BLE controller you are using is not HCI 5.0, set this marco to true." - default y - help - It is just a temporary solution, which will be modified later. + config HCI_5_0_VERSION + bool "Support sending 20ms non-connectable advertising packets" + default y + help + It is a temporary solution and needs further modifications. endmenu diff --git a/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/main/ble_mesh_demo_main.c b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/main/ble_mesh_demo_main.c index c31bf3cbd4..09a9917419 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/main/ble_mesh_demo_main.c +++ b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/main/ble_mesh_demo_main.c @@ -52,12 +52,12 @@ static const esp_ble_mesh_client_op_pair_t fast_prov_cli_op_pair[] = { static esp_ble_mesh_cfg_srv_t config_server = { .relay = ESP_BLE_MESH_RELAY_DISABLED, .beacon = ESP_BLE_MESH_BEACON_ENABLED, -#if defined(CONFIG_BT_MESH_FRIEND) +#if defined(CONFIG_BLE_MESH_FRIEND) .friend_state = ESP_BLE_MESH_FRIEND_ENABLED, #else .friend_state = ESP_BLE_MESH_FRIEND_NOT_SUPPORTED, #endif -#if defined(CONFIG_BT_MESH_GATT_PROXY) +#if defined(CONFIG_BLE_MESH_GATT_PROXY) .gatt_proxy = ESP_BLE_MESH_GATT_PROXY_ENABLED, #else .gatt_proxy = ESP_BLE_MESH_GATT_PROXY_NOT_SUPPORTED, diff --git a/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/sdkconfig.defaults b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/sdkconfig.defaults index cbd75f168f..84d6bbbcc4 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/sdkconfig.defaults +++ b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_client/sdkconfig.defaults @@ -6,30 +6,30 @@ CONFIG_SCAN_DUPLICATE_TYPE=2 CONFIG_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 -CONFIG_BT_MESH=y -CONFIG_BT_MESH_USE_DUPLICATE_SCAN=y -CONFIG_BT_MESH_PROV=y -CONFIG_BT_MESH_PROVISIONER=y -CONFIG_BT_MESH_UNPROV_DEV_ADD=10 -CONFIG_BT_MESH_MAX_PROV_NODES=10 -CONFIG_BT_MESH_MAX_STORED_NODES=10 -CONFIG_BT_MESH_PBA_SAME_TIME=1 -CONFIG_BT_MESH_PBG_SAME_TIME=1 -CONFIG_BT_MESH_PROVISIONER_SUBNET_COUNT=3 -CONFIG_BT_MESH_PROVISIONER_APP_KEY_COUNT=3 -CONFIG_BT_MESH_PB_ADV=y -CONFIG_NET_BUF_POOL_USAGE=y -CONFIG_BT_MESH_PB_GATT=y -CONFIG_BT_MESH_GATT_PROXY=y -CONFIG_BT_MESH_RELAY=y -CONFIG_BT_MESH_LOW_POWER= -CONFIG_BT_MESH_FRIEND= +CONFIG_BLE_MESH=y +CONFIG_BLE_MESH_USE_DUPLICATE_SCAN=y +CONFIG_BLE_MESH_PROV=y +CONFIG_BLE_MESH_PROVISIONER=y +CONFIG_BLE_MESH_WAIT_FOR_PROV_MAX_DEV_NUM=10 +CONFIG_BLE_MESH_MAX_PROV_NODES=10 +CONFIG_BLE_MESH_MAX_STORED_NODES=10 +CONFIG_BLE_MESH_PBA_SAME_TIME=1 +CONFIG_BLE_MESH_PBG_SAME_TIME=1 +CONFIG_BLE_MESH_PROVISIONER_SUBNET_COUNT=3 +CONFIG_BLE_MESH_PROVISIONER_APP_KEY_COUNT=3 +CONFIG_BLE_MESH_PB_ADV=y +CONFIG_BLE_MESH_NET_BUF_POOL_USAGE=y +CONFIG_BLE_MESH_PB_GATT=y +CONFIG_BLE_MESH_GATT_PROXY=y +CONFIG_BLE_MESH_RELAY=y +CONFIG_BLE_MESH_LOW_POWER= +CONFIG_BLE_MESH_FRIEND= CONFIG_BTU_TASK_STACK_SIZE=4512 -CONFIG_BT_MESH_CFG_CLI=y -CONFIG_BT_MESH_GENERIC_ONOFF_CLI=y -CONFIG_BT_MESH_ADV_BUF_COUNT=100 -CONFIG_BT_MESH_CRPL=10 -CONFIG_BT_MESH_TX_SEG_MSG_COUNT=10 -CONFIG_BT_MESH_RX_SEG_MSG_COUNT=10 -CONFIG_BT_MESH_NO_LOG=n -CONFIG_BT_MESH_STACK_INITIAL_TRACE_LEVEL=1 \ No newline at end of file +CONFIG_BLE_MESH_CFG_CLI=y +CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y +CONFIG_BLE_MESH_ADV_BUF_COUNT=100 +CONFIG_BLE_MESH_CRPL=10 +CONFIG_BLE_MESH_TX_SEG_MSG_COUNT=10 +CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=10 +CONFIG_BLE_MESH_NO_LOG=n +CONFIG_BLE_MESH_STACK_TRACE_LEVEL=1 \ No newline at end of file diff --git a/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/CMakeLists.txt b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/CMakeLists.txt new file mode 100644 index 0000000000..594effdbb8 --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/CMakeLists.txt @@ -0,0 +1,8 @@ +# The following lines of boilerplate have to be in your project's CMakeLists +# in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(ble_mesh_fast_prov_server) diff --git a/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/Makefile b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/Makefile index 1eb2b69638..f6ece484ac 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/Makefile +++ b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/Makefile @@ -3,10 +3,10 @@ # project subdirectory. # -PROJECT_NAME := bt_mesh_fast_prov_server +PROJECT_NAME := ble_mesh_fast_prov_server COMPONENT_ADD_INCLUDEDIRS := components/include -EXTRA_COMPONENT_DIRS := $(IDF_PATH)/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model +EXTRA_COMPONENT_DIRS := $(IDF_PATH)/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components include $(IDF_PATH)/make/project.mk diff --git a/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/main/CMakeLists.txt b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/main/CMakeLists.txt new file mode 100644 index 0000000000..1eb2d87ed2 --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/main/CMakeLists.txt @@ -0,0 +1,6 @@ +set(COMPONENT_SRCS "ble_mesh_demo_main.c" + "board.c") + +set(COMPONENT_ADD_INCLUDEDIRS ".") + +register_component() diff --git a/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/main/Kconfig.projbuild b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/main/Kconfig.projbuild index b9ace4e0d1..aa8b9f3687 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/main/Kconfig.projbuild +++ b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/main/Kconfig.projbuild @@ -1,15 +1,22 @@ -menu "Example 'BLE Mesh' Config" +menu "Example Configuration" -config ESP_WROOM_32_BOARD - bool "If used the ESP32-DevKitC board this macro set to true, if used the ESP-WROVER-KIT board this macro should set to false" - default n - help - this marco only affect the LED pin set with the different board. + choice ESP32_BOARD + prompt "Board selection for BLE Mesh" + default ESP_WROOM_32_BOARD + help + Select this option to choose the board for BLE Mesh. The default is ESP32-WROOM-32 -config HCI_5_0_VERSION - bool "If you need to send 20ms non-connectable advertising packets but BLE controller is not HCI 5.0, this macro set to true." - default y - help - it is a temporal solution, need further modification. + config ESP_WROOM_32_BOARD + bool "ESP32-WROOM-32" + + config ESP_WROVER_BOARD + bool "ESP32-WROVER" + endchoice + + config HCI_5_0_VERSION + bool "Support sending 20ms non-connectable advertising packets" + default y + help + It is a temporary solution and needs further modifications. endmenu diff --git a/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/main/ble_mesh_demo_main.c b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/main/ble_mesh_demo_main.c index d1ccf4ff9a..39ca5cb9e3 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/main/ble_mesh_demo_main.c +++ b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/main/ble_mesh_demo_main.c @@ -38,7 +38,7 @@ extern struct _led_state led_state[3]; extern struct k_delayed_work send_self_prov_node_addr_timer; -extern atomic_t fast_prov_cli_flags; +extern bt_mesh_atomic_t fast_prov_cli_flags; static uint8_t dev_uuid[16] = { 0xdd, 0xdd }; static uint8_t prov_start_num = 0; @@ -58,12 +58,12 @@ esp_ble_mesh_client_t config_client; esp_ble_mesh_cfg_srv_t config_server = { .relay = ESP_BLE_MESH_RELAY_ENABLED, .beacon = ESP_BLE_MESH_BEACON_DISABLED, -#if defined(CONFIG_BT_MESH_FRIEND) +#if defined(CONFIG_BLE_MESH_FRIEND) .friend_state = ESP_BLE_MESH_FRIEND_ENABLED, #else .friend_state = ESP_BLE_MESH_FRIEND_NOT_SUPPORTED, #endif -#if defined(CONFIG_BT_MESH_GATT_PROXY) +#if defined(CONFIG_BLE_MESH_GATT_PROXY) .gatt_proxy = ESP_BLE_MESH_GATT_PROXY_ENABLED, #else .gatt_proxy = ESP_BLE_MESH_GATT_PROXY_NOT_SUPPORTED, @@ -192,7 +192,7 @@ static void gen_onoff_get_handler(esp_ble_mesh_model_t *model, /* When the node receives the first Generic OnOff Get/Set/Set Unack message, it will * start the timer used to disable fast provisioning functionality. */ - if (!atomic_test_and_set_bit(fast_prov_server.srv_flags, DISABLE_FAST_PROV_START)) { + if (!bt_mesh_atomic_test_and_set_bit(fast_prov_server.srv_flags, DISABLE_FAST_PROV_START)) { k_delayed_work_submit(&fast_prov_server.disable_fast_prov_timer, DISABLE_FAST_PROV_TIMEOUT); } } @@ -220,7 +220,7 @@ static void gen_onoff_set_unack_handler(esp_ble_mesh_model_t *model, /* When the node receives the first Generic OnOff Get/Set/Set Unack message, it will * start the timer used to disable fast provisioning functionality. */ - if (!atomic_test_and_set_bit(fast_prov_server.srv_flags, DISABLE_FAST_PROV_START)) { + if (!bt_mesh_atomic_test_and_set_bit(fast_prov_server.srv_flags, DISABLE_FAST_PROV_START)) { k_delayed_work_submit(&fast_prov_server.disable_fast_prov_timer, DISABLE_FAST_PROV_TIMEOUT); } } @@ -296,10 +296,10 @@ static void provisioner_prov_complete(int node_idx, const uint8_t uuid[16], uint return; } if (fast_prov_server.node_addr_cnt <= fast_prov_server.max_node_num) { - if (atomic_test_and_clear_bit(fast_prov_server.srv_flags, SEND_ALL_NODE_ADDR_START)) { + if (bt_mesh_atomic_test_and_clear_bit(fast_prov_server.srv_flags, SEND_ALL_NODE_ADDR_START)) { k_delayed_work_cancel(&fast_prov_server.send_all_node_addr_timer); } - if (!atomic_test_and_set_bit(fast_prov_server.srv_flags, SEND_ALL_NODE_ADDR_START)) { + if (!bt_mesh_atomic_test_and_set_bit(fast_prov_server.srv_flags, SEND_ALL_NODE_ADDR_START)) { k_delayed_work_submit(&fast_prov_server.send_all_node_addr_timer, SEND_ALL_NODE_ADDR_TIMEOUT); } } @@ -307,15 +307,15 @@ static void provisioner_prov_complete(int node_idx, const uint8_t uuid[16], uint /* When a device is provisioned, the non-primary Provisioner shall reset the timer * which is used to send node addresses to the primary Provisioner. */ - if (atomic_test_and_clear_bit(&fast_prov_cli_flags, SEND_SELF_PROV_NODE_ADDR_START)) { + if (bt_mesh_atomic_test_and_clear_bit(&fast_prov_cli_flags, SEND_SELF_PROV_NODE_ADDR_START)) { k_delayed_work_cancel(&send_self_prov_node_addr_timer); } - if (!atomic_test_and_set_bit(&fast_prov_cli_flags, SEND_SELF_PROV_NODE_ADDR_START)) { + if (!bt_mesh_atomic_test_and_set_bit(&fast_prov_cli_flags, SEND_SELF_PROV_NODE_ADDR_START)) { k_delayed_work_submit(&send_self_prov_node_addr_timer, SEND_SELF_PROV_NODE_ADDR_TIMEOUT); } } - if (atomic_test_bit(fast_prov_server.srv_flags, DISABLE_FAST_PROV_START)) { + if (bt_mesh_atomic_test_bit(fast_prov_server.srv_flags, DISABLE_FAST_PROV_START)) { /* When a device is provisioned, and the stop_prov flag of the Provisioner has been * set, the Provisioner shall reset the timer which is used to stop the provisioner * functionality. diff --git a/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/sdkconfig.defaults b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/sdkconfig.defaults index 96d927b74a..6f6dd42d95 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/sdkconfig.defaults +++ b/examples/bluetooth/ble_mesh/ble_mesh_fast_provision/ble_mesh_fast_prov_server/sdkconfig.defaults @@ -8,32 +8,32 @@ CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_GATTS_ENABLE=y CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL=y -CONFIG_BT_MESH=y -CONFIG_BT_MESH_USE_DUPLICATE_SCAN=y -CONFIG_BT_MESH_FAST_PROV=y -CONFIG_BT_MESH_PROV=y -CONFIG_BT_MESH_NODE=y -CONFIG_BT_MESH_PROVISIONER=y -CONFIG_BT_MESH_UNPROV_DEV_ADD=20 -CONFIG_BT_MESH_MAX_STORED_NODES=10 -CONFIG_BT_MESH_MAX_PROV_NODES=6 -CONFIG_BT_MESH_PBA_SAME_TIME=3 -CONFIG_BT_MESH_PBG_SAME_TIME=3 -CONFIG_BT_MESH_PROVISIONER_SUBNET_COUNT=3 -CONFIG_BT_MESH_PROVISIONER_APP_KEY_COUNT=9 -CONFIG_BT_MESH_PB_ADV=y -CONFIG_NET_BUF_POOL_USAGE=y -CONFIG_BT_MESH_PB_GATT=y -CONFIG_BT_MESH_GATT_PROXY=y -CONFIG_BT_MESH_RELAY=y -CONFIG_BT_MESH_LOW_POWER= -CONFIG_BT_MESH_FRIEND= +CONFIG_BLE_MESH=y +CONFIG_BLE_MESH_USE_DUPLICATE_SCAN=y +CONFIG_BLE_MESH_FAST_PROV=y +CONFIG_BLE_MESH_PROV=y +CONFIG_BLE_MESH_NODE=y +CONFIG_BLE_MESH_PROVISIONER=y +CONFIG_BLE_MESH_WAIT_FOR_PROV_MAX_DEV_NUM=20 +CONFIG_BLE_MESH_MAX_STORED_NODES=10 +CONFIG_BLE_MESH_MAX_PROV_NODES=6 +CONFIG_BLE_MESH_PBA_SAME_TIME=3 +CONFIG_BLE_MESH_PBG_SAME_TIME=3 +CONFIG_BLE_MESH_PROVISIONER_SUBNET_COUNT=3 +CONFIG_BLE_MESH_PROVISIONER_APP_KEY_COUNT=9 +CONFIG_BLE_MESH_PB_ADV=y +CONFIG_BLE_MESH_NET_BUF_POOL_USAGE=y +CONFIG_BLE_MESH_PB_GATT=y +CONFIG_BLE_MESH_GATT_PROXY=y +CONFIG_BLE_MESH_RELAY=y +CONFIG_BLE_MESH_LOW_POWER= +CONFIG_BLE_MESH_FRIEND= CONFIG_BTU_TASK_STACK_SIZE=4512 -CONFIG_BT_MESH_CFG_CLI=y -CONFIG_BT_MESH_CRPL=60 -CONFIG_BT_MESH_MSG_CACHE_SIZE=60 -CONFIG_BT_MESH_ADV_BUF_COUNT=200 -CONFIG_BT_MESH_TX_SEG_MSG_COUNT=10 -CONFIG_BT_MESH_RX_SEG_MSG_COUNT=10 -CONFIG_BT_MESH_NO_LOG=n -CONFIG_BT_MESH_STACK_INITIAL_TRACE_LEVEL=0 \ No newline at end of file +CONFIG_BLE_MESH_CFG_CLI=y +CONFIG_BLE_MESH_CRPL=60 +CONFIG_BLE_MESH_MSG_CACHE_SIZE=60 +CONFIG_BLE_MESH_ADV_BUF_COUNT=200 +CONFIG_BLE_MESH_TX_SEG_MSG_COUNT=10 +CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=10 +CONFIG_BLE_MESH_NO_LOG=n +CONFIG_BLE_MESH_STACK_TRACE_LEVEL=0 \ No newline at end of file diff --git a/examples/bluetooth/ble_mesh/ble_mesh_node/CMakeLists.txt b/examples/bluetooth/ble_mesh/ble_mesh_node/CMakeLists.txt new file mode 100644 index 0000000000..d8b91b1efc --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_node/CMakeLists.txt @@ -0,0 +1,6 @@ +# The following lines of boilerplate have to be in your project's CMakeLists +# in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(ble_mesh_node) diff --git a/examples/bluetooth/ble_mesh/ble_mesh_node/main/CMakeLists.txt b/examples/bluetooth/ble_mesh/ble_mesh_node/main/CMakeLists.txt new file mode 100644 index 0000000000..1eb2d87ed2 --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_node/main/CMakeLists.txt @@ -0,0 +1,6 @@ +set(COMPONENT_SRCS "ble_mesh_demo_main.c" + "board.c") + +set(COMPONENT_ADD_INCLUDEDIRS ".") + +register_component() diff --git a/examples/bluetooth/ble_mesh/ble_mesh_node/main/Kconfig.projbuild b/examples/bluetooth/ble_mesh/ble_mesh_node/main/Kconfig.projbuild index d223968606..9cc80d069a 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_node/main/Kconfig.projbuild +++ b/examples/bluetooth/ble_mesh/ble_mesh_node/main/Kconfig.projbuild @@ -1,30 +1,28 @@ - menu "Example Configuration" -choice ESP32_BOARD - prompt "Board selection for BLE Mesh" - default ESP_WROOM_32_BOARD - help - Select this option to choose the board for BLE Mesh. The default is ESP32-WROOM-32 + choice ESP32_BOARD + prompt "Board selection for BLE Mesh" + default ESP_WROOM_32_BOARD + help + Select this option to choose the board for BLE Mesh. The default is ESP32-WROOM-32 -config ESP_WROOM_32_BOARD - bool "ESP32-WROOM-32" + config ESP_WROOM_32_BOARD + bool "ESP32-WROOM-32" -config ESP_WROVER_BOARD - bool "ESP32-WROVER" + config ESP_WROVER_BOARD + bool "ESP32-WROVER" + endchoice -endchoice + config HCI_5_0_VERSION + bool "Support sending 20ms non-connectable advertising packets" + default y + help + It is a temporary solution and needs further modifications. -config HCI_5_0_VERSION - bool "This option facilitates sending with 20ms non-connectable interval even if the controller is not HCI 5.0" - default y - help - It is a temporary solution and needs further modifications - -config PATCH_FOR_SILICONLAB_APP_1_1_0 - bool "This option fixes the bug of Silicon Lab Android App 1.1.0 when reconnection will cause the sequence number to recount from 0" - default y - help - It is an ad hoc solution and needs further modifications + config PATCH_FOR_SILICONLAB_APP_1_1_0 + bool "Fix bug of Silicon Lab Android App v1.1.0 when reconnection will cause sequence number to recount from 0" + default y + help + It is an ad hoc solution and needs further modifications endmenu diff --git a/examples/bluetooth/ble_mesh/ble_mesh_node/main/ble_mesh_demo_main.c b/examples/bluetooth/ble_mesh/ble_mesh_node/main/ble_mesh_demo_main.c index 396aeab56d..2e8297f9ee 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_node/main/ble_mesh_demo_main.c +++ b/examples/bluetooth/ble_mesh/ble_mesh_node/main/ble_mesh_demo_main.c @@ -36,12 +36,12 @@ static uint8_t dev_uuid[16] = { 0xdd, 0xdd }; static esp_ble_mesh_cfg_srv_t config_server = { .relay = ESP_BLE_MESH_RELAY_DISABLED, .beacon = ESP_BLE_MESH_BEACON_ENABLED, -#if defined(CONFIG_BT_MESH_FRIEND) +#if defined(CONFIG_BLE_MESH_FRIEND) .friend_state = ESP_BLE_MESH_FRIEND_ENABLED, #else .friend_state = ESP_BLE_MESH_FRIEND_NOT_SUPPORTED, #endif -#if defined(CONFIG_BT_MESH_GATT_PROXY) +#if defined(CONFIG_BLE_MESH_GATT_PROXY) .gatt_proxy = ESP_BLE_MESH_GATT_PROXY_ENABLED, #else .gatt_proxy = ESP_BLE_MESH_GATT_PROXY_NOT_SUPPORTED, diff --git a/examples/bluetooth/ble_mesh/ble_mesh_node/sdkconfig.defaults b/examples/bluetooth/ble_mesh/ble_mesh_node/sdkconfig.defaults index 38cf86cd21..f0031b8e07 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_node/sdkconfig.defaults +++ b/examples/bluetooth/ble_mesh/ble_mesh_node/sdkconfig.defaults @@ -8,30 +8,29 @@ CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_GATTS_ENABLE=y CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL=y -CONFIG_BT_MESH=y -CONFIG_BT_MESH_USE_DUPLICATE_SCAN=y -CONFIG_BT_MESH_NODE=y -CONFIG_BT_MESH_PROV=y -CONFIG_NET_BUF_POOL_USAGE=y -CONFIG_BT_MESH_PROXY=y -CONFIG_BT_MESH_PB_GATT=y -CONFIG_BT_MESH_GATT_PROXY=y -CONFIG_BT_MESH_NODE_ID_TIMEOUT=60 -CONFIG_BT_MESH_PROXY_FILTER_SIZE=1 -CONFIG_BT_MESH_SUBNET_COUNT=1 -CONFIG_BT_MESH_APP_KEY_COUNT=1 -CONFIG_BT_MESH_MODEL_KEY_COUNT=1 -CONFIG_BT_MESH_MODEL_GROUP_COUNT=1 -CONFIG_BT_MESH_LABEL_COUNT=1 -CONFIG_BT_MESH_CRPL=10 -CONFIG_BT_MESH_MSG_CACHE_SIZE=10 -CONFIG_BT_MESH_ADV_BUF_COUNT=20 -CONFIG_BT_MESH_TX_SEG_MSG_COUNT=6 -CONFIG_BT_MESH_RX_SEG_MSG_COUNT=1 -CONFIG_BT_MESH_RX_SDU_MAX=384 -CONFIG_BT_MESH_RELAY=y -CONFIG_BT_MESH_LOW_POWER= -CONFIG_BT_MESH_FRIEND= -CONFIG_BT_MESH_CFG_CLI=y -CONFIG_BT_MESH_HEALTH_CLI=y +CONFIG_BLE_MESH=y +CONFIG_BLE_MESH_USE_DUPLICATE_SCAN=y +CONFIG_BLE_MESH_NODE=y +CONFIG_BLE_MESH_PROV=y +CONFIG_BLE_MESH_NET_BUF_POOL_USAGE=y +CONFIG_BLE_MESH_PROXY=y +CONFIG_BLE_MESH_PB_GATT=y +CONFIG_BLE_MESH_GATT_PROXY=y +CONFIG_BLE_MESH_NODE_ID_TIMEOUT=60 +CONFIG_BLE_MESH_PROXY_FILTER_SIZE=1 +CONFIG_BLE_MESH_SUBNET_COUNT=1 +CONFIG_BLE_MESH_APP_KEY_COUNT=1 +CONFIG_BLE_MESH_MODEL_KEY_COUNT=1 +CONFIG_BLE_MESH_MODEL_GROUP_COUNT=1 +CONFIG_BLE_MESH_LABEL_COUNT=1 +CONFIG_BLE_MESH_CRPL=10 +CONFIG_BLE_MESH_MSG_CACHE_SIZE=10 +CONFIG_BLE_MESH_ADV_BUF_COUNT=20 +CONFIG_BLE_MESH_TX_SEG_MSG_COUNT=6 +CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=1 +CONFIG_BLE_MESH_RX_SDU_MAX=384 +CONFIG_BLE_MESH_RELAY=y +CONFIG_BLE_MESH_LOW_POWER= +CONFIG_BLE_MESH_FRIEND= +CONFIG_BLE_MESH_CFG_CLI=y CONFIG_BTU_TASK_STACK_SIZE=4512 \ No newline at end of file diff --git a/examples/bluetooth/ble_mesh/ble_mesh_node/tutorial/Ble_Mesh_Node_Example_Walkthrough.md b/examples/bluetooth/ble_mesh/ble_mesh_node/tutorial/Ble_Mesh_Node_Example_Walkthrough.md index b1aa47285b..639d10de3f 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_node/tutorial/Ble_Mesh_Node_Example_Walkthrough.md +++ b/examples/bluetooth/ble_mesh/ble_mesh_node/tutorial/Ble_Mesh_Node_Example_Walkthrough.md @@ -241,10 +241,10 @@ struct esp_ble_mesh_model { esp_ble_mesh_model_pub_t *const pub; /* AppKey List */ - uint16_t keys[CONFIG_BT_MESH_MODEL_KEY_COUNT]; + uint16_t keys[CONFIG_BLE_MESH_MODEL_KEY_COUNT]; /* Subscription List (group or virtual addresses) */ - uint16_t groups[CONFIG_BT_MESH_MODEL_GROUP_COUNT]; + uint16_t groups[CONFIG_BLE_MESH_MODEL_GROUP_COUNT]; /* Model operation context */ esp_ble_mesh_model_op_t *op; diff --git a/examples/bluetooth/ble_mesh/ble_mesh_provisioner/CMakeLists.txt b/examples/bluetooth/ble_mesh/ble_mesh_provisioner/CMakeLists.txt new file mode 100644 index 0000000000..dfffbf786f --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_provisioner/CMakeLists.txt @@ -0,0 +1,6 @@ +# The following lines of boilerplate have to be in your project's CMakeLists +# in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(ble_mesh_provisioner) diff --git a/examples/bluetooth/ble_mesh/ble_mesh_provisioner/Makefile b/examples/bluetooth/ble_mesh/ble_mesh_provisioner/Makefile index 6152826c50..bceab36a3e 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_provisioner/Makefile +++ b/examples/bluetooth/ble_mesh/ble_mesh_provisioner/Makefile @@ -3,7 +3,7 @@ # project subdirectory. # -PROJECT_NAME := bt_mesh_provisioner +PROJECT_NAME := ble_mesh_provisioner COMPONENT_ADD_INCLUDEDIRS := components/include diff --git a/examples/bluetooth/ble_mesh/ble_mesh_provisioner/main/CMakeLists.txt b/examples/bluetooth/ble_mesh/ble_mesh_provisioner/main/CMakeLists.txt new file mode 100644 index 0000000000..3d3bc6f9a5 --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_provisioner/main/CMakeLists.txt @@ -0,0 +1,5 @@ +set(COMPONENT_SRCS "ble_mesh_demo_main.c") + +set(COMPONENT_ADD_INCLUDEDIRS ".") + +register_component() diff --git a/examples/bluetooth/ble_mesh/ble_mesh_provisioner/main/Kconfig.projbuild b/examples/bluetooth/ble_mesh/ble_mesh_provisioner/main/Kconfig.projbuild index acca212403..eb3de7ae00 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_provisioner/main/Kconfig.projbuild +++ b/examples/bluetooth/ble_mesh/ble_mesh_provisioner/main/Kconfig.projbuild @@ -1,24 +1,9 @@ - menu "Example Configuration" -choice ESP32_BOARD - prompt "Board selection for BLE Mesh" - default ESP_WROOM_32_BOARD - help - Select this option to choose the board for BLE Mesh. The default is ESP32-WROOM-32 - -config ESP_WROOM_32_BOARD - bool "ESP32-WROOM-32" - -config ESP_WROVER_BOARD - bool "ESP32-WROVER" - -endchoice - -config HCI_5_0_VERSION - bool "This option facilitates sending with 20ms non-connectable interval even if the controller is not HCI 5.0" - default y - help - It is a temporary solution and needs further modifications + config HCI_5_0_VERSION + bool "Support sending 20ms non-connectable advertising packets" + default y + help + It is a temporary solution and needs further modifications. endmenu diff --git a/examples/bluetooth/ble_mesh/ble_mesh_provisioner/main/ble_mesh_demo_main.c b/examples/bluetooth/ble_mesh/ble_mesh_provisioner/main/ble_mesh_demo_main.c index 7d204bd07b..7f3ddeb405 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_provisioner/main/ble_mesh_demo_main.c +++ b/examples/bluetooth/ble_mesh/ble_mesh_provisioner/main/ble_mesh_demo_main.c @@ -23,24 +23,25 @@ #include "esp_ble_mesh_config_model_api.h" #include "esp_ble_mesh_generic_model_api.h" -#include "board.h" - #define TAG "ble_mesh_provisioner" -#define CID_ESP 0x02E5 -#define CID_NVAL 0xFFFF +#define LED_OFF 0x0 +#define LED_ON 0x1 -#define PROVISIONER_OWN_ADDR 0x0001 +#define CID_ESP 0x02E5 +#define CID_NVAL 0xFFFF -#define MSG_SEND_TTL 3 -#define MSG_SEND_REL false -#define MSG_TIMEOUT 0 -#define MSG_ROLE ROLE_PROVISIONER +#define PROV_OWN_ADDR 0x0001 -#define COMPOSITION_DATA_PAGE_0 0x00 +#define MSG_SEND_TTL 3 +#define MSG_SEND_REL false +#define MSG_TIMEOUT 0 +#define MSG_ROLE ROLE_PROVISIONER -#define ESP_BLE_MESH_APP_IDX 0x0000 -#define APP_KEY_OCTET 0x12 +#define COMP_DATA_PAGE_0 0x00 + +#define APP_KEY_IDX 0x0000 +#define APP_KEY_OCTET 0x12 static uint8_t dev_uuid[16]; @@ -51,8 +52,8 @@ typedef struct { uint8_t onoff; } esp_ble_mesh_node_info_t; -static esp_ble_mesh_node_info_t nodes[CONFIG_BT_MESH_MAX_PROV_NODES] = { - [0 ... (CONFIG_BT_MESH_MAX_PROV_NODES - 1)] = { +static esp_ble_mesh_node_info_t nodes[CONFIG_BLE_MESH_MAX_PROV_NODES] = { + [0 ... (CONFIG_BLE_MESH_MAX_PROV_NODES - 1)] = { .unicast = ESP_BLE_MESH_ADDR_UNASSIGNED, .elem_num = 0, .onoff = LED_OFF, @@ -71,12 +72,12 @@ static esp_ble_mesh_client_t onoff_client; static esp_ble_mesh_cfg_srv_t config_server = { .relay = ESP_BLE_MESH_RELAY_DISABLED, .beacon = ESP_BLE_MESH_BEACON_ENABLED, -#if defined(CONFIG_BT_MESH_FRIEND) +#if defined(CONFIG_BLE_MESH_FRIEND) .friend_state = ESP_BLE_MESH_FRIEND_ENABLED, #else .friend_state = ESP_BLE_MESH_FRIEND_NOT_SUPPORTED, #endif -#if defined(CONFIG_BT_MESH_GATT_PROXY) +#if defined(CONFIG_BLE_MESH_GATT_PROXY) .gatt_proxy = ESP_BLE_MESH_GATT_PROXY_ENABLED, #else .gatt_proxy = ESP_BLE_MESH_GATT_PROXY_NOT_SUPPORTED, @@ -105,7 +106,7 @@ static esp_ble_mesh_comp_t composition = { static esp_ble_mesh_prov_t provision = { .prov_uuid = dev_uuid, - .prov_unicast_addr = PROVISIONER_OWN_ADDR, + .prov_unicast_addr = PROV_OWN_ADDR, .prov_start_address = 0x0005, .prov_attention = 0x00, .prov_algorithm = 0x00, @@ -221,7 +222,7 @@ static esp_err_t prov_complete(int node_idx, const esp_ble_mesh_octet16_t uuid, } esp_ble_mesh_set_msg_common(&common, node, config_client.model, ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET); - get_state.comp_data_get.page = COMPOSITION_DATA_PAGE_0; + get_state.comp_data_get.page = COMP_DATA_PAGE_0; err = esp_ble_mesh_config_client_get_state(&common, &get_state); if (err) { ESP_LOGE(TAG, "%s: Send config comp data get failed", __func__); @@ -325,7 +326,7 @@ static void esp_ble_mesh_prov_cb(esp_ble_mesh_prov_cb_event_t event, if (param->provisioner_add_app_key_comp.err_code == ESP_OK) { esp_err_t err = 0; prov_key.app_idx = param->provisioner_add_app_key_comp.app_idx; - err = esp_ble_mesh_provisioner_bind_app_key_to_local_model(PROVISIONER_OWN_ADDR, prov_key.app_idx, + err = esp_ble_mesh_provisioner_bind_app_key_to_local_model(PROV_OWN_ADDR, prov_key.app_idx, ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_CLI, CID_NVAL); if (err != ESP_OK) { ESP_LOGE(TAG, "Provisioner bind local model appkey failed"); @@ -454,7 +455,7 @@ static void esp_ble_mesh_config_client_cb(esp_ble_mesh_cfg_client_cb_event_t eve case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET: { esp_ble_mesh_cfg_client_get_state_t get_state = {0}; esp_ble_mesh_set_msg_common(&common, node, config_client.model, ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET); - get_state.comp_data_get.page = COMPOSITION_DATA_PAGE_0; + get_state.comp_data_get.page = COMP_DATA_PAGE_0; err = esp_ble_mesh_config_client_get_state(&common, &get_state); if (err) { ESP_LOGE(TAG, "%s: Config Composition Data Get failed", __func__); @@ -604,7 +605,7 @@ static int ble_mesh_init(void) int err = 0; prov_key.net_idx = ESP_BLE_MESH_KEY_PRIMARY; - prov_key.app_idx = ESP_BLE_MESH_APP_IDX; + prov_key.app_idx = APP_KEY_IDX; memset(prov_key.app_key, APP_KEY_OCTET, sizeof(prov_key.app_key)); memcpy(dev_uuid, esp_bt_dev_get_address(), ESP_BD_ADDR_LEN); @@ -676,8 +677,6 @@ void app_main(void) ESP_LOGI(TAG, "Initializing..."); - board_init(); - err = bluetooth_init(); if (err) { ESP_LOGE(TAG, "esp32_bluetooth_init failed (err %d)", err); diff --git a/examples/bluetooth/ble_mesh/ble_mesh_provisioner/main/board.c b/examples/bluetooth/ble_mesh/ble_mesh_provisioner/main/board.c deleted file mode 100644 index 57ccfda1a7..0000000000 --- a/examples/bluetooth/ble_mesh/ble_mesh_provisioner/main/board.c +++ /dev/null @@ -1,128 +0,0 @@ -/* board.c - Board-specific hooks */ - -/* - * Copyright (c) 2017 Intel Corporation - * Additional Copyright (c) 2018 Espressif Systems (Shanghai) PTE LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include "freertos/FreeRTOS.h" -#include "freertos/task.h" -#include "freertos/event_groups.h" - -#include "driver/gpio.h" -#include "esp_log.h" -#include "board.h" - -#define TAG "BOARD" - -#define INTR_FLAG_DEFAULT 0 - -static xQueueHandle s_evt_queue; -static struct _led_state led_state[3] = { - { LED_OFF, LED_OFF, LED_R, "red" }, - { LED_OFF, LED_OFF, LED_G, "green" }, - { LED_OFF, LED_OFF, LED_B, "blue" }, -}; - -void board_output_number(esp_ble_mesh_output_action_t action, uint32_t number) -{ - ESP_LOGI(TAG, "Board output number %d", number); -} - -void board_prov_complete(void) -{ - board_led_operation(LED_G, LED_OFF); -} - -void board_led_operation(uint8_t pin, uint8_t onoff) -{ - for (int i = 0; i < 3; i++) { - if (led_state[i].pin != pin) { - continue; - } - if (onoff == led_state[i].previous) { - ESP_LOGW(TAG, "led %s is already %s", - led_state[i].name, (onoff ? "on" : "off")); - return; - } - gpio_set_level(pin, onoff); - led_state[i].previous = onoff; - return; - } - - ESP_LOGE(TAG, "LED is not found!"); -} - -static void board_led_init(void) -{ - for (int i = 0; i < 3; i++) { - gpio_pad_select_gpio(led_state[i].pin); - gpio_set_direction(led_state[i].pin, GPIO_MODE_OUTPUT); - gpio_set_level(led_state[i].pin, LED_OFF); - led_state[i].previous = LED_OFF; - } -} - -static void IRAM_ATTR switch_isr_handler(void *arg) -{ - uint32_t gpio_num = (uint32_t) arg; - xQueueSendFromISR(s_evt_queue, &gpio_num, NULL); -} - -static void switch_key_init(uint32_t key) -{ - gpio_config_t io_conf; - io_conf.intr_type = GPIO_INTR_NEGEDGE; - io_conf.pin_bit_mask = 1 << key; - io_conf.mode = GPIO_MODE_INPUT; - io_conf.pull_up_en = 1; - io_conf.pull_down_en = 0; - gpio_config(&io_conf); - - gpio_set_intr_type(key, GPIO_INTR_NEGEDGE); - gpio_install_isr_service(INTR_FLAG_DEFAULT); - gpio_isr_handler_add(key, switch_isr_handler, (void *)key); -} - -static void switch_task_entry(void *arg) -{ - while (1) { - uint32_t io_num; - if (xQueueReceive(s_evt_queue, &io_num, portMAX_DELAY) == pdTRUE) { - uint8_t onoff = led_state[0].previous; - ESP_LOGI(TAG, "GPIO[%d] intr, val: %d", io_num, gpio_get_level(io_num)); - board_led_operation(LED_R, !onoff); - led_state[0].previous = !onoff; - //TODO: publish state change message - } - } -} - -static void switch_init(gpio_num_t gpio_num) -{ - s_evt_queue = xQueueCreate(3, sizeof(uint32_t)); - if (!s_evt_queue) { - return; - } - - BaseType_t ret = xTaskCreate(switch_task_entry, "switch", 4096, NULL, 4, NULL); - if (ret == pdFAIL) { - goto fail; - } - - switch_key_init(gpio_num); - return; - -fail: - vQueueDelete(s_evt_queue); -} - -void board_init(void) -{ - board_led_init(); - switch_init(GPIO_NUM_18); -} diff --git a/examples/bluetooth/ble_mesh/ble_mesh_provisioner/main/board.h b/examples/bluetooth/ble_mesh/ble_mesh_provisioner/main/board.h deleted file mode 100644 index c30626a997..0000000000 --- a/examples/bluetooth/ble_mesh/ble_mesh_provisioner/main/board.h +++ /dev/null @@ -1,41 +0,0 @@ -/* board.h - Board-specific hooks */ - -/* - * Copyright (c) 2017 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ -#ifndef _BOARD_H_ -#define _BOARD_H_ - -#include "esp_ble_mesh_defs.h" - -#if defined(CONFIG_ESP_WROOM_32_BOARD) -#define LED_R GPIO_NUM_25 -#define LED_G GPIO_NUM_26 -#define LED_B GPIO_NUM_27 -#elif defined(CONFIG_ESP_WROVER_BOARD) -#define LED_R GPIO_NUM_0 -#define LED_G GPIO_NUM_2 -#define LED_B GPIO_NUM_4 -#endif - -#define LED_ON 1 -#define LED_OFF 0 - -struct _led_state { - uint8_t current; - uint8_t previous; - uint8_t pin; - char *name; -}; - -void board_output_number(esp_ble_mesh_output_action_t action, uint32_t number); - -void board_prov_complete(void); - -void board_led_operation(uint8_t pin, uint8_t onoff); - -void board_init(void); - -#endif diff --git a/examples/bluetooth/ble_mesh/ble_mesh_provisioner/sdkconfig.defaults b/examples/bluetooth/ble_mesh/ble_mesh_provisioner/sdkconfig.defaults index e485d01284..2b5c4a37de 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_provisioner/sdkconfig.defaults +++ b/examples/bluetooth/ble_mesh/ble_mesh_provisioner/sdkconfig.defaults @@ -6,27 +6,26 @@ CONFIG_SCAN_DUPLICATE_TYPE=2 CONFIG_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 -CONFIG_BT_MESH=y -CONFIG_BT_MESH_USE_DUPLICATE_SCAN=y -CONFIG_BT_MESH_PROV=y -CONFIG_BT_MESH_PROVISIONER=y -CONFIG_BT_MESH_UNPROV_DEV_ADD=10 -CONFIG_BT_MESH_MAX_STORED_NODES=10 -CONFIG_BT_MESH_MAX_PROV_NODES=10 -CONFIG_BT_MESH_PBA_SAME_TIME=3 -CONFIG_BT_MESH_PBG_SAME_TIME=2 -CONFIG_BT_MESH_PROVISIONER_SUBNET_COUNT=3 -CONFIG_BT_MESH_PROVISIONER_APP_KEY_COUNT=3 -CONFIG_BT_MESH_PB_ADV=y -CONFIG_NET_BUF_POOL_USAGE=y -CONFIG_BT_MESH_PB_GATT=y -CONFIG_BT_MESH_GATT_PROXY=y -CONFIG_BT_MESH_RELAY=y -CONFIG_BT_MESH_LOW_POWER= -CONFIG_BT_MESH_FRIEND= -CONFIG_BT_MESH_TX_SEG_MSG_COUNT=6 -CONFIG_BT_MESH_RX_SEG_MSG_COUNT=6 +CONFIG_BLE_MESH=y +CONFIG_BLE_MESH_USE_DUPLICATE_SCAN=y +CONFIG_BLE_MESH_PROV=y +CONFIG_BLE_MESH_PROVISIONER=y +CONFIG_BLE_MESH_WAIT_FOR_PROV_MAX_DEV_NUM=10 +CONFIG_BLE_MESH_MAX_STORED_NODES=10 +CONFIG_BLE_MESH_MAX_PROV_NODES=10 +CONFIG_BLE_MESH_PBA_SAME_TIME=3 +CONFIG_BLE_MESH_PBG_SAME_TIME=2 +CONFIG_BLE_MESH_PROVISIONER_SUBNET_COUNT=3 +CONFIG_BLE_MESH_PROVISIONER_APP_KEY_COUNT=3 +CONFIG_BLE_MESH_PB_ADV=y +CONFIG_BLE_MESH_NET_BUF_POOL_USAGE=y +CONFIG_BLE_MESH_PB_GATT=y +CONFIG_BLE_MESH_GATT_PROXY=y +CONFIG_BLE_MESH_RELAY=y +CONFIG_BLE_MESH_LOW_POWER= +CONFIG_BLE_MESH_FRIEND= +CONFIG_BLE_MESH_TX_SEG_MSG_COUNT=6 +CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=6 CONFIG_BTU_TASK_STACK_SIZE=4512 -CONFIG_BT_MESH_CFG_CLI=y -CONFIG_BT_MESH_HEALTH_CLI=y -CONFIG_BT_MESH_GENERIC_ONOFF_CLI=y \ No newline at end of file +CONFIG_BLE_MESH_CFG_CLI=y +CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y \ No newline at end of file diff --git a/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/CMakeLists.txt b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/CMakeLists.txt new file mode 100644 index 0000000000..cb92f4b374 --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/CMakeLists.txt @@ -0,0 +1,6 @@ +# The following lines of boilerplate have to be in your project's CMakeLists +# in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(fast_prov_vendor_model) diff --git a/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/Makefile b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/Makefile new file mode 100644 index 0000000000..274dd33494 --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/Makefile @@ -0,0 +1,10 @@ +# +# This is a project Makefile. It is assumed the directory this Makefile resides in is a +# project subdirectory. +# + +PROJECT_NAME := fast_prov_vendor_model + +COMPONENT_ADD_INCLUDEDIRS := components/include + +include $(IDF_PATH)/make/project.mk diff --git a/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/component.mk b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/component.mk deleted file mode 100644 index 7c4fb90ccd..0000000000 --- a/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/component.mk +++ /dev/null @@ -1,6 +0,0 @@ -# -# Component Makefile -# -COMPONENT_SRCDIRS := src - -COMPONENT_ADD_INCLUDEDIRS := include \ No newline at end of file diff --git a/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/CMakeLists.txt b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/CMakeLists.txt new file mode 100644 index 0000000000..44699eb00e --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/CMakeLists.txt @@ -0,0 +1,9 @@ +set(COMPONENT_SRCS "esp_fast_prov_client_model.c" + "esp_fast_prov_server_model.c" + "esp_fast_prov_operation.c") + +set(COMPONENT_ADD_INCLUDEDIRS ".") + +set(COMPONENT_REQUIRES bt) + +register_component() diff --git a/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/component.mk b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/component.mk new file mode 100644 index 0000000000..646c890db8 --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/component.mk @@ -0,0 +1,6 @@ +# +# "main" pseudo-component makefile. +# +# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) +# +COMPONENT_ADD_INCLUDEDIRS := . \ No newline at end of file diff --git a/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/src/esp_fast_prov_client_model.c b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_client_model.c similarity index 94% rename from examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/src/esp_fast_prov_client_model.c rename to examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_client_model.c index 51ca0e27c2..2c555eb08c 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/src/esp_fast_prov_client_model.c +++ b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_client_model.c @@ -29,7 +29,7 @@ #define GET_ALL_NODE_ADDR_TIMEOUT K_SECONDS(60) /* Timer used to send Fast Prov All Node Addr Get message */ -#if !defined(CONFIG_BT_MESH_FAST_PROV) +#if !defined(CONFIG_BLE_MESH_FAST_PROV) static struct k_delayed_work get_all_node_addr_timer; #endif @@ -43,7 +43,7 @@ static uint16_t prim_prov_addr; /* Timer used to send self-provisioned node addresses to Primary Provisioner */ struct k_delayed_work send_self_prov_node_addr_timer; -atomic_t fast_prov_cli_flags; +bt_mesh_atomic_t fast_prov_cli_flags; /* Self-provisioned node addresses that are being sent */ typedef struct { @@ -59,7 +59,7 @@ static example_send_prov_node_addr_t node_addr_send = { }; /* Self-provisioned node addresses that have been sent successfully */ -uint16_t addr_already_sent[CONFIG_BT_MESH_MAX_PROV_NODES]; +uint16_t addr_already_sent[CONFIG_BLE_MESH_MAX_PROV_NODES]; static example_fast_prov_server_t *get_fast_prov_srv_user_data(void) { @@ -82,7 +82,7 @@ void example_send_self_prov_node_addr(struct k_work *work) esp_ble_mesh_model_t *model = NULL; int i, j, err; - atomic_test_and_clear_bit(&fast_prov_cli_flags, SEND_SELF_PROV_NODE_ADDR_START); + bt_mesh_atomic_test_and_clear_bit(&fast_prov_cli_flags, SEND_SELF_PROV_NODE_ADDR_START); fast_prov_srv = get_fast_prov_srv_user_data(); if (!fast_prov_srv) { @@ -107,7 +107,7 @@ void example_send_self_prov_node_addr(struct k_work *work) * timeout event comes, we will update the send buffer (node_addr_send). */ net_buf_simple_init(node_addr_send.addr, 0); - for (i = 0; i < CONFIG_BT_MESH_MAX_PROV_NODES; i++) { + for (i = 0; i < CONFIG_BLE_MESH_MAX_PROV_NODES; i++) { uint16_t addr = example_get_node_address(i); if (!ESP_BLE_MESH_ADDR_IS_UNICAST(addr)) { continue; @@ -150,7 +150,7 @@ void example_send_self_prov_node_addr(struct k_work *work) * no other devices will be provisioned and the timer will never start. */ if (node_addr_send.send_succeed == false && node_addr_send.ack_received == false) { - if (!atomic_test_and_set_bit(&fast_prov_cli_flags, SEND_SELF_PROV_NODE_ADDR_START)) { + if (!bt_mesh_atomic_test_and_set_bit(&fast_prov_cli_flags, SEND_SELF_PROV_NODE_ADDR_START)) { k_delayed_work_submit(&send_self_prov_node_addr_timer, SEND_SELF_PROV_NODE_ADDR_TIMEOUT); } } @@ -158,7 +158,7 @@ void example_send_self_prov_node_addr(struct k_work *work) return; } -#if !defined(CONFIG_BT_MESH_FAST_PROV) +#if !defined(CONFIG_BLE_MESH_FAST_PROV) /* Timeout handler for get_all_node_addr_timer */ static void example_get_all_node_addr(struct k_work *work) { @@ -197,7 +197,7 @@ static void example_get_all_node_addr(struct k_work *work) esp_err_t example_fast_prov_client_recv_timeout(uint32_t opcode, esp_ble_mesh_model_t *model, esp_ble_mesh_msg_ctx_t *ctx) { -#if defined(CONFIG_BT_MESH_FAST_PROV) +#if defined(CONFIG_BLE_MESH_FAST_PROV) example_fast_prov_server_t *fast_prov_srv = NULL; #endif example_node_info_t *node = NULL; @@ -209,7 +209,7 @@ esp_err_t example_fast_prov_client_recv_timeout(uint32_t opcode, esp_ble_mesh_mo return ESP_ERR_INVALID_ARG; } -#if defined(CONFIG_BT_MESH_FAST_PROV) +#if defined(CONFIG_BLE_MESH_FAST_PROV) fast_prov_srv = get_fast_prov_srv_user_data(); if (!fast_prov_srv) { ESP_LOGE(TAG, "%s: Failed to get fast prov server model user_data", __func__); @@ -230,7 +230,7 @@ esp_err_t example_fast_prov_client_recv_timeout(uint32_t opcode, esp_ble_mesh_mo .dst = node->unicast_addr, .timeout = 0, }; -#if defined(CONFIG_BT_MESH_FAST_PROV) +#if defined(CONFIG_BLE_MESH_FAST_PROV) if (node->lack_of_addr == false) { set.ctx_flags = 0x03FE; memcpy(&set.unicast_min, &node->unicast_min, @@ -255,7 +255,7 @@ esp_err_t example_fast_prov_client_recv_timeout(uint32_t opcode, esp_ble_mesh_mo } case ESP_BLE_MESH_VND_MODEL_OP_FAST_PROV_NET_KEY_ADD: break; -#if defined(CONFIG_BT_MESH_FAST_PROV) +#if defined(CONFIG_BLE_MESH_FAST_PROV) case ESP_BLE_MESH_VND_MODEL_OP_FAST_PROV_NODE_ADDR: if (node_addr_send.addr->len) { example_msg_common_info_t info = { @@ -275,7 +275,7 @@ esp_err_t example_fast_prov_client_recv_timeout(uint32_t opcode, esp_ble_mesh_mo node_addr_send.ack_received = false; } if (node_addr_send.send_succeed == false && node_addr_send.ack_received == false) { - if (!atomic_test_and_set_bit(&fast_prov_cli_flags, SEND_SELF_PROV_NODE_ADDR_START)) { + if (!bt_mesh_atomic_test_and_set_bit(&fast_prov_cli_flags, SEND_SELF_PROV_NODE_ADDR_START)) { k_delayed_work_submit(&send_self_prov_node_addr_timer, SEND_SELF_PROV_NODE_ADDR_TIMEOUT); } } @@ -320,7 +320,7 @@ esp_err_t example_fast_prov_client_recv_status(esp_ble_mesh_model_t *model, switch (ctx->recv_op) { case ESP_BLE_MESH_VND_MODEL_OP_FAST_PROV_INFO_STATUS: ESP_LOG_BUFFER_HEX("fast prov info status", data, len); -#if !defined(CONFIG_BT_MESH_FAST_PROV) +#if !defined(CONFIG_BLE_MESH_FAST_PROV) prim_prov_addr = ctx->addr; k_delayed_work_init(&get_all_node_addr_timer, example_get_all_node_addr); k_delayed_work_submit(&get_all_node_addr_timer, GET_ALL_NODE_ADDR_TIMEOUT); @@ -362,7 +362,7 @@ esp_err_t example_fast_prov_client_recv_status(esp_ble_mesh_model_t *model, * to receive ack), and the timer for the second or further messages is timeout, * thus the Provisioner will never be able to send other addresses. */ - if (!atomic_test_and_set_bit(&fast_prov_cli_flags, SEND_SELF_PROV_NODE_ADDR_START)) { + if (!bt_mesh_atomic_test_and_set_bit(&fast_prov_cli_flags, SEND_SELF_PROV_NODE_ADDR_START)) { k_delayed_work_submit(&send_self_prov_node_addr_timer, SEND_SELF_PROV_NODE_ADDR_TIMEOUT); } break; diff --git a/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/include/esp_fast_prov_client_model.h b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_client_model.h similarity index 100% rename from examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/include/esp_fast_prov_client_model.h rename to examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_client_model.h diff --git a/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/include/esp_fast_prov_common.h b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_common.h similarity index 100% rename from examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/include/esp_fast_prov_common.h rename to examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_common.h diff --git a/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/src/esp_fast_prov_operation.c b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_operation.c similarity index 99% rename from examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/src/esp_fast_prov_operation.c rename to examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_operation.c index 170c7940d5..d198a5f5be 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/src/esp_fast_prov_operation.c +++ b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_operation.c @@ -29,8 +29,8 @@ #define TAG "FAST_PROV_OP" /* Provisioned node information context */ -static example_node_info_t nodes_info[CONFIG_BT_MESH_MAX_PROV_NODES] = { - [0 ... (CONFIG_BT_MESH_MAX_PROV_NODES - 1)] = { +static example_node_info_t nodes_info[CONFIG_BLE_MESH_MAX_PROV_NODES] = { + [0 ... (CONFIG_BLE_MESH_MAX_PROV_NODES - 1)] = { .reprov = false, .unicast_addr = ESP_BLE_MESH_ADDR_UNASSIGNED, .element_num = 0x0, @@ -306,7 +306,7 @@ esp_err_t example_send_config_appkey_add(esp_ble_mesh_model_t *model, set.app_key_add.app_idx = add_key->app_idx; memcpy(set.app_key_add.app_key, add_key->app_key, 16); } else { -#if defined(CONFIG_BT_MESH_FAST_PROV) +#if defined(CONFIG_BLE_MESH_FAST_PROV) key = esp_ble_mesh_get_fast_prov_app_key(info->net_idx, info->app_idx); #endif if (!key) { diff --git a/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/include/esp_fast_prov_operation.h b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_operation.h similarity index 100% rename from examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/include/esp_fast_prov_operation.h rename to examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_operation.h diff --git a/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/src/esp_fast_prov_server_model.c b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_server_model.c similarity index 97% rename from examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/src/esp_fast_prov_server_model.c rename to examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_server_model.c index 32e70a8759..d64c967e5c 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/src/esp_fast_prov_server_model.c +++ b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_server_model.c @@ -106,7 +106,7 @@ static void example_send_all_node_addr(struct k_work *work) return; } - if (atomic_test_and_clear_bit(fast_prov_srv_data->srv_flags, RELAY_PROXY_DISABLED)) { + if (bt_mesh_atomic_test_and_clear_bit(fast_prov_srv_data->srv_flags, RELAY_PROXY_DISABLED)) { ESP_LOGI(TAG, "%s: Enable BLE Mesh Relay & GATT Proxy", __func__); cfg_srv_data->relay = ESP_BLE_MESH_RELAY_ENABLED; esp_ble_mesh_proxy_gatt_enable(); @@ -201,7 +201,7 @@ esp_err_t example_fast_prov_server_recv_msg(esp_ble_mesh_model_t *model, case FAST_PROV_ACT_SUSPEND: case FAST_PROV_ACT_EXIT: srv->pend_act = action & BIT_MASK(2); - if (!atomic_test_and_set_bit(srv->srv_flags, DISABLE_FAST_PROV_START)) { + if (!bt_mesh_atomic_test_and_set_bit(srv->srv_flags, DISABLE_FAST_PROV_START)) { k_delayed_work_submit(&srv->disable_fast_prov_timer, DISABLE_FAST_PROV_TIMEOUT); } net_buf_simple_add_u8(msg, 0x00); /* action succeed */ @@ -340,7 +340,7 @@ esp_err_t example_fast_prov_server_recv_msg(esp_ble_mesh_model_t *model, return ESP_FAIL; } - if (atomic_test_and_clear_bit(srv->srv_flags, SEND_ALL_NODE_ADDR_START)) { + if (bt_mesh_atomic_test_and_clear_bit(srv->srv_flags, SEND_ALL_NODE_ADDR_START)) { k_delayed_work_cancel(&srv->send_all_node_addr_timer); } @@ -545,7 +545,7 @@ esp_err_t example_handle_fast_prov_status_send_comp_evt(int err_code, uint32_t o switch (opcode) { case ESP_BLE_MESH_VND_MODEL_OP_FAST_PROV_INFO_STATUS: if (err_code == 0 && srv->set_info && srv->set_info->set_succeed == true) { - if (!atomic_test_and_set_bit(srv->srv_flags, RELAY_PROXY_DISABLED)) { + if (!bt_mesh_atomic_test_and_set_bit(srv->srv_flags, RELAY_PROXY_DISABLED)) { /* For Primary Provisioner: disable Relay and GATT Proxy; * For other Provisioners: only disable GATT Proxy */ @@ -560,7 +560,7 @@ esp_err_t example_handle_fast_prov_status_send_comp_evt(int err_code, uint32_t o case ESP_BLE_MESH_VND_MODEL_OP_FAST_PROV_NODE_ADDR_ACK: /* Minus 1 which is provisioned by the top device */ if (all_node_addr_cnt < srv->node_addr_cnt - 1) { - if (!atomic_test_and_set_bit(srv->srv_flags, SEND_ALL_NODE_ADDR_START)) { + if (!bt_mesh_atomic_test_and_set_bit(srv->srv_flags, SEND_ALL_NODE_ADDR_START)) { k_delayed_work_submit(&srv->send_all_node_addr_timer, SEND_ALL_NODE_ADDR_TIMEOUT); } } diff --git a/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/include/esp_fast_prov_server_model.h b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_server_model.h similarity index 98% rename from examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/include/esp_fast_prov_server_model.h rename to examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_server_model.h index 43f3b254da..0cc060625c 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/include/esp_fast_prov_server_model.h +++ b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components/esp_fast_prov_server_model.h @@ -51,7 +51,7 @@ struct fast_prov_info_set { typedef struct { esp_ble_mesh_model_t *model; /* Fast Prov Server model pointer */ - ATOMIC_DEFINE(srv_flags, SRV_MAX_FLAGS); + BLE_MESH_ATOMIC_DEFINE(srv_flags, SRV_MAX_FLAGS); bool primary_role; /* Indicate if the device is a Primary Provisioner */ uint8_t max_node_num; /* The maximum number of devices can be provisioned by the Provisioner */ diff --git a/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/main/CMakeLists.txt b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/main/CMakeLists.txt new file mode 100644 index 0000000000..f475ba4612 --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/main/CMakeLists.txt @@ -0,0 +1,3 @@ +set(COMPONENT_SRCS "main.c") + +register_component() diff --git a/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/main/component.mk b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/main/component.mk new file mode 100644 index 0000000000..d68c5375e9 --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/main/component.mk @@ -0,0 +1,5 @@ +# +# "main" pseudo-component makefile. +# +# (Uses default behaviour of compiling all source files in directory, adding 'include' to include path.) +# \ No newline at end of file diff --git a/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/main/main.c b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/main/main.c new file mode 100644 index 0000000000..889f706f78 --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/main/main.c @@ -0,0 +1,21 @@ +// Copyright 2017-2018 Espressif Systems (Shanghai) PTE LTD +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at + +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +void app_main(void) +{ + /* This main.c is for CI. The fast_prov_vendor_model shall be + * included by other ble mesh examples which need vendor fast + * provisioning client/server models. + */ +} diff --git a/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/sdkconfig.defaults b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/sdkconfig.defaults new file mode 100644 index 0000000000..8840abdc37 --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/sdkconfig.defaults @@ -0,0 +1,31 @@ +# Override some defaults so BT stack is enabled +# by default in this example +CONFIG_BT_ENABLED=y +CONFIG_BLE_MESH=y +CONFIG_BLE_MESH_FAST_PROV=y +CONFIG_BLE_MESH_PROV=y +CONFIG_BLE_MESH_NODE=y +CONFIG_BLE_MESH_PROVISIONER=y +CONFIG_BLE_MESH_WAIT_FOR_PROV_MAX_DEV_NUM=20 +CONFIG_BLE_MESH_MAX_STORED_NODES=10 +CONFIG_BLE_MESH_MAX_PROV_NODES=6 +CONFIG_BLE_MESH_PBA_SAME_TIME=3 +CONFIG_BLE_MESH_PBG_SAME_TIME=3 +CONFIG_BLE_MESH_PROVISIONER_SUBNET_COUNT=3 +CONFIG_BLE_MESH_PROVISIONER_APP_KEY_COUNT=9 +CONFIG_BLE_MESH_PB_ADV=y +CONFIG_BLE_MESH_NET_BUF_POOL_USAGE=y +CONFIG_BLE_MESH_PB_GATT=y +CONFIG_BLE_MESH_GATT_PROXY=y +CONFIG_BLE_MESH_RELAY=y +CONFIG_BLE_MESH_LOW_POWER= +CONFIG_BLE_MESH_FRIEND= +CONFIG_BTU_TASK_STACK_SIZE=4512 +CONFIG_BLE_MESH_CFG_CLI=y +CONFIG_BLE_MESH_CRPL=60 +CONFIG_BLE_MESH_MSG_CACHE_SIZE=60 +CONFIG_BLE_MESH_ADV_BUF_COUNT=200 +CONFIG_BLE_MESH_TX_SEG_MSG_COUNT=10 +CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=10 +CONFIG_BLE_MESH_NO_LOG=n +CONFIG_BLE_MESH_STACK_TRACE_LEVEL=0 \ No newline at end of file diff --git a/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/CMakeLists.txt b/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/CMakeLists.txt new file mode 100644 index 0000000000..8f5e74e32f --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/CMakeLists.txt @@ -0,0 +1,8 @@ +# The following lines of boilerplate have to be in your project's CMakeLists +# in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.5) + +set(EXTRA_COMPONENT_DIRS $ENV{IDF_PATH}/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(ble_mesh_wifi_coexist) diff --git a/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/Makefile b/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/Makefile index 8d310f3ef1..2db430c14f 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/Makefile +++ b/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/Makefile @@ -7,6 +7,6 @@ PROJECT_NAME := ble_mesh_wifi_coexist COMPONENT_ADD_INCLUDEDIRS := components/include -EXTRA_COMPONENT_DIRS := $(IDF_PATH)/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model +EXTRA_COMPONENT_DIRS := $(IDF_PATH)/examples/bluetooth/ble_mesh/ble_mesh_vendor_models/fast_prov_vendor_model/components include $(IDF_PATH)/make/project.mk diff --git a/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/components/iperf/CMakeLists.txt b/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/components/iperf/CMakeLists.txt new file mode 100644 index 0000000000..5073db6d0f --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/components/iperf/CMakeLists.txt @@ -0,0 +1,8 @@ +set(COMPONENT_SRCS "cmd_wifi.c" + "iperf.c") + +set(COMPONENT_ADD_INCLUDEDIRS .) + +set(COMPONENT_REQUIRES lwip console) + +register_component() diff --git a/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/main/CMakeLists.txt b/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/main/CMakeLists.txt new file mode 100644 index 0000000000..1eb2d87ed2 --- /dev/null +++ b/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/main/CMakeLists.txt @@ -0,0 +1,6 @@ +set(COMPONENT_SRCS "ble_mesh_demo_main.c" + "board.c") + +set(COMPONENT_ADD_INCLUDEDIRS ".") + +register_component() diff --git a/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/main/Kconfig.projbuild b/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/main/Kconfig.projbuild index 0625129f04..aa8b9f3687 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/main/Kconfig.projbuild +++ b/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/main/Kconfig.projbuild @@ -1,23 +1,22 @@ -menu "Example 'BLE Mesh' Config" +menu "Example Configuration" -choice ESP32_BOARD - prompt "Board selection for BLE Mesh" - default ESP_WROOM_32_BOARD - help - Select this option to choose the board for BLE Mesh. The default is ESP32-WROOM-32 + choice ESP32_BOARD + prompt "Board selection for BLE Mesh" + default ESP_WROOM_32_BOARD + help + Select this option to choose the board for BLE Mesh. The default is ESP32-WROOM-32 -config ESP_WROOM_32_BOARD - bool "ESP32-WROOM-32" + config ESP_WROOM_32_BOARD + bool "ESP32-WROOM-32" -config ESP_WROVER_BOARD - bool "ESP32-WROVER" + config ESP_WROVER_BOARD + bool "ESP32-WROVER" + endchoice -endchoice - -config HCI_5_0_VERSION - bool "If you need to send 20ms non-connectable advertising packets and the BLE controller you are using is not HCI 5.0, set this marco to true." - default y - help - It is just a temporary solution, which will be modified later. + config HCI_5_0_VERSION + bool "Support sending 20ms non-connectable advertising packets" + default y + help + It is a temporary solution and needs further modifications. endmenu diff --git a/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/main/ble_mesh_demo_main.c b/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/main/ble_mesh_demo_main.c index 3820693434..a67034e4ff 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/main/ble_mesh_demo_main.c +++ b/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/main/ble_mesh_demo_main.c @@ -50,7 +50,7 @@ extern struct _led_state led_state[3]; extern struct k_delayed_work send_self_prov_node_addr_timer; -extern atomic_t fast_prov_cli_flags; +extern bt_mesh_atomic_t fast_prov_cli_flags; static uint8_t dev_uuid[16] = { 0xdd, 0xdd }; static uint8_t prov_start_num = 0; @@ -70,12 +70,12 @@ esp_ble_mesh_client_t config_client; esp_ble_mesh_cfg_srv_t config_server = { .relay = ESP_BLE_MESH_RELAY_ENABLED, .beacon = ESP_BLE_MESH_BEACON_DISABLED, -#if defined(CONFIG_BT_MESH_FRIEND) +#if defined(CONFIG_BLE_MESH_FRIEND) .friend_state = ESP_BLE_MESH_FRIEND_ENABLED, #else .friend_state = ESP_BLE_MESH_FRIEND_NOT_SUPPORTED, #endif -#if defined(CONFIG_BT_MESH_GATT_PROXY) +#if defined(CONFIG_BLE_MESH_GATT_PROXY) .gatt_proxy = ESP_BLE_MESH_GATT_PROXY_ENABLED, #else .gatt_proxy = ESP_BLE_MESH_GATT_PROXY_NOT_SUPPORTED, @@ -204,7 +204,7 @@ static void gen_onoff_get_handler(esp_ble_mesh_model_t *model, /* When the node receives the first Generic OnOff Get/Set/Set Unack message, it will * start the timer used to disable fast provisioning functionality. */ - if (!atomic_test_and_set_bit(fast_prov_server.srv_flags, DISABLE_FAST_PROV_START)) { + if (!bt_mesh_atomic_test_and_set_bit(fast_prov_server.srv_flags, DISABLE_FAST_PROV_START)) { k_delayed_work_submit(&fast_prov_server.disable_fast_prov_timer, DISABLE_FAST_PROV_TIMEOUT); } } @@ -232,7 +232,7 @@ static void gen_onoff_set_unack_handler(esp_ble_mesh_model_t *model, /* When the node receives the first Generic OnOff Get/Set/Set Unack message, it will * start the timer used to disable fast provisioning functionality. */ - if (!atomic_test_and_set_bit(fast_prov_server.srv_flags, DISABLE_FAST_PROV_START)) { + if (!bt_mesh_atomic_test_and_set_bit(fast_prov_server.srv_flags, DISABLE_FAST_PROV_START)) { k_delayed_work_submit(&fast_prov_server.disable_fast_prov_timer, DISABLE_FAST_PROV_TIMEOUT); } } @@ -308,10 +308,10 @@ static void provisioner_prov_complete(int node_idx, const uint8_t uuid[16], uint return; } if (fast_prov_server.node_addr_cnt <= fast_prov_server.max_node_num) { - if (atomic_test_and_clear_bit(fast_prov_server.srv_flags, SEND_ALL_NODE_ADDR_START)) { + if (bt_mesh_atomic_test_and_clear_bit(fast_prov_server.srv_flags, SEND_ALL_NODE_ADDR_START)) { k_delayed_work_cancel(&fast_prov_server.send_all_node_addr_timer); } - if (!atomic_test_and_set_bit(fast_prov_server.srv_flags, SEND_ALL_NODE_ADDR_START)) { + if (!bt_mesh_atomic_test_and_set_bit(fast_prov_server.srv_flags, SEND_ALL_NODE_ADDR_START)) { k_delayed_work_submit(&fast_prov_server.send_all_node_addr_timer, SEND_ALL_NODE_ADDR_TIMEOUT); } } @@ -319,15 +319,15 @@ static void provisioner_prov_complete(int node_idx, const uint8_t uuid[16], uint /* When a device is provisioned, the non-primary Provisioner shall reset the timer * which is used to send node addresses to the primary Provisioner. */ - if (atomic_test_and_clear_bit(&fast_prov_cli_flags, SEND_SELF_PROV_NODE_ADDR_START)) { + if (bt_mesh_atomic_test_and_clear_bit(&fast_prov_cli_flags, SEND_SELF_PROV_NODE_ADDR_START)) { k_delayed_work_cancel(&send_self_prov_node_addr_timer); } - if (!atomic_test_and_set_bit(&fast_prov_cli_flags, SEND_SELF_PROV_NODE_ADDR_START)) { + if (!bt_mesh_atomic_test_and_set_bit(&fast_prov_cli_flags, SEND_SELF_PROV_NODE_ADDR_START)) { k_delayed_work_submit(&send_self_prov_node_addr_timer, SEND_SELF_PROV_NODE_ADDR_TIMEOUT); } } - if (atomic_test_bit(fast_prov_server.srv_flags, DISABLE_FAST_PROV_START)) { + if (bt_mesh_atomic_test_bit(fast_prov_server.srv_flags, DISABLE_FAST_PROV_START)) { /* When a device is provisioned, and the stop_prov flag of the Provisioner has been * set, the Provisioner shall reset the timer which is used to stop the provisioner * functionality. diff --git a/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/sdkconfig.defaults b/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/sdkconfig.defaults index 9a11835df6..89e4084602 100644 --- a/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/sdkconfig.defaults +++ b/examples/bluetooth/ble_mesh/ble_mesh_wifi_coexist/sdkconfig.defaults @@ -12,36 +12,36 @@ CONFIG_BLE_MESH_SCAN_DUPLICATE_EN=y CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE=200 CONFIG_GATTS_ENABLE=y CONFIG_GATTS_SEND_SERVICE_CHANGE_MANUAL=y -CONFIG_BT_MESH=y -CONFIG_BT_MESH_USE_DUPLICATE_SCAN=y -CONFIG_BT_MESH_FAST_PROV=y -CONFIG_BT_MESH_PROV=y -CONFIG_BT_MESH_NODE=y -CONFIG_BT_MESH_PROVISIONER=y -CONFIG_BT_MESH_UNPROV_DEV_ADD=20 -CONFIG_BT_MESH_MAX_STORED_NODES=10 -CONFIG_BT_MESH_MAX_PROV_NODES=6 -CONFIG_BT_MESH_PBA_SAME_TIME=3 -CONFIG_BT_MESH_PBG_SAME_TIME=3 -CONFIG_BT_MESH_PROVISIONER_SUBNET_COUNT=3 -CONFIG_BT_MESH_PROVISIONER_APP_KEY_COUNT=9 -CONFIG_BT_MESH_PB_ADV=y -CONFIG_NET_BUF_POOL_USAGE=y -CONFIG_BT_MESH_PB_GATT=y -CONFIG_BT_MESH_GATT_PROXY=y -CONFIG_BT_MESH_RELAY=y -CONFIG_BT_MESH_LOW_POWER= -CONFIG_BT_MESH_FRIEND= +CONFIG_BLE_MESH=y +CONFIG_BLE_MESH_USE_DUPLICATE_SCAN=y +CONFIG_BLE_MESH_FAST_PROV=y +CONFIG_BLE_MESH_PROV=y +CONFIG_BLE_MESH_NODE=y +CONFIG_BLE_MESH_PROVISIONER=y +CONFIG_BLE_MESH_WAIT_FOR_PROV_MAX_DEV_NUM=20 +CONFIG_BLE_MESH_MAX_STORED_NODES=10 +CONFIG_BLE_MESH_MAX_PROV_NODES=6 +CONFIG_BLE_MESH_PBA_SAME_TIME=3 +CONFIG_BLE_MESH_PBG_SAME_TIME=3 +CONFIG_BLE_MESH_PROVISIONER_SUBNET_COUNT=3 +CONFIG_BLE_MESH_PROVISIONER_APP_KEY_COUNT=9 +CONFIG_BLE_MESH_PB_ADV=y +CONFIG_BLE_MESH_NET_BUF_POOL_USAGE=y +CONFIG_BLE_MESH_PB_GATT=y +CONFIG_BLE_MESH_GATT_PROXY=y +CONFIG_BLE_MESH_RELAY=y +CONFIG_BLE_MESH_LOW_POWER= +CONFIG_BLE_MESH_FRIEND= CONFIG_BTU_TASK_STACK_SIZE=4512 -CONFIG_BT_MESH_CFG_CLI=y -CONFIG_BT_MESH_GENERIC_ONOFF_CLI=y -CONFIG_BT_MESH_CRPL=60 -CONFIG_BT_MESH_MSG_CACHE_SIZE=60 -CONFIG_BT_MESH_ADV_BUF_COUNT=200 -CONFIG_BT_MESH_TX_SEG_MSG_COUNT=10 -CONFIG_BT_MESH_RX_SEG_MSG_COUNT=10 -CONFIG_BT_MESH_NO_LOG=n -CONFIG_BT_MESH_STACK_INITIAL_TRACE_LEVEL=0 +CONFIG_BLE_MESH_CFG_CLI=y +CONFIG_BLE_MESH_GENERIC_ONOFF_CLI=y +CONFIG_BLE_MESH_CRPL=60 +CONFIG_BLE_MESH_MSG_CACHE_SIZE=60 +CONFIG_BLE_MESH_ADV_BUF_COUNT=200 +CONFIG_BLE_MESH_TX_SEG_MSG_COUNT=10 +CONFIG_BLE_MESH_RX_SEG_MSG_COUNT=10 +CONFIG_BLE_MESH_NO_LOG=n +CONFIG_BLE_MESH_STACK_TRACE_LEVEL=0 CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE=4096 @@ -59,8 +59,8 @@ CONFIG_FREERTOS_HZ=1000 CONFIG_INT_WDT= CONFIG_TASK_WDT= -CONFIG_TCP_SND_BUF_DEFAULT=65535 -CONFIG_TCP_WND_DEFAULT=65535 +CONFIG_TCP_SND_BUF_DEFAULT=65534 +CONFIG_TCP_WND_DEFAULT=65534 CONFIG_TCP_RECVMBOX_SIZE=64 CONFIG_UDP_RECVMBOX_SIZE=64 CONFIG_TCPIP_RECVMBOX_SIZE=64