Skip to content

Instantly share code, notes, and snippets.

@jadonk
Last active January 26, 2022 13:38
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jadonk/208f209351f16fa02ecb56a9f75447d9 to your computer and use it in GitHub Desktop.
Hacks and node-beaglebone-boot

Current status:

playdoh:BBBlfs jason$ node --version
v7.5.0
playdoh:BBBlfs jason$ gcc --version
Configured with: --prefix=/Applications/Xcode.app/Contents/Developer/usr --with-gxx-include-dir=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include/c++/4.2.1
Apple LLVM version 8.0.0 (clang-800.0.38)
Target: x86_64-apple-darwin16.5.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
playdoh:BBBlfs jason$ node main.js 
Device {
  busNumber: 20,
  deviceAddress: 22,
  deviceDescriptor: 
   { bLength: 18,
     bDescriptorType: 1,
     bcdUSB: 512,
     bDeviceClass: 2,
     bDeviceSubClass: 0,
     bDeviceProtocol: 0,
     bMaxPacketSize0: 64,
     idVendor: 1105,
     idProduct: 24897,
     bcdDevice: 0,
     iManufacturer: 33,
     iProduct: 37,
     iSerialNumber: 0,
     bNumConfigurations: 1 },
  portNumbers: [ 1, 1 ] }
Interface {
  device: 
   Device {
     busNumber: 20,
     deviceAddress: 22,
     deviceDescriptor: 
      { bLength: 18,
        bDescriptorType: 1,
        bcdUSB: 512,
        bDeviceClass: 2,
        bDeviceSubClass: 0,
        bDeviceProtocol: 0,
        bMaxPacketSize0: 64,
        idVendor: 1105,
        idProduct: 24897,
        bcdDevice: 0,
        iManufacturer: 33,
        iProduct: 37,
        iSerialNumber: 0,
        bNumConfigurations: 1 },
     portNumbers: [ 1, 1 ],
     interfaces: [ [Object], [Circular] ],
     _configDescriptor: 
      { bLength: 9,
        bDescriptorType: 2,
        wTotalLength: 70,
        bNumInterfaces: 2,
        bConfigurationValue: 1,
        iConfiguration: 1,
        bmAttributes: 192,
        bMaxPower: 50,
        extra: <Buffer 03 09 03>,
        interfaces: [Object] } },
  id: 1,
  altSetting: 0,
  descriptor: 
   { bLength: 9,
     bDescriptorType: 4,
     bInterfaceNumber: 1,
     bAlternateSetting: 0,
     bNumEndpoints: 2,
     bInterfaceClass: 10,
     bInterfaceSubClass: 0,
     bInterfaceProtocol: 0,
     iInterface: 2,
     extra: <Buffer >,
     endpoints: [ [Object], [Object] ] },
  interfaceNumber: 1,
  endpoints: 
   [ InEndpoint {
       device: [Object],
       descriptor: [Object],
       address: 129,
       transferType: 2 },
     OutEndpoint {
       device: [Object],
       descriptor: [Object],
       address: 2,
       transferType: 2 } ] }
isKernelDriverActive = false
/Users/jason/workspace/BBBlfs/node_modules/usb/usb.js:168
	this.device.__claimInterface(this.id)
	            ^

Error: LIBUSB_ERROR_ACCESS
    at Interface.claim (/Users/jason/workspace/BBBlfs/node_modules/usb/usb.js:168:14)
    at Object.<anonymous> (/Users/jason/workspace/BBBlfs/main.js:13:36)
    at Module._compile (module.js:571:32)
    at Object.Module._extensions..js (module.js:580:10)
    at Module.load (module.js:488:32)
    at tryModuleLoad (module.js:447:12)
    at Function.Module._load (module.js:439:3)
    at Module.runMain (module.js:605:10)
    at run (bootstrap_node.js:418:7)
    at startup (bootstrap_node.js:139:9)
