pldmtool: Use a non-listening transport for command access

pldmtool does not really need to create a listening (bind) transport
to do a simple send/receive transaction. Hence refactor PldmTransport
allowing a user to specify if the required transport is expected
to be listening or non-listening and switch pldmtool to use a
non-listening transport.

Change-Id: I390298397d71c0ea27234880b844898c7a100ca5
Signed-off-by: Amithash Prasad <amithash@meta.com>
diff --git a/common/transport.cpp b/common/transport.cpp
index 5c9678a..f8bcdc3 100644
--- a/common/transport.cpp
+++ b/common/transport.cpp
@@ -8,7 +8,8 @@
 #include <ranges>
 #include <system_error>
 
-struct pldm_transport* transport_impl_init(TransportImpl& impl, pollfd& pollfd);
+struct pldm_transport* transport_impl_init(TransportImpl& impl, pollfd& pollfd,
+                                           bool listening);
 void transport_impl_destroy(TransportImpl& impl);
 
 static constexpr uint8_t MCTP_EID_VALID_MIN = 8;
@@ -64,7 +65,7 @@
 }
 
 [[maybe_unused]] static struct pldm_transport* pldm_transport_impl_af_mctp_init(
-    TransportImpl& impl, pollfd& pollfd)
+    TransportImpl& impl, pollfd& pollfd, bool listening)
 {
     impl.af_mctp = nullptr;
     pldm_transport_af_mctp_init(&impl.af_mctp);
@@ -85,7 +86,7 @@
     }
 
     /* Listen for requests on any interface */
-    if (pldm_transport_af_mctp_bind(impl.af_mctp, nullptr, 0))
+    if (listening && pldm_transport_af_mctp_bind(impl.af_mctp, nullptr, 0))
     {
         return nullptr;
     }
@@ -100,12 +101,13 @@
     return pldmTransport;
 }
 
-struct pldm_transport* transport_impl_init(TransportImpl& impl, pollfd& pollfd)
+struct pldm_transport* transport_impl_init(TransportImpl& impl, pollfd& pollfd,
+                                           [[maybe_unused]] bool listening)
 {
 #if defined(PLDM_TRANSPORT_WITH_MCTP_DEMUX)
     return pldm_transport_impl_mctp_demux_init(impl, pollfd);
 #elif defined(PLDM_TRANSPORT_WITH_AF_MCTP)
-    return pldm_transport_impl_af_mctp_init(impl, pollfd);
+    return pldm_transport_impl_af_mctp_init(impl, pollfd, listening);
 #else
     return nullptr;
 #endif
@@ -120,9 +122,9 @@
 #endif
 }
 
-PldmTransport::PldmTransport()
+PldmTransport::PldmTransport(bool listening)
 {
-    transport = transport_impl_init(impl, pfd);
+    transport = transport_impl_init(impl, pfd, listening);
     if (!transport)
     {
         throw std::system_error(ENOMEM, std::generic_category());
diff --git a/common/transport.hpp b/common/transport.hpp
index e9e1808..c7a1ec0 100644
--- a/common/transport.hpp
+++ b/common/transport.hpp
@@ -19,7 +19,7 @@
 class PldmTransport
 {
   public:
-    PldmTransport();
+    PldmTransport(bool listening = true);
     PldmTransport(const PldmTransport& other) = delete;
     PldmTransport(const PldmTransport&& other) = delete;
     PldmTransport& operator=(const PldmTransport& other) = delete;
diff --git a/pldmtool/pldm_cmd_helper.cpp b/pldmtool/pldm_cmd_helper.cpp
index e488557..ae74d91 100644
--- a/pldmtool/pldm_cmd_helper.cpp
+++ b/pldmtool/pldm_cmd_helper.cpp
@@ -130,7 +130,7 @@
     }
 
     auto tid = mctp_eid;
-    PldmTransport pldmTransport{};
+    PldmTransport pldmTransport(false);
     uint8_t retry = 0;
     int rc = PLDM_ERROR;