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

📄 sysnet.c

📁 au1500开发的应用程序
💻 C
字号:
/* sysNet.c - system-dependent Network Library *//* Copyright 2002-2005 Founder Communications,Inc. *//*modification history--------------------01a,28feb05,fhchen  adopted from wrSbc8260Atm/sysNet.c (ver 01e)*//*DESCRIPTIONsysEnetAddrSet was called by mEnet in bootConfig.c, the unit number issupposed to be get via IO. however, passing the unit number as a parameteris also desirable, so sysEnetUnitAddrSet is written.sysMacAddrSet and sysMacAddrGet deal with run-time address, the formerwill restart corresponding network interface.*//* includes */#include "vxWorks.h"#include "vme.h"#include "memLib.h"#include "cacheLib.h"#include "sysLib.h"#include "string.h"#include "intLib.h"#include "logLib.h"#include "stdio.h"#include "taskLib.h" #include "vxLib.h"#include "tyLib.h"#include "config.h"#if defined(INCLUDE_END)# include "muxLib.h"# include "muxTkLib.h"# include "end.h"# include "types/vxTypes.h"#endif  /* INCLUDE_END *//* globals */static UINT8 glbEnetAddr[MAX_MAC_ADRS][MAC_ADRS_LEN] = {	{ SCB_ENET0, SCB_ENET1, SCB_ENET2, SCB_ENET3_0, SCB_ENET4, SCB_ENET5 }, /* FCC1 */	{ SCB_ENET0, SCB_ENET1, SCB_ENET2, SCB_ENET3_1, SCB_ENET4, SCB_ENET5 }, /* FCC3 */	{ SCB_ENET0, SCB_ENET1, SCB_ENET2, SCB_ENET3_2, SCB_ENET4, SCB_ENET5 },	{ SCB_ENET0, SCB_ENET1, SCB_ENET2, SCB_ENET3_3, SCB_ENET4, SCB_ENET5 },};/************************************************************************* sysEnetAddrSet - sets the 6 byte ethernet address** This routine sets the 6 byte ethernet address used by the ethernet * device, device number is get via IO.** RETURNS: N/A** SEE ALSO: sysEnetAddrGet()*/void sysEnetAddrSet     (    UCHAR byte5, /* MSB */    UCHAR byte4,    UCHAR byte3,    UCHAR byte2,    UCHAR byte1,    UCHAR byte0 /* LSB */    )    {    BOOL   next;    int    offset;    int    unit = 0;    /* get interface unit number */    do        {        next = FALSE;                    printf("Please enter the Unit number between 0 - 3: ");                    scanf ("%d", &unit);         /* Check if the unit number is between 0 to 3 */        if ((unit < 0) || (unit >= MAX_MAC_ADRS))            {            printf ("\n");            printf ("The unit number is not between 0 - 3, please enter it again.\n");            next = TRUE;            }        }while(next);    printf ("\n");    offset = unit * MAC_ADRS_LEN;    /* store address in table */        glbEnetAddr[unit][0] = byte5;    glbEnetAddr[unit][1] = byte4;    glbEnetAddr[unit][2] = byte3;    glbEnetAddr[unit][3] = byte2;    glbEnetAddr[unit][4] = byte1;    glbEnetAddr[unit][5] = byte0;#if (NV_RAM_SIZE != NONE)        /* if NVRAM present, save MAC address in NvRAM. */        sysNvRamSet((char *)&glbEnetAddr[unit], MAC_ADRS_LEN, NV_MAC_ADRS_OFFSET + offset);#endif /* (NV_RAM_SIZE != NONE) */    }/************************************************************************* sysEnetAddrGet - gets the 6 byte ethernet address** This routine gets the 6 byte ethernet address used by specific* ethernet device.** RETURNS: OK or ERROR if invalid unit number** SEE ALSO: sysEnetAddrSet()*/STATUS sysEnetAddrGet    (    int unit,    /* ethernet device number */    UINT8 *addr  /* store returned MAC address */    )    {    int   offset;    char *pEnet;    /* sanity check */    if ((unit < 0) || (unit >= MAX_MAC_ADRS))        {        return (ERROR);        }    pEnet  = (char*)glbEnetAddr[unit];    offset = unit * MAC_ADRS_LEN;#if (NV_RAM_SIZE != NONE)    /* if NVRAM present, get MAC address from NvRAM. */    sysNvRamGet(addr, MAC_ADRS_LEN, NV_MAC_ADRS_OFFSET + offset);    /* check if NVRAM content consistent with the glbEnetAddr table  */    if (memcmp(addr,pEnet,MAC_ADRS_LEN))        {         return OK;        }#if 0    /* update NVRAM using the table */    sysNvRamSet(pEnet, MAC_ADRS_LEN, NV_MAC_ADRS_OFFSET + offset);#endif    /* update the table using NVRAM */    memcpy(pEnet, addr, MAC_ADRS_LEN);    #endif /* (NV_RAM_SIZE != NONE) */    /* get MAC address from the glbEnetAddr table */        memcpy(addr,pEnet,MAC_ADRS_LEN);    return (OK);    }/************************************************************************* sysEnetUnitAddrSet - sets the 6 byte ethernet address** This routine sets the 6 byte ethernet address used by the ethernet * device, device number is passed in as parameter.** RETURNS: OK, or ERROR if invalid unit number** SEE ALSO: sysEnetAddrGet()*/STATUS sysEnetUnitAddrSet     (    int   unit,  /* device number */    UCHAR byte5, /* MSB */    UCHAR byte4,    UCHAR byte3,    UCHAR byte2,    UCHAR byte1,    UCHAR byte0 /* LSB */    )    {    int    offset;    STATUS status = OK;        /* sanity check */    if ((unit < 0) || (unit >= MAX_MAC_ADRS))        {        return (ERROR);        }    offset = unit * MAC_ADRS_LEN;    /* store address in table */        glbEnetAddr[unit][0] = byte5;    glbEnetAddr[unit][1] = byte4;    glbEnetAddr[unit][2] = byte3;    glbEnetAddr[unit][3] = byte2;    glbEnetAddr[unit][4] = byte1;    glbEnetAddr[unit][5] = byte0;#if (NV_RAM_SIZE != NONE)        /* if NVRAM present, save MAC address in NvRAM. */        status = sysNvRamSet((char *)&glbEnetAddr[unit], MAC_ADRS_LEN, NV_MAC_ADRS_OFFSET + offset);#endif /* (NV_RAM_SIZE != NONE) */        return (status);    }#if defined(INCLUDE_END)/************************************************************************* sysMacAddrSet - set the 6 byte ethernet address at run-time** This routine sets the 6 byte ethernet address used by the ethernet * device on the fly, device number is passed in as parameter. The* device will be restarted to make new address take affect.** NOTE* - END driver must support changing MAC dynamically** RETURNS: OK, or ERROR** SEE ALSO: sysMacAddrGet()*/STATUS sysMacAddrSet (    char *pName, /* device name  */    int   unit,  /* device number */    char *pAddr  /* address to set, MSB first */    )    {    END_OBJ *pCookie = NULL;    STATUS status = OK;        /* sanity check */    if((pName == NULL) || (pAddr == NULL) || (unit < 0) || (unit >= MAX_MAC_ADRS))        return (ERROR);        /* try to find the device */    pCookie = (END_OBJ *)muxTkCookieGet(pName, unit);    if(pCookie == NULL)        return (ERROR);    /* set address */    status = muxIoctl((void *)pCookie, EIOCSADDR, (caddr_t)pAddr);    return ((status == OK) ? OK : ERROR);    /* update ip_info->idr.ac_enaddr? */    }/************************************************************************* sysMacAddrGet - get the 6 byte ethernet address at run-time** This routine get the 6 byte ethernet address used by the ethernet * device on the fly, device number is passed in as parameter. ** NOTE* - END driver must support EIOCGADDR.** RETURNS: OK, or ERROR** SEE ALSO: sysMacAddrSet()*/STATUS sysMacAddrGet (    char *pName, /* device name  */    int   unit,  /* device number */    char *pAddr  /* store return MAC address, MSB first */    )    {    END_OBJ *pCookie = NULL;    STATUS status = OK;        /* sanity check */    if((pName == NULL) || (pAddr == NULL) || (unit < 0) || (unit >= MAX_MAC_ADRS))        return (ERROR);        /* try to find the device */    pCookie = (END_OBJ *)muxTkCookieGet(pName, unit);    if(pCookie == NULL)        return (ERROR);    /* get address */    status = muxIoctl((void *)pCookie, EIOCGADDR, (caddr_t)pAddr);    return ((status == OK) ? OK : ERROR);    }#endif  /* INCLUDE_END */

⌨️ 快捷键说明

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