1 /* 2 * Copyright 2008, Haiku Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Michael Lotz <mmlr@mlotz.ch> 7 */ 8 9 #ifndef _USB_DISK_H_ 10 #define _USB_DISK_H_ 11 12 #include <lock.h> 13 #include <USB3.h> 14 15 #define REQUEST_MASS_STORAGE_RESET 0xff 16 #define REQUEST_GET_MAX_LUN 0xfe 17 #define MAX_LOGICAL_UNIT_NUMBER 15 18 19 #define CBW_SIGNATURE 0x43425355 20 #define CBW_DATA_OUTPUT 0x00 21 #define CBW_DATA_INPUT 0x80 22 23 #define CSW_SIGNATURE 0x53425355 24 #define CSW_STATUS_COMMAND_PASSED 0x00 25 #define CSW_STATUS_COMMAND_FAILED 0x01 26 #define CSW_STATUS_PHASE_ERROR 0x02 27 28 #define SYNC_SUPPORT_RELOAD 5 29 30 typedef struct device_lun_s device_lun; 31 32 // holds common information about an attached device (pointed to by luns) 33 typedef struct disk_device_s { 34 usb_device device; 35 bool removed; 36 uint32 open_count; 37 mutex lock; 38 void * link; 39 40 // device state 41 usb_pipe bulk_in; 42 usb_pipe bulk_out; 43 uint8 interface; 44 uint32 current_tag; 45 uint8 sync_support; 46 47 // used to store callback information 48 sem_id notify; 49 status_t status; 50 size_t actual_length; 51 52 // logical units of this device 53 uint8 lun_count; 54 device_lun **luns; 55 } disk_device; 56 57 58 // represents a logical unit on the pointed to device - this gets published 59 struct device_lun_s { 60 disk_device *device; 61 char name[32]; 62 uint8 logical_unit_number; 63 bool should_sync; 64 65 // device information through read capacity/inquiry 66 bool media_present; 67 bool media_changed; 68 uint32 block_count; 69 uint32 block_size; 70 uint8 device_type; 71 bool removable; 72 }; 73 74 75 typedef struct command_block_wrapper_s { 76 uint32 signature; 77 uint32 tag; 78 uint32 data_transfer_length; 79 uint8 flags; 80 uint8 lun; 81 uint8 command_block_length; 82 uint8 command_block[16]; 83 } _PACKED command_block_wrapper; 84 85 86 typedef struct command_status_wrapper_s { 87 uint32 signature; 88 uint32 tag; 89 uint32 data_residue; 90 uint8 status; 91 } _PACKED command_status_wrapper; 92 93 #endif // _USB_DISK_H_ 94