feat(ble_mesh): Support Bluetooth Mesh Protocol v1.1 (Preview)

This commit is contained in:
Liu Linyan 2023-08-28 16:09:37 +08:00 committed by wangjialiang
parent fd451f5856
commit 5bab168b0e
271 changed files with 32403 additions and 7253 deletions

View File

@ -390,7 +390,11 @@ if(CONFIG_BT_ENABLED)
"esp_ble_mesh/models/server/include"
"esp_ble_mesh/api/core/include"
"esp_ble_mesh/api/models/include"
"esp_ble_mesh/api")
"esp_ble_mesh/api"
"esp_ble_mesh/v1.1/api/core/include"
"esp_ble_mesh/v1.1/api/models/include"
"esp_ble_mesh/v1.1/btc/include"
"esp_ble_mesh/v1.1/include")
list(APPEND srcs "esp_ble_mesh/api/core/esp_ble_mesh_ble_api.c"
"esp_ble_mesh/api/core/esp_ble_mesh_common_api.c"
@ -452,15 +456,18 @@ if(CONFIG_BT_ENABLED)
"esp_ble_mesh/core/lpn.c"
"esp_ble_mesh/core/main.c"
"esp_ble_mesh/core/net.c"
"esp_ble_mesh/core/prov_common.c"
"esp_ble_mesh/core/prov_node.c"
"esp_ble_mesh/core/prov_pvnr.c"
"esp_ble_mesh/core/proxy_client.c"
"esp_ble_mesh/core/proxy_server.c"
"esp_ble_mesh/core/pvnr_mgmt.c"
"esp_ble_mesh/core/rpl.c"
"esp_ble_mesh/core/scan.c"
"esp_ble_mesh/core/test.c"
"esp_ble_mesh/core/transport.c"
"esp_ble_mesh/models/common/device_property.c"
"esp_ble_mesh/models/common/model_common.c"
"esp_ble_mesh/models/client/client_common.c"
"esp_ble_mesh/models/client/generic_client.c"
"esp_ble_mesh/models/client/lighting_client.c"
@ -472,7 +479,29 @@ if(CONFIG_BT_ENABLED)
"esp_ble_mesh/models/server/server_common.c"
"esp_ble_mesh/models/server/state_binding.c"
"esp_ble_mesh/models/server/state_transition.c"
"esp_ble_mesh/models/server/time_scene_server.c")
"esp_ble_mesh/models/server/time_scene_server.c"
"esp_ble_mesh/v1.1/api/core/esp_ble_mesh_agg_model_api.c"
"esp_ble_mesh/v1.1/api/core/esp_ble_mesh_brc_model_api.c"
"esp_ble_mesh/v1.1/api/core/esp_ble_mesh_cm_data_api.c"
"esp_ble_mesh/v1.1/api/core/esp_ble_mesh_df_model_api.c"
"esp_ble_mesh/v1.1/api/core/esp_ble_mesh_lcd_model_api.c"
"esp_ble_mesh/v1.1/api/core/esp_ble_mesh_odp_model_api.c"
"esp_ble_mesh/v1.1/api/core/esp_ble_mesh_prb_model_api.c"
"esp_ble_mesh/v1.1/api/core/esp_ble_mesh_rpr_model_api.c"
"esp_ble_mesh/v1.1/api/core/esp_ble_mesh_sar_model_api.c"
"esp_ble_mesh/v1.1/api/core/esp_ble_mesh_srpl_model_api.c"
"esp_ble_mesh/v1.1/api/models/esp_ble_mesh_mbt_model_api.c"
"esp_ble_mesh/v1.1/btc/btc_ble_mesh_agg_model.c"
"esp_ble_mesh/v1.1/btc/btc_ble_mesh_brc_model.c"
"esp_ble_mesh/v1.1/btc/btc_ble_mesh_df_model.c"
"esp_ble_mesh/v1.1/btc/btc_ble_mesh_lcd_model.c"
"esp_ble_mesh/v1.1/btc/btc_ble_mesh_mbt_model.c"
"esp_ble_mesh/v1.1/btc/btc_ble_mesh_odp_model.c"
"esp_ble_mesh/v1.1/btc/btc_ble_mesh_prb_model.c"
"esp_ble_mesh/v1.1/btc/btc_ble_mesh_rpr_model.c"
"esp_ble_mesh/v1.1/btc/btc_ble_mesh_sar_model.c"
"esp_ble_mesh/v1.1/btc/btc_ble_mesh_srpl_model.c"
"esp_ble_mesh/v1.1/ext.c")
endif()
@ -741,6 +770,25 @@ if(CONFIG_BT_ENABLED)
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
endif()
if(CONFIG_BLE_MESH)
if(CONFIG_IDF_TARGET_ESP32)
add_prebuilt_library(mesh_v11 "esp_ble_mesh/v1.1/lib/esp32/libmesh_v1.1.a")
target_link_libraries(${COMPONENT_LIB} PRIVATE mesh_v11)
elseif(CONFIG_IDF_TARGET_ESP32S3)
add_prebuilt_library(mesh_v11 "esp_ble_mesh/v1.1/lib/esp32s3/libmesh_v1.1.a")
target_link_libraries(${COMPONENT_LIB} PRIVATE mesh_v11)
elseif(CONFIG_IDF_TARGET_ESP32C3)
add_prebuilt_library(mesh_v11 "esp_ble_mesh/v1.1/lib/esp32c3/libmesh_v1.1.a")
target_link_libraries(${COMPONENT_LIB} PRIVATE mesh_v11)
elseif(CONFIG_IDF_TARGET_ESP32C6)
add_prebuilt_library(mesh_v11 "esp_ble_mesh/v1.1/lib/esp32c6/libmesh_v1.1.a")
target_link_libraries(${COMPONENT_LIB} PRIVATE mesh_v11)
elseif(CONFIG_IDF_TARGET_ESP32H2)
add_prebuilt_library(mesh_v11 "esp_ble_mesh/v1.1/lib/esp32h2/libmesh_v1.1.a")
target_link_libraries(${COMPONENT_LIB} PRIVATE mesh_v11)
endif()
endif()
if(CONFIG_BT_NIMBLE_MESH)
set_source_files_properties("host/nimble/nimble/nimble/host/mesh/src/net.c"
PROPERTIES COMPILE_FLAGS -Wno-type-limits)

View File

@ -69,10 +69,20 @@
#include "btc_ble_mesh_prov.h"
#include "btc_ble_mesh_health_model.h"
#include "btc_ble_mesh_config_model.h"
#include "btc_ble_mesh_agg_model.h"
#include "btc_ble_mesh_brc_model.h"
#include "btc_ble_mesh_df_model.h"
#include "btc_ble_mesh_lcd_model.h"
#include "btc_ble_mesh_odp_model.h"
#include "btc_ble_mesh_prb_model.h"
#include "btc_ble_mesh_rpr_model.h"
#include "btc_ble_mesh_sar_model.h"
#include "btc_ble_mesh_srpl_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"
#include "btc_ble_mesh_mbt_model.h"
#endif /* #if CONFIG_BLE_MESH */
#define BTC_TASK_PINNED_TO_CORE (TASK_PINNED_TO_CORE)
@ -158,6 +168,60 @@ static const btc_func_t profile_tab[BTC_PID_NUM] = {
[BTC_PID_CONFIG_CLIENT] = {btc_ble_mesh_config_client_call_handler, btc_ble_mesh_config_client_cb_handler },
#endif /* CONFIG_BLE_MESH_CFG_CLI */
[BTC_PID_CONFIG_SERVER] = {NULL, btc_ble_mesh_config_server_cb_handler },
#if CONFIG_BLE_MESH_AGG_CLI
[BTC_PID_AGG_CLIENT] = {btc_ble_mesh_agg_client_call_handler, btc_ble_mesh_agg_client_cb_handler },
#endif /* CONFIG_BLE_MESH_AGG_CLI */
#if CONFIG_BLE_MESH_AGG_SRV
[BTC_PID_AGG_SERVER] = {NULL, btc_ble_mesh_agg_server_cb_handler },
#endif /* CONFIG_BLE_MESH_AGG_SRV */
#if CONFIG_BLE_MESH_BRC_CLI
[BTC_PID_BRC_CLIENT] = {btc_ble_mesh_brc_client_call_handler, btc_ble_mesh_brc_client_cb_handler },
#endif /* CONFIG_BLE_MESH_BRC_CLI */
#if CONFIG_BLE_MESH_BRC_SRV
[BTC_PID_BRC_SERVER] = {NULL, btc_ble_mesh_brc_server_cb_handler },
#endif /* CONFIG_BLE_MESH_BRC_SRV */
#if CONFIG_BLE_MESH_DF_CLI
[BTC_PID_DF_CLIENT] = {btc_ble_mesh_df_client_call_handler, btc_ble_mesh_df_client_cb_handler },
#endif /* CONFIG_BLE_MESH_DF_CLI */
#if CONFIG_BLE_MESH_DF_SRV
[BTC_PID_DF_SERVER] = {NULL, btc_ble_mesh_df_server_cb_handler },
#endif /* CONFIG_BLE_MESH_DF_SRV */
#if CONFIG_BLE_MESH_LCD_CLI
[BTC_PID_LCD_CLIENT] = {btc_ble_mesh_lcd_client_call_handler, btc_ble_mesh_lcd_client_cb_handler },
#endif /* CONFIG_BLE_MESH_LCD_CLI */
#if CONFIG_BLE_MESH_LCD_SRV
[BTC_PID_LCD_SERVER] = {NULL, btc_ble_mesh_lcd_server_cb_handler },
#endif /* CONFIG_BLE_MESH_LCD_SRV */
#if CONFIG_BLE_MESH_ODP_CLI
[BTC_PID_ODP_CLIENT] = {btc_ble_mesh_odp_client_call_handler, btc_ble_mesh_odp_client_cb_handler },
#endif /* CONFIG_BLE_MESH_ODP_CLI */
#if CONFIG_BLE_MESH_ODP_SRV
[BTC_PID_ODP_SERVER] = {NULL, btc_ble_mesh_odp_server_cb_handler },
#endif /* CONFIG_BLE_MESH_ODP_SRV */
#if CONFIG_BLE_MESH_PRB_CLI
[BTC_PID_PRB_CLIENT] = {btc_ble_mesh_prb_client_call_handler, btc_ble_mesh_prb_client_cb_handler },
#endif /* CONFIG_BLE_MESH_PRB_CLI */
#if CONFIG_BLE_MESH_PRB_SRV
[BTC_PID_PRB_SERVER] = {NULL, btc_ble_mesh_prb_server_cb_handler },
#endif /*CONFIG_BLE_MESH_PRB_SRV*/
#if CONFIG_BLE_MESH_RPR_CLI
[BTC_PID_RPR_CLIENT] = {btc_ble_mesh_rpr_client_call_handler, btc_ble_mesh_rpr_client_cb_handler },
#endif /* CONFIG_BLE_MESH_RPR_CLI */
#if CONFIG_BLE_MESH_RPR_SRV
[BTC_PID_RPR_SERVER] = {NULL, btc_ble_mesh_rpr_server_cb_handler },
#endif /* CONFIG_BLE_MESH_RPR_SRV */
#if CONFIG_BLE_MESH_SAR_CLI
[BTC_PID_SAR_CLIENT] = {btc_ble_mesh_sar_client_call_handler, btc_ble_mesh_sar_client_cb_handler },
#endif /* CONFIG_BLE_MESH_SAR_CLI */
#if CONFIG_BLE_MESH_SAR_SRV
[BTC_PID_SAR_SERVER] = {NULL, btc_ble_mesh_sar_server_cb_handler },
#endif /* CONFIG_BLE_MESH_SAR_SRV */
#if CONFIG_BLE_MESH_SRPL_CLI
[BTC_PID_SRPL_CLIENT] = {btc_ble_mesh_srpl_client_call_handler, btc_ble_mesh_srpl_client_cb_handler },
#endif /* CONFIG_BLE_MESH_SRPL_CLI */
#if CONFIG_BLE_MESH_SRPL_SRV
[BTC_PID_SRPL_SERVER] = {NULL, btc_ble_mesh_srpl_server_cb_handler },
#endif /* CONFIG_BLE_MESH_SRPL_SRV */
#if CONFIG_BLE_MESH_GENERIC_CLIENT
[BTC_PID_GENERIC_CLIENT] = {btc_ble_mesh_generic_client_call_handler, btc_ble_mesh_generic_client_cb_handler },
#endif /* CONFIG_BLE_MESH_GENERIC_CLIENT */
@ -182,6 +246,12 @@ static const btc_func_t profile_tab[BTC_PID_NUM] = {
#if CONFIG_BLE_MESH_TIME_SCENE_SERVER
[BTC_PID_TIME_SCENE_SERVER] = {NULL, btc_ble_mesh_time_scene_server_cb_handler},
#endif /* CONFIG_BLE_MESH_TIME_SCENE_SERVER */
#if CONFIG_BLE_MESH_MBT_CLI
[BTC_PID_MBT_CLIENT] = {btc_ble_mesh_mbt_client_call_handler, btc_ble_mesh_mbt_client_cb_handler },
#endif /* CONFIG_BLE_MESH_MBT_CLI */
#if CONFIG_BLE_MESH_MBT_SRV
[BTC_PID_MBT_SERVER] = {btc_ble_mesh_mbt_server_call_handler, btc_ble_mesh_mbt_server_cb_handler },
#endif /* CONFIG_BLE_MESH_MBT_SRV */
#if CONFIG_BLE_MESH_BLE_COEX_SUPPORT
[BTC_PID_BLE_MESH_BLE_COEX] = {btc_ble_mesh_ble_call_handler, btc_ble_mesh_ble_cb_handler },
#endif /* CONFIG_BLE_MESH_BLE_COEX_SUPPORT */

View File

@ -75,6 +75,24 @@ typedef enum {
BTC_PID_HEALTH_SERVER,
BTC_PID_CONFIG_CLIENT,
BTC_PID_CONFIG_SERVER,
BTC_PID_AGG_CLIENT,
BTC_PID_AGG_SERVER,
BTC_PID_BRC_CLIENT,
BTC_PID_BRC_SERVER,
BTC_PID_DF_CLIENT,
BTC_PID_DF_SERVER,
BTC_PID_LCD_CLIENT,
BTC_PID_LCD_SERVER,
BTC_PID_ODP_CLIENT,
BTC_PID_ODP_SERVER,
BTC_PID_PRB_CLIENT,
BTC_PID_PRB_SERVER,
BTC_PID_RPR_CLIENT,
BTC_PID_RPR_SERVER,
BTC_PID_SAR_CLIENT,
BTC_PID_SAR_SERVER,
BTC_PID_SRPL_CLIENT,
BTC_PID_SRPL_SERVER,
BTC_PID_GENERIC_CLIENT,
BTC_PID_LIGHTING_CLIENT,
BTC_PID_SENSOR_CLIENT,
@ -83,6 +101,8 @@ typedef enum {
BTC_PID_LIGHTING_SERVER,
BTC_PID_SENSOR_SERVER,
BTC_PID_TIME_SCENE_SERVER,
BTC_PID_MBT_CLIENT,
BTC_PID_MBT_SERVER,
BTC_PID_BLE_MESH_BLE_COEX,
#endif /* CONFIG_BLE_MESH */
BTC_PID_NUM,

View File

@ -21,6 +21,11 @@ if BLE_MESH
option in the Bluetooth Controller section in menuconfig, which is
"Scan Duplicate By Device Address and Advertising Data".
config BLE_MESH_ACTIVE_SCAN
bool "Support Active Scan in BLE Mesh"
help
Enable this option to allow using BLE Active Scan for BLE Mesh.
choice BLE_MESH_MEM_ALLOC_MODE
prompt "Memory allocation strategy"
default BLE_MESH_MEM_ALLOC_MODE_INTERNAL
@ -264,6 +269,31 @@ if BLE_MESH
Enable this option to support BLE Mesh Provisioning functionality. For
BLE Mesh, this option should be always enabled.
config BLE_MESH_PROV_EPA
bool "BLE Mesh enhanced provisioning authentication"
depends on BLE_MESH_PROV
default y
help
Enable this option to support BLE Mesh enhanced provisioning authentication
functionality. This option can increase the security level of provisioning.
It is recommended to enable this option.
config BLE_MESH_CERT_BASED_PROV
bool "Support Certificate-based provisioning"
depends on BLE_MESH_PROV
default n
help
Enable this option to support BLE Mesh Certificate-Based Provisioning.
config BLE_MESH_RECORD_FRAG_MAX_SIZE
int "Maximum size of the provisioning record fragment that Provisioner can receive"
depends on BLE_MESH_CERT_BASED_PROV
default 56
range 1 57
help
This option sets the maximum size of the provisioning record fragment that the
Provisioner can receive. The range depends on provisioning bearer.
config BLE_MESH_PB_ADV
bool "Provisioning support using the advertising bearer (PB-ADV)"
select BLE_MESH_PROV
@ -338,6 +368,34 @@ if BLE_MESH
list of addresses which can be used to decide which messages will be forwarded
to the Proxy Client by the Proxy Server.
config BLE_MESH_PROXY_PRIVACY
bool "Support Proxy Privacy"
depends on BLE_MESH_PRB_SRV && BLE_MESH_GATT_PROXY_SERVER
default y
help
The Proxy Privacy parameter controls the privacy of the Proxy Server
over the connection. The value of the Proxy Privacy parameter is
controlled by the type of proxy connection, which is dependent on the
bearer used by the proxy connection.
config BLE_MESH_PROXY_SOLIC_PDU_RX
bool "Support receiving Proxy Solicitation PDU"
depends on BLE_MESH_GATT_PROXY_SERVER
help
Enable this option to support receiving Proxy Solicitation PDU.
config BLE_MESH_PROXY_SOLIC_RX_CRPL
int "Maximum capacity of solicitation replay protection list"
depends on BLE_MESH_PROXY_SOLIC_PDU_RX
default 2
range 1 255
help
This option specifies the maximum capacity of the solicitation replay
protection list. The solicitation replay protection list is used to
reject Solicitation PDUs that were already processed by a node, which
will store the solicitation src and solicitation sequence number of
the received Solicitation PDU message.
config BLE_MESH_GATT_PROXY_CLIENT
bool "BLE Mesh GATT Proxy Client"
select BLE_MESH_PROXY
@ -347,6 +405,25 @@ if BLE_MESH
can use the GATT bearer to send mesh messages to a node that supports the
advertising bearer.
config BLE_MESH_PROXY_SOLIC_PDU_TX
bool "Support sending Proxy Solicitation PDU"
depends on BLE_MESH_GATT_PROXY_CLIENT
help
Enable this option to support sending Proxy Solicitation PDU.
config BLE_MESH_PROXY_SOLIC_TX_SRC_COUNT
int "Maximum number of SSRC that can be used by Proxy Client"
depends on BLE_MESH_PROXY_SOLIC_PDU_TX
default 2
range 1 16
help
This option specifies the maximum number of Solicitation Source (SSRC)
that can be used by Proxy Client for sending a Solicitation PDU.
A Proxy Client may use the primary address or any of the secondary
addresses as the SSRC for a Solicitation PDU.
So for a Proxy Client, it's better to choose the value based on its
own element count.
config BLE_MESH_NET_BUF_POOL_USAGE
bool
default y
@ -994,6 +1071,244 @@ if BLE_MESH
help
Enable support for Health Server model.
config BLE_MESH_BRC_CLI
bool "Bridge Configuration Client model"
help
Enable support for Bridge Configuration Client model.
config BLE_MESH_BRC_SRV
bool "Bridge Configuration Server model"
default n
help
Enable support for Bridge Configuration Server model.
if BLE_MESH_BRC_SRV
config BLE_MESH_MAX_BRIDGING_TABLE_ENTRY_COUNT
int "Maximum number of Bridging Table entries"
range 16 65535
default 16
help
Maximum number of Bridging Table entries that the Bridge Configuration Server can support.
endif #BLE_MESH_BRC_SRV
config BLE_MESH_PRB_CLI
bool "Mesh Private Beacon Client model"
help
Enable support for Mesh Private Beacon Client model.
config BLE_MESH_PRB_SRV
bool "Mesh Private Beacon Server model"
help
Enable support for Mesh Private Beacon Server model.
config BLE_MESH_ODP_CLI
bool "On-Demand Private Proxy Client model"
help
Enable support for On-Demand Private Proxy Client model.
config BLE_MESH_ODP_SRV
bool "On-Demand Private Proxy Server model"
depends on BLE_MESH_PROXY_SOLIC_PDU_RX
select BLE_MESH_SRPL_SRV
help
Enable support for On-Demand Private Proxy Server model.
config BLE_MESH_SRPL_CLI
bool "Solicitation PDU RPL Configuration Client model"
help
Enable support for Solicitation PDU RPL Configuration Client model.
config BLE_MESH_SRPL_SRV
bool "Solicitation PDU RPL Configuration Server model"
depends on BLE_MESH_PROXY_SOLIC_PDU_RX
help
Enable support for Solicitation PDU RPL Configuration Server model.
Note:
This option depends on the functionality of receiving Solicitation
PDU. If the device doesn't support receiving Solicitation PDU, then
there is no need to enable this server model.
config BLE_MESH_AGG_CLI
bool "Opcodes Aggregator Client model"
help
Enable support for Opcodes Aggregator Client model.
config BLE_MESH_AGG_SRV
bool "Opcodes Aggregator Server model"
help
Enable support for Opcodes Aggregator Server model.
config BLE_MESH_SAR_CLI
bool "SAR Configuration Client model"
help
Enable support for SAR Configuration Client model.
config BLE_MESH_SAR_SRV
bool "SAR Configuration Server model"
help
Enable support for SAR Configuration Server model.
config BLE_MESH_COMP_DATA_1
bool "Support Composition Data Page 1"
help
Composition Data Page 1 contains information about the relationships
among models.
Each model either can be a root model or can extend other models.
config BLE_MESH_COMP_DATA_128
bool "Support Composition Data Page 128"
help
Composition Data Page 128 is used to indicate the structure of
elements, features, and models of a node after the successful
execution of the Node Address Refresh procedure or the Node
Composition Refresh procedure, or after the execution of the
Node Removal procedure followed by the provisioning process.
Composition Data Page 128 shall be present if the node supports
the Remote Provisioning Server model; otherwise it is optional.
config BLE_MESH_MODELS_METADATA_0
bool "Support Models Metadata Page 0"
help
The Models Metadata state contains metadata of a nodes models.
The Models Metadata state is composed of a number of pages of
information.
Models Metadata Page 0 shall be present if the node supports
the Large Composition Data Server model.
config BLE_MESH_MODELS_METADATA_128
bool "Support Models Metadata Page 128"
depends on BLE_MESH_MODELS_METADATA_0
help
The Models Metadata state contains metadata of a nodes models.
The Models Metadata state is composed of a number of pages of
information.
Models Metadata Page 128 contains metadata for the nodes models
after the successful execution of the Node Address Refresh
procedure or the Node Composition Refresh procedure, or after
the execution of the Node Removal procedure followed by the
provisioning process.
Models Metadata Page 128 shall be present if the node supports
the Remote Provisioning Server model and the node supports the
Large Composition Data Server model.
config BLE_MESH_LCD_CLI
bool "Large Composition Data Client model"
help
Enable support for Large Composition Data Client model.
config BLE_MESH_LCD_SRV
bool "Large Composition Data Server model"
select BLE_MESH_MODELS_METADATA_0
help
Enable support for Large Composition Data Server model.
config BLE_MESH_RPR_CLI
bool "Remote Provisioning Client model"
depends on BLE_MESH_PROVISIONER
select BLE_MESH_PROV
help
Enable support for Remote Provisioning Client model
if BLE_MESH_RPR_CLI
config BLE_MESH_RPR_CLI_PROV_SAME_TIME
int "Maximum number of PB-Remote running at the same time by Provisioner"
range 1 5
default 2
help
This option specifies how many devices can be provisioned at the same time
using PB-REMOTE. For example, if the value is 2, it means a Provisioner can
provision two unprovisioned devices with PB-REMOTE at the same time.
endif # BLE_MESH_RPR_CLI
config BLE_MESH_RPR_SRV
bool "Remote Provisioning Server model"
depends on BLE_MESH_NODE
select BLE_MESH_PB_ADV
help
Enable support for Remote Provisioning Server model
if BLE_MESH_RPR_SRV
config BLE_MESH_RPR_SRV_MAX_SCANNED_ITEMS
int "Maximum number of device information can be scanned"
range 4 255
default 10
help
This option specifies how many device information can a Remote
Provisioning Server store each time while scanning.
config BLE_MESH_RPR_SRV_ACTIVE_SCAN
bool "Support Active Scan for remote provisioning"
select BLE_MESH_ACTIVE_SCAN
help
Enable this option to support Active Scan for remote provisioning.
config BLE_MESH_RPR_SRV_MAX_EXT_SCAN
int "Maximum number of extended scan procedures"
range 1 10
default 1
help
This option specifies how many extended scan procedures can be
started by the Remote Provisioning Server.
endif # BLE_MESH_RPR_SRV
config BLE_MESH_DF_CLI
bool "Directed Forwarding Configuration Client model"
help
Enable support for Directed Forwarding Configuration Client model.
config BLE_MESH_DF_SRV
bool "Directed Forwarding Configuration Server model"
help
Enable support for Directed Forwarding Configuration Server model.
if BLE_MESH_DF_SRV
config BLE_MESH_MAX_DISC_TABLE_ENTRY_COUNT
int "Maximum number of discovery table entries in a given subnet"
range 2 255
default 2
help
Maximum number of Discovery Table entries supported by the node in a given subnet.
config BLE_MESH_MAX_FORWARD_TABLE_ENTRY_COUNT
int "Maximum number of forward table entries in a given subnet"
range 2 64
default 2
help
Maximum number of Forward Table entries supported by the node in a given subnet.
config BLE_MESH_MAX_DEPS_NODES_PER_PATH
int "Maximum number of dependent nodes per path"
range 2 64
default 2
help
Maximum size of dependent nodes list supported by each forward table entry.
config BLE_MESH_PATH_MONITOR_TEST
bool "Enable Path Monitoring test mode"
default n
help
The option only removes the Path Use timer; all other behavior of the
device is not changed.
If Path Monitoring test mode is going to be used, this option should
be enabled.
if BLE_MESH_GATT_PROXY_SERVER
config BLE_MESH_SUPPORT_DIRECTED_PROXY
bool "Enable Directed Proxy functionality"
default y
help
Support Directed Proxy functionality.
endif
endif # BLE_MESH_DF_SRV
endmenu #Support for BLE Mesh Foundation models
menu "Support for BLE Mesh Client/Server models"
@ -1107,6 +1422,30 @@ if BLE_MESH
help
Enable support for Lighting server models.
config BLE_MESH_MBT_CLI
bool "BLOB Transfer Client model"
default y
help
Enable support for BLOB Transfer Client model.
if BLE_MESH_MBT_CLI
config BLE_MESH_MAX_BLOB_RECEIVERS
int "Maximum number of simultaneous blob receivers"
default 2
range 1 255
help
Maximum number of BLOB Transfer Server models that can participating
in the BLOB transfer with a BLOB Transfer Client model.
endif # BLE_MESH_MBT_CLI
config BLE_MESH_MBT_SRV
bool "BLOB Transfer Server model"
default y
help
Enable support for BLOB Transfer Server model.
endmenu #Support for BLE Mesh Client/Server models
config BLE_MESH_IV_UPDATE_TEST

View File

@ -17,6 +17,7 @@ int32_t esp_ble_mesh_get_model_publish_period(esp_ble_mesh_model_t *model)
if (model == NULL) {
return 0;
}
return btc_ble_mesh_model_pub_period_get(model);
}
@ -31,6 +32,7 @@ uint16_t *esp_ble_mesh_is_model_subscribed_to_group(esp_ble_mesh_model_t *model,
if (model == NULL) {
return NULL;
}
return btc_ble_mesh_model_find_group(model, group_addr);
}
@ -39,6 +41,7 @@ esp_ble_mesh_elem_t *esp_ble_mesh_find_element(uint16_t element_addr)
if (!ESP_BLE_MESH_ADDR_IS_UNICAST(element_addr)) {
return NULL;
}
return btc_ble_mesh_elem_find(element_addr);
}
@ -53,6 +56,7 @@ esp_ble_mesh_model_t *esp_ble_mesh_find_vendor_model(const esp_ble_mesh_elem_t *
if (element == NULL) {
return NULL;
}
return btc_ble_mesh_model_find_vnd(element, company_id, model_id);
}
@ -62,6 +66,7 @@ esp_ble_mesh_model_t *esp_ble_mesh_find_sig_model(const esp_ble_mesh_elem_t *ele
if (element == NULL) {
return NULL;
}
return btc_ble_mesh_model_find(element, model_id);
}
@ -122,6 +127,15 @@ esp_err_t esp_ble_mesh_model_unsubscribe_group_addr(uint16_t element_addr, uint1
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#if CONFIG_BLE_MESH_DF_SRV
esp_err_t esp_ble_mesh_enable_directed_forwarding(uint16_t net_idx, bool directed_forwarding,
bool directed_forwarding_relay)
{
return btc_ble_mesh_enable_directed_forwarding(net_idx, directed_forwarding,
directed_forwarding_relay);
}
#endif /* CONFIG_BLE_MESH_DF_SRV */
#if CONFIG_BLE_MESH_NODE
const uint8_t *esp_ble_mesh_node_get_local_net_key(uint16_t net_idx)

View File

@ -35,11 +35,6 @@ static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model,
return ESP_ERR_INVALID_ARG;
}
if (device_role > ROLE_FAST_PROV) {
BT_ERR("Invalid device role 0x%02x", device_role);
return ESP_ERR_INVALID_ARG;
}
/* When data is NULL, it is mandatory to set length to 0 to prevent users from misinterpreting parameters. */
if (data == NULL) {
length = 0;
@ -61,9 +56,18 @@ static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model,
}
if (act == BTC_BLE_MESH_ACT_MODEL_PUBLISH) {
mic_len = ESP_BLE_MESH_MIC_SHORT;
/* When "send_rel" is true and "send_szmic" is 1, 8-octets TransMIC will
* be used, otherwise 4-octets TransMIC will be used.
*/
mic_len = (model->pub->send_rel && model->pub->send_szmic) ?
ESP_BLE_MESH_MIC_LONG : ESP_BLE_MESH_MIC_SHORT;
} else {
mic_len = ctx->send_rel ? ESP_BLE_MESH_MIC_LONG : ESP_BLE_MESH_MIC_SHORT;
/* When the message is tagged with the send-segmented tag and "send_szmic"
* is 1, 8-octets TransMIC will be used, otherwise 4-octets TransMIC will
* be used.
*/
mic_len = ((ctx->send_tag & ESP_BLE_MESH_TAG_SEND_SEGMENTED) && ctx->send_szmic) ?
ESP_BLE_MESH_MIC_LONG : ESP_BLE_MESH_MIC_SHORT;
}
if (op_len + length + mic_len > MIN(ESP_BLE_MESH_SDU_MAX_LEN, ESP_BLE_MESH_TX_SDU_MAX)) {
@ -89,7 +93,6 @@ static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model,
if (act == BTC_BLE_MESH_ACT_MODEL_PUBLISH) {
arg.model_publish.model = model;
arg.model_publish.device_role = device_role;
} else {
arg.model_send.model = model;
arg.model_send.ctx = ctx;
@ -97,7 +100,6 @@ static esp_err_t ble_mesh_model_send_msg(esp_ble_mesh_model_t *model,
arg.model_send.opcode = opcode;
arg.model_send.length = op_len + length;
arg.model_send.data = msg_data;
arg.model_send.device_role = device_role;
arg.model_send.msg_timeout = msg_timeout;
}
@ -254,8 +256,7 @@ esp_err_t esp_ble_mesh_node_local_reset(void)
return (btc_transfer_context(&msg, NULL, 0, NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#if (CONFIG_BLE_MESH_PROVISIONER)
#if CONFIG_BLE_MESH_PROVISIONER
esp_err_t esp_ble_mesh_provisioner_set_node_name(uint16_t index, const char *name)
{
btc_ble_mesh_prov_args_t arg = {0};
@ -312,6 +313,7 @@ esp_err_t esp_ble_mesh_provisioner_store_node_comp_data(uint16_t unicast_addr,
arg.store_node_comp_data.unicast_addr = unicast_addr;
arg.store_node_comp_data.length = length;
arg.store_node_comp_data.data = data;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), btc_ble_mesh_prov_arg_deep_copy,
btc_ble_mesh_prov_arg_deep_free) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
@ -414,6 +416,7 @@ esp_err_t esp_ble_mesh_provisioner_add_local_app_key(const uint8_t app_key[16],
} else {
bzero(arg.add_local_app_key.app_key, 16);
}
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
@ -437,6 +440,7 @@ esp_err_t esp_ble_mesh_provisioner_update_local_app_key(const uint8_t app_key[16
memcpy(arg.update_local_app_key.app_key, app_key, 16);
arg.update_local_app_key.net_idx = net_idx;
arg.update_local_app_key.app_idx = app_idx;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
@ -466,6 +470,7 @@ esp_err_t esp_ble_mesh_provisioner_bind_app_key_to_local_model(uint16_t element_
arg.local_mod_app_bind.app_idx = app_idx;
arg.local_mod_app_bind.model_id = model_id;
arg.local_mod_app_bind.cid = company_id;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
@ -491,6 +496,7 @@ esp_err_t esp_ble_mesh_provisioner_add_local_net_key(const uint8_t net_key[16],
} else {
bzero(arg.add_local_net_key.net_key, 16);
}
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
@ -512,13 +518,14 @@ esp_err_t esp_ble_mesh_provisioner_update_local_net_key(const uint8_t net_key[16
memcpy(arg.update_local_net_key.net_key, net_key, 16);
arg.update_local_net_key.net_idx = net_idx;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
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);
return bt_mesh_provisioner_net_key_get(net_idx);
}
#if CONFIG_BLE_MESH_PROVISIONER_RECV_HB
@ -760,9 +767,85 @@ uint8_t esp_ble_mesh_provisioner_get_free_settings_count(void)
}
#endif /* CONFIG_BLE_MESH_USE_MULTIPLE_NAMESPACE */
#if CONFIG_BLE_MESH_CERT_BASED_PROV
esp_err_t esp_ble_mesh_provisioner_send_prov_records_get(uint16_t link_idx)
{
btc_ble_mesh_prov_args_t arg = {0};
btc_msg_t msg = {0};
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PROV;
msg.act = BTC_BLE_MESH_ACT_PROVISIONER_SEND_PROV_RECORDS_GET;
arg.send_prov_records_get.link_idx = link_idx;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL, NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_mesh_provisioner_send_prov_record_req(uint16_t link_idx, uint16_t record_id,
uint16_t frag_offset, uint16_t max_size)
{
btc_ble_mesh_prov_args_t arg = {0};
btc_msg_t msg = {0};
if (record_id >= ESP_BLE_MESH_PROV_RECORD_MAX_ID) {
return ESP_ERR_INVALID_ARG;
}
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PROV;
msg.act = BTC_BLE_MESH_ACT_PROVISIONER_SEND_PROV_RECORD_REQUEST;
arg.send_prov_record_req.link_idx = link_idx;
arg.send_prov_record_req.record_id = record_id;
arg.send_prov_record_req.frag_offset = frag_offset;
arg.send_prov_record_req.max_size = max_size;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_mesh_provisioner_send_prov_invite(uint16_t link_idx)
{
btc_ble_mesh_prov_args_t arg = {0};
btc_msg_t msg = {0};
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PROV;
msg.act = BTC_BLE_MESH_ACT_PROVISIONER_SEND_PROV_INVITE;
arg.send_prov_invite.link_idx = link_idx;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
esp_err_t esp_ble_mesh_provisioner_send_link_close(uint16_t link_idx)
{
btc_ble_mesh_prov_args_t arg = {0};
btc_msg_t msg = {0};
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PROV;
msg.act = BTC_BLE_MESH_ACT_PROVISIONER_SEND_LINK_CLOSE;
arg.send_link_close.link_idx = link_idx;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#endif /* CONFIG_BLE_MESH_CERT_BASED_PROV */
#endif /* CONFIG_BLE_MESH_PROVISIONER */
#if (CONFIG_BLE_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);

View File

@ -38,6 +38,7 @@ static bool prov_bearers_valid(esp_ble_mesh_prov_bearer_t bearers)
!(bearers & ESP_BLE_MESH_PROV_GATT))) {
return false;
}
return true;
}
@ -169,7 +170,7 @@ esp_err_t esp_ble_mesh_set_unprovisioned_device_name(const char *name)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#if (CONFIG_BLE_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])
{
@ -305,6 +306,7 @@ esp_err_t esp_ble_mesh_provisioner_add_unprov_dev(esp_ble_mesh_unprov_dev_add_t
memcpy(arg.provisioner_dev_add.add_dev.addr, add_dev->addr, sizeof(esp_ble_mesh_bd_addr_t));
memcpy(arg.provisioner_dev_add.add_dev.uuid, add_dev->uuid, 16);
arg.provisioner_dev_add.flags = flags;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
@ -339,6 +341,7 @@ esp_err_t esp_ble_mesh_provisioner_prov_device_with_addr(const uint8_t uuid[16],
arg.provisioner_prov_dev_with_addr.bearer = bearer;
arg.provisioner_prov_dev_with_addr.oob_info = oob_info;
arg.provisioner_prov_dev_with_addr.unicast_addr = unicast_addr;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
@ -366,6 +369,7 @@ esp_err_t esp_ble_mesh_provisioner_delete_dev(esp_ble_mesh_device_delete_t *del_
} else if (del_dev->flag & DEL_DEV_UUID_FLAG) {
memcpy(arg.provisioner_dev_del.del_dev.uuid, del_dev->uuid, 16);
}
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
@ -392,6 +396,7 @@ esp_err_t esp_ble_mesh_provisioner_set_dev_uuid_match(const uint8_t *match_val,
arg.set_dev_uuid_match.match_len = match_len;
arg.set_dev_uuid_match.offset = offset;
arg.set_dev_uuid_match.prov_after_match = prov_after_match;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
@ -420,6 +425,7 @@ esp_err_t esp_ble_mesh_provisioner_set_prov_data_info(esp_ble_mesh_prov_data_inf
} else if (prov_data_info->flag & PROV_DATA_IV_INDEX_FLAG) {
arg.set_prov_data_info.prov_data.iv_index = prov_data_info->iv_index;
}
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
@ -441,6 +447,7 @@ esp_err_t esp_ble_mesh_provisioner_set_static_oob_value(const uint8_t *value, ui
arg.set_static_oob_val.length = length;
memcpy(arg.set_static_oob_val.value, value, length);
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
@ -461,16 +468,15 @@ esp_err_t esp_ble_mesh_provisioner_set_primary_elem_addr(uint16_t addr)
msg.act = BTC_BLE_MESH_ACT_PROVISIONER_SET_PRIMARY_ELEM_ADDR;
arg.set_primary_elem_addr.addr = addr;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#endif /* CONFIG_BLE_MESH_PROVISIONER */
/* The following APIs are for fast provisioning */
#if (CONFIG_BLE_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_ble_mesh_prov_args_t arg = {0};
@ -497,6 +503,7 @@ esp_err_t esp_ble_mesh_set_fast_prov_info(esp_ble_mesh_fast_prov_info_t *fast_pr
if (fast_prov_info->match_len) {
memcpy(arg.set_fast_prov_info.match_val, fast_prov_info->match_val, fast_prov_info->match_len);
}
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
@ -517,8 +524,8 @@ esp_err_t esp_ble_mesh_set_fast_prov_action(esp_ble_mesh_fast_prov_action_t acti
msg.act = BTC_BLE_MESH_ACT_SET_FAST_PROV_ACTION;
arg.set_fast_prov_action.action = action;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#endif /* CONFIG_BLE_MESH_FAST_PROV */

View File

@ -11,6 +11,8 @@
#include "btc_ble_mesh_prov.h"
#include "esp_ble_mesh_defs.h"
#include "esp_ble_mesh_local_data_operation_api.h"
#include "esp_ble_mesh_proxy_api.h"
esp_err_t esp_ble_mesh_proxy_identity_enable(void)
{
@ -166,3 +168,54 @@ esp_err_t esp_ble_mesh_proxy_client_remove_filter_addr(uint8_t conn_handle, uint
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), btc_ble_mesh_prov_arg_deep_copy,
btc_ble_mesh_prov_arg_deep_free) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#if CONFIG_BLE_MESH_DF_CLI
esp_err_t esp_ble_mesh_proxy_client_directed_proxy_set(uint8_t conn_handle, uint16_t net_idx,
uint8_t use_directed)
{
btc_ble_mesh_prov_args_t arg = {0};
btc_msg_t msg = {0};
if (use_directed > ESP_BLE_MESH_PROXY_CLI_DIRECTED_FORWARDING_ENABLE) {
return ESP_ERR_INVALID_ARG;
}
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PROV;
msg.act = BTC_BLE_MESH_ACT_PROXY_CLIENT_DIRECTED_PROXY_SET;
arg.proxy_client_directed_proxy_set.conn_handle = conn_handle;
arg.proxy_client_directed_proxy_set.net_idx = net_idx;
arg.proxy_client_directed_proxy_set.use_directed = use_directed;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), btc_ble_mesh_prov_arg_deep_copy, btc_ble_mesh_prov_arg_deep_free)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#endif /* CONFIG_BLE_MESH_DF_CLI */
#if CONFIG_BLE_MESH_PROXY_SOLIC_PDU_TX
esp_err_t esp_ble_mesh_proxy_client_send_solic_pdu(uint8_t net_idx, uint16_t ssrc, uint16_t dst)
{
btc_ble_mesh_prov_args_t arg = {0};
btc_msg_t msg = {0};
if (esp_ble_mesh_find_element(ssrc) == NULL) {
return ESP_ERR_INVALID_ARG;
}
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_PROV;
msg.act = BTC_BLE_MESH_ACT_PROXY_CLIENT_SEND_SOLIC_PDU;
arg.proxy_client_send_solic_pdu.net_idx = net_idx;
arg.proxy_client_send_solic_pdu.ssrc = ssrc;
arg.proxy_client_send_solic_pdu.dst = dst;
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL, NULL)
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
}
#endif /* CONFIG_BLE_MESH_PROXY_SOLIC_PDU_TX */

View File

@ -76,7 +76,7 @@ typedef void (* esp_ble_mesh_ble_cb_t)(esp_ble_mesh_ble_cb_event_t event,
/**
* @brief Register BLE scanning callback.
*
* @param[in] callback: Pointer to the BLE scaning callback function.
* @param[in] callback: Pointer to the BLE scanning callback function.
*
* @return ESP_OK on success or error code otherwise.
*

View File

@ -200,6 +200,24 @@ esp_err_t esp_ble_mesh_node_add_local_app_key(const uint8_t app_key[16], uint16_
esp_err_t esp_ble_mesh_node_bind_app_key_to_local_model(uint16_t element_addr, uint16_t company_id,
uint16_t model_id, uint16_t app_idx);
/**
* @brief This function used to enable directed forwarding and directed forwarding relay on self.
*
* @param[in] net_idx: NetKey Index.
* @param[in] directed_forwarding: Enable or Disable directed forwarding.
* @param[in] directed_forwarding_relay: Enable or Disable directed forwarding relay.
*
* @note If the directed forwarding was set to disable, the directed forwarding relay
* must also be set to disable.
*
* @return ESP_OK on success or error code otherwise.
*
*/
#if CONFIG_BLE_MESH_DF_SRV
esp_err_t esp_ble_mesh_enable_directed_forwarding(uint16_t net_idx, bool directed_forwarding,
bool directed_forwarding_relay);
#endif
#ifdef __cplusplus
}
#endif

View File

@ -60,7 +60,7 @@ esp_err_t esp_ble_mesh_model_msg_opcode_init(uint8_t *data, uint32_t opcode);
/**
* @brief Initialize the user-defined client model. All user-defined client models
* shall call this function to initialize the client model internal data.
* Node: Before calling this API, the op_pair_size and op_pair variabled within
* Node: Before calling this API, the op_pair_size and op_pair variables within
* the user_data(defined using esp_ble_mesh_client_t_) of the client model
* need to be initialized.
*
@ -168,7 +168,7 @@ esp_err_t esp_ble_mesh_server_model_update_state(esp_ble_mesh_model_t *model,
* @brief Reset the provisioning procedure of the local BLE Mesh node.
*
* @note All provisioning information in this node will be deleted and the node
* needs to be reprovisioned. The API function esp_ble_mesh_node_prov_enable()
* needs to be re-provisioned. The API function esp_ble_mesh_node_prov_enable()
* needs to be called to start a new provisioning procedure.
*
* @return ESP_OK on success or error code otherwise.
@ -641,6 +641,55 @@ uint8_t esp_ble_mesh_provisioner_get_free_settings_count(void);
*/
const uint8_t *esp_ble_mesh_get_fast_prov_app_key(uint16_t net_idx, uint16_t app_idx);
#if CONFIG_BLE_MESH_CERT_BASED_PROV
/**
* @brief This function is called by provisioner to send provisioning records
* get message.
*
* @param[in] link_idx: The provisioning link index.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_send_prov_records_get(uint16_t link_idx);
/**
* @brief This function is called by provisioner to send provisioning record
* request message.
*
* @param[in] link_idx: The provisioning link index.
* @param[in] record_id: The record identity.
* @param[in] frag_offset: The starting offset of the fragment.
* @param[in] max_size: The max record fragment size.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_send_prov_record_req(uint16_t link_idx, uint16_t record_id,
uint16_t frag_offset, uint16_t max_size);
/**
* @brief This function is called by provisioner to send provisioning invite
* message.
*
* @param[in] link_idx: The provisioning link index.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_send_prov_invite(uint16_t link_idx);
/**
* @brief This function is called by provisioner to send link close
*
* @param[in] link_idx: The provisioning link index.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_provisioner_send_link_close(uint16_t link_idx);
#endif /* #if CONFIG_BLE_MESH_CERT_BASED_PROV */
#ifdef __cplusplus
}
#endif

View File

@ -13,6 +13,9 @@
extern "C" {
#endif
#define ESP_BLE_MESH_PROXY_CLI_DIRECTED_FORWARDING_ENABLE 0x01
#define ESP_BLE_MESH_PROXY_CLI_DIRECTED_FORWARDING_DISABLE 0x00
/**
* @brief Enable advertising with Node Identity.
*
@ -111,6 +114,31 @@ esp_err_t esp_ble_mesh_proxy_client_add_filter_addr(uint8_t conn_handle, uint16_
esp_err_t esp_ble_mesh_proxy_client_remove_filter_addr(uint8_t conn_handle, uint16_t net_idx,
uint16_t *addr, uint16_t addr_num);
/**
* @brief Proxy Client sets whether or not the Directed Proxy Server uses directed forwarding
* for Directed Proxy Client messages.
*
* @param[in] conn_handle: Proxy connection handle.
* @param[in] net_idx: Corresponding NetKey Index.
* @param[in] use_directed: Whether or not to send message by directed forwarding.
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_proxy_client_directed_proxy_set(uint8_t conn_handle, uint16_t net_idx,
uint8_t use_directed);
/**
* @brief Proxy Client sends Solicitation PDU.
*
* @param[in] net_idx: Corresponding NetKey Index.
* @param[in] ssrc: Solicitation SRC, shall be one of its element address.
* @param[in] dst: Solicitation DST (TBD).
*
* @return ESP_OK on success or error code otherwise.
*
*/
esp_err_t esp_ble_mesh_proxy_client_send_solic_pdu(uint8_t net_idx, uint16_t ssrc, uint16_t dst);
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2017-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2017-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -36,6 +36,9 @@ extern "C" {
/*!< The maximum length of settings user id */
#define ESP_BLE_MESH_SETTINGS_UID_SIZE 20
/*!< The default value of Random Update Interval Steps */
#define ESP_BLE_MESH_RAND_UPDATE_INTERVAL_DEFAULT 0x3C
/*!< Invalid settings index */
#define ESP_BLE_MESH_INVALID_SETTINGS_IDX 0xFF
@ -80,11 +83,22 @@ typedef uint8_t esp_ble_mesh_octet8_t[ESP_BLE_MESH_OCTET8_LEN];
#define ESP_BLE_MESH_BEACON_DISABLED 0x00
#define ESP_BLE_MESH_BEACON_ENABLED 0x01
#define ESP_BLE_MESH_PRIVATE_BEACON_DISABLE 0x00
#define ESP_BLE_MESH_PRIVATE_BEACON_ENABLE 0x01
/*!< GATT Proxy state value */
#define ESP_BLE_MESH_GATT_PROXY_DISABLED 0x00
#define ESP_BLE_MESH_GATT_PROXY_ENABLED 0x01
#define ESP_BLE_MESH_GATT_PROXY_NOT_SUPPORTED 0x02
#define ESP_BLE_MESH_PRIVATE_GATT_PROXY_DISABLED 0x00
#define ESP_BLE_MESH_PRIVATE_GATT_PROXY_ENABLED 0x01
#define ESP_BLE_MESH_PRIVATE_GATT_PROXY_NOT_SUPPORTED 0x02
#define ESP_BLE_MESH_PRIVATE_NODE_IDENTITY_DISABLED 0x00
#define ESP_BLE_MESH_PRIVATE_NODE_IDENTITY_ENABLED 0x01
#define ESP_BLE_MESH_PRIVATE_NODE_IDENTITY_NOT_SUPPORTED 0x02
/*!< Friend state value */
#define ESP_BLE_MESH_FRIEND_DISABLED 0x00
#define ESP_BLE_MESH_FRIEND_ENABLED 0x01
@ -95,6 +109,10 @@ typedef uint8_t esp_ble_mesh_octet8_t[ESP_BLE_MESH_OCTET8_LEN];
#define ESP_BLE_MESH_NODE_IDENTITY_RUNNING 0x01
#define ESP_BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED 0x02
/*!< Subnet Bridge state value */
#define ESP_BLE_MESH_SUBNET_BRIDGE_DISABLED 0x00
#define ESP_BLE_MESH_SUBNET_BRIDGE_ENABLED 0x01
/*!< Supported features */
#define ESP_BLE_MESH_FEATURE_RELAY BIT(0)
#define ESP_BLE_MESH_FEATURE_PROXY BIT(1)
@ -112,6 +130,8 @@ typedef uint8_t esp_ble_mesh_octet8_t[ESP_BLE_MESH_OCTET8_LEN];
#define ESP_BLE_MESH_INVALID_NODE_INDEX 0xFFFF
#define ESP_BLE_MESH_PROV_RECORD_MAX_ID 0x0013
/** @def ESP_BLE_MESH_TRANSMIT
*
* @brief Encode transmission count & interval steps.
@ -238,7 +258,9 @@ typedef enum {
ESP_BLE_MESH_PROV_OOB_NFC = BIT(4),
ESP_BLE_MESH_PROV_OOB_NUMBER = BIT(5),
ESP_BLE_MESH_PROV_OOB_STRING = BIT(6),
/* 7 - 10 are reserved */
ESP_BLE_MESH_PROV_CERT_BASED = BIT(7),
ESP_BLE_MESH_PROV_RECORDS = BIT(8),
/* 9 - 10 are reserved */
ESP_BLE_MESH_PROV_OOB_ON_BOX = BIT(11),
ESP_BLE_MESH_PROV_OOB_IN_BOX = BIT(12),
ESP_BLE_MESH_PROV_OOB_ON_PAPER = BIT(13),
@ -317,18 +339,19 @@ typedef enum {
.input_action = in_act, \
}
typedef uint8_t UINT8;
typedef uint16_t UINT16;
typedef uint32_t UINT32;
typedef uint64_t UINT64;
typedef uint8_t UINT8 __attribute__((deprecated));
typedef uint16_t UINT16 __attribute__((deprecated));
typedef uint32_t UINT32 __attribute__((deprecated));
typedef uint64_t UINT64 __attribute__((deprecated));
#ifndef BT_OCTET32_LEN
#define BT_OCTET32_LEN 32
typedef UINT8 BT_OCTET32[BT_OCTET32_LEN]; /* octet array: size 32 */
typedef UINT8 BT_OCTET32[BT_OCTET32_LEN] __attribute__((deprecated));
#endif
#ifndef BD_ADDR_LEN
#define BD_ADDR_LEN 6
typedef uint8_t BD_ADDR[BD_ADDR_LEN];
typedef uint8_t BD_ADDR[BD_ADDR_LEN] __attribute__((deprecated));
#endif
typedef uint8_t esp_ble_mesh_bd_addr_t[BD_ADDR_LEN];
@ -340,11 +363,59 @@ typedef uint8_t esp_ble_mesh_bd_addr_t[BD_ADDR_LEN];
/// BLE device address type
typedef uint8_t esp_ble_mesh_addr_type_t;
#define ESP_BLE_MESH_DIRECTED_FORWARDING_DISABLED 0x00
#define ESP_BLE_MESH_DIRECTED_FORWARDING_ENABLED 0x01
#define ESP_BLE_MESH_DIRECTED_RELAY_DISABLED 0x00
#define ESP_BLE_MESH_DIRECTED_RELAY_ENABLED 0x01
#define ESP_BLE_MESH_DIRECTED_PROXY_IGNORE 0xFF
#define ESP_BLE_MESH_DIRECTED_PROXY_USE_DEFAULT_IGNORE 0xFF
#define ESP_BLE_MESH_DIRECTED_FRIEND_IGNORE 0xFF
#define ESP_BLE_MESH_DIRECTED_PROXY_DISABLED 0x00
#define ESP_BLE_MESH_DIRECTED_PROXY_ENABLED 0x01
#define ESP_BLE_MESH_DIRECTED_PROXY_NOT_SUPPORTED 0x02
#define ESP_BLE_MESH_DIRECTED_PROXY_USE_DEF_DISABLED 0x00
#define ESP_BLE_MESH_DIRECTED_PROXY_USE_DEF_ENABLED 0x01
#define ESP_BLE_MESH_DIRECTED_PROXY_USE_DEF_NOT_SUPPORTED 0x02
#define ESP_BLE_MESH_DIRECTED_FRIEND_DISABLED 0x00
#define ESP_BLE_MESH_DIRECTED_FRIEND_ENABLED 0x01
#define ESP_BLE_MESH_DIRECTED_FRIEND_NOT_SUPPORTED 0x02
#define ESP_BLE_MESH_DIRECTED_PUB_POLICY_FLOODING 0x00
#define ESP_BLE_MESH_DIRECTED_PUB_POLICY_FORWARD 0x01
#define ESP_BLE_MESH_PROXY_USE_DIRECTED_DISABLED 0x00
#define ESP_BLE_MESH_PROXY_USE_DIRECTED_ENABLED 0x01
#define ESP_BLE_MESH_FLOODING_CRED 0x00 /* Managed flooding security credentials */
#define ESP_BLE_MESH_FRIENDSHIP_CRED 0x01 /* Friendship security credentials */
#define ESP_BLE_MESH_DIRECTED_CRED 0x02 /* Directed security credentials */
#define ESP_BLE_MESH_TAG_SEND_SEGMENTED BIT(0) /* Tagged with send-segmented */
#define ESP_BLE_MESH_TAG_IMMUTABLE_CRED BIT(1) /* Tagged with immutable-credentials */
#define ESP_BLE_MESH_TAG_USE_DIRECTED BIT(2) /* Tagged with use-directed */
#define ESP_BLE_MESH_TAG_RELAY BIT(3) /* Tagged as relay */
#define ESP_BLE_MESH_TAG_FRIENDSHIP BIT(4) /* Tagged as a friendship PDU */
#define ESP_BLE_MESH_SEG_SZMIC_SHORT 0 /* Using 4-octets TransMIC for a segmented message */
#define ESP_BLE_MESH_SEG_SZMIC_LONG 1 /* Using 8-octets TransMIC for a segmented message */
/** BLE Mesh deinit parameters */
typedef struct {
bool erase_flash; /*!< Indicate if erasing flash when deinit mesh stack */
} esp_ble_mesh_deinit_param_t;
/** Format of Unicast Address Range */
typedef struct {
uint16_t len_present:1, /*!< Indicate the presence or absence of the RangeLength field */
range_start:15; /*!< 15 least significant bits of the starting unicast address */
uint8_t range_length; /*!< Number of addresses in the range (0x02 - 0xFF) */
} esp_ble_mesh_uar_t;
typedef struct esp_ble_mesh_model esp_ble_mesh_model_t;
/** Abstraction that describes a BLE Mesh Element.
@ -374,7 +445,8 @@ typedef struct {
uint16_t publish_addr; /*!< Publish Address. */
uint16_t app_idx:12, /*!< Publish AppKey Index. */
cred:1, /*!< Friendship Credentials Flag. */
send_rel:1; /*!< Force reliable sending (segment acks) */
send_rel:1, /*!< Force reliable sending (segment acks) */
send_szmic:1; /*!< Size of TransMIC when publishing a Segmented Access message */
uint8_t ttl; /*!< Publish Time to Live. */
uint8_t retransmit; /*!< Retransmit Count & Interval Steps. */
@ -386,6 +458,10 @@ typedef struct {
uint32_t period_start; /*!< Start of the current period. */
#if CONFIG_BLE_MESH_DF_SRV
uint8_t directed_pub_policy; /*!< Directed publish policy */
#endif
/** @brief Publication buffer, containing the publication message.
*
* This will get correctly created when the publication context
@ -402,7 +478,7 @@ typedef struct {
struct k_delayed_work timer;
/** Role of the device that is going to publish messages */
uint8_t dev_role;
uint8_t dev_role __attribute__((deprecated));
} esp_ble_mesh_model_pub_t;
/** @def ESP_BLE_MESH_MODEL_PUB_DEFINE
@ -418,7 +494,6 @@ typedef struct {
static esp_ble_mesh_model_pub_t _name = { \
.update = (uint32_t)NULL, \
.msg = &bt_mesh_pub_msg_##_name, \
.dev_role = _role, \
}
/** @def ESP_BLE_MESH_MODEL_OP
@ -524,26 +599,41 @@ typedef struct {
/** Destination address of a received message. Not used for sending. */
uint16_t recv_dst;
/** RSSI of received packet. Not used for sending. */
/** RSSI of a received message. Not used for sending. */
int8_t recv_rssi;
/** Received TTL value. Not used for sending. */
uint8_t recv_ttl: 7;
/** Opcode of a received message. Not used for sending. */
uint32_t recv_op;
/** Force sending reliably by using segment acknowledgement */
uint8_t send_rel: 1;
/** Received TTL value. Not used for sending. */
uint8_t recv_ttl;
/** Security credentials of a received message. Not used for sending. */
uint8_t recv_cred;
/** Tag of a received message. Not used for sending. */
uint8_t recv_tag;
/** Force sending reliably by using segment acknowledgement. */
uint8_t send_rel:1 __attribute__((deprecated));
/** Size of TransMIC when sending a Segmented Access message. */
uint8_t send_szmic:1;
/** TTL, or ESP_BLE_MESH_TTL_DEFAULT for default TTL. */
uint8_t send_ttl;
/** Opcode of a received message. Not used for sending message. */
uint32_t recv_op;
/** Security credentials used for sending the message */
uint8_t send_cred;
/** Tag used for sending the message. */
uint8_t send_tag;
/** Model corresponding to the message, no need to be initialized before sending message */
esp_ble_mesh_model_t *model;
esp_ble_mesh_model_t *model __attribute__((deprecated));
/** Indicate if the message is sent by a node server model, no need to be initialized before sending message */
bool srv_send;
bool srv_send __attribute__((deprecated));
} esp_ble_mesh_msg_ctx_t;
/** Provisioning properties & capabilities.
@ -576,6 +666,9 @@ typedef struct {
/** Callback used to notify to set OOB Public Key. Initialized by the stack. */
esp_ble_mesh_cb_t oob_pub_key_cb;
/** OOB type */
uint8_t oob_type;
/** Static OOB value */
const uint8_t *static_val;
/** Static OOB value length */
@ -668,6 +761,12 @@ typedef struct {
esp_ble_mesh_cb_t provisioner_link_close;
/** Callback used to indicate that a device is provisioned. Initialized by the stack. */
esp_ble_mesh_cb_t provisioner_prov_comp;
/** Callback used to indicate that certificate based provisioning needs to start. Initialized by the stack. */
esp_ble_mesh_cb_t cert_based_prov_start;
/** Callback used to indicate that provisioner has received provisioning records list successfully. Initialized by the stack. */
esp_ble_mesh_cb_t records_list_get;
/** Callback used to indicate that provisioner has received a complete provisioning record successfully. Initialized by the stack. */
esp_ble_mesh_cb_t prov_record_recv_comp;
#endif /* CONFIG_BLE_MESH_PROVISIONER */
} esp_ble_mesh_prov_t;
@ -710,7 +809,9 @@ typedef struct {
#define DEL_DEV_UUID_FLAG BIT(1)
/** Information of the device which is going to be deleted. */
typedef struct {
/** Union of Device information */
union {
/** Device address */
struct {
esp_ble_mesh_bd_addr_t addr; /*!< Device address */
esp_ble_mesh_addr_type_t addr_type; /*!< Device address type */
@ -725,6 +826,7 @@ typedef struct {
#define PROV_DATA_IV_INDEX_FLAG BIT(2)
/** Information of the provisioner which is going to be updated. */
typedef struct {
/** Provisioning data */
union {
uint16_t net_idx; /*!< NetKey Index */
uint8_t flags; /*!< Flags */
@ -828,6 +930,13 @@ typedef enum {
ESP_BLE_MESH_PROVISIONER_PROV_LINK_OPEN_EVT, /*!< Provisioner establish a BLE Mesh link event */
ESP_BLE_MESH_PROVISIONER_PROV_LINK_CLOSE_EVT, /*!< Provisioner close a BLE Mesh link event */
ESP_BLE_MESH_PROVISIONER_PROV_COMPLETE_EVT, /*!< Provisioner provisioning done event */
ESP_BLE_MESH_PROVISIONER_CERT_BASED_PROV_START_EVT, /*!< Provisioner initiate a certificate based provisioning */
ESP_BLE_MESH_PROVISIONER_RECV_PROV_RECORDS_LIST_EVT, /*!< Provisioner receive provisioning records list event */
ESP_BLE_MESH_PROVISIONER_PROV_RECORD_RECV_COMP_EVT, /*!< Provisioner receive provisioning record complete event */
ESP_BLE_MESH_PROVISIONER_SEND_PROV_RECORDS_GET_EVT, /*!< Provisioner send provisioning records get to device event */
ESP_BLE_MESH_PROVISIONER_SEND_PROV_RECORD_REQUEST_EVT, /*!< Provisioner send provisioning record request to device event */
ESP_BLE_MESH_PROVISIONER_SEND_PROV_INVITE_EVT, /*!< Provisioner send provisioning invite to device event */
ESP_BLE_MESH_PROVISIONER_SEND_LINK_CLOSE_EVT, /*!< Provisioner send link close to device event */
ESP_BLE_MESH_PROVISIONER_ADD_UNPROV_DEV_COMP_EVT, /*!< Provisioner add a device to the list which contains devices that are waiting/going to be provisioned completion event */
ESP_BLE_MESH_PROVISIONER_PROV_DEV_WITH_ADDR_COMP_EVT, /*!< Provisioner start to provision an unprovisioned device completion event */
ESP_BLE_MESH_PROVISIONER_DELETE_DEV_COMP_EVT, /*!< Provisioner delete a device from the list, close provisioning link with the device completion event */
@ -877,8 +986,10 @@ typedef enum {
ESP_BLE_MESH_PROXY_CLIENT_SET_FILTER_TYPE_COMP_EVT, /*!< Proxy Client set filter type completion event */
ESP_BLE_MESH_PROXY_CLIENT_ADD_FILTER_ADDR_COMP_EVT, /*!< Proxy Client add filter address completion event */
ESP_BLE_MESH_PROXY_CLIENT_REMOVE_FILTER_ADDR_COMP_EVT, /*!< Proxy Client remove filter address completion event */
ESP_BLE_MESH_PROXY_CLIENT_DIRECTED_PROXY_SET_COMP_EVT, /*!< Proxy Client directed proxy set completion event */
ESP_BLE_MESH_PROXY_SERVER_CONNECTED_EVT, /*!< Proxy Server establishes connection successfully event */
ESP_BLE_MESH_PROXY_SERVER_DISCONNECTED_EVT, /*!< Proxy Server terminates connection successfully event */
ESP_BLE_MESH_PROXY_CLIENT_SEND_SOLIC_PDU_COMP_EVT, /*!< Proxy Client send Solicitation PDU completion event */
ESP_BLE_MESH_MODEL_SUBSCRIBE_GROUP_ADDR_COMP_EVT, /*!< Local model subscribes group address completion event */
ESP_BLE_MESH_MODEL_UNSUBSCRIBE_GROUP_ADDR_COMP_EVT, /*!< Local model unsubscribes group address completion event */
ESP_BLE_MESH_DEINIT_MESH_COMP_EVT, /*!< De-initialize BLE Mesh stack completion event */
@ -924,6 +1035,7 @@ typedef union {
*/
struct ble_mesh_link_close_evt_param {
esp_ble_mesh_prov_bearer_t bearer; /*!< Type of the bearer used when device link is closed */
uint8_t reason; /*!< Reason of the closed provisioning link */
} node_prov_link_close; /*!< Event parameter of ESP_BLE_MESH_NODE_PROV_LINK_CLOSE_EVT */
/**
* @brief ESP_BLE_MESH_NODE_PROV_OUTPUT_NUMBER_EVT
@ -1030,7 +1142,7 @@ typedef union {
esp_ble_mesh_bd_addr_t addr; /*!< Device address of the unprovisioned device */
esp_ble_mesh_addr_type_t addr_type; /*!< Device address type */
uint16_t oob_info; /*!< OOB Info of the unprovisioned device */
uint8_t adv_type; /*!< Avertising type of the unprovisioned device */
uint8_t adv_type; /*!< Advertising type of the unprovisioned device */
esp_ble_mesh_prov_bearer_t bearer; /*!< Bearer of the unprovisioned device */
int8_t rssi; /*!< RSSI of the received advertising packet */
} provisioner_recv_unprov_adv_pkt; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_RECV_UNPROV_ADV_PKT_EVT */
@ -1075,6 +1187,7 @@ typedef union {
esp_ble_mesh_input_action_t action; /*!< Action of device Input OOB Authentication */
uint8_t size; /*!< Size of device Input OOB Authentication */
uint8_t link_idx; /*!< Index of the provisioning link */
/** Union of output OOB */
union {
char string[8]; /*!< String output by the Provisioner */
uint32_t number; /*!< Number output by the Provisioner */
@ -1097,6 +1210,62 @@ typedef union {
uint8_t element_num; /*!< Element count of the provisioned device */
uint16_t netkey_idx; /*!< NetKey Index of the provisioned device */
} provisioner_prov_complete; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_PROV_COMPLETE_EVT */
/**
* @brief ESP_BLE_MESH_PROVISIONER_CERT_BASED_PROV_START_EVT
*/
struct ble_mesh_provisioner_cert_based_prov_start_evt_param {
uint16_t link_idx; /*!< Index of the provisioning link */
} provisioner_cert_based_prov_start; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_CERT_BASED_PROV_START_EVT */
/**
* @brief ESP_BLE_MESH_PROVISIONER_RECV_PROV_RECORDS_LIST_EVT
*/
struct ble_mesh_provisioner_recv_prov_records_list_evt_param {
uint16_t link_idx; /*!< Index of the provisioning link */
uint16_t len; /*!< Length of message */
uint8_t *msg; /*!< Lists the Record IDs of the provisioning records stored on the Provisionee */
} recv_provisioner_records_list; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_RECV_PROV_RECORDS_LIST_EVT */
/**
* @brief ESP_BLE_MESH_PROVISIONER_PROV_RECORD_RECV_COMP_EVT
*/
struct ble_mesh_provisioner_prov_record_recv_comp_evt_param {
uint8_t status; /*!< Indicates whether or not the request was handled successfully */
uint16_t link_idx; /*!< Index of the provisioning link */
uint16_t record_id; /*!< Identifies the provisioning record for which the request is made */
uint16_t frag_offset; /*!< The starting offset of the requested fragment in the provisioning record data */
uint16_t total_len; /*!< Total length of the provisioning record data stored on the Provisionee */
uint8_t *record; /*!< Provisioning record data fragment */
} provisioner_prov_record_recv_comp; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_PROV_RECORD_RECV_COMP_EVT */
/**
* @brief ESP_BLE_MESH_PROVISIONER_SEND_PROV_RECORDS_GET_EVT
*/
struct ble_mesh_provisioner_send_prov_records_get_evt_param {
int err_code; /*!< Indicate the result of send Provisioning Records List Get message */
uint16_t link_idx; /*!< Index of the provisioning link */
} provisioner_send_records_get; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_SEND_PROV_RECORDS_GET_EVT */
/**
* @brief ESP_BLE_MESH_PROVISIONER_SEND_PROV_RECORD_REQUEST_EVT
*/
struct ble_mesh_provisioner_send_prov_record_req_evt_param {
int err_code; /*!< Indicate the result of send Provisioning Record Request message */
uint16_t link_idx; /*!< Index of the provisioning link */
uint16_t record_id; /*!< Identifies the provisioning record for which the request is made */
uint16_t frag_offset; /*!< The starting offset of the requested fragment in the provisioning record data */
uint16_t max_size; /*!< The maximum size of the provisioning record fragment that the Provisioner can receive */
} provisioner_send_record_req; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_SEND_PROV_RECORD_REQUEST_EVT */
/**
* @brief ESP_BLE_MESH_PROVISIONER_SEND_PROV_INVITE_EVT
*/
struct ble_mesh_provisioner_send_prov_invite_evt_param {
uint16_t link_idx; /*!< Index of the provisioning link */
int err_code; /*!< Indicate the result of send Provisioning Invite message */
} provisioner_send_prov_invite; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_SEND_PROV_INVITE_EVT */
/**
* @brief ESP_BLE_MESH_PROVISIONER_SEND_LINK_CLOSE_EVT
*/
struct ble_mesh_provisioner_send_link_close_evt_param {
uint16_t link_idx; /*!< Index of the provisioning link */
int err_code; /*!< Indicate the result of send Link Close message */
} provisioner_send_link_close; /*!< Event parameter of ESP_BLE_MESH_PROVISIONER_SEND_LINK_CLOSE_EVT */
/**
* @brief ESP_BLE_MESH_PROVISIONER_ADD_UNPROV_DEV_COMP_EVT
*/
@ -1461,6 +1630,14 @@ typedef union {
uint8_t conn_handle; /*!< Proxy connection handle */
uint16_t net_idx; /*!< Corresponding NetKey Index */
} proxy_client_remove_filter_addr_comp; /*!< Event parameter of ESP_BLE_MESH_PROXY_CLIENT_REMOVE_FILTER_ADDR_COMP_EVT */
/**
* @brief ESP_BLE_MESH_PROXY_CLIENT_DIRECTED_PROXY_CONTROL_COMP_EVT
*/
struct ble_mesh_proxy_client_directed_proxy_set_param {
int err_code; /*!< Indicate the result of Proxy Client directed proxy control address */
uint8_t conn_handle; /*!< Proxy connection handle */
uint16_t net_idx; /*!< Corresponding NetKey Index */
} proxy_client_directed_proxy_set_comp; /*!< Event parameter of ESP_BLE_MESH_PROXY_CLIENT_DIRECTED_PROXY_SET_COMP_EVT */
/**
* @brief ESP_BLE_MESH_PROXY_SERVER_CONNECTED_EVT
*/
@ -1474,6 +1651,15 @@ typedef union {
uint8_t conn_handle; /*!< Proxy connection handle */
uint8_t reason; /*!< Proxy disconnect reason */
} proxy_server_disconnected; /*!< Event parameter of ESP_BLE_MESH_PROXY_SERVER_DISCONNECTED_EVT */
/**
* @brief ESP_BLE_MESH_PROXY_CLIENT_SEND_SOLIC_PDU_COMP_EVT
*/
struct {
int err_code; /*!< Indicate the result of Proxy Client send Solicitation PDU */
uint16_t net_idx; /*!< Corresponding NetKey Index */
uint16_t ssrc; /*!< Solicitation SRC */
uint16_t dst; /*!< Solicitation DST */
} proxy_client_send_solic_pdu_comp; /*!< Event parameter of ESP_BLE_MESH_PROXY_CLIENT_SEND_SOLIC_PDU_COMP_EVT */
/**
* @brief ESP_BLE_MESH_MODEL_SUBSCRIBE_GROUP_ADDR_COMP_EVT
*/
@ -1500,7 +1686,7 @@ typedef union {
struct ble_mesh_deinit_mesh_comp_param {
int err_code; /*!< Indicate the result of BLE Mesh deinitialization */
} deinit_mesh_comp; /*!< Event parameter of ESP_BLE_MESH_DEINIT_MESH_COMP_EVT */
} esp_ble_mesh_prov_cb_param_t;
} esp_ble_mesh_prov_cb_param_t; /*!< Event parameters of ESP_BLE_MESH_DEINIT_MESH_COMP_EVT */
/**
* @brief BLE Mesh models related Model ID and Opcode definitions
@ -1511,6 +1697,24 @@ typedef union {
#define ESP_BLE_MESH_MODEL_ID_CONFIG_CLI 0x0001
#define ESP_BLE_MESH_MODEL_ID_HEALTH_SRV 0x0002
#define ESP_BLE_MESH_MODEL_ID_HEALTH_CLI 0x0003
#define ESP_BLE_MESH_MODEL_ID_RPR_SRV 0x0004
#define ESP_BLE_MESH_MODEL_ID_RPR_CLI 0x0005
#define ESP_BLE_MESH_MODEL_ID_DF_SRV 0x0006
#define ESP_BLE_MESH_MODEL_ID_DF_CLI 0x0007
#define ESP_BLE_MESH_MODEL_ID_BRC_SRV 0x0008
#define ESP_BLE_MESH_MODEL_ID_BRC_CLI 0x0009
#define ESP_BLE_MESH_MODEL_ID_PRB_SRV 0x000A
#define ESP_BLE_MESH_MODEL_ID_PRB_CLI 0x000B
#define ESP_BLE_MESH_MODEL_ID_ODP_SRV 0x000C
#define ESP_BLE_MESH_MODEL_ID_ODP_CLI 0x000D
#define ESP_BLE_MESH_MODEL_ID_SAR_SRV 0x000E
#define ESP_BLE_MESH_MODEL_ID_SAR_CLI 0x000F
#define ESP_BLE_MESH_MODEL_ID_AGG_SRV 0x0010
#define ESP_BLE_MESH_MODEL_ID_AGG_CLI 0x0011
#define ESP_BLE_MESH_MODEL_ID_LCD_SRV 0x0012
#define ESP_BLE_MESH_MODEL_ID_LCD_CLI 0x0013
#define ESP_BLE_MESH_MODEL_ID_SRPL_SRV 0x0014
#define ESP_BLE_MESH_MODEL_ID_SRPL_CLI 0x0015
/*!< Models from the Mesh Model Specification */
#define ESP_BLE_MESH_MODEL_ID_GEN_ONOFF_SRV 0x1000
@ -1565,6 +1769,8 @@ typedef union {
#define ESP_BLE_MESH_MODEL_ID_LIGHT_LC_SRV 0x130f
#define ESP_BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV 0x1310
#define ESP_BLE_MESH_MODEL_ID_LIGHT_LC_CLI 0x1311
#define ESP_BLE_MESH_MODEL_ID_MBT_SRV 0x1400
#define ESP_BLE_MESH_MODEL_ID_MBT_CLI 0x1401
/**
* esp_ble_mesh_opcode_config_client_get_t belongs to esp_ble_mesh_opcode_t, this typedef is only
@ -1686,6 +1892,10 @@ typedef uint8_t esp_ble_mesh_cfg_status_t;
#define ESP_BLE_MESH_CFG_STATUS_CANNOT_SET 0x0F
#define ESP_BLE_MESH_CFG_STATUS_UNSPECIFIED_ERROR 0x10
#define ESP_BLE_MESH_CFG_STATUS_INVALID_BINDING 0x11
#define ESP_BLE_MESH_CFG_STATUS_INVALID_PATH_ENTRY 0x12
#define ESP_BLE_MESH_CFG_STATUS_CANNOT_GET 0x13
#define ESP_BLE_MESH_CFG_STATUS_OBSOLETE_INFO 0x14
#define ESP_BLE_MESH_CFG_STATUS_INVALID_BEARER 0x15
/**
* esp_ble_mesh_opcode_health_client_get_t belongs to esp_ble_mesh_opcode_t, this typedef is
@ -2037,11 +2247,12 @@ typedef struct {
/** Client Model user data context. */
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to the client model. Initialized by the stack. */
int op_pair_size; /*!< Size of the op_pair */
uint32_t op_pair_size; /*!< Size of the op_pair */
const esp_ble_mesh_client_op_pair_t *op_pair; /*!< Table containing get/set message opcode and corresponding status message opcode */
uint32_t publish_status; /*!< Callback used to handle the received unsolicited message. Initialized by the stack. */
void *internal_data; /*!< Pointer to the internal data of client model */
uint8_t msg_role; /*!< Role of the device (Node/Provisioner) that is going to send messages */
void *vendor_data; /*!< Pointer to the vendor data of client model */
uint8_t msg_role __attribute__((deprecated)); /*!< Role of the device (Node/Provisioner) that is going to send messages */
} esp_ble_mesh_client_t;
/** Common parameters of the messages sent by Client Model. */
@ -2051,7 +2262,7 @@ typedef struct {
esp_ble_mesh_msg_ctx_t ctx; /*!< The context used to send message */
int32_t msg_timeout; /*!< Timeout value (ms) to get response to the sent message */
/*!< Note: if using default timeout value in menuconfig, make sure to set this value to 0 */
uint8_t msg_role; /*!< Role of the device - Node/Provisioner */
uint8_t msg_role __attribute__((deprecated)); /*!< Role of the device - Node/Provisioner */
} esp_ble_mesh_client_common_param_t;
/**

View File

@ -42,7 +42,7 @@ extern "C" {
NULL, NULL, cli_data)
/** Configuration Server Model context */
typedef struct esp_ble_mesh_cfg_srv {
typedef struct {
esp_ble_mesh_model_t *model; /*!< Pointer to Configuration Server Model */
uint8_t net_transmit; /*!< Network Transmit state */
@ -610,6 +610,7 @@ typedef enum {
* @brief Configuration Server model related context.
*/
/** Parameters of Config Model Publication Set */
typedef struct {
uint16_t element_addr; /*!< Element Address */
uint16_t pub_addr; /*!< Publish Address */
@ -622,6 +623,19 @@ typedef struct {
uint16_t model_id; /*!< Model ID */
} esp_ble_mesh_state_change_cfg_mod_pub_set_t;
/** Parameters of Config Model Publication Virtual Address Set */
typedef struct {
uint16_t element_addr; /*!< Element Address */
uint8_t label_uuid[16]; /*!< Label UUID */
uint16_t app_idx; /*!< AppKey Index */
bool cred_flag; /*!< Friendship Credential Flag */
uint8_t pub_ttl; /*!< Publish TTL */
uint8_t pub_period; /*!< Publish Period */
uint8_t pub_retransmit; /*!< Publish Retransmit */
uint16_t company_id; /*!< Company ID */
uint16_t model_id; /*!< Model ID */
} esp_ble_mesh_state_change_cfg_mod_pub_va_set_t;
/** Parameters of Config Model Subscription Add */
typedef struct {
uint16_t element_addr; /*!< Element Address */
@ -705,6 +719,7 @@ typedef union {
* The recv_op in ctx can be used to decide which state is changed.
*/
esp_ble_mesh_state_change_cfg_mod_pub_set_t mod_pub_set; /*!< Config Model Publication Set */
esp_ble_mesh_state_change_cfg_mod_pub_va_set_t mod_pub_va_set; /*!< Config Model Publication Virtual Address Set */
esp_ble_mesh_state_change_cfg_model_sub_add_t mod_sub_add; /*!< Config Model Subscription Add */
esp_ble_mesh_state_change_cfg_model_sub_delete_t mod_sub_delete; /*!< Config Model Subscription Delete */
esp_ble_mesh_state_change_cfg_netkey_add_t netkey_add; /*!< Config NetKey Add */

View File

@ -134,7 +134,7 @@ typedef struct {
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t ctl_lightness; /*!< Target value of light ctl lightness state */
uint16_t ctl_temperatrue; /*!< Target value of light ctl temperature state */
uint16_t ctl_temperature; /*!< Target value of light ctl temperature state */
int16_t ctl_delta_uv; /*!< Target value of light ctl delta UV state */
uint8_t tid; /*!< Transaction ID */
uint8_t trans_time; /*!< Time to complete state transition (optional) */
@ -144,7 +144,7 @@ typedef struct {
/** Parameters of Light CTL Temperature Set */
typedef struct {
bool op_en; /*!< Indicate if optional parameters are included */
uint16_t ctl_temperatrue; /*!< Target value of light ctl temperature state */
uint16_t ctl_temperature; /*!< Target value of light ctl temperature state */
int16_t ctl_delta_uv; /*!< Target value of light ctl delta UV state */
uint8_t tid; /*!< Transaction ID */
uint8_t trans_time; /*!< Time to complete state transition (optional) */

View File

@ -468,7 +468,7 @@ esp_err_t esp_ble_mesh_time_scene_client_set_state(esp_ble_mesh_client_common_pa
#define ESP_BLE_MESH_TIME_NONE 0x00 /*!< Time Role - None */
#define ESP_BLE_MESH_TIME_AUTHORITY 0x01 /*!< Time Role - Mesh Time Authority */
#define ESP_BLE_MESH_TIME_RELAY 0x02 /*!< Time Role - Mesh Time Relay */
#define ESP_BLE_MESH_TIME_CLINET 0x03 /*!< Time Role - Mesh Time Client */
#define ESP_BLE_MESH_TIME_CLIENT 0x03 /*!< Time Role - Mesh Time Client */
#define ESP_BLE_MESH_SCENE_SUCCESS 0x00 /*!< Scene operation - Success */
#define ESP_BLE_MESH_SCENE_REG_FULL 0x01 /*!< Scene operation - Scene Register Full */
@ -482,7 +482,7 @@ typedef struct {
uint8_t uncertainty; /*!< The value of the Uncertainty field */
uint8_t time_zone_offset_curr; /*!< The value of the Time Zone Offset Current field */
uint8_t time_zone_offset_new; /*!< The value of the Time Zone Offset New state */
uint8_t tai_zone_change[5]; /*!< The value of the TAI of Zone Chaneg field */
uint8_t tai_zone_change[5]; /*!< The value of the TAI of Zone Change field */
uint16_t time_authority : 1, /*!< The value of the Time Authority bit */
tai_utc_delta_curr : 15; /*!< The value of the TAI-UTC Delta Current state */
uint16_t tai_utc_delta_new : 15; /*!< The value of the TAI-UTC Delta New state */

View File

@ -7,8 +7,8 @@
#include <string.h>
#include <errno.h>
#include "btc_ble_mesh_model_common.h"
#include "btc_ble_mesh_config_model.h"
#include "foundation.h"
#include "esp_ble_mesh_config_model_api.h"
#if CONFIG_BLE_MESH_CFG_CLI
@ -143,8 +143,8 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des
case ESP_BLE_MESH_CFG_CLIENT_PUBLISH_EVT:
if (p_src_data->params) {
switch (p_src_data->params->opcode) {
case OP_DEV_COMP_DATA_GET:
case OP_DEV_COMP_DATA_STATUS:
case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET:
case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_STATUS:
if (p_src_data->status_cb.comp_data_status.composition_data) {
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);
@ -157,10 +157,10 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des
p_src_data->status_cb.comp_data_status.composition_data->len);
}
break;
case OP_MOD_SUB_GET:
case OP_MOD_SUB_GET_VND:
case OP_MOD_SUB_LIST:
case OP_MOD_SUB_LIST_VND:
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET:
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_GET:
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_LIST:
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_LIST:
if (p_src_data->status_cb.model_sub_list.sub_addr) {
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);
@ -173,8 +173,8 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des
p_src_data->status_cb.model_sub_list.sub_addr->len);
}
break;
case OP_NET_KEY_GET:
case OP_NET_KEY_LIST:
case ESP_BLE_MESH_MODEL_OP_NET_KEY_GET:
case ESP_BLE_MESH_MODEL_OP_NET_KEY_LIST:
if (p_src_data->status_cb.netkey_list.net_idx) {
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);
@ -187,8 +187,8 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des
p_src_data->status_cb.netkey_list.net_idx->len);
}
break;
case OP_APP_KEY_GET:
case OP_APP_KEY_LIST:
case ESP_BLE_MESH_MODEL_OP_APP_KEY_GET:
case ESP_BLE_MESH_MODEL_OP_APP_KEY_LIST:
if (p_src_data->status_cb.appkey_list.app_idx) {
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);
@ -201,10 +201,10 @@ static void btc_ble_mesh_config_client_copy_req_data(btc_msg_t *msg, void *p_des
p_src_data->status_cb.appkey_list.app_idx->len);
}
break;
case OP_SIG_MOD_APP_GET:
case OP_VND_MOD_APP_GET:
case OP_SIG_MOD_APP_LIST:
case OP_VND_MOD_APP_LIST:
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET:
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_GET:
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_LIST:
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_LIST:
if (p_src_data->status_cb.model_app_list.app_idx) {
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);
@ -245,28 +245,28 @@ static void btc_ble_mesh_config_client_free_req_data(btc_msg_t *msg)
case ESP_BLE_MESH_CFG_CLIENT_PUBLISH_EVT:
if (arg->params) {
switch (arg->params->opcode) {
case OP_DEV_COMP_DATA_GET:
case OP_DEV_COMP_DATA_STATUS:
case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_GET:
case ESP_BLE_MESH_MODEL_OP_COMPOSITION_DATA_STATUS:
bt_mesh_free_buf(arg->status_cb.comp_data_status.composition_data);
break;
case OP_MOD_SUB_GET:
case OP_MOD_SUB_GET_VND:
case OP_MOD_SUB_LIST:
case OP_MOD_SUB_LIST_VND:
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_GET:
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_GET:
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_SUB_LIST:
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_SUB_LIST:
bt_mesh_free_buf(arg->status_cb.model_sub_list.sub_addr);
break;
case OP_NET_KEY_GET:
case OP_NET_KEY_LIST:
case ESP_BLE_MESH_MODEL_OP_NET_KEY_GET:
case ESP_BLE_MESH_MODEL_OP_NET_KEY_LIST:
bt_mesh_free_buf(arg->status_cb.netkey_list.net_idx);
break;
case OP_APP_KEY_GET:
case OP_APP_KEY_LIST:
case ESP_BLE_MESH_MODEL_OP_APP_KEY_GET:
case ESP_BLE_MESH_MODEL_OP_APP_KEY_LIST:
bt_mesh_free_buf(arg->status_cb.appkey_list.app_idx);
break;
case OP_SIG_MOD_APP_GET:
case OP_VND_MOD_APP_GET:
case OP_SIG_MOD_APP_LIST:
case OP_VND_MOD_APP_LIST:
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_GET:
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_GET:
case ESP_BLE_MESH_MODEL_OP_SIG_MODEL_APP_LIST:
case ESP_BLE_MESH_MODEL_OP_VENDOR_MODEL_APP_LIST:
bt_mesh_free_buf(arg->status_cb.model_app_list.app_idx);
break;
default:
@ -287,8 +287,6 @@ static void btc_ble_mesh_config_client_callback(esp_ble_mesh_cfg_client_cb_param
{
btc_msg_t msg = {0};
BT_DBG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_CONFIG_CLIENT)) {
return;
@ -311,7 +309,7 @@ void bt_mesh_config_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
esp_ble_mesh_client_common_param_t params = {0};
uint8_t act = 0U;
if (!model || !ctx) {
if (!model || !ctx || len > sizeof(cb_params.status_cb)) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
@ -349,14 +347,14 @@ void bt_mesh_config_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
cb_params.params = &params;
if (val && len) {
memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb)));
memcpy(&cb_params.status_cb, val, len);
}
btc_ble_mesh_config_client_callback(&cb_params, act);
return;
}
void btc_ble_mesh_config_client_publish_callback(uint32_t opcode, struct bt_mesh_model *model,
void btc_ble_mesh_config_client_publish_callback(uint32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
@ -367,7 +365,6 @@ void btc_ble_mesh_config_client_publish_callback(uint32_t opcode, struct bt_mesh
bt_mesh_config_client_cb_evt_to_btc(opcode, BTC_BLE_MESH_EVT_CONFIG_CLIENT_PUBLISH,
model, ctx, buf->data, buf->len);
return;
}
static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param_t *params,
@ -400,15 +397,7 @@ static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param
break;
}
param.opcode = params->opcode;
param.model = (struct bt_mesh_model *)params->model;
param.ctx.net_idx = params->ctx.net_idx;
param.ctx.app_idx = BLE_MESH_KEY_DEV;
param.ctx.addr = params->ctx.addr;
param.ctx.send_rel = params->ctx.send_rel;
param.ctx.send_ttl = params->ctx.send_ttl;
param.msg_timeout = params->msg_timeout;
param.msg_role = params->msg_role;
btc_ble_mesh_set_client_common_param(params, &param, true);
switch (param.opcode) {
case ESP_BLE_MESH_MODEL_OP_BEACON_GET:
@ -461,8 +450,6 @@ static int btc_ble_mesh_config_client_get_state(esp_ble_mesh_client_common_param
BT_ERR("Invalid Configuration Get opcode 0x%04x", param.opcode);
return -EINVAL;
}
return 0;
}
static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param_t *params,
@ -480,15 +467,7 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param
return -EINVAL;
}
param.opcode = params->opcode;
param.model = (struct bt_mesh_model *)params->model;
param.ctx.net_idx = params->ctx.net_idx;
param.ctx.app_idx = BLE_MESH_KEY_DEV;
param.ctx.addr = params->ctx.addr;
param.ctx.send_rel = params->ctx.send_rel;
param.ctx.send_ttl = params->ctx.send_ttl;
param.msg_timeout = params->msg_timeout;
param.msg_role = params->msg_role;
btc_ble_mesh_set_client_common_param(params, &param, true);
switch (param.opcode) {
case ESP_BLE_MESH_MODEL_OP_BEACON_SET:
@ -609,8 +588,6 @@ static int btc_ble_mesh_config_client_set_state(esp_ble_mesh_client_common_param
BT_ERR("Invalid Configuration Set opcode 0x%04x", param.opcode);
return -EINVAL;
}
return 0;
}
void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg)
@ -649,7 +626,6 @@ void btc_ble_mesh_config_client_call_handler(btc_msg_t *msg)
}
btc_ble_mesh_config_client_arg_deep_free(msg);
return;
}
void btc_ble_mesh_config_client_cb_handler(btc_msg_t *msg)
@ -670,7 +646,6 @@ void btc_ble_mesh_config_client_cb_handler(btc_msg_t *msg)
}
btc_ble_mesh_config_client_free_req_data(msg);
return;
}
#endif /* CONFIG_BLE_MESH_CFG_CLI */
@ -691,8 +666,6 @@ static void btc_ble_mesh_config_server_callback(esp_ble_mesh_cfg_server_cb_param
{
btc_msg_t msg = {0};
BT_DBG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_CONFIG_SERVER)) {
return;
@ -705,14 +678,15 @@ static void btc_ble_mesh_config_server_callback(esp_ble_mesh_cfg_server_cb_param
btc_transfer_context(&msg, cb_params, cb_params == NULL ? 0 : sizeof(esp_ble_mesh_cfg_server_cb_param_t), NULL, NULL);
}
void bt_mesh_config_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model *model,
void bt_mesh_config_server_cb_evt_to_btc(uint8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const uint8_t *val, size_t len)
{
esp_ble_mesh_cfg_server_cb_param_t cb_params = {0};
uint8_t act = 0U;
if (!model || !ctx) {
if (!model || !ctx || len > sizeof(cb_params.value)) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
@ -737,11 +711,10 @@ void bt_mesh_config_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model
cb_params.ctx.send_ttl = ctx->send_ttl;
if (val && len) {
memcpy(&cb_params.value, val, MIN(len, sizeof(cb_params.value)));
memcpy(&cb_params.value, val, len);
}
btc_ble_mesh_config_server_callback(&cb_params, act);
return;
}
void btc_ble_mesh_config_server_cb_handler(btc_msg_t *msg)

View File

@ -7,6 +7,7 @@
#include <string.h>
#include <errno.h>
#include "btc_ble_mesh_model_common.h"
#include "btc_ble_mesh_generic_model.h"
#include "esp_ble_mesh_generic_model_api.h"
@ -357,8 +358,6 @@ static void btc_ble_mesh_generic_client_callback(esp_ble_mesh_generic_client_cb_
{
btc_msg_t msg = {0};
BT_DBG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_GENERIC_CLIENT)) {
return;
@ -381,7 +380,7 @@ void bt_mesh_generic_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
esp_ble_mesh_client_common_param_t params = {0};
uint8_t act = 0U;
if (!model || !ctx) {
if (!model || !ctx || len > sizeof(cb_params.status_cb)) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
@ -419,14 +418,14 @@ void bt_mesh_generic_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
cb_params.params = &params;
if (val && len) {
memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb)));
memcpy(&cb_params.status_cb, val, len);
}
btc_ble_mesh_generic_client_callback(&cb_params, act);
return;
}
void btc_ble_mesh_generic_client_publish_callback(uint32_t opcode, struct bt_mesh_model *model,
void btc_ble_mesh_generic_client_publish_callback(uint32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
@ -437,15 +436,13 @@ void btc_ble_mesh_generic_client_publish_callback(uint32_t opcode, struct bt_mes
bt_mesh_generic_client_cb_evt_to_btc(opcode, BTC_BLE_MESH_EVT_GENERIC_CLIENT_PUBLISH,
model, ctx, buf->data, buf->len);
return;
}
void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
{
esp_ble_mesh_client_common_param_t *params = NULL;
btc_ble_mesh_generic_client_args_t *arg = NULL;
esp_ble_mesh_generic_client_cb_param_t cb = {0};
bt_mesh_client_common_param_t common = {0};
btc_ble_mesh_generic_client_args_t *arg = NULL;
bt_mesh_client_common_param_t param = {0};
if (!msg) {
BT_ERR("%s, Invalid parameter", __func__);
@ -455,52 +452,31 @@ void btc_ble_mesh_generic_client_call_handler(btc_msg_t *msg)
arg = (btc_ble_mesh_generic_client_args_t *)(msg->arg);
switch (msg->act) {
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE: {
params = arg->generic_client_get_state.params;
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
common.ctx.net_idx = params->ctx.net_idx;
common.ctx.app_idx = params->ctx.app_idx;
common.ctx.addr = params->ctx.addr;
common.ctx.send_rel = params->ctx.send_rel;
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
common.msg_role = params->msg_role;
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_GET_STATE:
btc_ble_mesh_set_client_common_param(arg->generic_client_get_state.params, &param, false);
cb.params = arg->generic_client_get_state.params;
cb.error_code = bt_mesh_generic_client_get_state(&common, arg->generic_client_get_state.get_state);
cb.error_code = bt_mesh_generic_client_get_state(&param, arg->generic_client_get_state.get_state);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_ble_mesh_generic_client_callback(&cb, ESP_BLE_MESH_GENERIC_CLIENT_GET_STATE_EVT);
}
break;
}
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE: {
params = arg->generic_client_set_state.params;
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
common.ctx.net_idx = params->ctx.net_idx;
common.ctx.app_idx = params->ctx.app_idx;
common.ctx.addr = params->ctx.addr;
common.ctx.send_rel = params->ctx.send_rel;
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
common.msg_role = params->msg_role;
case BTC_BLE_MESH_ACT_GENERIC_CLIENT_SET_STATE:
btc_ble_mesh_set_client_common_param(arg->generic_client_set_state.params, &param, false);
cb.params = arg->generic_client_set_state.params;
cb.error_code = bt_mesh_generic_client_set_state(&common, arg->generic_client_set_state.set_state);
cb.error_code = bt_mesh_generic_client_set_state(&param, arg->generic_client_set_state.set_state);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_ble_mesh_generic_client_callback(&cb, ESP_BLE_MESH_GENERIC_CLIENT_SET_STATE_EVT);
}
break;
}
default:
break;
}
btc_ble_mesh_generic_client_arg_deep_free(msg);
return;
}
void btc_ble_mesh_generic_client_cb_handler(btc_msg_t *msg)
@ -521,7 +497,6 @@ void btc_ble_mesh_generic_client_cb_handler(btc_msg_t *msg)
}
btc_ble_mesh_generic_client_free_req_data(msg);
return;
}
#endif /* CONFIG_BLE_MESH_GENERIC_CLIENT */
@ -674,8 +649,6 @@ static void btc_ble_mesh_generic_server_callback(esp_ble_mesh_generic_server_cb_
{
btc_msg_t msg = {0};
BT_DBG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_GENERIC_SERVER)) {
return;
@ -689,14 +662,15 @@ static void btc_ble_mesh_generic_server_callback(esp_ble_mesh_generic_server_cb_
btc_ble_mesh_generic_server_copy_req_data, btc_ble_mesh_generic_server_free_req_data);
}
void bt_mesh_generic_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model *model,
void bt_mesh_generic_server_cb_evt_to_btc(uint8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const uint8_t *val, size_t len)
{
esp_ble_mesh_generic_server_cb_param_t cb_params = {0};
uint8_t act = 0U;
if (model == NULL || ctx == NULL) {
if (model == NULL || ctx == NULL || len > sizeof(cb_params.value)) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
@ -725,13 +699,13 @@ void bt_mesh_generic_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model
cb_params.ctx.recv_dst = ctx->recv_dst;
cb_params.ctx.recv_rssi = ctx->recv_rssi;
cb_params.ctx.send_ttl = ctx->send_ttl;
cb_params.ctx.recv_cred = ctx->recv_cred;
if (val && len) {
memcpy(&cb_params.value, val, MIN(len, sizeof(cb_params.value)));
memcpy(&cb_params.value, val, len);
}
btc_ble_mesh_generic_server_callback(&cb_params, act);
return;
}
void btc_ble_mesh_generic_server_cb_handler(btc_msg_t *msg)
@ -752,7 +726,6 @@ void btc_ble_mesh_generic_server_cb_handler(btc_msg_t *msg)
}
btc_ble_mesh_generic_server_free_req_data(msg);
return;
}
#endif /* CONFIG_BLE_MESH_GENERIC_SERVER */

View File

@ -7,8 +7,8 @@
#include <string.h>
#include <errno.h>
#include "btc_ble_mesh_model_common.h"
#include "btc_ble_mesh_health_model.h"
#include "foundation.h"
#include "esp_ble_mesh_health_model_api.h"
#if CONFIG_BLE_MESH_HEALTH_CLI
@ -136,7 +136,7 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des
case ESP_BLE_MESH_HEALTH_CLIENT_PUBLISH_EVT:
if (p_src_data->params) {
switch (p_src_data->params->opcode) {
case OP_HEALTH_CURRENT_STATUS:
case ESP_BLE_MESH_MODEL_OP_HEALTH_CURRENT_STATUS:
if (p_src_data->status_cb.current_status.fault_array) {
length = p_src_data->status_cb.current_status.fault_array->len;
p_dest_data->status_cb.current_status.fault_array = bt_mesh_alloc_buf(length);
@ -149,10 +149,10 @@ static void btc_ble_mesh_health_client_copy_req_data(btc_msg_t *msg, void *p_des
p_src_data->status_cb.current_status.fault_array->len);
}
break;
case OP_HEALTH_FAULT_GET:
case OP_HEALTH_FAULT_CLEAR:
case OP_HEALTH_FAULT_TEST:
case OP_HEALTH_FAULT_STATUS:
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET:
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR:
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST:
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_STATUS:
if (p_src_data->status_cb.fault_status.fault_array) {
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);
@ -193,13 +193,13 @@ static void btc_ble_mesh_health_client_free_req_data(btc_msg_t *msg)
case ESP_BLE_MESH_HEALTH_CLIENT_PUBLISH_EVT:
if (arg->params) {
switch (arg->params->opcode) {
case OP_HEALTH_CURRENT_STATUS:
case ESP_BLE_MESH_MODEL_OP_HEALTH_CURRENT_STATUS:
bt_mesh_free_buf(arg->status_cb.current_status.fault_array);
break;
case OP_HEALTH_FAULT_GET:
case OP_HEALTH_FAULT_CLEAR:
case OP_HEALTH_FAULT_TEST:
case OP_HEALTH_FAULT_STATUS:
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_GET:
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_CLEAR:
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_TEST:
case ESP_BLE_MESH_MODEL_OP_HEALTH_FAULT_STATUS:
bt_mesh_free_buf(arg->status_cb.fault_status.fault_array);
break;
default:
@ -220,8 +220,6 @@ static void btc_ble_mesh_health_client_callback(esp_ble_mesh_health_client_cb_pa
{
btc_msg_t msg = {0};
BT_DBG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_HEALTH_CLIENT)) {
return;
@ -244,7 +242,7 @@ void bt_mesh_health_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
esp_ble_mesh_client_common_param_t params = {0};
uint8_t act = 0U;
if (!model || !ctx) {
if (!model || !ctx || len > sizeof(cb_params.status_cb)) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
@ -282,14 +280,14 @@ void bt_mesh_health_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
cb_params.params = &params;
if (val && len) {
memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb)));
memcpy(&cb_params.status_cb, val, len);
}
btc_ble_mesh_health_client_callback(&cb_params, act);
return;
}
void btc_ble_mesh_health_publish_callback(uint32_t opcode, struct bt_mesh_model *model,
void btc_ble_mesh_health_publish_callback(uint32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
@ -300,7 +298,6 @@ void btc_ble_mesh_health_publish_callback(uint32_t opcode, struct bt_mesh_model
bt_mesh_health_client_cb_evt_to_btc(opcode, BTC_BLE_MESH_EVT_HEALTH_CLIENT_PUBLISH,
model, ctx, buf->data, buf->len);
return;
}
static int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param_t *params,
@ -318,15 +315,7 @@ static int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param
return -EINVAL;
}
param.opcode = params->opcode;
param.model = (struct bt_mesh_model *)params->model;
param.ctx.net_idx = params->ctx.net_idx;
param.ctx.app_idx = params->ctx.app_idx;
param.ctx.addr = params->ctx.addr;
param.ctx.send_rel = params->ctx.send_rel;
param.ctx.send_ttl = params->ctx.send_ttl;
param.msg_timeout = params->msg_timeout;
param.msg_role = params->msg_role;
btc_ble_mesh_set_client_common_param(params, &param, false);
switch (param.opcode) {
case ESP_BLE_MESH_MODEL_OP_ATTENTION_GET:
@ -339,8 +328,6 @@ static int btc_ble_mesh_health_client_get_state(esp_ble_mesh_client_common_param
BT_ERR("Invalid Health Get opcode 0x%04x", param.opcode);
return -EINVAL;
}
return 0;
}
static int btc_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param_t *params,
@ -353,15 +340,7 @@ static int btc_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param
return -EINVAL;
}
param.opcode = params->opcode;
param.model = (struct bt_mesh_model *)params->model;
param.ctx.net_idx = params->ctx.net_idx;
param.ctx.app_idx = params->ctx.app_idx;
param.ctx.addr = params->ctx.addr;
param.ctx.send_rel = params->ctx.send_rel;
param.ctx.send_ttl = params->ctx.send_ttl;
param.msg_timeout = params->msg_timeout;
param.msg_role = params->msg_role;
btc_ble_mesh_set_client_common_param(params, &param, false);
switch (param.opcode) {
case ESP_BLE_MESH_MODEL_OP_ATTENTION_SET:
@ -384,8 +363,6 @@ static int btc_ble_mesh_health_client_set_state(esp_ble_mesh_client_common_param
BT_ERR("Invalid Health Set opcode 0x%04x", param.opcode);
return -EINVAL;
}
return 0;
}
void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg)
@ -426,7 +403,6 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg)
}
btc_ble_mesh_health_client_arg_deep_free(msg);
return;
}
void btc_ble_mesh_health_client_cb_handler(btc_msg_t *msg)
@ -447,7 +423,6 @@ void btc_ble_mesh_health_client_cb_handler(btc_msg_t *msg)
}
btc_ble_mesh_health_client_free_req_data(msg);
return;
}
#endif /* CONFIG_BLE_MESH_HEALTH_CLI */
@ -531,8 +506,6 @@ static void btc_ble_mesh_health_server_callback(esp_ble_mesh_health_server_cb_pa
{
btc_msg_t msg = {0};
BT_DBG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_HEALTH_SERVER)) {
return;
@ -570,7 +543,6 @@ void btc_ble_mesh_health_server_call_handler(btc_msg_t *msg)
}
btc_ble_mesh_health_server_arg_deep_free(msg);
return;
}
void btc_ble_mesh_health_server_cb_handler(btc_msg_t *msg)
@ -591,7 +563,6 @@ void btc_ble_mesh_health_server_cb_handler(btc_msg_t *msg)
}
btc_ble_mesh_health_server_free_req_data(msg);
return;
}
void btc_ble_mesh_health_server_fault_clear(struct bt_mesh_model *model, uint16_t company_id)

View File

@ -7,6 +7,7 @@
#include <string.h>
#include <errno.h>
#include "btc_ble_mesh_model_common.h"
#include "btc_ble_mesh_lighting_model.h"
#include "esp_ble_mesh_lighting_model_api.h"
@ -79,7 +80,7 @@ void btc_ble_mesh_lighting_client_arg_deep_free(btc_msg_t *msg)
{
btc_ble_mesh_lighting_client_args_t *arg = NULL;
if (!msg || !msg->arg) {
if (!msg) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
@ -165,7 +166,7 @@ static void btc_ble_mesh_lighting_client_free_req_data(btc_msg_t *msg)
{
esp_ble_mesh_light_client_cb_param_t *arg = NULL;
if (!msg || !msg->arg) {
if (!msg) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
@ -201,8 +202,6 @@ static void btc_ble_mesh_lighting_client_callback(esp_ble_mesh_light_client_cb_p
{
btc_msg_t msg = {0};
BT_DBG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_LIGHTING_CLIENT)) {
return;
@ -225,7 +224,7 @@ void bt_mesh_lighting_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
esp_ble_mesh_client_common_param_t params = {0};
uint8_t act = 0U;
if (!model || !ctx) {
if (!model || !ctx || len > sizeof(cb_params.status_cb)) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
@ -263,14 +262,14 @@ void bt_mesh_lighting_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
cb_params.params = &params;
if (val && len) {
memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb)));
memcpy(&cb_params.status_cb, val, len);
}
btc_ble_mesh_lighting_client_callback(&cb_params, act);
return;
}
void btc_ble_mesh_lighting_client_publish_callback(uint32_t opcode, struct bt_mesh_model *model,
void btc_ble_mesh_lighting_client_publish_callback(uint32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
@ -281,17 +280,15 @@ void btc_ble_mesh_lighting_client_publish_callback(uint32_t opcode, struct bt_me
bt_mesh_lighting_client_cb_evt_to_btc(opcode, BTC_BLE_MESH_EVT_LIGHTING_CLIENT_PUBLISH,
model, ctx, buf->data, buf->len);
return;
}
void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
{
esp_ble_mesh_client_common_param_t *params = NULL;
btc_ble_mesh_lighting_client_args_t *arg = NULL;
esp_ble_mesh_light_client_cb_param_t cb = {0};
bt_mesh_client_common_param_t common = {0};
bt_mesh_client_common_param_t param = {0};
if (!msg || !msg->arg) {
if (!msg) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
@ -299,59 +296,38 @@ void btc_ble_mesh_lighting_client_call_handler(btc_msg_t *msg)
arg = (btc_ble_mesh_lighting_client_args_t *)(msg->arg);
switch (msg->act) {
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE: {
params = arg->light_client_get_state.params;
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
common.ctx.net_idx = params->ctx.net_idx;
common.ctx.app_idx = params->ctx.app_idx;
common.ctx.addr = params->ctx.addr;
common.ctx.send_rel = params->ctx.send_rel;
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
common.msg_role = params->msg_role;
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_GET_STATE:
btc_ble_mesh_set_client_common_param(arg->light_client_get_state.params, &param, false);
cb.params = arg->light_client_get_state.params;
cb.error_code = bt_mesh_light_client_get_state(&common, arg->light_client_get_state.get_state);
cb.error_code = bt_mesh_light_client_get_state(&param, arg->light_client_get_state.get_state);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_ble_mesh_lighting_client_callback(&cb, ESP_BLE_MESH_LIGHT_CLIENT_GET_STATE_EVT);
}
break;
}
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE: {
params = arg->light_client_set_state.params;
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
common.ctx.net_idx = params->ctx.net_idx;
common.ctx.app_idx = params->ctx.app_idx;
common.ctx.addr = params->ctx.addr;
common.ctx.send_rel = params->ctx.send_rel;
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
common.msg_role = params->msg_role;
case BTC_BLE_MESH_ACT_LIGHTING_CLIENT_SET_STATE:
btc_ble_mesh_set_client_common_param(arg->light_client_set_state.params, &param, false);
cb.params = arg->light_client_set_state.params;
cb.error_code = bt_mesh_light_client_set_state(&common, arg->light_client_set_state.set_state);
cb.error_code = bt_mesh_light_client_set_state(&param, arg->light_client_set_state.set_state);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_ble_mesh_lighting_client_callback(&cb, ESP_BLE_MESH_LIGHT_CLIENT_SET_STATE_EVT);
}
break;
}
default:
break;
}
btc_ble_mesh_lighting_client_arg_deep_free(msg);
return;
}
void btc_ble_mesh_lighting_client_cb_handler(btc_msg_t *msg)
{
esp_ble_mesh_light_client_cb_param_t *param = NULL;
if (!msg || !msg->arg) {
if (!msg) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
@ -365,7 +341,6 @@ void btc_ble_mesh_lighting_client_cb_handler(btc_msg_t *msg)
}
btc_ble_mesh_lighting_client_free_req_data(msg);
return;
}
#endif /* CONFIG_BLE_MESH_LIGHTING_CLIENT */
@ -486,8 +461,6 @@ static void btc_ble_mesh_lighting_server_callback(esp_ble_mesh_lighting_server_c
{
btc_msg_t msg = {0};
BT_DBG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_LIGHTING_SERVER)) {
return;
@ -501,14 +474,15 @@ static void btc_ble_mesh_lighting_server_callback(esp_ble_mesh_lighting_server_c
btc_ble_mesh_lighting_server_copy_req_data, btc_ble_mesh_lighting_server_free_req_data);
}
void bt_mesh_lighting_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model *model,
void bt_mesh_lighting_server_cb_evt_to_btc(uint8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const uint8_t *val, size_t len)
{
esp_ble_mesh_lighting_server_cb_param_t cb_params = {0};
uint8_t act = 0U;
if (model == NULL || ctx == NULL) {
if (model == NULL || ctx == NULL || len > sizeof(cb_params.value)) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
@ -542,11 +516,10 @@ void bt_mesh_lighting_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_mode
cb_params.ctx.send_ttl = ctx->send_ttl;
if (val && len) {
memcpy(&cb_params.value, val, MIN(len, sizeof(cb_params.value)));
memcpy(&cb_params.value, val, len);
}
btc_ble_mesh_lighting_server_callback(&cb_params, act);
return;
}
void btc_ble_mesh_lighting_server_cb_handler(btc_msg_t *msg)
@ -567,7 +540,6 @@ void btc_ble_mesh_lighting_server_cb_handler(btc_msg_t *msg)
}
btc_ble_mesh_lighting_server_free_req_data(msg);
return;
}
#endif /* CONFIG_BLE_MESH_LIGHTING_SERVER */

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,7 @@
#include <string.h>
#include <errno.h>
#include "btc_ble_mesh_model_common.h"
#include "btc_ble_mesh_sensor_model.h"
#include "esp_ble_mesh_sensor_model_api.h"
@ -439,8 +440,6 @@ static void btc_ble_mesh_sensor_client_callback(esp_ble_mesh_sensor_client_cb_pa
{
btc_msg_t msg = {0};
BT_DBG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_SENSOR_CLIENT)) {
return;
@ -463,7 +462,7 @@ void bt_mesh_sensor_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
esp_ble_mesh_client_common_param_t params = {0};
uint8_t act = 0U;
if (!model || !ctx) {
if (!model || !ctx || len > sizeof(cb_params.status_cb)) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
@ -501,14 +500,14 @@ void bt_mesh_sensor_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
cb_params.params = &params;
if (val && len) {
memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb)));
memcpy(&cb_params.status_cb, val, len);
}
btc_ble_mesh_sensor_client_callback(&cb_params, act);
return;
}
void btc_ble_mesh_sensor_client_publish_callback(uint32_t opcode, struct bt_mesh_model *model,
void btc_ble_mesh_sensor_client_publish_callback(uint32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
@ -519,15 +518,13 @@ void btc_ble_mesh_sensor_client_publish_callback(uint32_t opcode, struct bt_mesh
bt_mesh_sensor_client_cb_evt_to_btc(opcode, BTC_BLE_MESH_EVT_SENSOR_CLIENT_PUBLISH,
model, ctx, buf->data, buf->len);
return;
}
void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
{
esp_ble_mesh_client_common_param_t *params = NULL;
btc_ble_mesh_sensor_client_args_t *arg = NULL;
esp_ble_mesh_sensor_client_cb_param_t cb = {0};
bt_mesh_client_common_param_t common = {0};
btc_ble_mesh_sensor_client_args_t *arg = NULL;
bt_mesh_client_common_param_t param = {0};
if (!msg) {
BT_ERR("%s, Invalid parameter", __func__);
@ -537,52 +534,31 @@ void btc_ble_mesh_sensor_client_call_handler(btc_msg_t *msg)
arg = (btc_ble_mesh_sensor_client_args_t *)(msg->arg);
switch (msg->act) {
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_GET_STATE: {
params = arg->sensor_client_get_state.params;
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
common.ctx.net_idx = params->ctx.net_idx;
common.ctx.app_idx = params->ctx.app_idx;
common.ctx.addr = params->ctx.addr;
common.ctx.send_rel = params->ctx.send_rel;
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
common.msg_role = params->msg_role;
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_GET_STATE:
btc_ble_mesh_set_client_common_param(arg->sensor_client_get_state.params, &param, false);
cb.params = arg->sensor_client_get_state.params;
cb.error_code = bt_mesh_sensor_client_get_state(&common, arg->sensor_client_get_state.get_state);
cb.error_code = bt_mesh_sensor_client_get_state(&param, arg->sensor_client_get_state.get_state);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_ble_mesh_sensor_client_callback(&cb, ESP_BLE_MESH_SENSOR_CLIENT_GET_STATE_EVT);
}
break;
}
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE: {
params = arg->sensor_client_set_state.params;
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
common.ctx.net_idx = params->ctx.net_idx;
common.ctx.app_idx = params->ctx.app_idx;
common.ctx.addr = params->ctx.addr;
common.ctx.send_rel = params->ctx.send_rel;
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
common.msg_role = params->msg_role;
case BTC_BLE_MESH_ACT_SENSOR_CLIENT_SET_STATE:
btc_ble_mesh_set_client_common_param(arg->sensor_client_set_state.params, &param, false);
cb.params = arg->sensor_client_set_state.params;
cb.error_code = bt_mesh_sensor_client_set_state(&common, arg->sensor_client_set_state.set_state);
cb.error_code = bt_mesh_sensor_client_set_state(&param, arg->sensor_client_set_state.set_state);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_ble_mesh_sensor_client_callback(&cb, ESP_BLE_MESH_SENSOR_CLIENT_SET_STATE_EVT);
}
break;
}
default:
break;
}
btc_ble_mesh_sensor_client_arg_deep_free(msg);
return;
}
void btc_ble_mesh_sensor_client_cb_handler(btc_msg_t *msg)
@ -603,7 +579,6 @@ void btc_ble_mesh_sensor_client_cb_handler(btc_msg_t *msg)
}
btc_ble_mesh_sensor_client_free_req_data(msg);
return;
}
#endif /* CONFIG_BLE_MESH_SENSOR_CLI */
@ -806,8 +781,6 @@ static void btc_ble_mesh_sensor_server_callback(esp_ble_mesh_sensor_server_cb_pa
{
btc_msg_t msg = {0};
BT_DBG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_SENSOR_SERVER)) {
return;
@ -821,14 +794,15 @@ static void btc_ble_mesh_sensor_server_callback(esp_ble_mesh_sensor_server_cb_pa
btc_ble_mesh_sensor_server_copy_req_data, btc_ble_mesh_sensor_server_free_req_data);
}
void bt_mesh_sensor_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model *model,
void bt_mesh_sensor_server_cb_evt_to_btc(uint8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const uint8_t *val, size_t len)
{
esp_ble_mesh_sensor_server_cb_param_t cb_params = {0};
uint8_t act = 0U;
if (model == NULL || ctx == NULL) {
if (model == NULL || ctx == NULL || len > sizeof(cb_params.value)) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
@ -859,11 +833,10 @@ void bt_mesh_sensor_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model
cb_params.ctx.send_ttl = ctx->send_ttl;
if (val && len) {
memcpy(&cb_params.value, val, MIN(len, sizeof(cb_params.value)));
memcpy(&cb_params.value, val, len);
}
btc_ble_mesh_sensor_server_callback(&cb_params, act);
return;
}
void btc_ble_mesh_sensor_server_cb_handler(btc_msg_t *msg)
@ -884,7 +857,6 @@ void btc_ble_mesh_sensor_server_cb_handler(btc_msg_t *msg)
}
btc_ble_mesh_sensor_server_free_req_data(msg);
return;
}
#endif /* CONFIG_BLE_MESH_SENSOR_SERVER */

View File

@ -7,6 +7,7 @@
#include <string.h>
#include <errno.h>
#include "btc_ble_mesh_model_common.h"
#include "btc_ble_mesh_time_scene_model.h"
#include "esp_ble_mesh_time_scene_model_api.h"
@ -79,7 +80,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) {
if (!msg) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
@ -166,7 +167,7 @@ static void btc_ble_mesh_time_scene_client_free_req_data(btc_msg_t *msg)
{
esp_ble_mesh_time_scene_client_cb_param_t *arg = NULL;
if (!msg || !msg->arg) {
if (!msg) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
@ -203,8 +204,6 @@ static void btc_ble_mesh_time_scene_client_callback(esp_ble_mesh_time_scene_clie
{
btc_msg_t msg = {0};
BT_DBG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_TIME_SCENE_CLIENT)) {
return;
@ -227,7 +226,7 @@ void bt_mesh_time_scene_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
esp_ble_mesh_client_common_param_t params = {0};
uint8_t act = 0U;
if (!model || !ctx) {
if (!model || !ctx || len > sizeof(cb_params.status_cb)) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
@ -265,14 +264,14 @@ void bt_mesh_time_scene_client_cb_evt_to_btc(uint32_t opcode, uint8_t evt_type,
cb_params.params = &params;
if (val && len) {
memcpy(&cb_params.status_cb, val, MIN(len, sizeof(cb_params.status_cb)));
memcpy(&cb_params.status_cb, val, len);
}
btc_ble_mesh_time_scene_client_callback(&cb_params, act);
return;
}
void btc_ble_mesh_time_scene_client_publish_callback(uint32_t opcode, struct bt_mesh_model *model,
void btc_ble_mesh_time_scene_client_publish_callback(uint32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
@ -283,17 +282,15 @@ void btc_ble_mesh_time_scene_client_publish_callback(uint32_t opcode, struct bt_
bt_mesh_time_scene_client_cb_evt_to_btc(opcode, BTC_BLE_MESH_EVT_TIME_SCENE_CLIENT_PUBLISH,
model, ctx, buf->data, buf->len);
return;
}
void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
{
btc_ble_mesh_time_scene_client_args_t *arg = NULL;
esp_ble_mesh_client_common_param_t *params = NULL;
esp_ble_mesh_time_scene_client_cb_param_t cb = {0};
bt_mesh_client_common_param_t common = {0};
btc_ble_mesh_time_scene_client_args_t *arg = NULL;
bt_mesh_client_common_param_t param = {0};
if (!msg || !msg->arg) {
if (!msg) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
@ -301,59 +298,38 @@ void btc_ble_mesh_time_scene_client_call_handler(btc_msg_t *msg)
arg = (btc_ble_mesh_time_scene_client_args_t *)(msg->arg);
switch (msg->act) {
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_GET_STATE: {
params = arg->time_scene_client_get_state.params;
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
common.ctx.net_idx = params->ctx.net_idx;
common.ctx.app_idx = params->ctx.app_idx;
common.ctx.addr = params->ctx.addr;
common.ctx.send_rel = params->ctx.send_rel;
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
common.msg_role = params->msg_role;
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_GET_STATE:
btc_ble_mesh_set_client_common_param(arg->time_scene_client_get_state.params, &param, false);
cb.params = arg->time_scene_client_get_state.params;
cb.error_code = bt_mesh_time_scene_client_get_state(&common, arg->time_scene_client_get_state.get_state);
cb.error_code = bt_mesh_time_scene_client_get_state(&param, arg->time_scene_client_get_state.get_state);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_ble_mesh_time_scene_client_callback(&cb, ESP_BLE_MESH_TIME_SCENE_CLIENT_GET_STATE_EVT);
}
break;
}
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_SET_STATE: {
params = arg->time_scene_client_set_state.params;
common.opcode = params->opcode;
common.model = (struct bt_mesh_model *)params->model;
common.ctx.net_idx = params->ctx.net_idx;
common.ctx.app_idx = params->ctx.app_idx;
common.ctx.addr = params->ctx.addr;
common.ctx.send_rel = params->ctx.send_rel;
common.ctx.send_ttl = params->ctx.send_ttl;
common.msg_timeout = params->msg_timeout;
common.msg_role = params->msg_role;
case BTC_BLE_MESH_ACT_TIME_SCENE_CLIENT_SET_STATE:
btc_ble_mesh_set_client_common_param(arg->time_scene_client_set_state.params, &param, false);
cb.params = arg->time_scene_client_set_state.params;
cb.error_code = bt_mesh_time_scene_client_set_state(&common, arg->time_scene_client_set_state.set_state);
cb.error_code = bt_mesh_time_scene_client_set_state(&param, arg->time_scene_client_set_state.set_state);
if (cb.error_code) {
/* If send failed, callback error_code to app layer immediately */
btc_ble_mesh_time_scene_client_callback(&cb, ESP_BLE_MESH_TIME_SCENE_CLIENT_SET_STATE_EVT);
}
break;
}
default:
break;
}
btc_ble_mesh_time_scene_client_arg_deep_free(msg);
return;
}
void btc_ble_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) {
if (!msg) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
@ -367,7 +343,6 @@ void btc_ble_mesh_time_scene_client_cb_handler(btc_msg_t *msg)
}
btc_ble_mesh_time_scene_client_free_req_data(msg);
return;
}
#endif /* CONFIG_BLE_MESH_TIME_SCENE_CLIENT */
@ -390,8 +365,6 @@ static void btc_ble_mesh_time_scene_server_callback(esp_ble_mesh_time_scene_serv
{
btc_msg_t msg = {0};
BT_DBG("%s", __func__);
/* If corresponding callback is not registered, event will not be posted. */
if (!btc_profile_cb_get(BTC_PID_TIME_SCENE_SERVER)) {
return;
@ -404,14 +377,15 @@ static void btc_ble_mesh_time_scene_server_callback(esp_ble_mesh_time_scene_serv
btc_transfer_context(&msg, cb_params, cb_params == NULL ? 0 : sizeof(esp_ble_mesh_time_scene_server_cb_param_t), NULL, NULL);
}
void bt_mesh_time_scene_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model *model,
void bt_mesh_time_scene_server_cb_evt_to_btc(uint8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const uint8_t *val, size_t len)
{
esp_ble_mesh_time_scene_server_cb_param_t cb_params = {0};
uint8_t act = 0U;
if (model == NULL || ctx == NULL) {
if (model == NULL || ctx == NULL || len > sizeof(cb_params.value)) {
BT_ERR("%s, Invalid parameter", __func__);
return;
}
@ -445,11 +419,10 @@ void bt_mesh_time_scene_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_mo
cb_params.ctx.send_ttl = ctx->send_ttl;
if (val && len) {
memcpy(&cb_params.value, val, MIN(len, sizeof(cb_params.value)));
memcpy(&cb_params.value, val, len);
}
btc_ble_mesh_time_scene_server_callback(&cb_params, act);
return;
}
void btc_ble_mesh_time_scene_server_cb_handler(btc_msg_t *msg)
@ -468,8 +441,6 @@ void btc_ble_mesh_time_scene_server_cb_handler(btc_msg_t *msg)
} else {
BT_ERR("%s, Unknown act %d", __func__, msg->act);
}
return;
}
#endif /* CONFIG_BLE_MESH_TIME_SCENE_SERVER */

View File

@ -47,7 +47,8 @@ void btc_ble_mesh_config_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
void btc_ble_mesh_config_client_arg_deep_free(btc_msg_t *msg);
void btc_ble_mesh_config_client_publish_callback(uint32_t opcode, struct bt_mesh_model *model,
void btc_ble_mesh_config_client_publish_callback(uint32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf);
@ -63,7 +64,8 @@ typedef enum {
BTC_BLE_MESH_EVT_CONFIG_SERVER_MAX,
} btc_ble_mesh_config_server_evt_t;
void bt_mesh_config_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model *model,
void bt_mesh_config_server_cb_evt_to_btc(uint8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const uint8_t *val, size_t len);

View File

@ -47,7 +47,8 @@ void btc_ble_mesh_generic_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, voi
void btc_ble_mesh_generic_client_arg_deep_free(btc_msg_t *msg);
void btc_ble_mesh_generic_client_publish_callback(uint32_t opcode, struct bt_mesh_model *model,
void btc_ble_mesh_generic_client_publish_callback(uint32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf);
@ -63,7 +64,8 @@ typedef enum {
BTC_BLE_MESH_EVT_GENERIC_SERVER_MAX,
} btc_ble_mesh_generic_server_evt_t;
void bt_mesh_generic_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model *model,
void bt_mesh_generic_server_cb_evt_to_btc(uint8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const uint8_t *val, size_t len);

View File

@ -47,7 +47,8 @@ void btc_ble_mesh_health_client_call_handler(btc_msg_t *msg);
void btc_ble_mesh_health_client_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_health_publish_callback(uint32_t opcode, struct bt_mesh_model *model,
void btc_ble_mesh_health_publish_callback(uint32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf);

View File

@ -47,7 +47,8 @@ void btc_ble_mesh_lighting_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, vo
void btc_ble_mesh_lighting_client_arg_deep_free(btc_msg_t *msg);
void btc_ble_mesh_lighting_client_publish_callback(uint32_t opcode, struct bt_mesh_model *model,
void btc_ble_mesh_lighting_client_publish_callback(uint32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf);
@ -64,7 +65,8 @@ typedef enum {
BTC_BLE_MESH_EVT_LIGHTING_SERVER_MAX,
} btc_ble_mesh_lighting_server_evt_t;
void bt_mesh_lighting_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model *model,
void bt_mesh_lighting_server_cb_evt_to_btc(uint8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const uint8_t *val, size_t len);

View File

@ -0,0 +1,42 @@
/*
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _BTC_BLE_MESH_MODEL_COMMON_H_
#define _BTC_BLE_MESH_MODEL_COMMON_H_
#include "btc/btc_manage.h"
#include "mesh/access.h"
#include "mesh/client_common.h"
#include "esp_ble_mesh_defs.h"
#ifdef __cplusplus
extern "C" {
#endif
static inline void btc_ble_mesh_set_client_common_param(esp_ble_mesh_client_common_param_t *input,
bt_mesh_client_common_param_t *output,
bool use_dev_key)
{
if (input && output) {
output->opcode = input->opcode;
output->model = (struct bt_mesh_model *)input->model;
output->ctx.net_idx = input->ctx.net_idx;
output->ctx.app_idx = use_dev_key ? BLE_MESH_KEY_DEV : input->ctx.app_idx;
output->ctx.addr = input->ctx.addr;
output->ctx.send_szmic = input->ctx.send_szmic;
output->ctx.send_ttl = input->ctx.send_ttl;
output->ctx.send_cred = input->ctx.send_cred;
output->ctx.send_tag = input->ctx.send_tag;
output->msg_timeout = input->msg_timeout;
}
}
#ifdef __cplusplus
}
#endif
#endif /* _BTC_BLE_MESH_MODEL_COMMON_H_ */

View File

@ -12,7 +12,6 @@
#include "mesh/config.h"
#include "mesh/main.h"
#include "fast_prov.h"
#include "prov_pvnr.h"
#include "esp_ble_mesh_defs.h"
#ifdef __cplusplus
@ -65,6 +64,10 @@ typedef enum {
BTC_BLE_MESH_ACT_PROVISIONER_CLOSE_SETTINGS_WITH_UID,
BTC_BLE_MESH_ACT_PROVISIONER_DELETE_SETTINGS_WITH_INDEX,
BTC_BLE_MESH_ACT_PROVISIONER_DELETE_SETTINGS_WITH_UID,
BTC_BLE_MESH_ACT_PROVISIONER_SEND_PROV_RECORDS_GET,
BTC_BLE_MESH_ACT_PROVISIONER_SEND_PROV_RECORD_REQUEST,
BTC_BLE_MESH_ACT_PROVISIONER_SEND_PROV_INVITE,
BTC_BLE_MESH_ACT_PROVISIONER_SEND_LINK_CLOSE,
BTC_BLE_MESH_ACT_SET_FAST_PROV_INFO,
BTC_BLE_MESH_ACT_SET_FAST_PROV_ACTION,
BTC_BLE_MESH_ACT_LPN_ENABLE,
@ -75,6 +78,8 @@ typedef enum {
BTC_BLE_MESH_ACT_PROXY_CLIENT_SET_FILTER_TYPE,
BTC_BLE_MESH_ACT_PROXY_CLIENT_ADD_FILTER_ADDR,
BTC_BLE_MESH_ACT_PROXY_CLIENT_REMOVE_FILTER_ADDR,
BTC_BLE_MESH_ACT_PROXY_CLIENT_DIRECTED_PROXY_SET,
BTC_BLE_MESH_ACT_PROXY_CLIENT_SEND_SOLIC_PDU,
BTC_BLE_MESH_ACT_MODEL_SUBSCRIBE_GROUP_ADDR,
BTC_BLE_MESH_ACT_MODEL_UNSUBSCRIBE_GROUP_ADDR,
BTC_BLE_MESH_ACT_DEINIT_MESH,
@ -248,6 +253,21 @@ typedef union {
struct {
char uid[ESP_BLE_MESH_SETTINGS_UID_SIZE + 1];
} delete_settings_with_uid;
struct {
uint16_t link_idx;
} send_prov_records_get;
struct {
uint16_t link_idx;
uint16_t record_id;
uint16_t frag_offset;
uint16_t max_size;
} send_prov_record_req;
struct {
uint16_t link_idx;
} send_prov_invite;
struct {
uint16_t link_idx;
} send_link_close;
struct ble_mesh_set_fast_prov_info_args {
uint16_t unicast_min;
uint16_t unicast_max;
@ -295,6 +315,16 @@ typedef union {
uint16_t addr_num;
uint16_t *addr;
} proxy_client_remove_filter_addr;
struct ble_mesh_proxy_client_directed_proxy_set_args {
uint8_t conn_handle;
uint16_t net_idx;
uint8_t use_directed;
} proxy_client_directed_proxy_set;
struct {
uint16_t net_idx;
uint16_t ssrc;
uint16_t dst;
} proxy_client_send_solic_pdu;
struct ble_mesh_model_sub_group_addr_args {
uint16_t element_addr;
uint16_t company_id;
@ -315,7 +345,7 @@ typedef union {
typedef union {
struct ble_mesh_model_publish_args {
esp_ble_mesh_model_t *model;
uint8_t device_role;
uint8_t device_role __attribute__((deprecated));
} model_publish;
struct ble_mesh_model_send_args {
esp_ble_mesh_model_t *model;
@ -324,7 +354,7 @@ typedef union {
bool need_rsp;
uint16_t length;
uint8_t *data;
uint8_t device_role;
uint8_t device_role __attribute__((deprecated));
int32_t msg_timeout;
} model_send;
struct ble_mesh_server_model_update_state_args {
@ -389,6 +419,11 @@ void btc_ble_mesh_model_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_prov_call_handler(btc_msg_t *msg);
void btc_ble_mesh_prov_cb_handler(btc_msg_t *msg);
#if CONFIG_BLE_MESH_DF_SRV
int btc_ble_mesh_enable_directed_forwarding(uint16_t net_idx, bool directed_forwarding,
bool directed_forwarding_relay);
#endif
#ifdef __cplusplus
}
#endif

View File

@ -47,7 +47,8 @@ void btc_ble_mesh_sensor_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void
void btc_ble_mesh_sensor_client_arg_deep_free(btc_msg_t *msg);
void btc_ble_mesh_sensor_client_publish_callback(uint32_t opcode, struct bt_mesh_model *model,
void btc_ble_mesh_sensor_client_publish_callback(uint32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf);
@ -63,7 +64,8 @@ typedef enum {
BTC_BLE_MESH_EVT_SENSOR_SERVER_MAX,
} btc_ble_mesh_sensor_server_evt_t;
void bt_mesh_sensor_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model *model,
void bt_mesh_sensor_server_cb_evt_to_btc(uint8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const uint8_t *val, size_t len);

View File

@ -45,7 +45,10 @@ void btc_ble_mesh_time_scene_client_cb_handler(btc_msg_t *msg);
void btc_ble_mesh_time_scene_client_arg_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_ble_mesh_time_scene_client_publish_callback(uint32_t opcode, struct bt_mesh_model *model,
void btc_ble_mesh_time_scene_client_arg_deep_free(btc_msg_t *msg);
void btc_ble_mesh_time_scene_client_publish_callback(uint32_t opcode,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf);
@ -62,7 +65,8 @@ typedef enum {
BTC_BLE_MESH_EVT_TIME_SCENE_SERVER_MAX,
} btc_ble_mesh_time_scene_server_evt_t;
void bt_mesh_time_scene_server_cb_evt_to_btc(uint8_t evt_type, struct bt_mesh_model *model,
void bt_mesh_time_scene_server_cb_evt_to_btc(uint8_t evt_type,
struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
const uint8_t *val, size_t len);

View File

@ -281,7 +281,7 @@ uint32_t net_buf_simple_pull_le24(struct net_buf_simple *buf)
{
struct uint24 {
uint32_t u24:24;
} __packed val;
} __attribute__((packed)) val;
val = UNALIGNED_GET((struct uint24 *)buf->data);
net_buf_simple_pull(buf, sizeof(val));
@ -293,7 +293,7 @@ uint32_t net_buf_simple_pull_be24(struct net_buf_simple *buf)
{
struct uint24 {
uint32_t u24:24;
} __packed val;
} __attribute__((packed)) val;
val = UNALIGNED_GET((struct uint24 *)buf->data);
net_buf_simple_pull(buf, sizeof(val));
@ -325,7 +325,7 @@ uint64_t net_buf_simple_pull_le48(struct net_buf_simple *buf)
{
struct uint48 {
uint64_t u48:48;
} __packed val;
} __attribute__((packed)) val;
val = UNALIGNED_GET((struct uint48 *)buf->data);
net_buf_simple_pull(buf, sizeof(val));
@ -337,7 +337,7 @@ uint64_t net_buf_simple_pull_be48(struct net_buf_simple *buf)
{
struct uint48 {
uint64_t u48:48;
} __packed val;
} __attribute__((packed)) val;
val = UNALIGNED_GET((struct uint48 *)buf->data);
net_buf_simple_pull(buf, sizeof(val));
@ -459,7 +459,7 @@ struct net_buf *net_buf_ref(struct net_buf *buf)
return buf;
}
#if defined(CONFIG_BLE_MESH_NET_BUF_LOG)
#if 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)
@ -471,7 +471,7 @@ void net_buf_unref(struct net_buf *buf)
struct net_buf *frags = buf->frags;
struct net_buf_pool *pool = NULL;
#if defined(CONFIG_BLE_MESH_NET_BUF_LOG)
#if CONFIG_BLE_MESH_NET_BUF_LOG
if (!buf->ref) {
NET_BUF_ERR("%s():%d: buf %p double free", func, line,
buf);
@ -491,7 +491,7 @@ void net_buf_unref(struct net_buf *buf)
pool = buf->pool;
pool->uninit_count++;
#if defined(CONFIG_BLE_MESH_NET_BUF_POOL_USAGE)
#if CONFIG_BLE_MESH_NET_BUF_POOL_USAGE
pool->avail_count++;
NET_BUF_DBG("Unref, pool %p, avail_count %d, uninit_count %d",
pool, pool->avail_count, pool->uninit_count);
@ -533,7 +533,7 @@ static uint8_t *data_alloc(struct net_buf *buf, size_t *size, int32_t timeout)
return pool->alloc->cb->alloc(buf, size, timeout);
}
#if defined(CONFIG_BLE_MESH_NET_BUF_LOG)
#if CONFIG_BLE_MESH_NET_BUF_LOG
struct net_buf *net_buf_alloc_len_debug(struct net_buf_pool *pool, size_t size,
int32_t timeout, const char *func, int line)
#else
@ -594,7 +594,7 @@ success:
net_buf_reset(buf);
pool->uninit_count--;
#if defined(CONFIG_BLE_MESH_NET_BUF_POOL_USAGE)
#if CONFIG_BLE_MESH_NET_BUF_POOL_USAGE
pool->avail_count--;
NET_BUF_ASSERT(pool->avail_count >= 0);
#endif
@ -602,7 +602,7 @@ success:
return buf;
}
#if defined(CONFIG_BLE_MESH_NET_BUF_LOG)
#if CONFIG_BLE_MESH_NET_BUF_LOG
struct net_buf *net_buf_alloc_fixed_debug(struct net_buf_pool *pool,
int32_t timeout, const char *func,
int line)
@ -656,7 +656,7 @@ struct net_buf *net_buf_frag_add(struct net_buf *head, struct net_buf *frag)
return head;
}
#if defined(CONFIG_BLE_MESH_NET_BUF_LOG)
#if CONFIG_BLE_MESH_NET_BUF_LOG
struct net_buf *net_buf_frag_del_debug(struct net_buf *parent,
struct net_buf *frag,
const char *func, int line)
@ -678,7 +678,7 @@ struct net_buf *net_buf_frag_del(struct net_buf *parent, struct net_buf *frag)
frag->frags = NULL;
#if defined(CONFIG_BLE_MESH_NET_BUF_LOG)
#if CONFIG_BLE_MESH_NET_BUF_LOG
net_buf_unref_debug(frag, func, line);
#else
net_buf_unref(frag);

View File

@ -72,25 +72,6 @@ void bt_mesh_free_buf(struct net_buf_simple *buf)
}
}
uint8_t bt_mesh_get_device_role(struct bt_mesh_model *model, bool srv_send)
{
bt_mesh_client_user_data_t *client = NULL;
if (srv_send) {
BT_DBG("Message is sent by a server model");
return NODE;
}
if (!model || !model->user_data) {
BT_ERR("%s, Invalid parameter", __func__);
return ROLE_NVAL;
}
client = (bt_mesh_client_user_data_t *)model->user_data;
return client->msg_role;
}
int bt_mesh_rand(void *buf, size_t len)
{
if (buf == NULL || len == 0) {

View File

@ -816,7 +816,7 @@ struct net_buf_pool {
/** Number of uninitialized buffers */
uint16_t uninit_count;
#if defined(CONFIG_BLE_MESH_NET_BUF_POOL_USAGE)
#if CONFIG_BLE_MESH_NET_BUF_POOL_USAGE
/** Amount of available buffers in the pool. */
int16_t avail_count;
@ -837,7 +837,7 @@ struct net_buf_pool {
struct net_buf *const __bufs;
};
#if defined(CONFIG_BLE_MESH_NET_BUF_POOL_USAGE)
#if CONFIG_BLE_MESH_NET_BUF_POOL_USAGE
#define NET_BUF_POOL_INITIALIZER(_pool, _alloc, _bufs, _count, _destroy) \
{ \
.alloc = _alloc, \
@ -962,7 +962,7 @@ int net_buf_id(struct net_buf *buf);
*
* @return New buffer or NULL if out of buffers.
*/
#if defined(CONFIG_BLE_MESH_NET_BUF_LOG)
#if CONFIG_BLE_MESH_NET_BUF_LOG
struct net_buf *net_buf_alloc_fixed_debug(struct net_buf_pool *pool, int32_t timeout,
const char *func, int line);
#define net_buf_alloc_fixed(_pool, _timeout) \
@ -1031,7 +1031,7 @@ struct net_buf *net_buf_slist_get(sys_slist_t *list);
*
* @param buf A valid pointer on a buffer
*/
#if defined(CONFIG_BLE_MESH_NET_BUF_LOG)
#if 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__)
@ -1630,7 +1630,7 @@ struct net_buf *net_buf_frag_add(struct net_buf *head, struct net_buf *frag);
* @return Pointer to the buffer following the fragment, or NULL if it
* had no further fragments.
*/
#if defined(CONFIG_BLE_MESH_NET_BUF_LOG)
#if CONFIG_BLE_MESH_NET_BUF_LOG
struct net_buf *net_buf_frag_del_debug(struct net_buf *parent,
struct net_buf *frag,
const char *func, int line);

View File

@ -335,7 +335,7 @@ static inline void sys_put_le16(uint16_t val, uint8_t dst[2])
* @brief Put a 24-bit integer as little-endian to arbitrary location.
*
* Put a 24-bit integer, originally in host endianness, to a
* potentially unaligned memory location in littel-endian format.
* potentially unaligned memory location in little-endian format.
*
* @param val 24-bit integer in host endianness.
* @param dst Destination memory address to store the result.

View File

@ -51,20 +51,6 @@ struct net_buf_simple *bt_mesh_alloc_buf(uint16_t size);
*/
void bt_mesh_free_buf(struct net_buf_simple *buf);
/**
* @brief This function gets device role for stack internal use.
*
* @Note Currently Provisioner only support client models, Node supports
* client models and server models. Hence if srv_send is set to be
* TRUE, then role NODE will be returned.
*
* @param[in] model: Pointer to the model structure
* @param[in] srv_send: Indicate if the message is sent by a server model
*
* @return 0 - Node, 1 - Provisioner
*/
uint8_t bt_mesh_get_device_role(struct bt_mesh_model *model, bool srv_send);
int bt_mesh_rand(void *buf, size_t len);
#ifdef __cplusplus

View File

@ -13,6 +13,17 @@
extern "C" {
#endif
#ifndef CONFIG_BLE_MESH_PBA_SAME_TIME
#define CONFIG_BLE_MESH_PBA_SAME_TIME 0
#endif
#ifndef CONFIG_BLE_MESH_PBG_SAME_TIME
#define CONFIG_BLE_MESH_PBG_SAME_TIME 0
#endif
#define CONFIG_BLE_MESH_PRIVATE_BEACON (CONFIG_BLE_MESH_PRB_SRV || \
CONFIG_BLE_MESH_PRB_CLI)
#define CONFIG_BLE_MESH_GENERIC_CLIENT (CONFIG_BLE_MESH_GENERIC_ONOFF_CLI || \
CONFIG_BLE_MESH_GENERIC_LEVEL_CLI || \
CONFIG_BLE_MESH_GENERIC_DEF_TRANS_TIME_CLI || \
@ -40,6 +51,9 @@ extern "C" {
#define CONFIG_BLE_MESH_BLE_COEX_SUPPORT (CONFIG_BLE_MESH_SUPPORT_BLE_ADV || \
CONFIG_BLE_MESH_SUPPORT_BLE_SCAN)
#define CONFIG_BLE_MESH_PROXY_SOLIC (CONFIG_BLE_MESH_PROXY_SOLIC_PDU_RX || \
CONFIG_BLE_MESH_PROXY_SOLIC_PDU_TX)
#ifdef __cplusplus
}
#endif

View File

@ -27,6 +27,11 @@ void bt_mesh_mutex_free(bt_mesh_mutex_t *mutex);
void bt_mesh_mutex_lock(bt_mesh_mutex_t *mutex);
void bt_mesh_mutex_unlock(bt_mesh_mutex_t *mutex);
void bt_mesh_r_mutex_create(bt_mesh_mutex_t *mutex);
void bt_mesh_r_mutex_free(bt_mesh_mutex_t *mutex);
void bt_mesh_r_mutex_lock(bt_mesh_mutex_t *mutex);
void bt_mesh_r_mutex_unlock(bt_mesh_mutex_t *mutex);
void bt_mesh_alarm_lock(void);
void bt_mesh_alarm_unlock(void);

View File

@ -50,15 +50,15 @@ struct k_work;
typedef void (*k_work_handler_t)(struct k_work *work);
struct k_work {
void *_reserved;
k_work_handler_t handler;
int index;
void *user_data;
};
#define _K_WORK_INITIALIZER(work_handler) \
{ \
._reserved = NULL, \
.handler = work_handler, \
.user_data = NULL, \
}
/**
@ -119,6 +119,18 @@ struct k_work {
*/
#define K_HOURS(h) K_MINUTES((h) * 60)
/**
* @brief Generate timeout delay from days.
*
* This macro generates a timeout delay that that instructs a kernel API
* to wait up to @a d days to perform the requested operation.
*
* @param d Duration in days.
*
* @return Timeout delay value.
*/
#define K_DAYS(d) K_HOURS((d) * 24)
/**
* @brief Generate infinite timeout delay.
*

View File

@ -92,7 +92,7 @@ extern "C" {
#define BT_DBG(fmt, args...)
#endif
#if defined(CONFIG_BLE_MESH_NET_BUF_LOG) && (!CONFIG_BLE_MESH_NO_LOG)
#if (CONFIG_BLE_MESH_NET_BUF_LOG && !CONFIG_BLE_MESH_NO_LOG)
#define NET_BUF_ERR(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_ERROR) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, ERROR)) BLE_MESH_PRINT_E(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0)
#define NET_BUF_WARN(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_WARN) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, WARN)) BLE_MESH_PRINT_W(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0)
#define NET_BUF_INFO(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_INFO) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, INFO)) BLE_MESH_PRINT_I(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0)
@ -106,7 +106,7 @@ extern "C" {
#define NET_BUF_ASSERT(cond)
#endif
#if defined(CONFIG_BLE_MESH_NET_BUF_SIMPLE_LOG) && (!CONFIG_BLE_MESH_NO_LOG)
#if (CONFIG_BLE_MESH_NET_BUF_SIMPLE_LOG && !CONFIG_BLE_MESH_NO_LOG)
#define NET_BUF_SIMPLE_ERR(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_ERROR) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, ERROR)) BLE_MESH_PRINT_E(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0)
#define NET_BUF_SIMPLE_WARN(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_WARN) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, WARN)) BLE_MESH_PRINT_W(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0)
#define NET_BUF_SIMPLE_INFO(fmt, args...) do {if ((BLE_MESH_NET_BUF_LOG_LEVEL >= BLE_MESH_LOG_LEVEL_INFO) && BLE_MESH_LOG_LEVEL_CHECK(BLE_MESH_NET_BUF, INFO)) BLE_MESH_PRINT_I(BLE_MESH_TRACE_TAG, fmt, ## args);} while(0)

View File

@ -74,10 +74,54 @@ void bt_mesh_mutex_unlock(bt_mesh_mutex_t *mutex)
}
}
static inline void bt_mesh_alarm_mutex_new(void)
void bt_mesh_r_mutex_create(bt_mesh_mutex_t *mutex)
{
if (!alarm_lock.mutex) {
bt_mesh_mutex_create(&alarm_lock);
if (!mutex) {
BT_ERR("Create, invalid recursive mutex");
return;
}
#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC
#if CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL
mutex->buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
#elif CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_IRAM_8BIT
mutex->buffer = heap_caps_calloc_prefer(1, sizeof(StaticQueue_t), 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
#endif
__ASSERT(mutex->buffer, "Failed to create recursive mutex buffer");
mutex->mutex = xSemaphoreCreateRecursiveMutexStatic(mutex->buffer);
__ASSERT(mutex->mutex, "Failed to create static recursive mutex");
#else /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */
mutex->mutex = xSemaphoreCreateRecursiveMutex();
__ASSERT(mutex->mutex, "Failed to create recursive mutex");
#endif /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */
}
void bt_mesh_r_mutex_free(bt_mesh_mutex_t *mutex)
{
bt_mesh_mutex_free(mutex);
}
void bt_mesh_r_mutex_lock(bt_mesh_mutex_t *mutex)
{
if (!mutex) {
BT_ERR("Lock, invalid recursive mutex");
return;
}
if (mutex->mutex) {
xSemaphoreTakeRecursive(mutex->mutex, portMAX_DELAY);
}
}
void bt_mesh_r_mutex_unlock(bt_mesh_mutex_t *mutex)
{
if (!mutex) {
BT_ERR("Unlock, invalid recursive mutex");
return;
}
if (mutex->mutex) {
xSemaphoreGiveRecursive(mutex->mutex);
}
}
@ -91,13 +135,6 @@ void bt_mesh_alarm_unlock(void)
bt_mesh_mutex_unlock(&alarm_lock);
}
static inline void bt_mesh_list_mutex_new(void)
{
if (!list_lock.mutex) {
bt_mesh_mutex_create(&list_lock);
}
}
void bt_mesh_list_lock(void)
{
bt_mesh_mutex_lock(&list_lock);
@ -108,13 +145,6 @@ void bt_mesh_list_unlock(void)
bt_mesh_mutex_unlock(&list_lock);
}
static inline void bt_mesh_buf_mutex_new(void)
{
if (!buf_lock.mutex) {
bt_mesh_mutex_create(&buf_lock);
}
}
void bt_mesh_buf_lock(void)
{
bt_mesh_mutex_lock(&buf_lock);
@ -125,13 +155,6 @@ void bt_mesh_buf_unlock(void)
bt_mesh_mutex_unlock(&buf_lock);
}
static inline void bt_mesh_atomic_mutex_new(void)
{
if (!atomic_lock.mutex) {
bt_mesh_mutex_create(&atomic_lock);
}
}
void bt_mesh_atomic_lock(void)
{
bt_mesh_mutex_lock(&atomic_lock);
@ -144,38 +167,18 @@ void bt_mesh_atomic_unlock(void)
void bt_mesh_mutex_init(void)
{
bt_mesh_alarm_mutex_new();
bt_mesh_list_mutex_new();
bt_mesh_buf_mutex_new();
bt_mesh_atomic_mutex_new();
bt_mesh_mutex_create(&alarm_lock);
bt_mesh_mutex_create(&list_lock);
bt_mesh_mutex_create(&buf_lock);
bt_mesh_mutex_create(&atomic_lock);
}
#if CONFIG_BLE_MESH_DEINIT
static inline void bt_mesh_alarm_mutex_free(void)
{
bt_mesh_mutex_free(&alarm_lock);
}
static inline void bt_mesh_list_mutex_free(void)
{
bt_mesh_mutex_free(&list_lock);
}
static inline void bt_mesh_buf_mutex_free(void)
{
bt_mesh_mutex_free(&buf_lock);
}
static inline void bt_mesh_atomic_mutex_free(void)
{
bt_mesh_mutex_free(&atomic_lock);
}
void bt_mesh_mutex_deinit(void)
{
bt_mesh_alarm_mutex_free();
bt_mesh_list_mutex_free();
bt_mesh_buf_mutex_free();
bt_mesh_atomic_mutex_free();
bt_mesh_mutex_free(&alarm_lock);
bt_mesh_mutex_free(&list_lock);
bt_mesh_mutex_free(&buf_lock);
bt_mesh_mutex_free(&atomic_lock);
}
#endif /* CONFIG_BLE_MESH_DEINIT */

View File

@ -12,11 +12,11 @@
#include "osi/alarm.h"
#include "osi/hash_functions.h"
#include "mesh/config.h"
#include "mesh/common.h"
#include "prov_pvnr.h"
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 + \
static const size_t BLE_MESH_ALARM_HASH_MAP_SIZE = 20 + CONFIG_BLE_MESH_PBA_SAME_TIME +
CONFIG_BLE_MESH_PBG_SAME_TIME;
typedef struct alarm_t {
@ -45,7 +45,7 @@ uint32_t k_uptime_get_32(void)
void bt_mesh_timer_init(void)
{
bm_alarm_hash_map = hash_map_new(BLE_MESH_GENERAL_ALARM_HASH_MAP_SIZE,
bm_alarm_hash_map = hash_map_new(BLE_MESH_ALARM_HASH_MAP_SIZE,
hash_function_pointer, NULL,
(data_free_fn)osi_alarm_free, NULL);
__ASSERT(bm_alarm_hash_map, "Failed to create hash map");
@ -73,42 +73,53 @@ int k_delayed_work_init(struct k_delayed_work *work, k_work_handler_t handler)
k_work_init(&work->work, handler);
bt_mesh_alarm_lock();
if (!hash_map_has_key(bm_alarm_hash_map, (void *)work)) {
alarm = osi_alarm_new("bt_mesh", (osi_alarm_callback_t)handler, (void *)&work->work, 0);
if (alarm == NULL) {
BT_ERR("Alarm not created");
bt_mesh_alarm_unlock();
return -EIO;
}
if (!hash_map_set(bm_alarm_hash_map, work, (void *)alarm)) {
BT_ERR("Alarm not set");
bt_mesh_alarm_unlock();
return -EIO;
}
}
alarm = hash_map_get(bm_alarm_hash_map, work);
if (alarm == NULL) {
BT_ERR("Init, alarm not found");
if (alarm) {
BT_ERR("Init, alarm already exists");
bt_mesh_alarm_unlock();
return -ENODEV;
return -EEXIST;
}
alarm = osi_alarm_new("bt_mesh", (osi_alarm_callback_t)handler, (void *)&work->work, 0);
if (alarm == NULL) {
BT_ERR("Init, alarm not created");
bt_mesh_alarm_unlock();
return -EIO;
}
if (!hash_map_set(bm_alarm_hash_map, work, (void *)alarm)) {
BT_ERR("Init, alarm not set");
bt_mesh_alarm_unlock();
return -EIO;
}
// Just init the work timer only, don't start it.
osi_alarm_cancel(alarm);
bt_mesh_alarm_unlock();
return 0;
}
int k_delayed_work_submit(struct k_delayed_work *work, int32_t delay)
{
osi_alarm_t *alarm = NULL;
if (!work || !bm_alarm_hash_map) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
}
/* If delay is 0, call the corresponding timeout handler. */
if (delay == 0) {
k_work_submit(&work->work);
return 0;
}
bt_mesh_alarm_lock();
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
if (alarm == NULL) {
BT_WARN("Submit, alarm not found");
bt_mesh_alarm_unlock();
@ -118,19 +129,30 @@ int k_delayed_work_submit(struct k_delayed_work *work, int32_t delay)
// Cancel the alarm first, before start the alarm.
osi_alarm_cancel(alarm);
osi_alarm_set(alarm, delay);
bt_mesh_alarm_unlock();
return 0;
}
int k_delayed_work_submit_periodic(struct k_delayed_work *work, int32_t period)
{
osi_alarm_t *alarm = NULL;
if (!work || !bm_alarm_hash_map) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
}
/* If period is 0, call the corresponding timeout handler. */
if (period == 0) {
k_work_submit(&work->work);
return 0;
}
bt_mesh_alarm_lock();
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
if (alarm == NULL) {
BT_WARN("Submit, alarm not found");
bt_mesh_alarm_unlock();
@ -140,19 +162,24 @@ int k_delayed_work_submit_periodic(struct k_delayed_work *work, int32_t period)
/* Cancel the alarm first before starting it. */
osi_alarm_cancel(alarm);
osi_alarm_set_periodic(alarm, period);
bt_mesh_alarm_unlock();
return 0;
}
int k_delayed_work_cancel(struct k_delayed_work *work)
{
osi_alarm_t *alarm = NULL;
if (!work || !bm_alarm_hash_map) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
}
bt_mesh_alarm_lock();
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
if (alarm == NULL) {
BT_WARN("Cancel, alarm not found");
bt_mesh_alarm_unlock();
@ -161,19 +188,24 @@ int k_delayed_work_cancel(struct k_delayed_work *work)
osi_alarm_cancel(alarm);
alarm->deadline_us = 0;
bt_mesh_alarm_unlock();
return 0;
}
int k_delayed_work_free(struct k_delayed_work *work)
{
osi_alarm_t *alarm = NULL;
if (!work || !bm_alarm_hash_map) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
}
bt_mesh_alarm_lock();
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, work);
alarm = hash_map_get(bm_alarm_hash_map, work);
if (alarm == NULL) {
BT_WARN("Free, alarm not found");
bt_mesh_alarm_unlock();
@ -182,12 +214,15 @@ int k_delayed_work_free(struct k_delayed_work *work)
osi_alarm_cancel(alarm);
hash_map_erase(bm_alarm_hash_map, work);
bt_mesh_alarm_unlock();
return 0;
}
int32_t k_delayed_work_remaining_get(struct k_delayed_work *work)
{
osi_alarm_t *alarm = NULL;
int32_t time = 0;
if (!work || !bm_alarm_hash_map) {
@ -196,7 +231,8 @@ int32_t k_delayed_work_remaining_get(struct k_delayed_work *work)
}
bt_mesh_alarm_lock();
osi_alarm_t *alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
alarm = hash_map_get(bm_alarm_hash_map, (void *)work);
if (alarm == NULL) {
BT_WARN("Get time, alarm not found");
bt_mesh_alarm_unlock();
@ -204,6 +240,8 @@ int32_t k_delayed_work_remaining_get(struct k_delayed_work *work)
}
time = osi_alarm_get_remaining_ms(alarm);
bt_mesh_alarm_unlock();
return time;
}

View File

@ -12,6 +12,8 @@
#include "mesh.h"
#include "adv.h"
#include "lpn.h"
#include "friend.h"
#include "transport.h"
#include "access.h"
#include "foundation.h"
@ -20,11 +22,18 @@
#include "fast_prov.h"
#include "pvnr_mgmt.h"
#include "mesh_v1.1/utils.h"
#define BLE_MESH_SDU_MAX_LEN 384
static const struct bt_mesh_comp *dev_comp;
extern const struct bt_mesh_comp *comp_0;
static uint16_t dev_primary_addr;
static int model_send(struct bt_mesh_model *model,
struct bt_mesh_net_tx *tx, bool implicit_bind,
struct net_buf_simple *msg,
const struct bt_mesh_send_cb *cb, void *cb_data);
void bt_mesh_model_foreach(void (*func)(struct bt_mesh_model *mod,
struct bt_mesh_elem *elem,
bool vnd, bool primary,
@ -33,13 +42,13 @@ void bt_mesh_model_foreach(void (*func)(struct bt_mesh_model *mod,
{
int i, j;
if (dev_comp == NULL) {
if (comp_0 == NULL) {
BT_ERR("Invalid device composition");
return;
}
for (i = 0; i < dev_comp->elem_count; i++) {
struct bt_mesh_elem *elem = &dev_comp->elem[i];
for (i = 0; i < comp_0->elem_count; i++) {
struct bt_mesh_elem *elem = &comp_0->elem[i];
for (j = 0; j < elem->model_count; j++) {
struct bt_mesh_model *model = &elem->models[j];
@ -88,9 +97,9 @@ int32_t bt_mesh_model_pub_period_get(struct bt_mesh_model *mod)
if (mod->pub->fast_period) {
return period >> mod->pub->period_div;
} else {
return period;
}
return period;
}
static int32_t next_period(struct bt_mesh_model *mod)
@ -169,43 +178,49 @@ static const struct bt_mesh_send_cb pub_sent_cb = {
static int publish_retransmit(struct bt_mesh_model *mod)
{
struct bt_mesh_model_pub *pub = mod->pub;
if (!pub) {
BT_ERR("Model has no publication support");
return -ENOTSUP;
}
struct bt_mesh_app_key *key = NULL;
struct net_buf_simple *sdu = NULL;
struct bt_mesh_msg_ctx ctx = {
.addr = pub->addr,
.send_ttl = pub->ttl,
.model = mod,
.srv_send = (pub->dev_role == NODE ? true : false),
};
struct bt_mesh_msg_ctx ctx = {0};
struct bt_mesh_net_tx tx = {
.ctx = &ctx,
.src = bt_mesh_model_elem(mod)->addr,
.xmit = bt_mesh_net_transmit_get(),
.friend_cred = pub->cred,
};
int err = 0;
key = bt_mesh_tx_appkey_get(pub->dev_role, pub->key);
if (!pub || !pub->msg) {
BT_ERR("Model has no publication support");
return -ENOTSUP;
}
key = bt_mesh_app_key_get(pub->key);
if (!key) {
BT_ERR("AppKey 0x%03x not exists", pub->key);
BT_ERR("Publish, AppKey 0x%03x not found", pub->key);
return -EADDRNOTAVAIL;
}
tx.sub = bt_mesh_tx_netkey_get(pub->dev_role, key->net_idx);
tx.sub = bt_mesh_subnet_get(key->net_idx);
if (!tx.sub) {
BT_ERR("Subnet 0x%04x not exists", key->net_idx);
BT_ERR("Publish, NetKey 0x%04x not found", key->net_idx);
return -EADDRNOTAVAIL;
}
ctx.addr = pub->addr;
ctx.net_idx = key->net_idx;
ctx.app_idx = key->app_idx;
ctx.send_ttl = pub->ttl;
ctx.send_cred = pub->cred ? BLE_MESH_FRIENDSHIP_CRED : BLE_MESH_FLOODING_CRED;
ctx.send_szmic = pub->send_szmic;
if (pub->send_rel) {
/* Tag with send-segmented */
ctx.send_tag |= BLE_MESH_TAG_SEND_SEGMENTED;
}
sdu = bt_mesh_alloc_buf(pub->msg->len + BLE_MESH_MIC_SHORT);
#if CONFIG_BLE_MESH_DF_SRV
bt_mesh_model_pub_use_directed(&tx, pub->directed_pub_policy);
#endif
sdu = bt_mesh_alloc_buf(pub->msg->len + BLE_MESH_MIC_LONG);
if (!sdu) {
BT_ERR("%s, Out of memory", __func__);
return -ENOMEM;
@ -215,7 +230,7 @@ static int publish_retransmit(struct bt_mesh_model *mod)
pub->count--;
err = bt_mesh_trans_send(&tx, sdu, &pub_sent_cb, mod);
err = model_send(mod, &tx, true, sdu, &pub_sent_cb, mod);
bt_mesh_free_buf(sdu);
return err;
@ -237,8 +252,6 @@ static void mod_publish(struct k_work *work)
int32_t period_ms = 0;
int err = 0;
BT_DBG("%s", __func__);
period_ms = bt_mesh_model_pub_period_get(pub->mod);
BT_INFO("Publish period %u ms", period_ms);
@ -254,7 +267,6 @@ static void mod_publish(struct k_work *work)
k_delayed_work_submit(&pub->timer, period_ms);
}
}
return;
}
@ -282,24 +294,24 @@ static void mod_publish(struct k_work *work)
struct bt_mesh_elem *bt_mesh_model_elem(struct bt_mesh_model *mod)
{
return &dev_comp->elem[mod->elem_idx];
return &comp_0->elem[mod->elem_idx];
}
struct bt_mesh_model *bt_mesh_model_get(bool vnd, uint8_t elem_idx, uint8_t mod_idx)
{
struct bt_mesh_elem *elem = NULL;
if (!dev_comp) {
BT_ERR("dev_comp not initialized");
if (!comp_0) {
BT_ERR("comp_0 not initialized");
return NULL;
}
if (elem_idx >= dev_comp->elem_count) {
if (elem_idx >= comp_0->elem_count) {
BT_ERR("Invalid element index %u", elem_idx);
return NULL;
}
elem = &dev_comp->elem[elem_idx];
elem = &comp_0->elem[elem_idx];
if (vnd) {
if (mod_idx >= elem->vnd_model_count) {
@ -346,7 +358,7 @@ static void mod_init(struct bt_mesh_model *mod, struct bt_mesh_elem *elem,
}
mod->flags = 0;
mod->elem_idx = elem - dev_comp->elem;
mod->elem_idx = elem - comp_0->elem;
if (vnd) {
mod->model_idx = mod - elem->vnd_models;
} else {
@ -371,7 +383,7 @@ int bt_mesh_comp_register(const struct bt_mesh_comp *comp)
return -EINVAL;
}
dev_comp = comp;
comp_0 = comp;
bt_mesh_model_foreach(mod_init, &err);
@ -423,13 +435,13 @@ int bt_mesh_comp_deregister(void)
{
int err = 0;
if (dev_comp == NULL) {
if (comp_0 == NULL) {
return -EINVAL;
}
bt_mesh_model_foreach(mod_deinit, &err);
dev_comp = NULL;
comp_0 = NULL;
return err;
}
@ -441,10 +453,10 @@ void bt_mesh_comp_provision(uint16_t addr)
dev_primary_addr = addr;
BT_INFO("Primary address 0x%04x, element count %u", addr, dev_comp->elem_count);
BT_INFO("Primary address 0x%04x, element count %u", addr, comp_0->elem_count);
for (i = 0; i < dev_comp->elem_count; i++) {
struct bt_mesh_elem *elem = &dev_comp->elem[i];
for (i = 0; i < comp_0->elem_count; i++) {
struct bt_mesh_elem *elem = &comp_0->elem[i];
elem->addr = addr++;
@ -455,8 +467,6 @@ void bt_mesh_comp_provision(uint16_t addr)
void bt_mesh_comp_unprovision(void)
{
BT_DBG("%s", __func__);
dev_primary_addr = BLE_MESH_ADDR_UNASSIGNED;
}
@ -511,16 +521,16 @@ struct bt_mesh_elem *bt_mesh_elem_find(uint16_t addr)
uint16_t index = 0U;
if (BLE_MESH_ADDR_IS_UNICAST(addr)) {
index = (addr - dev_comp->elem[0].addr);
if (index < dev_comp->elem_count) {
return &dev_comp->elem[index];
} else {
return NULL;
}
index = (addr - comp_0->elem[0].addr);
if (index < comp_0->elem_count) {
return &comp_0->elem[index];
}
for (index = 0; index < dev_comp->elem_count; index++) {
struct bt_mesh_elem *elem = &dev_comp->elem[index];
return NULL;
}
for (index = 0; index < comp_0->elem_count; index++) {
struct bt_mesh_elem *elem = &comp_0->elem[index];
if (bt_mesh_elem_find_group(elem, addr)) {
return elem;
@ -532,7 +542,7 @@ struct bt_mesh_elem *bt_mesh_elem_find(uint16_t addr)
uint8_t bt_mesh_elem_count(void)
{
return dev_comp->elem_count;
return comp_0->elem_count;
}
static bool model_has_key(struct bt_mesh_model *mod, uint16_t key)
@ -548,15 +558,20 @@ static bool model_has_key(struct bt_mesh_model *mod, uint16_t key)
return false;
}
static bool model_has_dst(struct bt_mesh_model *model, uint16_t dst)
static bool model_has_dst(struct bt_mesh_model *model,
struct bt_mesh_subnet *sub,
uint16_t dst)
{
if (BLE_MESH_ADDR_IS_UNICAST(dst)) {
return (dev_comp->elem[model->elem_idx].addr == dst);
} else if (BLE_MESH_ADDR_IS_GROUP(dst) || BLE_MESH_ADDR_IS_VIRTUAL(dst)) {
return (comp_0->elem[model->elem_idx].addr == dst);
}
if (BLE_MESH_ADDR_IS_GROUP(dst) || BLE_MESH_ADDR_IS_VIRTUAL(dst)) {
return !!bt_mesh_model_find_group(model, dst);
}
return (model->elem_idx == 0 && bt_mesh_fixed_group_match(dst));
return (model->elem_idx == 0 && (bt_mesh_fixed_group_match(dst) ||
bt_mesh_fixed_direct_match(sub, dst)));
}
static const struct bt_mesh_model_op *find_op(struct bt_mesh_model *models,
@ -581,7 +596,7 @@ static const struct bt_mesh_model_op *find_op(struct bt_mesh_model *models,
return NULL;
}
static int get_opcode(struct net_buf_simple *buf, uint32_t *opcode)
static int get_opcode(struct net_buf_simple *buf, uint32_t *opcode, bool pull_buf)
{
switch (buf->data[0] >> 6) {
case 0x00:
@ -591,34 +606,51 @@ static int get_opcode(struct net_buf_simple *buf, uint32_t *opcode)
return -EINVAL;
}
*opcode = net_buf_simple_pull_u8(buf);
*opcode = pull_buf ? net_buf_simple_pull_u8(buf) : buf->data[0];
return 0;
case 0x02:
if (buf->len < 2) {
BT_ERR("Too short payload for 2-octet OpCode");
return -EINVAL;
}
*opcode = net_buf_simple_pull_be16(buf);
*opcode = pull_buf ? net_buf_simple_pull_be16(buf) : sys_get_be16(buf->data);
return 0;
case 0x03:
if (buf->len < 3) {
BT_ERR("Too short payload for 3-octet OpCode");
return -EINVAL;
}
if (pull_buf) {
*opcode = net_buf_simple_pull_u8(buf) << 16;
/* Using LE for the CID since the model layer is defined as
* little-endian in the mesh spec and using BT_MESH_MODEL_OP_3
* will declare the opcode in this way.
*/
*opcode |= net_buf_simple_pull_le16(buf);
} else {
*opcode = buf->data[0] << 16 | sys_get_le16(&buf->data[1]);
}
return 0;
}
return -EINVAL;
}
int bt_mesh_get_opcode(struct net_buf_simple *buf,
uint32_t *opcode, bool pull_buf)
{
if (buf == NULL || buf->len == 0 || opcode == NULL) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
}
return get_opcode(buf, opcode, pull_buf);
}
bool bt_mesh_fixed_group_match(uint16_t addr)
{
/* Check for fixed group addresses */
@ -636,6 +668,22 @@ bool bt_mesh_fixed_group_match(uint16_t addr)
}
}
bool bt_mesh_fixed_direct_match(struct bt_mesh_subnet *sub, uint16_t addr)
{
/* A message sent to the all-directed-forwarding-nodes address
* shall be processed by the primary element of all nodes that
* have directed forwarding functionality enabled.
*/
#if CONFIG_BLE_MESH_DF_SRV
if (addr == BLE_MESH_ADDR_DIRECTS && sub &&
sub->directed_forwarding == BLE_MESH_DIRECTED_FORWARDING_ENABLED) {
return true;
}
#endif
return false;
}
void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
{
struct bt_mesh_model *models = NULL, *model = NULL;
@ -648,15 +696,15 @@ void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
rx->ctx.addr, rx->ctx.recv_dst);
BT_INFO("recv, len %u: %s", buf->len, bt_hex(buf->data, buf->len));
if (get_opcode(buf, &opcode) < 0) {
if (get_opcode(buf, &opcode, true) < 0) {
BT_WARN("Unable to decode OpCode");
return;
}
BT_DBG("OpCode 0x%08x", opcode);
for (i = 0; i < dev_comp->elem_count; i++) {
struct bt_mesh_elem *elem = &dev_comp->elem[i];
for (i = 0; i < comp_0->elem_count; i++) {
struct bt_mesh_elem *elem = &comp_0->elem[i];
struct net_buf_simple_state state = {0};
/* SIG models cannot contain 3-byte (vendor) OpCodes, and
@ -681,7 +729,7 @@ void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
continue;
}
if (!model_has_dst(model, rx->ctx.recv_dst)) {
if (!model_has_dst(model, rx->sub, rx->ctx.recv_dst)) {
continue;
}
@ -690,17 +738,28 @@ void bt_mesh_model_recv(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
continue;
}
/* The following three operations are added by Espressif.
* 1. Update the "recv_op" with the opcode got from the buf;
* 2. Update the model pointer with the found model;
* 3. Update the "srv_send" to be true when received a message.
* This flag will be used when a server model sends a status
* message, and has no impact on the client messages.
* Most of these info will be used by the application layer.
/* The following operation is added by Espressif.
* Update the "recv_op" with the opcode got from the buf;
*/
rx->ctx.recv_op = opcode;
rx->ctx.model = model;
rx->ctx.srv_send = true;
/* The message is transmitted by a model in response to a message that
* it has received.
*
* The TTL field shall be set to the value of the Default TTL state.
*
* The response message shall use master security credentials. However,
* the security credentials may be changed by a lower layer unless the
* received message uses the master security credentials. If the received
* message uses master security credentials, then the response message
* shall be tagged with the immutable-credentials tag, and the security
* credentials will not be changed by any lower layer.
*/
rx->ctx.send_ttl = BLE_MESH_TTL_DEFAULT;
if (rx->ctx.recv_cred == BLE_MESH_FLOODING_CRED) {
rx->ctx.send_tag |= BLE_MESH_TAG_IMMUTABLE_CRED;
rx->ctx.send_cred = BLE_MESH_FLOODING_CRED;
}
/* The callback will likely parse the buffer, so store
* the parsing state in case multiple models receive
@ -737,18 +796,19 @@ void bt_mesh_model_msg_init(struct net_buf_simple *msg, uint32_t opcode)
}
}
static bool ready_to_send(uint8_t role, uint16_t dst)
static bool ready_to_send(uint16_t dst)
{
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned() && role == NODE) {
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
return true;
} else if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en() && role == PROVISIONER) {
if (!bt_mesh_provisioner_check_msg_dst(dst)) {
}
if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en()) {
if (bt_mesh_provisioner_check_msg_dst(dst) == false &&
bt_mesh_elem_find(dst) == false) {
BT_ERR("Failed to find DST 0x%04x", dst);
return false;
}
return true;
} else if (IS_ENABLED(CONFIG_BLE_MESH_FAST_PROV) && bt_mesh_is_provisioned() && role == FAST_PROV) {
return true;
}
return false;
@ -759,23 +819,23 @@ static int model_send(struct bt_mesh_model *model,
struct net_buf_simple *msg,
const struct bt_mesh_send_cb *cb, void *cb_data)
{
uint8_t role = 0U;
role = bt_mesh_get_device_role(model, tx->ctx->srv_send);
if (role == ROLE_NVAL) {
BT_ERR("Failed to get model role");
return -EINVAL;
}
int err = 0;
BT_INFO("send, app_idx 0x%04x src 0x%04x dst 0x%04x",
tx->ctx->app_idx, tx->src, tx->ctx->addr);
BT_INFO("send, len %u: %s", msg->len, bt_hex(msg->data, msg->len));
if (!ready_to_send(role, tx->ctx->addr)) {
if (ready_to_send(tx->ctx->addr) == false) {
BT_ERR("Not ready to send");
return -EINVAL;
}
if (tx->ctx->send_ttl != BLE_MESH_TTL_DEFAULT &&
tx->ctx->send_ttl > BLE_MESH_TTL_MAX) {
BT_ERR("Too big send TTL 0x%02x", tx->ctx->send_ttl);
return -EINVAL;
}
if (net_buf_simple_tailroom(msg) < BLE_MESH_MIC_SHORT) {
BT_ERR("Not enough tailroom for TransMIC");
return -EINVAL;
@ -791,7 +851,43 @@ static int model_send(struct bt_mesh_model *model,
return -EINVAL;
}
return bt_mesh_trans_send(tx, msg, cb, cb_data);
if (bt_mesh_valid_security_cred(tx) == false) {
BT_ERR("Can not use security cred 0x%02x", tx->ctx->send_cred);
return -EIO;
}
bt_mesh_choose_better_security_cred(tx);
err = bt_mesh_trans_send(tx, msg, cb, cb_data);
#if CONFIG_BLE_MESH_DF_SRV
bt_mesh_is_directed_path_needed(tx);
#endif
return err;
}
int bt_mesh_model_send_implicit(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,bool implicit_bind,
struct net_buf_simple *msg,
const struct bt_mesh_send_cb *cb, void *cb_data)
{
struct bt_mesh_subnet *sub = NULL;
sub = bt_mesh_subnet_get(ctx->net_idx);
if (!sub) {
BT_ERR("Send, NetKey 0x%04x not found", ctx->net_idx);
return -EADDRNOTAVAIL;
}
struct bt_mesh_net_tx tx = {
.sub = sub,
.ctx = ctx,
.src = bt_mesh_model_elem(model)->addr,
.xmit = bt_mesh_net_transmit_get(),
};
return model_send(model, &tx, implicit_bind, msg, cb, cb_data);
}
int bt_mesh_model_send(struct bt_mesh_model *model,
@ -800,28 +896,18 @@ int bt_mesh_model_send(struct bt_mesh_model *model,
const struct bt_mesh_send_cb *cb, void *cb_data)
{
struct bt_mesh_subnet *sub = NULL;
uint8_t role = 0U;
role = bt_mesh_get_device_role(model, ctx->srv_send);
if (role == ROLE_NVAL) {
BT_ERR("Failed to get model role");
return -EINVAL;
}
sub = bt_mesh_tx_netkey_get(role, ctx->net_idx);
sub = bt_mesh_subnet_get(ctx->net_idx);
if (!sub) {
BT_ERR("Invalid NetKeyIndex 0x%04x", ctx->net_idx);
return -EINVAL;
BT_ERR("Send, NetKey 0x%04x not found", ctx->net_idx);
return -EADDRNOTAVAIL;
}
ctx->model = model;
struct bt_mesh_net_tx tx = {
.sub = sub,
.ctx = ctx,
.src = bt_mesh_model_elem(model)->addr,
.xmit = bt_mesh_net_transmit_get(),
.friend_cred = 0,
};
return model_send(model, &tx, false, msg, cb, cb_data);
@ -832,19 +918,14 @@ int bt_mesh_model_publish(struct bt_mesh_model *model)
struct bt_mesh_model_pub *pub = model->pub;
struct bt_mesh_app_key *key = NULL;
struct net_buf_simple *sdu = NULL;
struct bt_mesh_msg_ctx ctx = {
.model = model,
};
struct bt_mesh_msg_ctx ctx = {0};
struct bt_mesh_net_tx tx = {
.sub = NULL,
.ctx = &ctx,
.src = bt_mesh_model_elem(model)->addr,
.xmit = bt_mesh_net_transmit_get(),
};
int err = 0;
BT_DBG("%s", __func__);
if (!pub || !pub->msg) {
BT_ERR("Model has no publication support");
return -ENOTSUP;
@ -855,12 +936,6 @@ int bt_mesh_model_publish(struct bt_mesh_model *model)
return -EADDRNOTAVAIL;
}
key = bt_mesh_tx_appkey_get(pub->dev_role, pub->key);
if (!key) {
BT_ERR("Invalid AppKeyIndex 0x%03x", pub->key);
return -EADDRNOTAVAIL;
}
if (pub->msg->len + BLE_MESH_MIC_SHORT > MIN(BLE_MESH_TX_SDU_MAX, BLE_MESH_SDU_MAX_LEN)) {
BT_ERR("Message does not fit maximum SDU size");
return -EMSGSIZE;
@ -871,27 +946,39 @@ int bt_mesh_model_publish(struct bt_mesh_model *model)
k_delayed_work_cancel(&pub->timer);
}
ctx.addr = pub->addr;
ctx.send_rel = pub->send_rel;
ctx.send_ttl = pub->ttl;
ctx.net_idx = key->net_idx;
ctx.app_idx = key->app_idx;
ctx.srv_send = pub->dev_role == NODE ? true : false;
tx.friend_cred = pub->cred;
tx.sub = bt_mesh_tx_netkey_get(pub->dev_role, ctx.net_idx);
if (!tx.sub) {
BT_ERR("Invalid NetKeyIndex 0x%04x", ctx.net_idx);
key = bt_mesh_app_key_get(pub->key);
if (!key) {
BT_ERR("Publish, AppKey 0x%03x not found", pub->key);
return -EADDRNOTAVAIL;
}
tx.sub = bt_mesh_subnet_get(ctx.net_idx);
if (!tx.sub) {
BT_ERR("Publish, NetKey 0x%04x not found", ctx.net_idx);
return -EADDRNOTAVAIL;
}
ctx.addr = pub->addr;
ctx.net_idx = key->net_idx;
ctx.app_idx = key->app_idx;
ctx.send_ttl = pub->ttl;
ctx.send_cred = pub->cred ? BLE_MESH_FRIENDSHIP_CRED : BLE_MESH_FLOODING_CRED;
ctx.send_szmic = pub->send_szmic;
if (pub->send_rel) {
/* Tag with send-segmented */
ctx.send_tag |= BLE_MESH_TAG_SEND_SEGMENTED;
}
#if CONFIG_BLE_MESH_DF_SRV
bt_mesh_model_pub_use_directed(&tx, pub->directed_pub_policy);
#endif
pub->count = BLE_MESH_PUB_TRANSMIT_COUNT(pub->retransmit);
BT_INFO("Publish Retransmit Count %u Interval %ums", pub->count,
BLE_MESH_PUB_TRANSMIT_INT(pub->retransmit));
sdu = bt_mesh_alloc_buf(pub->msg->len + BLE_MESH_MIC_SHORT);
sdu = bt_mesh_alloc_buf(pub->msg->len + BLE_MESH_MIC_LONG);
if (!sdu) {
BT_ERR("%s, Out of memory", __func__);
return -ENOMEM;
@ -938,56 +1025,26 @@ struct bt_mesh_model *bt_mesh_model_find(struct bt_mesh_elem *elem, uint16_t id)
const struct bt_mesh_comp *bt_mesh_comp_get(void)
{
return dev_comp;
return comp_0;
}
/* APIs used by messages encryption in upper transport layer & network layer */
struct bt_mesh_subnet *bt_mesh_tx_netkey_get(uint8_t role, uint16_t net_idx)
{
struct bt_mesh_subnet *sub = NULL;
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned() && role == NODE) {
sub = bt_mesh_subnet_get(net_idx);
} else if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en() && role == PROVISIONER) {
sub = bt_mesh_provisioner_subnet_get(net_idx);
} else if (IS_ENABLED(CONFIG_BLE_MESH_FAST_PROV) && bt_mesh_is_provisioned() && role == FAST_PROV) {
sub = bt_mesh_fast_prov_subnet_get(net_idx);
}
return sub;
}
const uint8_t *bt_mesh_tx_devkey_get(uint8_t role, uint16_t dst)
const uint8_t *bt_mesh_dev_key_get(uint16_t dst)
{
const uint8_t *key = NULL;
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned() && role == NODE) {
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
if (!IS_ENABLED(CONFIG_BLE_MESH_FAST_PROV)) {
key = bt_mesh.dev_key;
} else if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en() && role == PROVISIONER) {
key = bt_mesh_provisioner_dev_key_get(dst);
} else if (IS_ENABLED(CONFIG_BLE_MESH_FAST_PROV) && bt_mesh_is_provisioned() && role == FAST_PROV) {
} else {
key = bt_mesh_fast_prov_dev_key_get(dst);
}
return key;
}
struct bt_mesh_app_key *bt_mesh_tx_appkey_get(uint8_t role, uint16_t app_idx)
{
struct bt_mesh_app_key *key = NULL;
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned() && role == NODE) {
key = bt_mesh_app_key_find(app_idx);
} else if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en() && role == PROVISIONER) {
key = bt_mesh_provisioner_app_key_find(app_idx);
} else if (IS_ENABLED(CONFIG_BLE_MESH_FAST_PROV) && bt_mesh_is_provisioned() && role == FAST_PROV) {
key = bt_mesh_fast_prov_app_key_find(app_idx);
} else if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en()) {
key = bt_mesh_provisioner_dev_key_get(dst);
}
return key;
}
/* APIs used by messages decryption in network layer & upper transport layer */
size_t bt_mesh_rx_netkey_size(void)
{
size_t size = 0U;
@ -1048,6 +1105,9 @@ size_t bt_mesh_rx_devkey_size(void)
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (bt_mesh_is_provisioned()) {
size = 1;
if (bt_mesh_dev_key_ca_valid()) {
size += 1;
}
}
#endif
@ -1059,6 +1119,9 @@ size_t bt_mesh_rx_devkey_size(void)
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
size = 1;
if (bt_mesh_dev_key_ca_valid()) {
size += 1;
}
if (bt_mesh_is_provisioner_en()) {
size += 1;
}
@ -1073,7 +1136,11 @@ const uint8_t *bt_mesh_rx_devkey_get(size_t index, uint16_t src)
#if CONFIG_BLE_MESH_NODE && !CONFIG_BLE_MESH_PROVISIONER
if (bt_mesh_is_provisioned()) {
if (index == 0) {
key = bt_mesh.dev_key;
} else if (index == 1) {
key = bt_mesh.dev_key_ca;
}
}
#endif
@ -1084,8 +1151,18 @@ const uint8_t *bt_mesh_rx_devkey_get(size_t index, uint16_t src)
#endif
#if CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PROVISIONER
if (index < 1) {
if (index == 0) {
key = bt_mesh.dev_key;
} else if (index == 1 && bt_mesh_dev_key_ca_valid()) {
/* If index == 1, there are two cases.
* 1. bt_mesh_dev_key_ca_valid() is true, it should be return bt_mesh.dev_key_ca.
* 2. bt_mesh_is_provisioner_en() is true, it should be return bt_mesh_provisioner_dev_key_get(src).
*
* If index == 2, that means bt_mesh_dev_key_ca_valid() and bt_mesh_is_provisioner_en() are true.
* So the previous round of function bt_mesh_rx_devkey_get(1, src) will return bt_mesh.dev_key_ca.
* Then this round of function bt_mesh_rx_devkey_get(2, src) will return bt_mesh_provisioner_dev_key_get(src).
*/
key = bt_mesh.dev_key_ca;
} else {
key = bt_mesh_provisioner_dev_key_get(src);
}

View File

@ -31,8 +31,13 @@ struct bt_mesh_elem *bt_mesh_elem_find(uint16_t addr);
uint16_t *bt_mesh_model_find_group(struct bt_mesh_model *mod, uint16_t addr);
int bt_mesh_get_opcode(struct net_buf_simple *buf,
uint32_t *opcode, bool pull_buf);
bool bt_mesh_fixed_group_match(uint16_t addr);
bool bt_mesh_fixed_direct_match(struct bt_mesh_subnet *sub, uint16_t addr);
void bt_mesh_model_foreach(void (*func)(struct bt_mesh_model *mod,
struct bt_mesh_elem *elem,
bool vnd, bool primary,
@ -55,11 +60,7 @@ 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);
int bt_mesh_comp_deregister(void);
struct bt_mesh_subnet *bt_mesh_tx_netkey_get(uint8_t role, uint16_t net_idx);
const uint8_t *bt_mesh_tx_devkey_get(uint8_t role, uint16_t dst);
struct bt_mesh_app_key *bt_mesh_tx_appkey_get(uint8_t role, uint16_t app_idx);
const uint8_t *bt_mesh_dev_key_get(uint16_t dst);
size_t bt_mesh_rx_netkey_size(void);

View File

@ -11,11 +11,11 @@
#include <string.h>
#include <errno.h>
#include "mesh/kernel.h"
#include "adv.h"
#include "mesh.h"
#include "mesh/hci.h"
#include "mesh/kernel.h"
#include "mesh/common.h"
#include "adv.h"
#include "beacon.h"
#include "prov_node.h"
#include "foundation.h"
@ -63,7 +63,7 @@ static struct bt_mesh_queue adv_queue;
#define BLE_MESH_ADV_QUEUE_SIZE (CONFIG_BLE_MESH_ADV_BUF_COUNT + 1)
#endif
#if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
#if CONFIG_BLE_MESH_RELAY_ADV_BUF
NET_BUF_POOL_DEFINE(relay_adv_buf_pool, CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT,
BLE_MESH_ADV_DATA_SIZE, BLE_MESH_ADV_USER_DATA_SIZE, NULL);
@ -79,7 +79,7 @@ static QueueSetHandle_t mesh_queue_set;
#define BLE_MESH_MAX_TIME_INTERVAL 0xFFFFFFFF
static bool ignore_relay_packet(uint32_t timestamp);
#endif /* defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
#endif /* CONFIG_BLE_MESH_RELAY_ADV_BUF */
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
/* length + advertising data + length + scan response data */
@ -175,9 +175,21 @@ static inline int adv_send(struct net_buf *buf)
param.interval_min = ADV_SCAN_UNIT(adv_int);
param.interval_max = param.interval_min;
#if CONFIG_BLE_MESH_PROXY_SOLIC_PDU_TX
if (BLE_MESH_ADV(buf)->type == BLE_MESH_ADV_PROXY_SOLIC) {
bt_mesh_adv_buf_ref_debug(__func__, buf, 3U, BLE_MESH_BUF_REF_SMALL);
struct bt_mesh_adv_data solic_ad[3] = {
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, 0x29, 0x18),
BLE_MESH_ADV_DATA(BLE_MESH_DATA_SVC_DATA16, buf->data, buf->len),
};
err = bt_le_adv_start(&param, solic_ad, 3, NULL, 0);
} else
#endif
{
bt_mesh_adv_buf_ref_debug(__func__, buf, 4U, BLE_MESH_BUF_REF_SMALL);
err = bt_le_adv_start(&param, &ad, 1, NULL, 0);
}
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
} else {
struct bt_mesh_ble_adv_data data = {0};
@ -238,7 +250,7 @@ static inline TickType_t K_WAIT(int32_t val)
static void adv_thread(void *p)
{
#if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
#if CONFIG_BLE_MESH_RELAY_ADV_BUF
QueueSetMemberHandle_t handle = NULL;
#endif
bt_mesh_msg_t msg = {0};
@ -250,7 +262,7 @@ static void adv_thread(void *p)
while (1) {
*buf = NULL;
#if !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
#if !CONFIG_BLE_MESH_RELAY_ADV_BUF
#if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_SERVER
xQueueReceive(adv_queue.handle, &msg, K_NO_WAIT);
@ -266,7 +278,7 @@ static void adv_thread(void *p)
#else
xQueueReceive(adv_queue.handle, &msg, portMAX_DELAY);
#endif /* (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_SERVER */
#else /* !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
#else /* !CONFIG_BLE_MESH_RELAY_ADV_BUF */
#if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_SERVER
handle = xQueueSelectFromSet(mesh_queue_set, K_NO_WAIT);
@ -304,7 +316,7 @@ static void adv_thread(void *p)
}
}
#endif /* (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_SERVER */
#endif /* !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
#endif /* !CONFIG_BLE_MESH_RELAY_ADV_BUF */
if (*buf == NULL) {
continue;
@ -313,11 +325,11 @@ static void adv_thread(void *p)
/* busy == 0 means this was canceled */
if (BLE_MESH_ADV(*buf)->busy) {
BLE_MESH_ADV(*buf)->busy = 0U;
#if !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
#if !CONFIG_BLE_MESH_RELAY_ADV_BUF
if (adv_send(*buf)) {
BT_WARN("Failed to send adv packet");
}
#else /* !defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
#else /* !CONFIG_BLE_MESH_RELAY_ADV_BUF */
if (msg.relay && ignore_relay_packet(msg.timestamp)) {
/* If the interval between "current time - msg.timestamp" is bigger than
* BLE_MESH_RELAY_TIME_INTERVAL, this relay packet will not be sent.
@ -329,7 +341,7 @@ static void adv_thread(void *p)
BT_WARN("Failed to send adv packet");
}
}
#endif
#endif /* !CONFIG_BLE_MESH_RELAY_ADV_BUF */
} else {
bt_mesh_adv_buf_ref_debug(__func__, *buf, 1U, BLE_MESH_BUF_REF_EQUAL);
net_buf_unref(*buf);
@ -343,7 +355,7 @@ static void adv_thread(void *p)
struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool,
bt_mesh_adv_alloc_t get_id,
enum bt_mesh_adv_type type,
uint8_t xmit, int32_t timeout)
int32_t timeout)
{
struct bt_mesh_adv *adv = NULL;
struct net_buf *buf = NULL;
@ -367,7 +379,6 @@ struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool,
(void)memset(adv, 0, sizeof(*adv));
adv->type = type;
adv->xmit = xmit;
return buf;
}
@ -390,11 +401,10 @@ void bt_mesh_unref_buf_from_pool(struct net_buf_pool *pool)
}
}
struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, uint8_t xmit,
int32_t timeout)
struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, int32_t timeout)
{
return bt_mesh_adv_create_from_pool(&adv_buf_pool, adv_alloc, type,
xmit, timeout);
return bt_mesh_adv_create_from_pool(&adv_buf_pool, adv_alloc,
type, timeout);
}
void bt_mesh_adv_buf_ref_debug(const char *func, struct net_buf *buf,
@ -433,14 +443,10 @@ static void bt_mesh_unref_buf(bt_mesh_msg_t *msg)
}
net_buf_unref(buf);
}
return;
}
static void bt_mesh_task_post(bt_mesh_msg_t *msg, uint32_t timeout, bool front)
{
BT_DBG("%s", __func__);
if (adv_queue.handle == NULL) {
BT_ERR("Invalid adv queue");
return;
@ -459,7 +465,8 @@ static void bt_mesh_task_post(bt_mesh_msg_t *msg, uint32_t timeout, bool front)
}
}
void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
void bt_mesh_adv_send(struct net_buf *buf, uint8_t xmit,
const struct bt_mesh_send_cb *cb,
void *cb_data)
{
bt_mesh_msg_t msg = {
@ -472,6 +479,7 @@ void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
BLE_MESH_ADV(buf)->cb = cb;
BLE_MESH_ADV(buf)->cb_data = cb_data;
BLE_MESH_ADV(buf)->busy = 1U;
BLE_MESH_ADV(buf)->xmit = xmit;
bt_mesh_adv_buf_ref_debug(__func__, buf, 3U, BLE_MESH_BUF_REF_SMALL);
@ -486,12 +494,10 @@ void bt_mesh_adv_update(void)
.arg = NULL,
};
BT_DBG("%s", __func__);
bt_mesh_task_post(&msg, K_NO_WAIT, false);
}
#if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
#if CONFIG_BLE_MESH_RELAY_ADV_BUF
static bool ignore_relay_packet(uint32_t timestamp)
{
uint32_t now = k_uptime_get_32();
@ -511,11 +517,10 @@ static struct bt_mesh_adv *relay_adv_alloc(int id)
return &relay_adv_pool[id];
}
struct net_buf *bt_mesh_relay_adv_create(enum bt_mesh_adv_type type, uint8_t xmit,
int32_t timeout)
struct net_buf *bt_mesh_relay_adv_create(enum bt_mesh_adv_type type, int32_t timeout)
{
return bt_mesh_adv_create_from_pool(&relay_adv_buf_pool, relay_adv_alloc, type,
xmit, timeout);
return bt_mesh_adv_create_from_pool(&relay_adv_buf_pool, relay_adv_alloc,
type, timeout);
}
static void ble_mesh_relay_task_post(bt_mesh_msg_t *msg, uint32_t timeout)
@ -523,8 +528,6 @@ static void ble_mesh_relay_task_post(bt_mesh_msg_t *msg, uint32_t timeout)
QueueSetMemberHandle_t handle = NULL;
bt_mesh_msg_t old_msg = {0};
BT_DBG("%s", __func__);
if (relay_queue.handle == NULL) {
BT_ERR("Invalid relay queue");
return;
@ -534,8 +537,7 @@ static void ble_mesh_relay_task_post(bt_mesh_msg_t *msg, uint32_t timeout)
return;
}
/**
* If failed to send packet to the relay queue(queue is full), we will
/* If failed to send packet to the relay queue(queue is full), we will
* remove the oldest packet in the queue and put the new one into it.
*/
handle = xQueueSelectFromSet(mesh_queue_set, K_NO_WAIT);
@ -561,8 +563,10 @@ static void ble_mesh_relay_task_post(bt_mesh_msg_t *msg, uint32_t timeout)
}
}
void bt_mesh_relay_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
void *cb_data, uint16_t src, uint16_t dst)
void bt_mesh_relay_adv_send(struct net_buf *buf, uint8_t xmit,
uint16_t src, uint16_t dst,
const struct bt_mesh_send_cb *cb,
void *cb_data)
{
bt_mesh_msg_t msg = {
.relay = true,
@ -574,6 +578,7 @@ void bt_mesh_relay_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *c
BLE_MESH_ADV(buf)->cb = cb;
BLE_MESH_ADV(buf)->cb_data = cb_data;
BLE_MESH_ADV(buf)->busy = 1U;
BLE_MESH_ADV(buf)->xmit = xmit;
msg.arg = (void *)net_buf_ref(buf);
msg.src = src;
@ -587,7 +592,7 @@ uint16_t bt_mesh_get_stored_relay_count(void)
{
return (uint16_t)uxQueueMessagesWaiting(relay_queue.handle);
}
#endif /* #if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
#endif /* #if CONFIG_BLE_MESH_RELAY_ADV_BUF */
void bt_mesh_adv_init(void)
{
@ -611,7 +616,7 @@ void bt_mesh_adv_init(void)
__ASSERT(adv_queue.handle, "Failed to create static queue");
#endif /* !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */
#if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
#if CONFIG_BLE_MESH_RELAY_ADV_BUF
#if !CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC
relay_queue.handle = xQueueCreate(BLE_MESH_RELAY_QUEUE_SIZE, sizeof(bt_mesh_msg_t));
__ASSERT(relay_queue.handle, "Failed to create relay queue");
@ -636,7 +641,7 @@ void bt_mesh_adv_init(void)
__ASSERT(mesh_queue_set, "Failed to create queue set");
xQueueAddToSet(adv_queue.handle, mesh_queue_set);
xQueueAddToSet(relay_queue.handle, mesh_queue_set);
#endif /* defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
#endif /* CONFIG_BLE_MESH_RELAY_ADV_BUF */
#if (CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC_EXTERNAL && \
(CONFIG_SPIRAM_CACHE_WORKAROUND || !CONFIG_IDF_TARGET_ESP32) && \
@ -674,7 +679,7 @@ void bt_mesh_adv_deinit(void)
adv_task.task = NULL;
#endif
#if defined(CONFIG_BLE_MESH_RELAY_ADV_BUF)
#if CONFIG_BLE_MESH_RELAY_ADV_BUF
xQueueRemoveFromSet(adv_queue.handle, mesh_queue_set);
xQueueRemoveFromSet(relay_queue.handle, mesh_queue_set);
@ -685,14 +690,14 @@ void bt_mesh_adv_deinit(void)
relay_queue.buffer = NULL;
heap_caps_free(relay_queue.storage);
relay_queue.storage = NULL;
#endif
#endif /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */
bt_mesh_unref_buf_from_pool(&relay_adv_buf_pool);
memset(relay_adv_pool, 0, sizeof(relay_adv_pool));
vQueueDelete(mesh_queue_set);
mesh_queue_set = NULL;
#endif /* defined(CONFIG_BLE_MESH_RELAY_ADV_BUF) */
#endif /* CONFIG_BLE_MESH_RELAY_ADV_BUF */
vQueueDelete(adv_queue.handle);
adv_queue.handle = NULL;
@ -701,14 +706,14 @@ void bt_mesh_adv_deinit(void)
adv_queue.buffer = NULL;
heap_caps_free(adv_queue.storage);
adv_queue.storage = NULL;
#endif
#endif /* CONFIG_BLE_MESH_FREERTOS_STATIC_ALLOC */
bt_mesh_unref_buf_from_pool(&adv_buf_pool);
memset(adv_pool, 0, sizeof(adv_pool));
#if CONFIG_BLE_MESH_SUPPORT_BLE_ADV
bt_mesh_ble_adv_deinit();
#endif
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_ADV */
}
#endif /* CONFIG_BLE_MESH_DEINIT */
@ -718,10 +723,10 @@ static struct bt_mesh_adv *ble_adv_alloc(int id)
return &ble_adv_pool[id];
}
static struct net_buf *bt_mesh_ble_adv_create(enum bt_mesh_adv_type type, uint8_t xmit, int32_t timeout)
static struct net_buf *bt_mesh_ble_adv_create(enum bt_mesh_adv_type type, int32_t timeout)
{
return bt_mesh_adv_create_from_pool(&ble_adv_buf_pool, ble_adv_alloc, type,
xmit, timeout);
return bt_mesh_adv_create_from_pool(&ble_adv_buf_pool, ble_adv_alloc,
type, timeout);
}
static void bt_mesh_ble_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
@ -789,11 +794,7 @@ static void ble_adv_send_end(int err, void *cb_data)
}
if (tx->param.count) {
if (tx->param.period) {
k_delayed_work_submit(&tx->resend, tx->param.period);
} else {
k_work_submit(&tx->resend.work);
}
} else {
ble_adv_tx_reset(tx, true);
}
@ -806,7 +807,9 @@ static struct bt_mesh_send_cb ble_adv_send_cb = {
static void ble_adv_resend(struct k_work *work)
{
struct ble_adv_tx *tx = CONTAINER_OF(work, struct ble_adv_tx, resend.work);
struct ble_adv_tx *tx = CONTAINER_OF(work,
struct ble_adv_tx,
resend.work);
bool front = false;
if (tx->buf == NULL) {
@ -880,7 +883,7 @@ int bt_mesh_start_ble_advertising(const struct bt_mesh_ble_adv_param *param,
return -EINVAL;
}
buf = bt_mesh_ble_adv_create(BLE_MESH_ADV_BLE, 0U, K_NO_WAIT);
buf = bt_mesh_ble_adv_create(BLE_MESH_ADV_BLE, K_NO_WAIT);
if (!buf) {
BT_ERR("No empty ble adv buffer");
return -ENOBUFS;

View File

@ -39,6 +39,7 @@ enum bt_mesh_adv_type {
BLE_MESH_ADV_BEACON,
BLE_MESH_ADV_URI,
BLE_MESH_ADV_BLE,
BLE_MESH_ADV_PROXY_SOLIC,
};
struct bt_mesh_adv {
@ -52,9 +53,7 @@ struct bt_mesh_adv {
typedef struct bt_mesh_adv *(*bt_mesh_adv_alloc_t)(int id);
/* xmit_count: Number of retransmissions, i.e. 0 == 1 transmission */
struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, uint8_t xmit,
int32_t timeout);
struct net_buf *bt_mesh_adv_create(enum bt_mesh_adv_type type, int32_t timeout);
typedef enum {
BLE_MESH_BUF_REF_EQUAL,
@ -68,18 +67,20 @@ void bt_mesh_adv_buf_ref_debug(const char *func, struct net_buf *buf,
struct net_buf *bt_mesh_adv_create_from_pool(struct net_buf_pool *pool,
bt_mesh_adv_alloc_t get_id,
enum bt_mesh_adv_type type,
uint8_t xmit, int32_t timeout);
int32_t timeout);
void bt_mesh_unref_buf_from_pool(struct net_buf_pool *pool);
void bt_mesh_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
void bt_mesh_adv_send(struct net_buf *buf, uint8_t xmit,
const struct bt_mesh_send_cb *cb,
void *cb_data);
struct net_buf *bt_mesh_relay_adv_create(enum bt_mesh_adv_type type, uint8_t xmit,
int32_t timeout);
struct net_buf *bt_mesh_relay_adv_create(enum bt_mesh_adv_type type, int32_t timeout);
void bt_mesh_relay_adv_send(struct net_buf *buf, const struct bt_mesh_send_cb *cb,
void *cb_data, uint16_t src, uint16_t dst);
void bt_mesh_relay_adv_send(struct net_buf *buf, uint8_t xmit,
uint16_t src, uint16_t dst,
const struct bt_mesh_send_cb *cb,
void *cb_data);
uint16_t bt_mesh_get_stored_relay_count(void);

View File

@ -11,41 +11,45 @@
#include <errno.h>
#include "adv.h"
#include "scan.h"
#include "mesh.h"
#include "prov_node.h"
#include "crypto.h"
#include "beacon.h"
#include "access.h"
#include "foundation.h"
#include "proxy_client.h"
#include "mesh/main.h"
#include "prov_common.h"
#include "prov_node.h"
#include "prov_pvnr.h"
#include "pvnr_mgmt.h"
#include "mesh/common.h"
#include "mesh_v1.1/utils.h"
#if defined(CONFIG_BLE_MESH_UNPROVISIONED_BEACON_INTERVAL)
#define UNPROVISIONED_INTERVAL K_SECONDS(CONFIG_BLE_MESH_UNPROVISIONED_BEACON_INTERVAL)
#define UNPROV_BEACON_INTERVAL K_SECONDS(CONFIG_BLE_MESH_UNPROVISIONED_BEACON_INTERVAL)
#else
#define UNPROVISIONED_INTERVAL K_SECONDS(5)
#define UNPROV_BEACON_INTERVAL K_SECONDS(5)
#endif
#define PROVISIONED_INTERVAL K_SECONDS(10)
#define BEACON_TYPE_UNPROVISIONED 0x00
#define BEACON_TYPE_SECURE 0x01
#define SECURE_BEACON_INTERVAL K_SECONDS(10)
/* 3 transmissions, 20ms interval */
#define UNPROV_XMIT BLE_MESH_TRANSMIT(2, 20)
/* 1 transmission, 20ms interval */
#define PROV_XMIT BLE_MESH_TRANSMIT(0, 20)
#define SNB_XMIT BLE_MESH_TRANSMIT(0, 20)
#define SNB_NET_IDX_SET(_val) ((void *)((uint32_t)(_val)))
#define SNB_NET_IDX_GET(_ptr) ((uint32_t)(_ptr))
/* For a device, using the snb_timer when sending Unprovisioned Device Beacon;
* For a node, using the snb_timer when sending Secure Network Beacon.
*/
static struct k_delayed_work snb_timer;
static struct k_delayed_work beacon_timer;
static struct bt_mesh_subnet *cache_check(uint8_t data[21])
struct bt_mesh_subnet *cache_check(uint8_t data[21], bool private_beacon)
{
size_t subnet_size = 0U;
uint8_t *cache = NULL;
int i = 0;
subnet_size = bt_mesh_rx_netkey_size();
@ -57,7 +61,13 @@ static struct bt_mesh_subnet *cache_check(uint8_t data[21])
continue;
}
if (!memcmp(sub->beacon_cache, data, 21)) {
#if CONFIG_BLE_MESH_PRIVATE_BEACON
cache = private_beacon ? sub->mpb_cache : sub->snb_cache;
#else
cache = sub->snb_cache;
#endif
if (!memcmp(cache, data, 21)) {
return sub;
}
}
@ -65,19 +75,26 @@ static struct bt_mesh_subnet *cache_check(uint8_t data[21])
return NULL;
}
static void cache_add(uint8_t data[21], struct bt_mesh_subnet *sub)
void cache_add(uint8_t data[21], struct bt_mesh_subnet *sub, bool private_beacon)
{
memcpy(sub->beacon_cache, data, 21);
#if CONFIG_BLE_MESH_PRIVATE_BEACON
if (private_beacon) {
memcpy(sub->mpb_cache, data, 21);
} else
#endif
{
memcpy(sub->snb_cache, data, 21);
}
}
static void beacon_complete(int err, void *user_data)
static void secure_beacon_complete(int err, void *user_data)
{
struct bt_mesh_subnet *sub = NULL;
uint16_t net_idx = BLE_MESH_KEY_UNUSED;
BT_DBG("err %d", err);
net_idx = (uint16_t)SNB_NET_IDX_GET(user_data);
net_idx = (uint16_t)NET_IDX_GET(user_data);
/* For node, directly updating the "beacon_sent" timestamp is fine,
* since the subnet is pre-allocated.
@ -86,19 +103,13 @@ static void beacon_complete(int err, void *user_data)
* a chance that the subnet is removed just before the completion of
* sending the Secure Network Beacon.
*/
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
sub = bt_mesh_subnet_get(net_idx);
} else if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) &&
bt_mesh_is_provisioner_en()) {
sub = bt_mesh_provisioner_subnet_get(net_idx);
}
if (sub) {
sub->beacon_sent = k_uptime_get_32();
sub->snb_sent = k_uptime_get_32();
}
}
void bt_mesh_beacon_create(struct bt_mesh_subnet *sub,
void bt_mesh_secure_beacon_create(struct bt_mesh_subnet *sub,
struct net_buf_simple *buf)
{
uint8_t flags = bt_mesh_net_flags(sub);
@ -122,26 +133,21 @@ void bt_mesh_beacon_create(struct bt_mesh_subnet *sub,
net_buf_simple_add_mem(buf, sub->auth, 8);
BT_INFO("net_idx 0x%03x iv_index 0x%08x flags 0x%02x",
BT_DBG("SNB: net_idx 0x%03x iv_index 0x%08x flags 0x%02x",
sub->net_idx, bt_mesh.iv_index, flags);
BT_DBG("NetID %s Auth %s", bt_hex(keys->net_id, 8),
BT_DBG("SNB: NetID %s Auth %s", bt_hex(keys->net_id, 8),
bt_hex(sub->auth, 8));
}
/* If the interval has passed or is within 5 seconds from now send a beacon */
#define BEACON_THRESHOLD(sub) (K_SECONDS(10 * ((sub)->beacons_last + 1)) - K_SECONDS(5))
static int secure_beacon_send(void)
{
static const struct bt_mesh_send_cb send_cb = {
.end = beacon_complete,
.end = secure_beacon_complete,
};
uint32_t now = k_uptime_get_32();
size_t subnet_size = 0U;
int i = 0;
BT_DBG("%s", __func__);
subnet_size = bt_mesh_rx_netkey_size();
for (i = 0; i < subnet_size; i++) {
@ -153,129 +159,138 @@ static int secure_beacon_send(void)
continue;
}
time_diff = now - sub->beacon_sent;
time_diff = now - sub->snb_sent;
if (time_diff < K_SECONDS(600) &&
time_diff < BEACON_THRESHOLD(sub)) {
time_diff < BEACON_THRESHOLD(sub->snb_last)) {
continue;
}
/**
* If a node enables the Proxy Client functionality, and it
/* If a node enables the Proxy Client functionality, and it
* succeeds to send Secure Network Beacon with GATT bearer,
* here we will continue to send Secure Network Beacon of
* other subnets.
*/
#if defined(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)
if (bt_mesh_proxy_client_beacon_send(sub)) {
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
if (bt_mesh_proxy_client_beacon_send(sub, false)) {
continue;
}
#endif
buf = bt_mesh_adv_create(BLE_MESH_ADV_BEACON, PROV_XMIT,
K_NO_WAIT);
buf = bt_mesh_adv_create(BLE_MESH_ADV_BEACON, K_NO_WAIT);
if (!buf) {
BT_ERR("Out of beacon buffer");
BT_ERR("Out of secure beacon buffer");
return -ENOBUFS;
}
bt_mesh_beacon_create(sub, &buf->b);
bt_mesh_secure_beacon_create(sub, &buf->b);
/* Care should be taken here. Previously the user_data is the
* pointer of a subnet. When the device is a Provisioner, its
* subnet is created dynamically. If the corresponding subnet
* is removed right after the Secure Network Beacon is sent,
* update its "beacon_sent" timestamp in beacon_complete() will
* cause exception.
* update its "snb_sent" timestamp in secure_beacon_complete()
* will cause exception.
* Here we use the "net_idx" of the subnet instead. And in the
* beacon_complete(), we will try to get the subnet before
* updating its "beacon_sent" timestamp.
* secure_beacon_complete(), we will try to get the subnet before
* updating its "snb_sent" timestamp.
*/
bt_mesh_adv_send(buf, &send_cb, SNB_NET_IDX_SET(sub->net_idx));
bt_mesh_adv_send(buf, SNB_XMIT, &send_cb, NET_IDX_SET(sub->net_idx));
net_buf_unref(buf);
}
return 0;
}
#if defined(CONFIG_BLE_MESH_NODE)
#if (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_ADV)
static int unprovisioned_beacon_send(void)
{
#if defined(CONFIG_BLE_MESH_PB_ADV)
const struct bt_mesh_prov *prov = NULL;
uint8_t uri_hash[16] = { 0 };
uint8_t uri_hash[16] = {0};
struct net_buf *buf = NULL;
uint16_t oob_info = 0U;
BT_DBG("%s", __func__);
if (bt_mesh_prov_get() == NULL) {
BT_ERR("No provisioning context provided");
return -EINVAL;
}
buf = bt_mesh_adv_create(BLE_MESH_ADV_BEACON, UNPROV_XMIT, K_NO_WAIT);
buf = bt_mesh_adv_create(BLE_MESH_ADV_BEACON, K_NO_WAIT);
if (!buf) {
BT_ERR("Out of beacon buffer");
BT_ERR("Out of unprov beacon buffer");
return -ENOBUFS;
}
prov = bt_mesh_prov_get();
net_buf_add_u8(buf, BEACON_TYPE_UNPROVISIONED);
net_buf_add_mem(buf, prov->uuid, 16);
net_buf_add_mem(buf, bt_mesh_prov_get()->uuid, 16);
if (prov->uri && bt_mesh_s1(prov->uri, uri_hash) == 0) {
oob_info = prov->oob_info | BLE_MESH_PROV_OOB_URI;
if (bt_mesh_prov_get()->uri &&
bt_mesh_s1(bt_mesh_prov_get()->uri, uri_hash) == 0) {
oob_info = bt_mesh_prov_get()->oob_info | BLE_MESH_PROV_OOB_URI;
} else {
oob_info = prov->oob_info;
oob_info = bt_mesh_prov_get()->oob_info;
}
net_buf_add_be16(buf, oob_info);
net_buf_add_mem(buf, uri_hash, 4);
bt_mesh_adv_send(buf, NULL, NULL);
bt_mesh_adv_send(buf, UNPROV_XMIT, NULL, NULL);
net_buf_unref(buf);
if (prov->uri) {
size_t len;
if (bt_mesh_prov_get()->uri) {
size_t len = 0;
buf = bt_mesh_adv_create(BLE_MESH_ADV_URI, UNPROV_XMIT,
K_NO_WAIT);
buf = bt_mesh_adv_create(BLE_MESH_ADV_URI, K_NO_WAIT);
if (!buf) {
BT_ERR("Unable to allocate URI buffer");
return -ENOBUFS;
}
len = strlen(prov->uri);
len = strlen(bt_mesh_prov_get()->uri);
if (net_buf_tailroom(buf) < len) {
BT_WARN("Too long URI to fit advertising data");
} else {
net_buf_add_mem(buf, prov->uri, len);
bt_mesh_adv_send(buf, NULL, NULL);
net_buf_add_mem(buf, bt_mesh_prov_get()->uri, len);
bt_mesh_adv_send(buf, UNPROV_XMIT, NULL, NULL);
}
net_buf_unref(buf);
}
#endif /* CONFIG_BLE_MESH_PB_ADV */
return 0;
}
#else /* CONFIG_BLE_MESH_NODE */
#else /* (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_ADV) */
static int unprovisioned_beacon_send(void)
{
return 0;
}
#endif /* CONFIG_BLE_MESH_NODE */
#endif /* (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_ADV) */
static void update_beacon_observation(void)
void update_beacon_observation(bool private_beacon)
{
static bool first_half;
static bool snb_first_half;
size_t subnet_size = 0U;
int i = 0;
/* Observation period is 20 seconds, whereas the beacon timer
* runs every 10 seconds. We process what's happened during the
* window only after the second half.
* runs every 10 seconds. We process what's happened during
* the window only after the second half.
*/
first_half = !first_half;
if (first_half) {
#if CONFIG_BLE_MESH_PRB_SRV
static bool mpb_first_half;
if (private_beacon) {
mpb_first_half = !mpb_first_half;
if (mpb_first_half) {
return;
}
} else
#endif
{
snb_first_half = !snb_first_half;
if (snb_first_half) {
return;
}
}
subnet_size = bt_mesh_rx_netkey_size();
@ -286,8 +301,16 @@ static void update_beacon_observation(void)
continue;
}
sub->beacons_last = sub->beacons_cur;
sub->beacons_cur = 0U;
#if CONFIG_BLE_MESH_PRB_SRV
if (private_beacon) {
sub->mpb_last = sub->mpb_cur;
sub->mpb_cur = 0U;
} else
#endif
{
sub->snb_last = sub->snb_cur;
sub->snb_cur = 0U;
}
}
}
@ -299,34 +322,31 @@ static bool ready_to_send(void)
return false;
}
static void beacon_send(struct k_work *work)
static void secure_beacon_send_timeout(struct k_work *work)
{
/* Don't send anything if we have an active provisioning link */
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node() &&
IS_ENABLED(CONFIG_BLE_MESH_PROV) && bt_prov_active()) {
k_delayed_work_submit(&beacon_timer, UNPROVISIONED_INTERVAL);
IS_ENABLED(CONFIG_BLE_MESH_PROV) && bt_mesh_prov_active()) {
k_delayed_work_submit(&snb_timer, UNPROV_BEACON_INTERVAL);
return;
}
BT_DBG("%s", __func__);
if (ready_to_send()) {
update_beacon_observation();
update_beacon_observation(false);
secure_beacon_send();
/* Only resubmit if beaconing is still enabled */
if (bt_mesh_beacon_get() == BLE_MESH_BEACON_ENABLED ||
if (bt_mesh_secure_beacon_get() == BLE_MESH_SECURE_BEACON_ENABLED ||
bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_IVU_INITIATOR)) {
k_delayed_work_submit(&beacon_timer,
PROVISIONED_INTERVAL);
k_delayed_work_submit(&snb_timer, SECURE_BEACON_INTERVAL);
}
} else {
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node()) {
unprovisioned_beacon_send();
k_delayed_work_submit(&beacon_timer, UNPROVISIONED_INTERVAL);
k_delayed_work_submit(&snb_timer, UNPROV_BEACON_INTERVAL);
}
}
}
static void secure_beacon_recv(struct net_buf_simple *buf)
@ -339,12 +359,12 @@ static void secure_beacon_recv(struct net_buf_simple *buf)
bool new_key = false;
uint8_t flags = 0U;
if (buf->len < 21) {
BT_ERR("Too short secure beacon (len %u)", buf->len);
if (buf->len != 21) {
BT_ERR("Malformed secure beacon (len %u)", buf->len);
return;
}
sub = cache_check(buf->data);
sub = cache_check(buf->data, false);
if (sub) {
/* We've seen this beacon before - just update the stats */
goto update_stats;
@ -361,9 +381,9 @@ static void secure_beacon_recv(struct net_buf_simple *buf)
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);
sub = bt_mesh_subnet_find_with_snb(net_id, flags, iv_index, auth, &new_key);
if (!sub) {
BT_DBG("No subnet that matched beacon");
BT_DBG("No subnet that matched secure beacon");
return;
}
@ -372,16 +392,16 @@ static void secure_beacon_recv(struct net_buf_simple *buf)
return;
}
cache_add(data, sub);
cache_add(data, sub, false);
/* Spec v1.0.1, Section 3.8.4:
* If a node on a primary subnet receives an update on
/* If we have NetKey0 accept initiation only from it.
*
* Spec v1.1, Section 3.8.4:
* If a device on a primary subnet receives an update on
* the primary subnet, it shall propagate the IV update
* to all other subnets. If a node on a primary subnet
* to all other subnets. If a device on a primary subnet
* receives an IV update on any other subnet, the update
* shall be ignored.
* If a node on a primary subnet receives an key update
* on any other subnet, the update shall not be ignored.
*/
if (bt_mesh_primary_subnet_exist() &&
sub->net_idx != BLE_MESH_KEY_PRIMARY &&
@ -391,7 +411,7 @@ static void secure_beacon_recv(struct net_buf_simple *buf)
goto update_stats;
}
BT_INFO("net_idx 0x%03x iv_index 0x%08x current iv_index 0x%08x",
BT_DBG("SNB: net_idx 0x%03x iv_index 0x%08x current iv_index 0x%08x",
sub->net_idx, iv_index, bt_mesh.iv_index);
if (bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_IVU_INITIATOR) &&
@ -412,7 +432,7 @@ static void secure_beacon_recv(struct net_buf_simple *buf)
kr_change = bt_mesh_kr_update(sub, BLE_MESH_KEY_REFRESH(flags), new_key);
if (kr_change) {
bt_mesh_net_beacon_update(sub);
bt_mesh_net_secure_beacon_update(sub);
}
if (iv_change) {
@ -424,9 +444,9 @@ static void secure_beacon_recv(struct net_buf_simple *buf)
}
update_stats:
if (bt_mesh_beacon_get() == BLE_MESH_BEACON_ENABLED &&
sub->beacons_cur < 0xff) {
sub->beacons_cur++;
if (bt_mesh_secure_beacon_get() == BLE_MESH_SECURE_BEACON_ENABLED &&
sub->snb_cur < 0xff) {
sub->snb_cur++;
}
}
@ -445,14 +465,28 @@ void bt_mesh_beacon_recv(struct net_buf_simple *buf, int8_t rssi)
switch (type) {
case BEACON_TYPE_UNPROVISIONED:
BT_DBG("Unprovisioned device beacon received");
if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) &&
IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) &&
bt_mesh_is_provisioner_en()) {
bt_mesh_provisioner_unprov_beacon_recv(buf, rssi);
}
if (IS_ENABLED(CONFIG_BLE_MESH_RPR_SRV) &&
bt_mesh_is_provisioned()) {
const bt_mesh_addr_t *addr = bt_mesh_get_unprov_dev_addr();
bt_mesh_unprov_dev_fifo_enqueue(buf->data, addr->val, bt_mesh_get_adv_type());
bt_mesh_rpr_srv_unprov_beacon_recv(buf, bt_mesh_get_adv_type(), addr, rssi);
}
break;
case BEACON_TYPE_SECURE:
secure_beacon_recv(buf);
break;
#if CONFIG_BLE_MESH_PRIVATE_BEACON
case BEACON_TYPE_PRIVATE:
bt_mesh_private_beacon_recv(buf);
break;
#endif
default:
BT_DBG("Unknown beacon type 0x%02x", type);
break;
@ -461,13 +495,31 @@ void bt_mesh_beacon_recv(struct net_buf_simple *buf, int8_t rssi)
void bt_mesh_beacon_init(void)
{
k_delayed_work_init(&beacon_timer, beacon_send);
/* secure beacon init */
if (k_delayed_work_init(&snb_timer, secure_beacon_send_timeout)) {
BT_ERR("Failed to create a snb_timer");
return;
}
#if CONFIG_BLE_MESH_PRB_SRV
/* private beacon init */
if (bt_mesh_private_beacon_timer_init()) {
BT_ERR("Failed to create a mpb_timer");
return;
}
#endif
}
#if CONFIG_BLE_MESH_DEINIT
void bt_mesh_beacon_deinit(void)
{
k_delayed_work_free(&beacon_timer);
/* secure beacon deinit */
k_delayed_work_free(&snb_timer);
#if CONFIG_BLE_MESH_PRB_SRV
/* private beacon deinit */
bt_mesh_private_beacon_timer_free();
#endif
}
#endif /* CONFIG_BLE_MESH_DEINIT */
@ -476,20 +528,32 @@ void bt_mesh_beacon_ivu_initiator(bool enable)
bt_mesh_atomic_set_bit_to(bt_mesh.flags, BLE_MESH_IVU_INITIATOR, enable);
if (enable) {
k_work_submit(&beacon_timer.work);
} else if (bt_mesh_beacon_get() == BLE_MESH_BEACON_DISABLED) {
k_delayed_work_cancel(&beacon_timer);
k_delayed_work_submit(&snb_timer, K_NO_WAIT);
#if CONFIG_BLE_MESH_PRB_SRV
if (bt_mesh_private_beacon_state_get() == BLE_MESH_PRIVATE_BEACON_ENABLED) {
bt_mesh_private_beacon_timer_submit(K_NO_WAIT);
}
#endif
} else {
if (bt_mesh_secure_beacon_get() == BLE_MESH_SECURE_BEACON_DISABLED) {
k_delayed_work_cancel(&snb_timer);
}
#if CONFIG_BLE_MESH_PRB_SRV
if (bt_mesh_private_beacon_state_get() == BLE_MESH_PRIVATE_BEACON_DISABLED) {
bt_mesh_private_beacon_timer_cancel();
}
#endif
}
}
void bt_mesh_beacon_enable(void)
void bt_mesh_secure_beacon_enable(void)
{
size_t subnet_size = 0U;
int i = 0;
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node() &&
!bt_mesh_is_provisioned()) {
k_work_submit(&beacon_timer.work);
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) &&
bt_mesh_is_node() && !bt_mesh_is_provisioned()) {
k_delayed_work_submit(&snb_timer, K_NO_WAIT);
return;
}
@ -502,18 +566,18 @@ void bt_mesh_beacon_enable(void)
continue;
}
sub->beacons_last = 0U;
sub->beacons_cur = 0U;
sub->snb_last = 0U;
sub->snb_cur = 0U;
bt_mesh_net_beacon_update(sub);
bt_mesh_net_secure_beacon_update(sub);
}
k_work_submit(&beacon_timer.work);
k_delayed_work_submit(&snb_timer, K_NO_WAIT);
}
void bt_mesh_beacon_disable(void)
void bt_mesh_secure_beacon_disable(void)
{
if (!bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_IVU_INITIATOR)) {
k_delayed_work_cancel(&beacon_timer);
k_delayed_work_cancel(&snb_timer);
}
}

View File

@ -15,17 +15,28 @@
extern "C" {
#endif
void bt_mesh_beacon_enable(void);
void bt_mesh_beacon_disable(void);
#define BEACON_TYPE_UNPROVISIONED 0x00
#define BEACON_TYPE_SECURE 0x01
#define BEACON_TYPE_PRIVATE 0x02
#define NET_IDX_SET(_val) ((void *)((uint32_t)(_val)))
#define NET_IDX_GET(_ptr) ((uint32_t)(_ptr))
/* If the interval has passed or is within 5 seconds from now send a beacon */
#define BEACON_THRESHOLD(last) (K_SECONDS(10 * ((last) + 1)) - K_SECONDS(5))
void bt_mesh_secure_beacon_enable(void);
void bt_mesh_secure_beacon_disable(void);
void bt_mesh_beacon_ivu_initiator(bool enable);
void bt_mesh_beacon_recv(struct net_buf_simple *buf, int8_t rssi);
void bt_mesh_beacon_create(struct bt_mesh_subnet *sub,
void bt_mesh_secure_beacon_create(struct bt_mesh_subnet *sub,
struct net_buf_simple *buf);
void bt_mesh_beacon_init(void);
void bt_mesh_beacon_deinit(void);
#ifdef __cplusplus

View File

@ -18,7 +18,9 @@
#include "osi/future.h"
#include "device/controller.h"
#if CONFIG_MBEDTLS_HARDWARE_AES
#include "mbedtls/aes.h"
#endif
#include <tinycrypt/aes.h>
#include <tinycrypt/constants.h>
@ -27,6 +29,9 @@
#include "mesh/adapter.h"
#include "mesh/common.h"
#include "prov_pvnr.h"
#include "net.h"
#include "mesh_v1.1/utils.h"
struct bt_mesh_dev bt_mesh_dev;
@ -48,14 +53,15 @@ struct bt_mesh_dev bt_mesh_dev;
/* P-256 Variables */
static uint8_t bt_mesh_public_key[64];
static BT_OCTET32 bt_mesh_private_key;
static uint8_t bt_mesh_private_key[32];
/* Scan related functions */
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 (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_SERVER
CONFIG_BLE_MESH_GATT_PROXY_SERVER || \
(CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT)
/* Using UUID with a fixed pattern 0x96 for BLE Mesh GATT Proxy Server */
#define BLE_MESH_GATTS_APP_UUID_BYTE 0x96
/* the gatt database list to save the attribute table */
@ -65,7 +71,7 @@ static sys_slist_t bt_mesh_gatts_db;
static struct bt_mesh_conn bt_mesh_gatts_conn[BLE_MESH_MAX_CONN];
static struct bt_mesh_conn_cb *bt_mesh_gatts_conn_cb;
static tBTA_GATTS_IF bt_mesh_gatts_if;
static BD_ADDR bt_mesh_gatts_addr;
static uint8_t bt_mesh_gatts_addr[BLE_MESH_ADDR_LEN];
static uint16_t svc_handle, char_handle;
static future_t *future_mesh;
@ -74,7 +80,8 @@ static struct bt_mesh_gatt_attr *bt_mesh_gatts_find_attr_by_handle(uint16_t hand
#endif
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \
(CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT)
/* Using UUID with a fixed pattern 0x97 for BLE Mesh GATT Proxy Client */
#define BLE_MESH_GATTC_APP_UUID_BYTE 0x97
static struct gattc_prov_info {
@ -261,7 +268,7 @@ static bool valid_scan_param(const struct bt_mesh_scan_param *param)
static int start_le_scan(uint8_t scan_type, uint16_t interval, uint16_t window,
uint8_t filter_dup, uint8_t scan_fil_policy)
{
UINT8 addr_type_own = BLE_MESH_ADDR_PUBLIC; /* Currently only support Public Address */
uint8_t addr_type_own = BLE_MESH_ADDR_PUBLIC; /* Currently only support Public Address */
tGATT_IF client_if = 0xFF; /* Default GATT interface id */
BLE_MESH_BTM_CHECK_STATUS(
@ -297,7 +304,7 @@ static void bt_mesh_scan_result_callback(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARC
net_buf_simple_init_with_data(&buf, p_data->inq_res.p_eir, p_data->inq_res.adv_data_len);
if (bt_mesh_scan_dev_found_cb) {
bt_mesh_scan_dev_found_cb(&addr, p_data->inq_res.rssi, p_data->inq_res.ble_evt_type, &buf);
bt_mesh_scan_dev_found_cb(&addr, p_data->inq_res.rssi, p_data->inq_res.ble_evt_type, &buf, p_data->inq_res.scan_rsp_len);
}
} else if (event == BTA_DM_INQ_CMPL_EVT) {
BT_INFO("Scan completed, number of scan response %d", p_data->inq_cmpl.num_resps);
@ -360,7 +367,13 @@ int bt_le_adv_start(const struct bt_mesh_adv_param *param,
} else {
adv_type = BLE_MESH_ADV_NONCONN_IND;
}
addr_type_own = BLE_MESH_ADDR_PUBLIC; /* Currently only support Public Address */
#if CONFIG_BLE_MESH_PRB_SRV
addr_type_own = bt_mesh_private_beacon_update_addr_type(ad);
#else
addr_type_own = BLE_MESH_ADDR_PUBLIC;
#endif
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;
@ -740,7 +753,7 @@ struct gatts_incl {
uint16_t start_handle;
uint16_t end_handle;
uint16_t uuid16;
} __packed;
} __attribute__((packed));
ssize_t bt_mesh_gatts_attr_read_included(struct bt_mesh_conn *conn,
const struct bt_mesh_gatt_attr *attr,
@ -790,7 +803,7 @@ struct gatts_chrc {
uint16_t uuid16;
uint8_t uuid[16];
};
} __packed;
} __attribute__((packed));
ssize_t bt_mesh_gatts_attr_read_chrc(struct bt_mesh_conn *conn,
const struct bt_mesh_gatt_attr *attr,
@ -845,8 +858,6 @@ static void bta_uuid_to_bt_mesh_uuid(tBT_UUID *bta_uuid, const struct bt_mesh_uu
} else {
BT_ERR("Invalid mesh uuid type %d", uuid->type);
}
return;
}
static int gatts_register(struct bt_mesh_gatt_service *svc)
@ -1099,7 +1110,8 @@ int bt_mesh_gatts_set_local_device_name(const char *name)
#endif /* (CONFIG_BLE_MESH_NODE && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_SERVER */
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \
(CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT)
void bt_mesh_gattc_conn_cb_register(struct bt_mesh_prov_conn_cb *cb)
{
bt_mesh_gattc_conn_cb = cb;
@ -1281,7 +1293,6 @@ void bt_mesh_gattc_disconnect(struct bt_mesh_conn *conn)
}
BT_ERR("Conn %p not found", conn);
return;
}
/** Mesh Provisioning Service: 0x1827
@ -1388,7 +1399,8 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
BTA_GATTC_GetDBSizeByType(p_data->search_cmpl.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) {
if (count != 3 && count != 2) {
BT_ERR("Invalid characteristic num(%d) within Mesh Provisioning/Proxy Service", count);
bt_mesh_gattc_disconnect(conn);
return;
}
@ -1572,7 +1584,8 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
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);
p_data->notify.value,
p_data->notify.len);
if (len < 0) {
BT_ERR("prov_notify failed");
bt_mesh_gattc_disconnect(conn);
@ -1582,7 +1595,8 @@ static void bt_mesh_bta_gattc_cb(tBTA_GATTC_EVT event, tBTA_GATTC *p_data)
} 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);
p_data->notify.value,
p_data->notify.len);
if (len < 0) {
BT_ERR("proxy_notify failed");
bt_mesh_gattc_disconnect(conn);
@ -1728,7 +1742,8 @@ void bt_mesh_gatt_init(void)
#endif
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \
(CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT)
tBT_UUID gattc_app_uuid = {LEN_UUID_128, {0}};
for (int i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
bt_mesh_gattc_info[i].conn.handle = 0xFFFF;
@ -1753,7 +1768,8 @@ void bt_mesh_gatt_deinit(void)
#endif
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \
(CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT)
BTA_GATTC_AppDeregister(bt_mesh_gattc_if);
bt_mesh_gattc_if = 0U;
for (int i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
@ -1774,8 +1790,6 @@ void bt_mesh_gatt_deinit(void)
void bt_mesh_adapt_init(void)
{
BT_DBG("%s", __func__);
/* initialization of P-256 parameters */
p_256_init_curve(KEY_LENGTH_DWORDS_P256);
@ -1795,7 +1809,7 @@ void bt_mesh_set_private_key(const uint8_t pri_key[32])
const uint8_t *bt_mesh_pub_key_get(void)
{
BT_OCTET32 private_key = {0};
uint8_t private_key[32] = {0};
Point public_key = {0};
if (bt_mesh_atomic_test_bit(bt_mesh_dev.flags, BLE_MESH_DEV_HAS_PUB_KEY)) {
@ -1842,17 +1856,17 @@ bool bt_mesh_check_public_key(const uint8_t key[64])
return ECC_CheckPointIsInElliCur_P256((Point *)&check);
}
int bt_mesh_dh_key_gen(const uint8_t remote_pk[64], bt_mesh_dh_key_cb_t cb, const uint8_t idx)
int bt_mesh_dh_key_gen(const uint8_t remote_pub_key[64], uint8_t dhkey[32])
{
BT_OCTET32 private_key = {0};
uint8_t private_key[32] = {0};
Point peer_pub_key = {0};
Point new_pub_key = {0};
BT_DBG("private key = %s", bt_hex(bt_mesh_private_key, BT_OCTET32_LEN));
memcpy(private_key, bt_mesh_private_key, BT_OCTET32_LEN);
memcpy(peer_pub_key.x, remote_pk, BT_OCTET32_LEN);
memcpy(peer_pub_key.y, &remote_pk[BT_OCTET32_LEN], BT_OCTET32_LEN);
memcpy(peer_pub_key.x, remote_pub_key, BT_OCTET32_LEN);
memcpy(peer_pub_key.y, &remote_pub_key[BT_OCTET32_LEN], BT_OCTET32_LEN);
BT_DBG("remote public key x = %s", bt_hex(peer_pub_key.x, BT_OCTET32_LEN));
BT_DBG("remote public key y = %s", bt_hex(peer_pub_key.y, BT_OCTET32_LEN));
@ -1862,9 +1876,7 @@ int bt_mesh_dh_key_gen(const uint8_t remote_pk[64], bt_mesh_dh_key_cb_t cb, cons
BT_DBG("new public key x = %s", bt_hex(new_pub_key.x, 32));
BT_DBG("new public key y = %s", bt_hex(new_pub_key.y, 32));
if (cb != NULL) {
cb((const uint8_t *)new_pub_key.x, idx);
}
memcpy(dhkey, new_pub_key.x, 32);
return 0;
}
@ -1959,10 +1971,10 @@ int bt_mesh_encrypt_be(const uint8_t key[16], const uint8_t plaintext[16],
return 0;
}
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
#if CONFIG_BLE_MESH_USE_DUPLICATE_SCAN
int bt_mesh_update_exceptional_list(uint8_t sub_code, uint32_t type, void *info)
{
BD_ADDR value = {0};
uint8_t value[BLE_MESH_ADDR_LEN] = {0};
if ((sub_code > BLE_MESH_EXCEP_LIST_SUB_CODE_CLEAN) ||
(sub_code < BLE_MESH_EXCEP_LIST_SUB_CODE_CLEAN &&

View File

@ -24,7 +24,7 @@
static const bt_mesh_client_op_pair_t cfg_op_pair[] = {
{ OP_BEACON_GET, OP_BEACON_STATUS },
{ OP_BEACON_SET, OP_BEACON_STATUS },
{ OP_DEV_COMP_DATA_GET, OP_DEV_COMP_DATA_STATUS },
{ OP_COMP_DATA_GET, OP_COMP_DATA_STATUS },
{ OP_DEFAULT_TTL_GET, OP_DEFAULT_TTL_STATUS },
{ OP_DEFAULT_TTL_SET, OP_DEFAULT_TTL_STATUS },
{ OP_GATT_PROXY_GET, OP_GATT_PROXY_STATUS },
@ -73,40 +73,17 @@ static const bt_mesh_client_op_pair_t cfg_op_pair[] = {
static bt_mesh_mutex_t cfg_client_lock;
static inline void bt_mesh_cfg_client_mutex_new(void)
{
if (!cfg_client_lock.mutex) {
bt_mesh_mutex_create(&cfg_client_lock);
}
}
#if CONFIG_BLE_MESH_DEINIT
static inline void bt_mesh_cfg_client_mutex_free(void)
{
bt_mesh_mutex_free(&cfg_client_lock);
}
#endif /* CONFIG_BLE_MESH_DEINIT */
static inline void bt_mesh_cfg_client_lock(void)
{
bt_mesh_mutex_lock(&cfg_client_lock);
}
static inline void bt_mesh_cfg_client_unlock(void)
{
bt_mesh_mutex_unlock(&cfg_client_lock);
}
static void timeout_handler(struct k_work *work)
{
struct k_delayed_work *timer = NULL;
bt_mesh_client_node_t *node = NULL;
struct bt_mesh_model *model = NULL;
struct bt_mesh_msg_ctx ctx = {0};
uint32_t opcode = 0U;
BT_WARN("Receive configuration status message timeout");
bt_mesh_cfg_client_lock();
bt_mesh_mutex_lock(&cfg_client_lock);
timer = CONTAINER_OF(work, struct k_delayed_work, work);
@ -115,15 +92,14 @@ static void timeout_handler(struct k_work *work)
if (node) {
memcpy(&ctx, &node->ctx, sizeof(ctx));
opcode = node->opcode;
model = node->model;
bt_mesh_client_free_node(node);
bt_mesh_config_client_cb_evt_to_btc(
opcode, BTC_BLE_MESH_EVT_CONFIG_CLIENT_TIMEOUT, ctx.model, &ctx, NULL, 0);
opcode, BTC_BLE_MESH_EVT_CONFIG_CLIENT_TIMEOUT, model, &ctx, NULL, 0);
}
}
bt_mesh_cfg_client_unlock();
return;
bt_mesh_mutex_unlock(&cfg_client_lock);
}
static void cfg_client_recv_status(struct bt_mesh_model *model,
@ -143,7 +119,7 @@ static void cfg_client_recv_status(struct bt_mesh_model *model,
buf.data = (uint8_t *)status;
buf.len = (uint16_t)len;
bt_mesh_cfg_client_lock();
bt_mesh_mutex_lock(&cfg_client_lock);
node = bt_mesh_is_client_recv_publish_msg(model, ctx, &buf, true);
if (!node) {
@ -151,7 +127,7 @@ static void cfg_client_recv_status(struct bt_mesh_model *model,
} else {
switch (node->opcode) {
case OP_BEACON_GET:
case OP_DEV_COMP_DATA_GET:
case OP_COMP_DATA_GET:
case OP_DEFAULT_TTL_GET:
case OP_GATT_PROXY_GET:
case OP_RELAY_GET:
@ -213,10 +189,10 @@ static void cfg_client_recv_status(struct bt_mesh_model *model,
}
}
bt_mesh_cfg_client_unlock();
bt_mesh_mutex_unlock(&cfg_client_lock);
switch (ctx->recv_op) {
case OP_DEV_COMP_DATA_STATUS: {
case OP_COMP_DATA_STATUS: {
struct bt_mesh_cfg_comp_data_status *val = status;
bt_mesh_free_buf(val->comp_data);
break;
@ -649,7 +625,7 @@ static void net_trans_status(struct bt_mesh_model *model,
}
const struct bt_mesh_model_op bt_mesh_cfg_cli_op[] = {
{ OP_DEV_COMP_DATA_STATUS, 15, comp_data_status },
{ OP_COMP_DATA_STATUS, 15, comp_data_status },
{ OP_BEACON_STATUS, 1, beacon_status },
{ OP_DEFAULT_TTL_STATUS, 1, ttl_status },
{ OP_FRIEND_STATUS, 1, friend_status },
@ -707,7 +683,7 @@ static int send_msg_with_le16(bt_mesh_client_common_param_t *param, uint32_t op,
int bt_mesh_cfg_comp_data_get(bt_mesh_client_common_param_t *param, uint8_t page)
{
return send_msg_with_u8(param, OP_DEV_COMP_DATA_GET, page);
return send_msg_with_u8(param, OP_COMP_DATA_GET, page);
}
int bt_mesh_cfg_beacon_get(bt_mesh_client_common_param_t *param)
@ -1264,10 +1240,14 @@ static int cfg_cli_init(struct bt_mesh_model *model)
return -EINVAL;
}
if (!client->internal_data) {
if (client->internal_data) {
BT_WARN("%s, Already", __func__);
return -EALREADY;
}
internal = bt_mesh_calloc(sizeof(config_internal_data_t));
if (!internal) {
BT_ERR("Allocate memory for Configuration Client internal data fail");
BT_ERR("%s, Out of memory", __func__);
return -ENOMEM;
}
@ -1277,14 +1257,11 @@ static int cfg_cli_init(struct bt_mesh_model *model)
client->op_pair_size = ARRAY_SIZE(cfg_op_pair);
client->op_pair = cfg_op_pair;
client->internal_data = internal;
} else {
bt_mesh_client_clear_list(client->internal_data);
}
/* Configuration Model security is device-key based */
model->keys[0] = BLE_MESH_KEY_DEV;
bt_mesh_cfg_client_mutex_new();
bt_mesh_mutex_create(&cfg_client_lock);
return 0;
}
@ -1319,7 +1296,7 @@ static int cfg_cli_deinit(struct bt_mesh_model *model)
client->internal_data = NULL;
}
bt_mesh_cfg_client_mutex_free();
bt_mesh_mutex_free(&cfg_client_lock);
return 0;
}

View File

@ -18,6 +18,7 @@
#include "lpn.h"
#include "transport.h"
#include "crypto.h"
#include "net.h"
#include "access.h"
#include "beacon.h"
#include "foundation.h"
@ -28,92 +29,15 @@
#include "mesh/main.h"
#include "mesh/common.h"
#define DEFAULT_TTL 7
#include "mesh_v1.1/utils.h"
/* 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
* store device composition data.
*/
#define COMP_DATA_MAX_LEN 379
#define DEFAULT_TTL 7
static struct bt_mesh_cfg_srv *conf;
static struct label labels[CONFIG_BLE_MESH_LABEL_COUNT];
static int comp_add_elem(struct net_buf_simple *buf, struct bt_mesh_elem *elem,
bool primary)
{
struct bt_mesh_model *mod = NULL;
int i;
if (net_buf_simple_tailroom(buf) <
4 + (elem->model_count * 2U) + (elem->vnd_model_count * 4U)) {
BT_ERR("Too large device composition");
return -E2BIG;
}
net_buf_simple_add_le16(buf, elem->loc);
net_buf_simple_add_u8(buf, elem->model_count);
net_buf_simple_add_u8(buf, elem->vnd_model_count);
for (i = 0; i < elem->model_count; i++) {
mod = &elem->models[i];
net_buf_simple_add_le16(buf, mod->id);
}
for (i = 0; i < elem->vnd_model_count; i++) {
mod = &elem->vnd_models[i];
net_buf_simple_add_le16(buf, mod->vnd.company);
net_buf_simple_add_le16(buf, mod->vnd.id);
}
return 0;
}
static int comp_get_page_0(struct net_buf_simple *buf)
{
const struct bt_mesh_comp *comp = NULL;
uint16_t feat = 0U;
int i;
comp = bt_mesh_comp_get();
if (IS_ENABLED(CONFIG_BLE_MESH_RELAY)) {
feat |= BLE_MESH_FEAT_RELAY;
}
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) {
feat |= BLE_MESH_FEAT_PROXY;
}
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
feat |= BLE_MESH_FEAT_FRIEND;
}
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_BLE_MESH_CRPL);
net_buf_simple_add_le16(buf, feat);
for (i = 0; i < comp->elem_count; i++) {
int err;
err = comp_add_elem(buf, &comp->elem[i], i == 0);
if (err) {
return err;
}
}
return 0;
}
static void dev_comp_data_get(struct bt_mesh_model *model,
static void comp_data_get(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
@ -124,23 +48,59 @@ static void dev_comp_data_get(struct bt_mesh_model *model,
ctx->net_idx, ctx->app_idx, ctx->addr, buf->len,
bt_hex(buf->data, buf->len));
page = net_buf_simple_pull_u8(buf);
if (page != 0U) {
BT_WARN("Composition page %u not available", page);
page = 0U;
}
/* TODO:
*
* When an element receives a Config Composition Data Get message with
* the Page field of the message containing a value of a Composition
* Data Page that the node contains, it shall respond with a Config
* Composition Data Status message with the Page field set to the page
* number of the Composition Data and the Data field set to the value
* of the largest portion of the Composition Data Page that fits in the
* Data field. If an element is reported in the Config Composition Data
* Status message, the complete list of models supported by the element
* shall be included in the elements description. If the complete list
* of models does not fit in the Data field, the element shall not be
* reported.
*
* When an element receives a Config Composition Data Get message with
* the Page field of the message containing a reserved page number or a
* page number the node does not support, it shall respond with a Config
* Composition Data Status message with the Page field set to the largest
* page number of the Composition Data that the node supports and that is
* less than the Page field value of the received Config Composition Data
* Get message and with the Data field set to the value of the largest
* portion of the Composition Data Page for that page number that fits in
* the Data field. If an element is reported in a Config Composition Data
* Status message, the complete list of models supported by the element
* shall be included in the elements description. If the complete list of
* models does not fit in the Data field, the element shall not be reported.
*/
sdu = bt_mesh_alloc_buf(MIN(BLE_MESH_TX_SDU_MAX, COMP_DATA_MAX_LEN));
page = net_buf_simple_pull_u8(buf);
/* Check if the page exists, and if not, get the largest one
* which is smaller than this page.
*/
page = bt_mesh_comp_page_check(page, false);
sdu = bt_mesh_alloc_buf(MIN(BLE_MESH_TX_SDU_MAX, BLE_MESH_MAX_PDU_LEN_WITH_SMIC));
if (!sdu) {
BT_ERR("%s, Out of memory", __func__);
return;
}
bt_mesh_model_msg_init(sdu, OP_DEV_COMP_DATA_STATUS);
bt_mesh_model_msg_init(sdu, OP_COMP_DATA_STATUS);
net_buf_simple_add_u8(sdu, page);
if (comp_get_page_0(sdu) < 0) {
BT_ERR("Unable to get composition page 0");
/* Mesh v1.1 updates:
* If an element is reported in the Config Composition Data
* Status message, the complete list of models supported by
* the element shall be included in the elements description.
* If the complete list of models does not fit in the Data
* field, the element shall not be reported.
*/
if (bt_mesh_get_comp_data(sdu, page, 0, true)) {
BT_ERR("Unable to get composition page 0x%02x", page);
bt_mesh_free_buf(sdu);
return;
}
@ -150,15 +110,14 @@ static void dev_comp_data_get(struct bt_mesh_model *model,
}
bt_mesh_free_buf(sdu);
return;
}
static struct bt_mesh_model *get_model(struct bt_mesh_elem *elem,
struct net_buf_simple *buf, bool *vnd)
{
if (buf->len < 4) {
uint16_t id = 0U;
uint16_t company = 0U, id = 0U;
if (buf->len < 4) {
id = net_buf_simple_pull_le16(buf);
BT_DBG("ID 0x%04x addr 0x%04x", id, elem->addr);
@ -166,8 +125,7 @@ static struct bt_mesh_model *get_model(struct bt_mesh_elem *elem,
*vnd = false;
return bt_mesh_model_find(elem, id);
} else {
uint16_t company = 0U, id = 0U;
}
company = net_buf_simple_pull_le16(buf);
id = net_buf_simple_pull_le16(buf);
@ -178,23 +136,6 @@ static struct bt_mesh_model *get_model(struct bt_mesh_elem *elem,
*vnd = true;
return bt_mesh_model_find_vnd(elem, company, id);
}
}
static bool app_key_is_valid(uint16_t app_idx)
{
int i;
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 != BLE_MESH_KEY_UNUSED &&
key->app_idx == app_idx) {
return true;
}
}
return false;
}
static bool mod_pub_app_key_bound(struct bt_mesh_model *model,
@ -208,7 +149,7 @@ static bool mod_pub_app_key_bound(struct bt_mesh_model *model,
}
}
BT_ERR("Appkey(0x%02x) not bound to this model.", app_idx);
BT_ERR("AppKey(0x%02x) not bound to this model", app_idx);
return false;
}
@ -255,7 +196,7 @@ static uint8_t _mod_pub_set(struct bt_mesh_model *model, uint16_t pub_addr,
/* For case MESH/NODE/CFG/MP/BI-03-C, need to check if appkey
* is bound to model identified by the ModelIdentifier.
*/
if (!bt_mesh_app_key_find(app_idx) ||
if (!bt_mesh_app_key_get(app_idx) ||
!mod_pub_app_key_bound(model, app_idx)) {
return STATUS_INVALID_APPKEY;
}
@ -293,7 +234,7 @@ static uint8_t mod_bind(struct bt_mesh_model *model, uint16_t key_idx)
BT_DBG("model %p key_idx 0x%03x", model, key_idx);
if (!app_key_is_valid(key_idx)) {
if (!bt_mesh_app_key_get(key_idx)) {
return STATUS_INVALID_APPKEY;
}
@ -325,7 +266,7 @@ static uint8_t mod_unbind(struct bt_mesh_model *model, uint16_t key_idx, bool st
BT_DBG("model %p key_idx 0x%03x store %u", model, key_idx, store);
if (!app_key_is_valid(key_idx)) {
if (!bt_mesh_app_key_get(key_idx)) {
return STATUS_INVALID_APPKEY;
}
@ -379,7 +320,7 @@ static uint8_t app_key_set(uint16_t net_idx, uint16_t app_idx, const uint8_t val
return STATUS_INVALID_NETKEY;
}
key = bt_mesh_app_key_find(app_idx);
key = bt_mesh_app_key_get(app_idx);
if (update) {
if (!key) {
return STATUS_INVALID_APPKEY;
@ -403,9 +344,9 @@ static uint8_t app_key_set(uint16_t net_idx, uint16_t app_idx, const uint8_t val
if (key->updated) {
if (memcmp(keys->val, val, 16)) {
return STATUS_CANNOT_UPDATE;
} else {
return STATUS_SUCCESS;
}
return STATUS_SUCCESS;
}
key->updated = true;
@ -418,9 +359,9 @@ static uint8_t app_key_set(uint16_t net_idx, uint16_t app_idx, const uint8_t val
if (key->net_idx == net_idx) {
return STATUS_IDX_ALREADY_STORED;
} else {
return STATUS_INVALID_NETKEY;
}
return STATUS_INVALID_NETKEY;
}
key = bt_mesh_app_key_alloc(app_idx);
@ -569,7 +510,7 @@ static void app_key_del(struct bt_mesh_model *model,
goto send_status;
}
key = bt_mesh_app_key_find(key_app_idx);
key = bt_mesh_app_key_get(key_app_idx);
if (!key) {
/* Treat as success since the client might have missed a
* previous response and is resending the request.
@ -679,7 +620,7 @@ static void beacon_get(struct bt_mesh_model *model,
bt_hex(buf->data, buf->len));
bt_mesh_model_msg_init(&msg, OP_BEACON_STATUS);
net_buf_simple_add_u8(&msg, bt_mesh_beacon_get());
net_buf_simple_add_u8(&msg, bt_mesh_secure_beacon_get());
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
BT_ERR("Unable to send Config Beacon Status");
@ -708,9 +649,9 @@ static void beacon_set(struct bt_mesh_model *model,
}
if (cfg->beacon) {
bt_mesh_beacon_enable();
bt_mesh_secure_beacon_enable();
} else {
bt_mesh_beacon_disable();
bt_mesh_secure_beacon_disable();
}
}
} else {
@ -719,7 +660,7 @@ static void beacon_set(struct bt_mesh_model *model,
}
bt_mesh_model_msg_init(&msg, OP_BEACON_STATUS);
net_buf_simple_add_u8(&msg, bt_mesh_beacon_get());
net_buf_simple_add_u8(&msg, bt_mesh_secure_beacon_get());
if (bt_mesh_model_send(model, ctx, &msg, NULL, NULL)) {
BT_ERR("Unable to send Config Beacon Status");
@ -835,6 +776,23 @@ static void gatt_proxy_set(struct bt_mesh_model *model,
cfg->gatt_proxy = buf->data[0];
#if CONFIG_BLE_MESH_PRB_SRV
/* If the value of the GATT Proxy state of the node is 0x01 (see Table 4.21),
* then the value of the Private GATT Proxy state shall be Disable (0x00).
*/
if (buf->data[0] == BLE_MESH_GATT_PROXY_ENABLED) {
bt_mesh_disable_private_gatt_proxy();
}
#endif
#if CONFIG_BLE_MESH_DF_SRV
/* If the value of the GATT Proxy state of the node is 0x00,
* then the value of the directed proxy state shall be 0x00,
* directed proxy use directed default shall be 0x02.
*/
bt_mesh_disable_directed_proxy_state(ctx->net_idx);
#endif
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
bt_mesh_store_cfg();
}
@ -1464,7 +1422,8 @@ static void mod_sub_add(struct bt_mesh_model *model,
goto send_status;
}
BT_BQB(BLE_MESH_BQB_TEST_LOG_LEVEL_PRIMARY_ID_NODE | BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_TNPT,
BT_BQB(BLE_MESH_BQB_TEST_LOG_LEVEL_PRIMARY_ID_NODE | \
BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_TNPT,
"SubGroupAddr: 0x%x", sub_addr);
for (i = 0; i < ARRAY_SIZE(mod->groups); i++) {
@ -1492,6 +1451,10 @@ send_status:
send_mod_sub_status(model, ctx, status, elem_addr, sub_addr,
mod_id, vnd);
#if CONFIG_BLE_MESH_DF_SRV
bt_mesh_directed_forwarding_node_solicitation(mod, bt_mesh_subnet_get(ctx->net_idx));
#endif
if (status == STATUS_SUCCESS) {
bt_mesh_cfg_server_state_change_t change = {0};
change.cfg_mod_sub_add.elem_addr = elem_addr;
@ -1868,7 +1831,8 @@ static void mod_sub_va_add(struct bt_mesh_model *model,
goto send_status;
}
BT_BQB(BLE_MESH_BQB_TEST_LOG_LEVEL_PRIMARY_ID_NODE | BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_TNPT,
BT_BQB(BLE_MESH_BQB_TEST_LOG_LEVEL_PRIMARY_ID_NODE | \
BLE_MESH_BQB_TEST_LOG_LEVEL_SUB_ID_TNPT,
"SubVirtualAddr: 0x%x", sub_addr);
for (i = 0; i < ARRAY_SIZE(mod->groups); i++) {
@ -2230,11 +2194,24 @@ 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);
bt_mesh_net_secure_beacon_update(sub);
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) {
sub->node_id = BLE_MESH_NODE_IDENTITY_STOPPED;
bt_mesh_proxy_server_beacon_send(sub);
#if CONFIG_BLE_MESH_DF_SRV && CONFIG_BLE_MESH_SUPPORT_DIRECTED_PROXY
/* When the Directed Proxy Server is added to a new subnet, and the
* Proxy_Client_Type parameter for the connection is either Unset or
* Directed_Proxy_Client, then the Directed Proxy Server shall send a
* DIRECTED_PROXY_CAPABILITIES_STATUS message for that subnet to the
* Proxy Client.
*/
if (sub->directed_proxy != BLE_MESH_DIRECTED_PROXY_NOT_SUPPORTED) {
bt_mesh_directed_proxy_server_directed_proxy_caps_send(sub, false);
}
#endif
bt_mesh_adv_update();
} else {
sub->node_id = BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED;
@ -2242,6 +2219,12 @@ static void net_key_add(struct bt_mesh_model *model,
send_net_key_status(model, ctx, idx, STATUS_SUCCESS);
#if CONFIG_BLE_MESH_DF_SRV
if (bt_mesh_directed_forwarding_sub_init(sub)) {
BT_ERR("Failed to init subnet for directed forward");
}
#endif
bt_mesh_cfg_server_state_change_t change = {0};
change.cfg_netkey_add.net_idx = sub->net_idx;
memcpy(change.cfg_netkey_add.net_key, sub->keys[0].net, 16);
@ -2313,7 +2296,7 @@ static void net_key_update(struct bt_mesh_model *model,
bt_mesh_store_subnet(sub);
}
bt_mesh_net_beacon_update(sub);
bt_mesh_net_secure_beacon_update(sub);
send_net_key_status(model, ctx, idx, STATUS_SUCCESS);
@ -2326,8 +2309,6 @@ static void net_key_update(struct bt_mesh_model *model,
static void hb_pub_disable(struct bt_mesh_cfg_srv *cfg)
{
BT_DBG("%s", __func__);
cfg->hb_pub.dst = BLE_MESH_ADDR_UNASSIGNED;
cfg->hb_pub.count = 0U;
cfg->hb_pub.ttl = 0U;
@ -2369,9 +2350,44 @@ static void net_key_del(struct bt_mesh_model *model,
goto send_status;
}
#if CONFIG_BLE_MESH_DF_SRV && CONFIG_BLE_MESH_SUPPORT_DIRECTED_PROXY
/* When the Directed Proxy Server is deleted from a subnet, and the
* Proxy_Client_Type parameter for the connection is either Unset or
* Directed_Proxy_Client, then the Directed Proxy Server shall set
* the Use_Directed parameter of the connection for the deleted subnet
* to 0x00, shall set the Proxy_Client_Address_Range parameter of the
* connection for the deleted subnet to the Unassigned value, and shall
* send a DIRECTED_PROXY_CAPABILITIES_STATUS message for the deleted
* subnet to the Proxy Client.
*/
if (sub->directed_proxy != BLE_MESH_DIRECTED_PROXY_NOT_SUPPORTED) {
/* Directed Proxy Caps Status must be sent before the subnet is deleted */
bt_mesh_directed_proxy_server_directed_proxy_caps_send(sub, true);
}
#if CONFIG_BLE_MESH_SETTINGS
bt_mesh_clear_directed_forwarding_table_data(del_idx);
#endif
#endif
bt_mesh_subnet_del(sub, true);
status = STATUS_SUCCESS;
#if CONFIG_BLE_MESH_BRC_SRV
/**
* TODO: When a NetKey is deleted from the NetKey List state,
* and subnet bridge functionality is supported, then all the
* Bridging Table state entries with one of the values of the
* NetKeyIndex1 and NetKeyIndex2 fields that matches the NetKey
* Index of the deleted NetKey are removed.
*/
bt_mesh_delete_netkey_in_bridge_table(del_idx);
#endif /* CONFIG_BLE_MESH_BRC_SRV */
#if CONFIG_BLE_MESH_RPR_SRV
bt_mesh_rpr_srv_netkey_del(del_idx);
#endif
send_status:
send_net_key_status(model, ctx, del_idx, status);
@ -2490,17 +2506,24 @@ static void node_identity_set(struct bt_mesh_model *model,
net_buf_simple_add_le16(&msg, idx);
net_buf_simple_add_u8(&msg, node_id);
} else {
net_buf_simple_add_u8(&msg, STATUS_SUCCESS);
net_buf_simple_add_le16(&msg, idx);
if (IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) {
if (node_id) {
if (node_id == BLE_MESH_NODE_IDENTITY_RUNNING) {
#if CONFIG_BLE_MESH_PRB_SRV
/* If the value of the Node Identity state of the node for
* any subnet is 0x01, then the value of the Private Node
* Identity state shall be Disable (0x00).
*/
disable_all_private_node_identity();
#endif
bt_mesh_proxy_server_identity_start(sub);
} else {
bt_mesh_proxy_server_identity_stop(sub);
}
bt_mesh_adv_update();
}
net_buf_simple_add_u8(&msg, STATUS_SUCCESS);
net_buf_simple_add_le16(&msg, idx);
net_buf_simple_add_u8(&msg, sub->node_id);
}
@ -2570,6 +2593,7 @@ static void mod_app_bind(struct bt_mesh_model *model,
status = mod_bind(mod, key_app_idx);
BT_INFO("bind app key %#x on mode %#x", key_app_idx, mod->id);
send_status:
BT_DBG("status 0x%02x", status);
create_mod_app_status(&msg, mod, vnd, elem_addr, key_app_idx, status,
@ -2805,6 +2829,13 @@ static void friend_set(struct bt_mesh_model *model,
if (cfg->frnd == BLE_MESH_FRIEND_DISABLED) {
bt_mesh_friend_clear_net_idx(BLE_MESH_KEY_ANY);
#if CONFIG_BLE_MESH_DF_SRV && CONFIG_BLE_MESH_FRIEND
/* If the value of the friend state of the node is 0x00,
* then the value of the directed friend state shall be 0x00.
*/
bt_mesh_disable_directed_friend_state(ctx->net_idx);
#endif
}
}
@ -2941,7 +2972,7 @@ static void krp_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx,
bt_mesh_store_subnet(sub);
}
bt_mesh_net_beacon_update(sub);
bt_mesh_net_secure_beacon_update(sub);
} else if ((sub->kr_phase == BLE_MESH_KR_PHASE_1 ||
sub->kr_phase == BLE_MESH_KR_PHASE_2) &&
phase == BLE_MESH_KR_PHASE_3) {
@ -2951,10 +2982,10 @@ static void krp_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx,
if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER) ||
IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
friend_cred_refresh(ctx->net_idx);
friend_cred_refresh(sub->net_idx);
}
bt_mesh_net_beacon_update(sub);
bt_mesh_net_secure_beacon_update(sub);
}
send_krp_status(model, ctx, idx, sub->kr_phase, STATUS_SUCCESS);
@ -2968,35 +2999,39 @@ static void krp_set(struct bt_mesh_model *model, struct bt_mesh_msg_ctx *ctx,
static uint8_t hb_log(uint16_t val)
{
if (!val) {
switch (val) {
case 0x0000:
return 0x00;
} else if (val == 0xffff) {
return 0xff;
} else {
case 0xFFFF:
return 0xFF;
default:
return 32 - __builtin_clz(val);
}
}
static uint8_t hb_pub_count_log(uint16_t val)
{
if (!val) {
switch (val) {
case 0x0000:
return 0x00;
} else if (val == 0x01) {
case 0x0001:
return 0x01;
} else if (val == 0xffff) {
return 0xff;
} else {
case 0xFFFF:
return 0xFF;
default:
return 32 - __builtin_clz(val - 1) + 1;
}
}
static uint16_t hb_pwr2(uint8_t val, uint8_t sub)
{
if (!val) {
switch (val) {
case 0x00:
return 0x0000;
} else if (val == 0xff || val == 0x11) {
return 0xffff;
} else {
case 0x11:
case 0xFF:
return 0xFFFF;
default:
return (1 << (val - sub));
}
}
@ -3008,7 +3043,7 @@ struct hb_pub_param {
uint8_t ttl;
uint16_t feat;
uint16_t net_idx;
} __packed;
} __attribute__((packed));
static void hb_pub_send_status(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx, uint8_t status,
@ -3118,7 +3153,7 @@ static void heartbeat_pub_set(struct bt_mesh_model *model,
* has been configured for periodic publishing.
*/
if (param->period_log && param->count_log) {
k_work_submit(&cfg->hb_pub.timer.work);
k_delayed_work_submit(&cfg->hb_pub.timer, K_NO_WAIT);
} else {
k_delayed_work_cancel(&cfg->hb_pub.timer);
}
@ -3137,7 +3172,7 @@ static void heartbeat_pub_set(struct bt_mesh_model *model,
*/
if (dst != BLE_MESH_ADDR_UNASSIGNED) {
if (param->period_log && param->count_log) {
k_work_submit(&cfg->hb_pub.timer.work);
k_delayed_work_submit(&cfg->hb_pub.timer, K_NO_WAIT);
} else {
k_delayed_work_cancel(&cfg->hb_pub.timer);
}
@ -3278,7 +3313,7 @@ static void heartbeat_sub_set(struct bt_mesh_model *model,
}
const struct bt_mesh_model_op bt_mesh_cfg_srv_op[] = {
{ OP_DEV_COMP_DATA_GET, 1, dev_comp_data_get },
{ OP_COMP_DATA_GET, 1, comp_data_get },
{ OP_APP_KEY_ADD, 19, app_key_add },
{ OP_APP_KEY_UPDATE, 19, app_key_update },
{ OP_APP_KEY_DEL, 3, app_key_del },
@ -3376,6 +3411,21 @@ static bool conf_is_valid(struct bt_mesh_cfg_srv *cfg)
return false;
}
if (!IS_ENABLED(CONFIG_BLE_MESH_RELAY)) {
BT_INFO("Relay not supported");
cfg->relay = BLE_MESH_RELAY_NOT_SUPPORTED;
}
if (!IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) {
BT_INFO("GATT Proxy not supported");
cfg->gatt_proxy = BLE_MESH_GATT_PROXY_NOT_SUPPORTED;
}
if (!IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
BT_INFO("Friend not supported");
cfg->frnd = BLE_MESH_FRIEND_NOT_SUPPORTED;
}
return true;
}
@ -3489,8 +3539,6 @@ void bt_mesh_cfg_reset(bool store)
struct bt_mesh_cfg_srv *cfg = conf;
int i;
BT_DBG("%s", __func__);
if (!cfg) {
return;
}
@ -3589,13 +3637,13 @@ uint8_t bt_mesh_relay_retransmit_get(void)
return 0;
}
uint8_t bt_mesh_beacon_get(void)
uint8_t bt_mesh_secure_beacon_get(void)
{
if (conf) {
return conf->beacon;
}
return BLE_MESH_BEACON_DISABLED;
return BLE_MESH_SECURE_BEACON_DISABLED;
}
uint8_t bt_mesh_gatt_proxy_get(void)

View File

@ -14,11 +14,16 @@
#include <tinycrypt/aes.h>
#include <tinycrypt/constants.h>
#include <tinycrypt/cmac_mode.h>
#include <tinycrypt/hmac.h>
#include <tinycrypt/sha256.h>
#include "crypto.h"
#include "mesh/config.h"
#include "mesh/common.h"
#include "mesh/adapter.h"
#include "mesh_v1.1/utils.h"
#define NET_MIC_LEN(pdu) (((pdu)[1] & 0x80) ? 8 : 4)
#define APP_MIC_LEN(aszmic) ((aszmic) ? 8 : 4)
@ -512,7 +517,7 @@ static int bt_mesh_ccm_encrypt(const uint8_t key[16], uint8_t nonce[13],
return 0;
}
#if defined(CONFIG_BLE_MESH_PROXY)
#if CONFIG_BLE_MESH_PROXY
static void create_proxy_nonce(uint8_t nonce[13], const uint8_t *pdu,
uint32_t iv_index)
{
@ -538,7 +543,7 @@ static void create_proxy_nonce(uint8_t nonce[13], const uint8_t *pdu,
/* IV Index */
sys_put_be32(iv_index, &nonce[9]);
}
#endif /* PROXY */
#endif /* CONFIG_BLE_MESH_PROXY */
static void create_net_nonce(uint8_t nonce[13], const uint8_t *pdu,
uint32_t iv_index)
@ -593,7 +598,7 @@ int bt_mesh_net_obfuscate(uint8_t *pdu, uint32_t iv_index,
}
int bt_mesh_net_encrypt(const uint8_t key[16], struct net_buf_simple *buf,
uint32_t iv_index, bool proxy)
uint32_t iv_index, bool proxy, bool proxy_solic)
{
uint8_t mic_len = NET_MIC_LEN(buf->data);
uint8_t nonce[13] = {0};
@ -603,15 +608,22 @@ int bt_mesh_net_encrypt(const uint8_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_BLE_MESH_PROXY)
#if CONFIG_BLE_MESH_PROXY
if (proxy) {
#if CONFIG_BLE_MESH_PROXY_SOLIC
if (proxy_solic) {
bt_mesh_create_proxy_solic_nonce(nonce, buf->data, iv_index);
} else
#endif /* CONFIG_BLE_MESH_PROXY_SOLIC */
{
create_proxy_nonce(nonce, buf->data, iv_index);
}
} else {
create_net_nonce(nonce, buf->data, iv_index);
}
#else
#else /* CONFIG_BLE_MESH_PROXY */
create_net_nonce(nonce, buf->data, iv_index);
#endif
#endif /* CONFIG_BLE_MESH_PROXY */
BT_DBG("Nonce %s", bt_hex(nonce, 13));
@ -625,7 +637,7 @@ int bt_mesh_net_encrypt(const uint8_t key[16], struct net_buf_simple *buf,
}
int bt_mesh_net_decrypt(const uint8_t key[16], struct net_buf_simple *buf,
uint32_t iv_index, bool proxy)
uint32_t iv_index, bool proxy, bool proxy_solic)
{
uint8_t mic_len = NET_MIC_LEN(buf->data);
uint8_t nonce[13] = {0};
@ -634,15 +646,22 @@ int bt_mesh_net_decrypt(const uint8_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_BLE_MESH_PROXY)
#if CONFIG_BLE_MESH_PROXY
if (proxy) {
#if CONFIG_BLE_MESH_PROXY_SOLIC
if (proxy_solic) {
bt_mesh_create_proxy_solic_nonce(nonce, buf->data, iv_index);
} else
#endif /* CONFIG_BLE_MESH_PROXY_SOLIC */
{
create_proxy_nonce(nonce, buf->data, iv_index);
}
} else {
create_net_nonce(nonce, buf->data, iv_index);
}
#else
#else /* CONFIG_BLE_MESH_PROXY */
create_net_nonce(nonce, buf->data, iv_index);
#endif
#endif /* CONFIG_BLE_MESH_PROXY */
BT_DBG("Nonce %s", bt_hex(nonce, 13));
@ -849,7 +868,7 @@ int bt_mesh_prov_encrypt(const uint8_t key[16], uint8_t nonce[13],
}
#endif
int bt_mesh_beacon_auth(const uint8_t beacon_key[16], uint8_t flags,
int bt_mesh_secure_beacon_auth(const uint8_t beacon_key[16], uint8_t flags,
const uint8_t net_id[8], uint32_t iv_index,
uint8_t auth[8])
{

View File

@ -70,7 +70,7 @@ static inline int bt_mesh_identity_key(const uint8_t net_key[16],
return bt_mesh_id128(net_key, "nkik", identity_key);
}
static inline int bt_mesh_beacon_key(const uint8_t net_key[16],
static inline int bt_mesh_secure_beacon_key(const uint8_t net_key[16],
uint8_t beacon_key[16])
{
return bt_mesh_id128(net_key, "nkbk", beacon_key);
@ -80,6 +80,10 @@ int bt_mesh_beacon_auth(const uint8_t beacon_key[16], uint8_t flags,
const uint8_t net_id[8], uint32_t iv_index,
uint8_t auth[8]);
int bt_mesh_secure_beacon_auth(const uint8_t beacon_key[16], uint8_t flags,
const uint8_t net_id[8], uint32_t iv_index,
uint8_t auth[8]);
static inline int bt_mesh_app_id(const uint8_t app_key[16], uint8_t app_id[1])
{
return bt_mesh_k4(app_key, app_id);
@ -133,10 +137,10 @@ int bt_mesh_net_obfuscate(uint8_t *pdu, uint32_t iv_index,
const uint8_t privacy_key[16]);
int bt_mesh_net_encrypt(const uint8_t key[16], struct net_buf_simple *buf,
uint32_t iv_index, bool proxy);
uint32_t iv_index, bool proxy, bool proxy_solic);
int bt_mesh_net_decrypt(const uint8_t key[16], struct net_buf_simple *buf,
uint32_t iv_index, bool proxy);
uint32_t iv_index, bool proxy, bool proxy_solic);
int bt_mesh_app_encrypt(const uint8_t key[16], bool dev_key, uint8_t aszmic,
struct net_buf_simple *buf, const uint8_t *ad,

View File

@ -9,6 +9,7 @@
#include "mesh.h"
#include "mesh/common.h"
#include "mesh/main.h"
#include "access.h"
#include "beacon.h"
#include "foundation.h"
@ -24,16 +25,27 @@
const uint8_t *bt_mesh_fast_prov_dev_key_get(uint16_t dst)
{
const uint8_t *key = NULL;
if (!BLE_MESH_ADDR_IS_UNICAST(dst)) {
BT_ERR("Invalid unicast address 0x%04x", dst);
return NULL;
}
if (dst == bt_mesh_primary_addr()) {
if (bt_mesh_is_provisioner_en() == false) {
return bt_mesh.dev_key;
}
return bt_mesh_provisioner_dev_key_get(dst);
/* For fast provisioning, try to find the DevKey from
* the database firstly. If the dst is not in the DB,
* then we will directly use the DevKey.
*/
key = bt_mesh_provisioner_dev_key_get(dst);
if (key) {
return key;
}
return bt_mesh.dev_key;
}
struct bt_mesh_subnet *bt_mesh_fast_prov_subnet_get(uint16_t net_idx)
@ -153,8 +165,8 @@ uint8_t bt_mesh_set_fast_prov_action(uint8_t action)
}
if (action == ACTION_ENTER) {
if (bt_mesh_beacon_get() == BLE_MESH_BEACON_ENABLED) {
bt_mesh_beacon_disable();
if (bt_mesh_secure_beacon_get() == BLE_MESH_SECURE_BEACON_ENABLED) {
bt_mesh_secure_beacon_disable();
}
if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) {
bt_mesh_proxy_client_prov_enable();
@ -167,8 +179,8 @@ uint8_t bt_mesh_set_fast_prov_action(uint8_t action)
if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) {
bt_mesh_proxy_client_prov_disable();
}
if (bt_mesh_beacon_get() == BLE_MESH_BEACON_ENABLED) {
bt_mesh_beacon_enable();
if (bt_mesh_secure_beacon_get() == BLE_MESH_SECURE_BEACON_ENABLED) {
bt_mesh_secure_beacon_enable();
}
bt_mesh_atomic_and(bt_mesh.flags, ~(BIT(BLE_MESH_PROVISIONER) | BIT(BLE_MESH_VALID_PROV)));
bt_mesh_provisioner_fast_prov_enable(false);

View File

@ -17,7 +17,7 @@ extern "C" {
#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_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)
@ -30,14 +30,14 @@ extern "C" {
#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_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_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)
@ -48,12 +48,12 @@ extern "C" {
#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_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)
@ -64,12 +64,12 @@ extern "C" {
#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_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)
@ -80,12 +80,12 @@ extern "C" {
#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_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)
@ -96,11 +96,129 @@ extern "C" {
#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 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 OP_REMOTE_PROV_SCAN_CAPS_GET BLE_MESH_MODEL_OP_2(0x80, 0x4F)
#define OP_REMOTE_PROV_SCAN_CAPS_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x50)
#define OP_REMOTE_PROV_SCAN_GET BLE_MESH_MODEL_OP_2(0x80, 0x51)
#define OP_REMOTE_PROV_SCAN_START BLE_MESH_MODEL_OP_2(0x80, 0x52)
#define OP_REMOTE_PROV_SCAN_STOP BLE_MESH_MODEL_OP_2(0x80, 0x53)
#define OP_REMOTE_PROV_SCAN_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x54)
#define OP_REMOTE_PROV_SCAN_REPORT BLE_MESH_MODEL_OP_2(0x80, 0x55)
#define OP_REMOTE_PROV_EXTENDED_SCAN_START BLE_MESH_MODEL_OP_2(0x80, 0x56)
#define OP_REMOTE_PROV_EXTENDED_SCAN_REPORT BLE_MESH_MODEL_OP_2(0x80, 0x57)
#define OP_REMOTE_PROV_LINK_GET BLE_MESH_MODEL_OP_2(0x80, 0x58)
#define OP_REMOTE_PROV_LINK_OPEN BLE_MESH_MODEL_OP_2(0x80, 0x59)
#define OP_REMOTE_PROV_LINK_CLOSE BLE_MESH_MODEL_OP_2(0x80, 0x5A)
#define OP_REMOTE_PROV_LINK_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x5B)
#define OP_REMOTE_PROV_LINK_REPORT BLE_MESH_MODEL_OP_2(0x80, 0x5C)
#define OP_REMOTE_PROV_PDU_SEND BLE_MESH_MODEL_OP_2(0x80, 0x5D)
#define OP_REMOTE_PROV_PDU_OUTBOUND_REPORT BLE_MESH_MODEL_OP_2(0x80, 0x5E)
#define OP_REMOTE_PROV_PDU_REPORT BLE_MESH_MODEL_OP_2(0x80, 0x5F)
#define OP_DIRECTED_CONTROL_GET BLE_MESH_MODEL_OP_2(0x80, 0x7B)
#define OP_DIRECTED_CONTROL_SET BLE_MESH_MODEL_OP_2(0x80, 0x7C)
#define OP_DIRECTED_CONTROL_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x7D)
#define OP_PATH_METRIC_GET BLE_MESH_MODEL_OP_2(0x80, 0x7E)
#define OP_PATH_METRIC_SET BLE_MESH_MODEL_OP_2(0x80, 0x7F)
#define OP_PATH_METRIC_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x80)
#define OP_DISCOVERY_TABLE_CAPS_GET BLE_MESH_MODEL_OP_2(0x80, 0x81)
#define OP_DISCOVERY_TABLE_CAPS_SET BLE_MESH_MODEL_OP_2(0x80, 0x82)
#define OP_DISCOVERY_TABLE_CAPS_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x83)
#define OP_FORWARDING_TABLE_ADD BLE_MESH_MODEL_OP_2(0x80, 0x84)
#define OP_FORWARDING_TABLE_DEL BLE_MESH_MODEL_OP_2(0x80, 0x85)
#define OP_FORWARDING_TABLE_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x86)
#define OP_FORWARDING_TABLE_DEPS_ADD BLE_MESH_MODEL_OP_2(0x80, 0x87)
#define OP_FORWARDING_TABLE_DEPS_DEL BLE_MESH_MODEL_OP_2(0x80, 0x88)
#define OP_FORWARDING_TABLE_DEPS_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x89)
#define OP_FORWARDING_TABLE_DEPS_GET BLE_MESH_MODEL_OP_2(0x80, 0x8A)
#define OP_FORWARDING_TABLE_DEPS_GET_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x8B)
#define OP_FORWARDING_TABLE_ENTRIES_CNT_GET BLE_MESH_MODEL_OP_2(0x80, 0x8C)
#define OP_FORWARDING_TABLE_ENTRIES_CNT_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x8D)
#define OP_FORWARDING_TABLE_ENTRIES_GET BLE_MESH_MODEL_OP_2(0x80, 0x8E)
#define OP_FORWARDING_TABLE_ENTRIES_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x8F)
#define OP_WANTED_LANES_GET BLE_MESH_MODEL_OP_2(0x80, 0x90)
#define OP_WANTED_LANES_SET BLE_MESH_MODEL_OP_2(0x80, 0x91)
#define OP_WANTED_LANES_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x92)
#define OP_TWO_WAY_PATH_GET BLE_MESH_MODEL_OP_2(0x80, 0x93)
#define OP_TWO_WAY_PATH_SET BLE_MESH_MODEL_OP_2(0x80, 0x94)
#define OP_TWO_WAY_PATH_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x95)
#define OP_PATH_ECHO_INTERVAL_GET BLE_MESH_MODEL_OP_2(0x80, 0x96)
#define OP_PATH_ECHO_INTERVAL_SET BLE_MESH_MODEL_OP_2(0x80, 0x97)
#define OP_PATH_ECHO_INTERVAL_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x98)
#define OP_DIRECTED_NET_TRANSMIT_GET BLE_MESH_MODEL_OP_2(0x80, 0x99)
#define OP_DIRECTED_NET_TRANSMIT_SET BLE_MESH_MODEL_OP_2(0x80, 0x9A)
#define OP_DIRECTED_NET_TRANSMIT_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x9B)
#define OP_DIRECTED_RELAY_RETRANSMIT_GET BLE_MESH_MODEL_OP_2(0x80, 0x9C)
#define OP_DIRECTED_RELAY_RETRANSMIT_SET BLE_MESH_MODEL_OP_2(0x80, 0x9D)
#define OP_DIRECTED_RELAY_RETRANSMIT_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x9E)
#define OP_RSSI_THRESHOLD_GET BLE_MESH_MODEL_OP_2(0x80, 0x9F)
#define OP_RSSI_THRESHOLD_SET BLE_MESH_MODEL_OP_2(0x80, 0xA0)
#define OP_RSSI_THRESHOLD_STATUS BLE_MESH_MODEL_OP_2(0x80, 0xA1)
#define OP_DIRECTED_PATHS_GET BLE_MESH_MODEL_OP_2(0x80, 0xA2)
#define OP_DIRECTED_PATHS_STATUS BLE_MESH_MODEL_OP_2(0x80, 0xA3)
#define OP_DIRECTED_PUB_POLICY_GET BLE_MESH_MODEL_OP_2(0x80, 0xA4)
#define OP_DIRECTED_PUB_POLICY_SET BLE_MESH_MODEL_OP_2(0x80, 0xA5)
#define OP_DIRECTED_PUB_POLICY_STATUS BLE_MESH_MODEL_OP_2(0x80, 0xA6)
#define OP_PATH_DISCOVERY_TIMING_CTL_GET BLE_MESH_MODEL_OP_2(0x80, 0xA7)
#define OP_PATH_DISCOVERY_TIMING_CTL_SET BLE_MESH_MODEL_OP_2(0x80, 0xA8)
#define OP_PATH_DISCOVERY_TIMING_CTL_STATUS BLE_MESH_MODEL_OP_2(0x80, 0xA9)
#define OP_DIRECTED_CTL_NET_TRANSMIT_GET BLE_MESH_MODEL_OP_2(0x80, 0xAB)
#define OP_DIRECTED_CTL_NET_TRANSMIT_SET BLE_MESH_MODEL_OP_2(0x80, 0xAC)
#define OP_DIRECTED_CTL_NET_TRANSMIT_STATUS BLE_MESH_MODEL_OP_2(0x80, 0xAD)
#define OP_DIRECTED_CTL_RELAY_RETRANSMIT_GET BLE_MESH_MODEL_OP_2(0x80, 0xAE)
#define OP_DIRECTED_CTL_RELAY_RETRANSMIT_SET BLE_MESH_MODEL_OP_2(0x80, 0xAF)
#define OP_DIRECTED_CTL_RELAY_RETRANSMIT_STATUS BLE_MESH_MODEL_OP_2(0x80, 0xB0)
#define OP_SUBNET_BRIDGE_GET BLE_MESH_MODEL_OP_2(0x80, 0xB1)
#define OP_SUBNET_BRIDGE_SET BLE_MESH_MODEL_OP_2(0x80, 0xB2)
#define OP_SUBNET_BRIDGE_STATUS BLE_MESH_MODEL_OP_2(0x80, 0xB3)
#define OP_BRIDGING_TABLE_ADD BLE_MESH_MODEL_OP_2(0x80, 0xB4)
#define OP_BRIDGING_TABLE_REMOVE BLE_MESH_MODEL_OP_2(0x80, 0xB5)
#define OP_BRIDGING_TABLE_STATUS BLE_MESH_MODEL_OP_2(0x80, 0xB6)
#define OP_BRIDGED_SUBNETS_GET BLE_MESH_MODEL_OP_2(0x80, 0xB7)
#define OP_BRIDGED_SUBNETS_LIST BLE_MESH_MODEL_OP_2(0x80, 0xB8)
#define OP_BRIDGING_TABLE_GET BLE_MESH_MODEL_OP_2(0x80, 0xB9)
#define OP_BRIDGING_TABLE_LIST BLE_MESH_MODEL_OP_2(0x80, 0xBA)
#define OP_BRIDGING_TABLE_SIZE_GET BLE_MESH_MODEL_OP_2(0x80, 0xBB)
#define OP_BRIDGING_TABLE_SIZE_STATUS BLE_MESH_MODEL_OP_2(0x80, 0xBC)
#define OP_PRIVATE_BEACON_GET BLE_MESH_MODEL_OP_2(0x80, 0x60)
#define OP_PRIVATE_BEACON_SET BLE_MESH_MODEL_OP_2(0x80, 0x61)
#define OP_PRIVATE_BEACON_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x62)
#define OP_PRIVATE_GATT_PROXY_GET BLE_MESH_MODEL_OP_2(0x80, 0x63)
#define OP_PRIVATE_GATT_PROXY_SET BLE_MESH_MODEL_OP_2(0x80, 0x64)
#define OP_PRIVATE_GATT_PROXY_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x65)
#define OP_PRIVATE_NODE_IDENTITY_GET BLE_MESH_MODEL_OP_2(0x80, 0x66)
#define OP_PRIVATE_NODE_IDENTITY_SET BLE_MESH_MODEL_OP_2(0x80, 0x67)
#define OP_PRIVATE_NODE_IDENTITY_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x68)
#define OP_ON_DEMAND_PRIVATE_PROXY_GET BLE_MESH_MODEL_OP_2(0x80, 0x69)
#define OP_ON_DEMAND_PRIVATE_PROXY_SET BLE_MESH_MODEL_OP_2(0x80, 0x6A)
#define OP_ON_DEMAND_PRIVATE_PROXY_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x6B)
#define OP_SAR_TRANSMITTER_GET BLE_MESH_MODEL_OP_2(0x80, 0x6C)
#define OP_SAR_TRANSMITTER_SET BLE_MESH_MODEL_OP_2(0x80, 0x6D)
#define OP_SAR_TRANSMITTER_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x6E)
#define OP_SAR_RECEIVER_GET BLE_MESH_MODEL_OP_2(0x80, 0x6F)
#define OP_SAR_RECEIVER_SET BLE_MESH_MODEL_OP_2(0x80, 0x70)
#define OP_SAR_RECEIVER_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x71)
#define OP_OPCODES_AGG_SEQUENCE BLE_MESH_MODEL_OP_2(0x80, 0x72)
#define OP_OPCODES_AGG_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x73)
#define OP_LARGE_COMP_DATA_GET BLE_MESH_MODEL_OP_2(0x80, 0x74)
#define OP_LARGE_COMP_DATA_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x75)
#define OP_MODELS_METADATA_GET BLE_MESH_MODEL_OP_2(0x80, 0x76)
#define OP_MODELS_METADATA_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x77)
#define OP_SOLIC_PDU_RPL_ITEMS_CLEAR BLE_MESH_MODEL_OP_2(0x80, 0x78)
#define OP_SOLIC_PDU_RPL_ITEMS_CLEAR_UNACK BLE_MESH_MODEL_OP_2(0x80, 0x79)
#define OP_SOLIC_PDU_RPL_ITEMS_STATUS BLE_MESH_MODEL_OP_2(0x80, 0x7A)
#define STATUS_SUCCESS 0x00
#define STATUS_INVALID_ADDRESS 0x01
@ -112,14 +230,26 @@ extern "C" {
#define STATUS_NVAL_PUB_PARAM 0x07
#define STATUS_NOT_SUB_MOD 0x08
#define STATUS_STORAGE_FAIL 0x09
#define STATUS_FEAT_NOT_SUPP 0x0a
#define STATUS_CANNOT_UPDATE 0x0b
#define STATUS_CANNOT_REMOVE 0x0c
#define STATUS_CANNOT_BIND 0x0d
#define STATUS_TEMP_STATE_CHG_FAIL 0x0e
#define STATUS_CANNOT_SET 0x0f
#define STATUS_FEAT_NOT_SUPP 0x0A
#define STATUS_CANNOT_UPDATE 0x0B
#define STATUS_CANNOT_REMOVE 0x0C
#define STATUS_CANNOT_BIND 0x0D
#define STATUS_TEMP_STATE_CHG_FAIL 0x0E
#define STATUS_CANNOT_SET 0x0F
#define STATUS_UNSPECIFIED 0x10
#define STATUS_INVALID_BINDING 0x11
#define STATUS_INVALID_PATH_ENTRY 0x12
#define STATUS_CANNOT_GET 0x13
#define STATUS_OBSOLETE_INFO 0x14
#define STATUS_INVALID_BEARER 0x15
/* Defines the status codes for Opcodes Aggregator messages. */
#define AGG_STATUS_SUCCESS 0x00
#define AGG_STATUS_INVALID_ADDRESS 0x01
#define AGG_STATUS_INVALID_MODEL 0x02
#define AGG_STATUS_WRONG_ACCESS_KEY 0x03
#define AGG_STATUS_WRONG_OPCODE 0x04
#define AGG_STATUS_MSG_NOT_UNDERSTOOD 0x05
enum {
BLE_MESH_VA_CHANGED, /* Label information changed */
@ -152,7 +282,7 @@ uint8_t bt_mesh_net_transmit_get(void);
uint8_t bt_mesh_relay_get(void);
uint8_t bt_mesh_friend_get(void);
uint8_t bt_mesh_relay_retransmit_get(void);
uint8_t bt_mesh_beacon_get(void);
uint8_t bt_mesh_secure_beacon_get(void);
uint8_t bt_mesh_gatt_proxy_get(void);
uint8_t bt_mesh_default_ttl_get(void);

View File

@ -18,8 +18,11 @@
#include "friend.h"
#include "foundation.h"
#include "mesh/main.h"
#include "mesh/common.h"
#include "pvnr_mgmt.h"
#include "mesh_v1.1/utils.h"
#ifdef CONFIG_BLE_MESH_FRIEND
/* We reserve one extra buffer for each friendship, since we need to be able
@ -32,6 +35,11 @@
/* PDUs from Friend to the LPN should only be transmitted once with the
* smallest possible interval (20ms).
*
* Spec v1.1, Section 3.4.6:
* When transmitting a Network PDU that is tagged as friendship, the
* Advertising Bearer Network Interface shall transmit the Network PDU
* over the advertising bearer only once.
*/
#define FRIEND_XMIT BLE_MESH_TRANSMIT(0, 20)
@ -70,15 +78,7 @@ static bool friend_init = false;
static struct bt_mesh_subnet *friend_subnet_get(uint16_t net_idx)
{
struct bt_mesh_subnet *sub = NULL;
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
sub = bt_mesh_subnet_get(net_idx);
} else if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en()) {
sub = bt_mesh_provisioner_subnet_get(net_idx);
}
return sub;
return bt_mesh_subnet_get(net_idx);
}
static struct bt_mesh_adv *adv_alloc(int id)
@ -166,6 +166,15 @@ static void friend_clear(struct bt_mesh_friend *frnd, uint8_t reason)
if (friend_cb) {
friend_cb(false, frnd->lpn, reason);
}
#if CONFIG_BLE_MESH_DF_SRV
struct bt_mesh_subnet *sub = friend_subnet_get(frnd->net_idx);
if (sub && sub->directed_friend == BLE_MESH_DIRECTED_FRIEND_ENABLED) {
if (bt_mesh_directed_update_dependent_node(sub, 0, frnd->lpn, frnd->num_elem)) {
BT_ERR("Friend failed to update dependent node");
}
}
#endif /* CONFIG_BLE_MESH_DF_SRV */
}
friend_cred_del(frnd->net_idx, frnd->lpn);
@ -297,6 +306,9 @@ int bt_mesh_friend_clear(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
}
tx.ctx->send_ttl = BLE_MESH_TTL_MAX;
tx.ctx->send_cred = BLE_MESH_FLOODING_CRED;
/* Tag with immutable-credentials */
tx.ctx->send_tag = BLE_MESH_TAG_IMMUTABLE_CRED;
cfm.lpn_addr = msg->lpn_addr;
cfm.lpn_counter = msg->lpn_counter;
@ -309,6 +321,19 @@ int bt_mesh_friend_clear(struct bt_mesh_net_rx *rx, struct net_buf_simple *buf)
return 0;
}
static bool friend_sub_exist(struct bt_mesh_friend *frnd, uint16_t addr)
{
int i;
for (i = 0; i < ARRAY_SIZE(frnd->sub_list); i++) {
if (frnd->sub_list[i] == addr) {
return true;
}
}
return false;
}
static void friend_sub_add(struct bt_mesh_friend *frnd, uint16_t addr)
{
int i;
@ -342,8 +367,7 @@ static struct net_buf *create_friend_pdu(struct bt_mesh_friend *frnd,
struct net_buf *buf = NULL;
buf = bt_mesh_adv_create_from_pool(&friend_buf_pool, adv_alloc,
BLE_MESH_ADV_DATA,
FRIEND_XMIT, K_NO_WAIT);
BLE_MESH_ADV_DATA, K_NO_WAIT);
if (!buf) {
return NULL;
}
@ -380,7 +404,6 @@ static int unseg_app_sdu_unpack(struct bt_mesh_friend *frnd,
struct unseg_app_sdu_meta *meta)
{
uint16_t app_idx = FRIEND_ADV(buf)->app_idx;
uint8_t role = 0U;
int err = 0;
meta->subnet = friend_subnet_get(frnd->net_idx);
@ -389,13 +412,10 @@ static int unseg_app_sdu_unpack(struct bt_mesh_friend *frnd,
return -EINVAL;
}
role = (IS_ENABLED(CONFIG_BLE_MESH_NODE) &&
bt_mesh_is_provisioned()) ? NODE : PROVISIONER;
meta->is_dev_key = (app_idx == BLE_MESH_KEY_DEV);
bt_mesh_net_header_parse(&buf->b, &meta->net);
err = bt_mesh_app_key_get(meta->subnet, app_idx, &meta->key,
&meta->aid, role, meta->net.ctx.addr);
err = bt_mesh_upper_key_get(meta->subnet, app_idx, &meta->key,
&meta->aid, meta->net.ctx.addr);
if (err) {
BT_ERR("Failed to get AppKey");
return err;
@ -532,7 +552,7 @@ static int encrypt_friend_pdu(struct bt_mesh_friend *frnd, struct net_buf *buf,
buf->data[0] = (nid | (iv_index & 1) << 7);
if (bt_mesh_net_encrypt(enc, &buf->b, iv_index, false)) {
if (bt_mesh_net_encrypt(enc, &buf->b, iv_index, false, false)) {
BT_ERR("Encrypting failed");
return -EINVAL;
}
@ -657,12 +677,29 @@ int bt_mesh_friend_sub_add(struct bt_mesh_net_rx *rx,
xact = net_buf_simple_pull_u8(buf);
while (buf->len >= 2U) {
friend_sub_add(frnd, net_buf_simple_pull_be16(buf));
uint16_t addr = net_buf_simple_pull_be16(buf);
if (!BLE_MESH_ADDR_IS_GROUP(addr) &&
!BLE_MESH_ADDR_IS_VIRTUAL(addr) &&
!BLE_MESH_ADDR_IS_FIXED_GROUP(addr)) {
BT_WARN("Invalid friend sub addr 0x%04x to add", addr);
continue;
}
if (friend_sub_exist(frnd, addr)) {
continue;
}
friend_sub_add(frnd, addr);
}
enqueue_sub_cfm(frnd, xact);
#if CONFIG_BLE_MESH_DF_SRV
return bt_mesh_directed_friend_solicitation(frnd, rx->sub);
#else
return 0;
#endif
}
int bt_mesh_friend_sub_rem(struct bt_mesh_net_rx *rx,
@ -692,7 +729,16 @@ int bt_mesh_friend_sub_rem(struct bt_mesh_net_rx *rx,
xact = net_buf_simple_pull_u8(buf);
while (buf->len >= 2U) {
friend_sub_rem(frnd, net_buf_simple_pull_be16(buf));
uint16_t addr = net_buf_simple_pull_be16(buf);
if (!BLE_MESH_ADDR_IS_GROUP(addr) &&
!BLE_MESH_ADDR_IS_VIRTUAL(addr) &&
!BLE_MESH_ADDR_IS_FIXED_GROUP(addr)) {
BT_WARN("Invalid friend sub addr 0x%04x to remove", addr);
continue;
}
friend_sub_rem(frnd, addr);
}
enqueue_sub_cfm(frnd, xact);
@ -812,6 +858,9 @@ static void send_friend_clear(struct bt_mesh_friend *frnd)
.app_idx = BLE_MESH_KEY_UNUSED,
.addr = frnd->clear.frnd,
.send_ttl = BLE_MESH_TTL_MAX,
.send_cred = BLE_MESH_FLOODING_CRED,
/* Tag with immutable-credentials */
.send_tag = BLE_MESH_TAG_IMMUTABLE_CRED,
};
struct bt_mesh_net_tx tx = {
.sub = friend_subnet_get(frnd->net_idx),
@ -824,8 +873,6 @@ static void send_friend_clear(struct bt_mesh_friend *frnd)
.lpn_counter = sys_cpu_to_be16(frnd->lpn_counter),
};
BT_DBG("%s", __func__);
if (!tx.sub) {
BT_ERR("Invalid subnet for Friend Clear");
return;
@ -870,8 +917,6 @@ int bt_mesh_friend_clear_cfm(struct bt_mesh_net_rx *rx,
struct bt_mesh_friend *frnd = NULL;
uint16_t lpn_addr = 0U, lpn_counter = 0U;
BT_DBG("%s", __func__);
if (buf->len < sizeof(*msg)) {
BT_WARN("Too short Friend Clear Confirm (len %d)", buf->len);
return -EINVAL;
@ -909,16 +954,14 @@ static void enqueue_offer(struct bt_mesh_friend *frnd, int8_t rssi)
NET_BUF_SIMPLE_DEFINE(sdu, 1 + sizeof(*off));
struct net_buf *buf = NULL;
BT_DBG("%s", __func__);
net_buf_simple_reserve(&sdu, 1);
off = net_buf_simple_add(&sdu, sizeof(*off));
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->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);
@ -1245,7 +1288,7 @@ static void friend_timeout(struct k_work *work)
send_last:
frnd->pending_req = 0U;
frnd->pending_buf = 1U;
bt_mesh_adv_send(frnd->last, &buf_sent_cb, frnd);
bt_mesh_adv_send(frnd->last, FRIEND_XMIT, &buf_sent_cb, frnd);
}
void bt_mesh_friend_set_cb(void (*cb)(bool establish, uint16_t lpn_addr, uint8_t reason))
@ -1513,6 +1556,29 @@ bool bt_mesh_friend_match(uint16_t net_idx, uint16_t addr)
return false;
}
bool bt_mesh_friend_unicast_match(uint16_t net_idx, uint16_t addr, uint8_t *selem)
{
int i;
if (!BLE_MESH_ADDR_IS_UNICAST(addr) || selem == NULL) {
BT_ERR("%s, Invalid parameter", __func__);
return false;
}
for (i = 0; i < ARRAY_SIZE(bt_mesh.frnd); i++) {
struct bt_mesh_friend *frnd = &bt_mesh.frnd[i];
if (frnd->established && net_idx == frnd->net_idx &&
BLE_MESH_ADDR_IS_UNICAST(frnd->lpn) &&
(addr >= frnd->lpn && addr < (frnd->lpn + frnd->num_elem))) {
*selem = frnd->num_elem - 1;
return true;
}
}
return false;
}
static bool friend_queue_has_space(struct bt_mesh_friend *frnd, uint16_t addr,
const uint64_t *seq_auth, uint8_t seg_count)
{
@ -1692,8 +1758,6 @@ void bt_mesh_friend_clear_incomplete(struct bt_mesh_subnet *sub, uint16_t src,
{
int i;
BT_DBG("%s", __func__);
for (i = 0; i < ARRAY_SIZE(bt_mesh.frnd); i++) {
struct bt_mesh_friend *frnd = &bt_mesh.frnd[i];
int j;

View File

@ -22,6 +22,7 @@ enum bt_mesh_friend_pdu_type {
};
bool bt_mesh_friend_match(uint16_t net_idx, uint16_t addr);
bool bt_mesh_friend_unicast_match(uint16_t net_idx, uint16_t addr, uint8_t *selem);
struct bt_mesh_friend *bt_mesh_friend_find(uint16_t net_idx, uint16_t lpn_addr,
bool valid, bool established);

View File

@ -31,40 +31,17 @@ static const bt_mesh_client_op_pair_t health_op_pair[] = {
static bt_mesh_mutex_t health_client_lock;
static inline void bt_mesh_health_client_mutex_new(void)
{
if (!health_client_lock.mutex) {
bt_mesh_mutex_create(&health_client_lock);
}
}
#if CONFIG_BLE_MESH_DEINIT
static inline void bt_mesh_health_client_mutex_free(void)
{
bt_mesh_mutex_free(&health_client_lock);
}
#endif /* CONFIG_BLE_MESH_DEINIT */
static inline void bt_mesh_health_client_lock(void)
{
bt_mesh_mutex_lock(&health_client_lock);
}
static inline void bt_mesh_health_client_unlock(void)
{
bt_mesh_mutex_unlock(&health_client_lock);
}
static void timeout_handler(struct k_work *work)
{
struct k_delayed_work *timer = NULL;
bt_mesh_client_node_t *node = NULL;
struct bt_mesh_model *model = NULL;
struct bt_mesh_msg_ctx ctx = {0};
uint32_t opcode = 0U;
BT_WARN("Receive health status message timeout");
bt_mesh_health_client_lock();
bt_mesh_mutex_lock(&health_client_lock);
timer = CONTAINER_OF(work, struct k_delayed_work, work);
@ -73,15 +50,14 @@ static void timeout_handler(struct k_work *work)
if (node) {
memcpy(&ctx, &node->ctx, sizeof(ctx));
opcode = node->opcode;
model = node->model;
bt_mesh_client_free_node(node);
bt_mesh_health_client_cb_evt_to_btc(
opcode, BTC_BLE_MESH_EVT_HEALTH_CLIENT_TIMEOUT, ctx.model, &ctx, NULL, 0);
opcode, BTC_BLE_MESH_EVT_HEALTH_CLIENT_TIMEOUT, model, &ctx, NULL, 0);
}
}
bt_mesh_health_client_unlock();
return;
bt_mesh_mutex_unlock(&health_client_lock);
}
static void health_client_recv_status(struct bt_mesh_model *model,
@ -101,7 +77,7 @@ static void health_client_recv_status(struct bt_mesh_model *model,
buf.data = (uint8_t *)status;
buf.len = (uint16_t)len;
bt_mesh_health_client_lock();
bt_mesh_mutex_lock(&health_client_lock);
node = bt_mesh_is_client_recv_publish_msg(model, ctx, &buf, true);
if (!node) {
@ -131,7 +107,7 @@ static void health_client_recv_status(struct bt_mesh_model *model,
}
}
bt_mesh_health_client_unlock();
bt_mesh_mutex_unlock(&health_client_lock);
switch (ctx->recv_op) {
case OP_HEALTH_FAULT_STATUS: {
@ -324,7 +300,11 @@ static int health_cli_init(struct bt_mesh_model *model)
return -EINVAL;
}
if (!client->internal_data) {
if (client->internal_data) {
BT_WARN("%s, Already", __func__);
return -EALREADY;
}
internal = bt_mesh_calloc(sizeof(health_internal_data_t));
if (!internal) {
BT_ERR("%s, Out of memory", __func__);
@ -337,11 +317,8 @@ static int health_cli_init(struct bt_mesh_model *model)
client->op_pair_size = ARRAY_SIZE(health_op_pair);
client->op_pair = health_op_pair;
client->internal_data = internal;
} else {
bt_mesh_client_clear_list(client->internal_data);
}
bt_mesh_health_client_mutex_new();
bt_mesh_mutex_create(&health_client_lock);
return 0;
}
@ -373,7 +350,7 @@ static int health_cli_deinit(struct bt_mesh_model *model)
client->internal_data = NULL;
}
bt_mesh_health_client_mutex_free();
bt_mesh_mutex_free(&health_client_lock);
return 0;
}

View File

@ -182,8 +182,6 @@ static void health_fault_test(struct bt_mesh_model *model,
uint16_t company_id = 0U;
uint8_t test_id = 0U;
BT_DBG("%s", __func__);
if (!srv) {
BT_ERR("No Health Server context provided");
return;
@ -241,8 +239,6 @@ static void attention_get(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
BT_DBG("%s", __func__);
send_attention_status(model, ctx);
}
@ -263,8 +259,6 @@ static void attention_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
BT_DBG("%s", __func__);
health_set_attention(model, ctx, buf);
if (ctx->recv_op == OP_ATTENTION_SET) {
@ -289,8 +283,6 @@ static void health_period_get(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
BT_DBG("%s", __func__);
send_health_period_status(model, ctx);
}
@ -315,8 +307,6 @@ static void health_period_set(struct bt_mesh_model *model,
struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *buf)
{
BT_DBG("%s", __func__);
health_set_period(model, ctx, buf);
if (ctx->recv_op == OP_HEALTH_PERIOD_SET) {
@ -367,8 +357,6 @@ static int health_pub_update(struct bt_mesh_model *model)
struct bt_mesh_model_pub *pub = model->pub;
size_t count = 0U;
BT_DBG("%s", __func__);
if (!pub || !pub->msg) {
BT_ERR("Invalid health publication context");
return -EINVAL;
@ -416,8 +404,6 @@ static void attention_off(struct k_work *work)
struct bt_mesh_health_srv *srv = CONTAINER_OF(work,
struct bt_mesh_health_srv,
attn_timer.work);
BT_DBG("%s", __func__);
if (!srv) {
BT_ERR("No Health Server context provided");
return;

View File

@ -4,7 +4,7 @@
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2021 Espressif Systems (Shanghai) CO LTD
* SPDX-FileContributor: 2018-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -29,13 +29,17 @@ extern "C" {
#define BLE_MESH_CID_NVAL 0xFFFF
#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 BLE_MESH_KEY_UNUSED 0xffff
#define BLE_MESH_KEY_DEV 0xfffe
#define BLE_MESH_ADDR_IPT_ROUTERS 0xFFF9
#define BLE_MESH_ADDR_IPT_NODES 0xFFFA
#define BLE_MESH_ADDR_DIRECTS 0xFFFB
#define BLE_MESH_ADDR_PROXIES 0xFFFC
#define BLE_MESH_ADDR_FRIENDS 0xFFFD
#define BLE_MESH_ADDR_RELAYS 0xFFFE
#define BLE_MESH_ADDR_ALL_NODES 0xFFFF
#define BLE_MESH_KEY_UNUSED 0xFFFF
#define BLE_MESH_KEY_DEV 0xFFFE
/** Helper to define a mesh element within an array.
*
@ -75,6 +79,24 @@ struct bt_mesh_elem {
#define BLE_MESH_MODEL_ID_CFG_CLI 0x0001
#define BLE_MESH_MODEL_ID_HEALTH_SRV 0x0002
#define BLE_MESH_MODEL_ID_HEALTH_CLI 0x0003
#define BLE_MESH_MODEL_ID_RPR_SRV 0x0004
#define BLE_MESH_MODEL_ID_RPR_CLI 0x0005
#define BLE_MESH_MODEL_ID_DF_SRV 0x0006
#define BLE_MESH_MODEL_ID_DF_CLI 0x0007
#define BLE_MESH_MODEL_ID_BRC_SRV 0x0008
#define BLE_MESH_MODEL_ID_BRC_CLI 0x0009
#define BLE_MESH_MODEL_ID_PRB_SRV 0x000A
#define BLE_MESH_MODEL_ID_PRB_CLI 0x000B
#define BLE_MESH_MODEL_ID_ODP_SRV 0x000C
#define BLE_MESH_MODEL_ID_ODP_CLI 0x000D
#define BLE_MESH_MODEL_ID_SAR_SRV 0x000E
#define BLE_MESH_MODEL_ID_SAR_CLI 0x000F
#define BLE_MESH_MODEL_ID_AGG_SRV 0x0010
#define BLE_MESH_MODEL_ID_AGG_CLI 0x0011
#define BLE_MESH_MODEL_ID_LCD_SRV 0x0012
#define BLE_MESH_MODEL_ID_LCD_CLI 0x0013
#define BLE_MESH_MODEL_ID_SRPL_SRV 0x0014
#define BLE_MESH_MODEL_ID_SRPL_CLI 0x0015
/* Models from the Mesh Model Specification */
#define BLE_MESH_MODEL_ID_GEN_ONOFF_SRV 0x1000
@ -129,6 +151,8 @@ struct bt_mesh_elem {
#define BLE_MESH_MODEL_ID_LIGHT_LC_SRV 0x130f
#define BLE_MESH_MODEL_ID_LIGHT_LC_SETUP_SRV 0x1310
#define BLE_MESH_MODEL_ID_LIGHT_LC_CLI 0x1311
#define BLE_MESH_MODEL_ID_MBT_SRV 0x1400
#define BLE_MESH_MODEL_ID_MBT_CLI 0x1401
/** Message sending context. */
struct bt_mesh_msg_ctx {
@ -144,28 +168,42 @@ struct bt_mesh_msg_ctx {
/** Destination address of a received message. Not used for sending. */
uint16_t recv_dst;
/** RSSI of received packet. Not used for sending. */
/** RSSI of a received message. Not used for sending. */
int8_t recv_rssi;
/** Received TTL value. Not used for sending. */
uint8_t recv_ttl: 7;
/** Opcode of a received message. Not used for sending. */
uint32_t recv_op;
/** Force sending reliably by using segment acknowledgement */
uint8_t send_rel: 1;
/** Received TTL value. Not used for sending. */
uint8_t recv_ttl;
/** Security credentials of a received message. Not used for sending. */
uint8_t recv_cred;
/** Tag of a received message. Not used for sending. */
uint8_t recv_tag;
/** Force sending reliably by using segment acknowledgement. */
uint8_t send_rel:1 __attribute__((deprecated));
/** Size of TransMIC when sending a Segmented Access message. */
uint8_t send_szmic:1;
/** TTL, or BLE_MESH_TTL_DEFAULT for default TTL. */
uint8_t send_ttl;
/** Change by Espressif, opcode of a received message.
* Not used for sending message. */
uint32_t recv_op;
/** Security credentials used for sending the message */
uint8_t send_cred;
/** Tag used for sending the message. */
uint8_t send_tag;
/** Change by Espressif, model corresponds to the message */
struct bt_mesh_model *model;
struct bt_mesh_model *model __attribute__((deprecated));
/** Change by Espressif, if the message is sent by a server
* model. Not used for receiving message. */
bool srv_send;
bool srv_send __attribute__((deprecated));
};
struct bt_mesh_model_op {
@ -194,9 +232,22 @@ struct bt_mesh_model_op {
/** Length of a short Mesh MIC. */
#define BLE_MESH_MIC_SHORT 4
/** Length of a long Mesh MIC. */
#define BLE_MESH_MIC_LONG 8
/* Using 4-octets TransMIC for a segmented message */
#define BLE_MESH_SEG_SZMIC_SHORT 0
/* Using 8-octets TransMIC for a segmented message */
#define BLE_MESH_SEG_SZMIC_LONG 1
/** Maximum length of payload with short MIC */
#define BLE_MESH_MAX_PDU_LEN_WITH_SMIC 380
/** Maximum length of payload with long MIC */
#define BLE_MESH_MAX_PDU_LEN_WITH_LMIC 376
/** @def BLE_MESH_MODEL_OP_LEN
*
* @brief Helper to determine the length of an opcode.
@ -364,7 +415,8 @@ struct bt_mesh_model_pub {
uint16_t addr; /**< Publish Address. */
uint16_t key:12, /**< Publish AppKey Index. */
cred:1, /**< Friendship Credentials Flag. */
send_rel:1; /**< Force reliable sending (segment acks) */
send_rel:1, /**< Force reliable sending (segment acks) */
send_szmic:1; /**< Size of TransMIC when sending Segmented Access message */
uint8_t ttl; /**< Publish Time to Live. */
uint8_t retransmit; /**< Retransmit Count & Interval Steps. */
@ -375,6 +427,10 @@ struct bt_mesh_model_pub {
uint32_t period_start; /**< Start of the current period. */
#if CONFIG_BLE_MESH_DF_SRV
uint8_t directed_pub_policy; /**< Directed publish policy */
#endif
/** @brief Publication buffer, containing the publication message.
*
* This will get correctly created when the publication context
@ -405,7 +461,7 @@ struct bt_mesh_model_pub {
struct k_delayed_work timer;
/* Change by Espressif, role of the device going to publish messages */
uint8_t dev_role;
uint8_t dev_role __attribute__((deprecated));
};
/** @def BLE_MESH_MODEL_PUB_DEFINE

View File

@ -113,20 +113,41 @@ extern "C" {
#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_TX_POWER 0x0A /* Tx Power */
#define BLE_MESH_DATA_CLASS_OF_DEVICE 0x0D /* Class of Device */
#define BLE_MESH_DATA_SIMP_PAIR_HASH_C 0x0E /* Simple Pairing Hash C */
#define BLE_MESH_DATA_SIMP_PAIR_RAND_R 0x0F /* Simple Pairing Randomizer R */
#define BLE_MESH_DATA_SEC_MANAGER_TK_VAL 0x10 /* Security Manager TK Value */
#define BLE_MESH_DATA_SEC_MANAGER_OOB_FLAG 0x11 /* Security Manager Out of Band Flags */
#define BLE_MESH_DATA_SLAVE_CONN_INT_RANGE 0x12 /* Slave Connection Interval Range */
#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_PUBLIC_TARGET_ADDR 0x17 /* Public Target Address */
#define BLE_MESH_DATA_RANDOM_TARGET_ADDR 0x18 /* Random Target Address */
#define BLE_MESH_DATA_GAP_APPEARANCE 0x19 /* GAP appearance */
#define BLE_MESH_DATA_SOLICIT32 0x1f /* Solicit UUIDs, 32-bit */
#define BLE_MESH_DATA_ADV_INTERVAL 0x1A /* Advertising Interval */
#define BLE_MESH_DATA_LE_DEVICE_ADDR 0x1B /* LE Bluetooth Device Address */
#define BLE_MESH_DATA_LE_ROLE 0x1C /* LE Role */
#define BLE_MESH_DATA_SIMP_PAIR_HASH_C_256 0x1D /* Simple Pairing Hash C-256 */
#define BLE_MESH_DATA_SIMP_PAIR_RAND_R_256 0x1E /* Simple Pairing Randomizer R-256 */
#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_LE_SEC_CONN_CFM_VAL 0x22 /* LE Secure Connections Confirmation Value */
#define BLE_MESH_DATA_LE_SEC_CONN_RAND_VAL 0x23 /* LE Secure Connections Random Value */
#define BLE_MESH_DATA_URI 0x24 /* URI */
#define BLE_MESH_DATA_INDOOR_POSITION 0x25 /* Indoor Positioning */
#define BLE_MESH_DATA_TRANS_DISC_DATA 0x26 /* Transport Discovery Data */
#define BLE_MESH_DATA_LE_SUPPORT_FEAT 0x27 /* LE Supported Features */
#define BLE_MESH_DATA_CHAN_MAP_UPDATE_IND 0x28 /* Channel Map Update Indication */
#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 BLE_MESH_DATA_MANUFACTURER_DATA 0xff /* Manufacturer Specific Data */
#define BLE_MESH_DATA_MESH_MESSAGE 0x2A /* Mesh Networking PDU */
#define BLE_MESH_DATA_MESH_BEACON 0x2B /* Mesh Beacon */
#define BLE_MESH_DATA_BIGINFO 0x2C /* BIGInf */
#define BLE_MESH_DATA_BROADCAST_COD 0x2D /* Broadcast_Cod */
#define BLE_MESH_DATA_3D_INFO_DATA 0x3D /* 3D Information Data */
#define BLE_MESH_DATA_MANUFACTURER_DATA 0xFF /* Manufacturer Specific Data */
#define BLE_MESH_AD_LIMITED 0x01 /* Limited Discoverable */
#define BLE_MESH_AD_GENERAL 0x02 /* General Discoverable */
@ -442,9 +463,11 @@ struct bt_mesh_conn {
* @param rssi Strength of advertiser signal.
* @param adv_type Type of advertising response from advertiser.
* @param data Buffer containing advertiser data.
* @param scan_rsp_len Scan Response data length.
*/
typedef void bt_mesh_scan_cb_t(const bt_mesh_addr_t *addr, int8_t rssi,
uint8_t adv_type, struct net_buf_simple *buf);
uint8_t adv_type, struct net_buf_simple *buf,
uint8_t scan_rsp_len);
/* @typedef bt_mesh_dh_key_cb_t
* @brief Callback type for DH Key calculation.
@ -452,11 +475,11 @@ typedef void bt_mesh_scan_cb_t(const bt_mesh_addr_t *addr, int8_t rssi,
* Used to notify of the calculated DH Key.
*
* @param key Public key.
* @param idx Provisioning link index, only used by Provisioner.
* @param user_data User data.
*
* @return The DH Key, or NULL in case of failure.
*/
typedef void (*bt_mesh_dh_key_cb_t)(const uint8_t key[32], const uint8_t idx);
typedef void (*bt_mesh_dh_key_cb_t)(const uint8_t key[32], void *user_data);
/** @typedef bt_mesh_gatt_attr_func_t
* @brief Attribute iterator callback.
@ -767,7 +790,7 @@ const uint8_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 uint8_t remote_pk[64], bt_mesh_dh_key_cb_t cb, const uint8_t idx);
int bt_mesh_dh_key_gen(const uint8_t remote_pub_key[64], uint8_t dhkey[32]);
int bt_mesh_encrypt_le(const uint8_t key[16], const uint8_t plaintext[16],
uint8_t enc_data[16]);

View File

@ -107,19 +107,19 @@ struct bt_mesh_hci_cp_set_adv_param {
bt_mesh_addr_t direct_addr;
uint8_t channel_map;
uint8_t filter_policy;
} __packed;
} __attribute__((packed));
#define BLE_MESH_HCI_OP_SET_ADV_DATA BLE_MESH_OP(BLE_MESH_OGF_LE, 0x0008)
struct bt_mesh_hci_cp_set_adv_data {
uint8_t len;
uint8_t data[31];
} __packed;
} __attribute__((packed));
#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 {
uint8_t len;
uint8_t data[31];
} __packed;
} __attribute__((packed));
/* Added by Espressif */
extern struct bt_mesh_dev bt_mesh_dev;

View File

@ -54,7 +54,9 @@ typedef enum {
BLE_MESH_PROV_OOB_NFC = BIT(4),
BLE_MESH_PROV_OOB_NUMBER = BIT(5),
BLE_MESH_PROV_OOB_STRING = BIT(6),
/* 7 - 10 are reserved */
BLE_MESH_PROV_CERT_BASED = BIT(7),
BLE_MESH_PROV_RECORDS = BIT(8),
/* 9 - 10 are reserved */
BLE_MESH_PROV_OOB_ON_BOX = BIT(11),
BLE_MESH_PROV_OOB_IN_BOX = BIT(12),
BLE_MESH_PROV_OOB_ON_PAPER = BIT(13),
@ -62,7 +64,12 @@ typedef enum {
BLE_MESH_PROV_OOB_ON_DEV = BIT(15),
} bt_mesh_prov_oob_info_t;
#if CONFIG_BLE_MESH_PROV_EPA
#define BLE_MESH_PROV_STATIC_OOB_MAX_LEN 32
#else /* CONFIG_BLE_MESH_PROV_EPA */
#define BLE_MESH_PROV_STATIC_OOB_MAX_LEN 16
#endif /* CONFIG_BLE_MESH_PROV_EPA */
#define BLE_MESH_PROV_OUTPUT_OOB_MAX_LEN 8
#define BLE_MESH_PROV_INPUT_OOB_MAX_LEN 8
@ -92,6 +99,9 @@ struct bt_mesh_prov {
*/
void (*oob_pub_key_cb)(void);
/** OOB type */
uint8_t oob_type;
/** Static OOB value */
const uint8_t *static_val;
/** Static OOB value length */
@ -161,8 +171,9 @@ struct bt_mesh_prov {
* link has been closed on the given provisioning bearer.
*
* @param bearer Provisioning bearer.
* @param reason Provisioning link close reason(disconnect reason)
*/
void (*link_close)(bt_mesh_prov_bearer_t bearer);
void (*link_close)(bt_mesh_prov_bearer_t bearer, uint8_t reason);
/** @brief Provisioning is complete.
*
@ -181,7 +192,7 @@ struct bt_mesh_prov {
/** @brief Node has been reset.
*
* This callback notifies the application that the local node
* has been reset and needs to be reprovisioned. The node will
* has been reset and needs to be re-provisioned. The node will
* not automatically advertise as unprovisioned, rather the
* bt_mesh_prov_enable() API needs to be called to enable
* unprovisioned advertising on one or more provisioning bearers.
@ -305,6 +316,41 @@ struct bt_mesh_prov {
void (*prov_complete)(uint16_t node_idx, const uint8_t device_uuid[16],
uint16_t unicast_addr, uint8_t element_num,
uint16_t netkey_idx);
/** @brief Provisioner start certificate based provisioning.
*
* This callback notifies the application that certificate based provisioning
* has started. Provisioner need to send prov_records_get, prov_record_request
* or prov_invite message.
*
* @param link_idx: The provisioning link index
*/
void (*cert_based_prov_start)(uint16_t link_idx);
/** @brief Provisioner receive provisioning records list from device.
*
* This callback notifies the application that provisioner has received
* provisioning records list, and will send the list to application.
*
* @param link_idx: The provisioning link index
* @param data: The provisioning records list.
*/
void (*records_list_get)(uint16_t link_idx, struct net_buf_simple *data);
/** @brief Provisioner receive complete provisioning record from device.
*
* This callback notifies the application that provisioner has received
* complete provisioning record, and will send the record to application.
*
* @param status: Status
* @param link_idx: The provisioning link index.
* @param record_id: The provisioning record index.
* @param frag_offset: The starting of the fragment.
* @param total_len: The length of the record.
* @param record: The data of the record.
*/
void (*prov_record_recv_comp)(uint8_t status, uint16_t link_idx, uint16_t record_id,
uint16_t frag_offset, uint16_t total_len, uint8_t *record);
#endif /* CONFIG_BLE_MESH_PROVISIONER */
};
@ -421,8 +467,8 @@ int bt_mesh_provisioner_disable(bt_mesh_prov_bearer_t bearers);
#define BLE_MESH_RELAY_ENABLED 0x01
#define BLE_MESH_RELAY_NOT_SUPPORTED 0x02
#define BLE_MESH_BEACON_DISABLED 0x00
#define BLE_MESH_BEACON_ENABLED 0x01
#define BLE_MESH_SECURE_BEACON_DISABLED 0x00
#define BLE_MESH_SECURE_BEACON_ENABLED 0x01
#define BLE_MESH_GATT_PROXY_DISABLED 0x00
#define BLE_MESH_GATT_PROXY_ENABLED 0x01
@ -436,6 +482,52 @@ int bt_mesh_provisioner_disable(bt_mesh_prov_bearer_t bearers);
#define BLE_MESH_NODE_IDENTITY_RUNNING 0x01
#define BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED 0x02
#define BLE_MESH_PRIVATE_BEACON_DISABLED 0x00
#define BLE_MESH_PRIVATE_BEACON_ENABLED 0x01
#define BLE_MESH_RANDOM_UPDATE_EVERY_PRIVATE_BEACON 0x00
#define BLE_MESH_PRIVATE_GATT_PROXY_DISABLED 0x00
#define BLE_MESH_PRIVATE_GATT_PROXY_ENABLED 0x01
#define BLE_MESH_PRIVATE_GATT_PROXY_NOT_SUPPORTED 0x02
#define BLE_MESH_PRIVATE_NODE_IDENTITY_STOPPED 0x00
#define BLE_MESH_PRIVATE_NODE_IDENTITY_RUNNING 0x01
#define BLE_MESH_PRIVATE_NODE_IDENTITY_NOT_SUPPORTED 0x02
#define BLE_MESH_SUBNET_BRIDGE_DISABLED 0x00
#define BLE_MESH_SUBNET_BRIDGE_ENABLED 0x01
#define BLE_MESH_PRIVATE_NET_ID_CANNOT_EN_ON_DEMAND 0x00
#define BLE_MESH_DIRECTED_FORWARDING_DISABLED 0x00
#define BLE_MESH_DIRECTED_FORWARDING_ENABLED 0x01
#define BLE_MESH_DIRECTED_RELAY_DISABLED 0x00
#define BLE_MESH_DIRECTED_RELAY_ENABLED 0x01
#define BLE_MESH_DIRECTED_PROXY_DISABLED 0x00
#define BLE_MESH_DIRECTED_PROXY_ENABLED 0x01
#define BLE_MESH_DIRECTED_PROXY_NOT_SUPPORTED 0x02
#define BLE_MESH_DIRECTED_PROXY_USE_DEF_DISABLED 0x00
#define BLE_MESH_DIRECTED_PROXY_USE_DEF_ENABLED 0x01
#define BLE_MESH_DIRECTED_PROXY_USE_DEF_NOT_SUPPORTED 0x02
#define BLE_MESH_DIRECTED_FRIEND_DISABLED 0x00
#define BLE_MESH_DIRECTED_FRIEND_ENABLED 0x01
#define BLE_MESH_DIRECTED_FRIEND_NOT_SUPPORTED 0x02
#define BLE_MESH_DIRECTED_PUB_POLICY_FLOODING 0x00
#define BLE_MESH_DIRECTED_PUB_POLICY_FORWARD 0x01
#define BLE_MESH_PROXY_USE_DIRECTED_DISABLED 0x00
#define BLE_MESH_PROXY_USE_DIRECTED_ENABLED 0x01
#define BLE_MESH_FLOODING_CRED 0x00
#define BLE_MESH_FRIENDSHIP_CRED 0x01
#define BLE_MESH_DIRECTED_CRED 0x02
/* Features */
#define BLE_MESH_FEAT_RELAY BIT(0)
#define BLE_MESH_FEAT_PROXY BIT(1)
@ -482,7 +574,7 @@ int bt_mesh_deinit(struct bt_mesh_deinit_param *param);
/** @brief Reset the state of the local Mesh node.
*
* Resets the state of the node, which means that it needs to be
* reprovisioned to become an active node in a Mesh network again.
* re-provisioned to become an active node in a Mesh network again.
*
* After calling this API, the node will not automatically advertise as
* unprovisioned, rather the bt_mesh_prov_enable() API needs to be called

View File

@ -466,6 +466,10 @@ struct bt_mesh_uuid_128 {
*/
#define BLE_MESH_UUID_MESH_PROXY_DATA_OUT BLE_MESH_UUID_DECLARE_16(0x2ade)
#define BLE_MESH_UUID_MESH_PROXY_DATA_OUT_VAL 0x2ade
/** @def BLE_MESH_UUID_MESH_PROXY_SOLIC_VAL
* @brief Mesh Proxy Solicitation UUID
*/
#define BLE_MESH_UUID_MESH_PROXY_SOLIC_VAL 0x7fcb
/*
* Protocol UUIDs

View File

@ -35,9 +35,9 @@ static struct bt_mesh_model *find_model(uint16_t elem_addr, uint16_t cid, uint16
if (cid == BLE_MESH_CID_NVAL) {
return bt_mesh_model_find(elem, mod_id);
} else {
return bt_mesh_model_find_vnd(elem, cid, mod_id);
}
return bt_mesh_model_find_vnd(elem, cid, mod_id);
}
int bt_mesh_model_subscribe_group_addr(uint16_t elem_addr, uint16_t cid,
@ -120,6 +120,36 @@ int bt_mesh_model_unsubscribe_group_addr(uint16_t elem_addr, uint16_t cid,
return 0;
}
#if CONFIG_BLE_MESH_DF_SRV
int bt_mesh_enable_directed_forwarding(uint16_t net_idx, bool directed_forwarding,
bool directed_forwarding_relay)
{
struct bt_mesh_subnet *sub = NULL;
if (net_idx > 0xFFF) {
BT_ERR("Invalid NetKeyIndex 0x%04x", net_idx);
return -EINVAL;
}
sub = bt_mesh_subnet_get(net_idx);
if (!sub) {
BT_ERR("NetKey 0x%04x not exists", net_idx);
return -EINVAL;
}
if (directed_forwarding == BLE_MESH_DIRECTED_FORWARDING_DISABLED &&
directed_forwarding_relay == BLE_MESH_DIRECTED_RELAY_ENABLED) {
BT_ERR("Invalid Config directed forwarding: %d, directed forwarding relay: %d", directed_forwarding, directed_forwarding_relay);
return -EINVAL;
}
sub->directed_forwarding = directed_forwarding;
sub->directed_relay = directed_forwarding_relay;
return 0;
}
#endif
#if CONFIG_BLE_MESH_NODE
const uint8_t *bt_mesh_node_get_local_net_key(uint16_t net_idx)
@ -149,7 +179,7 @@ const uint8_t *bt_mesh_node_get_local_app_key(uint16_t app_idx)
return NULL;
}
key = bt_mesh_app_key_find(app_idx);
key = bt_mesh_app_key_get(app_idx);
if (!key) {
BT_ERR("AppKey 0x%04x not exists", app_idx);
return NULL;
@ -225,7 +255,7 @@ int bt_mesh_node_local_net_key_add(uint16_t net_idx, const uint8_t net_key[16])
}
/* Make sure we have valid beacon data to be sent */
bt_mesh_net_beacon_update(sub);
bt_mesh_net_secure_beacon_update(sub);
return 0;
}
@ -250,7 +280,7 @@ int bt_mesh_node_local_app_key_add(uint16_t net_idx, uint16_t app_idx,
return -EIO;
}
key = bt_mesh_app_key_find(app_idx);
key = bt_mesh_app_key_get(app_idx);
if (key) {
BT_WARN("AppKey 0x%04x already exists", app_idx);
return -EEXIST;
@ -312,7 +342,7 @@ int bt_mesh_node_bind_app_key_to_model(uint16_t elem_addr, uint16_t mod_id,
return -ENODEV;
}
if (bt_mesh_app_key_find(app_idx) == NULL) {
if (bt_mesh_app_key_get(app_idx) == NULL) {
BT_ERR("Bind, AppKey 0x%03x not exists", app_idx);
return -ENODEV;
}

View File

@ -34,6 +34,11 @@ int bt_mesh_node_local_app_key_add(uint16_t net_idx, uint16_t app_idx,
int bt_mesh_node_bind_app_key_to_model(uint16_t elem_addr, uint16_t mod_id,
uint16_t cid, uint16_t app_idx);
#if CONFIG_BLE_MESH_DF_SRV
int bt_mesh_enable_directed_forwarding(uint16_t net_idx, bool directed_forwarding,
bool directed_forwarding_relay);
#endif
#ifdef __cplusplus
}
#endif

View File

@ -17,13 +17,16 @@
#include "access.h"
#include "beacon.h"
#include "lpn.h"
#include "rpl.h"
#include "foundation.h"
#include "mesh/main.h"
#include "mesh/cfg_srv.h"
#include "mesh_v1.1/utils.h"
#ifdef CONFIG_BLE_MESH_LOW_POWER
#if defined(CONFIG_BLE_MESH_LPN_AUTO)
#if CONFIG_BLE_MESH_LPN_AUTO
#define LPN_AUTO_TIMEOUT K_SECONDS(CONFIG_BLE_MESH_LPN_AUTO_TIMEOUT)
#else
#define LPN_AUTO_TIMEOUT 0
@ -184,6 +187,9 @@ static int send_friend_clear(void)
.app_idx = BLE_MESH_KEY_UNUSED,
.addr = bt_mesh.lpn.frnd,
.send_ttl = 0,
.send_cred = BLE_MESH_FLOODING_CRED,
/* Tag with immutable-credentials */
.send_tag = BLE_MESH_TAG_IMMUTABLE_CRED,
};
struct bt_mesh_net_tx tx = {
.sub = &bt_mesh.sub[0],
@ -196,8 +202,6 @@ static int send_friend_clear(void)
.lpn_counter = sys_cpu_to_be16(bt_mesh.lpn.counter),
};
BT_DBG("%s", __func__);
return bt_mesh_ctl_send(&tx, TRANS_CTL_OP_FRIEND_CLEAR, &req,
sizeof(req), &clear_sent_cb, NULL);
}
@ -216,7 +220,8 @@ static void clear_friendship(bool force, bool disable)
return;
}
bt_mesh_rx_reset(true);
bt_mesh_rx_reset();
bt_mesh_rpl_reset(true);
k_delayed_work_cancel(&lpn->timer);
@ -307,6 +312,9 @@ static int send_friend_req(struct bt_mesh_lpn *lpn)
.app_idx = BLE_MESH_KEY_UNUSED,
.addr = BLE_MESH_ADDR_FRIENDS,
.send_ttl = 0,
.send_cred = BLE_MESH_FLOODING_CRED,
/* Tag with immutable-credentials and as a friendship PDU */
.send_tag = BLE_MESH_TAG_IMMUTABLE_CRED | BLE_MESH_TAG_FRIENDSHIP,
};
struct bt_mesh_net_tx tx = {
.sub = &bt_mesh.sub[0],
@ -323,8 +331,6 @@ static int send_friend_req(struct bt_mesh_lpn *lpn)
.lpn_counter = sys_cpu_to_be16(lpn->counter),
};
BT_DBG("%s", __func__);
return bt_mesh_ctl_send(&tx, TRANS_CTL_OP_FRIEND_REQ, &req,
sizeof(req), &friend_req_sent_cb, NULL);
}
@ -348,7 +354,7 @@ static void req_sent(uint16_t duration, int err, void *user_data)
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
/* We start scanning a bit early to eliminate risk of missing
* response data due to HCI and other latencies.
*/
k_delayed_work_submit(&lpn->timer,
@ -378,13 +384,15 @@ static int send_friend_poll(void)
.app_idx = BLE_MESH_KEY_UNUSED,
.addr = bt_mesh.lpn.frnd,
.send_ttl = 0,
.send_cred = BLE_MESH_FRIENDSHIP_CRED,
/* Tag with immutable-credentials and as a friendship PDU */
.send_tag = BLE_MESH_TAG_IMMUTABLE_CRED | BLE_MESH_TAG_FRIENDSHIP,
};
struct bt_mesh_net_tx tx = {
.sub = &bt_mesh.sub[0],
.ctx = &ctx,
.src = bt_mesh_primary_addr(),
.xmit = POLL_XMIT,
.friend_cred = true,
};
struct bt_mesh_lpn *lpn = &bt_mesh.lpn;
uint8_t fsn = lpn->fsn;
@ -664,13 +672,15 @@ static bool sub_update(uint8_t op)
.app_idx = BLE_MESH_KEY_UNUSED,
.addr = lpn->frnd,
.send_ttl = 0,
.send_cred = BLE_MESH_FRIENDSHIP_CRED,
/* Tag with immutable-credentials and as a friendship PDU */
.send_tag = BLE_MESH_TAG_IMMUTABLE_CRED | BLE_MESH_TAG_FRIENDSHIP,
};
struct bt_mesh_net_tx tx = {
.sub = &bt_mesh.sub[0],
.ctx = &ctx,
.src = bt_mesh_primary_addr(),
.xmit = POLL_XMIT,
.friend_cred = true,
};
struct bt_mesh_ctl_friend_sub req = {0};
size_t i = 0U, g = 0U;
@ -988,7 +998,7 @@ int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx,
* credentials so we need to ensure the right ones (Friend
* Credentials) were used for this message.
*/
if (!rx->friend_cred) {
if (rx->ctx.recv_cred != BLE_MESH_FRIENDSHIP_CRED) {
BT_WARN("Friend Update with wrong credentials");
return -EINVAL;
}
@ -1008,6 +1018,17 @@ int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx,
/* Set initial poll timeout */
lpn->poll_timeout = MIN(POLL_TIMEOUT_MAX(lpn),
POLL_TIMEOUT_INIT);
/* If the Low Power node supports directed forwarding functionality when
* the friendship is established in a subnet, the Low Power node shall
* store the current value of the Directed Forwarding state and shall set
* the state to 0x00 for that subnet. When that friendship is terminated,
* the Low Power node shall set the Directed Forwarding state to the stored
* value.
*/
/* TODO:
* Store - clear - restore directed forwarding state value of the subnet.
*/
}
friend_response_received(lpn);
@ -1019,7 +1040,7 @@ int bt_mesh_lpn_friend_update(struct bt_mesh_net_rx *rx,
if (bt_mesh_kr_update(sub, BLE_MESH_KEY_REFRESH(msg->flags),
rx->new_key)) {
bt_mesh_net_beacon_update(sub);
bt_mesh_net_secure_beacon_update(sub);
}
bt_mesh_net_iv_update(iv_index, BLE_MESH_IV_UPDATE(msg->flags));
@ -1065,8 +1086,6 @@ int bt_mesh_lpn_init(void)
{
struct bt_mesh_lpn *lpn = &bt_mesh.lpn;
BT_DBG("%s", __func__);
k_delayed_work_init(&lpn->timer, lpn_timeout);
if (lpn->state == BLE_MESH_LPN_ENABLED) {

View File

@ -26,7 +26,7 @@ int bt_mesh_lpn_friend_sub_cfm(struct bt_mesh_net_rx *rx,
static inline bool bt_mesh_lpn_established(void)
{
#if defined(CONFIG_BLE_MESH_LOW_POWER)
#if CONFIG_BLE_MESH_LOW_POWER
return bt_mesh.lpn.established;
#else
return false;
@ -35,7 +35,7 @@ static inline bool bt_mesh_lpn_established(void)
static inline bool bt_mesh_lpn_match(uint16_t addr)
{
#if defined(CONFIG_BLE_MESH_LOW_POWER)
#if CONFIG_BLE_MESH_LOW_POWER
if (bt_mesh_lpn_established()) {
return (addr == bt_mesh.lpn.frnd);
}
@ -45,7 +45,7 @@ static inline bool bt_mesh_lpn_match(uint16_t addr)
static inline bool bt_mesh_lpn_waiting_update(void)
{
#if defined(CONFIG_BLE_MESH_LOW_POWER)
#if CONFIG_BLE_MESH_LOW_POWER
return (bt_mesh.lpn.state == BLE_MESH_LPN_WAIT_UPDATE);
#else
return false;
@ -54,7 +54,7 @@ static inline bool bt_mesh_lpn_waiting_update(void)
static inline bool bt_mesh_lpn_timer(void)
{
#if defined(CONFIG_BLE_MESH_LPN_AUTO)
#if CONFIG_BLE_MESH_LPN_AUTO
return (bt_mesh.lpn.state == BLE_MESH_LPN_TIMER);
#else
return false;

View File

@ -12,9 +12,9 @@
#include "adv.h"
#include "scan.h"
#include "prov_node.h"
#include "beacon.h"
#include "lpn.h"
#include "rpl.h"
#include "friend.h"
#include "transport.h"
#include "access.h"
@ -25,9 +25,13 @@
#include "mesh/common.h"
#include "proxy_client.h"
#include "proxy_server.h"
#include "prov_common.h"
#include "prov_node.h"
#include "prov_pvnr.h"
#include "pvnr_mgmt.h"
#include "mesh_v1.1/utils.h"
static bool mesh_init = false;
bool bt_mesh_is_initialized(void)
@ -45,9 +49,11 @@ int bt_mesh_provision(const uint8_t net_key[16], uint16_t net_idx,
BT_INFO("Primary Element: 0x%04x", addr);
BT_INFO("net_idx 0x%04x flags 0x%02x iv_index 0x%04x",
net_idx, flags, iv_index);
BT_INFO("dev_key %s", bt_hex(dev_key, 16));
BT_INFO("DevKey %s", bt_hex(dev_key, 16));
BT_INFO("NetKey %s", bt_hex(net_key, 16));
if (bt_mesh_atomic_test_and_set_bit(bt_mesh.flags, BLE_MESH_VALID)) {
BT_ERR("Already enter network!");
return -EALREADY;
}
@ -63,6 +69,7 @@ int bt_mesh_provision(const uint8_t net_key[16], uint16_t net_idx,
err = bt_mesh_net_create(net_idx, flags, net_key, iv_index);
if (err) {
BT_ERR("Create network for node failed");
bt_mesh_atomic_clear_bit(bt_mesh.flags, BLE_MESH_VALID);
if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) && pb_gatt_enabled) {
@ -111,8 +118,9 @@ void bt_mesh_node_reset(void)
bt_mesh_cfg_reset(true);
bt_mesh_rx_reset(true);
bt_mesh_rx_reset();
bt_mesh_tx_reset();
bt_mesh_rpl_reset(true);
if (IS_ENABLED(CONFIG_BLE_MESH_LOW_POWER)) {
if (IS_ENABLED(CONFIG_BLE_MESH_LPN_SUB_ALL_NODES_ADDR)) {
@ -135,14 +143,22 @@ void bt_mesh_node_reset(void)
(void)memset(bt_mesh.dev_key, 0, sizeof(bt_mesh.dev_key));
bt_mesh_scan_disable();
bt_mesh_beacon_disable();
bt_mesh_secure_beacon_disable();
#if CONFIG_BLE_MESH_PRB_SRV
bt_mesh_private_beacon_disable();
#endif
bt_mesh_comp_unprovision();
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
bt_mesh_clear_net();
bt_mesh_clear_seq();
bt_mesh_clear_dkca();
bt_mesh_clear_role();
if (IS_ENABLED(CONFIG_BLE_MESH_DF_SRV)) {
bt_mesh_clear_all_directed_forwarding_table_data();
}
}
memset(bt_mesh.flags, 0, sizeof(bt_mesh.flags));
@ -175,9 +191,9 @@ bool bt_mesh_is_provisioner_en(void)
{
if (bt_mesh_is_provisioner()) {
return bt_mesh_atomic_test_bit(bt_mesh.flags, BLE_MESH_VALID_PROV);
} else {
return false;
}
return false;
}
static bool prov_bearers_valid(bt_mesh_prov_bearer_t bearers)
@ -240,7 +256,7 @@ int bt_mesh_prov_enable(bt_mesh_prov_bearer_t bearers)
}
/* Enable unprovisioned beacon sending */
bt_mesh_beacon_enable();
bt_mesh_secure_beacon_enable();
}
if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) &&
@ -271,7 +287,7 @@ int bt_mesh_prov_disable(bt_mesh_prov_bearer_t bearers)
if (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) &&
(bearers & BLE_MESH_PROV_ADV)) {
bt_mesh_beacon_disable();
bt_mesh_secure_beacon_disable();
bt_mesh_scan_disable();
}
@ -313,10 +329,16 @@ int bt_mesh_suspend(void)
bt_mesh_hb_pub_disable();
if (bt_mesh_beacon_get() == BLE_MESH_BEACON_ENABLED) {
bt_mesh_beacon_disable();
if (bt_mesh_secure_beacon_get() == BLE_MESH_SECURE_BEACON_ENABLED) {
bt_mesh_secure_beacon_disable();
}
#if CONFIG_BLE_MESH_PRB_SRV
if (bt_mesh_private_beacon_state_get() == BLE_MESH_PRIVATE_BEACON_ENABLED) {
bt_mesh_private_beacon_disable();
}
#endif
bt_mesh_model_foreach(model_suspend, NULL);
return 0;
@ -353,10 +375,16 @@ int bt_mesh_resume(void)
return err;
}
if (bt_mesh_beacon_get() == BLE_MESH_BEACON_ENABLED) {
bt_mesh_beacon_enable();
if (bt_mesh_secure_beacon_get() == BLE_MESH_SECURE_BEACON_ENABLED) {
bt_mesh_secure_beacon_enable();
}
#if CONFIG_BLE_MESH_PRB_SRV
if (bt_mesh_private_beacon_state_get() == BLE_MESH_PRIVATE_BEACON_ENABLED) {
bt_mesh_private_beacon_enable();
}
#endif
bt_mesh_model_foreach(model_resume, NULL);
return err;
@ -372,6 +400,13 @@ int bt_mesh_init(const struct bt_mesh_prov *prov,
return -EALREADY;
}
extern int bt_mesh_v11_ext_init(void);
err = bt_mesh_v11_ext_init();
if (err) {
BT_ERR("Bluetooth Mesh v1.1 init failed");
return err;
}
bt_mesh_mutex_init();
bt_mesh_timer_init();
@ -401,15 +436,28 @@ int bt_mesh_init(const struct bt_mesh_prov *prov,
bt_mesh_proxy_client_init();
}
#if CONFIG_BLE_MESH_PROXY_SOLIC
err = bt_mesh_proxy_solic_init();
if (err) {
return err;
}
#endif
if (IS_ENABLED(CONFIG_BLE_MESH_PROV)) {
err = bt_mesh_prov_set(prov);
if (err) {
return err;
}
if (IS_ENABLED(CONFIG_BLE_MESH_NODE)) {
err = bt_mesh_prov_init(prov);
err = bt_mesh_prov_init();
if (err) {
return err;
}
}
if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER)) {
err = bt_mesh_provisioner_prov_init(prov);
err = bt_mesh_provisioner_prov_init();
if (err) {
return err;
}
@ -417,6 +465,7 @@ int bt_mesh_init(const struct bt_mesh_prov *prov,
}
bt_mesh_net_init();
bt_mesh_trans_init();
/* Changed by Espressif, add a random delay (0 ~ 3s) */
@ -458,7 +507,11 @@ int bt_mesh_deinit(struct bt_mesh_deinit_param *param)
}
bt_mesh_scan_disable();
bt_mesh_beacon_disable();
bt_mesh_secure_beacon_disable();
#if CONFIG_BLE_MESH_PRB_SRV
bt_mesh_private_beacon_disable();
#endif
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node()) {
if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) &&
@ -507,13 +560,20 @@ int bt_mesh_deinit(struct bt_mesh_deinit_param *param)
return err;
}
}
bt_mesh_prov_set(NULL);
}
bt_mesh_trans_deinit(param->erase);
bt_mesh_net_deinit();
bt_mesh_beacon_deinit();
#if CONFIG_BLE_MESH_PROXY_SOLIC
bt_mesh_proxy_solic_deinit();
#endif
if ((IS_ENABLED(CONFIG_BLE_MESH_NODE) &&
IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) ||
IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_SERVER)) {
@ -560,7 +620,7 @@ int bt_mesh_deinit(struct bt_mesh_deinit_param *param)
}
#endif /* CONFIG_BLE_MESH_DEINIT */
#if defined(CONFIG_BLE_MESH_PROVISIONER)
#if CONFIG_BLE_MESH_PROVISIONER
int bt_mesh_provisioner_enable(bt_mesh_prov_bearer_t bearers)
{
int err = 0;
@ -616,17 +676,19 @@ int bt_mesh_provisioner_enable(bt_mesh_prov_bearer_t bearers)
bt_mesh_comp_provision(bt_mesh_provisioner_get_primary_elem_addr());
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
#if 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_SUB_CODE_ADD,
BLE_MESH_EXCEP_LIST_TYPE_MESH_BEACON, NULL);
BLE_MESH_EXCEP_LIST_TYPE_MESH_BEACON,
NULL);
}
if (IS_ENABLED(CONFIG_BLE_MESH_PB_GATT) &&
(bearers & BLE_MESH_PROV_GATT)) {
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_SUB_CODE_ADD,
BLE_MESH_EXCEP_LIST_TYPE_MESH_PROV_ADV, NULL);
BLE_MESH_EXCEP_LIST_TYPE_MESH_PROV_ADV,
NULL);
}
#endif
@ -639,10 +701,16 @@ int bt_mesh_provisioner_enable(bt_mesh_prov_bearer_t bearers)
bt_mesh_friend_init();
}
if (bt_mesh_beacon_get() == BLE_MESH_BEACON_ENABLED) {
bt_mesh_beacon_enable();
if (bt_mesh_secure_beacon_get() == BLE_MESH_SECURE_BEACON_ENABLED) {
bt_mesh_secure_beacon_enable();
}
#if CONFIG_BLE_MESH_PRB_SRV
if (bt_mesh_private_beacon_state_get() == BLE_MESH_PRIVATE_BEACON_ENABLED) {
bt_mesh_private_beacon_enable();
}
#endif
err = bt_mesh_scan_enable();
if (err) {
return err;
@ -676,9 +744,11 @@ int bt_mesh_provisioner_disable(bt_mesh_prov_bearer_t bearers)
(enable & BLE_MESH_PROV_GATT) &&
(bearers & BLE_MESH_PROV_GATT)) {
bt_mesh_proxy_client_prov_disable();
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
#if CONFIG_BLE_MESH_USE_DUPLICATE_SCAN
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_SUB_CODE_REMOVE,
BLE_MESH_EXCEP_LIST_TYPE_MESH_PROV_ADV, NULL);
BLE_MESH_EXCEP_LIST_TYPE_MESH_PROV_ADV,
NULL);
#endif
}
@ -686,11 +756,12 @@ int bt_mesh_provisioner_disable(bt_mesh_prov_bearer_t bearers)
/* Provisioner is disabled completely, disable scan here */
bt_mesh_scan_disable();
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
#if CONFIG_BLE_MESH_USE_DUPLICATE_SCAN
if (IS_ENABLED(CONFIG_BLE_MESH_PB_ADV) &&
(enable & BLE_MESH_PROV_ADV)) {
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_SUB_CODE_REMOVE,
BLE_MESH_EXCEP_LIST_TYPE_MESH_BEACON, NULL);
BLE_MESH_EXCEP_LIST_TYPE_MESH_BEACON,
NULL);
}
#endif
@ -702,10 +773,16 @@ int bt_mesh_provisioner_disable(bt_mesh_prov_bearer_t bearers)
* its previous information can be recovered from flash properly.
*/
if (bt_mesh_beacon_get() == BLE_MESH_BEACON_ENABLED) {
bt_mesh_beacon_disable();
if (bt_mesh_secure_beacon_get() == BLE_MESH_SECURE_BEACON_ENABLED) {
bt_mesh_secure_beacon_disable();
}
#if CONFIG_BLE_MESH_PRB_SRV
if (bt_mesh_private_beacon_state_get() == BLE_MESH_PRIVATE_BEACON_ENABLED) {
bt_mesh_private_beacon_disable();
}
#endif
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
bt_mesh_friend_clear_net_idx(BLE_MESH_KEY_ANY);
}

View File

@ -17,12 +17,18 @@ extern "C" {
#endif
#define BLE_MESH_KEY_PRIMARY 0x0000
#define BLE_MESH_KEY_ANY 0xffff
#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)
#define BLE_MESH_ADDR_IS_VIRTUAL(addr) ((addr) >= 0x8000 && (addr) < 0xC000)
#define BLE_MESH_ADDR_IS_GROUP(addr) ((addr) >= 0xC000 && (addr) < 0xFF00)
/* Currently not including all-ipt-nodes & all-ipt-border-routers in RFU & fixed group */
#define BLE_MESH_ADDR_IS_RFU(addr) ((addr) >= 0xFF00 && (addr) <= 0xFFFA)
#define BLE_MESH_ADDR_IS_FIXED_GROUP(addr) ((addr) >= 0xFFFB && ((addr) < 0xFFFF || (addr) == 0xFFFF))
#define BLE_MESH_SUPPORTING_TYPE_FRIEND 1
#define BLE_MESH_SUPPORTING_TYPE_PROXY 2
#define BLE_MESH_SUPPORTING_TYPE_SBR 3
struct bt_mesh_net;

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,7 @@
#define _NET_H_
#include "mesh/access.h"
#include "mesh/mutex.h"
#ifdef __cplusplus
extern "C" {
@ -43,14 +44,31 @@ struct bt_mesh_app_key {
};
struct bt_mesh_subnet {
uint32_t beacon_sent; /* Timestamp of last sent beacon */
uint8_t beacons_last; /* Number of beacons during last observation window. */
uint8_t beacons_cur; /* Number of beacons observed during currently ongoing window. */
uint32_t snb_sent; /* Timestamp of last sent secure network beacon */
uint8_t snb_last; /* Number of secure network beacons during last observation window */
uint8_t snb_cur; /* Number of secure network beacons observed during currently ongoing window.*/
uint8_t snb_cache[21]; /* Cached last receive authenticated secure beacon */
uint8_t beacon_cache[21]; /* Cached last authenticated beacon */
#if CONFIG_BLE_MESH_PRIVATE_BEACON
uint32_t mpb_sent; /* Timestamp of last sent private beacon */
uint8_t mpb_last; /* Number of private beacons during last observation window */
uint8_t mpb_cur; /* Number of private beacons observed during currently ongoing window. */
uint8_t mpb_cache[21]; /* Cached last receive private beacon (Random + Authentication Tag) */
uint8_t mpb_flags_last; /* Flags of last sent private beacon */
uint8_t mpb_ivi_last: 1; /* IV Index of last sent private beacon */
uint8_t mpb_random[13]; /* Random of current private beacon */
uint8_t mpb_random_last[13]; /* Random of last sent private beacon */
uint8_t private_node_id; /* Private Node Identity State */
#endif /* CONFIG_BLE_MESH_PRIVATE_BEACON */
uint16_t net_idx; /* NetKeyIndex */
#if CONFIG_BLE_MESH_BRC_SRV
uint16_t sbr_net_idx; /* NetKeyIndex of bridged subnet */
#endif
bool kr_flag; /* Key Refresh Flag */
uint8_t kr_phase; /* Key Refresh Phase */
@ -64,24 +82,93 @@ struct bt_mesh_subnet {
uint8_t nid; /* NID */
uint8_t enc[16]; /* EncKey */
uint8_t net_id[8]; /* Network ID */
#if defined(CONFIG_BLE_MESH_GATT_PROXY_SERVER)
#if CONFIG_BLE_MESH_GATT_PROXY_SERVER
uint8_t identity[16]; /* IdentityKey */
#endif
#endif /* CONFIG_BLE_MESH_GATT_PROXY_SERVER */
uint8_t privacy[16]; /* PrivacyKey */
uint8_t beacon[16]; /* BeaconKey */
#if CONFIG_BLE_MESH_PRIVATE_BEACON
uint8_t private_beacon[16]; /* Private BeaconKey */
#endif /* CONFIG_BLE_MESH_PRIVATE_BEACON */
#if CONFIG_BLE_MESH_DF_SRV
uint8_t direct_nid; /* Directed NID */
uint8_t direct_enc[16]; /* Directed EncKey */
uint8_t direct_privacy[16]; /* Directed PrivacyKey */
#endif /* CONFIG_BLE_MESH_DF_SRV */
} keys[2];
/* Indicate if proxy privacy is enabled (i.e. sending Mesh Private Beacons
* or Secure Network Beacons) to proxy client.
*
* Note: in Mesh Spec, it describes as "the Proxy Privacy parameter for the
* connection". Here we put the parameter in the subnet, since when sending
* mesh beacon, and for the existing subnets, proxy server should send mesh
* beacon for each of the subnets.
*/
uint8_t proxy_privacy;
#if CONFIG_BLE_MESH_DF_SRV
uint8_t directed_forwarding;
uint8_t directed_relay; /* Binding with Directed Forwarding state */
uint8_t directed_proxy; /* Binding with Directed Forwarding state & GATT Proxy state */
uint8_t directed_proxy_use_default; /* Binding with Directed Proxy state */
uint8_t directed_friend;
uint8_t use_directed;
struct {
uint16_t len_present:1,
range_start:15;
uint8_t range_length;
} proxy_client_uar;
uint8_t path_metric_type:3,
path_lifetime_type:2,
two_way_path:1;
uint8_t forward_number;
/* The Discovery Table initially is empty. A Path Origin updates
* its Discovery Table when a Directed Forwarding Initialization
* procedure is executed. A Path Target or a Directed Relay node
* updates its Discovery Table when a PATH_REQUEST message is
* received and processed.
*/
struct bt_mesh_discovery_table {
uint8_t max_disc_entries;
uint8_t max_concurr_init; /* default is 0x02 */
uint8_t concurr_init;
bt_mesh_mutex_t mutex;
sys_slist_t entries;
} discovery_table;
struct bt_mesh_forward_table {
uint8_t max_ford_entries;
uint8_t max_deps_nodes;
uint16_t update_id;
bt_mesh_mutex_t mutex;
sys_slist_t entries;
} forward_table;
uint8_t wanted_lanes;
uint8_t unicast_echo_interval;
uint8_t multicast_echo_interval;
#endif /* CONFIG_BLE_MESH_DF_SRV */
};
struct bt_mesh_rpl {
uint16_t src;
bool old_iv;
#if defined(CONFIG_BLE_MESH_SETTINGS)
#if CONFIG_BLE_MESH_SETTINGS
bool store;
#endif
uint32_t seq;
};
#if defined(CONFIG_BLE_MESH_FRIEND)
#if 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
@ -133,7 +220,7 @@ struct bt_mesh_friend {
} clear;
};
#if defined(CONFIG_BLE_MESH_LOW_POWER)
#if CONFIG_BLE_MESH_LOW_POWER
#define LPN_GROUPS CONFIG_BLE_MESH_LPN_GROUPS
#else
#define LPN_GROUPS 0
@ -141,7 +228,7 @@ struct bt_mesh_friend {
/* Low Power Node state */
struct bt_mesh_lpn {
enum __packed {
enum __attribute__((packed)) {
BLE_MESH_LPN_DISABLED, /* LPN feature is disabled */
BLE_MESH_LPN_CLEAR, /* Clear in progress */
BLE_MESH_LPN_TIMER, /* Waiting for auto timer expiry */
@ -236,15 +323,14 @@ struct bt_mesh_net {
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_BLE_MESH_FRIEND)
#if CONFIG_BLE_MESH_FRIEND
/* Friend state, unique for each LPN that we're Friends for */
struct bt_mesh_friend frnd[CONFIG_BLE_MESH_FRIEND_LPN_COUNT];
#endif
#if defined(CONFIG_BLE_MESH_LOW_POWER)
#if CONFIG_BLE_MESH_LOW_POWER
struct bt_mesh_lpn lpn; /* Low Power Node state */
#endif
@ -254,7 +340,8 @@ struct bt_mesh_net {
/* Timer to track duration in current IV Update state */
struct k_delayed_work ivu_timer;
uint8_t dev_key[16];
uint8_t dev_key[16]; /* Device Key */
uint8_t dev_key_ca[16]; /* Device Key Candidate */
struct bt_mesh_app_key app_keys[CONFIG_BLE_MESH_APP_KEY_COUNT];
@ -262,7 +349,7 @@ struct bt_mesh_net {
struct bt_mesh_rpl rpl[CONFIG_BLE_MESH_CRPL];
#if defined(CONFIG_BLE_MESH_PROVISIONER)
#if CONFIG_BLE_MESH_PROVISIONER
/* Application keys stored by provisioner */
struct bt_mesh_app_key *p_app_keys[CONFIG_BLE_MESH_PROVISIONER_APP_KEY_COUNT];
/* Next app_idx can be assigned */
@ -283,6 +370,12 @@ enum bt_mesh_net_if {
BLE_MESH_NET_IF_PROXY_CFG,
};
#define BLE_MESH_NONE_BEARER 0
#define BLE_MESH_ADV_BEARER BIT(0)
#define BLE_MESH_GATT_BEARER BIT(1)
#define BLE_MESH_LOCAL_BEARER BIT(2)
#define BLE_MESH_ALL_BEARERS (BLE_MESH_ADV_BEARER | BLE_MESH_GATT_BEARER)
/* Decoding context for Network/Transport data */
struct bt_mesh_net_rx {
struct bt_mesh_subnet *sub;
@ -290,7 +383,7 @@ struct bt_mesh_net_rx {
uint32_t seq; /* Sequence Number */
uint8_t old_iv:1, /* iv_index - 1 was used */
new_key:1, /* Data was encrypted with updated key */
friend_cred:1, /* Data was encrypted with friend cred */
friend_cred:1 __attribute__((deprecated)), /* Data was encrypted with friend cred */
ctl:1, /* Network Control */
net_if:2, /* Network interface */
local_match:1, /* Matched a local element */
@ -304,9 +397,9 @@ struct bt_mesh_net_tx {
struct bt_mesh_msg_ctx *ctx;
uint16_t src;
uint8_t xmit;
uint8_t friend_cred:1,
uint8_t friend_cred:1 __attribute__((deprecated)),
aszmic:1,
aid: 6;
aid:6;
};
extern struct bt_mesh_net bt_mesh;
@ -318,6 +411,14 @@ extern struct bt_mesh_net bt_mesh;
#define BLE_MESH_NET_HDR_LEN 9
#define BLE_MESH_NET_HDR_IVI(pdu) ((pdu)[0] >> 7)
#define BLE_MESH_NET_HDR_NID(pdu) ((pdu)[0] & 0x7F)
#define BLE_MESH_NET_HDR_CTL(pdu) ((pdu)[1] >> 7)
#define BLE_MESH_NET_HDR_TTL(pdu) ((pdu)[1] & 0x7F)
#define BLE_MESH_NET_HDR_SEQ(pdu) (sys_get_be24(&(pdu)[2]))
#define BLE_MESH_NET_HDR_SRC(pdu) (sys_get_be16(&(pdu)[5]))
#define BLE_MESH_NET_HDR_DST(pdu) (sys_get_be16(&(pdu)[7]))
void bt_mesh_msg_cache_clear(uint16_t unicast_addr, uint8_t elem_num);
int bt_mesh_net_keys_create(struct bt_mesh_subnet_keys *keys,
@ -332,9 +433,7 @@ bool bt_mesh_kr_update(struct bt_mesh_subnet *sub, uint8_t new_kr, bool new_key)
void bt_mesh_net_revoke_keys(struct bt_mesh_subnet *sub);
int bt_mesh_net_beacon_update(struct bt_mesh_subnet *sub);
void bt_mesh_rpl_reset(void);
int bt_mesh_net_secure_beacon_update(struct bt_mesh_subnet *sub);
bool bt_mesh_net_iv_update(uint32_t iv_index, bool iv_update);
@ -342,7 +441,7 @@ void bt_mesh_net_sec_update(struct bt_mesh_subnet *sub);
struct bt_mesh_subnet *bt_mesh_subnet_get(uint16_t net_idx);
struct bt_mesh_subnet *bt_mesh_subnet_find(const uint8_t net_id[8], uint8_t flags,
struct bt_mesh_subnet *bt_mesh_subnet_find_with_snb(const uint8_t net_id[8], uint8_t flags,
uint32_t iv_index, const uint8_t auth[8],
bool *new_key);
@ -353,8 +452,8 @@ int bt_mesh_net_send(struct bt_mesh_net_tx *tx, struct net_buf *buf,
const struct bt_mesh_send_cb *cb, void *cb_data);
int bt_mesh_net_resend(struct bt_mesh_subnet *sub, struct net_buf *buf,
bool new_key, const struct bt_mesh_send_cb *cb,
void *cb_data);
bool new_key, uint8_t *tx_cred, uint8_t tx_tag,
const struct bt_mesh_send_cb *cb, void *cb_data);
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);

View File

@ -70,7 +70,7 @@ static uint8_t bt_mesh_private_key[32];
/* Scan related functions */
static bt_mesh_scan_cb_t *bt_mesh_scan_dev_found_cb;
#if defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE
#if CONFIG_BLE_MESH_NODE
/* the gatt database list to save the attribute table */
static sys_slist_t bt_mesh_gatts_db;
@ -79,8 +79,7 @@ static struct bt_mesh_conn bt_mesh_gatts_conn[BLE_MESH_MAX_CONN];
static struct bt_mesh_conn_cb *bt_mesh_gatts_conn_cb;
static uint8_t bt_mesh_gatts_addr[6];
#endif /* defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE */
#endif /* CONFIG_BLE_MESH_NODE */
int bt_mesh_host_init(void)
{
@ -119,7 +118,6 @@ void bt_mesh_hci_init(void)
#else
bt_mesh_dev.hci_version = ble_hs_hci_get_hci_version();
#endif
return;
}
static struct ble_gap_disc_params scan_param;
@ -149,6 +147,7 @@ static int ble_on_subscribe(uint16_t conn_handle,
struct bt_mesh_conn *conn = NULL;
uint8_t value[2] = {0x01, 0x00};
int i = (int)arg, j, len;
MODLOG_DFLT(INFO, "Subscribe complete; status=%d conn_handle=%d "
"attr_handle=%d\n",
error->status, conn_handle, attr->handle);
@ -158,8 +157,8 @@ static int ble_on_subscribe(uint16_t conn_handle,
break;
}
}
if (j == ARRAY_SIZE(bt_mesh_gattc_info)) {
if (j == ARRAY_SIZE(bt_mesh_gattc_info)) {
conn = &bt_mesh_gattc_info[i].conn;
if (bt_mesh_gattc_info[i].ccc_handle != attr->handle) {
@ -190,7 +189,6 @@ static int ble_on_subscribe(uint16_t conn_handle,
}
}
return 0;
}
@ -248,7 +246,6 @@ static int dsc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
return rc;
}
static int chr_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
const struct ble_gatt_chr *chr, void *arg)
{
@ -257,9 +254,11 @@ static int chr_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
int i = (int)arg; /* service index */
struct bt_mesh_conn *conn = &bt_mesh_gattc_info[i].conn;
const ble_uuid_any_t *uuid = &chr->uuid;
if (chr) {
uuid16 = (uint16_t) BLE_UUID16(uuid)->value;
}
switch (error->status) {
case 0:
/* Get Mesh Provisioning/Proxy Data In/Out Characteristic */
@ -279,6 +278,7 @@ static int chr_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
bt_mesh_gattc_info[i].data_out_handle = chr->val_handle;
}
break;
case BLE_HS_EDONE:
/* All characteristics in this service discovered; start discovering
* characteristics in the next service.
@ -310,7 +310,6 @@ static int chr_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
return rc;
}
static int svc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
const struct ble_gatt_svc *service, void *arg)
{
@ -318,16 +317,19 @@ static int svc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
int rc = 0, i;
const ble_uuid_any_t *uuid;
uint8_t uuid_length;
switch (error->status) {
case 0:
if (!service) {
return 0;
}
uuid = &service->uuid;
uuid_length = (uint8_t) (uuid->u.type == BLE_UUID_TYPE_16 ? 2 : 16);
if (uuid_length != 2) {
return 0;
}
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (bt_mesh_gattc_info[i].service_uuid == (uint16_t)BLE_UUID16(uuid)->value) {
bt_mesh_gattc_info[i].start_handle = service->start_handle;
@ -335,8 +337,8 @@ static int svc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
break;
}
}
break;
case BLE_HS_EDONE:
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (bt_mesh_gattc_info[i].conn.handle == conn_handle) {
@ -348,6 +350,7 @@ static int svc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
BT_ERR("Conn handle 0x%04x not found", conn_handle);
return 0;
}
conn = &bt_mesh_gattc_info[i].conn;
if (bt_mesh_gattc_info[i].start_handle == 0x00 ||
bt_mesh_gattc_info[i].end_handle == 0x00 ||
@ -368,14 +371,11 @@ static int svc_disced(uint16_t conn_handle, const struct ble_gatt_error *error,
return rc;
}
#endif /* (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
static int disc_cb(struct ble_gap_event *event, void *arg)
{
struct ble_gap_disc_desc *desc;
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
int rc, i;
@ -394,7 +394,8 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
net_buf_simple_init_with_data(&buf, (void *)desc->data, desc->length_data);
if (bt_mesh_scan_dev_found_cb) {
bt_mesh_scan_dev_found_cb((bt_mesh_addr_t *)&desc->addr, desc->rssi, desc->event_type, &buf);
/* TODO: Support Scan Response data length for NimBLE host */
bt_mesh_scan_dev_found_cb((bt_mesh_addr_t *)&desc->addr, desc->rssi, desc->event_type, &buf, 0);
}
break;
}
@ -561,7 +562,6 @@ static int disc_cb(struct ble_gap_event *event, void *arg)
static int start_le_scan(uint8_t scan_type, uint16_t interval, uint16_t window, uint8_t filter_dup)
{
scan_param.filter_duplicates = filter_dup;
scan_param.itvl = interval;
scan_param.window = window;
@ -600,7 +600,7 @@ static int set_ad(const struct bt_mesh_adv_data *ad, size_t ad_len, uint8_t *buf
return 0;
}
#if defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE
#if CONFIG_BLE_MESH_NODE
static struct bt_mesh_gatt_attr *bt_mesh_gatts_find_attr_by_handle(uint16_t handle);
static int gap_event_cb(struct ble_gap_event *event, void *arg)
@ -713,7 +713,6 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg)
0 /* offset */, 0)) > 0) {
}
}
return 0;
case BLE_GAP_EVENT_MTU:
@ -747,12 +746,11 @@ static int gap_event_cb(struct ble_gap_event *event, void *arg)
return 0;
}
#else
static int gap_event_cb(struct ble_gap_event *event, void *arg)
{
return 0;
}
#endif
#endif /* CONFIG_BLE_MESH_NODE */
/* APIs functions */
int bt_le_adv_start(const struct bt_mesh_adv_param *param,
@ -986,8 +984,7 @@ int bt_le_update_white_list(struct bt_mesh_white_list *wl)
}
#endif
#if defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE
#if CONFIG_BLE_MESH_NODE
void bt_mesh_gatts_conn_cb_register(struct bt_mesh_conn_cb *cb)
{
bt_mesh_gatts_conn_cb = cb;
@ -1084,7 +1081,7 @@ struct gatts_incl {
uint16_t start_handle;
uint16_t end_handle;
uint16_t uuid16;
} __packed;
} __attribute__((packed));
ssize_t bt_mesh_gatts_attr_read_included(struct bt_mesh_conn *conn,
const struct bt_mesh_gatt_attr *attr,
@ -1134,7 +1131,7 @@ struct gatts_chrc {
uint16_t uuid16;
uint8_t uuid[16];
};
} __packed;
} __attribute__((packed));
ssize_t bt_mesh_gatts_attr_read_chrc(struct bt_mesh_conn *conn,
const struct bt_mesh_gatt_attr *attr,
@ -1268,11 +1265,13 @@ int bt_mesh_gatts_service_stop(struct bt_mesh_gatt_service *svc)
{
int rc;
uint16_t handle;
const ble_uuid_t *uuid;
if (!svc) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
}
const ble_uuid_t *uuid;
if (BLE_MESH_UUID_16(svc->attrs[0].user_data)->val == BT_UUID_MESH_PROXY_VAL) {
uuid = BLE_UUID16_DECLARE(BT_UUID_MESH_PROXY_VAL);
} else {
@ -1294,6 +1293,7 @@ int bt_mesh_gatts_service_start(struct bt_mesh_gatt_service *svc)
int rc;
uint16_t handle;
const ble_uuid_t *uuid;
if (BLE_MESH_UUID_16(svc->attrs[0].user_data)->val == BT_UUID_MESH_PROXY_VAL) {
uuid = BLE_UUID16_DECLARE(BT_UUID_MESH_PROXY_VAL);
} else {
@ -1314,7 +1314,7 @@ int bt_mesh_gatts_set_local_device_name(const char *name)
{
return ble_svc_gap_device_name_set(name);
}
#endif /* defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE */
#endif /* CONFIG_BLE_MESH_NODE */
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
@ -1438,7 +1438,6 @@ int bt_mesh_gattc_conn_create(const bt_mesh_addr_t *addr, uint16_t service_uuid)
conn_params.min_ce_len = BLE_GAP_INITIAL_CONN_MIN_CE_LEN;
conn_params.max_ce_len = BLE_GAP_INITIAL_CONN_MAX_CE_LEN;
ble_addr_t peer_addr;
memcpy(peer_addr.val, addr->val, 6);
peer_addr.type = addr->type;
@ -1452,8 +1451,8 @@ static int mtu_cb(uint16_t conn_handle,
uint16_t mtu, void *arg)
{
int i;
if (error->status == 0) {
if (error->status == 0) {
for (i = 0; i < ARRAY_SIZE(bt_mesh_gattc_info); i++) {
if (bt_mesh_gattc_info[i].conn.handle == conn_handle) {
bt_mesh_gattc_info[i].mtu = mtu;
@ -1461,11 +1460,10 @@ static int mtu_cb(uint16_t conn_handle,
}
}
}
return 0;
}
void bt_mesh_gattc_exchange_mtu(uint8_t index)
{
/** Set local MTU and exchange with GATT server.
@ -1549,6 +1547,7 @@ void bt_mesh_gattc_disconnect(struct bt_mesh_conn *conn)
BT_ERR("Conn %p not found", conn);
return;
}
ble_gap_terminate(bt_mesh_gattc_info[i].conn.handle, BLE_ERR_REM_USER_CONN_TERM);
}
@ -1577,7 +1576,7 @@ void bt_mesh_conn_unref(struct bt_mesh_conn *conn)
BT_DBG("handle %u ref %u", conn->handle, bt_mesh_atomic_get(&conn->ref));
}
#if defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE
#if CONFIG_BLE_MESH_NODE
static int proxy_char_access_cb(uint16_t conn_handle, uint16_t attr_handle,
struct ble_gatt_access_ctxt *ctxt, void *arg)
{
@ -1660,10 +1659,10 @@ static const struct ble_gatt_svc_def svc_defs [] = {
0, /* No more services. */
},
};
#endif
#endif /* CONFIG_BLE_MESH_NODE */
void gatt_register_cb(struct ble_gatt_register_ctxt *ctxt,
void *arg )
void *arg)
{
if (ctxt->op == BLE_GATT_REGISTER_OP_SVC) {
if (ble_uuid_cmp(ctxt->svc.svc_def->uuid, BLE_UUID16_DECLARE(BT_UUID_MESH_PROXY_VAL)) == 0) {
@ -1680,7 +1679,7 @@ void bt_mesh_gatt_init(void)
ble_hs_cfg.gatts_register_cb = gatt_register_cb;
#if defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE
#if CONFIG_BLE_MESH_NODE
static bool init = false;
int rc;
@ -1701,7 +1700,7 @@ void bt_mesh_gatt_init(void)
init = true;
}
#endif
#endif /* CONFIG_BLE_MESH_NODE */
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
@ -1743,8 +1742,6 @@ void ble_sm_alg_ecc_init(void);
void bt_mesh_adapt_init(void)
{
BT_DBG("%s", __func__);
/* initialization of P-256 parameters */
ble_sm_alg_ecc_init();
@ -1838,18 +1835,12 @@ exit:
int ble_sm_alg_gen_dhkey(uint8_t *peer_pub_key_x, uint8_t *peer_pub_key_y,
uint8_t *our_priv_key, uint8_t *out_dhkey);
int bt_mesh_dh_key_gen(const uint8_t remote_pk[64], bt_mesh_dh_key_cb_t cb, const uint8_t idx)
int bt_mesh_dh_key_gen(const uint8_t remote_pub_key[64], uint8_t dhkey[32])
{
uint8_t dhkey[32];
BT_DBG("private key = %s", bt_hex(bt_mesh_private_key, 32));
ble_sm_alg_gen_dhkey((uint8_t *)&remote_pk[0], (uint8_t *)&remote_pk[32], bt_mesh_private_key, dhkey);
if (cb != NULL) {
cb((const uint8_t *)dhkey, idx);
}
return 0;
return ble_sm_alg_gen_dhkey((uint8_t *)&remote_pub_key[0], (uint8_t *)&remote_pub_key[32],
bt_mesh_private_key, dhkey);
}
int bt_mesh_encrypt_le(const uint8_t key[16], const uint8_t plaintext[16],
@ -1942,7 +1933,7 @@ int bt_mesh_encrypt_be(const uint8_t key[16], const uint8_t plaintext[16],
return 0;
}
#if defined(CONFIG_BLE_MESH_USE_DUPLICATE_SCAN)
#if CONFIG_BLE_MESH_USE_DUPLICATE_SCAN
int bt_mesh_update_exceptional_list(uint8_t sub_code, uint32_t type, void *info)
{
uint8_t value[6] = {0};

View File

@ -0,0 +1,684 @@
/* Bluetooth Mesh */
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <errno.h>
#include "adv.h"
#include "crypto.h"
#include "mesh/mutex.h"
#include "mesh/common.h"
#include "mesh/access.h"
#include "prov_common.h"
static const struct bt_mesh_prov *prov;
const struct bt_mesh_prov *bt_mesh_prov_get(void)
{
return prov;
}
int bt_mesh_prov_set(const struct bt_mesh_prov *val)
{
prov = val;
return 0;
}
void bt_mesh_prov_buf_init(struct net_buf_simple *buf, uint8_t type)
{
net_buf_simple_reserve(buf, PROV_BUF_HEADROOM);
net_buf_simple_add_u8(buf, type);
}
#define OUTPUT_OOB_BLINK 0x00
#define OUTPUT_OOB_BEEP 0x01
#define OUTPUT_OOB_VIBRATE 0x02
#define OUTPUT_OOB_NUMBER 0x03
#define OUTPUT_OOB_STRING 0x04
#define INPUT_OOB_PUSH 0x00
#define INPUT_OOB_TWIST 0x01
#define INPUT_OOB_NUMBER 0x02
#define INPUT_OOB_STRING 0x03
bt_mesh_output_action_t bt_mesh_prov_output_action(uint8_t action)
{
switch (action) {
case OUTPUT_OOB_BLINK:
return BLE_MESH_BLINK;
case OUTPUT_OOB_BEEP:
return BLE_MESH_BEEP;
case OUTPUT_OOB_VIBRATE:
return BLE_MESH_VIBRATE;
case OUTPUT_OOB_NUMBER:
return BLE_MESH_DISPLAY_NUMBER;
case OUTPUT_OOB_STRING:
return BLE_MESH_DISPLAY_STRING;
default:
return BLE_MESH_NO_OUTPUT;
}
}
bt_mesh_input_action_t bt_mesh_prov_input_action(uint8_t action)
{
switch (action) {
case INPUT_OOB_PUSH:
return BLE_MESH_PUSH;
case INPUT_OOB_TWIST:
return BLE_MESH_TWIST;
case INPUT_OOB_NUMBER:
return BLE_MESH_ENTER_NUMBER;
case INPUT_OOB_STRING:
return BLE_MESH_ENTER_STRING;
default:
return BLE_MESH_NO_INPUT;
}
}
static const struct {
uint16_t length;
} prov_pdu[] = {
{ 1 }, /* Provisioning Invite */
{ 11 }, /* Provisioning Capabilities */
{ 5 }, /* Provisioning Start */
{ 64 }, /* Provisioning Public Key */
{ 0 }, /* Provisioning Input Complete */
{ 16 }, /* Provisioning Confirmation */
{ 16 }, /* Provisioning Random */
{ 33 }, /* Provisioning Data */
{ 0 }, /* Provisioning Complete */
{ 1 }, /* Provisioning Failed */
{ 6 }, /* Provisioning Record Request */
{ 7 }, /* Provisioning Record Response */
{ 0 }, /* Provisioning Records Get */
{ 2 }, /* Provisioning Records List */
};
bool bt_mesh_prov_pdu_check(uint8_t type, uint16_t length, uint8_t *reason)
{
if (prov_pdu[type].length != length) {
#if CONFIG_BLE_MESH_CERT_BASED_PROV
if ((type == PROV_REC_LIST || type == PROV_REC_RSP) &&
length >= prov_pdu[type].length) {
return true;
}
#endif
#if CONFIG_BLE_MESH_PROV_EPA
/* NOTE: PROV_CONFIRM and PROV_RANDOM PDU may have length 16 or 32 */
if ((type == PROV_CONFIRM || type == PROV_RANDOM) && length == 32) {
return true;
}
#endif
BT_ERR("Invalid length %u for type 0x%02x", length, type);
if (reason) {
*reason = PROV_ERR_NVAL_FMT;
}
return false;
}
return true;
}
#if CONFIG_BLE_MESH_PB_ADV
/* 3 transmissions, 20ms interval */
#define PROV_XMIT BLE_MESH_TRANSMIT(2, 20)
/* 3 transmissions, 20ms interval */
#define CLOSE_XMIT BLE_MESH_TRANSMIT(2, 20)
#define CLOSE_TIMEOUT K_MSEC(100)
#define BUF_TIMEOUT K_MSEC(400)
#define XACT_SEG_DATA(link, _seg) (&link->rx.buf->data[20 + (((_seg) - 1) * 23)])
#define XACT_SEG_RECV(link, _seg) (link->rx.seg &= ~(1 << (_seg)))
uint8_t node_next_xact_id(struct bt_mesh_prov_link *link)
{
if (link->tx.id != 0 && link->tx.id != 0xFF) {
return ++link->tx.id;
}
link->tx.id = 0x80;
return link->tx.id;
}
uint8_t pvnr_next_xact_id(struct bt_mesh_prov_link *link)
{
if (link->tx.id > 0x7F) {
link->tx.id = 0;
}
return link->tx.id++;
}
bool bt_mesh_gen_prov_start(struct bt_mesh_prov_link *link,
struct net_buf_simple *buf,
struct prov_rx *rx, bool *close)
{
if (link->rx.seg) {
BT_INFO("Get Start while there are unreceived segments");
return false;
}
if (link->rx.prev_id == rx->xact_id) {
BT_INFO("Resending ack");
bt_mesh_gen_prov_ack_send(link, rx->xact_id);
return false;
}
link->rx.buf->len = net_buf_simple_pull_be16(buf);
link->rx.id = rx->xact_id;
link->rx.fcs = net_buf_simple_pull_u8(buf);
BT_DBG("len %u last_seg %u total_len %u fcs 0x%02x", buf->len,
START_LAST_SEG(rx->gpc), link->rx.buf->len, link->rx.fcs);
/* At least one-octet pdu type is needed */
if (link->rx.buf->len < 1) {
BT_ERR("Ignoring zero-length provisioning PDU");
if (close) {
*close = true;
}
return false;
}
if (START_LAST_SEG(rx->gpc) > START_LAST_SEG_MAX) {
BT_ERR("Invalid SegN 0x%02x", START_LAST_SEG(rx->gpc));
if (close) {
*close = true;
}
return false;
}
if (link->rx.buf->len > link->rx.buf->size) {
BT_ERR("Too large provisioning PDU (%u bytes)",
link->rx.buf->len);
if (close) {
*close = true;
}
return false;
}
if (START_LAST_SEG(rx->gpc) > 0 && link->rx.buf->len <= 20) {
BT_ERR("Too small total length for multi-segment PDU");
if (close) {
*close = true;
}
return false;
}
link->rx.seg = (1 << (START_LAST_SEG(rx->gpc) + 1)) - 1;
link->rx.last_seg = START_LAST_SEG(rx->gpc);
memcpy(link->rx.buf->data, buf->data, buf->len);
XACT_SEG_RECV(link, 0);
/* Still have some segments to receive */
if (link->rx.seg) {
return false;
}
return true;
}
bool bt_mesh_gen_prov_cont(struct bt_mesh_prov_link *link,
struct net_buf_simple *buf,
struct prov_rx *rx, bool *close)
{
uint8_t seg = CONT_SEG_INDEX(rx->gpc);
BT_DBG("len %u, seg_index %u", buf->len, seg);
if (link->rx.seg == 0 && link->rx.prev_id == rx->xact_id) {
BT_INFO("Resending ack");
bt_mesh_gen_prov_ack_send(link, rx->xact_id);
return false;
}
if (rx->xact_id != link->rx.id) {
BT_WARN("Data for unknown transaction (%u != %u)",
rx->xact_id, link->rx.id);
return false;
}
if (seg > link->rx.last_seg) {
BT_ERR("Invalid segment index %u", seg);
if (close) {
*close = true;
}
return false;
}
if (seg == link->rx.last_seg) {
uint8_t 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);
if (close) {
*close = true;
}
return false;
}
}
if ((link->rx.seg & BIT(seg)) == 0) {
BT_INFO("Ignore already received segment");
return false;
}
memcpy(XACT_SEG_DATA(link, seg), buf->data, buf->len);
XACT_SEG_RECV(link, seg);
/* Still have some segments to receive */
if (link->rx.seg) {
return false;
}
return true;
}
static struct net_buf *adv_buf_create(void)
{
struct net_buf *buf = NULL;
buf = bt_mesh_adv_create(BLE_MESH_ADV_PROV, BUF_TIMEOUT);
if (!buf) {
BT_ERR("Out of provisioning buffers");
return NULL;
}
return buf;
}
static void ack_complete(uint16_t duration, int err, void *user_data)
{
struct bt_mesh_prov_link *link = user_data;
BT_DBG("xact %u complete", link->pending_ack);
link->pending_ack = PROV_XACT_NVAL;
}
void bt_mesh_gen_prov_ack_send(struct bt_mesh_prov_link *link, uint8_t xact_id)
{
static const struct bt_mesh_send_cb cb = {
.start = ack_complete,
};
const struct bt_mesh_send_cb *complete = NULL;
struct net_buf *buf = NULL;
BT_DBG("xact_id %u", xact_id);
if (link->pending_ack == xact_id) {
BT_DBG("Not sending duplicate ack");
return;
}
buf = adv_buf_create();
if (!buf) {
return;
}
if (link->pending_ack == PROV_XACT_NVAL) {
link->pending_ack = xact_id;
complete = &cb;
} else {
complete = NULL;
}
net_buf_add_be32(buf, link->link_id);
net_buf_add_u8(buf, xact_id);
net_buf_add_u8(buf, GPC_ACK);
bt_mesh_adv_send(buf, PROV_XMIT, complete, link);
net_buf_unref(buf);
}
static void free_segments(struct bt_mesh_prov_link *link)
{
for (size_t i = 0; i < ARRAY_SIZE(link->tx.buf); i++) {
struct net_buf *buf = link->tx.buf[i];
if (!buf) {
break;
}
link->tx.buf[i] = NULL;
bt_mesh_adv_buf_ref_debug(__func__, buf, 3U, BLE_MESH_BUF_REF_SMALL);
/* Mark as canceled */
BLE_MESH_ADV(buf)->busy = 0U;
net_buf_unref(buf);
}
}
void bt_mesh_prov_clear_tx(struct bt_mesh_prov_link *link, bool cancel)
{
bt_mesh_mutex_lock(&link->buf_lock);
if (cancel) {
k_delayed_work_cancel(&link->tx.retransmit);
}
free_segments(link);
bt_mesh_mutex_unlock(&link->buf_lock);
}
static void buf_sent(int err, void *user_data)
{
struct bt_mesh_prov_link *link = user_data;
int32_t timeout = RETRANSMIT_TIMEOUT;
if (!link->tx.buf[0]) {
return;
}
/* The following may happen in TWO situations:
* 1. LINK_CLOSING flag is set, and Link Close is sent;
* 2. LINK_CLOSING flag is set, and any other provisioning
* PDU within the adv queue is sent.
* Regarding the second situation, since LINK_CLOSING flag
* is set, so once a pdu is sent, the link could be closed.
*/
if (bt_mesh_atomic_test_bit(link->flags, LINK_CLOSING)) {
timeout = CLOSE_TIMEOUT;
}
k_delayed_work_submit(&link->tx.retransmit, timeout);
}
static struct bt_mesh_send_cb buf_sent_cb = {
.end = buf_sent,
};
static void prov_retransmit(struct k_work *work)
{
struct bt_mesh_prov_link *link = work->user_data;
int64_t timeout = TRANSACTION_TIMEOUT;
if (!bt_mesh_atomic_test_bit(link->flags, LINK_ACTIVE)) {
BT_WARN("Link not active");
return;
}
#if CONFIG_BLE_MESH_FAST_PROV
if (link->tx_pdu_type >= link->last_tx_pdu) {
timeout = K_SECONDS(30);
}
#endif /* CONFIG_BLE_MESH_FAST_PROV */
/* Use a timeout of 0 ~ 60s for PB-Remote Link Open Procedure. */
if (bt_mesh_atomic_test_bit(link->flags, PB_REMOTE) &&
bt_mesh_atomic_test_bit(link->flags, PBR_OPENING)) {
timeout = K_SECONDS(link->pb_remote_timeout);
}
if (k_uptime_get() - link->tx.start > timeout) {
BT_WARN("Timeout, giving up transaction");
if (bt_mesh_atomic_test_bit(link->flags, PB_REMOTE)) {
bt_mesh_prov_clear_tx(link, true);
link->pb_remote_cbd = false;
link->pb_remote_reset = false;
link->pb_remote_csp = true;
if (link->pb_remote_close) {
link->pb_remote_close(link, CLOSE_REASON_TIMEOUT);
}
} else {
/* Send Link Close if the device is Provisioner, or
* directly reset adv link if the device is Node.
*/
if (link->retrans_timeout) {
link->retrans_timeout(link, CLOSE_REASON_TIMEOUT);
}
}
return;
}
if (bt_mesh_atomic_test_bit(link->flags, LINK_CLOSING)) {
if (bt_mesh_atomic_test_bit(link->flags, PB_REMOTE)) {
bt_mesh_prov_clear_tx(link, true);
link->pb_remote_cbd = false;
/* In this case, no need to send Link Close */
link->pb_remote_reset = true;
if (link->pb_remote_close) {
link->pb_remote_close(link, link->reason);
}
} else {
if (link->reset_adv_link) {
link->reset_adv_link(link, link->reason);
}
}
return;
}
bt_mesh_mutex_lock(&link->buf_lock);
for (size_t i = 0; i < ARRAY_SIZE(link->tx.buf); i++) {
struct net_buf *buf = link->tx.buf[i];
if (!buf) {
break;
}
if (BLE_MESH_ADV(buf)->busy) {
continue;
}
BT_DBG("%u bytes: %s", buf->len, bt_hex(buf->data, buf->len));
if (i + 1 < ARRAY_SIZE(link->tx.buf) && link->tx.buf[i + 1]) {
bt_mesh_adv_send(buf, PROV_XMIT, NULL, NULL);
} else {
bt_mesh_adv_send(buf, PROV_XMIT, &buf_sent_cb, link);
}
}
bt_mesh_mutex_unlock(&link->buf_lock);
}
int bt_mesh_prov_retransmit_init(struct bt_mesh_prov_link *link)
{
link->tx.retransmit.work.user_data = link;
return k_delayed_work_init(&link->tx.retransmit, prov_retransmit);
}
static void send_reliable(struct bt_mesh_prov_link *link, uint8_t xmit)
{
link->tx.start = k_uptime_get();
for (size_t i = 0; i < ARRAY_SIZE(link->tx.buf); i++) {
struct net_buf *buf = link->tx.buf[i];
if (!buf) {
break;
}
if (i + 1 < ARRAY_SIZE(link->tx.buf) && link->tx.buf[i + 1]) {
bt_mesh_adv_send(buf, xmit, NULL, NULL);
} else {
bt_mesh_adv_send(buf, xmit, &buf_sent_cb, link);
}
}
}
int bt_mesh_prov_bearer_ctl_send(struct bt_mesh_prov_link *link, uint8_t op,
void *data, uint8_t data_len)
{
struct net_buf *buf = NULL;
uint8_t xmit = 0;
BT_DBG("op 0x%02x data_len %u", op, data_len);
bt_mesh_prov_clear_tx(link, true);
buf = adv_buf_create();
if (!buf) {
return -ENOBUFS;
}
net_buf_add_be32(buf, link->link_id);
/* Transaction ID, always 0 for Bearer messages */
net_buf_add_u8(buf, 0x00);
net_buf_add_u8(buf, GPC_CTL(op));
net_buf_add_mem(buf, data, data_len);
link->tx.buf[0] = buf;
link->tx.id = 0; /* Set Transaction ID to 0 */
xmit = (op == LINK_CLOSE) ? CLOSE_XMIT : PROV_XMIT;
send_reliable(link, xmit);
if (op == LINK_CLOSE) {
bt_mesh_atomic_clear_bit(link->flags, LINK_ACTIVE);
bt_mesh_atomic_set_bit(link->flags, LINK_CLOSING);
link->reason = *((uint8_t *)data);
}
return 0;
}
static uint8_t last_seg(uint8_t len)
{
if (len <= START_PAYLOAD_MAX) {
return 0;
}
len -= START_PAYLOAD_MAX;
return 1 + (len / CONT_PAYLOAD_MAX);
}
int bt_mesh_prov_send_adv(struct bt_mesh_prov_link *link, struct net_buf_simple *msg)
{
struct net_buf *start = NULL, *buf = NULL;
int32_t timeout = PROTOCOL_TIMEOUT;
uint8_t seg_len = 0U, seg_id = 0U;
uint8_t xact_id = 0U;
BT_DBG("len %u: %s", msg->len, bt_hex(msg->data, msg->len));
if (link->next_xact_id == NULL) {
BT_ERR("Empty transaction id cb");
return -EIO;
}
bt_mesh_prov_clear_tx(link, true);
start = adv_buf_create();
if (!start) {
return -ENOBUFS;
}
xact_id = link->next_xact_id(link);
net_buf_add_be32(start, link->link_id);
net_buf_add_u8(start, xact_id);
net_buf_add_u8(start, GPC_START(last_seg(msg->len)));
net_buf_add_be16(start, msg->len);
net_buf_add_u8(start, bt_mesh_fcs_calc(msg->data, msg->len));
link->tx.buf[0] = start;
#if CONFIG_BLE_MESH_FAST_PROV
link->tx_pdu_type = msg->data[0];
#endif /* CONFIG_BLE_MESH_FAST_PROV */
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);
for (seg_id = 1; msg->len > 0; seg_id++) {
if (seg_id >= ARRAY_SIZE(link->tx.buf)) {
BT_ERR("Too big message (seg_id %d)", seg_id);
bt_mesh_prov_clear_tx(link, false);
return -E2BIG;
}
buf = adv_buf_create();
if (!buf) {
bt_mesh_prov_clear_tx(link, false);
return -ENOBUFS;
}
link->tx.buf[seg_id] = buf;
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));
net_buf_add_be32(buf, link->link_id);
net_buf_add_u8(buf, xact_id);
net_buf_add_u8(buf, GPC_CONT(seg_id));
net_buf_add_mem(buf, msg->data, seg_len);
net_buf_simple_pull(msg, seg_len);
}
send_reliable(link, PROV_XMIT);
#if CONFIG_BLE_MESH_FAST_PROV
if (link->tx_pdu_type >= link->last_tx_pdu) {
timeout = K_SECONDS(60);
}
#endif /* CONFIG_BLE_MESH_FAST_PROV */
k_delayed_work_submit(&link->prot_timer, timeout);
return 0;
}
#endif /* CONFIG_BLE_MESH_PB_ADV */
int bt_mesh_prov_send(struct bt_mesh_prov_link *link, struct net_buf_simple *buf)
{
#if CONFIG_BLE_MESH_RPR_SRV
if (bt_mesh_atomic_test_bit(link->flags, PB_NPPI)) {
if (link->pb_remote_send) {
BT_INFO("NPPI, send prov pdu 0x%02x", buf->data[0]);
return link->pb_remote_send(link, buf);
}
BT_ERR("No NPPI send callback provided");
return -EIO;
}
#endif /* CONFIG_BLE_MESH_RPR_SRV */
#if CONFIG_BLE_MESH_RPR_CLI || CONFIG_BLE_MESH_RPR_SRV
if (bt_mesh_atomic_test_bit(link->flags, PB_REMOTE)) {
if (link->pb_remote_send) {
BT_INFO("PB-Remote, send prov pdu 0x%02x", buf->data[0]);
return link->pb_remote_send(link, buf);
}
BT_ERR("No PB-Remote send callback provided");
return -EIO;
}
#endif /* CONFIG_BLE_MESH_RPR_CLI || CONFIG_BLE_MESH_RPR_SRV */
#if CONFIG_BLE_MESH_PB_GATT
if (link->conn) {
if (link->pb_gatt_send) {
return link->pb_gatt_send(link, buf);
}
BT_ERR("No PB-GATT send callback provided");
return -EIO;
}
#endif /* CONFIG_BLE_MESH_PB_GATT */
#if CONFIG_BLE_MESH_PB_ADV
return bt_mesh_prov_send_adv(link, buf);
#endif /* CONFIG_BLE_MESH_PB_ADV */
/* Shall not reach here. */
return 0;
}

View File

@ -0,0 +1,333 @@
/* Bluetooth Mesh */
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _PROV_COMMON_H_
#define _PROV_COMMON_H_
#include "mesh/config.h"
#include "mesh/types.h"
#include "mesh/main.h"
#include "mesh/mutex.h"
#include "mesh/timer.h"
#include "mesh/adapter.h"
#include "mesh_v1.1/utils.h"
#ifdef __cplusplus
extern "C" {
#endif
#define AUTH_METHOD_NO_OOB 0x00
#define AUTH_METHOD_STATIC 0x01
#define AUTH_METHOD_OUTPUT 0x02
#define AUTH_METHOD_INPUT 0x03
#define PROV_ERR_NONE 0x00
#define PROV_ERR_NVAL_PDU 0x01
#define PROV_ERR_NVAL_FMT 0x02
#define PROV_ERR_UNEXP_PDU 0x03
#define PROV_ERR_CFM_FAILED 0x04
#define PROV_ERR_RESOURCES 0x05
#define PROV_ERR_DECRYPT 0x06
#define PROV_ERR_UNEXP_ERR 0x07
#define PROV_ERR_ADDR 0x08
#define PROV_ERR_NVAL_DATA 0x09
#define PROV_INVITE 0x00
#define PROV_CAPABILITIES 0x01
#define PROV_START 0x02
#define PROV_PUB_KEY 0x03
#define PROV_INPUT_COMPLETE 0x04
#define PROV_CONFIRM 0x05
#define PROV_RANDOM 0x06
#define PROV_DATA 0x07
#define PROV_COMPLETE 0x08
#define PROV_FAILED 0x09
#define PROV_REC_REQ 0x0A
#define PROV_REC_RSP 0x0B
#define PROV_REC_GET 0x0C
#define PROV_REC_LIST 0x0D
/* NOTE: PROV_REC_EXP is specifically defined by Espressif.
* It indicates that the expected PDU may be PROV_INVITE,
* PROV_REC_REQ or PROV_REC_GET. */
#define PROV_REC_EXP 0xFF
#define REC_RSP_SUCCESS 0x00
#define REC_RSP_REC_NOT_PRESENT 0x01
#define REC_RSP_OFFSET_OUT_OF_BOUND 0x02
#define CERT_BASED_PROV_SUPPORT(oob) ((oob) & BIT_MASK(7))
#define PROV_REC_SUPPORT(oob) ((oob) & BIT_MASK(8))
#if CONFIG_BLE_MESH_PROV_EPA
#define PROV_ENC_SIZE(link) ((link)->algorithm == PROV_ALG_P256_HMAC_SHA256 ? 32 : 16)
#define PROV_AUTH_SIZE(link) ((link)->algorithm == PROV_ALG_P256_HMAC_SHA256 ? 32 : 16)
#define PROV_CONF_SIZE(link) ((link)->algorithm == PROV_ALG_P256_HMAC_SHA256 ? 32 : 16)
#define PROV_RAND_SIZE(link) ((link)->algorithm == PROV_ALG_P256_HMAC_SHA256 ? 32 : 16)
#define PROV_CONF_SALT_SIZE(link) ((link)->algorithm == PROV_ALG_P256_HMAC_SHA256 ? 32 : 16)
#define PROV_CONF_KEY_SIZE(link) ((link)->algorithm == PROV_ALG_P256_HMAC_SHA256 ? 32 : 16)
#define PROV_AUTH_MAX_SIZE 32
#define PROV_CONF_MAX_SIZE 32
#define PROV_RAND_MAX_SIZE 32
#else /* CONFIG_BLE_MESH_PROV_EPA */
#define PROV_ENC_SIZE(link) 16
#define PROV_AUTH_SIZE(link) 16
#define PROV_CONF_SIZE(link) 16
#define PROV_RAND_SIZE(link) 16
#define PROV_CONF_SALT_SIZE(link) 16
#define PROV_CONF_KEY_SIZE(link) 16
#define PROV_AUTH_MAX_SIZE 16
#define PROV_CONF_MAX_SIZE 16
#define PROV_RAND_MAX_SIZE 16
#endif /* CONFIG_BLE_MESH_PROV_EPA */
#define PROV_STATIC_OOB_AVAILABLE 0x00
#define PROV_ONLY_OOB_AUTH_SUPPORT 0x01
#define PROV_NO_OOB_PUB_KEY 0x00
#define PROV_OOB_PUB_KEY 0x01
#define GPCF(gpc) ((gpc) & 0x03)
#define GPC_START(last_seg) (((last_seg) << 2) | 0x00)
#define GPC_ACK 0x01
#define GPC_CONT(seg_id) (((seg_id) << 2) | 0x02)
#define GPC_CTL(op) (((op) << 2) | 0x03)
#define START_PAYLOAD_MAX 20
#define CONT_PAYLOAD_MAX 23
#define START_LAST_SEG_MAX 2
#define START_LAST_SEG(gpc) ((gpc) >> 2)
#define CONT_SEG_INDEX(gpc) ((gpc) >> 2)
#define BEARER_CTL(gpc) ((gpc) >> 2)
#define LINK_OPEN 0x00
#define LINK_ACK 0x01
#define LINK_CLOSE 0x02
#define CLOSE_REASON_SUCCESS 0x00
#define CLOSE_REASON_TIMEOUT 0x01
#define CLOSE_REASON_FAILED 0x02
#define PROV_DH_KEY_SIZE 32
#define PROV_CONF_INPUTS_SIZE 145
#define PROV_XACT_NVAL 0xFF
#define NPPI_DEV_KEY_REFRESH 0x00
#define NPPI_NODE_ADDR_REFRESH 0x01
#define NPPI_NODE_COMP_REFRESH 0x02
#define NPPI_UNKNOWN 0x03
#if CONFIG_BLE_MESH_FAST_PROV
#define RETRANSMIT_TIMEOUT K_MSEC(360)
#define TRANSACTION_TIMEOUT K_SECONDS(3)
#define PROTOCOL_TIMEOUT K_SECONDS(6)
#else
#define RETRANSMIT_TIMEOUT K_MSEC(500)
#define TRANSACTION_TIMEOUT K_SECONDS(30)
#define PROTOCOL_TIMEOUT K_SECONDS(60)
#endif /* CONFIG_BLE_MESH_FAST_PROV */
#if CONFIG_BLE_MESH_PB_GATT
#define PROV_BUF_HEADROOM 5
#else
#define PROV_BUF_HEADROOM 0
#endif
#define PROV_BUF(name, len) \
NET_BUF_SIMPLE_DEFINE(name, PROV_BUF_HEADROOM + len)
#define PROV_RX_BUF_SIZE 65
#define BLE_MESH_REC_MAX_ID 0x0013
enum {
PROV_ALG_P256_CMAC_AES128,
#if CONFIG_BLE_MESH_PROV_EPA
PROV_ALG_P256_HMAC_SHA256,
#endif
PROV_ALG_METHOD_MAX_NUM,
};
struct prov_rx {
uint32_t link_id;
uint8_t xact_id;
uint8_t gpc;
};
enum {
CONNECTING, /* Indicate if PB-GATT connection is in progress (Provisioner) */
REMOTE_PUB_KEY, /* Remote key has been received (Node & Provisioner) */
OOB_PUB_KEY, /* OOB public key is available (Node) */
LINK_ACTIVE, /* Link has been opened (Node & Provisioner) */
WAIT_GEN_DHKEY, /* Waiting for remote public key to generate DHKey (Provisioner) */
HAVE_DHKEY, /* DHKey has been calculated (Node & Provisioner) */
SEND_CONFIRM, /* Waiting to send Confirm value (Node & Provisioner) */
WAIT_NUMBER, /* Waiting for number input from user (Node & Provisioner) */
WAIT_STRING, /* Waiting for string input from user (Node & Provisioner) */
LINK_INVALID, /* Error occurred during provisioning (Node) */
LINK_CLOSING, /* Indicate Link Close is being sent (Provisioner) */
PB_REMOTE, /* Indicate if the link is used by PB-Remote */
PB_NPPI, /* Indicate if the link is used by NPPI */
PBR_OPENING, /* Indicate if the PB-Remote Open Link Procedure is ongoing*/
WAIT_PK_OBR, /* Waiting for Remote Provisioning Outbound Report for Public Key */
PROV_NUM_FLAGS,
};
struct bt_mesh_prov_link {
BLE_MESH_ATOMIC_DEFINE(flags, PROV_NUM_FLAGS);
uint8_t expect; /* Next expected PDU */
uint8_t public_key; /* Public Key type */
uint8_t auth_method; /* Authentication method */
uint8_t auth_action; /* Authentication action */
uint8_t auth_size; /* Authentication size */
uint8_t auth[PROV_AUTH_MAX_SIZE]; /* Authentication Value */
uint8_t rand[PROV_RAND_MAX_SIZE]; /* Local Random */
uint8_t conf[PROV_CONF_MAX_SIZE]; /* Remote Confirmation */
uint8_t local_conf[PROV_CONF_MAX_SIZE]; /* Local Confirmation */
uint8_t dhkey[32]; /* Calculated DHKey */
uint8_t algorithm; /* Provisioning Algorithm */
uint8_t conf_salt[PROV_CONF_MAX_SIZE]; /* ConfirmationSalt */
uint8_t conf_key[PROV_CONF_MAX_SIZE]; /* ConfirmationKey */
uint8_t conf_inputs[145]; /* ConfirmationInputs */
uint8_t prov_salt[16]; /* Provisioning Salt */
bt_mesh_addr_t addr; /* Device address */
#if CONFIG_BLE_MESH_NODE
bool invite_recv; /* Indicate if Provisioning Invite is received or not */
#endif /* CONFIG_BLE_MESH_NODE */
#if CONFIG_BLE_MESH_PROVISIONER
uint8_t uuid[16]; /* Check if device is being provisioned */
uint16_t oob_info; /* OOB info of this device */
uint8_t element_num; /* Element num of device */
uint8_t kri_flags; /* Key refresh flag and iv update flag */
uint16_t assign_addr; /* Application assigned address for the device */
uint16_t unicast_addr; /* Unicast address allocated for device */
#if CONFIG_BLE_MESH_CERT_BASED_PROV
uint16_t record_id_expect; /* The record id field of expected record response PDU */
uint16_t offset_expect; /* The offset field of expected record response PDU */
uint16_t max_size; /* The maximum size of provisioning record fragment can receive*/
uint8_t *records[BLE_MESH_REC_MAX_ID]; /* Used to store provisioning records */
#endif /* CONFIG_BLE_MESH_CERT_BASED_PROV */
#if CONFIG_BLE_MESH_PB_ADV
uint8_t expect_ack_for; /* Transaction ACK expected for provisioning pdu */
#endif /* CONFIG_BLE_MESH_PB_ADV */
#endif /* CONFIG_BLE_MESH_PROVISIONER */
#if CONFIG_BLE_MESH_FAST_PROV
uint8_t tx_pdu_type; /* Current transmitted Provisioning PDU type */
uint8_t last_tx_pdu; /* Type of last sent Provisioning PDU */
#endif /* CONFIG_BLE_MESH_FAST_PROV */
#if CONFIG_BLE_MESH_PB_GATT
struct bt_mesh_conn *conn; /* GATT connection */
int (*pb_gatt_send)(struct bt_mesh_prov_link *link, struct net_buf_simple *msg);
#endif /* CONFIG_BLE_MESH_PB_GATT */
#if CONFIG_BLE_MESH_PB_ADV
uint32_t link_id; /* Link ID */
uint8_t pending_ack; /* Decide which transaction id ack is pending */
uint8_t reason; /* Reason of closing provisioning link */
/* Callback used to get next transaction id */
uint8_t (*next_xact_id)(struct bt_mesh_prov_link *link);
/* Callback used to reset PB-ADV link */
void (*reset_adv_link)(struct bt_mesh_prov_link *link, uint8_t reason);
/* Callback used to handle PB-ADV 30s timeout */
void (*retrans_timeout)(struct bt_mesh_prov_link *link, uint8_t reason);
struct {
uint8_t id; /* Transaction ID */
uint8_t prev_id; /* Previous Transaction ID */
uint8_t seg; /* Bit-field of unreceived segments */
uint8_t last_seg; /* Last segment (to check length) */
uint8_t fcs; /* Expected FCS value */
struct net_buf_simple *buf; /* Incoming buffer */
} rx;
struct {
int64_t start; /* Start timestamp of the transaction */
uint8_t id; /* Transaction id*/
struct net_buf *buf[3]; /* Pending outgoing buffer(s) */
struct k_delayed_work retransmit; /* Retransmit timer */
} tx;
bt_mesh_mutex_t buf_lock; /* Mutex used to protect PB-ADV buffer */
#endif /* CONFIG_BLE_MESH_PB_ADV */
uint8_t pb_remote_uuid[16]; /* Device UUID used by PB-Remote */
uint8_t pb_remote_timeout; /* Timeout value used by PB-Remote Open Link procedure */
uint8_t pb_remote_nppi; /* NPPI Procedure */
uint8_t pb_remote_pub_key; /* Public Key used by PB-Remote */
uint8_t pb_remote_cbd:1, /* Indicate if the link is closed by the unprovisioned device */
pb_remote_csp:1, /* Indicate if the link is close as server can not send pdu */
pb_remote_reset:1; /* Indicate if the link is reset */
void *pb_remote_data; /* Remote Provisioning Server/Client PB-Remote information */
/* Callback used to send Remote Provisioning messages */
int (*pb_remote_send)(struct bt_mesh_prov_link *link, struct net_buf_simple *buf);
/* Callback used to notify Remote Provisioning Server that link is closed */
void (*pb_remote_close)(struct bt_mesh_prov_link *link, uint8_t reason);
struct k_delayed_work prot_timer; /* Protocol timer */
};
const struct bt_mesh_prov *bt_mesh_prov_get(void);
int bt_mesh_prov_set(const struct bt_mesh_prov *val);
void bt_mesh_prov_buf_init(struct net_buf_simple *buf, uint8_t type);
bt_mesh_output_action_t bt_mesh_prov_output_action(uint8_t action);
bt_mesh_input_action_t bt_mesh_prov_input_action(uint8_t action);
bool bt_mesh_prov_pdu_check(uint8_t type, uint16_t length, uint8_t *reason);
int bt_mesh_prov_send_adv(struct bt_mesh_prov_link *link, struct net_buf_simple *msg);
bool bt_mesh_gen_prov_start(struct bt_mesh_prov_link *link,
struct net_buf_simple *buf,
struct prov_rx *rx, bool *close);
bool bt_mesh_gen_prov_cont(struct bt_mesh_prov_link *link,
struct net_buf_simple *buf,
struct prov_rx *rx, bool *close);
void bt_mesh_gen_prov_ack_send(struct bt_mesh_prov_link *link, uint8_t xact_id);
void bt_mesh_prov_clear_tx(struct bt_mesh_prov_link *link, bool cancel);
int bt_mesh_prov_retransmit_init(struct bt_mesh_prov_link *link);
int bt_mesh_prov_bearer_ctl_send(struct bt_mesh_prov_link *link, uint8_t op,
void *data, uint8_t data_len);
int bt_mesh_prov_send(struct bt_mesh_prov_link *link, struct net_buf_simple *buf);
#ifdef __cplusplus
}
#endif
#endif /* _PROV_COMMON_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -18,24 +18,28 @@ extern "C" {
void bt_mesh_pb_adv_recv(struct net_buf_simple *buf);
bool bt_prov_active(void);
bool bt_mesh_prov_active(void);
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_close(struct bt_mesh_conn *conn, uint8_t reason);
int bt_mesh_pb_gatt_recv(struct bt_mesh_conn *conn, struct net_buf_simple *buf);
int bt_mesh_set_oob_pub_key(const uint8_t pub_key_x[32], const uint8_t pub_key_y[32],
const uint8_t pri_key[32]);
const struct bt_mesh_prov *bt_mesh_prov_get(void);
int bt_mesh_prov_init(const struct bt_mesh_prov *prov);
int bt_mesh_prov_init(void);
int bt_mesh_prov_deinit(void);
void bt_mesh_prov_complete(uint16_t net_idx, const uint8_t net_key[16],
uint16_t addr, uint8_t flags, uint32_t iv_index);
void bt_mesh_prov_reset(void);
struct bt_mesh_prov_link *bt_mesh_prov_node_get_link(void);
void bt_mesh_rpr_srv_reset_prov_link(struct bt_mesh_prov_link *link, uint8_t reason);
int bt_mesh_rpr_srv_nppi_pdu_recv(uint8_t type, const uint8_t *data);
#ifdef __cplusplus
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -8,20 +8,13 @@
#define _PROV_PVNR_H_
#include "mesh/main.h"
#include "prov_common.h"
#include "mesh/adapter.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef CONFIG_BLE_MESH_PBA_SAME_TIME
#define CONFIG_BLE_MESH_PBA_SAME_TIME 0
#endif
#ifndef CONFIG_BLE_MESH_PBG_SAME_TIME
#define CONFIG_BLE_MESH_PBG_SAME_TIME 0
#endif
#define RM_AFTER_PROV BIT(0)
#define START_PROV_NOW BIT(1)
#define FLUSHABLE_DEV BIT(2)
@ -80,17 +73,6 @@ void bt_mesh_provisioner_clear_link_info(const uint8_t addr[6]);
*/
void bt_mesh_provisioner_pb_adv_recv(struct net_buf_simple *buf);
/**
* @brief This function sends provisioning invite to start
* provisioning this unprovisioned device.
*
* @param[in] addr: Remote device address
* @param[in] conn: Pointer to the bt_conn structure
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_provisioner_set_prov_conn(const uint8_t addr[6], struct bt_mesh_conn *conn);
/**
* @brief This function sends provisioning invite to start
* provisioning this unprovisioned device.
@ -100,7 +82,7 @@ int bt_mesh_provisioner_set_prov_conn(const uint8_t addr[6], struct bt_mesh_conn
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_provisioner_pb_gatt_open(struct bt_mesh_conn *conn, uint8_t *addr);
int bt_mesh_provisioner_pb_gatt_open(struct bt_mesh_conn *conn, const uint8_t addr[6]);
/**
* @brief This function resets the used information when
@ -128,11 +110,9 @@ int bt_mesh_provisioner_pb_gatt_recv(struct bt_mesh_conn *conn, struct net_buf_s
* @brief This function initializes provisioner's PB-GATT and PB-ADV
* related information.
*
* @param[in] prov_info: Pointer to the application-initialized provisioner info.
*
* @return Zero - success, otherwise - fail
*/
int bt_mesh_provisioner_prov_init(const struct bt_mesh_prov *prov_info);
int bt_mesh_provisioner_prov_init(void);
int bt_mesh_provisioner_prov_reset(bool erase);
@ -161,13 +141,6 @@ void bt_mesh_provisioner_unprov_beacon_recv(struct net_buf_simple *buf, int8_t r
void bt_mesh_provisioner_prov_adv_recv(struct net_buf_simple *buf,
const bt_mesh_addr_t *addr, int8_t rssi);
/**
* @brief This function gets the bt_mesh_prov pointer.
*
* @return bt_mesh_prov pointer(prov)
*/
const struct bt_mesh_prov *bt_mesh_provisioner_get_prov_info(void);
void bt_mesh_provisioner_restore_prov_info(uint16_t primary_addr, uint16_t alloc_addr);
/* The following APIs are for primary provisioner application use */
@ -406,15 +379,12 @@ uint16_t bt_mesh_provisioner_get_fast_prov_net_idx(void);
*/
uint8_t bt_mesh_set_fast_prov_unicast_addr_range(uint16_t min, uint16_t max);
/**
* @brief This function is called to set flags & iv_index used for fast provisioning.
*
* @param[in] flags: Key refresh flag and iv update flag
* @param[in] iv_index: IV index
*
* @return None
*/
void bt_mesh_set_fast_prov_flags_iv_index(uint8_t flags, uint32_t iv_index);
int bt_mesh_rpr_cli_pdu_recv(struct bt_mesh_prov_link *link, uint8_t type,
struct net_buf_simple *buf);
int bt_mesh_rpr_cli_pdu_send(struct bt_mesh_prov_link *link, uint8_t type);
int bt_mesh_rpr_cli_recv_pub_key_outbound_report(struct bt_mesh_prov_link *link);
#ifdef __cplusplus
}

View File

@ -8,49 +8,51 @@
#include <errno.h>
#include "mesh.h"
#include "rpl.h"
#include "access.h"
#include "beacon.h"
#include "transport.h"
#include "mesh/common.h"
#include "foundation.h"
#include "proxy_common.h"
#include "proxy_client.h"
#include "prov_pvnr.h"
#include "prov_node.h"
#include "pvnr_mgmt.h"
#include "mesh/adapter.h"
#define PDU_TYPE(data) (data[0] & BIT_MASK(6))
#define PDU_SAR(data) (data[0] >> 6)
#define PROXY_SAR_TIMEOUT K_SECONDS(20)
#define SAR_COMPLETE 0x00
#define SAR_FIRST 0x01
#define SAR_CONT 0x02
#define SAR_LAST 0x03
#define PDU_HDR(sar, type) (sar << 6 | (type & BIT_MASK(6)))
#define SERVER_BUF_SIZE 68
#include "mesh_v1.1/utils.h"
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
static struct bt_mesh_proxy_server {
struct bt_mesh_conn *conn;
enum __packed {
NONE,
PROV,
PROXY,
enum __attribute__((packed)) {
CLI_NONE,
CLI_PROV,
CLI_PROXY,
} conn_type;
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
uint16_t net_idx;
#endif
uint8_t msg_type;
struct k_delayed_work sar_timer;
struct net_buf_simple buf;
} servers[BLE_MESH_MAX_CONN];
static uint8_t server_buf_data[SERVER_BUF_SIZE * BLE_MESH_MAX_CONN];
#if CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT
static struct {
struct bt_mesh_prov_link *link;
bt_mesh_addr_t addr;
} waiting_conn_link[BLE_MESH_MAX_CONN];
#endif
static uint8_t server_buf_data[BLE_MESH_PROXY_BUF_SIZE * BLE_MESH_MAX_CONN];
static struct bt_mesh_proxy_server *find_server(struct bt_mesh_conn *conn)
{
@ -111,6 +113,22 @@ void bt_mesh_proxy_client_set_filter_status_cb(proxy_client_recv_filter_status_c
proxy_client_filter_status_recv_cb = cb;
}
#if (CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT)
int bt_mesh_rpr_srv_set_waiting_prov_link(struct bt_mesh_prov_link *link,
bt_mesh_addr_t *addr)
{
for (size_t i = 0; i < ARRAY_SIZE(waiting_conn_link);i++) {
if (waiting_conn_link[i].link == NULL) {
waiting_conn_link[i].link = link;
memcpy(&waiting_conn_link[i].addr, addr, sizeof(bt_mesh_addr_t));
return 0;
}
}
return -ENOBUFS;
}
#endif /* CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT */
static void filter_status(struct bt_mesh_proxy_server *server,
struct bt_mesh_net_rx *rx,
struct net_buf_simple *buf)
@ -136,10 +154,23 @@ static void filter_status(struct bt_mesh_proxy_server *server,
if (proxy_client_filter_status_recv_cb) {
proxy_client_filter_status_recv_cb(server - servers, rx->ctx.addr, server->net_idx, filter_type, list_size);
}
return;
}
#if CONFIG_BLE_MESH_DF_SRV
static void recv_directed_proxy_caps_status(struct bt_mesh_proxy_server *server,
struct bt_mesh_net_rx *rx,
struct net_buf_simple *buf)
{
uint8_t directed_proxy = net_buf_simple_pull_u8(buf);
uint8_t use_directed = net_buf_simple_pull_u8(buf);
BT_INFO("Directed Proxy 0x%02x, Use Directed 0x%02x", directed_proxy, use_directed);
ARG_UNUSED(directed_proxy);
ARG_UNUSED(use_directed);
}
#endif /* CONFIG_BLE_MESH_DF_SRV */
static void proxy_cfg(struct bt_mesh_proxy_server *server)
{
NET_BUF_SIMPLE_DEFINE(buf, 29);
@ -188,6 +219,18 @@ static void proxy_cfg(struct bt_mesh_proxy_server *server)
case BLE_MESH_PROXY_CFG_FILTER_STATUS:
filter_status(server, &rx, &buf);
break;
#if CONFIG_BLE_MESH_DF_SRV
case BLE_MESH_PROXY_CFG_DIRECTED_PROXY_CAPS_STATUS:
if (buf.len != 2) {
BT_WARN("Invalid Directed Proxy Caps Status (len %d)", buf.len);
break;
}
recv_directed_proxy_caps_status(server, &rx, &buf);
break;
#endif /* CONFIG_BLE_MESH_DF_SRV */
default:
BT_WARN("Unknown Proxy Configuration OpCode 0x%02x", opcode);
break;
@ -212,10 +255,17 @@ static void proxy_complete_pdu(struct bt_mesh_proxy_server *server)
proxy_cfg(server);
break;
#endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
#if CONFIG_BLE_MESH_PB_GATT && (CONFIG_BLE_MESH_PROVISIONER || CONFIG_BLE_MESH_RPR_SRV)
case BLE_MESH_PROXY_PROV:
BT_DBG("Mesh Provisioning PDU");
#if CONFIG_BLE_MESH_RPR_SRV
if (server->conn == bt_mesh_prov_node_get_link()->conn) {
bt_mesh_pb_gatt_recv(server->conn, &server->buf);
} else
#endif
{
bt_mesh_provisioner_pb_gatt_recv(server->conn, &server->buf);
}
break;
#endif
default:
@ -252,7 +302,7 @@ static ssize_t proxy_recv(struct bt_mesh_conn *conn,
return -ENOTCONN;
}
if (ATTR_IS_PROV(srvc_uuid) != (PDU_TYPE(data) == BLE_MESH_PROXY_PROV)) {
if (ATTR_IS_PROV(srvc_uuid) != (BLE_MESH_PROXY_PDU_TYPE(data) == BLE_MESH_PROXY_PROV)) {
BT_WARN("Proxy PDU type doesn't match GATT service uuid");
return -EINVAL;
}
@ -262,51 +312,51 @@ static ssize_t proxy_recv(struct bt_mesh_conn *conn,
return -EINVAL;
}
switch (PDU_SAR(data)) {
case SAR_COMPLETE:
switch (BLE_MESH_PROXY_PDU_SAR(data)) {
case BLE_MESH_PROXY_SAR_COMP:
if (server->buf.len) {
BT_WARN("Complete PDU while a pending incomplete one");
return -EINVAL;
}
server->msg_type = PDU_TYPE(data);
server->msg_type = BLE_MESH_PROXY_PDU_TYPE(data);
net_buf_simple_add_mem(&server->buf, data + 1, len - 1);
proxy_complete_pdu(server);
break;
case SAR_FIRST:
case BLE_MESH_PROXY_SAR_FIRST:
if (server->buf.len) {
BT_WARN("First PDU while a pending incomplete one");
return -EINVAL;
}
k_delayed_work_submit(&server->sar_timer, PROXY_SAR_TIMEOUT);
server->msg_type = PDU_TYPE(data);
k_delayed_work_submit(&server->sar_timer, BLE_MESH_PROXY_SAR_TIMEOUT);
server->msg_type = BLE_MESH_PROXY_PDU_TYPE(data);
net_buf_simple_add_mem(&server->buf, data + 1, len - 1);
break;
case SAR_CONT:
case BLE_MESH_PROXY_SAR_CONT:
if (!server->buf.len) {
BT_WARN("Continuation with no prior data");
return -EINVAL;
}
if (server->msg_type != PDU_TYPE(data)) {
if (server->msg_type != BLE_MESH_PROXY_PDU_TYPE(data)) {
BT_WARN("Unexpected message type in continuation");
return -EINVAL;
}
k_delayed_work_submit(&server->sar_timer, PROXY_SAR_TIMEOUT);
k_delayed_work_submit(&server->sar_timer, BLE_MESH_PROXY_SAR_TIMEOUT);
net_buf_simple_add_mem(&server->buf, data + 1, len - 1);
break;
case SAR_LAST:
case BLE_MESH_PROXY_SAR_LAST:
if (!server->buf.len) {
BT_WARN("Last SAR PDU with no prior data");
return -EINVAL;
}
if (server->msg_type != PDU_TYPE(data)) {
if (server->msg_type != BLE_MESH_PROXY_PDU_TYPE(data)) {
BT_WARN("Unexpected message type in last SAR PDU");
return -EINVAL;
}
@ -320,7 +370,6 @@ static ssize_t proxy_recv(struct bt_mesh_conn *conn,
return len;
}
static int proxy_send(struct bt_mesh_conn *conn, const void *data, uint16_t len)
{
BT_DBG("%u bytes: %s", len, bt_hex(data, len));
@ -328,7 +377,7 @@ static int proxy_send(struct bt_mesh_conn *conn, const void *data, uint16_t len)
return bt_mesh_gattc_write_no_rsp(conn, NULL, data, len);
}
static int proxy_segment_and_send(struct bt_mesh_conn *conn, uint8_t type,
int bt_mesh_proxy_client_segment_send(struct bt_mesh_conn *conn, uint8_t type,
struct net_buf_simple *msg)
{
uint16_t mtu = 0U;
@ -351,22 +400,22 @@ static int proxy_segment_and_send(struct bt_mesh_conn *conn, uint8_t type,
/* ATT_MTU - OpCode (1 byte) - Handle (2 bytes) */
mtu -= 3;
if (mtu > msg->len) {
net_buf_simple_push_u8(msg, PDU_HDR(SAR_COMPLETE, type));
net_buf_simple_push_u8(msg, BLE_MESH_PROXY_PDU_HDR(BLE_MESH_PROXY_SAR_COMP, type));
return proxy_send(conn, msg->data, msg->len);
}
net_buf_simple_push_u8(msg, PDU_HDR(SAR_FIRST, type));
net_buf_simple_push_u8(msg, BLE_MESH_PROXY_PDU_HDR(BLE_MESH_PROXY_SAR_FIRST, type));
err = proxy_send(conn, msg->data, mtu);
net_buf_simple_pull(msg, mtu);
while (msg->len) {
if (msg->len + 1 < mtu) {
net_buf_simple_push_u8(msg, PDU_HDR(SAR_LAST, type));
net_buf_simple_push_u8(msg, BLE_MESH_PROXY_PDU_HDR(BLE_MESH_PROXY_SAR_LAST, type));
err = proxy_send(conn, msg->data, msg->len);
break;
}
net_buf_simple_push_u8(msg, PDU_HDR(SAR_CONT, type));
net_buf_simple_push_u8(msg, BLE_MESH_PROXY_PDU_HDR(BLE_MESH_PROXY_SAR_CONT, type));
err = proxy_send(conn, msg->data, mtu);
net_buf_simple_pull(msg, mtu);
}
@ -384,12 +433,12 @@ int bt_mesh_proxy_client_send(struct bt_mesh_conn *conn, uint8_t type,
return -ENOTCONN;
}
if ((server->conn_type == PROV) != (type == BLE_MESH_PROXY_PROV)) {
if ((server->conn_type == CLI_PROV) != (type == BLE_MESH_PROXY_PROV)) {
BT_ERR("Invalid PDU type for Proxy Server");
return -EINVAL;
}
return proxy_segment_and_send(conn, type, msg);
return bt_mesh_proxy_client_segment_send(conn, type, msg);
}
static void proxy_connected(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn, int id)
@ -402,7 +451,7 @@ static void proxy_connected(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn, int
if (!server) {
BT_ERR("No free Proxy Server objects");
/** Disconnect current connection, clear part of prov_link
/* Disconnect current connection, clear part of prov_link
* information, like uuid, dev_addr, linking flag, etc.
*/
bt_mesh_gattc_disconnect(conn);
@ -410,11 +459,19 @@ static void proxy_connected(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn, int
}
server->conn = bt_mesh_conn_ref(conn);
server->conn_type = NONE;
server->conn_type = CLI_NONE;
net_buf_simple_reset(&server->buf);
#if CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_PB_GATT
for (size_t i = 0; i < ARRAY_SIZE(waiting_conn_link); i++) {
if (!memcmp(addr, &waiting_conn_link[i].addr, sizeof(bt_mesh_addr_t))) {
waiting_conn_link[i].link->conn = conn;
break;
}
}
#endif
bt_mesh_gattc_exchange_mtu(id);
return;
}
static void proxy_disconnected(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn, uint8_t reason)
@ -428,14 +485,29 @@ static void proxy_disconnected(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn,
return;
}
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
if (server->conn_type == PROV) {
#if CONFIG_BLE_MESH_PB_GATT && \
(CONFIG_BLE_MESH_PROVISIONER || CONFIG_BLE_MESH_RPR_SRV)
if (server->conn_type == CLI_PROV) {
#if CONFIG_BLE_MESH_RPR_SRV
if (bt_mesh_prov_node_get_link()->conn == conn) {
for (size_t i = 0; i < ARRAY_SIZE(waiting_conn_link); i++) {
if (waiting_conn_link[i].link->conn == conn) {
memset(&waiting_conn_link[i].addr, 0, sizeof(bt_mesh_addr_t));
break;
}
}
bt_mesh_pb_gatt_close(conn, reason);
} else
#endif /* CONFIG_BLE_MESH_RPR_SRV */
{
bt_mesh_provisioner_pb_gatt_close(conn, reason);
}
#endif
}
#endif /* CONFIG_BLE_MESH_PB_GATT && (CONFIG_BLE_MESH_PROVISIONER || CONFIG_BLE_MESH_RPR_SRV) */
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
if (server->conn_type == PROXY) {
if (server->conn_type == CLI_PROXY) {
if (proxy_client_disconnect_cb) {
proxy_client_disconnect_cb(addr, server - servers, server->net_idx, reason);
}
@ -444,15 +516,14 @@ static void proxy_disconnected(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn,
k_delayed_work_cancel(&server->sar_timer);
server->conn = NULL;
server->conn_type = NONE;
server->conn_type = CLI_NONE;
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
server->net_idx = BLE_MESH_KEY_UNUSED;
#endif
return;
}
#if CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT
#if CONFIG_BLE_MESH_PB_GATT && \
(CONFIG_BLE_MESH_PROVISIONER || CONFIG_BLE_MESH_RPR_SRV)
static ssize_t prov_write_ccc(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn)
{
struct bt_mesh_proxy_server *server = find_server(conn);
@ -462,13 +533,21 @@ static ssize_t prov_write_ccc(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn)
return -ENOTCONN;
}
if (server->conn_type == NONE) {
server->conn_type = PROV;
if (server->conn_type == CLI_NONE) {
server->conn_type = CLI_PROV;
if (bt_mesh_provisioner_set_prov_conn(addr->val, server->conn)) {
bt_mesh_gattc_disconnect(server->conn);
return -EIO;
#if CONFIG_BLE_MESH_RPR_SRV
if (bt_mesh_prov_node_get_link()->conn == conn) {
int err = bt_mesh_pb_gatt_open(conn);
if (err) {
BT_ERR("proxy write ccc error %d", err);
return err;
}
return bt_mesh_rpr_srv_recv_link_ack(addr->val, false);
}
#endif
return bt_mesh_provisioner_pb_gatt_open(conn, addr->val);
}
@ -484,7 +563,7 @@ static ssize_t prov_recv_ntf(struct bt_mesh_conn *conn, uint8_t *data, uint16_t
return -ENOTCONN;
}
if (server->conn_type == PROV) {
if (server->conn_type == CLI_PROV) {
return proxy_recv(conn, NULL, data, len, 0, 0);
}
@ -495,11 +574,9 @@ int bt_mesh_proxy_client_prov_enable(void)
{
int i;
BT_DBG("%s", __func__);
for (i = 0; i < ARRAY_SIZE(servers); i++) {
if (servers[i].conn) {
servers[i].conn_type = PROV;
servers[i].conn_type = CLI_PROV;
}
}
@ -510,22 +587,20 @@ int bt_mesh_proxy_client_prov_disable(void)
{
int i;
BT_DBG("%s", __func__);
for (i = 0; i < ARRAY_SIZE(servers); i++) {
struct bt_mesh_proxy_server *server = &servers[i];
if (server->conn && server->conn_type == PROV) {
if (server->conn && server->conn_type == CLI_PROV) {
bt_mesh_gattc_disconnect(server->conn);
server->conn_type = NONE;
server->conn_type = CLI_NONE;
}
}
return 0;
}
#endif /* CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT */
#endif /* CONFIG_BLE_MESH_PB_GATT */
#if defined(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
static ssize_t proxy_write_ccc(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn)
{
struct bt_mesh_proxy_server *server = find_server(conn);
@ -535,8 +610,8 @@ static ssize_t proxy_write_ccc(bt_mesh_addr_t *addr, struct bt_mesh_conn *conn)
return -ENOTCONN;
}
if (server->conn_type == NONE) {
server->conn_type = PROXY;
if (server->conn_type == CLI_NONE) {
server->conn_type = CLI_PROXY;
if (proxy_client_connect_cb) {
proxy_client_connect_cb(addr, server - servers, server->net_idx);
@ -556,7 +631,7 @@ static ssize_t proxy_recv_ntf(struct bt_mesh_conn *conn, uint8_t *data, uint16_t
return -ENOTCONN;
}
if (server->conn_type == PROXY) {
if (server->conn_type == CLI_PROXY) {
return proxy_recv(conn, NULL, data, len, 0, 0);
}
@ -575,16 +650,13 @@ int bt_mesh_proxy_client_gatt_enable(void)
{
int i;
BT_DBG("%s", __func__);
for (i = 0; i < ARRAY_SIZE(servers); i++) {
if (servers[i].conn) {
servers[i].conn_type = PROXY;
servers[i].conn_type = CLI_PROXY;
}
}
/**
* TODO:
/* TODO:
* Once at least one device has been provisioned, proxy client can be
* set to allow receiving and parsing node_id & net_id adv packets,
* and we may use a global flag to indicate this.
@ -597,8 +669,6 @@ int bt_mesh_proxy_client_gatt_disable(void)
{
int i;
BT_DBG("%s", __func__);
/**
* TODO:
* Once this function is invoked, proxy client shall stop handling
@ -609,9 +679,9 @@ int bt_mesh_proxy_client_gatt_disable(void)
for (i = 0; i < ARRAY_SIZE(servers); i++) {
struct bt_mesh_proxy_server *server = &servers[i];
if (server->conn && server->conn_type == PROXY) {
if (server->conn && server->conn_type == CLI_PROXY) {
bt_mesh_gattc_disconnect(server->conn);
server->conn_type = NONE;
server->conn_type = CLI_NONE;
}
}
@ -626,13 +696,13 @@ static struct bt_mesh_prov_conn_cb conn_callbacks = {
.prov_write_descr = prov_write_ccc,
.prov_notify = prov_recv_ntf,
#endif /* CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT */
#if defined(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
.proxy_write_descr = proxy_write_ccc,
.proxy_notify = proxy_recv_ntf,
#endif /* CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
};
#if defined(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
static struct bt_mesh_subnet *bt_mesh_is_net_id_exist(const uint8_t net_id[8])
{
struct bt_mesh_subnet *sub = NULL;
@ -688,6 +758,12 @@ void bt_mesh_proxy_client_gatt_adv_recv(struct net_buf_simple *buf,
* the hash value (8 octets) with the received one.
*/
return;
case BLE_MESH_PROXY_ADV_PRIVATE_NET_ID:
BT_DBG("Mesh Proxy Private Network ID adv 0x%02x", type);
return;
case BLE_MESH_PROXY_ADV_PRIVATE_NODE_ID:
BT_DBG("Mesh Proxy Private Node Identity adv 0x%02x", type);
return;
default:
BT_DBG("Unknown Mesh Proxy adv type 0x%02x", type);
return;
@ -752,14 +828,14 @@ bool bt_mesh_proxy_client_relay(struct net_buf_simple *buf, uint16_t dst)
struct bt_mesh_proxy_server *server = &servers[i];
NET_BUF_SIMPLE_DEFINE(msg, 32);
if (!server->conn || server->conn_type != PROXY) {
if (!server->conn || server->conn_type != CLI_PROXY) {
continue;
}
/* Proxy PDU sending modifies the original buffer,
* so we need to make a copy.
*/
net_buf_simple_init(&msg, 1);
net_buf_simple_reserve(&msg, 1);
net_buf_simple_add_mem(&msg, buf->data, buf->len);
err = bt_mesh_proxy_client_send(server->conn, BLE_MESH_PROXY_NET_PDU, &msg);
@ -774,29 +850,36 @@ bool bt_mesh_proxy_client_relay(struct net_buf_simple *buf, uint16_t dst)
return send;
}
static int beacon_send(struct bt_mesh_conn *conn, struct bt_mesh_subnet *sub)
static int beacon_send(struct bt_mesh_conn *conn, struct bt_mesh_subnet *sub, bool private)
{
NET_BUF_SIMPLE_DEFINE(buf, 23);
NET_BUF_SIMPLE_DEFINE(buf, 28);
net_buf_simple_init(&buf, 1);
bt_mesh_beacon_create(sub, &buf);
net_buf_simple_reserve(&buf, 1);
#if CONFIG_BLE_MESH_PRB_SRV
if (private) {
bt_mesh_private_beacon_create(sub, &buf);
} else
#endif
{
bt_mesh_secure_beacon_create(sub, &buf);
}
return bt_mesh_proxy_client_send(conn, BLE_MESH_PROXY_BEACON, &buf);
}
bool bt_mesh_proxy_client_beacon_send(struct bt_mesh_subnet *sub)
bool bt_mesh_proxy_client_beacon_send(struct bt_mesh_subnet *sub, bool private)
{
bool send = false;
int err = 0;
int i;
/* NULL means we send Secure Network Beacon on all subnets */
/* NULL means we send Secure Network Beacon or Mesh Private Beacon on all subnets */
if (!sub) {
#if CONFIG_BLE_MESH_NODE
if (bt_mesh_is_provisioned()) {
for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) {
if (bt_mesh.sub[i].net_idx != BLE_MESH_KEY_UNUSED) {
send = bt_mesh_proxy_client_beacon_send(&bt_mesh.sub[i]);
send = bt_mesh_proxy_client_beacon_send(&bt_mesh.sub[i], private);
}
}
return send;
@ -806,7 +889,7 @@ bool bt_mesh_proxy_client_beacon_send(struct bt_mesh_subnet *sub)
if (bt_mesh_is_provisioner_en()) {
for (i = 0; i < ARRAY_SIZE(bt_mesh.p_sub); i++) {
if (bt_mesh.p_sub[i] && bt_mesh.p_sub[i]->net_idx != BLE_MESH_KEY_UNUSED) {
send = bt_mesh_proxy_client_beacon_send(bt_mesh.p_sub[i]);
send = bt_mesh_proxy_client_beacon_send(bt_mesh.p_sub[i], private);
}
}
return send;
@ -816,8 +899,8 @@ bool bt_mesh_proxy_client_beacon_send(struct bt_mesh_subnet *sub)
}
for (i = 0; i < ARRAY_SIZE(servers); i++) {
if (servers[i].conn && servers[i].conn_type == PROXY) {
err = beacon_send(servers[i].conn, sub);
if (servers[i].conn && servers[i].conn_type == CLI_PROXY) {
err = beacon_send(servers[i].conn, sub, private);
if (err) {
BT_ERR("Failed to send proxy beacon message (err %d)", err);
} else {
@ -836,6 +919,7 @@ static int send_proxy_cfg(struct bt_mesh_conn *conn, uint16_t net_idx, struct bt
.app_idx = BLE_MESH_KEY_UNUSED, /* CTL shall be set to 1 */
.addr = BLE_MESH_ADDR_UNASSIGNED, /* DST shall be set to the unassigned address */
.send_ttl = 0U, /* TTL shall be set to 0 */
.send_cred = BLE_MESH_FLOODING_CRED,
};
struct bt_mesh_net_tx tx = {
.ctx = &ctx,
@ -845,13 +929,9 @@ static int send_proxy_cfg(struct bt_mesh_conn *conn, uint16_t net_idx, struct bt
uint16_t alloc_len = 0U;
int err = 0;
if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_provisioned()) {
tx.sub = bt_mesh_subnet_get(net_idx);
} else if (IS_ENABLED(CONFIG_BLE_MESH_PROVISIONER) && bt_mesh_is_provisioner_en()) {
tx.sub = bt_mesh_provisioner_subnet_get(net_idx);
}
if (!tx.sub) {
BT_ERR("Invalid NetKeyIndex 0x%04x", net_idx);
BT_ERR("NetKey 0x%04x not found", net_idx);
return -EIO;
}
@ -864,6 +944,7 @@ static int send_proxy_cfg(struct bt_mesh_conn *conn, uint16_t net_idx, struct bt
alloc_len = sizeof(cfg->opcode) + sizeof(cfg->set.filter_type);
break;
case BLE_MESH_PROXY_CFG_FILTER_ADD:
if (cfg->add.addr == NULL || cfg->add.addr_num == 0) {
BT_ERR("Empty proxy addr list to add");
@ -872,6 +953,7 @@ static int send_proxy_cfg(struct bt_mesh_conn *conn, uint16_t net_idx, struct bt
alloc_len = sizeof(cfg->opcode) + (cfg->add.addr_num << 1);
break;
case BLE_MESH_PROXY_CFG_FILTER_REMOVE:
if (cfg->remove.addr == NULL || cfg->remove.addr_num == 0) {
BT_ERR("Empty proxy addr list to remove");
@ -880,14 +962,33 @@ static int send_proxy_cfg(struct bt_mesh_conn *conn, uint16_t net_idx, struct bt
alloc_len = sizeof(cfg->opcode) + (cfg->remove.addr_num << 1);
break;
#if CONFIG_BLE_MESH_DF_SRV
case BLE_MESH_PROXY_CFG_DIRECTED_PROXY_CONTROL:
if (cfg->direct_proxy_ctrl.use_directed > BLE_MESH_PROXY_USE_DIRECTED_ENABLED) {
BT_ERR("Invalid Use Directed 0x%02x", cfg->direct_proxy_ctrl.use_directed);
return -EINVAL;
}
if (cfg->direct_proxy_ctrl.use_directed == BLE_MESH_PROXY_USE_DIRECTED_ENABLED &&
!bt_mesh_uar_valid(&cfg->direct_proxy_ctrl.proxy_client_uar)) {
BT_ERR("Invalid Proxy Client Unicast Addr Range (0x%04x, %d)",
cfg->direct_proxy_ctrl.proxy_client_uar.range_start,
cfg->direct_proxy_ctrl.proxy_client_uar.range_length);
return -EINVAL;
}
alloc_len = sizeof(cfg->opcode) + 4;
break;
#endif /* CONFIG_BLE_MESH_DF_SRV */
default:
BT_ERR("Unknown Proxy Configuration opcode 0x%02x", cfg->opcode);
return -EINVAL;
}
/**
* For Proxy Configuration PDU:
* 1 octet Proxy PDU type + 9 octets network pdu header + Tranport PDU + 8 octets NetMIC
/* For Proxy Configuration PDU:
* 1 octet Proxy PDU type + 9 octets network pdu header + Transport PDU + 8 octets NetMIC
*/
buf = bt_mesh_alloc_buf(1 + BLE_MESH_NET_HDR_LEN + alloc_len + 8);
if (!buf) {
@ -902,32 +1003,43 @@ static int send_proxy_cfg(struct bt_mesh_conn *conn, uint16_t net_idx, struct bt
case BLE_MESH_PROXY_CFG_FILTER_SET:
net_buf_simple_add_u8(buf, cfg->set.filter_type);
break;
case BLE_MESH_PROXY_CFG_FILTER_ADD:
for (uint16_t i = 0U; i < cfg->add.addr_num; i++) {
net_buf_simple_add_le16(buf, cfg->add.addr[i]);
}
break;
case BLE_MESH_PROXY_CFG_FILTER_REMOVE:
for (uint16_t i = 0U; i < cfg->remove.addr_num; i++) {
net_buf_simple_add_le16(buf, cfg->remove.addr[i]);
}
break;
#if CONFIG_BLE_MESH_DF_SRV
case BLE_MESH_PROXY_CFG_DIRECTED_PROXY_CONTROL:
net_buf_simple_add_u8(buf, cfg->direct_proxy_ctrl.use_directed);
if (cfg->direct_proxy_ctrl.use_directed == BLE_MESH_PROXY_USE_DIRECTED_ENABLED) {
bt_mesh_add_uar_be(buf, &cfg->direct_proxy_ctrl.proxy_client_uar);
}
break;
#endif /* CONFIG_BLE_MESH_DF_SRV */
}
BT_DBG("len %u bytes: %s", buf->len, bt_hex(buf->data, buf->len));
err = bt_mesh_net_encode(&tx, buf, true);
if (err) {
BT_ERR("Encoding proxy message failed (err %d)", err);
bt_mesh_free_buf(buf);
return err;
BT_ERR("Encoding proxy cfg message failed (err %d)", err);
goto end;
}
err = bt_mesh_proxy_client_send(conn, BLE_MESH_PROXY_CONFIG, buf);
if (err) {
BT_ERR("Failed to send proxy cfg message (err %d)", err);
BT_ERR("Failed to send proxy cfg message 0x%02x (err %d)", cfg->opcode, err);
}
end:
bt_mesh_free_buf(buf);
return err;
}
@ -937,7 +1049,7 @@ int bt_mesh_proxy_client_cfg_send(uint8_t conn_handle, uint16_t net_idx,
{
struct bt_mesh_conn *conn = NULL;
if (conn_handle >= BLE_MESH_MAX_CONN || !pdu || pdu->opcode > BLE_MESH_PROXY_CFG_FILTER_REMOVE) {
if (conn_handle >= BLE_MESH_MAX_CONN || !pdu || pdu->opcode > BLE_MESH_PROXY_CFG_DIRECTED_PROXY_CONTROL) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
}
@ -950,8 +1062,7 @@ int bt_mesh_proxy_client_cfg_send(uint8_t conn_handle, uint16_t net_idx,
return -ENOTCONN;
}
/**
* Check if net_idx used to encrypt Proxy Configuration are the same
/* Check if net_idx used to encrypt Proxy Configuration are the same
* with the one added when creating proxy connection.
*/
if (servers[conn_handle].net_idx != net_idx) {
@ -973,8 +1084,8 @@ int bt_mesh_proxy_client_init(void)
struct bt_mesh_proxy_server *server = &servers[i];
k_delayed_work_init(&server->sar_timer, proxy_sar_timeout);
server->buf.size = SERVER_BUF_SIZE;
server->buf.__buf = server_buf_data + (i * SERVER_BUF_SIZE);
server->buf.size = BLE_MESH_PROXY_BUF_SIZE;
server->buf.__buf = server_buf_data + (i * BLE_MESH_PROXY_BUF_SIZE);
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
server->net_idx = BLE_MESH_KEY_UNUSED;
#endif
@ -984,7 +1095,8 @@ int bt_mesh_proxy_client_init(void)
#if CONFIG_BLE_MESH_USE_DUPLICATE_SCAN && CONFIG_BLE_MESH_GATT_PROXY_CLIENT
bt_mesh_update_exceptional_list(BLE_MESH_EXCEP_LIST_SUB_CODE_ADD,
BLE_MESH_EXCEP_LIST_TYPE_MESH_PROXY_ADV, NULL);
BLE_MESH_EXCEP_LIST_TYPE_MESH_PROXY_ADV,
NULL);
#endif
return 0;
@ -1010,4 +1122,5 @@ int bt_mesh_proxy_client_deinit(void)
}
#endif /* CONFIG_BLE_MESH_DEINIT */
#endif /* (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
#endif /* (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT */

View File

@ -9,24 +9,14 @@
#include "net.h"
#include "mesh/adapter.h"
#include "prov_common.h"
#include "mesh_v1.1/utils.h"
#ifdef __cplusplus
extern "C" {
#endif
#define BLE_MESH_PROXY_ADV_NET_ID 0x00
#define BLE_MESH_PROXY_ADV_NODE_ID 0x01
#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 BLE_MESH_PROXY_CFG_FILTER_SET 0x00
#define BLE_MESH_PROXY_CFG_FILTER_ADD 0x01
#define BLE_MESH_PROXY_CFG_FILTER_REMOVE 0x02
#define BLE_MESH_PROXY_CFG_FILTER_STATUS 0x03
typedef union {
struct {
uint8_t net_id[8];
@ -35,6 +25,13 @@ typedef union {
struct {
uint16_t src;
} node_id;
struct {
uint8_t net_id[8];
uint16_t net_idx;
} private_net_id;
struct {
uint16_t src;
} private_node_id;
} bt_mesh_proxy_adv_ctx_t;
struct bt_mesh_proxy_net_pdu {
@ -55,6 +52,14 @@ struct bt_mesh_proxy_cfg_pdu {
uint16_t *addr;
uint16_t addr_num;
} remove;
struct cfg_direct_proxy_ctrl {
uint8_t use_directed;
struct {
uint16_t len_present:1,
range_start:15;
uint8_t range_length;
} proxy_client_uar;
} direct_proxy_ctrl;
};
};
@ -95,13 +100,18 @@ void bt_mesh_proxy_client_gatt_adv_recv(struct net_buf_simple *buf,
int bt_mesh_proxy_client_connect(const uint8_t addr[6], uint8_t addr_type, uint16_t net_idx);
int bt_mesh_proxy_client_disconnect(uint8_t conn_handle);
bool bt_mesh_proxy_client_beacon_send(struct bt_mesh_subnet *sub);
bool bt_mesh_proxy_client_beacon_send(struct bt_mesh_subnet *sub, bool private);
bool bt_mesh_proxy_client_relay(struct net_buf_simple *buf, uint16_t dst);
int bt_mesh_proxy_client_cfg_send(uint8_t conn_handle, uint16_t net_idx,
struct bt_mesh_proxy_cfg_pdu *pdu);
#if CONFIG_BLE_MESH_RPR_SRV
int bt_mesh_rpr_srv_set_waiting_prov_link(struct bt_mesh_prov_link* link,
bt_mesh_addr_t *addr);
#endif
int bt_mesh_proxy_client_init(void);
int bt_mesh_proxy_client_deinit(void);

View File

@ -0,0 +1,67 @@
/*
* SPDX-FileCopyrightText: 2020-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _PROXY_COMMON_H_
#define _PROXY_COMMON_H_
#include "mesh/config.h"
#include "mesh/utils.h"
#include "mesh/timer.h"
#include "net.h"
#ifdef __cplusplus
extern "C" {
#endif
#define BLE_MESH_PROXY_ADV_NET_ID 0x00
#define BLE_MESH_PROXY_ADV_NODE_ID 0x01
#define BLE_MESH_PROXY_ADV_PRIVATE_NET_ID 0x02
#define BLE_MESH_PROXY_ADV_PRIVATE_NODE_ID 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 BLE_MESH_PROXY_SAR_COMP 0x00
#define BLE_MESH_PROXY_SAR_FIRST 0x01
#define BLE_MESH_PROXY_SAR_CONT 0x02
#define BLE_MESH_PROXY_SAR_LAST 0x03
#define BLE_MESH_PROXY_CFG_FILTER_SET 0x00
#define BLE_MESH_PROXY_CFG_FILTER_ADD 0x01
#define BLE_MESH_PROXY_CFG_FILTER_REMOVE 0x02
#define BLE_MESH_PROXY_CFG_FILTER_STATUS 0x03
#define BLE_MESH_PROXY_CFG_DIRECTED_PROXY_CAPS_STATUS 0x04
#define BLE_MESH_PROXY_CFG_DIRECTED_PROXY_CONTROL 0x05
#define BLE_MESH_PROXY_PRIVACY_DISABLED 0x00
#define BLE_MESH_PROXY_PRIVACY_ENABLED 0x01
#define BLE_MESH_PROXY_PRIVACY_NOT_SUPPORTED 0x02
#define BLE_MESH_PROXY_CLI_TYPE_UNSET BIT(0)
#define BLE_MESH_PROXY_CLI_TYPE_DIRECT_PROXY_CLIENT BIT(1)
#define BLE_MESH_PROXY_CLI_TYPE_BLACK_LIST_CLIENT BIT(2)
#define BLE_MESH_PROXY_CLI_TYPE_PROXY_CLIENT BIT(3)
#define BLE_MESH_PROXY_PDU_TYPE(data) (data[0] & BIT_MASK(6))
#define BLE_MESH_PROXY_PDU_SAR(data) (data[0] >> 6)
#define BLE_MESH_PROXY_PDU_HDR(sar, type) ((sar) << 6 | ((type) & BIT_MASK(6)))
/* Mesh spec 1.0.1 Section 6.6:
* "The timeout for the SAR transfer is 20 seconds. When the timeout
* expires, the Proxy Server shall disconnect."
*/
#define BLE_MESH_PROXY_SAR_TIMEOUT K_SECONDS(20)
#define BLE_MESH_PROXY_BUF_SIZE 68
#ifdef __cplusplus
}
#endif
#endif /* _PROXY_COMMON_H_ */

File diff suppressed because it is too large Load Diff

View File

@ -7,8 +7,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _PROXY_H_
#define _PROXY_H_
#ifndef _PROXY_SERVER_H_
#define _PROXY_SERVER_H_
#include "net.h"
#include "mesh/adapter.h"
@ -17,11 +17,6 @@
extern "C" {
#endif
#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
#if CONFIG_BLE_MESH_PROXY
/**
* Device Name Characteristic:
@ -38,11 +33,48 @@ extern "C" {
#define DEVICE_NAME_SIZE (BLE_MESH_GAP_ADV_MAX_LEN - 2)
#endif
struct bt_mesh_proxy_client {
struct bt_mesh_conn *conn;
enum __attribute__((packed)) {
SRV_NONE,
SRV_WHITELIST,
SRV_BLACKLIST,
SRV_PROV,
} filter_type;
uint8_t msg_type;
#if CONFIG_BLE_MESH_GATT_PROXY_SERVER
struct {
uint16_t addr;
bool proxy_client; /* Indicate if the address is the element address of Proxy Client. */
} filter[CONFIG_BLE_MESH_PROXY_FILTER_SIZE];
struct k_delayed_work send_beacons;
uint8_t proxy_client_type;
uint8_t proxy_msg_recv : 1; /* Indicate if proxy server has received a message from proxy client */
#if CONFIG_BLE_MESH_PROXY_PRIVACY
uint8_t proxy_privacy;
#endif
#endif /* CONFIG_BLE_MESH_GATT_PROXY_SERVER */
struct k_delayed_work sar_timer;
struct net_buf_simple buf;
};
typedef void (*proxy_server_connect_cb_t)(uint8_t conn_handle);
typedef void (*proxy_server_disconnect_cb_t)(uint8_t conn_handle, uint8_t reason);
int bt_mesh_set_device_name(const char *name);
const char *bt_mesh_get_device_name(void);
int bt_mesh_proxy_server_segment_send(struct bt_mesh_conn *conn, uint8_t type,
struct net_buf_simple *msg);
int bt_mesh_proxy_server_send(struct bt_mesh_conn *conn, uint8_t type,
struct net_buf_simple *msg);
@ -64,6 +96,22 @@ struct net_buf_simple *bt_mesh_proxy_server_get_buf(void);
int32_t bt_mesh_proxy_server_adv_start(void);
void bt_mesh_proxy_server_adv_stop(void);
void bt_mesh_proxy_server_update_net_id_rand(void);
void bt_mesh_proxy_server_update_net_id_rand_stop(void);
#if CONFIG_BLE_MESH_PRB_SRV
void bt_mesh_proxy_server_private_identity_start(struct bt_mesh_subnet *sub);
void bt_mesh_proxy_server_private_identity_stop(struct bt_mesh_subnet *sub);
void bt_mesh_disable_private_gatt_proxy(void);
bool bt_mesh_proxy_server_is_node_id_enable(void);
void disable_all_private_node_identity(void);
void bt_mesh_prb_pnid_adv_local_set(bool start);
#endif /* CONFIG_BLE_MESH_PRB_SRV */
void bt_mesh_proxy_server_identity_start(struct bt_mesh_subnet *sub);
void bt_mesh_proxy_server_identity_stop(struct bt_mesh_subnet *sub);
@ -73,8 +121,11 @@ void bt_mesh_proxy_server_addr_add(struct net_buf_simple *buf, uint16_t addr);
int bt_mesh_proxy_server_init(void);
int bt_mesh_proxy_server_deinit(void);
bool bt_mesh_proxy_server_find_client_by_addr(uint16_t addr);
uint8_t bt_mesh_proxy_server_get_all_client_type(void);
#ifdef __cplusplus
}
#endif
#endif /* _PROXY_H_ */
#endif /* _PROXY_SERVER_H_ */

View File

@ -10,6 +10,7 @@
#include "mesh.h"
#include "crypto.h"
#include "adv.h"
#include "rpl.h"
#include "access.h"
#include "settings.h"
#include "friend.h"
@ -17,9 +18,12 @@
#include "foundation.h"
#include "mesh/common.h"
#include "proxy_client.h"
#include "prov_common.h"
#include "prov_pvnr.h"
#include "pvnr_mgmt.h"
#include "mesh_v1.1/utils.h"
#if CONFIG_BLE_MESH_PROVISIONER
static struct bt_mesh_node *mesh_nodes[CONFIG_BLE_MESH_MAX_PROV_NODES];
@ -66,14 +70,10 @@ int bt_mesh_provisioner_init(void)
*/
int bt_mesh_provisioner_net_create(void)
{
const struct bt_mesh_prov *prov = NULL;
struct bt_mesh_subnet *sub = NULL;
uint8_t p_key[16] = {0};
BT_DBG("%s", __func__);
prov = bt_mesh_provisioner_get_prov_info();
if (!prov) {
if (bt_mesh_prov_get() == NULL) {
BT_ERR("No provisioning context provided");
return -EINVAL;
}
@ -99,7 +99,7 @@ int bt_mesh_provisioner_net_create(void)
return -ENOMEM;
}
sub->kr_flag = BLE_MESH_KEY_REFRESH(prov->flags);
sub->kr_flag = BLE_MESH_KEY_REFRESH(bt_mesh_prov_get()->flags);
if (sub->kr_flag) {
if (bt_mesh_net_keys_create(&sub->keys[1], p_key)) {
BT_ERR("Failed to generate net-related keys");
@ -119,6 +119,10 @@ int bt_mesh_provisioner_net_create(void)
sub->net_idx = BLE_MESH_KEY_PRIMARY;
sub->node_id = BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED;
#if CONFIG_BLE_MESH_DF_SRV
bt_mesh_directed_forwarding_sub_init(sub);
#endif
bt_mesh.p_sub[0] = sub;
/* Dynamically added appkey & netkey will use these key_idx */
@ -131,9 +135,9 @@ int bt_mesh_provisioner_net_create(void)
bt_mesh_store_p_subnet(bt_mesh.p_sub[0]);
}
bt_mesh.iv_index = prov->iv_index;
bt_mesh.iv_index = bt_mesh_prov_get()->iv_index;
bt_mesh_atomic_set_bit_to(bt_mesh.flags, BLE_MESH_IVU_IN_PROGRESS,
BLE_MESH_IV_UPDATE(prov->flags));
BLE_MESH_IV_UPDATE(bt_mesh_prov_get()->flags));
/* Set minimum required hours, since the 96-hour minimum requirement
* doesn't apply straight after provisioning (since we can't know how
@ -311,12 +315,10 @@ int bt_mesh_provisioner_provision(const bt_mesh_addr_t *addr, const uint8_t uuid
uint16_t oob_info, uint16_t unicast_addr,
uint8_t element_num, uint16_t net_idx,
uint8_t flags, uint32_t iv_index,
const uint8_t dev_key[16], uint16_t *index)
const uint8_t dev_key[16], uint16_t *index, bool nppi)
{
struct bt_mesh_node node = {0};
BT_DBG("%s", __func__);
if (!addr || !uuid || !dev_key || !index) {
BT_ERR("%s, Invalid parameter", __func__);
return -EINVAL;
@ -327,6 +329,11 @@ int bt_mesh_provisioner_provision(const bt_mesh_addr_t *addr, const uint8_t uuid
BT_INFO("UUID %s", bt_hex(uuid, 16));
BT_INFO("DevKey %s", bt_hex(dev_key, 16));
if (nppi == true) {
/* For NPPI, remove the node from database firstly. */
bt_mesh_provisioner_remove_node(uuid);
}
memcpy(node.addr, addr->val, BLE_MESH_ADDR_LEN);
node.addr_type = addr->type;
memcpy(node.dev_uuid, uuid, 16);
@ -367,6 +374,9 @@ static int provisioner_remove_node(uint16_t index, bool erase)
for (i = 0; i < node->element_num; i++) {
bt_mesh_tx_reset_single(node->unicast_addr + i);
}
for (i = 0; i < node->element_num; i++) {
bt_mesh_rpl_reset_single(node->unicast_addr + i, erase);
}
if (IS_ENABLED(CONFIG_BLE_MESH_FRIEND)) {
bt_mesh_friend_remove_lpn(node->unicast_addr);
@ -392,8 +402,6 @@ static struct bt_mesh_node *provisioner_find_node_with_uuid(const uint8_t uuid[1
{
int i;
BT_DBG("%s", __func__);
if (uuid == NULL) {
BT_ERR("Invalid device uuid");
return NULL;
@ -445,8 +453,6 @@ static struct bt_mesh_node *provisioner_find_node_with_addr(uint16_t addr, uint1
struct bt_mesh_node *node = NULL;
int i;
BT_DBG("%s", __func__);
if (!BLE_MESH_ADDR_IS_UNICAST(addr)) {
BT_ERR("Invalid unicast address 0x%04x", addr);
return NULL;
@ -711,39 +717,16 @@ const uint8_t *bt_mesh_provisioner_net_key_get(uint16_t net_idx)
struct bt_mesh_subnet *sub = NULL;
int i;
BT_DBG("%s", __func__);
for (i = 0; i < ARRAY_SIZE(bt_mesh.p_sub); i++) {
sub = bt_mesh.p_sub[i];
if (sub && sub->net_idx == net_idx) {
if (sub->kr_flag) {
return sub->keys[1].net;
} else {
}
return sub->keys[0].net;
}
}
}
return NULL;
}
struct bt_mesh_subnet *bt_mesh_provisioner_subnet_get(uint16_t net_idx)
{
struct bt_mesh_subnet *sub = NULL;
int i;
BT_DBG("%s", __func__);
if (net_idx == BLE_MESH_KEY_ANY) {
return bt_mesh.p_sub[0];
}
for (i = 0; i < ARRAY_SIZE(bt_mesh.p_sub); i++) {
sub = bt_mesh.p_sub[i];
if (sub && sub->net_idx == net_idx) {
return sub;
}
}
return NULL;
}
@ -753,8 +736,6 @@ bool bt_mesh_provisioner_check_msg_dst(uint16_t dst)
struct bt_mesh_node *node = NULL;
int i;
BT_DBG("%s", __func__);
if (!BLE_MESH_ADDR_IS_UNICAST(dst)) {
return true;
}
@ -770,25 +751,23 @@ bool bt_mesh_provisioner_check_msg_dst(uint16_t dst)
return false;
}
const uint8_t *bt_mesh_provisioner_dev_key_get(uint16_t dst)
const uint8_t *bt_mesh_provisioner_dev_key_get(uint16_t addr)
{
/* Device key is only used to encrypt configuration messages.
* Configuration model shall only be supported by the primary
* element which uses the primary unicast address.
*/
struct bt_mesh_node *node = NULL;
int i;
BT_DBG("%s", __func__);
if (!BLE_MESH_ADDR_IS_UNICAST(dst)) {
BT_ERR("Invalid unicast address 0x%04x", dst);
if (!BLE_MESH_ADDR_IS_UNICAST(addr)) {
BT_ERR("Invalid unicast address 0x%04x", addr);
return NULL;
}
for (i = 0; i < ARRAY_SIZE(mesh_nodes); i++) {
node = mesh_nodes[i];
if (node && node->unicast_addr == dst) {
struct bt_mesh_node *node = mesh_nodes[i];
if (node && node->unicast_addr == addr) {
return node->dev_key;
}
}
@ -796,24 +775,6 @@ const uint8_t *bt_mesh_provisioner_dev_key_get(uint16_t dst)
return NULL;
}
struct bt_mesh_app_key *bt_mesh_provisioner_app_key_find(uint16_t app_idx)
{
struct bt_mesh_app_key *key = NULL;
int i;
BT_DBG("%s", __func__);
for (i = 0; i < ARRAY_SIZE(bt_mesh.p_app_keys); i++) {
key = bt_mesh.p_app_keys[i];
if (key && key->net_idx != BLE_MESH_KEY_UNUSED &&
key->app_idx == app_idx) {
return key;
}
}
return NULL;
}
static int provisioner_check_app_key(const uint8_t app_key[16], uint16_t *app_idx)
{
struct bt_mesh_app_key *key = NULL;
@ -1054,9 +1015,9 @@ int bt_mesh_provisioner_local_app_key_update(const uint8_t app_key[16],
return -ENODEV;
}
key = bt_mesh_provisioner_app_key_find(app_idx);
key = bt_mesh_app_key_get(app_idx);
if (key == NULL) {
BT_ERR("Invalid AppKeyIndex 0x%04x", app_idx);
BT_ERR("AppKey 0x%04x not found", app_idx);
return -ENODEV;
}
@ -1084,8 +1045,6 @@ const uint8_t *bt_mesh_provisioner_local_app_key_get(uint16_t net_idx, uint16_t
struct bt_mesh_app_key *key = NULL;
int i;
BT_DBG("%s", __func__);
if (provisioner_check_net_idx(net_idx, false)) {
BT_ERR("Invalid NetKeyIndex 0x%04x", net_idx);
return NULL;
@ -1135,8 +1094,6 @@ static void model_pub_clear(struct bt_mesh_model *model, bool store)
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS) && store) {
bt_mesh_store_mod_pub(model);
}
return;
}
static void model_unbind(struct bt_mesh_model *model, uint16_t app_idx, bool store)
@ -1179,8 +1136,6 @@ int bt_mesh_provisioner_local_app_key_del(uint16_t net_idx, uint16_t app_idx, bo
struct bt_mesh_app_key *key = NULL;
int i;
BT_DBG("%s", __func__);
if (provisioner_check_net_idx(net_idx, false)) {
BT_ERR("Invalid NetKeyIndex 0x%04x", net_idx);
return -ENODEV;
@ -1290,6 +1245,10 @@ int bt_mesh_provisioner_local_net_key_add(const uint8_t net_key[16], uint16_t *n
sub->kr_flag = false;
sub->node_id = BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED;
#if CONFIG_BLE_MESH_DF_SRV
bt_mesh_directed_forwarding_sub_init(sub);
#endif
bt_mesh.p_sub[add] = sub;
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
@ -1312,9 +1271,9 @@ int bt_mesh_provisioner_local_net_key_update(const uint8_t net_key[16], uint16_t
BT_INFO("NetKey %s, net_idx 0x%03x", bt_hex(net_key, 16), net_idx);
sub = bt_mesh_provisioner_subnet_get(net_idx);
sub = bt_mesh_subnet_get(net_idx);
if (sub == NULL) {
BT_ERR("Invalid NetKeyIndex 0x%04x", net_idx);
BT_ERR("NetKey 0x%04x not found", net_idx);
return -ENODEV;
}
@ -1331,7 +1290,7 @@ int bt_mesh_provisioner_local_net_key_update(const uint8_t net_key[16], uint16_t
sub->kr_flag = false;
sub->node_id = BLE_MESH_NODE_IDENTITY_NOT_SUPPORTED;
err = bt_mesh_net_beacon_update(sub);
err = bt_mesh_net_secure_beacon_update(sub);
if (err) {
BT_ERR("Failed to update secure beacon");
return -EIO;
@ -1344,38 +1303,11 @@ int bt_mesh_provisioner_local_net_key_update(const uint8_t net_key[16], uint16_t
return 0;
}
const uint8_t *bt_mesh_provisioner_local_net_key_get(uint16_t net_idx)
{
struct bt_mesh_subnet *sub = NULL;
int i;
BT_DBG("%s", __func__);
if (provisioner_check_net_idx(net_idx, false)) {
BT_ERR("Invalid NetKeyIndex 0x%04x", net_idx);
return NULL;
}
for (i = 0; i < ARRAY_SIZE(bt_mesh.p_sub); i++) {
sub = bt_mesh.p_sub[i];
if (sub && sub->net_idx == net_idx) {
if (sub->kr_flag) {
return sub->keys[1].net;
}
return sub->keys[0].net;
}
}
return NULL;
}
int bt_mesh_provisioner_local_net_key_del(uint16_t net_idx, bool store)
{
struct bt_mesh_subnet *sub = NULL;
int i, j;
BT_DBG("%s", __func__);
if (provisioner_check_net_idx(net_idx, false)) {
BT_ERR("Invalid NetKeyIndex 0x%04x", net_idx);
return -ENODEV;
@ -1457,42 +1389,6 @@ int bt_mesh_provisioner_bind_local_model_app_idx(uint16_t elem_addr, uint16_t mo
return -ENOMEM;
}
int bt_mesh_print_local_composition_data(void)
{
const struct bt_mesh_comp *comp = NULL;
struct bt_mesh_model *model = NULL;
struct bt_mesh_elem *elem = NULL;
int i, j;
comp = bt_mesh_comp_get();
if (!comp) {
BT_ERR("Invalid composition data");
return -EINVAL;
}
BT_INFO("************************************************");
BT_INFO("* cid: 0x%04x pid: 0x%04x vid: 0x%04x *", comp->cid, comp->pid, comp->vid);
BT_INFO("* Element Number: 0x%02x *", comp->elem_count);
for (i = 0; i < comp->elem_count; i++) {
elem = &comp->elem[i];
BT_INFO("* Element %d: 0x%04x *", i, elem->addr);
BT_INFO("* Loc: 0x%04x NumS: 0x%02x NumV: 0x%02x *", elem->loc, elem->model_count, elem->vnd_model_count);
for (j = 0; j < elem->model_count; j++) {
model = &elem->models[j];
BT_INFO("* sig_model %d: id - 0x%04x *", j, model->id);
}
for (j = 0; j < elem->vnd_model_count; j++) {
model = &elem->vnd_models[j];
BT_INFO("* vnd_model %d: id - 0x%04x, cid - 0x%04x *", j, model->vnd.id, model->vnd.company);
}
}
BT_INFO("************************************************");
((void) model);
return 0;
}
#if CONFIG_BLE_MESH_TEST_AUTO_ENTER_NETWORK
int bt_mesh_provisioner_store_node_info(struct bt_mesh_node *node)
{

View File

@ -37,7 +37,7 @@ struct bt_mesh_node {
char name[BLE_MESH_NODE_NAME_SIZE + 1]; /* Node name */
uint16_t comp_length; /* Length of Composition Data */
uint8_t *comp_data; /* Value of Composition Data */
} __packed;
} __attribute__((packed));
int bt_mesh_provisioner_init(void);
@ -57,7 +57,7 @@ int bt_mesh_provisioner_provision(const bt_mesh_addr_t *addr, const uint8_t uuid
uint16_t oob_info, uint16_t unicast_addr,
uint8_t element_num, uint16_t net_idx,
uint8_t flags, uint32_t iv_index,
const uint8_t dev_key[16], uint16_t *index);
const uint8_t dev_key[16], uint16_t *index, bool nppi);
int bt_mesh_provisioner_remove_node(const uint8_t uuid[16]);
@ -89,13 +89,9 @@ int bt_mesh_provisioner_store_node_comp_data(uint16_t addr, const uint8_t *data,
const uint8_t *bt_mesh_provisioner_net_key_get(uint16_t net_idx);
struct bt_mesh_subnet *bt_mesh_provisioner_subnet_get(uint16_t net_idx);
bool bt_mesh_provisioner_check_msg_dst(uint16_t dst);
const uint8_t *bt_mesh_provisioner_dev_key_get(uint16_t dst);
struct bt_mesh_app_key *bt_mesh_provisioner_app_key_find(uint16_t app_idx);
const uint8_t *bt_mesh_provisioner_dev_key_get(uint16_t addr);
int bt_mesh_provisioner_local_app_key_add(const uint8_t app_key[16],
uint16_t net_idx, uint16_t *app_idx);
@ -111,8 +107,6 @@ int bt_mesh_provisioner_local_net_key_add(const uint8_t net_key[16], uint16_t *n
int bt_mesh_provisioner_local_net_key_update(const uint8_t net_key[16], uint16_t net_idx);
const uint8_t *bt_mesh_provisioner_local_net_key_get(uint16_t net_idx);
int bt_mesh_provisioner_local_net_key_del(uint16_t net_idx, bool store);
/* Provisioner bind local client model with proper appkey index */
@ -133,9 +127,6 @@ void bt_mesh_provisioner_heartbeat(uint16_t hb_src, uint16_t hb_dst,
uint8_t init_ttl, uint8_t rx_ttl,
uint8_t hops, uint16_t feat, int8_t rssi);
/* Provisioner print own element information */
int bt_mesh_print_local_composition_data(void);
int bt_mesh_provisioner_store_node_info(struct bt_mesh_node *node);
#ifdef __cplusplus

View File

@ -0,0 +1,141 @@
/* Bluetooth Mesh */
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <string.h>
#include <errno.h>
#include "mesh/config.h"
#include "mesh/trace.h"
#include "mesh.h"
#include "settings.h"
void bt_mesh_update_rpl(struct bt_mesh_rpl *rpl, 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_BLE_MESH_SETTINGS)) {
bt_mesh_store_rpl(rpl);
}
}
/* Check the Replay Protection List for a replay attempt. If non-NULL match
* parameter is given the RPL slot is returned but it is not immediately
* updated (needed for segmented messages), whereas if a NULL match is given
* the RPL is immediately updated (used for unsegmented messages).
*/
static bool rpl_check_and_store(struct bt_mesh_net_rx *rx, struct bt_mesh_rpl **match)
{
for (size_t i = 0; i < ARRAY_SIZE(bt_mesh.rpl); i++) {
struct bt_mesh_rpl *rpl = &bt_mesh.rpl[i];
/* Empty slot */
if (rpl->src == BLE_MESH_ADDR_UNASSIGNED) {
if (match) {
*match = rpl;
} else {
bt_mesh_update_rpl(rpl, rx);
}
return false;
}
/* Existing slot for given address */
if (rpl->src == rx->ctx.addr) {
if (rx->old_iv && !rpl->old_iv) {
return true;
}
if ((!rx->old_iv && rpl->old_iv) ||
rpl->seq < rx->seq) {
if (match) {
*match = rpl;
} else {
bt_mesh_update_rpl(rpl, rx);
}
return false;
}
return true;
}
}
BT_ERR("RPL is full!");
return true;
}
bool bt_mesh_rpl_check(struct bt_mesh_net_rx *rx, struct bt_mesh_rpl **match)
{
/* Don't bother checking messages from ourselves */
if (rx->net_if == BLE_MESH_NET_IF_LOCAL) {
return false;
}
/* The RPL is used only for the local node */
if (!rx->local_match) {
return false;
}
return rpl_check_and_store(rx, match);
}
bool bt_mesh_bridge_rpl_check(struct bt_mesh_net_rx *rx, struct bt_mesh_rpl **match)
{
return rpl_check_and_store(rx, match);
}
void bt_mesh_rpl_update(void)
{
/* Discard "old old" IV Index entries from RPL and flag
* any other ones (which are valid) as old.
*/
for (size_t i = 0; i < ARRAY_SIZE(bt_mesh.rpl); i++) {
struct bt_mesh_rpl *rpl = &bt_mesh.rpl[i];
if (rpl->src) {
if (rpl->old_iv) {
(void)memset(rpl, 0, sizeof(*rpl));
} else {
rpl->old_iv = true;
}
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS)) {
bt_mesh_store_rpl(rpl);
}
}
}
}
void bt_mesh_rpl_reset_single(uint16_t src, bool erase)
{
if (!BLE_MESH_ADDR_IS_UNICAST(src)) {
return;
}
for (size_t i = 0; i < ARRAY_SIZE(bt_mesh.rpl); i++) {
if (src == bt_mesh.rpl[i].src) {
memset(&bt_mesh.rpl[i], 0, sizeof(struct bt_mesh_rpl));
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS) && erase) {
bt_mesh_clear_rpl_single(src);
}
}
}
}
void bt_mesh_rpl_reset(bool erase)
{
(void)memset(bt_mesh.rpl, 0, sizeof(bt_mesh.rpl));
if (IS_ENABLED(CONFIG_BLE_MESH_SETTINGS) && erase) {
bt_mesh_clear_rpl();
}
}

View File

@ -0,0 +1,35 @@
/* Bluetooth Mesh */
/*
* SPDX-FileCopyrightText: 2017 Intel Corporation
* SPDX-FileContributor: 2018-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef _RPL_H_
#define _RPL_H_
#include "net.h"
#ifdef __cplusplus
extern "C" {
#endif
void bt_mesh_update_rpl(struct bt_mesh_rpl *rpl, struct bt_mesh_net_rx *rx);
bool bt_mesh_rpl_check(struct bt_mesh_net_rx *rx, struct bt_mesh_rpl **match);
bool bt_mesh_bridge_rpl_check(struct bt_mesh_net_rx *rx, struct bt_mesh_rpl **match);
void bt_mesh_rpl_update(void);
void bt_mesh_rpl_reset_single(uint16_t src, bool erase);
void bt_mesh_rpl_reset(bool erase);
#ifdef __cplusplus
}
#endif
#endif /* _RPL_H_ */

View File

@ -9,6 +9,7 @@
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <errno.h>
#include "btc_ble_mesh_ble.h"
@ -26,6 +27,8 @@
#include "prov_pvnr.h"
#include "mesh/adapter.h"
#include "mesh_v1.1/utils.h"
/* Scan Window and Interval are equal for continuous scanning */
#define SCAN_INTERVAL 0x20
#define SCAN_WINDOW 0x20
@ -33,18 +36,135 @@
#define PROV_SVC_DATA_LEN 0x12
#define PROXY_SVC_DATA_LEN_NET_ID 0x09
#define PROXY_SVC_DATA_LEN_NODE_ID 0x11
#define PROXY_SVC_DATA_LEN_PRIVATE_NET_ID 0x11
#define PROXY_SVC_DATA_LEN_PRIVATE_NODE_ID 0x11
#if CONFIG_BLE_MESH_PROVISIONER
#if (CONFIG_BLE_MESH_PROVISIONER || CONFIG_BLE_MESH_RPR_SRV)
static const bt_mesh_addr_t *unprov_dev_addr;
static uint8_t current_adv_type;
static struct {
uint8_t start_idx;
uint8_t end_idx;
uint8_t pair_num;
struct {
uint8_t uuid[16];
uint8_t adv_type;
uint8_t addr[6];
} info[BLE_MESH_STORE_UNPROV_INFO_MAX_NUM];
} unprov_dev_info_fifo;
int bt_mesh_unprov_dev_fifo_dequeue(uint8_t *uuid, uint8_t *addr)
{
uint8_t idx = 0;
if (unprov_dev_info_fifo.pair_num == 0) {
return 0;
}
idx = unprov_dev_info_fifo.start_idx;
if (uuid) {
memcpy(uuid, unprov_dev_info_fifo.info[idx].uuid, 16);
}
if (addr) {
memcpy(addr, unprov_dev_info_fifo.info[idx].addr, 6);
}
idx = (idx + 1) % BLE_MESH_STORE_UNPROV_INFO_MAX_NUM;
unprov_dev_info_fifo.start_idx = idx;
unprov_dev_info_fifo.pair_num--;
return 0;
}
int bt_mesh_unprov_dev_info_query(uint8_t uuid[16], uint8_t addr[6],
uint8_t *adv_type, uint8_t query_type)
{
uint8_t idx = 0;
uint8_t cnt = 0;
if (uuid == NULL || addr == NULL) {
BT_WARN("No available information to query");
return -1;
}
while (cnt < unprov_dev_info_fifo.pair_num) {
idx = (cnt + unprov_dev_info_fifo.start_idx) % BLE_MESH_STORE_UNPROV_INFO_MAX_NUM;
if (query_type & BLE_MESH_STORE_UNPROV_INFO_QUERY_TYPE_UUID) {
if (!memcmp(unprov_dev_info_fifo.info[idx].addr, addr, 6)) {
if (query_type & BLE_MESH_STORE_UNPROV_INFO_QUERY_TYPE_EXISTS) {
return 0;
} else {
memcpy(uuid, unprov_dev_info_fifo.info[idx].uuid, 16);
*adv_type = unprov_dev_info_fifo.info[idx].adv_type;
break;
}
}
} else {
if (!memcmp(unprov_dev_info_fifo.info[idx].uuid, uuid, 16)) {
if (query_type & BLE_MESH_STORE_UNPROV_INFO_QUERY_TYPE_EXISTS) {
return 0;
} else {
memcpy(addr, unprov_dev_info_fifo.info[idx].addr, 6);
*adv_type = unprov_dev_info_fifo.info[idx].adv_type;
break;
}
}
}
cnt++;
}
if (cnt == unprov_dev_info_fifo.pair_num) {
BT_WARN("Didn't find info for %d", query_type);
return -1;
}
return 0;
}
int bt_mesh_unprov_dev_fifo_enqueue(uint8_t uuid[16], const uint8_t addr[6], uint8_t adv_type)
{
uint8_t idx = 0;
if (uuid == NULL || addr == NULL) {
BT_ERR("Invalid argument %s", __func__);
return -EINVAL;
}
if (unprov_dev_info_fifo.pair_num == BLE_MESH_STORE_UNPROV_INFO_MAX_NUM) {
bt_mesh_unprov_dev_fifo_dequeue(NULL, NULL);
}
idx = unprov_dev_info_fifo.end_idx;
memcpy(unprov_dev_info_fifo.info[idx].uuid, uuid, 16);
memcpy(unprov_dev_info_fifo.info[idx].addr, addr, 6);
unprov_dev_info_fifo.info[idx].adv_type = adv_type;
idx = (idx + 1) % BLE_MESH_STORE_UNPROV_INFO_MAX_NUM;
unprov_dev_info_fifo.end_idx = idx;
unprov_dev_info_fifo.pair_num++;
return 0;
}
const bt_mesh_addr_t *bt_mesh_get_unprov_dev_addr(void)
{
return unprov_dev_addr;
}
#endif /* CONFIG_BLE_MESH_PROVISIONER */
uint8_t bt_mesh_get_adv_type(void)
{
return current_adv_type;
}
#endif /* (CONFIG_BLE_MESH_PROVISIONER || CONFIG_BLE_MESH_RPR_SRV) */
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \
CONFIG_BLE_MESH_PROXY_SOLIC_PDU_RX
static bool adv_flags_valid(struct net_buf_simple *buf)
{
uint8_t flags = 0U;
@ -76,20 +196,40 @@ static bool adv_service_uuid_valid(struct net_buf_simple *buf, uint16_t *uuid)
BT_DBG("Received adv pkt with service UUID: %d", *uuid);
if (*uuid != BLE_MESH_UUID_MESH_PROV_VAL &&
*uuid != BLE_MESH_UUID_MESH_PROXY_VAL) {
*uuid != BLE_MESH_UUID_MESH_PROXY_VAL &&
*uuid != BLE_MESH_UUID_MESH_PROXY_SOLIC_VAL) {
return false;
}
/**
* @brief In remote provisioning.
* A Node could handle the unprovisioned beacon.
* CASE: MESH/SR/RPR/SCN/BV-01-C
*/
#if CONFIG_BLE_MESH_RPR_SRV
if (*uuid == BLE_MESH_UUID_MESH_PROV_VAL &&
bt_mesh_is_provisioner_en() == false) {
!IS_ENABLED(CONFIG_BLE_MESH_PB_GATT)) {
return false;
}
#else
if (*uuid == BLE_MESH_UUID_MESH_PROV_VAL &&
(bt_mesh_is_provisioner_en() == false ||
!IS_ENABLED(CONFIG_BLE_MESH_PB_GATT))) {
return false;
}
#endif
if (*uuid == BLE_MESH_UUID_MESH_PROXY_VAL &&
!IS_ENABLED(CONFIG_BLE_MESH_GATT_PROXY_CLIENT)) {
return false;
}
if (*uuid == BLE_MESH_UUID_MESH_PROXY_SOLIC_VAL &&
!IS_ENABLED(CONFIG_BLE_MESH_PROXY_SOLIC_PDU_RX)) {
return false;
}
return true;
}
@ -122,12 +262,23 @@ static void handle_adv_service_data(struct net_buf_simple *buf,
BT_DBG("Start to handle Mesh Prov Service Data");
bt_mesh_provisioner_prov_adv_recv(buf, addr, rssi);
}
if (IS_ENABLED(CONFIG_BLE_MESH_RPR_SRV) &&
bt_mesh_is_provisioned()) {
const bt_mesh_addr_t *addr = bt_mesh_get_unprov_dev_addr();
bt_mesh_unprov_dev_fifo_enqueue(buf->data, addr->val, bt_mesh_get_adv_type());
bt_mesh_rpr_srv_unprov_beacon_recv(buf, bt_mesh_get_adv_type(), addr, rssi);
}
break;
#endif
#if CONFIG_BLE_MESH_GATT_PROXY_CLIENT
case BLE_MESH_UUID_MESH_PROXY_VAL:
if (buf->len != PROXY_SVC_DATA_LEN_NET_ID &&
buf->len != PROXY_SVC_DATA_LEN_NODE_ID) {
/* PROXY_SVC_DATA_LEN_NODE_ID,
* PROXY_SVC_DATA_LEN_PRIVATE_NET_ID and
* PROXY_SVC_DATA_LEN_PRIVATE_NODE_ID are equal to 0x11
*/
BT_WARN("Invalid Mesh Proxy Service Data length %d", buf->len);
return;
}
@ -135,13 +286,25 @@ static void handle_adv_service_data(struct net_buf_simple *buf,
BT_DBG("Start to handle Mesh Proxy Service Data");
bt_mesh_proxy_client_gatt_adv_recv(buf, addr, rssi);
break;
#endif
#if CONFIG_BLE_MESH_PROXY_SOLIC_PDU_RX
case BLE_MESH_UUID_MESH_PROXY_SOLIC_VAL:
if (buf->len != (1 + BLE_MESH_NET_HDR_LEN + 8)) {
BT_WARN("Invalid Mesh Proxy Solic Service Data length %d", buf->len);
return;
}
BT_DBG("Start to handle Mesh Proxy Solic Service Data");
bt_mesh_proxy_server_solic_recv(buf, addr, rssi);
break;
#endif
default:
break;
}
}
#endif /* (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT */
CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \
CONFIG_BLE_MESH_PROXY_SOLIC_PDU_RX */
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
static bool ble_scan_en;
@ -180,15 +343,35 @@ static void inline callback_ble_adv_pkt(const bt_mesh_addr_t *addr,
}
#endif /* CONFIG_BLE_MESH_SUPPORT_BLE_SCAN */
#if CONFIG_BLE_MESH_RPR_SRV
static bool rpr_ext_scan_handle_adv_pkt(const bt_mesh_addr_t *addr,
uint8_t data[], uint16_t length)
{
struct net_buf_simple buf = {0};
bool rpr_adv = false;
if (bt_mesh_is_provisioned() == false) {
return false;
}
net_buf_simple_init_with_data(&buf, data, length);
bt_mesh_rpr_srv_extended_scan(&buf, addr, &rpr_adv);
return rpr_adv;
}
#endif /* CONFIG_BLE_MESH_RPR_SRV */
static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
int8_t rssi, uint8_t adv_type,
struct net_buf_simple *buf)
struct net_buf_simple *buf,
uint8_t scan_rsp_len)
{
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \
CONFIG_BLE_MESH_PROXY_SOLIC_PDU_RX
uint16_t uuid = 0U;
#endif
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
#if (CONFIG_BLE_MESH_RPR_SRV || CONFIG_BLE_MESH_SUPPORT_BLE_SCAN)
uint8_t *adv_data = buf->data;
uint16_t adv_len = buf->len;
#endif
@ -202,8 +385,9 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
BT_DBG("scan, len %u: %s", buf->len, bt_hex(buf->data, buf->len));
#if CONFIG_BLE_MESH_PROVISIONER
#if (CONFIG_BLE_MESH_PROVISIONER || CONFIG_BLE_MESH_RPR_SRV)
unprov_dev_addr = addr;
current_adv_type = adv_type;
#endif
while (buf->len > 1) {
@ -257,7 +441,8 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
bt_mesh_beacon_recv(buf, rssi);
break;
#if (CONFIG_BLE_MESH_PROVISIONER && CONFIG_BLE_MESH_PB_GATT) || \
CONFIG_BLE_MESH_GATT_PROXY_CLIENT
CONFIG_BLE_MESH_GATT_PROXY_CLIENT || \
CONFIG_BLE_MESH_PROXY_SOLIC_PDU_RX
case BLE_MESH_DATA_FLAGS:
if (!adv_flags_valid(buf)) {
BT_DBG("Adv Flags mismatch, ignore this adv pkt");
@ -270,6 +455,14 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
case BLE_MESH_DATA_UUID16_ALL:
if (!adv_service_uuid_valid(buf, &uuid)) {
BT_DBG("Adv Service UUID mismatch, ignore this adv pkt");
#if CONFIG_BLE_MESH_RPR_SRV
if (rpr_ext_scan_handle_adv_pkt(addr, adv_data, adv_len)) {
/* If handled as extended scan report successfully, then not
* notify to the application layer as normal BLE adv packet.
*/
return;
}
#endif
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
callback_ble_adv_pkt(addr, adv_type, adv_data, adv_len, rssi);
#endif
@ -281,6 +474,14 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
break;
#endif
default:
#if CONFIG_BLE_MESH_RPR_SRV
if (rpr_ext_scan_handle_adv_pkt(addr, adv_data, adv_len)) {
/* If handled as extended scan report successfully, then not
* notify to the application layer as normal BLE adv packet.
*/
return;
}
#endif
#if CONFIG_BLE_MESH_SUPPORT_BLE_SCAN
callback_ble_adv_pkt(addr, adv_type, adv_data, adv_len, rssi);
#endif
@ -290,6 +491,14 @@ static void bt_mesh_scan_cb(const bt_mesh_addr_t *addr,
net_buf_simple_restore(buf, &state);
net_buf_simple_pull(buf, len);
}
#if CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_RPR_SRV_ACTIVE_SCAN
if (scan_rsp_len != 0) {
/**
* scan response is only visible for remote provisioning extend scan.
*/
rpr_ext_scan_handle_adv_pkt(addr, adv_data + adv_len, scan_rsp_len);
}
#endif /* CONFIG_BLE_MESH_RPR_SRV && CONFIG_BLE_MESH_RPR_SRV_ACTIVE_SCAN */
}
int bt_mesh_scan_enable(void)
@ -297,7 +506,11 @@ int bt_mesh_scan_enable(void)
int err = 0;
struct bt_mesh_scan_param scan_param = {
#if CONFIG_BLE_MESH_RPR_SRV_ACTIVE_SCAN
.type = BLE_MESH_SCAN_ACTIVE,
#else
.type = BLE_MESH_SCAN_PASSIVE,
#endif
#if CONFIG_BLE_MESH_USE_DUPLICATE_SCAN
.filter_dup = BLE_MESH_SCAN_FILTER_DUP_ENABLE,
#else
@ -308,8 +521,6 @@ int bt_mesh_scan_enable(void)
.scan_fil_policy = BLE_MESH_SP_ADV_ALL,
};
BT_DBG("%s", __func__);
err = bt_le_scan_start(&scan_param, bt_mesh_scan_cb);
if (err && err != -EALREADY) {
BT_ERR("starting scan failed (err %d)", err);
@ -323,8 +534,6 @@ int bt_mesh_scan_disable(void)
{
int err = 0;
BT_DBG("%s", __func__);
err = bt_le_scan_stop();
if (err && err != -EALREADY) {
BT_ERR("stopping scan failed (err %d)", err);
@ -351,8 +560,6 @@ int bt_mesh_scan_with_wl_enable(void)
.scan_fil_policy = BLE_MESH_SP_ADV_WL,
};
BT_DBG("%s", __func__);
err = bt_le_scan_start(&scan_param, bt_mesh_scan_cb);
if (err && err != -EALREADY) {
BT_ERR("starting scan failed (err %d)", err);

View File

@ -16,7 +16,18 @@
extern "C" {
#endif
#define BLE_MESH_STORE_UNPROV_INFO_MAX_NUM 10
#define BLE_MESH_STORE_UNPROV_INFO_QUERY_TYPE_ADDR 0
#define BLE_MESH_STORE_UNPROV_INFO_QUERY_TYPE_UUID BIT(0)
#define BLE_MESH_STORE_UNPROV_INFO_QUERY_TYPE_EXISTS BIT(1)
const bt_mesh_addr_t *bt_mesh_get_unprov_dev_addr(void);
uint8_t bt_mesh_get_adv_type(void);
int bt_mesh_unprov_dev_fifo_enqueue(uint8_t uuid[16], const uint8_t addr[6], uint8_t adv_type);
int bt_mesh_unprov_dev_info_query(uint8_t uuid[16], uint8_t addr[6],
uint8_t *adv_type, uint8_t query_type);
int bt_mesh_scan_enable(void);

View File

@ -22,6 +22,8 @@
#include "pvnr_mgmt.h"
#include "prov_pvnr.h"
#include "mesh_v1.1/utils.h"
/* BLE Mesh NVS Key and corresponding data struct.
* Note: The length of nvs key must be <= 15.
* "xxxx" (2 octet) means the rpl_src, net_idx, app_idx, model_key, etc.
@ -47,6 +49,7 @@
* key: "mesh/v/xxxx/p" -> write/read to set/get VENDOR MODEL Publication
* key: "mesh/vaddr" -> write/read to set/get all virtual addresses
* key: "mesh/va/xxxx" -> write/read to set/get the "xxxx" virtual address
* key: "mesh/dkca" -> write/read to set/get Device Key Candidate
*/
#if CONFIG_BLE_MESH_SETTINGS
@ -70,12 +73,12 @@ static void store_pending(struct k_work *work);
struct net_val {
uint16_t primary_addr;
uint8_t dev_key[16];
} __packed;
} __attribute__((packed));
/* Sequence number storage */
struct seq_val {
uint8_t val[3];
} __packed;
} __attribute__((packed));
/* Heartbeat Publication storage */
struct hb_pub_val {
@ -103,7 +106,7 @@ struct iv_val {
uint32_t iv_index;
uint8_t iv_update:1,
iv_duration:7;
} __packed;
} __attribute__((packed));
/* Replay Protection List storage */
struct rpl_val {
@ -116,14 +119,14 @@ struct net_key_val {
uint8_t kr_flag:1,
kr_phase:7;
uint8_t val[2][16];
} __packed;
} __attribute__((packed));
/* AppKey storage information */
struct app_key_val {
uint16_t net_idx;
bool updated;
uint8_t val[2][16];
} __packed;
} __attribute__((packed));
struct mod_pub_val {
uint16_t addr;
@ -133,6 +136,9 @@ struct mod_pub_val {
uint8_t period;
uint8_t period_div:4,
cred:1;
#if CONFIG_BLE_MESH_DF_SRV
uint8_t directed_pub_policy; /* Directed publish policy */
#endif /* CONFIG_BLE_MESH_DF_SRV */
};
/* Virtual Address information */
@ -140,7 +146,7 @@ struct va_val {
uint16_t ref;
uint16_t addr;
uint8_t uuid[16];
} __packed;
} __attribute__((packed));
/* We need this so we don't overwrite app-hardcoded values in case FCB
* contains a history of changes but then has a NULL at the end.
@ -166,7 +172,7 @@ struct node_info {
uint8_t flags;
uint32_t iv_index;
uint8_t dev_key[16];
} __packed;
} __attribute__((packed));
static bt_mesh_mutex_t settings_lock;
@ -199,8 +205,6 @@ static int role_set(const char *name)
bool exist = false;
int err = 0;
BT_DBG("%s", __func__);
err = bt_mesh_load_core_settings(name, (uint8_t *)bt_mesh.flags, sizeof(bt_mesh.flags), &exist);
if (err) {
BT_ERR("Failed to load mesh device role");
@ -227,8 +231,6 @@ static int net_set(const char *name)
bool exist = false;
int err = 0;
BT_DBG("%s", __func__);
err = bt_mesh_load_core_settings(name, (uint8_t *)&net, sizeof(net), &exist);
if (err) {
BT_ERR("Failed to load node net info");
@ -250,14 +252,32 @@ static int net_set(const char *name)
return 0;
}
static int dkca_set(const char *name)
{
bool exist = false;
int err = 0;
err = bt_mesh_load_core_settings(name, bt_mesh.dev_key_ca, sizeof(bt_mesh.dev_key_ca), &exist);
if (err) {
BT_ERR("Failed to load DevKey Candidate");
return 0;
}
if (exist == false) {
return 0;
}
BT_INFO("Restored DevKey Candidate %s", bt_hex(bt_mesh.dev_key_ca, 16));
return 0;
}
static int iv_set(const char *name)
{
struct iv_val iv = {0};
bool exist = false;
int err = 0;
BT_DBG("%s", __func__);
err = bt_mesh_load_core_settings(name, (uint8_t *)&iv, sizeof(iv), &exist);
if (err) {
BT_ERR("Failed to load iv_index");
@ -286,8 +306,6 @@ static int seq_set(const char *name)
bool exist = false;
int err = 0;
BT_DBG("%s", __func__);
err = bt_mesh_load_core_settings(name, (uint8_t *)&seq, sizeof(seq), &exist);
if (err) {
BT_ERR("Failed to load sequence number");
@ -354,8 +372,6 @@ static int rpl_set(const char *name)
int err = 0;
int i;
BT_DBG("%s", __func__);
buf = bt_mesh_get_core_settings_item(name);
if (!buf) {
return 0;
@ -405,6 +421,19 @@ free:
return err;
}
static struct bt_mesh_subnet *subnet_exist(uint16_t net_idx)
{
int i;
for (i = 0; i < ARRAY_SIZE(bt_mesh.sub); i++) {
if (bt_mesh.sub[i].net_idx == net_idx) {
return &bt_mesh.sub[i];
}
}
return NULL;
}
static struct bt_mesh_subnet *subnet_alloc(uint16_t net_idx)
{
int i;
@ -419,6 +448,20 @@ static struct bt_mesh_subnet *subnet_alloc(uint16_t net_idx)
return NULL;
}
static struct bt_mesh_app_key *appkey_exist(uint16_t app_idx)
{
int i;
for (i = 0; i < ARRAY_SIZE(bt_mesh.app_keys); i++) {
if (bt_mesh.app_keys[i].net_idx != BLE_MESH_KEY_UNUSED &&
bt_mesh.app_keys[i].app_idx == app_idx) {
return &bt_mesh.app_keys[i];
}
}
return NULL;
}
static int net_key_set(const char *name)
{
struct net_buf_simple *buf = NULL;
@ -430,8 +473,6 @@ static int net_key_set(const char *name)
int err = 0;
int i;
BT_DBG("%s", __func__);
buf = bt_mesh_get_core_settings_item(name);
if (!buf) {
return 0;
@ -453,7 +494,7 @@ static int net_key_set(const char *name)
continue;
}
sub = bt_mesh_subnet_get(net_idx);
sub = subnet_exist(net_idx);
if (!sub) {
sub = subnet_alloc(net_idx);
if (!sub) {
@ -490,8 +531,6 @@ static int app_key_set(const char *name)
int err = 0;
int i;
BT_DBG("%s", __func__);
buf = bt_mesh_get_core_settings_item(name);
if (!buf) {
return 0;
@ -513,13 +552,13 @@ static int app_key_set(const char *name)
continue;
}
sub = bt_mesh_subnet_get(key.net_idx);
sub = subnet_exist(key.net_idx);
if (!sub) {
BT_ERR("Failed to find subnet 0x%03x", key.net_idx);
continue;
}
app = bt_mesh_app_key_find(app_idx);
app = appkey_exist(app_idx);
if (!app) {
app = bt_mesh_app_key_alloc(app_idx);
if (!app) {
@ -554,8 +593,6 @@ static int hb_pub_set(const char *name)
bool exist = false;
int err = 0;
BT_DBG("%s", __func__);
if (!hb_pub) {
BT_ERR("Invalid heartbeat publication");
return -EINVAL;
@ -600,8 +637,6 @@ static int cfg_set(const char *name)
bool exist = false;
int err = 0;
BT_DBG("%s", __func__);
if (!cfg) {
BT_ERR("Invalid configuration");
stored_cfg.valid = false;
@ -719,6 +754,11 @@ static int model_set_pub(bool vnd, struct bt_mesh_model *model, uint16_t model_k
model->pub->retransmit = pub.retransmit;
model->pub->count = 0U;
#if CONFIG_BLE_MESH_DF_SRV
model->pub->directed_pub_policy = pub.directed_pub_policy; /* Directed publish policy */
bt_mesh_power_up_create_path_origin_fsm(model);
#endif /* CONFIG_BLE_MESH_DF_SRV */
BT_INFO("Restored Model Publication, address 0x%04x, app_idx 0x%03x", pub.addr, pub.key);
return 0;
@ -732,8 +772,6 @@ static int model_set(bool vnd, const char *name)
size_t length = 0U;
int i;
BT_DBG("%s", __func__);
buf = bt_mesh_get_core_settings_item(name);
if (!buf) {
return 0;
@ -785,8 +823,6 @@ static int va_set(const char *name)
int err = 0;
int i;
BT_DBG("%s", __func__);
buf = bt_mesh_get_core_settings_item(name);
if (!buf) {
return 0;
@ -840,8 +876,6 @@ static int p_prov_set(const char *name)
bool exist = false;
int err = 0;
BT_DBG("%s", __func__);
err = bt_mesh_load_core_settings(name, (uint8_t *)&val, sizeof(val), &exist);
if (err) {
BT_ERR("Failed to load next address allocation");
@ -866,8 +900,6 @@ static int p_net_idx_set(const char *name)
bool exist = false;
int err = 0;
BT_DBG("%s", __func__);
err = bt_mesh_load_core_settings(name, (uint8_t *)&net_idx, sizeof(net_idx), &exist);
if (err) {
BT_ERR("Failed to load next NetKeyIndex alloc");
@ -891,8 +923,6 @@ static int p_app_idx_set(const char *name)
bool exist = false;
int err = 0;
BT_DBG("%s", __func__);
err = bt_mesh_load_core_settings(name, (uint8_t *)&app_idx, sizeof(app_idx), &exist);
if (err) {
BT_ERR("Failed to load next AppKeyIndex alloc");
@ -910,6 +940,20 @@ static int p_app_idx_set(const char *name)
return 0;
}
static struct bt_mesh_subnet *p_subnet_exist(uint16_t net_idx)
{
int i;
for (i = 0; i < ARRAY_SIZE(bt_mesh.p_sub); i++) {
if (bt_mesh.p_sub[i] &&
bt_mesh.p_sub[i]->net_idx == net_idx) {
return bt_mesh.p_sub[i];
}
}
return NULL;
}
static struct bt_mesh_subnet *p_subnet_alloc(void)
{
int i;
@ -929,6 +973,21 @@ static struct bt_mesh_subnet *p_subnet_alloc(void)
return NULL;
}
static struct bt_mesh_app_key *p_appkey_exist(uint16_t app_idx)
{
int i;
for (i = 0; i < ARRAY_SIZE(bt_mesh.p_app_keys); i++) {
if (bt_mesh.p_app_keys[i] &&
bt_mesh.p_app_keys[i]->net_idx != BLE_MESH_KEY_UNUSED &&
bt_mesh.p_app_keys[i]->app_idx == app_idx) {
return bt_mesh.p_app_keys[i];
}
}
return NULL;
}
static struct bt_mesh_app_key *p_appkey_alloc(void)
{
int i;
@ -959,8 +1018,6 @@ static int p_net_key_set(const char *name)
int err = 0;
int i;
BT_DBG("%s", __func__);
buf = bt_mesh_get_core_settings_item(name);
if (!buf) {
return 0;
@ -982,7 +1039,7 @@ static int p_net_key_set(const char *name)
continue;
}
sub = bt_mesh_provisioner_subnet_get(net_idx);
sub = p_subnet_exist(net_idx);
if (!sub) {
sub = p_subnet_alloc();
if (!sub) {
@ -1019,8 +1076,6 @@ static int p_app_key_set(const char *name)
int err = 0;
int i;
BT_DBG("%s", __func__);
buf = bt_mesh_get_core_settings_item(name);
if (!buf) {
return 0;
@ -1042,13 +1097,13 @@ static int p_app_key_set(const char *name)
continue;
}
sub = bt_mesh_provisioner_subnet_get(key.net_idx);
sub = p_subnet_exist(key.net_idx);
if (!sub) {
BT_ERR("Failed to find subnet 0x%03x", key.net_idx);
continue;
}
app = bt_mesh_provisioner_app_key_find(app_idx);
app = p_appkey_exist(app_idx);
if (!app) {
app = p_appkey_alloc();
if (!app) {
@ -1217,6 +1272,7 @@ const struct bt_mesh_setting {
} settings[] = {
{ "mesh/role", role_set }, /* For Node & Provisioner */
{ "mesh/net", net_set }, /* For Node */
{ "mesh/dkca", dkca_set }, /* For Node */
{ "mesh/iv", iv_set }, /* For Node & Provisioner */
{ "mesh/seq", seq_set }, /* For Node & Provisioner */
{ "mesh/rpl", rpl_set }, /* For Node & Provisioner */
@ -1258,8 +1314,6 @@ int settings_core_load(void)
{
int i;
BT_DBG("%s", __func__);
for (i = 0; i < ARRAY_SIZE(settings); i++) {
if ((!strcmp(settings[i].name, "mesh/net") ||
!strcmp(settings[i].name, "mesh/netkey") ||
@ -1333,7 +1387,12 @@ static int subnet_init(struct bt_mesh_subnet *sub)
}
/* Make sure we have valid beacon data to be sent */
bt_mesh_net_beacon_update(sub);
bt_mesh_net_secure_beacon_update(sub);
#if CONFIG_BLE_MESH_DF_SRV
bt_mesh_directed_forwarding_sub_init(sub);
bt_mesh_recovery_directed_forwarding_table(sub);
#endif
return 0;
}
@ -1357,7 +1416,7 @@ int settings_core_commit(void)
int err = 0;
int i;
#if defined(CONFIG_BLE_MESH_NODE)
#if CONFIG_BLE_MESH_NODE
if (bt_mesh_is_node()) {
if (bt_mesh.sub[0].net_idx == BLE_MESH_KEY_UNUSED) {
/* Nothing to do since we're not yet provisioned */
@ -1385,7 +1444,7 @@ int settings_core_commit(void)
}
#endif /* CONFIG_BLE_MESH_NODE */
#if defined(CONFIG_BLE_MESH_PROVISIONER)
#if CONFIG_BLE_MESH_PROVISIONER
if (bt_mesh_is_provisioner()) {
if (bt_mesh.p_sub[0] == NULL ||
bt_mesh.p_sub[0]->net_idx == BLE_MESH_KEY_UNUSED) {
@ -1417,7 +1476,7 @@ int settings_core_commit(void)
bt_mesh_model_foreach(commit_model, NULL);
}
#if defined(CONFIG_BLE_MESH_NODE)
#if CONFIG_BLE_MESH_NODE
if (bt_mesh_is_node()) {
struct bt_mesh_hb_pub *hb_pub = NULL;
struct bt_mesh_cfg_srv *cfg = NULL;
@ -1426,7 +1485,7 @@ int settings_core_commit(void)
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);
k_delayed_work_submit(&hb_pub->timer, K_NO_WAIT);
}
cfg = bt_mesh_cfg_get();
@ -1603,8 +1662,6 @@ static void store_rpl(struct bt_mesh_rpl *entry)
if (err) {
BT_ERR("Failed to add 0x%04x to mesh/rpl", entry->src);
}
return;
}
static void clear_rpl(void)
@ -1615,8 +1672,6 @@ static void clear_rpl(void)
uint16_t src = 0U;
int i;
BT_DBG("%s", __func__);
buf = bt_mesh_get_core_settings_item("mesh/rpl");
if (!buf) {
bt_mesh_erase_core_settings("mesh/rpl");
@ -1640,15 +1695,12 @@ static void clear_rpl(void)
bt_mesh_erase_core_settings("mesh/rpl");
bt_mesh_free_buf(buf);
return;
}
static void store_pending_rpl(void)
{
int i;
BT_DBG("%s", __func__);
for (i = 0; i < ARRAY_SIZE(bt_mesh.rpl); i++) {
struct bt_mesh_rpl *rpl = &bt_mesh.rpl[i];
@ -1726,8 +1778,6 @@ static void clear_app_key(uint16_t app_idx)
if (err) {
BT_ERR("Failed to remove 0x%03x from mesh/appkey", app_idx);
}
return;
}
static void clear_net_key(uint16_t net_idx)
@ -1745,7 +1795,9 @@ static void clear_net_key(uint16_t net_idx)
BT_ERR("Failed to remove 0x%03x from mesh/netkey", net_idx);
}
return;
#if CONFIG_BLE_MESH_DF_SRV
bt_mesh_clear_directed_forwarding_table_data(net_idx);
#endif
}
static void store_net_key(struct bt_mesh_subnet *sub)
@ -1773,8 +1825,6 @@ static void store_net_key(struct bt_mesh_subnet *sub)
if (err) {
BT_ERR("Failed to add 0x%03x to mesh/netkey", sub->net_idx);
}
return;
}
static void store_app_key(struct bt_mesh_app_key *app)
@ -1799,8 +1849,6 @@ static void store_app_key(struct bt_mesh_app_key *app)
if (err) {
BT_ERR("Failed to add 0x%03x to mesh/appkey", app->app_idx);
}
return;
}
static void store_pending_keys(void)
@ -1823,7 +1871,7 @@ static void store_pending_keys(void)
} else {
if (update->app_key) {
struct bt_mesh_app_key *key = NULL;
key = bt_mesh_app_key_find(update->key_idx);
key = bt_mesh_app_key_get(update->key_idx);
if (key) {
store_app_key(key);
} else {
@ -1864,8 +1912,6 @@ static void store_pending_mod_bind(struct bt_mesh_model *model, bool vnd)
BT_ERR("Failed to add bound key to %s, model_key 0x%04x",
vnd ? "mesh/vnd" : "mesh/sig", model_key);
}
return;
}
static void store_pending_mod_sub(struct bt_mesh_model *model, bool vnd)
@ -1888,8 +1934,6 @@ static void store_pending_mod_sub(struct bt_mesh_model *model, bool vnd)
BT_ERR("Failed to add subscription to %s, model_key 0x%04x",
vnd ? "mesh/vnd" : "mesh/sig", model_key);
}
return;
}
static void store_pending_mod_pub(struct bt_mesh_model *model, bool vnd)
@ -1915,6 +1959,10 @@ static void store_pending_mod_pub(struct bt_mesh_model *model, bool vnd)
pub.period_div = model->pub->period_div;
pub.cred = model->pub->cred;
#if CONFIG_BLE_MESH_DF_SRV
pub.directed_pub_policy = model->pub->directed_pub_policy; /**< Directed publish policy */
#endif
err = bt_mesh_save_core_settings(name, (const uint8_t *)&pub, sizeof(pub));
if (err) {
BT_ERR("Failed to store %s", name);
@ -1926,8 +1974,6 @@ static void store_pending_mod_pub(struct bt_mesh_model *model, bool vnd)
BT_ERR("Failed to add publication to %s, model_key 0x%04x",
vnd ? "mesh/vnd" : "mesh/sig", model_key);
}
return;
}
static void store_pending_mod(struct bt_mesh_model *model,
@ -2062,8 +2108,6 @@ static void store_pending_va(void)
static void store_pending(struct k_work *work)
{
BT_DBG("%s", __func__);
if (bt_mesh_atomic_test_and_clear_bit(bt_mesh.flags, BLE_MESH_RPL_PENDING)) {
if (bt_mesh_is_provisioned() || bt_mesh_is_provisioner_en()) {
store_pending_rpl();
@ -2301,6 +2345,25 @@ void bt_mesh_clear_app_key(struct bt_mesh_app_key *key)
schedule_store(BLE_MESH_KEYS_PENDING);
}
void bt_mesh_clear_rpl_single(uint16_t src)
{
char name[16] = {'\0'};
int err = 0;
if (!BLE_MESH_ADDR_IS_UNICAST(src)) {
BT_ERR("Invalid src 0x%04x", src);
return;
}
sprintf(name, "mesh/rpl/%04x", src);
bt_mesh_erase_core_settings(name);
err = bt_mesh_remove_core_settings_item("mesh/rpl", src);
if (err) {
BT_ERR("Failed to remove 0x%04x from mesh/rpl", src);
}
}
void bt_mesh_clear_rpl(void)
{
schedule_store(BLE_MESH_RPL_PENDING);
@ -2329,6 +2392,16 @@ void bt_mesh_store_label(void)
schedule_store(BLE_MESH_VA_PENDING);
}
void bt_mesh_store_dkca(void)
{
bt_mesh_save_core_settings("mesh/dkca", bt_mesh.dev_key_ca, sizeof(bt_mesh.dev_key_ca));
}
void bt_mesh_clear_dkca(void)
{
bt_mesh_erase_core_settings("mesh/dkca");
}
#if CONFIG_BLE_MESH_PROVISIONER
/**
* key: "mesh/p_prov" -> write/read to set/get prov_ctx.curr_addr
@ -2495,25 +2568,6 @@ void bt_mesh_clear_p_app_key(uint16_t app_idx)
}
}
void bt_mesh_clear_rpl_single(uint16_t src)
{
char name[16] = {'\0'};
int err = 0;
if (!BLE_MESH_ADDR_IS_UNICAST(src)) {
BT_ERR("Invalid src 0x%04x", src);
return;
}
sprintf(name, "mesh/rpl/%04x", src);
bt_mesh_erase_core_settings(name);
err = bt_mesh_remove_core_settings_item("mesh/rpl", src);
if (err) {
BT_ERR("Failed to remove 0x%04x from mesh/rpl", src);
}
}
void bt_mesh_store_node_info(struct bt_mesh_node *node)
{
struct node_info val = {0};

View File

@ -39,8 +39,12 @@ void bt_mesh_clear_role(void);
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_single(uint16_t src);
void bt_mesh_clear_rpl(void);
void bt_mesh_store_dkca(void);
void bt_mesh_clear_dkca(void);
#if CONFIG_BLE_MESH_PROVISIONER
void bt_mesh_store_prov_info(uint16_t primary_addr, uint16_t alloc_addr);
void bt_mesh_clear_prov_info(void);
@ -52,7 +56,6 @@ void bt_mesh_store_p_subnet(struct bt_mesh_subnet *sub);
void bt_mesh_store_p_app_key(struct bt_mesh_app_key *key);
void bt_mesh_clear_p_subnet(uint16_t net_idx);
void bt_mesh_clear_p_app_key(uint16_t app_idx);
void bt_mesh_clear_rpl_single(uint16_t src);
void bt_mesh_store_node_info(struct bt_mesh_node *node);
void bt_mesh_clear_node_info(uint16_t unicast_addr);
void bt_mesh_store_node_name(struct bt_mesh_node *node);

View File

@ -432,7 +432,7 @@ struct net_buf_simple *bt_mesh_get_uid_settings_item(const char *key)
/* API used to check if the settings item exists */
static bool is_settings_item_exist(struct net_buf_simple *buf, const uint16_t val)
bool bt_mesh_is_settings_item_exist(struct net_buf_simple *buf, const uint16_t val)
{
struct net_buf_simple_state state = {0};
size_t length = 0U;
@ -469,7 +469,7 @@ static int settings_add_item(bt_mesh_nvs_handle_t handle, const char *key, const
buf = settings_get_item(handle, key);
/* Check if val already exists */
if (is_settings_item_exist(buf, val) == true) {
if (bt_mesh_is_settings_item_exist(buf, val) == true) {
BT_DBG("0x%04x already exists", val);
bt_mesh_free_buf(buf);
return 0;
@ -533,7 +533,7 @@ static int settings_remove_item(bt_mesh_nvs_handle_t handle, const char *key, co
buf = settings_get_item(handle, key);
/* Check if val does exist */
if (is_settings_item_exist(buf, val) == false) {
if (bt_mesh_is_settings_item_exist(buf, val) == false) {
BT_DBG("0x%04x not exists", val);
bt_mesh_free_buf(buf);
return 0;

View File

@ -57,6 +57,8 @@ int bt_mesh_remove_settings_item(bt_mesh_nvs_handle_t handle, const char *key, c
int bt_mesh_remove_core_settings_item(const char *key, const uint16_t val);
int bt_mesh_remove_uid_settings_item(const char *key, const uint16_t val);
bool bt_mesh_is_settings_item_exist(struct net_buf_simple *buf, const uint16_t val);
int bt_mesh_settings_erase_key(bt_mesh_nvs_handle_t handle, const char *key);
int bt_mesh_settings_erase_all(bt_mesh_nvs_handle_t handle);

View File

@ -9,6 +9,7 @@
#include <stdint.h>
#include "mesh.h"
#include "rpl.h"
#include "mesh/main.h"
#include "mesh/common.h"
#include "settings_nvs.h"
@ -354,8 +355,9 @@ static int settings_close(uint8_t index, bool erase)
bt_mesh_provisioner_prov_reset(erase);
bt_mesh_provisioner_main_reset(erase);
bt_mesh_net_reset();
bt_mesh_rx_reset(erase);
bt_mesh_rx_reset();
bt_mesh_tx_reset();
bt_mesh_rpl_reset(erase);
bt_mesh_settings_reset(erase);
if (erase == true) {

View File

@ -18,8 +18,11 @@
#include "access.h"
#include "foundation.h"
#include "mesh/main.h"
#include "transport.h"
#include "proxy_common.h"
#include "proxy_server.h"
#if defined(CONFIG_BLE_MESH_SELF_TEST)
#if CONFIG_BLE_MESH_SELF_TEST
int bt_mesh_test(void)
{
@ -158,9 +161,9 @@ int bt_mesh_test_start_scanning(bool wl_en)
if (wl_en) {
return bt_mesh_scan_with_wl_enable();
} else {
return bt_mesh_scan_enable();
}
return bt_mesh_scan_enable();
}
int bt_mesh_test_stop_scanning(void)
@ -169,4 +172,21 @@ int bt_mesh_test_stop_scanning(void)
}
#endif /* CONFIG_BLE_MESH_TEST_USE_WHITE_LIST */
bt_mesh_test_net_pdu_cb_t net_pdu_test_cb;
void bt_mesh_test_register_net_pdu_cb(bt_mesh_test_net_pdu_cb_t cb)
{
net_pdu_test_cb = cb;
}
void bt_mesh_test_set_seq(uint32_t seq)
{
if (seq > 0xFFFFFF) {
BT_ERR("Invalid SEQ 0x%08x", seq);
return;
}
bt_mesh.seq = seq;
}
#endif /* CONFIG_BLE_MESH_SELF_TEST */

View File

@ -10,14 +10,14 @@
#ifndef _BLE_MESH_TEST_H_
#define _BLE_MESH_TEST_H_
#include "net.h"
#include "proxy_client.h"
#include "mesh/adapter.h"
#ifdef __cplusplus
extern "C" {
#endif
int bt_mesh_test(void);
struct bt_mesh_device_network_info {
uint8_t net_key[16];
uint16_t net_idx;
@ -45,6 +45,14 @@ int bt_mesh_test_start_scanning(bool wl_en);
int bt_mesh_test_stop_scanning(void);
typedef void (* bt_mesh_test_net_pdu_cb_t)(const uint8_t *data, uint16_t length);
extern bt_mesh_test_net_pdu_cb_t net_pdu_test_cb;
void bt_mesh_test_register_net_pdu_cb(bt_mesh_test_net_pdu_cb_t cb);
void bt_mesh_test_set_seq(uint32_t seq);
#ifdef __cplusplus
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -26,7 +26,7 @@ extern "C" {
#define TRANS_SEQ_ZERO_MASK ((uint16_t)BIT_MASK(13))
#define TRANS_CTL_OP_MASK ((uint8_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_HDR(op, seg) (((op) & TRANS_CTL_OP_MASK) | ((seg) << 7))
#define TRANS_CTL_OP_ACK 0x00
#define TRANS_CTL_OP_FRIEND_POLL 0x01
@ -38,17 +38,24 @@ extern "C" {
#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_HEARTBEAT 0x0A
#define TRANS_CTL_OP_PATH_REQ 0x0B
#define TRANS_CTL_OP_PATH_REPLY 0x0C
#define TRANS_CTL_OP_PATH_CFM 0x0D
#define TRANS_CTL_OP_PATH_ECHO_REQ 0x0E
#define TRANS_CTL_OP_PATH_ECHO_REPLY 0x0F
#define TRANS_CTL_OP_DEP_NODE_UPDATE 0x10
#define TRANS_CTL_OP_PATH_REQ_SOLIC 0x11
struct bt_mesh_ctl_friend_poll {
uint8_t fsn;
} __packed;
} __attribute__((packed));
struct bt_mesh_ctl_friend_update {
uint8_t flags;
uint32_t iv_index;
uint8_t md;
} __packed;
} __attribute__((packed));
struct bt_mesh_ctl_friend_req {
uint8_t criteria;
@ -57,7 +64,7 @@ struct bt_mesh_ctl_friend_req {
uint16_t prev_addr;
uint8_t num_elem;
uint16_t lpn_counter;
} __packed;
} __attribute__((packed));
struct bt_mesh_ctl_friend_offer {
uint8_t recv_win;
@ -65,27 +72,27 @@ struct bt_mesh_ctl_friend_offer {
uint8_t sub_list_size;
int8_t rssi;
uint16_t frnd_counter;
} __packed;
} __attribute__((packed));
struct bt_mesh_ctl_friend_clear {
uint16_t lpn_addr;
uint16_t lpn_counter;
} __packed;
} __attribute__((packed));
struct bt_mesh_ctl_friend_clear_confirm {
uint16_t lpn_addr;
uint16_t lpn_counter;
} __packed;
} __attribute__((packed));
#define BLE_MESH_FRIEND_SUB_MIN_LEN (1 + 2)
struct bt_mesh_ctl_friend_sub {
uint8_t xact;
uint16_t addr_list[5];
} __packed;
} __attribute__((packed));
struct bt_mesh_ctl_friend_sub_confirm {
uint8_t xact;
} __packed;
} __attribute__((packed));
uint8_t bt_mesh_get_seg_retrans_num(void);
@ -93,11 +100,11 @@ int32_t bt_mesh_get_seg_retrans_timeout(uint8_t ttl);
void bt_mesh_set_hb_sub_dst(uint16_t addr);
struct bt_mesh_app_key *bt_mesh_app_key_find(uint16_t app_idx);
struct bt_mesh_app_key *bt_mesh_app_key_get(uint16_t app_idx);
bool bt_mesh_tx_in_progress(void);
void bt_mesh_rx_reset(bool erase);
void bt_mesh_rx_reset(void);
void bt_mesh_tx_reset(void);
void bt_mesh_rx_reset_single(uint16_t src);
void bt_mesh_tx_reset_single(uint16_t dst);
@ -114,12 +121,10 @@ 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_trans_deinit(bool erase);
bool bt_mesh_rpl_check(struct bt_mesh_net_rx *rx, struct bt_mesh_rpl **match);
void bt_mesh_heartbeat_send(void);
int bt_mesh_app_key_get(const struct bt_mesh_subnet *subnet, uint16_t app_idx,
const uint8_t **key, uint8_t *aid, uint8_t role, uint16_t dst);
int bt_mesh_upper_key_get(const struct bt_mesh_subnet *subnet, uint16_t app_idx,
const uint8_t **key, uint8_t *aid, uint16_t dst);
#ifdef __cplusplus
}

View File

@ -14,6 +14,8 @@
#include "mesh/client_common.h"
#include "mesh/common.h"
#include "mesh_v1.1/utils.h"
#define HCI_TIME_FOR_START_ADV K_MSEC(5) /* Three adv related hci commands may take 4 ~ 5ms */
static bt_mesh_client_node_t *bt_mesh_client_pick_node(sys_slist_t *list, uint16_t tx_dst)
@ -151,12 +153,22 @@ static uint32_t bt_mesh_client_get_status_op(const bt_mesh_client_op_pair_t *op_
return 0;
}
static int32_t bt_mesh_get_adv_duration(void)
static int32_t bt_mesh_get_adv_duration(struct bt_mesh_msg_ctx *ctx)
{
uint16_t duration, adv_int;
uint8_t xmit;
uint16_t duration = 0, adv_int = 0;
uint8_t xmit = 0;
/* Initialize with network transmission */
xmit = bt_mesh_net_transmit_get();
if (bt_mesh_tag_immutable_cred(ctx->send_tag)) {
#if CONFIG_BLE_MESH_DF_SRV
if (ctx->send_cred == BLE_MESH_DIRECTED_CRED) {
xmit = bt_mesh_direct_net_transmit_get(); /* Directed network transmission */
}
#endif
}
xmit = bt_mesh_net_transmit_get(); /* Network transmit */
adv_int = BLE_MESH_TRANSMIT_INT(xmit);
duration = (BLE_MESH_TRANSMIT_COUNT(xmit) + 1) * (adv_int + 10);
@ -167,29 +179,31 @@ static int32_t bt_mesh_client_calc_timeout(struct bt_mesh_msg_ctx *ctx,
struct net_buf_simple *msg,
uint32_t opcode, int32_t timeout)
{
int32_t seg_retrans_to = 0, duration = 0, time = 0;
uint8_t seg_count = 0, seg_retrans_num = 0;
int32_t seg_rtx_to = 0, duration = 0, time = 0;
uint8_t seg_count = 0, seg_rtx_num = 0;
bool need_seg = false;
uint8_t mic_size = 0;
if (msg->len > BLE_MESH_SDU_UNSEG_MAX || ctx->send_rel) {
if (msg->len > BLE_MESH_SDU_UNSEG_MAX ||
bt_mesh_tag_send_segmented(ctx->send_tag)) {
need_seg = true; /* Needs segmentation */
}
mic_size = (need_seg && net_buf_simple_tailroom(msg) >= BLE_MESH_MIC_LONG) ?
mic_size = (need_seg && ctx->send_szmic == BLE_MESH_SEG_SZMIC_LONG &&
net_buf_simple_tailroom(msg) >= BLE_MESH_MIC_LONG) ?
BLE_MESH_MIC_LONG : BLE_MESH_MIC_SHORT;
if (need_seg) {
/* Based on the message length, calculate how many segments are needed.
* All the messages sent from here are access messages.
*/
seg_retrans_num = bt_mesh_get_seg_retrans_num();
seg_retrans_to = bt_mesh_get_seg_retrans_timeout(ctx->send_ttl);
seg_rtx_num = bt_mesh_get_seg_retrans_num();
seg_rtx_to = bt_mesh_get_seg_retrans_timeout(ctx->send_ttl);
seg_count = (msg->len + mic_size - 1) / 12U + 1U;
duration = bt_mesh_get_adv_duration();
duration = bt_mesh_get_adv_duration(ctx);
/* Currenlty only consider the time consumption of the same segmented
/* Currently only consider the time consumption of the same segmented
* messages, but if there are other messages between any two retrans-
* missions of the same segmented messages, then the whole time will
* be longer.
@ -200,7 +214,7 @@ static int32_t bt_mesh_client_calc_timeout(struct bt_mesh_msg_ctx *ctx,
* the attempts reaches ZERO when the dst is a unicast address.
*/
int32_t seg_duration = seg_count * (duration + HCI_TIME_FOR_START_ADV);
time = (seg_duration + seg_retrans_to) * seg_retrans_num;
time = (seg_duration + seg_rtx_to) * seg_rtx_num;
BT_INFO("Original timeout %dms, calculated timeout %dms", timeout, time);
@ -274,11 +288,6 @@ int bt_mesh_client_send_msg(bt_mesh_client_common_param_t *param,
return -EINVAL;
}
if (bt_mesh_set_client_model_role(param->model, param->msg_role)) {
BT_ERR("Failed to set client role");
return -EIO;
}
if (need_ack == false || !BLE_MESH_ADDR_IS_UNICAST(param->ctx.addr)) {
/* 1. If this is an unacknowledged message, send it directly.
* 2. If this is an acknowledged message, but the destination
@ -311,11 +320,11 @@ int bt_mesh_client_send_msg(bt_mesh_client_common_param_t *param,
}
memcpy(&node->ctx, &param->ctx, sizeof(struct bt_mesh_msg_ctx));
node->ctx.model = param->model;
node->model = param->model;
node->opcode = param->opcode;
node->op_pending = bt_mesh_client_get_status_op(client->op_pair, client->op_pair_size, param->opcode);
if (node->op_pending == 0U) {
BT_ERR("Not found the status opcode in op_pair list");
BT_ERR("Status opcode not found in op_pair list, opcode 0x%08x", param->opcode);
bt_mesh_free(node);
return -EINVAL;
}
@ -348,20 +357,6 @@ int bt_mesh_client_send_msg(bt_mesh_client_common_param_t *param,
static bt_mesh_mutex_t client_model_lock;
static inline void bt_mesh_client_model_mutex_new(void)
{
if (!client_model_lock.mutex) {
bt_mesh_mutex_create(&client_model_lock);
}
}
#if CONFIG_BLE_MESH_DEINIT
static inline void bt_mesh_client_model_mutex_free(void)
{
bt_mesh_mutex_free(&client_model_lock);
}
#endif /* CONFIG_BLE_MESH_DEINIT */
void bt_mesh_client_model_lock(void)
{
bt_mesh_mutex_lock(&client_model_lock);
@ -374,7 +369,7 @@ void bt_mesh_client_model_unlock(void)
int bt_mesh_client_init(struct bt_mesh_model *model)
{
bt_mesh_client_internal_data_t *data = NULL;
bt_mesh_client_internal_data_t *internal = NULL;
bt_mesh_client_user_data_t *client = NULL;
if (!model || !model->op) {
@ -388,23 +383,23 @@ int bt_mesh_client_init(struct bt_mesh_model *model)
return -EINVAL;
}
if (!client->internal_data) {
data = bt_mesh_calloc(sizeof(bt_mesh_client_internal_data_t));
if (!data) {
if (client->internal_data) {
BT_WARN("%s, Already", __func__);
return -EALREADY;
}
internal = bt_mesh_calloc(sizeof(bt_mesh_client_internal_data_t));
if (!internal) {
BT_ERR("%s, Out of memory", __func__);
return -ENOMEM;
}
/* Init the client data queue */
sys_slist_init(&data->queue);
sys_slist_init(&internal->queue);
client->model = model;
client->internal_data = data;
} else {
bt_mesh_client_clear_list(client->internal_data);
}
client->internal_data = internal;
bt_mesh_client_model_mutex_new();
bt_mesh_mutex_create(&client_model_lock);
return 0;
}
@ -434,7 +429,7 @@ int bt_mesh_client_deinit(struct bt_mesh_model *model)
client->internal_data = NULL;
}
bt_mesh_client_model_mutex_free();
bt_mesh_mutex_free(&client_model_lock);
return 0;
}
@ -445,12 +440,12 @@ int bt_mesh_client_free_node(bt_mesh_client_node_t *node)
bt_mesh_client_internal_data_t *internal = NULL;
bt_mesh_client_user_data_t *client = NULL;
if (!node || !node->ctx.model) {
if (!node || !node->model) {
BT_ERR("Invalid client list item");
return -EINVAL;
}
client = (bt_mesh_client_user_data_t *)node->ctx.model->user_data;
client = (bt_mesh_client_user_data_t *)node->model->user_data;
if (!client) {
BT_ERR("Invalid client user data");
return -EINVAL;
@ -466,6 +461,7 @@ int bt_mesh_client_free_node(bt_mesh_client_node_t *node)
bt_mesh_list_lock();
sys_slist_find_and_remove(&internal->queue, &node->client_node);
bt_mesh_list_unlock();
// Free the node
bt_mesh_free(node);
@ -494,27 +490,3 @@ int bt_mesh_client_clear_list(void *data)
return 0;
}
int bt_mesh_set_client_model_role(struct bt_mesh_model *model, uint8_t role)
{
bt_mesh_client_user_data_t *client = NULL;
if (!model) {
BT_ERR("Invalid client model");
return -EINVAL;
}
client = (bt_mesh_client_user_data_t *)model->user_data;
if (!client) {
BT_ERR("Invalid client user data");
return -EINVAL;
}
if (role >= ROLE_NVAL) {
BT_ERR("Invalid client role 0x%02x", role);
return -EINVAL;
}
client->msg_role = role;
return 0;
}

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