Network handling

Network handling


This GOAL core module provides an interface to the application for TCP/IP connections, see Figure 15. A TCP/IP stack is required. The TCP/IP stack must be enabled by the compiler-define GOAL_CONFIG_TCPIP_STACK = 1.

 

Figure: topology for net channels


GOAL supports the following types of Net Channels:

  • GOAL_NET_UDP_SERVER

  • GOAL_NET_UDP_CLIENT

  • GOAL_NET_TCP_LISTENER (TCP server)

  • GOAL_NET_TCP_CLIENT

Both the local device and the remote devices are respresented by their respective IP address, netmask and gateway address. The devices’s IP address is determined in the function goal_miNetOpen(). It can be changed via the function goal_netIpSet(). The rules for determining the local address are shown in Figure 16. The remote address is configured when a net channel is opened by the function goal_netChanOpen().

Figure: determination of the local address of net channels

 

The connection to the application is realized by a callback function, see Chapter: Callback functions. Each net channel must be activated before data can be transmitted or received via the net channel. The activation is done by function goal_netChanActivate().
The following options are available to configure the TCP/IP stack:

  • GOAL_NET_OPTION_NONBLOCK: socket connection between net channel and TCP/IP stack is

    • 0: blocking

    • 1: non-blocking

  • GOAL_NET_OPTION_BROADCAST:

    • 0: no broadcast reception

    • 1: broadcast reception supported

  • GOAL_NET_OPTION_TTL:

    • set TTL value in IP-header

  • GOAL_NET_OPTION_TOS:

    • set TOS-value in IP-header

  • GOAL_NET_OPTION_MCAST_ADD:

    • enable the specified multicast address for the receipt of multicast packets

  • GOAL_NET_OPTION_MCAST_DROP:

    • disable the specified multicast address for the receipt of multicast packets

  • GOAL_NET_OPTION_REUSEADDR:

    • 0: TCP/IP socket shall be not reusable

    • 1: TCP/IP socket shall be reusable

The options can be can be changed by function goal_netChanOptionSet(). The availability and the default setting of the options depends on the TCP/IP stack.

  • GOAL files:

    • goal_net.[h,c], goal_net_chan.[h,c],goal_net_dhcp.[h,c], goal_net_cli.c

  • example:

    • …\goal\appl\00410_goal\tcp_client

    • …\goal\appl\00410_goal\tcp_server

    • …\goal\appl\00410_goal\udp_send

Configuration

Compiler-defines


The following compiler-defines are available to configure the network handling:

  • GOAL_CONFIG_TCPIP_STACK:

    • 0: network handling is disabled (default)

    • 1: network handling is enabled

  • GOAL_CONFIG_DHCP:

    • 0: static assignment of IP-addresses (default)

    • 1: dynamic assignment of IP-addresses via DHCP

  • GOAL_CONFIG_IP_STATS:

    • 0: output of IP-statistics switched off (default)

    • 1: output of IP-statistics switched on

CM-variables


The following CM-variables are available to configure the network handling:

Table: NET_CM_VAR_IP

CM-Module-ID

GOAL_ID_NET

CM-variable-ID

0

CM-variable name

NET_CM_VAR_IP

Description

IP address of first interface

CM data type

GOAL_CM_IPV4

Size

4 bytes

Default value

from NVS or 0

 

Table: NET_CM_VAR_ NETMASK

CM-Module-ID

GOAL_ID_NET

CM-variable-ID

1

CM-variable name

NET_CM_VAR_ NETMASK

Description

netmask of first interface

CM data type

GOAL_CM_IPV4

Size

4 bytes

Default value

from NVS or 0

 

Table: NET_CM_VAR_ GW

CM-Module-ID

GOAL_ID_NET

CM-variable-ID

2

CM-variable name

NET_CM_VAR_ GW

Description

gateway of first interface

CM data type

GOAL_CM_IPV4

Size

4 bytes

Default value

from NVS or 0

 

Table: NET_CM_VAR_ COMMIT

CM-Module-ID

GOAL_ID_NET

CM-variable-ID

3

CM-variable name

NET_CM_VAR_ COMMIT

Description

Write any value to this CM-variable applies the IP settings

CM data type

GOAL_CM_UINT8

Size

1 byte

Default value

from NVS or 0

 

Table: NET_CM_VAR_ VALID

CM-Module-ID

GOAL_ID_NET

CM-variable-ID

4

CM-variable name

NET_CM_VAR_ VALID

Description

validity of IP address:

  • 0: stored IP address is not valid, interface settings originate from network stack of system

  • 1: stored IP address is valid, will be applied to interface at start of device

CM data type

GOAL_CM_UINT8

Size

1 byte

Default value

from NVS or 0

 

Table: NET_CM_VAR_ DHCP_ENABLED

CM-Module-ID

GOAL_ID_NET

CM-variable-ID

5

CM-variable name

NET_CM_VAR_ DHCP_ENABLED

Description

CM-variable to disable/enable DHCP:

  • 0: DHCP disabled

  • 1: DHCP enabled

CM data type

GOAL_CM_UINT8

Size

1 byte

Default value

from NVS or 0

 

Table: NET_CM_VAR_ DHCP_STATE

CM-Module-ID

GOAL_ID_NET

CM-variable-ID

6

CM-variable name

NET_CM_VAR_ DHCP_STATE

Description

