0

This is a beginner's question on networking. I tried to find a solution on the web, but to no success.

Goal: Establish a TCP/IP connection over ethernet directly between my linux host pc and an STM32MP157 board, so I could then send and receive packets using C sockets and simple client/server programs (like these ones).

  • In this question I’m referring to a BeagleBone Black as an extra test case. I assume that whatever I’m missing is relevant to both, but please mind that my goal is to communicate with the STM32MP1 board.

Host PC: Kernel version 5.15.0-117-generic

Details: I conducted some testing, connecting ethernet cable in different situations, and this what comes up:

  1. When I connect my linux host straight to my home router, connection is established, IPv4: 10.100.102.47/24

  2. When I connect the STM32MP1 straight to my home router, connection is established:

root@stm32mp1:~# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: end0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 10:e7:7a:e1:8b:a4 brd ff:ff:ff:ff:ff:ff altname ethernet0 altname ethernet0.ethernet inet 10.100.102.46/24 metric 10 brd 10.100.102.255 scope global dynamic end0 valid_lft 3568sec preferred_lft 3568sec inet6 fe80::12e7:7aff:fee1:8ba4/64 scope link valid_lft forever preferred_lft forever 3: usb0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000 link/ether 7e:8f:a7:2e:04:e5 brd ff:ff:ff:ff:ff:ff root@stm32mp1:~# ping 8.8.8.8 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=7.27 ms 64 bytes from 8.8.8.8: icmp_seq=2 ttl=118 time=6.17 ms 
  1. When I connect the BBB straight to my home router, connection is established:
root@bela:~# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether e0:ff:f1:d8:ee:5d brd ff:ff:ff:ff:ff:ff inet 10.100.102.44/24 brd 10.100.102.255 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::e2ff:f1ff:fed8:ee5d/64 scope link valid_lft forever preferred_lft forever 3: usb0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether be:1a:f1:d8:ee:5f brd ff:ff:ff:ff:ff:ff inet 192.168.6.2/24 brd 192.168.6.255 scope global usb0 valid_lft forever preferred_lft forever inet6 fe80::bc1a:f1ff:fed8:ee5f/64 scope link valid_lft forever preferred_lft forever 4: usb1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether be:1a:f1:d8:ee:62 brd ff:ff:ff:ff:ff:ff inet 192.168.7.2/24 brd 192.168.7.255 scope global usb1 valid_lft forever preferred_lft forever inet6 fe80::bc1a:f1ff:fed8:ee62/64 scope link valid_lft forever preferred_lft forever root@bela:~# ping 8.8.8.8 PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data. 64 bytes from 8.8.8.8: icmp_seq=1 ttl=118 time=6.36 ms 64 bytes from 8.8.8.8: icmp_seq=2 ttl=118 time=5.79 ms 

192.168.6.2/24 and 192.168.7.2/24 are assigned before the connection to the router.

  1. When I connect the STM32MP1 (as well as with the BBB) straight to my linux host PC, connection is not established:
root@stm32mp1:~# [ 65.854953] stm32-dwmac 5800a000.ethernet end0: Link is Up - 1Gbps/Full - flow control rx/tx [ 65.862162] IPv6: ADDRCONF(NETDEV_CHANGE): end0: link becomes ready root@stm32mp1:~# ip addr 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: end0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether 10:e7:7a:e1:8b:a4 brd ff:ff:ff:ff:ff:ff altname ethernet0 altname ethernet0.ethernet inet6 fe80::12e7:7aff:fee1:8ba4/64 scope link valid_lft forever preferred_lft forever 3: usb0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000 link/ether e2:40:83:22:5d:7a brd ff:ff:ff:ff:ff:ff root@stm32mp1:~# 

Issue:

Check #1 shows that my host’s ethernet port is able to function.

Checks #2,3 show that the target boards’ ethernet ports are able to function.

Check #4 shows that connection isn’t established between the host and a target board.

Instead, when connecting the host and the STM32MP1: As long as the cable is plugged in, an error message saying “Connection failed: activation of network connection failed” would pop on the host screen in a periodic fashion.

How can this be solved? Thank you

Additional info: If I connect both the target (eth cable) and the host (wireless) to the router, I manage to communicate over the network. But I need a direct connection between the machine, without the router in the middle.

STM’s guide on how to configure STM32MP1’s ethernet interface suggests:

