Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

can: j1939: do not wait 250 ms if the same addr was already claimed

The ISO 11783-5 standard, in "4.5.2 - Address claim requirements", states:
d) No CF shall begin, or resume, transmission on the network until 250
ms after it has successfully claimed an address except when
responding to a request for address-claimed.

But "Figure 6" and "Figure 7" in "4.5.4.2 - Address-claim
prioritization" show that the CF begins the transmission after 250 ms
from the first AC (address-claimed) message even if it sends another AC
message during that time window to resolve the address contention with
another CF.

As stated in "4.4.2.3 - Address-claimed message":
In order to successfully claim an address, the CF sending an address
claimed message shall not receive a contending claim from another CF
for at least 250 ms.

As stated in "4.4.3.2 - NAME management (NM) message":
1) A commanding CF can
d) request that a CF with a specified NAME transmit the address-
claimed message with its current NAME.
2) A target CF shall
d) send an address-claimed message in response to a request for a
matching NAME

Taking the above arguments into account, the 250 ms wait is requested
only during network initialization.

Do not restart the timer on AC message if both the NAME and the address
match and so if the address has already been claimed (timer has expired)
or the AC message has been sent to resolve the contention with another
CF (timer is still running).

Signed-off-by: Devid Antonio Filoni <devid.filoni@egluetechnologies.com>
Acked-by: Oleksij Rempel <o.rempel@pengutronix.de>
Link: https://lore.kernel.org/all/20221125170418.34575-1-devid.filoni@egluetechnologies.com
Fixes: 9d71dd0c7009 ("can: add support of SAE J1939 protocol")
Cc: stable@vger.kernel.org
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>

authored by

Devid Antonio Filoni and committed by
Marc Kleine-Budde
4ae5e1e9 811d5811

+40
+40
net/can/j1939/address-claim.c
··· 165 165 * leaving this function. 166 166 */ 167 167 ecu = j1939_ecu_get_by_name_locked(priv, name); 168 + 169 + if (ecu && ecu->addr == skcb->addr.sa) { 170 + /* The ISO 11783-5 standard, in "4.5.2 - Address claim 171 + * requirements", states: 172 + * d) No CF shall begin, or resume, transmission on the 173 + * network until 250 ms after it has successfully claimed 174 + * an address except when responding to a request for 175 + * address-claimed. 176 + * 177 + * But "Figure 6" and "Figure 7" in "4.5.4.2 - Address-claim 178 + * prioritization" show that the CF begins the transmission 179 + * after 250 ms from the first AC (address-claimed) message 180 + * even if it sends another AC message during that time window 181 + * to resolve the address contention with another CF. 182 + * 183 + * As stated in "4.4.2.3 - Address-claimed message": 184 + * In order to successfully claim an address, the CF sending 185 + * an address claimed message shall not receive a contending 186 + * claim from another CF for at least 250 ms. 187 + * 188 + * As stated in "4.4.3.2 - NAME management (NM) message": 189 + * 1) A commanding CF can 190 + * d) request that a CF with a specified NAME transmit 191 + * the address-claimed message with its current NAME. 192 + * 2) A target CF shall 193 + * d) send an address-claimed message in response to a 194 + * request for a matching NAME 195 + * 196 + * Taking the above arguments into account, the 250 ms wait is 197 + * requested only during network initialization. 198 + * 199 + * Do not restart the timer on AC message if both the NAME and 200 + * the address match and so if the address has already been 201 + * claimed (timer has expired) or the AC message has been sent 202 + * to resolve the contention with another CF (timer is still 203 + * running). 204 + */ 205 + goto out_ecu_put; 206 + } 207 + 168 208 if (!ecu && j1939_address_is_unicast(skcb->addr.sa)) 169 209 ecu = j1939_ecu_create_locked(priv, name); 170 210