CM-variable to indicate the current state of DHCP if DHCP is enabled:

  • 0: DHCP initialized

  • 1: DHCP selecting server

  • 2: DHCP requesting configuration

  • 3: DHCP IP address bound

  • 4: DHCP renewing configuration

  • 5: DHCP rebinding IP address to interface

CM data type

GOAL_CM_UINT8

Size

1 byte

Default value

from NVS or 0

 

Table: NET_CM_VAR_ DNS0

CM-Module-ID

GOAL_ID_NET

CM-variable-ID

7

CM-variable name

NET_CM_VAR_ DNS0

Description

first DNS server of the first interface

CM data type

GOAL_CM_IPV4

Size

4 bytes

Default value

from NVS or 0

 

Table: NET_CM_VAR_ DNS1

CM-Module-ID

GOAL_ID_NET

CM-variable-ID

8

CM-variable name

NET_CM_VAR_ DNS1

Description

second DNS server of the first interface

CM data type

GOAL_CM_IPV4

Size

4 bytes

Default value

from NVS or 0

 

Table: NET_CM_VAR_ HOSTNAME

CM-Module-ID

GOAL_ID_NET

CM-variable-ID

9

CM-variable name

NET_CM_VAR_ HOSTNAME

Description

host name of the first interface

CM data type

GOAL_CM_STRING

Size

20 bytes

Default value

from NVS or 0

Callback functions


The user of this module can specify the following callback function for each network channel:

Table: Callback function cbNetFunc()

Prototype

GOAL_STATUS_T appl_netCallback(
void *pArg, /< callback argument */
GOAL_NET_CB_TYPE_T cbType, /< callback type */
struct GOAL_NET_CHAN_T *pChan, /< channel descriptor */
struct GOAL_BUFFER_T *pBuf /< GOAL buffer */
);

Description

This callback function is used for the following operations:

  • GOAL_NET_CB_NEW_DATA: to transfer received data to the application

  • GOAL_NET_CB_NEW_SOCKET: to inform the application, that a new connection of a net channel to the TCP/IP stack was opened

  • GOAL_NET_CB_CONNECTED: to inform the application, that the net channel was activated

  • GOAL_NET_CB_CLOSING: to inform the application, that the net channel was closed

Parameters

pArg

arbitrary callback data set via goal_netChanOpen()

 

cbType

type of operation:

  • GOAL_NET_CB_NEW_DATA,

  • GOAL_NET_CB_NEW_SOCKET,

  • GOAL_NET_CB_CONNECTED,

  • GOAL_NET_CB_CLOSING



pChan

handle of the network channel



pBuf

for GOAL_NET_CB_NEW_DATA: buffer with the received data
else: NUL

Return values

none

Category

optional
If a callback function is not available, specify NULL in the call of goal_netOpen().

Registration

during runtime via function goal_netChanOpen()

IP statistics


GOAL provides the possibility to analyze communication problems by IP statistics. The supported IP statistics bases on /RFC_1213/ and depend on the platform. GOAL provides the following typical IP statistics:

Table: provided IP statistic by GOAL

GOAL number of IP statistic



Description /RFC_1213/

Number

Identifier (object type)

0

GOAL_NET_IP_STATS_IPINHDRERRORS

The number of input datagrams discarded due to errors in their IP headers, including bad checksums, version number mismatch, other format errors, time-to-live exceeded, errors discovered in processing their IP options, etc.

1

GOAL_NET_IP_STATS_IPINADDRERRORS

The number of input datagrams discarded because the IP address in their IP headers destination field was not a valid address to be received at this entity. This count includes invalid addresses and addresses of unsupported classes. For entities which are not IP gateways and therefore do not forward datagrams, this counter includes datagrams discarded because the destination address was not a local address.

2

GOAL_NET_IP_STATS_IPINUNKNOWNPROTOS

The number of locally-addressed datagrams received successfully but discarded because of an unknown or unsupported protocol.

3

GOAL_NET_IP_STATS_IPINDISCARDS

The number of input IP datagrams for which no problems were encountered to prevent their continued processing, but which were discarded. Note that this counter does not include any datagrams discarded while awaiting re-assembly.

4

GOAL_NET_IP_STATS_IPINDELIVERS

The total number of input datagrams successfully delivered to IP user-protocols (including ICMP).

5

GOAL_NET_IP_STATS_IPOUTREQUESTS

The total number of IP datagrams which local IP user-protocols (including ICMP) supplied to IP in requests for transmission. Note that this counter does not include any datagrams counted in 14/GOAL_NET_IP_STATS_IPFORWDATAGRAMS.

6

GOAL_NET_IP_STATS_IPOUTDISCARDS

The number of output IP datagrams for which no problem was encountered to prevent their transmission to their destination, but which were discarded. Note that this counter would include datagrams counted in 14/GOAL_NET_IP_STATS_IPFORWDATAGRAMS if any such packets met this discard criterion.

7

GOAL_NET_IP_STATS_IPOUTNOROUTES

The number of IP datagrams discarded because no route could be found to transmit them to their destination. Note that this counter includes any packets counted in 14/GOAL_NET_IP_STATS_IPFORWDATAGRAMS which meet this "no-route" criterion. Note that this includes any datagram which a host cannot route because all of its default gateways are down.

8

GOAL_NET_IP_STATS_IPREASMOKS

The number of IP datagrams successfully reassembled.

9

GOAL_NET_IP_STATS_IPREASMFAILS