# HG changeset patch # User hgs # Date 1278483400 -28800 # Node ID f1fd07aa74c95b3ee62e1a6fb6ca245103587a01 # Parent 2fefb5a2b416d0d8ad9c0336fd64dec7939437bd 201025_08 diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/bld.inf --- a/usbmgmt/usbmgr/device/classdrivers/bld.inf Fri Jun 25 13:31:50 2010 +0800 +++ b/usbmgmt/usbmgr/device/classdrivers/bld.inf Wed Jul 07 14:16:40 2010 +0800 @@ -19,4 +19,5 @@ #include "ms/bld.inf" #include "obex/bld.inf" #include "whcm/bld.inf" +#include "ncm/group/bld.inf" diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/group/bld.inf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/group/bld.inf Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +PRJ_PLATFORMS +armv5 + +PRJ_MMPFILES +ncmclasscontroller.mmp + +PRJ_EXPORTS +usbncmconfiguration.hby /epoc32/rom/include/usbncmconfiguration.hby +usbncm.iby /epoc32/rom/include/usbncm.iby + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/group/ncmcc_over_dummy_stubs.mmp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/group/ncmcc_over_dummy_stubs.mmp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** +@file +@SYMPurpose ncmclasscontroller.dll USB NCM Class Controller over dummy stubs + */ + +macro OVERDUMMY_NCMCC + +#include "ncmclasscontroller_base.mmp" + +target dummy_ncmclasscontroller.dll + +UID 0x10009d8d 0x2002EA9F + +sourcepath ../src +START resource ncmcc_over_dummy.rss + TARGET dummy_ncmclasscontroller.rsc +END + +// Dummy librarys +LIBRARY dummy_sock.lib +LIBRARY dummyusbsclddapi.lib +LIBRARY dummy_ncminternalsrv.lib diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/group/ncmclasscontroller.mmp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/group/ncmclasscontroller.mmp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** +@file +@SYMPurpose ncmclasscontroller.dll USB NCM Class Controller + */ + +#include "ncmclasscontroller_base.mmp" + +target ncmclasscontroller.dll + +UID 0x10009d8d 0x2002bcfd + +sourcepath ../src +START resource 2002bcfd.rss + TARGET ncmclasscontroller.rsc +END + +LIBRARY esock.lib +LIBRARY ncminternalsrv.lib +LIBRARY usbcsc_bil.lib +LIBRARY insock.lib +LIBRARY nifman.lib diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/group/ncmclasscontroller_base.mmp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/group/ncmclasscontroller_base.mmp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** +@file +@SYMPurpose ncmclasscontroller.dll USB NCM Class Controller + */ + +CAPABILITY CommDD NetworkControl NetworkServices LocalServices ProtServ +targettype plugin + +userinclude ../inc +userinclude ../../inc +userinclude ../traces + +OS_LAYER_SYSTEMINCLUDE_SYMBIAN + +sourcepath ../src +source ncmclasscontroller.cpp +source ncmclassimpcollection.cpp +source ncmconnectionmanager.cpp +source ncmiapprogresswatcher.cpp +source ncmconnectionmanagerhelper.cpp +source ncmclassdescriptor.cpp +source ncmclientmanager.cpp +source ncmdhcpnotifwatcher.cpp +source ncmiapreader.cpp + +LIBRARY euser.lib +LIBRARY usbclasscontroller.lib +LIBRARY efsrv.lib +LIBRARY bafl.lib +LIBRARY commdb.lib +LIBRARY centralrepository.lib +LIBRARY commsfw.lib +LIBRARY esocksvr.lib +LIBRARY netmeta.lib +LIBRARY nodemessages.lib +LIBRARY random.lib +LIBRARY commsdataobjects.lib +LIBRARY commsdat.lib + + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/group/usbncm.iby --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/group/usbncm.iby Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Configuration for NCM functions +* +*/ + +#ifndef USBNCM_IBY +#define USBNCM_IBY + +// NCM Feature flag +#ifdef FF_AUTOMOTIVESTACK + +#include + +// *** NCM (networking control model) Class Controller. + +#ifdef USBNCM_PATCHDATA_KUSBNCM_CUSTOM_ETHERNET_FRAME_SIZE +patchdata ncmclasscontroller.dll@KEthernetFrameSize USBNCM_PATCHDATA_KUSBNCM_CUSTOM_ETHERNET_FRAME_SIZE +#endif + +USB_PLUGIN(ncmclasscontroller.dll,2002bcfd.rsc) +file=ABI_DIR\USB_DIR\ncmpkt.drv ncmpkt.drv +file=ABI_DIR\USB_DIR\ncminternalsrv.dll ncminternalsrv.dll + +#endif // FF_AUTOMOTIVESTACK + +#endif // USBNCM_IBY diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/group/usbncmconfiguration.hby --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/group/usbncmconfiguration.hby Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,25 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Configuration for NCM functions +* +*/ + +#ifndef USBNCMCONFIGURATION_HBY +#define USBNCMCONFIGURATION_HBY + + +#define USBNCM_PATCHDATA_KUSBNCM_CUSTOM_ETHERNET_FRAME_SIZE 8192 + +#endif // USBNCMCONFIGURATION_HBY diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmclasscontroller.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmclasscontroller.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,99 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file +@internalComponent +*/ + +#ifndef NCMCLASSCONTROLLER_H +#define NCMCLASSCONTROLLER_H + +#include +#include + +#include "ncmconnectionmanagerobserver.h" +#include "ncmcommon.h" + +#ifdef OVERDUMMY_NCMCC +#include +#else +#include "ncminternalsrv.h" +#endif // OVERDUMMY_NCMCC + +class CNcmConnectionManager; +class CNcmClientManager; + +/** + * NCM Class controller. + * It is derived from CUsbClassControllerPlugIn. The USB Manager will control + * NCM class through it. + * And it implements interface MNcmConnectionManagerObserver as well. + */ +NONSHARABLE_CLASS(CNcmClassController): + public CUsbClassControllerPlugIn, + public MNcmConnectionManagerObserver + { +public: + static CNcmClassController* NewL(MUsbClassControllerNotify& aOwner); + ~CNcmClassController(); + + // From MNcmConnectionManagerObserver + void McmoErrorIndication(TInt aError); + +private: + /** + * Two-phases construction: phase 1 + * @param[in] aOwner, an Interface to talk to the USB server. + */ + CNcmClassController(MUsbClassControllerNotify& aOwner); + /** + * Two-phases construction: phase 2 + */ + void ConstructL(); + + // From CActive + void RunL(); + void DoCancel(); + TInt RunError(TInt aError); + + // From CUsbClassControllerBase + void Start(TRequestStatus& aStatus); + void Stop(TRequestStatus& aStatus); + void GetDescriptorInfo(TUsbDescriptor& aDescriptorInfo) const; + + +private: + void RandomMacAddressL(); + +private: + TNcmMacAddress iHostMacAddress; + + CNcmConnectionManager* iConnectionMan; // Owned. + + // Not own. + TRequestStatus* iReportStatus; + + CNcmClientManager* iClientMgr; // Owned + + RNcmInternalSrv iNcmInternalSvr; + + TBool iConnectingToNcmPktDrv; + + TUint iDataBufferSize; // Buffer size of data end points + }; + +#endif // NCMCLASSCONTROLLER_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmclassdescriptor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmclassdescriptor.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file +@internalComponent +*/ + + +#ifndef NCMCLASSDESCRIPTOR_H +#define NCMCLASSDESCRIPTOR_H + +#include + + +const TUint KUSBNcmClassSpecificBufferSize = 29; + + +/** + * Defined NCM Class Descriptor + */ +NONSHARABLE_CLASS(TNcmClassDescriptor) ///< Class-specific descriptor + { +public: + + //Header Functional Descriptor + TUint8 iHdrSize; ///< Header size + TUint8 iHdrType; ///< Type + TUint8 iHdrSubType; ///< Sub-type + TUint16 iHdrBcdCDC; ///< CDC version no in binary coded decimal + + //Union Functional Descriptor + TUint8 iUnSize; ///< Union descriptor size + TUint8 iUnType; ///< Union descriptor type + TUint8 iUnSubType; ///< Union descriptor sub-type + TUint8 iUnMasterInterface; ///< Master interface number + TUint8 iUnSlaveInterface; ///< Slave interface number + + //Ethernet Networking Functional Descriptor + TUint8 iEthFunLength; ///< Size of this functional descriptor + TUint8 iEthFunType; ///< CS_INTERFACE + TUint8 iEthFunSubtype; ///< Ethernet Networking functional descriptor subtype as defined in [USBCDC1.2] + TUint8 iMACAddress; ///< Index of string descriptor. The string descriptor holds the 48bit Ethernet MAC address. + TUint iEthernetStatistics; ///< Indicates which Ethernet statistics functions the device collects. + TUint16 iMaxSegmentSize; ///< The maximum segment size that the Ethernet device is capable of supporting. + TUint16 iNumberMCFilters; ///< Contains the number of multicast filters that can be configured by the host. + TUint8 iNumberPowerFilters; ///< Contains the number of pattern filters that are available for causing wake-up of the host. + + + //NCM Functional Descriptor + TUint8 iNcmFunLength; ///< Size of this functional descriptor + TUint8 iNcmFunType; ///< CS_INTERFACE + TUint8 iNcmFunSubtype; ///< NCM Functional Descriptor subtype + TUint16 iNcmVersion; ///< Release number of this specification in BCD + TUint8 iNetworkCapabilities; ///< Specifies the capabilities of this function + +public: + TDes8& Des(); + +private: + + TBuf8 iBuffer; + }; + +#endif // NCMCLASSDESCRIPTOR_H + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmclientmanager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmclientmanager.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,102 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file +@internalComponent +*/ + + +#ifndef NCMCLIENTMANAGER_H +#define NCMCLIENTMANAGER_H + +#include +#include + +#ifdef OVERDUMMY_NCMCC +#include +#else +#include +#endif // OVERDUMMY_NCMCC + +#include "ncmcommon.h" + +class RNcmInternalSrv; + +/** + * A class which encapsulates the operations related to USB shared chunk LDD + */ +class CNcmClientManager : public CBase + { +public: + /** + * Constructor + * @param[in] aHostMacAddress, the NCM interface MAC address + * which will be used to config. + */ + CNcmClientManager(const TNcmMacAddress& aHostMacAddress); + + ~CNcmClientManager(); + + /** + * Setup NCM interfaces + * @param[out] aDataEpBufferSize, NCM data interface EP buffer size + */ + void SetNcmInterfacesL(TUint& aDataEpBufferSize); + /** + * Transfer ownership of NCM interface handles to NCM internal + * server which is located in C32 process space + * @param[in] aServer, NCM internal server. + */ + void TransferInterfacesL(RNcmInternalSrv& aServer); + +private: + /** + * Setup NCM communication interface + */ + void SetCommunicationInterfaceL(); + /** + * Setup NCM data interface + * @param aDataEpBufferSize, NCM data interface EP buffer size + */ + void SetDataInterfaceL(TUint& aDataEpBufferSize); + /** + * Setup NCM class specific descriptors + * @param aDataInterfaceNumber, NCM data interface number + */ + TInt SetupClassSpecificDescriptor(TUint8 aDataInterfaceNumber); + /** + * Set NCM interface MAC address into NCM class specific descriptor + * @param[out] aStrIndex, the index of string which contains NCM + * interface MAC address + */ + TInt SetMacAddressString(TUint8& aStrIndex); + /** + * Get NCM data interface number + * @param[out] aInterfaceNumber, NCM data interface number + */ + TInt DataInterfaceNumber(TUint8& aInterfaceNumber); + +private: + const TNcmMacAddress& iHostMacAddress; + + TBool iCommLddInitiated; + RDevUsbcScClient iCommLdd; + TBool iDataLddInitiated; + RDevUsbcScClient iDataLdd; + }; + +#endif // NCMCLIENTMANAGER_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmconnectionmanager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmconnectionmanager.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,166 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file +@internalComponent +*/ + +#ifndef NCMCONNECTIONMANAGER_H +#define NCMCONNECTIONMANAGER_H + +#ifdef OVERDUMMY_NCMCC +#include +#include +#include +#else +#include +#include +#include +#include +#endif // OVERDUMMY_NCMCC + +#include +#include "ncmcommon.h" +#include "ncmiapprogressstateobserver.h" +#include "ncmiapconnectionobserver.h" +#include "ncmdhcpnotifobserver.h" +#include "ncmiapreaderobserver.h" + + +class MNcmConnectionManagerObserver; +class CNcmIapProgressWatcher; +class CNcmConnectionManHelper; +class CNcmDhcpNotifWatcher; +class CNcmIapReader; +class RNcmInternalSrv; + +/** + * CNcmConnectionManager to control ncm networking interface + * It handles: + * 1 Searching NCM IAP + * 2 Start NCM connection + * 3 IAP progress notification + * 4 DHCP provisioning request from NCM internal server + */ +NONSHARABLE_CLASS(CNcmConnectionManager) : public CBase, + public MNcmIapProgressStateObserver, + public MNcmConnectionObserver, + public MNcmDhcpNotificationObserver, + public MNcmIAPReaderObserver + { +public: + /** + * Constructs a CNcmConnectionManager object. + * @param[in] aOwner, NCM connection observer + * @param[in] aHostMacAddress, the NCM interface MAC address + * @param[in] aDataBufferSize, the EndPoint buffer size + * @param[in] aNcmInternalSvr, the NCM internal server + * @return Ownership of a new CNcmConnectionManager object + */ + static CNcmConnectionManager* NewL(MNcmConnectionManagerObserver& aOwner, + const TNcmMacAddress& aMacAddress, TUint aDataBufferSize, + RNcmInternalSrv& aNcmInternalSvr); + ~CNcmConnectionManager(); + + /** + * Start NCM connection + * @param aStatus complete status for this request. + */ + void Start(TRequestStatus& aStatus); + + /** + * Cancel starting of NCM connection + */ + void StartCancel(); + + /** + * Stop NCM connection + */ + void Stop(); + + // From MIapPorgressStateObserver + virtual void MipsoHandleClassFatalError(TInt aError); + + // From MNcmConnectionObserver + virtual void MicoHandleConnectionComplete(TInt aError); + + // From MNcmDhcpNotificationObserver + virtual void MdnoHandleDhcpNotification(TInt aError); + + // From MNcmIAPReaderObserver + virtual void MicoHandleIAPReadingComplete(TInt aError); + +private: + /** + * Two-phase construction: phase 1 + * @param[in] aObserver, NCM connection observer + * @param[in] aHostMacAddress, the NCM interface MAC address + * @param[in] aDataBufferSize, the EndPoint buffer size + * @param[in] aNcmInternalSvr, the NCM internal server + */ + CNcmConnectionManager(MNcmConnectionManagerObserver& aObserver, + const TNcmMacAddress& aHostMacAddress, TUint aDataBufferSize, + RNcmInternalSrv& aNcmInternalSvr); + /** + * Two-phase construction: phase 2 + */ + void ConstructL(); + + /** + * Reset NCM connection manager + */ + void Reset(); + + /* + * Change default MTU size on NCM connection + */ + void SetCustomMtuL(); + + /* + * Handle NCM connection building completion + */ + void HandleConnectionCompleteL(); + +private: + // Owned. + CNcmIapProgressWatcher* iIapPrgrsWatcher; + CNcmConnectionManHelper* iConnManHelper; + CNcmDhcpNotifWatcher* iDhcpNotifWatcher; + CNcmIapReader* iIapReader; + + // Not own. + TRequestStatus* iReportStatus; + + MNcmConnectionManagerObserver& iConnMgrObserver; + + // RSocketServ used for starting NCM IAP and configuring DHCP and NAPT, owned + RSocketServ iSocketServ; + + // RConnection used for starting NCM IAP and configuring DHCP server, owned + RConnection iConnection; + + TCommDbConnPref iConnPref; + + RProperty iProperty; + TBool iConnComplete; + + const TNcmMacAddress& iHostMacAddress; + const TUint iDataBufferSize; + RNcmInternalSrv& iNcmInternalSvr; +}; + +#endif // NCMCONNECTIONMANAGER_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmconnectionmanagerhelper.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmconnectionmanagerhelper.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file +@internalComponent +*/ + +#ifndef NCMCONNECTIONMANAGERHELPER_H +#define NCMCONNECTIONMANAGERHELPER_H + +#include + +#ifdef OVERDUMMY_NCMCC +#include +#include +#else +#include +#include +#include +#endif // OVERDUMMY_NCMCC + +class MNcmConnectionObserver; + +/** + * CNcmConnectionManHelper is the handler for NCM connection. + * 1 Start a NCM connection + * 2 Cancel starting attempt + * 3 Stop a NCM connection + */ +NONSHARABLE_CLASS(CNcmConnectionManHelper) : public CActive + { +public: + /** + * Constructor + * @param[in] aObserver, IAP connection observer + * @param[in] aConnection, the NCM connection + */ + CNcmConnectionManHelper(MNcmConnectionObserver& aObserver, RConnection& aConnection); + + ~CNcmConnectionManHelper(); + void Start(TConnPref& aPref); + void Stop(); + +private: + + // From CActive + void RunL(); + void DoCancel(); + +private: + MNcmConnectionObserver& iObserver; // IAP connection observer + RConnection& iConnection; // The NCM connection + }; + +#endif // NCMCONNECTIONMANAGERHELPER_H + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmconnectionmanagerobserver.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmconnectionmanagerobserver.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file +@internalComponent +*/ + +#ifndef NCMCONNECTIONMANAGEROBSERVER_H +#define NCMCONNECTIONMANAGEROBSERVER_H + +#include + +/** + * MNcmConnectionManagerObserver defines the interface for connection manager + * callback. + */ +class MNcmConnectionManagerObserver + { +public: + /* + * Called by NCM connection manager to report error to NCM connection + * observer. + * @param aError, error code reports to NCM connection observer + */ + virtual void McmoErrorIndication(TInt aError) = 0; + }; + +#endif // NCMCONNECTIONMANAGEROBSERVER_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmdhcpnotifobserver.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmdhcpnotifobserver.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,42 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file +@internalComponent +*/ + +#ifndef NCMDHCPNOTIFOBSERVER_H +#define NCMDHCPNOTIFOBSERVER_H + +#include + +/** + * MdnoHandleDhcpNotification defines the interface for notification of Dhcp + * provisioning request + */ +class MNcmDhcpNotificationObserver + { +public: + /** + * Called by DHCP prvisioning requestion watcher to handle DHCP + * provisioning request notification from NCM internal server. + * @param aError, completion code of DHCP provisioning request + */ + virtual void MdnoHandleDhcpNotification(TInt aError) = 0; + }; + +#endif // NCMDHCPNOTIFOBSERVER_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmdhcpnotifwatcher.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmdhcpnotifwatcher.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file +@internalComponent +*/ + +#ifndef NCMDHCPNOTIFWATCHER_H +#define NCMDHCPNOTIFWATCHER_H + +#include + +#ifdef OVERDUMMY_NCMCC +#include +#include +#else +#include +#include +#endif // OVERDUMMY_NCMCC + +class MNcmDhcpNotificationObserver; +class RNcmInternalSrv; + +/* + * CNcmDhcpNotifWatcher is handler of DHCP provisioning requestion from NCM + * internal server. + */ +NONSHARABLE_CLASS(CNcmDhcpNotifWatcher) : public CActive + { +public: + /** + * Constructor + * @param[in] aObserver, the observer of DHCP provisioning result. + * @param[in] aNcmInteralSvr, the NCM internal server. + */ + CNcmDhcpNotifWatcher(MNcmDhcpNotificationObserver& aObserver, + RNcmInternalSrv& aNcmInteralSvr); + + ~CNcmDhcpNotifWatcher(); + + /** + * Start the watcher to monitor DHCP provisioning requestion from + * NCM internal server. + */ + void StartL(); + +private: + + // From CActive + void RunL(); + void DoCancel(); + +private: + + MNcmDhcpNotificationObserver& iObserver; // DHCP provisioning result observer + RNcmInternalSrv& iNcmInteralSvr; // NCM internal server + }; + +#endif // NCMDHCPNOTIFWATCHER_H + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmiapconnectionobserver.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmiapconnectionobserver.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file +@internalComponent +*/ + +#ifndef NCMIAPCONNECTIONOBSERVER_H +#define NCMIAPCONNECTIONOBSERVER_H + +#include + +/** MNcmConnectionObserver defines the interface to handle the Notification of + * NCM connection established. + */ +class MNcmConnectionObserver + { +public: + /** + * Called by connection watcher to handle NCM connection building + * completion. + */ + virtual void MicoHandleConnectionComplete(TInt aError) = 0; + }; + +#endif // NCMIAPCONNECTIONOBSERVER_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmiapprogressstateobserver.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmiapprogressstateobserver.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file +@internalComponent +*/ + +#ifndef NCMIAPPROGRESSSTATEOBSERVER_H +#define NCMIAPPROGRESSSTATEOBSERVER_H + +#include + +/** + * MNcmIapProgressStateObserver defines the interface for events + * on IAP progress stage changing. + */ +class MNcmIapProgressStateObserver + { +public: + /** + * Called by connection watcher when it detects the class fatal error. + */ + virtual void MipsoHandleClassFatalError(TInt aError) = 0; + }; + +#endif // NCMIAPPROGRESSSTATEOBSERVER_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmiapprogresswatcher.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmiapprogresswatcher.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file +@internalComponent +*/ + +#ifndef NCMIAPPROGRESSWATCHER_H +#define NCMIAPPROGRESSWATCHER_H + +#include + +#ifdef OVERDUMMY_NCMCC +#include +#include +#else +#include +#include +#endif // OVERDUMMY_NCMCC + +class MNcmIapProgressStateObserver; + +/** + * CNcmIapProgressWatcher will handle IAP state changes + */ +NONSHARABLE_CLASS(CNcmIapProgressWatcher) : public CActive + { +public: + /** + * Constructor + * @param[in] aObserver, the observer of IAP progress change. + * @param[in] aConnection, the NCM connection. + */ + CNcmIapProgressWatcher(MNcmIapProgressStateObserver& aObserver, + RConnection& aConnection); + + ~CNcmIapProgressWatcher(); + + /** + * Start IAP progress watcher + */ + void Start(); + +private: + // From CActive + void RunL(); + void DoCancel(); + +private: + + TNifProgressBuf iProgressInfoBuf; + MNcmIapProgressStateObserver& iObserver; + RConnection& iConnection; + }; + +#endif // NCMIAPPROGRESSWATCHER_H + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmiapreader.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmiapreader.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file +@internalComponent +*/ + +#ifndef NCMIAPREADER_H +#define NCMIAPREADER_H + +#include + +class MNcmIAPReaderObserver; +class TCommDbConnPref; + +/** + * IAP reader reads NCM IAP from CommDB and set it into NCM connection preference. + */ +NONSHARABLE_CLASS(CNcmIapReader) : public CActive + { +public: + + /** + * Constructor + * @param[in] aObserver, the observer of IAP reading progress. + * @param[in] aConnection, the NCM connection preference. + */ + CNcmIapReader(MNcmIAPReaderObserver& aObserver, TCommDbConnPref& aConnPref); + + /** + * Destructor + */ + ~CNcmIapReader(); + + /** + * Start NCM IAP reader + */ + void Start(); + +private: + + // From CActive + void RunL(); + void DoCancel(); + +private: + void SearchNcmIapL(); + +private: + MNcmIAPReaderObserver& iObserver; + TCommDbConnPref& iConnPref; + }; + +#endif // NCMIAPREADER_H + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmiapreaderobserver.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/inc/ncmiapreaderobserver.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file +@internalComponent +*/ + +#ifndef NCMIAPREADEROBSERVER_H +#define NCMIAPREADEROBSERVER_H + +#include + +/** +MNcmIAPReaderObserver defines the interface for handling IAP reading completion +*/ +class MNcmIAPReaderObserver + { +public: + /** + * Called by IAP reader when IAP reading completed + */ + virtual void MicoHandleIAPReadingComplete(TInt aError) = 0; + }; + +#endif // NCMIAPREADEROBSERVER_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/2002bcfd.rss --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/2002bcfd.rss Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + * @internalComponent + */ + + +#include + +RESOURCE REGISTRY_INFO theInfo + { + dll_uid = 0x2002bcfd; + interfaces = + { + INTERFACE_INFO + { + interface_uid = 0x101fbf21; + implementations = + { + IMPLEMENTATION_INFO + { + implementation_uid = 0x2002c305; + version_no = 1; + display_name = "NCM CC"; + default_data = ""; + opaque_data = ""; + } + }; + } + }; + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/ncmcc_over_dummy.rss --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/ncmcc_over_dummy.rss Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @prototype +*/ + + +#include + +RESOURCE REGISTRY_INFO theInfo + { + dll_uid = 0x2002EA9F; + interfaces = + { + INTERFACE_INFO + { + interface_uid = 0x101fbf21; + implementations = + { + IMPLEMENTATION_INFO + { + implementation_uid = 0x2002EA9F; + version_no = 1; + display_name = "Dummy NCM CC"; + default_data = ""; + opaque_data = ""; + } + }; + } + }; + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/ncmclasscontroller.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/ncmclasscontroller.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,397 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** + * @file + * @internalComponent + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "ncmclasscontroller.h" +#include "ncmconnectionmanager.h" +#include "ncmclientmanager.h" + +// For OST tracing +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "ncmclasscontrollerTraces.h" +#endif + + +using namespace UsbNcm; +_LIT(KNcmControllerPanic, "UsbNcmCC"); // must be <=16 chars +const TInt KNcmStartupPriority = 3; + +// MTU size. +extern const TUint KEthernetFrameSize = 8192; + +// Lengths of the various bits of the NCM descriptor. Taken from the NCM Specification rev 1.0. +const TInt KNcmInterfaceDescriptorLength = 3; +const TInt KNcmCcHeaderDescriptorLength = 5; +const TInt KNcmFunctionalDescriptorLength = 4; +const TInt KNcmCcUfdDescriptorLength = 5; +const TInt KNcmDataClassHeaderDescriptorLength = 5; +const TInt KNcmDeviceDescriptorLength = 18; +const TInt KNcmConfigurationDescriptorLength = 9; +const TInt KNcmCommunicationClassEndpointOutDescriptorLength = 9; +const TInt KNcmNotificationEndpointDescriptorLength = 7; +const TInt KNcmDataClassInterfaceDescriptorLength = 9; +const TInt KNcmDataClassEndpointInDescriptorLength = 7; +const TInt KNcmDataClassEndpointOutDescriptorLength = 7; + +const TInt KNcmDescriptorLength = KNcmInterfaceDescriptorLength + + KNcmCcHeaderDescriptorLength + KNcmFunctionalDescriptorLength + + KNcmCcUfdDescriptorLength + KNcmDataClassHeaderDescriptorLength + + KNcmDeviceDescriptorLength + KNcmConfigurationDescriptorLength + + KNcmCommunicationClassEndpointOutDescriptorLength + + KNcmNotificationEndpointDescriptorLength + + KNcmDataClassInterfaceDescriptorLength + + KNcmDataClassEndpointInDescriptorLength + + KNcmDataClassEndpointOutDescriptorLength; + +// Panic codes +enum TNcmClassControllerPanicCode + { + ENcmPanicBadState = 1, + ENcmPanicOutstandingRequestFromDevice, + ENcmPanicAlreadyActive, + ENcmPanicUnhandledError, + ENcmPanicBadApiCallStart, // Attempt to call Start() when in illegal state + ENcmPanicBadApiCallStop, // Attempt to call Stop() when in illegal state + ENcmPanicUnexpectedIapState, + ENcmPanicUnexpectedError + }; + +/** + * Constructs a CNcmClassController object. + * @param aOwner USB Device that owns and manages the class + * @return Ownership of a new CNcmClassController object + */ +CNcmClassController* CNcmClassController::NewL( + MUsbClassControllerNotify & aOwner) + { + OstTraceFunctionEntry0( CNCMCLASSCONTROLLER_NEWL_ENTRY ); + + CNcmClassController* self = + new (ELeave) CNcmClassController(aOwner); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + OstTraceFunctionExit1( CNCMCLASSCONTROLLER_NEWL_EXIT, ( TUint )( self ) ); + return self; + } + +/** + * Constructor. + * @param aOwner USB Device that owns and manages the class + */ +CNcmClassController::CNcmClassController( + MUsbClassControllerNotify& aOwner) : + CUsbClassControllerPlugIn(aOwner, KNcmStartupPriority) + { + OstTraceFunctionEntryExt( CNCMCLASSCONTROLLER_CNCMCLASSCONTROLLER_ENTRY, this ); + + iState = EUsbServiceIdle; // needs explicit initialisation as non-zero + + OstTraceFunctionExit1( CNCMCLASSCONTROLLER_CNCMCLASSCONTROLLER_EXIT, this ); + } + +/** + * Method to perform second phase construction. + */ +void CNcmClassController::ConstructL() + { + OstTraceFunctionEntry1( CNCMCLASSCONTROLLER_CONSTRUCTL_ENTRY, this ); + +#ifndef OVERDUMMY_NCMCC + TInt err = KErrNone; + + OstTrace0(TRACE_NORMAL, CNCMCLASSCONTROLLER_CONSTRUCTL, "About to load eusbcsc!"); + _LIT(KUsbSCLDDName, "eusbcsc"); + err = User::LoadLogicalDevice(KUsbSCLDDName); + OstTrace1( TRACE_NORMAL, CNCMCLASSCONTROLLER_CONSTRUCTL_LOAD_CSC_LDD, "LoadLogicalDevice() returns %d!", err ); + if (err != KErrNone && err != KErrAlreadyExists) + { + User::Leave(err); + } + OstTrace0(TRACE_NORMAL, CNCMCLASSCONTROLLER_CONSTRUCTL_CSC_LDD_LOADED, "Ldd eusbcsc loaded!"); +#endif // OVERDUMMY_NCMCC + + RandomMacAddressL(); // Create a random MAC address for NCM host side interface. + iConnectionMan = CNcmConnectionManager::NewL(*this, iHostMacAddress, iDataBufferSize, iNcmInternalSvr); + iClientMgr = new (ELeave) CNcmClientManager(iHostMacAddress); + OstTraceFunctionExit1( CNCMCLASSCONTROLLER_CONSTRUCTL_EXIT, this ); + } + +void CNcmClassController::RandomMacAddressL() + { + OstTraceFunctionEntry1( CNCMCLASSCONTROLLER_RANDOMMACADDRESSL_ENTRY, this ); + + //Create the NCM interface MAC address randomly + iHostMacAddress.SetLength(KEthernetAddressLength); + TRandom::RandomL(iHostMacAddress); + + //Mark it a locally administered address + iHostMacAddress[0] = 0x02; + iHostMacAddress[1] = 0x00; + iHostMacAddress[2] = 0x00; + OstTraceFunctionExit1( CNCMCLASSCONTROLLER_RANDOMMACADDRESSL_EXIT, this ); + } + +/** + * Destructor. + */ +CNcmClassController::~CNcmClassController() + { + OstTraceFunctionEntry1( CNCMCLASSCONTROLLER_CNCMCLASSCONTROLLER_ENTRY_DESTROY, this ); + Cancel(); + + // Close internal server to release some resource + iNcmInternalSvr.Close(); + delete iClientMgr; + delete iConnectionMan; + +#ifndef OVERDUMMY_NCMCC + OstTrace0(TRACE_NORMAL, CNCMCLASSCONTROLLER_CNCMCLASSCONTROLLER_PRE_UNLOAD_CSC_LDD, "About to unload Usbcsc!"); + _LIT(KUsbSCLDDName, "Usbcsc"); + TInt err = User::FreeLogicalDevice(KUsbSCLDDName); + OstTrace1(TRACE_NORMAL, CNCMCLASSCONTROLLER_CNCMCLASSCONTROLLER_UNLOAD_LDD_RESULT, "FreeLogicalDevice() returns %d!", err); +#endif // OVERDUMMY_NCMCC + OstTraceFunctionExit1( CNCMCLASSCONTROLLER_CNCMCLASSCONTROLLER_EXIT_DESTROY, this ); + } + +/** + * Called by UsbMan to start this class. + * @param aStatus Will be completed with success or failure. + */ +void CNcmClassController::Start(TRequestStatus& aStatus) + { + OstTraceFunctionEntryExt( CNCMCLASSCONTROLLER_START_ENTRY, this ); + OstTrace1(TRACE_NORMAL, CNCMCLASSCONTROLLER_START_PRINT_STATE, "iState=%d", iState); + + //Start() should only be called if the CC is idle state + __ASSERT_DEBUG((iState == EUsbServiceIdle), + User::Panic(KNcmControllerPanic, ENcmPanicBadApiCallStart)); + + // NB We enforce that the device doesn't re-post requests on us. + __ASSERT_DEBUG(!iReportStatus, + User::Panic(KNcmControllerPanic, ENcmPanicOutstandingRequestFromDevice)); + + // We should not be active before start + __ASSERT_DEBUG(!IsActive(), User::Panic(KNcmControllerPanic, ENcmPanicAlreadyActive)); + + aStatus = KRequestPending; + iReportStatus = &aStatus; + + iState = EUsbServiceStarting; + + // According to the latest discussion of 100ms limitation to + // each personality starting, the calling to iConnectionMan->Start + // will happen later. A controller will set sevice state to started + // immediately after calling to RDevUsbcScClient::SetInterface() + + TInt err = KErrNone; + + // Can not leave. Trap any error from SetNcmInterfacesL() + TRAP(err, iClientMgr->SetNcmInterfacesL(iDataBufferSize)); + User::RequestComplete(iReportStatus, err); + + if (KErrNone == err) + { + // Set service state to started + iState = EUsbServiceStarted; + + iStatus = KRequestPending; + SetActive(); + TRequestStatus* status = &iStatus; + User::RequestComplete(status, err); + } + OstTraceFunctionExit1( CNCMCLASSCONTROLLER_START_EXIT, this ); + } + +/** + * Called by UsbMan to stop this class. + * @param aStatus Will be completed with success or failure. + */ +void CNcmClassController::Stop(TRequestStatus& aStatus) + { + OstTraceFunctionEntryExt( CNCMCLASSCONTROLLER_STOP_ENTRY, this ); + OstTrace1( TRACE_NORMAL, CNCMCLASSCONTROLLER_STOP_PRINT_STATE, "iState=%d", iState ); + + __ASSERT_DEBUG(((iState == EUsbServiceStarted)||(iState == EUsbServiceStarting)), + User::Panic(KNcmControllerPanic, ENcmPanicBadApiCallStop)); + + // NB We enforce that the device doesn't re-post requests on us. + __ASSERT_DEBUG(!iReportStatus, + User::Panic(KNcmControllerPanic, ENcmPanicOutstandingRequestFromDevice)); + + if (IsActive()) // Networking connetion building is ongoing! + { + Cancel(); + } + else + { + iConnectionMan->Stop(); + } + + aStatus = KRequestPending; + iReportStatus = &aStatus; + User::RequestComplete(iReportStatus, KErrNone); + + iConnectingToNcmPktDrv = EFalse; + iState = EUsbServiceIdle; + OstTraceFunctionExit1( CNCMCLASSCONTROLLER_STOP_EXIT, this ); + } + +/** + * Returns information about the interfaces supported by this class. + * @param aDescriptorInfo Will be filled in with interface information. + */ +void CNcmClassController::GetDescriptorInfo( + TUsbDescriptor& aDescriptorInfo) const + { + OstTraceFunctionEntryExt( CNCMCLASSCONTROLLER_GETDESCRIPTORINFO_ENTRY, this ); + + aDescriptorInfo.iNumInterfaces = 2; + aDescriptorInfo.iLength = KNcmDescriptorLength; + OstTraceFunctionExit1( CNCMCLASSCONTROLLER_GETDESCRIPTORINFO_EXIT, this ); + } + +void CNcmClassController::McmoErrorIndication(TInt aError) + { + OstTraceFunctionEntryExt( CNCMCLASSCONTROLLER_MCMOERRORINDICATION_ENTRY, this ); + + Owner().UccnError(aError); + + OstTraceFunctionExit1( CNCMCLASSCONTROLLER_MCMOERRORINDICATION_EXIT, this ); + } + +/** + * Called when connection manager completes. + */ +void CNcmClassController::RunL() + { + OstTraceFunctionEntry1( CNCMCLASSCONTROLLER_RUNL_ENTRY, this ); + TInt completionCode = iStatus.Int(); + OstTraceExt2( TRACE_NORMAL, CNCMCLASSCONTROLLER_RUNL_PRINT_INFO, "iState=%d; completionCode=%d", iState, completionCode ); + + // Goto RunError() to handle any exception + User::LeaveIfError(completionCode); + + // We should only be in starting state when connection manager completes. Stopping is a synchronous call. + __ASSERT_DEBUG(EUsbServiceStarted == iState, User::Panic(KNcmControllerPanic, + ENcmPanicBadState)); + + switch (iState) + { + case EUsbServiceStarted: + { + OstTrace0( TRACE_NORMAL, CNCMCLASSCONTROLLER_RUNL_STARTED, "EUsbServiceStarted" ); + if (iConnectingToNcmPktDrv) + { + OstTrace0( TRACE_FLOW, CNCMCLASSCONTROLLER_RUNL_TRANSFER_HANDLES, "An Ethernet connection over NCM built. Transfer interface handlers to NCM internal server." ); + // NCM Packet Driver Loaded in C32, now transfer LDD handles to packet driver side through NCM internal server + iClientMgr->TransferInterfacesL(iNcmInternalSvr); + + delete iClientMgr; + iClientMgr = NULL; + } + else + { + OstTrace0( TRACE_NORMAL, CNCMCLASSCONTROLLER_RUNL_BUILT_NCM_CONNECTION, "Going to build ethernet connection over NCM!" ); + iConnectingToNcmPktDrv = ETrue; + iStatus = KRequestPending; + SetActive(); + iConnectionMan->Start(iStatus); + } + + break; + } + + default: + { + OstTrace0( TRACE_ERROR, CNCMCLASSCONTROLLER_RUNL_DEFAULT, "Default::SHOULD NOT BE HERE!!!" ); + User::Panic(KNcmControllerPanic, ENcmPanicBadState); + break; + } + } + OstTraceFunctionExit1( CNCMCLASSCONTROLLER_RUNL_EXIT, this ); + } + +/** + * Implements cancellation of an outstanding request. + */ +void CNcmClassController::DoCancel() + { + OstTraceFunctionEntry1( CNCMCLASSCONTROLLER_DOCANCEL_ENTRY, this ); + + OstTraceExt2( TRACE_NORMAL, CNCMCLASSCONTROLLER_DOCANCEL_INFO_PRINT, "iState=%d; iReportStatus=%p", iState, iReportStatus ); + + // Update our iState. If we're starting, then roll back to idle. If we're + // stopping, role back to started. Nothing else is legal. + switch (iState) + { + case EUsbServiceStarted: + OstTrace0( TRACE_NORMAL, CNCMCLASSCONTROLLER_DOCANCEL_IDLE, "EUsbServiceIdle" ); + iState = EUsbServiceIdle; + if (iConnectingToNcmPktDrv) + { + iConnectionMan->StartCancel(); + } + __ASSERT_DEBUG(!iReportStatus, User::Panic(KNcmControllerPanic, ENcmPanicUnhandledError)); + + OstTraceFunctionExit1( CNCMCLASSCONTROLLER_DOCANCEL_EXIT, this ); + return; + + default: + OstTrace1(TRACE_FATAL, CNCMCLASSCONTROLLER_DOCANCEL_DEFAULT, "Default::Should not be here:iState=%d", iState); + User::Panic(KNcmControllerPanic, ENcmPanicBadState); + break; + } + + // Complete the client's request. + __ASSERT_DEBUG(iReportStatus, User::Panic(KNcmControllerPanic, ENcmPanicUnhandledError)); + User::RequestComplete(iReportStatus, KErrCancel); + + OstTraceFunctionExit1( CNCMCLASSCONTROLLER_DOCANCEL_EXIT_DUP1, this ); + } + +/** + * Called when RunL leaves. Does nothing, just return KErrNone. + * @return Error code. Simply return KErrNone. + */ +TInt CNcmClassController::RunError(TInt aError) + { + OstTraceFunctionEntryExt( CNCMCLASSCONTROLLER_RUNERROR_ENTRY, this ); + + if (KErrCancel != aError) + { + // Report this failure to the observer + // Finally this will report to usbman and NCM class will be stopped. + McmoErrorIndication(aError); + } + + OstTraceFunctionExitExt( CNCMCLASSCONTROLLER_RUNERROR_EXIT, this, KErrNone ); + return KErrNone; + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/ncmclassdescriptor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/ncmclassdescriptor.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,87 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** + * @file + * @internalComponent + */ + +#ifdef OVERDUMMY_NCMCC +#include +#else +#include +#endif // OVERDUMMY_NCMCC + +#include "ncmclassdescriptor.h" +// For OST tracing +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "ncmclassdescriptorTraces.h" +#endif + + +/** + * This function packs the TNcmClassDescriptor class into a descriptor with + * the correct byte alignment for transmission on the USB bus. + * + * @return Correctly-aligned buffer. NB The buffer returned is a member of + * this class and has the same lifetime. + */ +TDes8& TNcmClassDescriptor::Des() + { + OstTraceFunctionEntry0( TNCMCLASSDESCRIPTOR_DES_ENTRY ); + TUint index = 0; + + iBuffer.SetLength(KUSBNcmClassSpecificBufferSize); + + iBuffer[index++] = iHdrSize; + iBuffer[index++] = iHdrType; + iBuffer[index++] = iHdrSubType; + LittleEndian::Put16(&iBuffer[index], iHdrBcdCDC); + index += 2; + + iBuffer[index++] = iUnSize; + iBuffer[index++] = iUnType; + iBuffer[index++] = iUnSubType; + iBuffer[index++] = iUnMasterInterface; + iBuffer[index++] = iUnSlaveInterface; + + iBuffer[index++] = iEthFunLength; + iBuffer[index++] = iEthFunType; + iBuffer[index++] = iEthFunSubtype; + iBuffer[index++] = iMACAddress; + LittleEndian::Put32(&iBuffer[index], iEthernetStatistics); + index += 4; + LittleEndian::Put16(&iBuffer[index], iMaxSegmentSize); + index += 2; + LittleEndian::Put16(&iBuffer[index], iNumberMCFilters); + index += 2; + iBuffer[index++] = iNumberPowerFilters; + + iBuffer[index++] = iNcmFunLength; + iBuffer[index++] = iNcmFunType; + iBuffer[index++] = iNcmFunSubtype; + LittleEndian::Put16(&iBuffer[index], iNcmVersion); + index += 2; + iBuffer[index++] = iNetworkCapabilities; + + OstTraceFunctionExit0( TNCMCLASSDESCRIPTOR_DES_EXIT ); + return iBuffer; + } + +// End of file + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/ncmclassimpcollection.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/ncmclassimpcollection.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** + * @file + * @internalComponent + */ + +#include +#include +#include +#include +#include "ncmclasscontroller.h" + +// Define the private interface UIDs +const TImplementationProxy UsbCCImplementationTable[] = + { +#ifdef OVERDUMMY_NCMCC + IMPLEMENTATION_PROXY_ENTRY(0x2002EA9F, CNcmClassController::NewL), +#else + IMPLEMENTATION_PROXY_ENTRY(0x2002c305, CNcmClassController::NewL), +#endif // OVERDUMMY_NCMCC + }; + +EXPORT_C const TImplementationProxy* ImplementationGroupProxy(TInt& aTableCount) + { + aTableCount = sizeof(UsbCCImplementationTable) / sizeof(TImplementationProxy); + + return UsbCCImplementationTable; + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/ncmclientmanager.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/ncmclientmanager.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,546 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** + * @file + * @internalComponent + */ + +#include "ncmclientmanager.h" + + +#ifdef OVERDUMMY_NCMCC +#include +#else +#include "ncminternalsrv.h" +#endif // OVERDUMMY_NCMCC + +#include "ncmclassdescriptor.h" +// For OST tracing +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "ncmclientmanagerTraces.h" +#endif + + +// NCM Interface MTU size +extern const TUint KEthernetFrameSize; + +// NCM MAC Address String descriptor buffer length +const TUint KMacAddrStringDescSize = 32; + + +/** + * Construtor + * @param aMacAddress the NCM ethernet interface MAC address + */ +CNcmClientManager::CNcmClientManager(const TNcmMacAddress& aHostMacAddress): + iHostMacAddress(aHostMacAddress) + { + OstTraceFunctionEntryExt( CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_ENTRY, this ); + + // No implementation required + OstTraceFunctionExit1( CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_EXIT, this ); + } + +/** + * Destructor + */ +CNcmClientManager::~CNcmClientManager() + { + OstTraceFunctionEntry0( CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_ENTRY_DESTRUCTOR ); + + TInt err = KErrNone; + if (iCommLddInitiated) + { + RChunk* commChunk = NULL; + OstTrace0(TRACE_NORMAL, CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_PRE_CLOSE_COMM_INTERFACE, "About to get chunk handle for communication interface!"); + err = iCommLdd.GetDataTransferChunk(commChunk); + if (KErrNone == err) + { + OstTrace0(TRACE_NORMAL, CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_CLOSE_COMM_CHUNK, "About to close chunk handle for communication interface!"); + commChunk->Close(); + } + else + { + OstTrace1(TRACE_ERROR, CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_CLOSE_COMM_CHUNK_FAIL, "Can not get chunk handle for communication interface: err = %d", err); + } + + OstTrace0(TRACE_NORMAL, CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_CLOSE_COMM_INTERFACE, "About to close device handle for communication interface!"); + iCommLdd.Close(); + } + + if (iDataLddInitiated) + { + RChunk* dataChunk = NULL; + OstTrace0(TRACE_NORMAL, CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_PRE_CLOSE_DATA_INTERFACE, "About to get chunk handle for data interface!"); + err = iDataLdd.GetDataTransferChunk(dataChunk); + if (KErrNone == err) + { + OstTrace0(TRACE_NORMAL, CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_CLOSE_DATA_CHUNK, "About to close chunk handle for communication interface!"); + dataChunk->Close(); + } + else + { + OstTrace1(TRACE_ERROR, CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_CLOSE_DATA_CHUNK_FAIL, "Can not get chunk handle for data interface: err = %d", err); + } + + OstTrace0(TRACE_NORMAL, CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_CLOSE_DATA_INTERFACE, "About to close device handle for data interface!"); + iDataLdd.Close(); + } + OstTraceFunctionExit0( CNCMCLIENTMANAGER_CNCMCLIENTMANAGER_ENTRY_DESTRUCTOR_EXIT ); + } + + +/** + * Setup NCM interfaces + * @param[out] aDataEpBufferSize, NCM data interface EP buffer size + */ +void CNcmClientManager::SetNcmInterfacesL(TUint& aDataEpBufferSize) + { + OstTraceFunctionEntryExt( CNCMCLIENTMANAGER_SETNCMINTERFACESL_ENTRY, this ); + + // Setup NCM communication interface + SetCommunicationInterfaceL(); + + // Setup NCM data interface + SetDataInterfaceL(aDataEpBufferSize); + + // Retrieve data interface number + TUint8 dataInterfaceNumber = 1; + User::LeaveIfError(DataInterfaceNumber(dataInterfaceNumber)); + + // Setup NCM class descriptor with correct interface number + User::LeaveIfError(SetupClassSpecificDescriptor(dataInterfaceNumber)); + OstTraceFunctionExit1( CNCMCLIENTMANAGER_SETNCMINTERFACESL_EXIT, this ); + } + +/** + * Transfer NCM interface handlers from NCM class controller to NCM + * packet driver through NCM internal server. + * @param aServer a reference to RNcmInternalSrv + */ +void CNcmClientManager::TransferInterfacesL(RNcmInternalSrv& aServer) + { + OstTraceFunctionEntryExt( CNCMCLIENTMANAGER_TRANSFERINTERFACESL_ENTRY, this ); + + RChunk* commChunk = NULL; + RChunk* dataChunk = NULL; + + OstTrace0(TRACE_NORMAL, CNCMCLIENTMANAGER_TRANSFERINTERFACESL_PRE_TRANSFER_INTERFACES, "About to Transfer handles to NCM internal server!"); + User::LeaveIfError(iCommLdd.GetDataTransferChunk(commChunk)); + User::LeaveIfError(iDataLdd.GetDataTransferChunk(dataChunk)); + User::LeaveIfError(aServer.TransferHandle(iCommLdd, *commChunk, + iDataLdd, *dataChunk)); + OstTrace0(TRACE_NORMAL, CNCMCLIENTMANAGER_TRANSFERINTERFACESL_INTERFACES_TRANSFERED, "Transfer handles to NCM internal server Done!"); + OstTraceFunctionExit1( CNCMCLIENTMANAGER_TRANSFERINTERFACESL_EXIT, this ); + } + +/** + * Setup NCM communication inteface + */ +void CNcmClientManager::SetCommunicationInterfaceL() + { + OstTraceFunctionEntry1( CNCMCLIENTMANAGER_SETCOMMUNICATIONINTERFACEL_ENTRY, this ); + + User::LeaveIfError(iCommLdd.Open(0)); + iCommLddInitiated = ETrue; + + TInt err = KErrNone; + + TUsbcScInterfaceInfoBuf ifc0; + TUsbcDeviceState deviceStatus; + + User::LeaveIfError(iCommLdd.DeviceStatus(deviceStatus)); + + if (deviceStatus == EUsbcDeviceStateConfigured) + { + User::Leave( KErrInUse); + } + + TUsbDeviceCaps dCaps; + User::LeaveIfError(iCommLdd.DeviceCaps(dCaps)); + + TInt epNum = dCaps().iTotalEndpoints; + + TUsbcEndpointData data[KUsbcMaxEndpoints]; + TPtr8 dataptr(reinterpret_cast (data), sizeof(data), + sizeof(data)); + + User::LeaveIfError(iCommLdd.EndpointCaps(dataptr)); + + TBool foundIntIN = EFalse; + for (TInt i = 0; i < epNum; i++) + { + const TUsbcEndpointCaps* caps = &data[i].iCaps; + if ((caps->iTypesAndDir & (KUsbEpTypeInterrupt | KUsbEpDirIn)) + == (KUsbEpTypeInterrupt | KUsbEpDirIn)) + { + // EEndpoint1 is going to be our INTERRUPT (IN, write) endpoint + ifc0().iEndpointData[0].iType = KUsbEpTypeInterrupt; + ifc0().iEndpointData[0].iDir = KUsbEpDirIn; + ifc0().iEndpointData[0].iSize = caps->MinPacketSize(); + ifc0().iEndpointData[0].iInterval = 0x01; + ifc0().iEndpointData[0].iInterval_Hs = 0x01; + + foundIntIN = ETrue; + break; + } + } + if (EFalse == foundIntIN) + { + OstTrace0( TRACE_ERROR, CNCMCLIENTMANAGER_SETCOMMUNICATIONINTERFACEL, "Can not find proper endpint for NCM communication interface" ); + User::Leave( KErrNotFound); + } + + /*********************************************************************************************/ + //Communication Class Interface (0x00) + /*********************************************************************************************/ + _LIT16(KIfClassName0, "USB Networking (NCM)"); + HBufC16* string0 = KIfClassName0().AllocLC(); + + ifc0().iString = string0; + ifc0().iTotalEndpointsUsed = 1; + ifc0().iClass.iClassNum = 0x02; + ifc0().iClass.iSubClassNum = 0x0D; + ifc0().iClass.iProtocolNum = 0x00; + + User::LeaveIfError(iCommLdd.SetInterface(0, ifc0)); + + err = iCommLdd.FinalizeInterface(); + if (KErrNone != err) + { + OstTrace1(TRACE_ERROR, CNCMCLIENTMANAGER_SETCOMMUNICATIONINTERFACEL_FAIL_TO_INIT, "Failed to FinalizeInterface, err %d", err); + User::Leave(err); + } + CleanupStack::PopAndDestroy(string0); + OstTraceFunctionExit1( CNCMCLIENTMANAGER_SETCOMMUNICATIONINTERFACEL_EXIT, this ); + } + +/** + * Setup NCM data interface + * @param aDataEpBufferSize, the determined data interface + * endpoint buffer size. + */ +void CNcmClientManager::SetDataInterfaceL(TUint& aDataEpBufferSize) + { + OstTraceFunctionEntryExt( CNCMCLIENTMANAGER_SETDATAINTERFACEL_ENTRY, this ); + + const TUint KMaxScBufferSize = 1048576; // Up limit of end point buffer + const TUint KMinScBufferSize = 262144; // Lower limit of end point buffer + const TUint KMaxScReadSize = 65536; + + User::LeaveIfError(iDataLdd.Open(0)); + iDataLddInitiated = ETrue; + + TUsbcScInterfaceInfoBuf ifc0, ifc1; + TUsbDeviceCaps dCaps; + User::LeaveIfError(iDataLdd.DeviceCaps(dCaps)); + + TBool isResourceAllocationV2 = ((dCaps().iFeatureWord1 + & KUsbDevCapsFeatureWord1_EndpointResourceAllocV2) != 0); + + TUsbcDeviceState deviceStatus; + + User::LeaveIfError(iDataLdd.DeviceStatus(deviceStatus)); + if (deviceStatus == EUsbcDeviceStateConfigured) + { + User::Leave(KErrInUse); + } + + TInt epNum = dCaps().iTotalEndpoints; + TUsbcEndpointData data[KUsbcMaxEndpoints]; + TPtr8 dataptr(reinterpret_cast (data), sizeof(data), + sizeof(data)); + + User::LeaveIfError(iDataLdd.EndpointCaps(dataptr)); + + const TUint KNcmDataInterfaceEpNumber = 2; + TBool foundBulkIN = EFalse; + TBool foundBulkOUT = EFalse; + TInt maxPacketSize = 0; + for (TInt i = 0; i < epNum; i++) + { + const TUsbcEndpointCaps* caps = &data[i].iCaps; + maxPacketSize = caps->MaxPacketSize(); + if (!foundBulkIN && (caps->iTypesAndDir & (KUsbEpTypeBulk + | KUsbEpDirIn)) == (KUsbEpTypeBulk | KUsbEpDirIn)) + { + // EEndpoint1 is going to be our TX (IN, write) endpoint + ifc1().iEndpointData[0].iType = KUsbEpTypeBulk; + ifc1().iEndpointData[0].iDir = KUsbEpDirIn; + ifc1().iEndpointData[0].iSize = maxPacketSize; + ifc1().iEndpointData[0].iInterval_Hs = 0x01; + ifc1().iEndpointData[0].iBufferSize = KMaxScBufferSize; + + if (isResourceAllocationV2) + { + ifc1().iEndpointData[0].iFeatureWord1 |= + (KUsbcEndpointInfoFeatureWord1_DMA | KUsbcEndpointInfoFeatureWord1_DoubleBuffering); + } + + foundBulkIN = ETrue; + if (foundBulkIN && foundBulkOUT) + { + break; + } + continue; + } + + if (!foundBulkOUT && (caps->iTypesAndDir & (KUsbEpTypeBulk + | KUsbEpDirOut)) == (KUsbEpTypeBulk | KUsbEpDirOut)) + { + // EEndpoint2 is going to be our RX (OUT, read) endpoint + ifc1().iEndpointData[1].iType = KUsbEpTypeBulk; + ifc1().iEndpointData[1].iDir = KUsbEpDirOut; + ifc1().iEndpointData[1].iSize = maxPacketSize; + ifc1().iEndpointData[1].iInterval_Hs = 0; + ifc1().iEndpointData[1].iBufferSize = KMaxScBufferSize; + ifc1().iEndpointData[1].iReadSize = KMaxScReadSize; + + if (isResourceAllocationV2) + { + ifc1().iEndpointData[1].iFeatureWord1 |= + (KUsbcEndpointInfoFeatureWord1_DMA | KUsbcEndpointInfoFeatureWord1_DoubleBuffering); + } + + foundBulkOUT = ETrue; + if (foundBulkIN && foundBulkOUT) + { + break; + } + continue; + } + } + + // Leave if no properly endpoint is found + if (EFalse == foundBulkIN || EFalse == foundBulkOUT) + { + User::Leave(KErrNotFound); + } + + _LIT16(KIfClassName0, "NCM Data Interface 0"); + + HBufC16* string0 = KIfClassName0().AllocL(); + CleanupStack::PushL(string0); + ifc0().iString = string0; + ifc0().iTotalEndpointsUsed = 0; + ifc0().iClass.iClassNum = 0x0A; + ifc0().iClass.iSubClassNum = 0x00; + ifc0().iClass.iProtocolNum = 0x01; + User::LeaveIfError(iDataLdd.SetInterface(0, ifc0)); + + _LIT16(KIfClassName1, "NCM Data Interface 1"); + HBufC16* string1 = KIfClassName1().AllocL(); + CleanupStack::PushL(string1); + ifc1().iString = string1; + ifc1().iTotalEndpointsUsed = KNcmDataInterfaceEpNumber; + ifc1().iClass.iClassNum = 0x0A; + ifc1().iClass.iSubClassNum = 0x00; + ifc1().iClass.iProtocolNum = 0x01; + + // Try to allocate expected memory for data interface endpoints + aDataEpBufferSize = KMaxScBufferSize; + + TInt err = KErrNone; + FOREVER + { + OstTrace1(TRACE_NORMAL, CNCMCLIENTMANAGER_SETDATAINTERFACEL_TRY_NEW_BUF_SIZE, "Try buffer size: %d", aDataEpBufferSize); + err = iDataLdd.SetInterface(1, ifc1); + if (KErrNoMemory == err) + { + // Reduce buffer size and retry + aDataEpBufferSize = aDataEpBufferSize / 2; + if (aDataEpBufferSize < KMinScBufferSize) + { + User::Leave(KErrNoMemory); + } + ifc1().iEndpointData[0].iBufferSize = aDataEpBufferSize; + ifc1().iEndpointData[1].iBufferSize = aDataEpBufferSize; + continue; + } + else + { + OstTrace1(TRACE_ERROR, CNCMCLIENTMANAGER_SETDATAINTERFACEL_SET_INTERFACE_FAIL, "Set data interface and the returned err code is %d", err); + // Leave with error code + User::LeaveIfError(err); + break; + } + } + + CleanupStack::PopAndDestroy(2, string0); + + User::LeaveIfError(iDataLdd.FinalizeInterface()); + OstTraceFunctionExit1( CNCMCLIENTMANAGER_SETDATAINTERFACEL_EXIT, this ); + } + +/** + * Setup the Class Descriptors + * @param aDataInterfaceNumber The interface number of the data class + * @return Error. + */ +TInt CNcmClientManager::SetupClassSpecificDescriptor(TUint8 aDataInterfaceNumber) + { + OstTraceFunctionEntryExt( CNCMCLIENTMANAGER_SETUPCLASSSPECIFICDESCRIPTOR_ENTRY, this ); + + TInt res; + + TNcmClassDescriptor descriptor; + + // Header Functional Descriptor- CDC spec table 15 + descriptor.iHdrSize = 0x05; + descriptor.iHdrType = 0x24; + descriptor.iHdrSubType = 0x00; + descriptor.iHdrBcdCDC = 0x0120; + + // Ethernet Networking Functional Descriptor- ECM spec table 3 + descriptor.iEthFunLength = 0x0D; + descriptor.iEthFunType = 0x24; + descriptor.iEthFunSubtype = 0x0F; + + // Generate the MAC address new NCM interface + res = SetMacAddressString(descriptor.iMACAddress); + + if (res != KErrNone) + { + OstTraceFunctionExitExt( CNCMCLIENTMANAGER_SETUPCLASSSPECIFICDESCRIPTOR_EXIT, this, res ); + return res; + } + + descriptor.iEthernetStatistics = 0; + descriptor.iMaxSegmentSize = KEthernetFrameSize; + descriptor.iNumberMCFilters = 0; + descriptor.iNumberPowerFilters = 0; + + // NCM Functional Descriptor- NCM spec table 5-2 + descriptor.iNcmFunLength = 0x06; + descriptor.iNcmFunType = 0x24; + descriptor.iNcmFunSubtype = 0x1A; + descriptor.iNcmVersion = 0x0100; + descriptor.iNetworkCapabilities = 0; + + // Union functional descriptor- CDC spec table 16 + descriptor.iUnSize = 0x05; + descriptor.iUnType = 0x24; + descriptor.iUnSubType = 0x06; + descriptor.iUnMasterInterface = 0; + descriptor.iUnSlaveInterface = aDataInterfaceNumber; + + OstTrace0( TRACE_NORMAL, CNCMCLIENTMANAGER_SETUPCLASSSPECIFICDESCRIPTOR_PRE_SET_BLOCK, "About to call SetCSInterfaceDescriptorBlock" ); + res = iCommLdd.SetCSInterfaceDescriptorBlock(0, descriptor.Des()); + if (res != KErrNone) + { + OstTraceFunctionExitExt( CNCMCLIENTMANAGER_SETUPCLASSSPECIFICDESCRIPTOR_EXIT_DUP1, this, res ); + return res; + } + + OstTraceFunctionExitExt( CNCMCLIENTMANAGER_SETUPCLASSSPECIFICDESCRIPTOR_EXIT_DUP2, this, KErrNone ); + return KErrNone; + } + +/** + * Set the MAC address string in descriptor + * @param aStrIndex the MAC address string index + */ +TInt CNcmClientManager::SetMacAddressString(TUint8& aStrIndex) + { + OstTraceFunctionEntryExt( CNCMCLIENTMANAGER_SETMACADDRESSSTRING_ENTRY, this ); + + TBuf16 str; + + // Search for MAC address string from index 0x10 + aStrIndex = 0x10; + + TInt ret = KErrNone; +#ifndef OVERDUMMY_NCMCC + while (aStrIndex++ < 0xFF && ret != KErrNotFound) + { + ret = iDataLdd.GetStringDescriptor(aStrIndex, str); + } +#endif // OVERDUMMY_NCMCC + + if (aStrIndex < 0xFF) + { + TBuf8 macAddrStr; + _LIT8(KMacAddressFormat, "%02X%02X%02X%02X%02X%02X"); + OstTraceExt1(TRACE_NORMAL, CNCMCLIENTMANAGER_SETMACADDRESSSTRING, "The MAC address is %s", iHostMacAddress); + macAddrStr.AppendFormat(KMacAddressFormat, iHostMacAddress[0], + iHostMacAddress[1], iHostMacAddress[2], iHostMacAddress[3], + iHostMacAddress[4], iHostMacAddress[5]); + str.Copy(macAddrStr); + ret = iDataLdd.SetStringDescriptor(aStrIndex, str); + } + + OstTraceFunctionExitExt( CNCMCLIENTMANAGER_SETMACADDRESSSTRING_EXIT, this, ret ); + return ret; + } + +/** + * Get NCM data interface number + * @param aInterfaceNumber NCM data interface number + * @return Error. + */ +TInt CNcmClientManager::DataInterfaceNumber(TUint8& aInterfaceNumber) + { + OstTraceFunctionEntryExt( CNCMCLIENTMANAGER_DATAINTERFACENUMBER_ENTRY, this ); + + TInt interfaceSize = 0; + + // 0 means the main interface in the LDD API + TInt res = iDataLdd.GetInterfaceDescriptorSize(0, interfaceSize); + + if ( KErrNone == res ) + { + OstTraceFunctionExitExt( CNCMCLIENTMANAGER_DATAINTERFACENUMBER_EXIT, this, res ); + return res; + } + + HBufC8* interfaceBuf = HBufC8::New(interfaceSize); + if ( !interfaceBuf ) + { + OstTraceFunctionExitExt( CNCMCLIENTMANAGER_DATAINTERFACENUMBER_EXIT_DUP1, this, KErrNoMemory); + return KErrNoMemory; + } + + TPtr8 interfacePtr = interfaceBuf->Des(); + interfacePtr.SetLength(0); + // 0 means the main interface in the LDD API + res = iDataLdd.GetInterfaceDescriptor(0, interfacePtr); + + if ( KErrNone == res ) + { + delete interfaceBuf; + OstTraceFunctionExitExt( CNCMCLIENTMANAGER_DATAINTERFACENUMBER_EXIT_DUP2, this, res ); + return res; + } + + OstTrace1(TRACE_NORMAL, CNCMCLIENTMANAGER_DATAINTERFACENUMBER_INTERFACE_INFO, "***Interface length =% d", interfacePtr.Length()); + for ( TInt i = 0 ; i < interfacePtr.Length() ; i++ ) + { + OstTrace1(TRACE_NORMAL, CNCMCLIENTMANAGER_DATAINTERFACENUMBER_INTERFACE_INFO2, "***** %x", interfacePtr[i]); + } + + const TUint8* buffer = reinterpret_cast(interfacePtr.Ptr()); + // 2 is where the interface number is, according to the LDD API + aInterfaceNumber = buffer[2]; + OstTraceExt1(TRACE_NORMAL, CNCMCLIENTMANAGER_DATAINTERFACENUMBER, "Interface number = %hhu", aInterfaceNumber); + + delete interfaceBuf; + + OstTraceFunctionExitExt( CNCMCLIENTMANAGER_DATAINTERFACENUMBER_EXIT_DUP3, this, KErrNone ); + return KErrNone; + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/ncmconnectionmanager.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/ncmconnectionmanager.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,480 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** + * @file + * @internalComponent + */ + +#ifndef OVERDUMMY_NCMCC +#include +#include +#endif // OVERDUMMY_NCMCC + +#include +#include +#include +#include + +#include "ncmconnectionmanager.h" +#include "ncmiapprogresswatcher.h" +#include "ncmiapreader.h" +#include "ncmdhcpnotifwatcher.h" + +#ifdef OVERDUMMY_NCMCC +#include +#else +#include "ncminternalsrv.h" +#endif // OVERDUMMY_NCMCC + +#include "ncmclasscontroller.h" +#include "ncmconnectionmanagerobserver.h" +#include "ncmconnectionmanagerhelper.h" + +// For OST tracing +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "ncmconnectionmanagerTraces.h" +#endif + +using namespace UsbNcm; + +#if defined(_DEBUG) +_LIT(KNcmConnManagerPanic, "UsbNcmCM"); // must be <=16 chars +#endif + +extern const TUint KEthernetFrameSize; + +// Panic codes +enum TNcmCMPanicCode + { + ENcmCMPanicOutstandingRequestFromDevice = 1, + ENcmCMPanicNoRegisteredWatcher = 2, + ENcmCMEndMark + }; + +/** + * Constructs a CNcmConnectionManager object. + * @param[in] aObserver, NCM connection observer + * @param[in] aHostMacAddress, the NCM interface MAC address + * @param[in] aDataBufferSize, the EndPoint buffer size + * @param[in] aNcmInternalSvr, the NCM internal server + * @return Ownership of a new CNcmConnectionManager object + */ +CNcmConnectionManager* CNcmConnectionManager::NewL( + MNcmConnectionManagerObserver& aObserver, + const TNcmMacAddress& aMacAddress, TUint aDataBufferSize, + RNcmInternalSrv& aNcmInternalSvr) + { + OstTraceFunctionEntry0(CNCMCONNECTIONMANAGER_NEWL_ENTRY); + + CNcmConnectionManager* self = new (ELeave) CNcmConnectionManager(aObserver, + aMacAddress, aDataBufferSize, aNcmInternalSvr); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + + OstTraceFunctionExit0(CNCMCONNECTIONMANAGER_NEWL_EXIT); + return self; + } + +/** + * Method to perform second phase construction. + */ +void CNcmConnectionManager::ConstructL() + { + OstTraceFunctionEntry0(CNCMCONNECTIONMANAGER_CONSTRUCTL_ENTRY); + + TInt err = RProperty::Define(KUsbmanSvrUid, KKeyNcmSharedState, RProperty::EInt, + KAllowAllPolicy, KCommDDPolicy); + + if (KErrNone != err) + { + OstTrace1( TRACE_ERROR, CNCMCONNECTIONMANAGER_CONSTRUCTL, "Define NCM shared state P&S key fail: err=%d", err ); + User::Leave(err); + } + + User::LeaveIfError(iProperty.Attach(KUsbmanSvrUid, KKeyNcmSharedState)); + User::LeaveIfError(iProperty.Set(ENcmStateIntial)); + + User::LeaveIfError(iSocketServ.Connect()); + User::LeaveIfError(iConnection.Open(iSocketServ)); + + iIapPrgrsWatcher = new (ELeave) CNcmIapProgressWatcher(*this, iConnection); + iConnManHelper = new (ELeave) CNcmConnectionManHelper(*this, iConnection); + iDhcpNotifWatcher = new (ELeave) CNcmDhcpNotifWatcher(*this, iNcmInternalSvr); + iIapReader = new (ELeave) CNcmIapReader(*this, iConnPref); + + OstTraceFunctionExit0(CNCMCONNECTIONMANAGER_CONSTRUCTL_EXIT); + } + +/** + * Called when NCM connection starting attempt completed + */ +void CNcmConnectionManager::HandleConnectionCompleteL() + { + OstTraceFunctionEntry0( CNCMCONNECTIONMANAGER_HANDLECONNECTIONCOMPLETEL_ENTRY ); + OstTrace0(TRACE_NORMAL, CNCMCONNECTIONMANAGER_HANDLECONNECTIONCOMPLETEL_CHANGE_MTU, "About to change default MTU size!"); + // Change default MTU size + SetCustomMtuL(); + + OstTrace0(TRACE_NORMAL, CNCMCONNECTIONMANAGER_HANDLECONNECTIONCOMPLETEL_CONN_NCM_INTERNAL_SVR, "About to connect to internal NCM server!"); + + // Connect to internal server in packet driver + User::LeaveIfError(iNcmInternalSvr.Connect()); + + iNcmInternalSvr.TransferBufferSize(iDataBufferSize); + iNcmInternalSvr.SetIapId(iConnPref.IapId()); + iDhcpNotifWatcher->StartL(); + OstTraceFunctionExit0( CNCMCONNECTIONMANAGER_HANDLECONNECTIONCOMPLETEL_EXIT ); + } + +/** + * Destructor. + */ +CNcmConnectionManager::~CNcmConnectionManager() + { + OstTraceFunctionEntry0(CNCMCONNECTIONMANAGER_CNCMCONNECTIONMANAGER_DESTRUCTOR_ENTRY); + + delete iIapReader; + delete iDhcpNotifWatcher; + delete iConnManHelper; + delete iIapPrgrsWatcher; + + iConnection.Close(); + iSocketServ.Close(); + iProperty.Close(); + + RProperty::Delete(KKeyNcmSharedState); + + OstTraceFunctionExit0(CNCMCONNECTIONMANAGER_CNCMCONNECTIONMANAGER_DESTRUCTOR_EXIT); + } + +/** + * Constructor. + * @param[in] aObserver, NCM connection observer + * @param[in] aHostMacAddress, the NCM interface MAC address + * @param[in] aDataBufferSize, the EndPoint buffer size + * @param[in] aNcmInternalSvr, the NCM internal server + */ +CNcmConnectionManager::CNcmConnectionManager(MNcmConnectionManagerObserver& aObserver, + const TNcmMacAddress& aHostMacAddress, TUint aDataBufferSize, + RNcmInternalSrv& aNcmInternalSvr): + iConnMgrObserver(aObserver), + iHostMacAddress(aHostMacAddress), iDataBufferSize(aDataBufferSize), + iNcmInternalSvr(aNcmInternalSvr) + { + // No implementation needed. + } + +/** + *Called by class controller to start the connection building process. + *@param aStatus, reference to ncm class controller's iStatus + */ +void CNcmConnectionManager::Start(TRequestStatus& aStatus) + { + OstTraceFunctionEntry0(CNCMCONNECTIONMANAGER_START_ENTRY); + + __ASSERT_DEBUG(!iReportStatus, + User::Panic(KNcmConnManagerPanic, ENcmCMPanicOutstandingRequestFromDevice)); + + aStatus = KRequestPending; + iReportStatus = &aStatus; + + Reset(); + + // Preparing IAP information + iIapReader->Start(); + OstTraceFunctionExit0(CNCMCONNECTIONMANAGER_START_EXIT); + } + +/** + * Cancel ongoing starting attempt + */ +void CNcmConnectionManager::StartCancel() + { + OstTraceFunctionEntry0(CNCMCONNECTIONMANAGER_STARTCANCEL_ENTRY); + + __ASSERT_DEBUG(iReportStatus, + User::Panic(KNcmConnManagerPanic, ENcmCMPanicNoRegisteredWatcher)); + + Stop(); + + User::RequestComplete(iReportStatus, KErrCancel); + + OstTraceFunctionExit0(CNCMCONNECTIONMANAGER_STARTCANCEL_EXIT); + } + +/** + * Called by class controller to stop the connection. + */ +void CNcmConnectionManager::Stop() + { + OstTraceFunctionEntry0(CNCMCONNECTIONMANAGER_STOP_ENTRY); + + // Cancel any current ongoing operations + Reset(); + + // Reset shared state + iProperty.Set(ENcmStateIntial); + + iConnManHelper->Stop(); + OstTraceFunctionExit0(CNCMCONNECTIONMANAGER_STOP_EXIT); + } + +/** + * Reset conneciton manager itself + */ +void CNcmConnectionManager::Reset() + { + OstTraceFunctionEntry0(CNCMCONNECTIONMANAGER_RESET_ENTRY); + + iConnComplete = EFalse; + + iIapReader->Cancel(); + iDhcpNotifWatcher->Cancel(); + iIapPrgrsWatcher->Cancel(); + iConnManHelper->Cancel(); + + OstTraceFunctionExit0(CNCMCONNECTIONMANAGER_RESET_EXIT); + } +/** + * Change the default MTU size on NCM networking connection + */ +void CNcmConnectionManager::SetCustomMtuL() + { + OstTraceFunctionEntry0(CNCMCONNECTIONMANAGER_SETCUSTOMMTUL_ENTRY); + + RSocket socket; + User::LeaveIfError(socket.Open(iSocketServ, KAfInet, KSockStream, KProtocolInetTcp, + iConnection)); + + TPckgBuf interfaceInfo; + TPckgBuf interfaceName; + + TUint cnt = 0; + iConnection.EnumerateConnections(cnt); // Count all underlying interfaces + + TUint iap = iConnPref.IapId(); + TInt index = 1; + for (index = 1; index <= cnt; index++) + { + TConnectionInfoBuf info; + iConnection.GetConnectionInfo(index, info); + if (info().iIapId == iap) + { + break; + } + } + + if (index > cnt) + { + OstTrace0( TRACE_NORMAL, CNCMCONNECTIONMANAGER_SETCUSTOMMTUL, "Can not find an interface based on NCM!" ); + User::Leave(KErrNotFound); + } + + interfaceName().iIndex = index; + OstTraceExt2( TRACE_NORMAL, CNCMCONNECTIONMANAGER_SETCUSTOMMTUL_INTER_INFO, ";cnt=%d;interfaceName().iIndex=%u", cnt, interfaceName().iIndex ); + User::LeaveIfError(iConnection.Control(KCOLProvider, KConnGetInterfaceName, interfaceName)); + OstTraceExt3( TRACE_NORMAL, CNCMCONNECTIONMANAGER_SETCUSTOMMTUL_NEW_MTU_SIZE, ";Interface Name=%S, ;current MTU=%d. MTU size will be changed to %d!", interfaceName().iName, interfaceInfo().iMtu, KEthernetFrameSize); + + TInt err = socket.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl); + if (err != KErrNone) + { + OstTrace1(TRACE_NORMAL, CNCMCONNECTIONMANAGER_SETCUSTOMMTUL_START_INTER_ENUM, "Failed to set KSoInetEnumInterfaces option [%d]", err); + User::LeaveIfError(err); + } + + err = KErrNotFound; + while (socket.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, interfaceInfo) == KErrNone) + { + OstTraceExt1(TRACE_NORMAL, CNCMCONNECTIONMANAGER_SETCUSTOMMTUL_INTER_NAME, "InterfaceInfo().iName = %S", interfaceInfo().iName); + OstTrace1(TRACE_NORMAL, CNCMCONNECTIONMANAGER_SETCUSTOMMTUL_INTER_MTU, "InterfaceInfo().iMtu = %d", interfaceInfo().iMtu); + if (interfaceInfo().iName == interfaceName().iName) + { + // found the interface + err = KErrNone; + break; + } + } + if (KErrNone != err) + { + OstTrace1(TRACE_ERROR, CNCMCONNECTIONMANAGER_SETCUSTOMMTUL_SEARCH_FAIL, "Can not find NCM connection: err=%x", err); + User::LeaveIfError(err); + } + + // Set new MTU size + TPckgBuf newinterfaceInfo; + newinterfaceInfo().iMtu = KEthernetFrameSize; + newinterfaceInfo().iDoPrefix = 0; + newinterfaceInfo().iDoId = 0; + newinterfaceInfo().iDoState = 0; + newinterfaceInfo().iDoAnycast = 0; + newinterfaceInfo().iDoProxy = 0; + newinterfaceInfo().iAlias = interfaceInfo().iAlias; + newinterfaceInfo().iDelete = interfaceInfo().iDelete; + newinterfaceInfo().iState = interfaceInfo().iState; + newinterfaceInfo().iSpeedMetric = interfaceInfo().iSpeedMetric; + newinterfaceInfo().iFeatures = interfaceInfo().iFeatures; + newinterfaceInfo().iTag = interfaceInfo().iTag; + newinterfaceInfo().iName = interfaceInfo().iName; + newinterfaceInfo().iSpeedMetric = interfaceInfo().iSpeedMetric; + newinterfaceInfo().iFeatures = interfaceInfo().iFeatures; + newinterfaceInfo().iHwAddr = interfaceInfo().iHwAddr; + newinterfaceInfo().iAddress = interfaceInfo().iAddress; + newinterfaceInfo().iNetMask = interfaceInfo().iNetMask; + newinterfaceInfo().iDefGate = interfaceInfo().iDefGate; + newinterfaceInfo().iNameSer2 = interfaceInfo().iNameSer2; + newinterfaceInfo().iNameSer1 = interfaceInfo().iNameSer1; + + OstTrace0( TRACE_NORMAL, CNCMCONNECTIONMANAGER_SETCUSTOMMTUL_PRE_SETMTU, "About to change the default MTU size." ); + User::LeaveIfError(socket.SetOpt(KSoInetConfigInterface, KSolInetIfCtrl, newinterfaceInfo)); + + socket.Close(); + + OstTraceFunctionExit0(CNCMCONNECTIONMANAGER_SETCUSTOMMTUL_EXIT); + } + +/** + * Called by connection watcher when it detects the class fatal error. + */ +void CNcmConnectionManager::MipsoHandleClassFatalError(TInt aError) + { + OstTraceFunctionEntryExt( CNCMCONNECTIONMANAGER_MIPSOHANDLECLASSFATALERROR_ENTRY, this ); + + Reset(); + + __ASSERT_DEBUG(!iReportStatus, User::Panic(KNcmConnManagerPanic, ENcmCMPanicOutstandingRequestFromDevice)); + + OstTrace1(TRACE_ERROR, CNCMCONNECTIONMANAGER_MIPSOHANDLECLASSFATALERROR, "NCM connection fatal error occurs: %d", aError); + + iConnMgrObserver.McmoErrorIndication(aError); + + OstTraceFunctionExit1( CNCMCONNECTIONMANAGER_MIPSOHANDLECLASSFATALERROR_EXIT, this ); + } + +/** + * Called by connection help when it get notification the + * connection over NCM has been established. + */ +void CNcmConnectionManager::MicoHandleConnectionComplete(TInt aError) + { + OstTraceFunctionEntryExt( CNCMCONNECTIONMANAGER_MICOHANDLECONNECTIONCOMPLETE_ENTRY, this ); + + // Reset shared state + iProperty.Set(ENcmStateIntial); + + if (KErrNone == aError) + { + TRAPD(err, HandleConnectionCompleteL()); + User::RequestComplete(iReportStatus, err); + } + else + { + // Leave if connection build failed + User::RequestComplete(iReportStatus, aError); + } + + OstTraceFunctionExit1( CNCMCONNECTIONMANAGER_MICOHANDLECONNECTIONCOMPLETE_EXIT, this ); + } + +/** + * Called by DHCP notification watcher. + * When the NCM internal server send DHCP request notification to + * the watcher, watcher call this function to do DHCP provisioning + * for NCM connection. + */ +void CNcmConnectionManager::MdnoHandleDhcpNotification(TInt aError) + { + OstTraceFunctionEntryExt( CNCMCONNECTIONMANAGER_MDNOHANDLEDHCPNOTIFICATION_ENTRY, this ); + if (KErrNone != aError) + { + // Report this failure to the observer + // Finally this will report to usbman and NCM class will be stopped. + iConnMgrObserver.McmoErrorIndication(aError); + OstTraceFunctionExit1( CNCMCONNECTIONMANAGER_MDNOHANDLEDHCPNOTIFICATION_EXIT, this ); + return; + } + + // Doing DHCP for NCM + aError = KErrNone; + + // Configuring DHCP server to assign the IP address to PC(host) + // Using static IP temporarily and will swithch to use DHCP server to do provision. +// TRequestStatus stat; +// OstTrace0(TRACE_NORMAL, CNCMCONNECTIONMANAGER_MDNOHANDLEDHCPNOTIFICATION_CALL_IOCTL, "About to call to Ioctl()"); +// +// TNcmMacAddress macAddr = iHostMacAddress; +// iConnection.Ioctl(KCOLConfiguration, KConnDhcpSetHwAddressParams, stat, +// &macAddr); +// User::WaitForRequest(stat); +// aError = stat.Int(); +// OstTrace1( TRACE_NORMAL, CNCMCONNECTIONMANAGER_MDNOHANDLEDHCPNOTIFICATION_RETURN_IOCTL, "Return from Ioctl:;aError=%d", aError ); + + if (KErrNone == aError) + { + // Disable timer on interface and wont let interface coming down due to timer expiry. + iConnection.SetOpt(KCOLProvider, KConnDisableTimers, ETrue); + iIapPrgrsWatcher->Start(); + } + else + { + // Silent stop the NCM connection. + iConnManHelper->Stop(); + + // Report this failure to the observer + // Finally this will report to usbman and NCM class will be stopped. + iConnMgrObserver.McmoErrorIndication(aError); + } + + // Set DHCP result to NCM internal server + iNcmInternalSvr.SetDhcpResult(aError); + OstTraceFunctionExit1( CNCMCONNECTIONMANAGER_MDNOHANDLEDHCPNOTIFICATION_EXIT_DUP1, this ); + } + +/** + * Called by IAP reader. + * When IAP reader finished reading NCM IAP preference from CentRep, + * it will call this function to start building ethernet connection + * using NCM IAP configuration. + */ +void CNcmConnectionManager::MicoHandleIAPReadingComplete(TInt aError) + { + OstTraceFunctionEntryExt( CNCMCONNECTIONMANAGER_MICOHANDLEIAPREADINGCOMPLETE_ENTRY, this ); + if (KErrNone != aError) + { + OstTrace1( TRACE_ERROR, CNCMCONNECTIONMANAGER_MICOHANDLEIAPREADINGCOMPLETE_IAP_RESULT, "IAP reading failed with error;aError=%d", aError ); + User::RequestComplete(iReportStatus, aError); + + OstTraceFunctionExit1( CNCMCONNECTIONMANAGER_MICOHANDLEIAPREADINGCOMPLETE_EXIT, this ); + return; + } + + aError = iProperty.Set(ENcmStartRequested); + + if (KErrNone != aError) + { + OstTrace1( TRACE_ERROR, CNCMCONNECTIONMANAGER_MICOHANDLEIAPREADINGCOMPLETE_SET_SHARED_STATE, "Property set failed with error:;aError=%d", aError ); + User::RequestComplete(iReportStatus, aError); + + OstTraceFunctionExit1( CNCMCONNECTIONMANAGER_MICOHANDLEIAPREADINGCOMPLETE_EXIT_DUP1, this ); + return; + } + + iConnManHelper->Start(iConnPref); + OstTraceFunctionExit1( CNCMCONNECTIONMANAGER_MICOHANDLEIAPREADINGCOMPLETE_EXIT_DUP2, this ); + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/ncmconnectionmanagerhelper.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/ncmconnectionmanagerhelper.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,116 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** + * @file + * @internalComponent + */ + +#include + +#include "ncmconnectionmanagerhelper.h" +#include "ncmiapconnectionobserver.h" +#include "ncmconnectionmanager.h" + +// For OST tracing +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "ncmconnectionmanagerhelperTraces.h" +#endif + +/** + * Constructor. + * @param aObserver The object which is interested in the IAP connection completion + * @param aConnection The reference of the NCM connection to be used + */ +CNcmConnectionManHelper::CNcmConnectionManHelper(MNcmConnectionObserver& aObserver, + RConnection& aConnection) + : CActive(CActive::EPriorityStandard) + , iObserver(aObserver) + , iConnection(aConnection) + { + OstTraceFunctionEntryExt( CNCMCONNECTIONMANHELPER_CNCMCONNECTIONMANHELPER_ENTRY, this ); + CActiveScheduler::Add(this); + OstTraceFunctionExit1( CNCMCONNECTIONMANHELPER_CNCMCONNECTIONMANHELPER_EXIT, this ); + } + + +/** + * Destructor. + */ +CNcmConnectionManHelper::~CNcmConnectionManHelper() + { + OstTraceFunctionEntry1( CNCMCONNECTIONMANHELPER_CNCMCONNECTIONMANHELPER_ENTRY_DESTRUCTOR, this ); + if (IsActive()) + { + Cancel(); + } + else + { + Stop(); + } + OstTraceFunctionExit1( CNCMCONNECTIONMANHELPER_CNCMCONNECTIONMANHELPER_ENTRY_DESTRUCTOR_EXIT, this ); + } + +/** + * Start the connection. + * @param aPref NCM connect preference + */ +void CNcmConnectionManHelper::Start(TConnPref& aPref) + { + OstTraceFunctionEntryExt( CNCMCONNECTIONMANHELPER_START_ENTRY, this ); + if (!IsActive()) + { + iConnection.Start(aPref, iStatus); + SetActive(); + } + OstTraceFunctionExit1( CNCMCONNECTIONMANHELPER_START_EXIT, this ); + } + +/** + * Stop the connection. + */ +void CNcmConnectionManHelper::Stop() + { + OstTraceFunctionEntry1( CNCMCONNECTIONMANHELPER_STOP_ENTRY, this ); + + TInt err = iConnection.Stop(RConnection::EStopAuthoritative); + OstTrace1( TRACE_NORMAL, CNCMCONNECTIONMANHELPER_STOP_RETURN_CODE, "Return code from Stop() is:;err=%d", err ); + OstTraceFunctionExit1( CNCMCONNECTIONMANHELPER_STOP_EXIT, this ); + } +/** + * Implements cancellation of an outstanding request. + */ +void CNcmConnectionManHelper::DoCancel() + { + OstTraceFunctionEntry0( CNCMCONNECTIONMANHELPER_DOCANCEL_ENTRY ); + + TInt err = iConnection.Stop(RConnection::EStopAuthoritative); + + OstTrace1( TRACE_NORMAL, CNCMCONNECTIONMANHELPER_DOCNCEL, "Return code from Stop() is:;err=%d", err ); + OstTraceFunctionExit0( CNCMCONNECTIONMANHELPER_DOCANCEL_EXIT ); + } + +/** + * Called when connection completed. + */ +void CNcmConnectionManHelper::RunL() + { + OstTraceFunctionEntry0( CNCMCONNECTIONMANHELPER_RUNL_ENTRY ); + iObserver.MicoHandleConnectionComplete(iStatus.Int()); + OstTraceFunctionExit0( CNCMCONNECTIONMANHELPER_RUNL_EXIT ); + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/ncmdhcpnotifwatcher.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/ncmdhcpnotifwatcher.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,122 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** + *@file + *@internalComponent + */ + +#include "ncmdhcpnotifwatcher.h" +#include "ncmconnectionmanager.h" +#include "ncmdhcpnotifobserver.h" + +#ifdef OVERDUMMY_NCMCC +#include +#else +#include "ncminternalsrv.h" + +#endif // OVERDUMMY_NCMCC + +// For OST trace +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "ncmdhcpnotifwatcherTraces.h" +#endif + +/** + * Constructor. + * @param aObserver The AO which handle the DHCP provisioning request from NCM internal server + * @param aNcmInteralSvr The reference of the NCM internal server client API handle + */ +CNcmDhcpNotifWatcher::CNcmDhcpNotifWatcher(MNcmDhcpNotificationObserver& aObserver, + RNcmInternalSrv& aNcmInteralSvr) + : CActive(CActive::EPriorityStandard), + iObserver(aObserver), + iNcmInteralSvr(aNcmInteralSvr) + { + OstTraceFunctionEntryExt( CNCMDHCPNOTIFWATCHER_CNCMDHCPNOTIFWATCHER_ENTRY, this ); + + CActiveScheduler::Add(this); + OstTraceFunctionExit1( CNCMDHCPNOTIFWATCHER_CNCMDHCPNOTIFWATCHER_EXIT, this ); + } + + +/** + * Destructor. + */ +CNcmDhcpNotifWatcher::~CNcmDhcpNotifWatcher() + { + OstTraceFunctionEntry0( CNCMDHCPNOTIFWATCHER_CNCMDHCPNOTIFWATCHER_ENTRY_DESTROY ); + Cancel(); + OstTraceFunctionExit0( CNCMDHCPNOTIFWATCHER_CNCMDHCPNOTIFWATCHER_EXIT_DESTROY ); + } + +/** + * Start observing the connection stage changes. + */ +void CNcmDhcpNotifWatcher::StartL() + { + OstTraceFunctionEntry0( CNCMDHCPNOTIFWATCHER_START_ENTRY ); + + if(!IsActive()) + { + iNcmInteralSvr.DhcpProvisionNotify(iStatus); + SetActive(); + } + else + { + // Report this to NCM connection manager + OstTrace0( TRACE_FATAL, CNCMDHCPNOTIFWATCHER_STARTL, "DHCP notifier already actived!" ); + User::Leave(KErrInUse); + } + + OstTraceFunctionExit0( CNCMDHCPNOTIFWATCHER_START_EXIT ); + } + +/** + * Implements cancellation of an outstanding request. Cancels the connection progress notification request. + */ +void CNcmDhcpNotifWatcher::DoCancel() + { + OstTraceFunctionEntry0( CNCMDHCPNOTIFWATCHER_DOCANCEL_ENTRY ); + + iNcmInteralSvr.DhcpProvisionNotifyCancel(); + OstTraceFunctionExit0( CNCMDHCPNOTIFWATCHER_DOCANCEL_EXIT ); + } + +/** + * Called when got DHCP provisioning request from NCM internal server. + */ +void CNcmDhcpNotifWatcher::RunL() + { + OstTraceFunctionEntry0( CNCMDHCPNOTIFWATCHER_RUNL_ENTRY ); + + TInt completionCode = iStatus.Int(); + if (KErrCancel != completionCode) + { + // Doing DHCP + iObserver.MdnoHandleDhcpNotification(iStatus.Int()); + + if (KErrNone == completionCode) + { + // Restart the watcher + StartL(); + } + } + OstTraceFunctionExit0( CNCMDHCPNOTIFWATCHER_RUNL_EXIT ); + } + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/ncmiapprogresswatcher.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/ncmiapprogresswatcher.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,122 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** + * @file + * @internalComponent + */ + +#include "ncmiapprogresswatcher.h" +#include "ncmiapprogressstateobserver.h" +#include "ncmconnectionmanager.h" + +// For OST Tracing +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "ncmiapprogresswatcherTraces.h" +#endif + +/** + * Constructor. + * @param aObserver The object which is interested in the IAP progress stage change + * @param aConnection The reference of the NCM connection to be used + */ +CNcmIapProgressWatcher::CNcmIapProgressWatcher(MNcmIapProgressStateObserver& aObserver, RConnection& aConnection) + : CActive(CActive::EPriorityStandard) + , iObserver(aObserver) + , iConnection(aConnection) + { + OstTraceFunctionEntryExt( CNCMIAPPROGRESSWATCHER_CNCMIAPPROGRESSWATCHER_ENTRY, this ); + + CActiveScheduler::Add(this); + OstTraceFunctionExit1( CNCMIAPPROGRESSWATCHER_CNCMIAPPROGRESSWATCHER_EXIT, this ); + } + + +/** + * Destructor. + */ +CNcmIapProgressWatcher::~CNcmIapProgressWatcher() + { + OstTraceFunctionEntry0( CNCMIAPPROGRESSWATCHER_CNCMIAPPROGRESSWATCHER_ENTRY_DESTRUCTOR ); + + Cancel(); + OstTraceFunctionExit0( CNCMIAPPROGRESSWATCHER_CNCMIAPPROGRESSWATCHER_ENTRY_DESTRUCTOR_EXIT ); + } + +/** + * Start observing the connection stage changes. + */ +void CNcmIapProgressWatcher::Start() + { + OstTraceFunctionEntry0( CNCMIAPPROGRESSWATCHER_START_ENTRY ); + + if (!IsActive()) + { + iConnection.ProgressNotification(iProgressInfoBuf, iStatus); + SetActive(); + } + OstTraceFunctionExit0( CNCMIAPPROGRESSWATCHER_START_EXIT ); + } + +/** + * Implements cancellation of an outstanding request. Cancels the connection progress notification request. + */ +void CNcmIapProgressWatcher::DoCancel() + { + OstTraceFunctionEntry0( CNCMIAPPROGRESSWATCHER_DOCANCEL_ENTRY ); + + iConnection.CancelProgressNotification(); + OstTraceFunctionExit0( CNCMIAPPROGRESSWATCHER_DOCANCEL_EXIT ); + } + +/** + * Called when connection stage changed. + */ +void CNcmIapProgressWatcher::RunL() + { + OstTraceFunctionEntry0( CNCMIAPPROGRESSWATCHER_RUNL_ENTRY ); + + OstTrace1( TRACE_NORMAL, CNCMIAPPROGRESSWATCHER_RUNL_COMPLETION_CODE, ";iStatus.Int()=%d", iStatus.Int() ); + OstTraceExt2( TRACE_NORMAL, CNCMIAPPROGRESSWATCHER_RUNL_INFO, ";iProgressInfoBuf().iStage=%d;iProgressInfoBuf().iError=%d", iProgressInfoBuf().iStage, iProgressInfoBuf().iError ); + + + TInt completionCode = iStatus.Int(); + if (KErrNone == completionCode) + { + switch (iProgressInfoBuf().iStage) + { + case KConnectionUninitialised: + { + iObserver.MipsoHandleClassFatalError(KErrDisconnected); + break; + } + case ENcmPktDrvFatalError: + { + iObserver.MipsoHandleClassFatalError(iProgressInfoBuf().iError); + break; + } + default: + { + // Request the next notification + OstTrace0( TRACE_NORMAL, CNCMIAPPROGRESSWATCHER_RUNL_RESTART_WATCHER, "Request the next notification" ); + Start(); + } + } + } + OstTraceFunctionExit0( CNCMIAPPROGRESSWATCHER_RUNL_EXIT ); + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/ncmiapreader.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classcontroller/src/ncmiapreader.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,210 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** + * @file + * @internalComponent + */ + +#include +#include + +#ifdef OVERDUMMY_NCMCC +#include +#else +#include +#endif + +#include + +#include "ncmiapreaderobserver.h" +#include "ncmiapreader.h" + +// For OST Tracing +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "ncmiapreaderTraces.h" +#endif + + +_LIT(KNcmIapReaderPanic, "UsbNcmIapReader"); // must be <=16 chars + +// Panic codes +enum TNcmIapReaderPanicCode + { + ENcmIapReaderPanicOutstandingRequest = 1, + ENcmIapReaderPanicTooManyIAPs = 2, + ENcmIapReaderEndMark + }; + +// NCM configuration item names +_LIT(KBearerNifName, "ethint"); +_LIT(KBearerLddFileName, "eusbcsc"); +_LIT(KBearerPktDrvName, "ncmpkt.drv"); + +/** + * Constructs a CNcmIapReader object. + * @param aObserver An MNcmIAPReaderObserver instance which handles IAP reading completing + * @param aConnPref The reference of the NCM connection aConnPref + */ +CNcmIapReader::CNcmIapReader(MNcmIAPReaderObserver& aObserver, TCommDbConnPref& aConnPref) +: CActive(CActive::EPriorityStandard), + iObserver(aObserver), + iConnPref(aConnPref) + { + OstTraceFunctionEntryExt( CNCMIAPREADER_CNCMIAPREADER_ENTRY, this ); + CActiveScheduler::Add(this); + OstTraceFunctionExit1( CNCMIAPREADER_CNCMIAPREADER_EXIT, this ); + } + +/** + * Destructor. + */ +CNcmIapReader::~CNcmIapReader() + { + OstTraceFunctionEntry0( CNCMIAPREADER_CNCMIAPREADER_ENTRY_DESTRUCTOR ); + + Cancel(); + OstTraceFunctionExit0( CNCMIAPREADER_CNCMIAPREADER_ENTRY_DESTRUCTOR_EXIT ); + } + +/** + * Start the connection. + */ +void CNcmIapReader::Start() + { + OstTraceFunctionEntry0( CNCMIAPREADER_START_ENTRY ); + + __ASSERT_ALWAYS(!IsActive(), + User::Panic(KNcmIapReaderPanic, ENcmIapReaderPanicOutstandingRequest)); + + SetActive(); + TRequestStatus* status = &iStatus; + User::RequestComplete(status, KErrNone); + + OstTraceFunctionExit0( CNCMIAPREADER_START_EXIT ); + } + +/** + * Implements cancellation of an outstanding request. + */ +void CNcmIapReader::DoCancel() + { + OstTraceFunctionEntry0( CNCMIAPREADER_DOCANCEL_ENTRY ); + + TRequestStatus* status = &iStatus; + User::RequestComplete(status, KErrCancel); + OstTraceFunctionExit0( CNCMIAPREADER_DOCANCEL_EXIT ); + } + +/** + * Simulate an async way and give + * the scheduler a chance to schedule all AOs. + */ +void CNcmIapReader::RunL() + { + OstTraceFunctionEntry0( CNCMIAPREADER_RUNL_ENTRY ); + + // Reading + TRAPD(err, SearchNcmIapL()) + OstTrace1( TRACE_NORMAL, CNCMIAPREADER_RUNL_GETIAP, "Get NCM IAP with error code %d", err ); + + + // Complete connection manager + iObserver.MicoHandleIAPReadingComplete(err); + OstTraceFunctionExit0( CNCMIAPREADER_RUNL_EXIT ); + } + +/** + * Search NCM IAP in current commDB and set it into the ncm connection manager. + */ +void CNcmIapReader::SearchNcmIapL() + { + OstTraceFunctionEntry0( CNCMIAPREADER_GETNCMIAPIDL_ENTRY ); + + using namespace CommsDat; + CMDBSession* dbs = CMDBSession::NewLC(KCDLatestVersion); // Current version is 1.1 + + CMDBRecordSet* lanBearerTable = + new (ELeave) CMDBRecordSet(KCDTIdLANBearerRecord); + CleanupStack::PushL(lanBearerTable); + // Load the table into memory + lanBearerTable->LoadL(*dbs); + + TInt numLanBearers = lanBearerTable->iRecords.Count(); + OstTrace1( TRACE_NORMAL, CNCMIAPREADER_GETNCMIAPIDL_COUNT_LAN_BEARER, "Found %d Lan Bearer!", numLanBearers ); + TInt chosenLanBearer = KErrNotFound; + TInt i = 0; + for(i = 0; i(lanBearerTable->iRecords[i]); + if ((lanBearer->iLanBearerNifName.GetL().Compare(KBearerNifName()) == 0) && + (lanBearer->iLanBearerLddFilename.GetL().Compare(KBearerLddFileName()) == 0) && + (lanBearer->iLanBearerPacketDriverName.GetL().Compare(KBearerPktDrvName()) == 0)) + { + // Matched all check points. We found LAN bearer for NCM + chosenLanBearer = lanBearer->RecordId(); + break; + } + } + CleanupStack::PopAndDestroy(lanBearerTable); // lanBearerTable + if (KErrNotFound == chosenLanBearer) + { + OstTrace0( TRACE_ERROR, CNCMIAPREADER_GETNCMIAPIDL, "Can not find NCM Lan Bearer!" ); + User::Leave(KErrNotFound); + } + OstTrace1( TRACE_NORMAL, CNCMIAPREADER_GETNCMIAPIDL_CHOSEN_LAN_BEARER, "Chosen Lan Bearer %d!", chosenLanBearer ); + + CMDBRecordSet * iapTable = + new (ELeave) CMDBRecordSet(KCDTIdIAPRecord); + CleanupStack::PushL(iapTable); + // Load the table into memory + iapTable->LoadL(*dbs); + + TInt numIaps = iapTable->iRecords.Count(); + TInt chosenIAP = KErrNotFound; + TInt iapLanBearer = KErrNotFound; + for (i = 0; i < numIaps; i++) + { + CCDIAPRecord* iap = + static_cast (iapTable->iRecords[i]); + OstTrace1( TRACE_NORMAL, CNCMIAPREADER_GETNCMIAPIDL_RECORD_ID, "Id of current IAP is %d!", iap->RecordId() ); + OstTrace1( TRACE_NORMAL, CNCMIAPREADER_GETNCMIAPIDL_RECORD_BEARER_ID, "Lan Bearer Id of current IAP is %d!", TMDBElementId(iap->iBearer) ); + iapLanBearer = TMDBElementId(iap->iBearer); + if ((iap->iBearerType.GetL().Compare(TPtrC(KCDTypeNameLANBearer)) == 0) && + (iapLanBearer == chosenLanBearer)) + { + // NCM IAP found! + // Panic if there is more than NCM IAP found + OstTrace1( TRACE_NORMAL, CNCMIAPREADER_SEARCHNCMIAPL_ONLY_ONE_NCM_IAP, "NCM IAP found: Current chosenIAP value is %d", chosenIAP ); + + __ASSERT_ALWAYS(KErrNotFound == chosenIAP, User::Panic(KNcmIapReaderPanic, ENcmIapReaderPanicTooManyIAPs)); + chosenIAP = iap->RecordId(); + break; + } + } + CleanupStack::PopAndDestroy(2, dbs); // iapTable, dbs + if(chosenIAP == KErrNotFound) + { + OstTrace0( TRACE_ERROR, CNCMIAPREADER_GETNCMIAPIDL_NOT_FOUND, "Can not find NCM IAP!" ); + User::Leave(KErrNotFound); + } + OstTrace1( TRACE_NORMAL, CNCMIAPREADER_GETNCMIAPIDL_CHOSEN_IAP_ID, "Chosen IAP is %d!", chosenIAP ); + iConnPref.SetIapId(chosenIAP); + OstTraceFunctionExit0( CNCMIAPREADER_GETNCMIAPIDL_EXIT ); + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/group/bld.inf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/group/bld.inf Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +PRJ_PLATFORMS +ARMV5 + +#include "../ncmpktdrv/group/bld.inf" + +PRJ_MMPFILES + + +PRJ_TESTMMPFILES + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/client/bwins/ncminternalsrvu.def --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/client/bwins/ncminternalsrvu.def Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,12 @@ +EXPORTS + ?SetDhcpResult@RNcmInternalSrv@@QAEHH@Z @ 1 NONAME ; int RNcmInternalSrv::SetDhcpResult(int) + ?Version@RNcmInternalSrv@@QBE?AVTVersion@@XZ @ 2 NONAME ; class TVersion RNcmInternalSrv::Version(void) const + ?TransferHandle@RNcmInternalSrv@@QAEHAAVRHandleBase@@000@Z @ 3 NONAME ; int RNcmInternalSrv::TransferHandle(class RHandleBase &, class RHandleBase &, class RHandleBase &, class RHandleBase &) + ??0RNcmInternalSrv@@QAE@XZ @ 4 NONAME ; RNcmInternalSrv::RNcmInternalSrv(void) + ?DhcpProvisionNotify@RNcmInternalSrv@@QAEXAAVTRequestStatus@@@Z @ 5 NONAME ; void RNcmInternalSrv::DhcpProvisionNotify(class TRequestStatus &) + ?DhcpProvisionNotifyCancel@RNcmInternalSrv@@QAEXXZ @ 6 NONAME ; void RNcmInternalSrv::DhcpProvisionNotifyCancel(void) + ?Connect@RNcmInternalSrv@@QAEHXZ @ 7 NONAME ; int RNcmInternalSrv::Connect(void) + ?SetIapId@RNcmInternalSrv@@QAEHI@Z @ 8 NONAME ; int RNcmInternalSrv::SetIapId(unsigned int) + ??1RNcmInternalSrv@@QAE@XZ @ 9 NONAME ; RNcmInternalSrv::~RNcmInternalSrv(void) + ?TransferBufferSize@RNcmInternalSrv@@QAEHI@Z @ 10 NONAME ; int RNcmInternalSrv::TransferBufferSize(unsigned int) + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/client/eabi/ncminternalsrvu.def --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/client/eabi/ncminternalsrvu.def Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,14 @@ +EXPORTS + _ZN15RNcmInternalSrv13SetDhcpResultEi @ 1 NONAME + _ZN15RNcmInternalSrv14TransferHandleER11RHandleBaseS1_S1_S1_ @ 2 NONAME + _ZN15RNcmInternalSrv19DhcpProvisionNotifyER14TRequestStatus @ 3 NONAME + _ZN15RNcmInternalSrv25DhcpProvisionNotifyCancelEv @ 4 NONAME + _ZN15RNcmInternalSrv7ConnectEv @ 5 NONAME + _ZN15RNcmInternalSrv8SetIapIdEj @ 6 NONAME + _ZN15RNcmInternalSrvC1Ev @ 7 NONAME + _ZN15RNcmInternalSrvC2Ev @ 8 NONAME + _ZN15RNcmInternalSrvD1Ev @ 9 NONAME + _ZN15RNcmInternalSrvD2Ev @ 10 NONAME + _ZNK15RNcmInternalSrv7VersionEv @ 11 NONAME + _ZN15RNcmInternalSrv18TransferBufferSizeEj @ 12 NONAME + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/client/group/bld.inf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/client/group/bld.inf Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,26 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +PRJ_PLATFORMS +ARMV5 + +PRJ_EXPORTS + +PRJ_MMPFILES +ncminternalsrv.mmp + +PRJ_TESTMMPFILES diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/client/group/ncminternalsrv.mmp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/client/group/ncminternalsrv.mmp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + +TARGET ncminternalsrv.dll +TARGETTYPE DLL + +UID 0x1000008d 0x2002E6A5 +VENDORID 0x70000001 + + +//Being run in usbsvr.exe(usbman) +CAPABILITY CommDD PowerMgmt TrustedUI ProtServ NetworkControl NetworkServices LocalServices ReadUserData WriteUserData ReadDeviceData WriteDeviceData + +OS_LAYER_SYSTEMINCLUDE_SYMBIAN + +USERINCLUDE ../../../../inc +USERINCLUDE ../../server/inc + + +SOURCEPATH ../src +SOURCE ncminternalsrv.cpp + +LIBRARY euser.lib diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/group/bld.inf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/group/bld.inf Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +PRJ_PLATFORMS +ARMV5 + +#include "../pktdrv/group/bld.inf" +#include "../client/group/bld.inf" + +PRJ_MMPFILES + + +PRJ_TESTMMPFILES + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/eabi/ncmpktu.def --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/eabi/ncmpktu.def Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,3 @@ +EXPORTS + NewNcmPktDrvFactoryL @ 1 NONAME + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/group/bld.inf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/group/bld.inf Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,27 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +PRJ_PLATFORMS +ARMV5 + +PRJ_EXPORTS + +PRJ_MMPFILES +pktdrv.mmp + + + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/group/pktdrv.mmp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/group/pktdrv.mmp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +TARGET ncmpkt.drv +TARGETTYPE DLL + +UID 0x1000053f 0x2002C306 +VENDORID 0x70000001 + + +// Being run in C32EXE +CAPABILITY CommDD PowerMgmt TrustedUI ProtServ NetworkControl NetworkServices LocalServices ReadUserData WriteUserData ReadDeviceData WriteDeviceData + + +OS_LAYER_SYSTEMINCLUDE_SYMBIAN + + +USERINCLUDE ../inc +USERINCLUDE ../../server/inc +USERINCLUDE ../../../../inc/ +USERINCLUDE ../traces + + +SOURCEPATH ../src +SOURCE ncmpktdrvfactory.cpp +SOURCE ncmpktdrv.cpp +SOURCE ncmengine.cpp +SOURCE ncmcommunicationinterface.cpp +SOURCE ncmcomminterfacesenderandreceiver.cpp +SOURCE ncmnotificationdescriptor.cpp +SOURCE ncmdatainterface.cpp +SOURCE ncmdatareceiver.cpp +SOURCE ncmdatasender.cpp +SOURCE ncmntbparser.cpp +SOURCE ncmntbbuilder.cpp +SOURCE ncmntb16builder.cpp +SOURCE ncmbuffermanager.cpp +SOURCE ncmntbbuildpolicy.cpp +SOURCE ncmntbbuildsimplepolicy.cpp +SOURCE ncmsharedstatemanager.cpp +SOURCE ncmcoexistbearerwatcher.cpp + +#include "../../server/group/server.mmh" + +LIBRARY euser.lib mbufmgr.lib esock.lib ethint.lib usbcsc_bil.lib +LIBRARY efsrv.lib random.lib +LIBRARY nodemessages.lib +LIBRARY netmeta.lib diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/group/pktdrv_overdummyusbldd.mmp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/group/pktdrv_overdummyusbldd.mmp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,62 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + +TARGET ncmpkt.drv +TARGETTYPE DLL + +UID 0x1000053f 0x2002C306 +VENDORID 0x70000001 +#include + +// Being run in C32EXE +CAPABILITY CommDD PowerMgmt TrustedUI ProtServ NetworkControl NetworkServices LocalServices ReadUserData WriteUserData ReadDeviceData WriteDeviceData + +OS_LAYER_SYSTEMINCLUDE_SYMBIAN + +USERINCLUDE ../inc +USERINCLUDE ../../server/inc +USERINCLUDE ../../../../inc/ +USERINCLUDE ../traces + +MACRO __OVER_DUMMYUSBSCLDD__ + +SOURCEPATH ../src +SOURCE ncmpktdrvfactory.cpp +SOURCE ncmpktdrv.cpp +SOURCE ncmengine.cpp +SOURCE ncmcommunicationinterface.cpp +SOURCE ncmcomminterfacesenderandreceiver.cpp +SOURCE ncmnotificationdescriptor.cpp +SOURCE ncmdatainterface.cpp +SOURCE ncmdatareceiver.cpp +SOURCE ncmdatasender.cpp +SOURCE ncmntbparser.cpp +SOURCE ncmntbbuilder.cpp +SOURCE ncmntb16builder.cpp +SOURCE ncmbuffermanager.cpp +SOURCE ncmntbbuildpolicy.cpp +SOURCE ncmntbbuildsimplepolicy.cpp +SOURCE ncmsharedstatemanager.cpp +SOURCE ncmcoexistbearerwatcher.cpp + +#include "../../server/group/server.mmh" + +LIBRARY euser.lib esock.lib +LIBRARY efsrv.lib random.lib +LIBRARY dummyusbsclddapi.lib diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmbuffermanager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmbuffermanager.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,104 @@ +// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// +// + + +/** +@file +@internalComponent +*/ + + +#ifndef NCMBUFFERMANAGER_H +#define NCMBUFFERMANAGER_H + +#include +#include "ncmpktdrvcommon.h" + + + +/** +Responsible for share chunk buffer managerment +*/ + +NONSHARABLE_CLASS(CNcmBufferManager) : public CBase + + { +public: + static CNcmBufferManager* NewL(); + ~CNcmBufferManager(); + /** + * get a free buffer block + * + * @param aBuffer to store the buffer block + * @return KErrNone if success + * KErrCongestion if there is not enough buffer block, should start flow control + */ + TInt GetBuffer(TNcmBuffer& aBuffer); + /** + * free a buffer block + * + * @param aBuffer store the buffer block to free + */ + void FreeBuffer(const TNcmBuffer& aBuffer); + void InitBufferArea(TAny* aBuf, TInt aLength); + /** + * get a free buffer block + * + * @param aSize new ntb size + * @return KErrNone if success + * KErrUnknown if too big ntb size, can't create enought buffer block + */ + TInt SetBufferCellSize(TInt aSize); + TBool IsCongestion(); + TInt RequiredBufferCount(); + inline void SetAlignSize(TInt aSize); + inline TInt FreeBufferCount(); + +private: + CNcmBufferManager(); + +private: + /** + * array of free buffer blocks + */ + RArray iFreeQueue; + /** + * share chunk LDD buffer area + */ + TUint8* iBuf; + TInt iLen; + TInt iCellSize; + TInt iAlignSize; + /** + * there is enough buffer blocks or not + */ + TBool iIsCongestion; + + }; + +inline void CNcmBufferManager::SetAlignSize(TInt aSize) + { + iAlignSize = aSize; + } + +inline TInt CNcmBufferManager::FreeBufferCount() + { + return iFreeQueue.Count(); + } + + +#endif //NCMBUFFERMANAGER_H + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmcoexistbearerwatcher.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmcoexistbearerwatcher.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,80 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** +@file +@internalComponent +*/ + +#ifndef NCMCOEXISTBEARERWATCHER_H +#define NCMCOEXISTBEARERWATCHER_H + +#include +#include + +#include "ncmpktdrvcommon.h" + + +/** +The IPBearerCoexistence P&S key watcher. +*/ +NONSHARABLE_CLASS(CNcmCoexistBearerWatcher) : public CActive + { +public: + static CNcmCoexistBearerWatcher* NewL(); + ~CNcmCoexistBearerWatcher(); + + /** + Set the IP Over USB active if none is actived, or wait + @param[in] aStatus, asychronous request status. + @return KErrCompletion, successfully active IP Over USB. + KErrNone, asychronous call, the result will be returned by aStatus later. + other, system-wide error code. + */ + TInt SetIpOverUsbActive(TRequestStatus& aStatus); + /** Deactive IP Over USB */ + TInt SetIpOverUsbDeactive(); + /** Check whether IP Over USB Bearer is actived or not. */ + inline TBool IsIpOverUsbActived() const; + +private: + //From CActive + void RunL(); + void DoCancel(); + + CNcmCoexistBearerWatcher(); + void ConstructL(); + TInt DoActive(); + +private: + enum TIPBearerCoexistenceStatus + { + EIPBearerNoneActive = 0, + EIPBearerIPOverUSB = 1, + EIPBearerBTPan = 2 + }; + +private: + RProperty iProperty; + TRequestStatus* iReportStatus; + TIPBearerCoexistenceStatus iBearerState; + }; + +// Inline functions +#include "ncmcoexistbearerwatcher.inl" + +#endif /* NCMCOEXISTBEARERWATCHER_H */ diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmcoexistbearerwatcher.inl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmcoexistbearerwatcher.inl Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** +@file +@internalComponent +*/ + +#ifndef NCMCOEXISTBEARERWATCHER_INL +#define NCMCOEXISTBEARERWATCHER_INL + +inline TBool CNcmCoexistBearerWatcher::IsIpOverUsbActived() const + { + return EIPBearerIPOverUSB==iBearerState; + } + +#endif //NCMCOEXISTBEARERWATCHER_INL diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmcomminterfacesenderandreceiver.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmcomminterfacesenderandreceiver.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,112 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* header file of class for read and write data from share chunk LDD +* +*/ + + +/** +@file +@internalComponent +*/ + +#ifndef NCMCOMMINTERFACESENDERANDRECEIVER_H +#define NCMCOMMINTERFACESENDERANDRECEIVER_H + +#include + +#ifndef __OVER_DUMMYUSBSCLDD__ +#include +#else +#include +#endif + + + +class CNcmCommunicationInterface; + +/** +Responsible for sending and receiving data on Control Endpoint +*/ + +NONSHARABLE_CLASS(CNcmCommInterfaceSenderAndReceiver) : public CActive + { +public: + static CNcmCommInterfaceSenderAndReceiver* NewL(RDevUsbcScClient& aPort, CNcmCommunicationInterface& aCommInterface); + ~CNcmCommInterfaceSenderAndReceiver(); + void Start(); + void Stop(); + /** + * read aLength data from LDD + * + * @param aStatus complete status for this request. + * @param aBuf buffer to store data. + * @param aLength length to read. + */ + TInt Read(TRequestStatus& aStatus, TDes8& aBuf, TInt aLength); + /** + * write aLength data to LDD + * + * @param aStatus complete status for this request. + * @param aBuf buffer of data. + * @param aLength length to write. + */ + TInt Write(TRequestStatus& aStatus, TDesC8& aBuf, TInt aLength); + +private: + enum TNcmControlEndpointState + { + EUnInit = 1, + EIdle, + EReceiving, + ESending + }; + + CNcmCommInterfaceSenderAndReceiver(RDevUsbcScClient& aPort, CNcmCommunicationInterface& aCommInterface); + void ReadData(); + +private: + /** + * derived from CActive + */ + void RunL(); + void DoCancel(); + +private: + RDevUsbcScClient& iPort; + /** + * LDD control endpoint buffer + */ + TEndpointBuffer iEp0Buffer; + CNcmCommunicationInterface& iCommInterface; + /** + * point to buffer to store data of Read function, this is not ownership + */ + TDes8* iReceiveBuf; + /** + * length of data left to be read from LDD for a Read request + */ + TInt iToReceiveLength; + /** + * complete status for Read and Write function, this is not ownership + */ + TRequestStatus* iCompleteStatus; + TNcmControlEndpointState iState; + + }; + + +#endif //NCMCOMMINTERFACESENDERANDRECEIVER_H + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmcommunicationinterface.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmcommunicationinterface.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,153 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* header file for NCM communication interface class +* +*/ + +/** +@file +@internalComponent +*/ + +#ifndef NCMCOMMUNICATIONINTERFACE_H +#define NCMCOMMUNICATIONINTERFACE_H + +#include + +#ifndef __OVER_DUMMYUSBSCLDD__ +#include +#else //!__OVER_DUMMYUSBSCLDD__ +#include +#endif// __OVER_DUMMYUSBSCLDD__ + +#include "ncmcomminterfacesenderandreceiver.h" +#include "ncmpktdrvcommon.h" + +const TUint KSetupPacketLength = 8; +const TUint KNtbParamStructLength = 28; +const TUint KNtbInputSizeStructLength = 4; + +_LIT(KNcmCommInterface, "NcmCommunicationInterface"); + +enum TNcmCommErrorCode + { + EInternalError, + EInvalidSetupPacketLength, + EInvalidOutSetupPacket, + EInvalidInSetupPacket, + EInvalidLengthToRead, + EInvalidDataPacketLength, + EInvalidFilterOffset + }; + +/** +* The interface to Ncm engine +*/ + +NONSHARABLE_CLASS(MNcmControlObserver) +{ +public: + virtual TInt HandleSetNtbInputSize(TDes8& aBuf) = 0; + virtual TInt HandleGetNtbParam(TDes8& aBuf) = 0; + virtual TInt HandleGetNtbInputSize(TDes8& aBuf) = 0; + virtual void ControlError(TInt aError) = 0; +}; + +/** +* implement NCM control interface +*/ + +NONSHARABLE_CLASS(CNcmCommunicationInterface) : public CActive + { +public: + static CNcmCommunicationInterface* NewL(MNcmControlObserver& aEngine, RDevUsbcScClient& aLdd); + ~CNcmCommunicationInterface(); + TInt Start(); + void Stop(); + void ControlMsgError(TNcmCommErrorCode aCode); + TInt SendConnectionNotification(TBool aConnected); + TInt SendSpeedNotification(TInt aUSBitRate, TInt aDSBitRate); + +public: + inline RDevUsbcScClient& Ldd(); + inline TBool IsStarted(); + +private: + enum TNcmCommRWState + { + EStateInitial = 0, + EStateReadSetup, + EStateReadDataout, + EStateWriteDatain + }; + + enum TUsbRequestType + { + EGetNtbParameters = 0x80, + EGetNtbInputSize = 0x85, + ESetNtbInputSize = 0x86 + }; + +private: + CNcmCommunicationInterface(MNcmControlObserver& aEngine, RDevUsbcScClient& aLdd); + void ConstructL(); + void RunL(); + void DoCancel(); + void ReadSetup(); + void DecodeSetup(); + void ReadDataOut(); + void WriteDataIn(); + void ParseDataOut(); + TInt WriteInterruptData(TInt aEndPoint, TDesC8& aDes, TInt aLength); + TInt GetInterfaceNumber(); + + +private: + + MNcmControlObserver& iEngine; + /** + * USB request type + */ + TUint8 iRequestType; + /** + * data stage data length + */ + TUint16 iDataStageLength; + /** + * usb setup packet + */ + TBuf8 iSetupPacket; + /** + * control transfer data + */ + TBuf8 iDataBuffer; + TNcmCommRWState iRWState; + TBool iStarted; + RDevUsbcScClient& iPort; + /** + * instance to CNcmCommInterfaceSenderAndReceiver + */ + CNcmCommInterfaceSenderAndReceiver* iSenderAndReceiver; + /** + * communication interface number + */ + TUint8 iInterfaceNumber; + + }; + +// Inline functions +#include "ncmcommunicationinterface.inl" + +#endif //NCMCOMMUNICATIONINTERFACE_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmcommunicationinterface.inl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmcommunicationinterface.inl Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* NCM communication interface class inl file +* +*/ + +/** +@file +@internalComponent +*/ + +#ifndef NCMCOMMUNICATIONINTERFACE_INL +#define NCMCOMMUNICATIONINTERFACE_INL + +inline RDevUsbcScClient& CNcmCommunicationInterface::Ldd() + { + return iPort; + } + +inline TBool CNcmCommunicationInterface::IsStarted() + { + return iStarted; + } + + +#endif //NCMCOMMUNICATIONINTERFACE_INL \ No newline at end of file diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmdatainterface.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmdatainterface.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,115 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** +@file +@internalComponent +*/ + +#ifndef NCMDATAINTERFACE_H +#define NCMDATAINTERFACE_H + +#include +#ifndef __OVER_DUMMYUSBSCLDD__ +#include +#include +#include +#else +#include +#include +#endif + +#include "ncmpktdrvcommon.h" + +class CNcmDataSender; +class CNcmDataReceiver; + +/** +The interface to NCM data channel. +*/ +NONSHARABLE_CLASS(MNcmDataObserver) +{ +public: + /** + Process received datagram parsed from NCM. + @param[in] aPacket, contains the datagram(ethernet frame) to be dealed with. + */ + virtual void ProcessReceivedDatagram(RMBufPacket& aPacket) = 0; + /** + Notify the upper layer(TCP/IP stack) to continue to send data. + */ + virtual void ResumeSending() = 0; + /** + Notify unrecoverable error in data channel. + */ + virtual void DataError(TInt aError) = 0; + /** + Notify the Data Interface's alt-setting changes, which commonly from 0 to 1, or vice versa. + @param[in] aIfAltSet, the alt-setting number. + */ + virtual void HandleAltSetting(TInt aIfAltSet) = 0; +}; + +/** +Maintain the logic of Ncm data channel +*/ +NONSHARABLE_CLASS(CNcmDataInterface) : public CActive + { +public: + static CNcmDataInterface* NewL(MNcmDataObserver& aEngine, RDevUsbcScClient& aLdd); + ~CNcmDataInterface(); + + inline TBool IsStarted() const; + void Start(); + void Stop(); + TInt Send(RMBufChain& aPacket); + + TInt GetSpeed(TInt& aSpeed); + TInt GetNtbInputSize(TDes8& aSize); + TInt SetNtbInputSize(TDesC8& aSize); + TInt GetNtbParam(TDes8& aParam); + TInt SetInEpBufferSize(TUint aSize); + + void ActivateLdd(); + inline void DataError(TInt aErroCode) const; + inline void ResumeSending() const; + inline void ProcessDatagram(RMBufPacket& aPacket) const; + inline TInt AltSetting() const; + +private: + CNcmDataInterface(MNcmDataObserver& aEngine, RDevUsbcScClient& aLdd); + void ConstructL(); + + //From CActive + void RunL(); + void DoCancel(); + +private: + TBool iStarted; + CNcmDataSender* iSender; + CNcmDataReceiver* iReceiver; + MNcmDataObserver& iEngine; + + RDevUsbcScClient& iLdd; + TInt iAltSetting; + TUint iIfState; + }; + +// inline functions +#include "ncmdatainterface.inl" + +#endif // NCMDATAINTERFACE_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmdatainterface.inl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmdatainterface.inl Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,67 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** +@file +@internalComponent +*/ + +#ifndef NCMDATAINTERFACE_INL +#define NCMDATAINTERFACE_INL + +/** + * Indicate whether DataInterface is started or not, called by Engine. + */ +inline TBool CNcmDataInterface::IsStarted() const + { + return iStarted; + } + +/** + * Return current alternate setting. + */ +inline TInt CNcmDataInterface::AltSetting() const + { + return iAltSetting; + } + +/** + * Notify the Engine that unrecoverable data error, like no memory, etc. + */ +inline void CNcmDataInterface::DataError(TInt aError) const + { + iEngine.DataError(aError); + } + +/** + * Resume sending, used when KStopSending returned by last send. + */ +inline void CNcmDataInterface::ResumeSending() const + { + iEngine.ResumeSending(); + } + +/** + * Process(upwards simply) received NCM Datagram (ethernet frame). + */ +void CNcmDataInterface::ProcessDatagram(RMBufPacket& aPacket) const + { + iEngine.ProcessReceivedDatagram(aPacket); + } + + +#endif //NCMDATAINTERFACE_INL diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmdatareceiver.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmdatareceiver.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,80 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** +@file +@internalComponent +*/ +#ifndef NCMDATARECEIVER_H +#define NCMDATARECEIVER_H + +#include + +#ifndef __OVER_DUMMYUSBSCLDD__ +#include +#else +#include +#endif + +#include "ncmpktdrvcommon.h" +#include "ncmntbparser.h" + + +class CNcmDataInterface; + +/** +Responsible for receiving NCM packet data +*/ +NONSHARABLE_CLASS(CNcmDataReceiver) : public CActive, public MNcmNdpFrameObserver + { +public: + static CNcmDataReceiver* NewL(RDevUsbcScClient& aPort, CNcmDataInterface& aParent); + ~CNcmDataReceiver(); + + void Start(); + void Stop(); + + //from MNcmNdpFrameObserver + void ProcessEtherFrame(RMBufPacket&); + void ExpireBuffer(TAny*); + + inline TUint NtbOutMaxSize() const; +private: + void ConstructL(); + CNcmDataReceiver(RDevUsbcScClient& aPort, CNcmDataInterface& aParent); + + //From CActive + void RunL(); + void DoCancel(); + + void ReadData(); + +private: + RDevUsbcScClient& iPort; + TEndpointBuffer iEpIn; + TUint8* iBuf; + TUint iBufLen; + TBool iZlp; + CNcmNtbParser* iNtbParser; + CNcmDataInterface& iParent; + }; + +// inline functions +#include "ncmdatareceiver.inl" + +#endif //NCMDATARECEIVER_H + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmdatareceiver.inl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmdatareceiver.inl Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** +@file +@internalComponent +*/ +#ifndef NCMDATARECEIVER_INL +#define NCMDATARECEIVER_INL + +inline TUint CNcmDataReceiver::NtbOutMaxSize() const + { + return iNtbParser ? iNtbParser->NtbOutMaxSize() : 0xFFFF; + } + +#endif //NCMDATARECEIVER_INL diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmdatasender.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmdatasender.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,143 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** +@file +@internalComponent +*/ + + +#ifndef NCMDATASENDER_H +#define NCMDATASENDER_H + +#include + +#ifndef __OVER_DUMMYUSBSCLDD__ +#include +#else +#include +#include +#endif + +#include "ncmntbbuilder.h" +#include "ncmpktdrvcommon.h" + + +class CNcmDataInterface; +class RDevUsbcScClient; +class CNcmBufferManager; +class CNcmNtbBuildPolicy; + + +NONSHARABLE_CLASS(MNcmNtbBuildObserver) + { +public: + /** + * send a NTB out, this is interface with CNtbBuilder + * + * @param aBuffer contain a whole NTB. + */ + virtual void SendNtbPayload(TNcmBuffer& aBuffer) = 0; + }; + + + +/** +Responsible for sending Ncm packet data +*/ + +NONSHARABLE_CLASS(CNcmDataSender) : public CActive, + public MNcmNtbBuildObserver + + { +public: + static CNcmDataSender* NewL(RDevUsbcScClient& aPort, CNcmDataInterface& aParent); + ~CNcmDataSender(); + +public: + /** derived from MNcmNtbBuildObserver */ + void SendNtbPayload(TNcmBuffer& aBuffer); + +public: + /** + * change NtbInMax size + * + * @param aSize, new NtbInMax size + * @param aIsAltZero, is alternate setting 0 + * @return KErrNone if success, + * KErrArgument if the aSize is bigger than 65535, + * KErrUnknown if aSize is too bigger and can't create enough buffer block + */ + TInt SetNtbInMaxSize(TInt aSize, TBool aIsAltZero=ETrue); + void RunL(); + void Start(); + /** + * send a ethernet frame + * + * @param aPacket, the ethernet frame + * @return KErrNone if success, + * KErrNotReady if sender is not started. + * KErrCongestion if there is less buffers, need to start flow control. + */ + TInt Send(RMBufChain& aPacket); + void GetNtbParam(TNcmNtbInParam& aParam); + void Stop(); + TInt SetInEpBufferSize(TUint aSize); + inline TInt NtbInMaxSize(); + +private: + CNcmDataSender(RDevUsbcScClient& aPort, CNcmDataInterface& aParent); + void ConstructL(); + void SendNtbComplete(); + TInt StartNewNtb(); + void DoCancel(); + +private: + RDevUsbcScClient& iPort; + CNcmDataInterface& iParent; + /** + * LDD Endpoint buffer for in NCM in endpoint + */ + TEndpointBuffer iEpOut; + /** + * store the buffers to be sent to LDD + */ + RArray iTxArray; + /** + * store the buffer is on sending + */ + TNcmBuffer iSendingBuffer; + /** + * there is a buffer currenly on sending + */ + TBool iIsSending; + TBool iStarted; + CNcmNtbBuilder* iNtbBuilder; + CNcmBufferManager* iBufferManager; + CNcmNtbBuildPolicy* iBuildPolicy; + /** + * networking may send packet when data sender is not started, use this to determin if do send resuming when start + */ + TBool iStopSending; + + }; + +// Inline functions +#include "ncmdatasender.inl" + +#endif //NCMDATASENDER_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmdatasender.inl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmdatasender.inl Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,38 @@ +// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +// All rights reserved. +// This component and the accompanying materials are made available +// under the terms of the License "Eclipse Public License v1.0" +// which accompanies this distribution, and is available +// at the URL "http://www.eclipse.org/legal/epl-v10.html". +// +// Initial Contributors: +// Nokia Corporation - initial contribution. +// +// Contributors: +// +// Description: +// +// + + +/** +@file +@internalComponent +*/ + + + +#ifndef NCMDATASENDER_INL +#define NCMDATASENDER_INL + + + +inline TInt CNcmDataSender::NtbInMaxSize() + { + return iNtbBuilder->NtbInMaxSize(); + } + + +#endif + + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmengine.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmengine.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,133 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** +@file +@internalComponent +*/ +#ifndef NCMENGINE_H +#define NCMENGINE_H + + +#ifndef __OVER_DUMMYUSBSCLDD__ +#include +#else +#include +#endif + +#include + +#include "ncmpktdrvcommon.h" +#include "ncmcommunicationinterface.h" +#include "ncmdatainterface.h" +#include "ncmsharedstatemanager.h" + +class CNcmPktDrv; + +/** +NCM Engine: coordinate with Data Interface, Comm Interface and Shared State Manager. +*/ +NONSHARABLE_CLASS(CNcmEngine) : public CActive, + public MNcmDataObserver, + public MNcmControlObserver, + public MShareStateObserver + { +public: + static CNcmEngine* NewL(CNcmPktDrv& aPktDrv); + ~CNcmEngine(); + + //Start the engine, called by TransferHandle after PktDrvBase's StartInterface; + TInt Start(RMessagePtr2& aMsg); + //Stop the engine, called by PktDrvBase's StopInterface; + void Stop(); + + //Send a Packet to USB Host. + TInt Send(RMBufChain &aPacket); + //Get the Interface Mac Address; + TUint8* InterfaceAddress(); + + //From MNcmControlObserver + TInt HandleSetNtbInputSize(TDes8&); + TInt HandleGetNtbParam(TDes8&); + TInt HandleGetNtbInputSize(TDes8&); + void ControlError(TInt aError); + + //From MNcmDataObserver + void ProcessReceivedDatagram(RMBufPacket&); + void ResumeSending(); + void DataError(TInt aError); + void HandleAltSetting(TInt aIfNum); + TInt SetInEpBufferSize(TUint aSize); + + //From MShareStateObserver + void NotifyDhcpStarted(); + + inline TInt SetStateToWatcher(TInt aType, TInt aValue) const; + inline TInt RegisterNotify(const RMessage2& aMsg) const; + inline TInt DeRegisterNotify() const; + +#ifdef __OVER_DUMMYUSBSCLDD__ +public: + TInt State() const {return iEngineState;} +#endif + +private: + //From CActive + void RunL(); + void DoCancel(); + + CNcmEngine(); + CNcmEngine(CNcmPktDrv& aPktDrv); + void ConstructL(); + + void InitLddL(const RMessagePtr2& aMsg); + void RandomMacAddressL(TNcmMacAddress& aMacAddress); + void DoNcmStarted(); + void StartDataLayer(); + void StopDataLayer(); + +private: + enum TNcmEngineState + { + ENcmStateUninitialized = 0, + ENcmStateStarting, + ENcmStateStarted, + ENcmStatePaused, + ENcmStateStopped, + ENcmStateMax + }; + +private: + CNcmPktDrv& iPktDrv; + + CNcmDataInterface* iDataInterface; + CNcmCommunicationInterface* iCommInterface; + CNcmSharedStateManager* iSharedStateManager; + + TNcmEngineState iEngineState; + TUint iDeviceState; + + TNcmMacAddress iSymbianMacAddress; + + RDevUsbcScClient iDataLdd; + RDevUsbcScClient iCommLdd; + }; + +//inline functions +#include "ncmengine.inl" + +#endif // NCMENGINE_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmengine.inl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmengine.inl Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** +@file +@internalComponent +*/ +#ifndef NCMENGINE_INL +#define NCMENGINE_INL + +//Assumption: NcmEngine & NcmServer are existed simultaneously!! +#ifdef _DEBUG +_LIT(KEnginePanic, "CNcmEnginePanic"); +#endif +/** + * Set IapId and Dhcp Provision Result to SharedState manager. + */ +inline TInt CNcmEngine::SetStateToWatcher(TInt aType, TInt aValue) const + { + __ASSERT_DEBUG(iSharedStateManager, User::Panic(KEnginePanic, __LINE__)); + return iSharedStateManager->SetStateValue(aType, aValue); + } + +/** + * Register the callback of Class Controller to do Dhcp Provision. + */ +inline TInt CNcmEngine::RegisterNotify(const RMessage2& aMsg) const + { + __ASSERT_DEBUG(iSharedStateManager, User::Panic(KEnginePanic, __LINE__)); + return iSharedStateManager->RegisterNotify(aMsg); + } + +/* + * Deregister the callback. + */ +inline TInt CNcmEngine::DeRegisterNotify() const + { + __ASSERT_DEBUG(iSharedStateManager, User::Panic(KEnginePanic, __LINE__)); + return iSharedStateManager->DeRegisterNotify(); + } + + +#endif //NCMENGINE_INL diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmnotificationdescriptor.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmnotificationdescriptor.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* header file for NCM notification message class +* +*/ + + + +#ifndef NCMNOTIFICATIONDESCRIPTOR_H +#define NCMNOTIFICATIONDESCRIPTOR_H + +#include + + +const TUint KUSBNotificationNetworkConnection = 8; + +/** + * USB NetworkConnection Notification + */ + +NONSHARABLE_CLASS(TUSBNotificationNetworkConnection) + { +public: + TUint8 iRequestType; ///< Request type + TUint8 iNotification; ///< Notification number + TUint16 iValue; ///< Notification value + TUint16 iIndex; ///< Notification index + TUint16 iLength; ///< Notification length +public: + TDes8& Des(); + +private: + TBuf8 iBuffer; + }; + +const TUint KUSBNotificationConnectionSpeedChange = 16; + +/** + * USB ConnectionSpeedChange Notification + */ + +NONSHARABLE_CLASS(TUSBNotificationConnectionSpeedChange) + { +public: + TUint8 iRequestType; ///< Request type + TUint8 iNotification; ///< Notification number + TUint16 iValue; ///< Notification value + TUint16 iIndex; ///< Notification index + TUint16 iLength; ///< Notification length + TUint32 iUSBitRate; ///< upstream bit rate, in bits per second + TUint32 iDSBitRate; ///< downstream bit rate, in bits per second +public: + TDes8& Des(); + +private: + TBuf8 iBuffer; + }; + +#endif // NCMNOTIFICATIONDESCRIPTOR_H + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmntb16builder.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmntb16builder.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,92 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* header file for NTB16 build class +* +*/ + + +/** +@file +@internalComponent +*/ + + +#ifndef NCMNTB16BUILDER_H +#define NCMNTB16BUILDER_H + +#include +#include "ncmntbbuilder.h" +#include "ncmpktdrvcommon.h" + + +class MNcmNtbBuildObserver; + + +NONSHARABLE_CLASS(TDatagramEntry) + { +public: + TUint16 iWDatagramIndex; + TUint16 iWDatagramLength; + }; + +/** +Responsible for build NTB16 payload +*/ + +NONSHARABLE_CLASS(CNcmNtb16Builder) : public CNcmNtbBuilder + { +public: + static CNcmNtbBuilder* NewL(MNcmNtbBuildObserver&); + ~CNcmNtb16Builder(); + +public: +/** +*derived from CNcmNtbBuilder +*/ + void StartNewNtb(const TNcmBuffer& aBuffer); + TInt AppendPacket(const RMBufChain& aPacket); + TInt SetNtbInMaxSize(TInt aSize); + void CompleteNtbBuild(); + void Reset(); + +private: + CNcmNtb16Builder(MNcmNtbBuildObserver&); + void ConstructL(); + void BuildNtbHeader(); + void BuildNdp(); + + +private: + /** + * offset of NDP in buffer + */ + TUint16 iNdpOffset; + /** + * length of NDP + */ + TUint16 iNdpLength; + /** + * offset of next datagram can be in. + */ + TUint16 iDatagramOffset; + /** + * array of datagrams index and length in NTB. + */ + RArray iPacketsArray; + }; + + +#endif //NCMNTB16BUILDER_H + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmntbbuilder.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmntbbuilder.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,129 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* header file for NTB build base class +* +*/ + + + +/** +@file +@internalComponent +*/ + + +#ifndef NCMNTBBUILDER_H +#define NCMNTBBUILDER_H + +#include + +#include "ncmpktdrvcommon.h" + + +class MNcmNtbBuildObserver; +class RMBufChain; +class CNcmNtbBuildPolicy; +class TNcmNtbInParam; + + +const TInt KErrBufferFull = -6667; + + +/** +Base class for build NTB +*/ + +NONSHARABLE_CLASS(CNcmNtbBuilder) : public CBase + { +public: + /** + * append a ethernet frame to current NTB + * + * @param aPacket ethernet packet buffer + * @return KErrNone if success + * KErrBufferFull if current NTB is full and can't insert the new packet to NTB and send the current NTB immediately + */ + virtual TInt AppendPacket(const RMBufChain& aPacket) = 0; + /** + * complete the current NTB + * + */ + virtual void CompleteNtbBuild(); + /** + * change the NtbInMaxSize + * + * @param aSize new size + * @return KErrNone if success + * KErrArgument if the size is bigger than allowed size in NCM spec. + */ + virtual TInt SetNtbInMaxSize(TInt aSize) = 0; + /** + * prepare build a new NTB + * + * @param aBuffer buffer to construct NTB + */ + virtual void StartNewNtb(const TNcmBuffer& aBuffer); + /** + * reset builder to intial state. + */ + virtual void Reset(); + +public: + ~CNcmNtbBuilder(); + void GetNtbParam(TNcmNtbInParam& aParam); + inline void SetBuildPolicy(CNcmNtbBuildPolicy& aPolicy); + /** + * @return ETrue if has called StartNewNtb for current NTB + * EFalse otherwise + */ + inline TBool IsNtbStarted(); + inline TInt NtbInMaxSize(); + inline TInt MinNtbInMaxSize(); + +protected: + CNcmNtbBuilder(MNcmNtbBuildObserver&); + void SendNtbPayload(); + +protected: + /** + * refer to NCM spec for following five variable meaning. + */ + TInt iNtbInMaxSize; + TInt iNdpInDivisor; + TInt iNdpInPayloadRemainder; + TInt iNdpInAlignment; + TUint16 iSequence; + + MNcmNtbBuildObserver& iObserver; + /** + * buffer contains NTB + */ + TNcmBuffer iBuffer; + /** + * point to builder policy, this is not ownership + */ + CNcmNtbBuildPolicy* iBuildPolicy; + /** + * a NTB is started or not. + */ + TBool iNtbStarted; + }; + + +// Inline functions +#include "ncmntbbuilder.inl" + + +#endif /* NCMNTBBUILDER_H */ diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmntbbuilder.inl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmntbbuilder.inl Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* NTB build base class inl file +* +*/ + + +/** +@file +@internalComponent +*/ + + +#ifndef NCMNTBBUILDER_INL +#define NCMNTBBUILDER_INL + +const TInt KMinNtbInMaxSize = 2048; + +inline TInt CNcmNtbBuilder::NtbInMaxSize() + { + return iNtbInMaxSize; + } + +inline void CNcmNtbBuilder::SetBuildPolicy(CNcmNtbBuildPolicy& aPolicy) + { + iBuildPolicy = &aPolicy; + } + +inline TBool CNcmNtbBuilder::IsNtbStarted() + { + return iNtbStarted; + } + +inline TInt CNcmNtbBuilder::MinNtbInMaxSize() + { + return KMinNtbInMaxSize; + } + + + +#endif diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmntbbuildpolicy.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmntbbuildpolicy.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,71 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Header file NTB build policy base class +* +*/ + + +/** +@file +@internalComponent +*/ + +#ifndef NCMNTBBUILDPOLICY_H +#define NCMNTBBUILDPOLICY_H + + +#include +#include "ncmpktdrvcommon.h" + +class CNcmNtbBuilder; + +/** +base class for ntb build policy +*/ + +NONSHARABLE_CLASS(CNcmNtbBuildPolicy) : public CActive + { +public: + /** + * call by builder when begin a new NTB + */ + virtual void StartNewNtb() = 0; + /** + * call by builder when a ethernet frame is added to NTB + */ + virtual void UpdateNtb(TInt aSize) = 0; + /** + * call by builder when complete a NTB + */ + virtual void CompleteNtbBuild() = 0; + virtual void UpdateBufferSize(TInt aSize) = 0; + virtual void UpdateFreeBufferCount(TInt aCount) = 0; + virtual void UpdateTotalBufferCount(TInt aCount) = 0; + ~CNcmNtbBuildPolicy(); + inline CNcmNtbBuilder& NtbBuilder(); + +protected: + CNcmNtbBuildPolicy(CNcmNtbBuilder&); + CNcmNtbBuilder& iNtbBuilder; +}; + + +inline CNcmNtbBuilder& CNcmNtbBuildPolicy::NtbBuilder() + { + return iNtbBuilder; + } + + +#endif //NCMNTBBUILDPOLICY_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmntbbuildsimplepolicy.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmntbbuildsimplepolicy.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,77 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* Header file for simple NTB build policy +* +*/ + + +/** +@file +@internalComponent +*/ + + +#ifndef NCMNTBBUILDSIMPLEPOLICY_H +#define NCMNTBBUILDSIMPLEPOLICY_H + + +#include +#include "ncmntbbuildpolicy.h" + + +/** +* a simple build policy, fix packets count in a NTB and a timer to restrict maxiam time delay +*/ + +NONSHARABLE_CLASS(CNcmNtbBuildSimplePolicy) : public CNcmNtbBuildPolicy + { +public: + static CNcmNtbBuildPolicy* NewL(CNcmNtbBuilder& aPolicy); + ~CNcmNtbBuildSimplePolicy(); + +public: + /** + derived from CNcmNtbBuildPolicy + */ + virtual void StartNewNtb(); + virtual void UpdateNtb(TInt aSize); + virtual void CompleteNtbBuild(); + + virtual void UpdateBufferSize(TInt aSize); + virtual void UpdateFreeBufferCount(TInt aCount); + virtual void UpdateTotalBufferCount(TInt aCount); + +private: + void RunL(); + void DoCancel(); + void ConstructL(); + CNcmNtbBuildSimplePolicy(CNcmNtbBuilder& aPolicy); + /** + * timer for maxiam packet time delay + */ + RTimer iTimer; + /** + * packets number in current NTB + */ + TInt iPacketsCount; + TInt iTotalBufferCount; + TInt iFreeBufferCount; + TInt iBufferSize; + +}; + + +#endif //NCMNTBBUILDSIMPLEPOLICY_H + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmntbparser.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmntbparser.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,210 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +/** +@file +@internalComponent +*/ +#ifndef NCMNTBPARSER_H +#define NCMNTBPARSER_H + +#include + +//DEBUG MACRO to dump the parsed NDP info. +//#define DEBUG_DUMP_NTBINNER +#ifdef DEBUG_DUMP_NTBINNER +#include +#endif + +#ifndef __OVER_DUMMYUSBSCLDD__ +#include +#else +#include +#endif + +#include "ncmpktdrvcommon.h" + +/** + * interface for parsed NDP(ethernet frame). + */ +NONSHARABLE_CLASS(MNcmNdpFrameObserver) + { +public: + virtual void ProcessEtherFrame(RMBufPacket&) = 0; + virtual void ExpireBuffer(TAny*) = 0; + }; + +#ifdef DEBUG_DUMP_NTBINNER +class NTHNDPDumper : public MNcmNdpFrameObserver + { +public: + inline void ProcessEtherFrame(RMBufPacket& aPacket) + { + RDebug::Printf("NTHNDPDumper::parsed Ethernet Frame, length=%d", aPacket.Length()); + aPacket.Free(); + } + inline void ExpireBuffer(TAny* aBuf) + { + } + inline void FatalError(TInt aErrCode) + { + RDebug::Printf("NTHNDPDumper::Fatal Error=%d", aErrCode); + } + }; +#endif //DEBUG_DUMP_NTBINNER + +/** + * NCM NTH for NTB16 + */ +NONSHARABLE_CLASS(TNcmNth16) + { +public: + TUint8 dwSignature[4]; + TUint16 wHeaderLength; + TUint16 wSequence; + TUint16 wBlockLength; + TUint16 wNdpIndex; + +public: + inline void Dump(); + }; + +/** + * NCM NDP 16 + */ +NONSHARABLE_CLASS(TNcmNdp16) + { +public: + TUint8 dwSignature[4]; + TUint16 wLength; + TUint16 wNextNdpIndex; + TUint16 wDatagram0Index; + TUint16 wDatagram0Length; + TUint16 wDatagram1Index; + TUint16 wDatagram1Length; + +public: + inline void Dump(); + }; + +/** + * NCM packet parser + * NOTE:the buffer to be parsed was not guaranteed as a whole USB transfer. + * So, a internal state is used to remember previous parsed result. + */ +NONSHARABLE_CLASS(CNcmNtbParser) : public CBase + { +public: + virtual TInt Parse(const TUint8* aBuf, TInt aBufLen, TBool aZlp = EFalse) = 0; + virtual void Reset(TInt aResetType=0) = 0; + virtual TUint NtbOutMaxSize() const = 0; + virtual ~CNcmNtbParser(); + +protected: + inline CNcmNtbParser(MNcmNdpFrameObserver&); + + MNcmNdpFrameObserver& iObserver; + }; + +/** + * NCM NTB 16 parser + */ +NONSHARABLE_CLASS(CNcmNtb16Parser): public CNcmNtbParser + { +public: + //From CNcmNtbParser + TInt Parse(const TUint8* aBuf, TInt aBufLen, TBool aZlp = EFalse); + TUint NtbOutMaxSize() const; + void Reset(TInt aType = 0); + + virtual ~CNcmNtb16Parser(); + + static CNcmNtb16Parser* NewL(MNcmNdpFrameObserver&); + +private: + inline CNcmNtb16Parser(MNcmNdpFrameObserver&); + //parse NTH + TInt ParseNcmNtb16Header(const TUint8* aBuf, TInt aBufLen, TBool aZlp); + //parse NDP + TInt ParseNcmNtb16Ndp(const TUint8* aBuf, TInt aBufLen); + //parse NdpDatagram + TInt ParseNcmNtb16NdpDatagram(const TUint8* aBuf, TInt aBufLen); + //queue buffer. + TInt QueueBuf(const TUint8* aBuf, TInt aBufLen); + TUint8 DataTUint8(TUint aOffset, const TUint8* aBuf, TInt aBufLen); + TUint16 DataTUint16(TUint aOffset, const TUint8* aBuf, TInt aBufLen); + TInt DataPacket(const TUint8* aBuf, TInt aBufLen); + //search NCMH in the stream if the NTH header signature is wrong. + TInt SearchNcmHead(const TUint8* aBuf, TInt aBufLen); + + + enum TNcmNtb16ResetType + { + ENcmNtb16TypeResetAll = 0, + ENcmNtb16TypeResetQueue = 1, + ENcmNtb16TypeResetData = 2 + }; + + enum TNcmNtb16ParseState + { + //initial state, NTH is not ready. + ENcmNtb16ParseStateUninitialized = 0, + //NTH is ready, NDP is not ready. + ENcmNtb16ParseStateNdpParsing, + //NDP is ready, NdpDatagram is not finished. + ENcmNtb16ParseStateNdpSeeking, + //Error state or NULL NDP, ignore coming bytes until this NTB end. + ENcmNtb16ParseStateSkipBytes + }; + + enum TNcmNtb16ParseNdpState + { + ENcmNtb16ParseNdpStateUninitialized = 0, + ENcmNtb16ParseNdpStateDatagramed + }; + +private: + TNcmNth16 iNth; + TNcmNdp16 iNdp; + + TNcmNtb16ParseState iState; + + TUint iDataLen; //NTB data length. + TUint iQueLen; //Queue length. + TUint iDataOffset; //start offset in first buffer in queue. + RArray iBufQueue; + + TNcmNtb16ParseNdpState iNdpState; + TUint iNdpDataOffset; + TUint iNdpBound; + TUint16 iDatagramIndex; + TUint16 iDatagramLength; + + RMBufPacket iPacket; + +#ifdef _DEBUG + //error statistics + TUint16 iPrevSeq; + TUint iTotalSeq; +#endif + + TUint16 iMaxSize; + }; + +// inline functions +#include "ncmntbparser.inl" + +#endif /* NCMNTBPARSER_H_ */ diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmntbparser.inl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmntbparser.inl Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +/** +@file +@internalComponent +*/ +#ifndef NCMNTBPARSER_INL +#define NCMNTBPARSER_INL + +inline void TNcmNth16::Dump() + { +#ifdef DEBUG_DUMP_NTBINNER + RDebug::Printf("NcmNth16:%08x\n" + "\tdwSignature=%S,\n" + "\twHeaderLength=%d,\n" + "\twSequence=%d,\n" + "\twBlockLength=%d,\n" + "\twNdpIndex=%d.", + this, &TPtrC8((TUint8*)&dwSignature, 4), wHeaderLength, wSequence, wBlockLength, + wNdpIndex); +#endif + } + +inline void TNcmNdp16::Dump() + { +#ifdef DEBUG_DUMP_NTBINNER + RDebug::Printf("NcmNdp16:%08x,\n" + "\tdwSignature=%S,\n" + "\twLength=%d,\n" + "\twNextNdpIndex=%d,\n" + "\twDatagram0Index=%d,\n" + "\twDatagram0Length=%d,\n" + "\twDatagram1Index=%d,\n" + "\twDatagram1Length=%d,\n", + this, &TPtrC8((TUint8*)&dwSignature, 4), + wLength, wNextNdpIndex, wDatagram0Index, wDatagram0Length, + wDatagram1Index, wDatagram1Length); +#endif + } + +inline CNcmNtb16Parser::CNcmNtb16Parser(MNcmNdpFrameObserver& aObserver) + : CNcmNtbParser(aObserver), iMaxSize(0xFFFF) + { + } + +inline CNcmNtbParser::CNcmNtbParser(MNcmNdpFrameObserver& aObserver) + : iObserver(aObserver) + { + } + + +#endif //NCMNTBPARSER_INL diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmpktdrv.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmpktdrv.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,82 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** +@file +@internalComponent +*/ +#ifndef NCMPKTDRV_H +#define NCMPKTDRV_H + + +#include +#ifndef __OVER_DUMMYUSBSCLDD__ +#include +#include +#include +#include +#else +#include +#endif + +class CNcmEngine; +class CNcmServer; + +/** +The Ncm packet driver +*/ +NONSHARABLE_CLASS(CNcmPktDrv) : public CPktDrvBase + { +public: + CNcmPktDrv(CPktDrvFactory& aFactory); + virtual ~CNcmPktDrv(); + virtual void ConstructL(CLANLinkCommon* aParent); + + //From CPktDrvBase + virtual TInt StartInterface(); + virtual TInt StopInterface(); + virtual TInt ResetInterface(); + virtual TInt SetRxMode(TRxMode AMode); + virtual TInt GetRxMode() const; + virtual TInt SetInterfaceAddress(const THWAddr&); + virtual TUint8* GetInterfaceAddress()const; + virtual TInt GetMulticastList(const THWAddr* aAddr, TInt& n) const; + virtual TInt SetMulticastList(const THWAddr* aAddr, TInt n); + virtual TInt InterfacePowerUp(); + virtual TInt InterfacePowerDown(); + virtual TInt InterfaceSleep(); + virtual TInt InterfaceResume(); + virtual TInt Notification(enum TAgentToNifEventType aEvent, void* aInfo); + virtual TInt Control(TUint aLevel,TUint aName,TDes8& aOption, TAny* aSource=0); + virtual TInt Send(RMBufChain& aPkt); + + //Upcall from Control Object + void ReceiveEthFrame(RMBufPacket&); + void ResumeSending(); + void FatalErrorNotification(TInt aError); + +#ifdef __OVER_DUMMYUSBSCLDD__ +public: + TInt State() const; +#endif + +private: + CNcmEngine* iEngine; + CNcmServer* iNcmServer; + }; + +#endif // NCMPKTDRV_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmpktdrvcommon.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmpktdrvcommon.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** +@file +@internalComponent +*/ +#ifndef NCMPKTDRVCOMMON_H +#define NCMPKTDRVCOMMON_H + +#include +#include "ncmcommon.h" + +const TInt KErrCongestion = -6668; +const TInt KErrNoBuffer = -6669; + + +NONSHARABLE_CLASS(TNcmNtbInParam) + { +public: + TUint32 iNtbInMaxSize; + TUint16 iNdpInDivisor; + TUint16 iNdpInPayloadRemainder; + TUint16 iNdpInAlignment; + }; + + +NONSHARABLE_CLASS(TNcmBuffer) + { +public: + TUint8* iPtr; + TUint32 iLen; + TUint32 iMaxLength; + }; + +#endif // NCMPKTDRVCOMMON_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmpktdrvfactory.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmpktdrvfactory.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** +@file +@internalComponent +*/ + +#ifndef NCMPKTDRVFACTORY_H +#define NCMPKTDRVFACTORY_H + +#include + +#ifndef __OVER_DUMMYUSBSCLDD__ +#include +#include +#else +#include +#endif + +const TUint KNcmDrvMajorVersionNumber=1; +const TUint KNcmDrvMinorVersionNumber=0; +const TUint KNcmDrvBuildVersionNumber=0; + +NONSHARABLE_CLASS(CNcmPktDrvFactory) : public CPktDrvFactory + { +public: + virtual CPktDrvBase* NewDriverL(CLANLinkCommon* aParent); + virtual TVersion Version() const; + }; + +#endif // NCMPKTDRVFACTORY_H + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmsharedstatemanager.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/inc/ncmsharedstatemanager.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** +@file +@internalComponent +*/ + +#ifndef NCMSHAREDSTATEMANAGER_H +#define NCMSHAREDSTATEMANAGER_H + +#include +#include + +#include "ncmpktdrvcommon.h" +#include "ncmcoexistbearerwatcher.h" + + +/** +The interface to Ncm Engine. +*/ +NONSHARABLE_CLASS(MShareStateObserver) + { +public: + virtual void NotifyDhcpStarted() = 0; + }; + +using namespace UsbNcm; + +/** +Maintain the shared state between the Paket Driver and NCM class controller +*/ +NONSHARABLE_CLASS(CNcmSharedStateManager) : public CActive + { +public: + static CNcmSharedStateManager* NewL(MShareStateObserver& aEngine); + ~CNcmSharedStateManager(); + + TInt NotifyDhcpProvisionRequested(); + void NotifyNcmConnected(); + void NotifyNcmDisconnected(TInt aReason); + + TInt SetStateValue(TInt aType, TInt aValue); + TInt RegisterNotify(const RMessage2& aMsg); + TInt DeRegisterNotify(); + +private: + CNcmSharedStateManager(MShareStateObserver& aEngine); + void ConstructL(); + + //From CActive + void RunL(); + void DoCancel(); + + TInt DoDhcpProvisionRequest(); + +private: + RProperty iProperty; + RMessage2 iNotifyMsg; + TPckgBuf iNcmState; + MShareStateObserver& iEngine; + CNcmCoexistBearerWatcher* iCoexistBearer; + }; + +#endif // NCMSHAREDSTATEMANAGER_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmbuffermanager.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmbuffermanager.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,170 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** +@file +@internalComponent +*/ + + +#include "ncmbuffermanager.h" +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "ncmbuffermanagerTraces.h" +#endif + + + + +// if there are KCongestionCount buffers will notify networking to stop sending +// if there are at least KUnCongestionCount, will notify networking to start sending +const TInt KCongestionCount = 1; +const TInt KUnCongestionCount = 3; + + + +// ======== MEMBER FUNCTIONS ======== +// + +CNcmBufferManager* CNcmBufferManager::NewL() + { + OstTraceFunctionEntry0( CNCMBUFFERMANAGER_NEWL_ENTRY ); + CNcmBufferManager *self = new (ELeave) CNcmBufferManager(); + OstTraceFunctionExit0( CNCMBUFFERMANAGER_NEWL_EXIT ); + return self; + } + +CNcmBufferManager::~CNcmBufferManager() + { + OstTraceFunctionEntry1( CNCMBUFFERMANAGER_CNCMBUFFERMANAGER_ENTRY, this ); + iFreeQueue.Reset(); + OstTraceFunctionExit1( CNCMBUFFERMANAGER_CNCMBUFFERMANAGER_EXIT, this ); + } + +// +// get a buffer block from manager +// +TInt CNcmBufferManager::GetBuffer(TNcmBuffer& aBuffer) + { + OstTraceFunctionEntry1( CNCMBUFFERMANAGER_GETBUFFER_ENTRY, this ); + + TInt count = iFreeQueue.Count(); + TInt ret = KErrNone; + + if (count == 0) + { + OstTraceFunctionExit1( CNCMBUFFERMANAGER_GETBUFFER_EXIT, this ); + return KErrNoBuffer; + } + else if (count == KCongestionCount) + { + iIsCongestion = ETrue; + ret = KErrCongestion; + } + aBuffer = iFreeQueue[0]; + iFreeQueue.Remove(0); + OstTraceFunctionExit1( CNCMBUFFERMANAGER_GETBUFFER_EXIT_DUP1, this ); + return ret; + } + +// +// free a buffer block to manager +// +void CNcmBufferManager::FreeBuffer(const TNcmBuffer& aBuffer) + { + OstTraceFunctionEntry1( CNCMBUFFERMANAGER_FREEBUFFER_ENTRY, this ); + iFreeQueue.Append(aBuffer); + int count = iFreeQueue.Count(); + iFreeQueue[count-1].iLen = 0; + if (count == KUnCongestionCount) + { + iIsCongestion = EFalse; + } + OstTraceFunctionExit1( CNCMBUFFERMANAGER_FREEBUFFER_EXIT, this ); + } + +// +// set the whole buffer area to create buffer blocks +// +void CNcmBufferManager::InitBufferArea(TAny* aBuf, TInt aLength) + { + OstTrace1( TRACE_NORMAL, CNCMBUFFERMANAGER_INITBUFFERAREA, "CNcmBufferManager::InitBufferArea aLength=%d", aLength ); + iBuf = (TUint8*)aBuf; + iLen = aLength; + } + +// +// set the size of a buffer block, create buffer blocks on the buffer area +// +TInt CNcmBufferManager::SetBufferCellSize(TInt aSize) + { + OstTraceFunctionEntry1( CNCMBUFFERMANAGER_SETBUFFERCELLSIZE_ENTRY, this ); + +// buffer block size must be aligned with KAlignSize to make the each buffer start align with KAlignSize + iCellSize = (aSize+iAlignSize-1)&~(iAlignSize-1); + OstTraceExt2( TRACE_NORMAL, CNCMBUFFERMANAGER_SETBUFFERCELLSIZE, "CNcmBufferManager::SetBufferCellSize aSize=%d, iCellSize=%d", aSize, iCellSize ); + +// buffer area got from share chunk LDD may not align, make it align to KAlignSize first + TUint32 buf = (TUint)iBuf; + buf = (buf+iAlignSize-1)&~(iAlignSize-1); + TUint8* alignbuf = (TUint8*)buf; + TUint32 offset = buf - (TUint)iBuf; + + int count = (iLen-offset)/iCellSize; + iFreeQueue.Reset(); + if (count < KUnCongestionCount) + { + OstTrace1( TRACE_FATAL, CNCMBUFFERMANAGER_SETBUFFERCELLSIZE1, "the buffer cell size is too big and create too less buffers %d", count ); + OstTraceFunctionExit1( CNCMBUFFERMANAGER_SETBUFFERCELLSIZE_EXIT, this ); + return KErrUnknown; + } + + TNcmBuffer ncmbuf; + for (TInt i=0 ; iConstructL(); + CleanupStack::Pop(self); + return self; + } + +CNcmCoexistBearerWatcher::CNcmCoexistBearerWatcher() : CActive(CActive::EPriorityStandard) + { + CActiveScheduler::Add(this); + } + + +CNcmCoexistBearerWatcher::~CNcmCoexistBearerWatcher() + { + Cancel(); + iProperty.Close(); + } + + +void CNcmCoexistBearerWatcher::ConstructL() + { + OstTraceFunctionEntry0(CNCMCOEXISTBEARERWATCHER_CONSTRUCTL); + + const TUint KIPBearerCoexistenceProperty = 0x10286a95; + + TInt err = iProperty.Define(KIPBearerCoexistenceProperty, RProperty::EInt, KAllowAllPolicy, KNetworkControlPolicy); + if ( (err != KErrNone) && (err != KErrAlreadyExists) ) + { + OstTrace1( TRACE_ERROR, CNCMCOEXISTBEARERWATCHER_CONSTRUCTL_DUP02, "Failed to define the property;err=%d", err ); + User::Leave(err); + } + + TSecureId thisSID = RProcess().SecureId(); + User::LeaveIfError(iProperty.Attach(thisSID, KIPBearerCoexistenceProperty)); + User::LeaveIfError(iProperty.Get(reinterpret_cast(iBearerState))); + + OstTraceFunctionExit0(CNCMCOEXISTBEARERWATCHER_CONSTRUCTL_DUP01); + } + + +TInt CNcmCoexistBearerWatcher::SetIpOverUsbActive(TRequestStatus& aStatus) + { + OstTraceFunctionEntry0(CNCMCOEXISTBEARERWATCHER_SETIPOVERUSBACTIVE); + + TInt ret = DoActive(); + OstTrace1(TRACE_NORMAL, CNCMCOEXISTBEARERWATCHER_SETIPOVERUSBACTIVE_DUP01, "DoActive()=%d.", ret); + + if (KErrNone == ret) + { + OstTraceFunctionExitExt(CNCMCOEXISTBEARERWATCHER_SETIPOVERUSBACTIVE_DUP02, this, KErrCompletion); + return KErrCompletion; + } + else if (KErrInUse == ret) + { + iReportStatus = &aStatus; + *iReportStatus = KRequestPending; + + iProperty.Subscribe(iStatus); + SetActive(); + return KErrNone; + } + + OstTraceFunctionExitExt(CNCMCOEXISTBEARERWATCHER_SETIPOVERUSBACTIVE_DUP03, this, ret); + return ret; + } +/** + * do Set IP Over USB Actived. + */ +TInt CNcmCoexistBearerWatcher::DoActive() + { + __ASSERT_DEBUG(iBearerState != EIPBearerIPOverUSB, User::Panic(KCoBearerPanic, __LINE__)); + + _LIT(KIPBearerCoexistenceMutex, "IPBearerCoexistenceMutex"); + RMutex gMutex; + TInt error = gMutex.CreateGlobal(KIPBearerCoexistenceMutex); + if ( error != KErrNone ) + { + if( error == KErrAlreadyExists ) + { + error = gMutex.OpenGlobal(KIPBearerCoexistenceMutex); + if(error != KErrNone) + { + OstTrace1(TRACE_ERROR, CNCMCOEXISTBEARERWATCHER_DOACTIVE, "Failed to open global mutex, error=%d", error); + return KErrNotReady; + } + } + else + { + OstTrace1(TRACE_ERROR, CNCMCOEXISTBEARERWATCHER_DOACTIVE_DUP01, "Failed to create a global mutex, error=%d", error); + return KErrNotReady; + } + } + + gMutex.Wait(); + error = iProperty.Get(reinterpret_cast(iBearerState)); + if (error != KErrNone) + { + OstTrace1(TRACE_ERROR, CNCMCOEXISTBEARERWATCHER_DOACTIVE_DUP02, "Failed to get property value, error=%d", error); + } + else + { + if (iBearerState == EIPBearerNoneActive) + { + error = iProperty.Set(EIPBearerIPOverUSB); + if (error != KErrNone) + { + OstTrace1(TRACE_ERROR, CNCMCOEXISTBEARERWATCHER_DOACTIVE_DUP03, "Failed to set property value, error=%d", error); + } + else + { + iBearerState = EIPBearerIPOverUSB; + } + } + else + { + error = KErrInUse; + __ASSERT_DEBUG(iBearerState != EIPBearerIPOverUSB, User::Panic(KCoBearerPanic, __LINE__)); + OstTrace1(TRACE_WARNING, CNCMCOEXISTBEARERWATCHER_DOACTIVE_DUP04, "Failed to set CoexistIPBearer to IPOverUsb since iBearerState=%d", iBearerState); + } + } + + gMutex.Signal(); + gMutex.Close(); + + return error; + } + +TInt CNcmCoexistBearerWatcher::SetIpOverUsbDeactive() + { + __ASSERT_DEBUG(iBearerState==EIPBearerIPOverUSB, User::Panic(KCoBearerPanic, __LINE__)); + + TInt err = iProperty.Set(EIPBearerNoneActive); + OstTrace1(TRACE_NORMAL, CNCMCOEXISTBEARERWATCHER_SETIPOVERUSBDEACTIVE, "Stop using Coexistence Bearer, result=%d", err); + iBearerState = EIPBearerNoneActive; + + return err; + } + +void CNcmCoexistBearerWatcher::RunL() + { + OstTrace1(TRACE_NORMAL, CNCMCOEXISTBEARERWATCHER_RUNL, "iStatus.Int()=%d", iStatus.Int()); + + if (KErrNone == iStatus.Int()) + { + TInt ret = DoActive(); + OstTrace1(TRACE_NORMAL, CNCMCOEXISTBEARERWATCHER_RUNL_DUP01, "DoActive()=%d", ret); + if (KErrNone == ret) + { + User::RequestComplete(iReportStatus, KErrNone); + } + else if (KErrInUse == ret) + { + iProperty.Subscribe(iStatus); + SetActive(); + } + else + { + User::RequestComplete(iReportStatus, ret); + } + } + else if (KErrCancel != iStatus.Int()) + { + User::RequestComplete(iReportStatus, iStatus.Int()); + } + } + +void CNcmCoexistBearerWatcher::DoCancel() + { + OstTraceFunctionEntry0(CNCMCOEXISTBEARERWATCHER_DOCANCEL); + iProperty.Cancel(); + User::RequestComplete(iReportStatus, KErrCancel); + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmcomminterfacesenderandreceiver.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmcomminterfacesenderandreceiver.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,265 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* implementation for read and write data from share chunk LDD +* +*/ + + +/** +@internalComponent +*/ + +#include "ncmcommunicationinterface.h" +#include "ncmengine.h" +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "ncmcomminterfacesenderandreceiverTraces.h" +#endif + + + +// ======== MEMBER FUNCTIONS ======== +// + +CNcmCommInterfaceSenderAndReceiver::CNcmCommInterfaceSenderAndReceiver(RDevUsbcScClient& aPort, CNcmCommunicationInterface& aComm) + : CActive(CActive::EPriorityStandard), + iPort(aPort), + iCommInterface(aComm), + iState(EUnInit) + { + CActiveScheduler::Add(this); + } + +CNcmCommInterfaceSenderAndReceiver* CNcmCommInterfaceSenderAndReceiver::NewL(RDevUsbcScClient& aPort, CNcmCommunicationInterface& aComm) + { + return new(ELeave) CNcmCommInterfaceSenderAndReceiver(aPort, aComm); + } + +CNcmCommInterfaceSenderAndReceiver::~CNcmCommInterfaceSenderAndReceiver() + { + Stop(); + } + +void CNcmCommInterfaceSenderAndReceiver::Start() + { + OstTraceFunctionEntry1( CNCMCOMMINTERFACESENDERANDRECEIVER_START_ENTRY, this ); + + TInt ret = iPort.OpenEndpoint(iEp0Buffer, KEp0Number); + if (ret != KErrNone) + { + OstTrace1( TRACE_FATAL, CNCMCOMMINTERFACESENDERANDRECEIVER_START1, "OpenEndpoint error %d", ret); + iCommInterface.ControlMsgError(EInternalError); + OstTraceFunctionExit1( CNCMCOMMINTERFACESENDERANDRECEIVER_START_EXIT, this ); + return; + } + iState = EIdle; + OstTraceFunctionExit1( CNCMCOMMINTERFACESENDERANDRECEIVER_START_EXIT_DUP1, this ); + } + +void CNcmCommInterfaceSenderAndReceiver::Stop() + { + OstTraceFunctionEntry0( CNCMCOMMINTERFACESENDERANDRECEIVER_STOP_ENTRY ); + + iState = EIdle; + Cancel(); + iEp0Buffer.Close(); + OstTraceFunctionExit0( CNCMCOMMINTERFACESENDERANDRECEIVER_STOP_EXIT ); + } + + +// +//Read data of aLength from LDD +// + +TInt CNcmCommInterfaceSenderAndReceiver::Read(TRequestStatus& aStatus, TDes8& aBuf, TInt aLength) + { + OstTraceFunctionEntry1( CNCMCOMMINTERFACESENDERANDRECEIVER_READ_ENTRY, this ); + OstTrace1( TRACE_NORMAL, CNCMCOMMINTERFACESENDERANDRECEIVER_READ, "CNcmCommInterfaceSenderAndReceiver::Read length %d", aLength ); + + iCompleteStatus = &aStatus; + *iCompleteStatus = KRequestPending; + if (iState != EIdle) + { + OstTrace0( TRACE_FATAL, CNCMCOMMINTERFACESENDERANDRECEIVER_READ_DUP1, "CNcmCommInterfaceSenderAndReceiver Read In Use" ); + OstTraceFunctionExit1( CNCMCOMMINTERFACESENDERANDRECEIVER_READ_EXIT, this ); + return KErrInUse; + } + iReceiveBuf = &aBuf; + iReceiveBuf->Zero(); + iToReceiveLength = aLength; + iState = EReceiving; + ReadData(); + OstTraceFunctionExit1( CNCMCOMMINTERFACESENDERANDRECEIVER_READ_EXIT_DUP1, this ); + return KErrNone; + } + +// +//write aLength data to ldd +// +TInt CNcmCommInterfaceSenderAndReceiver::Write(TRequestStatus& aStatus, TDesC8& aBuf, TInt aLength) + { + OstTraceFunctionEntry1( CNCMCOMMINTERFACESENDERANDRECEIVER_WRITE_ENTRY, this ); + OstTrace1( TRACE_NORMAL, CNCMCOMMINTERFACESENDERANDRECEIVER_WRITE, "CNcmCommInterfaceSenderAndReceiver::Write length %d", aLength ); + + iCompleteStatus = &aStatus; + *iCompleteStatus = KRequestPending; + + if (iState != EIdle) + { + OstTrace0( TRACE_FATAL, CNCMCOMMINTERFACESENDERANDRECEIVER_WRITE1, "CNcmCommInterfaceSenderAndReceiver::Write in Use" ); + OstTraceFunctionExit1( CNCMCOMMINTERFACESENDERANDRECEIVER_WRITE_EXIT, this ); + return KErrInUse; + } + + TAny *buf; + TUint size; + TInt ret = iEp0Buffer.GetInBufferRange(buf, size); + if (ret != KErrNone) + { + OstTrace0( TRACE_FATAL, CNCMCOMMINTERFACESENDERANDRECEIVER_WRITE2, "CNcmCommInterfaceSenderAndReceiver::Write in Use" ); + OstTraceFunctionExit1( CNCMCOMMINTERFACESENDERANDRECEIVER_WRITE_EXIT_DUP1, this ); + return ret; + } + else if (size < aLength) + { + OstTrace0( TRACE_FATAL, CNCMCOMMINTERFACESENDERANDRECEIVER_WRITE3, "write data is bigger than ldd buffer size" ); + OstTraceFunctionExit1( CNCMCOMMINTERFACESENDERANDRECEIVER_WRITE_EXIT_DUP2, this ); + return KErrArgument; + } + + TPtr8 writeBuf((TUint8 *)buf, size); + writeBuf.Copy(aBuf.Ptr(), aLength); + ret = iEp0Buffer.WriteBuffer(buf, writeBuf.Size(), ETrue, iStatus); + if (ret != KErrNone) + { + OstTrace1( TRACE_FATAL, CNCMCOMMINTERFACESENDERANDRECEIVER_WRITE4, "WriteBuffer error %d", ret ); + OstTraceFunctionExit1( CNCMCOMMINTERFACESENDERANDRECEIVER_WRITE_EXIT_DUP3, this ); + return ret; + } + iState = ESending; + SetActive(); + OstTraceFunctionExit1( CNCMCOMMINTERFACESENDERANDRECEIVER_WRITE_EXIT_DUP4, this ); + return KErrNone; + } + + + +// +//Read data from USB share chunk LDD +// +void CNcmCommInterfaceSenderAndReceiver::ReadData() + { + OstTraceFunctionEntry1( CNCMCOMMINTERFACESENDERANDRECEIVER_READDATA_ENTRY, this ); + TInt ret; + TAny* buf; + TUint8* receivebuf; + TUint receiveLen; + TBool zlp; + + FOREVER + { + ret = iEp0Buffer.GetBuffer(buf, receiveLen, zlp, iStatus, iToReceiveLength); + receivebuf = (TUint8*)buf; + if (ret == TEndpointBuffer::KStateChange) + { + OstTrace0( TRACE_NORMAL, CNCMCOMMINTERFACESENDERANDRECEIVER_READDATA, "receive state change, discard it" ); + continue; + } + + else if (ret == KErrCompletion) + { + OstTrace1( TRACE_NORMAL, CNCMCOMMINTERFACESENDERANDRECEIVER_READDATA1, "read data length %d from ldd", receiveLen ); + if (receiveLen > iToReceiveLength) + { + User::RequestComplete(iCompleteStatus, KErrOverflow); + iState = EIdle; + OstTrace0( TRACE_NORMAL, CNCMCOMMINTERFACESENDERANDRECEIVER_READDATA2,"data from ldd is bigger than receive buffer" ); + OstTraceFunctionExit1( CNCMCOMMINTERFACESENDERANDRECEIVER_READDATA_EXIT, this ); + return; + } + + iReceiveBuf->Append(receivebuf, receiveLen); + iToReceiveLength -= receiveLen; + if (!iToReceiveLength) + { + User::RequestComplete(iCompleteStatus, KErrNone); + iState = EIdle; + OstTrace0( TRACE_NORMAL, CNCMCOMMINTERFACESENDERANDRECEIVER_READDATA3,"Complete read request" ); + OstTraceFunctionExit1( CNCMCOMMINTERFACESENDERANDRECEIVER_READDATA_EXIT_DUP1, this ); + return; + } + continue; + } + else if (ret == KErrNone) + { + break; + } + else + { + OstTrace1( TRACE_NORMAL, CNCMCOMMINTERFACESENDERANDRECEIVER_READDATA4, "GetBuffer error %d", ret); + User::RequestComplete(iCompleteStatus, KErrNone); + iState = EIdle; + OstTraceFunctionExit1( CNCMCOMMINTERFACESENDERANDRECEIVER_READDATA_EXIT_DUP2, this ); + return; + } + } + SetActive(); + OstTraceFunctionExit1( CNCMCOMMINTERFACESENDERANDRECEIVER_READDATA_EXIT_DUP3, this ); + } + +// +//RunL, looply receive data from share chunk LDD until receive all required data +// +void CNcmCommInterfaceSenderAndReceiver::RunL() + { + OstTraceFunctionEntry1( CNCMCOMMINTERFACESENDERANDRECEIVER_RUNL_ENTRY, this ); + if(iStatus.Int() != KErrNone) + { + if (KErrCancel == iStatus.Int() ) + { + OstTrace0( TRACE_NORMAL, CNCMCOMMINTERFACESENDERANDRECEIVER_RUNL,"CNcmCommInterfaceSenderAndReceiver, control channel is cancelled" ); + } + else + { + OstTrace1( TRACE_NORMAL, CNCMCOMMINTERFACESENDERANDRECEIVER_RUNL1, "CNcmCommInterfaceSenderAndReceiver::RunL error %d", iStatus.Int()); + } + User::RequestComplete(iCompleteStatus, iStatus.Int()); + } + else + { + if (iState == EReceiving) + { + ReadData(); + } + else if (iState == ESending) + { + User::RequestComplete(iCompleteStatus, KErrNone); + iState = EIdle; + OstTrace0( TRACE_NORMAL, CNCMCOMMINTERFACESENDERANDRECEIVER_RUNL2,"Complete write request" ); + } + } + OstTraceFunctionExit1( CNCMCOMMINTERFACESENDERANDRECEIVER_RUNL_EXIT, this ); + } + +// +//Cancel the outgoing read request +// +void CNcmCommInterfaceSenderAndReceiver::DoCancel() + { + OstTraceFunctionEntry1( CNCMCOMMINTERFACESENDERANDRECEIVER_DOCANCEL_ENTRY, this ); + iPort.ReadCancel(KUsbcScEndpointZero); + iPort.WriteCancel(KUsbcScEndpointZero); + OstTraceFunctionExit1( CNCMCOMMINTERFACESENDERANDRECEIVER_DOCANCEL_EXIT, this ); + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmcommunicationinterface.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmcommunicationinterface.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,522 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* implementation of NCM communication interface class +* +*/ + + +#include +#include "ncmcommunicationinterface.h" +#include "ncmnotificationdescriptor.h" +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "ncmcommunicationinterfaceTraces.h" +#endif + + + +const TUint KUsbRequestLengthIdx = 6; +const TUint KUsbRequestTypeIdx = 1; +const TInt KIntEndpoint = 1; +const TInt KNotificationRequestType = 0xA1; + + +#if defined(_DEBUG) +_LIT(KNcmCommInterfacePanic, "UsbNcmComm"); // must be <=16 chars +#endif + + +// Panic codes +enum TNcmCommPanicCode + { + ENcmCommWrongSetupLength = 1, + ENcmCommWrongDataLength, + ENcmCommWriteError, + ENcmCMEndMark + }; + + +// ======== MEMBER FUNCTIONS ======== +// + +CNcmCommunicationInterface::CNcmCommunicationInterface(MNcmControlObserver& aEngine, RDevUsbcScClient& aLdd) : CActive(CActive::EPriorityHigh), + iEngine(aEngine), iPort(aLdd) + { + CActiveScheduler::Add(this); + } + +void CNcmCommunicationInterface::ConstructL() + { + iSenderAndReceiver = CNcmCommInterfaceSenderAndReceiver::NewL(iPort, *this); + } + +CNcmCommunicationInterface* CNcmCommunicationInterface::NewL(MNcmControlObserver& aEngine, RDevUsbcScClient& aLdd) + { + OstTraceFunctionEntry0( CNCMCOMMUNICATIONINTERFACE_NEWL_ENTRY ); + CNcmCommunicationInterface *self=new (ELeave) CNcmCommunicationInterface(aEngine, aLdd); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(); + OstTraceFunctionExit0( CNCMCOMMUNICATIONINTERFACE_NEWL_EXIT ); + return self; + } + +CNcmCommunicationInterface::~CNcmCommunicationInterface() + { + OstTraceFunctionEntry1( CNCMCOMMUNICATIONINTERFACE_CNCMCOMMUNICATIONINTERFACE_ENTRY, this ); + + Cancel(); + delete iSenderAndReceiver; + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_CNCMCOMMUNICATIONINTERFACE_EXIT, this ); + } + +// +//Start the control channel of NCM +// +TInt CNcmCommunicationInterface::Start() + { + OstTraceFunctionEntry1( CNCMCOMMUNICATIONINTERFACE_START_ENTRY, this ); + if (iStarted) + { + OstTrace0( TRACE_WARNING, CNCMCOMMUNICATIONINTERFACE_START, "CNcmCommunicationInterface, already started!" ); + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_START_EXIT, this ); + return KErrInUse; + } + + TInt ret = GetInterfaceNumber(); + if (ret != KErrNone) + { + OstTrace1( TRACE_FATAL, CNCMCOMMUNICATIONINTERFACE_START1, "GetInterfaceNumber failed ret=%d", ret); + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_START_EXIT_DUP1, this ); + return ret; + } + + iStarted = ETrue; + iRWState = EStateInitial; + + iSenderAndReceiver->Start(); + + //force a call to RunL + SetActive(); + TRequestStatus* status=&iStatus; + User::RequestComplete(status, KErrNone); + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_START_EXIT_DUP2, this ); + return KErrNone; + } + +// +//Listen on the ep0 to receive the NCM control message from host +// +void CNcmCommunicationInterface::ReadSetup() + { + OstTraceFunctionEntry1( CNCMCOMMUNICATIONINTERFACE_READSETUP_ENTRY, this ); + iRWState = EStateReadSetup; + iRequestType = 0; + iDataStageLength = 0; + TInt ret = iSenderAndReceiver->Read(iStatus, iSetupPacket, KSetupPacketLength); + + if (ret != KErrNone) + { + OstTrace1( TRACE_FATAL, CNCMCOMMUNICATIONINTERFACE_READSETUP, "read setup packet error %d", ret); + ControlMsgError(EInternalError); + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_READSETUP_EXIT, this ); + return; + } + SetActive(); + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_READSETUP_EXIT_DUP1, this ); + } + + +// +//decode the setup packet to get command information. +// +void CNcmCommunicationInterface::DecodeSetup() + { + OstTraceFunctionEntry1( CNCMCOMMUNICATIONINTERFACE_DECODESETUP_ENTRY, this ); + + __ASSERT_DEBUG(iSetupPacket.Length()==KSetupPacketLength, + User::Panic(KNcmCommInterfacePanic, ENcmCommWrongSetupLength)); + + iRequestType = iSetupPacket[KUsbRequestTypeIdx]; + iDataStageLength = LittleEndian::Get16(&iSetupPacket[KUsbRequestLengthIdx]); + + switch (iRequestType) + { + case EGetNtbParameters: + if (iDataStageLength != KNtbParamStructLength) + { + ControlMsgError(EInvalidLengthToRead); + break; + } + iEngine.HandleGetNtbParam(iDataBuffer); + __ASSERT_DEBUG(iDataBuffer.Length()==KNtbParamStructLength, + User::Panic(KNcmCommInterfacePanic, ENcmCommWrongDataLength)); + WriteDataIn(); + break; + + case EGetNtbInputSize: + if (iDataStageLength != KNtbInputSizeStructLength) + { + ControlMsgError(EInvalidLengthToRead); + break; + } + iEngine.HandleGetNtbInputSize(iDataBuffer); + __ASSERT_DEBUG(iDataBuffer.Length()==KNtbInputSizeStructLength, + User::Panic(KNcmCommInterfacePanic, ENcmCommWrongDataLength)); + WriteDataIn(); + break; + + case ESetNtbInputSize: + if (iDataStageLength != KNtbInputSizeStructLength) + { + ControlMsgError(EInvalidLengthToRead); + break; + } + ReadDataOut(); + break; + default: + TInt ret = iPort.EndpointZeroRequestError(); + OstTrace1( TRACE_ERROR, CNCMCOMMUNICATIONINTERFACE_DECODESETUP, "unsupport request, halt endpoint with EndpointZeroRequestError %d", ret); + ReadSetup(); + break; + } + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_DECODESETUP_EXIT, this ); + } + + + +// +//Read the raw data of a control request message from host +// +void CNcmCommunicationInterface::ReadDataOut() + { + OstTraceFunctionEntry1( CNCMCOMMUNICATIONINTERFACE_READDATAOUT_ENTRY, this ); + iRWState = EStateReadDataout; + iSenderAndReceiver->Read(iStatus, iDataBuffer, iDataStageLength); + SetActive(); + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_READDATAOUT_EXIT, this ); + } + + + + +// +//Parse the data out from host to specific NCM control message +// +void CNcmCommunicationInterface::ParseDataOut() + { + OstTraceFunctionEntry1( CNCMCOMMUNICATIONINTERFACE_PARSEDATAOUT_ENTRY, this ); + + __ASSERT_DEBUG(iDataBuffer.Length()>0, + User::Panic(KNcmCommInterfacePanic, ENcmCommWrongDataLength)); + + TInt ret = KErrNone; + switch (iRequestType) + { + case ESetNtbInputSize: + ret = iEngine.HandleSetNtbInputSize(iDataBuffer); + break; + default: + ret = KErrNotSupported; + break; + } + + if (ret == KErrNone) + { + iPort.SendEp0StatusPacket(); + } + else + { + OstTrace1( TRACE_WARNING, CNCMCOMMUNICATIONINTERFACE_PARSEDATAOUT, "handle request iRequestType error %d stall endpoint", ret); + iPort.EndpointZeroRequestError(); + } + ReadSetup(); + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_PARSEDATAOUT_EXIT, this ); + } + +// +// send connection status notification, aConnected = ETrue if connection up, otherwise EFalse if connection discnnected +// +TInt CNcmCommunicationInterface::SendConnectionNotification(TBool aConnected) + { + OstTraceFunctionEntry1( CNCMCOMMUNICATIONINTERFACE_SENDCONNECTIONNOTIFICATION_ENTRY, this ); + const TUint8 KConnectionNotificationCode = 0x00; + const TUint16 KConnectedCode = 0x0001; + const TUint16 KDisconnectCode = 0x0000; + + TUSBNotificationNetworkConnection netNotify; + netNotify.iRequestType = KNotificationRequestType; + netNotify.iNotification = KConnectionNotificationCode; + netNotify.iValue = (aConnected)?KConnectedCode:KDisconnectCode; + netNotify.iIndex = iInterfaceNumber; + netNotify.iLength = 0; + + return WriteInterruptData(KIntEndpoint, netNotify.Des(), + netNotify.Des().Length()); + } + +// +// send speed notification +// +TInt CNcmCommunicationInterface::SendSpeedNotification(TInt aUSBitRate, TInt aDSBitRate) + { + OstTraceFunctionEntry1( CNCMCOMMUNICATIONINTERFACE_SENDSPEEDNOTIFICATION_ENTRY, this ); + const TUint8 KSpeedNotificationCode = 0x2A; + + TUSBNotificationConnectionSpeedChange speedNotify; + speedNotify.iRequestType = KNotificationRequestType; + speedNotify.iNotification = KSpeedNotificationCode; + speedNotify.iValue = 0x00; + speedNotify.iIndex = iInterfaceNumber; + speedNotify.iLength = 0x08; + speedNotify.iUSBitRate = aUSBitRate; + speedNotify.iDSBitRate = aDSBitRate; + + return WriteInterruptData(KIntEndpoint, speedNotify.Des(), + speedNotify.Des().Length()); + } + + +// +//According to the receving request message, send back a response to the host +// +void CNcmCommunicationInterface::WriteDataIn() + { + OstTraceFunctionEntry1( CNCMCOMMUNICATIONINTERFACE_WRITEDATAIN_ENTRY, this ); + + iRWState = EStateWriteDatain; + TInt ret = iSenderAndReceiver->Write(iStatus, iDataBuffer, iDataBuffer.Length()); + __ASSERT_DEBUG(ret==KErrNone, User::Panic(KNcmCommInterfacePanic, ENcmCommWriteError)); + SetActive(); + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_WRITEDATAIN_EXIT, this ); + } + +// +//Cancel the outgoing request +// +void CNcmCommunicationInterface::DoCancel() + { + OstTraceFunctionEntry1( CNCMCOMMUNICATIONINTERFACE_DOCANCEL_ENTRY, this ); + TRequestStatus* status = &iStatus; + User::RequestComplete(status, KErrCancel); + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_DOCANCEL_EXIT, this ); + } + +// +//Stop the control channel to stop the NCM +// +void CNcmCommunicationInterface::Stop() + { + OstTraceFunctionEntry1( CNCMCOMMUNICATIONINTERFACE_STOP_ENTRY, this ); + iStarted = EFalse; + iSenderAndReceiver->Stop(); + Cancel(); + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_STOP_EXIT, this ); + } + +// +//AO RunL +// +void CNcmCommunicationInterface::RunL() + { + OstTraceFunctionEntry1( CNCMCOMMUNICATIONINTERFACE_RUNL_ENTRY, this ); + if(iStatus.Int() != KErrNone) + { + if (KErrCancel == iStatus.Int() ) + { + } + else + { + ControlMsgError(EInternalError); + } + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_RUNL_EXIT, this ); + return; + } + + switch(iRWState) + { + case EStateInitial: + { + ReadSetup(); + break; + } + + case EStateReadSetup: + { + DecodeSetup(); + break; + } + + case EStateReadDataout: + { + ParseDataOut(); + break; + } + + case EStateWriteDatain: + { + ReadSetup(); + break; + } + } + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_RUNL_EXIT_DUP1, this ); + } + + +// +//Any fatal error occurs when reading/sending a NCM control message via USB interface +// +void CNcmCommunicationInterface::ControlMsgError(TNcmCommErrorCode aCode) + { + OstTraceFunctionEntry1( CNCMCOMMUNICATIONINTERFACE_CONTROLMSGERROR_ENTRY, this ); + OstTrace1( TRACE_NORMAL, CNCMCOMMUNICATIONINTERFACE_CONTROLMSGERROR, "CNcmCommunicationInterface, Handle Ncm Control Message with err=%d", aCode); + + // Stall bus, there's nothing else we can do + iPort.EndpointZeroRequestError(); + iEngine.ControlError(aCode); + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_CONTROLMSGERROR_EXIT, this ); + } + + +TInt CNcmCommunicationInterface::WriteInterruptData(TInt aEndPoint, + TDesC8& aDes, + TInt aLength) + + { + OstTraceFunctionEntry1( CNCMCOMMUNICATIONINTERFACE_WRITEINTERRUPTDATA_ENTRY, this ); + + TInt ret; + RTimer timer; + ret = timer.CreateLocal(); + if ( ret ) + { + OstTrace1( TRACE_FATAL, CNCMCOMMUNICATIONINTERFACE_WRITEINTERRUPTDATA, "\ttimer.CreateLocal = %d- returning", ret); + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_WRITEINTERRUPTDATA_EXIT, this ); + return ret; + } + TRequestStatus status; + TRequestStatus timerStatus; + + TEndpointBuffer epBuffer; + ret = iPort.OpenEndpoint(epBuffer, aEndPoint); + if (ret != KErrNone) + { + timer.Close(); + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_WRITEINTERRUPTDATA_EXIT_DUP1, this ); + return ret; + } + + TAny *buf; + TUint size; + ret = epBuffer.GetInBufferRange(buf, size); + if (ret != KErrNone) + { + timer.Close(); + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_WRITEINTERRUPTDATA_EXIT_DUP2, this ); + return ret; + } + else if (size < aLength) + { + timer.Close(); + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_WRITEINTERRUPTDATA_EXIT_DUP3, this ); + return KErrArgument; + } + + TPtr8 writeBuf((TUint8 *)buf, size); + writeBuf.Copy(aDes.Ptr(), aLength); + ret = epBuffer.WriteBuffer(buf, writeBuf.Size(), ETrue, status); + if (ret != KErrNone) + { + timer.Close(); + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_WRITEINTERRUPTDATA_EXIT_DUP4, this ); + return ret; + } + + const TInt KWriteDataTimeout = 1000000; + timer.After(timerStatus, KWriteDataTimeout); + User::WaitForRequest(status, timerStatus); + if ( timerStatus != KRequestPending ) + { + // Timeout occurred, silently ignore error condition. + // Assuming that the line has been disconnected + OstTrace0( TRACE_ERROR, CNCMCOMMUNICATIONINTERFACE_WRITEINTERRUPTDATA1, "CNcmCommunicationInterface::WriteInterruptData() - Timeout occurred"); + iPort.WriteCancel(epBuffer.BufferNumber()); + User::WaitForRequest(status); + ret = timerStatus.Int(); + } + else + { + OstTrace0( TRACE_ERROR, CNCMCOMMUNICATIONINTERFACE_WRITEINTERRUPTDATA2, "CNcmCommunicationInterface::WriteInterruptData() - Write completed"); + timer.Cancel(); + User::WaitForRequest(timerStatus); + ret = status.Int(); + } + + epBuffer.Close(); + timer.Close(); + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_WRITEINTERRUPTDATA_EXIT_DUP5, this ); + return ret; + } + + +// +// Get interface number +// +TInt CNcmCommunicationInterface::GetInterfaceNumber() + { + OstTraceFunctionEntry1( CNCMCOMMUNICATIONINTERFACE_GETINTERFACENUMBER_ENTRY, this ); + + TInt interfaceSize = 0; + // 2 is where the interface number is, according to the LDD API + const TInt intNumOffsetInDes = 2; + + // 0 means the main interface in the LDD API + TInt res = iPort.GetInterfaceDescriptorSize(0, interfaceSize); + + if ( res ) + { + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_GETINTERFACENUMBER_EXIT, this ); + return res; + } + + HBufC8* interfaceBuf = HBufC8::New(interfaceSize); + if ( !interfaceBuf ) + { + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_GETINTERFACENUMBER_EXIT_DUP1, this ); + return KErrNoMemory; + } + + TPtr8 interfacePtr = interfaceBuf->Des(); + interfacePtr.SetLength(0); + // 0 means the main interface in the LDD API + res = iPort.GetInterfaceDescriptor(0, interfacePtr); + + if ( res ) + { + delete interfaceBuf; + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_GETINTERFACENUMBER_EXIT_DUP2, this ); + return res; + } + + const TUint8* buffer = reinterpret_cast(interfacePtr.Ptr()); + iInterfaceNumber = buffer[intNumOffsetInDes]; + + delete interfaceBuf; + OstTraceFunctionExit1( CNCMCOMMUNICATIONINTERFACE_GETINTERFACENUMBER_EXIT_DUP3, this ); + return KErrNone; + } + + + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmdatainterface.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmdatainterface.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,309 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include +#include + +#ifndef __OVER_DUMMYUSBSCLDD__ +#include //EEndPoint2 +#else +#include +#endif +#include "ncmdatainterface.h" +#include "ncmdatareceiver.h" +#include "ncmdatasender.h" +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "ncmdatainterfaceTraces.h" +#endif + + + + +const TInt KAltSetting1 = 1; +const TInt KAltSetting0 = 0; + + +CNcmDataInterface* CNcmDataInterface::NewL(MNcmDataObserver& aEngine, + RDevUsbcScClient& aLdd) + { + CNcmDataInterface *self = new (ELeave) CNcmDataInterface(aEngine, aLdd); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + return self; + } + +CNcmDataInterface::CNcmDataInterface(MNcmDataObserver& aEngine, + RDevUsbcScClient& aLdd) : + CActive(CActive::EPriorityStandard), iEngine(aEngine), iLdd(aLdd) + { + CActiveScheduler::Add(this); + } + +void CNcmDataInterface::ConstructL() + { + OstTraceFunctionEntry0(CNCMDATAINTERFACE_CONSTRUCTL); + + iReceiver = CNcmDataReceiver::NewL(iLdd, *this); + iSender = CNcmDataSender::NewL(iLdd, *this); + OstTraceFunctionExit0(CNCMDATAINTERFACE_CONSTRUCTL_DUP01); + } + +CNcmDataInterface::~CNcmDataInterface() + { + OstTraceFunctionEntry0(CNCMDATAINTERFACE_CNCMDATAINTERFACE_DUP01); + Cancel(); + + delete iReceiver; + delete iSender; + OstTraceFunctionExit0(CNCMDATAINTERFACE_CNCMDATAINTERFACE_DUP02); + } + +/** + Start the NCM data channel + */ +void CNcmDataInterface::Start() + { + OstTraceFunctionEntry0(CNCMDATAINTERFACE_START); + if (!iStarted) + { + iReceiver->Start(); + iSender->Start(); + iStarted = ETrue; + } + OstTraceFunctionExit0(CNCMDATAINTERFACE_START_DUP01); + } + +/** + Stop the NCM data channel + */ +void CNcmDataInterface::Stop() + { + OstTraceFunctionEntry0(CNCMDATAINTERFACE_STOP); + if (iStarted) + { + iReceiver->Stop(); + iSender->Stop(); + iStarted = EFalse; + + //after stop(). + if (KAltSetting1 == iAltSetting) + { + + iAltSetting = KAltSetting0; + } + } + OstTraceFunctionExit0(CNCMDATAINTERFACE_STOP_DUP01); + } + +/** + Send packet data from upper link to NCM host + */ +TInt CNcmDataInterface::Send(RMBufChain &aPacket) + { + const TInt KContinue = 1; + const TInt KStop = 0; + + TInt ret = iSender->Send(aPacket); + if (ret == KErrNone) + { + return KContinue; + } + else if (ret == KErrNotReady || ret == KErrCongestion) + { + return KStop; + } + else + { + iEngine.DataError(ret); + return KStop; + } + } + +/** + * Acitve this AO to monitor the LDD's alt-setting changes. + */ +void CNcmDataInterface::ActivateLdd() + { + TInt alt = 0; + TInt ret = KErrNone; + + ret = iLdd.GetAlternateSetting(alt); + OstTraceExt2(TRACE_NORMAL, CNCMDATAINTERFACE_ACTIVATELDD, "ActivateLDD:alt=%d, ret=%d", alt, ret); + + if (KErrNone == ret) + { + if (iAltSetting == alt) + { + iLdd.AlternateDeviceStatusNotify(iStatus, iIfState); + SetActive(); + } + else + { + TRequestStatus* status = &iStatus; + iStatus = KRequestPending; + iIfState = KUsbAlternateSetting | alt; + SetActive(); + + User::RequestComplete(status, KErrNone); + } + } + else + { + //It's possible when Usb Device Status is not configed. + iLdd.AlternateDeviceStatusNotify(iStatus, iIfState); + SetActive(); + } + } + +void CNcmDataInterface::RunL() + { + OstTraceExt2(TRACE_NORMAL, CNCMDATAINTERFACE_RUNL, "State=%x, status=%d", iIfState, iStatus.Int()); + + if (KErrNone == iStatus.Int()) + { + iLdd.AlternateDeviceStatusNotify(iStatus, iIfState); + SetActive(); + + if (iIfState & KUsbAlternateSetting) + { + TInt ret = KErrNone; + iAltSetting = iIfState & ~KUsbAlternateSetting; + + if (KAltSetting1 == iAltSetting) + { + ret = iLdd.StartNextOutAlternateSetting(ETrue); + if (KAltSetting1 == ret) + { + iEngine.HandleAltSetting(iAltSetting); + } + else + { + iEngine.DataError(ret); + } + } + else + { + iEngine.HandleAltSetting(iAltSetting); + ret = iLdd.StartNextOutAlternateSetting(ETrue); + if (KAltSetting0 != ret) + { + iEngine.DataError(ret); + } + } + } + } + else + { + iEngine.DataError(iStatus.Int()); + } + } + +/** + * AO cancel. + */ +void CNcmDataInterface::DoCancel() + { + iLdd.AlternateDeviceStatusNotifyCancel(); + } + + +/** + * Get Connection Speed. (NB. Upstream's is the same as downstream's). + */ +TInt CNcmDataInterface::GetSpeed(TInt& aSpeed) + { + const TInt KHighSpeed = 480 * 1024 * 1024; + const TInt KFullSpeed = 12 * 1024 * 1024; + + if (iLdd.CurrentlyUsingHighSpeed()) + { + aSpeed = KHighSpeed; + } + else + { + aSpeed = KFullSpeed; + } + + return KErrNone; + + } +/** + * Get Ntb Input Size. + */ +TInt CNcmDataInterface::GetNtbInputSize(TDes8& aSize) + { + const TUint KNtbIntputSizeLength = 4; + aSize.SetLength(KNtbIntputSizeLength); + LittleEndian::Put32(&aSize[0], iSender->NtbInMaxSize()); + return KErrNone; + } + +/** + * Set Ntb Input Size. + */ +TInt CNcmDataInterface::SetNtbInputSize(TDesC8& aSize) + { + TInt size = LittleEndian::Get32(aSize.Ptr()); + return iSender->SetNtbInMaxSize(size, KAltSetting0==iAltSetting); + } + +/** + * Get Ntb Parameter. + */ +TInt CNcmDataInterface::GetNtbParam(TDes8& aParamBuf) + { + TNcmNtbInParam param; + + iSender->GetNtbParam(param); + + const TUint32 KNtbParamLength = 0x001C; + const TUint32 KNtbFormat = 0x0001; + const TUint KNtbParamLengthOffset = 0; //0 + const TUint KNtbFormatOffset = KNtbParamLengthOffset + 2; //2 + const TUint KNtbInMaxSizeOffset = KNtbFormatOffset + 2; //4 + const TUint KNtbInDivisorOffset = KNtbInMaxSizeOffset + 4; //8 + const TUint KNtbInPayloadRemainderOffset = KNtbInDivisorOffset + 2; //10 + const TUint KNtbInAlignmentOffset = KNtbInPayloadRemainderOffset + 2;//12 + const TUint KNtbOutMaxSizeOffset = KNtbInAlignmentOffset + 4; //16 + const TUint KNtbOutDivisorOffset = KNtbOutMaxSizeOffset + 4; //20 + const TUint KNtbOutPayloadRemainderOffset = KNtbOutDivisorOffset + 2;//22 + const TUint KNtbOutAlignmentOffset = KNtbOutPayloadRemainderOffset + 2;//24 + + aParamBuf.FillZ(KNtbParamLength); + LittleEndian::Put16(&aParamBuf[KNtbParamLengthOffset], KNtbParamLength); + LittleEndian::Put16(&aParamBuf[KNtbFormatOffset], KNtbFormat); + LittleEndian::Put32(&aParamBuf[KNtbInMaxSizeOffset], param.iNtbInMaxSize); + LittleEndian::Put16(&aParamBuf[KNtbInDivisorOffset], param.iNdpInDivisor); + LittleEndian::Put16(&aParamBuf[KNtbInPayloadRemainderOffset], param.iNdpInPayloadRemainder); + LittleEndian::Put16(&aParamBuf[KNtbInAlignmentOffset], param.iNdpInAlignment); + + //Tricky way: copy the Sender's parameter as the Receiver's. + LittleEndian::Put32(&aParamBuf[KNtbOutMaxSizeOffset], iReceiver->NtbOutMaxSize()); + LittleEndian::Put16(&aParamBuf[KNtbOutDivisorOffset], param.iNdpInDivisor); + LittleEndian::Put16(&aParamBuf[KNtbOutPayloadRemainderOffset], param.iNdpInPayloadRemainder); + LittleEndian::Put16(&aParamBuf[KNtbOutAlignmentOffset], param.iNdpInAlignment); + + return KErrNone; + } + +TInt CNcmDataInterface::SetInEpBufferSize(TUint aSize) + { + return iSender->SetInEpBufferSize(aSize); + } + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmdatareceiver.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmdatareceiver.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,204 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + +#ifndef __OVER_DUMMYUSBSCLDD__ +#include +#include //EEndPoint2 +#else +#include +#endif + +#include "ncmdatareceiver.h" +#include "ncmdatainterface.h" + +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "ncmdatareceiverTraces.h" +#endif + + + +#ifdef _DEBUG +_LIT(KDataReceiverPanic, "DataRcvrPanic"); +#endif + +/** +@file +@internalComponent +*/ + +/** + * Constructor + */ +CNcmDataReceiver::CNcmDataReceiver(RDevUsbcScClient& aPort, CNcmDataInterface& aParent) : + CActive(CActive::EPriorityStandard), + iPort(aPort), + iParent(aParent) + { + CActiveScheduler::Add(this); + } + +/** + * NewL to create object. + */ +CNcmDataReceiver* CNcmDataReceiver::NewL(RDevUsbcScClient& aPort, CNcmDataInterface& aParent) + { + OstTraceFunctionEntry0(CNCMDATARECEIVER_NEWL); + + CNcmDataReceiver* self = new(ELeave) CNcmDataReceiver(aPort, aParent); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + + OstTraceFunctionExit1(CNCMDATARECEIVER_NEWL_DUP01, self); + return self; + } + +void CNcmDataReceiver::ConstructL() + { + iNtbParser = CNcmNtb16Parser::NewL(*this); + } + +/** + * Destructor + */ +CNcmDataReceiver::~CNcmDataReceiver() + { + OstTraceFunctionEntry0(CNCMDATARECEIVER_CNCMDATARECEIVER_DUP01); + + Cancel(); + delete iNtbParser; + } + +/** + * Start to receive and parse the USB data. + */ +void CNcmDataReceiver::Start() + { + OstTraceFunctionEntry0(CNCMDATARECEIVER_START); + + TInt ret = iPort.OpenEndpoint(iEpIn, EEndpoint2); + if (KErrNone != ret) + { + OstTrace1(TRACE_ERROR, CNCMDATARECEIVER_START_DUP01, "OpenEndpoint error=%d", ret); + iParent.DataError(ret); + OstTraceFunctionExit0(CNCMDATARECEIVER_START_DUP02); + return; + } + ReadData(); + OstTraceFunctionExit0(CNCMDATARECEIVER_START_DUP03); + } + +/** + * Read the data packet from NCM host + */ +void CNcmDataReceiver::ReadData() + { + OstTraceFunctionEntry0(CNCMDATARECEIVER_READDATA); + + const TInt KRetryCount = 3; + TInt ret = KErrNone; + TInt errCnt = KRetryCount; + + while(errCnt) + { + ret = iEpIn.TakeBuffer(reinterpret_cast(iBuf), iBufLen, iZlp, iStatus); + if (KErrCompletion == ret) + { + errCnt = KRetryCount; + if (iBufLen > 0) + { + OstTraceExt3(TRACE_NORMAL, CNCMDATARECEIVER_READDATA_DUP02, "iBuf=%x, iBufLen=%d, iZlp=%d", (TInt)iBuf, iBufLen, iZlp); + ret = iNtbParser->Parse(iBuf, iBufLen, iZlp); + } + } + else if (KErrNone == ret || KErrEof == ret) + { + break; + } + else + { + OstTrace1(TRACE_ERROR, CNCMDATARECEIVER_READDATA_DUP03, "TakeBuffer error=%d", ret); + errCnt --; + } + } + + if (KErrNone == ret) + { + SetActive(); + } + else if (KErrEof != ret) + { + iParent.DataError(ret); + } + + OstTraceFunctionExit0(CNCMDATARECEIVER_READDATA_DUP01); + } + +/** + * Expire the Share Chunk LDD's buffer (see above TakeBuffer) + */ +void CNcmDataReceiver::ExpireBuffer(TAny* aBuf) + { + TInt ret = iEpIn.Expire(aBuf); + __ASSERT_DEBUG(KErrNone==ret, User::Panic(KDataReceiverPanic, __LINE__)); + } + +/** + * Deliver the received packet data to upper link + */ +void CNcmDataReceiver::ProcessEtherFrame(RMBufPacket& aPacket) + { + iParent.ProcessDatagram(aPacket); + } + +/** + * RunL, a state machine to read the NCM packet data from NCM host + */ +void CNcmDataReceiver::RunL() + { + if(KErrNone == iStatus.Int()) + { + ReadData(); + } + else + { + OstTrace1(TRACE_ERROR, CNCMDATARECEIVER_RUNL, "iStatus.Int()=%d", iStatus.Int()); + iParent.DataError(iStatus.Int()); + } + } + +/** + * Cancel the outgoing read request + */ +void CNcmDataReceiver::DoCancel() + { + OstTraceFunctionEntry0(CNCMDATARECEIVER_DOCANCEL); + iPort.ReadCancel(iEpIn.BufferNumber()); + } + +void CNcmDataReceiver::Stop() + { + OstTraceFunctionEntry0(CNCMDATARECEIVER_STOP); + Cancel(); + iNtbParser->Reset(); + TInt ret = iEpIn.Close(); + + OstTraceFunctionExit0(CNCMDATARECEIVER_STOP_DUP01); + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmdatasender.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmdatasender.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,439 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + + +/** +@file +@internalComponent +*/ + + +#include + +#ifndef __OVER_DUMMYUSBSCLDD__ +#include +#else +#include +#endif + +#include "ncmdatasender.h" +#include "ncmntb16builder.h" +#include "ncmdatainterface.h" +#include "ncmbuffermanager.h" +#include "ncmntbbuildsimplepolicy.h" +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "ncmdatasenderTraces.h" +#endif + + +// +//write buffer alignment value should get from share chunk LDD, current LDD has no API for this +//use a pagesize here instead +// +const TInt KAlignSize = 1024; + + +// ======== MEMBER FUNCTIONS ======== +// + +CNcmDataSender::CNcmDataSender(RDevUsbcScClient& aPort, CNcmDataInterface& aParent) : CActive(EPriorityStandard), + iPort(aPort), + iParent(aParent) + { + CActiveScheduler::Add(this); + } + +CNcmDataSender* CNcmDataSender::NewL(RDevUsbcScClient& aPort, CNcmDataInterface& aParent) + { + OstTraceFunctionEntry0( CNCMDATASENDER_NEWL_ENTRY ); + CNcmDataSender *self = new (ELeave) CNcmDataSender(aPort, aParent); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + OstTraceFunctionExit0( CNCMDATASENDER_NEWL_EXIT ); + return self; + } + +void CNcmDataSender::ConstructL() + { + + iNtbBuilder = CNcmNtb16Builder::NewL(*this); + iBufferManager = CNcmBufferManager::NewL(); + iBufferManager->SetAlignSize(KAlignSize); + iBuildPolicy = CNcmNtbBuildSimplePolicy::NewL(*iNtbBuilder); + iBuildPolicy->NtbBuilder().SetBuildPolicy(*iBuildPolicy); + iStarted = EFalse; + iStopSending = EFalse; + iIsSending = EFalse; + } + +CNcmDataSender::~CNcmDataSender() + { + Cancel(); + delete iNtbBuilder; + delete iBufferManager; + delete iBuildPolicy; + } + +// +// Start the sender +// +void CNcmDataSender::Start() + { + OstTraceFunctionEntry1( CNCMDATASENDER_START_ENTRY, this ); + if (iStarted) + { + OstTrace0( TRACE_ERROR, CNCMDATASENDER_START, "Alrealy start, return directly." ); + OstTraceFunctionExit1( CNCMDATASENDER_START_EXIT, this ); + return; + } + + if (iStopSending) + { + iParent.ResumeSending(); + iStopSending = EFalse; + } + + TInt ret = iPort.OpenEndpoint(iEpOut, EEndpoint1); + if (ret != KErrNone) + { + OstTrace1( TRACE_FATAL, CNCMDATASENDER_START1, "OpenEndpoint error %d", ret ); + iParent.DataError(ret); + OstTraceFunctionExit1( CNCMDATASENDER_START_EXIT_DUP1, this ); + return; + } + + TAny* buf = NULL; + TUint size; + ret = iEpOut.GetInBufferRange(buf, size); + if (ret != KErrNone) + { + OstTrace1( TRACE_FATAL, CNCMDATASENDER_START2, "iEpOut.GetInBufferRange failed ret=%d", ret ); + iParent.DataError(ret); + OstTraceFunctionExit1( CNCMDATASENDER_START_EXIT_DUP2, this ); + return; + } + else if (size < NtbInMaxSize()) + { + OstTrace0( TRACE_FATAL, CNCMDATASENDER_START3, "LDD buffer size is small than NTB size" ); + iParent.DataError(KErrArgument); + OstTraceFunctionExit1( CNCMDATASENDER_START_EXIT_DUP3, this ); + return; + } + OstTraceExt2( TRACE_NORMAL, CNCMDATASENDER_START4, "GetInBufferRange at 0x%x size %d", (TUint)buf, size); + + + iBufferManager->InitBufferArea(buf, size); + ret = iBufferManager->SetBufferCellSize(NtbInMaxSize()); + if (ret != KErrNone) + { + OstTrace1( TRACE_FATAL, CNCMDATASENDER_START5, "iBufferManager->SetBufferCellSize failed ret=%d", ret ); + iParent.DataError(KErrArgument); + OstTraceFunctionExit1( CNCMDATASENDER_START_EXIT_DUP4, this ); + return; + } + iBuildPolicy->UpdateBufferSize(NtbInMaxSize()); + iBuildPolicy->UpdateTotalBufferCount(iBufferManager->FreeBufferCount()); + iStarted = ETrue; + OstTraceFunctionExit1( CNCMDATASENDER_START_EXIT_DUP5, this ); + } + + +void CNcmDataSender::RunL() + { + OstTraceFunctionEntry1( CNCMDATASENDER_RUNL_ENTRY, this ); + OstTrace1( TRACE_NORMAL, CNCMDATASENDER_RUNL, "CNcmDataSender::RunL:Status=%d", iStatus.Int()); + + if(iStatus.Int() != KErrNone) + { + if (KErrCancel == iStatus.Int() ) + { + } + else + { + iParent.DataError(iStatus.Int()); + } + OstTraceFunctionExit1( CNCMDATASENDER_RUNL_EXIT, this ); + return; + } + SendNtbComplete(); + OstTraceFunctionExit1( CNCMDATASENDER_RUNL_EXIT_DUP1, this ); + } + +// +//Start a New Ntb in Builder +// + +TInt CNcmDataSender::StartNewNtb() + { + OstTraceFunctionEntry1( CNCMDATASENDER_STARTNEWNTB_ENTRY, this ); + TNcmBuffer ncmBuffer; + TInt ret = iBufferManager->GetBuffer(ncmBuffer); + if (ret == KErrNone || ret == KErrCongestion) + { + iNtbBuilder->StartNewNtb(ncmBuffer); + } + else + { + OstTrace1( TRACE_FATAL, CNCMDATASENDER_STARTNEWNTB, "iBufferManager->GetBuffer failed ret=%d", ret); + } + OstTraceFunctionExit1( CNCMDATASENDER_STARTNEWNTB_EXIT, this ); + return ret; + } + + +//add a Ethernet packet to current NTB +// + +TInt CNcmDataSender::Send(RMBufChain& aPacket) + { + OstTraceFunctionEntry1( CNCMDATASENDER_SEND_ENTRY, this ); + + if (!iStarted) + { + OstTrace0( TRACE_WARNING, CNCMDATASENDER_SEND1, "Sender is not started" ); + iStopSending = ETrue; + OstTraceFunctionExit1( CNCMDATASENDER_SEND_EXIT, this ); + return KErrNotReady; + } + + TInt ret = KErrNone; + if (!iNtbBuilder->IsNtbStarted()) + { + ret = StartNewNtb(); + if (ret != KErrNone && ret != KErrCongestion) + { + OstTraceFunctionExit1( CNCMDATASENDER_SEND_EXIT_DUP1, this ); + return ret; + } + } + + TBool isCongestion = (ret == KErrCongestion)?ETrue:EFalse; + + ret = iNtbBuilder->AppendPacket(aPacket); + + if (ret == KErrBufferFull) + { + //current NTB is full and can't add new packet, start a new NTB and insert packet to it + ret = StartNewNtb(); + if (ret == KErrNone) + { + ret = iNtbBuilder->AppendPacket(aPacket); + } + else if (ret == KErrCongestion) + { + isCongestion = ETrue; + ret = iNtbBuilder->AppendPacket(aPacket); + } + } + + if (isCongestion && ret == KErrNone) + { + OstTrace0( TRACE_NORMAL, CNCMDATASENDER_SEND2, "CNcmDataSender::Send congestion" ); + iStopSending = ETrue; + OstTraceFunctionExit1( CNCMDATASENDER_SEND_EXIT_DUP2, this ); + return KErrCongestion; + } + OstTraceFunctionExit1( CNCMDATASENDER_SEND_EXIT_DUP3, this ); + return ret; + } + +// +//Cancel the outgoing request of sending +// + +void CNcmDataSender::DoCancel() + { + OstTraceFunctionEntry1( CNCMDATASENDER_DOCANCEL_ENTRY, this ); + iPort.WriteCancel(iEpOut.BufferNumber()); + OstTraceFunctionExit1( CNCMDATASENDER_DOCANCEL_EXIT, this ); + } + +void CNcmDataSender::SendNtbPayload(TNcmBuffer& aBuf) + { + OstTraceFunctionEntry1( CNCMDATASENDER_SENDNTBPAYLOAD_ENTRY, this ); + OstTraceExt2( TRACE_NORMAL, CNCMDATASENDER_SENDNTBPAYLOAD, "SendNtbPayload:%08x, len=%d", (TUint)aBuf.iPtr, aBuf.iLen); + + if (iIsSending) + { + OstTrace0( TRACE_NORMAL, CNCMDATASENDER_SENDNTBPAYLOAD1, "SendNtbPayload: there is NTB on sending, store the buffer" ); + iTxArray.Append(aBuf); + OstTraceFunctionExit1( CNCMDATASENDER_SENDNTBPAYLOAD_EXIT, this ); + return; + } + + iSendingBuffer = aBuf; + iIsSending = ETrue; + + iStatus = KRequestPending; + TInt ret; + // + // compliant to NCM spec with Zlp case + // + if (aBuf.iLen == NtbInMaxSize()) + { + OstTrace0( TRACE_NORMAL, CNCMDATASENDER_SENDNTBPAYLOAD2, "iEpOut.WriteBuffer without zlp" ); + ret = iEpOut.WriteBuffer((TAny*)aBuf.iPtr, aBuf.iLen, EFalse, iStatus); + } + else + { + OstTrace0( TRACE_NORMAL, CNCMDATASENDER_SENDNTBPAYLOAD3, "iEpOut.WriteBuffer with zlp" ); + ret = iEpOut.WriteBuffer((TAny*)aBuf.iPtr, aBuf.iLen, ETrue, iStatus); + } + if (ret == KErrNone && !IsActive()) + { + SetActive(); + } + else + { + OstTrace1( TRACE_FATAL, CNCMDATASENDER_SENDNTBPAYLOAD4, "iEpOut.WriteBuffer failed ret = %d", ret); + iParent.DataError(ret); + } + OstTraceFunctionExit1( CNCMDATASENDER_SENDNTBPAYLOAD_EXIT_DUP1, this ); + return; + } + +// +// called when a sender request is completed by LDD +// + +void CNcmDataSender::SendNtbComplete() + { + OstTraceFunctionEntry1( CNCMDATASENDER_SENDNTBCOMPLETE_ENTRY, this ); + + iIsSending = EFalse; + iBufferManager->FreeBuffer(iSendingBuffer); + iBuildPolicy->UpdateFreeBufferCount(iBufferManager->FreeBufferCount()); + + // when buffer manage has enough buffers, notify networking to stop flow control + if (!iBufferManager->IsCongestion() && iStopSending) + { + iStopSending = EFalse; + iParent.ResumeSending(); + } + if (iTxArray.Count()) + { + OstTrace0( TRACE_NORMAL, CNCMDATASENDER_SENDNTBCOMPLETE3, "send NTB in sending queue" ); + SendNtbPayload(iTxArray[0]); + iTxArray.Remove(0); + } + OstTraceFunctionExit1( CNCMDATASENDER_SENDNTBCOMPLETE_EXIT, this ); + } + +void CNcmDataSender::GetNtbParam(TNcmNtbInParam& aParam) + { + iNtbBuilder->GetNtbParam(aParam); + } + +TInt CNcmDataSender::SetNtbInMaxSize(TInt aSize, TBool aIsAltZero) + { + OstTraceFunctionEntry1( CNCMDATASENDER_SETNTBINMAXSIZE_ENTRY, this ); + OstTrace1( TRACE_NORMAL, CNCMDATASENDER_SETNTBINMAXSIZE, "SetNtbInMaxSize %d", aSize); + + TInt ret = iNtbBuilder->SetNtbInMaxSize(aSize); + if (ret != KErrNone) + { + OstTrace1( TRACE_FATAL, CNCMDATASENDER_SETNTBINMAXSIZE1, "iNtbBuilder->SetNtbInMaxSize failed %d", ret); + OstTraceFunctionExit1( CNCMDATASENDER_SETNTBINMAXSIZE_EXIT, this ); + return ret; + } + +// +//if sender is not started, endpoint buffer is not setup, so does not call SetBufferCellSize +// + if (!iStarted) + { + OstTraceFunctionExit1( CNCMDATASENDER_SETNTBINMAXSIZE_EXIT_DUP1, this ); + return KErrNone; + } + +// if not in alternate setting 0, there may be data in buffer, so doesn't reset buffers. + if (!aIsAltZero) + { + OstTraceFunctionExit1( CNCMDATASENDER_SETNTBINMAXSIZE_EXIT_DUP2, this ); + return KErrNone; + } + + OstTraceFunctionExit1( CNCMDATASENDER_SETNTBINMAXSIZE_EXIT_DUP4, this ); + return KErrNone; + } + + +void CNcmDataSender::Stop() + { + OstTraceFunctionEntry1( CNCMDATASENDER_STOP_ENTRY, this ); + Cancel(); + iBuildPolicy->Cancel(); + iNtbBuilder->Reset(); + iTxArray.Reset(); + iEpOut.Close(); + iStopSending = EFalse; + iStarted = EFalse; + iIsSending = EFalse; + OstTraceFunctionExit1( CNCMDATASENDER_STOP_EXIT, this ); + } + +// call this function to notify the buffer size of In endpoint buffer size of LDD and adjust the MaxInNtbSize supported +// report to host + +TInt CNcmDataSender::SetInEpBufferSize(TUint aSize) + { + OstTraceFunctionEntry1( CNCMDATASENDER_SETINEPBUFFERSIZE_ENTRY, this ); + TInt ret = KErrNone; + TUint size = aSize; + + OstTrace1( TRACE_NORMAL, CNCMDATASENDER_SETINEPBUFFERSIZE, "SetInEpBufferSize aSize=%d", aSize); + + +// the buffer may not aligned, so decrease max possible offset due to aligment + size -= KAlignSize-1; + TInt ntbSize = iNtbBuilder->NtbInMaxSize(); + TInt cellSize = KAlignSize; + TInt minNtbInMaxSize = iNtbBuilder->MinNtbInMaxSize(); + TInt count; + TBool find = EFalse; + while (ntbSize >= minNtbInMaxSize) + { + cellSize = (ntbSize+KAlignSize-1)&~(KAlignSize-1); + count = size / cellSize; + if (count < iBufferManager->RequiredBufferCount()) + { + ntbSize /= 2; + continue; + } + find = ETrue; + break; + } + + if (ntbSize == iNtbBuilder->NtbInMaxSize()) + { + ret = KErrNone; + } + else if (find) + { + ret = iNtbBuilder->SetNtbInMaxSize(cellSize); + } + else + { + ret = KErrGeneral; + } + OstTraceFunctionExit1( CNCMDATASENDER_SETINEPBUFFERSIZE_EXIT, this ); + return ret; + } + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmengine.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmengine.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,506 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include "ncmengine.h" +#include "ncmpktdrv.h" +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "ncmengineTraces.h" +#endif + + + +const TUint8 KDataIFAltSet1 = 1; + +/** +Create a new CNcmControlEngine object. +*/ +CNcmEngine *CNcmEngine::NewL(CNcmPktDrv& aPktDrv) + { + OstTraceFunctionEntry0( CNCMENGINE_NEWL ); + + CNcmEngine *self=new (ELeave) CNcmEngine(aPktDrv); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + + OstTraceFunctionExit1( CNCMENGINE_NEWL_DUP01, self ); + return self; + } + +/** +Create the CNcmEngine object. +*/ +void CNcmEngine::ConstructL() + { + OstTraceFunctionEntry0( CNCMENGINE_CONSTRUCTL ); + + RandomMacAddressL(iSymbianMacAddress); + + iSharedStateManager = CNcmSharedStateManager::NewL(*this); + iDataInterface = CNcmDataInterface::NewL(*this, iDataLdd); + iCommInterface = CNcmCommunicationInterface::NewL(*this, iCommLdd); + + OstTraceFunctionExit0( CNCMENGINE_CONSTRUCTL_DUP01 ); + } + +/** +Constructor. +@param aPktDrv Pointer to NCM Packet Driver. +*/ +CNcmEngine::CNcmEngine(CNcmPktDrv& aPktDrv) : CActive(CActive::EPriorityStandard), + iPktDrv(aPktDrv) + { + CActiveScheduler::Add(this); + } + +/** +Destructor. +*/ +CNcmEngine::~CNcmEngine() + { + OstTraceFunctionEntry0( CNCMENGINE_CNCMENGINE_DUP10 ); + + //double check for possibly missed by PktDrvBase's StopInterface; + Stop(); + + delete iCommInterface; + delete iDataInterface; + delete iSharedStateManager; + + OstTraceFunctionExit0( CNCMENGINE_CNCMENGINE_DUP11 ); + } + +/** + * Initialize the DataInterface's and CommInterface's LDD instances with transferred handle. + */ +void CNcmEngine::InitLddL(const RMessagePtr2& aMsg) + { + OstTraceFunctionEntry0( CNCMENGINE_INITLDDL ); + + const TUint KCommLddOffset = 0; //0 + const TUint KCommChunkOffset = KCommLddOffset + 1; //1 + const TUint KDataLddOffset = KCommChunkOffset + 1; //2 + const TUint KDataChunkOffset = KDataLddOffset + 1; //3 + const TUint KHandlesInStackCount = 3; + + User::LeaveIfError(iCommLdd.Open(aMsg, KCommLddOffset, EOwnerProcess)); + CleanupClosePushL(iCommLdd); + + RChunk* chunk; + //Get the Ldd's RChunk, but don't own it. + User::LeaveIfError(iCommLdd.GetDataTransferChunk(chunk)); + + User::LeaveIfError(chunk->Open(aMsg, KCommChunkOffset, FALSE, EOwnerProcess)); + CleanupClosePushL(*chunk); + + User::LeaveIfError(iDataLdd.Open(aMsg, KDataLddOffset, EOwnerProcess)); + CleanupClosePushL(iDataLdd); + + User::LeaveIfError(iDataLdd.GetDataTransferChunk(chunk)); + User::LeaveIfError(chunk->Open(aMsg, KDataChunkOffset, FALSE, EOwnerProcess)); + + CleanupStack::Pop(KHandlesInStackCount); + + OstTraceFunctionExit0( CNCMENGINE_INITLDDL_DUP01 ); + } + +/** + * Start Engine to initialize LDD, and start monitor LDD device status changes. + */ +TInt CNcmEngine::Start(RMessagePtr2& aMsg) + { + OstTraceFunctionEntry0( CNCMENGINE_START ); + + __ASSERT_DEBUG(iEngineState == ENcmStateUninitialized, User::Panic(KEnginePanic, __LINE__)); + if (ENcmStateUninitialized != iEngineState) + { + OstTraceFunctionExitExt( CNCMENGINE_START_DUP10, this, KErrNotSupported ); + return KErrNotSupported; + } + + TRAPD(err, InitLddL(aMsg)); + if (KErrNone != err) + { + OstTrace1( TRACE_ERROR, CNCMENGINE_START_DUP01, "InitLdd return error=%d;", err ); + return err; + } + + if (KErrNone != iCommLdd.DeviceStatus(reinterpret_cast(iDeviceState))) + { + RChunk* commChunk = NULL; + RChunk* dataChunk = NULL; + iCommLdd.GetDataTransferChunk(commChunk); + iDataLdd.GetDataTransferChunk(dataChunk); + commChunk->Close(); + dataChunk->Close(); + iDataLdd.Close(); + iCommLdd.Close(); + OstTraceFunctionExitExt( CNCMENGINE_START_DUP11, this, KErrNotReady ); + return KErrNotReady; + } + OstTrace1( TRACE_NORMAL, CNCMENGINE_START_DUP02, "CommLdd DeviceStatus=%d", iDeviceState); + + if (EUsbcDeviceStateConfigured == iDeviceState) + { + iStatus = KRequestPending; + TRequestStatus* reportStatus = &iStatus; + SetActive(); + + User::RequestComplete(reportStatus, KErrNone); + } + else + { + iCommLdd.AlternateDeviceStatusNotify(iStatus, iDeviceState); + SetActive(); + } + + iDataInterface->ActivateLdd(); + + iEngineState = ENcmStateStarting; + + OstTraceFunctionExitExt( CNCMENGINE_START_DUP12, this, KErrNone ); + return KErrNone; + } + +/** + * Monitor the USB device State, Start/Stop Communication/Data Interface + */ +void CNcmEngine::RunL() + { + OstTraceExt2( TRACE_NORMAL, CNCMENGINE_RUNL, "iDeviceState=%d;iStatus.Int()=%d", iDeviceState, iStatus.Int() ); + + if (KErrNone == iStatus.Int()) + { + iCommLdd.AlternateDeviceStatusNotify(iStatus, iDeviceState); + SetActive(); + } + else + { + iPktDrv.FatalErrorNotification(iStatus.Int()); + Stop(); + return; + } + + switch(iDeviceState) + { + case EUsbcDeviceStateConfigured: + if (!iCommInterface->IsStarted()) + { + iCommInterface->Start(); + + StartDataLayer(); + } + break; + + case EUsbcDeviceStateSuspended: + StopDataLayer(); + break; + + case EUsbcDeviceStateUndefined: + + iDataLdd.ResetAltSetting(); + StopDataLayer(); + if (iCommInterface->IsStarted()) + { + iCommInterface->Stop(); + } + break; + + default: + //do nothing here. + break; + } + } + +/** +AO cancel +*/ +void CNcmEngine::DoCancel() + { + OstTraceFunctionEntry0( CNCMENGINE_DOCANCEL ); + iCommLdd.AlternateDeviceStatusNotifyCancel(); + } + +/** + * Fatal error report from Control Channel + */ +void CNcmEngine::ControlError(TInt aError) + { + OstTrace1( TRACE_NORMAL, CNCMENGINE_CONTROLERROR, "aError=%d", aError ); + + iPktDrv.FatalErrorNotification(aError); + Stop(); + } + +/** + *Enter the started state. + */ +void CNcmEngine::DoNcmStarted() + { + OstTraceFunctionEntry0( CNCMENGINE_DONCMSTARTED ); + + iDataInterface->Start(); + TInt speed = 0; + iDataInterface->GetSpeed(speed); + + iCommInterface->SendSpeedNotification(speed, speed); + iCommInterface->SendConnectionNotification(ETrue); + + __ASSERT_DEBUG(((iEngineState==ENcmStateStarting) || (iEngineState==ENcmStatePaused)), User::Panic(KEnginePanic, __LINE__)); + iEngineState = ENcmStateStarted; + iSharedStateManager->NotifyNcmConnected(); + } + +/** + *Start the data channel + */ +void CNcmEngine::StartDataLayer() + { + OstTraceFunctionEntry0( CNCMENGINE_STARTDATALAYER ); + + if (iDataInterface->IsStarted()) + { + OstTrace0( TRACE_WARNING, CNCMENGINE_STARTDATALAYER_DUP01, "The DataIf has already been started!" ); + + __ASSERT_DEBUG(0, User::Panic(KEnginePanic, __LINE__)); + return; + } + + if (KDataIFAltSet1 != iDataInterface->AltSetting()) + { + OstTrace0( TRACE_NORMAL, CNCMENGINE_STARTDATALAYER_DUP02, "Data Interface is not ready to start; it's fine!!" ); + return; + } + + TInt ret = iSharedStateManager->NotifyDhcpProvisionRequested(); + if (KErrAlreadyExists == ret) + { + DoNcmStarted(); + } + else + { + if (KErrNone != ret) + { + //minus error when try to set IPBearerCoexistence P&S key. just continue... + OstTrace1( TRACE_WARNING, CNCMENGINE_STARTDATALAYER_DUP03, "SharedStateManager issued dhcp request return error:;ret=%d", ret ); + } + + iCommInterface->SendConnectionNotification(EFalse); + + if (ENcmStatePaused == iEngineState) + { + iEngineState = ENcmStateStarting; + } + } + } + +/** + *Stop the data channel + */ +void CNcmEngine::StopDataLayer() + { + OstTraceFunctionEntry0( CNCMENGINE_STOPDATALAYER ); + + if (iDataInterface->IsStarted()) + { + __ASSERT_DEBUG((iEngineState==ENcmStateStarted), User::Panic(KEnginePanic, __LINE__)); + iEngineState = ENcmStatePaused; + iSharedStateManager->NotifyNcmDisconnected(KErrNone); + + iDataInterface->Stop(); + } + } + +/** + *Stop NCM + */ +void CNcmEngine::Stop() + { + OstTraceFunctionEntry0( CNCMENGINE_STOP ); + + if (ENcmStateStarted == iEngineState || + ENcmStatePaused == iEngineState || + ENcmStateStarting == iEngineState) + { + Cancel(); + iDataInterface->Cancel(); + + if (iDataInterface->IsStarted()) + { + iDataInterface->Stop(); + } + + if (iCommInterface->IsStarted()) + { + iCommInterface->Stop(); + } + + RChunk* commChunk = NULL; + RChunk* dataChunk = NULL; + + iCommLdd.GetDataTransferChunk(commChunk); + iDataLdd.GetDataTransferChunk(dataChunk); + commChunk->Close(); + dataChunk->Close(); + iDataLdd.Close(); + iCommLdd.Close(); + } + + if (ENcmStateStarted == iEngineState || + ENcmStateStarting == iEngineState) + { + iSharedStateManager->NotifyNcmDisconnected(KErrNone); + } + iEngineState = ENcmStateStopped; + } + +/** + * Send the ethernet frame to USB Host. +*/ +TInt CNcmEngine::Send(RMBufChain &aPacket) + { + OstTraceExt2( TRACE_NORMAL, CNCMENGINE_SEND, "aPacket=%x;aPacket.Length()=%d", ( TUint )&( aPacket ), aPacket.Length() ); + + return iDataInterface->Send(aPacket); + } + +/** +Get the Hardware address of the LAN Device +@return MAC address of the Symbian device +*/ +TUint8* CNcmEngine::InterfaceAddress() + { + OstTraceExt3( TRACE_NORMAL, CNCMENGINE_INTERFACEADDRESS, "Local MAC is 02:00:00:%02X:%02X:%02X.", iSymbianMacAddress[3], iSymbianMacAddress[4], iSymbianMacAddress[5]); + return static_cast(&iSymbianMacAddress[0]); + } + +void CNcmEngine::RandomMacAddressL(TNcmMacAddress& aMacAddress) + { + OstTrace1( TRACE_NORMAL, CNCMENGINE_RANDOMMACADDRESSL, "aMacAddress=%x", ( TUint )&( aMacAddress ) ); + //random the MAC address + aMacAddress.SetLength(KEthernetAddressLength); + const TUint KOUILength = 3; + const TInt len = KEthernetAddressLength - KOUILength; + + TPtr8 ptr(&aMacAddress[0] + KOUILength, len, len); + TRandom::RandomL(ptr); + + //mark it as locally managed address + aMacAddress[0] = 0x02; + aMacAddress[1] = 0x00; + aMacAddress[2] = 0x00; + } + +/** MControlInterfaceObserver + * Set Ntb Input Size. See NCM1.0 spec. + */ +TInt CNcmEngine::HandleSetNtbInputSize(TDes8& aSize) + { + OstTraceFunctionEntry1( CNCMENGINE_HANDLESETNTBINPUTSIZE, ( TUint )&( aSize ) ); + + return iDataInterface->SetNtbInputSize(aSize); + } + +/** + * Set Ntb Parameters. See NCM1.0 spec. + */ +TInt CNcmEngine::HandleGetNtbParam(TDes8& aReturnBuf) + { + OstTraceFunctionEntry1( CNCMENGINE_HANDLEGETNTBPARAM, ( TUint )&( aReturnBuf ) ); + + return iDataInterface->GetNtbParam(aReturnBuf); + } + +/** + * Get Ntb Input Size. See NCM1.0 spec. + */ +TInt CNcmEngine::HandleGetNtbInputSize(TDes8& aSize) + { + OstTraceFunctionEntry1( CNCMENGINE_HANDLEGETNTBINPUTSIZE, ( TUint )&( aSize ) ); + + return iDataInterface->GetNtbInputSize(aSize); + } + +/** + * Enable NCM connection by setting NCM speed & connection, when notified that DHCP Provison done successfully. + */ +void CNcmEngine::NotifyDhcpStarted() + { + OstTraceFunctionEntry0( CNCMENGINE_NOTIFYDHCPSTARTED ); + __ASSERT_DEBUG(!iDataInterface->IsStarted(), User::Panic(KEnginePanic, __LINE__)); + if (iDeviceState != EUsbcDeviceStateConfigured || KDataIFAltSet1 != iDataInterface->AltSetting()) + { + OstTraceExt2( TRACE_WARNING, CNCMENGINE_NOTIFYDHCPSTARTED_DUP01, "NotifyDhcpStarted comes so later;iDeviceState=%d;iDataInterface->AltSetting()=%d", iDeviceState, iDataInterface->AltSetting() ); + return; + } + + DoNcmStarted(); + } + +/** + *Upwards notify + * @param aPacket A Reference to a buffer holding data. + */ +void CNcmEngine::ProcessReceivedDatagram(RMBufPacket& aPacket) + { + OstTraceExt2( TRACE_NORMAL, CNCMENGINE_PROCESSRECEIVEDDATAGRAM, "aPacket=%x;aPacket.Length()=%d", ( TUint )&( aPacket ), aPacket.Length() ); + iPktDrv.ReceiveEthFrame(aPacket); + } + +/** + * Resume Sending is a notification call into NIF from the lower layer telling the NIF that a + * previous sending congestion situation has been cleared and it can accept more downstack data. + */ +void CNcmEngine::ResumeSending() + { + OstTraceFunctionEntry0( CNCMENGINE_RESUMESENDING ); + iPktDrv.ResumeSending(); + } + +/** + * Error report from Data Channel + */ +void CNcmEngine::DataError(TInt aError) + { + OstTrace1( TRACE_ERROR, CNCMENGINE_DATAERROR, "CNcmEngine::DataError;aError=%d", aError ); + + iPktDrv.FatalErrorNotification(aError); + } +/** + * Handle the data interface alt setting changes. + */ +void CNcmEngine::HandleAltSetting(TInt aIfAltSet) + { + OstTraceExt3( TRACE_NORMAL, CNCMENGINE_HANDLEALTSETTING, "CNcmEngine::HandleAltSetting;aIfAltSet=%d;iDataInterface->AltSetting()=%d;iDeviceState=%d", aIfAltSet, iDataInterface->AltSetting(), (TInt) iDeviceState ); + + if (KDataIFAltSet1 == aIfAltSet) + { + StartDataLayer(); + } + else + { + StopDataLayer(); + } + } + +TInt CNcmEngine::SetInEpBufferSize(TUint aSize) + { + OstTrace1( TRACE_NORMAL, CNCMENGINE_SETINEPBUFFERSIZE, "aSize=%u", aSize ); + return iDataInterface->SetInEpBufferSize(aSize); + } + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmnotificationdescriptor.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmnotificationdescriptor.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,77 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* implementation for NCM notification message class +* +*/ + + +/** +@file +@internalComponent +*/ + + +#include +#include "ncmnotificationdescriptor.h" + + +// ======== MEMBER FUNCTIONS ======== +// + + +// +// This function packs the TUSBNotificationNetworkConnection class into a descriptor with +// the correct byte alignment for transmission on the USB bus. + + +TDes8& TUSBNotificationNetworkConnection::Des() + { + TUint index = 0; + + iBuffer.SetLength(KUSBNotificationNetworkConnection); + iBuffer[index++] = iRequestType; + iBuffer[index++] = iNotification; + LittleEndian::Put16(&iBuffer[index], iValue); + index += 2; + LittleEndian::Put16(&iBuffer[index], iIndex); + index += 2; + LittleEndian::Put16(&iBuffer[index], iLength); + return iBuffer; + } + +// +//This function packs the TUSBNotificationConnectionSpeedChange class into a descriptor with +//the correct byte alignment for transmission on the USB bus. + +TDes8& TUSBNotificationConnectionSpeedChange::Des() + { + TUint index = 0; + + iBuffer.SetLength(KUSBNotificationConnectionSpeedChange); + iBuffer[index++] = iRequestType; + iBuffer[index++] = iNotification; + LittleEndian::Put16(&iBuffer[index], iValue); + index += 2; + LittleEndian::Put16(&iBuffer[index], iIndex); + index += 2; + LittleEndian::Put16(&iBuffer[index], iLength); + index += 2; + LittleEndian::Put32(&iBuffer[index], iUSBitRate); + index += 4; + LittleEndian::Put32(&iBuffer[index], iDSBitRate); + return iBuffer; + } + + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmntb16builder.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmntb16builder.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,269 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* implementation for NTB16 build class +* +*/ + + + +/** +@file +@internalComponent +*/ + + + +#include +#ifndef __OVER_DUMMYUSBSCLDD__ +#include +#else +#include +#endif +#include "ncmntb16builder.h" +#include "ncmntbbuildpolicy.h" +#include "ncmpktdrvcommon.h" +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "ncmntb16builderTraces.h" +#endif + + +const TInt KNtb16InMaxSize = 32768; + + +const TInt KNth16Signature = 0x484D434E; +const TInt KNth16Length = 0x0C; + +const TInt KNdp16Signature = 0x304D434E; +const TInt KNdp16HeaderSize = 8; +const TInt KNdp16EntrySize = 4; +const TInt KNdp16InDivisor = 4; +const TInt KNdp16InRemainder = 0; +const TInt KNdp16InAlignment = 4; + + +// ======== MEMBER FUNCTIONS ======== +// + + +CNcmNtbBuilder* CNcmNtb16Builder::NewL(MNcmNtbBuildObserver& aObserver) + { + OstTraceFunctionEntry1( CNCMNTB16BUILDER_NEWL_ENTRY, ( TUint )&( aObserver ) ); + CNcmNtb16Builder *self=new (ELeave) CNcmNtb16Builder(aObserver); + self->ConstructL(); + OstTraceFunctionExit0( CNCMNTB16BUILDER_NEWL_EXIT ); + return self; + } + +CNcmNtb16Builder::CNcmNtb16Builder(MNcmNtbBuildObserver& aObserver) + : CNcmNtbBuilder(aObserver) + { + } + +void CNcmNtb16Builder::ConstructL() + { + iNtbInMaxSize = KNtb16InMaxSize; + iNdpInDivisor = KNdp16InDivisor; + iNdpInPayloadRemainder = KNdp16InRemainder; + iNdpInAlignment = KNdp16InAlignment; + } + +CNcmNtb16Builder::~CNcmNtb16Builder() + { + iPacketsArray.Reset(); + } + + +TInt CNcmNtb16Builder::SetNtbInMaxSize(TInt aSize) + { + OstTraceFunctionEntry1( CNCMNTB16BUILDER_SETNTBINMAXSIZE_ENTRY, this ); + if (aSize > KNtb16InMaxSize || aSize < MinNtbInMaxSize()) + { + OstTraceFunctionExit1( CNCMNTB16BUILDER_SETNTBINMAXSIZE_EXIT, this ); + return KErrArgument; + } + iNtbInMaxSize = aSize; + OstTraceFunctionExit1( CNCMNTB_DUP116BUILDER_SETNTBINMAXSIZE_EXIT, this ); + return KErrNone; + } + +// +//construct NTB header information +// + +void CNcmNtb16Builder::BuildNtbHeader() + { + OstTraceFunctionEntry1( CNCMNTB16BUILDER_BUILDNTBHEADER_ENTRY, this ); + TPtr8 buf(iBuffer.iPtr, KNth16Length, KNth16Length); + TInt pos = 0; + LittleEndian::Put32(&buf[pos], KNth16Signature); + pos += 4; + LittleEndian::Put16(&buf[pos], KNth16Length); + pos += 2; + LittleEndian::Put16(&buf[pos], iSequence); + pos += 2; + LittleEndian::Put32(&buf[pos], iNdpOffset+iNdpLength); + pos += 2; + LittleEndian::Put16(&buf[pos], iNdpOffset); + pos += 2; + + OstTraceExt3( TRACE_NORMAL, CNCMNTB16BUILDER_BUILDNTBHEADER, "CNcmNtb16Builder::BuildNtbHeader %d %d %d", iSequence, iNdpOffset, iNdpOffset+iNdpLength ); + OstTraceFunctionExit1( CNCMNTB16BUILDER_BUILDNTBHEADER_EXIT, this ); + } + + +// +//construct NDP inforamtion +// + +void CNcmNtb16Builder::BuildNdp() + { + OstTraceFunctionEntry1( CNCMNTB16BUILDER_BUILDNDP_ENTRY, this ); + TPtr8 buf(iBuffer.iPtr+iNdpOffset, iNdpLength, iNdpLength); + TInt pos = 0; + + LittleEndian::Put32(&buf[pos], KNdp16Signature); + pos += 4; + LittleEndian::Put16(&buf[pos], iNdpLength); + pos += 2; + LittleEndian::Put16(&buf[pos], 0); + pos += 2; + + TInt i; + for (i=0 ; i iBuffer.iMaxLength || newNdpLen+newNdpOffset > iNtbInMaxSize) + { + CompleteNtbBuild(); + OstTraceFunctionExit1( CNCMNTB16BUILDER_APPENDPACKET_EXIT, this ); + return KErrBufferFull; + } + + TPtr8 ptr((TUint8*)(alignedDataOffset+iBuffer.iPtr), len, len); + aPacket.CopyOut(ptr); + TDatagramEntry entry; + entry.iWDatagramIndex = alignedDataOffset; + entry.iWDatagramLength = len; + iPacketsArray.Append(entry); + iNdpOffset = newNdpOffset; + iNdpLength = newNdpLen; + iDatagramOffset = newDatagramOffset; + if (iBuildPolicy) + { + iBuildPolicy->UpdateNtb(iNdpOffset+iNdpLength); + } + OstTraceFunctionExit1( CNCMNTB_DUP116BUILDER_APPENDPACKET_EXIT, this ); + return KErrNone; + } + +// +//complete a NTB, is called by buildpolicy or current NTB is full. +// + + +void CNcmNtb16Builder::CompleteNtbBuild() + { + OstTraceFunctionEntry1( CNCMNTB16BUILDER_COMPLETENTBBUILD_ENTRY, this ); + + BuildNtbHeader(); + BuildNdp(); + iBuffer.iLen = iNdpOffset+iNdpLength; + SendNtbPayload(); + CNcmNtbBuilder::CompleteNtbBuild(); + OstTraceFunctionExit1( CNCMNTB16BUILDER_COMPLETENTBBUILD_EXIT, this ); + } + + +// +//start a new ntb, is called by sender +// + +void CNcmNtb16Builder::StartNewNtb(const TNcmBuffer& aBuffer) + { + OstTraceFunctionEntry1( CNCMNTB16BUILDER_STARTNEWNTB_ENTRY, this ); + + iBuffer = aBuffer; + iNdpOffset = 0; + iNdpLength = 0; + iPacketsArray.Reset(); + iDatagramOffset = KNth16Length; +// NDP must align with iNdpInAlignment, refer to NCM spec Table 6-3 for detail + iNdpOffset = (iDatagramOffset+iNdpInAlignment-1)&~(iNdpInAlignment-1); +// must have a zero entry in the end of NDP, so the NDP length is added with KNdp16EntrySize + iNdpLength = KNdp16HeaderSize + KNdp16EntrySize; + + if (iBuildPolicy) + { + iBuildPolicy->StartNewNtb(); + } + CNcmNtbBuilder::StartNewNtb(aBuffer); + OstTraceFunctionExit1( CNCMNTB16BUILDER_STARTNEWNTB_EXIT, this ); + } + + +void CNcmNtb16Builder::Reset() + { + OstTraceFunctionEntry1( CNCMNTB16BUILDER_RESET_ENTRY, this ); + iNtbInMaxSize = KNtb16InMaxSize; + iNdpOffset = 0; + iNdpLength = 0; + iDatagramOffset = 0; + iPacketsArray.Reset(); + CNcmNtbBuilder::Reset(); + OstTraceFunctionExit1( CNCMNTB16BUILDER_RESET_EXIT, this ); + } + + + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmntbbuilder.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmntbbuilder.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,78 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* implementation for NTB build base class +* +*/ + + +/** +@file +@internalComponent +*/ + + + +#include "ncmntbbuilder.h" +#include "ncmdatasender.h" +#include "ncmpktdrvcommon.h" +#include "ncmntbbuildpolicy.h" + + +// ======== MEMBER FUNCTIONS ======== +// + + +CNcmNtbBuilder::CNcmNtbBuilder(MNcmNtbBuildObserver& aObserver) + : iObserver(aObserver) + { + iSequence = 0xFFFF; + } + +CNcmNtbBuilder::~CNcmNtbBuilder() + { + } + +void CNcmNtbBuilder::SendNtbPayload() + { + iObserver.SendNtbPayload(iBuffer); + } + +void CNcmNtbBuilder::StartNewNtb(const TNcmBuffer& aBuffer) + { + iSequence++; + iBuffer = aBuffer; + iNtbStarted = ETrue; + } + +void CNcmNtbBuilder::GetNtbParam(TNcmNtbInParam& aParam) + { + aParam.iNtbInMaxSize = iNtbInMaxSize; + aParam.iNdpInDivisor = iNdpInDivisor; + aParam.iNdpInPayloadRemainder = iNdpInPayloadRemainder; + aParam.iNdpInAlignment = iNdpInAlignment; + } + +void CNcmNtbBuilder::Reset() + { + iNtbStarted = EFalse; + iSequence = 0xFFFF; + } + +void CNcmNtbBuilder::CompleteNtbBuild() + { + iNtbStarted = EFalse; + iBuildPolicy->CompleteNtbBuild(); + } + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmntbbuildpolicy.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmntbbuildpolicy.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* implementation for NTB build policy base class +* +*/ + + +/** +@file +@internalComponent +*/ + + +#include "ncmntbbuildpolicy.h" + +// ======== MEMBER FUNCTIONS ======== +// + +CNcmNtbBuildPolicy::CNcmNtbBuildPolicy(CNcmNtbBuilder& aBuilder) + : CActive(CActive::EPriorityStandard), iNtbBuilder(aBuilder) + { + } + +CNcmNtbBuildPolicy::~CNcmNtbBuildPolicy() + { + } + + + + + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmntbbuildsimplepolicy.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmntbbuildsimplepolicy.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,160 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* implementation for simple NTB build policy +* +*/ + + +/** +@file +@internalComponent +*/ + + +#include "ncmntbbuildsimplepolicy.h" +#include "ncmntbbuilder.h" +#include "ncmpktdrvcommon.h" +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "ncmntbbuildsimplepolicyTraces.h" +#endif + + + +const TInt KMaxPacketsOfNtb = 10; +const TInt KMaxPacketDelay = 1000; +const TInt KMinFreeBuffers = 5; + + +_LIT(KSimPolicyPanic, "CNcmNtbBuildSimplePolicy"); +const TInt KTimerError = 1; + + +// ======== MEMBER FUNCTIONS ======== +// + + +CNcmNtbBuildPolicy* CNcmNtbBuildSimplePolicy::NewL(CNcmNtbBuilder& aNtbBuilder) + { + OstTraceFunctionEntry1( CNCMNTBBUILDSIMPLEPOLICY_NEWL_ENTRY, ( TUint )&( aNtbBuilder ) ); + CNcmNtbBuildSimplePolicy *self=new (ELeave) CNcmNtbBuildSimplePolicy(aNtbBuilder); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(); + OstTraceFunctionExit0( CNCMNTBBUILDSIMPLEPOLICY_NEWL_EXIT ); + return self; + } + +CNcmNtbBuildSimplePolicy::CNcmNtbBuildSimplePolicy(CNcmNtbBuilder& aNtbBuilder) + : CNcmNtbBuildPolicy(aNtbBuilder) + { + CActiveScheduler::Add(this); + } + +CNcmNtbBuildSimplePolicy::~CNcmNtbBuildSimplePolicy() + { + OstTraceFunctionEntry1( CNCMNTBBUILDSIMPLEPOLICY_CNCMNTBBUILDSIMPLEPOLICY_ENTRY, this ); + Cancel(); + iTimer.Close(); + OstTraceFunctionExit1( CNCMNTBBUILDSIMPLEPOLICY_CNCMNTBBUILDSIMPLEPOLICY_EXIT, this ); + } + +void CNcmNtbBuildSimplePolicy::DoCancel() + { + OstTraceFunctionEntry1( CNCMNTBBUILDSIMPLEPOLICY_DOCANCEL_ENTRY, this ); + iTimer.Cancel(); + iPacketsCount = 0; + OstTraceFunctionExit1( CNCMNTBBUILDSIMPLEPOLICY_DOCANCEL_EXIT, this ); + } + + +void CNcmNtbBuildSimplePolicy::ConstructL() + { + User::LeaveIfError(iTimer.CreateLocal()); + } + +void CNcmNtbBuildSimplePolicy::RunL() + { + OstTraceFunctionEntry1( CNCMNTBBUILDSIMPLEPOLICY_RUNL_ENTRY, this ); + OstTrace1( TRACE_NORMAL, CNCMNTBBUILDSIMPLEPOLICY_RUNL, "CNcmNtbBuildSimplePolicy::RunL Status=%d", iStatus.Int() ); + + if(iStatus.Int() != KErrNone) + { + User::Panic(KSimPolicyPanic, KTimerError); + OstTraceFunctionExit1( CNCMNTBBUILDSIMPLEPOLICY_RUNL_EXIT, this ); + return; + } + + if (iPacketsCount > 0) + { + iNtbBuilder.CompleteNtbBuild(); + } + OstTraceFunctionExit1( CNCMNTBBUILDSIMPLEPOLICY_RUNL_EXIT_DUP1, this ); + } + +void CNcmNtbBuildSimplePolicy::CompleteNtbBuild() + { + OstTraceFunctionEntry1( CNCMNTBBUILDSIMPLEPOLICY_COMPLETENTBBUILD_ENTRY, this ); + + Cancel(); + iPacketsCount = 0; + OstTraceFunctionExit1( CNCMNTBBUILDSIMPLEPOLICY_COMPLETENTBBUILD_EXIT, this ); + } + + +void CNcmNtbBuildSimplePolicy::StartNewNtb() + { + OstTraceFunctionEntry1( CNCMNTBBUILDSIMPLEPOLICY_STARTNEWNTB_ENTRY, this ); + OstTraceFunctionExit1( CNCMNTBBUILDSIMPLEPOLICY_STARTNEWNTB_EXIT, this ); + } + +void CNcmNtbBuildSimplePolicy::UpdateNtb(TInt aSize) + { + OstTraceFunctionEntryExt( CNCMNTBBUILDSIMPLEPOLICY_UPDATENTB_ENTRY, this ); + OstTrace1( TRACE_NORMAL, CNCMNTBBUILDSIMPLEPOLICY_UPDATENTB, "CNcmNtbBuildSimplePolicy::UpdateNtb aSize=%d", aSize ); + + if (iPacketsCount == 0) + { + iStatus = KRequestPending; + iTimer.After(iStatus, KMaxPacketDelay); + SetActive(); + } + + if (KMaxPacketsOfNtb <= ++iPacketsCount && aSize >= iBufferSize/2) + { + iNtbBuilder.CompleteNtbBuild(); + } + else if (iFreeBufferCount >= KMinFreeBuffers && aSize >= iBufferSize/8) + { + iNtbBuilder.CompleteNtbBuild(); + } + OstTraceFunctionExit1( CNCMNTBBUILDSIMPLEPOLICY_UPDATENTB_EXIT, this ); + } + +void CNcmNtbBuildSimplePolicy::UpdateBufferSize(TInt aSize) + { + iBufferSize = aSize; + } + +void CNcmNtbBuildSimplePolicy::UpdateFreeBufferCount(TInt aCount) + { + iFreeBufferCount = aCount; + } + +void CNcmNtbBuildSimplePolicy::UpdateTotalBufferCount(TInt aCount) + { + iTotalBufferCount = aCount; + } + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmntbparser.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmntbparser.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,629 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include "ncmntbparser.h" +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "ncmntbparserTraces.h" +#endif + + +#ifdef _DEBUG +_LIT(KNTBParsePanic, "NtbParsePanic"); +#endif + + +const TUint KNcmNtb16HeadLength = sizeof(TNcmNth16); +const TUint KNcmNtb16NdpMiniLength = sizeof(TNcmNdp16); +const TUint KNcmNtb16NdpDatagramOffset = 4 + 2 + 2;//dwSignature + wLength + wNextNdpIndex; +const TUint KNcmNtb16NdpDatagramLength = 2 + 2;//wDatagram0Index + wDatagram0Length; +const TUint KNcmNtb16NdpDatagramLenOffset = 2;//wDatagram0Index +const TUint8 KLetterN = 0x4E; +const TUint8 KLetterC = 0x43; +const TUint8 KLetterM = 0x4D; +const TUint8 KLetterH = 0x48; +const TUint8 KLetter0 = 0x30; + +CNcmNtb16Parser* CNcmNtb16Parser::NewL(MNcmNdpFrameObserver& aObserver) + { + return new(ELeave)CNcmNtb16Parser(aObserver); + } + +CNcmNtb16Parser::~CNcmNtb16Parser() + { + Reset(); + } + +CNcmNtbParser::~CNcmNtbParser() + { + } + +TUint CNcmNtb16Parser::NtbOutMaxSize() const + { + return iMaxSize; + } + +/** + * Parsing a buffer as NCM Ntb16 data format. + * NOTE: this function has "memory" because the Shared Chunk LDD can't guarantee the buffer as a whole USB Transfer. + * this function tries to parse the buffer as much as possible and save the buffer if it can't be parsed exactly. + * @param [in] aBuf, the buffer to be parsed, which can't be released(free) until the ExpireBuffer() is called. + * @param [in] aBufLen, the buffer length. + * @param [in] aZlp, flag of Zlp used to indicate a USB transfer completion. + * @return KErrNone, no error occurs during parsing this buffer. + * other, Symbian system error code. + */ +TInt CNcmNtb16Parser::Parse(const TUint8* aBuf, TInt aBufLen, TBool aZlp) + { + TInt ret = KErrNone; + TInt dataLen = iDataLen + aBufLen - (iQueLen==0?iDataOffset:0); + OstTraceExt3( TRACE_NORMAL, CNCMNTB16PARSER_PARSE, "==>Parse:aBuf=0x%08x, aBufLen=%d, aZlp=%d.", (TUint)aBuf, aBufLen, aZlp); + OstTraceExt5( TRACE_NORMAL, CNCMNTB16PARSER_PARSE_DUP01, " iState=%d, dataLen=%d, iDataLen=%d, iQueLen=%d, iDataOffset=%d", iState, dataLen, iDataLen, iQueLen, iDataOffset); + + //Zlp comes so late, so updated here. + if (aZlp) + { + iNth.wBlockLength = dataLen; + __ASSERT_DEBUG(iNth.wBlockLength < iMaxSize, User::Panic(KNTBParsePanic, __LINE__)); + } + + switch(iState) + { + //iNth is not ready. + case ENcmNtb16ParseStateUninitialized: + if (dataLen >= KNcmNtb16HeadLength) + { + ret = ParseNcmNtb16Header(aBuf, aBufLen, aZlp); + } + else + { + ret = QueueBuf(aBuf, aBufLen); + } + break; + + //iNth is ready, but iNdp not. + case ENcmNtb16ParseStateNdpParsing: + if (dataLen >= iNth.wNdpIndex + KNcmNtb16NdpMiniLength) + { + ret = ParseNcmNtb16Ndp(aBuf, aBufLen); + } + else + { + ret = QueueBuf(aBuf, aBufLen); + } + break; + + //iNdp is ready, try to seek datagram. + case ENcmNtb16ParseStateNdpSeeking: + ret = ParseNcmNtb16NdpDatagram(aBuf, aBufLen); + break; + + //iNth is ready, ignore the remaining bytes for errors or NULL NDP. + case ENcmNtb16ParseStateSkipBytes: + __ASSERT_DEBUG(0==iQueLen, User::Panic(KNTBParsePanic, __LINE__)); + __ASSERT_DEBUG(0==iDataLen||0==iDataOffset, User::Panic(KNTBParsePanic, __LINE__)); + //buffer contains the following NTB data. + if (dataLen > iNth.wBlockLength) + { + iDataOffset += iNth.wBlockLength - iDataLen; + Reset(); + ret = Parse(aBuf, aBufLen); + } + else if (dataLen == iNth.wBlockLength) + { + Reset(); + iDataOffset = 0; + iObserver.ExpireBuffer((TAny*)aBuf); + } + else + { + iDataLen += aBufLen; + iObserver.ExpireBuffer((TAny*)aBuf); + } + break; + + default: + __ASSERT_DEBUG(0, User::Panic(KNTBParsePanic, __LINE__)); + break; + } + OstTraceExt3(TRACE_NORMAL, CNCMNTB16PARSER_PARSE_DUP02, "<==Parse:iDataLen=%d, iQueLen=%d, iDataOffset=%d.", (TInt)iDataLen, iQueLen, iDataOffset); + + return ret; + } + +//Reset the parser to clear the queue and indicators. +void CNcmNtb16Parser::Reset(TInt aType) + { + if (ENcmNtb16TypeResetAll == aType) + { + iState = ENcmNtb16ParseStateUninitialized; + iDataLen = 0; + } + + if (iQueLen > 0) + { + for (TInt i = 0; i < iQueLen; i++) + { + iObserver.ExpireBuffer((TAny*)(iBufQueue[i].Ptr())); + } + iBufQueue.Reset(); + iQueLen = 0; + iDataOffset = 0; + } + } + +//Search NCM header:"NCMH". +TInt CNcmNtb16Parser::SearchNcmHead(const TUint8* aBuf, TInt aBufLen) + { + TInt dataLen = aBufLen + (iQueLen==0?(0-iDataOffset):iDataLen); + const TInt KNotFound = 0; + const TInt KShrinkQueue = 1; + const TInt KFound = 2; + TInt ii = 1;//first one(0) has already tested(not matched) before entering this function. + TInt ret = KNotFound; + + const TUint KMatchLastOne = 1; + const TUint KMatchLastTwo = 2; + const TUint KMatchLastThree = 3; + + while (KNotFound == ret) + { + while (ii < dataLen && KLetterN != DataTUint8(ii, aBuf, aBufLen)) + { + ii++; + } + if (ii == dataLen) + { + Reset(); + iDataOffset = 0; + iObserver.ExpireBuffer((TAny*)aBuf); + return KErrCorrupt; + } + else if (ii + KMatchLastOne == dataLen)//last one matched 'N' + { + ret = KShrinkQueue; + } + else if (ii + KMatchLastTwo == dataLen) + { + if (KLetterC == DataTUint8(ii+KMatchLastOne, aBuf, aBufLen))//'NC' matched. + { + ret = KShrinkQueue; + } + else + { + ii++; + } + } + else if (ii + KMatchLastThree == dataLen) + { + if (KLetterC != DataTUint8(ii+KMatchLastOne, aBuf, aBufLen)) + { + ii++; + } + else if (KLetterM != DataTUint8(ii+KMatchLastTwo, aBuf, aBufLen)) + { + ii += 2; + } + else //'NCM' matched. + { + ret = KShrinkQueue; + } + } + else + { + if (KLetterC != DataTUint8(ii+KMatchLastOne, aBuf, aBufLen)) + { + ii ++; + } + else if (KLetterM != DataTUint8(ii+KMatchLastTwo, aBuf, aBufLen)) + { + ii += 2; + } + else if (KLetterH != DataTUint8(ii+KMatchLastThree, aBuf, aBufLen)) + { + ii += 3; + } + else + { + ret = KFound; + } + } + } + + OstTraceExt5(TRACE_NORMAL, CNCMNTB16PARSER_SEARCHNCMHEAD, "Search:ii=%d, dataLen=%d,iDataLen=%d,iDataOffset=%d,iQueLen=%d", ii, dataLen, iDataLen, iDataOffset, iQueLen); + + switch(ret) + { + case KShrinkQueue: + { + TInt err = QueueBuf(aBuf, aBufLen); + if (KErrNone != err) + { + return err; + } + } + //fall-through!! no break!! + case KFound: + { + TInt newOffset = ii + iDataOffset; + iDataLen += (iDataLen!=0?iDataOffset:0); + while(iQueLen && iBufQueue[0].Length() <= newOffset) + { + iObserver.ExpireBuffer((TAny*)iBufQueue[0].Ptr()); + newOffset -= iBufQueue[0].Length(); + iDataLen -= iBufQueue[0].Length(); + iBufQueue.Remove(0); + iQueLen--; + } + iDataOffset = newOffset; + iDataLen -= (iQueLen!=0?iDataOffset:0); + __ASSERT_DEBUG((iQueLen==0&&iDataLen==0)||(iQueLen>0&&iDataLen>0), User::Panic(KNTBParsePanic, __LINE__)); + if (KFound == ret) + { + return Parse(aBuf, aBufLen); + } + } + break; + + default: + __ASSERT_DEBUG(0, User::Panic(KNTBParsePanic, __LINE__)); + break; + } + + return KErrNone; + } + +TInt CNcmNtb16Parser::ParseNcmNtb16Header(const TUint8* aBuf, TInt aBufLen, TBool aZlp) + { + const TUint KLetterNOffset = 0; //0 + const TUint KLetterCOffset = KLetterNOffset + 1; //1 + const TUint KLetterMOffset = KLetterCOffset + 1; //2 + const TUint KLetterHOffset = KLetterMOffset + 1; //3 + const TUint KHeaderLengthOffset = KLetterHOffset + 1;//4 + const TUint KSequeceOffset = KHeaderLengthOffset + 2;//6 + const TUint KBlockLengthOffset = KSequeceOffset + 2;//8 + const TUint KNdpIndexOffset = KBlockLengthOffset + 2;//10 + //NCMH + if (KLetterN != DataTUint8(KLetterNOffset, aBuf, aBufLen) || + KLetterC != DataTUint8(KLetterCOffset, aBuf, aBufLen) || + KLetterM != DataTUint8(KLetterMOffset, aBuf, aBufLen) || + KLetterH != DataTUint8(KLetterHOffset, aBuf, aBufLen)) + { + //NOT a valid NTB header signature. Try to search NCMH in the buffer... + OstTrace0(TRACE_ERROR, CNCMNTB16PARSER_PARSENCMNTB16HEADER, "BAD error, missed NCMH!!"); + return SearchNcmHead(aBuf, aBufLen); + } + +#ifdef _DEBUG + iNth.wHeaderLength = DataTUint16(KHeaderLengthOffset, aBuf, aBufLen); + iNth.wSequence = DataTUint16(KSequeceOffset, aBuf, aBufLen); + //keep silence for release. not critical error. + __ASSERT_DEBUG(iNth.wHeaderLength == 0xC, User::Panic(KNTBParsePanic, __LINE__)); +#endif + +#ifdef _DEBUG + OstTrace1(TRACE_NORMAL, CNCMNTB16PARSER_PARSENCMNTB16HEADER_DUP01, "iNth.wBlockLength=%d", DataTUint16(KBlockLengthOffset, aBuf, aBufLen)); +#endif + + //using Zlp first. + if (aZlp) + { + iNth.wBlockLength = iDataLen + aBufLen - (iQueLen==0?iDataOffset:0); + __ASSERT_DEBUG(iNth.wBlockLength < iMaxSize, User::Panic(KNTBParsePanic, __LINE__)); + } + else + { + iNth.wBlockLength = DataTUint16(KBlockLengthOffset, aBuf, aBufLen); + if (0 == iNth.wBlockLength) + { + iNth.wBlockLength = iMaxSize; + } + } + iNth.wNdpIndex = DataTUint16(KNdpIndexOffset, aBuf, aBufLen); + +#ifdef _DEBUG + iNth.Dump(); +#endif + + if ((iNth.wNdpIndex >= 0xC) && + (iNth.wNdpIndex + KNcmNtb16NdpMiniLength <= iNth.wBlockLength)) + { + iState = ENcmNtb16ParseStateNdpParsing; + } + else //underflow or overflow + { + Reset(ENcmNtb16TypeResetQueue); + iState = ENcmNtb16ParseStateSkipBytes; + } + + return Parse(aBuf, aBufLen); + } + +TInt CNcmNtb16Parser::ParseNcmNtb16Ndp(const TUint8* aBuf, TInt aBufLen) + { + const TUint KLetterNOffset = 0; //0 + const TUint KLetterCOffset = KLetterNOffset + 1; //1 + const TUint KLetterMOffset = KLetterCOffset + 1; //2 + const TUint KLetterZeroOffset = KLetterMOffset + 1; //3 + const TUint KLengthOffset = KLetterZeroOffset + 1;//4 + + //NCM0 + if (KLetterN != DataTUint8(iNth.wNdpIndex + KLetterNOffset, aBuf, aBufLen) || + KLetterC != DataTUint8(iNth.wNdpIndex+KLetterCOffset, aBuf, aBufLen) || + KLetterM != DataTUint8(iNth.wNdpIndex+KLetterMOffset, aBuf, aBufLen) || + KLetter0 != DataTUint8(iNth.wNdpIndex+KLetterZeroOffset, aBuf, aBufLen)) + { + //Not valid NDP! Skip this NTB. + Reset(ENcmNtb16TypeResetQueue); + iState = ENcmNtb16ParseStateSkipBytes; + return Parse(aBuf, aBufLen); + } + + iNdp.wLength = DataTUint16(iNth.wNdpIndex+KLengthOffset, aBuf, aBufLen); + if (iNdp.wLength < 0x10) + { + //Not valid ndp header, Skip this NTB. + Reset(ENcmNtb16TypeResetQueue); + iState = ENcmNtb16ParseStateSkipBytes; + return Parse(aBuf, aBufLen); + } + iNdpBound = iNth.wNdpIndex + iNdp.wLength; + +#ifdef _DEBUG + if (iNdpBound > iNth.wBlockLength) + { + //warning: overflow.. + } + const TUint KNextNdpIndexOffset = KLengthOffset + 2;//6 + iNdp.wNextNdpIndex = DataTUint16(iNth.wNdpIndex + KNextNdpIndexOffset, aBuf, aBufLen); + __ASSERT_DEBUG(iNdp.wNextNdpIndex==0, User::Panic(KNTBParsePanic, __LINE__)); + + iNdp.Dump(); +#endif + + iNdpDataOffset = iNth.wNdpIndex + KNcmNtb16NdpDatagramOffset; + iState = ENcmNtb16ParseStateNdpSeeking; + return Parse(aBuf, aBufLen); + } + +//parse NdpDatagram +TInt CNcmNtb16Parser::ParseNcmNtb16NdpDatagram(const TUint8* aBuf, TInt aBufLen) + { + TInt dataLen = aBufLen + (iQueLen==0?(0-iDataOffset):iDataLen); + TInt ret = KErrNone; + OstTraceExt3(TRACE_NORMAL, CNCMNTB16PARSER_PARSENCMNTB16NDPDATAGRAM, "ParseNcmNtb16NdpDatagram:iNdpState=%d, iDataLen=%d, dataLen=%d", iNdpState, iDataLen, dataLen); + + switch(iNdpState) + { + case ENcmNtb16ParseNdpStateUninitialized: + { + TUint datagramBound = iNdpDataOffset+ KNcmNtb16NdpDatagramLength; + if (iNdpDataOffset >= iNdpBound || datagramBound > iNth.wBlockLength) + { + //finish this NTB. + Reset(ENcmNtb16TypeResetQueue); + iState = ENcmNtb16ParseStateSkipBytes; + ret = Parse(aBuf, aBufLen); + } + else if (datagramBound <= dataLen) + { + iDatagramIndex = DataTUint16(iNdpDataOffset, aBuf, aBufLen); + iDatagramLength = DataTUint16(iNdpDataOffset+KNcmNtb16NdpDatagramLenOffset, aBuf, aBufLen); + OstTraceExt2(TRACE_NORMAL, CNCMNTB16PARSER_PARSENCMNTB16NDPDATAGRAM_DUP01, "Index=%d, Length=%d", iDatagramIndex, iDatagramLength); + // NULL NDP; + if (iDatagramIndex == 0 || iDatagramLength == 0) + { + Reset(ENcmNtb16TypeResetQueue); + iState = ENcmNtb16ParseStateSkipBytes; + ret = Parse(aBuf, aBufLen); + } + else if (iDatagramIndex + iDatagramLength <= iNth.wBlockLength) + { + TRAPD(err, iPacket.CreateL(iDatagramLength)); + if (KErrNone == err) + { + iNdpState = ENcmNtb16ParseNdpStateDatagramed; + ret = ParseNcmNtb16NdpDatagram(aBuf, aBufLen); + } + else + { + iPacket.Free(); + + iNdpDataOffset += KNcmNtb16NdpDatagramLength;//skip this ethernet frame, do nothing else. + ret = ParseNcmNtb16NdpDatagram(aBuf, aBufLen); + } + + } + else + { + //skip this datagram because of overflow. + iNdpDataOffset += KNcmNtb16NdpDatagramLength; + ret = ParseNcmNtb16NdpDatagram(aBuf, aBufLen); + } + } + else + { + ret = QueueBuf(aBuf, aBufLen); + } + } + break; + + case ENcmNtb16ParseNdpStateDatagramed: + ret = DataPacket(aBuf, aBufLen); + if (KErrCompletion == ret) + { + iPacket.Pack(); + iObserver.ProcessEtherFrame(iPacket); + + iNdpDataOffset += KNcmNtb16NdpDatagramLength; + iNdpState = ENcmNtb16ParseNdpStateUninitialized; + ret = ParseNcmNtb16NdpDatagram(aBuf, aBufLen); + } + break; + } + + return ret; + } + +//queue buffer. +TInt CNcmNtb16Parser::QueueBuf(const TUint8* aBuf, TInt aBufLen) + { + __ASSERT_DEBUG(iQueLen==0?(iDataLen==0):ETrue, User::Panic(KNTBParsePanic, __LINE__)); + TPtrC8 ptr(aBuf, aBufLen); + TInt ret = iBufQueue.Append(ptr); + if(KErrNone != ret) + { + OstTrace1(TRACE_ERROR, CNCMNTB16PARSER_QUEUEBUF, "Append Queue Error: ret=%d!!", ret); + Reset(); + return ret; + } + iDataLen += aBufLen - (iQueLen==0?iDataOffset:0); + iQueLen ++; + return KErrNone; + } + +TUint8 CNcmNtb16Parser::DataTUint8(TUint aOffset, const TUint8* aBuf, TInt aBufLen) + { + if (0 == iQueLen) + { + return aBuf[iDataOffset + aOffset]; + } + else if (iDataLen <= aOffset) + { + return aBuf[aOffset - iDataLen]; + } + else + { + TInt i = 1; + TPtrC8* pPtr = &iBufQueue[0]; + TUint totalOffset = pPtr->Length() - iDataOffset; + while(totalOffset <= aOffset) + { + pPtr = &iBufQueue[i]; + totalOffset += pPtr->Length(); + i++; + __ASSERT_DEBUG(i<=iQueLen, User::Panic(KNTBParsePanic, __LINE__)); + } + return pPtr->Ptr()[pPtr->Length() + aOffset - totalOffset]; + } + } + +TUint16 CNcmNtb16Parser::DataTUint16(TUint aOffset, const TUint8* aBuf, TInt aBufLen) + { + if (0 == iQueLen) + { + return LittleEndian::Get16(aBuf + aOffset + iDataOffset); + } + else if (iDataLen <= aOffset) + { + return LittleEndian::Get16(aBuf + aOffset - iDataLen); + } + else + { + TUint16 ret = 0; + TInt i = 1; + TPtrC8* pPtr = &iBufQueue[0]; + TUint totalOffset = pPtr->Length() - iDataOffset; + + while(totalOffset <= aOffset) + { + pPtr = &iBufQueue[i]; + totalOffset += pPtr->Length(); + i++; + __ASSERT_DEBUG(i<=iQueLen, User::Panic(KNTBParsePanic, __LINE__)); + } + ret = pPtr->Ptr()[pPtr->Length() + aOffset - totalOffset]; + if (totalOffset > aOffset + 1) + { + ret += ((pPtr->Ptr()[pPtr->Length() + aOffset - totalOffset + 1])<<8)&0xFF00; + } + else if (i < iQueLen) + { + pPtr = &iBufQueue[i]; + ret += ((pPtr->Ptr()[0])<<8)&0xFF00; + } + else + { + ret += (aBuf[0]<<8)&0xFF00; + } + + return ret; + } + } + +TInt CNcmNtb16Parser::DataPacket(const TUint8* aBuf, TInt aBufLen) + { + TInt dataLen = aBufLen + (iQueLen==0?(0-iDataOffset):iDataLen); + OstTraceExt5(TRACE_NORMAL, CNCMNTB16PARSER_DATAPACKET, "DataPacket:dataLen=%d, index=%d, len=%d, iDataLen=%d, iDataOffset=%d", dataLen, iDatagramIndex, iDatagramLength, iDataLen, iDataOffset); + if (dataLen < iDatagramIndex + iDatagramLength) + { + return QueueBuf(aBuf, aBufLen); + } + + if (0 == iQueLen) + { + iPacket.CopyIn(TPtrC8(aBuf + iDatagramIndex + iDataOffset, iDatagramLength)); + } + else if (iDataLen <= iDatagramIndex) + { + iPacket.CopyIn(TPtrC8(aBuf + iDatagramIndex - iDataLen, iDatagramLength)); + } + else + { + TInt i = 1; + TPtrC8* pPtr = &iBufQueue[0]; + TUint totalOffset = pPtr->Length() - iDataOffset; + + while (totalOffset <= iDatagramIndex) + { + pPtr = &iBufQueue[i]; + totalOffset += pPtr->Length(); + i++; + __ASSERT_DEBUG(i<=iQueLen, User::Panic(KNTBParsePanic, __LINE__)); + } + if (totalOffset >= iDatagramIndex + iDatagramLength) + { + iPacket.CopyIn(TPtrC8(pPtr->Ptr() + pPtr->Length() + iDatagramIndex - totalOffset, iDatagramLength)); + } + else + { + TInt len = totalOffset - iDatagramIndex; + iPacket.CopyIn(TPtrC8(pPtr->Ptr() + pPtr->Length() + iDatagramIndex - totalOffset, len)); + + while(i < iQueLen && iBufQueue[i].Length() + len <= iDatagramLength) + { + iPacket.CopyIn(iBufQueue[i], len); + len += iBufQueue[i].Length(); + i++; + } + + if (len < iDatagramLength) + { + if (i < iQueLen) + { + iPacket.CopyIn(TPtrC8(iBufQueue[i].Ptr(), iDatagramLength-len), len); + } + else + { + iPacket.CopyIn(TPtrC8(aBuf, iDatagramLength - len), len); + } + } + } + } + + return KErrCompletion; + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmpktdrv.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmpktdrv.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,273 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include "ncmpktdrv.h" + +#include "ncmengine.h" +#include "ncmserver.h" +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "ncmpktdrvTraces.h" +#endif + + +/** +Constructor. Packet Driver object. +*/ +CNcmPktDrv::CNcmPktDrv(CPktDrvFactory& aFactory) : CPktDrvBase(aFactory) + { + } + +/** +Destructor. +*/ +CNcmPktDrv::~CNcmPktDrv() + { + delete iNcmServer; + delete iEngine; + } + +/** +Construction of the CNcmDrvBase object +@param aParent Pointer to the CLANLinkCommon class. +*/ +void CNcmPktDrv::ConstructL(CLANLinkCommon* aParent) + { + OstTraceFunctionEntry0(CNCMPKTDRV_CONSTRUCTL); + + iParent = aParent; + iEngine = CNcmEngine::NewL(*this); + iNcmServer = CNcmServer::NewL(*iEngine); + } + +/** +Call to LDD or subordinate object to start/initialise the Physical device +*/ +TInt CNcmPktDrv::StartInterface() + { + OstTraceFunctionEntry0(CNCMPKTDRV_STARTINTERFACE); + + TRAPD(err, iParent->FoundMACAddrL()); + if (KErrNone != err) + { + return err; + } + + OstTrace0(TRACE_NORMAL, CNCMPKTDRV_STARTINTERFACE_DUP02, "CNcmPktDrv, calling LinkLayerUp"); + iParent->LinkLayerUp(); + OstTraceFunctionExit0(CNCMPKTDRV_STARTINTERFACE_DUP01); + return err; + } + +/** +Call to LDD or subordinate object to stop/de-initialise the Physical device +*/ +TInt CNcmPktDrv::StopInterface() + { + OstTraceFunctionEntry0(CNCMPKTDRV_STOPINTERFACE); + + iEngine->Stop(); + + return KErrNone; + } + +/** +Call to LDD or subordinate object to reset/re-initialise the Physical device +*/ +TInt CNcmPktDrv::ResetInterface() + { + return KErrNone; + } + +/** +EtherII MAC layer comments say we should free the packet buffer +RMBuf could contain a chain so get into a contiguous buffer +@param aPacket Reference to a chain of data buffers to be passed to the line. +@return 0 Tells the higher layer to send no more data. + 1 Tells higher layer that it can send more data. +*/ +TInt CNcmPktDrv::Send(RMBufChain &aPacket) + { + TInt error = iEngine->Send(aPacket); + aPacket.Free(); + + return error; + } + +/** +Read the Available data. +@param aBuffer A Reference to a buffer holding data. +*/ +void CNcmPktDrv::ReceiveEthFrame(RMBufPacket& aPacket) + { + iParent->Process(aPacket); + } + +/** +Resume Sending is a notification call into NIF from the lower layer telling the NIF that a +previous sending congestion situation has been cleared and it can accept more downstack data. +*/ +void CNcmPktDrv::ResumeSending() + { + iParent->ResumeSending(); + } + +/** +Call to LDD or subordinate object to set the receive mode of the LAN Device +@param aMode The mode to be set for the LAN Device. +@return KErrNotSupported LAN Device does not support. +*/ +TInt CNcmPktDrv::SetRxMode(TRxMode /*aMode*/) + { + return KErrNotSupported; + } + +/** +Call to LDD or subordinate object to Get the receive mode of the LAN Device +@return KErrNotSupported LAN Device does not support. +*/ +TInt CNcmPktDrv::GetRxMode() const + { + return KErrNotSupported; + } + +/** +Call to LDD or subordinate object to get the Hardware address of the LAN Device +@return NULL Failure. + (NULL Terminated Binary String) The Hardware Address of the interface. LAN Device + Specific +*/ +TUint8* CNcmPktDrv::GetInterfaceAddress()const + { + return iEngine->InterfaceAddress(); + } + +/** +Call to LDD or subordinate object to set the Hardware address of the LAN Device. +@param THWAddr Address of where the Multicast list should be written. +@return KErrNone if Successful + KErrNotSupported LAN Device does not support. + Implementation specific Error Code Failure +*/ +TInt CNcmPktDrv::SetInterfaceAddress(const THWAddr&) + { + return KErrNotSupported; + } + +/** +Call to LDD or subordinate object to retrieve the Multicast List from the LAN Device +@param aAddr Address of where the Multicast list should be written. +@param n Output Parameter , number of Addresses written +@return KErrNone if Successful + KErrNotSupported LAN Device does not support. + Implementation specific Error Code Failure +*/ +TInt CNcmPktDrv::GetMulticastList(const THWAddr* /*aAddr*/, TInt& /*n*/) const + { + return KErrNotSupported; + } + +/** +Call to LDD or subordinate object to set the Multicast List for the LAN Device. +@param aAddr Address of where the Multicast list should be written. +@param n Output Parameter , number of Addresses written +@return KErrNone if Successful + KErrNotSupported LAN Device does not support. + Implementation specific Error Code Failure +*/ +TInt CNcmPktDrv::SetMulticastList(const THWAddr* /*aAddr*/, TInt /*n*/) + { + return KErrNotSupported; + } + +/** +Call to LDD or subordinate object to power up the LAN Device. +@return KErrNone if Successful + KErrNotSupported LAN Device does not support. + Implementation specific Error Code Failure +*/ +TInt CNcmPktDrv::InterfacePowerUp() + { + return KErrNotSupported; + } + +/** +Call to LDD or subordinate object to power down the LAN Device +@return KErrNone if Successful + KErrNotSupported LAN Device does not support. + Implementation specific Error Code Failure +*/ +TInt CNcmPktDrv::InterfacePowerDown() + { + return KErrNotSupported; + } + +/** +Call to LDD or subordinate object to suspend the LAN Device. +@return KErrNone if Successful + KErrNotSupported LAN Device does not support. + Implementation specific Error Code Failure +*/ +TInt CNcmPktDrv::InterfaceSleep() + { + return KErrNotSupported; + } + +/** +Call to LDD or subordinate object to resume the LAN Device. +@return KErrNone if Successful + KErrNotSupported LAN Device does not support. + Implementation specific Error Code Failure +*/ +TInt CNcmPktDrv::InterfaceResume() + { + return KErrNotSupported; + } + +/** +Receive notifications from agent +*/ +TInt CNcmPktDrv::Notification(enum TAgentToNifEventType aEvent, void* aInfo) + { + TInt retval = KErrNotSupported; + + return retval; + } + +/** +Receive Control() calls from agent/nifman/connection +*/ +TInt CNcmPktDrv::Control(TUint /*aLevel*/,TUint /*aName*/,TDes8& /*aOption*/, TAny* /*aSource*/) + { + return KErrNotSupported; + } + +/** +Report the progress of packet driver to NCM Class Controller for fatal error +*/ +void CNcmPktDrv::FatalErrorNotification(TInt aError) + { + iParent->IfProgress(ENcmPktDrvFatalError, aError); + } + +#ifdef __OVER_DUMMYUSBSCLDD__ +TInt CNcmPktDrv::State() const + { + return iEngine->State(); + } +#endif + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmpktdrvfactory.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmpktdrvfactory.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include "ncmpktdrvfactory.h" +#include "ncmpktdrv.h" + + +/** +@file +@internalComponent +*/ +extern "C" + { + IMPORT_C CPktDrvFactory * NewNcmPktDrvFactoryL(); ///< Force export + } + +/** +Library file is opened and this is the the first and only export. +@internalComponent +@return A pointer to CPktDrvFactory object. +*/ +EXPORT_C CPktDrvFactory* NewNcmPktDrvFactoryL() + { + return new (ELeave) CNcmPktDrvFactory; + } + +/** +Create the packet driver object +@param aParent Pointer to the parent Ethint NIF class. +@return A pointer to CPktDrvBase object. +*/ +CPktDrvBase* CNcmPktDrvFactory::NewDriverL(CLANLinkCommon* aParent) + { + CNcmPktDrv *drv = new (ELeave) CNcmPktDrv(*this); + CleanupStack::PushL(drv); + drv->ConstructL(aParent); + CleanupStack::Pop(drv); + return drv; + } + + +/** +Packet Driver version number. +@return Version number of the Packet Driver +*/ +TVersion CNcmPktDrvFactory::Version() const + { + return(TVersion(KNcmDrvMajorVersionNumber,KNcmDrvMinorVersionNumber,KNcmDrvBuildVersionNumber)); + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmsharedstatemanager.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/pktdrv/src/ncmsharedstatemanager.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,234 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#include "ncmsharedstatemanager.h" +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "ncmsharedstatemanagerTraces.h" +#endif + + + +#ifdef _DEBUG +_LIT(KPanicSharedState, "SharedStatePanic"); +#endif + +CNcmSharedStateManager* CNcmSharedStateManager::NewL(MShareStateObserver& aEngine) + { + CNcmSharedStateManager* self = new(ELeave) CNcmSharedStateManager(aEngine); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + return self; + } + +CNcmSharedStateManager::CNcmSharedStateManager(MShareStateObserver& aEngine) : CActive(CActive::EPriorityStandard), + iNotifyMsg(RMessage2()), iEngine(aEngine) + { + CActiveScheduler::Add(this); + } + + +CNcmSharedStateManager::~CNcmSharedStateManager() + { + OstTraceFunctionEntry0(CNCMSHAREDSTATEMANAGER_CNCMSHAREDSTATEMANAGER); + + Cancel(); + + iProperty.Close(); + iProperty.Delete(KKeyNcmConnectionEvent); + + delete iCoexistBearer; + OstTraceFunctionExit0(CNCMSHAREDSTATEMANAGER_CNCMSHAREDSTATEMANAGER_DUP01); + } + + +void CNcmSharedStateManager::ConstructL() + { + OstTraceFunctionEntry0(CNCMSHAREDSTATEMANAGER_CONSTRUCTL); + + TInt ccStartRequested = ENcmStartRequested; + User::LeaveIfError(RProperty::Get(KUsbmanSvrUid, KKeyNcmSharedState, ccStartRequested)); + if (ccStartRequested != ENcmStartRequested) + { + User::Leave(KErrNotReady); + } + + User::LeaveIfError(iProperty.Define(KKeyNcmConnectionEvent, RProperty::EByteArray, KAllowAllPolicy, KNetworkControlPolicy)); + User::LeaveIfError(iProperty.Attach(RProcess().SecureId(), KKeyNcmConnectionEvent, EOwnerThread)); + + iCoexistBearer = CNcmCoexistBearerWatcher::NewL(); + + iNcmState().iIapId = 0; + OstTraceFunctionExit0(CNCMSHAREDSTATEMANAGER_CONSTRUCTL_DUP01); + } + +/** +Maintains the shared state between the NCM class controller and packet driver. +*/ +void CNcmSharedStateManager::RunL() + { + TInt err = iStatus.Int(); + + OstTrace1(TRACE_NORMAL, CNCMSHAREDSTATEMANAGER_RUNL, "iStatus.Int()=%d", iStatus.Int()); + + if (KErrNone == err) + { + DoDhcpProvisionRequest(); + } + else if (KErrCancel != err) + { + NotifyNcmDisconnected(err); + } + } + +/** +Stop checking the shared state +*/ +void CNcmSharedStateManager::DoCancel() + { + iCoexistBearer->Cancel(); + } + +TInt CNcmSharedStateManager::NotifyDhcpProvisionRequested() + { + OstTraceFunctionEntry0(CNCMSHAREDSTATEMANAGER_NOTIFYDHCPPROVISIONREQUESTED); + + TInt ret = iCoexistBearer->SetIpOverUsbActive(iStatus); + + if (ret == KErrCompletion) + { + return DoDhcpProvisionRequest(); + } + else if (ret == KErrNone) + { + //notify the upper apps BTPAN is used by others. + NotifyNcmDisconnected(KErrInUse); + SetActive(); + } + else + { + NotifyNcmDisconnected(ret); + } + + OstTraceFunctionEntry0(CNCMSHAREDSTATEMANAGER_NOTIFYDHCPPROVISIONREQUESTED_DUP01); + return ret; + } + +TInt CNcmSharedStateManager::DoDhcpProvisionRequest() + { + if (iNotifyMsg.IsNull()) + { + __ASSERT_DEBUG(0, User::Panic(KPanicSharedState, __LINE__)); + + //return AlreadyExists, so that Engine can start immediately. + return KErrAlreadyExists; + } + else + { + iNotifyMsg.Complete(KErrNone); + iNotifyMsg = RMessage2(); + } + + return KErrNone; + } + + +void CNcmSharedStateManager::NotifyNcmConnected() + { + iNcmState().iState = ENcmStateConnected; + iProperty.Set(iNcmState); + } + +void CNcmSharedStateManager::NotifyNcmDisconnected(TInt aReason) + { + iNcmState().iState = ENcmStateDisconnected; + iNcmState().iErrCode = aReason; + iProperty.Set(iNcmState); + + if (iCoexistBearer->IsIpOverUsbActived()) + { + iCoexistBearer->SetIpOverUsbDeactive(); + } + else + { + Cancel(); + } + } + +TInt CNcmSharedStateManager::SetStateValue(TInt aType, TInt aValue) + { + OstTraceExt2(TRACE_NORMAL, CNCMSHAREDSTATEMANAGER_SETSTATEVALUE, "SetStateValue: type=%d, val=%d", aType, aValue); + + const TInt KTypeIapId = 0; + const TInt KTypeDhcpReturn = 1; + TInt ret = KErrNone; + switch(aType) + { + case KTypeIapId: + //don't assign more than once. + __ASSERT_DEBUG(iNcmState().iIapId==0, User::Panic(KPanicSharedState, __LINE__)); + iNcmState().iIapId = aValue; + break; + + case KTypeDhcpReturn: + if (KErrNone == aValue) + { + iEngine.NotifyDhcpStarted(); + } + else + { + OstTrace1(TRACE_WARNING, CNCMSHAREDSTATEMANAGER_SETSTATEVALUE_DUP01, "Dhcp Provision Request return error:%d", aValue); + NotifyNcmDisconnected(aValue); + } + break; + + default: + OstTraceExt2(TRACE_ERROR, CNCMSHAREDSTATEMANAGER_SETSTATEVALUE_DUP02, "unknow type:%d, value:%d", aType, aValue); + __ASSERT_DEBUG(0, User::Panic(KPanicSharedState, __LINE__)); + break; + } + + return ret; + } + +TInt CNcmSharedStateManager::RegisterNotify(const RMessage2& aMsg) + { + if (!iNotifyMsg.IsNull()) + { + return KErrInUse; + } + + iNotifyMsg = aMsg; + + return KErrNone; + } + +TInt CNcmSharedStateManager::DeRegisterNotify() + { + if (iNotifyMsg.IsNull()) + { + return KErrNotReady; + } + else + { + iNotifyMsg.Complete(KErrCancel); + iNotifyMsg = RMessage2(); + } + + return KErrNone; + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/server/group/server.mmh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/server/group/server.mmh Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,22 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +USERINCLUDE ../inc + +SOURCEPATH ../src +SOURCE ncmserver.cpp +SOURCE ncmsession.cpp diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/server/inc/ncmserver.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/server/inc/ncmserver.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** + @file + @internalComponent +*/ + +#ifndef NCMSERVER_H +#define NCMSERVER_H + +#include + +class CNcmEngine; + +NONSHARABLE_CLASS(CNcmServer) : public CPolicyServer + { +public: + static CNcmServer* NewL(CNcmEngine& aEngine); + ~CNcmServer(); + +private: + CNcmServer(CNcmEngine& aEngine); + +private: + // from CPolicyServer + CSession2* NewSessionL(const TVersion &aVersion, const RMessage2& aMessage) const; + +private: + // unowned + CNcmEngine& iNcmEngine; + }; + +#endif // NCMSERVER_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/server/inc/ncmserverconsts.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/server/inc/ncmserverconsts.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** + @file + @internalComponent +*/ + +#ifndef NCMSERVERCONSTS_H +#define NCMSERVERCONSTS_H + +#include + +_LIT(KNcmServerName, "!NcmInternalSrv"); + +/** Version numbers. */ +const TInt8 KNcmSrvMajorVersionNumber = 1; +const TInt8 KNcmSrvMinorVersionNumber = 1; +const TInt16 KNcmSrvBuildNumber = 0; + +/** IPC messages supported by the server. */ +enum TNcmIpc + { + ENcmTransferHandle = 0, + ENcmSetIapId, + ENcmSetDhcpResult, + ENcmDhcpProvisionNotify, + ENcmDhcpProvisionNotifyCancel, + ENcmTransferBufferSize, + ENcmNotSupport + }; + +/** Panic category with which the NCM server panics the client. */ +_LIT(KNcmSrvPanic,"NCMInternSrv"); + +/** Panic codes with which the NCM server panics the client. */ +enum TNcmSvrPanic + { + /** The client has sent a bad IPC message number. */ + ENcmBadNcmMessage = 0 + }; + +/** Set value to server. the value is defined by type.*/ +enum TNcmSetType + { + ENcmSetTypeIapId, + ENcmSetTypeDhcpReturn + }; + +#endif // NCMSERVERCONSTS_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/server/inc/ncmserversecuritypolicy.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/server/inc/ncmserversecuritypolicy.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,70 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** + @file + @internalComponent +*/ + +#ifndef NCMSERVERSECURITYPOLICY_H +#define NCMSERVERSECURITYPOLICY_H + +#include +#include "ncmserverconsts.h" + +/** NCM Server Security Policy Definition */ +const TInt KNcmServerRanges[] = + { + ENcmTransferHandle, /** pass */ + ENcmNotSupport, /** fail (to KMaxTInt) */ + }; + +const TUint KNcmServerRangeCount = sizeof(KNcmServerRanges) / sizeof(KNcmServerRanges[0]); + +/** Index numbers into KAcmServerElements[] */ +const TInt KPolicyPass = 0; + +/** Mapping IPCs to policy element */ +const TUint8 KNcmServerElementsIndex[KNcmServerRangeCount] = + { + KPolicyPass, /** All (valid) APIs */ + CPolicyServer::ENotSupported, /** remainder of possible IPCs */ + }; + +/** Individual policy elements */ +const CPolicyServer::TPolicyElement KNcmServerElements[] = + { + { + // These caps are those of USBSVR's process. This is the recommended + // way to check that an API is called by a specific process only. [The + // alternative would be an SID check.] + //_INIT_SECURITY_POLICY_C5(ECapabilityCommDD, ECapabilityNetworkControl, ECapabilityNetworkServices, ECapabilityLocalServices, ECapabilityProtServ), CPolicyServer::EFailClient + _INIT_SECURITY_POLICY_PASS + }, + }; + +/** Main policy */ +const CPolicyServer::TPolicy KNcmServerPolicy = + { + CPolicyServer::EAlwaysPass, /** Specifies all connect attempts should pass */ + KNcmServerRangeCount, + KNcmServerRanges, + KNcmServerElementsIndex, + KNcmServerElements, + }; + +#endif // NCMSERVERSECURITYPOLICY_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/server/inc/ncmsession.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/server/inc/ncmsession.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** + @file + @internalComponent +*/ + +#ifndef NCMSESSION_H +#define NCMSESSION_H + +#include + + +class CNcmEngine; + +NONSHARABLE_CLASS(CNcmSession) : public CSession2 + { +public: + static CNcmSession* NewL(CNcmEngine& aEngine); + ~CNcmSession(); + +private: + CNcmSession(CNcmEngine& aEngine); + +private: // from CSession2 + /** + Called when a message is received from the client. + @param aMessage Message received from the client. + */ + void ServiceL(const RMessage2& aMessage); + +private: + // unowned + CNcmEngine& iNcmEngine; + }; + +#endif // NCMSESSION_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/server/src/ncmserver.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/server/src/ncmserver.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,77 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** + @file + @internalComponent +*/ + + +#include "ncmserver.h" +#include "ncmsession.h" +#include "ncmserversecuritypolicy.h" +#include "ncmserverconsts.h" + + +CNcmServer* CNcmServer::NewL(CNcmEngine& aEngine) + { + CNcmServer* self = new(ELeave) CNcmServer(aEngine); + CleanupStack::PushL(self); + TInt err = self->Start(KNcmServerName); + // KErrAlreadyExists is a success case (c.f. transient server boilerplate + // code). + if ( err != KErrAlreadyExists ) + { + User::LeaveIfError(err); + } + CleanupStack::Pop(self); + return self; + } + +CNcmServer::~CNcmServer() + { + } + +CNcmServer::CNcmServer(CNcmEngine& aEngine) + : CPolicyServer(CActive::EPriorityStandard, KNcmServerPolicy, ESharableSessions), + iNcmEngine(aEngine) + { + } + +CSession2* CNcmServer::NewSessionL(const TVersion& aVersion, const RMessage2& aMessage) const + { + //Validate session as coming from UsbSvr + static _LIT_SECURITY_POLICY_S0(KSidPolicy, 0x101fe1db); + TBool auth = KSidPolicy.CheckPolicy(aMessage); + if(!auth) + { + User::Leave(KErrPermissionDenied); + } + + // Version number check... + TVersion v( KNcmSrvMajorVersionNumber, + KNcmSrvMinorVersionNumber, + KNcmSrvBuildNumber); + + if ( !User::QueryVersionSupported(v, aVersion) ) + { + User::Leave(KErrNotSupported); + } + + CNcmSession* sess = CNcmSession::NewL(iNcmEngine); + return sess; + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/server/src/ncmsession.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/classimplementation/ncmpktdrv/server/src/ncmsession.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,117 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** + @file + @internalComponent +*/ + +#include + +#include "ncmserverconsts.h" +#include "ncmsession.h" +#include "ncmengine.h" +#include "OstTraceDefinitions.h" +#ifdef OST_TRACE_COMPILER_IN_USE +#include "ncmsessionTraces.h" +#endif + + + +CNcmSession* CNcmSession::NewL(CNcmEngine& aEngine) + { + CNcmSession* self = new(ELeave) CNcmSession(aEngine); + return self; + } + +CNcmSession::CNcmSession(CNcmEngine& aEngine) + : iNcmEngine(aEngine) + { + } + +CNcmSession::~CNcmSession() + { + } + +void CNcmSession::ServiceL(const RMessage2& aMessage) + { + OstTraceFunctionEntry0(CNCMSESSION_SERVICEL); + + OstTraceExt3(TRACE_NORMAL,CNCMSESSION_SERVICEL_DUP01, "CNcmSession::ServiceL %d %d %d", aMessage.Function(), + aMessage.Int0(), aMessage.Int1()); + + switch ( aMessage.Function() ) + { + case ENcmTransferHandle: + { + RMessagePtr2 messagePtr(aMessage); + TInt ret = iNcmEngine.Start(messagePtr); + + aMessage.Complete(ret); + break; + } + + case ENcmSetIapId: + { + TInt iap = aMessage.Int0(); + TInt ret = iNcmEngine.SetStateToWatcher(ENcmSetTypeIapId, iap); + + aMessage.Complete(ret); + } + break; + + case ENcmSetDhcpResult: + { + TInt result = aMessage.Int0(); + TInt ret = iNcmEngine.SetStateToWatcher(ENcmSetTypeDhcpReturn, result); + + aMessage.Complete(ret); + } + break; + + case ENcmDhcpProvisionNotify: + { + TInt ret = iNcmEngine.RegisterNotify(aMessage); + + if (KErrNone != ret) + { + aMessage.Complete(ret); + } + } + break; + + case ENcmDhcpProvisionNotifyCancel: + { + iNcmEngine.DeRegisterNotify(); + aMessage.Complete(KErrNone); + } + break; + + case ENcmTransferBufferSize: + { + TInt size = aMessage.Int0(); + TInt ret = iNcmEngine.SetInEpBufferSize(size); + aMessage.Complete(ret); + } + break; + + default: + // Unknown function, panic the user + aMessage.Panic(KNcmSrvPanic, ENcmBadNcmMessage); + break; + } + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/group/bld.inf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/group/bld.inf Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#if !(defined(WINS) || defined(WINSCW)) +#include "../classimplementation/group/bld.inf" +#include "../classcontroller/group/bld.inf" +#endif + +PRJ_EXPORTS +../public/usbncm.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(usb/usbncm.h) + +PRJ_MMPFILES + +PRJ_TESTMMPFILES diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/inc/ncmcommon.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/inc/ncmcommon.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** +@file +@internalTechnology + */ + +#ifndef NCMCOMMON_H +#define NCMCOMMON_H + +#ifndef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY +#error "NCM needs the 3-plane comms environment!" +#endif + +#include + +#ifndef __OVER_DUMMYUSBSCLDD__ +#include +#include //FOR KEthernetAddressLength +#else +#include +#endif + +//property's category UID. +//This Property is used to indicate the Packet Driver that it's started by NCM Class Controller. +#ifdef OVERDUMMY_NCMCC +static const TUid KUsbmanSvrUid = {0x2002EA88}; // +#else +static const TUid KUsbmanSvrUid = {0x101fe1db}; +#endif // OVERDUMMY_NCMCC + +//property's sub-key. +static const TUint KKeyNcmSharedState = 0x2002C340; + +//Platform Security for the property. +static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy); +static _LIT_SECURITY_POLICY_C1(KNetworkControlPolicy, ECapabilityNetworkControl); +static _LIT_SECURITY_POLICY_C1(KCommDDPolicy, ECapabilityCommDD); + + +/** +NCM network device MAC address. +*/ +typedef TBuf8 TNcmMacAddress; + +/** +NCM SharedState between NCM Class Controller and Packet Driver. +*/ +enum TNcmSharedState + { + ENcmStateIntial = 0, + ENcmStartRequested = 1, // NCM class controller is request NCM packet driver + ENcmStateEndMark + }; + +/** + Packet driver progress to Comms + */ +enum TNcmNifProgress + { + ENcmPktDrvFatalError = KMinNifProgress // NCM packet driver fatal error + }; + +#endif // NCMCOMMON_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/inc/ncminternalsrv.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/inc/ncminternalsrv.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,92 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** + @file + @internalTechnology +*/ + +#ifndef NCMINTERNALSRV_H +#define NCMINTERNALSRV_H + +#include + +/** +Client-side interface of the NCM internal server for the communication between the NCM Class Controller and the Packet Driver. +*/ +NONSHARABLE_CLASS(RNcmInternalSrv) : public RSessionBase + { +public: + IMPORT_C RNcmInternalSrv(); + IMPORT_C ~RNcmInternalSrv(); + +public: + /** + Connect the handle to the server. + Must be called before all other methods (except Version and Close). + @return Symbian error code + */ + IMPORT_C TInt Connect(); + /** + Getter for the version of the server. + @return Version of the server + */ + IMPORT_C TVersion Version() const; + +public: + /** + Transfer the Ldd's handles from NCM Class Controller to the Packet Driver. + @param[in] aCommHandle, the Communication Interface handle. + @param[in] aCommChunk, the Communication Interface's RChunk handle. + @param[in] aDataHandle, the Data Interface handle. + @param[in] aDataChunk, the Data Interface's RChunk handle. + @return KErrNone, successfully transferred handle to Packet Driver. + others, system-wide error code. + */ + IMPORT_C TInt TransferHandle(RHandleBase& aCommHandle, RHandleBase& aCommChunk, RHandleBase& aDataHandle, RHandleBase& aDataChunk); + /** + Set this RConnection's IapId to Packet Driver. + @param[in] aIapId, the RConnection's, which loads the Packet Driver, IapId. + @return KErrNone, successfully set IapId. + others, system-wide error code. + */ + IMPORT_C TInt SetIapId(TUint aIapId); + /** + Set the DHCP Provision result to Packet Driver. + @param[in] aResult, the result of DHCP Provision done by Class Controller. + @return KErrNone, successfully set the result to Packet Driver. + others, system-wide error code. + */ + IMPORT_C TInt SetDhcpResult(TInt aResult); + /** + Register the notification of doing DHCP Provision. + @param[in,out] aStatus, the request status to be registered. + */ + IMPORT_C void DhcpProvisionNotify(TRequestStatus& aStatus); + /** + Cancel the registration of DHCP Provision. + */ + IMPORT_C void DhcpProvisionNotifyCancel(); + /** + Transfer the buffer size of in endpoint of data interface. + */ + IMPORT_C TInt TransferBufferSize(TUint aSize); + +private: + }; + +#endif // NCMINTERNALSRV_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/device/classdrivers/ncm/public/usbncm.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgr/device/classdrivers/ncm/public/usbncm.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,164 @@ +/* +* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + + +/** +@file +@publishedPartner +*/ + +#ifndef USBNCM_H +#define USBNCM_H + +//INCLUDES +#include + +/** Defines the exported P&S key and data structure of the value. */ +namespace UsbNcm + { + /** The property's category UID. + * This property is to notify the NCM connection state. + */ + static const TUid KCatNcmSvrUid = {0x101F7989}; + + /** The property's sub-key.*/ + static const TUint KKeyNcmConnectionEvent = 0x2002C33F; + + + /** NCM connection state.*/ + enum TNcmConnectionState + { + ENcmStateDisconnected = 0, + ENcmStateConnected, + ENcmStateMax + }; + + /** + * Defines the NCM connection event, which contains the IapId, NCM connection state and corresponding error code. + * The NCM connection is a special one which can not only be used by RConnection, but also needed to monitor the P&S to fetch its state changing. + * Once the P&S published the ENcmStateConnected, the iIapId is also available for starting this connection. + * Otherwise, if the P&S published the ENcmStateDisconnected, the iErrCode should be checked to notify the failure reason: + * KErrNone, normally disconnected probably because of USB cable unpluged. + * KErrInUse, means the other component(currently, BtPan or RNDIS) hold the other P&S key so that the DHCP Provision can't be done by NCM. + * system-wide error code, please check Developer Library. + * It is also possible that this P&S key is deleted when fetching its value because of the NCM connection closed by its driver. + * + * @see below sample code. + */ + struct TNcmConnectionEvent + { + TUint32 iIapId; + TNcmConnectionState iState; + TInt iErrCode; + TUint8 reserved[20]; + }; + } // namespace UsbNcm + +/** + Example Usage: + @code + //header file. + #include + using namespace UsbNcm; + + CMySampleClass: public CActive + { + private: + RProperty iProperty; + RConnection iConnection; + TPckgBuf iNcmEvent; + RSocket iSocket; + } + @endcode + + @code + #include "mysampleclass.h" + + void CMySampleClass::ContructL() + { + User::LeaveIfError(iProperty.Attach(KCatNcmSvrUid, KKeyNcmConnectionEvent, EOwnerThread)); + + iProperty.Get(iNcmEvent); + if (ENcmStateConnected == iNcmEvent.iState) + { + TRequestStatus* pStatus = &iStatus; + iStatus = KRequestPending; + User::RequestComplete(pStatus, KErrNone); + } + else + { + iProperty.Subscribe(iStatus); + SetActive(); + } + } + + void CMySampleClass::RunL() + { + if (KErrNone == iStatus.Int()) + { + iProperty.Get(iNcmEvent); + + switch(iNcmEvent.iState) + { + case ENcmStateConnected: + StartConnection(); + break; + + case ENcmStateDisconnected: + if (KErrInUse == iNcmEvent.u.iErrCode) + { + //Show error UI with msg like "BtPan or Rndis is active, pls deactive it then re-try....", etc. + } + else + { + //Show error UI with other msg as you like. + //StopConnection(); + } + break; + } + } + } + + //Sample code, not all string in this panic show on. + LIT(KNotFoundNcm, "NotFoundPanic - The NCM connection was not found!"); + + TInt CMySampleClass::StartConnection() + { + //the number of connections. + TInt cnt = 0; + iConnection.EnumerateConnections(cnt); + + TInt index = 1; + for (index = 1; index <= cnt; index++) + { + TPckgBuf info; + iConnection.GetConnectionInfo(index, info); + if (info().iIapId == iNcmEvent.iIapId) + { + iConnection.Attach(info, RConnection::EAttachTypeNormal); + break; + } + } + __ASSERT_ALWAYS(index <= cnt, User::Panic(KErrNotFound, KNotFoundNcm)); + + TInt ret = iSocket.Open(...., iConnection); + //..... + return ret; + } + @endcode +*/ +#endif // USBNCM_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgr/group/Usbman.iby --- a/usbmgmt/usbmgr/group/Usbman.iby Fri Jun 25 13:31:50 2010 +0800 +++ b/usbmgmt/usbmgr/group/Usbman.iby Wed Jul 07 14:16:40 2010 +0800 @@ -67,6 +67,8 @@ #include +#include + #ifndef __OBEX_OVER_USB__ #ifndef __TEST_USB_ZLP__ #ifdef __EXAMPLE_OBEX_CC__ diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrautotest/TestExecute/USB/ncm_unit_test/ncmcctest/dummy_ncminternalsrv/group/bld.inf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrautotest/TestExecute/USB/ncm_unit_test/ncmcctest/dummy_ncminternalsrv/group/bld.inf Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This material, including documentation and any related + * computer programs, is protected by copyright controlled by + * Nokia. All rights are reserved. Copying, including + * reproducing, storing, adapting or translating, any + * or all of this material requires the prior written consent of + * Nokia. This material also contains confidential + * information which may not be disclosed to others without the + * prior written consent of Nokia. + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: + * + */ + +PRJ_PLATFORMS +ARMV5 winscw + +PRJ_TESTEXPORTS +../inc/dummy_ncminternalsrv.h SYMBIAN_OS_LAYER_PLATFORM_EXPORT_PATH(usb/testncmcc/dummy_ncminternalsrv.h) + +PRJ_TESTMMPFILES +dummy_ncminternalsrv.mmp diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrautotest/TestExecute/USB/ncm_unit_test/ncmcctest/dummy_ncminternalsrv/group/dummy_ncminternalsrv.mmp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrautotest/TestExecute/USB/ncm_unit_test/ncmcctest/dummy_ncminternalsrv/group/dummy_ncminternalsrv.mmp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). + * All rights reserved. + * This material, including documentation and any related + * computer programs, is protected by copyright controlled by + * Nokia. All rights are reserved. Copying, including + * reproducing, storing, adapting or translating, any + * or all of this material requires the prior written consent of + * Nokia. This material also contains confidential + * information which may not be disclosed to others without the + * prior written consent of Nokia. + * + * Initial Contributors: + * Nokia Corporation - initial contribution. + * + * Contributors: + * + * Description: + * + */ + +TARGET dummy_ncminternalsrv.dll +TARGETTYPE DLL + +UID 0x1000008d 0x2002EA86 +VENDORID 0x70000001 + +// Being run in usbsvr.exe(usbman) +CAPABILITY CommDD PowerMgmt TrustedUI ProtServ NetworkControl NetworkServices LocalServices ReadUserData WriteUserData ReadDeviceData WriteDeviceData + +OS_LAYER_SYSTEMINCLUDE_SYMBIAN + +SOURCEPATH ../src + +LIBRARY euser.lib +LIBRARY usblogger.lib + +SOURCE dummy_ncminternalsrv.cpp + +USERINCLUDE ../inc ../../inc diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_charging_emu/src/tbatterycharging.cpp --- a/usbmgmt/usbmgrtest/t_charging_emu/src/tbatterycharging.cpp Fri Jun 25 13:31:50 2010 +0800 +++ b/usbmgmt/usbmgrtest/t_charging_emu/src/tbatterycharging.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -1,5 +1,5 @@ /* -* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). +* Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). * All rights reserved. * This component and the accompanying materials are made available * under the terms of "Eclipse Public License v1.0" @@ -128,7 +128,6 @@ iPlugin = iExtensionPlugins[0]; iDummyLdd.Initialise(); - //iRepository = CRepository::NewL(KUsbBatteryChargingCentralRepositoryUid); User::LeaveIfError(iTimer.CreateLocal()); DefinePropertyL(KBattChargWriteRepositoryUid, KBattChargWriteRepositoryKey,RProperty::EInt); @@ -345,7 +344,7 @@ TInt CDummyUsbDevice::GetNextLine() { - TInt newLineOffset = (iPtr.Mid(iFileOffset)).Locate(13);//Find(_L("\r\n")); + TInt newLineOffset = (iPtr.Mid(iFileOffset)).Locate(13); if (newLineOffset < 0) { return newLineOffset; @@ -426,7 +425,6 @@ { TInt err = WriteToRepositoryProperty(iCommandValue); - //TInt err = iRepository->Set(KUsbBatteryChargingKeyEnabledUserSetting, iCommandValue); iTest(err == KErrNone); } break; @@ -482,8 +480,6 @@ TInt current; TInt err = GetChargingCurrentFromProperty(current); - //TInt err = RProperty::Get(KPropertyUidUsbBatteryChargingCategory, - // KPropertyUidUsbBatteryChargingChargingCurrent, current); iTest(err == KErrNone); iTest(current == iCheckValue); } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/group/bld.inf --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/group/bld.inf Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + +PRJ_PLATFORMS +ARMV5 winscw + +PRJ_TESTEXPORTS +ncmtestconsole.iby /epoc32/rom/include/ncmtestconsole.iby + +PRJ_TESTMMPFILES +ncmtestconsole.mmp diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/group/ncmtestconsole.iby --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/group/ncmtestconsole.iby Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + +#ifndef NCM_TEST_CONSOLE_IBY +#define NCM_TEST_CONSOLE_IBY + + +#ifdef _DEBUG +file= ABI_DIR\DEBUG_DIR\ncmtestconsole.exe sys\bin\ncmtestconsole.exe +#else +file= ABI_DIR\BUILD_DIR\ncmtestconsole.exe sys\bin\ncmtestconsole.exe +#endif + +#endif //NCM_TEST_CONSOLE_IBY diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/group/ncmtestconsole.mmp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/group/ncmtestconsole.mmp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + +target ncmtestconsole.exe +targettype exe +UID 0 0xE228E991 + +capability All -Tcb + +OS_LAYER_SYSTEMINCLUDE_SYMBIAN + +userinclude ../inc + +sourcepath ../src + +library euser.lib +library usbman.lib +library centralrepository.lib +library esock.lib +library commdb.lib +library insock.lib +library esocksvr.lib + +source ncmtestconsole.cpp commandengine.cpp devicewatcher.cpp servicewatcher.cpp +source exitcommand.cpp +source simpancommand.cpp +source setncmiapcommand.cpp tcptest.cpp tcpcommand.cpp +source ncmwatcher.cpp + +#include +#include + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/inc/commandengine.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/inc/commandengine.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,119 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + + +#ifndef COMMANDENGINE_H +#define COMMANDENGINE_H + +#include "ncmtestdefines.hrh" + +#include +#include + +#define COMMAND_MAX_COUNT_PER_PAGE NUM_EVENT_ON_SCREEN +#define COMMAND_MAX_PAGE 9 + +class CUsbNcmConsole; + +NONSHARABLE_CLASS(CNcmCommandBase) : public CActive +/** + The CNcmCommandBase class is the base class of command classes + */ + { + friend class CNcmCommandEngine; +public: + virtual ~CNcmCommandBase(); + + //Set the command key + void SetKey(TUint aKey); + //Get the command key + TUint Key() const; + + //The command action when user choose a command. It must be implemneted by command classes. + virtual void DoCommandL() = 0; + + //Set the command description. which will be displayed in command help. + void SetDescription(const TDesC& aDescription); + const virtual TDesC& Description(); + +protected: + CNcmCommandBase(TInt aPriority, CUsbNcmConsole& aConsole, TUint aKey); + +protected: + //From CActive + virtual void DoCancel(); + virtual void RunL(); + +protected: + //Main console + CUsbNcmConsole& iTestConsole; + + //The character which indicates the command + TUint iKey; + //The command's description + TBuf iDescription; + + }; + +NONSHARABLE_CLASS(CNcmCommandEngine) : public CActive +/** + CNcmCommandEngine manages all command classes. + */ + { +public: + static CNcmCommandEngine* NewL(CUsbNcmConsole& aUsb); + ~CNcmCommandEngine(); + + //Add command to command engine. + void RegisterCommand(CNcmCommandBase* aCommand); + //Destroy all commands in command engine. + void RemoveAllCommand(); + + //Get command help info. + void PrintHelp(TInt aPage); + +private: + CNcmCommandEngine(CUsbNcmConsole& aUsb); + void ConstructL(); + + //From CActive + void DoCancel(); + void RunL(); + TInt RunError(TInt aError); + +private: + //Main console + CUsbNcmConsole& iTestConsole; + + //The mapping of key and commands. + RHashMap iCommandMap; + //keep the key infomation, the command will be displayed in which page and which line. + TUint iCommandKeys[COMMAND_MAX_PAGE][COMMAND_MAX_COUNT_PER_PAGE]; + //Indicate the page of the last command . + TInt iLastPage; + //Indicate the place of the last command in the last page. + TInt iLastItem; + //Indicate the rest lines in the last used page. + TInt iRemainLine; + }; + +#endif // COMMANDENGINE_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/inc/devicewatcher.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/inc/devicewatcher.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,80 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + +#ifndef DEVICEWATCHER_H +#define DEVICEWATCHER_H + +#include +#include + +class CUsbNcmConsole; + +//The mode of CDeviceWatcher +enum TDeviceWatchMode + { + EWatchMode, //Only monitor the device state + EWatchAndStartMode //monitor the device state and start/stop NCM and NCM control app + //when usb cable plugin/unplug + }; + +NONSHARABLE_CLASS(CDeviceWatcher) : public CActive +/** +Monitor the USB device state. +*/ + { +public: + + static CDeviceWatcher* NewL(CUsbNcmConsole& aUsb); + ~CDeviceWatcher(); + + void SetWatchMode(TDeviceWatchMode aWatchMode); + TDeviceWatchMode GetWatchMode() const; + +private: + CDeviceWatcher(CUsbNcmConsole& aUsb); + void ConstructL(); + +private: + //From CActive + void DoCancel(); + void RunL(); + TInt RunError(TInt aError); + +private: + void DisplayDeviceState(TUint aDeviceState); + +private: + //Main console + CUsbNcmConsole& iTestConsole; + RDevUsbcClient iLdd; + + //Usb device state + TUint iDeviceState; + //Usb old device state + TUint iOldDeviceState; + //Indicate whether start/stop behavior are used. ETrue means start/stop is needed. + TBool iStartNcm; + TDeviceWatchMode iWatchMode; + }; + + +#endif //DEVICEWATCHER_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/inc/exitcommand.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/inc/exitcommand.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + + +#ifndef EXITCOMMAND_H +#define EXITCOMMAND_H + +#include "commandengine.h" + +NONSHARABLE_CLASS(CExitCommand) : public CNcmCommandBase +/** +Quit from the main console +*/ + { +public: + static CExitCommand* NewL(CUsbNcmConsole& aUsb, TUint aKey); + ~CExitCommand(); + +public: + //From CNcmCommandBase + void DoCommandL(); + +private: + CExitCommand(CUsbNcmConsole& aUsb, TUint aKey); + void ConstructL(); + +private: + + }; + +#endif // EXITCOMMAND_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/inc/ncmtestconsole.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/inc/ncmtestconsole.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,196 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + + +#ifndef NCMTESTCONSOLE_H +#define NCMTESTCONSOLE_H + +#include +#include +#include +#include +#include + +void Panic(TInt aPanic); + +#ifdef __FLOG_ACTIVE +_LIT8(KSubSys, "NCM"); +_LIT8(KLogComponent, "TEST"); +#endif + + +class CConsoleBase; +class CNcmCommandEngine; +class CDeviceWatcher; +class CServiceWatcher; +class CSharedStateWatcher; + +_LIT(KUsbNcmConsoleTitle, "NCM Test Console"); + +//Display item index +enum TDisplayItemIndex + { + EUsbServiceStateItem = 0, + EUsbDeviceStateItem, + ENcmConnStatusItem, + ENcmConnIpItem, + EUplinkConnStatusItem, + EUplinkConnIpItem, + ENcmBtPanItem, + ENcmAgentStateItem, + EAuthorisationSettingItem, + ENcmConnectionStateItem, + ELastItem //not used, just for count + }; + +#define DISPLAY_USB_SERVICE_STATE_LEN 11 //EUsbServiceStateItem +#define DISPLAY_USB_DEVICE_STATE_LEN 11 //EUsbDeviceStateItem +#define DISPLAY_NCM_CONN_STATE_LEN 16 //ENcmConnStatusItem +#define DISPLAY_NCM_CONN_IP_LEN 15 //ENcmConnIpItem +#define DISPLAY_UPLINK_CONN_STATE_LEN 16 //EUplinkConnStatusItem +#define DISPLAY_UPLINK_CONN_IP_LEN 15 //EUplinkConnIpItem +#define DISPLAY_NCM_BTPAN_LEN 10 //ENcmBtPanItem +#define DISPLAY_AGENT_STATE_LEN 30 //ENcmAgentStateItem +#define DISPLAY_AUTH_SETTING_LEN 15 //EAuthorisationSettingItem +#define DISPLAY_NCM_CONNECTION_STATE 16 + +//The SID of Ncm state P&S key used +const TUid KC32ExeSid = {0x101F7989}; + +NONSHARABLE_CLASS(CUsbNcmConsoleEvent) +/** +Event reported by running commands and watcher classes +*/ + { +public: + static CUsbNcmConsoleEvent* NewL(); + ~CUsbNcmConsoleEvent(); +private: + CUsbNcmConsoleEvent(); + void ConstructL(); +public: + //Event queue link + TDblQueLink iLink; + //Event description + RBuf iEvent; + }; + + +NONSHARABLE_CLASS(CUsbNcmConsole) : public CActive +/** +The Main Console of NCM manual test +*/ + { +friend class CNcmCommandEngine; + +public: + static CUsbNcmConsole* NewLC(TBool aDemo); + ~CUsbNcmConsole(); + +public: + void StartL(); + void Stop() const; + + RUsb& Usb(); + +public: + //commands use it to report event to main console + void NotifyEvent(CUsbNcmConsoleEvent* aEvent); + + //Set the Ncm IAP and monitor the related connection status + void SetLocalIapId(TInt aId); + //Set the Uplink IAP and monitor the related connection status + void SetUplinkIapId(TInt aId); + + //Get Ncm Iap ID + TInt LocalIapId() const; + //Get Uplink Iap ID + TInt UplinkIapId() const; + + //Called by commands and watchers to notify main console refresh the screen + void ScheduleDraw(TUint aKey); + + //Set the permanent info to display on screen + void SetDisplayItem(TInt aIndex, TDes& aInfo); + //Get the permanent info on screen + const TDes& GetDisplayItem(TInt aIndex); + + //Display all Iaps configured in commsdb + TInt DrawAvailableIapsL(); + + //Attach the connection specified by aIap + TBool AttachConnectionL(TInt aIap, RConnection& aConnection); + +private: + CUsbNcmConsole(TBool aDemo); + void ConstructL(); + + //Display all kinds of info. + void DrawL(); + //Init the items which are displayed on screen permanently + void CreateDisplayItemL(); + + //Call back function + static TInt DoCommandCallback(TAny *aThisPtr); + +private: + //From Active + void DoCancel(); + void RunL(); + TInt RunError(TInt aError); + +private: + CConsoleBase* iConsole; + RUsb iUsb; + + //The info displayed on screen permanently + RArray iDisplayArray; + + TVersion iVersion; + + //The Uplink IAP id + TInt iLocalIapId; + + CNcmCommandEngine* iKeys; + + //monitor the USB device state + CDeviceWatcher* iDeviceWatcher; + //monitor the USB service state + CServiceWatcher* iServiceWatcher; + + //Get the agent state of Ncm + CSharedStateWatcher* iSharedStateWatcher; + //Indicate current operation is display the help or not. + TInt iHelp; + + //If 'DEMO' is used as application parameter, iDemo will be set true. The Ncm + //Control app will be started automaticly and start Ncm automicly when usb cable + //plugin. This is used to demo for licencee. + TBool iDemo; +// CAsyncCallBack* iStartWatcherCallback; + + // Event list + TDblQue iEventList; + }; + + +#endif // NCMTESTCONSOLE_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/inc/ncmtestdefines.hrh --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/inc/ncmtestdefines.hrh Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,54 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + + + +#ifndef NCMTESTDEFINES_HRH +#define NCMTESTDEFINES_HRH + +// H4 screen can have 22 lines of text on it at once +// H4 screen can have 53 characters per line. +#define NUM_CHARACTERS_ON_LINE 53 +#define NUM_EVENT_ON_SCREEN 12 + + +enum TNcmTestConsolePanic + { + //The event is null. + ENcmEventIsNull = 300000, + //The lengh of event info is larger than allowed + ENcmEventLengthValid, + //The index of display item is valid + ENcmDisplayItemVaild, + //The command instance is null + ENcmCommandIsNull, + //The ncm start command is null + ENcmStartCommandIsNull, + //The command key exists + ENcmCommandKeyExists, + //InsertCommandError + ENcmInsertCommandError, + //The index of array item is valid + ENcmArrayBound + + }; +#endif // NCMTESTDEFINES_HRH diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/inc/ncmwatcher.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/inc/ncmwatcher.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,57 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + + +#ifndef NCMWATCHER_H +#define NCMWATCHER_H + +#include +#include +#include + +class CUsbNcmConsole; + +NONSHARABLE_CLASS(CSharedStateWatcher) : public CActive + { +public: + static CSharedStateWatcher* NewL(CUsbNcmConsole& aConsole); + ~CSharedStateWatcher(); + +private: + CSharedStateWatcher(CUsbNcmConsole& aConsole); + void ConstructL(); + void reportState(); + + //From CActive + void RunL(); + void DoCancel(); + +private: + RProperty iProperty; + TInt iIapId; + TInt iErrCode; + TPtr8 iNcmStateDes; + UsbNcm::TNcmConnectionEvent iSharedState; + CUsbNcmConsole& iConsole; + }; + +#endif // NCMWATCHER_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/inc/servicewatcher.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/inc/servicewatcher.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + + +#ifndef SERVICEWATCHER_H +#define SERVICEWATCHER_H + +#include +#include + +class CUsbNcmConsole; + +NONSHARABLE_CLASS(CServiceWatcher) : public CActive +/** +Monitor USB service state +*/ + { +public: + static CServiceWatcher* NewL(CUsbNcmConsole& aUsb); + ~CServiceWatcher(); + +private: + CServiceWatcher(CUsbNcmConsole& aUsb); + void ConstructL(); + + //Display USB service state on main console + void DisplayServiceState(TUsbServiceState aServiceState); + +private: + //From CActive + void DoCancel(); + void RunL(); + TInt RunError(TInt aError); + +private: + CUsbNcmConsole& iTestConsole; + TUsbServiceState iServiceState; + }; + + +#endif // SERVICEWATCHER_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/inc/setncmiapcommand.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/inc/setncmiapcommand.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,105 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + +#ifndef SETNCMIAPCOMMAND_H +#define SETNCMIAPCOMMAND_H + +#include "commandengine.h" +#include + +NONSHARABLE_CLASS(CSetNcmIapCommand) : public CNcmCommandBase +/** +Set the Ncm Iap Id into central repository +*/ + { +public: + enum TSetNcmIapCommandState + { + EIapId, //The command is in state of wait user input iap + EIapPriority //The command is in state of wait user input iap index + }; +public: + static CSetNcmIapCommand* NewL(CUsbNcmConsole& aUsb, TUint aKey); + ~CSetNcmIapCommand(); + + //Get the first IAP ID stored in central repository. + void GetDefaultIapL(TInt& aDefaultIap); + +public: + //From CNcmCommandBase + void DoCommandL(); + +private: + CSetNcmIapCommand(CUsbNcmConsole& aUsb, TUint aKey); + void ConstructL(); + +private: + //From CActive + void DoCancel(); + void RunL(); + TInt RunError(TInt aError); + +private: + //Display all IAPs stored in central repository which are used for Ncm + void ListAllNcmIapL(); + //Set the Iap Id inputed by user into central repository + void SetNcmIapL(); + + //Init work for run this command + void InitWorkL(); + //Stop work when finish or terminate this command + void EndWork(); + +private: + + TSetNcmIapCommandState iCommandState; + + //The console used to display iap info and get user input for ncm iap + CConsoleBase* iConsole; + //user current input + RBuf iChars; + //the Iap id user want to store in central repository + TInt iIapId; + //the position of the Iap id which will be stored in central repository + TInt iIndex; + //central repository handle + CRepository* iRepository; + //all Iaps get from central repository + RArray iRows; + + //followed are used for finding Iap Id stored in central repository + static const TUint KPartialKey = 0x01010000; + static const TUint KMask = 0xFFFF0000; + static const TInt KMaxNumOfChars = 255; + + + }; + + +_LIT(KSetIapMemo ,"Input the NcmIap you want to set:"); +_LIT(KSetIapIndexMemo, "Input the index of iap you want to set:"); +_LIT(KErrInput, "Error input. Input again.\n"); + +const TUid KNcmIapIdRepositoryUID = {0x10286a43}; + +#endif // SETNCMIAPCOMMAND_H + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/inc/simpancommand.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/inc/simpancommand.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,88 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + +#ifndef SIMPANCOMMAND_H +#define SIMPANCOMMAND_H + +#include "commandengine.h" +#include + +// This is a local definition of this shared enum of P&S key values. These values should not be changed without changing +// the equivalent definition in the other IP bearer code. +enum TIPBearerCoexistenceStatus + { + ENoneIsActive, + ENcmIsActive, + EBTPanIsActive + }; + +// This is a local definition of this shared P&S id. This value should not be changed without changing +// the equivalent definition in the other IP bearer code. +const TInt KIPBearerCoexistenceProperty = 0x10286a95; + +// This is the identifer of the shared mutex used to allow safe read / write of the coexistence P&S key. +// This can only be changed if all other existing definitions of the mutex name are also changed. +_LIT(KIPBearerCoexistenceMutex, "IPBearerCoexistenceMutex"); + +//static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy); +//static _LIT_SECURITY_POLICY_C1(KNetworkControlPolicy, ECapabilityNetworkControl); + + +NONSHARABLE_CLASS(CSimPANCommand) : public CNcmCommandBase +/** +Simulate PAN has an active connection or not. +It is also response for display the exclusive state on main console +*/ + { +public: + static CSimPANCommand* NewL(CUsbNcmConsole& aUsb, TUint aKey); + ~CSimPANCommand(); + +public: + //From CNcmCommandBase + void DoCommandL(); + +private: + CSimPANCommand(CUsbNcmConsole& aUsb, TUint aKey); + void ConstructL(); + +private: + //From CActive + void RunL(); + void DoCancel(); + TInt RunError(TInt aError); + +private: + //Display the exclusive state on main screen + void DisplayExclusive(TInt aState); + //When the PAN is active, the command description should be + //changed to 'Simulate PAN disactive' + void ChangeDescription(); + +private: + //Indicate the PAN is active or not + TBool iSetPAN; + //The property which store the exclusive state + RProperty iNcmExclusiveProp; + }; + +#endif // SIMPANCOMMAND_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/inc/startwatchercommand.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/inc/startwatchercommand.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + +#ifndef STARTWATCHERCOMMAND_H +#define STARTWATCHERCOMMAND_H + +#include "commandengine.h" + +class CDeviceWatcher; + +NONSHARABLE_CLASS(CStartWatcherCommand) : public CNcmCommandBase +/** +Set the test mode to run NCM automaticly when usb cable plugin. +*/ + { +public: + static CStartWatcherCommand* NewL(CUsbNcmConsole& aUsb, TUint aKey, CDeviceWatcher& aDeviceWatch); + ~CStartWatcherCommand(); + +public: + //From CNcmCommandBase + void DoCommandL(); + +private: + CStartWatcherCommand(CUsbNcmConsole& aUsb, TUint aKey, CDeviceWatcher& aDeviceWatch); + void ConstructL(); + +private: + CDeviceWatcher& iDeviceWatcher; + }; + +#endif // STARTWATCHERCOMMAND_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/inc/tcpcommand.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/inc/tcpcommand.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + +#ifndef TCPCOMMAND_H +#define TCPCOMMAND_H + +#include "commandengine.h" + +//The max count of tcp test in a same time +const static TInt KMaxTcpTestCount = 5; + +class CTcpTestConsole; + +NONSHARABLE_CLASS(CTcpCommand) : public CNcmCommandBase +/** +Make TCP test: Create a tcp connection and tansfer data on it. +*/ + { +public: + static CTcpCommand* NewL(CUsbNcmConsole& aUsb, TUint aKey, TBool aIsTcp, TBool aIsServer); + ~CTcpCommand(); + +public: + //From CNcmCommandBase + void DoCommandL(); + +public: + void CloseTcpTest(TInt aIndex); + +private: + CTcpCommand(CUsbNcmConsole& aUsb, TUint aKey, TBool aIsTcp, TBool aIsServer); + void ConstructL(); + +private: + //Indicate the tcp type: ETrue - as TCP server; EFalse - as TCP client + TBool iIsServer; + TBool iIsTcp; + //Store the instances of tcp test console + CTcpTestConsole* iTestArray[KMaxTcpTestCount]; + }; + +#endif // TCPCOMMAND_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/inc/tcptest.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/inc/tcptest.h Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,190 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + +#ifndef TCPTEST_H +#define TCPTEST_H + +#include +#include +#include + +class CTcpProcess : public CActive +/** +Run TCP test: Create a tcp connection and make data transfer on it. +*/ + { +public: + static CTcpProcess* NewL(CConsoleBase& aConsole, TInetAddr& aAddr, TInt aPort, TInt aSize, TBool aMode); + ~CTcpProcess(); + +private: + CTcpProcess(CConsoleBase& aConsole, TInetAddr& aAddr, TInt aPort, TInt aSize, TBool aMode); + void ConstructL(); + + void RecvDataL(); + TInt SendDataL(TDes8& aData, TInt aSize); + void PrintData(TDes8& aData); + +private: + //From CActive + virtual void RunL(); + virtual void DoCancel(); + TInt RunError(TInt aError); + +private: + enum TProcessState + { + ECreateConnection, //Create tcp connection + EDataTransfer //Data transfer + }; + +private: + CConsoleBase& iConsole; + + RSocketServ iSockServ; + RSocket iListenSocket; + RSocket iSocket; + + TInetAddr& iAddr; + TInt iPort; + + //The size of send buf and receive buf + TInt iSize; + + RBuf8 iRecvBuf; + RBuf8 iSendBuf; + + TSockXfrLength iRecvSize; + + TBool iMode; //ETrue: as a Server, and data transfer is receive first, then send back + //EFalse: as a client, and data transfer is send first, then receive. + + TProcessState iProcessState; + + }; + + +class CUdpProcess : public CActive + /** + Run TCP test: Create a udp connection and make data transfer on it. + */ +{ + public: + static CUdpProcess* NewL(CConsoleBase& aConsole, TInetAddr& aAddr, TInt aPort, TInt aSize, TBool aMode); + ~CUdpProcess(); + + private: + CUdpProcess(CConsoleBase& aConsole, TInetAddr& aAddr, TInt aPort, TInt aSize, TBool aMode); + void ConstructL(); + + void RecvDataL(); + TInt SendDataL(TDes8& aData, TInetAddr& aAddr, TInt aSize); + void PrintData(TDes8& aData); + + private: + //From CActive + virtual void RunL(); + virtual void DoCancel(); + TInt RunError(TInt aError); + + private: + enum TProcessState + { + EDataSending, //Data Sending + EDataTransfer //Data Recving + }; + + private: + CConsoleBase& iConsole; + + RSocketServ iSockServ; + RSocket iListenSocket; + RSocket iSocket; + + TInetAddr iAddr; + TInetAddr iPeerAddr; + TInt iPort; + + //The size of send buf and receive buf + TInt iSize; + + RBuf8 iRecvBuf; + RBuf8 iSendBuf; + + TSockXfrLength iRecvSize; + + TBool iMode; //ETrue: as a Server, and data transfer is receive first, then send back + //EFalse: as a client, and data transfer is send first, then receive. + + TProcessState iProcessState; + +}; + + +class CTcpCommand; +class CTcpTestConsole : public CActive +/** +The console of tcp test. +*/ + { +public: + static CTcpTestConsole* NewL(TBool aIsTcp, TBool aMode, TDesC& aDefautAddr, TInt aIndex, CTcpCommand& aOwner); + ~CTcpTestConsole(); + + TBool StartL(); + void Help(); + +private: + CTcpTestConsole(TBool aIsTcp, TBool aMode, TDesC& aDefautAddr, TInt aIndex, CTcpCommand& aOwner); + void ConstructL(); + +private: + //From CActive + virtual void RunL(); + virtual void DoCancel(); + TInt RunError(TInt aError); + +private: + enum TCommandMode + { + ECommandInit, //Get parameter from user input + ECommandRunning //tcp test run + }; + +private: + CConsoleBase* iConsole; + RBuf iChars; + TCommandMode iCommandMode; + + CTcpProcess* iTcp; + CUdpProcess* iUdp; + TBool iMode; //ETrue server EFalse client + TBool iIsTcp; + + //The defaut addr, format like 'addr port' (192.168.2.101 5000) + const TDesC& iDefaultAddr; + TInt iIndex; + CTcpCommand& iOwner; + + }; + +#endif //TCPTEST_H diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/sis/ncmtestconsole.pkg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/sis/ncmtestconsole.pkg Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,24 @@ +; Installation file for Symbian OS 9.x for generic console application +; Installation file for ncmtestconsole EXE +; +; This is an auto-generated PKG file by Carbide. +; This file uses variables specific to Carbide builds that will not work +; on command-line builds. If you want to use this generated PKG file from the +; command-line tools you will need to modify the variables with the appropriate +; values: $(EPOCROOT), $(PLATFORM), $(TARGET) +; + +; +; UID is the exe's UID +; +#{"ncmtestconsole"},(0xE228E991),1,0,0 + + +;Localised Vendor name +%{"Vendor-EN"} + +;Unique Vendor name +:"Vendor" + +"$(EPOCROOT)Epoc32\release\$(PLATFORM)\$(TARGET)\ncmtestconsole.exe" -"!:\sys\bin\ncmtestconsole.exe" + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/src/commandengine.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/src/commandengine.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,249 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + +#include "commandengine.h" +#include "ncmtestconsole.h" + +CNcmCommandEngine* CNcmCommandEngine::NewL(CUsbNcmConsole& aTestConsole) +/** +Constructs a CNcmCommandEngine object. + @param aTestConsole The main console +*/ + { + LOG_STATIC_FUNC_ENTRY + CNcmCommandEngine* self = new(ELeave) CNcmCommandEngine(aTestConsole); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + return self; + } + +CNcmCommandEngine::~CNcmCommandEngine() + { + Cancel(); + RemoveAllCommand(); + } + +CNcmCommandEngine::CNcmCommandEngine(CUsbNcmConsole& aTestConsole) + : CActive(EPriorityStandard) + , iTestConsole(aTestConsole) + , iLastPage(0), iLastItem(-1), iRemainLine(COMMAND_MAX_COUNT_PER_PAGE) + { + CActiveScheduler::Add(this); + } + +void CNcmCommandEngine::ConstructL() + { + //wait user select command + iTestConsole.iConsole->Read(iStatus); + SetActive(); + } + +void CNcmCommandEngine::DoCancel() + { + iTestConsole.iConsole->ReadCancel(); + } + +void CNcmCommandEngine::RunL() + { + LOG_FUNC + + User::LeaveIfError(iStatus.Int()); + + TUint key = iTestConsole.iConsole->KeyCode(); + + __FLOG_STATIC1(KSubSys, KLogComponent , _L8("key = %c"), key); + + if((key >= '0') && (key <= '9')) + { + iTestConsole.ScheduleDraw(key-0x30); + } + else + { + CNcmCommandBase* command = NULL; + if(iCommandMap.Find(key)) + { + command = *(iCommandMap.Find(key)); + if(command) + { + command->DoCommandL(); + } + else + { + __FLOG_STATIC0(KSubSys, KLogComponent , _L8("The command in hashmap is NULL")); + } + } + else + { + CUsbNcmConsoleEvent* event = CUsbNcmConsoleEvent::NewL(); + event->iEvent.AppendFormat(_L("G:Unknown:Key[%c]"), key); + iTestConsole.NotifyEvent(event); + } + + } + iTestConsole.iConsole->Read(iStatus); + + SetActive(); + } + +void CNcmCommandEngine::RegisterCommand(CNcmCommandBase* aCommand) +/** +Add command object into command map + @param aCommand a command which will be used by user +*/ + { + //Assert if aCommand is NULL + __ASSERT_ALWAYS(aCommand, Panic(ENcmCommandIsNull)); + //Assert if the key exists in command map + __ASSERT_ALWAYS(!iCommandMap.Find(aCommand->Key()), Panic(ENcmCommandKeyExists)); + + //add command + TInt err = iCommandMap.Insert(aCommand->Key(), aCommand); + if(err != KErrNone) + { + User::Panic(_L("RegisterCommand"), err); + } + + //make the command to be displayed in which page, which line + TInt line = (aCommand->Description().Length() + NUM_CHARACTERS_ON_LINE + 4) / (NUM_CHARACTERS_ON_LINE); + iRemainLine -= line; + if(iRemainLine < 0) + { + iLastPage ++; + iRemainLine = COMMAND_MAX_COUNT_PER_PAGE - line; + iLastItem = 0; + } + else + { + iLastItem ++; + } + iCommandKeys[iLastPage][iLastItem] = aCommand->Key(); + + } + +void CNcmCommandEngine::RemoveAllCommand() +/** +Destroy all commands in command map +*/ + { + CNcmCommandBase* currentitem; + + RHashMap::TIter hashMapIter(iCommandMap); + TInt count = iCommandMap.Count(); + for(TInt i=0; i< count; i++) + { + currentitem = *(hashMapIter.NextValue()); + if(currentitem) + { + hashMapIter.RemoveCurrent(); + delete currentitem; + } + } + iCommandMap.Close(); + + } + + +void CNcmCommandEngine::PrintHelp(TInt aPage) +/** +Get command help info (command key - command description) +@param aPage the command help info of specified page +*/ + { + LOG_FUNC + + __ASSERT_ALWAYS(((aPage <= COMMAND_MAX_PAGE) && (aPage > 0)), Panic(ENcmArrayBound)); + + TUint key = iCommandKeys[aPage-1][0]; + if(key == 0) + { + //No commands in this page + iTestConsole.iConsole->Printf(_L("No commands\n")); + } + else + { + //Display command + TInt i = 0; + while((key != 0) && (i < COMMAND_MAX_COUNT_PER_PAGE)) + { + CNcmCommandBase* command = NULL; + command = *(iCommandMap.Find(key)); + iTestConsole.iConsole->Printf(_L("%c - %S\n"), command->Key(), &command->Description()); + i++; + key = iCommandKeys[aPage-1][i]; + } + } + + } + +CNcmCommandBase::CNcmCommandBase(TInt aPriority, CUsbNcmConsole& aConsole, TUint aKey) + : CActive(aPriority), iTestConsole(aConsole), iKey(aKey) +/** +Constructor +@param aPriority Active object's priority +@param aConsole The main console +@param aKey command key +*/ + { + } + +CNcmCommandBase::~CNcmCommandBase() + { + } + +TUint CNcmCommandBase::Key() const + { + return iKey; + } + +void CNcmCommandBase::SetKey(TUint aKey) + { + iKey = aKey; + } + + +const TDesC& CNcmCommandBase::Description() + { + return iDescription; + } + +void CNcmCommandBase::SetDescription(const TDesC& aDescription) +/** +Set command description +@param aDescription the new description for the command +*/ + { + iDescription.SetLength(0); + iDescription.Copy(aDescription.Left(NUM_CHARACTERS_ON_LINE)); + } +void CNcmCommandBase::RunL() + { + } + +void CNcmCommandBase::DoCancel() + { + } +TInt CNcmCommandEngine::RunError(TInt aError) + { + User::Panic(_L("CNcmCommandEngine"), aError); + return aError; + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/src/devicewatcher.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/src/devicewatcher.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,179 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + +#include "devicewatcher.h" +#include "ncmtestconsole.h" + +CDeviceWatcher* CDeviceWatcher::NewL(CUsbNcmConsole& aTestConsole) + { + LOG_STATIC_FUNC_ENTRY + + CDeviceWatcher* self = new(ELeave) CDeviceWatcher(aTestConsole); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + return self; + } +CDeviceWatcher::~CDeviceWatcher() + { + Cancel(); + iLdd.Close(); + } + +CDeviceWatcher::CDeviceWatcher(CUsbNcmConsole& aTestConsole) + : CActive(EPriorityStandard), iTestConsole(aTestConsole), iWatchMode(EWatchMode) + { + CActiveScheduler::Add(this); + } + +void CDeviceWatcher::ConstructL() + { + User::LeaveIfError(iLdd.Open(0)); + iLdd.AlternateDeviceStatusNotify(iStatus, iDeviceState); + + SetActive(); + + //Get current device state + TUsbcDeviceState deviceState; + User::LeaveIfError(iLdd.DeviceStatus(deviceState)); + + DisplayDeviceState(deviceState); + + } + +void CDeviceWatcher::DoCancel() + { + iLdd.AlternateDeviceStatusNotifyCancel(); + } + +void CDeviceWatcher::RunL() + { + //Get USB device state change + iLdd.AlternateDeviceStatusNotify(iStatus, iDeviceState); + SetActive(); + + LOG_FUNC + __FLOG_STATIC1(KSubSys, KLogComponent , _L8("CDeviceWatcherCommand::RunL - iStatus = %d"), iStatus.Int()); + + //Display the current state on main console + DisplayDeviceState(iDeviceState); + + TUsbServiceState serviceState; + User::LeaveIfError(iTestConsole.Usb().GetServiceState(serviceState)); + + __FLOG_STATIC3(KSubSys, KLogComponent , + _L8("iDeviceState = %d, serviceState = %d, iStartNcm=%d"), + iDeviceState, serviceState, iStartNcm); + + iOldDeviceState = iDeviceState; + } + +TInt CDeviceWatcher::RunError(TInt aError) + { + User::Panic(_L("CDeviceWatcher"), aError); + return aError; + } + +TDeviceWatchMode CDeviceWatcher::GetWatchMode() const + { + return iWatchMode; + } + +void CDeviceWatcher::SetWatchMode(TDeviceWatchMode aWatchMode) +/** +Set the watch mode : If the mode is EWatchMode, only monitor the USB device status. +If the mode is EWatchAndStartMode, when cable plugin, NCM will be started automaticly + @param aWatchMode The mode user want to set +*/ + { + iWatchMode = aWatchMode; + switch(iWatchMode) + { + case EWatchMode: + iStartNcm = EFalse; + break; + case EWatchAndStartMode: + iStartNcm = ETrue; + break; + } + //When USB device state changed, CDeviceWatcher will check iStartNcm. The detail please see + //RunL() + } + +void CDeviceWatcher::DisplayDeviceState(TUint aDeviceState) +/** +Display device status on main console + @param aDeviceState the device state +*/ + { + TBuf devStatus; + switch(aDeviceState) + { + case EUsbcDeviceStateUndefined: + devStatus = + // 12345678901 + _L("Undefined "); + break; + + case EUsbcDeviceStateDefault: + devStatus = + // 12345678901 + _L("Default "); + break; + + case EUsbcDeviceStateAttached: + devStatus = + // 12345678901 + _L("Attached "); + break; + + case EUsbcDeviceStatePowered: + devStatus = + // 12345678901 + _L("Powered "); + break; + + case EUsbcDeviceStateConfigured: + devStatus = + // 12345678901 + _L("Configured "); + break; + + case EUsbcDeviceStateAddress: + devStatus = + // 12345678901 + _L("Address "); + break; + + case EUsbcDeviceStateSuspended: + devStatus = + // 12345678901 + _L("Suspended "); + break; + default: + devStatus = + // 12345678901 + _L("Unknown "); + break; + } + iTestConsole.SetDisplayItem(EUsbDeviceStateItem, devStatus); + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/src/exitcommand.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/src/exitcommand.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + +#include "exitcommand.h" +#include "ncmtestconsole.h" + +_LIT(KExitCommandDescription, "Exit"); + +CExitCommand* CExitCommand::NewL(CUsbNcmConsole& aTestConsole, TUint aKey) + { + LOG_STATIC_FUNC_ENTRY + + CExitCommand* self = new(ELeave) CExitCommand(aTestConsole, aKey); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + return self; + } +CExitCommand::~CExitCommand() + { + } + +CExitCommand::CExitCommand(CUsbNcmConsole& aTestConsole, TUint aKey) + : CNcmCommandBase(EPriorityStandard, aTestConsole, aKey) + { + } + +void CExitCommand::ConstructL() + { + SetDescription(KExitCommandDescription()); + } + +void CExitCommand::DoCommandL() + { + LOG_FUNC + __FLOG_STATIC0(KSubSys, KLogComponent , _L8("CExitCommand::DoCommandL - Stop scheduler")); + + //Quit the main console + iTestConsole.Stop(); + } + + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/src/ncmtestconsole.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/src/ncmtestconsole.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,565 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + + +#include "ncmtestconsole.h" +#include "ncmtestdefines.hrh" +#include "commandengine.h" +#include "devicewatcher.h" +#include "servicewatcher.h" +#include "ncmwatcher.h" +#include "exitcommand.h" +#include "setncmiapcommand.h" +#include "simpancommand.h" +#include "tcpcommand.h" + +#include +#include +#include +#include + +//#include +using namespace UsbNcm; + +//The app parameter +_LIT(KArgDemo, "DEMO"); + +//Set the display item length +//every display item has fixed length. It will be displayed screen permanently. +//The details about how to use display item is in CUsbNcmConsole::DrawL() +TInt gDisplayItemLength[] = { + DISPLAY_USB_SERVICE_STATE_LEN, //EUsbServiceStateItem + DISPLAY_USB_DEVICE_STATE_LEN, //EUsbDeviceStateItem + DISPLAY_NCM_CONN_STATE_LEN, //ENcmConnStatusItem + DISPLAY_NCM_CONN_IP_LEN, //ENcmConnIpItem + DISPLAY_UPLINK_CONN_STATE_LEN, //EUplinkConnStatusItem + DISPLAY_UPLINK_CONN_IP_LEN, //EUplinkConnIpItem + DISPLAY_NCM_BTPAN_LEN, //ENcmBtPanItem + DISPLAY_AGENT_STATE_LEN, //ENcmAgentStateItem + DISPLAY_AUTH_SETTING_LEN, //EAuthorisationSettingItem + DISPLAY_NCM_CONNECTION_STATE + }; + +void Panic(TInt aPanic) + { + User::Panic(_L("NcmTestConsole"), aPanic); + } + + +void RunConsoleL() + { + TInt cmdLineLength(User::CommandLineLength()); + HBufC* cmdLine = HBufC::NewMaxLC(cmdLineLength); + TPtr cmdLinePtr = cmdLine->Des(); + User::CommandLine(cmdLinePtr); + + TLex args(*cmdLine); + // args are separated by spaces + args.SkipSpace(); + + TPtrC cmdToken = args.NextToken(); + HBufC* tc = HBufC::NewLC(80); + *tc = cmdToken; + + TBool isDemo = EFalse; + + //Find if there is 'DEMO' or not. + while (tc->Length()) + { + TInt pos = tc->FindF(KArgDemo); + if ( pos != KErrNotFound ) + { + isDemo = ETrue; + break; + } + + // next parameter + *tc = args.NextToken(); + } + CleanupStack::PopAndDestroy(tc); + CleanupStack::PopAndDestroy(cmdLine); + + CUsbNcmConsole* console = CUsbNcmConsole::NewLC(isDemo); + console->StartL(); + CleanupStack::PopAndDestroy(console); + } + +TInt E32Main() + { + __UHEAP_MARK; + CTrapCleanup* cleanup = CTrapCleanup::New(); + CActiveScheduler* activeScheduler = new CActiveScheduler; + TInt err = KErrNoMemory; + if(cleanup && activeScheduler) + { + CActiveScheduler::Install(activeScheduler); + TRAP(err,RunConsoleL()); + } + delete activeScheduler; + delete cleanup; + __UHEAP_MARKEND; + return err; + } + +CUsbNcmConsoleEvent* CUsbNcmConsoleEvent::NewL() + { + CUsbNcmConsoleEvent* self = new(ELeave) CUsbNcmConsoleEvent(); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + return self; + + } + +CUsbNcmConsoleEvent::CUsbNcmConsoleEvent() + { + } + +CUsbNcmConsoleEvent::~CUsbNcmConsoleEvent() + { + iLink.Deque(); + iEvent.Close(); + } + +void CUsbNcmConsoleEvent::ConstructL() + { + User::LeaveIfError(iEvent.Create(NUM_CHARACTERS_ON_LINE-1)); + } + + +CUsbNcmConsole* CUsbNcmConsole::NewLC(TBool aDemo) +/** +Constructs a CUsbNcmConsole object. + @param aDemo Indicate start NCM control app and NCM automaticly or manually + +When iDemo is ETrue, means ncmtestconsole starts as a demo. It will ask user to set ncm iap and +uplink iap.Then user can experience the NCM function by plug/unplug usb cable. +*/ + { + LOG_STATIC_FUNC_ENTRY + + CUsbNcmConsole* self = new(ELeave) CUsbNcmConsole(aDemo); + CleanupStack::PushL(self); + self->ConstructL(); + return self; + } + +CUsbNcmConsole::~CUsbNcmConsole() + { + LOG_FUNC + + //If Ncm control app is not stopped, stop it. + //destroy all commands + delete iKeys; + + //destroy event list + TDblQueIter iter(iEventList); + CUsbNcmConsoleEvent* event = NULL; + while((event = iter++) != NULL) + { + delete event; + } + + //delete iStartWatcherCallback; + + //destroy all watches + delete iSharedStateWatcher; + delete iDeviceWatcher; + delete iServiceWatcher; + + iUsb.Close(); + + delete iConsole; + + //Destroy all display items + for(TInt i=0; iRegisterCommand(command); + //Get the default iap used by ncm + TInt defaultIap = 0; + ((CSetNcmIapCommand*)command)->GetDefaultIapL(defaultIap); + SetLocalIapId(defaultIap); + + //the command to simulate PAN actvie/inactive + command = CSimPANCommand::NewL(*this, 'p'); + iKeys->RegisterCommand(command); + + //the command to create a connection from PC to H4 and make data transfer + command = CTcpCommand::NewL(*this, 'v', ETrue, ETrue); + iKeys->RegisterCommand(command); + //the command to create a connection from H4 to PC and make data transfer + command = CTcpCommand::NewL(*this, 'i', ETrue, EFalse); + iKeys->RegisterCommand(command); + + command = CTcpCommand::NewL(*this , 'r', EFalse, ETrue); + iKeys->RegisterCommand(command); + command = CTcpCommand::NewL(*this , 's', EFalse, EFalse); + iKeys->RegisterCommand(command); + + //here to add new command + + //the command to quit + command = CExitCommand::NewL(*this, 'q'); + iKeys->RegisterCommand(command); + + //Monitor the status published by NCM agent + iSharedStateWatcher = CSharedStateWatcher::NewL(*this); + } + +void CUsbNcmConsole::StartL() + { + //Output the init state to screen + DrawL(); + //Do StartWatcherCommand if 'demo' is the command parameter + if(iDemo) + { +// iStartWatcherCallback->CallBack(); + } + CActiveScheduler::Start(); + } + +void CUsbNcmConsole::Stop() const + { + CActiveScheduler::Stop(); + } + +void CUsbNcmConsole::DoCancel() + { + } + +void CUsbNcmConsole::RunL() + { + DrawL(); + } + +TInt CUsbNcmConsole::RunError(TInt aError) + { + User::Panic(_L("CUsbNcmConsole"), aError); + return aError; + } + +void CUsbNcmConsole::ScheduleDraw(TUint aKey) +/** +Called by commands and monitors.To notify main console there's new infomation to show. + @param aKey Display type. '1'-'9' - display the command help + 'E' - display the events. + '0' - back from command help +*/ + { + iHelp = aKey; + if(!IsActive()) + { + SetActive(); + TRequestStatus* status = &iStatus; + User::RequestComplete(status, KErrNone); + } + } + +RUsb& CUsbNcmConsole::Usb() + { + return iUsb; + } + +void CUsbNcmConsole::SetLocalIapId(TInt aId) +/** +Set the Ncm Iap which will be monitored and displayed on screen + @param aId The Ncm Iap Id +*/ + { + iLocalIapId = aId; + ScheduleDraw('E'); + } + +void CUsbNcmConsole::NotifyEvent(CUsbNcmConsoleEvent* aEvent) +/** +Called by commands and monitors. To tell main console to display the new event. + @param aEvent Event reported by commands and monitors +*/ + { + //Console can't display a NULL event + __ASSERT_ALWAYS(aEvent, Panic(ENcmEventIsNull)); + //Console can't display a string more than one line + __ASSERT_ALWAYS(aEvent->iEvent.Length() <= NUM_CHARACTERS_ON_LINE, Panic(ENcmEventLengthValid)); + + iEventList.AddFirst(*aEvent); + CUsbNcmConsoleEvent* theLastEvent = iEventList.Last(); + delete theLastEvent; + + ScheduleDraw('E'); + } + +void CUsbNcmConsole::DrawL() +/** +Display all infomation on screen. +There are two parts on the screen. One is permanent info. It will display all kinds of states such as USB device state, +USB service state, NCM state, and so on. The other is event info show. It will display the events reported by monitors +and commands. It also used to show command help when user need command help. +*/ + { + iConsole->ClearScreen(); + // First line is the server version number + TVersionName versionName = iVersion.Name(); + iConsole->Printf(_L( + // 1 2 3 4 5 + // 12345678901234567890123456789012345678901234567890123 + "Server Version: %S %S\n" + ), + &versionName, &iDisplayArray[EAuthorisationSettingItem] + ); + + + iConsole->Printf(_L("Service: %S Device: %S\n"), + &iDisplayArray[EUsbServiceStateItem], &iDisplayArray[EUsbDeviceStateItem]); + iConsole->Printf(_L("NCM Iap:%2d state:%S IP:%S\n"), + iLocalIapId, &iDisplayArray[ENcmConnStatusItem], &iDisplayArray[ENcmConnIpItem]); + iConsole->Printf(_L("Active:%S NcmConnection:%S\n"), + &iDisplayArray[ENcmBtPanItem], &iDisplayArray[ENcmAgentStateItem]); + iConsole->Printf(_L("Ncm connection:%S\n"), &iDisplayArray[ENcmConnectionStateItem]); + + if ((iHelp > 0) && (iHelp <=9)) + { + iConsole->Printf(_L("Press 0 to quit help\n\n")); + //Display the command help + iKeys->PrintHelp(iHelp); + } + else + { + iConsole->Printf(_L("Press 1 to 9 to get menu help\n\n")); + //Display the event list + TDblQueIter iter(iEventList); + CUsbNcmConsoleEvent* event = NULL; + while((event = iter++) != NULL) + { + iConsole->Printf(event->iEvent.Left(NUM_CHARACTERS_ON_LINE-1)); + iConsole->Printf(_L("\n")); + } + } + } + + +void CUsbNcmConsole::CreateDisplayItemL() +/** +Init the display item. +*/ + { + for(TInt i = 0; i < ELastItem; i++) + { + RBuf buf; + iDisplayArray.AppendL(buf); + iDisplayArray[i].CreateL(gDisplayItemLength[i]); + } + } + +void CUsbNcmConsole::SetDisplayItem(TInt aIndex, TDes& aInfo) +/** +Called by commands and monitors to show the changed info in screen +*/ + { + //Prevent array is out of bound + __ASSERT_ALWAYS(((aIndex < ELastItem) && (aIndex >= 0)), Panic(ENcmDisplayItemVaild)); + + iDisplayArray[aIndex].SetLength(0); + iDisplayArray[aIndex].Copy(aInfo); + + ScheduleDraw('E'); + } + +TInt CUsbNcmConsole::LocalIapId() const + { + return iLocalIapId; + } + +const TDes& CUsbNcmConsole::GetDisplayItem(TInt aIndex) + { + //Prevent array is out of bound + __ASSERT_ALWAYS(((aIndex < ELastItem) && (aIndex >= 0)), Panic(ENcmDisplayItemVaild)); + + return iDisplayArray[aIndex]; + } + + +TInt CUsbNcmConsole::DoCommandCallback(TAny *aThisPtr) + { + CNcmCommandBase* command = static_cast(aThisPtr); + TRAPD(err,command->DoCommandL()); + if(err != KErrNone) + { + User::Panic(_L("DoCommandCallback"), err); + } + return err; + } + + +TInt CUsbNcmConsole::DrawAvailableIapsL() +/** +Display commsdb's iaps on console +@return the count of iaps +*/ + { + LOG_FUNC + __FLOG_STATIC0(KSubSys, KLogComponent , _L8("CNcmTestUtil::DrawAvailableIapsL")); + + iConsole->Printf(_L("CommDB IAPs:\n")); + iConsole->Printf(_L("ID: Name\n")); + + //Get commsdb handle + CCommsDatabase* db = CCommsDatabase::NewL(); + __FLOG_STATIC0(KSubSys, KLogComponent , _L8("Get CommsDatabase ok")); + CleanupStack::PushL(db); + + //Get Iap table infomation + CCommsDbTableView* iapTableView = db->OpenTableLC(TPtrC(IAP)); + __FLOG_STATIC0(KSubSys, KLogComponent , _L8("OpenTableLC ok")); + + + TUint32 iapId; + TBuf<128> iapName; + TInt iapCount = 0; + + for (TInt iapTableErr = iapTableView->GotoFirstRecord(); iapTableErr == KErrNone; iapTableErr = iapTableView->GotoNextRecord()) + { + //Get every IAP + iapTableView->ReadTextL(TPtrC(COMMDB_NAME), iapName); + iapTableView->ReadUintL(TPtrC(COMMDB_ID), iapId); + + __FLOG_STATIC2(KSubSys, KLogComponent , _L8("Read: %d: %S"), iapId, &iapName); + + iConsole->Printf(_L("%d: %S\n"), iapId, &iapName); + iapCount++; + } + + if (0 == iapCount) + { + iConsole->Printf(_L("No available IAP!\n")); + } + + CleanupStack::PopAndDestroy(2); // iapTableView, db + return iapCount; + + } + +TBool CUsbNcmConsole::AttachConnectionL(TInt aIap, RConnection& aConnection) +/** +Try to attach the connection specified by iIapId. If attach failed or no specified connection,return false +*/ + { + LOG_FUNC + __FLOG_STATIC1(KSubSys, KLogComponent , _L8("AttachConnectionL aIap=%d"), aIap); + + TBool result = ETrue; + TUint count = 0; + //Get active connections + User::LeaveIfError(aConnection.EnumerateConnections(count)); + __FLOG_STATIC2(KSubSys, KLogComponent , _L8("active connection count = %d, watch iap = %d"), count, aIap); + + TBool hasConnection = EFalse; + for(TInt i = 1; i <= count; i++) + { + TPckgBuf info; + User::LeaveIfError(aConnection.GetConnectionInfo(i,info)); + TUint32 id = info().iIapId; + __FLOG_STATIC2(KSubSys, KLogComponent , _L8("aIap=%d, id=%d"), aIap, id); + + if(id == aIap) + { + hasConnection = ETrue; + //The connection is the connection specified by aIap + __FLOG_STATIC0(KSubSys, KLogComponent , _L8("Got it!")); + + //Attach the connection + TInt err = aConnection.Attach(info, RConnection::EAttachTypeMonitor); + if(err != KErrNone) + { + result = EFalse; + __FLOG_STATIC1(KSubSys, KLogComponent , _L8("Attach error[%d]"), err); + } + else + { + __FLOG_STATIC0(KSubSys, KLogComponent , _L8("Attach it!")); + } + break; + } + } + + if(!hasConnection) + { + //connection not found; + __FLOG_STATIC0(KSubSys, KLogComponent , _L8("No connection found!")); + result = EFalse; + } + + return result; + + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/src/ncmwatcher.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/src/ncmwatcher.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,103 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + +#include "ncmwatcher.h" +#include "ncmtestconsole.h" + +using namespace UsbNcm; + +// +// CSharedStateWatcher +// +CSharedStateWatcher* CSharedStateWatcher::NewL(CUsbNcmConsole& aConsole) + { + CSharedStateWatcher* self = new (ELeave) CSharedStateWatcher(aConsole); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + return self; + } + +CSharedStateWatcher::CSharedStateWatcher(CUsbNcmConsole& aConsole) : + CActive(EPriorityStandard), iConsole(aConsole), iNcmStateDes( + reinterpret_cast (&iSharedState), sizeof(iSharedState), + sizeof(iSharedState)) + { + CActiveScheduler::Add(this); + } + +CSharedStateWatcher::~CSharedStateWatcher() + { + Cancel(); + iProperty.Close(); + } + +void CSharedStateWatcher::ConstructL() + { + User::LeaveIfError(iProperty.Attach(KC32ExeSid, KKeyNcmConnectionEvent)); + reportState(); + iProperty.Subscribe(iStatus); + SetActive(); + } + +void CSharedStateWatcher::RunL() + { + TInt err = iStatus.Int(); + iProperty.Subscribe(iStatus); + SetActive(); + + if (KErrNone == err) + { + reportState(); + } + } + +void CSharedStateWatcher::reportState() + { + iProperty.Get(iNcmStateDes); + TBuf stateBuf; + switch (iSharedState.iState) + { + case ENcmStateDisconnected: + stateBuf = _L("DisConnected"); + break; + case ENcmStateConnected: + stateBuf = _L("Connected"); + break; + default: + stateBuf = _L("Unknown"); + break; + } + __FLOG_STATIC2(KSubSys, KLogComponent , + _L8("NCM state=%d, iapid=%d"), iSharedState.iState, iSharedState.iIapId); + + iConsole.SetLocalIapId(iSharedState.iIapId); + iConsole.SetDisplayItem(ENcmConnectionStateItem, stateBuf); + } + +/** + Stop checking the shared state + */ +void CSharedStateWatcher::DoCancel() + { + iProperty.Cancel(); + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/src/servicewatcher.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/src/servicewatcher.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,135 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + +#include "servicewatcher.h" +#include "ncmtestconsole.h" +#include "ncmtestdefines.hrh" + +CServiceWatcher* CServiceWatcher::NewL(CUsbNcmConsole& aTestConsole) + { + LOG_STATIC_FUNC_ENTRY + + CServiceWatcher* self = new(ELeave) CServiceWatcher(aTestConsole); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + return self; + } +CServiceWatcher::~CServiceWatcher() + { + Cancel(); + } + +CServiceWatcher::CServiceWatcher(CUsbNcmConsole& aTestConsole) + : CActive(EPriorityStandard), iTestConsole(aTestConsole) + { + CActiveScheduler::Add(this); + } + +void CServiceWatcher::ConstructL() + { + iTestConsole.Usb().ServiceStateNotification(iServiceState, iStatus); + SetActive(); + + TUsbServiceState serviceState; + User::LeaveIfError(iTestConsole.Usb().GetServiceState(serviceState)); + DisplayServiceState(serviceState); + } + +void CServiceWatcher::DoCancel() + { + iTestConsole.Usb().ServiceStateNotificationCancel(); + } + +void CServiceWatcher::RunL() + { + LOG_FUNC + __FLOG_STATIC2(KSubSys, KLogComponent , + _L8("CServiceWatcherCommand::RunL - iStatus = %d, iServiceState = %d"), + iStatus.Int(), iServiceState); + + User::LeaveIfError(iStatus.Int()); + + iTestConsole.Usb().ServiceStateNotification(iServiceState, iStatus); + SetActive(); + + iTestConsole.Usb().GetServiceState(iServiceState); + //Display the service state on main console + DisplayServiceState(iServiceState); + + } + +TInt CServiceWatcher::RunError(TInt aError) + { + User::Panic(_L("CServiceWatcher"), aError); + return aError; + } + +void CServiceWatcher::DisplayServiceState(TUsbServiceState aServiceState) +/** +Display the service state on main console + @param aServiceState Service state +*/ + { + TBuf servStatus; + switch(aServiceState) + { + case EUsbServiceIdle: + servStatus = + // 12345678901 + _L("Idle "); + break; + + case EUsbServiceStarting: + servStatus = + // 12345678901 + _L("Starting "); + break; + + case EUsbServiceStarted: + servStatus = + // 12345678901 + _L("Started "); + break; + + case EUsbServiceStopping: + servStatus = + // 12345678901 + _L("Stopping "); + break; + + case EUsbServiceFatalError: + servStatus = + // 12345678901 + _L("Error "); + break; + + default: + servStatus = + _L("Unknown "); + + break; + } + + iTestConsole.SetDisplayItem(EUsbServiceStateItem, servStatus); + + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/src/setncmiapcommand.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/src/setncmiapcommand.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,308 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + +#include "setncmiapcommand.h" +#include "ncmtestconsole.h" + +_LIT(KSetNcmIapCommandDescription, "Set Ncm Iap ID"); + +CSetNcmIapCommand* CSetNcmIapCommand::NewL(CUsbNcmConsole& aTestConsole, TUint aKey) + { + LOG_STATIC_FUNC_ENTRY + + CSetNcmIapCommand* self = new(ELeave) CSetNcmIapCommand(aTestConsole, aKey); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + return self; + } +CSetNcmIapCommand::~CSetNcmIapCommand() + { + EndWork(); + } + +CSetNcmIapCommand::CSetNcmIapCommand(CUsbNcmConsole& aTestConsole, TUint aKey) + : CNcmCommandBase(EPriorityStandard, aTestConsole, aKey) + { + CActiveScheduler::Add(this); + } + +void CSetNcmIapCommand::ConstructL() + { + SetDescription(KSetNcmIapCommandDescription()); + } + +void CSetNcmIapCommand::DoCommandL() +/** +Main function of set ncm iap. +It will start a new console to display all Iaps in commsdb and current setting for ncm. +Then prompt user to input ncm iap id and the index of this iap will be placed in central +repository. Press 'ESC' for give up this function. After the setting is successful, the +console will be destroyed and return to main console +*/ + { + LOG_FUNC + + if(!IsActive()) + { + //If the console has existed, close the old console. The work on old console will be + //gived up. + if(iConsole) + { + __FLOG_STATIC0(KSubSys, KLogComponent , _L8("Close old console")); + EndWork(); + } + InitWorkL(); + + iConsole->Printf(_L("Press \'ESC\' to exit without change\n")); + + //Display all iaps in commsdb + ListAllNcmIapL(); + + //wait user input iap id + iConsole->Printf(KSetIapMemo()); + iCommandState = EIapId; + iConsole->Read(iStatus); + SetActive(); + } + } + +void CSetNcmIapCommand::ListAllNcmIapL() +/** +Display all iaps in commsdb on console and get current config in cental repoistory +*/ + { + LOG_FUNC + + //Display commsdb's iaps + TInt iapcount = iTestConsole.DrawAvailableIapsL(); + + TInt iapId = 0; + + //Get iap config from central repository + TInt err = iRepository->FindL(KPartialKey, KMask, iRows); + if(err == KErrNone) + { + TUint count = iRows.Count(); + for (TInt row = 0; row < count; ++row) + { + // Read each IAP ID + User::LeaveIfError(iRepository->Get(iRows[row], iapId)); + __FLOG_STATIC2(KSubSys, KLogComponent , _L8("index[%d]: iap = %d"), row, iapId); + iConsole->Printf(_L("index[%d]: iap = %d\n"), row, iapId); + } + } + else + { + __FLOG_STATIC1(KSubSys, KLogComponent , _L8("FindL() err[%d]"), err); + } + } + +void CSetNcmIapCommand::GetDefaultIapL(TInt& aDefaultIap) +/** +Get the default iap id (The first one) stored in central repository. +@return the default iap id +*/ + { + LOG_FUNC + aDefaultIap = 13; + return ; + } + +void CSetNcmIapCommand::SetNcmIapL() +/** +Set iap id into central repository. The iap id is iIapId. The place of iap id in central +repository is iIndex. iIndex is started from 0. If the iIndex is not exist in central +repository, iIapId will be placed at last place. +*/ + { + LOG_FUNC + + TUint count = iRows.Count(); + __FLOG_STATIC1(KSubSys, KLogComponent , _L8("now iap count = %d"), count); + + TInt idx; + if(iIndex >= count) + { + //iIndex is not exist in central repository, create a new entry in central repository + idx = iRows[count-1]+1; + User::LeaveIfError(iRepository->Create(idx, iIapId)); + __FLOG_STATIC2(KSubSys, KLogComponent , _L8("add iap: idx = %d, iIapId"), idx, iIapId); + } + else + { + //iIndex exists, just set in the new value + idx = iRows[iIndex]; + User::LeaveIfError(iRepository->Set(idx, iIapId)); + __FLOG_STATIC2(KSubSys, KLogComponent , _L8("set iap: aIdx = %d, iIapId"), idx, iIapId); + } + + } + +void CSetNcmIapCommand::RunL() + { + LOG_FUNC + __FLOG_STATIC1(KSubSys, KLogComponent , _L8("CSetNcmIapCommand::RunL - iStatus = %d"), iStatus.Int()); + + User::LeaveIfError(iStatus.Int()); + + TKeyCode code = iConsole->KeyCode(); + switch(code) + { + case EKeyEnter: + { + iConsole->Printf(_L("\n")); + + //get value + TInt val; + TBool typeErr = EFalse; + if(iChars.Length() != 0) + { + TLex lex(iChars); + lex.SkipSpaceAndMark(); + + if(KErrNone != lex.Val(val)) + { + typeErr = ETrue; + } + } + else + { + typeErr = ETrue; + } + + if(typeErr) + { + //Prompt user input again + iConsole->Printf(KErrInput()); + iConsole->Printf(KSetIapMemo()); + iChars.SetLength(0); + __FLOG_STATIC0(KSubSys, KLogComponent , _L8("Input error")); + break; + } + + //The input is correct + __FLOG_STATIC1(KSubSys, KLogComponent , _L8("Get val = %d"), val); + + if(iCommandState == EIapId) + { + //if the command state is wait iap id, now get the iap id, wait for iap index + iIapId = val; + iChars.SetLength(0); + iConsole->Printf(KSetIapIndexMemo()); + iCommandState = EIapPriority; + } + else //(iCommandState == EIapPriority) + { + //if the command state is wait iap index, now the index. set into central repoistory. + //Then destroy the current console and update the value displayed on main console if the + //setting value is ncm default value. + iIndex = val; + SetNcmIapL(); + EndWork(); + if(iIndex == 0) + { + iTestConsole.SetLocalIapId(iIapId); + } + __FLOG_STATIC2(KSubSys, KLogComponent , _L8("Set Ncm Iap, idx = %d, id = %d"), + iIndex, iIapId); + + return; + } + } + break; + case EKeyEscape: + //delete this; + EndWork(); + return; + case EKeyBackspace: + if(iChars.Length() > 0) + { + iConsole->SetCursorPosRel(TPoint(-1, 0)); + iConsole->ClearToEndOfLine(); + iChars.SetLength(iChars.Length()-1); + } + break; + default: + iChars.Append(code); + iConsole->Printf(_L("%c"), code); + break; + } + iConsole->Read(iStatus); + SetActive(); + + } + +void CSetNcmIapCommand::DoCancel() + { + iConsole->ReadCancel(); + } + +TInt CSetNcmIapCommand::RunError(TInt aError) + { + User::Panic(_L("CSetNcmIapCommand"), aError); + return aError; + } + +void CSetNcmIapCommand::InitWorkL() +/** +Initialize work. Including start a new console, create buf for getting user input, get repoistory handle. +*/ + { + LOG_FUNC + + if(!iConsole) + { + iConsole = Console::NewL(_L("Set Ncm IAP Console"), TSize(-1,-1)); + __FLOG_STATIC0(KSubSys, KLogComponent , _L8("Create Console ok!")); + + User::LeaveIfError(iChars.Create(KMaxNumOfChars)); + __FLOG_STATIC0(KSubSys, KLogComponent , _L8("Create iChars ok!")); + + iRepository = CRepository::NewL(KNcmIapIdRepositoryUID); + __FLOG_STATIC0(KSubSys, KLogComponent , _L8("Get CRepository ok!")); + + iIapId = 1; + iIndex = 0; + } + } + +void CSetNcmIapCommand::EndWork() +/** +Finalize work. Including delete console, delete the buf used for getting user input, close repoistory handle. +*/ + { + LOG_FUNC + + if(iConsole) + { + __FLOG_STATIC0(KSubSys, KLogComponent , _L8("Destroy console...")); + Cancel(); + iChars.Close(); + iRows.Close(); + delete iRepository; + delete iConsole; + iConsole = NULL; + __FLOG_STATIC0(KSubSys, KLogComponent , _L8("Destroy console ok!")); + } + } + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/src/simpancommand.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/src/simpancommand.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,269 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + +#include + +#include "simpancommand.h" +#include "ncmtestconsole.h" + +static _LIT_SECURITY_POLICY_PASS(KAllowAllPolicy); +static _LIT_SECURITY_POLICY_C1(KNetworkControlPolicy, ECapabilityNetworkControl); + +_LIT(KSimPANCommandActive, "Simulate PAN connection is active"); +_LIT(KSimPANCommandNone, "Simulate PAN connection is not active"); + +CSimPANCommand* CSimPANCommand::NewL(CUsbNcmConsole& aTestConsole, TUint aKey) + { + LOG_STATIC_FUNC_ENTRY + + CSimPANCommand* self = new(ELeave) CSimPANCommand(aTestConsole, aKey); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + return self; + } +CSimPANCommand::~CSimPANCommand() + { + Cancel(); + iNcmExclusiveProp.Close(); + } + +CSimPANCommand::CSimPANCommand(CUsbNcmConsole& aTestConsole, TUint aKey) + : CNcmCommandBase(EPriorityStandard, aTestConsole, aKey) + { + } + +void CSimPANCommand::ConstructL() + { + //Attach the property of Exclusive state + User::LeaveIfError(iNcmExclusiveProp.Attach(KC32ExeSid, KIPBearerCoexistenceProperty)); + CActiveScheduler::Add(this); + iNcmExclusiveProp.Subscribe(iStatus); + SetActive(); + + //Get the current value of exclusive state + TInt state; + TInt err = iNcmExclusiveProp.Get(state); + switch(err) + { + case KErrNotFound: + //The property is not defined. means BtPAN and Ncm didn't start. + DisplayExclusive(ENoneIsActive); + break; + case KErrNone: + //Display the exclusive state on main console + DisplayExclusive(state); + break; + default: + User::LeaveIfError(err); + break; + } + + } + +void CSimPANCommand::RunL() +/** +Get the current exclusive state and update on main console when the state changed +*/ + { + LOG_FUNC + __FLOG_STATIC1(KSubSys, KLogComponent , _L8("CNcmExclusiveStateAO::RunL - iStatus = %d"), iStatus.Int()); + + User::LeaveIfError(iStatus.Int()); + + iNcmExclusiveProp.Subscribe(iStatus); + SetActive(); + + TInt exclusiveState; + TInt err = iNcmExclusiveProp.Get(exclusiveState); + + __FLOG_STATIC2(KSubSys, KLogComponent , _L8("Get[IPBearerCoexistence]=%d, err=%d"), exclusiveState, err); + + if(err == KErrNone) + { + //Display the exclusive state on main console + DisplayExclusive(exclusiveState); + } + } + +void CSimPANCommand::DoCancel() + { + iNcmExclusiveProp.Cancel(); + } + +TInt CSimPANCommand::RunError(TInt aError) + { + User::Panic(_L("CSimPANCommand"), aError); + return aError; + } + +void CSimPANCommand::DoCommandL() +/** +Main function of simualate Pan active/inactive. +It will try to get the exclusive state from P&S key. And set the value based on the iSetPAN. +There's three value for this P&S key: EExclusiveNone,ENcmOwned,EBtPanOwned + +If now the command is 'active PAN'(iSetPAN=ETrue), then set the value of property to Pan active. +If now the command is 'inactive PAN'(iSetPAN=EFalse), then set the value of property to Pan inactive. +*/ + { + LOG_FUNC + + //Get the mutex which used to protect the P&S key. + RMutex mtx; + TInt ret; + ret = mtx.CreateGlobal(KIPBearerCoexistenceMutex); + if (ret == KErrAlreadyExists) + { + ret = mtx.OpenGlobal(KIPBearerCoexistenceMutex); + } + User::LeaveIfError(ret); + __FLOG_STATIC0(KSubSys, KLogComponent , _L8("Get Mutex, wait()")); + CleanupClosePushL(mtx); + mtx.Wait(); + + RProperty prop; + TInt state; + TBool bSet = ETrue; + + //Get the exclusive state. + ret = prop.Get(KC32ExeSid, KIPBearerCoexistenceProperty, state); + CleanupClosePushL(prop); + __FLOG_STATIC2(KSubSys, KLogComponent , _L8("Get Property[IPBearerCoexistence]: ret=%d, val=%d"), ret, state); + + switch(ret) + { + case KErrNotFound: + { + //The property not exists. (NCM not start.) + + __FLOG_STATIC0(KSubSys, KLogComponent , _L8("Not define property yet. define it")); + CUsbNcmConsoleEvent* event = CUsbNcmConsoleEvent::NewL(); + event->iEvent.AppendFormat(_L("Not define property yet. define it.")); + iTestConsole.NotifyEvent(event); + + //Define the property + User::LeaveIfError(RProperty::Define(KC32ExeSid, KIPBearerCoexistenceProperty, RProperty::EInt, KAllowAllPolicy, KNetworkControlPolicy)); + __FLOG_STATIC0(KSubSys, KLogComponent , _L8("Define Property[IPBearerCoexistence] ok")); + break; + } + case KErrNone: + { + //property exists. + if(state == ENcmIsActive) + { + //Ncm hold the key. PAN can't active. Do nothing in this command. + CUsbNcmConsoleEvent* event = CUsbNcmConsoleEvent::NewL(); + event->iEvent.AppendFormat(_L("NCM hold the P&S key!")); + iTestConsole.NotifyEvent(event); + bSet = EFalse; + } + break; + } + default: + { + //error when get P&S key. + CUsbNcmConsoleEvent* event = CUsbNcmConsoleEvent::NewL(); + event->iEvent.AppendFormat(_L("Get P&S key error! err = %d"), ret); + iTestConsole.NotifyEvent(event); + bSet = EFalse; + break; + } + } + + if(bSet) + { + //Set the property value + CUsbNcmConsoleEvent* event = CUsbNcmConsoleEvent::NewL(); + CleanupStack::PushL(event); + if(this->iSetPAN) + { + User::LeaveIfError(prop.Set(KC32ExeSid, KIPBearerCoexistenceProperty, EBTPanIsActive)); + __FLOG_STATIC1(KSubSys, KLogComponent , _L8("Set Property[IPBearerCoexistence]: val = %d"), EBTPanIsActive); + event->iEvent.AppendFormat(_L("Set PAN active! prop=%d"), EBTPanIsActive); + } + else + { + User::LeaveIfError(prop.Set(KC32ExeSid, KIPBearerCoexistenceProperty, ENoneIsActive)); + __FLOG_STATIC1(KSubSys, KLogComponent , _L8("Set Property[IPBearerCoexistence]: val = %d"), ENoneIsActive); + event->iEvent.AppendFormat(_L("Set PAN disactive! prop=%d"), ENoneIsActive); + } + CleanupStack::Pop(event); + iTestConsole.NotifyEvent(event); + + } + + CleanupStack::Pop(2, &mtx); //prop, mtx + mtx.Signal(); + prop.Close(); + mtx.Close(); + + } + +void CSimPANCommand::ChangeDescription() + { + if(iSetPAN) + { + SetDescription(KSimPANCommandActive()); + } + else + { + SetDescription(KSimPANCommandNone()); + } + } + +void CSimPANCommand::DisplayExclusive(TInt aState) +/** +Display the exclusive state on main console and change the description of command by the +value of aState + @param aState Exclusive state +*/ + { + TBuf exclusive; + iSetPAN = ETrue; + switch(aState) + { + case ENoneIsActive: + { + exclusive = _L("None "); + } + break; + case ENcmIsActive: + { + exclusive = _L("NCM "); + } + break; + case EBTPanIsActive: + { + exclusive = _L("BT PAN "); + //If Bt Pan is active, the command description should be 'disactive BT PAN' + iSetPAN = EFalse; + } + break; + default: + exclusive = _L(" "); + break; + } + + ChangeDescription(); + iTestConsole.SetDisplayItem(ENcmBtPanItem, exclusive); + } diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/src/tcpcommand.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/src/tcpcommand.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,142 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + +#include "tcpcommand.h" +#include "tcptest.h" +#include "ncmtestconsole.h" + +_LIT(KTcpClientCommandDescription, "Create tcp connection from H4 to PC"); +_LIT(KTcpServerCommandDescription, "Create tcp connection from PC to H4"); +_LIT(KUdpClientCommandDescription, "Create udp connection from H4 to PC"); +_LIT(KUdpServerCommandDescription, "Create udp connection from PC to H4"); + + +const TInt KDefaultPortFrom = 5000; + +CTcpCommand* CTcpCommand::NewL(CUsbNcmConsole& aTestConsole, TUint aKey, TBool aIsTcp, TBool aIsServer) + { + LOG_STATIC_FUNC_ENTRY + + CTcpCommand* self = new(ELeave) CTcpCommand(aTestConsole, aKey, aIsTcp, aIsServer); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + return self; + } +CTcpCommand::~CTcpCommand() + { + for(TInt i = 0; i < KMaxTcpTestCount; i++) + { + delete iTestArray[i]; + } + } + +CTcpCommand::CTcpCommand(CUsbNcmConsole& aTestConsole, TUint aKey, TBool aIsTcp, TBool aIsServer) + : CNcmCommandBase(EPriorityStandard, aTestConsole, aKey), iIsTcp(aIsTcp), iIsServer(aIsServer) + { + } + +void CTcpCommand::ConstructL() + { + if (iIsServer) + { + if (iIsTcp) + { + SetDescription(KTcpServerCommandDescription()); + } + else + { + SetDescription(KUdpServerCommandDescription()); + } + } + else + { + if (iIsTcp) + { + SetDescription(KTcpClientCommandDescription()); + } + else + { + SetDescription(KUdpClientCommandDescription()); + } + } + } + +void CTcpCommand::DoCommandL() + { + LOG_FUNC + + //Create an CTcpTestConsole object to run the tcp test. + TBool noRun = ETrue; + for(TInt i = 0; i < KMaxTcpTestCount; i++) + { + if(!iTestArray[i]) + { + //create the default parameter for tcp test + // as a server : the parameter is port (Listen at which port) + // as a client : the parameter is ip and port. IP is got from NCM's IP + 1 + // (The DHCP server will assign "NCM's IP+1" to PC.) + RBuf addr; + addr.CreateL(30); + + if(!iIsServer) + { + TInetAddr serverIP; + serverIP.Input(_L("192.168.3.100")); + //serverIP.Input(iTestConsole.GetDisplayItem(ENcmConnIpItem)); + TUint32 serverAddr = serverIP.Address(); + TUint32 hostId = (serverAddr & ~KInetAddrNetMaskC) + 1; + if (hostId >= 255) + { + hostId = 1; + } + TUint32 clientAddr = (serverAddr & KInetAddrNetMaskC) | hostId; + TInetAddr clientIP(clientAddr, 0); + clientIP.Output(addr); + } + + addr.AppendFormat(_L(" %d"), KDefaultPortFrom+i); + //Create a tcp test console + iTestArray[i] = CTcpTestConsole::NewL(iIsTcp, iIsServer, addr, i, *this); + noRun = EFalse; + addr.Close(); + break; + } + } + if(noRun) + { + //The count of tcp test is up to the max value. + CUsbNcmConsoleEvent* event = CUsbNcmConsoleEvent::NewL(); + TInt count = KMaxTcpTestCount; + event->iEvent.AppendFormat(_L("The test connection is up to %d.Please close some."), count); + iTestConsole.NotifyEvent(event); + } + } + +void CTcpCommand::CloseTcpTest(TInt aIndex) + { + __ASSERT_ALWAYS(((aIndex < KMaxTcpTestCount) && (aIndex >= 0)), Panic(ENcmArrayBound)); + + delete iTestArray[aIndex]; + iTestArray[aIndex] = NULL; + } + diff -r 2fefb5a2b416 -r f1fd07aa74c9 usbmgmt/usbmgrtest/t_ncm/src/tcptest.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/usbmgmt/usbmgrtest/t_ncm/src/tcptest.cpp Wed Jul 07 14:16:40 2010 +0800 @@ -0,0 +1,612 @@ +/* +* Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +/** @file + @internalComponent + @test + */ + +#include "tcptest.h" +#include +#include +#include +#include "tcpcommand.h" +#include "ncmtestconsole.h" + +_LIT8(KSendData, "TCP-Packet::HelloWorld\n"); + +static const TInt KMaxNumOfChars = 255; + +//The title of TCP test console +_LIT(KTcpServerMode, "Tcp Server"); +_LIT(KTcpClientMode, "Tcp Client"); + +//The default value of data size +static const TInt KDefaultDataSize = 30; + +CTcpProcess* CTcpProcess::NewL(CConsoleBase& aConsole, TInetAddr& aAddr, TInt aPort, TInt aSize, TBool aMode) + { + CTcpProcess* self = new(ELeave) CTcpProcess(aConsole, aAddr, aPort, aSize, aMode); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + return self; + } + +CTcpProcess::~CTcpProcess() + { + Cancel(); + iRecvBuf.Close(); + iSendBuf.Close(); + iSocket.Close(); + iListenSocket.Close(); + iSockServ.Close(); + } + +CTcpProcess::CTcpProcess(CConsoleBase& aConsole, TInetAddr& aAddr, TInt aPort, TInt aSize, TBool aMode) + : CActive(EPriorityStandard), iConsole(aConsole), iAddr(aAddr), iPort(aPort), iSize(aSize), iMode(aMode) + { + CActiveScheduler::Add(this); + } + +void CTcpProcess::ConstructL() + { + //Create the data buffer + User::LeaveIfError(iSendBuf.Create(iSize)); + User::LeaveIfError(iRecvBuf.Create(iSize)); + iRecvSize = iSize; + + iProcessState = ECreateConnection; + + User::LeaveIfError(iSockServ.Connect()); + if(iMode) + { + //Listen at specified port + TBuf<5> protocol = _L("tcp"); + User::LeaveIfError(iListenSocket.Open(iSockServ, protocol)); + User::LeaveIfError(iListenSocket.SetOpt(KSoReuseAddr, KProtocolInetIp, 1)); + User::LeaveIfError(iListenSocket.SetLocalPort(iPort)); + User::LeaveIfError(iListenSocket.Listen(5)); + User::LeaveIfError(iSocket.Open(iSockServ)); + iListenSocket.Accept(iSocket, iStatus); + iConsole.Printf(_L("\nWait for a connection at port[%d].\n"), iPort); + } + else + { + RConnection conn; + User::LeaveIfError(conn.Open(iSockServ)); + TCommDbConnPref pref; + pref.SetIapId(13); + pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); + User::LeaveIfError(conn.Start(pref)); + + //Connect to specified server + User::LeaveIfError(iSocket.Open(iSockServ, KAfInet, KSockStream, KProtocolInetTcp, conn)); + iSocket.Connect(iAddr, iStatus); + + iConsole.Printf(_L("\nConnecting....\n")); + } + SetActive(); + } + + +void CTcpProcess::RunL() + { + switch(iProcessState) + { + case ECreateConnection: + //Get result of connect + if(iStatus.Int() != KErrNone) + { + iConsole.Printf(_L("Connect err[%d].\nPress any key to quit."), iStatus.Int()); + return; + } + else + { + //A TCP connection is created. + if(iMode) + { + iConsole.Printf(_L("Get a connection.\n")); + } + else + { + iConsole.Printf(_L("\nConnected.\n")); + } + iProcessState = EDataTransfer; + + //Ready for read data + iSocket.RecvOneOrMore(iRecvBuf, 0, iStatus, iRecvSize); + __FLOG_STATIC1(KSubSys, KLogComponent , _L8("Ready for read data"), iRecvSize); + SetActive(); + if(!iMode) + { + //As a client, send data first. + iSendBuf.SetLength(iSize); + iSendBuf.Repeat(KSendData()); + + iConsole.Printf(_L("Send data.")); + PrintData(iSendBuf); + TInt sendLen = SendDataL(iSendBuf, iSize); + if(sendLen != iSize) + { + iConsole.Printf(_L("The length of data sent is not equal to requested! requested[%d], sent[%d]"), + iSize, sendLen); + } + } + } + break; + + case EDataTransfer: + //In data transfer, some data is received + iConsole.Printf(_L("recv Package, size[%d], status[%d]\n"), iRecvSize(), iStatus.Int()); + if((KErrEof == iStatus.Int()) || (KErrDisconnected == iStatus.Int())) + { + iConsole.Printf(_L("Connection closed!")); + return; + } + else if(KErrNone == iStatus.Int()) + { + iConsole.Printf(_L("Receive data.")); + PrintData(iRecvBuf); + + if(iMode) + { + //As a server, send back the data received + TInt len = SendDataL(iRecvBuf, iRecvSize()); + iConsole.Printf(_L("Send back the data. len[%d]"), len); + } + } + iRecvBuf.SetLength(0); + iRecvSize = iSize; + iSocket.RecvOneOrMore(iRecvBuf, 0, iStatus, iRecvSize); + SetActive(); + + break; + } + } + +void CTcpProcess::DoCancel() + { + switch(iProcessState) + { + case ECreateConnection: + if(iMode) + { + iListenSocket.CancelAccept(); + } + else + { + iSocket.CancelConnect(); + } + break; + case EDataTransfer: + iSocket.CancelRecv(); + break; + } + } + +TInt CTcpProcess::RunError(TInt aError) + { + User::Panic(_L("CTcpProcess"), aError); + return aError; + } + +TInt CTcpProcess::SendDataL(TDes8& aData, TInt aSize) +/** +Send data. + @return the size of data sent + */ + { + TRequestStatus status; + TSockXfrLength sendSize = aSize; + iSocket.Send(aData, 0, status, sendSize); + User::WaitForRequest(status); + + switch(status.Int()) + { + case KErrEof: + iConsole.Printf(_L("Connection closed!")); + return 0; + case KErrNone: + iConsole.Printf(_L("Send successfully.")); + break; + default: + User::LeaveIfError(status.Int()); + break; + } + return sendSize(); + } + +void CTcpProcess::PrintData(TDes8& aData) + { + iConsole.Printf(_L("The data is: \n")); + for(TInt i=0; i< aData.Length();i++) + { + iConsole.Printf(_L("%c"), aData[i]); + } + iConsole.Printf(_L("\n")); + } + +CUdpProcess* CUdpProcess::NewL(CConsoleBase& aConsole, TInetAddr& aAddr, + TInt aPort, TInt aSize, TBool aMode) + { + CUdpProcess* self = new (ELeave) CUdpProcess(aConsole, aAddr, aPort, + aSize, aMode); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + return self; + } + +CUdpProcess::~CUdpProcess() + { + Cancel(); + iRecvBuf.Close(); + iSendBuf.Close(); + iSocket.Close(); + iListenSocket.Close(); + iSockServ.Close(); + } + +CUdpProcess::CUdpProcess(CConsoleBase& aConsole, TInetAddr& aAddr, + TInt aPort, TInt aSize, TBool aMode) : + CActive(EPriorityStandard), iConsole(aConsole), iAddr(aAddr), + iPort(aPort), iSize(aSize), iMode(aMode) + { + CActiveScheduler::Add(this); + } + +void CUdpProcess::ConstructL() + { + //Create the data buffer + User::LeaveIfError(iSendBuf.Create(iSize)); + User::LeaveIfError(iRecvBuf.Create(iSize)); + iRecvSize = iSize; + + User::LeaveIfError(iSockServ.Connect()); + + // Start NCM IAP + RConnection conn; + User::LeaveIfError(conn.Open(iSockServ)); + TCommDbConnPref pref; + pref.SetIapId(13); + pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt); + User::LeaveIfError(conn.Start(pref)); + + User::LeaveIfError(iSocket.Open(iSockServ, KAfInet, KSockDatagram, + KProtocolInetUdp, conn)); + + iConsole.Printf(_L("In constructL, port=%d"), iAddr.Port()); + + if (iMode) + { + iProcessState = EDataTransfer; + + User::LeaveIfError(iSocket.SetLocalPort(iPort)); + iSocket.RecvFrom(iRecvBuf, iPeerAddr, 0, iStatus); + iConsole.Printf(_L("\nWait for UDP incoming data at port[%d]...\n"),iPort); + SetActive(); + } + else + { + iProcessState = EDataSending; + SetActive(); + TRequestStatus* status = &iStatus; + User::RequestComplete(status, KErrNone); + } + } + + +void CUdpProcess::RunL() + { + __FLOG_STATIC0(KSubSys, KLogComponent , _L8("CUdpProcess::RunL")); + switch (iProcessState) + { + case EDataSending: + //As a client, send data first. + iSendBuf.SetLength(iSize); + iSendBuf.Repeat(KSendData()); + iConsole.Printf(_L("Send data..")); + PrintData(iSendBuf); + iConsole.Printf(_L("In RunL, port=%d"), iAddr.Port()); + TInt sendLen = SendDataL(iSendBuf, iAddr, iSize); + + if (sendLen != iSize) + { + iConsole.Printf( + _L("The length of data sent is not equal to requested! requested[%d], sent[%d]"), + iSize, sendLen); + } + break; + + case EDataTransfer: + //In data transfer, some data is received + iConsole.Printf(_L("recv Package, size[%d], status[%d]\n"), + iRecvSize(), iStatus.Int()); + if (KErrNone == iStatus.Int()) + { + iConsole.Printf(_L("Receive data.")); + PrintData(iRecvBuf); + + if (iMode) + { + //As a server, send back the data received + TInt len = SendDataL(iRecvBuf, iPeerAddr, iRecvBuf.Length()); + iConsole.Printf(_L("Send back the data. len[%d]"), len); + } + } + else + { + iConsole.Printf(_L("Something is wrong...")); + return; + } + + iRecvBuf.SetLength(0); + iRecvSize = iSize; + //iListenSocket.RecvFrom(iRecvBuf, iPeerAddr, 0, iStatus); + iSocket.RecvFrom(iRecvBuf, iPeerAddr, 0, iStatus); + SetActive(); + iConsole.Printf(_L("\nWait for UDP incoming data at port[%d]...\n"),iPort); + break; + } + } + +void CUdpProcess::DoCancel() +{ + switch(iProcessState) + { + case EDataTransfer: + //iListenSocket.CancelRecv(); + iSocket.CancelRecv(); + break; + } +} + +TInt CUdpProcess::RunError(TInt aError) +{ + User::Panic(_L("CUdpProcess"), aError); + return aError; +} + +TInt CUdpProcess::SendDataL(TDes8& aData, TInetAddr& aAddr, TInt aSize) + /** + Send data. + @return the size of data sent + */ +{ + TRequestStatus status; + + TInt port = aAddr.Port(); + iConsole.Printf(_L("Before sending, size = %d, port=%d\n"), aSize, port); + TSockXfrLength sendSize = 0; //aSize; + iSocket.SendTo(aData, aAddr, 0, status, sendSize); + User::WaitForRequest(status); + iConsole.Printf(_L("Sending result = %d, and sent=%d\n"), status.Int(), sendSize()); + + switch(status.Int()) + { + case KErrEof: + iConsole.Printf(_L("Connection closed!")); + return 0; + case KErrNone: + iConsole.Printf(_L("Send successfully.\n")); + break; + default: + User::LeaveIfError(status.Int()); + break; + } + return sendSize(); +} + +void CUdpProcess::PrintData(TDes8& aData) +{ + iConsole.Printf(_L("The data is: \n")); + for(TInt i=0; i< aData.Length();i++) + { + iConsole.Printf(_L("%c"), aData[i]); + } + iConsole.Printf(_L("\n")); +} + + + +CTcpTestConsole* CTcpTestConsole::NewL(TBool aIsTcp, TBool aMode, TDesC& aDefautAddr, TInt aIndex, CTcpCommand& aOwner) + { + CTcpTestConsole* self = new(ELeave) CTcpTestConsole(aIsTcp, aMode, aDefautAddr, aIndex, aOwner); + CleanupStack::PushL(self); + self->ConstructL(); + CleanupStack::Pop(self); + return self; + + } + +CTcpTestConsole::CTcpTestConsole(TBool aIsTcp, TBool aMode, TDesC& aDefautAddr, TInt aIndex, CTcpCommand& aOwner) + : CActive(EPriorityStandard),iCommandMode(ECommandInit), iIsTcp(aIsTcp), iMode(aMode), + iDefaultAddr(aDefautAddr), iIndex(aIndex), iOwner(aOwner) + { + CActiveScheduler::Add(this); + } + +CTcpTestConsole::~CTcpTestConsole() + { + Cancel(); + delete iTcp; + delete iUdp; + delete iConsole; + iChars.Close(); + } + + +void CTcpTestConsole::ConstructL() + { + if(iMode) + { + iConsole = Console::NewL(KTcpServerMode(),TSize(KConsFullScreen,KConsFullScreen)); + } + else + { + iConsole = Console::NewL(KTcpClientMode(),TSize(KConsFullScreen,KConsFullScreen)); + } + User::LeaveIfError(iChars.Create(KMaxNumOfChars)); + //Generate the default value and display on screen, user can modify it if they want to use other value. + iChars.AppendFormat(_L("%S %d"), &iDefaultAddr, KDefaultDataSize); + Help(); + //wait user input + iConsole->Read(iStatus); + SetActive(); + } + +void CTcpTestConsole::Help() + { + iConsole->Printf(_L("Please change the parameters, then press enter\n")); + if(iMode) + { + iConsole->Printf(_L(" The parameters are port size \n")); + iConsole->Printf(_L(" port - The port of the Tcp/udp Server listen to \n")); + iConsole->Printf(_L(" size - the max package size \n")); + } + else + { + iConsole->Printf(_L(" The parameters are destAddr port size \n")); + iConsole->Printf(_L(" destAddr - The ip address of Tcp/udp Client connect to.\n")); + iConsole->Printf(_L(" port - The port of Tcp Client connect to \n")); + iConsole->Printf(_L(" size - the package size \n")); + } + //Display the default value + iConsole->Printf(_L("%S"), &iChars); + + } +TBool CTcpTestConsole::StartL() + { + TLex args(iChars); + // args are separated by spaces + args.SkipSpace(); + + TInetAddr addr; + TInt size; + + if(!iMode) + { + //Get ip addr + TPtrC cmdAddr = args.NextToken(); + if(!args.Eos()) + { + if(KErrNone == addr.Input(cmdAddr)) + { + args.Inc(); + } + else + { + return EFalse; + } + } + else + { + return EFalse; + } + } + + //Get port + TInt port; + if(KErrNone != args.Val(port)) + { + return EFalse; + } + addr.SetPort(port); + + //Get pkg size + args.Inc(); + if(KErrNone != args.Val(size)) + { + return EFalse; + } + + iCommandMode = ECommandRunning; + if (iIsTcp) + { + iConsole->Printf(_L("Test for TCP...\n")); + iTcp = CTcpProcess::NewL(*iConsole, addr, port, size, iMode); + } + else + { + iConsole->Printf(_L("Test for UDP...\n")); + iUdp = CUdpProcess::NewL(*iConsole, addr, port, size, iMode); + } + + return ETrue; + + } + +void CTcpTestConsole::DoCancel() + { + iConsole->ReadCancel(); + } + +void CTcpTestConsole::RunL() + { + User::LeaveIfError(iStatus.Int()); + switch(iCommandMode) + { + case ECommandInit: + { + TKeyCode code = iConsole->KeyCode(); + switch(code) + { + case EKeyEnter: + { + //User input ok + if(!StartL()) + { + Help(); + } + } + break; + case EKeyEscape: + //connection has not been created. User want to cancel and quit + iOwner.CloseTcpTest(iIndex); + return; + case EKeyBackspace: + if(iChars.Length() > 0) + { + iConsole->SetCursorPosRel(TPoint(-1, 0)); + iConsole->ClearToEndOfLine(); + iChars.SetLength(iChars.Length()-1); + } + break; + default: + iChars.Append(code); + iConsole->Printf(_L("%c"), code); + break; + } + iConsole->Read(iStatus); + SetActive(); + } + break; + case ECommandRunning: + //Connection has been created. User quit by press any key. + iOwner.CloseTcpTest(iIndex); + break; + } + } + +TInt CTcpTestConsole::RunError(TInt aError) + { + User::Panic(_L("CTcpTestConsole"), aError); + return aError; + } + +