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