Network Configuration
Non-Volatile Memory
The basic network configuration is typically stored in non-volatile memory, using the packed CONFNET structure located at byte offset 64.
<source lang="c"> typedef struct {
uint8_t cd_size; char cd_name[9]; uint8_t cdn_mac[6]; uint32_t cdn_ip_addr; uint32_t cdn_ip_mask; uint32_t cdn_gateway; uint32_t cdn_cip_addr;
} CONFNET; </source>
Applications need not to deal with these settings, they are automatically loaded by the network setup functions. If required, applications may however access the global variable
<source lang="c">CONFNET confnet;</source>
which is defined in the header file sys/confnet.h.
Furthermore, the functions NutNetLoadConfig() and NutNetSaveConfig() are available to load and save the global confnet structure.
Depending on your target hardware, there may be preferred ways to set the network configuration.
AVR based boards
For Ethernut 1 and Ethernut 2 and similar boards you can also use Basemon to modify the network configuration, which is stored in the internal EEPROM of the ATmega128. Check the related hardware pages
Note, that the Basemon binary will work on most AVR boards, so you don't need to compile a specifically configured version.
Ethernut 3
For Ethernut 3 the bootmon bootloader can be used to modify the network configuration. While the values are stored in EEPROM on Ethernut 3.0, the DataFlash is used on Ethernut 3.1.
API
Over the years a somewhat weird collection of API calls had developed.
Function | Description |
---|---|
NutDhcpIfConfig | This function will fit for most cases.
If no MAC address is specified, this routine will try to read a previously stored configuration from the EEPROM. If this retrieves a fixed IP configuration, then the network interface will be immediately configured with these values by calling NutNetIfConfig(). If no valid IP configuration has been read, then this routine will start the DHCP client thread and wait upto a given number of milliseconds for an acknowledged configuration from a DHCP server. If a MAC address has been specified, this routine will not read the EEPROM configuration. If the application has set the global CONFNET structure to a valid IP configuration before calling this function, then the network interface will be immediately configured with these values by calling NutNetIfConfig(). Otherwise the DHCP client thread will be started and this routine will wait upto a given number of milliseconds for an acknowledged configuration from a DHCP server. |
NutNetIfConfig | Internally calls NutNetIfSetup(). |
NutNetIfConfig2 | Similar to NutNetIfConfig(), but additionally allows to configure the default gateway address. |
NutNetIfSetup | Sets basic IP configuration, local address, net mask and default gate. Internally calls NutNetSaveConfig() to saves the configuration in non-volatile memory. |
NutIpRouteAdd | Used to add an entry to the routing table. Default, net and host routes are accepted. |
NutNetLoadConfig | Loads global confnet variable from non-volatile memory. |
NutNetSaveConfig | Stores global confnet variable in non-volatile memory, so it will be available after the next reboot. |
See also
- Nut/OS software manual, contains additional information about the network configuration.
- Non-Volatile Memory explains how applications can use persistent storage.
- Network Configuration Using Hard Coded Configuration, the most basic way to get you up and running.
- Network Configuration Using Stored Configuration
- Network Configuration Using a Configuration Editor, which may serve as a template for your advanced applications.
- Discovery Service, enables users to detect and remotely configure network settings by using a simple GUI tool.