blob: 3ff3886e6fd131e0853c8a26de2b08e5122bdf6f [file] [log] [blame]
// Copyright 2018 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "shill/cellular/cellular_error.h"
#include <string>
#include <ModemManager/ModemManager.h>
// TODO(armansito): Once we refactor the code to handle the ModemManager D-Bus
// bindings in a dedicated class, this code should move there.
// (See crbug.com/246425)
namespace shill {
namespace {
// TODO(b/217612447): How can we prevent a change in MM from messing up
// the hardcoded strings?
const char kErrorMissingOrUnknownApn[] =
MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".MissingOrUnknownApn";
const char kErrorServiceOptionNotSubscribed[] =
MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".ServiceOptionNotSubscribed";
const char kErrorUserAuthenticationFailed[] =
MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".UserAuthenticationFailed";
const char kErrorIncorrectPassword[] =
MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".IncorrectPassword";
const char kErrorSimPin[] = MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".SimPin";
const char kErrorSimPuk[] = MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".SimPuk";
const char kErrorWrongState[] = MM_CORE_ERROR_DBUS_PREFIX ".WrongState";
} // namespace
// static
void CellularError::FromMM1ChromeosDBusError(brillo::Error* dbus_error,
Error* error) {
if (!error)
return;
if (!dbus_error) {
error->Reset();
return;
}
const std::string name = dbus_error->GetCode();
const std::string msg = dbus_error->GetMessage();
Error::Type type;
if (name == kErrorIncorrectPassword)
type = Error::kIncorrectPin;
else if (name == kErrorSimPin)
type = Error::kPinRequired;
else if (name == kErrorSimPuk)
type = Error::kPinBlocked;
else if (name == kErrorMissingOrUnknownApn)
type = Error::kInvalidApn;
else if (name == kErrorServiceOptionNotSubscribed)
type = Error::kInvalidApn;
else if (name == kErrorUserAuthenticationFailed)
type = Error::kInvalidApn;
else if (name == kErrorWrongState)
type = Error::kWrongState;
else
type = Error::kOperationFailed;
if (!msg.empty())
return error->Populate(type, msg, name);
else
return error->Populate(type, "", name);
}
} // namespace shill