FreeCalypso > hg > fc-sim-tools
annotate libcommon/atr.c @ 86:de23872796cb
fc-uicc-tool: update-rec-imm and update-rec-fill ported over from fc-simtool
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 11 Apr 2021 03:19:22 +0000 |
parents | c9ef9e91dd8e |
children |
rev | line source |
---|---|
9
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <stdio.h> |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <stdlib.h> |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <string.h> |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <strings.h> |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 extern FILE *cpipeF, *rpipeF; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 extern char be_atr_string[]; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 cmd_atr() |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 { |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 char inbuf[128], *cp; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 /* do we have it already? */ |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 if (be_atr_string[0]) { |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 printf("ATR: %s\n", be_atr_string); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 return(0); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 } |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 /* nope - request it from the BE */ |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 fputs("atr\n", cpipeF); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 fflush(cpipeF); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 /* collect BE response */ |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 if (!fgets(inbuf, sizeof inbuf, rpipeF)) { |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 fprintf(stderr, "comm error: EOF reading from back end\n"); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 return(-1); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 } |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 cp = index(inbuf, '\n'); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (!cp) { |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 fprintf(stderr, |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 "comm error: response from back end has no newline\n"); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 return(-1); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 } |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 *cp = '\0'; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 if (!inbuf[0]) { |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 fprintf(stderr, |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 "comm error: response from back end is an empty line\n"); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 return(-1); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 puts(inbuf); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 return(0); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 } |