示例#1
0
 def _ShouldStartStateMachine(self):
     state = self._modem.Get(mm1_constants.I_MODEM, 'State')
     # Return success if already enabled.
     if state >= mm1_constants.MM_MODEM_STATE_ENABLED:
         logging.info('Modem is already enabled. Nothing to do.')
         if self.return_cb:
             self.return_cb()
         return False
     if self._modem.enable_step and self._modem.enable_step != self:
         # There is already an enable operation in progress.
         # Note: ModemManager currently returns "WrongState" for this case.
         # The API suggests that "InProgress" should be returned, so that's
         # what we do here.
         logging.error('There is already an ongoing enable operation')
         if state == mm1_constants.MM_MODEM_STATE_ENABLING:
             message = 'Modem enable already in progress.'
         else:
             message = 'Modem enable has already been initiated' \
                       ', ignoring.'
         raise pm_errors.MMCoreError(pm_errors.MMCoreError.IN_PROGRESS,
                                     message)
     elif self._modem.enable_step is None:
         # There is no enable operation going on, cancelled or otherwise.
         if state != mm1_constants.MM_MODEM_STATE_DISABLED:
             message = 'Modem cannot be enabled if not in the DISABLED' \
                       ' state.'
             logging.error(message)
             raise pm_errors.MMCoreError(pm_errors.MMCoreError.WRONG_STATE,
                                         message)
         logging.info('Starting Enable')
         self._modem.enable_step = self
     return True
示例#2
0
    def _ShouldStartStateMachine(self):
        if self._modem.cdma_activate_step and \
            self._modem.cdma_activate_step != self:
            # There is already an activate operation in progress.
            logging.error('There is already an ongoing activate operation.')
            raise pm_errors.MMCoreError(pm_errors.MMCoreError.IN_PROGRESS,
                                        "Activation already in progress.")

        if self._modem.cdma_activate_step is None:
            # There is no activate operation going on, cancelled or otherwise.
            state = self._modem.Get(mm1_constants.I_MODEM_CDMA,
                                    'ActivationState')
            if (state !=
                    mm1_constants.MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED
                ):
                message = "Modem is not in state 'NOT_ACTIVATED'."
                logging.error(message)
                raise pm_errors.MMCoreError(pm_errors.MMCoreError.WRONG_STATE,
                                            message)

            state = self._modem.Get(mm1_constants.I_MODEM, 'State')
            if state != mm1_constants.MM_MODEM_STATE_REGISTERED:
                message = 'Modem cannot be activated if not in the ' \
                          'REGISTERED state.'
                logging.error(message)
                raise pm_errors.MMCoreError(pm_errors.MMCoreError.WRONG_STATE,
                                            message)

            self._modem.cdma_activate_step = self
        return True
    def _ShouldStartStateMachine(self):
        if self._modem.register_step and self._modem.register_step != self:
            # There is already an ongoing register operation.
            message = 'Register operation already in progress.'
            logging.info(message)
            error = pm_errors.MMCoreError(pm_errors.MMCoreError.IN_PROGRESS,
                                          message)
            if self._raise_cb:
                self._raise_cb(error)
            else:
                raise error
        elif self._modem.register_step is None:
            # There is no register operation going on, canceled or otherwise.
            state = self._modem.Get(mm1_constants.I_MODEM, 'State')
            if state != mm1_constants.MM_MODEM_STATE_ENABLED:
                message = 'Cannot initiate register while in state %d, ' \
                          'state needs to be ENABLED.' % state
                error = pm_errors.MMCoreError(
                    pm_errors.MMCoreError.WRONG_STATE, message)
                if self._raise_cb:
                    self._raise_cb(error)
                else:
                    raise error

            logging.info('Starting Register.')
            self._modem.register_step = self
        return True
