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