Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 78 additions & 64 deletions storage/umass/umass.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@
}


static int _umass_scsiInit(umass_dev_t *dev)

Check warning on line 357 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt117x-evk)

'_umass_scsiInit' defined but not used [-Wunused-function]

Check warning on line 357 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt106x-evk)

'_umass_scsiInit' defined but not used [-Wunused-function]

Check warning on line 357 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-pc)

'_umass_scsiInit' defined but not used [-Wunused-function]

Check warning on line 357 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-qemu)

'_umass_scsiInit' defined but not used [-Wunused-function]

Check warning on line 357 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a7-imx6ull-evk)

'_umass_scsiInit' defined but not used [-Wunused-function]
{
int ret;
int i, ok;
Expand Down Expand Up @@ -390,7 +390,7 @@
}


static int _umass_check(umass_dev_t *dev)

Check warning on line 393 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt117x-evk)

'_umass_check' defined but not used [-Wunused-function]

Check warning on line 393 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt106x-evk)

'_umass_check' defined but not used [-Wunused-function]

Check warning on line 393 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-pc)

'_umass_check' defined but not used [-Wunused-function]

Check warning on line 393 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-qemu)

'_umass_check' defined but not used [-Wunused-function]

Check warning on line 393 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a7-imx6ull-evk)

'_umass_check' defined but not used [-Wunused-function]
{
scsi_cdb10_t readcmd = {
.opcode = 0x28,
Expand Down Expand Up @@ -748,7 +748,15 @@
}


static umass_dev_t *umass_devAlloc(void)
static void _umass_devFree(umass_dev_t *dev)
{
idtree_remove(&umass_common.devices, &dev->node);
resourceDestroy(dev->lock);
free(dev);
}


static umass_dev_t *_umass_devAlloc(void)

Check warning on line 759 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt117x-evk)

'_umass_devAlloc' defined but not used [-Wunused-function]

Check warning on line 759 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt106x-evk)

'_umass_devAlloc' defined but not used [-Wunused-function]

Check warning on line 759 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-pc)

'_umass_devAlloc' defined but not used [-Wunused-function]

Check warning on line 759 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-qemu)

'_umass_devAlloc' defined but not used [-Wunused-function]

Check warning on line 759 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a7-imx6ull-evk)

'_umass_devAlloc' defined but not used [-Wunused-function]
{
umass_dev_t *dev;
int rv;
Expand All @@ -769,9 +777,8 @@
dev->fileId = idtree_id(&dev->node);

rv = snprintf(dev->path, sizeof(dev->path), "/dev/umass%d", dev->fileId);
if (rv < 0) {
resourceDestroy(dev->lock);
free(dev);
if (rv < 0 || rv >= sizeof(dev->path)) {
_umass_devFree(dev);
return NULL;
}

Expand All @@ -779,7 +786,7 @@
}


static int umass_mountRoot(umass_dev_t *dev)

Check warning on line 789 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt117x-evk)

'umass_mountRoot' defined but not used [-Wunused-function]

Check warning on line 789 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt106x-evk)

'umass_mountRoot' defined but not used [-Wunused-function]

Check warning on line 789 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-pc)

'umass_mountRoot' defined but not used [-Wunused-function]

Check warning on line 789 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-qemu)

'umass_mountRoot' defined but not used [-Wunused-function]

Check warning on line 789 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a7-imx6ull-evk)

'umass_mountRoot' defined but not used [-Wunused-function]
{
#ifdef UMASS_MOUNT_EXT2
int err;
Expand All @@ -802,81 +809,89 @@
}


static int umass_handleInsertion(usb_driver_t *drv, usb_devinfo_t *insertion)
static int umass_handleInsertion(usb_driver_t *drv, usb_devinfo_t *insertion, usb_event_insertion_t *event)

Check failure on line 812 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt117x-evk)

unknown type name 'usb_event_insertion_t'

