| 0 |      1 | // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
 | 
|  |      2 | // All rights reserved.
 | 
|  |      3 | // This component and the accompanying materials are made available
 | 
|  |      4 | // under the terms of the License "Eclipse Public License v1.0"
 | 
|  |      5 | // which accompanies this distribution, and is available
 | 
|  |      6 | // at the URL "http://www.eclipse.org/legal/epl-v10.html".
 | 
|  |      7 | //
 | 
|  |      8 | // Initial Contributors:
 | 
|  |      9 | // Nokia Corporation - initial contribution.
 | 
|  |     10 | //
 | 
|  |     11 | // Contributors:
 | 
|  |     12 | //
 | 
|  |     13 | // Description:
 | 
|  |     14 | //
 | 
|  |     15 | 
 | 
|  |     16 | /**
 | 
|  |     17 |  @file
 | 
|  |     18 |  @internalTechnology
 | 
|  |     19 | */
 | 
|  |     20 | 
 | 
|  |     21 | #include <e32std.h>
 | 
|  |     22 | 
 | 
|  |     23 | #include "msgservice.h"
 | 
|  |     24 | #include "rusbhostmsdevice.h"
 | 
|  |     25 | #include "rusbhostmslogicalunit.h"
 | 
|  |     26 | #include "debug.h"
 | 
|  |     27 | 
 | 
|  |     28 | TVersion RUsbHostMsLogicalUnit::Version() const
 | 
|  |     29 | 	{
 | 
|  |     30 | 	return(TVersion(KUsbHostMsSrvMajorVersionNumber,
 | 
|  |     31 |                     KUsbHostMsSrvMinorVersionNumber,
 | 
|  |     32 |                     KUsbHostMsSrvBuildVersionNumber));
 | 
|  |     33 | 	}
 | 
|  |     34 | 
 | 
|  |     35 | EXPORT_C RUsbHostMsLogicalUnit::RUsbHostMsLogicalUnit()
 | 
|  |     36 | 	{
 | 
|  |     37 | 	// Intentionally left blank
 | 
|  |     38 | 	}
 | 
|  |     39 | 
 | 
|  |     40 | /**
 | 
|  |     41 | Send a command to initialise the Mass Storage device.
 | 
|  |     42 | 
 | 
|  |     43 | @param aMsg
 | 
|  |     44 | @param aDevHandleIndex
 | 
|  |     45 | @param aLun
 | 
|  |     46 | 
 | 
|  |     47 | @return TInt
 | 
|  |     48 | */
 | 
|  |     49 | EXPORT_C TInt RUsbHostMsLogicalUnit::Initialise(const RMessage2& aMsg,
 | 
|  |     50 |                                                 TInt aDevHandleIndex,
 | 
|  |     51 | 												TUint32 aLun)
 | 
|  |     52 | 	{
 | 
|  |     53 | 	__FNLOG("RUsbHostMsLogicalUnit::Initialise");
 | 
|  |     54 | 	TInt r = dev.Open(aMsg, aDevHandleIndex);
 | 
|  |     55 | 	if (r != KErrNone)
 | 
|  |     56 | 		{
 | 
|  |     57 | 		__PRINT1(_L("Session handle can not be opened %d"),r);
 | 
|  |     58 | 		return r;
 | 
|  |     59 | 		}
 | 
|  |     60 | 
 | 
|  |     61 | 	r = CreateSubSession(dev, EUsbHostMsRegisterLun, TIpcArgs(aLun));
 | 
|  |     62 | 	if (r != KErrNone)
 | 
|  |     63 | 		{
 | 
|  |     64 | 		__PRINT1(_L("SubSession creation failed %d"),r);
 | 
|  |     65 | 		return r;
 | 
|  |     66 | 		}
 | 
|  |     67 | 	return r;
 | 
|  |     68 | 	}
 | 
|  |     69 | 
 | 
|  |     70 | 
 | 
