annotate rvinterf/etmsync/interf.c @ 369:e2a05eb3129f

OSL: the bogus event group code appears to be unused aside from the os_EvGrpInit() call in os_Initialize(), so let's table it aside for now, and thus spare the boatload of compiler warnings.
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Thu, 29 May 2014 06:41:52 +0000
parents f77480d3dd21
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
277
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * In this module we implement our synchronous interface to the target
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 * via rvinterf.
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4 */
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <sys/types.h>
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdio.h>
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdlib.h>
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <unistd.h>
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include "limits.h"
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "localsock.h"
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "pktmux.h"
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include "exitcodes.h"
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15 extern int sock;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17 int rx_enable_state;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 u_char rvi_msg[LOCALSOCK_MAX_MSG];
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 int rvi_msg_len;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 static void
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 collect_bytes_from_rvi(buf, nbytes)
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 u_char *buf;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24 {
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 int cc;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 while (nbytes) {
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 cc = read(sock, buf, nbytes);
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 if (cc <= 0) {
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 perror("read from rvinterf socket");
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 exit(ERROR_RVINTERF);
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 }
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 buf += cc;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 nbytes -= cc;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 }
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 }
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 collect_rvi_msg()
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 {
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 u_char lenbuf[2];
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 collect_bytes_from_rvi(lenbuf, 2);
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 rvi_msg_len = lenbuf[0] << 8 | lenbuf[1];
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 if (rvi_msg_len < 1 || rvi_msg_len > LOCALSOCK_MAX_MSG) {
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45 fprintf(stderr, "Invalid length from rvinterf: %02X%02X\n",
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 lenbuf[0], lenbuf[1]);
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 exit(ERROR_RVINTERF);
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 }
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 collect_bytes_from_rvi(rvi_msg, rvi_msg_len);
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 return(0);
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 }
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 send_rvimisc_command(cmdpkt, cmdlen)
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 u_char *cmdpkt;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 {
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 u_char lenbuf[2];
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 lenbuf[0] = 0;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59 lenbuf[1] = cmdlen;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 write(sock, lenbuf, 2);
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 write(sock, cmdpkt, cmdlen);
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 }
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 rx_control(enable)
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 {
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 u_char cmdpkt[2];
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 int cmdlen;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 /* are we already in the desired state? */
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 if (rx_enable_state == enable)
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 return(0);
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 /* no, do the work */
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 if (enable) {
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 cmdpkt[0] = CLI2RVI_WANT_MUXPROTO;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 cmdpkt[1] = RVT_TM_HEADER;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 cmdlen = 2;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 } else {
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 cmdpkt[0] = CLI2RVI_RESET_PACKET_RX;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 cmdlen = 1;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 }
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 send_rvimisc_command(cmdpkt, cmdlen);
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 collect_rvi_msg();
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 if (rvi_msg[0] != RVI2CLI_LOCAL_CMD_RESP || rvi_msg_len < 2) {
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 fprintf(stderr,
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 "error: unexpected response to rvinterf local command\n");
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 exit(ERROR_RVINTERF);
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 }
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 if (rvi_msg[1] != '+') {
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 fprintf(stderr, "Error from rvinterf: %.*s\n", rvi_msg_len - 1,
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 rvi_msg + 1);
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 exit(ERROR_RVINTERF);
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 }
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 rx_enable_state = enable;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 return(0);
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 }
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 send_pkt_to_target(pkt, pktlen)
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 u_char *pkt;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 {
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 u_char hdrbuf[3];
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 int len1;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 len1 = pktlen + 1;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 hdrbuf[0] = len1 >> 8;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
105 hdrbuf[1] = len1 & 0xFF;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
106 hdrbuf[2] = CLI2RVI_PKT_TO_TARGET;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
107 write(sock, hdrbuf, 3);
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
108 write(sock, pkt, pktlen);
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
109 }
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
110
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
111 target_pkt_exch(outpkt, outpktlen)
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
112 u_char *outpkt;
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
113 {
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
114 rx_control(1);
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
115 send_pkt_to_target(outpkt, outpktlen);
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
116 collect_rvi_msg();
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
117 if (rvi_msg[0] != RVI2CLI_PKT_FROM_TARGET) {
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
118 fprintf(stderr,
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
119 "error: unexpected response type from rvinterf\n");
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
120 exit(ERROR_RVINTERF);
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
121 }
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
122 return(0);
e23fc1228efd fc-fsio: low-level rvinterf link implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
123 }
278
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
124
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
125 etm_pkt_exch(outbuf, outlen)
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
126 u_char *outbuf;
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
127 {
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
128 int i, c;
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
129
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
130 outbuf[0] = RVT_TM_HEADER;
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
131 c = 0;
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
132 for (i = 1; i <= outlen; i++)
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
133 c ^= outbuf[i];
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
134 outbuf[i] = c;
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
135 target_pkt_exch(outbuf, outlen + 2);
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
136 if (rvi_msg[1] != RVT_TM_HEADER) {
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
137 printf("error: packet from target is not ETM!\n");
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
138 return(ERROR_TARGET);
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
139 }
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
140 if (rvi_msg_len < 5) {
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
141 printf("error: ETM response packet is too short\n");
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
142 return(ERROR_TARGET);
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
143 }
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
144 c = 0;
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
145 for (i = 2; i < rvi_msg_len; i++)
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
146 c ^= rvi_msg[i];
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
147 if (c) {
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
148 printf("ETM response checksum error!\n");
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
149 return(ERROR_TARGET);
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
150 }
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
151 if (rvi_msg[2] != outbuf[1]) {
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
152 printf("error: target response is from wrong ETM component\n");
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
153 return(ERROR_TARGET);
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
154 }
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
155 return(0);
f77480d3dd21 fc-fsio: first ffs2ver command implemented
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 277
diff changeset
156 }