示例#4
0
    def ActivateBearer(self, bearer_path):
        """
        Activates a data bearer by setting its 'Connected' property to True.

        This request may fail if the modem does not support additional active
        bearers, if too many bearers are already active, if the requested
        bearer doesn't exist, or if the requested bearer is already active.

        @param bearer_path: DBus path of the bearer to activate.

        """
        logging.info('ActivateBearer: %s', bearer_path)
        bearer = self.bearers.get(bearer_path, None)
        if bearer is None:
            message = 'Could not find bearer with path "%s"' % bearer_path
            logging.info(message)
            raise pm_errors.MMCoreError(pm_errors.MMCoreError.NOT_FOUND,
                                        message)

        max_active_bearers = self.Get(mm1_constants.I_MODEM,
                                      'MaxActiveBearers')
        if len(self.active_bearers) >= max_active_bearers:
            message = ('Cannot activate bearer: maximum active bearer count '
                       'reached.')
            logging.info(message)
            raise pm_errors.MMCoreError(pm_errors.MMCoreError.TOO_MANY,
                                        message)
        if bearer.IsActive():
            message = 'Bearer with path "%s" already active.', bearer_path
            logging.info(message)
            raise pm_errors.MMCoreError(pm_errors.MMCoreError.CONNECTED,
                                        message)

        self.active_bearers[bearer_path] = bearer
        bearer.Connect()
示例#5
0
    def _ShouldStartStateMachine(self):
        if self._modem.disable_step and self._modem.disable_step != self:
            # There is already a disable operation in progress.
            message = 'Modem disable already in progress.'
            logging.info(message)
            raise pm_errors.MMCoreError(pm_errors.MMCoreError.IN_PROGRESS,
                                        message)
        elif self._modem.disable_step is None:
            # There is no disable operation going in, cancelled or otherwise.
            state = self._modem.Get(mm1_constants.I_MODEM, 'State')
            if state == mm1_constants.MM_MODEM_STATE_DISABLED:
                # The reason we're not raising an error here is that
                # shill will make multiple successive calls to disable
                # but WON'T check for raised errors, which causes
                # problems. Treat this particular case as success.
                logging.info('Already in a disabled state. Ignoring.')
                if self.return_cb:
                    self.return_cb()
                return False

            invalid_states = [
                mm1_constants.MM_MODEM_STATE_FAILED,
                mm1_constants.MM_MODEM_STATE_UNKNOWN,
                mm1_constants.MM_MODEM_STATE_INITIALIZING,
                mm1_constants.MM_MODEM_STATE_LOCKED
            ]
            if state in invalid_states:
                raise pm_errors.MMCoreError(
                    pm_errors.MMCoreError.WRONG_STATE,
                    ('Modem disable cannot be initiated while in state'
                     ' %u.') % state)
            if self._modem.connect_step:
                logging.info('There is an ongoing Connect, canceling it.')
                self._modem.connect_step.Cancel()
            if self._modem.register_step:
                logging.info('There is an ongoing Register, canceling it.')
                self._modem.register_step.Cancel()
            if self._modem.enable_step:
                # This needs to be done here, because the case where an enable
                # cycle has been initiated but it hasn't triggered any state
                # transitions yet would not be detected in a state handler.
                logging.info('There is an ongoing Enable, canceling it.')
                logging.info('This should bring the modem to a disabled state.'
                             ' DisableMachine will not start.')
                self._modem.enable_step.Cancel()
                assert self._modem.Get(mm1_constants.I_MODEM, 'State') == \
                    mm1_constants.MM_MODEM_STATE_DISABLED
            if self._modem.Get(mm1_constants.I_MODEM, 'State') == \
                    mm1_constants.MM_MODEM_STATE_DISABLED:
                if self.return_cb:
                    self.return_cb()
                return False

            logging.info('Starting Disable.')
            self._modem.disable_step = self
        return True
    def _ShouldStartStateMachine(self):
        if (self._modem.disconnect_step and
                # There is already a disconnect operation in progress.
                self._modem.disconnect_step != self):
            message = 'There is already an ongoing disconnect operation.'
            logging.error(message)
            self.raise_cb(
                pm_errors.MMCoreError(pm_errors.MMCoreError.IN_PROGRESS,
                                      message))
            return False
        elif self._modem.disconnect_step is None:
            # There is no disconnect operation going on, canceled or otherwise.
            state = self._modem.Get(mm1_constants.I_MODEM, 'State')
            if state != mm1_constants.MM_MODEM_STATE_CONNECTED:
                message = 'Modem cannot be disconnected when not connected.'
                logging.error(message)
                self.raise_cb(
                    pm_errors.MMCoreError(pm_errors.MMCoreError.WRONG_STATE,
                                          message))
                return False

            if self.bearer_path == mm1_constants.ROOT_PATH:
                logging.info('All bearers will be disconnected.')
            elif not (self.bearer_path in self._modem.bearers):
                message = ('Bearer with path "%s" not found' %
                           self.bearer_path)
                logging.error(message)
                self.raise_cb(
                    pm_errors.MMCoreError(pm_errors.MMCoreError.NOT_FOUND,
                                          message))
                return False
            elif not (self.bearer_path in self._modem.active_bearers):
                message = ('No active bearer with path ' + self.bearer_path +
                           ' found, current active bearers are ' +
                           str(self._modem.active_bearers))
                logging.error(message)
                self.raise_cb(
                    pm_errors.MMCoreError(pm_errors.MMCoreError.NOT_FOUND,
                                          message))
                return False

            assert not self._modem.IsPendingConnect()
            assert not self._modem.IsPendingEnable()
            assert not self._modem.IsPendingRegister()

            logging.info('Starting Disconnect.')
            self._modem.disconnect_step = self
        return True
