provision

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 11 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package provision defines USB-only network configuration and its flash journal.

Index

Constants

View Source
const (
	RequestSize  = 512
	ResponseSize = 512
)
View Source
const (
	MaxSSID       = 32
	MaxPassphrase = 63
	MaxManager    = 255
	MaxTimezone   = 64
)
View Source
const RecordSize = 512

Variables

View Source
var (
	ErrBlank   = errors.New("provision: blank")
	ErrCorrupt = errors.New("provision: corrupt")
	ErrStorage = errors.New("provision: invalid storage")
)
View Source
var ErrInvalidConfig = errors.New("provision: invalid configuration")
View Source
var ErrInvalidState = errors.New("provision: invalid state transition")

Functions

func EncodeRequest

func EncodeRequest(dst []byte, request Request) error

func EncodeResponse

func EncodeResponse(dst []byte, response Response) error

func ValidESP32Endpoint added in v0.3.0

func ValidESP32Endpoint(endpoint string) bool

ValidESP32Endpoint admits the same literal TCP DNS/IPv4 endpoint as the receiver.

Types

type AuthMode

type AuthMode uint8
const AuthWPA2PSK AuthMode = 2
const AuthWPA3SAE AuthMode = 1

type BlockDevice

type BlockDevice interface {
	io.ReaderAt
	io.WriterAt
	Size() int64
	WriteBlockSize() int64
	EraseBlockSize() int64
	EraseBlocks(start, length int64) error
}

type Code

type Code uint8

Code is a stable, source-free USB result. State describes the authoritative journal read after the operation, including when Code reports a failed write.

const (
	CodeOK Code = iota
	CodeConfiguration
	CodeState
	CodeStorage
	CodeBusy
	CodeRecovery // Boot lifetime unavailable; physical erase then reboot required.
)

type Codec

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

Codec selects one explicit board's admission policy. Its zero value retains Pico's WPA3-only contract; an ESP32 policy never affects device flash decoding.

func ESP32Codec

func ESP32Codec() Codec

func (Codec) AuthMode

func (c Codec) AuthMode() AuthMode

func (Codec) DecodeCorrelatedResponse

func (codec Codec) DecodeCorrelatedResponse(src []byte, id RequestID) (Response, error)

DecodeCorrelatedResponse validates the v3 envelope before applying all v2 metadata and padding rules. A legacy/stale reply never acknowledges v3 work.

func (Codec) DecodeRequest

func (codec Codec) DecodeRequest(source []byte) (Request, error)

func (Codec) DecodeResponse

func (codec Codec) DecodeResponse(source []byte) (Response, error)

func (Codec) EncodeCorrelatedRequest

func (codec Codec) EncodeCorrelatedRequest(dst []byte, request Request, id RequestID) error

EncodeCorrelatedRequest adds the ESP32 v3 envelope; stored EPC2 stays unchanged.

func (Codec) EncodeRequest

func (codec Codec) EncodeRequest(destination []byte, request Request) error

func (Codec) EncodeResponse

func (codec Codec) EncodeResponse(destination []byte, response Response) error

type Config

type Config struct {
	SSID       string
	Passphrase string
	Manager    string
	Timezone   string
	DeviceID   [16]byte
	DeviceKey  [32]byte
	Auth       AuthMode
}

func (Config) Validate

func (c Config) Validate() error

func (Config) ValidateFor

func (c Config) ValidateFor(codec Codec) error

type ManagerChange added in v0.3.0

type ManagerChange struct {
	DeviceID   [16]byte
	Generation uint64
	Endpoint   string
}

ManagerChange replaces one endpoint on the exact journal snapshot inspected over USB. It contains no Wi-Fi credentials or device key.

type Operation

type Operation uint8
const (
	OperationInspect Operation = iota + 1
	OperationProvision
	OperationRotate
	OperationErase
	OperationDiagnose
	OperationSetManager     // ESP32 correlated USB only; never valid on the v2 wire.
	OperationInspectManager // Read-only feature probe for endpoint-only updates.
)

type Request

type Request struct {
	Operation Operation
	Config    Config
	Change    ManagerChange
}

func DecodeRequest

func DecodeRequest(src []byte) (Request, error)

type RequestID

type RequestID [16]byte

RequestID binds a physical USB reply to one attempt, not a retryable intent. It is neither authentication nor a durable idempotency key.

type Response

type Response struct {
	Operation  Operation
	Code       Code
	State      State
	Generation uint64
	Auth       AuthMode
	DeviceID   [16]byte
	SSID       string
	Manager    string
	Timezone   string
}

func DecodeResponse

func DecodeResponse(src []byte) (Response, error)

type Service

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

func NewService

func NewService(store *Store) (*Service, error)

func (*Service) Execute

func (s *Service) Execute(request Request) (Response, error)

func (*Service) Report

func (s *Service) Report(request Request) (Response, Config)

Report executes once, then reloads the journal even after an error. Save may fail after writing a valid slot; FactoryReset can erase only one of two slots before failure. Only the reload, never the requested config, is authoritative. Physical USB ownership/credential fencing belongs to the caller. Config contains secrets for the owner; only Response may be serialized.

func (*Service) Snapshot

func (s *Service) Snapshot(operation Operation) (Response, Config)

Snapshot is read-only. Unknown means an I/O failure, not an erased journal.

type State

type State uint8
const (
	StateBlank State = iota
	StateProvisioned
	StateCorrupt
	StateUnknown // The journal could not be read; never infer Blank after I/O failure.
)

type Store

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

func NewStore

func NewStore(device BlockDevice, start int64) (*Store, error)

func (*Store) FactoryReset

func (s *Store) FactoryReset() error

func (*Store) Load

func (s *Store) Load() (Config, uint64, error)

func (*Store) Save

func (s *Store) Save(config Config) (uint64, error)

Jump to

Keyboard shortcuts

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