Example #1
0
/*---------------------------------------------------------------------------
    wpalIteratorInit – Initialize an interator by updating pCur to first item.
    Param: 
        pIter – pointer to a caller allocated wpt_iterator
        pPacket – pointer to a wpt_packet
    Return:
        eWLAN_PAL_STATUS_SUCCESS - success
---------------------------------------------------------------------------*/
wpt_status wpalIteratorInit(wpt_iterator *pIter, wpt_packet *pPacket)
{
   wpt_status         status     = eWLAN_PAL_STATUS_SUCCESS;
   wpt_iterator_info* pCurInfo   = NULL;
   wpt_iterator_info* pNextInfo  = NULL;
   wpt_iterator_info* pPktInfo   = NULL;

   // Validate the parameter pointers
   if (unlikely((NULL == pPacket)||(NULL==pIter)))
   {
      WPAL_TRACE(eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_ERROR,
                "%s : NULL input pointers %x %x", __func__, pPacket, pIter);
      return eWLAN_PAL_STATUS_E_INVAL;
   }

   pPktInfo = (wpt_iterator_info*)pPacket->pInternalData;
   if (unlikely(NULL == pPktInfo))
   {
      WPAL_TRACE(eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_ERROR,
                "%s : Invalid Packet Info", __func__);
      return eWLAN_PAL_STATUS_E_INVAL;
   }

   // if there is NO BD on this frame, then initialize the next pointer to
   // point the first fragment.
   if ( NULL == WPAL_PACKET_GET_BD_PHYS(pPacket) )
   {
     pCurInfo   = pPktInfo;
     pNextInfo           = NULL;
   }
   else
   {
     /*Allocate memory for the current info*/
     pCurInfo = wpalMemoryAllocate( sizeof(wpt_iterator_info) );

     // Validate the memory allocation
     if (unlikely(NULL == pCurInfo))
     {
        WPAL_TRACE(eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_ERROR,
                  "%s : Failed to allocate memory ", __func__);
        return eWLAN_PAL_STATUS_E_INVAL;
     }

     pCurInfo->pPhyAddr = WPAL_PACKET_GET_BD_PHYS(pPacket);
     pCurInfo->uLen     = WPAL_PACKET_GET_BD_LENGTH(pPacket);

     pNextInfo           = pPktInfo;
   }      

   pIter->pCur     = (void*)pCurInfo; 
   pIter->pNext    = (void*)pNextInfo;
   pIter->pContext = NULL;

   return status;
}/*wpalIteratorInit*/
wpt_status wpalIteratorInit(wpt_iterator *pIter, wpt_packet *pPacket)
{
   wpt_status         status     = eWLAN_PAL_STATUS_SUCCESS;
   wpt_iterator_info* pCurInfo   = NULL;
   wpt_iterator_info* pNextInfo  = NULL;
   wpt_iterator_info* pPktInfo   = NULL;

   //                                
   if (unlikely((NULL == pPacket)||(NULL==pIter)))
   {
      WPAL_TRACE(eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_ERROR,
                "%s : NULL input pointers %x %x", __func__, pPacket, pIter);
      return eWLAN_PAL_STATUS_E_INVAL;
   }

   pPktInfo = (wpt_iterator_info*)pPacket->pInternalData;
   if (unlikely(NULL == pPktInfo))
   {
      WPAL_TRACE(eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_ERROR,
                "%s : Invalid Packet Info", __func__);
      return eWLAN_PAL_STATUS_E_INVAL;
   }

   //                                                                     
   //                          
   if ( NULL == WPAL_PACKET_GET_BD_PHYS(pPacket) )
   {
     pCurInfo   = pPktInfo;
     pNextInfo           = NULL;
   }
   else
   {
     /*                                    */
     pCurInfo = wpalMemoryAllocate( sizeof(wpt_iterator_info) );

     //                               
     if (unlikely(NULL == pCurInfo))
     {
        WPAL_TRACE(eWLAN_MODULE_PAL, eWLAN_PAL_TRACE_LEVEL_ERROR,
                  "%s : Failed to allocate memory ", __func__);
        return eWLAN_PAL_STATUS_E_INVAL;
     }

     pCurInfo->pPhyAddr = WPAL_PACKET_GET_BD_PHYS(pPacket);
     pCurInfo->uLen     = WPAL_PACKET_GET_BD_LENGTH(pPacket);

     pNextInfo           = pPktInfo;
   }      

   pIter->pCur     = (void*)pCurInfo; 
   pIter->pNext    = (void*)pNextInfo;
   pIter->pContext = NULL;

   return status;
}/*                */