📄 xp_osi_filte.c
字号:
{ (notify_fn)(&Info); } } /*------------------------------------------------------------------------+ | Process any pending filter operations +------------------------------------------------------------------------*/ xp_osi_filter_process_pending(pGlobal,wChannelId);// xp_os_semaphore_signal();}/*----------------------------------------------------------------------------+| xp0_filter_valid+----------------------------------------------------------------------------*/SHORT xp_osi_filter_valid(GLOBAL_RESOURCES *pGlobal,SHORT wFilterId){ if((wFilterId < 0) || (wFilterId >= XP_FILTER_MAX_BLOCKS)) { return(XP_ERROR_FILTER_INVALID); } if(pGlobal->FilterInfo.pXpFilterData[wFilterId] == NULL) { return(XP_ERROR_FILTER_FREE); } return(0);}/*----------------------------------------------------------------------------+| XX XXXXXX XXXXXX XXXXX| XXXX XX XX XX XX XX| XX XX XX XX XX XX| XX XX XXXXX XX XX| XXXXXX XX XX XX| XX XX XX XX XX XX| XX XX XX XXXXXX XXXXX+----------------------------------------------------------------------------*//*----------------------------------------------------------------------------+| xp0_filter_add_to_channel+-----------------------------------------------------------------------------+|| DESCRIPTION: add table section filter to channel|| PROTOTYPE : short xp0_filter_add_to_channel(| short channel_id,| short filter_id)|| ARGUMENTS : channel_id - the channel id as returned from the| xp0_channel_allocate().| filter_id - the filter number as returned from the| xp0_filter_allocate().|| RETURNS : match_id if the operation was successful, or a negative| value if an error occurs|| ERRORS : XP_ERROR_CHANNEL_INVALID - channel_id is not defined| XP_ERROR_FILTER_INVALID - one or more filters invalid| XP_ERROR_INTERNAL - failed allocating space|| COMMENTS : This function adds a filter to the channel. The match| id. returned may be used with the match word when data| is delivered to the application. This match id. is a| bit position in the match word.|| Filters may be added to an active channel.|+----------------------------------------------------------------------------*/SHORT xp_osi_filter_add_to_channel(GLOBAL_RESOURCES *pGlobal,SHORT wChannelId,SHORT wFilterId){ short rc; short i=0; /* index into channel_data array */ short j; short count; FILTER_TYPE *pFilter=NULL; FILTER_CHANNEL_TYPE *pChannel=NULL;// short *list;// xp_os_semaphore_wait(); /*------------------------------------------------------------------------+ | Verify the channel and filter id's are valid +------------------------------------------------------------------------*/ rc = xp_osi_channel_valid(pGlobal,wChannelId); if(rc == 0) { rc = xp_osi_filter_valid(pGlobal,wFilterId); } /*------------------------------------------------------------------------+ | Check that the filter has been defined +------------------------------------------------------------------------*/ if(rc == 0) { pFilter = pGlobal->FilterInfo.pXpFilterData[wFilterId]; pChannel = &pGlobal->FilterInfo.XpFilterChData[wChannelId]; switch(pFilter->state) { case XP_FILTER_UNUSED: rc = XP_ERROR_FILTER_UNDEFINED; break; case XP_FILTER_DEFINED: break; case XP_FILTER_ENABLED: case XP_FILTER_DISABLED: rc = XP_ERROR_FILTER_INUSE; break; default: rc = XP_ERROR_INTERNAL; break; } } if(rc == 0) { if(pFilter->pending != PENDING_NONE) { rc = XP_ERROR_FILTER_PENDING; } } /*------------------------------------------------------------------------+ | Find an unused index to add the filter to the channel +------------------------------------------------------------------------*/ if (rc == 0) { for(i=0; i<pChannel->wCount; i++) { if(pChannel->wFilterId[i] == FILTER_ID_UNUSED) { break; } } if(i >= 32) { rc = XP_ERROR_FILTER_MAX; } /*--------------------------------------------------------------------+ | Allocate additional space if there are no available blocks | Allocate/realloc space and increase space by groups of 4 +--------------------------------------------------------------------*/ else if(i == pChannel->wCount) { count = 32; for(j=pChannel->wCount;j<count;j++) { pChannel->wFilterId[j] = FILTER_ID_UNUSED; } pChannel->wCount = count; } } /*------------------------------------------------------------------------+ | Define the new hardware filter links now, add the filter_id to the | channel add the filter_id to the sorted array +------------------------------------------------------------------------*/ if(rc == 0) { pFilter->state = XP_FILTER_DISABLED; pFilter->wChannelId = wChannelId; pFilter->wMatchId = i; hw_filter_add(pGlobal,pChannel, wChannelId, pFilter); pChannel->wFilterId[i] = wFilterId; pChannel->wInuse++; }// xp_os_semaphore_signal(); /*------------------------------------------------------------------------+ | If there were errors, return the error code +------------------------------------------------------------------------*/ if(rc) { return(rc); } return(i);}/*----------------------------------------------------------------------------+| xp0_filter_allocate+-----------------------------------------------------------------------------+|| DESCRIPTION: allocate space for a table section filter|| PROTOTYPE : short xp0_filter_allocate(| unsigned short length)|| ARGUMENTS : length - number of bytes defined to the filter|| RETURNS : filter_id if the operation was successful, or a negative| value if an error occurs|| ERRORS : XP_ERROR_FILTER_UNAVAILABLE - not enough filters available|| COMMENTS : This function allocates space to contain the filter| definition, and reserves filter blocks in hardware. The| reserved filter blocks are linked together to save time| when the filter is added to a channel.|+----------------------------------------------------------------------------*/SHORT xp_osi_filter_allocate(GLOBAL_RESOURCES *pGlobal, ULONG ulLength){ short rc=0; short i=0; short j=0; short count; FILTER_TYPE *pFilter=NULL;// xp_os_semaphore_wait(); PDEBUG("Entering into xp_osi_filter_allocate\n"); /*------------------------------------------------------------------------+ | Try to process any pending section filter changes. +------------------------------------------------------------------------*/ if(pGlobal->FilterInfo.ulXpFilterSectionChange) { process_section_change(pGlobal); } if(ulLength == 0) { rc = XP_ERROR_FILTER_BAD_LENGTH; } /*------------------------------------------------------------------------+ | Find the index of the filter block +------------------------------------------------------------------------*/ if (rc == 0) { for (i=0; i<XP_FILTER_MAX_BLOCKS; i++) { if(pGlobal->FilterInfo.pXpFilterData[i] == NULL) { break; } } if(i == XP_FILTER_MAX_BLOCKS) { rc = XP_ERROR_FILTER_UNAVAILABLE; } } /*------------------------------------------------------------------------+ | Allocate a new filter, and initialize pointers to NULL +------------------------------------------------------------------------*/ if(rc == 0) { pFilter = (FILTER_TYPE *) MALLOC(sizeof(FILTER_TYPE)); if(pFilter == NULL) { rc = XP_ERROR_INTERNAL; } } if (rc == 0) { pFilter->state = XP_FILTER_UNUSED; pFilter->pending = 0; pFilter->wChannelId = XP_CHANNEL_COUNT; pFilter->uwLength = ulLength; for(j = 0; j<XP_FILTER_MAX_BLOCKS; j++) { pFilter->cData[j] = 0; pFilter->cMask[j] = 0; pFilter->cPolarity[j] = 0; pFilter->cHwBlockId[j] = 0; } pFilter->wSoftFilter = 0; /*--------------------------------------------------------------------+ | We skip bytes 1,2 and use bytes 0, 3,4,5,... so hardware filtering | length is always 2 bytes less than the total since bytes 1, & 2 | are not filtered Calculate the number of hardware blocks based on | the ceiling of a 4 byte block +--------------------------------------------------------------------*/ if(ulLength < 3) { count = 1; } else { count = ulLength - 2; } /*--------------------------------------------------------------------+ | Allocate space for the block id's, and then reserve these blocks +--------------------------------------------------------------------*/ pFilter->uwHwBlockCount = (count + 3) / 4; } if(rc == 0) { rc = reserve_hw_blocks(pGlobal,pFilter->uwHwBlockCount, pFilter->cHwBlockId); } if(rc == 0) { init_filter_links(pGlobal,pFilter); PDEBUG("i = %d\n",i); PDEBUG("pFilter = %x\n",pFilter); pGlobal->FilterInfo.pXpFilterData[i] = pFilter; }// xp_os_semaphore_signal(); /*------------------------------------------------------------------------+ | Clean up any allocate space due to errors +------------------------------------------------------------------------*/ if (rc) { if(pFilter) { FREE(pFilter); } return(rc); } /*------------------------------------------------------------------------+ | Return the filter id which was setup +------------------------------------------------------------------------*/ return(i);}/*----------------------------------------------------------------------------+| xp0_filter_control+-----------------------------------------------------------------------------+|| DESCRIPTION: controls the state of the filter|| PROTOTYPE : short xp0_filter_control(| short filter_id,| FILTER_CONTROL_TYPE cmd)|| ARGUMENTS : filter_id - the filter_id as returned from the| xp0_filter_allocate()| cmd - XP_FILTER_CONTROL_ENABLE - enable filter| XP_FILTER_CONTROL_DISABLE - disable filter|| RETURNS : 0 if successful, or non-zero if an error occurs
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -