shill

package
v0.0.0-...-683b059 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 23, 2022 License: BSD-3-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package shill provides D-Bus wrappers and utilities for shill service.

Index

Constants

View Source
const (
	EnableWaitTime = 500 * time.Millisecond
)

Exported constants

Variables

This section is empty.

Functions

func WaitForOnline

func WaitForOnline(ctx context.Context) error

WaitForOnline waits for Internet connectivity, a shorthand which is useful so external packages don't have to worry about Shill details (e.g., Service, Manager). Tests that require Internet connectivity (e.g., for a real GAIA login) need to ensure that before trying to perform Internet requests. This function is one way to do that. Returns an error if we don't come back online within a reasonable amount of time.

func WifiInterface

func WifiInterface(ctx context.Context, m *Manager, timeout time.Duration) (string, error)

WifiInterface polls the WiFi interface name with timeout. It returns "" with error if no (or more than one) WiFi interface is found.

Types

type Device

type Device struct {
	*PropertyHolder
}

Device wraps a Device D-Bus object in shill.

func NewDevice

func NewDevice(ctx context.Context, path dbus.ObjectPath) (*Device, error)

NewDevice connects to shill's Device. It also obtains properties after device creation.

func (*Device) ChangePin

func (d *Device) ChangePin(ctx context.Context, oldPin, newPin string) error

ChangePin changes the PIN used to unlock a SIM card, The existing PIN must be provided along with the new PIN.

func (*Device) Disable

func (d *Device) Disable(ctx context.Context) error

Disable disables the device.

func (*Device) Enable

func (d *Device) Enable(ctx context.Context) error

Enable enables the device.

func (*Device) EnterPin

func (d *Device) EnterPin(ctx context.Context, pin string) error

EnterPin is to lock/unlock a SIM card with given PIN.

func (*Device) RequestRoam

func (d *Device) RequestRoam(ctx context.Context, bssid string) error

RequestRoam requests that we roam to the specified BSSID. Note: this operation assumes that: 1- We are connected to an SSID for which |bssid| is a member. 2- There is a BSS with an appropriate ID in our scan results.

func (*Device) RequirePin

func (d *Device) RequirePin(ctx context.Context, pin string, require bool) error

RequirePin enables/disables SIM PIN based on required value.

func (*Device) Reset

func (d *Device) Reset(ctx context.Context) error

Reset resets underlying modem.

func (*Device) SetUsbEthernetMacAddressSource

func (d *Device) SetUsbEthernetMacAddressSource(ctx context.Context, source string) error

SetUsbEthernetMacAddressSource sets USB Ethernet MAC address source for the device.

func (*Device) UnblockPin

func (d *Device) UnblockPin(ctx context.Context, pukCode, newPin string) error

UnblockPin used to unblock the locked sim with puk code.

func (*Device) WaitForSelectedService

func (d *Device) WaitForSelectedService(ctx context.Context, timeout time.Duration) (dbus.ObjectPath, error)

WaitForSelectedService returns the first valid value (i.e., not "/") of the "SelectedService" property.

type IPConfig

type IPConfig struct {
	*PropertyHolder
}

IPConfig wraps an IPConfig D-Bus object in shill.

func NewIPConfig

func NewIPConfig(ctx context.Context, path dbus.ObjectPath) (*IPConfig, error)

NewIPConfig connects to an IPConfig in Shill.

type Manager

type Manager struct {
	*PropertyHolder
}

Manager wraps a Manager D-Bus object in shill.

func NewManager

func NewManager(ctx context.Context) (*Manager, error)

NewManager connects to shill's Manager.

func (*Manager) ActiveProfile

func (m *Manager) ActiveProfile(ctx context.Context) (*Profile, error)

ActiveProfile returns the active profile.

func (*Manager) ConfigureService

func (m *Manager) ConfigureService(ctx context.Context, props map[string]interface{}) (dbus.ObjectPath, error)

ConfigureService configures a service with the given properties and returns its path.

func (*Manager) ConfigureServiceForProfile

func (m *Manager) ConfigureServiceForProfile(ctx context.Context, path dbus.ObjectPath, props map[string]interface{}) (dbus.ObjectPath, error)

ConfigureServiceForProfile configures a service at the given profile path.

func (*Manager) CreateProfile

