11/*
2- * SPDX-FileCopyrightText: 2017-2024 Espressif Systems (Shanghai) CO LTD
2+ * SPDX-FileCopyrightText: 2017-2025 Espressif Systems (Shanghai) CO LTD
33 *
44 * SPDX-License-Identifier: Apache-2.0
55 */
@@ -20,6 +20,12 @@ extern "C" {
2020
2121/*!< The maximum length of a BLE Mesh message, including Opcode, Payload and TransMIC */
2222#define ESP_BLE_MESH_SDU_MAX_LEN 384
23+ #if CONFIG_BLE_MESH_LONG_PACKET
24+ /* Extended SDU maximum length (included Opcode, Payload and TransMIC) calculation:
25+ * SEGMENT_COUNT × (ADV_PAYLOAD_LEN - 17 bytes overhead)
26+ * 17 bytes = 9 bytes mesh network header + 4 bytes transport overhead + 4 bytes NetMIC */
27+ #define ESP_BLE_MESH_EXT_SDU_MAX_LEN (CONFIG_BLE_MESH_LONG_PACKET_TX_SEG_CNT * (CONFIG_BLE_MESH_LONG_PACKET_ADV_LEN - 17))
28+ #endif /* CONFIG_BLE_MESH_LONG_PACKET */
2329
2430/*!< Length of a short Mesh MIC. */
2531#define ESP_BLE_MESH_MIC_SHORT 4
@@ -613,6 +619,166 @@ struct esp_ble_mesh_model {
613619 */
614620#define ESP_BLE_MESH_MODEL_NONE ((esp_ble_mesh_model_t []){})
615621
622+ #if CONFIG_BLE_MESH_USE_BLE_50
623+ #define ESP_BLE_MESH_ADV_CHAN_UNASSIGNED (0)
624+ #define ESP_BLE_MESH_ADV_CHAN_37 BIT(0)
625+ #define ESP_BLE_MESH_ADV_CHAN_38 BIT(1)
626+ #define ESP_BLE_MESH_ADV_CHAN_39 BIT(2)
627+
628+ #define ESP_BLE_MESH_DEFAULT_CHANNEL_MAP (ESP_BLE_MESH_ADV_CHAN_37| \
629+ ESP_BLE_MESH_ADV_CHAN_38| \
630+ ESP_BLE_MESH_ADV_CHAN_39)
631+
632+ #define ESP_BLE_MESH_ADV_PHY_UNASSIGNED (0)
633+ #define ESP_BLE_MESH_ADV_PHY_1M (1)
634+ #define ESP_BLE_MESH_ADV_PHY_2M (2)
635+ #define ESP_BLE_MESH_ADV_PHY_CODED (3)
636+ #define ESP_BLE_MESH_ADV_PHY_DEFAULT ESP_BLE_MESH_ADV_PHY_1M
637+ #endif /* CONFIG_BLE_MESH_USE_BLE_50 */
638+
639+ /**
640+ * Enhanced configuration for Mesh messages with legacy advertising
641+ */
642+ typedef struct {
643+ /**
644+ * Advertising interval in milliseconds.
645+ * If set to 0, the Mesh protocol stack's xmit parameters are used.
646+ * If set to another value (e.g., 10), the advertising interval will be 10 ms.
647+ */
648+ uint32_t adv_itvl ;
649+
650+ /**
651+ * Number of advertising per packet.
652+ * If set to 0, the Mesh protocol stack's xmit parameters are used.
653+ * If set to another value (e.g., 3), the number of advertising per packet will be 3.
654+ */
655+ uint8_t adv_cnt ;
656+
657+ /**
658+ * Advertising channel map.
659+ * If set to 0, the protocol stack uses default channels.
660+ * If set to another value (e.g., ESP_BLE_MESH_ADV_CHAN_37),
661+ * the advertising channel map will be 0x01, the advertising
662+ * packet will only advertise on channel 37.
663+ */
664+ uint8_t channel_map ;
665+ } esp_ble_mesh_adv_cfg_t ;
666+
667+ #if CONFIG_BLE_MESH_EXT_ADV
668+ /** Enhanced configuration for Mesh messages with extended advertising */
669+ typedef struct {
670+ /**
671+ * Primary PHY for advertising (ESP_BLE_MESH_ADV_PHY_1M or
672+ * ESP_BLE_MESH_ADV_PHY_CODED).
673+ * When using coded PHY, receivers must use coded scanning.
674+ */
675+ uint8_t primary_phy ;
676+
677+ /**
678+ * Secondary PHY for advertising (ESP_BLE_MESH_ADV_PHY_1M,
679+ * ESP_BLE_MESH_ADV_PHY_2M, or ESP_BLE_MESH_ADV_PHY_CODED).
680+ * When using coded PHY, receivers must use coded scanning.
681+ */
682+ uint8_t secondary_phy ;
683+
684+ /**
685+ * Include TX power in advertising packets (0: disabled, 1: enabled).
686+ * Allows receivers/relays to maintain original transmission power.
687+ */
688+ uint8_t include_tx_power :1 ;
689+
690+ /** Transmission power level (in dBm) */
691+ int8_t tx_power ;
692+ } esp_ble_mesh_ext_adv_cfg_t ;
693+ #endif /* CONFIG_BLE_MESH_EXT_ADV */
694+
695+ #if CONFIG_BLE_MESH_LONG_PACKET
696+ /** Force this message to use long packet format */
697+ #define ESP_BLE_MESH_LONG_PACKET_FORCE (1)
698+
699+ /**
700+ * Whether to use the long packet mode will be chosen by the protocol stack,
701+ * which currently makes the decision based on message length.
702+ * Advertising using the standard BLE Mesh protocol when possible.
703+ * Switch to long packet mode for advertising when the standard BLE
704+ * Mesh protocol cannot be used.
705+ */
706+ #define ESP_BLE_MESH_LONG_PACKET_PREFER (2)
707+ #endif /* CONFIG_BLE_MESH_LONG_PACKET */
708+
709+ /** Enhanced message advertising parameters */
710+ typedef struct {
711+ /**
712+ * Use custom advertising parameters (0: disabled, 1: enabled).
713+ * When enabled, `adv_cfg` parameters override stack defaults.
714+ */
715+ uint8_t adv_cfg_used :1 ;
716+
717+ #if CONFIG_BLE_MESH_EXT_ADV
718+ /**
719+ * Use extended advertising parameters (0: disabled, 1: enabled).
720+ * When enabled, `ext_adv_cfg` parameters override stack defaults.
721+ */
722+ uint8_t ext_adv_cfg_used :1 ;
723+ #endif /* CONFIG_BLE_MESH_EXT_ADV */
724+
725+ #if CONFIG_BLE_MESH_LONG_PACKET
726+ /**
727+ * Control long packet usage (0: disabled, 1: enabled).
728+ * When disabled, the protocol stack cannot use long packets to
729+ * send this message.
730+ */
731+ uint8_t long_pkt_cfg_used :1 ;
732+ #endif /* CONFIG_BLE_MESH_LONG_PACKET */
733+
734+ /** Standard advertising parameters */
735+ esp_ble_mesh_adv_cfg_t adv_cfg ;
736+
737+ #if CONFIG_BLE_MESH_EXT_ADV
738+ /** Extended advertising parameters */
739+ esp_ble_mesh_ext_adv_cfg_t ext_adv_cfg ;
740+ #endif /* CONFIG_BLE_MESH_EXT_ADV */
741+
742+ #if CONFIG_BLE_MESH_LONG_PACKET
743+ /**
744+ * Long packet configuration:
745+ * - ESP_BLE_MESH_LONG_PACKET_FORCE
746+ * - ESP_BLE_MESH_LONG_PACKET_PREFER
747+ */
748+ uint8_t long_pkt_cfg :2 ;
749+ #endif /* CONFIG_BLE_MESH_LONG_PACKET */
750+ } esp_ble_mesh_msg_enh_params_t ;
751+
752+ #define ESP_BLE_MESH_ADV_CFG_NULL ((esp_ble_mesh_adv_cfg_t){0})
753+ #define ESP_BLE_MESH_EXT_ADV_CFG_NULL ((esp_ble_mesh_ext_adv_cfg_t){0})
754+
755+ #define ESP_BLE_MESH_ADV_CFG_DEFAULT \
756+ ((esp_ble_mesh_adv_cfg_t){\
757+ .adv_itvl= 0, \
758+ .adv_cnt = 0, \
759+ .channel_map = ESP_BLE_MESH_DEFAULT_CHANNEL_MAP, \
760+ })
761+
762+ #define ESP_BLE_MESH_EXT_ADV_CFG_DEFAULT \
763+ ((esp_ble_mesh_ext_adv_cfg_t){ \
764+ .primary_phy = ESP_BLE_MESH_ADV_PHY_1M, \
765+ .secondary_phy = ESP_BLE_MESH_ADV_PHY_1M, \
766+ .tx_power = 0x7f, \
767+ .include_tx_power = false,\
768+ })
769+
770+ #if CONFIG_BLE_MESH_LONG_PACKET
771+ #define ESP_BLE_MESH_LONG_PACKET_DEF_ENH_SET (ADV_CFG , EXT_ADV_CFG , LONG_PACKET_CFG ) \
772+ ((esp_ble_mesh_msg_enh_params_t){ \
773+ .adv_cfg_used = true,\
774+ .adv_cfg = ADV_CFG, \
775+ .ext_adv_cfg_used = true, \
776+ .ext_adv_cfg = EXT_ADV_CFG, \
777+ .long_pkt_cfg_used = true, \
778+ .long_pkt_cfg = LONG_PACKET_CFG, \
779+ })
780+ #endif /* CONFIG_BLE_MESH_LONG_PACKET */
781+
616782/** Message sending context.
617783 * This structure is associated with struct bt_mesh_msg_ctx in mesh_access.h
618784 */
@@ -664,6 +830,9 @@ typedef struct {
664830
665831 /** Indicate if the message is sent by a node server model, no need to be initialized before sending message */
666832 bool srv_send __attribute__((deprecated ));
833+
834+ /** Enhanced message advertising parameters */
835+ esp_ble_mesh_msg_enh_params_t enh ;
667836} esp_ble_mesh_msg_ctx_t ;
668837
669838/** Provisioning properties & capabilities.
0 commit comments