Merge branch 'ansi'

FossilOrigin-Name: cc01b9d81e72d713d6739d318f5e8b022685f71ffd6c084b85da542a1e6fa34b
This commit is contained in:
7u83@mail.ru 2018-03-02 07:54:15 +00:00
commit 8f12f61dbd
141 changed files with 1451 additions and 3212 deletions

5
.gitignore vendored
View File

@ -46,5 +46,10 @@ ssl/intermediate-ca/
*.tar.xz
# other stuff
.depend
.codelite/
lib/
obj/
bin/
src/Config.local.mak

View File

@ -7,6 +7,7 @@
<Project Name="mod_cisco" Path="mod_cisco.project" Active="No"/>
<Project Name="libcw" Path="libcw.project" Active="Yes"/>
<Project Name="mod_capwap80211" Path="mod_capwap80211.project" Active="No"/>
<Project Name="mod_fortinet" Path="mod_fortinet.project" Active="No"/>
<BuildMatrix>
<WorkspaceConfiguration Name="Debug" Selected="yes">
<Environment/>
@ -17,6 +18,7 @@
<Project Name="mod_cisco" ConfigName="Debug"/>
<Project Name="libcw" ConfigName="Debug"/>
<Project Name="mod_capwap80211" ConfigName="Debug"/>
<Project Name="mod_fortinet" ConfigName="Debug"/>
</WorkspaceConfiguration>
<WorkspaceConfiguration Name="Release" Selected="yes">
<Environment/>
@ -27,6 +29,7 @@
<Project Name="mod_cisco" ConfigName="Release"/>
<Project Name="libcw" ConfigName="Release"/>
<Project Name="mod_capwap80211" ConfigName="Release"/>
<Project Name="mod_fortinet" ConfigName="Release"/>
</WorkspaceConfiguration>
</BuildMatrix>
</CodeLite_Workspace>

View File

@ -305,6 +305,8 @@
<File Name="src/cw/capwap_items.c"/>
<File Name="src/cw/message_set.c"/>
<File Name="src/cw/message_set.h"/>
<File Name="src/mod/cisco/mod_cisco.h"/>
<File Name="src/cw/cw_filename.c"/>
</VirtualDirectory>
</VirtualDirectory>
<Description/>

107
mod_capwap80211.project Normal file
View File

@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<CodeLite_Project Name="mod_capwap80211" InternalType="">
<VirtualDirectory Name="src">
<VirtualDirectory Name="mod">
<VirtualDirectory Name="capwap80211">
<File Name="src/mod/capwap80211/mod_capwap80211_wtp.c"/>
<File Name="src/mod/capwap80211/mod_capwap80211_ac.c"/>
<File Name="src/mod/capwap80211/mod_capwap80211.h"/>
<File Name="src/mod/capwap80211/capwap80211_actions_wtp.c"/>
<File Name="src/mod/capwap80211/capwap80211_out_wtp_radio_cfg.c"/>
<File Name="src/mod/capwap80211/capwap80211_actions_ac.c"/>
</VirtualDirectory>
</VirtualDirectory>
</VirtualDirectory>
<Description/>
<Dependencies/>
<Settings Type="Dynamic Library">
<GlobalSettings>
<Compiler Options="" C_Options="" Assembler="">
<IncludePath Value="."/>
</Compiler>
<Linker Options="">
<LibraryPath Value="."/>
</Linker>
<ResourceCompiler Options=""/>
</GlobalSettings>
<Configuration Name="Debug" CompilerType="GCC" DebuggerType="GNU gdb debugger" Type="Dynamic Library" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
<Compiler Options="-g" C_Options="-g" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
<IncludePath Value="."/>
</Compiler>
<Linker Options="" Required="yes"/>
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="" IntermediateDirectory="./Debug" Command="" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
<![CDATA[]]>
</Environment>
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
<DebuggerSearchPaths/>
<PostConnectCommands/>
<StartupCommands/>
</Debugger>
<PreBuild/>
<PostBuild/>
<CustomBuild Enabled="yes">
<RebuildCommand>make clean &amp;&amp; make
</RebuildCommand>
<CleanCommand>make clean</CleanCommand>
<BuildCommand>make</BuildCommand>
<PreprocessFileCommand/>
<SingleFileCommand/>
<MakefileGenerationCommand/>
<ThirdPartyToolName>None</ThirdPartyToolName>
<WorkingDirectory>$(WorkspacePath)/src/mod/capwap80211/</WorkingDirectory>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild/>
<CustomPreBuild/>
</AdditionalRules>
<Completion EnableCpp11="no" EnableCpp14="no">
<ClangCmpFlagsC/>
<ClangCmpFlags/>
<ClangPP/>
<SearchPaths/>
</Completion>
</Configuration>
<Configuration Name="Release" CompilerType="GCC" DebuggerType="GNU gdb debugger" Type="Dynamic Library" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
<Compiler Options="" C_Options="" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
<IncludePath Value="."/>
</Compiler>
<Linker Options="-O2" Required="yes"/>
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="" IntermediateDirectory="./Release" Command="" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
<![CDATA[]]>
</Environment>
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
<DebuggerSearchPaths/>
<PostConnectCommands/>
<StartupCommands/>
</Debugger>
<PreBuild/>
<PostBuild/>
<CustomBuild Enabled="yes">
<RebuildCommand/>
<CleanCommand>make clean</CleanCommand>
<BuildCommand>make</BuildCommand>
<PreprocessFileCommand/>
<SingleFileCommand/>
<MakefileGenerationCommand/>
<ThirdPartyToolName>None</ThirdPartyToolName>
<WorkingDirectory>$(WorkspacePath)</WorkingDirectory>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild/>
<CustomPreBuild/>
</AdditionalRules>
<Completion EnableCpp11="no" EnableCpp14="no">
<ClangCmpFlagsC/>
<ClangCmpFlags/>
<ClangPP/>
<SearchPaths/>
</Completion>
</Configuration>
</Settings>
<Dependencies Name="Debug"/>
<Dependencies Name="Release"/>
</CodeLite_Project>

View File

@ -13,7 +13,6 @@
<File Name="src/mod/cisco/cisco_out_wtp_descriptor.c"/>
<File Name="src/mod/cisco/cisco_out_wtp_administrative_state.c"/>
<File Name="src/mod/cisco/cisco_out_ac_descriptor.c"/>
<File Name="src/mod/cisco/mod_cisco.h"/>
<File Name="src/mod/cisco/cw_in_check_disc_req.c"/>
<File Name="src/mod/cisco/mod_cisco_ac.c"/>
<File Name="src/mod/cisco/cisco_in_ac_descriptor.c"/>
@ -36,6 +35,7 @@
<File Name="src/mod/cisco/cisco_out_ap_timesync.c"/>
<File Name="src/mod/cisco/mod_cisco_wtp.c"/>
<File Name="src/mod/cisco/cisco80211.c"/>
<File Name="src/mod/cisco/mod_cisco.h"/>
</VirtualDirectory>
</VirtualDirectory>
</VirtualDirectory>

104
mod_fortinet.project Normal file
View File

@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<CodeLite_Project Name="mod_fortinet" InternalType="">
<VirtualDirectory Name="src">
<VirtualDirectory Name="mod">
<VirtualDirectory Name="fortinet">
<File Name="src/mod/fortinet/mod_fortinet_ac.c"/>
<File Name="src/mod/fortinet/mod_fortinet_wtp.c"/>
<File Name="src/mod/fortinet/fortinet.h"/>
<File Name="src/mod/fortinet/fortinet_actions_ac.c"/>
<File Name="src/mod/fortinet/fortinet_actions_wtp.c"/>
<File Name="src/mod/fortinet/mod_fortinet.h"/>
</VirtualDirectory>
</VirtualDirectory>
</VirtualDirectory>
<Description/>
<Dependencies/>
<Settings Type="Dynamic Library">
<GlobalSettings>
<Compiler Options="" C_Options="" Assembler="">
<IncludePath Value="."/>
</Compiler>
<Linker Options="">
<LibraryPath Value="."/>
</Linker>
<ResourceCompiler Options=""/>
</GlobalSettings>
<Configuration Name="Debug" CompilerType="GCC" DebuggerType="GNU gdb debugger" Type="Dynamic Library" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
<Compiler Options="-g" C_Options="-g" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
<IncludePath Value="."/>
</Compiler>
<Linker Options="" Required="yes"/>
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="" IntermediateDirectory="./Debug" Command="" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
<![CDATA[]]>
</Environment>
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
<DebuggerSearchPaths/>
<PostConnectCommands/>
<StartupCommands/>
</Debugger>
<PreBuild/>
<PostBuild/>
<CustomBuild Enabled="yes">
<RebuildCommand>make clean &amp;&amp; make</RebuildCommand>
<CleanCommand>make clean</CleanCommand>
<BuildCommand>make</BuildCommand>
<PreprocessFileCommand/>
<SingleFileCommand/>
<MakefileGenerationCommand/>
<ThirdPartyToolName>None</ThirdPartyToolName>
<WorkingDirectory>$(WorkspacePath)/src/mod/fortinet</WorkingDirectory>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild/>
<CustomPreBuild/>
</AdditionalRules>
<Completion EnableCpp11="no" EnableCpp14="no">
<ClangCmpFlagsC/>
<ClangCmpFlags/>
<ClangPP/>
<SearchPaths/>
</Completion>
</Configuration>
<Configuration Name="Release" CompilerType="GCC" DebuggerType="GNU gdb debugger" Type="Dynamic Library" BuildCmpWithGlobalSettings="append" BuildLnkWithGlobalSettings="append" BuildResWithGlobalSettings="append">
<Compiler Options="" C_Options="" Assembler="" Required="yes" PreCompiledHeader="" PCHInCommandLine="no" PCHFlags="" PCHFlagsPolicy="0">
<IncludePath Value="."/>
</Compiler>
<Linker Options="-O2" Required="yes"/>
<ResourceCompiler Options="" Required="no"/>
<General OutputFile="" IntermediateDirectory="./Release" Command="" CommandArguments="" UseSeparateDebugArgs="no" DebugArguments="" WorkingDirectory="$(IntermediateDirectory)" PauseExecWhenProcTerminates="yes" IsGUIProgram="no" IsEnabled="yes"/>
<Environment EnvVarSetName="&lt;Use Defaults&gt;" DbgSetName="&lt;Use Defaults&gt;">
<![CDATA[]]>
</Environment>
<Debugger IsRemote="no" RemoteHostName="" RemoteHostPort="" DebuggerPath="" IsExtended="no">
<DebuggerSearchPaths/>
<PostConnectCommands/>
<StartupCommands/>
</Debugger>
<PreBuild/>
<PostBuild/>
<CustomBuild Enabled="yes">
<RebuildCommand/>
<CleanCommand>make clean</CleanCommand>
<BuildCommand>make</BuildCommand>
<PreprocessFileCommand/>
<SingleFileCommand/>
<MakefileGenerationCommand/>
<ThirdPartyToolName>None</ThirdPartyToolName>
<WorkingDirectory>$(WorkspacePath)</WorkingDirectory>
</CustomBuild>
<AdditionalRules>
<CustomPostBuild/>
<CustomPreBuild/>
</AdditionalRules>
<Completion EnableCpp11="no" EnableCpp14="no">
<ClangCmpFlagsC/>
<ClangCmpFlags/>
<ClangPP/>
<SearchPaths/>
</Completion>
</Configuration>
</Settings>
</CodeLite_Project>

View File

@ -1,8 +1,7 @@
include ../Config.mak
#Define SSL Library: OPENSSL or GNUTLS
#SSL_LIBRARY=OPENSSL
SSL_LIBRARY=GNUTLS
# Define SSL Library: OPENSSL or GNUTLS
# SSL_LIBRARY=OPENSSL
SSL_LIBRARY=OPENSSL

View File

@ -1,25 +1,37 @@
#
# OpenSSL definitions
#
#OPENSSL_VERSION=openssl-1.0.1l # doesn't work
#OPENSSL_VERSION=openssl-1.0.2 # doesn't work
OPENSSL_VERSION=openssl-1.0.1i
# OPENSSL_VERSION=openssl-1.0.1i
USE_CONTRIB_OPENSSL=0
# GnuTLS definitions
GNUTLS_VERSION=3.3.9
# GNUTLS_VERSION=3.3.9
USE_CONTRIB_GNUTLS=0
# Compiler to use
CC=clang
#CC=gcc
#CC=mips-openwrt-linux-uclibc-gcc
#LD=mips-openwrt-linux-uclibc-ld
#AR=mips-openwrt-linux-uclibc-ar
# CC=clang
# CC=mips-openwrt-linux-uclibc-gcc
# LD=mips-openwrt-linux-uclibc-ld
# AR=mips-openwrt-linux-uclibc-ar
# CC=clang
COMPDEFS=-DWITH_CW_LOG
COMPDEFS+=-DWITH_CW_LOG_DEBUG
# LIBCW settings
# WITH_GNUTLS
# compile in support for GnuTLS
#
WITH_GNUTLS=1
# Compile in openssl support
WITH_OPENSSL=1
#
#
LIBDIR=lib

View File

@ -9,21 +9,42 @@ endif
ifeq ($(USE_CONTRIB_GNUTLS),1)
GNUTLS_CFLAGS=-I../contrib/gnutls-${GNUTLS_VERSION}/lib/includes
#GNUTLS_LIBS=-lnettle -lgmp ../contrib/gnutls-${GNUTLS_VERSION}/lib/.libs/libgnutls.a
GNUTLS_LIBS=-lgmp -lgnutls -lnettle
GNUTLS_LDFLAGS=-L../contrib/gnutls-${GNUTLS_VERSION}/lib/.libs/
else
GNUTLS_CFLAGS=
GNUTLS_LIBS=-lgnutls -lnettle -lgmp
GNUTLS_LDFLAGS=
#-lgnutls -lnettle -lgmp
endif
ifndef ARCH
ARCH = $(shell $(CC) -dumpmachine)
ARCH = $(shell uname -m)
endif
ifeq ($(CC),clang)
LDFLAGS += -g -L/usr/local/lib
CFLAGS += -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -fPIC -g -O0 -D_REENTRANT -I /usr/local/include -I../
LD = gcc
endif
ifeq ($(CC),gcc)
LDFLAGS += -g -L/usr/local/lib
CFLAGS += -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -fPIC -g -O0 -D_REENTRANT -I /usr/local/include -I../
LD = gcc
endif
ifeq ($(CC),tcc)
LDFLAGS += -g -L/usr/local/lib
CFLAGS += -Wall -Wunusupported -Wimplicit-function-declaration -I /usr/local/include -I../
LD = tcc
endif
CFLAGS += -DWITH_IPV6 -DWITH_RMAC_SUPPORT

View File

@ -1,30 +1,28 @@
include ../Config.mak
include ../ACConfig.mak
-include ../Config.local.mak
-include ../ACConfig.local.mak
include ../Macros.mak
ifndef CC
CC=gcc
endif
#SYSARCH := $(shell uname -m)
ifndef ARCH
ARCH = $(shell $(CC) -dumpmachine)
endif
LDFLAGS+=-g -D_REENTRANT -L/usr/local/lib -L../lib/$(ARCH)
CFLAGS += -Wall -g -O0 -D_REENTRANT -DIPV6 -I/usr/local/include -I../ -DSYS_ARCH=\"${ARCH}\"
LIBARCHDIR=../../lib/$(ARCH)
LDFLAGS+=-g -L/usr/local/lib -L$(LIBARCHDIR)
CFLAGS += -W -g -O0 -D_REENTRANT -DIPV6 -I/usr/local/include -I../ -DSYS_ARCH=\"${ARCH}\"
LIBS+=-lcapwap
LIBS+=-lcapwap80211
LIBS+=-lcipwap
LIBS+=-lcisco
LIBS+=-lfortinet
LIBS+=-lzyxel
#LIBS+=-lcapwap
#LIBS+=-lcapwap80211
#LIBS+=-lcipwap
#LIBS+=-lcisco
#LIBS+=-lfortinet
#LIBS+=-lzyxel
LIBS+=-lcw
LIBS+=-lrt
LIBS+=-lpthread
LIBS+=-lconfuse
LIBS+=-lsqlite3
LIBS+=-ldl
ifeq ($(SSL_LIBRARY),GNUTLS)
@ -51,7 +49,7 @@ CFLAGS += -DWITH_IPV6
RM = /bin/rm -f
AC_MODULES = mod_cipwap.o
#AC_MODULES = mod_cipwap.o
# list of generated object files for AC.
@ -77,12 +75,13 @@ AC_NAME = actube
all: $(AC_NAME)
%.o:%.c
@echo " CC "$<
@echo " $(CC) "$<
@$(CC) -c $(CFLAGS) $< -o $@
$(AC_NAME): $(AC_OBJS)
$(CC) $(AC_OBJS) ../mod/modload_ac.o -o $(AC_NAME) $(LDFLAGS) $(LIBS)
# $(CC) $(AC_OBJS) ../mod/modload_ac.o -o $(AC_NAME) $(LDFLAGS) $(LIBS)
$(LD) $(AC_OBJS) -o $(AC_NAME) $(LDFLAGS) $(LIBS)
clean:
@ -92,6 +91,6 @@ clean_deps:
$(AC_DEPS)
deps: $(AC_SRC)
$(CC) -MD -E $(AC_SRCS) $(CFLAGS) >/dev/null
$(LD) -MD -E $(AC_SRCS) $(CFLAGS) >/dev/null
-include $(AC_DEPS)

View File

@ -87,22 +87,17 @@ static int parse_args(int argc, char *argv[])
#include "cw/mod.h"
extern struct mod_ac * cw_get_mod_ac(const char *name);
extern struct cw_Mod * cw_get_mod_ac(const char *name);
#include "cw/mlist.h"
extern void test_sets();
#include "cw/file.h"
int main(int argc, char *argv[])
{
int rc = 0;
/* parse arguments */
@ -125,6 +120,14 @@ int main(int argc, char *argv[])
developers is turned on ;) */
DBGX("Attention! %s", "DBG X is ON!");
// cw_mod_set_mod_path("../../lib/actube");
// cw_mod_load("capwap");
//test_sets();
//exit(0);
/* Initialize the database */
if (!db_init())

View File

@ -38,7 +38,7 @@ uint8_t conf_macaddress_len = 0;
long conf_strict_capwap = 1;
long conf_strict_headers = 0;
char *conf_capwap_mode_str = NULL;
//char *conf_capwap_mode_str = NULL;
int conf_capwap_mode = CW_MODE_CAPWAP;
@ -539,8 +539,8 @@ static int conf_read_dbg_level(cfg_t * cfg)
struct mod_ac ** conf_mods; //[10];
struct cw_Mod ** conf_mods; //[10];
char *conf_mods_dir = NULL;
static int init_mods()
@ -570,21 +570,22 @@ static int conf_read_mods(cfg_t *cfg){
int n, i;
n = cfg_size(cfg,CFG_ENTRY_MODS);
conf_mods = malloc(sizeof(struct mod_ac *)*(n+1));
conf_mods = malloc(sizeof(struct cw_Mod *)*(n+1));
cw_dbg(DBG_INFO,"Mods directory: %s",conf_mods_dir);
cw_mod_set_mod_path(conf_mods_dir);
for (i=0; i < n; i++){
char *modname = cfg_getnstr(cfg, CFG_ENTRY_MODS, i);
conf_mods[i] = modload_ac(modname);
if (!conf_mods[i]){
cw_log(LOG_ERR,"Can't load mod: %s",modname);
struct cw_Mod * mod = cw_mod_load(modname);
if (!mod)
return 0;
}
cw_mod_add_to_list(mod);
}
conf_mods[i]=NULL;
return 1;
}
/*
void conf_init_capwap_mode()
{
if (conf_capwap_mode_str == NULL)
@ -600,7 +601,7 @@ void conf_init_capwap_mode()
}
*/
int conf_parse_listen_addr(const char *addrstr, char *saddr, char *port, int *proto)
@ -700,6 +701,8 @@ int read_config(const char *filename)
cfg_opt_t opts[] = {
CFG_STR_LIST("mods", "{}", CFGF_NONE),
CFG_SIMPLE_STR("mods_dir", &conf_mods_dir),
CFG_STR_LIST("dbg", "{}", CFGF_NONE),
CFG_STR_LIST("listen", "{}", CFGF_NONE),
CFG_STR_LIST("mcast_groups", "{}", CFGF_NONE),
@ -710,7 +713,7 @@ int read_config(const char *filename)
CFG_SIMPLE_BOOL("strict_capwap", &conf_strict_capwap),
CFG_SIMPLE_BOOL("strict_headers", &conf_strict_headers),
CFG_SIMPLE_BOOL("use_loopback", &conf_use_loopback),
CFG_SIMPLE_STR("capwap_mode", &conf_capwap_mode_str),
// CFG_SIMPLE_STR("capwap_mode", &conf_capwap_mode_str),
#ifdef WITH_LWAPP
@ -815,16 +818,18 @@ int read_config(const char *filename)
if (!conf_image_dir)
conf_image_dir = CONF_DEFAULT_IMAGE_DIR;
init_mods();
//printf("INIT MODS\n");
// init_mods();
//printf("done init mods");
conf_init_capwap_mode();
// conf_init_capwap_mode();
init_listen_addrs();
init_mcast_groups();
init_bcast_addrs();
//printf("Yea all mods inited\n");
return 1;
}

View File

@ -33,7 +33,7 @@
#include "cw/vendors.h"
extern struct mod_ac ** conf_mods;
extern struct cw_Mod ** conf_mods;
#ifndef CONF_DEFAULT_ACNAME
#define CONF_DEFAULT_ACNAME "AC"

View File

@ -305,10 +305,10 @@ errX:
}
// TODO XXXX
mavl_conststr_t db_get_update_tasks(struct conn * conn,const char * wtpid)
{
/*
sqlite3_reset(get_tasks_stmt);
sqlite3_clear_bindings(get_tasks_stmt);
@ -385,14 +385,14 @@ errX:
return NULL;
*/
}
mavl_conststr_t db_get_radio_tasks(struct conn * conn,const char * wtpid)
{
/*
//cw_dbg(DBG_X,"Get Radio Tasks for %s",wtpid);
sqlite3_reset(stmt_get_radio_tasks);
@ -479,7 +479,7 @@ errX:
return NULL;
*/
}

View File

@ -91,7 +91,7 @@ static void wtpman_run_discovery(void *arg)
extern cw_actionlist_in_t the_tree;
wtpman->conn->capwap_state = CAPWAP_STATE_DISCOVERY;
wtpman->conn->actions = &capwap_actions;
// wtpman->conn->actions = &capwap_actions;
wtpman->conn->outgoing = mbag_create();
wtpman->conn->incomming = mbag_create();
@ -276,8 +276,12 @@ static void wtpman_image_data(struct wtpman *wtpman)
}
// TODO XXXX
void props_to_sql(struct conn *conn, mbag_t mb, const char *mid)
{
/*
// XXX for the now we use just the IP adress as ID
char *wtp_id = sock_addr2str(&conn->addr);
@ -327,6 +331,7 @@ void props_to_sql(struct conn *conn, mbag_t mb, const char *mid)
}
}
*/
}
@ -334,6 +339,8 @@ void props_to_sql(struct conn *conn, mbag_t mb, const char *mid)
void config_to_sql(struct conn *conn)
{
/*
// XXX for the moment we use just the IP adress as ID
char *wtp_id = sock_addr2str(&conn->addr);
@ -370,10 +377,13 @@ void config_to_sql(struct conn *conn)
}
}
*/
}
void radio_to_sql(struct conn *conn, char *wtp_id, int rid, mbag_t radio)
{
/*
MAVLITER_DEFINE(it, radio);
mavliter_foreach(&it) {
mbag_item_t *i = mavliter_get(&it);
@ -408,7 +418,7 @@ void radio_to_sql(struct conn *conn, char *wtp_id, int rid, mbag_t radio)
// int rid = ((struct mbag_item*)mavliter_get(&it))->iid;
*/
}

View File

@ -1,207 +1,16 @@
include ../CapwapConfig.mak
include ../CWConfig.mak
-include ../Config.local.mak
include ../Macros.mak
ifndef CC
CC=gcc
endif
ifndef AR
AR = ar
endif
LIBDIR := ../../lib
LIBARCHDIR := $(LIBDIR)/$(ARCH)
OBJDIR := ../../obj/cw/$(ARCH)
#ifndef ARCH
# ARCH = $(shell $(CC) -dumpmachine)
#endif
SNAME := $(LIBARCHDIR)/libcw.a
DNAME := $(LIBARCHDIR)/libcw.so
#OPENSSLINC=$(OPENSSLINC)
#../contrib/openssl-1.0.1i/include
NAME=libcw.a
LIBDIR=../lib/$(ARCH)
SOCKOBJS=\
sock_create.o\
sock_copyaddr.o\
sock_strtoaddr.o\
sock_cmpaddr.o\
sock_addrlen.o \
sock_mwait.o\
sock_addrtostr.o \
sock_setport.o \
sock_getport.o \
sock_getifaddr.o \
sock_getifhwaddr.o \
sock_hwaddrtostr.o \
sock_set_recvtimeout.o \
sock_getbroadcastaddr.o \
sock_addrinit.o \
sock_set_dontfrag.o \
sock_get_primary_if.o \
sock_receive.o \
sock_getifinfo.o \
LOGOBJS=log.o \
log_syslog.o \
log_file.o \
dbg_strings.o\
dbg.o \
WTPINFOOBJS =\
#wtpinfo_print.o
#wtpinfo_set_location.o \
wtpinfo_lwreadelem_wtp_descriptor.o \
UTILOBJS= \
cw_setstr.o \
cw_is_printable.o \
cw_rand.o \
stravltree.o \
intavltree.o \
cw_util.o \
send.o \
cw_read_wtp_descriptor.o \
cw_read_wtp_descriptor_7.o \
cw_read_wtp_descriptor_versions.o \
cw_read_descriptor_subelems.o \
cw_out_80211_supported_rates.o
MAVLOBJS= \
mavl_del.o \
mavl_add.o \
mavl_create.o\
mavl_get.o\
mavl_del_all.o\
mavliter_seek.o \
mavliter_next.o \
mavl_get_node.o \
mavl_foreach.o \
mavl_foreach_lr.o \
mavl_merge.o \
mavl_create_conststr.o \
mlist.o \
cw_load_file.o \
cw_save_file.o \
message_set.o
FORMATOBJS = \
format_is_utf8.o \
format_dot11_fc.o \
# lw_readelem_vendor_specific.o \
# LWAPP objs
LWAPPOBJS = \
lw_checksum.o \
lw_put_ac_descriptor.o \
lw_put_cisco_path_mtu.o \
lw_elem_id_to_str.o \
lw_msg_id_to_str.o \
lw_cisco_id_to_str.o \
lw_put_sockaddr.o \
lw_put_image_data.o \
lw_in_vendor_specific.o
#lw_put_80211_wtp_wlan_radio_configuration.o \
# lw_readelem_wtp_name.o \
lw_readelem_wtp_board_data.o \
cw_log_debug.o \
lw_vendor_id_to_str.o \
# LWAPP cisco vendor specific objs
#//#LWAPPCISCOOBJS = \
# lw_addelem.o
# cw_tohex.o\
#capwap_parse_ctrlhdr.o \
# hdr_print.o \
CAPWAPOBJS= \
cw_iplist.o \
aciplist.o \
lwmsg_init.o \
cw_cisco_id_to_str.o\
cw_strlist_get_str.o \
cw_strlist_get_id.o \
capwap_strings_msg.o \
capwap_strings_elem80211.o\
acpriolist.o\
capwap_strings_state.o \
capwap_strings_vendor.o \
capwap_strings_elem.o \
cw_in_vendor_specific_payload.o \
cw_in_mtu_discovery_padding.o\
cw_in_wtp_board_data.o \
cw_in_check_disc_req.o \
cw_in_check_chng_state_evnt_req.o\
cw_in_check_disc_resp.o\
cw_in_check_cfg_update_req.o\
cw_in_check_join_req.o \
cw_in_check_cipwap_join_req.o \
cw_in_check_join_resp.o \
cw_in_check_img_data_req_ac.o \
cw_in_check_img_data_req_wtp.o \
cw_in_check_img_data_resp.o \
cw_in_check_generic_resp.o \
cw_in_check_generic_req.o \
cw_in_80211_mac_operation.o \
cw_read_80211_mac_operation.o \
cw_out_generic.o \
cw_out_wtp_descriptor.o \
cw_out_wtp_reboot_statistics.o \
cw_in_wtp_reboot_statistics.o\
cw_in_cisco_image_identifier.o\
cw_put_radio_operational_states.o \
cw_put_ac_status.o \
cw_in_ac_descriptor.o\
cw_read_ac_descriptor.o\
cw_out_capwap_local_ip_address.o\
cw_out_wtp_ip_address.o\
cw_out_capwap_control_ip_addr_list.o \
cw_in_capwap_control_ip_address.o\
cw_in_capwap_local_ipv4_address.o \
cw_in_capwap_local_ipv6_address.o \
cw_in_radio_administrative_state.o \
cw_in_radio_administrative_state_wtp.o \
cw_radio_set_admin_state.o \
cw_put_elem_radio_administrative_state.o\
cw_put_elem_radio_operational_state.o \
cw_out_radio_administrative_states.o\
strheap.o \
cw_check_missing_mand.o \
md5sum.o \
format.o \
# action_sources.o \
# cw_in_cisco_add_wlan.o
# cw_in_radio_operational_state.o\
DOT11OBJS = \
dot11.o \
dot11_beacon.o
# cw_out_ac_descriptor.o \
CAPWAP80211OBJS=\
capwap80211_items.o\
capwap80211_type_rateset.o \
# cw_out_radio_operational_states.o\
# cw_out_radio_operational_states_7.o\
#
# SSL objects
#
LIBS=
ifeq ($(WITH_OPENSSL),1)
CFLAGS+=$(OPENSSL_CFLAGS)
@ -211,6 +20,7 @@ DTLSOBJS += dtls_openssl.o \
dtls_openssl_connect.o \
dtls_openssl_get_cipher.o \
dtls_openssl_bio.o
LIBS+=-lssl
endif
ifeq ($(WITH_GNUTLS),1)
@ -222,145 +32,38 @@ DTLSOBJS+= dtls_gnutls.o \
dtls_gnutls_bio.o \
dtls_gnutls_get_cipher.o \
dtls_gnutls_get_peers_cert.o
LIBS+=-lgnutls
endif
DTLSOBJS+=dtls_bio.o
CONNOBJS= conn_create.o \
conn_process_packet.o \
conn_q_add_packet.o \
conn_q_get_packet.o \
conn_q_recv_packet.o \
conn_recv_packet.o \
conn_destroy.o \
connlist.o \
conn_create_noq.o \
conn_init.o \
conn_send_packet.o \
conn_send_data_packet.o \
netconn.o \
cw_init_data_keep_alive_msg.o \
conn_clear_upd.o
SRC=$(wildcard *.c)
OBJS=$(patsubst %.c,%.o,$(SRC))
OBJS:=$(patsubst %.o,$(OBJDIR)/%.o,$(OBJS))
# conn_send_msg.o
#conn_get_message.o \
# conn_send_response.o \
# cw_prepare_configuration_status_request.o \
# cw_prepare_change_state_event_request.o \
conn_prepare_configuration_update_request.o \
all: $(SNAME) $(DNAME)
#bstr_to_str.o \
BSTROBJS= bstr_create.o \
bstr_create_from_cfgstr.o \
bstr16_create_from_cfgstr.o \
bstr_replace.o \
bstr16cfgstr.o \
bstr16_create_from_str.o \
bstr_create_from_str.o \
bstrv_create_from_str.o
FRAGOBJS=fragman.o
CWACTION=action.o \
cw_in_generic.o \
cw_in_generic2.o \
cw_out_wtp_board_data.o \
cw_out_ac_name_with_priority.o \
cw_in_ac_name_with_priority.o \
cw_out_image_data.o \
cipwap_strings_elem.o \
capwap_strings_result.o\
capwap_strings_board.o \
cw_put_msg.o \
cw_put_mbag_item.o \
cw_put_local_ip_address.o \
capwap_action_helpers.o \
cw_put_image_data.o \
cisco.o \
radio.o \
cw_in_radio_generic.o\
cw_out_radio_generic.o \
cw_out_radio_info.o \
capwap_items.o \
item.o \
mod.o
# cw_process_msg.o \
# item_strings.o \
#
MBAGOBJS = \
mbag.o\
mbag_type_word.o\
mbag_type_byte.o\
mbag_type_vendorstr.o\
mbag_type_sockaddr.o\
mbag_type_dword.o\
mbag_type_bstr16.o\
mbag_type_mbag.o\
mbag_set_from_buf.o\
mbag_type_str.o \
mbag_type_ptr.o \
mbag_type_data.o \
mbag_get_upd.o
OBJS=$(CONNOBJS) $(FRAGOBJS) $(SOCKOBJS) $(CAPWAPOBJS) $(WTPINFOOBJS) \
$(LOGOBJS) $(UTILOBJS) $(DTLSOBJS) $(BSTROBJS) \
$(LWAPPOBJS) \
$(LWAPPCISCOOBJS) \
$(CWACTION) \
$(MAVLOBJS) \
$(FORMATOBJS) \
$(DOT11OBJS) \
$(MBAGOBJS) \
$(CAPWAP80211OBJS)
#include $(OBJS:.o=.d)
O:=$(OBJS);
OBJS:=$(patsubst %.o,$(ARCH)/%.o,$(OBJS))
CFLAGS = -Wall -g -O0 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I /usr/local/include -I../
#CFLAGS = -Wall -Os -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I/usr/local/include
CFLAGS += $(GNUTLS_CFLAGS) \
-DWITH_CW_LOG \
-DWITH_CW_LOG_DEBUG \
-DWITH_DTLS \
$(XINCLUDE)\
-I $(OPENSSLINC)\
-Werror
-DWITH_DTLS
#SRCS = $(OBJS:.o=.c)
#MODOBJS=$(wildcard ./mod/cipwap/$(ARCH)/*.o)
#MODOBJS+=$(wildcard ./mod/capwap/$(ARCH)/*.o)
$(ARCH)/%.o:%.c
@mkdir -p $(ARCH)
@echo " CC "$<
$(OBJDIR)/%.o:%.c
@mkdir -p $(OBJDIR)
@echo " $(CC) "$<
@$(CC) -c $(CFLAGS) $< -o $@
# @$(CC) -MM $(CFLAGS) $< > $*.d
$(LIBDIR)/$(NAME) : $(OBJS) $(MODOBJS)
@mkdir -p $(LIBDIR)
@echo " AR $(LIBDIR)/$(NAME)"
@$(AR) rcs $(LIBDIR)/$(NAME) $(OBJS) $(MODOBJS)
$(SNAME) : $(OBJS)
@mkdir -p $(LIBARCHDIR)
@echo " $(AR) $(SNAME)"
@$(AR) rcs $(SNAME) $(OBJS)
$(DNAME) : $(OBJS)
@mkdir -p $(LIBARCHDIR)
@echo " $(LD) $(DNAME)"
@$(LD) $(LDFLAGS) -shared -o $(DNAME) $(OBJS) $(LIBS)
SRCS = $(OBJS:.o=.c)
@ -370,19 +73,11 @@ DEPS := $(OBJS:.o=.d)
.PHONY: deps clean clean_libs libs
# top-level rule, to compile everything.
all: $(ARCH)/$(NAME)
clean:
$(RM) $(ARCH)/*
$(RM) $(LIBDIR)/$(NAME)
# $(RM) $(OBJS)
# $(RM) $(DEPS)
# $(RM) $(ARCH)/$(NAME)
$(RM) $(OBJDIR)/*
$(RM) $(DNAME)
$(RM) $(SNAME)
clean_deps:

View File

@ -1,78 +0,0 @@
/**
* @file
* @breif defines acinfo_print function
*/
#include <string.h>
#include <stdio.h>
#include "capwap.h"
#include "sock.h"
#include "acinfo.h"
#include "cw_util.h"
/**
* Formats an acinfo object.
*
*/
int acinfo_print(char *str,const struct ac_info *acinfo)
{
char *s = str;
s+=sprintf(s,"\tAC name: %s\n",acinfo->ac_name);
s+=sprintf(s,"\tHardware version: ");
s+=cw_format_version(s,acinfo->hardware_version,0,"-");
s+=sprintf(s,"\n");
s+=sprintf(s,"\tSoftware version: ");
s+=cw_format_version(s,acinfo->software_version,0,"-");
s+=sprintf(s,"\n");
s+=sprintf(s,"\tStations: %i\n",acinfo->stations);
s+=sprintf(s,"\tSation limit: %i\n",acinfo->limit);
s+=sprintf(s,"\tActive WTPs: %i\n",acinfo->active_wtps);
s+=sprintf(s,"\tMax WTPs: %i\n",acinfo->max_wtps);
char help[64];
sock_addrtostr((struct sockaddr*)&acinfo->local_ip,help,64);
s+=sprintf(s,"\tLocal IP: %s\n",help);
s+=sprintf(s,"\tECN support: %s\n",acinfo->ecn_support==0 ? "limited" : "full");
s+=sprintf(s,"\tRMAC support: %s\n",acinfo->rmac==1 ? "supported" : "not supported");
help[0]=0;
if (acinfo->security & AC_SECURITY_S)
strcpy(help,"psk");
if (acinfo->security & AC_SECURITY_X){
if (strlen(help))
strcat(help,"/");
strcat(help,"X.509");
}
if (!strlen(help))
strcpy(help,"None");
s+=sprintf(s,"\tSecurity: %s\n",help);
help[0]=0;
/* if (acinfo->dtls_policy & AC_DTLS_POLICY_D){
strcpy(help,"dtls");
}
if (acinfo->dtls_policy & AC_DTLS_POLICY_C){
if(strlen(help))
strcat(help,"/");
strcat(help,"clear");
}
*/ if (!strlen(help))
strcpy(help,"Not set");
s+=sprintf(s,"\tDTLS policy: %s\n",help);
return s-str;
}

View File

@ -1,69 +0,0 @@
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
/**
*@file
*@brief Implementation of avliter_next
*/
#include "avltree.h"
/**
* Get the next element within an AVL Tree.
* @param i pointer to AVL Iterator
* @return the element or NULL if there is no next elemeent.
*/
void * avliter_next(avliter_t *i)
{
while ( i->stack_ptr) {
i->stack_ptr--;
i->cur=i->stack[i->stack_ptr];
if (!i->cur)
continue;
if ((i->stack_ptr)&1) {
return i->cur->data;
}
break;
}
if (!i->cur){
return NULL;
}
while(i->cur->left) {
/* push right branch */
i->stack[i->stack_ptr++]=i->cur->right;
/* push node */
i->stack[i->stack_ptr++]=i->cur;
i->cur=i->cur->left;
}
i->stack[i->stack_ptr++]=i->cur->right;
return i->cur->data;
}

View File

@ -1,66 +0,0 @@
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
/**
*@file
*@brief Implementation of avliter_seek
*/
#include "avltree.h"
/**
* Set an AVL Iterator to a specific position.
* @param i AVL Iterator
* @param d element to search for
* @return element found or NULL if not found
*/
void * avliter_seek(avliter_t *i,void *d)
{
if (!i->root)
return NULL;
i->cur=i->root;
i->stack_ptr=0;
int rc;
while(i->cur) {
rc = i->cmp(d,i->cur->data);
if (rc==0){
i->stack[i->stack_ptr++]=i->cur->right;
i->stack[i->stack_ptr++]=i->cur;
return avliter_next(i);
}
if (rc<0) {
i->stack[i->stack_ptr++]=i->cur->right;
i->stack[i->stack_ptr++]=i->cur;
i->cur=i->cur->left;
}
if (rc>0) {
i->cur=i->cur->right;
}
}
return NULL;
}

View File

@ -1,39 +0,0 @@
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
#include "avltree.h"
int avltree_foreach_rl(struct avlnode *n, int (*callback)(void *,void *),void *cbpriv)
{
if (!n)
return 1;
if (!avltree_foreach_rl(n->right,callback,cbpriv))
return 0;
if (!callback(cbpriv,n->data))
return 0;
return avltree_foreach_rl(n->left,callback,cbpriv);
}
void avltree_foreach(struct avltree *t, int (*callback)(void *,void *),void * cbpriv,int dir)
{
if (dir)
avltree_foreach_lr(t->root,callback,cbpriv);
else
avltree_foreach_rl(t->root,callback,cbpriv);
}

View File

@ -1,31 +0,0 @@
#include "avltree.h"
// XXX Function is buggy
int avltree_foreach_from_lr(struct avltree *t, struct avlnode *n, void *data,int (*callback)(void *,void *),void *cbpriv)
{
if (!n)
return 1;
int rc=t->cmp(data,n->data);
if (rc<0){
if(!avltree_foreach_from_lr(t,n->left,data,callback,cbpriv))
return 0;
if (!callback(cbpriv,n->data))
return 0;
return avltree_foreach_lr(n->right,callback,cbpriv);
}
if (rc>0) {
avltree_foreach_from_lr(t,n->right,data,callback,cbpriv);
return 0;
}
if (!callback(cbpriv,n->data))
return 0;
return avltree_foreach_lr(n->right,callback,cbpriv);
}

View File

@ -1,17 +0,0 @@
#include "avltree.h"
int avltree_foreach_lr(struct avlnode *n, int (*callback)(void *,void *),void *cbpriv)
{
if (!n)
return 1;
if (!avltree_foreach_lr(n->left,callback,cbpriv))
return 0;
if (!callback(cbpriv,n->data))
return 0;
return avltree_foreach_lr(n->right,callback,cbpriv);
}

View File

@ -1,33 +0,0 @@
int avltree_foreach_lr_node(struct avltree *t, struct avlnode *n, void *data,int (*callback)(void *,void *),void *cbpriv)
{
if (!n)
return 1;
int rc=t->cmp(data,n->data);
if (rc<0){
avltree_foreach_lr_node(t,n->left,data,callback,cbpriv);
callback(cbpriv,n->data);
avltree_foreach_lr(n->right,
return 0;
}
if (rc>0) {
avltree_foreach_lr_node(t,n->right,data,callback,cbpriv);
return 0;
}
return callback(cbpriv,n->data);
}
int avltree_foreach_2(struct avltree *t,void *data,int (*callback)(void *,void *),void *cbpriv)
{
}

View File

@ -1,18 +0,0 @@
#include "avltree.h"
int avltree_foreach_rl(struct avlnode *n, int (*callback)(void *,void *),void *cbpriv)
{
if (!n)
return 1;
if (!avltree_foreach_rl(n->right,callback,cbpriv))
return 0;
if (!callback(cbpriv,n->data))
return 0;
return avltree_foreach_rl(n->left,callback,cbpriv);
}

View File

@ -1,47 +0,0 @@
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file
* @brief Implementation of avltree_get
*/
#include <stdio.h>
#include "avltree.h"
/**
* Get an AVL tree element.
* @param data Element to get
* @return pointer to element or NULL if not found.
*/
void * avltree_get(struct avltree *t ,void *data)
{
struct avlnode *n = t->root;
while(n){
int rc=t->cmp(data,n->data);
if (rc==0)
return n->data;
if (rc<0)
n=n->left;
else
n=n->right;
}
return NULL;
}

View File

@ -1,39 +0,0 @@
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include "avltree.h"
struct avlnode * avltree_get_node(struct avltree *t ,void *data)
{
struct avlnode *n = t->root;
while(n){
int rc=t->cmp(data,n->data);
if (rc==0)
return n;
if (rc<0)
n=n->left;
else
n=n->right;
}
return NULL;
}

View File

@ -130,16 +130,7 @@ static inline int bstr16_ncpy(uint8_t *dst,uint8_t*src,uint16_t len)
*/
static inline uint8_t * bstr16_create(const uint8_t *data, uint16_t len)
{
uint8_t * str = malloc(2+len*sizeof(uint8_t));
if (!str)
return 0;
*((uint16_t*)str)=len;
memcpy(str+2,data,len);
return str;
}
extern uint8_t * bstr16_create(const uint8_t *data, uint16_t len);
uint8_t * bstr16_create_from_str(const char *s);
extern uint8_t * bstr16_create_from_cfgstr(const char * s);
@ -182,25 +173,10 @@ typedef uint8_t * bstrv_t;
(1+6+(n)*sizeof(uint8_t))
static inline uint8_t * bstrv_create(uint32_t vendor_id, uint8_t *data, uint8_t len)
{
uint8_t * str = malloc(bstrv_size(len));
if (!str)
return 0;
bstrv_set_vendor_id(str,vendor_id);
bstrv_set_len(str,len);
memcpy(bstrv_data(str),data,len);
*(bstrv_data(str)+bstrv_len(str))=0;
return str;
}
uint8_t * bstrv_create_from_str(uint32_t vendor_id,const char *s);
uint8_t * bstrv_create(uint32_t vendor_id, uint8_t *data, uint8_t len);
//uint8_t * bstr16cfgstr(const char * s);
#endif

13
src/cw/bstr16_create.c Normal file
View File

@ -0,0 +1,13 @@
#include "bstr.h"
uint8_t * bstr16_create(const uint8_t *data, uint16_t len)
{
uint8_t * str = malloc(2+len*sizeof(uint8_t));
if (!str)
return 0;
*((uint16_t*)str)=len;
memcpy(str+2,data,len);
return str;
}

17
src/cw/bstrv_create.c Normal file
View File

@ -0,0 +1,17 @@
#include "bstr.h"
uint8_t * bstrv_create(uint32_t vendor_id, uint8_t *data, uint8_t len)
{
uint8_t * str = malloc(bstrv_size(len));
if (!str)
return 0;
bstrv_set_vendor_id(str,vendor_id);
bstrv_set_len(str,len);
memcpy(bstrv_data(str),data,len);
*(bstrv_data(str)+bstrv_len(str))=0;
return str;
}

View File

@ -499,7 +499,7 @@ enum cw_reboot_failure_types {
17 Image Data Error (Image Already Present)
*/
#define CW_RESULT_MSG_INVALID_IN_CURRENT_STATE 18
#define CAPWAP_RESULT_MSG_INVALID_IN_CURRENT_STATE 18
#define CW_RESULT_MSG_UNRECOGNIZED 19
#define CW_RESULT_MISSING_MAND_ELEM 20

View File

@ -1,13 +0,0 @@
#include "capwap80211.h"
#include "capwap_items.h"
#define CW_ACTION_IN_80211_WTP_RADIO_INFORMATION \
CW_ELEM80211_WTP_RADIO_INFORMATION, /* Element ID*/ \
cw_in_radio_generic, 0, /* start/end callback */ \
MBAG_DWORD, /* Type of element */ \
CW_ITEM_LOCATION_DATA, /* ID to use store */ \
5, 5 /* min/max length */

View File

@ -1,65 +0,0 @@
#include "action.h"
#include "capwap_80211_actions.h"
#include "capwap80211.h"
#include "capwap.h"
cw_action_in_t capwap_80211_actions_ac_in[] = {
/* --------------------------------------------------------
* Discovery Resquest
*/
{0, 0, CAPWAP_STATE_DISCOVERY, CAPWAP_MSG_DISCOVERY_REQUEST,
CW_ACTION_IN_80211_WTP_RADIO_INFORMATION, 1}
,
/* --------------------------------------------------------
* Discovery Resquest
*/
{0, 0, CW_STATE_JOIN, CAPWAP_MSG_JOIN_REQUEST,
CW_ACTION_IN_80211_WTP_RADIO_INFORMATION, 1}
,
{0, 0, 0}
};
cw_action_out_t capwap_80211_actions_ac_out[]={
/* Radio Infos */
{CAPWAP_MSG_DISCOVERY_RESPONSE, NULL /*CW_ELEM80211_WTP_RADIO_INFORMATION*/, 0,
CW_ELEM80211_WTP_RADIO_INFORMATION, NULL,cw_out_radio_infos, NULL,1}
,
/* Radio Infos */
{CAPWAP_MSG_JOIN_RESPONSE, NULL /*CW_ELEM80211_WTP_RADIO_INFORMATION*/, 0,
CW_ELEM80211_WTP_RADIO_INFORMATION, NULL,cw_out_radio_infos, NULL,1}
,
{0,0,0}
};
int cw_register_actions_capwap_80211_ac(struct cw_actiondef *def)
{
int rc;
rc=cw_actionlist_in_register_actions(def->in, capwap_80211_actions_ac_in);
rc+=cw_actionlist_out_register_actions(def->out, capwap_80211_actions_ac_out);
rc+= cw_strheap_register_strings(def->strelem, capwap_strings_elem80211);
/*rc += cw_strheap_register_strings(def->strelem, capwap_strings_elem);
*/
return rc;
}

View File

@ -1,64 +0,0 @@
#include "action.h"
#include "capwap_80211_actions.h"
#include "capwap80211.h"
#include "capwap.h"
cw_action_in_t capwap_80211_actions_wtp_in[] = {
/* Discovery Response */
{0, 0, CAPWAP_STATE_DISCOVERY, CAPWAP_MSG_DISCOVERY_RESPONSE,
CW_ACTION_IN_80211_WTP_RADIO_INFORMATION, 1}
,
/* Join Response */
{0, 0, CW_STATE_JOIN, CAPWAP_MSG_JOIN_RESPONSE,
CW_ACTION_IN_80211_WTP_RADIO_INFORMATION, 1}
,
{0, 0, 0}
};
cw_action_out_t capwap_80211_actions_wtp_out[]={
/* --------------------------------------------------------
* Discovery Resquest
*/
/* 802.11 Radio Information */
{CAPWAP_MSG_DISCOVERY_REQUEST, CW_ITEM_RADIO_INFOS /*CW_ELEM80211_WTP_RADIO_INFORMATION*/, 0,
CW_ELEM80211_WTP_RADIO_INFORMATION, NULL,cw_out_radio_infos, NULL,1}
,
/* --------------------------------------------------------
* Join Resquest
*/
/* 802.11 Radio Information */
{CAPWAP_MSG_JOIN_REQUEST, CW_ITEM_RADIO_INFOS, 0,
CW_ELEM80211_WTP_RADIO_INFORMATION, NULL,cw_out_radio_infos, NULL,1},
{0,0,0}
};
int cw_register_actions_capwap_80211_wtp(struct cw_actiondef *def)
{
int rc;
rc=cw_actionlist_in_register_actions(def->in, capwap_80211_actions_wtp_in);
rc+=cw_actionlist_out_register_actions(def->out, capwap_80211_actions_wtp_out);
rc+=cw_strheap_register_strings(def->strelem, capwap_strings_elem80211);
return rc;
}

View File

@ -1,9 +0,0 @@
struct cw_str capwap_strings_item[] = {
{CW_ITEM_AC_DESCRIPTOR, "AC Descriptor"},
{CW_ITEM_AC_IPV4_LIST, "AC IPv4 List"},
{CW_ITEM_WTP_DESCRIPTOR,"WTP Descriptor"},
{CW_STR_STOP,"Unknown"}
}

View File

@ -9,7 +9,7 @@ struct cw_strlist_elem capwap_strings_result[] = {
{CW_RESULT_RESET_UNABLE_TO_RESET,"Reset Failure - Unable to Reset"}, /* 10 */
{CW_RESULT_IMAGE_DATA_INVALID_CHECKSUM,"Image Data Error (Invalid Checksum)"}, /* 14 */
{CW_RESULT_IMAGE_DATA_ERROR,"Image Data Error (Unspecified)"}, /* 16 */
{CW_RESULT_MSG_INVALID_IN_CURRENT_STATE,"Message unexpected (Invalid in current state)"}, /* 18 */
{CAPWAP_RESULT_MSG_INVALID_IN_CURRENT_STATE,"Message unexpected (Invalid in current state)"}, /* 18 */
{CW_RESULT_MISSING_MAND_ELEM,"Missing Mandatory Message Element"}, /* 20 */
{CW_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT,"Unrecognized Message Element"}, /* 21 */
{CW_STR_STOP,"Unknown Result Code"}

View File

@ -96,7 +96,9 @@ struct conn {
/** Actionsdefs - this defines the possible actions for
this conn object, so in the end this is the specification
of the protocoll */
struct cw_actiondef *actions;
// struct cw_actiondef *actions;
struct cw_MsgSet * msgset;
/** Current CAPWAP state */

View File

@ -1,35 +0,0 @@
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
#include "capwap.h"
#include "wtpinfo.h"
#include "conn.h"
#include "log.h"
#include "sock.h"
void conn_detect_capwap(struct conn * conn, struct wtpinfo * wtpinfo)
{
if (wtpinfo->software_vendor_id == CW_VENDOR_ID_CISCO){
cw_dbg(DBG_CW_INFO,"Setting capwap mode *Cisco* on connection %s",sock_addr2str(&conn->addr));
conn->capwap_mode = CWMODE_CISCO;
return;
}
conn->capwap_mode = CWMODE_STD;
}

View File

@ -1,78 +0,0 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "conn.h"
#include "cwrmsg.h"
#include "cw_log.h"
#include "capwap.h"
#include "sock.h"
#include "cw_util.h"
struct args {
struct conn *conn;
struct cwrmsg *cwrmsg;
};
static int message_cb(void *p, uint8_t *rawmsg, int len)
{
struct args *args = (struct args *) p;
struct conn *conn = args->conn;
memcpy(conn->cwrmsg_buffer, rawmsg, len);
/*
memcpy(&conn->cwrmsg, cwrmsg, sizeof(struct cwrmsg));
conn->cwrmsg.msgelems = conn->cwrmsg_buffer;
*/
args->cwrmsg = &conn->cwrmsg;
return 0;
}
int conn_msg_processor(struct conn *conn)
{
uint8_t buf[2024];
int len = 2024;
int n = conn->read(conn, buf, len);
if (n<0 )
return n;
if (n > 0)
conn_process_packet(conn, buf, n, cw_process_msg, conn);
}
uint8_t *conn_get_message(struct conn *conn)
{
struct args args;
args.cwrmsg = 0;
args.conn = conn;
uint8_t buf[2024];
int len = 2024;
int n = conn->read(conn, buf, len);
if (n > 0)
conn_process_packet(conn, buf, n, message_cb, &args);
if (args.cwrmsg) {
cw_dbg(DBG_MSG,"Message recieved from %s",sock_addr2str(&conn->addr));
/*
cw_dbg(DBG_MSG,
"Received message from %s, type=%d - %s, seq=%d",
sock_addr2str(&conn->addr), args.cwrmsg->type,
cw_msgtostr(args.cwrmsg->type),
args.cwrmsg->seqnum);
*/
}
return conn->cwrmsg_buffer;
}

View File

@ -1,44 +0,0 @@
#include "capwap.h"
#include "cw_log.h"
#include "sock.h"
#include "cw_util.h"
struct cwrmsg * conn_get_response(struct conn * conn)
{
struct cwmsg * cwmsg = &conn->req_msg;
int type = cwmsg->type+1;
struct cwrmsg * cwrmsg;
int i;
for (i=0; i<conn->max_retransmit; i++) {
time_t r_timer = cw_timer_start(conn->retransmit_interval);
while(!cw_timer_timeout(r_timer)){
cwrmsg = conn_get_message(conn);
if (cwrmsg){
cw_dbg(DBG_MSG,"Received message from %s, type=%d - %s"
,sock_addr2str(&conn->addr),cwrmsg->type,cw_msgtostr(cwrmsg->type));
if (cwrmsg->type == type){
return cwrmsg;
}
}
if (conn->dtls_error)
return 0;
}
cw_dbg(DBG_MSG_ERR,"Retransmitting message, type=%d,seq=%d",cwmsg->type,cwmsg->seqnum);
conn_send_cwmsg(conn,&conn->req_msg);
}
cw_dbg(DBG_MSG_ERR,"Max retransmit's reached, message type=%d,seq=%d",cwmsg->type,cwmsg->seqnum);
return 0;
}

View File

@ -1,12 +0,0 @@
#include "conn.h"
#include "capwap.h"
void conn_prepare_configuration_update_request(struct conn * conn)
{
struct cwmsg * cwmsg = &conn->req_msg;
uint8_t * buffer = conn->req_buffer;
cwmsg_init(cwmsg,buffer,CW_MSG_CONFIGURATION_UPDATE_REQUEST,conn_get_next_seqnum(conn),0);
}

View File

@ -19,7 +19,7 @@
#include "capwap.h"
#include "lwapp.h"
/*
int conn_prepare_image_data_request(struct conn *conn, struct cwimage_data *data,
struct image_identifier *id)
@ -33,7 +33,7 @@ int conn_prepare_image_data_request(struct conn *conn, struct cwimage_data *data
/* for Cisco APs send image data in "LWAPP format" */
// for Cisco APs send image data in "LWAPP format"
if (conn->capwap_mode == CWMODE_CISCO) {
uint8_t type = 3;
uint16_t checksum = htons(lw_checksum(data->data, data->len));
@ -46,7 +46,7 @@ int conn_prepare_image_data_request(struct conn *conn, struct cwimage_data *data
}
/* standard capwap operation */
// standard capwap operation
cwmsg_vaddelem(cwmsg,CW_ELEM_IMAGE_DATA,
&data->type, sizeof(data->type),
@ -57,3 +57,5 @@ int conn_prepare_image_data_request(struct conn *conn, struct cwimage_data *data
return 0;
}
*/

View File

@ -1,10 +0,0 @@
#include "conn.h"
#include "capwap.h"
void conn_prepare_request(struct conn * conn, int type)
{
struct cwmsg * cwmsg = &conn->req_msg;
uint8_t * buffer = conn->req_buffer;
cwmsg_init(cwmsg,buffer,type,conn_get_next_seqnum(conn),0);
cwmsg->capwap_mode=conn->capwap_mode;
}

View File

@ -32,7 +32,7 @@
#include "stravltree.h"
#include "mod.h"
#include "message_set.h"
int conn_send_msg(struct conn *conn, uint8_t * rawmsg);
@ -151,7 +151,7 @@ static int check_len(struct conn *conn, struct cw_action_in *a, uint8_t * data,
if (!a->max_len)
return 1;
if (len < a->min_len) {
/* if (len < a->min_len) {
cw_dbg(DBG_ELEM_ERR,
"%d (%s) message element too short, len=%d, min len=%d",
a->elem_id, cw_strelemp(conn->actions, a->elem_id), len,
@ -164,81 +164,35 @@ static int check_len(struct conn *conn, struct cw_action_in *a, uint8_t * data,
cw_strelemp(conn->actions, a->elem_id), len, a->max_len);
return 0;
}
*/
return 1;
}
static struct mod_ac *detect_mod(struct conn *conn, uint8_t * rawmsg, int len,
int elems_len, struct sockaddr *from, int mode)
{
if (conn->mods) {
struct mod_ac **mods = (struct mod_ac **) conn->mods;
int i;
for (i = 0; mods[i]; i++) {
if (mods[i]->detect) {
if (mods[i]->detect
(conn, rawmsg, len, elems_len, from, mode)) {
return mods[i];
}
}
}
}
return MOD_NULL;
}
static struct cw_actiondef *load_mods(struct conn *conn, uint8_t * rawmsg, int len,
static struct cw_MsgSet *load_msg_set(struct conn *conn, uint8_t * rawmsg, int len,
int elems_len, struct sockaddr *from)
{
struct mod_ac *cmod =
detect_mod(conn, rawmsg, len, elems_len, from, MOD_MODE_CAPWAP);
struct cw_Mod *cmod =
cw_mod_detect(conn, rawmsg, len, elems_len, from, CW_MOD_MODE_CAPWAP);
if (cmod == MOD_NULL) {
cw_dbg(DBG_MSG_ERR,
"Can't find mod to handle connection from %s , discarding message",
"Can't find mod to handle connection from %s, discarding message",
sock_addr2str_p(from));
return NULL;
}
struct mod_ac *bmod =
detect_mod(conn, rawmsg, len, elems_len, from, MOD_MODE_BINDINGS);
struct cw_Mod *bmod =
cw_mod_detect(conn, rawmsg, len, elems_len, from, MOD_MODE_BINDINGS);
cw_dbg(DBG_INFO, "Mods deteced: %s,%s", cmod->name, bmod->name);
struct cw_actiondef *ad = mod_cache_add(conn,cmod, bmod);
return ad;
// struct cw_actiondef *ad = mod_cache_add(conn,cmod, bmod);
struct cw_MsgSet * set = cw_mod_get_msg_set(conn,cmod,bmod);
/*
if (bindins_mod) {
cw_dbg(DBG_INFO, "Using mod '%s' to handle CAWPAP for %s", mod->name,
sock_addr2str_p(from));
conn->detected=1;
}
else{
// errno = EAGAIN;
// return -1;
}
mod = detect_mod(conn, rawmsg, len, elems_len, from, MOD_DETECT_BINDINGS);
if (mod) {
cw_dbg(DBG_INFO, "Using bindings '%s' to handle %s", mod->name,
sock_addr2str_p(from));
conn->detected=1;
}
else{
cw_dbg(DBG_MSG_ERR, "Can't detect bindings ... for %s",
sock_addr2str_p(from));
}
return 0;
*/
return set;
}
int cw_in_check_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data,
@ -295,33 +249,47 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
}
}
if (!conn->detected) {
//struct mod_ac *mod;
struct cw_actiondef *ad = load_mods(conn, rawmsg, len, elems_len, from);
if (!ad) {
cw_log(LOG_ERR, "Error");
struct cw_MsgSet *set = load_msg_set(conn, rawmsg, len, elems_len, from);
if (!set) {
//cw_log(LOG_ERR, "Error");
errno = EAGAIN;
return -1;
}
conn->actions = ad;
conn->msgset= set;
// conn->actions = ad;
conn->detected = 1;
}
cw_dbg_msg(DBG_MSG_IN, conn, rawmsg, len, from);
/* prepare struct for search operation */
struct cw_MsgData search;
search.type = cw_get_msg_id(msg_ptr);
struct cw_MsgData * message;
/* Search for message combination */
message = mavl_get(conn->msgset->messages,&search);
int result_code = 0;
if (!message){
/* Message is unknown */
cw_dbg(DBG_MSG_ERR, "Message type %d (%s) unknown.",
search.type, cw_strmsg(search.type),
cw_strstate(conn->capwap_state));
result_code = CW_RESULT_MSG_UNRECOGNIZED;
cw_send_error_response(conn, rawmsg, result_code);
errno = EAGAIN;
return -1;
}
/* prepare struct for search operation */
as.capwap_state = conn->capwap_state;
as.msg_id = cw_get_msg_id(msg_ptr);
as.vendor_id = 0;
as.elem_id = 0;
as.proto = 0;
/* Search for state/message combination */
afm = cw_actionlist_in_get(conn->actions->in, &as);
// afm = cw_actionlist_in_get(conn->actions->in, &as);
if (!afm) {
/* Throw away unexpected response messages */
@ -336,14 +304,16 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
/* Request message not found in current state, check if we know
anything else about this message type */
const char *str = cw_strheap_get(conn->actions->strmsg, as.msg_id);
// TODO XXXX
//const char *str = cw_strheap_get(conn->actions->strmsg, as.msg_id);
const char *str = 0;
int result_code = 0;
if (str) {
/* Message found, but it was in wrong state */
cw_dbg(DBG_MSG_ERR,
"Message type %d (%s) not allowed in %s State.", as.msg_id,
cw_strmsg(as.msg_id), cw_strstate(as.capwap_state));
result_code = CW_RESULT_MSG_INVALID_IN_CURRENT_STATE;
result_code = CAPWAP_RESULT_MSG_INVALID_IN_CURRENT_STATE;
} else {
/* Message is unknown */
cw_dbg(DBG_MSG_ERR, "Message type %d (%s) unknown.",
@ -381,15 +351,18 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
as.elem_id = cw_get_elem_id(elem);
int elem_len = cw_get_elem_len(elem);
af = cw_actionlist_in_get(conn->actions->in, &as);
// TODO XXX
// af = cw_actionlist_in_get(conn->actions->in, &as);
af = 0;
if (!af) {
unrecognized++;
cw_dbg(DBG_ELEM_ERR,
// TOOO XXXX
/* cw_dbg(DBG_ELEM_ERR,
"Element %d (%s) not allowed in msg of type %d (%s), ignoring.",
as.elem_id, cw_strelemp(conn->actions, as.elem_id),
as.msg_id, cw_strmsg(as.msg_id));
*/
continue;
}
@ -415,7 +388,8 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
}
if(conn->elem_end){
afrc = conn->elem_end(conn,af,afrc,cw_get_elem_data(elem), elem_len,from);
// TODO XXXX
// afrc = conn->elem_end(conn,af,afrc,cw_get_elem_data(elem), elem_len,from);
}
}
@ -423,7 +397,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
/* all message elements are processed, do now after processing
by calling the "end" function for the message */
int result_code = 0;
//int result_code = 0;
@ -496,7 +470,6 @@ int process_message(struct conn *conn, uint8_t * rawmsg, int rawlen,
{
uint8_t *msgptr = rawmsg + cw_get_hdr_msg_offset(rawmsg);
@ -638,7 +611,7 @@ int conn_process_packet2(struct conn *conn, uint8_t * packet, int len,
cw_dbg_pkt(DBG_PKT_IN, conn, f + 4, *(uint32_t *) f, from);
cw_dbg_msg(DBG_MSG_IN, conn, f + 4, *(uint32_t *) f, from);
// cw_dbg_msg(DBG_MSG_IN, conn, f + 4, *(uint32_t *) f, from);
// XXX: Modify fragman to not throw away CAPWAP headers
@ -649,7 +622,7 @@ int conn_process_packet2(struct conn *conn, uint8_t * packet, int len,
}
/* not fragmented, we have a complete message */
cw_dbg_msg(DBG_MSG_IN, conn, packet, len, from);
// cw_dbg_msg(DBG_MSG_IN, conn, packet, len, from);
return conn->process_message(conn, packet, len, from);
}

View File

@ -23,7 +23,7 @@
#include "capwap.h"
#include "cw_util.h"
#include "cw_log.h"
#include "log.h"
/**
* Send a request message and wait for its response
@ -32,6 +32,9 @@
* The message has to be prepared and put to conn->req_msg
*
*/
/*
struct cwrmsg * conn_send_request(struct conn * conn)
{
int i;
@ -58,4 +61,4 @@ struct cwrmsg * conn_send_request(struct conn * conn)
cw_dbg(DBG_MSG_ERR,"Max retransmit's reached, message type=%d,seq=%d",cwmsg->type,cwmsg->seqnum);
return 0;
}
*/

View File

@ -1,37 +0,0 @@
#include "conn.h"
#include "cw_util.h"
struct cwrmsg * conn_wait_for_message(struct conn * conn, time_t timer)
{
struct cwrmsg * cwrmsg;
while (!cw_timer_timeout(timer)){
cwrmsg = conn_get_message(conn);
if (!cwrmsg){
if (!conn_is_error(conn))
continue;
return 0;
}
if (cwrmsg->type & 1){
if (conn->request_handler){
if (conn->request_handler(conn->request_handler_param))
continue;
}
}
return cwrmsg;
}
return 0;
}

View File

@ -1,78 +0,0 @@
#include "conn.h"
#include "cw_log.h"
#include "sock.h"
#include "cw_util.h"
struct rh_param{
struct conn * conn;
int *msglist;
};
static int conn_rh(void *param)
{
struct rh_param * p = (struct rh_param*)param;
int i;
int *msglist=p->msglist;
printf("Param %p\n",param);
for (i=0; msglist[i]!=-1; i++){
if (msglist[i] == p->conn->cwrmsg.type )
return 0;
}
/* unexpected response here */
cw_log(LOG_ERR,"Unexpected message from %s",sock_addr2str(&p->conn->addr));
cwsend_unknown_response(p->conn,p->conn->cwrmsg.seqnum,p->conn->cwrmsg.type);
return 1;
}
struct cwrmsg * conn_wait_for_request(struct conn * conn, int *msglist, time_t timer)
{
int (*request_handler_save) (void*);
void * request_handler_param_save;
struct rh_param rh_param;
if (msglist){
request_handler_save=conn->request_handler;
request_handler_param_save=conn->request_handler_param;
rh_param.conn=conn;
rh_param.msglist=msglist;
conn->request_handler=conn_rh;
conn->request_handler_param=&rh_param;
}
struct cwrmsg * cwrmsg;
while (!cw_timer_timeout(timer)){
cwrmsg = conn_wait_for_message(conn,timer);
if (!cwrmsg){
if (!conn_is_error(conn))
continue;
break;
}
/* response message? no action*/
if (! (cwrmsg->type & 1) )
continue;
/* it's a request message */
break;
}
if (msglist){
conn->request_handler=request_handler_save;
conn->request_handler_param=request_handler_param_save;
}
return cwrmsg;
}

View File

@ -4,6 +4,7 @@
#include "conn.h"
#include "mavl.h"
#include "pthread.h"
struct connlist {
/* struct conn ** connlist; */

View File

@ -120,10 +120,12 @@ typedef struct {
}cw_elem_handler_t;
typedef struct {
struct cw_MsgSet {
mavl_t messages;
mavl_t all_elems;
}cw_message_set_t;
};
typedef struct cw_MsgSet cw_MsgSet_t;
typedef struct{
cw_elem_handler_t * elem;
@ -131,12 +133,13 @@ typedef struct{
int op;
}cw_msgelemprops_t;
typedef struct {
struct cw_MsgDef{
int type;
int * states;
cw_msgelemprops_t * elements;
const char * name;
}cw_msgdef_t;
};
typedef struct cw_MsgDef cw_msgdef_t;
/**
* Get length wireless specific data

View File

@ -27,6 +27,7 @@
#include "cwmsg.h"
#include "conn.h"
/*
uint8_t * cw_addelem(uint8_t * buf,int type, uint8_t *elem, int len)
{
@ -76,4 +77,4 @@ void cw_addelem_capwap_local_ip_addr(struct cwmsg *msg, int sock, int cw_mode)
}
*/

View File

@ -1,48 +0,0 @@
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
/**
*@file
*@brief cw_addelem_vendor_specific_payload
*/
#include "capwap.h"
/**
* Add a Vendor Specific Payload message element to a buffer
* @param dst destination buffer
* @param vendor_id the vendor id
* @param type vendor specific message type
* @data pointer to data the will be put
* @len length of data
*/
int cw_addelem_vendor_specific_payload(uint8_t * dst, uint32_t vendor_id,
uint16_t type, uint8_t * data, uint16_t len)
{
uint8_t *d = dst + 4;
d += cw_put_dword(d, vendor_id);
d += cw_put_word(d, type);
d += cw_put_data(d, data, len);
int l = d - dst;
cw_put_elem_hdr(dst, CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, l - 4);
return l;
}

View File

@ -13,7 +13,8 @@ int cw_check_missing_mand(cw_action_in_t ** out, struct conn * conn, cw_action_i
as.vendor_id = 0;
as.elem_id = 0;
as.proto=0;
/// TODO XXXX
/*
DEFINE_AVLITER(it,conn->actions->in);
int n=0;
avliter_foreach_from(&it,&as) {
@ -30,7 +31,8 @@ int cw_check_missing_mand(cw_action_in_t ** out, struct conn * conn, cw_action_i
}
}
return n;
return n;
*/
}

81
src/cw/cw_filename.c Normal file
View File

@ -0,0 +1,81 @@
/*
This file is part of actube.
actube is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
actube is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with actube. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file
* @brief implents cw_filename
**/
#include <string.h>
#include <stdio.h>
#include "file.h"
/**
* @brief Build full pathname from path, filename and extension
* @param path Path
* @param name Filename
* @param ext Extension
* @return a pointer to the create filename which has to be
* released using free.
*/
char * cw_filename(const char * path, const char * name, const char * ext){
int size=0;
int path_len;
char c;
char * slash="";
path_len = strlen(path);
if (path_len>0){
c = path[path_len-1];
if (!strchr(CW_FILE_PATH_DELIMITERS,c)){
path_len++;
slash = "/";
}
}
int name_len = strlen (name);
int ext_len;
if (ext != NULL){
if (ext[0]=='.'){
ext++;
}
ext_len = strlen(ext);
}
else
ext_len=-1;
size = (path_len) + name_len + (ext_len+1) + 1;
char * result = malloc(size);
if (!result)
return NULL;
strncpy(result,path,path_len);
result[path_len]=0;
strcat(result,slash);
strcat(result,name);
if (ext){
strcat(result,".");
strcat(result,ext);
}
return result;
}

View File

@ -1,23 +0,0 @@
#include <string.h>
#include "mod.h"
#include <stdio.h>
struct mod_ac *(*mods_ac[])() = MODS_AC;
struct mod_ac * cw_get_mod_ac(const char *name)
{
int i;
for (i=0; mods_ac[i];i++){
struct mod_ac * m = mods_ac[i]();
if (strcmp(m->name,name)==0)
return m;
}
return NULL;
}

View File

@ -5,10 +5,11 @@
#include "mbag.h"
#include "cw.h"
/// TODO XXXX
int static check_len(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
struct sockaddr *from)
{
/*
if (len < a->min_len) {
cw_dbg(DBG_ELEM_ERR,
"%d (%s) message element too short, len=%d, min len=%d",
@ -22,7 +23,7 @@ int static check_len(struct conn *conn, struct cw_action_in *a, uint8_t * data,
cw_strelemp(conn->actions, a->elem_id), len, a->max_len);
return 0;
}
*/
return 1;
}

View File

@ -98,7 +98,10 @@ int static do_save(mbag_t itemstore, struct conn *conn, struct cw_action_in *a,
int cw_in_generic2(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
struct sockaddr *from)
{
const cw_itemdef_t * idef = cw_itemdef_get(conn->actions->items,a->item_id,CW_ITEM_NONE);
/// TODO XXXX
// const cw_itemdef_t * idef = cw_itemdef_get(conn->actions->items,a->item_id,CW_ITEM_NONE);
const cw_itemdef_t * idef=0;
if (!idef) {
cw_log(LOG_ERR,"No itemdef found for %s",a->item_id);

View File

@ -14,8 +14,10 @@
int cw_in_radio_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len, struct sockaddr *from)
{
const cw_itemdef_t * idef = cw_itemdef_get(conn->actions->radioitems,a->item_id,CW_ITEM_NONE);
// TODO XXXX
// const cw_itemdef_t * idef = cw_itemdef_get(conn->actions->radioitems,a->item_id,CW_ITEM_NONE);
const cw_itemdef_t * idef = 0;
if (!idef){
cw_log(LOG_ERR,"No definition found for %s",a->item_id);
return 0;

View File

@ -22,9 +22,10 @@ int cw_in_vendor_specific_payload(struct conn *conn, struct cw_action_in *a,
as.vendor_id = cw_get_dword(data);
as.elem_id = cw_get_word(data + 4);
af = cw_actionlist_in_get(conn->actions->in, &as);
// TODO XXXX
// af = cw_actionlist_in_get(conn->actions->in, &as);
af = 0;
if (!af) {
cw_dbg(DBG_WARN,
"Can't handle Vendor Specific Payload %s/%d, in msg %d (%s) in %s state.",
@ -44,4 +45,5 @@ int cw_in_vendor_specific_payload(struct conn *conn, struct cw_action_in *a,
}
return 1;
}

View File

@ -1,254 +0,0 @@
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
#include "capwap.h"
#include "capwap_items.h"
#include "cw_util.h"
#include "dbg.h"
#include "sock.h"
static int _cw_read_wtp_descriptor_versions(mbag_t mbag, uint8_t * data,
int len, int silent)
{
int i = 0;
while (i<len) {
if (i + 8 > len) {
if (!silent)
cw_dbg(DBG_ELEM_ERR,
"WTP descriptor subelement to long, length=%d>%d",
i + 8, len);
return 0;
}
uint32_t vendor_id = cw_get_dword(data + i);
uint32_t val = cw_get_dword(data + i + 4);
int subtype = (val >> 16) & 0xffff;
int sublen = val & 0xffff;
i += 8;
if (sublen + i > len) {
if (!silent)
cw_dbg(DBG_ELEM_ERR,
"WTP Descriptor sub-element too long, length = %d",
sublen);
return 0;
}
if (!silent) {
char *dmp;
char *dmpmem = NULL;
if (cw_dbg_is_level(DBG_SUBELEM_DMP)) {
dmpmem = cw_dbg_mkdmp(data + i, sublen);
dmp = dmpmem;
} else
dmp = "";
cw_dbg(DBG_SUBELEM, "WTP Descriptor subtype=%d,len=%d%s", subtype,
sublen, dmp);
if (dmpmem)
free(dmpmem);
}
switch (subtype) {
case CW_SUBELEM_WTP_HARDWARE_VERSION:
/*
mbag_set_dword(mbag,
CW_ITEM_WTP_HARDWARE_VENDOR,
vendor_id);
mbag_set_bstrn(mbag,
CW_ITEM_WTP_HARDWARE_VERSION,
data + i, sublen);
*/
mbag_set_bstrv(mbag,
CW_ITEM_WTP_HARDWARE_VERSION,
vendor_id, data + i, sublen);
break;
case CW_SUBELEM_WTP_SOFTWARE_VERSION:
mbag_set_bstrv(mbag,
CW_ITEM_WTP_SOFTWARE_VERSION,
vendor_id, data + i, sublen);
/*
mbag_set_dword(mbag,
CW_ITEM_WTP_SOFTWARE_VENDOR,
vendor_id);
mbag_set_bstrn(mbag,
CW_ITEM_WTP_SOFTWARE_VERSION,
data + i, sublen);
*/
break;
case CW_SUBELEM_WTP_BOOTLOADER_VERSION:
mbag_set_bstrv(mbag,
CW_ITEM_WTP_BOOTLOADER_VERSION,
vendor_id, data + i, sublen);
/*
mbag_set_dword(mbag,
CW_ITEM_WTP_BOOTLOADER_VENDOR,
vendor_id);
mbag_set_bstrn(mbag,
CW_ITEM_WTP_BOOTLOADER_VERSION,
data + i, sublen);
*/
break;
default:
if (!silent)
cw_dbg(DBG_ELEM_ERR,
"Unknown WTP descriptor subelement, type = %d",
subtype);
break;
}
i += sublen;
} //while (i < len);
return 1;
}
static int cw_read_wtp_descriptor(mbag_t mbag, struct conn *conn,
struct cw_action_in *a, uint8_t * data, int len,
int silent)
{
mbag_set_byte(mbag, CW_ITEM_WTP_MAX_RADIOS, cw_get_byte(data));
mbag_set_byte(mbag, CW_ITEM_WTP_RADIOS_IN_USE,
cw_get_byte(data + 1));
/* Get number of encryption elements */
int ncrypt = cw_get_byte(data + 2);
if (ncrypt == 0) {
if (conn->strict_capwap) {
if (!silent)
cw_dbg(DBG_ELEM_ERR,
"Bad WTP Descriptor, number of encryption elements is 0.");
return 0;
}
if (!silent)
cw_dbg(DBG_RFC,
"Non standard conform WTP Descriptor, number of encryptoin elements is 0.");
}
int pos = 3;
int i;
for (i = 0; i < ncrypt; i++) {
// It's a dummy for now
pos += 3;
}
return _cw_read_wtp_descriptor_versions(mbag, data + pos, len - pos, silent);
}
/**
* Read WTP Descriptor in Cisco-Style (Draft 7)
*/
static int cw_read_cisco_wtp_descriptor(mbag_t mbag, struct conn *conn,
struct cw_action_in *a, uint8_t * data, int len,
int silent)
{
mbag_set_byte(mbag, CW_ITEM_WTP_MAX_RADIOS, cw_get_byte(data));
mbag_set_byte(mbag, CW_ITEM_WTP_RADIOS_IN_USE,
cw_get_byte(data + 1));
int pos = 2;
/* Encryption element, for now dumy XXX */
cw_get_word(data + pos + 2);
pos += 2;
return _cw_read_wtp_descriptor_versions(mbag, data + pos, len - pos, silent);
}
int cw_in_wtp_descriptor(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len, struct sockaddr *from)
{
mbag_t mbag = conn->incomming;
return cw_read_wtp_descriptor(mbag, conn, a, data, len, 0);
}
int cw_in_cipwap_wtp_descriptor(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len, struct sockaddr *from)
{
mbag_t mbag = conn->incomming;
switch (conn->capwap_mode) {
case CW_MODE_CISCO:
return cw_read_cisco_wtp_descriptor(mbag, conn, a, data, len,
0);
case CW_MODE_CIPWAP:
{
/* try to get the right WTP Descriptor */
int rc;
rc = cw_read_wtp_descriptor(mbag, conn, a, data, len,
1);
if (rc) {
return cw_read_wtp_descriptor(mbag, conn, a,
data, len, 0);
}
rc = cw_read_cisco_wtp_descriptor(mbag, conn, a,
data, len, 0);
if (rc) {
return cw_read_cisco_wtp_descriptor(mbag,
conn, a, data,
len, 0);
}
return cw_read_wtp_descriptor(mbag, conn, a, data,
len, 0);
}
default:
return cw_read_wtp_descriptor(mbag, conn, a, data, len, 0);
}
return 0;
}

View File

@ -1,31 +0,0 @@
#include "conn.h"
#include "capwap.h"
void cw_init(struct conn * conn, uint8_t *buffer, int type, int seqnum, struct radioinfo * radioinfo)
{
}
void cw_init_response(struct conn * conn, uint8_t *req)
{
uint8_t *buffer=conn->resp_buffer;
int shbytes = cw_get_hdr_msg_offset(req);
int dhbytes;
memcpy(buffer,req,shbytes);
cw_set_hdr_hlen(buffer,2);
cw_set_hdr_flags(buffer,CAPWAP_FLAG_HDR_M,1);
dhbytes = cw_get_hdr_msg_offset(buffer);
uint8_t * msgptr = req+shbytes;
uint8_t * dmsgptr = buffer+dhbytes;
cw_set_msg_type(dmsgptr,cw_get_msg_type(msgptr)+1);
cw_set_msg_seqnum(dmsgptr,cw_get_msg_seqnum(msgptr));
cw_set_msg_flags(dmsgptr,0);
}

View File

@ -1,42 +0,0 @@
#include "capwap.h"
#include "capwap_cisco.h"
#include "itemstore.h"
int cw_put_cisco_wtp_radio_cfg(uint8_t *dst, int rid, cw_itemstore radio)
{
cw_put_byte(dst,rid);
cw_put_byte(dst+1,0); //?
cw_put_word(dst+2,cw_istore_get_word(radio,CW_RADIO_OCCUPANCY_LIMIT);
cw_put_byte(dst+4,cw_istore_get_byte(radio,CW_RADIO_CFP_PERIOD));
cw_put_word(dst+5,cw_istore_get_word(radio,CW_RADIO_CFP_MAX_DURATION,200);
/* XXX catch rmac shorter or longer than 6*/
cw_put_bstr(dst+7,cw_istore_get_datari->rmac); /* length MUST be 6 */
cw_put_word(dst+13,200); // beacon period
cw_put_data(dst+15,cw_itemstore_get_datari->country_str,3);
cw_put_data(dst+18,ri->country_str2,3);
cw_put_byte(dst+10+21,10); // gPeriod
cw_put_dword(dst+10+22,0x3538); // ?
return 28; //+cw_put_elem_vendor_hdr(dst,CW_VENDOR_ID_CISCO,CW_CISCO_WTP_RADIO_CFG,28);
}
int cw_out_cisco_wtp_radio_cfg(struct conn *conn, struct cw_action_out *a, uint8_t * dst)
{
uint8_t *d = dst;
return 28+cw_put_elem_vendor_hdr(dst,CW_VENDOR_ID_CISCO,CW_CISCO_WTP_RADIO_CFG,28);
}

View File

@ -29,20 +29,20 @@ int cw_out_generic(struct conn *conn, struct cw_action_out *a, uint8_t * dst)
vendor=cw_strvendor(a->vendor_id);
}
if (a->mand) {
cw_log(LOG_ERR,
/* cw_log(LOG_ERR,
"Can't put mandatory element %s %d - (%s) into %s. No value for '%s' found.",
vendor,
a->elem_id, cw_strelemp(conn->actions, a->elem_id)
, cw_strmsg(a->msg_id)
, a->item_id
);
}
*/ }
else{
cw_dbg(DBG_WARN,"No output for element %s%d -(%s) in %s. Item %s not found.",
/* cw_dbg(DBG_WARN,"No output for element %s%d -(%s) in %s. Item %s not found.",
vendor,
a->elem_id, cw_strelemp(conn->actions, a->elem_id)
, cw_strmsg(a->msg_id),a->item_id);
*/
}
return 0;
} else {

View File

@ -1,24 +0,0 @@
#include "capwap.h"
#include "capwap_items.h"
#include "log.h"
#include "rand.h"
int cw_out_init_session_id(struct conn *conn,struct cw_action_out * a,uint8_t *dst)
{
printf("Vendor ID: %d\n", a->vendor_id);
uint8_t session_id[16];
int l = cw_rand(session_id,16);
if ( l!=16 ) {
cw_log(LOG_ERR,"Can't init session ID.");
return -1;
}
cw_itemstore_set_bstrn(conn->local,CW_ITEM_SESSION_ID,session_id,16);
return 0;
}

View File

@ -1,37 +0,0 @@
#include "capwap.h"
#include "lwapp_cisco.h"
#include "capwap_cisco.h"
#include "conn.h"
#include "wtpinfo.h"
void cw_prepare_configuration_status_request(struct conn * conn, struct radioinfo * radioinfo, struct wtpinfo *wtpinfo)
{
struct cwmsg * cwmsg = &conn->req_msg;
uint8_t * buffer = conn->req_buffer;
cwmsg_init(cwmsg,buffer,CAPWAP_MSG_CONFIGURATION_STATUS_REQUEST,conn_get_next_seqnum(conn),radioinfo);
cwmsg->capwap_mode=conn->capwap_mode;
cwmsg_addelem_ac_name(cwmsg,(uint8_t *)"AC-iMaxi");
cwmsg_addelem_cisco_ap_regulatory_domain(cwmsg,&wtpinfo->radioinfo[0]);
cwmsg_addelem_cisco_ap_regulatory_domain(cwmsg,&wtpinfo->radioinfo[1]);
cwmsg_addelem_cisco_wtp_radio_cfg(cwmsg,&wtpinfo->radioinfo[0]);
cwmsg_addelem_cisco_wtp_radio_cfg(cwmsg,&wtpinfo->radioinfo[1]);
/*
uint8_t mtu[2048];
int l = lw_put_cisco_path_mtu(mtu,1485,1701);
printf("Len = %d\n",l);
cwmsg_addelem_vendor_specific_payload(cwmsg,LW_VENDOR_CISCO,
LW_ELEM_VENDOR_SPECIFIC,mtu,l);
*/
}

View File

@ -53,7 +53,9 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout)
uint8_t *dst = msgptr+8;
mlist_t m = cw_actionlist_out_get(conn->actions->out,cw_get_msg_type(msgptr));
/// TODO XXXX
//mlist_t m = cw_actionlist_out_get(conn->actions->out,cw_get_msg_type(msgptr));
mlist_t m =0;
if (!m){
cw_log(LOG_ERR,"Error: Can't create message of type %d (%s) - no definition found.",
@ -152,8 +154,9 @@ int cw_put_custom_msg(struct conn *conn, uint8_t * rawout, mavl_conststr_t elems
uint8_t *dst = msgptr+8;
DEFINE_AVLITER(i,conn->actions->out);
/// TODO XXXX
// DEFINE_AVLITER(i,conn->actions->out);
DEFINE_AVLITER(i,0);
cw_action_out_t *am;
if (! (am=avliter_seek(&i,&as))){

View File

@ -1,75 +0,0 @@
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
/**
*@file
*@brief Image Data handling
*/
#include <string.h>
#include "capwap.h"
#include "cw_log.h"
#include "cw_util.h"
#include <stdio.h>
int cw_readelem_image_identifier(struct cwimage_data *data, int type,uint8_t *msgelem, int len)
{
if (type != CW_ELEM_IMAGE_IDENTIFIER)
return 0;
data->vendor_id = ntohl(*((uint32_t*)msgelem));
if (len >= 1024) {
cw_dbg(DBG_MSG_ERR,"Image identifier too long (>1024), truncating");
len = 1024;
}
if ( data->identifier ){
memcpy(data->identifier,msgelem,len);
*(data->identifier+len)=0;
}
return 1;
}
static int imgdata_request(void * ptr,int type,uint8_t* msgelem,int len)
{
cw_dbg_msgelem(CW_MSG_IMAGE_DATA_REQUEST, type, msgelem, len);
cw_dbg(DBG_ALL,"Reading image data req msgelem, type=%d - %s ,len=%d\n",type,cw_strelem(type),len);
if (cw_readelem_image_identifier(ptr,type,msgelem,len))
return 1;
return 0;
}
/**
* Read an image data request message
*/
void cw_read_image_data_request(struct cwimage_data *data, uint8_t * msg, int len)
{
cw_foreach_msgelem(msg,len,imgdata_request,data);
}

View File

@ -1,51 +0,0 @@
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
#include <arpa/inet.h>
#include "wtpinfo.h"
#include "capwap_80211.h"
#include "cw_log.h"
int cw_readelem_80211_wtp_radio_info(void *dst,int type,uint8_t *msgelem, int len)
{
if (type != CWMSGELEM_80211_WTP_RADIO_INFO)
return 0;
if (len!=5){
cw_dbg(DBG_MSG_ERR,"Discarding msgelem 80211_WTP_RADIO_INFO, wrong size, len=%d\n",len);
return 0;
}
if (*msgelem <1 || *msgelem>31){
cw_dbg(DBG_CW_RFC,"Non-standard conform radio id, val=%d (must be between 1 to 31, See RFC 5415");
}
// int rid=*msgelem & 0x1f;
/*
wtpinfo->radioinfo[rid].set=1;
wtpinfo->radioinfo[rid].rid=rid;
wtpinfo->radioinfo[rid].type=ntohl(*(uint32_t*)(msgelem+1));
*/
return 1;
}

View File

@ -1,140 +0,0 @@
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file
* @brief cw_readelem_ac_descriptor is implemented here.
*/
#include "capwap.h"
#include "acinfo.h"
#include "bstr.h"
#include "cw_log.h"
static int read_subelem_cisco(struct ac_info* acinfo,int subtype,uint8_t * elem, int len)
{
switch (subtype) {
case 0:
/* hardware version */
bstr_replace(&acinfo->hardware_version,bstr_create(elem,len));
break;
case 1:
/* software version */
bstr_replace(&acinfo->software_version,bstr_create(elem,len));
break;
default:
//printf("What? %d\n",subtype);
break;
}
return 1;
}
static int read_subelem(struct ac_info* acinfo,int subtype,uint8_t *elem, int len)
{
switch (subtype){
case 4:
/* hardware version */
bstr_replace(&acinfo->hardware_version,bstr_create(elem,len));
break;
case 5:
/* software version */
bstr_replace(&acinfo->software_version,bstr_create(elem,len));
break;
}
return 1;
}
/**
* Read CAPWAP message elment: AC Descriptor
* @param acinfo pointer to acinfo where the result is stored
* @param type message element type
* @param msgelem pointer to message element
* @param len length of message element
* @return 1 AC descriptor sucessfull read \n
* 0 not an ac descriptor message\n
* -1 an error has occured
*/
int cw_readelem_ac_descriptor(struct ac_info * acinfo,int type, uint8_t *msgelem, int len)
{
if (type != CAPWAP_ELEM_AC_DESCRIPTOR)
return 0;
if (len<12)
return -1;
uint32_t val;
/* read stations and limit */
val = ntohl(*((uint32_t*)msgelem));
acinfo->stations = val>>16;
acinfo->limit = val&0xffff;
/* read active wtps and max wtps */
val = ntohl(*((uint32_t*)(msgelem+4)));
acinfo->active_wtps = val>>16;
acinfo->max_wtps = val&0xffff;
/* read active wtps and max wtps */
val = ntohl(*((uint32_t*)(msgelem+8)));
acinfo->security = val >>24;
acinfo->rmac= (val >> 16)&0xff;
acinfo->dtls_policy=val&0xf;
int sub=12;
int sublen;
while (sub<len){
if (len-sub<8)
return -1;
uint32_t vendor = ntohl(*((uint32_t*)(msgelem+sub)));
val = ntohl(*((uint32_t*)(msgelem+sub+4)));
sublen = val&0xffff;
sub+=8;
int subtype = val>>16;
cw_dbg(DBG_ELEM,"AC Descriptor sub-element vendor: %d, type:%d, len: %d",vendor,subtype,sublen);
switch (vendor) {
case 0:
read_subelem(acinfo,subtype,msgelem+sub,sublen);
break;
case CW_VENDOR_ID_CISCO:
read_subelem_cisco(acinfo,subtype,msgelem+sub,sublen);
break;
}
if (sub+sublen>len)
return -1;
sub+=sublen;
}
return 1;
}

View File

@ -1,4 +1,4 @@
/*
#include "capwap_cisco.h"
#include "cw_log.h"
@ -19,4 +19,7 @@ int cw_readelem_cisco_wtp_radio_cfg(int elem_id,uint8_t *elem, int len,struct ra
ri->beacon_period = lw_get_word(elem+13);
return 1;
}
}
*/

View File

@ -1,37 +0,0 @@
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
#include "capwap.h"
#include "cw_util.h"
#include "log.h"
int cw_readelem_maximum_message_length(uint16_t *dst, int type,uint8_t *msgelem, int len)
{
if (type != CWMSGELEM_MAXIMUM_MESSAGE_LENGTH)
return 0;
if (len!=2){
cw_dbg(DBG_CW_RFC,"Discarding MAXIMUM_MESSAGE_LENTGH msgelem, wrong size, type=%d,len=%d",type,len);
return 0;
}
*dst = ntohs(* ((uint16_t*)msgelem));
return 1;
}

View File

@ -1,45 +0,0 @@
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
#include "capwap.h"
#include "cw_log.h"
int cw_readelem_radio_operational_state(struct radioinfo * radioinfo, int type,uint8_t *msgelem, int len)
{
if (type != CW_ELEM_RADIO_OPERATIONAL_STATE)
return 0;
if (len<3)
return 0;
if (len!=3){
cw_dbg(DBG_CW_RFC,"Radio operational state size != 3, RFC 5415");
}
int radioid = msgelem[0];
radioid&=0x1f;
radioinfo[radioid].state=msgelem[1];
radioinfo[radioid].cause=msgelem[2];
return 1;
}

View File

@ -1,6 +1,6 @@
#include "capwap.h"
#include "cw_log.h"
#include "dbg.h"
int cw_readelem_statistics_timer(uint16_t *timer, int type, uint8_t * msgelem, int len)
{
@ -8,7 +8,7 @@ int cw_readelem_statistics_timer(uint16_t *timer, int type, uint8_t * msgelem, i
return 0;
if (len!=2){
cw_dbg(DBG_CW_RFC,"Statistics timer msgelem has wrong size, type=%d,len=%d",type,len);
cw_dbg(DBG_RFC,"Statistics timer msgelem has wrong size, type=%d,len=%d",type,len);
return 0;
}
*timer=*((uint16_t*)msgelem);

View File

@ -1,22 +0,0 @@
#include "capwap.h"
#include "cw_log.h"
int cw_readmsg_configuration_update_request(uint8_t *elems,int elems_len)
{
uint8_t * elem;
cw_foreach_elem(elem,elems,elems_len){
int type = cw_get_elem_type(elem);
int len = cw_get_elem_len(elem);
uint8_t *data = cw_get_elem_data(elem);
cw_dbg_msgelem(CAPWAP_MSG_CONFIGURATION_STATUS_REQUEST, type, data, len);
// cw_readelem_vendor_specific_payload(elem,CW_MSG_CONFIGURATION_STATUS_RESPONSE, type,data,len );
}
}

View File

@ -33,8 +33,8 @@
int cw_send_echo_response(struct conn * conn,int seqnum,struct radioinfo * radioinfo)
{
struct cwmsg * cwmsg = &conn->resp_msg;
cwmsg_init(cwmsg,conn->resp_buffer,CW_MSG_ECHO_RESPONSE,seqnum,radioinfo);
// cwmsg_init(cwmsg,conn->resp_buffer,CW_MSG_ECHO_RESPONSE,seqnum,radioinfo);
conn_send_response(conn,cwmsg,seqnum);
// conn_send_response(conn,cwmsg,seqnum);
return 1;
}

View File

@ -1,102 +0,0 @@
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file
* @breif send image file
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include "capwap.h"
#include "lwapp.h"
#include "sock.h"
#include "cw_log.h"
/**
* Send an image file to an AP
*
*/
void cw_send_image_file(struct conn *conn)
{
/*
FILE *infile;
infile = fopen(filename, "rb");
if (!infile) {
cw_log(LOG_ERR, "Can't open image file %s:%s", filename, strerror(errno));
return;
}
cw_log(LOG_INFO, "Sending image file %s to %s", filename, sock_addr2str(&conn->addr));
*/
uint8_t buffer[1024]; /* buffer MUST be 1024 */
struct cwimage_data data;
memset(&data,0,sizeof(struct cwimage_data));
data.data = buffer;
/*
conn->request_handler = cw_handle_echo_request;
conn->request_handler_param = conn;
*/
int bl = 0;
do {
data.len = fread(buffer, 1, sizeof(buffer), infile);
if (feof(infile))
data.type = 2;
else
data.type = 1;
cw_dbg(DBG_CW_IMG_DTL, "Sending img data request, block=%d, len=%d, ch=%d\n", bl,
data.len, lw_checksum(data.data, data.len));
bl++;
// conn_prepare_image_data_request(conn, &data, 0);
// cwrmsg = conn_send_request(conn);
if (!cwrmsg) {
cw_log(LOG_ERR,"Error sneding image file to %s",sock_addr2str(&conn->addr));
break;
}
} while (!feof(infile));
}

View File

@ -1,40 +0,0 @@
/**
* @file
* @brief add wlan msg element implementation
*/
#include "capwap.h"
#include "capwap_80211.h"
#include "cwmsg.h"
#include "bstr.h"
void cwmsg_addelem_80211_add_wlan(struct cwmsg *cwmsg,struct cwwlan *wlan)
{
uint16_t capab=htons(wlan->capab);
uint16_t keylen=htons(wlan->key_length);
cwmsg_vaddelem(cwmsg,CW_ELEM_80211_ADD_WLAN,
&wlan->rid,1,
&wlan->wid,1,
&capab,2,
&wlan->key_index,1,
&wlan->key_status,1,
&keylen,2,
wlan->key,wlan->key_length,
wlan->group_tsc,6,
&wlan->qos,1,
&wlan->auth_type,1,
&wlan->mac_mode,1,
&wlan->tunnel_mode,1,
&wlan->suppress_ssid,1,
bstr_data(wlan->ssid),bstr_len(wlan->ssid),
NULL
);
}

View File

@ -33,7 +33,7 @@ printf("MTU discovery len %d %d and pos %d:\n",conn->mtu,len,msg->pos);
if (len < 0 )
return;
uint32_t val = CWMSGELEM_MTU_DISCOVERY_PADDING<<16|len;
uint32_t val = CW_ELEM_MTU_DISCOVERY_PADDING<<16|len;
*((uint32_t*)(msg->msgelems+msg->pos))=htonl(val);
memset(msg->msgelems+4+msg->pos,0xff,len);
msg->pos+=4+len;

View File

@ -1,58 +0,0 @@
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include "capwap.h"
#include "capwap_cisco.h"
#include "cwmsg.h"
#include "conn.h"
#include "sock.h"
void cwmsg_addelem_vendor_cisco_mwar_addr(struct cwmsg *msg, struct conn *conn)
{
uint8_t data [7];
switch (((struct sockaddr*)&conn->addr)->sa_family){
case AF_INET:
{
data[0]=2; /* mwar type */
data[5]=0;
data[6]=0;
printf("Adding mwar addr %s\n",sock_addr2str(&conn->addr));
struct sockaddr_in * sain = (struct sockaddr_in*)&conn->addr;
memcpy(data+1,(uint8_t*)&sain->sin_addr,4);
cwmsg_addelem_vendor_specific_payload(msg, CW_VENDOR_ID_CISCO,
CW_CISCO_MWAR_ADDR,
data,7);
break;
}
/* case AF_INET6:
{
int id;
if (cw_mode == CWMODE_CISCO)
id = CWMSGELEM_WTP_IPV6_IP_ADDR;
else
id = CWMSGELEM_CAPWAP_LOCAL_IPV6_ADDRESS;
struct sockaddr_in6 * sain = (struct sockaddr_in6*)&a;
return cwmsg_addelem(msg,id,(uint8_t*)&sain->sin6_addr,16);
}
break;
*/
}
}

View File

@ -25,6 +25,7 @@
* @file Debugging Functions
* @brief Various debug functions.
*/
#include <stdarg.h>
#include "capwap.h"
#include "dbg.h"
@ -36,6 +37,10 @@
#include "capwap.h"
#include "capwap_cisco.h"
#include "lwapp_cisco.h"
#include "cw.h"
#include "message_set.h"
/**
*@addtogroup DBG
@ -196,10 +201,12 @@ void cw_dbg_missing_mand(int level, struct conn *conn, cw_action_in_t ** ml, int
char *p = buffer;
int i;
char *delim = "";
// TODO XXXX
for (i = 0; i < n; i++) {
p += sprintf(p, "%s", delim);
/* p += sprintf(p, "%s", delim);
delim = ", ";
p += sprintf(p, "%s", cw_strelemp(conn->actions, ml[i]->elem_id));
*/
}
cw_dbg(level, "Missing mandatory elements: [%s]", buffer);
}
@ -483,7 +490,19 @@ void cw_dbg_msg(int level, struct conn *conn, uint8_t * packet, int len,
// int pplen = len - (msgptr-packet);
int msg_id = cw_get_msg_id(msgptr);
s += sprintf(s, "%s Message (type=%d) ", cw_strmsg(msg_id), msg_id);
struct cw_MsgData search;
search.type = msg_id;
struct cw_MsgData * message;
message = mavl_get(conn->msgset->messages,&search);
char * msname;
if (!message)
msname="Unknown";
else
msname = message->name;
s += sprintf(s, "%s Message (type=%d) ", msname /*cw_strmsg(msg_id)*/, msg_id);
if (level == DBG_MSG_IN)
s += sprintf(s, "from %s ", sock_addr2str(from));
else
@ -548,18 +567,21 @@ void cw_dbg_elem_colored(int level, struct conn *conn, int msg, int msgelem,
char vendorname[256];
char vendor_details[265];
*vendor_details = 0;
/// TODO XXXX
if (msgelem == CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD) {
uint32_t vendor_id = ntohl(*((uint32_t *) msgbuf));
int type = ntohs(*((uint16_t *) (msgbuf + 4)));
cw_format_vendor(vendor_details, vendor_id, type, msgbuf);
sprintf(vendorname, "%s/%s/%s",
/* sprintf(vendorname, "%s/%s/%s",
cw_strelemp(conn->actions, msgelem),
(char *) cw_strvendor(vendor_id), vendor_details);
*/
elemname = vendorname;
} else {
elemname = cw_strelemp(conn->actions, msgelem);
// elemname = cw_strelemp(conn->actions, msgelem);
elemname=0;
}

View File

@ -19,19 +19,7 @@
#define __CW_DTLS_H
#include <stdint.h>
#include "conn.h"
struct dtls_ssl_cert
{
int size;
int type;
uint8_t * data;
};
extern int dtls_bio_read(struct conn *conn, char *out, int maxlen);
extern int dtls_bio_write(struct conn * conn, const char *data, int len);
#include "dtls_common.h"

13
src/cw/dtls_common.h Normal file
View File

@ -0,0 +1,13 @@
#include <stdint.h>
#include "conn.h"
struct dtls_ssl_cert
{
int size;
int type;
uint8_t * data;
};
extern int dtls_bio_read(struct conn *conn, char *out, int maxlen);
extern int dtls_bio_write(struct conn * conn, const char *data, int len);

View File

@ -22,6 +22,7 @@
#include <gnutls/gnutls.h>
#include <gnutls/dtls.h>
#include "dtls_common.h"
#include "dtls_gnutls.h"
#include "conn.h"

View File

@ -29,6 +29,7 @@
#include "log.h"
#include "sock.h"
#include "capwap.h"
#include "dtls_common.h"
#include "dtls_gnutls.h"
#include "timer.h"

View File

@ -1,5 +1,5 @@
#include "dtls_common.h"
#include "dtls_gnutls.h"
const char *dtls_gnutls_get_cipher(struct conn *conn)

View File

@ -10,6 +10,9 @@
char *cw_load_file(const char *filename,size_t *size);
int cw_save_file(const char *filename, char *data,int len);
char * cw_filename(const char * path, const char * name, const char * ext);
#define CW_FILE_PATH_DELIMITERS "/"
/**@}*/

View File

@ -31,6 +31,7 @@
#include <stdint.h>
#include <time.h>
#include <unistd.h>
#ifndef FRAG_MAXSIZE
/** maximaum size of a fragment */

View File

@ -23,7 +23,7 @@
#include "capwap.h"
#include "sock.h"
/*
int hdr_print(char *str, uint8_t *packet, int len)
{
@ -119,3 +119,5 @@ int hdr_print(char *str, uint8_t *packet, int len)
return s-str;
}
*/

View File

@ -1,16 +0,0 @@
#include "capwap_items.h"
#include "strheap.h"
struct cw_str cw_item_strings[] = {
{ CW_ITEM_WTP_HARDWARE_VERSION,"WTP Hardware Version"},
{ CW_ITEM_WTP_NAME, "WTP Name "},
{ CW_ITEM_AC_NAME, "AC Name "},
{ CW_ITEM_WTP_BOARD_VENDOR, "WTP Board Vendor"},
{ CW_ITEM_WTP_BOARD_MODELNO,"WTP Board Model No."},
{ CW_ITEM_WTP_BOARD_MACADDRESS, "WTP Board MAC Address"},
{ CW_ITEM_WTP_BOARD_ID,"WTP Board ID"},
{ CW_ITEM_WTP_GROUP_NAME,"WTP Group Name"},
{ CW_STR_STOP,"Unknown"}
};

View File

@ -16,6 +16,7 @@
*/
#include <stdarg.h>
#include "log.h"

View File

@ -23,8 +23,10 @@ int lw_in_vendor_specific(struct conn *conn, struct cw_action_in *a,
as.elem_id = cw_get_word(data + 4);
as.proto = CW_ACTION_PROTO_LWAPP;
af = cw_actionlist_in_get(conn->actions->in, &as);
// TODO XXXX
//af = cw_actionlist_in_get(conn->actions->in, &as);
af = 0;
if (!af) {
cw_dbg(DBG_WARN,

View File

@ -1,6 +1,7 @@
#include "lwapp.h"
/*
int lw_put_80211_wtp_wlan_radio_configuration(uint8_t*dst,struct radioinfo *ri)
{
lw_put_byte(dst,ri->rid);
@ -9,18 +10,18 @@ int lw_put_80211_wtp_wlan_radio_configuration(uint8_t*dst,struct radioinfo *ri)
lw_put_byte(dst+4,ri->cfp_period);
lw_put_word(dst+5,ri->cfp_max_duration);
/* XXX catch rmac shorter or longer than 6*/
// XXX catch rmac shorter or longer than 6
lw_put_bstr(dst+7,ri->rmac); /* length MUST be 6 */
lw_put_bstr(dst+7,ri->rmac); // length MUST be 6
lw_put_word(dst+13,ri->beacon_period);
lw_put_byte(dst+15,ri->dtim_period);
lw_put_data(dst+16,ri->country_str,4);
lw_put_byte(dst+20,ri->max_bssid);
/* XXX not LWAP conform */
// XXX not LWAP conform
lw_put_data(dst+21,(uint8_t*)"DEAU990",7);
return 21+7;
}
*/

View File

@ -1,21 +0,0 @@
#include "lwapp.h"
int lw_readelem_80211_wtp_wlan_radio_configuration(int elem_id,uint8_t *elem, int len,struct radioinfo *ri)
{
if (elem_id != LW_ELEM_80211_WLAN_RADIO_CONFIGURATION)
return 1;
if (len<21){
cw_dbg(DBG_ERR,"LWAPP Radio Cfg element too short, %d < 21",len);
return -1;
}
ri->rid = lw_get_byte(elem);
ri->occupancy_limit = lw_get_word(elem+2);
bstr_replace(ri->bssid,bstr_create(elem+7,6);
}

View File

@ -1,39 +0,0 @@
/**
* @file
* @brief Implementation of lw_readelem_wtp_board_data
*/
#include <arpa/inet.h>
#include "log.h"
#include "wtpinfo.h"
#include "lwapp.h"
/**
* Read LWAPP board data element
* @param wtpinfo results are stored here
* @param type type of msg element (must be LWMSGELEM_WTP_BOARD_DATA)
* @param msgelem msg element data
* @param len length of msg element
* @return 0 if msg is not wtp board data\n
* 1 board data successful read
*/
int lw_readelem_wtp_board_data(struct wtpinfo *wtpinfo, int type, uint8_t *msgelem, int len)
{
if (type != LW_ELEM_WTP_BOARD_DATA)
return 0;
if ( len != 46 ) {
cw_dbg(DBG_MSG_ERR,"LWAPP msg size wrong. (WTP BOARD DATA) must be 46");
return -1;
}
// uint16_t card_id = htonl( * ( (uint16_t*)(msgelem) ) );
// uint16_t card_rev = htonl( * ( (uint16_t*)(msgelem +2 ) ) );
return 1;
}

View File

@ -26,6 +26,7 @@
#include "cw_util.h"
#include "log.h"
#include "dbg.h"
/**
* Reads the LWAPP message element WTP Name
@ -42,7 +43,7 @@ int lw_readelem_wtp_name(uint8_t ** dst, int type, uint8_t * msgelem, int len)
if (len>254){
cw_dbg(DBG_MSG_ERR,"Truncating WTP_NAME msgelem to 254, wrong size, type=%d,len=%d",type,len);
cw_dbg(DBG_ELEM_ERR,"Truncating WTP_NAME msgelem to 254, wrong size, type=%d,len=%d",type,len);
len=254;
}

View File

@ -117,31 +117,12 @@ int mavl_foreach_from_lr(struct mavl *t, struct mavlnode *n, void *data,
//extern void mavl_foreach(struct mavl *t, int (*callback)(void *,void*),void *cbpriv,int dir);
static inline void *mavl_replace_data(struct mavl *t, void *data, int len)
{
void *df = mavl_get(t, data);
if (!df)
return NULL;
memcpy(df, data, len);
return df;
}
void *mavl_replace_data(struct mavl *t, void *data, int len);
static inline void *mavl_replace(struct mavl *t,void *data){
struct mavlnode * node = mavl_get_node(t,data);
if (node){
t->del(node->data);
return node->data=data;
}
return mavl_add(t,data);
}
void *mavl_replace(struct mavl *t,void *data);
static inline void mavl_destroy(struct mavl *t)
{
mavl_del_all(t);
free (t);
}
void mavl_destroy(struct mavl *t);
@ -169,41 +150,12 @@ typedef struct mavliter mavliter_t;
void * mavliter_next(mavliter_t *i);
static inline void * mavliter_seek_set(struct mavliter *i)
{
i->stack_ptr=0;
i->cur=i->root;
return mavliter_next(i);
}
void * mavliter_seek_set(struct mavliter *i);
/**
* Init an AVL Tree Iterator.
*
* After initialization #mavliter_next would return the first element.
* The behavior of #mavliter_get would still be undefined.
* @param i AVL Iterator to initialize
* @param t correspondending AVL Tree
*
* @See mavliter_t,
*/
static inline void mavliter_init(mavliter_t *i, mavl_t t){
i->root = t->root;
i->stack_ptr=0;
i->cmp=t->cmp;
}
void mavliter_init(mavliter_t *i, mavl_t t);
/**
* Get the element, where AVL Iterator currently is positioned.
* @param i AVL Iterator
* @return element or NULL if not found.
*/
static inline void * mavliter_get(mavliter_t *i){
if(!i->cur)
return NULL;
return i->cur->data;
}
void * mavliter_get(mavliter_t *i);
extern void * mavliter_seek(mavliter_t *i,void *d);

9
src/cw/mavl_destroy.c Normal file
View File

@ -0,0 +1,9 @@
#include "mavl.h"
void mavl_destroy(struct mavl *t)
{
mavl_del_all(t);
free (t);
}

12
src/cw/mavl_replace.c Normal file
View File

@ -0,0 +1,12 @@
#include "mavl.h"
void *mavl_replace(struct mavl *t,void *data){
struct mavlnode * node = mavl_get_node(t,data);
if (node){
t->del(node->data);
return node->data=data;
}
return mavl_add(t,data);
}

View File

@ -0,0 +1,12 @@
#include "mavl.h"
void *mavl_replace_data(struct mavl *t, void *data, int len)
{
void *df = mavl_get(t, data);
if (!df)
return NULL;
memcpy(df, data, len);
return df;
}

14
src/cw/mavliter_get.c Normal file
View File

@ -0,0 +1,14 @@
#include "mavl.h"
/**
* Get the element, where AVL Iterator currently is positioned.
* @param i AVL Iterator
* @return element or NULL if not found.
*/
void * mavliter_get(mavliter_t *i){
if(!i->cur)
return NULL;
return i->cur->data;
}

19
src/cw/mavliter_init.c Normal file
View File

@ -0,0 +1,19 @@
#include "mavl.h"
/**
* Init an AVL Tree Iterator.
*
* After initialization #mavliter_next would return the first element.
* The behavior of #mavliter_get would still be undefined.
* @param i AVL Iterator to initialize
* @param t correspondending AVL Tree
*
* @See mavliter_t,
*/
void mavliter_init(mavliter_t *i, mavl_t t){
i->root = t->root;
i->stack_ptr=0;
i->cmp=t->cmp;
}

Some files were not shown because too many files have changed in this diff Show More