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

📄 muxtklib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
            {            if (pNBuff)                netMblkClChainFree (pNBuff);            return ERROR;            }	}    else /* NPT driver */	{	/* if we get here we send the packet to the driver */	return (sendRtn (pEnd, pNBuff, dstMacAddr, netType, pSpareData));	}    }/******************************************************************************* muxTkSend - send a packet out on a Toolkit or END network interface** This routine uses <pCookie> to find a specific network interface and* uses that driver's send routine to transmit a packet.* * The transmit entry point for an NPT driver uses the following prototype:* .CS* STATUS nptSend*     (*     END_OBJ * pEND, 	        /@ END object @/*     M_BLK_ID 	pPkt, 		/@ network packet to transmit @/*     char * 	pDstAddr, 	/@ destination MAC address @/*     int 	netType 	/@ network service type @/*     void * 	pSpareData 	/@ optional network service data @/*     )* .CE** The transmit entry point for an END driver the following prototype:* .CS* STATUS endSend*     (*     void * 	pEND, 	/@ END object @/*     M_BLK_ID 	pPkt,	/@ Network packet to transmit @/*     )* .CE** An END driver must continue to provide the addressForm() entry point to* construct the appropriate link-level header. The <pDst> and <pSrc> M_BLK* arguments to that routine supply the link-level addresses with the* 'mData' and 'mLen' fields. The reserved field of the destination M_BLK* contains the network service type. Both arguments \f2must\fP* be treated as read-only.** To send a fully formed physical layer frame to a device using an NPT* driver (which typically forms the frame itself), set the M_L2HDR flag* in the 'mBlk' header.** A driver may be written so that it returns the error END_ERR_BLOCK if* the driver has insufficient resources to transmit data.  The network* service sublayer can use this feedback to establish a flow control* mechanism by holding off on making any further calls to muxTkSend()* until the device is ready to restart transmission, at which time the* device should call muxTxRestart() which will call the service sublayer's* stackRestartRtn() that was registered for the interface at bind time.** .IP <pCookie>* Expects the cookie returned from muxTkBind().  This Cookie* identifies the device to which the MUX has bound this protocol.** .IP <pNBuff>* The network packet to be sent, formed into an 'mBlk' chain.** .IP <dstMacAddr>* Destination MAC address to which packet is to be sent, determined* perhaps by calling the address resolution function that was registered* for this service/device interface.** .IP <netType>* Network service type of the sending service.  This will be used to* identify the payload type in the MAC frame.** .IP <pSpareData>* Reference to any additional data the network service wants to pass to the* driver during the send operation.** NOTE: A driver may return END_ERR_BLOCK if it is temporarily unable* to complete the send, and then call muxTxRestart() to indicate that it* is again able to send data.  If the driver has been written in this way,* muxTkSend() will pass the ERR_END_BLOCK back as its own return value and* the service can wait for its stackRestartRtn() callback routine to be* called before trying the send operation again.** RETURNS: OK; ENETDOWN, if <pCookie> doesn't represent a valid device;* or an error, if the driver's send() routine fails.** ERRNO: S_muxLib_NO_DEVICE*/STATUS muxTkSend    (    void *    pCookie,		/* returned by muxTkBind()*/    M_BLK_ID  pNBuff,		/* data to be sent */    char *    dstMacAddr,	/* destination MAC address */    USHORT    netType,		/* network protocol that is calling us */                                /** is netType redundant? **/    void *    pSpareData	/* spare data passed on each send */    )    {    MUX_ID    muxId = (MUX_ID)pCookie;    END_OBJ * pEnd = muxId->pEnd;    if (pEnd == NULL)        {        errnoSet (S_muxLib_NO_DEVICE);        if (pNBuff)            netMblkClChainFree (pNBuff);        return (ENETDOWN);        }    else        {	FUNCPTR sendRtn = pEnd->pFuncTable->send;	return (_muxTkSend (muxId, pNBuff, dstMacAddr, netType, pSpareData,			    sendRtn));        }    }/******************************************************************************* muxTkPollSend - send a packet out in polled mode to an END or NPT interface** This routine uses <pCookie> to find a specific network interface and* use that driver's pollSend() routine to transmit a packet.** This routine replaces the muxPollSend() routine for both END and NPT* drivers.** When using this routine, the driver does not need to call muxAddressForm()* to complete the packet, nor does it need to prepend an 'mBlk' of type* MF_IFADDR containing the destination address.** An NPT driver's pollSend() entry point is called based on this prototype:* .CS* STATUS nptPollSend*     (*     END_OBJ * pEND, 	        /@ END object @/*     M_BLK_ID 	pPkt, 		/@ network packet to transmit @/*     char * 	pDstAddr, 	/@ destination MAC address @/*     long 	netType 	/@ network service type @/*     void * 	pSpareData 	/@ optional network service data @/*     )* .CE** The pollSend() entry point for an END uses this prototype:* .CS* STATUS endPollSend*     (*     END_OBJ * pEND, 	/@ END object @/*     M_BLK_ID 	pPkt, 	/@ network packet to transmit @/*     )* .CE** An END driver must provide the addressForm() entry point to* construct the appropriate link-level header. The <pDst> and <pSrc> M_BLK* arguments to that routine supply the link-level addresses with the* mData and mLen fields. The reserved field of the destination M_BLK* contains the network service type. Both arguments \f2must\fP be treated as* read-only.** .IP <pCookie>* Expects the cookie returned from muxBind() or muxTkBind().  This cookie* identifies the device to which the MUX has bound this protocol.** .IP <pNBuff>* The network packet to be sent.** .IP <dstMacAddr>* Destination MAC address to which packet is to be sent** .IP <netType>* Network service type that will be used to identify the payload data in* the MAC frame.** .IP <pSpareData>* Reference to any additional data the network service wants to pass to the* driver during the send operation.** RETURNS: OK, ENETDOWN if <pCookie> doesn't represent a valid device,* or an error if the driver's pollSend() routine fails.** ERRNO: S_muxLib_NO_DEVICE*/STATUS muxTkPollSend    (    void *    pCookie,		/* returned by muxTkBind()*/    M_BLK_ID  pNBuff,		/* data to be sent */    char *    dstMacAddr,	/* destination MAC address */    USHORT    netType,		/* network protocol that is calling us */                                /** is netType redundant? **/    void *    pSpareData	/* spare data passed on each send */    )    {    MUX_ID    muxId = (MUX_ID)pCookie;    END_OBJ * pEnd = muxId->pEnd;    if (pEnd == NULL)        {        if (pNBuff)            netMblkClChainFree (pNBuff);        errnoSet (S_muxLib_NO_DEVICE);        return (ENETDOWN);        }    else        {	FUNCPTR sendRtn = pEnd->pFuncTable->pollSend;	return (_muxTkSend (muxId, pNBuff, dstMacAddr, netType,			    pSpareData, sendRtn));        }    }/****************************************************************************** * muxTkPollReceive - poll for a packet from a NPT or END driver** This is the routine that an upper layer can call to poll for a packet.* Any service type retrieved from the MAC frame is passed via the reserved* member of the M_BLK header.** This API effectively replaces muxPollReceive() for both END and NPT drivers.** For an NPT driver its pollReceive() entry point is called based on the new* prototype:* .CS* STATUS nptPollReceive*     (*     END_OBJ * pEND, 	        /@ END object @/*     M_BLK_ID 	pPkt, 		/@ network packet buffer @/*     long * 	pNetSvc, 	/@ service type from MAC frame @/*     long * 	pNetOffset, 	/@ offset to network packet @/*     void * 	pSpareData 	/@ optional network service data @/*     )* .CE** The pollReceive() entry point for an END driver uses the original prototype:* .CS* STATUS endPollRcv*     (*     END_OBJ * pEND, 	/@ END object @/*     M_BLK_ID 	pPkt, 	/@ network packet buffer @/*     )* .CE** An END driver must continue to provide the packetDataGet() entry point** .IP <pCookie>* Expects the cookie that was returned from muxBind() or muxTkBind().* This "cookie" identifies the driver. ** .IP <pNBuff>* Expects a pointer to a buffer chain into which incoming data will be put.** .IP <pSpareData>* A pointer to any optional spare data provided by a NPT driver. Always* NULL with an END driver.** RETURNS: OK; EAGAIN, if no packet was available; ENETDOWN, if the 'pCookie'* does not represent a loaded driver; or an error value returned from the * driver's registered pollReceive() function.** ERRNO: S_muxLib_NO_DEVICE*/STATUS muxTkPollReceive    (    void *    pCookie,	/* cookie from muxTkBind routine */    M_BLK_ID  pNBuff,	/* a vector of buffers passed to us */    void *    pSpare	/* a reference to  spare data is returned here */    )    {    int          error        = OK;    MUX_ID       muxId        = (MUX_ID)pCookie;    END_OBJ *    pEnd         = muxId->pEnd;    FUNCPTR      pollRcvRtn;    LL_HDR_INFO  llHdrInfo;     int          netPktOffset = 0;    int          netSvcType   = 0;    if (pEnd == NULL)	{        errnoSet (S_muxLib_NO_DEVICE);	return (ENETDOWN);	}    pollRcvRtn = pEnd->pFuncTable->pollRcv;    if (!TK_DRV_CHECK(muxId))	{	/* call END poll receive routine */	if ((error = pollRcvRtn (pEnd, pNBuff)) == OK)	    {	    if (pEnd->pFuncTable->packetDataGet (pNBuff,&llHdrInfo) == ERROR)		return (ERROR);	    }	netPktOffset = llHdrInfo.dataOffset;	netSvcType = llHdrInfo.pktType;	if (pSpare)	    *(UINT32 *)pSpare = (UINT32)NULL;	}    else	{	error = pollRcvRtn (pEnd, pNBuff,&netSvcType,			    &netPktOffset, pSpare);        if (error != OK)	    return error;	}    /* restore the network layer packet for a non SNARF protocol */    if (muxId->netSvcType != MUX_PROTO_SNARF)	{	pNBuff->mBlkHdr.mData += netPktOffset;	pNBuff->mBlkHdr.mLen -= netPktOffset;	}    /* Save the service type returned by the driver in the reserved field. */    pNBuff->mBlkHdr.reserved = (USHORT)netSvcType;    return (error);    }/******************************************************************************** muxTkPollReceive2 - muxTkPollReceive + muxTkReceive** Combines muxTkPollReceive and muxTkReceive.** RETURNS: OK if the packet is passed up the stack* * NOMANUAL*/STATUS muxTkPollReceive2    (    void *    pCookie,  /* cookie from muxTkBind routine */    M_BLK_ID  pNBuff    )    {    MUX_ID       muxId        = (MUX_ID)pCookie;    END_OBJ *    pEnd         = muxId->pEnd;    FUNCPTR      pollRcvRtn;    int          netPktOffset = 0;    int          netSvcType   = 0;        pollRcvRtn = pEnd->pFuncTable->pollRcv;    if (pollRcvRtn (pEnd, pNBuff, &netSvcType, &netPktOffset, NULL) == ERROR)	return (ERROR);        /* restore the network layer packet for a non SNARF protocol */    if (((MUX_ID)pCookie)->netSvcType != MUX_PROTO_SNARF)	{	pNBuff->mBlkHdr.mData += netPktOffset;	pNBuff->mBlkHdr.mLen -= netPktOffset;	}    /* Save the service type returned by the driver in the reserved field. */    pNBuff->mBlkHdr.reserved = (USHORT)netSvcType;    muxTkReceive (pCookie, pNBuff, netPktOffset, netSvcType,	((END_OBJ *)pCookie)->flags & IFF_PROMISC, NULL);    return (OK);    }/******************************************************************************** muxEndRcvRtn - wrapper stack receive routine for END drivers* * This routine is installed as the stackRcvRoutine() for all END drivers bound* to with the muxTkBind() call. This allows muxTkBind() to support both END* and NPT drivers and thus eliminates the need to call muxTkDrvCheck().** For incoming data, the <pCookie> argument is equal to the value from the* muxBind() routine (if it had been used). For an NPT output filter bound* to an END device, the <pCookie> argument is equal to NULL.** The <pSpare> argument is equal to the address of the BIB entry for the* protocol/device binding.** RETURNS: OK or ERROR** NOMANUAL*/int muxEndRcvRtn    (    void *        pCookie,       	/* muxReceive cookie, or NULL */    long          type,			/* network service type */    M_BLK_ID      pMblk,		/* MAC frame */    LL_HDR_INFO * pLinkHdrInfo,		/* link level information */    void *        pSpare		/* pSpare argument (from muxBind) */    )    {    BOOL      retVal = FALSE;    MUX_ID    muxId  = (MUX_ID) pSpare;    END_OBJ * pEnd   = muxId->pEnd;    if (pLinkHdrInfo == NULL || pEnd == NULL)	return ERROR;    /* point to network packet and adjust the length */    pMblk->mBlkHdr.mData        += pLinkHdrInfo->dataOffset;    pMblk->mBlkHdr.mLen         -= pLinkHdrInfo->dataOffset;    pMblk->mBlkPktHdr.len       -= pLinkHdrInfo->dataOffset;    /* call the registered network service's stack recv routine */    retVal = muxId->netStackRcvRtn (muxId->pNetCallbackId,type,pMblk,NULL);    if (muxId->netSvcType == MUX_PROTO_OUTPUT && retVal == FALSE)	{	/*	 * if we are called via the output filter mechanism and the	 * filter does not consume the packet we need to undo the stripping	 * of the MAC header	 */	pMblk->mBlkHdr.mData        -= pLinkHdrInfo->dataOffset;	pMblk->mBlkHdr.mLen         += pLinkHdrInfo->dataOffset;	pMblk->mBlkPktHdr.len       += pLinkHdrInfo->dataOffset;	}    return (retVal);    }/******************************************************************************** muxTkBibEntryGet - find the next available slot in the BIB ** This is a internal function called to find the next available entry in* the BIB. For the first protocol that binds to a particular device the* entry that was partially filled at the time of driver load, using

⌨️ 快捷键说明

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