blob: eb2cb17fd1af1d89e48aa290aaa95942fa0a0637 [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
Thieu Lea853df52013-09-09 14:44:07 -070021const char *kErrorGprsNotSubscribed =
22 MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".GprsServiceOptionNotSubscribed";
23
Arman Uguray763df862013-07-02 12:49:10 -070024const char *kErrorIncorrectPassword =
Ben Chan034e6892013-08-22 14:18:14 -070025 MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".IncorrectPassword";
Arman Uguray763df862013-07-02 12:49:10 -070026
Arman Uguray763df862013-07-02 12:49:10 -070027const 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
Thieu Lea853df52013-09-09 14:44:07 -070030const char *kErrorSimPuk =
31 MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".SimPuk";
32
Ben Chan151d4472013-09-06 13:29:46 -070033const char* kErrorWrongState = MM_CORE_ERROR_DBUS_PREFIX ".WrongState";
34
Arman Uguray763df862013-07-02 12:49:10 -070035} // namespace
36
37// static
38void CellularError::FromMM1DBusError(const DBus::Error &dbus_error,
39 Error *error) {
40 if (!error)
41 return;
42
43 if (!dbus_error.is_set()) {
44 error->Reset();
45 return;
46 }
47
48 string name(dbus_error.name());
49 const char *msg = dbus_error.message();
50 Error::Type type;
51
52 if (name == kErrorIncorrectPassword)
53 type = Error::kIncorrectPin;
54 else if (name == kErrorSimPin)
55 type = Error::kPinRequired;
56 else if (name == kErrorSimPuk)
57 type = Error::kPinBlocked;
Thieu Lea853df52013-09-09 14:44:07 -070058 else if (name == kErrorGprsNotSubscribed)
59 type = Error::kInvalidApn;
Ben Chan151d4472013-09-06 13:29:46 -070060 else if (name == kErrorWrongState)
61 type = Error::kWrongState;
Arman Uguray763df862013-07-02 12:49:10 -070062 else
63 type = Error::kOperationFailed;
64
65 if (msg)
66 return error->Populate(type, msg);
67 else
68 return error->Populate(type);
69}
70
71} // namespace shill