36 |
{ |
{ |
37 |
|
|
38 |
/* Check sequence number */ |
/* Check sequence number */ |
39 |
if ( header->type == TYPE_DATA && |
if (header->type == TYPE_DATA && |
40 |
(header->seq < PACKET_MIN_SEQ || header->seq > PACKET_MAX_SEQ)) |
(header->seq < PACKET_MIN_SEQ || header->seq > PACKET_MAX_SEQ)) |
41 |
{ |
{ |
42 |
debug (2, "P3 - Bad header received\n"); |
debug (2, "P3 - Bad header received\n"); |
43 |
debug (3,"\tbad sequence: %02x\n", header->seq); |
debug (3, "\tbad sequence: %02x\n", header->seq); |
44 |
return 0; |
return 0; |
45 |
} |
} |
46 |
|
|
48 |
if (header->ack < PACKET_MIN_SEQ || header->ack > PACKET_MAX_SEQ) |
if (header->ack < PACKET_MIN_SEQ || header->ack > PACKET_MAX_SEQ) |
49 |
{ |
{ |
50 |
debug (2, "P3 - Bad header received\n"); |
debug (2, "P3 - Bad header received\n"); |
51 |
debug (3,"\tbad ack: %02x\n", header->ack); |
debug (3, "\tbad ack: %02x\n", header->ack); |
52 |
return 0; |
return 0; |
53 |
} |
} |
54 |
|
|
57 |
ntohs (header->size) < P3_SIZE_OFFSET) |
ntohs (header->size) < P3_SIZE_OFFSET) |
58 |
{ |
{ |
59 |
debug (2, "P3 - Bad header received\n"); |
debug (2, "P3 - Bad header received\n"); |
60 |
debug (3,"\tbad size: %d\n", ntohs (header->size)); |
debug (3, "\tbad size: %d\n", ntohs (header->size)); |
61 |
return 0; |
return 0; |
62 |
} |
} |
63 |
|
|
65 |
if (header->type < TYPE_DATA || header->type > TYPE_PING) |
if (header->type < TYPE_DATA || header->type > TYPE_PING) |
66 |
{ |
{ |
67 |
debug (2, "P3 - Bad header received\n"); |
debug (2, "P3 - Bad header received\n"); |
68 |
debug (3,"\tbad type: %02x\n", header->type); |
debug (3, "\tbad type: %02x\n", header->type); |
69 |
return 0; |
return 0; |
70 |
} |
} |
71 |
|
|
86 |
/* Check packet is 0x0d terminated */ |
/* Check packet is 0x0d terminated */ |
87 |
if (p[data_size] != P3_STOP) |
if (p[data_size] != P3_STOP) |
88 |
{ |
{ |
89 |
debug (1,"P3 - Bad packet received:\n"); |
debug (1, "P3 - Bad packet received:\n"); |
90 |
debug (1,"\tnot 0x0d terminated\n"); |
debug (1, "\tnot 0x0d terminated\n"); |
91 |
p3_send_nack (header); |
p3_send_nack (header); |
92 |
return 0; |
return 0; |
93 |
} |
} |
94 |
|
|
95 |
/* Check client bit */ |
/* Check client bit */ |
96 |
if(header->client) |
if (header->client) |
97 |
{ |
{ |
98 |
debug (1,"P3 - Bad packet received:\n"); |
debug (1, "P3 - Bad packet received:\n"); |
99 |
debug (1,"\tthis is a client packet!\n"); |
debug (1, "\tthis is a client packet!\n"); |
100 |
p3_send_nack (header); |
p3_send_nack (header); |
101 |
return 0; |
return 0; |
102 |
} |
} |
105 |
crc = htons (p3_crc16 ((char *) &header->size, data_size + 5)); |
crc = htons (p3_crc16 ((char *) &header->size, data_size + 5)); |
106 |
if (crc != header->checksum) |
if (crc != header->checksum) |
107 |
{ |
{ |
108 |
debug (1,"P3 - Bad packet received:\n"); |
debug (1, "P3 - Bad packet received:\n"); |
109 |
debug (1,"\tbad CRC checksum\n"); |
debug (1, "\tbad CRC checksum\n"); |
110 |
p3_send_nack (header); |
p3_send_nack (header); |
111 |
return 0; |
return 0; |
112 |
} |
} |