creation of links to ports has been moved to the directory /dev/dongle

This commit is contained in:
Alexander Zhirov 2023-12-21 14:24:36 +03:00
parent 766fcad371
commit f2fce3463d
6 changed files with 47 additions and 4 deletions

View File

@ -18,7 +18,8 @@
"*.tcc": "c",
"cstdint": "c",
"fcntl.h": "c",
"file.h": "c"
"file.h": "c",
"dir.h": "c"
},
"cmake.configureOnOpen": false
}

View File

@ -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)

View File

@ -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.

View File

@ -5,6 +5,7 @@
#include <sys/stat.h>
#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);

View File

@ -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;

View File

@ -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);