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

📄 mac2port.c

📁 802.1x 源码,基于linux平台开发
💻 C
字号:

/*$Id: mac2port.c,v 1.4 2007/01/19 07:08:14 leoncao Exp $*/                                                                   
/***************************************************************************** 
;                                                                              
;   (C) Unpublished Work of SUMINET(ShangHai).  All Rights Reserved.    
;                                                                              
;       THIS WORK IS AN UNPUBLISHED WORK AND CONTAINS CONFIDENTIAL,            
;       PROPRIETARY AND TRADESECRET INFORMATION OF SUMINET(ShangHai)  TECHNOLOGY CORP.     
;       ACCESS TO THIS WORK IS RESTRICTED TO (I) SUMINET(ShangHai)  EMPLOYEES WHO HAVE A   
;       NEED TO KNOW TO PERFORM TASKS WITHIN THE SCOPE OF THEIR ASSIGNMENTS    
;       AND (II) ENTITIES OTHER THAN SUMINET(ShangHai)  WHO HAVE ENTERED INTO APPROPRIATE  
;       LICENSE AGREEMENTS.  NO PART OF THIS WORK MAY BE USED, PRACTICED,      
;       PERFORMED, COPIED, DISTRIBUTED, REVISED, MODIFIED, TRANSLATED,         
;       ABBRIDGED, CONDENSED, EXPANDED, COLLECTED, COMPILED, LINKED, RECAST,   
;       TRANSFORMED OR ADAPTED WITHOUT THE PRIOR WRITTEN CONSENT OF SUMINET(ShangHai) .    
;       ANY USE OR EXPLOITATION OF THIS WORK WITHOUT AUTHORIZATION COULD       
;       SUBJECT THE PERPERTRATOR TO CRIMINAL AND CIVIL LIABILITY.              
;                                                                              
;------------------------------------------------------------------------------
;                                                                              
;    * Creator     :  leon cao
;    * created date:  2006年12月29日
;    * FileName    :  Mac2Port.c
;    * version     :  "$Name:  $"                                            
;    * ModuleName :                                                        
;    * Purpose     :                                                           
;     {1. What is covered in this file - function and scope.}                
;     {2. Related documents or hardware information}Abstract :}              
;   * NOTES: {Something must be known or noticed}                             
;     {1. How to use these functions - Give an example.}                         
;     {2. Sequence of messages if applicable.}                               
;     {3. Any design limitation}                                             
;     {4. Any performance limitation}                                            
;     {5. Is it a reusable component}                                             
;                                                                              
;    * Modification History:                                                   
;     {}                                                                          
;                                                                               
;                                                                  
;*****************************************************************************/
                                                                               
/*****************************************************************************/
/*    INCLUDE FILE DECLARATIONS                                              */
/*****************************************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <netinet/in.h>

#include "string.h"
#include "mac2port.h"
#include "rt61apd.h"
                                                                               
/*****************************************************************************/
/*    DEFINE DECLARATIONS                                                    */
/*****************************************************************************/


/*****************************************************************************/
/*    DATA TYPE DECLARATIONS                                                 */
/*****************************************************************************/
                                                                               
                                                                               
/*****************************************************************************/
/*    VARIABLE DECLARATIONS                                                  */
/*****************************************************************************/
MAC2PORT_S  g_Mac2Port[MAX_8021X_PORT_NUM];
                                                                               
                                                                               
/*****************************************************************************/
/*    STATIC FUNCTION DECLARATIONS                                           */
/*****************************************************************************/
int Mac2Port_FindMacByPort(int lport, unsigned char **ppcMac)
{
DBGPRINT(RT_DEBUG_TRACE," Mac2Port_FindPortByMac\n");
    if((lport < 0) || (lport >= 24))
    {
        return -1;
    }
    
    if(g_Mac2Port[lport].Status == 0)
    {
        return 1;
    }

    *ppcMac = g_Mac2Port[lport].Mac;
    return 0;
}

int Mac2Port_FindPortByMac(unsigned char *pcMac)
{
    int loopi;
DBGPRINT(RT_DEBUG_TRACE," Mac2Port_FindPortByMac\n");
    for(loopi = 0; loopi < MAX_8021X_PORT_NUM; loopi++)
    {
        if(g_Mac2Port[loopi].Status == 0)
        {
            continue;
        }
        
        if( 0 == memcmp(g_Mac2Port[loopi].Mac, pcMac, 6))
        {
            return loopi;
        }
    }

    return -1;
}

struct sta_info* Mac2Port_FindStaByMac(unsigned char *pcMac)
{
    int loopi;
DBGPRINT(RT_DEBUG_TRACE," Mac2Port_FindStaByMac\n");
    for(loopi = 0; loopi < MAX_8021X_PORT_NUM; loopi++)
    {
        if(g_Mac2Port[loopi].Status == 0)
        {
            continue;
        }
        
        if( 0 == memcmp(g_Mac2Port[loopi].Mac, pcMac, 6))
        {
            return g_Mac2Port[loopi].sta;
        }
    }

    return NULL;
}

int Mac2Port_AddSta(unsigned char *pcMac, struct sta_info* sta)
{
DBGPRINT(RT_DEBUG_TRACE," Mac2Port_AddSta\n");
    int lPort;
    
    lPort = Mac2Port_FindPortByMac(pcMac);

    if((lPort < 0) || (lPort >= MAX_8021X_PORT_NUM)
        || (g_Mac2Port[lPort].Status != 1))
        return -1;
    
    g_Mac2Port[lPort].sta = sta;
    
    return 0;
}

int Mac2Port_AddMac(unsigned char *pcMac, int lPort)
{
DBGPRINT(RT_DEBUG_TRACE," Mac2Port_AddMac\n");
    if((lPort < 0) || (lPort >= MAX_8021X_PORT_NUM)
        || (g_Mac2Port[lPort].Status != 0))
        return -1;
    
    memcpy(g_Mac2Port[lPort].Mac, pcMac, 6);
    g_Mac2Port[lPort].Status = 1;
    if(g_Mac2Port[lPort].sta != NULL)
    {
        memcpy(g_Mac2Port[lPort].sta->addr, pcMac, 6);
    }
    
    return 0;
}

void Mac2Port_DelMac(unsigned char *pcMac)
{
DBGPRINT(RT_DEBUG_TRACE," Mac2Port_DelMac\n");
    int lPort;

    lPort = Mac2Port_FindPortByMac(pcMac);
    if(lPort == -1)
    {
        return ;
    }
    
    g_Mac2Port[lPort].Status = 0;
    memset(g_Mac2Port[lPort].Mac, 0, 6);
    if(g_Mac2Port[lPort].sta != NULL)
    {
        memset(g_Mac2Port[lPort].sta->addr, 0, 6);
    }
}

void Mac2Port_Init()
{

    memset(g_Mac2Port, 0, sizeof(g_Mac2Port));

}

⌨️ 快捷键说明

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