DLMS-Client-UserManual C#
DLMS-Client-UserManual C#
DLMS-Client-UserManual C#
User Manual
www.kalkitech.com
Disclaimer
Contact Information
Purpose
This manual serves as a guide for using DLMS/COSEM Client Source Code Library. This manual
familiarizes the user with the source code library and provides a step–by–step instruction on how to
integrate the code with the user application.
Intended Audience
Confidential
3
DLMS/COSEM Client SCL User Manual Version 3.15.1
Documentation Conventions
1 Field Name, Screen Name and Button Arial, Bold face font
2 Note Note:
Confidential
4
DLMS/COSEM Client SCL User Manual Version 3.15.1
List of Abbreviations
The following table shows the acronyms/abbreviations used in this document:
Acronyms/Abbreviations Description
COSEM Companion Specification for Energy Metering
DLMS Device Language Message Specification
IP Internet Protocol
LN Logical Name
OBIS Object Identification System
OEM Original Equipment Manufacturer
PDU Protocol Data Unit
SAP Service Access Point
SN Short Name
Confidential
5
DLMS/COSEM Client SCL User Manual Version 3.15.1
Contents
1 Introduction...........................................................................................................................................9
1.1 Overview of The Protocol Stack...................................................................................................9
1.2 Sample Implementations...............................................................................................................9
1.3 Key Features..................................................................................................................................9
2 Implementation Procedure..................................................................................................................10
2.1 Overview.....................................................................................................................................10
2.2 Client Library Functions.............................................................................................................10
2.2.1 initClient()..........................................................................................................................10
2.2.2 initPort()..............................................................................................................................12
2.2.3 modeEInit()..........................................................................................................................13
2.2.4 closePort()............................................................................................................................14
2.2.5 closeClient().........................................................................................................................14
2.2.6 setParamsHDLC()................................................................................................................14
2.2.7 sendSNRM()........................................................................................................................16
2.2.8 sendDISC()..........................................................................................................................17
2.2.9 SetParamsCosemWrapper().................................................................................................17
2.2.10 SetParamsAARQ...............................................................................................................18
2.2.11 sendAARQ()......................................................................................................................21
2.2.12 SetParamsPreEstablishedAssociation................................................................................23
2.2.13 sendRLRQ().......................................................................................................................26
2.2.14 getData()............................................................................................................................28
2.2.15 cleanupMemory()..............................................................................................................31
2.2.16 setData().............................................................................................................................31
2.2.17 CleanUpMemoryForSet.....................................................................................................33
2.2.18 executeAction()..................................................................................................................34
2.2.19 createSocket.......................................................................................................................36
2.2.20 acceptSocket......................................................................................................................36
2.2.21 initIncomingPort................................................................................................................37
2.2.22 closeSocket........................................................................................................................37
2.2.23 setParamsUnsolicitedCommunication...............................................................................38
2.2.24 registerSecurityCallbacks..................................................................................................39
2.2.25 registerCertCallback.........................................................................................................43
2.2.26 registerCipheringKeysCallback.........................................................................................43
2.2.27 registerPushCallback.........................................................................................................44
2.3 Special Functions........................................................................................................................44
2.3.1 registerErrCallback..............................................................................................................44
2.3.2 registerDiagCallback...........................................................................................................45
2.3.3 UpdateHdlcAdvancedSettings.............................................................................................45
2.3.4 updateSerialAdvancedSettings............................................................................................46
2.3.5 Set Frame Counter...............................................................................................................47
2.3.6 CosemEncodeAXDR..........................................................................................................47
2.3.7 CosemEncodeAARQ...........................................................................................................51
2.3.8 CleanUpEncodedAXDR......................................................................................................56
Confidential
6
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.3.9 CosemDecodeAXDR...........................................................................................................57
2.3.10 CleanupDecodedAXDR...................................................................................................60
2.3.11 cosemDecodeCompactFrameData.....................................................................................60
2.3.12 cleanDecodedCompactFrameData....................................................................................61
2.3.13 getSystemTitleFromPushNotification...............................................................................62
2.3.14 cleanUpencodeComHeader...............................................................................................62
2.3.15 encodeComProfileParams..................................................................................................63
2.3.16 decodeComProfileParams..................................................................................................64
2.3.17 cleanUpdecodedComHeader.............................................................................................65
2.3.18 EncodeHDLCrequest.........................................................................................................65
2.3.19 cleanUpEncodedHDLC.....................................................................................................68
2.3.20 DecodeHDLCrequest.........................................................................................................68
2.3.21 CleanUpEncodedAXDR....................................................................................................71
2.3.22 Sendpacket.........................................................................................................................71
2.3.23 Call Sequence(HDLC).......................................................................................................72
2.3.24 setGatewayParams.............................................................................................................72
2.3.25 useDedicatedCiphering......................................................................................................73
2.3.26 cosemEncodeRLRQ..........................................................................................................74
2.3.27 processChallenge...............................................................................................................78
2.3.28 setFrameCounter................................................................................................................79
2.3.29 cleanPushData....................................................................................................................80
2.3.30 getAssociationParameters..................................................................................................80
2.3.31 cleanEventData..................................................................................................................80
2.3.32 getEvent.............................................................................................................................81
2.3.33 triggerEventNotification....................................................................................................81
2.3.34 imageTransfer....................................................................................................................81
2.4 Structures and Unions.................................................................................................................83
2.4.1 DLMS_UNION_CS............................................................................................................83
2.4.2 ACTION_UNION_CS.........................................................................................................84
2.5 Security Implementation.............................................................................................................85
3 Call Sequence......................................................................................................................................90
3.1 Multichannel Operation...............................................................................................................91
4 Debugging Options.............................................................................................................................91
5 Running on Linux (+Windows)..........................................................................................................92
6 Appendix A.........................................................................................................................................93
6.1 Return Codes in SCL...................................................................................................................93
6.1.1 Generic return codes............................................................................................................93
6.1.2 Library generated HDLC specific return codes...................................................................93
6.1.3 Library generated COSEM specific return codes................................................................93
6.1.4 Server generated return codes..............................................................................................94
7 Appendix B: Interoperability Details of DLMS Client SCL...............................................................96
Confidential
7
DLMS/COSEM Client SCL User Manual Version 3.15.1
Index of Tables
Table 1: Organization of the document......................................................................................3
Table 2: Document Conventions................................................................................................4
Table 3: List of abbreviations.....................................................................................................5
Confidential
8
DLMS/COSEM Client SCL User Manual Version 3.15.1
1 Introduction
• Sample implementations.
• Key features.
1.1 Overview of The Protocol Stack
The DLMS/COSEM Client Source Code Library provides a complete implementation of a 62056
DLMS/COSEM protocol stack to enable interested OEMs to create DLMS Client Applications to
read/write DLMS enabled meters and devices.
The protocol source is written in ANSI-C and can be used on most platforms as-is without any
changes.
1.2 Sample Implementations
The SCL ships with sample implementations using either source code or object library, depending on
the type of delivery opted by the OEM. The OEM can build this sample implementation and start
running the client on a Windows/Linux machine and test against a server to trace the flow and logic of
the protocol-stack.
1.3 Key Features
• DLMS UA attested stack
• Platform independent with default implementation for Windows and Linux
• Supports HDLC and UDP TCP/IP communication profiles
• Support for IEC 62056-21 Mode E
Confidential
9
DLMS/COSEM Client SCL User Manual Version 3.15.1
2 Implementation Procedure
The object library is shipped with a sample application to demonstrate the implementation
methodology.
The exported library functions provide a means to open and initialize a serial or IP port/, establish a
HDLC connection (only for HDLC based communication profile), establish an application association,
and then functions to read/write/execute attributes and methods in the connected DLMS server
(meter). The client application can then call functions to disconnect from the meter, close the
communication port and cleanup memory.
2.2 Client Library Functions
The following are the exported functions in the Client Object Library. The following description is specific to
usage from within a .NET application.
2.2.1 initClient()
This function is to be used to initialize the client as the first step when using the library.
Prototype
Arguments
ResTimeOut
Response timeout used by the client, in milliseconds. This is the amount of time
Confidential
10
DLMS/COSEM Client SCL User Manual Version 3.15.1
that the Client is to wait after sending a request without receiving a response
before declaring that the request has timed-out.
interframeTmOut
Frame timeout in milliseconds. This is the amount of time that the Client will wait
after receiving the initial few bytes of a frame-header, for the rest of the frame to
be received.
linkBuffsz
HDLC/wrapper(for IPv4) buffer size. Suggested value is 512 bytes. This allocates
the size of the HDLC or TCP/IP Layer buffers for received and transmit data.
cosemBufsz
COSEM buffer size, This is the size of the COSEM Application Layer buffers that
hold the received data when performing a Get/Read operation. This should be a
large value to hold the largest possible attribute value that may be read from the
meter. Certain array-type attributes (for example, the Buffer attribute of a Profile
object) may contain several entries. This buffer should be sized appropriately to
hold the entire response.
commProfile
Communication Profile .This is the type of communication profile in use
NOTE: Stack will use this value only for some initialization and buffer allocations. Actual ciphering depends on
the ciphering values passed in further functions (like sendAARQ / getData/ setData/ executeAction ). User
should ensure cipheringSupport to be consistent with appCtxt of setParamsAARQ, cipheringType of getData
/ setData / executeAction. If user is doubtful or may “sometimes” want to use ciphering in Application
association, then cipheringSupport shall be set to 1.
Confidential
11
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.2.2 initPort()
Prototype
Arguments
clientIpAddr_p Required only for IP based communication profile. IP address of client as string
(ending with ‘\0’) (e.g. “127.0.0.1”).
serverIpAddr_p Required only for IP based communication profile. IP address of server as string
(ending with ‘\0’) (e.g. “127.0.0.1”).
serverPort Required only for IP based communication profile. UDP/TCP port of server.
port_p Only for serial . The serial port name as a string(char string, e.g. “”//./COM1” ).
BaudRate [ Only for serial ] The baud rate for communication.(integer, e.g. 9600 ) .
Parity Specifies the parity scheme to be used, 0-4 = no, odd, even, mark, space
max_no_of_conn_retries This argument is used to define the maximum number of retries that client should
perform to connect to server before invoking application error callback . This
Confidential
12
DLMS/COSEM Client SCL User Manual Version 3.15.1
connWaitTimeout 0 - blocking mode, >0 - time in ms for select() timeout in non -blocking mode
Return Value SUCCESS if function succeeds, else FAILURE. (Here SUCCESS is 0, and
FAILURE is 1).
2.2.3 modeEInit()
This function performs the mode E (IEC 62056-21) handshaking before switching to COSEM/ HDLC.
Prototype
Arguments
Return Value SUCCESS if function succeeds, else FAILURE. (Here SUCCESS is 0, and
FAILURE is 1).
Confidential
13
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.2.4 closePort()
Prototype
byte closePort (IntPtr clientHandle)
Arguments
2.2.5 closeClient()
Prototype
Arguments
2.2.6 setParamsHDLC()
Set HDLC parameters in stack. This function will only set HDLC parameters and will not establish
HDLC connection .
NOTE: For users who are familiar with previous versions(versions prior to 3.3.0) of DLMS Client stack,
it shall be noted that sendSNRM() function has been now split into two functions : setParamsHDLC()
and sendSNRM().
Prototype
Confidential
14
DLMS/COSEM Client SCL User Manual Version 3.15.1
Arguments
clientHandle Client handle returned by the initClient() function
addressSize Number of bytes used for addressing the server. Possible values are 1, 2
or 4. When a value of 1 is specified, the destination address (server-
address) contains only 1 byte which contains the Upper HDLC address
of the meter. This can be used for point-to-point communication. In case
of a multi-drop scenario (daisy-chained meters), the address must also
specify the lower HDLC or device-address to identify which physical
device is being addressed. This can use a 2-byte or a 4-byte destination
address. In case of a 2-byte address, the server address has 1-byte
Upper HDLC address and 1-byte Lower HDLC address. In case of 4-
byte addressing, the server-address contains 2-bytes Upper and 2-bytes
Lower HDLC addresses.
ClntID Client id for current association. This is the ID of DLMS client . The client-
ID is used by the server to determine which association in the addressed
Logical-device is to be activated. A value of 16 (0x10) is
predefined by the DLMS standard to specify a Public-Access client. Any
DLMS server must provide at least one Public-Access association. Other
Client IDs supported shall be obtained from meter manufacturer or from
respective project/companion specification.
ServerID Upper HDLC address of the server. This identifies which Logical-device
in the addressed-meter is being queried. Any DLMS server will provide at
least one Logical-device with an address of 1, which indicates the
Management Logical device.
devAddr Lower HDLC address of the server. This is the physical-device address
of the meter. Please note that a physical device can contain multiple
logical devices identified by unique Upper HDLC addresses In turn, each
Logical device can support multiple associations (with different object-lists
and access-rights) defined by unique client-IDs.
windowTx Number of windows receive. This identifies the number of segmented
Confidential
15
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.2.7 sendSNRM()
Function is used to establish a HDLC-MAC connection by sending an SNRM (Set Normal Response Mode)
frame. This function if successful establishes a link layer connection to the Meter. The significant parameters are
the client and server addresses which will be compared by the Meter against its configured list of Association
client IDs and server logical device ids. This function also allows user to make use of optional HDLC parameter
negotiation (Maximum Information Size Transmit and Receive, Maximum windows Size Transmit and
Receive).The user is expected to send the required values, however the final values used in further
communication may be different from these, since the meter will negotiate these parameters and set the
minimum values that is acceptable to both client and server.
Note:- This function is required only for HDLC based communication profile.
Prototype
Arguments
Return Value SUCCESS if function succeeds, else an error code indicating the
reason for error.
Confidential
16
DLMS/COSEM Client SCL User Manual Version 3.15.1
When a value of 1 is specified, the destination address (server-address) contains only 1 byte which
contains the Upper HDLC address of the meter. This can be used for point-to-point communication.
In case of a multi-drop scenario (daisy-chained meters), the address must also specify the lower
HDLC or device-address to identify which physical device is being addressed. This can use a 2-byte
or a 4-byte destination address. In case of a 2-byte address, the server address has 1-byte Upper
HDLC address and 1-byte Lower HDLC address. In case of 4-byte addressing, the server-address
contains 2-bytes Upper and 2-bytes Lower HDLC addresses.
2.2.8 sendDISC()
This function can be used to send the disconnect frame which disconnects both the Link-layer as well
as the Application layers. A DISC frame can be sent after a successful SNRM and also after a
successful Association.
If a DISC frame is not sent after either case above and if there is no further activity from the client, the
DLMS server will automatically go to disconnected mode (DM) after a configured Inactivity timeout.
• Note:- This function is required only for HDLC based communication profile.
Prototype
Arguments
2.2.9 SetParamsCosemWrapper()
Set Application address parameters(Client address and Server Logical address) in stack, in case of
IP(Cosem-Wrapper) communication profile. This function will only set parameters and will not
establish Application Association. This function is required only in IP based communication.
Prototype
Confidential
17
DLMS/COSEM Client SCL User Manual Version 3.15.1
Arguments
2.2.10 SetParamsAARQ
Set Application layer (AARQ) parameters in stack. This function will only set parameters and will not
establish Application Association. This function is required in both IP and HDLC based communication.
Prototype
Arguments
Confidential
18
DLMS/COSEM Client SCL User Manual Version 3.15.1
authenticationKey_p authentication key used for security policies 1 and 3. This key is used in
protecting APDUs exchanged within application
association.encryptionKey_p → encryption key used for ciphered
application contexts. This key is used in protecting APDUs exchanged within
application association.
encryptionKey_p
encryption key used for ciphered application contexts. This key is used in
protecting APDUs exchanged within application association.dedEncKey_p
Confidential
19
DLMS/COSEM Client SCL User Manual Version 3.15.1
globalbroadcastkey
Global broadcast key used to secure broadcast communication between a
DLMS client and several DLMS servers.
priKeyClient Private key to use for signature generation. Either 32 or 48 bytes based on
security suite.
pubKeyServer Public key to use for signature verification. Either 64 or 96 bytes based on
security suite.
auth_mech is 1 : in case of Low level security, this field will be the pointer
to the unsigned character array which contains authentication value.
auth_mech is 2,3,4 and 5: in case of High level security, this field will be the
pointer to the unsigned character array which contains the key used for HLS.
Presently the library expects key to be always 16 bytes long
passwrdLen Length(number of bytes) of the password filled.
maxApduSizeRecv This is the maximum APDU size that the client can receive. This is used only in
LN referencing contexts that support Block transfer. In SN contexts a value of
0xFFFF can be specified.
conformance This is the conformance block that specifies which functional components of the
server are required by the client. This is a number formed by enabling the
appropriate bits corresponding to specified functionality. For more details refer
Appendix B
• For example a value of 0x180000 indicates Read and Write
functions for SN and a value of 0x001818 indicates Get, Set, Block
Transfer with Get and Block Transfer with Set functions. The supplied
conformance block will be negotiated by the server by “AND”-ing with its
own conformance block to return a negotiated value that contains the
functions that are common to both.Example: 0xFFFFFF
Confidential
20
DLMS/COSEM Client SCL User Manual Version 3.15.1
generalGlobalCipher Enumeration indicating the kind of ciphering used for Action service during HLS
0 for service specific global ciphering
1 for General Global ciphering with out system title(System title length =
0)
It shall be noted that this is used only to specify the type of ciphering used in
APDU for Action service used during HLS. This does not have any influence on
ciphering used after Association establishment.
• curUserId Specify the ID for current user information to encode in AARQ request.
Return Value 0 in case of success, otherwise an error code.
2.2.11 sendAARQ()
This function is used to establish an application association which connects the COSEM layers of the client
and server. This can only be called after a successful SNRM which connects the lower layers. The parameters
of the Association must match the settings in the meter for the Association that was identified in the SNRM by
the client and server ids.
Prototype
NOTE: Before calling sendAARQ() user should set Application layer parameters using following
functions
Confidential
21
DLMS/COSEM Client SCL User Manual Version 3.15.1
Arguments
Confidential
22
DLMS/COSEM Client SCL User Manual Version 3.15.1
There are two methods to handle frame counters. In one method, library
will take care of frame counters and user need not interfere at all. In
other method, user can pass frame counter values to library which shall
be used while applying protection. For former method set “userCfg” to 0
and for latter method, user shall set “userCfg” to 1 and also pass frame
counter value in “ frameCounterToUse” variable
2.2.12 SetParamsPreEstablishedAssociation
For pre-established association, the cosem parameters initialized in SetParamsAARQ is not sufficient.
Additional parameters for pre-established association are set by using this function. If Client Server
communication is using HDLC as communication profile, then this function shall be called only after
ensuring a valid HDLC connection. The parameters to initialize application association in client shall be
set by calling SetParamsAARQ.
Confidential
23
DLMS/COSEM Client SCL User Manual Version 3.15.1
Prototype
Arguments
Confidential
24
DLMS/COSEM Client SCL User Manual Version 3.15.1
0xFFFFFF.
maxApduSizeSend This is the maximum APDU size that the client can send in a frame.
Example: 512.
KDEFS_UCHAR cipheringType;
FRAME_COUNTER_CFG *frameCounter;
KDEFS_UCHAR enbCompression;
KDEFS_UCHAR enablebroadcastkey;
}SECURITY_PARAM;
2 authenticated request,
3 encrypted request,
5 authenticated response,
6 encrypted response,
6th and 7th bit of security control byte is reserved for key set and to
enable or disable the compression respectively.
Confidential
25
DLMS/COSEM Client SCL User Manual Version 3.15.1
KDEFS_UCHAR userCfg;
KDEFS_ULONG frameCounterToUse;
}FRAME_COUNTER_CFG;
There are two methods to handle frame counters. In one method, library
will take care of frame counters and user need not interfere at all. In
other method, user can pass frame counter values to library which shall
be used while applying protection. For former method set “userCfg” to 0
and for latter method, user shall set “userCfg” to 1 and also pass frame
counter value in “ frameCounterToUse” variable.
2.2.13 sendRLRQ()
Confidential
26
DLMS/COSEM Client SCL User Manual Version 3.15.1
Prototype
Arguments
KDEFS_UCHAR enablebroadcastkey;
}SECURITY_PARAM;
meaning of each bit in cipheringType as shown below:
0 unused, shall be set to 0,
1 unused, shall be set to 0,
2 authenticated request,
3 encrypted request,
4 digitally signed request,
5 authenticated response,
6 encrypted response,
7 digitally signed response
6th and 7th bit of security control byte is reserved for key set and to
enable or disable the compression respectively.
If 6th bit is 0 or FALSE, it indicates Unicast key is being used. If it is
1 or TRUE, Broadcast Key is being used.
If 7th bit is 0 or FALSE, it indicates compression is disabled and if
7th bit is 1 or TRUE, it indicates compression is enabled.
Confidential
27
DLMS/COSEM Client SCL User Manual Version 3.15.1
There are two methods to handle frame counters. In one method, library
will take care of frame counters and user need not interfere at all. In other
method, user can pass frame counter values to library which shall be used
while applying protection. For former method set “userCfg” to 0 and for
latter method, user shall set “userCfg” to 1 and also pass frame counter
value in “ frameCounterToUse” variable
2.2.14 getData()
This function can be used to get values from the meter. The function accepts the reference to a structure in
which the read data is filled. The definition for this structure can be found in the ICStructs.h header file.
The function automatically checks which context is being used and sends either a Get (for LN contexts) or a
Read (for SN contexts). The referenced structure contains all attributes of all Interface classes supported. The
user of the library is required to only read or process the attribute of the object that was requested. Attempts to
read other attributes or other class objects may result in NULL errors.
Prototype
Arguments
Confidential
28
DLMS/COSEM Client SCL User Manual Version 3.15.1
{
KDEFS_ULONG numDescriptors;
COSEM_ATTR_METH_DESC *cosemAttrMethDesc;
KDEFS_UCHAR useWithList;
}COSEM_ATTR_METH_DESC_LIST;
invokeId Invoke id of the request. Only last 4 bit value will be used for encoding
Range : 0 to 15
securityParam typedef struct SecurityParam{
KDEFS_UCHAR cipheringType;
FRAME_COUNTER_CFG *frameCounter;
KDEFS_UCHAR enbCompression;
KDEFS_UCHAR enablebroadcastkey;
}SECURITY_PARAM;
meaning of each bit in ciphering type is as shown below:Bit Security policy
0 unused, shall be set to 0,
1 unused, shall be set to 0,
2 authenticated request,
3 encrypted request,
4 digitally signed request,
5 authenticated response,
6 encrypted response,
7 digitally signed response
6th and 7th bit of security control byte is reserved for key set and to enable
Confidential
29
DLMS/COSEM Client SCL User Manual Version 3.15.1
There are two methods to handle frame counters. In one method, library
will take care of frame counters and user need not interfere at all. In other
method, user can pass frame counter values to library which shall be used
while applying protection. For former method set “userCfg” to 0 and for
latter method, user shall set “userCfg” to 1 and also pass frame counter
value in “ frameCounterToUse” variable
Confidential
30
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.2.15 cleanupMemory()
This function must be called after the getData() function call, to free the memory allocated by that
function. getData() returns a DLMS_UNION pointer that has various elements allocated dynamically.
Before calling another getData() call, this function must be called to enable the library to clean-up the
memory used.
• NOTE: This function need not be called from a managed code, as it has been already
handled in the wrapper DLL.
Prototype
Arguments •
clientHandle
Client handle returned by the initClient() function
2.2.16 setData()
This function can be used to write data to the meter. Before invoking this function, the write data must be filled
within a DLMS_UNION_CS structure variable. Its address has to be passed through this function.
The user of the library is expected to allocate and fill in a DLMS_UNION_CS structure with the appropriate
attribute data to be set. After the call completes the user is also expected to cleanup and release the memory
used. The client library does not clean-up setdata.
Prototype
IntPtr SetData( IntPtr clientHandle,
SETDATAINFO setDataInfo,
byte priority,
byte serviceClass,
byte invokeId,
SECURITY_PARAM securityParam);
• Arguments
Confidential
31
DLMS/COSEM Client SCL User Manual Version 3.15.1
securityParam
typedef struct SecurityParam {
KDEFS_UCHAR cipheringType;
FRAME_COUNTER_CFG *frameCounter;
KDEFS_UCHAR enbCompression;
KDEFS_UCHAR enablebroadcastkey;
}SECURITY_PARAM;
meaning of each bit in ciphering type is as shown below:
Bit Security policy
0 unused, shall be set to 0,
1 unused, shall be set to 0,
2 authenticated request,
3 encrypted request,
4 digitally signed request,
5 authenticated response,
6 encrypted response,
7 digitally signed response
Confidential
32
DLMS/COSEM Client SCL User Manual Version 3.15.1
6th and 7th bit of security control byte is reserved for key set and to
enable or disable the compression respectively.
If 6th bit is 0 or FALSE, it indicates Unicast key is being used. If it
is 1 or TRUE, Broadcast Key is being used.
If 7th bit is 0 or FALSE, it indicates compression is disabled and if
7th bit is 1 or TRUE, it indicates compression is enabled.
Return Value 0x0000 : List of results in the same sequence as cosem attribute
descriptors filled in request. IntPtr : points to structure:
•
typedef struct ResultInfo{
KDEFS_ULONG numDescriptors;
KDEFS_USHORT *dataResult;
KDEFS_USHORT genResult;
}RESULTINFO;
Non zero :indicates error. See Appendix A for detailed list of error codes
2.2.17 CleanUpMemoryForSet
Clean memory allocated to store set result for each cosem attribute descriptor. User shall call this
function after every setData()
Prototype
Arguments •
Confidential
33
DLMS/COSEM Client SCL User Manual Version 3.15.1
clientHandle
Client handle returned by the initClient() function
2.2.18 executeAction()
This function can be used to execute methods of objects. The method arguments have to be filled in a
structure variable before invoking the function. The definitions of the ACTION_UNION_CS structure can
be found in ICStructs.h file.
Prototype
Arguments
Confidential
34
DLMS/COSEM Client SCL User Manual Version 3.15.1
securityParam
typedef struct SecurityParam {
KDEFS_UCHAR cipheringType;
FRAME_COUNTER_CFG *frameCounter;
KDEFS_UCHAR enbCompression;
KDEFS_UCHAR enablebroadcastkey;
}SECURITY_PARAM;
meaning of each bit in ciphering type is as shown below:
Bit Security policy
0 unused, shall be set to 0,
1 unused, shall be set to 0,
2 authenticated request,
3 encrypted request,
4 digitally signed request,
5 authenticated response,
6 encrypted response,
7 digitally signed response
6th and 7th bit of security control byte is reserved for key set and to enable
or disable the compression respectively.
If 6th bit is 0 or FALSE, it indicates Unicast key is being used. If it is 1 or
TRUE, Broadcast Key is being used.
If 7th bit is 0 or FALSE, it indicates compression is disabled and if 7 th bit is
1 or TRUE, it indicates compression is enabled.
typedef struct FrameCounter
{
KDEFS_UCHAR userCfg;
KDEFS_ULONG frameCounterToUse;
}FRAME_COUNTER_CFG;
There are two methods to handle frame counters. In one method, library
will take care of frame counters and user need not interfere at all. In
other method, user can pass frame counter values to library which shall
be used while applying protection. For former method set “userCfg” to 0
and for latter method, user shall set “userCfg” to 1 and also pass
frame counter value in “ frameCounterToUse” variable.
Return Value 0x0000 : List of results in the same sequence as cosem attribute
Confidential
35
DLMS/COSEM Client SCL User Manual Version 3.15.1
Non zero :indicates error. See Appendix A for detailed list of error codes
2.2.19 createSocket
This function is used to create TCP or UDP sockets. The socket handle returned by the
function shall used to pass as argument on API's expecting TCP/UDP sockets.
In case of TCP sockets, this function shall create sockets, bind to a TCP port and start
listening on the newly created port.
In case of UDP sockets, this function shall create sockets and bind to a UDP port.
Prototype
Arguments
portNum port number through which the socket is to communicate.
commProfile Indicates the chosen communication profile- TCP or UDP.
options 1.Ipv4
2.Ipv6
backlog the limit for the queue of incoming connections
2.2.20 acceptSocket
This function is used to accept incoming connection on TCP sockets. This function shall return a
valid socket number on a valid connection to socket created by createSocket() API.
Prototype
Confidential
36
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.2.21 initIncomingPort
This function initializes all thread to read and process push/ event data received on the TCP/UDP
sockets.
Prototype
Arguments
clientHandle clientHandle returned by initClient().
2.2.22 closeSocket
Prototype
• Arguments
Confidential
37
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.2.23 setParamsUnsolicitedCommunication
• This function is used to set the parameters for unsolicited communication(Server
initiated).
• This parameter shall used to process packets received on server initiated connections.
Prototype
• Arguments
clientHandle clientHandle returned by initClient().
authenticationKey_p authentication key for ciphered application contexts
encryptionKey_p encryption key for ciphered application contexts
serverSystemTitle System title of associated server
clientSystemTitle System title of associated client
serverSystemTitleLen length of system title
authTagLen length of authentication tag
appCntx Application context. Values can be 1, 2, 3 or 4. The application context
defines the referencing method to be used (LN or SN)
1 for LN Association with No ciphering
Confidential
38
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.2.24 registerSecurityCallbacks
This function registers the security callback function. Library shall use the registered
function to encrypt/decrypt, prepare hash values.
Prototype
void registerSecurityCallbacks( CryptCallback encryptFn,
CryptCallback decryptFn,
HashCallback hashFn,
SigGenCallback sigGenFunPtr,
SigVerCallback sigVerFunPtr,
ParseCRTCallback parseCRTFunPtr,
DigKeyPairGenCallback digKeyPairFunPtr,
GetCRTCallback getCRTFunPtr,
DigKeyPairGenCallback digKeyPairFunPtr,
GenSharedKeyCallback genSharedKeyFunPtr,
KeyDerivCallback keyDerivFunPtr,
AssymHashCallback assymHashGenFunPtr,
GetSignKeysCallback getSignKeysFunPtr);
Arguments
Confidential
39
DLMS/COSEM Client SCL User Manual Version 3.15.1
SigGenCallback is defined as :
byte SigGenCallback( IntPtr privateKey,
IntPtr plainText,
uint ptLen,
byte notUsedByteIndex,
IntPtr sig,
IntPtr sigLen,
byte DER_Encoding,
byte SecuritySuite)
This function is used to generate digital signature on the data pointed to by the plainText pointer,
length of which is contained in ptLen. The private key used for signing is held in privateKey pointer,
and the flag DER_Encoding is 1 if DER encoding is to be used. The generated signature is held in sig
pointer with length in sigLen pointer.
SigVerCallback is defined as :
byte SigVerCallback( IntPtr publicKey,
IntPtr plainText,
uint ptLen,
Confidential
40
DLMS/COSEM Client SCL User Manual Version 3.15.1
byte notUsedByteIndex,
IntPtr sig,
uint slen,
byte DER_Encoding,
byte SecuritySuite)
This function is used to verify digital signed data contained in the plainText pointer, length of which is
contained in ptLen. The public key used for verification is held in publicKey pointer, and the flag
DER_Encoding is 1 if DER encoding is used. The signature contained in the packet is passed to this
function through the sig pointer with length in slen pointer.
ParseCRTCallback is defines as :
byte ParseCRTCallback( IntPtr cert,
uint certLen,
IntPtr certificate_publicKey,
IntPtr certificate_Signature,
IntPtr signLen)
This function is used to parse the input certificate, stored in cert pointer with length in certLen variable.
The user is also required to pass the digital signature and its length in pointers certificate_Signature
and signLen. The function parses the certificate and returns the public key stored in the certificate
incertificate_publicKey pointer.
DigKeyPairGenCallback is defined as
byte DigKeyPairGenCallback( IntPtr privateKey,
IntPtr publicKey)
This function is used to generate a pair of keys consisting of private and public key to be used for
digitally signing and verifying data.
GetCertificateIdentificationByserial is defined as
byte DigKeyPairGetCertificateIdentificationByserial( IntPtr serial_number,
byte serial_numberLen,
IntPtr issuer,
byte issuerLen,
IntPtr Certifcate,
uint CertificateLen,
IntPtr CRT,
IntPtr len)
This function is used to obtain a digital keys and certificate on passing serial number and its length,
issuer and length and also the certificate length.CRT is the certificate request pointer.
GetCertCallback is defined as
byte GetCertCallback( IntPtr certBuf_Len_CRT,
IntPtr Cert_Buf,
IntPtr PrivateKey,
IntPtr PublicKey,
IntPtr PublicKey2,
byte flag)
This function is used to obtain a digital certificate on passing the private key and public key in the
PrivateKey and PublicKey pointers. The generated certificate is stored into the Cert_Buf pointer by the
Confidential
41
DLMS/COSEM Client SCL User Manual Version 3.15.1
function, with length in the certBuf_Len_CRT pointer. The arguments PublicKey2 and flag are not used
in the current stack.
GenSharedKeyCallback is defined as
byte GenSharedKeyCallback( IntPtr PrivateKeyServer,
IntPtr PublicKeyClient,
IntPtr result,
byte SecuritySuite)
This function is used in the Key Agreement method (IC64 version 1, method 3) to generate a shared
key. The user is required to pass the private key of the Server and public key of the client into the
PrivateKeyServer and PublicKeyClient pointers, with algorithm ID I in the Algo_ID pointer and system
titles of server and client in the Server_Sys and Client_Sys pointers respectively. The generated
shared key will be contained in the result pointer on execution of this function.
KeyDerivCallback is defined as
byte KeyDerivCallback (IntPtr cntr,
IntPtr sharedSecret,
IntPtr algID,
IntPtr SystitleClient,
IntPtr SystitleServer,
IntPtr DerivedKey,
byte secSuite)
This function is also used in the Key Agreement method (IC64 version 1, method 3) to derive the new
key from the shared key generated by the above function.The user is reured to pass the generated
shared key into sharedSecret pointer, along with required values into the cntr, algID, SystitleClient
(Client System title), SystitleServer(server system title) pointers and the security suite used into the
secSuite argument. The new key to be used will be returned in the DerivedKey pointer.
•
assymHashGenerate is defined as
byte assymHashGenerate( byte hashMethod,
IntPtr plainText_p,
byte ptLen,
IntPtr hash)
This function decrypts the data for HLS Authentication and data transport security. Its arguments
include the hashMethod which indicates the Hashing algorithm used (3 for MD5 and 4 for SHA1, 6 for
SHA256), plainText_p pointer contains the plaintext, length of which is stored in ptLen (ciphertext
length is the same). The function returns the hash which is pointed to by the hash pointer.
getCertificate is defined as
byte getCertificate( IntPtr certSignLen,
IntPtr certBuffer,
IntPtr privKey,
IntPtr pubKey,
IntPtr dlmsInstance)
This function is used to obtain a digital certificate on passing the private key and public key in the
Confidential
42
DLMS/COSEM Client SCL User Manual Version 3.15.1
PrivateKey and PublicKey pointers.Generated certificate is stored in Cert_Buf pointer with length in
the certBuf_Len_CRT pointer.
2.2.25 registerCertCallback
Arguments
certCbk Registers the getCertificate callback function:
byte getCertificate( IntPtr certSignLen,
IntPtr certBuffer,
IntPtr privKey,
IntPtr pubKey,
IntPtr dlmsInstance,
ushort ChannelNo)
2.2.26 registerCipheringKeysCallback
To register call back function to get ciphering keys.
Prototype
void registerCipheringKeysCallback(
CIPHERING_KEYS_CALLBACK cipheringKeysFunPtr)
Arguments
callbackPointer typedef void(*CIPHERING_KEYS_CALLBACK)(void *dlmsInstance,
KDEFS_USHORT ChannelNo,
KDEFS_UCHAR *key,
KDEFS_UCHAR KeyType,
KDEFS_UCHAR operation,
KDEFS_UCHAR secSuite,
KDEFS_UCHAR* SystitleServer);
Confidential
43
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.2.27 registerPushCallback
This function registers the data notification callback function. Library will invoke the
registered function on a valid push processed by library.
Prototype
• Arguments
• callbackPointer
void PUSH_CALLBACK(IntPtr clientHandle, /* uniquely identifies the
communication channel */
2.3.1 registerErrCallback
This function registers the error reporting callback function.
Prototype
• Arguments
• callbackPointer
void ERROR_CALLBACK(IntPtr clientHandle, /* uniquely identifies
the communication channel */
Confidential
44
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.3.2 registerDiagCallback
This function registers the diagnostic callback function.
Prototype
Arguments
callbackPointer Diagnostic callback function pointer.
2.3.3 UpdateHdlcAdvancedSettings
This function is used to configure a delay between the sending of HDLC frames.
Confidential
45
DLMS/COSEM Client SCL User Manual Version 3.15.1
Prototype
• Arguments
• clientHandle Handle returned by initClient()
2.3.4 updateSerialAdvancedSettings
Prototype
byte UpdateSerialAdvancedSettings(IntPtr clientHandle,
ref SER_ADV_PORT_SETTINGS portSettings)
Arguments
clientHandle Handle returned by initClient()
Confidential
46
DLMS/COSEM Client SCL User Manual Version 3.15.1
This is an optional function using which user application can set or change frame counter used by library to
build IV which is used while applying protection to APDUs while sending.
Prototype
void setFrameCouter(void *clientHandle,
KDEFS_ULONG frameCounterToUse)
• Arguments
• clientHandle Handle returned by initClient()
2.3.6 CosemEncodeAXDR
This function is used if user want library to prepare a data communication service request APDU(such as
Get request / Set Request / Action Request) and return the APDU back to user(instead of following the
usual Client state machine where in library send the request to server by library itself).
Prototype
IntPtr CosemEncodeAXDR(SECURITY_PARAM securityParam,
byte appCtxt,
byte SecuritySuite,
byte[] clientSystemTitle,
byte[] ServerSystemTitle,
byte[] authenticationKey,
byte[] encryptionKey,
byte[] globalbroadcastkey,
uint authTagLen,
byte serviceClass,
byte priority,
byte invokeId,
ushort maxApduSizeSend,
byte useGenGloCiph,
Confidential
47
DLMS/COSEM Client SCL User Manual Version 3.15.1
byte useGlobalCiph,
byte service,
uint cosemBufSize,
GENERAL_ATTR_METH_DESC_LIST generalAttrMethDescList,
byte[] privateKey,
ushort channelNo,
byte enableLLCHeader);
• Arguments
securityParam
typedef struct SecurityParam{
KDEFS_UCHAR cipheringType;
FRAME_COUNTER_CFG *frameCounter;
KDEFS_UCHAR enbCompression;
KDEFS_UCHAR enablebroadcastkey;
}SECURITY_PARAM;
meaning of each bit in ciphering type is as shown
below:
Bit Security policy
0 unused, shall be set to 0,
1 unused, shall be set to 0,
2 authenticated request,
3 encrypted request,
4 digitally signed request,
5 authenticated response,
6 encrypted response,
7 digitally signed response
6th and 7th bit of security control byte is reserved for key set and
to enable or disable the compression respectively.
If 6th bit is 0 or FALSE, it indicates Unicast key is being used. If it
is 1 or TRUE, Broadcast Key is being used.
If 7th bit is 0 or FALSE, it indicates compression is disabled and if
7th bit is 1 or TRUE, it indicates compression is enabled.
Confidential
48
DLMS/COSEM Client SCL User Manual Version 3.15.1
SecuritySuite Security suit used for PDU’s generation shall be configured by this
argument. IC64 version 0 supports only security suit 0.
clientSystemTitle_p Client system title used by the library to generate IV required while
applying protection. This parameter will be used only if security policy
demand authentication/encryption to be applied.
ServerSystemTitle_p Server system title is used for generating PDU’s with server system title
encoded in it like Generel signing request..
maxApduSizeSend This is the maximum APDU size that the client can included in a block. If
Confidential
49
DLMS/COSEM Client SCL User Manual Version 3.15.1
the generated request APDU exceeds this value the APDU will be
returned in multiple blocks.
cosemBufSize This is the size of the COSEM Application Layer buffer that hold the
APDU's on the function execution. This should be a large value to hold
the largest possible APDU that may be generated by the function.
Example: 10000
generalAttrMethDescList User can specify one or more cosem attribute /method descriptor which
is being referred in the APDU to be generated.
typedef struct CosemServiceSpecAttrMethDescList {
KDEFS_ULONG numDescriptors;
GENERAL_ATTR_METH_DESC *generalAttrMethDesc;
KDEFS_UCHAR useWithList;
}GENERAL_ATTR_METH_DESC_LIST;
typedef struct ServiceIndepAttrMethDesc{
OBISCODE * obis_p;
KDEFS_USHORT ic;
KDEFS_UCHAR icVersion;
KDEFS_UCHAR attrMethIndex;
void * serviceSpecificData_p;
} GENERAL_ATTR_METH_DESC;
This pointer can hold 3 kinds of data based on the value of service.if
Service is
• 0xC0 then this pointer is optional. If not used then set as NUL.If
Confidential
50
DLMS/COSEM Client SCL User Manual Version 3.15.1
channelNo any ushort value given by user application that can be optionally used
by
• enableLLCHeader Enabling this flag shall generate packet with LLC header. This can be
used to generate packets for HDLC communication profile. Use 0 for IP
based communication.
2.3.7 CosemEncodeAARQ
This function is used if user want library to prepare a AARQ APDU and return the APDU back to
user(instead of following the usual Client state machine where in library send the request to server by
library itself).
Confidential
51
DLMS/COSEM Client SCL User Manual Version 3.15.1
Arguments
Confidential
52
DLMS/COSEM Client SCL User Manual Version 3.15.1
3 for High Level Security (with encrypted password using md5 algorithm)
authenticationKey_p authentication key used for security policies 1 and 3. This key is used in
protecting APDUs exchanged within application association.
encryptionKey_p encryption key used for ciphered application contexts. This key is used
in protecting APDUs exchanged within application association.
0 for No Security
secSuite SecuritySuite of the security object used for the association. It Specifies
Confidential
53
DLMS/COSEM Client SCL User Manual Version 3.15.1
0 for AES_GCM_128
1 for AES_GCM_128_ECDSA_256
2 for AES_GCM_256_ECDSA_384
clientSystemTitle_p Client system title. This should be a string of length 8.This key is used
for generating Initialization Vector used in ciphering .
password auth_mech is 0 : in case of Lowest level security, this field is not used by
library.
maxApduSizeRecv This is the maximum APDU size that the client can receive. This is used
only in LN referencing contexts that support Block transfer. In SN
contexts a value of 0xFFFF can be specified.
curUserId Specify the ID for current user information to encode in AARQ request
Confidential
54
DLMS/COSEM Client SCL User Manual Version 3.15.1
KDEFS_UCHAR enablebroadcastkey;
}SECURITY_PARAM;
Bit Security policy
0 unused, shall be set to 0,
1 unused, shall be set to 0,
2 authenticated request,
3 encrypted request,
4 digitally signed request,
5 authenticated response,
6 encrypted response,
7 digitally signed response
6th and 7th bit of security control byte is reserved for key set and to
enable or disable the compression respectively.
If 6th bit is 0 or FALSE, it indicates Unicast key is being used. If it is 1 or
TRUE, Broadcast Key is being used.
If 7th bit is 0 or FALSE, it indicates compression is disabled and if 7 th bit
is 1 or TRUE, it indicates compression is enabled.
typedef struct FrameCounter {
KDEFS_UCHAR userCfg;
KDEFS_ULONG frameCounterToUse;
}FRAME_COUNTER_CFG;
There are two methods to handle frame counters. In one method, library
will take care of frame counters and user need not interfere at all. In other
method, user can pass frame counter values to library which shall be
used while applying protection. For former method set “userCfg” to 0 and
for latter method, user shall set “userCfg” to 1 and also pass frame
counter value in “ frameCounterToUse” variable
clientChallenge Client challenge
Confidential
55
DLMS/COSEM Client SCL User Manual Version 3.15.1
• cosemBufSize This is the size of the COSEM Application Layer buffer that hold the
APDU's on the function execution. This should be a large value to hold
the largest possible APDU that may be generated by the function.
Example: 10000
privateKey private key used in digital signature
channelNo any ushort value given by user application that can be optionally used
byapplication in future to distinguish the client handle(especially in case
of push/event receipt)
enableLLCHeader Enabling this flag shall generate packet with LLC header. This can be
used to generate packets for HDLC communication profile. Use 0 for IP
based communication.
IntPtr :
Return Value points to.PREPARED_APDU * Structure with list of structures(each
structure contain one APDU block); length of list is indicated in
blockCount
typedef struct PrepareApduParams{
ENCODED_AXDR *cosemPreparedApdu;
KDEFS_USHORT blockCount;
KDEFS_UCHAR curServiceType;
KDEFS_USHORT result;
} PREPARED_APDU;
typedef struct EncodedAXDR{
KDEFS_UCHAR *cosemDataBuf;
KDEFS_USHORT cosemDataLen;
}ENCODED_AXDR;
2.3.8 CleanUpEncodedAXDR
This function must be called after the cosemEncodeAXDR(), cosemEncodeAARQ() and cosemEncodeRLRQ()
functions returned and CleanUpEncodedAXDR() is used by user to free the memory allocated by library during
cosemEncodeAXDR() , cosemEncodeAARQ() and cosemEncodeRLRQ() functions. cosemEncodeAXDR()
returns a PREPARED_APDU pointer that has various elements allocated dynamically. Before calling another
Confidential
56
DLMS/COSEM Client SCL User Manual Version 3.15.1
cosemEncodeAXDR() call, this function must be called to enable the library to clean-up the memory used. Client
user can call this function irrespective of the result(Success/Failure) returned by cosemEncodeAXDR().
Prototype
cleanUpEncodedAXDR(IntPtr preparedAPDU);
Arguments
preparedAPDU This is a pointer to a structure variable which hold the encoded APDU (returned
by cosemEncodeAXDR() function).
• void
Return Value
2.3.9 CosemDecodeAXDR
This function is used if user want library to decode a data communication response APDU(such as Get
response / Set Response / Action Response/AARQ/RLRQ) and return the result and data(if any) in
DLMS UNION(in case of Get response).
IntPtr CosemDecodeAXDR(byte securityPolicy,
byte[] serverSystemTitle,
byte[] authenticationKey,
byte[] encryptionKey,
byte[] globalbroadcastkey,
uint authTagLen,
uint cosemBufSize,
GENERAL_ATTR_METH_DESC_LIST generalAttrMethDescList,
ENCODED_PRIMARY_APDU apduData,
byte[] ClientSystemTitle,
SECURITY_PARAM securityParam,
byte[] publicKey,
ushort channelNo,
byte securitySuite,
byte enableLLCHeader);
Arguments
securityPolicy Security policy(this is used for the library to decide on the kind of protection to
be applied on APDU being generated)
meaning of each bit in ciphering type is as shown elow:
Bit Security policy
0 unused, shall be set to 0,
1 unused, shall be set to 0,
2 authenticated request,
Confidential
57
DLMS/COSEM Client SCL User Manual Version 3.15.1
3 encrypted request,
4 digitally signed request,
5 authenticated response,
6 encrypted response,
7 digitally signed response
serverSystemTitle_p Server system title required for library to generate IV required while verifying
protection
cosemBufSize
This is the size of the COSEM Application Layer buffer that hold the APDU's on
the function execution. This should be a large value to hold the largest possible
APDU that may be handled by the function.Example: 10000
generalAttrMethDescList
User can specify one or more cosem attribute /method descriptor which is
being referred in the APDU to be generated.
ApduData User have to pass the complete response PDU to decode, in this structure. If
the response in received in different block then full response need to be stored
Confidential
58
DLMS/COSEM Client SCL User Manual Version 3.15.1
clientSystemTitle_p will be used in case of block transfer. For example, while decoding an APDU
which is Get response wit data block, this function will also prepare Get request
next block for which client system title is required.
securityParam this will be used in case of block transfer. For example, while decoding an
APDU which is Get response wit data block, this function will also prepare Get
request next block for which client system title is required.
channelNo any ushort value given by user application that can be optionally used by
application in future to distinguish the client handle(especially in case of
push/event receipt)
securitySuite SecuritySuite of the security object used for the association. It Specifies the
security algorithms available.
0 for AES_GCM_128
1 for AES_GCM_128_ECDSA_256
2 for AES_GCM_256_ECDSA_384
enableLLCHeader Enabling this flag shall make function to decode packet with LLC header. This
can be used to generate packets for HDLC communication profile. Use 0 for IP
based communication.
Confidential
59
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.3.10 CleanupDecodedAXDR
This function must be called after the cosemDecodeAXDR() function call, to free the memory allocated
by library during cosemDecodeAXDR() function. This function must be called to enable the library to
clean-up the memory used. Client user can call this function irrespective of the result(Success/Failure)
returned by cosemDecodeAXDR().
Prototype
Arguments
decodedData pointer returned by cosemDecodeAXDR function.
• void
Return Value
2.3.11 cosemDecodeCompactFrameData
This function must be called after the cosemDecodeAXDR() function call, to free the memory allocated by library
during cosemDecodeAXDR() function. This function must be called to enable the library to clean-up the memory
used. Client user can call this function irrespective of the result(Success/Failure) returned by
cosemDecodeAXDR().
Arguments
Confidential
60
DLMS/COSEM Client SCL User Manual Version 3.15.1
2 for Push(if compact frame was received as Push Data Notification callback)
asnList List of ASN1 structures (each structure having template ID and ASN1 string)
ServiceSpecificData DLMS_UNION pointer (in case of get) or VARVALUE pointer contained in the inner
structure of PUSH_STR (in case of push) containing compact frame.
2.3.12 cleanDecodedCompactFrameData
Prototype
Arguments
decodedData DLMS_UNION pointer was returned by cosemDecodeCompactFrameData().
•
Return Value
Confidential
61
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.3.13 getSystemTitleFromPushNotification
This function is used to get system title from a Data notification APDU.
Prototype
Arguments
APDU Data notificaiton APDU input to library as byte array
serverSystemTitle library will search for system title in received data notification APDU and
if found, will update in the memory indicated in this argument
2.3.14 cleanUpencodeComHeader
This function is used to clear the memory allocated by encodeComProfileParams().User need to be
aware that after this function call, the pointer and memory created by library during
encodeComProfileParams() will not more be available
Prototype
Arguments
encodedHdrInfo pointer returned by library in encodeComProfileParams()
• void
Return Value
Confidential
62
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.3.15 encodeComProfileParams
This function is used to encode communication profile header. Communication profile may be either of the
following two :
Wrapper header (Cosem Transport layer) only
Gateway header and Wrapper header
If the function succeeds, library will return the header which application can prefix to the
APDU(generation of APDU need to be done separately using CosemEncodeAXDR or encodeAARQ
or encodeRLRQ functions).
Prototype
Arguments
comProfile Any of the following three values
3 : TCP
4: UDP
9 : GATEWAY
apduLen COSEM APDU Length
Confidential
63
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.3.16 decodeComProfileParams
This function is used to decode an APDU which contain communication profile header(either wrapper
header or both wrapper header and Gateway header
Prototype
IntPtr decodeComProfileParams(COM_HDR_ENC_DATA
decodeComHdr);
Arguments
decodeComHdr COM_HDR_ENC_DATA decodeComHdr - structure containing
Confidential
64
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.3.17 cleanUpdecodedComHeader
This function is used to clear the memory allocated by decodeComProfileParams(). User need to be
aware that after this function call, the pointer and memory created by library during
decodeComProfileParams() will not more be available.
Prototype
Arguments
decodedhdrInfo DECODE_HDR_DATA returned in decodeComProfileParams()
void
Return Value
2.3.18 EncodeHDLCrequest
User can generate HDLC packets from the application layer packet using the EncodeHDLCrequest().
The application layer packet with LLC header is the expected input (Only for I / UI frame). The function
can also used to generate other HDLC frames like RR frame, SNRM, DISC etc.
Prototype
Confidential
65
DLMS/COSEM Client SCL User Manual Version 3.15.1
Arguments
addressSize Number of bytes used for addressing the server. Possible values are 1, 2 or 4.
When a value of 1 is specified, the destination address (server-address)
contains only 1 byte which contains the Upper HDLC address of the meter. This
can be used for point-to-point communication. In case of a multi-drop scenario
(daisy
chained meters), the address must also specify the lower HDLC or device-
address to identify which physical device is being addressed. This can use a 2-
byte or a 4-byte destination address. In case of a 2-byte address, the server
address has 1-byte Upper
HDLC address and 1-byte Lower HDLC address. In case of 4-byte addressing,
the server-address contains 2-bytes Upper and 2- bytes Lower HDLC
addresses. Example: 1
clntID
Client id for current association. This is the ID of DLMS client. The
client-ID is used by the server to determine which association in the
addressed Logical-device is to be activated. A value of 16 (0x10) is
predefined by the DLMS standard to specify a Public Access client. Any
DLMS server must
serverID Upper HDLC address of the server. This identifies which Logical-device
in the addressed-meter is being queried. Any DLMS server will provide at
least one Logical device with an address of 1, which indicates the
Management Logical device Example: 1
devAddr Lower HDLC address of the server. This is the physical-device address of
the meter. Please note that a physical device can contain multiple logical
devices identified by unique
Upper HDLC addresses In turn, each Logical device can support
multiple associations (with different object lists and access-rights) defined
by unique client-IDs Example: 0
windowRx Number of windows receive. This identifies the number of segmented frames
that can be received at a go by this client, before requiring to send a RR
(Request-Ready)
handshake. The DLMS default value is 1. Example: 1
windowTx Number of windows transmit. This identifies the number of segmented frames
that can be transmitted at a go by this client, before requiring a RR (Request-
Ready) handshake from the server. The DLMS default value is 1. Example: 1
infoFieldLenRx Information field length receive. This defines the size of the Info-field part of a
received DLMS frame. The info-field is the carrier of all COSEM data destined to
be processed by the upper Layers. The DLMS default value is 128. Example:
128
Confidential
66
DLMS/COSEM Client SCL User Manual Version 3.15.1
infoFieldLenTx Information field length transmit. This defines the size of the Info-field part of a
transmitted DLMS frame. The info-field is
the carrier of all COSEM data destined to be processed by the upper Layers.
The DLMS default value is 128. Example: 128
linkBufSz HDLC/ IP wrapper buffer size. This is the maximum number of bytes which
needs to be buffered in link layer for both transmission as well as reception. User
should set this value judiciously depending on server's Maximum APDU/block
size transmit/receive. A recommended value can be Maximum Transmit/Receive
APDU size (in case of HDLC HDLC protocol overhead 17 bytes also shall be
added to APDU size to calculate LinkBufSize). Example: 1024
apduData Application layer data along with LLC header shall pass here. This
argument is only applicable to I-frame. Application layer frame (AARQ,
Get Request, Set Request, Action request, .etc) with LLC header (0xE6,
0xE6, 0x00) shall pass here along with number pf bytes.
IntPtr :
Return Value
points to.ENCODED_PRIMARY_APDU * Structure with list of structures(each
structure contain one APDU block); length of list is indicated in blockCount .
Confidential
67
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.3.19 cleanUpEncodedHDLC
• The function used to release the memory allocated by the encodeHDLCrequest() function.
Prototype
Arguments
preparedAPDU This is a pointer to a structure variable which hold the encoded APDU
(returned by encodeHDLCrequest() function).
void
Return Value
2.3.20 DecodeHDLCrequest
User shall extract the application layer+LLC header content from I /UI frames using
DecodeHDLCrequest() function. This function also tells the frame type and information included in it
(Receive sequence number of RR frame, Information size and window size of RR frame, etc). The
function shall return only 1 application layer packets. Also handle segmented I frame.
•
• Arguments
Confidential
68
DLMS/COSEM Client SCL User Manual Version 3.15.1
apduData User have to pass the complete response PDU to decode, in this structure. If the
response in received in different HDLC segments then full response need to be
stored in "apduData" array pointer with each element in the array pointing to
different block data in the order of sequence number. The total number of blocks
need to be stored in "blockCount" element. Partial block input shall return partial
data response.
addressSize Number of bytes used for addressing the server. Possible values are 1, 2 or 4.
When a value of 1 is specified, the destination address (server-address)
contains only 1 byte which contains the Upper HDLC address of the meter. This
can be used for point-to-point communication. In case of a multi-drop scenario
(daisy
chained meters), the address must also specify the lower HDLC or device-
address to identify which physical device is being addressed. This can use a 2-
byte or a 4-byte destination address. In case of a 2-byte address, the server
address has 1-byte Upper
HDLC address and 1-byte Lower HDLC address. In case of 4-byte addressing,
the server-address contains 2-bytes Upper and 2- bytes Lower HDLC
addresses. Example: 1
clntID Number of bytes used for addressing the server. Possible values are 1, 2 or 4.
When a value of 1 is specified, the destination address (server-address)
contains only 1 byte which contains the Upper HDLC address of the meter. This
can be used for point-to-point communication. In case of a multi-drop scenario
(daisy
chained meters), the address must also specify the lower HDLC or device-
address to identify which physical device is being addressed. This can use a 2-
byte or a 4-byte destination address. In case of a 2-byte address, the server
address has 1-byte Upper
HDLC address and 1-byte Lower HDLC address. In case of 4-byte addressing,
the server-address contains 2-bytes Upper and 2- bytes Lower HDLC
addresses. Example: 1
Client id for current association. This is the ID of DLMS client. The client-ID is
used by the server to determine which association in the addressed Logical-
device is to be activated. A value of 16 (0x10) is predefined by the DLMS
standard to specify a Public Access client. Any DLMS server must
provide at least one Public-Access association. Other Client IDs supported shall
be obtained from meter manufacturer or from
respective project/companion specification. Example: 16
serverID Upper HDLC address of the server. This identifies which Logical-device in the
addressed-meter is being queried. Any DLMS server will provide at least one
Logical device with an address of 1, which indicates the Management Logical
device Example: 1
devAddr Lower HDLC address of the server. This is the physical-device address of the
meter. Please note that a physical device can contain multiple logical devices
identified by unique
Upper HDLC addresses In turn, each Logical device can support
Confidential
69
DLMS/COSEM Client SCL User Manual Version 3.15.1
windowRx Number of windows receive. This identifies the number of segmented frames
that can be received at a go by this client, before requiring to send a RR
(Request-Ready)
handshake. The DLMS default value is 1. Example: 1
windowTx Number of windows transmit. This identifies the number of segmented frames
that can be transmitted at a go by this client, before requiring a RR (Request-
Ready) handshake from the server. The DLMS default value is 1. Example: 1
infoFieldLenRx Information field length receive. This defines the size of the Info-field part of a
received DLMS frame. The info-field is the carrier of all COSEM data destined to
be processed by the upper Layers. The DLMS default value is 128. Example:
128
infoFieldLenTx Information field length transmit. This defines the size of the Info-field part of a
transmitted DLMS frame. The info-field is
the carrier of all COSEM data destined to be processed by the upper Layers.
The DLMS default value is 128. Example: 128
cosemBufSize Application size buffer size. This is the maximum number of bytes which needs
to be buffered in application layer for both transmission as well as reception.
User should set this value judiciously depending on server's Maximum APDU. A
recommended value can be Maximum Transmit/Receive APDU size. Example:
1024
Rrr N( R ), Receive sequence number of processed frame. Only valid for RR & T
frame
NULL or valid pointer. The pointer to the structure shall tell you the number of
blocks available in the structure. Only 1 block expected on return. The structure
also includes individual blocks with length field. Data in the buffer on index 0
indicate type of frame. 1- RR frame, 2- I Frame, 3- UA frame, 4 – Partial I frame,
5- UI frame.
In case of complete I-frame segments, full application layer data shall
return with LLC header. 1st byte shall be 2, indicate I frame. Followed by
LLC header and application layer data.
Confidential
70
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.3.21 CleanUpEncodedAXDR
• The function used to release the memory allocated by the decodeHDLCrequest() function.
Prototype
Arguments
preparedAPDU This is a pointer to a structure variable which hold the encoded APDU (returned
by decodeHDLCrequest() function).
void
Return Value
2.3.22 Sendpacket
The function used to release the memory allocated by the decodeHDLCrequest() function.
Confidential
71
DLMS/COSEM Client SCL User Manual Version 3.15.1
Prototype
Arguments
2.3.23 registerWrapperAppDataCallback
The function used register the callback to notify the received bytes on existing TCP/UDP connection.
Prototype
registerWrapperAppDataCallback(APPLNDATA_CALLBACK callbackPointer)
Arguments
callbackPointer The prototype of callbackPointer is
public delegate ushort APPLNDATA_CALLBACK(IntPtr applnDataBuf,
uint appDataLen,
IntPtr clientHandle,
byte wait,
ushort recvPortClient,
ushort recvWPortServer,
byte result).
Confidential
72
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.3.25 setGatewayParams
This function shall be called to initialize DLMS Gateway profile header parameters when gateway
profile is being used in regular synchronous mode of library(i.e. when not using encodeXXX functions).
Prototype
Arguments
clientHandle Handle returned by initClient()
Confidential
73
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.3.26 useDedicatedCiphering
This is an optional function called before a data communication service( Get/ Set/ Action requests) to
change ciphering type( from dedicated ciphering to global ciphering or vice versa).Note that this
setting will be effective for one data communication service only.
Prototype
Arguments
clientHandle Handle returned by initClient()
dedicatedSupport byte – KDEFS_TRIUE for dedicated key usage and KDEFS_FALSE for
global key usage
Return value zero if success, non zero if failed
2.3.27 cosemEncodeRLRQ
This function is used if user want library to prepare a RLRQ APDU and return the APDU back to
user(instead of following
IntPtr the usual Client state machine
cosemEncodeRLRQ(byte appCtxt,where in library send the request to server by
library itself).. byte authMech,
IntPtr authenticationKey_p,
Prototype
IntPtr encryptionKey_p,
IntPtr dedEncKey_p,
IntPtr globalbroadcastkey,
byte securityPolicy,
byte secSuite,
byte authTagLen,
IntPtr clientSystemTitle_p,
IntPtr serverSystemTitle_p,
ushort maxApduSizeRecv,
SECURITY_PARAM securityParam,
uint conformance,
byte reason,
Confidential
byte dedicatedKeyPresent,
74
uint cosemBufSize,
byte serviceClass,
byte[] privateKey,
ushort channelNo
byte enableLLCHeader);
DLMS/COSEM Client SCL User Manual Version 3.15.1
Argument
appContext Application context. Values can be 1, 2, 3 or 4. The
application context defines the referencing method to
be
used (LN or SN)
• 1 for LN Association with No ciphering
• 2 for SN Association with No ciphering
• 3 for LN Association with ciphering
• 4 for SN Association with ciphering.
authMech Authentication mechanism used. Values can be 0, 1,
2, 3, 4, 5, 6 or 7.
0 for Lowest Level Security (without password)
1 for Low Level Security (with static password)
2 for High Level Security (with coded password)
3 for High Level Security (with encrypted password
using md5 algorithm)
4 for High Level Security (with encrypted password
using sha-1 algorithm)
5 for High Level Security (with encrypted password
using GMAC algorithm)
6 for High Level Security (with encrypted password
using SHA-256 algorithm)
7 for High Level Security (with encrypted password
using ECDSA algorithm)
authenticationKey authentication key used for security policies 1 and 3.
This key is used in protecting APDUs exchanged
within application association. Also used for
processing challenge in HLS mechanism id 5.
encryptionKey Encryption key used for ciphered application
contexts and processing challenge in HLS mechanism
id 5. This key is used in protecting APDUs exchanged
within application association.
Confidential
75
DLMS/COSEM Client SCL User Manual Version 3.15.1
0 for AES_GCM_128
1 for AES_GCM_128_ECDSA_256
2 for AES_GCM_256_ECDSA_384
authTagLen Length of GMAC Authentication tag of APDUs used
within Application Association
Possible values are
12(normal Authentication tag)
8(short Authentication tag)
clientSystemTitle Client System title
ServerSystemTitle_p Server System tile
maxApduSize This is the maximum APDU size that the client can
receive. This is used only in LN referencing contexts
that support Block transfer. In SN contexts a value of
0xFFFF can be specified.
0 := this is a special value in DLMS to indicate there is
no limit on PDU size received. It is recommended to
use this value only when necessary(i.e. Some servers
require client max receive PDU size to be 0)
secrtyParam NOTE: this is required only in case of
Confidential
76
DLMS/COSEM Client SCL User Manual Version 3.15.1
encryption/decryption.
}SECURITY_PARAM;
•2 authenticated request,
•3 encrypted request,
•5 authenticated response,
•6 encrypted response,
6th and 7th bit of security control byte is reserved for
key set and to enable or disable the compression
respectively.
If 6th bit is 0 or FALSE, it indicates Unicast key is
being used. If it is 1 or TRUE, Broadcast Key is being
Confidential
77
DLMS/COSEM Client SCL User Manual Version 3.15.1
used.
If 7th bit is 0 or FALSE, it indicates compression is
disabled and if 7th bit is 1 or TRUE, it indicates
compression is enabled.
conformance Proposed conformance to use in AARQ
reason Reason field in RLRQ
dedKeyFlag Set to enable dedicated key encoding in RLRQ
cosemBufSize This is the size of the COSEM Application Layer
buffer that hold the APDU's on the function execution.
This should be a large value to hold the largest
possible APDU that may be generated by the function.
Example: 10000
serviceClass 1 -> confirmed, 0->unconfirmeds
privateKey PrivateKey used for digital signing
channelNo any ushort value given by user application that can
be optionally used by application to distinguish the
client handle.
enableLLCHeader
Enabling this flag shall generate packet with LLC
header. This can be used to generate packets for
HDLC communication profile. Use 0 for IP based
communication.
Return
IntPtr pointing to structure Structure with list of structures(each structure contain
PREPARED_APDU one APDU block); length of list is indicated in
blockCount
Confidential
78
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.3.28 processChallenge
This function is used if user want library to process the challenge based on the HLS authentication
mechanism and return the processed challenge back to user(instead of following the usual Client state
machine where in library send the request to server by library itself).
Prototype
IntPtr processChallenge(IntPtr plainText,
byte length,
IntPtr cipherText,
byte authMech,
IntPtr HLSKey_p,
IntPtr clientSystemTitle_p,
IntPtr ServerSystemTitle_p,
IntPtr encryptionKey_p,
IntPtr authenticationKey_p,
uint frameCounterToUse,
uint SignatureVerify,
byte securitySuite,
byte[] privateKey,
byte[] publicKey)
Argument
plainText The challenge string to process.
length Length of challenge
cipherText Processed challenge shall be available in this pointer. The
pointer shall have sufficient space to hold it the
processed challenge.
authMech Client system title used by the library to generate IV required
while applying protection. This parameter will be used
only if security policy demand
authentication/encryption to be applied.
HLSKey_p HLS secret
clientSystemTitle_p Client system title
ServerSystemTitle Server system title
encryptionKey Encryption key
authenticationKey_p Authentication key.
frameCounterToUse Frame counter. Applicable only or authentication mechanism
Confidential
79
DLMS/COSEM Client SCL User Manual Version 3.15.1
available.
0 for AES_GCM_128
1 for AES_GCM_128_ECDSA_256
2 for AES_GCM_256_ECDSA_384
privateKey Privatekey used for digital signing
PublicKey Publickey used for signature verification
Return
void
2.3.29 setFrameCounter
This is an optional function using which user application can set or change frame counter used by
library to build IV which is used while applying protection to APDUs while sending.
Prototype
Argument
clientHandle Handle returned by initClient()
frameCounterToUse Frame counter to be used - 32 bit integer
value
Return
2.3.30 cleanPushData
After using push data received via Push call back function, user shall call cleanPushData() to free
dynamically allocated memory.
Prototype
Argument
PUSH_STR decodedData Push structure
Confidential
80
DLMS/COSEM Client SCL User Manual Version 3.15.1
Return
2.3.31 getAssociationParameters
This function shall be called by user to get specific application layer and link layer parameters of
current association. The argument passed is the handle returned by initClient(). The return value is a
structure holding the parameters of current association.
Prototype
IntPtr getAssociationParameters(IntPtr ClientHandle);
Argument
IntPtr ClientHandle Handle returned by initClient
Return
2.3.32 cleanEventData
After using event data received via Event call back function, user shall call cleanEventData() to free
dynamically allocated memory.
Prototype
2.3.33 getEvent
Call back function registered using registerEventCallback() will be called by library when one / more
events are received. Call back function is only meant to notify user-application about receipt of event
and event information is not send in call back function. Client user-application shall retrieve events
separately by calling API : getEvent().
Prototype
getEvent(IntPtr clientHandle, ushort len);
Confidential
81
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.3.34 triggerEventNotification
This function shall be called by user to get specific application layer and link layer parameters of
current association. The argument passed is the handle returned by initClient(). The return value is a
structure holding the parameters of current association.
Prototype
Argument
IntPtr ClientHandle Handle returned by initClient
Return
2.3.35 imageTransfer
Prototype
ushort imageTransfer(IntPtr clientHandle,
byte cipheringType,
byte clientID,
IntPtr servLogID_p,
IntPtr servPhyID_p,
byte serverAddrLen,
byte broadCastFlag,
ushort numServers,
byte appContext,
byte authMechLevel,
IntPtr authValue_p,
byte authValLen,
IntPtr authenticationKey_p,
IntPtr encryptionKey_p,
IntPtr dedEncKey_p,
byte securityPolicy,
IntPtr clientSystemTitle_p,
ushort clientMaxReceivePduSz,
[MarshalAs(UnmanagedType.LPStr)] string fileName,
IntPtr identifierName,
OBISCODE obj,
ushort delay);
Arguments:
IntPtr clientHandle
byte cipheringType
byte clientID
IntPtr servLogID_p
IntPtr servPhyID_p
Confidential
82
DLMS/COSEM Client SCL User Manual Version 3.15.1
byte serverAddrLen
byte broadCastFlag
ushort numServers
byte appContext
byte authMechLevel
IntPtr authValue_p
byte authValLen
IntPtr authenticationKey_p
IntPtr encryptionKey_p
IntPtr dedEncKey_p
byte securityPolicy
IntPtr clientSystemTitle_p
ushort clientMaxReceivePduSz
[MarshalAs(UnmanagedType.LPStr)] string fileName
IntPtr identifierName
OBISCODE obj
ushort delayIntPtr clientHandle
byte cipheringType
byte clientID
IntPtr servLogID_p
IntPtr servPhyID_p
byte serverAddrLen
byte broadCastFlag
ushort numServers
byte appContext
byte authMechLevel
IntPtr authValue_p
byte authValLen
IntPtr authenticationKey_p
IntPtr encryptionKey_p
IntPtr dedEncKey_p
byte securityPolicy
IntPtr clientSystemTitle_p
ushort clientMaxReceivePduSz
MarshalAs(UnmanagedType.LPStr)] string fileName
IntPtr identifierName
OBISCODE obj
ushort delay
Return
zero if success, non zero if failed
2.4.1 DLMS_UNION_CS
The DLMS_UNION_CS structure is not a UNION, but a structure with all supported Interface-Class object
structures within. This structure is the means to pass data between the user-application and the library. In case
of Get/Read operations, the structure is allocated, filled-in and passed to the user-application from the library. In
case of Set/Write operations, the user-application must allocate, fill-in and pass the structure to the library.
Please refer the corresponding IC files file for complete structure definitions.
Confidential
83
DLMS/COSEM Client SCL User Manual Version 3.15.1
In case of Set/Write the user-application must also handle the freeing of memory allocated to the structure (In
Get/Read, simply calling the cleanupMemory() function in the library will do)
Definition
public struct DLMS_UNION_CS
{
public byte result;
public GENIC_CS genericIc;
public DATA_CS data;
public REGISTER_CS register;
public EXTREGISTER_CS extRegister;
public DEMANDREG_CS dmdRegister;
public REGISTER_ACTIVATION_CS regAct;
public PROFILE_CS profile;
public CLOCK clock;
public SCRIPT_TABLE_CS scriptTable;
public SCHEDULE_CS schedule;
public SPECDAYTABLE_CS specDaysTable;
public ACTIVITYCALENDAR_CS actCal;
public REG_MONITOR_CS regMonitor;
public ASSOC_LN_CS assocLN;
public ASSOC_SN_CS assocSN;
public SAPASSIGN_CS SAPAssign;
public IMAGE_TRANSFER_CS imageTransfer;
public SINGLEACTIONSCHEDULE_CS SingleActionSchedule;
public IECLOCALPORT_CS IECLocal;
public MBUS_SLAVEPORT_SETUP mbusSlavePortSetup;
public UTILITY_TABLE_CS utilityTable;
public PSTNMODEMCONFIG_CS PSTNmc;
public PSTN_AUTOANSWER_CS PSTNAutoAnswer;
public AUTOCONNECT_CS autoConnect;
public HDLC_SETUP hdlcSetup;
public PUSH_SETUP_CS pushSetup;
public TCPUDPSETUP tcpUdpSetup;
public IPv4SETUP_CS ipv4;
public IPv6_SETUP_CS ipv6;
public ETHERNETSETUP_CS ethernetSetup;
public PPP_SETUP_CS pppSetup;
public GPRSMODEMSETUP_CS GPRSModemSetup;
public SMTPSETUP_CS SMTPSetup;
public GSM_DIAG_CS gsmDiag;
public LLC432SETUP_CS LLC432Setup;
public LLC80222T1SETUP_CS LLC80222T1Setup;
public LLC80222T2SETUP_CS LLC80222T2Setup;
public LLC80222T3SETUP_CS LLC80222T3Setup;
public REGISTER_TABLE_CS registerTable;
public SECURITY_SETUP securitySetup;
public COMPACT_DATA_CS compactData;
public PARAMETER_MONITOR_CS paramMonitor;
public SENSOR_MANAGER_CS sensorManager;
public DISC_CONTROL discControl;
public LIMITER_CS limiter;
Confidential
84
DLMS/COSEM Client SCL User Manual Version 3.15.1
2.4.2 ACTION_UNION_CS
The ACTION_UNION_CS structure is similar in procedure to the Set/Write operation. (In fact when using SN
referencing the executeAction() method actually sends a Write command). When calling executeAction(), the
user-application must allocate, fill-in and pass this structure to the library.
Definition
public struct ACTION_UNION_CS
{
public GENERIC_IC_ACTION_CS genAction;
public REG_ACTN regAct;
public EXT_REG_ACTN exRegAct;
public DMD_REG_ACT dmdRegAct;
public REG_ACT_ACT_CS regActivationAct;
public PROF_ACTN profAct;
public CLOCK_ACTN clockAct;
public SCR_TAB_ACTN scrAct;
public SCHEDULE_ACTN_CS schedActn;
public SPEC_DAY_TAB_ACTN spDayAct;
public ACT_CAL_ACTN actCalAct;
public ASSOC_LN_ACTN_CS assocLNAct;
public ASSOC_SN_ACTN_CS assocSNAct;
Confidential
85
DLMS/COSEM Client SCL User Manual Version 3.15.1
encrypt/decrpyt
encrypt(byte encMeth,
IntPtr key,
ushort keyLen,
IntPtr plainText_p,
uint ptLen,
IntPtr cipherText_p,
IntPtr initialisationVector,
ushort ivLen,
IntPtr aad,
uint aadLen,
IntPtr authTag,
uint authTagLen)
decrypt(byte encMeth,
Confidential
86
DLMS/COSEM Client SCL User Manual Version 3.15.1
IntPtr key,
ushort keyLen,
IntPtr plainText_p,
uint ptLen,
IntPtr cipherText_p,
IntPtr initialisationVector,
ushort ivLen,
IntPtr aad,
uint aadLen,
IntPtr authTag,
uint authTagLen)
The function encrypt encrypts he data for HLS Authentication and data transport security and
the function decrypt performs the corresponding decryption. The variable definitions are as
follows
encMeth - Identifies the encryption used. The values are 2 for encryption using AES used in challenge
for HLS Mechanism_Id(2) and 5 for encryption using GCM used in HLS_Mechanism_ID(5) and for
data transport security(ciphering)
key - The secret key required for encryption
keyLen - The key length in bytes
plainText_p - The plain text. It will contain the challenge for authentication mechanism and frame the
to be encrypted in case of encryption and the decrypted output obtained in case of decryption.
ptLen - The length of the plain text (cipher text length is the same)
cipherText_p - The cipher text. It will contain the data to be decrypted in case of decryption and
encrypted data output in case of encryption
initialisationVector - The initialization vector used in GCM encryption
ivLen - The length of the initialization vector(will be 12 bytes in DLMS)
aad - The additional authentication data used in GCM encryption
aadLen - The length of the aad
authTag - pointer to authentication tag. This should be filled with authentication tag generated after
encryption if aad is not empty. The length of authTag is fixed at 12 bytes.
AuthTagLen - Length of authTag hash function
computeHash(byte hashMethod,
IntPtr plainText_p,
ushort ptLen,
IntPtr cipherText_p)
Confidential
87
DLMS/COSEM Client SCL User Manual Version 3.15.1
Confidential
88
DLMS/COSEM Client SCL User Manual Version 3.15.1
Confidential
89
DLMS/COSEM Client SCL User Manual Version 3.15.1
byte secSuite)
This function is also used in the Key Agreement method (IC64 version 1, method 3) to derive the new
key from the shared key generated by the above function.The user is required to pass the generated
shared key into sharedSecret pointer, along with required values into the cntr, algID, SystitleClient
(Client System title), SystitleServer(server system title) pointers and the security suite used into the
secSuite argumemnt. The new key to be used will be returned in the DerivedKey pointer.
Confidential
90
DLMS/COSEM Client SCL User Manual Version 3.15.1
genSharedKey256FunPtr,
KeyDerivCallback
keyDerivFunPtr,
AssymHashCallback
assymHashGenFunPtr,
GetSignKeysCallback
getSignKeysFunPtr);
NOTE: A sample implementation of the security callback functions for Windows/Linux based on the
publicly available LibTomCrypt library is available from us on demand.
3 Call Sequence
registerSecurityCallbacks(), optional. Global setting, and the call needs to be made only once.
registerDiagCallback(), optional. Global setting, and the call needs to be made only once. For description, see
Chapter 4.
initClient()
initPort()
modeEInit() only for HDLC based communication profile, and opening mode is Mode E
sendAARQ()
setData()
executeAction()
Finally
sendRLRQ()
closePort()
closeClient()
Confidential
91
DLMS/COSEM Client SCL User Manual Version 3.15.1
Please note that you can go back to sendSNRM() after doing a sendDISC() and continue polling another meter
(or another association/logical-device in the same meter). HDLC functions (modeEInit(), sendSNRM(),
sendDISC()) are not used for TCP/ UDP based communication profile.
4 Debugging Options
Debugging options are provided for troubleshooting and analyzing the DLMS frames sent and received by the
client. To enable debugging options, a function as follows is used.
void diagcallback (IntPtr clientHandle,
byte layerId,
byte diagType,
IntPtr pMsg,
uint msgLen,
ushort ChannelNo)
OEM should write their own code inside this function to print or log the diagnostic message. The string pMsg will
have the message. Variable clientHandle contains the handle returned by the initClient() function, layerId
contains the source id of the message, ie whether the message is from physical layer or application layer,
diagType shows whether it is an information message, error message or a communication frame.There is a
sample implementation of this function which prints the data-link and application layer frames to the output
device. However a callback to this function is be passed to SCL via registerDiagCallback() function with
definition as follows
void registerDiagCallback(DiagCallback callbackPointer)
The argument callbackPointer is the pointer to the diagcallback function defined by the user.
The DLMS Client Dot Net version is designed to run on both windows and Linux platform. To build the libraries to
to run on LINUX (Same project ill run on windows), user has to uncomment the LINUX_SUPPORT macro in the
DLMSClient.cs file. Replace the WinSecurity\Linux_DotNet\security.cs in the WinDLMSClientApp folder.
To generate shared object library to run in LINUX, Execute the make file using the command “make dotnet”
from LINUXDLMSCLIENT folder. Run the compilesecuritylibdotnet.sh script in the LinuxAsymSecurity folder
to generate the asymmetric security shared object library. Run the compilesecuritylibdotnet.sh script in the
LinuxSecurity folder to generate symmetric security shared object library.
The Same C# application and wrapper DLL build for LINUX platform can run for Windows operating system, The
name of DLL need to change to use it in Widows OS. Required DLL names are given below.
• DLMSSecurity.dll
Confidential
92
DLMS/COSEM Client SCL User Manual Version 3.15.1
• AsymmDLMSSecurity.dll
• DLMSClient.dll
The corresponding projects are configured with “LINUX” build configuration to generate DLL with
required names.
Confidential
93
DLMS/COSEM Client SCL User Manual Version 3.15.1
6 Appendix A
6.1 Return Codes in SCL
Confidential
94
DLMS/COSEM Client SCL User Manual Version 3.15.1
state-error:
service-not-allowed (1),
• service-unknown (2)
service-error:
operation-not-possible (1),
service-not-supported (2),
other-reason (3)
0x00XX (upper byte = 0x00, lower byte XX = error code returned by DLMS Server – see below –
excerpt taken from DLMS UA Green book)
Confidential
95
DLMS/COSEM Client SCL User Manual Version 3.15.1
Confidential
96
DLMS/COSEM Client SCL User Manual Version 3.15.1
: T LN with no Ciphering
Application contexts T SN with no Ciphering
T LN with Ciphering
T SN with Ciphering
T Suite 0
Security Suites T Suite 1
Confidential
97
DLMS/COSEM Client SCL User Manual Version 3.15.1
T Suite 2
Confidential
98
DLMS/COSEM Client SCL User Manual Version 3.15.1
Confidential
99
DLMS/COSEM Client SCL User Manual Version 3.15.1
Confidential
100
DLMS/COSEM Client SCL User Manual Version 3.15.1
Alphabetical Index
ACTION_UNION_CS.............................................................................................................................84
Call Sequence........................................................................................................................................89
Client Library Functions.........................................................................................................................10
Debugging Options................................................................................................................................90
DLMS_UNION_CS................................................................................................................................82
Implementation......................................................................................................................................10
Introduction..............................................................................................................................................9
Key Features............................................................................................................................................9
Multichannel Operation..........................................................................................................................90
Overview................................................................................................................................................10
Overview of The Protocol Stack...............................................................................................................9
Return Codes in SCL.............................................................................................................................92
Sample Implementations.........................................................................................................................9
Security Implementation........................................................................................................................85
Structures and Unions...........................................................................................................................82
Confidential
101