Use proper errors when failing to set time

Previously it reports InsufficientPermission when it is not allowed to
set time.

Now phosphor-dbus-interfaces defines proper errors for such case, so
report NotAllowed error when it is not allowed to set time, and report
Failed error when it failed to set time.

Tested: Get NotAllowed and Failed error with expected metadata from
        journal log.

Change-Id: I53610bf27ffc3f62608cea6fd0e66ca859d94675
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/bmc_epoch.cpp b/bmc_epoch.cpp
index c06c464..8c251ee 100644
--- a/bmc_epoch.cpp
+++ b/bmc_epoch.cpp
@@ -1,9 +1,11 @@
 #include "bmc_epoch.hpp"
+#include "utils.hpp"
 
 #include <phosphor-logging/elog.hpp>
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/log.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
+#include <xyz/openbmc_project/Time/error.hpp>
 
 #include <sys/timerfd.h>
 #include <unistd.h>
@@ -24,7 +26,9 @@
 {
 namespace server = sdbusplus::xyz::openbmc_project::Time::server;
 using namespace phosphor::logging;
-using namespace sdbusplus::xyz::openbmc_project::Common::Error;
+
+using NotAllowedError =
+    sdbusplus::xyz::openbmc_project::Time::Error::NotAllowed;
 
 BmcEpoch::BmcEpoch(sdbusplus::bus::bus& bus,
                    const char* objPath)
@@ -107,8 +111,12 @@
     */
     if (timeOwner == Owner::Host)
     {
-        log<level::ERR>("Setting BmcTime with HOST owner is not allowed");
-        elog<InsufficientPermission>();
+        using namespace xyz::openbmc_project::Time;
+        elog<NotAllowedError>(
+            NotAllowed::OWNER(utils::ownerToStr(timeOwner).c_str()),
+            NotAllowed::SYNC_METHOD(utils::modeToStr(timeMode).c_str()),
+            NotAllowed::REASON(
+                "Setting BmcTime with HOST owner is not allowed"));
     }
 
     auto time = microseconds(value);