os/kernelhwsrv/kerneltest/f32test/shostmassstorage/testclient/usbtestmsclient/protocol/tscsiserverreq.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 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 #include <e32def.h>
    18 #include <e32cmn.h>
    19 #include <e32des8.h>
    20 #include <e32std.h>
    21 #include <e32base.h>
    22 
    23 #include "msctypes.h"
    24 #include "tscsiserverreq.h"
    25 #include "tscsiservercmds.h"
    26 #include "debug.h"
    27 #include "msdebug.h"
    28 
    29 TScsiServerReq* TScsiServerReq::CreateL(TScsiServerReq::TOperationCode aOperationCode,
    30                                         TDesC8& aDes)
    31     {
    32     __MSFNSLOG
    33     TScsiServerReq* req = NULL;
    34 
    35     __SCSIPRINT1(_L("SCSI CMD 0x%x"), aOperationCode);
    36 
    37     switch (aOperationCode)
    38         {
    39         case ETestUnitReady:
    40             {
    41             req = new (ELeave) TScsiServerTestUnitReadyReq;
    42             }
    43             break;
    44         case ERequestSense:
    45             {
    46             req = new (ELeave) TScsiServerRequestSenseReq;
    47             }
    48             break;
    49         case EInquiry:
    50             {
    51             req = new (ELeave) TScsiServerInquiryReq;
    52             }
    53             break;
    54         case EModeSense6:
    55             {
    56             req = new (ELeave) TScsiServerModeSense6Req;
    57             }
    58             break;
    59         case EStartStopUnit:
    60             {
    61             req = new (ELeave) TScsiServerStartStopUnitReq;
    62             }
    63             break;
    64         case EPreventMediaRemoval:
    65             {
    66             req = new (ELeave) TScsiServerPreventMediaRemovalReq;
    67             }
    68             break;
    69         case EReadFormatCapacities:
    70             {
    71             req = new (ELeave) TScsiServerReadFormatCapacitiesReq;
    72             }
    73             break;
    74         case EReadCapacity10:
    75             {
    76             req = new (ELeave) TScsiServerReadCapacity10Req;
    77             }
    78             break;
    79 
    80         case ERead10:
    81             {
    82             req = new (ELeave) TScsiServerRead10Req;
    83             }
    84             break;
    85         case EWrite10:
    86             {
    87             req = new (ELeave) TScsiServerWrite10Req;
    88             }
    89             break;
    90         default:
    91             {
    92             __SCSIPRINT(_L("NOT SUPPORTED!"));
    93             User::Leave(KErrNotSupported);
    94             }
    95         }
    96 
    97     if (req)
    98         {
    99         CleanupStack::PushL(req);
   100         // got a class into which it can parse itself from the protocol
   101         req->DecodeL(aDes);
   102         CleanupStack::Pop(req);
   103         }
   104     return req;
   105     }
   106 
   107 
   108 void TScsiServerReq::DecodeL(const TDesC8& aPtr)
   109     {
   110     __MSFNLOG
   111     // OPERATION CODE
   112 	iOperationCode = static_cast<TOperationCode>(aPtr[0]);
   113 
   114     // CONTROL byte
   115     TInt length = 0;
   116     switch (GetGroupCode())
   117         {
   118         case 0:
   119             // 6 byte commands
   120             length = 6;
   121             break;
   122         case 1:
   123         case 2:
   124             // 10 byte commands
   125             length = 10;
   126             break;
   127         default:
   128             User::Leave(KErrNotSupported);
   129             break;
   130         }
   131 
   132 
   133     // CONTROL byte is last element of Command
   134     TUint8 control = aPtr[length - 1];
   135 
   136     iLink = control & 0x04 ? ETrue : EFalse;
   137     iNaca = control & 0x01 ? ETrue : EFalse;
   138     }