|  |     71 | /**
 | 
|  |     72 | Send a command to read the Mass Storage device.
 | 
|  |     73 | 
 | 
|  |     74 | @param aPos Position to start reading from
 | 
|  |     75 | @param aLength Number of Bytes
 | 
|  |     76 | @param aTrg Buffer to copy data to
 | 
|  |     77 | 
 | 
|  |     78 | @return TInt KErrNone, if the send operation is successful;
 | 
|  |     79 | 	KErrServerTerminated, if the server no longer present; KErrServerBusy, if there are no message slots available;
 | 
|  |     80 | 	KErrNoMemory, if there is insufficient memory available.
 | 
|  |     81 | */
 | 
|  |     82 | EXPORT_C TInt RUsbHostMsLogicalUnit::Read(TInt64 aPos, TInt aLength, TDes8& aTrg)
 | 
|  |     83 | 	{
 | 
|  |     84 | 	__FNLOG("RUsbHostMsLogicalUnit::Read");
 | 
|  |     85 | 
 | 
|  |     86 | 	TReadWrite data;
 | 
|  |     87 | 	data.iPos = aPos;
 | 
|  |     88 | 	data.iLen = aLength;
 | 
|  |     89 | 
 | 
|  |     90 | 	__PRINT2(_L("pos = 0x%lx, len = x%x"), data.iPos, data.iLen);
 | 
|  |     91 | 
 | 
|  |     92 | 	TPckg<TReadWrite> pckg(data);
 | 
|  |     93 | 	/* We handle the message asynchronously in the thread modelled MSC */
 | 
|  |     94 | 	TRequestStatus	status;
 | 
|  |     95 | 	SendReceive(EUsbHostMsRead, TIpcArgs(&pckg, &aTrg), status);
 | 
|  |     96 | 	User::WaitForRequest(status);
 | 
|  |     97 |     __PRINT2(_L("pos = 0x%lx, len = x%x"), data.iPos, data.iLen);
 | 
|  |     98 | 	return status.Int();
 | 
|  |     99 | 	}
 | 
|  |    100 | 
 | 
|  |    101 | 
 | 
|  |    102 | /**
 | 
|  |    103 | Send a command to write to the Mass Storage device.
 | 
|  |    104 | 
 | 
|  |    105 | @param aPos Position to start reading from
 | 
|  |    106 | @param aLength Number of Bytes
 | 
|  |    107 | @param aTrg Buffer to copy data from
 | 
|  |    108 | 
 | 
|  |    109 | @return TInt KErrNone, if the send operation is successful;
 | 
|  |    110 | 	KErrServerTerminated, if the server no longer present; KErrServerBusy, if there are no message slots available;
 | 
|  |    111 | 	KErrNoMemory, if there is insufficient memory available.
 | 
|  |    112 | available.
 | 
|  |    113 | */
 | 
|  |    114 | EXPORT_C TInt RUsbHostMsLogicalUnit::Write(TInt64 aPos, TInt aLength, const TDesC8& aTrg)
 | 
|  |    115 | 	{
 | 
|  |    116 | 	__FNLOG("RUsbHostMsLogicalUnit::Write");
 | 
|  |    117 | 
 | 
|  |    118 | 	TReadWrite data;
 | 
|  |    119 | 	data.iPos = aPos;
 | 
|  |    120 | 	data.iLen = aLength;
 | 
|  |    121 | 
 | 
|  |    122 | 	__PRINT2(_L("pos = 0x%lx, len = x%x"), data.iPos, data.iLen);
 | 
|  |    123 | 
 | 
|  |    124 | 	TPckg<TReadWrite> pckg(data);
 | 
|  |    125 | 	/* We handle the message asynchronously in the thread modelled MSC */
 | 
|  |    126 | 	TRequestStatus	status;
 | 
|  |    127 | 	SendReceive(EUsbHostMsWrite, TIpcArgs(&aTrg, &pckg), status);
 | 
|  |    128 | 	User::WaitForRequest(status);
 | 
|  |    129 | 	return status.Int();
 | 
|  |    130 | 	}
 | 
|  |    131 | 
 | 
|  |    132 | 
 | 
|  |    133 | /**
 | 
|  |    134 | Send a command to erase an area of the Mass Storage device.
 | 
|  |    135 | 
 | 
|  |    136 | @param aPos Position to start reading from
 | 
|  |    137 | @param aLength Number of Bytes
 | 
|  |    138 | 
 | 
|  |    139 | @return TInt KErrNone, if the send operation is successful;
 | 
|  |    140 | 	KErrServerTerminated, if the server no longer present; KErrServerBusy, if there are no message slots available;
 | 
|  |    141 | 	KErrNoMemory, if there is insufficient memory available.
 | 
|  |    142 | available.
 | 
|  |    143 | */
 | 
|  |    144 | EXPORT_C TInt RUsbHostMsLogicalUnit::Erase(TInt64 aPos, TInt aLength)
 | 
|  |    145 | 	{
 | 
|  |    146 | 	__FNLOG("RUsbHostMsLogicalUnit::Erase");
 | 
|  |    147 | 
 | 
|  |    148 | 	TReadWrite data;
 | 
|  |    149 | 	data.iPos = aPos;
 | 
|  |    150 | 	data.iLen = aLength;
 | 
|  |    151 | 
 | 
|  |    152 | 	__PRINT2(_L("pos = 0x%lx, len = x%x"), data.iPos, data.iLen);
 | 
|  |    153 | 
 | 
|  |    154 | 	TPckg<TReadWrite> pckg(data);
 | 
|  |    155 | 	/* We handle the message asynchronously in the thread modelled MSC */
 | 
|  |    156 | 	TRequestStatus	status;
 | 
|  |    157 | 	SendReceive(EUsbHostMsErase, TIpcArgs(&pckg), status);
 | 
|  |    158 | 	User::WaitForRequest(status);
 | 
|  |    159 | 	return status.Int();
 | 
|  |    160 | 	}
 | 
|  |    161 | 
 | 
|  |    162 | 
 | 
|  |    163 | /**
 | 
|  |    164 | Send a command to get the nedia's capacity info.
 | 
|  |    165 | 
 | 
|  |    166 | @param aCapsInfo [OUT] A buffer to copy the capacity info to.
 | 
|  |    167 | 
 | 
|  |    168 | @return TInt KErrNone, if the send operation is successful;
 | 
|  |    169 | KErrServerTerminated, if the server no longer present; KErrServerBusy, if there
 | 
|  |    170 | are no message slots available; KErrNoMemory, if there is insufficient memory
 | 
|  |    171 | available.
 | 
|  |    172 | */
 | 
|  |    173 | EXPORT_C TInt RUsbHostMsLogicalUnit::Caps(TCapsInfo& aCapsInfo)
 | 
|  |    174 | 	{
 | 
|  |    175 | 	__FNLOG("RUsbHostMsLogicalUnit::Caps");
 | 
|  |    176 | 
 | 
|  |    177 |     TPckg<TCapsInfo> data(aCapsInfo);
 | 
|  |    178 | 
 | 
|  |    179 | 	/* We handle the message asynchronously in the thread modelled MSC */
 | 
|  |    180 | 	TRequestStatus	status;
 | 
|  |    181 | 	SendReceive(EUsbHostMsCapacity, TIpcArgs(&data),status);
 | 
|  |    182 | 	User::WaitForRequest(status);
 | 
|  |    183 | 	return status.Int();
 | 
|  |    184 | 	}
 | 
|  |    185 | 
 | 
|  |    186 | /**
 | 
|  |    187 | Request notification of media change to the file server
 | 
|  |    188 | 
 | 
|  |    189 | @param aChanged The descriptor pointing to iChanged flag in TDrive to be updated
 | 
|  |    190 | when error occurs during read or write.
 | 
|  |    191 | @param aStatus The request status This is set to KErrNone on completion, or KErrCancel when the logical unit is closed;
 | 
|  |    192 | 	KErrServerTerminated, if the server no longer present; KErrServerBusy, if there are no message slots available;
 | 
|  |    193 | 	KErrNoMemory, if there is insufficient memory available.
 | 
|  |    194 | @return None
 | 
|  |    195 | */
 | 
