我正在处理Mastercard Paypass事务,我发送了一个READ RECORD命令,并得到了结果:
70 81 AB 57 11 54 13 33 00 89 60 10 83 D2 51 22
20 01 23 40 91 72 5A 08 54 13 33 00 89 60 10 83
5F 24 03 25 12 31 5F 25 03 04 01 01 5F 28 02 00
56 5F 34 01 01 8C 21 9F 02 06 9F 03 06 9F 1A 02
95 05 5F 2A 02 9A 03 9C 01 9F 37 04 9F 35 01 9F
45 02 9F 4C 08 9F 34 03 8D 0C 91 0A 8A 02 95 05
9F 37 04 9F 4C 08 8E 0E 00 00 00 00 00 00 00 00
42 03 5E 03 1F 03 9F 07 02 FF 00 9F 08 02 00 02
9F 0D 05 00 00 00 00 00 9F 0E 05 00 08 00 60 00
9F 0F 05 00 00 00 00 00 9F 42 02 09 78 9F 4A 01
82 9F 14 01 00 9F 23 01 00 9F 13 02 00 00 此响应包含TLV数据对象(没有空格)。我已将答复改为如下所述:
// Read Record 1 with SFI2
//---------------------------------SEND READ RECORD-------------------
inCtlsSendVAPDU(0x2C,0x03,(unsigned char *)"\x00\xB2\x01\x14\x00",5);
clrscr();
inRet = inCTLSRecv2(Response, 269);
LOG_HEX_PRINTF("Essai EMV4 Read record 1 EMV Paypass:",Response,inRet);
if(Response[14]==0x70)
{
sprintf(Response_PPSE,"%02X%02X",Response[12],Response[13]);//To retrieve length of received data
t1=hexToInt(Response_PPSE);// Convert length to integer
t11=t1-2;
i=14;
k=0;
//--------------------------- Converting data to be used later---------
while(i<t11+14)// 14 to escape the header+ command+ status+ length
{
sprintf(READ1+(2*k),"%02X",Response[i]);
i++;
k++;
}现在,我应该检查这个响应是否包含强制标记:
因此,我试着检查5A标签(申请主要帐号(PAN)):
i=0;
t11=2*t11;
while(i<=t11)
{
strncpy(Response_PPSE,READ1+i,2);
if(strncmp(Response_PPSE,"\x05\x0A")==0)
{
write_at("true",4,1,1);// Just to test on the terminal display
goto end;
}
else
i=i+2;
}
goto end;我不知道为什么终端上什么都不显示,if块不执行!
我试图通过以下方式手动打印5A标记:
strncpy(Response_PPSE,READ1+44,2);
write_at(Response_PPSE,strlen(Response_PPSE),1,1);并显示正确的价值!
有人能帮助解决这个问题吗?
发布于 2015-04-17 07:39:43
您找不到那个标记,因为您不是在搜索字符串"5A“,而是搜索字符串"\x05\x0A”(ENQ字符+行提要字符)。此外,我不知道上面的代码是否真的编译,因为您没有为strncmp()指定强制长度参数。你可以试试
if(strncmp(Response_PPSE,"5A", 2)==0)而不是。
但是,您应该了解,您正在扫描整个响应数据以获得值5A。因此,找到这个值也可能意味着它是一些其他TLV标记的数据字段、长度字段甚至多字节标记字段的一部分。因此,为BER (基本编码规则)格式实现(或使用现有的) TLV解析器是有意义的。
发布于 2015-05-08 23:01:09
首先使用字符串函数在原始字节流数据中搜索特定字节并不是一种好方法。
通用的TLV解析器是一个非常简单的算法,您将在30分钟左右完成它。
通常,查找特定标记的TLV解析器的伪代码如下所示:
index = 0
while (byte[i] != 0x5A or EOF)
{
length = DecodeLength(byte[i+1])
i += length + 2 // + 1 for L (length) byte itself, it might be encoded with
// 2 bytes so the function DecodeLength can return the number
// of bytes lenght has been encoded
// +1 for T (tag) byte
}
if(EOF) return tag_not_found
return byte[i + 2], length // pointer to data for Tag '5A'and length of datahttps://stackoverflow.com/questions/29680515
复制相似问题