20 |
20 |
21 #include <e32std.h> |
21 #include <e32std.h> |
22 #include <f32file.h> |
22 #include <f32file.h> |
23 |
23 |
24 #include "rusbhostmsdevice.h" |
24 #include "rusbhostmsdevice.h" |
25 #include "debug.h" |
|
26 #include "msgservice.h" |
25 #include "msgservice.h" |
27 |
26 |
|
27 #include "OstTraceDefinitions.h" |
|
28 #ifdef OST_TRACE_COMPILER_IN_USE |
|
29 #include "rusbhostmsdeviceTraces.h" |
|
30 #endif |
|
31 |
|
32 |
28 _LIT(KFileSystem, "FAT"); |
33 _LIT(KFileSystem, "FAT"); |
29 |
34 |
30 TVersion RUsbHostMsDevice::Version() const |
35 TVersion RUsbHostMsDevice::Version() const |
31 { |
36 { |
32 __FNLOG("RUsbHostMsDevice::Version"); |
|
33 return(TVersion(KUsbHostMsSrvMajorVersionNumber, |
37 return(TVersion(KUsbHostMsSrvMajorVersionNumber, |
34 KUsbHostMsSrvMinorVersionNumber, |
38 KUsbHostMsSrvMinorVersionNumber, |
35 KUsbHostMsSrvBuildVersionNumber)); |
39 KUsbHostMsSrvBuildVersionNumber)); |
36 } |
40 } |
37 |
41 |
38 |
42 |
39 TInt RUsbHostMsDevice::StartServer() |
43 TInt RUsbHostMsDevice::StartServer() |
40 { |
44 { |
41 __FNLOG("RUsbHostMsDevice::StartServer"); |
|
42 TInt r; |
45 TInt r; |
43 RProcess server; |
46 RProcess server; |
44 |
47 |
45 const TUid KServerUid3={0x10286A83}; |
48 const TUid KServerUid3={0x10286A83}; |
46 const TUidType serverUid(KNullUid,KNullUid,KServerUid3); |
49 const TUidType serverUid(KNullUid,KNullUid,KServerUid3); |
47 |
50 |
48 // Create the server process |
51 // Create the server process |
49 if((r=server.Create(KUsbHostMsServerName,KNullDesC,serverUid)) != KErrNone) |
52 if((r=server.Create(KUsbHostMsServerName,KNullDesC,serverUid)) != KErrNone) |
50 { |
53 { |
51 __PRINT1(_L("Server process create = %d\n"), r); |
54 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, RUSBHOSTMSDEVICE_10, |
|
55 "Server process create = %d", r); |
52 return r; |
56 return r; |
53 } |
57 } |
54 |
58 |
55 // Create the rendezvous request with the server process |
59 // Create the rendezvous request with the server process |
56 TRequestStatus stat; |
60 TRequestStatus stat; |
94 @param aStatus [In] A reference to TRequestStatus to be used for asynchronous |
98 @param aStatus [In] A reference to TRequestStatus to be used for asynchronous |
95 request completion |
99 request completion |
96 */ |
100 */ |
97 EXPORT_C void RUsbHostMsDevice::Add(const THostMassStorageConfig& aConfig, TRequestStatus& aStatus) |
101 EXPORT_C void RUsbHostMsDevice::Add(const THostMassStorageConfig& aConfig, TRequestStatus& aStatus) |
98 { |
102 { |
99 __FNLOG("RUsbHostMsDevice::Add"); |
|
100 TInt err = KErrNone; |
103 TInt err = KErrNone; |
101 |
104 |
102 err = CreateSession(KUsbHostMsServerName, Version(), 128, EIpcSession_GlobalSharable); |
105 err = CreateSession(KUsbHostMsServerName, Version(), 128, EIpcSession_GlobalSharable); |
103 |
106 |
104 // Being a transient server, the first session creation would fail with if |
107 // Being a transient server, the first session creation would fail with if |
117 err = CreateSession(KUsbHostMsServerName, Version(), 128, EIpcSession_GlobalSharable); |
120 err = CreateSession(KUsbHostMsServerName, Version(), 128, EIpcSession_GlobalSharable); |
118 } |
121 } |
119 } |
122 } |
120 } |
123 } |
121 |
124 |
122 TRequestStatus* statusPtr = &aStatus; |
125 TRequestStatus* statusPtr = &aStatus; |
123 if(err == KErrNone) |
126 if(err == KErrNone) |
124 { |
127 { |
125 // Create a session handle that can be passed via IPC to another process |
128 // Create a session handle that can be passed via IPC to another process |
126 // (also being shared by other threads in the current process) |
129 // (also being shared by other threads in the current process) |
127 err = ShareProtected(); |
130 err = ShareProtected(); |
128 if(err == KErrNone) |
131 if(err == KErrNone) |
129 { |
132 { |
130 // synchronous call to register the interface |
133 // synchronous call to register the interface |
131 TPckg<THostMassStorageConfig> pckg(aConfig); |
134 TPckg<THostMassStorageConfig> pckg(aConfig); |
132 err = SendReceive(EUsbHostMsRegisterInterface, TIpcArgs(&pckg)); |
135 err = SendReceive(EUsbHostMsRegisterInterface, TIpcArgs(&pckg)); |
133 if(err != KErrNone) |
136 if(err != KErrNone) |
134 { |
137 { |
135 User::RequestComplete(statusPtr, err); |
138 User::RequestComplete(statusPtr, err); |
136 } |
139 } |
137 else |
140 else |
138 { |
141 { |
139 // Asynchronous call to initialise the interface |
142 // Asynchronous call to initialise the interface |
140 SendReceive(EUsbHostMsInitialiseInterface, TIpcArgs(NULL), aStatus); |
143 SendReceive(EUsbHostMsInitialiseInterface, TIpcArgs(NULL), aStatus); |
141 } |
144 } |
142 } |
145 } |
143 else |
146 else |
144 { |
147 { |
145 Close(); // Close the session handle |
148 Close(); // Close the session handle |
146 __PRINT1(_L("Could not create a sharable session handle %d\n"), err); |
149 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, RUSBHOSTMSDEVICE_11, |
|
150 "Could not create a sharable session handle %d", err); |
147 User::RequestComplete(statusPtr, err); |
151 User::RequestComplete(statusPtr, err); |
148 } |
152 } |
149 } |
153 } |
150 else |
154 else |
151 { |
155 { |
152 // Check whether the error is in starting the server or in creating the |
156 // Check whether the error is in starting the server or in creating the |
153 // session |
157 // session |
154 __PRINT1(_L("Creating server/session failed with %d\n"), err); |
158 OstTrace1(TRACE_SHOSTMASSSTORAGE_HOST, RUSBHOSTMSDEVICE_12, |
|
159 "Creating server/session failed with %d", err); |
155 User::RequestComplete(statusPtr, err); |
160 User::RequestComplete(statusPtr, err); |
156 } |
161 } |
157 } |
162 } |
158 |
163 |
159 |
164 |
163 |
168 |
164 Remove the Mass Storage device from the MSC server. |
169 Remove the Mass Storage device from the MSC server. |
165 */ |
170 */ |
166 EXPORT_C void RUsbHostMsDevice::Remove() |
171 EXPORT_C void RUsbHostMsDevice::Remove() |
167 { |
172 { |
168 // Note: Here, at present we use only the interface token. But we still take |
173 // Note: Here, at present we use only the interface token. But we still take |
169 // THostMassStorageConfig as parameter for future needs |
174 // THostMassStorageConfig as parameter for future needs |
170 __FNLOG("RUsbHostMsDevice::Remove"); |
175 _LIT(KUsbHostMsClientPanicCat, "usbhostmsclient"); |
171 _LIT(KUsbHostMsClientPanicCat, "usbhostmsclient"); |
176 |
172 |
177 TInt r = SendReceive(EUsbHostMsUnRegisterInterface); |
173 TInt r = SendReceive(EUsbHostMsUnRegisterInterface); |
178 |
174 |
179 r = SendReceive(EUsbHostMsFinalCleanup); |
175 r = SendReceive(EUsbHostMsFinalCleanup); |
180 if(r != KErrNone) |
176 if(r != KErrNone) |
181 { |
177 { |
182 User::Panic(KUsbHostMsClientPanicCat ,KErrCouldNotDisconnect); |
178 User::Panic(KUsbHostMsClientPanicCat ,KErrCouldNotDisconnect); |
183 } |
179 } |
|
180 Close(); // Close the session handle |
184 Close(); // Close the session handle |
181 } |
185 } |
182 |
186 |
183 |
187 |
184 /** |
188 /** |
193 |
197 |
194 @return TInt |
198 @return TInt |
195 */ |
199 */ |
196 EXPORT_C TInt RUsbHostMsDevice::GetNumLun(TUint32& aNumLuns) |
200 EXPORT_C TInt RUsbHostMsDevice::GetNumLun(TUint32& aNumLuns) |
197 { |
201 { |
198 __FNLOG("RUsbHostMsDevice::GetNumLun"); |
|
199 TPckg<TUint32> pckg(aNumLuns); |
202 TPckg<TUint32> pckg(aNumLuns); |
200 return SendReceive(EUsbHostMsGetNumLun,TIpcArgs(&pckg)); |
203 return SendReceive(EUsbHostMsGetNumLun,TIpcArgs(&pckg)); |
201 } |
204 } |
202 |
205 |
203 |
206 |
204 EXPORT_C TInt RUsbHostMsDevice::MountLun(TUint32 aLunId, TInt aDriveNum) |
207 EXPORT_C TInt RUsbHostMsDevice::MountLun(TUint32 aLunId, TInt aDriveNum) |
205 { |
208 { |
206 __FNLOG("RUsbHostMsDevice::MountLun"); |
209 OstTraceExt2(TRACE_SHOSTMASSSTORAGE_MSDEV, RUSBHOSTMSDEVICE_13, |
207 __MSDEVPRINT2(_L(">>> RUsbHostMsDevice::MountLun Drv=%d LUN=%d"), aDriveNum, aLunId); |
210 ">>> RUsbHostMsDevice::MountLun Drv=%d LUN=%d", aDriveNum, aLunId); |
208 RFs TheFs; |
211 RFs TheFs; |
209 TInt r = TheFs.Connect(); |
212 TInt r = TheFs.Connect(); |
210 if(r == KErrNone) |
213 if(r == KErrNone) |
211 { |
214 { |
212 TPckgBuf<TMassStorageUnitInfo> unitPkg; |
215 TPckgBuf<TMassStorageUnitInfo> unitPkg; |
213 unitPkg().iLunID = aLunId; |
216 unitPkg().iLunID = aLunId; |
214 |
217 |
215 r = TheFs.MountProxyDrive(aDriveNum, _L("usbhostms"), &unitPkg, *this); |
218 r = TheFs.MountProxyDrive(aDriveNum, _L("usbhostms"), &unitPkg, *this); |
216 __MSDEVPRINT1(_L("MountProxyDrive %d"), r); |
219 OstTrace1(TRACE_SHOSTMASSSTORAGE_MSDEV, RUSBHOSTMSDEVICE_14, |
217 if(r >= KErrNone) |
220 "MountProxyDrive %d", r); |
218 { |
221 if(r >= KErrNone) |
219 r = TheFs.MountFileSystem(KFileSystem, aDriveNum); |
222 { |
220 __MSDEVPRINT1(_L("MountFileSystem %d"), r); |
223 r = TheFs.MountFileSystem(KFileSystem, aDriveNum); |
221 if(r != KErrNone && r != KErrNotReady && r != KErrCorrupt && r != KErrNotSupported) |
224 OstTrace1(TRACE_SHOSTMASSSTORAGE_MSDEV, RUSBHOSTMSDEVICE_15, |
222 { |
225 "MountFileSystem %d", r); |
223 TheFs.DismountFileSystem(KFileSystem, aDriveNum); |
226 if(r != KErrNone && r != KErrNotReady && r != KErrCorrupt && r != KErrNotSupported) |
224 TheFs.DismountProxyDrive(aDriveNum); |
227 { |
225 } |
228 TheFs.DismountFileSystem(KFileSystem, aDriveNum); |
226 } |
229 TheFs.DismountProxyDrive(aDriveNum); |
227 TheFs.Close(); |
230 } |
228 } |
231 } |
229 return r; |
232 TheFs.Close(); |
230 } |
233 } |
|
234 return r; |
|
235 } |
231 |
236 |
232 EXPORT_C TInt RUsbHostMsDevice::DismountLun(TInt aDriveNum) |
237 EXPORT_C TInt RUsbHostMsDevice::DismountLun(TInt aDriveNum) |
233 { |
238 { |
234 __FNLOG("RUsbHostMsDevice::DismountLun"); |
239 OstTrace1(TRACE_SHOSTMASSSTORAGE_MSDEV, RUSBHOSTMSDEVICE_20, |
235 __MSDEVPRINT1(_L(">>> RUsbHostMsDevice::DismountLun Drv=%d"), aDriveNum); |
240 ">>> RUsbHostMsDevice::DismountLun Drv=%d", aDriveNum); |
236 RFs TheFs; |
241 RFs TheFs; |
237 TInt r; |
242 TInt r; |
238 r = TheFs.Connect(); |
243 r = TheFs.Connect(); |
239 if(r == KErrNone) |
244 if(r == KErrNone) |
240 { |
245 { |
241 r = TheFs.DismountFileSystem(KFileSystem, aDriveNum); |
246 r = TheFs.DismountFileSystem(KFileSystem, aDriveNum); |
242 if(r != KErrNone) |
247 if(r != KErrNone) |
243 { |
248 { |
244 // dismount failed - attempt a forced dismount |
249 // dismount failed - attempt a forced dismount |
245 TRequestStatus stat; |
250 TRequestStatus stat; |
246 TheFs.NotifyDismount(aDriveNum, stat, EFsDismountForceDismount); |
251 TheFs.NotifyDismount(aDriveNum, stat, EFsDismountForceDismount); |
247 User::WaitForRequest(stat); |
252 User::WaitForRequest(stat); |
248 r = stat.Int(); |
253 r = stat.Int(); |
249 } |
254 } |
250 if(r == KErrNone) |
255 if(r == KErrNone) |
251 { |
256 { |
252 r = TheFs.DismountProxyDrive(aDriveNum); |
257 r = TheFs.DismountProxyDrive(aDriveNum); |
253 } |
258 } |
254 TheFs.Close(); |
259 TheFs.Close(); |
255 } |
260 } |
256 return r; |
261 return r; |
257 } |
262 } |