-
Notifications
You must be signed in to change notification settings - Fork 78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Userland PM16D17 #582
Open
BaochengSu
wants to merge
2
commits into
master
Choose a base branch
from
su/userland-pm16d17-pr
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Userland PM16D17 #582
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# SPDX-License-Identifier: MIT | ||
# SPDX-FileCopyrightText: Copyright (c) Siemens AG, 2025 | ||
# SPDX-FileContributor: Authored by Su Bao Cheng <[email protected]> | ||
|
||
CROSS_COMPILE ?= aarch64-linux-gnu- | ||
|
||
CC = $(CROSS_COMPILE)gcc | ||
|
||
LDFLAGS = -lsystemd | ||
|
||
TARGET = iot2050-pxmtd | ||
|
||
INSTALL ?= install | ||
|
||
DESTDIR ?= / | ||
|
||
SRC = main.c \ | ||
dbus-service.c \ | ||
sensor.c | ||
|
||
.PHONY: all clean install | ||
|
||
all: $(TARGET) | ||
|
||
$(TARGET): $(SRC) | ||
$(CC) $(CFLAGS) -o $(TARGET) $(SRC) $(LDFLAGS) | ||
|
||
clean: | ||
rm -f $(TARGET) | ||
|
||
install: | ||
$(INSTALL) -v -d $(DESTDIR)/usr/bin | ||
$(INSTALL) -v -d $(DESTDIR)/etc/dbus-1/system.d | ||
$(INSTALL) -v -m 0755 $(TARGET) $(DESTDIR)/usr/bin | ||
$(INSTALL) -v -m 0644 com.siemens.iot2050.pxmt.conf \ | ||
$(DESTDIR)/etc/dbus-1/system.d | ||
$(INSTALL) -v -d ${DESTDIR}/lib/systemd/system/ | ||
$(INSTALL) -v -m 0644 iot2050-proximity-driver.service\ | ||
${DESTDIR}/lib/systemd/system/ |
9 changes: 9 additions & 0 deletions
9
recipes-core/iot2050-proximity-driver/files/src/com.siemens.iot2050.pxmt.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<!DOCTYPE busconfig PUBLIC | ||
"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN" | ||
"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd"> | ||
<busconfig> | ||
<policy user="root"> | ||
<allow own="com.siemens.iot2050.pxmt"/> | ||
<allow send_interface="com.siemens.iot2050.pxmt"/> | ||
</policy> | ||
</busconfig> |
96 changes: 96 additions & 0 deletions
96
recipes-core/iot2050-proximity-driver/files/src/dbus-service.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
/* SPDX-License-Identifier: MIT | ||
* SPDX-FileCopyrightText: Copyright (c) Siemens AG, 2025 | ||
* SPDX-FileContributor: Authored by Su Bao Cheng <[email protected]> | ||
*/ | ||
|
||
#include <systemd/sd-bus.h> | ||
#include <errno.h> | ||
#include <sys/capability.h> | ||
#include "dbus-service.h" | ||
|
||
typedef int (*retrieve_callback_t)(uint16_t *); | ||
|
||
static retrieve_callback_t iot2050_pxmtd_retrieve_cb = NULL; | ||
|
||
static int iot2050_pxmtd_retrieve(sd_bus_message *m, | ||
void *userdata, | ||
sd_bus_error *ret_error) | ||
{ | ||
if (!iot2050_pxmtd_retrieve_cb) | ||
return -ENXIO; | ||
|
||
uint16_t ps_val; | ||
int ret = iot2050_pxmtd_retrieve_cb(&ps_val); | ||
if (ret < 0) | ||
return ret; | ||
|
||
return sd_bus_reply_method_return(m, "q", ps_val); | ||
} | ||
|
||
static const sd_bus_vtable iot2050_pxmtd_vtable[] = { | ||
SD_BUS_VTABLE_START(0), | ||
SD_BUS_METHOD("Retrieve", | ||
SD_BUS_NO_ARGS, | ||
"q", | ||
iot2050_pxmtd_retrieve, | ||
SD_BUS_VTABLE_UNPRIVILEGED), | ||
SD_BUS_VTABLE_END | ||
}; | ||
|
||
int dbus_serve(retrieve_callback_t cb) | ||
{ | ||
sd_bus_slot *slot = NULL; | ||
sd_bus *bus = NULL; | ||
int ret; | ||
|
||
ret = sd_bus_open_system(&bus); | ||
if (ret < 0) { | ||
fprintf(stderr, "Failed to connect to system bus: %s\n", | ||
strerror(-ret)); | ||
goto out; | ||
} | ||
|
||
iot2050_pxmtd_retrieve_cb = cb; | ||
|
||
ret = sd_bus_add_object_vtable(bus, &slot, | ||
"/com/siemens/iot2050/pxmt", | ||
"com.siemens.iot2050.pxmt", | ||
iot2050_pxmtd_vtable, NULL); | ||
if (ret < 0) { | ||
fprintf(stderr, "Failed to set dbus service property: %s\n", | ||
strerror(-ret)); | ||
goto out; | ||
} | ||
|
||
ret = sd_bus_request_name(bus, "com.siemens.iot2050.pxmt", 0); | ||
if (ret < 0) { | ||
fprintf(stderr, "Failed to acquire service name: %s\n", | ||
strerror(-ret)); | ||
goto out; | ||
} | ||
|
||
for (;;) { | ||
ret = sd_bus_process(bus, NULL); | ||
if (ret < 0) { | ||
fprintf(stderr, "Failed to process bus: %s\n", | ||
strerror(-ret)); | ||
goto out; | ||
} | ||
if (ret > 0) | ||
continue; | ||
|
||
ret = sd_bus_wait(bus, (uint64_t) -1); | ||
if (ret < 0) { | ||
fprintf(stderr, "Failed to wait on bus: %s\n", | ||
strerror(-ret)); | ||
goto out; | ||
} | ||
} | ||
|
||
ret = 0; | ||
out: | ||
sd_bus_slot_unref(slot); | ||
sd_bus_unref(bus); | ||
|
||
return ret; | ||
} |
15 changes: 15 additions & 0 deletions
15
recipes-core/iot2050-proximity-driver/files/src/dbus-service.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* SPDX-License-Identifier: MIT | ||
* SPDX-FileCopyrightText: Copyright (c) Siemens AG, 2025 | ||
* SPDX-FileContributor: Authored by Su Bao Cheng <[email protected]> | ||
*/ | ||
|
||
#ifndef IOT2050_PXMTD_DBUS_SERVICE_H | ||
#define IOT2050_PXMTD_DBUS_SERVICE_H | ||
|
||
#include <stdint.h> | ||
|
||
typedef int (*retrieve_callback_t)(uint16_t *); | ||
|
||
int dbus_serve(retrieve_callback_t cb); | ||
|
||
#endif /* IOT2050_PXMTD_DBUS_SERVICE_H */ |
24 changes: 24 additions & 0 deletions
24
recipes-core/iot2050-proximity-driver/files/src/iot2050-proximity-driver.service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# SPDX-License-Identifier: MIT | ||
# SPDX-FileCopyrightText: Copyright (c) Siemens AG, 2025 | ||
# SPDX-FileContributor: Authored by Su Bao Cheng <[email protected]> | ||
|
||
[Unit] | ||
Description=Userspace driver for the proximity sensor of IOT2050 | ||
# Only run on IOT2050-SM variant | ||
ConditionFirmware=device-tree-compatible(siemens,iot2050-advanced-sm) | ||
ConditionVirtualization=!container | ||
|
||
[Service] | ||
Type=dbus | ||
BusName=com.siemens.iot2050.pxmt | ||
ExecStart=/usr/bin/iot2050-pxmtd | ||
Restart=always | ||
RestartSec=5 | ||
ProtectSystem=strict | ||
ProtectHome=true | ||
NoNewPrivileges=true | ||
User=root | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
Alias=dbus-com.siemens.iot2050.pxmt.service |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* SPDX-License-Identifier: MIT | ||
* SPDX-FileCopyrightText: Copyright (c) Siemens AG, 2025 | ||
* SPDX-FileContributor: Authored by Su Bao Cheng <[email protected]> | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <string.h> | ||
#include <stdlib.h> | ||
#include "sensor.h" | ||
#include "dbus-service.h" | ||
|
||
int main() | ||
{ | ||
setbuf(stdout, NULL); | ||
|
||
int ret = init_sensor(); | ||
if (ret < 0) { | ||
fprintf(stderr, "Failed to initialize the sensor: %s\n", | ||
strerror(-ret)); | ||
exit(EXIT_FAILURE); | ||
} | ||
|
||
return dbus_serve(retrieve_sensor_data) == 0 ? EXIT_SUCCESS : EXIT_FAILURE; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make the
event-record
an identical user story?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a leakage due to the lack of kernel ABI or userspace API compatibility, which seems to be an unmanageable limitation.
Otherwise, looks good to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding our upcoming release, we may need to hold off on merging this PR to avoid involving additional third-party libraries for OSS clearance.