comparison simtool/pbcommon.c @ 104:a60645b75a57

fc-simtool: phonebook dump implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 25 Jan 2021 05:55:40 +0000
parents
children b1bf0ec6fff5
comparison
equal deleted inserted replaced
103:90eff13a72fd 104:a60645b75a57
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 <pcsclite.h>
11 #include <winscard.h>
12 #include "globals.h"
13 #include "file_id.h"
14
15 static struct map {
16 char *user_name;
17 char *canon_name;
18 int file_id;
19 } phonebook_map[] = {
20 {"adn", "EF_ADN", EF_ADN},
21 {"ADN", "EF_ADN", EF_ADN},
22 {"EF_ADN", "EF_ADN", EF_ADN},
23 {"fdn", "EF_FDN", EF_FDN},
24 {"FDN", "EF_FDN", EF_FDN},
25 {"EF_FDN", "EF_FDN", EF_FDN},
26 {"sdn", "EF_SDN", EF_SDN},
27 {"SDN", "EF_SDN", EF_SDN},
28 {"EF_SDN", "EF_SDN", EF_SDN},
29 {"msisdn", "EF_MSISDN", EF_MSISDN},
30 {"MSISDN", "EF_MSISDN", EF_MSISDN},
31 {"EF_MSISDN", "EF_MSISDN", EF_MSISDN},
32 /* table search terminator */
33 {0, 0, -1}
34 };
35
36 phonebook_op_common(reqname)
37 char *reqname;
38 {
39 struct map *tp;
40 int rc;
41
42 for (tp = phonebook_map; *tp->user_name; tp++)
43 if (!strcmp(tp->user_name, reqname))
44 break;
45 if (!tp->canon_name) {
46 fprintf(stderr, "error: phone book name \"%s\" not known",
47 reqname);
48 return(-1);
49 }
50 rc = select_op(DF_TELECOM);
51 if (rc < 0)
52 return(rc);
53 rc = select_op(tp->file_id);
54 if (rc < 0)
55 return(rc);
56 rc = parse_ef_select_response();
57 if (rc < 0)
58 return(rc);
59 if (curfile_structure != 0x01) {
60 fprintf(stderr, "error: %s is not linear fixed\n",
61 tp->canon_name);
62 return(-1);
63 }
64 if (curfile_record_len < 14) {
65 fprintf(stderr,
66 "error: %s has record length of %u bytes, less than minimum 14\n",
67 tp->canon_name, curfile_record_len);
68 return(-1);
69 }
70 return(0);
71 }