diff --git a/bin/Makefile b/bin/Makefile index 46e8cf7..58062ee 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -7,7 +7,7 @@ INCLUDE_PATH = ../include CFLAGS += -I$(INCLUDE_PATH) LDFLAGS = -L../src -lhexagram STATIC = ../src/libhexagram.a -OBJS = capture.o convert.o replay.o replaypcap.o main.o +OBJS = capture.o pcap2can.o replay.o pcapreplay.o main.o NAME = hexagram RM = /bin/rm diff --git a/bin/convert.h b/bin/convert.h deleted file mode 100644 index e3f946f..0000000 --- a/bin/convert.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _CONVERT_H -#define _CONVERT_H - -char *hexagram_arglist_convert(void); - -int hexagram_main_convert(int argc, char **argv); - -#endif /* _CONVERT_H */ diff --git a/bin/main.c b/bin/main.c index f8915c0..76aa16f 100644 --- a/bin/main.c +++ b/bin/main.c @@ -4,9 +4,9 @@ #include #include "capture.h" -#include "convert.h" #include "replay.h" -#include "replaypcap.h" +#include "pcap2can.h" +#include "pcapreplay.h" typedef struct { const char *name; @@ -16,9 +16,9 @@ typedef struct { hexagram_app apps[] = { { "capture", hexagram_arglist_capture, hexagram_main_capture }, - { "convert", hexagram_arglist_convert, hexagram_main_convert }, { "replay", hexagram_arglist_replay, hexagram_main_replay }, - { "replaypcap", hexagram_arglist_replaypcap, hexagram_main_replaypcap }, + { "pcap2can", hexagram_arglist_pcap2can, hexagram_main_pcap2can }, + { "pcapreplay", hexagram_arglist_pcapreplay, hexagram_main_pcapreplay }, { NULL, NULL, NULL } }; diff --git a/bin/convert.c b/bin/pcap2can.c similarity index 98% rename from bin/convert.c rename to bin/pcap2can.c index 0cba80a..c2a96b0 100644 --- a/bin/convert.c +++ b/bin/pcap2can.c @@ -10,7 +10,7 @@ #include #include -char *hexagram_arglist_convert(void) { +char *hexagram_arglist_pcap2can(void) { return "[infile.pcapng] [outfile.can]"; } @@ -190,7 +190,7 @@ error_io: return -1; } -int hexagram_main_convert(int argc, char **argv) { +int hexagram_main_pcap2can(int argc, char **argv) { int fd; hexagram_pcapng_stream *stream; diff --git a/bin/pcap2can.h b/bin/pcap2can.h new file mode 100644 index 0000000..dc0bf74 --- /dev/null +++ b/bin/pcap2can.h @@ -0,0 +1,8 @@ +#ifndef _CONVERT_H +#define _CONVERT_H + +char *hexagram_arglist_pcap2can(void); + +int hexagram_main_pcap2can(int argc, char **argv); + +#endif /* _CONVERT_H */ diff --git a/bin/replaypcap.c b/bin/pcapreplay.c similarity index 94% rename from bin/replaypcap.c rename to bin/pcapreplay.c index 08b60cf..097f662 100644 --- a/bin/replaypcap.c +++ b/bin/pcapreplay.c @@ -16,14 +16,14 @@ #include -#include "replaypcap.h" +#include "pcapreplay.h" struct pcapinfo { int sock; useconds_t last_time; }; -char *hexagram_arglist_replaypcap(void) { +char *hexagram_arglist_pcapreplay(void) { return "canif [file.pcapng]"; } @@ -37,7 +37,7 @@ static void usage(int argc, char **argv, const char *message, ...) { } fprintf(stderr, "usage: hexagram %s %s\n", - argv[0], hexagram_arglist_replaypcap()); + argv[0], hexagram_arglist_pcapreplay()); exit(1); } @@ -161,11 +161,6 @@ static ssize_t handle_block_packet(hexagram_pcapng_stream *stream, frame.can_id = be32toh(frame.can_id); - printf("Read packet %"PRIu32" bytes time hi %"PRIu32" lo %"PRIu32" id %8"PRIx32" payload %d\n", - header.caplen, header.timestamp[0], header.timestamp[1], - frame.can_id, - frame.can_dlc); - if (write(data->sock, &frame, sizeof(struct can_frame)) < 0) { goto error_io; } @@ -232,7 +227,7 @@ error_io: return -1; } -int hexagram_main_replaypcap(int argc, char **argv) { +int hexagram_main_pcapreplay(int argc, char **argv) { int fd; struct sockaddr_can addr; diff --git a/bin/pcapreplay.h b/bin/pcapreplay.h new file mode 100644 index 0000000..aa96d8e --- /dev/null +++ b/bin/pcapreplay.h @@ -0,0 +1,8 @@ +#ifndef _REPLAYPCAP_H +#define _REPLAYPCAP_H + +char *hexagram_arglist_pcapreplay(void); + +int hexagram_main_pcapreplay(int argc, char **argv); + +#endif /* _REPLAYPCAP_H */ diff --git a/bin/replaypcap.h b/bin/replaypcap.h deleted file mode 100644 index 8f34b70..0000000 --- a/bin/replaypcap.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _REPLAYPCAP_H -#define _REPLAYPCAP_H - -char *hexagram_arglist_replaypcap(void); - -int hexagram_main_replaypcap(int argc, char **argv); - -#endif /* _REPLAYPCAP_H */ diff --git a/include/hexagram/module.h b/include/hexagram/module.h index 0985e87..a1451d8 100644 --- a/include/hexagram/module.h +++ b/include/hexagram/module.h @@ -14,6 +14,8 @@ int hexagram_module_close(hexagram_module *module); const char *hexagram_module_name(hexagram_module *module); +int hexagram_module_win(hexagram_module *module); + int hexagram_module_run(hexagram_module *module, hexagram_dict *buses); diff --git a/src/module.c b/src/module.c index 439a10c..c4a93d7 100644 --- a/src/module.c +++ b/src/module.c @@ -11,6 +11,7 @@ struct _hexagram_module { const char *soname; void *handle; char *(*name)(); + int (*win)(); int (*run)(hexagram_dict *buses); pid_t pid; }; @@ -57,6 +58,14 @@ const char *hexagram_module_name(hexagram_module *module) { return module->name(); } +int hexagram_module_win(hexagram_module *module) { + if (module->win == NULL) { + return -1; + } + + return module->win(); +} + int hexagram_module_run(hexagram_module *module, hexagram_dict *buses) { if (module->run == NULL) { diff --git a/src/sim.c b/src/sim.c index a96caae..04f45ef 100644 --- a/src/sim.c +++ b/src/sim.c @@ -4,7 +4,7 @@ #include struct _hexagram_sim { - hexagram_dict *can_ifs; + hexagram_dict *buses; hexagram_dict *modules; }; @@ -15,8 +15,8 @@ hexagram_sim *hexagram_sim_new() { goto error_malloc; } - if ((sim->can_ifs = hexagram_dict_new()) == NULL) { - goto error_dict_new_can_ifs; + if ((sim->buses = hexagram_dict_new()) == NULL) { + goto error_dict_new_buses; } if ((sim->modules = hexagram_dict_new()) == NULL) { @@ -26,9 +26,9 @@ hexagram_sim *hexagram_sim_new() { return sim; error_dict_new_modules: - hexagram_dict_destroy(sim->can_ifs); + hexagram_dict_destroy(sim->buses); -error_dict_new_can_ifs: +error_dict_new_buses: free(sim); error_malloc: @@ -37,22 +37,21 @@ error_malloc: void hexagram_sim_destroy(hexagram_sim *sim) { hexagram_dict_destroy(sim->modules); - hexagram_dict_destroy(sim->can_ifs); + hexagram_dict_destroy(sim->buses); free(sim); } -int hexagram_sim_add_can_if(hexagram_sim *sim, - const char *name, - hexagram_can_if *can_if) { - if (hexagram_dict_set(sim->can_ifs, - (void *)name, strlen(name), can_if) == NULL) { - goto error_dict_set; +int hexagram_sim_add_bus(hexagram_sim *sim, + const char *name, + hexagram_can_if *bus) { + if (hexagram_dict_set_s(sim->buses, name, bus) == NULL) { + goto error_dict_set_s; } return 0; -error_dict_set: +error_dict_set_s: return -1; } @@ -64,14 +63,13 @@ int hexagram_sim_add_module(hexagram_sim *sim, goto error_module_name; } - if (hexagram_dict_set(sim->modules, - (void *)name, strlen(name), module) == NULL) { - goto error_dict_set; + if (hexagram_dict_set_s(sim->modules, name, module) == NULL) { + goto error_dict_set_s; } return 0; -error_dict_set: +error_dict_set_s: error_module_name: return -1; }