summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcbdev <cb@cbcdn.com>2023-06-17 23:20:39 +0200
committercbdev <cb@cbcdn.com>2023-06-17 23:20:39 +0200
commit209897056d43ea0d682700e1078a8988a9b133f3 (patch)
tree9190807286b9aff9d2dafecc6a9fe0229d0d15a3
parentaa692f0dcdeefc846d7fa11222d6b2f6af17f5fa (diff)
downloadnfcommander-209897056d43ea0d682700e1078a8988a9b133f3.tar.gz
nfcommander-209897056d43ea0d682700e1078a8988a9b133f3.tar.bz2
nfcommander-209897056d43ea0d682700e1078a8988a9b133f3.zip
Core fd handling
-rw-r--r--Makefile2
-rw-r--r--command.c14
-rw-r--r--command.h2
-rw-r--r--control.c6
-rw-r--r--control.h1
-rw-r--r--nfcommander.c41
-rw-r--r--reader.c6
-rw-r--r--reader.h1
8 files changed, 69 insertions, 4 deletions
diff --git a/Makefile b/Makefile
index 6b04db5..ca709b7 100644
--- a/Makefile
+++ b/Makefile
@@ -1,7 +1,7 @@
.PHONY: all
CFLAGS += -g -Wall -Wpedantic
-CORE_OBJS = control.o reader.o config.o
+CORE_OBJS = control.o reader.o config.o command.o
PLUGINS = reader_yhy.so
reader_yhy.so: LDLIBS = -lyhy
diff --git a/command.c b/command.c
new file mode 100644
index 0000000..c7a7be8
--- /dev/null
+++ b/command.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+
+#include "command.h"
+
+int command_handle(int fd){
+ //TODO
+ printf("Handling data on command fd\n");
+ return 0;
+}
+
+void command_free(){
+ //TODO
+ printf("Shutting down any remaining commands\n");
+}
diff --git a/command.h b/command.h
new file mode 100644
index 0000000..7bae5ae
--- /dev/null
+++ b/command.h
@@ -0,0 +1,2 @@
+int command_handle(int fd);
+void command_free();
diff --git a/control.c b/control.c
index 2965d93..2c9b72b 100644
--- a/control.c
+++ b/control.c
@@ -8,6 +8,12 @@ int control_start(){
return 0;
}
+int control_handle(int fd){
+ //TODO
+ printf("Handling data on control fd\n");
+ return 0;
+}
+
void control_free(){
printf("Shutting down control interface\n");
}
diff --git a/control.h b/control.h
index 9537682..8cd260c 100644
--- a/control.h
+++ b/control.h
@@ -1,2 +1,3 @@
int control_start();
+int control_handle(int fd);
void control_free();
diff --git a/nfcommander.c b/nfcommander.c
index ceadec7..3c58d6c 100644
--- a/nfcommander.c
+++ b/nfcommander.c
@@ -7,6 +7,15 @@
#include "config.h"
#include "reader.h"
#include "control.h"
+#include "command.h"
+
+typedef union {
+ struct {
+ uint32_t system;
+ uint32_t fd;
+ } components;
+ uint64_t u64;
+} epoll_private_t;
static volatile sig_atomic_t shutdown_requested = 0;
static int epoll_fd = -1;
@@ -23,9 +32,14 @@ static int usage(char* fn){
}
int core_manage_fd(int fd, int manage, notification_target_t system){
+ epoll_private_t data = {
+ .components.system = system,
+ .components.fd = fd
+ };
+
struct epoll_event event = {
.events = EPOLLIN,
- .data.u32 = system
+ .data.u64 = data.u64
};
if(epoll_ctl(epoll_fd, manage ? EPOLL_CTL_ADD : EPOLL_CTL_DEL, fd, &event)){
@@ -37,6 +51,10 @@ int core_manage_fd(int fd, int manage, notification_target_t system){
}
int main(int argc, char** argv){
+ size_t n;
+ int event_count;
+ epoll_private_t polldata;
+
if(argc < 2){
return usage(argv[0]);
}
@@ -66,12 +84,28 @@ int main(int argc, char** argv){
//handle events
while(!shutdown_requested){
- int event_count = epoll_wait(epoll_fd, events, sizeof(events) / sizeof(struct epoll_event), 1000);
+ event_count = epoll_wait(epoll_fd, events, sizeof(events) / sizeof(struct epoll_event), 1000);
if(event_count < 0){
break;
}
- printf("%d events\n", event_count);
+ for(n = 0; n < event_count; n++){
+ polldata.u64 = events[n].data.u64;
+ switch(polldata.components.system){
+ case system_control:
+ control_handle(polldata.components.fd);
+ break;
+ case system_reader:
+ reader_handle(polldata.components.fd);
+ break;
+ case system_command:
+ command_handle(polldata.components.fd);
+ break;
+ default:
+ printf("Unhandled target system for fd %d\n", polldata.components.fd);
+ break;
+ }
+ }
}
//clean up
@@ -79,5 +113,6 @@ int main(int argc, char** argv){
epoll_fd = -1;
reader_free();
control_free();
+ command_free();
config_free();
}
diff --git a/reader.c b/reader.c
index 1186800..5c5881c 100644
--- a/reader.c
+++ b/reader.c
@@ -28,6 +28,12 @@ int reader_init(){
return 0;
}
+int reader_handle(int fd){
+ //TODO
+ printf("Handling data on reader fd\n");
+ return 0;
+}
+
void reader_free(){
if(reader_module){
dlclose(reader_module);
diff --git a/reader.h b/reader.h
index 650119a..c1136bb 100644
--- a/reader.h
+++ b/reader.h
@@ -1,2 +1,3 @@
int reader_init();
+int reader_handle(int fd);
void reader_free();