xref: /openbmc/linux/net/can/j1939/j1939-priv.h (revision c595db6d7c8bcf87ef42204391fa890e5950e566)
19d71dd0cSThe j1939 authors /* SPDX-License-Identifier: GPL-2.0 */
29d71dd0cSThe j1939 authors // Copyright (c) 2010-2011 EIA Electronics,
39d71dd0cSThe j1939 authors //                         Kurt Van Dijck <kurt.van.dijck@eia.be>
49d71dd0cSThe j1939 authors // Copyright (c) 2017-2019 Pengutronix,
59d71dd0cSThe j1939 authors //                         Marc Kleine-Budde <kernel@pengutronix.de>
69d71dd0cSThe j1939 authors // Copyright (c) 2017-2019 Pengutronix,
79d71dd0cSThe j1939 authors //                         Oleksij Rempel <kernel@pengutronix.de>
89d71dd0cSThe j1939 authors 
99d71dd0cSThe j1939 authors #ifndef _J1939_PRIV_H_
109d71dd0cSThe j1939 authors #define _J1939_PRIV_H_
119d71dd0cSThe j1939 authors 
129d71dd0cSThe j1939 authors #include <linux/can/j1939.h>
139d71dd0cSThe j1939 authors #include <net/sock.h>
149d71dd0cSThe j1939 authors 
159d71dd0cSThe j1939 authors /* Timeout to receive the abort signal over loop back. In case CAN
169d71dd0cSThe j1939 authors  * bus is open, the timeout should be triggered.
179d71dd0cSThe j1939 authors  */
189d71dd0cSThe j1939 authors #define J1939_XTP_ABORT_TIMEOUT_MS 500
199d71dd0cSThe j1939 authors #define J1939_SIMPLE_ECHO_TIMEOUT_MS (10 * 1000)
209d71dd0cSThe j1939 authors 
219d71dd0cSThe j1939 authors struct j1939_session;
229d71dd0cSThe j1939 authors enum j1939_sk_errqueue_type {
23cd85d3aeSOleksij Rempel 	J1939_ERRQUEUE_TX_ACK,
24cd85d3aeSOleksij Rempel 	J1939_ERRQUEUE_TX_SCHED,
25cd85d3aeSOleksij Rempel 	J1939_ERRQUEUE_TX_ABORT,
265b9272e9SOleksij Rempel 	J1939_ERRQUEUE_RX_RTS,
275b9272e9SOleksij Rempel 	J1939_ERRQUEUE_RX_DPO,
285b9272e9SOleksij Rempel 	J1939_ERRQUEUE_RX_ABORT,
299d71dd0cSThe j1939 authors };
309d71dd0cSThe j1939 authors 
319d71dd0cSThe j1939 authors /* j1939 devices */
329d71dd0cSThe j1939 authors struct j1939_ecu {
339d71dd0cSThe j1939 authors 	struct list_head list;
349d71dd0cSThe j1939 authors 	name_t name;
359d71dd0cSThe j1939 authors 	u8 addr;
369d71dd0cSThe j1939 authors 
379d71dd0cSThe j1939 authors 	/* indicates that this ecu successfully claimed @sa as its address */
389d71dd0cSThe j1939 authors 	struct hrtimer ac_timer;
399d71dd0cSThe j1939 authors 	struct kref kref;
409d71dd0cSThe j1939 authors 	struct j1939_priv *priv;
419d71dd0cSThe j1939 authors 
429d71dd0cSThe j1939 authors 	/* count users, to help transport protocol decide for interaction */
439d71dd0cSThe j1939 authors 	int nusers;
449d71dd0cSThe j1939 authors };
459d71dd0cSThe j1939 authors 
469d71dd0cSThe j1939 authors struct j1939_priv {
479d71dd0cSThe j1939 authors 	struct list_head ecus;
489d71dd0cSThe j1939 authors 	/* local list entry in priv
499d71dd0cSThe j1939 authors 	 * These allow irq (& softirq) context lookups on j1939 devices
509d71dd0cSThe j1939 authors 	 * This approach (separate lists) is done as the other 2 alternatives
519d71dd0cSThe j1939 authors 	 * are not easier or even wrong
529d71dd0cSThe j1939 authors 	 * 1) using the pure kobject methods involves mutexes, which are not
539d71dd0cSThe j1939 authors 	 *    allowed in irq context.
549d71dd0cSThe j1939 authors 	 * 2) duplicating data structures would require a lot of synchronization
559d71dd0cSThe j1939 authors 	 *    code
569d71dd0cSThe j1939 authors 	 * usage:
579d71dd0cSThe j1939 authors 	 */
589d71dd0cSThe j1939 authors 
599d71dd0cSThe j1939 authors 	/* segments need a lock to protect the above list */
609d71dd0cSThe j1939 authors 	rwlock_t lock;
619d71dd0cSThe j1939 authors 
629d71dd0cSThe j1939 authors 	struct net_device *ndev;
639d71dd0cSThe j1939 authors 
649d71dd0cSThe j1939 authors 	/* list of 256 ecu ptrs, that cache the claimed addresses.
659d71dd0cSThe j1939 authors 	 * also protected by the above lock
669d71dd0cSThe j1939 authors 	 */
679d71dd0cSThe j1939 authors 	struct j1939_addr_ent {
689d71dd0cSThe j1939 authors 		struct j1939_ecu *ecu;
699d71dd0cSThe j1939 authors 		/* count users, to help transport protocol */
709d71dd0cSThe j1939 authors 		int nusers;
719d71dd0cSThe j1939 authors 	} ents[256];
729d71dd0cSThe j1939 authors 
739d71dd0cSThe j1939 authors 	struct kref kref;
749d71dd0cSThe j1939 authors 
759d71dd0cSThe j1939 authors 	/* List of active sessions to prevent start of conflicting
769d71dd0cSThe j1939 authors 	 * one.
779d71dd0cSThe j1939 authors 	 *
789d71dd0cSThe j1939 authors 	 * Do not start two sessions of same type, addresses and
799d71dd0cSThe j1939 authors 	 * direction.
809d71dd0cSThe j1939 authors 	 */
819d71dd0cSThe j1939 authors 	struct list_head active_session_list;
829d71dd0cSThe j1939 authors 
839d71dd0cSThe j1939 authors 	/* protects active_session_list */
849d71dd0cSThe j1939 authors 	spinlock_t active_session_list_lock;
859d71dd0cSThe j1939 authors 
869d71dd0cSThe j1939 authors 	unsigned int tp_max_packet_size;
879d71dd0cSThe j1939 authors 
889d71dd0cSThe j1939 authors 	/* lock for j1939_socks list */
8926dfe112SZiqi Zhao 	rwlock_t j1939_socks_lock;
909d71dd0cSThe j1939 authors 	struct list_head j1939_socks;
919d71dd0cSThe j1939 authors 
929d71dd0cSThe j1939 authors 	struct kref rx_kref;
935b9272e9SOleksij Rempel 	u32 rx_tskey;
949d71dd0cSThe j1939 authors };
959d71dd0cSThe j1939 authors 
969d71dd0cSThe j1939 authors void j1939_ecu_put(struct j1939_ecu *ecu);
979d71dd0cSThe j1939 authors 
989d71dd0cSThe j1939 authors /* keep the cache of what is local */
999d71dd0cSThe j1939 authors int j1939_local_ecu_get(struct j1939_priv *priv, name_t name, u8 sa);
1009d71dd0cSThe j1939 authors void j1939_local_ecu_put(struct j1939_priv *priv, name_t name, u8 sa);
1019d71dd0cSThe j1939 authors 
j1939_address_is_unicast(u8 addr)1029d71dd0cSThe j1939 authors static inline bool j1939_address_is_unicast(u8 addr)
1039d71dd0cSThe j1939 authors {
1049d71dd0cSThe j1939 authors 	return addr <= J1939_MAX_UNICAST_ADDR;
1059d71dd0cSThe j1939 authors }
1069d71dd0cSThe j1939 authors 
j1939_address_is_idle(u8 addr)1079d71dd0cSThe j1939 authors static inline bool j1939_address_is_idle(u8 addr)
1089d71dd0cSThe j1939 authors {
1099d71dd0cSThe j1939 authors 	return addr == J1939_IDLE_ADDR;
1109d71dd0cSThe j1939 authors }
1119d71dd0cSThe j1939 authors 
j1939_address_is_valid(u8 addr)1129d71dd0cSThe j1939 authors static inline bool j1939_address_is_valid(u8 addr)
1139d71dd0cSThe j1939 authors {
1149d71dd0cSThe j1939 authors 	return addr != J1939_NO_ADDR;
1159d71dd0cSThe j1939 authors }
1169d71dd0cSThe j1939 authors 
j1939_pgn_is_pdu1(pgn_t pgn)1179d71dd0cSThe j1939 authors static inline bool j1939_pgn_is_pdu1(pgn_t pgn)
1189d71dd0cSThe j1939 authors {
1199d71dd0cSThe j1939 authors 	/* ignore dp & res bits for this */
1209d71dd0cSThe j1939 authors 	return (pgn & 0xff00) < 0xf000;
1219d71dd0cSThe j1939 authors }
1229d71dd0cSThe j1939 authors 
1239d71dd0cSThe j1939 authors /* utility to correctly unmap an ECU */
1249d71dd0cSThe j1939 authors void j1939_ecu_unmap_locked(struct j1939_ecu *ecu);
1259d71dd0cSThe j1939 authors void j1939_ecu_unmap(struct j1939_ecu *ecu);
1269d71dd0cSThe j1939 authors 
1279d71dd0cSThe j1939 authors u8 j1939_name_to_addr(struct j1939_priv *priv, name_t name);
1289d71dd0cSThe j1939 authors struct j1939_ecu *j1939_ecu_find_by_addr_locked(struct j1939_priv *priv,
1299d71dd0cSThe j1939 authors 						u8 addr);
1309d71dd0cSThe j1939 authors struct j1939_ecu *j1939_ecu_get_by_addr(struct j1939_priv *priv, u8 addr);
1319d71dd0cSThe j1939 authors struct j1939_ecu *j1939_ecu_get_by_addr_locked(struct j1939_priv *priv,
1329d71dd0cSThe j1939 authors 					       u8 addr);
1339d71dd0cSThe j1939 authors struct j1939_ecu *j1939_ecu_get_by_name(struct j1939_priv *priv, name_t name);
1349d71dd0cSThe j1939 authors struct j1939_ecu *j1939_ecu_get_by_name_locked(struct j1939_priv *priv,
1359d71dd0cSThe j1939 authors 					       name_t name);
1369d71dd0cSThe j1939 authors 
1379d71dd0cSThe j1939 authors enum j1939_transfer_type {
1389d71dd0cSThe j1939 authors 	J1939_TP,
1399d71dd0cSThe j1939 authors 	J1939_ETP,
1409d71dd0cSThe j1939 authors 	J1939_SIMPLE,
1419d71dd0cSThe j1939 authors };
1429d71dd0cSThe j1939 authors 
1439d71dd0cSThe j1939 authors struct j1939_addr {
1449d71dd0cSThe j1939 authors 	name_t src_name;
1459d71dd0cSThe j1939 authors 	name_t dst_name;
1469d71dd0cSThe j1939 authors 	pgn_t pgn;
1479d71dd0cSThe j1939 authors 
1489d71dd0cSThe j1939 authors 	u8 sa;
1499d71dd0cSThe j1939 authors 	u8 da;
1509d71dd0cSThe j1939 authors 
1519d71dd0cSThe j1939 authors 	u8 type;
1529d71dd0cSThe j1939 authors };
1539d71dd0cSThe j1939 authors 
1549d71dd0cSThe j1939 authors /* control buffer of the sk_buff */
1559d71dd0cSThe j1939 authors struct j1939_sk_buff_cb {
1569d71dd0cSThe j1939 authors 	/* Offset in bytes within one ETP session */
1579d71dd0cSThe j1939 authors 	u32 offset;
1589d71dd0cSThe j1939 authors 
1599d71dd0cSThe j1939 authors 	/* for tx, MSG_SYN will be used to sync on sockets */
1609d71dd0cSThe j1939 authors 	u32 msg_flags;
1619d71dd0cSThe j1939 authors 	u32 tskey;
1629d71dd0cSThe j1939 authors 
1639d71dd0cSThe j1939 authors 	struct j1939_addr addr;
1649d71dd0cSThe j1939 authors 
1659d71dd0cSThe j1939 authors 	/* Flags for quick lookups during skb processing.
1669d71dd0cSThe j1939 authors 	 * These are set in the receive path only.
1679d71dd0cSThe j1939 authors 	 */
1689d71dd0cSThe j1939 authors #define J1939_ECU_LOCAL_SRC BIT(0)
1699d71dd0cSThe j1939 authors #define J1939_ECU_LOCAL_DST BIT(1)
1709d71dd0cSThe j1939 authors 	u8 flags;
1719d71dd0cSThe j1939 authors 
1729d71dd0cSThe j1939 authors 	priority_t priority;
1739d71dd0cSThe j1939 authors };
1749d71dd0cSThe j1939 authors 
1759d71dd0cSThe j1939 authors static inline
j1939_skb_to_cb(const struct sk_buff * skb)1769d71dd0cSThe j1939 authors struct j1939_sk_buff_cb *j1939_skb_to_cb(const struct sk_buff *skb)
1779d71dd0cSThe j1939 authors {
1789d71dd0cSThe j1939 authors 	BUILD_BUG_ON(sizeof(struct j1939_sk_buff_cb) > sizeof(skb->cb));
1799d71dd0cSThe j1939 authors 
1809d71dd0cSThe j1939 authors 	return (struct j1939_sk_buff_cb *)skb->cb;
1819d71dd0cSThe j1939 authors }
1829d71dd0cSThe j1939 authors 
1839d71dd0cSThe j1939 authors int j1939_send_one(struct j1939_priv *priv, struct sk_buff *skb);
1849d71dd0cSThe j1939 authors void j1939_sk_recv(struct j1939_priv *priv, struct sk_buff *skb);
1859d71dd0cSThe j1939 authors bool j1939_sk_recv_match(struct j1939_priv *priv,
1869d71dd0cSThe j1939 authors 			 struct j1939_sk_buff_cb *skcb);
1879d71dd0cSThe j1939 authors void j1939_sk_send_loop_abort(struct sock *sk, int err);
1889d71dd0cSThe j1939 authors void j1939_sk_errqueue(struct j1939_session *session,
1899d71dd0cSThe j1939 authors 		       enum j1939_sk_errqueue_type type);
1909d71dd0cSThe j1939 authors void j1939_sk_queue_activate_next(struct j1939_session *session);
1919d71dd0cSThe j1939 authors 
1929d71dd0cSThe j1939 authors /* stack entries */
1939d71dd0cSThe j1939 authors struct j1939_session *j1939_tp_send(struct j1939_priv *priv,
1949d71dd0cSThe j1939 authors 				    struct sk_buff *skb, size_t size);
1959d71dd0cSThe j1939 authors int j1939_tp_recv(struct j1939_priv *priv, struct sk_buff *skb);
1969d71dd0cSThe j1939 authors int j1939_ac_fixup(struct j1939_priv *priv, struct sk_buff *skb);
1979d71dd0cSThe j1939 authors void j1939_ac_recv(struct j1939_priv *priv, struct sk_buff *skb);
1989d71dd0cSThe j1939 authors void j1939_simple_recv(struct j1939_priv *priv, struct sk_buff *skb);
1999d71dd0cSThe j1939 authors 
2009d71dd0cSThe j1939 authors /* network management */
2019d71dd0cSThe j1939 authors struct j1939_ecu *j1939_ecu_create_locked(struct j1939_priv *priv, name_t name);
2029d71dd0cSThe j1939 authors 
2039d71dd0cSThe j1939 authors void j1939_ecu_timer_start(struct j1939_ecu *ecu);
2049d71dd0cSThe j1939 authors void j1939_ecu_timer_cancel(struct j1939_ecu *ecu);
2059d71dd0cSThe j1939 authors void j1939_ecu_unmap_all(struct j1939_priv *priv);
2069d71dd0cSThe j1939 authors 
2079d71dd0cSThe j1939 authors struct j1939_priv *j1939_netdev_start(struct net_device *ndev);
2089d71dd0cSThe j1939 authors void j1939_netdev_stop(struct j1939_priv *priv);
2099d71dd0cSThe j1939 authors 
2109d71dd0cSThe j1939 authors void j1939_priv_put(struct j1939_priv *priv);
2119d71dd0cSThe j1939 authors void j1939_priv_get(struct j1939_priv *priv);
2129d71dd0cSThe j1939 authors 
2139d71dd0cSThe j1939 authors /* notify/alert all j1939 sockets bound to ifindex */
2149d71dd0cSThe j1939 authors void j1939_sk_netdev_event_netdown(struct j1939_priv *priv);
2159d71dd0cSThe j1939 authors int j1939_cancel_active_session(struct j1939_priv *priv, struct sock *sk);
2169d71dd0cSThe j1939 authors void j1939_tp_init(struct j1939_priv *priv);
2179d71dd0cSThe j1939 authors 
2189d71dd0cSThe j1939 authors /* decrement pending skb for a j1939 socket */
2199d71dd0cSThe j1939 authors void j1939_sock_pending_del(struct sock *sk);
2209d71dd0cSThe j1939 authors 
2219d71dd0cSThe j1939 authors enum j1939_session_state {
2229d71dd0cSThe j1939 authors 	J1939_SESSION_NEW,
2239d71dd0cSThe j1939 authors 	J1939_SESSION_ACTIVE,
2249d71dd0cSThe j1939 authors 	/* waiting for abort signal on the bus */
2259d71dd0cSThe j1939 authors 	J1939_SESSION_WAITING_ABORT,
2269d71dd0cSThe j1939 authors 	J1939_SESSION_ACTIVE_MAX,
2279d71dd0cSThe j1939 authors 	J1939_SESSION_DONE,
2289d71dd0cSThe j1939 authors };
2299d71dd0cSThe j1939 authors 
2309d71dd0cSThe j1939 authors struct j1939_session {
2319d71dd0cSThe j1939 authors 	struct j1939_priv *priv;
2329d71dd0cSThe j1939 authors 	struct list_head active_session_list_entry;
2339d71dd0cSThe j1939 authors 	struct list_head sk_session_queue_entry;
2349d71dd0cSThe j1939 authors 	struct kref kref;
2359d71dd0cSThe j1939 authors 	struct sock *sk;
2369d71dd0cSThe j1939 authors 
2379d71dd0cSThe j1939 authors 	/* ifindex, src, dst, pgn define the session block
2389d71dd0cSThe j1939 authors 	 * the are _never_ modified after insertion in the list
2399d71dd0cSThe j1939 authors 	 * this decreases locking problems a _lot_
2409d71dd0cSThe j1939 authors 	 */
2419d71dd0cSThe j1939 authors 	struct j1939_sk_buff_cb skcb;
2429d71dd0cSThe j1939 authors 	struct sk_buff_head skb_queue;
2439d71dd0cSThe j1939 authors 
2449d71dd0cSThe j1939 authors 	/* all tx related stuff (last_txcmd, pkt.tx)
2459d71dd0cSThe j1939 authors 	 * is protected (modified only) with the txtimer hrtimer
2469d71dd0cSThe j1939 authors 	 * 'total' & 'block' are never changed,
2479d71dd0cSThe j1939 authors 	 * last_cmd, last & block are protected by ->lock
2489d71dd0cSThe j1939 authors 	 * this means that the tx may run after cts is received that should
2499d71dd0cSThe j1939 authors 	 * have stopped tx, but this time discrepancy is never avoided anyhow
2509d71dd0cSThe j1939 authors 	 */
2519d71dd0cSThe j1939 authors 	u8 last_cmd, last_txcmd;
2529d71dd0cSThe j1939 authors 	bool transmission;
2539d71dd0cSThe j1939 authors 	bool extd;
2549d71dd0cSThe j1939 authors 	/* Total message size, number of bytes */
2559d71dd0cSThe j1939 authors 	unsigned int total_message_size;
2569d71dd0cSThe j1939 authors 	/* Total number of bytes queue from socket to the session */
2579d71dd0cSThe j1939 authors 	unsigned int total_queued_size;
2589d71dd0cSThe j1939 authors 	unsigned int tx_retry;
2599d71dd0cSThe j1939 authors 
2609d71dd0cSThe j1939 authors 	int err;
2619d71dd0cSThe j1939 authors 	u32 tskey;
2629d71dd0cSThe j1939 authors 	enum j1939_session_state state;
2639d71dd0cSThe j1939 authors 
2649d71dd0cSThe j1939 authors 	/* Packets counters for a (extended) transfer session. The packet is
2659d71dd0cSThe j1939 authors 	 * maximal of 7 bytes.
2669d71dd0cSThe j1939 authors 	 */
2679d71dd0cSThe j1939 authors 	struct {
2689d71dd0cSThe j1939 authors 		/* total - total number of packets for this session */
2699d71dd0cSThe j1939 authors 		unsigned int total;
2709d71dd0cSThe j1939 authors 		/* last - last packet of a transfer block after which
2719d71dd0cSThe j1939 authors 		 * responder should send ETP.CM_CTS and originator
2729d71dd0cSThe j1939 authors 		 * ETP.CM_DPO
2739d71dd0cSThe j1939 authors 		 */
2749d71dd0cSThe j1939 authors 		unsigned int last;
2759d71dd0cSThe j1939 authors 		/* tx - number of packets send by originator node.
2769d71dd0cSThe j1939 authors 		 * this counter can be set back if responder node
2779d71dd0cSThe j1939 authors 		 * didn't received all packets send by originator.
2789d71dd0cSThe j1939 authors 		 */
2799d71dd0cSThe j1939 authors 		unsigned int tx;
2809d71dd0cSThe j1939 authors 		unsigned int tx_acked;
2819d71dd0cSThe j1939 authors 		/* rx - number of packets received */
2829d71dd0cSThe j1939 authors 		unsigned int rx;
2839d71dd0cSThe j1939 authors 		/* block - amount of packets expected in one block */
2849d71dd0cSThe j1939 authors 		unsigned int block;
2859d71dd0cSThe j1939 authors 		/* dpo - ETP.CM_DPO, Data Packet Offset */
2869d71dd0cSThe j1939 authors 		unsigned int dpo;
2879d71dd0cSThe j1939 authors 	} pkt;
2889d71dd0cSThe j1939 authors 	struct hrtimer txtimer, rxtimer;
2899d71dd0cSThe j1939 authors };
2909d71dd0cSThe j1939 authors 
2919d71dd0cSThe j1939 authors struct j1939_sock {
2929d71dd0cSThe j1939 authors 	struct sock sk; /* must be first to skip with memset */
2939d71dd0cSThe j1939 authors 	struct j1939_priv *priv;
2949d71dd0cSThe j1939 authors 	struct list_head list;
2959d71dd0cSThe j1939 authors 
2969d71dd0cSThe j1939 authors #define J1939_SOCK_BOUND BIT(0)
2979d71dd0cSThe j1939 authors #define J1939_SOCK_CONNECTED BIT(1)
2989d71dd0cSThe j1939 authors #define J1939_SOCK_PROMISC BIT(2)
2999d71dd0cSThe j1939 authors #define J1939_SOCK_ERRQUEUE BIT(3)
3009d71dd0cSThe j1939 authors 	int state;
3019d71dd0cSThe j1939 authors 
3029d71dd0cSThe j1939 authors 	int ifindex;
3039d71dd0cSThe j1939 authors 	struct j1939_addr addr;
304*f84e7534SOleksij Rempel 	spinlock_t filters_lock;
3059d71dd0cSThe j1939 authors 	struct j1939_filter *filters;
3069d71dd0cSThe j1939 authors 	int nfilters;
3079d71dd0cSThe j1939 authors 	pgn_t pgn_rx_filter;
3089d71dd0cSThe j1939 authors 
3099d71dd0cSThe j1939 authors 	/* j1939 may emit equal PGN (!= equal CAN-id's) out of order
3109d71dd0cSThe j1939 authors 	 * when transport protocol comes in.
3119d71dd0cSThe j1939 authors 	 * To allow emitting in order, keep a 'pending' nr. of packets
3129d71dd0cSThe j1939 authors 	 */
3139d71dd0cSThe j1939 authors 	atomic_t skb_pending;
3149d71dd0cSThe j1939 authors 	wait_queue_head_t waitq;
3159d71dd0cSThe j1939 authors 
3169d71dd0cSThe j1939 authors 	/* lock for the sk_session_queue list */
3179d71dd0cSThe j1939 authors 	spinlock_t sk_session_queue_lock;
3189d71dd0cSThe j1939 authors 	struct list_head sk_session_queue;
3199d71dd0cSThe j1939 authors };
3209d71dd0cSThe j1939 authors 
j1939_sk(const struct sock * sk)3219d71dd0cSThe j1939 authors static inline struct j1939_sock *j1939_sk(const struct sock *sk)
3229d71dd0cSThe j1939 authors {
3239d71dd0cSThe j1939 authors 	return container_of(sk, struct j1939_sock, sk);
3249d71dd0cSThe j1939 authors }
3259d71dd0cSThe j1939 authors 
3269d71dd0cSThe j1939 authors void j1939_session_get(struct j1939_session *session);
3279d71dd0cSThe j1939 authors void j1939_session_put(struct j1939_session *session);
3289d71dd0cSThe j1939 authors void j1939_session_skb_queue(struct j1939_session *session,
3299d71dd0cSThe j1939 authors 			     struct sk_buff *skb);
3309d71dd0cSThe j1939 authors int j1939_session_activate(struct j1939_session *session);
3319d71dd0cSThe j1939 authors void j1939_tp_schedule_txtimer(struct j1939_session *session, int msec);
3329d71dd0cSThe j1939 authors void j1939_session_timers_cancel(struct j1939_session *session);
3339d71dd0cSThe j1939 authors 
334a4fbe70cSZhang Changzhong #define J1939_MIN_TP_PACKET_SIZE 9
3359d71dd0cSThe j1939 authors #define J1939_MAX_TP_PACKET_SIZE (7 * 0xff)
3369d71dd0cSThe j1939 authors #define J1939_MAX_ETP_PACKET_SIZE (7 * 0x00ffffff)
3379d71dd0cSThe j1939 authors 
3389d71dd0cSThe j1939 authors #define J1939_REGULAR 0
3399d71dd0cSThe j1939 authors #define J1939_EXTENDED 1
3409d71dd0cSThe j1939 authors 
3419d71dd0cSThe j1939 authors /* CAN protocol */
3429d71dd0cSThe j1939 authors extern const struct can_proto j1939_can_proto;
3439d71dd0cSThe j1939 authors 
3449d71dd0cSThe j1939 authors #endif /* _J1939_PRIV_H_ */
345