isotp.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2016 OTA keys S.A.
3  * SPDX-License-Identifier: LGPL-2.1-only
4  */
5 
6 #pragma once
7 
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23 
24 #include "can/can.h"
25 #include "can/common.h"
26 #include "thread.h"
27 #include "ztimer.h"
28 #include "net/gnrc/pktbuf.h"
29 
30 #ifndef CAN_ISOTP_BS
34 #define CAN_ISOTP_BS (10)
35 #endif
36 
37 #ifndef CAN_ISOTP_STMIN
41 #define CAN_ISOTP_STMIN (5)
42 #endif
43 
44 #ifndef CAN_ISOTP_WFTMAX
48 #define CAN_ISOTP_WFTMAX (1)
49 #endif
50 
57  uint8_t bs;
64  uint8_t stmin;
65 
66  uint8_t wftmax;
67 };
68 
74 struct isotp_options {
77  uint16_t flags;
78  uint8_t ext_address;
79  uint8_t txpad_content;
80  uint8_t rx_ext_address;
81 };
82 
88 struct tpcon {
89  unsigned idx;
90  uint8_t state;
91  uint8_t bs;
92  uint8_t sn;
93  int tx_handle;
95 };
96 
102 struct isotp {
103  struct isotp *next;
104  struct isotp_options opt;
105  struct isotp_fc_options rxfc;
106  struct isotp_fc_options txfc;
107  struct tpcon tx;
108  struct tpcon rx;
112  uint32_t tx_gap;
113  uint8_t tx_wft;
114  void *arg;
115 };
116 
121 #define CAN_ISOTP_RX_FLAGS_MASK 0x0000FFFF
122 #define CAN_ISOTP_LISTEN_MODE 0x0001
123 #define CAN_ISOTP_EXTEND_ADDR 0x0002
124 #define CAN_ISOTP_TX_PADDING 0x0004
125 #define CAN_ISOTP_HALF_DUPLEX 0x0040
126 #define CAN_ISOTP_RX_EXT_ADDR 0x0200
128 #define CAN_ISOTP_TX_FLAGS_MASK 0xFFFF0000
129 #define CAN_ISOTP_TX_DONT_WAIT 0x00010000
136 #define CAN_ISOTP_DEFAULT_FLAGS 0
137 #define CAN_ISOTP_DEFAULT_EXT_ADDRESS 0x00
138 #define CAN_ISOTP_DEFAULT_PAD_CONTENT 0xCC /* prevent bit-stuffing */
139 #define CAN_ISOTP_DEFAULT_FRAME_TXTIME 0
140 #define CAN_ISOTP_DEFAULT_RECV_BS 0
141 #define CAN_ISOTP_DEFAULT_RECV_STMIN 0x00
142 #define CAN_ISOTP_DEFAULT_RECV_WFTMAX 0
155 kernel_pid_t isotp_init(char *stack, int stacksize, char priority, const char *name);
156 
168 int isotp_send(struct isotp *isotp, const void *buf, int len, int flags);
169 
185 int isotp_bind(struct isotp *isotp, can_reg_entry_t *entry, void *arg,
186  struct isotp_fc_options *fc_options);
187 
198 int isotp_release(struct isotp *isotp);
199 
208 
209 #ifdef __cplusplus
210 }
211 #endif
212 
int16_t kernel_pid_t
Unique process identifier.
Definition: sched.h:135
uint32_t canid_t
Controller Area Network Identifier structure.
Definition: can.h:92
int isotp_release(struct isotp *isotp)
Release a bound isotp channel.
int isotp_send(struct isotp *isotp, const void *buf, int len, int flags)
Send data through an isotp channel.
kernel_pid_t isotp_init(char *stack, int stacksize, char priority, const char *name)
Initialize the isotp layer.
void isotp_free_rx(can_rx_data_t *rx)
Free a received buffer.
int isotp_bind(struct isotp *isotp, can_reg_entry_t *entry, void *arg, struct isotp_fc_options *fc_options)
Bind an isotp channel.
Interface definition for the global network buffer.
registry entry
Definition: common.h:152
Received data structure.
Definition: common.h:131
Type to represent parts (either headers or payload) of a packet, called snips.
Definition: pkt.h:105
The isotp_fc_options struct.
Definition: isotp.h:56
uint8_t wftmax
max.
Definition: isotp.h:66
uint8_t bs
blocksize provided in FC frame, 0 = off
Definition: isotp.h:57
uint8_t stmin
separation time provided in FC frame 0x00 - 0x7F : 0 - 127 ms 0x80 - 0xF0 : reserved 0xF1 - 0xF9 : 10...
Definition: isotp.h:64
The isotp_options struct.
Definition: isotp.h:74
uint8_t txpad_content
set content of padding byte (tx)
Definition: isotp.h:79
uint8_t rx_ext_address
set address for extended addressing
Definition: isotp.h:80
canid_t rx_id
Receive CAN ID.
Definition: isotp.h:76
uint8_t ext_address
set address for extended addressing
Definition: isotp.h:78
uint16_t flags
set flags for isotp behaviour.
Definition: isotp.h:77
canid_t tx_id
transmit CAN ID
Definition: isotp.h:75
The isotp struct.
Definition: isotp.h:102
struct isotp_options opt
channel options
Definition: isotp.h:104
uint8_t tx_wft
transmit wait counter
Definition: isotp.h:113
void * arg
upper layer private arg
Definition: isotp.h:114
struct isotp_fc_options rxfc
rx flow control options (defined locally)
Definition: isotp.h:105
struct isotp * next
next bound channel
Definition: isotp.h:103
ztimer_t rx_timer
timer for rx operations
Definition: isotp.h:110
struct isotp_fc_options txfc
tx flow control options (defined remotely)
Definition: isotp.h:106
ztimer_t tx_timer
timer for tx operations
Definition: isotp.h:109
struct tpcon rx
receive state
Definition: isotp.h:108
uint32_t tx_gap
transmit gap from fc (in us)
Definition: isotp.h:112
struct tpcon tx
transmit state
Definition: isotp.h:107
can_reg_entry_t entry
entry containing ifnum and upper layer msg system
Definition: isotp.h:111
The tpcon struct.
Definition: isotp.h:88
unsigned idx
current index in buf
Definition: isotp.h:89
gnrc_pktsnip_t * snip
allocated snip containing data buffer
Definition: isotp.h:94
uint8_t sn
current sequence number
Definition: isotp.h:92
uint8_t state
the protocol state
Definition: isotp.h:90
uint8_t bs
block size
Definition: isotp.h:91
int tx_handle
handle of the last sent frame
Definition: isotp.h:93
ztimer structure
Definition: ztimer.h:316
Definitions high-level CAN interface.
Definitions of high-level CAN interface.
ztimer API