Colored debugging...

FossilOrigin-Name: 153201cffee624726d6bcd3e428c0d69d7cc9e9cba6a84a5687de94a850550dd
This commit is contained in:
7u83@mail.ru 2015-04-11 17:00:51 +00:00
parent 4460a959b9
commit 73aba62d2b
66 changed files with 890 additions and 688 deletions

View File

@ -68,14 +68,11 @@ cw_aciplist_t get_aciplist()
void * get_iplist(void * arg)
{
printf("************************************************************************************\n");
printf("The ist an iplist getter\n");
return get_aciplist();
}
void release_iplist(void *arg,void *data)
{
printf("And an releaser\n");
}
int ac_global_init()

View File

@ -29,6 +29,7 @@
#include "wtplist.h"
#include "capwap/dtls.h"
#include "capwap/log.h"
#include "capwap/dbg.h"
#include "conf.h"
#include "capwap/sock.h"
@ -137,7 +138,7 @@ int main (int argc, const char * argv[])
cw_log(LOG_INFO,"Starting AC-Tube, Name=%s, ID=%s",conf_acname,conf_acid);
cw_dbg_opt_detail=DBG_DETAIL_ASC_DMP;
cw_dbg_opt_display=DBG_DISP_ASC_DMP | DBG_DISP_COLORS;
cw_register_actions_cipwap_ac(&capwap_actions);
@ -305,7 +306,7 @@ void process_cw_ctrl_packet(int index,struct sockaddr * addr, uint8_t * buffer,
char hdrstr[1024];
hdr_print(hdrstr,buffer,len);
cw_dbg(DBG_CW_PKT_IN,"Header for packet from %s\n%s",sock_addr2str(addr),hdrstr);
// cw_dbg(DBG_CW_PKT_IN,"Header for packet from %s\n%s",sock_addr2str(addr),hdrstr);
@ -317,7 +318,7 @@ void process_cw_ctrl_packet(int index,struct sockaddr * addr, uint8_t * buffer,
#else
if (preamble != CAPWAP_PACKET_PREAMBLE ){
#endif
cw_dbg(DBG_CW_PKT_ERR,"Discarding packet, wrong preamble, preamble = 0x%01X",preamble);
cw_dbg(DBG_PKT_ERR,"Discarding packet, wrong preamble, preamble = 0x%01X",preamble);
return;
}
@ -428,10 +429,10 @@ void process_ctrl_packet(int index,struct sockaddr * addr, uint8_t * buffer, int
#ifdef WITH_CW_LOG_DEBUG
char str[100];
sock_addrtostr(addr,str,100);
cw_dbg(DBG_CW_PKT_IN,"Received packet from %s, len = %i, via %s\n",sock_addr2str(addr),len,
socklist[index].type==SOCKLIST_UNICAST_SOCKET ? "unicast":"bcast/mcast");
// cw_dbg(DBG_PKT_IN,"Received packet from %s, len = %i, via %s\n",sock_addr2str(addr),len,
// socklist[index].type==SOCKLIST_UNICAST_SOCKET ? "unicast":"bcast/mcast");
cw_dbg_dmp(DBG_CW_PKT_DMP,buffer,len,"Dump ...");
// cw_dbg_dmp(DBG_CW_PKT_DMP,buffer,len,"Dump ...");
// cw_dbg_dmp(buffer,len,"Packet data for packet, recevied from %s",str);
#endif

View File

@ -27,6 +27,7 @@
#include "conf.h"
#include "capwap/log.h"
#include "capwap/dbg.h"
#include "capwap/cw_util.h"
uint8_t conf_macaddress[12];
@ -537,12 +538,13 @@ static int conf_read_strings( cfg_t * cfg, char * name, char ***dst,int *len)
}
/*
struct conf_dbg_level_names{
const char *name;
int level;
};
*/
static int conf_read_dbg_level(cfg_t *cfg)
@ -555,7 +557,7 @@ static int conf_read_dbg_level(cfg_t *cfg)
for (i=0; i<n; i++) {
char * str = cfg_getnstr(cfg,name,i);
//int u = cw_log_str2dbglevel(str);
cw_dbg_opt_level|=cw_log_str2dbglevel(str);
cw_dbg_opt_level|= cw_strlist_get_id(cw_dbg_strings,str); //cw_log_str2dbglevel(str);
}
return 1;

View File

@ -2,6 +2,7 @@
#include <sqlite3.h>
#include "capwap/log.h"
#include "capwap/dbg.h"
#include "conf.h"
@ -18,7 +19,7 @@ int db_init()
{
const char * filename="ac.sqlite3";
cw_dbg(DBG_CW_INFO,"Init sqlite3 db: %s",filename);
cw_dbg(DBG_INFO,"Init sqlite3 db: %s",filename);
int rc = sqlite3_open(filename,&handle);
if (rc)
{
@ -46,7 +47,7 @@ static sqlite3_stmt * ping_stmt;
int db_start()
{
cw_dbg(DBG_CW_INFO,"Start sqlite3 db");
cw_dbg(DBG_INFO,"Start sqlite3 db");
sqlite3_stmt *stmt;
int rc = sqlite3_prepare_v2(handle, "INSERT INTO acs (acid,acname) VALUES (?,?);",-1,&stmt,0);

View File

@ -15,6 +15,7 @@
#include "wtpman.h"
#include "conf.h"
#include "capwap/log.h"
#include "capwap/timer.h"
#include "conf.h"
@ -35,6 +36,8 @@
#include "capwap/dtls.h"
#include "capwap/dbg.h"
extern struct cw_actiondef capwap_actions;
@ -91,7 +94,7 @@ static void wtpman_remove(struct wtpman *wtpman)
int check_discovery(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len)
{
printf("Discovery END!!!\n");
conn->capwap_state=CW_STATE_NONE;
conn->capwap_state = CW_STATE_NONE;
return 0;
}
@ -173,7 +176,7 @@ static void wtpman_run_discovery(void *arg)
char wtpinfostr[8192];
wtpinfo_print(wtpinfostr, &wtpman->wtpinfo);
cw_dbg(DBG_CW_INFO, "Discovery request gave us the follwing WTP Info:\n%s",
cw_dbg(DBG_INFO, "Discovery request gave us the follwing WTP Info:\n%s",
wtpinfostr);
@ -190,7 +193,7 @@ static void wtpman_run_discovery(void *arg)
/* char wtpinfostr[8192];
wtpinfo_print(wtpinfostr,&wtpman->wtpinfo);
cw_dbg(DBG_CW_INFO,"Discovery request gave us the follwing WTP Info:\n%s",wtpinfostr);
cw_dbg(DBG_INFO,"Discovery request gave us the follwing WTP Info:\n%s",wtpinfostr);
*/
cwsend_discovery_response(wtpman->conn, cwrmsg->seqnum, &radioinfo, acinfo,
@ -223,8 +226,8 @@ static int wtpman_establish_dtls(void *arg)
wtpman->conn->dtls_cert_file = conf_sslcertfilename;
wtpman->conn->dtls_key_pass = conf_sslkeypass;
wtpman->conn->dtls_verify_peer = conf_dtls_verify_peer;
cw_dbg(DBG_DTLS, "DTLS - Using key file %s", wtpman->conn->dtls_key_file);
cw_dbg(DBG_DTLS, "DTLS - Using cert file %s",
cw_dbg(DBG_DTLS, "Using key file %s", wtpman->conn->dtls_key_file);
cw_dbg(DBG_DTLS, "Using cert file %s",
wtpman->conn->dtls_cert_file);
dtls_ok = 1;
}
@ -258,12 +261,11 @@ static int wtpman_establish_dtls(void *arg)
FILE *f;
f = fopen("pcert.der", "wb");
printf("Calling peers cert\n");
cert = dtls_get_peers_cert(wtpman->conn, 0);
printf("Back from peers cert\n");
printf("Have Peers Cert: %p, %d\n", cert.data, cert.size);
fwrite(cert.data, 1, cert.size, f);
// printf("Have Peers Cert: %p, %d\n", cert.data, cert.size);
// fwrite(cert.data, 1, cert.size, f);
fclose(f);
return 1;
@ -284,6 +286,11 @@ static int wtpman_join(void *arg, time_t timer)
wtpman->conn->outgoing = ac_config;
wtpman->conn->incomming = cw_itemstore_create();
wtpman->conn->local = cw_itemstore_create();
struct conn * conn = wtpman->conn;
cw_dbg(DBG_INFO,"Join State - %s",sock_addr2str(&conn->addr));
while (!cw_timer_timeout(timer) && wtpman->conn->capwap_state == CW_STATE_JOIN) {
int rc = cw_read_messages(wtpman->conn);
@ -292,13 +299,13 @@ static int wtpman_join(void *arg, time_t timer)
}
}
if (wtpman->conn->capwap_state==CW_STATE_JOIN){
if (wtpman->conn->capwap_state == CW_STATE_JOIN) {
cw_dbg(DBG_MSG_ERR, "No join request from %s after %d seconds, WTP died.",
sock_addr2str(&wtpman->conn->addr), wtpman->conn->wait_dtls);
return 0;
}
return 1;
@ -384,280 +391,76 @@ static void wtpman_run(void *arg)
State is Image update
*/
while (!cw_timer_timeout(timer) && wtpman->conn->capwap_state == CW_STATE_CONFIGURE) {
int rc = cw_read_messages(wtpman->conn);
int rc = 0;
while (!cw_timer_timeout(timer)
&& wtpman->conn->capwap_state == CW_STATE_CONFIGURE) {
rc = cw_read_messages(wtpman->conn);
if (rc < 0) {
break;
if (errno != EAGAIN)
break;
}
}
if (!rc) {
cw_dbg(DBG_INFO, "WTP Problem: %s", cw_strrc(rc));
}
struct conn *conn = wtpman->conn;
exit(0);
/*
do {
int cfg_status_msgs[] =
{ CW_MSG_IMAGE_DATA_REQUEST, CW_MSG_CONFIGURATION_STATUS_REQUEST,
-1 };
cwrmsg = conn_wait_for_request(wtpman->conn, cfg_status_msgs, timer);
if (!cwrmsg) {
cw_dbg(DBG_MSG_ERR,
"No conf status or img data request from %s after %d seconds, WTP died.",
sock_addr2str(&wtpman->conn->addr),
wtpman->conn->wait_join);
wtpman_remove(wtpman);
if (conn->capwap_state == CW_STATE_IMAGE_DATA) {
/* Image upload */
const char *filename =
cw_itemstore_get_str(conn->outgoing, CW_ITEM_IMAGE_FILENAME);
if (!filename) {
cw_log(LOG_ERR,
"Can't send image to %s. No Image Filename Item found.",
sock_addr2str(&conn->addr));
return;
}
cw_dbg(DBG_INFO, "Sending image file '%s' to '%s'.", filename,
sock_addr2str(&conn->addr));
FILE *infile = fopen(filename, "rb");
if (infile == NULL) {
cw_log(LOG_ERR, "Can't open image %s: %s",
sock_addr2str(&conn->addr), strerror(errno));
return;
}
// Image data request, the WTP wants an update
if (cwrmsg->type == CW_MSG_IMAGE_DATA_REQUEST) {
int rc = wtpman_send_image_file(wtpman, cwrmsg);
if (rc) {
wtpman_remove(wtpman);
return;
}
cw_itemstore_set_const_ptr(conn->outgoing, CW_ITEM_IMAGE_FILEHANDLE,
infile);
clock_t clk = cw_clock_start();
int rc=0;
while (conn->capwap_state == CW_STATE_IMAGE_DATA && !feof(infile) && rc==0) {
rc = cw_send_request(conn, CW_MSG_IMAGE_DATA_REQUEST);
}
} while (cwrmsg->type != CW_MSG_CONFIGURATION_STATUS_REQUEST);
printf("Have Masseg %d\n", cwrmsg->type);
cwread_configuration_status_request(&wtpman->wtpinfo, cwrmsg->msgelems,
cwrmsg->msgelems_len);
int result_code = 0;
struct ac_info *acinfo = get_acinfo();
struct radioinfo rinf;
cwsend_conf_status_response(wtpman->conn, cwrmsg->seqnum, result_code, &rinf,
acinfo, &wtpman->wtpinfo);
printf("Send the respi but sleep\n");
printf("Next thoing\n");
int change_status_msgs[] =
{ CW_MSG_IMAGE_DATA_REQUEST, CW_MSG_CHANGE_STATE_EVENT_REQUEST, -1 };
cwrmsg = conn_wait_for_request(wtpman->conn, change_status_msgs, timer);
printf("Done\n");
if (!cwrmsg) {
wtpman_remove(wtpman);
return;
}
switch (cwrmsg->type) {
case CW_MSG_CHANGE_STATE_EVENT_REQUEST:
{
printf("Change state event\n!");
struct radioinfo ri;
cwsend_change_state_event_response(wtpman->conn,
cwrmsg->seqnum, &ri);
}
break;
case CW_MSG_IMAGE_DATA_REQUEST:
printf("Image update\n!");
//cwread_image_data_request(0,cwrmsg->msgelems,cwrmsg->msgelems_len);
//cwsend_image_data_response(wtpman->conn,cwrmsg->seqnum,CW_RESULT_SUCCESS);
//send_image_file(wtpman->conn,"/tftpboot/c1130-k9w7-tar.default");
// send_image_file(wtpman->conn,"/home/tube/Downloads/c1130-k9w7-tar.123-8.JEA3.tar");
// send_image_file(wtpman->conn,"/home/tube/Downloads/c1130-k9w8-tar.124-25e.JAP.tar");
// send_image_file(wtpman->conn,"/home/tube/Downloads/c1130-rcvk9w8-tar.124-25e.JAP.tar");
break;
}
printf("WTP is joined now\n");
*/
/*
struct radioinfo * radioinfo;
cwrmsg = wtpman_wait_for_message(wtpman,timer);
if (!cwrmsg){
cw_dbg(DBG_CW_MSG_ERR,"No config or update request from %s after %d seconds, WTP died.",
sock_addr2str(&wtpman->conn->addr),wtpman->conn->wait_join);
wtpman_remove(wtpman);
return;
}
printf("CWR TYPE %d\n",cwrmsg->type);
exit(0);
*/
// cwread_configuration_status_request(&wtpman->wtpinfo,cwrmsg->msgelems, cwrmsg->msgelems_len);
// cwsend_conf_status_response(wtpman->conn,cwrmsg->seqnum,result_code,&radioinfo,acinfo,&wtpman->wtpinfo);
/*
char wtpinfostr[8192];
wtpinfo_print(wtpinfostr, &wtpman->wtpinfo);
cw_dbg(DBG_ALL, "WTP conf_status\n%s", wtpinfostr);
printf("Run run run run run\n");
wtpman_run_run(wtpman);
exit(0);
*/
/*
int ii;
for (ii=0; ii<3; ii++){
cwrmsg = wtpman_wait_for_message(wtpman,timer);
if (cwrmsg){
if (cwrmsg->type == CWMSG_CHANGE_STATE_EVENT_REQUEST){
cwread_change_state_event_request(&wtpman->wtpinfo,cwrmsg->msgelems,cwrmsg->msgelems_len);
cwsend_change_state_event_response(wtpman->conn,cwrmsg->seqnum,wtpman->wtpinfo.radioinfo);
if (rc) {
cw_log(LOG_ERR,"Image download RC: %s",cw_strrc(rc));
}
}
}
*/
/*
wtpman_run_run(wtpman);
exit(0);
if (cwrmsg->type == CW_MSG_IMAGE_DATA_REQUEST) {
cwread_image_data_request(0, cwrmsg->msgelems, cwrmsg->msgelems_len);
cwsend_image_data_response(wtpman->conn, cwrmsg->seqnum,
CW_RESULT_FAILURE);
}
*/
/*
printf("Sending image file\n");
send_image_file(wtpman->conn,"/home/tube/Downloads/c1130-rcvk9w8-tar.124-25e.JAO5.tar");
printf("Back from sending image file\n");
*/
exit(0);
/*
timer = cw_timer_start(30);
cwrmsg = wtpman_wait_for_message(wtpman, timer);
if (cwrmsg)
printf("I have got a message of type %d\n", cwrmsg->type);
if (cwrmsg->type == CW_MSG_IMAGE_DATA_REQUEST) {
cwread_image_data_request(0, cwrmsg->msgelems, cwrmsg->msgelems_len);
cwsend_image_data_response(wtpman->conn, cwrmsg->seqnum,
CW_RESULT_FAILURE);
}
*/
// char wtpinfostr[8192];
// wtpinfo_print(wtpinfostr,&wtpman->wtpinfo);
// cw_log_debug0("WTP joined\n%s",wtpinfostr);
//exit(0);
/*
int msg_counter = 0;
while (1) {
struct cwrmsg *cwrmsg = conn_get_message(wtpman->conn);
if (!cwrmsg) {
msg_counter++;
if (msg_counter < CAPWAP_ECHO_INTERVAL * 2)
continue;
// cw_log_debug0("WTP died");
wtpman_remove(wtpman);
return;
else {
cw_dbg(DBG_INFO,"Image '%s' sucessful sent to %s in %0.1f seconds.",
filename,sock_addr2str(&conn->addr),cw_clock_stop(clk));
conn->capwap_state=CW_STATE_NONE;
}
*/
/*
if (cwrmsg->type == CWMSG_CONFIGURATION_STATUS_REQUEST){
process_conf_status_request(&wtpman->wtpinfo,cwrmsg->msgelems,cwrmsg->msgelems_len);
{
char wtpinfostr[8192];
wtpinfo_print(wtpinfostr,&wtpman->wtpinfo);
cw_dbg(DBG_CW_INFO,"Join request gave us the follwing WTP Info:\n%s",wtpinfostr);
cwsend_conf_status_response(wtpman->conn,cwrmsg->seqnum,result_code,&radioinfo,acinfo,&wtpman->wtpinfo);
}
}
*/
/*
msg_counter = 0;
if (cwrmsg->type == CW_MSG_ECHO_REQUEST) {
cwsend_echo_response(wtpman->conn, cwrmsg->seqnum,
wtpman->wtpinfo.radioinfo);
}
*/
// printf("Got msg: %i\n",cwrmsg->type);
}
fclose(infile);
// process_discovery(wtpman,cwrmsg);
/*
while (1) {
uint8_t *packet = conn_q_get_packet(wtpman->conn);
// int len = *( (uint32_t*)(packet));
// conn_process_packet(wtpman->conn,packet+4,len);
free(packet);
}
*/
return;
}
void wtpman_destroy(struct wtpman *wtpman)
{
if (wtpman->conn)
@ -754,11 +557,11 @@ void wtpman_lw_addpacket(struct wtpman *wtpman, uint8_t * packet, int len)
void wtpman_start(struct wtpman *wtpman, int dtlsmode)
{
if (dtlsmode) {
cw_dbg(DBG_CW_INFO, "Starting wtpman in DTLS mode");
cw_dbg(DBG_INFO, "Starting wtpman in DTLS mode");
pthread_create(&wtpman->thread, NULL, (void *) &wtpman_run,
(void *) wtpman);
} else {
cw_dbg(DBG_CW_INFO, "Starting wtpman in non-dtls mode");
cw_dbg(DBG_INFO, "Starting wtpman in non-dtls mode");
pthread_create(&wtpman->thread, NULL, (void *) &wtpman_run_discovery,
(void *) wtpman);
}

View File

@ -38,8 +38,8 @@ LOGOBJS=log.o \
log_syslog.o \
log_file.o \
cw_log_debug.o \
cw_log_str2dbglevel.o \
cw_dbg_elem.o
cw_dbg_elem.o \
dbg_strings.o
@ -74,7 +74,6 @@ LWAPPOBJS = \
lw_checksum.o \
lw_put_ac_descriptor.o \
lw_put_cisco_path_mtu.o \
lw_readelem_wtp_name.o \
lw_put_80211_wtp_wlan_radio_configuration.o \
lw_readelem_vendor_specific.o \
lw_vendor_id_to_str.o \
@ -83,6 +82,8 @@ LWAPPOBJS = \
lw_cisco_id_to_str.o \
lw_put_sockaddr.o \
# lw_readelem_wtp_name.o \
lw_readelem_wtp_board_data.o \
# LWAPP cisco vendor specific objs
@ -95,20 +96,17 @@ LWAPPCISCOOBJS = \
CAPWAPOBJS= \
cwmsg_addelem_maximum_message_length.o \
cwmsg_addelem_image_identifier.o \
cwmsg_send.o \
wtpinfo.o \
aciplist.o \
acinfo.o \
acinfo_print.o \
lwmsg_init.o \
wtpinfo_lwreadelem_wtp_descriptor.o \
hdr_print.o \
cwmsg_addelem_vendor_cisco_mwar_addr.o \
lw_readelem_wtp_board_data.o \
cw_cisco_id_to_str.o\
cw_strlist_get_str.o \
cw_strlist_get_id.o \
capwap_strings_msg.o \
capwap_strings_elem80211.o\
acpriolist.o\
@ -122,9 +120,12 @@ CAPWAPOBJS= \
cw_in_check_disc_resp.o\
cw_in_check_join_req.o \
cw_in_check_join_resp.o \
cw_in_check_img_data_req.o \
cw_in_check_img_data_req_ac.o \
cw_in_check_img_data_req_wtp.o \
cw_in_check_img_data_resp.o \
cw_out_generic.o \
cw_out_ac_descriptor.o \
cw_out_wtp_descriptor.o \
cw_out_cisco_ac_descriptor.o \
cw_out_cisco_ap_timesync.o \
cw_in_cisco_image_identifier.o\
@ -137,12 +138,15 @@ CAPWAPOBJS= \
format.o \
#acinfo.o \
# cwsend_unknow_response.o \
cw_send_configuration_update_response.o \
cwsend_echo_request.o \
cwmsg_init_echo_request.o \
cwmsg_addelem.o \
cwmsg_vaddelem.o \
cw_log_str2dbglevel.o \
cwmsg_addelem_maximum_message_length.o \
cwmsg_addelem_ac_descriptor.o \
cwmsg_addelem_wtp_descriptor.o \
cwmsg_addelem_cw_local_ip_addr.o \
@ -157,6 +161,7 @@ cw_readelem_maximum_message_length.o \
cw_readelem_result_code.o\
cw_readelem_ac_name.o \
cw_readelem_ac_descriptor.o \
conn_detect_capwap.o \
cw_readelem_radio_administrative_state.o \
cw_readelem_radio_operational_state.o \
cw_readelem_statistics_timer.o \
@ -164,6 +169,7 @@ cw_readelem_maximum_message_length.o \
cw_readelem_vendor_specific_payload.o \
cw_readelem_capwap_local_ip_addr.o \
cw_readelem_wtp_reboot_statistics.o\
cwmsg_addelem_image_identifier.o \
conn_get_response.o \
# cwsend_change_state_event_response.o \
cwread_discovery_response.o \
@ -174,6 +180,7 @@ cw_readelem_maximum_message_length.o \
cwread_wtp_event_request.o \
process_conf_status_request.o \
cw_readelem_ecn_support.o \
conn_wait_for_message.o \
# wtpinfo_readelem_wtp_mac_type.o \
# wtpinfo_readelem_wtp_descriptor.o \
@ -251,7 +258,6 @@ endif
DTLSOBJS+=dtls_bio.o
CONNOBJS= conn_create.o \
conn_detect_capwap.o \
conn_send_packet.o \
conn_process_packet.o \
conn_q_add_packet.o \
@ -266,7 +272,6 @@ CONNOBJS= conn_create.o \
cw_prepare_configuration_status_request.o \
cw_prepare_change_state_event_request.o \
conn_prepare_request.o \
conn_wait_for_message.o \
conn_init.o \
conn_send_msg.o
#conn_get_message.o \
@ -288,6 +293,7 @@ CWACTION=action.o \
cw_in_generic.o \
cw_in_wtp_descriptor.o \
cw_out_wtp_board_data.o \
cw_out_image_data.o \
cipwap_actions_ac.o \
cipwap_strings_elem.o \
capwap_strings_result.o\
@ -311,7 +317,7 @@ 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 -O3 -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) \
-DWITH_CW_LOG \

View File

@ -137,11 +137,12 @@ static int cw_action_out_cmp(const void *elem1, const void *elem2)
*/
void *cw_actionlist_add(struct avltree *t, void *a, size_t s)
{
void *r = avltree_replace_data(t, a, sizeof(struct cw_action_in));
if (r)
return r;
void *an = malloc(sizeof(struct cw_action_in));
void *an = malloc(s);
if (!an)
return NULL;

View File

@ -78,7 +78,9 @@ struct cw_action_out{
struct cw_item *(*get)(struct conn *conn,struct cw_action_out *a);
uint8_t mand;
uint8_t itemtype;
void *defval;
int xopt;
};
@ -99,7 +101,7 @@ struct cw_actiondef{
cw_strheap_t strmsg;
cw_strheap_t strelem;
};

View File

@ -34,7 +34,7 @@
#include "conn.h"
#include "lwapp.h"
#include "strheap.h"
#include "strlist.h"
/* capwap version and iana number */
#define CW_VERSION 0
@ -86,7 +86,7 @@ enum capwap_states {
/**
* CAWAP header flags.
*/
*/
#define CW_FLAG_HDR_R1 0x01 /* bit 0 reserved 1 */
#define CW_FLAG_HDR_R2 0x02 /* bit 1 reserved 2 */
#define CW_FLAG_HDR_R3 0x04 /* bit 2 reserved 3 */
@ -478,15 +478,15 @@ extern int cw_readelem_vendor_specific_payload(void *data, int msgtype, int elem
14 Image Data Error (Invalid Checksum)
*/
#define CW_RESULT_IMAGE_DATA_IVALID_LENGTH 15 //Image Data Error (Invalid Data Length)
#define CW_RESULT_IMAGE_DATA_IVALID_LENGTH 15 //Image Data Error (Invalid Data Length)
#define CW_RESULT_IMAGE_DATA_OTHER_ERROR 16 //Image Data Error (Other Error)
#define CW_RESULT_IMAGE_DATA_ERROR 16 //Image Data Error (Other Error)
/*
17 Image Data Error (Image Already Present)
*/
#define CW_RESULT_MSG_INVALID_IN_CURRENT_STATE 18
#define CW_RESULT_MSG_UNRECOGNIZED 19
#define CW_RESULT_MSG_INVALID_IN_CURRENT_STATE 18
#define CW_RESULT_MSG_UNRECOGNIZED 19
#define CW_RESULT_MISSING_MAND_ELEM 20
/*
@ -571,36 +571,39 @@ extern int cw_readmsg_configuration_update_request(uint8_t * elems, int elems_le
* Set the HLEN 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_hlen(uint8_t *th,int hlen){
*/
static inline void cw_set_hdr_hlen(uint8_t * th, int hlen)
{
uint32_t d = cw_get_dword(th);
d &= (0x1f << 19) ^ 0xffffffff;
d |= ((hlen) & 0x1f) <<19;
cw_set_dword(th,d);
d |= ((hlen) & 0x1f) << 19;
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){
*/
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);
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){
*/
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);
d |= ((rid) & 0x1f) << 14;
cw_set_dword(th, d);
}
@ -641,7 +644,7 @@ static inline uint8_t *cw_get_hdr_msg_elems_ptr(uint8_t * m)
return cw_get_msg_elems_ptr(m + cw_get_hdr_msg_offset(m));
}
static inline uint8_t * cw_get_hdr_msg_ptr(uint8_t *rawmsg)
static inline uint8_t *cw_get_hdr_msg_ptr(uint8_t * rawmsg)
{
return rawmsg + cw_get_hdr_msg_offset(rawmsg);
}
@ -654,7 +657,7 @@ static inline int cw_get_hdr_msg_total_len(uint8_t * rawmsg)
{
int offset = cw_get_hdr_msg_offset(rawmsg);
return offset + cw_get_msg_elems_len(rawmsg + offset)+8 ;
return offset + cw_get_msg_elems_len(rawmsg + offset) + 8;
}
/**
@ -855,16 +858,23 @@ extern struct cw_str capwap_strings_result[];
#define cw_strresult(id) cw_strlist_get_str(capwap_strings_result,(id))
static inline const char * cw_strelemp_(cw_strheap_t h, int msg_id) {
const char * rc = cw_strheap_get(h,msg_id);
#define cw_strrc(rc) \
((rc)<0 ? ((rc)!=EAGAIN ? strerror(errno):"Timed out"): cw_strresult(rc))
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,CW_STR_STOP);
return cw_strheap_get(h, CW_STR_STOP);
}
#define cw_strelemp(p,id) cw_strelemp_((p)->strelem,id)
extern const char *cw_strlist_get_str(struct cw_str *s, int id);
@ -882,22 +892,27 @@ extern int cw_in_wtp_board_data(struct conn *conn, struct cw_action_in *a, uint8
int len);
extern int cw_in_wtp_descriptor(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len);
extern int cw_in_capwap_control_ipv4_address(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len);
extern int cw_in_capwap_control_ipv4_address(struct conn *conn, struct cw_action_in *a,
uint8_t * data, int len);
//extern int cw_out_generic(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len);
extern int cw_out_generic(struct conn *conn, struct cw_action_out *a, uint8_t * dst); //, struct cw_item *item);
extern int cw_out_generic(struct conn *conn, struct cw_action_out *a, uint8_t * dst); //, struct cw_item *item);
//extern int cw_out_ac_descriptor(struct conn *conn, uint32_t elem_id, uint8_t * dst,
//struct cw_item *item);
extern int cw_out_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_t *dst); //,struct cw_item * item)
extern int cw_out_ac_descriptor(struct conn *conn, struct cw_action_out *a, uint8_t * dst); //,struct cw_item * item)
extern int cw_out_wtp_descriptor(struct conn *conn, struct cw_action_out *a,
uint8_t * dst);
//extern int cw_out_capwap_control_ip_addrs(struct conn *conn, uint32_t elem_id,
// uint8_t * dst, struct cw_item *item);
// uint8_t * dst, struct cw_item *item);
extern int cw_out_capwap_control_ip_addr_list(struct conn *conn,struct cw_action_out *a,uint8_t *dst) ;
extern int cw_out_capwap_control_ip_addr_list(struct conn *conn, struct cw_action_out *a,
uint8_t * dst);
extern int cw_put_msg(struct conn *conn, uint8_t * rawout);
int cw_out_image_data(struct conn *conn, struct cw_action_out *a, uint8_t * dst); // ,struct cw_item * item)
struct cw_ac_status {
@ -918,23 +933,25 @@ struct cw_ac_status {
* This function is only useful (used) in conjunction with
* putting AC Descriptor message elements.
*/
static inline int cw_put_ac_status(uint8_t *dst, struct cw_ac_status *s){
uint8_t *d=dst;
static inline int cw_put_ac_status(uint8_t * dst, struct cw_ac_status *s)
{
uint8_t *d = dst;
d += cw_put_dword (d, (s->stations << 16) | (s->limit) );
d += cw_put_dword (d, (s->active_wtps <<16) | (s->max_wtps) );
d += cw_put_dword (d, (s->security<<24) | (s->rmac_field<<16) | (s->dtls_policy));
return d-dst;
d += cw_put_dword(d, (s->stations << 16) | (s->limit));
d += cw_put_dword(d, (s->active_wtps << 16) | (s->max_wtps));
d += cw_put_dword(d,
(s->security << 24) | (s->rmac_field << 16) | (s->dtls_policy));
return d - dst;
}
static inline int cw_put_version(uint8_t *dst,uint16_t subelem_id, uint8_t *v)
static inline int cw_put_version(uint8_t * dst, uint16_t subelem_id, uint8_t * v)
{
uint8_t *d=dst;
d += cw_put_dword(d,vendorstr_get_vendor_id(v));
d += cw_put_dword(d, (subelem_id<<16) | vendorstr_len(v));
d += cw_put_data(d,vendorstr_data(v),vendorstr_len(v));
return d-dst;
uint8_t *d = dst;
d += cw_put_dword(d, vendorstr_get_vendor_id(v));
d += cw_put_dword(d, (subelem_id << 16) | vendorstr_len(v));
d += cw_put_data(d, vendorstr_data(v), vendorstr_len(v));
return d - dst;
}
@ -944,53 +961,36 @@ 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_outgoing(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_join_resp(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len);
extern int cw_in_check_join_resp(struct conn *conn, struct cw_action_in *a,
uint8_t * data, int len);
extern int cw_in_check_disc_req(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len);
extern int cw_in_check_disc_req(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len);
int cw_in_check_disc_resp(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);
extern int cw_in_check_img_data_req_wtp(struct conn *conn, struct cw_action_in *a,
uint8_t * data, int len);
extern int cw_in_check_img_data_req_ac(struct conn *conn, struct cw_action_in *a,
uint8_t * data, int len);
int cw_in_check_img_data_resp(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);
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);
struct cw_item * cw_out_get_session_id(struct conn *conn,struct cw_action_out * a);
void cw_init_request(struct conn *conn, int msg_id);
struct cw_item *cw_out_get_session_id(struct conn *conn, struct cw_action_out *a);
/**
* @defgroup TimerFunctions Timer functions
* @{
*/
/**
* Start a timer.
* @param t number of seconds until the timer expires
* @return timer value to initialize a variable of time_t
*
* Example: time_t timer = cw_timer_start(60);
*/
#define cw_timer_start(t) (time(NULL)+t)
/**
* Check if a timer is expired.
* @param t an time_t variable intializes by #cw_timer_start
* @return 0=timer is not expired\n 1=timer is expired.
*/
#define cw_timer_timeout(t) (time(NULL)>t ? 1 : 0)
/** @} */
int cw_send_request(struct conn *conn,int msg_id);
int cw_send_request(struct conn *conn, int msg_id);
#endif

View File

@ -37,15 +37,12 @@ struct cw_item *cw_out_get_local(struct conn *conn, struct cw_action_out *a)
struct cw_item * cw_out_get_session_id(struct conn *conn,struct cw_action_out * a)
{
printf("Vendor ID: %d\n", a->vendor_id);
uint8_t session_id[16];
int l = cw_rand(session_id,16);
if ( l!=16 ) {
cw_log(LOG_ERR,"Can't init session ID.");
return NULL;
}
return cw_itemstore_set_bstrn(conn->local,CW_ITEM_SESSION_ID,session_id,4);
return cw_itemstore_set_bstrn(conn->local,CW_ITEM_SESSION_ID,session_id,16);
}

View File

@ -127,13 +127,26 @@ cw_action_in_t capwap_actions_ac_in[] = {
/* Message: Image Data Request - in Config State */
{0, 0, CW_STATE_CONFIGURE, CW_MSG_IMAGE_DATA_REQUEST, 0,
0, cw_in_check_img_data_req}
0, cw_in_check_img_data_req_ac}
,
{0, 0, CW_STATE_CONFIGURE, CW_MSG_IMAGE_DATA_REQUEST,
CW_ACTION_IN_IMAGE_IDENTIFIER,
0}
,
/* ------------------------------------------------------------------------------- */
/* Message Image Data Response IN */
{0, 0, CW_STATE_IMAGE_DATA, CW_MSG_IMAGE_DATA_RESPONSE, 0,
0, cw_in_check_img_data_resp }
,
/* Element: Result Code */
{0, 0, CW_STATE_IMAGE_DATA, CW_MSG_IMAGE_DATA_RESPONSE,
CW_ACTION_IN_RESULT_CODE, 1}
,
@ -198,6 +211,21 @@ cw_action_out_t capwap_actions_ac_out[] = {
,
/* -------------------------------------------------------------------------------
* Image Data Request OUT
*/
{CW_MSG_IMAGE_DATA_REQUEST, CW_ITEM_NONE}
,
/* Image Data */
{CW_MSG_IMAGE_DATA_REQUEST, CW_ITEM_IMAGE_FILEHANDLE, 0,
CW_ELEM_IMAGE_DATA, NULL,cw_out_image_data, cw_out_get_outgoing,0}
,
/* End of list */
{0, 0}
@ -224,7 +252,6 @@ int cw_register_actions_capwap_ac(struct cw_actiondef *def)
rc += cw_strheap_register_strings(def->strelem, capwap_strings_elem);
printf("Registered %d strings\n", rc);
return 1;
}

View File

@ -68,6 +68,26 @@ cw_action_in_t capwap_actions_wtp_in[] = {
CW_ACTION_IN_RESULT_CODE, 1}
,
/* ------------------------------------------------------------------------------- */
/* Message Image Data Response */
{0, 0, CW_STATE_CONFIGURE, CW_MSG_IMAGE_DATA_RESPONSE, 0,
0, cw_in_check_img_data_resp }
,
/* Element: Result Code */
{0, 0, CW_STATE_CONFIGURE, CW_MSG_IMAGE_DATA_RESPONSE,
CW_ACTION_IN_RESULT_CODE, 1}
,
/* ------------------------------------------------------------------------------- */
/* Message Image Data Request */
{0, 0, CW_STATE_IMAGE_DATA, CW_MSG_IMAGE_DATA_REQUEST, 0,
0, cw_in_check_img_data_req_wtp }
,
@ -113,21 +133,60 @@ cw_action_out_t capwap_actions_wtp_out[] = {
/* WTP Board Data */
{CW_MSG_JOIN_REQUEST, CW_ITEM_WTP_BOARD_DATA, 0,
CW_ELEM_WTP_BOARD_DATA, NULL,cw_out_wtp_board_data, cw_out_get_outgoing}
CW_ELEM_WTP_BOARD_DATA, NULL,cw_out_wtp_board_data, cw_out_get_outgoing,1}
,
/* WTP Descriptor */
{CW_MSG_JOIN_REQUEST, CW_ITEM_WTP_DESCRIPTOR, 0,
CW_ELEM_WTP_DESCRIPTOR, NULL,cw_out_wtp_descriptor, NULL,1}
,
/* WTP Name */
{CW_MSG_JOIN_REQUEST, CW_ITEM_WTP_NAME, 0,
CW_ELEM_WTP_NAME, NULL,cw_out_generic, cw_out_get_local,1}
,
/* WTP MAC Type */
{CW_MSG_JOIN_REQUEST, CW_ITEM_WTP_MAC_TYPE, 0,
CW_ELEM_WTP_MAC_TYPE, NULL,cw_out_generic, cw_out_get_local,1}
,
/* WTP MAC Type */
{CW_MSG_JOIN_REQUEST, CW_ITEM_WTP_FRAME_TUNNEL_MODE, 0,
CW_ELEM_WTP_FRAME_TUNNEL_MODE, NULL,cw_out_generic, cw_out_get_local,1}
,
/* Session ID */
{CW_MSG_JOIN_REQUEST, CW_ITEM_SESSION_ID, 0,
CW_ELEM_SESSION_ID, NULL,cw_out_generic, cw_out_get_session_id,1}
,
/* -------------------------------------------------------------------------------
* Image Data Request OUT
*/
{CW_MSG_IMAGE_DATA_REQUEST, CW_ITEM_NONE}
,
/* Image Identifier */
{CW_MSG_IMAGE_DATA_REQUEST, CW_ITEM_IMAGE_IDENTIFIER, 0,
CW_ELEM_IMAGE_IDENTIFIER, NULL,cw_out_generic, cw_out_get_outgoing,0}
,
/* -------------------------------------------------------------------------------
* 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, NULL,cw_out_generic, cw_out_get_outgoing, 1}
,
{0, 0}
};
@ -151,7 +210,6 @@ int cw_register_actions_capwap_wtp(struct cw_actiondef *def)
rc += cw_strheap_register_strings(def->strelem, capwap_strings_elem);
printf("Registered %d strings\n", rc);
return 1;
}

View File

@ -53,9 +53,10 @@ enum capwap_items {
/* Other Items */
CW_ITEM_AC_IMAGE_DIR, /* Path where WTP images are stored */
CW_ITEM_WTP_IMAGE_FILENAME, /* Full path of image filename */
CW_ITEM_IMAGE_FILENAME, /* Full path of image filename */
CW_ITEM_DISCOVERIES,
CW_ITEM_AC_PRIO_LIST /* AC Name with Priority list */
CW_ITEM_AC_PRIO_LIST, /* AC Name with Priority list */
CW_ITEM_IMAGE_FILEHANDLE /* FILE handle for uploading and downloading images */
};

View File

@ -6,6 +6,7 @@ struct cw_str capwap_strings_result[] = {
{CW_RESULT_SUCCESS,"Success"}, /* 0 */
{CW_RESULT_MISSING_AC_LIST,"AC List Message Element MUST be Present"}, /* 1 */
{CW_RESULT_SUCCESS_NAT,"Success - NAT Detected"}, /* 2 */
{CW_RESULT_IMAGE_DATA_ERROR,"Image Data Error (Unspecified)"}, /* 16 */
{CW_RESULT_MISSING_MAND_ELEM,"Missing Mandatory Message Element"}, /* 20 */
{CW_STR_STOP,"Unknown Result Code"}

View File

@ -5,6 +5,7 @@ struct cw_str capwap_strings_state[] = {
{ CW_STATE_JOIN,"Join" },
{ CW_STATE_RUN,"Run" },
{ CW_STATE_CONFIGURE,"Configure" },
{ CW_STR_STOP,"Undefined" }
{ CW_STATE_IMAGE_DATA,"Image Data" },
{ CW_STR_STOP,"Undefined" },
};

View File

@ -173,7 +173,8 @@ static int cw_process_msg(struct conn *conn, uint8_t * rawmsg, int len)
"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;
errno=EAGAIN;
return -1;
}
/* Request message not found in current state, check if we know
@ -339,65 +340,61 @@ static int process_message(struct conn *conn, uint8_t * rawmsg, int rawlen,
//int conn_process_packet(struct conn *conn, uint8_t * packet, int len,
// int (*cb) (void *, uint8_t *, int), void *cbarg)
int conn_process_packet(struct conn *conn, uint8_t * packet, int len)
{
/* log this packet */
cw_dbg_pkt(DBG_PKT_IN,conn, packet, len);
if (len < 8) {
/* packet too short */
cw_dbg(DBG_CW_PKT_ERR,
cw_dbg(DBG_PKT_ERR,
"Discarding packet from %s, packet too short, len=%d",
sock_addr2str(&conn->addr), len);
return 0;
errno = EAGAIN;
return -1;
}
int preamble = cw_get_hdr_preamble(packet);
if ((preamble & 0xf0) != CW_VERSION) {
/* wrong version */
cw_dbg(DBG_CW_PKT_ERR,
cw_dbg(DBG_PKT_ERR,
"Discarding packet from %s, wrong version, version=%d",
sock_addr2str(&conn->addr), (preamble & 0xf0) >> 8);
return 0;
errno=EAGAIN;
return -1;
}
if (preamble & 0xf) {
/* decode dtls */
return 0;
/* dtls encoded, this shuold never happen here */
cw_dbg(DBG_PKT_ERR,
"Discarding packet from %s, encrypted data, after encryption ...",
sock_addr2str(&conn->addr));
errno = EAGAIN;
return -1;
}
/* log this packet */
cw_dbg_packet(conn, packet, len);
int offs = cw_get_hdr_msg_offset(packet);
int payloadlen = len - offs;
if (payloadlen < 0) {
cw_dbg(DBG_CW_PKT_ERR,
cw_dbg(DBG_PKT_ERR,
"Discarding packet from %s, header length greater than len, hlen=%d",
sock_addr2str(&conn->addr), offs);
/* EINVAL */
return 0;
}
/*
struct cwrmsg cwrmsg;
cwrmsg.wbid=(val>>9) & 0x1f;
cwrmsg.rid=(val>>14) & 0x1f;
*/
//printf ("Offs is %d RML is %d\n",offs,cw_get_hdr_rmac_len(packet));
/* Check Radio MAC if preset */
if (cw_get_hdr_flag_m(packet)) {
if (cw_get_hdr_rmac_len(packet) + 8 > offs) {
/* wrong rmac size */
cw_dbg(DBG_CW_PKT_ERR,
cw_dbg(DBG_PKT_ERR,
"Discarding packet, wrong R-MAC size, size=%d",
*(packet + 8));
return 0;
@ -415,7 +412,7 @@ int conn_process_packet(struct conn *conn, uint8_t * packet, int len)
if (f == NULL)
return 0;
cw_dbg_packet(conn, f + 4, *(uint32_t *) f);
// cw_dbg_packet(conn, f + 4, *(uint32_t *) f);