Documentation
¶
Overview ¶
Package server is the meter side of DLMS/COSEM: a logical device that holds COSEM objects (package classes) and serves them to clients over the wrapper (TCP or UDP) and HDLC.
It accepts application associations per client address with no security, low-level security or HLS (mechanisms 2 to 7), security suites 0 to 2 with authenticated, encrypted or authenticated and encrypted APDUs under the global or a dedicated key, in service-specific, general-glo or general-ded ciphering. It answers GET, SET and ACTION (normal, with list, and in data blocks both ways), the ACCESS service, and, with ShortNames, the short name services (read, write, unconfirmed write, with data blocks and parameterized access). Long answers go in data blocks, or in general block transfer when the client negotiated it. Data notifications are pushed to a client address or a push setup's destination. The current association object (class 15, or class 12 with short names) is built from the server's objects and the client's rights.
The protection of APDUs is cosem's (Protect, UnprotectKeys and the HLS answers), so a client of this module and this server share one implementation; dlms-sim's meter, written separately, and Gurux's client check both.
Index ¶
- type Association
- type Op
- type PushOptions
- type Server
- func (s *Server) Add(objs ...classes.Object)
- func (s *Server) AddSN(o classes.Object, base uint16)
- func (s *Server) BaseName(class uint16, ln string) (uint16, bool)
- func (s *Server) Close() error
- func (s *Server) DataNotification(invokeID uint32, at time.Time, loc *time.Location, body *axdr.DlmsData) ([]byte, error)
- func (s *Server) ListenHDLC(addr string) (string, error)
- func (s *Server) ListenUDP(addr string) (string, error)
- func (s *Server) ListenWrapper(addr string) (string, error)
- func (s *Server) Object(class uint16, ln string) (classes.Object, bool)
- func (s *Server) Objects() []classes.Object
- func (s *Server) Push(setupLN string, o PushOptions) error
- func (s *Server) PushHDLC(body *axdr.DlmsData, o PushOptions) error
- func (s *Server) PushTo(network, addr string, body *axdr.DlmsData, o PushOptions) error
- func (s *Server) Resolve(class uint16, ln string, attr int8) (*axdr.DlmsData, error)
- func (s *Server) ServeHDLC(rw io.ReadWriter) error
- func (s *Server) ServeWrapper(c io.ReadWriter) error
- func (s *Server) Stats() Stats
- type Stats
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Association ¶
type Association struct {
// ClientAddress is the client's SAP (wrapper wPort, HDLC client
// address); 16 is the public client.
ClientAddress uint16
// Mechanism is the authentication: 0 none, 1 low-level (Secret is the
// password), 2 to 7 HLS (Secret is the secret of 2, 3, 4 and 6).
Mechanism byte
Secret []byte
// Policy protects APDUs after the association: 0 none, or
// cosem.SecAuthentication and/or cosem.SecEncryption. Suite is the
// security suite (0, 1 or 2); Key and AuthKey the global unicast and
// authentication keys; BroadcastKey the global broadcast key.
Policy byte
Suite byte
Key, AuthKey []byte
BroadcastKey []byte
// SigningKey is the server's key and ClientKey the client's public key
// (mechanism 7).
SigningKey *ecdsa.PrivateKey
ClientKey *ecdsa.PublicKey
// Context, when not 0, is the only application context accepted (1 LN,
// 2 SN, 3 LN with ciphering, 4 SN with ciphering); an AARQ proposing
// another is refused with diagnostic 2. 0 accepts the server's
// referencing with or without ciphering.
Context byte
// InvocationCounter, when set, is the logical name of a class 1 object
// holding the client's last invocation counter (readable by the public
// client): an AARQ whose counter is not above it is refused.
InvocationCounter string
// Allow, when set, decides each access (rights of the association);
// nil allows everything the objects allow.
Allow func(class uint16, ln string, id int8, op Op) bool
// Conformance is the services offered to this client (0: the server's).
Conformance uint32
}
Association is what the server accepts from one client address.
type PushOptions ¶
type PushOptions struct {
// ClientAddress is the wPort pushes go to (default 64, the push
// client of IS 15959 and of Gurux's examples).
ClientAddress uint16
// Security, when set, protects pushes in general-glo-ciphering with
// its policy, suite and keys (its client address is not used).
Security *Association
// Time stamps each notification (the date-time field) when set.
Time func() time.Time
// Loc is the zone of the date-time (default UTC).
Loc *time.Location
}
PushOptions are how pushes are sent.
type Server ¶
type Server struct {
// SystemTitle is the server's, 8 octets (needed with protected APDUs
// and mechanisms 5 to 7).
SystemTitle []byte
// Associations are the clients accepted, by client address; a client
// address with none is refused.
Associations []*Association
// ShortNames serves short name referencing instead of logical names;
// objects get base names as they are added (AddSN to choose one).
ShortNames bool
// MaxPDU is the largest APDU the server receives and sends (default
// 1024); BlockSize, when set, bounds the data in one block.
MaxPDU uint16
BlockSize int
// Conformance is the services offered (default: get, set, action,
// selective access, block transfer in all three, multiple references,
// ACCESS, data notification and general protection; with ShortNames
// read, write, unconfirmed write, parameterized access, multiple
// references and block transfer). GBT adds general block transfer.
Conformance uint32
GBT bool
// Address is the server's SAP: the wrapper wPort and the HDLC upper
// address (default 1). HDLCAddress is the lower (physical) address and
// HDLCAddressSize the size of the server address (1, 2 or 4; default
// 1); HDLCParams the data link parameters (zero: the defaults).
Address uint16
HDLCAddress int
HDLCAddressSize int
HDLCParams hdlc.Params
HDLCInactivity time.Duration
// Logf, when set, receives events (refused associations, protocol
// errors).
Logf func(format string, args ...any)
// contains filtered or unexported fields
}
Server is one logical device. Set the fields, Add objects, then serve.
func (*Server) Add ¶
Add puts objects in the server. An object with the class and logical name of one already there replaces it.
func (*Server) DataNotification ¶
func (s *Server) DataNotification(invokeID uint32, at time.Time, loc *time.Location, body *axdr.DlmsData) ([]byte, error)
DataNotification is the APDU of a data-notification with body.
func (*Server) ListenHDLC ¶
ListenHDLC serves HDLC over TCP at addr (a meter behind a serial to Ethernet converter) until Close.
func (*Server) ListenUDP ¶
ListenUDP serves the wrapper over UDP at addr until Close: one WPDU per datagram each way, a session per client address and port.
func (*Server) ListenWrapper ¶
ListenWrapper serves the wrapper over TCP at addr ("127.0.0.1:0", ":4059") until Close, and returns the address listened on.
func (*Server) Push ¶
func (s *Server) Push(setupLN string, o PushOptions) error
Push runs the push of a push setup object (class 40): its object list read from the server's objects, as a structure, to its destination (send_destination_and_method: TCP or UDP, "host:port").
func (*Server) PushHDLC ¶
func (s *Server) PushHDLC(body *axdr.DlmsData, o PushOptions) error
PushHDLC queues a data-notification with body on every open HDLC link: it goes in a UI frame at the next right to talk.
func (*Server) PushTo ¶
PushTo sends a data-notification with body to network ("tcp" or "udp") address addr in a WPDU from the server's wPort.
func (*Server) ServeHDLC ¶
func (s *Server) ServeHDLC(rw io.ReadWriter) error
ServeHDLC answers HDLC on rw (a serial port, a converter's connection) until it ends: the server is a secondary station at Address (upper) and HDLCAddress (lower); each client address is a data link of its own, with its session from SNRM to DISC. APDUs in UI frames are served and never answered.
func (*Server) ServeWrapper ¶
func (s *Server) ServeWrapper(c io.ReadWriter) error
ServeWrapper answers the wrapper on one connection (TCP, or a stream someone else opened) until it ends; each client wPort has its own session. WPDUs for another server wPort are dropped; the all-station wPort is served but never answered.
type Stats ¶
type Stats struct {
Associations int // accepted (after HLS pass 3 when HLS is used)
Refused int // AARQs refused and failed HLS passes
Blocks int // data blocks sent (GET, ACTION, short name read)
GBTBlocks int // general-block-transfer APDUs sent
// Protected requests opened, by form.
ServiceSpecific, GeneralGlo, GeneralDed int
}
Stats counts what the server did.