This source file includes following definitions.
- j1939_address_is_unicast
- j1939_address_is_idle
- j1939_address_is_valid
- j1939_pgn_is_pdu1
- j1939_skb_to_cb
- j1939_sk
1
2
3
4
5
6
7
8
9 #ifndef _J1939_PRIV_H_
10 #define _J1939_PRIV_H_
11
12 #include <linux/can/j1939.h>
13 #include <net/sock.h>
14
15
16
17
18 #define J1939_XTP_ABORT_TIMEOUT_MS 500
19 #define J1939_SIMPLE_ECHO_TIMEOUT_MS (10 * 1000)
20
21 struct j1939_session;
22 enum j1939_sk_errqueue_type {
23 J1939_ERRQUEUE_ACK,
24 J1939_ERRQUEUE_SCHED,
25 J1939_ERRQUEUE_ABORT,
26 };
27
28
29 struct j1939_ecu {
30 struct list_head list;
31 name_t name;
32 u8 addr;
33
34
35 struct hrtimer ac_timer;
36 struct kref kref;
37 struct j1939_priv *priv;
38
39
40 int nusers;
41 };
42
43 struct j1939_priv {
44 struct list_head ecus;
45
46
47
48
49
50
51
52
53
54
55
56
57 rwlock_t lock;
58
59 struct net_device *ndev;
60
61
62
63
64 struct j1939_addr_ent {
65 struct j1939_ecu *ecu;
66
67 int nusers;
68 } ents[256];
69
70 struct kref kref;
71
72
73
74
75
76
77
78 struct list_head active_session_list;
79
80
81 spinlock_t active_session_list_lock;
82
83 unsigned int tp_max_packet_size;
84
85
86 spinlock_t j1939_socks_lock;
87 struct list_head j1939_socks;
88
89 struct kref rx_kref;
90 };
91
92 void j1939_ecu_put(struct j1939_ecu *ecu);
93
94
95 int j1939_local_ecu_get(struct j1939_priv *priv, name_t name, u8 sa);
96 void j1939_local_ecu_put(struct j1939_priv *priv, name_t name, u8 sa);
97
98 static inline bool j1939_address_is_unicast(u8 addr)
99 {
100 return addr <= J1939_MAX_UNICAST_ADDR;
101 }
102
103 static inline bool j1939_address_is_idle(u8 addr)
104 {
105 return addr == J1939_IDLE_ADDR;
106 }
107
108 static inline bool j1939_address_is_valid(u8 addr)
109 {
110 return addr != J1939_NO_ADDR;
111 }
112
113 static inline bool j1939_pgn_is_pdu1(pgn_t pgn)
114 {
115
116 return (pgn & 0xff00) < 0xf000;
117 }
118
119
120 void j1939_ecu_unmap_locked(struct j1939_ecu *ecu);
121 void j1939_ecu_unmap(struct j1939_ecu *ecu);
122
123 u8 j1939_name_to_addr(struct j1939_priv *priv, name_t name);
124 struct j1939_ecu *j1939_ecu_find_by_addr_locked(struct j1939_priv *priv,
125 u8 addr);
126 struct j1939_ecu *j1939_ecu_get_by_addr(struct j1939_priv *priv, u8 addr);
127 struct j1939_ecu *j1939_ecu_get_by_addr_locked(struct j1939_priv *priv,
128 u8 addr);
129 struct j1939_ecu *j1939_ecu_get_by_name(struct j1939_priv *priv, name_t name);
130 struct j1939_ecu *j1939_ecu_get_by_name_locked(struct j1939_priv *priv,
131 name_t name);
132
133 enum j1939_transfer_type {
134 J1939_TP,
135 J1939_ETP,
136 J1939_SIMPLE,
137 };
138
139 struct j1939_addr {
140 name_t src_name;
141 name_t dst_name;
142 pgn_t pgn;
143
144 u8 sa;
145 u8 da;
146
147 u8 type;
148 };
149
150
151 struct j1939_sk_buff_cb {
152
153 u32 offset;
154
155
156 u32 msg_flags;
157 u32 tskey;
158
159 struct j1939_addr addr;
160
161
162
163
164 #define J1939_ECU_LOCAL_SRC BIT(0)
165 #define J1939_ECU_LOCAL_DST BIT(1)
166 u8 flags;
167
168 priority_t priority;
169 };
170
171 static inline
172 struct j1939_sk_buff_cb *j1939_skb_to_cb(const struct sk_buff *skb)
173 {
174 BUILD_BUG_ON(sizeof(struct j1939_sk_buff_cb) > sizeof(skb->cb));
175
176 return (struct j1939_sk_buff_cb *)skb->cb;
177 }
178
179 int j1939_send_one(struct j1939_priv *priv, struct sk_buff *skb);
180 void j1939_sk_recv(struct j1939_priv *priv, struct sk_buff *skb);
181 bool j1939_sk_recv_match(struct j1939_priv *priv,
182 struct j1939_sk_buff_cb *skcb);
183 void j1939_sk_send_loop_abort(struct sock *sk, int err);
184 void j1939_sk_errqueue(struct j1939_session *session,
185 enum j1939_sk_errqueue_type type);
186 void j1939_sk_queue_activate_next(struct j1939_session *session);
187
188
189 struct j1939_session *j1939_tp_send(struct j1939_priv *priv,
190 struct sk_buff *skb, size_t size);
191 int j1939_tp_recv(struct j1939_priv *priv, struct sk_buff *skb);
192 int j1939_ac_fixup(struct j1939_priv *priv, struct sk_buff *skb);
193 void j1939_ac_recv(struct j1939_priv *priv, struct sk_buff *skb);
194 void j1939_simple_recv(struct j1939_priv *priv, struct sk_buff *skb);
195
196
197 struct j1939_ecu *j1939_ecu_create_locked(struct j1939_priv *priv, name_t name);
198
199 void j1939_ecu_timer_start(struct j1939_ecu *ecu);
200 void j1939_ecu_timer_cancel(struct j1939_ecu *ecu);
201 void j1939_ecu_unmap_all(struct j1939_priv *priv);
202
203 struct j1939_priv *j1939_netdev_start(struct net_device *ndev);
204 void j1939_netdev_stop(struct j1939_priv *priv);
205
206 void j1939_priv_put(struct j1939_priv *priv);
207 void j1939_priv_get(struct j1939_priv *priv);
208
209
210 void j1939_sk_netdev_event_netdown(struct j1939_priv *priv);
211 int j1939_cancel_active_session(struct j1939_priv *priv, struct sock *sk);
212 void j1939_tp_init(struct j1939_priv *priv);
213
214
215 void j1939_sock_pending_del(struct sock *sk);
216
217 enum j1939_session_state {
218 J1939_SESSION_NEW,
219 J1939_SESSION_ACTIVE,
220
221 J1939_SESSION_WAITING_ABORT,
222 J1939_SESSION_ACTIVE_MAX,
223 J1939_SESSION_DONE,
224 };
225
226 struct j1939_session {
227 struct j1939_priv *priv;
228 struct list_head active_session_list_entry;
229 struct list_head sk_session_queue_entry;
230 struct kref kref;
231 struct sock *sk;
232
233
234
235
236
237 struct j1939_sk_buff_cb skcb;
238 struct sk_buff_head skb_queue;
239
240
241
242
243
244
245
246
247 u8 last_cmd, last_txcmd;
248 bool transmission;
249 bool extd;
250
251 unsigned int total_message_size;
252
253 unsigned int total_queued_size;
254 unsigned int tx_retry;
255
256 int err;
257 u32 tskey;
258 enum j1939_session_state state;
259
260
261
262
263 struct {
264
265 unsigned int total;
266
267
268
269
270 unsigned int last;
271
272
273
274
275 unsigned int tx;
276 unsigned int tx_acked;
277
278 unsigned int rx;
279
280 unsigned int block;
281
282 unsigned int dpo;
283 } pkt;
284 struct hrtimer txtimer, rxtimer;
285 };
286
287 struct j1939_sock {
288 struct sock sk;
289 struct j1939_priv *priv;
290 struct list_head list;
291
292 #define J1939_SOCK_BOUND BIT(0)
293 #define J1939_SOCK_CONNECTED BIT(1)
294 #define J1939_SOCK_PROMISC BIT(2)
295 #define J1939_SOCK_ERRQUEUE BIT(3)
296 int state;
297
298 int ifindex;
299 struct j1939_addr addr;
300 struct j1939_filter *filters;
301 int nfilters;
302 pgn_t pgn_rx_filter;
303
304
305
306
307
308 atomic_t skb_pending;
309 wait_queue_head_t waitq;
310
311
312 spinlock_t sk_session_queue_lock;
313 struct list_head sk_session_queue;
314 };
315
316 static inline struct j1939_sock *j1939_sk(const struct sock *sk)
317 {
318 return container_of(sk, struct j1939_sock, sk);
319 }
320
321 void j1939_session_get(struct j1939_session *session);
322 void j1939_session_put(struct j1939_session *session);
323 void j1939_session_skb_queue(struct j1939_session *session,
324 struct sk_buff *skb);
325 int j1939_session_activate(struct j1939_session *session);
326 void j1939_tp_schedule_txtimer(struct j1939_session *session, int msec);
327 void j1939_session_timers_cancel(struct j1939_session *session);
328
329 #define J1939_MAX_TP_PACKET_SIZE (7 * 0xff)
330 #define J1939_MAX_ETP_PACKET_SIZE (7 * 0x00ffffff)
331
332 #define J1939_REGULAR 0
333 #define J1939_EXTENDED 1
334
335
336 extern const struct can_proto j1939_can_proto;
337
338 #endif