示例#7
0
    def CreateBearer(self, properties):
        """
        Creates a new packet data bearer using the given characteristics.

        This request may fail if the modem does not support additional bearers,
        if too many bearers are already defined, or if properties are invalid.

        @param properties: A dictionary containing the properties to assign to
                the bearer after creating it. The allowed property values are
                contained in modem.ALLOWED_PROPERTIES.
        @returns: On success, the object path of the newly created bearer.

        """
        logging.info('CreateBearer')
        maxbearers = self.Get(mm1_constants.I_MODEM, 'MaxBearers')
        if len(self.bearers) == maxbearers:
            raise pm_errors.MMCoreError(
                pm_errors.MMCoreError.TOO_MANY,
                ('Maximum number of bearers reached. Cannot create new '
                 'bearer.'))
        else:
            self.ValidateBearerProperties(properties)
            bearer_obj = bearer.Bearer(self.bus, properties)
            logging.info('Created bearer with path "%s".', bearer_obj.path)
            self.bearers[bearer_obj.path] = bearer_obj
            self._UpdateBearersProperty()
            return bearer_obj.path
示例#8
0
    def SendPuk(self, puk, pin):
        """
        Sends the PUK and a new PIN to unlock the SIM card.

        @param puk: A string containing the PUK code.
        @param pin: A string containing the PIN code.

        """
        if self._lock_type != mm1_constants.MM_MODEM_LOCK_SIM_PUK:
            logging.info('No PUK lock in place. Nothing to do.')
            return

        lock_data = self._lock_data.get(self._lock_type, None)
        if not lock_data:
            raise pm_errors.MMCoreError(
                    pm_errors.MMCoreError.FAILED,
                    'Current lock type does not match the SIM locks in place.')

        if lock_data['retries'] == 0:
            raise SimFailureError()

        self._CheckCode(puk, lock_data, None, SimFailureError())

        logging.info('Entered correct PUK.')
        self._ResetRetries(mm1_constants.MM_MODEM_LOCK_SIM_PIN)
        self._ResetRetries(mm1_constants.MM_MODEM_LOCK_SIM_PUK)
        self._lock_data[mm1_constants.MM_MODEM_LOCK_SIM_PIN]['code'] = pin
        self._lock_type = mm1_constants.MM_MODEM_LOCK_NONE
        self._modem.UpdateLockStatus()
        self._modem.Expose3GPPProperties()
        self._UpdateProperties()
示例#9
0
    def SyncScan(self):
        """ The synchronous implementation of |Scan| for this class. """
        state = self.Get(mm1_constants.I_MODEM, 'State')
        if state < mm1_constants.MM_MODEM_STATE_ENABLED:
            raise pm_errors.MMCoreError(
                    pm_errors.MMCoreError.WRONG_STATE,
                    'Modem not enabled, cannot scan for networks.')

        sim_path = self.Get(mm1_constants.I_MODEM, 'Sim')
        if not self.sim:
            assert sim_path == mm1_constants.ROOT_PATH
            raise pm_errors.MMMobileEquipmentError(
                pm_errors.MMMobileEquipmentError.SIM_NOT_INSERTED,
                'Cannot scan for networks because no SIM is inserted.')
        assert sim_path != mm1_constants.ROOT_PATH

        # TODO(armansito): check here for SIM lock?

        scanned = [network.ToScanDictionary()
                   for network in self.roaming_networks]

        # get home network
        sim_props = self.sim.GetAll(mm1_constants.I_SIM)
        scanned.append({
            'status': dbus.types.UInt32(
                    mm1_constants.MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE),
            'operator-long': sim_props['OperatorName'],
            'operator-short': sim_props['OperatorName'],
            'operator-code': sim_props['OperatorIdentifier'],
            'access-technology': dbus.types.UInt32(self.sim.access_technology)
        })

        self._scanned_networks = (
                {network['operator-code']: network for network in scanned})
        return scanned
示例#10
0
    def SendPin(self, pin):
        """
        Sends the PIN to unlock the SIM card.

        @param pin: A string containing the PIN code.

        """
        if not self.locked:
            logging.info('SIM is not locked. Nothing to do.')
            return

        if self._lock_type == mm1_constants.MM_MODEM_LOCK_SIM_PUK:
            if self._lock_data[self._lock_type]['retries'] == 0:
                raise SimFailureError()
            else:
                raise SimPukError()

        lock_data = self._lock_data.get(self._lock_type, None)
        if not lock_data:
            raise pm_errors.MMCoreError(
                pm_errors.MMCoreError.FAILED,
                'Current lock type does not match the SIM lock capabilities.')

        self._CheckCode(pin, lock_data, mm1_constants.MM_MODEM_LOCK_SIM_PUK,
                        SimPukError())

        logging.info('Entered correct PIN.')
        self._ResetRetries(mm1_constants.MM_MODEM_LOCK_SIM_PIN)
        self._lock_type = mm1_constants.MM_MODEM_LOCK_NONE
        self._modem.UpdateLockStatus()
        self._modem.Expose3GPPProperties()
        self._UpdateProperties()
示例#11
0
    def Register(self, operator_id, return_cb=None, raise_cb=None):
        """
        Request registration with a given modem network.

        @param operator_id: The operator ID to register. An empty string can be
                used to register to the home network.
        @param return_cb: Async success callback.
        @param raise_cb: Async error callback.

        """
        logging.info('Modem3gpp.Register: %s', operator_id)

        # Check if we're already registered with the given network.
        if (self.Get(mm1_constants.I_MODEM_3GPP, 'OperatorCode') ==
            operator_id or
            ((not operator_id and self.Get(mm1_constants.I_MODEM, 'State') >=
                    mm1_constants.MM_MODEM_STATE_REGISTERED))):
            message = 'Already registered.'
            logging.info(message)
            raise pm_errors.MMCoreError(pm_errors.MMCoreError.FAILED, message)

        if (self.Get(mm1_constants.I_MODEM, 'State') <
            mm1_constants.MM_MODEM_STATE_ENABLED):
            message = 'Cannot register the modem if not enabled.'
            logging.info(message)
            raise pm_errors.MMCoreError(pm_errors.MMCoreError.FAILED, message)

        self.CancelAllStateMachines()

        def _Reregister():
            if (self.Get(mm1_constants.I_MODEM, 'State') ==
                mm1_constants.MM_MODEM_STATE_REGISTERED):
                self.UnregisterWithNetwork()
            self.RegisterWithNetwork(operator_id, return_cb, raise_cb)

        if (self.Get(mm1_constants.I_MODEM, 'State') ==
            mm1_constants.MM_MODEM_STATE_CONNECTED):
            self.Disconnect(mm1_constants.ROOT_PATH, _Reregister, raise_cb)
        else:
            _Reregister()
    def _ShouldStartStateMachine(self):
        if self._modem.connect_step and self._modem.connect_step != self:
            # There is already a connect operation in progress.
            message = 'There is already an ongoing connect operation.'
            logging.error(message)
            self.raise_cb(
                pm_errors.MMCoreError(pm_errors.MMCoreError.IN_PROGRESS,
                                      message))
            return False
        elif self._modem.connect_step is None:
            # There is no connect operation going on, cancelled or otherwise.
            if self._modem.IsPendingDisable():
                message = 'Modem is currently being disabled. Ignoring ' \
                          'connect.'
                logging.error(message)
                self.raise_cb(
                    pm_errors.MMCoreError(pm_errors.MMCoreError.WRONG_STATE,
                                          message))
                return False
            state = self._modem.Get(mm1_constants.I_MODEM, 'State')
            if state == mm1_constants.MM_MODEM_STATE_CONNECTED:
                message = 'Modem is already connected.'
                logging.error(message)
                self.raise_cb(
                    pm_errors.MMCoreError(pm_errors.MMCoreError.CONNECTED,
                                          message))
                return False
            if state == mm1_constants.MM_MODEM_STATE_DISCONNECTING:
                assert self._modem.IsPendingDisconnect()
                message = 'Cannot connect while disconnecting.'
                logging.error(message)
                self.raise_cb(
                    pm_errors.MMCoreError(pm_errors.MMCoreError.WRONG_STATE,
                                          message))
                return False

            logging.info('Starting Connect.')
            self._modem.connect_step = self
        return True
