usbdrv/peripheral/pdd/pil/src/chapter9.cpp
author hgs
Wed, 20 Oct 2010 12:04:53 +0800
changeset 59 bbdce6bffaad
parent 33 089413cdde3c
permissions -rw-r--r--
201041_02
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
59
bbdce6bffaad 201041_02
hgs
parents: 33
diff changeset
     1
/*
bbdce6bffaad 201041_02
hgs
parents: 33
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
bbdce6bffaad 201041_02
hgs
parents: 33
diff changeset
     3
* All rights reserved.
bbdce6bffaad 201041_02
hgs
parents: 33
diff changeset
     4
* This component and the accompanying materials are made available
bbdce6bffaad 201041_02
hgs
parents: 33
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
bbdce6bffaad 201041_02
hgs
parents: 33
diff changeset
     6
* which accompanies this distribution, and is available
bbdce6bffaad 201041_02
hgs
parents: 33
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
bbdce6bffaad 201041_02
hgs
parents: 33
diff changeset
     8
*
bbdce6bffaad 201041_02
hgs
parents: 33
diff changeset
     9
* Initial Contributors:
bbdce6bffaad 201041_02
hgs
parents: 33
diff changeset
    10
* Nokia Corporation - initial contribution.
bbdce6bffaad 201041_02
hgs
parents: 33
diff changeset
    11
*
bbdce6bffaad 201041_02
hgs
parents: 33
diff changeset
    12
* Contributors:
bbdce6bffaad 201041_02
hgs
parents: 33
diff changeset
    13
*
bbdce6bffaad 201041_02
hgs
parents: 33
diff changeset
    14
* Description:
bbdce6bffaad 201041_02
hgs
parents: 33
diff changeset
    15
* e32/drivers/usbcc/chapter9.cpp
bbdce6bffaad 201041_02
hgs
parents: 33
diff changeset
    16
* Platform independent layer (PIL) of the USB Device controller driver:
bbdce6bffaad 201041_02
hgs
parents: 33
diff changeset
    17
* Processing of USB spec chapter 9 standard requests.
bbdce6bffaad 201041_02
hgs
parents: 33
diff changeset
    18
*
bbdce6bffaad 201041_02
hgs
parents: 33
diff changeset
    19
*/
33
089413cdde3c 201028_02
hgs
parents:
diff changeset
    20
089413cdde3c 201028_02
hgs
parents:
diff changeset
    21
/**
089413cdde3c 201028_02
hgs
parents:
diff changeset
    22
 @file chapter9.cpp
089413cdde3c 201028_02
hgs
parents:
diff changeset
    23
 @internalTechnology
089413cdde3c 201028_02
hgs
parents:
diff changeset
    24
*/
089413cdde3c 201028_02
hgs
parents:
diff changeset
    25
089413cdde3c 201028_02
hgs
parents:
diff changeset
    26
#include <usb/usbc.h>
089413cdde3c 201028_02
hgs
parents:
diff changeset
    27
089413cdde3c 201028_02
hgs
parents:
diff changeset
    28
#include "controltransfersm.h"
089413cdde3c 201028_02
hgs
parents:
diff changeset
    29
089413cdde3c 201028_02
hgs
parents:
diff changeset
    30
//#define ENABLE_EXCESSIVE_DEBUG_OUTPUT
089413cdde3c 201028_02
hgs
parents:
diff changeset
    31
//
089413cdde3c 201028_02
hgs
parents:
diff changeset
    32
// === USB Controller member function implementation - PSL API (protected) ========================
089413cdde3c 201028_02
hgs
parents:
diff changeset
    33
//
089413cdde3c 201028_02
hgs
parents:
diff changeset
    34
089413cdde3c 201028_02
hgs
parents:
diff changeset
    35
/** Used to synchronize the Ep0 state machine between the PSL and PIL.
089413cdde3c 201028_02
hgs
parents:
diff changeset
    36
    Accepts a SETUP packet and returns the next Ep0 state.
089413cdde3c 201028_02
hgs
parents:
diff changeset
    37
089413cdde3c 201028_02
hgs
parents:
diff changeset
    38
    @param aSetupBuf The SETUP packet just received by the PSL.
089413cdde3c 201028_02
hgs
parents:
diff changeset
    39
    @return The next Ep0 state.
089413cdde3c 201028_02
hgs
parents:
diff changeset
    40
089413cdde3c 201028_02
hgs
parents:
diff changeset
    41
    @publishedPartner @released
089413cdde3c 201028_02
hgs
parents:
diff changeset
    42
*/
089413cdde3c 201028_02
hgs
parents:
diff changeset
    43
UsbShai::TControlStage DUsbClientController::EnquireEp0NextStage(const TUint8* aSetupBuf) const
089413cdde3c 201028_02
hgs
parents:
diff changeset
    44
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
    45
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::EnquireEp0NextState()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
    46
089413cdde3c 201028_02
hgs
parents:
diff changeset
    47
    // This function may be called by the PSL from within an ISR -- so we have
089413cdde3c 201028_02
hgs
parents:
diff changeset
    48
    // to take care what we do here (and also in all functions that get called
089413cdde3c 201028_02
hgs
parents:
diff changeset
    49
    // from here).
089413cdde3c 201028_02
hgs
parents:
diff changeset
    50
089413cdde3c 201028_02
hgs
parents:
diff changeset
    51
    if (SWAP_BYTES_16((reinterpret_cast<const TUint16*>(aSetupBuf)[3])) == 0) // iLength
