refactor network initialisation

pull/783/head
Ömer Şiar Baysal 2 weeks ago committed by GitHub
parent 94fceb78a2
commit 541d17a9f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 49
      src/minidexed.cpp

@ -2299,25 +2299,34 @@ bool CMiniDexed::InitNetwork()
TNetDeviceType NetDeviceType = NetDeviceTypeUnknown; TNetDeviceType NetDeviceType = NetDeviceTypeUnknown;
if (m_pConfig->GetNetworkEnabled () && (strcmp(m_pConfig->GetNetworkType(), "wlan") == 0)) if (m_pConfig->GetNetworkEnabled())
{ {
LOGNOTE("Initializing WLAN"); if (strcmp(m_pConfig->GetNetworkType(), "wlan") == 0)
NetDeviceType = NetDeviceTypeWLAN;
if (m_WLAN.Initialize())
{ {
LOGNOTE("WLAN initialized"); LOGNOTE("Initializing WLAN");
NetDeviceType = NetDeviceTypeWLAN;
if (m_WLAN.Initialize())
{
LOGNOTE("WLAN initialized");
}
else
{
LOGERR("Failed to initialize WLAN, maybe firmware files are missing?");
return false;
}
} }
else else if (strcmp(m_pConfig->GetNetworkType(), "ethernet") == 0)
LOGERR("Failed to initialize WLAN, maybe firmware files are missing?"); {
return false; LOGNOTE("Initializing Ethernet");
} NetDeviceType = NetDeviceTypeEthernet;
else if (m_pConfig->GetNetworkEnabled () && (strcmp(m_pConfig->GetNetworkType(), "ethernet") == 0)) }
{ else
LOGNOTE("Initializing Ethernet"); {
NetDeviceType = NetDeviceTypeEthernet; LOGERR("Network type is not set, please check your minidexed configuration file.");
} NetDeviceType = NetDeviceTypeUnknown;
}
if (NetDeviceType != NetDeviceTypeUnknown)
if (NetDeviceType != NetDeviceTypeUnknown)
{ {
if (m_pConfig->GetNetworkDHCP()) if (m_pConfig->GetNetworkDHCP())
m_pNet = new CNetSubSystem(0, 0, 0, 0, m_pConfig->GetNetworkHostname(), NetDeviceType); m_pNet = new CNetSubSystem(0, 0, 0, 0, m_pConfig->GetNetworkHostname(), NetDeviceType);
@ -2336,16 +2345,18 @@ bool CMiniDexed::InitNetwork()
delete m_pNet; delete m_pNet;
m_pNet = nullptr; m_pNet = nullptr;
} }
m_pNetDevice = CNetDevice::GetNetDevice(NetDeviceType);
// WPASupplicant needs to be started after netdevice available // WPASupplicant needs to be started after netdevice available
if (NetDeviceType == NetDeviceTypeWLAN) if (NetDeviceType == NetDeviceTypeWLAN)
{ {
if (!m_WPASupplicant.Initialize()) { if (!m_WPASupplicant.Initialize())
{
// It seems no way to catch if config is missing unless circle provides it // It seems no way to catch if config is missing unless circle provides it
// or we catch the faults in config file ourselves // or we catch the faults in config file ourselves
LOGERR("Failed to initialize WPASupplicant, maybe wlan config is missing?"); LOGERR("Failed to initialize WPASupplicant, maybe wlan config is missing?");
} }
} }
} }
return m_pNet != nullptr; return m_pNet != nullptr;
}
} }

Loading…
Cancel
Save