FreeCalypso > hg > freecalypso-hwlab
annotate simtool/pbcommon.c @ 161:d3128f3e1bde
fc-simtool and fc-uicc-tool moved to new fc-pcsc-tools repository
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 12 Feb 2021 05:39:38 +0000 |
parents | b1bf0ec6fff5 |
children |
rev | line source |
---|---|
104
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the common functions for all phonebook commands. |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <string.h> |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <strings.h> |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <pcsclite.h> |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <winscard.h> |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "globals.h" |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "file_id.h" |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 static struct map { |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 char *user_name; |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 char *canon_name; |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 int file_id; |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 } phonebook_map[] = { |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 {"adn", "EF_ADN", EF_ADN}, |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 {"ADN", "EF_ADN", EF_ADN}, |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 {"EF_ADN", "EF_ADN", EF_ADN}, |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 {"fdn", "EF_FDN", EF_FDN}, |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 {"FDN", "EF_FDN", EF_FDN}, |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 {"EF_FDN", "EF_FDN", EF_FDN}, |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 {"sdn", "EF_SDN", EF_SDN}, |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 {"SDN", "EF_SDN", EF_SDN}, |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 {"EF_SDN", "EF_SDN", EF_SDN}, |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 {"msisdn", "EF_MSISDN", EF_MSISDN}, |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 {"MSISDN", "EF_MSISDN", EF_MSISDN}, |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 {"EF_MSISDN", "EF_MSISDN", EF_MSISDN}, |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 /* table search terminator */ |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 {0, 0, -1} |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 }; |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 phonebook_op_common(reqname) |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 char *reqname; |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 { |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 struct map *tp; |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 int rc; |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 |
105
b1bf0ec6fff5
fc-simtool: pb-dump: first round of bugfixes
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
42 for (tp = phonebook_map; tp->user_name; tp++) |
104
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 if (!strcmp(tp->user_name, reqname)) |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 break; |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (!tp->canon_name) { |
105
b1bf0ec6fff5
fc-simtool: pb-dump: first round of bugfixes
Mychaela Falconia <falcon@freecalypso.org>
parents:
104
diff
changeset
|
46 fprintf(stderr, "error: phone book name \"%s\" not known\n", |
104
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 reqname); |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 return(-1); |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 } |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 rc = select_op(DF_TELECOM); |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 if (rc < 0) |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 return(rc); |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 rc = select_op(tp->file_id); |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 if (rc < 0) |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 return(rc); |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 rc = parse_ef_select_response(); |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (rc < 0) |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 return(rc); |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 if (curfile_structure != 0x01) { |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 fprintf(stderr, "error: %s is not linear fixed\n", |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 tp->canon_name); |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 return(-1); |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 } |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 if (curfile_record_len < 14) { |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 fprintf(stderr, |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 "error: %s has record length of %u bytes, less than minimum 14\n", |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 tp->canon_name, curfile_record_len); |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 return(-1); |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 } |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 return(0); |
a60645b75a57
fc-simtool: phonebook dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 } |