089413cdde3c 201028_02
hgs
parents:
diff changeset
    52
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
    53
        __KTRACE_OPT(KUSB, Kern::Printf("  --> EControlTransferStageStatusIn"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
    54
        return UsbShai::EControlTransferStageStatusIn;                            // No-data Control => Status_IN
089413cdde3c 201028_02
hgs
parents:
diff changeset
    55
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
    56
    else if ((aSetupBuf[0] & KUsbRequestType_DirMask) == KUsbRequestType_DirToDev)
089413cdde3c 201028_02
hgs
parents:
diff changeset
    57
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
    58
        __KTRACE_OPT(KUSB, Kern::Printf("  --> EControlTransferStageDataOut"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
    59
        return UsbShai::EControlTransferStageDataOut;                            // Control Write => Data_OUT
089413cdde3c 201028_02
hgs
parents:
diff changeset
    60
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
    61
    else
089413cdde3c 201028_02
hgs
parents:
diff changeset
    62
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
    63
        __KTRACE_OPT(KUSB, Kern::Printf("  --> EControlTransferStageDataIn"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
    64
        return UsbShai::EControlTransferStageDataIn;                                // Control Read => Data_IN
089413cdde3c 201028_02
hgs
parents:
diff changeset
    65
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
    66
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
    67
089413cdde3c 201028_02
hgs
parents:
diff changeset
    68
//
089413cdde3c 201028_02
hgs
parents:
diff changeset
    69
// About iLastError.
089413cdde3c 201028_02
hgs
parents:
diff changeset
    70
// This member is used to remember the last error happend during a
089413cdde3c 201028_02
hgs
parents:
diff changeset
    71
// processXXX likewise function.
089413cdde3c 201028_02
hgs
parents:
diff changeset
    72
//
089413cdde3c 201028_02
hgs
parents:
diff changeset
    73
// Before entry of each ProcessXXX, iLastError will be cleared to KErrNone.
089413cdde3c 201028_02
hgs
parents:
diff changeset
    74
//
089413cdde3c 201028_02
hgs
parents:
diff changeset
    75
089413cdde3c 201028_02
hgs
parents:
diff changeset
    76
// --- The USB Spec Chapter 9 Standard Endpoint Zero Device Requests ---
089413cdde3c 201028_02
hgs
parents:
diff changeset
    77
// Record error happend with iLastError, the value already been set to zero
089413cdde3c 201028_02
hgs
parents:
diff changeset
    78
// before entering ProcessSetupPacket call.
089413cdde3c 201028_02
hgs
parents:
diff changeset
    79
void DUsbClientController::ProcessGetDeviceStatus(const TUsbcSetup& aPacket)
089413cdde3c 201028_02
hgs
parents:
diff changeset
    80
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
    81
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessGetDeviceStatus()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
    82
    if ( iDeviceState < UsbShai::EUsbPeripheralStateAddress)
089413cdde3c 201028_02
hgs
parents:
diff changeset
    83
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
    84
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid device state"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
    85
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
    86
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
    87
    else
089413cdde3c 201028_02
hgs
parents:
diff changeset
    88
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
    89
        // We always assume Device is bus-powered, even though mobile phone almost always
089413cdde3c 201028_02
hgs
parents:
diff changeset
    90
        // has a battry there, because self-powered device can not required more then 100ma current
089413cdde3c 201028_02
hgs
parents:
diff changeset
    91
        // which is not acceptable for Usb charging.
089413cdde3c 201028_02
hgs
parents:
diff changeset
    92
        TBool selfPowered = EFalse;         
089413cdde3c 201028_02
hgs
parents:
diff changeset
    93
        
089413cdde3c 201028_02
hgs
parents:
diff changeset
    94
        /*  FIXME: modify selfPowered to make it compilance with following rule.
089413cdde3c 201028_02
hgs
parents:
diff changeset
    95
           
089413cdde3c 201028_02
hgs
parents:
diff changeset
    96
             1. If current draw exceeds 100mA, the device must report itself 
089413cdde3c 201028_02
hgs
parents:
diff changeset
    97
                as bus-powered during enumeration.
089413cdde3c 201028_02
hgs
parents:
diff changeset
    98
             
089413cdde3c 201028_02
hgs
parents:
diff changeset
    99
             2. In all cases, the GetStatus(DEVICE) call must accurately report 
089413cdde3c 201028_02
hgs
parents:
diff changeset
   100
                whether the device is currently operating on self- or bus-power.
089413cdde3c 201028_02
hgs
parents:
diff changeset
   101
                
089413cdde3c 201028_02
hgs
parents:
diff changeset
   102
             3. A device that is actively drawing more than 100mA from USB must 
089413cdde3c 201028_02
hgs
parents:
diff changeset
   103
                report itself as bus-powered in the GetStatus(DEVICE) call.
089413cdde3c 201028_02
hgs
parents:
diff changeset
   104
             
089413cdde3c 201028_02
hgs
parents:
diff changeset
   105
             4. Peripherals that return "Self-powered" in the GetStatus(DEVICE) 
089413cdde3c 201028_02
hgs
parents:
diff changeset
   106
                call are prohibited from drawing more than 100mA at any time.
089413cdde3c 201028_02
hgs
parents:
diff changeset
   107
        */
089413cdde3c 201028_02
hgs
parents:
diff changeset
   108
        /*   
089413cdde3c 201028_02
hgs
parents:
diff changeset
   109
        TBuf8<KUsbDescSize_Config> config;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   110
        
089413cdde3c 201028_02
hgs
parents:
diff changeset
   111
        if(iDescriptors.GetConfigurationDescriptorTC(&Kern::CurrentThread(),config) == KErrNone)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   112
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   113
            TUint8 maxPower = config[8];
089413cdde3c 201028_02
hgs
parents:
diff changeset
   114
            if(maxPower <= 50)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   115
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   116
                selfPowered = EFalse;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   117
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   118
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   119
        */
089413cdde3c 201028_02
hgs
parents:
diff changeset
   120
        
089413cdde3c 201028_02
hgs
parents:
diff changeset
   121
        const TUint16 status = ((selfPowered ? KUsbDevStat_SelfPowered : 0) |
089413cdde3c 201028_02
hgs
parents:
diff changeset
   122
                        (iRmWakeupStatus_Enabled ? KUsbDevStat_RemoteWakeup : 0));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   123
        __KTRACE_OPT(KUSB, Kern::Printf("  Reporting device status: 0x%02x", status));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   124
        *reinterpret_cast<TUint16*>(iEp0_TxBuf) = SWAP_BYTES_16(status);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   125
        if (iConTransferMgr->SetupEndpointZeroWrite(iEp0_TxBuf, sizeof(status)) == KErrNone)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   126
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   127
            iEp0WritePending = ETrue;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   128
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   129
        else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   130
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   131
            __KTRACE_OPT(KUSB, Kern::Printf("  Wrong: Write to Ep0 Failed"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   132
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   133
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   134
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   135
089413cdde3c 201028_02
hgs
parents:
diff changeset
   136
void DUsbClientController::ProcessGetInterfaceStatus(const TUsbcSetup& aPacket)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   137
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   138
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessGetInterfaceStatus()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   139
    if ( iDeviceState < UsbShai::EUsbPeripheralStateConfigured)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   140
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   141
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid device state"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   142
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   143
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   144
    else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   145
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   146
        if (InterfaceExists(aPacket.iIndex) == EFalse)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   147
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   148
            __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Interface does not exist"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   149
            iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   150
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   151
        else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   152
            {        
089413cdde3c 201028_02
hgs
parents:
diff changeset
   153
            const TUint16 status = 0x0000;                            // as of USB Spec 2.0
089413cdde3c 201028_02
hgs
parents:
diff changeset
   154
            __KTRACE_OPT(KUSB, Kern::Printf("  Reporting interface status: 0x%02x", status));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   155
            *reinterpret_cast<TUint16*>(iEp0_TxBuf) = SWAP_BYTES_16(status);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   156
            if (iConTransferMgr->SetupEndpointZeroWrite(iEp0_TxBuf, sizeof(status)) == KErrNone)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   157
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   158
                iEp0WritePending = ETrue;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   159
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   160
            else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   161
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   162
                __KTRACE_OPT(KUSB, Kern::Printf("  Wrong: Write to Ep0 Failed"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   163
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   164
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   165
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   166
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   167
089413cdde3c 201028_02
hgs
parents:
diff changeset
   168
089413cdde3c 201028_02
hgs
parents:
diff changeset
   169
void DUsbClientController::ProcessGetEndpointStatus(const TUsbcSetup& aPacket)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   170
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   171
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessGetEndpointStatus()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   172
    if (
089413cdde3c 201028_02
hgs
parents:
diff changeset
   173
        ((iDeviceState < UsbShai::EUsbPeripheralStateAddress) ||
089413cdde3c 201028_02
hgs
parents:
diff changeset
   174
         (iDeviceState == UsbShai::EUsbPeripheralStateAddress && (aPacket.iIndex & KUsbEpAddress_Portmask) != 0)))
089413cdde3c 201028_02
hgs
parents:
diff changeset
   175
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   176
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid device state"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   177
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   178
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   179
    else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   180
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   181
        if (EndpointExists(aPacket.iIndex) == EFalse)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   182
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   183
            __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Endpoint does not exist"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   184
            iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   185
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   186
        else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   187
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   188
            const TInt ep = EpAddr2Idx(aPacket.iIndex);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   189
            const TUint16 status = (iRealEndpoints[ep].iHalt) ?     KUsbEpStat_Halt : 0;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   190
            __KTRACE_OPT(KUSB, Kern::Printf("  Reporting endpoint status 0x%02x for real endpoint %d",
089413cdde3c 201028_02
hgs
parents:
diff changeset
   191
                                            status, ep));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   192
            *reinterpret_cast<TUint16*>(iEp0_TxBuf) = SWAP_BYTES_16(status);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   193
            if (iConTransferMgr->SetupEndpointZeroWrite(iEp0_TxBuf, 2) == KErrNone)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   194
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   195
                iEp0WritePending = ETrue;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   196
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   197
            else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   198
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   199
                __KTRACE_OPT(KUSB, Kern::Printf("  Wrong: Write to Ep0 Failed"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   200
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   201
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   202
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   203
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   204
089413cdde3c 201028_02
hgs
parents:
diff changeset
   205
089413cdde3c 201028_02
hgs
parents:
diff changeset
   206
void DUsbClientController::ProcessSetClearDevFeature(const TUsbcSetup& aPacket)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   207
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   208
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetClearDevFeature()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   209
    if ( iDeviceState < UsbShai::EUsbPeripheralStateDefault)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   210
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   211
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid device state"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   212
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   213
        return;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   214
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   215
089413cdde3c 201028_02
hgs
parents:
diff changeset
   216
    TInt test_sel = 0;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   217
089413cdde3c 201028_02
hgs
parents:
diff changeset
   218
    if (aPacket.iRequest == KUsbRequest_SetFeature)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   219
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   220
        switch (aPacket.iValue)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   221
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   222
            case KUsbFeature_RemoteWakeup:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   223
                if ( iDeviceState < UsbShai::EUsbPeripheralStateAddress)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   224
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   225
                    __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid device state"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   226
                    iLastError = KErrGeneral;                
089413cdde3c 201028_02
hgs
parents:
diff changeset
   227
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   228
                else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   229
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   230
                    iRmWakeupStatus_Enabled = ETrue;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   231
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   232
                break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   233
                
089413cdde3c 201028_02
hgs
parents:
diff changeset
   234
            case KUsbFeature_TestMode:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   235
                if (!iHighSpeed)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   236
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   237
                    __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Request only supported in High-Speed mode"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   238
                    iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   239
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   240
                else if (LowByte(aPacket.iIndex) != 0)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   241
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   242
                    __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Lower byte of wIndex must be zero"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   243
                    iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   244
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   245
                else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   246
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   247
                    test_sel = HighByte(aPacket.iIndex);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   248
                    if ((test_sel < UsbShai::EUsbTestSelector_Test_J) || (test_sel > UsbShai::EUsbTestSelector_Test_Force_Enable))
089413cdde3c 201028_02
hgs
parents:
diff changeset
   249
                        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   250
                        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid test selector: %d", test_sel));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   251
                        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   252
                        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   253
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   254
                break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   255
                
089413cdde3c 201028_02
hgs
parents:
diff changeset
   256
            case KUsbFeature_B_HnpEnable:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   257
                if (!iOtgSupport)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   258
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   259
                    __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Request only supported on a OTG device"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   260
                    iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   261
                    }            
089413cdde3c 201028_02
hgs
parents:
diff changeset
   262
                else if (!(iOtgFuncMap & KUsbOtgAttr_HnpSupp))
089413cdde3c 201028_02
hgs
parents:
diff changeset
   263
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   264
                    __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Request only valid if OTG device supports HNP"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   265
                    iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   266
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   267
                else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   268
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   269
                    iOtgFuncMap |= KUsbOtgAttr_B_HnpEnable;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   270
                    OtgFeaturesNotify();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   271
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   272
                break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   273
                
089413cdde3c 201028_02
hgs
parents:
diff changeset
   274
            case KUsbFeature_A_HnpSupport:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   275
                if (!iOtgSupport)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   276
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   277
                    __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Request only supported on a OTG device"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   278
                    iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   279
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   280
                else if (!(iOtgFuncMap & KUsbOtgAttr_HnpSupp))
089413cdde3c 201028_02
hgs
parents:
diff changeset
   281
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   282
                    __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Request only valid if OTG device supports HNP"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   283
                    iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   284
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   285
                else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   286
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   287
                    iOtgFuncMap |= KUsbOtgAttr_A_HnpSupport;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   288
                    OtgFeaturesNotify();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   289
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   290
                break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   291
                
089413cdde3c 201028_02
hgs
parents:
diff changeset
   292
            case KUsbFeature_A_AltHnpSupport:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   293
                if (!iOtgSupport)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   294
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   295
                    __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Request only supported on a OTG device"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   296
                    iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   297
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   298
                else if (!(iOtgFuncMap & KUsbOtgAttr_HnpSupp))
089413cdde3c 201028_02
hgs
parents:
diff changeset
   299
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   300
                    __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Request only valid if OTG device supports HNP"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   301
                    iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   302
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   303
                else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   304
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   305
                    iOtgFuncMap |= KUsbOtgAttr_A_AltHnpSupport;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   306
                    OtgFeaturesNotify();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   307
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   308
                break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   309
                
089413cdde3c 201028_02
hgs
parents:
diff changeset
   310
            default:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   311
                __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Unknown feature requested"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   312
                iLastError = KErrGeneral;                
089413cdde3c 201028_02
hgs
parents:
diff changeset
   313
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   314
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   315
    else // KUsbRequest_ClearFeature
089413cdde3c 201028_02
hgs
parents:
diff changeset
   316
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   317
        switch (aPacket.iValue)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   318
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   319
            case KUsbFeature_RemoteWakeup:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   320
                if ( iDeviceState < UsbShai::EUsbPeripheralStateAddress)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   321
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   322
                    __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid device state"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   323
                    iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   324
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   325
                else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   326
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   327
                    iRmWakeupStatus_Enabled = EFalse;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   328
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   329
                break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   330
                
089413cdde3c 201028_02
hgs
parents:
diff changeset
   331
            default:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   332
                __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Unknown feature requested"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   333
                iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   334
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   335
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   336
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
   337
    if(iLastError == KErrNone)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   338
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   339
        // Sent out status packet if no error found.
089413cdde3c 201028_02
hgs
parents:
diff changeset
   340
        iConTransferMgr->SendEp0ZeroByteStatusPacket();                            // success: zero bytes data during status stage
089413cdde3c 201028_02
hgs
parents:
diff changeset
   341
        
089413cdde3c 201028_02
hgs
parents:
diff changeset
   342
        // 9.4.9: "The transition to test mode of an upstream facing port must not happen until
089413cdde3c 201028_02
hgs
parents:
diff changeset
   343
        // after the status stage of the request."
089413cdde3c 201028_02
hgs
parents:
diff changeset
   344
        if (test_sel)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   345
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   346
            __KTRACE_OPT(KPANIC, Kern::Printf("  Entering HS Test Mode %d", test_sel));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   347
            iController.EnterTestMode((UsbShai::TUsbTestModeSelector)test_sel);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   348
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   349
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   350
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   351
089413cdde3c 201028_02
hgs
parents:
diff changeset
   352
089413cdde3c 201028_02
hgs
parents:
diff changeset
   353
void DUsbClientController::ProcessSetClearIfcFeature(const TUsbcSetup& aPacket)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   354
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   355
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetClearIfcFeature()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   356
    if ( iDeviceState < UsbShai::EUsbPeripheralStateConfigured)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   357
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   358
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid device state"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   359
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   360
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   361
    else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   362
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   363
        // No interface features defined in USB spec, thus
089413cdde3c 201028_02
hgs
parents:
diff changeset
   364
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   365
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   366
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   367
089413cdde3c 201028_02
hgs
parents:
diff changeset
   368
089413cdde3c 201028_02
hgs
parents:
diff changeset
   369
void DUsbClientController::ProcessSetClearEpFeature(const TUsbcSetup& aPacket)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   370
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   371
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetClearEpFeature()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   372
    if (
089413cdde3c 201028_02
hgs
parents:
diff changeset
   373
        ((iDeviceState < UsbShai::EUsbPeripheralStateAddress) ||
089413cdde3c 201028_02
hgs
parents:
diff changeset
   374
         (iDeviceState == UsbShai::EUsbPeripheralStateAddress && (aPacket.iIndex & KUsbEpAddress_Portmask) != 0)))
089413cdde3c 201028_02
hgs
parents:
diff changeset
   375
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   376
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid device state"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   377
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   378
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   379
    else if (aPacket.iValue != KUsbFeature_EndpointHalt)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   380
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   381
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Unknown feature requested"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   382
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   383
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   384
    else if (EndpointExists(aPacket.iIndex) == EFalse)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   385
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   386
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Endpoint does not exist"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   387
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   388
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   389
    else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   390
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   391
        const TInt ep = EpAddr2Idx(aPacket.iIndex);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   392
        if (iRealEndpoints[ep].iLEndpoint->iInfo.iType == UsbShai::KUsbEpTypeControl ||
089413cdde3c 201028_02
hgs
parents:
diff changeset
   393
            iRealEndpoints[ep].iLEndpoint->iInfo.iType == UsbShai::KUsbEpTypeIsochronous)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   394
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   395
            __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Endpoint is Control or Isochronous"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   396
            iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   397
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   398
        else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   399
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   400
            SetClearHaltFeature(ep, aPacket.iRequest);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   401
        
089413cdde3c 201028_02
hgs
parents:
diff changeset
   402
            // success: zero bytes data during status stage
089413cdde3c 201028_02
hgs
parents:
diff changeset
   403
            iConTransferMgr->SendEp0ZeroByteStatusPacket();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   404
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   405
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   406
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   407
089413cdde3c 201028_02
hgs
parents:
diff changeset
   408
089413cdde3c 201028_02
hgs
parents:
diff changeset
   409
void DUsbClientController::ProcessSetAddress(const TUsbcSetup& aPacket)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   410
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   411
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetAddress()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   412
    if ( iDeviceState > UsbShai::EUsbPeripheralStateAddress)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   413
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   414
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid device state"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   415
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   416
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   417
    else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   418
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   419
        const TUint16 addr = aPacket.iValue;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   420
        
089413cdde3c 201028_02
hgs
parents:
diff changeset
   421
        if (addr > 127)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   422
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   423
            __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Bad address value: %d (>127)", addr));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   424
            iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   425
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   426
        else if (addr == 0)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   427
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   428
            // Enter Default state (from Default or Address)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   429
            NextDeviceState(UsbShai::EUsbPeripheralStateDefault);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   430
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   431
        
089413cdde3c 201028_02
hgs
parents:
diff changeset
   432
        __KTRACE_OPT(KUSB, Kern::Printf("  USB address: %d", addr));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   433
        
089413cdde3c 201028_02
hgs
parents:
diff changeset
   434
        // If controller support hw acceleration,call set address first and then status
089413cdde3c 201028_02
hgs
parents:
diff changeset
   435
        if(iControllerProperties.iControllerCaps & UsbShai::KDevCapSetAddressAcceleration)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   436
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   437
            iController.SetDeviceAddress(addr);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   438
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   439
089413cdde3c 201028_02
hgs
parents:
diff changeset
   440
        // The spec says, under section 9.4.6:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   441
        // "Stages after the initial Setup packet assume the same device address as the Setup packet. The USB
089413cdde3c 201028_02
hgs
parents:
diff changeset
   442
        // device does not change its device address until after the Status stage of this request is completed
089413cdde3c 201028_02
hgs
parents:
diff changeset
   443
        // successfully. Note that this is a difference between this request and all other requests. For all other
089413cdde3c 201028_02
hgs
parents:
diff changeset
   444
        // requests, the operation indicated must be completed before the Status stage."
089413cdde3c 201028_02
hgs
parents:
diff changeset
   445
        // Therefore, here we first send the status packet and only then actually execute the request.
089413cdde3c 201028_02
hgs
parents:
diff changeset
   446
        iConTransferMgr->SendEp0ZeroByteStatusPacket();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   447
        
089413cdde3c 201028_02
hgs
parents:
diff changeset
   448
        // If controller doesn't support hw acceleration, call set address after status
089413cdde3c 201028_02
hgs
parents:
diff changeset
   449
        if((iControllerProperties.iControllerCaps & UsbShai::KDevCapSetAddressAcceleration) == 0)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   450
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   451
            iController.SetDeviceAddress(addr);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   452
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   453
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   454
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   455
089413cdde3c 201028_02
hgs
parents:
diff changeset
   456
089413cdde3c 201028_02
hgs
parents:
diff changeset
   457
void DUsbClientController::ProcessGetDescriptor(const TUsbcSetup& aPacket)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   458
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   459
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessGetDescriptor()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   460
    if ( iDeviceState < UsbShai::EUsbPeripheralStateDefault)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   461
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   462
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid device state"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   463
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   464
        return ;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   465
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   466
089413cdde3c 201028_02
hgs
parents:
diff changeset
   467
    // Make sure we assume the correct speed
089413cdde3c 201028_02
hgs
parents:
diff changeset
   468
    __ASSERT_DEBUG((iHighSpeed == CurrentlyUsingHighSpeed()), Kern::Fault(KUsbPILPanicCat, __LINE__));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   469
089413cdde3c 201028_02
hgs
parents:
diff changeset
   470
    TInt size = 0;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   471
    const TInt result = iDescriptors.FindDescriptor(HighByte(aPacket.iValue), // Type
089413cdde3c 201028_02
hgs
parents:
diff changeset
   472
                                                    LowByte(aPacket.iValue), // Index
089413cdde3c 201028_02
hgs
parents:
diff changeset
   473
                                                    aPacket.iIndex, // Language ID
089413cdde3c 201028_02
hgs
parents:
diff changeset
   474
                                                    size);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   475
089413cdde3c 201028_02
hgs
parents:
diff changeset
   476
    if ((result != KErrNone) || (size == 0))
089413cdde3c 201028_02
hgs
parents:
diff changeset
   477
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   478
        // This doesn't have to be an error - protocol-wise it's OK.
089413cdde3c 201028_02
hgs
parents:
diff changeset
   479
        __KTRACE_OPT(KUSB, Kern::Printf("  Couldn't retrieve descriptor"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   480
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   481
        return;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   482
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   483
089413cdde3c 201028_02
hgs
parents:
diff changeset
   484
    __KTRACE_OPT(KUSB, Kern::Printf("  Descriptor found, size: %d (requested: %d)",
089413cdde3c 201028_02
hgs
parents:
diff changeset
   485
                                    size, aPacket.iLength));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   486
    if (size > KUsbcBufSz_Ep0Tx)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   487
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   488
        // This should actually not be possible (i.e. we should never get here).
089413cdde3c 201028_02
hgs
parents:
diff changeset
   489
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Ep0_Tx buffer too small"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   490
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   491
    if (size > aPacket.iLength)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   492
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   493
        // Send only as much data as requested by the host
089413cdde3c 201028_02
hgs
parents:
diff changeset
   494
        size = aPacket.iLength;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   495
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   496
089413cdde3c 201028_02
hgs
parents:
diff changeset
   497
#ifdef ENABLE_EXCESSIVE_DEBUG_OUTPUT
089413cdde3c 201028_02
hgs
parents:
diff changeset
   498
    __KTRACE_OPT(KUSB,
089413cdde3c 201028_02
hgs
parents:
diff changeset
   499
                 Kern::Printf("  Data: 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x 0x%02x ...",
089413cdde3c 201028_02
hgs
parents:
diff changeset
   500
                              iEp0_TxBuf[0], iEp0_TxBuf[1], iEp0_TxBuf[2], iEp0_TxBuf[3],
089413cdde3c 201028_02
hgs
parents:
diff changeset
   501
                              iEp0_TxBuf[4], iEp0_TxBuf[5], iEp0_TxBuf[6], iEp0_TxBuf[7]));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   502
#endif
089413cdde3c 201028_02
hgs
parents:
diff changeset
   503
    // If we're about to send less bytes than expected by the host AND our number is a
089413cdde3c 201028_02
hgs
parents:
diff changeset
   504
    // multiple of the packet size, in order to indicate the end of the control transfer,
089413cdde3c 201028_02
hgs
parents:
diff changeset
   505
    // we must finally send a zero length data packet (ZLP):
089413cdde3c 201028_02
hgs
parents:
diff changeset
   506
    const TBool zlp = ((size < aPacket.iLength) && (size % iEp0MaxPacketSize == 0));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   507
    if (iConTransferMgr->SetupEndpointZeroWrite(iEp0_TxBuf, size, zlp) == KErrNone)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   508
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   509
        iEp0WritePending = ETrue;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   510
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   511
    else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   512
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   513
        __KTRACE_OPT(KUSB, Kern::Printf("  Wrong: Write to Ep0 Failed"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   514
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   515
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   516
089413cdde3c 201028_02
hgs
parents:
diff changeset
   517
089413cdde3c 201028_02
hgs
parents:
diff changeset
   518
void DUsbClientController::ProcessSetDescriptor(const TUsbcSetup& aPacket)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   519
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   520
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetDescriptor()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   521
#ifndef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
089413cdde3c 201028_02
hgs
parents:
diff changeset
   522
    iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   523
    return;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   524
#else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   525
    if ( iDeviceState < UsbShai::EUsbPeripheralStateAddress)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   526
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   527
        // Error: Invalid device state!
089413cdde3c 201028_02
hgs
parents:
diff changeset
   528
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   529
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   530
    else if (aPacket.iLength > KUsbcBufSz_Ep0Rx)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   531
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   532
        // Error: Our Rx buffer is too small! (Raise a defect to make it larger)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   533
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Ep0_Rx buffer too small"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   534
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   535
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   536
    else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   537
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   538
        SetEp0DataOutVars();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   539
        iConTransferMgr->SetupEndpointZeroRead();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   540
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   541
#endif
089413cdde3c 201028_02
hgs
parents:
diff changeset
   542
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   543
089413cdde3c 201028_02
hgs
parents:
diff changeset
   544
void DUsbClientController::ProcessGetConfiguration(const TUsbcSetup& aPacket)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   545
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   546
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessGetConfiguration()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   547
    if ( iDeviceState < UsbShai::EUsbPeripheralStateAddress)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   548
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   549
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid device state"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   550
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   551
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   552
    else if ( iDeviceState == UsbShai::EUsbPeripheralStateAddress && iCurrentConfig != 0)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   553
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   554
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: DeviceState Address && Config != 0"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   555
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   556
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   557
    else if ( iDeviceState == UsbShai::EUsbPeripheralStateConfigured && iCurrentConfig == 0)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   558
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   559
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: DeviceState Configured && Config == 0"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   560
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   561
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   562
    else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   563
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   564
        if (aPacket.iLength != 1)                                // "unspecified behavior"
089413cdde3c 201028_02
hgs
parents:
diff changeset
   565
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   566
            __KTRACE_OPT(KUSB, Kern::Printf("  Warning: wLength != 1 (= %d)", aPacket.iLength));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   567
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   568
        __KTRACE_OPT(KUSB, Kern::Printf("  Reporting configuration value %d", iCurrentConfig));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   569
        if (iConTransferMgr->SetupEndpointZeroWrite(&iCurrentConfig, sizeof(iCurrentConfig)) == KErrNone)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   570
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   571
            iEp0WritePending = ETrue;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   572
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   573
        else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   574
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   575
            __KTRACE_OPT(KUSB, Kern::Printf("  Wrong: Write to Ep0 Failed"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   576
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   577
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   578
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   579
089413cdde3c 201028_02
hgs
parents:
diff changeset
   580
089413cdde3c 201028_02
hgs
parents:
diff changeset
   581
/** Changes the device's configuration value, including interface setup and/or
089413cdde3c 201028_02
hgs
parents:
diff changeset
   582
    teardown and state change notification of higher-layer clients.
089413cdde3c 201028_02
hgs
parents:
diff changeset
   583
    May also be called by the PSL in special cases - therefore publishedPartner.
089413cdde3c 201028_02
hgs
parents:
diff changeset
   584
089413cdde3c 201028_02
hgs
parents:
diff changeset
   585
    @param aPacket The received Ep0 SET_CONFIGURATION setup request packet.
089413cdde3c 201028_02
hgs
parents:
diff changeset
   586
    @return KErrGeneral in case of a protocol error, KErrNone otherwise.
089413cdde3c 201028_02
hgs
parents:
diff changeset
   587
089413cdde3c 201028_02
hgs
parents:
diff changeset
   588
    @publishedPartner @released
089413cdde3c 201028_02
hgs
parents:
diff changeset
   589
*/
089413cdde3c 201028_02
hgs
parents:
diff changeset
   590
TInt DUsbClientController::ProcessSetConfiguration(const TUsbcSetup& aPacket)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   591
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   592
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetConfiguration()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   593
089413cdde3c 201028_02
hgs
parents:
diff changeset
   594
    // This function may be called by the PSL from within an ISR -- so we have
089413cdde3c 201028_02
hgs
parents:
diff changeset
   595
    // to take care what we do here (and also in all functions that get called
089413cdde3c 201028_02
hgs
parents:
diff changeset
   596
    // from here).
089413cdde3c 201028_02
hgs
parents:
diff changeset
   597
    const TInt value = aPacket.iValue;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   598
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
   599
    if ( iDeviceState < UsbShai::EUsbPeripheralStateAddress)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   600
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   601
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid device state"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   602
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   603
        }    
089413cdde3c 201028_02
hgs
parents:
diff changeset
   604
    else if (value > 1)                                            // we support only one configuration
089413cdde3c 201028_02
hgs
parents:
diff changeset
   605
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   606
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Configuration value too large: %d", value));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   607
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   608
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   609
    else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   610
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   611
        __KTRACE_OPT(KUSB, Kern::Printf("  Configuration value: %d", value));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   612
        ChangeConfiguration(value);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   613
089413cdde3c 201028_02
hgs
parents:
diff changeset
   614
        // In 9.4.5 under GET_STATUS we read, that after SET_CONFIGURATION the HALT feature
089413cdde3c 201028_02
hgs
parents:
diff changeset
   615
        // for all endpoints is reset to zero.
089413cdde3c 201028_02
hgs
parents:
diff changeset
   616
        TInt num = 0;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   617
        (TAny) DoForEveryEndpointInUse(&DUsbClientController::ClearHaltFeature, num);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   618
        __KTRACE_OPT(KUSB, Kern::Printf("  Called ClearHaltFeature() for %d endpoints", num));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   619
        // success: zero bytes data during status stage
089413cdde3c 201028_02
hgs
parents:
diff changeset
   620
        iConTransferMgr->SendEp0ZeroByteStatusPacket();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   621
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   622
        
089413cdde3c 201028_02
hgs
parents:
diff changeset
   623
    return iLastError;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   624
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   625
089413cdde3c 201028_02
hgs
parents:
diff changeset
   626
void DUsbClientController::ProcessGetInterface(const TUsbcSetup& aPacket)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   627
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   628
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessGetInterface()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   629
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
   630
    const TInt number = aPacket.iIndex;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   631
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
   632
    if ( iDeviceState < UsbShai::EUsbPeripheralStateConfigured)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   633
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   634
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid device state"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   635
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   636
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   637
    else if (iCurrentConfig == 0)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   638
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   639
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Device not configured"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   640
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   641
        }    
089413cdde3c 201028_02
hgs
parents:
diff changeset
   642
    else if (!InterfaceExists(number))
089413cdde3c 201028_02
hgs
parents:
diff changeset
   643
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   644
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Bad interface index: %d", number));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   645
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   646
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   647
    else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   648
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   649
        // Send alternate setting code of iCurrentInterface of Interface(set) <number> of the current
089413cdde3c 201028_02
hgs
parents:
diff changeset
   650
        // config (iCurrentConfig).
089413cdde3c 201028_02
hgs
parents:
diff changeset
   651
        const TUint8 setting = InterfaceNumber2InterfacePointer(number)->iCurrentInterface;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   652
        __KTRACE_OPT(KUSB, Kern::Printf("  Reporting interface setting %d", setting));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   653
        if (iConTransferMgr->SetupEndpointZeroWrite(&setting, 1) == KErrNone)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   654
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   655
            iEp0WritePending = ETrue;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   656
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   657
        else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   658
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   659
            __KTRACE_OPT(KUSB, Kern::Printf("  Wrong: Write to Ep0 Failed"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   660
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   661
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   662
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   663
089413cdde3c 201028_02
hgs
parents:
diff changeset
   664
089413cdde3c 201028_02
hgs
parents:
diff changeset
   665
void DUsbClientController::ProcessSetInterface(const TUsbcSetup& aPacket)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   666
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   667
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSetInterface()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   668
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
   669
    const TInt number = aPacket.iIndex;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   670
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
   671
    if ( iDeviceState < UsbShai::EUsbPeripheralStateConfigured)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   672
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   673
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid device state"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   674
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   675
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   676
    else if (iCurrentConfig == 0)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   677
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   678
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Device not configured"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   679
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   680
        }    
089413cdde3c 201028_02
hgs
parents:
diff changeset
   681
    else if (!InterfaceExists(number))
089413cdde3c 201028_02
hgs
parents:
diff changeset
   682
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   683
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Bad interface index: %d", number));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   684
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   685
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   686
    else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   687
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   688
        const TInt setting = aPacket.iValue;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   689
        TUsbcInterfaceSet* const ifcset_ptr = InterfaceNumber2InterfacePointer(number);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   690
        RPointerArray<TUsbcInterface>& ifcs = ifcset_ptr->iInterfaces;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   691
        if (setting >= ifcs.Count())
089413cdde3c 201028_02
hgs
parents:
diff changeset
   692
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   693
            __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Alt Setting >= bNumAltSettings: %d", setting));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   694
            iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   695
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   696
        else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   697
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   698
            __KTRACE_OPT(KUSB, Kern::Printf("  Interface setting:: %d", setting));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   699
            // Set iCurrentInterface of Interface(set) <number> of the current config
089413cdde3c 201028_02
hgs
parents:
diff changeset
   700
            // (iCurrentConfig) to alternate setting <setting>.
089413cdde3c 201028_02
hgs
parents:
diff changeset
   701
            ChangeInterface(ifcs[setting]);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   702
            // In 9.4.5 under GET_STATUS we read, that after SET_INTERFACE the HALT feature
089413cdde3c 201028_02
hgs
parents:
diff changeset
   703
            // for all endpoints (of the now current interface setting) is reset to zero.
089413cdde3c 201028_02
hgs
parents:
diff changeset
   704
            RPointerArray<TUsbcLogicalEndpoint>& eps = ifcset_ptr->CurrentInterface()->iEndpoints;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   705
            const TInt num_eps = eps.Count();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   706
            for (TInt i = 0; i < num_eps; i++)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   707
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   708
                const TInt ep_num = EpAddr2Idx(eps[i]->iPEndpoint->iEndpointAddr);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   709
                (TAny) ClearHaltFeature(ep_num);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   710
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   711
            // success: zero bytes data during status stage
089413cdde3c 201028_02
hgs
parents:
diff changeset
   712
            iConTransferMgr->SendEp0ZeroByteStatusPacket();    
089413cdde3c 201028_02
hgs
parents:
diff changeset
   713
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   714
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   715
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   716
089413cdde3c 201028_02
hgs
parents:
diff changeset
   717
089413cdde3c 201028_02
hgs
parents:
diff changeset
   718
void DUsbClientController::ProcessSynchFrame(const TUsbcSetup& aPacket)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   719
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   720
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProcessSynchFrame()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   721
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
   722
    const TInt ep = aPacket.iIndex;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   723
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
   724
    if ( iDeviceState < UsbShai::EUsbPeripheralStateConfigured)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   725
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   726
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid device state"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   727
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   728
        }    
089413cdde3c 201028_02
hgs
parents:
diff changeset
   729
    else if (EndpointExists(ep) == EFalse)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   730
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   731
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Endpoint does not exist"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   732
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   733
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   734
    else if (iRealEndpoints[EpAddr2Idx(ep)].iLEndpoint->iInfo.iType != UsbShai::KUsbEpTypeIsochronous)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   735
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   736
        __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Endpoint is not isochronous"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   737
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   738
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   739
    else 
089413cdde3c 201028_02
hgs
parents:
diff changeset
   740
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   741
        // We always send 0:
089413cdde3c 201028_02
hgs
parents:
diff changeset
   742
        *reinterpret_cast<TUint16*>(iEp0_TxBuf) = 0x00;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   743
        if (iConTransferMgr->SetupEndpointZeroWrite(iEp0_TxBuf, 2) == KErrNone)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   744
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   745
            iEp0WritePending = ETrue;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   746
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   747
        else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   748
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   749
            __KTRACE_OPT(KUSB, Kern::Printf("  Wrong: Write to Ep0 Failed"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   750
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   751
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   752
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   753
089413cdde3c 201028_02
hgs
parents:
diff changeset
   754
089413cdde3c 201028_02
hgs
parents:
diff changeset
   755
#ifdef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST
089413cdde3c 201028_02
hgs
parents:
diff changeset
   756
void DUsbClientController::ProceedSetDescriptor()
089413cdde3c 201028_02
hgs
parents:
diff changeset
   757
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   758
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ProceedSetDescriptor()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   759
    // iEp0DataReceived already reflects the current buffer state
089413cdde3c 201028_02
hgs
parents:
diff changeset
   760
    if (iEp0DataReceived < iConTransferMgr->PktParser().DataLength())
089413cdde3c 201028_02
hgs
parents:
diff changeset
   761
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   762
        // Not yet all data received => proceed
089413cdde3c 201028_02
hgs
parents:
diff changeset
   763
        return;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   764
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   765
    if (iEp0DataReceived > iConTransferMgr->PktParser().DataLength())
089413cdde3c 201028_02
hgs
parents:
diff changeset
   766
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   767
        // Error: more data received than expected
089413cdde3c 201028_02
hgs
parents:
diff changeset
   768
        // but we don't care...
089413cdde3c 201028_02
hgs
parents:
diff changeset
   769
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   770
    const TUint8 type = HighByte(iConTransferMgr->PktParser().Value());
089413cdde3c 201028_02
hgs
parents:
diff changeset
   771
    if (type == KUsbDescType_String)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   772
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   773
        // set/add new string descriptor
089413cdde3c 201028_02
hgs
parents:
diff changeset
   774
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   775
    else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   776
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   777
        // set/add new ordinary descriptor
089413cdde3c 201028_02
hgs
parents:
diff changeset
   778
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   779
    TUint8 index = LowByte(iConTransferMgr->PktParser().Value());
089413cdde3c 201028_02
hgs
parents:
diff changeset
   780
    TUint16 langid = iConTransferMgr->PktParser().Index();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   781
    TUint16 length_total = iConTransferMgr->PktParser().DataLength();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   782
089413cdde3c 201028_02
hgs
parents:
diff changeset
   783
    iConTransferMgr->SendEp0ZeroByteStatusPacket();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   784
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   785
#endif
089413cdde3c 201028_02
hgs
parents:
diff changeset
   786
089413cdde3c 201028_02
hgs
parents:
diff changeset
   787
089413cdde3c 201028_02
hgs
parents:
diff changeset
   788
// --- Secondary (Helper) Functions
089413cdde3c 201028_02
hgs
parents:
diff changeset
   789
089413cdde3c 201028_02
hgs
parents:
diff changeset
   790
void DUsbClientController::SetClearHaltFeature(TInt aRealEndpoint, TUint8 aRequest)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   791
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   792
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::SetClearHaltFeature()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   793
    if (aRequest == KUsbRequest_SetFeature)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   794
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   795
        if (iRealEndpoints[aRealEndpoint].iHalt)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   796
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   797
            // (This condition is not really an error)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   798
            __KTRACE_OPT(KUSB, Kern::Printf("  Warning: HALT feature already set"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   799
            return;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   800
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   801
        __KTRACE_OPT(KUSB, Kern::Printf("  setting HALT feature for real endpoint %d",
089413cdde3c 201028_02
hgs
parents:
diff changeset
   802
                                        aRealEndpoint));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   803
        iController.StallEndpoint(aRealEndpoint);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   804
        iRealEndpoints[aRealEndpoint].iHalt = ETrue;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   805
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   806
    else                                                    // KUsbRequest_ClearFeature
089413cdde3c 201028_02
hgs
parents:
diff changeset
   807
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   808
        if (iRealEndpoints[aRealEndpoint].iHalt == EFalse)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   809
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   810
            // In this case, before we return, the data toggles are reset to DATA0.
089413cdde3c 201028_02
hgs
parents:
diff changeset
   811
            __KTRACE_OPT(KUSB, Kern::Printf("  Warning: HALT feature already cleared"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   812
            iController.ResetDataToggle(aRealEndpoint);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   813
            return;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   814
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   815
        __KTRACE_OPT(KUSB, Kern::Printf("  clearing HALT feature for real endpoint %d",
089413cdde3c 201028_02
hgs
parents:
diff changeset
   816
                                        aRealEndpoint));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   817
        iController.ResetDataToggle(aRealEndpoint);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   818
        iController.ClearStallEndpoint(aRealEndpoint);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   819
        iRealEndpoints[aRealEndpoint].iHalt = EFalse;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   820
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   821
    EpStatusNotify(aRealEndpoint);                            // only called if actually something changed
089413cdde3c 201028_02
hgs
parents:
diff changeset
   822
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   823
089413cdde3c 201028_02
hgs
parents:
diff changeset
   824
089413cdde3c 201028_02
hgs
parents:
diff changeset
   825
TInt DUsbClientController::ClearHaltFeature(TInt aRealEndpoint)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   826
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   827
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ClearHaltFeature()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   828
    if (iRealEndpoints[aRealEndpoint].iHalt != EFalse)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   829
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   830
        iController.ClearStallEndpoint(aRealEndpoint);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   831
        iRealEndpoints[aRealEndpoint].iHalt = EFalse;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   832
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   833
    return KErrNone;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   834
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   835
089413cdde3c 201028_02
hgs
parents:
diff changeset
   836
089413cdde3c 201028_02
hgs
parents:
diff changeset
   837
void DUsbClientController::ChangeConfiguration(TUint16 aValue)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   838
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   839
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ChangeConfiguration()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   840
    // New configuration is the same as the old one: 0
089413cdde3c 201028_02
hgs
parents:
diff changeset
   841
    if (iCurrentConfig == 0 && aValue == 0)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   842
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   843
        // no-op
089413cdde3c 201028_02
hgs
parents:
diff changeset
   844
        __KTRACE_OPT(KUSB, Kern::Printf("  Configuration: New == Old == 0 --> exiting"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   845
        return;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   846
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   847
    // New configuration is the same as the old one (but not 0)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   848
    if (iCurrentConfig == aValue)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   849
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   850
        // no-op
089413cdde3c 201028_02
hgs
parents:
diff changeset
   851
        __KTRACE_OPT(KUSB, Kern::Printf("  Configuration: New == Old == %d --> exiting", aValue));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   852
        return;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   853
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   854
    // Device is already configured
089413cdde3c 201028_02
hgs
parents:
diff changeset
   855
    if (iCurrentConfig != 0)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   856
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   857
        __KTRACE_OPT(KUSB, Kern::Printf("  Device was configured: %d", iCurrentConfig));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   858
        // Tear down all interface(set)s of the old configuration
089413cdde3c 201028_02
hgs
parents:
diff changeset
   859
        RPointerArray<TUsbcInterfaceSet>& ifcsets = CurrentConfig()->iInterfaceSets;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   860
        for (TInt i = 0; i < ifcsets.Count(); ++i)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   861
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   862
            __KTRACE_OPT(KUSB, Kern::Printf("  Tearing down InterfaceSet %d", i));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   863
            InterfaceSetTeardown(ifcsets[i]);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   864
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   865
        iCurrentConfig = 0;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   866
        // Enter Address state (from Configured)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   867
        if (iDeviceState == UsbShai::EUsbPeripheralStateConfigured)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   868
            NextDeviceState(UsbShai::EUsbPeripheralStateAddress);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   869
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   870
    // Device gets a new configuration
089413cdde3c 201028_02
hgs
parents:
diff changeset
   871
    if (aValue != 0)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   872
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   873
        __KTRACE_OPT(KUSB, Kern::Printf("  Device gets new configuration..."));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   874
        // Setup all alternate settings 0 of all interfaces
089413cdde3c 201028_02
hgs
parents:
diff changeset
   875
        // (Don't separate the next two lines of code.)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   876
        iCurrentConfig = aValue;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   877
        RPointerArray<TUsbcInterfaceSet>& ifcsets = CurrentConfig()->iInterfaceSets;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   878
        const TInt n = ifcsets.Count();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   879
        for (TInt i = 0; i < n; ++i)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   880
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   881
            __KTRACE_OPT(KUSB, Kern::Printf("  Setting up InterfaceSet %d", i));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   882
            InterfaceSetup(ifcsets[i]->iInterfaces[0]);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   883
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   884
        // Enter Configured state (from Address or Configured)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   885
        NextDeviceState(UsbShai::EUsbPeripheralStateConfigured);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   886
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   887
    __KTRACE_OPT(KUSB, Kern::Printf("  New configuration: %d", iCurrentConfig));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   888
    return;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   889
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   890
089413cdde3c 201028_02
hgs
parents:
diff changeset
   891
089413cdde3c 201028_02
hgs
parents:
diff changeset
   892
void DUsbClientController::InterfaceSetup(TUsbcInterface* aIfc)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   893
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   894
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::InterfaceSetup()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   895
    const TInt num_eps = aIfc->iEndpoints.Count();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   896
    for (TInt i = 0; i < num_eps; i++)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   897
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   898
        // Prepare this endpoint for I/O
089413cdde3c 201028_02
hgs
parents:
diff changeset
   899
        TUsbcLogicalEndpoint* const ep = aIfc->iEndpoints[i];
089413cdde3c 201028_02
hgs
parents:
diff changeset
   900
        // (TUsbcLogicalEndpoint's FS/HS endpoint sizes and interval values got
089413cdde3c 201028_02
hgs
parents:
diff changeset
   901
        //  adjusted in its constructor.)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   902
        if (iHighSpeed)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   903
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   904
            __KTRACE_OPT(KUSB, Kern::Printf("  Setting Ep info size to %d (HS)", ep->iEpSize_Hs));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   905
            ep->iInfo.iSize = ep->iEpSize_Hs;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   906
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   907
        else
089413cdde3c 201028_02
hgs
parents:
diff changeset
   908
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   909
            __KTRACE_OPT(KUSB, Kern::Printf("  Setting Ep info size to %d (FS)", ep->iEpSize_Fs));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   910
            ep->iInfo.iSize = ep->iEpSize_Fs;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   911
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   912
        const TInt idx = EpAddr2Idx(ep->iPEndpoint->iEndpointAddr);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   913
        if (iController.ConfigureEndpoint(idx, ep->iInfo) != KErrNone)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   914
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   915
            __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Endpoint %d configuration failed", idx));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   916
            continue;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   917
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   918
        // Should there be a problem with it then we could try resetting the ep
089413cdde3c 201028_02
hgs
parents:
diff changeset
   919
        // data toggle at this point (or before the Configure) as well.
089413cdde3c 201028_02
hgs
parents:
diff changeset
   920
        __KTRACE_OPT(KUSB, Kern::Printf("  Connecting real ep addr 0x%02x & logical ep #%d",
089413cdde3c 201028_02
hgs
parents:
diff changeset
   921
                                        ep->iPEndpoint->iEndpointAddr, ep->iLEndpointNum));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   922
        ep->iPEndpoint->iLEndpoint = ep;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   923
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   924
    aIfc->iInterfaceSet->iCurrentInterface = aIfc->iSettingCode;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   925
    return;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   926
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   927
089413cdde3c 201028_02
hgs
parents:
diff changeset
   928
089413cdde3c 201028_02
hgs
parents:
diff changeset
   929
void DUsbClientController::InterfaceSetTeardown(TUsbcInterfaceSet* aIfcSet)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   930
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   931
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::InterfaceSetTeardown()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   932
    if (aIfcSet->iInterfaces.Count() == 0)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   933
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   934
        __KTRACE_OPT(KUSB, Kern::Printf("  No interfaces exist - returning"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   935
        return;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   936
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   937
    RPointerArray<TUsbcLogicalEndpoint>& eps = aIfcSet->CurrentInterface()->iEndpoints;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   938
    const TInt num_eps = eps.Count();
089413cdde3c 201028_02
hgs
parents:
diff changeset
   939
    for (TInt i = 0; i < num_eps; i++)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   940
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   941
        TUsbcLogicalEndpoint* const ep = eps[i];
089413cdde3c 201028_02
hgs
parents:
diff changeset
   942
        const TInt idx = EpAddr2Idx(ep->iPEndpoint->iEndpointAddr);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   943
089413cdde3c 201028_02
hgs
parents:
diff changeset
   944
        CancelTransferRequests(idx);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   945
089413cdde3c 201028_02
hgs
parents:
diff changeset
   946
        if (!ep->iPEndpoint->iLEndpoint)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   947
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   948
            __KTRACE_OPT(KUSB, Kern::Printf("  real ep %d not configured: skipping", idx));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   949
            continue;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   950
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   951
        if (iController.ResetDataToggle(idx) != KErrNone)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   952
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   953
            __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Endpoint %d data toggle reset failed", idx));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   954
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   955
        if (iController.DeConfigureEndpoint(idx) != KErrNone)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   956
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   957
            __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Endpoint %d de-configuration failed", idx));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   958
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   959
089413cdde3c 201028_02
hgs
parents:
diff changeset
   960
        __KTRACE_OPT(KUSB, Kern::Printf("  disconnecting real ep & logical ep"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   961
        ep->iPEndpoint->iLEndpoint = NULL;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   962
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   963
    if (aIfcSet->CurrentInterface() != 0)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   964
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   965
        __KTRACE_OPT(KUSB, Kern::Printf("  Resetting alternate interface setting to 0"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   966
        //Add this mutex to protect the interface set data structure
089413cdde3c 201028_02
hgs
parents:
diff changeset
   967
        if (NKern::CurrentContext() == EThread)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   968
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   969
            NKern::FMWait(&iMutex);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   970
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   971
        
089413cdde3c 201028_02
hgs
parents:
diff changeset
   972
        aIfcSet->iCurrentInterface = 0;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   973
        if (NKern::CurrentContext() == EThread)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   974
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   975
            NKern::FMSignal(&iMutex);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   976
            }        
089413cdde3c 201028_02
hgs
parents:
diff changeset
   977
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   978
    return;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   979
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   980
089413cdde3c 201028_02
hgs
parents:
diff changeset
   981
089413cdde3c 201028_02
hgs
parents:
diff changeset
   982
void DUsbClientController::ChangeInterface(TUsbcInterface* aIfc)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   983
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   984
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::ChangeInterface()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   985
    TUsbcInterfaceSet* ifcset = aIfc->iInterfaceSet;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   986
    const TUint8 setting = aIfc->iSettingCode;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   987
    if (ifcset->iCurrentInterface == setting)
089413cdde3c 201028_02
hgs
parents:
diff changeset
   988
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
   989
        __KTRACE_OPT(KUSB, Kern::Printf("  New Ifc == old Ifc: nothing to do"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   990
        return;
089413cdde3c 201028_02
hgs
parents:
diff changeset
   991
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   992
    __KTRACE_OPT(KUSB, Kern::Printf("  Setting new interface setting #%d", setting));
089413cdde3c 201028_02
hgs
parents:
diff changeset
   993
    InterfaceSetTeardown(ifcset);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   994
    InterfaceSetup(aIfc);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   995
    StatusNotify(static_cast<UsbShai::TUsbPeripheralState>(KUsbAlternateSetting | setting), ifcset->iClientId);
089413cdde3c 201028_02
hgs
parents:
diff changeset
   996
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
   997
089413cdde3c 201028_02
hgs
parents:
diff changeset
   998
089413cdde3c 201028_02
hgs
parents:
diff changeset
   999
// aFunction gets called, successively, with the endpoint index of every ep in-use as its argument.
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1000
// (BTW: The declaration "type (class::*name)(params)" makes <name> a "pointer to element function".)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1001
//
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1002
TInt DUsbClientController::DoForEveryEndpointInUse(TInt (DUsbClientController::*aFunction)(TInt), TInt& aCount)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1003
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1004
    __KTRACE_OPT(KUSB, Kern::Printf("DUsbClientController::DoForEveryEndpointInUse()"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1005
    aCount = 0;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1006
    TUsbcConfiguration* const config = CurrentConfig();
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1007
    if (!config)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1008
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1009
        __KTRACE_OPT(KUSB, Kern::Printf("  Device is not configured - returning"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1010
        return KErrNone;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1011
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1012
    RPointerArray<TUsbcInterfaceSet>& ifcsets = config->iInterfaceSets;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1013
    const TInt num_ifcsets = ifcsets.Count();
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1014
    for (TInt i = 0; i < num_ifcsets; i++)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1015
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1016
        RPointerArray<TUsbcLogicalEndpoint>& eps = ifcsets[i]->CurrentInterface()->iEndpoints;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1017
        const TInt num_eps = eps.Count();
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1018
        for (TInt j = 0; j < num_eps; j++)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1019
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1020
            const TInt ep_num = EpAddr2Idx(eps[j]->iPEndpoint->iEndpointAddr);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1021
            const TInt result = (this->*aFunction)(ep_num);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1022
            ++aCount;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1023
            if (result != KErrNone)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1024
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1025
                return result;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1026
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1027
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1028
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1029
    return KErrNone;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1030
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1031
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1032
// Data Tx is done.
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1033
void DUsbClientController::ProcessDataInPacket(TInt aCount,TInt aErrCode)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1034
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1035
    // Clear Error Code
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1036
    iLastError = KErrNone;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1037
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1038
    // For tx, no premature end is allowed.
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1039
    if(aErrCode != KErrNone)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1040
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1041
        // something wrong in hardware, we can do nothing as remedy
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1042
        // just stall the endpoint.
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1043
        iConTransferMgr->StallEndpoint(KEp0_In);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1044
        iConTransferMgr->SetupEndpointZeroRead();
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1045
        
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1046
        // set err code to Error general if end point is stalled
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1047
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1048
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1049
    else
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1050
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1051
        // no longer a write pending
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1052
        iEp0WritePending = EFalse;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1053
        
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1054
        // If it was a client who set up this transmission, we report to that client
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1055
        if (iEp0ClientDataTransmitting)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1056
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1057
            iEp0ClientDataTransmitting = EFalse;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1058
            TUsbcRequestCallback* const p = iRequestCallbacks[KEp0_Tx];
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1059
            
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1060
            if (p)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1061
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1062
                __ASSERT_DEBUG((p->iTransferDir == UsbShai::EControllerWrite), Kern::Fault(KUsbPILPanicCat, __LINE__));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1063
                p->iError = aErrCode;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1064
                p->iTxBytes = aCount;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1065
                
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1066
                // tell the client that the sending is done
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1067
                // later, it is possible that a status out packet comes in,
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1068
                // just ignore it.
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1069
                ProcessDataTransferDone(*p);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1070
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1071
            else
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1072
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1073
                // we should never goes here
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1074
                iConTransferMgr->StallEndpoint(KEp0_In);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1075
                
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1076
                // request not found
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1077
                iLastError = KErrNotFound;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1078
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1079
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1080
        // else
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1081
        //   it is our own who sending the data, no more action needed
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1082
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1083
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1084
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1085
// Status Rx is done    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1086
void DUsbClientController::ProcessStatusOutPacket(TInt aErrCode)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1087
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1088
    // Clear Error Code
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1089
    iLastError = KErrNone;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1090
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1091
    // Dangdang, psl saying a status out packet recieved from
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1092
    // host, but, we already completed user's writting request, just ignore it.
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1093
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1094
    // any way, receiving this means no write is pending.
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1095
    iEp0WritePending = EFalse;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1096
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1097
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1098
// Data Rx is (partial) done
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1099
void DUsbClientController::ProcessDataOutPacket(TInt aCount,TInt aErrCode)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1100
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1101
    // Clear Error Code
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1102
    iLastError = KErrNone;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1103
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1104
    if (aErrCode != KErrNone && aErrCode != KErrPrematureEnd)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1105
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1106
        // something wrong in hardware, we can do nothing as remedy
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1107
        // just stall the endpoint.
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1108
        iConTransferMgr->StallEndpoint(KEp0_Out);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1109
        iConTransferMgr->SetupEndpointZeroRead();
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1110
        
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1111
        // set err code to Error general if end point is stalled
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1112
        iLastError = KErrGeneral;       
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1113
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1114
    else
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1115
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1116
        // Trim aCount with iEp0MaxPacketSize per packet
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1117
        if (aCount > iEp0MaxPacketSize)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1118
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1119
            aCount = iEp0MaxPacketSize;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1120
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1121
               
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1122
        iEp0DataReceived += aCount;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1123
        
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1124
        if (iEp0ClientId == NULL)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1125
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1126
            // it is us( not an app), who owns this transaction
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1127
            switch( iConTransferMgr->PktParser().Request())
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1128
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1129
#ifdef USB_SUPPORTS_SET_DESCRIPTOR_REQUEST                
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1130
                case KUsbRequest_SetDescriptor:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1131
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1132
                    memcpy(iEp0_RxCollectionBuf + iEp0DataReceived, iEp0_RxBuf, aCount);                    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1133
                    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1134
                    // Status will be sent in side this function
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1135
                    // if we had recieved enough bytes
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1136
                    ProceedSetDescriptor();
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1137
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1138
                    break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1139
#endif                    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1140
                default:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1141
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1142
                    iConTransferMgr->StallEndpoint(KEp0_In);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1143
                    ResetEp0DataOutVars();
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1144
                    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1145
                    // set err code to Error general if end point is stalled
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1146
                    iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1147
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1148
                    break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1149
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1150
            
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1151
            if (iEp0DataReceived >= iConTransferMgr->PktParser().DataLength())
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1152
                {                
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1153
                // all data seems now to be here
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1154
                ResetEp0DataOutVars();
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1155
                }                
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1156
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1157
        else
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1158
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1159
            // it is an application who is requesting this data
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1160
            // pass the data on to a client
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1161
            
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1162
            // it is the client's responsibility of sending a status
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1163
            // packet back to host to indicate the whole transfer is
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1164
            // done
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1165
            
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1166
            // Find the client Request callback
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1167
            TSglQueIter<TUsbcRequestCallback> iter(iEp0ReadRequestCallbacks);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1168
            TUsbcRequestCallback* p;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1169
            while ((p = iter++) != NULL)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1170
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1171
                if (p->Owner() == iEp0ClientId)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1172
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1173
                    memcpy(p->iBufferStart, iEp0_RxBuf, aCount);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1174
                    p->iError = KErrNone;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1175
                    *(p->iPacketSize) = aCount;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1176
                    p->iRxPackets = 1;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1177
                    *(p->iPacketIndex) = 0;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1178
                    break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1179
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1180
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1181
            
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1182
            // pass data to client if found one.
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1183
            if ( p != NULL)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1184
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1185
                ProcessDataTransferDone(*p);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1186
                    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1187
                if (iEp0DataReceived >= iConTransferMgr->PktParser().DataLength())
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1188
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1189
                    // all data seems now to be here
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1190
                    ResetEp0DataOutVars();
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1191
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1192
                
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1193
                iLastError = KErrNone;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1194
                
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1195
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1196
            else
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1197
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1198
                // that's bad, we found a client is request this data
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1199
                // but no matching request callback found.
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1200
                
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1201
                iEp0_RxExtraCount = aCount;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1202
                //iEp0_RxExtraData = ETrue;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1203
                //iEp0_RxExtraError = aErrCode;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1204
                iEp0DataReceived -= aCount;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1205
                
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1206
                // No status packet will be send to host since no client is reading this data,
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1207
                // waiting client to send a status packet.
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1208
                
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1209
                iLastError = KErrNotFound;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1210
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1211
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1212
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1213
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1214
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1215
// Status Tx is done    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1216
void DUsbClientController::ProcessStatusInPacket(TInt aErrCode)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1217
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1218
    // Clear Error Code
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1219
    iLastError = KErrNone; 
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1220
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1221
    // it is time to start a new read
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1222
    iEp0WritePending = EFalse;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1223
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1224
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1225
//
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1226
// Setup Rx is done
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1227
//
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1228
void DUsbClientController::ProcessSetupPacket(TInt aCount,TInt aErrCode)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1229
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1230
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1231
    if (aErrCode != KErrNone)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1232
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1233
        // something wrong in hardware, we can do nothing as remedy
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1234
        // just stall the endpoint.
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1235
        iConTransferMgr->StallEndpoint(KEp0_Out);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1236
        iConTransferMgr->SetupEndpointZeroRead();
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1237
        
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1238
        // set err code to Error general if end point is stalled
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1239
        iLastError = KErrGeneral;       
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1240
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1241
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1242
    TUsbcSetup packet;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1243
    Buffer2Setup(iEp0_RxBuf, packet);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1244
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1245
    // Clear Error Code
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1246
    iLastError = KErrNone;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1247
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1248
    // If this is a standard request, we can handle it here
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1249
    // not need to bother app layer
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1250
    if ((packet.iRequestType & KUsbRequestType_TypeMask) == KUsbRequestType_TypeStd)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1251
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1252
        // Fixme: this may not needed any more
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1253
        iEp0ReceivedNonStdRequest = EFalse;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1254
        ProcessStandardRequest(aCount,packet);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1255
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1256
    else
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1257
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1258
        // Fixme: This may not needed anymore
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1259
        iEp0ReceivedNonStdRequest = ETrue;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1260
        ProcessNonStandardRequest(aCount,packet);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1261
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1262
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1263
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1264
#define USB_PROCESS_REQUEST(request,param) \
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1265
    do \
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1266
    { \
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1267
    Process ## request(param); \
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1268
    if (iLastError != KErrNone) \
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1269
        { \
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1270
        __KTRACE_OPT(KUSB, \
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1271
                    Kern::Printf("  ProcessEp0SetupReceived: Stalling Ep0")); \
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1272
        iConTransferMgr->StallEndpoint(KEp0_In); \
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1273
        } \
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1274
    }while(0)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1275
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1276
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1277
//
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1278
// Standard request
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1279
// Please note that:Macro USB_PROCESS_REQUEST(xxx) will stall endpoint
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1280
// if anything wrong during the process, in which case status packet is 
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1281
// not needed.
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1282
//
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1283
void DUsbClientController::ProcessStandardRequest(TInt /*aCount*/,const TUsbcSetup& aPacket)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1284
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1285
    switch (aPacket.iRequest)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1286
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1287
        case KUsbRequest_GetStatus:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1288
            switch (aPacket.iRequestType & KUsbRequestType_DestMask)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1289
                { // Recipient
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1290
                case KUsbRequestType_DestDevice:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1291
                    USB_PROCESS_REQUEST(GetDeviceStatus,aPacket);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1292
                    break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1293
                    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1294
                case KUsbRequestType_DestIfc:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1295
                    USB_PROCESS_REQUEST(GetInterfaceStatus,aPacket);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1296
                    break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1297
                    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1298
                case KUsbRequestType_DestEp:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1299
                    USB_PROCESS_REQUEST(GetEndpointStatus,aPacket);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1300
                    break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1301
                    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1302
                default:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1303
                    __KTRACE_OPT(KPANIC, Kern::Printf("  Error: GET STATUS - Other or Unknown recipient"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1304
                    __KTRACE_OPT(KPANIC, Kern::Printf("  -> DUsbClientController::ProcessEp0SetupReceived: "
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1305
                                                      "Stalling Ep0"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1306
                    iConTransferMgr->StallEndpoint(KEp0_In);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1307
                    iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1308
                    break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1309
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1310
                break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1311
        
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1312
        case KUsbRequest_ClearFeature:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1313
        case KUsbRequest_SetFeature:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1314
            switch (aPacket.iRequestType & KUsbRequestType_DestMask)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1315
                { // Recipient
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1316
                case KUsbRequestType_DestDevice:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1317
                    USB_PROCESS_REQUEST(SetClearDevFeature,aPacket);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1318
                    break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1319
                case KUsbRequestType_DestIfc:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1320
                    // will 100% stall endpoint
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1321
                    USB_PROCESS_REQUEST(SetClearIfcFeature,aPacket);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1322
                    break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1323
                case KUsbRequestType_DestEp:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1324
                    USB_PROCESS_REQUEST(SetClearEpFeature,aPacket);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1325
                    break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1326
                default:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1327
                    __KTRACE_OPT(KPANIC, Kern::Printf("  Error: SET/CLEAR FEATURE - "
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1328
                                                      "Other or Unknown recipient"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1329
                    __KTRACE_OPT(KPANIC, Kern::Printf("  -> Stalling Ep0"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1330
                    iConTransferMgr->StallEndpoint(KEp0_In);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1331
                    iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1332
                    break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1333
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1334
                break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1335
                
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1336
        case KUsbRequest_SetAddress:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1337
            USB_PROCESS_REQUEST(SetAddress,aPacket);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1338
            break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1339
            
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1340
        case KUsbRequest_GetDescriptor:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1341
            USB_PROCESS_REQUEST(GetDescriptor,aPacket);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1342
            break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1343
            
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1344
        case KUsbRequest_SetDescriptor:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1345
            USB_PROCESS_REQUEST(SetDescriptor,aPacket);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1346
            break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1347
            
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1348
        case KUsbRequest_GetConfig:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1349
            USB_PROCESS_REQUEST(GetConfiguration,aPacket);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1350
            break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1351
            
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1352
        case KUsbRequest_SetConfig:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1353
            USB_PROCESS_REQUEST(SetConfiguration,aPacket);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1354
            break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1355
            
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1356
        case KUsbRequest_GetInterface:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1357
            USB_PROCESS_REQUEST(GetInterface,aPacket);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1358
            break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1359
            
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1360
        case KUsbRequest_SetInterface:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1361
            USB_PROCESS_REQUEST(SetInterface,aPacket);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1362
            break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1363
            
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1364
        case KUsbRequest_SynchFrame:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1365
            USB_PROCESS_REQUEST(SynchFrame,aPacket);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1366
            break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1367
            
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1368
        default:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1369
            __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Unknown/unsupported Std Setup Request"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1370
            __KTRACE_OPT(KPANIC, Kern::Printf("  -> Stalling Ep0"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1371
            iConTransferMgr->StallEndpoint(KEp0_In);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1372
            iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1373
            break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1374
        }       
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1375
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1376
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1377
#undef USB_PROCESS_REQUEST
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1378
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1379
//
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1380
// class- or vendor-specific request    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1381
// we dont send back any status to host in PIL for class- or vendor-specific request
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1382
// if no client is waiting, stall the endpoint
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1383
// if client is not ready, just record them and waiting for client to read them
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1384
// (and, send a status packet)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1385
//
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1386
void DUsbClientController::ProcessNonStandardRequest(TInt aCount,const TUsbcSetup& aPacket)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1387
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1388
    // Find out which client can handle this request
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1389
    const DBase* client = FindNonStandardRequestClient(aPacket.iRequestType & KUsbRequestType_DestMask,aPacket);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1390
        
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1391
    // If client is valide
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1392
    if (client != NULL)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1393
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1394
        // Try to relay aPacket to the real recipient
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1395
        TSglQueIter<TUsbcRequestCallback> iter(iEp0ReadRequestCallbacks);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1396
        TUsbcRequestCallback* p;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1397
        
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1398
        // Find out the request callback with match the client 
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1399
        // returned from last FindNonStandardRequestClient().
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1400
        while ((p = iter++) != NULL)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1401
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1402
            if (p->Owner() == client)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1403
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1404
                __ASSERT_DEBUG((p->iEndpointNum == 0), Kern::Fault(KUsbPILPanicCat, __LINE__));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1405
                __ASSERT_DEBUG((p->iTransferDir == UsbShai::EControllerRead), Kern::Fault(KUsbPILPanicCat, __LINE__));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1406
                __KTRACE_OPT(KUSB, Kern::Printf("  Found Ep0 read request"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1407
                if (aPacket.iLength != 0)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1408
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1409
                    if ((aPacket.iRequestType & KUsbRequestType_DirMask) == KUsbRequestType_DirToDev)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1410
                        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1411
                        // Data transfer & direction OUT => there'll be a DATA_OUT stage
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1412
                        __KTRACE_OPT(KUSB, Kern::Printf("  Next is DATA_OUT: setting up DataOutVars"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1413
                        SetEp0DataOutVars(client);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1414
                        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1415
                    else if ((aPacket.iRequestType & KUsbRequestType_DirMask) == KUsbRequestType_DirToHost)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1416
                        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1417
                        // For possible later use (ZLP).
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1418
                        iEp0_TxNonStdCount = aPacket.iLength;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1419
                        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1420
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1421
                    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1422
                // Found the request callback, jump out now
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1423
                break;                
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1424
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1425
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1426
            
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1427
        // if a request callback matching the client is found,
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1428
        // complete the request
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1429
        if( p != NULL)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1430
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1431
            __KTRACE_OPT(KUSB, Kern::Printf("  Ep0 read request completed to client"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1432
            memcpy(p->iBufferStart, iEp0_RxBuf, aCount);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1433
            p->iError = KErrNone;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1434
            *(p->iPacketSize) = aCount;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1435
            p->iRxPackets = 1;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1436
            *(p->iPacketIndex) = 0;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1437
            ProcessDataTransferDone(*p);            
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1438
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1439
        else
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1440
            {            
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1441
            __KTRACE_OPT(KUSB, Kern::Printf("  Ep0 read request not found: setting RxExtra vars (Setup)"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1442
            iEp0_RxExtraCount = aCount;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1443
            //iEp0_RxExtraData = ETrue;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1444
            //iEp0_RxExtraError = aErrCode;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1445
            iSetupPacketPending = ETrue;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1446
            
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1447
            // For setup packet,a zero bytes status is always needed
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1448
            iLastError = KErrNotFound;           
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1449
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1450
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1451
    else // if (client == NULL)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1452
        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1453
        // Pil don't know how to deal with non-standard request, stall endpoint
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1454
        __KTRACE_OPT(KPANIC, Kern::Printf("  Ep0 request error: Stalling Ep0"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1455
        iConTransferMgr->StallEndpoint(KEp0_In);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1456
        iLastError = KErrGeneral;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1457
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1458
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1459
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1460
const DBase* DUsbClientController::FindNonStandardRequestClient(TUint8 aPacketTypeDestination,const TUsbcSetup& aPacket)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1461
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1462
    const DBase* client = NULL;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1463
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1464
    switch (aPacketTypeDestination)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1465
        { // Recipient
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1466
        case KUsbRequestType_DestDevice:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1467
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1468
            client = iEp0DeviceControl;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1469
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1470
            break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1471
            
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1472
        case KUsbRequestType_DestIfc:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1473
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1474
            //Add this mutex to protect the interface set data structure
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1475
            if (NKern::CurrentContext() == EThread)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1476
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1477
                NKern::FMWait(&iMutex);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1478
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1479
                
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1480
            if ( iDeviceState < UsbShai::EUsbPeripheralStateConfigured)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1481
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1482
                __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid device state"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1483
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1484
            else
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1485
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1486
                const TUsbcInterfaceSet* const ifcset_ptr =
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1487
                    InterfaceNumber2InterfacePointer(aPacket.iIndex);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1488
                    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1489
                //In some rare case, ifcset_ptr is not NULL but the ifcset_ptr->iInterfaces.Count() is 0,
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1490
                //so panic will happen when excute the following line. so I add the conditon
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1491
                //0 != ifcset_ptr->iInterfaces.Count() here.
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1492
                if (ifcset_ptr && 0 != ifcset_ptr->iInterfaces.Count())
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1493
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1494
                    if (ifcset_ptr->CurrentInterface()->iNoEp0Requests)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1495
                        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1496
                        __KTRACE_OPT(KUSB, Kern::Printf("  Recipient says: NoEp0RequestsPlease"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1497
                        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1498
                    else
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1499
                        {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1500
                        client = ifcset_ptr->iClientId;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1501
                        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1502
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1503
                else
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1504
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1505
                    __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Interface 0x%02x does not exist",
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1506
                                                      aPacket.iIndex));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1507
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1508
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1509
                
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1510
            if (NKern::CurrentContext() == EThread)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1511
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1512
                NKern::FMSignal(&iMutex);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1513
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1514
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1515
            break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1516
                        
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1517
        case KUsbRequestType_DestEp:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1518
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1519
            //Add this mutex to protect the interface set data structure
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1520
            if (NKern::CurrentContext() == EThread)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1521
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1522
                NKern::FMWait(&iMutex);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1523
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1524
            if ( iDeviceState < UsbShai::EUsbPeripheralStateConfigured)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1525
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1526
                __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Invalid device state"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1527
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1528
            else if (EndpointExists(aPacket.iIndex) == EFalse)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1529
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1530
                __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Endpoint 0x%02x does not exist",
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1531
                                                  aPacket.iIndex));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1532
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1533
            else
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1534
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1535
                const TInt idx = EpAddr2Idx(aPacket.iIndex);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1536
                const TUsbcInterfaceSet* const ifcset_ptr =
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1537
                    iRealEndpoints[idx].iLEndpoint->iInterface->iInterfaceSet;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1538
                if (ifcset_ptr->CurrentInterface()->iNoEp0Requests)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1539
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1540
                    __KTRACE_OPT(KUSB, Kern::Printf("  Recipient says: NoEp0RequestsPlease"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1541
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1542
                else
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1543
                    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1544
                    client = ifcset_ptr->iClientId;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1545
                    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1546
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1547
            if (NKern::CurrentContext() == EThread)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1548
                {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1549
                NKern::FMSignal(&iMutex);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1550
                }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1551
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1552
            break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1553
            
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1554
        default:
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1555
            {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1556
            __KTRACE_OPT(KPANIC, Kern::Printf("  Error: Other or Unknown recipient"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1557
            break;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1558
            }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1559
        }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1560
        
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1561
    return client;
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1562
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1563
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1564
TInt DUsbClientController::ProcessSetupEndpointZeroRead()
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1565
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1566
    __KTRACE_OPT(KPANIC, Kern::Printf("DUsbClientController:: Read EP0 Issued"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1567
    return iController.SetupEndpointZeroRead();
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1568
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1569
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1570
TInt DUsbClientController::ProcessSetupEndpointZeroWrite(const TUint8* aBuffer, TInt aLength, TBool aZlpReqd)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1571
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1572
    __KTRACE_OPT(KPANIC, Kern::Printf("DUsbClientController:: Write EP0 Issued"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1573
    return iController.SetupEndpointZeroWrite(aBuffer,aLength,aZlpReqd);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1574
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1575
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1576
TInt DUsbClientController::ProcessSendEp0ZeroByteStatusPacket()
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1577
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1578
    __KTRACE_OPT(KPANIC, Kern::Printf("DUsbClientController:: Zero Status to EP0 Issued"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1579
    return iController.SendEp0ZeroByteStatusPacket();
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1580
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1581
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1582
TInt DUsbClientController::ProcessStallEndpoint(TInt aRealEndpoint)
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1583
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1584
    __KTRACE_OPT(KPANIC, Kern::Printf("DUsbClientController:: EP0(%d) Stall Issued",aRealEndpoint));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1585
    return iController.StallEndpoint(aRealEndpoint);
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1586
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1587
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1588
void DUsbClientController::ProcessEp0SetupPacketProceed()
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1589
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1590
    __KTRACE_OPT(KPANIC, Kern::Printf("DUsbClientController:: Missed setup packet procced"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1591
    iController.Ep0ReadSetupPktProceed();
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1592
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1593
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1594
void DUsbClientController::ProcessEp0DataPacketProceed()
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1595
    {
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1596
    __KTRACE_OPT(KPANIC, Kern::Printf("DUsbClientController:: Missed data packet procced"));
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1597
    iController.Ep0ReadDataPktProceed();
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1598
    }
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1599
    
089413cdde3c 201028_02
hgs
parents:
diff changeset
  1600
// -eof-