blob: 2e3818a44d76553ef5ed90484d08771bd0df54e0 [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);
23
24// static
25void CellularError::FromDBusError(const DBus::Error &dbus_error,
26 Error *error) {
27 if (!error)
28 return;
29
30 if (!dbus_error.is_set()) {
31 error->Reset();
32 return;
33 }
34
35 string name(dbus_error.name());
36 const char *msg = dbus_error.message();
37 Error::Type type;
38
39 if (name == kErrorIncorrectPassword)
40 type = Error::kIncorrectPin;
41 else if (name == kErrorSimPinRequired)
42 type = Error::kPinRequired;
43 else if (name == kErrorSimPukRequired)
44 type = Error::kPinBlocked;
45 else
46 type = Error::kOperationFailed;
47
48 if (msg)
49 return error->Populate(type, msg);
50 else
51 return error->Populate(type);
52}
53
54} // namespace shill