FossilOrigin-Name: 4bbb8402b5110003c6d19908b6fa9b4a7a6b5903ba1fa691eb93a49aa0f089f4
This commit is contained in:
7u83@mail.ru 2015-04-07 05:42:36 +00:00
parent a4175d4cce
commit 4c0d06e21d
55 changed files with 1312 additions and 1226 deletions

View File

@ -14,7 +14,7 @@ USE_CONTRIB_GNUTLS=1
# Compiler to use # Compiler to use
CC=clang CC=clang
#CC=gcca #CC=gcc
#CC=mips-openwrt-linux-uclibc-gcc #CC=mips-openwrt-linux-uclibc-gcc
#LD=mips-openwrt-linux-uclibc-ld #LD=mips-openwrt-linux-uclibc-ld
#AR=mips-openwrt-linux-uclibc-ar #AR=mips-openwrt-linux-uclibc-ar

View File

@ -11,7 +11,7 @@ ifndef ARCH
endif endif
LDFLAGS+=-g -D_REENTRANT -L/usr/local/lib -L../capwap/$(ARCH) LDFLAGS+=-g -D_REENTRANT -L/usr/local/lib -L../capwap/$(ARCH)
CFLAGS += -Wall -g -O0 -D_REENTRANT -DIPV6 -I/usr/local/include -I../capwap CFLAGS += -Wall -g -O0 -D_REENTRANT -DIPV6 -I/usr/local/include -I../
LIBS+=-lcapwap LIBS+=-lcapwap

View File

@ -3,11 +3,11 @@
#include "ac.h" #include "ac.h"
#include "conf.h" #include "conf.h"
#include "capwap.h" #include "capwap/capwap.h"
#include "capwap_items.h" #include "capwap/capwap_items.h"
#include "aciplist.h" #include "capwap/aciplist.h"
#include "socklist.h" #include "socklist.h"
#include "sock.h" #include "capwap/sock.h"
struct cw_ac_status ac_status; struct cw_ac_status ac_status;
@ -93,11 +93,14 @@ int ac_global_init()
ac_status.dtls_policy = CW_FLAG_DTLS_POLICY_C | CW_FLAG_DTLS_POLICY_D; ac_status.dtls_policy = CW_FLAG_DTLS_POLICY_C | CW_FLAG_DTLS_POLICY_D;
cw_itemstore_set_version(ac_config, CW_ITEM_AC_HARDWARE_VERSION, 0, cw_itemstore_set_vendorstr(ac_config, CW_ITEM_AC_HARDWARE_VERSION, 0,
bstr_data(conf_hardware_version), bstr_len(conf_hardware_version)); bstr_data(conf_hardware_version), bstr_len(conf_hardware_version));
cw_itemstore_set_version(ac_config, CW_ITEM_AC_SOFTWARE_VERSION, 0, cw_itemstore_set_vendorstr(ac_config, CW_ITEM_AC_SOFTWARE_VERSION, 0,
bstr_data(conf_software_version), bstr_len(conf_software_version)); bstr_data(conf_software_version), bstr_len(conf_software_version));
cw_itemstore_set_str(ac_config,CW_ITEM_AC_IMAGE_DIR,conf_image_dir);
// cw_itemstore_set_avltree(ac_config, CW_ITEM_AC_IP_LIST, aciplist); // cw_itemstore_set_avltree(ac_config, CW_ITEM_AC_IP_LIST, aciplist);

View File

@ -4,15 +4,15 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#include "sock.h" #include "capwap/sock.h"
#include "socklist.h" #include "socklist.h"
#include "acinfo.h" #include "capwap/acinfo.h"
#include "conf.h" #include "conf.h"
#include "capwap.h" #include "capwap/capwap.h"
#include "capwap_80211.h" #include "capwap/capwap_80211.h"
#include "aciplist.h" #include "capwap/aciplist.h"

View File

