📄 muxlib.c
字号:
/* muxLib.c - MUX network interface library *//* Copyright 1984 - 2002 Wind River Systems, Inc. *//*modification history--------------------03z,10may02,wap Remove unnecessary redeclaration of endList (SPR #74201)03y,07may02,kbw man page edits03x,25apr02,vvv return on muxTkBindUpdate error in muxBind (SPR #74042)03w,22apr02,wap Don't call muxTkUnbindUpdate() on invalid/free()'ed pointer (SPR #74861)03v,05nov01,vvv fixed compilation warnings03u,26oct01,vvv added NULL check for END object in muxEndFlagsNotify (SPR #69540)03t,15oct01,rae merge from truestack ver 03o, base 02n(?) (SPRs 69573,70722, 64471, 64473, 64406, 32626, ROUTER_STACK, etc.)03s,14jun01,vvv fixed compilation warnings03r,08jun01,vvv added missing closing for-loop closing bracket in muxReceive03q,10apr01,rae muxReceive only calls interested protocols (SPR #65557)03p,09nov00,spm removed pNptCookie from END_OBJ for binary compatibility03o,07nov00,spm removed nptFlag from END_OBJ for T2 END binary compatibility03n,30oct00,kbw putting back the NOMANUAL per request of dgross03m,30oct00,kbw removing NOMANUAL assignemnt to muxReceive, OK'd by GNN03m,24oct00,niq Merging in RFC2233 changes fron tor2_0.open_stack-f1 branch 03n,24oct00,ann fixed a bug in the EIOCGMCASTLIST part of muxIoctl 03m,16may00,ann merging from post R1 on openstack branch to incorporate RFC2233 implementation 03k,10mar00,ead fixed MIB-2 counter updates to use new RFC 2233 m2IfLib03l,17oct00,niq Update pEnd->snarfCount only when protocol addition is complete03k,16oct00,spm merged from version 03a of tor3_0_x branch (base version 02n): adds multiple SNARF protocol support, bug fixes and cleanup, and backward compatibility fixes03i,07jul99,pul modify description for man page generation03h,30apr99,pul muxIoctl: check for error before calling muxEndFlagsNotify 03g,29apr99,pul muxPollSend: Call endpacketDataGet directly instead of muxPacketDataGet 03f,29apr99,pul Upgraded NPT phase3 code to tor2.0.003e,31mar99,spm removed \040 codes from muxMCastAddrGet() entry (SPR #26268)03d,30mar99,pul removed all references to muxSvcFunc and muxMCastFunc03c,25mar99,sj detect if the end.flags actually changed before notifying all03b,25mar99,sj muxDevUnload does not free pEnd->devObject.pDevice + misc03a,24mar99,sj before calling Error,Restart or Shutdown callbacks check for MUX_BIND or MUX_TK_BIND02z,19mar99,sj no need to notify the protocol that changed the END flags02y,18mar99,sj in muxLibInit return status returned by muxTkBibInit02x,18mar99,sj added notification to protocols when END flags change02w,05mar99,sj eliminated hooks; not cleanly though. next version will do that02v,03mar99,pul fix for SPR# 2428502u,02mar99,pul fixed the return value for muxUnbind(): SPR# 2429302t,13nov98,n_s added muxDevStopAll function. Added reboot hook in muxLibInit so that muxDevStop all is called prior to reboot. spr #2322902s,10nov98,sj more doc changes for NPT02r,03nov98,sj added check for NPT driver in muxSend + doc fixes02q,12oct98,pul modified the NPT hooks for compatibility with SENS 02p,08oct98,sj making DOC fixes for NPT02o,07oct98,sj added npt hooks02n,09sep98,ham corrected the comprison of ifTypes and MUX_MAX_IFTYPE.02m,09sep98,ham cont'd SPR#22298.02l,08sep98,ham moved MUX_MAX_TYPE to h/muxLib.h, SPR#22298.02k,21aug98,n_s fixed ifInUnknownProtos update in muxReceive, ifOutNUcastPkts update in muxSend (). spr 21074.02j,16jul98,n_s Added semGive () to ERROR condition for driver unload call in muxDevUnload ().02i,13jul98,n_s fixed muxDevLoad () to limit device name strcpy () to END_NAME_MAX. spr # 2164202h,13jul98,n_s fixed muxBind () to clear malloc'd NET_PROTOCOL. spr # 2164402g,24jun98,n_s fixed muxUnbind () to check NET_PROTOCOL node for type 02f,15jun98,n_s fixed muxDevUnload () and muxUnbind (). spr # 2154202e,13feb98,n_s fixed endFindByName () to handle multiple devices. spr # 21055.02d,02feb98,spm removed unneeded '&' operator and corrected spacing02c,17jan98,gnn fixed a bug in the output filter with passing LL_HDR_INFO.02b,17jan98,gnn changed output routines so they can be BOOL like receive routines.02a,17jan98,kbw made man page fixes01z,14dec97,kbw made man page fixes01y,10dec97,kbw made man page fixes01x,08dec97,gnn END code review fixes.01w,21oct97,kbw made man page fixes01v,08oct97,vin fixed muxPacketAddrGet().01u,07oct97,vin fixed a problem with calling muxIoctl, removed IFF_LOAN01t,03oct97,gnn added error routine and cleaned up function prototypes01s,25sep97,gnn SENS beta feedback fixes01r,25aug97,gnn documenatation changs to make mangen happy.01q,25aug97,gnn fixed a bug in the restart routine.01p,22aug97,gnn updated polled mode support.01o,19aug97,gnn changes due to new buffering scheme.01n,12aug97,gnn changes necessitated by MUX/END update.01m,31jul97,kbw fixed man page bug that broke build, comment in comment01l,31jul97,kbw fixed man page problems found in beta review01k,15may97,gnn removed many warnings. added code to handle MUX_PROTO_OUTPUT.01j,30apr97,jag man edits for funtion muxBufInit()01i,17apr97,gnn removed muxDevStart from muxDevLoad.01h,07apr97,gnn added errnoSet calls added muxDevNameGet. modified the way muxDevLoad works.01g,12mar97,gnn fixed a bug in muxReceive's calling API.01f,03feb97,gnn Modified muxBuf code to be more generic and support other, non-TMD systems.01e,29jan97,gnn Removed the code to start the tNetTask.01d,21jan97,gnn Added muxBuf* code to handle buffering system. Added code to handle the new SNARF option. Removed all loaning and reference counting stuff. Removed TxBuf stuff.01e,23oct96,gnn name changes to follow coding standards. removed some compiler warnings.01d,22oct96,gnn added routines to start and stop drivers. added code to handle buffer loaning startup requests on both the protocol and device side. replaced netVectors with netBuffers.01c,23sep96,gnn moved some generic code to here from the driver.01b,22Apr96,gnn filling in with real code.01a,21Mar96,gnn written.*/ /*DESCRIPTIONThis library provides the routines that define the MUX interface, a facilitythat handles communication between the data link layer and the networkprotocol layer. Using the MUX, the VxWorks network stack has decoupled thedata link and network layers. Drivers and services no longer need knowledge of each other's internals. This independence makes it much easier to add new drivers or services. For example, if you add a new MUX-based "END" driver, all existing MUX-based services can use the new driver. Likewise, if you add a new MUX-based service, any existing END can use the MUX to access the new service. INCLUDE FILES: errno.h, lstLib.h, logLib.h, string.h, m2Lib.h, bufLib.h, if.h,end.h, muxLib.h, vxWorks.h, taskLib.h, stdio.h, errnoLib.h, if_ether.h,netLib.h, semLib.h, rebootLib.hTo use this feature, include the following component:INCLUDE_MUXSEE ALSO.I "VxWorks AE Network Programmer's Guide"*//* includes */#include "vxWorks.h"#include "taskLib.h"#include "stdio.h"#include "errno.h"#include "errnoLib.h"#include "lstLib.h"#include "logLib.h"#include "string.h"#include "m2Lib.h"#include "net/if.h" /* Needed for IFF_LOAN flag. */#include "netinet/if_ether.h"#include "netLib.h" /* Needed for netJobAdd */#include "bufLib.h"#include "semLib.h"#include "end.h" /* Necessary for any END as well as the MUX */#include "muxLib.h"#include "muxTkLib.h"#include "private/muxLibP.h"#include "rebootLib.h"#include "memPartLib.h"#ifdef VIRTUAL_STACK #include "netinet/vsLib.h"#endif /* VIRTUAL_STACK *//* defines */#define STREQ(A, B) (strcmp(A, B) == 0 ? 1 : 0)#define NET_TASK_NAME "tNetTask"#define TK_DRV_CHECK(pBib) ((((MUX_ID)pBib)->flags & BIB_TK_DRV) ? TRUE : FALSE)#define GET_IFMTU(a) (((a)->flags & END_MIB_2233) ? \ (a)->pMib2Tbl->m2Data.mibIfTbl.ifMtu : (a)->mib2Tbl.ifMtu)/* externs *//* globals *//* locals */LOCAL muxLib muxLibState;LOCAL LIST endList;#ifndef STANDALONE_AGENTLOCAL LIST addrResList[MUX_MAX_IFTYPE + 1]; /* IFT_xxx begins from 1 */#endif /* STANDALONE_AGENT *//* forward declarations */LOCAL M_BLK_ID *pMuxPollMblkRing;LOCAL void **ppMuxPollDevices;LOCAL int muxPollDevCount;LOCAL int muxPollDevMax;IMPORT STATUS muxTkReceive (void *, M_BLK_ID, long, long, BOOL, void *);LOCAL void muxEndFlagsNotify (void * pCookie, long endFlags); LOCAL STATUS muxDevStopAllImmediate (void);/********************************************************************************* muxLibInit - initialize global state for the MUX** This routine initializes all global states for the MUX.** RETURNS: OK or ERROR.*/STATUS muxLibInit (void) {#ifndef STANDALONE_AGENT int count;#endif /* STANDALONE_AGENT */ STATUS status = OK; if (muxLibState.lock != NULL) return (OK); muxLibState.debug = FALSE; muxLibState.lock = NULL; muxLibState.mode = MUX_MODE_NORM; muxLibState.priority = MUX_POLL_TASK_PRIORITY; /* Lame */ muxLibState.taskDelay = MUX_POLL_TASK_DELAY; /* Lame */ muxLibState.taskID = 0; muxLibState.lock = semBCreate(SEM_Q_PRIORITY, SEM_FULL); if (muxLibState.lock == NULL) return (ERROR);#ifndef STANDALONE_AGENT /* * Initialize our lists to empty. * addrResList[0] will not be used because IFT_xxx begins from 1 */ for (count = 0; count <= MUX_MAX_IFTYPE; count++) lstInit (&addrResList[count]);#endif /* STANDALONE_AGENT */ /* initialize END list */ lstInit (&endList); /* Add hook to stop all ENDs when the system reboots */ if (rebootHookAdd ((FUNCPTR) muxDevStopAllImmediate) != OK) { return (ERROR); } /* Initialize BIB. */ status = muxTkBibInit(); if (muxLibState.debug) logMsg ("End of muxLibInit\n", 0, 0, 0, 0, 0, 0); return (status); } /******************************************************************************* * muxDevLoad - load a driver into the MUX* * The muxDevLoad() routine loads a network driver into the MUX. Internally, * this routine calls the specified <endLoad> routine to initialize the* software state of the device. After the device is initialized,* you must call muxDevStart() to start the device. * .IP <unit> 15* Expects the unit number of the device. * .IP <endLoad> * Expects a pointer to the network driver's endLoad() or nptLoad() entry* point. * .IP <pInitString> * Expects a pointer to an initialization string, typically a colon-delimited* list of options. The muxDevLoad() routine passes this along blindly to * the <endLoad> function.* .IP <loaning> * Currently unused.* .IP <pBSP>* The MUX blindly passes this argument to the driver, which may or may not * use it. Some BSPs use this parameter to pass in tables of functions that * the diver can use to deal with the particulars of the BSP. ** VXWORKS AE PROTECTION DOMAINS* Under VxWorks AE, you can call muxDevLoad() from within the kernel * protection domain only, and the data referenced in the <endLoad> and * <pBSP> parameters must reside in the kernel protection domain. In * addition, the returned void pointer is valid in the kernel protection * domain only. This restriction does not apply under non-AE versions of * VxWorks. * * RETURNS: A cookie representing the new device, or NULL if an error occurred.** ERRNO: S_muxLib_LOAD_FAILED*/void * muxDevLoad ( int unit, /* unit number of device */ END_OBJ * (*endLoad) (char*, void*), /* load function of the driver */ char * pInitString, /* init string for this driver */ BOOL loaning, /* we loan buffers */ void * pBSP /* for BSP group */ ) { END_OBJ * pNew; END_TBL_ROW * pNode; char initString [END_INIT_STR_MAX]; char devName [END_NAME_MAX]; BOOL found = FALSE; void * pCookie = NULL; if (muxLibState.debug) logMsg ("Start of muxDevLoad\n", 0, 0, 0, 0, 0, 0); bzero ( (char *)initString, END_INIT_STR_MAX); bzero ( (char *)devName, END_NAME_MAX); /* Let's mutually exclude here, wouldn't you say? */ semTake (muxLibState.lock, WAIT_FOREVER); /* * Loading a device is a two pass algorithm. * * This is Pass 1. * * In the first pass we ask the device what its name is. If that name * exists in our table then we add the new node to the end of the * already existing list. If not then we create a new row in the * table, and place the new node as the zero'th (0) element in the node's * list. */ if (endLoad ( (char *)devName, NULL) != 0) { goto muxLoadErr; } if (endFindByName ( (char *)devName, unit) != NULL) { goto muxLoadErr; } for (pNode = (END_TBL_ROW *)lstFirst(&endList); pNode != NULL; pNode = (END_TBL_ROW *)lstNext(&pNode->node)) { if (STREQ (pNode->name, (char *)devName)) { found = TRUE; break; } } /* If there is no row for this device then add it. */ if (!found) { pNode = KHEAP_ALLOC (sizeof(END_TBL_ROW)); if (pNode == NULL) { goto muxLoadErr; } bzero ((char *)pNode, sizeof(END_TBL_ROW)); strncpy(pNode->name, devName, END_NAME_MAX - 1); pNode->name [END_NAME_MAX - 1] = EOS; lstAdd(&endList, &pNode->node); } /* * This is Pass 2. * * Now that we can determine a unique number we assign that number to * the device and actually load it. */ sprintf ( (char *)initString, "%d:%s", unit, pInitString); pNew = (END_OBJ *)endLoad ( (char *)initString, pBSP); if (pNew == NULL) { goto muxLoadErr; } /* * Leave this stuff last to prevent a race condition. The condition * would be that the driver could call the receive routine
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -