service

package
v0.0.0-...-b320325 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2023 License: GPL-3.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	USB_EP_USAGE_HID_RAW      = 1
	USB_EP_USAGE_HID_KEYBOARD = 1
	USB_EP_USAGE_HID_MOUSE    = 1
	USB_EP_USAGE_RNDIS        = 2
	USB_EP_USAGE_CDC_ECM      = 2
	USB_EP_USAGE_CDC_SERIAL   = 2
	USB_EP_USAGE_UMS          = 2
	USB_EP_USAGE_MAX          = 7

	USB_GADGET_NAME     = "mame82_gadget"
	USB_GADGET_DIR_BASE = "/sys/kernel/config/usb_gadget"
	USB_GADGET_DIR      = USB_GADGET_DIR_BASE + "/" + USB_GADGET_NAME

	USB_bcdDevice = "0x0100" //Version 1.00
	USB_bcdUSB    = "0x0200" //mode: USB 2.0

	// composite class / subclass / proto (needs single configuration)
	USB_bDeviceClass    = "0xEF"
	USB_bDeviceSubClass = "0x02"
	USB_bDeviceProtocol = "0x01"

	USB_CONFIGURATION_MaxPower     = "250"
	USB_CONFIGURATION_bmAttributes = "0x80" //should be 0x03 for USB_OTG_SRP | USB_OTG_HNP

	//OS descriptors for RNDIS composite function on Windows
	USB_FUNCTION_RNDIS_os_desc_use                         = "1"
	USB_FUNCTION_RNDIS_os_desc_b_vendor_code               = "0xbc"
	USB_FUNCTION_RNDIS_os_desc_qw_sign                     = "MSFT100"
	USB_FUNCTION_RNDIS_os_desc_interface_compatible_id     = "RNDIS"
	USB_FUNCTION_RNDIS_os_desc_interface_sub_compatible_id = "5162001"

	//HID function, keyboard constants
	USB_FUNCTION_HID_KEYBOARD_protocol      = "1"
	USB_FUNCTION_HID_KEYBOARD_subclass      = "1"
	USB_FUNCTION_HID_KEYBOARD_report_length = "8"
	USB_FUNCTION_HID_KEYBOARD_report_desc   = "" /* 214-byte string literal not displayed */
	USB_FUNCTION_HID_KEYBOARD_name          = "hid.keyboard"

	//HID function, mouse constants
	USB_FUNCTION_HID_MOUSE_protocol      = "2"
	USB_FUNCTION_HID_MOUSE_subclass      = "1"
	USB_FUNCTION_HID_MOUSE_report_length = "6"
	USB_FUNCTION_HID_MOUSE_report_desc   = "" /* 373-byte string literal not displayed */
	USB_FUNCTION_HID_MOUSE_name          = "hid.mouse"

	//HID function, custom vendor device constants
	USB_FUNCTION_HID_RAW_protocol      = "1"
	USB_FUNCTION_HID_RAW_subclass      = "1"
	USB_FUNCTION_HID_RAW_report_length = "64"
	USB_FUNCTION_HID_RAW_report_desc   = "\x06\x00\xff\t\x01\xa1\x01\t\x01\x15\x00&\xff\x00u\x08\x95@\x81\x02\t\x02\x15\x00&\xff\x00u\x08\x95@\x91\x02\xc0"
	USB_FUNCTION_HID_RAW_name          = "hid.raw"
)
View Source
const (
	DEFAULT_CDC_ECM_HOST_ADDR = "42:63:66:12:34:56"
	DEFAULT_CDC_ECM_DEV_ADDR  = "42:63:66:56:34:12"
	DEFAULT_RNDIS_HOST_ADDR   = "42:63:65:12:34:56"
	DEFAULT_RNDIS_DEV_ADDR    = "42:63:65:56:34:12"
	USB_ETHERNET_BRIDGE_MAC   = "24:22:26:12:14:16"
	USB_ETHERNET_BRIDGE_NAME  = "usbeth"
	BT_ETHERNET_BRIDGE_MAC    = "44:22:26:12:14:16"
	BT_ETHERNET_BRIDGE_NAME   = "bteth"
	WIFI_ETHERNET_IFACE_NAME  = "wlan0"
)
View Source
const (
	LED_TRIGGER_PATH    = "/sys/class/leds/led0/trigger"
	LED_BRIGHTNESS_PATH = "/sys/class/leds/led0/brightness"
	LED_TRIGGER_MANUAL  = "none"
	LED_ON              = "0"
	LED_OFF             = "1"
	LED_DELAY_ON        = 200 * time.Millisecond
	LED_DELAY_OFF       = 200 * time.Millisecond
	LED_DELAY_PAUSE     = 500 * time.Millisecond
)
View Source
const (
	WPA_SUPPLICANT_CONNECT_TIMEOUT = time.Second * 20
	HOSTAPD_WAIT_AP_UP_TIMEOUT     = time.Second * 8
)