Check failure on line 812 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt106x-evk)

unknown type name 'usb_event_insertion_t'

Check failure on line 812 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-pc)

unknown type name 'usb_event_insertion_t'

Check failure on line 812 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-qemu)

unknown type name 'usb_event_insertion_t'

Check failure on line 812 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a7-imx6ull-evk)

unknown type name 'usb_event_insertion_t'
{
int err;
umass_dev_t *dev;
oid_t oid;
int ret;

fprintf(stderr, "umass: pending insertion\n");

mutexLock(umass_common.lock);

if ((dev = umass_devAlloc()) == NULL) {
fprintf(stderr, "umass: devAlloc failed\n");
return -ENOMEM;
}
do {
dev = _umass_devAlloc();
if (dev == NULL) {
fprintf(stderr, "umass: devAlloc failed\n");
err = -ENOMEM;
break;
}

dev->drv = drv;
dev->instance = *insertion;
dev->pipeCtrl = usb_open(drv, insertion, usb_transfer_control, 0);
if (dev->pipeCtrl < 0) {
free(dev);
fprintf(stderr, "umass: usb_open failed\n");
return -EINVAL;
}
dev->drv = drv;
dev->instance = *insertion;
dev->pipeCtrl = usb_open(drv, insertion, usb_transfer_control, 0);
if (dev->pipeCtrl < 0) {
fprintf(stderr, "umass: usb_open failed\n");
_umass_devFree(dev);
err = -EINVAL;
break;
}

err = usb_setConfiguration(drv, dev->pipeCtrl, 1);
if (err != 0) {
free(dev);
fprintf(stderr, "umass: setConfiguration failed\n");
return -EINVAL;
}
err = usb_setConfiguration(drv, dev->pipeCtrl, 1);
if (err != 0) {
fprintf(stderr, "umass: setConfiguration failed\n");
_umass_devFree(dev);
break;
}

dev->pipeIn = usb_open(drv, insertion, usb_transfer_bulk, usb_dir_in);
if (dev->pipeIn < 0) {
fprintf(stderr, "umass: pipe open failed \n");
free(dev);
return -EINVAL;
}
dev->pipeIn = usb_open(drv, insertion, usb_transfer_bulk, usb_dir_in);
if (dev->pipeIn < 0) {
fprintf(stderr, "umass: pipe open failed \n");
_umass_devFree(dev);
err = -EINVAL;
break;
}

dev->pipeOut = usb_open(drv, insertion, usb_transfer_bulk, usb_dir_out);
if (dev->pipeOut < 0) {
fprintf(stderr, "umass: pipe open failed\n");
free(dev);
return -EINVAL;
}
dev->tag = 0;
dev->pipeOut = usb_open(drv, insertion, usb_transfer_bulk, usb_dir_out);
if (dev->pipeOut < 0) {
fprintf(stderr, "umass: pipe open failed\n");
_umass_devFree(dev);
err = -EINVAL;
break;
}
dev->tag = 0;

ret = _umass_scsiInit(dev);
if (ret < 0) {
fprintf(stderr, "umass: device didn't initialize properly after scsi init sequence\n");
free(dev);
return -EINVAL;
}
err = _umass_scsiInit(dev);
if (err < 0) {
fprintf(stderr, "umass: device didn't initialize properly after scsi init sequence\n");
_umass_devFree(dev);
break;
}

ret = _umass_check(dev);
if (ret < 0) {
fprintf(stderr, "umass: umass_check failed\n");
free(dev);
return -EINVAL;
}
err = _umass_check(dev);
if (err < 0) {
fprintf(stderr, "umass: umass_check failed\n");
_umass_devFree(dev);
break;
}

oid.port = umass_common.msgport;
oid.id = dev->fileId;
err = create_dev(&oid, dev->path);
if (err != 0) {
free(dev);
fprintf(stderr, "usb: Can't create dev!\n");
return -EINVAL;
}
oid.port = umass_common.msgport;
oid.id = dev->fileId;
err = create_dev(&oid, dev->path);
if (err != 0) {
fprintf(stderr, "usb: Can't create dev!\n");
_umass_devFree(dev);
break;
}

printf("umass: New USB Mass Storage device: %s sectors: %d\n", dev->path, dev->part.sectors);
printf("umass: New USB Mass Storage device: %s sectors: %d\n", dev->path, dev->part.sectors);

event->deviceCreated = true;
event->dev = oid;
strncpy(event->devPath, dev->path, sizeof(event->devPath));
} while (0);

mutexUnlock(umass_common.lock);

if (umass_common.mount_root) {
if (err == 0 && umass_common.mount_root) {
err = umass_mountRoot(dev);
if (err < 0) {
fprintf(stderr, "umass: failed to mount root partition\n");
Expand All @@ -885,7 +900,7 @@
umass_common.mount_root = false; /* don't try to mount root again */
}

return 0;
return err;
}


Expand All @@ -903,10 +918,9 @@
dev = lib_treeof(umass_dev_t, node, lib_treeof(idnode_t, linkage, node));
if (dev->instance.bus == del->bus && dev->instance.dev == del->dev &&
dev->instance.interface == del->interface) {
resourceDestroy(dev->lock);
remove(dev->path);
fprintf(stderr, "umass: Device removed: %s\n", dev->path);
free(dev);
_umass_devFree(dev);
}

node = next;
Expand Down Expand Up @@ -1009,7 +1023,7 @@
static usb_driver_t umass_driver = {
.name = "umass",
.handlers = {
.insertion = umass_handleInsertion,

Check failure on line 1026 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt117x-evk)

'umass_handleInsertion' undeclared here (not in a function); did you mean 'umass_handleDeletion'?

Check failure on line 1026 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt106x-evk)

'umass_handleInsertion' undeclared here (not in a function); did you mean 'umass_handleDeletion'?

Check failure on line 1026 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-pc)

'umass_handleInsertion' undeclared here (not in a function); did you mean 'umass_handleDeletion'?

Check failure on line 1026 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (ia32-generic-qemu)

'umass_handleInsertion' undeclared here (not in a function); did you mean 'umass_handleDeletion'?

Check failure on line 1026 in storage/umass/umass.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7a7-imx6ull-evk)

'umass_handleInsertion' undeclared here (not in a function); did you mean 'umass_handleDeletion'?
.deletion = umass_handleDeletion,
.completion = umass_handleCompletion,
},
Expand Down
40 changes: 38 additions & 2 deletions tty/usbacm/usbacm.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
#define USBACM_UMSG_PRIO 3
#endif

#ifndef USBACM_SET_LINE_DEFAULT_RATE
#define USBACM_SET_LINE_DEFAULT_RATE 57600
#endif

#define USBACM_BULK_SZ 2048

/* clang-format off */
Expand Down Expand Up @@ -91,6 +95,8 @@
int rxState;

usb_driver_t *drv;

usb_cdc_line_coding_t line;
} usbacm_dev_t;


Expand All @@ -117,7 +123,7 @@
};


static const usb_modeswitch_t modeswitch[] = {

Check warning on line 126 in tty/usbacm/usbacm.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt117x-evk)

'modeswitch' defined but not used [-Wunused-const-variable=]

Check warning on line 126 in tty/usbacm/usbacm.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt106x-evk)

'modeswitch' defined but not used [-Wunused-const-variable=]
/* Huawei E3372 ACM mode */
{
.vid = 0x12d1,
Expand Down Expand Up @@ -257,6 +263,20 @@
}


static int usbacm_setLine(usbacm_dev_t *dev)

Check warning on line 266 in tty/usbacm/usbacm.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt117x-evk)

'usbacm_setLine' defined but not used [-Wunused-function]

Check warning on line 266 in tty/usbacm/usbacm.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt106x-evk)

'usbacm_setLine' defined but not used [-Wunused-function]
{
usb_setup_packet_t setup = {
.bmRequestType = REQUEST_DIR_HOST2DEV | REQUEST_TYPE_CLASS | REQUEST_RECIPIENT_INTERFACE,
.bRequest = 0x20, /* SET_LINE_CODING */
.wValue = 0,
.wIndex = 0,
.wLength = sizeof(usb_cdc_line_coding_t),
};

return usb_transferControl(dev->drv, dev->pipeCtrl, &setup, &dev->line, sizeof(usb_cdc_line_coding_t), usb_dir_out);
}


static int usbacm_handleCompletion(usb_driver_t *drv, usb_completion_t *c, const char *data, size_t len)
{
usbacm_dev_t *dev;
Expand Down Expand Up @@ -412,7 +432,7 @@
}


static usbacm_dev_t *usbacm_devAlloc(void)

Check warning on line 435 in tty/usbacm/usbacm.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt117x-evk)

'usbacm_devAlloc' defined but not used [-Wunused-function]

Check warning on line 435 in tty/usbacm/usbacm.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt106x-evk)

'usbacm_devAlloc' defined but not used [-Wunused-function]
{
usbacm_dev_t *dev;

Expand Down Expand Up @@ -639,7 +659,7 @@
}


static int usbacm_handleInsertion(usb_driver_t *drv, usb_devinfo_t *insertion)
static int usbacm_handleInsertion(usb_driver_t *drv, usb_devinfo_t *insertion, usb_event_insertion_t *event)

Check failure on line 662 in tty/usbacm/usbacm.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt117x-evk)

unknown type name 'usb_event_insertion_t'

Check failure on line 662 in tty/usbacm/usbacm.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt106x-evk)

unknown type name 'usb_event_insertion_t'
{
usbacm_dev_t *dev;
const usb_modeswitch_t *mode;
Expand Down Expand Up @@ -697,13 +717,25 @@
break;
}

condCreate(&dev->rxCond);
err = condCreate(&dev->rxCond);
if (err != 0) {
resourceDestroy(dev->rxLock);
err = -ENOMEM;
break;
}

dev->line.dwDTERate = USBACM_SET_LINE_DEFAULT_RATE;
dev->line.bCharFormat = 0;
dev->line.bParityType = 0;
dev->line.bDataBits = 8;

/* Some broken devices won't function without doing the set line cmd first */
err = usbacm_setLine(dev);
if (err < 0) {
fprintf(stderr, "usbacm: Set line to speed %d failed/unsupported: %d\n", dev->line.dwDTERate, err);
/* Continue as this is optional: device may reject the setting/not support the set line cmd */
}

oid.port = usbacm_common.msgport;
oid.id = dev->fileId;

Expand All @@ -728,6 +760,10 @@

fprintf(stdout, "usbacm: New device: %s\n", dev->path);

event->deviceCreated = true;
event->dev = oid;
strncpy(event->devPath, dev->path, sizeof(event->devPath));

return 0;
}

Expand Down Expand Up @@ -822,7 +858,7 @@
static usb_driver_t usbacm_driver = {
.name = "usbacm",
.handlers = {
.insertion = usbacm_handleInsertion,

Check failure on line 861 in tty/usbacm/usbacm.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt117x-evk)

'usbacm_handleInsertion' undeclared here (not in a function); did you mean 'usbacm_handleDeletion'?

Check failure on line 861 in tty/usbacm/usbacm.c

View workflow job for this annotation

GitHub Actions / call-ci / build (armv7m7-imxrt106x-evk)

'usbacm_handleInsertion' undeclared here (not in a function); did you mean 'usbacm_handleDeletion'?
.deletion = usbacm_handleDeletion,
.completion = usbacm_handleCompletion,
},
Expand Down
Loading