示例#13
0
 def Cancel(self):
     """ Overriden from superclass. """
     logging.info('EnableMachine: Canceling enable.')
     super(EnableMachine, self).Cancel()
     state = self._modem.Get(mm1_constants.I_MODEM, 'State')
     reason = mm1_constants.MM_MODEM_STATE_CHANGE_REASON_USER_REQUESTED
     if state == mm1_constants.MM_MODEM_STATE_ENABLING:
         logging.info('EnableMachine: Setting state to DISABLED.')
         self._modem.ChangeState(mm1_constants.MM_MODEM_STATE_DISABLED,
                                 reason)
     self._modem.enable_step = None
     if self.raise_cb:
         self.raise_cb(
             pm_errors.MMCoreError(pm_errors.MMCoreError.CANCELLED,
                                   'Operation cancelled'))
示例#14
0
    def ValidateBearerProperties(self, properties):
        """
        The default implementation makes sure that all keys in properties are
        one of the allowed bearer properties. Subclasses can override this
        method to provide CDMA/3GPP specific checks.

        @param properties: The dictionary of properties and values to validate.
        @raises: MMCoreError, if one or more properties are invalid.

        """
        for key in properties.iterkeys():
            if key not in ALLOWED_BEARER_PROPERTIES:
                raise pm_errors.MMCoreError(
                    pm_errors.MMCoreError.INVALID_ARGS,
                    'Invalid property "%s", not creating bearer.' % key)
示例#15
0
    def DeactivateBearer(self, bearer_path):
        """
        Deactivates data bearer by setting its 'Connected' property to False.

        This request may fail if the modem with the requested path doesn't
        exist, or if the bearer is not active.

        @param bearer_path: DBus path of the bearer to activate.

        """
        logging.info('DeactivateBearer: %s', bearer_path)
        bearer = self.bearers.get(bearer_path, None)
        if bearer is None:
            raise pm_errors.MMCoreError(
                pm_errors.MMCoreError.NOT_FOUND,
                'Could not find bearer with path "%s".' % bearer_path)
        if not bearer.IsActive():
            assert bearer_path not in self.active_bearers
            raise pm_errors.MMCoreError(
                pm_errors.MMCoreError.WRONG_STATE,
                'Bearer with path "%s" is not active.' % bearer_path)
        assert bearer_path in self.active_bearers
        bearer.Disconnect()
        self.active_bearers.pop(bearer_path)
示例#16
0
    def SetPowerState(self, power_state):
        """
        Sets the power state of the modem. This action can only be run when the
        modem is in the MM_MODEM_STATE_DISABLED state.

        @param power_state: Specifies the desired power state as a
                MMModemPowerState value.
        @raises: MMCoreError if state is not DISABLED.

        """
        if (self.Get(mm1_constants.I_MODEM, 'State') !=
                mm1_constants.MM_MODEM_STATE_DISABLED):
            raise pm_errors.MMCoreError(
                pm_errors.MMCoreError.WRONG_STATE,
                'Cannot set the power state if modem is not DISABLED.')
        self.SetUInt32(mm1_constants.I_MODEM, 'PowerState', power_state)
示例#17
0
    def SetCurrentCapabilities(self, capabilities):
        """
        Set the capabilities of the device. A restart of the modem may be
        required.

        @param capabilities: Bitmask of MMModemCapability values, to specify the
                capabilities to use.

        """
        supported = self.Get(mm1_constants.I_MODEM, 'SupportedCapabilities')
        if not capabilities in supported:
            raise pm_errors.MMCoreError(
                pm_errors.MMCoreError.FAILED,
                'Given capabilities not supported: ' + capabilities)
        self.SetUInt32(mm1_constants.I_MODEM, 'CurrentCapabilities',
                       capabilities)
