static NDIS_STATUS
VenetSetupAdapter(PADAPTER a)
{

    NDIS_STATUS			rc;
    NDIS_TIMER_CHARACTERISTICS	timer;

    a->lookAhead = NIC_MAX_LOOKAHEAD;
    a->numTcbs = NIC_MAX_BUSY_SENDS;
    a->refCount = 1;
    VENET_SET_FLAG(a, VNET_DISCONNECTED);

    QueueInit(&a->sendQueue);

    NdisInitializeListHead(&a->recvFreeList);
    NdisInitializeListHead(&a->recvToProcess);
    NdisInitializeListHead(&a->tcbFree);
    NdisInitializeListHead(&a->tcbBusy);

    NdisAllocateSpinLock(&a->lock);
    NdisAllocateSpinLock(&a->recvLock);
    NdisAllocateSpinLock(&a->sendLock);

    NdisInitializeEvent(&a->removeEvent);
    NdisInitializeEvent(&a->sendEvent);


    /* We use the opposite sense of the sendEvent,
     * SET == No Tx in use
     * UNSET == Tx in use
     */
    NdisInitializeEvent(&a->sendEvent);
    NdisSetEvent(&a->sendEvent);

    /* Create Rest and receive timers. */
    NdisZeroMemory(&timer, sizeof(NDIS_TIMER_CHARACTERISTICS));
    timer.Header.Type = NDIS_OBJECT_TYPE_TIMER_CHARACTERISTICS;
    timer.Header.Revision = NDIS_TIMER_CHARACTERISTICS_REVISION_1;
    timer.Header.Size = sizeof(NDIS_TIMER_CHARACTERISTICS);
    timer.AllocationTag = VNET;
    timer.TimerFunction = VenetResetTimerDpc;
    timer.FunctionContext = a;

    rc = NdisAllocateTimerObject(a->adapterHandle, &timer, &a->resetTimer);
    if (rc != NDIS_STATUS_SUCCESS)
        goto done;

    timer.TimerFunction = VenetReceiveTimerDpc;
    rc = NdisAllocateTimerObject(a->adapterHandle, &timer, &a->recvTimer);
    if (rc != NDIS_STATUS_SUCCESS)
        goto done;

done:
    return rc;
}
//------------------------------------------------------------------------------
tOplkError hrestimer_init(void)
{
    NDIS_TIMER_CHARACTERISTICS    timerChars;
    NDIS_STATUS                   status = NDIS_STATUS_SUCCESS;
    NDIS_HANDLE                   adapterHandle = ndis_getAdapterHandle();
    UINT                          index;

    OPLK_MEMSET(&hresTimerInstance_l, 0, sizeof(hresTimerInstance_l));

    for (index = 0; index < TIMER_COUNT; index++)
    {
        NdisZeroMemory(&timerChars, sizeof(timerChars));

        {C_ASSERT(NDIS_SIZEOF_TIMER_CHARACTERISTICS_REVISION_1 <= sizeof(timerChars)); }
        timerChars.Header.Type = NDIS_OBJECT_TYPE_TIMER_CHARACTERISTICS;
        timerChars.Header.Size = NDIS_SIZEOF_TIMER_CHARACTERISTICS_REVISION_1;
        timerChars.Header.Revision = NDIS_TIMER_CHARACTERISTICS_REVISION_1;

        timerChars.TimerFunction = timerDpc;
        timerChars.FunctionContext = &hresTimerInstance_l.aTimerInfo[index];
        timerChars.AllocationTag = TIMER_MEM_TAG;

        status = NdisAllocateTimerObject(adapterHandle,
                                         &timerChars,
                                         &hresTimerInstance_l.aTimerInfo[index].timerObjHandle);
        if (status != NDIS_STATUS_SUCCESS)
        {
            DEBUG_LVL_ERROR_TRACE("%s() Timer Creation Failed %x\n", __func__, status);
            return kErrorNoResource;
        }
    }

    ExSetTimerResolution(10000, TRUE);

    hresTimerInstance_l.fInitialized = TRUE;

    return kErrorOk;
}
//------------------------------------------------------------------------------
NTSTATUS powerlinkCreate(PDEVICE_OBJECT pDeviceObject_p,
                         PIRP pIrp_p)
{
    NDIS_TIMER_CHARACTERISTICS  timerChars;
    tFileContext*               pFileContext;
    PIO_STACK_LOCATION          irpStack;
    NDIS_STATUS                 status;

    UNUSED_PARAMETER(pDeviceObject_p);

    DEBUG_LVL_ALWAYS_TRACE("PLK: + %s() ...\n", __func__);

    if (pIrp_p == NULL)
        return NDIS_STATUS_RESOURCES;

    irpStack = IoGetCurrentIrpStackLocation(pIrp_p);

    pFileContext = ExAllocatePoolWithQuotaTag(NonPagedPool,
                                              sizeof(tFileContext),
                                              PLK_MEM_TAG);
    if (pFileContext == NULL)
    {
        DEBUG_LVL_ERROR_TRACE("PLK: Failed to create file context\n");
    }

    IoInitializeRemoveLock(&pFileContext->driverAccessLock, PLK_MEM_TAG, 0, 0);

    irpStack->FileObject->FsContext = (void*)pFileContext;

    if (!plkDriverInstance_l.fInitialized)
    {
        NdisZeroMemory(&timerChars, sizeof(timerChars));

        C_ASSERT(NDIS_SIZEOF_TIMER_CHARACTERISTICS_REVISION_1 <= sizeof(timerChars));
        timerChars.Header.Type = NDIS_OBJECT_TYPE_TIMER_CHARACTERISTICS;
        timerChars.Header.Size = NDIS_SIZEOF_TIMER_CHARACTERISTICS_REVISION_1;
        timerChars.Header.Revision = NDIS_TIMER_CHARACTERISTICS_REVISION_1;

        timerChars.TimerFunction = increaseHeartbeatCb;
        timerChars.FunctionContext = NULL;
        timerChars.AllocationTag = PLK_MEM_TAG;

        status = NdisAllocateTimerObject(plkDriverInstance_l.driverHandle,
                                         &timerChars,
                                         &heartbeatTimer_l);
        if (status != NDIS_STATUS_SUCCESS)
        {
            DEBUG_LVL_ERROR_TRACE("%s() Timer Creation Failed %x\n", __func__, status);
            return STATUS_SUCCESS;
        }

        if (ctrlk_init(NULL) != kErrorOk)
        {
            return NDIS_STATUS_RESOURCES;
        }

        startHeartbeatTimer(20);
        plkDriverInstance_l.fInitialized = TRUE;
    }

    // Increase the count for open instances
    plkDriverInstance_l.instanceCount++;

    pIrp_p->IoStatus.Information = 0;
    pIrp_p->IoStatus.Status = STATUS_SUCCESS;
    IoCompleteRequest(pIrp_p, IO_NO_INCREMENT);

    DEBUG_LVL_ALWAYS_TRACE("PLK: + %s() - OK\n", __func__);

    return STATUS_SUCCESS;
}
Exemple #4
0
NDIS_STATUS
Hw11Allocate(
    __in  NDIS_HANDLE             MiniportAdapterHandle,
    __deref_out_opt PHW*          Hw,
    __in  PADAPTER                Adapter
    )
{
    NDIS_STATUS                 ndisStatus = NDIS_STATUS_SUCCESS;
    PHW                         newHw = NULL;
    ULONG                       size;
    NDIS_TIMER_CHARACTERISTICS  timerChar;               

    *Hw = NULL;
    do
    {
        // Allocate a HW data structure
        MP_ALLOCATE_MEMORY(MiniportAdapterHandle, &newHw, sizeof(HW), HW_MEMORY_TAG);
        if (newHw == NULL)
        {
            MpTrace(COMP_INIT_PNP, DBG_SERIOUS, ("Failed to allocate %d bytes for HW\n",
                                 sizeof(HW)));
            ndisStatus = NDIS_STATUS_RESOURCES;
            break;
        }

        // Clear everything
        NdisZeroMemory(newHw, sizeof(HW));

        // We start in the PAUSED state
        HW_SET_ADAPTER_STATUS(newHw, HW_ADAPTER_PAUSED);
        newHw->InterruptDisableCount = 1;       // Since we are paused, we want the interrupts to be disabled
#if DBG
        NdisInterlockedIncrement(&newHw->Tracking_InterruptDisable[HW_ISR_TRACKING_PAUSE]);
#endif
        
        // Allocate memory for fields inside the HW structure
        size = sizeof(DOT11_REG_DOMAINS_SUPPORT_VALUE) + 
               (HW_MAX_NUM_DOT11_REG_DOMAINS_VALUE - 1) * sizeof(DOT11_REG_DOMAIN_VALUE);
        MP_ALLOCATE_MEMORY(MiniportAdapterHandle,
                           &(newHw->PhyState.RegDomainsSupportValue),
                           size,
                           HW_MEMORY_TAG);
        if (newHw->PhyState.RegDomainsSupportValue == NULL)
        {
            MpTrace(COMP_INIT_PNP,
                    DBG_SERIOUS,
                    ("Failed to allocate memory for RegDomainsSupportValue\n"));
            ndisStatus = NDIS_STATUS_RESOURCES;
            break;
        }
        NdisZeroMemory(newHw->PhyState.RegDomainsSupportValue, size);

        size = sizeof(DOT11_DIVERSITY_SELECTION_RX_LIST) +
              (HW_MAX_NUM_DIVERSITY_SELECTION_RX_LIST - 1) * sizeof(DOT11_DIVERSITY_SELECTION_RX);
        MP_ALLOCATE_MEMORY(MiniportAdapterHandle,
                           &(newHw->PhyState.DiversitySelectionRxList),
                           size, 
                           HW_MEMORY_TAG);
        if (newHw->PhyState.DiversitySelectionRxList == NULL) 
        {
            MpTrace(COMP_INIT_PNP,
                    DBG_SERIOUS,
                    ("Failed to allocate memory for DiversitySelectionRxList\n"));
            ndisStatus = NDIS_STATUS_RESOURCES;
            break;
        }
        NdisZeroMemory(newHw->PhyState.DiversitySelectionRxList, size);        

        NdisZeroMemory(&timerChar, sizeof(NDIS_TIMER_CHARACTERISTICS));
        
        // Allocate the power save wake timer
        timerChar.Header.Type = NDIS_OBJECT_TYPE_TIMER_CHARACTERISTICS;
        timerChar.Header.Revision = NDIS_TIMER_CHARACTERISTICS_REVISION_1;
        timerChar.Header.Size = sizeof(NDIS_TIMER_CHARACTERISTICS);
        timerChar.AllocationTag = HW_MEMORY_TAG;
        
        timerChar.TimerFunction = HwAwakeTimer;
        timerChar.FunctionContext = newHw;

        ndisStatus = NdisAllocateTimerObject(
                        MiniportAdapterHandle,
                        &timerChar,
                        &newHw->PhyState.Timer_Awake
                        );
        if (ndisStatus != NDIS_STATUS_SUCCESS)
        {
            MpTrace(COMP_INIT_PNP, DBG_SERIOUS, ("Failed to allocate power save awake timer\n"));
            break;
        }

        // Allocate the power save sleep timer
        timerChar.TimerFunction = HwDozeTimer;
        timerChar.FunctionContext = newHw;

        ndisStatus = NdisAllocateTimerObject(
                        MiniportAdapterHandle,
                        &timerChar,
                        &newHw->PhyState.Timer_Doze
                        );
        if (ndisStatus != NDIS_STATUS_SUCCESS)
        {
            MpTrace(COMP_INIT_PNP, DBG_SERIOUS, ("Failed to allocate power save doze timer\n"));
            break;
        }
        
        // Allocate the scan timer
        timerChar.TimerFunction = HwScanTimer;
        timerChar.FunctionContext = newHw;

        ndisStatus = NdisAllocateTimerObject(
                        MiniportAdapterHandle,
                        &timerChar,
                        &newHw->ScanContext.Timer_Scan
                        );
        if (ndisStatus != NDIS_STATUS_SUCCESS)
        {
            MpTrace(COMP_INIT_PNP, DBG_SERIOUS, ("Failed to allocate scan timer\n"));
            break;
        }

        newHw->PhyState.PhyProgramWorkItem = NdisAllocateIoWorkItem(MiniportAdapterHandle);
        if(newHw->PhyState.PhyProgramWorkItem == NULL)
        {
            MpTrace(COMP_INIT_PNP, DBG_SERIOUS, ("Failed to allocate channel switch work item\n"));
            ndisStatus = NDIS_STATUS_RESOURCES;
            break;
        }

        // The hardware lock
        NdisAllocateSpinLock(&newHw->Lock);

        // Save the Adapter pointer in the HW
        newHw->Adapter = Adapter;
        newHw->MiniportAdapterHandle = MiniportAdapterHandle;

        // Return the newly created structure to the caller
        *Hw = newHw;

    } while (FALSE);

    if (ndisStatus != NDIS_STATUS_SUCCESS)
    {
        if (newHw != NULL)
        {
            Hw11Free(newHw);
        }
    }

    return ndisStatus;
}
Exemple #5
0
NDIS_STATUS
HelperPortInitializeScanContext(
    _In_  PMP_HELPER_PORT         HelperPort
    )
{
    NDIS_STATUS                 ndisStatus = NDIS_STATUS_SUCCESS;
    NDIS_TIMER_CHARACTERISTICS  timerChar;               
    ULONG                       i;
    do
    {
        HelperPort->ScanContext.ActiveScanParameters = NULL;

        // Allocate the power save timeout call back
        NdisZeroMemory(&timerChar, sizeof(NDIS_TIMER_CHARACTERISTICS));
        
        timerChar.Header.Type = NDIS_OBJECT_TYPE_TIMER_CHARACTERISTICS;
        timerChar.Header.Revision = NDIS_TIMER_CHARACTERISTICS_REVISION_1;
        timerChar.Header.Size = sizeof(NDIS_TIMER_CHARACTERISTICS);
        timerChar.AllocationTag = PORT_MEMORY_TAG;
        
        timerChar.TimerFunction = HelperPortScanTimer;
        timerChar.FunctionContext = HelperPort;

        ndisStatus = NdisAllocateTimerObject(
                        HELPPORT_GET_MP_PORT(HelperPort)->MiniportAdapterHandle,
                        &timerChar,
                        &HelperPort->ScanContext.Timer_Scan
                        );
        if (ndisStatus != NDIS_STATUS_SUCCESS)
        {
            MpTrace(COMP_INIT_PNP, DBG_SERIOUS, ("Failed to allocate helper port scan timer\n"));
            break;
        }

        //
        // Get list of channels we would scan
        //
        ndisStatus = HelperPortCreateScanChannelList(HelperPort);
        if (ndisStatus != NDIS_STATUS_SUCCESS)
        {
            MpTrace(COMP_INIT_PNP, DBG_SERIOUS, ("Failed to create helper port scan list\n"));
            break;
        }        

        // Initialize the preallocated scan parameter structures
        for (i = 0; i < MP_MAX_NUMBER_OF_PORT; i++)
        {
            NdisZeroMemory(&HelperPort->ScanContext.ScanParameters[i], sizeof(MP_SCAN_PARAMETERS));
            
            HelperPort->ScanContext.ScanParameters[i].State = SCAN_EMPTY_REQUEST;
            HelperPort->ScanContext.ScanParameters[i].UsageCount = 0;
        }

        // To maintain the scan list, we need to receive all beacons and probe responses. Set the
        // appropriate packet filter
        VNic11SetPacketFilter(HELPPORT_GET_VNIC(HelperPort), 
            NDIS_PACKET_TYPE_802_11_BROADCAST_MGMT | NDIS_PACKET_TYPE_802_11_DIRECTED_MGMT
            );
        
    }while (FALSE);

    if (ndisStatus != NDIS_STATUS_SUCCESS)
    {
        if (HelperPort->ScanContext.Timer_Scan)
        {
            NdisFreeTimerObject(HelperPort->ScanContext.Timer_Scan);
            HelperPort->ScanContext.Timer_Scan = NULL;
        }
    
        for (i = 0; i < HW11_MAX_PHY_COUNT; i++)
        {
            if (HelperPort->ScanContext.ScanChannels[i].ChannelList != NULL)
            {
                MP_FREE_MEMORY(HelperPort->ScanContext.ScanChannels[i].ChannelList);
                HelperPort->ScanContext.ScanChannels[i].ChannelList = NULL;
            }
        }

    }
    
    return ndisStatus;
}