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

📄 conax.c

📁 在原来基础上新添加了对ST、V、I、C卡的处理
💻 C
📖 第 1 页 / 共 3 页
字号:
	}
	memset(Command,0,len+5);
	memcpy(Command,ins,5);
	memcpy(Command+5,pBuf,len);
	
	error = Smart_Transfer(Handle,			/* Send the command to the card */
						 Command,
						 NumberToWrite,
						 Response,
						 0,
						 &Read,
						 Status);
	if(error == SMC_NO_ERROR)
	{
		/* We must do different things according to diffent Procedure bytes */
		switch(Status[0]) 
		{
			case 0x98:
				/* We must read the data provide by the card */
				error = ConaxRead(Handle,
								  Response,
								  Status[1],
								  &Read,
								  Status,
								  0);
				
				/* We have to know what data we have got */
				if(error == SMC_NO_ERROR)
				{
					iParsedLength = 0;
					while(iParsedLength < Read)
					{
						pi = buf[0];
						iLength = buf[1];
						/* Each data have a pi parameter,we use this to identify them */
						switch(pi) 
						{
							/* The following four objects can be received after ECM send */
							case CW_PI:
								if(iLength < 5)
									return false;
								if(buf[4]==0x00)
								{
									memcpy(pucCWBuffer,buf+7,8);
								}
								else
								{
									memcpy(pucCWBuffer+8,buf+7,8);
								}
								bRet = true;
								break;
							case ACCESS_STATUS_PI:

							if(!ConaxParseAccessStatus(0,buf))
								bRet = false;
							else
								bRet = true;
							break;
								
							default:
								break;
						}
						iParsedLength += (iLength+2);
						buf += (iLength + 2);
					}
				}
				break;
			default:
				break;
			}
	}	
	
	return bRet;
}

/*-------------------------------------------------------------------*/
/*    函 数 名:conax_parse_ecm                                      */
/*    函数功能:处理ECM数据                                     */
/*    参    数:pbuf  : ECM表头指针                 */
/*              pucCW : CW                          */
/*    返 回 值:成功:true , 失败 : false                             */
/*    全局变量:                                                     */
/*    调用模块:                                                      */
/*    备    注:注意ECM数据的格式                                    */
/*-------------------------------------------------------------------*/
bool conax_parse_ecm(Smart_Handle_t Handle,U8* pbuf,U8* pucCW)
{
	U8 aucEcmSection[300];
	int len=((pbuf[1]&0x0F)<<8)+pucCW[2]+7;
	memset(aucEcmSection,0,sizeof(aucEcmSection));
	aucEcmSection[0] = 0x14;
	aucEcmSection[1] = len + 1;
	aucEcmSection[2] = 0;			    /* Pay attention to ECM mode indicate bit! */
	memcpy(aucEcmSection+3,pbuf,len);    /* Copy the ECM data to the command */
	return ConaxEcmCOM(Handle,0,aucEcmSection,len+3,pucCW);
}

/*-------------------------------------------------------------------*/
/*    函 数 名:ConaxParseAccessStatus                               */
/*    函数功能:处理ACCESS_STATUS                                  */
/*    参    数:Response: 数据头指针                 */
/*    返 回 值:成功:true                                           */
/*              失败:fasle                                         */
/*    全局变量:                                                     */
/*    调用模块:                                                      */
/*    备    注:                                                     */
/*-------------------------------------------------------------------*/
static bool ConaxParseAccessStatus(Smart_Handle_t Handle,U8* Response)
{
	U8* pBuf;
	int len;
	int expectedlength = 2;
	Conax_AccessStatus_t ConaxAccessStatus;
	len = Response[1];

	if(len < 2)
		return false;
	if(len == 2)
	{
		if((Response[2]==0x00) && (Response[3]==0x00))
			return false;
	}
	
	pBuf = Response + 2;
	ConaxAccessStatus.not_sufficient_info	= (pBuf[0] & 0x80) >> 7;
	ConaxAccessStatus.access_granted	    = (pBuf[0] & 0x40) >> 6;
	ConaxAccessStatus.order_ppv_event       = (pBuf[0] & 0x20) >> 5;
	ConaxAccessStatus.geographical_blackout = (pBuf[0] & 0x04) >> 2;
	ConaxAccessStatus.maturity_rating		= (pBuf[0] & 0x02) >> 1;
	ConaxAccessStatus.accept_viewing		= pBuf[0] & 0x01;
	ConaxAccessStatus.ppv_preview			= (pBuf[1] & 0x80) >> 7;
	ConaxAccessStatus.ppv_expried			= (pBuf[1] & 0x40) >> 6;
	ConaxAccessStatus.no_access_to_network	= (pBuf[1] & 0x20) >> 5;

	pBuf += 2;
	if(ConaxAccessStatus.maturity_rating)
	{
		ConaxAccessStatus.current_mat_rat_value = pBuf[0];
		pBuf++;
		expectedlength++;
	}
	if(ConaxAccessStatus.accept_viewing)
	{
		ConaxAccessStatus.minutes_left = (pBuf[0] << 8) | pBuf[1];
		pBuf += 2;
		expectedlength += 2;
	}
	if(ConaxAccessStatus.order_ppv_event || 
	   ConaxAccessStatus.accept_viewing)
	{
		memcpy(ConaxAccessStatus.product_ref,pBuf,6);
		expectedlength += 6;
	}

	if(len < expectedlength)
		return false;
	return true;
}