示例#18
0
    def SetCurrentModes(self, modes):
        """
        Sets the access technologies (eg 2G/3G/4G preference) the device is
        currently allowed to use when connecting to a network.

        @param modes: Specifies all the modes allowed in the modem as a bitmask
                of MMModemModem values.
        @param preferred: Specific MMModemMode preferred among the ones allowed,
                if any.

        """
        allowed = self.Get(mm1_constants.I_MODEM, 'SupportedModes')
        if not modes in allowed:
            raise pm_errors.MMCoreError(pm_errors.MMCoreError.FAILED,
                                        'Mode not supported: ' + repr(modes))
        self.Set(mm1_constants.I_MODEM, 'CurrentModes', modes)
    def _HandleSearchingState(self):
        logging.info('RegisterMachine: Modem is SEARCHING.')
        if not self._networks:
            logging.info('RegisterMachine: Scan returned no networks.')
            logging.info('RegisterMachine: Setting state to ENABLED.')
            self._modem.ChangeState(
                mm1_constants.MM_MODEM_STATE_ENABLED,
                mm1_constants.MM_MODEM_STATE_CHANGE_REASON_UNKNOWN)
            # TODO(armansito): Figure out the correct registration
            # state to transition to when no network is present.
            logging.info('RegisterMachine: Setting registration state '
                         'to IDLE.')
            self._modem.SetRegistrationState(
                mm1_constants.MM_MODEM_3GPP_REGISTRATION_STATE_IDLE)
            self._modem.register_step = None
            if self._raise_cb:
                self._raise_cb(
                    pm_errors.MMMobileEquipmentError(
                        pm_errors.MMMobileEquipmentError.NO_NETWORK,
                        'No networks were found to register.'))
            return False

        # Pick the last network in the list. Roaming networks will come before
        # the home network which makes the last item in the list the home
        # network.
        if self._operator_code:
            if not self._operator_code in self._modem.scanned_networks:
                if self._raise_cb:
                    self._raise_cb(
                        pm_errors.MMCoreError(
                            pm_errors.MMCoreError.FAILED,
                            "Unknown network: " + self._operator_code))
                return False
            network = self._modem.scanned_networks[self._operator_code]
        else:
            network = self._networks[-1]
        logging.info('RegisterMachine: Registering to network: ' +
                     str(network))
        self._modem.SetRegistered(network['operator-code'],
                                  network['operator-long'])

        # The previous call should have set the state to REGISTERED.
        self._modem.register_step = None

        if self._return_cb:
            self._return_cb()
        return False
 def Cancel(self):
     """ Overriden from superclass. """
     logging.info('RegisterMachine: Canceling register.')
     super(RegisterMachine, self).Cancel()
     state = self._modem.Get(mm1_constants.I_MODEM, 'State')
     reason = mm1_constants.MM_MODEM_STATE_CHANGE_REASON_USER_REQUESTED
     if state == mm1_constants.MM_MODEM_STATE_SEARCHING:
         logging.info('RegisterMachine: Setting state to ENABLED.')
         self._modem.ChangeState(mm1_constants.MM_MODEM_STATE_ENABLED,
                                 reason)
         self._modem.SetRegistrationState(
             mm1_constants.MM_MODEM_3GPP_REGISTRATION_STATE_IDLE)
     self._modem.register_step = None
     if self._raise_cb:
         self._raise_cb(
             pm_errors.MMCoreError(pm_errors.MMCoreError.CANCELLED,
                                   'Cancelled'))
    def _HandleDisabledState(self):
        logging.info('ConnectMachine: Modem is DISABLED.')
        assert not self._modem.IsPendingEnable()
        if self.enable_initiated:
            message = 'ConnectMachine: Failed to enable modem.'
            logging.error(message)
            self.Cancel()
            self._modem.connect_step = None
            self.raise_cb(
                pm_errors.MMCoreError(pm_errors.MMCoreError.FAILED, message))
            return False
        else:
            logging.info('ConnectMachine: Initiating Enable.')
            self.enable_initiated = True
            self._modem.Enable(True)

            # state machine will spin until modem gets enabled,
            # or if enable fails
            return True
    def _HandleEnabledState(self):
        logging.info('ConnectMachine: Modem is ENABLED.')

        # Check to see if a register is going on, if not,
        # start register
        if self.register_initiated:
            message = 'ConnectMachine: Failed to register.'
            logging.error(message)
            self.Cancel()
            self._modem.connect_step = None
            self.raise_cb(
                pm_errors.MMCoreError(pm_errors.MMCoreError.FAILED, message))
            return False
        else:
            logging.info('ConnectMachine: Waiting for Register.')
            if not self._modem.IsPendingRegister():
                self._modem.RegisterWithNetwork("", self._return_cb,
                                                self._raise_cb)
            self.register_initiated = True
            return True
