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