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

📄 muxtklib.c

📁 VXWORKS源代码
💻 C
📖 第 1 页 / 共 4 页
字号:
* muxDevLoad(), is used. For the second protocol onwards a new entry is* claimed** RETURNS : muxId or NULL.* NOMANUAL*/int muxTkBibEntryGet    (    END_OBJ * pEnd	/* the END the protocol is trying to bind to */    )    {    int            multBinds = 0;    int            count = 0;    int            index = -1;    NET_PROTOCOL * pProto;   /*    * mutual exclusion begins here and we keep it till we have a valid    * BIB index     */    if (semTake (muxBibLock, WAIT_FOREVER) == ERROR)       return (-1);    /* are one or more protocols already bound to this device ? */    multBinds = lstCount (&pEnd->protocols);     /*     * KLUDGE to accomodate muxBind     */     if (multBinds == 1)	 {	 pProto = (NET_PROTOCOL *)lstFirst (&pEnd->protocols);	 if (! pProto->nptFlag)	     multBinds = 0;	 }    /*     * if this is the first protocol being registered with this device,     * we simply use search for and use the BIB slot in which the driver     * was loaded using muxDevLoad(); else we find the next available slot     * in the BIB     */      if (!multBinds)	{	for (count = 0; count < muxMaxBinds; count++)	    {	    if (STREQ(muxBindBase[count].devName, pEnd->devObject.name) &&		muxBindBase[count].unitNo == pEnd->devObject.unit)	       {	       index = count;	       break;	       }	    }	}    else        {        for (count = 0; (count < muxMaxBinds) && 		    (muxBindBase[count].pEnd != NULL); count++)		    ;	/*	 * these fields in the BIB entry need to be filled only when 	 * more than one protocol is bound to the same device	 */	if (count < muxMaxBinds)	    {	    index = count;	    /* reserve this slot for us */	    muxBindBase[index].pEnd = pEnd;	    muxBindBase[index].unitNo = pEnd->devObject.unit;	    strcpy(muxBindBase[count].devName, pEnd->devObject.name);	    if ((END_IOCTL(pEnd)(pEnd, EIOCGNPT, NULL)) == OK)		{		TK_DRV_SET(&muxBindBase[count]);		}	    else		{		TK_DRV_CLEAR(&muxBindBase[count]);		}	    }        }    /* say that a protocol has taken this slot */    muxBindBase[index].flags |= BIB_PROTO_ENTRY;    /* we have the BIB index and we are clear to release muxLock */    semGive (muxBibLock);    return (index);    }/******************************************************************************** muxTkBibEntryFill - fill and complete the BIB entry** This is a internal function called to complete the BIB entry that was* claimed using muxTkBibEntryGet()** RETURNS : muxId or NULL.* NOMANUAL*/void muxTkBibEntryFill    (    int    index,		/* BIB entry pointer */    int    netSvcType,		/* protocol that is being bound */    void * pNetCallbackId	/* protocols callback Id */    )    {    M2_INTERFACETBL mib2Tbl;    M2_ID * pM2ID;    long            netDrvType = 0;    /* get the MAC type from the END MIB table */    if (muxBindBase[index].pEnd->flags & END_MIB_2233)        {        muxIoctl(&muxBindBase[index], EIOCGMIB2233, (caddr_t)&pM2ID);        netDrvType = pM2ID->m2Data.mibIfTbl.ifType;        }    else /* (RFC1213 style counters supported) XXX */        {        muxIoctl(&muxBindBase[index], EIOCGMIB2, (caddr_t)&mib2Tbl);        netDrvType = mib2Tbl.ifType;        }    /* populate the rest of the BIB entry */    muxBindBase[index].netSvcType = netSvcType;    muxBindBase[index].netDrvType = netDrvType;    muxBindBase[index].pNetCallbackId = pNetCallbackId;    /* populate the BIB entry with the registered network service functions */    muxBindBase[index].addrResFunc = muxAddrResFuncGet (netDrvType,netSvcType);    }/******************************************************************************** muxTkBibEntryFree - free the BIB entry** This is a internal function called to free the said BIB entry** RETURNS : N/A* NOMANUAL*/LOCAL void muxTkBibEntryFree    (    MUX_ID muxId	/* BIB entry pointer */    )    {    if (muxId == NULL)	return;    /*     * we bzero the entry if it is a driver load entry and no protocols     * are bound OR if it is not a driver load entry and a protocol is     * bound at this entry     */    if (((DRV_ENTRY_CHECK(muxId) == TRUE) &&	 (PROTO_ENTRY_CHECK(muxId)== FALSE)) ||        ((DRV_ENTRY_CHECK(muxId) == FALSE) &&	 (PROTO_ENTRY_CHECK(muxId)== TRUE)))	{	bzero ((void *)muxId, sizeof(MUX_BIND_ENTRY));	}    else if ((PROTO_ENTRY_CHECK(muxId) == TRUE) && 	     (DRV_ENTRY_CHECK(muxId) == TRUE))	{	/* here we simply clean up the protocol information */    	muxId->flags &= ~BIB_PROTO_ENTRY;	muxId->addrResFunc = NULL;	muxId->netSvcType = 0;	muxId->netDrvType = 0;	muxId->pNetCallbackId = NULL;	}    }/******************************************************************************** muxTkBibShow - show the BIB entries** This is an unpublished BIB show routine ** RETURNS : N/A* NOMANUAL*/void muxTkBibShow (void)    {    int    i;    int    count = 0;    MUX_ID muxId = NULL;    for (i = 0; i < muxMaxBinds; i++)	{	if (muxBindBase[i].pEnd == NULL)	    {	    continue;	    }	else if (++count == 1)	    {	    /* print banner */	    printf("\n%5s   %8s  %8s  %8s  %8s \n", "Slot#",		    "Svc Type", "Drv Name", "Drv Unit", "DRV_ENT");	    printf("%4s   %8s  %8s  %8s  %8s \n\n", "----",		    "--------", "--------", "--------", "--------");	    }	muxId = &muxBindBase[i];	printf ("%5d  0x%x  %8s  %8d  %8s \n", i,	        (UINT)muxId->netSvcType, muxId->devName, muxId->unitNo,	        (char *)(DRV_ENTRY_CHECK(muxId) ? "DRV_ENTRY" : "    "));	}    }/* * The functions below are called by the SENS MUX API implementation to upgrade * to NPT infrastructure using the BIB *//******************************************************************************** muxTkBibInit - Initialize the BIB** This initializes the MUX BIB used by NPT to store binding information. This* routine also initializes the list to store the MUX service functions. ** Note: This routine is called by muxLibInit()** RETURNS: OK  or ERROR* NOMANUAL*/STATUS muxTkBibInit (void)    {    int count;    if (muxBibLock != NULL)	return (OK);    muxBibLock = semBCreate (SEM_Q_PRIORITY, SEM_FULL);    if (muxBibLock == NULL)	return (ERROR);    /* allocate the BIB table */    muxBindBase = (MUX_ID) KHEAP_ALLOC(muxMaxBinds * sizeof (MUX_BIND_ENTRY));    if (muxBindBase == NULL)	return (ERROR);    /* Initialize the BIB table */    for (count = 0; count < muxMaxBinds; count++)        bzero ((char*) &muxBindBase[count], sizeof(MUX_BIND_ENTRY));    return (OK);    }/********************************************************************************* muxTkDevLoadUpdate - Hook routine called from muxDevLoad** This is called from muxDevLoad() to load the driver into the BIB.* The driver is queried for NPT/END mode of operation and the receive* routine in the END_OBJ is set accordingly.** RETURNS: muxId or NULL.* NOMANUAL*/void * muxTkDevLoadUpdate    (    END_OBJ * pEnd    )    {    int count = 0;  /* index for BIB */    if (pEnd == NULL)        return (NULL);    /* Take the Bib semaphore and create an Entry in the BIB table */    semTake (muxBibLock, WAIT_FOREVER);    while ( (muxBindBase[count].pEnd != NULL) && (count < muxMaxBinds))	{	count++;	}    semGive (muxBibLock);    if (count == muxMaxBinds)        return (NULL);    muxBindBase[count].unitNo = pEnd->devObject.unit;    strcpy (muxBindBase[count].devName, pEnd->devObject.name);    muxBindBase[count].pEnd = pEnd;    muxBindBase[count].flags = BIB_DRV_ENTRY;    /* set the toolkit flag and the MUX receive routine  */    if ((END_IOCTL(pEnd)(pEnd, EIOCGNPT, NULL)) == OK)        {        TK_DRV_SET(&muxBindBase[count]);        pEnd->receiveRtn = (FUNCPTR)muxTkReceive;        }    else        {        TK_DRV_CLEAR(&muxBindBase[count]);        pEnd->receiveRtn = (FUNCPTR)muxReceive;        }    return (&muxBindBase[count]);    }/********************************************************************************* muxTkUnbindUpdate - free the BIB entry upon unbind** This routine is called by muxUnbind()** RETURNS : N/A* NOMANUAL*/void muxTkUnbindUpdate    (    void * pCookie	/* bind cookie */    )    {    MUX_ID muxId = (MUX_ID) pCookie;    muxTkBibEntryFree (muxId);    }/********************************************************************************* muxTkBindUpdate - Hook routine is called from muxBind** This hook is called from muxBind() to update the BIB introduced by NPT* Finds an entry in the mux BIB and fills in the relevant information** RETURNS : muxId or NULL.* NOMANUAL*/void * muxTkBindUpdate    (    END_OBJ *      pEnd,	/* the END being bound to */    NET_PROTOCOL * pProto	/* the protocol node added to the END */    )    {    int    index          = -1;    BOOL   tkFlag         = FALSE;    int    netSvcType     = 0;    void * pNetCallbackId = NULL;    if (pEnd == NULL)        return (NULL);    /* find and get a BIB entry */    if ((index = muxTkBibEntryGet (pEnd)) < 0)	return (NULL);    else	{	if ((tkFlag = TK_DRV_CHECK(&muxBindBase[index])) == TRUE)	    {	    /*	     * cannot bind to a NPT driver using muxBind; free BIB entry	     * and return	     */            muxTkBibEntryFree (&muxBindBase[index]);	    return (NULL);	    }	}    if (pProto != NULL)	{	netSvcType = pProto->type;	pNetCallbackId = pProto->pSpare;	muxBindBase[index].netStackRcvRtn = pProto->stackRcvRtn;	}    /* complete the BIB entry */    muxTkBibEntryFill (index, netSvcType,pNetCallbackId);    return (&muxBindBase[index]);    }/******************************************************************************** muxTkUnloadUpdate - delete the entries in the BIB** This hook is called from muxDevUnload() when a device is being unloaded and* the corresponding entry in the BIB is to be removed** RETURNS STATUS* NOMANUAL*/STATUS muxTkUnloadUpdate    (    END_OBJ * pEnd    )    {    int  count = 0;     /* index */    BOOL error = FALSE;    /* delete the corresponding entry in the BIB table */    semTake (muxBibLock, WAIT_FOREVER);     for (count = 0; count < muxMaxBinds; count++)        {        /* commented out since T2 NPT	if (STREQ(muxBindBase[count].devName, pEnd->devObject.name) &&	    muxBindBase[count].unitNo==pEnd->devObject.unit &&	    (DRV_ENTRY_CHECK(&muxBindBase[count]) == TRUE))	*/	if (muxBindBase[count].pEnd == pEnd)	    {	    if (muxBindBase[count].netSvcType == MUX_PROTO_OUTPUT)		muxTkBibEntryFree(&muxBindBase[count]);	    if (DRV_ENTRY_CHECK(&muxBindBase[count]) == TRUE)		{		muxTkBibEntryFree (&muxBindBase[count]);		error = TRUE;		}	    }        }     semGive (muxBibLock);    return (error);    }

⌨️ 快捷键说明

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