{"id":22,"date":"2008-11-17T22:37:38","date_gmt":"2008-11-17T11:37:38","guid":{"rendered":"http:\/\/www.madox.net\/blog\/?p=22"},"modified":"2008-11-18T00:42:40","modified_gmt":"2008-11-17T13:42:40","slug":"reverse-engineering-the-mazda-can-bus-part-1","status":"publish","type":"post","link":"http:\/\/www.madox.net\/blog\/2008\/11\/17\/reverse-engineering-the-mazda-can-bus-part-1\/","title":{"rendered":"Reverse Engineering the Mazda CAN Bus &#8211; Part 1"},"content":{"rendered":"<p><a href=\"http:\/\/en.wikipedia.org\/wiki\/Controller_Area_Network\">Controller-Area Network<\/a> or CAN Bus is one of many automotive communication buses for communications between various &#8216;car computers&#8217;.\u00a0 Information such as speed, fuel consumption, accelerator pedal position is all transmitted between the various controllers of a car akin to &#8216;fly-by-wire&#8217; control systems of aircraft but I guess &#8216;drive-by-wire&#8217; is more appropriate in this case.<\/p>\n<p>There are other rival bus technologies include LIN (Local Interconnect Network) which is supposed to be a lower cost alternative to CAN, but I&#8217;m not interested in that.\u00a0 Why?\u00a0 My car uses the CAN bus, not LIN, not Ethernet.\u00a0 So lets go about figuring what can be gleened from the communications whizzing around my car!<\/p>\n<figure id=\"attachment_28\" aria-describedby=\"caption-attachment-28\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.madox.net\/blog\/wp-content\/uploads\/2008\/11\/carpig2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-28\" title=\"carpig2\" src=\"http:\/\/www.madox.net\/blog\/wp-content\/uploads\/2008\/11\/carpig2-300x225.jpg\" alt=\"Aside from CAN bus, my car has a pig too.  This photo is from 2 years ago and the pig no longer has the tail or the tag on its ass...\" width=\"300\" height=\"225\" srcset=\"http:\/\/www.madox.net\/blog\/wp-content\/uploads\/2008\/11\/carpig2-300x225.jpg 300w, http:\/\/www.madox.net\/blog\/wp-content\/uploads\/2008\/11\/carpig2.jpg 1024w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-28\" class=\"wp-caption-text\">Aside from CAN bus, my car has a pig too (Long story).  This photo is from 2 years ago and the pig no longer has the weird thing hanging from its belly or the tag on its ass...<\/figcaption><\/figure>\n<p><!--more--><\/p>\n<h2>Background \/ Reason Why<\/h2>\n<p>In June 2006 I bought a &#8216;new&#8217; car, an Australian Mazda 3 Facelift Model.\u00a0 The car was a great drive, Mazda excelled in the build and features but one thing nagged at me &#8211; the speedometer.\u00a0 It was stylish I had to admit but the scaling was &#8216;off&#8217; to me.\u00a0 0 speed was vertically down and the scaling was&#8230; better not rant on but the thought was &#8216;maybe I can get another speedometer on&#8217;.\u00a0 A history of my &#8216;better speedometer&#8217; fantasies follow \ud83d\ude09<\/p>\n<figure id=\"attachment_24\" aria-describedby=\"caption-attachment-24\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.madox.net\/blog\/wp-content\/uploads\/2008\/11\/speed432.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-24\" title=\"speed432\" src=\"http:\/\/www.madox.net\/blog\/wp-content\/uploads\/2008\/11\/speed432-300x266.jpg\" alt=\"My old (and free!) Sony Ericson showing my speed on a MagLev\" width=\"300\" height=\"266\" srcset=\"http:\/\/www.madox.net\/blog\/wp-content\/uploads\/2008\/11\/speed432-300x266.jpg 300w, http:\/\/www.madox.net\/blog\/wp-content\/uploads\/2008\/11\/speed432.jpg 536w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-24\" class=\"wp-caption-text\">My old (and free!) Sony Ericson showing my speed on a MagLev<\/figcaption><\/figure>\n<figure id=\"attachment_25\" aria-describedby=\"caption-attachment-25\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.madox.net\/blog\/wp-content\/uploads\/2008\/11\/hudtest.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-25\" title=\"hudtest\" src=\"http:\/\/www.madox.net\/blog\/wp-content\/uploads\/2008\/11\/hudtest-300x225.jpg\" alt=\"Testing the feasibility of using the same crappy phone as a HUD on another car of mine on a rainy night...\" width=\"300\" height=\"225\" srcset=\"http:\/\/www.madox.net\/blog\/wp-content\/uploads\/2008\/11\/hudtest-300x225.jpg 300w, http:\/\/www.madox.net\/blog\/wp-content\/uploads\/2008\/11\/hudtest.jpg 500w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-25\" class=\"wp-caption-text\">Testing the feasibility of using the same crappy phone as a HUD on another car of mine on a rainy night...yup that&#39;s the image on my windscreen!<\/figcaption><\/figure>\n<p>A little bit of research later I found out the Mazda had two CAN buses: a &#8216;HS-CAN&#8217; (High Speed) network on which most of the essential systems (ECU, ABS) were connected, and a slower &#8216;MS-CAN&#8217; (Medium Speed?) network on which accessories such as the audio system were connected.\u00a0 These two networks are joined together by the instrument panel which also acts as the gateway to allow some messages to pass between the two networks.\u00a0 Both buses are conveniently available via a &#8216;standard&#8217; J1962 plug just below the steering wheel (Do a search on <a href=\"http:\/\/en.wikipedia.org\/wiki\/On_Board_Diagnostics\">OBD<\/a>) so I didn&#8217;t have to hack anything open.<\/p>\n<p>[Note : Most of the information below is from back in 2006, I only recently picked this project back up]<\/p>\n<p>[Note 2 : Please don&#8217;t any of what I say below if you&#8217;re not familiar with electronics\/cars or if you value your life&#8230; I hold no responsibility for anything that happens&#8230; I need to learn how to write a better disclaimer]<\/p>\n<h2>So what is on the network exactly?<\/h2>\n<p>Officially?\u00a0 &#8216;I dunno&#8217;.\u00a0 Mazda naturally doesn&#8217;t publish this information nor can it be found on the net easily, I hope Mazda doesn&#8217;t take offense at me writing this post actually&#8230; I loved the car and I&#8217;m doing this because its such a great car \ud83d\ude09 [\/grovel].<\/p>\n<p>Now if that information isn&#8217;t forthcoming from the great ol&#8217; google, I just had to try figure it out for myself!<\/p>\n<h2>How it was done<\/h2>\n<p>First step &#8211; Find the pin-outs of the J1962 connector, since its standard connector albeit with slightly different pin-outs per car type the answer is easily found on google.\u00a0 Go search it up yourself \ud83d\ude42<\/p>\n<p>Second step &#8211; Oscilloscope.\u00a0 A lovely portable fluke connected to the two CAN bus lines told me the baud rates of each of the two buses.\u00a0 500kbps and 125kbps respectively.<\/p>\n<p>Third step &#8211; Start sniffing, or at least buy the stuff to do so.\u00a0 I had wanted to build my own CAN interface board but laziness got the better of me and I bought the cheapest one online I could find from <a href=\"http:\/\/www.qprotos.com\/\">QProtos<\/a>.\u00a0 In hindsight it wasn&#8217;t the best choice but it wasn&#8217;t that bad either.\u00a0 Coupled with a J1962 cable from <a href=\"www.obd2cables.com\">OBD2Cables.com<\/a> (only remember them because i&#8217;m still receiving email offers hehe) I had everything I need to start.<\/p>\n<p>Fourth step &#8211; Really start sniffing.\u00a0 A precaution I took was to set the CAN-USB adaptor to &#8216;listen&#8217; mode only, I didn&#8217;t want to risk the brakes suddenly not working.<\/p>\n<p>A bunch of static tests to start things off nice and slow.\u00a0 The methodology was simple, start the CAN bus logging then carry out actions on the car at certain times &#8211; turn the blinker, step on the accelerator etc.\u00a0 All was left to be done was to review the logs to see which bits or bytes changed at those matching times.<\/p>\n<p>Fifth step &#8211; The fun bit!\u00a0 Dynamic testing!\u00a0 This time with the same setup as above but with my GPS phone logging simultaneously too.\u00a0 Oh what fun you can achieve here.<\/p>\n<figure id=\"attachment_23\" aria-describedby=\"caption-attachment-23\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/www.madox.net\/blog\/wp-content\/uploads\/2008\/11\/speed-gps-can.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-23\" title=\"speed-gps-can\" src=\"http:\/\/www.madox.net\/blog\/wp-content\/uploads\/2008\/11\/speed-gps-can-300x199.jpg\" alt=\"Speed from GPS vs Speed from CAN bus\" width=\"300\" height=\"199\" srcset=\"http:\/\/www.madox.net\/blog\/wp-content\/uploads\/2008\/11\/speed-gps-can-300x199.jpg 300w, http:\/\/www.madox.net\/blog\/wp-content\/uploads\/2008\/11\/speed-gps-can.jpg 708w\" sizes=\"auto, (max-width: 300px) 85vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-23\" class=\"wp-caption-text\">Speed from GPS vs Speed from CAN bus<\/figcaption><\/figure>\n<p>Anyone familiar with the Australian Design Rules and the laws?\u00a0 The displayed vehicle speed must not be reported lower than actual, so what most manufacturers do is artificially bump that number up.\u00a0 Hence you see the almost always consistently higher CAN speed compared to the GPS speed&#8230; Hey I haven&#8217;t even said how many &#8216;speed&#8217; signals are transmitted across the CAN bus&#8230;the &#8216;actual&#8217; (unmodified) one is there too.<\/p>\n<h2>The state of affairs<\/h2>\n<p>As of the end of 2006 (Yes two years ago) I had mapped out &#8230; (in no particular order&#8230;well actually in order of CAN bus ID&#8217;s)<\/p>\n<p>On the HS-CAN<\/p>\n<ul>\n<li>Brake Active<\/li>\n<li>RPM<\/li>\n<li>Vehicle Speed<\/li>\n<li>Accelerator Pedal position<\/li>\n<li>Brake Active (Again)<\/li>\n<li>True Vehicle Speed<\/li>\n<li>Gear Position &#8211; Park<\/li>\n<li>Gear Position -Reverse<\/li>\n<li>Gear Position -Drive<\/li>\n<li>1st, 2nd&#8230; etc Gears<\/li>\n<li>Gear Shift<\/li>\n<li>Manual\/Tiptronic Selection [Yes I drive an Auto]<\/li>\n<li>Gears again&#8230;<\/li>\n<li>Accelerator Pedal position again&#8230;in a different scaling&#8230;Mazda is strange<\/li>\n<li>Left Front Wheel Speed<\/li>\n<li>Right Front Wheel Speed<\/li>\n<li>Left Rear Wheel Speed<\/li>\n<li>Right Rear Wheel Speed<\/li>\n<li>Steering Wheel Angle (I&#8217;m going to have fun with this one!)<\/li>\n<li>Odometer<\/li>\n<\/ul>\n<p>On the MS-CAN<\/p>\n<ul>\n<li>RPM (Retransmitted)<\/li>\n<li>Vehicle Speed (Retransmitted)<\/li>\n<li>Head Unit LCD Display (Oh this will be fun too)<\/li>\n<li>TRIP COMPUTER! Average Speed, Fuel Consumption, Average Fuel Consumption, Distance Remaining<\/li>\n<\/ul>\n<p>Oh I so forgot to rant.\u00a0 Trip Computer, very nice little pieces of information for driving a car.\u00a0 Official Mazda Australia line?\u00a0 Oh our Mazda 3&#8217;s don&#8217;t have this.\u00a0 All overseas models have it.\u00a0 All information is already on the car.\u00a0 The car even has a head unit with all the trip computer LCD displays present (you can see it if you tilt your head).\u00a0 Infact there&#8217;s a little trick you can do with every Mazda 3 model just prior to mine that you can hold down certain keys on the head unit before starting the car that activates it&#8230; but nooooooooooooo its disabled on mine for what reason I don&#8217;t know&#8230; erm&#8230; rant over.\u00a0 Guess I have to do a better speedometer and trip meter too.<\/p>\n<p>If anyone was expecting to see the results, you have to wait for Part 2 (or 3)&#8230;does anyone actually want to see?\u00a0\u00a0 Or got any questions? mmmm<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Controller-Area Network or CAN Bus is one of many automotive communication buses for communications between various &#8216;car computers&#8217;.\u00a0 Information such as speed, fuel consumption, accelerator pedal position is all transmitted between the various controllers of a car akin to &#8216;fly-by-wire&#8217; control systems of aircraft but I guess &#8216;drive-by-wire&#8217; is more appropriate in this case. There &hellip; <a href=\"http:\/\/www.madox.net\/blog\/2008\/11\/17\/reverse-engineering-the-mazda-can-bus-part-1\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Reverse Engineering the Mazda CAN Bus &#8211; Part 1&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[12,11,9],"class_list":["post-22","post","type-post","status-publish","format-standard","hentry","category-engineering","tag-can-bus","tag-mazda","tag-perverted-engineering"],"_links":{"self":[{"href":"http:\/\/www.madox.net\/blog\/wp-json\/wp\/v2\/posts\/22","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.madox.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.madox.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.madox.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.madox.net\/blog\/wp-json\/wp\/v2\/comments?post=22"}],"version-history":[{"count":5,"href":"http:\/\/www.madox.net\/blog\/wp-json\/wp\/v2\/posts\/22\/revisions"}],"predecessor-version":[{"id":30,"href":"http:\/\/www.madox.net\/blog\/wp-json\/wp\/v2\/posts\/22\/revisions\/30"}],"wp:attachment":[{"href":"http:\/\/www.madox.net\/blog\/wp-json\/wp\/v2\/media?parent=22"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.madox.net\/blog\/wp-json\/wp\/v2\/categories?post=22"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.madox.net\/blog\/wp-json\/wp\/v2\/tags?post=22"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}