private void processSetSystemPropertiesCmd(DataInputStream params, IOTACommandHelper helper) throws IOException { int dataSize = helper.getDataInputStream().readInt(); ByteArrayOutputStream baos = new ByteArrayOutputStream(dataSize); helper.receiveFile(dataSize, baos); Properties newPersistentProperties = new Properties(); newPersistentProperties.load(new ByteArrayInputStream(baos.toByteArray())); Properties oldPersistentProperties = spot.getPersistentProperties(); // store new properties in flash spot.storeProperties(newPersistentProperties); // remove deleted properties from current isolate Enumeration oldKeys = oldPersistentProperties.keys(); while (oldKeys.hasMoreElements()) { String oldKey = (String) oldKeys.nextElement(); if (!newPersistentProperties.containsKey(oldKey)) { VM.setProperty(oldKey, null); } } // store new and modified properties in current isolate Enumeration newKeys = newPersistentProperties.keys(); while (newKeys.hasMoreElements()) { String newKey = (String) newKeys.nextElement(); VM.setProperty(newKey, newPersistentProperties.getProperty(newKey)); } helper.sendPrompt(); }
private void processGetSystemPropertiesCmd(IOTACommandHelper helper) throws IOException { Properties p = spot.getPersistentProperties(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); p.store(baos, "System properties on SPOT"); helper.sendData(baos.toByteArray(), 0, baos.size()); helper.sendPrompt(); }
private void processFlashLibCmd(DataInputStream params, IOTACommandHelper helper) throws IOException { helper.replaceSuiteFile(params, ConfigPage.LIBRARY_URI, ConfigPage.LIBRARY_VIRTUAL_ADDRESS); MIDletSuiteDescriptor[] suites = MIDletSuiteDescriptor.getAllInstances(); for (int i = 0; i < suites.length; i++) { FlashFile suiteFile = new FlashFile(suites[i].getURI()); suiteFile.setObsolete(true); suiteFile.commit(); } helper.sendPrompt(); }
private void processGetFileInfoCmd(DataInputStream params, IOTACommandHelper helper) throws IOException { String filename = params.readUTF(); FlashFile flashFile = new FlashFile(filename); if (flashFile.exists()) { helper.getDataOutputStream().writeBoolean(true); byte[] fileData = new OTAFlashFileInfo(flashFile).toByteArray(); helper.sendData(fileData, 0, fileData.length); } else { helper.getDataOutputStream().writeBoolean(false); } helper.sendPrompt(); }
private void processGetConfigPageCmd(IOTACommandHelper helper, boolean len) throws IOException { ConfigPage configPage; configPage = spot.getConfigPage(); byte[] data = configPage.asByteArray(); if (len) { int i = data.length - 1; while (i > 0 && data[i] == 0) i--; i = i / 4; helper.getDataOutputStream().writeByte(i & 0xff); helper.getDataOutputStream().write(data, 0, (i + 1) * 4); } else { helper.getDataOutputStream().write(data); } helper.sendPrompt(); }
private void processGetFileListCmd(DataInputStream params, IOTACommandHelper helper) throws IOException { IFAT fat = FlashFile.getFAT(); IFlashFileInfo[] fileInfos = fat.getFileInfos(); DataOutputStream dos = helper.getDataOutputStream(); dos.writeInt(fileInfos.length); for (int i = 0; i < fileInfos.length; i++) { dos.writeUTF(fileInfos[i].getName()); } int[] freeSectorIndices = fat.getFreeSectorIndices(); dos.writeInt(freeSectorIndices.length); for (int i = 0; i < freeSectorIndices.length; i++) { dos.writeInt(freeSectorIndices[i]); } helper.sendPrompt(); }
private void processSetPublicKeyCmd(DataInputStream params, IOTACommandHelper helper) throws IOException { byte[] newKey = new byte[params.readShort()]; params.readFully(newKey); setPublicKey(newKey); helper.sendPrompt(); }
private void processSetStartupCmd(DataInputStream params, IOTACommandHelper helper) throws IOException { ConfigPage configPage = spot.getConfigPage(); configPage.setStartup(params.readUTF(), params.readUTF(), params.readUTF()); spot.flashConfigPage(configPage); helper.sendPrompt(); }
private void processBlinkCmd(DataInputStream params, IOTACommandHelper helper) throws IOException { int duration = params.readInt(); IService s[] = ServiceRegistry.getInstance().lookupAll(ISpotBlink.class); for (int i = 0; i < s.length; i++) { ((ISpotBlink) s[i]).blink(duration); } helper.sendPrompt(); }
private void processUndeployCmd(DataInputStream params, IOTACommandHelper helper) throws IOException { String suiteUri = params.readUTF(); FlashFile suiteFile = new FlashFile(suiteUri); if (suiteFile.exists()) { if (helper.isSuiteInUse(suiteUri)) { if (suiteUri.equals(Isolate.currentIsolate().getParentSuiteSourceURI())) { helper.makeObsolete(suiteUri); } else { helper.sendErrorDetails("Attempt to undeploy suite that is in use"); return; } } else { VM.unregisterSuite(suiteUri); suiteFile.delete(); } } else { helper.sendErrorDetails("Attempt to undeploy unknown suite: " + suiteUri); return; } helper.sendPrompt(); }
private void processSetTimeCmd(DataInputStream params, IOTACommandHelper helper) throws IOException { long newTime = params.readLong(); powerController.setTime(newTime); helper.sendPrompt(); }
private void processAttentionCmd(IOTACommandHelper helper) { if (helper.isRemote()) { Utils.log("Redirecting output to " + hostAddress.asDottedHex()); remotePrintManager.redirectOutputStreams(hostAddress.asDottedHex()); } }
private void processResyncCmd(IOTACommandHelper helper) throws IOException { sendUTF(helper.getDataOutputStream(), helper.getBootloaderIdentificationString()); }
private void processFlashAppCmd(DataInputStream params, IOTACommandHelper helper) throws IOException { String fileNameOnTarget = params.readUTF(); FlashFile suiteFile = new FlashFile(fileNameOnTarget); String currentSuiteUri = Isolate.currentIsolate().getParentSuiteSourceURI(); boolean isReplacingCurrentAppSuite = fileNameOnTarget.equals(currentSuiteUri); boolean isRunningLibrary = currentSuiteUri.equals(ConfigPage.LIBRARY_URI); boolean isLibrarySuiteObsolete = new FlashFile("obsolete:" + ConfigPage.LIBRARY_URI).exists(); boolean isMasterAppSuiteObsolete = !isRunningLibrary && new FlashFile("obsolete:" + currentSuiteUri).exists(); /* * ircas irl ilso imaso action * 0 x 0 0 delete if exists and not in use, flash * 0 0 0 1 error return "Attempt to flash child suite while update to master is pending" * 0 1 0 1 cannot happen * 0 x 1 x error return "Attempt to flash application suite while update to library is pending" * 1 0 x 0 obsolete master app, then flash * 1 0 x 1 flash master app * 1 1 x x cannot happen * */ if (!isReplacingCurrentAppSuite) { if (isLibrarySuiteObsolete) { helper.sendErrorDetails( "Attempt to flash application suite while update to library is pending"); return; } if (isMasterAppSuiteObsolete) { helper.sendErrorDetails( "Attempt to flash child suite while update to master is pending"); // because if we // allowed this we'd need to perform a remap of the MMU, which would cause us to start // executing the // new bytecodes of the pending master app return; } if (suiteFile.exists()) { if (helper.isSuiteInUse(fileNameOnTarget)) { helper.sendErrorDetails("Attempt to replace child suite that is in use"); return; } VM.unregisterSuite(fileNameOnTarget); suiteFile.delete(); } } int virtualAddress; FlashFile currentFile = new FlashFile(fileNameOnTarget); if (currentFile.exists()) { virtualAddress = currentFile.getVirtualAddress(); } else { virtualAddress = FlashFile.getUnusedVirtualAddress(); } helper.sendPrompt(); Utils.log("[OTA] Flashing suite: " + fileNameOnTarget); helper.replaceSuiteFile(params, fileNameOnTarget, virtualAddress); if (!isReplacingCurrentAppSuite) { Utils.log("[OTA] remapping virtual addresses..."); suiteFile.map(); } helper.sendPrompt(); }
private void processDeletePublicKeyCmd(IOTACommandHelper helper) throws IOException { setPublicKey(new byte[0]); helper.sendPrompt(); }