From d2178f3b737f75f4bd80a7b6102354bda108bb9d Mon Sep 17 00:00:00 2001 From: Ruakij Date: Wed, 24 Nov 2021 22:35:07 +0100 Subject: [PATCH] Implemented PacketType Disassociation --- src/dto/Packet.js | 5 +++++ src/streamHandler/PacketStreamFactory.js | 8 +++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/dto/Packet.js b/src/dto/Packet.js index 77c8138..3da3015 100644 --- a/src/dto/Packet.js +++ b/src/dto/Packet.js @@ -12,6 +12,7 @@ const PacketType = { Authentication: 'Authentication', AssociationRequest: 'AssociationRequest', AssociationResponse: 'AssociationResponse', + Disassociation: 'Disassociation', Unknown: 'Unknown' } @@ -58,6 +59,10 @@ class AssociationResponsePacket extends Packet{ associationIsSuccessful; } +class DisassociationPacket extends Packet{ + disassociationReason; +} + // Specify exports module.exports = { PacketType, diff --git a/src/streamHandler/PacketStreamFactory.js b/src/streamHandler/PacketStreamFactory.js index ac25b6a..262341f 100644 --- a/src/streamHandler/PacketStreamFactory.js +++ b/src/streamHandler/PacketStreamFactory.js @@ -1,7 +1,7 @@ const logger = require.main.require("./helper/logger.js")("PacketStreamFactory"); const { Transform } = require('stream'); const { DateTime } = require("luxon"); -const { PacketType, Packet, PacketWithSSID, BeaconPacket, ProbeRequestPacket, ProbeResponsePacket, AuthenticationPacket, AuthenticationType, AssociationResponsePacket } = require.main.require('./dto/Packet.js'); +const { PacketType, Packet, PacketWithSSID, BeaconPacket, ProbeRequestPacket, ProbeResponsePacket, AuthenticationPacket, AuthenticationType, AssociationResponsePacket, DisassociationPacket } = require.main.require('./dto/Packet.js'); const PACKET_TYPE_MAP = { "Beacon": PacketType.Beacon, @@ -16,6 +16,7 @@ const PACKET_TYPE_MAP = { "Authentication": PacketType.Authentication, "Assoc Request": PacketType.AssociationRequest, "Assoc Response": PacketType.AssociationResponse, + "Disassociation:": PacketType.Disassociation, }; const PACKET_TYPES_REGEX = Object.keys(PACKET_TYPE_MAP).join('|'); @@ -92,6 +93,11 @@ class PacketStreamFactory extends Transform{ newPacket = new AssociationResponsePacket(); newPacket.associationIsSuccessful = data.match(/Assoc Response\s.{0,30}Successful(?=\s|$)/img) ? true : false; break; + + case PacketType.Disassociation: + newPacket = new DisassociationPacket(); + newPacket.disassociationReason = data.match(/(?<=(^|\s)Disassociation:\s).*?(?=\sBSS|$)/img)?.[0] ?? null; + break; } if(newPacket) packet = Object.assign(new newPacket, packet); // Use new, more specific, packet and copy old data over }