BOROSOFTWAREAll work →
scantool/diag_l3_vag.c 141 lines
1/*
2 * !!! INCOMPLETE !!!!
3 *
4 * freediag - Vehicle Diagnostic Utility
5 *
6 *
7 * Copyright (C) 2001 Richard Almeida & Ibex Ltd ([email protected])
8 * Copyright (C) 2004 Steve Meisner <[email protected]>
9 * Copyright (C) 2014-2015 fenugrec <[email protected]>
10 * Copyright (C) 2015 - 2016 Tomasz Kaźmierczak <[email protected]>
11 *
12 * This program is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 *
25 *************************************************************************
26 *
27 * Diag
28 *
29 * L3 driver for Volkswagen Aktiengesellschaft (VAG) protocol (on ISO9141 interface
30 * with 5 baud init using specific keywords)
31 *
32 *
33 * XXX NOT YET WRITTEN
34 */
35
36#include <stdint.h>
37#include <stdio.h>
38
39#include "diag.h"
40#include "diag_err.h"
41#include "diag_l2.h"
42#include "diag_l3.h"
43
44#include "diag_vag.h"
45#include "diag_l3_vag.h"
46
47/*
48 * Insert the L3 layer on top of the layer 2 connection
49 *
50 */
51static int diag_l3_vag_start(struct diag_l3_conn *d_l3_conn) {
52 struct diag_l2_data l2data;
53 struct diag_l2_conn *d_l2_conn;
54
55 /* 5 baud init has been done, make sure we got the correct keybytes */
56 d_l2_conn = d_l3_conn->d_l3l2_conn;
57
58 (void)diag_l2_ioctl(d_l2_conn, DIAG_IOCTL_GET_L2_DATA, (void *)&l2data);
59
60 DIAG_DBGM(diag_l3_debug, DIAG_DEBUG_INIT, DIAG_DBGLEVEL_V,
61 FLFMT "start L3 KB 0x%X 0x%X need 0x01 0x8A\n",
62 FL, l2data.kb1, l2data.kb2);
63
64 if (l2data.kb1 != 0x01) {
65 return diag_iseterr(DIAG_ERR_WRONGKB);
66 }
67 if (l2data.kb2 != 0x8A) {
68 return diag_iseterr(DIAG_ERR_WRONGKB);
69 }
70
71 /* OK, ISO 9141 keybytes are correct ! */
72
73 /* Get the initial stuff the ECU tells us */
74
75 return 0;
76}
77
78
79/*
80 * This is called without just the VW protocol data
81 */
82
83void diag_l3_vag_decode(UNUSED(struct diag_l3_conn *d_l3_conn),
84 struct diag_msg *msg, char *buf, size_t bufsize) {
85 char buf2[128];
86 char buf3[16];
87 const char *s;
88
89 fprintf(stderr, FLFMT "Obviously broken code !\n", FL);
90
91 switch (msg->type) {
92 case DIAG_VAG_CMD_DTC_CLEAR:
93 s = "Clear DTCs";
94 break;
95 case DIAG_VAG_CMD_END_COMMS:
96 s = "End Comms";
97 break;
98 case DIAG_VAG_CMD_DTC_RQST:
99 s = "Request DTCs";
100 break;
101 case DIAG_VAG_CMD_READ_DATA:
102 s = "Read Data (single)";
103 break;
104 case DIAG_VAG_RSP_ASCII:
105 s = "ASCII Data";
106 break;
107 case DIAG_VAG_RSP_HEX:
108 s = "Hex Data";
109 break;
110 default:
111 snprintf(buf3, sizeof(buf3), "0x%X", msg->type);
112 s = buf3;
113 break;
114 }
115 snprintf(buf2, sizeof(buf2), "Command: %s: ", s);
116 smartcat(buf, bufsize, buf2);
117
118 snprintf(buf2, sizeof(buf2), "Data : ");
119 smartcat(buf, bufsize, buf2);
120
121 for (int i=3; i < msg->data[0]; i++) {
122 snprintf(buf2, sizeof(buf2), "0x%X ", msg->data[i]);
123 smartcat(buf, bufsize, buf2);
124 }
125 smartcat(buf, bufsize, "\n");
126
127 return;
128}
129
130const struct diag_l3_proto diag_l3_vag = {
131 "VAG",
132 diag_l3_vag_start,
133 diag_l3_base_stop,
134 diag_l3_base_send,
135 diag_l3_base_recv,
136 NULL, //ioctl
137 diag_l3_base_request,
138 diag_l3_vag_decode,
139 NULL //timer
140};
141