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.4
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 TCI field is divided into PCP, DEI, and VID
204  vlanTag->tci = htons(vlanId);
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 VID is encoded in a 12-bit field. The null VID indicates that the
240  //tag header contains only priority information (refer to IEEE 802.1q,
241  //section 9.6)
242  *vlanId = ntohs(vlanTag->tci) & VLAN_VID_MASK;
243 
244  //The EtherType field indicates which protocol is encapsulated in the
245  //payload
246  *type = ntohs(vlanTag->type);
247 
248  //Successful processing
249  return NO_ERROR;
250 }
251 
252 
253 /**
254  * @brief Destination MAC address filtering
255  * @param[in] interface Underlying network interface
256  * @param[in] macAddr Destination MAC address to be checked
257  * @return Error code
258  **/
259 
260 error_t ethCheckDestAddr(NetInterface *interface, const MacAddr *macAddr)
261 {
262  error_t error;
263  uint_t i;
264  MacFilterEntry *entry;
265  NetInterface *logicalInterface;
266 
267  //Filter out any invalid addresses
268  error = ERROR_INVALID_ADDRESS;
269 
270  //Point to the logical interface
271  logicalInterface = nicGetLogicalInterface(interface);
272 
273  //Interface MAC address?
274  if(macCompAddr(macAddr, &logicalInterface->macAddr))
275  {
276  error = NO_ERROR;
277  }
278  //Broadcast address?
279  else if(macCompAddr(macAddr, &MAC_BROADCAST_ADDR))
280  {
281  error = NO_ERROR;
282  }
283  //Multicast address?
284  else if(macIsMulticastAddr(macAddr))
285  {
286  //Go through the MAC filter table
287  for(i = 0; i < MAC_ADDR_FILTER_SIZE; i++)
288  {
289  //Point to the current entry
290  entry = &interface->macAddrFilter[i];
291 
292  //Valid entry?
293  if(entry->refCount > 0)
294  {
295  //Check whether the destination MAC address matches
296  //a relevant multicast address
297  if(macCompAddr(&entry->addr, macAddr))
298  {
299  //The MAC address is acceptable
300  error = NO_ERROR;
301  //Stop immediately
302  break;
303  }
304  }
305  }
306  }
307 
308  //Return status code
309  return error;
310 }
311 
312 
313 /**
314  * @brief Update Ethernet input statistics
315  * @param[in] interface Underlying network interface
316  * @param[in] destMacAddr Destination MAC address
317  **/
318 
319 void ethUpdateInStats(NetInterface *interface, const MacAddr *destMacAddr)
320 {
321  //Check whether the destination address is a unicast, broadcast or multicast address
322  if(macCompAddr(destMacAddr, &MAC_BROADCAST_ADDR))
323  {
324  //Number of non-unicast packets delivered to a higher-layer protocol
325  MIB2_INC_COUNTER32(ifGroup.ifTable[interface->index].ifInNUcastPkts, 1);
326 
327  //Number of broadcast packets delivered to a higher-layer protocol
328  IF_MIB_INC_COUNTER32(ifXTable[interface->index].ifInBroadcastPkts, 1);
329  IF_MIB_INC_COUNTER64(ifXTable[interface->index].ifHCInBroadcastPkts, 1);
330  }
331  else if(macIsMulticastAddr(destMacAddr))
332  {
333  //Number of non-unicast packets delivered to a higher-layer protocol
334  MIB2_INC_COUNTER32(ifGroup.ifTable[interface->index].ifInNUcastPkts, 1);
335 
336  //Number of multicast packets delivered to a higher-layer protocol
337  IF_MIB_INC_COUNTER32(ifXTable[interface->index].ifInMulticastPkts, 1);
338  IF_MIB_INC_COUNTER64(ifXTable[interface->index].ifHCInMulticastPkts, 1);
339  }
340  else
341  {
342  //Number of unicast packets delivered to a higher-layer protocol
343  MIB2_INC_COUNTER32(ifGroup.ifTable[interface->index].ifInUcastPkts, 1);
344  IF_MIB_INC_COUNTER32(ifTable[interface->index].ifInUcastPkts, 1);
345  IF_MIB_INC_COUNTER64(ifXTable[interface->index].ifHCInUcastPkts, 1);
346  }
347 }
348 
349 
350 /**
351  * @brief Update Ethernet output statistics
352  * @param[in] interface Underlying network interface
353  * @param[in] destMacAddr Destination MAC address
354  * @param[in] length Length of the Ethernet frame, in bytes
355  **/
356 
357 void ethUpdateOutStats(NetInterface *interface, const MacAddr *destMacAddr,
358  size_t length)
359 {
360  //Total number of octets transmitted out of the interface
361  MIB2_INC_COUNTER32(ifGroup.ifTable[interface->index].ifOutOctets, length);
362  IF_MIB_INC_COUNTER32(ifTable[interface->index].ifOutOctets, length);
363  IF_MIB_INC_COUNTER64(ifXTable[interface->index].ifHCOutOctets, length);
364 
365  //Check whether the destination address is a unicast, broadcast or multicast address
366  if(macCompAddr(destMacAddr, &MAC_BROADCAST_ADDR))
367  {
368  //Number of non-unicast packets that higher-level protocols requested be transmitted
369  MIB2_INC_COUNTER32(ifGroup.ifTable[interface->index].ifOutNUcastPkts, 1);
370 
371  //Number of broadcast packets that higher-level protocols requested be transmitted
372  IF_MIB_INC_COUNTER32(ifXTable[interface->index].ifOutBroadcastPkts, 1);
373  IF_MIB_INC_COUNTER64(ifXTable[interface->index].ifHCOutBroadcastPkts, 1);
374  }
375  else if(macIsMulticastAddr(destMacAddr))
376  {
377  //Number of non-unicast packets that higher-level protocols requested be transmitted
378  MIB2_INC_COUNTER32(ifGroup.ifTable[interface->index].ifOutNUcastPkts, 1);
379 
380  //Number of multicast packets that higher-level protocols requested be transmitted
381  IF_MIB_INC_COUNTER32(ifXTable[interface->index].ifOutMulticastPkts, 1);
382  IF_MIB_INC_COUNTER64(ifXTable[interface->index].ifHCOutMulticastPkts, 1);
383  }
384  else
385  {
386  //Number of unicast packets that higher-level protocols requested be transmitted
387  MIB2_INC_COUNTER32(ifGroup.ifTable[interface->index].ifOutUcastPkts, 1);
388  IF_MIB_INC_COUNTER32(ifTable[interface->index].ifOutUcastPkts, 1);
389  IF_MIB_INC_COUNTER64(ifXTable[interface->index].ifHCOutUcastPkts, 1);
390  }
391 }
392 
393 
394 /**
395  * @brief Update Ethernet error statistics
396  * @param[in] interface Underlying network interface
397  * @param[in] error Status code describing the error
398  **/
399 
400 void ethUpdateErrorStats(NetInterface *interface, error_t error)
401 {
402  //Check error code
403  switch(error)
404  {
407  //Number of inbound packets which were chosen to be discarded even
408  //though no errors had been detected
409  MIB2_INC_COUNTER32(ifGroup.ifTable[interface->index].ifInDiscards, 1);
410  IF_MIB_INC_COUNTER32(ifTable[interface->index].ifInDiscards, 1);
411  break;
414  //Number of inbound packets that contained errors
415  MIB2_INC_COUNTER32(ifGroup.ifTable[interface->index].ifInErrors, 1);
416  IF_MIB_INC_COUNTER32(ifTable[interface->index].ifInErrors, 1);
417  break;
419  //Number of packets received via the interface which were discarded
420  //because of an unknown or unsupported protocol
421  MIB2_INC_COUNTER32(ifGroup.ifTable[interface->index].ifInUnknownProtos, 1);
422  IF_MIB_INC_COUNTER32(ifTable[interface->index].ifInUnknownProtos, 1);
423  break;
424  default:
425  //Just for sanity
426  break;
427  }
428 }
429 
430 
431 /**
432  * @brief Ethernet CRC calculation
433  * @param[in] data Pointer to the data over which to calculate the CRC
434  * @param[in] length Number of bytes to process
435  * @return Resulting CRC value
436  **/
437 
438 uint32_t ethCalcCrc(const void *data, size_t length)
439 {
440 //A lookup table can be used to speed up CRC calculation
441 #if (ETH_FAST_CRC_SUPPORT == ENABLED)
442  uint_t i;
443 
444  //Point to the data over which to calculate the CRC
445  const uint8_t *p = (uint8_t *) data;
446  //CRC preset value
447  uint32_t crc = 0xFFFFFFFF;
448 
449  //Loop through data
450  for(i = 0; i < length; i++)
451  {
452  //The message is processed byte by byte
453  crc = (crc >> 8) ^ crc32Table[(crc & 0xFF) ^ p[i]];
454  }
455 
456  //Return 1's complement value
457  return ~crc;
458 
459 //Bit by bit CRC calculation
460 #else
461  uint_t i;
462  uint_t j;
463 
464  //Point to the data over which to calculate the CRC
465  const uint8_t *p = (uint8_t *) data;
466  //CRC preset value
467  uint32_t crc = 0xFFFFFFFF;
468 
469  //Loop through data
470  for(i = 0; i < length; i++)
471  {
472  //Update CRC value
473  crc ^= p[i];
474  //The message is processed bit by bit
475  for(j = 0; j < 8; j++)
476  {
477  if(crc & 0x00000001)
478  crc = (crc >> 1) ^ 0xEDB88320;
479  else
480  crc = crc >> 1;
481  }
482  }
483 
484  //Return 1's complement value
485  return ~crc;
486 #endif
487 }
488 
489 
490 /**
491  * @brief Calculate CRC over a multi-part buffer
492  * @param[in] buffer Pointer to the multi-part buffer
493  * @param[in] offset Offset from the beginning of the buffer
494  * @param[in] length Number of bytes to process
495  * @return Resulting CRC value
496  **/
497 
498 uint32_t ethCalcCrcEx(const NetBuffer *buffer, size_t offset, size_t length)
499 {
500  uint_t i;
501  uint_t n;
502  uint32_t crc;
503  uint8_t *p;
504 #if (ETH_FAST_CRC_SUPPORT == DISABLED)
505  uint_t k;
506 #endif
507 
508  //CRC preset value
509  crc = 0xFFFFFFFF;
510 
511  //Loop through data chunks
512  for(i = 0; i < buffer->chunkCount && length > 0; i++)
513  {
514  //Is there any data to process in the current chunk?
515  if(offset < buffer->chunk[i].length)
516  {
517  //Point to the first data byte
518  p = (uint8_t *) buffer->chunk[i].address + offset;
519  //Compute the number of bytes to process
520  n = MIN(buffer->chunk[i].length - offset, length);
521  //Adjust byte counter
522  length -= n;
523 
524  //Process current chunk
525  while(n > 0)
526  {
527 #if (ETH_FAST_CRC_SUPPORT == ENABLED)
528  //The message is processed byte by byte
529  crc = (crc >> 8) ^ crc32Table[(crc & 0xFF) ^ *p];
530 #else
531  //Update CRC value
532  crc ^= *p;
533 
534  //The message is processed bit by bit
535  for(k = 0; k < 8; k++)
536  {
537  if(crc & 0x00000001)
538  crc = (crc >> 1) ^ 0xEDB88320;
539  else
540  crc = crc >> 1;
541  }
542 #endif
543  //Next byte
544  p++;
545  n--;
546  }
547 
548  //Process the next block from the start
549  offset = 0;
550  }
551  else
552  {
553  //Skip the current chunk
554  offset -= buffer->chunk[i].length;
555  }
556  }
557 
558  //Return 1's complement value
559  return ~crc;
560 }
561 
562 
563 /**
564  * @brief Ethernet CRC verification
565  * @param[in] interface Underlying network interface
566  * @param[in] frame Pointer to the received Ethernet frame
567  * @param[in] length Length of the frame, in bytes
568  * @return Error code
569  **/
570 
571 error_t ethCheckCrc(NetInterface *interface, const uint8_t *frame,
572  size_t length)
573 {
574  uint32_t crc;
575 
576  //Malformed Ethernet frame?
577  if(length < (sizeof(EthHeader) + ETH_CRC_SIZE))
578  {
579  //Drop the received frame
580  return ERROR_INVALID_LENGTH;
581  }
582 
583  //CRC verification not supported by hardware?
584  if(!interface->nicDriver->autoCrcVerif)
585  {
586  //The value of the residue is 0x2144DF1C when no CRC errors
587  //are detected
588  if(ethCalcCrc(frame, length) != 0x2144DF1C)
589  {
590  //Drop the received frame
591  return ERROR_WRONG_CHECKSUM;
592  }
593  }
594 
595  //Retrieve CRC value
596  crc = LOAD32BE(frame + length - ETH_CRC_SIZE);
597  //Reseed the pseudo-random number generator
598  netInitRand(crc);
599 
600  //Successful CRC verification
601  return NO_ERROR;
602 }
603 
604 #endif
ARP (Address Resolution Protocol)
MacAddr addr
MAC address.
Definition: ethernet.h:222
Interfaces Group MIB module.
#define VLAN_VID_MASK
Definition: ethernet.h:101
TCP/IP stack core.
#define ETH_MIN_FRAME_SIZE
Definition: ethernet.h:87
Debugging facilities.
uint8_t p
Definition: ndp.h:298
#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:110
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.
__start_packed struct @108 MacAddr
MAC address.
__start_packed struct @110 EthHeader
Ethernet frame header.
#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:223
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
uint8_t data[]
Definition: dtls_misc.h:169
#define NetInterface
Definition: net.h:36
#define macCompAddr(macAddr1, macAddr2)
Definition: ethernet.h:107
error_t ethCheckDestAddr(NetInterface *interface, const MacAddr *macAddr)
Destination MAC address filtering.
__start_packed struct @111 VlanTag
VLAN tag.
const uint8_t ethPadding[64]
Definition: ethernet_misc.c:55
error_t netInitRand(uint32_t seed)
Seed pseudo-random number generator.
Definition: net.c:1525
NetInterface * nicGetLogicalInterface(NetInterface *interface)
Retrieve logical interface.
Definition: nic.c:64
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:220