Hello!
My device doesn't have CD (Carrier Detect) signal on COM port and I'd like to override ioctl function and catch the CD (TIOCM_CAR) toggling of the serial port and convert it into toggling of one of free GPIOs.
I've found overriding ioctl() for toggling RTS signal to DMZ LED GPIO:
#include <sys/ioctl.h>
#include <dlfcn.h>
#include <stdarg.h>
#include <stdio.h>
#include <termios.h>
int
ioctl(int d, unsigned long int request, ...)
{
static int (*orig_ioctl)(int, unsigned long int, ...);
static void *handle = NULL;
static int last_seen_rts = -1;
va_list opt;
void *arg;
va_start(opt, request);
arg = va_arg(opt, void *);
va_end(opt);
if(request == TIOCMSET) {
int current_rts = ((*(int *)arg) & TIOCM_RTS);
if(current_rts != last_seen_rts) {
FILE *fddiag = fopen("/proc/sys/diag", "w");
if(fddiag != NULL) {
fprintf(fddiag, "%c", (current_rts) ? '1' : '0');
fclose(fddiag);
} else {
printf("You need to install kmod-diag\n");
exit(1);
}
last_seen_rts = current_rts;
}
}
if(handle == NULL) {
handle = dlopen("/lib/libc.so.0", RTLD_LAZY);
orig_ioctl = dlsym(handle, "ioctl");
}
return orig_ioctl(d, request, arg);
}
but I've not found in thi code where DMZ GPIO toggle... :-/
Also, my device havn't /proc/sys/diag.
Can somebody help me with this?
Normally there is only one COM port on the device.
Can I using overriding ioctl function create second COM port on free GPIOs?
Thanks for your answers!
-Alex