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