Skip to content

Instantly share code, notes, and snippets.

@ravikp7
Created May 27, 2017 16:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravikp7/6ed9581124ec3c6abdbb2847ede20c08 to your computer and use it in GitHub Desktop.
Save ravikp7/6ed9581124ec3c6abdbb2847ede20c08 to your computer and use it in GitHub Desktop.
Testing parsing
var usb = require('usb');
var Parser = require('binary-parser').Parser;
// Connect to BeagleBone
var device = usb.findByIds(0x0451, 0x6141);
//console.log(device);
device.open();
var interface = device.interface(1);
//console.log(interface);
// Detach Kernel driver
if (interface.isKernelDriverActive()){
console.log('isKernelDriverActive = ' + interface.isKernelDriverActive());
interface.detachKernelDriver();
}
//Interface claim
console.log('claim = ' + interface.claim());
// Set endpoints
var inEndpoint = interface.endpoint(0x81);
//console.log(inEndpoint);
var outEndpoint = interface.endpoint(0x02);
//console.log(outEndpoint);
// Parsing
var ethhdr = new Parser()
.array('h_dest',{
type: 'uint8',
length: 6
})
.array('h_source',{
type: 'uint8',
length: 6
})
.int16be('h_proto');
// rndis packet size = 44
// Buffer to store ether packet
const data1 = Buffer.alloc(406,0,'hex'); // buffer size = 450-44(rndisSize)
// Receive BOOTP
inEndpoint.timeout = 1000;
inEndpoint.transfer(450, onFirstIn);
function onFirstIn(error, data) {
console.log(error);
console.log(data);
console.log(data1);
data.copy(data1, 0, 44, 450); // copying buffer data from bytes 44 onwards
console.log(data1);
console.log(ethhdr.parse(data1));
}
ravi@ravi-Lenovo-G50-45:~/beagle-js$ sudo node main.js
claim = undefined
undefined
<Buffer 01 00 00 00 c2 01 00 00 24 00 00 00 96 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 ff ff ff ff ff ff ... >
<Buffer 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 ... >
<Buffer ff ff ff ff ff ff a0 f6 fd 8a e9 1a 08 00 45 00 01 88 02 00 00 00 40 11 77 66 00 00 00 00 ff ff ff ff 00 44 00 43 01 74 6a
d0 01 01 06 00 00 00 00 01 ... >
{ h_dest: [ 255, 255, 255, 255, 255, 255 ],
h_source: [ 160, 246, 253, 138, 233, 26 ],
h_proto: 2048 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment