Initial commit: ESP32-C6 Zigbee Router project

This commit is contained in:
2025-11-01 16:04:31 +11:00
commit d430d8c3df
1760 changed files with 280339 additions and 0 deletions

View File

@@ -0,0 +1,134 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "esp_err.h"
#include "esp_zigbee_type.h"
/*!< Minimum commissioning period */
#define ESP_ZB_BDB_MIN_COMMISSIONING_TIME 180U
/**
* @brief Mask bit of the Base Device Behavior commissioning mode
*
*/
typedef enum esp_zb_bdb_commissioning_mode_mask_s {
ESP_ZB_BDB_INITIALIZATION = 0x00, /*!< BDB commissioning initialization bit */
ESP_ZB_BDB_TOUCHLINK_COMMISSIONING = 0x01, /*!< BDB Touchlink commissioning bit */
ESP_ZB_BDB_NETWORK_STEERING = 0x02, /*!< BDB commissioning network steering bit */
ESP_ZB_BDB_NETWORK_FORMATION = 0x04, /*!< BDB commissioning network formation bit */
ESP_ZB_BDB_FINDING_N_BINDING = 0x08, /*!< BDB commissioning finding & binding bit */
ESP_ZB_BDB_TOUCHLINK_TARGET = 0x40, /*!< BDB Touchlink commissioning target bit */
} esp_zb_bdb_commissioning_mode_mask_t;
/**
* @brief Enumeration of the typical Base Device Behavior (BDB) mode
*
*/
typedef enum {
ESP_ZB_BDB_MODE_INITIALIZATION = ESP_ZB_BDB_INITIALIZATION, /*!< BDB initialization mode */
ESP_ZB_BDB_MODE_TOUCHLINK_COMMISSIONING = ESP_ZB_BDB_TOUCHLINK_COMMISSIONING, /*!< BDB touchlink commissioning mode */
ESP_ZB_BDB_MODE_NETWORK_STEERING = ESP_ZB_BDB_NETWORK_STEERING, /*!< BDB network steering mode */
ESP_ZB_BDB_MODE_NETWORK_FORMATION = ESP_ZB_BDB_NETWORK_FORMATION, /*!< BDB network formation mode */
ESP_ZB_BDB_MODE_TOUCHLINK_TARGET = ESP_ZB_BDB_TOUCHLINK_TARGET, /*!< BDB network touchlink target mode */
} esp_zb_bdb_commissioning_mode_t;
/**
* @brief BDB commissioning status
*
*/
typedef enum esp_zb_bdb_commissioning_status_s
{
ESP_ZB_BDB_STATUS_SUCCESS = 0, /*!< The commissioning sub-procedure was successful. */
ESP_ZB_BDB_STATUS_IN_PROGRESS, /*!< One of the commissioning sub-procedures has started but is not yet complete. */
ESP_ZB_BDB_STATUS_NOT_AA_CAPABLE, /*!< The initiator is not address assignment capable during touchlink. */
ESP_ZB_BDB_STATUS_NO_NETWORK, /*!< A network has not been found during network steering or touchlink. */
ESP_ZB_BDB_STATUS_TARGET_FAILURE, /*!< A node has not joined a network when requested during touchlink. */
ESP_ZB_BDB_STATUS_FORMATION_FAILURE, /*!< A network could not be formed during network formation. */
ESP_ZB_BDB_STATUS_NO_IDENTIFY_QUERY_RESPONSE, /*!< No response to an identify query command has been received during finding and binding. */
ESP_ZB_BDB_STATUS_BINDING_TABLE_FULL, /*!< A binding table entry could not be created due to insufficient space in the binding table during finding and binding. */
ESP_ZB_BDB_STATUS_NO_SCAN_RESPONSE, /*!< No response to a scan request inter-PAN command has been received during touchlink. */
ESP_ZB_BDB_STATUS_NOT_PERMITTED, /*!< A touchlink (steal) attempt was made when a node is already connected to a centralized security network.
A node was instructed to form a network when it did not have a logical type of either Zigbee coordinator or Zigbee router. */
ESP_ZB_BDB_STATUS_TCLK_EX_FAILURE, /*!< The Trust Center link key exchange procedure has failed attempting to join a centralized security network. */
ESP_ZB_BDB_STATUS_NOT_ON_A_NETWORK, /*!< A commissioning procedure was forbidden since the node was not currently on a network. */
ESP_ZB_BDB_STATUS_ON_A_NETWORK, /*!< A commissioning procedure was forbidden since the node was currently on a network. */
ESP_ZB_BDB_STATUS_CANCELLED, /*!< The current operation (steering or formation) was cancelled by an app */
ESP_ZB_BDB_STATUS_DEV_ANNCE_SEND_FAILURE /*!< A device announce sending has been failed (e.g. device announce haven't acked by parent router). */
} esp_zb_bdb_commissioning_status_t;
/**
* @brief BDB find & binding commissioning callback state
*
*/
typedef enum esp_zb_bdb_commissioning_binding_cb_state_e {
ESP_ZB_BDB_COMM_BIND_SUCCESS = 0, /*!< Previously user applied bind finished successfully */
ESP_ZB_BDB_COMM_BIND_FAIL = 1, /*!< Previously user applied bind failed */
ESP_ZB_BDB_COMM_BIND_ASK_USER = 2, /*!< Ask user whether to perform binding */
} esp_zb_bdb_commissioning_binding_cb_state_t;
/**
* @brief A callback for the application to determine which clusters should be bound to the device during BDB finding & binding.
*
* @param[in] status The status of the callback. See @ref esp_zb_bdb_commissioning_binding_cb_state_t.
* @param[in] ieee_addr The IEEE address where the cluster is located.
* @param[in] ep_id The endpoint identifier where the cluster is located.
*
* @return true if the cluster should be bound; false otherwise.
*/
typedef bool (*esp_zb_bdb_binding_initiator_callback_t)(int16_t status, esp_zb_ieee_addr_t ieee_addr, uint8_t ep_id, uint16_t cluster_id);
/**
* @brief Start the endpoint in BDB Finding & Binding target commissioning mode.
*
* @param[in] ep_id The endpoint identifier to be started in BDB F&B target mode.
* @param[in] duration The duration (in seconds, ≥ ESP_ZB_BDB_MIN_COMMISSIONING_TIME) during which the BDB Finding and Binding target mode remains active.
*
* @return
* - ESP_OK: Success.
* - ESP_ERR_INVALID_ARG: Invalid argument; either the ep_id is not registered or the duration is out of range.
* - ESP_ERR_INVALID_STATE: Invalid state; the device is not connected to a network.
* - ESP_FAIL: Failure.
*/
esp_err_t esp_zb_bdb_finding_binding_start_target(uint8_t ep_id, uint16_t duration);
/**
* @brief Cancel the endpoint from BDB Finding & Binding target commissioning mode.
*
* @param[in] ep_id The endpoint identifier to be cancel from BDB F&B target mode.
*
* @return
* - ESP_OK: Success, otherwise, failure.
*/
esp_err_t esp_zb_bdb_finding_binding_cancel_target(uint8_t ep_id);
/**
* @brief Start the endpoint in BDB Finding & Binding initiator commissioning mode.
*
* @param[in] ep_id The endpoint identifier to be start in BDB F&B initiator mode.
* @param[in] cb The callback to be invoked when attempting to bind to a F&B target, See @ref esp_zb_bdb_binding_initiator_callback_t.
*
* @return
* - ESP_OK: Success.
* - ESP_ERR_INVALID_STATE: Invalid state; the device is not connected to a network.
* - ESP_FAIL: Failure.
*/
esp_err_t esp_zb_bdb_finding_binding_start_initiator(uint8_t ep_id, esp_zb_bdb_binding_initiator_callback_t cb);
/**
* @brief Cancel the endpoint from BDB Finding & Binding initiator commissioning mode.
*
* @return
* - ESP_OK: Success, otherwise, failure.
*/
esp_err_t esp_zb_bdb_finding_binding_cancel_initiator(void);
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,140 @@
/*
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include "esp_err.h"
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
#include "esp_zigbee_type.h"
/** @brief Enumeration of touchlink actions, that should be approved by end user application.
*
*/
typedef enum esp_zb_touchlink_action_s {
ESP_ZB_TOUCHLINK_ACTION_START_NEW_NETWORK,
ESP_ZB_TOUCHLINK_ACTION_JOIN_ROUTER,
ESP_ZB_TOUCHLINK_ACTION_JOIN_ED
} esp_zb_touchlink_action_t;
/** @brief Enumeration of touchlink key bitmask
*
*/
typedef enum esp_zb_touchlink_key_bitmask_s {
ESP_ZB_TOUCHLINK_MASTER_KEY = (1U << 4), /*!< Master key is a secret shared by all certified touchlink devices */
ESP_ZB_TOUCHLINK_CERTIFICATION_KEY = (1U << 15), /*!< Certification key is is used to allow testing of the security mechanisms */
} esp_zb_touchlink_key_bitmask_t;
/** Touchlink action callback
*
* @brief Touchlink action
*
* @param[in] action action of the touchlink, refer to esp_zb_touchlink_action_t
* @return
* - True: allow
* - False: reject
*
*/
typedef bool (*esp_zb_touchlink_action_allowed_callback_t)(uint8_t action);
/**
* @brief Zll identify callback
*
* @param[in] identify_on An indication that needs start or stop identify
*/
typedef void (*esp_zb_zll_identify_req_callback_t)(bool identify_on);
/**
* @brief Register the Zigbee touchlink action check handler
*
* @param[in] callback A callback that allow the user to determine whether the touchlink device
* can start a network or join as a router/end device, refer to esp_zb_touchlink_action_allowed_callback_t.
*
*/
esp_err_t esp_zb_touchlink_action_check_register(esp_zb_touchlink_action_allowed_callback_t callback);
/**
* @brief BDB touchlink network parameter information
*
*/
typedef struct esp_zb_bdb_signal_touchlink_nwk_params_s {
esp_zb_ieee_addr_t device_ieee_addr; /*!< address of device that started the network */
uint8_t endpoint; /*!< endpoint of device that started the network */
uint16_t profile_id; /*!< profile_id of device that started the network */
} esp_zb_bdb_signal_touchlink_nwk_params_t;
/** Touchlink clear factory new
*
* @brief Clear the factory new state
*
*/
void esp_zb_touchlink_clear_factory_new(void);
/**
* @brief Set the timeout for Touchlink target
*
* @param[in] timeout The waiting time for the device to exit the Touchlink target mode
*
*/
void esp_zb_zdo_touchlink_target_set_timeout(uint32_t timeout);
/**
* @brief Set the key bitmask for Touchlink commissioning
*
* Configures the key bitmask used for Touchlink commissioning. The network key will be encrypted
* using one of the key types specified in the bitmask. Higher priority is given to keys with higher
* bits. By default, the certification and master keys are included in the bitmask.
*
* @param[in] bitmask The bitmask to be applied for Touchlink commissioning
*
*/
void esp_zb_zdo_touchlink_set_key_bitmask(esp_zb_touchlink_key_bitmask_t bitmask);
/**
* @brief Set the master key for Touchlink
*
* @param[in] key The master key that will be utilized for the Touchlink network
*
*/
void esp_zb_zdo_touchlink_set_master_key(uint8_t *key);
/**
* @brief Set the RSSI threshold for the Touchlink target
*
* @note The default value for the RSSI threshold is set to -64
* @param[in] rssi_threshold The RSSI threshold determines whether the Touchlink target responds to the initiator
*
*/
void esp_zb_zdo_touchlink_set_rssi_threshold(int8_t rssi_threshold);
/**
* @brief Get the RSSI threshold of Touchlink target
*
* @return The value of RSSI threshold
*
*/
int8_t esp_zb_zdo_touchlink_get_rssi_threshold(void);
/**
* @brief Schedule to cancel touchlink target commissioning procedure
*
* @return
* - RET_OK: On success
* - RET_ERROR: Not in touchlink target procedure
*/
esp_err_t esp_zb_bdb_cancel_touchlink_target(void);
/**
* @brief Register ZLL identify request handler
*
* @param[in] cb A callback for zll identify notification, refer to esp_zb_zll_identify_req_callback_t
*/
void esp_zb_zll_identify_req_handler_register(esp_zb_zll_identify_req_callback_t cb);
#ifdef __cplusplus
}
#endif