usbengines/usbotgwatcher/src/cusbstatehostabase.cpp
changeset 0 1e05558e2206
child 3 47c263f7e521
equal deleted inserted replaced
-1:000000000000 0:1e05558e2206
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implementation
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #include <e32base.h> 
       
    20 #include <usbhosterrors.h>
       
    21 #include <d32otgdi_errors.h>
       
    22 #include <d32usbdi_errors.h>
       
    23 
       
    24 #include "cusbstatehostabase.h"
       
    25 #include "cusbstatehosthandle.h"
       
    26 
       
    27 #include "errors.h"
       
    28 
       
    29 #include "debug.h"
       
    30 #include "panic.h"
       
    31 
       
    32 // ---------------------------------------------------------------------------
       
    33 // 
       
    34 // ---------------------------------------------------------------------------
       
    35 //
       
    36 CUsbStateHostABase::CUsbStateHostABase(CUsbOtgWatcher* aWatcher) :
       
    37     CUsbState(aWatcher)
       
    38     {
       
    39     }
       
    40 
       
    41 // ---------------------------------------------------------------------------
       
    42 // 
       
    43 // ---------------------------------------------------------------------------
       
    44 //
       
    45 void CUsbStateHostABase::ConstructL()
       
    46     {
       
    47         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostABase::ConstructL" ) );
       
    48     }
       
    49 
       
    50 // ---------------------------------------------------------------------------
       
    51 // 
       
    52 // ---------------------------------------------------------------------------
       
    53 //
       
    54 CUsbStateHostABase::~CUsbStateHostABase()
       
    55     {
       
    56         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostABase::~CUsbStateHostABase" ) );
       
    57 
       
    58     }
       
    59 
       
    60 // From VBus observer
       
    61 // ---------------------------------------------------------------------------
       
    62 // 
       
    63 // ---------------------------------------------------------------------------
       
    64 //
       
    65 void CUsbStateHostABase::VBusDownL()
       
    66     {
       
    67         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostABase::VBusDownL" ) );
       
    68     ChangeHostStateL(EUsbStateHostAIdle);
       
    69     }
       
    70 
       
    71 // From OTG state observer
       
    72 // ---------------------------------------------------------------------------
       
    73 // 
       
    74 // ---------------------------------------------------------------------------
       
    75 //
       
    76 void CUsbStateHostABase::AIdleL()
       
    77     {
       
    78         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostABase::AIdleL" ) );
       
    79     // do nothing
       
    80     }
       
    81 
       
    82 // ---------------------------------------------------------------------------
       
    83 // 
       
    84 // ---------------------------------------------------------------------------
       
    85 //
       
    86 void CUsbStateHostABase::AVBusErrorL()
       
    87     {
       
    88         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostABase::AVBusErrorL" ) );
       
    89     // No need to handle BusClearError error code, due to Bus will be dropped anyway
       
    90     iWatcher->Usb().BusClearError();
       
    91     HandleL(EUsbWatcherErrDeviceRequiresTooMuchPower);
       
    92     }
       
    93 
       
    94 // From bus activity observer
       
    95 // ---------------------------------------------------------------------------
       
    96 // 
       
    97 // ---------------------------------------------------------------------------
       
    98 //
       
    99 void CUsbStateHostABase::BusIdleL()
       
   100     {
       
   101         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostABase::BusIdleL" ) );
       
   102     //do nothing
       
   103     }
       
   104 
       
   105 // ---------------------------------------------------------------------------
       
   106 // 
       
   107 // ---------------------------------------------------------------------------
       
   108 //
       
   109 void CUsbStateHostABase::BusActiveL()
       
   110     {
       
   111         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostABase::BusActiveL" ) );
       
   112     // do nothing
       
   113     }
       
   114 
       
   115 // From message notification observer
       
   116 // ---------------------------------------------------------------------------
       
   117 // 
       
   118 // ---------------------------------------------------------------------------
       
   119 //
       
   120 void CUsbStateHostABase::MessageNotificationReceivedL(TInt aMessage)
       
   121     {
       
   122         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbStateHostABase::MessageNotificationReceivedL = %d" ), aMessage));
       
   123 
       
   124     switch (aMessage)
       
   125         {
       
   126 
       
   127         // OTGDI
       
   128         case KErrUsbOtgEventQueueOverflow: //         = -6670;
       
   129         case KErrUsbOtgStateQueueOverflow://         = -6671;
       
   130         case KErrUsbOtgMessageQueueOverflow: //       = -6672;
       
   131 
       
   132         case KErrUsbOtgBadState://                   = -6675;
       
   133 
       
   134         case KErrUsbOtgStackNotStarted://            = -6680;
       
   135         //case KErrUsbOtgVbusAlreadyRaised://          = -6681;
       
   136         //case KErrUsbOtgSrpForbidden://               = -6682;
       
   137 
       
   138         case KErrUsbOtgHnpNotResponding://           = -6683;
       
   139         //case KErrUsbOtgHnpBusDrop://                 = -6684;
       
   140 
       
   141         case KErrUsbOtgBusControlProblem://          = -6685;
       
   142 
       
   143         case KErrUsbOtgVbusPowerUpError://           = -6686;
       
   144 
       
   145         case KErrUsbOtgHnpEnableProblem://           = -6687;
       
   146 
       
   147         case KErrUsbOtgVbusError://                  = -6690;
       
   148         case KErrUsbOtgSrpTimeout://                 = -6691;
       
   149         //case KErrUsbOtgSrpActive://                  = -6692;
       
   150         //case KErrUsbOtgSrpNotPermitted://            = -6693;
       
   151         //case KErrUsbOtgHnpNotPermitted://            = -6694;
       
   152         //case KErrUsbOtgHnpNotEnabled://              = -6695;
       
   153         //case KErrUsbOtgHnpNotSuspended://            = -6696;
       
   154         //case KErrUsbOtgVbusPowerUpNotPermitted://    = -6697;
       
   155         //case KErrUsbOtgVbusPowerDownNotPermitted://  = -6698;
       
   156         //case KErrUsbOtgVbusClearErrorNotPermitted:// = -6699;
       
   157 
       
   158             // hosterrors.h
       
   159         case KErrUsbConfigurationHasNoInterfaces:
       
   160         case KErrUsbInterfaceCountMismatch:
       
   161         case KErrUsbDuplicateInterfaceNumbers:
       
   162         case KErrUsbBadDescriptor:
       
   163         case KErrUsbDeviceDetachedDuringDriverLoading:
       
   164         case KErrUsbAttachmentFailureGeneralError:
       
   165             {
       
   166                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostABase::MessageNotificationReceivedL ErrorInConnection" ) );
       
   167             HandleL(EUsbWatcherErrorInConnection);
       
   168             break;
       
   169             }
       
   170 
       
   171             // OTGDI
       
   172         case KErrUsbOtgPeriphNotSupported: //        = -6688
       
   173 
       
   174             // USBDI
       
   175         case KErrUsbRequestsPending:
       
   176         case KErrUsbBadAddress:
       
   177         case KErrUsbNoAddress:
       
   178         case KErrUsbSetAddrFailed:
       
   179         case KErrUsbNoPower:
       
   180         case KErrUsbTooDeep:
       
   181         case KErrUsbIOError:
       
   182         case KErrUsbNotConfigured:
       
   183         case KErrUsbTimeout:
       
   184         case KErrUsbStalled:
       
   185         case KErrUsbTestFailure:
       
   186         case KErrUsbBadState:
       
   187         case KErrUsbDeviceSuspended:
       
   188         case KErrUsbBadDescriptorTopology:
       
   189         case KErrUsbDeviceRejected:
       
   190         case KErrUsbDeviceFailed:
       
   191         case KErrUsbBadDevice:
       
   192         case KErrUsbBadHub:
       
   193         case KErrUsbEventOverflow:
       
   194 
       
   195             // hosterrors.h
       
   196         case KErrUsbUnsupportedDevice:
       
   197             {
       
   198                 FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostABase::MessageNotificationReceivedL UnsupportedDevice" ) );
       
   199             HandleL(EUsbWatcherErrUnsupportedDevice);
       
   200             break;
       
   201             }
       
   202         default:
       
   203             {
       
   204                 FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbStateHostABase::MessageNotificationReceivedL Unhandled message = %d" ), aMessage));
       
   205             break;
       
   206             }
       
   207 
       
   208         }
       
   209 
       
   210     }
       
   211 
       
   212 // ---------------------------------------------------------------------------
       
   213 // 
       
   214 // ---------------------------------------------------------------------------
       
   215 //
       
   216 void CUsbStateHostABase::BadHubPositionL()
       
   217     {
       
   218         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostABase::BadHubPositionL" ) );
       
   219     HandleL(EUsbWatcherHubsNotSupported);
       
   220     }
       
   221 
       
   222 // ---------------------------------------------------------------------------
       
   223 // 
       
   224 // ---------------------------------------------------------------------------
       
   225 //
       
   226 void CUsbStateHostABase::VBusErrorL()
       
   227     {
       
   228         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostABase::VBusErrorL" ) );
       
   229     // No error code handling after BusClearError call, due to bus will be dropped anyway
       
   230     iWatcher->Usb().BusClearError();
       
   231     HandleL(EUsbWatcherErrDeviceRequiresTooMuchPower);
       
   232     }
       
   233 
       
   234 // ---------------------------------------------------------------------------
       
   235 // 
       
   236 // ---------------------------------------------------------------------------
       
   237 //
       
   238 void CUsbStateHostABase::SessionRequestedL()
       
   239     {
       
   240         FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostABase::SessionRequestedL" ) );
       
   241 
       
   242     if (iWatcher->VBusObserver()->VBus() == CUsbVBusObserver::EVBusUp)
       
   243         {
       
   244             // session already ongoing; BusRequest() in this case returns KErrUsbOtgBadState...
       
   245             FLOG( _L( "[USBOTGWATCHER]\tCUsbStateHostABase::SessionRequestedL() VBus is already UP; ignore Session request." ) );
       
   246         return;
       
   247         }
       
   248 
       
   249     TInt err = iWatcher->Usb().BusRequest();
       
   250     if (KErrNone != err && KErrUsbOtgVbusAlreadyRaised != err) // sometimes this also comes...
       
   251         {
       
   252             FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbStateHostABase::SessionRequestedL BusRequestError err = %d" ), err));
       
   253         iWatcher->HandleHostProblemL(EUsbWatcherErrorInConnection);
       
   254         return;
       
   255         }
       
   256 
       
   257         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbStateHostABase::SessionRequestedL Session started OK (or VBUS already UP) err = %d" ), err));
       
   258     }
       
   259 
       
   260 // ---------------------------------------------------------------------------
       
   261 // 
       
   262 // ---------------------------------------------------------------------------
       
   263 //
       
   264 void CUsbStateHostABase::HandleL(TInt aWhat)
       
   265     {
       
   266         FTRACE( FPrint(_L( "[USBOTGWATCHER]\tCUsbStateHostABase::HandleL aWhat = %d" ), aWhat));
       
   267 
       
   268     iWatcher->HandleHostProblemL(aWhat);
       
   269     }