blob: b2fbde232bb40895191a72657919f91a45c8154b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
#ifndef __VAG_BAP_H__
#define __VAG_BAP_H__
#include <stdio.h>
#define VAG_DEBUG(...) do { fprintf(stdout, __VA_ARGS__); } while(0)
#include <linux/can.h>
typedef unsigned char BAP_OpCode;
typedef unsigned char BAP_Node;
typedef unsigned char BAP_Port;
typedef unsigned short BAP_FrameLen;
/* A BAP frame at the BCL (BAP communication layer) as defined in
* http://www.itwissen.info/BCL-BAP-communication-layer.html
*
* This is basically BAP's equivalent of IP and TCP.
*/
struct BAP_Frame {
/* True if frame was/will be transmitted in multi-frame syntax */
int is_multiframe;
/* Request/reply, kind of */
BAP_OpCode opcode;
/* LSG = Logisches Steuergeraet
* https://www.springerprofessional.de/technische-informatik/eingebettete-systeme/neues-protokoll-vereinfacht-kommunikation-von-steuergeraeten/6592480
*
* BAP's equivalent of an IP address (to be confirmed).
*
* Always the same per CAN ID in the (simple) devices I looked at.
*/
BAP_Node node;
/* The "RPC" port, or "status register" ID.
*
* BAP's equivalent of a "UDP port".
*/
BAP_Port port;
/* Payload length, up to 2^12-1 = 4095 bytes. */
BAP_FrameLen len;
/* Payload */
char data[4096];
};
struct BAP_RXer {
/* Temporary storage for incomplete frames */
struct BAP_Frame *mfchannel[8];
/* How many bytes have we already received on each channel? */
BAP_FrameLen len_done[8];
};
struct BAP_TXer {
/* Temporary storage for frames not yet fully sent */
struct BAP_Frame *slot[4];
/* How many bytes have we already sent on each open slot? */
BAP_FrameLen slot_done[4];
};
/* BAP frame struct handling */
struct BAP_Frame* vag_bap_frame_alloc(void);
void vag_bap_frame_free(struct BAP_Frame *bap_frame);
int vag_bap_frame_is_valid(struct BAP_Frame *bap_frame);
struct BAP_Frame* vag_bap_frame_clone(struct BAP_Frame *bap_frame);
void vag_bap_frame_dump(struct BAP_Frame *bap_frame);
/* BAP reception */
struct BAP_Frame* vag_bap_handle_can_frame(struct BAP_RXer *bap, struct can_frame *frame);
struct BAP_RXer* vag_bap_rxer_alloc();
void vag_bap_rxer_free(struct BAP_RXer *bap);
/* BAP transmission */
int vag_bap_txer_queue(struct BAP_TXer* bap, struct BAP_Frame *bap_frame, struct can_frame *frame);
struct BAP_TXer* vag_bap_txer_alloc();
void vag_bap_txer_free(struct BAP_TXer *bap);
#endif
|