First Steps
In the previous article, I described how trying to solve audio issues with Carlinkit gradually led me to the idea of building my own CarPlay implementation.
By that point, I already had an MFi chip found inside the Carlinkit U2W Mini and connected to a Raspberry Pi 3B+ via I²C. Scanning the bus confirmed that the chip responded at its address.
But detecting a device on the bus is one thing. Getting it to perform the necessary authentication operations is something entirely different.
I had a very specific goal: establish a connection with the iPhone, complete the required authentication steps, and obtain a decrypted H.264 video stream.
Receiving video was the main objective of my first experiments with CaRaBack.
To achieve this, I needed to understand several protocols, each responsible for a different part of communication with the iPhone.
Studying the LIVI Source Code
The LIVI source code became my main source of technical information.
In the previous article, I explained how I unexpectedly discovered a Native CarPlay implementation in this project. Now it was time to understand how it worked.
I gradually studied the necessary components, examined message exchange sequences, authentication commands, and connection establishment mechanisms.
However, my goal was not simply to run LIVI on the Raspberry Pi.
I wanted to create my own C++ application where I could independently control the connection process, protocol handling, and subsequent data transmission.
Therefore, CaRaBack development progressed alongside my study of LIVI. Whenever I found the mechanisms I needed in its source code, I gradually implemented the corresponding components in my own project.
The first of these was a class for communicating with the MFi chip.
Communicating with MFi over I²C
The physical connection to the chip was already in place. Now I needed to learn how to communicate with it properly.
The MFi chip performs cryptographic operations required for device authentication. Its private keys remain inside the chip and are not exposed to the application.
By studying the LIVI implementation, I figured out the necessary communication commands and started writing my own C++ class to interact with the chip over I²C.
The main task was to send requests and receive responses that could later be used when establishing a secure connection with the iPhone.
Gradually, I managed to get communication working.
The Raspberry Pi could now do more than simply detect the chip on the bus. It could interact with it through software.
This was the first important step. The hardware authentication component no longer depended on Carlinkit's software.
However, the MFi chip alone was not enough. I still needed to establish a connection with the iPhone itself.
Bluetooth and iAP2
The next part of the work involved communicating with the iPhone over Bluetooth.
For this, I used the standard Linux Bluetooth stack — BlueZ.
Writing my own low-level Bluetooth implementation from scratch made little sense. BlueZ already provided the necessary mechanisms for working with the Bluetooth adapter, discovering devices, and establishing connections.
However, establishing a Bluetooth connection did not automatically mean that the iPhone would recognize CaRaBack as a CarPlay device.
That required support for iAP2, the protocol Apple devices use to communicate with compatible accessories.
Once again, the LIVI source code proved useful.
By studying the sequence of exchanged messages, I gradually worked out what data needed to be sent to the iPhone and what responses to expect.
The task turned out to be considerably more complicated than an ordinary Bluetooth connection.
Simply discovering the phone and establishing a connection was not enough. I needed to organize the subsequent data exchange correctly so that the iPhone would recognize the device and proceed to the next connection stages.
I constantly had to compare the behavior of my own implementation with what I had learned from the LIVI source code.
Gradually, the individual components started coming together into a single system.
But the most difficult part was still ahead — AirPlay.
Moving to AirPlay
My main goal was not simply to make the iPhone discover a new device.
I wanted to receive an actual CarPlay video stream from it.
This was where the work on AirPlay began.
I needed to implement network communication, the required request sequence, and the mechanism for establishing a secure session.
Unlike ordinary video streaming over a network, I could not simply open a connection and start receiving ready-to-decode H.264 frames.
First, the necessary connection negotiation and authentication steps had to be completed.
In addition, the transmitted data was encrypted.
Therefore, successfully receiving network packets did not mean that their contents could already be used for playback.
I needed to understand how the secure session was established and how the received data should be processed.
Once again, LIVI remained my main source of information.
I studied its implementation of the relevant mechanisms and gradually incorporated the necessary logic into CaRaBack, adapting it to my own architecture.
Progress was not as fast as I would have liked.
Some stages were relatively straightforward, while others required lengthy investigation of message sequences and the reasons why a connection would not advance to the next state.
But gradually, I achieved the main objective: the iPhone started establishing a connection with my own CarPlay implementation.
The First iPhone Connection
Once I managed to complete the necessary connection and authentication steps, CaRaBack started receiving data from the iPhone.
This was an important moment.
Until then, all my experiments had involved individual components: the MFi chip, Bluetooth, iAP2, and network protocols.
Now, for the first time, they started working together.
However, receiving data did not mean the problem was solved.
The CarPlay video stream was transmitted in encrypted form. To obtain H.264 data suitable for decoding, I needed to process the protected stream correctly.
This turned out to be one of the most difficult parts of the entire development process.
I continued studying the relevant mechanisms in LIVI, checking the message exchange sequence, and investigating how to process the incoming data.
Gradually, I managed to achieve what I had been working toward from the beginning.
CaRaBack started receiving a decrypted H.264 video stream directly from the iPhone.
Without using Carlinkit as an intermediary.
The First H.264 Video Stream
Once the first decrypted data became available, I needed to verify that it was actually a valid video stream.
At that point, I did not yet have an application ready to play it.
And developing a video player before verifying the data itself did not make much sense.
So I decided to take a simpler approach.
I wrote the received H.264 stream directly to a file.
Then I transferred that file to a Windows computer and tried playing it.
This was the simplest way to verify the result without having to work on a graphical interface, video decoding, and real-time display at the same time.
And the test was successful.
The recorded file really did contain a CarPlay video stream received directly from the iPhone.
This meant that I had not only established a connection and completed the necessary authentication steps, but also obtained valid decrypted video data.
For me, this was the most important result of the early stages of CaRaBack development.
The First Major Achievement
At this stage, CaRaBack could not yet be considered a complete replacement for Carlinkit.
I did not have a finished graphical interface, audio playback, or the ability to control CarPlay.
But I had already managed to accomplish the most difficult part.
The Raspberry Pi 3B+, with the MFi chip connected, was able to establish a connection with the iPhone independently and receive a decrypted H.264 video stream.
Something that had recently seemed like a complicated task full of unknowns was now working in practice.
Of course, achieving this result would have been considerably more difficult without studying the LIVI source code. That project helped me understand the necessary mechanisms and significantly accelerated the development of my own implementation.
But an equally interesting question remained.
I had the video stream. But what should I do with it now?
That is what I will cover in the next article.