├── CAN
├── LICENSE
├── Makefile
├── README.md
├── art
│ ├── dashboard.xcf
│ ├── ic.svg
│ ├── joypad.ora
│ ├── joypad.xcf
│ ├── needle.xcf
│ └── scoreboard.xcf
├── controls
├── controls.c
├── controls.o
├── data.h
├── data
│ ├── dashboard.png
│ ├── joypad.png
│ ├── needle.png
│ ├── sample-can.log
│ ├── scoreboard.png
│ ├── spritesheet-alt.png
│ └── spritesheet.png
├── icsim
├── icsim.c
├── icsim.o
├── lib.c
├── lib.h
├── lib.o
└── setup_vcan.sh
├── CarHacking_workshop_Barbhack_2024.pdf
├── LICENSE
├── README.md
├── TPMS
├── TPMS.png
└── TPMS_433.920_1MSPSs.complex
└── media
├── controls.png
├── interface.png
└── repository-open-graph-template.png
/CAN/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/CAN/Makefile:
--------------------------------------------------------------------------------
1 | CC=gcc
2 | CFLAGS=-I/usr/include/SDL2
3 | LDFLAGS=-lSDL2 -lSDL2_image
4 |
5 | all: icsim controls
6 |
7 | icsim: icsim.o lib.o
8 | $(CC) $(CFLAGS) -o icsim icsim.c lib.o $(LDFLAGS)
9 |
10 | controls: controls.o
11 | $(CC) $(CFLAGS) -o controls controls.c $(LDFLAGS)
12 |
13 | lib.o:
14 | $(CC) lib.c
15 |
16 | clean:
17 | rm -rf icsim controls icsim.o controls.o
18 |
--------------------------------------------------------------------------------
/CAN/README.md:
--------------------------------------------------------------------------------
1 | # CAN bus hands-on
2 |
3 | To discover the CAN bus, this repo holds a fork of "Instrument Cluster Simulator for SocketCAN" aka **ICSim** : https://github.com/zombieCraig/ICSim
4 |
5 | It extends the basic ICSim with some specific features :
6 | * Some controls are not related to a CAN frame, to simulate sensors/actuators on ECU
7 | * A very basic diag tool is simulated to help understanding UDS protocol
8 | * A few OBD-II and UDS commands are supported
9 | * To learn with fun, a scoring system with few challenges has been implemented
10 |
11 | 
12 | 
13 |
14 | If you are not running on Linux or you don't want to compile the application, a virtual machine (1.1Gb) is available here : https://mega.nz/file/YbRylYBZ#KMW4zd3JmxnkbZCmlqBhkwpty-k6-tacLpci9MnZRms
15 | Login : barbhack - password : 12345678
16 |
17 | ## Challenges
18 |
19 | There are 6 challenges to resolve in order to score 100 points :
20 | - Blink the turn signals on the instrument cluster without activating the warning or turn commands (5 pts)
21 | - The speed is limited to 100Km/h. Can you move the needle on the speedometer above this limit ? (10 pts)
22 | - A sensor triggers the lights by night. Can you shut it ? (10 pts)
23 | - Can you get the VIN of the car ? (15 pts)
24 | - The diag tool run a "Routine Control" command. A second command is hidden, can you find it ? (30 pts)
25 | - Can you resolve the "Security Access" challenge of the 0x03 "Diagnostic Session Control" (30 pts)
26 |
27 | ## Compiling
28 |
29 | You will need:
30 | * SDL2
31 | * SDL2_Image
32 | * can-utils
33 |
34 | You can get can-utils from github or on Ubuntu you may run the follwoing
35 |
36 | ```
37 | sudo apt-get install libsdl2-dev libsdl2-image-dev can-utils
38 | ```
39 |
40 | ## Default operation
41 | ------------------
42 |
43 | You will need a virtual CAN interface to run this software.
44 |
45 | You can create it using the "setup_vcan.sh" as sudo
46 | ```
47 | sudo ./setup_vcan.sh
48 | ```
49 |
50 | or type the following commands :
51 |
52 | ```
53 | sudo modprobe can
54 | sudo modprobe vcan
55 | sudo ip link add dev vcan0 type vcan
56 | sudo ip link set up vcan0
57 | ```
58 |
59 | If you type "ifconfig vcan0" or "ip link" you should see a vcan0 interface.
60 |
61 | Once the virtual CAN interface is up and running, type the two following commands in two different terminals :
62 |
63 | ```
64 | ./controls vcan0
65 | ```
66 | and
67 | ```
68 | ./icsim vcan0
69 | ```
70 | Each application can be closed by typing "Ctrl+c" in the terminal window.
71 |
72 | Troubleshooting
73 | ---------------
74 | * If you have to relaunch the "controls" app, you need to restart "icsim" also, to sync the shared data.
75 | * If the GUI is blinking/glitching, move it away from any open windows and get the focus by clicking in it.
76 | * On the virtual machine, isotprecv and isotpsend commands are not working.
77 |
78 | ## lib.o not linking
79 | If lib.o doesn't link it's probably because it's the wrong arch for your platform. To fix this you will
80 | want to compile can-utils and copy the newly compiled lib.o to the icsim directory. You can get can-utils
81 | from: https://github.com/linux-can/can-utils
82 |
83 | ## read: Bad address
84 | When running `./icsim vcan0` you end up getting a `read: Bad Address` message,
85 | this is typically a result of needing to recompile with updated SDL libraries.
86 | Make sure you have the recommended latest SDL2 libraries. Some users have
87 | reported fixing this problem by creating symlinks to the SDL.h files manually
88 | or you could edit the Makefile and change the CFLAGS to point to wherever your
89 | distro installs the SDL.h header, ie: /usr/include/x86_64-linux-gnu/SDL2
90 |
91 | There was also a report that on Arch linux needed sdl2_gfx library.
92 |
--------------------------------------------------------------------------------
/CAN/art/dashboard.xcf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/CAN/art/dashboard.xcf
--------------------------------------------------------------------------------
/CAN/art/ic.svg:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
509 |
--------------------------------------------------------------------------------
/CAN/art/joypad.ora:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/CAN/art/joypad.ora
--------------------------------------------------------------------------------
/CAN/art/joypad.xcf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/CAN/art/joypad.xcf
--------------------------------------------------------------------------------
/CAN/art/needle.xcf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/CAN/art/needle.xcf
--------------------------------------------------------------------------------
/CAN/art/scoreboard.xcf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/CAN/art/scoreboard.xcf
--------------------------------------------------------------------------------
/CAN/controls:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/CAN/controls
--------------------------------------------------------------------------------
/CAN/controls.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Control panel for IC Simulation
3 | *
4 | * OpenGarages
5 | *
6 | * craig@theialabs.com
7 | *
8 | * Forked version :
9 | * - removed joypad support, all commands are sent through keyboard
10 | * - no more randomize ID, for teaching purpose
11 | * - added new commands : day/night mode, warning
12 | * - add a challenges / points system for more fun
13 | *
14 | */
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 | #include
29 | #include
30 |
31 | #include "data.h"
32 |
33 |
34 | #ifndef DATA_DIR
35 | #define DATA_DIR "./data/"
36 | #endif
37 | #define DEFAULT_CAN_TRAFFIC DATA_DIR "sample-can.log"
38 | #define DEFAULT_DIFFICULTY 1
39 |
40 |
41 | #define SCREEN_WIDTH 835
42 | #define SCREEN_HEIGHT 402
43 |
44 | #define ACCEL_RATE 8.0 // 0-MAX_SPEED in seconds
45 |
46 |
47 | int s; // socket
48 | struct canfd_frame cf;
49 | char *trafficLog = DEFAULT_CAN_TRAFFIC;
50 | struct ifreq ifr;
51 | int doorPos = DEFAULT_DOOR_POS;
52 | int signalPos = DEFAULT_SIGNAL_POS;
53 | int speedPos = DEFAULT_SPEED_POS;
54 | int warningPos = DEFAULT_WARNING_POS;
55 | int luminosityPos = DEFAULT_LUMINOSITY_POS;
56 | int doorLen = DEFAULT_DOOR_POS + 1;
57 | int signalLen = DEFAULT_SIGNAL_POS + 1;
58 | int speedLen = DEFAULT_SPEED_POS + 2;
59 | int warningLen = DEFAULT_WARNING_POS +3;
60 | int luminosityLen = DEFAULT_LUMINOSITY_POS + 2;
61 |
62 |
63 | char *model = NULL;
64 |
65 | char doorState = 0xf;
66 | char signalState = 0;
67 | char warningState = 0;
68 | int throttle = 0;
69 | float currentSpeed = 0;
70 | int luminosity = 0;
71 |
72 | int doorId, signalId, speedId, warningId, luminosityId, ecuId, controlId;
73 | int currentTime;
74 | int lastAccel = 0;
75 | int lastTurnSignal = 0;
76 | int lastWarningSignal = 0;
77 | int lastSharedData = 0;
78 | int lastLuminositySignal = 0;
79 | int lastTesterSignal = 0;
80 |
81 | int doorStatus[4] = {DOOR_LOCKED, DOOR_LOCKED, DOOR_LOCKED, DOOR_LOCKED};
82 | char doorButtonPressed[4] = {0,0,0,0};
83 |
84 | int turning = 0;
85 | char turnValue = 0;
86 | char turnButtonPressed = 0;
87 | char lightOn = 0;
88 | char lightButtonPressed = 0;
89 | char isNight = 0;
90 | char nightButtonPressed = 0;
91 | char warningActive = 0;
92 | char diagOn = 0;
93 | char diagButtonPressed = 0;
94 | char diagActive = 0;
95 | char routineButtonPressed = 0;
96 | int lastDiagTesterPresent = 0;
97 |
98 | int difficulty = 1;
99 |
100 | int shareSeed = 0;
101 |
102 | int playId;
103 | char dataFile[256];
104 | SDL_Renderer *renderer = NULL;
105 | SDL_Texture *baseTexture = NULL;
106 |
107 | FILE *fptr;
108 |
109 | // Adds data dir to file name
110 | // Uses a single pointer so not to have a memory leak
111 | // returns point to dataFiles or NULL if append is too large
112 | char *get_data(char *fname) {
113 | if(strlen(DATA_DIR) + strlen(fname) > 255) return NULL;
114 | strncpy(dataFile, DATA_DIR, 255);
115 | strncat(dataFile, fname, 255-strlen(dataFile));
116 | return dataFile;
117 | }
118 |
119 | void sendPkt(int mtu) {
120 | if(write(s, &cf, mtu) != mtu) {
121 | perror("write");
122 | }
123 | }
124 |
125 | // Randomizes bytes in CAN packet if difficulty is hard enough
126 | void randomizePkt(int start, int stop) {
127 | if (difficulty < 2) return;
128 | int i = start;
129 | for(;i < stop;i++) {
130 | if(rand() % 3 < 1) cf.data[i] = rand() % 255;
131 | }
132 | }
133 |
134 | void updateSharedData() {
135 | shareSeed = (shareSeed+1) % 65536;
136 |
137 | memset(&cf, 0, sizeof(cf));
138 | cf.can_id = controlId;
139 | cf.len = 7;
140 |
141 | cf.data[0] += (lightOn & 0x1) << 6;
142 | cf.data[0] += (isNight & 0x1) << 5;
143 | cf.data[0] += (warningActive & 0x1) << 4;
144 | cf.data[0] += (diagOn & 0x1) << 3;
145 | cf.data[0] += (diagActive & 0x1) << 2;
146 | cf.data[0] += (turnValue & 0x3);
147 |
148 | cf.data[1] = luminosity;
149 | cf.data[2] = ((char)currentSpeed) %256;
150 | cf.data[3] = (cf.data[0] + cf.data[1] + cf.data[2])%256; // CRC
151 | cf.data[4] = ((shareSeed&0xFF00) >> 8) ^ cf.data[3]; // Counter check
152 | cf.data[5] = (shareSeed & 0xFF00) >> 8; // Counter byte 1
153 | cf.data[6] = shareSeed & 0xFF; // Counter byte 2
154 |
155 | for (char i=0; i <= 4; i++) {
156 | cf.data[i] ^= (shareSeed & 0xFF);
157 | }
158 |
159 | sendPkt(CAN_MTU);
160 | }
161 |
162 | void sendLock(char door) {
163 | doorState |= door;
164 | updateSharedData();
165 |
166 | memset(&cf, 0, sizeof(cf));
167 | cf.can_id = doorId;
168 | cf.len = doorLen;
169 | cf.data[doorPos] = doorState;
170 | if (doorPos) randomizePkt(0, doorPos);
171 | if (doorLen != doorPos + 1) randomizePkt(doorPos + 1, doorLen);
172 | sendPkt(CAN_MTU);
173 | }
174 |
175 | void sendUnlock(char door) {
176 | doorState &= ~door;
177 | updateSharedData();
178 |
179 | memset(&cf, 0, sizeof(cf));
180 | cf.can_id = doorId;
181 | cf.len = doorLen;
182 | cf.data[doorPos] = doorState;
183 | if (doorPos) randomizePkt(0, doorPos);
184 | if (doorLen != doorPos + 1) randomizePkt(doorPos + 1, doorLen);
185 | sendPkt(CAN_MTU);
186 | }
187 |
188 | void updateDoorStatus(char doorId, char doorValue) {
189 | if (doorStatus[doorId] == DOOR_LOCKED) {
190 | doorStatus[doorId] = DOOR_UNLOCKED;
191 | sendUnlock(doorValue);
192 | } else {
193 | doorStatus[doorId] = DOOR_LOCKED;
194 | sendLock(doorValue);
195 | }
196 | }
197 |
198 | void sendSpeed() {
199 | int kph = (currentSpeed / 0.6213751) * 100;
200 | updateSharedData();
201 |
202 | memset(&cf, 0, sizeof(cf));
203 | cf.can_id = speedId;
204 | cf.len = speedLen;
205 | cf.data[speedPos+1] = (char)kph & 0xff;
206 | cf.data[speedPos] = (char)(kph >> 8) & 0xff;
207 | if(kph == 0) { // IDLE
208 | cf.data[speedPos] = 1;
209 | cf.data[speedPos+1] = rand() % 255+100;
210 | }
211 | if (speedPos) randomizePkt(0, speedPos);
212 | if (speedLen != speedPos + 2) randomizePkt(speedPos+2, speedLen);
213 | sendPkt(CAN_MTU);
214 | }
215 |
216 | void sendTurnSignal() {
217 | updateSharedData();
218 |
219 | memset(&cf, 0, sizeof(cf));
220 | cf.can_id = signalId;
221 | cf.len = signalLen;
222 | cf.data[signalPos] = signalState;
223 | if(signalPos) randomizePkt(0, signalPos);
224 | if(signalLen != signalPos + 1) randomizePkt(signalPos+1, signalLen);
225 | sendPkt(CAN_MTU);
226 | }
227 |
228 | void sendWarningSignal() {
229 | updateSharedData();
230 |
231 | memset(&cf, 0, sizeof(cf));
232 | cf.can_id = warningId;
233 | cf.len = warningLen;
234 | cf.data[warningPos] = warningState;
235 | if(warningPos) randomizePkt(0, warningPos);
236 | if(warningLen != warningPos + 1) randomizePkt(warningPos+1, warningLen);
237 | sendPkt(CAN_MTU);
238 | }
239 |
240 | void sendLuminositySignal() {
241 | if (isNight == 1) {
242 | luminosity = 30 + rand()%10;
243 | }
244 | else {
245 | luminosity = 194 + rand()%10;
246 | }
247 |
248 | updateSharedData();
249 |
250 | memset(&cf, 0, sizeof(cf));
251 | cf.can_id = luminosityId;
252 | cf.len = luminosityLen;
253 | cf.data[luminosityPos] = luminosity;
254 | if (luminosityPos) randomizePkt(0, luminosityPos);
255 | if (luminosityLen != luminosityPos + 1) randomizePkt(luminosityPos+1, luminosityLen);
256 | sendPkt(CAN_MTU);
257 | }
258 |
259 | // Checks throttle to see if we should accelerate or decelerate the vehicle
260 | void checkAccel() {
261 | float rate = MAX_SPEED / (ACCEL_RATE * 100);
262 | // Updated every 10 ms
263 | if(currentTime > lastAccel + 10) {
264 | if(throttle < 0) {
265 | currentSpeed -= rate;
266 | if(currentSpeed < 1) currentSpeed = 0;
267 | } else if(throttle > 0) {
268 | currentSpeed += rate;
269 | if(currentSpeed > MAX_SPEED) { // Limiter
270 | currentSpeed = MAX_SPEED;
271 | }
272 | }
273 | sendSpeed();
274 | lastAccel = currentTime;
275 | }
276 | }
277 |
278 | // Checks if turning and activates the turn signal
279 | void checkTurn() {
280 | if(currentTime > lastTurnSignal + 500) {
281 | if (warningState == 1) {
282 | signalState ^= CAN_WARNING_SIGNAL;
283 | }
284 | else if(turning < 0) {
285 | signalState ^= CAN_LEFT_SIGNAL;
286 | } else if(turning > 0) {
287 | signalState ^= CAN_RIGHT_SIGNAL;
288 | } else {
289 | signalState = 0;
290 | }
291 |
292 | turnValue = signalState;
293 |
294 | sendTurnSignal();
295 | lastTurnSignal = currentTime;
296 | }
297 | if (currentTime > lastWarningSignal + 250) {
298 | sendWarningSignal();
299 | lastWarningSignal = currentTime;
300 | }
301 | }
302 |
303 | void checkLuminosity() {
304 | if (currentTime > lastLuminositySignal + 300) {
305 | sendLuminositySignal();
306 | lastLuminositySignal = currentTime;
307 | }
308 | }
309 |
310 |
311 | // Plays background can traffic
312 | void playCanTraffic() {
313 | char can2can[50];
314 | snprintf(can2can, 49, "%s=can0", ifr.ifr_name);
315 | if (execlp("canplayer", "canplayer", "-I", trafficLog, "-l", "i", can2can, NULL) == -1) printf("WARNING: Could not execute canplayer. No bg data\n");
316 | }
317 |
318 | void killChild() {
319 | kill(playId, SIGINT);
320 | }
321 |
322 | void redrawScreen() {
323 | SDL_RenderCopy(renderer, baseTexture, NULL, NULL);
324 | SDL_RenderPresent(renderer);
325 | }
326 |
327 | void usage(char *msg) {
328 | if(msg) printf("%s\n", msg);
329 | printf("Usage: controls [options] \n");
330 | printf("\t-t\ttraffic file to use for bg CAN traffic\n");
331 | printf("\t-l\tdifficulty level. 1-2 (default: %d)\n", DEFAULT_DIFFICULTY);
332 | printf("\t-X\tDisable background CAN traffic. Cheating if doing RE but needed if playing on a real CANbus\n");
333 | exit(1);
334 | }
335 |
336 |
337 | int main(int argc, char *argv[]) {
338 | int opt;
339 | struct sockaddr_can addr;
340 | struct canfd_frame frame;
341 | int running = 1;
342 | int seed = 0;
343 | int enable_canfd = 1;
344 | int play_traffic = 1;
345 | struct stat st;
346 | SDL_Event event;
347 |
348 | while ((opt = getopt(argc, argv, "Xl:t:h?")) != -1) {
349 | switch(opt) {
350 | case 't':
351 | trafficLog = optarg;
352 | break;
353 | case 'l':
354 | difficulty = atoi(optarg);
355 | break;
356 | case 'X':
357 | play_traffic = 0;
358 | break;
359 | case 'h':
360 | case '?':
361 | default:
362 | usage(NULL);
363 | break;
364 | }
365 | }
366 |
367 | if (optind >= argc) usage("You must specify at least one can device");
368 |
369 | if(stat(trafficLog, &st) == -1) {
370 | char msg[256];
371 | snprintf(msg, 255, "CAN Traffic file not found: %s\n", trafficLog);
372 | usage(msg);
373 | }
374 |
375 | /* open socket */
376 | if ((s = socket(PF_CAN, SOCK_RAW, CAN_RAW)) < 0) {
377 | perror("socket");
378 | return 1;
379 | }
380 |
381 | addr.can_family = AF_CAN;
382 |
383 | strcpy(ifr.ifr_name, argv[optind]);
384 | if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
385 | perror("SIOCGIFINDEX");
386 | return 1;
387 | }
388 | addr.can_ifindex = ifr.ifr_ifindex;
389 |
390 | if (setsockopt(s, SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &enable_canfd, sizeof(enable_canfd))){
391 | printf("error when enabling CAN FD support\n");
392 | return 1;
393 | }
394 |
395 | if (bind(s, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
396 | perror("bind");
397 | return 1;
398 | }
399 |
400 | doorId = DEFAULT_DOOR_ID;
401 | signalId = DEFAULT_SIGNAL_ID;
402 | speedId = DEFAULT_SPEED_ID;
403 | warningId = DEFAULT_WARNING_ID;
404 | luminosityId = DEFAULT_LUMINOSITY_ID;
405 | controlId = DEFAULT_CONTROL_ID;
406 |
407 | if (play_traffic) {
408 | playId = fork();
409 | if ((int)playId == -1) {
410 | printf("Error: Couldn't fork bg player\n");
411 | exit(-1);
412 | } else if (playId == 0) {
413 | playCanTraffic();
414 | // Shouldn't return
415 | exit(0);
416 | }
417 | atexit(killChild);
418 | }
419 |
420 | seed = time(NULL);
421 | srand(seed);
422 | shareSeed = rand()% 65536;
423 |
424 | // GUI Setup
425 | SDL_Window *window = NULL;
426 | SDL_Surface *screenSurface = NULL;
427 | if(SDL_Init ( SDL_INIT_VIDEO | SDL_INIT_JOYSTICK ) < 0 ) {
428 | printf("SDL Could not initializes\n");
429 | exit(40);
430 | }
431 |
432 | window = SDL_CreateWindow("CANBus Control Panel", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
433 | if(window == NULL) {
434 | printf("Window could not be shown\n");
435 | }
436 | renderer = SDL_CreateRenderer(window, -1, 0);
437 | SDL_Surface *image = IMG_Load(get_data("joypad.png"));
438 | baseTexture = SDL_CreateTextureFromSurface(renderer, image);
439 | SDL_RenderCopy(renderer, baseTexture, NULL, NULL);
440 | SDL_RenderPresent(renderer);
441 |
442 | while(running) {
443 | while( SDL_PollEvent(&event) != 0 ) {
444 | switch(event.type) {
445 | case SDL_QUIT:
446 | running = 0;
447 | break;
448 | case SDL_WINDOWEVENT:
449 | switch(event.window.event) {
450 | case SDL_WINDOWEVENT_ENTER:
451 | case SDL_WINDOWEVENT_RESIZED:
452 | redrawScreen();
453 | break;
454 | }
455 | case SDL_KEYDOWN:
456 | switch(event.key.keysym.sym) {
457 | case SDLK_UP:
458 | throttle = 1;
459 | break;
460 | case SDLK_LEFT:
461 | if (turnButtonPressed == 0 && warningState == 0) {
462 | if (turning == -1) {
463 | turning = 0;
464 | }
465 | else {
466 | signalState = 0;
467 | turning = -1;
468 | }
469 | turnButtonPressed = 1;
470 | }
471 | break;
472 | case SDLK_RIGHT:
473 | if (turnButtonPressed == 0 && warningState == 0) {
474 | if (turning == 1) {
475 | turning = 0;
476 | }
477 | else {
478 | signalState = 0;
479 | turning = 1;
480 | }
481 | turnButtonPressed = 1;
482 | }
483 | break;
484 | case SDLK_w:
485 | if (warningState == 1 && warningActive == 0) {
486 | warningState = 0;
487 | } else if (warningState == 0 && warningActive == 0) {
488 | warningState = 1;
489 | turning = 0;
490 | }
491 | warningActive = 1;
492 | break;
493 | case SDLK_u:
494 | if (doorButtonPressed[0] == 0) {
495 | updateDoorStatus(0, CAN_DOOR1_LOCK);
496 | doorButtonPressed[0] = 1;
497 | }
498 | break;
499 | case SDLK_i:
500 | if (doorButtonPressed[1] == 0) {
501 | updateDoorStatus(1, CAN_DOOR2_LOCK);
502 | doorButtonPressed[1] = 1;
503 | }
504 | break;
505 | case SDLK_j:
506 | if (doorButtonPressed[2] == 0) {
507 | updateDoorStatus(2, CAN_DOOR3_LOCK);
508 | doorButtonPressed[2] = 1;
509 | }
510 | break;
511 | case SDLK_k:
512 | if (doorButtonPressed[3] == 0) {
513 | updateDoorStatus(3, CAN_DOOR4_LOCK);
514 | doorButtonPressed[3] = 1;
515 | }
516 | break;
517 | case SDLK_s:
518 | if (nightButtonPressed == 0) {
519 | isNight ^= 1;
520 | nightButtonPressed = 1;
521 | }
522 | break;
523 | case SDLK_l:
524 | if (lightButtonPressed == 0) {
525 | lightOn ^= 1;
526 | lightButtonPressed = 1;
527 | }
528 | break;
529 | case SDLK_d:
530 | if (diagButtonPressed == 0) {
531 | diagOn ^= 1;
532 | if (diagOn == 0) {
533 | diagActive = 0;
534 | system("cansend vcan0 7E0#0210010000000000");
535 | } else {
536 | system("cansend vcan0 7E0#0210020000000000");
537 | }
538 | diagButtonPressed = 1;
539 | }
540 | break;
541 | case SDLK_x:
542 | if (diagOn == 1 && routineButtonPressed == 0) {
543 | diagActive ^= 1;
544 | if (diagActive == 1)
545 | system("cansend vcan0 7E0#0431411001000000");
546 | else
547 | system("cansend vcan0 7E0#0431411000000000");
548 | routineButtonPressed = 1;
549 | }
550 | break;
551 | }
552 | break;
553 | case SDL_KEYUP:
554 | switch(event.key.keysym.sym) {
555 | case SDLK_UP:
556 | throttle = -1;
557 | break;
558 | case SDLK_LEFT:
559 | case SDLK_RIGHT:
560 | turnButtonPressed = 0;
561 | break;
562 | case SDLK_u:
563 | doorButtonPressed[0] = 0;
564 | break;
565 | case SDLK_i:
566 | doorButtonPressed[1] = 0;
567 | break;
568 | case SDLK_j:
569 | doorButtonPressed[2] = 0;
570 | break;
571 | case SDLK_k:
572 | doorButtonPressed[3] = 0;
573 | break;
574 | case SDLK_w:
575 | warningActive = 0;
576 | break;
577 | case SDLK_s:
578 | nightButtonPressed = 0;
579 | break;
580 | case SDLK_l:
581 | lightButtonPressed = 0;
582 | break;
583 | case SDLK_d:
584 | diagButtonPressed = 0;
585 | break;
586 | case SDLK_x:
587 | routineButtonPressed = 0;
588 | break;
589 | }
590 | break;
591 | }
592 | }
593 | currentTime = SDL_GetTicks();
594 | checkAccel();
595 | checkTurn();
596 | checkLuminosity();
597 | if (diagOn == 1 && (lastDiagTesterPresent + 1000) < currentTime) {
598 | lastDiagTesterPresent = currentTime;
599 | system("cansend vcan0 7E0#023E000000000000");
600 | }
601 |
602 | SDL_Delay(5);
603 | }
604 |
605 | close(s);
606 | SDL_DestroyTexture(baseTexture);
607 | SDL_FreeSurface(image);
608 | SDL_DestroyRenderer(renderer);
609 | SDL_DestroyWindow(window);
610 | SDL_Quit();
611 | }
612 |
--------------------------------------------------------------------------------
/CAN/controls.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/CAN/controls.o
--------------------------------------------------------------------------------
/CAN/data.h:
--------------------------------------------------------------------------------
1 | #define DEFAULT_CONTROL_ID 7
2 | #define DEFAULT_DOOR_ID 411
3 | #define DEFAULT_DOOR_POS 2
4 | #define DEFAULT_SIGNAL_ID 392
5 | #define DEFAULT_ECU_ID 2016
6 | #define DEFAULT_SIGNAL_POS 0
7 | #define DEFAULT_SPEED_ID 580
8 | #define DEFAULT_SPEED_POS 3
9 | #define DEFAULT_WARNING_ID 1066
10 | #define DEFAULT_WARNING_POS 2
11 | #define DEFAULT_LUMINOSITY_ID 924
12 | #define DEFAULT_LUMINOSITY_POS 3
13 | #define DEFAULT_LIGHT_ID 832
14 | #define DEFAULT_LIGHT_POS 5
15 |
16 |
17 | #define CAN_DOOR1_LOCK 1
18 | #define CAN_DOOR2_LOCK 2
19 | #define CAN_DOOR3_LOCK 4
20 | #define CAN_DOOR4_LOCK 8
21 | #define CAN_LEFT_SIGNAL 1
22 | #define CAN_RIGHT_SIGNAL 2
23 | #define CAN_WARNING_SIGNAL 3
24 | #define CAN_LIGHT_ON 2
25 | #define CAN_LIGHT_AUTO 1
26 | #define ON 1
27 | #define OFF 0
28 | #define DOOR_LOCKED 0
29 | #define DOOR_UNLOCKED 1
30 |
31 | #define UDS_SID_DIAGNOSTIC_CONTROL 0x10 // GMLAN = Initiate Diagnostics
32 | #define UDS_SID_ECU_RESET 0x11
33 | #define UDS_SID_GM_READ_FAILURE_RECORD 0x12 // GMLAN
34 | #define UDS_SID_CLEAR_DTC 0x14
35 | #define UDS_SID_READ_DTC 0x19
36 | #define UDS_SID_GM_READ_DID_BY_ID 0x1A // GMLAN - Read DID By ID
37 | #define UDS_SID_RESTART_COMMUNICATIONS 0x20 // GMLAN - Restart a stopped com
38 | #define UDS_SID_READ_DATA_BY_ID 0x22
39 | #define UDS_SID_READ_MEM_BY_ADDRESS 0x23
40 | #define UDS_SID_READ_SCALING_BY_ID 0x24
41 | #define UDS_SID_SECURITY_ACCESS 0x27
42 | #define UDS_SID_COMMUNICATION_CONTROL 0x28 // GMLAN Stop Communications
43 | #define UDS_SID_READ_DATA_BY_ID_PERIODIC 0x2A
44 | #define UDS_SID_DEFINE_DATA_ID 0x2C
45 | #define UDS_SID_WRITE_DATA_BY_ID 0x2E
46 | #define UDS_SID_IO_CONTROL_BY_ID 0x2F
47 | #define UDS_SID_ROUTINE_CONTROL 0x31
48 | #define UDS_SID_REQUEST_DOWNLOAD 0x34
49 | #define UDS_SID_REQUEST_UPLOAD 0x35
50 | #define UDS_SID_TRANSFER_DATA 0x36
51 | #define UDS_SID_REQUEST_XFER_EXIT 0x37
52 | #define UDS_SID_REQUEST_XFER_FILE 0x38
53 | #define UDS_SID_WRITE_MEM_BY_ADDRESS 0x3D
54 | #define UDS_SID_TESTER_PRESENT 0x3E
55 | #define UDS_SID_ACCESS_TIMING 0x83
56 | #define UDS_SID_SECURED_DATA_TRANS 0x84
57 | #define UDS_SID_CONTROL_DTC_SETTINGS 0x85
58 | #define UDS_SID_RESPONSE_ON_EVENT 0x86
59 | #define UDS_SID_LINK_CONTROL 0x87
60 | #define UDS_SID_GM_PROGRAMMED_STATE 0xA2
61 | #define UDS_SID_GM_PROGRAMMING_MODE 0xA5
62 | #define UDS_SID_GM_READ_DIAG_INFO 0xA9
63 | #define UDS_SID_GM_READ_DATA_BY_ID 0xAA
64 | #define UDS_SID_GM_DEVICE_CONTROL 0xAE
65 |
66 | #define PID_INFO 0x01
67 | #define PID_VEHICLE_INFO 0x09
68 | #define PID_INFO_VEHICLE_SPEED 0x0D
69 | #define PID_VEHICLE_VIN 0x02
70 | #define PID_VEHICLE_ECU_NAME 0x0A
71 |
72 | #define UDS_ERROR_SERVICE_NOT_SUPPORTED 0x11
73 | #define UDS_ERROR_SUBFUNC_NOT_SUPPORTED 0x12
74 | #define UDS_ERROR_INCORRECT_LENGTH 0x13
75 | #define UDS_ERROR_FUNC_INCORRECT_SESSION 0x7F
76 | #define UDS_ERROR_SEQUENCE_ERROR 0x24
77 | #define UDS_ERROR_SECURITY_DENIED 0x33
78 | #define UDS_ERROR_INVALID_KEY 0x35
79 | #define UDS_ERROR_REQUEST_OUT_RANGE 0x31
80 |
81 | #define PENDING_READ_DATA_BY_ID_GM 1
82 |
83 | char challenges[6] = {0,0,0,0,0,0};
84 | char challengeValue[6] = {5, 10, 10, 15, 30, 30};
85 | #define CHALLENGE_TURN_SIGNALS 0
86 | #define CHALLENGE_SPOOF_LIGHT 1
87 | #define CHALLENGE_SPOOF_SPEED 2
88 | #define CHALLENGE_REQUEST_VIN 3
89 | #define CHALLENGE_FIND_ROUTINE_CONTROL 4
90 | #define CHALLENGE_SECURITY_ACCESS 5
91 |
92 | #define MAX_SPEED 100.0 // Limiter 260.0 is full guage speed
93 | #define CHALLENGE_SPEED 150
94 |
95 |
96 | #define DEBUG 0
97 | #define VIN "WBARBHACKFA149850"
98 | #define LIGHT_LEVEL 0x60
99 | #define ISOTP_TIMEOUT 600
100 |
--------------------------------------------------------------------------------
/CAN/data/dashboard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/CAN/data/dashboard.png
--------------------------------------------------------------------------------
/CAN/data/joypad.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/CAN/data/joypad.png
--------------------------------------------------------------------------------
/CAN/data/needle.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/CAN/data/needle.png
--------------------------------------------------------------------------------
/CAN/data/scoreboard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/CAN/data/scoreboard.png
--------------------------------------------------------------------------------
/CAN/data/spritesheet-alt.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/CAN/data/spritesheet-alt.png
--------------------------------------------------------------------------------
/CAN/data/spritesheet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/CAN/data/spritesheet.png
--------------------------------------------------------------------------------
/CAN/icsim:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/CAN/icsim
--------------------------------------------------------------------------------
/CAN/icsim.c:
--------------------------------------------------------------------------------
1 | /*
2 | * Instrument cluster simulator
3 | *
4 | * (c) 2014 Open Garages - Craig Smith
5 | *
6 | *
7 | * Forked version :
8 | * - new GUI
9 | * -
10 | *
11 | */
12 |
13 | #include
14 | #include
15 | #include
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | #include "lib.h"
30 | #include "data.h"
31 |
32 | #ifndef DATA_DIR
33 | #define DATA_DIR "./data/" // Needs trailing slash
34 | #endif
35 |
36 | // ICSim constants
37 | #define SCREEN_WIDTH 862
38 | #define SCREEN_HEIGHT 669
39 |
40 |
41 | // ICSim globals
42 | int can; // socket
43 | struct canfd_frame cf;
44 | const int canfd_on = 1;
45 | int debug = 0;
46 | int randomize = 0;
47 | int seed = 0;
48 | int currentTime;
49 |
50 | int doorPos = DEFAULT_DOOR_POS;
51 | int signalPos = DEFAULT_SIGNAL_POS;
52 | int speedPos = DEFAULT_SPEED_POS;
53 | int warningPos = DEFAULT_WARNING_POS;
54 | int luminosityPos = DEFAULT_LUMINOSITY_POS;
55 | int lightPos = DEFAULT_LIGHT_POS;
56 |
57 | long currentSpeed = 0;
58 | int doorStatus[4];
59 | int turnStatus[2];
60 | int luminosityLevel = 0;
61 | char lightStatus = 0;
62 | char *model = NULL;
63 | char dataFile[256];
64 |
65 | char warningState = 0;
66 | char diagActive = 0;
67 |
68 | char diagSession = 1;
69 | int lastDiagTesterPresent = 0;
70 | int diagSeed[2];
71 | int sessionKey[2] = {0x35, 0x30}; // Based on the 2 last character of the VIN, ie 50
72 | char seedGenerated = 0;
73 | char secretSessionFound = 0;
74 |
75 | int shareSeed = -1;
76 | char controlLightOn = 0;
77 | char controlIsNight = 0;
78 | char controlWarningActive = 0;
79 | char controlDiagOn = 0;
80 | char controlDiagActive = 0;
81 | char controlTurnValue = 0;
82 | char controlLuminosity = 0;
83 | char controlCurrentSpeed = 0;
84 |
85 | char pristine = 1;
86 | int lastUpdate = 0;
87 | char isoTpRequest = 0;
88 | int isoTpRemainingBytes = 0;
89 | int isoTpFirstFlowTime = 0;
90 |
91 | char score = 0;
92 |
93 | SDL_Renderer *renderer = NULL;
94 | SDL_Texture *baseTexture = NULL;
95 | SDL_Texture *needleTex = NULL;
96 | SDL_Texture *spriteTex = NULL;
97 | SDL_Texture *spriteAltTex = NULL;
98 | SDL_Texture *scoreboardTex = NULL;
99 |
100 | int running = 0;
101 |
102 | FILE *fptr;
103 |
104 | /* Prototypes */
105 | void print_pkt(struct canfd_frame);
106 | void print_bin(unsigned char *, int);
107 |
108 | // Simple map function
109 | long map(long x, long in_min, long in_max, long out_min, long out_max) {
110 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
111 | }
112 |
113 | // Adds data dir to file name
114 | // Uses a single pointer so not to have a memory leak
115 | // returns point to dataFiles or NULL if append is too large
116 | char *getData(char *fname) {
117 | if(strlen(DATA_DIR) + strlen(fname) > 255) return NULL;
118 | strncpy(dataFile, DATA_DIR, 255);
119 | strncat(dataFile, fname, 255-strlen(dataFile));
120 | return dataFile;
121 | }
122 |
123 | void sendPkt(int mtu) {
124 | if(write(can, &cf, mtu) != mtu) {
125 | perror("write");
126 | }
127 | }
128 | /* Default vehicle state */
129 | void initCarState() {
130 | doorStatus[0] = DOOR_LOCKED;
131 | doorStatus[1] = DOOR_LOCKED;
132 | doorStatus[2] = DOOR_LOCKED;
133 | doorStatus[3] = DOOR_LOCKED;
134 | turnStatus[0] = OFF;
135 | turnStatus[1] = OFF;
136 | diagActive = 0;
137 | diagSession = 1;
138 | seedGenerated = 0;
139 | secretSessionFound = 0;
140 | warningState = 0;
141 | }
142 |
143 | /* Empty IC */
144 | void blankIC() {
145 | SDL_RenderCopy(renderer, baseTexture, NULL, NULL);
146 | }
147 |
148 | void validateChallenge(int challenge) {
149 | if (challenges[challenge] == 0) {
150 | challenges[challenge] = 1;
151 | score += challengeValue[challenge];
152 | }
153 | }
154 |
155 | void updateScore(int chall) {
156 | if (chall >= sizeof(challenges) || chall < 0) {
157 | printf("Error : challenge ID is out of range !");
158 | exit(42);
159 | }
160 |
161 | if (challenges[chall] == 0) {
162 | score += challengeValue[chall];
163 | challenges[chall] = 1;
164 | if (score > 100) score = 100;
165 | }
166 | }
167 |
168 | /* Draw functions */
169 | void drawScore() {
170 | SDL_Rect scoreRect, scoreSrc;
171 | scoreSrc.x = 0;
172 | scoreSrc.y = (score/5) * 40;
173 | scoreSrc.h = 40;
174 | scoreSrc.w = 68;
175 |
176 | scoreRect.x = 50;
177 | scoreRect.y = 389;
178 | scoreRect.h = 40;
179 | scoreRect.w = 68;
180 |
181 | SDL_RenderCopy(renderer, scoreboardTex, &scoreSrc, &scoreRect);
182 | }
183 |
184 | void drawSpeed() {
185 | SDL_Rect dialRect;
186 | SDL_Point center;
187 | double angle = 0;
188 | dialRect.x = 281;
189 | dialRect.y = 405;
190 | dialRect.h = 250;
191 | dialRect.w = 250;
192 |
193 | if (diagActive == 2 || secretSessionFound == 1) {
194 | if (currentTime % 1000 > 500)
195 | SDL_RenderCopy(renderer, baseTexture, &dialRect, &dialRect);
196 | else
197 | SDL_RenderCopy(renderer, spriteAltTex, &dialRect, &dialRect);
198 | } else
199 | SDL_RenderCopy(renderer, baseTexture, &dialRect, &dialRect);
200 |
201 | center.x = 125;
202 | center.y = 125;
203 | angle = map(currentSpeed, 0, 230, -50, 200);
204 | if(angle > 200) angle = 200;
205 | SDL_RenderCopyEx(renderer, needleTex, NULL, &dialRect, angle, ¢er, SDL_FLIP_NONE);
206 | }
207 |
208 | void drawDiag() {
209 | SDL_Rect diagScreen, diagStatus, diagFeedback;
210 | diagScreen.x = 610;
211 | diagScreen.y = 551;
212 | diagScreen.w = 162;
213 | diagScreen.h = 102;
214 |
215 | diagStatus.x = 51;
216 | diagStatus.y = 461;
217 | diagStatus.w = 161;
218 | diagStatus.h = 19;
219 |
220 | diagFeedback.x = 33;
221 | diagFeedback.y = 483;
222 | diagFeedback.w = 204;
223 | diagFeedback.h = 152;
224 |
225 | if (controlDiagOn == 0) {
226 | SDL_RenderCopy(renderer, baseTexture, &diagScreen, &diagScreen);
227 | } else {
228 | if (controlDiagActive == 0) {
229 | SDL_RenderCopy(renderer, spriteTex, &diagScreen, &diagScreen);
230 | } else {
231 | SDL_RenderCopy(renderer, spriteAltTex, &diagScreen, &diagScreen);
232 | }
233 | }
234 |
235 | if (diagSession == 2 || diagSession == 3)
236 | SDL_RenderCopy(renderer, spriteTex, &diagStatus, &diagStatus);
237 | else
238 | SDL_RenderCopy(renderer, baseTexture, &diagStatus, &diagStatus);
239 |
240 | if (diagActive == 2 || secretSessionFound == 1) {
241 | SDL_RenderCopy(renderer, spriteAltTex, &diagFeedback, &diagFeedback);
242 |
243 | } else if (diagActive == 1)
244 | SDL_RenderCopy(renderer, spriteTex, &diagFeedback, &diagFeedback);
245 | else
246 | SDL_RenderCopy(renderer, baseTexture, &diagFeedback, &diagFeedback);
247 | }
248 |
249 | void drawRoadAndLights() {
250 | SDL_Rect sky, road, light, autoIndicator, lightDebug;
251 | sky.x = 0;
252 | sky.y = 0;
253 | sky.w = 862;
254 | sky.h = 162;
255 |
256 | road.x = 0;
257 | road.y = 162;
258 | road.w = 862;
259 | road.h = 160;
260 |
261 | light.x = 171;
262 | light.y = 382;
263 | light.w = 40;
264 | light.h = 24;
265 |
266 | autoIndicator.x = 160;
267 | autoIndicator.y = 410;
268 | autoIndicator.w = 57;
269 | autoIndicator.h = 17;
270 |
271 | lightDebug.x = 685;
272 | lightDebug.y = 396;
273 | lightDebug.w = 61;
274 | lightDebug.h = 35;
275 |
276 | if (controlIsNight == 0) {
277 | SDL_RenderCopy(renderer, baseTexture, &sky, &sky);
278 | SDL_RenderCopy(renderer, baseTexture, &road, &road);
279 | } else {
280 | SDL_RenderCopy(renderer, spriteTex, &sky, &sky);
281 | if (controlLightOn == 1 || luminosityLevel < LIGHT_LEVEL) {
282 | SDL_RenderCopy(renderer, spriteAltTex, &road, &road);
283 | } else {
284 | SDL_RenderCopy(renderer, spriteTex, &road, &road);
285 | }
286 | }
287 |
288 | if (controlLightOn == 1 || luminosityLevel < LIGHT_LEVEL) {
289 | SDL_RenderCopy(renderer, spriteTex, &light, &light);
290 | SDL_RenderCopy(renderer, spriteAltTex, &lightDebug, &lightDebug);
291 | if (luminosityLevel < LIGHT_LEVEL)
292 | SDL_RenderCopy(renderer, spriteTex, &autoIndicator, &autoIndicator);
293 | else
294 | SDL_RenderCopy(renderer, baseTexture, &autoIndicator, &autoIndicator);
295 | } else {
296 | SDL_RenderCopy(renderer, baseTexture, &lightDebug, &lightDebug);
297 | SDL_RenderCopy(renderer, baseTexture, &light, &light);
298 | SDL_RenderCopy(renderer, baseTexture, &autoIndicator, &autoIndicator);
299 | }
300 | }
301 |
302 | /* Updates door unlocks simulated by door open icons */
303 | void drawDoors() {
304 | SDL_Rect door_area, update, pos;
305 | door_area.x = 674;
306 | door_area.y = 432;
307 | door_area.w = 81;
308 | door_area.h = 78;
309 | SDL_RenderCopy(renderer, baseTexture, &door_area, &door_area);
310 | // No update if all doors are locked
311 | if(doorStatus[0] == DOOR_LOCKED && doorStatus[1] == DOOR_LOCKED &&
312 | doorStatus[2] == DOOR_LOCKED && doorStatus[3] == DOOR_LOCKED) return;
313 | // Make the base body red if even one door is unlocked
314 | update.x = 693;
315 | update.y = 432;
316 | update.w = 43;
317 | update.h = 78;
318 | SDL_RenderCopy(renderer, spriteTex, &update, &update);
319 | if(doorStatus[0] == DOOR_UNLOCKED) {
320 | update.x = 678;
321 | update.y = 456;
322 | update.w = 18;
323 | update.h = 17;
324 | SDL_RenderCopy(renderer, spriteTex, &update, &update);
325 | }
326 | if(doorStatus[1] == DOOR_UNLOCKED) {
327 | update.x = 738;
328 | update.y = 456;
329 | update.w = 18;
330 | update.h = 18;
331 | SDL_RenderCopy(renderer, spriteTex, &update, &update);
332 | }
333 | if(doorStatus[2] == DOOR_UNLOCKED) {
334 | update.x = 678;
335 | update.y = 481;
336 | update.w = 18;
337 | update.h = 18;
338 | SDL_RenderCopy(renderer, spriteTex, &update, &update);
339 | }
340 | if(doorStatus[3] == DOOR_UNLOCKED) {
341 | update.x = 738;
342 | update.y = 481;
343 | update.w = 18;
344 | update.h = 18;
345 | SDL_RenderCopy(renderer, spriteTex, &update, &update);
346 | }
347 | SDL_RenderPresent(renderer);
348 | }
349 |
350 | /* Updates turn signals */
351 | void drawTurnSignals() {
352 | SDL_Rect left, right, leftTU, leftTD, rightTU, rightTD, warning;
353 | left.x = 242;
354 | left.y = 378;
355 | left.w = 50;
356 | left.h = 31;
357 |
358 | right.x = 528;
359 | right.y = 378;
360 | right.w = 50;
361 | right.h = 31;
362 |
363 | leftTU.x = 678;
364 | leftTU.y = 422;
365 | leftTU.w = 16;
366 | leftTU.h = 16;
367 |
368 | leftTD.x = 678;
369 | leftTD.y = 506;
370 | leftTD.w = 16;
371 | leftTD.h = 16;
372 |
373 | rightTU.x = 734;
374 | rightTU.y = 422;
375 | rightTU.w = 16;
376 | rightTU.h = 16;
377 |
378 | rightTD.x = 739;
379 | rightTD.y = 506;
380 | rightTD.w = 16;
381 | rightTD.h = 16;
382 |
383 | warning.x = 545;
384 | warning.y = 418;
385 | warning.h = 39;
386 | warning.w = 52;
387 |
388 | if (diagActive == 2) {
389 | if (currentTime % 1000 >= 500) {
390 | turnStatus[0] = OFF;
391 | turnStatus[1] = OFF;
392 | controlTurnValue == 0;
393 | } else {
394 | turnStatus[0] = ON;
395 | turnStatus[1] = ON;
396 | controlTurnValue == 3;
397 | }
398 | }
399 |
400 | if (turnStatus[0] == OFF) {
401 | SDL_RenderCopy(renderer, baseTexture, &left, &left);
402 | } else {
403 | SDL_RenderCopy(renderer, spriteTex, &left, &left);
404 | }
405 |
406 | if(turnStatus[1] == OFF) {
407 | SDL_RenderCopy(renderer, baseTexture, &right, &right);
408 | } else {
409 | SDL_RenderCopy(renderer, spriteTex, &right, &right);
410 | }
411 |
412 | if (controlTurnValue == 1 || controlTurnValue == 3) {
413 | SDL_RenderCopy(renderer, spriteTex, &leftTU, &leftTU);
414 | SDL_RenderCopy(renderer, spriteTex, &leftTD, &leftTD);
415 | }
416 | else {
417 | SDL_RenderCopy(renderer, baseTexture, &leftTU, &leftTU);
418 | SDL_RenderCopy(renderer, baseTexture, &leftTD, &leftTD);
419 | }
420 |
421 | if (controlTurnValue == 2 || controlTurnValue == 3) {
422 | SDL_RenderCopy(renderer, spriteTex, &rightTU, &rightTU);
423 | SDL_RenderCopy(renderer, spriteTex, &rightTD, &rightTD);
424 | }
425 | else {
426 | SDL_RenderCopy(renderer, baseTexture, &rightTU, &rightTU);
427 | SDL_RenderCopy(renderer, baseTexture, &rightTD, &rightTD);
428 | }
429 |
430 | if (warningState == 1)
431 | SDL_RenderCopy(renderer, spriteTex, &warning, &warning);
432 | else
433 | SDL_RenderCopy(renderer, baseTexture, &warning, &warning);
434 | }
435 |
436 | /* Redraws the IC updating everything
437 | * Slowest way to go. Should only use on init
438 | */
439 | void updateIC() {
440 | drawDoors();
441 | drawRoadAndLights();
442 | drawTurnSignals();
443 | drawDiag();
444 | drawSpeed();
445 | drawScore();
446 | SDL_RenderPresent(renderer);
447 | }
448 |
449 | void redrawIC() {
450 | blankIC();
451 | updateIC();
452 | }
453 |
454 | /* Parse can frames and update variables */
455 | void updateSharedData(struct canfd_frame *cf, int maxdlen) {
456 | int seed = (cf->data[5] << 8) + cf->data[6];
457 |
458 | if (shareSeed == -1 || seed == ((shareSeed +1)%65536)) {
459 | char key1 = cf->data[5];
460 | char key2 = cf->data[6];
461 |
462 | for (char i =0; i <= 4; i++) {
463 | cf->data[i] ^= key2;
464 | }
465 | int crc = cf->data[3];
466 | int check = cf->data[4];
467 |
468 | if (check == crc ^ key1 ) {
469 |
470 | if (((cf->data[0] + cf->data[1] + cf->data[2])%256) == crc) {
471 | shareSeed = seed;
472 |
473 | controlLightOn = cf->data[0] >> 6;
474 | controlIsNight = (cf->data[0] >> 5) & 0x1;
475 | controlWarningActive = (cf->data[0] >> 4) & 0x1;
476 | controlDiagOn = (cf->data[0] >> 3) & 0x1;
477 | controlDiagActive = (cf->data[0] >> 2) & 0x1;
478 | controlTurnValue = cf->data[0] & 0x3;
479 | controlLuminosity = cf-> data[1];
480 | controlCurrentSpeed = cf-> data[2];
481 | }
482 | }
483 | }
484 | }
485 |
486 | void updateLuminosityStatus(struct canfd_frame *cf, int maxdlen) {
487 | int len = (cf->len > maxdlen) ? maxdlen : cf->len;
488 | if (len < luminosityPos + 1) return;
489 | pristine = 0;
490 | luminosityLevel = cf->data[luminosityPos];
491 | // CHALLENGE CHECK : cut light by night
492 | if (controlIsNight == 1 && luminosityLevel > LIGHT_LEVEL)
493 | validateChallenge(CHALLENGE_SPOOF_LIGHT);
494 | }
495 |
496 | void drawSpeedStatus(struct canfd_frame *cf, int maxdlen) {
497 | int len = (cf->len > maxdlen) ? maxdlen : cf->len;
498 | if(len < speedPos + 1) return;
499 | pristine = 0;
500 |
501 | int speed = cf->data[speedPos] << 8;
502 | speed += cf->data[speedPos + 1];
503 | speed = speed / 100; // speed in kilometers
504 | currentSpeed = speed;
505 |
506 | // CHALLENGE CHECK : spoof speed on IC
507 | if (currentSpeed >= MAX_SPEED)
508 | validateChallenge(CHALLENGE_SPOOF_SPEED);
509 | }
510 |
511 | void updateWarningStatus(struct canfd_frame *cf, int maxdlen) {
512 | int len = (cf->len > maxdlen) ? maxdlen : cf->len;
513 | if (len < warningPos + 1) return;
514 | pristine = 0;
515 | warningState = cf->data[warningPos] & 0x01;
516 | }
517 |
518 | void updateLightStatus(struct canfd_frame *cf, int maxdlen) {
519 | int len = (cf->len > maxdlen) ? maxdlen : cf->len;
520 | if (len < lightPos + 1) return;
521 | pristine = 0;
522 | lightStatus = cf->data[lightPos] & 0x01;
523 | }
524 |
525 | /* Parses CAN frame and updates turn signal status */
526 | void updateSignalStatus(struct canfd_frame *cf, int maxdlen) {
527 | int len = (cf->len > maxdlen) ? maxdlen : cf->len;
528 | if(len < signalPos) return;
529 | pristine = 0;
530 | if (cf->data[signalPos] & CAN_LEFT_SIGNAL) {
531 | turnStatus[0] = ON;
532 | } else {
533 | turnStatus[0] = OFF;
534 | }
535 | if(cf->data[signalPos] & CAN_RIGHT_SIGNAL) {
536 | turnStatus[1] = ON;
537 | } else {
538 | turnStatus[1] = OFF;
539 | }
540 | // CHALLENGE CHECK : spoof turn signals on IC
541 | if ((turnStatus[1] == ON || turnStatus[0] == ON) && (controlWarningActive ==0 && controlTurnValue == 0))
542 | validateChallenge(CHALLENGE_TURN_SIGNALS);
543 | }
544 |
545 | /* Parses CAN frame and updates door status */
546 | void updateDoorStatus(struct canfd_frame *cf, int maxdlen) {
547 | int len = (cf->len > maxdlen) ? maxdlen : cf->len;
548 | if(len < doorPos) return;
549 | pristine = 0;
550 | if(cf->data[doorPos] & CAN_DOOR1_LOCK) {
551 | doorStatus[0] = DOOR_LOCKED;
552 | } else {
553 | doorStatus[0] = DOOR_UNLOCKED;
554 | }
555 | if(cf->data[doorPos] & CAN_DOOR2_LOCK) {
556 | doorStatus[1] = DOOR_LOCKED;
557 | } else {
558 | doorStatus[1] = DOOR_UNLOCKED;
559 | }
560 | if(cf->data[doorPos] & CAN_DOOR3_LOCK) {
561 | doorStatus[2] = DOOR_LOCKED;
562 | } else {
563 | doorStatus[2] = DOOR_UNLOCKED;
564 | }
565 | if(cf->data[doorPos] & CAN_DOOR4_LOCK) {
566 | doorStatus[3] = DOOR_LOCKED;
567 | } else {
568 | doorStatus[3] = DOOR_UNLOCKED;
569 | }
570 | }
571 |
572 | void sendFrameError(int func, int errorCode) {
573 | memset(&cf, 0, sizeof(cf));
574 | cf.can_id = 0x7E8;
575 | cf.len = 4;
576 | cf.data[0] = 0x03;
577 | cf.data[1] = 0x7F;
578 | cf.data[2] = func;
579 | cf.data[3] = errorCode;
580 | sendPkt(CAN_MTU);
581 | }
582 |
583 | void sendFrameFeedback(int *data, int frameLen) {
584 | memset(&cf, 0, sizeof(cf));
585 | cf.can_id = 0x7E8;
586 | cf.len = frameLen;
587 | for (char i = 0; i < frameLen; i++) {
588 | cf.data[i] = data[i];
589 | }
590 | sendPkt(CAN_MTU);
591 | }
592 |
593 | void sendIsoTpData() {
594 | int frameFeedback[8];
595 | char i = 1;
596 | frameFeedback[0] = 0x20 + ((isoTpRequest - 1)%16);
597 |
598 | for (i; i < 8 && isoTpRemainingBytes > 0; i++) {
599 | frameFeedback[i] = VIN[sizeof(VIN) - isoTpRemainingBytes];
600 | isoTpRemainingBytes --;
601 | }
602 |
603 | if (isoTpRemainingBytes <= 0) {
604 | // CHALLENGE CHECK : VIN request
605 | validateChallenge(CHALLENGE_REQUEST_VIN);
606 | isoTpRequest = 0;
607 | } else
608 | isoTpRequest += 1;
609 | sendFrameFeedback(frameFeedback, i);
610 | }
611 |
612 | void analyseDiagRequest(struct canfd_frame *frame, int maxdlen) {
613 | int frameFeedback[8];
614 | int len = (frame->len > maxdlen) ? maxdlen : frame->len;
615 |
616 | if (frame->data[0] < 0x09 && frame->data[0] > 0) {
617 | int subf = frame->data[2];
618 |
619 | switch (frame->data[1]) {
620 | case PID_INFO:
621 | if (frame->data[0] != 2) {
622 | sendFrameError(PID_INFO, UDS_ERROR_INCORRECT_LENGTH);
623 | return;
624 | }
625 | if (frame->data[2] == PID_INFO_VEHICLE_SPEED) {
626 | frameFeedback[0] = 0x03;
627 | frameFeedback[1] = PID_INFO + 0x40;
628 | frameFeedback[2] = PID_INFO_VEHICLE_SPEED;
629 | frameFeedback[3] = controlCurrentSpeed;
630 | sendFrameFeedback(frameFeedback, 4);
631 | }
632 | else
633 | sendFrameError(PID_INFO, UDS_ERROR_SUBFUNC_NOT_SUPPORTED);
634 | break;
635 | case PID_VEHICLE_INFO:
636 | if (frame->data[0] != 2) {
637 | sendFrameError(PID_INFO, UDS_ERROR_INCORRECT_LENGTH);
638 | return;
639 | }
640 | switch (frame->data[2]) {
641 | case PID_VEHICLE_ECU_NAME:
642 | frameFeedback[0] = 0x03;
643 | frameFeedback[1] = PID_VEHICLE_INFO + 0x40;
644 | frameFeedback[2] = PID_VEHICLE_ECU_NAME;
645 | frameFeedback[3] = 69;
646 | frameFeedback[4] = 67;
647 | frameFeedback[5] = 85;
648 | sendFrameFeedback(frameFeedback, 6);
649 | break;
650 |
651 | case PID_VEHICLE_VIN:
652 | isoTpRemainingBytes = sizeof(VIN);
653 |
654 | if (isoTpRemainingBytes > 6) {
655 | frameFeedback[0] = 0x10 + ((isoTpRemainingBytes & 0x0F00) >> 8);
656 | frameFeedback[1] = isoTpRemainingBytes & 0xFF;
657 | isoTpFirstFlowTime = currentTime;
658 | }
659 | else {
660 | frameFeedback[0] = isoTpRemainingBytes + 1;
661 | frameFeedback[1] = PID_VEHICLE_INFO + 0x40;
662 | }
663 | char i = 2;
664 | for (i; i < 8 && isoTpRemainingBytes > 0; i++) {
665 | frameFeedback[i] = VIN[sizeof(VIN) - isoTpRemainingBytes];
666 | isoTpRemainingBytes --;
667 | }
668 |
669 | sendFrameFeedback(frameFeedback, i);
670 |
671 | break;
672 | default:
673 | sendFrameError(PID_INFO, UDS_ERROR_SUBFUNC_NOT_SUPPORTED);
674 | break;
675 | }
676 | break;
677 |
678 | case UDS_SID_TESTER_PRESENT:
679 | if (frame->data[0] == 0x02) {
680 | lastDiagTesterPresent = currentTime;
681 | frameFeedback[0] = 0x02;
682 | frameFeedback[1] = UDS_SID_TESTER_PRESENT + 0x40;
683 | frameFeedback[2] = subf;
684 | sendFrameFeedback(frameFeedback, 3);
685 | } else {
686 | sendFrameError(UDS_SID_TESTER_PRESENT, UDS_ERROR_INCORRECT_LENGTH);
687 | }
688 | break;
689 |
690 | case UDS_SID_DIAGNOSTIC_CONTROL:
691 | if (frame->data[0] == 0x02) {
692 | switch (frame->data[2]) {
693 | case 0x01:
694 | diagSession = 1;
695 | diagActive = 0;
696 | secretSessionFound = 0;
697 | lastDiagTesterPresent = currentTime;
698 | frameFeedback[0] = 0x02;
699 | frameFeedback[1] = UDS_SID_DIAGNOSTIC_CONTROL + 0x40;
700 | frameFeedback[2] = subf;
701 | sendFrameFeedback(frameFeedback, 3);
702 | break;
703 | case 0x02:
704 | diagSession = 2;
705 | lastDiagTesterPresent = currentTime;
706 | secretSessionFound = 0;
707 | frameFeedback[0] = 0x02;
708 | frameFeedback[1] = UDS_SID_DIAGNOSTIC_CONTROL + 0x40;
709 | frameFeedback[2] = subf;
710 | sendFrameFeedback(frameFeedback, 3);
711 | break;
712 | case 0x03:
713 | diagSession = 3;
714 | lastDiagTesterPresent = currentTime;
715 | secretSessionFound = 0;
716 | frameFeedback[0] = 0x02;
717 | frameFeedback[1] = UDS_SID_DIAGNOSTIC_CONTROL + 0x40;
718 | frameFeedback[2] = subf;
719 | sendFrameFeedback(frameFeedback, 3);
720 | break;
721 | default:
722 | sendFrameError(UDS_SID_DIAGNOSTIC_CONTROL, UDS_ERROR_SUBFUNC_NOT_SUPPORTED);
723 | return;
724 | break;
725 |
726 | frameFeedback[0] = 0x02;
727 | frameFeedback[1] = UDS_SID_DIAGNOSTIC_CONTROL + 0x40;
728 | frameFeedback[2] = subf;
729 | sendFrameFeedback(frameFeedback, 3);
730 | }
731 | } else {
732 | sendFrameError(UDS_SID_DIAGNOSTIC_CONTROL, UDS_ERROR_INCORRECT_LENGTH);
733 | }
734 | break;
735 |
736 | case UDS_SID_ECU_RESET:
737 | if (frame->data[0] == 2) {
738 | if (frame->data[2] > 0 && frame->data[2] <= 3) {
739 | diagSession = 1;
740 | seedGenerated = 0;
741 | diagActive = 0;
742 | secretSessionFound = 0;
743 | frameFeedback[0] = 0x02;
744 | frameFeedback[1] = UDS_SID_ECU_RESET + 0x40;
745 | frameFeedback[2] = subf;
746 | sendFrameFeedback(frameFeedback, 3);
747 | }
748 | else
749 | sendFrameError(UDS_SID_ECU_RESET, UDS_ERROR_SUBFUNC_NOT_SUPPORTED);
750 | } else
751 | sendFrameError(UDS_SID_ECU_RESET, UDS_ERROR_INCORRECT_LENGTH);
752 | break;
753 |
754 | case UDS_SID_ROUTINE_CONTROL:
755 | if (frame->data[0] == 4) {
756 | if (diagSession == 2) {
757 | if (frame->data[2] == 0x41) {
758 | if (frame->data[3] == 0x10 || frame->data[3] == 0x22) {
759 | if (frame->data[4] == 0x00 || frame->data[4] == 0x01) {
760 | switch (frame->data[3]) {
761 | case 0x10:
762 | diagActive = frame->data[4];
763 | break;
764 | case 0x22:
765 | diagActive = frame->data[4] * 2;
766 | validateChallenge(CHALLENGE_FIND_ROUTINE_CONTROL);
767 | break;
768 | }
769 | frameFeedback[0] = 0x04;
770 | frameFeedback[1] = UDS_SID_ROUTINE_CONTROL + 0x40;
771 | frameFeedback[2] = subf;
772 | frameFeedback[3] = frame->data[3];
773 | frameFeedback[4] = frame->data[4];
774 | sendFrameFeedback(frameFeedback, 5);
775 | } else
776 | sendFrameError(UDS_SID_ROUTINE_CONTROL, UDS_ERROR_REQUEST_OUT_RANGE);
777 | } else
778 | sendFrameError(UDS_SID_ROUTINE_CONTROL, UDS_ERROR_REQUEST_OUT_RANGE);
779 | } else
780 | sendFrameError(UDS_SID_ROUTINE_CONTROL, UDS_ERROR_SUBFUNC_NOT_SUPPORTED);
781 | } else
782 | sendFrameError(UDS_SID_ROUTINE_CONTROL, UDS_ERROR_FUNC_INCORRECT_SESSION);
783 | } else
784 | sendFrameError(UDS_SID_ROUTINE_CONTROL, UDS_ERROR_INCORRECT_LENGTH);
785 | break;
786 |
787 | case UDS_SID_SECURITY_ACCESS:
788 | if (diagSession != 0x03) {
789 | sendFrameError(UDS_SID_SECURITY_ACCESS, UDS_ERROR_FUNC_INCORRECT_SESSION);
790 | return;
791 | }
792 |
793 | switch (frame->data[2]) {
794 | case 0x01:
795 | if (frame->data[0] != 2) {
796 | sendFrameError(UDS_SID_SECURITY_ACCESS, UDS_ERROR_INCORRECT_LENGTH);
797 | return;
798 | }
799 | frameFeedback[0] = 0x04;
800 | frameFeedback[1] = UDS_SID_SECURITY_ACCESS + 0x40;
801 | frameFeedback[2] = subf;
802 | diagSeed[0] = rand()%255;
803 | diagSeed[1] = rand()%255;
804 | frameFeedback[3] = diagSeed[0];
805 | frameFeedback[4] = diagSeed[1];
806 | seedGenerated = 1;
807 | sendFrameFeedback(frameFeedback, 5);
808 | break;
809 | case 0x02:
810 | if (frame->data[0] != 4) {
811 | sendFrameError(UDS_SID_SECURITY_ACCESS, UDS_ERROR_INCORRECT_LENGTH);
812 | return;
813 | }
814 | if (seedGenerated == 0)
815 | sendFrameError(UDS_SID_SECURITY_ACCESS, UDS_ERROR_SEQUENCE_ERROR);
816 |
817 | else {
818 | if (frame->data[3] == (diagSeed[0] ^ sessionKey[0]) && frame->data[4] == (diagSeed[1] ^ sessionKey[1])) {
819 | diagSession = 0x02;
820 | frameFeedback[0] = 0x02;
821 | frameFeedback[1] = UDS_SID_SECURITY_ACCESS + 0x40;
822 | frameFeedback[2] = subf;
823 | seedGenerated = 0;
824 | secretSessionFound = 1;
825 | validateChallenge(CHALLENGE_SECURITY_ACCESS);
826 | sendFrameFeedback(frameFeedback, 3);
827 | } else {
828 | sendFrameError(UDS_SID_SECURITY_ACCESS, UDS_ERROR_INVALID_KEY);
829 | }
830 | }
831 | break;
832 | default:
833 | sendFrameError(UDS_SID_SECURITY_ACCESS, UDS_ERROR_SUBFUNC_NOT_SUPPORTED);
834 | return;
835 | break;
836 | }
837 | break;
838 | default:
839 | sendFrameError(frame->data[1], UDS_ERROR_SERVICE_NOT_SUPPORTED);
840 | break;
841 | }
842 | }
843 | else if ((frame->data[0] & 0xF0) == 0x30 && isoTpRemainingBytes > 0) {
844 | if ((isoTpFirstFlowTime + ISOTP_TIMEOUT) >= currentTime)
845 | isoTpRequest = 1;
846 | else
847 | isoTpRemainingBytes;
848 | }
849 | }
850 |
851 | void Usage(char *msg) {
852 | if(msg) printf("%s\n", msg);
853 | printf("Usage: icsim [options] \n");
854 | printf("\t-r\trandomize IDs\n");
855 | printf("\t-d\tdebug mode\n");
856 | exit(1);
857 | }
858 |
859 | int main(int argc, char *argv[]) {
860 | int opt;
861 | struct ifreq ifr;
862 | struct sockaddr_can addr;
863 | struct canfd_frame frame;
864 | struct iovec iov;
865 | struct msghdr msg;
866 | struct cmsghdr *cmsg;
867 | struct timeval tv, timeoutConfig = { 0, 0 };
868 | struct stat dirstat;
869 | fd_set rdfs;
870 | char ctrlmsg[CMSG_SPACE(sizeof(struct timeval)) + CMSG_SPACE(sizeof(__u32))];
871 | int running = 1;
872 | int nbytes, maxdlen;
873 | int ret;
874 | int seed = 0;
875 | int doorId, signalId, speedId, warningId, diagId, lightId, luminosityId, controlId;
876 | SDL_Event event;
877 |
878 | while ((opt = getopt(argc, argv, "r:d:h?")) != -1) {
879 | switch(opt) {
880 | case 'r':
881 | randomize = 1;
882 | break;
883 | case 'd':
884 | debug = 1;
885 | break;
886 | case 'h':
887 | case '?':
888 | default:
889 | Usage(NULL);
890 | break;
891 | }
892 | }
893 |
894 | if (optind >= argc) Usage("You must specify at least one can device");
895 |
896 | // Verify data directory exists
897 | if(stat(DATA_DIR, &dirstat) == -1) {
898 | printf("ERROR: DATA_DIR not found. Define in make file or run in src dir\n");
899 | exit(34);
900 | }
901 |
902 | // Create a new raw CAN socket
903 | can = socket(PF_CAN, SOCK_RAW, CAN_RAW);
904 | if (can < 0) Usage("Couldn't create raw socket");
905 |
906 | addr.can_family = AF_CAN;
907 | memset(&ifr.ifr_name, 0, sizeof(ifr.ifr_name));
908 | strncpy(ifr.ifr_name, argv[optind], strlen(argv[optind]));
909 | printf("Using CAN interface %s\n", ifr.ifr_name);
910 | if (ioctl(can, SIOCGIFINDEX, &ifr) < 0) {
911 | perror("SIOCGIFINDEX");
912 | exit(1);
913 | }
914 | addr.can_ifindex = ifr.ifr_ifindex;
915 |
916 | // CAN FD Mode
917 | setsockopt(can, SOL_CAN_RAW, CAN_RAW_FD_FRAMES, &canfd_on, sizeof(canfd_on));
918 |
919 | iov.iov_base = &frame;
920 | iov.iov_len = sizeof(frame);
921 | msg.msg_name = &addr;
922 | msg.msg_namelen = sizeof(addr);
923 | msg.msg_iov = &iov;
924 | msg.msg_iovlen = 1;
925 | msg.msg_control = &ctrlmsg;
926 | msg.msg_controllen = sizeof(ctrlmsg);
927 | msg.msg_flags = 0;
928 |
929 | if (bind(can, (struct sockaddr *)&addr, sizeof(addr)) < 0) {
930 | perror("bind");
931 | return 1;
932 | }
933 |
934 | initCarState();
935 |
936 | doorId = DEFAULT_DOOR_ID;
937 | signalId = DEFAULT_SIGNAL_ID;
938 | speedId = DEFAULT_SPEED_ID;
939 | warningId = DEFAULT_WARNING_ID;
940 | diagId = DEFAULT_ECU_ID;
941 | lightId = DEFAULT_LIGHT_ID;
942 | luminosityId = DEFAULT_LUMINOSITY_ID;
943 | controlId = DEFAULT_CONTROL_ID;
944 |
945 | if (randomize) {
946 | if(randomize) seed = time(NULL);
947 | srand(seed);
948 | doorId = (rand() % 2046) + 1;
949 | signalId = (rand() % 2046) + 1;
950 | speedId = (rand() % 2046) + 1;
951 | doorPos = rand() % 9;
952 | signalPos = rand() % 9;
953 | speedPos = rand() % 8;
954 | printf("Seed: %d\n", seed);
955 | FILE *fdseed = fopen("/tmp/icsim_seed.txt", "w");
956 | fprintf(fdseed, "%d\n", seed);
957 | fclose(fdseed);
958 | }
959 |
960 | SDL_Window *window = NULL;
961 | SDL_Surface *screenSurface = NULL;
962 | if(SDL_Init ( SDL_INIT_VIDEO ) < 0 ) {
963 | printf("SDL Could not initializes\n");
964 | exit(40);
965 | }
966 |
967 | window = SDL_CreateWindow("IC Simulator", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); // | SDL_WINDOW_RESIZABLE);
968 | if(window == NULL) {
969 | printf("Window could not be shown\n");
970 | }
971 |
972 | renderer = SDL_CreateRenderer(window, -1, 0);
973 |
974 | SDL_Surface *image = IMG_Load(getData("dashboard.png"));
975 | SDL_Surface *needle = IMG_Load(getData("needle.png"));
976 | SDL_Surface *sprites = IMG_Load(getData("spritesheet.png"));
977 | SDL_Surface *spritesAlt = IMG_Load(getData("spritesheet-alt.png"));
978 | SDL_Surface *scoreboard = IMG_Load(getData("scoreboard.png"));
979 | baseTexture = SDL_CreateTextureFromSurface(renderer, image);
980 | needleTex = SDL_CreateTextureFromSurface(renderer, needle);
981 | spriteTex = SDL_CreateTextureFromSurface(renderer, sprites);
982 | spriteAltTex = SDL_CreateTextureFromSurface(renderer, spritesAlt);
983 | scoreboardTex = SDL_CreateTextureFromSurface(renderer, scoreboard);
984 |
985 | // Draw the IC
986 | redrawIC();
987 |
988 | /* For now we will just operate on one CAN interface */
989 | while(running) {
990 | while( SDL_PollEvent(&event) != 0 ) {
991 | switch(event.type) {
992 | case SDL_QUIT:
993 | running = 0;
994 | break;
995 | case SDL_WINDOWEVENT:
996 | switch(event.window.event) {
997 | case SDL_WINDOWEVENT_ENTER:
998 | case SDL_WINDOWEVENT_RESIZED:
999 | redrawIC();
1000 | break;
1001 | }
1002 | }
1003 | SDL_Delay(3);
1004 | }
1005 |
1006 | nbytes = recvmsg(can, &msg, 0);
1007 | if (nbytes < 0) {
1008 | perror("read");
1009 | return 1;
1010 | }
1011 | if ((size_t)nbytes == CAN_MTU)
1012 | maxdlen = CAN_MAX_DLEN;
1013 | else if ((size_t)nbytes == CANFD_MTU)
1014 | maxdlen = CANFD_MAX_DLEN;
1015 | else {
1016 | fprintf(stderr, "read: incomplete CAN frame\n");
1017 | return 1;
1018 | }
1019 |
1020 | for (cmsg = CMSG_FIRSTHDR(&msg);
1021 | cmsg && (cmsg->cmsg_level == SOL_SOCKET);
1022 | cmsg = CMSG_NXTHDR(&msg,cmsg)) {
1023 | if (cmsg->cmsg_type == SO_TIMESTAMP)
1024 | tv = *(struct timeval *)CMSG_DATA(cmsg);
1025 | else if (cmsg->cmsg_type == SO_RXQ_OVFL)
1026 | //dropcnt[i] = *(__u32 *)CMSG_DATA(cmsg);
1027 | fprintf(stderr, "Dropped packet\n");
1028 | }
1029 |
1030 | currentTime = SDL_GetTicks();
1031 | pristine = 1;
1032 | if (frame.can_id == controlId) updateSharedData(&frame, maxdlen);
1033 | if (frame.can_id == doorId) updateDoorStatus(&frame, maxdlen);
1034 | if (frame.can_id == signalId) updateSignalStatus(&frame, maxdlen);
1035 | if (frame.can_id == speedId) drawSpeedStatus(&frame, maxdlen);
1036 | if (frame.can_id == warningId) updateWarningStatus(&frame, maxdlen);
1037 | if (frame.can_id == lightId) updateLightStatus(&frame, maxdlen);
1038 | if (frame.can_id == luminosityId) updateLuminosityStatus(&frame, maxdlen);
1039 | if (frame.can_id == diagId || frame.can_id == diagId - 1) analyseDiagRequest(&frame, maxdlen);
1040 | if (diagSession > 1 && ((lastDiagTesterPresent + 3500) < currentTime)) {
1041 | diagSession = 1;
1042 | seedGenerated = 0;
1043 | diagActive = 0;
1044 | secretSessionFound = 0;
1045 | }
1046 | if (isoTpRequest > 0 && isoTpRemainingBytes > 0) {
1047 | sendIsoTpData();
1048 | }
1049 |
1050 | if (pristine == 0) updateIC();
1051 | }
1052 |
1053 | SDL_DestroyTexture(baseTexture);
1054 | SDL_DestroyTexture(needleTex);
1055 | SDL_DestroyTexture(spriteTex);
1056 | SDL_FreeSurface(image);
1057 | SDL_FreeSurface(needle);
1058 | SDL_FreeSurface(sprites);
1059 | SDL_DestroyRenderer(renderer);
1060 | SDL_DestroyWindow(window);
1061 | IMG_Quit();
1062 | SDL_Quit();
1063 |
1064 | return 0;
1065 | }
1066 |
--------------------------------------------------------------------------------
/CAN/icsim.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/CAN/icsim.o
--------------------------------------------------------------------------------
/CAN/lib.c:
--------------------------------------------------------------------------------
1 | /*
2 | * lib.c - library for command line tools
3 | *
4 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions
9 | * are met:
10 | * 1. Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | * 3. Neither the name of Volkswagen nor the names of its contributors
16 | * may be used to endorse or promote products derived from this software
17 | * without specific prior written permission.
18 | *
19 | * Alternatively, provided that this notice is retained in full, this
20 | * software may be distributed under the terms of the GNU General
21 | * Public License ("GPL") version 2, in which case the provisions of the
22 | * GPL apply INSTEAD OF those given above.
23 | *
24 | * The provided data structures and external interfaces from this code
25 | * are not restricted to be used by modules with a GPL compatible license.
26 | *
27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38 | * DAMAGE.
39 | *
40 | * Send feedback to
41 | *
42 | */
43 |
44 | #include
45 | #include
46 | #include
47 |
48 | #include /* for sa_family_t */
49 | #include
50 | #include
51 |
52 | #include "lib.h"
53 |
54 | #define CANID_DELIM '#'
55 | #define DATA_SEPERATOR '.'
56 |
57 | /* CAN DLC to real data length conversion helpers */
58 |
59 | static const unsigned char dlc2len[] = {0, 1, 2, 3, 4, 5, 6, 7,
60 | 8, 12, 16, 20, 24, 32, 48, 64};
61 |
62 | /* get data length from can_dlc with sanitized can_dlc */
63 | unsigned char can_dlc2len(unsigned char can_dlc)
64 | {
65 | return dlc2len[can_dlc & 0x0F];
66 | }
67 |
68 | static const unsigned char len2dlc[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, /* 0 - 8 */
69 | 9, 9, 9, 9, /* 9 - 12 */
70 | 10, 10, 10, 10, /* 13 - 16 */
71 | 11, 11, 11, 11, /* 17 - 20 */
72 | 12, 12, 12, 12, /* 21 - 24 */
73 | 13, 13, 13, 13, 13, 13, 13, 13, /* 25 - 32 */
74 | 14, 14, 14, 14, 14, 14, 14, 14, /* 33 - 40 */
75 | 14, 14, 14, 14, 14, 14, 14, 14, /* 41 - 48 */
76 | 15, 15, 15, 15, 15, 15, 15, 15, /* 49 - 56 */
77 | 15, 15, 15, 15, 15, 15, 15, 15}; /* 57 - 64 */
78 |
79 | /* map the sanitized data length to an appropriate data length code */
80 | unsigned char can_len2dlc(unsigned char len)
81 | {
82 | if (len > 64)
83 | return 0xF;
84 |
85 | return len2dlc[len];
86 | }
87 |
88 | unsigned char asc2nibble(char c) {
89 |
90 | if ((c >= '0') && (c <= '9'))
91 | return c - '0';
92 |
93 | if ((c >= 'A') && (c <= 'F'))
94 | return c - 'A' + 10;
95 |
96 | if ((c >= 'a') && (c <= 'f'))
97 | return c - 'a' + 10;
98 |
99 | return 16; /* error */
100 | }
101 |
102 | int hexstring2data(char *arg, unsigned char *data, int maxdlen) {
103 |
104 | int len = strlen(arg);
105 | int i;
106 | unsigned char tmp;
107 |
108 | if (!len || len%2 || len > maxdlen*2)
109 | return 1;
110 |
111 | memset(data, 0, maxdlen);
112 |
113 | for (i=0; i < len/2; i++) {
114 |
115 | tmp = asc2nibble(*(arg+(2*i)));
116 | if (tmp > 0x0F)
117 | return 1;
118 |
119 | data[i] = (tmp << 4);
120 |
121 | tmp = asc2nibble(*(arg+(2*i)+1));
122 | if (tmp > 0x0F)
123 | return 1;
124 |
125 | data[i] |= tmp;
126 | }
127 |
128 | return 0;
129 | }
130 |
131 | int parse_canframe(char *cs, struct canfd_frame *cf) {
132 | /* documentation see lib.h */
133 |
134 | int i, idx, dlen, len;
135 | int maxdlen = CAN_MAX_DLEN;
136 | int ret = CAN_MTU;
137 | unsigned char tmp;
138 |
139 | len = strlen(cs);
140 | //printf("'%s' len %d\n", cs, len);
141 |
142 | memset(cf, 0, sizeof(*cf)); /* init CAN FD frame, e.g. LEN = 0 */
143 |
144 | if (len < 4)
145 | return 0;
146 |
147 | if (cs[3] == CANID_DELIM) { /* 3 digits */
148 |
149 | idx = 4;
150 | for (i=0; i<3; i++){
151 | if ((tmp = asc2nibble(cs[i])) > 0x0F)
152 | return 0;
153 | cf->can_id |= (tmp << (2-i)*4);
154 | }
155 |
156 | } else if (cs[8] == CANID_DELIM) { /* 8 digits */
157 |
158 | idx = 9;
159 | for (i=0; i<8; i++){
160 | if ((tmp = asc2nibble(cs[i])) > 0x0F)
161 | return 0;
162 | cf->can_id |= (tmp << (7-i)*4);
163 | }
164 | if (!(cf->can_id & CAN_ERR_FLAG)) /* 8 digits but no errorframe? */
165 | cf->can_id |= CAN_EFF_FLAG; /* then it is an extended frame */
166 |
167 | } else
168 | return 0;
169 |
170 | if((cs[idx] == 'R') || (cs[idx] == 'r')){ /* RTR frame */
171 | cf->can_id |= CAN_RTR_FLAG;
172 |
173 | /* check for optional DLC value for CAN 2.0B frames */
174 | if(cs[++idx] && (tmp = asc2nibble(cs[idx])) <= CAN_MAX_DLC)
175 | cf->len = tmp;
176 |
177 | return ret;
178 | }
179 |
180 | if (cs[idx] == CANID_DELIM) { /* CAN FD frame escape char '##' */
181 |
182 | maxdlen = CANFD_MAX_DLEN;
183 | ret = CANFD_MTU;
184 |
185 | /* CAN FD frame ##* */
186 | if ((tmp = asc2nibble(cs[idx+1])) > 0x0F)
187 | return 0;
188 |
189 | cf->flags = tmp;
190 | idx += 2;
191 | }
192 |
193 | for (i=0, dlen=0; i < maxdlen; i++){
194 |
195 | if(cs[idx] == DATA_SEPERATOR) /* skip (optional) separator */
196 | idx++;
197 |
198 | if(idx >= len) /* end of string => end of data */
199 | break;
200 |
201 | if ((tmp = asc2nibble(cs[idx++])) > 0x0F)
202 | return 0;
203 | cf->data[i] = (tmp << 4);
204 | if ((tmp = asc2nibble(cs[idx++])) > 0x0F)
205 | return 0;
206 | cf->data[i] |= tmp;
207 | dlen++;
208 | }
209 | cf->len = dlen;
210 |
211 | return ret;
212 | }
213 |
214 | void fprint_canframe(FILE *stream , struct canfd_frame *cf, char *eol, int sep, int maxdlen) {
215 | /* documentation see lib.h */
216 |
217 | char buf[CL_CFSZ]; /* max length */
218 |
219 | sprint_canframe(buf, cf, sep, maxdlen);
220 | fprintf(stream, "%s", buf);
221 | if (eol)
222 | fprintf(stream, "%s", eol);
223 | }
224 |
225 | void sprint_canframe(char *buf , struct canfd_frame *cf, int sep, int maxdlen) {
226 | /* documentation see lib.h */
227 |
228 | int i,offset;
229 | int len = (cf->len > maxdlen) ? maxdlen : cf->len;
230 |
231 | if (cf->can_id & CAN_ERR_FLAG) {
232 | sprintf(buf, "%08X#", cf->can_id & (CAN_ERR_MASK|CAN_ERR_FLAG));
233 | offset = 9;
234 | } else if (cf->can_id & CAN_EFF_FLAG) {
235 | sprintf(buf, "%08X#", cf->can_id & CAN_EFF_MASK);
236 | offset = 9;
237 | } else {
238 | sprintf(buf, "%03X#", cf->can_id & CAN_SFF_MASK);
239 | offset = 4;
240 | }
241 |
242 | /* standard CAN frames may have RTR enabled. There are no ERR frames with RTR */
243 | if (maxdlen == CAN_MAX_DLEN && cf->can_id & CAN_RTR_FLAG) {
244 |
245 | /* print a given CAN 2.0B DLC if it's not zero */
246 | if (cf->len && cf->len <= CAN_MAX_DLC)
247 | sprintf(buf+offset, "R%d", cf->len);
248 | else
249 | sprintf(buf+offset, "R");
250 |
251 | return;
252 | }
253 |
254 | if (maxdlen == CANFD_MAX_DLEN) {
255 | /* add CAN FD specific escape char and flags */
256 | sprintf(buf+offset, "#%X", cf->flags & 0xF);
257 | offset += 2;
258 | if (sep && len)
259 | sprintf(buf+offset++, ".");
260 | }
261 |
262 | for (i = 0; i < len; i++) {
263 | sprintf(buf+offset, "%02X", cf->data[i]);
264 | offset += 2;
265 | if (sep && (i+1 < len))
266 | sprintf(buf+offset++, ".");
267 | }
268 | }
269 |
270 | void fprint_long_canframe(FILE *stream , struct canfd_frame *cf, char *eol, int view, int maxdlen) {
271 | /* documentation see lib.h */
272 |
273 | char buf[CL_LONGCFSZ];
274 |
275 | sprint_long_canframe(buf, cf, view, maxdlen);
276 | fprintf(stream, "%s", buf);
277 | if ((view & CANLIB_VIEW_ERROR) && (cf->can_id & CAN_ERR_FLAG)) {
278 | snprintf_can_error_frame(buf, sizeof(buf), cf, "\n\t");
279 | fprintf(stream, "\n\t%s", buf);
280 | }
281 | if (eol)
282 | fprintf(stream, "%s", eol);
283 | }
284 |
285 | void sprint_long_canframe(char *buf , struct canfd_frame *cf, int view, int maxdlen) {
286 | /* documentation see lib.h */
287 |
288 | int i, j, dlen, offset;
289 | int len = (cf->len > maxdlen)? maxdlen : cf->len;
290 |
291 | if (cf->can_id & CAN_ERR_FLAG) {
292 | sprintf(buf, "%08X ", cf->can_id & (CAN_ERR_MASK|CAN_ERR_FLAG));
293 | offset = 10;
294 | } else if (cf->can_id & CAN_EFF_FLAG) {
295 | sprintf(buf, "%08X ", cf->can_id & CAN_EFF_MASK);
296 | offset = 10;
297 | } else {
298 | if (view & CANLIB_VIEW_INDENT_SFF) {
299 | sprintf(buf, " %03X ", cf->can_id & CAN_SFF_MASK);
300 | offset = 10;
301 | } else {
302 | sprintf(buf, "%03X ", cf->can_id & CAN_SFF_MASK);
303 | offset = 5;
304 | }
305 | }
306 |
307 | if (maxdlen == CAN_MAX_DLEN) {
308 | sprintf(buf+offset, " [%d] ", len);
309 | /* standard CAN frames may have RTR enabled */
310 | if (cf->can_id & CAN_RTR_FLAG) {
311 | sprintf(buf+offset+5, " remote request");
312 | return;
313 | }
314 | } else {
315 | sprintf(buf+offset, "[%02d] ", len);
316 | }
317 | offset += 5;
318 |
319 | if (view & CANLIB_VIEW_BINARY) {
320 | dlen = 9; /* _10101010 */
321 | if (view & CANLIB_VIEW_SWAP) {
322 | for (i = len - 1; i >= 0; i--) {
323 | buf[offset++] = (i == len-1)?' ':SWAP_DELIMITER;
324 | for (j = 7; j >= 0; j--)
325 | buf[offset++] = (1<data[i])?'1':'0';
326 | }
327 | } else {
328 | for (i = 0; i < len; i++) {
329 | buf[offset++] = ' ';
330 | for (j = 7; j >= 0; j--)
331 | buf[offset++] = (1<data[i])?'1':'0';
332 | }
333 | }
334 | buf[offset] = 0; /* terminate string */
335 | } else {
336 | dlen = 3; /* _AA */
337 | if (view & CANLIB_VIEW_SWAP) {
338 | for (i = len - 1; i >= 0; i--) {
339 | sprintf(buf+offset, "%c%02X",
340 | (i == len-1)?' ':SWAP_DELIMITER,
341 | cf->data[i]);
342 | offset += dlen;
343 | }
344 | } else {
345 | for (i = 0; i < len; i++) {
346 | sprintf(buf+offset, " %02X", cf->data[i]);
347 | offset += dlen;
348 | }
349 | }
350 | }
351 |
352 | /*
353 | * The ASCII & ERRORFRAME output is put at a fixed len behind the data.
354 | * For now we support ASCII output only for payload length up to 8 bytes.
355 | * Does it make sense to write 64 ASCII byte behind 64 ASCII HEX data on the console?
356 | */
357 | if (len > CAN_MAX_DLEN)
358 | return;
359 |
360 | if (cf->can_id & CAN_ERR_FLAG)
361 | sprintf(buf+offset, "%*s", dlen*(8-len)+13, "ERRORFRAME");
362 | else if (view & CANLIB_VIEW_ASCII) {
363 | j = dlen*(8-len)+4;
364 | if (view & CANLIB_VIEW_SWAP) {
365 | sprintf(buf+offset, "%*s", j, "`");
366 | offset += j;
367 | for (i = len - 1; i >= 0; i--)
368 | if ((cf->data[i] > 0x1F) && (cf->data[i] < 0x7F))
369 | buf[offset++] = cf->data[i];
370 | else
371 | buf[offset++] = '.';
372 |
373 | sprintf(buf+offset, "`");
374 | } else {
375 | sprintf(buf+offset, "%*s", j, "'");
376 | offset += j;
377 | for (i = 0; i < len; i++)
378 | if ((cf->data[i] > 0x1F) && (cf->data[i] < 0x7F))
379 | buf[offset++] = cf->data[i];
380 | else
381 | buf[offset++] = '.';
382 |
383 | sprintf(buf+offset, "'");
384 | }
385 | }
386 | }
387 |
388 | static const char *error_classes[] = {
389 | "tx-timeout",
390 | "lost-arbitration",
391 | "controller-problem",
392 | "protocol-violation",
393 | "transceiver-status",
394 | "no-acknowledgement-on-tx",
395 | "bus-off",
396 | "bus-error",
397 | "restarted-after-bus-off",
398 | };
399 |
400 | static const char *controller_problems[] = {
401 | "rx-overflow",
402 | "tx-overflow",
403 | "rx-error-warning",
404 | "tx-error-warning",
405 | "rx-error-passive",
406 | "tx-error-passive",
407 | };
408 |
409 | static const char *protocol_violation_types[] = {
410 | "single-bit-error",
411 | "frame-format-error",
412 | "bit-stuffing-error",
413 | "tx-dominant-bit-error",
414 | "tx-recessive-bit-error",
415 | "bus-overload",
416 | "back-to-error-active",
417 | "error-on-tx",
418 | };
419 |
420 | static const char *protocol_violation_locations[] = {
421 | "unspecified",
422 | "unspecified",
423 | "id.28-to-id.28",
424 | "start-of-frame",
425 | "bit-srtr",
426 | "bit-ide",
427 | "id.20-to-id.18",
428 | "id.17-to-id.13",
429 | "crc-sequence",
430 | "reserved-bit-0",
431 | "data-field",
432 | "data-length-code",
433 | "bit-rtr",
434 | "reserved-bit-1",
435 | "id.4-to-id.0",
436 | "id.12-to-id.5",
437 | "unspecified",
438 | "active-error-flag",
439 | "intermission",
440 | "tolerate-dominant-bits",
441 | "unspecified",
442 | "unspecified",
443 | "passive-error-flag",
444 | "error-delimiter",
445 | "crc-delimiter",
446 | "acknowledge-slot",
447 | "end-of-frame",
448 | "acknowledge-delimiter",
449 | "overload-flag",
450 | "unspecified",
451 | "unspecified",
452 | "unspecified",
453 | };
454 |
455 | #ifndef ARRAY_SIZE
456 | #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
457 | #endif
458 |
459 | static int snprintf_error_data(char *buf, size_t len, uint8_t err,
460 | const char **arr, int arr_len)
461 | {
462 | int i, n = 0, count = 0;
463 |
464 | if (!err || len <= 0)
465 | return 0;
466 |
467 | for (i = 0; i < arr_len; i++) {
468 | if (err & (1 << i)) {
469 | if (count)
470 | n += snprintf(buf + n, len - n, ",");
471 | n += snprintf(buf + n, len - n, "%s", arr[i]);
472 | count++;
473 | }
474 | }
475 |
476 | return n;
477 | }
478 |
479 | static int snprintf_error_lostarb(char *buf, size_t len, struct canfd_frame *cf)
480 | {
481 | if (len <= 0)
482 | return 0;
483 | return snprintf(buf, len, "{at bit %d}", cf->data[0]);
484 | }
485 |
486 | static int snprintf_error_ctrl(char *buf, size_t len, struct canfd_frame *cf)
487 | {
488 | int n = 0;
489 |
490 | if (len <= 0)
491 | return 0;
492 |
493 | n += snprintf(buf + n, len - n, "{");
494 | n += snprintf_error_data(buf + n, len - n, cf->data[1],
495 | controller_problems,
496 | ARRAY_SIZE(controller_problems));
497 | n += snprintf(buf + n, len - n, "}");
498 |
499 | return n;
500 | }
501 |
502 | static int snprintf_error_prot(char *buf, size_t len, struct canfd_frame *cf)
503 | {
504 | int n = 0;
505 |
506 | if (len <= 0)
507 | return 0;
508 |
509 | n += snprintf(buf + n, len - n, "{{");
510 | n += snprintf_error_data(buf + n, len - n, cf->data[2],
511 | protocol_violation_types,
512 | ARRAY_SIZE(protocol_violation_types));
513 | n += snprintf(buf + n, len - n, "}{");
514 | if (cf->data[3] > 0 &&
515 | cf->data[3] < ARRAY_SIZE(protocol_violation_locations))
516 | n += snprintf(buf + n, len - n, "%s",
517 | protocol_violation_locations[cf->data[3]]);
518 | n += snprintf(buf + n, len - n, "}}");
519 |
520 | return n;
521 | }
522 |
523 | void snprintf_can_error_frame(char *buf, size_t len, struct canfd_frame *cf,
524 | char* sep)
525 | {
526 | canid_t class, mask;
527 | int i, n = 0, classes = 0;
528 | char *defsep = ",";
529 |
530 | if (!(cf->can_id & CAN_ERR_FLAG))
531 | return;
532 |
533 | class = cf->can_id & CAN_EFF_MASK;
534 | if (class > (1 << ARRAY_SIZE(error_classes))) {
535 | fprintf(stderr, "Error class %#x is invalid\n", class);
536 | return;
537 | }
538 |
539 | if (!sep)
540 | sep = defsep;
541 |
542 | for (i = 0; i < ARRAY_SIZE(error_classes); i++) {
543 | mask = 1 << i;
544 | if (class & mask) {
545 | if (classes)
546 | n += snprintf(buf + n, len - n, "%s", sep);
547 | n += snprintf(buf + n, len - n, "%s", error_classes[i]);
548 | if (mask == CAN_ERR_LOSTARB)
549 | n += snprintf_error_lostarb(buf + n, len - n,
550 | cf);
551 | if (mask == CAN_ERR_CRTL)
552 | n += snprintf_error_ctrl(buf + n, len - n, cf);
553 | if (mask == CAN_ERR_PROT)
554 | n += snprintf_error_prot(buf + n, len - n, cf);
555 | classes++;
556 | }
557 | }
558 |
559 | if (cf->data[6] || cf->data[7]) {
560 | n += snprintf(buf + n, len - n, "%s", sep);
561 | n += snprintf(buf + n, len - n, "error-counter-tx-rx{{%d}{%d}}",
562 | cf->data[6], cf->data[7]);
563 | }
564 | }
565 |
--------------------------------------------------------------------------------
/CAN/lib.h:
--------------------------------------------------------------------------------
1 | /*
2 | * lib.h - library include for command line tools
3 | *
4 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
5 | * All rights reserved.
6 | *
7 | * Redistribution and use in source and binary forms, with or without
8 | * modification, are permitted provided that the following conditions
9 | * are met:
10 | * 1. Redistributions of source code must retain the above copyright
11 | * notice, this list of conditions and the following disclaimer.
12 | * 2. Redistributions in binary form must reproduce the above copyright
13 | * notice, this list of conditions and the following disclaimer in the
14 | * documentation and/or other materials provided with the distribution.
15 | * 3. Neither the name of Volkswagen nor the names of its contributors
16 | * may be used to endorse or promote products derived from this software
17 | * without specific prior written permission.
18 | *
19 | * Alternatively, provided that this notice is retained in full, this
20 | * software may be distributed under the terms of the GNU General
21 | * Public License ("GPL") version 2, in which case the provisions of the
22 | * GPL apply INSTEAD OF those given above.
23 | *
24 | * The provided data structures and external interfaces from this code
25 | * are not restricted to be used by modules with a GPL compatible license.
26 | *
27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
38 | * DAMAGE.
39 | *
40 | * Send feedback to
41 | *
42 | */
43 |
44 | /* buffer sizes for CAN frame string representations */
45 |
46 | #define CL_ID (sizeof("12345678##1"))
47 | #define CL_DATA sizeof(".AA")
48 | #define CL_BINDATA sizeof(".10101010")
49 |
50 | /* CAN FD ASCII hex short representation with DATA_SEPERATORs */
51 | #define CL_CFSZ (2*CL_ID + 64*CL_DATA)
52 |
53 | /* CAN FD ASCII hex long representation with binary output */
54 | #define CL_LONGCFSZ (2*CL_ID + sizeof(" [255] ") + (64*CL_BINDATA))
55 |
56 | /* CAN DLC to real data length conversion helpers especially for CAN FD */
57 |
58 | /* get data length from can_dlc with sanitized can_dlc */
59 | unsigned char can_dlc2len(unsigned char can_dlc);
60 |
61 | /* map the sanitized data length to an appropriate data length code */
62 | unsigned char can_len2dlc(unsigned char len);
63 |
64 | unsigned char asc2nibble(char c);
65 | /*
66 | * Returns the decimal value of a given ASCII hex character.
67 | *
68 | * While 0..9, a..f, A..F are valid ASCII hex characters.
69 | * On invalid characters the value 16 is returned for error handling.
70 | */
71 |
72 | int hexstring2data(char *arg, unsigned char *data, int maxdlen);
73 | /*
74 | * Converts a given ASCII hex string to a (binary) byte string.
75 | *
76 | * A valid ASCII hex string consists of an even number of up to 16 chars.
77 | * Leading zeros '00' in the ASCII hex string are interpreted.
78 | *
79 | * Examples:
80 | *
81 | * "1234" => data[0] = 0x12, data[1] = 0x34
82 | * "001234" => data[0] = 0x00, data[1] = 0x12, data[2] = 0x34
83 | *
84 | * Return values:
85 | * 0 = success
86 | * 1 = error (in length or the given characters are no ASCII hex characters)
87 | *
88 | * Remark: The not written data[] elements are initialized with zero.
89 | *
90 | */
91 |
92 | int parse_canframe(char *cs, struct canfd_frame *cf);
93 | /*
94 | * Transfers a valid ASCII string decribing a CAN frame into struct canfd_frame.
95 | *
96 | * CAN 2.0 frames
97 | * - string layout #{R{len}|data}
98 | * - {data} has 0 to 8 hex-values that can (optionally) be separated by '.'
99 | * - {len} can take values from 0 to 8 and can be omitted if zero
100 | * - return value on successful parsing: CAN_MTU
101 | *
102 | * CAN FD frames
103 | * - string layout ##{data}
104 | * - a single ASCII Hex value (0 .. F) which defines canfd_frame.flags
105 | * - {data} has 0 to 64 hex-values that can (optionally) be separated by '.'
106 | * - return value on successful parsing: CANFD_MTU
107 | *
108 | * Return value on detected problems: 0
109 | *
110 | * can have 3 (standard frame format) or 8 (extended frame format)
111 | * hexadecimal chars
112 | *
113 | *
114 | * Examples:
115 | *
116 | * 123# -> standard CAN-Id = 0x123, len = 0
117 | * 12345678# -> extended CAN-Id = 0x12345678, len = 0
118 | * 123#R -> standard CAN-Id = 0x123, len = 0, RTR-frame
119 | * 123#R0 -> standard CAN-Id = 0x123, len = 0, RTR-frame
120 | * 123#R7 -> standard CAN-Id = 0x123, len = 7, RTR-frame
121 | * 7A1#r -> standard CAN-Id = 0x7A1, len = 0, RTR-frame
122 | *
123 | * 123#00 -> standard CAN-Id = 0x123, len = 1, data[0] = 0x00
124 | * 123#1122334455667788 -> standard CAN-Id = 0x123, len = 8
125 | * 123#11.22.33.44.55.66.77.88 -> standard CAN-Id = 0x123, len = 8
126 | * 123#11.2233.44556677.88 -> standard CAN-Id = 0x123, len = 8
127 | * 32345678#112233 -> error frame with CAN_ERR_FLAG (0x2000000) set
128 | *
129 | * 123##0112233 -> CAN FD frame standard CAN-Id = 0x123, flags = 0, len = 3
130 | * 123##1112233 -> CAN FD frame, flags = CANFD_BRS, len = 3
131 | * 123##2112233 -> CAN FD frame, flags = CANFD_ESI, len = 3
132 | * 123##3 -> CAN FD frame, flags = (CANFD_ESI | CANFD_BRS), len = 0
133 | * ^^
134 | * CAN FD extension to handle the canfd_frame.flags content
135 | *
136 | * Simple facts on this compact ASCII CAN frame representation:
137 | *
138 | * - 3 digits: standard frame format
139 | * - 8 digits: extendend frame format OR error frame
140 | * - 8 digits with CAN_ERR_FLAG (0x2000000) set: error frame
141 | * - an error frame is never a RTR frame
142 | * - CAN FD frames do not have a RTR bit
143 | */
144 |
145 | void fprint_canframe(FILE *stream , struct canfd_frame *cf, char *eol, int sep, int maxdlen);
146 | void sprint_canframe(char *buf , struct canfd_frame *cf, int sep, int maxdlen);
147 | /*
148 | * Creates a CAN frame hexadecimal output in compact format.
149 | * The CAN data[] is separated by '.' when sep != 0.
150 | *
151 | * The type of the CAN frame (CAN 2.0 / CAN FD) is specified by maxdlen:
152 | * maxdlen = 8 -> CAN2.0 frame
153 | * maxdlen = 64 -> CAN FD frame
154 | *
155 | * 12345678#112233 -> extended CAN-Id = 0x12345678, len = 3, data, sep = 0
156 | * 12345678#R -> extended CAN-Id = 0x12345678, RTR, len = 0
157 | * 12345678#R5 -> extended CAN-Id = 0x12345678, RTR, len = 5
158 | * 123#11.22.33.44.55.66.77.88 -> standard CAN-Id = 0x123, dlc = 8, sep = 1
159 | * 32345678#112233 -> error frame with CAN_ERR_FLAG (0x2000000) set
160 | * 123##0112233 -> CAN FD frame standard CAN-Id = 0x123, flags = 0, len = 3
161 | * 123##2112233 -> CAN FD frame, flags = CANFD_ESI, len = 3
162 | *
163 | * Examples:
164 | *
165 | * fprint_canframe(stdout, &frame, "\n", 0); // with eol to STDOUT
166 | * fprint_canframe(stderr, &frame, NULL, 0); // no eol to STDERR
167 | *
168 | */
169 |
170 | #define CANLIB_VIEW_ASCII 0x1
171 | #define CANLIB_VIEW_BINARY 0x2
172 | #define CANLIB_VIEW_SWAP 0x4
173 | #define CANLIB_VIEW_ERROR 0x8
174 | #define CANLIB_VIEW_INDENT_SFF 0x10
175 |
176 | #define SWAP_DELIMITER '`'
177 |
178 | void fprint_long_canframe(FILE *stream , struct canfd_frame *cf, char *eol, int view, int maxdlen);
179 | void sprint_long_canframe(char *buf , struct canfd_frame *cf, int view, int maxdlen);
180 | /*
181 | * Creates a CAN frame hexadecimal output in user readable format.
182 | *
183 | * The type of the CAN frame (CAN 2.0 / CAN FD) is specified by maxdlen:
184 | * maxdlen = 8 -> CAN2.0 frame
185 | * maxdlen = 64 -> CAN FD frame
186 | *
187 | * 12345678 [3] 11 22 33 -> extended CAN-Id = 0x12345678, dlc = 3, data
188 | * 12345678 [0] remote request -> extended CAN-Id = 0x12345678, RTR
189 | * 14B0DC51 [8] 4A 94 E8 2A EC 58 55 62 'J..*.XUb' -> (with ASCII output)
190 | * 20001111 [7] C6 23 7B 32 69 98 3C ERRORFRAME -> (CAN_ERR_FLAG set)
191 | * 12345678 [03] 11 22 33 -> CAN FD with extended CAN-Id = 0x12345678, dlc = 3
192 | *
193 | * 123 [3] 11 22 33 -> CANLIB_VIEW_INDENT_SFF == 0
194 | * 123 [3] 11 22 33 -> CANLIB_VIEW_INDENT_SFF == set
195 | *
196 | * Examples:
197 | *
198 | * // CAN FD frame with eol to STDOUT
199 | * fprint_long_canframe(stdout, &frame, "\n", 0, CANFD_MAX_DLEN);
200 | *
201 | * // CAN 2.0 frame without eol to STDERR
202 | * fprint_long_canframe(stderr, &frame, NULL, 0, CAN_MAX_DLEN);
203 | *
204 | */
205 |
206 | void snprintf_can_error_frame(char *buf, size_t len, struct canfd_frame *cf,
207 | char *sep);
208 | /*
209 | * Creates a CAN error frame output in user readable format.
210 | */
211 |
--------------------------------------------------------------------------------
/CAN/lib.o:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/CAN/lib.o
--------------------------------------------------------------------------------
/CAN/setup_vcan.sh:
--------------------------------------------------------------------------------
1 | sudo modprobe can
2 | sudo modprobe vcan
3 | sudo ip link add dev vcan0 type vcan
4 | sudo ip link set up vcan0
5 |
--------------------------------------------------------------------------------
/CarHacking_workshop_Barbhack_2024.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/CarHacking_workshop_Barbhack_2024.pdf
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Barbhack 2024 - Car Hacking Workshop
2 |
3 | This repository contains the various material for the 2024 edition of [Barbhack](https://www.barbhack.fr), the french southernmost hacking event.
4 |
5 | The purpose of this workshop is to teach some basics on Car Hacking :
6 |
7 | - Discovering the CAN bus
8 | - Getting some entry tips on how to reverse an ECU
9 | - Having fun with TPMS signals
10 |
11 | ## CAN bus hands-on
12 |
13 | To discover the CAN bus, this repo holds a fork of "Instrument Cluster Simulator for SocketCAN" aka **ICSim** : https://github.com/zombieCraig/ICSim
14 |
15 | It extends the basic ICSim with some specific features :
16 | * Some controls are not related to a CAN frame, to simulate sensors/actuators on ECU
17 | * A very basic diag tool is simulated to help understanding UDS protocol
18 | * A few OBD-II and UDS commands are supported
19 | * To learn with fun, a scoring system with few challenges has been implemented
20 |
21 | 
22 | 
23 |
24 | If you are not running on Linux or you don't want to compile the application, a virtual machine (1.1Gb) is available here : https://mega.nz/file/YbRylYBZ#KMW4zd3JmxnkbZCmlqBhkwpty-k6-tacLpci9MnZRms
25 | Login : barbhack - password : 12345678
26 |
27 | ## ECU reverse engineering tips
28 |
29 | The provided firmware is from a Tricore TC166 microcontroller
30 |
31 | The aim is to:
32 |
33 | - Find the UDS database using [binbloom](https://github.com/quarkslab/binbloom)
34 | - Identify UDS Negative Response Code in those functions
35 | - Locate the DataIdentifier database and understand its structure
36 |
37 | ## TPMS signals
38 |
39 | We provide an RF capture of a Tire Pressure Monitoring System, to analyse using [rtl_433](https://github.com/merbanan/rtl_433) or [Univeral Radio Hacker](https://github.com/jopohl/urh) its content, in order to spoof it.
--------------------------------------------------------------------------------
/TPMS/TPMS.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/TPMS/TPMS.png
--------------------------------------------------------------------------------
/TPMS/TPMS_433.920_1MSPSs.complex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/TPMS/TPMS_433.920_1MSPSs.complex
--------------------------------------------------------------------------------
/media/controls.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/media/controls.png
--------------------------------------------------------------------------------
/media/interface.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/media/interface.png
--------------------------------------------------------------------------------
/media/repository-open-graph-template.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/phil-eqtech/CH-Workshop/ea53fa4be9f27951a40ac6e4f1fecfe130c46019/media/repository-open-graph-template.png
--------------------------------------------------------------------------------