| 1 | #ifndef _DIAG_L2_ISO9141_H_ |
| 2 | #define _DIAG_L2_ISO9141_H_ |
| 3 | /* |
| 4 | * freediag - Vehicle Diagnostic Utility |
| 5 | * |
| 6 | * |
| 7 | * Copyright (C) 2001 Richard Almeida & Ibex Ltd ([email protected]) |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | * |
| 23 | ************************************************************************* |
| 24 | * |
| 25 | * Diag |
| 26 | * |
| 27 | * L2 driver for ISO 9141 and ISO 9141-2 interface |
| 28 | * |
| 29 | * NOTE: this is only the startcommunications routine, raw routines are |
| 30 | * used for read/write |
| 31 | * |
| 32 | * ISO9141-2 defines it's message packet as: |
| 33 | * Header Byte 1 = 0x68 from Tester; 0x48 from ECU; |
| 34 | * Header Byte 2 = 0x6A from Tester; 0x6B from ECU; |
| 35 | * Source Addr. = 0xF1 from Tester; 0x?? from ECU; |
| 36 | * Data Bytes (1 up to 7); |
| 37 | * 1 Checksum byte. |
| 38 | * |
| 39 | */ |
| 40 | |
| 41 | #if defined(__cplusplus) |
| 42 | extern "C" { |
| 43 | #endif |
| 44 | |
| 45 | #include <stdint.h> |
| 46 | |
| 47 | // Message overhead length (header + checksum): |
| 48 | #define OHLEN_ISO9141 4 |
| 49 | // Maximum message length (including overhead): |
| 50 | #define MAXLEN_ISO9141 (OHLEN_ISO9141 + 7) |
| 51 | |
| 52 | // Communication Initialization Timings: |
| 53 | #define W0min 2 // w0 = bus high prior to address byte; |
| 54 | #define W1min 60 // w1 = gap from address byte to synch pattern; |
| 55 | #define W1max 300 |
| 56 | #define W2min 5 // w2 = gap from synch pattern to keybyte 1; |
| 57 | #define W2max 20 |
| 58 | #define W3min 0 // w3 = gap from keybyte 1 to keybyte 2; |
| 59 | #define W3max 20 |
| 60 | #define W4min 25 // w4 = gap from keybyte 2 and inversion from tester; |
| 61 | #define W4max 50 |
| 62 | #define W5min 300 // w5 = guard time before retransmitting address byte; |
| 63 | |
| 64 | /* |
| 65 | * ISO9141 specific data |
| 66 | */ |
| 67 | struct diag_l2_iso9141 { |
| 68 | uint8_t srcaddr; // Src address used, normally 0xF1 (tester) |
| 69 | uint8_t target; // Target address used, normally 0x33 (ISO9141) |
| 70 | |
| 71 | // These should be only in specific protocol structs, but |
| 72 | // someone put them in the generic L2 struct, and there seem to be |
| 73 | //a lot of protocols that expect them to be there... :( |
| 74 | // uint8_t kb1; // key Byte 1 |
| 75 | // uint8_t kb2; // key Byte 2 |
| 76 | |
| 77 | uint8_t rxbuf[MAXLEN_ISO9141]; // Receive buffer, for building message in. |
| 78 | uint8_t rxoffset; |
| 79 | |
| 80 | enum { |
| 81 | STATE_CLOSED=0, |
| 82 | STATE_CONNECTING=1, |
| 83 | STATE_ESTABLISHED=2, |
| 84 | } state; |
| 85 | |
| 86 | }; |
| 87 | |
| 88 | |
| 89 | #if defined(__cplusplus) |
| 90 | } |
| 91 | #endif |
| 92 | #endif /* _DIAG_L2_ISO9141_H_ */ |
| 93 | |