Make chip-tool compile with multi connection support
diff --git a/examples/chip-tool/main.cpp b/examples/chip-tool/main.cpp index 1019d13..68c22c2 100644 --- a/examples/chip-tool/main.cpp +++ b/examples/chip-tool/main.cpp
@@ -39,21 +39,39 @@ constexpr NodeId kLocalDeviceId = 112233; constexpr NodeId kRemoteDeviceId = 12344321; +static const unsigned char local_private_key[] = { 0x00, 0xd1, 0x90, 0xd9, 0xb3, 0x95, 0x1c, 0x5f, 0xa4, 0xe7, 0x47, + 0x92, 0x5b, 0x0a, 0xa9, 0xa7, 0xc1, 0x1c, 0xe7, 0x06, 0x10, 0xe2, + 0xdd, 0x16, 0x41, 0x52, 0x55, 0xb7, 0xb8, 0x80, 0x8d, 0x87, 0xa1 }; + +static const unsigned char remote_public_key[] = { 0x04, 0xe2, 0x07, 0x64, 0xff, 0x6f, 0x6a, 0x91, 0xd9, 0xc2, 0xc3, 0x0a, 0xc4, + 0x3c, 0x56, 0x4b, 0x42, 0x8a, 0xf3, 0xb4, 0x49, 0x29, 0x39, 0x95, 0xa2, 0xf7, + 0x02, 0x8c, 0xa5, 0xce, 0xf3, 0xc9, 0xca, 0x24, 0xc5, 0xd4, 0x5c, 0x60, 0x79, + 0x48, 0x30, 0x3c, 0x53, 0x86, 0xd9, 0x23, 0xe6, 0x61, 0x1f, 0x5a, 0x3d, 0xdf, + 0x9f, 0xdc, 0x35, 0xea, 0xd0, 0xde, 0x16, 0x7e, 0x64, 0xde, 0x7f, 0x3c, 0xa6 }; + static const char * PAYLOAD = "Message from Standalone CHIP echo client!"; +static void EchoKeyExchange(chip::DeviceController::ChipDeviceController * controller, Transport::PeerConnectionState * state, + void * appReqState) +{ + CHIP_ERROR err = controller->ManualKeyExchange(state, remote_public_key, sizeof(remote_public_key), local_private_key, + sizeof(local_private_key)); + + if (err != CHIP_NO_ERROR) + { + fprintf(stderr, "Failed to exchange keys"); + } +} + // Device Manager Callbacks static void EchoResponse(chip::DeviceController::ChipDeviceController * deviceController, void * appReqState, - System::PacketBuffer * buffer, const IPPacketInfo * packet_info) + System::PacketBuffer * buffer) { char src_addr[INET_ADDRSTRLEN]; char dest_addr[INET_ADDRSTRLEN]; size_t data_len = buffer->DataLength(); - packet_info->SrcAddress.ToString(src_addr, sizeof(src_addr)); - packet_info->DestAddress.ToString(dest_addr, sizeof(dest_addr)); - - printf("UDP packet received from %s:%u to %s:%u (%zu bytes)\n", src_addr, packet_info->SrcPort, dest_addr, - packet_info->DestPort, static_cast<size_t>(buffer->DataLength())); + printf("UDP packet received from :%zu bytes)\n", static_cast<size_t>(buffer->DataLength())); // attempt to print the incoming message char msg_buffer[data_len]; @@ -288,16 +306,6 @@ // ================================================================================ // Main Code // ================================================================================ -static const unsigned char local_private_key[] = { 0x00, 0xd1, 0x90, 0xd9, 0xb3, 0x95, 0x1c, 0x5f, 0xa4, 0xe7, 0x47, - 0x92, 0x5b, 0x0a, 0xa9, 0xa7, 0xc1, 0x1c, 0xe7, 0x06, 0x10, 0xe2, - 0xdd, 0x16, 0x41, 0x52, 0x55, 0xb7, 0xb8, 0x80, 0x8d, 0x87, 0xa1 }; - -static const unsigned char remote_public_key[] = { 0x04, 0xe2, 0x07, 0x64, 0xff, 0x6f, 0x6a, 0x91, 0xd9, 0xc2, 0xc3, 0x0a, 0xc4, - 0x3c, 0x56, 0x4b, 0x42, 0x8a, 0xf3, 0xb4, 0x49, 0x29, 0x39, 0x95, 0xa2, 0xf7, - 0x02, 0x8c, 0xa5, 0xce, 0xf3, 0xc9, 0xca, 0x24, 0xc5, 0xd4, 0x5c, 0x60, 0x79, - 0x48, 0x30, 0x3c, 0x53, 0x86, 0xd9, 0x23, 0xe6, 0x61, 0x1f, 0x5a, 0x3d, 0xdf, - 0x9f, 0xdc, 0x35, 0xea, 0xd0, 0xde, 0x16, 0x7e, 0x64, 0xde, 0x7f, 0x3c, 0xa6 }; - int main(int argc, char * argv[]) { IPAddress host_addr; @@ -316,12 +324,9 @@ err = controller->Init(kLocalDeviceId); VerifyOrExit(err == CHIP_NO_ERROR, fprintf(stderr, "Failed to initialize the device controller")); - err = controller->ConnectDevice(kRemoteDeviceId, host_addr, NULL, EchoResponse, ReceiveError, port); + err = controller->ConnectDevice(kRemoteDeviceId, host_addr, NULL, EchoKeyExchange, EchoResponse, ReceiveError, port); VerifyOrExit(err == CHIP_NO_ERROR, fprintf(stderr, "Failed to connect to the device")); - err = controller->ManualKeyExchange(remote_public_key, sizeof(remote_public_key), local_private_key, sizeof(local_private_key)); - VerifyOrExit(err == CHIP_NO_ERROR, fprintf(stderr, "Failed to exchange keys")); - if (command == Command::Echo) { DoEcho(controller, host_addr, port);