Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 1 | // Copyright (c) 2013 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 <string> |
| 8 | |
| 9 | #include <ModemManager/ModemManager.h> |
| 10 | |
| 11 | // TODO(armansito): Once we refactor the code to handle the ModemManager D-Bus |
| 12 | // bindings in a dedicated class, this code should move there. |
| 13 | // (See crbug.com/246425) |
| 14 | |
| 15 | using std::string; |
| 16 | |
| 17 | namespace shill { |
| 18 | |
| 19 | namespace { |
| 20 | |
| 21 | const char *kErrorIncorrectPassword = |
Ben Chan | 034e689 | 2013-08-22 14:18:14 -0700 | [diff] [blame] | 22 | MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".IncorrectPassword"; |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 23 | |
| 24 | const char *kErrorSimPuk = |
Ben Chan | 034e689 | 2013-08-22 14:18:14 -0700 | [diff] [blame] | 25 | MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".SimPuk"; |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 26 | |
| 27 | const char *kErrorSimPin = |
Ben Chan | 034e689 | 2013-08-22 14:18:14 -0700 | [diff] [blame] | 28 | MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".SimPin"; |
Arman Uguray | 763df86 | 2013-07-02 12:49:10 -0700 | [diff] [blame] | 29 | |
| 30 | } // namespace |
| 31 | |
| 32 | // static |
| 33 | void CellularError::FromMM1DBusError(const DBus::Error &dbus_error, |
| 34 | Error *error) { |
| 35 | if (!error) |
| 36 | return; |
| 37 | |
| 38 | if (!dbus_error.is_set()) { |
| 39 | error->Reset(); |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | string name(dbus_error.name()); |
| 44 | const char *msg = dbus_error.message(); |
| 45 | Error::Type type; |
| 46 | |
| 47 | if (name == kErrorIncorrectPassword) |
| 48 | type = Error::kIncorrectPin; |
| 49 | else if (name == kErrorSimPin) |
| 50 | type = Error::kPinRequired; |
| 51 | else if (name == kErrorSimPuk) |
| 52 | type = Error::kPinBlocked; |
| 53 | else |
| 54 | type = Error::kOperationFailed; |
| 55 | |
| 56 | if (msg) |
| 57 | return error->Populate(type, msg); |
| 58 | else |
| 59 | return error->Populate(type); |
| 60 | } |
| 61 | |
| 62 | } // namespace shill |