|
| 1 | +/* |
| 2 | + * |
| 3 | + * Copyright (c) 2024 Project CHIP Authors |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + * you may not use this file except in compliance with the License. |
| 7 | + * You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +#include <app-common/zap-generated/cluster-enums.h> |
| 19 | +#include <app/clusters/wifi-network-diagnostics-server/WiFiDiagnosticsTestEventTriggerHandler.h> |
| 20 | +#include <app/clusters/wifi-network-diagnostics-server/wifi-network-diagnostics-server.h> |
| 21 | +#include <platform/CHIPDeviceLayer.h> |
| 22 | +#include <platform/DiagnosticDataProvider.h> |
| 23 | + |
| 24 | +#include <ctime> |
| 25 | +#include <string> |
| 26 | + |
| 27 | +using namespace chip; |
| 28 | +using namespace chip::app; |
| 29 | +using namespace chip::DeviceLayer; |
| 30 | +using namespace chip::app::Clusters; |
| 31 | + |
| 32 | +namespace { |
| 33 | + |
| 34 | +/** |
| 35 | + * @brief Helper function to simulate a Disconnection event |
| 36 | + */ |
| 37 | +void SetTestEventTrigger_Disconnection() |
| 38 | +{ |
| 39 | + uint16_t reasonCode = 3; // Deauthenticated because sending STA is leaving (or has left) IBSS or ESS. |
| 40 | + |
| 41 | + WiFiDiagnosticsServer::Instance().OnDisconnectionDetected(reasonCode); |
| 42 | +} |
| 43 | + |
| 44 | +/** |
| 45 | + * @brief Helper function to simulate an Association Failure event |
| 46 | + */ |
| 47 | +void SetTestEventTrigger_AssociationFailure() |
| 48 | +{ |
| 49 | + uint8_t associationFailureCause = |
| 50 | + static_cast<uint8_t>(WiFiNetworkDiagnostics::AssociationFailureCauseEnum::kAuthenticationFailed); |
| 51 | + uint16_t status = 4; // IEEE 802.11-2020 Status Codes, AP is unable to handle additional associated STAs |
| 52 | + |
| 53 | + WiFiDiagnosticsServer::Instance().OnAssociationFailureDetected(associationFailureCause, status); |
| 54 | +} |
| 55 | + |
| 56 | +/** |
| 57 | + * @brief Helper function to simulate a Connection Status event |
| 58 | + */ |
| 59 | +void SetTestEventTrigger_ConnectionStatus() |
| 60 | +{ |
| 61 | + uint8_t connectionStatus = static_cast<uint8_t>(WiFiNetworkDiagnostics::ConnectionStatusEnum::kNotConnected); |
| 62 | + WiFiDiagnosticsServer::Instance().OnConnectionStatusChanged(connectionStatus); |
| 63 | +} |
| 64 | + |
| 65 | +} // anonymous namespace |
| 66 | + |
| 67 | +bool HandleWiFiDiagnosticsTestEventTrigger(uint64_t eventTrigger) |
| 68 | +{ |
| 69 | + // Convert raw trigger to our enum |
| 70 | + WiFiDiagnosticsTrigger trigger = static_cast<WiFiDiagnosticsTrigger>(eventTrigger); |
| 71 | + |
| 72 | + switch (trigger) |
| 73 | + { |
| 74 | + case WiFiDiagnosticsTrigger::kDisconnection: |
| 75 | + ChipLogProgress(Support, "[WiFiDiagnostics-Test-Event] => Disconnection triggered"); |
| 76 | + SetTestEventTrigger_Disconnection(); |
| 77 | + break; |
| 78 | + |
| 79 | + case WiFiDiagnosticsTrigger::kAssociationFailure: |
| 80 | + ChipLogProgress(Support, "[WiFiDiagnostics-Test-Event] => AssociationFailure triggered"); |
| 81 | + SetTestEventTrigger_AssociationFailure(); |
| 82 | + break; |
| 83 | + |
| 84 | + case WiFiDiagnosticsTrigger::kConnectionStatus: |
| 85 | + ChipLogProgress(Support, "[WiFiDiagnostics-Test-Event] => ConnectionStatus triggered"); |
| 86 | + SetTestEventTrigger_ConnectionStatus(); |
| 87 | + break; |
| 88 | + |
| 89 | + default: |
| 90 | + // If we get here, the trigger value is unknown to this handler |
| 91 | + return false; |
| 92 | + } |
| 93 | + |
| 94 | + // Indicate that we handled the trigger successfully |
| 95 | + return true; |
| 96 | +} |
0 commit comments