#!/usr/bin/env node
var usb = require('usb');
var packet = require('packet');
// Connect to BeagleBone
var device = usb.findByIds(0x0451, 0x6141);
console.log(device);
device.open();
var interface = device.interface(1);
console.log(interface);
console.log('isKernelDriverActive = ' + interface.isKernelDriverActive());
//sudo kextunload /System/Library/Extensions/HoRNDIS.kext
console.log('claim = ' + interface.claim());
//interface.attachKernelDriver();
var inEndpoint = interface.endpoint(0x81);
console.log(inEndpoint);
var outEndpoint = interface.endpoint(0x02);
console.log(outEndpoint);
// Send BOOTP
inEndpoint.timeout = 1000;
inEndpoint.transfer(450, onFirstIn);
function onFirstIn(error, data) {
console.log(error);
console.log(data);
}
var parser = packet.createParser();
parser.packet("rndis", "\
msg_type: b32, \
msg_len: b32, \
data_offset: b32, \
band_offset: b32, \
band_len: b32, \
out_band_elements: b32, \
packet_offset: b32, \
packet_info_len: b32, \
reserved_first: b32, \
reserved_second: b32");
var serializer = parser.createSerializer();
// Get ARP request, send response
// Get TFTP request, send data
{
"name": "beaglebone-boot",
"version": "0.0.1",
"description": "Boot BeagleBone over USB using on-chip ROM",
"main": "main.js",
"dependencies": {
"usb": "1.2.0"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/jadonk/beaglebone-boot.git"
},
"keywords": [
"beaglebone",
"boot",
"bootp",
"tftp",
"rndis",
"libusb"
],
"author": "Jason Kridner",
"license": "MIT",
"bugs": {
"url": "https://github.com/jadonk/beaglebone-boot/issues"
},
"homepage": "https://github.com/jadonk/beaglebone-boot#readme"
}
@ravikp7
Copy link

ravikp7 commented Mar 6, 2017

jKridner, have you tested the packet library? its documentation is outdated. require('packet').createParser is not a function. I have installed packet v 0.0.7 the latest one. I tested it on my machine as well as on runkit.com (npm's online tester), it fails on both. I've attached a screenshot. Trying require('packet').createPacketizer().createParser() which seems to be a valid function, also seems to throw some error. I think we should look for an alternative for this library.
screenshot from 2017-03-06 23-36-24

@uditagarwal97
Copy link

Do you observe that each time you connect PDA it gets different USB address?
if yes, then this might indicate randisc 110 error
http://synce-users.narkive.com/75dqaxM7/rndis-error-110-with-hp214-ubuntu-8-10
Also, did you give root access to node?

@uditagarwal97
Copy link

uditagarwal97 commented Mar 10, 2017

finally, i was able to claim the RNDIS interface
logs at: https://gist.github.com/madaari/a1d86104b985ee1a096e001397102c32
There was some issue with program permissions.(Nodejs didn't have sufficient rights to claim interaface).
also, try upgrading node-pre-gyp

@ravikp7
Copy link

ravikp7 commented Mar 10, 2017

This seems to be an OSX specific issue, even doesn't work with admin user, issue is still open on node-usb github node-usb/node-usb#30

@uditagarwal97
Copy link

jkridner , I tested the code on OSX, and was able to claim the interface!!
logs https://gist.github.com/madaari/a595b173256f0d31e42365b46cb17722
did you tried it with node 7.7.3?? also can you please send logs of " ioreg -p IOUSB -l -w 0 " and "dmesg"?
what i found was that, i case of hid device like an optical mouse there was an error in claiming the interface ; while in case of RNDIS (CDC) there's no such error!

@ravikp7
Copy link

ravikp7 commented Mar 18, 2017

madaari, check your code again, you've not specified any interface number while accessing the interface. Specify interface number 1 in the device.interface argument and then try to claim the interface.

@uditagarwal97
Copy link

Hi ravikp7, Thanks for pointing out! I did the correction and tested the code, but still there's no error.
logs at https://gist.github.com/madaari/e8cb562dd8ab4c76a4d8174d8e6dae04

@inactivist
Copy link

inactivist commented Feb 6, 2018

jKridner, have you tested the packet library? its documentation is outdated. require('packet').createParser is not a function. I have installed packet v 0.0.7 the latest one. I tested it on my machine as well as on runkit.com (npm's online tester), it fails on both. I've attached a screenshot. Trying require('packet').createPacketizer().createParser() which seems to be a valid function, also seems to throw some error. I think we should look for an alternative for this library.

@ravikp7 - packet@0.0.6 version seems to work according to the docs on that version's branch (confirmed via a quick test on RunKit). Haven't tested it thoroughly, though -- YMMV. Cheers!

@MunoDevelop
Copy link

documentation outdated!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment