⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dvb_caemm.c

📁 我国有线电视条件接受标准目前还没有统一
💻 C
📖 第 1 页 / 共 2 页
字号:
	{		if((pucBuffer[4] + 1)!= g_stEmmSec.ucMaxSectionNum			 || pucBuffer[5] != g_stEmmSec.ucEmmType)		{			g_usEmmSecLen = 0;							memset(&g_stEmmSec, 0x0, sizeof(ST_EMM_SECTION));			}		for(i = 0; i < g_stEmmSec.ucSectionNum; i++)		{			if(pucBuffer[3] == g_stEmmSec.aucSectionID[i])				return;		}		g_stEmmSec.ucMaxSectionNum = pucBuffer[4] + 1;		g_stEmmSec.ucEmmType = pucBuffer[5];		usSectionLen = (pucBuffer[1] << 8) | pucBuffer[2];		usSectionLen = usSectionLen & 0x0FFF;		g_stEmmSec.pucSectionAddr[g_stEmmSec.ucSectionNum] = (UINT8 *)(g_ucEmmSecBuffer + g_usEmmSecLen);		g_stEmmSec.aucSectionID[g_stEmmSec.ucSectionNum] = pucBuffer[3];		if(pucBuffer[3] == 0x00)			g_stEmmSec.aucSectionLen[g_stEmmSec.ucSectionNum] = usSectionLen + 3 - 4;		else			g_stEmmSec.aucSectionLen[g_stEmmSec.ucSectionNum] = usSectionLen - 7;		g_usEmmSecLen += g_stEmmSec.aucSectionLen[g_stEmmSec.ucSectionNum];		if(g_usEmmSecLen > MAX_EMM_BUFFER_SIZE)		{			g_usEmmSecLen = 0;							memset(&g_stEmmSec, 0x0, sizeof(ST_EMM_SECTION));				return;		}				if(pucBuffer[3] == 0x00)			memcpy(g_stEmmSec.pucSectionAddr[g_stEmmSec.ucSectionNum], pucBuffer, usSectionLen + 3 - 4);		else			memcpy(g_stEmmSec.pucSectionAddr[g_stEmmSec.ucSectionNum], pucBuffer + 6, usSectionLen - 7);		g_stEmmSec.ucSectionNum++;		if(g_stEmmSec.ucSectionNum < g_stEmmSec.ucMaxSectionNum)			return;		usSectionLen = 0;		for(i = 0; i < g_stEmmSec.ucSectionNum; i++)		{			for(j = 0; j < g_stEmmSec.ucSectionNum; j++)			{				if(i == g_stEmmSec.aucSectionID[j])					break;			}			if(j == g_stEmmSec.ucSectionNum)				break;			memcpy(pucBuffer + usSectionLen, g_stEmmSec.pucSectionAddr[j], g_stEmmSec.aucSectionLen[j]);			usSectionLen += g_stEmmSec.aucSectionLen[j];		}					if(i != g_stEmmSec.ucSectionNum || (usSectionLen + 4 - 3) > MAX_EMM_BUFFER_SIZE)		{			g_usEmmSecLen = 0;							memset(&g_stEmmSec, 0x0, sizeof(ST_EMM_SECTION));			return;		}		g_usEmmSecLen = 0;						memset(&g_stEmmSec, 0x0, sizeof(ST_EMM_SECTION));		uiCrcValue = crc32(pucBuffer, usSectionLen);		pucBuffer[usSectionLen] = (uiCrcValue>> 24) & 0xFF;		pucBuffer[usSectionLen + 1] = (uiCrcValue>> 16) & 0xFF;		pucBuffer[usSectionLen + 2] = (uiCrcValue>> 8) & 0xFF;		pucBuffer[usSectionLen + 3] = (uiCrcValue) & 0xFF;		usSectionLen = (usSectionLen + 4 - 3);		pucBuffer[1] = (pucBuffer[1] & 0xF0) | ((usSectionLen >> 8) & 0x0F);		pucBuffer[2] = (usSectionLen & 0xFF);		pucBuffer[3] = 0;		pucBuffer[4] = 0;	}	else	{		g_usEmmSecLen = 0;						memset(&g_stEmmSec, 0x0, sizeof(ST_EMM_SECTION));		}	#endif	int iReturnMsg = 0;	memset(&g_stEmmPack, 0x0, sizeof(S_HLCAPack));		HLCA_ParsePack(pucBuffer,&g_stEmmPack);	if(g_stEmmPack.isParseSucees == 1)	{		switch(g_stEmmPack.EMMType)		{			case NETPARA:				DVB_CAService_SetDisableArea(g_stEmmPack.contents.NetPara.areaDisablesum,					g_stEmmPack.contents.NetPara.areano);				DVB_CAService_SetStbMark(g_stEmmPack.contents.NetPara.stbAndScardMatchSgn);				#if defined(SDT_CA_40)				DVB_CAEMM_UpdateTime(&(g_stEmmPack.contents.NetPara.curtime));				#endif								DVB_CAService_SetNetwork(g_stEmmPack.contents.NetPara.net_number);								ucMessage = CA_NEW_SERVICE;				stMsg.u8MsgID   	= DVB_MODULE_ID;				stMsg.u8SubModID = CA_UI_ID;				stMsg.u16FuncID  	= CA_MESSAGE;				stMsg.pData = (void *)&ucMessage;				DVB_SendBackMsg(&stMsg, 1);									#if defined(SDT_CA_50)				DVB_CAService_SetNetName((UINT8 *)g_stEmmPack.contents.NetPara.net_name);				DVB_CAService_SetFaceTime(g_stEmmPack.contents.NetPara.STBFace_Stop_Timer);				if(g_ucFreqVer == 0xFF)					g_ucFreqVer = DVB_CAService_GetFreqVer();				if(g_stEmmPack.contents.NetPara.freq_change_count > 0 					&& g_ucFreqVer != g_stEmmPack.contents.NetPara.freq_change_version)				{					g_ucFreqVer = g_stEmmPack.contents.NetPara.freq_change_version;					/*g_ucFreqNum = g_stEmmPack.contents.NetPara.freq_change_count;					if(g_ucFreqNum > MAX_FREQ_NUM)						g_ucFreqNum = MAX_FREQ_NUM;					memcpy(g_stFreq, g_stEmmPack.contents.NetPara.frequ_symbol, g_ucFreqNum * sizeof(S_Frequ_Symbol));*/					int iFreqPos = 0;					g_ucFreqNum = 0;					for(iFreqPos = 0; iFreqPos < g_stEmmPack.contents.NetPara.freq_change_count && g_ucFreqNum < MAX_FREQ_NUM; iFreqPos++)					{						#if defined(DVB_QAM)						if(g_stEmmPack.contents.NetPara.frequ_symbol[iFreqPos].modunation != 0)						#elif defined(DVB_QPSK)						if(g_stEmmPack.contents.NetPara.frequ_symbol[iFreqPos].modunation == 0)						#endif												{							memcpy(&(g_stFreq[g_ucFreqNum]),&(g_stEmmPack.contents.NetPara.frequ_symbol[iFreqPos]), sizeof(S_Frequ_Symbol));							g_ucFreqNum++;						}					}					if(g_ucFreqNum > 0)					{						g_ucFreqNew = 1;												ucMessage = CA_NEW_FREQ;						stMsg.u8MsgID   	= DVB_MODULE_ID;						stMsg.u8SubModID = CA_UI_ID;						stMsg.u16FuncID  	= CA_MESSAGE;						stMsg.pData = (void *)&ucMessage;						DVB_SendBackMsg(&stMsg, 1);					}				}				#endif				break;		 	case EMM:				if(DVB_CAService_SetService(&g_stEmmPack.contents.EMM) >= 0)				{					main_prog_msg_t stMsg;					UINT8 ucMessage = CA_NEW_SERVICE;					stMsg.u8MsgID   	= DVB_MODULE_ID;					stMsg.u8SubModID = CA_UI_ID;					stMsg.u16FuncID  	= CA_MESSAGE;					stMsg.pData = (void *)&ucMessage;					DVB_SendBackMsg(&stMsg, 1);				}				break;		 	case MAIL:				DVB_CAEMM_Mail();				break;		 	case MSG:				DVB_CAEMM_Message();				break;		 	case STB_FACE:				if(g_stEmmPack.contents.STB_face.millMark == SUNPLUS)					DVB_CALogo_AddBlock(&g_stEmmPack.contents.STB_face);				break;		 	case STBUPDATE_FREQU:				DVB_CAEMM_UpgradeInfo();				break;		 	case BROADCAST_FREQU:				if(g_pAddFreq)					g_pAddFreq(&(g_stEmmPack.contents.broadcast_frequ));				break;		 	case BROADCAST_DATA:				if(g_pAddChild)					g_pAddChild(&(g_stEmmPack.contents.broadcastdata));				break;			default:				break;		}		HLCA_FreeMem(&g_stEmmPack, g_stEmmPack.EMMType);	}}static UINT16 DVB_CAEMM_ParseCat(UINT8 *pucBuffer){	UINT16 usPos = 0;	UINT16 usEmmPid = 0x1FFF;	UINT16 usSectionLen = 0;		if(pucBuffer == NULL)		goto ERROR;	if(pucBuffer[0] != CAT_TABLED_ID)		goto ERROR;	usSectionLen = ((pucBuffer[1] & 0x0f) << 8) | (pucBuffer[2] & 0xFF);	usPos = 8;	while(((usPos + 4) < (usSectionLen + 3)) && (usEmmPid == 0x1FFF))	{		UINT8 ucDescTag;		UINT8 ucDescLen;		UINT16 usCaSysId = 0;		ucDescTag = pucBuffer[usPos];		ucDescLen = pucBuffer[usPos + 1];		usPos += 2;		switch(ucDescTag)		{			case CA_DESC_TAG:				usCaSysId = (pucBuffer[usPos] << 8) | pucBuffer[usPos + 1];				if(usCaSysId != CA_SYSTEM_ID)					break;				usEmmPid = (pucBuffer[usPos + 2] << 8) | pucBuffer[usPos + 3];				usEmmPid &= 0x1FFF;								break;			default:				break;		}		usPos += ucDescLen;	}ERROR:	return usEmmPid;}static void DVB_CAEMM_UpgradeInfo(void){	int i;	main_prog_msg_t stMsg;	UINT32 uiFactoryID = 0;	UINT32 uiHwVer = 0;	UINT32 uiSwVer = 0;	UINT32 uiStbID = 0;	if(g_pstLeadInfo != NULL)		return;	DVB_CADB_Get(CA_DB_CMD_STB_ID, (void *)(&uiStbID));	DVB_CADB_Get(CA_DB_CMD_HW_VER, (void *)(&uiHwVer));	DVB_CADB_Get(CA_DB_CMD_SW_VER, (void *)(&uiSwVer));	DVB_CADB_Get(CA_DB_CMD_FACTORY_ID, (void *)(&uiFactoryID));	uiHwVer = SWAP32(uiHwVer);	uiSwVer = SWAP32(uiSwVer);	uiStbID = SWAP32(uiStbID);	#if 0	ecos_printf("Upgrade Info\n");	ecos_printf("%x:%x:%x:%x   %x:%x:%x:%x \n",		g_stEmmPack.contents.STB_Update_frequ.lead_Info[0].software_version[0],		g_stEmmPack.contents.STB_Update_frequ.lead_Info[0].software_version[1],		g_stEmmPack.contents.STB_Update_frequ.lead_Info[0].software_version[2],		g_stEmmPack.contents.STB_Update_frequ.lead_Info[0].software_version[3], 		*((UINT8 *)(&uiSwVer)),		*(((UINT8 *)(&uiSwVer)) + 1),		*(((UINT8 *)(&uiSwVer)) + 2),		*(((UINT8 *)(&uiSwVer)) + 3));	ecos_printf("%x:%x:%x:%x   %x:%x:%x:%x     %x:%x:%x:%x\n",		g_stEmmPack.contents.STB_Update_frequ.lead_Info[0].start_STB_ID[8],		g_stEmmPack.contents.STB_Update_frequ.lead_Info[0].start_STB_ID[9],		g_stEmmPack.contents.STB_Update_frequ.lead_Info[0].start_STB_ID[10],		g_stEmmPack.contents.STB_Update_frequ.lead_Info[0].start_STB_ID[11], 		g_stEmmPack.contents.STB_Update_frequ.lead_Info[0].end_STB_ID[8],		g_stEmmPack.contents.STB_Update_frequ.lead_Info[0].end_STB_ID[9],		g_stEmmPack.contents.STB_Update_frequ.lead_Info[0].end_STB_ID[10],		g_stEmmPack.contents.STB_Update_frequ.lead_Info[0].end_STB_ID[11], 		*((UINT8 *)(&uiStbID)),		*(((UINT8 *)(&uiStbID)) + 1),		*(((UINT8 *)(&uiStbID)) + 2),		*(((UINT8 *)(&uiStbID)) + 3));	#endif	for(i = 0; i < g_stEmmPack.contents.STB_Update_frequ.update_sum; i++)	{		if(g_stEmmPack.contents.STB_Update_frequ.lead_Info[i].maufactory_code == uiFactoryID			&& DVB_CAStrcmp((UINT8 *)g_stEmmPack.contents.STB_Update_frequ.lead_Info[i].hardware_version, (UINT8 *)(&uiHwVer), 4) == 0			&& DVB_CAStrcmp((UINT8 *)g_stEmmPack.contents.STB_Update_frequ.lead_Info[i].software_version, (UINT8 *)(&uiSwVer), 4) > 0			&& DVB_CAStrcmp((UINT8 *)g_stEmmPack.contents.STB_Update_frequ.lead_Info[i].start_STB_ID + 8, (UINT8 *)(&uiStbID), 4) <= 0			&& DVB_CAStrcmp((UINT8 *)g_stEmmPack.contents.STB_Update_frequ.lead_Info[i].end_STB_ID + 8, (UINT8 *)(&uiStbID), 4) >= 0)		{						if(g_pstLeadInfo == NULL)			{				g_pstLeadInfo = (S_leadinfo *)malloc(sizeof(S_leadinfo));				if(g_pstLeadInfo == NULL)					continue;				memset(g_pstLeadInfo, 0x0, sizeof(S_leadinfo));			}						memcpy((void *)g_pstLeadInfo, (void *)(&(g_stEmmPack.contents.STB_Update_frequ.lead_Info[i])), sizeof(S_leadinfo));			#if 0			ecos_printf("frequ:%d\n",g_pstLeadInfo->frequ);			ecos_printf("symbol_rate:%d\n",g_pstLeadInfo->symbol_rate);			ecos_printf("PID:%d\n",g_pstLeadInfo->PID);			ecos_printf("TID:%d\n",g_pstLeadInfo->TID);			#endif			UINT8 ucMessage = CA_UPGRADE_INFO;			stMsg.u8MsgID   	= DVB_MODULE_ID;			stMsg.u8SubModID = CA_UI_ID;			stMsg.u16FuncID  	= CA_MESSAGE;			stMsg.pData = (void *)&ucMessage;			DVB_SendBackMsg(&stMsg, 1);			g_ucNewUpgradeInfo = 1;		}	}}static void DVB_CA_SendNewMail(void){	if((g_ucLastMailTime + 50) >= cyg_current_time())	{		main_prog_msg_t stMsg;		g_ucLastMailTime = cyg_current_time();		UINT8 ucMessage = CA_NEW_MAIL;		stMsg.u8MsgID   	= DVB_MODULE_ID;		stMsg.u8SubModID = CA_UI_ID;		stMsg.u16FuncID  	= CA_MESSAGE;		stMsg.pData = (void *)&ucMessage;		DVB_SendBackMsg(&stMsg, 1);		g_ucNewMsg = 0;	}}static void DVB_CA_SendNewMsg(void){	if((g_ucLastMsgTime + 50) >= cyg_current_time())	{		main_prog_msg_t stMsg;		g_ucLastMsgTime = cyg_current_time();		UINT8 ucMessage = CA_NEW_MESSAGE;		stMsg.u8MsgID   	= DVB_MODULE_ID;		stMsg.u8SubModID = CA_UI_ID;		stMsg.u16FuncID  	= CA_MESSAGE;		stMsg.pData = (void *)&ucMessage;		DVB_SendBackMsg(&stMsg, 1);		g_ucNewMail = 0;	}}static void DVB_CAEMM_Mail(void){	int iResult  = 0;	ST_CA_MAIL stMail;	UINT32 uiAreaID;	UINT32 uiSmartID;		uiAreaID = DVB_CAService_GetAreaID();	DVB_CADB_Get(CA_DB_CMD_SMART_ID, &uiSmartID);	if(g_stEmmPack.EMMType != MAIL)		return;	if(g_stEmmPack.contents.Mail.Areano != 0 && g_stEmmPack.contents.Mail.Areano != uiAreaID)		return;	if(g_stEmmPack.contents.Mail.card_ID != 0 && g_stEmmPack.contents.Mail.card_ID != uiSmartID)		return;	memset(&stMail, 0x0, sizeof(ST_CA_MAIL));	stMail.usMailID = g_stEmmPack.contents.Mail.ID;	memcpy(stMail.aucTitle, g_stEmmPack.contents.Mail.title, MAIL_TITLE_SIZE);	memcpy(stMail.aucTerm, g_stEmmPack.contents.Mail.term, MAIL_TERM_SIZE);	memcpy(stMail.aucContext, g_stEmmPack.contents.Mail.content, MAIL_CONTEXT_SIZE);	iResult = DVB_CADB_AddMail(&stMail);	if(iResult == CA_DB_SUCCESS)	{		g_ucNewMail = 1;		DVB_CA_SendNewMail();	}}static void DVB_CAEMM_Message(void){	int iResult  = 0;	UINT32 uiAreaID;	UINT32 uiSmartID;	#if defined(SDT_CA_40)	int iShowMsg = 0;	int iBufferPriority = 0;	int iBufferPos = 0;	int i;	#endif		uiAreaID = DVB_CAService_GetAreaID();	DVB_CADB_Get(CA_DB_CMD_SMART_ID, &uiSmartID);//	ecos_printf("msg:%d:%d:%x:%x\n",g_stEmmPack.contents.Msg.Areano, uiAreaID,g_stEmmPack.contents.Msg.card_ID, 	uiSmartID);	if(g_stEmmPack.EMMType != MSG)		return;	if(g_stEmmPack.contents.Msg.Areano != 0 && g_stEmmPack.contents.Msg.Areano != uiAreaID)		return;	if(g_stEmmPack.contents.Msg.card_ID != 0 && g_stEmmPack.contents.Msg.card_ID != uiSmartID)		return;	#if defined(SDT_CA_40)	iResult = DVB_CADB_AddMsg(g_stEmmPack.contents.Msg.ID);	if(iResult == CA_DB_SUCCESS)	{		for(i = 0; i < MAX_MESSAGE_BUFFER; i++)		{			if(g_stMessage[i].ucEnable == 0 && iBufferPriority < 2)			{				iBufferPriority = 2;				iBufferPos = i;			}			else if(g_stMessage[i].ucEnable == 1)			{				iShowMsg = 1;				if(g_stMessage[i].ucGetTimes < g_stMessage[iBufferPos].ucGetTimes)				{					iBufferPos = i;					iBufferPriority = 1;				}			}			if(iShowMsg && iBufferPriority == 2)				break;		}		ecos_printf("Add Msg Buffer:%d\n",iBufferPos);		memset(&(g_stMessage[iBufferPos]), 0x0, sizeof(ST_EMM_MSGBUF));				memcpy(g_stMessage[iBufferPos].ucMsgBuffer, g_stEmmPack.contents.Msg.content, MAIL_CONTEXT_SIZE);		g_stMessage[iBufferPos].ucEnable = 1;		if(iShowMsg == 0)		{			g_ucNewMsg = 1;			DVB_CA_SendNewMsg();		}	}#elif defined(SDT_CA_50)	ST_CA_MSG stCaMsg;	UINT32 uiDay = 0;	UINT32 uiTime = 0;	memset(&stCaMsg, 0x0, sizeof(ST_CA_MSG));	stCaMsg.usMsgID = g_stEmmPack.contents.Msg.ID;		uiDay = TransYMD(g_stEmmPack.contents.Msg.msg_show_time.YY,					g_stEmmPack.contents.Msg.msg_show_time.MM,					g_stEmmPack.contents.Msg.msg_show_time.DD);					uiTime = (g_stEmmPack.contents.Msg.msg_show_time.HH << 8) | g_stEmmPack.contents.Msg.msg_show_time.MINUTE;					stCaMsg.uiShowTime = (uiDay << 16) | uiTime;	memcpy(stCaMsg.aucContext, g_stEmmPack.contents.Msg.content, MSG_CONTEXT_SIZE);		stCaMsg.ucBgColor = g_stEmmPack.contents.Msg.back_color;	stCaMsg.ucFontColor = g_stEmmPack.contents.Msg.font_color;	iResult = DVB_CADB_AddMsg(&stCaMsg);#endif}#if defined(SDT_CA_50)static  void DVB_CAEMM_MsgPolling(void){	int iShowMsg = 0;	int i;	int iBufferPriority = 0;	int iBufferPos = 0;	UINT8 ucFontColor = 0;	UINT8 ucBgColor = 0;	UINT8 ucMsgBuffer[MSG_CONTEXT_SIZE + 1];	cyg_mutex_lock(&g_CAEmmMutex);	if(DVB_CAECM_GetOsdView() == 0 )	{			if(DVB_CADB_GetMsg(ucMsgBuffer, &ucBgColor, &ucFontColor) > 0)		{			for(i = 0; i < MAX_MESSAGE_BUFFER; i++)			{				if(g_stMessage[i].ucEnable == 0 && iBufferPriority < 2)				{					iBufferPriority = 2;					iBufferPos = i;				}				else if(g_stMessage[i].ucEnable == 1)				{					iShowMsg = 1;					if(g_stMessage[i].ucGetTimes < g_stMessage[iBufferPos].ucGetTimes)					{						iBufferPos = i;						iBufferPriority = 1;					}				}				if(iShowMsg && iBufferPriority == 2)					break;			}			memset(&(g_stMessage[iBufferPos]), 0x0, sizeof(ST_EMM_MSGBUF));			aucMsgBgColor[iBufferPos] = ucBgColor;			aucMsgFontColor[iBufferPos] = ucFontColor;			memcpy(g_stMessage[iBufferPos].ucMsgBuffer, ucMsgBuffer, MAIL_CONTEXT_SIZE);			g_stMessage[iBufferPos].ucEnable = 1;			if(iShowMsg == 0)			{				g_ucNewMsg = 1;				DVB_CA_SendNewMsg();			}		}	}	cyg_mutex_unlock(&g_CAEmmMutex);}#endifint DVB_CAStrcmp(void *ptr1, void *ptr2, int iLen){	int i;	unsigned char *str1,*str2;	if(ptr1 == NULL || ptr2 == NULL)		return 0;	str1 = (unsigned char *)ptr1;	str2 = (unsigned char *)ptr2;	for(i= 0; i < iLen; i++)	{		if(str1[i] > str2[i])			return 1;		else if(str1[i] < str2[i])			return -1;	}	return 0;}void DVB_CAEmmDump(UINT8 *pBuffer){	UINT16 ucLen = (pBuffer[1] << 8) | pBuffer[2];	ucLen = ucLen & 0xFFF;	int i;	for(i = 0; i <ucLen + 3; i ++)	{		if(i % 16 == 0)			ecos_printf("\n");		ecos_printf("0x%02x,",pBuffer[i]);	}	ecos_printf("\n");}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -