FreeCalypso > hg > fc-sim-tools
comparison libcommon/backend.c @ 45:9eb5460f51a6
main tools: support both pcsc and serial back ends
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sun, 21 Mar 2021 01:56:49 +0000 |
| parents | c9ef9e91dd8e |
| children |
comparison
equal
deleted
inserted
replaced
| 44:0bc89d61fc59 | 45:9eb5460f51a6 |
|---|---|
| 5 | 5 |
| 6 #include <stdio.h> | 6 #include <stdio.h> |
| 7 #include <stdlib.h> | 7 #include <stdlib.h> |
| 8 #include <unistd.h> | 8 #include <unistd.h> |
| 9 | 9 |
| 10 extern unsigned calypso_fd, pcsc_reader_num; | 10 extern unsigned calypso_fd, pcsc_reader_num, serial_spenh; |
| 11 extern int use_pcsc; | |
| 12 extern char *serial_device, *serial_baud; | |
| 11 | 13 |
| 12 static char calypso_be_pathname[] = "/opt/freecalypso/bin/fcsim-calypso-be"; | 14 static char calypso_be_pathname[] = "/opt/freecalypso/bin/fcsim-calypso-be"; |
| 15 static char serial_be_pathname[] = "/opt/freecalypso/bin/fcsim-serial-be"; | |
| 13 static char pcsc_be_pathname[] = "/opt/freecalypso/bin/fc-pcsc-backend"; | 16 static char pcsc_be_pathname[] = "/opt/freecalypso/bin/fc-pcsc-backend"; |
| 14 | 17 |
| 15 static char *backend_prog, *backend_argv[3], backend_optarg[16]; | 18 static char *backend_prog, *backend_argv[4], backend_optarg[16]; |
| 16 | 19 |
| 17 FILE *cpipeF, *rpipeF; | 20 FILE *cpipeF, *rpipeF; |
| 18 | 21 |
| 19 static void | 22 static void |
| 20 setup_be_calypso() | 23 setup_be_calypso() |
| 34 sprintf(backend_optarg, "-p%u", pcsc_reader_num); | 37 sprintf(backend_optarg, "-p%u", pcsc_reader_num); |
| 35 backend_argv[1] = backend_optarg; | 38 backend_argv[1] = backend_optarg; |
| 36 backend_argv[2] = 0; | 39 backend_argv[2] = 0; |
| 37 } | 40 } |
| 38 | 41 |
| 42 static void | |
| 43 setup_be_serial() | |
| 44 { | |
| 45 backend_prog = serial_be_pathname; | |
| 46 backend_argv[0] = "fcsim-serial-be"; | |
| 47 backend_argv[1] = serial_device; | |
| 48 if (serial_baud) | |
| 49 backend_argv[2] = serial_baud; | |
| 50 else if (serial_spenh) { | |
| 51 sprintf(backend_optarg, "9600,55800,%u", serial_spenh); | |
| 52 backend_argv[2] = backend_optarg; | |
| 53 } else | |
| 54 backend_argv[2] = "9600"; | |
| 55 backend_argv[3] = 0; | |
| 56 } | |
| 57 | |
| 39 launch_backend() | 58 launch_backend() |
| 40 { | 59 { |
| 41 int cpipe[2], rpipe[2], rc; | 60 int cpipe[2], rpipe[2], rc; |
| 42 | 61 |
| 43 if (calypso_fd) | 62 if (calypso_fd) |
| 44 setup_be_calypso(); | 63 setup_be_calypso(); |
| 45 else | 64 else if (use_pcsc) |
| 46 setup_be_pcsc(); | 65 setup_be_pcsc(); |
| 66 else if (serial_device) | |
| 67 setup_be_serial(); | |
| 68 else { | |
| 69 fprintf(stderr, "error: no -d or -p target selected\n"); | |
| 70 exit(1); | |
| 71 } | |
| 47 if (pipe(cpipe) < 0 || pipe(rpipe) < 0) { | 72 if (pipe(cpipe) < 0 || pipe(rpipe) < 0) { |
| 48 perror("pipe"); | 73 perror("pipe"); |
| 49 exit(1); | 74 exit(1); |
| 50 } | 75 } |
| 51 rc = vfork(); | 76 rc = vfork(); |
