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