int bsd_check_tty(const char *devname) { int fd; ticables_info(_("Check for tty support:")); ticables_info(_(" tty support: available.")); // check for node usability ticables_info(_("Check for tty usability:")); if(check_for_node_usability(devname) == -1) return ERR_TTDEV; // check for device availability fd = open(devname, 0); if (fd == -1) { ticables_warning("unable to open serial device '%s'", devname); return ERR_TTDEV; } ticables_info(_(" is useable: yes")); close(fd); return 0; }
int linux_check_tiusb(const char *devname) { int fd; int arg; // check for node usability ticables_info(_("Check for tiusb usability:")); if(check_for_node_usability(devname) == -1) return ERR_TTDEV; #ifdef HAVE_LINUX_TICABLE_H // check for device availability fd = open(devname, 0); if (fd == -1) { ticables_warning("unable to open USB device '%s'", devname); return ERR_TTDEV; } if (ioctl(fd, IOCTL_TIUSB_GET_MAXPS, &arg) == -1) return ERR_TTDEV; ticables_info(_(" is useable: yes")); close(fd); return 0; #else fd = arg = -1; ticables_info(_(" tiusb support: not compiled.")); return ERR_TTDEV; #endif }
int bsd_check_libusb(void) { ticables_info(_("Check for libusb support:")); #if defined(HAVE_LIBUSB) || defined(HAVE_LIBUSB_1_0) ticables_info(_(" usb support: available.")); return 0; #else ticables_info(_(" usb support: not compiled.")); return ERR_USBFS; #endif }
int linux_check_tty(const char *devname) { ticables_info(_("Check for tty usability:")); if(check_for_node_usability(devname) == -1) return ERR_TTDEV; return 0; }
int linux_check_root(void) { uid_t uid = getuid(); ticables_info(_("Check for super-user access: %s"), uid ? "no" : "yes"); return (uid ? ERR_ROOT : 0); }
static void ticables_probing_show(int **array) { CableModel model; for(model = CABLE_NUL; model < CABLE_MAX; model++) { ticables_info(_(" %i: %i %i %i %i"), model, array[model][1], array[model][2], array[model][3], array[model][4]); } }
int linux_check_tty(const char *devname) { int fd; #ifdef HAVE_LINUX_SERIAL_H struct serial_struct serinfo; memset(&serinfo, 0, sizeof(serinfo)); #endif ticables_info(_("Check for tty support:")); #ifdef HAVE_LINUX_SERIAL_H ticables_info(_(" tty support: available.")); #else ticables_info(_(" tty support: not compiled.")); return ERR_TTDEV; #endif // check for node usability ticables_info(_("Check for tty usability:")); if(check_for_node_usability(devname) == -1) { ticables_warning(_("not usable")); return ERR_TTDEV; } #ifdef HAVE_LINUX_SERIAL_H // check for device availability fd = open(devname, 0); if (fd == -1) { ticables_warning(_("unable to open serial device '%s'"), devname); return ERR_TTDEV; } serinfo.reserved_char[0] = 0; if (ioctl(fd, TIOCGSERIAL, &serinfo) < 0) { ticables_warning(_("Error running TIOCGSERIAL ioctl on device %s - %s"), devname, strerror(errno)); close(fd); return ERR_TTDEV; } if(serinfo.type == PORT_UNKNOWN || serinfo.type == PORT_MAX) { ticables_info(_(" is useable: no")); close(fd); return ERR_TTDEV; } ticables_info(_(" is useable: yes")); close(fd); #endif return 0; }
int linux_check_parport(const char *devname) { int fd; ticables_info(_("Check for parport support:")); #ifdef HAVE_LINUX_PARPORT_H ticables_info(_(" parport support: available.")); #else ticables_info(_(" parport support: not compiled.")); return ERR_PPDEV; #endif // check for node usability ticables_info(_("Check for parport usability:")); if(check_for_node_usability(devname) == -1) return ERR_PPDEV; #ifdef HAVE_LINUX_PARPORT_H // check for device availability fd = open(devname, 0); if (fd == -1) { ticables_warning("unable to open parallel device '%s'.", devname); return ERR_PPDEV; } if (ioctl(fd, PPCLAIM) == -1) { ticables_info(_(" is useable: no")); close(fd); return ERR_PPDEV; } ticables_info(_(" is useable: yes")); if (ioctl(fd, PPRELEASE) == -1) { ticables_info("unable to release parallel device '%s'", devname); } close(fd); #endif return 0; }
static int check_for_node_usability(const char *pathname) { struct stat st; if(!access(pathname, F_OK)) { ticables_info(_(" node %s: exists"), pathname); } else { ticables_info(_(" node %s: does not exist"), pathname); ticables_info(_(" => you will have to create the node.")); return -1; } if(!stat(pathname, &st)) { ticables_info(_(" permissions/user/group:%s%s %s"), get_attributes(st.st_mode), get_user_name(st.st_uid), get_group_name(st.st_gid)); } else { ticables_warning("can't stat '%s'.", pathname); return -1; } if(getuid() == st.st_uid) { ticables_info(_(" user can r/w on device: yes")); return 0; } else { ticables_info(_(" user can r/w on device: no")); } if((st.st_mode & S_IROTH) && (st.st_mode & S_IWOTH)) { ticables_info(_(" others can r/w on device: yes")); } else { char *user, *group; ticables_info(_(" others can r/w on device: no")); user = strdup(get_user_name(getuid())); group = strdup(get_group_name(st.st_gid)); if(!search_for_user_in_group(user, group)) { ticables_info(_(" is the user '%s' in the group '%s': yes"), user, group); } else { ticables_info(_(" is the user '%s' in the group '%s': no"), user, group); ticables_info(_(" => you should add your username at the group '%s' in '/etc/group'"), group); ticables_info(_(" => you will have to restart your session, too"), group); free(user); free(group); return -1; } free(user); free(group); } return 0; }
static int vti_open(CableHandle *h) { int i; char vLinkFileName[32]; char name[32]; HANDLE hVLinkFileMap = NULL; HANDLE Handle; ATOM a; /* Get an handle on the VTi window */ otherWnd = FindWindow("TEmuWnd", NULL); if (!otherWnd) return ERR_VTI_FINDWINDOW; /* Get the current DLL handle */ Handle = GetModuleHandle("libticables2.dll"); if(!Handle) Handle = GetModuleHandle("libticables2-5.dll"); if (!Handle) { ticables_critical(_("FATAL ERROR: unable to get an handle on the ticables-2 library.")); ticables_critical(_("Did you rename the library ?!")); return ERR_NO_LIBRARY; } /* Create a file mapping handle for the 'lib->VTi' communication channel */ for (i = 0; ; i++) { sprintf(vLinkFileName, "Virtual Link %d", i); hVLinkFileMap = CreateFileMapping((HANDLE) - 1, NULL, PAGE_READWRITE, 0, sizeof(LinkBuffer), vLinkFileName); if (GetLastError() != ERROR_ALREADY_EXISTS) break; } ticables_info("Virtual Link L->V %i", i); vSendBuf = (LinkBuffer *)MapViewOfFile(hVLinkFileMap, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(LinkBuffer)); // Inform VTI of our virtual link so that it can enable it. It should return // its virtual link name in a message. SendMessage(otherWnd, WM_HELLO, 0, (LPARAM) Handle); /* Retrieve the VTi virtual link name */ //b = GetMessage(&msg, NULL, WM_HELLO, WM_SEND_BUFFER); //WaitMessage(); // Waits VTi answer /* Create a file mapping handle for the 'Vti->lib' communication channel */ ticables_info("Virtual Link V->L %i", i-1); sprintf(name, "Virtual Link %d", i - 1); hMap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, name); if (hMap) { ticables_info(_("Opened %s"), name); vRecvBuf = (LinkBuffer *)MapViewOfFile(hMap, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(LinkBuffer)); } else return ERR_VTI_OPENFILEMAPPING; /* Send to VTi the name of our virtual link. VTi should open it (lib -> Vti) */ a = GlobalAddAtom(vLinkFileName); SendMessage(otherWnd, WM_SEND_BUFFER, 0, (LPARAM) a); GlobalDeleteAtom(a); /* Enable linking (check the VTi's Virtual Link|Enable cable link' item) */ if (otherWnd) SendMessage(otherWnd, WM_ENABLE_LINK, 0, 0); vSendBuf->start = vSendBuf->end = 0; vRecvBuf->start = vRecvBuf->end = 0; return 0; }
/** * ticables_probing_do: * @result: address of an array of integers to put the result. * @timeout: timeout to set during probing * @method: defines which link cables you want to search for. * * Returns cables which have been detected. All cables should be closed before ! * The array is like a matrix which contains 5 columns (PORT_0 to PORT_4) and * 7 lines (CABLE_GRY to CABLE_USB). * The array must be freed by #ticables_probing_finish when no longer used. * * Return value: 0 if successful, ERR_NO_CABLE if no cables found. **/ TIEXPORT1 int TICALL ticables_probing_do(int ***result, int timeout, ProbingMethod method) { CablePort port; CableModel model; int **array; int found = 0; if (result == NULL) { ticables_critical("%s: result is NULL", __FUNCTION__); return ERR_PROBE_FAILED; } ticables_info(_("Link cable probing:")); array = (int **)calloc(CABLE_MAX + 1, sizeof(int *)); for(model = CABLE_NUL; model <= CABLE_MAX; model++) array[model] = (int *)calloc(5, sizeof(int)); // look for USB devices (faster) if(method & PROBE_USB) { int *list, n, i; ticables_get_usb_devices(&list, &n); for(i = 0; i < n; i++) { port = i+1; if(list[i] == PID_TIGLUSB) array[CABLE_SLV][port] = !0; if(list[i]) array[CABLE_USB][port] = !0; if(list[i]) found = !0; } } if((method & PROBE_FIRST) && found) { *result = array; return found ? 0 : ERR_NO_CABLE; } // look for DBUS devices (slower) if(method & PROBE_DBUS) { for(model = CABLE_GRY; model <= CABLE_PAR; model++) { for(port = PORT_1; port <= PORT_4; port++) { CableHandle* handle; int err, ret; handle = ticables_handle_new(model, port); if(handle) { ticables_options_set_timeout(handle, timeout); err = ticables_cable_probe(handle, &ret); array[model][port] = (ret && !err) ? 1: 0; if(array[model][port]) found = !0; if(found && (method & PROBE_FIRST)) { ticables_handle_del(handle); break; } } ticables_handle_del(handle); } } } *result = array; return found ? 0 : ERR_NO_CABLE; }
int linux_check_libusb(void) { ticables_info(_("Check for libusb support:")); #if defined(HAVE_LIBUSB) || defined(HAVE_LIBUSB_1_0) ticables_info(_(" usb support: available.")); #else ticables_info(_(" usb support: not compiled.")); return ERR_USBFS; #endif ticables_info(_("Check for libusb usability:")); if(!access(DEVFS, F_OK)) { ticables_info(_(" usb filesystem (%s): %s"), DEVFS, "mounted"); } else if(!access(USBFS, F_OK)) { DIR* dir; struct dirent *dirent; int i; dir = opendir(USBFS); if(dir == NULL) { ticables_info(_(" usb filesystem (%s): %s"), USBFS, "not mounted"); return ERR_USBFS; } for(i = 0; (dirent = readdir(dir)); i++); closedir(dir); if(i > 2) ticables_info(_(" usb filesystem (%s): %s"), USBFS, "mounted"); else { ticables_info(_(" usb filesystem (%s): %s"), USBFS, "not mounted"); return ERR_USBFS; } } else { ticables_info(_(" usb filesystem (/[proc|dev]/bus/usb): %s"), "not present"); ticables_info(_(" => you must have udev or usbfs support.")); ticables_info(_(" => take a look at the ticables2/CONFIG file.")); return ERR_USBFS; } return 0; }