FreeCalypso > hg > fc-sim-tools
comparison simtool/pbcommon.c @ 10:ddd767f6e15b
fc-simtool ported over
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 14 Mar 2021 07:11:25 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
9:c9ef9e91dd8e | 10:ddd767f6e15b |
---|---|
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 dir_id; | |
18 int file_id; | |
19 } phonebook_map[] = { | |
20 {"adn", "EF_ADN", DF_TELECOM, EF_ADN}, | |
21 {"ADN", "EF_ADN", DF_TELECOM, EF_ADN}, | |
22 {"EF_ADN", "EF_ADN", DF_TELECOM, EF_ADN}, | |
23 {"fdn", "EF_FDN", DF_TELECOM, EF_FDN}, | |
24 {"FDN", "EF_FDN", DF_TELECOM, EF_FDN}, | |
25 {"EF_FDN", "EF_FDN", DF_TELECOM, EF_FDN}, | |
26 {"sdn", "EF_SDN", DF_TELECOM, EF_SDN}, | |
27 {"SDN", "EF_SDN", DF_TELECOM, EF_SDN}, | |
28 {"EF_SDN", "EF_SDN", DF_TELECOM, EF_SDN}, | |
29 {"msisdn", "EF_MSISDN", DF_TELECOM, EF_MSISDN}, | |
30 {"MSISDN", "EF_MSISDN", DF_TELECOM, EF_MSISDN}, | |
31 {"EF_MSISDN", "EF_MSISDN", DF_TELECOM, EF_MSISDN}, | |
32 {"mbdn", "EF_MBDN", DF_GSM, EF_MBDN}, | |
33 {"MBDN", "EF_MBDN", DF_GSM, EF_MBDN}, | |
34 {"EF_MBDN", "EF_MBDN", DF_GSM, EF_MBDN}, | |
35 /* table search terminator */ | |
36 {0, 0, -1, -1} | |
37 }; | |
38 | |
39 phonebook_op_common(reqname) | |
40 char *reqname; | |
41 { | |
42 struct map *tp; | |
43 int rc; | |
44 | |
45 for (tp = phonebook_map; tp->user_name; tp++) | |
46 if (!strcmp(tp->user_name, reqname)) | |
47 break; | |
48 if (!tp->canon_name) { | |
49 fprintf(stderr, "error: phone book name \"%s\" not known\n", | |
50 reqname); | |
51 return(-1); | |
52 } | |
53 rc = select_op(tp->dir_id); | |
54 if (rc < 0) | |
55 return(rc); | |
56 rc = select_op(tp->file_id); | |
57 if (rc < 0) | |
58 return(rc); | |
59 rc = parse_ef_select_response(); | |
60 if (rc < 0) | |
61 return(rc); | |
62 if (curfile_structure != 0x01) { | |
63 fprintf(stderr, "error: %s is not linear fixed\n", | |
64 tp->canon_name); | |
65 return(-1); | |
66 } | |
67 if (curfile_record_len < 14) { | |
68 fprintf(stderr, | |
69 "error: %s has record length of %u bytes, less than minimum 14\n", | |
70 tp->canon_name, curfile_record_len); | |
71 return(-1); | |
72 } | |
73 return(0); | |
74 } | |
75 | |
76 select_ef_lnd() | |
77 { | |
78 int rc; | |
79 | |
80 rc = select_op(DF_TELECOM); | |
81 if (rc < 0) | |
82 return(rc); | |
83 rc = select_op(EF_LND); | |
84 if (rc < 0) | |
85 return(rc); | |
86 rc = parse_ef_select_response(); | |
87 if (rc < 0) | |
88 return(rc); | |
89 if (curfile_structure != 0x03) { | |
90 fprintf(stderr, "error: EF_LND is not cyclic\n"); | |
91 return(-1); | |
92 } | |
93 if (curfile_record_len < 14) { | |
94 fprintf(stderr, | |
95 "error: EF_LND has record length of %u bytes, less than minimum 14\n", | |
96 curfile_record_len); | |
97 return(-1); | |
98 } | |
99 return(0); | |
100 } |