annotate simtool/pbcommon.c @ 64:8cd4771bdd79

doc/User-oriented-commands: document started
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Feb 2021 19:01:04 +0000
parents 2f697a8c5196
children e89004a245ce
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 }