Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const CHECK_LIBUSB_TRANSFER_TIMED_OUT: number = usb.LIBUSB_TRANSFER_TIMED_OUT;
const CHECK_LIBUSB_TRANSFER_CANCELLED: number = usb.LIBUSB_TRANSFER_CANCELLED;
const CHECK_LIBUSB_TRANSFER_STALL: number = usb.LIBUSB_TRANSFER_STALL;
const CHECK_LIBUSB_TRANSFER_NO_DEVICE: number = usb.LIBUSB_TRANSFER_NO_DEVICE;
const CHECK_LIBUSB_TRANSFER_OVERFLOW: number = usb.LIBUSB_TRANSFER_OVERFLOW;
// libusb_transfer_flags
const CHECK_LIBUSB_TRANSFER_SHORT_NOT_OK: number = usb.LIBUSB_TRANSFER_SHORT_NOT_OK;
const CHECK_LIBUSB_TRANSFER_FREE_BUFFER: number = usb.LIBUSB_TRANSFER_FREE_BUFFER;
const CHECK_LIBUSB_TRANSFER_FREE_TRANSFER: number = usb.LIBUSB_TRANSFER_FREE_TRANSFER;
// libusb_request_type
const CHECK_LIBUSB_REQUEST_TYPE_STANDARD: number = usb.LIBUSB_REQUEST_TYPE_STANDARD;
const CHECK_LIBUSB_REQUEST_TYPE_CLASS: number = usb.LIBUSB_REQUEST_TYPE_CLASS;
const CHECK_LIBUSB_REQUEST_TYPE_VENDOR: number = usb.LIBUSB_REQUEST_TYPE_VENDOR;
const CHECK_LIBUSB_REQUEST_TYPE_RESERVED: number = usb.LIBUSB_REQUEST_TYPE_RESERVED;
// libusb_request_recipient
const CHECK_LIBUSB_RECIPIENT_DEVICE: number = usb.LIBUSB_RECIPIENT_DEVICE;
const CHECK_LIBUSB_RECIPIENT_INTERFACE: number = usb.LIBUSB_RECIPIENT_INTERFACE;
const CHECK_LIBUSB_RECIPIENT_ENDPOINT: number = usb.LIBUSB_RECIPIENT_ENDPOINT;
const CHECK_LIBUSB_RECIPIENT_OTHER: number = usb.LIBUSB_RECIPIENT_OTHER;
const CHECK_LIBUSB_CONTROL_SETUP_SIZE: number = usb.LIBUSB_CONTROL_SETUP_SIZE;
// libusb_error
// Input/output error
const CHECK_LIBUSB_ERROR_IO: number = usb.LIBUSB_ERROR_IO;
// Invalid parameter
const CHECK_LIBUSB_ERROR_INVALID_PARAM: number = usb.LIBUSB_ERROR_INVALID_PARAM;
// Access denied (insufficient permissions)
const CHECK_LIBUSB_ERROR_ACCESS: number = usb.LIBUSB_ERROR_ACCESS;
// No such device (it may have been disconnected)
const CHECK_LIBUSB_ERROR_NO_DEVICE: number = usb.LIBUSB_ERROR_NO_DEVICE;
// Entity not found
var DFU = require('./dfu');
var log = require('./log');
function debug(message) {
log.debug(`(discovery:usb) ${message}`);
}
function debugCommands(message) {
log.debug(`(commands:usb) ${message}`);
}
var isUSBAvailable = true;
try {
var usb = require('usb');
var VENDOR_REQ_OUT = usb.LIBUSB_REQUEST_TYPE_VENDOR | usb.LIBUSB_RECIPIENT_DEVICE | usb.LIBUSB_ENDPOINT_OUT;
// var VENDOR_REQ_IN = usb.LIBUSB_REQUEST_TYPE_VENDOR | usb.LIBUSB_RECIPIENT_DEVICE | usb.LIBUSB_ENDPOINT_IN;
} catch (error) {
isUSBAvailable = false;
// do not exit the process during tests because usb is not needed to run them
/* istanbul ignore next */
if (!global.IS_TEST_ENV) {
log.error('Node version mismatch for USB drivers.');
log.info(tags.stripIndent `
Automatically rebuilding USB drivers for t2-cli to correct this issue. Please try running your command again.
If the error persists, please file an issue at https://github.com/tessel/t2-cli/issues/new with this warning.
`);
execSync(`cd ${__dirname} && npm rebuild --update-binary usb`);
process.exit(1);
}
var // External dependencies
usb = require('usb'),
Promise = require('es6-promise').Promise,
// Local dependencies
Connection = require('../connection/Connection'),
AbstractTransport = require('./AbstractTransport'),
// Constannts
TESSEL_VID = 0x1d50,
TESSEL_PID = 0x6097,
VENDOR_REQ_OUT = usb.LIBUSB_REQUEST_TYPE_VENDOR | usb.LIBUSB_RECIPIENT_DEVICE | usb.LIBUSB_ENDPOINT_OUT,
VENDOR_REQ_IN = usb.LIBUSB_REQUEST_TYPE_VENDOR | usb.LIBUSB_RECIPIENT_DEVICE | usb.LIBUSB_ENDPOINT_IN,
TRANSFER_SIZE = 4096,
POST_MESSAGE = {},
CONTROL_TRANSFER = {},
TAG_METHOD_MAP = {};
// Init constant map
TAG_METHOD_MAP[Connection.TAG_KILL] = { method: CONTROL_TRANSFER, direction: VENDOR_REQ_OUT };
TAG_METHOD_MAP[Connection.TAG_FLASH] = { method: POST_MESSAGE };
TAG_METHOD_MAP[Connection.TAG_RUN] = { method: POST_MESSAGE };
*/
var // External dependencies
usb = require('usb'),
Promise = require('es6-promise').Promise,
// Local dependencies
Connection = require('../connection/Connection'),
AbstractTransport = require('./AbstractTransport'),
// Constannts
TESSEL_VID = 0x1d50,
TESSEL_PID = 0x6097,
VENDOR_REQ_OUT = usb.LIBUSB_REQUEST_TYPE_VENDOR | usb.LIBUSB_RECIPIENT_DEVICE | usb.LIBUSB_ENDPOINT_OUT,
VENDOR_REQ_IN = usb.LIBUSB_REQUEST_TYPE_VENDOR | usb.LIBUSB_RECIPIENT_DEVICE | usb.LIBUSB_ENDPOINT_IN,
TRANSFER_SIZE = 4096,
POST_MESSAGE = {},
CONTROL_TRANSFER = {},
TAG_METHOD_MAP = {};
// Init constant map
TAG_METHOD_MAP[Connection.TAG_KILL] = { method: CONTROL_TRANSFER, direction: VENDOR_REQ_OUT };
TAG_METHOD_MAP[Connection.TAG_FLASH] = { method: POST_MESSAGE };
TAG_METHOD_MAP[Connection.TAG_RUN] = { method: POST_MESSAGE };
return new Promise((resolve, reject) => {
let requestType = 0;
let lengthOrData = ti.length ? ti.length : Buffer.from(ti.data);
if (ti.requestType === 'vendor') {
requestType |= usb.LIBUSB_REQUEST_TYPE_VENDOR;
}
if (ti.recipient === 'device') {
requestType |= usb.LIBUSB_RECIPIENT_DEVICE;
}
if (ti.direction === 'out') {
requestType |= usb.LIBUSB_ENDPOINT_OUT;
} else if (ti.direction === 'in') {
requestType |= usb.LIBUSB_ENDPOINT_IN;
}
this._device.controlTransfer(requestType, ti.request, ti.value, ti.index, lengthOrData, (err, data) => {
if (err) {
return reject(err);
}
if (data) {
return resolve(Uint8Array.from(data).buffer);
}