installifd.c

Go to the documentation of this file.
00001 /*
00002  * MUSCLE SmartCard Development ( http://www.linuxnet.com )
00003  *
00004  * Copyright (C) 2000-2003
00005  *  David Corcoran <corcoran@linuxnet.com>
00006  *  Ludovic Rousseau <ludovic.rousseau@free.fr>
00007  *
00008  * $Id: installifd.c 1421 2005-04-12 12:09:21Z rousseau $
00009  */
00010 
00016 #include "config.h"
00017 #include <stdio.h>
00018 #include <stdlib.h>
00019 #include <string.h>
00020 #include <sys/stat.h>
00021 #include <errno.h>
00022 
00023 #include "PCSC/wintypes.h"
00024 #include "PCSC/winscard.h"
00025 
00026 #ifndef PCSCLITE_READER_CONFIG
00027 #define PCSCLITE_READER_CONFIG "/etc/reader.conf"
00028 #endif
00029 
00030 int main(int argc, char *argv[])
00031 {
00032 
00033     struct stat statbuf;
00034     char lpcReader[MAX_READERNAME];
00035     char lpcLibrary[FILENAME_MAX];
00036     char *lpcPortID = NULL;
00037     int iPort;
00038     int iStat;
00039     FILE *fd;
00040 
00041     printf("Please enter a friendly name for your reader (%d char max)\n",
00042         (int)sizeof(lpcReader));
00043     printf("-----> ");
00044 
00045     fgets(lpcReader, sizeof(lpcReader), stdin);
00046 
00047     /* remove trailing \n */
00048     lpcReader[strlen(lpcReader)-1] = '\0';
00049 
00050   retrylib:
00051 
00052     printf("Please enter the full path of the readers driver (%d char max)\n",
00053         (int)sizeof(lpcLibrary));
00054     printf("Example: %s/librdr_generic.so\n", PCSCLITE_HP_DROPDIR);
00055     printf("-----> ");
00056 
00057     fgets(lpcLibrary, sizeof(lpcLibrary), stdin);
00058 
00059     /* remove trailing \n */
00060     lpcLibrary[strlen(lpcLibrary)-1] = '\0';
00061 
00062     iStat = stat(lpcLibrary, &statbuf);
00063 
00064     if (iStat != 0)
00065     {
00066         /*
00067          * Library does not exist 
00068          */
00069         printf("Library path %s does not exist.\n\n", lpcLibrary);
00070         goto retrylib;
00071     }
00072 
00073     printf("Please select the I/O port from the list below:\n");
00074     printf("------------------------------------------------\n");
00075     printf("1) COM1 (Serial Port 1)\n");
00076     printf("2) COM2 (Serial Port 2)\n");
00077     printf("3) COM3 (Serial Port 3)\n");
00078     printf("4) COM4 (Serial Port 4)\n");
00079     printf("5) LPT1 (Parallel Port 1)\n");
00080     printf("6) USR1 (Sym Link Defined)\n");
00081     printf("------------------------------------------------\n");
00082 
00083   retryport:
00084 
00085     printf("\n");
00086     printf("Enter number (1-6): ");
00087 
00088     if ((scanf("%d", &iPort) != 1) || iPort < 1 || iPort > 6)
00089     {
00090         printf("Invalid input (%d) please choose (1-5)\n", iPort);
00091         /* eat the \n */
00092         getchar();
00093         goto retryport;
00094     }
00095 
00096     switch (iPort)
00097     {
00098         case 1:
00099             lpcPortID = "0x0103F8";
00100             break;
00101         case 2:
00102             lpcPortID = "0x0102F8";
00103             break;
00104         case 3:
00105             lpcPortID = "0x0103E8";
00106             break;
00107         case 4:
00108             lpcPortID = "0x0102E8";
00109             break;
00110         case 5:
00111             lpcPortID = "0x020378";
00112             break;
00113         case 6:
00114             lpcPortID = "0x000001";
00115             break;
00116     }
00117 
00118     printf("\n\n");
00119     printf("Now creating new " PCSCLITE_READER_CONFIG "\n");
00120 
00121     fd = fopen(PCSCLITE_READER_CONFIG, "w");
00122 
00123     if (fd == NULL)
00124     {
00125         printf("Cannot open file %s: %s\n", PCSCLITE_READER_CONFIG, strerror(errno));
00126         return 1;
00127     }
00128 
00129     fprintf(fd, "%s", "# Configuration file for pcsc-lite\n");
00130     fprintf(fd, "%s", "# David Corcoran <corcoran@linuxnet.com\n");
00131 
00132     fprintf(fd, "%s", "\n\n");
00133 
00134     fprintf(fd, "FRIENDLYNAME     \"%s\"\n", lpcReader);
00135     fprintf(fd, "DEVICENAME       /dev/null\n");
00136     fprintf(fd, "LIBPATH          %s\n", lpcLibrary);
00137     fprintf(fd, "CHANNELID        %s\n", lpcPortID);
00138 
00139     fprintf(fd, "%s", "\n\n");
00140 
00141     fprintf(fd, "%s", "# End of file\n");
00142     return 0;
00143 }
00144 

Generated on Sat Sep 15 17:18:32 2007 for pcsc-lite by  doxygen 1.4.7