Lines Matching +full:- +full:eproto

1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2010-2011 EIA Electronics,
4 // Copyright (c) 2010-2011 EIA Electronics,
6 // Copyright (c) 2017-2019 Pengutronix,
7 // Marc Kleine-Budde <kernel@pengutronix.de>
8 // Copyright (c) 2017-2019 Pengutronix,
13 * - keeps track of the AC states of ECU's,
14 * - resolves NAME<=>SA taking into account the AC states of ECU's.
16 * All Address Claim msgs (including host-originated msg) are processed
30 #include "j1939-priv.h"
34 return le64_to_cpup((__le64 *)skb->data); in j1939_skb_to_name()
42 if (skb->len < 3 || skcb->addr.pgn != J1939_PGN_REQUEST) in j1939_ac_msg_is_request()
45 req_pgn = skb->data[0] | (skb->data[1] << 8) | (skb->data[2] << 16); in j1939_ac_msg_is_request()
55 if (skb->len != 8) { in j1939_ac_verify_outgoing()
56 netdev_notice(priv->ndev, "tx address claim with dlc %i\n", in j1939_ac_verify_outgoing()
57 skb->len); in j1939_ac_verify_outgoing()
58 return -EPROTO; in j1939_ac_verify_outgoing()
61 if (skcb->addr.src_name != j1939_skb_to_name(skb)) { in j1939_ac_verify_outgoing()
62 netdev_notice(priv->ndev, "tx address claim with different name\n"); in j1939_ac_verify_outgoing()
63 return -EPROTO; in j1939_ac_verify_outgoing()
66 if (skcb->addr.sa == J1939_NO_ADDR) { in j1939_ac_verify_outgoing()
67 netdev_notice(priv->ndev, "tx address claim with broadcast sa\n"); in j1939_ac_verify_outgoing()
68 return -EPROTO; in j1939_ac_verify_outgoing()
72 if (skcb->addr.dst_name || skcb->addr.da != J1939_NO_ADDR) { in j1939_ac_verify_outgoing()
73 netdev_notice(priv->ndev, "tx address claim with dest, not broadcast\n"); in j1939_ac_verify_outgoing()
74 return -EPROTO; in j1939_ac_verify_outgoing()
86 if (skcb->addr.pgn == J1939_PGN_ADDRESS_CLAIMED) { in j1939_ac_fixup()
93 ecu = j1939_ecu_get_by_name(priv, skcb->addr.src_name); in j1939_ac_fixup()
95 return -ENODEV; in j1939_ac_fixup()
97 if (ecu->addr != skcb->addr.sa) in j1939_ac_fixup()
101 } else if (skcb->addr.src_name) { in j1939_ac_fixup()
103 addr = j1939_name_to_addr(priv, skcb->addr.src_name); in j1939_ac_fixup()
106 netdev_notice(priv->ndev, "tx drop: invalid sa for name 0x%016llx\n", in j1939_ac_fixup()
107 skcb->addr.src_name); in j1939_ac_fixup()
108 return -EADDRNOTAVAIL; in j1939_ac_fixup()
110 skcb->addr.sa = addr; in j1939_ac_fixup()
114 if (skcb->addr.dst_name) { in j1939_ac_fixup()
115 addr = j1939_name_to_addr(priv, skcb->addr.dst_name); in j1939_ac_fixup()
117 netdev_notice(priv->ndev, "tx drop: invalid da for name 0x%016llx\n", in j1939_ac_fixup()
118 skcb->addr.dst_name); in j1939_ac_fixup()
119 return -EADDRNOTAVAIL; in j1939_ac_fixup()
121 skcb->addr.da = addr; in j1939_ac_fixup()
132 if (skb->len != 8) { in j1939_ac_process()
133 netdev_notice(priv->ndev, "rx address claim with wrong dlc %i\n", in j1939_ac_process()
134 skb->len); in j1939_ac_process()
139 skcb->addr.src_name = name; in j1939_ac_process()
141 netdev_notice(priv->ndev, "rx address claim without name\n"); in j1939_ac_process()
145 if (!j1939_address_is_valid(skcb->addr.sa)) { in j1939_ac_process()
146 netdev_notice(priv->ndev, "rx address claim with broadcast sa\n"); in j1939_ac_process()
150 write_lock_bh(&priv->lock); in j1939_ac_process()
169 if (ecu && ecu->addr == skcb->addr.sa) { in j1939_ac_process()
170 /* The ISO 11783-5 standard, in "4.5.2 - Address claim in j1939_ac_process()
175 * address-claimed. in j1939_ac_process()
177 * But "Figure 6" and "Figure 7" in "4.5.4.2 - Address-claim in j1939_ac_process()
179 * after 250 ms from the first AC (address-claimed) message in j1939_ac_process()
183 * As stated in "4.4.2.3 - Address-claimed message": in j1939_ac_process()
188 * As stated in "4.4.3.2 - NAME management (NM) message": in j1939_ac_process()
191 * the address-claimed message with its current NAME. in j1939_ac_process()
193 * d) send an address-claimed message in response to a in j1939_ac_process()
208 if (!ecu && j1939_address_is_unicast(skcb->addr.sa)) in j1939_ac_process()
217 if (j1939_address_is_idle(skcb->addr.sa)) { in j1939_ac_process()
223 if (ecu->addr != skcb->addr.sa) in j1939_ac_process()
225 ecu->addr = skcb->addr.sa; in j1939_ac_process()
227 prev = j1939_ecu_get_by_addr_locked(priv, skcb->addr.sa); in j1939_ac_process()
229 if (ecu->name > prev->name) { in j1939_ac_process()
244 write_unlock_bh(&priv->lock); in j1939_ac_process()
253 if (skcb->addr.pgn == J1939_PGN_ADDRESS_CLAIMED) { in j1939_ac_recv()
255 } else if (j1939_address_is_unicast(skcb->addr.sa)) { in j1939_ac_recv()
257 ecu = j1939_ecu_get_by_addr(priv, skcb->addr.sa); in j1939_ac_recv()
259 skcb->addr.src_name = ecu->name; in j1939_ac_recv()
265 ecu = j1939_ecu_get_by_addr(priv, skcb->addr.da); in j1939_ac_recv()
267 skcb->addr.dst_name = ecu->name; in j1939_ac_recv()