VOID ndisprotAuditFreeMem( PVOID Pointer ) { PNPROTD_ALLOCATION pAllocInfo; NdisAcquireSpinLock(&(ndisprotdMemoryLock)); pAllocInfo = CONTAINING_RECORD(Pointer, NPROTD_ALLOCATION, UserData); if (pAllocInfo->Signature != NPROTD_MEMORY_SIGNATURE) { DEBUGP(DL_ERROR, ("ndisprotAuditFreeMem: unknown buffer 0x%p!\n", Pointer)); NdisReleaseSpinLock(&(ndisprotdMemoryLock)); #if DBG DbgBreakPoint(); #endif return; } pAllocInfo->Signature = (ULONG)'DEAD'; if (pAllocInfo->Prev != (PNPROTD_ALLOCATION)NULL) { pAllocInfo->Prev->Next = pAllocInfo->Next; } else { ndisprotdMemoryHead = pAllocInfo->Next; } if (pAllocInfo->Next != (PNPROTD_ALLOCATION)NULL) { pAllocInfo->Next->Prev = pAllocInfo->Prev; } else { ndisprotdMemoryTail = pAllocInfo->Prev; } ndisprotdAllocCount--; NdisReleaseSpinLock(&(ndisprotdMemoryLock)); NdisFreeMemory(pAllocInfo, 0, 0); }
VOID FilterCancelOidRequest( IN NDIS_HANDLE FilterModuleContext, IN PVOID RequestId ) { PNETGW_ADAPT pAdapter = (PNETGW_ADAPT)FilterModuleContext; PNDIS_OID_REQUEST OriginalRequest = NULL; NdisAcquireSpinLock(&pAdapter->Lock); OriginalRequest = pAdapter->m_IntReq.pOrigReq; if ((OriginalRequest != NULL) && (OriginalRequest->RequestId == RequestId)) { NdisReleaseSpinLock(&pAdapter->Lock); NdisFCancelOidRequest(pAdapter->FilterHandle, RequestId); } else NdisReleaseSpinLock(&pAdapter->Lock); }
VOID NPF_StopUsingOpenInstance( IN POPEN_INSTANCE pOpen ) { NdisAcquireSpinLock(&pOpen->OpenInUseLock); ASSERT(pOpen->NumPendingIrps > 0); pOpen->NumPendingIrps --; NdisReleaseSpinLock(&pOpen->OpenInUseLock); }
static void ba_mpdu_blk_free(struct rt_rtmp_adapter *pAd, struct reordering_mpdu *mpdu_blk) { ASSERT(mpdu_blk); NdisAcquireSpinLock(&pAd->mpdu_blk_pool.lock); /* blk_count--; */ ba_enqueue(&pAd->mpdu_blk_pool.freelist, mpdu_blk); NdisReleaseSpinLock(&pAd->mpdu_blk_pool.lock); }
/* Wait for NDIS to return any outstanding packets. The caller must already have taken some appropriate measures to make sure that no more packets arrive in the meantime. */ void ReceiverWaitForPacketReturn(PRECEIVER Receiver) { LARGE_INTEGER interval; interval.QuadPart = -100000; /* 100ms in units of 100ns */ NdisAcquireSpinLock(&Receiver->Common.Lock); while (Receiver->nRxInNdis) { TraceVerbose (("%d rx.\n", Receiver->nRxInNdis)); NdisReleaseSpinLock(&Receiver->Common.Lock); KeDelayExecutionThread(KernelMode, FALSE, &interval); NdisAcquireSpinLock(&Receiver->Common.Lock); ReceiverSwizzle(Receiver); } NdisReleaseSpinLock(&Receiver->Common.Lock); }
void ssh_interceptor_iodevice_cancel_queued_ioctl(PDEVICE_OBJECT device, PIRP irp) { SshInterceptorIoDevice io_dev; SshIoctlCancelFunction cancel_fn = NULL_FNPTR; void *cancel_context; SshIoctlCancelID cancel_id; Boolean cancelled = FALSE; PLIST_ENTRY entry; /* Cancel processing is protected by queue-specific lock, not by the (one and only) system-wide Cancel lock */ IoReleaseCancelSpinLock(irp->CancelIrql); io_dev = SSH_NTDEV_TO_SSHDEV(device); NdisAcquireSpinLock(&io_dev->ioctl_req_list_lock); entry = io_dev->active_ioctl_req_list.Flink; while (entry != &io_dev->active_ioctl_req_list) { SshIoDeviceIoctlRequest ioctl; SshIoDeviceIoctlHandler handler; ioctl = CONTAINING_RECORD(entry, SshIoDeviceIoctlRequestStruct, private_data.link); if (ioctl->private_data.irp == irp) { handler = ioctl->public_data.context; cancel_fn = handler->cancel_fn; cancel_context = handler->context; cancel_id = ioctl->public_data.cancel_id; break; } entry = entry->Flink; } NdisReleaseSpinLock(&io_dev->ioctl_req_list_lock); if (cancel_fn != NULL_FNPTR) { cancelled = (*cancel_fn)(cancel_context, cancel_id); } if (cancelled == FALSE) { /* We have a bug somewhere if we end up here */ SSH_NOTREACHED; } }
BOOLEAN RTMPRepeaterRemoveInvaildMacEntry( IN PRTMP_ADAPTER pAd, IN UCHAR idx, IN PUCHAR pAddr) { USHORT HashIdx; INVAILD_TRIGGER_MAC_ENTRY *pEntry = NULL; INVAILD_TRIGGER_MAC_ENTRY *pPrevEntry, *pProbeEntry; NdisAcquireSpinLock(&pAd->ApCfg.ReptCliEntryLock); HashIdx = MAC_ADDR_HASH_INDEX(pAddr); pEntry = &pAd->ApCfg.ReptControl.RepeaterInvaildEntry[idx]; if (pEntry && pEntry->bInsert) { pPrevEntry = NULL; pProbeEntry = pAd->ApCfg.ReptControl.ReptInvaildHash[HashIdx]; ASSERT(pProbeEntry); if (pProbeEntry != NULL) { /* update Hash list*/ do { if (pProbeEntry == pEntry) { if (pPrevEntry == NULL) { pAd->ApCfg.ReptControl.ReptInvaildHash[HashIdx] = pEntry->pNext; } else { pPrevEntry->pNext = pEntry->pNext; } break; } pPrevEntry = pProbeEntry; pProbeEntry = pProbeEntry->pNext; } while (pProbeEntry); } /* not found !!!*/ ASSERT(pProbeEntry != NULL); pAd->ApCfg.ReptControl.ReptInVaildMacSize--; } NdisZeroMemory(pEntry->MacAddr, MAC_ADDR_LEN); pEntry->bInsert = FALSE; NdisReleaseSpinLock(&pAd->ApCfg.ReptCliEntryLock); return TRUE; }
BOOLEAN NPF_StartUsingBinding( IN POPEN_INSTANCE pOpen) { ASSERT(pOpen != NULL); ASSERT(KeGetCurrentIrql() == PASSIVE_LEVEL); NdisAcquireSpinLock(&pOpen->AdapterHandleLock); if (pOpen->AdapterBindingStatus != ADAPTER_BOUND) { NdisReleaseSpinLock(&pOpen->AdapterHandleLock); return FALSE; } pOpen->AdapterHandleUsageCounter++; NdisReleaseSpinLock(&pOpen->AdapterHandleLock); return TRUE; }
//------------------------------------------------------------------------------ void circbuf_unlock(tCircBufInstance* pInstance_p) { tCircBufArchInstance* pArchInstance; // Check parameter validity ASSERT(pInstance_p != NULL); pArchInstance = (tCircBufArchInstance*)pInstance_p->pCircBufArchInstance; NdisReleaseSpinLock(&pArchInstance->spinlock); }
__inline SshDeviceBuffer ssh_iodevice_buffer_alloc(SshInterceptorIoDevice io_dev, Boolean reliable) { SshDeviceBuffer buf = NULL; PLIST_ENTRY entry; /* 1. Try to get a SshDeviceBuffer from a free list */ entry = NdisInterlockedRemoveHeadList(&io_dev->free_list, &io_dev->free_list_lock); if (entry) buf = CONTAINING_RECORD(entry, SshDeviceBufferStruct, link); /* 2. If failed and this is a reliable message, try to replace an existing unreliable one */ if ((buf == NULL) && (reliable)) { NdisAcquireSpinLock(&io_dev->output_queue_lock); if (!IsListEmpty(&io_dev->unreliable_output_queue)) { /* We found an existing unreliable message */ entry = RemoveHeadList(&io_dev->unreliable_output_queue); /* We must remove the entry from output_queue too */ buf = CONTAINING_RECORD(entry, SshDeviceBufferStruct, unreliable_list_link); SSH_ASSERT(buf != io_dev->current_read_buf); /* This removes the entry from output_queue */ RemoveEntryList(&(buf->link)); } NdisReleaseSpinLock(&io_dev->output_queue_lock); /* If found, we must delete the old message */ if (buf != NULL) ssh_free(buf->addr); } /* 3. If still failed, try to allocate memory for a new SshDeviceBuffer */ if ((buf == NULL) && (reliable)) { buf = ssh_malloc(sizeof(*buf)); if (buf) { /* This buffer will be deleted after use */ buf->pre_allocated = 0; } } return buf; }
/* Cancel routine for queued read operations initiated by user-mode daemons. */ void ssh_interceptor_iodevice_cancel_queued_read(PDEVICE_OBJECT device, PIRP irp) { SshInterceptorIoDevice io_dev; PLIST_ENTRY entry, next_entry; LIST_ENTRY cancelled_irps; /* Cancel processing is protected by queue-specific lock, not by the (one and only) system-wide Cancel lock */ IoReleaseCancelSpinLock(irp->CancelIrql); io_dev = SSH_NTDEV_TO_SSHDEV(device); NdisInitializeListHead(&cancelled_irps); SSH_DEBUG(SSH_D_MIDSTART, ("ssh_interceptor_iodevice_cancel_queued_read()")); /* Find and dequeue all canceled IRPs (not just the one given as argument). Complete the IRPs after releasing the spin lock. */ NdisAcquireSpinLock(&io_dev->read_queue_lock); entry = io_dev->read_queue.Flink; while (entry && (entry != &io_dev->read_queue)) { next_entry = entry->Flink; irp = CONTAINING_RECORD(entry, IRP, Tail.Overlay.ListEntry); if (irp->Cancel) { RemoveEntryList(entry); InsertTailList(&cancelled_irps, entry); } entry = next_entry; } NdisReleaseSpinLock(&io_dev->read_queue_lock); while (!IsListEmpty(&cancelled_irps)) { entry = RemoveHeadList(&cancelled_irps); irp = CONTAINING_RECORD(entry, IRP, Tail.Overlay.ListEntry); irp->IoStatus.Status = STATUS_CANCELLED; irp->IoStatus.Information = 0; IoCompleteRequest(irp, IO_NO_INCREMENT); SSH_DEBUG(SSH_D_NICETOKNOW, ("IoCompleteRequest(irp = 0x%p, status = STATUS_CANCELLED)", irp)); }; }
/* set idd mtu */ mtl_set_idd_mtu(VOID *mtl_1, USHORT mtu) { MTL *mtl = (MTL*)mtl_1; D_LOG(D_ENTRY, ("mtl_set_idd_mtu: entry, mtu: 0x%x\n", mtu)); /* get lock, set, release & return */ NdisAcquireSpinLock(&mtl->lock); mtl->idd_mtu = mtu; NdisReleaseSpinLock(&mtl->lock); return(MTL_E_SUCC); }
// Unlock void NeoUnlock(NEO_LOCK *lock) { NDIS_SPIN_LOCK *spin_lock; // Validate arguments if (lock == NULL) { return; } spin_lock = &lock->spin_lock; NdisReleaseSpinLock(spin_lock); }
VOID QueueDescriptorForRxIndication( MTL *mtl, MTL_AS *as ) { NdisAcquireSpinLock(&mtl->RxIndicationFifo.lock); InsertTailList(&mtl->RxIndicationFifo.head, &as->link); NdisReleaseSpinLock(&mtl->RxIndicationFifo.lock); }
/* ======================================================================== Routine Description: Arguments: Return Value: Note: NULL frame use BulkOutPipeId = 0 ======================================================================== */ VOID RTUSBBulkOutNullFrame( IN PRTMP_ADAPTER pAd) { PTX_CONTEXT pNullContext = &(pAd->NullContext); PURB pUrb; int ret = 0; unsigned long IrqFlags; NdisAcquireSpinLock(&pAd->BulkOutLock[0], IrqFlags); if (pAd->BulkOutPending[0] == TRUE) { NdisReleaseSpinLock(&pAd->BulkOutLock[0], IrqFlags); return; } pAd->BulkOutPending[0] = TRUE; NdisReleaseSpinLock(&pAd->BulkOutLock[0], IrqFlags); // Increase Total transmit byte counter pAd->RalinkCounters.TransmittedByteCount += pNullContext->BulkOutSize; DBGPRINT_RAW(RT_DEBUG_INFO, "--->RTUSBBulkOutNullFrame \n"); // Clear Null frame bulk flag RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_DATA_NULL); // Init Tx context descriptor RTUSBInitTxDesc(pAd, pNullContext, 0, RTUSBBulkOutNullFrameComplete); pNullContext->IRPPending = TRUE; pUrb = pNullContext->pUrb; if((ret = rtusb_submit_urb(pUrb))!=0) { DBGPRINT(RT_DEBUG_ERROR,"Submit Tx URB failed %d\n", ret); return; } DBGPRINT_RAW(RT_DEBUG_INFO, "<---RTUSBBulkOutNullFrame \n"); return; }
/* ======================================================================== Routine Description: Close kernel threads. Arguments: *pAd the raxx interface data pointer Return Value: NONE Note: ======================================================================== */ VOID RtmpMgmtTaskExit( IN RTMP_ADAPTER *pAd) { INT ret; RTMP_OS_TASK *pTask; /* Sleep 50 milliseconds so pending io might finish normally */ RtmpusecDelay(50000); /* We want to wait until all pending receives and sends to the */ /* device object. We cancel any */ /* irps. Wait until sends and receives have stopped. */ RTUSBCancelPendingIRPs(pAd); /* We need clear timerQ related structure before exits of the timer thread. */ RtmpTimerQExit(pAd); /* Terminate cmdQ thread */ pTask = &pAd->cmdQTask; RTMP_OS_TASK_LEGALITY(pTask) { NdisAcquireSpinLock(&pAd->CmdQLock); pAd->CmdQ.CmdQState = RTMP_TASK_STAT_STOPED; NdisReleaseSpinLock(&pAd->CmdQLock); /*RTUSBCMDUp(&pAd->cmdQTask); */ ret = RtmpOSTaskKill(pTask); if (ret == NDIS_STATUS_FAILURE) { /* DBGPRINT(RT_DEBUG_ERROR, ("%s: kill task(%s) failed!\n", */ /* RTMP_OS_NETDEV_GET_DEVNAME(pAd->net_dev), pTask->taskName)); */ DBGPRINT(RT_DEBUG_ERROR, ("kill command task failed!\n")); } pAd->CmdQ.CmdQState = RTMP_TASK_STAT_UNKNOWN; } /* Terminate timer thread */ pTask = &pAd->timerTask; ret = RtmpOSTaskKill(pTask); if (ret == NDIS_STATUS_FAILURE) { /* DBGPRINT(RT_DEBUG_ERROR, ("%s: kill task(%s) failed!\n", */ /* RTMP_OS_NETDEV_GET_DEVNAME(pAd->net_dev), pTask->taskName)); */ DBGPRINT(RT_DEBUG_ERROR, ("kill timer task failed!\n")); } #ifdef WSC_INCLUDED WscThreadExit(pAd); #endif /* WSC_INCLUDED */ }
/************************************************************ Function that allows to perform a query on a network driver or to set the parameters of an adapter. ************************************************************/ DWORD PacketRequest( POPEN_INSTANCE Open, DWORD FunctionCode, DWORD dwDDB, DWORD hDevice, PDIOCPARAMETERS pDiocParms ) { PLIST_ENTRY RequestListEntry; PINTERNAL_REQUEST pRequest; PPACKET_RESERVED pReserved; PPACKET_OID_DATA OidData; NDIS_STATUS Status; TRACE_ENTER( "Request Packet" ); /*extract a request from the list*/ NdisAcquireSpinLock( &Open->RequestSpinLock ); RequestListEntry = PacketRemoveHeadList(&Open->RequestList); NdisReleaseSpinLock( &Open->RequestSpinLock ); if ( RequestListEntry == NULL ) { IF_TRACE( "Request List Error" ); *(DWORD *)(pDiocParms->lpcbBytesReturned) = 0; TRACE_LEAVE( "Request Packet" ); return NDIS_STATUS_FAILURE/*NDIS_STATUS_SUCCESS*/; } pReserved = CONTAINING_RECORD( RequestListEntry, PACKET_RESERVED, ListElement ); pRequest = CONTAINING_RECORD( pReserved, INTERNAL_REQUEST, Reserved ); OidData = (PPACKET_OID_DATA)(pDiocParms->lpvInBuffer); if ( ( pDiocParms->cbInBuffer == pDiocParms->cbOutBuffer ) && ( pDiocParms->cbInBuffer >= sizeof(PACKET_OID_DATA) - 1 + OidData->Length) ) { pReserved->lpBuffer = (PVOID)PacketPageLock( pDiocParms->lpvInBuffer, pDiocParms->cbInBuffer ); pReserved->lpcbBytesReturned= (PVOID)PacketPageLock( (PVOID)pDiocParms->lpcbBytesReturned, sizeof(DWORD) ); pReserved->lpoOverlapped = (PVOID)PacketPageLock( (PVOID)pDiocParms->lpoOverlapped, sizeof(OVERLAPPED) ); pReserved->cbBuffer = pDiocParms->cbInBuffer; if ( FunctionCode == BIOCSETOID ) { pRequest->Request.RequestType = NdisRequestSetInformation; pRequest->Request.DATA.SET_INFORMATION.Oid = OidData->Oid; pRequest->Request.DATA.SET_INFORMATION.InformationBufferLength = OidData->Length; pRequest->Request.DATA.SET_INFORMATION.InformationBuffer = OidData->Data; IF_PACKETDEBUG( PACKET_DEBUG_VERY_LOUD ) { IF_TRACE_MSG2( "Request Set: Oid=%08lx, Length=%08lx", OidData->Oid, OidData->Length ); } }
// RTS frame use BulkOutPipeId = PipeID VOID RTUSBBulkOutRTSFrameComplete(purbb_t pUrb, struct pt_regs *pt_regs) { PRTMP_ADAPTER pAd; PTX_CONTEXT pRTSContext; NTSTATUS status; unsigned long IrqFlags; pRTSContext= (PTX_CONTEXT)pUrb->context; pAd = pRTSContext->pAd; DBGPRINT_RAW(RT_DEBUG_INFO, "--->RTUSBBulkOutRTSFrameComplete\n"); // Reset RTS frame context flags pRTSContext->IRPPending = FALSE; pRTSContext->InUse = FALSE; status = pUrb->status; if (status == USB_ST_NOERROR) { // Don't worry about the queue is empty or not, this function will check itself RTMPDeQueuePacket(pAd, pRTSContext->BulkOutPipeId); } #if 1 // STATUS_OTHER else { if ((!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_RESET_IN_PROGRESS)) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_HALT_IN_PROGRESS)) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_NIC_NOT_EXIST)) && (!RTMP_TEST_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET))) { DBGPRINT_RAW(RT_DEBUG_ERROR, "Bulk Out RTS Frame Failed\n"); RTMP_SET_FLAG(pAd, fRTMP_ADAPTER_BULKOUT_RESET); RTUSBEnqueueInternalCmd(pAd, RT_OID_USB_RESET_BULK_OUT); } } #endif NdisAcquireSpinLock(&pAd->BulkOutLock[pRTSContext->BulkOutPipeId], IrqFlags); pAd->BulkOutPending[pRTSContext->BulkOutPipeId] = FALSE; NdisReleaseSpinLock(&pAd->BulkOutLock[pRTSContext->BulkOutPipeId], IrqFlags); // Always call Bulk routine, even reset bulk. // The protectioon of rest bulk should be in BulkOut routine RTUSBKickBulkOut(pAd); DBGPRINT_RAW(RT_DEBUG_INFO, "<---RTUSBBulkOutRTSFrameComplete\n"); }
VOID MiniportFreeAllPacketPools5( IN PADAPTER pAdapt ) { RECEIVED_PACKET PacketArray[MAX_RECV_PACKET_POOL_SIZE]; ULONG NumberOfPackets = 0, i; //释放所有已经接收并存储的包 NdisAcquireSpinLock(&pAdapt->Lock); if(pAdapt->ReceivedPacketCount > 0) { NumberOfPackets = pAdapt->ReceivedPacketCount; NdisMoveMemory(PacketArray, pAdapt->ReceivedPackets, NumberOfPackets * sizeof(RECEIVED_PACKET)); pAdapt->ReceivedPacketCount = 0; for(i=0;i<NumberOfPackets;i++) { if(PacketArray[i].pNdisPacket && PacketArray[i].bReturnPacket) { MiniportReturnPacket5(pAdapt, PacketArray[i].pNdisPacket); } } } NdisReleaseSpinLock(&pAdapt->Lock); if (pAdapt->RecvPacketPoolHandle != NULL) { NdisFreePacketPool(pAdapt->RecvPacketPoolHandle); pAdapt->RecvPacketPoolHandle = NULL; } if (pAdapt->SendPacketPoolHandle != NULL) { NdisFreePacketPool(pAdapt->SendPacketPoolHandle); pAdapt->SendPacketPoolHandle = NULL; } if(pAdapt->RecvBufferPool != NULL) { NdisFreeBufferPool(pAdapt->RecvBufferPool); pAdapt->RecvBufferPool = NULL; } if(pAdapt->SendBufferPool != NULL) { NdisFreeBufferPool(pAdapt->SendBufferPool); pAdapt->SendBufferPool = NULL; } }
static struct reordering_mpdu *ba_mpdu_blk_alloc(struct rt_rtmp_adapter *pAd) { struct reordering_mpdu *mpdu_blk; NdisAcquireSpinLock(&pAd->mpdu_blk_pool.lock); mpdu_blk = ba_dequeue(&pAd->mpdu_blk_pool.freelist); if (mpdu_blk) { /* blk_count++; */ /* reset mpdu_blk */ NdisZeroMemory(mpdu_blk, sizeof(struct reordering_mpdu)); } NdisReleaseSpinLock(&pAd->mpdu_blk_pool.lock); return mpdu_blk; }
INT BndStrg_InsertEntry( PBND_STRG_CLI_TABLE table, PUCHAR pAddr, PBND_STRG_CLI_ENTRY *entry_out) { INT i; UCHAR HashIdx; PBND_STRG_CLI_ENTRY entry = NULL, this_entry = NULL; INT ret_val = BND_STRG_SUCCESS; if (table->Size >= BND_STRG_MAX_TABLE_SIZE) { DBGPRINT(RT_DEBUG_WARN, ("%s(): Table is full!\n", __FUNCTION__)); return BND_STRG_TABLE_FULL; } NdisAcquireSpinLock(&table->Lock); for (i = 0; i< BND_STRG_MAX_TABLE_SIZE; i++) { entry = &table->Entry[i]; /* pick up the first available vacancy*/ if (entry->bValid == FALSE) { NdisZeroMemory(entry, sizeof(BND_STRG_CLI_ENTRY)); /* Fill Entry */ RTMP_GetCurrentSystemTick(&entry->jiffies); COPY_MAC_ADDR(entry->Addr, pAddr); entry->bValid = TRUE; break; } } if (entry) { /* add this MAC entry into HASH table */ HashIdx = MAC_ADDR_HASH_INDEX(pAddr); if (table->Hash[HashIdx] == NULL) { table->Hash[HashIdx] = entry; } else { this_entry = table->Hash[HashIdx]; while (this_entry->pNext != NULL) { this_entry = this_entry->pNext; } this_entry->pNext = entry; } *entry_out = entry; table->Size++; } NdisReleaseSpinLock(&table->Lock); return ret_val; }
/* set tx handler */ mtl_set_tx_handler(VOID *mtl_1, VOID (*handler)(), VOID *handler_arg) { MTL *mtl = (MTL*)mtl_1; D_LOG(D_ENTRY, ("mtl_set_tx_handler: entry, handler: 0x%lx, handler_arg: 0x%lx\n", \ handler, handler_arg)); /* get lock, set, release & return */ NdisAcquireSpinLock(&mtl->lock); mtl->tx_handler = handler; mtl->tx_handler_arg = handler_arg; NdisReleaseSpinLock(&mtl->lock); return(MTL_E_SUCC); }
void ParaNdis_DebugRegisterMiniport(PARANDIS_ADAPTER *pContext, BOOLEAN bRegister) { UINT i; NdisAcquireSpinLock(&CrashLock); for (i = 0; i < MAX_CONTEXTS; ++i) { UINT64 val1 = bRegister ? 0 : (UINT_PTR)pContext; UINT64 val2 = bRegister ? (UINT_PTR)pContext : 0; if (BugCheckData.StaticData.PerNicData[i].Context != val1) continue; BugCheckData.StaticData.PerNicData[i].Context = val2; break; } NdisReleaseSpinLock(&CrashLock); }
/* ======================================================================== Routine Description: Arguments: Return Value: Note: PsPoll use BulkOutPipeId = 0 ======================================================================== */ VOID RTUSBBulkOutPsPoll( IN PRTMP_ADAPTER pAd) { PTX_CONTEXT pPsPollContext = &(pAd->PsPollContext); PURB pUrb; int ret = 0; unsigned long IrqFlags; NdisAcquireSpinLock(&pAd->BulkOutLock[0], IrqFlags); if (pAd->BulkOutPending[0] == TRUE) { NdisReleaseSpinLock(&pAd->BulkOutLock[0], IrqFlags); return; } pAd->BulkOutPending[0] = TRUE; NdisReleaseSpinLock(&pAd->BulkOutLock[0], IrqFlags); DBGPRINT_RAW(RT_DEBUG_INFO, "--->RTUSBBulkOutPsPoll \n"); // Clear PS-Poll bulk flag RTUSB_CLEAR_BULK_FLAG(pAd, fRTUSB_BULK_OUT_PSPOLL); // Init Tx context descriptor RTUSBInitTxDesc(pAd, pPsPollContext, 0, RTUSBBulkOutPsPollComplete); pPsPollContext->IRPPending = TRUE; pUrb = pPsPollContext->pUrb; if((ret = rtusb_submit_urb(pUrb))!=0) { DBGPRINT(RT_DEBUG_ERROR,"Submit Tx URB failed %d\n", ret); return; } DBGPRINT_RAW(RT_DEBUG_INFO, "<---RTUSBBulkOutPsPoll \n"); return; }
// 过滤向外发送的数据,从MPSendPackets或者MPSend函数调用 // 如果从MPSendPackets调用就运行在IRQL <= DISPATCH_LEVEL级别 // 如果从MPSend调用,就运行在IRQL == DISPATCH_LEVEL级别 BOOLEAN FltFilterSendPacket( IN PADAPT pAdapt, IN PNDIS_PACKET pSendPacket, IN BOOLEAN bDispatchLevel // TRUE -> IRQL == DISPATCH_LEVEL ) { BOOLEAN bPass = TRUE; PADAPT_FILTER_RSVD pFilterContext = (PADAPT_FILTER_RSVD)&pAdapt->FilterReserved; UCHAR buffer[MAX_PACKET_HEADER_LEN]; ULONG nReadBytes; // 当使用过滤数据时,要获取旋转锁 if(bDispatchLevel) { NdisDprAcquireSpinLock(&pAdapt->Lock); } else { NdisAcquireSpinLock(&pAdapt->Lock); } // 设置统计数字 pFilterContext->Statistics.nMPSendPktsCt ++; // 如果没有设置过滤规则,则放行所有封包 if(pFilterContext->pFilterList == NULL) goto ExitTheFilter; //////////////////////////////////////////////////// // 读取封包中的数据,这里仅读取封包头即可 FltReadPacketData(pSendPacket, buffer, MAX_PACKET_HEADER_LEN, &nReadBytes); // 检查过滤规则,看看是否允许这个封包通过 bPass = FltCheckFilterRules(pFilterContext->pFilterList, buffer, nReadBytes, TRUE); if(!bPass) { // 拒绝了一个封包 pFilterContext->Statistics.nMPSendPktsDropped ++; } ExitTheFilter: // 过滤之后要释放旋转锁 if(bDispatchLevel) NdisDprReleaseSpinLock(&pAdapt->Lock); else NdisReleaseSpinLock(&pAdapt->Lock); return bPass; }
__declspec(dllexport) BOOL WINAPI QSI_Close(DWORD open_context) { SshInterceptorIoDevice io_dev = (SshInterceptorIoDevice)open_context; /* Validate the context. */ if (io_dev != the_interceptor->ipm_device) return FALSE; /* Decrement the reference count as appropriate. */ if (InterlockedDecrement(&io_dev->stream_interface_refcount) == 0) { /* Indicate that the device is now closed. */ NdisAcquireSpinLock(&io_dev->output_queue_lock); io_dev->open = 0; io_dev->cancel_io = 0; NdisReleaseSpinLock(&io_dev->output_queue_lock); /* Uninitialize the packetizer object */ ssh_interceptor_pktizer_uninit(&io_dev->pktizer); /* Indicate the close status. */ if (io_dev->status_cb) io_dev->status_cb(FALSE, io_dev->cb_context); /* Free any buffers in the output queue. */ while (!IsListEmpty(&io_dev->output_queue)) { SshDeviceBuffer buf; PLIST_ENTRY entry; entry = RemoveHeadList(&io_dev->output_queue); buf = CONTAINING_RECORD(entry, SshDeviceBufferStruct, link); ssh_iodevice_buffer_free(io_dev, buf); }; if (io_dev->current_read_buf) { ssh_iodevice_buffer_free(io_dev, io_dev->current_read_buf); io_dev->current_read_buf = NULL; } } else { SSH_NOTREACHED; } return TRUE; }
void _rtw_spinunlock(_lock *plock) { #ifdef PLATFORM_LINUX spin_unlock(plock); #endif #ifdef PLATFORM_WINDOWS NdisReleaseSpinLock(plock); #endif }
BOOLEAN IsRxIndicationFifoEmpty( MTL *mtl) { BOOLEAN Ret = 0; NdisAcquireSpinLock(&mtl->RxIndicationFifo.lock); Ret = IsListEmpty(&mtl->RxIndicationFifo.head); NdisReleaseSpinLock(&mtl->RxIndicationFifo.lock); return(Ret); }
/* get connection speed, add channels from chan_tbl */ mtl_get_conn_speed(VOID *mtl_1, ULONG *speed) { MTL *mtl = (MTL*)mtl_1; USHORT n; D_LOG(D_ENTRY, ("mtl_get_conn_speed: entry, mtk: 0x%lx, @speed: 0x%lx\n", mtl, speed)); /* get lock, count, release */ NdisAcquireSpinLock(&mtl->chan_tbl.lock); for ( n = 0, *speed = 0 ; n < mtl->chan_tbl.num ; n++ ) *speed += mtl->chan_tbl.tbl[n].speed; NdisReleaseSpinLock(&mtl->chan_tbl.lock); D_LOG(D_EXIT, ("mtl_get_conn_speed: exit, speed: %ld bps\n", *speed)); return(MTL_E_SUCC); }
MTL_AS* GetAssemblyFromRxIndicationFifo( MTL *mtl ) { MTL_AS *as = NULL; NdisAcquireSpinLock(&mtl->RxIndicationFifo.lock); if (!IsListEmpty(&mtl->RxIndicationFifo.head)) as = (MTL_AS*)RemoveHeadList(&mtl->RxIndicationFifo.head); NdisReleaseSpinLock(&mtl->RxIndicationFifo.lock); return(as); }