intprismend.c

来自「vworks 下wlan的实现代码」· C语言 代码 · 共 1,670 行 · 第 1/5 页

C
1,670 行
字号
        case EIOCPOLLSTART:	/* Begin polled operation */            intPrismPollStart ((END_OBJ*)pDrvCtrl);            break;        case EIOCPOLLSTOP:	/* End polled operation */            intPrismPollStop ((END_OBJ*)pDrvCtrl);            break;        case EIOCGMIB2:		/* return MIB information */            if (data == NULL)                {                status = ERROR;                break;                }            bcopy((char *)(&pDrvCtrl->mib2Tbl),                  (char *)data,                  sizeof(pDrvCtrl->mib2Tbl));            break;        case EIOCGFBUF:            /* return minimum First Buffer for chaining */            if (data == NULL)                {                status = ERROR;                break;                }            *(int *)data = WLAN_MIN_FBUF;            break;        case EIOCGHDRLEN:            if (data == NULL)                {                status = ERROR;                break;                }            *(int *)data = WLAN_EH_SIZE;            break;        default:            /* OK.  We have a non-standard IOCTL call - pass it to the            WLAN IOCTL manager.  It will return EINVAL if it doesn't            recognize the command either. */            if (((WLAN_DEV *)pDrvCtrl)->pIoctl != NULL)                {                status = (((WLAN_DEV *)pDrvCtrl)->pIoctl)                    ((WLAN_DEV *)pDrvCtrl, cmd, data);                }        }    return status;    }/***************************************************************************** intPrismUnload - Unloads this instance of the WLAN driver** De-allocates all memory allocated in intPrismLoad, and returns the system to * the pre-initialized state. It is assumed that any device power-down/disabling* is done in a high-level PCI or PCMCIA driver.** RETURNS: OK or ERROR** ERRNO: N/A*/STATUS intPrismUnload     (    END_OBJ* pDrvCtrl            /* Pointer to device handle */    )    {    WLAN_DEV* pWlanDev = (WLAN_DEV *)pDrvCtrl;    WLAN_DEV* pBug;    WLAN_DEBUG(DEBUG_INFO, ("Unloading WLAN Driver\n"));    END_OBJECT_UNLOAD (pDrvCtrl);    cacheDmaFree( pWlanDev->clDescTbl.memArea);    free (pWlanDev->mClBlkConfig.memArea);    /* Free the entry in the LL corresponding to this instance of the    driver */    for (pBug = pWlanHead; pBug->pNext != pWlanDev; pBug = pBug->pNext);    pBug->pNext = pWlanDev->pNext;    return OK;    }/****************************************************************************** NOMANUAL* intPrismInt - ISR for WLAN driver** This is the ISR for the WLAN driver.  Events on the card are shown in the * event status register. These events do not trigger a card interrupt* unless they have been enabled as an interrupt source.  Currently the only* events that are interrupt sources are: RX, INFO, ALLOC, CMD. CMD events are * used to release a semaphore for the intPrismCommandAsync() routeing, or are * polled for in the intPrismCommand() routine under an intLock (card commands * should work when interrupts are disabled or not yet enabled) .  ALLOC events* are generated when a transmit buffer is reclaimed by the card, and the* corresponding semaphore is freed.* * RETURNS: OK or ERROR** ERRNO: N/A*/STATUS intPrismInt    (    WLAN_DEV* pWlanDev           /* Pointer to device handle */    )    {    LOCAL UINT16 status;         /* Stores status register on card */    LOCAL UINT16 rxFID;          /* Store FID of incoming frame on RX event */    LOCAL UINT16 infoFID;        /* Store FID of imcoming INFO frame */    volatile LOCAL WLAN_FRAME frame; /* Frame structure to get rx frames */    LOCAL LTV_RECORD ltv;        /* Sample LTV record, necessary to get some                                     INFO frames */    LOCAL UINT16 lastSeq = 0;    /* Stored sequence number */    int datalen;    int i;    int fid;    UINT16 reg;    RX_PACKET * pRxPacket;    if (pWlanDev == NULL)        {        WLAN_LOG(DEBUG_ERROR, ("intPrismInt: Fatal error - NULL pWlanDev\n",                               0,0,0,0,0,0));        return OK;        }    if (WLAN_IN_16(WLAN_BASE_ADDR + WLAN_SW0) != WLAN_SW_MAGIC)        {        WLAN_LOG(DEBUG_ERROR, ("intPrismInt: card not found!\n",0,0,0,0,0,0));        return ERROR;        }    if (WLAN_IN_16(WLAN_BASE_ADDR + WLAN_INT_EN) == 0)        {        WLAN_LOG(DEBUG_INFO, ("intPrismInt: Interrupts are disabled!\n",                              0,0,0,0,0,0));        return ERROR;        }    do         {         /* Read the EVENT STATUS */        status = WLAN_IN_16(WLAN_BASE_ADDR + WLAN_EVENT_STAT);        if ((status & WLAN_EV_CMD) != 0)            {            semGive(pWlanDev->commandComplete);            }        /* Allocation Event */        if ((status & WLAN_EV_ALLOC) != 0)            {            fid = WLAN_IN_16(WLAN_BASE_ADDR + WLAN_ALLOC_FID);             /* Search for this FID, and free the corresponding semaphore */            for (i = 0; i< WLAN_MAX_TX_BUF; i++)                {                if (pWlanDev->txPool[i].fid == fid)                    {                    if (semGive(pWlanDev->txPool[i].empty) != OK)                        {                        WLAN_LOG(DEBUG_FATAL, ("ALLOC: Error giving sem\n",                                               0,0,0,0,0,0));                        }                    fid = -1;  /* Mark FID as found */                    if (pWlanDev->txBlocked == TRUE)                        {                        pWlanDev->txBlocked = FALSE;                        netJobAdd((FUNCPTR)muxTxRestart,(int)pWlanDev,0,0,0,0);                        }                    WLAN_LOG(DEBUG_FLOOD, ("ALLOC: Found\n",0,0,0,0,0,0));                    break;                     }                }            /* Spit out an error message if the allocated FID is not in the            pool of allocated TX FIDs */            if (fid != -1)                {                WLAN_LOG(DEBUG_FATAL, ("ALLOC: Reclaimed TX FID unknown!!!",                                       0,0,0,0,0,0));                }            }        /* RECEIVE EVENT */        if ((status & WLAN_EV_RX) != 0)             {            rxFID = WLAN_IN_16(WLAN_BASE_ADDR + WLAN_RX_FID);            /* Set up BAP 0 to read the data from.  Note : It is assumed that            other interrupts using this BAP will not pre-empt this one, thus            there is no protection for the BAP */            WLAN_OUT_16(WLAN_BASE_ADDR + WLAN_SEL0, rxFID);            WLAN_OUT_16(WLAN_BASE_ADDR + WLAN_OFF0, 0);            i = 0;            do                 {                if (i++ > WLAN_DEVICE_TIMEOUT)                    {                    WLAN_LOG(DEBUG_ERROR, ("intPrismInt: Timeout on BAP 0\n",                                           0,0,0,0,0,0));                    goto rxDone;                    }                reg = WLAN_IN_16(WLAN_BASE_ADDR + WLAN_OFF0);                }            while ((reg & WLAN_OFF_BUSY) != 0);            if ((reg & WLAN_OFF_ERR) != 0)                {                WLAN_LOG(DEBUG_ERROR, ("intPrismInt: Offset error on BAP 0\n",                                       0,0,0,0,0,0));                goto rxDone;                }            /* Read the first part of the header, to get the frame control            fields, determine if it's worth reading the rest of the packet */            for (i=0; i< (WLAN_802_11_OFFSET - 2)/2; i++)                {                *(( (UINT16*)&frame)+i)=WLAN_IN_16(WLAN_BASE_ADDR +WLAN_DATA0);                }            /* Copy the the thertype in unreversed */            *(( (UINT16*)&frame)+i) = WLAN_IN_16_ENDIAN(WLAN_BASE_ADDR +                                                         WLAN_DATA0);            datalen = frame.dat_len;                      /* 802.1x extensions - In 802.1x Mode packets will be receive that            are both encrytped and clear-text.  We need to filter out non            encrypted packets that are not the 802.1x protocol type */            if (pWlanDev->oneXMode == ONEX_MODE_ENABLED)                {                if ((frame.frame_ctl & INTPR_FCTL_WEP) == 0)                     {                    if (frame.type != htons(ONEX_PROTOCOL))                        {                        WLAN_LOG(DEBUG_INFO, ("intPrismInt - 802.1x : "                                              "dropping non-encrypted packet"                                              " of type %04x\n", frame.type,                                              0,0,0,0,0));                        goto rxDone;                        }                                 else                        {                        WLAN_LOG(DEBUG_INFO, ("intPrismInt - 802.1x packet"                                              " accepted\n",0,0,0,0,0,0));                        }                    }                }            /* Check for duplicate packets to remove bug that occurs when MAC            acknowledgements get lost.  If we've successfully received this             packet before and passed it up the stack, then drop this copy */            if ((frame.seq_ctl>>4) == lastSeq)                {                WLAN_LOG(DEBUG_INFO, ("Bad duplicate found!!!\n",0,0,0,0,0,0));                }            else                {                /* If there was an error decoding the frame, don't worry about                   it, just scrap the frame */                if ((frame.status & WLAN_STAT_ERRSTAT) != 0)                    {                                WLAN_LOG(DEBUG_INFO, ("interrupt: Bad RX Frame!\n",                                          0,0,0,0,0,0));                    END_ERR_ADD(&pWlanDev->endObj, MIB2_IN_ERRS, +1);                    }                else if (frame.dat_len == 0)                    {                    WLAN_LOG(DEBUG_INFO, ("interrupt: Zero length RX\n",                                          0,0,0,0,0,0));                    END_ERR_ADD(&pWlanDev->endObj, MIB2_IN_ERRS, +1);                    }                else if ((pRxPacket = (RX_PACKET *) netClusterGet (                                                   pWlanDev->endObj.pNetPool,                                                   pWlanDev->pClPool))                          == NULL)                    {                    WLAN_LOG(DEBUG_INFO, ("intPrismReceive: Error getting "                                           "cluster\n", 0, 0, 0, 0, 0, 0));                    }                else /* No errors, continue */                    {                    pRxPacket->pData = (char *)pRxPacket + sizeof(RX_PACKET);                    /*Save the seq. number of this packet to check for multiple                      copies */                    lastSeq = frame.seq_ctl >> 4;                                        /* Add the ethernet header size to the total packet                        length */                    datalen += WLAN_EH_SIZE;                                        /* Reset the offset register to begin reading ethernet                        addresses */                    WLAN_OUT_16(WLAN_BASE_ADDR + WLAN_OFF0, WLAN_802_3_OFFSET);                                        i = 0;                    do                         {                        if (i++ > WLAN_DEVICE_TIMEOUT)                            {                            WLAN_LOG(DEBUG_ERROR, ("intPrismInt: Timeout on "                                                   "BAP 0\n",0,0,0,0,0,0));                            goto rxDone;                            }                        reg = WLAN_IN_16(WLAN_BASE_ADDR + WLAN_OFF0);                        }                    while ((reg & WLAN_OFF_BUSY) != 0);                    if ((reg & WLAN_OFF_ERR) != 0)                        {                        WLAN_LOG(DEBUG_ERROR, ("intPrismInt: Offset error on "                                               "BAP 0\n",  0,0,0,0,0,0));                        goto rxDone;                        }                    /* If this is a WDS packet and a WDS link driver is installed                    via intPrismWDSEnd.c, then send it to the receive function */                    if ( ((frame.frame_ctl & INTPR_FCTL_FROM_DS) != 0)  &&                          ((frame.frame_ctl & INTPR_FCTL_TO_DS) != 0) &&                         (pWlanDev->pWds != NULL) )                                                {                        /* Reset the offset register to read the entire header */                        WLAN_OUT_16(WLAN_BASE_ADDR + WLAN_OFF0, 0);                                                i = 0;                        do                             {                            if (i++ > WLAN_DEVICE_TIMEOUT)                                {

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?