supla-device
Loading...
Searching...
No Matches
factory_test.h
1/*
2 * Copyright (C) AC SOFTWARE SP. Z O.O
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19#ifndef SRC_SUPLA_DEVICE_FACTORY_TEST_H_
20#define SRC_SUPLA_DEVICE_FACTORY_TEST_H_
21
22#include <supla/action_handler.h>
23#include <supla/element.h>
24
26
27namespace Supla {
28
29enum TestStage {
30 TestStage_None = 0,
31 TestStage_Init = 1,
32 TestStage_RegisteredAndReady = 2,
33 TestStage_WaitForCfgButton = 3,
34 TestStage_Failed = 4,
35 TestStage_Success = 5
36};
37
38enum TestActionType {
39 TestAction_CfgButtonOnPress = 11000,
40 TestAction_DeviceStatusChange = 11101
41};
42
43namespace Device {
44
46 public:
47 using InsecureOptions = uint32_t;
48
49 // Allows legacy factory behavior where the device starts in config mode on
50 // factory defaults. Risk: a shipped or reset device exposes the config AP
51 // and local web UI before the user completes provisioning.
52 static constexpr InsecureOptions AllowStartInCfgMode = 1u << 0;
53
54 // Allows factory configuration to remain without encryption. Risk: device
55 // configuration secrets are stored in a weaker or plaintext form.
56 static constexpr InsecureOptions AllowConfigEncryptionDisabled = 1u << 1;
57
58 // Allows missing or invalid embedded HTTPS certificates. Risk: the local web
59 // UI cannot provide authenticated TLS and may fall back to weaker transport.
60 static constexpr InsecureOptions AllowMissingHttpsCertificates = 1u << 2;
61
62 // Allows security logging to stay disabled. Risk: factory/security audit
63 // evidence is missing, which weakens detection and incident investigation.
64 static constexpr InsecureOptions AllowSecurityLogDisabled = 1u << 3;
65
72 FactoryTest(SuplaDeviceClass *sdc, uint32_t timeoutS);
73 virtual ~FactoryTest();
74
75 void onInit() override;
76 void iterateAlways() override;
77 void handleAction(int event, int action) override;
78
79 virtual int16_t getManufacturerId();
80 virtual void waitForConfigButtonPress();
81 virtual bool checkTestStep();
82
83 void setTestFailed(int reason);
84 void setTestFinished();
85 Supla::TestStage getTestStage() const;
86
87 void dontCheckAutomaticFirmwareUpdate();
88
89 // Set the factory-test security policy once before any FactoryTest instance
90 // is created. Both the short-lived self-test and the persistent test-mode
91 // tester consume the same static options.
92 static void setInsecureOptions(InsecureOptions options);
93 static InsecureOptions getInsecureOptions();
94
95 protected:
96 bool testFailed = false;
97 bool testFinished = false;
98 bool waitForRegisteredAndReady = true;
99 bool testingMachineEnabled = true;
100 SuplaDeviceClass *sdc = nullptr;
101 uint32_t timeoutS = 30;
102 uint32_t initTimestamp = 0;
103 Supla::TestStage testStage = Supla::TestStage_None;
104 int testStep = 0;
105 // fill fail reason for devices that can show it during the test
106 // Use values >= 100 for device specific failures
107 int failReason = 0;
108 bool checkAutomaticFirmwareUpdate = true;
109
110 static InsecureOptions insecureOptions;
111};
112
113} // namespace Device
114} // namespace Supla
115#endif // SRC_SUPLA_DEVICE_FACTORY_TEST_H_
Definition SuplaDevice.h:163
Definition action_handler.h:21
FactoryTest(SuplaDeviceClass *sdc, uint32_t timeoutS)
Construct a new Factory Test object.
Definition factory_test.cpp:44
void iterateAlways() override
Method called on each SuplaDevice iteration.
Definition factory_test.cpp:281
void onInit() override
Third method called on element in SuplaDevice.begin().
Definition factory_test.cpp:63
Base class for all elements of SuplaDevice.
Definition element.h:37