blob: da5e7b0266f28dd0ddc202be3d02f9fcb2b681b2 [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 =
22 MM_DBUS_INTERFACE ".MobileEquipment.IncorrectPassword";
23
24const char *kErrorSimPuk =
25 MM_DBUS_INTERFACE ".MobileEquipment.SimPuk";
26
27const char *kErrorSimPin =
28 MM_DBUS_INTERFACE ".MobileEquipment.SimPin";
29
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