func (m *Manager) CreateProfile(ctx context.Context, name string) (dbus.ObjectPath, error)

CreateProfile creates a profile.

func (*Manager) DeviceByName

func (m *Manager) DeviceByName(ctx context.Context, iface string) (*Device, error)

DeviceByName returns the Device matching the given interface name.

func (*Manager) DeviceByType

func (m *Manager) DeviceByType(ctx context.Context, deviceType string) (*Device, error)

DeviceByType returns a device matching |type| or a "Device not found" error.

func (*Manager) Devices

func (m *Manager) Devices(ctx context.Context) ([]*Device, error)

Devices returns a list of devices.

func (*Manager) DevicesByTechnology

func (m *Manager) DevicesByTechnology(ctx context.Context, technology Technology) ([]*Device, []*dbusutil.Properties, error)

DevicesByTechnology returns list of Devices and their Properties snapshots of the specified technology.

func (*Manager) DisableTechnology

func (m *Manager) DisableTechnology(ctx context.Context, technology Technology) error

DisableTechnology disables a technology interface.

func (*Manager) DisableTechnologyForTesting

func (m *Manager) DisableTechnologyForTesting(ctx context.Context, technology Technology) (func(ctx context.Context), error)

DisableTechnologyForTesting first checks whether |technology| is enabled. If it is enabled, it disables the technology and returns a callback that can be deferred to re-enable the technology when the test completes. (The callback should take a contexted shortened by shill.EnableWaitTime). If the technology is already enabled, no work is done and a nil callback is returned

func (*Manager) EnableTechnology

func (m *Manager) EnableTechnology(ctx context.Context, technology Technology) error

EnableTechnology enables a technology interface.

func (*Manager) FindMatchingService

func (m *Manager) FindMatchingService(ctx context.Context, expectProps map[string]interface{}) (*Service, error)

FindMatchingService returns the first Service that matches |expectProps|. If no matching Service is found, returns shillconst.ErrorMatchingServiceNotFound. Note that the complete list of Services is searched, including those with Visible=false. To find only visible services, please specify Visible=true in expectProps.

func (*Manager) GetDebugLevel

func (m *Manager) GetDebugLevel(ctx context.Context) (int, error)

GetDebugLevel gets the enabled debug level.

func (*Manager) GetDebugTags

func (m *Manager) GetDebugTags(ctx context.Context) ([]string, error)

GetDebugTags gets the list of enabled debug tags. The list is represented as a string of tag names separated by "+".

func (*Manager) GetEnabledTechnologies

func (m *Manager) GetEnabledTechnologies(ctx context.Context) ([]Technology, error)

GetEnabledTechnologies returns a list of all enabled shill networking technologies.

func (*Manager) IsAvailable

func (m *Manager) IsAvailable(ctx context.Context, technology Technology) (bool, error)

IsAvailable returns true if a technology is available.

func (*Manager) IsEnabled

func (m *Manager) IsEnabled(ctx context.Context, technology Technology) (bool, error)

IsEnabled returns true if a technology is enabled.

func (*Manager) PopAllUserProfiles

func (m *Manager) PopAllUserProfiles(ctx context.Context) error

PopAllUserProfiles removes all user profiles from the stack of managed profiles leaving only default profiles.

func (*Manager) PopProfile

func (m *Manager) PopProfile(ctx context.Context, name string) error

PopProfile pops the profile with the given name if it is on top of the stack.

func (*Manager) ProfilePaths

func (m *Manager) ProfilePaths(ctx context.Context) ([]dbus.ObjectPath, error)

ProfilePaths returns a list of profile paths.

func (*Manager) Profiles

func (m *Manager) Profiles(ctx context.Context) ([]*Profile, error)

Profiles returns a list of profiles.

func (*Manager) PushProfile

func (m *Manager) PushProfile(ctx context.Context, name string) (dbus.ObjectPath, error)

PushProfile pushes a profile.

func (*Manager) RecheckPortal

func (m *Manager) RecheckPortal(ctx context.Context) error

RecheckPortal requests shill to rerun its captive portal detector.

func (*Manager) RemoveProfile

func (m *Manager) RemoveProfile(ctx context.Context, name string) error

RemoveProfile removes the profile with the given name.

func (*Manager) RequestScan

func (m *Manager) RequestScan(ctx context.Context, technology Technology) error

