?? pppsioadapter.c
字號:
pfwInterfaceBind (&statisticsInterface->interfaceObj); } /* publish and bind our physical port interface */ if ((i = pfwInterfaceRegister(pfw, "PHY_PORT_INTERFACE")) > 0) { phyPortInterface = &pComponent->phyPortInterface; phyPortInterface->interfaceObj.id = i; phyPortInterface->interfaceObj.pluginObj = pluginObj; phyPortInterface->portNumberGet = sioAdptrPortNumberGet; phyPortInterface->portTypeGet = sioAdptrPortTypeGet; pfwInterfaceBind (&phyPortInterface->interfaceObj); } return (OK); }/***************************************************************************** sioAdapterInterfacesInit - initialize the interfaces for the SIO adapter* * This routine initializes the interfaces for the SIO adapter.** RETURNS: N/A.*/LOCAL void sioAdapterInterfacesInit ( SIO_ADPTR_COMPONENT * sioComponent ) { PPP_MODEM_INTERFACE * pModemInterface; pModemInterface = &sioComponent->pppModemInterface; pModemInterface->modemRead = pppSioAdapterModemRead; pModemInterface->modemWrite = pppSioAdapterModemWrite; pModemInterface->modemIoctl = pppSioAdapterModemIoctl; pModemInterface->modemOpen = pppSioAdapterModemOpen; pModemInterface->modemClose = pppSioAdapterModemClose; return; }/***************************************************************************** sioAdptrModemReceive - receive a string from a modem** This routine receives a string from a modem.** RETURNS: OK on success, ERROR otherwise*/LOCAL STATUS sioAdptrModemReceive ( SIO_ADPTR_STACK_DATA * pStackData, UINT8 octet ) { MODEM_DATA * pModemData = pStackData->pModemData; if (pModemData->inBufCount >= MODEM_MAX_RX_STR_LEN) { logMsg ("modem: too many characters \n", 0, 0, 0, 0, 0, 0); pModemData->inBufCount = 0; return (ERROR); } pModemData->inBuf [pModemData->inBufCount++] = octet; MODEM_READ_SEM_GIVE; return (OK); }/***************************************************************************** sioAdptrModemSend - receive a string from a modem** This routine receives a string from a modem.** RETURNS: OK on success, ERROR otherwise*/LOCAL STATUS sioAdptrModemSend ( PFW_PLUGIN_OBJ_STATE * state, SIO_ADPTR_STACK_DATA * pStackData, UINT8 * octet ) { MODEM_DATA * pModemData = pStackData->pModemData; if (pModemData->outBufLen <= pModemData->outBufCount) { return (ERROR); } *octet = pModemData->outBuf [pModemData->outBufCount++]; return (OK); }/******************************************************************************** sioAdptrReceiveOctet - Receive next character in SIO interrupt context ***/LOCAL STATUS sioAdptrReceiveOctet ( void * state, UINT8 octet ) { PFW_PLUGIN_OBJ_STATE * pComponentState = (PFW_PLUGIN_OBJ_STATE *)state; SIO_ADPTR_PROFILE_DATA * pProfileData; SIO_ADPTR_STACK_DATA * pStackData; SIO_RECEIVE_JOB receiveJob; M_BLK_ID pMblk; MODEM_DATA * pModemData = NULL; if (pComponentState == NULL) return ERROR; pProfileData = (SIO_ADPTR_PROFILE_DATA *)pComponentState->profileData; pStackData = (SIO_ADPTR_STACK_DATA *)pComponentState->stackData; RFC2233_COUNTER_UPDATE(pStackData->pfwRFC2233CountTest, pStackData->pfwRFC2233CountPair, M2_ctrId_ifInOctets, 1); RFC2233_COUNTER_UPDATE(pStackData->pfwRFC2233CountTest, pStackData->pfwRFC2233CountPair, M2_ctrId_ifHCInOctets, 1); pModemData = pStackData->pModemData; /* * receive from 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 (sioAdptrModemReceive (pStackData, octet)); /* we dont receive anything if LCP is not open */ if (FALSE == pStackData->lcpIsOpen) return ERROR; /* if the link is not UP yet we need to check for CLIENT/SERVER handshaking*/ if (pStackData->channelState == SIO_CHANNEL_DOWN) { if (pProfileData->peerType == SIO_PEER_REGULAR) return ERROR; /* Receive CLIENT/CLIENTSERVER string */ switch (pProfileData->peerType) { case SIO_PEER_NT_SERVER: if (pStackData->nextReceiveIndex == (SIZEOF_CLIENTSERVER_STRING - 1)) { pStackData->channelBuf[pStackData->nextReceiveIndex] =octet; if (strncmp(pStackData->channelBuf,SIO_NT_CLIENTSERVER_STRING, SIZEOF_CLIENTSERVER_STRING)) { bzero(pStackData->channelBuf,sizeof(pStackData->channelBuf)); pStackData->nextReceiveIndex = 0; return ERROR; } pStackData->nextReceiveIndex++; /* say that channel is UP and available */ sioAdptrChannelAvailable (pComponentState); return OK; } else if (pStackData->nextReceiveIndex > SIZEOF_CLIENTSERVER_STRING) { return OK; } break; case SIO_PEER_NT_CLIENT: if (pStackData->nextReceiveIndex == (SIZEOF_CLIENT_STRING - 1)) { pStackData->channelBuf[pStackData->nextReceiveIndex] = octet; if (strncmp (pStackData->channelBuf,SIO_NT_CLIENT_STRING, SIZEOF_CLIENT_STRING)) { bzero(pStackData->channelBuf,sizeof(pStackData->channelBuf)); pStackData->nextReceiveIndex = 0; return ERROR; } pStackData->nextReceiveIndex++; /* initiate sending of CLIENTSERVER string */ SIO_SEND_NT_CLIENTSERVER_STRING(pStackData); return OK; } else if (pStackData->nextReceiveIndex > SIZEOF_CLIENT_STRING) { return OK; } break; default: return ERROR; } pStackData->channelBuf[pStackData->nextReceiveIndex++] = octet; /* we are looking for CLIENT or CLIENTSERVER, drop extraneous characters */ if (pStackData->channelBuf[0] != 'C') pStackData->nextReceiveIndex = 0; return OK; } /* link is UP and we are receiving frames */ /* * check for buffer overflow; always accept frames of length less than * or equal to twice SIO_DEFAULT_MAX_MRU i.e.; 2 x 1500. * if frame length is greater than ( 2 x 1500) then use negotiated * local MRU times two as the upper limit */ if ((pStackData->nextReceiveIndex > (SIO_DEFAULT_MAX_MRU << 1)) && (pStackData->nextReceiveIndex > (pStackData->localMru << 1))) { SIO_DROP_RCV_FRAME(pStackData); /* this discards the remainder of large frame */ pStackData->nextReceiveIndex = 0; return OK; } /* check if we have a buffer */ if (pStackData->receiveChain == NULL) { if (octet != SIO_FRAME_FLAG) { /* in mid-frame: don't try to get a new mbuf just yet */ return ERROR; } /* try to get a buffer now */ SIO_GET_FIRST_RCV_BUF(pStackData); } /* get current receive buffer */ if ((pMblk = pStackData->receiveMblk) == NULL) { return ERROR; } /* check for very first frame start flag (0x7e)*/ if (octet != SIO_FRAME_FLAG && pStackData->nextReceiveIndex == 0) return ERROR; /* received first 0x7e */ if (octet == SIO_FRAME_FLAG && pStackData->nextReceiveIndex == 0) { pStackData->nextReceiveIndex = 1; return OK; } /* drop redundant 0x7e s */ if (octet == SIO_FRAME_FLAG && pStackData->nextReceiveIndex == 1) { return OK; } /* check if we need another mBlk-clBlk-cluster (mbuf) */ if (pMblk->mBlkHdr.mLen == SIO_CLUSTER_SIZE) { M_BLK_ID pNextMblk; if ((pNextMblk = netTupleGet(pStackData->netPoolId,SIO_CLUSTER_SIZE, M_DONTWAIT, MT_DATA ,TRUE)) == NULL) { logMsg("sioAdptrReceiveOctet:Failed to get next receive mBlk for Stack Id %d\n", pfwStackIdGet(pComponentState->stackObj),2,3,4,5,6); SIO_DROP_RCV_FRAME(pStackData); return ERROR; } pNextMblk->mBlkHdr.mLen = 0; pNextMblk->mBlkHdr.mFlags &= ~M_PKTHDR; pNextMblk->mBlkPktHdr.len = 0; pStackData->receiveMblk = pNextMblk; pMblk->mBlkHdr.mNext = pNextMblk; pMblk = pMblk->mBlkHdr.mNext; } if (octet == SIO_FRAME_FLAG) { if ((pStackData->nextReceiveIndex > 1) && (pStackData->nextReceiveIndex < SIO_MIN_FRAME_LEN)) { logMsg ("sioAdptrReceiveOctet: dropping tiny frame (%d bytes)\n", pStackData->nextReceiveIndex, 0, 0, 0, 0, 0); /* invalid frame */ SIO_DROP_RCV_FRAME(pStackData); return OK; } if (pStackData->nextReceiveIndex >= SIO_MIN_FRAME_LEN) { /* save last octet */ pMblk->mBlkHdr.mData[pMblk->mBlkHdr.mLen++] = octet; /* end of frame; set up receive job */ receiveJob.state = pComponentState; receiveJob.pMblk = pStackData->receiveChain; /* set packet length (used by sioAdptrFrameReceive) */ receiveJob.pMblk->mBlkPktHdr.len=++pStackData->nextReceiveIndex; /* check for chain of mBlks */ if (receiveJob.pMblk->mBlkHdr.mNext != NULL) { /* update packet chain length */ receiveJob.pMblk->mBlkHdr.mFlags |= M_PKTHDR; } /* get initial buffer for next frame */ SIO_GET_FIRST_RCV_BUF(pStackData); pStackData->nextReceiveIndex = 1; /* send frame up */ if (pfwDataJobAdd (pComponentState->pluginObj->pfwObj, sioAdptrFrameReceive, &receiveJob,sizeof(receiveJob)) != OK) { logMsg ("sioAdptrReceiveOctet: pfwDataJobAdd failed.\n", 0, 0, 0, 0, 0, 0); SIO_FREE_PKT_CHAIN (receiveJob.pMblk); } return OK; } #if 0 /* else begining of frame */ pMblk->mBlkHdr.mLen = 0; pStackData->nextReceiveIndex = 0; #endif } /* save octet */ pMblk->mBlkHdr.mData[pMblk->mBlkHdr.mLen++] = octet; pStackData->nextReceiveIndex++; return OK; }/******************************************************************************** sioAdptrChannelAvailable - mark channel available***/LOCAL void sioAdptrChannelAvailable ( PFW_PLUGIN_OBJ_STATE * pComponentState ) { SIO_ADPTR_STACK_DATA * pStackData; SIO_ADPTR_PROFILE_DATA *pProfileData; if (pComponentState == NULL) return; pStackData = (SIO_ADPTR_STACK_DATA * )pComponentState->stackData; pProfileData = (SIO_ADPTR_PROFILE_DATA * )pComponentState->profileData; /* get an initial receive buffer */ if (pStackData->receiveChain == NULL) SIO_GET_FIRST_RCV_BUF(pStackData); /* channel is now available */ pStackData->channelState = SIO_CHANNEL_UP; pStackData->nextSendIndex = 0; pStackData->nextReceiveIndex = 0; semGive(pStackData->channelSem);#ifdef PPP_DEBUG logMsg("sioAdptr: CHANNEL %d AVAILABLE: stackObj = 0x%x\n", pProfileData->channelNum,(int)pComponentState->stackObj,3,4,5,6);#endif /* PPP_DEBUG */ }/******************************************************************************** sioAdptrRaiseTxUnblockedEvent - say that we have space on the send queue** Raises the PPP_SUB_LAYER_TX_UNBLOCKED event*/LOCAL void sioAdptrRaiseTxUnblockedEvent ( void * data ) { PFW_PLUGIN_OBJ_STATE ** ppComponentState = data; PFW_PLUGIN_OBJ_STATE * pComponentState = *ppComponentState; SIO_ADPTR_STACK_DATA * pStackData; #ifdef PPP_DEBUG logMsg ("sioAdptrRaiseTxUnblockedEvent:pComponentState = %p\n", (int)pComponentState,2,3,4,5,6);#endif /* PPP_DEBUG */ if (pComponentState == NULL) return;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -