Wireless M-Bus Support#

The Wireless M-Bus Support component adds minimalist support for coding and decoding Wireless M-Bus packets. This component is essential for applications that need to communicate using the Wireless M-Bus protocol, providing the necessary tools to handle packet formatting and interpretation.

Key Features:

  • Packet Coding and Decoding: Functions to encode and decode Wireless M-Bus packets, ensuring correct data formatting for transmission and reception.

  • Function Codes: Defines a set of function codes used in the first block's C-field, such as WMBUS_FUNCTION_SND_NKE, WMBUS_FUNCTION_SND_UD, and WMBUS_FUNCTION_SND_NR.

  • Device Types: Supports various device types used in address fields, including oil meters, electricity meters, gas meters, and more.

  • Manufacturer ID: Functions to retrieve the manufacturer ID (M-field) for M-Bus addressing.

  • Encryption and Decryption: Includes functions for encrypting and decrypting Wireless M-Bus frames using the Crypto5 algorithm.

Modules#

Configurations

Type definitions

Functions#

uint16_t
sl_rail_sdk_wmbus_phy_software(uint8_t *buffer, uint8_t length, uint16_t buffer_length)

Runs the required software based phy processes on the buffer, depending on the mode.

Get the current Wireless M-Bus accessibility settings.

void
sl_rail_sdk_wmbus_set_accessibility(sl_rail_sdk_wmbus_accessibility_t new_wmbus_accessibility)

Set the current Wireless M-Bus accessibility settings.

void

Initializes the MBUS and its mode.

void
sl_rail_sdk_wmbus_set_mode(sl_rail_sdk_wmbus_mode_t mode)

Sets the MBUS mode to use.

Gets the selected Wireless M-Bus mode.

uint32_t

Returns the delay after TX when RX should start in limited accessibility sl_rail_sdk_wmbus_set_mode should be called before using this function.

uint32_t

Returns the delay after TX when RX should stop in limited accessibility sl_rail_sdk_wmbus_set_mode should be called before using this function.

uint8_t
sl_rail_sdk_wmbus_frame_add_payload_int8(uint8_t *buffer, sl_rail_sdk_wmbus_frame_dib_function_t dibFunction, uint8_t vib, int8_t value)

Helper function for building the payload of a Wireless M-Bus frame.

uint8_t
sl_rail_sdk_wmbus_frame_add_payload_int16(uint8_t *buffer, sl_rail_sdk_wmbus_frame_dib_function_t dibFunction, uint8_t vib, int16_t value)

Helper function for building the payload of a Wireless M-Bus frame.

uint8_t
sl_rail_sdk_wmbus_frame_add_payload_int32(uint8_t *buffer, sl_rail_sdk_wmbus_frame_dib_function_t dibFunction, uint8_t vib, int32_t value)

Helper function for building the payload of a Wireless M-Bus frame.

uint16_t
sl_rail_sdk_wmbus_frame_add_idle_filler(uint8_t *buffer, uint16_t fillerLength)

Helper function for building the payload of a Wireless M-Bus frame.

uint16_t

Helper function for converting uppercase ASCII letters to 2B manufacturer ID.

void
sl_rail_sdk_wmbus_frame_mfield_to_chars(const uint16_t mfield, char *manuf)

Helper function for converting 2B manufacturer ID to 3 uppercase ASCII letter.

void

Initializes crypto engine.

void

Sets key for mode5 encryption/decryption (AES-CBC)

void

Returns key for mode5 encryption/decryption (AES-CBC)

uint8_t
sl_rail_sdk_wmbus_frame_crypto5_encrypt(uint8_t *input, uint8_t *output, uint8_t *iv, uint16_t length, uint8_t encryptedBlocks)

Encrypts blocks using mode5 (AES-CBC) encryption.

void
sl_rail_sdk_wmbus_frame_crypto5_decrypt(uint8_t *input, uint8_t *output, uint8_t *iv, uint16_t length)

Decrypts blocks using mode5 (AES-CBC) encryption.

uint16_t
sl_rail_sdk_wmbus_setup_frame(uint8_t *buffer, uint8_t access_number, sl_rail_sdk_wmbus_accessibility_t accessibility, sl_rail_sdk_wmbus_device_type_t new_device_type, sl_rail_sdk_wmbus_sensor_data_t *sensors_data, bool periodic, bool encrypt)

Sets up a Wireless M-Bus frame.

Function Documentation#

sl_rail_sdk_wmbus_phy_software#

uint16_t sl_rail_sdk_wmbus_phy_software (uint8_t * buffer, uint8_t length, uint16_t buffer_length)

