/src/connectedhomeip/examples/all-clusters-app/all-clusters-common/src/wifi-diagnostics-stub.cpp
Line | Count | Source |
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/WiFiNetworkDiagnosticsCluster.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 | 0 | { |
39 | 0 | auto delegate = DeviceLayer::GetDiagnosticDataProvider().GetWiFiDiagnosticsDelegate(); |
40 | 0 | if (delegate != nullptr) |
41 | 0 | { |
42 | 0 | uint16_t reasonCode = 3; // Deauthenticated because sending STA is leaving (or has left) IBSS or ESS. |
43 | 0 | delegate->OnDisconnectionDetected(reasonCode); |
44 | 0 | } |
45 | 0 | } |
46 | | |
47 | | /** |
48 | | * @brief Helper function to simulate an Association Failure event |
49 | | */ |
50 | | void SetTestEventTrigger_AssociationFailure() |
51 | 0 | { |
52 | 0 | auto delegate = DeviceLayer::GetDiagnosticDataProvider().GetWiFiDiagnosticsDelegate(); |
53 | 0 | if (delegate != nullptr) |
54 | 0 | { |
55 | 0 | uint8_t associationFailureCause = |
56 | 0 | static_cast<uint8_t>(WiFiNetworkDiagnostics::AssociationFailureCauseEnum::kAuthenticationFailed); |
57 | 0 | uint16_t status = 4; // IEEE 802.11-2020 Status Codes, AP is unable to handle additional associated STAs |
58 | |
|
59 | 0 | delegate->OnAssociationFailureDetected(associationFailureCause, status); |
60 | 0 | } |
61 | 0 | } |
62 | | |
63 | | /** |
64 | | * @brief Helper function to simulate a Connection Status event |
65 | | */ |
66 | | void SetTestEventTrigger_ConnectionStatus() |
67 | 0 | { |
68 | 0 | auto delegate = DeviceLayer::GetDiagnosticDataProvider().GetWiFiDiagnosticsDelegate(); |
69 | 0 | if (delegate != nullptr) |
70 | 0 | { |
71 | 0 | uint8_t connectionStatus = static_cast<uint8_t>(WiFiNetworkDiagnostics::ConnectionStatusEnum::kNotConnected); |
72 | 0 | delegate->OnConnectionStatusChanged(connectionStatus); |
73 | 0 | } |
74 | 0 | } |
75 | | |
76 | | } // anonymous namespace |
77 | | |
78 | | bool HandleWiFiDiagnosticsTestEventTrigger(uint64_t eventTrigger) |
79 | 0 | { |
80 | | // Convert raw trigger to our enum |
81 | 0 | WiFiDiagnosticsTrigger trigger = static_cast<WiFiDiagnosticsTrigger>(eventTrigger); |
82 | |
|
83 | 0 | switch (trigger) |
84 | 0 | { |
85 | 0 | case WiFiDiagnosticsTrigger::kDisconnection: |
86 | 0 | ChipLogProgress(Support, "[WiFiDiagnostics-Test-Event] => Disconnection triggered"); |
87 | 0 | SetTestEventTrigger_Disconnection(); |
88 | 0 | break; |
89 | | |
90 | 0 | case WiFiDiagnosticsTrigger::kAssociationFailure: |
91 | 0 | ChipLogProgress(Support, "[WiFiDiagnostics-Test-Event] => AssociationFailure triggered"); |
92 | 0 | SetTestEventTrigger_AssociationFailure(); |
93 | 0 | break; |
94 | | |
95 | 0 | case WiFiDiagnosticsTrigger::kConnectionStatus: |
96 | 0 | ChipLogProgress(Support, "[WiFiDiagnostics-Test-Event] => ConnectionStatus triggered"); |
97 | 0 | SetTestEventTrigger_ConnectionStatus(); |
98 | 0 | break; |
99 | | |
100 | 0 | default: |
101 | | // If we get here, the trigger value is unknown to this handler |
102 | 0 | return false; |
103 | 0 | } |
104 | | |
105 | | // Indicate that we handled the trigger successfully |
106 | 0 | return true; |
107 | 0 | } |