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