Variables

View Source
var (
	EGpioNotAvailable = errors.New("sub system GPIO not available")
	EGpioPinInvalid   = errors.New("invalid GPIO pin")
)
View Source
var (
	ErrTaNotFound  = errors.New("Couldn't find given TriggerAction")
	ErrTaImmutable = errors.New("Not allowed to change immutable TriggerAction")
)
View Source
var (
	ErrUsbNotUsable = errors.New("USB subsystem not available")
	ErrHidNotUsable = errors.New("HIDScript not available (mouse and keyboard disabled)")
)
View Source
var (
	ErrUnmanagedInterface = errors.New("Not a managed network interface")
)

Functions

func AddInterfaceToBridgeIfExistent

func AddInterfaceToBridgeIfExistent(bridgeName string, ifName string) (err error)

func CheckInterfaceExistence

func CheckInterfaceExistence(name string) (res bool)

ToDo: remove error part

func CheckLibComposite

func CheckLibComposite() error

depends on `lsmod` binary

func ConstructEventHID

func ConstructEventHID(hidEvent hid.Event) *pb.Event

func ConstructEventLog

func ConstructEventLog(source string, level LogLevel, message string) *pb.Event

func ConstructEventNotifyStateChange

func ConstructEventNotifyStateChange(stateType common_web.EvtStateChangeType) *pb.Event

func ConstructEventTrigger

func ConstructEventTrigger(triggerType common_web.EvtTriggerType) *pb.Event

We add the Triggers to the oneof Values in proto later on (as they could carry arguments)

func ConstructEventTriggerDHCPLease

func ConstructEventTriggerDHCPLease(iface, mac, ip string, hostname string) *pb.Event

func ConstructEventTriggerGpioIn

func ConstructEventTriggerGpioIn(gpioName string, level bool) *pb.Event

func ConstructEventTriggerGroupReceive

func ConstructEventTriggerGroupReceive(groupName string, value int32) *pb.Event

func ConstructEventTriggerSSHLogin

func ConstructEventTriggerSSHLogin(username string) *pb.Event

func CreateBridge

func CreateBridge(name string) (err error)

func DHCPCreateConfigFile

func DHCPCreateConfigFile(s *pb.DHCPServerSettings, filename string) (err error)

func DHCPCreateConfigFileString

func DHCPCreateConfigFileString(s *pb.DHCPServerSettings) (config string, err error)

func DeconstructEventTriggerGpioIn

func DeconstructEventTriggerGpioIn(evt *pb.Event) (gpioName string, level bool, err error)

func DeconstructEventTriggerGroupReceive

func DeconstructEventTriggerGroupReceive(evt *pb.Event) (groupName string, value int32, err error)

func DeleteBridge

func DeleteBridge(name string) error

func GetDefaultBluetoothSettings

func GetDefaultBluetoothSettings() *pb.BluetoothSettings

func GetDefaultDHCPConfigBluetooth

func GetDefaultDHCPConfigBluetooth() (settings *pb.DHCPServerSettings)

