📄 pppmuxadapter.c
字号:
*/LOCAL STATUS muxAdptrStackDataDestruct ( PFW_OBJ * pfw, void * pStackData, /* reference to this component's Stack data */ void * profileData ) { MUX_ADPTR_STACK_DATA * pMuxAdptrStackData = (MUX_ADPTR_STACK_DATA *)pStackData; if (pMuxAdptrStackData->destAddr != NULL) { pfwFree(pMuxAdptrStackData->destAddr); pMuxAdptrStackData->destAddr = NULL; } return OK; }/******************************************************************************** muxAdptrStackInterfaceBind - bind our interfaces** RETURNS: OK on success and ERROR otherwise*/LOCAL STATUS muxAdptrInterfaceBind ( PFW_PLUGIN_OBJ * pluginObj ) { int id; MUX_ADPTR_COMPONENT * pComponent = (MUX_ADPTR_COMPONENT *)pluginObj; if ((id = pfwInterfaceRegister(pluginObj->pfwObj, "ADAPTER_DESTINATION_AND_PROTOCOL_SET_INTERFACE")) ==0) { printf("MUX ADAPTER: Failed to register %s \n", "ADAPTER_DESTINATION_AND_PROTOCOL_SET_INTERFACE"); return ERROR; } pComponent->adapterInterface.interfaceObj.id = id; pComponent->adapterInterface.interfaceObj.pluginObj = pluginObj; pComponent->adapterInterface.destAddrAndProtocolSet =destAddrAndProtocolSet; pfwInterfaceBind(&pComponent->adapterInterface.interfaceObj); if ((id = pfwInterfaceRegister(pluginObj->pfwObj, "ADAPTER_INFO_GET_INTERFACE")) ==0) { printf("MUX ADAPTER: Failed to register %s \n","ADAPTER_INFO_GET_INTERFACE"); return ERROR; } pComponent->adapterInfoGetInterface.interfaceObj.id = id; pComponent->adapterInfoGetInterface.interfaceObj.pluginObj = pluginObj; pComponent->adapterInfoGetInterface.adapterPortIdGet = adapterPortIdGet; return (pfwInterfaceBind(&pComponent->adapterInfoGetInterface.interfaceObj)); }/******************************************************************************** muxAdptrStackDataConstruct - initialize component stack data** This function is called by the framework at the time this component* is included in a stack for the purpose of initializing the stack Data** RETURNS: OK on success and ERROR otherwise*/LOCAL STATUS muxAdptrStackDataConstruct ( PFW_OBJ * pfw, void * pStackData, /* reference to this component's Stack data */ void * pProfileData ) { MUX_ADPTR_STACK_DATA * pMuxAdptrData = (MUX_ADPTR_STACK_DATA *)pStackData; /* start with a clean slate */ bzero ((void *)pMuxAdptrData, sizeof(MUX_ADPTR_STACK_DATA)); pMuxAdptrData->collectPppAttributesEvent = NULL; pMuxAdptrData->bindInfoCache = NULL; pMuxAdptrData->txBlocked = FALSE; pMuxAdptrData->txBlockedEvent = NULL; pMuxAdptrData->txUnblockedEvent = NULL; return OK; }/******************************************************************************** muxAdptrStackAdd - initialize a stack via the MUX** This is the first interface invoked by the framework to initialize a * stack which will use MUX. The profileData for this connection contained in* the componentState parameter has the device name & unit number and* protocol types that should be bound to the specified device* ** RETURNS: OK on success and ERROR otherwise*/LOCAL STATUS muxAdptrStackAdd ( PFW_PLUGIN_OBJ_STATE * pComponentState, /* our state for this connection */ PFW_PLUGIN_OBJ_CALLBACKS * callbacks ) { int i; int slot; void * cookie = NULL; UINT32 muxSvcType; char muxSvcName[25]; int svcNameLen = strlen("PPP"); MUX_ADPTR_COMPONENT * pComponent = (MUX_ADPTR_COMPONENT *)pComponentState->pluginObj; MUX_ADPTR_PROFILE_DATA * pMuxAdptrProfileData = (MUX_ADPTR_PROFILE_DATA *)pComponentState->profileData; MUX_ADPTR_STACK_DATA * pMuxAdptrStackData = (MUX_ADPTR_STACK_DATA *)pComponentState->stackData; pMuxAdptrStackData->portId = 0; /* * if we are going to send L2 frames simply add the provided L2 type * to the list of services that we'll bind to the device. */ if (pMuxAdptrProfileData->muxL2SvcType != 0x0) { pMuxAdptrProfileData->muxSvcType[pMuxAdptrProfileData->muxNumSvcs++] = pMuxAdptrProfileData->muxL2SvcType; } /* we must have atleast one protocol to bind to the MUX */ if (pMuxAdptrProfileData->muxNumSvcs <= 0) { logMsg("MUX_ADAPTER: No protocols to bind\n", 1,2,3,4,5,6); return ERROR; } bzero((void *)muxSvcName,sizeof(muxSvcName)); strcpy(muxSvcName,"PPP"); if (pMuxAdptrStackData->collectPppAttributesEvent == NULL) { if ((pMuxAdptrStackData->collectPppAttributesEvent = pfwEventObjGet(pComponentState->pluginObj->pfwObj, "COLLECT_PPP_ATTRIBUTES_EVENT")) != NULL) { pfwEventStackSubscribe(pComponentState,pMuxAdptrStackData->collectPppAttributesEvent, muxPPPAttributesEventHandler); } } /* get BLOCKED and UNBLOCKED events */ if ((pMuxAdptrStackData->txBlockedEvent = pfwEventObjGet(pComponentState->pluginObj->pfwObj, "PPP_SUB_LAYER_TX_BLOCKED")) == NULL) { logMsg("MUX_ADAPTER: Failed to get PPP_SUB_LAYER_TX_BLOCKED event\n", 1,2,3,4,5,6); } if ((pMuxAdptrStackData->txUnblockedEvent = pfwEventObjGet(pComponentState->pluginObj->pfwObj, "PPP_SUB_LAYER_TX_UNBLOCKED")) == NULL) { logMsg("MUX_ADAPTER: Failed to get PPP_SUB_LAYER_TX_UNBLOCKED event\n", 1,2,3,4,5,6); } /* get stack resolve Interface from framing component */ i = pfwInterfaceIdGet(pComponentState->pluginObj->pfwObj, "FRAMING_COMPONENT_STACK_RESOLVE_INTERFACE"); if (i == 0 || pfwInterfaceObjAndStateGetViaStackObj(pComponentState->stackObj, i,&pMuxAdptrStackData->resolverInterface) != OK) {#ifdef CANNOT_PROCEED_WITHOUT_RESOLVER_INTERFACE printf ("MUX Adapter: could not find %s for this stack 0x%x\n", "FRAMING_COMPONENT_STACK_RESOLVE_INTERFACE", (UINT32)pComponentState->stackObj); return ERROR;#else pMuxAdptrStackData->resolverInterface.interfaceObj = NULL; /* * without this interface frames received will always be passed to * the upper layers of this stackObj */ pMuxAdptrStackData->resolverInterface.state = pComponentState;#endif /* CANNOT_PROCEED_WITHOUT_RESOLVER_INTERFACE */ } for ( i = 0; i < pMuxAdptrProfileData->muxNumSvcs; i++) { muxSvcType = pMuxAdptrProfileData->muxSvcType[i]; if (semTake(pComponent->muxAdptrMutex,WAIT_FOREVER) != OK) return ERROR; /* attempt to find binding information for this protocol */ slot = muxAdptrBindInfoFind (pComponent, pMuxAdptrProfileData->muxDevName, pMuxAdptrProfileData->muxDevUnit, muxSvcType); if (slot == pComponent->muxMaxBinds) { logMsg ("muxAdptrStackAdd: No more Binds\n",1,2,3,4,5,6); semGive (pComponent->muxAdptrMutex); return ERROR; } if (slot < 0) { logMsg("MUX_ADPTR: Slot < 0\n",1,2,3,4,5,6); semGive (pComponent->muxAdptrMutex); return ERROR; } /* * check cookie and refCount to tell if this is already bound; * if so save bind entry reference in stack data * * NOTE: if this protocol is already bound to the named device * on a different framework stack and if the interface * FRAMING_COMPONENT_STACK_RESOLVE_INTERFACE was not provided * we cannot continue. */ if ((pComponent->bindInfo[slot].cookie != NULL) && (pComponent->bindInfo[slot].refCount > 0)) { if (pComponent->bindInfo[slot].stackObjResolver.interfaceObj == NULL) { logMsg("MUX_ADPTR: Protocol 0x%x already bound to Device %s,\ Unit %d, on stackObj %p and did not supply\ FRAMING_COMPONENT_STACK_RESOLVE_INTERFACE\n", muxSvcType,(int)pMuxAdptrProfileData->muxDevName, pMuxAdptrProfileData->muxDevUnit, (int)pComponentState->stackObj,5,6); MUX_ADPTR_STACK_ADD_ERROR(pComponentState); semGive (pComponent->muxAdptrMutex); return ERROR; } pComponent->bindInfo[slot].refCount++; pMuxAdptrStackData->bindInfoIndex[i] = slot; pMuxAdptrStackData->portId = pComponent->bindInfo[slot].portId; semGive (pComponent->muxAdptrMutex); continue; } /* need to bind */ sprintf(&muxSvcName[svcNameLen],"-0x%lx", (long unsigned int) muxSvcType); if (muxTkDrvCheck(pMuxAdptrProfileData->muxDevName)) { if (muxSvcType == pMuxAdptrProfileData->muxL2SvcType) { logMsg ("MUX_ADPTR: muxL2SvcType=0x%x cannot bind to NPT driver\ %s%d\n", (int)pMuxAdptrProfileData->muxL2SvcType, (int)pMuxAdptrProfileData->muxDevName, pMuxAdptrProfileData->muxDevUnit,4,5,6); semGive (pComponent->muxAdptrMutex); return ERROR; } cookie = muxTkBind ( pMuxAdptrProfileData->muxDevName, pMuxAdptrProfileData->muxDevUnit, muxAdptrRecvRtn,muxAdptrShutdownRtn, muxAdptrTxRestartRtn,#if ((defined STACK_NAME) && (STACK_NAME == STACK_NAME_V4_V6)) (FUNCPTR) muxAdptrErrorRtn,#else muxAdptrErrorRtn,#endif /* ((defined STACK_NAME) && (STACK_NAME == STACK_NAME_V4_V6)) */ muxSvcType,muxSvcName, &pComponent->bindInfo[slot], NULL,NULL); } else { cookie = muxBind ( pMuxAdptrProfileData->muxDevName, pMuxAdptrProfileData->muxDevUnit, muxAdptrEndRecvRtn,muxAdptrEndShutdownRtn, muxAdptrEndTxRestartRtn, muxAdptrEndErrorRtn, muxSvcType,muxSvcName,&pComponent->bindInfo[slot]); } if(cookie == NULL) { logMsg("MUX_ADAPTER: Failed to bind protocol 0x%x\n", muxSvcType ,2,3,4,5,6); semGive (pComponent->muxAdptrMutex); return ERROR; } else { if (0 == pMuxAdptrStackData->portId) { pMuxAdptrStackData->portId = (ULONG) cookie; } /* save the bind information in the bindInfo table */ pMuxAdptrStackData->bindInfoIndex[i] = slot; sllInit(&pComponent->bindInfo[slot].txBlockedList); pComponent->bindInfo[slot].refCount = 1; semGive (pComponent->muxAdptrMutex); pComponent->bindInfo[slot].stackObjResolver = pMuxAdptrStackData->resolverInterface; pComponent->bindInfo[slot].cookie = cookie; pComponent->bindInfo[slot].pluginObj = (PFW_PLUGIN_OBJ *)pComponent; pComponent->bindInfo[slot].portId = pMuxAdptrStackData->portId; pComponent->bindInfo[slot].netSvcType = muxSvcType; pComponent->bindInfo[slot].unitNo = pMuxAdptrProfileData->muxDevUnit; strcpy (pComponent->bindInfo[slot].devName, pMuxAdptrProfileData->muxDevName); /* * when muxL2SvcType is set we always use the resulting bindCookie * when sending frames. Also destAddrAndProtocolSet() is made * inactive. */ if (muxSvcType == pMuxAdptrProfileData->muxL2SvcType) pMuxAdptrStackData->bindInfoCache = &pComponent->bindInfo[slot]; } } /* save callbacks and state */ pMuxAdptrStackData->callbacks = callbacks; pMuxAdptrStackData->state = pComponentState; /* DONE processing stack add request*/ /* Get pfwRFC2233CountPair and set pfwRFC2233CountTest */ RFC2233_COUNT_PAIR_GET(pComponentState, pMuxAdptrStackData->pfwAuxIfId, pMuxAdptrStackData->pfwRFC2233CountPair, pMuxAdptrStackData->pfwRFC2233CountTest); MUX_STACK_ADD_DONE(pComponentState); return OK; }/******************************************************************************** muxAdptrStackDel - detach this component from the stack ** This interface is invoked as part of a pfwStackDelete() call. In here* we unbind the protocols bound to the mux as part of this stack instance.** RETURNS: OK on success and ERROR otherwise*/LOCAL STATUS muxAdptrStackDel ( PFW_PLUGIN_OBJ_STATE * pComponentState /* our state for this connection */ ) { int i; MUX_ADPTR_BIND_INFO * pBindInfo = NULL; MUX_ADPTR_COMPONENT * pComponent = (MUX_ADPTR_COMPONENT *)pComponentState->pluginObj; MUX_ADPTR_PROFILE_DATA * pMuxAdptrProfileData = (MUX_ADPTR_PROFILE_DATA *)pComponentState->profileData; MUX_ADPTR_STACK_DATA * pMuxAdptrStackData = (MUX_ADPTR_STACK_DATA *)pComponentState->stackData; for ( i = 0; i < pMuxAdptrProfileData->muxNumSvcs; i++) { pBindInfo = &pComponent->bindInfo[pMuxAdptrStackData->bindInfoIndex[i]]; if (semTake (pComponent->muxAdptrMutex,WAIT_FOREVER) != OK) return ERROR; muxAdptrBindInfoClear(pBindInfo,pMuxAdptrStackData); semGive (pComponent->muxAdptrMutex); } if (pMuxAdptrStackData->resolverInterface.interfaceObj != NULL) pfwInterfaceReferenceDelete( pMuxAdptrStackData->resolverInterface.interfaceObj); if (pMuxAdptrStackData->pfwRFC2233CountTest) pfwInterfaceReferenceDelete( pMuxAdptrStackData->pfwRFC2233CountPair.interfaceObj); /* DONE processing stack Delete request*/ MUX_STACK_DELETE_DONE(pComponentState); return OK; }/******************************************************************************** muxAdptrSend - MUX adapter send interface** This interface is invoked by the framework when a packet has to be sent * out to the network through us. In here we strip the destination address* protocol information from the incoming packet and call muxSend()/muxTkSend()* with the stripped out information to send the packet to the driver** RETURNS: OK on success and ERROR otherwise*/LOCAL STATUS muxAdptrSend ( PFW_PLUGIN_OBJ_STATE * pComponentState, /* our state for this stack */ M_BLK_ID * pMblkId /* packet to send */ ) { MUX_ADPTR_PROFILE_DATA * pMuxAdptrProfileData = (MUX_ADPTR_PROFILE_DATA *)pComponentState->profileData; MUX_ADPTR_STACK_DATA * pMuxAdptrStackData = (MUX_ADPTR_STACK_DATA *)pComponentState->stackData; void * cookie = NULL; M_BLK_ID pMblk = NULL; STATUS status; UINT pktLength; M_BLK_ID auxMblkId; pktLength = 0; if ((pMblkId == NULL) || ((pMblk = *pMblkId) == NULL)) { RFC2233_COUNTER_UPDATE(pMuxAdptrStackData->pfwRFC2233CountTest, pMuxAdptrStackData->pfwRFC2233CountPair, M2_ctrId_ifOutErrors, 1); return ERROR; } auxMblkId = pMblk; while (auxMblkId != NULL) { pktLength += auxMblkId->mBlkHdr.mLen; auxMblkId = auxMblkId->mBlkHdr.mNext; } /* we must be bound to atleast one protocol for this connection */ if (pMuxAdptrProfileData->muxNumSvcs <= 0) { MUX_FREE_PKT(pMblk); RFC2233_COUNTER_UPDATE(pMuxAdptrStackData->pfwRFC2233CountTest, pMuxAdptrStackData->pfwRFC2233CountPair, M2_ctrId_ifOutDiscards, 1); return ERROR; } /* cant proceed with a NULL cookie */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -