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