diff --git a/src/platform/include/CHIPDeviceConfig.h b/src/platform/include/CHIPDeviceConfig.h new file mode 100644 index 00000000000000..11e6833d5de01a --- /dev/null +++ b/src/platform/include/CHIPDeviceConfig.h @@ -0,0 +1,970 @@ +/* + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * Defines compile-time configuration values for the chip Device Layer. + */ + + + +#ifndef CHIP_DEVICE_CONFIG_H +#define CHIP_DEVICE_CONFIG_H + +/* Include a project-specific configuration file, if defined. + * + * An application or module that incorporates the chip Device Layer can define a project + * configuration file to override standard chip configuration with application-specific + * values. The project config file is typically located outside the Openchip source + * tree, alongside the source code for the application. + */ +#ifdef CHIP_DEVICE_PROJECT_CONFIG_INCLUDE +#include CHIP_DEVICE_PROJECT_CONFIG_INCLUDE +#endif + +/* Include a platform-specific configuration file, if defined. + * + * A platform configuration file contains overrides to standard chip Device Layer + * configuration that are specific to the platform or OS on which chip is running. + * It is typically provided as apart of an adaptation layer that adapts Openchip + * to the target environment. This adaptation layer may be included in the Openchip + * source tree itself or implemented externally. + */ +#ifdef CHIP_DEVICE_PLATFORM_CONFIG_INCLUDE +#include CHIP_DEVICE_PLATFORM_CONFIG_INCLUDE +#endif + +// -------------------- General Configuration -------------------- + +/** + * CHIP_DEVICE_CONFIG_CHIP_TASK_NAME + * + * The name of the chip task. + */ +#ifndef CHIP_DEVICE_CONFIG_CHIP_TASK_NAME +#define CHIP_DEVICE_CONFIG_CHIP_TASK_NAME "CHIP" +#endif + +/** + * CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE + * + * The size (in bytes) of the chip task stack. + */ +#ifndef CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE +#define CHIP_DEVICE_CONFIG_CHIP_TASK_STACK_SIZE 4096 +#endif + +/** + * CHIP_DEVICE_CONFIG_CHIP_TASK_PRIORITY + * + * The priority of the chip task. + */ +#ifndef CHIP_DEVICE_CONFIG_CHIP_TASK_PRIORITY +#define CHIP_DEVICE_CONFIG_CHIP_TASK_PRIORITY 1 +#endif + +/** + * CHIP_DEVICE_CONFIG_MAX_EVENT_QUEUE_SIZE + * + * The maximum number of events that can be held in the chip Platform event queue. + */ +#ifndef CHIP_DEVICE_CONFIG_MAX_EVENT_QUEUE_SIZE +#define CHIP_DEVICE_CONFIG_MAX_EVENT_QUEUE_SIZE 100 +#endif + +/** + * CHIP_DEVICE_CONFIG_SERVICE_DIRECTORY_CACHE_SIZE + * + * The size (in bytes) of the service directory cache. + */ +#ifndef CHIP_DEVICE_CONFIG_SERVICE_DIRECTORY_CACHE_SIZE +#define CHIP_DEVICE_CONFIG_SERVICE_DIRECTORY_CACHE_SIZE 512 +#endif + +/** + * CHIP_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE + * + * The maximum size (in bytes) of a debug logging message. + */ +#ifndef CHIP_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE +#define CHIP_DEVICE_CONFIG_LOG_MESSAGE_MAX_SIZE 256 +#endif + +/** + * CHIP_DEVICE_CONFIG_ENABLE_FACTORY_PROVISIONING + * + * Enable the device factory provisioning feature. + * + * The factory provisioning feature allows factory or developer-supplied provisioning information + * to be injected into a device at boot time and automatically stored in persistent storage. + */ +#ifndef CHIP_DEVICE_CONFIG_ENABLE_FACTORY_PROVISIONING +#define CHIP_DEVICE_CONFIG_ENABLE_FACTORY_PROVISIONING 1 +#endif + +/** + * CHIP_DEVICE_CONFIG_LOG_PROVISIONING_HASH + * + * Compute and log a hash of the device's provisioning data on boot. + * + * The generated hash value confirms to the form described in the CHIP: Factory + * Provisioning Specification. + */ +#ifndef CHIP_DEVICE_CONFIG_LOG_PROVISIONING_HASH +#define CHIP_DEVICE_CONFIG_LOG_PROVISIONING_HASH 1 +#endif + +// -------------------- Device Identification Configuration -------------------- + +/** + * CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID + * + * The CHIP-assigned vendor id for the organization responsible for producing the device. + */ +#ifndef CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID +#define CHIP_DEVICE_CONFIG_DEVICE_VENDOR_ID 9050 +#endif + +/** + * CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID + * + * The unique id assigned by the device vendor to identify the product or device type. This + * number is scoped to the device vendor id. + */ +#ifndef CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID +#define CHIP_DEVICE_CONFIG_DEVICE_PRODUCT_ID 65279 +#endif + +/** + * CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION + * + * The default product revision number assigned to the device or product by the device vendor. + * + * Product revisions are specific to a particular device vendor and product id, and typically + * correspond to a revision of the physical device, a change to its packaging, and/or a change + * to its marketing presentation. This value is generally *not* incremented for device software + * revisions. + * + * This is a default value which is used when a product revision has not been stored in device + * persistent storage (e.g. by a factory provisioning process). + */ +#ifndef CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION +#define CHIP_DEVICE_CONFIG_DEFAULT_DEVICE_PRODUCT_REVISION 1 +#endif + +/** + * CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION + * + * A string identifying the firmware revision running on the device. + */ +#ifndef CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION +#define CHIP_DEVICE_CONFIG_DEVICE_FIRMWARE_REVISION "prerelease" +#endif + +/** + * CHIP_DEVICE_CONFIG_USER_SELECTED_MODE_TIMEOUT_SEC + * + * The default amount of time (in whole seconds) that the device will remain in "user selected" + * mode. User selected mode is typically initiated by a button press, or other direct interaction + * by a user. While in user selected mode, the device will respond to Device Identify Requests + * that have the UserSelectedMode flag set. + */ +#ifndef CHIP_DEVICE_CONFIG_USER_SELECTED_MODE_TIMEOUT_SEC +#define CHIP_DEVICE_CONFIG_USER_SELECTED_MODE_TIMEOUT_SEC 30 +#endif // CHIP_DEVICE_CONFIG_USER_SELECTED_MODE_TIMEOUT_SEC + +// -------------------- WiFi Station Configuration -------------------- + +/** + * CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION + * + * Enable support for a WiFi station interface. + */ +#ifndef CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_STATION 1 +#endif + +/** + * CHIP_DEVICE_CONFIG_WIFI_STATION_RECONNECT_INTERVAL + * + * The interval at which the chip platform will attempt to reconnect to the configured WiFi + * network (in milliseconds). + */ +#ifndef CHIP_DEVICE_CONFIG_WIFI_STATION_RECONNECT_INTERVAL +#define CHIP_DEVICE_CONFIG_WIFI_STATION_RECONNECT_INTERVAL 5000 +#endif + +/** + * CHIP_DEVICE_CONFIG_MAX_SCAN_NETWORKS_RESULTS + * + * The maximum number of networks to return as a result of a NetworkProvisioning:ScanNetworks request. + */ +#ifndef CHIP_DEVICE_CONFIG_MAX_SCAN_NETWORKS_RESULTS +#define CHIP_DEVICE_CONFIG_MAX_SCAN_NETWORKS_RESULTS 10 +#endif + +/** + * CHIP_DEVICE_CONFIG_WIFI_SCAN_COMPLETION_TIMEOUT + * + * The amount of time (in milliseconds) after which the chip platform will timeout a WiFi scan + * operation that hasn't completed. A value of 0 will disable the timeout logic. + */ +#ifndef CHIP_DEVICE_CONFIG_WIFI_SCAN_COMPLETION_TIMEOUT +#define CHIP_DEVICE_CONFIG_WIFI_SCAN_COMPLETION_TIMEOUT 10000 +#endif + +/** + * CHIP_DEVICE_CONFIG_WIFI_CONNECTIVITY_TIMEOUT + * + * The amount of time (in milliseconds) to wait for Internet connectivity to be established on + * the device's WiFi station interface during a Network Provisioning TestConnectivity operation. + */ +#ifndef CHIP_DEVICE_CONFIG_WIFI_CONNECTIVITY_TIMEOUT +#define CHIP_DEVICE_CONFIG_WIFI_CONNECTIVITY_TIMEOUT 30000 +#endif + +/** + * CHIP_DEVICE_CONFIG_LWIP_WIFI_STATION_IF_NAME + * + * Name of the WiFi station interface on LwIP-based platforms. + */ +#ifndef CHIP_DEVICE_CONFIG_LWIP_WIFI_STATION_IF_NAME +#define CHIP_DEVICE_CONFIG_LWIP_WIFI_STATION_IF_NAME "wl" +#endif + +// -------------------- WiFi AP Configuration -------------------- + +/** + * CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP + * + * Enable support for a WiFi AP interface. + */ +#ifndef CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_AP 1 +#endif + +/** + * CHIP_DEVICE_CONFIG_WIFI_AP_SSID_PREFIX + * + * A prefix string used in forming the WiFi soft-AP SSID. The remainder of the SSID + * consists of the final two bytes of the device's primary WiFi MAC address in hex. + */ +#ifndef CHIP_DEVICE_CONFIG_WIFI_AP_SSID_PREFIX +#define CHIP_DEVICE_CONFIG_WIFI_AP_SSID_PREFIX "CHIP-" +#endif + +/** + * CHIP_DEVICE_CONFIG_WIFI_AP_CHANNEL + * + * The WiFi channel number to be used by the soft-AP. + */ +#ifndef CHIP_DEVICE_CONFIG_WIFI_AP_CHANNEL +#define CHIP_DEVICE_CONFIG_WIFI_AP_CHANNEL 1 +#endif + +/** + * CHIP_DEVICE_CONFIG_WIFI_AP_MAX_STATIONS + * + * The maximum number of stations allowed to connect to the soft-AP. + */ +#ifndef CHIP_DEVICE_CONFIG_WIFI_AP_MAX_STATIONS +#define CHIP_DEVICE_CONFIG_WIFI_AP_MAX_STATIONS 4 +#endif + +/** + * CHIP_DEVICE_CONFIG_WIFI_AP_BEACON_INTERVAL + * + * The beacon interval (in milliseconds) for the WiFi soft-AP. + */ +#ifndef CHIP_DEVICE_CONFIG_WIFI_AP_BEACON_INTERVAL +#define CHIP_DEVICE_CONFIG_WIFI_AP_BEACON_INTERVAL 100 +#endif + +/** + * CHIP_DEVICE_CONFIG_WIFI_AP_IDLE_TIMEOUT + * + * The amount of time (in milliseconds) after which the chip platform will deactivate the soft-AP + * if it has been idle. + */ +#ifndef CHIP_DEVICE_CONFIG_WIFI_AP_IDLE_TIMEOUT +#define CHIP_DEVICE_CONFIG_WIFI_AP_IDLE_TIMEOUT 120000 +#endif + +/** + * CHIP_DEVICE_CONFIG_LWIP_WIFI_AP_IF_NAME + * + * Name of the WiFi AP interface on LwIP-based platforms. + */ +#ifndef CHIP_DEVICE_CONFIG_LWIP_WIFI_AP_IF_NAME +#define CHIP_DEVICE_CONFIG_LWIP_WIFI_AP_IF_NAME "ap" +#endif + +// -------------------- BLE/WoBLE Configuration -------------------- + +/** + * CHIP_DEVICE_CONFIG_ENABLE_WOBLE + * + * Enable support for chip-over-BLE (WoBLE). + */ +#ifndef CHIP_DEVICE_CONFIG_ENABLE_WOBLE +#define CHIP_DEVICE_CONFIG_ENABLE_WOBLE 1 +#endif + +/** + * CHIP_DEVICE_CONFIG_SINGLE_WOBLE_CONNECTION + * + * Limit support for chip-over-BLE (WoBLE) to a single connection. + * When set, WoBLE advertisements will stop while a WoBLE connection is active. + */ +#ifndef CHIP_DEVICE_CONFIG_WOBLE_SINGLE_CONNECTION +#define CHIP_DEVICE_CONFIG_WOBLE_SINGLE_CONNECTION 0 +#endif + +/** + * CHIP_DEVICE_CONFIG_WOBLE_DISABLE_ADVERTISING_WHEN_PROVISIONED + * + * Automatically disable WoBLE advertising when the device transitions to a fully + * provisioned state. + */ +#ifndef CHIP_DEVICE_CONFIG_WOBLE_DISABLE_ADVERTISING_WHEN_PROVISIONED +#define CHIP_DEVICE_CONFIG_WOBLE_DISABLE_ADVERTISING_WHEN_PROVISIONED 0 +#endif + +/** + * CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX + * + * A prefix string used in forming the BLE device name. The remainder of the name + * consists of the final two bytes of the device's chip node id in hex. + * + * NOTE: The device layer limits the total length of a device name to 16 characters. + * However, due to other data sent in WoBLE advertise packets, the device name + * may need to be shorter. + */ +#ifndef CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX +#define CHIP_DEVICE_CONFIG_BLE_DEVICE_NAME_PREFIX "CHIP-" +#endif + +/** + * CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL + * + * The interval (in units of 0.625ms) at which the device will send BLE advertisements while + * in fast advertising mode. + * + * Defaults to 800 (500ms). + */ +#ifndef CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL +#define CHIP_DEVICE_CONFIG_BLE_FAST_ADVERTISING_INTERVAL 800 +#endif + +/** + * CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL + * + * The interval (in units of 0.625ms) at which the device will send BLE advertisements while + * in slow advertisement mode. + * + * Defaults to 3200 (20000ms). + */ +#ifndef CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL +#define CHIP_DEVICE_CONFIG_BLE_SLOW_ADVERTISING_INTERVAL 3200 +#endif + +// -------------------- Time Sync Configuration -------------------- + +/** + * CHIP_DEVICE_CONFIG_ENABLE_SERVICE_DIRECTORY_TIME_SYNC + * + * Enables synchronizing the device real-time clock using information returned during + * a chip service end point query. For any device that uses the chip service directory + * to lookup a tunnel server, enabling this option will result in the real time clock being + * synchronized every time the service tunnel is established. + */ +#ifndef CHIP_DEVICE_CONFIG_ENABLE_SERVICE_DIRECTORY_TIME_SYNC +#define CHIP_DEVICE_CONFIG_ENABLE_SERVICE_DIRECTORY_TIME_SYNC 1 +#endif + +/** + * CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC + * + * Enables synchronizing the device's real time clock with a remote chip Time service + * using the chip Time Sync protocol. + */ +#ifndef CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC +#define CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC 1 +#endif + +/** + * CHIP_DEVICE_CONFIG_CHIP_TIME_SERVICE_ENDPOINT_ID + * + * Specifies the service endpoint id of the chip Time Sync service to be used to synchronize time. + * + * This value is only meaningful if CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC has + * been enabled. + */ +#ifndef CHIP_DEVICE_CONFIG_CHIP_TIME_SERVICE_ENDPOINT_ID +#define CHIP_DEVICE_CONFIG_CHIP_TIME_SERVICE_ENDPOINT_ID 0x18B4300200000005ULL +#endif + +/** + * CHIP_DEVICE_CONFIG_DEFAULT_TIME_SYNC_INTERVAL + * + * Specifies the minimum interval (in seconds) at which the device should synchronize its real time + * clock with the configured chip Time Sync server. + * + * This value is only meaningful if CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC has + * been enabled. + */ +#ifndef CHIP_DEVICE_CONFIG_DEFAULT_TIME_SYNC_INTERVAL +#define CHIP_DEVICE_CONFIG_DEFAULT_TIME_SYNC_INTERVAL 180 +#endif + +/** + * CHIP_DEVICE_CONFIG_TIME_SYNC_TIMEOUT + * + * Specifies the maximum amount of time (in milliseconds) to wait for a response from a + * chip Time Sync server. + * + * This value is only meaningful if CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC has + * been enabled. + */ +#ifndef CHIP_DEVICE_CONFIG_TIME_SYNC_TIMEOUT +#define CHIP_DEVICE_CONFIG_TIME_SYNC_TIMEOUT 10000 +#endif + +// -------------------- Service Provisioning Configuration -------------------- + +/** + * CHIP_DEVICE_CONFIG_SERVICE_PROVISIONING_ENDPOINT_ID + * + * Specifies the service endpoint id of the chip Service Provisioning service. When a device + * undergoes service provisioning, this is the endpoint to which it will send its Pair Device + * to Account request. + */ +#ifndef CHIP_DEVICE_CONFIG_SERVICE_PROVISIONING_ENDPOINT_ID +#define CHIP_DEVICE_CONFIG_SERVICE_PROVISIONING_ENDPOINT_ID 0x18B4300200000010ULL +#endif + +/** + * CHIP_DEVICE_CONFIG_SERVICE_PROVISIONING_CONNECTIVITY_TIMEOUT + * + * The maximum amount of time (in milliseconds) to wait for service connectivity during the device + * service provisioning step. More specifically, this is the maximum amount of time the device will + * wait for connectivity to be established with the service at the point where the device waiting + * to send a Pair Device to Account request to the Service Provisioning service. + */ +#ifndef CHIP_DEVICE_CONFIG_SERVICE_PROVISIONING_CONNECTIVITY_TIMEOUT +#define CHIP_DEVICE_CONFIG_SERVICE_PROVISIONING_CONNECTIVITY_TIMEOUT 10000 +#endif + +/** + * CHIP_DEVICE_CONFIG_SERVICE_PROVISIONING_REQUEST_TIMEOUT + * + * Specifies the maximum amount of time (in milliseconds) to wait for a response from the Service + * Provisioning service. + */ +#ifndef CHIP_DEVICE_CONFIG_SERVICE_PROVISIONING_REQUEST_TIMEOUT +#define CHIP_DEVICE_CONFIG_SERVICE_PROVISIONING_REQUEST_TIMEOUT 10000 +#endif + +// -------------------- Just-In-Time Provisioning Configuration -------------------- + +/** + * CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING + * + * Enable just-in-time provisioning functionality in the chip Device Layer. + * + * When enabled, device creates and uses its ephemeral operational credentials: + * - operational device id + * - operational device self-signed certificate + * - operational device private key + * When enabled, device also implements certificate provisioning protocol and uses it to obtain + * service assigned certificate from the Certification Authority Service. + * + * Then, device uses these credentials to authenticate and communicate to other chip nodes. + */ +#ifndef CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING +#define CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING 0 +#endif + +// -------------------- Thread Configuration -------------------- + +/** + * CHIP_DEVICE_CONFIG_ENABLE_THREAD + * + * Enable support for Thread in the chip Device Layer. + */ +#ifndef CHIP_DEVICE_CONFIG_ENABLE_THREAD +#define CHIP_DEVICE_CONFIG_ENABLE_THREAD 0 +#endif + +/** + * CHIP_DEVICE_CONFIG_THREAD_TASK_NAME + * + * The name of the Thread task. + */ +#ifndef CHIP_DEVICE_CONFIG_THREAD_TASK_NAME +#define CHIP_DEVICE_CONFIG_THREAD_TASK_NAME "THREAD" +#endif + +/** + * CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE + * + * The size (in bytes) of the OpenThread task stack. + */ +#ifndef CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE +#define CHIP_DEVICE_CONFIG_THREAD_TASK_STACK_SIZE 8192 +#endif + +/** + * CHIP_DEVICE_CONFIG_THREAD_TASK_PRIORITY + * + * The priority of the OpenThread task. + */ +#ifndef CHIP_DEVICE_CONFIG_THREAD_TASK_PRIORITY +#define CHIP_DEVICE_CONFIG_THREAD_TASK_PRIORITY 2 +#endif + +/** + * CHIP_DEVICE_CONFIG_LWIP_THREAD_IF_NAME + * + * Name of the Thread interface on LwIP-based platforms. + */ +#ifndef CHIP_DEVICE_CONFIG_LWIP_THREAD_IF_NAME +#define CHIP_DEVICE_CONFIG_LWIP_THREAD_IF_NAME "th" +#endif + +/** + * CHIP_DEVICE_CONFIG_THREAD_IF_MTU + * + * Default MTU for Thread interface + */ +#ifndef CHIP_DEVICE_CONFIG_THREAD_IF_MTU +#define CHIP_DEVICE_CONFIG_THREAD_IF_MTU 1280 +#endif + +/** + * CHIP_DEVICE_CONFIG_DEFAULT_THREAD_NETWORK_NAME_PREFIX + * + * A prefix string to be used when forming a default Thread network name. + */ +#ifndef CHIP_DEVICE_CONFIG_DEFAULT_THREAD_NETWORK_NAME_PREFIX +#define CHIP_DEVICE_CONFIG_DEFAULT_THREAD_NETWORK_NAME_PREFIX "CHIP-PAN-" +#endif + +/** + * CHIP_DEVICE_CONFIG_THREAD_CONNECTIVITY_TIMEOUT + * + * The amount of time (in milliseconds) to wait for connectivity with a Thread mesh + * to be established on during a Network Provisioning TestConnectivity operation. + */ +#ifndef CHIP_DEVICE_CONFIG_THREAD_CONNECTIVITY_TIMEOUT +#define CHIP_DEVICE_CONFIG_THREAD_CONNECTIVITY_TIMEOUT 30000 +#endif + +// -------------------- Tunnel Configuration -------------------- + +/** + * CHIP_DEVICE_CONFIG_LWIP_SERVICE_TUN_IF_NAME + * + * Name of the service TUN interface on LwIP-based platforms. + */ +#ifndef CHIP_DEVICE_CONFIG_LWIP_SERVICE_TUN_IF_NAME +#define CHIP_DEVICE_CONFIG_LWIP_SERVICE_TUN_IF_NAME "tn" +#endif + +// -------------------- Trait Manager Configuration -------------------- + +/** + * CHIP_DEVICE_CONFIG_ENABLE_TRAIT_MANAGER + * + * Enable or disable the chip Trait Manager. + * + * NOTE: The Trait Manager is an experimental feature of the chip Device Layer. + */ +#ifndef CHIP_DEVICE_CONFIG_ENABLE_TRAIT_MANAGER +#define CHIP_DEVICE_CONFIG_ENABLE_TRAIT_MANAGER 0 +#endif + +// -------------------- Test Configuration -------------------- + +/** + * CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY + * + * Enables the use of a hard-coded default chip device id and credentials if no device id + * is found in chip NV storage. The value specifies which of 10 identities, numbered 1 through 10, + * is to be used. A value of 0 disables use of a default identity. + * + * This option is for testing only and should be disabled in production releases. + */ +#ifndef CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY +#define CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY 0 +#endif + +/** + * CHIP_DEVICE_CONFIG_ENABLE_FIXED_TUNNEL_SERVER + * + * Forces the use of a service tunnel server at a fixed IP address and port. This + * bypasses the need for a directory query to the service directory endpoint to + * determine the tunnel server address. When enabled, this option allows devices + * that haven't been service provisioned to establish a service tunnel. + * + * When this option is enabled, CHIP_DEVICE_CONFIG_TUNNEL_SERVER_ADDRESS must + * be set to the address of the tunnel server. + */ +#ifndef CHIP_DEVICE_CONFIG_ENABLE_FIXED_TUNNEL_SERVER +#define CHIP_DEVICE_CONFIG_ENABLE_FIXED_TUNNEL_SERVER 0 +#endif + + +/** CHIP_DEVICE_CONFIG_TUNNEL_SERVER_ADDRESS + * + * The address of the server to which the device should establish a service tunnel. + * + * This value is only meaningful if CHIP_DEVICE_CONFIG_ENABLE_FIXED_TUNNEL_SERVER + * has been enabled. + * + * Note: Currently this must be a dot-notation IP address--not a host name. + */ +#ifndef CHIP_DEVICE_CONFIG_TUNNEL_SERVER_ADDRESS +#define CHIP_DEVICE_CONFIG_TUNNEL_SERVER_ADDRESS "" +#endif + +/** + * CHIP_DEVICE_CONFIG_DISABLE_ACCOUNT_PAIRING + * + * Disables sending the PairDeviceToAccount request to the service during a RegisterServicePairAccount + * operation. When this option is enabled, the device will perform all local operations associated + * with registering a service, but will not request the service to add the device to the user's account. + */ +#ifndef CHIP_DEVICE_CONFIG_DISABLE_ACCOUNT_PAIRING +#define CHIP_DEVICE_CONFIG_DISABLE_ACCOUNT_PAIRING 0 +#endif + +// -------------------- Network Telemetry Configuration -------------------- + +/** + * @def CHIP_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY + * + * @brief + * Enable automatically uploading Wi-Fi telemetry via trait on an interval. + */ +#ifndef CHIP_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY +#define CHIP_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY (0) +#endif + +/** + * @def CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY + * + * @brief + * Enable automatically uploading minimal Thread telemetry and topology via trait on an interval. + */ +#ifndef CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY +#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY (0) +#endif + +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY && !CHIP_DEVICE_CONFIG_ENABLE_THREAD +#error "If CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY set, then CHIP_DEVICE_CONFIG_ENABLE_THREAD must also be set." +#endif + +/** + * @def CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY_FULL + * + * @brief + * Enable automatically uploading all Thread telemetry and topology via trait on an interval. + * This is suitable for products that have router capability. + * + * @note + * If set, CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY must also be set. + */ +#ifndef CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY_FULL +#define CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY_FULL (0) +#endif + +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY_FULL && !CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY +#error "If CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY_FULL set, then CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY must also be set." +#endif + +/** + * @def CHIP_DEVICE_CONFIG_ENABLE_TUNNEL_TELEMETRY + * + * @brief + * Enable automatically uploading chip tunnel telemetry via trait on an interval. + */ +#ifndef CHIP_DEVICE_CONFIG_ENABLE_TUNNEL_TELEMETRY +#define CHIP_DEVICE_CONFIG_ENABLE_TUNNEL_TELEMETRY (0) +#endif + +#if CHIP_DEVICE_CONFIG_ENABLE_TUNNEL_TELEMETRY && !CHIP_CONFIG_ENABLE_TUNNELING +#error "If CHIP_DEVICE_CONFIG_ENABLE_TUNNEL_TELEMETRY set, then CHIP_CONFIG_ENABLE_TUNNELING must also be set." +#endif + +// Enable Network Telemetry feature if it is enabled for at lease one network. +#define CHIP_DEVICE_CONFIG_ENABLE_NETWORK_TELEMETRY (CHIP_DEVICE_CONFIG_ENABLE_WIFI_TELEMETRY || \ + CHIP_DEVICE_CONFIG_ENABLE_THREAD_TELEMETRY || \ + CHIP_DEVICE_CONFIG_ENABLE_TUNNEL_TELEMETRY) + +/** + * @def CHIP_DEVICE_CONFIG_DEFAULT_TELEMETRY_INTERVAL_MS + * + * @brief + * This sets the default interval at which network telemetry events + * will be logged to chip buffers. This can be overwritten at runtime + * with a trait. + * + */ +#ifndef CHIP_DEVICE_CONFIG_DEFAULT_TELEMETRY_INTERVAL_MS +#define CHIP_DEVICE_CONFIG_DEFAULT_TELEMETRY_INTERVAL_MS 90000 +#endif + +/** + * @def CHIP_DEVICE_CONFIG_DEFAULT_TUNNEL_TELEMETRY_INTERVAL_MS + * + * @brief + * This sets the default interval at which chip tunnel telemetry events + * will be logged to chip buffers. + * + */ +#ifndef CHIP_DEVICE_CONFIG_DEFAULT_TUNNEL_TELEMETRY_INTERVAL_MS +#define CHIP_DEVICE_CONFIG_DEFAULT_TUNNEL_TELEMETRY_INTERVAL_MS 300000 +#endif + +// -------------------- Event Logging Configuration -------------------- + +/** + * @def CHIP_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE + * + * @brief + * A size, in bytes, of the individual critical event logging buffer. + * Note: the critical event buffer must exist. + */ +#ifndef CHIP_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE (1024) +#endif + +#if (CHIP_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE <= 0) +#error "The Prod critical event buffer must exist (CHIP_DEVICE_CONFIG_EVENT_LOGGING_CRIT_BUFFER_SIZE > 0)" +#endif + +/** + * @def CHIP_DEVICE_CONFIG_EVENT_LOGGING_PROD_BUFFER_SIZE + * + * @brief + * A size, in bytes, of the individual production event logging buffer. + * Note: the production event buffer must exist. + */ +#ifndef CHIP_DEVICE_CONFIG_EVENT_LOGGING_PROD_BUFFER_SIZE +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_PROD_BUFFER_SIZE (512) +#endif + +#if (CHIP_DEVICE_CONFIG_EVENT_LOGGING_PROD_BUFFER_SIZE <= 0) +#error "The Prod event buffer must exist (CHIP_DEVICE_CONFIG_EVENT_LOGGING_PROD_BUFFER_SIZE > 0)" +#endif + +/** + * @def CHIP_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE + * + * @brief + * A size, in bytes, of the individual info event logging buffer. + * Note: set to 0 to disable info event buffer and all support + * for the info level events. + */ +#ifndef CHIP_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_INFO_BUFFER_SIZE (512) +#endif + +/** + * @def CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE + * + * @brief + * A size, in bytes, of the individual debug event logging buffer. + * Note: set to 0 to disable debug event buffer and all support + * for the debug level events. + */ +#ifndef CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE +#define CHIP_DEVICE_CONFIG_EVENT_LOGGING_DEBUG_BUFFER_SIZE (256) +#endif + +/** + * @def CHIP_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH + * + * @brief + * The event id counter persisted storage epoch. + */ +#ifndef CHIP_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH +#define CHIP_DEVICE_CONFIG_EVENT_ID_COUNTER_EPOCH (0x10000) +#endif + +/** + * @def CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_CRIT_EIDC_KEY + * + * @brief + * The critical event id counter (eidc) persisted storage key. + */ +#ifndef CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_CRIT_EIDC_KEY +#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_CRIT_EIDC_KEY "crit-eidc" +#endif + +/** + * @def CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_PROD_EIDC_KEY + * + * @brief + * The production event id counter (eidc) persisted storage key. + */ +#ifndef CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_PROD_EIDC_KEY +#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_PROD_EIDC_KEY "prod-eidc" +#endif + +/** + * @def CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_INFO_EIDC_KEY + * + * @brief + * The info event id counter (eidc) persisted storage key. + */ +#ifndef CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_INFO_EIDC_KEY +#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_INFO_EIDC_KEY "info-eidc" +#endif + +/** + * @def CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_DEBUG_EIDC_KEY + * + * @brief + * The debug event id counter (eidc) persisted storage key. + */ +#ifndef CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_DEBUG_EIDC_KEY +#define CHIP_DEVICE_CONFIG_PERSISTED_STORAGE_DEBUG_EIDC_KEY "debug-eidc" +#endif + +// -------------------- Software Update Manager Configuration -------------------- + +/** + * CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER + * + * Enable or disable the chip Software Update Manager. + * + */ +#ifndef CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER +#define CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER 1 +#endif + +/** + * CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_URI_LEN + * + * Specifies the size in bytes of the buffer that stores the + * URI + * + */ +#ifndef CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_URI_LEN +#define CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_URI_LEN 128 +#endif + +/** + * CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_ENDPOINT_ID + * + * Specifies the service endpoint id of the chip Software Update service. When a device + * attempts software update, this is the endpoint to which it will send its Software Update + * Query request. + */ +#ifndef CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_ENDPOINT_ID +#define CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_ENDPOINT_ID 0x18B4300200000002ULL +#endif + +/** + * CHIP_DEVICE_CONFIG_FILE_DOWNLOAD_ENDPOINT_ID + * + * Specifies the service endpoint id of the chip File Download service. When a device + * attempts file download over BDX, this is the endpoint to which it will send its BDX request. + */ +#ifndef CHIP_DEVICE_CONFIG_FILE_DOWNLOAD_ENDPOINT_ID +#define CHIP_DEVICE_CONFIG_FILE_DOWNLOAD_ENDPOINT_ID 0x18B4300200000013ULL +#endif + +/** + * CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_RESPOSNE_TIMEOUT + * + * Specifies the maximum amount of time (in milliseconds) to wait for a response from a + * chip Software Update service. + * + */ +#ifndef CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_RESPOSNE_TIMEOUT +#define CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_RESPOSNE_TIMEOUT 10000 +#endif + +/** + * CHIP_DEVICE_CONFIG_FILE_DOWNLOAD_RESPOSNE_TIMEOUT + * + * Specifies the maximum amount of time (in milliseconds) to wait for a response from a + * chip File Download service. + * + */ +#ifndef CHIP_DEVICE_CONFIG_FILE_DOWNLOAD_RESPOSNE_TIMEOUT +#define CHIP_DEVICE_CONFIG_FILE_DOWNLOAD_RESPOSNE_TIMEOUT 10000 +#endif + +/** + * CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_MAX_RETRIES + * + * Specifies the maximum number of times a failed software is retried. + * + */ +#ifndef CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_MAX_RETRIES +#define CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_MAX_RETRIES 5 +#endif + +/** + * CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_MAX_WAIT_TIME_INTERVAL_MS + * + * If scheduled software update check is disabled & default retry policy is used, + * specify the max wait time interval to be used (in milliseconds) + */ +#ifndef CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_MAX_WAIT_TIME_INTERVAL_MS +#define CHIP_DEVICE_CONFIG_SOFTWARE_UPDATE_MAX_WAIT_TIME_INTERVAL_MS 1*60*60*1000 // 1 hour +#endif + +/** + * @def CHIP_DEVICE_CONFIG_SWU_MIN_WAIT_TIME_INTERVAL_PERCENT_PER_STEP + * + * @brief + * If default software update retry policy is used, + * specify the minimum wait + * time as a percentage of the max wait interval for that step. + * + */ +#ifndef CHIP_DEVICE_CONFIG_SWU_MIN_WAIT_TIME_INTERVAL_PERCENT_PER_STEP +#define CHIP_DEVICE_CONFIG_SWU_MIN_WAIT_TIME_INTERVAL_PERCENT_PER_STEP 50 +#endif + +/** + * @def CHIP_DEVICE_CONFIG_SWU_WAIT_TIME_MULTIPLIER_MS + * + * @brief + * If default software update retry policy is used, + * specify the multiplier that multiplies the result of a Fibonacci computation + * based on a specific index to provide a max wait time for + * a step. + * + */ +#ifndef CHIP_DEVICE_CONFIG_SWU_WAIT_TIME_MULTIPLIER_MS +#define CHIP_DEVICE_CONFIG_SWU_WAIT_TIME_MULTIPLIER_MS 1*60*1000 // 1 minute +#endif + +/** + * CHIP_DEVICE_CONFIG_SWU_BDX_BLOCK_SIZE + * + * Specifies the block size to be used during software download over BDX. + */ +#define CHIP_DEVICE_CONFIG_SWU_BDX_BLOCK_SIZE 1024 + +#endif // CHIP_DEVICE_CONFIG_H diff --git a/src/platform/include/CHIPDeviceError.h b/src/platform/include/CHIPDeviceError.h new file mode 100644 index 00000000000000..03b1522b750262 --- /dev/null +++ b/src/platform/include/CHIPDeviceError.h @@ -0,0 +1,62 @@ +/* + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CHIP_DEVICE_ERROR_H +#define CHIP_DEVICE_ERROR_H + + +#define CHIP_DEVICE_ERROR_MIN 11000000 +#define CHIP_DEVICE_ERROR_MAX 11000999 +#define _CHIP_DEVICE_ERROR(e) (CHIP_DEVICE_ERROR_MIN + (e)) + +/** + * @def CHIP_DEVICE_ERROR_CONFIG_VALUE_NOT_FOUND + * + * @brief + * The requested configuration value was not found. + * + */ +#define CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND _CHIP_DEVICE_ERROR(1) + +/** + * @def CHIP_DEVICE_ERROR_NOT_SERVICE_PROVISIONED + * + * @brief + * The device has not been service provisioned. + * + */ +#define CHIP_DEVICE_ERROR_NOT_SERVICE_PROVISIONED _CHIP_DEVICE_ERROR(2) + +/** + * @def CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED + * + * @brief + * The software update was aborted by application + * + */ +#define CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_ABORTED _CHIP_DEVICE_ERROR(3) + +/** + * @def CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_IGNORED + * + * @brief + * The software update was ignored by application. + * + */ +#define CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_IGNORED _CHIP_DEVICE_ERROR(4) + +#endif // CHIP_DEVICE_ERROR_H diff --git a/src/platform/include/CHIPDeviceEvent.h b/src/platform/include/CHIPDeviceEvent.h new file mode 100644 index 00000000000000..59fa2a2d942516 --- /dev/null +++ b/src/platform/include/CHIPDeviceEvent.h @@ -0,0 +1,408 @@ +/* + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * Defines events used by the chip Device Layer to signal actions + * or changes in device state. + */ + +#ifndef CHIP_DEVICE_EVENT_H +#define CHIP_DEVICE_EVENT_H + +namespace chip { +namespace DeviceLayer { + +namespace DeviceEventType { + +enum +{ + kFlag_IsPublic = 0x8000, + kFlag_IsPlatformSpecific = 0x4000, + kFlag_Reserved1 = 0x2000, + kFlag_Reserved2 = 0x1000, + kMaxEventNum = 0x0FFF, +}; + +/** + * Event Type Ranges + * + * Defines numeric ranges for event types based on their visibility to the application, + * an whether or not they are specific to a particular platform adaptation. + */ +enum EventTypeRanges +{ + /** + * Public Event Range + * + * Denotes a range of event types that are publicly visible to applications. Events in this + * range a generic to all platforms. + */ + kRange_Public = kFlag_IsPublic, + + /** + * Public, Platform-specific Event Range + * + * Denotes a range of platform-specific event types that are publicly visible to applications. + */ + kRange_PublicPlatformSpecific = kFlag_IsPublic | kFlag_IsPlatformSpecific, + + /** + * Internal Event Range + * + * Denotes a range of event types that are internal to the chip Device Layer. Events in this + * range a generic to all platforms. + */ + kRange_Internal = 0, + + /** + * Internal, Platform-specific Event Range + * + * Denotes a range of platform-specific event types that are internal to the chip Device Layer. + */ + kRange_InternalPlatformSpecific = kFlag_IsPlatformSpecific, +}; + +inline bool IsPublic(uint16_t eventType) { return (eventType & kFlag_IsPublic) != 0; } +inline bool IsInternal(uint16_t eventType) { return (eventType & kFlag_IsPublic) == 0; } +inline bool IsPlatformSpecific(uint16_t eventType) { return (eventType & kFlag_IsPlatformSpecific) != 0; } +inline bool IsPlatformGeneric(uint16_t eventType) { return (eventType & kFlag_IsPlatformSpecific) == 0; } + +/** + * Public Event Types + * + * Enumerates event types that are visible to the application and common across + * all platforms. + */ +enum PublicEventTypes +{ + /** + * WiFi Connectivity Change + * + * Signals a change in connectivity of the device's WiFi station interface. + */ + kWiFiConnectivityChange = kRange_Public, + + /** + * Thread Connectivity Change + * + * Signals a change in connectivity of the device's Thread interface. + */ + kThreadConnectivityChange, + + /** + * Internet Connectivity Change + * + * Signals a change in the device's ability to communicate via the Internet. + */ + kInternetConnectivityChange, + + /** + * Service Tunnel State Change + * + * Signals a change in connectivity of the device's IP tunnel to a chip-enabled service. + */ + kServiceTunnelStateChange, + + /** + * Service Connectivity Change + * + * Signals a change in the device's ability to communicate with a chip-enabled service. + */ + kServiceConnectivityChange, + + /** + * Service Subscription State Change + * + * Signals a change in the device's WDM subscription state with a chip-enabled service. + */ + kServiceSubscriptionStateChange, + + /** + * Fabric Membership Change + * + * Signals a change in the device's membership in a chip fabric. + */ + kFabricMembershipChange, + + /** + * Service Provisioning Change + * + * Signals a change to the device's service provisioning state. + */ + kServiceProvisioningChange, + + /** + * Account Pairing Change + * + * Signals a change to the device's state with respect to being paired to a user account. + */ + kAccountPairingChange, + + /** + * Time Sync Change + * + * Signals a change to the device's real time clock synchronization state. + */ + kTimeSyncChange, + + /** + * Security Session Established + * + * Signals that an external entity has established a new security session with the device. + */ + kSessionEstablished, + + /** + * WoBLE Connection Established + * + * Signals that an external entity has established a new WoBLE connection with the device. + */ + kWoBLEConnectionEstablished, + + /** + * Thread State Change + * + * Signals that a state change has occurred in the Thread stack. + */ + kThreadStateChange, + + /** + * Thread Interface State Change + * + * Signals that the state of the Thread network interface has changed. + */ + kThreadInterfaceStateChange, + + /** + * chip-over-BLE (WoBLE) Advertising Change + * + * Signals that the state of WoBLE advertising has changed. + */ + kWoBLEAdvertisingChange, +}; + +/** + * Internal Event Types + * + * Enumerates event types that are internal to the chip Device Layer, but common across + * all platforms. + */ +enum InternalEventTypes +{ + kEventTypeNotSet = kRange_Internal, + kNoOp, + kCallWorkFunct, + kChipSystemLayerEvent, + kWoBLESubscribe, + kWoBLEUnsubscribe, + kWoBLEWriteReceived, + kWoBLEIndicateConfirm, + kWoBLEConnectionError, +}; + +static_assert(kEventTypeNotSet == 0, "kEventTypeNotSet must be defined as 0"); + +} // namespace DeviceEventType + +/** + * Connectivity Change + * + * Describes a change in some aspect of connectivity associated with a chip device. + */ +enum ConnectivityChange +{ + kConnectivity_NoChange = 0, + kConnectivity_Established = 1, + kConnectivity_Lost = -1 +}; + +/** + * Activity Change + * + * Describes a change in some activity associated with a chip device. + */ +enum ActivityChange +{ + kActivity_NoChange = 0, + kActivity_Started = 1, + kActivity_Stopped = -1, +}; + +inline ConnectivityChange GetConnectivityChange(bool prevState, bool newState) +{ + if (prevState == newState) + return kConnectivity_NoChange; + else if (newState) + return kConnectivity_Established; + else + return kConnectivity_Lost; +} + +/** + * A pointer to a function that performs work asynchronously. + */ +typedef void (*AsyncWorkFunct)(intptr_t arg); + +} // namespace DeviceLayer +} // namespace chip + +/* Include a header file containing platform-specific event definitions. + */ +#ifdef EXTERNAL_CHIPDEVICEPLATFORMEVENT_HEADER +#include EXTERNAL_CHIPDEVICEPLATFORMEVENT_HEADER +#else +#define CHIPDEVICEPLATFORMEVENT_HEADER +#include CHIPDEVICEPLATFORMEVENT_HEADER +#endif + +namespace chip { +namespace DeviceLayer { + +/** + * Represents a chip Device Layer event. + */ +struct ChipDeviceEvent final +{ + uint16_t Type; + + union + { + ChipDevicePlatformEvent Platform; + struct + { + ::chip::System::EventType Type; + ::chip::System::Object * Target; + uintptr_t Argument; + } ChipSystemLayerEvent; + struct + { + AsyncWorkFunct WorkFunct; + intptr_t Arg; + } CallWorkFunct; + struct + { + ConnectivityChange Result; + } WiFiConnectivityChange; + struct + { + ConnectivityChange Result; + } ThreadConnectivityChange; + struct + { + ConnectivityChange IPv4; + ConnectivityChange IPv6; + } InternetConnectivityChange; + struct + { + ConnectivityChange Result; + bool IsRestricted; + } ServiceTunnelStateChange; + struct + { + struct + { + ConnectivityChange Result; + } Overall; + struct + { + ConnectivityChange Result; + } ViaTunnel; + struct + { + ConnectivityChange Result; + } ViaThread; + } ServiceConnectivityChange; + struct + { + ConnectivityChange Result; + } ServiceSubscriptionStateChange; + struct + { + bool IsMemberOfFabric; + } FabricMembershipChange; + struct + { + bool IsServiceProvisioned; + bool ServiceConfigUpdated; + } ServiceProvisioningChange; + struct + { + bool IsPairedToAccount; + } AccountPairingChange; + struct + { + bool IsTimeSynchronized; + } TimeSyncChange; + struct + { + uint64_t PeerNodeId; + uint16_t SessionKeyId; + uint8_t EncType; + ::chip::ChipAuthMode AuthMode; + bool IsCommissioner; + } SessionEstablished; + struct + { + BLE_CONNECTION_OBJECT ConId; + } WoBLESubscribe; + struct + { + BLE_CONNECTION_OBJECT ConId; + } WoBLEUnsubscribe; + struct + { + BLE_CONNECTION_OBJECT ConId; + PacketBuffer * Data; + } WoBLEWriteReceived; + struct + { + BLE_CONNECTION_OBJECT ConId; + } WoBLEIndicateConfirm; + struct + { + BLE_CONNECTION_OBJECT ConId; + CHIP_ERROR Reason; + } WoBLEConnectionError; + struct + { + bool RoleChanged : 1; + bool AddressChanged : 1; + bool NetDataChanged : 1; + bool ChildNodesChanged : 1; + struct + { + uint32_t Flags; + } OpenThread; + } ThreadStateChange; + struct + { + ActivityChange Result; + } WoBLEAdvertisingChange; + }; + + void Clear() { memset(this, 0, sizeof(*this)); } + bool IsPublic() const { return DeviceEventType::IsPublic(Type); } + bool IsInternal() const { return DeviceEventType::IsInternal(Type); } + bool IsPlatformSpecific() const { return DeviceEventType::IsPlatformSpecific(Type); } + bool IsPlatformGeneric() const { return DeviceEventType::IsPlatformGeneric(Type); } +}; + +} // namespace DeviceLayer +} // namespace chip + +#endif // CHIP_DEVICE_EVENT_H diff --git a/src/platform/include/CHIPDeviceLayer.h b/src/platform/include/CHIPDeviceLayer.h new file mode 100644 index 00000000000000..67c4ab2d9cba20 --- /dev/null +++ b/src/platform/include/CHIPDeviceLayer.h @@ -0,0 +1,54 @@ +/* + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CHIP_DEVICE_H +#define CHIP_DEVICE_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER +#include +#endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER +#include +#if CHIP_DEVICE_CONFIG_ENABLE_THREAD +#include +#endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD + +namespace chip { +namespace DeviceLayer { + +struct chipDeviceEvent; + +using chip::FabricState; +using chip::MessageLayer; +using chip::ExchangeMgr; +using chip::SecurityMgr; + +extern chip::System::Layer SystemLayer; +extern Inet::InetLayer InetLayer; + +} // namespace DeviceLayer +} // namespace chip + +#endif // CHIP_DEVICE_H diff --git a/src/platform/include/CHIPDeviceLayerInternal.h b/src/platform/include/CHIPDeviceLayerInternal.h new file mode 100644 index 00000000000000..ca1b27fc401224 --- /dev/null +++ b/src/platform/include/CHIPDeviceLayerInternal.h @@ -0,0 +1,54 @@ +/* + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CHIP_DEVICE_INTERNAL_H +#define CHIP_DEVICE_INTERNAL_H + +namespace chip { +namespace Logging { + +enum +{ + kLogModule_DeviceLayer = 255, +}; + +} // namespace Logging +} // namespace chip + +#include + +namespace chip { +namespace DeviceLayer { +namespace Internal { + +extern const char * const TAG; + +#if CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY +extern const uint64_t TestDeviceId; +extern const uint8_t TestDeviceCert[]; +extern const uint8_t TestDeviceIntermediateCACert[]; +extern const uint8_t TestDevicePrivateKey[]; +extern const uint16_t TestDeviceCertLength; +extern const uint16_t TestDeviceIntermediateCACertLength; +extern const uint16_t TestDevicePrivateKeyLength; +#endif // CHIP_DEVICE_CONFIG_ENABLE_TEST_DEVICE_IDENTITY + +} // namespace Internal +} // namespace DeviceLayer +} // namespace chip + +#endif // CHIP_DEVICE_INTERNAL_H diff --git a/src/platform/include/ConfigurationManager.h b/src/platform/include/ConfigurationManager.h new file mode 100644 index 00000000000000..2834ac37debe94 --- /dev/null +++ b/src/platform/include/ConfigurationManager.h @@ -0,0 +1,539 @@ +/* + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * Defines the public interface for the Device Layer ConfigurationManager object. + */ + +#ifndef CONFIGURATION_MANAGER_H +#define CONFIGURATION_MANAGER_H + +#include +#include +#include + +namespace chip { +namespace Ble { +struct ChipBLEDeviceIdentificationInfo; +} +} + +namespace chip { +namespace DeviceLayer { + +class PlatformManagerImpl; +class ConfigurationManagerImpl; +class TraitManager; +namespace Internal { +template class GenericPlatformManagerImpl; +class DeviceControlServer; +class NetworkProvisioningServer; +} + +/** + * Provides access to runtime and build-time configuration information for a chip device. + */ +class ConfigurationManager +{ + using ChipDeviceDescriptor = ::chip::Profiles::DeviceDescription::ChipDeviceDescriptor; + +public: + + // ===== Members that define the public interface of the ConfigurationManager + + enum + { + kMaxPairingCodeLength = 15, + kMaxSerialNumberLength = ChipDeviceDescriptor::kMaxSerialNumberLength, + kMaxFirmwareRevisionLength = ChipDeviceDescriptor::kMaxSoftwareVersionLength, + }; + + CHIP_ERROR GetVendorId(uint16_t & vendorId); + CHIP_ERROR GetProductId(uint16_t & productId); + CHIP_ERROR GetProductRevision(uint16_t & productRev); + CHIP_ERROR GetSerialNumber(char * buf, size_t bufSize, size_t & serialNumLen); + CHIP_ERROR GetPrimaryWiFiMACAddress(uint8_t * buf); + CHIP_ERROR GetPrimary802154MACAddress(uint8_t * buf); + CHIP_ERROR GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & dayOfMonth); + CHIP_ERROR GetFirmwareRevision(char * buf, size_t bufSize, size_t & outLen); + CHIP_ERROR GetFirmwareBuildTime(uint16_t & year, uint8_t & month, uint8_t & dayOfMonth, + uint8_t & hour, uint8_t & minute, uint8_t & second); + CHIP_ERROR GetDeviceId(uint64_t & deviceId); + CHIP_ERROR GetDeviceCertificate(uint8_t * buf, size_t bufSize, size_t & certLen); + CHIP_ERROR GetDeviceIntermediateCACerts(uint8_t * buf, size_t bufSize, size_t & certsLen); + CHIP_ERROR GetDevicePrivateKey(uint8_t * buf, size_t bufSize, size_t & keyLen); + CHIP_ERROR GetManufacturerDeviceId(uint64_t & deviceId); + CHIP_ERROR GetManufacturerDeviceCertificate(uint8_t * buf, size_t bufSize, size_t & certLen); + CHIP_ERROR GetManufacturerDeviceIntermediateCACerts(uint8_t * buf, size_t bufSize, size_t & certsLen); + CHIP_ERROR GetManufacturerDevicePrivateKey(uint8_t * buf, size_t bufSize, size_t & keyLen); + CHIP_ERROR GetPairingCode(char * buf, size_t bufSize, size_t & pairingCodeLen); + CHIP_ERROR GetServiceId(uint64_t & serviceId); + CHIP_ERROR GetFabricId(uint64_t & fabricId); + CHIP_ERROR GetServiceConfig(uint8_t * buf, size_t bufSize, size_t & serviceConfigLen); + CHIP_ERROR GetPairedAccountId(char * buf, size_t bufSize, size_t & accountIdLen); + + CHIP_ERROR StoreSerialNumber(const char * serialNum, size_t serialNumLen); + CHIP_ERROR StorePrimaryWiFiMACAddress(const uint8_t * buf); + CHIP_ERROR StorePrimary802154MACAddress(const uint8_t * buf); + CHIP_ERROR StoreManufacturingDate(const char * mfgDate, size_t mfgDateLen); + CHIP_ERROR StoreProductRevision(uint16_t productRev); + CHIP_ERROR StoreFabricId(uint64_t fabricId); +#if CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING + CHIP_ERROR StoreDeviceId(uint64_t deviceId); + CHIP_ERROR StoreDeviceCertificate(const uint8_t * cert, size_t certLen); + CHIP_ERROR StoreDeviceIntermediateCACerts(const uint8_t * certs, size_t certsLen); + CHIP_ERROR StoreDevicePrivateKey(const uint8_t * key, size_t keyLen); +#endif + CHIP_ERROR StoreManufacturerDeviceId(uint64_t deviceId); + CHIP_ERROR StoreManufacturerDeviceCertificate(const uint8_t * cert, size_t certLen); + CHIP_ERROR StoreManufacturerDeviceIntermediateCACerts(const uint8_t * certs, size_t certsLen); + CHIP_ERROR StoreManufacturerDevicePrivateKey(const uint8_t * key, size_t keyLen); + CHIP_ERROR StorePairingCode(const char * pairingCode, size_t pairingCodeLen); + CHIP_ERROR StoreServiceProvisioningData(uint64_t serviceId, const uint8_t * serviceConfig, size_t serviceConfigLen, const char * accountId, size_t accountIdLen); + CHIP_ERROR ClearServiceProvisioningData(); + CHIP_ERROR StoreServiceConfig(const uint8_t * serviceConfig, size_t serviceConfigLen); + CHIP_ERROR StorePairedAccountId(const char * accountId, size_t accountIdLen); + + CHIP_ERROR GetDeviceDescriptor(ChipDeviceDescriptor & deviceDesc); + CHIP_ERROR GetDeviceDescriptorTLV(uint8_t * buf, size_t bufSize, size_t & encodedLen); + CHIP_ERROR GetQRCodeString(char * buf, size_t bufSize); + + CHIP_ERROR GetWiFiAPSSID(char * buf, size_t bufSize); + + CHIP_ERROR GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo); + + bool IsServiceProvisioned(); + bool IsPairedToAccount(); + bool IsMemberOfFabric(); + bool IsFullyProvisioned(); +#if CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING + bool OperationalDeviceCredentialsProvisioned(); +#endif + + void InitiateFactoryReset(); + + CHIP_ERROR ComputeProvisioningHash(uint8_t * hashBuf, size_t hashBufSize); + +private: + + // ===== Members for internal use by the following friends. + + friend class ::chip::DeviceLayer::PlatformManagerImpl; + template friend class ::chip::DeviceLayer::Internal::GenericPlatformManagerImpl; + friend class ::chip::DeviceLayer::TraitManager; + friend class ::chip::DeviceLayer::Internal::DeviceControlServer; + // Parentheses used to fix clang parsing issue with these declarations + friend CHIP_ERROR (::chip::Platform::PersistedStorage::Read(::chip::Platform::PersistedStorage::Key key, uint32_t & value)); + friend CHIP_ERROR (::chip::Platform::PersistedStorage::Write(::chip::Platform::PersistedStorage::Key key, uint32_t value)); + + using ImplClass = ConfigurationManagerImpl; + + CHIP_ERROR Init(); + CHIP_ERROR ConfigureChipStack(); + ::chip::Profiles::Security::AppKeys::GroupKeyStoreBase * GetGroupKeyStore(); + bool CanFactoryReset(); + CHIP_ERROR GetFailSafeArmed(bool & val); + CHIP_ERROR SetFailSafeArmed(bool val); + CHIP_ERROR ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value); + CHIP_ERROR WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value); +#if CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING + CHIP_ERROR ClearOperationalDeviceCredentials(void); + void UseManufacturerCredentialsAsOperational(bool val); +#endif + +protected: + + // Construction/destruction limited to subclasses. + ConfigurationManager() = default; + ~ConfigurationManager() = default; + + // No copy, move or assignment. + ConfigurationManager(const ConfigurationManager &) = delete; + ConfigurationManager(const ConfigurationManager &&) = delete; + ConfigurationManager & operator=(const ConfigurationManager &) = delete; +}; + +/** + * Returns a reference to the public interface of the ConfigurationManager singleton object. + * + * chip application should use this to access features of the ConfigurationManager object + * that are common to all platforms. + */ +extern ConfigurationManager & ConfigurationMgr(void); + +/** + * Returns the platform-specific implementation of the ConfigurationManager singleton object. + * + * chip applications can use this to gain access to features of the ConfigurationManager + * that are specific to the selected platform. + */ +extern ConfigurationManagerImpl & ConfigurationMgrImpl(void); + +} // namespace DeviceLayer +} // namespace chip + +/* Include a header file containing the implementation of the ConfigurationManager + * object for the selected platform. + */ +#ifdef EXTERNAL_CONFIGURATIONMANAGERIMPL_HEADER +#include EXTERNAL_CONFIGURATIONMANAGERIMPL_HEADER +#else +#define CONFIGURATIONMANAGERIMPL_HEADER +#include CONFIGURATIONMANAGERIMPL_HEADER +#endif + +namespace chip { +namespace DeviceLayer { + +/** + * Id of the vendor that produced the device. + */ +inline CHIP_ERROR ConfigurationManager::GetVendorId(uint16_t & vendorId) +{ + return static_cast(this)->_GetVendorId(vendorId); +} + +/** + * Device product id assigned by the vendor. + */ +inline CHIP_ERROR ConfigurationManager::GetProductId(uint16_t & productId) +{ + return static_cast(this)->_GetProductId(productId); +} + +/** + * Product revision number assigned by the vendor. + */ +inline CHIP_ERROR ConfigurationManager::GetProductRevision(uint16_t & productRev) +{ + return static_cast(this)->_GetProductRevision(productRev); +} + +inline CHIP_ERROR ConfigurationManager::GetSerialNumber(char * buf, size_t bufSize, size_t & serialNumLen) +{ + return static_cast(this)->_GetSerialNumber(buf, bufSize, serialNumLen); +} + +inline CHIP_ERROR ConfigurationManager::GetPrimaryWiFiMACAddress(uint8_t * buf) +{ + return static_cast(this)->_GetPrimaryWiFiMACAddress(buf); +} + +inline CHIP_ERROR ConfigurationManager::GetPrimary802154MACAddress(uint8_t * buf) +{ + return static_cast(this)->_GetPrimary802154MACAddress(buf); +} + +inline CHIP_ERROR ConfigurationManager::GetManufacturingDate(uint16_t & year, uint8_t & month, uint8_t & dayOfMonth) +{ + return static_cast(this)->_GetManufacturingDate(year, month, dayOfMonth); +} + +inline CHIP_ERROR ConfigurationManager::GetFirmwareRevision(char * buf, size_t bufSize, size_t & outLen) +{ + return static_cast(this)->_GetFirmwareRevision(buf, bufSize, outLen); +} + +inline CHIP_ERROR ConfigurationManager::GetFirmwareBuildTime(uint16_t & year, uint8_t & month, uint8_t & dayOfMonth, + uint8_t & hour, uint8_t & minute, uint8_t & second) +{ + return static_cast(this)->_GetFirmwareBuildTime(year, month, dayOfMonth, hour, minute, second); +} + +inline CHIP_ERROR ConfigurationManager::GetDeviceId(uint64_t & deviceId) +{ + return static_cast(this)->_GetDeviceId(deviceId); +} + +inline CHIP_ERROR ConfigurationManager::GetDeviceCertificate(uint8_t * buf, size_t bufSize, size_t & certLen) +{ + return static_cast(this)->_GetDeviceCertificate(buf, bufSize, certLen); +} + +inline CHIP_ERROR ConfigurationManager::GetDeviceIntermediateCACerts(uint8_t * buf, size_t bufSize, size_t & certsLen) +{ + return static_cast(this)->_GetDeviceIntermediateCACerts(buf, bufSize, certsLen); +} + +inline CHIP_ERROR ConfigurationManager::GetDevicePrivateKey(uint8_t * buf, size_t bufSize, size_t & keyLen) +{ + return static_cast(this)->_GetDevicePrivateKey(buf, bufSize, keyLen); +} + +inline CHIP_ERROR ConfigurationManager::GetManufacturerDeviceId(uint64_t & deviceId) +{ + return static_cast(this)->_GetManufacturerDeviceId(deviceId); +} + +inline CHIP_ERROR ConfigurationManager::GetManufacturerDeviceCertificate(uint8_t * buf, size_t bufSize, size_t & certLen) +{ + return static_cast(this)->_GetManufacturerDeviceCertificate(buf, bufSize, certLen); +} + +inline CHIP_ERROR ConfigurationManager::GetManufacturerDeviceIntermediateCACerts(uint8_t * buf, size_t bufSize, size_t & certsLen) +{ + return static_cast(this)->_GetManufacturerDeviceIntermediateCACerts(buf, bufSize, certsLen); +} + +inline CHIP_ERROR ConfigurationManager::GetManufacturerDevicePrivateKey(uint8_t * buf, size_t bufSize, size_t & keyLen) +{ + return static_cast(this)->_GetManufacturerDevicePrivateKey(buf, bufSize, keyLen); +} + +inline CHIP_ERROR ConfigurationManager::GetPairingCode(char * buf, size_t bufSize, size_t & pairingCodeLen) +{ + return static_cast(this)->_GetPairingCode(buf, bufSize, pairingCodeLen); +} + +inline CHIP_ERROR ConfigurationManager::GetServiceId(uint64_t & serviceId) +{ + return static_cast(this)->_GetServiceId(serviceId); +} + +inline CHIP_ERROR ConfigurationManager::GetFabricId(uint64_t & fabricId) +{ + return static_cast(this)->_GetFabricId(fabricId); +} + +inline CHIP_ERROR ConfigurationManager::GetServiceConfig(uint8_t * buf, size_t bufSize, size_t & serviceConfigLen) +{ + return static_cast(this)->_GetServiceConfig(buf, bufSize, serviceConfigLen); +} + +inline CHIP_ERROR ConfigurationManager::GetPairedAccountId(char * buf, size_t bufSize, size_t & accountIdLen) +{ + return static_cast(this)->_GetPairedAccountId(buf, bufSize, accountIdLen); +} + +inline CHIP_ERROR ConfigurationManager::StoreSerialNumber(const char * serialNum, size_t serialNumLen) +{ + return static_cast(this)->_StoreSerialNumber(serialNum, serialNumLen); +} + +inline CHIP_ERROR ConfigurationManager::StorePrimaryWiFiMACAddress(const uint8_t * buf) +{ + return static_cast(this)->_StorePrimaryWiFiMACAddress(buf); +} + +inline CHIP_ERROR ConfigurationManager::StorePrimary802154MACAddress(const uint8_t * buf) +{ + return static_cast(this)->_StorePrimary802154MACAddress(buf); +} + +inline CHIP_ERROR ConfigurationManager::StoreManufacturingDate(const char * mfgDate, size_t mfgDateLen) +{ + return static_cast(this)->_StoreManufacturingDate(mfgDate, mfgDateLen); +} + +inline CHIP_ERROR ConfigurationManager::StoreProductRevision(uint16_t productRev) +{ + return static_cast(this)->_StoreProductRevision(productRev); +} + +inline CHIP_ERROR ConfigurationManager::StoreFabricId(uint64_t fabricId) +{ + return static_cast(this)->_StoreFabricId(fabricId); +} + +#if CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING + +inline CHIP_ERROR ConfigurationManager::StoreDeviceId(uint64_t deviceId) +{ + return static_cast(this)->_StoreDeviceId(deviceId); +} + +inline CHIP_ERROR ConfigurationManager::StoreDeviceCertificate(const uint8_t * cert, size_t certLen) +{ + return static_cast(this)->_StoreDeviceCertificate(cert, certLen); +} + +inline CHIP_ERROR ConfigurationManager::StoreDeviceIntermediateCACerts(const uint8_t * certs, size_t certsLen) +{ + return static_cast(this)->_StoreDeviceIntermediateCACerts(certs, certsLen); +} + +inline CHIP_ERROR ConfigurationManager::StoreDevicePrivateKey(const uint8_t * key, size_t keyLen) +{ + return static_cast(this)->_StoreDevicePrivateKey(key, keyLen); +} + +#endif // CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING + +inline CHIP_ERROR ConfigurationManager::StoreManufacturerDeviceId(uint64_t deviceId) +{ + return static_cast(this)->_StoreManufacturerDeviceId(deviceId); +} + +inline CHIP_ERROR ConfigurationManager::StoreManufacturerDeviceCertificate(const uint8_t * cert, size_t certLen) +{ + return static_cast(this)->_StoreManufacturerDeviceCertificate(cert, certLen); +} + +inline CHIP_ERROR ConfigurationManager::StoreManufacturerDeviceIntermediateCACerts(const uint8_t * certs, size_t certsLen) +{ + return static_cast(this)->_StoreManufacturerDeviceIntermediateCACerts(certs, certsLen); +} + +inline CHIP_ERROR ConfigurationManager::StoreManufacturerDevicePrivateKey(const uint8_t * key, size_t keyLen) +{ + return static_cast(this)->_StoreManufacturerDevicePrivateKey(key, keyLen); +} + +inline CHIP_ERROR ConfigurationManager::StorePairingCode(const char * pairingCode, size_t pairingCodeLen) +{ + return static_cast(this)->_StorePairingCode(pairingCode, pairingCodeLen); +} + +inline CHIP_ERROR ConfigurationManager::StoreServiceProvisioningData(uint64_t serviceId, const uint8_t * serviceConfig, size_t serviceConfigLen, const char * accountId, size_t accountIdLen) +{ + return static_cast(this)->_StoreServiceProvisioningData(serviceId, serviceConfig, serviceConfigLen, accountId, accountIdLen); +} + +inline CHIP_ERROR ConfigurationManager::ClearServiceProvisioningData() +{ + return static_cast(this)->_ClearServiceProvisioningData(); +} + +inline CHIP_ERROR ConfigurationManager::StoreServiceConfig(const uint8_t * serviceConfig, size_t serviceConfigLen) +{ + return static_cast(this)->_StoreServiceConfig(serviceConfig, serviceConfigLen); +} + +inline CHIP_ERROR ConfigurationManager::StorePairedAccountId(const char * accountId, size_t accountIdLen) +{ + return static_cast(this)->_StorePairedAccountId(accountId, accountIdLen); +} + +inline CHIP_ERROR ConfigurationManager::ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value) +{ + return static_cast(this)->_ReadPersistedStorageValue(key, value); +} + +inline CHIP_ERROR ConfigurationManager::WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value) +{ + return static_cast(this)->_WritePersistedStorageValue(key, value); +} + +inline CHIP_ERROR ConfigurationManager::GetDeviceDescriptor(chipDeviceDescriptor & deviceDesc) +{ + return static_cast(this)->_GetDeviceDescriptor(deviceDesc); +} + +inline CHIP_ERROR ConfigurationManager::GetDeviceDescriptorTLV(uint8_t * buf, size_t bufSize, size_t & encodedLen) +{ + return static_cast(this)->_GetDeviceDescriptorTLV(buf, bufSize, encodedLen); +} + +inline CHIP_ERROR ConfigurationManager::GetQRCodeString(char * buf, size_t bufSize) +{ + return static_cast(this)->_GetQRCodeString(buf, bufSize); +} + +inline CHIP_ERROR ConfigurationManager::GetWiFiAPSSID(char * buf, size_t bufSize) +{ + return static_cast(this)->_GetWiFiAPSSID(buf, bufSize); +} + +inline CHIP_ERROR ConfigurationManager::GetBLEDeviceIdentificationInfo(Ble::chipBLEDeviceIdentificationInfo & deviceIdInfo) +{ + return static_cast(this)->_GetBLEDeviceIdentificationInfo(deviceIdInfo); +} + +inline bool ConfigurationManager::IsServiceProvisioned() +{ + return static_cast(this)->_IsServiceProvisioned(); +} + +inline bool ConfigurationManager::IsPairedToAccount() +{ + return static_cast(this)->_IsPairedToAccount(); +} + +inline bool ConfigurationManager::IsMemberOfFabric() +{ + return static_cast(this)->_IsMemberOfFabric(); +} + +inline bool ConfigurationManager::IsFullyProvisioned() +{ + return static_cast(this)->_IsFullyProvisioned(); +} + +inline void ConfigurationManager::InitiateFactoryReset() +{ + static_cast(this)->_InitiateFactoryReset(); +} + +inline CHIP_ERROR ConfigurationManager::ComputeProvisioningHash(uint8_t * hashBuf, size_t hashBufSize) +{ + return static_cast(this)->_ComputeProvisioningHash(hashBuf, hashBufSize); +} + +inline CHIP_ERROR ConfigurationManager::Init() +{ + return static_cast(this)->_Init(); +} + +inline CHIP_ERROR ConfigurationManager::ConfigurechipStack() +{ + return static_cast(this)->_ConfigurechipStack(); +} + +inline ::chip::Profiles::Security::AppKeys::GroupKeyStoreBase * ConfigurationManager::GetGroupKeyStore() +{ + return static_cast(this)->_GetGroupKeyStore(); +} + +inline bool ConfigurationManager::CanFactoryReset() +{ + return static_cast(this)->_CanFactoryReset(); +} + +inline CHIP_ERROR ConfigurationManager::GetFailSafeArmed(bool & val) +{ + return static_cast(this)->_GetFailSafeArmed(val); +} + +inline CHIP_ERROR ConfigurationManager::SetFailSafeArmed(bool val) +{ + return static_cast(this)->_SetFailSafeArmed(val); +} + +#if CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING + +inline bool ConfigurationManager::OperationalDeviceCredentialsProvisioned() +{ + return static_cast(this)->_OperationalDeviceCredentialsProvisioned(); +} + +inline CHIP_ERROR ConfigurationManager::ClearOperationalDeviceCredentials(void) +{ + return static_cast(this)->_ClearOperationalDeviceCredentials(); +} + +inline void ConfigurationManager::UseManufacturerCredentialsAsOperational(bool val) +{ + static_cast(this)->_UseManufacturerCredentialsAsOperational(val); +} + +#endif // CHIP_DEVICE_CONFIG_ENABLE_JUST_IN_TIME_PROVISIONING + +} // namespace DeviceLayer +} // namespace chip + +#endif // CONFIGURATION_MANAGER_H diff --git a/src/platform/include/ConnectivityManager.h b/src/platform/include/ConnectivityManager.h new file mode 100644 index 00000000000000..52df85870c3fc5 --- /dev/null +++ b/src/platform/include/ConnectivityManager.h @@ -0,0 +1,567 @@ +/* + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * Defines the public interface for the Device Layer ConnectivityManager object. + */ + +#ifndef CONNECTIVITY_MANAGER_H +#define CONNECTIVITY_MANAGER_H + +namespace chip { +namespace DeviceLayer { + +namespace Internal { +class NetworkProvisioningServerImpl; +template class GenericNetworkProvisioningServerImpl; +template class GenericPlatformManagerImpl; +template class GenericPlatformManagerImpl_FreeRTOS; +} // namespace Internal + +class ConnectivityManagerImpl; + +/** + * Provides control of network connectivity for a chip device. + */ +class ConnectivityManager +{ + using ImplClass = ::chip::DeviceLayer::ConnectivityManagerImpl; + +public: + + // ===== Members that define the public interface of the ConnectivityManager + + enum WiFiStationMode + { + kWiFiStationMode_NotSupported = 0, + kWiFiStationMode_ApplicationControlled = 1, + kWiFiStationMode_Disabled = 2, + kWiFiStationMode_Enabled = 3, + }; + + enum WiFiAPMode + { + kWiFiAPMode_NotSupported = 0, + kWiFiAPMode_ApplicationControlled = 1, + kWiFiAPMode_Disabled = 2, + kWiFiAPMode_Enabled = 3, + kWiFiAPMode_OnDemand = 4, + kWiFiAPMode_OnDemand_NoStationProvision = 5, + }; + + enum ThreadMode + { + kThreadMode_NotSupported = 0, + kThreadMode_ApplicationControlled = 1, + kThreadMode_Disabled = 2, + kThreadMode_Enabled = 3, + }; + + enum ServiceTunnelMode + { + kServiceTunnelMode_NotSupported = 0, + kServiceTunnelMode_Disabled = 1, + kServiceTunnelMode_Enabled = 2, + }; + + enum WoBLEServiceMode + { + kWoBLEServiceMode_NotSupported = 0, + kWoBLEServiceMode_Enabled = 1, + kWoBLEServiceMode_Disabled = 2, + }; + + enum ThreadDeviceType + { + kThreadDeviceType_NotSupported = 0, + kThreadDeviceType_Router = 1, + kThreadDeviceType_FullEndDevice = 2, + kThreadDeviceType_MinimalEndDevice = 3, + kThreadDeviceType_SleepyEndDevice = 4, + }; + + struct ThreadPollingConfig; + + // WiFi station methods + WiFiStationMode GetWiFiStationMode(void); + CHIP_ERROR SetWiFiStationMode(WiFiStationMode val); + bool IsWiFiStationEnabled(void); + bool IsWiFiStationApplicationControlled(void); + bool IsWiFiStationConnected(void); + uint32_t GetWiFiStationReconnectIntervalMS(void); + CHIP_ERROR SetWiFiStationReconnectIntervalMS(uint32_t val); + bool IsWiFiStationProvisioned(void); + void ClearWiFiStationProvision(void); + CHIP_ERROR GetAndLogWifiStatsCounters(void); + + // WiFi AP methods + WiFiAPMode GetWiFiAPMode(void); + CHIP_ERROR SetWiFiAPMode(WiFiAPMode val); + bool IsWiFiAPActive(void); + bool IsWiFiAPApplicationControlled(void); + void DemandStartWiFiAP(void); + void StopOnDemandWiFiAP(void); + void MaintainOnDemandWiFiAP(void); + uint32_t GetWiFiAPIdleTimeoutMS(void); + void SetWiFiAPIdleTimeoutMS(uint32_t val); + + // Thread Methods + ThreadMode GetThreadMode(void); + CHIP_ERROR SetThreadMode(ThreadMode val); + bool IsThreadEnabled(void); + bool IsThreadApplicationControlled(void); + ThreadDeviceType GetThreadDeviceType(void); + CHIP_ERROR SetThreadDeviceType(ThreadDeviceType deviceType); + void GetThreadPollingConfig(ThreadPollingConfig & pollingConfig); + CHIP_ERROR SetThreadPollingConfig(const ThreadPollingConfig & pollingConfig); + bool IsThreadAttached(void); + bool IsThreadProvisioned(void); + void ClearThreadProvision(void); + bool HaveServiceConnectivityViaThread(void); + + // Internet connectivity methods + bool HaveIPv4InternetConnectivity(void); + bool HaveIPv6InternetConnectivity(void); + + // Service tunnel methods + ServiceTunnelMode GetServiceTunnelMode(void); + CHIP_ERROR SetServiceTunnelMode(ServiceTunnelMode val); + bool IsServiceTunnelConnected(void); + bool IsServiceTunnelRestricted(void); + bool HaveServiceConnectivityViaTunnel(void); + + // Service connectivity methods + bool HaveServiceConnectivity(void); + + // WoBLE service methods + WoBLEServiceMode GetWoBLEServiceMode(void); + CHIP_ERROR SetWoBLEServiceMode(WoBLEServiceMode val); + bool IsBLEAdvertisingEnabled(void); + CHIP_ERROR SetBLEAdvertisingEnabled(bool val); + bool IsBLEFastAdvertisingEnabled(void); + CHIP_ERROR SetBLEFastAdvertisingEnabled(bool val); + bool IsBLEAdvertising(void); + CHIP_ERROR GetBLEDeviceName(char * buf, size_t bufSize); + CHIP_ERROR SetBLEDeviceName(const char * deviceName); + uint16_t NumBLEConnections(void); + + // User selected mode methods + bool IsUserSelectedModeActive(void); + void SetUserSelectedMode(bool val); + uint16_t GetUserSelectedModeTimeout(void); + void SetUserSelectedModeTimeout(uint16_t val); + + // Support methods + static const char * WiFiStationModeToStr(WiFiStationMode mode); + static const char * WiFiAPModeToStr(WiFiAPMode mode); + static const char * ServiceTunnelModeToStr(ServiceTunnelMode mode); + static const char * WoBLEServiceModeToStr(WoBLEServiceMode mode); + +private: + + // ===== Members for internal use by the following friends. + + friend class PlatformManagerImpl; + template friend class Internal::GenericPlatformManagerImpl; + template friend class Internal::GenericPlatformManagerImpl_FreeRTOS; + friend class Internal::NetworkProvisioningServerImpl; + template friend class Internal::GenericNetworkProvisioningServerImpl; + + CHIP_ERROR Init(void); + void OnPlatformEvent(const ChipDeviceEvent * event); + bool CanStartWiFiScan(void); + void OnWiFiScanDone(void); + void OnWiFiStationProvisionChange(void); + +protected: + + // Construction/destruction limited to subclasses. + ConnectivityManager() = default; + ~ConnectivityManager() = default; + + // No copy, move or assignment. + ConnectivityManager(const ConnectivityManager &) = delete; + ConnectivityManager(const ConnectivityManager &&) = delete; + ConnectivityManager & operator=(const ConnectivityManager &) = delete; +}; + +/** + * Information describing the desired Thread polling behavior of a device. + */ +struct ConnectivityManager::ThreadPollingConfig +{ + uint32_t ActivePollingIntervalMS; /**< Interval at which the device polls its parent Thread router when + when there are active chip exchanges in progress. Only meaningful + when the device is acting as a sleepy end node. */ + + uint32_t InactivePollingIntervalMS; /**< Interval at which the device polls its parent Thread router when + when there are NO active chip exchanges in progress. Only meaningful + when the device is acting as a sleepy end node. */ + + void Clear() { memset(this, 0, sizeof(*this)); } +}; + + +/** + * Returns a reference to the public interface of the ConnectivityManager singleton object. + * + * chip applications should use this to access features of the ConnectivityManager object + * that are common to all platforms. + */ +extern ConnectivityManager & ConnectivityMgr(void); + +/** + * Returns the platform-specific implementation of the ConnectivityManager singleton object. + * + * chip applications can use this to gain access to features of the ConnectivityManager + * that are specific to the selected platform. + */ +extern ConnectivityManagerImpl & ConnectivityMgrImpl(void); + +} // namespace DeviceLayer +} // namespace chip + + +/* Include a header file containing the implementation of the ConfigurationManager + * object for the selected platform. + */ +#ifdef EXTERNAL_CONNECTIVITYMANAGERIMPL_HEADER +#include EXTERNAL_CONNECTIVITYMANAGERIMPL_HEADER +#else +#define CONNECTIVITYMANAGERIMPL_HEADER +#include CONNECTIVITYMANAGERIMPL_HEADER +#endif + + +namespace chip { +namespace DeviceLayer { + +inline ConnectivityManager::WiFiStationMode ConnectivityManager::GetWiFiStationMode(void) +{ + return static_cast(this)->_GetWiFiStationMode(); +} + +inline CHIP_ERROR ConnectivityManager::SetWiFiStationMode(WiFiStationMode val) +{ + return static_cast(this)->_SetWiFiStationMode(val); +} + +inline bool ConnectivityManager::IsWiFiStationEnabled(void) +{ + return static_cast(this)->_IsWiFiStationEnabled(); +} + +inline bool ConnectivityManager::IsWiFiStationApplicationControlled(void) +{ + return static_cast(this)->_IsWiFiStationApplicationControlled(); +} + +inline bool ConnectivityManager::IsWiFiStationConnected(void) +{ + return static_cast(this)->_IsWiFiStationConnected(); +} + +inline uint32_t ConnectivityManager::GetWiFiStationReconnectIntervalMS(void) +{ + return static_cast(this)->_GetWiFiStationReconnectIntervalMS(); +} + +inline CHIP_ERROR ConnectivityManager::SetWiFiStationReconnectIntervalMS(uint32_t val) +{ + return static_cast(this)->_SetWiFiStationReconnectIntervalMS(val); +} + +inline bool ConnectivityManager::IsWiFiStationProvisioned(void) +{ + return static_cast(this)->_IsWiFiStationProvisioned(); +} + +inline void ConnectivityManager::ClearWiFiStationProvision(void) +{ + static_cast(this)->_ClearWiFiStationProvision(); +} + +inline ConnectivityManager::WiFiAPMode ConnectivityManager::GetWiFiAPMode(void) +{ + return static_cast(this)->_GetWiFiAPMode(); +} + +inline CHIP_ERROR ConnectivityManager::SetWiFiAPMode(WiFiAPMode val) +{ + return static_cast(this)->_SetWiFiAPMode(val); +} + +inline bool ConnectivityManager::IsWiFiAPActive(void) +{ + return static_cast(this)->_IsWiFiAPActive(); +} + +inline bool ConnectivityManager::IsWiFiAPApplicationControlled(void) +{ + return static_cast(this)->_IsWiFiAPApplicationControlled(); +} + +inline void ConnectivityManager::DemandStartWiFiAP(void) +{ + static_cast(this)->_DemandStartWiFiAP(); +} + +inline void ConnectivityManager::StopOnDemandWiFiAP(void) +{ + static_cast(this)->_StopOnDemandWiFiAP(); +} + +inline void ConnectivityManager::MaintainOnDemandWiFiAP(void) +{ + static_cast(this)->_MaintainOnDemandWiFiAP(); +} + +inline uint32_t ConnectivityManager::GetWiFiAPIdleTimeoutMS(void) +{ + return static_cast(this)->_GetWiFiAPIdleTimeoutMS(); +} + +inline void ConnectivityManager::SetWiFiAPIdleTimeoutMS(uint32_t val) +{ + static_cast(this)->_SetWiFiAPIdleTimeoutMS(val); +} + +inline CHIP_ERROR ConnectivityManager::GetAndLogWifiStatsCounters(void) +{ + return static_cast(this)->_GetAndLogWifiStatsCounters(); +} + +inline bool ConnectivityManager::HaveServiceConnectivityViaTunnel(void) +{ + return static_cast(this)->_HaveServiceConnectivityViaTunnel(); +} + +inline bool ConnectivityManager::HaveIPv4InternetConnectivity(void) +{ + return static_cast(this)->_HaveIPv4InternetConnectivity(); +} + +inline bool ConnectivityManager::HaveIPv6InternetConnectivity(void) +{ + return static_cast(this)->_HaveIPv6InternetConnectivity(); +} + +inline ConnectivityManager::ServiceTunnelMode ConnectivityManager::GetServiceTunnelMode(void) +{ + return static_cast(this)->_GetServiceTunnelMode(); +} + +inline CHIP_ERROR ConnectivityManager::SetServiceTunnelMode(ServiceTunnelMode val) +{ + return static_cast(this)->_SetServiceTunnelMode(val); +} + +inline bool ConnectivityManager::IsServiceTunnelConnected(void) +{ + return static_cast(this)->_IsServiceTunnelConnected(); +} + +inline bool ConnectivityManager::IsServiceTunnelRestricted(void) +{ + return static_cast(this)->_IsServiceTunnelRestricted(); +} + +inline bool ConnectivityManager::HaveServiceConnectivity(void) +{ + return static_cast(this)->_HaveServiceConnectivity(); +} + +inline ConnectivityManager::ThreadMode ConnectivityManager::GetThreadMode(void) +{ + return static_cast(this)->_GetThreadMode(); +} + +inline CHIP_ERROR ConnectivityManager::SetThreadMode(ThreadMode val) +{ + return static_cast(this)->_SetThreadMode(val); +} + +inline bool ConnectivityManager::IsThreadEnabled(void) +{ + return static_cast(this)->_IsThreadEnabled(); +} + +inline bool ConnectivityManager::IsThreadApplicationControlled(void) +{ + return static_cast(this)->_IsThreadApplicationControlled(); +} + +inline ConnectivityManager::ThreadDeviceType ConnectivityManager::GetThreadDeviceType(void) +{ + return static_cast(this)->_GetThreadDeviceType(); +} + +inline CHIP_ERROR ConnectivityManager::SetThreadDeviceType(ThreadDeviceType deviceType) +{ + return static_cast(this)->_SetThreadDeviceType(deviceType); +} + +inline void ConnectivityManager::GetThreadPollingConfig(ThreadPollingConfig & pollingConfig) +{ + return static_cast(this)->_GetThreadPollingConfig(pollingConfig); +} + +inline CHIP_ERROR ConnectivityManager::SetThreadPollingConfig(const ThreadPollingConfig & pollingConfig) +{ + return static_cast(this)->_SetThreadPollingConfig(pollingConfig); +} + +inline bool ConnectivityManager::IsThreadAttached(void) +{ + return static_cast(this)->_IsThreadAttached(); +} + +inline bool ConnectivityManager::IsThreadProvisioned(void) +{ + return static_cast(this)->_IsThreadProvisioned(); +} + +inline void ConnectivityManager::ClearThreadProvision(void) +{ + static_cast(this)->_ClearThreadProvision(); +} + +inline bool ConnectivityManager::HaveServiceConnectivityViaThread(void) +{ + return static_cast(this)->_HaveServiceConnectivityViaThread(); +} + +inline ConnectivityManager::WoBLEServiceMode ConnectivityManager::GetWoBLEServiceMode(void) +{ + return static_cast(this)->_GetWoBLEServiceMode(); +} + +inline CHIP_ERROR ConnectivityManager::SetWoBLEServiceMode(WoBLEServiceMode val) +{ + return static_cast(this)->_SetWoBLEServiceMode(val); +} + +inline bool ConnectivityManager::IsBLEAdvertisingEnabled(void) +{ + return static_cast(this)->_IsBLEAdvertisingEnabled(); +} + +inline CHIP_ERROR ConnectivityManager::SetBLEAdvertisingEnabled(bool val) +{ + return static_cast(this)->_SetBLEAdvertisingEnabled(val); +} + +inline bool ConnectivityManager::IsBLEFastAdvertisingEnabled(void) +{ + return static_cast(this)->_IsBLEFastAdvertisingEnabled(); +} + +inline CHIP_ERROR ConnectivityManager::SetBLEFastAdvertisingEnabled(bool val) +{ + return static_cast(this)->_SetBLEFastAdvertisingEnabled(val); +} + +inline bool ConnectivityManager::IsBLEAdvertising(void) +{ + return static_cast(this)->_IsBLEAdvertising(); +} + +inline CHIP_ERROR ConnectivityManager::GetBLEDeviceName(char * buf, size_t bufSize) +{ + return static_cast(this)->_GetBLEDeviceName(buf, bufSize); +} + +inline CHIP_ERROR ConnectivityManager::SetBLEDeviceName(const char * deviceName) +{ + return static_cast(this)->_SetBLEDeviceName(deviceName); +} + +inline uint16_t ConnectivityManager::NumBLEConnections(void) +{ + return static_cast(this)->_NumBLEConnections(); +} + +inline bool ConnectivityManager::IsUserSelectedModeActive(void) +{ + return static_cast(this)->_IsUserSelectedModeActive(); +} + +inline void ConnectivityManager::SetUserSelectedMode(bool val) +{ + static_cast(this)->_SetUserSelectedMode(val); +} + +inline uint16_t ConnectivityManager::GetUserSelectedModeTimeout(void) +{ + return static_cast(this)->_GetUserSelectedModeTimeout(); +} + +inline void ConnectivityManager::SetUserSelectedModeTimeout(uint16_t val) +{ + static_cast(this)->_SetUserSelectedModeTimeout(val); +} + +inline const char * ConnectivityManager::WiFiStationModeToStr(WiFiStationMode mode) +{ + return ImplClass::_WiFiStationModeToStr(mode); +} + +inline const char * ConnectivityManager::WiFiAPModeToStr(WiFiAPMode mode) +{ + return ImplClass::_WiFiAPModeToStr(mode); +} + +inline const char * ConnectivityManager::ServiceTunnelModeToStr(ServiceTunnelMode mode) +{ + return ImplClass::_ServiceTunnelModeToStr(mode); +} + +inline const char * ConnectivityManager::WoBLEServiceModeToStr(WoBLEServiceMode mode) +{ + return ImplClass::_WoBLEServiceModeToStr(mode); +} + +inline CHIP_ERROR ConnectivityManager::Init(void) +{ + return static_cast(this)->_Init(); +} + +inline void ConnectivityManager::OnPlatformEvent(const ChipDeviceEvent * event) +{ + static_cast(this)->_OnPlatformEvent(event); +} + +inline bool ConnectivityManager::CanStartWiFiScan(void) +{ + return static_cast(this)->_CanStartWiFiScan(); +} + +inline void ConnectivityManager::OnWiFiScanDone(void) +{ + static_cast(this)->_OnWiFiScanDone(); +} + +inline void ConnectivityManager::OnWiFiStationProvisionChange(void) +{ + static_cast(this)->_OnWiFiStationProvisionChange(); +} + +} // namespace DeviceLayer +} // namespace chip + +#endif // CONNECTIVITY_MANAGER_H diff --git a/src/platform/include/GeneralUtils.h b/src/platform/include/GeneralUtils.h new file mode 100644 index 00000000000000..e73abaa0506e93 --- /dev/null +++ b/src/platform/include/GeneralUtils.h @@ -0,0 +1,34 @@ +/* + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * General utility functions available on all platforms. + */ + +namespace chip { +namespace DeviceLayer { + +extern CHIP_ERROR ParseCompilerDateStr(const char * dateStr, uint16_t & year, uint8_t & month, uint8_t & dayOfMonth); +extern CHIP_ERROR Parse24HourTimeStr(const char * timeStr, uint8_t & hour, uint8_t & minute, uint8_t & second); +extern const char * CharacterizeIPv6Address(const ::Inet::IPAddress & ipAddr); +extern const char * CharacterizeIPv6Prefix(const Inet::IPPrefix & inPrefix); +extern void RegisterDeviceLayerErrorFormatter(void); +extern bool FormatDeviceLayerError(char * buf, uint16_t bufSize, int32_t err); + +} // namespace DeviceLayer +} // namespace chip diff --git a/src/platform/include/PlatformManager.h b/src/platform/include/PlatformManager.h new file mode 100644 index 00000000000000..c1d4bc7d560fe2 --- /dev/null +++ b/src/platform/include/PlatformManager.h @@ -0,0 +1,223 @@ +/* + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * Defines the public interface for the Device Layer PlatformManager object. + */ + +#ifndef PLATFORM_MANAGER_H +#define PLATFORM_MANAGER_H + +#include + +namespace chip { +namespace System { +namespace Platform { +namespace Layer { + +System::Error PostEvent(System::Layer&, void*, System::Object&, System::EventType, uintptr_t); +System::Error DispatchEvents(System::Layer&, void*); +System::Error DispatchEvent(System::Layer&, void*, System::Event); +System::Error StartTimer(System::Layer&, void*, uint32_t); + +} // namespace Layer +} // namespace Platform +} // namespace System + +namespace DeviceLayer { + +class PlatformManagerImpl; +class ConnectivityManagerImpl; +class ConfigurationManagerImpl; +class TraitManager; +class TimeSyncManager; +namespace Internal { +class FabricProvisioningServer; +class ServiceProvisioningServer; +class BLEManagerImpl; +template class GenericConfigurationManagerImpl; +template class GenericPlatformManagerImpl; +template class GenericPlatformManagerImpl_FreeRTOS; +template class GenericConnectivityManagerImpl_Thread; +template class GenericThreadStackManagerImpl_OpenThread; +template class GenericThreadStackManagerImpl_OpenThread_LwIP; +} // namespace Internal + + +/** + * Provides features for initializing and interacting with the chip network + * stack on a chip-enabled device. + */ +class PlatformManager +{ + using ImplClass = ::chip::DeviceLayer::PlatformManagerImpl; + +public: + + // ===== Members that define the public interface of the PlatformManager + + typedef void (*EventHandlerFunct)(const ChipDeviceEvent * event, intptr_t arg); + + CHIP_ERROR InitChipStack(); + CHIP_ERROR AddEventHandler(EventHandlerFunct handler, intptr_t arg = 0); + void RemoveEventHandler(EventHandlerFunct handler, intptr_t arg = 0); + void ScheduleWork(AsyncWorkFunct workFunct, intptr_t arg = 0); + void RunEventLoop(void); + CHIP_ERROR StartEventLoopTask(void); + void LockChipStack(void); + bool TryLockChipStack(void); + void UnlockChipStack(void); + +private: + + // ===== Members for internal use by the following friends. + + friend class PlatformManagerImpl; + friend class ConnectivityManagerImpl; + friend class ConfigurationManagerImpl; + friend class TraitManager; + friend class TimeSyncManager; + friend class Internal::FabricProvisioningServer; + friend class Internal::ServiceProvisioningServer; + friend class Internal::BLEManagerImpl; + template friend class Internal::GenericPlatformManagerImpl; + template friend class Internal::GenericPlatformManagerImpl_FreeRTOS; + template friend class Internal::GenericConnectivityManagerImpl_Thread; + template friend class Internal::GenericThreadStackManagerImpl_OpenThread; + template friend class Internal::GenericThreadStackManagerImpl_OpenThread_LwIP; + template friend class Internal::GenericConfigurationManagerImpl; + // Parentheses used to fix clang parsing issue with these declarations + friend ::chip::System::Error (::chip::System::Platform::Layer::PostEvent(::chip::System::Layer & aLayer, void * aContext, ::chip::System::Object & aTarget, ::chip::System::EventType aType, uintptr_t aArgument)); + friend ::chip::System::Error (::chip::System::Platform::Layer::DispatchEvents(::chip::System::Layer & aLayer, void * aContext)); + friend ::chip::System::Error (::chip::System::Platform::Layer::DispatchEvent(::chip::System::Layer & aLayer, void * aContext, ::chip::System::Event aEvent)); + friend ::chip::System::Error (::chip::System::Platform::Layer::StartTimer(::chip::System::Layer & aLayer, void * aContext, uint32_t aMilliseconds)); + + void PostEvent(const ChipDeviceEvent * event); + void DispatchEvent(const ChipDeviceEvent * event); + CHIP_ERROR StartChipTimer(uint32_t durationMS); + +protected: + + // Construction/destruction limited to subclasses. + PlatformManager() = default; + ~PlatformManager() = default; + + // No copy, move or assignment. + PlatformManager(const PlatformManager &) = delete; + PlatformManager(const PlatformManager &&) = delete; + PlatformManager & operator=(const PlatformManager &) = delete; +}; + +/** + * Returns the public interface of the PlatformManager singleton object. + * + * chip applications should use this to access features of the PlatformManager object + * that are common to all platforms. + */ +extern PlatformManager & PlatformMgr(void); + +/** + * Returns the platform-specific implementation of the PlatformManager singleton object. + * + * chip applications can use this to gain access to features of the PlatformManager + * that are specific to the selected platform. + */ +extern PlatformManagerImpl & PlatformMgrImpl(void); + +} // namespace DeviceLayer +} // namespace chip + +/* Include a header file containing the implementation of the ConfigurationManager + * object for the selected platform. + */ +#ifdef EXTERNAL_PLATFORMMANAGERIMPL_HEADER +#include EXTERNAL_PLATFORMMANAGERIMPL_HEADER +#else +#define PLATFORMMANAGERIMPL_HEADER +#include PLATFORMMANAGERIMPL_HEADER +#endif + +namespace chip { +namespace DeviceLayer { + +inline CHIP_ERROR PlatformManager::InitchipStack() +{ + return static_cast(this)->_InitchipStack(); +} + +inline CHIP_ERROR PlatformManager::AddEventHandler(EventHandlerFunct handler, intptr_t arg) +{ + return static_cast(this)->_AddEventHandler(handler, arg); +} + +inline void PlatformManager::RemoveEventHandler(EventHandlerFunct handler, intptr_t arg) +{ + static_cast(this)->_RemoveEventHandler(handler, arg); +} + +inline void PlatformManager::ScheduleWork(AsyncWorkFunct workFunct, intptr_t arg) +{ + static_cast(this)->_ScheduleWork(workFunct, arg); +} + +inline void PlatformManager::RunEventLoop(void) +{ + static_cast(this)->_RunEventLoop(); +} + +inline CHIP_ERROR PlatformManager::StartEventLoopTask(void) +{ + return static_cast(this)->_StartEventLoopTask(); +} + +inline void PlatformManager::LockchipStack(void) +{ + static_cast(this)->_LockchipStack(); +} + +inline bool PlatformManager::TryLockchipStack(void) +{ + return static_cast(this)->_TryLockchipStack(); +} + +inline void PlatformManager::UnlockchipStack(void) +{ + static_cast(this)->_UnlockchipStack(); +} + +inline void PlatformManager::PostEvent(const chipDeviceEvent * event) +{ + static_cast(this)->_PostEvent(event); +} + +inline void PlatformManager::DispatchEvent(const chipDeviceEvent * event) +{ + static_cast(this)->_DispatchEvent(event); +} + +inline CHIP_ERROR PlatformManager::StartchipTimer(uint32_t durationMS) +{ + return static_cast(this)->_StartchipTimer(durationMS); +} + +} // namespace DeviceLayer +} // namespace chip + + + +#endif // PLATFORM_MANAGER_H diff --git a/src/platform/include/SoftwareUpdateManager.h b/src/platform/include/SoftwareUpdateManager.h new file mode 100644 index 00000000000000..823e57e1215e42 --- /dev/null +++ b/src/platform/include/SoftwareUpdateManager.h @@ -0,0 +1,521 @@ +/* + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * Defines the public interface for the Device Layer SoftwareUpdateManager object. + */ + +#ifndef SOFTWARE_UPDATE_MANAGER_H +#define SOFTWARE_UPDATE_MANAGER_H + +#if CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER + +#include +#include + +namespace chip { +namespace DeviceLayer { + +class SoftwareUpdateManagerImpl; + +class SoftwareUpdateManager +{ + typedef ::chip::TLV::TLVWriter TLVWriter; + typedef ::chip::Profiles::SoftwareUpdate::UpdatePriority UpdatePriority; + typedef ::chip::Profiles::SoftwareUpdate::UpdateCondition UpdateCondition; + + using ImplClass = SoftwareUpdateManagerImpl; + + +public: + + // ===== Members that define the public interface of the SoftwareUpdateManager + + enum State + { + kState_Idle = 1, + kState_ScheduledHoldoff = 2, + kState_PrepareQuery = 3, + kState_Query = 4, + kState_PrepareImageStorage = 5, + kState_Download = 6, + kState_Install = 7, + + kState_ApplicationManaged = 8, + + kState_MaxState + }; + + /** + * API events generated by the \c SoftwareUpdateManager object. + */ + enum EventType + { + /** + * Prepare ImageQuery message + * + * Generated when a software update check has been triggered. Provides an opportunity + * for the application to supply product related information to the + * SofwareUpdate:ImageQuery message. + */ + kEvent_PrepareQuery, + + /** + * Prepare meta-data for ImageQuery request + * + * Provides an opportunity for the application to append additional meta-data + * to the SofwareUpdate:ImageQuery message if needed. Generated when implementation + * is ready to get meta-data from the application. + */ + kEvent_PrepareQuery_Metadata, + + /** + * Error preparing an ImageQuery request + * + * Generated when the implementation encounters an error while preparing to send out + * a software update query. + */ + kEvent_QueryPrepareFailed, + + /** + * ImageQuery request has been sent + * + * Informational event to signal that a SofwareUpdate:ImageQuery message has been sent. + */ + kEvent_QuerySent, + + /** + * Software update is available + * + * Generated when a SofwareUpdate:ImageQueryResponse is received in response to + * a query containing information of the available update. + */ + kEvent_SoftwareUpdateAvailable, + + /** + * Fetch persisted state information for a partially downloaded image + * + * Provides an opportunity for the application to disclose information + * of a partial image previously downloaded so that the download + * may be continued from the point where it last stopped. URI of the available + * software update is provided as an input parameter that the application can use + * to compare if the image being downloaded is the same as the partial image. + * + * The application is expected to return the length of the partial image in the + * PartialImageLenInBytes output parameter. The application can set the value + * of PartialImageLenInBytes to 0 to indicate that no partial image exists or + * that the URI of the partial image does not match. + * + * The application may choose to ignore this event by passing it to the default + * event handler. If this is done, the system will always download the entirety + * of the available firmware image. + */ + kEvent_FetchPartialImageInfo, + + /** + * Prepare for storage of a new image + * + * Requests the application to perform any steps necessary to prepare local storage + * for the download of a new firmware image. The application can use this, for example, + * to erase flash pages. + * + * The PrepareImageStorage event is generated only in the case where a new firmware + * image is being downloaded. When a previously interrupted download is resumed, + * PrepareImageStorage is not generated. + * + * The application must signal completion of the prepare operation by calling the + * \c PrepareImageStorageComplete() method. It may do this within the event callback + * itself, or at a later time. If called from a task other than the chip task, + * the caller must hold the chip stack lock. + * + * The application can choose to ignore the PrepareImageStorage event by passing it + * to the default event handler. If this is done, the system automatically proceeds + * to the image download state. + * + * To support resuming an interrupted download, the application should persist the + * image URI (supplied as an event parameter), and use this when handling subsequent + * FetchPartialImageInfo events. + */ + kEvent_PrepareImageStorage, + + /** + * Image download has begun + * + * Informational event to signal the start of an image download transaction. + */ + kEvent_StartImageDownload, + + /** + * Store a block of image data + * + * Generated whenever a data block is received from the file download server. + * Parameters included with this event provide the data and the length of the data. + * + * To support resuming an interrupted download, the application should maintain a + * persistent count of the total number of image bytes stored, and use this value + * when handling subsequent FetchPartialImageInfo events. + */ + kEvent_StoreImageBlock, + + /** + * Compute an image integrity check value + * + * Requests the application to compute an integrity check value over the downloaded + * image. Generated once downloading is complete. + */ + kEvent_ComputeImageIntegrity, + + /** + * Reset state of partially downloaded image + * + * Requests the application to forget the persisted state associated with a downloaded + * image. A ResetPartialImageInfo event is generated whenever a downloaded image fails + * its integrity check. After a ResetPartialImageInfo event has been processed, + * subsequent FetchPartialImageInfo events should indicate that no partial image is + * available. + * + * Note that, when handling the ResetPartialImageInfo event, the application is NOT + * required to clear image data itself, only the state information associated with the + * image (i.e. the URI and partial image length). + * + * If the application does not support image download resumption, it may ignore this + * event by passing it to the default event handler. + */ + kEvent_ResetPartialImageInfo, + + /** + * Image is ready to be installed + * + * Informational event to signal that image is ready to be installed. + * Generated once an image passes the integrity check. + */ + kEvent_ReadyToInstall, + + /** + * Begin image installation + * + * Requests the application to being the process of installing a downloaded firmware + * image. + */ + kEvent_StartInstallImage, + + /** + * Software update process finished + * + * Generated when a software update check has finished with or without + * errors. Parameters included with this event provide the reason for failure + * if the attempt finished due to a failure. + */ + kEvent_Finished, + + /** + * Check default event handling behavior. + * + * Used to verify correct default event handling in the application. + * + * Applications must NOT handle this event. + */ + kEvent_DefaultCheck = 100, + + }; + + /** + * When a software update is available, the application can chose one of + * the following actions as part of the SoftwareUpdateAvailable API event + * callback. The default action will be set to kAction_Now. + */ + enum ActionType + { + /** + * Ignore the download completely. A kEvent_Finished API event callback will + * be generated with error CHIP_DEVICE_ERROR_SOFTWARE_UPDATE_CANCELLED if + * this option is selected and the retry logic will not be invoked. + */ + kAction_Ignore, + + /** + * Start the download right away. A kEvent_FetchPartialImageInfo API event + * callback will be generated right after. + */ + kAction_DownloadNow, + + /** + * Pause download on start. Scheduled software update checks (if enabled) will be suspended. + * State machine will remain in Download state. When ready, application can + * call the resume download API to proceed with download or call Abort to cancel. + */ + kAction_DownloadLater, + + /** + * Allows application to manage the rest of the phases of software update such as + * download, image integrity validation and install. Software update manager + * state machine will move to the ApplicationManaged state. Scheduled software update checks (if enabled) + * will be suspended till application calls Abort or ImageInstallComplete API. + */ + kAction_ApplicationManaged, + }; + + /** + * Incoming parameters sent with events generated directly from this component + * + */ + union InEventParam; + + /** + * Outgoing parameters sent with events generated directly from this component + * + */ + union OutEventParam; + + struct RetryParam + { + /** + * Specifies the retry attempt number. + * It is reset on a successful software update attempt. + */ + uint32_t NumRetries; + }; + + typedef void (*EventCallback)(void *apAppState, EventType aEvent, const InEventParam& aInParam, OutEventParam& aOutParam); + typedef void (*RetryPolicyCallback)(void *aAppState, RetryParam& aRetryParam, uint32_t& aOutIntervalMsec); + + CHIP_ERROR Abort(void); + CHIP_ERROR CheckNow(void); + CHIP_ERROR ImageInstallComplete(CHIP_ERROR aError); + CHIP_ERROR PrepareImageStorageComplete(CHIP_ERROR aError); + CHIP_ERROR SetEventCallback(void * const aAppState, const EventCallback aEventCallback); + CHIP_ERROR SetQueryIntervalWindow(uint32_t aMinWaitTimeMs, uint32_t aMaxWaitTimeMs); + + bool IsInProgress(void); + + void SetRetryPolicyCallback(const RetryPolicyCallback aRetryPolicyCallback); + + State GetState(void); + + static void DefaultEventHandler(void *apAppState, EventType aEvent, + const InEventParam& aInParam, + OutEventParam& aOutParam); + +private: + // ===== Members for internal use by the following friends. + + // friend class SoftwareUpdateManagerImpl; + template friend class Internal::GenericPlatformManagerImpl; + + CHIP_ERROR Init(void); + +protected: + + // Construction/destruction limited to subclasses. + SoftwareUpdateManager() = default; + ~SoftwareUpdateManager() = default; + + // No copy, move or assignment. + SoftwareUpdateManager(const SoftwareUpdateManager &) = delete; + SoftwareUpdateManager(const SoftwareUpdateManager &&) = delete; + SoftwareUpdateManager & operator=(const SoftwareUpdateManager &) = delete; +}; + +/** + * Returns a reference to the public interface of the SoftwareUpdateManager singleton object. + * + * chip application should use this to access features of the SoftwareUpdateManager object + * that are common to all platforms. + */ +extern SoftwareUpdateManager & SoftwareUpdateMgr(void); + +/** + * Returns the platform-specific implementation of the SoftwareUpdateManager singleton object. + * + * chip applications can use this to gain access to features of the SoftwareUpdateManager + * that are specific to the selected platform. + */ +extern SoftwareUpdateManagerImpl & SoftwareUpdateMgrImpl(void); + +} // namespace DeviceLayer +} // namespace chip + +/* Include a header file containing the implementation of the SoftwareUpdateManager + * object for the selected platform. + */ +#ifdef EXTERNAL_SOFTWAREUPDATEMANAGERIMPL_HEADER +#include EXTERNAL_SOFTWAREUPDATEMANAGERIMPL_HEADER +#else +#define SOFTWAREUPDATEMANAGERIMPL_HEADER +#include SOFTWAREUPDATEMANAGERIMPL_HEADER +#endif + +namespace chip { +namespace DeviceLayer { + +union SoftwareUpdateManager::InEventParam +{ + void Clear(void) { memset(this, 0, sizeof(*this)); } + + SoftwareUpdateManager * Source; + struct + { + TLVWriter * MetaDataWriter; + } PrepareQuery_Metadata; + + struct + { + CHIP_ERROR Error; + Profiles::StatusReporting::StatusReport *StatusReport; + } QueryPrepareFailed; + + struct + { + UpdatePriority Priority; + UpdateCondition Condition; + uint8_t IntegrityType; + const char *URI; + const char *Version; + } SoftwareUpdateAvailable; + + struct + { + const char *URI; + } FetchPartialImageInfo; + + struct + { + const char *URI; + uint8_t IntegrityType; + } PrepareImageStorage; + + struct + { + uint8_t *DataBlock; + uint32_t DataBlockLen; + } StoreImageBlock; + + struct + { + uint8_t IntegrityType; + uint8_t *IntegrityValueBuf; // Pointer to the buffer for the app to copy Integrity Value into. + uint8_t IntegrityValueBufLen; // Length of the provided buffer. + } ComputeImageIntegrity; + + struct + { + CHIP_ERROR Error; + Profiles::StatusReporting::StatusReport *StatusReport; + } Finished; +}; + +union SoftwareUpdateManager::OutEventParam +{ + void Clear(void) { memset(this, 0, sizeof(*this)); } + + bool DefaultHandlerCalled; + struct + { + const char *PackageSpecification; + const char *DesiredLocale; + CHIP_ERROR Error; + } PrepareQuery; + + struct + { + CHIP_ERROR Error; + } PrepareQuery_Metadata; + + struct + { + ActionType Action; + } SoftwareUpdateAvailable; + + struct + { + uint64_t PartialImageLen; + } FetchPartialImageInfo; + + struct + { + CHIP_ERROR Error; + } StoreImageBlock; + + struct + { + CHIP_ERROR Error; + } ComputeImageIntegrity; +}; + +inline CHIP_ERROR SoftwareUpdateManager::Init(void) +{ + return static_cast(this)->_Init(); +} + +inline CHIP_ERROR SoftwareUpdateManager::CheckNow(void) +{ + return static_cast(this)->_CheckNow(); +} + +inline CHIP_ERROR SoftwareUpdateManager::ImageInstallComplete(CHIP_ERROR aError) +{ + return static_cast(this)->_ImageInstallComplete(aError); +} + +inline CHIP_ERROR SoftwareUpdateManager::PrepareImageStorageComplete(CHIP_ERROR aError) +{ + return static_cast(this)->_PrepareImageStorageComplete(aError); +} + +inline SoftwareUpdateManager::State SoftwareUpdateManager::GetState(void) +{ + return static_cast(this)->_GetState(); +} + +inline CHIP_ERROR SoftwareUpdateManager::Abort(void) +{ + return static_cast(this)->_Abort(); +} + +inline bool SoftwareUpdateManager::IsInProgress(void) +{ + return static_cast(this)->_IsInProgress(); +} + +inline CHIP_ERROR SoftwareUpdateManager::SetQueryIntervalWindow(uint32_t aMinRangeSecs, uint32_t aMaxRangeSecs) +{ + return static_cast(this)->_SetQueryIntervalWindow(aMinRangeSecs, aMaxRangeSecs); +} + +inline void SoftwareUpdateManager::SetRetryPolicyCallback(const RetryPolicyCallback aRetryPolicyCallback) +{ + static_cast(this)->_SetRetryPolicyCallback(aRetryPolicyCallback); +} + +inline CHIP_ERROR SoftwareUpdateManager::SetEventCallback(void * const aAppState, const EventCallback aEventCallback) +{ + return static_cast(this)->_SetEventCallback(aAppState, aEventCallback); +} + +inline void SoftwareUpdateManager::DefaultEventHandler(void *apAppState, EventType aEvent, + const InEventParam& aInParam, + OutEventParam& aOutParam) +{ + ImplClass::_DefaultEventHandler(apAppState, aEvent, aInParam, aOutParam); +} + +} // namespace DeviceLayer +} // namespace chip + +#endif // CHIP_DEVICE_CONFIG_ENABLE_SOFTWARE_UPDATE_MANAGER +#endif // SOFTWARE_UPDATE_MANAGER_H diff --git a/src/platform/include/ThreadStackManager.h b/src/platform/include/ThreadStackManager.h new file mode 100644 index 00000000000000..d45b4831743032 --- /dev/null +++ b/src/platform/include/ThreadStackManager.h @@ -0,0 +1,288 @@ +/* + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * Defines the public interface for the Device Layer ThreadStackManager object. + */ + +#ifndef THREAD_STACK_MANAGER_H +#define THREAD_STACK_MANAGER_H + +namespace chip { +namespace DeviceLayer { + +class PlatformManagerImpl; +class ThreadStackManagerImpl; +class ConfigurationManagerImpl; + +namespace Internal { +class DeviceNetworkInfo; +class DeviceControlServer; +template class GenericPlatformManagerImpl; +template class GenericPlatformManagerImpl_FreeRTOS; +template class GenericConnectivityManagerImpl_Thread; +template class GenericThreadStackManagerImpl_OpenThread; +template class GenericThreadStackManagerImpl_OpenThread_LwIP; +template class GenericThreadStackManagerImpl_FreeRTOS; +template class GenericNetworkProvisioningServerImpl; +} // namespace Internal + +/** + * Provides features for initializing and interacting with the Thread stack on + * a chip-enabled device. + */ +class ThreadStackManager +{ + using ImplClass = ThreadStackManagerImpl; + +public: + + // ===== Members that define the public interface of the ThreadStackManager + + CHIP_ERROR InitThreadStack(void); + void ProcessThreadActivity(void); + CHIP_ERROR StartThreadTask(void); + void LockThreadStack(void); + bool TryLockThreadStack(void); + void UnlockThreadStack(void); + bool HaveRouteToAddress(const IPAddress & destAddr); + CHIP_ERROR GetAndLogThreadStatsCounters(void); + CHIP_ERROR GetAndLogThreadTopologyMinimal(void); + CHIP_ERROR GetAndLogThreadTopologyFull(void); + CHIP_ERROR GetPrimary802154MACAddress(uint8_t *buf); + +private: + + // ===== Members for internal use by the following friends. + + friend class PlatformManagerImpl; + friend class ConfigurationManagerImpl; + friend class Internal::BLEManagerImpl; + friend class Internal::DeviceControlServer; + template friend class Internal::GenericPlatformManagerImpl; + template friend class Internal::GenericConfigurationManagerImpl; + template friend class Internal::GenericPlatformManagerImpl_FreeRTOS; + template friend class Internal::GenericConnectivityManagerImpl_Thread; + template friend class Internal::GenericThreadStackManagerImpl_OpenThread; + template friend class Internal::GenericThreadStackManagerImpl_OpenThread_LwIP; + template friend class Internal::GenericThreadStackManagerImpl_FreeRTOS; + template friend class Internal::GenericNetworkProvisioningServerImpl; + + void OnPlatformEvent(const ChipDeviceEvent * event); + bool IsThreadEnabled(void); + CHIP_ERROR SetThreadEnabled(bool val); + bool IsThreadProvisioned(void); + bool IsThreadAttached(void); + CHIP_ERROR GetThreadProvision(Internal::DeviceNetworkInfo & netInfo, bool includeCredentials); + CHIP_ERROR SetThreadProvision(const Internal::DeviceNetworkInfo & netInfo); + void ClearThreadProvision(void); + ConnectivityManager::ThreadDeviceType GetThreadDeviceType(void); + CHIP_ERROR SetThreadDeviceType(ConnectivityManager::ThreadDeviceType threadRole); + void GetThreadPollingConfig(ConnectivityManager::ThreadPollingConfig & pollingConfig); + CHIP_ERROR SetThreadPollingConfig(const ConnectivityManager::ThreadPollingConfig & pollingConfig); + bool HaveMeshConnectivity(void); + void OnMessageLayerActivityChanged(bool messageLayerIsActive); + void OnWoBLEAdvertisingStart(void); + void OnWoBLEAdvertisingStop(void); + +protected: + + // Construction/destruction limited to subclasses. + ThreadStackManager() = default; + ~ThreadStackManager() = default; + + // No copy, move or assignment. + ThreadStackManager(const ThreadStackManager &) = delete; + ThreadStackManager(const ThreadStackManager &&) = delete; + ThreadStackManager & operator=(const ThreadStackManager &) = delete; +}; + +/** + * Returns the public interface of the ThreadStackManager singleton object. + * + * chip applications should use this to access features of the ThreadStackManager object + * that are common to all platforms. + */ +extern ThreadStackManager & ThreadStackMgr(void); + +/** + * Returns the platform-specific implementation of the ThreadStackManager singleton object. + * + * chip applications can use this to gain access to features of the ThreadStackManager + * that are specific to the selected platform. + */ +extern ThreadStackManagerImpl & ThreadStackMgrImpl(void); + +} // namespace DeviceLayer +} // namespace chip + +/* Include a header file containing the implementation of the ThreadStackManager + * object for the selected platform. + */ +#ifdef EXTERNAL_THREADSTACKMANAGERIMPL_HEADER +#include EXTERNAL_THREADSTACKMANAGERIMPL_HEADER +#else +#define THREADSTACKMANAGERIMPL_HEADER +#include THREADSTACKMANAGERIMPL_HEADER +#endif + +namespace chip { +namespace DeviceLayer { + +inline CHIP_ERROR ThreadStackManager::InitThreadStack() +{ + return static_cast(this)->_InitThreadStack(); +} + +inline void ThreadStackManager::ProcessThreadActivity() +{ + static_cast(this)->_ProcessThreadActivity(); +} + +inline CHIP_ERROR ThreadStackManager::StartThreadTask() +{ + return static_cast(this)->_StartThreadTask(); +} + +inline void ThreadStackManager::LockThreadStack() +{ + static_cast(this)->_LockThreadStack(); +} + +inline bool ThreadStackManager::TryLockThreadStack() +{ + return static_cast(this)->_TryLockThreadStack(); +} + +inline void ThreadStackManager::UnlockThreadStack() +{ + static_cast(this)->_UnlockThreadStack(); +} + +/** + * Determines whether a route exists via the Thread interface to the specified destination address. + */ +inline bool ThreadStackManager::HaveRouteToAddress(const IPAddress & destAddr) +{ + return static_cast(this)->_HaveRouteToAddress(destAddr); +} + +inline void ThreadStackManager::OnPlatformEvent(const chipDeviceEvent * event) +{ + static_cast(this)->_OnPlatformEvent(event); +} + +inline bool ThreadStackManager::IsThreadEnabled(void) +{ + return static_cast(this)->_IsThreadEnabled(); +} + +inline CHIP_ERROR ThreadStackManager::SetThreadEnabled(bool val) +{ + return static_cast(this)->_SetThreadEnabled(val); +} + +inline bool ThreadStackManager::IsThreadProvisioned(void) +{ + return static_cast(this)->_IsThreadProvisioned(); +} + +inline bool ThreadStackManager::IsThreadAttached(void) +{ + return static_cast(this)->_IsThreadAttached(); +} + +inline CHIP_ERROR ThreadStackManager::GetThreadProvision(Internal::DeviceNetworkInfo & netInfo, bool includeCredentials) +{ + return static_cast(this)->_GetThreadProvision(netInfo, includeCredentials); +} + +inline CHIP_ERROR ThreadStackManager::SetThreadProvision(const Internal::DeviceNetworkInfo & netInfo) +{ + return static_cast(this)->_SetThreadProvision(netInfo); +} + +inline void ThreadStackManager::ClearThreadProvision(void) +{ + static_cast(this)->_ClearThreadProvision(); +} + +inline ConnectivityManager::ThreadDeviceType ThreadStackManager::GetThreadDeviceType(void) +{ + return static_cast(this)->_GetThreadDeviceType(); +} + +inline CHIP_ERROR ThreadStackManager::SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType) +{ + return static_cast(this)->_SetThreadDeviceType(deviceType); +} + +inline void ThreadStackManager::GetThreadPollingConfig(ConnectivityManager::ThreadPollingConfig & pollingConfig) +{ + static_cast(this)->_GetThreadPollingConfig(pollingConfig); +} + +inline CHIP_ERROR ThreadStackManager::SetThreadPollingConfig(const ConnectivityManager::ThreadPollingConfig & pollingConfig) +{ + return static_cast(this)->_SetThreadPollingConfig(pollingConfig); +} + +inline bool ThreadStackManager::HaveMeshConnectivity(void) +{ + return static_cast(this)->_HaveMeshConnectivity(); +} + +inline void ThreadStackManager::OnMessageLayerActivityChanged(bool messageLayerIsActive) +{ + return static_cast(this)->_OnMessageLayerActivityChanged(messageLayerIsActive); +} + +inline void ThreadStackManager::OnWoBLEAdvertisingStart(void) +{ + static_cast(this)->_OnWoBLEAdvertisingStart(); +} + +inline void ThreadStackManager::OnWoBLEAdvertisingStop(void) +{ + static_cast(this)->_OnWoBLEAdvertisingStop(); +} + +inline CHIP_ERROR ThreadStackManager::GetAndLogThreadStatsCounters(void) +{ + return static_cast(this)->_GetAndLogThreadStatsCounters(); +} + +inline CHIP_ERROR ThreadStackManager::GetAndLogThreadTopologyMinimal(void) +{ + return static_cast(this)->_GetAndLogThreadTopologyMinimal(); +} + +inline CHIP_ERROR ThreadStackManager::GetAndLogThreadTopologyFull(void) +{ + return static_cast(this)->_GetAndLogThreadTopologyFull(); +} + +inline CHIP_ERROR ThreadStackManager::GetPrimary802154MACAddress(uint8_t * buf) +{ + return static_cast(this)->_GetPrimary802154MACAddress(buf); +} + +} // namespace DeviceLayer +} // namespace chip + +#endif // THREAD_STACK_MANAGER_H diff --git a/src/platform/include/TimeSyncManager.h b/src/platform/include/TimeSyncManager.h new file mode 100644 index 00000000000000..d89d4b5cf90a1b --- /dev/null +++ b/src/platform/include/TimeSyncManager.h @@ -0,0 +1,148 @@ +/* + * + * + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file + * Defines the chip Device Layer TimeSyncManager object. + * + */ + +#ifndef TIME_SYNC_MANAGER_H +#define TIME_SYNC_MANAGER_H + +namespace chip { +namespace Profiles { +namespace StatusReporting { +class StatusReport; +} +} +} + +namespace chip { +namespace DeviceLayer { + +class PlatformManagerImpl; +namespace Internal { +extern CHIP_ERROR InitServiceDirectoryManager(void); +template class GenericPlatformManagerImpl; +template class GenericPlatformManagerImpl_FreeRTOS; +} + +/** + * Manages time synchronization for chip Devices. + */ +class TimeSyncManager final +{ +public: + + // ===== Members that define the public interface of the TimeSyncManager + + enum TimeSyncMode + { + kTimeSyncMode_NotSupported = 0, + kTimeSyncMode_Disabled = 1, + kTimeSyncMode_Service = 2, + + kTimeSyncMode_Max, + }; + + TimeSyncMode GetMode(); + CHIP_ERROR SetMode(TimeSyncMode newMode); + + uint32_t GetSyncInterval(); + void SetSyncInterval(uint32_t intervalSec); + + bool IsTimeSynchronized(); + +private: + + // ===== Members for internal use by the following friends. + + friend class PlatformManagerImpl; + template friend class Internal::GenericPlatformManagerImpl; + template friend class Internal::GenericPlatformManagerImpl_FreeRTOS; + friend CHIP_ERROR Internal::InitServiceDirectoryManager(); + friend TimeSyncManager & TimeSyncMgr(void); + + static TimeSyncManager sInstance; + + CHIP_ERROR Init(); + void OnPlatformEvent(const ChipDeviceEvent * event); +#if CHIP_DEVICE_CONFIG_ENABLE_SERVICE_DIRECTORY_TIME_SYNC + static void MarkServiceDirRequestStart(); + static void ProcessServiceDirTimeData(uint64_t timeQueryReceiptMsec, uint32_t timeProcessMsec); +#endif + + // ===== Private members for use by this class only. + + uint64_t mLastSyncTimeMS; // in monotonic time +#if CHIP_DEVICE_CONFIG_ENABLE_SERVICE_DIRECTORY_TIME_SYNC + uint64_t mServiceDirTimeSyncStartUS; +#endif +#if CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC + ::chip::Binding * mTimeSyncBinding; +#endif + uint32_t mSyncIntervalSec; + TimeSyncMode mMode; + + void DriveTimeSync(); + void CancelTimeSync(); + void ApplySynchronizedTime(uint64_t syncedRealTimeUS); + void TimeSyncFailed(CHIP_ERROR reason, chip::Profiles::StatusReporting::StatusReport * statusReport); + +#if CHIP_DEVICE_CONFIG_ENABLE_CHIP_TIME_SERVICE_TIME_SYNC + static void TimeServiceSync_HandleBindingEvent(void * appState, ::chip::Binding::EventType event, + const ::chip::Binding::InEventParam & inParam, ::chip::Binding::OutEventParam & outParam); + static void TimeServiceSync_HandleSyncComplete(void * context, CHIP_ERROR result, int64_t syncedRealTimeUS); +#endif + + static void DriveTimeSync(::chip::System::Layer * layer, void * appState, ::chip::System::Error err); + +protected: + + // Construction/destruction limited to subclasses. + TimeSyncManager() = default; + ~TimeSyncManager() = default; + + // No copy, move or assignment. + TimeSyncManager(const TimeSyncManager &) = delete; + TimeSyncManager(const TimeSyncManager &&) = delete; + TimeSyncManager & operator=(const TimeSyncManager &) = delete; +}; + +inline TimeSyncManager::TimeSyncMode TimeSyncManager::GetMode() +{ + return mMode; +} + +inline uint32_t TimeSyncManager::GetSyncInterval() +{ + return mSyncIntervalSec; +} + +/** + * Returns a reference to the TimeSyncManager singleton object. + */ +inline TimeSyncManager & TimeSyncMgr(void) +{ + return TimeSyncManager::sInstance; +} + +} // namespace DeviceLayer +} // namespace chip + +#endif // TIME_SYNC_MANAGER_H