jacobschaer / python-doipclient

Pure Python ISO 13400 Client
MIT License
155 stars 51 forks source link

DoIPClient.get_entity() with ipv6 #46

Open slycoderr opened 11 months ago

slycoderr commented 11 months ago

On IPv4, we can send the vehicle request identification message to via the broadcast address and we will get a response along with the ECU's IP address. Of course on IPv6, there is no broadcast. Is the only way to get the ECU's IP address on IPv6 is to listen to the vehicle announcement message on ff02::1?

address2, announcement2 = DoIPClient.await_vehicle_announcement(ipv6=True)

I've tried sending the vehicle request identification message(get_entity) on ff02::1, the gateway does not respond at all.

jacobschaer commented 11 months ago

Not sure - I don't recall the details. I would have imagined that you could request it on the link local multicast address analogous to the broadcast on IPv4 but I've mostly deferred to PR's for IPv6 stuff. You could try get_entity() with the LINK_LOCAL_MULTICAST_ADDRESS as the argument and see if it works.

slycoderr commented 11 months ago

2 issues. on client.py line, 218 I get a "[WinError 10049] The requested address is not valid in its context" because we are trying to bind on LINK_LOCAL_MULTICAST_ADDRESS? hardcoded the interface's ipv6 address in there instead and it seemed to like that (not sure if that is the correct way for ipv6).

sock.bind((LINK_LOCAL_MULTICAST_ADDRESS, udp_port))

Second issue, on client.py line 351, ipv6 is always false so we always create an ipv4 socket. I passed true, then I get an exception on client.py 371 "[Errno 11001] getaddrinfo failed". That's after setting the ecu ip address to LINK_LOCAL_MULTICAST_ADDRESS. I'm not sure why its complaining about that, you think you would want to send the message to the multicast group.

sock = cls._create_udp_socket(udp_port=0, timeout=A_DOIP_CTRL)

sock.sendto(data_bytes, (ecu_ip_address, UDP_DISCOVERY))

On a separate note, I was able to send the vehicle request identification message directly to its ipv6 address and it did respond. I stumbled upon something interesting in the ISO documents, I don't know if this pertains to our situation or not (see bold).

"The vehicle discovery process (see 6.2) allows the client DoIP entity to map physical logical addresses to IP addresses. Functional logical addresses are used to address messages to groups of, or all of, the diagnostic application layer entities within a vehicle. As DoIP does not support multicast, for functional adressing in vehicles with multiple DoIP entities the client DoIP entity shall send unicast (point to point) IP packets to each DoIP entity, which is part of the functional address, in order to reach all servers addressed by the functional logical address. There is no mechanism to address multiple DoIP entities via a single IP address. For a DoIP gateway the reception of a functionally addressed diagnostic message implies a multi- or broadcast on the connected in-vehicle sub-networks."