-
Notifications
You must be signed in to change notification settings - Fork 8
Usbd MSC windows minimum scsi implementation #47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alexrayne
wants to merge
7
commits into
insane-adding-machines:master
Choose a base branch
from
alexrayne:usbd-FRC
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9415f2d
*usbd:USBD_DEBUG - now accepts numeric verbosity level.
alexrayne 34e79c4
*usbd:USBD_LOG - continue migrate to USBD_LOG, make messages shorter
alexrayne e4e171b
*usbd:msc:backend:msc_lba_t - a bit fine code introduced typedef for …
alexrayne 187aa70
+usbd:msc:scsi:USB_MSC_SCSI_READ_FORMAT_CAPACITIES support - requred …
alexrayne a0691e9
*usbd:log - shorter messages
alexrayne de582cb
<usbd:log enhanses
alexrayne 9831aa0
!windows:msc - provided minimum api for msc requres <inquiry serial> …
alexrayne File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#ifndef _USB_BYTEORDER_H | ||
#define _USB_BYTEORDER_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#ifndef __LITTLE_ENDIAN_BITFIELD | ||
#define __LITTLE_ENDIAN_BITFIELD | ||
#endif | ||
|
||
#ifndef HTONS | ||
|
||
#include <stdint.h> | ||
static inline | ||
uint32_t usb_ntohl(uint32_t x){ | ||
return ((x)>> 24 & 0xff) | ||
| ((x)>>8 & 0xff00) | ||
| ((x)<<8 & 0xff0000L) | ||
| ((x)<<24 & 0xff000000L) | ||
; | ||
} | ||
|
||
static inline | ||
uint16_t usb_ntohs(uint16_t x){ | ||
return ((x)>>8 & 0xff) | ((x)<<8 & 0xff00); | ||
} | ||
|
||
static inline | ||
uint32_t usb_htonl(uint32_t x) { return usb_ntohl(x); }; | ||
|
||
static inline | ||
uint16_t usb_htons(uint16_t x) {return usb_ntohs(x); }; | ||
|
||
#define HTONS(x) usb_htons(x) | ||
#define HTONL(x) usb_htonl(x) | ||
#define NTOHS(x) usb_ntohs(x) | ||
#define NTOHL(x) usb_ntohl(x) | ||
|
||
#endif | ||
|
||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
/** @defgroup usb_msc_scsi_defines USB MSC SCSI API Definitions | ||
|
||
@brief <b>Defined Constants and Types for the USB MSC SCSI API Definitions</b> | ||
|
||
@ingroup USB_defines | ||
|
||
@version 1.0.0 | ||
|
||
@author @htmlonly © @endhtmlonly 2013 | ||
alexrayne <[email protected]> | ||
@date 30 ecember 2016 | ||
|
||
LGPL License Terms @ref lgpl_license | ||
*/ | ||
/* | ||
* Copyright (C) 2016 alexrayne <[email protected]> | ||
* | ||
* This library is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Lesser General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#ifndef UNICORE_USB_CLASS_MSC_SCSI_H | ||
#define UNICORE_USB_CLASS_MSC_SCSI_H | ||
|
||
#include <stdint.h> | ||
|
||
/* Implemented SCSI Commands */ | ||
#define USB_MSC_SCSI_TEST_UNIT_READY 0x00 | ||
#define USB_MSC_SCSI_REQUEST_SENSE 0x03 | ||
#define USB_MSC_SCSI_FORMAT_UNIT 0x04 | ||
#define USB_MSC_SCSI_READ_6 0x08 | ||
#define USB_MSC_SCSI_WRITE_6 0x0A | ||
#define USB_MSC_SCSI_INQUIRY 0x12 | ||
#define USB_MSC_SCSI_MODE_SENSE_6 0x1A | ||
#define USB_MSC_SCSI_SEND_DIAGNOSTIC 0x1D | ||
#define USB_MSC_SCSI_READ_FORMAT_CAPACITIES 0x23 | ||
#define USB_MSC_SCSI_READ_CAPACITY 0x25 | ||
#define USB_MSC_SCSI_READ_10 0x28 | ||
/* Required SCSI Commands */ | ||
|
||
/* Optional SCSI Commands */ | ||
#define USB_MSC_SCSI_REPORT_LUNS 0xA0 | ||
#define USB_MSC_SCSI_PREVENT_ALLOW_MEDIUM_REMOVAL 0x1E | ||
#define USB_MSC_SCSI_MODE_SELECT_6 0x15 | ||
#define USB_MSC_SCSI_MODE_SELECT_10 0x55 | ||
#define USB_MSC_SCSI_MODE_SENSE_10 0x5A | ||
#define USB_MSC_SCSI_READ_12 0xA8 | ||
#define USB_MSC_SCSI_READ_TOC_PMA_ATIP 0x43 | ||
#define USB_MSC_SCSI_START_STOP_UNIT 0x1B | ||
#define USB_MSC_SCSI_SYNCHRONIZE_CACHE 0x35 | ||
#define USB_MSC_SCSI_VERIFY 0x2F | ||
#define USB_MSC_SCSI_WRITE_10 0x2A | ||
#define USB_MSC_SCSI_WRITE_12 0xAA | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
//* structires uses net order (big_endian) | ||
typedef uint32_t net_u32_t; | ||
typedef uint16_t net_u16_t; | ||
typedef uint8_t net_u24_t[3]; | ||
|
||
static inline | ||
void u24_assign(net_u24_t dst, uint32_t x){ | ||
dst[2] = x & 0xff; | ||
x >>= 8; | ||
dst[1] = x & 0xff; | ||
x >>= 8; | ||
dst[0] = x & 0xff; | ||
}; | ||
|
||
static inline | ||
uint32_t u24_asul(net_u24_t x) | ||
{ | ||
uint32_t res = (x[0] << 8) | x[1]; | ||
res = (res << 8) | x[2]; | ||
return res; | ||
}; | ||
|
||
typedef enum{ | ||
scsi_vpd_Supported = 0 //* < Supported Vital Product Data pages | ||
, scsi_vpd_Serial = 0x80 //* < Unit Serial Number page | ||
, scsi_vpd_DevIdentification = 0x83 //* < Device Identification | ||
} scsi_VPD_page; | ||
|
||
//* SCSI - INQUIRY structures | ||
typedef struct { | ||
uint8_t op_code; | ||
uint8_t evpd; | ||
uint8_t page_code; //* \see scsi_VPD_page | ||
net_u16_t alloc_len; | ||
} __attribute__((packed)) usb_inquiry_cmd ; | ||
|
||
|
||
typedef enum { | ||
/** A peripheral device having the specified peripheral device type is connected to this logical unit. If the | ||
device server is unable to determine whether or not a peripheral device is connected, it also shall use | ||
this peripheral qualifier. This peripheral qualifier does not mean that the peripheral device connected | ||
to the logical unit is ready for access.*/ | ||
scsi_pqAvail = 0 | ||
/** A peripheral device having the specified peripheral device type is not connected to this logical unit. | ||
However, the device server is capable of supporting the specified peripheral device type on this logi- | ||
cal unit. */ | ||
, scsi_pqRemoved = 1 | ||
/** The device server is not capable of supporting a peripheral device on this logical unit. For this periph- | ||
eral qualifier the peripheral device type shall be set to 1Fh. All other peripheral device type values are | ||
reserved for this peripheral qualifier */ | ||
, scsi_pqNoSupport = 3 | ||
} scsi_periferial_qualify; | ||
|
||
typedef enum { | ||
scsi_dtDirectBlock = 0 //* < Direct access block device (e.g., magnetic disk) | ||
, scsi_dtSeqBlock = 1 //* < Sequential-access device (e.g., magnetic tape) | ||
, scsi_dtWriteOnce = 4 //* < Write-once device (e.g., some optical disks) | ||
, scsi_dtCDDVD = 5 //* < CD/DVD device | ||
, scsi_dtOptical = 7 //* <Optical memory device (e.g., some optical disks) | ||
, scsi_dtRAID = 0xc //* <Storage array controller device (e.g., RAID) | ||
, scsi_dtSimleDirect= 0xe //* <Simplified direct-access device (e.g., magnetic disk) | ||
} scsi_periferial_devtype; | ||
|
||
#define SCSI_DEVICE_CODE(type, qual) ( (((qual) & 0x7)<<5) | ((type) & 0x1f) ) | ||
|
||
typedef struct { | ||
uint8_t device_code; //* \see SCSI_DEVICE_CODE | ||
uint8_t page_code; //* \see scsi_VPD_page | ||
uint8_t page_len; | ||
} __attribute__((packed)) usb_inquiry_ack ; | ||
|
||
|
||
|
||
//* SCSI - READ FORMAT CAPACITIES structures | ||
typedef struct { | ||
net_u24_t dummy; | ||
uint8_t list_len; | ||
} __attribute__((packed)) usb_msc_rfc_capacity_list_header ; | ||
|
||
typedef enum { | ||
rfc_dc_Unfomatted = 1 //* < Unformatted Media - Maximum formattable capacity for this cartridge | ||
, rfc_dc_Fomatted = 2 //* < Formatted Media - Current media capacity | ||
, rfc_dc_NoMedia = 3 //* < No Cartridge in Drive - Maximum formattable capacity for any cartridge | ||
} usb_msc_rfc_capacity_descriptor_code; | ||
|
||
typedef struct { | ||
net_u32_t blocks_count; | ||
uint8_t code; //* < \see usb_msc_rfc_capacity_descriptor_code | ||
net_u24_t block_size; | ||
} __attribute__((packed)) usb_msc_rfc_capacity_descriptor; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif//UNICORE_USB_CLASS_MSC_SCSI_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,6 +46,10 @@ | |
#include <unicore-mx/usbd/usbd.h> | ||
#include <unicore-mx/usb/class/msc.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct usbd_msc usbd_msc; | ||
typedef struct usbd_msc_backend usbd_msc_backend; | ||
|
||
|
@@ -64,18 +68,28 @@ typedef struct usbd_msc_backend usbd_msc_backend; | |
* @param lock Lock. Optional - can be NULL | ||
* @param unlock Unlock. Optional - can be NULL | ||
*/ | ||
typedef uint32_t msc_lba_t; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Look ok to me but, Tab between "uint32_t" "msc_lba_t;" |
||
typedef unsigned msc_lun_t; | ||
|
||
struct usbd_msc_backend { | ||
const char *vendor_id; | ||
const char *product_id; | ||
const char *product_rev; | ||
uint32_t block_count; | ||
msc_lba_t block_count; | ||
int (*read_block)(const usbd_msc_backend *backend, | ||
uint32_t lba, void *copy_to); | ||
msc_lba_t lba, void *copy_to); | ||
int (*write_block)(const usbd_msc_backend *backend, | ||
uint32_t lba, const void *copy_from); | ||
msc_lba_t lba, const void *copy_from); | ||
int (*format_unit)(const usbd_msc_backend *backend); | ||
int (*lock)(void); | ||
int (*unlock)(void); | ||
msc_lba_t (*unit_blocks_count)(const usbd_msc_backend *self); | ||
int (*inquiry_page)(const usbd_msc_backend *self | ||
//, usb_inquiry_cmd* cmd | ||
, int vpd_page //* < \value -1 request standart iquiry page (EVPD=0) | ||
, unsigned alloc_limit //* < TODO limited by sector size now, due use MCS sector buffer as buf | ||
, void* buf //* < buffer for inquiry data fill to | ||
); | ||
}; | ||
|
||
usbd_msc *usbd_msc_init(usbd_device *dev, | ||
|
@@ -91,6 +105,36 @@ void usbd_msc_set_config(usbd_msc *ms, | |
|
||
void usbd_msc_start(usbd_msc *ms); | ||
|
||
static inline | ||
msc_lba_t usbd_msc_blocks(const usbd_msc_backend *u) | ||
{ | ||
if (u->unit_blocks_count != NULL) | ||
return (u->unit_blocks_count)(u); | ||
return u->block_count; | ||
} | ||
|
||
|
||
|
||
//* INQUIRY support routines. | ||
//* this resources linked as weak, and can be ovverriden in user code. | ||
int usbd_scsi_inquiry_page(const usbd_msc_backend *self | ||
//, usb_inquiry_cmd* cmd | ||
, int vpd_page //* < \value -1 request standart iquiry page (EVPD=0) | ||
, unsigned alloc_limit //* < TODO limited by sector size now, due use MCS sector buffer as buf | ||
, void* buf //* < buffer for inquiry data fill to | ||
); | ||
int usbd_scsi_inquiry_standart_page(const usbd_msc_backend *self, unsigned alloc_limit, void* buf); | ||
int usbd_scsi_inquiry_evpd_supports(const usbd_msc_backend *self, unsigned alloc_limit, void* buf); | ||
int usbd_scsi_inquiry_evpd_serial(const usbd_msc_backend *self, unsigned alloc_limit, void* buf); | ||
|
||
extern const uint8_t usbd_scsi_inquiry_evpd_supports_Data[]; | ||
extern const uint8_t usbd_scsi_inquiry_evpd_serial_Data[]; | ||
|
||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif | ||
|
||
/**@}*/ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor note: INAL, as of my understanding of copyright.
copyright name/year/email for Weston Schmidt and/or Pavol Rusnak need to be added because they authored the file from which some of the content you moved.