@ -27,18 +27,19 @@
#include "actube.h" #include "actube.h"
#include "wtplist.h" #include "wtplist.h"
#include "dtls.h" #include "capwap/dtls.h"
#include "cw_log.h" #include "capwap/cw_log.h"
#include "conf.h" #include "conf.h"
#include "sock.h" #include "capwap/sock.h"
#include "socklist.h" #include "socklist.h"
#include "db.h" #include "db.h"
#include "capwap_items.h" #include "capwap/capwap_items.h"
#include "capwap_cisco.h" #include "capwap/capwap_cisco.h"
#include "ac.h" #include "ac.h"
#include "capwap/format.h"
int ac_run(); int ac_run();
@ -50,7 +51,7 @@ void alive_thread(void *data)
} }
} }
#include "action.h" #include "capwap/action.h"
/* /*
@ -98,20 +99,13 @@ int readelem_cisco_rad_name(struct conn *conn,struct cw_action * a,uint8_t *data
*/ */
/* #include "capwap/capwap_crypto.h"
int avlprint(void *priv, void *data)
{
struct cw_str * d = (struct cw_str*) data;
printf("String: %d - %s\n",d->id,d->str);
}
*/
int main (int argc, const char * argv[]) int main (int argc, const char * argv[])
{ {
cw_log_name="AC-Tube"; cw_log_name="AC-Tube";
read_config("ac.conf"); read_config("ac.conf");

View File

@ -21,13 +21,13 @@
#include <confuse.h> #include <confuse.h>
#include "capwap.h" #include "capwap/capwap.h"
#include "sock.h" #include "capwap/sock.h"
#include "conf.h" #include "conf.h"
#include "cw_log.h" #include "capwap/cw_log.h"
#include "cw_util.h" #include "capwap/cw_util.h"
uint8_t conf_macaddress[12]; uint8_t conf_macaddress[12];
uint8_t conf_macaddress_len=0; uint8_t conf_macaddress_len=0;
@ -391,7 +391,7 @@ static char * conf_default_mcast_groups_ipv6[] = {
#endif #endif
//#include "avltree" //#include "avltree"
#include "stravltree.h" #include "capwap/stravltree.h"
@ -568,6 +568,12 @@ int read_config(const char * filename){
if (!init_control_port()) if (!init_control_port())
return 0; return 0;
cfg_opt_t opts[] = { cfg_opt_t opts[] = {
CFG_STR_LIST("dbg", "{}", CFGF_NONE), CFG_STR_LIST("dbg", "{}", CFGF_NONE),
CFG_STR_LIST("listen", "{}", CFGF_NONE), CFG_STR_LIST("listen", "{}", CFGF_NONE),

View File

@ -26,9 +26,9 @@
#include <net/if.h> #include <net/if.h>
#include "capwap.h" #include "capwap/capwap.h"
#include "lwapp.h" #include "capwap/lwapp.h"
#include "bstr.h" #include "capwap/bstr.h"
#ifndef CONF_DEFAULT_ACNAME #ifndef CONF_DEFAULT_ACNAME
#define CONF_DEFAULT_ACNAME "AC" #define CONF_DEFAULT_ACNAME "AC"

View File

@ -1,7 +1,7 @@
#include <sqlite3.h> #include <sqlite3.h>
#include "cw_log.h" #include "capwap/cw_log.h"
#include "conf.h" #include "conf.h"

View File

@ -25,8 +25,8 @@
#include <pthread.h> #include <pthread.h>
#include "cw_log.h" #include "capwap/cw_log.h"
#include "sock.h" #include "capwap/sock.h"
#include "socklist.h" #include "socklist.h"

View File

@ -30,12 +30,12 @@
#include <stdio.h> #include <stdio.h>
#include "wtplist.h" #include "wtplist.h"
#include "conn.h" #include "capwap/conn.h"
#include "sock.h" #include "capwap/sock.h"
#include "conf.h" #include "conf.h"
#include "cw_log.h" #include "capwap/cw_log.h"
/* /*
static struct wtpman ** wtplist = 0; static struct wtpman ** wtplist = 0;

File diff suppressed because it is too large Load Diff

View File

@ -5,8 +5,8 @@
#include <semaphore.h> #include <semaphore.h>
#include <pthread.h> #include <pthread.h>
#include "capwap.h" #include "capwap/capwap.h"
#include "fragman.h" #include "capwap/fragman.h"
#define WTPMAN_QSIZE 1024 #define WTPMAN_QSIZE 1024

View File

@ -98,7 +98,6 @@ CAPWAPOBJS= \
cwmsg_addelem_ac_descriptor.o \ cwmsg_addelem_ac_descriptor.o \
cwmsg_addelem_wtp_descriptor.o \ cwmsg_addelem_wtp_descriptor.o \
cwmsg_addelem_wtp_radio_infos.o \ cwmsg_addelem_wtp_radio_infos.o \
cwmsg_addelem_wtp_board_data.o \
cwmsg_addelem_cw_local_ip_addr.o \ cwmsg_addelem_cw_local_ip_addr.o \
cwmsg_addelem_mtu_discovery_padding.o \ cwmsg_addelem_mtu_discovery_padding.o \
cwmsg_addelem_ac_timestamp.o \ cwmsg_addelem_ac_timestamp.o \
@ -121,11 +120,9 @@ CAPWAPOBJS= \
cw_handle_echo_request.o \ cw_handle_echo_request.o \
cwsend_conf_status_response.o\ cwsend_conf_status_response.o\
cwread_configuration_status_request.o\ cwread_configuration_status_request.o\
cwread_discovery_request.o\
cwread_change_state_event_request.o\ cwread_change_state_event_request.o\
cwread_wtp_event_request.o \ cwread_wtp_event_request.o \
process_conf_status_request.o \ process_conf_status_request.o \
wtpinfo_readelem_wtp_board_data.o \
wtpinfo_readelem_wtp_mac_type.o \ wtpinfo_readelem_wtp_mac_type.o \
wtpinfo_readelem_wtp_radio_info.o \ wtpinfo_readelem_wtp_radio_info.o \
cw_readelem_80211_wtp_radio_info.o \ cw_readelem_80211_wtp_radio_info.o \
@ -172,20 +169,27 @@ CAPWAPOBJS= \
cw_in_wtp_board_data.o \ cw_in_wtp_board_data.o \
cw_in_check_disc_req.o \ cw_in_check_disc_req.o \
cw_in_check_join_req.o \ cw_in_check_join_req.o \
cw_in_check_img_data_req.o \
cw_out_generic.o \ cw_out_generic.o \
cw_out_ac_descriptor.o \ cw_out_ac_descriptor.o \
cw_out_cisco_ac_descriptor.o \ cw_out_cisco_ac_descriptor.o \
cw_out_cisco_ap_timesync.o \ cw_out_cisco_ap_timesync.o \
cw_in_cisco_image_identifier.o\
cw_out_capwap_control_ip_addrs.o \ cw_out_capwap_control_ip_addrs.o \
strheap.o \ strheap.o \
cw_check_missing_mand.o \ cw_check_missing_mand.o \
dbg.o dbg.o \
md5sum.o \
format.o
#cw_in_wtp_name.o \ #cw_in_wtp_name.o \
#cw_msgtostr.o \ #cw_msgtostr.o \
#cw_msgelemtostr.o \ #cw_msgelemtostr.o \
#cwmsg_addelem_ctrl_ip_addrs.o \ #cwmsg_addelem_ctrl_ip_addrs.o \
#process_join_request.o \ #process_join_request.o \
#cwmsg_addelem_wtp_board_data.o \
#wtpinfo_readelem_wtp_board_data.o \
#cw_ianavendoridtostr.o \ #cw_ianavendoridtostr.o \
#cwmsg_addelem_result_code.o \ #cwmsg_addelem_result_code.o \
@ -202,6 +206,7 @@ CAPWAPOBJS= \
# cwmsg_set_control_header.o # cwmsg_set_control_header.o
# process_msgelems.o \ # process_msgelems.o \
# cwsend_join_response.o \ # cwsend_join_response.o \
# cwread_discovery_request.o\
# #
# SSL objects # SSL objects
@ -243,7 +248,6 @@ CONNOBJS= conn_create.o \
connlist.o \ connlist.o \
conn_create_noq.o \ conn_create_noq.o \
conn_send_response.o \ conn_send_response.o \
conn_get_message.o \
conn_get_response.o \ conn_get_response.o \
conn_prepare_configuration_update_request.o \ conn_prepare_configuration_update_request.o \
cw_prepare_configuration_status_request.o \ cw_prepare_configuration_status_request.o \
@ -255,6 +259,7 @@ CONNOBJS= conn_create.o \
conn_wait_for_request.o \ conn_wait_for_request.o \
conn_init.o \ conn_init.o \
conn_send_msg.o conn_send_msg.o
#conn_get_message.o \
@ -269,8 +274,10 @@ FRAGOBJS=fragman.o
CWACTION=action.o \ CWACTION=action.o \
cw_process_msg.o \ cw_process_msg.o \
capwap_actions_ac.o \ capwap_actions_ac.o \
capwap_actions_wtp.o \
cw_in_generic.o \ cw_in_generic.o \
cw_in_wtp_descriptor.o \ cw_in_wtp_descriptor.o \
cw_out_wtp_board_data.o \
cipwap_actions_ac.o \ cipwap_actions_ac.o \
cipwap_strings_elem.o \ cipwap_strings_elem.o \
cw_put_msg.o \ cw_put_msg.o \
@ -291,7 +298,7 @@ O:=$(OBJS);
OBJS:=$(patsubst %.o,$(ARCH)/%.o,$(OBJS)) OBJS:=$(patsubst %.o,$(ARCH)/%.o,$(OBJS))
CFLAGS = -Wall -g -O0 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I /usr/local/include CFLAGS = -Wall -g -O0 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I /usr/local/include
#CFLAGS += -Wall -g -O0 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I/usr/local/include CFLAGS = -Wall -O3 -D_REENTRANT -DWITH_IPV6 -DWITH_RMAC_SUPPORT -I/usr/local/include
CFLAGS += $(GNUTLS_CFLAGS) \ CFLAGS += $(GNUTLS_CFLAGS) \
-DWITH_CW_LOG \ -DWITH_CW_LOG \

View File

@ -27,30 +27,30 @@
#include "action.h" #include "action.h"
static inline int cw_action_in_cmp(const void *elem1,const void *elem2) static inline int cw_action_in_cmp(const void *elem1, const void *elem2)
{ {
struct cw_action_in * e1 = (struct cw_action_in*)elem1; struct cw_action_in *e1 = (struct cw_action_in *) elem1;
struct cw_action_in * e2 = (struct cw_action_in*)elem2; struct cw_action_in *e2 = (struct cw_action_in *) elem2;
int r; int r;
r = e1->msg_id - e2->msg_id; r = e1->msg_id - e2->msg_id;
if (r!=0) if (r != 0)
return r;
r = e1->capwap_state - e2->capwap_state;
if (r!=0)
return r; return r;
r = e1->elem_id - e2->elem_id; r = e1->elem_id - e2->elem_id;
if (r!=0) if (r != 0)
return r;
r = e1->capwap_state - e2->capwap_state;
if (r != 0)
return r; return r;
r = e1->vendor_id - e2->vendor_id; r = e1->vendor_id - e2->vendor_id;
if (r!=0) if (r != 0)
return r; return r;
r = e1->proto - e2->proto; r = e1->proto - e2->proto;
if (r!=0) if (r != 0)
return r; return r;
@ -59,40 +59,40 @@ static inline int cw_action_in_cmp(const void *elem1,const void *elem2)
} }
cw_action_in_t * cw_actionlist_in_add(cw_actionlist_in_t t, struct cw_action_in * a) cw_action_in_t *cw_actionlist_in_add(cw_actionlist_in_t t, struct cw_action_in * a)
{ {
return cw_actionlist_add(t,a,sizeof(struct cw_action_in)); return cw_actionlist_add(t, a, sizeof(struct cw_action_in));
} }
struct cw_action_in * cw_actionlist_in_get(cw_actionlist_in_t t,struct cw_action_in *a) struct cw_action_in *cw_actionlist_in_get(cw_actionlist_in_t t, struct cw_action_in *a)
{ {
return avltree_get(t,a); return avltree_get(t, a);
} }
cw_actionlist_in_t cw_actionlist_in_create() cw_actionlist_in_t cw_actionlist_in_create()
{ {
return avltree_create(cw_action_in_cmp,free); return avltree_create(cw_action_in_cmp, free);
} }
int cw_actionlist_in_register_actions(cw_actionlist_in_t t,cw_action_in_t * actions) int cw_actionlist_in_register_actions(cw_actionlist_in_t t, cw_action_in_t * actions)
{ {
while(actions->capwap_state){ while (actions->capwap_state) {
cw_action_in_t * rc = cw_actionlist_in_add(t,actions); cw_action_in_t *rc = cw_actionlist_in_add(t, actions);
if (rc==0) if (rc == 0)
return 0; return 0;
actions++; actions++;
} }
return 1; return 1;
} }
int cw_actionlist_out_register_actions(cw_actionlist_out_t t,cw_action_out_t * actions) int cw_actionlist_out_register_actions(cw_actionlist_out_t t, cw_action_out_t * actions)
{ {
while(actions->msg_id!=0){ while (actions->msg_id != 0) {
cw_action_out_t * rc = cw_actionlist_out_add(t,actions); cw_action_out_t *rc = cw_actionlist_out_add(t, actions);
if (rc==0) if (rc == 0)
return 0; return 0;
actions++; actions++;
} }
@ -105,22 +105,22 @@ int cw_actionlist_out_register_actions(cw_actionlist_out_t t,cw_action_out_t * a
/* /*
* Compare function for actionlist_out_t lists * Compare function for actionlist_out_t lists
*/ */
static int cw_action_out_cmp(const void *elem1,const void *elem2) static int cw_action_out_cmp(const void *elem1, const void *elem2)
{ {
struct cw_action_out * e1 = (struct cw_action_out*)elem1; struct cw_action_out *e1 = (struct cw_action_out *) elem1;
struct cw_action_out * e2 = (struct cw_action_out*)elem2; struct cw_action_out *e2 = (struct cw_action_out *) elem2;
int r; int r;
r = e1->msg_id - e2->msg_id; r = e1->msg_id - e2->msg_id;
if (r!=0) if (r != 0)
return r; return r;
r = e1->item_id - e2->item_id; r = e1->item_id - e2->item_id;
if (r!=0) if (r != 0)
return r; return r;
r = e1->vendor_id - e2->vendor_id; r = e1->vendor_id - e2->vendor_id;
if (r!=0) if (r != 0)
return r; return r;
return 0; return 0;
@ -135,9 +135,9 @@ static int cw_action_out_cmp(const void *elem1,const void *elem2)
* @param s size of element to add * @param s size of element to add
* @return pointer to added element or NULL if an error has opccured * @return pointer to added element or NULL if an error has opccured
*/ */
void * cw_actionlist_add(struct avltree *t, void *a, size_t s) void *cw_actionlist_add(struct avltree *t, void *a, size_t s)
{ {
void * r = avltree_replace_data(t,a,sizeof(struct cw_action_in)); void *r = avltree_replace_data(t, a, sizeof(struct cw_action_in));
if (r) if (r)
return r; return r;
@ -145,8 +145,8 @@ void * cw_actionlist_add(struct avltree *t, void *a, size_t s)
if (!an) if (!an)
return NULL; return NULL;
memcpy(an,a,s); memcpy(an, a, s);
return avltree_add(t,an); return avltree_add(t, an);
} }
@ -157,16 +157,35 @@ void * cw_actionlist_add(struct avltree *t, void *a, size_t s)
*/ */
cw_actionlist_out_t cw_actionlist_out_create() cw_actionlist_out_t cw_actionlist_out_create()
{ {
return avltree_create(cw_action_out_cmp,free); return avltree_create(cw_action_out_cmp, free);
} }
cw_action_out_t * cw_actionlist_out_add(cw_actionlist_out_t t, struct cw_action_out * a) cw_action_out_t *cw_actionlist_out_add(cw_actionlist_out_t t, struct cw_action_out * a)
{ {
return cw_actionlist_add(t,a,sizeof (struct cw_action_out)); return cw_actionlist_add(t, a, sizeof(struct cw_action_out));
} }
cw_action_in_t *cw_actionlist_in_set_msg_end_callback(cw_actionlist_in_t a,
uint8_t capwap_state,
uint32_t msg_id,
int (*fun) (struct conn * conn,
struct cw_action_in * a, uint8_t * data,
int len))
{
cw_action_in_t as,*ar;
as.vendor_id=0;
as.proto=0;
as.elem_id=-1;
as.msg_id=msg_id;
as.capwap_state=capwap_state;
ar = cw_actionlist_in_get(a,&as);
if (!ar)
return NULL;
ar->end=fun;
return ar;
}

View File

@ -46,6 +46,7 @@ struct cw_action_in{
uint16_t item_id; uint16_t item_id;
uint16_t min_len; uint16_t min_len;
uint16_t max_len; uint16_t max_len;
uint8_t mand;
}; };
@ -58,6 +59,12 @@ extern cw_actionlist_in_t cw_actionlist_in_create();
extern cw_action_in_t * cw_actionlist_in_get(cw_actionlist_in_t t,cw_action_in_t *a); extern cw_action_in_t * cw_actionlist_in_get(cw_actionlist_in_t t,cw_action_in_t *a);
extern cw_action_in_t * cw_actionlist_in_add(cw_actionlist_in_t t,cw_action_in_t *a); extern cw_action_in_t * cw_actionlist_in_add(cw_actionlist_in_t t,cw_action_in_t *a);
extern int cw_actionlist_in_register_actions(cw_actionlist_in_t t,cw_action_in_t * actions); extern int cw_actionlist_in_register_actions(cw_actionlist_in_t t,cw_action_in_t * actions);
extern cw_action_in_t *cw_actionlist_in_set_msg_end_callback(cw_actionlist_in_t a,
uint8_t capwap_state,
uint32_t msg_id,
int (*fun) (struct conn * conn,
struct cw_action_in * a, uint8_t * data,
int len));
/* Definitions for outgoing messages */ /* Definitions for outgoing messages */
@ -69,9 +76,12 @@ struct cw_action_out{
int (*out)(struct conn * conn, struct cw_action_out *a, uint8_t * dst); int (*out)(struct conn * conn, struct cw_action_out *a, uint8_t * dst);
struct cw_item *(*get)(struct conn *conn,struct cw_action_out *a); struct cw_item *(*get)(struct conn *conn,struct cw_action_out *a);
uint8_t mand;
uint8_t itemtype;
void *defval;
}; };
typedef struct cw_action_out cw_action_out_t; typedef struct cw_action_out cw_action_out_t;
typedef struct avltree *cw_actionlist_out_t; typedef struct avltree *cw_actionlist_out_t;

View File

@ -91,6 +91,7 @@ static inline void avltree_destroy(struct avltree *t)
} }
#define avltree_find(t,d) avltree_get(t,d) #define avltree_find(t,d) avltree_get(t,d)
#define avltree_insert(t,d) avltree_add(t,d) #define avltree_insert(t,d) avltree_add(t,d)
//#define avltree_walk(t,dir) avltree_foreach(t,dir) //#define avltree_walk(t,dir) avltree_foreach(t,dir)

View File

@ -24,6 +24,7 @@
#ifndef __BSTR_H #ifndef __BSTR_H
#define __BSTR_H #define __BSTR_H
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdint.h> #include <stdint.h>
@ -46,7 +47,7 @@ extern int bstr_to_str(char *dst, bstr_t str,char * def);
/** /**
* Return the length of a bstr_t string. * Return the length of a bstr_t string.
*/ */
#define bstr_len(s) (*(s)) #define bstr_len(s) (*((uint8_t*)(s)))
/** /**
* Return the data of a bstr_t string. * Return the data of a bstr_t string.
@ -77,6 +78,53 @@ static inline int bstr16_ncpy(uint8_t *dst,uint8_t*src,uint16_t len)
return len+2; return len+2;
} }
static inline uint8_t * bstr16_create(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;
}
#define vendorstr_get_vendor_id(str)\
( *((uint32_t*)((str)+2)))
#define vendorstr_set_vendor_id(str,id)\
( *((uint32_t*)((str)+2)) = id)
#define vendorstr_len(str)\
(*((uint16_t*)((str)+0)))
#define vendorstr_set_len(str,len)\
(*((uint16_t*)((str)+0))=len)
#define vendorstr_data(str)\
(((uint8_t*)(str))+6)
#define vendorstr_size(n)\
(1+6+(len)*sizeof(uint8_t))
static inline uint8_t * vendorstr_create(uint32_t vendor_id, uint8_t *data, uint8_t len)
{
uint8_t * str = malloc(vendorstr_size(len));
if (!str)
return 0;
vendorstr_set_vendor_id(str,vendor_id);
vendorstr_set_len(str,len);
memcpy(vendorstr_data(str),data,len);
*(vendorstr_data(str)+vendorstr_len(str))=0;
return str;
}
#endif #endif

View File

@ -36,7 +36,7 @@
*/ */
uint8_t * bstr_create(uint8_t *data, uint8_t len) uint8_t * bstr_create(uint8_t *data, uint8_t len)
{ {
uint8_t * str = malloc(len*sizeof(uint8_t)); uint8_t * str = malloc(1+len*sizeof(uint8_t));
if (!str) if (!str)
return 0; return 0;
*str=len; *str=len;

View File

@ -65,7 +65,7 @@ enum capwap_states {
CW_STATE_DISCOVERY, CW_STATE_DISCOVERY,
CW_STATE_JOIN, CW_STATE_JOIN,
CW_STATE_CONFIGURE, CW_STATE_CONFIGURE,
CW_STATE_IMAGE, CW_STATE_IMAGE_DATA,
CW_STATE_UPDATE, CW_STATE_UPDATE,
CW_STATE_RUN CW_STATE_RUN
}; };
@ -227,7 +227,7 @@ struct capwap_ctrlhdr
#define CW_ELEM_WTP_NAME 45 #define CW_ELEM_WTP_NAME 45
#define CW_ELEM_RESERVED_46 46 #define CW_ELEM_RESERVED_46 46
#define CW_ELEM_WTP_RADIO_STATISTICS 47 #define CW_ELEM_WTP_RADIO_STATISTICS 47
#define CWMSGELEM_WTP_REBOOT_STATISTICS 48 #define CW_ELEM_WTP_REBOOT_STATISTICS 48
#define CW_ELEM_WTP_STATIC_IP_ADDRESS_INFORMATION 49 #define CW_ELEM_WTP_STATIC_IP_ADDRESS_INFORMATION 49
#define CW_ELEM_WTP_STATIC_IP_ADDR_INFO 49 #define CW_ELEM_WTP_STATIC_IP_ADDR_INFO 49
@ -247,11 +247,11 @@ struct capwap_ctrlhdr
/* wtp board data subelements */ /* wtp board data subelements */
#define CWBOARDDATA_MODELNO 0 #define CW_BOARDDATA_MODELNO 0
#define CWBOARDDATA_SERIALNO 1 #define CW_BOARDDATA_SERIALNO 1
#define CWBOARDDATA_BOARDID 2 #define CW_BOARDDATA_BOARDID 2
#define CWBOARDDATA_REVISION 3 #define CW_BOARDDATA_REVISION 3
#define CWBOARDDATA_MACADDRESS 4 #define CW_BOARDDATA_MACADDRESS 4
/* AC Security flags for authentication */ /* AC Security flags for authentication */
@ -397,7 +397,7 @@ extern void cwsend_join_response(struct conn *conn, int seqnum, int rc,
struct wtpinfo *wtpinfo); struct wtpinfo *wtpinfo);
extern void cwread_discovery_request(struct wtpinfo *wtpinfo, uint8_t * msg, int len); //extern void cwread_discovery_request(struct wtpinfo *wtpinfo, uint8_t * msg, int len);
extern void process_join_request(struct wtpinfo *wtpinfo, uint8_t * msg, int len); extern void process_join_request(struct wtpinfo *wtpinfo, uint8_t * msg, int len);
extern void process_conf_status_request(struct wtpinfo *wtpinfo, uint8_t * msg, int len); extern void process_conf_status_request(struct wtpinfo *wtpinfo, uint8_t * msg, int len);
@ -477,18 +477,18 @@ extern int cw_readelem_vendor_specific_payload(void *data, int msgtype, int elem
14 Image Data Error (Invalid Checksum) 14 Image Data Error (Invalid Checksum)
15 Image Data Error (Invalid Data Length) */
#define CW_RESULT_IMAGE_DATA_IVALID_LENGTH 15 //Image Data Error (Invalid Data Length)
16 Image Data Error (Other Error)
#define CW_RESULT_IMAGE_DATA_OTHER_ERROR 16 //Image Data Error (Other Error)
/*
17 Image Data Error (Image Already Present) 17 Image Data Error (Image Already Present)
18 Message Unexpected (Invalid in Current State)
19 Message Unexpected (Unrecognized Request)
*/ */
#define CW_RESULT_MSG_INVALID_IN_CURRENT_STATE 18
#define CW_RESULT_MSG_UNRECOGNIZED 19
#define CW_RESULT_MISSING_MAND_ELEM 20 #define CW_RESULT_MISSING_MAND_ELEM 20
/* /*
21 Failure - Unrecognized Message Element 21 Failure - Unrecognized Message Element
@ -579,6 +579,33 @@ static inline void cw_set_hdr_hlen(uint8_t *th,int hlen){
cw_set_dword(th,d); cw_set_dword(th,d);
} }
/**
* Set the WBID field of a CAWAP Header
* @param th pointer to the header
* @param hlen velue to set (max. 5 bits)
*/
static inline void cw_set_hdr_wbid(uint8_t *th,int wbid){
uint32_t d = cw_get_dword(th);
d &= (0x1f << 9) ^ 0xffffffff;
d |= ((wbid) & 0x1f) <<9;
cw_set_dword(th,d);
}
/**
* Set the RID field of a CAWAP Header
* @param th pointer to the header
* @param hlen velue to set (max. 5 bits)
*/
static inline void cw_set_hdr_rid(uint8_t *th,int rid){
uint32_t d = cw_get_dword(th);
d &= (0x1f << 9) ^ 0xffffffff;
d |= ((rid) & 0x1f) <<14;
cw_set_dword(th,d);
}
/** /**
* Set CAPWAP header flags * Set CAPWAP header flags
* @param th pointer to header * @param th pointer to header
@ -718,7 +745,7 @@ static inline int cw_addelem_bstr(uint8_t * dst, uint16_t type, const bstr_t bst
} }
static inline int cw_addelem_result_code(uint8_t * dst, uint32_t code) static inline int cw_put_elem_result_code(uint8_t * dst, uint32_t code)
{ {
cw_put_dword(dst + 4, code); cw_put_dword(dst + 4, code);
return 4 + cw_put_elem_hdr(dst, CW_ELEM_RESULT_CODE, 4); return 4 + cw_put_elem_hdr(dst, CW_ELEM_RESULT_CODE, 4);
@ -778,6 +805,12 @@ extern int cw_send_configuration_update_response(struct conn *conn, int seqnum,
/* cwmsg methods */ /* cwmsg methods */
static inline int cw_addelem_result_code(uint8_t * dst, uint32_t code)
{
cw_put_dword(dst + 4, code);
return 4 + cw_put_elem_hdr(dst, CW_ELEM_RESULT_CODE, 4);
}
#define cwmsg_addelem_vendor_specific_payload(cwmsg,vendor_id, type, data,len) \ #define cwmsg_addelem_vendor_specific_payload(cwmsg,vendor_id, type, data,len) \
(cwmsg)->pos+=cw_addelem_vendor_specific_payload((cwmsg)->msgelems+(cwmsg)->pos,vendor_id,type,data,len) (cwmsg)->pos+=cw_addelem_vendor_specific_payload((cwmsg)->msgelems+(cwmsg)->pos,vendor_id,type,data,len)
@ -811,7 +844,14 @@ extern struct cw_str capwap_strings_elem[];
#define cw_strvendor(id) cw_strlist_get_str(capwap_strings_vendor,id) #define cw_strvendor(id) cw_strlist_get_str(capwap_strings_vendor,id)
#define cw_strelemp(p,id) cw_strheap_get((p)->strelem,id) static inline const char * cw_strelemp_(cw_strheap_t h, int msg_id) {
const char * rc = cw_strheap_get(h,msg_id);
if (rc)
return rc;
return cw_strheap_get(h,0);
}
#define cw_strelemp(p,id) cw_strelemp_((p)->strelem,id)
extern const char *cw_strlist_get_str(struct cw_str *s, int id); extern const char *cw_strlist_get_str(struct cw_str *s, int id);
@ -875,13 +915,12 @@ static inline int cw_put_ac_status(uint8_t *dst, struct cw_ac_status *s){
} }
static inline int cw_put_version(uint8_t *dst,uint16_t subelem_id, uint32_t vendor_id,bstr16_t data) static inline int cw_put_version(uint8_t *dst,uint16_t subelem_id, uint8_t *v)
{ {
uint8_t *d=dst; uint8_t *d=dst;
d += cw_put_dword(d,vendor_id); d += cw_put_dword(d,vendorstr_get_vendor_id(v));
d += cw_put_dword(d, (subelem_id<<16) | bstr16_len(data)); d += cw_put_dword(d, (subelem_id<<16) | vendorstr_len(v));
d += cw_put_data(d,bstr16_data(data),bstr16_len(data)); d += cw_put_data(d,vendorstr_data(v),vendorstr_len(v));
return d-dst; return d-dst;
} }
@ -889,9 +928,20 @@ static inline int cw_put_version(uint8_t *dst,uint16_t subelem_id, uint32_t vend
int cw_register_actions_capwap_ac(struct cw_actiondef *def); int cw_register_actions_capwap_ac(struct cw_actiondef *def);
int cw_register_actions_cipwap_ac(struct cw_actiondef *def); int cw_register_actions_cipwap_ac(struct cw_actiondef *def);
int cw_register_actions_capwap_wtp(struct cw_actiondef *def);
int cw_in_set_state_none(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len); int cw_in_set_state_none(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len);
struct cw_item *cw_out_get_local(struct conn *conn, struct cw_action_out *a); struct cw_item *cw_out_get_local(struct conn *conn, struct cw_action_out *a);
extern int cw_in_check_disc_req(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len);
int cw_check_missing_mand(cw_action_in_t ** out, struct conn * conn, cw_action_in_t *a);
int cw_in_check_join_req(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len);
int cw_in_check_img_data_req(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len);
int cw_out_wtp_board_data(struct conn *conn,struct cw_action_out * a,uint8_t *dst) ;
void cw_init_request(struct conn *conn,int msg_id);

View File

@ -46,6 +46,35 @@
CW_ITEM_SESSION_ID, /* ID to use store */ \ CW_ITEM_SESSION_ID, /* ID to use store */ \
16, 16 /* min/max length */ 16, 16 /* min/max length */
#define CW_ACTION_IN_IMAGE_IDENTIFIER \
CW_ELEM_IMAGE_IDENTIFIER, /* Element ID*/ \
cw_in_generic, 0, /* start/end callback */ \
CW_ITEMTYPE_VENDORSTR, /* Type of element */ \
CW_ITEM_IMAGE_IDENTIFIER, /* ID to use store */ \
5, 4096 /* min/max length */
#define CW_ACTION_IN_AC_NAME \
CW_ELEM_AC_NAME, /* Element ID*/ \
cw_in_generic, 0, /* start/end callback */ \
CW_ITEMTYPE_STR, /* Type of element */ \
CW_ITEM_AC_NAME, /* ID to use store */ \
1, 1024 /* min/max length */
#define CW_ACTION_IN_STATISTICS_TIMER \
CW_ELEM_STATISTICS_TIMER, /* Element ID*/ \
cw_in_generic, 0, /* start/end callback */ \
CW_ITEMTYPE_DWORD, /* Type of element */ \
CW_ITEM_STATISTICS_TIMER, /* ID to use store */ \
1, 1024 /* min/max length */
#define CW_ACTION_IN_WTP_REBOOT_STATISTICS \
CW_ELEM_WTP_REBOOT_STATISTICS, /* Element ID*/ \
cw_in_generic, 0, /* start/end callback */ \
CW_ITEMTYPE_DATA, /* Type of element */ \
CW_ITEM_WTP_REBOOT_STATISTICS, /* ID to use store */ \
15, 15 /* min/max length */
#define CW_ACTION_IN_WTP_FRAME_TUNNEL_MODE \ #define CW_ACTION_IN_WTP_FRAME_TUNNEL_MODE \
CW_ELEM_WTP_FRAME_TUNNEL_MODE, /* Element ID*/ \ CW_ELEM_WTP_FRAME_TUNNEL_MODE, /* Element ID*/ \
cw_in_generic, 0, /* start/end callback */ \ cw_in_generic, 0, /* start/end callback */ \
@ -63,16 +92,24 @@
#define CW_ACTION_IN_VENDOR_SPECIFIC_PAYLOAD \ #define CW_ACTION_IN_VENDOR_SPECIFIC_PAYLOAD \
CW_ELEM_VENDOR_SPECIFIC_PAYLOAD, /* Element ID */ \ CW_ELEM_VENDOR_SPECIFIC_PAYLOAD, /* Element ID */ \
cw_in_vendor_specific_payload, 0 /* start/end callback*/ \ cw_in_vendor_specific_payload,0, /* start/end callback*/ \
0, \
0, \
0,0
#define CW_ACTION_IN_WTP_BOARD_DATA \ #define CW_ACTION_IN_WTP_BOARD_DATA \
CW_ELEM_WTP_BOARD_DATA, /* Element ID */ \ CW_ELEM_WTP_BOARD_DATA, /* Element ID */ \
cw_in_wtp_board_data, 0 /* start/end callback */ \ cw_in_wtp_board_data, 0, /* start/end callback */ \
0, \
CW_ITEM_WTP_BOARD_DATA, \
0,0
#define CW_ACTION_IN_WTP_DESCRIPTOR \ #define CW_ACTION_IN_WTP_DESCRIPTOR \
CW_ELEM_WTP_DESCRIPTOR, /* Element ID */ \ CW_ELEM_WTP_DESCRIPTOR, /* Element ID */ \
cw_in_wtp_descriptor, 0 /* start/end callback */ \ cw_in_wtp_descriptor, 0, /* start/end callback */ \
0, \
CW_ITEM_WTP_DESCRIPTOR, \
0,0
#endif #endif

View File

@ -28,117 +28,127 @@
cw_action_in_t capwap_actions_ac_in[] = { cw_action_in_t capwap_actions_ac_in[] = {
/* -------------------------------------------------------------------------------*/ /* ------------------------------------------------------------------------------- */
/* Message Discovery Request */ /* Message Discovery Request */
{0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, -1, {0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, 0,
0, cw_in_set_state_none} 0, cw_in_check_disc_req}
, ,
/* Element Discovery Type */ /* Element Discovery Type */
{0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ELEM_DISCOVERY_TYPE, {0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ELEM_DISCOVERY_TYPE,
cw_in_generic, 0, CW_ITEMTYPE_BYTE, CW_ITEM_DISCOVERY_TYPE, 1, 1} cw_in_generic, 0, CW_ITEMTYPE_BYTE, CW_ITEM_DISCOVERY_TYPE, 1, 1, 1}
, ,
/* Element WTP Board Data */ /* Element WTP Board Data */
{0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ACTION_IN_WTP_BOARD_DATA } {0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ACTION_IN_WTP_BOARD_DATA,
1}
, ,
/* Element WTP Descriptor */ /* Element WTP Descriptor */
{0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ACTION_IN_WTP_DESCRIPTOR } {0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ACTION_IN_WTP_DESCRIPTOR,
1}
, ,
/* Element Frame Tunnel Mode */ /* Element Frame Tunnel Mode */
{0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ACTION_IN_WTP_FRAME_TUNNEL_MODE} {0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST,
CW_ACTION_IN_WTP_FRAME_TUNNEL_MODE, 1}
, ,
/* Element WTP Mac Tpe */ /* Element WTP Mac Tpe */
{0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ACTION_IN_WTP_MAC_TYPE} {0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ACTION_IN_WTP_MAC_TYPE, 1}
, ,
/* Vendor Specific Payload */ /* Vendor Specific Payload */
{0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_ACTION_IN_VENDOR_SPECIFIC_PAYLOAD} {0, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST,
CW_ACTION_IN_VENDOR_SPECIFIC_PAYLOAD}
, ,
/* -------------------------------------------------------------------------------*/ /* ------------------------------------------------------------------------------- */
/* Message: Join Request */ /* Message: Join Request */
{0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, -1, {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, 0,
0, 0} 0, cw_in_check_join_req}
, ,
/* Element Location Data */ /* Element Location Data */
{0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_LOCATION_DATA} {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_LOCATION_DATA, 1}
, ,
/* Element WTP Board Data */ /* Element WTP Board Data */
{0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_WTP_BOARD_DATA} {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_WTP_BOARD_DATA, 1}
, ,
/* Element WTP Board Data */ /* Element WTP Board Data */
{0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_WTP_DESCRIPTOR} {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_WTP_DESCRIPTOR, 1}
, ,
/* Element WTP Board Data */ /* Element WTP Board Data */
{0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_WTP_NAME} {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_WTP_NAME, 1}
, ,
/* Element WTP Board Data */ /* Element WTP Board Data */
{0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_SESSION_ID} {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_SESSION_ID, 1}
, ,
/* Element WTP Board Data */ /* Element WTP Board Data */
{0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_WTP_FRAME_TUNNEL_MODE} {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_WTP_FRAME_TUNNEL_MODE, 1}
, ,
/* Element WTP MAC Type */ /* Element WTP MAC Type */
{0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_WTP_MAC_TYPE} {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_WTP_MAC_TYPE, 1}
, ,
/* Element Vendor Specific Payload */ /* Element Vendor Specific Payload */
{0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_VENDOR_SPECIFIC_PAYLOAD} {0, 0, CW_STATE_JOIN, CW_MSG_JOIN_REQUEST, CW_ACTION_IN_VENDOR_SPECIFIC_PAYLOAD}
, ,
/* ------------------------------------------------------------------------------- */
/* Message: Configuration Status Request */
{0, 0, CW_STATE_CONFIGURE, CW_MSG_CONFIGURATION_STATUS_REQUEST, 0,
0, cw_in_check_join_req}
,
/* Element: AC Name */
{0, 0, CW_STATE_CONFIGURE, CW_MSG_CONFIGURATION_STATUS_REQUEST,
CW_ACTION_IN_AC_NAME, 1}
,
/* Element: Statistics Timer */
{0, 0, CW_STATE_CONFIGURE, CW_MSG_CONFIGURATION_STATUS_REQUEST,
CW_ACTION_IN_STATISTICS_TIMER, 1}
,
/* /* Element: Statistics Timer */
{0, 1, 1, CW_MSG_DISCOVERY_RESPONSE, 0, {0, 0, CW_STATE_CONFIGURE, CW_MSG_CONFIGURATION_STATUS_REQUEST,
0, 0} CW_ACTION_IN_WTP_REBOOT_STATISTICS, 1}
, ,
{0, 1, 1, CW_MSG_DISCOVERY_RESPONSE, CW_ELEM_AC_NAME, /* Element Vendor Specific Payload */
cw_out_generic, 0, CW_ITEMTYPE_DATA,CW_ITEM_AC_NAME} {0, 0, CW_STATE_CONFIGURE, CW_MSG_CONFIGURATION_STATUS_REQUEST,
CW_ACTION_IN_VENDOR_SPECIFIC_PAYLOAD}
, ,
{0, 1, 2, CW_MSG_DISCOVERY_RESPONSE, 0, /* Element WTP Board Data */
0, 0} {0, 0, CW_STATE_CONFIGURE, CW_MSG_DISCOVERY_REQUEST, CW_ACTION_IN_WTP_BOARD_DATA,
1}
, ,
*/ /* ------------------------------------------------------------------------------- */
/* Message: Image Data Request - in Config State */
/* {0, 0, CW_STATE_CONFIGURE, CW_MSG_IMAGE_DATA_REQUEST, 0,
{CW_VENDOR_ID_CISCO, 0, CW_STATE_DISCOVERY, CW_MSG_DISCOVERY_REQUEST, CW_CISCO_RAD_NAME, 0, cw_in_check_img_data_req}
cw_in_wtp_name, 0}
, ,
*/ {0, 0, CW_STATE_CONFIGURE, CW_MSG_IMAGE_DATA_REQUEST,
CW_ACTION_IN_IMAGE_IDENTIFIER,
0}
,
{0, 0, 0} {0, 0, 0}
}; };
/*
int cw_out_ac_name(uint8_t * dst, struct cw_item *item)
{
printf("Putting out the AC name %s\n", item->data);
uint8_t *data = item->data;
int len = cw_put_data(dst + 4, data, strlen((char *) data));
return len + cw_put_elem_hdr(dst, CW_ELEM_AC_NAME, len);
}
*/
cw_action_out_t capwap_actions_ac_out[] = { cw_action_out_t capwap_actions_ac_out[] = {
{CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_NONE} {CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_NONE}
, ,
/* AC Descriptor */ /* AC Descriptor */
{CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0 {CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0, CW_ELEM_AC_DESCRIPTOR,
,CW_ELEM_AC_DESCRIPTOR, cw_out_ac_descriptor, 0} cw_out_ac_descriptor, 0}
, ,
/* AC Name */ /* AC Name */
@ -160,17 +170,36 @@ cw_action_out_t capwap_actions_ac_out[] = {
/* Result Code */ /* Result Code */
{CW_MSG_JOIN_RESPONSE, CW_ITEM_RESULT_CODE, 0, {CW_MSG_JOIN_RESPONSE, CW_ITEM_RESULT_CODE, 0,
CW_ELEM_RESULT_CODE, cw_out_generic, cw_out_get_local} CW_ELEM_RESULT_CODE, cw_out_generic, cw_out_get_local, 1}
, ,
/* AC Descriptor */ /* AC Descriptor */
{CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0 {CW_MSG_JOIN_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0, CW_ELEM_AC_DESCRIPTOR,
,CW_ELEM_AC_DESCRIPTOR, cw_out_ac_descriptor, 0} cw_out_ac_descriptor, 0, 1}
,
/* AC Name */
{CW_MSG_JOIN_RESPONSE, CW_ITEM_AC_NAME, 0,
CW_ELEM_AC_NAME, cw_out_generic, cw_out_get_local}
, ,
/* -------------------------------------------------------------------------------
* Image Data Response OUT
*/
{CW_MSG_IMAGE_DATA_RESPONSE, CW_ITEM_NONE}
,
/* Result Code */
{CW_MSG_IMAGE_DATA_RESPONSE, CW_ITEM_RESULT_CODE, 0,
CW_ELEM_RESULT_CODE, cw_out_generic, cw_out_get_local, 1}
,
/* End of list */
{0, 0} {0, 0}
}; };
@ -190,12 +219,12 @@ int cw_register_actions_capwap_ac(struct cw_actiondef *def)
cw_actionlist_in_register_actions(def->in, capwap_actions_ac_in); cw_actionlist_in_register_actions(def->in, capwap_actions_ac_in);
cw_actionlist_out_register_actions(def->out, capwap_actions_ac_out); cw_actionlist_out_register_actions(def->out, capwap_actions_ac_out);
int rc ; int rc;
rc = cw_strheap_register_strings(def->strmsg,capwap_strings_msg); rc = cw_strheap_register_strings(def->strmsg, capwap_strings_msg);
rc += cw_strheap_register_strings(def->strelem,capwap_strings_elem); rc += cw_strheap_register_strings(def->strelem, capwap_strings_elem);
printf("Registered %d strings\n",rc); printf("Registered %d strings\n", rc);
return 1; return 1;
} }

View File

@ -191,6 +191,7 @@ int cw_readelem_cisco_wtp_radio_cfg(int elem_id,uint8_t *elem, int len,struct ra
int cw_addelem_cisco_wtp_radio_cfg(uint8_t*dst,struct radioinfo * ri); int cw_addelem_cisco_wtp_radio_cfg(uint8_t*dst,struct radioinfo * ri);
extern int cw_out_cisco_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_t *dst) ; extern int cw_out_cisco_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_t *dst) ;
int cw_in_cisco_image_identifier(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len);

View File

@ -23,6 +23,8 @@ enum capwap_items {
CW_ITEM_WTP_BOOTLOADER_VERSION, CW_ITEM_WTP_BOOTLOADER_VERSION,
CW_ITEM_WTP_OTHERSOFTWARE_VENDOR, CW_ITEM_WTP_OTHERSOFTWARE_VENDOR,
CW_ITEM_WTP_OTHERSOFTWARE_VERSION, CW_ITEM_WTP_OTHERSOFTWARE_VERSION,
CW_ITEM_WTP_BOARD_DATA,
CW_ITEM_WTP_DESCRIPTOR,
CW_ITEM_AC_NAME, CW_ITEM_AC_NAME,
CW_ITEM_AC_DESCRIPTOR, CW_ITEM_AC_DESCRIPTOR,
@ -39,12 +41,20 @@ enum capwap_items {
CW_ITEM_SESSION_ID, CW_ITEM_SESSION_ID,
CW_ITEM_AC_TIMESTAMP, CW_ITEM_AC_TIMESTAMP,
CW_ITEM_STATISTICS_TIMER,
CW_ITEM_WTP_REBOOT_STATISTICS,
CW_ITEM_IMAGE_IDENTIFIER,
/* CIPWAP and Cisco */ /* CIPWAP and Cisco */
CW_ITEM_WTP_GROUP_NAME CW_ITEM_WTP_GROUP_NAME,
/* Other Items */
CW_ITEM_AC_IMAGE_DIR, /* Path where image WTP images are stored */
CW_ITEM_WTP_IMAGE_FILENAME /* Full path of image filename */
}; };

View File

@ -54,7 +54,7 @@ struct cw_str capwap_strings_elem[] = {
{CW_ELEM_WTP_NAME, "WTP Name"}, {CW_ELEM_WTP_NAME, "WTP Name"},
{CW_ELEM_RESERVED_46, "Reserved 46"}, {CW_ELEM_RESERVED_46, "Reserved 46"},
{CW_ELEM_WTP_RADIO_STATISTICS, "WTP Radio Statistics"}, {CW_ELEM_WTP_RADIO_STATISTICS, "WTP Radio Statistics"},
{CWMSGELEM_WTP_REBOOT_STATISTICS, "WTP Reboot Statistics"}, {CW_ELEM_WTP_REBOOT_STATISTICS, "WTP Reboot Statistics"},
{CW_ELEM_WTP_STATIC_IP_ADDRESS_INFORMATION, "WTP Static IP Address Information"}, {CW_ELEM_WTP_STATIC_IP_ADDRESS_INFORMATION, "WTP Static IP Address Information"},

View File

@ -9,6 +9,12 @@
*brief CIPWAP Actions *brief CIPWAP Actions
*/ */
#define CW_ACTION_IN_CISCO_IMAGE_IDENTIFIER \
CW_ELEM_IMAGE_IDENTIFIER, /* Element ID*/ \
cw_in_cisco_image_identifier, 0, /* start/end callback */ \
CW_ITEMTYPE_VENDORSTR, /* Type of element */ \
CW_ITEM_IMAGE_IDENTIFIER, /* ID to use store */ \
1, 4096 /* min/max length */
cw_action_in_t cipwap_actions_ac_in[] = { cw_action_in_t cipwap_actions_ac_in[] = {
@ -26,6 +32,15 @@ cw_action_in_t cipwap_actions_ac_in[] = {
cw_in_generic, 0, CW_ITEMTYPE_STR,CW_ITEM_WTP_GROUP_NAME,1,512} cw_in_generic, 0, CW_ITEMTYPE_STR,CW_ITEM_WTP_GROUP_NAME,1,512}
, ,
/* -------------------------------------------------------------------------------
* Image Data Request - Conig State
*/
{0, 0, CW_STATE_CONFIGURE, CW_MSG_IMAGE_DATA_REQUEST,
CW_ACTION_IN_CISCO_IMAGE_IDENTIFIER,
0}
,
{0,0,0} {0,0,0}
@ -39,7 +54,6 @@ cw_action_out_t cipwap_actions_ac_out[] = {
* Discovery Response OUT * Discovery Response OUT
*/ */
/* AC Descriptor (Cisco) */ /* AC Descriptor (Cisco) */
{CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0 , {CW_MSG_DISCOVERY_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0 ,
CW_ELEM_AC_DESCRIPTOR, cw_out_cisco_ac_descriptor, 0} CW_ELEM_AC_DESCRIPTOR, cw_out_cisco_ac_descriptor, 0}
@ -51,6 +65,17 @@ cw_action_out_t cipwap_actions_ac_out[] = {
CW_CISCO_AP_TIMESYNC, cw_out_cisco_ap_timesync, 0} CW_CISCO_AP_TIMESYNC, cw_out_cisco_ap_timesync, 0}
, ,
/* -------------------------------------------------------------------------------
* Join Response OUT
*/
/* AC Descriptor (Cisco) */
{CW_MSG_JOIN_RESPONSE, CW_ITEM_AC_DESCRIPTOR, 0 ,
CW_ELEM_AC_DESCRIPTOR, cw_out_cisco_ac_descriptor, 0}
,
{0,0,0} {0,0,0}

View File

@ -38,6 +38,7 @@
#include "action.h" #include "action.h"
#include "itemstore.h" #include "itemstore.h"
#include "intavltree.h"
/** /**
* Connection Object * Connection Object
@ -53,6 +54,9 @@ struct conn {
A WTP holds here data about it's AC */ A WTP holds here data about it's AC */
cw_itemstore_t remote; cw_itemstore_t remote;
/** Counter for mandatory message elements */
struct avltree *mand;
struct cw_actiondef *actions; struct cw_actiondef *actions;
@ -227,5 +231,9 @@ struct cwrmsg *conn_wait_for_request(struct conn *conn, int *msglist, time_t tim
void conn_init(struct conn *conn); void conn_init(struct conn *conn);
extern int cw_read_messages(struct conn *conn);
#endif /* __CONLIST_H */ #endif /* __CONLIST_H */

View File

@ -232,8 +232,8 @@ void conn_process_packet(struct conn * conn, uint8_t *packet, int len,int (*cb)(
// extern int cw_process_msg(struct conn * conn,uint8_t*msg,int len); // extern int cw_process_msg(struct conn * conn,uint8_t*msg,int len);
// cw_process_msg(conn,f+4,*(uint32_t*)f); // cw_process_msg(conn,f+4,*(uint32_t*)f);
printf("Received a fragmented packetm should process it"); //printf("Received a fragmented packetm should process it");
exit(0); //exit(0);
/* /*
if (!cwrmsg_init_ctrlhdr(conn,&cwrmsg,f+4,*(uint32_t*)f)){ if (!cwrmsg_init_ctrlhdr(conn,&cwrmsg,f+4,*(uint32_t*)f)){
@ -261,3 +261,23 @@ exit(0);
return; return;
} }
/**
* Used as main message loop
*/
int cw_read_messages(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);
}

View File

@ -1,3 +1,5 @@
#include "cw_log.h" #include "cw_log.h"
#include "capwap.h" #include "capwap.h"
#include "capwap_cisco.h" #include "capwap_cisco.h"

View File

@ -2,34 +2,21 @@
#include "action.h" #include "action.h"
#include "cw_log.h" #include "cw_log.h"
#include "itemstore.h" #include "itemstore.h"
#include "capwap.h"
int cw_itemstore_set(cw_itemstore_t itemstore, uint32_t item_id, int item_type, uint8_t *data, int len)
{
switch (item_type) {
case CW_ITEMTYPE_BYTE:
cw_itemstore_set_byte(itemstore,item_id,*data);
break;
case CW_ITEMTYPE_STR:
cw_itemstore_set_strn(itemstore,item_id,(char*)data,len);
break;
case CW_ITEMTYPE_BSTR:
cw_itemstore_set_bstrn(itemstore,item_id,data,len);
break;
}
return 0;
}
int cw_in_generic(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len) int cw_in_generic(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len)
{ {
if (len<a->min_len) { if (len<a->min_len) {
cw_dbg(DBG_ELEM_ERR,"Message element too short, %d < %d", len,a->min_len); cw_dbg(DBG_ELEM_ERR,"Message element too short, %d < %d", len,a->min_len);
return 0; return 0;
} }
if (len>a->max_len) {
cw_dbg(DBG_ELEM_ERR,"Message element too big, %d > %d", len,a->max_len);
return 0;
}
cw_itemstore_set(conn->remote,a->item_id,a->itemtype,data,len); cw_itemstore_set(conn->remote,a->item_id,a->itemtype,data,len);

View File

@ -54,25 +54,25 @@ static void readsubelems_wtp_board_data(cw_itemstore_t itemstore, uint8_t * msge
sublen); sublen);
switch (subtype) { switch (subtype) {
case CWBOARDDATA_MODELNO: case CW_BOARDDATA_MODELNO:
cw_itemstore_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_MODELNO, cw_itemstore_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_MODELNO,
msgelem + i, sublen); msgelem + i, sublen);
break; break;
case CWBOARDDATA_SERIALNO: case CW_BOARDDATA_SERIALNO:
cw_itemstore_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_SERIALNO, cw_itemstore_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_SERIALNO,
msgelem + i, sublen); msgelem + i, sublen);
break; break;
case CWBOARDDATA_MACADDRESS: case CW_BOARDDATA_MACADDRESS:
cw_itemstore_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_MACADDRESS, cw_itemstore_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_MACADDRESS,
msgelem + i, sublen); msgelem + i, sublen);
break; break;
case CWBOARDDATA_BOARDID: case CW_BOARDDATA_BOARDID:
cw_itemstore_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_ID, cw_itemstore_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_ID,
msgelem + i, sublen); msgelem + i, sublen);
break; break;
case CWBOARDDATA_REVISION: case CW_BOARDDATA_REVISION:
cw_itemstore_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_REVISION, cw_itemstore_set_bstrn(itemstore, CW_ITEM_WTP_BOARD_REVISION,
msgelem + i, sublen); msgelem + i, sublen);
default: default:

