add WifiSettingsSet

This commit is contained in:
DavidVentura
2024-01-31 10:58:44 +01:00
parent 5204020e7b
commit 7229f5781e
4 changed files with 47 additions and 9 deletions
+1
View File
@@ -40,6 +40,7 @@ export const ControlCommands = {
// CloseSessionAck: 0x3111, // CloseSessionAck: 0x3111,
DevStatus: 0x0810, // CMD_SYSTEM_STATUS_GET DevStatus: 0x0810, // CMD_SYSTEM_STATUS_GET
DevStatusAck: 0x0811, DevStatusAck: 0x0811,
WifiSettingsSet: 0x0160, // CMD_NET_WIFISETTING_SET
WifiSettings: 0x0260, // CMD_NET_WIFISETTING_GET WifiSettings: 0x0260, // CMD_NET_WIFISETTING_GET
WifiSettingsAck: 0x0261, WifiSettingsAck: 0x0261,
ListWifi: 0x0360, // CMD_NET_WIFI_SCAN ListWifi: 0x0360, // CMD_NET_WIFI_SCAN
+26 -1
View File
@@ -114,11 +114,36 @@ export const SendVideoResolution = (session: Session, resol: 1 | 2 | 3 | 4): nul
}; };
export const SendReboot = (session: Session): DataView => { export const SendReboot = (session: Session): DataView => {
//const dv = new DataView(new Uint8Array(8).fill(0).buffer);
let dv = null; let dv = null;
return makeDataReadWrite(session, ControlCommands.Reboot, dv); return makeDataReadWrite(session, ControlCommands.Reboot, dv);
}; };
export const SendWifiDetails = (session: Session, ssid: string, password: string, dhcp: boolean): DataView => {
if (!dhcp) {
throw new Error("only DHCP is supported");
}
let buf = new Uint8Array(0x108).fill(0);
let cmd_payload = new DataView(buf.buffer);
let mask_reversed = "0.255.255.255";
// unclear which is which ))
let m_ip = "0.0.0.0";
let m_gw = "0.0.0.0";
let m_dns1 = "0.0.0.0";
let m_dns2 = "0.0.0.0";
cmd_payload.add(0x14).writeU8(1); // DHCP ?
cmd_payload.add(0x18).writeByteArray(str2byte(ssid));
cmd_payload.add(0x38).writeByteArray(str2byte(password));
cmd_payload.add(0xb8).writeByteArray(str2byte(mask_reversed));
cmd_payload.add(0xc8).writeByteArray(str2byte(m_ip));
cmd_payload.add(0xd8).writeByteArray(str2byte(m_gw));
cmd_payload.add(0xe8).writeByteArray(str2byte(m_dns1));
cmd_payload.add(0xf8).writeByteArray(str2byte(m_dns2));
const ret = makeDataReadWrite(session, ControlCommands.WifiSettingsSet, cmd_payload);
return ret;
};
export const SendUsrChk = (session: Session, username: string, password: string): DataView => { export const SendUsrChk = (session: Session, username: string, password: string): DataView => {
let buf = new Uint8Array(0x20 + 0x80); let buf = new Uint8Array(0x20 + 0x80);
buf.fill(0); buf.fill(0);
+10 -7
View File
@@ -19,16 +19,14 @@ data = [
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x31, 0x2f, 0x31, 0x2f, 0x31, 0x2f, 0x31, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x31, 0x2f, 0x31, 0x2f, 0x31, 0x2f, 0x31, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
] ]
payload = data[0x14:]
def dec(d): def dec(d):
ret = [] ret = []
for b in d: for b in d[0x14:]:
if b % 2: if b % 2:
ret.append(b - 1) ret.append(b - 1)
else: else:
ret.append(b + 1) ret.append(b + 1)
ret = ret[4:] + ret[:4] ret = d[:0x14] + ret[-4:] + ret[:-4]
return ret return ret
def hexdump(dump): def hexdump(dump):
@@ -52,11 +50,16 @@ def hexdump(dump):
print(" ", end="") print(" ", end="")
for b in line: for b in line:
rep = "." rep = "."
if chr(b) in string.printable: if chr(b) in string.digits or chr(b) in string.ascii_letters:
rep = chr(b) rep = chr(b)
print(rep, end="") print(rep, end="")
print("") print("")
_dec = dec(payload) _dec = dec(data)
hexdump(_dec) hexdump(_dec[0x14:])
#print([hex(n) for n in _dec])
print("for test values, DEC")
print("".join([f"{n:02x}" for n in _dec]))
print("for test values, enc")
print("".join([f"{n:02x}" for n in data]))
+10 -1
View File
@@ -5,7 +5,7 @@ import assert from "assert";
import { XqBytesDec, XqBytesEnc } from "../func_replacements.js"; import { XqBytesDec, XqBytesEnc } from "../func_replacements.js";
import { createResponseForControlCommand } from "../handlers.js"; import { createResponseForControlCommand } from "../handlers.js";
import { hexdump } from "../hexdump.js"; import { hexdump } from "../hexdump.js";
import { SendDevStatus, SendUsrChk } from "../impl.ts"; import { SendDevStatus, SendUsrChk, SendWifiDetails } from "../impl.ts";
import { placeholderTypes, sprintf } from "../utils.js"; import { placeholderTypes, sprintf } from "../utils.js";
describe("debug_tools", () => { describe("debug_tools", () => {
@@ -151,4 +151,13 @@ describe("make packet", () => {
const got = SendDevStatus(sess); const got = SendDevStatus(sess);
assert.deepEqual(got.buffer, expected); assert.deepEqual(got.buffer, expected);
}); });
it("builds a good WifiSettingsSet", () => {
const sess = { outgoingCommandId: 2, ticket: [1, 2, 3, 4] };
const _expected_str =
"f1d00118d1000002110a01600c010000010203040101010101010101010101010101010100010101726a786f647501010101010101010101010101010101010101010101010101017274716473627360710101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101312f3334342f3334342f333434010101312f312f312f31010101010101010101312f312f312f31010101010101010101312f312f312f31010101010101010101312f312f312f3101010101010101010101010101";
const expected = hstrToBA(_expected_str);
const got = SendWifiDetails(sess, "skynet", "supercrap", true);
assert.deepEqual(got.buffer, expected);
});
}); });