wlan_bearer/wlannwif/etherpkt/CardDll.cpp
changeset 0 c40eb8fe8501
child 22 c6a1762761b8
child 42 a828660c511c
equal deleted inserted replaced
-1:000000000000 0:c40eb8fe8501
       
     1 /*
       
     2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Implements PcCardPktDrv class
       
    15 *
       
    16 */
       
    17 
       
    18 /*
       
    19 * %version: 12 %
       
    20 */
       
    21 
       
    22 #include <nifmbuf.h>
       
    23 #include <es_mbuf.h>
       
    24 #include "carddrv.h"
       
    25 #include "EtherCardApi.h"
       
    26 #include "am_debug.h" 
       
    27 #include "WlanProto.h"
       
    28 #include "sender_hw.h"
       
    29 #include "receiver_hw.h"
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CPcCardPktDrvFactory::NewDriverL()
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 CPcCardPktDrv* CPcCardPktDrv::NewL( CLANLinkCommon* aParent )
       
    38     {
       
    39     // Create the packet driver object
       
    40     CPcCardPktDrv *drv = new(ELeave) CPcCardPktDrv();
       
    41 
       
    42     CleanupStack::PushL(drv);
       
    43     drv->ConstructL(aParent);
       
    44     CleanupStack::Pop(drv);
       
    45 
       
    46     return drv;
       
    47     }
       
    48 
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // CPcCardPktDrv::CPcCardPktDrv()
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 // Packet Driver object
       
    55 CPcCardPktDrv::CPcCardPktDrv()
       
    56     :iCardOpen( EFalse )
       
    57     {   
       
    58     }
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CPcCardPktDrvFactory::~CPcCardPktDrv()
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CPcCardPktDrv::~CPcCardPktDrv()
       
    65     {
       
    66     delete iReceiver; 
       
    67     delete iSender;  
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // CPcCardPktDrvFactory::ConstructL()
       
    72 // -----------------------------------------------------------------------------
       
    73 //
       
    74 void CPcCardPktDrv::ConstructL( CLANLinkCommon* aParent )
       
    75     {
       
    76     DEBUG("CPcCardPktDrv::ConstructL()");
       
    77 
       
    78     iParent = aParent;
       
    79 
       
    80     iSender = CSender::NewL( this );
       
    81     iReceiver = CReceiver::NewL( this );
       
    82 
       
    83     User::LeaveIfError( iCard.Open() );
       
    84 
       
    85     User::LeaveIfError( iCard.InitialiseBuffers( iFrameXferBlock ) );
       
    86   }
       
    87 
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CPcCardPktDrvFactory::StartInterface()
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 TInt CPcCardPktDrv::StartInterface()
       
    94     {
       
    95     DEBUG("CPcCardPktDrv::StartInterface()");
       
    96     // Opens the card and queues a read
       
    97     // validates
       
    98     TRAPD( err, StartL() );
       
    99     return err;
       
   100     }
       
   101  
       
   102 // -----------------------------------------------------------------------------
       
   103 // CPcCardPktDrvFactory::StopInterface()
       
   104 // -----------------------------------------------------------------------------
       
   105 //
       
   106 TInt CPcCardPktDrv::StopInterface()
       
   107     {
       
   108     DEBUG("CPcCardPktDrv::StopInterface()");
       
   109     // Closes the card
       
   110     // validates
       
   111     Stop();
       
   112     
       
   113     return KErrNone;
       
   114     }
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CPcCardPktDrvFactory::ResetInterface()
       
   118 // -----------------------------------------------------------------------------
       
   119 //
       
   120 TInt CPcCardPktDrv::ResetInterface()
       
   121     {
       
   122     DEBUG("CPcCardPktDrv::ResetInterface()");
       
   123     Stop();
       
   124     TRAPD( err, StartL() );
       
   125     return err;
       
   126     }
       
   127 
       
   128 // -----------------------------------------------------------------------------
       
   129 // CPcCardPktDrvFactory::Send()
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 TInt CPcCardPktDrv::Send( RMBufChain &aPacket )
       
   133     {
       
   134     if( !CardOpen() )
       
   135         {
       
   136         aPacket.Free();
       
   137         return KErrNotReady;
       
   138         }
       
   139 
       
   140     return iSender->Send( aPacket );
       
   141     }
       
   142 
       
   143 // -----------------------------------------------------------------------------
       
   144 // CPcCardPktDrvFactory::GetInterfaceAddress()
       
   145 // -----------------------------------------------------------------------------
       
   146 //
       
   147 TUint8* CPcCardPktDrv::GetInterfaceAddress()
       
   148     {
       
   149     DEBUG("CPcCardPktDrv::GetInterfaceAddress()");
       
   150     
       
   151     iConfig.SetMax();
       
   152     iCard.GetConfig( iConfig );
       
   153 
       
   154     // MAC address is located 3 bytes from the start of the buffer
       
   155     return( (TUint8*)iConfig.Ptr() )+3;
       
   156     }
       
   157 
       
   158 // -----------------------------------------------------------------------------
       
   159 // CPcCardPktDrv::StartL()
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 void CPcCardPktDrv::StartL()
       
   163     {
       
   164     // Open the Card LDD
       
   165     DEBUG("CPcCardPktDrv::StartL()");
       
   166 
       
   167     iCardOpen = ETrue;
       
   168     
       
   169     // We just assume that "link layer" is always immediatedly up
       
   170     iParent->LinkLayerUp();
       
   171     iReceiver->QueueRead();
       
   172     }
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 // CPcCardPktDrv::Stop()
       
   176 // -----------------------------------------------------------------------------
       
   177 //
       
   178 void CPcCardPktDrv::Stop()
       
   179     {
       
   180     DEBUG("CPcCardPktDrv::Stop()");
       
   181 
       
   182     iCard.ResumeTxCancel();
       
   183     iSender->Cancel();
       
   184 
       
   185     iCard.ReadCancel();
       
   186     iReceiver->Cancel();
       
   187     
       
   188     iCard.ReleaseBuffers();
       
   189 
       
   190     iCard.Close();
       
   191     iCardOpen = EFalse; 
       
   192     } 
       
   193 
       
   194 
       
   195 /**
       
   196 * Implementation for methods declared in 802dot11.h
       
   197 */
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // os_memcpy
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 TAny* os_memcpy( TAny* aDest, const TAny* aSrc, TUint32 aLengthinBytes )
       
   204     {
       
   205     Mem::Copy( aDest, aSrc, aLengthinBytes );
       
   206     return aDest;
       
   207     }
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // os_memcmp
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 TInt os_memcmp( const TAny* aSrc1, const TAny* aSrc2, TUint32 aLengthinBytes )
       
   214     {
       
   215     return Mem::Compare( reinterpret_cast<const TUint8*>( aSrc1 ), aLengthinBytes,
       
   216         reinterpret_cast<const TUint8*>( aSrc2 ), aLengthinBytes );
       
   217     }
       
   218 
       
   219