FreeCalypso > hg > sms-coding-utils
annotate enc-text/gsm7.c @ 9:003660a57f99
new program sms-gen-tpdu
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 05 Aug 2023 07:43:45 +0000 |
parents | 265b8103530c |
children | e56bb9f09ff1 |
rev | line source |
---|---|
2
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * In this module we implement SMS encoding in GSM7. |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdlib.h> |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <string.h> |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <strings.h> |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <unistd.h> |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "defs.h" |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 extern int utf8_input; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 extern int concat_enable, concat_refno_set; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 extern char msgtext[MAX_MSG_CHARS*2+2]; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 extern u_char concat_refno; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 gsm7_mode_main() |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 { |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 u_char msgtext_gsm7[MAX_MSG_CHARS]; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 unsigned msgtext_gsmlen; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 int rc; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 unsigned nparts, n; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 u_char udh[6]; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 unsigned pos, remain, chunk; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (utf8_input && utf8_to_latin1(msgtext) < 0) { |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 fprintf(stderr, "error: invalid UTF-8 message\n"); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 exit(1); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 rc = latin1_to_gsm7(msgtext, msgtext_gsm7, MAX_MSG_CHARS, |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 &msgtext_gsmlen); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 if (rc == -1) { |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 fprintf(stderr, "error: message not valid for GSM7 charset\n"); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 exit(1); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 } |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 if (rc == -2) { |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 fprintf(stderr, "error: message too long for max concat SMS\n"); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 exit(1); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 } |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 if (msgtext_gsmlen <= 160) { |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 fputs("dcs 0 septet\nmsg ", stdout); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 if (msgtext_gsmlen) |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 emit_hex_out(msgtext_gsm7, msgtext_gsmlen, stdout); |
8
265b8103530c
sms-encode-text: emit empty messages as ""
Mychaela Falconia <falcon@freecalypso.org>
parents:
2
diff
changeset
|
45 else { |
265b8103530c
sms-encode-text: emit empty messages as ""
Mychaela Falconia <falcon@freecalypso.org>
parents:
2
diff
changeset
|
46 putchar('"'); |
265b8103530c
sms-encode-text: emit empty messages as ""
Mychaela Falconia <falcon@freecalypso.org>
parents:
2
diff
changeset
|
47 putchar('"'); |
265b8103530c
sms-encode-text: emit empty messages as ""
Mychaela Falconia <falcon@freecalypso.org>
parents:
2
diff
changeset
|
48 } |
2
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 putchar('\n'); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 exit(0); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 } |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (!concat_enable) { |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 fprintf(stderr, "error: message exceeds 160 chars\n"); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 exit(1); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 if (!concat_refno_set) |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 concat_refno = get_concsms_refno_from_host_fs(); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 puts("dcs 0 septet"); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 nparts = (msgtext_gsmlen + 152) / 153; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 udh[0] = 5; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 udh[1] = 0x00; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 udh[2] = 0x03; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 udh[3] = concat_refno; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 udh[4] = nparts; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 pos = 0; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 remain = msgtext_gsmlen; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 for (n = 1; n <= nparts; n++) { |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 udh[5] = n; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 chunk = 153; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 if (chunk > remain) |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 chunk = remain; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 fputs("msg-udh ", stdout); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 emit_hex_out(udh, 6, stdout); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 emit_hex_out(msgtext_gsm7 + pos, chunk, stdout); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 putchar('\n'); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 pos += chunk; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 remain -= chunk; |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 } |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 exit(0); |
a16b1b9728f6
enc-text: sms-encode-text program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 } |