# HG changeset patch # User Deepak Kumar-Gupta # Date 1267703916 0 # Node ID e7dfaa7b0b8d24ce7436ff11e92ab090b80df023 # Parent 1422c6cd3f0c2b8452ef92acbd504fcedab1540e Fix for Bug 69 - provide missing source for EtherPkt.drv diff -r 1422c6cd3f0c -r e7dfaa7b0b8d linklayerprotocols/ethernetnif/EtherPkt/CardCtl.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/linklayerprotocols/ethernetnif/EtherPkt/CardCtl.cpp Thu Mar 04 11:58:36 2010 +0000 @@ -0,0 +1,452 @@ +// Copyright (c) 1997-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: +// Control engine for ethernet packet driver +// +// + +/** + @file +*/ + +#include +#include +#include +#include +#include +#include +#include "PKTDRV.H" +#include "ETHINTER.H" +#include "Cardctl.h" +#include +#include + +//#define __DebugCardCtl__ 1 + + + +/** +Create a new CPcCardControlEngine object. +@param aPktDrv Pointer to PC Card Packet Driver. +@return A pointer to CPcCardControlEngine object. +*/ +CPcCardControlEngine *CPcCardControlEngine::NewL(CPcCardPktDrv* aPktDrv) +{ + CPcCardControlEngine *cc=new (ELeave) CPcCardControlEngine(aPktDrv); + CleanupStack::PushL(cc); + cc->ConstructL(); + CleanupStack::Pop(); + return cc; +} + +/** +Physical device driver settings +@internalComponent +*/ +_LIT(KPddSection,"pdd_settings"); + +/** +PCMCIA Socket Number +@internalComponent +*/ +_LIT(KSocketNumber,"PCMCIA_socket"); + +/** +Create the CPcCardControlEngine object. +*/ +void CPcCardControlEngine::ConstructL() +{ + iSender = CPcCardSender::NewL(this); + iReceiver = CPcCardReceiver::NewL(this); + iEventHandler = CPcCardEventHandler::NewL(this); + + LoadDeviceDriversL(); + + CESockIniData* ini = CESockIniData::NewL(ETHER802_CONFIG_FILENAME); + CleanupStack::PushL(ini); + + TInt socket; + if(!ini->FindVar(KPddSection,KSocketNumber,socket)) + { + User::Leave(KErrNotFound); + } + + CleanupStack::PopAndDestroy(ini); + + TInt error = iCard.Open(socket); + User::LeaveIfError(error); +} + +/** +Open the Card LDD +*/ +void CPcCardControlEngine::StartL() +{ + iCardOpen = ETrue; + iReceiver->QueueRead(); + LinkLayerUp(); +} + +/** +Find and loads the LDD and the PDD if the logical device driver loaded OK. +The driver names are read from the LAN bearer table in commdb. +*/ +void CPcCardControlEngine::LoadDeviceDriversL() +{ + TInt err; + + // + // Get the device driver filenames for loading + // + TBuf pddOrLddFileName; + + // LDD first... + TBuf columnName=TPtrC(LAN_BEARER); + columnName.Append(TChar(KSlashChar)); + columnName.Append(TPtrC(LAN_BEARER_LDD_FILENAME)); + + err = iNotify->NifNotify()->ReadDes(columnName, pddOrLddFileName); // Get the LDD name from commdb + + if(err!=KErrNone) + { + __FLOG_STATIC(KEther802LogTag1,KEthLogTag3, _L("Could not find LDD filename in commdb - is .cfg file up-to-date? See ether802.ini for information on required fields in commdb.")); + User::Leave(err); + } + + err=User::LoadLogicalDevice(pddOrLddFileName); + if(err != KErrNone && err != KErrAlreadyExists) + { + User::Leave(err); + } + + // ...and now the PDD + columnName.Zero(); + columnName.Append(TPtrC(LAN_BEARER)); + columnName.Append(TChar(KSlashChar)); + columnName.Append(TPtrC(LAN_BEARER_PDD_FILENAME)); + + err = iNotify->NifNotify()->ReadDes(columnName, pddOrLddFileName); // Get the PDD filename from commdb + + if(err!=KErrNone) + { + __FLOG_STATIC(KEther802LogTag1,KEthLogTag3, _L("Could not find PDD filename in commdb - is .cfg file up-to-date? See ether802.ini for information on required fields in commdb.")); + User::Leave(err); + } + + err = User::LoadPhysicalDevice(pddOrLddFileName); + if (err != KErrNone && err != KErrAlreadyExists) + { + User::Leave(err); + } + + // + // Get device driver names for unloading + // + columnName.Zero(); + columnName.Append(TPtrC(LAN_BEARER)); + columnName.Append(TChar(KSlashChar)); + columnName.Append(TPtrC(LAN_BEARER_PDD_NAME)); + + err = iNotify->NifNotify()->ReadDes(columnName, iPDDName); // Get the PDD name from commdb (so we can close it when we've finished with it) + + if(err!=KErrNone) + { + __FLOG_STATIC(KEther802LogTag1,KEthLogTag3, _L("Could not find PDD name in commdb - is .cfg file up-to-date? See ether802.ini for information on required fields in commdb.")); + +#ifdef _DEBUG + // Not being able to unload the device drivers is not a fatal error, so don't worry too + // much if we can't read the field out of commdb in release builds, but if the user is + // using a debug nif they ought to get it right... + User::Leave(err); +#endif // _DEBUG + } + + // Rather than fiddle around trying to reuse the contents of the descriptor (problems with field name lengths), just zero and start again + columnName.Zero(); + columnName.Append(TPtrC(LAN_BEARER)); + columnName.Append(TChar(KSlashChar)); + columnName.Append(TPtrC(LAN_BEARER_LDD_NAME)); + + err = iNotify->NifNotify()->ReadDes(columnName, iLDDName); // Get the LDD name from commdb (so we can close it when we've finished with it) + + if(err!=KErrNone) + { + __FLOG_STATIC(KEther802LogTag1,KEthLogTag3, _L("Could not find LDD name in commdb - is .cfg file up-to-date? See ether802.ini for information on required fields in commdb.")); + +#ifdef _DEBUG + User::Leave(err); // see reasoning for LDD above +#endif // _DEBUG + } + + __FLOG_STATIC(KEther802LogTag1,KEthLogTag3, _L("Device drivers loaded")); +} + +/** +Cancel I/O and close the Card LDD. +*/ +void CPcCardControlEngine::Stop() +{ + // LDD Performs status checks on Read and Write + // Completes requests with an error code if they are pending + iCard.WriteCancel(); + iSender->EmptyQueue(); + iSender->Cancel(); + + iCard.ReadCancel(); + iCardOpen = EFalse; + iCard.Close(); +} + +CPcCardControlEngine::CPcCardControlEngine(CPcCardPktDrv* aPktDrv) +:iCardOpen(EFalse), iNotify(aPktDrv) +/** +Constructor. +@param aPktDrv Pointer to PC Card Packet Driver. +*/ +{ + +} + +/** +Destructor. +*/ +CPcCardControlEngine::~CPcCardControlEngine() +{ +#ifdef _DEBUG + // see reasoning for only doing this in debug builds in LoadPacketDrivers() + User::FreeLogicalDevice(iLDDName); + User::FreePhysicalDevice(iPDDName); +#endif + + delete iReceiver; + delete iSender; + delete iEventHandler; +} + +/** +Upwards notify +@param aBuffer A Reference to a buffer holding data. +*/ +void CPcCardControlEngine::ProcessReceivedPacket(TDesC8& aBuffer) +{ + iNotify->ReadDataAvailable(aBuffer); +} + +/** +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 CPcCardControlEngine::ResumeSending() +{ + iNotify->ResumeSending(); +} + +/** +Resume Sending is a notification call into NIF from the lower layer telling the NIF that +the interface is now up and can accept and transmit data. NIF subsequently calls all the +bearers' StartSending() methods directly. +*/ +void CPcCardControlEngine::LinkLayerUp() +{ + iNotify->LinkLayerUp(); +} + +/** +Sender class handles queueing and takes ownership of the HBuf and the CIOBuffer. +@param aBuffer The data to be send is set. +@return 0 Tells the higher layer to send no more data. + 1 Tells higher layer that it can send more data. +*/ +TInt CPcCardControlEngine::Send(HBufC8* aBuffer) +{ + CIOBuffer* buf = NULL; + TRAPD(err,buf = CIOBuffer::NewL(aBuffer)); + if(err != KErrNone) + { + delete aBuffer; + } + else + { + err = iSender->Send(buf); + } + return err; +} + +/** +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* CPcCardControlEngine::GetInterfaceAddress() +{ + iConfig.SetMax(); + iCard.Config(iConfig); + return ((TUint8*)iConfig.Ptr())+2; // The MAC address is located 2 bytes + // from the start of the buffer +} + +#if !defined(__WINS__) +// + +/** +ethermac.dat reading - work around for mac address problem +@internal component +*/ +_LIT(KEtherMacFileName,"C:\\System\\Data\\EtherMac.dat"); + +/** +Parse the Machine Address from the File. +*/ +void CPcCardControlEngine::ParseMACFromFileL() +{ + + TBuf8<64> controlBuf; // the size of this is defined in the driver as 64. + TBuf8<12> macAddress = 0; + RFile macFile; + RFs fileSrv; + + User::LeaveIfError(fileSrv.Connect()); + User::LeaveIfError(macFile.Open(fileSrv,KEtherMacFileName,EFileRead)); + User::LeaveIfError(macFile.Read(macAddress,12)); + macFile.Close(); + fileSrv.Close(); + controlBuf.SetLength(8); + controlBuf[0] = KEthSpeed10BaseT; + controlBuf[1] = KEthDuplexHalf; + + TBuf<20> validChars(_L("0123456789abcdef")); + TUint8 value; + TUint8 upper=0; + TChar c; + TInt pos; + iConfig.SetMax(); // MAC Address fix + for(TInt i=0; i<6; i++) + { + c = macAddress[2*i]; + c.LowerCase(); + if((pos = validChars.Locate(c))==KErrNotFound) + { + pos = upper; + break; + } + upper = (TUint8)pos; + c = macAddress[(2*i)+1]; + c.LowerCase(); + if((pos = validChars.Locate(c))==KErrNotFound) + { + User::Leave(KErrNotFound); + } + value = (TUint8)pos; + value = (TUint8)((upper<<4) | value); + controlBuf.Append(value); + iConfig[i+2]=value; // MAC Address fix 21/05/01 + } + TRequestStatus status = 0; + + User::LeaveIfError(iCard.SetMAC(controlBuf)); + + User::WaitForRequest(status); + User::LeaveIfError(status.Int()); +} +#endif + +/** +Constructor. Generic Buffer class +Currently used for transmit buffers +*/ +CIOBuffer::CIOBuffer() : iBufPtr(NULL,0) +{ +} + +/** +Destructor. Free the HBuf if there is one +*/ +CIOBuffer::~CIOBuffer() +{ + FreeData(); +} + +/** +Creation where we new the HBuf. +@param aSize Length of the Buffer. +@return A pointer to CIOBuffer object. +*/ +CIOBuffer* CIOBuffer::NewL(const TInt aSize) +{ + CIOBuffer * self = new (ELeave) CIOBuffer; + CleanupStack::PushL(self); + self->ConstructL(aSize); + CleanupStack::Pop(); + return self; +} + +/** +Construction where we new the HBuf +@param aSize Length of the Buffer. +*/ +void CIOBuffer::ConstructL(const TInt aSize) +{ + iBuf = HBufC8::NewL(aSize); + TPtr8 temp=iBuf->Des(); + iBufPtr.Set(temp); +} + +/** +HBuf provided. +@param aBuf The data to be assigned +@return A pointer to CIOBuffer object. +*/ +CIOBuffer* CIOBuffer::NewL(HBufC8* aBuf) +{ + CIOBuffer * self = new (ELeave) CIOBuffer; + self->Assign(aBuf); + return self; +} + +/** +Offset +*/ +TInt CIOBuffer::LinkOffset() +{ + return _FOFF(CIOBuffer,iLink); +} + +/** +Assigns the data from buffer to pointer. + +@param aBuffer The data to be assigned +*/ +void CIOBuffer::Assign(HBufC8* aBuffer) +{ + FreeData(); + iBuf = aBuffer; + if(aBuffer) + { + TPtr8 temp=iBuf->Des(); + iBufPtr.Set(temp); + } +} + +/** +Frees the data. +*/ +void CIOBuffer::FreeData() +{ + if(iBuf) + { + delete iBuf; + iBuf = NULL; + } +} + diff -r 1422c6cd3f0c -r e7dfaa7b0b8d linklayerprotocols/ethernetnif/EtherPkt/CardDll.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/linklayerprotocols/ethernetnif/EtherPkt/CardDll.cpp Thu Mar 04 11:58:36 2010 +0000 @@ -0,0 +1,365 @@ +// Copyright (c) 1997-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: +// + + +#include +#include +#include +#include +#include +#include "PKTDRV.H" +#include "ETHINTER.H" +#include "Cardctl.h" + + +/** +@internalComponent +*/ +extern "C" +{ + IMPORT_C CPktDrvFactory * NewPcCardPktDrvFactoryL(); //< 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* NewPcCardPktDrvFactoryL() +{ + CPktDrvFactory *f=new (ELeave) CPcCardPktDrvFactory; + return f; +} + +/** +Create the packet driver object +@param aParent Pointer to the parent Ethint NIF class. +@return A pointer to CPktDrvBase object. +*/ +CPktDrvBase* CPcCardPktDrvFactory::NewDriverL(CLANLinkCommon* aParent) +{ + CPktDrvBase *drv = new (ELeave) CPcCardPktDrv(*this); + CleanupStack::PushL(drv); + drv->ConstructL(aParent); + CleanupStack::Pop(); + return drv; +} + +/** +Constructor. +*/ +CPcCardPktDrvFactory::CPcCardPktDrvFactory() +{ + +} + +/** +Packet Driver version number. +@return Version number of the Packet Driver +*/ +TVersion CPcCardPktDrvFactory::Version() const +{ + return(TVersion(KPcCardDrvMajorVersionNumber,KPcCardDrvMinorVersionNumber,KPcCardDrvBuildVersionNumber)); +} + + +/** +Constructor. Packet Driver object. +*/ +CPcCardPktDrv::CPcCardPktDrv(CPktDrvFactory& aFactory) : CPktDrvBase(aFactory) +{ + +} + +/** +Only one object owned +Destructor. +*/ +CPcCardPktDrv::~CPcCardPktDrv() +{ + delete iControl; +} + +/** +Pure Virtual Construction of the CPktDrvBase object +@param aParent Pointer to the CLANLinkCommon class. +*/ +void CPcCardPktDrv::ConstructL(CLANLinkCommon* aParent) +{ + iParent = aParent; + // Card control engine + iControl=CPcCardControlEngine::NewL(this); +} + +/** +Pure Virtual Downstack call. " Call to LDD or subordinate object to start/initialise the +Physical device +@return KErrNone if Successful + KErrNotSupported LAN Device does not support. + Implementation specific Error Code Failure +*/ +TInt CPcCardPktDrv::StartInterface() +{ + // Opens the card and queues a read + // Control engine validates + TRAPD(err,iControl->StartL()); + return err; +} + +/** +Call to LDD or subordinate object to stop/de-initialise the Physical device +@return KErrNone if Successful + KErrNotSupported LAN Device does not support. + Implementation specific Error Code Failure +*/ +TInt CPcCardPktDrv::StopInterface() +{ + // Closes the card + // Control engine validates + iControl->Stop(); + return KErrNone; +} + +/** +Call to LDD or subordinate object to reset/re-initialise the Physical device +@return KErrNone if Successful + KErrNotSupported LAN Device does not support. + Implementation specific Error Code Failure +*/ +TInt CPcCardPktDrv::ResetInterface() +{ + iControl->Stop(); + TRAPD(err,iControl->StartL()); + return err; +} + +/** +Sender Class is generic and does not want to know about RMBuf's +Copy to a Heap Buffer and Free the packet. 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 CPcCardPktDrv::Send(RMBufChain &aPacket) +{ + if(!iControl->CardOpen()) + { + aPacket.Free(); + return KErrNotReady; + } + HBufC8 * buf = NULL; + TRAPD(err,buf = HBufC8::NewMaxL(aPacket.Length())); + if(err != KErrNone) + { + aPacket.Free(); + return err; + } + TPtr8 ptr = buf->Des(); + aPacket.CopyOut(ptr); + aPacket.Free(); + return(iControl->Send(buf)); +} + +/** +Read the Available data. +@param aBuffer A Reference to a buffer holding data. +*/ +void CPcCardPktDrv::ReadDataAvailable(TDesC8& aBuffer) +{ + RMBufPacket frame; + TRAPD(ret,frame.CreateL(aBuffer,0)); + if (ret == KErrNone) + { + frame.Pack(); + iParent->Process(frame); + } +} + +/** +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 CPcCardPktDrv::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 CPcCardPktDrv::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 CPcCardPktDrv::GetRxMode() const +{ + return KErrNotSupported; +} + +/** +Specifies the AccessType. +@return KErrNotSupported LAN Device does not support. +*/ +TInt CPcCardPktDrv::AccessType() +{ + return KErrNotSupported; +} + +/** +Specifies the ReleaseType. +@return KErrNotSupported LAN Device does not support. +*/ +TInt CPcCardPktDrv::ReleaseType() +{ + 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* CPcCardPktDrv::GetInterfaceAddress()const +{ + return (iControl->GetInterfaceAddress()); +} + +/** +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 CPcCardPktDrv::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 CPcCardPktDrv::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 CPcCardPktDrv::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 CPcCardPktDrv::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 CPcCardPktDrv::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 CPcCardPktDrv::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 CPcCardPktDrv::InterfaceResume() +{ + return KErrNotSupported; +} + +/** +Resume Sending is a notification call into NIF from the lower layer telling the NIF that +the interface is now up and can accept and transmit data. NIF subsequently calls all the +bearers' StartSending() methods directly. +*/ +void CPcCardPktDrv::LinkLayerUp() +{ + iParent->LinkLayerUp(); +} + +/** +Receive notifications from agent +*/ +TInt CPcCardPktDrv::Notification(enum TAgentToNifEventType /*aEvent*/, void* /*aInfo*/) +{ + return KErrNotSupported; +} + +/** +Receive Control() calls from agent/nifman/connection +*/ +TInt CPcCardPktDrv::Control(TUint /*aLevel*/,TUint /*aName*/,TDes8& /*aOption*/, TAny* /*aSource*/) +{ + return KErrNotSupported; +} + +/** +Return the pointer to the ethernet nif. +Purely for access to commdb reading functionality +*/ +CLANLinkCommon* CPcCardPktDrv::NifNotify() +{ + return iParent; +} + diff -r 1422c6cd3f0c -r e7dfaa7b0b8d linklayerprotocols/ethernetnif/EtherPkt/CardIo.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/linklayerprotocols/ethernetnif/EtherPkt/CardIo.cpp Thu Mar 04 11:58:36 2010 +0000 @@ -0,0 +1,461 @@ +// Copyright (c) 1997-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 +*/ + +#include +#include +#include +#include +#include "PKTDRV.H" +#include "ETHINTER.H" +#include "Cardctl.h" + + + + +#ifdef __DebugCardLo__ +// TCP packet tracing debug +const TUint8 ETHER2_TYPE_IP_MSB = 0x08; +const TUint8 ETHER2_TYPE_IP_LSB = 0x00; +const TUint8 IP_TYPE_TCP = 0x06; +static inline TBool IsTcp(TDesC8 &aFrame) +{ + return (aFrame[12] == ETHER2_TYPE_IP_MSB && aFrame[13] == ETHER2_TYPE_IP_LSB && aFrame[23] == IP_TYPE_TCP); +} +static TInt GetTcpSeqNumber(TDesC8 &aFrame) + { + TInt seqNum = 0; + if (IsTcp(aFrame)) + seqNum = aFrame[38] << 24 | aFrame[39] << 16 | aFrame[40] << 8| aFrame[41]; + return seqNum; + } +static TInt GetTcpAckNumber(TDesC8 &aFrame) + { + TInt ackNum = 0; + if (IsTcp(aFrame)) + ackNum = aFrame[42] << 24 | aFrame[43] << 16 | aFrame[44] << 8| aFrame[45]; + return ackNum; + } +#endif + + +/** +Send active object class +When CIOBuffer's are passed to SendL() the class takes ownership and is +therefore resposible for freeing them in the RunL() +@internalComponent +*/ +const TInt KTxQueueThreshold = 40; + +/** +Constructor. +*/ +CPcCardSender::CPcCardSender() : CActive(EPriorityStandard) +{ + +} + +/** +Destructor. +Could be buffers on the transmit queue, free them as this class should be sole owner. +*/ +CPcCardSender::~CPcCardSender() +{ + EmptyQueue(); + Cancel(); +} + +/** +Standard CActive construction. +@param aParent Pointer to the parent CPcCardControlEngine class. +@return A pointer to CPcCardSender object. +*/ +CPcCardSender* CPcCardSender::NewL(CPcCardControlEngine* aParent) +{ + CPcCardSender *sd=new (ELeave) CPcCardSender; + CleanupStack::PushL(sd); + sd->InitL(aParent); + CActiveScheduler::Add(sd); + CleanupStack::Pop(); + return sd; +} + +/** +Add the newly created object to an object container. +@param aParent Pointer to the parent CPcCardControlEngine class. +*/ +void CPcCardSender::InitL(CPcCardControlEngine* aParent) +{ + iParent=aParent; + iTxQueue.SetOffset(CIOBuffer::LinkOffset()); + iQueueLength = 0; + iStopSending = EFalse; +} + +/** +Protocol inspects return +It blocks sending if it receives a return <= 0 +This value should be propogated up through the stack +@internalComponent +*/ +const TInt KStopSending = 0; + +/** +Protocol inspects return to indicate Keep sending the data. +@internalComponent +*/ +const TInt KContinueSending = 1; + +/** +Writes the data to buffer. + +@param aBuffer The data to be send. +@return 0 Tells the higher layer to stop sending the data. + 1 Tells higher layer that it can continue sending more data. +*/ +TInt CPcCardSender::Send(CIOBuffer *aBuffer) +{ + + // Check to see if we need to start transmission + // Pseudo interrupt queue + TBool startTx = iTxQueue.IsEmpty(); + + iTxQueue.AddLast(*aBuffer); + iQueueLength++; + if(startTx) + { + // Transmitter was idle start next transmit + iParent->iCard.Write(iStatus,aBuffer->Ptr()); + SetActive(); + } + else + { + } + // The stack could saturate us with data + // Tell the stack to send no more + // We will unblock the stack when the queue size drops below + // the the threshold + if(iQueueLength >= KTxQueueThreshold) + { + iStopSending = ETrue; + return KStopSending; + } + else + { + return KContinueSending; + } +} + +/** +Free all queued buffers. Should be safe as this class owns them +*/ +void CPcCardSender::EmptyQueue() +{ + + while(!iTxQueue.IsEmpty()) + { + CIOBuffer* buf = iTxQueue.First(); + iTxQueue.Remove(*buf); + delete buf; + } + iQueueLength = 0; + iStopSending = EFalse; +} + +/** +Write completion from the LDD. Pseudo transmit interrupt handler +*/ +void CPcCardSender::RunL() +{ + // Check for error, all we can do is free the buffers + if(iStatus.Int()!=KErrNone) + { + EmptyQueue(); + return; + } + + if(!iTxQueue.IsEmpty()) + { + // Head of the queue has been transmitted + // Remove it and free it + CIOBuffer* buf = iTxQueue.First(); + iTxQueue.Remove(*buf); + iQueueLength--; + delete buf; + + + // Check to see if there are still buffers queued. + // Start next transmit if there are + TBool startTx; + (iTxQueue.IsEmpty()) ? (startTx = EFalse) : (startTx = ETrue); + if(startTx) + { + buf = iTxQueue.First(); + iParent->iCard.Write(iStatus,buf->Ptr()); + SetActive(); + } + else + { + + } + // Resume sending if the protocol was previously blocked + if(iStopSending && iQueueLength < KTxQueueThreshold) + { + iStopSending = EFalse; + iParent->ResumeSending(); + } + } +} + +/** +cancellation of an outstanding request. +*/ +void CPcCardSender::DoCancel() +{ + iParent->iCard.WriteCancel(); +} + +/** +Read active object class. +Read kept permanently on the LDD +Read completion is notified immediately up through the stack +with the one receive buffer therefore no Q. +*/ +CPcCardReceiver::CPcCardReceiver() : CActive(EPriorityMore) , iRecvBufPtr(NULL,0) +{ + +} + +/** +Constructor. +*/ +CPcCardReceiver::~CPcCardReceiver() +{ + Cancel(); + // One buffer only + delete iRecvBuffer; +} + +/** +Standard CActive construction. +@param aParent Pointer to the parent CPcCardControlEngine class. +@return A pointer to CPcCardReceiver object. +*/ +CPcCardReceiver* CPcCardReceiver::NewL(CPcCardControlEngine* aParent) +{ + CPcCardReceiver *rv=new (ELeave) CPcCardReceiver; + CleanupStack::PushL(rv); + rv->InitL(aParent); + CActiveScheduler::Add(rv); + CleanupStack::Pop(); + return rv; +} + +/** +Allocate the one and only read buffer. +@param aParent Pointer to the parent CPcCardControlEngine class. +*/ +void CPcCardReceiver::InitL(CPcCardControlEngine* aParent) +{ + iParent=aParent; + iRecvBufLength=KEtherBufSize; + iRecvBuffer=HBufC8::NewMaxL(iRecvBufLength); + TPtr8 temp=iRecvBuffer->Des(); + iRecvBufPtr.Set(temp); +} + +/** +Pass the receive buffer to the Card. +*/ +void CPcCardReceiver::QueueRead() +{ + iRecvBufPtr.SetMax(); + iParent->iCard.Read(iStatus,iRecvBufPtr); + SetActive(); +} + +/** +Pseudo read interrupt handler. +*/ +void CPcCardReceiver::RunL() +{ + if (iParent->CardOpen()) + { + if (iStatus.Int()!=KErrNone) + { + QueueRead(); + return; + } + // Pass the buffer up the stack + // and queue the next read, safe to reuse the buffer. + if(iRecvBufPtr.Length()) + { + iParent->ProcessReceivedPacket(iRecvBufPtr); + } + QueueRead(); + } + else + { + + } +} + +/** +Cancellation of an outstanding request. +*/ +void CPcCardReceiver::DoCancel() +{ + iParent->iCard.ReadCancel(); +} + +/** +Constructor. +*/ +CPcCardEventHandler::CPcCardEventHandler() : CActive(EPriorityStandard) +{ + +} + +/** +Destructor. +*/ +CPcCardEventHandler::~CPcCardEventHandler() +{ + Cancel(); +} + +/** +Allocate the one and only read buffer. +@param aParent Pointer to the parent CPcCardControlEngine class. +*/ +void CPcCardEventHandler::InitL(CPcCardControlEngine* aParent) +{ + iParent = aParent; +} + +/** +Standard CActive construction +@param aParent Pointer to the parent CPcCardControlEngine class. +@return A pointer to the CPcCardEventHandler object. +*/ +CPcCardEventHandler* CPcCardEventHandler::NewL(CPcCardControlEngine* aParent) +{ + CPcCardEventHandler *p=new (ELeave) CPcCardEventHandler; + CleanupStack::PushL(p); + p->InitL(aParent); + CActiveScheduler::Add(p); + CleanupStack::Pop(); + return p; +} + +/** +Handles an active object’s request completion event. +*/ +void CPcCardEventHandler::RunL() +{ + // TODO Parse code in iStatus for type of event +} + +/** +Cancellation of an outstanding request. +*/ +void CPcCardEventHandler::DoCancel() +{ +} + +/** +Gets the Event generated by the device drivers. +*/ +void CPcCardEventHandler::GetEvent() +{ + // Tell the device driver we want ALL Events + iEventBuffer.SetLength(1); + iEventBuffer[0] = 0xFF; + SetActive(); +} + +/** +Constructor. +*/ +CPcCardIOCTL::CPcCardIOCTL() : CActive(EPriorityStandard) +{ + +} + +/** +Destructor. +*/ +CPcCardIOCTL::~CPcCardIOCTL() +{ + Cancel(); +} + +/** +Add the newly created object to an object container. +@param aParent Pointer to the parent CPcCardControlEngine class. +*/ +void CPcCardIOCTL::InitL(CPcCardControlEngine* aParent) +{ + iParent = aParent; +} + +TInt CPcCardIOCTL::Ioctl(const TUint8 aIOCTLCode) +{ + if(IsActive()) + return KErrNotReady; + iIOCTLBuffer.SetLength(1); + iIOCTLBuffer[0] = aIOCTLCode; + iCurrentIOCTL = aIOCTLCode; + SetActive(); + return KErrNone; +} + + +/** +Standard CActive construction. +@param aParent Pointer to the parent CPcCardControlEngine class. +@return A pointer to CPcCardIOCTL object. +*/ +CPcCardIOCTL* CPcCardIOCTL::NewL(CPcCardControlEngine* aParent) +{ + CPcCardIOCTL *p=new (ELeave) CPcCardIOCTL; + CleanupStack::PushL(p); + p->InitL(aParent); + CActiveScheduler::Add(p); + CleanupStack::Pop(); + return p; +} + +/** +Handles an active object’s request completion event. +*/ +void CPcCardIOCTL::RunL() +{ + { + iParent->iReceiver->QueueRead(); + iParent->LinkLayerUp(); + } +} + +/** +Cancellation of an outstanding request. +*/ +void CPcCardIOCTL::DoCancel() +{ +} diff -r 1422c6cd3f0c -r e7dfaa7b0b8d linklayerprotocols/ethernetnif/EtherPkt/Cardctl.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/linklayerprotocols/ethernetnif/EtherPkt/Cardctl.h Thu Mar 04 11:58:36 2010 +0000 @@ -0,0 +1,201 @@ +// Copyright (c) 1997-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 +*/ + +#if !defined(__CARDCTL_H__) +#define __CARDCTL_H__ + +#include + +#include "carddrv.h" +#include // for KSlashChar + +const TInt KConfigBufferSize = 12; + + +NONSHARABLE_CLASS(CIOBuffer) : public CBase +/** +Generic buffer class +Enables HBufC8 pointers to be queued +@internalComponent +*/ +{ +public: + ~CIOBuffer(); + inline HBufC8* Data() const {return iBuf;}; + void FreeData(); + inline TPtr8& Ptr() {return iBufPtr;}; + void Assign(HBufC8* aBuffer = NULL); + static CIOBuffer* NewL(HBufC8* aBuf = NULL); + static CIOBuffer* NewL(const TInt aSize); + static TInt LinkOffset(); + +private: + CIOBuffer(); + void ConstructL(const TInt aSize); + // void Construct(HBufC8* aBuffer); + + TSglQueLink iLink; + HBufC8* iBuf; + TPtr8 iBufPtr; +}; + + +// Main Card Control class. Controls open, close, read, write etc +class CPcCardSender; +class CPcCardReceiver; +class CPcCardIOCTL; +class CPcCardEventHandler; + +NONSHARABLE_CLASS(CPcCardControlEngine) : public CBase +/** +@internalComponent +*/ +{ +public: + friend class CPcCardSender; + friend class CPcCardReceiver; + friend class CPcCardIOCTL; + friend class CPcCardEventHandler; + + static CPcCardControlEngine *NewL(CPcCardPktDrv* aPktDrv); + ~CPcCardControlEngine(); + void StartL(); + void Stop(); + TUint8* GetInterfaceAddress(); + TInt Send(HBufC8* aBuffer); + TBool CardOpen(){return iCardOpen;}; + +#if (!defined __WINS__) + void ParseMACFromFileL(); +#endif + + +private: + CPcCardControlEngine(CPcCardPktDrv* aPktDrv); + void ConstructL(); + void ProcessReceivedPacket(TDesC8 &aBuffer); + void ResumeSending(); + void LinkLayerUp(); + void LoadDeviceDriversL(); + +private: + TBool iCardOpen; + CPcCardPktDrv* iNotify; + + TBuf8 iConfig; + + CPcCardSender* iSender; + CPcCardReceiver* iReceiver; + CPcCardEventHandler* iEventHandler; + RBusDevEthernet iCard; + TInt iPcmciaSocket; + + TBuf iPDDName; + TBuf iLDDName; +}; + +NONSHARABLE_CLASS(CPcCardSender) : public CActive +/** +Writer Active object class +Queues buffers for transmit +@internalComponent +*/ +{ +public: + static CPcCardSender* NewL(CPcCardControlEngine* aParent); + ~CPcCardSender(); + TInt Send(CIOBuffer* aBuffer); + void EmptyQueue(); + +private: + virtual void RunL(); + virtual void DoCancel(); + CPcCardSender(); + void InitL(CPcCardControlEngine* aParent); + + TInt iQueueLength; + CPcCardControlEngine* iParent; + TSglQue iTxQueue; + TBool iStopSending; +}; + +NONSHARABLE_CLASS(CPcCardReceiver) : public CActive +/** +Reader active object +One receive buffer only, read queue handled by LDD +@internalComponent +*/ +{ +public: + static CPcCardReceiver* NewL(CPcCardControlEngine* aParent); + ~CPcCardReceiver(); + void QueueRead(); +private: + virtual void RunL(); + virtual void DoCancel(); + CPcCardReceiver(); + void InitL(CPcCardControlEngine* aParent); + + CPcCardControlEngine* iParent; + HBufC8* iRecvBuffer; + TUint iRecvBufLength; + TPtr8 iRecvBufPtr; +}; + +NONSHARABLE_CLASS(CPcCardEventHandler) : public CActive +/** +@internalComponent +*/ +{ +public: + ~CPcCardEventHandler(); + static CPcCardEventHandler* NewL(CPcCardControlEngine* aParent); + void GetEvent(); +private: + virtual void RunL(); + virtual void DoCancel(); + CPcCardEventHandler(); + void InitL(CPcCardControlEngine* aParent); + + TBuf8<32> iEventBuffer; + CPcCardControlEngine* iParent; +}; + +NONSHARABLE_CLASS(CPcCardIOCTL) : public CActive +/** +@internalComponent +*/ +{ +public: + ~CPcCardIOCTL(); + static CPcCardIOCTL* NewL(CPcCardControlEngine* aParent); + TInt Ioctl(const TUint8 aIOCTLCode); +private: + virtual void RunL(); + virtual void DoCancel(); + CPcCardIOCTL(); + void InitL(CPcCardControlEngine* aParent); + TBuf8<32> iIOCTLBuffer; + TUint8 iCurrentIOCTL; + + CPcCardControlEngine* iParent; +}; + +#endif