use of org.eclipse.kura.web.shared.model.GwtModemPdpType in project kura by eclipse.
the class GwtNetworkServiceImpl method updateNetInterfaceConfigurations.
@Override
public void updateNetInterfaceConfigurations(GwtXSRFToken xsrfToken, GwtNetInterfaceConfig config) throws GwtKuraException {
checkXSRFToken(xsrfToken);
NetworkAdminService nas = ServiceLocator.getInstance().getService(NetworkAdminService.class);
s_logger.debug("config.getStatus(): {}", GwtSafeHtmlUtils.htmlEscape(config.getStatus()));
String status = config.getStatus();
boolean autoConnect = true;
if (GwtNetIfStatus.netIPv4StatusDisabled.name().equals(status)) {
autoConnect = false;
}
try {
// Interface status
NetInterfaceStatus netInterfaceStatus = null;
if (config.getStatus().equals(GwtNetIfStatus.netIPv4StatusDisabled.name())) {
netInterfaceStatus = NetInterfaceStatus.netIPv4StatusDisabled;
} else if (config.getStatus().equals(GwtNetIfStatus.netIPv4StatusEnabledLAN.name())) {
netInterfaceStatus = NetInterfaceStatus.netIPv4StatusEnabledLAN;
} else if (config.getStatus().equals(GwtNetIfStatus.netIPv4StatusEnabledWAN.name())) {
netInterfaceStatus = NetInterfaceStatus.netIPv4StatusEnabledWAN;
}
// Set up configs
List<NetConfig> netConfigs = new ArrayList<NetConfig>();
// Initialize NetConfigIP4 object
NetConfigIP4 netConfig4 = new NetConfigIP4(netInterfaceStatus, autoConnect);
// build the appropriate NetConfig objects for ethernet type
if (config.getHwTypeEnum() == GwtNetIfType.ETHERNET || config.getHwTypeEnum() == GwtNetIfType.WIFI || config.getHwTypeEnum() == GwtNetIfType.MODEM) {
s_logger.debug("config.getConfigMode(): {}", config.getConfigMode());
String regexp = "[\\s,;\\n\\t]+";
if (GwtNetIfConfigMode.netIPv4ConfigModeDHCP.name().equals(config.getConfigMode())) {
s_logger.debug("mode is DHCP");
netConfig4.setDhcp(true);
} else {
s_logger.debug("mode is STATIC");
netConfig4.setDhcp(false);
if (config.getIpAddress() != null && !config.getIpAddress().isEmpty()) {
s_logger.debug("setting address: {}", config.getIpAddress());
netConfig4.setAddress((IP4Address) IPAddress.parseHostAddress(config.getIpAddress()));
}
if (config.getSubnetMask() != null && !config.getSubnetMask().isEmpty()) {
s_logger.debug("setting subnet mask: {}", config.getSubnetMask());
netConfig4.setSubnetMask((IP4Address) IPAddress.parseHostAddress(config.getSubnetMask()));
}
if (config.getGateway() != null && !config.getGateway().isEmpty()) {
s_logger.debug("setting gateway: {}", config.getGateway());
netConfig4.setGateway((IP4Address) IPAddress.parseHostAddress(config.getGateway()));
}
String[] winServersString = config.getSearchDomains().split(regexp);
if (winServersString != null && winServersString.length > 0) {
IP4Address winServer;
List<IP4Address> dnsServers = new ArrayList<IP4Address>();
for (String winsEntry : winServersString) {
if (!winsEntry.trim().isEmpty()) {
s_logger.debug("setting WINs: {}", winsEntry);
winServer = (IP4Address) IPAddress.parseHostAddress(winsEntry);
dnsServers.add(winServer);
}
}
netConfig4.setDnsServers(dnsServers);
}
}
String[] dnsServersString = config.getDnsServers().split(regexp);
if (dnsServersString != null && dnsServersString.length > 0) {
IP4Address dnsServer;
List<IP4Address> dnsServers = new ArrayList<IP4Address>();
for (String dnsEntry : dnsServersString) {
if (!dnsEntry.trim().isEmpty()) {
s_logger.debug("setting DNS: {}", dnsEntry);
dnsServer = (IP4Address) IPAddress.parseHostAddress(dnsEntry);
dnsServers.add(dnsServer);
}
}
netConfig4.setDnsServers(dnsServers);
}
netConfigs.add(netConfig4);
// Set up DHCP and NAT
if (!GwtNetIfConfigMode.netIPv4ConfigModeDHCP.name().equals(config.getConfigMode())) {
// <--
List<NetConfig> dhcpConfigs = getDhcpConfig(config);
if (dhcpConfigs != null) {
s_logger.debug("Adding dhcp and/or nat configs to interface update config");
netConfigs.addAll(dhcpConfigs);
}
}
if (config.getHwTypeEnum() == GwtNetIfType.ETHERNET) {
nas.updateEthernetInterfaceConfig(GwtSafeHtmlUtils.htmlEscape(config.getName()), autoConnect, config.getHwMTU(), netConfigs);
}
}
if (config.getHwTypeEnum() == GwtNetIfType.WIFI) {
if (config instanceof GwtWifiNetInterfaceConfig) {
GwtWifiConfig gwtWifiConfig = ((GwtWifiNetInterfaceConfig) config).getActiveWifiConfig();
if (gwtWifiConfig != null) {
WifiConfig wifiConfig = getWifiConfig(gwtWifiConfig);
String passKey = new String(wifiConfig.getPasskey().getPassword());
if (passKey != null && passKey.equals(PLACEHOLDER)) {
List<GwtNetInterfaceConfig> result = privateFindNetInterfaceConfigurations();
for (GwtNetInterfaceConfig netConfig : result) {
if (netConfig instanceof GwtWifiNetInterfaceConfig && config.getName().equals(((GwtWifiNetInterfaceConfig) netConfig).getName())) {
GwtWifiNetInterfaceConfig oldWifiConfig = (GwtWifiNetInterfaceConfig) netConfig;
GwtWifiConfig oldGwtWifiConfig;
if (gwtWifiConfig.getWirelessMode().equals(GwtWifiWirelessMode.netWifiWirelessModeAccessPoint.name())) {
oldGwtWifiConfig = oldWifiConfig.getAccessPointWifiConfig();
} else {
oldGwtWifiConfig = oldWifiConfig.getStationWifiConfig();
}
if (oldGwtWifiConfig != null) {
wifiConfig.setPasskey(oldGwtWifiConfig.getPassword());
}
}
}
}
netConfigs.add(wifiConfig);
nas.updateWifiInterfaceConfig(GwtSafeHtmlUtils.htmlEscape(config.getName()), autoConnect, null, netConfigs);
}
}
} else if (config.getHwTypeEnum() == GwtNetIfType.MODEM) {
if (config instanceof GwtModemInterfaceConfig) {
GwtModemInterfaceConfig gwtModemConfig = (GwtModemInterfaceConfig) config;
ModemConfig modemConfig = new ModemConfig();
String serialNum = gwtModemConfig.getHwSerial();
String modemId = gwtModemConfig.getModemId();
int pppNum = gwtModemConfig.getPppNum();
// modem enabled/disabled
if (netInterfaceStatus.equals(NetInterfaceStatus.netIPv4StatusEnabledWAN)) {
modemConfig.setEnabled(true);
} else {
modemConfig.setEnabled(false);
}
modemConfig.setApn(gwtModemConfig.getApn());
modemConfig.setPppNumber(gwtModemConfig.getPppNum());
modemConfig.setDataCompression(gwtModemConfig.getDataCompression());
modemConfig.setDialString(gwtModemConfig.getDialString());
modemConfig.setHeaderCompression(gwtModemConfig.getHeaderCompression());
String passKey = new String(gwtModemConfig.getPassword());
if (passKey != null && passKey.equals(PLACEHOLDER)) {
List<GwtNetInterfaceConfig> result = privateFindNetInterfaceConfigurations();
for (GwtNetInterfaceConfig netConfig : result) {
if (netConfig instanceof GwtModemInterfaceConfig) {
GwtModemInterfaceConfig oldModemConfig = (GwtModemInterfaceConfig) netConfig;
if (gwtModemConfig.getName().equals(oldModemConfig.getName())) {
modemConfig.setPassword(oldModemConfig.getPassword());
}
}
}
} else if (passKey != null) {
modemConfig.setPassword(passKey);
}
modemConfig.setUsername(gwtModemConfig.getUsername());
modemConfig.setResetTimeout(gwtModemConfig.getResetTimeout());
modemConfig.setPersist(gwtModemConfig.isPersist());
modemConfig.setMaxFail(gwtModemConfig.getMaxFail());
modemConfig.setIdle(gwtModemConfig.getIdle());
modemConfig.setActiveFilter(gwtModemConfig.getActiveFilter());
modemConfig.setLcpEchoInterval(gwtModemConfig.getLcpEchoInterval());
modemConfig.setLcpEchoFailure(gwtModemConfig.getLcpEchoFailure());
modemConfig.setGpsEnabled(gwtModemConfig.isGpsEnabled());
GwtModemAuthType authType = gwtModemConfig.getAuthType();
if (authType != null) {
if (authType.equals(GwtModemAuthType.netModemAuthNONE)) {
modemConfig.setAuthType(ModemConfig.AuthType.NONE);
} else if (authType.equals(GwtModemAuthType.netModemAuthAUTO)) {
modemConfig.setAuthType(ModemConfig.AuthType.AUTO);
} else if (authType.equals(GwtModemAuthType.netModemAuthCHAP)) {
modemConfig.setAuthType(ModemConfig.AuthType.CHAP);
} else if (authType.equals(GwtModemAuthType.netModemAuthPAP)) {
modemConfig.setAuthType(ModemConfig.AuthType.PAP);
}
}
GwtModemPdpType pdpType = gwtModemConfig.getPdpType();
if (pdpType != null) {
if (pdpType.equals(GwtModemPdpType.netModemPdpIP)) {
modemConfig.setPdpType(ModemConfig.PdpType.IP);
} else if (pdpType.equals(GwtModemPdpType.netModemPdpIPv6)) {
modemConfig.setPdpType(ModemConfig.PdpType.IPv6);
} else if (pdpType.equals(GwtModemPdpType.netModemPdpPPP)) {
modemConfig.setPdpType(ModemConfig.PdpType.PPP);
} else {
modemConfig.setPdpType(ModemConfig.PdpType.UNKNOWN);
}
}
netConfigs.add(modemConfig);
nas.updateModemInterfaceConfig(config.getName(), serialNum, modemId, pppNum, autoConnect, -1, netConfigs);
}
} else {
// TODO - more types
}
} catch (Exception e) {
s_logger.warn("Failed", e);
throw new GwtKuraException(GwtKuraErrorCode.INTERNAL_ERROR, e);
}
}
Aggregations