⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 packet.java

📁 The WLAN Traffic Visualizer is a platform independent Java program providing accurate measurement of
💻 JAVA
字号:
package model;

//Copyright (C) 2008 Harald Unander, Wang Wenjuan
//
//    This file is part of WlanTV.
//
//    WlanTV is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    WlanTV is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with WlanTV.  If not, see <http://www.gnu.org/licenses/>.

import java.util.LinkedHashMap;

import main.Main;

public class Packet extends RawPacket {
	private static final long serialVersionUID = 1L;
	
	private static LinkedHashMap<Integer,FType> map = new LinkedHashMap<Integer,FType>();

	static public enum CH_MODES {
		auto("AutoMode"), m11g("802.11g"), m11("802.11"), m11a("802.11a"),
		m11b_short("802.11b_short"), m11b_long("802.11b_long");

		private final String s;
		CH_MODES(String s) {
			this.s = s;
		}
		public String toString() {
			return s;
		}
	}

	public enum FType {DATA,ACK,BEACON,UNKNOWN,PROBE_RSP,NULL, ASS_REQ, 
		ASS_RSP, REASS_REQ, REASS_RSP, PROBE_REQ, ATIM, AUTH, DISASS, DEAUTH, 
		ACTION, BLKACK_REQ, BLKACK, PS_POLL, RTS, CTS, CF_END, CF_END_ACK,
		DATA_CF_ACK, DATA_CF_POLL, DATA_CF_ACK_POLL, CF_ACK, CF_POLL, Q_DATA,
		Q_NULL, CF_ACK_POLL, Q_DATA_CF_ACK, Q_DATA_CF_POLL, Q_DATA_CF_ACK_POLL,
		Q_CF_ACK, Q_CF_POLL, Q_CF_ACK_POLL, RECONSTRUCTED, FILL};

		public enum FClass {DATA,MANAGEMENT,CONTROL,UNKNOWN};

		public transient int channel;
		public transient long timeStamp;
		public transient FType fType;
		public transient int frameDur;
		public transient int psduDur;
		public transient CH_MODES chMode;
		public transient int slotTime;
		
		private static transient boolean first = true;

		public static FType getWlanSubType(int t) {
			if (getMap().containsKey(t)) {
				return getMap().get(t);
			}
			else {
				//				Main.log.println(String.format("??? %d %02x",l,t));
				return FType.UNKNOWN;
			}
		}

		static {
			getMap().put(0x00,FType.ASS_REQ);
			getMap().put(0x01,FType.ASS_RSP);
			getMap().put(0x02,FType.REASS_REQ);
			getMap().put(0x03,FType.REASS_RSP);
			getMap().put(0x04,FType.PROBE_REQ);
			getMap().put(0x05,FType.PROBE_RSP);

			getMap().put(0x08,FType.BEACON);
			getMap().put(0x09,FType.ATIM);
			getMap().put(0x0a,FType.DISASS);
			getMap().put(0x0b,FType.AUTH);
			getMap().put(0x0c,FType.DEAUTH);
			getMap().put(0x0d,FType.ACTION);

			getMap().put(0x18,FType.BLKACK_REQ);
			getMap().put(0x19,FType.BLKACK);
			getMap().put(0x1a,FType.PS_POLL);
			getMap().put(0x1b,FType.RTS);
			getMap().put(0x1c,FType.CTS);
			getMap().put(0x1d,FType.ACK);
			getMap().put(0x1e,FType.CF_END);
			getMap().put(0x1f,FType.CF_END_ACK);

			getMap().put(0x20,FType.DATA);
			getMap().put(0x21,FType.DATA_CF_ACK);
			getMap().put(0x22,FType.DATA_CF_POLL);
			getMap().put(0x23,FType.DATA_CF_ACK_POLL);
			getMap().put(0x24,FType.NULL);
			getMap().put(0x25,FType.CF_ACK);
			getMap().put(0x26,FType.CF_POLL);
			getMap().put(0x27,FType.CF_ACK_POLL);

			getMap().put(0x28,FType.Q_DATA);
			getMap().put(0x29,FType.Q_DATA_CF_ACK);
			getMap().put(0x2a,FType.Q_DATA_CF_POLL);
			getMap().put(0x2b,FType.Q_DATA_CF_ACK_POLL);
			getMap().put(0x2c,FType.Q_NULL);
			getMap().put(0x2d,FType.Q_CF_ACK);
			getMap().put(0x2e,FType.Q_CF_POLL);
			getMap().put(0x2f,FType.Q_CF_ACK_POLL);

			getMap().put(0x40,FType.UNKNOWN);
			getMap().put(0x41,FType.RECONSTRUCTED);
			getMap().put(0x42,FType.FILL);
		}

		public void calculate(CH_MODES mode) {
			if (mode == CH_MODES.auto) {
				if (frameProtocols.contains("radiotap")) {
					setChMode();
				}
				else {
					chMode = CH_MODES.m11g;
					if (first) {
						Main.myLogging.addWarning(this,"The header lacks channel mode information and AutoMode selected - guessing 11g.");
						first = false;
					}
				}
			}
			else {
				chMode = mode;
			}
			innerCalculate();
			fType = getWlanSubType(wlanSubtype);
		}

		public void innerCalculate() {
			frameDur = getFrameDur();
			timeStamp = frameTimeRel - frameDur;
			psduDur = frameDur - getPreambleDur() - getPlcpDur();
		}