View File

@ -361,6 +361,7 @@ void lw_dbg_elem_(int msg_id, int elem_id, const uint8_t * elem_data, int elem_l
} }
/*
void cw_dbg_missing_mand_elems_(struct conn *conn, int msgtype, int *mand) void cw_dbg_missing_mand_elems_(struct conn *conn, int msgtype, int *mand)
{ {
if (!cw_dbg_is_level(DBG_CW_RFC)) if (!cw_dbg_is_level(DBG_CW_RFC))
@ -372,3 +373,4 @@ void cw_dbg_missing_mand_elems_(struct conn *conn, int msgtype, int *mand)
cw_dbg(DBG_CW_RFC, "Missing msgelems in %s: %s", cw_strmsg(msgtype), str); cw_dbg(DBG_CW_RFC, "Missing msgelems in %s: %s", cw_strmsg(msgtype), str);
} }
} }
*/

View File

@ -32,6 +32,4 @@ void cw_init_response(struct conn * conn, uint8_t *req)
cw_set_msg_type(dmsgptr,cw_get_msg_type(msgptr)+1); cw_set_msg_type(dmsgptr,cw_get_msg_type(msgptr)+1);
cw_set_msg_seqnum(dmsgptr,cw_get_msg_seqnum(msgptr)); cw_set_msg_seqnum(dmsgptr,cw_get_msg_seqnum(msgptr));
cw_set_msg_flags(dmsgptr,0); cw_set_msg_flags(dmsgptr,0);
} }

