ethernet_misc.c
Go to the documentation of this file.
1 /**
2  * @file ethernet_misc.c
3  * @brief Helper functions for Ethernet
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2019 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 1.9.2
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL ETH_TRACE_LEVEL
33 
34 //Dependencies
35 #include <stdlib.h>
36 #include <string.h>
37 #include <ctype.h>
38 #include "core/net.h"
39 #include "core/nic.h"
40 #include "core/ethernet.h"
41 #include "core/socket.h"
42 #include "core/raw_socket.h"
43 #include "core/tcp_timer.h"
44 #include "ipv4/arp.h"
45 #include "ipv4/ipv4.h"
46 #include "ipv6/ipv6.h"
47 #include "mibs/mib2_module.h"
48 #include "mibs/if_mib_module.h"
49 #include "debug.h"
50 
51 //Check TCP/IP stack configuration
52 #if (ETH_SUPPORT == ENABLED)
53 
54 //Padding bytes
55 const uint8_t ethPadding[64] =
56 {
57  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
58  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
59  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
60  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
61  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
62  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
64  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
65 };
66 
67 //A lookup table can be used to speed up CRC calculation
68 #if (ETH_FAST_CRC_SUPPORT == ENABLED)
69 
70 static const uint32_t crc32Table[256] =
71 {
72  0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,
73  0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3,
74  0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988,
75  0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91,
76  0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE,
77  0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7,
78  0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC,
79  0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5,
80  0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172,
81  0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B,
82  0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940,
83  0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59,
84  0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116,
85  0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F,
86  0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924,
87  0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D,
88  0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A,
89  0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433,
90  0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818,
91  0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01,
92  0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E,
93  0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457,
94  0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C,
95  0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65,
96  0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2,
97  0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB,
98  0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0,
99  0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9,
100  0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086,
101  0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F,
102  0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4,
103  0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD,
104  0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A,
105  0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683,
106  0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8,
107  0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1,
108  0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE,
109  0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7,
110  0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC,
111  0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5,
112  0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252,
113  0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B,
114  0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60,
115  0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79,
116  0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236,
117  0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F,
118  0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04,
119  0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D,
120  0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A,
121  0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713,
122  0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38,
123  0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21,
124  0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E,
125  0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777,
126  0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C,
127  0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45,
128  0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2,
129  0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB,
130  0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0,
131  0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9,
132  0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6,
133  0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF,
134  0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94,
135  0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D
136 };
137 
138 #endif
139 
140 
141 /**
142  * @brief Ethernet frame padding
143  * @param[in] buffer Multi-part buffer containing the Ethernet frame
144  * @param[in,out] length Length of the Ethernet frame, in bytes
145  * @return Error code
146  **/
147 
149 {
150  error_t error;
151  size_t n;
152 
153  //Ethernet frames have a minimum length of 64 byte
155  {
156  //Add padding as necessary
158 
159  //Append padding bytes
160  error = netBufferAppend(buffer, ethPadding, n);
161 
162  //Check status code
163  if(!error)
164  {
165  //Adjust frame length
166  *length += n;
167  }
168  }
169  else
170  {
171  //No padding needed
172  error = NO_ERROR;
173  }
174 
175  //Return status code
176  return error;
177 }
178 
179 
180 /**
181  * @brief VLAN tag encoding
182  * @param[in] buffer Multi-part buffer containing the payload
183  * @param[in,out] offset Offset to the first payload byte
184  * @param[in] vlanId VLAN identifier
185  * @param[in] type Ethernet type
186  * @return Error code
187  **/
188 
189 error_t ethEncodeVlanTag(NetBuffer *buffer, size_t *offset, uint16_t vlanId,
190  uint16_t type)
191 {
192  VlanTag *vlanTag;
193 
194  //Sanity check
195  if(*offset < sizeof(VlanTag))
197 
198  //Make room for the VLAN tag
199  *offset -= sizeof(VlanTag);
200  //Point to the VLAN tag
201  vlanTag = netBufferAt(buffer, *offset);
202 
203  //The VLAN identifier is encoded in a 12-bit field
204  vlanTag->tci = htons(vlanId & VLAN_VID_MASK);
205 
206  //The EtherType field indicates which protocol is encapsulated in the
207  //payload
208  vlanTag->type = htons(type);
209 
210  //Successful processing
211  return NO_ERROR;
212 }
213 
214 
215 /**
216  * @brief VLAN tag deccoding
217  * @param[in] frame Pointer to the received Ethernet frame
218  * @param[in] length Length of the frame, in bytes
219  * @param[out] vlanId VLAN identifier
220  * @param[out] type Ethernet type
221  * @return Error code
222  **/
223 
224 error_t ethDecodeVlanTag(const uint8_t *frame, size_t length, uint16_t *vlanId,
225  uint16_t *type)
226 {
227  VlanTag *vlanTag;
228 
229  //Malformed Ethernet frame?
230  if(length < sizeof(VlanTag))
231  {
232  //Drop the received frame
233  return ERROR_INVALID_LENGTH;
234  }
235 
236  //Point to the VLAN tag
237  vlanTag = (VlanTag *) frame;
238 
239  //The VLAN identifier is encoded in a 12-bit field
240  *vlanId = ntohs(vlanTag->tci) & VLAN_VID_MASK;
241 
242  //The null VID indicates that the tag header contains only priority
243  //information (refer to IEEE 802.1q, section 9.6)
244  if(*vlanId == 0)
245  {
246  //Drop the received frame
247  return ERROR_WRONG_IDENTIFIER;
248  }
249 
250  //The EtherType field indicates which protocol is encapsulated in the
251  //payload
252  *type = ntohs(vlanTag->type);
253 
254  //Successful processing
255  return NO_ERROR;
256 }
257 
258 
259 /**
260  * @brief Destination MAC address filtering
261  * @param[in] interface Underlying network interface
262  * @param[in] macAddr Destination MAC address to be checked
263  * @return Error code
264  **/
265 
266 error_t ethCheckDestAddr(NetInterface *interface, const MacAddr *macAddr)
267 {
268  error_t error;
269  uint_t i;
270  MacFilterEntry *entry;
271  NetInterface *logicalInterface;
272 
273  //Filter out any invalid addresses
274  error = ERROR_INVALID_ADDRESS;
275 
276  //Point to the logical interface
277  logicalInterface = nicGetLogicalInterface(interface);
278 
279  //Interface MAC address?
280  if(macCompAddr(macAddr, &logicalInterface->macAddr))
281  {
282  error = NO_ERROR;
283  }
284  //Broadcast address?
285  else if(macCompAddr(macAddr, &MAC_BROADCAST_ADDR))
286  {
287  error = NO_ERROR;
288  }
289  //Multicast address?
290  else if(macIsMulticastAddr(macAddr))
291  {
292  //Go through the MAC filter table
293  for(i = 0; i < MAC_ADDR_FILTER_SIZE; i++)
294  {
295  //Point to the current entry
296  entry = &interface->macAddrFilter[i];
297 
298  //Valid entry?
299  if(entry->refCount > 0)
300  {
301  //Check whether the destination MAC address matches
302  //a relevant multicast address
303  if(macCompAddr(&entry->addr, macAddr))
304  {
305  //The MAC address is acceptable
306  error = NO_ERROR;
307  //Stop immediately
308  break;
309  }
310  }
311  }
312  }
313 
314  //Return status code
315  return error;
316 }
317 
318 
319 /**
320  * @brief Update Ethernet input statistics
321  * @param[in] interface Underlying network interface
322  * @param[in] destMacAddr Destination MAC address
323  **/
324 
325 void ethUpdateInStats(NetInterface *interface, const MacAddr *destMacAddr)
326 {
327  //Check whether the destination address is a unicast, broadcast or multicast address
328  if(macCompAddr(destMacAddr, &MAC_BROADCAST_ADDR))
329  {
330  //Number of non-unicast packets delivered to a higher-layer protocol
331  MIB2_INC_COUNTER32(ifGroup.ifTable[interface->index].ifInNUcastPkts, 1);
332 
333  //Number of broadcast packets delivered to a higher-layer protocol
334  IF_MIB_INC_COUNTER32(ifXTable[interface->index].ifInBroadcastPkts, 1);
335  IF_MIB_INC_COUNTER64(ifXTable[interface->index].ifHCInBroadcastPkts, 1);
336  }
337  else if(macIsMulticastAddr(destMacAddr))
338  {
339  //Number of non-unicast packets delivered to a higher-layer protocol
340  MIB2_INC_COUNTER32(ifGroup.ifTable[interface->index].ifInNUcastPkts, 1);
341 
342  //Number of multicast packets delivered to a higher-layer protocol
343  IF_MIB_INC_COUNTER32(ifXTable[interface->index].ifInMulticastPkts, 1);
344  IF_MIB_INC_COUNTER64(ifXTable[interface->index].ifHCInMulticastPkts, 1);
345  }
346  else
347  {
348  //Number of unicast packets delivered to a higher-layer protocol
349  MIB2_INC_COUNTER32(ifGroup.ifTable[interface->index].ifInUcastPkts, 1);
350  IF_MIB_INC_COUNTER32(ifTable[interface->index].ifInUcastPkts, 1);
351  IF_MIB_INC_COUNTER64(ifXTable[interface->index].ifHCInUcastPkts, 1);
352  }
353 }
354 
355 
356 /**
357  * @brief Update Ethernet output statistics
358  * @param[in] interface Underlying network interface
359  * @param[in] destMacAddr Destination MAC address
360  * @param[in] length Length of the Ethernet frame, in bytes
361  **/
362 
363 void ethUpdateOutStats(NetInterface *interface, const MacAddr *destMacAddr,
364  size_t length)
365 {
366  //Total number of octets transmitted out of the interface
367  MIB2_INC_COUNTER32(ifGroup.ifTable[interface->index].ifOutOctets, length);
368  IF_MIB_INC_COUNTER32(ifTable[interface->index].ifOutOctets, length);
369  IF_MIB_INC_COUNTER64(ifXTable[interface->index].ifHCOutOctets, length);
370 
371  //Check whether the destination address is a unicast, broadcast or multicast address
372  if(macCompAddr(destMacAddr, &MAC_BROADCAST_ADDR))
373  {
374  //Number of non-unicast packets that higher-level protocols requested be transmitted
375  MIB2_INC_COUNTER32(ifGroup.ifTable[interface->index].ifOutNUcastPkts, 1);
376 
377  //Number of broadcast packets that higher-level protocols requested be transmitted
378  IF_MIB_INC_COUNTER32(ifXTable[interface->index].ifOutBroadcastPkts, 1);
379  IF_MIB_INC_COUNTER64(ifXTable[interface->index].ifHCOutBroadcastPkts, 1);
380  }
381  else if(macIsMulticastAddr(destMacAddr))
382  {
383  //Number of non-unicast packets that higher-level protocols requested be transmitted
384  MIB2_INC_COUNTER32(ifGroup.ifTable[interface->index].ifOutNUcastPkts, 1);
385 
386  //Number of multicast packets that higher-level protocols requested be transmitted
387  IF_MIB_INC_COUNTER32(ifXTable[interface->index].ifOutMulticastPkts, 1);
388  IF_MIB_INC_COUNTER64(ifXTable[interface->index].ifHCOutMulticastPkts, 1);
389  }
390  else
391  {
392  //Number of unicast packets that higher-level protocols requested be transmitted
393  MIB2_INC_COUNTER32(ifGroup.ifTable[interface->index].ifOutUcastPkts, 1);
394  IF_MIB_INC_COUNTER32(ifTable[interface->index].ifOutUcastPkts, 1);
395  IF_MIB_INC_COUNTER64(ifXTable[interface->index].ifHCOutUcastPkts, 1);
396  }
397 }
398 
399 
400 /**
401  * @brief Update Ethernet error statistics
402  * @param[in] interface Underlying network interface
403  * @param[in] error Status code describing the error
404  **/
405 
406 void ethUpdateErrorStats(NetInterface *interface, error_t error)
407 {
408  //Check error code
409  switch(error)
410  {
413  //Number of inbound packets which were chosen to be discarded even
414  //though no errors had been detected
415  MIB2_INC_COUNTER32(ifGroup.ifTable[interface->index].ifInDiscards, 1);
416  IF_MIB_INC_COUNTER32(ifTable[interface->index].ifInDiscards, 1);
417  break;
420  //Number of inbound packets that contained errors
421  MIB2_INC_COUNTER32(ifGroup.ifTable[interface->index].ifInErrors, 1);
422  IF_MIB_INC_COUNTER32(ifTable[interface->index].ifInErrors, 1);
423  break;
425  //Number of packets received via the interface which were discarded
426  //because of an unknown or unsupported protocol
427  MIB2_INC_COUNTER32(ifGroup.ifTable[interface->index].ifInUnknownProtos, 1);
428  IF_MIB_INC_COUNTER32(ifTable[interface->index].ifInUnknownProtos, 1);
429  break;
430  default:
431  //Just for sanity
432  break;
433  }
434 }
435 
436 
437 /**
438  * @brief Ethernet CRC calculation
439  * @param[in] data Pointer to the data over which to calculate the CRC
440  * @param[in] length Number of bytes to process
441  * @return Resulting CRC value
442  **/
443 
444 uint32_t ethCalcCrc(const void *data, size_t length)
445 {
446 //A lookup table can be used to speed up CRC calculation
447 #if (ETH_FAST_CRC_SUPPORT == ENABLED)
448  uint_t i;
449 
450  //Point to the data over which to calculate the CRC
451  const uint8_t *p = (uint8_t *) data;
452  //CRC preset value
453  uint32_t crc = 0xFFFFFFFF;
454 
455  //Loop through data
456  for(i = 0; i < length; i++)
457  {
458  //The message is processed byte by byte
459  crc = (crc >> 8) ^ crc32Table[(crc & 0xFF) ^ p[i]];
460  }
461 
462  //Return 1's complement value
463  return ~crc;
464 
465 //Bit by bit CRC calculation
466 #else
467  uint_t i;
468  uint_t j;
469 
470  //Point to the data over which to calculate the CRC
471  const uint8_t *p = (uint8_t *) data;
472  //CRC preset value
473  uint32_t crc = 0xFFFFFFFF;
474 
475  //Loop through data
476  for(i = 0; i < length; i++)
477  {
478  //Update CRC value
479  crc ^= p[i];
480  //The message is processed bit by bit
481  for(j = 0; j < 8; j++)
482  {
483  if(crc & 0x00000001)
484  crc = (crc >> 1) ^ 0xEDB88320;
485  else
486  crc = crc >> 1;
487  }
488  }
489 
490  //Return 1's complement value
491  return ~crc;
492 #endif
493 }
494 
495 
496 /**
497  * @brief Calculate CRC over a multi-part buffer
498  * @param[in] buffer Pointer to the multi-part buffer
499  * @param[in] offset Offset from the beginning of the buffer
500  * @param[in] length Number of bytes to process
501  * @return Resulting CRC value
502  **/
503 
504 uint32_t ethCalcCrcEx(const NetBuffer *buffer, size_t offset, size_t length)
505 {
506  uint_t i;
507  uint_t n;
508  uint32_t crc;
509  uint8_t *p;
510 #if (ETH_FAST_CRC_SUPPORT == DISABLED)
511  uint_t k;
512 #endif
513 
514  //CRC preset value
515  crc = 0xFFFFFFFF;
516 
517  //Loop through data chunks
518  for(i = 0; i < buffer->chunkCount && length > 0; i++)
519  {
520  //Is there any data to process in the current chunk?
521  if(offset < buffer->chunk[i].length)
522  {
523  //Point to the first data byte
524  p = (uint8_t *) buffer->chunk[i].address + offset;
525  //Compute the number of bytes to process
526  n = MIN(buffer->chunk[i].length - offset, length);
527  //Adjust byte counter
528  length -= n;
529 
530  //Process current chunk
531  while(n > 0)
532  {
533 #if (ETH_FAST_CRC_SUPPORT == ENABLED)
534  //The message is processed byte by byte
535  crc = (crc >> 8) ^ crc32Table[(crc & 0xFF) ^ *p];
536 #else
537  //Update CRC value
538  crc ^= *p;
539 
540  //The message is processed bit by bit
541  for(k = 0; k < 8; k++)
542  {
543  if(crc & 0x00000001)
544  crc = (crc >> 1) ^ 0xEDB88320;
545  else
546  crc = crc >> 1;
547  }
548 #endif
549  //Next byte
550  p++;
551  n--;
552  }
553 
554  //Process the next block from the start
555  offset = 0;
556  }
557  else
558  {
559  //Skip the current chunk
560  offset -= buffer->chunk[i].length;
561  }
562  }
563 
564  //Return 1's complement value
565  return ~crc;
566 }
567 
568 
569 /**
570  * @brief Ethernet CRC verification
571  * @param[in] interface Underlying network interface
572  * @param[in] frame Pointer to the received Ethernet frame
573  * @param[in] length Length of the frame, in bytes
574  * @return Error code
575  **/
576 
577 error_t ethCheckCrc(NetInterface *interface, const uint8_t *frame,
578  size_t length)
579 {
580  uint32_t crc;
581 
582  //Malformed Ethernet frame?
583  if(length < (sizeof(EthHeader) + ETH_CRC_SIZE))
584  {
585  //Drop the received frame
586  return ERROR_INVALID_LENGTH;
587  }
588 
589  //CRC verification not supported by hardware?
590  if(!interface->nicDriver->autoCrcVerif)
591  {
592  //The value of the residue is 0x2144DF1C when no CRC errors
593  //are detected
594  if(ethCalcCrc(frame, length) != 0x2144DF1C)
595  {
596  //Drop the received frame
597  return ERROR_WRONG_CHECKSUM;
598  }
599  }
600 
601  //Retrieve CRC value
602  crc = LOAD32BE(frame + length - ETH_CRC_SIZE);
603  //Reseed the pseudo-random number generator
604  netInitRand(crc);
605 
606  //Successful CRC verification
607  return NO_ERROR;
608 }
609 
610 #endif
ARP (Address Resolution Protocol)
MacAddr addr
MAC address.
Definition: ethernet.h:219
__start_packed struct @114 EthHeader
Ethernet frame header.
Interfaces Group MIB module.
#define VLAN_VID_MASK
Definition: ethernet.h:98
TCP/IP stack core.
#define ETH_MIN_FRAME_SIZE
Definition: ethernet.h:87
Debugging facilities.
uint8_t p
Definition: ndp.h:297
#define IF_MIB_INC_COUNTER32(name, value)
Definition: if_mib_module.h:47
uint32_t ethCalcCrcEx(const NetBuffer *buffer, size_t offset, size_t length)
Calculate CRC over a multi-part buffer.
#define macIsMulticastAddr(macAddr)
Definition: ethernet.h:107
MIB-II module.
Invalid parameter.
Definition: error.h:47
#define IF_MIB_INC_COUNTER64(name, value)
Definition: if_mib_module.h:48
void ethUpdateErrorStats(NetInterface *interface, error_t error)
Update Ethernet error statistics.
void ethUpdateInStats(NetInterface *interface, const MacAddr *destMacAddr)
Update Ethernet input statistics.
char_t type
#define LOAD32BE(p)
Definition: cpu_endian.h:194
#define htons(value)
Definition: cpu_endian.h:392
#define MIB2_INC_COUNTER32(name, value)
Definition: mib2_module.h:156
void * address
Definition: net_mem.h:78
error_t ethPadFrame(NetBuffer *buffer, size_t *length)
Ethernet frame padding.
#define MAC_ADDR_FILTER_SIZE
Definition: ethernet.h:74
error_t ethCheckCrc(NetInterface *interface, const uint8_t *frame, size_t length)
Ethernet CRC verification.
Ethernet.
ChunkDesc chunk[]
Definition: net_mem.h:92
#define ntohs(value)
Definition: cpu_endian.h:398
void * netBufferAt(const NetBuffer *buffer, size_t offset)
Returns a pointer to the data at the specified position.
Definition: net_mem.c:413
TCP/IP raw sockets.
IPv4 (Internet Protocol Version 4)
Structure describing a buffer that spans multiple chunks.
Definition: net_mem.h:88
#define MIN(a, b)
Definition: os_port.h:62
error_t ethDecodeVlanTag(const uint8_t *frame, size_t length, uint16_t *vlanId, uint16_t *type)
VLAN tag deccoding.
const MacAddr MAC_BROADCAST_ADDR
Definition: ethernet.c:58
void ethUpdateOutStats(NetInterface *interface, const MacAddr *destMacAddr, size_t length)
Update Ethernet output statistics.
error_t ethEncodeVlanTag(NetBuffer *buffer, size_t *offset, uint16_t vlanId, uint16_t type)
VLAN tag encoding.
IPv6 (Internet Protocol Version 6)
Success.
Definition: error.h:44
uint32_t ethCalcCrc(const void *data, size_t length)
Ethernet CRC calculation.
uint16_t length
Definition: net_mem.h:79
uint_t refCount
Reference count for the current entry.
Definition: ethernet.h:220
error_t
Error codes.
Definition: error.h:42
#define ETH_CRC_SIZE
Definition: ethernet.h:93
unsigned int uint_t
Definition: compiler_port.h:45
error_t netBufferAppend(NetBuffer *dest, const void *src, size_t length)
Append data a multi-part buffer.
Definition: net_mem.c:586
__start_packed struct @112 MacAddr
MAC address.
uint8_t data[]
Definition: dtls_misc.h:169
#define NetInterface
Definition: net.h:36
#define macCompAddr(macAddr1, macAddr2)
Definition: ethernet.h:104
error_t ethCheckDestAddr(NetInterface *interface, const MacAddr *macAddr)
Destination MAC address filtering.
const uint8_t ethPadding[64]
Definition: ethernet_misc.c:55
error_t netInitRand(uint32_t seed)
Seed pseudo-random number generator.
Definition: net.c:1524
NetInterface * nicGetLogicalInterface(NetInterface *interface)
Retrieve logical interface.
Definition: nic.c:64
__start_packed struct @115 VlanTag
VLAN tag.
Socket API.
uint8_t length
Definition: dtls_misc.h:142
uint8_t n
Network interface controller abstraction layer.
TCP timer management.
uint_t chunkCount
Definition: net_mem.h:90
MAC filter table entry.
Definition: ethernet.h:217