?? pppsioadapter.c
字號:
{ if (pfwParameterAdd ((PFW_PLUGIN_OBJ *)pComponent, sioAdptrParams[i].name, sioAdptrParams[i].handler) == ERROR) { logMsg ("sioAdptrCreate - Parameter %s could not be added\n", (int)sioAdptrParams[i].name,2,3,4,5,6); return (ERROR); } } /* allocate an array for the number of channels specified */ if ((pComponent->channelMap = (PFW_PLUGIN_OBJ_STATE **) pfwMalloc (pfw,numSioChannels * sizeof(PFW_PLUGIN_OBJ_STATE *))) == NULL) return ERROR; bzero ((void *)pComponent->channelMap, numSioChannels * sizeof(PFW_PLUGIN_OBJ_STATE *)); return OK; }/******************************************************************************** sioAdapterDelete - delete the SIO adapter component from the framework** The SIO_ADAPTER plug-in component object allocated by sioAdapterCreate() is * freed if there are no references to this object from a * Stack or Profile object in the framework.** RETURNS: OK or ERROR*/STATUS sioAdapterDelete ( PFW_OBJ * pfw /* framework */ ) { PFW_COMPONENT_OBJ *pComponent; SIO_ADPTR_COMPONENT * sioComponent; pComponent = pfwComponentObjGetByName(pfw,"SIO_ADAPTER"); if (pComponent == NULL) return ERROR; if (pfwComponentDelete(pComponent) != OK) return ERROR; sioComponent = (SIO_ADPTR_COMPONENT *)pComponent; pfwFree(sioComponent->channelMap); semDelete(sioComponent->sioAdptrMutex); pfwFree(pComponent); return OK; }/******************************************************************************** sioAdptrProfileDataConstruct - initialize SIO adapter profile data***/LOCAL STATUS sioAdptrProfileDataConstruct ( PFW_OBJ * pfw, void * pData /* reference to profile data */ ) { bzero(pData, sizeof (SIO_ADPTR_PROFILE_DATA)); /* default minimum baud rate */ ((SIO_ADPTR_PROFILE_DATA *)pData)->baudRate = 9600; ((SIO_ADPTR_PROFILE_DATA *)pData)->maxSendQSize = SIO_SEND_Q_DEFAULT_SIZE; return OK; }/******************************************************************************** sioAdptrStackDataConstruct - initialize SIO adapter Stack data***/LOCAL STATUS sioAdptrStackDataConstruct ( PFW_OBJ * pfw, void * stackData, /* reference to stack data */ void * profileData /* reference to profile data */ ) { SIO_ADPTR_STACK_DATA * pStackData = (SIO_ADPTR_STACK_DATA *)stackData; bzero((void *)pStackData, sizeof (SIO_ADPTR_PROFILE_DATA)); if ((pStackData->netPoolId = pfwNetPoolIdGet(pfw)) == NULL) { printf("SIO: MUST have a valid NetPoolId; See pfwCreate()\n"); return ERROR; } pStackData->collectPppAttributesEvent = NULL; pStackData->channelState = SIO_CHANNEL_DOWN; pStackData->sendQHead = NULL; pStackData->sendQTail = NULL; pStackData->sendQSize = 0; pStackData->sendQFull = FALSE; pStackData->sendMblk = NULL; pStackData->receiveChain = NULL; pStackData->receiveMblk = NULL; pStackData->localMru = SIO_DEFAULT_MAX_MRU; pStackData->nextSendIndex = 0; pStackData->nextReceiveIndex = 0; pStackData->inputOctets = 0; pStackData->outputOctets = 0; pStackData->inputPackets = 0; pStackData->outputPackets = 0; pStackData->txBlockedEvent = NULL; pStackData->txUnblockedEvent = NULL; pStackData->lcpIsOpen = FALSE; pStackData->reTransmitClientString = 0x1; return OK; }/******************************************************************************** sioAdptrStackDataDestruct - clean up SIO adapter Stack data***/LOCAL STATUS sioAdptrStackDataDestruct ( PFW_OBJ * pfw, void * stackData, /* reference to stack data */ void * profileData /* reference to profile data */ ) { return OK; }/******************************************************************************** sioAdptrStackAdd - initialize a connection via the configured interface***/LOCAL STATUS sioAdptrStackAdd ( PFW_PLUGIN_OBJ_STATE * pComponentState, PFW_PLUGIN_OBJ_CALLBACKS * callbacks ) { SIO_ADPTR_PROFILE_DATA * pProfileData = (SIO_ADPTR_PROFILE_DATA * )pComponentState->profileData; SIO_ADPTR_STACK_DATA * pStackData = (SIO_ADPTR_STACK_DATA * )pComponentState->stackData; SIO_ADPTR_COMPONENT * pSioComponent = (SIO_ADPTR_COMPONENT * )pComponentState->pluginObj; SIO_CHAN *pSioChan = NULL; int id; /* check if channel is already taken */ if (semTake(pSioComponent->sioAdptrMutex,WAIT_FOREVER) != OK) { return ERROR; } if (pStackData->collectPppAttributesEvent == NULL) { if ((pStackData->collectPppAttributesEvent = pfwEventObjGet(pComponentState->pluginObj->pfwObj, "COLLECT_PPP_ATTRIBUTES_EVENT")) != NULL) { pfwEventStackSubscribe(pComponentState,pStackData->collectPppAttributesEvent, sioChannelIDConnectSpeedEventHandler); } } if (pProfileData->peerType == SIO_PEER_MODEM) { MODEM_DATA * pModemData = NULL; PFW_OBJ * pfw = pComponentState->pluginObj->pfwObj; if ((pModemData = pfwMalloc (pfw, sizeof (MODEM_DATA))) == NULL) return (ERROR); pStackData->pModemData = pModemData; pStackData->pModemData->modemFlags = 0; pStackData->pModemData->inBufCount = 0; pStackData->pModemData->outBufCount = 0; pStackData->pModemData->rspBufCount = 0; pStackData->pModemData->rspBufOffset = 0; MODEM_READ_SEM_CREATE; } if (pSioComponent->channelMap[pProfileData->channelNum] != NULL) { printf ("Sio Adapter: Channel Number %d in use by Stack ID %d\n", pProfileData->channelNum, pfwStackIdGet(pSioComponent->channelMap[pProfileData->channelNum]->stackObj)); semGive(pSioComponent->sioAdptrMutex); return ERROR; } else { /* get channel */ if ((pSioChan = sysSerialChanGet(pProfileData->channelNum)) <= (SIO_CHAN *)NULL) { semGive (pSioComponent->sioAdptrMutex); return ERROR; } if ((pStackData->channelSem = semBCreate(SEM_Q_PRIORITY,SEM_EMPTY)) == NULL) { semGive (pSioComponent->sioAdptrMutex); return ERROR; } pStackData->pSioChan = pSioChan; pStackData->channelNum = pProfileData->channelNum; pStackData->callbacks = callbacks; pSioComponent->channelMap[pProfileData->channelNum] = pComponentState; } /* got channel */ semGive(pSioComponent->sioAdptrMutex); /* install send and receive callbacks and set baudRate */ if (sioCallbackInstall(pSioChan,SIO_CALLBACK_GET_TX_CHAR, (SIO_FUNCPTR) sioAdptrSendOctet, pComponentState) != OK) { printf ("sioAdapter: Failed to install SIO_CALLBACK_GET_TX_CHAR \n"); return ERROR; } if (sioCallbackInstall(pSioChan,SIO_CALLBACK_PUT_RCV_CHAR, (SIO_FUNCPTR) sioAdptrReceiveOctet, pComponentState) != OK) { printf ("sioAdapter: Failed to install SIO_CALLBACK_PUT_RCV_CHAR \n"); return ERROR; } if (sioIoctl(pSioChan,SIO_BAUD_SET,(void *)pProfileData->baudRate) != OK) { printf ("sioAdapter: Failed to set baud rate %d\n", pProfileData->baudRate); return ERROR; } /* setting the device to interrupt mode essentially starts the device */ if (sioIoctl(pSioChan,SIO_MODE_SET, (void *)SIO_MODE_INT) != OK) { printf ("sioAdapter: Failed to set Interrupt mode \n"); return ERROR; } /* get PPP administrative open event object and subcribe to it*/ if ((pStackData->lcpOpen = pfwEventObjGet(pComponentState->pluginObj->pfwObj,"LCP_OPEN_EVENT")) != NULL) { pfwEventStackSubscribe(pComponentState,pStackData->lcpOpen, lcpOpenHandler); } else return ERROR; /* get PPP close event object and subcribe to it*/ if ((pStackData->lcpDown = pfwEventObjGet(pComponentState->pluginObj->pfwObj,"LCP_DOWN_EVENT")) != NULL) { pfwEventStackSubscribe(pComponentState,pStackData->lcpDown, lcpDownHandler); } else return ERROR; /* get PPP administrative close event object and subcribe to it */ if ((pStackData->lcpClose = pfwEventObjGet(pComponentState->pluginObj->pfwObj,"LCP_CLOSE_EVENT")) != NULL) { pfwEventStackSubscribe(pComponentState,pStackData->lcpClose, lcpCloseHandler); } else return ERROR; /* get LCP UP event object and subcribe to it*/ if ((pStackData->lcpUpEvent = pfwEventObjGet(pComponentState->pluginObj->pfwObj,"LCP_UP_EVENT")) != NULL) { pfwEventStackSubscribe(pComponentState,pStackData->lcpUpEvent, lcpUpEventHandler); } else return ERROR; /* get BLOCKED and UNBLOCKED events */ if ((pStackData->txBlockedEvent = pfwEventObjGet(pComponentState->pluginObj->pfwObj, "PPP_SUB_LAYER_TX_BLOCKED")) == NULL) { logMsg("SIO_ADAPTER: Failed to get PPP_SUB_LAYER_TX_BLOCKED event\n", 1,2,3,4,5,6); } if ((pStackData->txUnblockedEvent = pfwEventObjGet(pComponentState->pluginObj->pfwObj, "PPP_SUB_LAYER_TX_UNBLOCKED")) == NULL) { logMsg("SIO_ADAPTER: Failed to get PPP_SUB_LAYER_TX_UNBLOCKED event\n", 1,2,3,4,5,6); } /* get LCP interfaces */ if ((id = pfwInterfaceIdGet(pComponentState->pluginObj->pfwObj, "PPP_LINK_STATUS_ENTRY_INTERFACE")) > 0) { if (pfwInterfaceObjAndStateGetViaStackObj(pComponentState->stackObj, id, &pStackData->pppLinkStatusInterface) != OK) return ERROR; } else return ERROR; /* if we are a peer to a regular(non NT machine) we are done */ if (pProfileData->peerType == SIO_PEER_REGULAR) { sioAdptrChannelAvailable (pComponentState); } /* Get pfwRFC2233CountPair and set pfwRFC2233CountTest */ RFC2233_COUNT_PAIR_GET(pComponentState, pStackData->pfwAuxIfId, pStackData->pfwRFC2233CountPair, pStackData->pfwRFC2233CountTest); /* DONE processing stack add request */ if (pStackData->callbacks && pStackData->callbacks->stackAddComplete) { (*pStackData->callbacks->stackAddComplete)(pStackData->callbacks, pComponentState); } return OK; }/******************************************************************************** sioStackDel - terminate a connection via the configured interface***/LOCAL STATUS sioAdptrStackDel ( PFW_PLUGIN_OBJ_STATE * pComponentState ) { SIO_ADPTR_COMPONENT * pSioComponent = (SIO_ADPTR_COMPONENT * )pComponentState->pluginObj; SIO_ADPTR_STACK_DATA * pStackData = (SIO_ADPTR_STACK_DATA * )pComponentState->stackData; SIO_ADPTR_PROFILE_DATA * pProfileData = (SIO_ADPTR_PROFILE_DATA *) pComponentState->profileData; /* wait for channel to become available */ #if 0 if (semTake(pStackData->channelSem, WAIT_FOREVER) != OK) return ERROR; #endif while((pStackData->channelState != SIO_CHANNEL_DOWN) && (semTake(pStackData->channelSem, NO_WAIT) != OK)) ; if (pStackData->sendMblk != NULL) { semGive(pStackData->channelSem); return ERROR; } if (semTake(pSioComponent->sioAdptrMutex,WAIT_FOREVER) != OK) { semGive(pStackData->channelSem); return ERROR; } /* free captured receive buffer */ if (pStackData->receiveChain != NULL ) { SIO_FREE_PKT_CHAIN(pStackData->receiveChain); pStackData->receiveChain = NULL; } /* setting the device to POLL mode essentially disables the device */ sioIoctl (pStackData->pSioChan, SIO_MODE_SET, (void *)SIO_MODE_POLL); /* * install our callbacks again with NULL callback args to handle spurious * interrupts */ sioCallbackInstall(pStackData->pSioChan,SIO_CALLBACK_GET_TX_CHAR, (SIO_FUNCPTR) sioAdptrSendOctet, NULL); sioCallbackInstall(pStackData->pSioChan,SIO_CALLBACK_PUT_RCV_CHAR, (SIO_FUNCPTR) sioAdptrReceiveOctet, NULL); /* infree resources allocated for the modem, if appropriate */ if (pProfileData->peerType == SIO_PEER_MODEM) { MODEM_DATA * pModemData = pStackData->pModemData; MODEM_READ_SEM_DELETE; if (pStackData->pModemData != NULL) pfwFree (pStackData->pModemData); } /* mark channel available for others */ pSioComponent->channelMap[pStackData->channelNum] = NULL; semGive(pSioComponent->sioAdptrMutex); /* kill channel sem */ semDelete(pStackData->channelSem); pfwInterfaceReferenceDelete(pStackData->pppLinkStatusInterface.interfaceObj);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -