Skip to content
Open
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
55 changes: 42 additions & 13 deletions common/usbx_device_classes/inc/ux_device_class_storage.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
*
* Copyright (c) 2024 Microsoft Corporation
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
*
* SPDX-License-Identifier: MIT
**************************************************************************/

Expand Down Expand Up @@ -67,15 +67,15 @@
#ifndef UX_DEVICE_CLASS_STORAGE_H
#define UX_DEVICE_CLASS_STORAGE_H

/* Determine if a C++ compiler is being used. If so, ensure that standard
C is used to process the API information. */
/* Determine if a C++ compiler is being used. If so, ensure that standard
C is used to process the API information. */

#ifdef __cplusplus
#ifdef __cplusplus

/* Yes, C++ compiler is present. Use standard C. */
extern "C" {
/* Yes, C++ compiler is present. Use standard C. */
extern "C" {

#endif
#endif


/* Internal option: enable the basic USBX error checking. This define is typically used
Expand Down Expand Up @@ -112,7 +112,10 @@ extern "C" {
#define UX_SLAVE_CLASS_STORAGE_MEDIA_OPTICAL_DISK 7
#define UX_SLAVE_CLASS_STORAGE_MEDIA_IOMEGA_CLICK 0x55

/* Define Storage Class USB medium removable type. */

#define UX_SLAVE_CLASS_STORAGE_MEDIA_IS_NOT_REMOVABLE 0x00
#define UX_SLAVE_CLASS_STORAGE_MEDIA_IS_REMOVABLE (1u<<8)

/* Define Storage Class SCSI command constants. */

Expand Down Expand Up @@ -321,6 +324,10 @@ extern "C" {
#define UX_SLAVE_CLASS_STORAGE_SENSE_KEY_VOLUME_OVERFLOW 0x0d
#define UX_SLAVE_CLASS_STORAGE_SENSE_KEY_MISCOMPARE 0x0e

#define UX_SLAVE_CLASS_STORAGE_SENSE_CODE_NOT_READY 0x04
#define UX_SLAVE_CLASS_STORAGE_SENSE_CODE_WRITE_PROTECTED 0x27
#define UX_SLAVE_CLASS_STORAGE_SENSE_CODE_NOT_READY_TO_READY 0x28
#define UX_SLAVE_CLASS_STORAGE_SENSE_CODE_NOT_PRESENT 0x3A

/* Define Storage Class SCSI sense key definition constants. */

Expand Down Expand Up @@ -361,6 +368,23 @@ extern "C" {
#define UX_SLAVE_CLASS_STORAGE_READ_DISK_INFORMATION_ALLOCATION_LENGTH 7
#define UX_SLAVE_CLASS_STORAGE_READ_DISK_INFORMATION_LENGTH 10

/* Define Storage Class (SBC-4) POWER CONDITION constants. */

#define UX_SLAVE_CLASS_STORAGE_POWER_CONDITION_START_VALID 0x00
#define UX_SLAVE_CLASS_STORAGE_POWER_CONDITION_ACTIVE 0x01
#define UX_SLAVE_CLASS_STORAGE_POWER_CONDITION_IDLE 0x02
#define UX_SLAVE_CLASS_STORAGE_POWER_CONDITION_STANDBY 0x03
#define UX_SLAVE_CLASS_STORAGE_POWER_CONDITION_LU_CONTROL 0x07
#define UX_SLAVE_CLASS_STORAGE_POWER_CONDITION_FORCE_IDLE_0 0x0A
#define UX_SLAVE_CLASS_STORAGE_POWER_CONDITION_FORCE_STANDBY_0 0x0B

/* Define Storage Class (SBC-4) PREVENT constants. */

#define UX_SLAVE_CLASS_STORAGE_MEDIUM_REMOVAL_IS_ALLOWED 0x00
#define UX_SLAVE_CLASS_STORAGE_MEDIUM_REMOVAL_SHALL_BE_PREVENTED 0x01
#define UX_SLAVE_CLASS_STORAGE_MEDIUM_PREVENT_OBSOLETE_2 0x02
#define UX_SLAVE_CLASS_STORAGE_MEDIUM_PREVENT_OBSOLETE_3 0x03

/* Define Storage Class Feature Descriptor generic format. */

#define USBX_DEVICE_CLASS_STORAGE_FEATURE_DESCRIPTOR_FEATURE_CODE 0
Expand Down Expand Up @@ -504,12 +528,17 @@ typedef struct UX_SLAVE_CLASS_STORAGE_LUN_STRUCT
ULONG ux_slave_class_storage_request_sense_status;
ULONG ux_slave_class_storage_disk_status;
ULONG ux_slave_class_storage_last_session_state;
ULONG ux_slave_class_storage_prevent_medium_removal;
ULONG ux_slave_class_storage_medium_loaded_status;

UINT (*ux_slave_class_storage_media_read)(VOID *storage, ULONG lun, UCHAR *data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status);
UINT (*ux_slave_class_storage_media_write)(VOID *storage, ULONG lun, UCHAR *data_pointer, ULONG number_blocks, ULONG lba, ULONG *media_status);
UINT (*ux_slave_class_storage_media_flush)(VOID *storage, ULONG lun, ULONG number_blocks, ULONG lba, ULONG *media_status);
UINT (*ux_slave_class_storage_media_status)(VOID *storage, ULONG lun, ULONG media_id, ULONG *media_status);
UINT (*ux_slave_class_storage_media_notification)(VOID *storage, ULONG lun, ULONG media_id, ULONG notification_class, UCHAR **media_notification, ULONG *media_notification_length);

/* Optional callback invoked when load/eject media is requested. */
UINT (*ux_slave_class_storage_media_start_stop)(VOID *storage, ULONG lun, ULONG power_condition, ULONG start, ULONG load_eject);
} UX_SLAVE_CLASS_STORAGE_LUN;

/* Sense status value (key at bit0-7, code at bit8-15 and qualifier at bit16-23). */
Expand Down Expand Up @@ -674,10 +703,10 @@ UINT _uxe_device_class_storage_initialize(UX_SLAVE_CLASS_COMMAND *command);

#define ux_device_class_storage_entry _ux_device_class_storage_entry

/* Determine if a C++ compiler is being used. If so, complete the standard
C conditional started above. */
/* Determine if a C++ compiler is being used. If so, complete the standard
C conditional started above. */
#ifdef __cplusplus
}
#endif
}
#endif

#endif
88 changes: 48 additions & 40 deletions common/usbx_device_classes/src/ux_device_class_storage_activate.c
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
*
* Copyright (c) 2024 Microsoft Corporation
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
*
* SPDX-License-Identifier: MIT
**************************************************************************/


/**************************************************************************/
/**************************************************************************/
/** */
/** USBX Component */
/** */
/** USBX Component */
/** */
/** Device Storage Class */
/** */
Expand All @@ -29,40 +29,40 @@
#include "ux_device_stack.h"


/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_device_class_storage_activate PORTABLE C */
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_device_class_storage_activate PORTABLE C */
/* 6.3.0 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function activates the USB storage device. */
/* */
/* INPUT */
/* */
/* command Pointer to storage command */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* _ux_device_thread_resume Resume thread */
/* */
/* CALLED BY */
/* */
/* Device Storage Class */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* */
/* This function activates the USB storage device. */
/* */
/* INPUT */
/* */
/* command Pointer to storage command */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* _ux_device_thread_resume Resume thread */
/* */
/* CALLED BY */
/* */
/* Device Storage Class */
/* */
/* RELEASE HISTORY */
/* */
/* DATE NAME DESCRIPTION */
/* */
/* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
/* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
/* resulting in version 6.1 */
Expand All @@ -81,11 +81,12 @@
/**************************************************************************/
UINT _ux_device_class_storage_activate(UX_SLAVE_CLASS_COMMAND *command)
{

UINT status = UX_SUCCESS;
UX_SLAVE_INTERFACE *interface_ptr;
UX_SLAVE_CLASS *class_ptr;
UX_SLAVE_CLASS_STORAGE *storage;
ULONG lun_index;
#if defined(UX_DEVICE_STANDALONE)
UX_SLAVE_ENDPOINT *endpoint;
#endif
Expand All @@ -99,17 +100,17 @@ UX_SLAVE_ENDPOINT *endpoint;

/* Get the interface that owns this instance. */
interface_ptr = (UX_SLAVE_INTERFACE *) command -> ux_slave_class_command_interface;

/* Store the class instance into the interface. */
interface_ptr -> ux_slave_interface_class_instance = (VOID *)storage;

/* Now the opposite, store the interface in the class instance. */
storage -> ux_slave_class_storage_interface = interface_ptr;

#if !defined(UX_DEVICE_STANDALONE)

/* Resume thread. */
_ux_device_thread_resume(&class_ptr -> ux_slave_class_thread);
_ux_device_thread_resume(&class_ptr -> ux_slave_class_thread);

#else

Expand All @@ -130,7 +131,7 @@ UX_SLAVE_ENDPOINT *endpoint;

/* We found the IN endpoint first. */
storage -> ux_device_class_storage_ep_in = endpoint;

/* So the next endpoint has to be the OUT endpoint. */
storage -> ux_device_class_storage_ep_out = endpoint -> ux_slave_endpoint_next_endpoint;
}
Expand Down Expand Up @@ -162,13 +163,20 @@ UX_SLAVE_ENDPOINT *endpoint;
status = UX_SUCCESS;
#endif

/* Default when activating storage device: media removal is allowed (not prevented) and loaded. */
for (lun_index = 0; lun_index < storage -> ux_slave_class_storage_number_lun; lun_index++)
{
storage -> ux_slave_class_storage_lun[lun_index].ux_slave_class_storage_prevent_medium_removal = 0;
storage -> ux_slave_class_storage_lun[lun_index].ux_slave_class_storage_medium_loaded_status = 1;
}

/* If there is a activate function call it. */
if (storage -> ux_slave_class_storage_instance_activate != UX_NULL)
{
{
/* Invoke the application. */
storage -> ux_slave_class_storage_instance_activate(storage);
}

/* If trace is enabled, insert this event into the trace buffer. */
UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_STORAGE_ACTIVATE, storage, 0, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ ULONG lun_index;
storage -> ux_slave_class_storage_lun[lun_index].ux_slave_class_storage_media_write = storage_parameter -> ux_slave_class_storage_parameter_lun[lun_index].ux_slave_class_storage_media_write;
storage -> ux_slave_class_storage_lun[lun_index].ux_slave_class_storage_media_status = storage_parameter -> ux_slave_class_storage_parameter_lun[lun_index].ux_slave_class_storage_media_status;
storage -> ux_slave_class_storage_lun[lun_index].ux_slave_class_storage_media_notification = storage_parameter -> ux_slave_class_storage_parameter_lun[lun_index].ux_slave_class_storage_media_notification;
storage -> ux_slave_class_storage_lun[lun_index].ux_slave_class_storage_media_start_stop = storage_parameter -> ux_slave_class_storage_parameter_lun[lun_index].ux_slave_class_storage_media_start_stop;
}

/* If it's OK, complete it. */
Expand Down
Loading