annotate rvinterf/misc/sendsp.c @ 649:042735181793

gsm-fw/ccd/README: description of how we are going to tackle this component
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Thu, 04 Sep 2014 06:41:01 +0000
parents 5d9001f0c3aa
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
328
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * This hack-utility sends a GPF System Primitive given on the command line
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * to a target GSM device via rvinterf.
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 */
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <sys/types.h>
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdio.h>
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <string.h>
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <strings.h>
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <stdlib.h>
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "pktmux.h"
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "limits.h"
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 char *socket_pathname = "/tmp/rvinterf_socket";
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 main(argc, argv)
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 char **argv;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 {
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 char *stackdest, *primarg;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 unsigned intlen;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 u_char sendpkt[MAX_PKT_TO_TARGET];
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 unsigned pktlen;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 if (argc < 3) {
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 usage: fprintf(stderr, "usage: %s [-s socket] stackdest primarg\n",
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 argv[0]);
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 exit(1);
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 }
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 if (strcmp(argv[1], "-s")) {
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 if (argc != 3)
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 goto usage;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 stackdest = argv[1];
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 primarg = argv[2];
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 } else {
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 if (argc != 5)
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 goto usage;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37 socket_pathname = argv[2];
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 stackdest = argv[3];
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 primarg = argv[4];
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 }
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 if (strlen(stackdest) > 4) {
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 fprintf(stderr,
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 "error: stack destination arg may not exceed 4 characters\n");
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 exit(1);
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 }
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 intlen = 12 + strlen(primarg) + 1;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 pktlen = intlen + 4;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 if (pktlen > MAX_PKT_TO_TARGET) {
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 fprintf(stderr, "error: max pkt to target limit exceeded\n");
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 exit(1);
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 }
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 /* fill out the packet */
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 sendpkt[0] = RVT_L23_HEADER;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 sendpkt[1] = 0xB7; /* system prim */
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 sendpkt[2] = intlen;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 sendpkt[3] = intlen >> 8;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 /* send zeros for the timestamp */
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 sendpkt[4] = 0;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 sendpkt[5] = 0;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 sendpkt[6] = 0;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 sendpkt[7] = 0;
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 /* as far as TI's sw is concerned, we are PCO */
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 sendpkt[8] = 'P';
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 sendpkt[9] = 'C';
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 sendpkt[10] = 'O';
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 sendpkt[11] = ' ';
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 sprintf(sendpkt + 12, "%-4s%s", stackdest, primarg);
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68 /* send it! */
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 send_pkt_to_target(sendpkt, pktlen);
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 exit(0);
5d9001f0c3aa fc-sendsp: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 }