@@ -69,11 +69,16 @@ struct AdbdPacketTlsDeviceDisconnected {
6969 std::string public_key;
7070};
7171
72+ struct AdbdPacketTlsServerPort {
73+ uint16_t port;
74+ };
75+
7276using AdbdAuthPacket = std::variant<AdbdAuthPacketAuthenticated,
7377 AdbdAuthPacketDisconnected,
7478 AdbdAuthPacketRequestAuthorization,
7579 AdbdPacketTlsDeviceConnected,
76- AdbdPacketTlsDeviceDisconnected>;
80+ AdbdPacketTlsDeviceDisconnected,
81+ AdbdPacketTlsServerPort>;
7782
7883struct AdbdAuthContext {
7984 static constexpr uint64_t kEpollConstSocket = 0 ;
@@ -249,6 +254,7 @@ struct AdbdAuthContext {
249254 auto & packet = output_queue_.front ();
250255 struct iovec iovs[3 ];
251256 int iovcnt = 2 ;
257+
252258 if (auto * p = std::get_if<AdbdAuthPacketAuthenticated>(&packet)) {
253259 iovs[0 ].iov_base = const_cast <char *>(" CK" );
254260 iovs[0 ].iov_len = 2 ;
@@ -280,10 +286,18 @@ struct AdbdAuthContext {
280286 iovs[1 ].iov_len = 1 ;
281287 iovs[2 ].iov_base = p->public_key .data ();
282288 iovs[2 ].iov_len = p->public_key .size ();
289+ } else if (auto * p = std::get_if<AdbdPacketTlsServerPort>(&packet)) {
290+ iovcnt = 2 ;
291+ iovs[0 ].iov_base = const_cast <char *>(" TP" );
292+ iovs[0 ].iov_len = 2 ;
293+ iovs[1 ].iov_base = &p->port ;
294+ iovs[1 ].iov_len = 2 ;
283295 } else {
284296 LOG (FATAL) << " adbd_auth: unhandled packet type?" ;
285297 }
286298
299+ LOG (INFO) << " adbd_auth: sending packet: " << std::string ((const char *)iovs[0 ].iov_base , 2 );
300+
287301 ssize_t rc = writev (framework_fd_.get (), iovs, iovcnt);
288302 output_queue_.pop_front ();
289303 if (rc == -1 && errno != EAGAIN && errno != EWOULDBLOCK) {
@@ -469,6 +483,14 @@ struct AdbdAuthContext {
469483 Interrupt ();
470484 }
471485
486+ void SendTLSServerPort (uint16_t port) {
487+ std::lock_guard<std::mutex> lock (mutex_);
488+ output_queue_.emplace_back (AdbdPacketTlsServerPort{
489+ .port = port
490+ });
491+ Interrupt ();
492+ }
493+
472494 // Interrupt the worker thread to do some work.
473495 void Interrupt () {
474496 uint64_t value = 1 ;
@@ -588,3 +610,7 @@ bool adbd_auth_supports_feature(AdbdAuthFeature f) {
588610 UNUSED (f);
589611 return false ;
590612}
613+
614+ void adbd_auth_send_tls_server_port (AdbdAuthContext* ctx, uint16_t port) {
615+ ctx->SendTLSServerPort (port);
616+ }
0 commit comments