provision

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 10 Imported by: 0

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

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 Operation

type Operation uint8
const (
	OperationInspect Operation = iota + 1
	OperationProvision
	OperationRotate
	OperationErase
	OperationDiagnose
)

type Request

type Request struct {
	Operation Operation
	Config    Config
}

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