supla-device
Loading...
Searching...
No Matches
network.h
1// SPDX-FileCopyrightText: AC SOFTWARE SP. Z O.O.
2// SPDX-License-Identifier: GPL-2.0-or-later
3
4#ifndef SRC_SUPLA_NETWORK_NETWORK_H_
5#define SRC_SUPLA_NETWORK_NETWORK_H_
6
7#include <stdint.h>
8
9#include "supla-common/proto.h"
10#include "supla/storage/config.h"
11
13
14namespace Supla {
15
16const char WifiDisableTag[] = "wifi_dis";
17const char EthDisableTag[] = "eth_dis";
18
19class Client;
20
21class Network {
22 public:
23 enum class IntfType {
24 Unknown = 0,
25 Ethernet = 1,
26 WiFi = 2,
27 };
28
29 static Network *Instance();
30 static Network *FirstInstance();
31 static Network *NextInstance(Network *instance);
32 static Network *GetInstanceByIP(uint32_t ip);
33 static int GetNetIntfCount();
34 static void DisconnectProtocols();
35 static void Setup();
36 static void Disable();
37 static void Uninit();
38 static bool IsReady();
39 static bool Iterate();
40 static void SetConfigMode();
41 static void SetNormalMode();
42 static void SetOfflineMode();
43 static void SetTestMode();
44 static void SetSetupNeeded();
45 static bool PopSetupNeeded();
46 // returns MAC addres of the main network interface
47 static bool GetMainMacAddr(uint8_t *);
48 // Initialize hostname on all network interfaces with given prefix
49 static void SetHostname(const char *prefix, int macSize);
50 // Returns true when all network interfaces are in timeout
51 static bool IsIpSetupTimeout();
52 static void LoadConfig();
53
54 static void printData(const char *prefix, const void *buf, const int count);
55
56 explicit Network(uint8_t ip[4]);
57 Network();
58 virtual ~Network();
59 virtual void onLoadConfig();
60 virtual void setup() = 0;
61 virtual void disable() = 0;
62 virtual void uninit();
63 virtual void setConfigMode();
64 virtual void setNormalMode();
65 virtual void setOfflineMode();
66 void setTestMode();
67 virtual bool getMacAddr(uint8_t *);
68 virtual void setHostname(const char *, int macSize);
69 void generateHostname(const char *prefix, int macSize, char *output);
70 virtual bool isIpSetupTimeout();
71 virtual uint32_t getIP();
72 bool hasStaticIpConfig() const;
73 const NetifConfigBlob& getNetifConfig() const;
74
75 virtual Supla::Client *createClient();
76
77 virtual bool isReady() = 0;
78 virtual bool iterate();
79
80 virtual void fillStateData(TDSC_ChannelState *channelState);
81
82 // WiFi specific part
83 virtual bool isWifiConfigRequired();
84 virtual void setSsid(const char *wifiSsid);
85 virtual void setPassword(const char *wifiPassword);
86
87 // SSL configuration
88 static void setSSLEnabled(bool enabled);
89
90 void clearTimeCounters();
91 void setSuplaDeviceClass(SuplaDeviceClass *);
92
93 void setSetupNeeded();
94 bool popSetupNeeded();
95
96 enum IntfType getIntfType() const;
97 virtual const char* getIntfName() const;
98
99 bool isIntfDisabledInConfig() const;
100
101 protected:
102 static Network *netIntf;
103 static Network *firstNetIntf;
104
105 Network *nextNetIntf = nullptr;
106 SuplaDeviceClass *sdc = nullptr;
107 const char *rootCACert = nullptr;
108 unsigned int rootCACertSize = 0;
109 unsigned char localIp[4];
110 char hostname[32] = {};
111
112 enum IntfType intfType = IntfType::Unknown;
113
114 static enum DeviceMode mode;
115 bool setupNeeded = false;
116 bool useLocalIp = false;
117 bool intfDisabledInConfig = false;
118 bool testMode = false;
119 NetifConfigBlob netifConfig = {};
120};
121
122}; // namespace Supla
123
124#endif // SRC_SUPLA_NETWORK_NETWORK_H_
Definition SuplaDevice.h:167
Definition client.h:24
Definition network.h:21
Definition netif_config.h:22
Definition proto.h:2705