diff --git a/.vscode/settings.json b/.vscode/settings.json index 4a03d14..344ca2e 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -18,7 +18,8 @@ "*.tcc": "c", "cstdint": "c", "fcntl.h": "c", - "file.h": "c" + "file.h": "c", + "dir.h": "c" }, "cmake.configureOnOpen": false } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 07e51d9..373bcf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog -## [0.1.0] +## [0.2.0](https://github.com/AlexanderZhirov/MPortLink/compare/0.1.0...v0.2.0) +### Changed +- Creation of links to ports has been moved to the directory `/dev/dongle` + +## [0.1.0](https://github.com/AlexanderZhirov/MPortLink/tree/36a71e51b9fc38793366a70264864d43771c5b81) - The first version is linked to the original [ModemManager](https://gitlab.freedesktop.org/mobile-broadband/ModemManager) diff --git a/README.md b/README.md index 97b148b..fcde2ff 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,21 @@ After installing the dependencies, you just need to run the script `build.sh `an gcc -Werror -Wall -Os src/*.c `pkg-config --libs --cflags mm-glib` -o mportlink ``` +## Using + +Superuser rights are required to work. Start the daemon and connect your USB modem. In `journalctl` you will see his work. Links to the ports of the connected modem will be created in the `/dev/dongle` directory. + +``` +Dec 21 13:51:02 solus mportlink[17764]: main: starting the mportlink daemon +Dec 21 13:51:26 solus mportlink[17764]: mpl_symlink_ports, dst_path: the symbolic link has been successfully created [/dev/dongle/358**********26-0 -> /dev/ttyUSB0] +Dec 21 13:51:26 solus mportlink[17764]: mpl_symlink_ports, dst_path: the symbolic link has been successfully created [/dev/dongle/358**********26-1 -> /dev/ttyUSB1] +Dec 21 13:51:41 solus mportlink[17764]: mpl_unlink_ports, dst_path: link was successfully deleted [/dev/dongle/358**********26-0] +Dec 21 13:51:41 solus mportlink[17764]: mpl_unlink_ports, dst_path: link was successfully deleted [/dev/dongle/358**********26-1] +Dec 21 13:51:48 solus mportlink[17764]: signals_handler: cancelling the operation... +Dec 21 13:51:48 solus mportlink[17764]: signals_handler: cancelling the main loop... +Dec 21 13:51:48 solus mportlink[17764]: main: stopping the mportlink daemon +``` + ## To-Do Currently, the utility is linked to the ModemManager server, through which the connected modems are identified. It is planned to disconnect from this server, as there is a problem with the capture of the device and the unavailability of using Asterisk. diff --git a/src/mportlink-core.c b/src/mportlink-core.c index e89403d..a1b3732 100644 --- a/src/mportlink-core.c +++ b/src/mportlink-core.c @@ -5,6 +5,7 @@ #include #define DEV_PATH "/dev/" +#define DONGLE_PATH "/dev/dongle/" typedef struct { @@ -16,6 +17,25 @@ typedef struct guint n_ports; } MPLmodem; +void mpl_create_dongle_dir() +{ + struct stat st; + + if (stat(DONGLE_PATH, &st) == 0) + { + if (!S_ISDIR(st.st_mode)) + { + syslog(LOG_ERR, "mpl_create_dongle_dir: %s exists and is not a directory", DONGLE_PATH); + raise(SIGINT); + } + } + else if (mkdir(DONGLE_PATH, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == -1) + { + syslog(LOG_ERR, "mpl_create_dongle_dir: unable to create a directory %s", DONGLE_PATH); + raise(SIGINT); + } +} + MPLmodem *mpl_get_new_modem() { MPLmodem *modem = (MPLmodem *)calloc(1, sizeof(MPLmodem)); @@ -108,7 +128,7 @@ char *mpl_get_dst_path(guint index, const gchar *imei) sprintf(id, "-%d", index); - guint dst_path_size = strlen(DEV_PATH) + strlen(imei) + size_id; + guint dst_path_size = strlen(DONGLE_PATH) + strlen(imei) + size_id; dst_path = (char *)calloc(dst_path_size + 1, sizeof(char)); if (dst_path == NULL) @@ -117,7 +137,7 @@ char *mpl_get_dst_path(guint index, const gchar *imei) raise(SIGINT); } - strcpy(dst_path, DEV_PATH); + strcpy(dst_path, DONGLE_PATH); strcat(dst_path, imei); strcat(dst_path, id); diff --git a/src/mportlink.c b/src/mportlink.c index 8625822..21d66ff 100644 --- a/src/mportlink.c +++ b/src/mportlink.c @@ -50,6 +50,8 @@ int main() syslog(LOG_NOTICE, "main: starting the %s daemon", MPL); + mpl_create_dongle_dir(); + GError *error = NULL; GDBusConnection *connection = NULL; diff --git a/src/mportlink.h b/src/mportlink.h index 6e7358e..a9e4f2c 100644 --- a/src/mportlink.h +++ b/src/mportlink.h @@ -1,4 +1,5 @@ #include "mm.h" +void mpl_create_dongle_dir(); void mpl_device_added(MMManager *manager, MMObject *obj); void mpl_device_removed(MMManager *manager, MMObject *obj);