Commit e93c27aa authored by axel.maurer's avatar axel.maurer
Browse files

.

parent a6915416
......@@ -70,6 +70,7 @@
#define ACTION_BWCARD_READ_NUMBER_DEVICEUID 62
#define ACTION_BWCARD_READ_NUMBER_DEVICEUID_CARDUID 63
#define ACTION_BWCARD_READ_NUMBER_ENCRYPTED_DEVICEUID 64
#define ACTION_BWCARD_READ_ALL 65
#define ACTION_CREATE_OSS_APP 70
#define ACTION_READ_OSS_APP_INFO_FILE 71
......@@ -893,15 +894,13 @@ void ReadDeviceUid(char *result)
{
byte deviceUid[DEVICE_UID_LEN];
GetDeviceUID(deviceUid);
ConvertBinaryToString(deviceUid, 0, DEVICE_UID_LEN * 8, result, 16, 0, 50);
ConvertBinaryToString(deviceUid, 0, DEVICE_UID_LEN * 8, result, 16, DEVICE_UID_LEN*2, 50);
}
int ReadDesFireCardUID(int appId, char *resultBuffer, int *resultBufferLen)
{
byte uid[UID_SIZE];
int uidLen;
byte uidReverse[UID_SIZE];
int i;
if (!DesfireCardOpenApp(appId, AUTH_KEY_READ))
{
......@@ -913,12 +912,8 @@ int ReadDesFireCardUID(int appId, char *resultBuffer, int *resultBufferLen)
{
sprintf(mBuffer, "uid: %02X%02X%02X%02X%02X%02X%02X", (unsigned int)uid[0], (unsigned int)uid[1], (unsigned int)uid[2], (unsigned int)uid[3], (unsigned int)uid[4], (unsigned int)uid[5], (unsigned int)uid[6]);
PrintLnDebug(mBuffer);
for (i = 0; i <= 6; i++)
{
uidReverse[6 - i] = uid[i];
}
*resultBufferLen = ConvertBinaryToString(uidReverse, 0, UID_SIZE * 8, (char *)resultBuffer, 10, 0, 20);
*resultBufferLen = ConvertBinaryToString(uid, 0, UID_SIZE * 8, (char *)resultBuffer, 16, UID_SIZE*2, 20);
}
else
{
......@@ -972,6 +967,7 @@ int DoDesFireCardAction(int action, char *parmStr, char *resultStr)
byte byteBuffer[250];
char bwCardNumber[30];
char bwCardNumberEnc[200];
char outBufferStr[MBUFFER_LEN];
byte appFileBuffer[PARM_BUFFER_LEN / 2];
int appFileBufferLen = sizeof(appFileBuffer);
......@@ -979,7 +975,7 @@ int DoDesFireCardAction(int action, char *parmStr, char *resultStr)
char deviceUid[50];
OssInfoFileData ossInfoFileData[32];
OssInfoFileData *pOssInfoFileData;
int appId;
int appId = 0;
int fileId;
int position;
int opCode;
......@@ -995,20 +991,31 @@ int DoDesFireCardAction(int action, char *parmStr, char *resultStr)
case ACTION_BWCARD_OLD_READ_NUMBER_DEVICEUID:
case ACTION_BWCARD_OLD_READ_NUMBER_ENCRYPTED:
case ACTION_BWCARD_OLD_READ_NUMBER:
appId = BWCARD_OLD_APP;
case ACTION_BWCARD_READ_NUMBER_DEVICEUID_CARDUID:
case ACTION_BWCARD_READ_NUMBER_ENCRYPTED_DEVICEUID:
case ACTION_BWCARD_READ_NUMBER_DEVICEUID:
case ACTION_BWCARD_READ_NUMBER_ENCRYPTED:
case ACTION_BWCARD_READ_NUMBER:
case ACTION_CHECK_KIT_CARD_FILE:
if (appId == 0)
{
appId = BWCARD_APP;
}
// App oeffnen
if (!DesfireCardOpenApp(BWCARD_OLD_APP, AUTH_KEY_READ))
if (!DesfireCardOpenApp(appId, AUTH_KEY_READ))
{
sprintf(resultStr, "103,Error opening App: 0x%x with Key: %d", BWCARD_OLD_APP, AUTH_KEY_READ);
sprintf(resultStr, "103,Error opening App: 0x%x with Key: %d", appId, AUTH_KEY_READ);
return (false);
}
// UID lesen und in cardUid speichern
bufferLen = sizeof(cardUid);
FillBytes((byte *)cardUid, 0, sizeof(bufferLen));
if (ReadDesFireCardUID(BWCARD_OLD_APP, cardUid, &bufferLen))
if (ReadDesFireCardUID(appId, cardUid, &bufferLen))
{
sprintf(mBuffer, "ReadDesFireCardUID: DESFire appId: 0x%x, resultbuffer: %s", BWCARD_OLD_APP, cardUid);
sprintf(mBuffer, "ReadDesFireCardUID: DESFire appId: 0x%x, resultbuffer: %s", appId, cardUid);
PrintLnDebug(mBuffer);
}
else
......@@ -1020,14 +1027,15 @@ int DoDesFireCardAction(int action, char *parmStr, char *resultStr)
//cardNumber lesen und in bwCardNumber speichern
bufferLen = sizeof(bwCardNumber);
FillBytes((byte *)bwCardNumber, 0, bufferLen);
if (!ReadDesFireCardAppFile(BWCARD_OLD_APP, BWCARD_DESFIRE_APP_FILEID, (byte *)bwCardNumber, &bufferLen, 0, 0, AUTH_KEY_READ, resultStr))
if (!ReadDesFireCardAppFile(appId, BWCARD_DESFIRE_APP_FILEID, (byte *)bwCardNumber, &bufferLen, 0, 0, AUTH_KEY_READ, resultStr))
{
sprintf(mBuffer, "124,Error: Action: %d, Reading App 0x:%x failed: %s", action, BWCARD_OLD_APP, resultStr);
sprintf(mBuffer, "124,Error: Action: %d, Reading App 0x:%x failed: %s", action, appId, resultStr);
PrintLnDebug(mBuffer);
sprintf(resultStr, "%s", mBuffer);
return (false);
}
sprintf(mBuffer,"cardNumber read: bwCardNumber=%s, bufferLen=%d", bwCardNumber, bufferLen);
PrintLnDebug(mBuffer);
// Kartennummer verschlüsslen und in bwCardEnc speichern
bufferLen = sizeof(bwCardNumberEnc);
FillBytes((byte *)bwCardNumberEnc, 0, bufferLen);
......@@ -1043,18 +1051,23 @@ int DoDesFireCardAction(int action, char *parmStr, char *resultStr)
switch (action)
{
case ACTION_BWCARD_OLD_READ_NUMBER_DEVICEUID_CARDUID:
sprintf(resultStr, "%s,%s,%s", bwCardNumber, cardUid, deviceUid);
case ACTION_BWCARD_READ_NUMBER_DEVICEUID_CARDUID:
sprintf(resultStr, "%s;%s;%s", bwCardNumber, cardUid, deviceUid);
break;
case ACTION_BWCARD_OLD_READ_NUMBER_ENCRYPTED_DEVICEUID:
sprintf(resultStr, "%s,%s", bwCardNumberEnc, deviceUid);
case ACTION_BWCARD_READ_NUMBER_ENCRYPTED_DEVICEUID:
sprintf(resultStr, "%s;%s", bwCardNumberEnc, deviceUid);
break;
case ACTION_BWCARD_OLD_READ_NUMBER_ENCRYPTED:
case ACTION_BWCARD_READ_NUMBER_ENCRYPTED:
sprintf(resultStr, "%s", bwCardNumberEnc);
break;
case ACTION_BWCARD_OLD_READ_NUMBER_DEVICEUID:
sprintf(resultStr, "%s,%s", bwCardNumber, deviceUid);
case ACTION_BWCARD_READ_NUMBER_DEVICEUID:
sprintf(resultStr, "%s;%s", bwCardNumber, deviceUid);
break;
case ACTION_BWCARD_OLD_READ_NUMBER:
case ACTION_BWCARD_READ_NUMBER:
sprintf(resultStr, "%s", bwCardNumber);
break;
case ACTION_CHECK_KIT_CARD_FILE:
......@@ -1146,6 +1159,61 @@ int DoDesFireCardAction(int action, char *parmStr, char *resultStr)
break;
}
break;
case ACTION_BWCARD_READ_ALL:
appId = BWCARD_APP;
// App oeffnen
if (!DesfireCardOpenApp(appId, AUTH_KEY_READ))
{
sprintf(resultStr, "103,Error opening App: 0x%x with Key: %d", appId, AUTH_KEY_READ);
return (false);
}
//cardNumber lesen und in bwCardNumber speichern
bufferLen = sizeof(bwCardNumber);
FillBytes((byte *)bwCardNumber, 0, bufferLen);
if (!ReadDesFireCardAppFile(appId, 0, (byte *)bwCardNumber, &bufferLen, 0, 0, AUTH_KEY_READ, resultStr))
{
sprintf(mBuffer, "124,Error: Action: %d, Reading App 0x:%x failed: %s", action, appId, resultStr);
PrintLnDebug(mBuffer);
sprintf(resultStr, "%s", mBuffer);
return (false);
}
bufferLen = sizeof(byteBuffer);
FillBytes(byteBuffer, 0, bufferLen);
if (!ReadDesFireCardAppFile(appId, 1, byteBuffer, &bufferLen, 0, 0, AUTH_KEY_READ, resultStr))
{
sprintf(mBuffer, "124,Error: Action: %d, Reading App 0x:%x failed: %s", action, appId, resultStr);
PrintLnDebug(mBuffer);
sprintf(resultStr, "%s", mBuffer);
return (false);
}
sprintf(outBufferStr,"%s;%s;",bwCardNumber,(char *) byteBuffer);
sprintf("bwCardAll File 0 & 1: %s",outBufferStr);
bufferLen = sizeof(byteBuffer);
FillBytes(byteBuffer, 0, bufferLen);
if (!ReadDesFireCardAppFile(appId, 2, byteBuffer, &bufferLen, 0, 0, AUTH_KEY_READ, resultStr))
{
sprintf(mBuffer, "124,Error: Action: %d, Reading App 0x:%x failed: %s", action, appId, resultStr);
PrintLnDebug(mBuffer);
sprintf(resultStr, "%s", mBuffer);
return (false);
}
ConvertBinaryToString(byteBuffer,0,8*10,bwCardNumber,16,2*10,2*10);
strcat(outBufferStr,bwCardNumber);
bufferLen = sizeof(byteBuffer);
FillBytes(byteBuffer, 0, bufferLen);
if (!ReadDesFireCardAppFile(appId, 3, byteBuffer, &bufferLen, 0, 0, AUTH_KEY_READ, resultStr))
{
sprintf(mBuffer, "124,Error: Action: %d, Reading App 0x:%x failed: %s", action, appId, resultStr);
PrintLnDebug(mBuffer);
sprintf(resultStr, "%s", mBuffer);
return (false);
}
strcat(outBufferStr, ";");
strcat(outBufferStr, (char *)byteBuffer);
sprintf(mBuffer,"bwCardReadAll: %s",outBufferStr);
PrintLnDebug(mBuffer);
sprintf(resultStr,"%s",outBufferStr);
break;
case ACTION_DELETE_APP:
appId = HexStr2Int(parmStr, strlen(parmStr));
if (!CheckForApp(appId))
......@@ -1825,6 +1893,12 @@ int main(void)
case ACTION_READ_OSS_APP_INFO_FILE:
case ACTION_CHECK_KIT_CARD_FILE:
case ACTION_READ_FILE_DATA:
case ACTION_BWCARD_READ_NUMBER_DEVICEUID_CARDUID:
case ACTION_BWCARD_READ_NUMBER_ENCRYPTED_DEVICEUID:
case ACTION_BWCARD_READ_NUMBER_DEVICEUID:
case ACTION_BWCARD_READ_NUMBER_ENCRYPTED:
case ACTION_BWCARD_READ_NUMBER:
case ACTION_BWCARD_READ_ALL:
#endif
case ACTION_DELETE_APP:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment