stm32plus::net Static IP module

The static IP application layer module gives you the option of hard-coding your IP address, subnet mask, default gateway, domain name and DNS servers. In a modern network all these parameters would generally be provided to you by a DHCP server. However, if no such server is available to you then this module lets you hardcode the parameters.

Static IP implementation

The static IP client is configured into your application layer like this:

typedef ApplicationLayer<MyTransportLayer,StaticIpClient> MyApplicationLayer;

This example shows only the static IP module in the application layer. In practice you will probably have more modules configured than just this one.

Configuration parameters

StaticIpClient makes the following configuration parameters available in your network stack’s configuration object:

IpAddress staticip_address;
IpSubnetMask staticip_subnetMask;
IpAddress staticip_defaultGateway;
IpAddress staticip_dnsServers[3];
const char *staticip_domainName;

These parameters should be set by you to the hardcoded values that you have been given by your network administrator. You don’t have to set them all. For example if you only have one DNS server then just set staticip_dnsServers[0] to that value. All the parameters default to ‘not set’ so only set the ones you require.

Events raised by the static IP module

The static IP module raises a number of events that correspond to the values that you have set. The other modules in the stack may subscribe to these events to configure themselves. For example, many modules need to know your IP address and so they will subscribe to the event that announces your IP address.

sender NetworkNotificationEventSender
event IpAddressAnnouncementEvent
identifier NetEventType::IP_ADDRESS_ANNOUNCEMENT
context IRQ
purpose IP address assigned

		/**
		 * Event descriptor that announces a new client IP address
		 */

		struct IpAddressAnnouncementEvent : NetEventDescriptor {

			/**
			 * References to the value
			 */

			const IpAddress& ipAddress;						///< Your IP address


			/**
			 * Constructor
			 */

			IpAddressAnnouncementEvent(const IpAddress& address)
				: NetEventDescriptor(NetEventType::IP_ADDRESS_ANNOUNCEMENT),
					ipAddress(address) {
			}
		};

This event is raised to notify you that an IP address has been assigned. Various modules within the stack subscribe to this event and you can do too if you need to know your IP address.

sender NetworkNotificationEventSender
event IpSubnetMaskAnnouncementEvent
identifier NetEventType::SUBNET_MASK_ANNOUNCEMENT
context IRQ
purpose Subnet mask assigned
		/**
		 * Event descriptor that announces a new subnet mask
		 */

		struct IpSubnetMaskAnnouncementEvent : NetEventDescriptor {

			/**
			 *  Your subnet mask
			 */

			const IpSubnetMask& subnetMask;


			/**
			 * Constructor
			 */

			IpSubnetMaskAnnouncementEvent(const IpSubnetMask& subnetMask)
				: NetEventDescriptor(NetEventType::SUBNET_MASK_ANNOUNCEMENT),
					subnetMask(subnetMask) {
			}
		};

This event is raised to inform you of the subnet mask assigned.

sender NetworkNotificationEventSender
event IpDefaultGatewayAnnouncementEvent
identifier NetEventType::DEFAULT_GATEWAY_ANNOUNCEMENT
context IRQ
purpose Default gateway assigned
		/**
		 * Your default gateway (router)
		 */

		struct IpDefaultGatewayAnnouncementEvent : NetEventDescriptor {

			/**
			 * References to the values
			 */

			const IpAddress& defaultGateway;


			/**
			 * Constructor
			 */

			IpDefaultGatewayAnnouncementEvent(const IpAddress& gateway)
				: NetEventDescriptor(NetEventType::DEFAULT_GATEWAY_ANNOUNCEMENT),
					defaultGateway(gateway) {
			}
		};

This event is raised to inform you of the default gateway that’s been assigned to you. IP packets that do not match your subnet mask are send to the default gateway for forwarding. If you are on a home network then the default gateway is likely to be your home router.

sender NetworkNotificationEventSender
event IpDnsServersAnnouncementEvent
identifier NetEventType::DNS_SERVERS_ANNOUNCEMENT
context IRQ
purpose DNS servers assigned
		/**
		 * Event descriptor that announces a new set of DNS servers (up to 3)
		 */

		struct IpDnsServersAnnouncementEvent : NetEventDescriptor {

			/**
			 * Up to 3 DNS servers, call isValid() to find the end of the set if less than 3
			 */

			const IpAddress *ipDnsServers;


			/**
			 * Constructor
			 */

			IpDnsServersAnnouncementEvent(const IpAddress *dnsServers)
				: NetEventDescriptor(NetEventType::DNS_SERVERS_ANNOUNCEMENT),
					ipDnsServers(dnsServers) {
			}
		};

This event is sent to inform you of that at least one DNS server has been assigned to you. The stm32plus::net DNS module subscribes to this event, as can you if you’re interested in knowing what your DNS server IP addresses are.

Up to three IP addresses are held in the array pointed to by the ipDnsServers pointer. At least one will be valid. Call the ipAddress.isValid() member on each of the three to discover if it points to a valid address.