Runs the required software based phy processes on the buffer, depending on the mode.

Parameters
[inout]buffer

The buffer that holds the data, and what will hold the processed data

[in]length

Length of the input buffer

[in]buffer_length

Size of the buffer, to prevent writing outside of the buffer

The buffer must be big enough to hold the processed data. Currently, only T mode's Meter to Other requires software based crc and 3of6 encoding. For that, the buffer should be at 436B long for the longest packet. All other modes passes through this call without modifications sl_rail_sdk_wmbus_set_mode should be called before using this function.

Returns

  • The length of the processed packet, that can be passed to the hardware, or 0 on error


Definition at line 306 of file /mnt/raid/workspaces/ws.bVpTDXqvc/overlay/gsdk/app/rail/component/sl_rail_sdk_wmbus_support/sl_rail_sdk_wmbus_support.h

sl_rail_sdk_wmbus_get_accessibility#

sl_rail_sdk_wmbus_accessibility_t sl_rail_sdk_wmbus_get_accessibility (void )

Get the current Wireless M-Bus accessibility settings.

Parameters
N/A

Returns

  • the current value


Definition at line 313 of file /mnt/raid/workspaces/ws.bVpTDXqvc/overlay/gsdk/app/rail/component/sl_rail_sdk_wmbus_support/sl_rail_sdk_wmbus_support.h

sl_rail_sdk_wmbus_set_accessibility#

void sl_rail_sdk_wmbus_set_accessibility (sl_rail_sdk_wmbus_accessibility_t new_wmbus_accessibility)

Set the current Wireless M-Bus accessibility settings.

Parameters
[in]new_wmbus_accessibility

to be applied


Definition at line 319 of file /mnt/raid/workspaces/ws.bVpTDXqvc/overlay/gsdk/app/rail/component/sl_rail_sdk_wmbus_support/sl_rail_sdk_wmbus_support.h

sl_rail_sdk_wmbus_init#

void sl_rail_sdk_wmbus_init (void )

Initializes the MBUS and its mode.

Parameters
N/A

Definition at line 324 of file /mnt/raid/workspaces/ws.bVpTDXqvc/overlay/gsdk/app/rail/component/sl_rail_sdk_wmbus_support/sl_rail_sdk_wmbus_support.h

sl_rail_sdk_wmbus_set_mode#

void sl_rail_sdk_wmbus_set_mode (sl_rail_sdk_wmbus_mode_t mode)

Sets the MBUS mode to use.

Parameters
[in]mode

is the desired mode of the Wireless M-Bus

Currently only used to init and enable GPCRC for T mode Tx, and it also changes the time returned by sl_rail_sdk_wmbus_get_meter_limited_acc_rx_start().


Definition at line 333 of file /mnt/raid/workspaces/ws.bVpTDXqvc/overlay/gsdk/app/rail/component/sl_rail_sdk_wmbus_support/sl_rail_sdk_wmbus_support.h

sl_rail_sdk_wmbus_get_selected_mode#

sl_rail_sdk_wmbus_mode_t sl_rail_sdk_wmbus_get_selected_mode (void )

Gets the selected Wireless M-Bus mode.

Parameters
N/A

Returns

  • The selected mode of the Wireless M-Bus


Definition at line 340 of file /mnt/raid/workspaces/ws.bVpTDXqvc/overlay/gsdk/app/rail/component/sl_rail_sdk_wmbus_support/sl_rail_sdk_wmbus_support.h

sl_rail_sdk_wmbus_get_meter_limited_acc_rx_start#

uint32_t sl_rail_sdk_wmbus_get_meter_limited_acc_rx_start (bool slowMode)

Returns the delay after TX when RX should start in limited accessibility sl_rail_sdk_wmbus_set_mode should be called before using this function.

Parameters
[in]slowMode

True in case of slow mode. Only used in mode C and F

Returns

  • The delay in microseconds


Definition at line 351 of file /mnt/raid/workspaces/ws.bVpTDXqvc/overlay/gsdk/app/rail/component/sl_rail_sdk_wmbus_support/sl_rail_sdk_wmbus_support.h

sl_rail_sdk_wmbus_get_meter_limited_acc_rx_stop#

uint32_t sl_rail_sdk_wmbus_get_meter_limited_acc_rx_stop (bool slowMode)

Returns the delay after TX when RX should stop in limited accessibility sl_rail_sdk_wmbus_set_mode should be called before using this function.

Parameters
[in]slowMode

True in case of slow mode. Only used in mode C and F

Returns

  • The delay in microseconds


Definition at line 362 of file /mnt/raid/workspaces/ws.bVpTDXqvc/overlay/gsdk/app/rail/component/sl_rail_sdk_wmbus_support/sl_rail_sdk_wmbus_support.h

sl_rail_sdk_wmbus_frame_add_payload_int8#

uint8_t sl_rail_sdk_wmbus_frame_add_payload_int8 (uint8_t * buffer, sl_rail_sdk_wmbus_frame_dib_function_t dibFunction, uint8_t vib, int8_t value)

Helper function for building the payload of a Wireless M-Bus frame.

Parameters
[in]buffer

The buffer to write into. Should point at the first free byte

[in]dibFunction

Function field in the DIB (Data Information Block)

[in]vib

Value information block containing the VIF (Value Information Field)

[in]value

The value of the data block.

Adds an 8 bit integer (binary) data block to a buffer. Returns

  • the number of bytes written into buffer


Definition at line 373 of file /mnt/raid/workspaces/ws.bVpTDXqvc/overlay/gsdk/app/rail/component/sl_rail_sdk_wmbus_support/sl_rail_sdk_wmbus_support.h

sl_rail_sdk_wmbus_frame_add_payload_int16#

uint8_t sl_rail_sdk_wmbus_frame_add_payload_int16 (uint8_t * buffer, sl_rail_sdk_wmbus_frame_dib_function_t dibFunction, uint8_t vib, int16_t value)

Helper function for building the payload of a Wireless M-Bus frame.

Parameters
[in]buffer

The buffer to write into. Should point at the first free byte

[in]dibFunction

Function field in the DIB (Data Information Block)

[in]vib

Value information block containing the VIF (Value Information Field)

[in]value

The value of the data block.

Adds a 16 bit integer (binary) data block to a buffer. Returns

  • the number of bytes written into buffer


Definition at line 385 of file /mnt/raid/workspaces/ws.bVpTDXqvc/overlay/gsdk/app/rail/component/sl_rail_sdk_wmbus_support/sl_rail_sdk_wmbus_support.h

sl_rail_sdk_wmbus_frame_add_payload_int32#

uint8_t sl_rail_sdk_wmbus_frame_add_payload_int32 (uint8_t * buffer, sl_rail_sdk_wmbus_frame_dib_function_t dibFunction, uint8_t vib, int32_t value)

Helper function for building the payload of a Wireless M-Bus frame.

Parameters
[in]buffer

The buffer to write into. Should point at the first free byte

[in]dibFunction

Function field in the DIB (Data Information Block)

[in]vib

Value information block containing the VIF (Value Information Field)

[in]value

The value of the data block.

Adds a 32 bit integer (binary) data block to a buffer. Returns

  • the number of bytes written into buffer


Definition at line 397 of file /mnt/raid/workspaces/ws.bVpTDXqvc/overlay/gsdk/app/rail/component/sl_rail_sdk_wmbus_support/sl_rail_sdk_wmbus_support.h

sl_rail_sdk_wmbus_frame_add_idle_filler#

uint16_t sl_rail_sdk_wmbus_frame_add_idle_filler (uint8_t * buffer, uint16_t fillerLength)

Helper function for building the payload of a Wireless M-Bus frame.

Parameters
[in]buffer

The buffer to write into. Should point at the first free byte

[in]fillerLength

Number of bytes to fill.

Adds filler bytes required before encryption Returns

  • the number of bytes written into buffer


Definition at line 407 of file /mnt/raid/workspaces/ws.bVpTDXqvc/overlay/gsdk/app/rail/component/sl_rail_sdk_wmbus_support/sl_rail_sdk_wmbus_support.h

sl_rail_sdk_wmbus_frame_chars_to_mfield#

uint16_t sl_rail_sdk_wmbus_frame_chars_to_mfield (const char * manuf)

Helper function for converting uppercase ASCII letters to 2B manufacturer ID.

Parameters
[in]manuf

Pointer to a 3 element char array, containing the uppercase letters of the manufacturer assigned by also known as DLMS FLAG ID

Returns

  • the manufacturer id (or M-field) for M-Bus addressing


Definition at line 416 of file /mnt/raid/workspaces/ws.bVpTDXqvc/overlay/gsdk/app/rail/component/sl_rail_sdk_wmbus_support/sl_rail_sdk_wmbus_support.h

sl_rail_sdk_wmbus_frame_mfield_to_chars#

void sl_rail_sdk_wmbus_frame_mfield_to_chars (const uint16_t mfield, char * manuf)

Helper function for converting 2B manufacturer ID to 3 uppercase ASCII letter.

Parameters
[in]mfield

mfield value

[out]manuf

pointer to a 3 element char array to write the 3 letters


Definition at line 424 of file /mnt/raid/workspaces/ws.bVpTDXqvc/overlay/gsdk/app/rail/component/sl_rail_sdk_wmbus_support/sl_rail_sdk_wmbus_support.h

sl_rail_sdk_wmbus_frame_crypto5_init#

void sl_rail_sdk_wmbus_frame_crypto5_init (void )

Initializes crypto engine.

Parameters
N/A

Definition at line 429 of file /mnt/raid/workspaces/ws.bVpTDXqvc/overlay/gsdk/app/rail/component/sl_rail_sdk_wmbus_support/sl_rail_sdk_wmbus_support.h

sl_rail_sdk_wmbus_frame_crypto5_set_key#

void sl_rail_sdk_wmbus_frame_crypto5_set_key (const uint8_t * newKey)

Sets key for mode5 encryption/decryption (AES-CBC)

Parameters
[in]newKey

16B array containing the new key


Definition at line 435 of file /mnt/raid/workspaces/ws.bVpTDXqvc/overlay/gsdk/app/rail/component/sl_rail_sdk_wmbus_support/sl_rail_sdk_wmbus_support.h

sl_rail_sdk_wmbus_frame_crypto5_get_key#

void sl_rail_sdk_wmbus_frame_crypto5_get_key (uint8_t * key)

Returns key for mode5 encryption/decryption (AES-CBC)

Parameters
[out]key

Copy of the current key


Definition at line 441 of file /mnt/raid/workspaces/ws.bVpTDXqvc/overlay/gsdk/app/rail/component/sl_rail_sdk_wmbus_support/sl_rail_sdk_wmbus_support.h

sl_rail_sdk_wmbus_frame_crypto5_encrypt#

uint8_t sl_rail_sdk_wmbus_frame_crypto5_encrypt (uint8_t * input, uint8_t * output, uint8_t * iv, uint16_t length, uint8_t encryptedBlocks)

Encrypts blocks using mode5 (AES-CBC) encryption.

Parameters
[in]input

Input data. Should be at least 16B*encryptedBlocks long.

[out]output

Output data. Should be at least 16B*encryptedBlocks long. Can be the same as input.

[inout]iv

Initialization vector, 16B long

[in]length

Length of the input data

[in]encryptedBlocks

Number of blocks to encode. If 0, all data will be encoded based on length

Also adds padding if needed, but the payload should include the 2B AES check (0x2f2f) in the beginning of the payload

Returns

  • the number of blocks encoded. Output length is 16 times this value.


Definition at line 458 of file /mnt/raid/workspaces/ws.bVpTDXqvc/overlay/gsdk/app/rail/component/sl_rail_sdk_wmbus_support/sl_rail_sdk_wmbus_support.h

sl_rail_sdk_wmbus_frame_crypto5_decrypt#

void sl_rail_sdk_wmbus_frame_crypto5_decrypt (uint8_t * input, uint8_t * output, uint8_t * iv, uint16_t length)

Decrypts blocks using mode5 (AES-CBC) encryption.

Parameters
[in]input

Input data. Should be at least length long.

[out]output

Output data. Should be at least length long. Can be the same as input.

[inout]iv

Initialization vector, 16B long

[in]length

Length of the input data. Should be divisible by 16


Definition at line 470 of file /mnt/raid/workspaces/ws.bVpTDXqvc/overlay/gsdk/app/rail/component/sl_rail_sdk_wmbus_support/sl_rail_sdk_wmbus_support.h

sl_rail_sdk_wmbus_setup_frame#

uint16_t sl_rail_sdk_wmbus_setup_frame (uint8_t * buffer, uint8_t access_number, sl_rail_sdk_wmbus_accessibility_t accessibility, sl_rail_sdk_wmbus_device_type_t new_device_type, sl_rail_sdk_wmbus_sensor_data_t * sensors_data, bool periodic, bool encrypt)

Sets up a Wireless M-Bus frame.

Parameters
[out]buffer

The buffer to store the Wireless M-Bus frame.

[in]access_number

The access number of the frame.

[in]accessibility

The accessibility of the frame.

[in]new_device_type

The device type of the frame.

[in]sensors_data

An array of data to be included in the frame.

[in]periodic

Indicates whether the frame is periodic or not.

[in]encrypt

Indicates whether the frame should be encrypted or not.

Sets up a Wireless M-Bus frame by populating the provided buffer with the necessary information.

Returns

  • The length of the assembled frame.


Definition at line 93 of file /mnt/raid/workspaces/ws.bVpTDXqvc/overlay/gsdk/app/rail/component/sl_rail_sdk_wmbus_packet_assembler/sl_rail_sdk_wmbus_packet_assembler.h