PC SOFT

PROFESSIONAL NEWSGROUPS
WINDEVWEBDEV and WINDEV Mobile

Home → WINDEV 2024 → Problème envoi APDU - carte à puce
Problème envoi APDU - carte à puce
Started by GerardB, Apr., 25 2018 5:55 PM - 1 reply
Posted on April, 25 2018 - 5:55 PM
************************************************CODE VB FOURNI DANS LE SDK
Private Sub REQUESTICCBUTTON_Click()

Dim rc As Byte ' return Code
Dim CTN As Integer
Dim PN As Integer

' CT_DATA parameters
Dim Dad As Integer ' Destination adresse 01 = CT, 0 = ICC
Dim Sad As Integer ' Source address 02 = HOST, 05 = REMOTE_HOST
Dim Lenc As Integer ' Command length in byte
Dim APDUCde(20) As Byte ' Command buffer
Dim Lenr As Integer ' Returned response length
Dim Response(MAX_RESPONSE_SIZE) As Byte ' APDU response

' Set CT_DATA parameters

Sad = &H2 ' Source address 02 = HOST, 05 = REMOTE_HOST
Dad = &H1 ' Destination adresse 01 = CT, 0 = ICC
Lenr = MAX_RESPONSE_SIZE ' Size of response buffer
CTN = Form1.CTNEdt.Text ' Set (Card Terminal Number)

'Set Header Command

APDUCde(0) = &H20 ' CLA
APDUCde(1) = &H12 ' INS 12 = Request ICC
APDUCde(2) = &H1 ' P1 01-0E = CT/ICC-Interface 1-14
APDUCde(3) = &H1 ' P2 01 = return complete ATR

'Set Body Command

APDUCde(4) = &H0 ' LE 00 = return full length of requested information
Lenc = 5 ' Length of APDUCde

' Display commande
Form1.APDUEdt.Text = HexaToString(APDUCde, 5)

' Execute CT_DATA

rc = CT_DATA(CTN, Dad, Sad, Lenc, APDUCde(LBound(APDUCde)), Lenr, Response(LBound(Response)))

' Return code treatment

If rc <> OK Then
rc = MsgBox("CT_DATA not successfull", vbOKOnly, "Error")
End If

' Display error if CT_DATA was successfull, but the card returned
' StatusBytes which aren´t '9000'
If Response(Lenr - 2) <> &H90 Then
rc = MsgBox(Switch(Response(Lenr - 2) = &H62 And Response(Lenr - 1) = &H0, "Warning: no card presented within specified time", _
Response(Lenr - 2) = &H62 And Response(Lenr - 1) = &H1, "Warning: ICC already present and activated", _
Response(Lenr - 2) = &H64 And Response(Lenr - 1) = &H0, "Warning: reset not successfull", _
Response(Lenr - 2) = &H64 And Response(Lenr - 1) = &H1, "Process aborted by pressing of Cancel Key", _
Response(Lenr - 2) = &H69 And Response(Lenr - 1) = &H0, "APDUCde with timer not supported", _
1 = 1, "unknown error"), _
vbOKOnly, "Error")
Exit Sub
End If

' Card type detection : If SW2 = &H0 -> Synchronous card detected, If SW2 = &H1 -> Asynchronous card detected
If Response(Lenr - 1) = &H0 Then
Form1.SynchronousType.Value = 1
Form1.ASynchronousType.Value = 0
ElseIf Response(Lenr - 1) = &H1 Then
Form1.ASynchronousType.Value = 1
Form1.SynchronousType.Value = 0
End If


' if RequestICC was successfull display ATR
Form1.ATREdt.Text = HexaToString(Response, Lenr - 2)

End Sub
*****************************************MON CODE WL
Apdu is array of 20 byte


Apdu[1] = 0x20
//CL
Apdu[2] = 0x12
// INS
Apdu[3] = 0x01
//P1
Apdu[4] = 0x01
//P2
Apdu[5] = 0x00

ChargeDLL("CTGmplus.dll")

AP_Reponse est un entier

AP_Reponse=API("CTGmplus.dll", "CT_init",1,0)


//APDU qui doit être envoyé 20 12 01 01 00

tabDad,tabSad,tabLenth are array of 1 byte

tabDad[1] =0x01
tabSad[1] =0x02
tabLenth[1] =0x10
RESP est un Buffer
Req est un int


dad,sad,lenth sont des int
dad = &tabDad[1]
sad = &tabSad[1]

//request ICC
lenth = 1500
Req = API("CTGmplus.dll", "CT_data", 1,dad,sad,5, &Apdu,1500,&RESP)
**************************ici Req doit renvoyer 0 si l'opération réussie mais c'est toujours > 0 genre 255 ou autres...
SI Req = 0 ALORS
Info("Opération términée avec succès!")
SINON
Info(ErreurInfo(errComplet))

FIN

//Merci de votre aide
Registered member
939 messages
Popularité : +66 (68 votes)
Posted on April, 26 2018 - 5:35 PM
bonjour,

comme çà la, pas évident, déjà je dirais qu'il y a un problème sur votre paramètre 1500 , c'est votre DLL qui va vous donner la taille de ce qu'elle vous à retournez et pas à vous de lui dire.
donc il faudrait remplacer le 1500 par un &lenth
et pour RESP c'est un buffer, mais pas initialiser.
Remplacez le par un buffer sur MAX_RESPONSE_SIZE ( je connais pas cette valeur )

après vos tableaux de 1 byte où vous transférez leur adresses dans des entiers me parait compliqué.