int etherMultiDel ( LIST *pList, /* pointer to list of multicast addresses */ char* pAddress /* address you want to add to list */ ) { ETHER_MULTI* pCurr; /* * Look up the address in our list. */ for (pCurr = (ETHER_MULTI *)lstFirst(pList); pCurr != NULL && (bcmp(pCurr->addr, pAddress, 6) != 0); pCurr = (ETHER_MULTI *)lstNext(&pCurr->node)); if (pCurr == NULL) { return (ENXIO); } if (--pCurr->refcount != 0) { /* * Still some claims to this record. */ return (0); } /* * No remaining claims to this record; unlink and free it. */ lstDelete(pList, &pCurr->node); KHEAP_FREE((char *)pCurr); /* * Return ENETRESET to inform the driver that the list has changed * and its reception filter should be adjusted accordingly. */ return (ENETRESET); }
ETHER_MULTI* endMultiLstNext ( ETHER_MULTI* pCurrent ) { return((ETHER_MULTI *)(lstNext(&pCurrent->node))); }
BST_UINT32 BST_CTaskSchdler::ChkTaskExist ( BST_CORE_CPTask *pC_PTask ) { BST_CORE_PTASK_NODE_STRU *pstPtaskNode; if ( BST_NULL_PTR == pC_PTask ) { BST_RLS_LOG( "BST_CTaskSchdler::ChkTaskExist pC_PTask=NULL" ); return BST_FALSE; } if ( 0 == lstCount( &g_stPTaskList ) ) { BST_RLS_LOG( "BST_CTaskSchdler::ChkTaskExist g_stPTaskList count=0" ); return BST_FALSE; } /* * 遍历任务表,对比pcPtask,相等的记为找到 */ for ( pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstFirst( &g_stPTaskList ); pstPtaskNode!= BST_NULL_PTR; pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstNext((NODE *)pstPtaskNode) ) { if ( BST_NULL_PTR == pstPtaskNode->pcTask ) { continue; } if ( pC_PTask == pstPtaskNode->pcTask ) { return BST_TRUE; } } return BST_FALSE; }
void etherOutputHookDelete ( FUNCPTR outputHook ) { HOOK_ENTRY *pHookEnt; extern LIST outputHookList; NODE index; for (pHookEnt = (HOOK_ENTRY *)lstFirst(&outputHookList); pHookEnt != NULL; pHookEnt = (HOOK_ENTRY *)lstNext(&index)) { index = pHookEnt->node; if (pHookEnt->routine == outputHook) { lstDelete(&outputHookList, &pHookEnt->node); free(pHookEnt); } } if (lstCount(&outputHookList) <= 0) { etherOutputHookRtn = NULL; lstFree(&outputHookList); } }
STATUS hostTblSearchByAddr ( int addr, /* inet address of host */ char *name /* buffer to hold name */ ) { HOSTENTRY *pHostEntry; struct in_addr netAddr; STATUS status = ERROR; int n; netAddr.s_addr = addr; semTake (hostListSem, WAIT_FOREVER); /* search for internet address */ for (pHostEntry = (HOSTENTRY *)lstFirst (&hostList); pHostEntry != NULL; pHostEntry = (HOSTENTRY *)lstNext (&pHostEntry->node)) { if (pHostEntry->netAddr.s_addr == netAddr.s_addr) { n = strlen (pHostEntry->hostName.name); strncpy (name, pHostEntry->hostName.name, min (n + 1 , MAXHOSTNAMELEN +1)); status = OK; break; } } semGive (hostListSem); return (status); }
LOCAL BOOL isInMulticastList ( END_CTRL* pDrvCtrl, /* pointer to END_CTRL structure */ UINT16* enetAddr /* address to check */ ) { ETHER_MULTI* pCurr; pCurr = (ETHER_MULTI *)lstFirst(&pDrvCtrl->endObject.multiList); while (pCurr != (ETHER_MULTI *)NULL) { if (((UINT32)(pCurr->addr) & 0x01) == 0) { /* address is aligned on a 2 or 4 byte boundary */ if (MAC_ADDR_EQ(((UINT16 *)(pCurr->addr)), enetAddr) == TRUE) return TRUE; } else { /* address is aligned on a byte-boundary */ if (bcmp(pCurr->addr, (char *)enetAddr, 6) == 0) return TRUE; } pCurr = (ETHER_MULTI *)lstNext(&pCurr->node); } return FALSE; }
BST_VOID BST_CTaskSchdler::Suspend ( BST_VOID ) { BST_CORE_PTASK_NODE_STRU *pstPtaskNode; if ( 0 == lstCount( &g_stPTaskList ) ) { BST_RLS_LOG( "BST_CTaskSchdler::Suspend g_stPTaskList count=0" ); return; } /* * 遍历任务表,找到相关任务对齐进行挂起 */ for ( pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstFirst( &g_stPTaskList ); pstPtaskNode!= BST_NULL_PTR; pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstNext((NODE *)pstPtaskNode) ) { if ( BST_NULL_PTR == pstPtaskNode->pcTask ) { continue; } if ( BST_TASK_STATE_START == pstPtaskNode->pcTask->GetState () ) { pstPtaskNode->pcTask->Suspend(); } } }
BST_VOID BST_CTaskSchdler::TimerExpired( BST_OS_TIMERID_T ulId, BST_VOID *pvPara) { BST_CORE_PTASK_NODE_STRU *pstPtaskNode; BST_CORE_PTASK_NODE_STRU *pstPtaskNodeNext; if ( !BST_OS_IsTimerValid (m_ulTimerId) ) { BST_RLS_LOG1( "BST_CTaskSchdler::TimerExpired m_ulTimerId=%u is invalid", m_ulTimerId ); return; } if ( ulId != m_ulTimerId ) { BST_RLS_LOG2( "BST_CTaskSchdler::TimerExpired ulId=%u,m_ulTimerId=%u", ulId, m_ulTimerId ); return; } /* * 如果没有任务,则直接返回,不做任何操作 */ if ( 0 == lstCount( &g_stPTaskList ) ) { BST_RLS_LOG( "BST_CTaskSchdler::TimerExpired g_stPTaskList count=0" ); return; } /* * 更新系统TICK值 */ m_ulSystemTick += BST_TASK_SYS_TICKS; BST_DBG_LOG1 ( "BST_CTaskSchdler::TimerExpired Scheduler TimeOut, Tick=%d ", m_ulSystemTick ); /* * 遍历任务列表,获取任务并进行相应调度 */ for ( pstPtaskNode = ( BST_CORE_PTASK_NODE_STRU *)lstFirst( &g_stPTaskList ); pstPtaskNode!= BST_NULL_PTR; pstPtaskNode = pstPtaskNodeNext ) { pstPtaskNodeNext = ( BST_CORE_PTASK_NODE_STRU *) lstNext((NODE *)pstPtaskNode); if ( BST_NULL_PTR == pstPtaskNode->pcTask ) { continue; } /* * 如果任务不为空,则根据状态进行调度 */ ScheduleTask ( pstPtaskNode->pcTask ); } /* * 再次启动系统TICK定时器 */ BST_OS_TimerStart ( m_ulTimerId, BST_TASK_SYS_BASE_TIMELEN ); }
BST_UINT32 BST_CTaskSchdler::NearRrcTrig ( BST_UINT32 const ulSysTimerRemainMs ) { BST_CORE_PTASK_NODE_STRU *pstPtaskNode; BST_UINT32 ulNextSysTick; BST_UINT32 ulNextLongCycle; ulNextLongCycle = 0; ulNextSysTick = m_ulSystemTick + BST_TASK_SYS_TICKS; /* * 遍历任务列表,找出所有有效任务 */ for( pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstFirst( &g_stPTaskList ); pstPtaskNode!= BST_NULL_PTR; pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstNext((NODE *)pstPtaskNode) ) { if( BST_NULL_PTR == pstPtaskNode->pcTask ) { continue; } if( 0 == pstPtaskNode->pcTask->m_ulCycle ) { continue; } if( BST_TRUE == pstPtaskNode->pcTask->IsBusy () ) { continue; } if( BST_TASK_STATE_START != pstPtaskNode->pcTask->GetState () ) { continue; } /* * 查看是否有任务周期与Tick整除项,代码周期到来 */ if( 0 == ( ulNextSysTick % pstPtaskNode->pcTask->m_ulCycle ) ) { if( pstPtaskNode->pcTask->m_ulCycle > ulNextLongCycle ) { ulNextLongCycle = pstPtaskNode->pcTask->m_ulCycle; } } } /* * 获取当前系统周期,并取比例,如果剩余时间低于该值,则说明足够靠近 */ ulNextLongCycle = BST_CORE_GetCycleToMs( ulNextLongCycle ); if( BST_TASK_IsNearEnough( ulSysTimerRemainMs, ulNextLongCycle ) ) { BST_RLS_LOG("BST_CTaskSchdler::NearRrcTrig Closing To RRC Enough, Periodic Runing after 200Ms"); return BST_TASK_RRC_SEND_TIMER; } else { return ulSysTimerRemainMs; } }
BST_BOOL BST_CTaskSchdler::TryTaskExist ( BST_VOID ) { BST_UINT32 ulNextTick; BST_TASK_STATE_ENUM_UINT8 enTaskState; BST_SRV_CTaskMng *pcTaskManager; BST_CORE_PTASK_NODE_STRU *pstPtaskNode; ulNextTick = 0; pcTaskManager = BST_SRV_CTaskMng::GetInstance (); BST_ASSERT_NULL_RTN( pcTaskManager, BST_FALSE ); /* * 在当前系统值加一个TICK单位,获得下一时刻TICK值 */ ulNextTick = m_ulSystemTick + BST_TASK_SYS_TICKS; for ( pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstFirst( &g_stPTaskList ); pstPtaskNode!= BST_NULL_PTR; pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstNext((NODE *)pstPtaskNode ) ) { if ( BST_NULL_PTR == pstPtaskNode->pcTask ) { continue; } /* * 如果任务没有执行完成,处于繁忙状态,则立即返回 */ if ( BST_TRUE == pstPtaskNode->pcTask->IsBusy () ) { continue; } /* * 如果TICK值能够被任务周期整除,说明到了该任务周期 */ if ( 0 == ( ulNextTick % pstPtaskNode->pcTask->m_ulCycle ) ) { enTaskState = pstPtaskNode->pcTask->GetState (); if ( BST_TASK_STATE_START == enTaskState ) { return BST_TRUE; } else { continue; } } else { continue; } } return BST_FALSE; }
/*lint -e429*/ BST_VOID BST_CTaskSchdler::Attach ( BST_CORE_CPTask *pC_PTask ) { BST_CORE_PTASK_NODE_STRU *pstPtaskNode; if ( !BST_OS_IsTimerValid (m_ulTimerId) ) { BST_RLS_LOG1( "BST_CTaskSchdler::Attach m_ulTimerId=%u is invalid", m_ulTimerId ); return; } if ( BST_NULL_PTR == pC_PTask ) { BST_RLS_LOG( "BST_CTaskSchdler::Attach pC_PTask=NULL" ); return; } for ( pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstFirst( &g_stPTaskList ); pstPtaskNode!= BST_NULL_PTR; pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstNext((NODE *)pstPtaskNode) ) { if( pstPtaskNode->pcTask == pC_PTask ) { return; } } /* * 申请链表节点资源,用于存储任务 */ pstPtaskNode = ( BST_CORE_PTASK_NODE_STRU *)BST_OS_MALLOC ( BST_OS_SIZEOF( BST_CORE_PTASK_NODE_STRU ) ); if( BST_NULL_PTR == pstPtaskNode ) { BST_RLS_LOG( "BST_CTaskSchdler::Attach pstPtaskNode=NULL" ); return; } /* * 初始化任务数据,添加如任务列表 */ pC_PTask->m_ulSuspCounter = 0; pstPtaskNode->pcTask = pC_PTask; lstAdd( &g_stPTaskList, (NODE *)pstPtaskNode ); /* * 如果此时系统TICK定时已经关闭,且PS域服务状态正常,那么需要再次启动定时 */ if( BST_TRUE == BST_OS_TimerIsStop( m_ulTimerId ) ) { m_ulSystemTick = 0; BST_OS_TimerStart ( m_ulTimerId, BST_TASK_SYS_BASE_TIMELEN ); BST_DBG_LOG1( "BST_CTaskSchdler::Attach Start Scheduler Timer:%u", BST_TASK_SYS_BASE_TIMELEN ); } }
OM_BST_APP_INFO_STRU *BST_SYS_MntnSrchAppByPort( BST_UINT16 usLocalPortNumber ) { BST_SYS_MNTN_APP_NODE_STRU *pstAppNode; /* 查找链表中是否已经存在该Port信息 */ for ( pstAppNode = ( BST_SYS_MNTN_APP_NODE_STRU *)lstFirst(BST_SYS_MNTN_GetAppListHead()); pstAppNode != BST_NULL_PTR; pstAppNode = ( BST_SYS_MNTN_APP_NODE_STRU *)lstNext( (NODE *)pstAppNode ) ) { if ( usLocalPortNumber == pstAppNode->stAppInfo.usLocalPort ) { return &pstAppNode->stAppInfo; } } return BST_NULL_PTR; }
void *lstGoto( HLST hLst, long nIndex ) { long n = 0; if ( !hLst ) return NULL; lstFirst( hLst ); while ( (n < nIndex) && (!lstEOL( hLst )) ) { n++; lstNext( hLst ); } return hLst->hCurrent; }
LOCAL BOOL nptEtherInputHookRtn ( void * pCallBackId, /* Sent down in muxTkBind(); same as pSpare as in muxBind() */ long type, /* SNARF */ M_BLK_ID pMblk, /* Received frame (with link-level header). */ void * pSpareData /* Extra protocol data */ ) { HOOK_ENTRY * pHookEnt = (HOOK_ENTRY*) pCallBackId; char devName[32]; char packetData [ETHERMTU + SIZEOF_ETHERHEADER]; struct ifnet fakeIF; extern LIST inputHookList; int flags; int len; END_OBJ* pEnd=PCOOKIE_TO_ENDOBJ(pHookEnt->pCookie); int ifHdrLen=0; bzero ( (char *)&fakeIF, sizeof (fakeIF)); fakeIF.if_name = &devName[0]; strcpy (fakeIF.if_name, pEnd->devObject.name); fakeIF.if_unit = pEnd->devObject.unit; muxIoctl (pHookEnt->pCookie, EIOCGFLAGS, (caddr_t)&flags); fakeIF.if_flags = flags; /* Get the Link Level header length . */ if (muxIoctl (pHookEnt->pCookie, EIOCGHDRLEN, (caddr_t)&ifHdrLen) != OK) fakeIF.if_hdrlen = 0; else fakeIF.if_hdrlen = (UCHAR)ifHdrLen; len = netMblkToBufCopy(pMblk, (char *)packetData, NULL); for (pHookEnt = (HOOK_ENTRY *)lstFirst (&inputHookList); pHookEnt != NULL; pHookEnt = (HOOK_ENTRY *)lstNext (&pHookEnt->node)) { if ( (* pHookEnt->routine) (&fakeIF, packetData, len)) { netMblkClChainFree (pMblk); /* hook has consumed the packet */ return (TRUE); } } return (FALSE); }
int hostTblSearchByName ( char *name /* name of host */ ) { HOSTNAME *pHostName; HOSTENTRY *pHostEntry; int retAddr = ERROR; semTake (hostListSem, WAIT_FOREVER); for (pHostEntry = (HOSTENTRY *)lstFirst (&hostList); pHostEntry != NULL; pHostEntry = (HOSTENTRY *)lstNext (&pHostEntry->node)) { /* check official name */ if (strcmp (pHostEntry->hostName.name, name) == 0) { retAddr = (int)pHostEntry->netAddr.s_addr; break; } /* check aliases */ for (pHostName = pHostEntry->hostName.link; pHostName != NULL; pHostName = pHostName->link) { if (strcmp (pHostName->name, name) == 0) { retAddr = (int)pHostEntry->netAddr.s_addr; /* force termination of outer loop */ pHostEntry = (HOSTENTRY *)lstLast (&hostList); break; } } } semGive (hostListSem); return (retAddr); }
OM_BST_APP_INFO_STRU *BST_SYS_MntnSrchAppByTask( BST_UINT16 usType, BST_UINT16 usTaskId ) { BST_SYS_MNTN_APP_NODE_STRU *pstAppNode; /* 查找链表中是否已经存在该Task信息 */ for ( pstAppNode = ( BST_SYS_MNTN_APP_NODE_STRU *)lstFirst(BST_SYS_MNTN_GetAppListHead()); pstAppNode != BST_NULL_PTR; pstAppNode = ( BST_SYS_MNTN_APP_NODE_STRU *)lstNext( (NODE *)pstAppNode ) ) { if ( ( usTaskId == pstAppNode->stAppInfo.usTaskId ) && ( usType == pstAppNode->stAppInfo.usAppType ) ) { return &pstAppNode->stAppInfo; } } return BST_NULL_PTR; }
LOCAL BOOL etherOutputHook ( struct ifnet *pIf, char *buffer, int length ) { HOOK_ENTRY* pHookEnt; extern LIST outputHookList; for (pHookEnt = (HOOK_ENTRY *)lstFirst(&outputHookList); pHookEnt != NULL; pHookEnt = (HOOK_ENTRY *)lstNext(&pHookEnt->node)) { if ((* pHookEnt->routine) (pIf, buffer, length)) return (TRUE); } return (FALSE); }
/*lint -e438*/ BST_VOID BST_CTaskSchdler::Detach ( BST_CORE_CPTask *pC_PTask ) { BST_CORE_PTASK_NODE_STRU *pstPtaskNode; if ( !BST_OS_IsTimerValid (m_ulTimerId) ) { BST_RLS_LOG1( "BST_CTaskSchdler::Detach m_ulTimerId=%u is invalid", m_ulTimerId ); return; } if ( BST_NULL_PTR == pC_PTask ) { BST_RLS_LOG( "BST_CTaskSchdler::Detach pC_PTask=NULL" ); return; } /* * 遍历列表,找到pctask相符的任务,从链表删除,释放资源 */ for ( pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstFirst( &g_stPTaskList ); pstPtaskNode!= BST_NULL_PTR; pstPtaskNode = (BST_CORE_PTASK_NODE_STRU *)lstNext((NODE *)pstPtaskNode) ) { if( pstPtaskNode->pcTask != pC_PTask ) { continue; } lstDelete( &g_stPTaskList, (NODE *)pstPtaskNode ); BST_OS_FREE( pstPtaskNode ); break; } /* * 注销后,如果认为列表为空,则直接关闭定时器,不进行任何调度 */ if ( 0 == lstCount( &g_stPTaskList ) ) { BST_DBG_LOG( "BST_CTaskSchdler::Detach Stop Scheduler Timer" ); BST_OS_TimerStop ( m_ulTimerId ); } }
BST_VOID BST_SYS_MntnRemoveTask( BST_UINT16 usType, BST_UINT16 usTaskId ) { BST_SYS_MNTN_APP_NODE_STRU *pstAppNode; BST_OS_LOCKCNT_T tThreadLockCnt; if ( !BST_SYS_MNTN_IsMntnInited() ) { return; } tThreadLockCnt = BST_OS_ThreadLock(); /* 查找链表中是否已经存在该Task信息 */ for ( pstAppNode = ( BST_SYS_MNTN_APP_NODE_STRU *)lstFirst(BST_SYS_MNTN_GetAppListHead()); pstAppNode != BST_NULL_PTR; pstAppNode = ( BST_SYS_MNTN_APP_NODE_STRU *)lstNext( (NODE *)pstAppNode ) ) { if ( ( usTaskId == pstAppNode->stAppInfo.usTaskId ) && ( usType == pstAppNode->stAppInfo.usAppType ) ) { break; } } if ( BST_NULL_PTR == pstAppNode ) { BST_OS_ThreadUnLock( tThreadLockCnt ); return; } lstDelete( BST_SYS_MNTN_GetAppListHead(), (NODE *)pstAppNode ); BST_OS_FREE( pstAppNode ); BST_RLS_LOG3( "[Mntn] Remove Task: TypeId=, TaskId=, Total=", usType, usTaskId, BST_SYS_MNTN_GetAppNumber() ); BST_SYS_MntnChangedInd(); BST_OS_ThreadUnLock( tThreadLockCnt ); /*lint -e438*/ }
BST_UINT32 BST_SYS_MntnBuildAgentInfoInd( OM_BST_APP_INFO_STRU *pstAgentInfo, const BST_UINT16 usAppNumber ) { BST_SYS_MNTN_APP_NODE_STRU *pstAppNode; BST_UINT16 usAppCounter; BST_OS_LOCKCNT_T tThreadLockCnt; if ( BST_NULL_PTR == pstAgentInfo ) { return BST_FALSE; } tThreadLockCnt = BST_OS_ThreadLock(); usAppCounter = 0; /* 查找链表中是否已经存在该Task信息 */ for ( pstAppNode = ( BST_SYS_MNTN_APP_NODE_STRU *)lstFirst(BST_SYS_MNTN_GetAppListHead()); pstAppNode != BST_NULL_PTR; pstAppNode = ( BST_SYS_MNTN_APP_NODE_STRU *)lstNext( (NODE *)pstAppNode ) ) { if ( ID_BST_OM_TASK_TYPE_MAIN == pstAppNode->stAppInfo.usAppType ) { continue; } BST_OS_MEMCPY( &pstAgentInfo[usAppCounter], &(pstAppNode->stAppInfo), BST_OS_SIZEOF(OM_BST_APP_INFO_STRU) ); usAppCounter++; if ( usAppCounter >= usAppNumber ) { break; } } BST_OS_ThreadUnLock( tThreadLockCnt ); return BST_TRUE; }
int etherMultiGet ( LIST* pList, /* pointer to list of multicast addresses */ MULTI_TABLE* pTable /* table into which to copy addresses */ ) { int count = 0; int len; ETHER_MULTI* pCurr; len = pTable->len; /* Save the passed in table length. */ pTable->len = 0; pCurr = (ETHER_MULTI *)lstFirst(pList); while (pCurr != NULL && count < len) { if (etherMultiDebug) { logMsg("%x:%x:%x:%x:%x:%x\n", pCurr->addr[0], pCurr->addr[1], pCurr->addr[2], pCurr->addr[3], pCurr->addr[4], pCurr->addr[5]); } bcopy(pCurr->addr, (char *)&pTable->pTable[count], 6); count+=6; pTable->len += 6; pCurr = (ETHER_MULTI *)lstNext(&pCurr->node); } return (OK); }
STATUS etherInputHookAdd ( FUNCPTR inputHook, /* routine to receive Ethernet input */ char* pName, /* name of device if MUX/END is being used */ int unit /* unit of device if MUX/END is being used */ ) { HOOK_ENTRY *pHookEnt; HOOK_ENTRY *pHookCurr; void * pBinding = NULL; /* Existing END device binding, if any. */ BOOL tkDevice=FALSE; if (pName != NULL) /* We are dealing with an END. */ { if (etherInputHookActive == FALSE) /* First END driver hook? */ { if (etherInputHookRtn == NULL) { /* Initialize list - first network driver of either type. */ lstInit (&inputHookList); } etherInputHookActive = TRUE; } /* Check if bind is necessary and eliminate duplicate hook routine. */ for (pHookCurr = (HOOK_ENTRY *)lstFirst(&inputHookList); pHookCurr != NULL; pHookCurr = (HOOK_ENTRY *)lstNext(&pHookCurr->node)) { /* Ignore BSD device hook entries. */ if (pHookCurr->pCookie == NULL) continue; if (STREQ(pHookCurr->name, pName) && (pHookCurr->unit == unit)) { if (pHookCurr->routine == inputHook) return (ERROR); /* Additional hook for same device - reuse binding. */ pBinding = pHookCurr->pCookie; } } pHookEnt = malloc (sizeof (HOOK_ENTRY)); if (pHookEnt == NULL) return (ERROR); bzero ( (char *)pHookEnt, sizeof (HOOK_ENTRY)); if (pBinding == NULL) /* No hook entry for this END device? */ { /* Attach Ethernet input hook handler for this device. */ tkDevice = muxTkDrvCheck (pName); if (tkDevice) { pBinding = muxTkBind (pName, unit, nptEtherInputHookRtn, NULL, NULL, NULL, MUX_PROTO_SNARF, "etherInputHook", pHookEnt, NULL, NULL); } else { pBinding = muxBind (pName, unit, endEtherInputHookRtn, NULL, NULL, NULL, MUX_PROTO_SNARF, "etherInputHook", pHookEnt); } if (pBinding == NULL) { free (pHookEnt); return (ERROR); } } /* * Assign (new or existing) handler attachment for the device, * allowing hook deletion in any order. */ pHookEnt->pCookie = pBinding; strcpy (pHookEnt->name, pName); pHookEnt->unit = unit; pHookEnt->routine = inputHook; lstAdd (&inputHookList, &pHookEnt->node); } else /* Old style driver. */ { /* Check for duplicate hook routine. */ for (pHookCurr = (HOOK_ENTRY *)lstFirst(&inputHookList); pHookCurr != NULL; pHookCurr = (HOOK_ENTRY *)lstNext(&pHookCurr->node)) { if (pHookCurr->pCookie) /* Ignore END device hook entries. */ continue; if (pHookCurr->routine == inputHook) return (ERROR); } pHookEnt = malloc(sizeof(HOOK_ENTRY)); if (pHookEnt == NULL) return (ERROR); bzero ( (char *)pHookEnt, sizeof (HOOK_ENTRY)); if (etherInputHookRtn == NULL) /* First BSD driver hook? */ { etherInputHookRtn = etherInputHook; if (!etherInputHookActive) { /* Initialize list - first network driver of either type. */ lstInit (&inputHookList); } } pHookEnt->routine = inputHook; lstAdd(&inputHookList, &pHookEnt->node); } return (OK); }
STATUS hostAdd ( char *hostName, /* host name */ char *hostAddr /* host addr in standard Internet format */ ) { HOSTNAME *pHostNamePrev = NULL; /* pointer to previous host name entry */ FAST HOSTNAME *pHostName; /* pointer to host name entry */ FAST HOSTENTRY *pHostEntry; struct in_addr netAddr; /* network address */ if (hostName == NULL || hostAddr == NULL) { errnoSet (S_hostLib_INVALID_PARAMETER); return (ERROR); } if ((netAddr.s_addr = inet_addr (hostAddr)) == ERROR) return (ERROR); if (semTake (hostListSem, WAIT_FOREVER) == ERROR) return (ERROR); for (pHostEntry = (HOSTENTRY *)lstFirst (&hostList); pHostEntry != NULL; pHostEntry = (HOSTENTRY *)lstNext (&pHostEntry->node)) { if (pHostEntry->netAddr.s_addr == netAddr.s_addr) { /* host internet address already in table, add name as an alias */ pHostNamePrev = &pHostEntry->hostName; for (pHostName = &pHostEntry->hostName; pHostName != NULL; pHostName = pHostName->link) { /* make sure name is not already used for this address */ if (strcmp (pHostName->name, hostName) == 0) { semGive (hostListSem); errnoSet (S_hostLib_HOST_ALREADY_ENTERED); return (ERROR); } pHostNamePrev = pHostName; } if (pHostNamePrev == NULL) { /* XXX corrupted list! */ return (ERROR); } /* name not used for this address, add it as an alias */ if ((pHostNamePrev->link = (HOSTNAME *) KHEAP_ALLOC(sizeof (HOSTNAME))) == NULL) { semGive (hostListSem); return (ERROR); } bzero ((char *)pHostNamePrev->link, sizeof(HOSTNAME)); if (hostNameFill (pHostNamePrev->link, hostName) == ERROR) { semGive (hostListSem); return (ERROR); } semGive (hostListSem); return (OK); } } /* host name and internet address not in host table, add new host */ if ((pHostEntry = (HOSTENTRY *) KHEAP_ALLOC(sizeof (HOSTENTRY))) == NULL) { semGive (hostListSem); return (ERROR); } bzero ((char *)pHostEntry, sizeof(HOSTENTRY)); if ((hostNameFill (&pHostEntry->hostName, hostName)) == ERROR) { semGive (hostListSem); return (ERROR); } pHostEntry->netAddr = netAddr; lstAdd (&hostList, &pHostEntry->node); semGive (hostListSem); return (OK); }
BST_VOID BST_CTaskSchdler::UtranBlockInfoChgProc( BST_UINT32 *pulBlockInfo ) { BST_INT32 lTaskCnt; BST_UINT32 ulNextTickRemainTime; BST_UINT32 ulBlockInfo; BST_CORE_PTASK_NODE_STRU *pstPtaskNode; BST_CORE_PTASK_NODE_STRU *pstPtaskNodeNext; BST_BOOL bTimerStop; if( BST_NULL_PTR == pulBlockInfo) { return; } ulBlockInfo = (BST_UINT32 )*pulBlockInfo; BST_DBG_LOG2( "BST_CTaskSchdler::UtranBlockInfoChgProc blockold=u%, blockNew=u%", m_ulBlockInfo,ulBlockInfo); if ( m_ulBlockInfo == ulBlockInfo ) { return; } m_ulBlockInfo = ulBlockInfo; if ( BST_AS_UNBLOCKED == m_ulBlockInfo ) { BST_DBG_LOG1( "BST_CTaskSchdler::UtranBlockInfoChgProc :%d", m_bTaskMissExec ); if(BST_FALSE == m_bTaskMissExec) { return; } lTaskCnt = lstCount( &g_stPTaskList ); BST_DBG_LOG1( "BST_CTaskSchdler::UtranBlockInfoChgProc TaskNum=u%", lTaskCnt ); if ( 0 == lTaskCnt ) { return; } ulNextTickRemainTime = 0; bTimerStop = BST_OS_TimerIsStop( m_ulTimerId ); if ( BST_FALSE == bTimerStop ) { ulNextTickRemainTime = BST_OS_TimeGetRemain( m_ulTimerId ); BST_OS_TimerStop ( m_ulTimerId ); } BST_DBG_LOG2( "BST_CTaskSchdler::UtranBlockInfoChgProc stop:%d,timerremain=u%", bTimerStop,ulNextTickRemainTime ); /* * 遍历任务列表,获取任务并进行相应调度 */ for ( pstPtaskNode = ( BST_CORE_PTASK_NODE_STRU *)lstFirst( &g_stPTaskList ); pstPtaskNode!= BST_NULL_PTR; pstPtaskNode = pstPtaskNodeNext ) { pstPtaskNodeNext = ( BST_CORE_PTASK_NODE_STRU *) lstNext((NODE *)pstPtaskNode); if ( BST_NULL_PTR == pstPtaskNode->pcTask ) { continue; } /* * 如果任务不为空,则根据状态进行调度 */ TrigScheduleTask ( pstPtaskNode->pcTask); } if((0 == ulNextTickRemainTime) || (ulNextTickRemainTime > BST_TASK_SYS_BASE_TIMELEN)) { ulNextTickRemainTime = BST_TASK_SYS_BASE_TIMELEN; } BST_OS_TimerStart ( m_ulTimerId, ulNextTickRemainTime ); } }
void etherInputHookDelete ( FUNCPTR inputHook, char *pName, int unit ) { HOOK_ENTRY *pHookEnt; HOOK_ENTRY *pTarget = NULL; BOOL unbindFlag = TRUE; /* Remove handler if hook found? */ if (pName != NULL) /* END case */ { for (pHookEnt = (HOOK_ENTRY *)lstFirst(&inputHookList); pHookEnt != NULL; pHookEnt = (HOOK_ENTRY *)lstNext(&pHookEnt->node)) { /* Ignore BSD device hook entries. */ if (pHookEnt->pCookie == NULL) continue; if (STREQ(pHookEnt->name, pName) && (pHookEnt->unit == unit)) { if (pHookEnt->routine == inputHook) { /* * Found matching hook entry to remove. Keep searching * for other hooks on this device if needed. */ pTarget = pHookEnt; if (!unbindFlag) /* Another hook already found? */ break; } else { /* * Different hook on same driver - do not unbind. * Stop searching if target hook entry already found. */ unbindFlag = FALSE; if (pTarget) break; } } } if (pTarget) /* Remove hook entry if match found. */ { if (unbindFlag) /* Remove binding if last hook for device. */ { if (muxTkDrvCheck (pName)) { muxUnbind (pTarget->pCookie, MUX_PROTO_SNARF, nptEtherInputHookRtn); } else { muxUnbind (pTarget->pCookie, MUX_PROTO_SNARF, endEtherInputHookRtn); } } lstDelete (&inputHookList, &pTarget->node); free (pTarget); } } else /* 4.4 case */ { for (pHookEnt = (HOOK_ENTRY *)lstFirst(&inputHookList); pHookEnt != NULL; pHookEnt = pTarget) { if (pHookEnt->pCookie) /* Ignore END device hook entries. */ continue; pTarget = (HOOK_ENTRY *)lstNext(&pHookEnt->node); if (pHookEnt->routine == inputHook) { lstDelete(&inputHookList, &pHookEnt->node); free(pHookEnt); } } } if (lstCount(&inputHookList) <= 0) { etherInputHookActive = FALSE; /* No END driver hooks installed. */ etherInputHookRtn = NULL; /* No BSD driver hooks installed. */ lstFree (&inputHookList); } }
STATUS hostDelete ( char *name, /* host name or alias */ char *addr /* host addr in standard Internet format */ ) { HOSTNAME *pHostNamePrev; /* pointer to previous host name entry */ HOSTNAME *pHostNameNext; /* pointer to next host name entry */ FAST HOSTNAME *pHostName; FAST HOSTENTRY *pHostEntry; struct in_addr netAddr; if (name == NULL || addr == NULL) { errnoSet (S_hostLib_INVALID_PARAMETER); return (ERROR); } /* convert from string to int format */ if ((netAddr.s_addr = inet_addr (addr)) == ERROR) return ERROR; semTake (hostListSem, WAIT_FOREVER); /* search inet address */ for (pHostEntry = (HOSTENTRY *)lstFirst (&hostList); pHostEntry != NULL; pHostEntry = (HOSTENTRY *)lstNext (&pHostEntry->node)) { if (pHostEntry->netAddr.s_addr != netAddr.s_addr) continue; if (strcmp (pHostEntry->hostName.name, name) == 0) /* given name is exact match */ { FAST HOSTNAME * pAlias = pHostEntry->hostName.link; FAST HOSTNAME * pNext = NULL; /* free all associated alias(es) 1st if any, then free itself */ for ( ; pAlias != NULL; pAlias = pNext) { pNext = pAlias->link; KHEAP_FREE(pAlias->name); KHEAP_FREE((char *) pAlias); } lstDelete (&hostList, &pHostEntry->node); semGive (hostListSem); KHEAP_FREE(pHostEntry->hostName.name); KHEAP_FREE((char *) pHostEntry); return (OK); } else /* given name is an alias */ { for (pHostNamePrev = pHostName = &pHostEntry->hostName; pHostName != NULL; pHostNamePrev = pHostName, pHostName = pHostName->link) { pHostNameNext = pHostName->link; if (strcmp (pHostName->name, name) == 0) /* found alias */ { pHostNamePrev->link = pHostNameNext; semGive (hostListSem); KHEAP_FREE(pHostName->name); KHEAP_FREE((char *) pHostName); return (OK); } } } } errnoSet (S_hostLib_UNKNOWN_HOST); semGive (hostListSem); return (ERROR); }
int etherMultiAdd ( LIST *pList, /* pointer to list of multicast addresses */ char* pAddress /* address you want to add to list */ ) { ETHER_MULTI* pCurr; /* * Verify that we have valid Ethernet multicast addresses. */ if ((pAddress[0] & 0x01) != 1) { if (etherMultiDebug) logMsg("Invalid address!\n", 1, 2, 3, 4, 5, 6); return (EINVAL); } /* * See if the address range is already in the list. */ for (pCurr = (ETHER_MULTI *)lstFirst(pList); pCurr != NULL && (bcmp(pCurr->addr, pAddress, 6) != 0); pCurr = (ETHER_MULTI *)lstNext(&pCurr->node)); if (pCurr != NULL) { /* * Found it; just increment the reference count. */ if (etherMultiDebug) logMsg("Address already exists!\n", 1, 2, 3, 4, 5, 6); ++pCurr->refcount; return (0); } /* * New address or range; malloc a new multicast record * and link it into the interface's multicast list. */ pCurr = (ETHER_MULTI *) KHEAP_ALLOC(sizeof(ETHER_MULTI)); if (pCurr == NULL) { if (etherMultiDebug) logMsg("Cannot allocate memory!\n", 1, 2, 3, 4, 5, 6); return (ENOBUFS); } bcopy((char *)pAddress, (char *)pCurr->addr, 6); pCurr->refcount = 1; lstAdd(pList, &pCurr->node); if (etherMultiDebug) { logMsg("Added address is %x:%x:%x:%x:%x:%x\n", pCurr->addr[0], pCurr->addr[1], pCurr->addr[2], pCurr->addr[3], pCurr->addr[4], pCurr->addr[5]); } /* * Return ENETRESET to inform the driver that the list has changed * and its reception filter should be adjusted accordingly. */ return (ENETRESET); }
STATUS mirrorEndRunningState(void) { BRIDGE_PORT_INFO* pPortInfo; END_OBJ *pEnd0, *pEnd1; END_MEDIA media; int error; long flags; pEnd1 = endFindByName (MIRROR_DEV_NAME,MIRROR_STACK_UNIT_NUM); pEnd0 = endFindByName (MIRROR_DEV_NAME,MIRROR_BRIDGE_UNIT_NUM); if (pEnd1) flags = END_FLAGS_GET(pEnd1); else return OK; for (pPortInfo = (BRIDGE_PORT_INFO*)lstFirst(&bridgePortList); (pPortInfo != NULL) && (strcmp(pPortInfo->name, MIRROR_DEV_NAME)!=0); pPortInfo = (BRIDGE_PORT_INFO*)lstNext((NODE*)pPortInfo)) { muxIoctl(pPortInfo->pMuxBindCookie,EIOCGIFMEDIA,(char *)&media); LOG_MSG("mirrorEndRunningState: port %s, unit %d, status 0x%x\n", pPortInfo->name, pPortInfo->unitNum, media.endMediaStatus, 4, 5, 6); if ((media.endMediaStatus & (IFM_AVALID|IFM_ACTIVE)) == (IFM_AVALID|IFM_ACTIVE)) { if ((flags & IP_IFF_RUNNING) == 0) { LOG_MSG("mirrorEndRunningState: state changed to RUNNING\n", 1, 2, 3, 4, 5, 6); /* raise both interface flags - mark the devices as RUNNING */ if (pEnd0) END_FLAGS_SET (pEnd0, IP_IFF_RUNNING); END_FLAGS_SET (pEnd1, IP_IFF_RUNNING); /* inform the stack about the interface UP state change */ jobQueueStdPost (netJobQueueId, NET_TASK_QJOB_PRI, muxLinkUpNotify, pEnd1, NULL, NULL, NULL, NULL); } return OK; } } if (flags & IP_IFF_RUNNING) { LOG_MSG("mirrorEndRunningState: state changed to NOT RUNNING\n", 1, 2, 3, 4, 5, 6); /* mark both drivers as NOT RUNNING */ if (pEnd0) END_FLAGS_CLR (pEnd0, IP_IFF_RUNNING); END_FLAGS_CLR (pEnd1, IP_IFF_RUNNING); /* inform the stack about the interface UP state change */ jobQueueStdPost (netJobQueueId, NET_TASK_QJOB_PRI, muxLinkDownNotify, pEnd1, NULL, NULL, NULL, NULL); } return OK; }