Commit 171cc12b authored by axel.maurer's avatar axel.maurer
Browse files

create app file for secure mode

parent 4bbb48fa
......@@ -58,8 +58,7 @@
#define ACTION_BWCARD_OLD_READ_NUMBER_FILE_1 14
#define ACTION_BWCARD_OLD_WRITE_FILE_1 15
#define ACTION_BWCARD_OLD_UID_READ_NUMBER_FILE_1 16
#define ACTION_BWCARD_OLD_WRITE_FILE_1_ENCRYPTED 19
#define ACTION_BWCARD_OLD_CHECK_FILE_1 19
#define ACTION_SUCCESS_BEEP 20
#define ACTION_SUCCESS_BEEP_OUT 21
......@@ -98,6 +97,8 @@
#define ACTION_SECURE_LIST_APPS 112
#define ACTION_SECURE_CREATE_APPS 120
#define ACTION_SECURE_DELETE_APPS 121
#define ACTION_SECURE_CHECK_FOR_APP_FILE 122
#define ACTION_SECURE_CREATE_APP_FILE 123
#define ACTION_SECURE_WRITE_FILE 130
#endif
......@@ -113,6 +114,7 @@
#define CLOSED_APP -1
#define APPID_LEN 6
#define FILEID_LEN 2
#define FILESIZE_LEN 3
#define UID_SIZE 7
#define DEVICE_UID_LEN 12
......@@ -223,18 +225,6 @@ void StartBeep(void)
}
// Ist die App auf der Karte vorhanden?
bool CardHasApp(int appId)
{
if (DESFire_SelectApplication(CRYPTO_ENV0, appId))
{
return true;
}
else
{
return false;
}
}
int GetKeyIndex(int appId, int oe)
{
int i = 0;
......@@ -1029,6 +1019,7 @@ int DoDesFireCardAction(int action, char *parmStr, char *resultStr)
case ACTION_BWCARD_OLD_READ_NUMBER_FILE_1:
case ACTION_BWCARD_OLD_WRITE_FILE_1:
case ACTION_BWCARD_OLD_UID_READ_NUMBER_FILE_1:
case ACTION_BWCARD_OLD_CHECK_FILE_1:
case ACTION_CHECK_KIT_CARD_FILE :
appId = BWCARD_OLD_APP;
case ACTION_BWCARD_READ_NUMBER_DEVICEUID_CARDUID:
......@@ -1187,6 +1178,13 @@ int DoDesFireCardAction(int action, char *parmStr, char *resultStr)
PrintLnDebug(mBuffer);
sprintf(resultStr, "0,%s", mBuffer);
break;
case ACTION_BWCARD_OLD_CHECK_FILE_1:
actSeconds=Dec2Int((byte *)parmStr,strlen(parmStr));
cardSeconds=HexStr2Int(outBufferStr+8,8);
sprintf(mBuffer,"3G seconds: parmStr=%s, actSeconds=%d, regSeconds=%d",parmStr,actSeconds,cardSeconds);
PrintLnDebug(mBuffer);
(actSeconds <= cardSeconds) ? sprintf(resultStr,"True"): sprintf(resultStr, "False");
break;
case ACTION_CHECK_KIT_CARD_FILE:
opCode = HexStr2Int(parmStr, 2);
count = 4;
......@@ -1565,6 +1563,7 @@ int DoDesfireSecureAction(int action, char *parmStr, char *resultStr)
int fileId = -1;
int fileIdFound = false;
int fileIdCount = -1;
int fileSize =0;
byte appFileBuffer[PARM_BUFFER_LEN / 2];
int appFileBufferLen = sizeof(appFileBuffer);
......@@ -1738,6 +1737,38 @@ int DoDesfireSecureAction(int action, char *parmStr, char *resultStr)
buffer2Len = 0;
parmDataLen = 0;
break;
case ACTION_SECURE_CREATE_APP_FILE:
appId = Hex2Int(buffer1, APPID_LEN);
fileId = Hex2Int(buffer1 + APPID_LEN, FILEID_LEN);
fileSize = Hex2Int(buffer1 + APPID_LEN + FILESIZE_LEN, FILEID_LEN);
sprintf(mBuffer, "%3d001,Create App File: appid=0x%x; fileId=%d; fileSize=0x%x", action, appId, fileId, fileSize);
PrintLnDebug(mBuffer);
if (!CheckForApp(appId))
{
sprintf(mBuffer, "%3d102,App not found: appId=0x%x", action, appId);
PrintLnDebug(mBuffer);
sprintf(resultStr, "%s", mBuffer);
return false;
}
if (CheckForAppFile(appId, fileId))
{
sprintf(mBuffer, "%3d103,App File found, not created: appId=0x%x; fileId=%d", action, appId, fileId);
PrintLnDebug(mBuffer);
sprintf(resultStr, "%s", mBuffer);
return false;
}
openedAppGlobal = CLOSED_APP;
if (!CreateAppStdFile(appId, fileId, DESF_FILETYPE_STDDATAFILE, DESF_COMMSET_FULLY_ENC, 0x1220, fileSize, resultStr))
{
sprintf(mBuffer, "%d_03, AppId: 0x%x, fileId: %d - File not created: %s", action, appId, fileId, resultStr);
PrintLnDebug(mBuffer);
return (false);
}
buffer2Len = 0;
parmDataLen = 0;
break;
case ACTION_SECURE_CHECK_FOR_APP:
appId = Hex2Int(buffer1, APPID_LEN);
......@@ -1751,6 +1782,28 @@ int DoDesfireSecureAction(int action, char *parmStr, char *resultStr)
buffer2Len = 0;
parmDataLen = 0;
break;
case ACTION_SECURE_CHECK_FOR_APP_FILE:
appId = Hex2Int(buffer1, APPID_LEN);
fileId = Hex2Int(buffer1 + APPID_LEN, FILEID_LEN);
sprintf(mBuffer, "%3d001,Check for App File: appid=0x%x; fileId=%d", action,appId, fileId);
PrintLnDebug(mBuffer);
if (!CheckForApp(appId))
{
sprintf(mBuffer, "%3d102,App not found: appId=0x%x", action, appId);
PrintLnDebug(mBuffer);
sprintf(resultStr, "%s", mBuffer);
return false;
}
if (!CheckForAppFile(appId, fileId))
{
sprintf(mBuffer, "%3d103,App File not found: appId=0x%x; fileId=%d", action, appId, fileId);
PrintLnDebug(mBuffer);
sprintf(resultStr, "%s", mBuffer);
return false;
}
buffer2Len = 0;
parmDataLen = 0;
break;
case ACTION_SECURE_LIST_APPS:
sprintf(mBuffer, "Entering Action 112 listApps");
PrintLnDebug(mBuffer);
......@@ -2040,9 +2093,12 @@ int main(void)
case ACTION_BWCARD_READ_NUMBER_ENCRYPTED:
case ACTION_BWCARD_READ_NUMBER:
case ACTION_BWCARD_READ_ALL:
#ifdef UKN
case ACTION_BWCARD_OLD_READ_NUMBER_FILE_1:
case ACTION_BWCARD_OLD_WRITE_FILE_1:
case ACTION_BWCARD_OLD_UID_READ_NUMBER_FILE_1:
#endif
case ACTION_BWCARD_OLD_CHECK_FILE_1:
#endif
// case ACTION_DELETE_APP:
......@@ -2055,50 +2111,39 @@ int main(void)
case ACTION_SECURE_CHECK_FOR_APP:
case ACTION_SECURE_LIST_APPS:
case ACTION_SECURE_WRITE_FILE:
case ACTION_SECURE_CHECK_FOR_APP_FILE:
case ACTION_SECURE_CREATE_APP_FILE:
#endif // NO_SECURE
#ifndef READER_ACTION
if (action != ACTION_CHECK_FOR_CARD)
{
LEDOn(REDLED);
if (action != ACTION_CHECK_FOR_CARD) { LEDOn(REDLED);
}
#endif
FillBytes((byte *)resultBuffer, 0, sizeof(resultBuffer));
if (CardAction(action, parmStr, resultBuffer))
{
PrintLnInfo(resultBuffer);
FillBytes((byte *)resultBuffer, 0, sizeof(resultBuffer));
if (CardAction(action, parmStr, resultBuffer)) { PrintLnInfo(resultBuffer);
#ifdef READER_ACTION
if ((pStr = strchr((char *)resultBuffer, ',')) != NULL)
{
*pStr = 0x0;
if (Dec2Int((byte *)resultBuffer, strlen(resultBuffer)) > 0)
{
Beep(60, 2249, 250, 50);
Beep(60, 2249, 350, 0);
}
else
{
Beep(50, 1318, 30, 20);
Beep(50, 1397, 30, 20);
Beep(30, 1568, 30, 20);
Beep(50, 1760, 30, 20);
Beep(50, 1975, 30, 20);
}
}
if ((pStr = strchr((char *)resultBuffer, ',')) != NULL) {
*pStr = 0x0;
if (Dec2Int((byte *)resultBuffer, strlen(resultBuffer)) > 0) { Beep(60, 2249, 250, 50);
Beep(60, 2249, 350, 0);
} else { Beep(50, 1318, 30, 20);
Beep(50, 1397, 30, 20);
Beep(30, 1568, 30, 20);
Beep(50, 1760, 30, 20);
Beep(50, 1975, 30, 20);
}
}
#endif
action = setAction(NO_ACTION);
}
else
{
action = setAction(NO_ACTION);
} else {
#ifndef READER_ACTION
sprintf(mBuffer, "09,no card for action %d", action);
PrintLnInfo(mBuffer);
action = setAction(NO_ACTION);
#endif
}
LEDOff(REDLED);
} LEDOff(REDLED);
break;
case ACTION_LOGIN_DATA:
case ACTION_LOGIN_DATA:
LEDOn(REDLED);
DoDesFireCardAction(action, parmStr, resultBuffer);
PrintLnInfo(resultBuffer);
......
Markdown is supported
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