• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2013 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 #include "shill/cellular/cellular_error.h"
18 
19 #include <string>
20 
21 #include <ModemManager/ModemManager.h>
22 
23 // TODO(armansito): Once we refactor the code to handle the ModemManager D-Bus
24 // bindings in a dedicated class, this code should move there.
25 // (See crbug.com/246425)
26 
27 using std::string;
28 
29 namespace shill {
30 
31 namespace {
32 
33 const char* kErrorGprsMissingOrUnknownApn =
34     MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".GprsMissingOrUnknownApn";
35 
36 const char* kErrorGprsServiceOptionNotSubscribed =
37     MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".GprsServiceOptionNotSubscribed";
38 
39 const char* kErrorIncorrectPassword =
40     MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".IncorrectPassword";
41 
42 const char* kErrorSimPin =
43     MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".SimPin";
44 
45 const char* kErrorSimPuk =
46     MM_MOBILE_EQUIPMENT_ERROR_DBUS_PREFIX ".SimPuk";
47 
48 const char* kErrorWrongState = MM_CORE_ERROR_DBUS_PREFIX ".WrongState";
49 
50 }  // namespace
51 
52 // static
FromMM1ChromeosDBusError(brillo::Error * dbus_error,Error * error)53 void CellularError::FromMM1ChromeosDBusError(brillo::Error* dbus_error,
54                                              Error* error) {
55   if (!error)
56     return;
57 
58   if (!dbus_error) {
59     error->Reset();
60     return;
61   }
62 
63   const string name = dbus_error->GetCode();
64   const string msg = dbus_error->GetMessage();
65   Error::Type type;
66 
67   if (name == kErrorIncorrectPassword)
68     type = Error::kIncorrectPin;
69   else if (name == kErrorSimPin)
70     type = Error::kPinRequired;
71   else if (name == kErrorSimPuk)
72     type = Error::kPinBlocked;
73   else if (name == kErrorGprsMissingOrUnknownApn)
74     type = Error::kInvalidApn;
75   else if (name == kErrorGprsServiceOptionNotSubscribed)
76     type = Error::kInvalidApn;
77   else if (name == kErrorWrongState)
78     type = Error::kWrongState;
79   else
80     type = Error::kOperationFailed;
81 
82   if (!msg.empty())
83     return error->Populate(type, msg);
84   else
85     return error->Populate(type);
86 }
87 
88 }  // namespace shill
89