int main(int argc, char *argv[]) { int getoptOption; char *getoptPort = "/dev/ttyUSB0"; char *getoptULM = "./ulm"; /* Global var with program name */ strcpy(programName,basename(argv[0])); while ((getoptOption = getopt (argc, argv, "h?p:u:")) != -1) switch (getoptOption) { case 'h':printHelp(); break; case '?':printHelp(); break; case 'p':getoptPort = optarg; break; case 'u':getoptULM = optarg; break; } printHeadline(); applicationBtx(getoptULM,getoptPort); return 0; }
/* Print online help (Commandline mode) */ void printHelp(void) { printHeadline(); printf("\r\n"); printf("Note: Currently only Phoenix readers are supported with command line mode!\r\n"); printf("\r\n"); printf(" * Parameters:\r\n"); printf(" -h or -? ............ Print this screen\r\n"); printf(" -v .................. Verbose mode - prints debug information\r\n"); printf(" -e .................. Phoenix reader mode\r\n"); printf(" -b [INT] ............ Specify baudrate (default: 9k6)\r\n"); printf(" -f [5|7|8] .......... Specify framesize (default: 8)\r\n"); printf(" -p [O|E|N]........... Specify parity (default: Even)\r\n"); printf(" -a .................. Reset card\r\n"); printf(" -A .................. Reset card and output ATR\r\n"); printf(" -c [HEX STRING] ..... Execute APDU-Command\r\n"); printf("\r\n"); printf(" * Usage:\r\n"); printf(" %s \r\n",programName); printf("\r\n"); printf(" * Phoenix Examples:\r\n"); printf(" Display ATR\r\n"); printf(" %s -v -e -A\r\n",programName); printf(" Read ICC-ID from a sim card\r\n"); printf(" %s -eac \"a0 a4 00 00 02 3f 00/a0 a4 00 00 02 2f e2/a0 b0 00 00 0a\" \r\n",programName); printf("\r\n"); exit(0); }
/* Print online help (Commandline mode) */ void printHelp(void) { printHeadline(); printf("\n"); printf(" * Parameters:\n"); printf(" -h or -? ............ Print this screen\n"); printf(" -p [PATH] ........... Serial port e.g. /dev/ttyUSB0\n"); printf(" -u [PATH] ........... ULM Directory (BTX-Pages)\n"); printf("\n"); exit(0); }
int main(int argc, char *argv[]) { /* Read out config file */ initalizeConfigFileValues(); /* Global var with program name */ strcpy(programName,basename(argv[0])); /* Getopt variables */ int getoptOption; int getoptVerbose = 0; int getoptPhoenix = 0; int getoptBaudrate = 9600; int getoptFramesize = 8; int getoptParity = 'E'; int getoptReset = 0; int getoptResetAtr = 0; char *getoptApduCommands = 0; /* Contains the batch of APUD commands as a delimeter seperated list */ char apduCommandString[3000]; char apduCommand[1000]; int apduCommandLen = 0; int apduCommandCount = 0; /* Number of APDU-Commands */ char *apduSwStart = 0; char *apduStatusWordPointer = 0; char apduStatusWord[1000]; int i; if(argc == 1) mainMenue(); /* No parameters given ==> Main menue */ else { while ((getoptOption = getopt (argc, argv, "h?veb:f:p:aAc:")) != -1) switch (getoptOption) { case 'h': printHelp(); break; case '?': printHelp(); break; case 'v': getoptVerbose = 1; break; case 'e': getoptPhoenix = 1; break; case 'a': getoptReset = 1; break; case 'A': getoptResetAtr = 1; break; case 'b': getoptBaudrate = atoi(optarg); break; case 'f': getoptFramesize = atoi(optarg); break; case 'p': getoptParity = optarg[0]; break; case 'c': getoptApduCommands = optarg; break; } if(getoptVerbose) { printHeadline(); printf("\r\n"); printf(" * Running in commandline mode:\r\n"); printf(" * Verbose mode is on\r\n"); printf(" * Serial port settings are:\r\n"); printf(" Communication port is: %s\r\n",configfilePortValue); printf(" Baudrate (for chipcardLab hardware) is: %s baud\r\n",configfileBaudrateValue); printf(" Baudrate (for smartcard) is: %i baud\r\n",getoptBaudrate); printf(" Framesize (for smartcard) is: %i bits\r\n",getoptFramesize); printf(" Parity setting (for smartcard) is: %c bits\r\n",getoptParity); } /* Phoenix reader mode */ if(getoptPhoenix) { setTerminalMode(PHOENIX); /* Tell the subsystem that we deal with a phoenix-reader */ if(getoptVerbose) printf(" * Info: Phoenix-Mode selected.\r\n"); phoenixSetup(getoptBaudrate, getoptFramesize, getoptParity, getoptVerbose); /* Reset the smartcard */ if(getoptReset) phoenixReset(getoptVerbose); else if(getoptResetAtr) { phoenixReset(getoptVerbose); phoenixDisplayAtr(getoptVerbose); printf("\r\n"); } /* Clear buffer */ ttyClearBuffer(configfilePortValue); /* Some commands have to be executed */ if(getoptApduCommands) { trimStringChar(getoptApduCommands, ' '); trimStringChar(getoptApduCommands, APDU_LIST_DELIMETER); trimStringChar(getoptApduCommands, ' '); apduCommandCount = countChar(getoptApduCommands, APDU_LIST_DELIMETER, strlen(getoptApduCommands)) + 1; if(getoptVerbose) printf(" * Number of APDU-Commands to process is: %i\r\n",apduCommandCount); for(i = 0; i < apduCommandCount; i++) { /* Extract item from delimeter seperated list */ listExtract(getoptApduCommands, strlen(getoptApduCommands),APDU_LIST_DELIMETER, apduCommandString, sizeof(apduCommandString),i); /* Check for status word definition */ apduSwStart = strchr(apduCommandString, APDU_SW_DELIMETER); if(apduSwStart) { strcpy(apduStatusWord,apduSwStart+1); *apduSwStart = '\0'; hexString2numeric(apduSwStart + 1,apduStatusWord,2); apduStatusWordPointer = apduStatusWord; } else apduStatusWordPointer = 0; if(getoptVerbose) printf(" * Executing command #%i APDU=%s\r\n", i+1, apduCommandString); apduCommandLen = hexString2numeric(apduCommandString,apduCommand,sizeof(apduCommand)); if(executeApduCommand(apduCommand, apduCommandLen, apduStatusWordPointer, getoptVerbose) != 0) { printf("\r\n"); exit(1); } if((!getoptVerbose)&&(i<apduCommandCount-1)) printf("/"); fflush(stdout); } if(!getoptVerbose) printf("\r\n"); } exit(0); } /* No suitable mode selected */ else { printf(" * Error: No suitable mode selected - exiting...\r\n"); exit(1); } } return 0; }
/* Menue driven mode */ void mainMenue(void) { char chrUserSelection = 0; printHeadline(); printMenu(); printf("\n\r"); printf(" * Note: Please report bugs/feedback to: [email protected]\r\n"); while(chrUserSelection != 'X') { chrUserSelection = userMenueButton("LVDRP?XONCMST32GHE","\r\n>>> ","^invalid selection\n\r"); if(connected) ttyClearBuffer(configfilePortValue); /* Clear serial line buffer */ switch(chrUserSelection) { case 'D': if(connected) chipcardLabDebug(); else notConnected(); break; case 'R': if(connected) script(); else notConnected(); break; case '3': if(connected) threeWhireCardTerminal(); else notConnected(); break; case '2': if(connected) i2cCardTerminal(); else notConnected(); break; case 'V': if(connected) chipcardLabVersion(); else notConnected(); break; case 'H': if(connected) chipcardLabPluginCheck(); else notConnected(); break; case 'G': if(connected) { if(chipcardLabPluginCheck() == 0) { printf(" * Executing plugin...\r\n"); plugin(); } } else notConnected(); break; case 'O': if(connected) logicanalyser(); else notConnected(); break; case 'N': if(connected) txSniff(); else notConnected(); break; case 'M': if(connected) txTerminal(); else notConnected(); break; case '?': printMenu(); break; case 'L': if(connected) printf("Already connected!"); else connectChipcardLab(1); break; case 'S': if(connected) alreadyConnected(); else openSeasonLogger(); break; case 'C': if(connected) alreadyConnected(); else dumpData(DUMP_SOURCE_FILE); break; case 'T': if(connected) alreadyConnected(); else openSerprogTerminal(); break; case 'E': if(connected) alreadyConnected(); else openPhoenixTerminal(); break; case 'P': if(connected) alreadyConnected(); else modifyPortConfig(); break; case 'X': printf("Exiting...\n\r"); break; } } }
/** * @brief Entry point. * * Run the program with "--no-fork" or "-n" to prevent it from forking. This might be useful for examining * crashes, but suppresses the corruption tests. * * @param argc Number of command line arguments. * @param argv Array with the command line arguments. * @return Always EXIT_SUCCESS. */ int main(int argc, char *argv[]) { struct Statistics s = {0, 0, 0, FORK_SUPPORTED}; /* Print introduction */ puts("====================================="); puts("MALLOC-TEST (Testcase fuer Aufgabe 4)"); puts("====================================="); /* Check command line */ if ((argc == 2) && ((strcmp(argv[1], "--no-fork") == 0) || (strcmp(argv[1], "-n") == 0))) { s.doFork = 0; putchar('\n'); puts("fork()-Modus wurde zwecks Fehlersuche ausgeschaltet."); puts("Die abort()-Tests wurden deshalb deaktiviert."); } /* malloc() tests */ printHeadline("1. malloc():"); runTest(&s, singleBlockTest, NULL, 1); runTest(&s, multiBlockTest, "Speicher mit mehreren Anfragen komplett fuellen", 1); runTest(&s, mallocZeroTest, "malloc(0)", 1); runTest(&s, mallocFailTest, NULL, 1); runTest(&s, alignmentTest, "Alignment", 0); /* free() tests */ printHeadline("2. free():"); runTest(&s, freeNullTest, "free(NULL)", 1); if (s.doFork) runTest(&s, freeCorruptTest, "free() mit kaputter Verwaltungsstruktur", 0); /* realloc() tests */ printHeadline("3. realloc():"); runTest(&s, reallocIncreaseTest, "Block mit realloc() vergroessern", 1); runTest(&s, reallocDecreaseTest, "Block mit realloc() verkleinern", 1); runTest(&s, reallocNullTest, "realloc() mit NULL-Zeiger aufrufen", 1); runTest(&s, reallocZeroTest, "realloc() mit Groesse 0", 1); runTest(&s, reallocFailTest, NULL, 1); if (s.doFork) runTest(&s, reallocCorruptTest, "realloc() mit kaputter Verwaltungsstruktur", 0); /* calloc() tests */ printHeadline("4. calloc():"); runTest(&s, callocTest, "calloc()-Test", 1); runTest(&s, callocFailTest, NULL, 1); /* Print summary */ putchar('\n'); puts("======================================="); printf("%u von %u Tests waren erfolgreich. ", s.successCount, s.testCount); if (s.successCount == s.testCount) { /* All tests successful */ puts(":-D"); } else if (s.successCount * 3 >= s.testCount * 2) { /* >= 2/3 of all tests successful */ puts(":-)"); } else if (s.successCount * 3 >= s.testCount) { /* >= 1/3 of all tests successful */ puts(":-|"); } else if (s.successCount > 0) { /* At least one test successful */ puts(":-/"); } else { /* Everything FUBAR */ puts("=:-O"); } puts("======================================="); /* Print debugging hint if a crash has occurred */ if (s.crashCount > 0) { printf("\n%u Tests haben Abstuerze verursacht. Tipp fuers Debuggen:\n", s.crashCount); puts(" gdb ./malloc-test"); puts(" run --no-fork"); } return EXIT_SUCCESS; }