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 creates the number of GOAL_CONFIG_NET_CHAN_MAX
net channels during initialization automatically for this purpose. Each net channel can be opened as one of the following network connection types:
GOAL_NET_UDP_SERVER
GOAL_NET_UDP_CLIENT
GOAL_NET_TCP_LISTENER represents the TCP server
GOAL_NET_TCP_CLIENT
The connection between the net channels and the TCP/IP stack is addressed by the local IP address, local netmask and local gateway address. The connection between the TCP/IP Stack to a remote Ethernet device is addressed by the remote IP address, the remote netmask and remote gateway address. The rules for the determination of the local address are shown in Figure 16. The local address is determined during creation of the net channels in the state GOAL_FSA_INIT
automatically. The remote address is configured by calling the function goal_netOpen()
.
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_netActivate()
.
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_netSetOption()
. The availability and the default setting of the options depends on the TCP/IP stack.
GOAL files:
goal_net.[h,c], goal_net_dhcp.[h,c], goal_net_cli.c
example:
…\goal\appl\00410_goal\tcp_client
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_NET_CHAN_MAX:
number of network channels (default: 4)
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:
|
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:
|
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:
|
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 | void cbNetFunc(GOAL_NET_CB_TYPE_T cbType, struct GOAL_NET_CHAN_T *pChan, struct GOAL_BUFFER_T *pBuf) | |
Description | This callback function is used for the following operations:
| |
Parameters | cbType | type of operation:
|
pChan | handle of the network channel | |
pBuf | for GOAL_NET_CB_NEW_DATA: buffer with the received data | |
Return values | none | |
Category | optional | |
Registration | during runtime via function goal_netOpen() |
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 | The number of failures detected by the IP reassembly algorithm. Note that this is not necessarily a count of discarded IP fragments since some algorithms can lose track of the number of fragments by combining them as they are received. |
10 | GOAL_NET_IP_STATS_IPFRAGOKS | The number of IP datagrams that have been successfully fragmented at this entity. |
11 | GOAL_NET_IP_STATS_IPFRAGFAILS | The number of IP datagrams that have been discarded because they needed to be fragmented at this entity but could not be. |
12 | GOAL_NET_IP_STATS_IPFRAGCREATES | The number of IP datagram fragments that have been generated as a result of fragmentation at this entity. |
13 | GOAL_NET_IP_STATS_IPREASMREQGDS | The number of IP fragments received which needed to be reassembled at this entity. |
14 | GOAL_NET_IP_STATS_IPFORWDATAGRAMS | The number of input datagrams for which this entity was not their final IP destination, as a result of which an attempt was made to find a route to forward them to that final destination. In entities which do not act as IP gateways, this counter will include only those packets which were source-routed via this entity, and the source-route option processing was successful. |
15 | GOAL_NET_IP_STATS_IPINRECEIVES | The total number of input datagrams received from interfaces, including those received in error. |
16 | GOAL_NET_IP_STATS_TCPACTIVEOPENS | The number of times TCP connections have made a direct transition from the CLOSED state to the SYN-SENT state. |
17 | GOAL_NET_IP_STATS_TCPPASSIVEOPENS | The number of times TCP connections have made a direct transition from the LISTEN state to the SYN-RCVD state. |
18 | GOAL_NET_IP_STATS_TCPATTEMPTFAILS | The number of times TCP connections have made a direct transition from either the SYN-SENT or SYN-RCVD state to the CLOSED state, plus the number of times TCP connections have made a direct transition from the SYN-RCVD state to the LISTEN state. |
19 | GOAL_NET_IP_STATS_TCPESTABRESETS | The number of times TCP connections have made a direct transition from either the ESTABLISHED or CLOSE-WAIT state to the CLOSE state. |
20 | GOAL_NET_IP_STATS_TCPOUTSEGS | The total number of segments sent, including those on current connections but excluding those containing only retransmitted octets. |
21 | GOAL_NET_IP_STATS_TCPRETRANSSEGS | The total number of segments retransmitted. That is the number of TCP segments transmitted containing one or more previously transmitted. |
22 | GOAL_NET_IP_STATS_TCPINSEGS | The total number of segments received, including those received in error. This count includes segments received on currently established connections. |
23 | GOAL_NET_IP_STATS_TCPINERRS | The total number of segments received in error. |
24 | GOAL_NET_IP_STATS_TCPOUTRSTS | The number of TCP segments sent containing the RST flag. |
25 | GOAL_NET_IP_STATS_UDPINDATAGRAMS | The total number of UDP datagrams delivered to UDP user. |
26 | GOAL_NET_IP_STATS_UDPNOPORTS | The total number of received UDP datagrams for which there was no application at the destination port. |
27 | GOAL_NET_IP_STATS_UDPINERRORS | The number of received UDP datagrams that could not be delivered for reasons other than the lack of an application at the destination port. |
28 | GOAL_NET_IP_STATS_UDPOUTDATAGRAMS | The total number of UDP datagrams sent from this entity. |
29 | GOAL_NET_IP_STATS_ICMPINMSGS | The total number of ICMP messages which the entity received. Note that this counter includes all those counted by 30/ GOAL_NET_IP_STATS_ICMPINERRORS. |
30 | GOAL_NET_IP_STATS_ICMPINERRORS | The number of ICMP messages which the entity received but determined as having ICMP-specific errors. |
31 | GOAL_NET_IP_STATS_ICMPINDESTUNREACHS | The number of ICMP Destination Unreachable messages received. |
32 | GOAL_NET_IP_STATS_ICMPINTIMEEXDS | The number of ICMP Time Exceeded messages received. |
33 | GOAL_NET_IP_STATS_ICMPINPARMPROBS | The number of ICMP Parameter Problem messages received. |
34 | GOAL_NET_IP_STATS_ICMPINSRCQUENCHS | The number of ICMP Source Quench messages received. |
35 | GOAL_NET_IP_STATS_ICMPINREDIRECTS | The number of ICMP Redirect messages received. |
36 | GOAL_NET_IP_STATS_ICMPINECHOS | The number of ICMP Echo (request) messages received. |
37 | GOAL_NET_IP_STATS_ICMPINECHOREPS | The number of ICMP Echo Reply messages received. |
38 | GOAL_NET_IP_STATS_ICMPINTIMESTAMPS | The number of ICMP Timestamp (request) messages received. |
39 | GOAL_NET_IP_STATS_ICMPINTIMESTAMPREPS | The number of ICMP Timestamp Reply messages received. |
40 | GOAL_NET_IP_STATS_ICMPINADDRMASKS | The number of ICMP Address Mask Request messages received. |
41 | GOAL_NET_IP_STATS_ICMPINADDRMASKREPS | The number of ICMP Address Mask Reply messages received. |
42 | GOAL_NET_IP_STATS_ICMPOUTMSGS | The total number of ICMP messages which this entity attempted to send. Note that this counter includes all those counted by 43/ GOAL_NET_IP_STATS_ICMPOUTERRORS. |
43 | GOAL_NET_IP_STATS_ICMPOUTERRORS | The number of ICMP messages which this entity did not send due to problems discovered within ICMP such as a lack of buffers. This value should not include errors discovered outside the ICMP layer such as the inability of IP zo route the resultant datagram. In some implementations there may be no types of error which contribute to this counter's value. |
44 | GOAL_NET_IP_STATS_ICMPOUTDESTUNREACHS | The number of ICMP Destination Unreachable message sent. |
45 | GOAL_NET_IP_STATS_ICMPOUTTIMEEXCDS | The number of ICMP Time Exceeded messages sent. |
46 | GOAL_NET_IP_STATS_ICMPOUTECHOS | The number of ICMP Echo (request) messages sent. |
47 | GOAL_NET_IP_STATS_ICMPOUTECHOREPS | The number of TCMP Echo Reply messages sent. |
48 | GOAL_NET_IP_STATS_IFINOCTETS | The total number of octets received on the interface, including framing characters. |
49 | GOAL_NET_IP_STATS_IFINUCASTPKTS | The number of subnetwork-unicast packets delivered to a higher-layer protocol. |
50 | GOAL_NET_IP_STATS_IFINNUCASTPKTS | The number of non-unicast packets delivered to a higher-layer protocol. |
51 | GOAL_NET_IP_STATS_IFINDISCARDS | The number of inbound packet which were chosen to be discarded even though no errors had been detected to prevent their being deliverable to a higher-layer protocol. |
52 | GOAL_NET_IP_STATS_IFINERRORS | The number of inbound packets that contained errors preventing them from being deliverable to a higher-layer protocol. |
53 | GOAL_NET_IP_STATS_IFINUNKNOWNPROTOS | The number of packets received via the interface which were discarded because of an unknown or unsupported protocol. |
54 | GOAL_NET_IP_STATS_IFOUTOCTETS | The total number of octets transmitted out of the interface, including framing characters. |
55 | GOAL_NET_IP_STATS_IFOUTUCASTPKTS |