Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .github/workflows/docker_sink_service.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ jobs:
- name: checkout code
uses: actions/checkout@v4

- name: get c-mesh-api with submodule
run: git submodule update --init

- name: Set up QEMU
run: sudo apt-get update && sudo apt-get install qemu-user-static -y

Expand Down
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "sink_service/c-mesh-api"]
path = sink_service/c-mesh-api
url = https://github.com/wirepas/c-mesh-api
11 changes: 5 additions & 6 deletions docker/sink_service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ARG GATEWAY_BUILD_SHA1=unset

RUN adduser --disabled-password wirepas

RUN apk add --no-cache gcc make cmake musl-dev dpkg elogind-dev linux-headers
RUN apk add --no-cache gcc git make cmake musl-dev dpkg elogind-dev linux-headers
Comment thread
MauriKuorilehto marked this conversation as resolved.

USER wirepas

Expand All @@ -16,12 +16,11 @@ WORKDIR /home/wirepas

COPY --chown=wirepas ./sink_service /home/wirepas/sink_service

WORKDIR /home/wirepas/sink_service

RUN make
RUN CMAKE_BUILD_TYPE=Release cmake -S /home/wirepas/sink_service -B /home/wirepas/build
RUN cmake --build /home/wirepas/build

FROM scratch AS export
COPY --from=builder /home/wirepas/sink_service/build/sinkService .
COPY --from=builder /home/wirepas/build/sinkService .

FROM $BASE_IMAGE

Expand All @@ -34,7 +33,7 @@ RUN addgroup wirepas dialout
RUN apk add --no-cache libelogind coreutils

# Copy the built service and its dependencies from builder
COPY --from=builder /home/wirepas/sink_service/build/sinkService /home/wirepas/
COPY --from=builder /home/wirepas/build/sinkService /home/wirepas/

USER wirepas

Expand Down
2 changes: 1 addition & 1 deletion python_transport/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# wirepas
wirepas_mesh_messaging==1.3.0rc1
wirepas_mesh_messaging==1.3.0rc3

# dbus bindings
pydbus==0.6.0
Expand Down
2 changes: 1 addition & 1 deletion python_transport/wirepas_gateway/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
__pkg_name__ = "wirepas_gateway"
__title__ = "Wirepas Gateway Transport Service"
__url__ = "https://github.com/wirepas/gateway"
__version__ = "1.5.0rc1"
__version__ = "1.5.0rc2"
__keywords__ = "wirepas connectivity iot mesh"
59 changes: 54 additions & 5 deletions python_transport/wirepas_gateway/dbus/sink_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ def _set_param(self, dic, key, attribute):
# Exception raised when setting attribute
error = ReturnCode.error_from_dbus_exception(str(e))
logging.error(
"Cannot set %s for param %s on sink %s: %s (%s)",
value,
"Cannot set param %s on sink %s: %s (%s)",
key,
self.sink_id,
error.name,
Expand All @@ -241,12 +240,54 @@ def _set_param(self, dic, key, attribute):
except OverflowError:
# It may happens as protobuf has bigger container value
logging.error(
"Invalid range value for param %s with value %s", key, value
"Invalid range value for param %s", key
)
return wmm.GatewayResultCode.GW_RES_INVALID_PARAM

return wmm.GatewayResultCode.GW_RES_OK

def _set_network_keys(self, config):
if "network_keys" in config:
try:
cipher = config["network_keys"]["cipher"]
auth = config["network_keys"]["authentication"]
seq = config["network_keys"]["sequence"]
logging.info(f"Setting network security keys with sequence {seq}")
self.proxy.SetNetworkSecurityKeys(cipher, auth, seq)
except GLib.Error as e:
error_code = ReturnCode.error_from_dbus_exception(str(e))
logging.error("Error when setting network keys: %s", error_code.name)
return error_code
except OverflowError:
logging.error("Invalid sequence when setting network keys")
return wmm.GatewayResultCode.GW_RES_INVALID_PARAM
except Exception:
logging.exception("Unknown error when setting network keys")
return wmm.GatewayResultCode.GW_RES_INTERNAL_ERROR

return wmm.GatewayResultCode.GW_RES_OK

def _set_management_keys(self, config):
if "management_keys" in config:
try:
cipher = config["management_keys"]["cipher"]
auth = config["management_keys"]["authentication"]
seq = config["management_keys"]["sequence"]
logging.info(f"Setting management security keys with sequence {seq}")
self.proxy.SetManagementSecurityKeys(cipher, auth, seq)
except GLib.Error as e:
error_code = ReturnCode.error_from_dbus_exception(str(e))
logging.error("Error when setting management keys: %s", error_code.name)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (88 > 79 characters)

return error_code
except OverflowError:
logging.error("Invalid sequence when setting management keys")
return wmm.GatewayResultCode.GW_RES_INVALID_PARAM
except Exception:
logging.exception("Unknown error when setting management keys")
return wmm.GatewayResultCode.GW_RES_INTERNAL_ERROR

return wmm.GatewayResultCode.GW_RES_OK

def write_config(self, config):
# Force the node address if used
try:
Expand Down Expand Up @@ -296,11 +337,11 @@ def write_config(self, config):
diag = config["app_config_diag"]
data = config["app_config_data"]

logging.info("Set app config with %s", config)
logging.info(f"Set app config with seq: {seq}, diag: {diag}, data: {data}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (87 > 79 characters)

self.proxy.SetAppConfig(seq, diag, data)
except KeyError:
# App config not defined in new config
logging.debug("Missing key app_config key in config: %s", config)
logging.debug("Missing app config related key in config; will not set app config")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

line too long (94 > 79 characters)

except GLib.Error as e:
res = ReturnCode.error_from_dbus_exception(str(e))
logging.error("Cannot set App Config: %s", res.name)
Expand All @@ -309,6 +350,14 @@ def write_config(self, config):
res = wmm.GatewayResultCode.GW_RES_INVALID_PARAM
logging.error("Invalid range value")

res_network_keys = self._set_network_keys(config)
if res_network_keys != wmm.GatewayResultCode.GW_RES_OK:
res = res_network_keys

res_management_keys = self._set_management_keys(config)
if res_management_keys != wmm.GatewayResultCode.GW_RES_OK:
res = res_management_keys

# Set stack in state defined by new config or set it as it was
# previously
try:
Expand Down
29 changes: 27 additions & 2 deletions python_transport/wirepas_gateway/transport_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from time import time, sleep
from uuid import getnode
from threading import Thread, Event
from copy import deepcopy

from wirepas_gateway.dbus.dbus_client import BusClient
from wirepas_gateway.protocol.topic_helper import TopicGenerator, TopicParser
Expand Down Expand Up @@ -365,6 +366,29 @@ class TransportService(BusClient):
# Period in s to check for black hole issue
MONITORING_BUFFERING_PERIOD_S = 1

class MaskedRequest:
"""
Wrapper class to hide certain configuration fields of SetConfigRequest.
Can be used to exclude potentially sensitive fields from logs.
"""
def __init__(self, request: wmm.SetConfigRequest):
self.orig_request = request

def __str__(self):
hidden_fields = [
"cipher_key",
"authentication_key",
"network_keys",
"management_keys",
]

req_to_print = deepcopy(self.orig_request)
for key in req_to_print.new_config:
if key in hidden_fields:
req_to_print.new_config[key] = '<HIDDEN>'

return str(req_to_print)

def __init__(self, settings, **kwargs):
logging.info("Version is: %s", transport_version)

Expand All @@ -379,7 +403,8 @@ def __init__(self, settings, **kwargs):
self.gw_version = settings.gateway_version

self.gw_features = [
wmm.GatewayFeature.GW_FEATURE_CONFIGURATION_DATA_V1
wmm.GatewayFeature.GW_FEATURE_CONFIGURATION_DATA_V1,
wmm.GatewayFeature.GW_FEATURE_SINK_KEY_MANAGEMENT_V1
]

self.whitened_ep_filter = settings.whitened_endpoints_filter
Expand Down Expand Up @@ -731,7 +756,7 @@ def _on_set_config_cmd_received(self, client, userdata, message):
logging.error(str(e))
return

logging.debug("Set sink config: %s", request)
logging.debug("Set sink config: %s", self.MaskedRequest(request))
sink = self.sink_manager.get_sink(request.sink_id)
if sink is not None:
res = sink.write_config(request.new_config)
Expand Down
33 changes: 33 additions & 0 deletions sink_service/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.18)

project(sinkService LANGUAGES C)

set(CMAKE_C_STANDARD 99)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE RelWithDebInfo)
endif()
set(CMAKE_C_FLAGS_RELEASE "-O2")

