Skip to content

Commit

Permalink
Merge pull request #1 from yoziru/fix-unsigned-payload-add-info-request
Browse files Browse the repository at this point in the history
fix unsigned payload add info request
  • Loading branch information
yoziru authored Jul 17, 2024
2 parents 6655786 + 9868d04 commit 0157de3
Show file tree
Hide file tree
Showing 8 changed files with 143 additions and 35 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,3 @@ jobs:

- name: Configure and Build Project
uses: threeal/cmake-action@main

# run simple example as a test
- name: Build and run example
run: |
cd examples/simple
cmake --build .
./simple
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.22)

include(FetchContent)
project(TeslaBLE
VERSION 2.0.1
VERSION 2.0.2
DESCRIPTION "CPP Tesla BLE Library"
LANGUAGES CXX C
)
Expand Down
74 changes: 58 additions & 16 deletions examples/simple/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ int main()
printf("Failed create private key\n");
}

unsigned char private_key_buffer[sizeof MOCK_PRIVATE_KEY];
unsigned char private_key_buffer[sizeof MOCK_PRIVATE_KEY + 1];
size_t private_key_length;
client.getPrivateKey(private_key_buffer, sizeof(private_key_buffer),
&private_key_length);
status = client.getPrivateKey(private_key_buffer, sizeof(private_key_buffer),
&private_key_length);
if (status != 0)
{
printf("Failed to get private key\n");
}
printf("Private key length: %d\n", private_key_length);
printf("Private key: ");
for (int i = 0; i < private_key_length; i++)
Expand Down Expand Up @@ -63,15 +67,25 @@ int main()
printf("\n");
// mock received_message from VSSEC
// 321212102fddc145caccca430566370df149855d3a0208027a5e0801124104c7a1f47138486aa4729971494878d33b1a24e39571f748a6e16c5955b3d877d3a6aaa0e955166474af5d32c410f439a2234137ad1bb085fd4e8813c958f11d971a104c463f9cc0d3d26906e982ed224adde625854a000030066a2432220a205a0d3c7cb02c04d912a3588bc2a6fd8c00f244091bdd9dfe46fcdc4706415b269203103ccce3d51a6f3c2aeea8913644a70584
pb_byte_t received_bytes_vcsec[client.MAX_BLE_MESSAGE_SIZE] = {0x32, 0x12, 0x12, 0x10, 0x2f, 0xdd, 0xc1, 0x45, 0xca, 0xcc, 0xca, 0x43, 0x05, 0x66, 0x37, 0x0d, 0xf1, 0x49, 0x85, 0x5d, 0x3a, 0x02, 0x08, 0x02, 0x7a, 0x5e, 0x08, 0x01, 0x12, 0x41, 0x04, 0xc7, 0xa1, 0xf4, 0x71, 0x38, 0x48, 0x6a, 0xa4, 0x72, 0x99, 0x71, 0x49, 0x48, 0x78, 0xd3, 0x3b, 0x1a, 0x24, 0xe3, 0x95, 0x71, 0xf7, 0x48, 0xa6, 0xe1, 0x6c, 0x59, 0x55, 0xb3, 0xd8, 0x77, 0xd3, 0xa6, 0xaa, 0xa0, 0xe9, 0x55, 0x16, 0x64, 0x74, 0xaf, 0x5d, 0x32, 0xc4, 0x10, 0xf4, 0x39, 0xa2, 0x23, 0x41, 0x37, 0xad, 0x1b, 0xb0, 0x85, 0xfd, 0x4e, 0x88, 0x13, 0xc9, 0x58, 0xf1, 0x1d, 0x97, 0x1a, 0x10, 0x4c, 0x46, 0x3f, 0x9c, 0xc0, 0xd3, 0xd2, 0x69, 0x06, 0xe9, 0x82, 0xed, 0x22, 0x4a, 0xdd, 0xe6, 0x25, 0x85, 0x4a, 0x00, 0x00, 0x30, 0x06, 0x6a, 0x24, 0x32, 0x22, 0x0a, 0x20, 0x5a, 0x0d, 0x3c, 0x7c, 0xb0, 0x2c, 0x04, 0xd9, 0x12, 0xa3, 0x58, 0x8b, 0xc2, 0xa6, 0xfd, 0x8c, 0x00, 0xf2, 0x44, 0x09, 0x1b, 0xdd, 0x9d, 0xfe, 0x46, 0xfc, 0xdc, 0x47, 0x06, 0x41, 0x5b, 0x26, 0x92, 0x03, 0x10, 0x3c, 0xcc, 0xe3, 0xd5, 0x1a, 0x6f, 0x3c, 0x2a, 0xee, 0xa8, 0x91, 0x36, 0x44, 0xa7, 0x05, 0x84};
pb_byte_t received_bytes_vcsec[177] = {0x32, 0x12, 0x12, 0x10, 0x2f, 0xdd, 0xc1, 0x45, 0xca, 0xcc, 0xca, 0x43, 0x05, 0x66, 0x37, 0x0d, 0xf1, 0x49, 0x85, 0x5d, 0x3a, 0x02, 0x08, 0x02, 0x7a, 0x5e, 0x08, 0x01, 0x12, 0x41, 0x04, 0xc7, 0xa1, 0xf4, 0x71, 0x38, 0x48, 0x6a, 0xa4, 0x72, 0x99, 0x71, 0x49, 0x48, 0x78, 0xd3, 0x3b, 0x1a, 0x24, 0xe3, 0x95, 0x71, 0xf7, 0x48, 0xa6, 0xe1, 0x6c, 0x59, 0x55, 0xb3, 0xd8, 0x77, 0xd3, 0xa6, 0xaa, 0xa0, 0xe9, 0x55, 0x16, 0x64, 0x74, 0xaf, 0x5d, 0x32, 0xc4, 0x10, 0xf4, 0x39, 0xa2, 0x23, 0x41, 0x37, 0xad, 0x1b, 0xb0, 0x85, 0xfd, 0x4e, 0x88, 0x13, 0xc9, 0x58, 0xf1, 0x1d, 0x97, 0x1a, 0x10, 0x4c, 0x46, 0x3f, 0x9c, 0xc0, 0xd3, 0xd2, 0x69, 0x06, 0xe9, 0x82, 0xed, 0x22, 0x4a, 0xdd, 0xe6, 0x25, 0x85, 0x4a, 0x00, 0x00, 0x30, 0x06, 0x6a, 0x24, 0x32, 0x22, 0x0a, 0x20, 0x5a, 0x0d, 0x3c, 0x7c, 0xb0, 0x2c, 0x04, 0xd9, 0x12, 0xa3, 0x58, 0x8b, 0xc2, 0xa6, 0xfd, 0x8c, 0x00, 0xf2, 0x44, 0x09, 0x1b, 0xdd, 0x9d, 0xfe, 0x46, 0xfc, 0xdc, 0x47, 0x06, 0x41, 0x5b, 0x26, 0x92, 0x03, 0x10, 0x3c, 0xcc, 0xe3, 0xd5, 0x1a, 0x6f, 0x3c, 0x2a, 0xee, 0xa8, 0x91, 0x36, 0x44, 0xa7, 0x05, 0x84};

// parse received universal message
UniversalMessage_RoutableMessage received_message_vcsec = UniversalMessage_RoutableMessage_init_default;
client.parseUniversalMessage(received_bytes_vcsec, sizeof(received_bytes_vcsec), &received_message_vcsec);
return_code = client.parseUniversalMessage(received_bytes_vcsec, sizeof(received_bytes_vcsec), &received_message_vcsec);
if (return_code != 0)
{
printf("Failed to parse received message VSSEC\n");
return -1;
}
log_routable_message(&received_message_vcsec);

Signatures_SessionInfo session_info_vcsec = Signatures_SessionInfo_init_default;
client.parsePayloadSessionInfo(&received_message_vcsec.payload.session_info, &session_info_vcsec);
return_code = client.parsePayloadSessionInfo(&received_message_vcsec.payload.session_info, &session_info_vcsec);
if (return_code != 0)
{
printf("Failed to parse session info VSSEC\n");
return -1;
}
log_session_info(&session_info_vcsec);

uint32_t generated_at_vcsec = std::time(nullptr);
Expand All @@ -82,8 +96,8 @@ int main()
client.session_vcsec_.setTimeZero(&time_zero_vcsec);
client.session_vcsec_.setIsAuthenticated(true);
printf("Session authenticated: %s\n", client.session_vcsec_.isAuthenticated ? "true" : "false");
int result_code_vcsec = client.loadTeslaKey(false, session_info_vcsec.publicKey.bytes, session_info_vcsec.publicKey.size);
if (result_code_vcsec != 0)
return_code = client.loadTeslaKey(false, session_info_vcsec.publicKey.bytes, session_info_vcsec.publicKey.size);
if (return_code != 0)
{
printf("Failed load vssec tesla key\n");
return 1;
Expand All @@ -96,7 +110,7 @@ int main()
}
printf("\n");

printf("Parsed session info response\n");
printf("Parsed VCSEC session info response\n");
printf("Received new counter from the car: %" PRIu32, client.session_vcsec_.counter_);
printf("\n");
printf("Received new expires at from the car: %" PRIu32, client.session_vcsec_.expires_at_);
Expand All @@ -109,11 +123,11 @@ int main()
printf("\n");

// build wake command
printf("Building wake command\n");
unsigned char action_message_buffer[client.MAX_BLE_MESSAGE_SIZE];
size_t action_message_buffer_length = 0;
int return_code_action = client.buildVCSECActionMessage(VCSEC_RKEAction_E_RKE_ACTION_WAKE_VEHICLE, action_message_buffer, &action_message_buffer_length);

if (return_code_action != 0)
return_code = client.buildVCSECActionMessage(VCSEC_RKEAction_E_RKE_ACTION_WAKE_VEHICLE, action_message_buffer, &action_message_buffer_length);
if (return_code != 0)
{
printf("Failed to build action message \n");
return -1;
Expand All @@ -126,17 +140,45 @@ int main()
}
printf("\n");

// build information request status
printf("Building information request status\n");
pb_byte_t info_request_status_buffer[client.MAX_BLE_MESSAGE_SIZE];
size_t info_request_status_length = 0;
return_code = client.buildVCSECInformationRequestMessage(VCSEC_InformationRequestType_INFORMATION_REQUEST_TYPE_GET_STATUS, info_request_status_buffer, &info_request_status_length);
if (return_code != 0)
{
printf("Failed to build action message \n");
return -1;
}
printf("VCSEC InfoRequest status length: %d\n", info_request_status_length);
printf("VCSEC InfoRequest status hex: ");
for (int i = 0; i < info_request_status_length; i++)
{
printf("%02X", info_request_status_buffer[i]);
}
printf("\n");

// mock received message from INFOTAINMENT
// 321212108f3d244b50b07a9842cac108c928b5e73a0208037a5e0801124104c7a1f47138486aa4729971494878d33b1a24e39571f748a6e16c5955b3d877d3a6aaa0e955166474af5d32c410f439a2234137ad1bb085fd4e8813c958f11d971a104c463f9cc0d3d26906e982ed224adde6255f0a000030076a2432220a208e8dcd164ef361fd123c46c2b2bdfd1fc93056f4ef32c9311a275db908d4d23f9203100a404ec0fc9aa863aec3e50196fbf30b
pb_byte_t received_bytes_infotainment[client.MAX_BLE_MESSAGE_SIZE] = {0x32, 0x12, 0x12, 0x10, 0x8f, 0x3d, 0x24, 0x4b, 0x50, 0xb0, 0x7a, 0x98, 0x42, 0xca, 0xc1, 0x08, 0xc9, 0x28, 0xb5, 0xe7, 0x3a, 0x02, 0x08, 0x03, 0x7a, 0x5e, 0x08, 0x01, 0x12, 0x41, 0x04, 0xc7, 0xa1, 0xf4, 0x71, 0x38, 0x48, 0x6a, 0xa4, 0x72, 0x99, 0x71, 0x49, 0x48, 0x78, 0xd3, 0x3b, 0x1a, 0x24, 0xe3, 0x95, 0x71, 0xf7, 0x48, 0xa6, 0xe1, 0x6c, 0x59, 0x55, 0xb3, 0xd8, 0x77, 0xd3, 0xa6, 0xaa, 0xa0, 0xe9, 0x55, 0x16, 0x64, 0x74, 0xaf, 0x5d, 0x32, 0xc4, 0x10, 0xf4, 0x39, 0xa2, 0x23, 0x41, 0x37, 0xad, 0x1b, 0xb0, 0x85, 0xfd, 0x4e, 0x88, 0x13, 0xc9, 0x58, 0xf1, 0x1d, 0x97, 0x1a, 0x10, 0x4c, 0x46, 0x3f, 0x9c, 0xc0, 0xd3, 0xd2, 0x69, 0x06, 0xe9, 0x82, 0xed, 0x22, 0x4a, 0xdd, 0xe6, 0x25, 0x5f, 0x0a, 0x00, 0x00, 0x30, 0x07, 0x6a, 0x24, 0x32, 0x22, 0x0a, 0x20, 0x8e, 0x8d, 0xcd, 0x16, 0x4e, 0xf3, 0x61, 0xfd, 0x12, 0x3c, 0x46, 0xc2, 0xb2, 0xbd, 0xfd, 0x1f, 0xc9, 0x30, 0x56, 0xf4, 0xef, 0x32, 0xc9, 0x31, 0x1a, 0x27, 0x5d, 0xb9, 0x08, 0xd4, 0xd2, 0x3f, 0x92, 0x03, 0x10, 0x0a, 0x40, 0x4e, 0xc0, 0xfc, 0x9a, 0xa8, 0x63, 0xae, 0xc3, 0xe5, 0x01, 0x96, 0xfb, 0xf3, 0x0b};
pb_byte_t received_bytes_infotainment[177] = {0x32, 0x12, 0x12, 0x10, 0x8f, 0x3d, 0x24, 0x4b, 0x50, 0xb0, 0x7a, 0x98, 0x42, 0xca, 0xc1, 0x08, 0xc9, 0x28, 0xb5, 0xe7, 0x3a, 0x02, 0x08, 0x03, 0x7a, 0x5e, 0x08, 0x01, 0x12, 0x41, 0x04, 0xc7, 0xa1, 0xf4, 0x71, 0x38, 0x48, 0x6a, 0xa4, 0x72, 0x99, 0x71, 0x49, 0x48, 0x78, 0xd3, 0x3b, 0x1a, 0x24, 0xe3, 0x95, 0x71, 0xf7, 0x48, 0xa6, 0xe1, 0x6c, 0x59, 0x55, 0xb3, 0xd8, 0x77, 0xd3, 0xa6, 0xaa, 0xa0, 0xe9, 0x55, 0x16, 0x64, 0x74, 0xaf, 0x5d, 0x32, 0xc4, 0x10, 0xf4, 0x39, 0xa2, 0x23, 0x41, 0x37, 0xad, 0x1b, 0xb0, 0x85, 0xfd, 0x4e, 0x88, 0x13, 0xc9, 0x58, 0xf1, 0x1d, 0x97, 0x1a, 0x10, 0x4c, 0x46, 0x3f, 0x9c, 0xc0, 0xd3, 0xd2, 0x69, 0x06, 0xe9, 0x82, 0xed, 0x22, 0x4a, 0xdd, 0xe6, 0x25, 0x5f, 0x0a, 0x00, 0x00, 0x30, 0x07, 0x6a, 0x24, 0x32, 0x22, 0x0a, 0x20, 0x8e, 0x8d, 0xcd, 0x16, 0x4e, 0xf3, 0x61, 0xfd, 0x12, 0x3c, 0x46, 0xc2, 0xb2, 0xbd, 0xfd, 0x1f, 0xc9, 0x30, 0x56, 0xf4, 0xef, 0x32, 0xc9, 0x31, 0x1a, 0x27, 0x5d, 0xb9, 0x08, 0xd4, 0xd2, 0x3f, 0x92, 0x03, 0x10, 0x0a, 0x40, 0x4e, 0xc0, 0xfc, 0x9a, 0xa8, 0x63, 0xae, 0xc3, 0xe5, 0x01, 0x96, 0xfb, 0xf3, 0x0b};

// parse received universal message
UniversalMessage_RoutableMessage received_message = UniversalMessage_RoutableMessage_init_default;
client.parseUniversalMessage(received_bytes_infotainment, sizeof(received_bytes_infotainment), &received_message);
return_code = client.parseUniversalMessage(received_bytes_infotainment, sizeof(received_bytes_infotainment), &received_message);
if (return_code != 0)
{
printf("Failed to parse received message INFOTAINMENT\n");
return -1;
}
log_routable_message(&received_message);