View File

@ -38,7 +38,7 @@ int cw_out_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_t *dst
i = cw_itemstore_get(conn->local,CW_ITEM_AC_HARDWARE_VERSION); i = cw_itemstore_get(conn->local,CW_ITEM_AC_HARDWARE_VERSION);
if ( i ) { if ( i ) {
d += cw_put_version(d,CW_SUBELEM_AC_HARDWARE_VERSION,*((uint32_t*)(i->data)),i->data+4); d += cw_put_version(d,CW_SUBELEM_AC_HARDWARE_VERSION,i->data);
} }
else { else {
cw_dbg(DBG_ELEM_ERR, "Can't send hard version in AC descriptor, not set."); cw_dbg(DBG_ELEM_ERR, "Can't send hard version in AC descriptor, not set.");
@ -48,7 +48,7 @@ int cw_out_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_t *dst
i = cw_itemstore_get(conn->local,CW_ITEM_AC_SOFTWARE_VERSION); i = cw_itemstore_get(conn->local,CW_ITEM_AC_SOFTWARE_VERSION);
if ( i ) { if ( i ) {
d += cw_put_version(d,CW_SUBELEM_AC_SOFTWARE_VERSION,*((uint32_t*)(i->data)),i->data+4); d += cw_put_version(d,CW_SUBELEM_AC_SOFTWARE_VERSION,i->data);
} }
else { else {
cw_dbg(DBG_ELEM_ERR, "Can't send software version in AC descriptor, not set."); cw_dbg(DBG_ELEM_ERR, "Can't send software version in AC descriptor, not set.");

View File

@ -24,7 +24,7 @@ int cw_out_cisco_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_
i = cw_itemstore_get(conn->local,CW_ITEM_AC_SOFTWARE_VERSION); i = cw_itemstore_get(conn->local,CW_ITEM_AC_SOFTWARE_VERSION);
if ( i ) { if ( i ) {
d += cw_put_version(d,CW_SUBELEM_AC_SOFTWARE_VERSION,*((uint32_t*)(i->data)),i->data+4); d += cw_put_version(d,1,i->data);
} }
else { else {
cw_dbg(DBG_ELEM_ERR, "Can't send software version in AC descriptor, not set."); cw_dbg(DBG_ELEM_ERR, "Can't send software version in AC descriptor, not set.");

View File

@ -4,6 +4,8 @@
#include "capwap.h" #include "capwap.h"
#include "capwap_items.h" #include "capwap_items.h"
#include "cw_log.h"
int cw_put_item(uint8_t *dst,struct cw_item*item) int cw_put_item(uint8_t *dst,struct cw_item*item)
{ {
@ -31,7 +33,6 @@ int cw_out_generic(struct conn *conn,struct cw_action_out *a,uint8_t *dst) // ,s
item = a->get (conn,a); item = a->get (conn,a);
} }
printf("Out generic item %p\n",item);
/* Size for msg elem header depends on /* Size for msg elem header depends on
vendor specific payload */ vendor specific payload */
@ -39,13 +40,14 @@ int cw_out_generic(struct conn *conn,struct cw_action_out *a,uint8_t *dst) // ,s
int len; int len;
if ( !item ) if ( !item ){
len=0; if (a->mand){
cw_log(LOG_ERR,"Cannot send mandatory message element %d",a->elem_id);
}
return 0;
}
else{ else{
printf("Putting it\n");
printf("To put: %d %s\n",len,item->data);
len = cw_put_item(dst+start,item); len = cw_put_item(dst+start,item);
printf("Putted: %d %s\n",len,item->data);
} }

View File

@ -43,22 +43,40 @@ int conn_send_msg(struct conn *conn, uint8_t * rawmsg);
/** /**
* Init response message header * Init response message header
*/ */
void cw_init_response(struct conn * conn, uint8_t *req) void cw_init_response(struct conn *conn, uint8_t * req)
{ {
uint8_t *buffer=conn->resp_buffer; uint8_t *buffer = conn->resp_buffer;
int shbytes = cw_get_hdr_msg_offset(req); int shbytes = cw_get_hdr_msg_offset(req);
int dhbytes; int dhbytes;
memcpy(buffer,req,shbytes); memcpy(buffer, req, shbytes);
cw_set_hdr_hlen(buffer,2); cw_set_hdr_hlen(buffer, 2);
cw_set_hdr_flags(buffer,CW_FLAG_HDR_M,1); cw_set_hdr_flags(buffer, CW_FLAG_HDR_M, 1);
dhbytes = cw_get_hdr_msg_offset(buffer); dhbytes = cw_get_hdr_msg_offset(buffer);
uint8_t * msgptr = req+shbytes; uint8_t *msgptr = req + shbytes;
uint8_t * dmsgptr = buffer+dhbytes; 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);
}
void cw_init_request(struct conn *conn, int msg_id)
{
uint8_t *buffer = conn->req_buffer;
cw_put_dword(buffer + 0, 0);
cw_put_dword(buffer + 4, 0);
cw_set_hdr_preamble(buffer, 0);
cw_set_hdr_hlen(buffer, 2);
cw_set_hdr_wbid(buffer, 1);
cw_set_hdr_rid(buffer, 0);
uint8_t *msgptr = cw_get_hdr_msg_offset(buffer) + buffer;
cw_set_msg_type(msgptr, msg_id);
cw_set_msg_flags(msgptr, 0);
cw_set_msg_elems_len(msgptr, 0);
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);
} }
/** /**
@ -67,7 +85,8 @@ void cw_init_response(struct conn * conn, uint8_t *req)
int cw_send_response(struct conn *conn, uint8_t * rawmsg, int len) int cw_send_response(struct conn *conn, uint8_t * rawmsg, int len)
{ {
cw_init_response(conn, rawmsg); cw_init_response(conn, rawmsg);
cw_put_msg(conn,conn->resp_buffer); if (cw_put_msg(conn, conn->resp_buffer) == -1)
return 0;
conn_send_msg(conn, conn->resp_buffer); conn_send_msg(conn, conn->resp_buffer);
return 1; return 1;
} }
@ -83,16 +102,16 @@ int cw_send_response(struct conn *conn, uint8_t * rawmsg, int len)
* @pqram result_code result code to send * @pqram result_code result code to send
* @return 1 * @return 1
*/ */
int cw_send_error_response(struct conn *conn,uint8_t *rawmsg, uint32_t result_code) int cw_send_error_response(struct conn *conn, uint8_t * rawmsg, uint32_t result_code)
{ {
cw_init_response(conn,rawmsg); cw_init_response(conn, rawmsg);
uint8_t *out = conn->resp_buffer; uint8_t *out = conn->resp_buffer;
uint8_t *dst = cw_get_hdr_msg_elems_ptr(out); uint8_t *dst = cw_get_hdr_msg_elems_ptr(out);
int l = cw_put_elem_result_code(dst,result_code); int l = cw_put_elem_result_code(dst, result_code);
cw_set_msg_elems_len(out+cw_get_hdr_msg_offset(out), l); cw_set_msg_elems_len(out + cw_get_hdr_msg_offset(out), l);
conn_send_msg(conn, conn->resp_buffer); conn_send_msg(conn, conn->resp_buffer);
@ -102,7 +121,7 @@ int cw_send_error_response(struct conn *conn,uint8_t *rawmsg, uint32_t result_co
int cw_process_msg(struct conn *conn, uint8_t * rawmsg, int len) int cw_process_msg(struct conn *conn, uint8_t * rawmsg, int len)
{ {
struct cw_action_in as, *af,*afm; struct cw_action_in as, *af, *afm;
uint8_t *msg_ptr = rawmsg + cw_get_hdr_msg_offset(rawmsg); uint8_t *msg_ptr = rawmsg + cw_get_hdr_msg_offset(rawmsg);
@ -138,7 +157,7 @@ int cw_process_msg(struct conn *conn, uint8_t * rawmsg, int len)
as.msg_id = cw_get_msg_id(msg_ptr); as.msg_id = cw_get_msg_id(msg_ptr);
as.vendor_id = 0; as.vendor_id = 0;
as.elem_id = 0; as.elem_id = 0;
as.proto=0; as.proto = 0;
/* Search for state/message combination */ /* Search for state/message combination */
@ -146,30 +165,33 @@ int cw_process_msg(struct conn *conn, uint8_t * rawmsg, int len)
if (!afm) { if (!afm) {
/* Throw away unexpected response messages */ /* Throw away unexpected response messages */
if (!(as.msg_id &1)) { if (!(as.msg_id & 1)) {
cw_dbg(DBG_MSG_ERR, "Message type %d (%s) unexpected, discarding.", cw_dbg(DBG_MSG_ERR,
as.msg_id, cw_strmsg(as.msg_id)); "Message type %d (%s) unexpected/illigal in %s State, discarding.",
as.msg_id, cw_strmsg(as.msg_id),
cw_strstate(conn->capwap_state));
return 0; return 0;
} }
/* Request message not found in current state, check if we know /* Request message not found in current state, check if we know
anything else about this message type */ anything else about this message type */
const char *str = cw_strheap_get(conn->actions->strmsg,as.msg_id); const char *str = cw_strheap_get(conn->actions->strmsg, as.msg_id);
int result_code=0; int result_code = 0;
if (str) { if (str) {
/* Message found, but it was in wrong state */ /* Message found, but it was in wrong state */
cw_dbg(DBG_MSG_ERR, "Message type %d (%s) not allowed in %s State.", cw_dbg(DBG_MSG_ERR,
as.msg_id, cw_strmsg(as.msg_id), cw_strstate(as.capwap_state)); "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 = CW_RESULT_MSG_INVALID_IN_CURRENT_STATE;
} } else {
else {
/* Message is unknown */ /* Message is unknown */
cw_dbg(DBG_MSG_ERR, "Message type %d (%s) unknown.", cw_dbg(DBG_MSG_ERR, "Message type %d (%s) unknown.",
as.msg_id, cw_strmsg(as.msg_id), cw_strstate(as.capwap_state)); as.msg_id, cw_strmsg(as.msg_id),
cw_strstate(as.capwap_state));
result_code = CW_RESULT_MSG_UNRECOGNIZED; result_code = CW_RESULT_MSG_UNRECOGNIZED;
} }
cw_send_error_response(conn,rawmsg,result_code); cw_send_error_response(conn, rawmsg, result_code);
return 0; return 0;
} }
@ -182,6 +204,7 @@ int cw_process_msg(struct conn *conn, uint8_t * rawmsg, int len)
uint8_t *elems_ptr = cw_get_msg_elems_ptr(msg_ptr); uint8_t *elems_ptr = cw_get_msg_elems_ptr(msg_ptr);
uint8_t *elem; uint8_t *elem;
/* avltree to bag the found mandatory elements */
conn->mand = intavltree_create(); conn->mand = intavltree_create();
/* iterate through message elements */ /* iterate through message elements */
@ -190,7 +213,8 @@ int cw_process_msg(struct conn *conn, uint8_t * rawmsg, int len)
as.elem_id = cw_get_elem_id(elem); as.elem_id = cw_get_elem_id(elem);
int elem_len = cw_get_elem_len(elem); int elem_len = cw_get_elem_len(elem);
cw_dbg_elem(conn,as.msg_id, as.elem_id, cw_get_elem_data(elem), elem_len); cw_dbg_elem(conn, as.msg_id, as.elem_id, cw_get_elem_data(elem),
elem_len);
af = cw_actionlist_in_get(conn->actions->in, &as); af = cw_actionlist_in_get(conn->actions->in, &as);
@ -201,10 +225,10 @@ int cw_process_msg(struct conn *conn, uint8_t * rawmsg, int len)
continue; continue;
} }
if (af->mand){ if (af->mand) {
/* add found mandatory message element /* add found mandatory message element
to mand list */ to mand list */
intavltree_add(conn->mand,af->item_id); intavltree_add(conn->mand, af->item_id);
} }
if (af->start) { if (af->start) {
@ -213,19 +237,18 @@ int cw_process_msg(struct conn *conn, uint8_t * rawmsg, int len)
} }
int result_code=0; int result_code = 0;
if (afm->end) { if (afm->end) {
result_code=afm->end(conn, afm, rawmsg, len); result_code = afm->end(conn, afm, rawmsg, len);
} }
/* if we've got a request message, we have to send a response message */ /* if we've got a request message, we have to send a response message */
if (as.msg_id & 1) { if (as.msg_id & 1) {
if ( result_code>0 ) { if (result_code > 0) {
/* the end method gave us an result code, so /* the end method gave us an result code, so
send an error message */ send an error message */
cw_send_error_response(conn,rawmsg,result_code); cw_send_error_response(conn, rawmsg, result_code);
} } else {
else{
/* regular response message */ /* regular response message */
cw_send_response(conn, rawmsg, len); cw_send_response(conn, rawmsg, len);
} }

View File

@ -25,6 +25,8 @@
#include "capwap_items.h" #include "capwap_items.h"
#include "conn.h" #include "conn.h"
#include "cw_log.h"
struct args{ struct args{
struct conn * conn; struct conn * conn;
uint32_t msg_id; uint32_t msg_id;
@ -48,6 +50,7 @@ static int action_cb(void *args_param, void *a_param)
if (a->item_id == CW_ITEM_NONE) { if (a->item_id == CW_ITEM_NONE) {
/* Start of message */ /* Start of message */
args->len=0;
return 1; return 1;
} }
@ -94,7 +97,7 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout)
args.conn = conn; args.conn = conn;
args.msg_id = as.msg_id; args.msg_id = as.msg_id;
args.dst = msgptr+8; args.dst = msgptr+8;
args.len=0; args.len=-1;
avltree_foreach_from_asc(conn->actions->out, &as, action_cb, &args); avltree_foreach_from_asc(conn->actions->out, &as, action_cb, &args);
@ -104,6 +107,13 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout)
printf ("Total elems len = %d\n",args.len); printf ("Total elems len = %d\n",args.len);
printf("Total msg len = %d\n",cw_get_hdr_msg_total_len(rawout)); printf("Total msg len = %d\n",cw_get_hdr_msg_total_len(rawout));
*/ */
if (args.len==-1) {
cw_log(LOG_ERR,"Error: Can't create message of type %d (%s) - no definition found.",
args.msg_id,cw_strmsg(args.msg_id));
}
return args.len; return args.len;
} }

View File

@ -23,7 +23,7 @@
int cw_readelem_wtp_reboot_statistics(struct wtp_reboot_statistics *s, int type,uint8_t *msgelem, int len) int cw_readelem_wtp_reboot_statistics(struct wtp_reboot_statistics *s, int type,uint8_t *msgelem, int len)
{ {
if (type != CWMSGELEM_WTP_REBOOT_STATISTICS) if (type != CW_ELEM_WTP_REBOOT_STATISTICS)
return 0; return 0;
s->reboot_count=ntohs(*((uint16_t*)(msgelem+0))); s->reboot_count=ntohs(*((uint16_t*)(msgelem+0)));

View File

@ -55,6 +55,7 @@ void cw_get_missing_mand_elems(char *dst, int *l)
} }
} }
/*
int cw_is_missing_mand_elems(int *l) int cw_is_missing_mand_elems(int *l)
{ {
int i; int i;
@ -66,4 +67,4 @@ int cw_is_missing_mand_elems(int *l)
return 0; return 0;
} }
*/

View File

@ -56,7 +56,7 @@ extern int cw_rand(uint8_t*dst, int len);
/* functions used to "rfc-verify" message elements */ /* functions used to "rfc-verify" message elements */
void cw_mand_elem_found(int *l,int type); void cw_mand_elem_found(int *l,int type);
int cw_is_missing_mand_elems(int *l); //int cw_is_missing_mand_elems(int *l);
void cw_get_missing_mand_elems(char *dst, int *l); void cw_get_missing_mand_elems(char *dst, int *l);

View File

@ -74,7 +74,7 @@ void cwread_configuration_status_request(struct wtpinfo * wtpinfo, uint8_t * msg
{ {
int mand[] = { int mand[] = {
CW_ELEM_AC_NAME, CW_ELEM_AC_NAME,
CWMSGELEM_WTP_REBOOT_STATISTICS, CW_ELEM_WTP_REBOOT_STATISTICS,
CWMSGELEM_RADIO_ADMINISTRATIVE_STATE, CWMSGELEM_RADIO_ADMINISTRATIVE_STATE,
CW_ELEM_STATISTICS_TIMER, CW_ELEM_STATISTICS_TIMER,
-1}; -1};

View File

@ -4,6 +4,7 @@
#include "conn.h" #include "conn.h"
void cw_dbg_elem_(struct conn * conn, int msg, int msgelem, const uint8_t * msgbuf, int len); void cw_dbg_elem_(struct conn * conn, int msg, int msgelem, const uint8_t * msgbuf, int len);
void cw_dbg_missing_mand(int level,struct conn *conn,cw_action_in_t ** ml,int n,cw_action_in_t *a);
#ifdef WITH_CW_LOG_DEBUG #ifdef WITH_CW_LOG_DEBUG

View File

@ -15,11 +15,13 @@
along with Foobar. If not, see <http://www.gnu.org/licenses/>. along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __CW_DTLS_H
#define __CW_DTLS_H
#include <stdint.h> #include <stdint.h>
#include "conn.h" #include "conn.h"
#ifndef __DTLS_H
#define __DTLS_H
struct dtls_ssl_cert struct dtls_ssl_cert
{ {

View File

@ -3,6 +3,7 @@
#include <string.h> #include <string.h>
#include "itemstore.h" #include "itemstore.h"
#include "capwap.h"
@ -13,7 +14,8 @@ static inline void cw_itemstore_del_data(void *e)
case CW_ITEMTYPE_DATA: case CW_ITEMTYPE_DATA:
case CW_ITEMTYPE_STR: case CW_ITEMTYPE_STR:
case CW_ITEMTYPE_BSTR: case CW_ITEMTYPE_BSTR:
case CW_ITEMTYPE_VERSION: case CW_ITEMTYPE_BSTR16:
case CW_ITEMTYPE_VENDORSTR:
case CW_ITEMTYPE_FUN: case CW_ITEMTYPE_FUN:
free(item->data); free(item->data);
break; break;
@ -104,12 +106,28 @@ int cw_itemstore_set_str(cw_itemstore_t s, uint32_t id, const char *str)
return 1; return 1;
} }
int cw_itemstore_set_strn(cw_itemstore_t s, uint32_t id, const char *str, int n) int cw_itemstore_set_data(cw_itemstore_t s, uint32_t id, const uint8_t *data, int len)
{ {
struct cw_item *i = cw_item_create(s, id); struct cw_item *i = cw_item_create(s, id);
if (!i) if (!i)
return 0; return 0;
i->type = CW_ITEMTYPE_DATA; i->type = CW_ITEMTYPE_DATA;
i->data = malloc(len);
if(!i->data)
return 1;
memcpy(i->data,data,len);
return 1;
}
int cw_itemstore_set_strn(cw_itemstore_t s, uint32_t id, const char *str, int n)
{
struct cw_item *i = cw_item_create(s, id);
if (!i)
return 0;
i->type = CW_ITEMTYPE_STR;
i->data = strndup(str, n); i->data = strndup(str, n);
return 1; return 1;
} }
@ -134,6 +152,20 @@ int cw_itemstore_set_bstrn(cw_itemstore_t s, uint32_t id, uint8_t * data, int le
return 1; return 1;
} }
int cw_itemstore_set_bstr16n(cw_itemstore_t s, uint32_t id, uint8_t * data, int len)
{
struct cw_item *i = cw_item_create(s, id);
if (!i)
return 0;
i->type = CW_ITEMTYPE_BSTR16;
i->data = bstr16_create(data, len);
return 1;
}
int cw_itemstore_set_const_ptr(cw_itemstore_t s, uint32_t id, void *ptr) int cw_itemstore_set_const_ptr(cw_itemstore_t s, uint32_t id, void *ptr)
{ {
@ -145,23 +177,15 @@ int cw_itemstore_set_const_ptr(cw_itemstore_t s, uint32_t id, void *ptr)
return 1; return 1;
} }
int cw_itemstore_set_version(cw_itemstore_t s, uint32_t id, uint32_t vendor_id, int cw_itemstore_set_vendorstr(cw_itemstore_t s, uint32_t id, uint32_t vendor_id,
uint8_t * versionstr, int len) uint8_t * vendorstr, int len)
{ {
struct cw_item *i = cw_item_create(s, id); struct cw_item *i = cw_item_create(s, id);
if (!i) if (!i)
return 0; return 0;
i->type = CW_ITEMTYPE_VERSION;
uint8_t *ptr = malloc(bstr16_size(len) + 4);
i->data = ptr;
if (!ptr)
return 1;
*((uint32_t *) ptr) = vendor_id;
bstr16_ncpy(ptr + 4, versionstr, len);
i->type = CW_ITEMTYPE_VENDORSTR;
i->data = vendorstr_create(vendor_id,vendorstr,len);
return 1; return 1;
} }
@ -239,3 +263,33 @@ void cw_item_release_data_ptr(struct cw_item *item, void *data)
} }
} }
int cw_itemstore_set(cw_itemstore_t itemstore, uint32_t item_id, int item_type, uint8_t *data, int len)
{
switch (item_type) {
case CW_ITEMTYPE_BYTE:
cw_itemstore_set_byte(itemstore,item_id,*data);
break;
case CW_ITEMTYPE_STR:
cw_itemstore_set_strn(itemstore,item_id,(char*)data,len);
break;
case CW_ITEMTYPE_BSTR:
cw_itemstore_set_bstrn(itemstore,item_id,data,len);
break;
case CW_ITEMTYPE_DATA:
cw_itemstore_set_data(itemstore,item_id,data,len);
break;
case CW_ITEMTYPE_VENDORSTR:
cw_itemstore_set_vendorstr(itemstore,item_id,
cw_get_dword(data),data+4,len-4);
}
return 0;
}

View File

@ -26,8 +26,11 @@
#include "avltree.h" #include "avltree.h"
#include "bstr.h" #include "bstr.h"
enum cw_cfgtem_types{ /**
CW_ITEMTYPE_NONE=0, * Item types supported in item store
*/
enum cw_cfgtem_types {
CW_ITEMTYPE_NONE = 0,
CW_ITEMTYPE_BYTE, CW_ITEMTYPE_BYTE,
CW_ITEMTYPE_WORD, CW_ITEMTYPE_WORD,
CW_ITEMTYPE_DWORD, CW_ITEMTYPE_DWORD,
@ -35,7 +38,10 @@ enum cw_cfgtem_types{
CW_ITEMTYPE_CONST_DATA, CW_ITEMTYPE_CONST_DATA,
CW_ITEMTYPE_STR, CW_ITEMTYPE_STR,
CW_ITEMTYPE_BSTR, CW_ITEMTYPE_BSTR,
CW_ITEMTYPE_VERSION, CW_ITEMTYPE_BSTR16,
/** Vendor string contains a Vendor ID, followed by bstr16 data, containing
the string. */
CW_ITEMTYPE_VENDORSTR,
CW_ITEMTYPE_AVLTREE, CW_ITEMTYPE_AVLTREE,
CW_ITEMTYPE_FUN, CW_ITEMTYPE_FUN,
@ -52,25 +58,52 @@ struct cw_item {
}; };
}; };
typedef struct avltree * cw_itemstore_t; typedef struct avltree *cw_itemstore_t;
static inline struct cw_item * cw_itemstore_get(cw_itemstore_t s, uint32_t id) static inline struct cw_item *cw_itemstore_get(cw_itemstore_t s, uint32_t id)
{ {
struct cw_item i; struct cw_item i;
i.id=id; i.id = id;
return avltree_get(s,&i); return avltree_get(s, &i);
} }
extern cw_itemstore_t cw_itemstore_create(); extern cw_itemstore_t cw_itemstore_create();
extern int cw_itemstore_set_strn(cw_itemstore_t s,uint32_t id,const char *str,int n); extern int cw_itemstore_set_strn(cw_itemstore_t s, uint32_t id, const char *str, int n);
extern int cw_itemstore_set_str(cw_itemstore_t s,uint32_t id,const char *str); extern int cw_itemstore_set_str(cw_itemstore_t s, uint32_t id, const char *str);
extern int cw_itemstore_set_ptr(cw_itemstore_t s, uint32_t id, void*ptr); extern int cw_itemstore_set_ptr(cw_itemstore_t s, uint32_t id, void *ptr);
extern int cw_itemstore_set_bstrn(cw_itemstore_t s, uint32_t id, uint8_t *data,int len); extern int cw_itemstore_set_bstrn(cw_itemstore_t s, uint32_t id, uint8_t * data, int len);
extern int cw_itemstore_set_dword(cw_itemstore_t s,uint32_t id,uint32_t dword); extern int cw_itemstore_set_dword(cw_itemstore_t s, uint32_t id, uint32_t dword);
extern int cw_itemstore_set_byte(cw_itemstore_t s,uint32_t id,uint8_t byte); extern int cw_itemstore_set_word(cw_itemstore_t s, uint32_t id, uint32_t word);
extern int cw_itemstore_set_version(cw_itemstore_t s, uint32_t id, uint32_t vendor_id, uint8_t * versionstr, int len); extern int cw_itemstore_set_byte(cw_itemstore_t s, uint32_t id, uint8_t byte);
extern int cw_itemstore_set_vendorstr(cw_itemstore_t s, uint32_t id,
uint32_t vendor_id, uint8_t * vendorstr,
int len);
int cw_itemstore_set_avltree(cw_itemstore_t s, uint32_t id, struct avltree *t);
int cw_itemstore_set_bstr16n(cw_itemstore_t s, uint32_t id, uint8_t * data, int len);
extern int cw_itemstore_set_data(cw_itemstore_t s, uint32_t id, const uint8_t * data,
int len);
static inline char * cw_itemstore_get_str(cw_itemstore_t s,uint32_t id) {
struct cw_item *i = cw_itemstore_get(s,id);
if (!i)
return NULL;
return i->data;
};
static inline struct avltree * cw_itemstore_get_avltree(cw_itemstore_t s,uint32_t id){
struct cw_item *i = cw_itemstore_get(s,id);
if (!i)
return NULL;
if (i->type!=CW_ITEMTYPE_AVLTREE)
return NULL;
return i->data;
}
extern void *cw_item_get_data_ptr(struct cw_item *item); extern void *cw_item_get_data_ptr(struct cw_item *item);
extern void cw_item_release_data_ptr(struct cw_item *item, void *data); extern void cw_item_release_data_ptr(struct cw_item *item, void *data);
@ -80,5 +113,6 @@ int cw_itemstore_set_fun(cw_itemstore_t s, uint32_t id,
void *(*funget) (void *arg), void *(*funget) (void *arg),
void (*funfree) (void *arg, void *data), void *arg); void (*funfree) (void *arg, void *data), void *arg);
int cw_itemstore_set(cw_itemstore_t itemstore, uint32_t item_id, int item_type, uint8_t *data, int len);
#endif #endif

View File

@ -17,14 +17,13 @@ extern cw_strheap_t cw_strheap_create();
extern int cw_strheap_register_strings(cw_strheap_t h, struct cw_str *s); extern int cw_strheap_register_strings(cw_strheap_t h, struct cw_str *s);
static inline const char * cw_strheap_get(cw_strheap_t h, int id) { static inline const char * cw_strheap_get(cw_strheap_t h, int id) {
struct cw_str s, *rc; struct cw_str s;
s.id=id; s.id=id;
rc = avltree_get(h,&s); struct cw_str *r = avltree_get(h,&s);
if (rc) if (r)
return rc->str; return r->str;
return cw_strheap_get(h,0); return NULL;
} }
#endif #endif

View File

@ -6,7 +6,7 @@ ifndef CC
endif endif
V=0
CFLAGS+=-DWITH_RMAC_SUPPORT CFLAGS+=-DWITH_RMAC_SUPPORT
CFLAGS+=-DWITH_IPV6 CFLAGS+=-DWITH_IPV6
@ -21,6 +21,7 @@ endif
CFLAGS += -Os -Wall -g CFLAGS += -Os -Wall -g
CFLAGS += -Os -Wall
LDFLAGS += -L../../src/capwap/$(ARCH) LDFLAGS += -L../../src/capwap/$(ARCH)
@ -103,7 +104,7 @@ ALL=wtp
all: $(ALL) all: $(ALL)
Q= Q=@
E=echo E=echo
ifeq ($(V), 1) ifeq ($(V), 1)
Q= Q=
@ -111,8 +112,8 @@ E=true
endif endif
%.o: %.c %.o: %.c
$(Q)$(CC) -c -o $@ $(CFLAGS) $<
@$(E) " CC " $< @$(E) " CC " $<
$(Q)$(CC) -c -o $@ $(CFLAGS) $<
wtp: $(BCHECK) $(OBJS) wtp: $(BCHECK) $(OBJS)

View File

@ -6,6 +6,7 @@
int configure() int configure()
{ {
/*
struct conn * conn = get_conn(); struct conn * conn = get_conn();
struct wtpinfo * wtpinfo = get_wtpinfo(); struct wtpinfo * wtpinfo = get_wtpinfo();
@ -22,7 +23,7 @@ int configure()
printf("Got change resp %p\n",cwrmsg); printf("Got change resp %p\n",cwrmsg);
*/
} }

View File

@ -25,252 +25,54 @@
#include "capwap/capwap.h" #include "capwap/capwap.h"
#include "capwap/capwap_items.h"
#include "capwap/cw_log.h" #include "capwap/cw_log.h"
#include "capwap/wtpinfo.h" #include "capwap/wtpinfo.h"
#include "capwap/acinfo.h" #include "capwap/acinfo.h"
#include "capwap/sock.h" #include "capwap/sock.h"
#include "capwap/cw_util.h" #include "capwap/cw_util.h"
#include "wtp.h" #include "wtp.h"
#include "wtp_conf.h" #include "wtp_conf.h"
#include "wtp_interface.h" #include "wtp_interface.h"
#include <stdio.h> #include <stdio.h>
struct discovery_info{
ACIPLIST * aciplist;
struct conn * conn;
int response_count;
};
static int acprint(void *p,void*d) //,int ctr)
static int run_discovery(struct conn *conn)
{ {
conn->capwap_state=CW_STATE_DISCOVERY;
cw_itemstore_set_byte(conn->local,CW_ITEM_DISCOVERY_TYPE,CW_DISCOVERY_TYPE_UNKNOWN);
ACIP * ip = (ACIP*)d; cw_init_request(conn,CW_MSG_DISCOVERY_REQUEST);
char str[100]; cw_put_msg(conn,conn->req_buffer);
sock_addrtostr((struct sockaddr*)&ip->ip,str,100); conn_send_msg(conn,conn->req_buffer);
printf("ACIP: %s\n",str);
printf("CTR: %i\n",ip->wtp_count);
return 1;
}
struct ac_info wtp_acinfo; time_t timer = cw_timer_start(10);
while (!cw_timer_timeout(timer)
&& conn->capwap_state == CW_STATE_DISCOVERY) {
cw_read_messages(conn);
static int msg_cb(void *priv,struct cwrmsg * cwrmsg)
{
if (cwrmsg->type != CW_MSG_DISCOVERY_RESPONSE){
cw_dbg(DBG_ERR,"Expected discovery response, but received %i",cwrmsg->type);
return 1;
} }
struct discovery_info * di = (struct discovery_info*)priv;
/*
if (di->conn->seqnum != cwrmsg->seqnum){
cw_log_debug0("Ignoring discovery respone, seqnum=%i, expected seqnum %i",cwrmsg->seqnum,di->conn->seqnum);
return 1;
}
*/
struct ac_info * acinfo = &wtp_acinfo;
memset(acinfo,0,sizeof(struct ac_info));
acinfo->aciplist = di->aciplist;
cwread_discovery_response(acinfo,cwrmsg->msgelems,cwrmsg->msgelems_len);
char ai [4096];
acinfo_print(ai,acinfo);
printf("AC INFO\n%s",ai);
//printf("CWRHW: %s\n",sock_hwaddr2str(bstr_data(cwrmsg->rmac),bstr_len(cwrmsg->rmac)));
///exit(0);
/*
printf("AC NAME %s\n",acinfo.ac_name);
printf("AC Software version %s\n",acinfo.software_version);
printf("AC Hardwareversion %s\n",acinfo.hardware_version);
printf("Active wtps: %i\n",acinfo.active_wtps);
printf("Active max wtps: %i\n",acinfo.max_wtps);
printf("Got Discovery response\n");
printf("ACL COUNT: %i\n",acinfo.aciplist->count);
*/
aciplist_foreach(acinfo->aciplist,acprint,0);
// responses++;
//
di->response_count++;
return 1;
}
static void rand_sleep(int seconds)
{
int usecs = seconds * 1000;
uint16_t rnd;
cw_rand((uint8_t*)&rnd,sizeof(rnd));
uint16_t max = 0-1;
int r = (rnd * usecs) / max;
cw_dbg(DBG_CW_INFO,"Sleeping for %u milliseconds\n",r);
usleep(r*1000);
}
static int do_discover_conn(struct conn * conn,struct discovery_info * di)
{
rand_sleep(conf_max_discovery_interval);
struct wtpinfo * wtpinfo;
wtpinfo = get_wtpinfo();
// wtpinfo_print(wtpinfo);
// struct timespec tstart,tcur;
struct radioinfo ri;
memset(&ri,0,sizeof(ri));
struct radioinfo * rip = &wtpinfo->radioinfo[0];
/*
ri.rmac[0]=6;
ri.rmac[2]=14;
ri.rmac[3]=14;
ri.rmac[4]=14;
ri.rmac[5]=14;
ri.rmac[6]=14;
ri.rmac[7]=14;
*/
#ifdef WITH_CW_LOG_DEBUG
char str[100];
sock_addrtostr((struct sockaddr*)&conn->addr,str,100);
// cw_log_debug0("Sending discovery request to %s",str);
#endif
int rc;
do {
conn->capwap_mode=CWMODE_CISCO;
rc = cwsend_discovery_request(conn,rip,wtpinfo);
if (rc<0){
if (errno == EINTR)
continue;
if (errno == EMSGSIZE){
conn->mtu-=4;
// cw_log_debug2("Setting mtu to %i",conn->mtu);
continue;
}
}
break;
}while (rc<0);
if (rc < 0 )
{
char str[100];
sock_addrtostr((struct sockaddr*)&conn->addr,str,100);
cw_log(LOG_ERR,"Error sending discovery request to %s: %s",str,strerror(errno));
return 0; return 0;
}
struct connlist * connlist;
connlist = connlist_create(30);
// clock_gettime(CLOCK_REALTIME,&tstart);
//
int tstart = time(0);
int treset = 0;
do {
char buf[2048];
int buflen=2048;
struct sockaddr_storage sa;
socklen_t fromlen=sizeof(struct sockaddr_storage);
rc = recvfrom(conn->sock,buf,buflen,0,(struct sockaddr*)&sa,&fromlen);
if (rc<0){
if (errno==EINTR)
rc=0;
if (errno==EAGAIN)
rc=0;
if (errno==EWOULDBLOCK)
rc=0;
}
if (rc>0) {
#ifdef WITH_CW_LOG_DEBUG
char str[100];
sock_addrtostr((struct sockaddr*)&sa,str,100);
// cw_log_debug0("Received packet from %s",str);
#endif
struct conn * rconn;
rconn = connlist_get(connlist,(struct sockaddr*)&sa);
if (!rconn){
rconn = conn_create_noq(conn->sock,(struct sockaddr*)&sa); //msg_cb,NULL,0);
// rconn->pmsgarg=conn->pmsgarg;
rconn->mtu = conn->mtu;
rconn->seqnum=conn->seqnum;
connlist_add(connlist,rconn);
}
conn_process_packet(rconn,(uint8_t*)buf,rc,msg_cb,di);
}
/* reset discovery timer after we have received the first response */
if ( di->response_count == 1 && !treset ){
tstart=time(0);
treset=1;
}
//clock_gettime(CLOCK_REALTIME,&tcur);
// printf("TTSub: %i %i\n",time(0)-tstart, conf_discovery_interval);
}while(time(0)-tstart < conf_discovery_interval && rc>=0 );
if (rc <0){
char str[100];
sock_addrtostr((struct sockaddr*)&conn->addr,str,100);
cw_log(LOG_ERR,"Error sendings discovery request to %s: %s",str,strerror(errno));
}
connlist_destroy(connlist);
return 1;
} }
static int discovery_count;
ACIPLIST * do_discovery(const char *acaddr)
/**
* Run discovery for on address (eg broadcast 255.255.255.255)
*/
static int cw_run_discovery(struct conn *conn, const char *acaddr)
{ {
/* get an partially intialized connection object
* (seqnum should be set)
* */
struct conn * conn = get_conn();
if (!conn){
cw_log(LOG_ERR,"Can't create conn for %s: %s",acaddr,strerror(errno));
return 0;
}
/* get addr of destination */ /* get addr of destination */
struct addrinfo hints; struct addrinfo hints;
struct addrinfo * res,*res0; struct addrinfo * res,*res0;
@ -285,21 +87,8 @@ ACIPLIST * do_discovery(const char *acaddr)
return 0; return 0;
} }
struct discovery_info di;
memset (&di,0,sizeof(struct discovery_info));
di.aciplist = aciplist_create();
di.response_count=0;
for(res=res0; res; res=res->ai_next) for(res=res0; res; res=res->ai_next)
{ {
if ( discovery_count >= conf_max_discoveries){
sulking_state();
discovery_count=0;
// cw_log_debug0("Entering discovery state");
}
discovery_count++;
int sockfd; int sockfd;
int opt; int opt;
@ -311,39 +100,30 @@ ACIPLIST * do_discovery(const char *acaddr)
opt = 1; opt = 1;
if (setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &opt, sizeof(opt))<0){ if (setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &opt, sizeof(opt))<0){
cw_log(LOG_ERR,"Cant set broadcast sockopt"); cw_log(LOG_ERR,"Can't set broadcast sockopt");
} }
sock_set_recvtimeout(sockfd,1); sock_set_recvtimeout(sockfd,1);
sock_set_dontfrag(sockfd,0); sock_set_dontfrag(sockfd,0);
di.conn=conn;
sock_copyaddr(&conn->addr,res->ai_addr); sock_copyaddr(&conn->addr,res->ai_addr);
conn->sock=sockfd; conn->sock=sockfd;
do_discover_conn(conn,&di); run_discovery(conn);
if ( di.aciplist->count != 0){
set_sock(sockfd);
break;
}
close(sockfd); close(sockfd);
} }
freeaddrinfo(res0); freeaddrinfo(res0);
if (di.aciplist->count){
cw_dbg(DBG_CW_INFO,"Discovery responses received: %i\n",di.response_count);
return di.aciplist;
}
aciplist_destroy(di.aciplist);
return 0; return 0;
} }
int discovery()
{
struct conn * conn = get_conn();
cw_run_discovery(conn,"255.255.255.255");
return 0;
}

