annotate pircharge/init.c @ 408:14302e075f37 default tip

hr-bits: further conditionalize SID-1-diff
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 22 Jul 2024 10:06:38 +0000
parents fec90990f613
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
228
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <sys/types.h>
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <sys/socket.h>
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <sys/un.h>
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <stdio.h>
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <string.h>
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <strings.h>
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdlib.h>
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <unistd.h>
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <rvinterf/pktmux.h>
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <rvinterf/localsock.h>
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <rvinterf/exitcodes.h>
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 extern char *socket_pathname;
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 extern int sock;
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 connect_local_socket()
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 /* local socket binding voodoo copied from osmocon */
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 struct sockaddr_un local;
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 unsigned int namelen;
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 int rc;
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 sock = socket(AF_UNIX, SOCK_STREAM, 0);
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 if (sock < 0) {
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 perror("socket(AF_UNIX, SOCK_STREAM, 0)");
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 exit(ERROR_UNIX);
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 }
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 local.sun_family = AF_UNIX;
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 strncpy(local.sun_path, socket_pathname, sizeof(local.sun_path));
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 local.sun_path[sizeof(local.sun_path) - 1] = '\0';
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 /* we use the same magic that X11 uses in Xtranssock.c for
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 * calculating the proper length of the sockaddr */
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 #if defined(BSD44SOCKETS) || defined(__UNIXWARE__)
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 local.sun_len = strlen(local.sun_path);
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 #endif
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 #if defined(BSD44SOCKETS) || defined(SUN_LEN)
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 namelen = SUN_LEN(&local);
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 #else
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 namelen = strlen(local.sun_path) +
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 offsetof(struct sockaddr_un, sun_path) + 1;
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 #endif
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 rc = connect(sock, (struct sockaddr *) &local, namelen);
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (rc != 0) {
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 perror(socket_pathname);
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 exit(ERROR_RVINTERF);
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 return(0);
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 send_init_command(cmdpkt, cmdlen)
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 u_char *cmdpkt;
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 {
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 u_char lenbuf[2];
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 lenbuf[0] = 0;
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 lenbuf[1] = cmdlen;
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 write(sock, lenbuf, 2);
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 write(sock, cmdpkt, cmdlen);
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 init()
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 {
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 static u_char want_rvt_lost[9] = {CLI2RVI_WANT_RVTRACE,
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 0xFF, 0xFF, 0xFF, 0xFF,
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 0x00, 0x00, 0x00, 0x00};
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 static u_char want_rvt_drv[9] = {CLI2RVI_WANT_RVTRACE,
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 0xFF, 0xFF, 0xFF, 0xC7,
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 0x00, 0x0A, 0x00, 0x00};
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 static u_char want_rvt_lls[9] = {CLI2RVI_WANT_RVTRACE,
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 0xFF, 0xFF, 0xFF, 0xFF,
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 0x00, 0x1E, 0x00, 0x40};
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 static u_char want_etm_mux[2] = {CLI2RVI_WANT_MUXPROTO, RVT_TM_HEADER};
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 localsock_prep_for_length_rx();
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 send_init_command(want_rvt_lost, 9);
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 send_init_command(want_rvt_drv, 9);
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 send_init_command(want_rvt_lls, 9);
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 send_init_command(want_etm_mux, 2);
fec90990f613 pirchgdbg started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 }