isotp.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 OTA keys S.A.
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser General
5  * Public License v2.1. See the file LICENSE in the top level directory for more
6  * details.
7  */
8 
21 #ifndef CAN_ISOTP_H
22 #define CAN_ISOTP_H
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #include "can/can.h"
29 #include "can/common.h"
30 #include "thread.h"
31 #include "xtimer.h"
32 #include "net/gnrc/pktbuf.h"
33 
34 #ifndef CAN_ISOTP_BS
35 
38 #define CAN_ISOTP_BS (10)
39 #endif
40 
41 #ifndef CAN_ISOTP_STMIN
42 
45 #define CAN_ISOTP_STMIN (5)
46 #endif
47 
48 #ifndef CAN_ISOTP_WFTMAX
49 
52 #define CAN_ISOTP_WFTMAX (1)
53 #endif
54 
61  uint8_t bs;
68  uint8_t stmin;
69 
70  uint8_t wftmax;
71 };
72 
78 struct isotp_options {
81  uint16_t flags;
82  uint8_t ext_address;
83  uint8_t txpad_content;
84  uint8_t rx_ext_address;
85 };
86 
92 struct tpcon {
93  unsigned idx;
94  uint8_t state;
95  uint8_t bs;
96  uint8_t sn;
97  int tx_handle;
99 };
100 
106 struct isotp {
107  struct isotp *next;
111  struct tpcon tx;
112  struct tpcon rx;
116  uint32_t tx_gap;
117  uint8_t tx_wft;
118  void *arg;
119 };
120 
125 #define CAN_ISOTP_RX_FLAGS_MASK 0x0000FFFF
126 #define CAN_ISOTP_LISTEN_MODE 0x0001
127 #define CAN_ISOTP_EXTEND_ADDR 0x0002
128 #define CAN_ISOTP_TX_PADDING 0x0004
129 #define CAN_ISOTP_HALF_DUPLEX 0x0040
130 #define CAN_ISOTP_RX_EXT_ADDR 0x0200
132 #define CAN_ISOTP_TX_FLAGS_MASK 0xFFFF0000
133 #define CAN_ISOTP_TX_DONT_WAIT 0x00010000
140 #define CAN_ISOTP_DEFAULT_FLAGS 0
141 #define CAN_ISOTP_DEFAULT_EXT_ADDRESS 0x00
142 #define CAN_ISOTP_DEFAULT_PAD_CONTENT 0xCC /* prevent bit-stuffing */
143 #define CAN_ISOTP_DEFAULT_FRAME_TXTIME 0
144 #define CAN_ISOTP_DEFAULT_RECV_BS 0
145 #define CAN_ISOTP_DEFAULT_RECV_STMIN 0x00
146 #define CAN_ISOTP_DEFAULT_RECV_WFTMAX 0
147 
159 kernel_pid_t isotp_init(char *stack, int stacksize, char priority, const char *name);
160 
172 int isotp_send(struct isotp *isotp, const void *buf, int len, int flags);
173 
189 int isotp_bind(struct isotp *isotp, can_reg_entry_t *entry, void *arg,
190  struct isotp_fc_options *fc_options);
191 
202 int isotp_release(struct isotp *isotp);
203 
211 void isotp_free_rx(can_rx_data_t *rx);
212 
213 #ifdef __cplusplus
214 }
215 #endif
216 
217 #endif /* CAN_ISOTP_H */
218 
tpcon::sn
uint8_t sn
current sequence number
Definition: isotp.h:96
kernel_pid_t
int16_t kernel_pid_t
Unique process identifier.
Definition: sched.h:125
xtimer
xtimer timer structure
Definition: xtimer.h:81
tpcon::idx
unsigned idx
current index in buf
Definition: isotp.h:93
tpcon::tx_handle
int tx_handle
handle of the last sent frame
Definition: isotp.h:97
isotp_send
int isotp_send(struct isotp *isotp, const void *buf, int len, int flags)
Send data through an isotp channel.
isotp::next
struct isotp * next
next bound channel
Definition: isotp.h:107
isotp::arg
void * arg
upper layer private arg
Definition: isotp.h:118
can_rx_data
Received data structure.
Definition: common.h:122
isotp_options::ext_address
uint8_t ext_address
set address for extended addressing
Definition: isotp.h:82
tpcon
The tpcon struct.
Definition: isotp.h:92
isotp::txfc
struct isotp_fc_options txfc
tx flow control options (defined remotely)
Definition: isotp.h:110
isotp_init
kernel_pid_t isotp_init(char *stack, int stacksize, char priority, const char *name)
Initialize the isotp layer.
isotp::tx_timer
xtimer_t tx_timer
timer for tx operations
Definition: isotp.h:113
isotp_options
The isotp_options struct.
Definition: isotp.h:78
isotp::tx_gap
uint32_t tx_gap
transmit gap from fc (in us)
Definition: isotp.h:116
can.h
Definitions high-level CAN interface.
isotp::opt
struct isotp_options opt
channel options
Definition: isotp.h:108
isotp::rx
struct tpcon rx
receive state
Definition: isotp.h:112
isotp_fc_options::stmin
uint8_t stmin
separation time provided in FC frame 0x00 - 0x7F : 0 - 127 ms 0x80 - 0xF0 : reserved 0xF1 - 0xF9 : 10...
Definition: isotp.h:68
tpcon::state
uint8_t state
the protocol state
Definition: isotp.h:94
isotp_free_rx
void isotp_free_rx(can_rx_data_t *rx)
Free a received buffer.
common.h
Definitions of high-level CAN interface.
isotp_options::rx_id
canid_t rx_id
Receive CAN ID.
Definition: isotp.h:80
isotp_options::txpad_content
uint8_t txpad_content
set content of padding byte (tx)
Definition: isotp.h:83
tpcon::snip
gnrc_pktsnip_t * snip
allocated snip containing data buffer
Definition: isotp.h:98
isotp::entry
can_reg_entry_t entry
entry containing ifnum and upper layer msg system
Definition: isotp.h:115
isotp
The isotp struct.
Definition: isotp.h:106
isotp::tx
struct tpcon tx
transmit state
Definition: isotp.h:111
isotp_fc_options
The isotp_fc_options struct.
Definition: isotp.h:60
isotp_fc_options::wftmax
uint8_t wftmax
max.
Definition: isotp.h:70
isotp_bind
int isotp_bind(struct isotp *isotp, can_reg_entry_t *entry, void *arg, struct isotp_fc_options *fc_options)
Bind an isotp channel.
isotp::tx_wft
uint8_t tx_wft
transmit wait counter
Definition: isotp.h:117
pktbuf.h
Interface definition for the global network buffer. Network devices and layers can allocate space for...
tpcon::bs
uint8_t bs
block size
Definition: isotp.h:95
isotp_options::tx_id
canid_t tx_id
transmit CAN ID
Definition: isotp.h:79
isotp::rx_timer
xtimer_t rx_timer
timer for rx operations
Definition: isotp.h:114
can_reg_entry
registry entry
Definition: common.h:143
isotp_release
int isotp_release(struct isotp *isotp)
Release a bound isotp channel.
isotp::rxfc
struct isotp_fc_options rxfc
rx flow control options (defined locally)
Definition: isotp.h:109
isotp_options::rx_ext_address
uint8_t rx_ext_address
set address for extended addressing
Definition: isotp.h:84
isotp_fc_options::bs
uint8_t bs
blocksize provided in FC frame, 0 = off
Definition: isotp.h:61
isotp_options::flags
uint16_t flags
set flags for isotp behaviour.
Definition: isotp.h:81
xtimer.h
xtimer interface definitions
gnrc_pktsnip
Type to represent parts (either headers or payload) of a packet, called snips.
Definition: pkt.h:108
canid_t
uint32_t canid_t
Controller Area Network Identifier structure.
Definition: can.h:83