View File

@ -13,7 +13,7 @@
#include "capwap/sock.h" #include "capwap/sock.h"
#include "capwap/dtls.h" #include "capwap/dtls.h"
/*
#define acinfo_log acinfo_log_ #define acinfo_log acinfo_log_
void acinfo_log_(int level,const struct ac_info *acinfo,const char * xstr) void acinfo_log_(int level,const struct ac_info *acinfo,const char * xstr)
@ -175,3 +175,6 @@ printf("Joined with conn %p\n",conn);
return 1; return 1;
} }
*/

View File

@ -14,6 +14,7 @@
#include "wtp_conf.h" #include "wtp_conf.h"
/*
static int echo_interval_timer; static int echo_interval_timer;
struct cwrmsg * get_response(struct conn * conn, int type,int seqnum) struct cwrmsg * get_response(struct conn * conn, int type,int seqnum)
@ -34,9 +35,10 @@ struct cwrmsg * get_response(struct conn * conn, int type,int seqnum)
return 0; return 0;
} }
*/
/*
struct cwrmsg * send_request(struct conn * conn,struct cwmsg *cwmsg) struct cwrmsg * send_request(struct conn * conn,struct cwmsg *cwmsg)
{ {
int i; int i;
@ -61,10 +63,11 @@ struct cwrmsg * send_request(struct conn * conn,struct cwmsg *cwmsg)
return 0; return 0;
} }
*/
//extern struct conn * get_conn();
extern struct conn * get_conn(); /*
int run(struct conn * conn) int run(struct conn * conn)
{ {
@ -135,4 +138,4 @@ printf("Error !\n");
} }
*/

