blob: 1d5f79078d6680b0e58f594e76aa6b5aa0757074 [file] [log] [blame]
Arman Uguray763df862013-07-02 12:49:10 -07001// Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "shill/cellular_error.h"
6
7#include <string>
8
9#include <ModemManager/ModemManager.h>
10
11// TODO(armansito): Once we refactor the code to handle the ModemManager D-Bus
12// bindings in a dedicated class, this code should move there.
13// (See crbug.com/246425)
14
15using std::string;
16
17namespace shill {
18
19namespace {
20
21const char *kErrorIncorrectPassword =
Ben Chan034e6892013-08-22 14:18:14 -070022 MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".IncorrectPassword";
Arman Uguray763df862013-07-02 12:49:10 -070023
24const char *kErrorSimPuk =
Ben Chan034e6892013-08-22 14:18:14 -070025 MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".SimPuk";
Arman Uguray763df862013-07-02 12:49:10 -070026
27const char *kErrorSimPin =
Ben Chan034e6892013-08-22 14:18:14 -070028 MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".SimPin";
Arman Uguray763df862013-07-02 12:49:10 -070029
30} // namespace
31
32// static
33void CellularError::FromMM1DBusError(const DBus::Error &dbus_error,
34 Error *error) {
35 if (!error)
36 return;
37
38 if (!dbus_error.is_set()) {
39 error->Reset();
40 return;
41 }
42
43 string name(dbus_error.name());
44 const char *msg = dbus_error.message();
45 Error::Type type;
46
47 if (name == kErrorIncorrectPassword)
48 type = Error::kIncorrectPin;
49 else if (name == kErrorSimPin)
50 type = Error::kPinRequired;
51 else if (name == kErrorSimPuk)
52 type = Error::kPinBlocked;
53 else
54 type = Error::kOperationFailed;
55
56 if (msg)
57 return error->Populate(type, msg);
58 else
59 return error->Populate(type);
60}
61
62} // namespace shill