diff --git a/software/linux/.clang_complete b/software/linux/.clang_complete new file mode 100644 index 0000000..92bd311 --- /dev/null +++ b/software/linux/.clang_complete @@ -0,0 +1 @@ +-I../sss7core diff --git a/software/linux/Makefile b/software/linux/Makefile new file mode 100644 index 0000000..200be47 --- /dev/null +++ b/software/linux/Makefile @@ -0,0 +1,40 @@ +VERSION = 0.1 + +HEADERS = ../sss7core/sss7.h libsss7.h +OBJDIR = bin + +CC = clang + +CFLAGS = -I ../sss7core/ -Os -Wall -Wstrict-prototypes -fPIC +LDFLAGS = -Wl,--gc-sections + +all: start $(OBJDIR)/libsss7.so $(OBJDIR)/test + @echo ":: Done !" + +start: + @echo " SSS7 linux port $(VERSION)" + @echo "==========================" + +$(OBJDIR)/test : $(OBJDIR)/test.o $(OBJDIR)/sss7core/sss7.o $(OBJDIR)/libsss7.so + +$(OBJDIR)/%.o : %.c $(HEADERS) Makefile + @mkdir -p $$(dirname $@) + $(CC) $(CFLAGS) -c $< -o $@ + +$(OBJDIR)/sss7core/%.o : ../sss7core/%.c $(HEADERS) Makefile + @mkdir -p $$(dirname $@) + $(CC) $(CFLAGS) -c $< -o $@ + +$(OBJDIR)/%.so : $(OBJDIR)/%.o + @mkdir -p $$(dirname $@) + $(CC) $+ -shared $(LDFLAGS) -o $@ + +$(OBJDIR)/$(TARGET) : $(TARGET).o + $(CC) $(LDFLAGS) $+ -o $@ + + +clean : + @rm -rf $(OBJDIR) + +test: all + $(OBJDIR)/test diff --git a/software/linux/bin/libsss7.so b/software/linux/bin/libsss7.so new file mode 100755 index 0000000..a314a4b Binary files /dev/null and b/software/linux/bin/libsss7.so differ diff --git a/software/linux/bin/sss7core/sss7.o b/software/linux/bin/sss7core/sss7.o new file mode 100644 index 0000000..b7b5f5f Binary files /dev/null and b/software/linux/bin/sss7core/sss7.o differ diff --git a/software/linux/bin/test b/software/linux/bin/test new file mode 100755 index 0000000..a2cfd93 Binary files /dev/null and b/software/linux/bin/test differ diff --git a/software/linux/bin/test.o b/software/linux/bin/test.o new file mode 100644 index 0000000..15f97f5 Binary files /dev/null and b/software/linux/bin/test.o differ diff --git a/software/linux/libsss7.c b/software/linux/libsss7.c new file mode 100644 index 0000000..ea0fd6a --- /dev/null +++ b/software/linux/libsss7.c @@ -0,0 +1,96 @@ +#include "libsss7.h" + +#include +#include +#include +#include +#include +#include + +uint8_t uart_rx_byte; +uint8_t uart_tx_byte, uart_has_tx_byte; + +int serial_fd; + +int libsss7_start(char *serialport) { + sss7_init(); + + serial_fd = open(serialport, O_RDWR | O_NOCTTY | O_NDELAY); + if (serial_fd == -1) { + perror("Error: Unable to open serialport"); + return -1; + } + + //Switch to blocking mode + fcntl(serial_fd, F_SETFL, 0); + + struct termios options; + cfsetispeed(&options, B9600); + cfsetospeed(&options, B9600); + + // 8N1 + options.c_cflag = (CLOCAL | CREAD); + options.c_cflag |= CS8; + + // Raw mode, no features + options.c_lflag = 0; + + // No parity checks, no flow control + options.c_iflag = 0; + + // No output processing + options.c_oflag = 0; + + options.c_cc[VTIME] = 20; + options.c_cc[VMIN] = 0; + tcsetattr(serial_fd, TCSAFLUSH, &options); + + int res = 0; + while(1) { + res = read(serial_fd, &uart_rx_byte, 1); + if(res == 1) { + sss7_process_rx(); + } + + if(uart_has_tx_byte) { + uart_has_tx_byte = 0; + write(serial_fd, &uart_has_tx_byte, 1); + sss7_process_tx(); + } + } + + return 0; +} + +int libsss7_can_send(void) { + return sss7_can_send(); +} + +void libsss7_send(uint8_t msg[SSS7_PAYLOAD_SIZE]) { + +} + +int libsss7_send_failed(void) { + return sss7_send_failed(); +} + +int libsss7_has_received(void) { + return sss7_has_received(); +} + +void libsss7_get_received(uint8_t msg[SSS7_PAYLOAD_SIZE]) { + return sss7_get_received(msg); +} + +void libsss7_stop() { + close(serial_fd); +} + +uint8_t uart_get_byte(void) { + return uart_rx_byte; +} + +void uart_put_byte(uint8_t byte) { + uart_has_tx_byte = 1; + uart_tx_byte = byte; +} diff --git a/software/linux/libsss7.h b/software/linux/libsss7.h new file mode 100644 index 0000000..e26f3ac --- /dev/null +++ b/software/linux/libsss7.h @@ -0,0 +1,21 @@ +#ifndef _LIBSSS7_H_ +#define _LIBSSS7_H_ + +#include "sss7.h" + + +int libsss7_start(char *serialport); + +int libsss7_can_send(void); + +void libsss7_send(uint8_t msg[SSS7_PAYLOAD_SIZE]); + +int libsss7_send_failed(void); + +int libsss7_has_received(void); + +void libsss7_get_received(uint8_t msg[SSS7_PAYLOAD_SIZE]); + +void libsss7_stop(); + +#endif diff --git a/software/linux/test.c b/software/linux/test.c new file mode 100644 index 0000000..7374678 --- /dev/null +++ b/software/linux/test.c @@ -0,0 +1,11 @@ +#include +#include + +#include "libsss7.h" + +int main(int argc, char const *argv[]) { + libsss7_start("/tmp/ttyVA"); + + libsss7_stop(); + return 0; +}