/*-------------------------------------------------------------------*/
/*    函 数 名:ConaxCAStatusCOM                                     */
/*    函数功能:处理CA_STATUS_COM命令                                */
/*    参    数:Handle: SmartCard句柄                 */
/*              sid   : 会话号                    */
/*              pBuf  : 命令头指针                   */
/*              len   : 命令长度                    */
/*    返 回 值:                                                     */
/*    全局变量:                                                     */
/*    调用模块:                                                      */
/*    备    注:                                                     */
/*-------------------------------------------------------------------*/
static bool ConaxCAStatusCom(Smart_Handle_t Handle,
									   U8				sid,
									   U8*			    pBuf,
									   U16			    len)
{
	bool error;
	U8 ins[] = {0xDD,0xC6,0x00,0xFF,0xFF};
	U8 Command[255];

	ins[3] = sid;
	ins[4] = (U8)len;
	memcpy(Command,ins,5);
	memcpy(Command+5,pBuf,len);
	error = ConaxWrite(Handle,Command,len+5);

	return error;
}

/*-------------------------------------------------------------------*/
/*    函 数 名:ConaxCAStatusSelect                                  */
/*    函数功能:处理CA Status Select命令                             */
/*    参    数:type  : CA_Status_Type                               */
/*                      0x00: Retrieve entire table of subscription  */
/*                            status                                 */
/*                      0x01: Retrieve entire table of PPV event     */
/*                            status                                 */
/*                      0x05: Retrieve subscription status for a     */
/*                            specified subscription reference       */
/*                      0x06: Retrieve PPV event status for a        */
/*                            specified event tag                    */
/*              buf  : When type=0x05 this is subscription_ref       */
/*                     When type=0x06 this is event_tag              */
/*                     Leave this NULL otherwise                     */
/*    返 回 值:                                                     */
/*    全局变量:                                                     */
/*    调用模块:                                                      */
/*    备    注:                                                     */
/*-------------------------------------------------------------------*/
bool ConaxCAStatusSelect(Smart_Handle_t   Handle,
						 U8				  type,
						 U8*			  buf)
{
	U8 Command[100];
	U8 len;

	if(type == 0x05)
	{
		if(buf == NULL)
		{
			printf("ConaxCAStatusSelect : buf should not be NULL !\n");
			return false;
		}
		len = 5;
		memset(Command,0,5);
		Command[1] = 3;
		memcpy(Command+3,buf,2);
	}
	else if(type == 0x06)
	{
		if(buf == NULL)
		{
			printf("ConaxCAStatusSelect : buf should not be NULL !\n");
			return false;
		}
		len = 6;
		memset(Command,0,6);
		Command[1] = 4;
		memcpy(Command+3,buf,3);
	}
	else
	{
		len = 3;
		memset(Command,0,3);
		Command[1] = 1;
	}
	Command[0] = 0x1C;
	Command[2] = type;
	return(ConaxCAStatusCom(Handle,0,Command,len));
}

/*-------------------------------------------------------------------*/
/*    函 数 名:ConaxSecurityOp                                      */
/*    函数功能:Conax Security OP 命令                               */
/*    参    数:Handle: 卡句柄                                       */
/*              sid   :  会话号                                      */
/*              pBuf  :  命令头指针                                  */
/*              len   :  命令长度                                    */
/*    返 回 值:                                                     */
/*    全局变量:                                                     */
/*    调用模块:                                                      */
/*    备    注:                                                     */
/*-------------------------------------------------------------------*/
static Smart_ErrorCode_t ConaxSecurityOp(Smart_Handle_t  Handle,
								      U8				sid,
								      U8*			    pBuf,
								      U16			    len)
{
	U8 ins[] = {0xDD,0xC2,0x00,0xFF,0xFF};
	U8 Command[50];
 	Smart_ErrorCode_t error;
	ins[3] = sid;
	ins[4] = (U8)len;
	memset(Command,0,len+5);
	memcpy(Command,ins,5);
	memcpy(Command+5,pBuf,len);
	error = ConaxWrite(Handle,Command,len+5);
	return error;
}

/*-------------------------------------------------------------------*/
/*    函 数 名:ConaxReqCardNumber                                   */
/*    函数功能:读取卡号命令                                         */
/*    参    数:                                                     */
/*    返 回 值:成功:true                                           */
/*              失败:fasle                                          */
/*    全局变量:                                                     */
/*    调用模块:                                                      */
/*    备    注:                                                     */
/*-------------------------------------------------------------------*/
bool ConaxReqCardNumber(Smart_Handle_t Handle)
{
	U8 ins[2] = {0x66,0x00};

	return (ConaxSecurityOp(Handle,0,ins,2));
}


////////////////////////The end-------------

⌨️ 快捷键说明

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