Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 1 | // 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 Glasgow | 82f9ab3 | 2012-04-04 14:27:19 -0400 | [diff] [blame] | 7 | #include <string> |
| 8 | |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 9 | #include <base/logging.h> |
| 10 | #include <mm/mm-modem.h> |
| 11 | |
| 12 | using 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 | |
| 17 | namespace shill { |
| 18 | |
| 19 | static const char *kErrorIncorrectPassword = |
| 20 | MM_MOBILE_ERROR(MM_ERROR_MODEM_GSM_INCORRECTPASSWORD); |
| 21 | static const char *kErrorSimPinRequired = |
| 22 | MM_MOBILE_ERROR(MM_ERROR_MODEM_GSM_SIMPINREQUIRED); |
| 23 | static const char *kErrorSimPukRequired = |
| 24 | MM_MOBILE_ERROR(MM_ERROR_MODEM_GSM_SIMPUKREQUIRED); |
Eric Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 25 | static const char *kErrorGprsNotSubscribed = |
| 26 | MM_MOBILE_ERROR(MM_ERROR_MODEM_GSM_GPRSNOTSUBSCRIBED); |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 27 | |
| 28 | // static |
| 29 | void 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 Shienbrood | 30bc0ec | 2012-03-21 18:19:46 -0400 | [diff] [blame] | 49 | else if (name == kErrorGprsNotSubscribed) |
| 50 | type = Error::kInvalidApn; |
Eric Shienbrood | 5de44ab | 2011-12-05 10:46:27 -0500 | [diff] [blame] | 51 | 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 |