pcsc-lite  1.9.0
installifd.c
Go to the documentation of this file.
1 /*
2  * MUSCLE SmartCard Development ( https://pcsclite.apdu.fr/ )
3  *
4  * Copyright (C) 2000-2003
5  * David Corcoran <corcoran@musclecard.com>
6  * Copyright (C) 2002-2009
7  * Ludovic Rousseau <ludovic.rousseau@free.fr>
8  *
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions
11 are met:
12 
13 1. Redistributions of source code must retain the above copyright
14  notice, this list of conditions and the following disclaimer.
15 2. Redistributions in binary form must reproduce the above copyright
16  notice, this list of conditions and the following disclaimer in the
17  documentation and/or other materials provided with the distribution.
18 3. The name of the author may not be used to endorse or promote products
19  derived from this software without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
38 #include "config.h"
39 #include <stdio.h>
40 #include <stdlib.h>
41 #include <string.h>
42 #include <sys/stat.h>
43 #include <errno.h>
44 
45 #include "PCSC/wintypes.h"
46 #include "PCSC/winscard.h"
47 
48 #ifndef PCSCLITE_READER_CONFIG
49 #define PCSCLITE_READER_CONFIG "/etc/reader.conf"
50 #endif
51 
52 int main(/*@unused@*/ int argc, /*@unused@*/ char *argv[])
53 {
54 
55  struct stat statbuf;
56  char lpcReader[MAX_READERNAME];
57  char lpcLibrary[FILENAME_MAX];
58  char *lpcPortID = NULL;
59  int iPort;
60  int iStat;
61  FILE *fd;
62 
63  printf("Please enter a friendly name for your reader (%d char max)\n",
64  (int)sizeof(lpcReader));
65  printf("-----> ");
66 
67  (void)fgets(lpcReader, sizeof(lpcReader), stdin);
68 
69  /* remove trailing \n */
70  lpcReader[strlen(lpcReader)-1] = '\0';
71 
72  retrylib:
73 
74  printf("Please enter the full path of the readers driver (%d char max)\n",
75  (int)sizeof(lpcLibrary));
76  printf("Example: %s/librdr_generic.so\n", PCSCLITE_HP_DROPDIR);
77  printf("-----> ");
78 
79  (void)fgets(lpcLibrary, sizeof(lpcLibrary), stdin);
80 
81  /* remove trailing \n */
82  lpcLibrary[strlen(lpcLibrary)-1] = '\0';
83 
84  iStat = stat(lpcLibrary, &statbuf);
85 
86  if (iStat != 0)
87  {
88  /*
89  * Library does not exist
90  */
91  printf("Library path %s does not exist.\n\n", lpcLibrary);
92  goto retrylib;
93  }
94 
95  printf("Please select the I/O port from the list below:\n");
96  printf("------------------------------------------------\n");
97  printf("1) COM1 (Serial Port 1)\n");
98  printf("2) COM2 (Serial Port 2)\n");
99  printf("3) COM3 (Serial Port 3)\n");
100  printf("4) COM4 (Serial Port 4)\n");
101  printf("5) LPT1 (Parallel Port 1)\n");
102  printf("6) USR1 (Sym Link Defined)\n");
103  printf("------------------------------------------------\n");
104 
105  retryport:
106 
107  printf("\n");
108  printf("Enter number (1-6): ");
109 
110  if ((scanf("%d", &iPort) != 1) || iPort < 1 || iPort > 6)
111  {
112  printf("Invalid input (%d) please choose (1-5)\n", iPort);
113  /* eat the \n */
114  (void)getchar();
115  goto retryport;
116  }
117 
118  switch (iPort)
119  {
120  case 1:
121  lpcPortID = "0x0103F8";
122  break;
123  case 2:
124  lpcPortID = "0x0102F8";
125  break;
126  case 3:
127  lpcPortID = "0x0103E8";
128  break;
129  case 4:
130  lpcPortID = "0x0102E8";
131  break;
132  case 5:
133  lpcPortID = "0x020378";
134  break;
135  case 6:
136  lpcPortID = "0x000001";
137  break;
138  }
139 
140  printf("\n\n");
141  printf("Now creating new " PCSCLITE_READER_CONFIG "\n");
142 
143  fd = fopen(PCSCLITE_READER_CONFIG, "w");
144 
145  if (fd == NULL)
146  {
147  printf("Cannot open file %s: %s\n", PCSCLITE_READER_CONFIG, strerror(errno));
148  return 1;
149  }
150 
151  fprintf(fd, "%s", "# Configuration file for pcsc-lite\n");
152  fprintf(fd, "%s", "# David Corcoran <corcoran@musclecard.com\n");
153 
154  fprintf(fd, "%s", "\n\n");
155 
156  fprintf(fd, "FRIENDLYNAME \"%s\"\n", lpcReader);
157  fprintf(fd, "DEVICENAME /dev/null\n");
158  fprintf(fd, "LIBPATH %s\n", lpcLibrary);
159  fprintf(fd, "CHANNELID %s\n", lpcPortID);
160 
161  fprintf(fd, "%s", "\n\n");
162 
163  fprintf(fd, "%s", "# End of file\n");
164  return 0;
165 }
166 
winscard.h
This handles smart card reader communications.
wintypes.h
This keeps a list of Windows(R) types.