DWD: getSWVersion + auto key

This commit is contained in:
Kirill Zhumarin 2025-07-22 13:28:52 +00:00
parent 0198057adf
commit a892f418eb
4 changed files with 49 additions and 7 deletions

View file

@ -2,7 +2,6 @@ import { DWD } from "../src/index.js";
import fs from "fs";
import { openPort } from "./utils.js";
import { parseArgs } from "node:util";
import { sprintf } from "sprintf-js";
const { values: argv } = parseArgs({
options: {
@ -48,9 +47,11 @@ for (const key2 of possibleKeys) {
console.log(foundKeys);
*/
dwd.setKeys("panasonic");
dwd.setKeys("auto");
await dwd.connect();
console.log(await dwd.getSWVersion());
const result = await dwd.readMemory(0x00000000, 96 * 1024, {
onProgress({ percent, speed, remaining }) {
console.log(`Progress: ${percent.toFixed(2)}% | Speed: ${(speed / 1024).toFixed(2)} KB/s | ETA: ${remaining.toFixed(2)}s`);

1
mmu.ts
View file

@ -14,7 +14,6 @@ type MMUTableRow = {
};
const n = 0;
const table = readMmuTable(n * 16 * 1024, fs.readFileSync("/tmp/sram.bin"));
decodeMMU(table);

View file

@ -7,11 +7,10 @@
"scripts": {
"test": "vitest run",
"test:watch": "vitest",
"pub": "npm version patch && npm publish --access public",
"build": "tsc",
"watch": "tsc -w"
},
"author": "",
"author": "kirill.zhumarin@gmail.com",
"license": "MIT",
"description": "Various serial protocols which are used in the Siemens Mobile Phones.",
"repository": {

View file

@ -33,6 +33,8 @@ enum FrameType {
WRITE_MEMORY_REQ = 0x78,
WRITE_MEMORY_RESP = 0x79,
SW_RESET_REQ = 0xAD,
GET_SW_VERSION_REQ = 0x54,
GET_SW_VERSION_RESP = 0x55,
}
export type DWDKeys = {
@ -68,10 +70,18 @@ const FRAME_SIZE = {
[FrameType.READ_MEMORY_RESP]: 0,
[FrameType.WRITE_MEMORY_REQ]: 8,
[FrameType.WRITE_MEMORY_RESP]: 4,
[FrameType.SW_RESET_REQ]: 2
[FrameType.SW_RESET_REQ]: 2,
[FrameType.GET_SW_VERSION_REQ]: 2,
[FrameType.GET_SW_VERSION_RESP]: 0,
};
export const DWD_KEYS: Record<string, DWDKeys> = {
"auto": {
key1: Buffer.from("00000000000000000000000000000000", "hex"),
key2: 0x0000,
key3: Buffer.from("00000000000000000000000000000000", "hex"),
key4: 0x0000,
},
"lg": {
key1: Buffer.from("70C469DA2C399DB11E26AB61F0B25204", "hex"),
key2: 0x62B5,
@ -83,6 +93,12 @@ export const DWD_KEYS: Record<string, DWDKeys> = {
key2: 0x7C6C,
key3: Buffer.from("00000000000000000000000000000000", "hex"),
key4: 0x0000,
},
"siemens": {
key1: Buffer.from("F806A5AF18EE7E1C1E737C6CC0F95236", "hex"),
key2: 0x7C6C,
key3: Buffer.from("00000000000000000000000000000000", "hex"),
key4: 0x0000,
}
};
@ -99,7 +115,7 @@ export class DWDTimeoutError extends DWDError {
}
export class DWD extends BaseSerialProtocol {
private keys: DWDKeys = DWD_KEYS["panasonic"];
private keys: DWDKeys = DWD_KEYS["auto"];
setKeys(keys: DWDKeys | string) {
if (typeof keys === "string") {
@ -113,6 +129,26 @@ export class DWD extends BaseSerialProtocol {
}
async connect() {
if (this.keys === DWD_KEYS["auto"]) {
let lastError: unknown | undefined;
for (const keyName in DWD_KEYS) {
if (keyName == "auto")
continue;
debug(`Trying key: ${keyName}`);
try {
this.setKeys(keyName);
await this.connect();
debug(`Key found: ${keyName}`);
return;
} catch (e) {
debug(`Bad key: ${keyName}`);
lastError = e;
}
}
this.setKeys("auto");
throw lastError;
}
debug("Enabling V24 mode");
await this.setV24(true);
debug("Sending handshake #1");
@ -128,6 +164,13 @@ export class DWD extends BaseSerialProtocol {
await this.setV24(false);
}
async getSWVersion() {
const request = this.newRequest(FrameType.GET_SW_VERSION_REQ);
const response = await this.execCommand(request, FrameType.GET_SW_VERSION_RESP);
const [sw, power, cpu] = response.subarray(4, -1).toString().split(/\s+/);
return { sw, power, cpu };
}
async readMemory(address: number, length: number, options: IoReadWriteOptions = {}): Promise<IoReadResult> {
return ioReadMemory({
debug,