📄 pppsioadapter.c
字号:
/* pppSioAdapter.c - PPP over raw serial *//* Copyright 2003 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02g,14may03,ijm fixed diab compiler warning02f,07apr03,ijm fix for SPR#71047, pppSioAdapterModemRead response input buffer index not incremented; removed double free of pModemData in sioStackDel; in sioAdptrChannelAvailable get buffer only if receiveChain is NULL02e,03mar03,ijm SPR#86148, free packet if pfwReceive returns ERROR02d,09dec02,ijm fix for SPR#84845, cannot reconnect to Windows client/server 02c,14nov02,ijm add check for SIO_PEER_MODEM in ntSerialClientStringSetup, fix for SPR#8416202b,01nov02,ijm removed redundant RFC2233 counter update in sioAdptrModemSend()02a,29oct02,ijm added WIN_SERVER AND WIN_CLIENT parameters01z,28may02,rvr fixed build warnings 01y,13feb02,ijm corrected unused variables compiler warning in lcpDownHandler01x,29oct01,ijm Fixed SPR#70122: after authentication failure, link cannot re-establish serial connection to NT.01w,07mar01,ijm pComponent should be freed with pfwFree, if ERROR, in sioAdapterCreate01v,02mar01,ijm added LCP_CLOSE_EVENT handler deleted sioAdptrMutex when component is deleted01u,20feb01,ijm added check for NULL sendQHead in lcpDownHandler 01t,17dec00,ihw initialize mBlk Headers thoroughly upon netTupleGet + misc fixes01s,16nov00,sj Queue packets on send path01r,26oct00,sj on failure of SIO_GET_FIRST_RCV_BUF set stack->receiveMblk = NULL01q,29sep00,sj Merging in and reorganizing RFC2233 instrumentation01p,29sep00,sj merging with TOR2_0-WINDNET_PPP-CUM_PATCH_201o,08sep00,sj free received frame if pfwDataJobAdd fails01n,10aug00,adb fixed NT client dial-up01m,02aug00,adb Merging in LAC modifications01l,01aug00,adb Merging with openstack view except RFC 223301k,28jul00,md sets ppp attributes to a default value01j,18jul00,bsn Added Statistics and Port Interface01i,29jun00,md subscribed COLLECT_PPP_ATTRIBUTES_EVENT01h,20apr00,cn added support for PPP_MODEM_INTERFACE.01g,20mar00,sj free held buffer on CHANNEL DOWN01f,02mar00,sj always accept frames of size less than or equal to 2 x 150001e,29feb00,sj set receiveChain nextMblk to NULL after dropping frame01d,16dec99,sj call sioChannelAvailable in interrupt context01c,13dec99,sj fixing NT client/server mode; listen for LCP OPEN/DOWN events01b,09nov99,sj adding use of LCP interface to get MRU01a,02sep99,sj created*//*DESCRIPTIONThis component enables PPP sessions over serial devices using WRS SIO driverINCLUDE FILES: sioLib.h SEE ALSO*//* includes */#include "vxWorks.h"#include "logLib.h"#include "stdio.h"#include "stdlib.h"#include "string.h"#include "ctype.h"#include "memLib.h"#include "semLib.h"#include "sysLib.h"#include "intLib.h"#include "net/mbuf.h"#include "netBufLib.h"#include "pfw/pfw.h"#include "pfw/pfwStack.h"#include "pfw/pfwLayer.h"#include "pfw/pfwEvent.h"#include "pfw/pfwInterface.h"#include "pfw/pfwMemory.h"#include "ppp/kppp.h"#include "ppp/pppLacStructures.h"#include "pfw/pfwComponent.h"#include "ppp/pppSioAdapter.h"#include "ppp/interfaces/lcpInterfaces.h"#include "ppp/interfaces/pppModemInterface.h"#include "ppp/interfaces/pppInterfacesGroupInterfaces.h"#include "ppp/interfaces/adapterComponentInterfaces.h"#include "limits.h"#include "tickLib.h"/* defines */#define MODEM_MAX_RX_STR_LEN 256 /* max rx string lenght */#define MODEM_MAX_TX_STR_LEN 256 /* max tx string lenght */#define SIO_FREE_PKT_CHAIN netMblkClChainFree#define SIO_FREE_PKT netMblkClFree#define SIO_CLUSTER_SIZE 2048#define SIO_DEFAULT_MAX_MRU 1500#define SIO_MIN_FRAME_LEN 5 /* 0x7E + compressed protocol + 2 byte CRC + 0x7E */#define SIO_CHANNEL_DOWN 0x0#define SIO_CHANNEL_UP 0x1#define SIO_PEER_REGULAR 0x0 /* other end is a regular(NON NT) machine */#define SIO_PEER_NT_SERVER 0x1 /* other end is a NT server */#define SIO_PEER_NT_CLIENT 0x2 /* other end is a NT client */#define SIO_PEER_MODEM 0x4 /* other end is a modem */#define SIO_FRAME_FLAG 0x7e#define SIO_NT_CLIENT_STRING "CLIENT"#define SIO_NT_CLIENTSERVER_STRING "CLIENTSERVER"#define SIZEOF_CLIENT_STRING 6#define SIZEOF_CLIENTSERVER_STRING 12#define SIO_SEND_Q_DEFAULT_SIZE 15 /* arbitrarily chosen */#define SIO_SEND_Q_TWO_THIRDS_FULL(n) ((n << 1)/3)#define SIO_DROP_RCV_FRAME(stack) \ {\ /* drop the frame; free all mBufs except the first one in the chain */\ \ if (stack->receiveChain != NULL )\ {\ stack->receiveChain->mBlkHdr.mLen = 1;\ stack->nextReceiveIndex = 1;\ \ if (stack->receiveChain->mBlkHdr.mNext != NULL) \ {\ SIO_FREE_PKT_CHAIN(stack->receiveChain->mBlkHdr.mNext);\ stack->receiveChain->mBlkHdr.mNext = NULL; \ stack->receiveChain->mBlkHdr.mFlags &= ~M_PKTHDR;\ stack->receiveChain->mBlkPktHdr.len = 0;\ }\ }\ stack->receiveMblk = stack->receiveChain;\ stack->receiveMblk->mBlkHdr.mData[0] = SIO_FRAME_FLAG;\ }#define SIO_GET_FIRST_RCV_BUF(stack) \ {\ if ((stack->receiveChain = netTupleGet(stack->netPoolId,\ SIO_CLUSTER_SIZE,\ M_DONTWAIT, MT_DATA,TRUE)) == NULL)\ {\ stack->receiveMblk = NULL;\ logMsg("sioAdptr:Failed to get receive buffer for channel Id %d\n",\ stack->channelNum,2,3,4,5,6);\ }\ else\ {\ stack->receiveMblk = stack->receiveChain;\ stack->receiveMblk->mBlkHdr.mData[0] = SIO_FRAME_FLAG;\ stack->receiveMblk->mBlkHdr.mLen = 1;\ stack->receiveMblk->mBlkHdr.mFlags &= ~M_PKTHDR;\ stack->receiveMblk->mBlkPktHdr.len = 1;\ }\ }#define SIO_SEND_NT_CLIENTSERVER_STRING(stack)\ {\ /* setup the string to send */\ \ bzero (stack->channelBuf, sizeof(stack->channelBuf));\ strcpy(stack->channelBuf, SIO_NT_CLIENTSERVER_STRING);\ \ /* start transmission */\ \ stack->nextSendIndex = 0;\ sioTxStartup(stack->pSioChan);\ }#define MODEM_READ_SEM_CREATE \ if ((pModemData->modemReadSyncSem = semBCreate (SEM_Q_FIFO, SEM_EMPTY))\ == NULL) \ return (ERROR) #define MODEM_READ_SEM_DELETE \ if ((pModemData->modemReadSyncSem) != NULL) \ semDelete (pModemData->modemReadSyncSem) #define MODEM_READ_SEM_GIVE \ (semGive (pModemData->modemReadSyncSem)) /* typedefs */typedef struct sioAdptrParams { char * name; PFW_PARAMETER_HANDLER handler; } SIO_ADPTR_PARAMS;typedef struct sioProfileData { UINT32 channelNum; /* serial channel number */ UINT32 baudRate; /* baud rate to use on this channel */ UINT32 maxSendQSize;/* max outbound packets that we will queue */ UINT32 peerType; /* WIN_SERVER, WIN_CLIENT, REGULAR */ }SIO_ADPTR_PROFILE_DATA;typedef struct modemData { char inBuf [MODEM_MAX_RX_STR_LEN]; char rspBuf [MODEM_MAX_RX_STR_LEN]; UINT inBufCount; UINT rspBufCount; UINT rspBufOffset; char outBuf [MODEM_MAX_TX_STR_LEN]; UINT outBufCount; UINT outBufLen; SEM_ID modemReadSyncSem; int modemFlags; } MODEM_DATA;typedef struct sioStackData { UINT32 channelNum; /* serial channel number */ SEM_ID channelSem; /* channel access control */ UINT32 channelState; /* state of channel */ UINT32 localMru; /* receive MRU */ UINT32 remoteMru; /* MTU */ UINT32 nextSendIndex; /* index to next octet to send */ UINT32 nextReceiveIndex;/* index to next octet to receive */ UINT inputOctets; /* octets received */ UINT outputOctets; /* octets sent */ UINT inputPackets; /* packets received */ UINT outputPackets; /* packets sent */ char channelBuf[16]; /* buffer for WinNT CLIENTSERVER string */ NET_POOL_ID netPoolId; /* netPool from which to allocate frames */ M_BLK_ID sendQHead; /* Head of send Queue */ M_BLK_ID sendQTail; /* Tail of send Queue */ UINT32 sendQSize; /* Number of packets on send Queue */ BOOL sendQFull; /* when TRUE no packets are queued */ M_BLK_ID sendMblk; /* current Mblk that we are sending */ M_BLK_ID receiveChain;/* head mBuf of frame we are currently receiving */ M_BLK_ID receiveMblk; /* mbuf in to which we are currenty receiving */ SIO_CHAN * pSioChan; /* channel control structure */ PFW_EVENT_OBJ * lcpUpEvent; PFW_EVENT_OBJ * lcpOpen; /* PPP connection open initiated */ PFW_EVENT_OBJ * lcpDown; /* PPP connection closed */ PFW_EVENT_OBJ * lcpClose; /* PPP administrative close */ PFW_EVENT_OBJ * txBlockedEvent; PFW_EVENT_OBJ * txUnblockedEvent; PFW_INTERFACE_STATE_PAIR pppLinkStatusInterface; PFW_PLUGIN_OBJ_CALLBACKS * callbacks;/* framework add and delete callbacks*/ PFW_EVENT_OBJ *collectPppAttributesEvent; MODEM_DATA * pModemData; /* modem data */ BOOL lcpIsOpen; UINT32 reTransmitClientString; /* auxiliary variables aiding RFC 2233 counters's implementation */ int pfwAuxIfId; PFW_INTERFACE_STATE_PAIR pfwRFC2233CountPair; BOOL pfwRFC2233CountTest; }SIO_ADPTR_STACK_DATA;typedef struct sioComponent { PFW_COMPONENT_OBJ component; /* SIO framework component */ SEM_ID sioAdptrMutex; /* channel Map access control */ PFW_PLUGIN_OBJ_STATE ** channelMap; /* map of available/used channels */ PPP_MODEM_INTERFACE pppModemInterface; ADAPTER_COMPONENT_STATISTICS_INTERFACE statisticsInterface; PHY_PORT_INTERFACE phyPortInterface; }SIO_ADPTR_COMPONENT;typedef STATUS (*SIO_FUNCPTR) (void *,...); /* for sioLib */LOCAL STATUS sioAdptrModemSend (PFW_PLUGIN_OBJ_STATE * state, SIO_ADPTR_STACK_DATA * pStackData, UINT8 * pOctet);LOCAL STATUS sioAdptrModemReceive (SIO_ADPTR_STACK_DATA * pStackData, UINT8 octet);LOCAL STATUS pppSioAdapterModemIoctl (PFW_PLUGIN_OBJ_STATE * pSioState, int cmd, int arg);LOCAL STATUS pppSioAdapterModemClose (PFW_PLUGIN_OBJ_STATE * pSioState);LOCAL STATUS pppSioAdapterModemOpen (PFW_PLUGIN_OBJ_STATE * pSioState);LOCAL STATUS sioAdapterModemFlush (PFW_PLUGIN_OBJ_STATE * pSioState);LOCAL STATUS sioAdapterModemBringDown (PFW_PLUGIN_OBJ_STATE * pSioState);LOCAL STATUS sioAdapterModemBringUp (PFW_PLUGIN_OBJ_STATE * pSioState);LOCAL STATUS pppSioAdapterModemRead (PFW_PLUGIN_OBJ_STATE * pSioState, char * rsp, UINT rspLen, UINT timeout);LOCAL STATUS pppSioAdapterModemWrite (PFW_PLUGIN_OBJ_STATE * pSioState, char * cmd, UINT cmdLen);LOCAL void sioAdapterInterfacesInit (SIO_ADPTR_COMPONENT * sioComponent);LOCAL STATUS sioInterfaceBind (PFW_PLUGIN_OBJ * pluginObj);typedef struct sioReceiveJob { PFW_PLUGIN_OBJ_STATE * state; M_BLK_ID pMblk; }SIO_RECEIVE_JOB;/* forward declarations */ /* parameter handlers */LOCAL STATUS sio_channelNum (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE,void *, char *);LOCAL STATUS sio_baudRate (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE,void *, char *);LOCAL STATUS sio_maxSendQSize (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE,void *, char *);LOCAL STATUS sio_peerType (PFW_OBJ *, PFW_PARAMETER_OPERATION_TYPE,void *, char *); /* component interfaces */LOCAL STATUS sioAdptrProfileDataConstruct (PFW_OBJ * ,void *);LOCAL STATUS sioAdptrStackDataConstruct (PFW_OBJ * ,void *stackData, void * profileData);LOCAL STATUS sioAdptrStackDataDestruct (PFW_OBJ * ,void *stackData, void * profileData);LOCAL STATUS sioAdptrStackAdd(PFW_PLUGIN_OBJ_STATE *,PFW_PLUGIN_OBJ_CALLBACKS*);LOCAL STATUS sioAdptrStackDel(PFW_PLUGIN_OBJ_STATE *);LOCAL STATUS sioAdptrSend (PFW_PLUGIN_OBJ_STATE *, M_BLK_ID *);LOCAL STATUS sioAdptrStackDataShow (PFW_PLUGIN_OBJ_STATE *); /* SIO callbacks */LOCAL STATUS sioAdptrSendOctet (void * state, char * octetBuf);LOCAL STATUS sioAdptrReceiveOctet (void * state, UINT8 data); /* Event handler */LOCAL STATUS lcpOpenHandler (PFW_PLUGIN_OBJ_STATE *, void *eventData); LOCAL STATUS lcpDownHandler (PFW_PLUGIN_OBJ_STATE *, void *eventData); LOCAL STATUS lcpCloseHandler (PFW_PLUGIN_OBJ_STATE *, void *eventData);LOCAL STATUS lcpUpEventHandler (PFW_PLUGIN_OBJ_STATE *, void *eventData); LOCAL STATUS sioChannelIDConnectSpeedEventHandler ( PFW_PLUGIN_OBJ_STATE * state, void *eventData ); /* misc */LOCAL void sioAdptrChannelAvailable (PFW_PLUGIN_OBJ_STATE *);LOCAL void sioAdptrFrameReceive (void *);LOCAL void sioAdptrRaiseTxUnblockedEvent (void *);LOCAL void sioAdptrStatisticsGet (PFW_PLUGIN_OBJ_STATE *, UINT *, UINT *, UINT *, UINT *);LOCAL UINT sioAdptrPortNumberGet (PFW_PLUGIN_OBJ_STATE *);LOCAL UINT sioAdptrPortTypeGet (PFW_PLUGIN_OBJ_STATE *);LOCAL void flushSioTransmitQueue (PFW_PLUGIN_OBJ_STATE *, void *eventData);LOCAL STATUS ntSerialClientStringSetup (PFW_PLUGIN_OBJ_STATE *, void *eventData);/* locals *//* component configuration parameters */LOCAL SIO_ADPTR_PARAMS sioAdptrParams[]={{"sio_channelNum",sio_channelNum}, {"sio_baudRate", sio_baudRate}, {"sio_maxSendQSize", sio_maxSendQSize}, {"sio_peerType", sio_peerType}};LOCAL int numSioAdptrParams = NELEMENTS (sioAdptrParams);/******************************************************************************** sioAdapterCreate - initialize and add the SIO adapter to the framework** This component faciliates PPP over SIO model serial drivers. The parameter* numSioChannels specifies the number of serial channel IDs that may be * obtained using sysSerialChanGet().*/STATUS sioAdapterCreate ( PFW_OBJ * pfw, /* framework */ UINT32 numSioChannels /* number of channels */ ) { int i = 0; SIO_ADPTR_COMPONENT *pComponent; PFW_PLUGIN_OBJ * sioAdptrPluginObj = NULL; if (pfw == NULL || numSioChannels <= 0) { return ERROR; } /* allocate the component object */ if ( (pComponent = pfwMalloc(pfw,sizeof(SIO_ADPTR_COMPONENT))) == NULL) return ERROR; bzero((void *)pComponent,sizeof(SIO_ADPTR_COMPONENT)); if ((pComponent->sioAdptrMutex = semMCreate(SEM_Q_PRIORITY)) == NULL) { pfwFree(pComponent); } sioAdptrPluginObj = (PFW_PLUGIN_OBJ *)&(pComponent->component); /* initialize our component object */ bzero(sioAdptrPluginObj->name, PFW_MAX_NAME_LENGTH); strncpy(sioAdptrPluginObj->name,"SIO_ADAPTER", (PFW_MAX_NAME_LENGTH -1)); sioAdptrPluginObj->pfwObj = pfw; sioAdptrPluginObj->profileDataSize = sizeof (SIO_ADPTR_PROFILE_DATA); sioAdptrPluginObj->stackDataSize = sizeof (SIO_ADPTR_STACK_DATA); sioAdptrPluginObj->profileDataConstruct = sioAdptrProfileDataConstruct; sioAdptrPluginObj->profileDataCopy = NULL; sioAdptrPluginObj->profileDataDestruct = NULL; sioAdptrPluginObj->stackDataConstruct = sioAdptrStackDataConstruct; sioAdptrPluginObj->stackDataDestruct = sioAdptrStackDataDestruct; sioAdptrPluginObj->receive = NULL; sioAdptrPluginObj->send = sioAdptrSend; sioAdptrPluginObj->stackAdd = sioAdptrStackAdd; sioAdptrPluginObj->stackDelete = sioAdptrStackDel; sioAdptrPluginObj->stackDataShow = sioAdptrStackDataShow; sioAdptrPluginObj->interfaceBind = sioInterfaceBind; pComponent->component.protocol = 0; pComponent->component.layerObj = pfwLayerObjGet(pfw, "ADAPTER_LAYER"); /* register this component with the framework */ if (pfwComponentAdd (&pComponent->component) == ERROR) { logMsg ("sioAdpterCreate: Could not add SIO ADAPTER component\n", 1,2,3,4,5,6); semDelete (pComponent->sioAdptrMutex); pfwFree (pComponent); return (ERROR); } /* add our parameters to the framework */ for (i = 0; i < numSioAdptrParams ; i++)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -