provisioning

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2024 License: AGPL-3.0 Imports: 30 Imported by: 0

Documentation

Overview

Package provisioning is the subsystem responsible for network/wifi management, and initial device setup via hotspot.

Index

Constants

View Source
const (
	SubsysName = "agent-provisioning"

	DNSMasqFilepath          = "/etc/NetworkManager/dnsmasq-shared.d/80-viam.conf"
	DNSMasqContentsRedirect  = "address=/#/10.42.0.1\n"
	DNSMasqContentsSetupOnly = "address=/.setup/10.42.0.1\n"

	PortalBindAddr = "10.42.0.1"

	ConnCheckFilepath = "/etc/NetworkManager/conf.d/80-viam.conf"
	ConnCheckContents = "[connectivity]\nuri=http://packages.viam.com/check_network_status.txt\ninterval=300\n"

	NetworkTypeWifi    = "wifi"
	NetworkTypeWired   = "wired"
	NetworkTypeHotspot = "hotspot"

	IfNameAny = "any"

	HealthCheckTimeout = time.Minute
)

Variables

View Source
var (
	DefaultConf = Config{
		Manufacturer:       "viam",
		Model:              "custom",
		FragmentID:         "",
		HotspotPrefix:      "viam-setup",
		HotspotPassword:    "viamsetup",
		DisableDNSRedirect: false,
		RoamingMode:        false,
		OfflineTimeout:     Timeout(time.Minute * 2),
		UserTimeout:        Timeout(time.Minute * 5),
		FallbackTimeout:    Timeout(time.Minute * 10),
		Networks:           []NetworkConfig{},
	}

	// Can be overwritten via cli arguments.
	AppConfigFilePath          = "/etc/viam.json"
	ProvisioningConfigFilePath = "/etc/viam-provisioning.json"

	ErrBadPassword             = errors.New("bad or missing password")
	ErrConnCheckDisabled       = errors.New("NetworkManager connectivity checking disabled by user, network management will be unavailable")
	ErrNoActiveConnectionFound = errors.New("no active connection found")
)

Functions

func NetworkInfoToProto added in v0.9.0

func NetworkInfoToProto(net *NetworkInfo) *pb.NetworkInfo

func NewConnectionState added in v0.9.0

func NewConnectionState(logger logging.Logger) *connectionState

func NewNetworkState added in v0.9.0

func NewNetworkState(logger logging.Logger) *networkState

func NewProvisioning added in v0.9.0

func NewProvisioning(ctx context.Context, logger logging.Logger, updateConf *agentpb.DeviceSubsystemConfig) (subsystems.Subsystem, error)

func WriteDeviceConfig added in v0.9.0

func WriteDeviceConfig(file string, input userInput) error

Types

type CloudConfig added in v0.9.0

type CloudConfig struct {
	AppAddress string `json:"app_address"`
	ID         string `json:"id"`
	Secret     string `json:"secret"`
}

type Config added in v0.9.0

type Config struct {
	// Things typically set in agent-provisioning.json
	Manufacturer string `json:"manufacturer"`
	Model        string `json:"model"`
	FragmentID   string `json:"fragment_id"`

	// The interface to use for hotspot/provisioning/wifi management. Ex: "wlan0"
	// Defaults to the first discovered 802.11 device
	HotspotInterface string `json:"hotspot_interface"`
	// The prefix to prepend to the hotspot name.
	HotspotPrefix string `json:"hotspot_prefix"`
	// Password required to connect to the hotspot.
	HotspotPassword string `json:"hotspot_password"`
	// If true, mobile (phone) users connecting to the hotspot won't be automatically redirected to the web portal.
	DisableDNSRedirect bool `json:"disable_dns_redirect"`

	// How long without a connection before starting provisioning (hotspot) mode.
	OfflineTimeout Timeout `json:"offline_timeout"`

	// How long since the last user interaction (via GRPC/app or web portal) before the state machine can resume.
	UserTimeout Timeout `json:"user_timeout"`

	// If not "online", always drop out of hotspot mode and retry everything after this time limit.
	FallbackTimeout Timeout `json:"fallback_timeout"`

	// When true, will try all known networks looking for internet (global) connectivity.
	// Otherwise, will only try the primary wifi network and consider that sufficient if connected (regardless of global connectivity.)
	RoamingMode bool `json:"roaming_mode"`

	// Additional networks to add/configure. Only useful in RoamingMode.
	Networks []NetworkConfig `json:"networks"`
	// contains filtered or unexported fields
}

Config represents the json configurations parsed from either agent-provisioning.json OR passed from the "attributes" in the cloud config.

func ConfigFromJSON added in v0.9.0

func ConfigFromJSON(defaultConf Config, jsonBytes []byte) (*Config, error)

func LoadConfig added in v0.9.0

func LoadConfig(updateConf *agentpb.DeviceSubsystemConfig) (*Config, error)

type MachineConfig added in v0.9.0

type MachineConfig struct {
	Cloud *CloudConfig `json:"cloud"`
}

MachineConfig represents the minimal needed for /etc/viam.json.

type NetworkConfig added in v0.9.0

type NetworkConfig struct {
	// "wifi", "wired", "wifi-static", "wired-static"
	Type string `json:"type"`

	// name of interface, ex: "wlan0", "eth0", "enp14s0", etc.
	Interface string `json:"interface"`

	// Wifi Settings
	SSID string `json:"ssid"`
	PSK  string `json:"psk"`

	// Autoconnect Priority (primarily for wifi)
	// higher values are preferred/tried first
	// defaults to 0, but wifi networks added via hotspot are set to 999 when not in roaming mode
	Priority int32 `json:"priority"`

	// CIDR format address, ex: 192.168.0.1/24
	// If unset, will default to "auto" (dhcp)
	IPv4Address string `json:"ipv4_address"`
	IPv4Gateway string `json:"ipv4_gateway"`

	// optional
	IPv4DNS []string `json:"ipv4_dns"`

	// optional, 0 or -1 is default
	// lower values are preferred (lower "cost")
	// wired networks default to 100
	// wireless networks default to 600
	IPv4RouteMetric int64 `json:"ipv4_route_metric"`
}

type NetworkInfo added in v0.9.0

type NetworkInfo struct {
	Type      string
	SSID      string
	Security  string
	Signal    int32
	Connected bool
	LastError string
}

func NetworkInfoFromProto added in v0.9.0

func NetworkInfoFromProto(buf *pb.NetworkInfo) *NetworkInfo

type Provisioning added in v0.9.0

type Provisioning struct {
	AppCfgPath string

	pb.UnimplementedProvisioningServiceServer
	// contains filtered or unexported fields
}

func (*Provisioning) ActivateConnection added in v0.9.0

func (w *Provisioning) ActivateConnection(ctx context.Context, ifName, ssid string) error

func (*Provisioning) AddOrUpdateConnection added in v0.9.0

func (w *Provisioning) AddOrUpdateConnection(cfg NetworkConfig) (bool, error)

func (*Provisioning) Config added in v0.9.0

func (w *Provisioning) Config() Config

func (*Provisioning) DeactivateConnection added in v0.9.0

func (w *Provisioning) DeactivateConnection(ifName, ssid string) error

func (*Provisioning) GetNetworkList added in v0.9.0

func (*Provisioning) GetSmartMachineStatus added in v0.9.0

func (*Provisioning) HealthCheck added in v0.9.0

func (w *Provisioning) HealthCheck(ctx context.Context) error

HealthCheck reports if a subsystem is running correctly (it is restarted if not).

func (*Provisioning) SetNetworkCredentials added in v0.9.0

func (*Provisioning) SetSmartMachineCredentials added in v0.9.0

func (*Provisioning) Start added in v0.9.0

func (w *Provisioning) Start(ctx context.Context) error

func (*Provisioning) StartProvisioning added in v0.9.0

func (w *Provisioning) StartProvisioning(ctx context.Context, inputChan chan<- userInput) error

StartProvisioning puts the wifi in hotspot mode and starts a captive portal.

func (*Provisioning) Stop added in v0.9.0

func (w *Provisioning) Stop(ctx context.Context) error

func (*Provisioning) StopProvisioning added in v0.9.0

func (w *Provisioning) StopProvisioning() error

func (*Provisioning) Update added in v0.9.0

func (w *Provisioning) Update(ctx context.Context, updateConf *agentpb.DeviceSubsystemConfig) (bool, error)

Update validates and/or updates a subsystem, returns true if subsystem should be restarted.

func (*Provisioning) Version added in v0.9.0

func (w *Provisioning) Version() string

Version returns the current version of the subsystem.

type Timeout added in v0.9.0

type Timeout time.Duration

Timeout allows parsing golang-style durations (1h20m30s) OR seconds-as-float from/to json.

func (Timeout) MarshalJSON added in v0.9.0

func (t Timeout) MarshalJSON() ([]byte, error)

func (*Timeout) UnmarshalJSON added in v0.9.0

func (t *Timeout) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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