xref: /openbmc/linux/net/can/j1939/j1939-priv.h (revision 9d71dd0c70099914fcd063135da3c580865e924c)
1*9d71dd0cSThe j1939 authors /* SPDX-License-Identifier: GPL-2.0 */
2*9d71dd0cSThe j1939 authors // Copyright (c) 2010-2011 EIA Electronics,
3*9d71dd0cSThe j1939 authors //                         Kurt Van Dijck <kurt.van.dijck@eia.be>
4*9d71dd0cSThe j1939 authors // Copyright (c) 2017-2019 Pengutronix,
5*9d71dd0cSThe j1939 authors //                         Marc Kleine-Budde <kernel@pengutronix.de>
6*9d71dd0cSThe j1939 authors // Copyright (c) 2017-2019 Pengutronix,
7*9d71dd0cSThe j1939 authors //                         Oleksij Rempel <kernel@pengutronix.de>
8*9d71dd0cSThe j1939 authors 
9*9d71dd0cSThe j1939 authors #ifndef _J1939_PRIV_H_
10*9d71dd0cSThe j1939 authors #define _J1939_PRIV_H_
11*9d71dd0cSThe j1939 authors 
12*9d71dd0cSThe j1939 authors #include <linux/can/j1939.h>
13*9d71dd0cSThe j1939 authors #include <net/sock.h>
14*9d71dd0cSThe j1939 authors 
15*9d71dd0cSThe j1939 authors /* Timeout to receive the abort signal over loop back. In case CAN
16*9d71dd0cSThe j1939 authors  * bus is open, the timeout should be triggered.
17*9d71dd0cSThe j1939 authors  */
18*9d71dd0cSThe j1939 authors #define J1939_XTP_ABORT_TIMEOUT_MS 500
19*9d71dd0cSThe j1939 authors #define J1939_SIMPLE_ECHO_TIMEOUT_MS (10 * 1000)
20*9d71dd0cSThe j1939 authors 
21*9d71dd0cSThe j1939 authors struct j1939_session;
22*9d71dd0cSThe j1939 authors enum j1939_sk_errqueue_type {
23*9d71dd0cSThe j1939 authors 	J1939_ERRQUEUE_ACK,
24*9d71dd0cSThe j1939 authors 	J1939_ERRQUEUE_SCHED,
25*9d71dd0cSThe j1939 authors 	J1939_ERRQUEUE_ABORT,
26*9d71dd0cSThe j1939 authors };
27*9d71dd0cSThe j1939 authors 
28*9d71dd0cSThe j1939 authors /* j1939 devices */
29*9d71dd0cSThe j1939 authors struct j1939_ecu {
30*9d71dd0cSThe j1939 authors 	struct list_head list;
31*9d71dd0cSThe j1939 authors 	name_t name;
32*9d71dd0cSThe j1939 authors 	u8 addr;
33*9d71dd0cSThe j1939 authors 
34*9d71dd0cSThe j1939 authors 	/* indicates that this ecu successfully claimed @sa as its address */
35*9d71dd0cSThe j1939 authors 	struct hrtimer ac_timer;
36*9d71dd0cSThe j1939 authors 	struct kref kref;
37*9d71dd0cSThe j1939 authors 	struct j1939_priv *priv;
38*9d71dd0cSThe j1939 authors 
39*9d71dd0cSThe j1939 authors 	/* count users, to help transport protocol decide for interaction */
40*9d71dd0cSThe j1939 authors 	int nusers;
41*9d71dd0cSThe j1939 authors };
42*9d71dd0cSThe j1939 authors 
43*9d71dd0cSThe j1939 authors struct j1939_priv {
44*9d71dd0cSThe j1939 authors 	struct list_head ecus;
45*9d71dd0cSThe j1939 authors 	/* local list entry in priv
46*9d71dd0cSThe j1939 authors 	 * These allow irq (& softirq) context lookups on j1939 devices
47*9d71dd0cSThe j1939 authors 	 * This approach (separate lists) is done as the other 2 alternatives
48*9d71dd0cSThe j1939 authors 	 * are not easier or even wrong
49*9d71dd0cSThe j1939 authors 	 * 1) using the pure kobject methods involves mutexes, which are not
50*9d71dd0cSThe j1939 authors 	 *    allowed in irq context.
51*9d71dd0cSThe j1939 authors 	 * 2) duplicating data structures would require a lot of synchronization
52*9d71dd0cSThe j1939 authors 	 *    code
53*9d71dd0cSThe j1939 authors 	 * usage:
54*9d71dd0cSThe j1939 authors 	 */
55*9d71dd0cSThe j1939 authors 
56*9d71dd0cSThe j1939 authors 	/* segments need a lock to protect the above list */
57*9d71dd0cSThe j1939 authors 	rwlock_t lock;
58*9d71dd0cSThe j1939 authors 
59*9d71dd0cSThe j1939 authors 	struct net_device *ndev;
60*9d71dd0cSThe j1939 authors 
61*9d71dd0cSThe j1939 authors 	/* list of 256 ecu ptrs, that cache the claimed addresses.
62*9d71dd0cSThe j1939 authors 	 * also protected by the above lock
63*9d71dd0cSThe j1939 authors 	 */
64*9d71dd0cSThe j1939 authors 	struct j1939_addr_ent {
65*9d71dd0cSThe j1939 authors 		struct j1939_ecu *ecu;
66*9d71dd0cSThe j1939 authors 		/* count users, to help transport protocol */
67*9d71dd0cSThe j1939 authors 		int nusers;
68*9d71dd0cSThe j1939 authors 	} ents[256];
69*9d71dd0cSThe j1939 authors 
70*9d71dd0cSThe j1939 authors 	struct kref kref;
71*9d71dd0cSThe j1939 authors 
72*9d71dd0cSThe j1939 authors 	/* List of active sessions to prevent start of conflicting
73*9d71dd0cSThe j1939 authors 	 * one.
74*9d71dd0cSThe j1939 authors 	 *
75*9d71dd0cSThe j1939 authors 	 * Do not start two sessions of same type, addresses and
76*9d71dd0cSThe j1939 authors 	 * direction.
77*9d71dd0cSThe j1939 authors 	 */
78*9d71dd0cSThe j1939 authors 	struct list_head active_session_list;
79*9d71dd0cSThe j1939 authors 
80*9d71dd0cSThe j1939 authors 	/* protects active_session_list */
81*9d71dd0cSThe j1939 authors 	spinlock_t active_session_list_lock;
82*9d71dd0cSThe j1939 authors 
83*9d71dd0cSThe j1939 authors 	unsigned int tp_max_packet_size;
84*9d71dd0cSThe j1939 authors 
85*9d71dd0cSThe j1939 authors 	/* lock for j1939_socks list */
86*9d71dd0cSThe j1939 authors 	spinlock_t j1939_socks_lock;
87*9d71dd0cSThe j1939 authors 	struct list_head j1939_socks;
88*9d71dd0cSThe j1939 authors 
89*9d71dd0cSThe j1939 authors 	struct kref rx_kref;
90*9d71dd0cSThe j1939 authors };
91*9d71dd0cSThe j1939 authors 
92*9d71dd0cSThe j1939 authors void j1939_ecu_put(struct j1939_ecu *ecu);
93*9d71dd0cSThe j1939 authors 
94*9d71dd0cSThe j1939 authors /* keep the cache of what is local */
95*9d71dd0cSThe j1939 authors int j1939_local_ecu_get(struct j1939_priv *priv, name_t name, u8 sa);
96*9d71dd0cSThe j1939 authors void j1939_local_ecu_put(struct j1939_priv *priv, name_t name, u8 sa);
97*9d71dd0cSThe j1939 authors 
98*9d71dd0cSThe j1939 authors static inline bool j1939_address_is_unicast(u8 addr)
99*9d71dd0cSThe j1939 authors {
100*9d71dd0cSThe j1939 authors 	return addr <= J1939_MAX_UNICAST_ADDR;
101*9d71dd0cSThe j1939 authors }
102*9d71dd0cSThe j1939 authors 
103*9d71dd0cSThe j1939 authors static inline bool j1939_address_is_idle(u8 addr)
104*9d71dd0cSThe j1939 authors {
105*9d71dd0cSThe j1939 authors 	return addr == J1939_IDLE_ADDR;
106*9d71dd0cSThe j1939 authors }
107*9d71dd0cSThe j1939 authors 
108*9d71dd0cSThe j1939 authors static inline bool j1939_address_is_valid(u8 addr)
109*9d71dd0cSThe j1939 authors {
110*9d71dd0cSThe j1939 authors 	return addr != J1939_NO_ADDR;
111*9d71dd0cSThe j1939 authors }
112*9d71dd0cSThe j1939 authors 
113*9d71dd0cSThe j1939 authors static inline bool j1939_pgn_is_pdu1(pgn_t pgn)
114*9d71dd0cSThe j1939 authors {
115*9d71dd0cSThe j1939 authors 	/* ignore dp & res bits for this */
116*9d71dd0cSThe j1939 authors 	return (pgn & 0xff00) < 0xf000;
117*9d71dd0cSThe j1939 authors }
118*9d71dd0cSThe j1939 authors 
119*9d71dd0cSThe j1939 authors /* utility to correctly unmap an ECU */
120*9d71dd0cSThe j1939 authors void j1939_ecu_unmap_locked(struct j1939_ecu *ecu);
121*9d71dd0cSThe j1939 authors void j1939_ecu_unmap(struct j1939_ecu *ecu);
122*9d71dd0cSThe j1939 authors 
123*9d71dd0cSThe j1939 authors u8 j1939_name_to_addr(struct j1939_priv *priv, name_t name);
124*9d71dd0cSThe j1939 authors struct j1939_ecu *j1939_ecu_find_by_addr_locked(struct j1939_priv *priv,
125*9d71dd0cSThe j1939 authors 						u8 addr);
126*9d71dd0cSThe j1939 authors struct j1939_ecu *j1939_ecu_get_by_addr(struct j1939_priv *priv, u8 addr);
127*9d71dd0cSThe j1939 authors struct j1939_ecu *j1939_ecu_get_by_addr_locked(struct j1939_priv *priv,
128*9d71dd0cSThe j1939 authors 					       u8 addr);
129*9d71dd0cSThe j1939 authors struct j1939_ecu *j1939_ecu_get_by_name(struct j1939_priv *priv, name_t name);
130*9d71dd0cSThe j1939 authors struct j1939_ecu *j1939_ecu_get_by_name_locked(struct j1939_priv *priv,
131*9d71dd0cSThe j1939 authors 					       name_t name);
132*9d71dd0cSThe j1939 authors 
133*9d71dd0cSThe j1939 authors enum j1939_transfer_type {
134*9d71dd0cSThe j1939 authors 	J1939_TP,
135*9d71dd0cSThe j1939 authors 	J1939_ETP,
136*9d71dd0cSThe j1939 authors 	J1939_SIMPLE,
137*9d71dd0cSThe j1939 authors };
138*9d71dd0cSThe j1939 authors 
139*9d71dd0cSThe j1939 authors struct j1939_addr {
140*9d71dd0cSThe j1939 authors 	name_t src_name;
141*9d71dd0cSThe j1939 authors 	name_t dst_name;
142*9d71dd0cSThe j1939 authors 	pgn_t pgn;
143*9d71dd0cSThe j1939 authors 
144*9d71dd0cSThe j1939 authors 	u8 sa;
145*9d71dd0cSThe j1939 authors 	u8 da;
146*9d71dd0cSThe j1939 authors 
147*9d71dd0cSThe j1939 authors 	u8 type;
148*9d71dd0cSThe j1939 authors };
149*9d71dd0cSThe j1939 authors 
150*9d71dd0cSThe j1939 authors /* control buffer of the sk_buff */
151*9d71dd0cSThe j1939 authors struct j1939_sk_buff_cb {
152*9d71dd0cSThe j1939 authors 	/* Offset in bytes within one ETP session */
153*9d71dd0cSThe j1939 authors 	u32 offset;
154*9d71dd0cSThe j1939 authors 
155*9d71dd0cSThe j1939 authors 	/* for tx, MSG_SYN will be used to sync on sockets */
156*9d71dd0cSThe j1939 authors 	u32 msg_flags;
157*9d71dd0cSThe j1939 authors 	u32 tskey;
158*9d71dd0cSThe j1939 authors 
159*9d71dd0cSThe j1939 authors 	struct j1939_addr addr;
160*9d71dd0cSThe j1939 authors 
161*9d71dd0cSThe j1939 authors 	/* Flags for quick lookups during skb processing.
162*9d71dd0cSThe j1939 authors 	 * These are set in the receive path only.
163*9d71dd0cSThe j1939 authors 	 */
164*9d71dd0cSThe j1939 authors #define J1939_ECU_LOCAL_SRC BIT(0)
165*9d71dd0cSThe j1939 authors #define J1939_ECU_LOCAL_DST BIT(1)
166*9d71dd0cSThe j1939 authors 	u8 flags;
167*9d71dd0cSThe j1939 authors 
168*9d71dd0cSThe j1939 authors 	priority_t priority;
169*9d71dd0cSThe j1939 authors };
170*9d71dd0cSThe j1939 authors 
171*9d71dd0cSThe j1939 authors static inline
172*9d71dd0cSThe j1939 authors struct j1939_sk_buff_cb *j1939_skb_to_cb(const struct sk_buff *skb)
173*9d71dd0cSThe j1939 authors {
174*9d71dd0cSThe j1939 authors 	BUILD_BUG_ON(sizeof(struct j1939_sk_buff_cb) > sizeof(skb->cb));
175*9d71dd0cSThe j1939 authors 
176*9d71dd0cSThe j1939 authors 	return (struct j1939_sk_buff_cb *)skb->cb;
177*9d71dd0cSThe j1939 authors }
178*9d71dd0cSThe j1939 authors 
179*9d71dd0cSThe j1939 authors int j1939_send_one(struct j1939_priv *priv, struct sk_buff *skb);
180*9d71dd0cSThe j1939 authors void j1939_sk_recv(struct j1939_priv *priv, struct sk_buff *skb);
181*9d71dd0cSThe j1939 authors bool j1939_sk_recv_match(struct j1939_priv *priv,
182*9d71dd0cSThe j1939 authors 			 struct j1939_sk_buff_cb *skcb);
183*9d71dd0cSThe j1939 authors void j1939_sk_send_loop_abort(struct sock *sk, int err);
184*9d71dd0cSThe j1939 authors void j1939_sk_errqueue(struct j1939_session *session,
185*9d71dd0cSThe j1939 authors 		       enum j1939_sk_errqueue_type type);
186*9d71dd0cSThe j1939 authors void j1939_sk_queue_activate_next(struct j1939_session *session);
187*9d71dd0cSThe j1939 authors 
188*9d71dd0cSThe j1939 authors /* stack entries */
189*9d71dd0cSThe j1939 authors struct j1939_session *j1939_tp_send(struct j1939_priv *priv,
190*9d71dd0cSThe j1939 authors 				    struct sk_buff *skb, size_t size);
191*9d71dd0cSThe j1939 authors int j1939_tp_recv(struct j1939_priv *priv, struct sk_buff *skb);
192*9d71dd0cSThe j1939 authors int j1939_ac_fixup(struct j1939_priv *priv, struct sk_buff *skb);
193*9d71dd0cSThe j1939 authors void j1939_ac_recv(struct j1939_priv *priv, struct sk_buff *skb);
194*9d71dd0cSThe j1939 authors void j1939_simple_recv(struct j1939_priv *priv, struct sk_buff *skb);
195*9d71dd0cSThe j1939 authors 
196*9d71dd0cSThe j1939 authors /* network management */
197*9d71dd0cSThe j1939 authors struct j1939_ecu *j1939_ecu_create_locked(struct j1939_priv *priv, name_t name);
198*9d71dd0cSThe j1939 authors 
199*9d71dd0cSThe j1939 authors void j1939_ecu_timer_start(struct j1939_ecu *ecu);
200*9d71dd0cSThe j1939 authors void j1939_ecu_timer_cancel(struct j1939_ecu *ecu);
201*9d71dd0cSThe j1939 authors void j1939_ecu_unmap_all(struct j1939_priv *priv);
202*9d71dd0cSThe j1939 authors 
203*9d71dd0cSThe j1939 authors struct j1939_priv *j1939_netdev_start(struct net_device *ndev);
204*9d71dd0cSThe j1939 authors void j1939_netdev_stop(struct j1939_priv *priv);
205*9d71dd0cSThe j1939 authors 
206*9d71dd0cSThe j1939 authors void j1939_priv_put(struct j1939_priv *priv);
207*9d71dd0cSThe j1939 authors void j1939_priv_get(struct j1939_priv *priv);
208*9d71dd0cSThe j1939 authors 
209*9d71dd0cSThe j1939 authors /* notify/alert all j1939 sockets bound to ifindex */
210*9d71dd0cSThe j1939 authors void j1939_sk_netdev_event_netdown(struct j1939_priv *priv);
211*9d71dd0cSThe j1939 authors int j1939_cancel_active_session(struct j1939_priv *priv, struct sock *sk);
212*9d71dd0cSThe j1939 authors void j1939_tp_init(struct j1939_priv *priv);
213*9d71dd0cSThe j1939 authors 
214*9d71dd0cSThe j1939 authors /* decrement pending skb for a j1939 socket */
215*9d71dd0cSThe j1939 authors void j1939_sock_pending_del(struct sock *sk);
216*9d71dd0cSThe j1939 authors 
217*9d71dd0cSThe j1939 authors enum j1939_session_state {
218*9d71dd0cSThe j1939 authors 	J1939_SESSION_NEW,
219*9d71dd0cSThe j1939 authors 	J1939_SESSION_ACTIVE,
220*9d71dd0cSThe j1939 authors 	/* waiting for abort signal on the bus */
221*9d71dd0cSThe j1939 authors 	J1939_SESSION_WAITING_ABORT,
222*9d71dd0cSThe j1939 authors 	J1939_SESSION_ACTIVE_MAX,
223*9d71dd0cSThe j1939 authors 	J1939_SESSION_DONE,
224*9d71dd0cSThe j1939 authors };
225*9d71dd0cSThe j1939 authors 
226*9d71dd0cSThe j1939 authors struct j1939_session {
227*9d71dd0cSThe j1939 authors 	struct j1939_priv *priv;
228*9d71dd0cSThe j1939 authors 	struct list_head active_session_list_entry;
229*9d71dd0cSThe j1939 authors 	struct list_head sk_session_queue_entry;
230*9d71dd0cSThe j1939 authors 	struct kref kref;
231*9d71dd0cSThe j1939 authors 	struct sock *sk;
232*9d71dd0cSThe j1939 authors 
233*9d71dd0cSThe j1939 authors 	/* ifindex, src, dst, pgn define the session block
234*9d71dd0cSThe j1939 authors 	 * the are _never_ modified after insertion in the list
235*9d71dd0cSThe j1939 authors 	 * this decreases locking problems a _lot_
236*9d71dd0cSThe j1939 authors 	 */
237*9d71dd0cSThe j1939 authors 	struct j1939_sk_buff_cb skcb;
238*9d71dd0cSThe j1939 authors 	struct sk_buff_head skb_queue;
239*9d71dd0cSThe j1939 authors 
240*9d71dd0cSThe j1939 authors 	/* all tx related stuff (last_txcmd, pkt.tx)
241*9d71dd0cSThe j1939 authors 	 * is protected (modified only) with the txtimer hrtimer
242*9d71dd0cSThe j1939 authors 	 * 'total' & 'block' are never changed,
243*9d71dd0cSThe j1939 authors 	 * last_cmd, last & block are protected by ->lock
244*9d71dd0cSThe j1939 authors 	 * this means that the tx may run after cts is received that should
245*9d71dd0cSThe j1939 authors 	 * have stopped tx, but this time discrepancy is never avoided anyhow
246*9d71dd0cSThe j1939 authors 	 */
247*9d71dd0cSThe j1939 authors 	u8 last_cmd, last_txcmd;
248*9d71dd0cSThe j1939 authors 	bool transmission;
249*9d71dd0cSThe j1939 authors 	bool extd;
250*9d71dd0cSThe j1939 authors 	/* Total message size, number of bytes */
251*9d71dd0cSThe j1939 authors 	unsigned int total_message_size;
252*9d71dd0cSThe j1939 authors 	/* Total number of bytes queue from socket to the session */
253*9d71dd0cSThe j1939 authors 	unsigned int total_queued_size;
254*9d71dd0cSThe j1939 authors 	unsigned int tx_retry;
255*9d71dd0cSThe j1939 authors 
256*9d71dd0cSThe j1939 authors 	int err;
257*9d71dd0cSThe j1939 authors 	u32 tskey;
258*9d71dd0cSThe j1939 authors 	enum j1939_session_state state;
259*9d71dd0cSThe j1939 authors 
260*9d71dd0cSThe j1939 authors 	/* Packets counters for a (extended) transfer session. The packet is
261*9d71dd0cSThe j1939 authors 	 * maximal of 7 bytes.
262*9d71dd0cSThe j1939 authors 	 */
263*9d71dd0cSThe j1939 authors 	struct {
264*9d71dd0cSThe j1939 authors 		/* total - total number of packets for this session */
265*9d71dd0cSThe j1939 authors 		unsigned int total;
266*9d71dd0cSThe j1939 authors 		/* last - last packet of a transfer block after which
267*9d71dd0cSThe j1939 authors 		 * responder should send ETP.CM_CTS and originator
268*9d71dd0cSThe j1939 authors 		 * ETP.CM_DPO
269*9d71dd0cSThe j1939 authors 		 */
270*9d71dd0cSThe j1939 authors 		unsigned int last;
271*9d71dd0cSThe j1939 authors 		/* tx - number of packets send by originator node.
272*9d71dd0cSThe j1939 authors 		 * this counter can be set back if responder node
273*9d71dd0cSThe j1939 authors 		 * didn't received all packets send by originator.
274*9d71dd0cSThe j1939 authors 		 */
275*9d71dd0cSThe j1939 authors 		unsigned int tx;
276*9d71dd0cSThe j1939 authors 		unsigned int tx_acked;
277*9d71dd0cSThe j1939 authors 		/* rx - number of packets received */
278*9d71dd0cSThe j1939 authors 		unsigned int rx;
279*9d71dd0cSThe j1939 authors 		/* block - amount of packets expected in one block */
280*9d71dd0cSThe j1939 authors 		unsigned int block;
281*9d71dd0cSThe j1939 authors 		/* dpo - ETP.CM_DPO, Data Packet Offset */
282*9d71dd0cSThe j1939 authors 		unsigned int dpo;
283*9d71dd0cSThe j1939 authors 	} pkt;
284*9d71dd0cSThe j1939 authors 	struct hrtimer txtimer, rxtimer;
285*9d71dd0cSThe j1939 authors };
286*9d71dd0cSThe j1939 authors 
287*9d71dd0cSThe j1939 authors struct j1939_sock {
288*9d71dd0cSThe j1939 authors 	struct sock sk; /* must be first to skip with memset */
289*9d71dd0cSThe j1939 authors 	struct j1939_priv *priv;
290*9d71dd0cSThe j1939 authors 	struct list_head list;
291*9d71dd0cSThe j1939 authors 
292*9d71dd0cSThe j1939 authors #define J1939_SOCK_BOUND BIT(0)
293*9d71dd0cSThe j1939 authors #define J1939_SOCK_CONNECTED BIT(1)
294*9d71dd0cSThe j1939 authors #define J1939_SOCK_PROMISC BIT(2)
295*9d71dd0cSThe j1939 authors #define J1939_SOCK_ERRQUEUE BIT(3)
296*9d71dd0cSThe j1939 authors 	int state;
297*9d71dd0cSThe j1939 authors 
298*9d71dd0cSThe j1939 authors 	int ifindex;
299*9d71dd0cSThe j1939 authors 	struct j1939_addr addr;
300*9d71dd0cSThe j1939 authors 	struct j1939_filter *filters;
301*9d71dd0cSThe j1939 authors 	int nfilters;
302*9d71dd0cSThe j1939 authors 	pgn_t pgn_rx_filter;
303*9d71dd0cSThe j1939 authors 
304*9d71dd0cSThe j1939 authors 	/* j1939 may emit equal PGN (!= equal CAN-id's) out of order
305*9d71dd0cSThe j1939 authors 	 * when transport protocol comes in.
306*9d71dd0cSThe j1939 authors 	 * To allow emitting in order, keep a 'pending' nr. of packets
307*9d71dd0cSThe j1939 authors 	 */
308*9d71dd0cSThe j1939 authors 	atomic_t skb_pending;
309*9d71dd0cSThe j1939 authors 	wait_queue_head_t waitq;
310*9d71dd0cSThe j1939 authors 
311*9d71dd0cSThe j1939 authors 	/* lock for the sk_session_queue list */
312*9d71dd0cSThe j1939 authors 	spinlock_t sk_session_queue_lock;
313*9d71dd0cSThe j1939 authors 	struct list_head sk_session_queue;
314*9d71dd0cSThe j1939 authors };
315*9d71dd0cSThe j1939 authors 
316*9d71dd0cSThe j1939 authors static inline struct j1939_sock *j1939_sk(const struct sock *sk)
317*9d71dd0cSThe j1939 authors {
318*9d71dd0cSThe j1939 authors 	return container_of(sk, struct j1939_sock, sk);
319*9d71dd0cSThe j1939 authors }
320*9d71dd0cSThe j1939 authors 
321*9d71dd0cSThe j1939 authors void j1939_session_get(struct j1939_session *session);
322*9d71dd0cSThe j1939 authors void j1939_session_put(struct j1939_session *session);
323*9d71dd0cSThe j1939 authors void j1939_session_skb_queue(struct j1939_session *session,
324*9d71dd0cSThe j1939 authors 			     struct sk_buff *skb);
325*9d71dd0cSThe j1939 authors int j1939_session_activate(struct j1939_session *session);
326*9d71dd0cSThe j1939 authors void j1939_tp_schedule_txtimer(struct j1939_session *session, int msec);
327*9d71dd0cSThe j1939 authors void j1939_session_timers_cancel(struct j1939_session *session);
328*9d71dd0cSThe j1939 authors 
329*9d71dd0cSThe j1939 authors #define J1939_MAX_TP_PACKET_SIZE (7 * 0xff)
330*9d71dd0cSThe j1939 authors #define J1939_MAX_ETP_PACKET_SIZE (7 * 0x00ffffff)
331*9d71dd0cSThe j1939 authors 
332*9d71dd0cSThe j1939 authors #define J1939_REGULAR 0
333*9d71dd0cSThe j1939 authors #define J1939_EXTENDED 1
334*9d71dd0cSThe j1939 authors 
335*9d71dd0cSThe j1939 authors /* CAN protocol */
336*9d71dd0cSThe j1939 authors extern const struct can_proto j1939_can_proto;
337*9d71dd0cSThe j1939 authors 
338*9d71dd0cSThe j1939 authors #endif /* _J1939_PRIV_H_ */
339