		public static LinkedHashMap<Integer,FType> getMap() {
			return map;
		}

		public FClass findFrameClass () {
			if ((wlanSubtype & 0x30) == 0)
				return FClass.MANAGEMENT;
			else if ((wlanSubtype & 0x30) == 0x10)
				return FClass.CONTROL;
			else if ((wlanSubtype & 0x30) == 0x20)
				return FClass.DATA;
			else 
				return FClass.UNKNOWN;
		}

		public void setChMode() {
			if ((channelType & 0xc0) == 0xc0) {
				chMode = CH_MODES.m11g;
				if (mgmtShortSlotTime==1)
					slotTime = 9;
				else
					slotTime = 20;
			}
			else if ((channelType & 0x480) == 0x480) {
				if (is11bRate(frameRate)) {
					if (mgmtPreamble==0)
						chMode = CH_MODES.m11b_long;
					else
						chMode = CH_MODES.m11b_short;
					if (mgmtShortSlotTime==1)
						slotTime = 9;
					else
						slotTime = 20;
				}
				else {
					chMode = CH_MODES.m11g;
					if (mgmtShortSlotTime==1)
						slotTime = 9;
					else
						slotTime = 20;
				}
			}
			else if ((channelType & 0xa0)==0xa0) {
				if (mgmtPreamble==0)
					chMode = CH_MODES.m11b_long;
				else
					chMode = CH_MODES.m11b_short;
				if (mgmtShortSlotTime==1)
					slotTime = 9;
				else
					slotTime = 20;
			}
			else if ((channelType & 0x100) == 0x100) {
				chMode = CH_MODES.m11a;
				slotTime = 9;
			}
			else {
				chMode = CH_MODES.m11;
				slotTime = 50;
			}
		}

		private boolean is11bRate(float frameRate) {
			if (frameRate==1 || frameRate==2 || frameRate==5.5 || frameRate==11)
				return true;
			else
				return false;
		}

		public int getDifsDur() {
			return getSifsDur()+2*slotTime;
		}

		public int getSifsDur() {
			int v = 0;
			if (chMode == CH_MODES.m11a)
				v = 16;
			else if (chMode == CH_MODES.m11)
				v = 28;
			else
				v = 10;
			return v;
		}

		public int getBackoffDur() {
			int v = 0;
			if (chMode==CH_MODES.m11g)
				v = slotTime*15/2;
			else if (chMode==CH_MODES.m11b_short || chMode==CH_MODES.m11b_long)	
				v = slotTime*31/2;
			else if (chMode == CH_MODES.m11a)
				v = slotTime*15/2;
			else if (chMode == CH_MODES.m11)
				v = slotTime*15/2;
			return v;
		}

		public int getPreambleDur() {
			int v = 0;
			if (chMode==CH_MODES.m11g)
				v = 16;
			else if (chMode == CH_MODES.m11b_long)
				v = 144;
			else if (chMode == CH_MODES.m11b_short)
				v = 72;
			else if (chMode == CH_MODES.m11a)
				v = 16;
			else if (chMode == CH_MODES.m11)
				v = 96;
			return v;
		}

		public int getPlcpDur() {
			int v = 0;
			if (chMode==CH_MODES.m11g)
				v = 4;
			else if (chMode == CH_MODES.m11b_long)	
				v=48;
			else if (chMode == CH_MODES.m11b_short)
				v=24;
			else if (chMode == CH_MODES.m11a)
				v = 4;
			else if (chMode == CH_MODES.m11)
				v = 32;
			return v;
		}

		public int getFrameDur() {
			int v = 0;
			if (chMode==CH_MODES.m11g)
				v = (int) (26 + Math.ceil((22+8*frameLen)/(4*frameRate)) * 4);
			else if (chMode == CH_MODES.m11b_long)	
				v = (int)(192+8*frameLen/frameRate);
			else if (chMode == CH_MODES.m11b_short)	
				v = (int)(96+8*frameLen/frameRate);
			else if (chMode == CH_MODES.m11a)
				v = (int) (20 + Math.ceil((22+8*frameLen)/(4*frameRate)) * 4);
			else if (chMode == CH_MODES.m11)
				v = (int) (128 + Math.ceil(8*frameLen*33/32) / frameRate);
			return v;
		}

		public String getPacketInfo() {
			StringBuffer sb = new StringBuffer();
			sb.append("Channel\t"  +channel+"\n");
			sb.append("FrameDur\t" +frameDur+"\n");
			sb.append("PreambDur\t"+getPreambleDur()+"\n");
			sb.append("PlcpHdDur\t"+getPlcpDur()+"\n");
			sb.append("PsduDur\t"  +psduDur+"\n");
			//			sb.append("StartTime\t"+timeStamp+"\n");
			//			sb.append("EndTime\t"  +(timeStamp+frameDur)+"\n");
			sb.append("Type\t"     +fType+"\n");
			sb.append("ChMode\t"   +chMode+"\n");
			//			sb.append("ModeCorr\t" +modeCorrected+"\n");
			sb.append("SlotTime\t" +slotTime);
			return sb.toString();
		}

		public static int findAckDuration(Packet p) {
			Packet ackP = new Packet();
			ackP.chMode = p.chMode;
			ackP.frameRate = p.frameRate;
			ackP.frameLen = 12;
			return p.getSifsDur() + ackP.getFrameDur();
		}

		public static String getSlotTime(int shortSlotTime) {
			if (shortSlotTime == 1)
				return "short";
			else
				return "long";
		}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -