stub binding wifi engine

This commit is contained in:
vemax78 2013-05-01 21:33:54 +02:00
parent 930b0a6a3a
commit 05ab7a3787
9 changed files with 210 additions and 48 deletions

View File

@ -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

View File

@ -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])

View File

View File

@ -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);
}
}
}

View File

@ -0,0 +1,33 @@
#ifndef __WIFI_DRIVERS_HEADER__
#define __WIFI_DRIVERS_HEADER__
/* config */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#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__ */

View File

@ -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
};

View File

@ -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 */

View File

@ -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 */