• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright (c) 2014 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"""
6This module provides exception classes for pseudomodem.
7
8"""
9
10import dbus.exceptions
11
12import common
13from autotest_lib.client.cros.cellular import mm1_constants
14
15class MMError(dbus.exceptions.DBusException):
16    """
17    Generic DBusException subclass that serves as the base class for
18    ModemManager errors.
19
20    """
21
22    def __init__(self, errno, *args, **kwargs):
23        super(MMError, self).__init__(self, args, kwargs)
24        self.include_traceback = False
25        self._error_name_base = None
26        self._error_name_map = None
27        self._Setup()
28        self._dbus_error_name = (self._error_name_base +
29            self._error_name_map[errno])
30
31    def _Setup(self):
32        raise NotImplementedError()
33
34
35class MMConnectionError(MMError):
36    """ DBusException wrapper for MMConnectionError values. """
37
38    UNKNOWN = 0
39    NO_CARRIER = 1
40    NO_DIALTONE = 2
41    BUSY = 3
42    NO_ANSWER = 4
43
44    def _Setup(self):
45        self._error_name_base = mm1_constants.MM1_ERROR_PREFIX + '.Connection'
46        self._error_name_map = {
47            self.UNKNOWN : '.Unknown',
48            self.NO_CARRIER : '.NoCarrier',
49            self.NO_DIALTONE : '.NoDialtone',
50            self.BUSY : '.Busy',
51            self.NO_ANSWER : '.NoAnswer'
52        }
53
54
55class MMCoreError(MMError):
56    """
57    DBusException wrapper for MMCoreError values.
58
59    """
60
61    FAILED = 0
62    CANCELLED = 1
63    ABORTED = 2
64    UNSUPPORTED = 3
65    NO_PLUGINS = 4
66    UNAUTHORIZED = 5
67    INVALID_ARGS = 6
68    IN_PROGRESS = 7
69    WRONG_STATE = 8
70    CONNECTED = 9
71    TOO_MANY = 10
72    NOT_FOUND = 11
73    RETRY = 12
74    EXISTS = 13
75
76    def _Setup(self):
77        self._error_name_base = mm1_constants.MM1_ERROR_PREFIX + '.Core'
78        self._error_name_map = {
79            self.FAILED : '.Failed',
80            self.CANCELLED : '.Cancelled',
81            self.ABORTED : '.Aborted',
82            self.UNSUPPORTED : '.Unsupported',
83            self.NO_PLUGINS : '.NoPlugins',
84            self.UNAUTHORIZED : '.Unauthorized',
85            self.INVALID_ARGS : '.InvalidArgs',
86            self.IN_PROGRESS : '.InProgress',
87            self.WRONG_STATE : '.WrongState',
88            self.CONNECTED : '.Connected',
89            self.TOO_MANY : '.TooMany',
90            self.NOT_FOUND : '.NotFound',
91            self.RETRY : '.Retry',
92            self.EXISTS : '.Exists'
93        }
94
95
96class MMMessageError(MMError):
97    """ DBusException wrapper for MMMessageError values. """
98
99    ME_FAILURE = 300
100    SMS_SERVICE_RESERVED = 301
101    NOT_ALLOWED = 302
102    NOT_SUPPORTED = 303
103    INVALID_PDU_PARAMETER = 304
104    INVALID_TEXT_PARAMETER = 305
105    SIM_NOT_INSERTED = 310
106    SIM_PIN = 311
107    PH_SIM_PIN = 312
108    SIM_FAILURE = 313
109    SIM_BUSY = 314
110    SIM_WRONG = 315
111    SIM_PUK = 316
112    SIM_PIN2 = 317
113    SIM_PUK2 = 318
114    MEMORY_FAILURE = 320
115    INVALID_INDEX = 321
116    MEMORY_FULL = 322
117    SMSC_ADDRESS_UNKNOWN = 330
118    NO_NETWORK = 331
119    NETWORK_TIMEOUT = 332
120    NO_CNMA_ACK_EXPECTED = 340
121    UNKNOWN = 500
122
123    def _Setup(self):
124        self._error_name_base = mm1_constants.MM1_ERROR_PREFIX + '.Message'
125        self._error_name_map = {
126            self.ME_FAILURE : '.MeFailure ',
127            self.SMS_SERVICE_RESERVED : '.SmsServiceReserved',
128            self.NOT_ALLOWED : '.NotAllowed',
129            self.NOT_SUPPORTED : '.NotSupported',
130            self.INVALID_PDU_PARAMETER :
131                    '.InvalidPduParameter',
132            self.INVALID_TEXT_PARAMETER :
133                    '.InvalidTextParameter',
134            self.SIM_NOT_INSERTED : '.SimNotInserted',
135            self.SIM_PIN : '.SimPin',
136            self.PH_SIM_PIN : '.PhSimPin',
137            self.SIM_FAILURE : '.SimFailure',
138            self.SIM_BUSY : '.SimBusy',
139            self.SIM_WRONG : '.SimWrong',
140            self.SIM_PUK : '.SimPuk',
141            self.SIM_PIN2 : '.SimPin2',
142            self.SIM_PUK2 : '.SimPuk2',
143            self.MEMORY_FAILURE : '.MemoryFailure',
144            self.INVALID_INDEX : '.InvalidIndex',
145            self.MEMORY_FULL : '.MemoryFull',
146            self.SMSC_ADDRESS_UNKNOWN : '.SmscAddressUnknown',
147            self.NO_NETWORK : '.NoNetwork',
148            self.NETWORK_TIMEOUT : '.NetworkTimeout',
149            self.NO_CNMA_ACK_EXPECTED : '.NoCnmaAckExpected',
150            self.UNKNOWN : '.Unknown'
151        }
152
153
154class MMMobileEquipmentError(MMError):
155    """ DBusException wrapper for MMMobileEquipmentError values. """
156
157    PHONE_FAILURE = 0
158    NO_CONNECTION = 1
159    LINK_RESERVED = 2
160    NOT_ALLOWED = 3
161    NOT_SUPPORTED = 4
162    PH_SIM_PIN = 5
163    PH_FSIM_PIN = 6
164    PH_FSIM_PUK = 7
165    SIM_NOT_INSERTED = 10
166    SIM_PIN = 11
167    SIM_PUK = 12
168    SIM_FAILURE = 13
169    SIM_BUSY = 14
170    SIM_WRONG = 15
171    INCORRECT_PASSWORD = 16
172    SIM_PIN2 = 17
173    SIM_PUK2 = 18
174    MEMORY_FULL = 20
175    INVALID_INDEX = 21
176    NOT_FOUND = 22
177    MEMORY_FAILURE = 23
178    TEXT_TOO_LONG = 24
179    INVALID_CHARS = 25
180    DIAL_STRING_TOO_LONG = 26
181    DIAL_STRING_INVALID = 27
182    NO_NETWORK = 30
183    NETWORK_TIMEOUT = 31
184    NETWORK_NOT_ALLOWED = 32
185    NETWORK_PIN = 40
186    NETWORK_PUK = 41
187    NETWORK_SUBSET_PIN = 42
188    NETWORK_SUBSET_PUK = 43
189    SERVICE_PIN = 44
190    SERVICE_PUK = 45
191    CORP_PIN = 46
192    CORP_PUK = 47
193    UNKNOWN = 100
194    # GPRS related errors
195    GPRS_ILLEGAL_MS = 103
196    GPRS_ILLEGAL_ME = 106
197    GPRS_SERVICE_NOT_ALLOWED = 107
198    GPRS_PLMN_NOT_ALLOWED = 111
199    GPRS_LOCATION_NOT_ALLOWED = 112
200    GPRS_ROAMING_NOT_ALLOWED = 113
201    GPRS_SERVICE_OPTION_NOT_SUPPORTED = 132
202    GPRS_SERVICE_OPTION_NOT_SUBSCRIBED = 133
203    GPRS_SERVICE_OPTION_OUT_OF_ORDER = 134
204    GPRS_UNKNOWN = 148
205    GPRS_PDP_AUTH_FAILURE = 149
206    GPRS_INVALID_MOBILE_CLASS = 150
207
208    def _Setup(self):
209        self._error_name_base = \
210            mm1_constants.MM1_ERROR_PREFIX + '.MobileEquipment'
211        self._error_name_map = {
212            self.PHONE_FAILURE : '.PhoneFailure',
213            self.NO_CONNECTION : '.NoConnection',
214            self.LINK_RESERVED : '.LinkReserved',
215            self.NOT_ALLOWED : '.NotAllowed',
216            self.NOT_SUPPORTED : '.NotSupported',
217            self.PH_SIM_PIN : '.PhSimPin',
218            self.PH_FSIM_PIN : '.PhFsimPin',
219            self.PH_FSIM_PUK : '.PhFsimPuk',
220            self.SIM_NOT_INSERTED : '.SimNotInserted',
221            self.SIM_PIN : '.SimPin',
222            self.SIM_PUK : '.SimPuk',
223            self.SIM_FAILURE : '.SimFailure',
224            self.SIM_BUSY : '.SimBusy',
225            self.SIM_WRONG : '.SimWrong',
226            self.INCORRECT_PASSWORD :
227                '.IncorrectPassword',
228            self.SIM_PIN2 : '.SimPin2',
229            self.SIM_PUK2 : '.SimPuk2',
230            self.MEMORY_FULL : '.MemoryFull',
231            self.INVALID_INDEX : '.InvalidIndex',
232            self.NOT_FOUND : '.NotFound',
233            self.MEMORY_FAILURE : '.MemoryFailure',
234            self.TEXT_TOO_LONG : '.TextTooLong',
235            self.INVALID_CHARS : '.InvalidChars',
236            self.DIAL_STRING_TOO_LONG :
237                '.DialStringTooLong',
238            self.DIAL_STRING_INVALID :
239                '.DialStringInvalid',
240            self.NO_NETWORK : '.NoNetwork',
241            self.NETWORK_TIMEOUT : '.NetworkTimeout',
242            self.NETWORK_NOT_ALLOWED :
243                '.NetworkNotAllowed',
244            self.NETWORK_PIN : '.NetworkPin',
245            self.NETWORK_PUK : '.NetworkPuk',
246            self.NETWORK_SUBSET_PIN :
247                '.NetworkSubsetPin',
248            self.NETWORK_SUBSET_PUK :
249                '.NetworkSubsetPuk',
250            self.SERVICE_PIN : '.ServicePin',
251            self.SERVICE_PUK : '.ServicePuk',
252            self.CORP_PIN : '.CorpPin',
253            self.CORP_PUK : '.CorpPuk',
254            self.UNKNOWN : '.Unknown',
255            self.GPRS_ILLEGAL_MS : '.Gprs.IllegalMs',
256            self.GPRS_ILLEGAL_ME : '.Gprs.IllegalMe',
257            self.GPRS_SERVICE_NOT_ALLOWED :
258                '.Gprs.ServiceNotAllowed',
259            self.GPRS_PLMN_NOT_ALLOWED :
260                '.Gprs.PlmnNotAllowed',
261            self.GPRS_LOCATION_NOT_ALLOWED :
262                '.Gprs.LocationNotAllowed',
263            self.GPRS_ROAMING_NOT_ALLOWED :
264                '.Gprs.RoamingNotAllowed',
265            self.GPRS_SERVICE_OPTION_NOT_SUPPORTED :
266                '.Gprs.ServiceOptionNotSupported',
267            self.GPRS_SERVICE_OPTION_NOT_SUBSCRIBED :
268                '.Gprs.ServiceOptionNotSubscribed',
269            self.GPRS_SERVICE_OPTION_OUT_OF_ORDER :
270                '.Gprs.ServiceOptionOutOfOrder',
271            self.GPRS_UNKNOWN :
272                '.Gprs.Unknown',
273            self.GPRS_PDP_AUTH_FAILURE :
274                '.Gprs.PdpAuthFailure',
275            self.GPRS_INVALID_MOBILE_CLASS :
276                '.Gprs.InvalidMobileClass'
277        }
278
279
280class MMSerialError(MMError):
281    """ DBusException wrapper for MMSerialError values. """
282
283    UNKNOWN = 0
284    OPEN_FAILED = 1
285    SEND_FAILED = 2
286    RESPONSE_TIMEOUT = 3
287    OPEN_FAILED_NO_DEVICE = 4
288    FLASH_FAILED = 5
289    NOT_OPEN = 6
290
291    def _Setup(self):
292        self._error_name_base = mm1_constants.MM1_ERROR_PREFIX + '.Serial'
293        self._error_name_map = {
294            self.UNKNOWN : '.Unknown',
295            self.OPEN_FAILED : '.OpenFailed',
296            self.SEND_FAILED : '.SendFailed',
297            self.RESPONSE_TIMEOUT : '.ResponseTimeout',
298            self.OPEN_FAILED_NO_DEVICE : '.OpenFailedNoDevice',
299            self.FLASH_FAILED : '.FlashFailed',
300            self.NOT_OPEN : '.NotOpen'
301        }
302
303
304class MMCdmaActivationError(MMError):
305    """ DBusException wrapper for MMCdmaActivationError values. """
306
307    NONE = 0
308    UNKNOWN = 1
309    ROAMING = 2
310    WRONG_RADIO_INTERFACE = 3
311    COULD_NOT_CONNECT = 4
312    SECURITY_AUTHENTICATION_FAILED = 5
313    PROVISIONING_FAILED = 6
314    NO_SIGNAL = 7
315    TIMED_OUT = 8
316    START_FAILED = 9
317
318    def _Setup(self):
319        self._error_name_base = \
320            mm1_constants.MM1_ERROR_PREFIX + '.CdmaActivation'
321        self._error_name_map = {
322            self.NONE : '.None',
323            self.UNKNOWN :
324                '.Unknown',
325            self.ROAMING :
326                '.Roaming',
327            self.WRONG_RADIO_INTERFACE :
328                '.WrongRadioInterface',
329            self.COULD_NOT_CONNECT :
330                '.CouldNotConnect',
331            self.SECURITY_AUTHENTICATION_FAILED :
332                '.SecurityAuthenticationFailed',
333            self.PROVISIONING_FAILED :
334                '.ProvisioningFailed',
335            self.NO_SIGNAL :
336                '.NoSignal',
337            self.TIMED_OUT :
338                '.TimedOut',
339            self.START_FAILED :
340                '.StartFailed'
341        }
342
343
344class TestError(dbus.exceptions.DBusException):
345    """
346    Raised by the test interface of Pseudomodem.
347
348    This is not a core ModemManager error, and is raised only on the test
349    interface mostly to notify the user of invalid requests or misconfiguration
350    of pseudomodem.
351
352    """
353    pass
354