linklayerprotocols/ethernetnif/EtherPkt/CardDll.cpp
branchRCL_3
changeset 6 e7dfaa7b0b8d
equal deleted inserted replaced
5:1422c6cd3f0c 6:e7dfaa7b0b8d
       
     1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 #include <nifman.h>
       
    18 #include <nifvar.h>
       
    19 #include <nifutl.h>
       
    20 #include <es_mbuf.h>
       
    21 #include <nifmbuf.h>
       
    22 #include "PKTDRV.H"
       
    23 #include "ETHINTER.H"
       
    24 #include "Cardctl.h"
       
    25 
       
    26 
       
    27 /**
       
    28 @internalComponent
       
    29 */
       
    30 extern "C"
       
    31 {
       
    32 	IMPORT_C CPktDrvFactory * NewPcCardPktDrvFactoryL();	//< Force export 
       
    33 }
       
    34 
       
    35 /**
       
    36 Library file is opened and this is the the first and only export.
       
    37 @internalComponent
       
    38 @return A pointer to CPktDrvFactory object.
       
    39 */
       
    40 EXPORT_C CPktDrvFactory* NewPcCardPktDrvFactoryL()
       
    41 {
       
    42 	CPktDrvFactory *f=new (ELeave) CPcCardPktDrvFactory;
       
    43 	return f;
       
    44 }
       
    45 
       
    46 /**
       
    47 Create the packet driver object
       
    48 @param aParent Pointer to the parent Ethint NIF class.
       
    49 @return A pointer to CPktDrvBase object.
       
    50 */
       
    51 CPktDrvBase* CPcCardPktDrvFactory::NewDriverL(CLANLinkCommon* aParent)
       
    52 {
       
    53 	CPktDrvBase *drv = new (ELeave) CPcCardPktDrv(*this);
       
    54 	CleanupStack::PushL(drv);
       
    55 	drv->ConstructL(aParent);
       
    56 	CleanupStack::Pop();
       
    57 	return drv;
       
    58 }
       
    59 
       
    60 /**
       
    61 Constructor.
       
    62 */
       
    63 CPcCardPktDrvFactory::CPcCardPktDrvFactory()
       
    64 {
       
    65 	
       
    66 }
       
    67 
       
    68 /**
       
    69 Packet Driver version number.
       
    70 @return Version number of the Packet Driver
       
    71 */
       
    72 TVersion CPcCardPktDrvFactory::Version() const
       
    73 {
       
    74 	return(TVersion(KPcCardDrvMajorVersionNumber,KPcCardDrvMinorVersionNumber,KPcCardDrvBuildVersionNumber));
       
    75 }
       
    76 
       
    77 
       
    78 /**
       
    79 Constructor. Packet Driver object. 
       
    80 */
       
    81 CPcCardPktDrv::CPcCardPktDrv(CPktDrvFactory& aFactory) : CPktDrvBase(aFactory)
       
    82 {
       
    83 	
       
    84 }
       
    85 
       
    86 /**
       
    87 Only one object owned
       
    88 Destructor.
       
    89 */
       
    90 CPcCardPktDrv::~CPcCardPktDrv()
       
    91 {
       
    92 	delete iControl;
       
    93 }
       
    94 
       
    95 /**
       
    96 Pure Virtual Construction of the CPktDrvBase object
       
    97 @param aParent Pointer to the CLANLinkCommon class.
       
    98 */
       
    99 void CPcCardPktDrv::ConstructL(CLANLinkCommon* aParent)
       
   100 {
       
   101 	iParent = aParent;
       
   102 	// Card control engine
       
   103 	iControl=CPcCardControlEngine::NewL(this);
       
   104 }
       
   105 
       
   106 /**
       
   107 Pure Virtual Downstack call. "	Call to LDD or subordinate object to start/initialise the 
       
   108 Physical device
       
   109 @return KErrNone		 if Successful 
       
   110 		KErrNotSupported LAN Device does not support.
       
   111 		Implementation specific Error Code  Failure
       
   112 */
       
   113 TInt CPcCardPktDrv::StartInterface()
       
   114 {
       
   115 	// Opens the card and queues a read
       
   116 	// Control engine validates
       
   117 	TRAPD(err,iControl->StartL());
       
   118 	return err;
       
   119 }
       
   120  
       
   121 /**
       
   122 Call to LDD or subordinate object to stop/de-initialise the Physical device
       
   123 @return KErrNone		 if Successful 
       
   124 		KErrNotSupported LAN Device does not support.
       
   125 		Implementation specific Error Code  Failure
       
   126 */
       
   127 TInt CPcCardPktDrv::StopInterface()
       
   128 {
       
   129 	// Closes the card
       
   130 	// Control engine validates
       
   131 	iControl->Stop();
       
   132 	return KErrNone;
       
   133 }
       
   134 
       
   135 /**
       
   136 Call to LDD or subordinate object to reset/re-initialise the Physical device
       
   137 @return KErrNone		 if Successful 
       
   138 		KErrNotSupported LAN Device does not support.
       
   139 		Implementation specific Error Code  Failure
       
   140 */
       
   141 TInt CPcCardPktDrv::ResetInterface()
       
   142 {
       
   143 	iControl->Stop();
       
   144 	TRAPD(err,iControl->StartL());
       
   145 	return err;
       
   146 }
       
   147 
       
   148 /**
       
   149 Sender Class is generic and does not want to know about RMBuf's
       
   150 Copy to a Heap Buffer and Free the packet. EtherII MAC layer comments
       
   151 Say we should free the packet buffer
       
   152 RMBuf could contain a chain so get into a contiguous buffer
       
   153 @param aPacket Reference to a chain of data buffers to be passed to the line.
       
   154 @return 0 Tells the higher layer to send no more data.
       
   155 		1 Tells higher layer that it can send more data.
       
   156 */
       
   157 TInt CPcCardPktDrv::Send(RMBufChain &aPacket)
       
   158 {
       
   159 	if(!iControl->CardOpen())
       
   160 		{
       
   161 		aPacket.Free();
       
   162 		return KErrNotReady;
       
   163 		}
       
   164 	HBufC8 * buf = NULL;
       
   165 	TRAPD(err,buf = HBufC8::NewMaxL(aPacket.Length()));
       
   166 	if(err != KErrNone)
       
   167 		{
       
   168 		aPacket.Free();
       
   169 		return err;
       
   170 		}
       
   171 	TPtr8 ptr = buf->Des();
       
   172 	aPacket.CopyOut(ptr);
       
   173 	aPacket.Free();
       
   174 	return(iControl->Send(buf));
       
   175 }
       
   176 
       
   177 /**
       
   178 Read the Available data.
       
   179 @param aBuffer A Reference to a buffer holding data.
       
   180 */
       
   181 void CPcCardPktDrv::ReadDataAvailable(TDesC8& aBuffer)
       
   182 {
       
   183 	RMBufPacket frame;
       
   184 	TRAPD(ret,frame.CreateL(aBuffer,0));
       
   185 	if (ret == KErrNone)
       
   186 		{
       
   187 		frame.Pack();
       
   188 		iParent->Process(frame);
       
   189 		}
       
   190 }
       
   191 
       
   192 /**
       
   193 Resume Sending is a notification call into NIF from the lower layer telling the NIF that a 
       
   194 previous sending congestion situation has been cleared and it can accept more downstack data.
       
   195 */
       
   196 void CPcCardPktDrv::ResumeSending()
       
   197 {
       
   198 	iParent->ResumeSending();
       
   199 }
       
   200 
       
   201 /**
       
   202 Call to LDD or subordinate object to set the receive mode of the LAN Device
       
   203 @param aMode The mode to be set for the LAN Device.			
       
   204 @return KErrNotSupported LAN Device does not support.
       
   205 */
       
   206 TInt CPcCardPktDrv::SetRxMode(TRxMode /*aMode*/)
       
   207 {
       
   208 	return KErrNotSupported;
       
   209 }
       
   210 
       
   211 /**
       
   212 Call to LDD or subordinate object to Get the receive mode of the LAN Device
       
   213 @return KErrNotSupported LAN Device does not support.
       
   214 */
       
   215 TInt CPcCardPktDrv::GetRxMode() const
       
   216 {
       
   217 	return KErrNotSupported;
       
   218 }
       
   219 
       
   220 /**
       
   221 Specifies the AccessType.
       
   222 @return KErrNotSupported LAN Device does not support.
       
   223 */
       
   224 TInt CPcCardPktDrv::AccessType()
       
   225 {
       
   226 	return KErrNotSupported;
       
   227 }
       
   228 
       
   229 /**
       
   230 Specifies the ReleaseType.
       
   231 @return KErrNotSupported LAN Device does not support.
       
   232 */
       
   233 TInt CPcCardPktDrv::ReleaseType()
       
   234 {
       
   235 	return KErrNotSupported;
       
   236 }
       
   237 
       
   238 /**
       
   239 Call to LDD or subordinate object to get the Hardware address of the LAN Device
       
   240 @return NULL Failure.
       
   241 		(NULL Terminated Binary String) The Hardware Address of the interface. LAN Device 
       
   242 		Specific
       
   243 */
       
   244 TUint8* CPcCardPktDrv::GetInterfaceAddress()const
       
   245 {
       
   246 	return (iControl->GetInterfaceAddress());
       
   247 }
       
   248 
       
   249 /**
       
   250 Call to LDD or subordinate object to set the Hardware address of the LAN Device.
       
   251 @param THWAddr Address of where the Multicast list should be written.
       
   252 @return KErrNone		 if Successful 
       
   253 		KErrNotSupported LAN Device does not support.
       
   254 		Implementation specific Error Code  Failure
       
   255 */
       
   256 TInt CPcCardPktDrv::SetInterfaceAddress(const THWAddr&)
       
   257 {
       
   258 	return KErrNotSupported;
       
   259 }
       
   260 
       
   261 /**
       
   262 Call to LDD or subordinate object to retrieve the Multicast List from the LAN Device
       
   263 @param aAddr Address of where the Multicast list should be written.
       
   264 @param n Output Parameter , number of Addresses written
       
   265 @return KErrNone		 if Successful 
       
   266 		KErrNotSupported LAN Device does not support.
       
   267 		Implementation specific Error Code  Failure
       
   268 */
       
   269 TInt CPcCardPktDrv::GetMulticastList(const THWAddr* /*aAddr*/, TInt& /*n*/) const
       
   270 {
       
   271 	return KErrNotSupported;
       
   272 }
       
   273 
       
   274 /**
       
   275 Call to LDD or subordinate object to set the Multicast List for the LAN Device.
       
   276 @param aAddr Address of where the Multicast list should be written.
       
   277 @param n Output Parameter , number of Addresses written
       
   278 @return KErrNone		 if Successful 
       
   279 		KErrNotSupported LAN Device does not support.
       
   280 		Implementation specific Error Code  Failure
       
   281 */
       
   282 TInt CPcCardPktDrv::SetMulticastList(const THWAddr* /*aAddr*/, TInt /*n*/)
       
   283 {
       
   284 	return KErrNotSupported;
       
   285 }
       
   286 
       
   287 /**
       
   288 Call to LDD or subordinate object to power up the LAN Device.
       
   289 @return KErrNone		 if Successful 
       
   290 		KErrNotSupported LAN Device does not support.
       
   291 		Implementation specific Error Code  Failure
       
   292 */
       
   293 TInt CPcCardPktDrv::InterfacePowerUp()
       
   294 {
       
   295 	return KErrNotSupported;
       
   296 }
       
   297 	
       
   298 /**
       
   299 Call to LDD or subordinate object to power down the LAN Device
       
   300 @return KErrNone		 if Successful 
       
   301 		KErrNotSupported LAN Device does not support.
       
   302 		Implementation specific Error Code  Failure
       
   303 */
       
   304 TInt CPcCardPktDrv::InterfacePowerDown()
       
   305 {
       
   306 	return KErrNotSupported;
       
   307 }
       
   308 
       
   309 /**
       
   310 Call to LDD or subordinate object to suspend the LAN Device.
       
   311 @return KErrNone		 if Successful 
       
   312 		KErrNotSupported LAN Device does not support.
       
   313 		Implementation specific Error Code  Failure
       
   314 */
       
   315 TInt CPcCardPktDrv::InterfaceSleep()
       
   316 {
       
   317 	return KErrNotSupported;
       
   318 }
       
   319 
       
   320 /**
       
   321 Call to LDD or subordinate object to resume the LAN Device.
       
   322 @return KErrNone		 if Successful 
       
   323 		KErrNotSupported LAN Device does not support.
       
   324 		Implementation specific Error Code  Failure
       
   325 */
       
   326 TInt CPcCardPktDrv::InterfaceResume()
       
   327 {
       
   328 	return KErrNotSupported;
       
   329 }
       
   330 
       
   331 /**
       
   332 Resume Sending is a notification call into NIF from the lower layer telling the NIF that 
       
   333 the interface is now up and can accept and transmit data. NIF subsequently calls all the 
       
   334 bearers' StartSending() methods directly.
       
   335 */
       
   336 void CPcCardPktDrv::LinkLayerUp()
       
   337 {
       
   338 	iParent->LinkLayerUp();
       
   339 }
       
   340 
       
   341 /**
       
   342 Receive notifications from agent
       
   343 */
       
   344 TInt CPcCardPktDrv::Notification(enum TAgentToNifEventType /*aEvent*/, void* /*aInfo*/)
       
   345 {
       
   346 	return KErrNotSupported;
       
   347 }
       
   348 	
       
   349 /**
       
   350 Receive Control() calls from agent/nifman/connection
       
   351 */
       
   352 TInt CPcCardPktDrv::Control(TUint /*aLevel*/,TUint /*aName*/,TDes8& /*aOption*/, TAny* /*aSource*/)
       
   353 {
       
   354 	return KErrNotSupported;
       
   355 }
       
   356 
       
   357 /**
       
   358 Return the pointer to the ethernet nif.
       
   359 Purely for access to commdb reading functionality
       
   360 */
       
   361 CLANLinkCommon* CPcCardPktDrv::NifNotify()
       
   362 {
       
   363 	return iParent;
       
   364 }
       
   365