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

📄 loopend.c

📁 操作系统vxworks平台下end设备的驱动程序,支持多种芯片,支持多种cpu
💻 C
📖 第 1 页 / 共 2 页
字号:
/* loopEnd.c - software loopback END *//* Copyright 1984-1996 Wind River Systems, Inc. */#include "copyright_wrs.h"/*	$NetBSD: loopEnd.c,v 1.13 1994/10/30 21:48:50 cgd Exp $	*//* * Copyright (c) 1982, 1986, 1993 *	The Regents of the University of California.  All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software *    must display the following acknowledgement: *	This product includes software developed by the University of *	California, Berkeley and its contributors. * 4. Neither the name of the University nor the names of its contributors *    may be used to endorse or promote products derived from this software *    without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * *	@(#)loopEnd.c	8.1 (Berkeley) 6/10/93 *//*modification history--------------------01k,14jan99,sut  prepended protocol information01j,14jan99,sut  moved to tor2_0_0, renamed to loopEnd.c01i,14jan99,sut  added routines loAddressForm, loPacketDataGet, loPacketAddrGet01h,13jan99,sut  revoved loPollStart and loPollEnd01g,13jan99,sut  put back again multicast support01f,13jan99,sut  added more documentation01e,12jan99,sut  removed ether address storage01d,12jan99,sut  added debug routines01c,11jan99,sut  removed multicast support01b,11jan99,sut  converted into END driver01a,07jan99,sut  started with netif/if_loop.c*//*DESCRIPTIONThis module implements the software loopback Enhanced Network  Driver (END).The only external routine is loEndLoad(), which can only be called from muxinterface.The driver does not support polled mode operations. Even though the polledmode interfaces are exported to mux layer, just returns ERROR for polled modeoperations.BOARD LAYOUTThis device is "software only."  A jumpering diagram is not applicable.EXTERNAL INTERFACEThe only external interface is the loEndLoad() routine, which expectsthe <initString> parameter as input.  At present this rouine expects only<unit> from this string. This parameter passes in a colon-delimited string ofthe format:<unit>The loEndLoad() function uses strtok() to parse the stringTARGET-SPECIFIC PARAMETERS.IP <unit>A convenient holdover from the former model.  This parameter is used onlyin the string name for the driver.SEE ALSO: ifLib*/#include "vxWorks.h"#include "stdlib.h"#include "end.h"#include "endLib.h"#include "lstLib.h"#include "wdLib.h"#include "iv.h"#include "semLib.h"#include "etherLib.h"#include "logLib.h"#include "netLib.h"#include "stdio.h"#include "sysLib.h"#include "errno.h"#include "errnoLib.h"#include "memLib.h"#include "iosLib.h"#undef	ETHER_MAP_IP_MULTICAST#include "etherMultiLib.h"		/* multicast stuff. */#include "net/mbuf.h"#include "net/unixLib.h"#include "net/protosw.h"#include "net/systm.h"#include "net/if_subr.h"#include "net/route.h"#include "sys/socket.h"#include "sys/ioctl.h"#include "sys/times.h"/* maximum packet size */#define LO_SPEED	10000000#define LO_MIN_FBUF	0	/* Minimum size of the first buffer in a */                        	/* chain. */#define LO_ADDR_LEN	0	/* address length */#define LO_HDR_LEN 	0	/* header length *//* Naming items */#define LO_DEV_NAME	"lo"#define LO_DEV_NAME_LEN	3/* device states */#define LO_ST_STOPPED	0x80#define LO_IS_DEV_STOPPED(pDrvCtrl)\			   ((pDrvCtrl->state & LO_ST_STOPPED) == LO_ST_STOPPED)#define LO_DEV_STOP(pDrvCtrl) (pDrvCtrl->state |= LO_ST_STOPPED)#define LO_DEV_START(pDrvCtrl) (pDrvCtrl->state &= (!LO_ST_STOPPED))#define LO_PROTOCOL_LEN sizeof(USHORT)#undef DRV_DEBUG#ifdef	DRV_DEBUG#define DRV_DEBUG_OFF		0x0000#define	DRV_DEBUG_POLL		0x0001#define	DRV_DEBUG_LOAD		0x0002#define	DRV_DEBUG_IOCTL		0x0004#define	DRV_DEBUG_LOG_NVRAM	0x0008#ifdef LOCAL#undef LOCAL#endif /* LOCAL */#define LOCAL ;int	loDebug = DRV_DEBUG_OFF; /* Turn it off initially. */#include "nvLogLib.h"#define DRV_LOG(FLG, X0, X1, X2, X3, X4, X5, X6)                    \	if ((loDebug & FLG)&&(FLG & DRV_DEBUG_POLL))                \            nvLogMsg(X0, X1, X2, X3, X4, X5, X6);                   \        else if (loDebug & FLG)                                     \            logMsg(X0, X1, X2, X3, X4, X5, X6);#define DRV_PRINT(FLG,X)                                            \	if (loDebug & FLG) printf X;#else /*DRV_DEBUG*/#define DRV_LOG(DBG_SW, X0, X1, X2, X3, X4, X5, X6)#define DRV_PRINT(DBG_SW,X)#endif /*DRV_DEBUG*//* The definition of the driver control structure */#define U16 unsigned short inttypedef struct lo_device    {    END_OBJ     end;			/* The class we inherit from. */    int		unit;			/* unit number */    U16		state;    u_short     errorStat;              /* error status */    } LOEND_DEVICE;/* forward declarations *//* This is the only externally visible interface. */END_OBJ* 	loEndLoad (char* initString);/* END interfaces */LOCAL STATUS	loUnload (LOEND_DEVICE* pDrvCtrl);LOCAL STATUS	loIoctl (LOEND_DEVICE* pDrvCtrl, int cmd, caddr_t data);LOCAL STATUS	loSend (LOEND_DEVICE* pDrvCtrl, M_BLK_ID pBuf);LOCAL STATUS	loStart (LOEND_DEVICE* pDrvCtrl);LOCAL STATUS	loStop (LOEND_DEVICE* pDrvCtrl);LOCAL STATUS	loMCastAddrAdd (LOEND_DEVICE* pDrvCtrl, char* pAddress);LOCAL STATUS	loMCastAddrDel (LOEND_DEVICE* pDrvCtrl, char* pAddress);LOCAL STATUS	loMCastAddrGet (LOEND_DEVICE* pDrvCtrl,				    MULTI_TABLE* pTable);LOCAL STATUS	loPollSend (LOEND_DEVICE* pDrvCtrl, M_BLK_ID pBuf);LOCAL STATUS	loPollReceive (LOEND_DEVICE* pDrvCtrl, M_BLK_ID pBuf);M_BLK_ID loAddressForm (M_BLK_ID pMblk, M_BLK_ID pSrcAddr, M_BLK_ID pDstAddr);STATUS loPacketDataGet (M_BLK_ID pMblk, LL_HDR_INFO* pLinkHdrInfo);STATUS loPacketAddrGet (M_BLK_ID pMblk, M_BLK_ID pSrc, M_BLK_ID pDst,                        M_BLK_ID pESrc, M_BLK_ID pEDst);LOCAL STATUS	loInitStringParse ();/* * Declare our function table.  This is static across all driver * instances. */LOCAL NET_FUNCS loFuncTable =    {    (FUNCPTR)loStart,		/* Function to start the device. */    (FUNCPTR)loStop,		/* Function to stop the device. */    (FUNCPTR)loUnload,		/* Unloading function for the driver. */    (FUNCPTR)loIoctl,		/* Ioctl function for the driver. */    (FUNCPTR)loSend,		/* Send function for the driver. */    (FUNCPTR)loMCastAddrAdd,	/* Multicast address add */    (FUNCPTR)loMCastAddrDel, 	/* Multicast address delete */    (FUNCPTR)loMCastAddrGet, 	/* Multicast table retrieve */    (FUNCPTR)loPollSend,	/* Polling send function for the driver. */    (FUNCPTR)loPollReceive,	/* Polling receive function for the driver. */    loAddressForm,		/* Put address info into a packet.  */    loPacketDataGet,		/* Get a pointer to packet data.   */    loPacketAddrGet		/* Get packet addresses.  */    };/******************************************************************************** loEndLoad - initialize the driver and device** This routine initializes the driver and the device to the operational state.* All of the device-specific parameters are passed in <initString>, which* expects a string of the following format:** <unit>** This routine can be called in two modes. If it is called with an empty but* allocated string, it places the name of this device (that is, "lo") into * the <initString> and returns 0.** If the string is allocated and not empty, the routine attempts to load* the driver using the values specified in the string.** RETURNS: An END object pointer, or NULL on error, or 0 and the name of the* device if the <initString> was NULL.*/END_OBJ* loEndLoad    (    char* initString		/* string to be parse by the driver */    )    {    LOEND_DEVICE 	*pDrvCtrl;    DRV_LOG (DRV_DEBUG_LOAD, "Loading lo...\n", 1, 2, 3, 4, 5, 6);    if (initString == NULL)        return (NULL);        if (initString[0] == NULL)        {        bcopy((char *)LO_DEV_NAME, initString, LO_DEV_NAME_LEN);        return (0);        }        /* allocate the device structure */    pDrvCtrl = (LOEND_DEVICE *)calloc (sizeof (LOEND_DEVICE), 1);        if (pDrvCtrl == NULL)	goto errorExit;    /* parse the init string, filling in the device structure */    if (loInitStringParse (pDrvCtrl, initString) == ERROR)	goto errorExit;    /* initialize the END and MIB2 parts of the structure */    if (END_OBJ_INIT (&pDrvCtrl->end, (DEV_OBJ *)pDrvCtrl, LO_DEV_NAME,		    pDrvCtrl->unit, &loFuncTable,                      "Loopback Enhanced Network Driver") == ERROR     || END_MIB_INIT (&pDrvCtrl->end, M2_ifType_softwareLoopback, NULL,                      LO_ADDR_LEN, 0, LO_SPEED)                    == ERROR)	goto errorExit;    /* set the flags to indicate readiness */    END_OBJ_READY (&pDrvCtrl->end,		    IFF_UP | IFF_RUNNING | IFF_LOOPBACK | IFF_MULTICAST);        DRV_LOG (DRV_DEBUG_LOAD, "Done loading lo...\n", 1, 2, 3, 4, 5, 6);    return (&pDrvCtrl->end);errorExit:    if (pDrvCtrl != NULL)	free ((char *)pDrvCtrl);    return NULL;    }/******************************************************************************** loUnload - unload a driver from the system** This function first brings down the device, and then frees any* stuff that was allocated by the driver in the load function.*/LOCAL STATUS loUnload    (    LOEND_DEVICE* pDrvCtrl    )    {    END_OBJECT_UNLOAD (&pDrvCtrl->end);    return (OK);    }/********************************************************************************* loStart - start the device** This function calls BSP functions to connect interrupts and start the* device running in interrupt mode.** RETURNS: OK or ERROR**/LOCAL STATUS loStart    (    LOEND_DEVICE *pDrvCtrl    )    {    LO_DEV_START(pDrvCtrl);    return OK;    }/********************************************************************************* loStop - stop the device** This function calls BSP functions to disconnect interrupts and stop* the device from operating in interrupt mode.** RETURNS: OK or ERROR*/LOCAL STATUS loStop    (    LOEND_DEVICE *pDrvCtrl    )    {    LO_DEV_STOP(pDrvCtrl);        return OK;        }

⌨️ 快捷键说明

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