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