This implements some common helper functions for IPv6 over X implementations based on [network device types] (net_netdev_type).  
More...
This implements some common helper functions for IPv6 over X implementations based on [network device types] (net_netdev_type). 
- Attention
- If you add a new network device type have at least a look at the implementation of these functions. 
|  | 
| file | l2util.h | 
|  | Link-layer helper function definitions. 
 | 
|  | 
|  | 
| int | l2util_eui64_from_addr (int dev_type, const uint8_t *addr, size_t addr_len, eui64_t *eui64) | 
|  | Converts a given hardware address to an EUI-64. 
 | 
|  | 
| int | l2util_ipv6_iid_from_addr (int dev_type, const uint8_t *addr, size_t addr_len, eui64_t *iid) | 
|  | Converts a given hardware address to an IPv6 IID. 
 | 
|  | 
| int | l2util_ipv6_iid_to_addr (int dev_type, const eui64_t *iid, uint8_t *addr) | 
|  | Converts an IPv6 IID to a hardware address. 
 | 
|  | 
| int | l2util_ndp_addr_len_from_l2ao (int dev_type, const ndp_opt_t *opt) | 
|  | Derives the length of the link-layer address in an NDP link-layer address option from that option's length field and the given device type. 
 | 
|  | 
| int | l2util_ipv6_group_to_l2_group (int dev_type, const ipv6_addr_t *ipv6_group, uint8_t *l2_group) | 
|  | Converts an IPv6 multicast address to a multicast address of the respective link layer. 
 | 
|  | 
| char * | l2util_addr_to_str (const uint8_t *addr, size_t addr_len, char *out) | 
|  | Converts a hardware address to a human readable string. 
 | 
|  | 
| size_t | l2util_addr_from_str (const char *str, uint8_t *out) | 
|  | Parses a string of colon-separated hexadecimals to a hardware address. 
 | 
|  | 
| static bool | l2util_addr_equal (const uint8_t *addr_a, uint8_t addr_a_len, const uint8_t *addr_b, uint8_t addr_b_len) | 
|  | Checks if two l2 addresses are equal. 
 | 
|  | 
◆ L2UTIL_ADDR_MAX_LEN
      
        
          | #define L2UTIL_ADDR_MAX_LEN   (8U) | 
      
 
maximum expected length for addresses 
Definition at line 37 of file l2util.h.
 
 
◆ l2util_addr_equal()
  
  | 
        
          | static bool l2util_addr_equal | ( | const uint8_t * | addr_a, |  
          |  |  | uint8_t | addr_a_len, |  
          |  |  | const uint8_t * | addr_b, |  
          |  |  | uint8_t | addr_b_len ) |  | inlinestatic | 
 
Checks if two l2 addresses are equal. 
- Parameters
- 
  
    | [in] | addr_a | First hardware address. |  | [in] | addr_a_len | Length of first hardware address. |  | [in] | addr_b | Second hardware address. |  | [in] | addr_b_len | Length of second hardware address. |  
 
- Returns
- true if the addresses match, false if not. 
Definition at line 203 of file l2util.h.
 
 
◆ l2util_addr_from_str()
      
        
          | size_t l2util_addr_from_str | ( | const char * | str, | 
        
          |  |  | uint8_t * | out ) | 
      
 
Parses a string of colon-separated hexadecimals to a hardware address. 
The input format must be like xx:xx:xx:xx where xx will be the bytes of addr in hexadecimal representation.
- Precondition
- (out != NULL)
- 
outMUST have allocated at least GNRC_NETIF_L2ADDR_MAXLEN bytes.
- Parameters
- 
  
    | [in] | str | A string of colon-separated hexadecimals. |  | [out] | out | The resulting hardware address. Must at least have GNRC_NETIF_L2ADDR_MAXLEN bytes allocated. |  
 
- Returns
- Actual length of outon success.
- 
0, on failure. 
 
 
◆ l2util_addr_to_str()
      
        
          | char * l2util_addr_to_str | ( | const uint8_t * | addr, | 
        
          |  |  | size_t | addr_len, | 
        
          |  |  | char * | out ) | 
      
 
Converts a hardware address to a human readable string. 
The format will be like xx:xx:xx:xx where xx are the bytes of addr in hexadecimal representation.
- Precondition
- (out != NULL) && ((addr != NULL) || (addr_len == 0))
- 
outMUST have allocated at least 3 *addr_lenbytes.
- Parameters
- 
  
    | [in] | addr | A hardware address. |  | [in] | addr_len | Length of addr. |  | [out] | out | A string to store the output in. Must at least have 3 * addr_lenbytes allocated. |  
 
- Returns
- out.
 
 
◆ l2util_eui64_from_addr()
      
        
          | int l2util_eui64_from_addr | ( | int | dev_type, | 
        
          |  |  | const uint8_t * | addr, | 
        
          |  |  | size_t | addr_len, | 
        
          |  |  | eui64_t * | eui64 ) | 
      
 
