📄 rtmp_init.c
字号:
if(!pMLMEContext->TransferBuffer){
DBGPRINT(RT_DEBUG_ERROR,"Not enough memory\n");
Status = NDIS_STATUS_RESOURCES;
goto out2;
}
NdisZeroMemory(pMLMEContext->TransferBuffer, sizeof(TX_BUFFER));
pMLMEContext->pAd = pAd ;
pMLMEContext->InUse = FALSE;
pMLMEContext->IRPPending = FALSE;
}
//
// BEACON_RING_SIZE
//
for (i = 0; i < BEACON_RING_SIZE; i++)
{
PTX_CONTEXT pBeaconContext = &(pAd->BeaconContext[i]);
pBeaconContext->pUrb = RT_USB_ALLOC_URB(0);
if(pBeaconContext->pUrb == NULL){
Status = NDIS_STATUS_RESOURCES;
goto out2;
}
pBeaconContext->TransferBuffer= (PTX_BUFFER) kmalloc(sizeof(TX_BUFFER), GFP_KERNEL);
if(!pBeaconContext->TransferBuffer){
DBGPRINT(RT_DEBUG_ERROR,"Not enough memory\n");
Status = NDIS_STATUS_RESOURCES;
goto out3;
}
NdisZeroMemory(pBeaconContext->TransferBuffer, sizeof(TX_BUFFER));
pBeaconContext->pAd = pAd;
pBeaconContext->InUse = FALSE;
pBeaconContext->IRPPending = FALSE;
}
//
// NullContext
//
pNullContext->pUrb = RT_USB_ALLOC_URB(0);
if(pNullContext->pUrb == NULL){
Status = NDIS_STATUS_RESOURCES;
goto out3;
}
pNullContext->TransferBuffer= (PTX_BUFFER) kmalloc(sizeof(TX_BUFFER), GFP_KERNEL);
if(!pNullContext->TransferBuffer){
DBGPRINT(RT_DEBUG_ERROR,"Not enough memory\n");
Status = NDIS_STATUS_RESOURCES;
goto out4;
}
NdisZeroMemory(pNullContext->TransferBuffer, sizeof(TX_BUFFER));
pNullContext->pAd = pAd;
pNullContext->InUse = FALSE;
pNullContext->IRPPending = FALSE;
//
// RTSContext
//
pRTSContext->pUrb = RT_USB_ALLOC_URB(0);
if(pRTSContext->pUrb == NULL){
Status = NDIS_STATUS_RESOURCES;
goto out4;
}
pRTSContext->TransferBuffer= (PTX_BUFFER) kmalloc(sizeof(TX_BUFFER), GFP_KERNEL);
if(!pRTSContext->TransferBuffer){
DBGPRINT(RT_DEBUG_ERROR,"Not enough memory\n");
Status = NDIS_STATUS_RESOURCES;
goto out5;
}
NdisZeroMemory(pRTSContext->TransferBuffer, sizeof(TX_BUFFER));
pRTSContext->pAd = pAd;
pRTSContext->InUse = FALSE;
pRTSContext->IRPPending = FALSE;
//
// PsPollContext
//
pPsPollContext->pUrb = RT_USB_ALLOC_URB(0);
if(pPsPollContext->pUrb == NULL){
Status = NDIS_STATUS_RESOURCES;
goto out5;
}
pPsPollContext->TransferBuffer= (PTX_BUFFER) kmalloc(sizeof(TX_BUFFER), GFP_KERNEL);
if(!pPsPollContext->TransferBuffer){
DBGPRINT(RT_DEBUG_ERROR,"Not enough memory\n");
Status = NDIS_STATUS_RESOURCES;
goto out6;
}
NdisZeroMemory(pPsPollContext->TransferBuffer, sizeof(TX_BUFFER));
pPsPollContext->pAd = pAd;
pPsPollContext->InUse = FALSE;
pPsPollContext->IRPPending = FALSE;
} while (FALSE);
return Status;
out6:
if (NULL != pPsPollContext->pUrb)
{
RTUSB_UNLINK_URB(pPsPollContext->pUrb);
usb_free_urb(pPsPollContext->pUrb);
pPsPollContext->pUrb = NULL;
}
if (NULL != pPsPollContext->TransferBuffer)
{
kfree(pPsPollContext->TransferBuffer);
pPsPollContext->TransferBuffer = NULL;
}
out5:
if (NULL != pRTSContext->pUrb)
{
RTUSB_UNLINK_URB(pRTSContext->pUrb);
usb_free_urb(pRTSContext->pUrb);
pRTSContext->pUrb = NULL;
}
if (NULL != pRTSContext->TransferBuffer)
{
kfree(pRTSContext->TransferBuffer);
pRTSContext->TransferBuffer = NULL;
}
out4:
if (NULL != pNullContext->pUrb)
{
RTUSB_UNLINK_URB(pNullContext->pUrb);
usb_free_urb(pNullContext->pUrb);
pNullContext->pUrb = NULL;
}
if (NULL != pNullContext->TransferBuffer)
{
kfree(pNullContext->TransferBuffer);
pNullContext->TransferBuffer = NULL;
}
out3:
for (i = 0; i < BEACON_RING_SIZE; i++)
{
PTX_CONTEXT pBeaconContext = &(pAd->BeaconContext[i]);
if ( NULL != pBeaconContext->pUrb )
{
RTUSB_UNLINK_URB(pBeaconContext->pUrb);
usb_free_urb(pBeaconContext->pUrb);
pBeaconContext->pUrb = NULL;
}
if ( NULL != pBeaconContext->TransferBuffer )
{
kfree( pBeaconContext->TransferBuffer);
pBeaconContext->TransferBuffer = NULL;
}
}
out2:
for ( i= 0; i < PRIO_RING_SIZE; i++ )
{
PTX_CONTEXT pMLMEContext = &(pAd->MLMEContext[i]);
if ( NULL != pMLMEContext->pUrb )
{
RTUSB_UNLINK_URB(pMLMEContext->pUrb);
usb_free_urb(pMLMEContext->pUrb);
pMLMEContext->pUrb = NULL;
}
if ( NULL != pMLMEContext->TransferBuffer )
{
kfree( pMLMEContext->TransferBuffer);
pMLMEContext->TransferBuffer = NULL;
}
}
out1:
for (acidx = 0; acidx < 4; acidx++)
{
for ( i= 0; i < TX_RING_SIZE; i++ )
{
PTX_CONTEXT pTxContext = &(pAd->TxContext[acidx][i]);
if ( NULL != pTxContext->pUrb )
{
RTUSB_UNLINK_URB(pTxContext->pUrb);
usb_free_urb(pTxContext->pUrb);
pTxContext->pUrb = NULL;
}
if ( NULL != pTxContext->TransferBuffer )
{
kfree( pTxContext->TransferBuffer);
pTxContext->TransferBuffer = NULL;
}
}
}
done:
return Status;
}
/*
========================================================================
Routine Description:
Initialize receive data structures
Arguments:
Adapter Pointer to our adapter
Return Value:
NDIS_STATUS_SUCCESS
NDIS_STATUS_RESOURCES
Note:
Initialize all receive releated private buffer, include those define
in RTMP_ADAPTER structure and all private data structures. The mahor
work is to allocate buffer for each packet and chain buffer to
NDIS packet descriptor.
========================================================================
*/
NDIS_STATUS NICInitRecv(
IN PRTMP_ADAPTER pAd)
{
UCHAR i;
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
DBGPRINT(RT_DEBUG_TRACE,"--> NICInitRecv\n");
pAd->NextRxBulkInIndex = 0;
atomic_set( &pAd->PendingRx, 0);
for (i = 0; i < RX_RING_SIZE; i++)
{
PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
pRxContext->pUrb = RT_USB_ALLOC_URB(0);
if(pRxContext->pUrb == NULL)
{
Status = NDIS_STATUS_RESOURCES;
DBGPRINT(RT_DEBUG_TRACE,"--> pRxContext->pUrb == NULL\n");
break;
}
pRxContext->TransferBuffer= (PUCHAR) kmalloc(BUFFER_SIZE, MEM_ALLOC_FLAG);
if(!pRxContext->TransferBuffer)
{
DBGPRINT(RT_DEBUG_ERROR,"Not enough memory\n");
Status = NDIS_STATUS_RESOURCES;
break;
}
NdisZeroMemory(pRxContext->TransferBuffer, BUFFER_SIZE);
pRxContext->pAd = pAd;
pRxContext->InUse = FALSE;
pRxContext->IRPPending = FALSE;
}
DBGPRINT(RT_DEBUG_TRACE,"<-- NICInitRecv\n");
return Status;
}
////////////////////////////////////////////////////////////////////////////
//
// FUNCTION
// ReleaseAdapter
//
// DESCRIPTION
// Calls USB_InterfaceStop and frees memory allocated for the URBs
// calls NdisMDeregisterDevice and frees the memory
// allocated in VNetInitialize for the Adapter Object
//
// INPUT
// Adapter Pointer to RTMP_ADAPTER structure
//
// OUTPUT
// -
//
////////////////////////////////////////////////////////////////////////////
VOID ReleaseAdapter(
IN PRTMP_ADAPTER pAd,
IN BOOLEAN IsFree,
IN BOOLEAN IsOnlyTx)
{
UINT i, acidx;
PTX_CONTEXT pNullContext = &pAd->NullContext;
PTX_CONTEXT pPsPollContext = &pAd->PsPollContext;
PTX_CONTEXT pRTSContext = &pAd->RTSContext;
DBGPRINT(RT_DEBUG_TRACE, "---> ReleaseAdapter\n");
if (!IsOnlyTx)
{
// Free all resources for the RECEIVE buffer queue.
for (i = 0; i < RX_RING_SIZE; i++)
{
PRX_CONTEXT pRxContext = &(pAd->RxContext[i]);
if (pRxContext->pUrb != NULL)
{
RTUSB_UNLINK_URB(pRxContext->pUrb);
if (IsFree)
usb_free_urb(pRxContext->pUrb);
pRxContext->pUrb = NULL;
}
if (pRxContext->TransferBuffer != NULL)
{
kfree(pRxContext->TransferBuffer);
pRxContext->TransferBuffer = NULL;
}
}
}
// Free PsPoll frame resource
if (NULL != pPsPollContext->pUrb)
{
RTUSB_UNLINK_URB(pPsPollContext->pUrb);
if (IsFree)
usb_free_urb(pPsPollContext->pUrb);
pPsPollContext->pUrb = NULL;
}
if (NULL != pPsPollContext->TransferBuffer)
{
kfree(pPsPollContext->TransferBuffer);
pPsPollContext->TransferBuffer = NULL;
}
// Free NULL frame resource
if (NULL != pNullContext->pUrb)
{
RTUSB_UNLINK_URB(pNullContext->pUrb);
if (IsFree)
usb_free_urb(pNullContext->pUrb);
pNullContext->pUrb = NULL;
}
if (NULL != pNullContext->TransferBuffer)
{
kfree(pNullContext->TransferBuffer);
pNullContext->TransferBuffer = NULL;
}
// Free RTS frame resource
if (NULL != pRTSContext->pUrb)
{
RTUSB_UNLINK_URB(pRTSContext->pUrb);
if (IsFree)
usb_free_urb(pRTSContext->pUrb);
pRTSContext->pUrb = NULL;
}
if (NULL != pRTSContext->TransferBuffer)
{
kfree(pRTSContext->TransferBuffer);
pRTSContext->TransferBuffer = NULL;
}
// Free beacon frame resource
for (i = 0; i < BEACON_RING_SIZE; i++)
{
PTX_CONTEXT pBeaconContext = &(pAd->BeaconContext[i]);
if ( NULL != pBeaconContext->pUrb )
{
RTUSB_UNLINK_URB(pBeaconContext->pUrb);
if (IsFree)
usb_free_urb(pBeaconContext->pUrb);
pBeaconContext->pUrb = NULL;
}
if ( NULL != pBeaconContext->TransferBuffer )
{
kfree( pBeaconContext->TransferBuffer);
pBeaconContext->TransferBuffer = NULL;
}
}
// Free Prio frame resource
for ( i= 0; i < PRIO_RING_SIZE; i++ )
{
PTX_CONTEXT pMLMEContext = &(pAd->MLMEContext[i]);
if ( NULL != pMLMEContext->pUrb )
{
RTUSB_UNLINK_URB(pMLMEContext->pUrb);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -