Network Component
Version 6.3
MDK-Professional Middleware for IP Networking
|
Ethernet routines enable communication over an Ethernet-based IP network. More...
Typedefs | |
typedef void(* | net_icmp_cb_t )(icmpEvent event) |
ICMP Event callback function. | |
Enumerations | |
enum | arpCacheType { arpCacheFixedIP, arpCacheTemporaryIP } |
ARP Cache Entry types. More... | |
enum | icmpEvent { icmpEventSuccess = 0, icmpEventTimeout } |
ICMP (ping) Callback Events. More... | |
enum | ethLinkEvent { ethLinkDown = 0, ethLinkUp_10MHalfDuplex, ethLinkUp_10MFullDuplex, ethLinkUp_100MHalfDuplex, ethLinkUp_100MFullDuplex, ethLinkUp_1GHalfDuplex, ethLinkUp_1GFullDuplex } |
Ethernet Link Callback Events. More... | |
enum | dhcpClientOption { dhcpClientIPaddress = 0, dhcpClientNTPservers = 42, dhcpClientBootfileName = 67 } |
DHCP Client Callback Events. More... | |
Functions | |
netStatus | arp_cache_ip (uint32_t if_num, const uint8_t *ip_addr, arpCacheType type) |
Determine whether the ARP table has MAC address resolved for requested IP address. | |
netStatus | arp_cache_mac (uint32_t if_num, const uint8_t *mac_addr) |
Determine whether the ARP table has IP address resolved for requested MAC address. | |
netStatus | arp_get_ip (const uint8_t *mac_addr, uint8_t *ip_addr) |
Get IP address from the ARP cache. | |
netStatus | arp_get_mac (const uint8_t *ip_addr, uint8_t *mac_addr) |
Get MAC address from the ARP cache. | |
netStatus | dhcp_disable (uint32_t if_num) |
Disable Dynamic Host Configuration at runtime. | |
void | eth_link_notify (uint32_t if_num, ethLinkEvent event) |
Notify the user of Ethernet link state change event. | |
void | dhcp_client_notify (uint32_t if_num, dhcpClientOption opt, const uint8_t *val, uint32_t len) |
Notify the user of DHCP event or extended DHCP option. | |
netStatus | icmp_ping (const uint8_t *ip_addr, net_icmp_cb_t cb_func) |
Start ICMP ping process. | |
Ethernet routines enable communication over an Ethernet-based IP network.
Ethernet is a networking technology for local area networks (LANs). Ethernet is standardized as IEEE 802.3. Ethernet is today the de-facto standard for wired LAN technologies. Although the Ethernet standards comprise several wiring and signalling variants (such as coaxial cables), today most systems use twisted pair and fibre optic links in conjunction with hubs or switches. Microcontroller devices support typically data rates between 10 and 100 megabits per second..
Systems communicating over Ethernet divide a stream of data into shorter pieces called frames. Each frame contains source and destination addresses and error-checking data so that damaged data can be detected and re-transmitted.
Computers communicating via Ethernet (stations) are sending each other data packets in short pieces called frames: blocks of data are exchanged individually. Each station is given a unique 48-bit MAC address. The MAC addresses are used to identify the destination and the source of every data packet. Ethernet establishes link level connections, which can be defined using both the destination and source IP addresses. After reception, the receiving station uses the destination address to determine whether the transmission is relevant or should be ignored. Normally, packets addressed to other Ethernet stations are ignored. All generations of Ethernet are using the same frame formats, so that they can be readily interconnected through bridging.
void(* net_icmp_cb_t)(icmpEvent event) |
ICMP Event callback function.
[in] | event | - ICMP event as defined in icmpEvent. |
Is the type definition for the ICMP callback function. Users must provide the function. The callback function uses the event argument to signal one of the following ICMP events:
Event | Description |
---|---|
icmpEventSuccess | Remote host responded to ping. |
icmpEventTimeout | Ping session has timed out, remote host did not respond. |
Parameter for:
enum arpCacheType |
ARP Cache Entry types.
Parameter for:
enum dhcpClientOption |
DHCP Client Callback Events.
Option | Event | Description |
---|---|---|
0 | dhcpClientIPaddress | IP address change event. |
42 | dhcpClientNTPservers | NTP Servers option. |
67 | dhcpClientBootfileName | Bootfile name option. |
Parameter for:
enum ethLinkEvent |
Ethernet Link Callback Events.
Parameter for:
enum icmpEvent |
ICMP (ping) Callback Events.
Parameter for:
netStatus arp_cache_ip | ( | uint32_t | if_num, |
const uint8_t * | ip_addr, | ||
arpCacheType | type | ||
) |
Determine whether the ARP table has MAC address resolved for requested IP address.
[in] | if_num | interface number. |
[in] | ip_addr | requested IP address. |
[in] | type | address cache type |
The function arp_cache_ip determines whether the ARP table has a MAC (Ethernet) address entry for the requested IP address. If an entry does not exist, the function forces the Network Core to resolve and cache the MAC address into the internal ARP table buffer. To resolve the MAC address, the Network Core sends an ARP request to the network.
The argument if_num is the Ethernet interface number for which to check the ARP table.
The argument ip_addr points to a buffer containing the four octets of the dotted decimal IP address to be resolved.
The argument type specifies whether the IP address is fixed or temporary. This consequently determines whether or not the Network Core automatically refreshes the IP address entry in the ARP cache.
Type | Description |
---|---|
arpCacheTemporaryIP | The IP address is temporary, and thus Network removes the IP address entry from the ARP cache after a timeout. |
arpCacheFixedIP | The IP address is fixed, and thus Network's ARP module automatically refreshes the IP address entry after the timeout. |
Code Example
netStatus arp_cache_mac | ( | uint32_t | if_num, |
const uint8_t * | mac_addr | ||
) |
Determine whether the ARP table has IP address resolved for requested MAC address.
[in] | if_num | interface number. |
[in] | mac_addr | requested MAC address. |
The function arp_cache_mac determines whether the ARP table has an IP address entry for the requested MAC (Ethernet) address mac_addr. If an entry does not exist, the function forces the Network Core to resolve and cache the IP address into the internal ARP table buffer. To resolve the IP address, the Network Core sends an inverse ARP request to the network.
The argument if_num is the Ethernet interface number for which to check the ARP table.
The argument mac_addr points to a buffer containing the six octets of the MAC address to be resolved.
Code Example
netStatus arp_get_ip | ( | const uint8_t * | mac_addr, |
uint8_t * | ip_addr | ||
) |
Get IP address from the ARP cache.
[in] | mac_addr | requested MAC address. |
[out] | ip_addr | resolved IP address. |
The function arp_get_ip determines the resolved IP address for a specific MAC address.
The argument mac_addr points to a buffer containing the six octets of the MAC address to be resolved.
The out argument ip_addr points to a buffer containing the resolved IP address.
Refer to
Code Example
netStatus arp_get_mac | ( | const uint8_t * | ip_addr, |
uint8_t * | mac_addr | ||
) |
Get MAC address from the ARP cache.
[in] | ip_addr | requested IP address. |
[out] | mac_addr | resolved MAC address. |
The function arp_get_mac determines the resolved MAC address for a specific IP address.
The argument ip_addr points to a buffer containing the IP address.
The out argument mac_addr points to a buffer containing the resolved six octets of the MAC address.
Refer to
Code Example
void dhcp_client_notify | ( | uint32_t | if_num, |
dhcpClientOption | opt, | ||
const uint8_t * | val, | ||
uint32_t | len | ||
) |
Notify the user of DHCP event or extended DHCP option.
[in] | if_num | interface number. |
[in] | opt | DHCP option as defined in dhcpClientOption. |
[in] | val | pointer to the option value. |
[in] | len | length of the option value in bytes. |
The function dhcp_client_notify is called by the DHCP client when the extended DHCP options are enabled in the system configuration. This function is used to notify the user about extended DHCP option values. If this function is not provided in the user code, DHCP client notifications are not possible.
The argument if_num specifies the Ethernet interface for which DHCP is to be used.
The argument opt specifies the extended DHCP option code, as defined in dhcpClientOption enum:
Option | Event | Description |
---|---|---|
0 | dhcpClientIPaddress | IP address change event. |
42 | dhcpClientNTPservers | Pointer to an array of NTP Server IP addresses. |
67 | dhcpClientBootfileName | Pointer to a 0-terminated boot file name. |
The argument val is a pointer to the option value.
The argument len is specifying the length of the option value in bytes.
Code Example
netStatus dhcp_disable | ( | uint32_t | if_num | ) |
Disable Dynamic Host Configuration at runtime.
[in] | if_num | interface number. |
The function dhcp_disable permanently disables the Dynamic Host Configuration at runtime. To enable the DHCP client again, you must restart the system.
The argument if_num specifies the Ethernet interface for which DHCP is to be disabled.
Code Example
void eth_link_notify | ( | uint32_t | if_num, |
ethLinkEvent | event | ||
) |
Notify the user of Ethernet link state change event.
[in] | if_num | interface number. |
[in] | event | Ethernet link state event as defined in ethLinkEvent. |
The function eth_link_notify polls the PHY status and notifies the user about link state changes.
The argument if_num specifies the Ethernet interface for which is to be checked.
The argument event specifies link event, as defined in ethLinkEvent enum:
Event | Description |
---|---|
ethLinkDown | Link down. |
ethLinkUp_10MHalfDuplex | Link up (10 MBit half duplex). |
ethLinkUp_10MFullDuplex | Link up (10 MBit full duplex). |
ethLinkUp_100MHalfDuplex | Link up (100 MBit half duplex). |
ethLinkUp_100MFullDuplex | Link up (100 MBit full duplex). |
ethLinkUp_1GHalfDuplex | Link up (1 GBit half duplex). |
ethLinkUp_1GFullDuplex | Link up (1 GBit full duplex). |
netStatus icmp_ping | ( | const uint8_t * | ip_addr, |
net_icmp_cb_t | cb_func | ||
) |
Start ICMP ping process.
[in] | ip_addr | IP address of the remote host. |
[in] | cb_func | callback function to call, when ping session ends. |
The function icmp_ping starts the ICMP ping process on the Network Core. This causes the ICMP client to send the ICMP Echo request to remote IP address and waits for an ICMP Echo reply.
The argument ip_addr points to an array of 4 bytes containing the dotted-decimal notation of the IP address of the remote host to be pinged.
The argument cb_func points to an event callback function called by the ICMP client (running on Network Core) when the ping session ends. Refer to net_icmp_cb_t.
Code Example