From 47fcf7b0923fce5a5c95d4252615dbd83980c486 Mon Sep 17 00:00:00 2001 From: David Bauer Date: Fri, 16 Aug 2024 23:23:06 +0200 Subject: [PATCH] initial commit --- .github/workflows/build.yaml | 39 ++++++++++++++ .gitignore | 2 + Makefile | 14 ++++++ README.md | 21 ++++++++ t5g.c | 98 ++++++++++++++++++++++++++++++++++++ 5 files changed, 174 insertions(+) create mode 100644 .github/workflows/build.yaml create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 README.md create mode 100644 t5g.c diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..279a3ce --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,39 @@ +name: Build App + +on: + push: + pull_request: + +env: + COMPILER_VERSION: arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-linux-gnueabihf + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Download Toolchain + run: wget -O /tmp/toolchain.tar.xz https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu/13.3.rel1/binrel/${{ env.COMPILER_VERSION }}.tar.xz + + - name: Extract Toolchain + run: tar -xf /tmp/toolchain.tar.xz -C /tmp + + - name: Compile App + run: make CROSS_COMPILE=/tmp/${{ env.COMPILER_VERSION }}/bin/arm-none-linux-gnueabihf- + + - name: Upload Build output + uses: actions/upload-artifact@v4 + with: + name: build-output + path: output/ + + - name: Create GitHub Release + uses: softprops/action-gh-release@v2 + if: github.event_name == 'push' && github.ref_type == 'tag' + with: + body: "Version ${{ github.ref_name }}" + files: | + output/* diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..19b70a0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vscode/ +output/ \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..d5c8293 --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +CROSS_COMPILE ?= +GCC ?= $(CROSS_COMPILE)gcc +STRIP ?= $(CROSS_COMPILE)strip + +# Take git short-hash as version +VERSION ?= $(shell git rev-parse --short HEAD) + +# Flags +CFLAGS = --static -O2 -DVERSION=\"$(VERSION)\" + +all: + mkdir -p output + $(GCC) $(CFLAGS) -o output/t5g-at t5g.c + $(STRIP) output/t5g-at \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..abd2e68 --- /dev/null +++ b/README.md @@ -0,0 +1,21 @@ +# t5g-at-interface + +Quick and dirty programm for interfacing with the Modem AT Command interface on the host system of a Telekom 5G Empfänger SE. + +## TL;DR + +ToDo + +## How to compile + +```bash +wget -O /tmp/toolchain.tar.xz https://armkeil.blob.core.windows.net/developer/Files/downloads/gnu/13.3.rel1/binrel/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-linux-gnueabihf.tar.xz +tar -xf /tmp/toolchain.tar.xz -C /tmp +make CROSS_COMPILE=/tmp/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-linux-gnueabihf/bin/arm-none-linux-gnueabihf- +``` + +## How to use + +```bash +./t5g-at-interface +``` diff --git a/t5g.c b/t5g.c new file mode 100644 index 0000000..56e275a --- /dev/null +++ b/t5g.c @@ -0,0 +1,98 @@ +#include +#include +#include +#include +#include +#include +#include + +#define AT_COMMAND_FILE "/dev/smd7" + +int open_file(char *filename, int mode) { + int file = open(filename, mode); + if (file < 0) { + printf("Error: Could not open file %s\n", filename); + return file; + } + return file; +} + +int main(int argc, char *argv[]) { + char *file_path = NULL; + int file_in = 0, file_out = 0; + int ret = 0; + int i; + int n; + + file_path = AT_COMMAND_FILE; + if (argc == 2) { + file_path = argv[1]; + } + + /* Set stdin non-blocking */ + int flags = fcntl(STDIN_FILENO, F_GETFL, 0); + fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK); + + /* Open /dev/smd7 */ + file_in = open_file(file_path, O_RDONLY); + if (file_in < 0) { + fprintf(stderr, "Error: Could not open AT command file\n"); + ret = 1; + goto out_free; + } + flags = fcntl(file_in, F_GETFL, 0); + fcntl(file_in, F_SETFL, flags | O_NONBLOCK); + + file_out = open_file(file_path, O_WRONLY); + if (file_out < 0) { + fprintf(stderr, "Error: Could not open AT command file\n"); + ret = 1; + goto out_free; + } + + while (1) { + char buf[1024]; + + /* Read non-blocking from file */ + n = read(file_in, buf, sizeof(buf)); + if (n < 0 && errno != EAGAIN) { + ret = 1; + fprintf(stderr, "Error: Could not read from AT command file\n"); + goto out_free; + } else if (n > 0) { + buf[n] = '\0'; + fprintf(stdout, "%s", buf); + } + + /* Read non-blocking from stdin */ + n = read(STDIN_FILENO, buf, sizeof(buf)); + if (n < 0) { + if (errno == EAGAIN) + continue; + ret = 1; + fprintf(stderr, "Error: Could not read from AT command file\n"); + goto out_free; + } + + /* Print all character codes */ + buf[n - 1] = '\r'; + buf[n] = '\n'; + + //printf("Writing %d bytes to file\n", n); + if (write(file_out, buf, n + 1) != n + 1) { + fprintf(stderr, "Error: Could not write to AT command file\n"); + ret = 1; + goto out_free; + } + } + +out_free: + if (file_in > 0) { + close(file_in); + } + + if (file_out > 0) { + close(file_out); + } + return 0; +} \ No newline at end of file