The Pedigree Project  0.1
UsbMassStorageDevice.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef USBMASSSTORAGEDEVICE_H
21 #define USBMASSSTORAGEDEVICE_H
22 
23 #include "modules/drivers/common/scsi/ScsiController.h"
24 #include "modules/system/usb/UsbConstants.h"
25 #include "modules/system/usb/UsbDevice.h"
26 #include "pedigree/kernel/compiler.h"
27 #include "pedigree/kernel/processor/types.h"
28 #include "pedigree/kernel/utilities/String.h"
29 #include "pedigree/kernel/utilities/utility.h"
30 
31 class Device;
32 
34 {
35  public:
37  virtual ~UsbMassStorageDevice();
38 
39  virtual void initialiseDriver();
40 
41  virtual bool sendCommand(
42  size_t nUnit, uintptr_t pCommand, uint8_t nCommandSize,
43  uintptr_t pRespBuffer, uint16_t nRespBytes, bool bWrite);
44 
45  virtual void getUsbDeviceName(String &str)
46  {
47  str = "USB Mass Storage Device";
48  }
49 
50  virtual bool hasSubtree() const
51  {
52  return true;
53  }
54 
55  virtual Device *getDevice()
56  {
57  return this;
58  }
59 
60  private:
61  bool massStorageReset();
62 
63  enum MassStorageRequests
64  {
65  MassStorageRequest =
66  UsbRequestType::Class | UsbRequestRecipient::Interface,
67 
68  MassStorageReset = 0xFF,
69  MassStorageGetMaxLUN = 0xFE
70  };
71 
72  enum MassStorageSigs
73  {
74  CbwSig = HOST_TO_LITTLE32(0x43425355), // USBC
75  CswSig = HOST_TO_LITTLE32(0x53425355) // USBS
76  };
77 
78  struct Cbw
79  {
80  uint32_t nSig;
81  uint32_t nTag;
82  uint32_t nDataBytes;
83  uint8_t nFlags;
84  uint8_t nLUN;
85  uint8_t nCommandSize;
86  uint8_t pCommand[16];
87  } PACKED;
88 
89  struct Csw
90  {
91  uint32_t nSig;
92  uint32_t nTag;
93  uint32_t nResidue;
94  uint8_t nStatus;
95  } PACKED;
96 
97  size_t m_nUnits;
98  Endpoint *m_pInEndpoint;
99  Endpoint *m_pOutEndpoint;
100 
101  protected:
102  virtual size_t getNumUnits()
103  {
104  return m_nUnits;
105  }
106 };
107 
108 #endif
virtual void initialiseDriver()
Implemented by the driver class, initialises driver-specific stuff.
Definition: String.h:49
virtual bool hasSubtree() const
Do we expose our own Device tree?
Definition: Device.h:43
virtual bool sendCommand(size_t nUnit, uintptr_t pCommand, uint8_t nCommandSize, uintptr_t pRespBuffer, uint16_t nRespBytes, bool bWrite)
virtual Device * getDevice()