📄 conax.c
字号:
break;
case MAT_RAT_LEVEL_PI:
if(iLength != 1)
return false;
pstConaxInfo->stParam.MatRat = buf[2];
break;
case SESSION_INFO_PI:
if(iLength != 1)
return false;
pstConaxInfo->stParam.MaxSessionNum = buf[2];
break;
/* This Object can be received after EMM or ECM send */
case HOST_DATA_PI:
break;
/* This Object can be received after CAT send */
case CA_DESC_EMM_PI:
if(!ConaxParseCADescEMM(Handle,buf))
return false;
break;
/* The following four objects can be received after ECM send */
case ACCESS_STATUS_PI:
if(!ConaxParseAccessStatus(Handle,buf))
return false;
break;
case CW_PI:
if(iLength < 5)
return false;
memset(&ConaxCW,0,sizeof(Conax_CW_t));
ConaxCW.cw_id = (buf[2] << 8) | buf[3];
ConaxCW.odd_even_indicator = buf[4];
ConaxCW.iCWLen = iLength-5;
{
memset(ConaxCW.aucCWBuf,0,ConaxCW.iCWLen);
memcpy(ConaxCW.aucCWBuf,buf+7,ConaxCW.iCWLen);
}
break;
/* This object can be received when Req Card Number Command is send */
case CARD_NUMBER_PI:
if(iLength != 4)
return false;
pstConaxInfo->iCardNumber = (Response[2] << 24) | (Response[3] << 16) |
(Response[4] << 8) | Response[5];
break;
default:
break;
}
iParsedLength += (iLength+2);
buf += (iLength + 2);
}
return true;
}
/*-------------------------------------------------------------------*/
/* 函 数 名:ConaxInitCASS(void) */
/* 函数功能:INIT_CASS命令 */
/* 参 数:Handle: SmartCard句柄 */
/* 返 回 值: */
/* 全局变量: */
/* 调用模块: */
/* 备 注: */
/*-------------------------------------------------------------------*/
static bool ConaxInitCASS(Smart_Handle_t Handle)
{
U8 ins[] = {0xDD,0x26,0x00,0x00,0x03,0x10,0x01,0x40};
bool error;
error = ConaxWrite(Handle,ins,8);
return error;
}
/*-------------------------------------------------------------------*/
/* 函 数 名:ConaxResetSESS(void) */
/* 函数功能:RESET_SESSION命令 */
/* 参 数:Handle: SmartCard句柄 */
/* sid: 要复位的会话号 */
/* 返 回 值: */
/* 全局变量: */
/* 调用模块: */
/* 备 注: */
/*-------------------------------------------------------------------*/
static bool ConaxResetSESS(Smart_Handle_t Handle,
U8 sid)
{
U8 ins[] = {0xDD,0x26,0x00,0x00,0x03,0x69,0x01,0xFF};
bool error;
ins [7] = sid;
error = ConaxWrite(Handle,ins,8);
return error;
}
/*-------------------------------------------------------------------*/
/* 函 数 名:ConaxInitOAA */
/* 函数功能:处理 INITOAA命令 */
/* 参 数:Handle: SmartCard句柄 */
/* sid : 会话号 */
/* pBuf : Cat表头指针 */
/* len : Cat数据长度 */
/* 返 回 值:成功:true */
/* 失败:false */
/* 全局变量: */
/* 调用模块: */
/* 备 注: */
/*-------------------------------------------------------------------*/
static bool ConaxInitOAA(Smart_Handle_t Handle,
U8 sid,
U8* pBuf,
U16 len)
{
U8 ins[] = {0xDD,0x82,0x00,0xFF,0xFF};
U8 Command[255];
U16 NumberToWrite = 0;
bool error;
ins[3] = sid;
ins[4] = (U8)len;
NumberToWrite = len+5;
memset(Command,0,len+5);
memcpy(Command,ins,5);
memcpy(Command+5,pBuf,len);
error = ConaxWrite(Handle,Command,NumberToWrite);
return error;
}
/*-------------------------------------------------------------------*/
/* 函 数 名:conax_parse_cat */
/* 函数功能:处理Cat表 */
/* 参 数:pBuf : Cat表头指针 */
/* len : Cat数据长度 */
/* 返 回 值: */
/* 全局变量: */
/* 调用模块: */
/* 备 注:要求CAT表中CA Descriptor为Conax系统,且含有CRC校验码 */
/*-------------------------------------------------------------------*/
void conax_parse_cat(Smart_Handle_t Handle,U8* pBuf,U16 len)
{
U8 aucCatSection[300];
memset(aucCatSection,0,300);
aucCatSection[0] = 0x11;
aucCatSection[1] = (U8)len;
memcpy(aucCatSection+2,pBuf,len);
ConaxInitOAA(Handle,0,aucCatSection,len+2);
}
/*-------------------------------------------------------------------*/
/* 函 数 名:ConaxParseCADescEMM */
/* 函数功能:处理CA_DESC_EMM */
/* 参 数:Response: 数据头指针 */
/* 返 回 值:成功:true */
/* 失败:fasle */
/* 全局变量: */
/* 调用模块: */
/* 备 注: */
/*-------------------------------------------------------------------*/
static bool ConaxParseCADescEMM(Smart_Handle_t Handle,U8* Response)
{
int i;
U8* pBuf;
int length;
int iAddressLength;
int iDescLength;
int iParsedAddLen;
U8 EMM_Address_TABLE[10][7];
int EMM_Address_Count;
pBuf = Response;
length = pBuf[1];
iDescLength = pBuf[3];
iAddressLength = length - iDescLength - 2;
pBuf += (iDescLength+4);
EMM_Address_Count = 0;
iParsedAddLen = 0;
while(iParsedAddLen < iAddressLength)
{
if(pBuf[0] == EMM_ADDRESS_TAG && pBuf[1] == 7)
{
memcpy(EMM_Address_TABLE[EMM_Address_Count],pBuf+2,7);
EMM_Address_Count++;
iParsedAddLen += 9;
pBuf += 9;
}
else
{
return false;
}
}
pstConaxInfo->iEMMAddressCount = EMM_Address_Count;
for(i=0;i<EMM_Address_Count;i++)
memcpy(pstConaxInfo->auEMMAddress[i],EMM_Address_TABLE[i],7);
if(EMM_Address_Count < 1)
return false;
return true;
}
/*-------------------------------------------------------------------*/
/* 函 数 名:ConaxEmmCOM */
/* 函数功能:处理 EMM_COM命令 */
/* 参 数:Handle: SmartCard句柄 */
/* sid : 会话号 */
/* pBuf : EMM表头指针 */
/* len : EMM数据长度 */
/* 返 回 值: */
/* 全局变量: */
/* 调用模块: */
/* 备 注: */
/*-------------------------------------------------------------------*/
static bool ConaxEmmCOM(Smart_Handle_t Handle,
U8 sid,
U8* pBuf,
U16 len)
{
U8 ins[] = {0xDD,0x84,0x00,0xFF,0xFF};
U8 Command[300];
U16 NumberToWrite = 0;
bool error;
if(len > 290)
{
printf("ConaxEMMCom Error : Message too long !!\n");
return false;
}
ins[3] = sid;
ins[4] = (U8)len;
NumberToWrite = len+5;
memset(Command,0,sizeof(Command));
memcpy(Command,ins,5);
memcpy(Command+5,pBuf,len);
error = ConaxWrite(Handle,Command,NumberToWrite);
return error;
}
/*-------------------------------------------------------------------*/
/* 函 数 名:conax_parse_emm */
/* 函数功能:处理EMM数据 */
/* 参 数:pBuf : EMM表头指针 */
/* len : EMM数据长度 */
/* 返 回 值: */
/* 全局变量: */
/* 调用模块: */
/* 备 注: */
/*-------------------------------------------------------------------*/
bool conax_parse_emm(Smart_Handle_t Handle,U8* pBuf,U16 len)
{
U8 aucEmmSection[255];
aucEmmSection[0] = 0x12;
aucEmmSection[1] = (U8)len;
memcpy(aucEmmSection+2,pBuf,len);
ConaxEmmCOM(Handle,0,aucEmmSection,len+2);
return true;
}
/*-------------------------------------------------------------------*/
/* 函 数 名:ConaxEcmCOM */
/* 函数功能:处理 ECM_COM命令 */
/* 参 数:Handle: SmartCard句柄 */
/* sid : 会话号 */
/* pBuf : ECM表头指针 */
/* len : ECM数据长度 */
/* 返 回 值: */
/* 全局变量: */
/* 调用模块: */
/* 备 注: */
/*-------------------------------------------------------------------*/
static bool ConaxEcmCOM(Smart_Handle_t Handle,
U8 sid,
U8* pBuf,
U16 len,
U8* pucCWBuffer)
{
U8 ins[] = {0xDD,0xA2,0x00,0xFF,0xFF};
U8 Command[300];
U16 NumberToWrite = 0;
U8 Response[255];
U16 Read;
U8 Status[2];
Smart_ErrorCode_t error;
int iParsedLength;
bool bRet = false;
U8 pi;
int iLength;
U8* buf = Response;
ins[3] = sid;
ins[4] = (U8)len;
NumberToWrite = len+5;
if(len+5 > 290)
{
printf("Conax Ecm Com Error : Ecm Message too long !!\n");
return false;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -