wlan_bearer/wlanldd/wlan_symbian/wlanldd_symbian/src/EthernetFrameMemMngr.cpp
branchRCL_3
changeset 18 d3d7683d16f5
parent 17 a828660c511c
equal deleted inserted replaced
17:a828660c511c 18:d3d7683d16f5
    14 * Description:   Implementation of the DEthernetFrameMemMngr class.
    14 * Description:   Implementation of the DEthernetFrameMemMngr class.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 /*
    18 /*
    19 * %version: 25 %
    19 * %version: 24 %
    20 */
    20 */
    21 
    21 
    22 #include "WlLddWlanLddConfig.h"
    22 #include "WlLddWlanLddConfig.h"
    23 #include "DataFrameMemMngr.h"
    23 #include "DataFrameMemMngr.h"
    24 #include "MgmtFrameMemMngr.h"
    24 #include "MgmtFrameMemMngr.h"
   168 //
   168 //
   169 DEthernetFrameMemMngr::~DEthernetFrameMemMngr()
   169 DEthernetFrameMemMngr::~DEthernetFrameMemMngr()
   170     {
   170     {
   171     MarkMemFree();
   171     MarkMemFree();
   172     
   172     
   173     iFrameXferBlockBase = NULL;
   173     iFrameXferBlock = NULL;
       
   174     iTxDataBuffer = NULL;
   174     iRxDataChunk = NULL;
   175     iRxDataChunk = NULL;
   175     }
   176     }
   176 
   177 
   177 // ---------------------------------------------------------------------------
   178 // ---------------------------------------------------------------------------
   178 // 
   179 // 
   179 // ---------------------------------------------------------------------------
   180 // ---------------------------------------------------------------------------
   180 //
   181 //
   181 TDataBuffer* DEthernetFrameMemMngr::OnWriteEthernetFrame() const
   182 TDataBuffer* DEthernetFrameMemMngr::OnWriteEthernetFrame() const
   182     {
   183     {
       
   184     if ( iTxDataBuffer->GetLength() >= sizeof( SEthernetHeader ) )
       
   185         {
       
   186         return iTxDataBuffer;
       
   187         }
       
   188     else
       
   189         {
       
   190         os_assert( (TUint8*)("WLANLDD: panic"), (TUint8*)(WLAN_FILE), __LINE__ );
       
   191         return NULL;
       
   192         }
       
   193     }
       
   194 
       
   195 // ---------------------------------------------------------------------------
       
   196 // 
       
   197 // ---------------------------------------------------------------------------
       
   198 //
       
   199 TBool DEthernetFrameMemMngr::OnReadRequest()
       
   200     {
       
   201     TBool ret( EFalse );
       
   202 
       
   203     if ( IsMemInUse() )
       
   204         {
       
   205         if ( iCountCompleted )
       
   206             {
       
   207             // free relevant buffers
       
   208             DoFreeRxBuffers();
       
   209             iCountCompleted = 0; // no buffers anymore in process in user mode
       
   210             
       
   211             // make sure that the same buffers are not tried to be
       
   212             // freed again thru the incremental freeing method
       
   213             iFrameXferBlock->KeAllUserSideRxBuffersFreed();
       
   214             }
       
   215 
       
   216         if ( iCountTobeCompleted )
       
   217             {
       
   218             // there are Rx buffers to be completed
       
   219             
       
   220             iFrameXferBlock->KeRxComplete( DoGetTobeCompletedBuffersStart(), 
       
   221                 iCountTobeCompleted );  
       
   222             // mark the completed buffers
       
   223             assign( DoGetTobeCompletedBuffersStart(), 
       
   224                 DoGetCompletedBuffersStart(), 
       
   225                 iCountTobeCompleted );
       
   226             iCountCompleted = iCountTobeCompleted;
       
   227             iCountTobeCompleted = 0;
       
   228 
       
   229             ret = ETrue;
       
   230              // the frame Rx request won't be pending as the callee shall 
       
   231              // complete it
       
   232             iReadStatus = ENotPending;
       
   233             }
       
   234         else
       
   235             {
       
   236             // there are no Rx buffers to be completed. The Rx request is
       
   237             // left pending
       
   238             iReadStatus = EPending;
       
   239             }
       
   240         }
       
   241     else
       
   242         {
       
   243         os_assert( (TUint8*)("WLANLDD: panic"), (TUint8*)(WLAN_FILE), __LINE__ );
       
   244         }
       
   245 
       
   246     return ret;
       
   247     }
       
   248 
       
   249 // ---------------------------------------------------------------------------
       
   250 // 
       
   251 // ---------------------------------------------------------------------------
       
   252 //
       
   253 void DEthernetFrameMemMngr::DoMarkRxBufFree( TUint8* /*aBufferToFree*/ )
       
   254     {
   183     // not supported in default handler
   255     // not supported in default handler
   184 #ifndef NDEBUG    
       
   185     os_assert( (TUint8*)("WLANLDD: panic"), (TUint8*)(WLAN_FILE), __LINE__ );
   256     os_assert( (TUint8*)("WLANLDD: panic"), (TUint8*)(WLAN_FILE), __LINE__ );
   186 #endif        
       
   187     return NULL;
       
   188     }
   257     }
   189 
   258 
   190 // ---------------------------------------------------------------------------
   259 // ---------------------------------------------------------------------------
   191 // 
   260 // 
   192 // ---------------------------------------------------------------------------
   261 // ---------------------------------------------------------------------------
   194 void DEthernetFrameMemMngr::SetTxOffsets( 
   263 void DEthernetFrameMemMngr::SetTxOffsets( 
   195     TUint32 aEthernetFrameTxOffset,
   264     TUint32 aEthernetFrameTxOffset,
   196     TUint32 aDot11FrameTxOffset,
   265     TUint32 aDot11FrameTxOffset,
   197     TUint32 aSnapFrameTxOffset )
   266     TUint32 aSnapFrameTxOffset )
   198     {
   267     {
   199     if ( IsMemInUse() && iFrameXferBlockBase )
   268     if ( IsMemInUse() )
   200         {
   269         {
   201         iFrameXferBlockBase->KeSetTxOffsets(
   270         iFrameXferBlock->KeSetTxOffsets(
   202             aEthernetFrameTxOffset,
   271             aEthernetFrameTxOffset,
   203             aDot11FrameTxOffset,
   272             aDot11FrameTxOffset,
   204             aSnapFrameTxOffset );
   273             aSnapFrameTxOffset );
   205         }
   274         }
   206     }
   275     }
   219         buffer = DoGetNextFreeRxBuffer( aLengthinBytes );
   288         buffer = DoGetNextFreeRxBuffer( aLengthinBytes );
   220         }
   289         }
   221     else
   290     else
   222         {
   291         {
   223         // we are trying to acquire an Rx buffer but our user mode client 
   292         // we are trying to acquire an Rx buffer but our user mode client 
   224         // has not asked for the memory buffer pool to be initialized. In this
   293         // has not asked for the memorybuffer pool to be initialized. In this
   225         // case NULL is returned, as no buffers are available
   294         // case NULL is returned, as no buffers are available
   226          TraceDump(RX_FRAME, 
   295          TraceDump(RX_FRAME, 
   227             ("WLANLDD: DEthernetFrameMemMngr::OnGetEthernetFrameRxBuffer: not initialized => failed"));       
   296             ("WLANLDD: DEthernetFrameMemMngr::OnGetEthernetFrameRxBuffer: not initialized => failed"));       
   228         }
   297         }
   229 
   298 
   236 //
   305 //
   237 TDataBuffer* DEthernetFrameMemMngr::GetRxFrameMetaHeader()
   306 TDataBuffer* DEthernetFrameMemMngr::GetRxFrameMetaHeader()
   238     {
   307     {
   239     TDataBuffer* buffer ( NULL );
   308     TDataBuffer* buffer ( NULL );
   240 
   309 
   241     if ( IsMemInUse() && iRxFrameMemoryPool )
   310     if ( IsMemInUse() )
   242         {
   311         {
   243         buffer = reinterpret_cast<TDataBuffer*>(
   312         buffer = reinterpret_cast<TDataBuffer*>(
   244             iRxFrameMemoryPool->Alloc( sizeof( TDataBuffer ), ETrue ) );
   313             iRxFrameMemoryPool->Alloc( sizeof( TDataBuffer ), ETrue ) );
   245 
   314 
   246         TraceDump(RX_FRAME, 
   315         TraceDump(RX_FRAME, 
   264 // 
   333 // 
   265 // ---------------------------------------------------------------------------
   334 // ---------------------------------------------------------------------------
   266 //
   335 //
   267 void DEthernetFrameMemMngr::FreeRxFrameMetaHeader( TDataBuffer* aMetaHeader )
   336 void DEthernetFrameMemMngr::FreeRxFrameMetaHeader( TDataBuffer* aMetaHeader )
   268     {
   337     {
   269     if ( IsMemInUse() && iRxFrameMemoryPool )
   338     if ( IsMemInUse() )
   270         {
   339         {
   271         TraceDump( RX_FRAME, 
       
   272             (("WLANLDD: DEthernetFrameMemMngr::FreeRxFrameMetaHeader: "
       
   273               "at addr: 0x%08x"),
       
   274             reinterpret_cast<TUint32>(aMetaHeader)) );
       
   275         
       
   276         iRxFrameMemoryPool->Free( aMetaHeader );
   340         iRxFrameMemoryPool->Free( aMetaHeader );
   277         }
   341         }
   278     else
   342     else
   279         {
   343         {
   280         // the whole Rx memory pool - including aMetaHeader - has already
   344         // the whole Rx memory pool - including aMetaHeader - has already
   281         // been deallocated, so nothing is done in this case
   345         // been deallocated, so nothing is done in this case
   282         TraceDump( RX_FRAME, 
   346         TraceDump( RX_FRAME, 
   283             ("WLANLDD: MgmtFrameMemMngr::FreeRxFrameMetaHeader: Rx memory "
   347             ("WLANLDD: MgmtFrameMemMngr::FreeRxFrameMetaHeader: Rx memory pool already deallocated; no action needed") );                
   284              "pool already deallocated; no action needed") );                
       
   285         }    
   348         }    
   286     }
   349     }
   287 
   350 
   288 // ---------------------------------------------------------------------------
   351 // ---------------------------------------------------------------------------
   289 // Note! This method is executed in the context of the user mode client 
       
   290 // thread, but in supervisor mode
       
   291 // ---------------------------------------------------------------------------
       
   292 //
       
   293 void DEthernetFrameMemMngr::FreeRxPacket( 
       
   294     TDataBuffer* aFrameToFreeInUserSpace )
       
   295     {
       
   296     if ( IsMemInUse() && 
       
   297          aFrameToFreeInUserSpace && 
       
   298          iFrameXferBlockBase &&
       
   299          iRxFrameMemoryPool )
       
   300         {
       
   301         TDataBuffer* frameToFreeInKernSpace ( 
       
   302             reinterpret_cast<TDataBuffer*>(
       
   303                 reinterpret_cast<TUint8*>(
       
   304                     aFrameToFreeInUserSpace) + 
       
   305                 iFrameXferBlockBase->UserToKernAddrOffset()) );
       
   306         
       
   307         // first free the actual Rx frame buffer if relevant
       
   308         if ( frameToFreeInKernSpace->KeFlags() & 
       
   309              TDataBuffer::KDontReleaseBuffer )
       
   310             {
       
   311             // this buffer shall not be freed yet, so no action here
       
   312             
       
   313             TraceDump( RX_FRAME, 
       
   314                 (("WLANLDD: DEthernetFrameMemMngr::FreeRxPacket: don't free "
       
   315                   "yet Rx buf at addr: 0x%08x"),
       
   316                 reinterpret_cast<TUint32>(
       
   317                     frameToFreeInKernSpace->KeGetBufferStart()) ) );            
       
   318             }
       
   319         else
       
   320             {
       
   321             TraceDump( RX_FRAME, 
       
   322                 (("WLANLDD: DEthernetFrameMemMngr::FreeRxPacket: free Rx buf "
       
   323                   "at addr: 0x%08x"),
       
   324                 reinterpret_cast<TUint32>(
       
   325                     frameToFreeInKernSpace->KeGetBufferStart()) ) );
       
   326     
       
   327             iRxFrameMemoryPool->Free( 
       
   328                 frameToFreeInKernSpace->KeGetBufferStart()
       
   329                 // take into account the alignment padding 
       
   330                 - iRxBufAlignmentPadding );
       
   331             }
       
   332         
       
   333         // free the Rx frame meta header
       
   334         
       
   335         TraceDump( RX_FRAME, 
       
   336             (("WLANLDD: DEthernetFrameMemMngr::FreeRxPacket: "
       
   337               "free metahdr at addr: 0x%08x"),
       
   338             reinterpret_cast<TUint32>(frameToFreeInKernSpace)) );
       
   339         
       
   340         iRxFrameMemoryPool->Free( frameToFreeInKernSpace );
       
   341         aFrameToFreeInUserSpace = NULL;
       
   342         }
       
   343     }
       
   344 
       
   345 // ---------------------------------------------------------------------------
       
   346 // 
   352 // 
   347 // ---------------------------------------------------------------------------
   353 // ---------------------------------------------------------------------------
   348 //
   354 //
   349 TBool DEthernetFrameMemMngr::OnEthernetFrameRxComplete( 
   355 TBool DEthernetFrameMemMngr::OnEthernetFrameRxComplete( 
   350     TDataBuffer*& aBufferStart, 
   356     const TDataBuffer*& aBufferStart, 
   351     TUint32 aNumOfBuffers )
   357     TUint32 aNumOfBuffers )
   352     {
   358     {
   353     TBool ret( EFalse );
   359     TBool ret( EFalse );
   354 
   360 
   355     if ( IsMemInUse() && 
   361     if ( IsMemInUse() && 
   386 
   392 
   387     return NULL;
   393     return NULL;
   388     }
   394     }
   389 
   395 
   390 // ---------------------------------------------------------------------------
   396 // ---------------------------------------------------------------------------
   391 // 
   397 // This default implementation always returns NULL
   392 // ---------------------------------------------------------------------------
   398 // ---------------------------------------------------------------------------
   393 //
   399 //
   394 void DEthernetFrameMemMngr::DoMarkRxBufFree( TUint8* /*aBufferToFree*/ )
   400 TDataBuffer* DEthernetFrameMemMngr::AllocTxBuffer( TUint aLength )
       
   401     {
       
   402     return NULL;
       
   403     }
       
   404 
       
   405 // ---------------------------------------------------------------------------
       
   406 // 
       
   407 // ---------------------------------------------------------------------------
       
   408 //
       
   409 TBool DEthernetFrameMemMngr::AddTxFrame( 
       
   410     TDataBuffer* aPacketInUserSpace, 
       
   411     TDataBuffer*& aPacketInKernSpace,
       
   412     TBool aUserDataTxEnabled )
       
   413     {
       
   414     if ( IsMemInUse() )
       
   415         {
       
   416         return (static_cast<RFrameXferBlockProtocolStack*>(
       
   417             iFrameXferBlock))->AddTxFrame( 
       
   418                 aPacketInUserSpace, 
       
   419                 aPacketInKernSpace,
       
   420                 aUserDataTxEnabled );
       
   421         }
       
   422     else
       
   423         {
       
   424         return EFalse;
       
   425         }
       
   426     }
       
   427 
       
   428 // ---------------------------------------------------------------------------
       
   429 // 
       
   430 // ---------------------------------------------------------------------------
       
   431 //
       
   432 TDataBuffer* DEthernetFrameMemMngr::GetTxFrame( 
       
   433     const TWhaTxQueueState& aTxQueueState,
       
   434     TBool& aMore )
       
   435     {
       
   436     if ( IsMemInUse() && iFrameXferBlock )
       
   437         {
       
   438         return (static_cast<RFrameXferBlockProtocolStack*>(
       
   439             iFrameXferBlock))->GetTxFrame( aTxQueueState, aMore );
       
   440         }
       
   441     else
       
   442         {
       
   443         return NULL;
       
   444         }
       
   445     }
       
   446 
       
   447 // ---------------------------------------------------------------------------
       
   448 // 
       
   449 // ---------------------------------------------------------------------------
       
   450 //
       
   451 void DEthernetFrameMemMngr::FreeTxPacket( TDataBuffer*& /*aPacket*/ )
   395     {
   452     {
   396     // not suported in this default implementation 
   453     // not suported in this default implementation 
   397 #ifndef NDEBUG    
       
   398     os_assert( (TUint8*)("WLANLDD: panic"), (TUint8*)(WLAN_FILE), __LINE__ );
   454     os_assert( (TUint8*)("WLANLDD: panic"), (TUint8*)(WLAN_FILE), __LINE__ );
   399 #endif    
   455     }
   400     }
   456 
   401 
   457 // ---------------------------------------------------------------------------
   402 // ---------------------------------------------------------------------------
   458 // 
   403 // This default implementation always returns NULL
   459 // ---------------------------------------------------------------------------
   404 // ---------------------------------------------------------------------------
   460 //
   405 //
   461 TBool DEthernetFrameMemMngr::ResumeClientTx( TBool aUserDataTxEnabled ) const 
   406 TDataBuffer* DEthernetFrameMemMngr::AllocTxBuffer( TUint /*aLength*/ )
   462     {
   407     {
   463     return (static_cast<RFrameXferBlockProtocolStack*>(
   408     return NULL;
   464         iFrameXferBlock))->ResumeClientTx( aUserDataTxEnabled );
   409     }
       
   410 
       
   411 // ---------------------------------------------------------------------------
       
   412 // 
       
   413 // ---------------------------------------------------------------------------
       
   414 //
       
   415 TBool DEthernetFrameMemMngr::AddTxFrame( 
       
   416     TDataBuffer* /*aPacketInUserSpace*/, 
       
   417     TDataBuffer*& /*aPacketInKernSpace*/,
       
   418     TBool /*aUserDataTxEnabled*/ )
       
   419     {
       
   420     // not suported in this default implementation 
       
   421 #ifndef NDEBUG    
       
   422     os_assert( (TUint8*)("WLANLDD: panic"), (TUint8*)(WLAN_FILE), __LINE__ );
       
   423 #endif
       
   424     
       
   425     return EFalse;
       
   426     }
       
   427 
       
   428 // ---------------------------------------------------------------------------
       
   429 // 
       
   430 // ---------------------------------------------------------------------------
       
   431 //
       
   432 TDataBuffer* DEthernetFrameMemMngr::GetTxFrame( 
       
   433     const TWhaTxQueueState& /*aTxQueueState*/,
       
   434     TBool& /*aMore*/ )
       
   435     {
       
   436     // not suported in this default implementation 
       
   437 #ifndef NDEBUG    
       
   438     os_assert( (TUint8*)("WLANLDD: panic"), (TUint8*)(WLAN_FILE), __LINE__ );
       
   439 #endif
       
   440     
       
   441     return NULL;
       
   442     }
       
   443 
       
   444 // ---------------------------------------------------------------------------
       
   445 // 
       
   446 // ---------------------------------------------------------------------------
       
   447 //
       
   448 void DEthernetFrameMemMngr::FreeTxPacket( TDataBuffer*& /*aPacket*/ )
       
   449     {
       
   450     // not suported in this default implementation 
       
   451 #ifndef NDEBUG    
       
   452     os_assert( (TUint8*)("WLANLDD: panic"), (TUint8*)(WLAN_FILE), __LINE__ );
       
   453 #endif
       
   454     }
       
   455 
       
   456 // ---------------------------------------------------------------------------
       
   457 // 
       
   458 // ---------------------------------------------------------------------------
       
   459 //
       
   460 TBool DEthernetFrameMemMngr::ResumeClientTx( 
       
   461     TBool /*aUserDataTxEnabled*/ ) const 
       
   462     {
       
   463     // not suported in this default implementation 
       
   464 #ifndef NDEBUG    
       
   465     os_assert( (TUint8*)("WLANLDD: panic"), (TUint8*)(WLAN_FILE), __LINE__ );
       
   466 #endif
       
   467     
       
   468     return EFalse;
       
   469     }
   465     }
   470 
   466 
   471 // ---------------------------------------------------------------------------
   467 // ---------------------------------------------------------------------------
   472 // 
   468 // 
   473 // ---------------------------------------------------------------------------
   469 // ---------------------------------------------------------------------------
   474 //
   470 //
   475 TBool DEthernetFrameMemMngr::AllTxQueuesEmpty() const
   471 TBool DEthernetFrameMemMngr::AllTxQueuesEmpty() const
   476     {
   472     {
   477     // not suported in this default implementation 
   473     return (static_cast<RFrameXferBlockProtocolStack*>(
   478 #ifndef NDEBUG    
   474             iFrameXferBlock))->AllTxQueuesEmpty();
   479     os_assert( (TUint8*)("WLANLDD: panic"), (TUint8*)(WLAN_FILE), __LINE__ );
   475     }
   480 #endif
       
   481     
       
   482     return EFalse;
       
   483     }