Important: An Android device wants to see a valid gateway+DNS in order to get bluetooth networking workable (otherwise no follow up communication would be possible, after the DHCP lease is assigned, according to my tests). If this condition is full filled, there seems to be no need for a real upstream connection, in order to reach the gateway IP (accessing P4wnP1 is possible in this case.

func GetDefaultDHCPConfigUSB

func GetDefaultDHCPConfigUSB() (settings *pb.DHCPServerSettings)

func GetDefaultDHCPConfigWiFi

func GetDefaultDHCPConfigWiFi() (settings *pb.DHCPServerSettings)

func GetDefaultGadgetSettings

func GetDefaultGadgetSettings() (res pb.GadgetSettings)

Note: If no single function is enabled, the gadget mustn't be enabled itself in order to be deployable

func GetDefaultLEDSettings

func GetDefaultLEDSettings() (res *pb.LEDSettings)

func GetDefaultNetworkSettingsBluetooth

func GetDefaultNetworkSettingsBluetooth() *pb.EthernetInterfaceSettings

func GetDefaultNetworkSettingsUSB

func GetDefaultNetworkSettingsUSB() *pb.EthernetInterfaceSettings

func GetDefaultNetworkSettingsWiFi

func GetDefaultNetworkSettingsWiFi() *pb.EthernetInterfaceSettings

func IpNetFromIPv4AndNetmask

func IpNetFromIPv4AndNetmask(ipv4 string, netmask string) (*net.IPNet, error)

func ListFilesOfFolder

func ListFilesOfFolder(folderPath string, allowedExtensions ...string) (res []string, err error)

func MatchGivenBBSToScanResult

func MatchGivenBBSToScanResult(scanRes []BSS, targets []*pb.WiFiBSSCfg) (matches []*pb.WiFiBSSCfg)

func MountUMSFile

func MountUMSFile(filename string) error

This command is working on the active gadget directly, so changes aren't reflected back to the GadgetSettingsState

func NameConfigFileDHCPSrv

func NameConfigFileDHCPSrv(nameIface string) string

func NetworkLinkUp

func NetworkLinkUp(name string) (err error)

func NewDnsmasqLeaseMonitor

func NewDnsmasqLeaseMonitor(nim *NetworkInterfaceManager) *dnsmasqLeaseMonitor

func NewHostapdOutMonitor

func NewHostapdOutMonitor() *hostapdOutMonitor

func NewRpcServerService

func NewRpcServerService(root *Service) *server

func NewWpaSupplicantOutMonitor

func NewWpaSupplicantOutMonitor() *wpaSupplicantOutMonitor

func ParseIPv4Mask

func ParseIPv4Mask(maskstr string) (net.IPMask, error)

func ProcSoftKill

func ProcSoftKill(cmd *exec.Cmd, timeToKill time.Duration) (err error)

func SetBridgeForwardDelay

func SetBridgeForwardDelay(name string, fd uint) (err error)

func SetBridgeSTP

func SetBridgeSTP(name string, stp_on bool) (err error)

Uses sysfs (not IOCTL)

func ValidateGadgetSetting

func ValidateGadgetSetting(gs *pb.GadgetSettings) error

Types

type BSS

type BSS struct {
	SSID           string
	BSSID          net.HardwareAddr
	Frequency      int
	BeaconInterval time.Duration //carefull, on IE level beacon interval isn't measured in milliseconds
	AuthMode       WiFiAuthMode
	Signal         float32 //Signal strength in dBm
}

func ParseIwScan

func ParseIwScan(scanresult string) (bsslist []BSS, err error)

ToDo: Create netlink based implementation (not relying on 'iw'): low priority

func WifiScan

func WifiScan(ifName string) (result []BSS, err error)

type DhcpLease

type DhcpLease struct {
	Release bool
	Iface   string
	Ip      net.IP
	Mac     net.HardwareAddr
	Host    string //only used for lease, not release
}

type EventManager

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

func NewEventManager

func NewEventManager(queueSize int) *EventManager

func (*EventManager) Emit

func (em *EventManager) Emit(event *pb.Event)

func (*EventManager) RegisterReceiver

func (em *EventManager) RegisterReceiver(filterEventType int64) *EventReceiver

func (*EventManager) Start

func (evm *EventManager) Start()

func (*EventManager) Stop

func (evm *EventManager) Stop()

func (*EventManager) UnregisterReceiver

func (em *EventManager) UnregisterReceiver(receiver *EventReceiver)

func (*EventManager) Write

func (em *EventManager) Write(p []byte) (n int, err error)

type EventReceiver

type EventReceiver struct {
	Ctx             context.Context
	Cancel          context.CancelFunc
	EventQueue      chan *pb.Event
	FilterEventType int64
	// contains filtered or unexported fields
}

type GpioManager

type GpioManager struct {
	IsUsable bool

	*periph.State
	// contains filtered or unexported fields
}

func NewGpioManager

func NewGpioManager(rootSvc *Service) (res *GpioManager)

func (*GpioManager) DeployGpioTrigger

func (gm *GpioManager) DeployGpioTrigger(in *pb.TriggerGPIOIn) (err error)

func (*GpioManager) FireGpioAction

func (gm *GpioManager) FireGpioAction(out *pb.ActionGPIOOut) (err error)

func (*GpioManager) GetAvailableGpioNames

func (gm *GpioManager) GetAvailableGpioNames() (res []string, err error)

func (*GpioManager) GetAvailableGpios

func (gm *GpioManager) GetAvailableGpios() (res []*pgpio.P4wnp1PinIO, err error)

func (*GpioManager) ResetPins

func (gm *GpioManager) ResetPins()

func (*GpioManager) Start

func (gm *GpioManager) Start()

func (*GpioManager) Stop

func (gm *GpioManager) Stop()

type LedService

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

func NewLedService

func NewLedService() (res *LedService)

func (*LedService) DeploySettings

func (l *LedService) DeploySettings(sets *pb.LEDSettings)

func (*LedService) GetState

func (l *LedService) GetState() *LedState1

func (LedService) LoadSettings

func (LedService) LoadSettings()

func (*LedService) Start

func (l *LedService) Start() error

func (*LedService) Stop

func (l *LedService) Stop()

func (LedService) StoreSettings

func (LedService) StoreSettings()

type LedState

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

func NewLed

func NewLed(led_on bool) (ledState *LedState, err error)

var (

blink_count uint32 = 0

)

func (*LedState) GetLed

func (leds *LedState) GetLed() (res *pb.LEDSettings, err error)

func (*LedState) SetLed

func (leds *LedState) SetLed(s *pb.LEDSettings) error

type LedState1

type LedState1 struct {
	Available  bool
	IsRunning  bool
	BlinkCount *uint32
}

type LogLevel

type LogLevel int

case 1:

return prefix + "critical"

case 2:

return prefix + "error"

case 3:

return prefix + "warning"

case 4:

return prefix + "information"

case 5:

return prefix + "verbose"
const (
	LOG_LEVEL_UNDEFINED LogLevel = iota
	LOG_LEVEL_CRITICAL
	LOG_LEVEL_ERROR
	LOG_LEVEL_WARNING
	LOG_LEVEL_INFORMATION
	LOG_LEVEL_VERBOSE
)

type NetworkInterfaceManager

type NetworkInterfaceManager struct {
	InterfaceName string

	CmdDnsmasq *exec.Cmd

	LoggerDnsmasq *util.TeeLogger
	// contains filtered or unexported fields
}

ToDo: interface watcher (up/down --> auto redeploy)

func NewNetworkInterfaceManager

func NewNetworkInterfaceManager(nm *NetworkManager, ifaceName string, startupSettings *pb.EthernetInterfaceSettings) (nim *NetworkInterfaceManager, err error)

func (*NetworkInterfaceManager) DeploySettings

func (nim *NetworkInterfaceManager) DeploySettings(settings *pb.EthernetInterfaceSettings) (err error)

func (*NetworkInterfaceManager) GetState

func (nim *NetworkInterfaceManager) GetState() (res *NetworkInterfaceState)

func (*NetworkInterfaceManager) IsDHCPClientRunning

func (nim *NetworkInterfaceManager) IsDHCPClientRunning() (running bool, pid int, err error)

func (*NetworkInterfaceManager) OnHandedOutDhcpLease

func (nim *NetworkInterfaceManager) OnHandedOutDhcpLease(lease *DhcpLease)

func (*NetworkInterfaceManager) OnReceivedDhcpRelease

func (nim *NetworkInterfaceManager) OnReceivedDhcpRelease(release *DhcpLease)

func (*NetworkInterfaceManager) ReDeploy

func (nim *NetworkInterfaceManager) ReDeploy() (err error)

func (*NetworkInterfaceManager) StartDHCPClient

func (nim *NetworkInterfaceManager) StartDHCPClient() (err error)

func (*NetworkInterfaceManager) StartDHCPServer

func (nim *NetworkInterfaceManager) StartDHCPServer(configPath string) (err error)

func (*NetworkInterfaceManager) StopDHCPClient

func (nim *NetworkInterfaceManager) StopDHCPClient() (err error)

func (*NetworkInterfaceManager) StopDHCPServer

func (nim *NetworkInterfaceManager) StopDHCPServer() (err error)

type NetworkInterfaceState

type NetworkInterfaceState struct {
	InterfacePresent bool
	CurrentSettings  *pb.EthernetInterfaceSettings
}

type NetworkManager

type NetworkManager struct {
	ManagedInterfaces map[string]*NetworkInterfaceManager
	// contains filtered or unexported fields
}

func NewNetworkManager

func NewNetworkManager(rootService *Service) (nm *NetworkManager, err error)

func (*NetworkManager) AddManagedInterface

func (nm *NetworkManager) AddManagedInterface(startupConfig *pb.EthernetInterfaceSettings) (err error)

func (*NetworkManager) GetManagedInterface

func (nm *NetworkManager) GetManagedInterface(name string) (nim *NetworkInterfaceManager, err error)

func (*NetworkManager) GetManagedInterfaceNames

func (nm *NetworkManager) GetManagedInterfaceNames() (ifnames []string)

type SubSys

type SubSys interface {
	GetState()
	DeploySettings()
	LoadSettings()
	StoreSettings()
	SetLogger()
	Start()
	Stop()
}

type TriggerActionManager

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

func NewTriggerActionManager

func NewTriggerActionManager(rootService *Service) (tam *TriggerActionManager)

func (*TriggerActionManager) AddTriggerAction

func (tam *TriggerActionManager) AddTriggerAction(ta *pb.TriggerAction) (taAdded *pb.TriggerAction, err error)

returns the TriggerAction with assigned ID

func (*TriggerActionManager) ClearTriggerActions

func (tam *TriggerActionManager) ClearTriggerActions(keepImmutable bool) (err error)

func (*TriggerActionManager) GetCurrentTriggerActionSet

func (tam *TriggerActionManager) GetCurrentTriggerActionSet() (ta *pb.TriggerActionSet)

func (*TriggerActionManager) GetTriggerActionByID

func (tam *TriggerActionManager) GetTriggerActionByID(Id uint32) (ta *pb.TriggerAction, err error)

func (*TriggerActionManager) RemoveTriggerAction

func (tam *TriggerActionManager) RemoveTriggerAction(removeTa *pb.TriggerAction) (taRemoved *pb.TriggerAction, err error)

removes the given TriggerAction ToDo: for now only the ID is compared, to assure we don't remove a TriggerAction which has been changed meanwhile, we should deep-compare the whole object

func (*TriggerActionManager) Start

func (tam *TriggerActionManager) Start()

func (*TriggerActionManager) Stop

func (tam *TriggerActionManager) Stop()

func (*TriggerActionManager) UpdateTriggerAction

func (tam *TriggerActionManager) UpdateTriggerAction(srcTa *pb.TriggerAction, addIfMissing bool) (err error)

type UsbGadgetManager

type UsbGadgetManager struct {
	RootSvc *Service
	Usable  bool

	State *UsbManagerState
	// contains filtered or unexported fields
}

func NewUSBGadgetManager

func NewUSBGadgetManager(rooSvc *Service) (newUGM *UsbGadgetManager, err error)

func (*UsbGadgetManager) DeployGadgetSettings

func (gm *UsbGadgetManager) DeployGadgetSettings(settings *pb.GadgetSettings) (err error)

func (*UsbGadgetManager) DestroyAllGadgets

func (gm *UsbGadgetManager) DestroyAllGadgets() error

func (*UsbGadgetManager) DestroyGadget

func (gm *UsbGadgetManager) DestroyGadget(gadgetName string) error

func (*UsbGadgetManager) HandleEvent

func (gm *UsbGadgetManager) HandleEvent(event hid.Event)

func (*UsbGadgetManager) HidScriptCancelAllRunningBackgroundJobs

func (gm *UsbGadgetManager) HidScriptCancelAllRunningBackgroundJobs() (err error)

func (*UsbGadgetManager) HidScriptGetAllRunningBackgroundJobs

func (gm *UsbGadgetManager) HidScriptGetAllRunningBackgroundJobs() (jobs []*hid.AsyncOttoJob, err error)

func (*UsbGadgetManager) HidScriptGetBackgroundJobByID

func (gm *UsbGadgetManager) HidScriptGetBackgroundJobByID(id int) (job *hid.AsyncOttoJob, err error)

func (*UsbGadgetManager) HidScriptRun

func (gm *UsbGadgetManager) HidScriptRun(ctx context.Context, scriptContent string) (result interface{}, err error)

func (*UsbGadgetManager) HidScriptStartBackground

func (gm *UsbGadgetManager) HidScriptStartBackground(ctx context.Context, scriptContent string) (job *hid.AsyncOttoJob, err error)

func (*UsbGadgetManager) HidScriptUsable

func (gm *UsbGadgetManager) HidScriptUsable() error

func (*UsbGadgetManager) HidScriptWaitBackgroundJobResult

func (gm *UsbGadgetManager) HidScriptWaitBackgroundJobResult(ctx context.Context, job *hid.AsyncOttoJob) (result interface{}, err error)

WaitBackgroundJobResult(ctx context.Context, job *AsyncOttoJob) (val otto.Value, err error) {

func (*UsbGadgetManager) ParseGadgetState

func (gm *UsbGadgetManager) ParseGadgetState(gadgetName string) (result *pb.GadgetSettings, err error)

type UsbManagerState

type UsbManagerState struct {
	//UndeployedGadgetSettings *pb.GadgetSettings
	DevicePath map[string]string
}

type WiFiAuthMode

type WiFiAuthMode int
const (
	WiFiAuthMode_OPEN WiFiAuthMode = iota
	//WiFiAuthMode_WEP
	WiFiAuthMode_WPA_PSK
	WiFiAuthMode_WPA2_PSK
	WiFiAuthMode_UNSUPPORTED
)

type WiFiService

type WiFiService struct {
	RootSvc *Service

	State *pb.WiFiState

	CmdWpaSupplicant *exec.Cmd //Manages wpa-supplicant process

	CmdHostapd *exec.Cmd //Manages hostapd process

	IfaceName               string                   //Name of WiFi interface
	PathWpaSupplicantConf   string                   // path to config file for wpa-supplicant
	PathHostapdConf         string                   // path to config file for hostapd
	LoggerHostapd           *util.TeeLogger          //logger for hostapd
	LoggerWpaSupplicant     *util.TeeLogger          //logger for WPA supplicant
	OutMonitorWpaSupplicant *wpaSupplicantOutMonitor //Monitors wpa_supplicant output and sets signals where needed
	OutMonitorHostapd       *hostapdOutMonitor       //Monitors hostapd output and sets signals where needed
	// contains filtered or unexported fields
}

func NewWifiService

func NewWifiService(rootSvc *Service) (res *WiFiService)

func (*WiFiService) DeploySettings

func (wSvc *WiFiService) DeploySettings(newWifiSettings *pb.WiFiSettings) (wstate *pb.WiFiState, err error)

func (*WiFiService) StartHostapd

func (wSvc *WiFiService) StartHostapd(timeout time.Duration) (err error)

func (*WiFiService) StartWpaSupplicant

func (wSvc *WiFiService) StartWpaSupplicant(timeout time.Duration) (err error)

func (*WiFiService) StopHostapd

func (wSvc *WiFiService) StopHostapd() (err error)

func (*WiFiService) StopWpaSupplicant

func (wSvc *WiFiService) StopWpaSupplicant() (err error)

func (WiFiService) UpdateStateFromIw

func (wsvc WiFiService) UpdateStateFromIw() (err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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