Converts a given hardware address to an EUI-64. 
- Attention
- When the link-layer of the interface has link-layer addresses, and NDEBUGis not defined, the node fails with an assertion instead returning-ENOTSUP.
- Parameters
- 
  
    | [in] | dev_type | The network device type of the device addrcame from (either because it is the configured address of the device or from a packet that came over it). |  | [in] | addr | A hardware address. |  | [in] | addr_len | Number of bytes in addr. |  | [out] | eui64 | The EUI-64 based on gnrc_netif_t::device_type |  
 
- Returns
- sizeof(eui64_t)on success.
- 
-ENOTSUP, whendev_typedoes not support EUI-64 conversion.
- 
-EINVAL, whenaddr_lenis invalid for thedev_type.
 
 
◆ l2util_ipv6_group_to_l2_group()
      
        
          | int l2util_ipv6_group_to_l2_group | ( | int | dev_type, | 
        
          |  |  | const ipv6_addr_t * | ipv6_group, | 
        
          |  |  | uint8_t * | l2_group ) | 
      
 
Converts an IPv6 multicast address to a multicast address of the respective link layer. 
- Precondition
- There is enough allocated space in l2_groupfor an address for a device of typedev_type(e.g. 6 bytes for an ethernet address).
- Parameters
- 
  
    | [in] | dev_type | The network device type of the device l2_addrshould be generated for. |  | [in] | ipv6_group | An IPv6 multicast address. |  | [out] | l2_group | A link layer multicast address |  
 
- Returns
- Length of l2_groupin bytes
- 
-ENOTSUPif link layer does not support multicast.
 
 
◆ l2util_ipv6_iid_from_addr()
      
        
          | int l2util_ipv6_iid_from_addr | ( | int | dev_type, | 
        
          |  |  | const uint8_t * | addr, | 
        
          |  |  | size_t | addr_len, | 
        
          |  |  | eui64_t * | iid ) | 
      
 
Converts a given hardware address to an IPv6 IID. 
- Attention
- When the link-layer of the interface has link-layer addresses, and NDEBUGis not defined, the node fails with an assertion instead returning-ENOTSUP.
- Parameters
- 
  
    | [in] | dev_type | The network device type of the device addrcame from (either because it is the configured address of the device or from a packet that came over it). |  | [in] | addr | A hardware address. |  | [in] | addr_len | Number of bytes in addr. |  | [out] | iid | The IID based on gnrc_netif_t::device_type |  
 
- Returns
- sizeof(eui64_t)on success.
- 
-ENOTSUP, whendev_typedoes not support IID conversion.
- 
-EINVAL, whenaddr_lenis invalid for thedev_type.
 
 
◆ l2util_ipv6_iid_to_addr()
      
        
          | int l2util_ipv6_iid_to_addr | ( | int | dev_type, | 
        
          |  |  | const eui64_t * | iid, | 
        
          |  |  | uint8_t * | addr ) | 
      
 
Converts an IPv6 IID to a hardware address. 
- Precondition
- iidwas based on a hardware address
- 
The number of bytes available at addris less or equal to L2UTIL_ADDR_MAX_LEN.
- Attention
- When NDEBUGis not defined, the node fails with an assertion instead of returning-ENOTSUP
- Parameters
- 
  
    | [in] | dev_type | The network device type of the device the iidcame from (either because it is based on the configured address of the device or from a packet that came over it). |  | [in] | iid | An IID based on dev_type. |  | [out] | addr | The hardware address. It is assumed that iidwas based on a hardware address and that the available number of bytes inaddrare greater or equal to L2UTIL_ADDR_MAX_LEN. |  
 
- Returns
- Length of resulting addron success.
- 
-ENOTSUP, whendev_typedoes not support reverse IID conversion.
 
 
◆ l2util_ndp_addr_len_from_l2ao()
      
        
          | int l2util_ndp_addr_len_from_l2ao | ( | int | dev_type, | 
        
          |  |  | const ndp_opt_t * | opt ) | 
      
 
Derives the length of the link-layer address in an NDP link-layer address option from that option's length field and the given device type. 
- Note
- If an RFC exists that specifies how IPv6 operates over a link-layer, this function usually implements the section "Unicast Address
         Mapping".
- See also
- RFC 4861, section 4.6.1
- Attention
- When NDEBUGis not defined, the node fails with an assertion instead of returning-ENOTSUP
- Parameters
- 
  
    | [in] | dev_type | The network device type of the device the optcame over in an NDP message. |  | [in] | opt | An NDP source/target link-layer address option. |  
 
- Returns
- Length of the link-layer address in opton success
- 
-ENOTSUP, when implementation does not know how to derive the length of the link-layer address fromopt'slength field based ondev_type.
- 
-EINVALifopt->lenwas an invalid value for the givendev_type.