diff --git a/src/ac/conf.c b/src/ac/conf.c index b43e6aab..4a2528fa 100644 --- a/src/ac/conf.c +++ b/src/ac/conf.c @@ -143,7 +143,18 @@ static int init_mods() { conf_mods[0]=cw_get_mod_ac("cipwap"); - conf_mods[1]=NULL; + conf_mods[1]=cw_get_mod_ac("capwap"); + conf_mods[2]=NULL; + + + + + int i; + for(i=0; conf_mods[i]; i++){ + if (conf_mods[i]->init){ + conf_mods[i]->init(); + } + } return 0; } diff --git a/src/capwap/Makefile b/src/capwap/Makefile index 3b8e7abe..1f634c4a 100644 --- a/src/capwap/Makefile +++ b/src/capwap/Makefile @@ -189,6 +189,7 @@ DTLSOBJS+=dtls_bio.o CONNOBJS= conn_create.o \ conn_process_packet.o \ + conn_process_packet_x.o \ conn_q_add_packet.o \ conn_q_get_packet.o \ conn_q_recv_packet.o \ @@ -291,6 +292,7 @@ CFLAGS += $(GNUTLS_CFLAGS) \ #SRCS = $(OBJS:.o=.c) MODOBJS=$(wildcard ./mod/cipwap/$(ARCH)/*.o) +MODOBJS+=$(wildcard ./mod/capwap/$(ARCH)/*.o) $(ARCH)/%.o:%.c @mkdir -p $(ARCH) @@ -325,7 +327,6 @@ mod_cipwap: $(MAKE) -C mod/cipwap - clean: $(RM) $(ARCH)/* # $(RM) $(OBJS) diff --git a/src/capwap/action.h b/src/capwap/action.h index 6aa50e45..4fc93caa 100644 --- a/src/capwap/action.h +++ b/src/capwap/action.h @@ -19,7 +19,7 @@ /** * @file * @brief CAPWAP ACtions Header - * @defgroup ACTION CAPWAP/LWAP Actions + * @defgroup ACTION CAPWAP/LWAPP Actions * @{ */ #ifndef __ACTION_H diff --git a/src/capwap/capwap.h b/src/capwap/capwap.h index 04beab2a..d9bcc11a 100644 --- a/src/capwap/capwap.h +++ b/src/capwap/capwap.h @@ -991,6 +991,10 @@ static inline int cw_rcok(int rc) } +/** + *@defgroup CW CW + *@{ + */ static inline const char *cw_strelemp_(cw_strheap_t h, int msg_id) { @@ -1000,6 +1004,8 @@ static inline const char *cw_strelemp_(cw_strheap_t h, int msg_id) return cw_strheap_get(h, CW_STR_STOP); } +/**@}*/ + #define cw_strelemp(p,id) cw_strelemp_((p)->strelem,id) diff --git a/src/capwap/conn_process_packet.c b/src/capwap/conn_process_packet.c index 0e9f57b2..63c32509 100644 --- a/src/capwap/conn_process_packet.c +++ b/src/capwap/conn_process_packet.c @@ -173,12 +173,22 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len, int i; for (i=0; mods[i]; i++){ if (mods[i]->detect){ - mods[i]->detect(conn,rawmsg,len,from); + if (mods[i]->detect(conn,rawmsg,len,from)){ + cw_dbg(DBG_INFO,"Using mod '%s' to handle connection from %s",mods[i]->name,sock_addr2str(from)); + break; + } } } } } + if (!conn->detected){ + cw_dbg(DBG_INFO,"Cant't detect capwap, discarding message from %s",sock_addr2str(from)); + errno=EAGAIN; + return -1; + + } + /* prepare struct for search operation */ diff --git a/src/capwap/cw_in_generic.c b/src/capwap/cw_in_generic.c index 70a2ecbc..9afcaaf0 100644 --- a/src/capwap/cw_in_generic.c +++ b/src/capwap/cw_in_generic.c @@ -11,7 +11,7 @@ int static check_len(struct conn *conn, struct cw_action_in *a, uint8_t * data, { if (len < a->min_len) { cw_dbg(DBG_ELEM_ERR, - "%d (%s) message element too short, lan=%d, min len=%d", + "%d (%s) message element too short, len=%d, min len=%d", a->elem_id, cw_strelemp(conn->actions, a->elem_id), len, a->min_len); return 0; diff --git a/src/capwap/cw_load_file.c b/src/capwap/cw_load_file.c index 09e45d03..083777a6 100644 --- a/src/capwap/cw_load_file.c +++ b/src/capwap/cw_load_file.c @@ -59,4 +59,3 @@ char *cw_load_file(const char *filename, size_t * size) fclose(infile); return buf; } - diff --git a/src/capwap/dbg_strings.c b/src/capwap/dbg_strings.c index 59c54ead..ad394cd4 100644 --- a/src/capwap/dbg_strings.c +++ b/src/capwap/dbg_strings.c @@ -34,7 +34,6 @@ /** * Debug strings */ - struct cw_strlist_elem cw_dbg_strings[] = { { DBG_INFO, "info" }, { DBG_PKT_IN, "pkt_in" }, diff --git a/src/capwap/doc.dox b/src/capwap/doc.dox index ace9a291..e729383c 100644 --- a/src/capwap/doc.dox +++ b/src/capwap/doc.dox @@ -1,7 +1,7 @@ /*! - \mainpage LIBCAWAP Documentation + \mainpage LIBCAPWAP Documentation - \section IBCAPWAPInstall Installing + \section LIBCAPWAPInstall Installing To install libcapwap you need the following things: A computer, a keyboard, some software and time. diff --git a/src/capwap/format.c b/src/capwap/format.c index c784d7e8..1971c9a8 100644 --- a/src/capwap/format.c +++ b/src/capwap/format.c @@ -27,16 +27,17 @@ /** * Format bytes as hex string. - * @param dst destination buffer - * @param format format to use when writing a byte. - * @param delim delimiter - * @param src bytes to format - * @param len number of bytes to format - * @return the number character written to dst + * @param dst Destination buffer + * @param format Format to use, when writing a byte. Use the same format syntax as for printf, + * e.g. the string "%02X" would format a byte as upper case hexadeciaml string. + * @param delim Delimiter string. The given string is placed between bytes. + * @param src Bytes to format + * @param len Number of bytes to format + * @return the number of characters written to dst * * This function is used by macros like #cw_format_hexl, #cw_format_hex ... \n * The size of the destination buffer must be at least x * len + strlen(delim) * (len-1) +1, - * where x is the number of characters a formatted hex byte needs (typically 2). + * where x is the number of characters. A formatted hex byte needs (typically 2). * */ int cw_format_hex_bytes(char *dst, const char *format, const char *delim, diff --git a/src/capwap/fragman.c b/src/capwap/fragman.c index a921ca67..69d84a0a 100644 --- a/src/capwap/fragman.c +++ b/src/capwap/fragman.c @@ -16,8 +16,12 @@ */ +/** + * @addtogroup Fragman + * @{ + */ -/* +/** * @file * @brief This file implements a simple fragment management system for the capwap protocol. * @@ -110,6 +114,14 @@ void fragman_free(frag_t * frags,struct frag * f) } */ +/** + * Add a fragment + * @pram frags Fragman object + * @param packet Pointer to data of the packet to add + * @param hlen Length of the header od the packet + * @param payloadlen Number of bytes in payload + * @return NULL if someting went wrong + */ uint8_t * fragman_add(frag_t * frags, uint8_t *packet, int hlen, int payloadlen) { struct frag * f; @@ -200,3 +212,8 @@ void fragman_destroy(frag_t * frags) free (frags); } + +/** + * @} + */ + diff --git a/src/capwap/fragman.h b/src/capwap/fragman.h index 9306e65f..4299f698 100644 --- a/src/capwap/fragman.h +++ b/src/capwap/fragman.h @@ -17,6 +17,15 @@ */ +/** + *@defgroup Fragman FRAGMAN + *@breif Frgaman functions + * + * Detailed esription + *@{ + */ + + #ifndef __FRAGMAN_H #define __FRAGMAN_H @@ -24,6 +33,7 @@ #include #ifndef FRAG_MAXSIZE + /** maximaum size of a fragment */ #define FRAG_MAXSIZE 65536+4 #endif @@ -61,5 +71,7 @@ extern void fragman_destroy(frag_t * frags); extern void fragman_free(frag_t * frags,struct frag * f); +/**@}*/ + #endif diff --git a/src/capwap/mbag.h b/src/capwap/mbag.h index c7c69d8f..f2dac283 100644 --- a/src/capwap/mbag.h +++ b/src/capwap/mbag.h @@ -50,7 +50,7 @@ struct mbag_typedef{ struct mbag_item * (*from_str)(const char *src); }; -/** The type for an mbag typedf */ +/** The type for an mbag typedef */ typedef const struct mbag_typedef * mbagtype_t; @@ -59,24 +59,27 @@ typedef const struct mbag_typedef * mbagtype_t; * The MBAG item */ struct mbag_item{ + union { + uint32_t iid; /** * Key of this item + * * This could be either a string (default) or an integer uint32_t value. * If you whant to use with uint32_t keys, use the mbag_i_* functions, to * create mbags. */ - union { - uint32_t iid; const char *id; }; - /** indicates if the key is dynamic oder static. - If dynamic, the id will be freed using free - if mbag_item is deleted */ + /** + * Indicates if the key is dynamic oder static. + * If dynamic, the id will be freed using free, + * if mbag_item is deleted + */ uint8_t dynid; /** Type of this item */ const struct mbag_typedef * type; - /** Value of this item */ union { + /** Value of this item */ void *data; uint8_t byte; uint16_t word; diff --git a/src/capwap/mod.h b/src/capwap/mod.h index 9d92491f..8dc45d61 100644 --- a/src/capwap/mod.h +++ b/src/capwap/mod.h @@ -18,13 +18,17 @@ struct mod_ac CAPWAP message. Either on Discovery Request or Join Request **/ int (*detect)(struct conn *conn,const uint8_t *rawmsg, int rawlen,struct sockaddr *from); + + /** used for private data */ + void *data; }; #include "mod/cipwap/mod_cipwap.h" +#include "mod/capwap/mod_capwap.h" -#define MODS_AC { mod_cipwap_ac,NULL } +#define MODS_AC { mod_capwap_ac,mod_cipwap_ac,NULL } extern struct mod_ac * cw_get_mod_ac(const char *name); diff --git a/src/capwap/mod/capwap/Makefile b/src/capwap/mod/capwap/Makefile new file mode 100644 index 00000000..1056b428 --- /dev/null +++ b/src/capwap/mod/capwap/Makefile @@ -0,0 +1,25 @@ +include ../../../Macros.mak +include ../../../Config.mak + +OBJS=\ + mod_capwap_ac.o \ + capwap_actions_ac.o + +OBJS:=$(patsubst %.o,$(ARCH)/%.o,$(OBJS)) + + +CFLAGS = -Wall -g -O0 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I ../../../ + + +SRCS = $(OBJS:.o=.c) + +$(ARCH)/%.o:%.c + @mkdir -p $(ARCH) + @echo " CC "$< + @$(CC) -c $(CFLAGS) $< -o $@ + + +all: $(OBJS) + +clean: + rm -rf $(ARCH) diff --git a/src/capwap/mod/capwap/mod_capwap.h b/src/capwap/mod/capwap/mod_capwap.h new file mode 100644 index 00000000..c7e5988d --- /dev/null +++ b/src/capwap/mod/capwap/mod_capwap.h @@ -0,0 +1,6 @@ +#ifndef __MOD_CAPWAP_H +#define __MOD_CAPWAP_H + +struct mod_ac * mod_capwap_ac(); + +#endif diff --git a/src/capwap/mod/capwap/mod_capwap_ac.c b/src/capwap/mod/capwap/mod_capwap_ac.c new file mode 100644 index 00000000..1142d0e9 --- /dev/null +++ b/src/capwap/mod/capwap/mod_capwap_ac.c @@ -0,0 +1,44 @@ + +#include "capwap/mod.h" +#include "capwap/log.h" +#include "capwap/dbg.h" + +#include "capwap/action.h" + +#include "mod_capwap.h" + + +static struct cw_actiondef actions; + + + +extern int capwap_register_actions_ac(struct cw_actiondef *def); + + +static int init() +{ + cw_dbg(DBG_INFO,"Initialiazing mod_capwap ..."); + int rc = capwap_register_actions_ac(&actions); + cw_dbg(DBG_INFO,"Initialized mod capwap with %d actions",rc); + return 0; +} + + +static int detect(struct conn *conn,const uint8_t *rawmsg, int rawlen,struct sockaddr *from) +{ + cw_log(LOG_INFO,"Detecting ..."); + conn->detected=1; + return 1; +} + +static struct mod_ac capwap_ac = { + .name ="capwap", + .init = init, + .detect = detect + +}; + +struct mod_ac * mod_capwap_ac(){ + return &capwap_ac; +}; +