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

📄 muxlib.c

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 C
📖 第 1 页 / 共 4 页
字号:
        }    else        {        return (ERROR);        }    return (error);    }/******************************************************************************** muxPacketAddrGet - get addressing information from a packet** This routine takes a pointer to cookie that was handed back by muxBind(),* an M_BLK_ID that came from a device and up to four M_BLK_ID's that * can receive data pointers.** The routine returns appropriate information* on the immediate source, immediate destination, ultimate source and,* ultimate destination addresses from the packet pointed to in the first* M_BLK_ID.  This routine is a pass through to the device's own routine* which knows how to interpret packets that it has received.** .IP <pCookie>* Expects the cookie returned from the muxBind() call.  This* cookie identifies the device to which the MUX bound this protocol.** .IP <pMblk>* Expects an M_BLK_ID representing packet data from which the addressing* information is to be extracted** .IP <pSrcAddr>* Expects NULL or an M_BLK_ID which will hold the local source address* extracted from the packet** .IP <pDstAddr>* Expects NULL or an M_BLK_ID which will hold the local destination address* extracted from the packet** .IP <pESrcAddr>* Expects NULL or an M_BLK_ID which will hold the end source address* extracted from the packet** .IP <pEDstAddr>* Expects NULL or an M_BLK_ID which will hold the end destination address* extracted from the packet** RETURNS: OK or ERROR.** ERRNO: S_muxLib_NO_DEVICE*/STATUS muxPacketAddrGet    (    void* pCookie,		/* cookie that identifies the device */    M_BLK_ID pMblk,		/* structure to contain packet */    M_BLK_ID pSrcAddr,   	/* structure containing source address */    M_BLK_ID pDstAddr,          /* structure containing destination address */    M_BLK_ID pESrcAddr,         /* structure containing the end source */    M_BLK_ID pEDstAddr          /* structure containing the end destination */    )    {    int error = OK;    END_OBJ* pEnd;    pEnd = (END_OBJ *)pCookie;        if (pEnd == NULL)        {        errnoSet(S_muxLib_NO_DEVICE);        return (ERROR);        }        if (pEnd->pFuncTable->formAddress != NULL)        {        if (pEnd->pFuncTable->addrGet != NULL)            {              error = pEnd->pFuncTable->addrGet(pMblk,                                              pSrcAddr,                                              pDstAddr,                                              pESrcAddr,                                              pEDstAddr);            }        }    else        {        error = ERROR;        }    return (error);    }/******************************************************************************** endFindByName - find a device using its string name** This routine takes a string name and a unit number and finds the* END device that has that name/unit combination.** RETURNS: A pointer to an END_OBJ or NULL (if the device is not found).**/END_OBJ* endFindByName    (    char* pName,			/* device name to search for */    int unit    )    {    BOOL found = FALSE;    END_TBL_ROW* pNode;    END_OBJ* pEnd;        for (pNode = (END_TBL_ROW *)lstFirst(&endList); pNode != NULL; 	pNode = (END_TBL_ROW *)lstNext(&pNode->node))	{	if (STREQ(pNode->name, pName))	    {            found = TRUE;            break;	    }	}    if (found)        {        for (pEnd = (END_OBJ *)lstFirst(&pNode->units); pEnd != NULL;              pEnd = (END_OBJ *)lstNext(&pEnd->node))            {            if (pEnd->devObject.unit == unit)                {                return (pEnd);                }            }        }        return (NULL);    }/******************************************************************************** muxDevExists - tests whether a device is already loaded into the MUX** This routine takes a string device name (for example, ln or ei)* and a unit number.* If this device is already known to the MUX, it returns TRUE.* Otherwise, this routine returns FALSE. ** .IP <pName>* Expects a pointer to a string containing the device name** .IP <unit>* Expects the unit number of the device** RETURNS: TRUE if the device exists, else FALSE.**/BOOL muxDevExists    (    char* pName,	/* string containing a device name (ln, ei, ...)*/    int unit            /* unit number */    )    {    if (endFindByName(pName, unit) == NULL)        return (FALSE);    return (TRUE);    }/******************************************************************************** muxTxRestart - notify a protocol that it can restart its transmitter** This is routine is provided so that an END can tell all the protocols* bound to it that they can start transmitting again if transmission was* blocked due to the device being out of resources.** .IP <pCookie>* Expects the cookie that was returned from muxBind() that* identifies the protocol bound to the device that is calling the routine** RETURNS: N/A** ERRNO: S_muxLib_NO_DEVICE** NOMANUAL*/void muxTxRestart    (    void* pCookie    )    {    NET_PROTOCOL* pProto;    END_OBJ* pEnd;        pEnd = (END_OBJ *)pCookie;    if (pEnd == NULL)        {        errnoSet(S_muxLib_NO_DEVICE);        return;        }    if (muxDebug)        logMsg ("muxTxRestart\n", 1, 2, 3, 4, 5, 6);    /*     * Loop through the protocol list.     */    for (pProto = (NET_PROTOCOL *)lstFirst(&pEnd->protocols); 	pProto != NULL; pProto = (NET_PROTOCOL *)lstNext(&pProto->node))	{	if (pProto->stackTxRestartRtn != NULL)            pProto->stackTxRestartRtn(pCookie, pProto->pSpare);        }    }/******************************************************************************** muxError - notify a protocol that an error occurred.** This is routine is provided so that an END can tell all the protocols* bound to it that an error has occurred.  The errors are defined in end.h.** .IP <pCookie>* Expects the cookie that was returned by the driver's endLoad() routine;* a pointer to the driver's END_OBJ.** .IP <pError>* Expects an error structure as defined in end.h** RETURNS: N/A** ERRNO: S_muxLib_NO_DEVICE** NOMANUAL*/void muxError    (    void* pCookie,                           /* END_OBJ */    END_ERR* pError                          /* Error structure. */    )    {    NET_PROTOCOL* pProto;    END_OBJ* pEnd;        pEnd = (END_OBJ *)pCookie;    if (pEnd == NULL)        {        errnoSet(S_muxLib_NO_DEVICE);        return;        }    if (muxDebug)        logMsg ("muxError\n", 1, 2, 3, 4, 5, 6);    /*     * Loop through the protocol list.     */    for (pProto = (NET_PROTOCOL *)lstFirst(&pEnd->protocols); 	pProto != NULL; pProto = (NET_PROTOCOL *)lstNext(&pProto->node))	{	if (pProto->stackErrorRtn != NULL)            pProto->stackErrorRtn(pCookie, pError, pProto->pSpare);        }    }/******************************************************************************** muxAddrResFuncAdd - add an address resolution function** This routine takes an ifType from m2Lib.h, a protocol number from RFC 1700* and a pointer to an address resolution function and installs that function* for later retrieval by muxAddrResFuncGet().** .IP <ifType>* Expects a media interface or network driver type from m2Lib.h** .IP <protocol>* Expects a network service or protocol type from RFC 1700** .IP <addrResFunc>* Expects a pointer to an address resolution function for this driver and* protocol** RETURNS: OK or ERROR.**/STATUS muxAddrResFuncAdd    (    long ifType,         /* Media interface type from m2Lib.h */    long protocol,       /* Protocol type from RFC 1700 */    FUNCPTR addrResFunc  /* Function to call. */    )    {    BOOL found = FALSE;    MUX_ADDR_REC* pNode;        if (ifType > MUX_MAX_IFTYPE)        return (ERROR);    if (&addrResList[ifType] == NULL)        {        lstInit (&addrResList[ifType]);        pNode = malloc (sizeof(MUX_ADDR_REC));        if (pNode == NULL)            {            return (ERROR);            }        pNode->addrResFunc = addrResFunc;        pNode->protocol = protocol;        lstAdd(&addrResList[ifType], &pNode->node);        return (OK);        }    else        {        for (pNode = (MUX_ADDR_REC *)lstFirst(&addrResList[ifType]);             pNode != NULL;              pNode = (MUX_ADDR_REC *)lstNext(&pNode->node))            {            if (pNode->protocol == protocol)                {                found = TRUE;                break;                }            }        }    if (found)        {        return (ERROR);        }    else        {        pNode = malloc (sizeof(MUX_ADDR_REC));        if (pNode == NULL)            {            return (ERROR);            }        pNode->addrResFunc = addrResFunc;        pNode->protocol = protocol;        lstAdd(&addrResList[ifType], &pNode->node);        return (OK);        }        return (ERROR);    }/******************************************************************************** muxAddrResFuncGet - get the address resolution function for ifType/protocol** This routine takes an <ifType> (from m2Lib.h) and a protocol (from RFC 1700)* and returns a pointer to the address resolution function registered* for this <ifType>/protocol pair.  If no such function exists then NULL* is returned.** .IP <ifType>* Expects a media interface or network driver type from m2Lib.h** .IP <protocol>* Expects a network service or protocol type from RFC 1700** RETURNS: FUNCPTR to the routine or NULL.*/FUNCPTR muxAddrResFuncGet    (    long ifType,                             /* ifType from m2Lib.h */    long protocol                            /* protocol from RFC 1700 */    )    {    MUX_ADDR_REC* pNode;    if (ifType > MUX_MAX_IFTYPE)        return (NULL);    if (&addrResList[ifType] == NULL)        return (NULL);    for (pNode = (MUX_ADDR_REC *)lstFirst(&addrResList[ifType]);         pNode != NULL;          pNode = (MUX_ADDR_REC *)lstNext(&pNode->node))        {        if (pNode->protocol == protocol)            {            return (pNode->addrResFunc);            }        }    return (NULL);    }    /******************************************************************************** muxAddrResFuncDel - delete an address resolution function** This function takes an ifType (from m2Lib.h) and a protocol (from RFC 1700)* and deletes the associated address resolution routine (if such exists).** .IP <ifType>* Expects a media interface or network driver type from m2Lib.h** .IP <protocol>* Expects a network service or protocol type from RFC 1700** RETURNS: OK or ERROR.*/    STATUS muxAddrResFuncDel    (    long ifType,    /* ifType of function you want to delete */    long protocol   /* protocol from which to delete the function */    )    {    MUX_ADDR_REC* pNode;    if (ifType > MUX_MAX_IFTYPE)        return (ERROR);    if (&addrResList[ifType] == NULL)        return (ERROR);    for (pNode = (MUX_ADDR_REC *)lstFirst(&addrResList[ifType]);         pNode != NULL;          pNode = (MUX_ADDR_REC *)lstNext(&pNode->node))        {        if (pNode->protocol == protocol)            {            lstDelete (&addrResList[ifType], &pNode->node);            free (pNode);            return (OK);            }        }    return (ERROR);    }/******************************************************************************** muxDevStopAll - stop all ENDs that have been loaded into the MUX** This routine calls the "stop" entry point for all ENDs loaded into the MUX.** RETURNS: OK or ERROR** SEE ALSO* muxDevStop** NOMANUAL*/STATUS muxDevStopAll    (    )    {    END_TBL_ROW* pEndTblRow;        END_OBJ* pEnd;    /* Mutual exclusion is necessary to protect <endList> access */    semTake (muxLock, WAIT_FOREVER);        /* Each Table row contains a list of ENDs for a particular driver */    for (pEndTblRow = (END_TBL_ROW *)lstFirst(&endList); 	 pEndTblRow != NULL; 	 pEndTblRow = (END_TBL_ROW *)lstNext(&pEndTblRow->node))	{	/* Loop through all ENDs in the table row and call the stop routine */        for (pEnd = (END_OBJ *)lstFirst(&pEndTblRow->units); 	     pEnd != NULL;              pEnd = (END_OBJ *)lstNext(&pEnd->node))            {            if (pEnd->pFuncTable->stop != NULL)		{		(void) pEnd->pFuncTable->stop(pEnd->devObject.pDevice);		}	    }    	}    semGive (muxLock);    return (OK);    }

⌨️ 快捷键说明

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