blob: eb4fc0e31a92e2f7cb79f0d98a549ec4300b65a9 [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
Prathmesh Prabhue7c13ba2014-06-20 12:14:41 -070021const char *kErrorGprsMissingOrUnknownApn =
22 MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".GprsMissingOrUnknownApn";
23
24const char *kErrorGprsServiceOptionNotSubscribed =
Thieu Lea853df52013-09-09 14:44:07 -070025 MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".GprsServiceOptionNotSubscribed";
26
Arman Uguray763df862013-07-02 12:49:10 -070027const char *kErrorIncorrectPassword =
Ben Chan034e6892013-08-22 14:18:14 -070028 MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".IncorrectPassword";
Arman Uguray763df862013-07-02 12:49:10 -070029
Arman Uguray763df862013-07-02 12:49:10 -070030const char *kErrorSimPin =
Ben Chan034e6892013-08-22 14:18:14 -070031 MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".SimPin";
Arman Uguray763df862013-07-02 12:49:10 -070032
Thieu Lea853df52013-09-09 14:44:07 -070033const char *kErrorSimPuk =
34 MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".SimPuk";
35
Ben Chan151d4472013-09-06 13:29:46 -070036const char* kErrorWrongState = MM_CORE_ERROR_DBUS_PREFIX ".WrongState";
37
Arman Uguray763df862013-07-02 12:49:10 -070038} // namespace
39
40// static
41void CellularError::FromMM1DBusError(const DBus::Error &dbus_error,
42 Error *error) {
43 if (!error)
44 return;
45
46 if (!dbus_error.is_set()) {
47 error->Reset();
48 return;
49 }
50
51 string name(dbus_error.name());
52 const char *msg = dbus_error.message();
53 Error::Type type;
54
55 if (name == kErrorIncorrectPassword)
56 type = Error::kIncorrectPin;
57 else if (name == kErrorSimPin)
58 type = Error::kPinRequired;
59 else if (name == kErrorSimPuk)
60 type = Error::kPinBlocked;
Prathmesh Prabhue7c13ba2014-06-20 12:14:41 -070061 else if (name == kErrorGprsMissingOrUnknownApn)
62 type = Error::kInvalidApn;
63 else if (name == kErrorGprsServiceOptionNotSubscribed)
Thieu Lea853df52013-09-09 14:44:07 -070064 type = Error::kInvalidApn;
Ben Chan151d4472013-09-06 13:29:46 -070065 else if (name == kErrorWrongState)
66 type = Error::kWrongState;
Arman Uguray763df862013-07-02 12:49:10 -070067 else
68 type = Error::kOperationFailed;
69
70 if (msg)
71 return error->Populate(type, msg);
72 else
73 return error->Populate(type);
74}
75
76} // namespace shill