use of org.eclipse.kura.net.admin.visitor.linux.util.ModemXchangePair in project kura by eclipse.
the class PppConfigReader method getModemConfig.
private static ModemConfig getModemConfig(String ifaceName, UsbDevice usbDevice) throws KuraException {
s_logger.debug("parsePppPeerConfig()");
boolean isGsmGprsUmtsHspa = false;
List<ModemTechnologyType> technologyTypes = null;
if (usbDevice != null) {
SupportedUsbModemInfo usbModemInfo = SupportedUsbModemsInfo.getModem(usbDevice);
if (usbModemInfo != null) {
technologyTypes = usbModemInfo.getTechnologyTypes();
}
} else {
SupportedSerialModemInfo serialModemInfo = SupportedSerialModemsInfo.getModem();
if (serialModemInfo != null) {
technologyTypes = serialModemInfo.getTechnologyTypes();
}
}
if (technologyTypes != null) {
for (ModemTechnologyType technologyType : technologyTypes) {
if (technologyType == ModemTechnologyType.GSM_GPRS || technologyType == ModemTechnologyType.UMTS || technologyType == ModemTechnologyType.HSDPA || technologyType == ModemTechnologyType.HSPA) {
isGsmGprsUmtsHspa = true;
break;
}
}
}
boolean enabled = true;
int unitNum = getUnitNum(ifaceName);
String apn = "";
String pdpType = "UNKNOWN";
String dialString = "";
String username = "";
String password = "";
String model = "";
AuthType authType = AuthType.NONE;
boolean persist = false;
int maxFail = 0;
int idle = 0;
String activeFilter = "";
int lcpEchoInterval = 0;
int lcpEchoFailure = 0;
String peerFilename = getPeerFilename(ifaceName, usbDevice);
File peerFile = new File(peerFilename);
if (!peerFile.exists()) {
persist = true;
maxFail = 5;
idle = 95;
activeFilter = "inbound";
s_logger.warn("getModemConfig() :: PPPD peer file does not exist - {}", peerFilename);
} else {
s_logger.debug("getModemConfig() :: PPPD peer file exists - {}", peerFilename);
// Check if peer file is a symlink. If so, get information from the linked filename.
try {
if (!peerFile.getCanonicalPath().equals(peerFile.getAbsolutePath())) {
Map<String, String> fileInfo = PppUtil.parsePeerFilename(peerFile.getCanonicalFile().getName());
fileInfo.get("technology");
model = fileInfo.get("model");
fileInfo.get("serialNum");
fileInfo.get("modemId");
}
} catch (IOException e) {
s_logger.error("Error checking for symlink", e);
}
Properties props = new Properties();
FileInputStream fis = null;
try {
fis = new FileInputStream(peerFilename);
props.load(fis);
} catch (Exception e) {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "Error getting modem config", e);
} finally {
if (null != fis) {
try {
fis.close();
} catch (IOException e) {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "Error getting modem config", e);
}
}
}
s_logger.debug("peer properties: {}", props);
if (props.getProperty("unit") != null) {
unitNum = Integer.parseInt(props.getProperty("unit"));
}
if (props.getProperty("user") != null) {
username = removeQuotes(props.getProperty("user"));
}
if (props.getProperty("persist") != null) {
persist = true;
}
if (props.getProperty("maxfail") != null) {
maxFail = Integer.parseInt(props.getProperty("maxfail"));
}
if (props.getProperty("idle") != null) {
idle = Integer.parseInt(props.getProperty("idle"));
}
if (props.getProperty("active-filter") != null) {
activeFilter = removeQuotes(props.getProperty("active-filter"));
}
if (props.getProperty("lcp-echo-interval") != null) {
lcpEchoInterval = Integer.parseInt(props.getProperty("lcp-echo-interval"));
}
if (props.getProperty("lcp-echo-failure") != null) {
lcpEchoFailure = Integer.parseInt(props.getProperty("lcp-echo-failure"));
}
String chatFilename = "";
String connectProperty = removeQuotes(props.getProperty("connect"));
String[] args = connectProperty.split("\\s+");
for (int i = 0; i < args.length; i++) {
if (args[i].equals("-f") && args.length > i + 1) {
chatFilename = args[i + 1];
break;
}
}
// String disconnectFilename = "";
// String disconnectProperty = removeQuotes(props.getProperty("disconnect"));
// args = disconnectProperty.split("\\s+");
// for(int i=0; i<args.length; i++) {
// if(args[i].equals("-f") && args.length > i+1) {
// disconnectFilename = args[i+1];
// break;
// }
// }
// Parse the connect script
ModemXchangeScript connectScript = null;
try {
connectScript = ModemXchangeScript.parseFile(chatFilename);
} catch (Exception e) {
throw new KuraException(KuraErrorCode.INTERNAL_ERROR, "Error parsing " + chatFilename, e);
}
if (connectScript != null) {
ModemXchangePair modemXchangePair = connectScript.getFirstModemXchangePair();
ModemXchangePair prevXchangePair = null;
String expectedStr, sendStr;
while (modemXchangePair != null) {
expectedStr = modemXchangePair.getExpectString();
sendStr = removeQuotes(modemXchangePair.getSendString());
if (expectedStr.equals("OK")) {
// apn
if (sendStr.contains(",")) {
String[] sendArgs = sendStr.split(",");
if (sendArgs.length == 3 && isGsmGprsUmtsHspa) {
pdpType = removeQuotes(sendArgs[1]);
apn = removeQuotes(sendArgs[2]);
}
}
// } else if(expectedStr.equals("\"\"")) {
} else if (expectedStr.equals("CONNECT")) {
// dial string
if (prevXchangePair != null) {
dialString = removeQuotes(prevXchangePair.getSendString());
}
}
prevXchangePair = modemXchangePair;
modemXchangePair = connectScript.getNextModemXchangePair();
}
}
s_logger.debug("* Enabled: {}", enabled);
s_logger.debug("* CHAT file: {}", chatFilename);
s_logger.debug("* UnitNum: {}", unitNum);
s_logger.debug("* dial string: {}", dialString);
s_logger.debug("* persist: {}", persist);
s_logger.debug("* maxfail: {}", maxFail);
s_logger.debug("* idle: {}", idle);
s_logger.debug("* active-filter: {}", activeFilter);
s_logger.debug("* LCP Echo Interval: {}", lcpEchoInterval);
s_logger.debug("* LCP Echo Failure: {}", lcpEchoFailure);
// Get the auth type and credentials
// pppd will use CHAP if available, else PAP
password = "";
if (isGsmGprsUmtsHspa) {
String chapSecret = ChapLinux.getInstance().getSecret(model, username, "*", "*");
String papSecret = PapLinux.getInstance().getSecret(model, username, "*", "*");
if (chapSecret != null && papSecret != null && chapSecret.equals(papSecret)) {
authType = AuthType.AUTO;
password = chapSecret;
} else if (chapSecret != null) {
authType = AuthType.CHAP;
password = chapSecret;
} else if (papSecret != null) {
authType = AuthType.PAP;
password = papSecret;
}
s_logger.debug("* APN: {}", apn);
s_logger.debug("* auth: {}", authType);
s_logger.debug("* username: {}", username);
s_logger.debug("* password: {}", password);
}
}
boolean gpsEnabled = false;
StringBuilder key = new StringBuilder().append("net.interface.").append(ifaceName).append(".config.gpsEnabled");
String statusString = KuranetConfig.getProperty(key.toString());
if (statusString != null && !statusString.isEmpty()) {
gpsEnabled = Boolean.parseBoolean(statusString);
}
int resetTout = 5;
key = new StringBuilder().append("net.interface.").append(ifaceName).append(".config.resetTimeout");
statusString = KuranetConfig.getProperty(key.toString());
if (statusString != null && !statusString.isEmpty()) {
resetTout = Integer.parseInt(statusString);
}
// Populate the modem config
ModemConfig modemConfig = new ModemConfig();
modemConfig.setPppNumber(unitNum);
modemConfig.setPersist(persist);
modemConfig.setMaxFail(maxFail);
modemConfig.setIdle(idle);
modemConfig.setActiveFilter(activeFilter);
modemConfig.setLcpEchoInterval(lcpEchoInterval);
modemConfig.setLcpEchoFailure(lcpEchoFailure);
// TODO - from self configuring properties
modemConfig.setEnabled(enabled);
// FIXME
modemConfig.setDataCompression(0);
modemConfig.setDialString(dialString);
// FIXME
modemConfig.setHeaderCompression(0);
modemConfig.setGpsEnabled(gpsEnabled);
modemConfig.setResetTimeout(resetTout);
if (isGsmGprsUmtsHspa) {
modemConfig.setApn(apn);
modemConfig.setAuthType(authType);
modemConfig.setPassword(password);
modemConfig.setPdpType(PdpType.valueOf(pdpType.toUpperCase()));
modemConfig.setUsername(username);
}
return modemConfig;
}
use of org.eclipse.kura.net.admin.visitor.linux.util.ModemXchangePair in project kura by eclipse.
the class SierraMc87xxConfigGenerator method getDisconnectScript.
@Override
public ModemXchangeScript getDisconnectScript(ModemConfig modemConfig) {
ModemXchangeScript modemXchange = new ModemXchangeScript();
modemXchange.addmodemXchangePair(new ModemXchangePair("\"BUSY\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"VOICE\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"NO CARRIER\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"NO DIALTONE\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"NO DIAL TONE\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("BREAK", "\"\""));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"+++ATH\"", "\"\""));
return modemXchange;
}
use of org.eclipse.kura.net.admin.visitor.linux.util.ModemXchangePair in project kura by eclipse.
the class SierraMc87xxConfigGenerator method getConnectScript.
@Override
public ModemXchangeScript getConnectScript(ModemConfig modemConfig) {
int pdpPid = 1;
String apn = "";
String dialString = "";
if (modemConfig != null) {
apn = modemConfig.getApn();
dialString = modemConfig.getDialString();
}
ModemXchangeScript modemXchange = new ModemXchangeScript();
modemXchange.addmodemXchangePair(new ModemXchangePair("\"BUSY\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"VOICE\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"NO CARRIER\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"NO DIALTONE\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"NO DIAL TONE\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"ERROR\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"+++ath\"", "\"\""));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"AT\"", "OK"));
modemXchange.addmodemXchangePair(new ModemXchangePair(formPDPcontext(pdpPid, PdpType.IP, apn), "OK"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"\\d\\d\\d\"", "OK"));
modemXchange.addmodemXchangePair(new ModemXchangePair(formDialString(dialString), "\"\""));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"\\c\"", "CONNECT"));
return modemXchange;
}
use of org.eclipse.kura.net.admin.visitor.linux.util.ModemXchangePair in project kura by eclipse.
the class TelitHe910ConfigGenerator method getConnectScript.
@Override
public ModemXchangeScript getConnectScript(ModemConfig modemConfig) {
int pdpPid = 1;
String apn = "";
String dialString = "";
if (modemConfig != null) {
apn = modemConfig.getApn();
dialString = modemConfig.getDialString();
}
ModemXchangeScript modemXchange = new ModemXchangeScript();
modemXchange.addmodemXchangePair(new ModemXchangePair("\"BUSY\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"VOICE\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"NO CARRIER\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"NO DIALTONE\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"NO DIAL TONE\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"ERROR\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"+++ath\"", "\"\""));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"AT\"", "OK"));
modemXchange.addmodemXchangePair(new ModemXchangePair(formPDPcontext(pdpPid, PdpType.IP, apn), "OK"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"\\d\\d\\d\"", "OK"));
modemXchange.addmodemXchangePair(new ModemXchangePair(formDialString(dialString), "\"\""));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"\\c\"", "CONNECT"));
return modemXchange;
}
use of org.eclipse.kura.net.admin.visitor.linux.util.ModemXchangePair in project kura by eclipse.
the class TelitHe910ConfigGenerator method getDisconnectScript.
@Override
public ModemXchangeScript getDisconnectScript(ModemConfig modemConfig) {
ModemXchangeScript modemXchange = new ModemXchangeScript();
modemXchange.addmodemXchangePair(new ModemXchangePair("\"BUSY\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"VOICE\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"NO CARRIER\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"NO DIALTONE\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"NO DIAL TONE\"", "ABORT"));
modemXchange.addmodemXchangePair(new ModemXchangePair("BREAK", "\"\""));
modemXchange.addmodemXchangePair(new ModemXchangePair("\"+++ATH\"", "\"\""));
return modemXchange;
}
Aggregations