📄 caproc.c
字号:
offset+=g_ca_config.AC_Data_List[i].SubDataConfig[0].ECM_Private_Data_Length;
}
/* if(g_has_valid_ca1_config)*/
{
g_ca_config.AC_Data_List[i].SubDataConfig[1].ECM_PID=*(unsigned short *)(readbuf + offset);
offset+=2;
g_ca_config.AC_Data_List[i].SubDataConfig[1].AC_Data_Length=*(unsigned char *)(readbuf + offset);
offset++;
for(j=0;j<g_ca_config.AC_Data_List[i].SubDataConfig[1].AC_Data_Length;j++)
g_ca_config.AC_Data_List[i].SubDataConfig[1].AC_Data[j]=*(unsigned char *)(readbuf + offset + j);
offset+=g_ca_config.AC_Data_List[i].SubDataConfig[1].AC_Data_Length;
g_ca_config.AC_Data_List[i].SubDataConfig[1].ECM_Private_Data_Length=*(unsigned char *)(readbuf + offset);
offset++;
for(j=0;j<g_ca_config.AC_Data_List[i].SubDataConfig[1].ECM_Private_Data_Length;j++)
g_ca_config.AC_Data_List[i].SubDataConfig[1].ECM_Private_Data[j]=*(unsigned char *)(readbuf + offset + j);
offset+=g_ca_config.AC_Data_List[i].SubDataConfig[1].ECM_Private_Data_Length;
}
/* if(g_has_valid_ca1_config)*/
{
g_ca_config.AC_Data_List[i].SubDataConfig[2].ECM_PID=*(unsigned short *)(readbuf + offset);
offset+=2;
g_ca_config.AC_Data_List[i].SubDataConfig[2].AC_Data_Length=*(unsigned char *)(readbuf + offset);
offset++;
for(j=0;j<g_ca_config.AC_Data_List[i].SubDataConfig[2].AC_Data_Length;j++)
g_ca_config.AC_Data_List[i].SubDataConfig[2].AC_Data[j]=*(unsigned char *)(readbuf + offset + j);
offset+=g_ca_config.AC_Data_List[i].SubDataConfig[2].AC_Data_Length;
g_ca_config.AC_Data_List[i].SubDataConfig[2].ECM_Private_Data_Length=*(unsigned char *)(readbuf + offset);
offset++;
for(j=0;j<g_ca_config.AC_Data_List[i].SubDataConfig[2].ECM_Private_Data_Length;j++)
g_ca_config.AC_Data_List[i].SubDataConfig[2].ECM_Private_Data[j]=*(unsigned char *)(readbuf + offset + j);
offset+=g_ca_config.AC_Data_List[i].SubDataConfig[2].ECM_Private_Data_Length;
}
}
g_ca_config.Stream_Count=*(unsigned char *)(readbuf + offset);
offset++;
for(i=0;i<g_ca_config.Stream_Count;i++)
{
g_ca_config.Stream_Config[i].Stream_PID=*(unsigned short *)(readbuf + offset);
offset+=2;
g_ca_config.Stream_Config[i].CW_Index=*(unsigned char *)(readbuf + offset);
offset++;
}
MemFree(readbuf);
return 0;
}
}
void ca_write_reg(unsigned short address,unsigned int val)
{
NIB_ADDRESS_LOW_REG =address&0x00FF;
NIB_ADDRESS_HIGH_REG=(address&0xFF00)>>8;
NIB_DATA_LOW_REG =val&0xff;
NIB_DATA_HIGH_REG =(val>>8)&0xff;
NIB_ACTION_REG =0;
}
/*----------------------------------------------------------------*/
/* val:unit of 100ms */
/*----------------------------------------------------------------*/
void ca_set_timer_interval(unsigned int val)
{
ca_write_reg(CA_TIMER_INTERVAL_ADDRESS,val);
}
/*----------------------------------------------------------------*/
/* enableordisable=1 enable simucrypt, =0 disable */
/*----------------------------------------------------------------*/
void ca_enable_simucrypt(unsigned int enableordisable)
{
ca_write_reg(CA_SIMUCRYPT_CONTROL_ADDRESS,!enableordisable);
}
void ca_set_even_odd_cp(unsigned int evenodd)
{
ca_write_reg(CA_EVEN_ODD_CONTROL_ADDRESS,evenodd);
}
/*根据加扰设置填写CWG存储器*/
void ca_write_simucrypt_map(void)
{
PID_MAP_TABLE map;
unsigned int i,j,k;
volatile int pid9index;
volatile unsigned short pid9;
volatile unsigned short pid4;
volatile int found;
for(j=0;j<0x20;j++)
{
ca_write_reg(CA_HIGH_INDEX_BASE_ADDRESS,j);
for(k=0;k<0x10;k++)
ca_write_reg(CA_CW_INDEX_BASE_ADDRESS + k,0x80);
}
for(i=0;i<0x200;i++)
{
ca_write_reg(CA_HIGH_INDEX_BASE_ADDRESS + i,0x1F);
}
map.PIDs=0;
for(i=0;i<g_ca_config.Stream_Count;i++)
{/*读取配置中是否加扰信息*/
pid9=(g_ca_config.Stream_Config[i].Stream_PID&0x1FF0)>>4;
pid4=g_ca_config.Stream_Config[i].Stream_PID&0x000F;
found=0;
for(j=0;j<map.PIDs;j++)
{
if(map.PID9[j]==pid9)
{
found=1;
pid9index=j;
break;
}
}
if(!found)
{
map.PID9[map.PIDs]=pid9;
pid9index=map.PIDs;
map.PIDs++;
}
ca_write_reg(CA_HIGH_INDEX_BASE_ADDRESS + pid9,pid9index);
/*最高位为零表示需要加扰*/
ca_write_reg(CA_CW_INDEX_BASE_ADDRESS + pid4,g_ca_config.Stream_Config[i].CW_Index);
}
/*使能加扰*/
ca_enable_simucrypt(1);
}
/*根据加扰设置填写CWG存储器*/
void ca_Clear_simucrypt_map(void)
{
PID_MAP_TABLE map;
unsigned int i,j,k;
volatile int pid9index;
volatile unsigned short pid9;
volatile unsigned short pid4;
volatile int found;
for(j=0;j<0x20;j++)
{
ca_write_reg(CA_HIGH_INDEX_BASE_ADDRESS,j);
for(k=0;k<0x10;k++)
ca_write_reg(CA_CW_INDEX_BASE_ADDRESS + k,0x80);
}
for(i=0;i<0x200;i++)
{
ca_write_reg(CA_HIGH_INDEX_BASE_ADDRESS + i,0x1F);
}
map.PIDs=0;
for(i=0;i<g_ca_config.Stream_Count;i++)
{/*读取配置中是否加扰信息*/
pid9=(g_ca_config.Stream_Config[i].Stream_PID&0x1FF0)>>4;
pid4=g_ca_config.Stream_Config[i].Stream_PID&0x000F;
found=0;
for(j=0;j<map.PIDs;j++)
{
if(map.PID9[j]==pid9)
{
found=1;
pid9index=j;
break;
}
}
if(!found)
{
map.PID9[map.PIDs]=pid9;
pid9index=map.PIDs;
map.PIDs++;
}
ca_write_reg(CA_HIGH_INDEX_BASE_ADDRESS + pid9,pid9index);
/*0x80:clear */
ca_write_reg(CA_CW_INDEX_BASE_ADDRESS + pid4,0x80);
}
/*使能加扰*/
ca_enable_simucrypt(1);
}
/*
long dif_second(unsigned long time,unsigned long oldtime)
{
volatile unsigned short ts1,ts2;
volatile unsigned char tc1,tc2;
volatile long dif;
ts1=(time&0xFFFF0000)>>16;
ts2=(oldtime&0xFFFF0000)>>16;
tc1=(time&0x0000FF00)>>8;
tc2=(oldtime&0x0000FF00)>>8;
dif=(ts1-ts2)*60*60 + (tc1-tc2)*60;
tc1=(time&0x000000FF);
tc2=(oldtime&0x000000FF);
dif+=tc1-tc2;
return dif;
}
long dif_tick(unsigned long time,unsigned long tick,unsigned long oldtime,unsigned long oldtick)
{
return dif_second(time,oldtime)*KC_TICKS2SEC + tick-oldtick;
}
*/
/*返回两次时间差*/
long dif_second(unsigned long date,unsigned long time,unsigned long olddate,unsigned long oldtime)
{
/*
volatile unsigned short ts1,ts2;
volatile unsigned char tc1,tc2;
volatile unsigned long dif;
*/
unsigned short ts1,ts2;
unsigned char tc1,tc2;
unsigned long dif;
ts1=(time&0xFFFF0000)>>16;
ts2=(oldtime&0xFFFF0000)>>16;
tc1=(time&0x0000FF00)>>8;
tc2=(oldtime&0x0000FF00)>>8;
dif=(ts1-ts2)*60*60;
dif+=(tc1-tc2)*60;
tc1=(time&0x000000FF);
tc2=(oldtime&0x000000FF);
dif+=tc1-tc2;
dif+=(date-olddate)*24*60*60;
return dif;
}
long dif_tick(unsigned long date,unsigned long time,unsigned long tick,unsigned long olddate,unsigned long oldtime,unsigned long oldtick)
{
return dif_second(date,time,olddate,oldtime)*KC_TICKS2SEC + tick-oldtick;
}
/*获得协议版本号*/
unsigned char ca_get_protocol_version(char *buf)
{
CA_MESSAGE_HEAD *pHead;
pHead=(CA_MESSAGE_HEAD *)buf;
return pHead->protocol_version;
}
/*获得CA消息类型*/
unsigned short ca_get_message_type(char *buf)
{
CA_MESSAGE_HEAD *pHead;
pHead=(CA_MESSAGE_HEAD *)buf;
return pHead->message_type;
}
/*获得CA消息长度*/
unsigned short ca_get_message_length(char *buf)
{
CA_MESSAGE_HEAD *pHead;
pHead=(CA_MESSAGE_HEAD *)buf;
return pHead->message_length;
}
/*接收ECMG数据*/
int ca_recv(int socket,char *buf,int len,long int timetowait)
{
int nb;
fd_set read_mask;
struct timeval wait;
wait.tv_sec = 0;
wait.tv_usec = timetowait;
FD_ZERO (&read_mask);
FD_SET (socket, &read_mask);
nb = select (FD_SETSIZE, &read_mask, (fd_set *) 0,(fd_set *) 0, &wait);
/*
if(nb<0)
Display("ca_recv: socket error\r\n");
else if(nb==0)
Display("ca_recv: time out\r\n");
*/
if (nb <= 0)
{
return nb;
}
if (FD_ISSET(socket, &read_mask))
{
return recv(socket,buf,len,0);
}
else
return 0;
}
/*发送数据到ECMG*/
int ca_send(int socket,char *buf,int len,int timetowait)
{
int nb;
fd_set write_mask;
struct timeval wait;
int rc;
int SndLen;
/* rc = mu_lock(ulMultEMM, MU_WAIT, 0);
if(rc)
Display("Lock Error!");*/
wait.tv_sec = timetowait;
wait.tv_usec = 0;
FD_ZERO (&write_mask);
/*使标志与套接口对应*/
FD_SET (socket, &write_mask);
/* 打开I/O写*/
nb = select (FD_SETSIZE, (fd_set *) 0, &write_mask,(fd_set *) 0, &wait);
/*
if(nb<0)
Display("ca_send: socket error\r\n");
else if(nb==0)
Display("ca_send: time out\r\n");
*/
if (nb <= 0)
{
/* rc = mu_unlock(ulMultEMM);
if(rc)
Display("unlock error");
*/
return nb;
}
if (FD_ISSET(socket, &write_mask))
{/*成功,则发送数据*/
SndLen = send(socket,buf,len,0);
rc = mu_unlock(ulMultEMM);
if(rc)
Display("unlock error");
return SndLen;
}
/* rc = mu_unlock(ulMultEMM);
if(rc)
Display("unlock error");
*/
return 0;
}
/*---------------------------------------------------------------*/
/* when new ca config data received or new select mux command */
/* received, call the following function */
/*---------------------------------------------------------------*/
void ca_stop_service(void)
{
/*-----------------------------------------------------------*/
/* disable CW interrupt(IRQ3), clear the corresponding data */
/*-----------------------------------------------------------*/
S_SiMaskRegister &=~0x02000000;
ca_enable_simucrypt(0);
}
/*上报当前加扰设置*/
int ReportCAConfig(Packet *ThePacket)
{
MESSAGE Msg;
Packet *NMPkt;
unsigned char *pTmp;
int i;
unsigned char ucCACount=0;
NMPkt=(Packet *)MemAlloc(RNG2ID,"ReportCAConfig",sizeof(CA_CONFIG));
if(NMPkt == NULL)
return -1;
NMPkt->Command = ThePacket->Command;
NMPkt->DeviceType = DEVICE_TYPE_MULTIPLEXER;
NMPkt->PacketType = ThePacket->PacketType;
NMPkt->DeviceIdt = ThePacket->DeviceIdt;
NMPkt->PacketIdt = ThePacket->PacketIdt;
NMPkt->Result = 0;
NMPkt->PacketHeadLength=sizeof(Packet) - 4;
NMPkt->PacketLength =sizeof(Packet) - 4;
pTmp=(unsigned char *)&NMPkt->Data;
/*---------------------------------------------------------*/
/* 有加扰参数 */
/*---------------------------------------------------------*/
/*
if(g_has_valid_ca_config || g_has_valid_ca1_config || g_has_valid_ca2_config)
*pTmp= 1;
else
*pTmp = 0;
*/
if(!bJudgeConfig)
*pTmp = 0;
else
*pTmp = 1;
pTmp++;
/* if(g_has_valid_ca_config || g_has_valid_ca1_config || g_has_valid_ca2_config)*/
{/*获取当前加扰设置*/
if(g_has_valid_ca_config)
ucCACount |= 0x01;
if(g_has_valid_ca1_config)
ucCACount |= 0x02;
if(g_has_valid_ca2_config)
ucCACount |= 0x04;
/*当前CA设置个数*/
*pTmp = ucCACount;
pTmp++;
MemCopy(pTmp,(unsigned char *)&(g_ca_config.Para_Config[0]),sizeof(CA_PARA_CONFIG));
pTmp+=sizeof(CA_PARA_CONFIG);
/* if(g_has_valid_ca1_config) */
{
MemCopy(pTmp,(unsigned char *)&(g_ca_config.Para_Config[1]),sizeof(CA_PARA_CONFIG));
pTmp+=sizeof(CA_PARA_CONFIG);
}
/* if(g_has_valid_ca2_config)*/
{
MemCopy(pTmp,(unsigned char *)&(g_ca_config.Para_Config[2]),sizeof(CA_PARA_CONFIG));
pTmp+=sizeof(CA_PARA_CONFIG);
}
*(unsigned char *)pTmp=g_ca_config.AC_Data_Count;
pTmp++;
for(i=0;i<g_ca_config.AC_Data_Count;i++)
{
*(unsigned char *)pTmp=g_ca_config.AC_Data_List[i].AC_Index;
pTmp++;
*(unsigned char *)pTmp=g_ca_config.AC_Data_List[i].AC_Data_Name_Length;
pTmp++;
MemCopy(pTmp,g_ca_config.AC_Data_List[i].AC_Data_Name,g_ca_config.AC_Data_List[i].AC_Data_Name_Length);
pTmp+=g_ca_config.AC_Data_List[i].AC_Data_Name_Length;
*(unsigned short *)pTmp=g_ca_config.AC_Data_List[i].SubDataConfig[0].ECM_PID;
pTmp+=2;
*(unsigned char *)pTmp=g_ca_config.AC_Data_List[i].SubDataConfig[0].AC_Data_Length;
pTmp++;
MemCopy(pTmp,g_ca_config.AC_Data_List[i].SubDataConfig[0].AC_Data,g_ca_config.AC_Data_List[i].SubDataConfig[0].AC_Data_Length);
pTmp+=g_ca_config.AC_Data_List[i].SubDataConfig[0].AC_Data_Length;
/* added 2004-02-04 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -