supla-device
Loading...
Searching...
No Matches
factory_test.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_DEVICE_FACTORY_TEST_H_
5#define SRC_SUPLA_DEVICE_FACTORY_TEST_H_
6
7#include <supla/action_handler.h>
8#include <supla/element.h>
9
11
12namespace Supla {
13
14enum TestStage {
15 TestStage_None = 0,
16 TestStage_Init = 1,
17 TestStage_RegisteredAndReady = 2,
18 TestStage_WaitForCfgButton = 3,
19 TestStage_Failed = 4,
20 TestStage_Success = 5
21};
22
23enum TestActionType {
24 TestAction_CfgButtonOnPress = 11000,
25 TestAction_DeviceStatusChange = 11101
26};
27
28namespace Device {
29
31 public:
32 using InsecureOptions = uint32_t;
33
34 // Allows legacy factory behavior where the device starts in config mode on
35 // factory defaults. Risk: a shipped or reset device exposes the config AP
36 // and local web UI before the user completes provisioning.
37 static constexpr InsecureOptions AllowStartInCfgMode = 1u << 0;
38
39 // Allows factory configuration to remain without encryption. Risk: device
40 // configuration secrets are stored in a weaker or plaintext form.
41 static constexpr InsecureOptions AllowConfigEncryptionDisabled = 1u << 1;
42
43 // Allows missing or invalid embedded HTTPS certificates. Risk: the local web
44 // UI cannot provide authenticated TLS and may fall back to weaker transport.
45 static constexpr InsecureOptions AllowMissingHttpsCertificates = 1u << 2;
46
47 // Allows security logging to stay disabled. Risk: factory/security audit
48 // evidence is missing, which weakens detection and incident investigation.
49 static constexpr InsecureOptions AllowSecurityLogDisabled = 1u << 3;
50
57 FactoryTest(SuplaDeviceClass *sdc, uint32_t timeoutS);
58 virtual ~FactoryTest();
59
60 void onInit() override;
61 void iterateAlways() override;
62 void handleAction(int event, int action) override;
63
64 virtual int16_t getManufacturerId();
65 virtual void waitForConfigButtonPress();
66 virtual bool checkTestStep();
67
68 void setTestFailed(int reason);
69 void setTestFinished();
70 Supla::TestStage getTestStage() const;
71 bool hasFailed() const;
72 int getFailReason() const;
73
74 void dontCheckAutomaticFirmwareUpdate();
75
76 // Set the factory-test security policy once before any FactoryTest instance
77 // is created. Both the short-lived self-test and the persistent test-mode
78 // tester consume the same static options.
79 static void setInsecureOptions(InsecureOptions options);
80 static InsecureOptions getInsecureOptions();
81
82 protected:
83 bool testFailed = false;
84 bool testFinished = false;
85 bool waitForRegisteredAndReady = true;
86 bool testingMachineEnabled = true;
87 SuplaDeviceClass *sdc = nullptr;
88 uint32_t timeoutS = 30;
89 uint32_t initTimestamp = 0;
90 Supla::TestStage testStage = Supla::TestStage_None;
91 int testStep = 0;
92 // fill fail reason for devices that can show it during the test
93 // Use values >= 100 for device specific failures
94 int failReason = 0;
95 bool checkAutomaticFirmwareUpdate = true;
96
97 static InsecureOptions insecureOptions;
98};
99
100} // namespace Device
101} // namespace Supla
102#endif // SRC_SUPLA_DEVICE_FACTORY_TEST_H_
Definition SuplaDevice.h:167
Definition action_handler.h:8
Definition factory_test.h:30
FactoryTest(SuplaDeviceClass *sdc, uint32_t timeoutS)
Construct a new Factory Test object.
Definition factory_test.cpp:29
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition factory_test.cpp:266
void onInit() override
Third method called on element in SuplaDevice.begin()
Definition factory_test.cpp:48
Base class for all elements of SuplaDevice.
Definition element.h:27