1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
|
*** net.c 2004/03/13 18:52:43 1.1
--- net.c 2004/03/13 19:54:13
***************
*** 179,187 ****
bytes = next->write(ps, buf, PI_NET_HEADER_LEN, flags);
if (bytes < PI_NET_HEADER_LEN)
return bytes;
! bytes = next->write(ps, msg, len, flags);
! if (bytes < len)
return bytes;
CHECK(PI_DBG_NET, PI_DBG_LVL_INFO, net_dump_header(buf, 1));
CHECK(PI_DBG_NET, PI_DBG_LVL_DEBUG, dumpdata(msg, len));
--- 179,189 ----
bytes = next->write(ps, buf, PI_NET_HEADER_LEN, flags);
if (bytes < PI_NET_HEADER_LEN)
return bytes;
! if (len > 0) { /* avoid zero-length write on tickle */
! bytes = next->write(ps, msg, len, flags);
! if (bytes < len)
return bytes;
+ }
CHECK(PI_DBG_NET, PI_DBG_LVL_INFO, net_dump_header(buf, 1));
CHECK(PI_DBG_NET, PI_DBG_LVL_DEBUG, dumpdata(msg, len));
***************
*** 196,202 ****
total_bytes,
packet_len,
timeout,
! size;
struct pi_protocol *prot, *next;
struct pi_net_data *data;
--- 198,205 ----
total_bytes,
packet_len,
timeout,
! size,
! done;
struct pi_protocol *prot, *next;
struct pi_net_data *data;
***************
*** 216,255 ****
pi_setsockopt(ps->sd, PI_LEVEL_DEV, PI_DEV_TIMEOUT,
&timeout, &size);
! total_bytes = 0;
! if (data->txid == 0) {
/* Peek to see if it is a headerless packet */
bytes = next->read(ps, msg, 1, flags);
if (bytes > 0) {
! LOG ((PI_DBG_NET, PI_DBG_LVL_INFO,
! "NET RX: Checking for headerless packet %d\n", msg[0]));
! if (msg[0] == 0x90) {
! /* Cause the header bytes to be skipped */
! LOG ((PI_DBG_NET, PI_DBG_LVL_INFO,
! "NET RX: Headerless packet\n"));
! total_bytes = PI_NET_HEADER_LEN;
! msg[PI_NET_OFFSET_TYPE] = PI_NET_TYPE_DATA;
! msg[PI_NET_OFFSET_TXID] = 0x01;
! set_long (&msg[PI_NET_OFFSET_SIZE], 21);
! } else {
! total_bytes += bytes;
! }
} else {
! return bytes;
}
! }
! /* Bytes in what's left of the header */
! while (total_bytes < PI_NET_HEADER_LEN) {
bytes = next->read(ps, msg + total_bytes, PI_NET_HEADER_LEN - total_bytes, flags);
if (bytes <= 0)
! return bytes;
total_bytes += bytes;
}
/* Bytes in the rest of the packet */
- packet_len = get_long(&msg[PI_NET_OFFSET_SIZE]);
while (total_bytes < PI_NET_HEADER_LEN + packet_len) {
bytes = next->read(ps, msg + total_bytes,
PI_NET_HEADER_LEN + packet_len - total_bytes, flags);
--- 219,278 ----
pi_setsockopt(ps->sd, PI_LEVEL_DEV, PI_DEV_TIMEOUT,
&timeout, &size);
! done = 0;
! while (!done) {
! total_bytes = 0;
! if (data->txid == 0) {
/* Peek to see if it is a headerless packet */
bytes = next->read(ps, msg, 1, flags);
if (bytes > 0) {
! LOG ((PI_DBG_NET, PI_DBG_LVL_INFO,
! "NET RX: Checking for headerless packet %d\n", msg[0]));
! if (msg[0] == 0x90) {
! /* Cause the header bytes to be skipped */
! LOG ((PI_DBG_NET, PI_DBG_LVL_INFO,
! "NET RX: Headerless packet\n"));
! total_bytes = PI_NET_HEADER_LEN;
! msg[PI_NET_OFFSET_TYPE] = PI_NET_TYPE_DATA;
! msg[PI_NET_OFFSET_TXID] = 0x01;
! set_long (&msg[PI_NET_OFFSET_SIZE], 21);
! } else {
! total_bytes += bytes;
! }
} else {
! return bytes;
}
! }
! /* Bytes in what's left of the header */
! while (total_bytes < PI_NET_HEADER_LEN) {
bytes = next->read(ps, msg + total_bytes, PI_NET_HEADER_LEN - total_bytes, flags);
if (bytes <= 0)
! return bytes;
total_bytes += bytes;
+ }
+ packet_len = get_long(&msg[PI_NET_OFFSET_SIZE]);
+ data->type = msg[PI_NET_OFFSET_TYPE];
+ switch (data->type) {
+ case PI_NET_TYPE_TCKL:
+ if (packet_len != 0) {
+ LOG ((PI_DBG_NET, PI_DBG_LVL_ERR,
+ "NET RX: tickle packet with non-zero length\n"));
+ return -1;
+ }
+ /* valid tickle packet; continue reading. */
+ break;
+ case PI_NET_TYPE_DATA:
+ done = 1;
+ break;
+ default:
+ LOG ((PI_DBG_NET, PI_DBG_LVL_ERR,
+ "NET RX: Unknown packet type\n"));
+ }
}
/* Bytes in the rest of the packet */
while (total_bytes < PI_NET_HEADER_LEN + packet_len) {
bytes = next->read(ps, msg + total_bytes,
PI_NET_HEADER_LEN + packet_len - total_bytes, flags);
|