示例#23
0
    def Cancel(self, message='Activation canceled.'):
        """ Cancel the CdmaActivateMachine. """
        logging.info('CdmaActivateMachine: Canceling activate.')
        super(CdmaActivateMachine, self).Cancel()
        state = self._modem.Get(mm1_constants.I_MODEM_CDMA, 'ActivationState')

        # If activated, return success.
        if state == mm1_constants.MM_MODEM_CDMA_ACTIVATION_STATE_ACTIVATED:
            logging.info('CdmaActivateMachine: Already activated. '
                         'Returning success.')
            if self._return_cb:
                self._return_cb()
            return

        self._modem.ChangeActivationState(
            mm1_constants.MM_MODEM_CDMA_ACTIVATION_STATE_NOT_ACTIVATED,
            pm_errors.MMCdmaActivationError.UNKNOWN)

        self._modem.cdma_activate_step = None

        if self._raise_cb:
            self._raise_cb(
                pm_errors.MMCoreError(pm_errors.MMCoreError.CANCELLED,
                                      message))
    def _HandleRegisteredState(self):
        logging.info('ConnectCdmaMachine: Modem is REGISTERED.')
        assert not self._modem.IsPendingDisconnect()
        assert not self._modem.IsPendingEnable()
        assert not self._modem.IsPendingDisable()
        assert not self._modem.IsPendingRegister()

        # Check here that the network is activated. The UI should prevent
        # connecting to an unactivated service, but for tests, we want to be
        # sure that connect fails.
        network = self._modem.GetHomeNetwork()
        if not network.activated:
            logging.info('ConnectCdmaMachine: Service is not activated. Cannot'
                         ' connect.')
            self.raise_cb(
                pm_errors.MMCoreError(pm_errors.MMCoreError.FAILED,
                                      'Service not activated.'))
            return False

        logging.info('ConnectCdmaMachine: Setting state to CONNECTING.')
        reason = mm1_constants.MM_MODEM_STATE_CHANGE_REASON_USER_REQUESTED
        self._modem.ChangeState(mm1_constants.MM_MODEM_STATE_CONNECTING,
                                reason)
        return True
示例#25
0
    def Reset(self):
        """
        Clears non-persistent configuration and state, and returns the device to
        a newly-powered-on state.

        As a result of this operation, the modem will be removed from its
        current path and will be exposed on an incremented path. It will be
        enabled afterwards.

        """
        logging.info('Resetting modem.')

        if self.resetting:
            raise pm_errors.MMCoreError(pm_errors.MMCoreError.IN_PROGRESS,
                                        'Reset already in progress.')

        self.resetting = True

        self.CancelAllStateMachines()

        def _ResetFunc():
            # Disappear.
            manager = self.manager
            if manager:
                manager.Remove(self)
                if self.sim:
                    manager.Remove(self.sim)

            self.ClearBearers()

            # Reappear.
            def _DelayedReappear():
                self.IncrementPath()

                # Reset to defaults.
                if self.sim:
                    self.sim.Reset()
                self._properties = self._InitializeProperties()
                if self.sim:
                    self.Set(mm1_constants.I_MODEM, 'Sim',
                             dbus.types.ObjectPath(self.sim.path))
                    self.UpdateLockStatus()

                if manager:
                    manager.Add(self)

                self.resetting = False

                def _DelayedEnable():
                    state = self.Get(mm1_constants.I_MODEM, 'State')
                    if not self.IsPendingEnable() and \
                            state == mm1_constants.MM_MODEM_STATE_DISABLED:
                        self.Enable(True)
                    return False

                gobject.timeout_add(1000, _DelayedEnable)
                return False

            gobject.timeout_add(2000, _DelayedReappear)

        def _ErrorCallback(error):
            raise error

        if (self.Get(mm1_constants.I_MODEM,
                     'State') == mm1_constants.MM_MODEM_STATE_CONNECTED):
            self.Disconnect('/', _ResetFunc, _ErrorCallback)
        else:
            gobject.idle_add(_ResetFunc)