diff options
-rw-r--r-- | Makefile | 20 | ||||
-rw-r--r-- | commander.cfg | 12 | ||||
-rw-r--r-- | config.c | 29 | ||||
-rw-r--r-- | config.h | 3 | ||||
-rw-r--r-- | control.c | 13 | ||||
-rw-r--r-- | control.h | 2 | ||||
-rw-r--r-- | nfcommander.c | 37 | ||||
-rw-r--r-- | nfcommander.h | 8 | ||||
-rw-r--r-- | reader.c | 36 | ||||
-rw-r--r-- | reader.h | 2 | ||||
-rw-r--r-- | reader_yhy.c | 11 | ||||
-rw-r--r-- | reader_yhy.h | 0 |
12 files changed, 173 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9cb714b --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +.PHONY: all + +CFLAGS += -g -Wall -Wpedantic +CORE_OBJS = control.o reader.o config.o +PLUGINS = reader_yhy.so + +%.so: CFLAGS += -shared -fPIC + +%.so :: %.c %.h + $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS) $(LDLIBS) + +nfcommander: LDLIBS = -ldl + +all: nfcommander $(PLUGINS) + +nfcommander: nfcommander.c nfcommander.h $(CORE_OBJS) + +clean: + $(RM) nfcommander + $(RM) $(CORE_OBJS) diff --git a/commander.cfg b/commander.cfg new file mode 100644 index 0000000..ec9895f --- /dev/null +++ b/commander.cfg @@ -0,0 +1,12 @@ +[nfc] +reader=yhy +device=/dev/ttyACM0 +mifare.defaultkeys=FFFFFFFFFFFF,000000000000 +mifare.prodkey=123456123456 + +[control] +bind = 0.0.0.0 7812 + +[command play] +chdir = commands +exec = ./play diff --git a/config.c b/config.c new file mode 100644 index 0000000..f11bbb6 --- /dev/null +++ b/config.c @@ -0,0 +1,29 @@ +#include <stdio.h> +#include <string.h> + +#include "nfcommander.h" +#include "config.h" + +int config_read(char* path){ + //TODO + printf("Reading config file %s\n", path); + + return 0; +} + +char* config_get(char* section, char* property){ + //TODO + printf("Querying for config property %s->%s\n", section, property); + + //TEMP + if(!strcmp(property, "reader")){ + return "yhy"; + } + + return NULL; +} + +void config_free(){ + //TODO + printf("Cleaning up config data\n"); +} diff --git a/config.h b/config.h new file mode 100644 index 0000000..d39b6ff --- /dev/null +++ b/config.h @@ -0,0 +1,3 @@ +int config_read(char* path); +char* config_get(char* section, char* property); +void config_free(); diff --git a/control.c b/control.c new file mode 100644 index 0000000..2965d93 --- /dev/null +++ b/control.c @@ -0,0 +1,13 @@ +#include <stdio.h> + +#include "control.h" + +int control_start(){ + //TODO + printf("Starting up control interface\n"); + return 0; +} + +void control_free(){ + printf("Shutting down control interface\n"); +} diff --git a/control.h b/control.h new file mode 100644 index 0000000..9537682 --- /dev/null +++ b/control.h @@ -0,0 +1,2 @@ +int control_start(); +void control_free(); diff --git a/nfcommander.c b/nfcommander.c new file mode 100644 index 0000000..de50ef4 --- /dev/null +++ b/nfcommander.c @@ -0,0 +1,37 @@ +#include <stdio.h> + +#include "nfcommander.h" +#include "config.h" +#include "reader.h" +#include "control.h" + +int usage(char* fn){ + printf("NFCommander - trigger actions based on near-field tags\n"); + printf("\tUsage: %s <config-file>\n", fn); + return EXIT_FAILURE; +} + +int main(int argc, char** argv){ + if(argc < 2){ + return usage(argv[0]); + } + + //read configuration + if(config_read(argv[1])){ + return usage(argv[0]); + } + + //start reader api + reader_init(); + + //start control api + control_start(); + + //handle events + //TODO + + //clean up + reader_free(); + control_free(); + config_free(); +} diff --git a/nfcommander.h b/nfcommander.h new file mode 100644 index 0000000..dbab99f --- /dev/null +++ b/nfcommander.h @@ -0,0 +1,8 @@ +#include <stdlib.h> +#include <stdint.h> +#include <inttypes.h> + +#ifndef NFCOMMANDER_VERSION + #define NFCOMMANDER_VERSION "v0.1-dev" +#endif + diff --git a/reader.c b/reader.c new file mode 100644 index 0000000..1186800 --- /dev/null +++ b/reader.c @@ -0,0 +1,36 @@ +#include <stdio.h> +#include <limits.h> +#include <dlfcn.h> + +#include "reader.h" +#include "config.h" + +#define MAX_PLUGIN_PATH NAME_MAX +void* reader_module = NULL; + +int reader_init(){ + char plugin[MAX_PLUGIN_PATH] = ""; + char* reader = config_get("nfc", "reader"); + + if(!reader){ + printf("No reader plugin configured\n"); + return -1; + } + + snprintf(plugin, sizeof(plugin), "./reader_%s.so", reader); + reader_module = dlopen(plugin, RTLD_NOW); + + if(!reader_module){ + printf("Failed to load reader plugin %s\n", plugin); + return -1; + } + + return 0; +} + +void reader_free(){ + if(reader_module){ + dlclose(reader_module); + reader_module = NULL; + } +} diff --git a/reader.h b/reader.h new file mode 100644 index 0000000..650119a --- /dev/null +++ b/reader.h @@ -0,0 +1,2 @@ +int reader_init(); +void reader_free(); diff --git a/reader_yhy.c b/reader_yhy.c new file mode 100644 index 0000000..da5be5e --- /dev/null +++ b/reader_yhy.c @@ -0,0 +1,11 @@ +#include <stdio.h> + +#include "nfcommander.h" + +static void __attribute__((constructor)) init() { + printf("This is the yhy reader plugin\n"); +} + +static void __attribute__((destructor)) cleanup() { + printf("This is the yhy reader plugin cleanup\n"); +} diff --git a/reader_yhy.h b/reader_yhy.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/reader_yhy.h |