From 1703c70fd5df3fd45a2dfe302147140b15b4574a Mon Sep 17 00:00:00 2001 From: David Lin Date: Wed, 10 Jun 2020 12:53:51 +0800 Subject: [ drivers/usb]Fixed a bug may cause stackover flow --- components/drivers/usb/usbhost/core/usbhost_core.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'components') diff --git a/components/drivers/usb/usbhost/core/usbhost_core.c b/components/drivers/usb/usbhost/core/usbhost_core.c index 71341a33c3..d72dca82f2 100644 --- a/components/drivers/usb/usbhost/core/usbhost_core.c +++ b/components/drivers/usb/usbhost/core/usbhost_core.c @@ -162,6 +162,10 @@ rt_err_t rt_usbh_attatch_instance(uinst_t device) /* alloc memory for configuration descriptor */ device->cfg_desc = (ucfg_desc_t)rt_malloc(cfg_desc.wTotalLength); + if(device->cfg_desc == RT_NULL) + { + return RT_ENOMEM; + } rt_memset(device->cfg_desc, 0, cfg_desc.wTotalLength); /* get full configuration descriptor */ @@ -219,6 +223,10 @@ rt_err_t rt_usbh_attatch_instance(uinst_t device) { /* allocate memory for interface device */ device->intf[i] = (struct uhintf*)rt_malloc(sizeof(struct uhintf)); + if(device->intf[i] == RT_NULL) + { + return RT_ENOMEM; + } device->intf[i]->drv = drv; device->intf[i]->device = device; device->intf[i]->intf_desc = intf_desc; -- cgit v1.3.1 From 6cafbf07ce76d55e67c64341e8f88c6ecf3af8ab Mon Sep 17 00:00:00 2001 From: hphuang Date: Mon, 22 Jun 2020 15:25:29 +0800 Subject: mstorage.c: fix bug in device descriptor that MAC OS enumeration failed. --- components/drivers/usb/usbdevice/class/mstorage.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'components') diff --git a/components/drivers/usb/usbdevice/class/mstorage.c b/components/drivers/usb/usbdevice/class/mstorage.c index a681b8212f..f0cd0b20fb 100644 --- a/components/drivers/usb/usbdevice/class/mstorage.c +++ b/components/drivers/usb/usbdevice/class/mstorage.c @@ -78,9 +78,9 @@ static struct udevice_descriptor dev_desc = USB_DESC_LENGTH_DEVICE, //bLength; USB_DESC_TYPE_DEVICE, //type; USB_BCD_VERSION, //bcdUSB; - USB_CLASS_MASS_STORAGE, //bDeviceClass; - 0x06, //bDeviceSubClass; - 0x50, //bDeviceProtocol; + 0x00, //bDeviceClass; + 0x00, //bDeviceSubClass; + 0x00, //bDeviceProtocol; 0x40, //bMaxPacketSize0; _VENDOR_ID, //idVendor; _PRODUCT_ID, //idProduct; @@ -98,9 +98,9 @@ static struct usb_qualifier_descriptor dev_qualifier = sizeof(dev_qualifier), //bLength USB_DESC_TYPE_DEVICEQUALIFIER, //bDescriptorType 0x0200, //bcdUSB - USB_CLASS_MASS_STORAGE, //bDeviceClass - 0x06, //bDeviceSubClass - 0x50, //bDeviceProtocol + 0x00, //bDeviceClass + 0x00, //bDeviceSubClass + 0x00, //bDeviceProtocol 64, //bMaxPacketSize0 0x01, //bNumConfigurations 0, -- cgit v1.3.1 From 0bfb881168c0c69d8d5903391c0a16d13e393ec8 Mon Sep 17 00:00:00 2001 From: hphuang Date: Fri, 3 Jul 2020 11:13:24 +0800 Subject: merge latest usb class with workaround --- components/drivers/usb/usbdevice/class/cdc_vcom.c | 5 +-- components/drivers/usb/usbdevice/class/hid.c | 18 ++++++----- components/drivers/usb/usbdevice/class/mstorage.c | 38 ++++++++++++++++------- 3 files changed, 40 insertions(+), 21 deletions(-) (limited to 'components') diff --git a/components/drivers/usb/usbdevice/class/cdc_vcom.c b/components/drivers/usb/usbdevice/class/cdc_vcom.c index c4fc3b0ad9..64230533ae 100644 --- a/components/drivers/usb/usbdevice/class/cdc_vcom.c +++ b/components/drivers/usb/usbdevice/class/cdc_vcom.c @@ -589,8 +589,9 @@ ufunction_t rt_usbd_function_cdc_create(udevice_t device) /* create a cdc function */ func = rt_usbd_function_new(device, &dev_desc, &ops); - //not support HS - //rt_usbd_device_set_qualifier(device, &dev_qualifier); + + /* support HS */ + rt_usbd_device_set_qualifier(device, &dev_qualifier); /* allocate memory for cdc vcom data */ data = (struct vcom*)rt_malloc(sizeof(struct vcom)); diff --git a/components/drivers/usb/usbdevice/class/hid.c b/components/drivers/usb/usbdevice/class/hid.c index 5df63daddf..a4acce75ea 100644 --- a/components/drivers/usb/usbdevice/class/hid.c +++ b/components/drivers/usb/usbdevice/class/hid.c @@ -29,7 +29,7 @@ struct hid_s uep_t ep_in; uep_t ep_out; int status; - rt_uint16_t protocol; + rt_uint8_t protocol; rt_uint8_t report_buf[MAX_REPORT_SIZE]; struct rt_messagequeue hid_mq; }; @@ -246,7 +246,7 @@ static struct udevice_descriptor _dev_desc = USB_DESC_LENGTH_DEVICE, //bLength; USB_DESC_TYPE_DEVICE, //type; USB_BCD_VERSION, //bcdUSB; - USB_CLASS_HID, //bDeviceClass; + 0x0, //bDeviceClass; 0x00, //bDeviceSubClass; 0x00, //bDeviceProtocol; 64, //bMaxPacketSize0; @@ -266,8 +266,8 @@ static struct usb_qualifier_descriptor dev_qualifier = sizeof(dev_qualifier), //bLength USB_DESC_TYPE_DEVICEQUALIFIER, //bDescriptorType 0x0200, //bcdUSB - USB_CLASS_MASS_STORAGE, //bDeviceClass - 0x06, //bDeviceSubClass + 0x0, //bDeviceClass + 0x0, //bDeviceSubClass 0x50, //bDeviceProtocol 64, //bMaxPacketSize0 0x01, //bNumConfigurations @@ -347,7 +347,7 @@ const static struct uhid_comm_descriptor _hid_comm_desc = USB_DYNAMIC | USB_DIR_IN, USB_EP_ATTR_INT, 0x40, - 0x01, + 0x0A, }, /* Endpoint Descriptor OUT */ @@ -458,6 +458,7 @@ static rt_err_t _interface_handler(ufunction_t func, ureq_t setup) struct hid_s *data = (struct hid_s *) func->user_data; + switch (setup->bRequest) { case USB_REQ_GET_DESCRIPTOR: @@ -486,7 +487,7 @@ static rt_err_t _interface_handler(ufunction_t func, ureq_t setup) dcd_ep0_send_status(func->device->dcd); break; case USB_HID_REQ_GET_PROTOCOL: - rt_usbd_ep0_write(func->device, &data->protocol,2); + rt_usbd_ep0_write(func->device, &data->protocol,1); break; case USB_HID_REQ_SET_REPORT: @@ -692,8 +693,9 @@ ufunction_t rt_usbd_function_hid_create(udevice_t device) /* create a cdc function */ func = rt_usbd_function_new(device, &_dev_desc, &ops); - //not support hs - //rt_usbd_device_set_qualifier(device, &_dev_qualifier); + + /* For high speed mode supporting */ + rt_usbd_device_set_qualifier(device, &dev_qualifier); /* allocate memory for cdc vcom data */ data = (struct hid_s*)rt_malloc(sizeof(struct hid_s)); diff --git a/components/drivers/usb/usbdevice/class/mstorage.c b/components/drivers/usb/usbdevice/class/mstorage.c index f0cd0b20fb..d0a2b7f736 100644 --- a/components/drivers/usb/usbdevice/class/mstorage.c +++ b/components/drivers/usb/usbdevice/class/mstorage.c @@ -78,9 +78,9 @@ static struct udevice_descriptor dev_desc = USB_DESC_LENGTH_DEVICE, //bLength; USB_DESC_TYPE_DEVICE, //type; USB_BCD_VERSION, //bcdUSB; - 0x00, //bDeviceClass; - 0x00, //bDeviceSubClass; - 0x00, //bDeviceProtocol; + USB_CLASS_MASS_STORAGE, //bDeviceClass; + 0x06, //bDeviceSubClass; + 0x50, //bDeviceProtocol; 0x40, //bMaxPacketSize0; _VENDOR_ID, //idVendor; _PRODUCT_ID, //idProduct; @@ -98,9 +98,9 @@ static struct usb_qualifier_descriptor dev_qualifier = sizeof(dev_qualifier), //bLength USB_DESC_TYPE_DEVICEQUALIFIER, //bDescriptorType 0x0200, //bcdUSB - 0x00, //bDeviceClass - 0x00, //bDeviceSubClass - 0x00, //bDeviceProtocol + USB_CLASS_MASS_STORAGE, //bDeviceClass + 0x06, //bDeviceSubClass + 0x50, //bDeviceProtocol 64, //bMaxPacketSize0 0x01, //bNumConfigurations 0, @@ -610,8 +610,11 @@ static rt_err_t _ep_in_handler(ufunction_t func, rt_size_t size) rt_usbd_ep_set_stall(func->device, data->ep_out); } else - { - rt_usbd_ep_set_stall(func->device, data->ep_in); + { + //rt_kprintf("warning:in stall path but not stall\n"); + + /* FIXME: Disable the operation or the disk cannot work. */ + //rt_usbd_ep_set_stall(func->device, data->ep_in); } data->csw_response.data_reside = 0; } @@ -719,9 +722,22 @@ static void _cb_len_calc(ufunction_t func, struct scsi_cmd* cmd, break; } } + + //workaround: for stability in full-speed mode + else if(cmd->cmd_len == 12) + { + switch(cmd->type) + { + case COUNT: + data->cb_data_size = cbw->cb[4]; + break; + default: + break; + } + } else { -// rt_kprintf("cmd_len error %d\n", cmd->cmd_len); + rt_kprintf("cmd_len error %d\n", cmd->cmd_len); } } @@ -737,7 +753,7 @@ static rt_bool_t _cbw_verify(ufunction_t func, struct scsi_cmd* cmd, data = (struct mstorage*)func->user_data; if(cmd->cmd_len != cbw->cb_len) { - // rt_kprintf("cb_len error\n"); + rt_kprintf("cb_len error\n"); cmd->cmd_len = cbw->cb_len; } @@ -768,7 +784,7 @@ static rt_bool_t _cbw_verify(ufunction_t func, struct scsi_cmd* cmd, if(cbw->xfer_len < data->cb_data_size) { - // rt_kprintf("xfer_len < data_size\n"); + rt_kprintf("xfer_len < data_size\n"); data->cb_data_size = cbw->xfer_len; data->csw_response.status = 1; } -- cgit v1.3.1 From 50dc41468ef69b6b79979772f9689d8d3099df30 Mon Sep 17 00:00:00 2001 From: tangyuxin <462747508@qq.com> Date: Sat, 26 Sep 2020 09:55:58 +0800 Subject: [add] DFS file system supports device types --- components/dfs/filesystems/devfs/devfs.c | 2 ++ components/dfs/include/dfs.h | 1 + components/dfs/src/dfs.c | 1 + 3 files changed, 4 insertions(+) (limited to 'components') diff --git a/components/dfs/filesystems/devfs/devfs.c b/components/dfs/filesystems/devfs/devfs.c index 936b074ce1..7637074dbb 100644 --- a/components/dfs/filesystems/devfs/devfs.c +++ b/components/dfs/filesystems/devfs/devfs.c @@ -186,6 +186,7 @@ int dfs_device_fs_open(struct dfs_fd *file) result = file->fops->open(file); if (result == RT_EOK || result == -RT_ENOSYS) { + file->type = FT_DEVICE; return 0; } } @@ -197,6 +198,7 @@ int dfs_device_fs_open(struct dfs_fd *file) if (result == RT_EOK || result == -RT_ENOSYS) { file->data = device; + file->type = FT_DEVICE; return RT_EOK; } } diff --git a/components/dfs/include/dfs.h b/components/dfs/include/dfs.h index eb32a4b411..1158df93cb 100644 --- a/components/dfs/include/dfs.h +++ b/components/dfs/include/dfs.h @@ -55,6 +55,7 @@ #define FT_SOCKET 1 /* socket file */ #define FT_DIRECTORY 2 /* directory */ #define FT_USER 3 /* user defined */ +#define FT_DEVICE 4 /* device */ /* File flags */ #define DFS_F_OPEN 0x01000000 diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index b20de13988..7ace0bc160 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -542,6 +542,7 @@ int list_fd(void) else if (fd->type == FT_REGULAR) rt_kprintf("%-7.7s ", "file"); else if (fd->type == FT_SOCKET) rt_kprintf("%-7.7s ", "socket"); else if (fd->type == FT_USER) rt_kprintf("%-7.7s ", "user"); + else if (fd->type == FT_DEVICE) rt_kprintf("%-7.7s ", "device"); else rt_kprintf("%-8.8s ", "unknown"); rt_kprintf("%3d ", fd->ref_count); rt_kprintf("%04x ", fd->magic); -- cgit v1.3.1 From 8861202c3b0a74d5e4d73176c38518a5418b2019 Mon Sep 17 00:00:00 2001 From: tangyuxin <462747508@qq.com> Date: Sat, 26 Sep 2020 12:30:39 +0800 Subject: [dfs] fix the DEVICE could not get or set flags --- components/dfs/src/dfs_file.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'components') diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index 91d39597f0..fd205f2f3a 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -157,7 +157,7 @@ int dfs_file_ioctl(struct dfs_fd *fd, int cmd, void *args) return -EINVAL; /* regular file system fd */ - if (fd->type == FT_REGULAR) + if (fd->type == FT_REGULAR || fd->type == FT_DEVICE) { switch (cmd) { -- cgit v1.3.1