Network Component  Version 7.10.0
MDK Middleware for IPv4 and IPv6 Networking
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
User Callbacks

Functions to notify the user application about events on the Ethernet interface. More...

Functions

void netETH_Notify (uint32_t if_num, netETH_Event event, uint32_t val)
 Notify the user of Ethernet link state change event. [user-provided]. More...
 
void netETH_ReceiveRaw (uint32_t if_num, const uint8_t *buf, uint32_t len)
 Receive raw Ethernet data. [user-provided]. More...
 
void netDHCP_Notify (uint32_t if_num, uint8_t option, const uint8_t *val, uint32_t len)
 Notify the user of DHCP event or extended DHCP option. [user-provided]. More...
 
void netDHCP6_Notify (uint32_t if_num, uint8_t option, const uint8_t *val, uint32_t len)
 Notify the user of DHCPv6 event or extended DHCPv6 option. [user-provided]. More...
 

Description

Functions to notify the user application about events on the Ethernet interface.

An Ethernet link state change is reported by the function netETH_Notify. An interface configuration change is reported by the function netDHCP_Notify for IPv4 and netDHCP6_Notify for IPv6. If you need to monitor the status of your connection, you must implement these functions.

Function Documentation

void netDHCP6_Notify ( uint32_t  if_num,
uint8_t  option,
const uint8_t *  val,
uint32_t  len 
)

Notify the user of DHCPv6 event or extended DHCPv6 option. [user-provided].

Parameters
[in]if_numinterface_number.
[in]optionDHCPv6 option code.
[in]valpointer to option value.
[in]lenlength of option value in bytes.
Returns
none.

The user function netDHCP6_Notify is called by the DHCPv6 client to signal IPv6 address changes or provide information about extended DHCPv6 options. Extended DHCP options are enabled in the Configuration files.

DHCPv6 client notifications require the implementation of the function netDHCP6_Notify in the user code.

The parameter if_num indicates the interface_number.

The parameter option specifies the extended DHCPv6 option code.

The parameter val is a pointer to information provided by the DCHPv6 server replies (see table below).

The parameter len contains the length of the option value in bytes.

The following table shows the various option codes.

Option Code (option) Description val is
NET_DHCP6_OPTION_IP_ADDRESS IP address change event pointer to new dynamic IPv6 address (binary)
Note
  • This function is optional. It is not required for a default DHCPv6 client configuration.
  • The DHCPv6 service is supported only for IPv6 networks.

Code Example

// Process DCHPv6 server information
void netDHCP6_Notify (uint32_t if_num, uint8_t option, const uint8_t *val, uint32_t len) {
char ip_ascii[40];
switch (option) {
case NET_DHCP6_OPTION_IP_ADDRESS: // IPv6 address has changed
netIP_ntoa (NET_ADDR_IP6, &val[0], ip_ascii, sizeof(ip_ascii));
printf ("IP6 address: %s", ip_ascii);
break;
}
}
void netDHCP_Notify ( uint32_t  if_num,
uint8_t  option,
const uint8_t *  val,
uint32_t  len 
)

Notify the user of DHCP event or extended DHCP option. [user-provided].

Parameters
[in]if_numinterface_number.
[in]optionDHCP option code.
[in]valpointer to option value.
[in]lenlength of option value in bytes.
Returns
none.

The user function netDHCP_Notify is called by the DHCP client to signal IP address changes or provide information about extended DHCP options. Extended DHCP options are enabled in the Configuration files and that allow request information such as a boot file name or NTP Server IP addresses.

DHCP client notifications require the implementation of the function netDHCP_Notify in the user code.

The parameter if_num indicates the interface_number.

The parameter option specifies the extended DHCP option code.

The parameter val is a pointer to information provided by the DCHP server replies (see table below).

The parameter len contains the length of the option value in bytes.

The following table shows the various option codes.

Option Code (option) Description val is
NET_DHCP_OPTION_IP_ADDRESS IP address change event pointer to new dynamic IPv4 address (binary)
NET_DHCP_OPTION_NTP_SERVERS IP addresses of NTP Server pointer to list of NTP Server IPv4 addresses (binary)
NET_DHCP_OPTION_BOOTFILE_NAME Boot file name from DHCP server pointer to boot file name (ASCII string)
Note
  • This function is optional. It is not required for a default DHCP client configuration.
  • The DHCP service is supported only for IPv4 networks.

Code Example

// Process DCHP server information
void netDHCP_Notify (uint32_t if_num, uint8_t option, const uint8_t *val, uint32_t len) {
char ip_ascii[16];
uint32_t idx;
switch (option) {
case NET_DHCP_OPTION_IP_ADDRESS: // IP address has changed
netIP_ntoa (NET_ADDR_IP4, &val[0], ip_ascii, sizeof(ip_ascii));
printf ("IP address: %s", ip_ascii);
break;
case NET_DHCP_OPTION_NTP_SERVERS: // List of NTP Server IP addresses
printf ("NTP Server IP address list:\n");
idx = 0;
while ((idx+3) < len) {
netIP_ntoa (NET_ADDR_IP4, &val[idx], ip_ascii, sizeof(ip_ascii));
printf ("IP address: %s", ip_ascii);
idx += 4;
}
break;
case NET_DHCP_OPTION_BOOTFILE_NAME: // DCHP server boot file
printf ("Boot File: %s\n", val);
break;
}
}
void netETH_Notify ( uint32_t  if_num,
netETH_Event  event,
uint32_t  val 
)

Notify the user of Ethernet link state change event. [user-provided].

Parameters
[in]if_numinterface_number.
[in]eventEthernet link state event as defined in netETH_Event.
[in]valpointer to the event value.
Returns
none.

The callback function netETH_Notify polls the link status and notifies the user about state changes.

The argument if_num specifies the Ethernet interface for which the link status has changed.

The argument event specifies link event, as defined in netETH_Event enumeration:

Event Description
netETH_LinkDown Link down
netETH_LinkUp Link up; val=link_info
netETH_Wakeup Wake-up (on Magic Packet)
netETH_TimerAlarm Timer Alarm (PTP)

The argument val stores the value of the link event.

Code Example

void netETH_Notify (uint32_t if_num, netETH_Event event, uint32_t val) {
switch (event) {
printf ("Link is down\n");
break;
printf ("Link is up\n");
info = (NET_ETH_LINK_INFO *)&val;
switch (info->speed) {
case 0:
printf ("10 MBit\n");
break;
case 1:
printf ("100 MBit\n");
break;
case 2:
printf ("1 GBit\n");
break;
}
switch (info->duplex) {
case 0:
printf ("Half duplex\n");
break;
case 1:
printf ("Full duplex\n");
break;
}
break;
printf ("Wakeup frame received\n");
break;
printf ("Timer alarm\n");
break;
}
}
void netETH_ReceiveRaw ( uint32_t  if_num,
const uint8_t *  buf,
uint32_t  len 
)

Receive raw Ethernet data. [user-provided].

Parameters
[in]if_numinterface_number.
[in]bufbuffer containing the received data.
[in]lenlength of received data in bytes.
Returns
none.

The user function netETH_ReceiveRaw is called by the Ethernet interface to provide raw Ethernet frames to the user. The data contains Ethernet header and payload data. This allows the users to implement additional Ethernet protocols, which are not supported by the network library.

The network library calls this function, if the Ethernet Type is not supported. For supported Ethernet Types: ARP (0x0806), IPv4 (0x0800) and IPv6 (0x86dd), the function is not called.

The argument if_num specifies the Ethernet interface which received the frame.

The argument buf points to a buffer containing the received Ethernet frame data.

The argument len specifies the number of received data bytes.

Note
  • This function is optional. It is not required for a default Ethernet interface configuration.

Code Example

void netETH_ReceiveRaw (uint32_t if_num, const uint8_t *buf, uint32_t len) {
uint16_t ether_type;
ether_type = (buf[12] << 8) | buf[13];
if (ether_type == 0x888E) { // EAPoL protocol
// Process the frame here
}
}