equal
deleted
inserted
replaced
14 #include "eth_linux.h" |
14 #include "eth_linux.h" |
15 |
15 |
16 enum { |
16 enum { |
17 MAXPACKET = 1500, |
17 MAXPACKET = 1500, |
18 MAXSEQ = 100, |
18 MAXSEQ = 100, |
19 HEAD = 9 |
19 HEAD = 13 |
20 }; |
20 }; |
21 |
21 |
22 static struct |
22 static struct |
23 { |
23 { |
24 int socket; |
24 int socket; |
29 unsigned int seq_send; |
29 unsigned int seq_send; |
30 unsigned int seq_wait; |
30 unsigned int seq_wait; |
31 unsigned int wrong_recv; |
31 unsigned int wrong_recv; |
32 char send_buffer[MAXPACKET]; |
32 char send_buffer[MAXPACKET]; |
33 int send_buffer_size; |
33 int send_buffer_size; |
|
34 int port; |
34 } edata; |
35 } edata; |
35 |
36 |
36 enum Control { |
37 enum Control { |
37 SEND, |
38 SEND, |
38 ACK, |
39 ACK, |
46 static int make_head(unsigned char *data, unsigned int seq, enum Control c, |
47 static int make_head(unsigned char *data, unsigned int seq, enum Control c, |
47 int size) |
48 int size) |
48 { |
49 { |
49 *((unsigned int *) data) = htonl(seq); |
50 *((unsigned int *) data) = htonl(seq); |
50 data[4] = (unsigned char) c; |
51 data[4] = (unsigned char) c; |
51 *((unsigned int *)(data+5)) = htonl(size); |
52 *((unsigned int *)(data+5)) = htonl(edata.port); |
|
53 *((unsigned int *)(data+5+4)) = htonl(size); |
52 return HEAD; |
54 return HEAD; |
53 } |
55 } |
54 |
56 |
55 static int parse_head(unsigned char *data, unsigned int *seq, enum Control *c, |
57 static int parse_head(unsigned char *data, unsigned int *seq, enum Control *c, |
56 int *size) |
58 int *port, int *size) |
57 { |
59 { |
58 *seq = ntohl( *((unsigned int*) data) ); |
60 *seq = ntohl( *((unsigned int*) data) ); |
59 *c = data[4]; |
61 *c = data[4]; |
|
62 if (port) |
|
63 *port = ntohl(*((unsigned int *)(data+5))); |
60 if (size) |
64 if (size) |
61 *size = ntohl(*((unsigned int *)(data+5))); |
65 *size = ntohl(*((unsigned int *)(data+5+4))); |
62 return HEAD; |
66 return HEAD; |
63 } |
67 } |
64 |
68 |
65 int eth_proto_max_send() |
69 int eth_proto_max_send() |
66 { |
70 { |
68 } |
72 } |
69 |
73 |
70 void eth_proto_init() |
74 void eth_proto_init() |
71 { |
75 { |
72 edata.socket = -1; |
76 edata.socket = -1; |
|
77 edata.port = command_line.eth_port; |
73 edata.seq_send = 0; |
78 edata.seq_send = 0; |
74 edata.seq_wait = 0; |
79 edata.seq_wait = 0; |
75 edata.send_acked = 1; /* Fine at the beginning, as if the last data was acked */ |
80 edata.send_acked = 1; /* Fine at the beginning, as if the last data was acked */ |
76 edata.partner_set = 0; |
81 edata.partner_set = 0; |
77 } |
82 } |
123 int eth_proto_recv(char *data, int size) |
128 int eth_proto_recv(char *data, int size) |
124 { |
129 { |
125 int res; |
130 int res; |
126 int seq; |
131 int seq; |
127 int data_length; |
132 int data_length; |
|
133 int port; |
128 enum Control c; |
134 enum Control c; |
129 char partner[6]; |
135 char partner[6]; |
130 |
136 |
131 do { |
137 do { |
132 res = eth_recv(eth_buffer, sizeof(eth_buffer), partner); |
138 res = eth_recv(eth_buffer, sizeof(eth_buffer), partner); |
133 edata.partner_set = 1; |
139 edata.partner_set = 1; |
134 } while(res < HEAD); |
140 } while(res < HEAD); |
135 parse_head(eth_buffer, &seq, &c, &data_length); |
141 parse_head(eth_buffer, &seq, &c, &port, &data_length); |
|
142 if (port != edata.port) |
|
143 return -1; /* Nothing the parent should care about. Not a packet for us. */ |
|
144 |
136 /* We admit any first connection */ |
145 /* We admit any first connection */ |
137 if (seq == 0 && c == INIT) |
146 if (seq == 0 && c == INIT) |
138 { |
147 { |
139 edata.seq_wait = 1; /* next of the just receive 0 */ |
148 edata.seq_wait = 1; /* next of the just receive 0 */ |
140 edata.seq_send = 0; /* New partner we send to, so 0 sent */ |
149 edata.seq_send = 0; /* New partner we send to, so 0 sent */ |