kb_dc_filterdata.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:8k
- /*****************************************************************************
- File name : kb_dc_filterdata.c
- Description: Private Section filter for download.
- COPYRIGHT (C) STMicroelectronics 2004.
- *****************************************************************************/
- //-----------------------------------------------------------------------------
- // Project include files:
- //-----------------------------------------------------------------------------
- #include "kb_dc_pub.h"
- KB_DC_FILTER_STATUS filter_status = FILTER_READY;
- UINT32 DCchannelID;
- UINT32 DCfilterID;
- static unsigned char DCSectionHardMask[8];
- static unsigned char DCSectionHardValue[8];
- unsigned char byFilterBuf[PSI_SECTION_SIZE];
- int KB_DC_DmxInit(void)
- {
- signed long nReturn;
- #define FILTER_DEPTH (8)
-
- nReturn = KB_DmxAllocateChnnl(DMX_CHANNEL_SECTION, 5 * 1024, TRUE, &DCchannelID);
- if(nReturn != 0)
- {
- DCDebug1("KD_DmxAllocateChnnl fail = %ldn",nReturn);
- return -1;
- }
- KB_DmxRegNotice(DCchannelID, DCGetSectionCallback);
- nReturn = KB_DmxAllocateFilter(DMX_SECTION_FILTER, FILTER_DEPTH, &DCfilterID);
- if(nReturn != 0)
- {
- DCDebug1("KD_DmxAllocateFilter fail = %ldn",nReturn);
- return -1;
- }
- DCDebug4("n DCchannelID=%ld",DCchannelID);
- DCDebug4("n DCfilterID=%ld",DCfilterID);
- nReturn = KB_DmxAssociateFilter(DCchannelID, DCfilterID);
- if(nReturn != 0)
- {
- DCDebug1("KD_DmxAssociateFilter fail = %ldn",nReturn);
- return -1;
- }
-
- return 0;
- }
- int KB_DC_FilterStop(void)
- {
- int ErrorCode = RETFIAL1;
-
- ErrorCode = KB_DmxControlChnnl(DCchannelID, KB_DMX_STOP);
- if(RETOK != ErrorCode)
- {
- return -1;
- }
-
- return 0;
- }
- int KB_DC_FilterStart(void)
- {
- int ErrorCode = RETFIAL1;
-
- ErrorCode = KB_DmxControlChnnl(DCchannelID, KB_DMX_START);
- if(RETOK != ErrorCode)
- {
- return -1;
- }
-
- return 0;
- }
- static signed long Kb_Filter_Setup(unsigned long lFilterId, unsigned short lPid,
- unsigned short lTableId, unsigned short lTableIdExt,
- unsigned short lVersion, unsigned short lSectionNumber)
- {
- unsigned char byte1, byte2;
- INT32 sErr = Err_OK;
- KB_DmxControlChnnl(DCchannelID,KB_DMX_STOP);
- KB_DmxDisassociateFilter(DCchannelID, lFilterId);
- sErr = KB_DmxFreeFilter(lFilterId);
- if(Err_OK != sErr )
- {
- DCDebug1("[LOADER]:KD_DmxFreeFilter error[0x%x].nr ",sErr);
- return sErr;
- }
-
- KBDcMemset(DCSectionHardMask, 0, 8);
- if(lTableId != UNSET_PARAM)
- {
- DCSectionHardMask[0] = 0xff;
- DCSectionHardValue[0] = (unsigned char)lTableId;
- }
- if(lTableIdExt != UNSET_PARAM)
- {
- byte1 = (unsigned char)((lTableIdExt >> 8) & 0xff);
- byte2 = (unsigned char)(lTableIdExt & 0xff);
-
- DCSectionHardMask[3] = 0xff;
- DCSectionHardMask[4] = 0xff;
- DCSectionHardValue[3] = byte1;
- DCSectionHardValue[4] = byte2;
- if(lTableId == 0xfe && byte2 == 0xff)
- {
- DCSectionHardMask[2] = 0x00;
- }
- }
- if(lVersion != UNSET_PARAM)
- {
- DCSectionHardMask[5] = 0x02;
- DCSectionHardValue[5] = (unsigned char)(~lVersion);
- }
- if(lSectionNumber != UNSET_PARAM)
- {
- DCSectionHardMask[6] = 0xff;
- DCSectionHardValue[6] = (unsigned char)lSectionNumber;
- }
- #if 0
- DCDebug4("nvalue[8]={%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x}", DCSectionHardValue[0], DCSectionHardValue[1],DCSectionHardValue[2], DCSectionHardValue[3],
- DCSectionHardValue[4], DCSectionHardValue[5],DCSectionHardValue[6], DCSectionHardValue[1]);
- DCDebug4("nmask[8]= {%02x,%02x,%02x,%02x,%02x,%02x,%02x,%02x}", DCSectionHardMask[0], DCSectionHardMask[1],DCSectionHardMask[2], DCSectionHardMask[3],
- DCSectionHardMask[4], DCSectionHardMask[5],DCSectionHardMask[6], DCSectionHardMask[1]);
- #endif
- sErr = KB_DmxAllocateFilter(DMX_SECTION_FILTER, 8, &DCfilterID);
- if(sErr != 0)
- {
- DCDebug1("DDB_FilterSet KD_DmxAllocateFilter fail = %ldn",sErr);
- return -1;
- }
-
- sErr = KB_DmxAssociateFilter(DCchannelID, DCfilterID);
- if(sErr != 0)
- {
- DCDebug1("DDB_FilterSet KB_DmxAssociateFilter fail = %ldn",sErr);
- return -1;
- }
- KB_DmxSetChnnlPID(DCchannelID, lPid);
- sErr = KB_DmxSetFilter(DCfilterID, DCSectionHardValue, DCSectionHardMask, 0);
- if(Err_OK != sErr)
- {
- DCDebug1("DDB_FilterSet KB_DmxSetFilter fail = %ldn",sErr);
- return sErr;
- }
-
- return (sErr);
- }
- unsigned long KB_DC_FilterReSet(unsigned short lPid, unsigned short lTableId, unsigned short lTableIdExt, unsigned short lVersion, unsigned short lSectionNumber)
- {
- unsigned long ErrCode =Err_OK;
-
- DCDebug3("n KB_DC_FilterReSet: lPid=%x, lTableId=%x, lTableIdExt=%x, lSectionNumber=%x", lPid, lTableId, lTableIdExt, lSectionNumber);
- ErrCode = Kb_Filter_Setup(DCfilterID, lPid, lTableId, lTableIdExt, UNSET_PARAM, lSectionNumber);
- if(Err_OK != ErrCode)
- {
- return ErrCode;
- }
- Section_Pool_Reset();
-
- return Err_OK;
- }
- KB_DC_FILTER_STATUS KB_DC_FilterStatGet(void)
- {
- return filter_status;
- }
- void KB_DC_FilterStatSet(KB_DC_FILTER_STATUS status)
- {
- filter_status = status;
- }
- int DTV_SectionGet(unsigned char *buf, unsigned char *ptr, int *sec_len, PSI_MALLOC_OPT flag)
- {
- unsigned char *read_ptr=NULL;
- unsigned char *dest,cur_sec,last_sec;
-
- if( buf==NULL)
- {
- DCDebug1("rnSection found null.");
- return -1;
- }
-
- //第一个字节是 TABLE ID
- read_ptr = buf;
- *sec_len=(((read_ptr[1] << 8) | read_ptr[2]) & 0x0FFF);
- cur_sec = read_ptr[6];
- last_sec = read_ptr[7];
- DCDebug4("n PSI_SectionGet Section : %1x Len=%d, cur=%x, flag %d",read_ptr[0],*sec_len,cur_sec,flag);
- switch(flag)
- {
- case PSI_S_ALLOC_NONE:
- dest = (unsigned char *)ptr;
- break;
- case PSI_S_ALLOC_SECTION:
- if((dest=(unsigned char *)KBDcMalloc(PSI_SECTION_SIZE))==NULL)
- {
- DCDebug1("PSI_get_sction: Out of memory!rn");
- return DC_NOT_OK;
- }
- *((unsigned char **)ptr) = dest;
- break;
- case PSI_S_ALLOC_TABLE:
- if((dest=(unsigned char *)KBDcMalloc(((UINT32)PSI_SECTION_SIZE*((UINT32)last_sec+1))))==NULL)
- {
- DCDebug1("PSI_get_sction: Out of memory!!! size = %drn", PSI_SECTION_SIZE*(last_sec+1));
- return DC_NOT_OK;
- }
- *((unsigned char **)ptr) = dest;
- break;
- default:
- break;
- }
- KBDcMemcpy(dest, read_ptr,(*sec_len)+3 );
-
- return DC_OK;
- }
- int KB_DC_GetTable(unsigned short pid,
- unsigned char tableId,
- unsigned int extId,
- unsigned char ** table_info,
- int style)
- {
- ST_ErrorCode_t ErrCode;
- unsigned short Pid;
- unsigned char Tableid;
- U8 Instance=0;
- U32 Section = 0;
- int sec_len=0;
- unsigned short iDataSize =0;
- int total_sec_len=0;
- unsigned char *dest_ptr=NULL;
- Tableid = tableId;
- Pid = pid;
- KBDcMemset(byFilterBuf, 0, PSI_SECTION_SIZE);
- do
- {
- ErrCode = KB_DC_FilterReSet( Pid, Tableid, extId, UNSET_PARAM, Section);
- if ( ErrCode != Err_OK )
- break;
- ErrCode = KB_DC_GetSection(byFilterBuf, &iDataSize);
- if(Err_OK != ErrCode)
- {
- DCDebug1("nr Get section error[%d].rn",ErrCode );
- return ErrCode;
- }
- if(Section==0)
- {
- *table_info = NULL;
- if(DTV_SectionGet(byFilterBuf, (unsigned char *)table_info,&sec_len, PSI_S_ALLOC_TABLE)!=DC_OK)
- {
- ErrCode = -1;
- DCDebug1("rnGet PSI Section Error 0!");
- break;
- }
-
- DCDebug4("n DTV_GetTable:sec_len=%d",sec_len);
- dest_ptr = *table_info;
- dest_ptr += sec_len + 3;
-
- }
- else
- {
- if(DTV_SectionGet(byFilterBuf, (unsigned char *)dest_ptr,&sec_len, PSI_S_ALLOC_NONE)!=DC_OK)
- {
- ErrCode = -2;
- DCDebug1("==no table id=%xrn", tableId);
- break;
- }
- dest_ptr += sec_len + 3;
- }
- total_sec_len+=sec_len+3;
- DCDebug3(" n -------cursec=%d -have received %d byte data",byFilterBuf[6],total_sec_len);
- if(ErrCode!=0 && *table_info )
- {
- KBDcFree(*table_info);
- *table_info=0;
- }
- }while ( Section++ < byFilterBuf[LASTSECT_IDX]);
- return total_sec_len;
- }
- /* EOF --------------------------------------------------------------------- */