
/* SPDX-License-Identifier: BSD-2-Clause-Patent
 *
 * SPDX-FileCopyrightText: 2020 the prplMesh contributors (see AUTHORS.md)
 *
 * This code is subject to the terms of the BSD+Patent license.
 * See LICENSE file for more details.
 */

%define {
    mib HTCapabilities {
        /* Coming from 17.2.8 of the Multi-AP Specification */
        object HTCapabilities {
            /* Maximum number of supported Tx spatial streams */
            %read-only uint32 MaxNumberOfTxSpatialStreams {
                on action validate call check_maximum 4;
            }
            /* Maximum number of supported Rx spatial streams */
            %read-only uint32 MaxNumberOfRxSpatialStreams {
                on action validate call check_maximum 4;
            }
            %read-only bool HTShortGI20;        /* HT short GI for 20 MHz support. */
            %read-only bool HTShortGI40;        /* HT short GI for 40 MHz support. */
            %read-only bool HT40;               /* HT 40 MHz bandwidth support.*/
        }
    }
}

%define {
    mib VHTCapabilities {
        /* Coming from 17.2.9 of the Multi-AP Specification */
        object VHTCapabilities {
            /* Supported set of VHT MCSs and NSSs that can be transmitted. */
            %read-only uint16 MCSNSSTxSet {
                on action validate call check_range [0, 65536];
            }
            /* Supported set of VHT MCSs and NSSs that can be received. */
            %read-only uint16 MCSNSSRxSet {
                on action validate call check_range [0, 65536];
            }
            /* Maximum number of supported Tx spatial streams */
            %read-only uint32 MaxNumberOfTxSpatialStreams {
                on action validate call check_maximum 8;
            }
            /* Maximum number of supported Rx spatial streams */
            %read-only uint32 MaxNumberOfRxSpatialStreams {
                on action validate call check_maximum 8;
            }
            %read-only bool VHTShortGI80;               /* VHT short GI for 80 MHz support. */
            %read-only bool VHTShortGI160;              /* VHT short GI for 160 MHz and 80+80 MHz support. */
            %read-only bool VHT8080;                    /* VHT 80+80 MHz bandwidth support. */
            %read-only bool VHT160;                     /* VHT 160 MHz bandwidth support. */
            %read-only bool SUBeamformer;               /* Single-user beamformer support. */
            %read-only bool MUBeamformer;               /* Multi-user beamformer support. */
        }
    }
}

%define {
    mib WiFi6Capabilities {
        /* Coming from 17.2.72 of the Multi-AP Specification R4 and TR-181 spec v2.15 */
        object WiFi6Capabilities {
            /* Supported HE MCS and NSS indicating set of supported HE Tx and Rx MCS/NSS. */
            object MCSNSS[] {
                counted with MCSNSSNumberOfEntries;
                %read-only uint32 MCSNSSSet;            /* Individual MCS and NSS set*/
            }
            /* Maximum number of supported Tx spatial streams */
            %read-only uint32 MaxNumberOfTxSpatialStreams {
                on action validate call check_maximum 8;
            }
            /* Maximum number of supported Rx spatial streams */
            %read-only uint32 MaxNumberOfRxSpatialStreams {
                on action validate call check_maximum 8;
            }
            %read-only bool HE160;                      /* HE 160 MHz bandwidth support. */
            %read-only bool HE8080;                     /* HE 80+80 MHz bandwidth support. */
            %read-only bool SUBeamformer;               /* Single-user beamformer support. */
            %read-only bool SUBeamformee;               /* Single-user beamformee support. */
            %read-only bool MUBeamformer;               /* Multi-user beamformer support. */
            %read-only bool Beamformee80orLess;         /* Beamformee STS ≤ 80 MHz support. */
            %read-only bool BeamformeeAbove80;          /* Beamformee STS > 80 MHz support. */

            %read-only bool ULMUMIMO;                   /* UL MU-MIMO support. */
            %read-only bool ULOFDMA;                    /* UL OFDMA support. */
            %read-only bool DLOFDMA;                    /* DL OFDMA support. */

            /* Maximum number of users supported per DL MU-MIMO TX in an AP role. */
            %read-only uint32 MaxDLMUMIMO = 0 {
                on action validate call check_range [0, 255];
            }
            /* Maximum number of users supported per UL MU-MIMO RX in an AP role. */
            %read-only uint32 MaxULMUMIMO = 0 {
                on action validate call check_range [0, 255];
            }
            /* Maximum number of users supported per DL OFDMA TX in an AP role. */
            %read-only uint32 MaxDLOFDMA = 0 {
                on action validate call check_range [0, 255];
            }
            /* Maximum number of users supported per UL OFDMA RX in an AP role */
            %read-only uint32 MaxULOFDMA = 0 {
                on action validate call check_range [0, 255];
            }

            %read-only bool RTS;                        /* Request To Send (RTS) support. */
            %read-only bool MURTS;                      /* Multi-user RTS support. */
            %read-only bool MultiBSSID;                 /* Multi-BSSID support. */
            %read-only bool MUEDCA;                     /* Multi-user enhanced distributed channel access (MU EDCA) support. */
            %read-only bool TWTRequestor;               /* TWT Requester support. */
            %read-only bool TWTResponder;               /* TWT Responder support. */
            %read-only bool SpatialReuse;               /* EasyMesh configuration and reporting of BSS Color/Spatial Reuse support. */
            %read-only bool AnticipatedChannelUsage;    /* Anticipated Channel Usage (ACU) reporting support. */
        }
    }
}


%define {

    /* --- PRPL Controller DM --- */

    @CONTROLLER_ROOT_DM_Header@

                /* Configuration options for the controller */
                %persistent object Configuration {

                    /* Enables the persistent database to store clients persistently. Requires platform support */
                    %persistent bool PersistentDatabaseEnabled {
                        default false;
                    }

                    /* Maximum number of clients to store in the persistent database */
                    %persistent uint32 ClientsPersistentDatabaseMaxSize {
                        default 256;
                    }

                    /* Maximum lifetime (in minutes) of clients in the persistent database */
                    %persistent uint32 MaxTimeLifeDelayMinutes {
                        default 525600;
                    }

                    /* Maximum lifetime (in minutes) of "unfriendly" clients in the persistent database */
                    %persistent uint32 UnfriendlyDeviceMaxTimeLifeDelayMinutes {
                        default 1440;
                    }

                    /* Interval (in seconds) to run the persistent DB aging mechanism */
                    %persistent uint32 PersistentDatabaseAgingIntervalSec {
                        default 3600;
                    }

                    /* If enabled, ire roaming is active in the optimal path task */
                    %persistent bool IRERoamingEnabled {
                        userflags %upc;
                        default true;
                    }

                    /* Used in optimal_path_task to compute new BSS for the STA based on 11k measurements by STA */
                    %persistent bool Client11kRoamingEnabled {
                        default true;
                    }

                    /* Used in optimal_path_task; applies bonus to current BSS {phy_rate or rssi}; 
                    choice of parameter is based on prefer_signal_strength flag */
                    %persistent uint32 SteeringCurrentBonus {
                        default 10;
                        on action validate call check_range [0, 10000];
                    }

                    /* Used in client_steering_task to format the 1905 Client Steering Request 
                    packet sent to the steering source agent */
                    %persistent uint32 SteeringDisassociationTimerMSec {
                        default 200;
                    }

                    /* Interval for periodic link metrics requests from all agents (set to 0 to disable). */
                    %persistent uint32 LinkMetricsRequestIntervalSec {
                        default 60;
                    }

                    /* Used by controller to start / stop channel selection task */
                    %persistent bool ChannelSelectionTaskEnabled {
                        userflags %upc;
                        default true;
                    }
                    
                    /* Used by controller to start / stop dynamic channel selection task */
                    %persistent bool DynamicChannelSelectionTaskEnabled {
                        userflags %upc;
                        default false;
                    }

                    /* Used to start IRE network optimization task */
                    %persistent bool BackhaulOptimizationEnabled {
                        default false;
                    }

                    /* Load balancer task will use client steering task to move a STA between agents */
                    %persistent bool LoadBalancingTaskEnabled {
                        default false;
                    }

                    /* Used by optimal_path_task; chooses best BSS based on `rssi` 
                    if prefer_signal_strength is TRUE, `phy_rate` otherwise */
                    %persistent bool OptimalPathPreferSignalStrength {
                        default false;
                    }

                    /* Used by controller to start / stop the health check task */
                    %persistent bool HealthCheckTaskEnabled {
                        default false;
                    }

                    /* Used by controller to start / stop statistics polling task */
                    %persistent bool StatisticsPollingTaskEnabled {
                        default true;
                    }

                    /* Interval (in seconds) for statistics polling task */
                    %persistent uint32 StatisticsPollingRateSec {
                        default 10;
                        on action validate call check_range [1, 10000];
                    }
                    
                    /* Used by channel selection task; currently (03.2024) does nothing 
                    as the task never goes to the state where this flag is checked */
                    %persistent bool DFSReentryEnabled {
                        default true;
                    }

                    /* Used by channel selection task; currently (03.2024) does nothing 
                    as the task never goes to the state where this flag is checked */
                    %persistent bool DFSTaskEnabled {
                        default true;
                    }

                    /* Used by handle_cmdu_1905_autoconfiguration_WSC; don`t send credentials to extenders if enabled */
                    %persistent bool DaisyChainingDisabled {
                        default false;
                    }

                    /* used by controller to start / stop statistics_polling_task */
                    %persistent bool DiagnosticsMeasurements {
                        default true;
                    }

                    /* used by statistics_polling_task as interval for sending 
                    beerocks_message::cACTION_CONTROL_HOSTAP_STATS_MEASUREMENT_REQUEST to known agents */
                    %persistent uint32 DiagnosticsMeasurementsRate {
                        default 10;
                    }

                    /* If set to 1, enable reporting for unsuccessful associations. */
                    %persistent bool UnsuccessfulAssocReportPolicy {
                        default true;
                    }

                    /* Maximum rate for reporting unsuccessful association in attempts per minute. */
                    %persistent uint32 UnsuccessfulAssocMaxReportingRate {
                        default 30;
                    }

                    /* optimal_path_task; applies bonus to current BSS {phy_rate or rssi}; 
                    choice of parameter is based on prefer_signal_strength flag */
                    %persistent uint32 RoamingHysteresisPercentBonus {
                        default 10;
                    }

                    /* RSSI measurements responses timeout */
                    %persistent uint32 RSSIMeasurementsTimeout {
                        default 10000;
                    }
                    
                    /* used by controller to start / stop statistics_polling_task */
                    %persistent uint32 BeaconMeasurementsTimeout {
                        default 6000;
                    }

                    /* RCPI (Received Channel Power Indicator) threshold in dB.
                    If a station's RCPI drops below this value, a metrics report is triggered.
                    Value is encoded per IEEE 802.11 Table 9-176. Default 0 disables reporting. */
                    %persistent uint32 STAReportingRCPIThreshold {
                        default 0;
                    }

                    /* Override value for RCPI hysteresis margin in dB.
                    Adds a margin before RCPI changes trigger a report to reduce report noise.
                    Set to 0 to use system default margin. Default is 0 (no override). */
                    %persistent uint32 STAReportingRCPIHystMarginOverrideThreshold {
                        default 0;
                    }

                    /* Channel Utilization threshold (%) for triggering AP Metrics reports.
                    If channel usage exceeds this value, a report is sent.
                    Helps detect overloaded environments. Default is 0 (disabled). */
                    %persistent uint32 APReportingChannelUtilizationThreshold {
                        default 0;
                    }

                    /* Steering policy */
                    %persistent uint32 SteeringPolicy {
                        default 0;
                    }

                    /* Controls whether Associated STA Link Metrics TLV is included in reports.
                    If true, per-client metrics like RSSI and PHY rate are reported.
                    Default is false (not included). */
                    %persistent bool AssocSTALinkMetricsInclusionPolicy {
                        default false;
                    }

                    /* Controls whether Associated STA Traffic Stats TLV is included in reports.
                    If true, includes data such as bytes transmitted/received per STA.
                    Default is false (not included). */
                    %persistent bool AssocSTATrafficStatsInclusionPolicy {
                        default false;
                    }

                    /* Controls whether Wi-Fi 6 STA Status Report TLV is included in reports.
                    If true, reports include Wi-Fi 6 features like BSS color and HE capabilities.
                    Default is false (not included). */
                    %persistent bool AssocWiFi6STAStatusReportInclusionPolicy {
                        default false;
                    }

                    /* DCS channel pool for radio 2.4 GHz that is used to determine what channels to scan */
                    %persistent string DCSChannelPool_24GHz {
                        default "1,6,11";
                    }
                    
                    /* DCS channel pool for radio 5 GHz that is used to determine what channels to scan */
                    %persistent string DCSChannelPool_5GHz {
                        default "36-48,149-165";
                    }
                    
                    /* DCS channel pool for radio 6 GHz that is used to determine what channels to scan */
                    %persistent string DCSChannelPool_6GHz {
                        default "0";
                    }

                    /* QoS configuration */
                    %persistent object QoS {
                        /* Output queue priority mapping */
                        %persistent uint32 QoSRuleOutput {
                            on action validate call check_range [0, 9];
                        }

                        /* DSCP to QoS mapping */
                        %persistent string DSCPMapping {
                            on action validate call check_range [0, 64];
                        }
                    }
                }
    @CONTROLLER_ROOT_DM_Footer@ 


    /* --- TR-181 DataElements DM --- */

    @DATAELEMENTS_ROOT_DM_Header@

                // Define controller.Network element
                object Network {

                    // Define string variable
                    %read-only string ID = "0";

                    // Define date variable in format YYYY-MM-DDThh:mm:ssZ
                    %read-only datetime TimeStamp = "2020-08-31T11:22:39Z";

                    %read-only string ControllerID = "0";

                    /*
                        Network devices list.
                    */
                    object Device[] {
                        counted with DeviceNumberOfEntries;
                    }

                    object AccessPoint[] {
                        counted with AccessPointNumberOfEntries;
                    }
                    
                    void AccessPointCommit();

                    // Global network wide enable
                    bool Enable = true; 

                    // Global network wide enable
                    object X-PRPL_ORG_Group[] {
                        //name of the group (private / guest, etc...)
                        %read-only string Name = "";

                        //  Enable of the group
                        bool Enable;
                    }

                    void SetServicePrioritization();

                    void ClientSteering(
                        %in %mandatory string station_mac,
                        %in %mandatory string target_bssid
                    );

                    %read-only object MultiAPSteeringSummaryStats {
                        %read-only uint64 NoCandidateAPFailures = 0;
                        %read-only uint64 BlacklistAttempts = 0;
                        %read-only uint64 BlacklistSuccesses = 0;
                        %read-only uint64 BlacklistFailures = 0;
                        %read-only uint64 BTMAttempts = 0;
                        %read-only uint64 BTMSuccesses = 0;
                        %read-only uint64 BTMFailures = 0;
                        %read-only uint64 BTMQueryResponses = 0;
                    }
                    /* Update all unassociated stations stats, from all agents and all radios */
                    bool UpdateUnassociatedStationsStats();
                }
                %persistent %read-only object SteerEvent[] {
                    counted with SteerEventNumberOfEntries;
                    %persistent %read-only string DeviceId = "00:00:00:00:00:00";
                    %persistent %read-only string TimeStamp = "2020-08-31T11:22:39Z";
                    %persistent %read-only string SteeredFrom = "00:00:00:00:00:00";
                    %persistent %read-only string Result {
                        default "Unknown";
                        on action validate call check_enum [
                            "Unknown",
                            "Success",
                            "Fail"
                        ];
                    }
                    %persistent %read-only uint16 StatusCode;
                    %persistent %read-only string Status = "Unknown";
                    %persistent %read-only string SteeredTo = "00:00:00:00:00:00";
                    %persistent %read-only int64 TimeTaken;
                    %persistent %read-only int32 NewLinkRate;
                    %persistent %read-only string SteeringType {
                        default "Unknown";
                        on action validate call check_enum [
                            "BTM",
                            "Blacklist",
                            "Unknown"
                        ];
                    }
                    %persistent %read-only string SteeringOrigin {
                        default "Unknown";
                        on action validate call check_enum [
                            "Unknown",
                            "NBAPI",
                            "CLI",
                            "Controller",
                            "Agent",
                            "Station"
                        ];
                    }
                }
                %read-only object AgentConnectedEvent[];
                %read-only object AgentDisconnectedEvent[];

    @DATAELEMENTS_ROOT_DM_Footer@ 

}

%populate {
    on event "dm:object-changed" call event_configuration_changed
        filter 'object matches "@CONTROLLER_ROOT_DM_literal@\.Configuration\."';

    on event "dm:object-changed" call event_network_enable_changed                                                                                             
        filter 'object matches "@DATAELEMENTS_ROOT_DM_literal@\.Network\." && contains("parameters.Enable")'; 

    on event "*" call event_network_group_changed                                                                                             
        filter 'object matches "@DATAELEMENTS_ROOT_DM_literal@\.Network\.X-PRPL_ORG_Group\."'; 
}

include "device.odl";
include "radio.odl";
include "bss.odl";
include "capabilities.odl";
include "scan_result.odl";
include "sta.odl";
include "association_event.odl";
include "disassociation_event.odl";
include "access_point.odl";
include "agent_connected_event.odl";
include "failed_connection_event.odl";
include "agent_disconnected_event.odl";
include "unassociated_sta.odl";
