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