Signatures_SessionInfo session_info = Signatures_SessionInfo_init_default;
client.parsePayloadSessionInfo(&received_message.payload.session_info, &session_info);
return_code = client.parsePayloadSessionInfo(&received_message.payload.session_info, &session_info);
if (return_code != 0)
{
printf("Failed to parse session info INFOTAINMENT\n");
return -1;
}
log_session_info(&session_info);

uint32_t generated_at = std::time(nullptr);
Expand All @@ -149,7 +191,7 @@ int main()
printf("Session authenticated: %s\n", client.session_infotainment_.isAuthenticated ? "true" : "false");
client.loadTeslaKey(true, session_info.publicKey.bytes, session_info.publicKey.size);

printf("Parsed session info response\n");
printf("Parsed INFOTAINMENT session info response\n");
printf("Received new counter from the car: %" PRIu32, client.session_infotainment_.counter_);
printf("\n");
printf("Received new counter from the car (hex): ");
Expand Down
4 changes: 4 additions & 0 deletions include/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ namespace TeslaBLE

int buildVCSECActionMessage(const VCSEC_RKEAction_E action,
pb_byte_t *output_buffer, size_t *output_length);
int buildVCSECInformationRequestMessage(VCSEC_InformationRequestType request_type,
pb_byte_t *output_buffer,
size_t *output_length,
uint32_t key_slot = 0);

int buildCarServerActionMessage(const CarServer_VehicleAction *vehicle_action,
pb_byte_t *output_buffer,
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "TeslaBLE",
"version": "2.0.1",
"version": "2.0.2",
"description": "This CPP library facilitates direct communication with Tesla vehicles via the BLE API. It offers fundamental features such as unlocking/locking, opening the trunk, and more. The library's capabilities are contingent on the range of actions implemented by Tesla, which is the only limitation at present.",
"keywords": "tesla, ble",
"repository": {
Expand Down
3 changes: 2 additions & 1 deletion proto/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
generate_raw:
nanopb_generator *.proto --output-dir=out/
mkdir -p out
nanopb_generator *.proto --output-dir=out/

fix:
sed '/google\/protobuf\/timestamp/d' out/car_server.pb.h > out/car_server.pb.h.tmp
Expand Down
81 changes: 72 additions & 9 deletions src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,12 @@ namespace TeslaBLE
printf("Encoding whitelist message\n");
pb_byte_t payload_buffer[80];
size_t payload_length;
pb_encode_fields(payload_buffer, &payload_length, VCSEC_UnsignedMessage_fields, &payload);
int return_code = pb_encode_fields(payload_buffer, &payload_length, VCSEC_UnsignedMessage_fields, &payload);
if (return_code != 0)
{
printf("Failed to encode whitelist message\n");
return 1;
}

printf("Encoded whitelist message :");
for (int i = 0; i < payload_length; i++)
Expand All @@ -563,7 +568,12 @@ namespace TeslaBLE
printf("Encoding VCSEC to VCSEC message\n");
pb_byte_t vcsec_encode_buffer[86];
size_t vcsec_encode_buffer_size;
pb_encode_fields(vcsec_encode_buffer, &vcsec_encode_buffer_size, VCSEC_ToVCSECMessage_fields, &vcsec_message);
return_code = pb_encode_fields(vcsec_encode_buffer, &vcsec_encode_buffer_size, VCSEC_ToVCSECMessage_fields, &vcsec_message);
if (return_code != 0)
{
printf("Failed to encode VCSEC to VCSEC message\n");
return 1;
}
printf("Encoded VCSEC to VCSEC message length: %d\n", vcsec_encode_buffer_size);
printf("Encoded VCSEC to VCSEC message :");
for (int i = 0; i < vcsec_encode_buffer_size; i++)
Expand Down Expand Up @@ -891,7 +901,12 @@ namespace TeslaBLE
}
memcpy(universal_message.uuid, uuid, sizeof(uuid));

pb_encode_fields(output_buffer, output_length, UniversalMessage_RoutableMessage_fields, &universal_message);
int return_code = pb_encode_fields(output_buffer, output_length, UniversalMessage_RoutableMessage_fields, &universal_message);
if (return_code != 0)
{
printf("\033[1;31mFailed to encode universal message\033[0m\n");
return 1;
}
return 0;
}

Expand Down Expand Up @@ -939,7 +954,12 @@ namespace TeslaBLE

