Documentation ¶
Index ¶
- Constants
- Variables
- func Discover(ctx context.Context, conn []*DiscoveryClient, href string, ...) error
- func DiscoverDeviceOwnership(ctx context.Context, conn []*DiscoveryClient, status DiscoverOwnershipStatus, ...) error
- func DiscoverDevices(ctx context.Context, conn []*DiscoveryClient, handler DiscoverDevicesHandler, ...) error
- func GetResourceLink(links schema.ResourceLinks, href string) (schema.ResourceLink, error)
- func MakeAborted(e error) error
- func MakeAlreadyExists(e error) error
- func MakeCanceled(e error) error
- func MakeDataLoss(e error) error
- func MakeDeadlineExceeded(e error) error
- func MakeFailedPrecondition(e error) error
- func MakeInternal(e error) error
- func MakeInternalStr(str string, e error) error
- func MakeInvalidArgument(e error) error
- func MakeNotFound(e error) error
- func MakeOutOfRange(e error) error
- func MakePermissionDenied(e error) error
- func MakeResourceExhausted(e error) error
- func MakeSdkError(code codes.Code, err error) error
- func MakeUnauthenticated(e error) error
- func MakeUnavailable(e error) error
- func MakeUnimplemented(e error) error
- func MakeUnknown(e error) error
- type ActionAfterOwnFunc
- type ActionDuringOwnFunc
- type CertificateSigner
- type Client
- func (c *Client) GetDeviceByIP(ctx context.Context, ip string) (*Device, error)
- func (c *Client) GetDeviceByMulticast(ctx context.Context, deviceID string, ...) (*Device, error)
- func (c *Client) GetDevicesByIP(ctx context.Context, ip string) ([]*Device, error)
- func (c *Client) GetDevicesByMulticast(ctx context.Context, discoveryConfiguration DiscoveryConfiguration, ...) error
- func (c *Client) GetOwnerships(ctx context.Context, discoveryConfiguration DiscoveryConfiguration, ...) error
- func (c *Client) GetSdkOwnerID() (string, error)
- type Config
- type Device
- func (d *Device) Close(ctx context.Context) error
- func (d *Device) DeleteResource(ctx context.Context, link schema.ResourceLink, response interface{}, ...) error
- func (d *Device) DeleteResourceWithCodec(ctx context.Context, link schema.ResourceLink, codec coap.Codec, ...) error
- func (d *Device) DeviceID() string
- func (d *Device) DeviceTypes() []string
- func (d *Device) Disown(ctx context.Context, links schema.ResourceLinks, options ...coap.OptionFunc) error
- func (d *Device) FactoryReset(ctx context.Context, links schema.ResourceLinks, options ...coap.OptionFunc) error
- func (d *Device) FoundByIP() string
- func (d *Device) GetEndpoints() schema.Endpoints
- func (d *Device) GetOwnership(ctx context.Context, links schema.ResourceLinks, options ...coap.OptionFunc) (doxm.Doxm, error)
- func (d *Device) GetResource(ctx context.Context, link schema.ResourceLink, response interface{}, ...) error
- func (d *Device) GetResourceLinks(ctx context.Context, endpoints []schema.Endpoint, options ...coap.OptionFunc) (schema.ResourceLinks, error)
- func (d *Device) GetResourceWithCodec(ctx context.Context, link schema.ResourceLink, codec coap.Codec, ...) error
- func (d *Device) GetResources(links schema.ResourceLinks) *ResourceIterator
- func (d *Device) GetSdkOwnerID() (string, error)
- func (d *Device) IsConnected() bool
- func (d *Device) IsSecured() bool
- func (d *Device) ObserveResource(ctx context.Context, link schema.ResourceLink, handler ObservationHandler, ...) (observationID string, _ error)
- func (d *Device) ObserveResourceWithCodec(ctx context.Context, link schema.ResourceLink, codec coap.Codec, ...) (observationID string, _ error)
- func (d *Device) Own(ctx context.Context, links schema.ResourceLinks, otmClients []otm.Client, ...) error
- func (d *Device) Provision(ctx context.Context, links schema.ResourceLinks, options ...coap.OptionFunc) (*ProvisioningClient, error)
- func (d *Device) Reboot(ctx context.Context, links schema.ResourceLinks, options ...coap.OptionFunc) error
- func (d *Device) SetDeviceID(deviceID string)
- func (d *Device) SetEndpoints(getEndpoints func() schema.Endpoints)
- func (d *Device) StopObservingResource(ctx context.Context, observationID string) (bool, error)
- func (d *Device) UpdateBy(v *Device)
- func (d *Device) UpdateResource(ctx context.Context, link schema.ResourceLink, request interface{}, ...) error
- func (d *Device) UpdateResourceWithCodec(ctx context.Context, link schema.ResourceLink, codec coap.Codec, ...) error
- type DeviceConfiguration
- type DeviceHandler
- type DeviceMulticastHandler
- type DialDTLS
- type DialTCP
- type DialTLS
- type DialUDP
- type DiscoverDeviceCodec
- type DiscoverDeviceOwnershipHandler
- type DiscoverDevicesHandler
- type DiscoverOwnershipStatus
- type DiscoveryClient
- type DiscoveryConfiguration
- type DiscoveryHandler
- type GetCertificateAuthoritiesFunc
- type GetCertificateFunc
- type Logger
- type ObservationHandler
- type OptionFunc
- type OwnOption
- type OwnershipHandler
- type ProvisioningClient
- func (c *ProvisioningClient) AddCertificateAuthority(ctx context.Context, subject string, cert *x509.Certificate) error
- func (c *ProvisioningClient) AddCredentials(ctx context.Context, cr credential.CredentialUpdateRequest) error
- func (c *ProvisioningClient) Close(ctx context.Context) error
- func (c *ProvisioningClient) SetAccessControl(ctx context.Context, permission acl.Permission, subject acl.Subject, ...) error
- func (c *ProvisioningClient) SetCloudResource(ctx context.Context, r cloud.ConfigurationUpdateRequest) error
- type ResourceIterator
- type SdkError
- type TLSConfig
Constants ¶
const ( DiscoveryAddressUDP4Local = "224.0.1.187:5683" DiscoveryAddressUDP6LinkLocal = "[ff02::158]:5683" DiscoveryAddressUDP6RealmLocal = "[ff03::158]:5683" DiscoveryAddressUDP6SiteLocal = "[ff05::158]:5683" )
See the section 10.4 on the line 2482 of the Core specification: https://openconnectivity.org/specs/OCF_Core_Specification_v2.0.0.pdf https://iotivity.org/documentation/linux/programmers-guide
const ( // DiscoverAllDevices discovers owned and disowned devices. DiscoverAllDevices = DiscoverOwnershipStatus(0) // DiscoverOwnedDevices discovers owned devices, DiscoverOwnedDevices = DiscoverOwnershipStatus(1) // DiscoverDisownedDevices discovers disowned devices, DiscoverDisownedDevices = DiscoverOwnershipStatus(2) )
const ANY_DEVICE = "anydevice"
Variables ¶
var ( DiscoveryAddressUDP4 = []string{DiscoveryAddressUDP4Local} DiscoveryAddressUDP6 = []string{DiscoveryAddressUDP6LinkLocal, DiscoveryAddressUDP6RealmLocal, DiscoveryAddressUDP6SiteLocal} )
var ErrCannotDetermineDeviceID = errors.New("cannot determine device ID")
Functions ¶
func Discover ¶
func Discover( ctx context.Context, conn []*DiscoveryClient, href string, handler DiscoveryHandler, options ...coap.OptionFunc, ) error
Discover discovers devices using a CoAP multicast request via UDP. It waits for device responses until the context is canceled. Device resources can be queried in DiscoveryHandler. An empty typeFilter queries all resource types. Note: Iotivity 1.3 which responds with BadRequest if more than 1 resource type is queried.
func DiscoverDeviceOwnership ¶
func DiscoverDeviceOwnership( ctx context.Context, conn []*DiscoveryClient, status DiscoverOwnershipStatus, handler DiscoverDeviceOwnershipHandler, ) error
DiscoverDeviceOwnership discovers devices using a CoAP multicast request via UDP. It waits for device responses until the context is canceled.
func DiscoverDevices ¶
func DiscoverDevices( ctx context.Context, conn []*DiscoveryClient, handler DiscoverDevicesHandler, options ...coap.OptionFunc, ) error
DiscoverDevices discovers devices using a CoAP multicast request via UDP. It waits for device responses until the context is canceled. Device resources can be queried in DiscoveryHandler. An empty typeFilter queries all resource types. Note: Iotivity 1.3 which responds with BadRequest if more than 1 resource type is queried.
func GetResourceLink ¶
func GetResourceLink(links schema.ResourceLinks, href string) (schema.ResourceLink, error)
func MakeAborted ¶
func MakeAlreadyExists ¶
func MakeCanceled ¶
func MakeDataLoss ¶
func MakeDeadlineExceeded ¶
func MakeFailedPrecondition ¶
func MakeInternal ¶
func MakeInternalStr ¶
func MakeInvalidArgument ¶
func MakeNotFound ¶
func MakeOutOfRange ¶
func MakePermissionDenied ¶
func MakeResourceExhausted ¶
func MakeUnauthenticated ¶
func MakeUnavailable ¶
func MakeUnimplemented ¶
func MakeUnknown ¶
Types ¶
type ActionAfterOwnFunc ¶
type ActionAfterOwnFunc = func(ctx context.Context, client *coap.ClientCloseHandler) error
type ActionDuringOwnFunc ¶
type CertificateSigner ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client an OCF local client.
func NewClient ¶
func NewClient(opts ...OptionFunc) *Client
func (*Client) GetDeviceByIP ¶
GetDeviceByIP gets the device directly via IP address and multicast listen port 5683.
func (*Client) GetDeviceByMulticast ¶
func (c *Client) GetDeviceByMulticast(ctx context.Context, deviceID string, discoveryConfiguration DiscoveryConfiguration) (*Device, error)
GetDeviceByMulticast performs a multicast and returns a device object if the device responds.
func (*Client) GetDevicesByIP ¶ added in v2.3.0
GetDevicesByIP gets the devices directly via IP address and multicast listen port 5683.
func (*Client) GetDevicesByMulticast ¶
func (c *Client) GetDevicesByMulticast(ctx context.Context, discoveryConfiguration DiscoveryConfiguration, handler DeviceMulticastHandler) error
GetDevicesByMulticast discovers devices using a CoAP multicast request via UDP. Device resources can be queried in DeviceHandler using device.Client,
func (*Client) GetOwnerships ¶
func (c *Client) GetOwnerships( ctx context.Context, discoveryConfiguration DiscoveryConfiguration, status DiscoverOwnershipStatus, handler OwnershipHandler, ) error
GetOwnerships discovers device's ownerships using a CoAP multicast request via UDP. It waits for device responses until the context is canceled.
func (*Client) GetSdkOwnerID ¶
GetSdkOwnerID returns sdk ownerID from sdk identity certificate.
type Device ¶
type Device struct {
// contains filtered or unexported fields
}
func (*Device) DeleteResource ¶
func (d *Device) DeleteResource( ctx context.Context, link schema.ResourceLink, response interface{}, options ...coap.OptionFunc, ) error
func (*Device) DeleteResourceWithCodec ¶
func (d *Device) DeleteResourceWithCodec( ctx context.Context, link schema.ResourceLink, codec coap.Codec, response interface{}, options ...coap.OptionFunc, ) error
func (*Device) DeviceTypes ¶
func (*Device) Disown ¶
func (d *Device) Disown( ctx context.Context, links schema.ResourceLinks, options ...coap.OptionFunc, ) error
Disown removes ownership of device
func (*Device) FactoryReset ¶
func (d *Device) FactoryReset( ctx context.Context, links schema.ResourceLinks, options ...coap.OptionFunc, ) error
func (*Device) GetEndpoints ¶
func (*Device) GetOwnership ¶
func (d *Device) GetOwnership(ctx context.Context, links schema.ResourceLinks, options ...coap.OptionFunc) (doxm.Doxm, error)
GetOwnership gets device's ownership resource.
func (*Device) GetResource ¶
func (d *Device) GetResource( ctx context.Context, link schema.ResourceLink, response interface{}, options ...coap.OptionFunc, ) error
GetResource queries a device for a resource value in CBOR.
func (*Device) GetResourceLinks ¶
func (d *Device) GetResourceLinks(ctx context.Context, endpoints []schema.Endpoint, options ...coap.OptionFunc) (schema.ResourceLinks, error)
func (*Device) GetResourceWithCodec ¶
func (d *Device) GetResourceWithCodec( ctx context.Context, link schema.ResourceLink, codec coap.Codec, response interface{}, options ...coap.OptionFunc, ) error
GetResourceWithCodec queries a device for a resource value.
func (*Device) GetResources ¶
func (d *Device) GetResources(links schema.ResourceLinks) *ResourceIterator
GetResources resolves URIs and returns an iterator for querying resources of given resource types.
func (*Device) GetSdkOwnerID ¶
GetSdkOwnerID returns sdk ownerID
func (*Device) IsConnected ¶
func (*Device) ObserveResource ¶
func (d *Device) ObserveResource( ctx context.Context, link schema.ResourceLink, handler ObservationHandler, options ...coap.OptionFunc, ) (observationID string, _ error)
func (*Device) ObserveResourceWithCodec ¶
func (d *Device) ObserveResourceWithCodec( ctx context.Context, link schema.ResourceLink, codec coap.Codec, handler ObservationHandler, options ...coap.OptionFunc, ) (observationID string, _ error)
func (*Device) Own ¶
func (d *Device) Own( ctx context.Context, links schema.ResourceLinks, otmClients []otm.Client, options ...OwnOption, ) error
Own set ownership of device. For owning, the first match in order of otmClients with the device will be used. Note: In case if the device fails before changing RFOTM the iotivity-stack invokes disown by itself. This can result in a state where the disown is invoked two times in a row. Once by the iotivity-stack and second time by device core.
func (*Device) Provision ¶
func (d *Device) Provision(ctx context.Context, links schema.ResourceLinks, options ...coap.OptionFunc) (*ProvisioningClient, error)
func (*Device) Reboot ¶
func (d *Device) Reboot( ctx context.Context, links schema.ResourceLinks, options ...coap.OptionFunc, ) error
func (*Device) SetDeviceID ¶
func (*Device) SetEndpoints ¶
func (*Device) StopObservingResource ¶
func (*Device) UpdateResource ¶
func (d *Device) UpdateResource( ctx context.Context, link schema.ResourceLink, request interface{}, response interface{}, options ...coap.OptionFunc, ) error
func (*Device) UpdateResourceWithCodec ¶
func (d *Device) UpdateResourceWithCodec( ctx context.Context, link schema.ResourceLink, codec coap.Codec, request interface{}, response interface{}, options ...coap.OptionFunc, ) error
type DeviceConfiguration ¶
type DeviceHandler ¶
type DeviceHandler interface { // Handle gets a device connection and is responsible for closing it. Handle(ctx context.Context, device *Device, deviceLinks schema.ResourceLinks) // Error gets errors during discovery. Error(err error) }
DeviceHandler conveys device connections and errors during discovery.
type DeviceMulticastHandler ¶
type DeviceMulticastHandler interface { // Handle gets a device connection and is responsible for closing it. Handle(ctx context.Context, device *Device) // Error gets errors during discovery. Error(err error) }
DeviceMulticastHandler conveys device connections and errors during discovery.
type DiscoverDeviceCodec ¶
type DiscoverDeviceCodec struct{}
func (DiscoverDeviceCodec) ContentFormat ¶
func (c DiscoverDeviceCodec) ContentFormat() message.MediaType
ContentFormat propagates the CoAP media type.
func (DiscoverDeviceCodec) Decode ¶
func (c DiscoverDeviceCodec) Decode(msg *pool.Message, v interface{}) error
Decode validates the content format and propagates the payload to v as *schema.ResourceLinks
func (DiscoverDeviceCodec) Encode ¶
func (c DiscoverDeviceCodec) Encode(interface{}) ([]byte, error)
Encode propagates the payload without any conversions.
type DiscoverDeviceOwnershipHandler ¶
type DiscoverDeviceOwnershipHandler interface { Handle(ctx context.Context, client *client.Conn, device doxm.Doxm) Error(err error) }
DiscoverDeviceOwnershipHandler receives devices ownership info.
type DiscoverDevicesHandler ¶
type DiscoverDevicesHandler interface { Handle(ctx context.Context, client *client.Conn, device schema.ResourceLinks) Error(err error) }
DiscoverDevicesHandler receives device links and errors from the discovery multicast request.
type DiscoverOwnershipStatus ¶
type DiscoverOwnershipStatus int
DiscoverOwnershipStatus type of discover ownership status.
type DiscoveryClient ¶
type DiscoveryClient struct {
// contains filtered or unexported fields
}
func DialDiscoveryAddresses ¶
func DialDiscoveryAddresses(ctx context.Context, cfg DiscoveryConfiguration, errFn func(error)) ([]*DiscoveryClient, error)
DialDiscoveryAddresses connects to discovery endpoints.
func (*DiscoveryClient) Close ¶
func (d *DiscoveryClient) Close() error
func (*DiscoveryClient) PublishMsgWithContext ¶
func (d *DiscoveryClient) PublishMsgWithContext(req *pool.Message, discoveryHandler DiscoveryHandler) error
type DiscoveryConfiguration ¶
type DiscoveryConfiguration struct { MulticastHopLimit int // default: {224.0.1.187:5683, ff02::158]:5683} = 1, {[ff03::158]:5683, [ff05::158]:5683} = 255, https://openconnectivity.org/specs/OCF_Core_Specification.pdf 12.2.9 MulticastAddressUDP4 []string // default: "[224.0.1.187:5683] (client.DiscoveryAddressUDP4), empty: don't use ipv4 multicast" MulticastAddressUDP6 []string // default: "[ff02::158]:5683", "[ff03::158]:5683", "[ff05::158]:5683]"] (client.DiscoveryAddressUDP6), empty: don't use ipv6 multicast" MulticastOptions []coapNet.MulticastOption }
DiscoveryConfiguration setup discovery configuration
func DefaultDiscoveryConfiguration ¶
func DefaultDiscoveryConfiguration() DiscoveryConfiguration
type GetCertificateAuthoritiesFunc ¶
type GetCertificateAuthoritiesFunc func() ([]*x509.Certificate, error)
GetCertificateAuthoritiesFunc returns certificate authorities to verify peers
type GetCertificateFunc ¶
type GetCertificateFunc func() (tls.Certificate, error)
GetCertificateFunc returns certificate for connection
type ObservationHandler ¶
type ObservationHandler interface { Handle(ctx context.Context, body coap.DecodeFunc) OnClose() Error(err error) }
type OptionFunc ¶
func WithDialDTLS ¶
func WithDialDTLS(dial DialDTLS) OptionFunc
func WithDialTCP ¶
func WithDialTCP(dial DialTCP) OptionFunc
func WithDialTLS ¶
func WithDialTLS(dial DialTLS) OptionFunc
func WithDialUDP ¶
func WithDialUDP(dial DialUDP) OptionFunc
func WithLogger ¶
func WithLogger(logger Logger) OptionFunc
func WithTLS ¶
func WithTLS(tlsConfig *TLSConfig) OptionFunc
type OwnOption ¶
type OwnOption = func(ownCfg) ownCfg
func WithActionAfterOwn ¶
func WithActionAfterOwn(actionAfterOwn ActionAfterOwnFunc) OwnOption
WithActionAfterOwn allows initialize configuration at the device via DTLS connection with preshared key. For example setup time / NTP. if it returns error device will be disowned.
func WithActionDuringOwn ¶
func WithActionDuringOwn(actionDuringOwn ActionDuringOwnFunc) OwnOption
WithActionDuringOwn allows to set deviceID of owned device and other staff over owner TLS. returns new deviceID, if it returns error device will be disowned.
func WithPresharedKey ¶
WithPresharedKey allows to set preshared key for owner. It is not set, it will be randomized.
func WithSetupCertificates ¶
WithSetupCertificates signs identity ceriticates and install root ca.
type OwnershipHandler ¶
type OwnershipHandler interface { // Handle gets a device ownership. Handle(ctx context.Context, doxm doxm.Doxm) // Error gets errors during discovery. Error(err error) }
OwnershipHandler conveys device ownership and errors during discovery.
type ProvisioningClient ¶
type ProvisioningClient struct { *Device // contains filtered or unexported fields }
func (*ProvisioningClient) AddCertificateAuthority ¶
func (c *ProvisioningClient) AddCertificateAuthority(ctx context.Context, subject string, cert *x509.Certificate) error
func (*ProvisioningClient) AddCredentials ¶
func (c *ProvisioningClient) AddCredentials(ctx context.Context, cr credential.CredentialUpdateRequest) error
func (*ProvisioningClient) SetAccessControl ¶
func (c *ProvisioningClient) SetAccessControl( ctx context.Context, permission acl.Permission, subject acl.Subject, resources ...acl.Resource, ) error
SetAccessControl updates the acl resource. Usage: SetAccessControl(ctx, schema.AllPermissions, schema.TLSConnection, schema.AllResources)
func (*ProvisioningClient) SetCloudResource ¶
func (c *ProvisioningClient) SetCloudResource(ctx context.Context, r cloud.ConfigurationUpdateRequest) error
type ResourceIterator ¶
type ResourceIterator struct { Err error // contains filtered or unexported fields }
ResourceIterator queries resource values.
func (*ResourceIterator) Next ¶
func (it *ResourceIterator) Next(ctx context.Context, v interface{}) bool
Next queries the next resource value. Returns false when failed or having no more items. Check it.Err for errors. Usage:
for { var v MyStruct if !it.Next(ctx, &v) { break } } if it.Err != nil { }
type TLSConfig ¶
type TLSConfig struct { // User for communication with owned devices and cloud GetCertificate GetCertificateFunc GetCertificateAuthorities GetCertificateAuthoritiesFunc }
Source Files ¶
- certificateSigner.go
- client.go
- deleteResource.go
- device.go
- discover.go
- discoverDeviceCodec.go
- discoverDeviceOwnership.go
- discoverDevices.go
- disownDevice.go
- getDevice.go
- getDevices.go
- getEndpoints.go
- getOwnership.go
- getOwnerships.go
- getResource.go
- getResourceLinks.go
- getSdkOwnerID.go
- isSecured.go
- logger.go
- maintenance.go
- observeResource.go
- ownDevice.go
- provisionDevice.go
- sdkError.go
- updateResource.go