RequestScan requests a scan for the specified technology.

func (*Manager) SetDebugLevel

func (m *Manager) SetDebugLevel(ctx context.Context, level int) error

SetDebugLevel sets the debugging level.

func (*Manager) SetDebugTags

func (m *Manager) SetDebugTags(ctx context.Context, tags []string) error

SetDebugTags sets the debug tags that are enabled for logging. "tags" is a list of valid tag names separated by "+". Shill silently ignores invalid flags.

func (*Manager) WaitForDeviceByName

func (m *Manager) WaitForDeviceByName(ctx context.Context, iface string, timeout time.Duration) (*Device, error)

WaitForDeviceByName returns the Device matching the given interface name. If there's no match, it waits until one appears, or until timeout.

func (*Manager) WaitForServiceProperties

func (m *Manager) WaitForServiceProperties(ctx context.Context, expectProps map[string]interface{}, timeout time.Duration) (*Service, error)

WaitForServiceProperties returns the first matching Service who has the expected properties. If there's no matching service, it polls until timeout is reached. Noted that it searches all services including Visible=false ones. To focus on visible services, please specify Visible=true in expectProps.

type Profile

type Profile struct {
	*PropertyHolder
}

Profile wraps a Profile D-Bus object in shill.

func NewProfile

func NewProfile(ctx context.Context, path dbus.ObjectPath) (*Profile, error)

NewProfile connects to a profile in Shill.

func (*Profile) DeleteEntry

func (p *Profile) DeleteEntry(ctx context.Context, entryID string) error

DeleteEntry calls the DeleteEntry method on the profile.

func (*Profile) GetEntry

func (p *Profile) GetEntry(ctx context.Context, entryID string) (map[string]interface{}, error)

GetEntry calls the GetEntry method on the profile.

type PropertiesWatcher

type PropertiesWatcher struct {
	// contains filtered or unexported fields
}

PropertiesWatcher watches for Shill "PropertyChanged" signals.

func NewPropertiesWatcher

func NewPropertiesWatcher(ctx context.Context, obj *dbusutil.DBusObject) (*PropertiesWatcher, error)

NewPropertiesWatcher returns a PropertiesWatcher to observe the shill specific "PropertyChanged" signal.

func (*PropertiesWatcher) Close

func (pw *PropertiesWatcher) Close(ctx context.Context) error

Close stops watching for signals.

func (*PropertiesWatcher) Expect

func (pw *PropertiesWatcher) Expect(ctx context.Context, prop string, expected interface{}) error

Expect waits for the expected value of a given property.

func (*PropertiesWatcher) ExpectIn

func (pw *PropertiesWatcher) ExpectIn(ctx context.Context, prop string, expected []interface{}) (interface{}, error)

ExpectIn expects the prop's value to become one of the expected values and returns the first matched one.

func (*PropertiesWatcher) Wait

func (pw *PropertiesWatcher) Wait(ctx context.Context) (string, interface{}, dbus.Sequence, error)

Wait waits for "PropertyChanged" signal and updates corresponding property value.

func (*PropertiesWatcher) WaitAll

func (pw *PropertiesWatcher) WaitAll(ctx context.Context, props ...string) ([]interface{}, error)

WaitAll waits for all expected properties were shown on at least one "PropertyChanged" signal and returns the last updated value of each property.

type PropertyHolder

type PropertyHolder struct {
	*dbusutil.PropertyHolder
}

PropertyHolder provides methods to access properties of shill via D-Bus. The interface for property get/set in shill is different from the general org.freedesktop.DBus.Properties, so we'll need to overwrite the {Get,Set}Properties, while the other utilities provided by dbusutil can still be reused.

func NewPropertyHolder

func NewPropertyHolder(ctx context.Context, service, iface string, path dbus.ObjectPath) (*PropertyHolder, error)

NewPropertyHolder creates a shill DBus object with the given service, interface and path which can be used for accessing and setting properties.

func (*PropertyHolder) CreateWatcher

func (h *PropertyHolder) CreateWatcher(ctx context.Context) (*PropertiesWatcher, error)

CreateWatcher returns a PropertiesWatcher to observe the object's "PropertyChanged" signal.

func (*PropertyHolder) GetAndSetProperty

func (h *PropertyHolder) GetAndSetProperty(ctx context.Context, prop string, value interface{}) (interface{}, error)

