MBS - SmartCardMBS

Hi, I’m trying to use “SmartCardMBS”, following the sample project named “SmartCard”.
I need to read personal data from a health card (Italy).

I can’t figure out how to use the “ReadFile” method.

Can I, using it, access the file directly? Or do I have to navigate step-by-step from node MF, to node DF1 and then, finally, to EF?

ReadFile takes MemoryBlock as parameter: but only the node id? or all the APDU command?

You can do your own transfers as you need.
ReadFile is a convenience function, which just takes the file ID and then does various commands to get the file.

So it does a select command (A4) and then a loop with read commands (B0)

but if the file is in a sublevel
(MF \ DF 1 \ EF_personal_data)

Can I directly use a single call to the ReadFile method, directly indexing the file containing the personal data?

dim mydata as MemoryBlock
Dim comando1 as new MemoryBlock(2)
comando1.UInt8Value(0) = &h3F
comando1.UInt8Value(1) = &h00
mydata = card.ReadFile(comando1)

PS: is sending the bytes in little or big endian?

for example, 3F00 should be written
3F
00

or

00
3F
?

after a few months I took up the matter again. I just can’t get anything with ReadFile

Well, it’s a convenience function, which works for swiss Health cards and Belgian identify cards for us.
It may work for others if they use the same format (APDU protocol).

For Swiss health cards, the relevant IDs are 2F06 and 2F07.

For Belgian EID:

4031 ID RN
4032 SGN RN
4033 ID Address
4034 SGN Address
4035 ID Photo

You find the IDs for files usually in documentation or your card!
For some cards you may first need to move down a hierarchy of folders to get an item via Transmit().

yes, my card is the italian SSN card.
I’m trying this code

dim header as new memoryBlock(8)
header.Int32Value(0) = 2 // T1
header.Int32Value(4) = 8 // size of this block

'MF
dim command as new MemoryBlock(7)
command.Int8Value(0) = 0
command.Int8Value(1) = &hA4
command.Int8Value(2) = 0
command.Int8Value(3) = 0
command.Int8Value(4) = &h02
command.Int8Value(5) = &h3F
command.Int8Value(6) = 0

dim buffer as new MemoryBlock(512)
dim ReceiveHeader as new MemoryBlock(8)
dim RecvLength as UInt32 = 512
card.Transmit(header, command, command.Size, nil, buffer, RecvLength)

'DF1
dim command2 as new MemoryBlock(7)
command2.Int8Value(0) = 0
command2.Int8Value(1) = &hA4
command2.Int8Value(2) = 0
command2.Int8Value(3) = 0
command2.Int8Value(4) = &h02
command2.Int8Value(5) = &h11
command2.Int8Value(6) = 0
card.Transmit(header, command2, command2.Size, nil, buffer, RecvLength)

'EF_dati_personali
dim command3 as new MemoryBlock(7)
command3.Int8Value(0) = 0
command3.Int8Value(1) = &hA4
command3.Int8Value(2) = 0
command3.Int8Value(3) = 0
command3.Int8Value(4) = &h02
command3.Int8Value(5) = &h11
command3.Int8Value(6) = &h02
card.Transmit(header, command3, command3.Size, nil, buffer, RecvLength)

'lettura
dim command4 as new MemoryBlock(6)
command4.Int8Value(0) = 0
command4.Int8Value(1) = &hB0
command4.Int8Value(2) = 0
command4.Int8Value(3) = 0
command4.Int8Value(4) = 0
command4.Int8Value(5) = 0
card.Transmit(header, command4, command4.Size, nil, buffer, RecvLength)

I try to enter in the hyerarchy of folder, then the file with personal information.
But I don’t read the information that I need

So our ReadFile would do the step with 0xA4 to select file based on your ID. But we only used 2 byte IDs there so far.

Next it will do the 0xB0 request to read blocks.
If it succeeds, it will read more blocks. So your buffer is over 258 bytes long to hold data?

You get errors?
After each call, you should check first two bytes of buffer for error codes.

In “Trasmi” with command, command2 and command3, I obtain “90”, so I think it’s ok
at moment of command4 I obtain “670000000000000000000000000000…”, so no data.
Is 67 an error code? I don’t know.

yes, please lookup the error description.
This is hex 67!

yes, hex67, I know.

But error description of what? of plugins? of card?

67 00 E Wrong length
you pass wrong length!

ok, thank you…

I’ll have to try to figure out what the right length is

0 is maybe invalid.
Read in 255 byte packages?

0 or &h00 looks like the same thing…

in the QuerySerialNoButton I found “0”

Some cards don’t take a 0 for 256 bytes in length.
So we go with 255 then.

has anyone had experience with the Italian health card? :weary:

I managed to get a “9000”, ie an ok, when reading the file using the “transmit” command. But unfortunately I don’t have the contents of the file. I think the content should immediately follow.

Dear Christian, I think I resolved my situation.
Look the new code:

dim header as new memoryBlock(8)
header.Int32Value(0) = SmartCardMBS.kProtocolT1 // T1
header.Int32Value(4) = 8 // size of this block

dim buffer as new MemoryBlock(256)
dim bufferFinale as new MemoryBlock(258)
dim ReceiveHeader as new MemoryBlock(8)
dim RecvLength as UInt32 = 256 'buffer.Size
dim RecvLengthFinale as UInt32 = 258 

'MF
dim command1 as new MemoryBlock(7)
command1.Int8Value(0) = &h00
command1.Int8Value(1) = &hA4
command1.Int8Value(2) = &h00
command1.Int8Value(3) = &h00
command1.Int8Value(4) = &h02
command1.Int8Value(5) = &h3F
command1.Int8Value(6) = &h00
card.Transmit(header, command1, command1.Size, nil, buffer, RecvLength)

'DF1
dim command2 as new MemoryBlock(7)
command2.Int8Value(0) = &h00
command2.Int8Value(1) = &hA4
command2.Int8Value(2) = &h00
command2.Int8Value(3) = &h00
command2.Int8Value(4) = &h02
command2.Int8Value(5) = &h11
command2.Int8Value(6) = &h00
card.Transmit(header, command2, command2.Size, nil, buffer, RecvLength)

'EF_dati_personali
dim command3 as new MemoryBlock(7)
command3.Int8Value(0) = &h00
command3.Int8Value(1) = &hA4
command3.Int8Value(2) = &h00
command3.Int8Value(3) = &h00
command3.Int8Value(4) = &h02
command3.Int8Value(5) = &h11
command3.Int8Value(6) = &h02
card.Transmit(header, command3, command3.Size, nil, buffer, RecvLength)


'lettura
dim command4 as new MemoryBlock(5)
command4.Int8Value(0) = &h00
command4.Int8Value(1) = &hB0
command4.Int8Value(2) = &h00
command4.Int8Value(3) = &h00
command4.Int8Value(4) = &h00
'command4.Int8Value(5) = &h00
'command4.Int8Value(6) = &h22
card.Transmit(header, command4, command4.Size, nil, bufferFinale, RecvLengthFinale)

I simply created a new and different “buffer” variable (bufferFinale) and a new and different RecvLength variable (RecvLengthFinale). Isn’t that a weird behavior anyway?

2 Likes