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 
41  uint8_t bs;
48  uint8_t stmin;
49 
50  uint8_t wftmax;
51 };
52 
58 struct isotp_options {
61  uint16_t flags;
62  uint8_t ext_address;
63  uint8_t txpad_content;
64  uint8_t rx_ext_address;
65 };
66 
72 struct tpcon {
73  unsigned idx;
74  uint8_t state;
75  uint8_t bs;
76  uint8_t sn;
77  int tx_handle;
79 };
80 
86 struct isotp {
87  struct isotp *next;
88  struct isotp_options opt;
89  struct isotp_fc_options rxfc;
90  struct isotp_fc_options txfc;
91  struct tpcon tx;
92  struct tpcon rx;
96  uint32_t tx_gap;
97  uint8_t tx_wft;
98  void *arg;
99 };
100 
105 #define CAN_ISOTP_RX_FLAGS_MASK 0x0000FFFF
106 #define CAN_ISOTP_LISTEN_MODE 0x0001
107 #define CAN_ISOTP_EXTEND_ADDR 0x0002
108 #define CAN_ISOTP_TX_PADDING 0x0004
109 #define CAN_ISOTP_HALF_DUPLEX 0x0040
110 #define CAN_ISOTP_RX_EXT_ADDR 0x0200
112 #define CAN_ISOTP_TX_FLAGS_MASK 0xFFFF0000
113 #define CAN_ISOTP_TX_DONT_WAIT 0x00010000
120 #define CAN_ISOTP_DEFAULT_FLAGS 0
121 #define CAN_ISOTP_DEFAULT_EXT_ADDRESS 0x00
122 #define CAN_ISOTP_DEFAULT_PAD_CONTENT 0xCC /* prevent bit-stuffing */
123 #define CAN_ISOTP_DEFAULT_FRAME_TXTIME 0
124 #define CAN_ISOTP_DEFAULT_RECV_BS 0
125 #define CAN_ISOTP_DEFAULT_RECV_STMIN 0x00
126 #define CAN_ISOTP_DEFAULT_RECV_WFTMAX 0
127 
139 kernel_pid_t isotp_init(char *stack, int stacksize, char priority, const char *name);
140 
152 int isotp_send(struct isotp *isotp, const void *buf, int len, int flags);
153 
167 int isotp_bind(struct isotp *isotp, can_reg_entry_t *entry, void *arg);
168 
179 int isotp_release(struct isotp *isotp);
180 
188 void isotp_free_rx(can_rx_data_t *rx);
189 
190 #ifdef __cplusplus
191 }
192 #endif
193 
194 #endif /* CAN_ISOTP_H */
195 
void isotp_free_rx(can_rx_data_t *rx)
Free a received buffer.
uint8_t bs
blocksize provided in FC frame, 0 = off
Definition: isotp.h:41
uint8_t stmin
separation time provided in FC frame 0x00 - 0x7F : 0 - 127 ms 0x80 - 0xF0 : reserved 0xF1 - 0xF9 : 10...
Definition: isotp.h:48
uint8_t state
the protocol state
Definition: isotp.h:74
gnrc_pktsnip_t * snip
allocated snip containing data buffer
Definition: isotp.h:78
xtimer_t tx_timer
timer for tx operations
Definition: isotp.h:93
int16_t kernel_pid_t
Unique process identifier.
Definition: kernel_types.h:83
uint32_t canid_t
Controller Area Network Identifier structure.
Definition: can.h:83
can_reg_entry_t entry
entry containing ifnum and upper layer msg system
Definition: isotp.h:95
void * arg
upper layer private arg
Definition: isotp.h:98
Received data structure.
kernel_pid_t isotp_init(char *stack, int stacksize, char priority, const char *name)
Initialize the isotp layer.
struct isotp * next
next bound channel
Definition: isotp.h:87
uint8_t wftmax
max.
Definition: isotp.h:50
Interface definition for the global network buffer.
uint8_t rx_ext_address
set address for extended addressing
Definition: isotp.h:64
The isotp_options struct.
Definition: isotp.h:58
Definitions of high-level CAN interface.
Threading API.
uint32_t tx_gap
transmit gap from fc (in us)
Definition: isotp.h:96
registry entry
uint8_t tx_wft
transmit wait counter
Definition: isotp.h:97
uint8_t bs
block size
Definition: isotp.h:75
int isotp_release(struct isotp *isotp)
Release a bound isotp channel.
xtimer interface definitions
int isotp_bind(struct isotp *isotp, can_reg_entry_t *entry, void *arg)
Bind an isotp channel.
The isotp_fc_options struct.
Definition: isotp.h:40
int tx_handle
handle of the last sent frame
Definition: isotp.h:77
uint8_t ext_address
set address for extended addressing
Definition: isotp.h:62
xtimer_t rx_timer
timer for rx operations
Definition: isotp.h:94
uint8_t txpad_content
set content of padding byte (tx)
Definition: isotp.h:63
int isotp_send(struct isotp *isotp, const void *buf, int len, int flags)
Send data through an isotp channel.
Type to represent parts (either headers or payload) of a packet, called snips.
xtimer timer structure
Definition: xtimer.h:70
canid_t rx_id
Receive CAN ID.
Definition: isotp.h:60
The isotp struct.
Definition: isotp.h:86
Definitions high-level CAN interface.
The tpcon struct.
Definition: isotp.h:72
uint8_t sn
current sequence number
Definition: isotp.h:76
unsigned idx
current index in buf
Definition: isotp.h:73
uint16_t flags
set flags for isotp behaviour.
Definition: isotp.h:61
canid_t tx_id
transmit CAN ID
Definition: isotp.h:59