Home | History | Annotate | Download | only in cellular
      1 //
      2 // Copyright (C) 2012 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 <mm/mm-modem.h>
     22 
     23 using std::string;
     24 
     25 #define MM_MODEM_ERROR(error)  MM_MODEM_INTERFACE "." error
     26 #define MM_MOBILE_ERROR(error) MM_MODEM_GSM_INTERFACE "." error
     27 
     28 namespace shill {
     29 
     30 static const char* kErrorIncorrectPassword =
     31     MM_MOBILE_ERROR(MM_ERROR_MODEM_GSM_INCORRECTPASSWORD);
     32 static const char* kErrorSimPinRequired =
     33     MM_MOBILE_ERROR(MM_ERROR_MODEM_GSM_SIMPINREQUIRED);
     34 static const char* kErrorSimPukRequired =
     35     MM_MOBILE_ERROR(MM_ERROR_MODEM_GSM_SIMPUKREQUIRED);
     36 static const char* kErrorGprsNotSubscribed =
     37     MM_MOBILE_ERROR(MM_ERROR_MODEM_GSM_GPRSNOTSUBSCRIBED);
     38 
     39 // static
     40 void CellularError::FromChromeosDBusError(brillo::Error* dbus_error,
     41                                           Error* error) {
     42   if (!error)
     43     return;
     44 
     45   if (!dbus_error) {
     46     error->Reset();
     47     return;
     48   }
     49 
     50   const string name = dbus_error->GetCode();
     51   const string msg = dbus_error->GetMessage();
     52   Error::Type type;
     53 
     54   if (name == kErrorIncorrectPassword)
     55     type = Error::kIncorrectPin;
     56   else if (name == kErrorSimPinRequired)
     57     type = Error::kPinRequired;
     58   else if (name == kErrorSimPukRequired)
     59     type = Error::kPinBlocked;
     60   else if (name == kErrorGprsNotSubscribed)
     61     type = Error::kInvalidApn;
     62   else
     63     type = Error::kOperationFailed;
     64 
     65   if (!msg.empty())
     66     return error->Populate(type, msg);
     67   else
     68     return error->Populate(type);
     69 }
     70 
     71 }  // namespace shill
     72