Refactor: Handler expands TID parameter

Adding tid as a parameter to each handler so that the handler
can know the message sent from which device

Tested:
- Unit Tests passed.

Change-Id: Ida37bf61146d2f59ea11ebc7bf009f7837ed496d
Signed-off-by: Delphine CC Chiu <Delphine_CC_Chiu@wiwynn.com>
diff --git a/libpldmresponder/base.hpp b/libpldmresponder/base.hpp
index 1bd88f8..544e913 100644
--- a/libpldmresponder/base.hpp
+++ b/libpldmresponder/base.hpp
@@ -30,20 +30,24 @@
         instanceIdDb(instanceIdDb), event(event),
         oemPlatformHandler(oemPlatformHandler), handler(handler)
     {
-        handlers.emplace(PLDM_GET_PLDM_TYPES,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_GET_PLDM_TYPES,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->getPLDMTypes(request, payloadLength);
         });
-        handlers.emplace(PLDM_GET_PLDM_COMMANDS,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_GET_PLDM_COMMANDS,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->getPLDMCommands(request, payloadLength);
         });
-        handlers.emplace(PLDM_GET_PLDM_VERSION,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_GET_PLDM_VERSION,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->getPLDMVersion(request, payloadLength);
         });
-        handlers.emplace(PLDM_GET_TID,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_GET_TID,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->getTID(request, payloadLength);
         });
     }
diff --git a/libpldmresponder/bios.cpp b/libpldmresponder/bios.cpp
index 986e74a..6687901 100644
--- a/libpldmresponder/bios.cpp
+++ b/libpldmresponder/bios.cpp
@@ -78,29 +78,35 @@
     biosConfig.removeTables();
     biosConfig.buildTables();
 
-    handlers.emplace(PLDM_SET_DATE_TIME,
-                     [this](const pldm_msg* request, size_t payloadLength) {
+    handlers.emplace(
+        PLDM_SET_DATE_TIME,
+        [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
         return this->setDateTime(request, payloadLength);
     });
-    handlers.emplace(PLDM_GET_DATE_TIME,
-                     [this](const pldm_msg* request, size_t payloadLength) {
+    handlers.emplace(
+        PLDM_GET_DATE_TIME,
+        [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
         return this->getDateTime(request, payloadLength);
     });
-    handlers.emplace(PLDM_GET_BIOS_TABLE,
-                     [this](const pldm_msg* request, size_t payloadLength) {
+    handlers.emplace(
+        PLDM_GET_BIOS_TABLE,
+        [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
         return this->getBIOSTable(request, payloadLength);
     });
-    handlers.emplace(PLDM_SET_BIOS_TABLE,
-                     [this](const pldm_msg* request, size_t payloadLength) {
+    handlers.emplace(
+        PLDM_SET_BIOS_TABLE,
+        [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
         return this->setBIOSTable(request, payloadLength);
     });
-    handlers.emplace(PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE,
-                     [this](const pldm_msg* request, size_t payloadLength) {
+    handlers.emplace(
+        PLDM_GET_BIOS_ATTRIBUTE_CURRENT_VALUE_BY_HANDLE,
+        [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
         return this->getBIOSAttributeCurrentValueByHandle(request,
                                                           payloadLength);
     });
-    handlers.emplace(PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE,
-                     [this](const pldm_msg* request, size_t payloadLength) {
+    handlers.emplace(
+        PLDM_SET_BIOS_ATTRIBUTE_CURRENT_VALUE,
+        [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
         return this->setBIOSAttributeCurrentValue(request, payloadLength);
     });
 }
diff --git a/libpldmresponder/fru.hpp b/libpldmresponder/fru.hpp
index b986836..78a1a3e 100644
--- a/libpldmresponder/fru.hpp
+++ b/libpldmresponder/fru.hpp
@@ -232,17 +232,19 @@
             pldm_entity_association_tree* bmcEntityTree) :
         impl(configPath, fruMasterJsonPath, pdrRepo, entityTree, bmcEntityTree)
     {
-        handlers.emplace(PLDM_GET_FRU_RECORD_TABLE_METADATA,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_GET_FRU_RECORD_TABLE_METADATA,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->getFRURecordTableMetadata(request, payloadLength);
         });
-
-        handlers.emplace(PLDM_GET_FRU_RECORD_TABLE,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_GET_FRU_RECORD_TABLE,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->getFRURecordTable(request, payloadLength);
         });
-        handlers.emplace(PLDM_GET_FRU_RECORD_BY_OPTION,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_GET_FRU_RECORD_BY_OPTION,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->getFRURecordByOption(request, payloadLength);
         });
     }
diff --git a/libpldmresponder/platform.hpp b/libpldmresponder/platform.hpp
index 8df9625..eb01e5f 100644
--- a/libpldmresponder/platform.hpp
+++ b/libpldmresponder/platform.hpp
@@ -69,28 +69,34 @@
             pdrCreated = true;
         }
 
-        handlers.emplace(PLDM_GET_PDR,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_GET_PDR,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->getPDR(request, payloadLength);
         });
-        handlers.emplace(PLDM_SET_NUMERIC_EFFECTER_VALUE,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_SET_NUMERIC_EFFECTER_VALUE,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->setNumericEffecterValue(request, payloadLength);
         });
-        handlers.emplace(PLDM_GET_NUMERIC_EFFECTER_VALUE,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_GET_NUMERIC_EFFECTER_VALUE,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->getNumericEffecterValue(request, payloadLength);
         });
-        handlers.emplace(PLDM_SET_STATE_EFFECTER_STATES,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_SET_STATE_EFFECTER_STATES,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->setStateEffecterStates(request, payloadLength);
         });
-        handlers.emplace(PLDM_PLATFORM_EVENT_MESSAGE,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_PLATFORM_EVENT_MESSAGE,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->platformEventMessage(request, payloadLength);
         });
-        handlers.emplace(PLDM_GET_STATE_SENSOR_READINGS,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_GET_STATE_SENSOR_READINGS,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->getStateSensorReadings(request, payloadLength);
         });
 
diff --git a/oem/ibm/libpldmresponder/file_io.hpp b/oem/ibm/libpldmresponder/file_io.hpp
index 67742af..87ef3a9 100644
--- a/oem/ibm/libpldmresponder/file_io.hpp
+++ b/oem/ibm/libpldmresponder/file_io.hpp
@@ -174,52 +174,64 @@
         hostSockFd(hostSockFd), hostEid(hostEid), instanceIdDb(instanceIdDb),
         handler(handler)
     {
-        handlers.emplace(PLDM_READ_FILE_INTO_MEMORY,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_READ_FILE_INTO_MEMORY,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->readFileIntoMemory(request, payloadLength);
         });
-        handlers.emplace(PLDM_WRITE_FILE_FROM_MEMORY,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_WRITE_FILE_FROM_MEMORY,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->writeFileFromMemory(request, payloadLength);
         });
-        handlers.emplace(PLDM_WRITE_FILE_BY_TYPE_FROM_MEMORY,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_WRITE_FILE_BY_TYPE_FROM_MEMORY,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->writeFileByTypeFromMemory(request, payloadLength);
         });
-        handlers.emplace(PLDM_READ_FILE_BY_TYPE_INTO_MEMORY,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_READ_FILE_BY_TYPE_INTO_MEMORY,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->readFileByTypeIntoMemory(request, payloadLength);
         });
-        handlers.emplace(PLDM_READ_FILE_BY_TYPE,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_READ_FILE_BY_TYPE,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->readFileByType(request, payloadLength);
         });
-        handlers.emplace(PLDM_WRITE_FILE_BY_TYPE,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_WRITE_FILE_BY_TYPE,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->writeFileByType(request, payloadLength);
         });
-        handlers.emplace(PLDM_GET_FILE_TABLE,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_GET_FILE_TABLE,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->getFileTable(request, payloadLength);
         });
-        handlers.emplace(PLDM_READ_FILE,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_READ_FILE,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->readFile(request, payloadLength);
         });
-        handlers.emplace(PLDM_WRITE_FILE,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_WRITE_FILE,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->writeFile(request, payloadLength);
         });
-        handlers.emplace(PLDM_FILE_ACK,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_FILE_ACK,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->fileAck(request, payloadLength);
         });
-        handlers.emplace(PLDM_HOST_GET_ALERT_STATUS,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_HOST_GET_ALERT_STATUS,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->getAlertStatus(request, payloadLength);
         });
-        handlers.emplace(PLDM_NEW_FILE_AVAILABLE,
-                         [this](const pldm_msg* request, size_t payloadLength) {
+        handlers.emplace(
+            PLDM_NEW_FILE_AVAILABLE,
+            [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) {
             return this->newFileAvailable(request, payloadLength);
         });
 
diff --git a/pldmd/handler.hpp b/pldmd/handler.hpp
index cfa95eb..b742519 100644
--- a/pldmd/handler.hpp
+++ b/pldmd/handler.hpp
@@ -17,8 +17,8 @@
 
 using Response = std::vector<uint8_t>;
 class CmdHandler;
-using HandlerFunc =
-    std::function<Response(const pldm_msg* request, size_t reqMsgLen)>;
+using HandlerFunc = std::function<Response(
+    pldm_tid_t tid, const pldm_msg* request, size_t reqMsgLen)>;
 
 class CmdHandler
 {
@@ -27,15 +27,16 @@
 
     /** @brief Invoke a PLDM command handler
      *
+     *  @param[in] tid - PLDM request TID
      *  @param[in] pldmCommand - PLDM command code
      *  @param[in] request - PLDM request message
      *  @param[in] reqMsgLen - PLDM request message size
      *  @return PLDM response message
      */
-    Response handle(Command pldmCommand, const pldm_msg* request,
-                    size_t reqMsgLen)
+    Response handle(pldm_tid_t tid, Command pldmCommand,
+                    const pldm_msg* request, size_t reqMsgLen)
     {
-        return handlers.at(pldmCommand)(request, reqMsgLen);
+        return handlers.at(pldmCommand)(tid, request, reqMsgLen);
     }
 
     /** @brief Create a response message containing only cc
diff --git a/pldmd/invoker.hpp b/pldmd/invoker.hpp
index 9903e7f..ddfb99d 100644
--- a/pldmd/invoker.hpp
+++ b/pldmd/invoker.hpp
@@ -30,16 +30,18 @@
 
     /** @brief Invoke a PLDM command handler
      *
+     *  @param[in] tid - PLDM request TID
      *  @param[in] pldmType - PLDM type code
      *  @param[in] pldmCommand - PLDM command code
      *  @param[in] request - PLDM request message
      *  @param[in] reqMsgLen - PLDM request message size
      *  @return PLDM response message
      */
-    Response handle(Type pldmType, Command pldmCommand, const pldm_msg* request,
-                    size_t reqMsgLen)
+    Response handle(pldm_tid_t tid, Type pldmType, Command pldmCommand,
+                    const pldm_msg* request, size_t reqMsgLen)
     {
-        return handlers.at(pldmType)->handle(pldmCommand, request, reqMsgLen);
+        return handlers.at(pldmType)->handle(tid, pldmCommand, request,
+                                             reqMsgLen);
     }
 
   private:
diff --git a/pldmd/pldmd.cpp b/pldmd/pldmd.cpp
index a85157f..c1ba345 100644
--- a/pldmd/pldmd.cpp
+++ b/pldmd/pldmd.cpp
@@ -107,7 +107,7 @@
         {
             if (hdrFields.pldm_type != PLDM_FWUP)
             {
-                response = invoker.handle(hdrFields.pldm_type,
+                response = invoker.handle(tid, hdrFields.pldm_type,
                                           hdrFields.command, request,
                                           requestLen);
             }
diff --git a/test/pldmd_registration_test.cpp b/test/pldmd_registration_test.cpp
index 4f50ae0..4293357 100644
--- a/test/pldmd_registration_test.cpp
+++ b/test/pldmd_registration_test.cpp
@@ -10,19 +10,21 @@
 using namespace pldm::responder;
 constexpr Command testCmd = 0xFF;
 constexpr Type testType = 0xFF;
+constexpr pldm_tid_t tid = 0;
 
 class TestHandler : public CmdHandler
 {
   public:
     TestHandler()
     {
-        handlers.emplace(testCmd,
-                         [this](const pldm_msg* request, size_t payloadLength) {
-            return this->handle(request, payloadLength);
+        handlers.emplace(testCmd, [this](uint8_t tid, const pldm_msg* request,
+                                         size_t payloadLength) {
+            return this->handle(tid, request, payloadLength);
         });
     }
 
-    Response handle(const pldm_msg* /*request*/, size_t /*payloadLength*/)
+    Response handle(uint8_t /*tid*/, const pldm_msg* /*request*/,
+                    size_t /*payloadLength*/)
     {
         return {100, 200};
     }
@@ -43,7 +45,7 @@
 {
     Invoker invoker{};
     invoker.registerHandler(testType, std::make_unique<TestHandler>());
-    auto result = invoker.handle(testType, testCmd, nullptr, 0);
+    auto result = invoker.handle(tid, testType, testCmd, nullptr, 0);
     ASSERT_EQ(result[0], 100);
     ASSERT_EQ(result[1], 200);
 }
@@ -51,10 +53,10 @@
 TEST(Registration, testFailure)
 {
     Invoker invoker{};
-    ASSERT_THROW(invoker.handle(testType, testCmd, nullptr, 0),
+    ASSERT_THROW(invoker.handle(tid, testType, testCmd, nullptr, 0),
                  std::out_of_range);
     invoker.registerHandler(testType, std::make_unique<TestHandler>());
     uint8_t badCmd = 0xFE;
-    ASSERT_THROW(invoker.handle(testType, badCmd, nullptr, 0),
+    ASSERT_THROW(invoker.handle(tid, testType, badCmd, nullptr, 0),
                  std::out_of_range);
 }