annotate uptools/atcmd/smsend_concat.c @ 995:74024eb17e04

fc-loadtool help: improve language regarding 16 MiB flash chips In FC project history, 16 MiB flash originally meant Pirelli DP-L10. Then we got FCDEV3B with the same flash (our own design), but now we are discovering more Calypso devices that used such large flash, both late Calypso era (Sony Ericsson K2x0) as well as much earlier ones (FIC FLUID devices.txt file with 2004 dates, Leonardo+ rev 5). Hence we need to migrate to more generic or neutral language in associated documentation, without giving elevated status to specific examples that drove our early project history.
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 03 Dec 2023 21:11:12 +0000
parents 076d533f840d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
370
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module contains the messy code for automatic generation and
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * increment of concat SMS reference numbers.
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/param.h>
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <sys/file.h>
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <sys/time.h>
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <ctype.h>
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdio.h>
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <stdlib.h>
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <unistd.h>
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "../../rvinterf/include/exitcodes.h"
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 static int
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 initial_seed()
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 struct timeval tv;
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 u_char refno, *cp, *endp;
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 gettimeofday(&tv, 0);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 cp = (u_char *) &tv;
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 endp = cp + sizeof(struct timeval);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 refno = 0;
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 while (cp < endp)
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 refno ^= *cp++;
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 return refno;
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 }
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 get_concsms_refno_from_host_fs()
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 {
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 char *homedir, statefile[MAXPATHLEN];
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 int fd, cc;
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 char buf[6];
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 u_char refno;
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 homedir = getenv("HOME");
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 if (!homedir) {
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 fprintf(stderr,
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 "error: no HOME= defined, needed for concat SMS refno\n");
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 exit(ERROR_UNIX);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 }
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 sprintf(statefile, "%s/.concat_sms_refno", homedir);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 fd = open(statefile, O_RDWR|O_CREAT, 0666);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (fd < 0) {
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 perror(statefile);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 exit(ERROR_UNIX);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 cc = read(fd, buf, 5);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 if (cc == 5 && buf[0] == '0' && buf[1] == 'x' && isxdigit(buf[2]) &&
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 isxdigit(buf[3]) && buf[4] == '\n')
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 refno = strtoul(buf, 0, 16) + 1;
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 else
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 refno = initial_seed();
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 sprintf(buf, "0x%02X\n", refno);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 lseek(fd, 0, SEEK_SET);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 write(fd, buf, 5);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 close(fd);
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return refno;
076d533f840d fcup-smsend: implemented automatic concat SMS refno generation
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 }