⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addresstable.c

📁 Mavell AP32 无线模块驱动。VxWorks BSP BootRom源代码
💻 C
📖 第 1 页 / 共 2 页
字号:

    ethernetAddHSwapped = GT_NIBBLE(ethernetAddH&0xf)+
                          ((GT_NIBBLE((ethernetAddH>>4)&0xf))<<4)+
                          ((GT_NIBBLE((ethernetAddH>>8)&0xf))<<8)+
                          ((GT_NIBBLE((ethernetAddH>>12)&0xf))<<12);


    ethernetAddLSwapped = GT_NIBBLE(ethernetAddL&0xf)+
                          ((GT_NIBBLE((ethernetAddL>>4)&0xf))<<4)+
                          ((GT_NIBBLE((ethernetAddL>>8)&0xf))<<8)+
                          ((GT_NIBBLE((ethernetAddL>>12)&0xf))<<12)+
                          ((GT_NIBBLE((ethernetAddL>>16)&0xf))<<16)+
                          ((GT_NIBBLE((ethernetAddL>>20)&0xf))<<20)+
                          ((GT_NIBBLE((ethernetAddL>>24)&0xf))<<24)+
                          ((GT_NIBBLE((ethernetAddL>>28)&0xf))<<28);



    ethernetAddH = ethernetAddHSwapped;
    ethernetAddL = ethernetAddLSwapped;

    if(hash_mode == 0)
    {
        ethernetAdd0 = (ethernetAddL>>2) & 0x3f;
        ethernetAdd1 = (ethernetAddL & 0x3) | ((ethernetAddL>>8) & 0x7f)<<2;
        ethernetAdd2 = (ethernetAddL>>15) & 0x1ff;
        ethernetAdd3 = ((ethernetAddL>>24) & 0xff) | ((ethernetAddH & 0x1)<<8);

    }
    else
    {
        ethernetAdd0 = FLIP_6_BITS((ethernetAddL) & 0x3f);
        ethernetAdd1 = FLIP_9_BITS(((ethernetAddL>>6) & 0x1ff));
        ethernetAdd2 = FLIP_9_BITS((ethernetAddL>>15) & 0x1ff);
        ethernetAdd3 = FLIP_9_BITS((((ethernetAddL>>24) & 0xff) | 
                                    ((ethernetAddH & 0x1)<<8)));

    }

    hashResult = (ethernetAdd0<<9) | (ethernetAdd1^ethernetAdd2^ethernetAdd3);

    if(HashSize == _8K_TABLE)
    {
        hashResult = hashResult & 0xffff;

    }
    else
    {
        hashResult = hashResult & 0x7ff;
    }

    return hashResult;
}




/*****************************************************************************
* 
* ADRS_TABLE_STATUS enableFiltering
* 
* This function will set the Promiscuous mode to normal mode.
* in ordet to enable Filtering.
* Inputs
* port - ETHERNET port number.
* Outputs
* address filtering will be enabled.
* ADRS_TABLE_OK if success.
* ADRS_TABLE_ERROR if fail to make the assignment.
*/
ADRS_TABLE_STATUS enableFiltering(ETH_PORT_INFO *pEthPortCtrl, int port)
{	/*
    unsigned int portControlReg;

    etherGetDefaultPortConfReg (&portControlReg,port);

    portControlReg = portControlReg & ~(1<<PROMISCUOUS_MODE);

    etherModifyDefaultPortConfReg(&portControlReg,port);
    etherSetPortConfReg(&portControlReg,port);
	  */
	ethernetResetConfigReg(pEthPortCtrl, (1 << PROMISCUOUS_MODE));
    return ADRS_TABLE_OK;
}



/*****************************************************************************
* 
* ADRS_TABLE_STATUS disableFiltering
* 
* This function will set the Promiscuous mode to Promiscuous mode.
* in order to disable Filtering.
* Inputs
* port - ETHERNET port number.
* Outputs
* address filtering will be enabled.
* ADRS_TABLE_OK if success.
* ADRS_TABLE_ERROR if fail to make the assignment.
*/
ADRS_TABLE_STATUS disableFiltering(ETH_PORT_INFO *pEthPortCtrl, int port)
{	/*
    unsigned int portControlReg;

    etherGetDefaultPortConfReg (&portControlReg,port);

    portControlReg = portControlReg | (1<<PROMISCUOUS_MODE);

    etherModifyDefaultPortConfReg(&portControlReg,port);
    etherSetPortConfReg(&portControlReg,port);
	*/
	ethernetSetConfigReg(pEthPortCtrl, (1 << PROMISCUOUS_MODE));
    return ADRS_TABLE_OK;
}



/*****************************************************************************
* 
* ADRS_TABLE_STATUS scanAddressTable(int port)
* 
* This function will scan and print all the address table valid entries.
* Inputs
* port - ETHERNET port number.
* ADRS_TABLE_OK if success.
* ADRS_TABLE_ERROR if fail to make the assignment.
*/
ADRS_TABLE_STATUS scanAddressTable(int port)
{
    unsigned int entry=0;
    char dummyBuffer[100];

    while(findFirstAddressTableEntry(port,&entry,dummyBuffer) != 
                                                            ADRS_TABLE_ERROR);


    return ADRS_TABLE_OK;
}



/*****************************************************************************
* 
* ADRS_TABLE_STATUS findFirstAddressTableEntry(int port,unsigned int* startEntry)
* 
* This function will scan and print the first address table valid entry.
* Inputs
* port - ETHERNET port number.
* ADRS_TABLE_OK if success.
* ADRS_TABLE_ERROR if fail to make the assignment.
*/
ADRS_TABLE_STATUS findFirstAddressTableEntry(int port,unsigned int* startEntry,
                                char* resultBuffer)
{
    unsigned int currentEntry;
    unsigned int hashLengh[MAX_ETH_PORT_NUM];
    unsigned int addressLowRead;
    unsigned int addressHighRead;
    unsigned int addressLowValue;
    unsigned int addressHighValue;
    unsigned int endTable;
    int hashSize;
    unsigned int firstEntry;

    hashLengh[0] = EIGHT_K; 
    hashLengh[1] = HALF_K;

    hashSize = addressTableHashSize[port];
    endTable = (addressTableBase[port]+hashLengh[hashSize]*MAC_ENTRY_SIZE);
    firstEntry = *startEntry;

    currentEntry = addressTableBase[port]+((firstEntry)*MAC_ENTRY_SIZE);
    while(currentEntry < endTable)
    {
        addressLowRead = *(unsigned int*)(currentEntry+4);
        if(addressLowRead & VALID)
        {
            addressHighRead = *(unsigned int*)(currentEntry);
            addressLowValue = (((addressHighRead>>11)&0xf)<<0) | 
                              (((addressHighRead>>15)&0xf)<<4) |
                              (((addressHighRead>>3)&0xf)<<8) | 
                              (((addressHighRead>>7)&0xf)<<12) |
                              (((addressLowRead>>27)&0xf)<<16) | 
                              (((addressHighRead>>0)&0x7)<<21) |
                              (((addressLowRead>>31)&0x1)<<20) | 
                              (((addressLowRead>>19)&0xf)<<24) |
                              (((addressLowRead>>23)&0xf)<<28);

            addressHighValue = (((addressLowRead>>11)&0xf)<<0) |
                               (((addressLowRead>>15)&0xf)<<4) |
                               (((addressLowRead>>3)&0xf)<<8) |
                               (((addressLowRead>>7)&0xf)<<12);

            printf("valid address %04x%08x was found in entry # \
                   0x%x SKIP=%d RD=%d\n",
                   addressHighValue,addressLowValue,firstEntry,
                   (addressLowRead>>1)&0x1,(addressLowRead>>2)&0x1);

            sprintf(resultBuffer,"%x!!!%02x!!!%02x!!!%02x!!!%02x \
                    !!!%02x!!!%02x!!!%x!!!%x!!!%x",firstEntry*8,
                    (addressHighValue>>8)&0xff,
                    (addressHighValue>>0)&0xff,(addressLowValue>>24)&0xff,
                    (addressLowValue>>16)&0xff,
                    (addressLowValue>>8)&0xff,(addressLowValue>>0)&0xff,
                    ((addressLowRead>>2)&0x1),((addressLowRead>>1)&0x1)
                    ,VALID);

            firstEntry++;
            *startEntry = firstEntry;
            return ADRS_TABLE_OK;
        }
        currentEntry += MAC_ENTRY_SIZE;
        firstEntry ++;

    }


    return ADRS_TABLE_ERROR;
}

/*****************************************************************************
* 
* ADRS_TABLE_STATUS addressTableClear(int port)
* 
* This function will clear the address table  
* Inputs
* port - ETHERNET port number.
* Outputs
* address table is clear.
* ADRS_TABLE_OK if success.
* ADRS_TABLE_ERROR if fail to make the assignment.
*/
ADRS_TABLE_STATUS addressTableClear(int port)        
{
    unsigned int hashLengh[MAX_ETH_PORT_NUM];

    hashLengh[0] = EIGHT_K; 
    hashLengh[1] = HALF_K;

    memset((void*)addressTableBase[port],0,
           hashLengh[addressTableHashSize[port]]*MAC_ENTRY_SIZE);

    return ADRS_TABLE_OK;
}

⌨️ 快捷键说明

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