emit ListWifi on scan

This commit is contained in:
David Ventura
2024-05-07 12:05:12 +02:00
parent db98e6685c
commit 17d00eaba9
+2 -6
View File
@@ -122,6 +122,7 @@ export const createResponseForControlCommand = (session: Session, dv: DataView):
return []; return [];
} }
const items = parseListWifi(dv); const items = parseListWifi(dv);
session.eventEmitter.emit("ListWifi", items);
return []; return [];
case ControlCommands.StartVideoAck: case ControlCommands.StartVideoAck:
logger.debug("Start video ack"); logger.debug("Start video ack");
@@ -135,7 +136,7 @@ export const createResponseForControlCommand = (session: Session, dv: DataView):
return []; return [];
}; };
type WifiListItem = { export type WifiListItem = {
ssid: string; ssid: string;
mac: string; mac: string;
security: number; security: number;
@@ -146,15 +147,12 @@ type WifiListItem = {
}; };
export const parseListWifi = (dv: DataView): WifiListItem[] => { export const parseListWifi = (dv: DataView): WifiListItem[] => {
logger.log("trace", `payload len ${dv.byteLength}`);
let startat = 0x10; let startat = 0x10;
const msg_len = 0x5c; // 0x58 + 0x4 of the last u32 const msg_len = 0x5c; // 0x58 + 0x4 of the last u32
const msg_count = dv.add(startat).readU32LE(); const msg_count = dv.add(startat).readU32LE();
logger.log("trace", `should get messages: ${msg_count} in payload`);
startat += 4; startat += 4;
let items = []; let items = [];
for (let i = 0; i < msg_count; i++) { for (let i = 0; i < msg_count; i++) {
logger.log("trace", `start parsing ${i} at ${startat} - 0x${startat.toString(16)}`);
if (startat + msg_len > dv.byteLength) { if (startat + msg_len > dv.byteLength) {
logger.warning("Wifi listing got cropped"); logger.warning("Wifi listing got cropped");
break; break;
@@ -170,9 +168,7 @@ export const parseListWifi = (dv: DataView): WifiListItem[] => {
mode: dv.add(startat + 0x54).readU32LE(), mode: dv.add(startat + 0x54).readU32LE(),
channel: dv.add(startat + 0x58).readU32LE(), channel: dv.add(startat + 0x58).readU32LE(),
}; };
logger.debug(`Wifi Item: ${JSON.stringify(wifiListItem, null, 2)}`);
startat += msg_len; startat += msg_len;
logger.log("trace", `ended at ${startat} - 0x${startat.toString(16)}`);
items.push(wifiListItem); items.push(wifiListItem);
} }
return items; return items;