diff --git a/build/wtp/Makefile.am b/build/wtp/Makefile.am index eb0eabb..7baf6db 100755 --- a/build/wtp/Makefile.am +++ b/build/wtp/Makefile.am @@ -33,7 +33,8 @@ endif INCLUDES = \ -I$(top_srcdir)/build \ -I$(top_srcdir)/src/common \ - -I$(top_srcdir)/src/wtp + -I$(top_srcdir)/src/wtp \ + -I$(top_srcdir)/src/binding/wifi/drivers include $(top_srcdir)/build/Makefile_common.am @@ -50,7 +51,8 @@ wtp_SOURCES = \ $(top_srcdir)/src/wtp/wtp_dfa_datacheck.c \ $(top_srcdir)/src/wtp/wtp_dfa_run.c \ $(top_srcdir)/src/wtp/wtp_dfa_reset.c \ - $(top_srcdir)/src/wtp/wtp_dfa_imagedata.c + $(top_srcdir)/src/wtp/wtp_dfa_imagedata.c \ + $(top_srcdir)/src/binding/wifi/drivers/wifi_drivers.c wtp_LDADD = \ $(CONFIG_LIBS) @@ -58,3 +60,7 @@ wtp_LDADD = \ if DTLS_ENABLED wtp_LDADD += $(SSL_LIBS) endif + +if BUILD_WTP_WIFI_DRIVERS_NL80211 +wtp_SOURCES += $(top_srcdir)/src/binding/wifi/drivers/wifi_nl80211.c +endif diff --git a/configure.ac b/configure.ac index be01770..bd044fc 100644 --- a/configure.ac +++ b/configure.ac @@ -93,6 +93,14 @@ AC_ARG_WITH( [with_mem_check="internal"] ) +# WTP drivers wifi binding +AC_ARG_ENABLE( + [wifi-drivers-nl80211], + [AS_HELP_STRING([--wifi-drivers-nl80211], [disable WTP support for nl80211 wifi binding @<:@default=yes@:>@])], + , + [enable_wifi_drivers_nl80211="yes"] +) + # specify output header file AM_CONFIG_HEADER(build/config.h) @@ -213,6 +221,10 @@ test "${enable_logging}" = "yes" && AC_DEFINE([ENABLE_LOGGING], [1], [Enable log AM_CONDITIONAL([BUILD_DEBUG], [test "${enable_debug}" = "yes"]) AM_CONDITIONAL([DTLS_ENABLED], [test "${enable_dtls}" = "yes"]) +# +test "${enable_wifi_drivers_nl80211}" = "yes" && AC_DEFINE([ENABLE_WIFI_DRIVERS_NL80211], [1], [Enable WTP support for nl80211 wifi binding]) +AM_CONDITIONAL([BUILD_WTP_WIFI_DRIVERS_NL80211], [test "${enable_wifi_drivers_nl80211}" = "yes"]) + # AC_SUBST([SSL_CFLAGS]) AC_SUBST([SSL_LIBS]) diff --git a/src/binding/wifi/ap/.hidden b/src/binding/wifi/ap/.hidden new file mode 100644 index 0000000..e69de29 diff --git a/src/common/startap.txt b/src/binding/wifi/drivers/startap.txt similarity index 100% rename from src/common/startap.txt rename to src/binding/wifi/drivers/startap.txt diff --git a/src/binding/wifi/drivers/wifi_drivers.c b/src/binding/wifi/drivers/wifi_drivers.c new file mode 100644 index 0000000..b0dc6a7 --- /dev/null +++ b/src/binding/wifi/drivers/wifi_drivers.c @@ -0,0 +1,48 @@ +#include "wifi_drivers.h" + +/* */ +struct wifi_driver_instance { + struct wifi_driver_ops* ops; /* Driver functions */ + + wifi_global_handle handle; /* Global instance handle */ +}; + +/* Declare enable wifi driver */ +#ifdef ENABLE_WIFI_DRIVERS_NL80211 +extern struct wifi_driver_ops wifi_driver_nl80211_ops; +#endif + +static struct wifi_driver_instance wifi_driver[] = { +#ifdef ENABLE_WIFI_DRIVERS_NL80211 + { &wifi_driver_nl80211_ops }, +#endif + { NULL } +}; + +/* */ +int wifi_init_driver(void) { + int i; + + for (i = 0; wifi_driver[i].ops != NULL; i++) { + if (!wifi_driver[i].ops->global_init) { + return -1; + } + + /* Initialize driver */ + wifi_driver[i].handle = wifi_driver[i].ops->global_init(); + } + + return 0; +} + +/* */ +void wifi_free_driver(void) { + int i; + + for (i = 0; wifi_driver[i].ops != NULL; i++) { + /* Free driver */ + if (wifi_driver[i].ops->global_deinit) { + wifi_driver[i].ops->global_deinit(wifi_driver[i].handle); + } + } +} diff --git a/src/binding/wifi/drivers/wifi_drivers.h b/src/binding/wifi/drivers/wifi_drivers.h new file mode 100644 index 0000000..942f399 --- /dev/null +++ b/src/binding/wifi/drivers/wifi_drivers.h @@ -0,0 +1,33 @@ +#ifndef __WIFI_DRIVERS_HEADER__ +#define __WIFI_DRIVERS_HEADER__ + +/* config */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include +#include +#include + +#include "capwap_debug.h" +#include "capwap_logging.h" + +/* */ +typedef void* wifi_global_handle; + +/* */ +struct wifi_driver_ops { + const char* name; /* Name of wifi driver */ + const char* description; /* Description of wifi driver */ + + /* Global initialize driver */ + wifi_global_handle (*global_init)(void); + void (*global_deinit)(wifi_global_handle handle); +}; + +/* Initialize wifi driver engine */ +int wifi_init_driver(void); +void wifi_free_driver(void); + +#endif /* __WIFI_DRIVERS_HEADER__ */ diff --git a/src/binding/wifi/drivers/wifi_nl80211.c b/src/binding/wifi/drivers/wifi_nl80211.c new file mode 100644 index 0000000..5b640b7 --- /dev/null +++ b/src/binding/wifi/drivers/wifi_nl80211.c @@ -0,0 +1,28 @@ +#include "wifi_drivers.h" + + + + + + + + + + + +/* */ +static wifi_global_handle nl80211_global_init(void) { + return NULL; +} + +/* */ +void nl80211_global_deinit(wifi_global_handle handle) { +} + +/* Driver function */ +const struct wifi_driver_ops wifi_driver_nl80211_ops = { + .name = "nl80211", + .description = "Linux nl80211/cfg80211", + .global_init = nl80211_global_init, + .global_deinit = nl80211_global_deinit +}; diff --git a/src/wtp/wtp.c b/src/wtp/wtp.c index 725840c..27a4803 100644 --- a/src/wtp/wtp.c +++ b/src/wtp/wtp.c @@ -900,60 +900,93 @@ int main(int argc, char** argv) { /* Init capwap */ if (geteuid() != 0) { capwap_logging_fatal("Request root privileges"); - return CAPWAP_REQUEST_ROOT; - } - - /* Init random generator */ - capwap_init_rand(); + result = CAPWAP_REQUEST_ROOT; + } else { + /* Init random generator */ + capwap_init_rand(); - /* Init crypt */ - if (!capwap_crypt_init()) { - capwap_logging_fatal("Error to init crypt engine"); - return CAPWAP_CRYPT_ERROR; - } + /* Init crypt */ + if (!capwap_crypt_init()) { + result = CAPWAP_CRYPT_ERROR; + capwap_logging_fatal("Error to init crypt engine"); + } else { + /* Alloc a WTP */ + if (!wtp_init()) { + result = WTP_ERROR_SYSTEM_FAILER; + capwap_logging_fatal("Error to init WTP engine"); + } else { + /* Read configuration file */ + value = wtp_load_configuration(argc, argv); + if (value < 0) { + result = WTP_ERROR_LOAD_CONFIGURATION; + capwap_logging_fatal("Error to load configuration"); + } else if (value > 0) { + /* Initialize binding */ + switch (g_wtp.binding) { + case CAPWAP_WIRELESS_BINDING_NONE: { + value = 0; + break; + } - /* Alloc a WTP */ - if (!wtp_init()) { - capwap_logging_fatal("Error to init WTP engine"); - return WTP_ERROR_SYSTEM_FAILER; - } + case CAPWAP_WIRELESS_BINDING_IEEE80211: { + /* Initialize wifi binding driver */ + capwap_logging_info("Initializing wifi binding engine"); + value = wifi_init_driver(); + break; + } + } - /* Read configuration file */ - value = wtp_load_configuration(argc, argv); - if (value < 0) { - result = WTP_ERROR_LOAD_CONFIGURATION; - } else if (value > 0) { - capwap_logging_info("Startup WTP"); + /* */ + if (value) { + result = WTP_ERROR_INIT_BINDING; + capwap_logging_fatal("Unable initialize binding engine"); + } else { + capwap_logging_info("Startup WTP"); - /* Start WTP */ - wtp_dfa_change_state(CAPWAP_START_TO_IDLE_STATE); + /* Start WTP */ + wtp_dfa_change_state(CAPWAP_START_TO_IDLE_STATE); - /* Complete configuration WTP */ - result = wtp_configure(); - if (result == CAPWAP_SUCCESSFUL) { - /* Init complete */ - wtp_dfa_change_state(CAPWAP_IDLE_STATE); + /* Complete configuration WTP */ + result = wtp_configure(); + if (result == CAPWAP_SUCCESSFUL) { + /* Init complete */ + wtp_dfa_change_state(CAPWAP_IDLE_STATE); - /* Running WTP */ - result = wtp_dfa_execute(); - - /* Close socket */ - capwap_close_sockets(&g_wtp.net); + /* Running WTP */ + result = wtp_dfa_execute(); + + /* Close socket */ + capwap_close_sockets(&g_wtp.net); + } + + capwap_logging_info("Terminate WTP"); + + /* Free binding */ + switch (g_wtp.binding) { + case CAPWAP_WIRELESS_BINDING_IEEE80211: { + /* Free wifi binding driver */ + wifi_free_driver(); + capwap_logging_info("Free wifi binding engine"); + break; + } + } + } + } + + /* Free memory */ + wtp_destroy(); + } + + /* Free crypt */ + capwap_crypt_free(); } - capwap_logging_info("Terminate WTP"); - } - - /* Free memory */ - wtp_destroy(); - - /* Free crypt */ - capwap_crypt_free(); - - /* Check memory leak */ - if (capwap_check_memory_leak(1)) { - if (result == CAPWAP_SUCCESSFUL) - result = WTP_ERROR_MEMORY_LEAK; + /* Check memory leak */ + if (capwap_check_memory_leak(1)) { + if (result == CAPWAP_SUCCESSFUL) { + result = WTP_ERROR_MEMORY_LEAK; + } + } } /* Close logging */ diff --git a/src/wtp/wtp.h b/src/wtp/wtp.h index a180ce5..633b370 100644 --- a/src/wtp/wtp.h +++ b/src/wtp/wtp.h @@ -6,6 +6,7 @@ #include "capwap_dtls.h" #include "capwap_network.h" #include "capwap_protocol.h" +#include "wifi_drivers.h" /* WTP Configuration */ #define WTP_STANDARD_CONFIGURATION_FILE "/etc/capwap/wtp.conf" @@ -14,6 +15,7 @@ #define WTP_ERROR_SYSTEM_FAILER -1000 #define WTP_ERROR_LOAD_CONFIGURATION -1001 #define WTP_ERROR_NETWORK -1002 +#define WTP_ERROR_INIT_BINDING -1003 #define WTP_ERROR_MEMORY_LEAK 1 /* Min and max dfa values */