FreeCalypso > hg > fc-pcsc-tools
annotate simtool/pbcommon.c @ 229:ed8cb3c0d312 default tip
new README, indicating repository move
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 14 Mar 2021 18:26:13 +0000 |
parents | e89004a245ce |
children |
rev | line source |
---|---|
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the common functions for all phonebook commands. |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <string.h> |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <strings.h> |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "simresp.h" |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "curfile.h" |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "file_id.h" |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 static struct map { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 char *user_name; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 char *canon_name; |
52
2f697a8c5196
fc-simtool pb-* commands support new EF_MBDN phonebook
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
17 int dir_id; |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 int file_id; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 } phonebook_map[] = { |
52
2f697a8c5196
fc-simtool pb-* commands support new EF_MBDN phonebook
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
20 {"adn", "EF_ADN", DF_TELECOM, EF_ADN}, |
2f697a8c5196
fc-simtool pb-* commands support new EF_MBDN phonebook
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
21 {"ADN", "EF_ADN", DF_TELECOM, EF_ADN}, |
2f697a8c5196
fc-simtool pb-* commands support new EF_MBDN phonebook
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
22 {"EF_ADN", "EF_ADN", DF_TELECOM, EF_ADN}, |
2f697a8c5196
fc-simtool pb-* commands support new EF_MBDN phonebook
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
23 {"fdn", "EF_FDN", DF_TELECOM, EF_FDN}, |
2f697a8c5196
fc-simtool pb-* commands support new EF_MBDN phonebook
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
24 {"FDN", "EF_FDN", DF_TELECOM, EF_FDN}, |
2f697a8c5196
fc-simtool pb-* commands support new EF_MBDN phonebook
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
25 {"EF_FDN", "EF_FDN", DF_TELECOM, EF_FDN}, |
2f697a8c5196
fc-simtool pb-* commands support new EF_MBDN phonebook
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
26 {"sdn", "EF_SDN", DF_TELECOM, EF_SDN}, |
2f697a8c5196
fc-simtool pb-* commands support new EF_MBDN phonebook
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
27 {"SDN", "EF_SDN", DF_TELECOM, EF_SDN}, |
2f697a8c5196
fc-simtool pb-* commands support new EF_MBDN phonebook
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
28 {"EF_SDN", "EF_SDN", DF_TELECOM, EF_SDN}, |
2f697a8c5196
fc-simtool pb-* commands support new EF_MBDN phonebook
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
29 {"msisdn", "EF_MSISDN", DF_TELECOM, EF_MSISDN}, |
2f697a8c5196
fc-simtool pb-* commands support new EF_MBDN phonebook
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
30 {"MSISDN", "EF_MSISDN", DF_TELECOM, EF_MSISDN}, |
2f697a8c5196
fc-simtool pb-* commands support new EF_MBDN phonebook
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
31 {"EF_MSISDN", "EF_MSISDN", DF_TELECOM, EF_MSISDN}, |
2f697a8c5196
fc-simtool pb-* commands support new EF_MBDN phonebook
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
32 {"mbdn", "EF_MBDN", DF_GSM, EF_MBDN}, |
2f697a8c5196
fc-simtool pb-* commands support new EF_MBDN phonebook
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
33 {"MBDN", "EF_MBDN", DF_GSM, EF_MBDN}, |
2f697a8c5196
fc-simtool pb-* commands support new EF_MBDN phonebook
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
34 {"EF_MBDN", "EF_MBDN", DF_GSM, EF_MBDN}, |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 /* table search terminator */ |
52
2f697a8c5196
fc-simtool pb-* commands support new EF_MBDN phonebook
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
36 {0, 0, -1, -1} |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 }; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 phonebook_op_common(reqname) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 char *reqname; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 struct map *tp; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 int rc; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 for (tp = phonebook_map; tp->user_name; tp++) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 if (!strcmp(tp->user_name, reqname)) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 break; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 if (!tp->canon_name) { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 fprintf(stderr, "error: phone book name \"%s\" not known\n", |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 reqname); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 return(-1); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } |
52
2f697a8c5196
fc-simtool pb-* commands support new EF_MBDN phonebook
Mychaela Falconia <falcon@freecalypso.org>
parents:
1
diff
changeset
|
53 rc = select_op(tp->dir_id); |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 if (rc < 0) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 return(rc); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 rc = select_op(tp->file_id); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (rc < 0) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 return(rc); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 rc = parse_ef_select_response(); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 if (rc < 0) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 return(rc); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 if (curfile_structure != 0x01) { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 fprintf(stderr, "error: %s is not linear fixed\n", |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 tp->canon_name); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 return(-1); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 if (curfile_record_len < 14) { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 fprintf(stderr, |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 "error: %s has record length of %u bytes, less than minimum 14\n", |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 tp->canon_name, curfile_record_len); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 return(-1); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 return(0); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 } |
81
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
75 |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
76 select_ef_lnd() |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
77 { |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
78 int rc; |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
79 |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
80 rc = select_op(DF_TELECOM); |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
81 if (rc < 0) |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
82 return(rc); |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
83 rc = select_op(EF_LND); |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
84 if (rc < 0) |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
85 return(rc); |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
86 rc = parse_ef_select_response(); |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
87 if (rc < 0) |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
88 return(rc); |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
89 if (curfile_structure != 0x03) { |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
90 fprintf(stderr, "error: EF_LND is not cyclic\n"); |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
91 return(-1); |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
92 } |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
93 if (curfile_record_len < 14) { |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
94 fprintf(stderr, |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
95 "error: EF_LND has record length of %u bytes, less than minimum 14\n", |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
96 curfile_record_len); |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
97 return(-1); |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
98 } |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
99 return(0); |
e89004a245ce
EF_LND code refactoring in prep for adding more lnd-* commands
Mychaela Falconia <falcon@freecalypso.org>
parents:
52
diff
changeset
|
100 } |