|  |    196 | EXPORT_C void RUsbHostMsLogicalUnit::NotifyChange(TDes8& aChanged, TRequestStatus &aStatus)
 | 
|  |    197 | 	{
 | 
|  |    198 | 	__FNLOG("RUsbHostMsLogicalUnit::NotifyChange");
 | 
|  |    199 | 
 | 
|  |    200 | 	SendReceive(EUsbHostMsNotifyChange, TIpcArgs(&aChanged), aStatus);
 | 
|  |    201 | 	}
 | 
|  |    202 | 
 | 
|  |    203 | /**
 | 
|  |    204 | Request to suspend the logical unit associated with this drive
 | 
|  |    205 | */
 | 
|  |    206 | EXPORT_C void RUsbHostMsLogicalUnit::SuspendLun()
 | 
|  |    207 | 	{
 | 
|  |    208 | 	__FNLOG("RUsbHostMsLogicalUnit::SuspendLun");
 | 
|  |    209 | 
 | 
|  |    210 | 	SendReceive(EUsbHostMsSuspendLun, TIpcArgs(NULL));
 | 
|  |    211 | 	}
 | 
|  |    212 | 
 | 
|  |    213 | /**
 | 
|  |    214 | Close the sub-session.
 | 
|  |    215 | 
 | 
|  |    216 | @return TInt KErrNone
 | 
|  |    217 | */
 | 
|  |    218 | EXPORT_C TInt RUsbHostMsLogicalUnit::UnInitialise()
 | 
|  |    219 | 	{
 | 
|  |    220 | 	__FNLOG("RUsbHostMsLogicalUnit::UnInitialise");
 | 
|  |    221 | 
 | 
|  |    222 | 	CloseSubSession(EUsbHostMsUnRegisterLun);
 | 
|  |    223 | 	dev.Close();
 | 
|  |    224 | 	return KErrNone;
 | 
|  |    225 | 	}
 | 
|  |    226 | 
 | 
|  |    227 | 
 | 
|  |    228 | /**
 | 
|  |    229 | Request that the drive is remounted.
 | 
|  |    230 | 
 | 
|  |    231 | @param aFlags Flags to be passed to the drive
 | 
|  |    232 | 
 | 
|  |    233 | @return EXPORT_C TInt KErrNone, if the send operation is successful;
 | 
|  |    234 | KErrServerTerminated, if the server no longer present; KErrServerBusy, if there
 | 
|  |    235 | are no message slots available; KErrNoMemory, if there is insufficient memory
 | 
|  |    236 | available.
 | 
|  |    237 | */
 | 
|  |    238 | EXPORT_C TInt RUsbHostMsLogicalUnit::ForceRemount(TUint aFlags)
 | 
|  |    239 | 	{
 | 
|  |    240 | 	__FNLOG("RUsbHostMsLogicalUnit::ForceRemount");
 | 
|  |    241 | 
 | 
|  |    242 | 	__PRINT1(_L("flags = %d"), aFlags);
 | 
|  |    243 | 
 | 
|  |    244 | 	TRequestStatus	status;
 | 
|  |    245 | 	SendReceive(EUsbHostMsForceRemount, TIpcArgs(aFlags), status);
 | 
|  |    246 | 	User::WaitForRequest(status);
 | 
|  |    247 | 	return status.Int();
 | 
|  |    248 | 	}
 | 
|  |    249 | 
 | 
|  |    250 | EXPORT_C void RUsbHostMsLogicalUnit::NotifyChangeCancel()
 | 
|  |    251 | 	{
 | 
|  |    252 | 	__FNLOG("RUsbHostMsLogicalUnit::NotifyChangeCancel");
 | 
|  |    253 | 	SendReceive(EUsbHostMsCancelChangeNotifier, TIpcArgs(NULL));
 | 
|  |    254 | 	}
 |