blob: ca404e3659a971ff685aaadee65b2dac9ea94509 [file] [log] [blame]
Eric Shienbrood5de44ab2011-12-05 10:46:27 -05001// Copyright (c) 2012 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 <base/logging.h>
8#include <mm/mm-modem.h>
9
10using std::string;
11
12#define MM_MODEM_ERROR(error) MM_MODEM_INTERFACE "." error
13#define MM_MOBILE_ERROR(error) MM_MODEM_GSM_INTERFACE "." error
14
15namespace shill {
16
17static const char *kErrorIncorrectPassword =
18 MM_MOBILE_ERROR(MM_ERROR_MODEM_GSM_INCORRECTPASSWORD);
19static const char *kErrorSimPinRequired =
20 MM_MOBILE_ERROR(MM_ERROR_MODEM_GSM_SIMPINREQUIRED);
21static const char *kErrorSimPukRequired =
22 MM_MOBILE_ERROR(MM_ERROR_MODEM_GSM_SIMPUKREQUIRED);
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -040023static const char *kErrorGprsNotSubscribed =
24 MM_MOBILE_ERROR(MM_ERROR_MODEM_GSM_GPRSNOTSUBSCRIBED);
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050025
26// static
27void CellularError::FromDBusError(const DBus::Error &dbus_error,
28 Error *error) {
29 if (!error)
30 return;
31
32 if (!dbus_error.is_set()) {
33 error->Reset();
34 return;
35 }
36
37 string name(dbus_error.name());
38 const char *msg = dbus_error.message();
39 Error::Type type;
40
41 if (name == kErrorIncorrectPassword)
42 type = Error::kIncorrectPin;
43 else if (name == kErrorSimPinRequired)
44 type = Error::kPinRequired;
45 else if (name == kErrorSimPukRequired)
46 type = Error::kPinBlocked;
Eric Shienbrood30bc0ec2012-03-21 18:19:46 -040047 else if (name == kErrorGprsNotSubscribed)
48 type = Error::kInvalidApn;
Eric Shienbrood5de44ab2011-12-05 10:46:27 -050049 else
50 type = Error::kOperationFailed;
51
52 if (msg)
53 return error->Populate(type, msg);
54 else
55 return error->Populate(type);
56}
57
58} // namespace shill