add_compile_options(-Wall -Werror -Wextra -Wno-unused-parameter)

include(FetchContent)
FetchContent_Declare(
c-mesh-api
GIT_REPOSITORY https://github.com/wirepas/c-mesh-api/
GIT_TAG c566fdbd693eb3fb6027286679f53db9f9958e0a

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder whether this should be extracted from here to some "config" file? Also should we use some explicit tags instead of commit hashes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think tags would be good too. There are some tags/releases for c-mesh-api from the past(2022) which were using the same version as gateway. I don't know if there would be an advantage to use the same version numbers, but we can start creating releases for c-mesh-api again.

SOURCE_SUBDIR lib
)
FetchContent_MakeAvailable(c-mesh-api)

find_package(PkgConfig REQUIRED)
pkg_check_modules(systemd REQUIRED IMPORTED_TARGET libsystemd)

add_executable(${CMAKE_PROJECT_NAME}
source/main.c
source/config.c
source/data.c
source/otap.c
)

target_link_libraries(${CMAKE_PROJECT_NAME} wpc PkgConfig::systemd)

24 changes: 13 additions & 11 deletions sink_service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,28 @@

The sink service is in charge of doing the interface between a physical device attached to a gateway through a uart port and the Dbus internal API.

## Getting the sources
## Requirements

On Debian 12, the following packages are needed to build:
```
cmake
git
libsystemd-dev
pkg-config
```

The sink service depends on [c-mesh-api](https://github.com/wirepas/c-mesh-api) repository.
It contains the low level library that implements the DualMCU API to communicate through an UART to a Wirepas node.

[Git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules) is used to upkeep the project
dependency with the c-mesh-api library.
c-mesh-api is fetched automatically from git by CMake when the project is configured.

Once this repository is cloned, please synchronize it to get the c-mesh-api
code at the right place.

```shell
git submodule update --init
```
## Building the sink service

From current folder, execute this command to build the sinkService
From current folder, execute following commands to build the sinkService

```shell
make
cmake -S . -B build
cmake --build build
```
Built sinkService will be generated under build/ folder.

Expand Down
1 change: 0 additions & 1 deletion sink_service/c-mesh-api
Submodule c-mesh-api deleted from 766e69
102 changes: 0 additions & 102 deletions sink_service/makefile

This file was deleted.

Loading