This implements some common helper functions for IPv6 over X implementations based on network device types.  
More...
This implements some common helper functions for IPv6 over X implementations based on network device types. 
- 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.  More...
  | 
|   | 
| 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.  More...
  | 
|   | 
| int  | l2util_ipv6_iid_to_addr (int dev_type, const eui64_t *iid, uint8_t *addr) | 
|   | Converts an IPv6 IID to a hardware address.  More...
  | 
|   | 
| 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.  More...
  | 
|   | 
| 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.  More...
  | 
|   | 
| char *  | l2util_addr_to_str (const uint8_t *addr, size_t addr_len, char *out) | 
|   | Converts a hardware address to a human readable string.  More...
  | 
|   | 
| size_t  | l2util_addr_from_str (const char *str, uint8_t *out) | 
|   | Parses a string of colon-separated hexadecimals to a hardware address.  More...
  | 
|   | 
| 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.  More...
  | 
|   | 
◆ 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)  
- 
out MUST 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 
out on 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))  
- 
out MUST have allocated at least 3 * addr_len bytes. 
- 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_len bytes 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 
NDEBUG is not defined, the node fails with an assertion instead returning -ENOTSUP. 
- Parameters
 - 
  
    | [in] | dev_type | The network device type of the device addr came 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, when dev_type does not support EUI-64 conversion.  
- 
-EINVAL, when addr_len is invalid for the dev_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_group for an address for a device of type dev_type (e.g. 6 bytes for an ethernet address). 
- Parameters
 - 
  
    | [in] | dev_type | The network device type of the device l2_addr should be generated for.  | 
    | [in] | ipv6_group | An IPv6 multicast address.  | 
    | [out] | l2_group | A link layer multicast address | 
  
   
- Returns
 - Length of 
l2_group in bytes  
- 
-ENOTSUP if 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 
NDEBUG is not defined, the node fails with an assertion instead returning -ENOTSUP. 
- Parameters
 - 
  
    | [in] | dev_type | The network device type of the device addr came 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, when dev_type does not support IID conversion.  
- 
-EINVAL, when addr_len is invalid for the dev_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
 iid was based on a hardware address  
- 
The number of bytes available at 
addr is less or equal to L2UTIL_ADDR_MAX_LEN. 
- Attention
 - When 
NDEBUG is not defined, the node fails with an assertion instead of returning -ENOTSUP 
- Parameters
 - 
  
    | [in] | dev_type | The network device type of the device the iid came 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 iid was based on a hardware address and that the available number of bytes in addr are greater or equal to L2UTIL_ADDR_MAX_LEN. | 
  
   
- Returns
 - Length of resulting 
addr on success.  
- 
-ENOTSUP, when dev_type does 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 
NDEBUG is not defined, the node fails with an assertion instead of returning -ENOTSUP 
- Parameters
 - 
  
    | [in] | dev_type | The network device type of the device the opt came over in an NDP message.  | 
    | [in] | opt | An NDP source/target link-layer address option. | 
  
   
- Returns
 - Length of the link-layer address in 
opt on success  
- 
-ENOTSUP, when implementation does not know how to derive the length of the link-layer address from opt's length field based on dev_type.  
- 
-EINVAL if opt->len was an invalid value for the given dev_type.