diff --git a/Makefile b/Makefile index 03fea4d..7370cbe 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ IncludeWithNewlines = $(subst # Name and release number of this package PKG_NAME := wifibox PKG_VERSION := 0.1.0 -PKG_RELEASE := 4 +PKG_RELEASE := 6 # This specifies the directory where we're going to build the program. # The root build directory, $(BUILD_DIR), is by default the build_mipsel @@ -73,6 +73,7 @@ endef WIFIBOX_BASE_DIR := $(PKG_BUILD_DIR) GPX_BASE_DIR := $(PKG_BUILD_DIR)/util/GPX.git +SETPORTSPEED_BASE_DIR := $(PKG_BUILD_DIR)/util/setportspeed TGT_LUA_DIR_SUFFIX := usr/share/lua/wifibox define Package/wifibox/install @@ -120,6 +121,8 @@ endif ### install gpx utility $(INSTALL_DIR) $(1)/usr/bin $(INSTALL_BIN) $(GPX_BASE_DIR)/gpx $(1)/usr/bin + + $(INSTALL_BIN) $(SETPORTSPEED_BASE_DIR)/setportspeed $(1)/usr/bin endef define Package/wifibox/postinst diff --git a/src/Makefile b/src/Makefile index fdf09fd..db977bc 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,9 +1,12 @@ GPX_PATH := util/GPX.git +SETPORTSPEED_PATH := util/setportspeed -.PHONY: $(GPX_PATH) +.PHONY: $(GPX_PATH) $(SETPORTSPEED_PATH) all: $(MAKE) -C $(GPX_PATH) + $(MAKE) -C $(SETPORTSPEED_PATH) clean: $(MAKE) -C $(GPX_PATH) clean + $(MAKE) -C $(SETPORTSPEED_PATH) clean diff --git a/src/util/setportspeed/Makefile b/src/util/setportspeed/Makefile new file mode 100644 index 0000000..efdd7b4 --- /dev/null +++ b/src/util/setportspeed/Makefile @@ -0,0 +1,17 @@ +SRC := setportspeed.c +OBJ := setportspeed.o +EXEC := setportspeed +CFLAGS += -Wall + +all: $(EXEC) + +$(EXEC): $(OBJ) + $(CC) $(LDFLAGS) -o $@ $(OBJ) + +%.o: %.c + $(CC) $(CFLAGS) -c -o $@ $< + +.PHONY: clean +clean: + rm -f $(EXEC) + rm -f $(OBJ) diff --git a/src/util/setportspeed/setportspeed.c b/src/util/setportspeed/setportspeed.c new file mode 100644 index 0000000..3a8b31a --- /dev/null +++ b/src/util/setportspeed/setportspeed.c @@ -0,0 +1,97 @@ +/* + * based on: http://lists.uclibc.org/pipermail/uclibc/2008-January/039683.html + * see: http://marc.info/?l=linux-serial&m=120661887111805&w=2 + */ +#include +#include +#include +#include +#include +#include +#include + +/* these includes are for ioctl() and cfmakeraw() but disabled to avoid conflicts with asm/* includes */ +//#include +//#include + +#include +#include + +int main(int argc, char** argv) { + struct termios2 options2; + int modemBits; + int serialfd = -1; + int ultiFiEnabled = 0; + int r; + const char* portname = NULL; + int baudrate = -1; + + if (argc < 3) { + fprintf(stderr, "%s: please supply a port name followed by the port speed, optionally followed by '-ultifi'\n", argv[0]); + exit(1); + } + + portname = argv[1]; + baudrate = strtol(argv[2], NULL, 10); + + if (argc >= 4 && strcmp(argv[3], "-ultifi") == 0) { + ultiFiEnabled = 1; + printf("%s: UltiFi-like bits will be set\n", argv[0]); + } + + serialfd = open(portname, O_RDWR); + if (serialfd == -1) { + fprintf(stderr, "%s: could not open port %s (%s)\n", argv[0], portname, strerror(errno)); + exit(2); + } + + r = ioctl(serialfd, TCGETS2, &options2); + + if (r == -1) { + fprintf(stderr, "%s: ioctl error on port %s (%s)\n", argv[0], portname, strerror(errno)); + close(serialfd); + } + + /***** START from UltiFi *****/ + if (ultiFiEnabled == 1) { + //tcgetattr(fd, &options); //done using ioctl() above + cfmakeraw(&options2); + + // Enable the receiver + options2.c_cflag |= CREAD; + // Clear handshake, parity, stopbits and size + options2.c_cflag &= ~CLOCAL; + options2.c_cflag &= ~CRTSCTS; + options2.c_cflag &= ~PARENB; + options2.c_cflag &= ~CSTOPB; + options2.c_cflag &= ~CSIZE; + + options2.c_cflag |= CS8; + options2.c_cflag |= CLOCAL; + } + /***** END from UltiFi *****/ + + options2.c_ospeed = options2.c_ispeed = baudrate; + options2.c_cflag &= ~CBAUD; + options2.c_cflag |= BOTHER; + r = ioctl(serialfd, TCSETS2, &options2); + + if (r == -1) { + fprintf(stderr, "%s: ioctl error on port %s (%s)\n", argv[0], portname, strerror(errno)); + close(serialfd); + } + + /***** START from UltiFi *****/ + if (ultiFiEnabled == 1) { + ioctl(serialfd, TIOCMGET, &modemBits); + modemBits |= TIOCM_DTR; + ioctl(serialfd, TIOCMSET, &modemBits); + usleep(100 * 1000); + modemBits &= ~TIOCM_DTR; + ioctl(serialfd, TIOCMSET, &modemBits); + } + /***** END from UltiFi *****/ + + close(serialfd); + exit(0); +}