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 SetSetupNeeded();
58 static bool PopSetupNeeded();
59 // returns MAC addres of the main network interface
60 static bool GetMainMacAddr(uint8_t *);
61 // Initialize hostname on all network interfaces with given prefix
62 static void SetHostname(const char *prefix, int macSize);
63 // Returns true when all network interfaces are in timeout
64 static bool IsIpSetupTimeout();
65 static void LoadConfig();
66
67 static void printData(const char *prefix, const void *buf, const int count);
68
69 explicit Network(uint8_t ip[4]);
70 Network();
71 virtual ~Network();
72 virtual void onLoadConfig();
73 virtual void setup() = 0;
74 virtual void disable() = 0;
75 virtual void uninit();
76 virtual void setConfigMode();
77 virtual void setNormalMode();
78 virtual bool getMacAddr(uint8_t *);
79 virtual void setHostname(const char *, int macSize);
80 void generateHostname(const char *prefix, int macSize, char *output);
81 virtual bool isIpSetupTimeout();
82 virtual uint32_t getIP();
83
84 virtual Supla::Client *createClient();
85
86 virtual bool isReady() = 0;
87 virtual bool iterate();
88
89 virtual void fillStateData(TDSC_ChannelState *channelState);
90
91 // WiFi specific part
92 virtual bool isWifiConfigRequired();
93 virtual void setSsid(const char *wifiSsid);
94 virtual void setPassword(const char *wifiPassword);
95
96 // SSL configuration
97 static void setSSLEnabled(bool enabled);
98
99 void clearTimeCounters();
100 void setSuplaDeviceClass(SuplaDeviceClass *);
101
102 void setSetupNeeded();
103 bool popSetupNeeded();
104
105 enum IntfType getIntfType() const;
106 virtual const char* getIntfName() const;
107
108 bool isIntfDisabledInConfig() const;
109
110 protected:
111 static Network *netIntf;
112 static Network *firstNetIntf;
113
114 Network *nextNetIntf = nullptr;
115 SuplaDeviceClass *sdc = nullptr;
116 const char *rootCACert = nullptr;
117 unsigned int rootCACertSize = 0;
118 unsigned char localIp[4];
119 char hostname[32] = {};
120
121 enum IntfType intfType = IntfType::Unknown;
122
123 static enum DeviceMode mode;
124 bool setupNeeded = false;
125 bool useLocalIp = false;
126 bool intfDisabledInConfig = false;
127};
128
129}; // namespace Supla
130
131#endif // SRC_SUPLA_NETWORK_NETWORK_H_
Definition SuplaDevice.h:93
Definition client.h:31
Definition proto.h:2575