diff --git a/common/include/usbhdfsd-common.h b/common/include/usbhdfsd-common.h index d644a3e6d8f..a066e12dfdd 100644 --- a/common/include/usbhdfsd-common.h +++ b/common/include/usbhdfsd-common.h @@ -22,6 +22,7 @@ typedef struct bd_fragment { u32 count; /// number of sector in this fragment } __attribute__((packed)) bd_fragment_t; + // IOCTL function codes /** Rename opened file. Data input to ioctl() -> new, full filename of file. */ #define USBMASS_IOCTL_RENAME 0x0000 @@ -37,6 +38,8 @@ typedef struct bd_fragment { #define USBMASS_IOCTL_GET_FRAGLIST 0x0005 /** Get the device number for the block device backing the mass partition */ #define USBMASS_IOCTL_GET_DEVICE_NUMBER 0x0006 +/** Get the physical USB port number where device is connected. 00 = Root Hub, 01=Rightmost port, 02=Leftmost Port */ +#define USBMASS_IOCTL_GET_USB_DEVICE_PORT_NUMBER 0x0007 // DEVCTL function codes /** Issues the SCSI STOP UNIT command to the specified device. Use this to shut down devices properly. */ diff --git a/iop/fs/bdmfs_fatfs/src/fs_driver.c b/iop/fs/bdmfs_fatfs/src/fs_driver.c index 8c5efe60796..b72ff19af8b 100644 --- a/iop/fs/bdmfs_fatfs/src/fs_driver.c +++ b/iop/fs/bdmfs_fatfs/src/fs_driver.c @@ -706,6 +706,28 @@ int fs_ioctl2(iop_file_t *fd, int cmd, void *data, unsigned int datalen, void *r *(u32*)rdata = bd->devNr; ret = 0; } + break; + case USBMASS_IOCTL_GET_USB_DEVICE_PORT_NUMBER: + struct block_device* bdu = fatfs_fs_driver_get_mounted_bd_from_index(file->obj.fs->pdrv); + + ret = -ENXIO; + + if(bdu && (strncmp(bdu->name, "mass", 4) == 0)) { + struct scsi_interface *scsi = (struct scsi_interface *)bdu->priv; + if (scsi) { + mass_dev *dev = (mass_dev *)scsi->priv; + if(dev) { + /* + <0 = Invalid + 00 = Root Hub, + 01 = Rightmost port, + 02 = Leftmost Port + */ + ret = dev->usbPortNumber; + } + } + } + break; } default: diff --git a/iop/fs/bdmfs_fatfs/src/imports.lst b/iop/fs/bdmfs_fatfs/src/imports.lst index 1d6c77ad1d7..1f9d4128e49 100644 --- a/iop/fs/bdmfs_fatfs/src/imports.lst +++ b/iop/fs/bdmfs_fatfs/src/imports.lst @@ -28,6 +28,7 @@ I_memcmp I_memcpy I_strlen I_strcmp +I_strncmp I_strcpy I_strncpy I_strtol diff --git a/iop/fs/bdmfs_fatfs/src/include/fs_driver.h b/iop/fs/bdmfs_fatfs/src/include/fs_driver.h index 8eacbcfc8cc..89e7b7e51fe 100644 --- a/iop/fs/bdmfs_fatfs/src/include/fs_driver.h +++ b/iop/fs/bdmfs_fatfs/src/include/fs_driver.h @@ -4,6 +4,31 @@ #include #include "ff.h" +struct scsi_interface +{ + void *priv; + char *name; + unsigned int max_sectors; + + int (*get_max_lun)(struct scsi_interface *scsi); + int (*queue_cmd)(struct scsi_interface *scsi, const unsigned char *cmd, unsigned int cmd_len, unsigned char *data, unsigned int data_len, unsigned int data_wr); +}; + +typedef struct _mass_dev +{ + int controlEp; // config endpoint id + int bulkEpI; // in endpoint id + int bulkEpO; // out endpoint id + int devId; // device id + unsigned char configId; // configuration id + unsigned char status; + unsigned char interfaceNumber; // interface number + unsigned char interfaceAlt; // interface alternate setting + int usbPortNumber; //physical port number the USB device is connected to + int ioSema; + struct scsi_interface scsi; +} mass_dev; + typedef struct fatfs_fs_driver_mount_info_ { FATFS fatfs; diff --git a/iop/usb/usbmass_bd/src/imports.lst b/iop/usb/usbmass_bd/src/imports.lst index 3bc11e05f9b..1f1674d1736 100644 --- a/iop/usb/usbmass_bd/src/imports.lst +++ b/iop/usb/usbmass_bd/src/imports.lst @@ -36,4 +36,5 @@ I_sceUsbdClosePipe I_sceUsbdSetPrivateData I_sceUsbdTransferPipe I_sceUsbdRegisterLdd +I_sceUsbdGetDeviceLocation usbd_IMPORTS_end diff --git a/iop/usb/usbmass_bd/src/usb_mass.c b/iop/usb/usbmass_bd/src/usb_mass.c index a29a8bdd742..bf541dacdcd 100644 --- a/iop/usb/usbmass_bd/src/usb_mass.c +++ b/iop/usb/usbmass_bd/src/usb_mass.c @@ -47,6 +47,7 @@ typedef struct _mass_dev unsigned char status; unsigned char interfaceNumber; // interface number unsigned char interfaceAlt; // interface alternate setting + int usbPortNumber; //physical port number the USB device is connected to int ioSema; struct scsi_interface scsi; } mass_dev; @@ -613,6 +614,13 @@ static int usb_mass_probe(int devId) return 1; } +static void usb_get_port_number(int devId, mass_dev *dev) { + dev->usbPortNumber = -1; + u8 path[16]; + if(sceUsbdGetDeviceLocation(devId, path) == 0) + dev->usbPortNumber = path[0]; +} + static int usb_mass_connect(int devId) { int i; @@ -642,6 +650,8 @@ static int usb_mass_connect(int devId) dev->bulkEpI = -1; dev->bulkEpO = -1; + usb_get_port_number(devId, dev); + /* open the config endpoint */ dev->controlEp = sceUsbdOpenPipe(devId, NULL);