If a DHCP server is not available, one can set the Ethernet IP address with : Board $> ifconfig end0 uuu.xxx.yyy.zzz 

I did that, but it doesn’t matter because connection is never established with the host.

2 Answers 2

1

Your home router is acting as a DHCP server; it is automatically assigning IP addresses for any system connected to its network segment. Having more than one DHCP server in a single network segment will cause chaos unless the DHCP servers are specifically configured to cooperate with each other, and the DHCP server feature of a normal consumer-grade home router might not be flexible enough for such a configuration.

Your Linux host PC does not currently have a DHCP server set up. In fact, the Linux host is probably currently acting as a DHCP client, getting its IP address automatically from the router, as it is the modern default setting for most IPv4-capable devices.

If you unplug the Linux host from the router and connect it directly to the STM32MP1, the host will detect the loss of connection to the router and will restart the DHCP address request process. But because the STM32MP1 does not have a DHCP server either, that request will time out unanswered; this is the probable cause of the Connection failed: activation of network connection failed error message you mentioned.

So in a nutshell, both the Linux host and the STM32MP1 will be expecting something else (like the router) to assign them IP addresses. When connecting them directly to each other, neither will get an IP address.

The ifconfig command is not persistent in Linux: its effect will be cancelled when the system is rebooted. This is why STM's guide you mentioned says the ifconfig method is quick and temporary. The second method (using systemd) is described as durable because that configuration will persist over a reboot.

For you, the simplest way to solve your problem would be to configure the STM32MP1 to act as a DHCP server: it would have a manually-configured static IP address of its own, and it would give a compatible IP address to any other system connected to it automatically. The chapter 3.5 of the STM guide you linked describes exactly such a configuration.

Step #1: You would have to first disable the DHCP autoconfiguration of the end0 network interface on the STM32MP1:

mv /lib/systemd/network/50-wired.network /lib/systemd/network/50-wired.network.dhcp cp /lib/systemd/network/50-wired.network.static /lib/systemd/network/50-wired.network 

Step #2: Then add the configuration described in chapter 3.5 for the end0 interface to enable the DHCP server function on it:

nano /lib/systemd/network/52-end0-dhcp-server.network #or use your preferred text editor 

Type in the configuration described in chapter 3.5, and save it:

[Match] Name=end0 [Network] Address=192.168.72.1/24 DHCPServer=yes IPForward=ipv4 IPMasquerade=yes 

Step #3: Now disconnect STM32MP1 from the router, reboot the STM32MP1, and connect the Linux host directly to STM32MP1.

The Linux host should now automatically get an IP address of the form 192.168.72.* from the STM32MP1, and the STM32MP1 should be accessible at IP address 192.168.72.1.

The systemd-networkd will read any file with a suffix *.network or *.link in the /lib/systemd/network/ directory, and will ignore any files with any other suffixes like *.static or *.sample or *.dhcp.

In a normal Linux distribution, I'd have recommended writing overriding configuration files to /etc/systemd/network/ directory instead; but since STM's own documentation calls for modifying the configuration under /lib/systemd/, I assume this might be a "bare-bones" embedded system installation, and the corresponding directories under /etc/ might not exist.

For a beginner, it might be advisable to follow STM's documentation for now, until you'll know better; but be aware that configuring as documented by STM will cause your configurations to be rolled back to factory defaults whenever the STM32MP1's OS or its systemd components are upgraded.

2
  • This worked, thank you very much sir. The directory on my board was slightly different than what the guide shows. I had to do just the following: # cp 80-wired.network 80-wired.network.dhcp and edit 80-wired.network with the dhcp server configuration Commented Aug 24, 2024 at 9:28
  • That's OK. Whenever there is a drop-in directory for configuration files like /lib/systemd/network, the common convention is to use the numbers at the beginning of the filenames to ensure the files are processed in an obvious order (i.e. the default alphanumeric sort order). Commented Aug 24, 2024 at 10:00
0

Your question has already been answered here.

In short, you need a DNS and DHCP server in your network to use the TCP/IP protocol. You can use dnsmasq on most Linux distros to let your host PC act as a DNS and DHCP server. (As an aside, Windows 10 has the APIPA protocol, but it requires both devices to run Windows OSes)

If running a server program on your host PC is not viable, I suggest looking at serial communication as an alternative to Ethernet.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.