View File

@ -1,7 +1,15 @@
#ifndef __WTP_H #ifndef __WTP_H
#define __WTP_H #define __WTP_H
#include "capwap/conn.h"
extern int sulking_state(); extern int sulking_state();
extern int join(); extern int join();
extern int discovery();
struct conn * get_conn();
#endif #endif

View File

@ -142,6 +142,8 @@ typedef struct {
extern LONGSTRS conf_timer_cfgstrs[]; extern LONGSTRS conf_timer_cfgstrs[];
int wtpconf_preinit();
int wtpconf_init();
#endif #endif

View File

@ -11,7 +11,7 @@
#include "wtp_conf.h" #include "wtp_conf.h"
#include "wtp_interface.h" #include "wtp_interface.h"
/*
struct wtpinfo * get_wtpinfo() struct wtpinfo * get_wtpinfo()
{ {
struct wtpinfo * wtpinfo; struct wtpinfo * wtpinfo;
@ -125,3 +125,8 @@ struct conn * get_conn()
printf("Get conn returns %p\n",conn); printf("Get conn returns %p\n",conn);
return conn; return conn;
} }
*/

View File

@ -3,119 +3,29 @@
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
//#include <iwlib.h>
#include "capwap/sock.h"
#include "capwap/conn.h"
#include "capwap/dtls.h"
#include "capwap/avltree.h"
#include "capwap/cw_log.h"
#include "capwap/capwap.h" #include "capwap/capwap.h"
#include "capwap/cw_util.h" #include "capwap/capwap_items.h"
#include "capwap/wtpinfo.h" #include "capwap/conn.h"
#include "capwap/cw_log.h"
#include "capwap/dtls.h"
#include "wtp.h" #include "wtp.h"
#include "wtp_conf.h" #include "wtp_conf.h"
struct wtpinfo wtpinfo; /** The one and only connection object */
struct conn *the_conn;
//int conf_rids[2]; struct cw_actiondef capwap_actions;
//int conf_rids_len[2];
//int responses = 0;
struct avltree * aclist =0;
extern struct wpa_driver_ops *wpa_drivers[];
#include <stdio.h>
#include <sys/types.h>
#include <ifaddrs.h>
#include <sys/socket.h>
//struct sockaddr conf_preferred_ac;
static void * drv_priv[2];
static void * drv_glob[2];
const char * interfaces[]={
"wlan0",
"wlan1-1"
};
/*static int drv_init()
{
return 1;
}
*/
int main() int main()
{ {
wtp_main();
}
#include <time.h>
int pmu;
//#include <openssl/ssl.h>
int do_connect(void *priv,void *data)
{
ACIP * ip = (ACIP*)data;
// char str[100];
// sock_addrtostr((struct sockaddr*)&ip->ip,str,100);
sock_setport(&ip->ip,atoi(conf_control_port));
// printf("Would connect to %s\n",str);
printf("Sleep 5000\n");
printf("slept\n");
int rc;
rc = join(&ip->ip);
if (!rc)
return 1;
printf("Sleep after oin\n");
printf("Go conf\n");
// extern struct conn * get_conn();
// extern join_state(struct conn * conn);
// struct conn * conn = get_conn();
//printf("Join conn = %p\n",conn);
// join_state(conn);
// rc = join(&ip->ip);
// if (!rc)
// return 1;
rc = configure();
run (get_conn());
return 0;
}
#include "capwap/bstr.h"
int wtp_main(const char *ad)
{
wtpconf_preinit(); wtpconf_preinit();
if (!read_config("./wtp_uci.conf")){ if (!read_config("./wtp_uci.conf")) {
return 1; return 1;
} }
@ -123,59 +33,41 @@ int wtp_main(const char *ad)
wtpconf_init(); wtpconf_init();
cw_dbg_opt_detail=DBG_DETAIL_ASC_DMP; cw_dbg_opt_detail = DBG_DETAIL_ASC_DMP;
// cw_log_debug_level=6; //conf_debug_level;
// conf_dtls_psk="Tube";
// conf_sslkeyfilename="../../ssl/wtp.key";
// conf_sslcertfilename="../../ssl/wtp.crt";
// conf_dtls_psk=0;
// conf_sslkeyfilename="../../ssl/ac_cisco.key";
// conf_sslcertfilename="../../ssl/ac_cisco.pem";
conf_sslkeypass="Tube";
#ifdef WITH_DTLS
dtls_init(); dtls_init();
#endif
//drv_init(); the_conn = conn_create_noq(-1, NULL);
struct conn *conn = the_conn;
while (1){ cw_register_actions_capwap_wtp(&capwap_actions);
ACIPLIST * aciplist=0; conn->actions = &capwap_actions;
int i; conn->remote = cw_itemstore_create();
conn->local = cw_itemstore_create();
cw_dbg(DBG_CW_INFO,"Entering discovery state"); cw_itemstore_t board_data = cw_itemstore_create();
cw_itemstore_set_dword(board_data, CW_ITEM_WTP_BOARD_VENDOR, conf_vendor_id);
do {
for (i=0; i<conf_ac_list_len; i++){
if ((aciplist = do_discovery(conf_ac_list[i])))
break;
}
}while (!aciplist);
// cw_log_debug0("Entering join state");
if (!aciplist){
// cw_log_debug0("Don't got any discovery response");
exit(0);
}
aciplist_foreach(aciplist,do_connect,0);
aciplist_destroy(aciplist);
} cw_itemstore_set_bstrn(board_data, CW_ITEM_WTP_BOARD_MACADDRESS, conf_macaddress,
exit(0); conf_macaddress_len);
cw_itemstore_set_bstr16n(board_data, CW_ITEM_WTP_BOARD_SERIALNO,
bstr_data(conf_serial_no), bstr_len(conf_serial_no));
cw_itemstore_set_avltree(conn->local, CW_ITEM_WTP_BOARD_DATA, board_data);
discovery();
return 0; }
struct conn *get_conn()
{
return the_conn;
} }