size_t universal_encode_buffer_size = this->MAX_BLE_MESSAGE_SIZE - 2;
pb_byte_t universal_encode_buffer[universal_encode_buffer_size];
pb_encode_fields(universal_encode_buffer, &universal_encode_buffer_size, UniversalMessage_RoutableMessage_fields, &universal_message);
int return_code = pb_encode_fields(universal_encode_buffer, &universal_encode_buffer_size, UniversalMessage_RoutableMessage_fields, &universal_message);
if (return_code != 0)
{
printf("\033[1;31mFailed to encode universal message\033[0m\n");
return 1;
}
this->prependLength(universal_encode_buffer, universal_encode_buffer_size,
output_buffer, output_length);

Expand All @@ -959,15 +979,20 @@ namespace TeslaBLE
size_t *output_length,
bool encryptPayload)
{
pb_byte_t payload_buffer;
size_t payload_length = 0;
pb_byte_t payload_buffer[100];
size_t payload_length;
printf("message: %p\n", message);
printf("message.which_sub_message: %d\n", message->which_sub_message);
pb_encode_fields(&payload_buffer, &payload_length, VCSEC_UnsignedMessage_fields, &message);
int return_code = pb_encode_fields(payload_buffer, &payload_length, VCSEC_UnsignedMessage_fields, message);
if (return_code != 0)
{
printf("\033[1;31mFailed to encode unsigned message\033[0m\n");
return 1;
}

// build universal message
return this->buildUniversalMessageWithPayload(
&payload_buffer, payload_length, UniversalMessage_Domain_DOMAIN_VEHICLE_SECURITY,
payload_buffer, payload_length, UniversalMessage_Domain_DOMAIN_VEHICLE_SECURITY,
output_buffer, output_length, encryptPayload);
}

Expand Down Expand Up @@ -1000,7 +1025,12 @@ namespace TeslaBLE
{
pb_byte_t payload_buffer[100];
size_t payload_length = 0;
pb_encode_fields(payload_buffer, &payload_length, CarServer_Action_fields, action);
int return_code = pb_encode_fields(payload_buffer, &payload_length, CarServer_Action_fields, action);
if (return_code != 0)
{
printf("\033[1;31mFailed to encode car action message\033[0m\n");
return 1;
}
printf("payload length: %zu\n", payload_length);
printf("payload: ");
for (int i = 0; i < payload_length; i++)
Expand Down Expand Up @@ -1182,6 +1212,39 @@ namespace TeslaBLE
return 0;
}

int Client::buildVCSECInformationRequestMessage(VCSEC_InformationRequestType request_type,
pb_byte_t *output_buffer,
size_t *output_length,
uint32_t key_slot)
{
VCSEC_InformationRequest information_request = VCSEC_InformationRequest_init_zero;
information_request.informationRequestType = request_type;

if (key_slot != 0xFFFFFFFF)
{
printf("Adding key slot info");
information_request.which_key = VCSEC_InformationRequest_slot_tag;
information_request.key.slot = key_slot;
}

VCSEC_UnsignedMessage unsigned_message = VCSEC_UnsignedMessage_init_default;
unsigned_message.which_sub_message = VCSEC_UnsignedMessage_InformationRequest_tag;
unsigned_message.sub_message.InformationRequest = information_request;


size_t universal_encode_buffer_size = this->MAX_BLE_MESSAGE_SIZE - 2;
pb_byte_t universal_encode_buffer[universal_encode_buffer_size];
int status = this->buildUnsignedMessagePayload(&unsigned_message, universal_encode_buffer, &universal_encode_buffer_size, false);
if (status != 0)
{
printf("Failed to build unsigned message\n");
return status;
}
this->prependLength(universal_encode_buffer, universal_encode_buffer_size,
output_buffer, output_length);
return 0;
}

int Client::buildWakeVehicleMessage(pb_byte_t *output_buffer,
size_t *output_length)
{
Expand Down
5 changes: 5 additions & 0 deletions src/tb_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ namespace TeslaBLE
return 1;
}
printf("Bytes written: %zu\n", unsigned_message_size_stream.bytes_written);
if (unsigned_message_size_stream.bytes_written == 0)
{
printf("\033[1;31mNo bytes written\033[0m\n");
return 1;
}
*output_length = unsigned_message_size_stream.bytes_written;
// printf("Message size: %hhu\n", *output_length);

Expand Down

0 comments on commit 0157de3

Please sign in to comment.