Socket
Socket
Sign inDemoInstall

usb

Package Overview
Dependencies
Maintainers
2
Versions
96
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

usb - npm Package Compare versions

Comparing version 1.4.0 to 1.5.0

libusb/.git

8

package.json
{
"name": "usb",
"description": "Library to access USB devices",
"version": "1.4.0",
"version": "1.5.0",
"engines": {
"node": ">=0.12.x"
"node": ">=6"
},

@@ -46,6 +46,6 @@ "keywords": [

"nan": "^2.8.0",
"node-pre-gyp": "^0.6.30"
"node-pre-gyp": "^0.11.0"
},
"devDependencies": {
"coffee-script": "~1.6.2",
"coffeescript": "~1.6.2",
"mocha": "~1.8.2",

@@ -52,0 +52,0 @@ "aws-sdk": "~2.0.0-rc.15"

USB Library for Node.JS
===============================
**POSIX:** [![Build Status](https://travis-ci.org/nonolith/node-usb.svg?branch=tcr-usb)](https://travis-ci.org/nonolith/node-usb)     **Windows:** [![Build status](https://ci.appveyor.com/api/projects/status/b23kn1pi386nguya/branch/master)](https://ci.appveyor.com/project/kevinmehall/node-usb/branch/master)
**POSIX:** [![Build Status](https://travis-ci.org/tessel/node-usb.svg?branch=master)](https://travis-ci.org/tessel/node-usb)    
**Windows:** [![Build status](https://ci.appveyor.com/api/projects/status/b23kn1pi386nguya/branch/master)](https://ci.appveyor.com/project/kevinmehall/node-usb/branch/master)

@@ -24,3 +25,3 @@ Node.JS library for communicating with USB devices in JavaScript / CoffeeScript.

### Windows
Use [Zadig](http://sourceforge.net/projects/libwdi/files/zadig/) to install the WinUSB driver for your USB device. Otherwise you will get `LIBUSB_ERROR_NOT_SUPPORTED` when attempting to open devices.
Use [Zadig](http://zadig.akeo.ie/) to install the WinUSB driver for your USB device. Otherwise you will get `LIBUSB_ERROR_NOT_SUPPORTED` when attempting to open devices.

@@ -95,10 +96,2 @@

### .bosDescriptor
Object with properties for the fields of the Binary Object Store descriptor:
- bLength
- bDescriptorType
- wTotalLength
- bNumDeviceCaps
### .allConfigDescriptors

@@ -132,2 +125,13 @@ Contains all config descriptors of the device (same structure as .configDescriptor above)

### .getBosDescriptor(callback(error, bosDescriptor))
Perform a control transfer to retrieve an object with properties for the fields of the Binary Object Store descriptor:
- bLength
- bDescriptorType
- wTotalLength
- bNumDeviceCaps
### .getCapabilities(callback(error, capabilities))
Retrieve a list of Capability objects for the Binary Object Store capabilities of the device.
### .interface(interface)

@@ -139,5 +143,2 @@ Return the interface with the specified interface number.

### .capabilities
List of Capability objects for the Binary Object Store capabilities of the device.
### .timeout

@@ -199,2 +200,3 @@ Timeout in milliseconds to use for control transfers.

Capability

@@ -211,3 +213,2 @@ ---------

Object with fields from the capability descriptor -- see libusb documentation or USB spec.
- bLength

@@ -217,2 +218,3 @@ - bDescriptorType

Endpoint

@@ -245,2 +247,5 @@ --------

### .clearHalt(callback(error))
Clear the halt/stall condition for this endpoint.
InEndpoint

@@ -276,3 +281,3 @@ ----------

### Event: error(error)
Emitted when polling encounters an error.
Emitted when polling encounters an error. All in flight transfers will be automatically canceled and no further polling will be done. You have to wait for the `end` event before you can start polling again.

@@ -279,0 +284,0 @@ ### Event: end

@@ -9,5 +9,10 @@ var binary = require('node-pre-gyp');

// Check that libusb was initialized.
if (usb.INIT_ERROR) {
throw new Error('Could not initialize libusb. Check that your system has a usb controller.');
console.warn("Failed to initialize libusb.")
usb.Device = function () { throw new Error("Device cannot be instantiated directly.") };
usb.Transfer = function () { throw new Error("Transfer cannot be instantiated directly.") };
usb.setDebugLevel = function () { };
usb.getDeviceList = function () { return []; };
usb._enableHotplugEvents = function () { };
usb._disableHotplugEvents = function () { };
}

@@ -41,7 +46,2 @@

}
this.capabilities = [];
len = this.bosDescriptor ? this.bosDescriptor.capabilities.length : 0
for (var i=0; i<len; i++){
this.capabilities[i] = new Capability(this, i)
}
}

@@ -52,3 +52,2 @@

this.interfaces = null
this.capabilities = null;
}

@@ -61,3 +60,5 @@

} catch(e) {
return null;
// Check descriptor exists
if (e.errno == usb.LIBUSB_ERROR_NOT_FOUND) return null;
throw e;
}

@@ -67,12 +68,2 @@ }

Object.defineProperty(usb.Device.prototype, "bosDescriptor", {
get: function() {
try {
return this._bosDescriptor || (this._bosDescriptor = this.__getBosDescriptor())
} catch(e) {
return null;
}
}
});
Object.defineProperty(usb.Device.prototype, "allConfigDescriptors", {

@@ -83,3 +74,5 @@ get: function() {

} catch(e) {
return null;
// Check descriptors exist
if (e.errno == usb.LIBUSB_ERROR_NOT_FOUND) return [];
throw e;
}

@@ -129,3 +122,3 @@ }

// http://libusbx.sourceforge.net/api-1.0/structlibusb__control__setup.html
var buf = new Buffer(wLength + SETUP_SIZE)
var buf = Buffer.alloc(wLength + SETUP_SIZE)
buf.writeUInt8( bmRequestType, 0)

@@ -179,2 +172,87 @@ buf.writeUInt8( bRequest, 1)

usb.Device.prototype.getBosDescriptor = function (callback) {
if (this._bosDescriptor) {
// Cached descriptor
return callback(undefined, this._bosDescriptor);
}
if (this.deviceDescriptor.bcdUSB < 0x201) {
// BOS is only supported from USB 2.0.1
return callback(undefined, null);
}
this.controlTransfer(
usb.LIBUSB_ENDPOINT_IN,
usb.LIBUSB_REQUEST_GET_DESCRIPTOR,
(usb.LIBUSB_DT_BOS << 8),
0,
usb.LIBUSB_DT_BOS_SIZE,
function (error, buffer) {
if (error) {
// Check BOS descriptor exists
if (error.errno == usb.LIBUSB_TRANSFER_STALL) return callback(undefined, null);
return callback(error, null);
}
var totalLength = buffer.readUInt16LE(2);
this.controlTransfer(
usb.LIBUSB_ENDPOINT_IN,
usb.LIBUSB_REQUEST_GET_DESCRIPTOR,
(usb.LIBUSB_DT_BOS << 8),
0,
totalLength,
function (error, buffer) {
if (error) {
// Check BOS descriptor exists
if (error.errno == usb.LIBUSB_TRANSFER_STALL) return callback(undefined, null);
return callback(error, null);
}
var descriptor = {
bLength: buffer.readUInt8(0),
bDescriptorType: buffer.readUInt8(1),
wTotalLength: buffer.readUInt16LE(2),
bNumDeviceCaps: buffer.readUInt8(4),
capabilities: []
};
var i = usb.LIBUSB_DT_BOS_SIZE;
while (i < descriptor.wTotalLength) {
var capability = {
bLength: buffer.readUInt8(i + 0),
bDescriptorType: buffer.readUInt8(i + 1),
bDevCapabilityType: buffer.readUInt8(i + 2)
};
capability.dev_capability_data = buffer.slice(i + 3, i + capability.bLength);
descriptor.capabilities.push(capability);
i += capability.bLength;
}
// Cache descriptor
this._bosDescriptor = descriptor;
callback(undefined, this._bosDescriptor);
}
);
}
);
}
usb.Device.prototype.getCapabilities = function (callback) {
var capabilities = [];
var self = this;
this.getBosDescriptor(function(error, descriptor) {
if (error) return callback(error, null);
var len = descriptor ? descriptor.capabilities.length : 0
for (var i=0; i<len; i++){
capabilities.push(new Capability(self, i))
}
callback(undefined, capabilities);
});
}
usb.Device.prototype.setConfiguration = function(desired, cb) {

@@ -189,7 +267,2 @@ var self = this;

}
this.capabilities = [];
len = this.bosDescriptor ? this.bosDescriptor.capabilities.length : 0
for (var i=0; i<len; i++){
this.capabilities[i] = new Capability(this, i)
}
}

@@ -292,9 +365,5 @@ cb.call(self, err)

this.id = id
this.__refresh()
}
Capability.prototype.__refresh = function(){
this.descriptor = this.device.bosDescriptor.capabilities[this.id]
this.descriptor = this.device._bosDescriptor.capabilities[this.id]
this.type = this.descriptor.bDevCapabilityType
this.data = this.descriptor.data
this.data = this.descriptor.dev_capability_data
}

@@ -312,2 +381,6 @@

Endpoint.prototype.clearHalt = function(callback){
return this.device.__clearHalt(this.address, callback);
}
Endpoint.prototype.makeTransfer = function(timeout, callback){

@@ -359,3 +432,3 @@ return new usb.Transfer(this.device, this.address, this.transferType, timeout, callback)

var self = this
var buffer = new Buffer(length)
var buffer = Buffer.alloc(length)

@@ -392,2 +465,3 @@ function callback(error, buf, actual){

if (self.pollPending == 0){
delete self.pollTransfers;
self.emit('end')

@@ -400,3 +474,3 @@ }

try {
t.submit(new Buffer(self.pollTransferSize), transferDone);
t.submit(Buffer.alloc(self.pollTransferSize), transferDone);
} catch (e) {

@@ -424,5 +498,5 @@ self.emit("error", e);

if (!buffer){
buffer = new Buffer(0)
buffer = Buffer.alloc(0)
}else if (!Buffer.isBuffer(buffer)){
buffer = new Buffer(buffer)
buffer = Buffer.from(buffer)
}

@@ -446,3 +520,3 @@

this.transfer(buf);
this.transfer(new Buffer(0), cb);
this.transfer(Buffer.alloc(0), cb);
} else {

@@ -456,3 +530,5 @@ this.transfer(buf, cb);

if (name !== 'attach' && name !== 'detach') return;
if (++hotplugListeners === 1) usb._enableHotplugEvents();
if (++hotplugListeners === 1) {
usb._enableHotplugEvents();
}
});

@@ -462,3 +538,5 @@

if (name !== 'attach' && name !== 'detach') return;
if (--hotplugListeners === 0) usb._disableHotplugEvents();
if (--hotplugListeners === 0) {
usb._disableHotplugEvents();
}
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc