Merge branch 'network' into network

pull/783/head
probonopd 2 months ago committed by GitHub
commit 1d341c62b2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 87
      src/minidexed.cpp

@ -2296,42 +2296,68 @@ void CMiniDexed::UpdateNetwork()
bool CMiniDexed::InitNetwork() bool CMiniDexed::InitNetwork()
{ {
LOGNOTE("InitNetwork: Starting network initialization");
assert(m_pNet == nullptr); assert(m_pNet == nullptr);
TNetDeviceType NetDeviceType = NetDeviceTypeUnknown; TNetDeviceType NetDeviceType = NetDeviceTypeUnknown;
if (m_pConfig->GetNetworkEnabled()) LOGNOTE("InitNetwork: NetworkEnabled=%d, NetworkType=%s", m_pConfig->GetNetworkEnabled(), m_pConfig->GetNetworkType());
{
if (strcmp(m_pConfig->GetNetworkType(), "wlan") == 0) if (m_pConfig->GetNetworkEnabled () && (strcmp(m_pConfig->GetNetworkType(), "wifi") == 0))
{ {
LOGNOTE("Initializing WLAN"); LOGNOTE("InitNetwork: Initializing WLAN");
NetDeviceType = NetDeviceTypeWLAN;
if (m_WLAN.Initialize()) if (m_WLAN.Initialize())
{ {
LOGNOTE("WLAN initialized"); LOGNOTE("InitNetwork: WLAN initialized");
} }
else else
{ {
LOGERR("Failed to initialize WLAN, maybe firmware files are missing?"); LOGERR("InitNetwork: Failed to initialize WLAN");
return false;
} }
if (m_WPASupplicant.Initialize())
{
LOGNOTE("InitNetwork: WPASupplicant initialized");
} }
else if (strcmp(m_pConfig->GetNetworkType(), "ethernet") == 0) else
{ {
LOGNOTE("Initializing Ethernet"); LOGERR("InitNetwork: Failed to initialize WPASupplicant");
NetDeviceType = NetDeviceTypeEthernet; }
if (m_WLAN.Initialize() && m_WPASupplicant.Initialize())
{
LOGNOTE("InitNetwork: WLAN and WPASupplicant initialized");
NetDeviceType = NetDeviceTypeWLAN;
} }
else else
{ {
LOGERR("Network type is not set, please check your minidexed configuration file."); LOGERR("InitNetwork: Failed to initialize WLAN or WPASupplicant");
NetDeviceType = NetDeviceTypeUnknown; }
}
else if (m_pConfig->GetNetworkEnabled () && (strcmp(m_pConfig->GetNetworkType(), "ethernet") == 0))
{
LOGNOTE("InitNetwork: Initializing Ethernet");
NetDeviceType = NetDeviceTypeEthernet;
} }
if (NetDeviceType != NetDeviceTypeUnknown) if (NetDeviceType != NetDeviceTypeUnknown)
{ {
LOGNOTE("InitNetwork: NetDeviceType set, proceeding to create CNetSubSystem");
if (m_pConfig->GetNetworkDHCP()) if (m_pConfig->GetNetworkDHCP())
{
LOGNOTE("InitNetwork: Using DHCP");
m_pNet = new CNetSubSystem(0, 0, 0, 0, m_pConfig->GetNetworkHostname(), NetDeviceType); m_pNet = new CNetSubSystem(0, 0, 0, 0, m_pConfig->GetNetworkHostname(), NetDeviceType);
}
else else
{
LOGNOTE("InitNetwork: Using static IP");
LOGNOTE("InitNetwork: IP=%u, Mask=%u, GW=%u, DNS=%u, Hostname=%s",
(unsigned)m_pConfig->GetNetworkIPAddress().Get(),
(unsigned)m_pConfig->GetNetworkSubnetMask().Get(),
(unsigned)m_pConfig->GetNetworkDefaultGateway().Get(),
(unsigned)m_pConfig->GetNetworkDNSServer().Get(),
m_pConfig->GetNetworkHostname());
m_pNet = new CNetSubSystem( m_pNet = new CNetSubSystem(
m_pConfig->GetNetworkIPAddress().Get(), m_pConfig->GetNetworkIPAddress().Get(),
m_pConfig->GetNetworkSubnetMask().Get(), m_pConfig->GetNetworkSubnetMask().Get(),
@ -2340,33 +2366,38 @@ bool CMiniDexed::InitNetwork()
m_pConfig->GetNetworkHostname(), m_pConfig->GetNetworkHostname(),
NetDeviceType NetDeviceType
); );
if (!m_pNet->Initialize(false)) }
if (!m_pNet->Initialize())
{ {
LOGERR("Failed to initialize network subsystem"); LOGERR("InitNetwork: Failed to initialize network subsystem");
delete m_pNet; delete m_pNet;
m_pNet = nullptr; m_pNet = nullptr;
} }
else
// WPASupplicant needs to be started after netdevice available
if (NetDeviceType == NetDeviceTypeWLAN)
{ {
m_pNetDevice = CNetDevice::GetNetDevice(NetDeviceType); LOGNOTE("InitNetwork: Network subsystem initialized");
} }
// Syslog configuration m_pNetDevice = CNetDevice::GetNetDevice(NetDeviceType);
LOGNOTE("InitNetwork: Got NetDevice, type=%d", (int)NetDeviceType);
// syslog configuration
CIPAddress ServerIP = m_pConfig->GetNetworkSyslogServerIPAddress(); CIPAddress ServerIP = m_pConfig->GetNetworkSyslogServerIPAddress();
if (ServerIP.IsSet () && !ServerIP.IsNull ()) if (ServerIP.IsSet () && !ServerIP.IsNull ())
{ {
if (!m_WPASupplicant.Initialize()) static const u16 usServerPort = 8514; // standard port is 514
{ CString IPString;
// It seems no way to catch if config is missing unless circle provides it ServerIP.Format (&IPString);
// or we catch the faults in config file ourselves LOGNOTE ("InitNetwork: Sending log messages to syslog server %s:%u",
LOGERR("Failed to initialize WPASupplicant, maybe wlan config is missing?"); (const char *) IPString, (unsigned) usServerPort);
new CSysLogDaemon (m_pNet, ServerIP, usServerPort);
} }
} }
m_pNetDevice = CNetDevice::GetNetDevice(NetDeviceType); else
{
LOGERR("InitNetwork: NetDeviceType is unknown, network not initialized");
} }
LOGNOTE("InitNetwork: Done, m_pNet %s", m_pNet ? "set" : "nullptr");
return m_pNet != nullptr; return m_pNet != nullptr;
} }
}

Loading…
Cancel
Save