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