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 uint32 device_number; 36 bool removed; 37 uint32 open_count; 38 mutex lock; 39 void * link; 40 41 // device state 42 usb_pipe bulk_in; 43 usb_pipe bulk_out; 44 uint8 interface; 45 uint32 current_tag; 46 uint8 sync_support; 47 bool tur_supported; 48 49 // used to store callback information 50 sem_id notify; 51 status_t status; 52 size_t actual_length; 53 54 // logical units of this device 55 uint8 lun_count; 56 device_lun **luns; 57 } disk_device; 58 59 60 // represents a logical unit on the pointed to device - this gets published 61 struct device_lun_s { 62 disk_device *device; 63 char name[32]; 64 uint8 logical_unit_number; 65 bool should_sync; 66 67 // device information through read capacity/inquiry 68 bool media_present; 69 bool media_changed; 70 uint32 block_count; 71 uint32 block_size; 72 uint8 device_type; 73 bool removable; 74 bool write_protected; 75 }; 76 77 78 typedef struct command_block_wrapper_s { 79 uint32 signature; 80 uint32 tag; 81 uint32 data_transfer_length; 82 uint8 flags; 83 uint8 lun; 84 uint8 command_block_length; 85 uint8 command_block[16]; 86 } _PACKED command_block_wrapper; 87 88 89 typedef struct command_status_wrapper_s { 90 uint32 signature; 91 uint32 tag; 92 uint32 data_residue; 93 uint8 status; 94 } _PACKED command_status_wrapper; 95 96 #endif // _USB_DISK_H_ 97