GetAndSetProperty returns the current value of a property and sets the property to a new value.

func (*PropertyHolder) GetProperties

func (h *PropertyHolder) GetProperties(ctx context.Context) (*dbusutil.Properties, error)

GetProperties calls GetProperties method of shill and return properties of the object.

func (*PropertyHolder) GetShillProperties

func (h *PropertyHolder) GetShillProperties(ctx context.Context) (*dbusutil.Properties, error)

GetShillProperties calls GetProperties method of shill and return properties of the object. Deprecated: use GetProperties instead.

func (*PropertyHolder) SetProperty

func (h *PropertyHolder) SetProperty(ctx context.Context, prop string, value interface{}) error

SetProperty calls SetProperties method of shill to set a property of the object.

func (*PropertyHolder) WaitForProperty

func (h *PropertyHolder) WaitForProperty(ctx context.Context, property string, expected interface{}, timeout time.Duration) error

WaitForProperty polls for the specified Shill property state to match |expected|.

func (*PropertyHolder) WaitForShillProperty

func (h *PropertyHolder) WaitForShillProperty(ctx context.Context, property string, expected interface{}, timeout time.Duration) error

WaitForShillProperty polls for the specified Shill property state to match |expected| Deprecated: use WaitForProperty instead.

type Service

type Service struct {
	*PropertyHolder
}

Service wraps a Service D-Bus object in shill.

func NewService

func NewService(ctx context.Context, path dbus.ObjectPath) (*Service, error)

NewService connects to a service in Shill.

func (*Service) Connect

func (s *Service) Connect(ctx context.Context) error

Connect calls the Connect method on the service.

func (*Service) Disconnect

func (s *Service) Disconnect(ctx context.Context) error

Disconnect calls the Disconnect method on the service.

func (*Service) GetDevice

func (s *Service) GetDevice(ctx context.Context) (*Device, error)

GetDevice returns the Device object corresponding to the Service object

func (*Service) GetSignalStrength

func (s *Service) GetSignalStrength(ctx context.Context) (uint8, error)

GetSignalStrength return the current signal strength

func (*Service) IsConnected

func (s *Service) IsConnected(ctx context.Context) (bool, error)

IsConnected returns true if the the service is connected.

func (*Service) Remove

func (s *Service) Remove(ctx context.Context) error

Remove calls the Remove method on the service.

func (*Service) WaitForConnectedOrError

func (s *Service) WaitForConnectedOrError(ctx context.Context) error

WaitForConnectedOrError polls for either: * Service.IsConnected to be true, in which case nil is returned. * Service.Error to be set to an error value, in which case that is returned as an error. Any failure also returns an error.

type Technology

type Technology string

Technology is the type of a shill device's technology

type WifiManager

type WifiManager struct {
	// contains filtered or unexported fields
}

WifiManager manages WiFi services, profiles, and devices through shill Manager.

func NewWifiManager

func NewWifiManager(ctx context.Context, m *Manager) (*WifiManager, error)

NewWifiManager makes sure WiFi interface is available and returns WiFi Manager.

func (*WifiManager) APConnected

func (wifi *WifiManager) APConnected(ctx context.Context, ssid string) (bool, error)

APConnected returns true if the given WiFi AP is connected.

func (*WifiManager) ConnectAP

func (wifi *WifiManager) ConnectAP(ctx context.Context, ssid, passphrase string) error

ConnectAP connects to a given WiFi AP identified by SSID.

func (*WifiManager) Connected

func (wifi *WifiManager) Connected(ctx context.Context) (bool, error)

Connected returns true if any WiFi AP is connected.

func (*WifiManager) Enable

func (wifi *WifiManager) Enable(ctx context.Context, enable bool) error

Enable enables or disables the WiFi network according to the given enable flag.

func (*WifiManager) ForgetAP

func (wifi *WifiManager) ForgetAP(ctx context.Context, ssid string) error

ForgetAP removes the WiFi AP from user profile.

func (*WifiManager) Interface

func (wifi *WifiManager) Interface(ctx context.Context) (string, error)

Interface returns the WiFi interface name.

func (*WifiManager) SetTimeout

func (wifi *WifiManager) SetTimeout(t time.Duration)

SetTimeout sets the WiFi manager timeout value for all WiFi operations.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL