annotate test/ota-smspp-envelope.c @ 4:c2de42994e57

ota-smspp-envelope utility written, compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 21 Feb 2021 23:41:46 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This test utility reads the output of ota-smswrap-* (should be run in a
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * pipeline) and prepends additional headers to transform this OTA message
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * into a byte string that can be fed to the SIM in an ENVELOPE command.
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * The intent is to test OTA RFM functionality of SIM cards using only
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * fc-simtool, without going through a GSM network.
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 */
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <sys/types.h>
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdio.h>
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <string.h>
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <strings.h>
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #define MAX_MSG_LEN 140
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #define ENVELOPE_BUF 255
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #define INIT_OFFSET (ENVELOPE_BUF - MAX_MSG_LEN)
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 u_char full_buffer[ENVELOPE_BUF], *curhead;
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 unsigned msglen;
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 u_char header1[14] = {0x40, 0x04, 0x81, 0x44, 0x44, 0x7F, 0xF6,
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 0x12, 0x10, 0x71, 0x90, 0x04, 0x05, 0x2B};
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 u_char header2[5] = {0x82, 0x02, 0x83, 0x81, 0x8B};
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 read_input()
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 {
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 int rc;
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 curhead = full_buffer + INIT_OFFSET;
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 rc = read_hex_from_stdin(curhead, MAX_MSG_LEN);
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (rc < 0)
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 exit(1); /* error msg already printed */
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 msglen = rc;
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 prepend_byte(newb)
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 {
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 curhead--;
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 *curhead = newb;
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 msglen++;
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 }
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 prepend_simple_len()
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 {
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 prepend_byte(msglen);
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 prepend_ber_len()
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 {
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (msglen < 0x80)
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 prepend_byte(msglen);
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 else {
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 prepend_byte(msglen);
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 prepend_byte(0x81);
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 }
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 prepend_header(hdr, hdrlen)
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 u_char *hdr;
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 {
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 curhead -= hdrlen;
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 bcopy(hdr, curhead, hdrlen);
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 msglen += hdrlen;
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 emit_output()
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 {
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 u_char *dp;
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 unsigned n;
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 dp = curhead;
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 for (n = 0; n < msglen; n++)
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 printf("%02X", *dp++);
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 putchar('\n');
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 main(argc, argv)
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 char **argv;
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 {
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 read_input();
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 prepend_simple_len();
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 prepend_header(header1, 14);
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 prepend_ber_len();
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 prepend_header(header2, 5);
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 prepend_ber_len();
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 prepend_byte(0xD1);
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 emit_output();
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 exit(0);
c2de42994e57 ota-smspp-envelope utility written, compiles
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 }