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

📄 pppsioadapter.c

📁 这是全套的PPP协议的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
    if (pStackData->pfwRFC2233CountTest)       pfwInterfaceReferenceDelete(pStackData->pfwRFC2233CountPair.interfaceObj);    /* DONE processing stack Delete request*/    if (pStackData->callbacks && pStackData->callbacks->stackDeleteComplete)	{	(*pStackData->callbacks->stackDeleteComplete)				    (pStackData->callbacks ,pComponentState);	return OK;	}    else	return ERROR;    }/******************************************************************************** sioAdptrSend - SIO adapter send interface ** In here we lock access to the channel and start frame transmission.* sioAdptrSendOctet() drains the frame and relinquishes the channel when done*/LOCAL int sioAdptrSend    (    PFW_PLUGIN_OBJ_STATE * pComponentState, /* our state for this stack */    M_BLK_ID * pMblkId			    /* frame to send */    )    {    SIO_ADPTR_STACK_DATA * pStackData = 		    (SIO_ADPTR_STACK_DATA * )pComponentState->stackData;    SIO_ADPTR_PROFILE_DATA * pProfileData = 		    (SIO_ADPTR_PROFILE_DATA * )pComponentState->profileData;    M_BLK_ID pMblk;    int key;    BOOL raiseBlockedEvent = FALSE;    if (pMblkId == NULL || ((pMblk = *pMblkId) == NULL))        {        RFC2233_COUNTER_UPDATE(pStackData->pfwRFC2233CountTest, 				pStackData->pfwRFC2233CountPair,                               M2_ctrId_ifOutErrors, 1);        return ERROR;        }    else if (pStackData->lcpIsOpen == FALSE)        {        netMblkClChainFree(pMblk);        RFC2233_COUNTER_UPDATE(pStackData->pfwRFC2233CountTest,                                pStackData->pfwRFC2233CountPair,                               M2_ctrId_ifOutDiscards, 1);        return ERROR;        }    else if (pStackData->channelState != SIO_CHANNEL_UP)        {        netMblkClChainFree(pMblk);        RFC2233_COUNTER_UPDATE(pStackData->pfwRFC2233CountTest,                                pStackData->pfwRFC2233CountPair,                               M2_ctrId_ifOutDiscards, 1);        if (pProfileData->peerType == SIO_PEER_NT_SERVER &&	        (pStackData->reTransmitClientString ^= 0x1))	        {            /*             * If nextSendIndex = SIZEOF_CLIENT_STRING, pppConnectionOpen happened             * in INITIAL state,  lcpOpenHandler sent the first CLIENT string, and             * we need to retransmit. We send CLIENT 5 times maximum. If the channelBuf             * is zeroed out, pppConnectionOpen happened in STOPPED state which does             * not trigger an OPEN event, in which case, we start transmitting CLIENT.             */            key = intLock();            if (pStackData->nextSendIndex == SIZEOF_CLIENT_STRING ||                pStackData->channelBuf[0] == '\0')                {                pStackData->nextSendIndex = 0;                intUnlock(key);                bzero(pStackData->channelBuf, sizeof(pStackData->channelBuf));                strcpy(pStackData->channelBuf, SIO_NT_CLIENT_STRING);#ifdef PPP_DEBUG                logMsg("sioAdptr: re-sending CLIENT string: stackObj = 0x%x\n",                       (int)pComponentState->stackObj,2,3,4,5,6);#endif /* PPP_DEBUG */                /* start transmission of CLIENT string */                sioTxStartup(pStackData->pSioChan);                return ERROR;                }            else                intUnlock(key);            }        return ERROR;        }    if (semTake(pStackData->channelSem, WAIT_FOREVER) != OK)        {       	netMblkClChainFree(pMblk);        RFC2233_COUNTER_UPDATE(pStackData->pfwRFC2233CountTest,                                pStackData->pfwRFC2233CountPair,                               M2_ctrId_ifOutDiscards, 1);        return ERROR;        }    pMblk->mBlkHdr.mNextPkt = NULL;    /*     * the send queue is manipulated in interrupt context so we lock     * interrupts here     */    key = intLock();    if (pStackData->sendMblk == NULL)	{	/*	 * nothing is being transmitted right now so we start transmitting	 * this pMblk right away 	 */	pStackData->sendMblk = pMblk;	pStackData->nextSendIndex = 0;	intUnlock(key);	/* start transmission */	sioTxStartup(pStackData->pSioChan);	}    else	{	/* queue packet for transmission */	if (pStackData->sendQFull == FALSE)	    {	    if (pStackData->sendQHead == NULL)		{		pStackData->sendQHead = pMblk;		pStackData->sendQTail = pMblk;		}	    else		{		pStackData->sendQTail->mBlkHdr.mNextPkt = pMblk;		pStackData->sendQTail = pMblk;		}	    pStackData->sendQSize++;#ifdef PPP_DEBUG	    logMsg ("SIO_ADPTER Queued packet %p\n",(int)pMblk,2,3,4,5,6);#endif /* PPP_DEBUG */	    if (pStackData->sendQFull == FALSE &&		pStackData->sendQSize == pProfileData->maxSendQSize)		{		pStackData->sendQFull = TRUE;		raiseBlockedEvent = TRUE;		}	    intUnlock(key);	    }	else	    {	    intUnlock(key);	    netMblkClChainFree(pMblk);	    RFC2233_COUNTER_UPDATE(pStackData->pfwRFC2233CountTest, 				    pStackData->pfwRFC2233CountPair,				   M2_ctrId_ifOutDiscards, 1);	    semGive(pStackData->channelSem);#ifdef PPP_DEBUG	    logMsg ("SIO_ADPTER Dropped packet %p on full Q;sendQSize = %d\n",		    (int)pMblk, pStackData->sendQSize,3,4,5,6);#endif /* PPP_DEBUG */	    return ERROR;	    }	}    if (raiseBlockedEvent == TRUE)	{	if (pStackData->txBlockedEvent != NULL)            pfwEventRaise(pComponentState->stackObj,                          pStackData->txBlockedEvent, NULL);#ifdef PPP_DEBUG	logMsg ("SIO_ADPTER SendQ Full;sendQSize = %d\n", pStackData->sendQSize,		2,3,4,5,6);#endif /* PPP_DEBUG */	}    /*      * RFC 2233 counters's update will be carried in sioAdptrSendOctet     * which is indirectly called viat the sioTxStartup macro     */    pStackData->outputPackets ++;    pStackData->outputOctets += ((pMblk->mBlkHdr.mNext != NULL) ?				pMblk->mBlkPktHdr.len : pMblk->mBlkHdr.mLen);    /* release channel semaphore only if queuing is enabled */    if (pProfileData->maxSendQSize != 0)	semGive(pStackData->channelSem);    return OK;    }/******************************************************************************** sioAdptrStackDataShow - show SIO connection statistics***/LOCAL STATUS sioAdptrStackDataShow     (    PFW_PLUGIN_OBJ_STATE * pComponentState    )    {    return OK;    }/******************************************************************************** sioAdptrSendOctet - send next character in SIO interrupt context ***/LOCAL STATUS sioAdptrSendOctet     (    void * state,    char * octetBuf    )    {    PFW_PLUGIN_OBJ_STATE * pComponentState = (PFW_PLUGIN_OBJ_STATE *)state;    SIO_ADPTR_PROFILE_DATA * pProfileData;     SIO_ADPTR_STACK_DATA * pStackData;     SIO_ADPTR_COMPONENT * pSioComponent;     M_BLK_ID pMblk;    MODEM_DATA	* pModemData;    /* state or buffer cant be NULL */    if (pComponentState == NULL || octetBuf == NULL)	return ERROR;    pProfileData = (SIO_ADPTR_PROFILE_DATA * )pComponentState->profileData;    pStackData = (SIO_ADPTR_STACK_DATA * )pComponentState->stackData;    pSioComponent = (SIO_ADPTR_COMPONENT * )pComponentState->pluginObj;    pModemData = pStackData->pModemData;    /*      * send to the modem if the peer type itself is a modem, and     * the modem connection is down.     */    if (pProfileData->peerType == SIO_PEER_MODEM &&	!(pModemData->modemFlags & MODEM_UP))	return (sioAdptrModemSend(pComponentState, pStackData,                                  (UINT8 *)octetBuf));    /* we dont send anything if LCP is not open */    if  (FALSE == pStackData->lcpIsOpen) 	return ERROR;    /* check if we have to send NT "CLIENT/CLIENTSERVER" strings */    if (pStackData->channelState == SIO_CHANNEL_DOWN)	{	if (pProfileData->peerType == SIO_PEER_REGULAR)	    return ERROR;	/* send CLIENT/CLIENTSERVER string */	switch (pProfileData->peerType)	    {	    case SIO_PEER_NT_SERVER:		if (pStackData->nextSendIndex == SIZEOF_CLIENT_STRING)		    {		    bzero(pStackData->channelBuf,sizeof(pStackData->channelBuf));		    break;		    }		*octetBuf =pStackData->channelBuf[pStackData->nextSendIndex++];		RFC2233_COUNTER_UPDATE(pStackData->pfwRFC2233CountTest, 					pStackData->pfwRFC2233CountPair,                                       M2_ctrId_ifOutOctets, 1);               		RFC2233_COUNTER_UPDATE(pStackData->pfwRFC2233CountTest, 					pStackData->pfwRFC2233CountPair,                                       M2_ctrId_ifHCOutOctets, 1);		return OK;	    case SIO_PEER_NT_CLIENT:		if (pStackData->nextSendIndex == SIZEOF_CLIENTSERVER_STRING)		    {		    /* say that channel is UP and available */		    sioAdptrChannelAvailable (pComponentState); 		    break;		    }		*octetBuf =pStackData->channelBuf[pStackData->nextSendIndex++];		RFC2233_COUNTER_UPDATE(pStackData->pfwRFC2233CountTest, 				    pStackData->pfwRFC2233CountPair,                                       M2_ctrId_ifOutOctets, 1);               		RFC2233_COUNTER_UPDATE(pStackData->pfwRFC2233CountTest, 				    pStackData->pfwRFC2233CountPair,                                       M2_ctrId_ifHCOutOctets, 1);		return OK;	    default:		break;	    }	/* returning ERROR stops the serial device transmitter */	return ERROR;	}    else if (pStackData->channelState != SIO_CHANNEL_UP)	return ERROR;    /* we are now sending a frame */    if ((pMblk = pStackData->sendMblk) == NULL)	return ERROR;    if ( pStackData->nextSendIndex == pMblk->mBlkHdr.mLen )	{	/* get next mBlk for this frame */	if (pMblk->mBlkHdr.mNext == NULL)	    {	     /* done sending frame; OK to send next frame */	     SIO_FREE_PKT(pMblk);	     /*	      * if queueing is disabled release semaphore to allow sending of	      * next frame	      */	     if (pProfileData->maxSendQSize == 0)		 {		 pStackData->sendMblk = NULL;		 semGive(pStackData->channelSem);		 return ERROR;		 }	     if (pStackData->sendQHead == NULL)		 {		 /*		  * done sending all queued packets; setting sendMblk to NULL		  * will cause the next send to re-start the serial transmitter		  */		 pStackData->sendMblk = NULL;		 return ERROR;		 }	     else		 {		 /* get next frame from queue */		 pStackData->sendMblk = pStackData->sendQHead;		 if ((pStackData->sendQHead = 			     pStackData->sendQHead->mBlkHdr.mNextPkt) == NULL)		     {		     pStackData->sendQTail = NULL;		     }		 pMblk = pStackData->sendMblk;		 pStackData->nextSendIndex = 0;		 pStackData->sendQSize--;		 if (pStackData->sendQFull == TRUE &&		     pStackData->sendQSize ==			 SIO_SEND_Q_TWO_THIRDS_FULL (pProfileData->maxSendQSize))		    {		    pStackData->sendQFull = FALSE;		    /* raise unblocked event via dataTask */		    if (pStackData->txUnblockedEvent != NULL)			{			pfwDataJobAdd (pComponentState->pluginObj->pfwObj,				   sioAdptrRaiseTxUnblockedEvent, 				   &pComponentState,sizeof(pComponentState));			}		    }#ifdef PPP_DEBUG		logMsg ("SIO_ADPTER De-queued packet %p\n",(int)pMblk,2,3,4,5,6);#endif /* PPP_DEBUG */		 }	    }	 else	    {	    /* more bytes to send in this frame*/	    pStackData->sendMblk = pMblk->mBlkHdr.mNext;	    pStackData->nextSendIndex = 0;	    SIO_FREE_PKT(pMblk);	    pMblk = pStackData->sendMblk;	    }	}    *octetBuf = pMblk->mBlkHdr.mData[pStackData->nextSendIndex++];    RFC2233_COUNTER_UPDATE(pStackData->pfwRFC2233CountTest, 			    pStackData->pfwRFC2233CountPair,                           M2_ctrId_ifOutOctets, 1);    RFC2233_COUNTER_UPDATE(pStackData->pfwRFC2233CountTest, 			    pStackData->pfwRFC2233CountPair,                           M2_ctrId_ifHCOutOctets, 1);    return OK;    }/******************************************************************************** sioInterfaceBind - bind interfaces to the SIO adapter component** This routine binds the interfaces to the SIO adapter component.* * RETURNS: OK, always.*/LOCAL STATUS sioInterfaceBind    (    PFW_PLUGIN_OBJ * pluginObj    )    {    SIO_ADPTR_COMPONENT * pComponent = (SIO_ADPTR_COMPONENT *) pluginObj;    ADAPTER_COMPONENT_STATISTICS_INTERFACE * statisticsInterface;    PHY_PORT_INTERFACE * phyPortInterface;    PPP_MODEM_INTERFACE * pppModemInterfaceEntry;    int i;    PFW_OBJ * pfw = pluginObj->pfwObj;    sioAdapterInterfacesInit (pComponent);    if ((i = pfwInterfaceRegister(pfw, "PPP_MODEM_INTERFACE")) > 0)        {        pppModemInterfaceEntry = &pComponent->pppModemInterface;        pppModemInterfaceEntry->interfaceObj.id = i;        pppModemInterfaceEntry->interfaceObj.pluginObj =                                        (PFW_PLUGIN_OBJ *)pComponent;        pfwInterfaceBind (&pppModemInterfaceEntry->interfaceObj);        }    /* publish and bind our adapter component statistics interface */    if ((i = pfwInterfaceRegister(pfw,                      "ADAPTER_COMPONENT_STATISTICS_INTERFACE")) > 0)        {        statisticsInterface = &pComponent->statisticsInterface;        statisticsInterface->interfaceObj.id = i;        statisticsInterface->interfaceObj.pluginObj = pluginObj;        statisticsInterface->statisticsGet = sioAdptrStatisticsGet;

⌨️ 快捷键说明

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