sl@0
|
1 |
// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
//
|
sl@0
|
15 |
|
sl@0
|
16 |
/**
|
sl@0
|
17 |
@file
|
sl@0
|
18 |
@internalTechnology
|
sl@0
|
19 |
*/
|
sl@0
|
20 |
|
sl@0
|
21 |
#ifndef CSCSIPROTOCOL_H
|
sl@0
|
22 |
#define CSCSIPROTOCOL_H
|
sl@0
|
23 |
|
sl@0
|
24 |
class CMassStorageFsm;
|
sl@0
|
25 |
|
sl@0
|
26 |
class TSbcClientInterface;
|
sl@0
|
27 |
|
sl@0
|
28 |
class RMediaChangeNotifier
|
sl@0
|
29 |
{
|
sl@0
|
30 |
public:
|
sl@0
|
31 |
RMediaChangeNotifier();
|
sl@0
|
32 |
~RMediaChangeNotifier();
|
sl@0
|
33 |
|
sl@0
|
34 |
void Register(const RMessage2& aMessage);
|
sl@0
|
35 |
void DoNotifyL();
|
sl@0
|
36 |
void DoCancelL();
|
sl@0
|
37 |
|
sl@0
|
38 |
private:
|
sl@0
|
39 |
void CompleteNotifierL(TInt);
|
sl@0
|
40 |
|
sl@0
|
41 |
private:
|
sl@0
|
42 |
/** Notification service */
|
sl@0
|
43 |
RMessage2 iNotifier;
|
sl@0
|
44 |
/** Flag to indicate that media change notification is active */
|
sl@0
|
45 |
TBool iRegistered;
|
sl@0
|
46 |
};
|
sl@0
|
47 |
|
sl@0
|
48 |
|
sl@0
|
49 |
/**
|
sl@0
|
50 |
SCSI Protocol procedures
|
sl@0
|
51 |
*/
|
sl@0
|
52 |
class CScsiProtocol: public CBase, public MProtocol, public MBlockTransferProtocol
|
sl@0
|
53 |
{
|
sl@0
|
54 |
public:
|
sl@0
|
55 |
/** SCSI state */
|
sl@0
|
56 |
enum TScsiState
|
sl@0
|
57 |
{
|
sl@0
|
58 |
EConnected,
|
sl@0
|
59 |
EDisconnected
|
sl@0
|
60 |
};
|
sl@0
|
61 |
|
sl@0
|
62 |
static CScsiProtocol* NewL(TLun aLun, MTransport& aTransport);
|
sl@0
|
63 |
~CScsiProtocol();
|
sl@0
|
64 |
private:
|
sl@0
|
65 |
void ConstructL(TLun aLun);
|
sl@0
|
66 |
CScsiProtocol(MTransport& aTransport);
|
sl@0
|
67 |
|
sl@0
|
68 |
public:
|
sl@0
|
69 |
void InitialiseUnitL();
|
sl@0
|
70 |
|
sl@0
|
71 |
// Stop unit command to uninitialise the lun
|
sl@0
|
72 |
void UninitialiseUnitL();
|
sl@0
|
73 |
|
sl@0
|
74 |
// Read command to read the media
|
sl@0
|
75 |
void ReadL(TPos aPos, TDes8& aCopybuf, TInt aLen);
|
sl@0
|
76 |
|
sl@0
|
77 |
// Write command to write to the media
|
sl@0
|
78 |
void WriteL(TPos aPos, TDesC8& aCopybuf, TInt aLen);
|
sl@0
|
79 |
|
sl@0
|
80 |
// ReadCapacity command to find the capacity of the media
|
sl@0
|
81 |
void GetCapacityL(TCapsInfo& aCapsInfo);
|
sl@0
|
82 |
|
sl@0
|
83 |
// unit testing
|
sl@0
|
84 |
void CreateSbcInterfaceL(TUint32 aBlockLen, TUint32 aLastLba);
|
sl@0
|
85 |
|
sl@0
|
86 |
void DoScsiReadyCheckEventL();
|
sl@0
|
87 |
|
sl@0
|
88 |
void NotifyChange(const RMessage2& aMessage);
|
sl@0
|
89 |
void ForceCompleteNotifyChangeL();
|
sl@0
|
90 |
void CancelChangeNotifierL();
|
sl@0
|
91 |
void CompleteNotifyChangeL();
|
sl@0
|
92 |
void SuspendL();
|
sl@0
|
93 |
void ResumeL();
|
sl@0
|
94 |
TBool IsConnected();
|
sl@0
|
95 |
|
sl@0
|
96 |
// Supported Mass Storage commands
|
sl@0
|
97 |
TInt MsInquiryL();
|
sl@0
|
98 |
TInt MsTestUnitReadyL();
|
sl@0
|
99 |
TInt MsStartStopUnitL(TBool aStart);
|
sl@0
|
100 |
TInt MsPreventAllowMediaRemovalL(TBool aPrevent);
|
sl@0
|
101 |
|
sl@0
|
102 |
TInt MsReadCapacityL();
|
sl@0
|
103 |
TInt MsModeSense10L();
|
sl@0
|
104 |
TInt MsModeSense6L();
|
sl@0
|
105 |
|
sl@0
|
106 |
TInt MsRequestSenseL();
|
sl@0
|
107 |
|
sl@0
|
108 |
TBool MsIsSbcSet() const;
|
sl@0
|
109 |
TBool MsIsRemovableMedia() const;
|
sl@0
|
110 |
const TSenseInfo& MsSenseInfo() const;
|
sl@0
|
111 |
|
sl@0
|
112 |
// MBlockTransferProtocol interface
|
sl@0
|
113 |
void BlockReadL(TPos aPos, TDes8& aBuf, TInt aLength);
|
sl@0
|
114 |
void BlockWriteL(TPos aPos, TDesC8& aBuf, TUint aOffset, TInt aLength);
|
sl@0
|
115 |
|
sl@0
|
116 |
private:
|
sl@0
|
117 |
void ResetSbc();
|
sl@0
|
118 |
|
sl@0
|
119 |
void DoCheckConditionL();
|
sl@0
|
120 |
|
sl@0
|
121 |
TInt GetSystemWideSenseError(const TSenseInfo& aSenseInfo);
|
sl@0
|
122 |
TInt ProcessAsCodes(const TSenseInfo& aSenseInfo);
|
sl@0
|
123 |
|
sl@0
|
124 |
private:
|
sl@0
|
125 |
|
sl@0
|
126 |
/** State machine for device initialisation protocol */
|
sl@0
|
127 |
CMassStorageFsm* iFsm;
|
sl@0
|
128 |
|
sl@0
|
129 |
/** SCSI SPC interface methods */
|
sl@0
|
130 |
TSpcClientInterface iSpcInterface;
|
sl@0
|
131 |
/** SCSI SBC interface methods */
|
sl@0
|
132 |
TSbcClientInterface* iSbcInterface;
|
sl@0
|
133 |
// buffers for block manipulation (for use in iSbcInterface)
|
sl@0
|
134 |
RBuf8 iHeadbuf;
|
sl@0
|
135 |
RBuf8 iTailbuf;
|
sl@0
|
136 |
|
sl@0
|
137 |
// Logical Unit properties
|
sl@0
|
138 |
/** LU removable */
|
sl@0
|
139 |
TBool iRemovableMedia;
|
sl@0
|
140 |
/** LU write protected */
|
sl@0
|
141 |
TBool iWriteProtect;
|
sl@0
|
142 |
|
sl@0
|
143 |
/** Result of the last SCSI command */
|
sl@0
|
144 |
TSenseInfo iSenseInfo;
|
sl@0
|
145 |
|
sl@0
|
146 |
/** State of the LUN represented by this object */
|
sl@0
|
147 |
TScsiState iState;
|
sl@0
|
148 |
|
sl@0
|
149 |
/** Notifier for media changes */
|
sl@0
|
150 |
RMediaChangeNotifier iMediaChangeNotifier;
|
sl@0
|
151 |
};
|
sl@0
|
152 |
|
sl@0
|
153 |
|
sl@0
|
154 |
/**
|
sl@0
|
155 |
Returns the state of the SBC interface. INQUIRY command is used to detect if
|
sl@0
|
156 |
device supports SBC and initialise the SBC interface.
|
sl@0
|
157 |
|
sl@0
|
158 |
@return TBool ETrue is SBC interface is initialised
|
sl@0
|
159 |
*/
|
sl@0
|
160 |
inline TBool CScsiProtocol::MsIsSbcSet() const
|
sl@0
|
161 |
{
|
sl@0
|
162 |
return iSbcInterface ? ETrue : EFalse;
|
sl@0
|
163 |
}
|
sl@0
|
164 |
|
sl@0
|
165 |
/**
|
sl@0
|
166 |
Returns the device removable property. MODE SENSE command is used to detect if
|
sl@0
|
167 |
the device is removable.
|
sl@0
|
168 |
|
sl@0
|
169 |
@return TBool ETrue if device is removable
|
sl@0
|
170 |
*/
|
sl@0
|
171 |
inline TBool CScsiProtocol::MsIsRemovableMedia() const
|
sl@0
|
172 |
{
|
sl@0
|
173 |
return iRemovableMedia;
|
sl@0
|
174 |
}
|
sl@0
|
175 |
|
sl@0
|
176 |
|
sl@0
|
177 |
/**
|
sl@0
|
178 |
Helper to return current SenseInfo. SCSI REQUEST SENSE command sets the sense
|
sl@0
|
179 |
info. The protocol will retrieve device's sense info in the event of a SCSI
|
sl@0
|
180 |
command error.
|
sl@0
|
181 |
|
sl@0
|
182 |
@return const TSenseInfo&
|
sl@0
|
183 |
*/
|
sl@0
|
184 |
inline const TSenseInfo& CScsiProtocol::MsSenseInfo() const
|
sl@0
|
185 |
{
|
sl@0
|
186 |
return iSenseInfo;
|
sl@0
|
187 |
}
|
sl@0
|
188 |
|
sl@0
|
189 |
#endif // CSCSIPROTOCOL_H
|