Skip to content

Commit 53c150f

Browse files
committed
Layout for 802.11AB Spec Created
1 parent f8575f2 commit 53c150f

12 files changed

+51
-12
lines changed

decode/lldp.js

+26-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
1-
var TLV = require("./lldp_tlv");
1+
var TLV = require("./lldp/lldp_tlv");
22

33
function LLDP(emitter) {
4-
this.emitter = emitter;
5-
this.tlvArray = [];
4+
this.emitter = emitter;
5+
this.chassisTlv = undefined;
6+
this.portIdTlv = undefined
7+
this.ttlTlv = undefined;
8+
this.optionalTlv = [];
69
}
710

811
LLDP.prototype.decode = function (raw_packet, offset) {
9-
while(raw_packet.readUInt16BE(offset, true) != 0) {
10-
currentTLVLength = (raw_packet.readUInt16BE(offset, true) & 0x01ff) + 2;
11-
this.tlvArray.push(new TLV(this.emitter).decode (raw_packet, offset));
12-
offset += currentTLVLength;
13-
}
12+
this.chassisTLV = new TLV(this.emitter).decode (raw_packet, offset);
13+
offset += getTlvLength(raw_packet, offset);
14+
this.portIdTLV = new TLV(this.emitter).decode (raw_packet, offset);
15+
offset += getTlvLength(raw_packet, offset);
16+
this.ttlTLV = new TLV(this.emitter).decode (raw_packet, offset);
17+
offset += getTlvLength(raw_packet, offset);
18+
while(raw_packet.readUInt16BE(offset, true) != 0) {
19+
this.optionalTlv.push(new TLV(this.emitter).decode (raw_packet, offset));
20+
offset += getTlvLength(raw_packet, offset);
21+
}
1422

15-
if(this.emitter) { this.emitter.emit("lldp", this); }
16-
return this;
23+
if(this.emitter) { this.emitter.emit("lldp", this); }
24+
return this;
25+
}
26+
27+
var getTlvLength = function(raw_packet, offset) {
28+
var tlvHeaderSize = 2;
29+
length = (raw_packet.readUInt16BE(offset, true) & 0x01ff) + tlvHeaderSize;
30+
return length;
1731
}
1832

1933
LLDP.prototype.decoderName = "lldp";
2034
LLDP.prototype.eventsOnDecode = true;
2135

36+
LLDP.prototype.toString() = function {}
37+
2238
module.exports = LLDP;

decode/lldp/chassisId.js

Whitespace-only changes.

decode/lldp_tlv.js renamed to decode/lldp/lldp_tlv.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
var types = require("./tlv_types");
2+
13
function TLV(emitter) {
24
this.emitter = emitter;
35
this.tlvType = undefined;
@@ -10,8 +12,12 @@ TLV.prototype.decode = function (raw_packet, offset) {
1012
// https://en.wikipedia.org/wiki/Link_Layer_Discovery_Protocol
1113
this.tlvType = (raw_packet.readUInt16BE(offset, true) & 0xfe00) >> 9;
1214
this.tlvLength = (raw_packet.readUInt16BE(offset, true) & 0x01ff);
13-
this.payload = new Buffer(this.tlvLength);
14-
this.payload.slice(raw_packet[offset+2],raw_packet[offset+this.tlvLength+2]);
15+
var TlvDecoder = types[this.tlvType];
16+
if(TlvDecoder == undefined) {
17+
this.payload = "Unknown";
18+
} else {
19+
this.payload = new TlvDecoder().decode(raw_packet, offset, tlvLength);
20+
}
1521
return this;
1622
}
1723

decode/lldp/managementAddress.js

Whitespace-only changes.

decode/lldp/organization.js

Whitespace-only changes.

decode/lldp/portDescription.js

Whitespace-only changes.

decode/lldp/portId.js

Whitespace-only changes.

decode/lldp/systemCaps.js

Whitespace-only changes.

decode/lldp/systemDescription.js

Whitespace-only changes.

decode/lldp/systemName.js

Whitespace-only changes.

decode/lldp/tlv_types.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var types = new Array(128);
2+
3+
module.exports = types;
4+
5+
function init(){
6+
types[0] = undefined;
7+
types[1] = require("./chassisId");
8+
types[2] = require("./portId");
9+
types[3] = require("./ttl");
10+
types[4] = require("./portDescription");
11+
types[5] = require("./systemName");
12+
types[6] = require("./systemDesciption");
13+
types[7] = require("./systemCaps");
14+
types[8] = require("./managementAddress");
15+
types[127] = require("./organization");
16+
}
17+
init();

decode/lldp/ttl.js

Whitespace-only changes.

0 commit comments

Comments
 (0)