Work in progress

FossilOrigin-Name: 155605fd55cbb193d4f5ac8c704930c050a11cda541f1a5cdb93c57a8c51534f
This commit is contained in:
7u83@mail.ru 2018-03-17 11:32:40 +00:00
parent c4307d9e70
commit b668a8f4a9
63 changed files with 770 additions and 982 deletions

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<CodeLite_Workspace Name="actube" Database="">
<Project Name="ac" Path="ac.project" Active="No"/>
<Project Name="wtp" Path="wtp.project" Active="No"/>
<Project Name="wtp" Path="wtp.project" Active="Yes"/>
<Project Name="mod_cipwap" Path="mod_cipwap.project" Active="No"/>
<Project Name="mod_capwap" Path="mod_capwap.project" Active="No"/>
<Project Name="mod_cisco" Path="mod_cisco.project" Active="No"/>
<Project Name="libcw" Path="libcw.project" Active="Yes"/>
<Project Name="libcw" Path="libcw.project" Active="No"/>
<Project Name="mod_capwap80211" Path="mod_capwap80211.project" Active="No"/>
<Project Name="mod_fortinet" Path="mod_fortinet.project" Active="No"/>
<BuildMatrix>

View File

@ -89,7 +89,6 @@
<File Name="src/cw/lw_readelem_wtp_name.c"/>
<File Name="src/cw/capwap_cisco.h"/>
<File Name="src/cw/cw_in_wtp_reboot_statistics.c"/>
<File Name="src/cw/mlist.c"/>
<File Name="src/cw/netconn.c"/>
<File Name="src/cw/cw_in_capwap_local_ipv6_address.c"/>
<File Name="src/cw/cw_out_capwap_local_ip_address.c"/>
@ -168,7 +167,6 @@
<File Name="src/cw/mavl_add.c"/>
<File Name="src/cw/dtls_gnutls_get_cipher.c"/>
<File Name="src/cw/cw_in_check_cipwap_join_req.c"/>
<File Name="src/cw/wtpinfo_readelem_wtp_board_data.c"/>
<File Name="src/cw/vendors.h"/>
<File Name="src/cw/cw_read_wtp_descriptor_7.c"/>
<File Name="src/cw/dbg.h"/>
@ -220,7 +218,6 @@
<File Name="src/cw/lwmsg.h"/>
<File Name="src/cw/cw_check_missing_mand.c"/>
<File Name="src/cw/format_dot11_fc.c"/>
<File Name="src/cw/wtpinfo_lwreadelem_wtp_descriptor.c"/>
<File Name="src/cw/dbg_strings.c"/>
<File Name="src/cw/dtls_gnutls.c"/>
<File Name="src/cw/conn_prepare_configuration_update_request.c"/>
@ -266,7 +263,6 @@
<File Name="src/cw/mavl_foreach.c"/>
<File Name="src/cw/lwapp_cisco.h"/>
<File Name="src/cw/hdr_print.c"/>
<File Name="src/cw/cw_out_wtp_board_data.c"/>
<File Name="src/cw/mbag_type_str.c"/>
<File Name="src/cw/cw_init_data_keep_alive_msg.c"/>
<File Name="src/cw/cw_in_check_chng_state_evnt_req.c"/>
@ -281,11 +277,7 @@
<File Name="src/cw/capwap_strings_state.c"/>
<File Name="src/cw/cw_out_radio_info.c"/>
<File Name="src/cw/capwap_items.c"/>
<File Name="src/mod/cisco/mod_cisco.h"/>
<File Name="src/cw/cw_filename.c"/>
<File Name="src/cw/mdata.h"/>
<File Name="src/cw/mdata.c"/>
<File Name="src/cw/mdata_elem_new.c"/>
<File Name="src/cw/cw_type_byte.c"/>
<File Name="src/cw/cw_type_word.c"/>
<File Name="src/cw/cw_type_dword.c"/>
@ -330,7 +322,12 @@
<File Name="src/cw/cw_ktv_put.c"/>
<File Name="src/cw/cw_ktv_get.c"/>
<File Name="src/cw/cw_write_descriptor_subelem.c"/>
<File Name="src/cw/cw_ktv_dump.c"/>
<File Name="src/cw/cw_ktv_get_word.c"/>
<File Name="src/cw/cw_ktv_get_byte.c"/>
<File Name="src/cw/cw_ktv_std_types.c"/>
</VirtualDirectory>
<File Name="src/mod/capwap/capwap_out_wtp_descriptor.c"/>
</VirtualDirectory>
<Description/>
<Dependencies/>

View File

@ -4,7 +4,6 @@
<VirtualDirectory Name="mod">
<VirtualDirectory Name="capwap">
<File Name="src/mod/capwap/capwap_out_ac_ip_list.c"/>
<File Name="src/mod/capwap/capwap_out_wtp_descriptor.c"/>
<File Name="src/mod/capwap/capwap_actions.h"/>
<File Name="src/mod/capwap/mod_capwap_ac.c"/>
<File Name="src/mod/capwap/capwap_in_wtp_board_data.c"/>
@ -20,6 +19,7 @@
<File Name="src/mod/capwap/capwap_actions_ac.c"/>
<File Name="src/mod/capwap/capwap_in_vendor_specific_payload.c"/>
<File Name="src/mod/capwap/capwap_in_mtu_discovery_padding.c"/>
<File Name="src/mod/capwap/capwap_out_wtp_board_data.c"/>
</VirtualDirectory>
</VirtualDirectory>
</VirtualDirectory>

View File

@ -1,10 +1,15 @@
#include "cw/capwap.h"
#include "cw/mbag.h"
#ifndef __ACTUBE_AC_H
#define __ACTUBE_AC_H
#include "cw/mavl.h"
extern mavl_t actube_global_cfg;
extern struct ac_status ac_global_status;
extern int ac_global_init();
extern mbag_t ac_config;
extern struct cw_actiondef capwap_actions;
int actube_global_init();
/* the protocol we understand */
@ -17,3 +22,4 @@ enum {
#endif

View File

@ -17,8 +17,8 @@ struct cw_ac_status ac_status;
struct cw_actiondef capwap_actions;
mbag_t ac_config;
mavl_t actube_global_cfg;
cw_aciplist_t get_aciplist()
{

View File

@ -21,7 +21,7 @@
#include <unistd.h>
#include <errno.h>
#include <stdint.h>
//#include <netinet/in.h>
#include "actube.h"
#include "wtplist.h"
@ -63,32 +63,69 @@ static void *alive_thread (void *data)
#include <getopt.h>
static int parse_args (int argc, char *argv[])
struct bootcfg {
const char * cfgfilename;
};
static int parse_args (int argc, char *argv[], struct bootcfg * bootcfg)
{
// int getopt_ret;
int option_index;
int c;
opterr = 1;
static struct option long_options[] = {
{"version", optional_argument, NULL, 'v'},
{0, 0, 0, 0}
};
int o;
bootcfg->cfgfilename = "config.ktv";
while ( (o = getopt_long (argc, argv, "v", long_options, &option_index)) != -1) {
switch (o) {
case 0:
while ( (c = getopt (argc, argv, "vc:d:p:")) != -1) {
switch (c) {
case 'c':
bootcfg->cfgfilename = optarg;
break;
case 'v':
printf ("AC-Tube 0.01, %s\n", SYS_ARCH);
exit (0);
printf("AC-Tube version 0.0.1, %s\n", SYS_ARCH);
exit(EXIT_SUCCESS);
break;
case 'd':{
int b = cw_strlist_get_id(cw_dbg_strings, optarg);
if (b==-1){
fprintf(stderr,"Invalid debug option: %s\n",optarg);
exit(EXIT_FAILURE);
}
cw_dbg_set_level(b, 1);
break;
}
case 'p':
cw_mod_set_path(optarg);
break;
case '?':
exit(EXIT_FAILURE);
default:
case 'h':
printf("%s: -vcmh\n",argv[0]);
exit(EXIT_SUCCESS);
break;
}
}
return 0;
}
#include "cw/mod.h"
extern struct cw_Mod * cw_get_mod_ac (const char *name);
@ -151,274 +188,55 @@ int stcmp (const void * sa1, const void *sa2)
return rc;
}
int main (int argc, char *argv[])
{
mlist_t list;
mlistelem_t * elem;
list = mlist_create_conststr();
mlist_append_ptr(list, "helo");
mlist_append_ptr(list, "tobias");
mlist_append_ptr(list, "nase");
mlist_foreach(elem,list){
// data = mlistelem_dataptr(elem);
// char * str = ((char**)data)[0];
// printf("%p %p\n",data,str);
printf("String: %s\n", mlistelem_get_str(elem));
}
mlist_destroy(list);
mlist_foreach(elem,list){
// data = mlistelem_dataptr(elem);
// char * str = ((char**)data)[0];
// printf("%p %p\n",data,str);
printf("String: %s\n", mlistelem_get_str(elem));
}
//exit(0);
/* mavl_t tree;
int i;
mavliter_t it;
mlist_t list;
struct mlistelem * elem;
int x;
list = mlist_create(NULL,sizeof(int));
x=8;
mlist_append(list,&x);
x=13;
mlist_append(list,&x);
x=11;
mlist_append(list,&x);
for(i=0; i<100000000; i++){
int val;
val = i;
mlistelem_t * result;
result = mlist_append(list,&val);
if (result == NULL){
printf("error\n");
}
}
printf("Count %d\n",list->count);
mlist_foreach(elem,list){
int * data = mlistelem_dataptr(elem);
printf("Here is %d\n",*data);
}
exit(0);
*/
/*tree = mavl_create_ptr( (int(*)(const void*,const void*))strcmp,free);
*/
/*
tree = mavl_create_ptr(mycmp,NULL);
struct mykv * mdata;
mdata = malloc(sizeof(struct mykv));
mdata->key=14;
mdata->value=15;
mavl_add_ptr(tree, mdata);
mdata = malloc(sizeof(struct mykv));
mdata->key=16;
mdata->value=17;
mavl_add_ptr(tree, mdata);
mdata = malloc(sizeof(struct mykv));
mdata->key=12;
mdata->value=13;
mavl_add_ptr(tree, mdata);
mavliter_init(&it,tree);
mavliter_foreach(&it){
mdata = mavliter_get_ptr(&it);
printf("MAVLIT: %d %d\n",mdata->key,mdata->value);
struct mykv search;
search.key=mdata->key;
mdata = mavl_get_ptr(tree,&search);
printf("Search T: %d %d\n",mdata->key,mdata->value);
}
exit(0);
*/
/*
if (tree==NULL)
return 0;
tree = mavl_create_str();
mavl_add_str(tree,cw_strdup("7u83"));
mavl_add_str(tree,cw_strdup("Herre"));
mavl_add_str(tree,cw_strdup("Tube"));
mavl_add_str(tree,cw_strdup("Tobias"));
printf("Count: %d\n", mavl_get_count(tree));
mavliter_init(&it,tree);
mavliter_foreach(&it){
printf("iterWert %s\n",mavliter_get_str(&it));
}
*/
/*
tree = mavl_create (mycmp, NULL, sizeof (struct mykv));
struct mykv nwert;
int result;
struct mykv * mr;
nwert.key = 7;
nwert.value = 777;
mr = mavl_add_exists (tree, &nwert, &result);
printf ("7Result %d: %d %d\n", result, mr->key, mr->value);
for (i = 0; i < 10; i++) {
//cw_rand(&nwert.key,sizeof(nwert.key));
// printf("Addwert: %u\n",nwert.key);
// printf("add %u\n", i);
nwert.key = 9 - i;
nwert.value = 100 + i;
result=0;
mr = mavl_add_exists (tree, &nwert, &result);
printf ("Result %d: %d %d\n", result, mr->key, mr->value);
}
mavliter_init (&it, tree);
mavliter_foreach (&it) {
struct mykv *kv;
kv = mavliter_get (&it);
printf ("iterWert %u\n", kv->key);
}
exit (0);
*/
/* mavl_t kv;
mavliter_t kviter;
uint8_t bytes[] = { 99,4,5,7 };
kv = cw_types_mavl_create();
//mavl_cmp_kv,cw_type_delete);
mavldata_t data, *result;
data.kv.key="wtp_board_data";
result = cw_type_byte.get(&data,bytes,1);
mavl_add(kv,result);
data.kv.key="wtp_next_data";
result = cw_type_byte.get(&data,bytes+1,1);
mavl_add(kv,result);
mavliter_init(&kviter,kv);
mavliter_foreach(&kviter){
char value[500];
mavldata_t * data;
data = mavliter_get(&kviter);
struct cw_Type * type = data->kv.priv;
type->to_str(data,value,0);
printf("Got %s (%s): %s\n",data->kv.key,type->name, value);
}
mavl_destroy(kv);
exit(0);
*/
/* cw_log_init();
cw_log(LOG_ERROR,"Hello Debug World222");
exit(0);
*/
/*
char * dump_data = "Eine kleine Mickey Maus zog sich mal die Hosen\
aus, zog sie wieder an, und du bist dran. Dran bist du noch lange nicht\
musst erst sagen, wie alt du bist.";
char * result = cw_format_dump(dump_data,strlen(dump_data),NULL);
printf("Dump Result:\n%s\n", result);
exit(0);
*/
/* char data[100];
mavl_t im;
mavldata_t * val, * val2,itt, itt2, * result, search ;
mavliter_t myit;
im = mavl_create(mavl_cmp_dword,NULL);
itt.dword = 7;
itt2.dword = 7;
val = mavl_add(im,&itt);
val2 = mavl_add(im,&itt2);
search.dword = 7;
result = mavl_get(im,&search);
printf("Result: (%p, %p) (%p, %p) (%p, %p)\n",val, &itt, val2, &itt2, result, &search);
exit(0);
for (itt.dword=100; itt.dword>0; itt.dword--){
printf("Copunting: %d\n",itt.dword);
mavl_add(im,&itt);
}
mavliter_init(&myit,im);
mavliter_foreach(&myit){
union mavldata * result;
result = mavliter_get(&myit);
printf("Got Value %d\n",result->dword);
}
mavl_destroy(im);
*/
int rc = 0;
struct bootcfg bootcfg;
FILE * file;
mavl_t types_tree, global_cfg;
const cw_Type_t **ti;
/* parse arguments */
parse_args (argc, argv);
parse_args (argc, argv, &bootcfg);
/* open config file */
file = fopen(bootcfg.cfgfilename,"r");
if (file == NULL){
cw_log(LOG_ERR,"Cant open config file '%s': %s",
bootcfg.cfgfilename, strerror(errno));
exit(EXIT_FAILURE);
}
/* create types tree with default types */
types_tree = cw_ktv_create_types_tree();
for (ti=CW_KTV_STD_TYPES;*ti;ti++){
mavl_add_ptr(types_tree,*ti);
}
global_cfg = cw_ktv_create();
if (global_cfg == NULL){
cw_log(LOG_ERR,"Can't create local_cfg: %s",strerror(errno));
exit(EXIT_FAILURE);
}
cw_ktv_read_file(file,global_cfg,types_tree);
fclose(file);
cw_ktv_dump(global_cfg,DBG_INFO,NULL,"CFG:",NULL);
actube_global_cfg = global_cfg;
cw_log_name = "AC-Tube";
if (!read_config ("ac.conf"))

View File

@ -577,7 +577,8 @@ static int conf_read_mods(cfg_t *cfg){
for (i=0; i < n; i++){
char *modname = cfg_getnstr(cfg, CFG_ENTRY_MODS, i);
struct cw_Mod * mod = cw_mod_load(modname);
struct cw_Mod * mod = cw_mod_load(modname, actube_global_cfg, CW_ROLE_AC);
if (!mod)
return 0;
cw_mod_add_to_list(mod);

View File

@ -751,11 +751,17 @@ struct wtpman *wtpman_create(int socklistindex, struct sockaddr *srcaddr)
wtpman->conn->strict_hdr = conf_strict_headers;
wtpman->conn->radios = mbag_i_create();
wtpman->conn->radios_upd = mbag_i_create();
wtpman->conn->local = ac_config;
// wtpman->conn->local = ac_config;
//wtpman->conn->capwap_mode=0; //CW_MODE_STD; //CISCO;
wtpman->conn->capwap_mode = CW_MODE_CISCO;
//wtpman->conn->strict_capwap_hdr=0;
wtpman->conn->local_cfg = cw_ktv_create();
wtpman->conn->global_cfg = actube_global_cfg;
return wtpman;
}

View File

@ -29,7 +29,7 @@ struct wtpman{
uint8_t * session_id;
uint8_t wtp_mactype;
//struct wtpinfo wtpinfo;
/* //struct wtpinfo wtpinfo;*/
int socklistindex;

View File

@ -4,7 +4,10 @@
uint8_t * bstr16_create_from_str(const char *s)
{
int l = strlen(s);
uint8_t * mem;
int msize;
int l;
l = strlen(s);
if (s[0]!='.')
return bstr16_create((uint8_t*)s,l);
@ -19,10 +22,10 @@ uint8_t * bstr16_create_from_str(const char *s)
/* the string starts with ".x" - read hexbytes */
l-=2;
int msize=l/2;
msize=l/2;
if(l&1)
msize++;
uint8_t * mem = malloc(2+msize);
mem = malloc(2+msize);
*((uint16_t*)mem)=msize;
cw_format_scan_hex_bytes(mem+2,s+2,l);
return mem;

View File

@ -188,12 +188,12 @@
*/
#define CAPWAP_ELEM_AC_DESCRIPTOR 1 /**< AC Descriptor */
#define CAPWAP_ELEM_AC_DESCRIPTOR 1 /**< AC Descriptor */
#define CAPWAP_ELEM_AC_IPV4_LIST 2 /**< AC IP V4 List */
#define CW_ELEM_AC_IPV6_LIST 3 /**< AC IP V6 List */
#define CW_ELEM_AC_NAME 4 /**< AC Name */
#define CW_ELEM_AC_NAME_WITH_PRIORITY 5
#define CAPWAP_ELEM_AC_IPV4_LIST 2 /**< AC IP V4 List */
#define CAPWAP_ELEM_AC_IPV6_LIST 3 /**< AC IP V6 List */
#define CAPWAP_ELEM_AC_NAME 4 /**< AC Name */
#define CW_ELEM_AC_NAME_WITH_PRIORITY 5
/**
* In CAPWAP RFC draft 7 the message element 5 was named
@ -380,9 +380,9 @@
* @{
*/
/** X.509 Support */
#define CW_FLAG_AC_SECURITY_X 2
#define CAPWAP_FLAG_AC_SECURITY_X 2
/* PSK Support */
#define CW_FLAG_AC_SECURITY_S 4
#define CAPWAP_FLAG_AC_SECURITY_S 4
/**
* @}
*/
@ -432,15 +432,18 @@ struct cwimage_identifier{
/*
//extern void cwmsg_addelem_wtp_radio_infos(struct cwmsg * cwmsg,struct wtpinfo * wtpinfo);
*/
/*
extern void cwmsg_addelem_wtp_radio_infos(struct cwmsg *msg,
struct radioinfo *radioinfos);
struct radioinfo *radioinfos);*/
/*
//extern void cwmsg_addelem_result_code(struct cwmsg *msg, int rc);
*/
/*
extern void cwmsg_addelem_vendor_specific_payload(struct cwmsg *msg, int vendor_id,
int type, uint8_t * payload, int len);
*/
/*
extern int hdr_print(char *str, uint8_t * packet, int len);
@ -464,7 +467,7 @@ extern int cw_readelem_ecn_support(uint8_t * ecn_support, int type, uint8_t * ms
// uint8_t * msgelem, int len);
*/
/*
extern int cw_readelem_statistics_timer(uint16_t * timer, int type, uint8_t * msgelem,
int len);
extern int cw_readelem_result_code(uint32_t * result_code, int type, uint8_t * msgelem,
@ -473,7 +476,7 @@ extern int cw_readelem_result_code(uint32_t * result_code, int type, uint8_t * m
extern int cw_readelem_vendor_specific_payload(void *data, int msgtype, int elemtype,
uint8_t * msgelem, int len);
*/
@ -635,6 +638,7 @@ extern struct cw_strlist_elem mbag_item_strings[];
#define cw_strerror(rc) cw_strrc(rc)
*/
#include "strheap.h"
const char * cw_strerror(int rc);
int cw_result_is_ok(int rc);
@ -658,12 +662,14 @@ extern int cw_in_vendor_specific_payload(struct conn *conn, struct cw_action_in
uint8_t * data, int len,struct sockaddr *from);
*/
/*
extern int cw_in_wtp_name(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len,struct sockaddr *from);
extern int cw_in_wtp_board_data(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len,struct sockaddr *from);
extern int cw_in_wtp_descriptor(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len,struct sockaddr *from);
*/
/*
//extern int cw_out_generic(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len);
@ -677,21 +683,21 @@ extern int cw_out_generic(struct conn *conn, struct cw_action_out *a, uint8_t *
//extern int cw_out_ac_descriptor(struct conn *conn, uint32_t elem_id, uint8_t * dst,
//struct mbag_item *item);
*/
extern int cw_out_ac_descriptor(struct conn *conn, struct cw_action_out *a, uint8_t * dst);
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 mbag_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_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_ac_status {
int stations;
@ -732,84 +738,6 @@ enum capwap_states {
int cw_register_actions_capwap_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);
struct mbag_item *cw_out_get_outgoing(struct conn *conn, struct cw_action_out *a);
struct mbag_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,struct sockaddr *from);
extern int cw_in_check_disc_req(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len,struct sockaddr *from);
int cw_in_check_disc_resp(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len,struct sockaddr *from);
int cw_in_check_join_req(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len,struct sockaddr *from);
extern int cw_in_check_img_data_req_wtp(struct conn *conn, struct cw_action_in *a,
uint8_t * data, int len,struct sockaddr *from);
extern int cw_in_check_img_data_req_ac(struct conn *conn, struct cw_action_in *a,
uint8_t * data, int len,struct sockaddr *from);
int cw_in_check_img_data_resp(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len,struct sockaddr *from);
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 mbag_item *cw_out_get_session_id(struct conn *conn, struct cw_action_out *a);
struct mbag_item *cw_out_get_config(struct conn *conn, struct cw_action_out *a);
extern int cw_in_radio_administrative_state(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
struct sockaddr *from);
int cw_out_ac_name_with_priority(struct conn *conn, struct cw_action_out *a, uint8_t * dst);
int cw_send_request(struct conn *conn, int msg_id);
/*
//int cw_is_utf8(unsigned char *str, size_t len);
*/
int cw_in_ac_name_with_priority(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
struct sockaddr *from);
int cw_out_radio_administrative_states(struct conn *conn, struct cw_action_out *a, uint8_t * dst);
int cw_in_radio_administrative_state(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
struct sockaddr *from);
int cw_in_ac_descriptor(struct conn *conn,struct cw_action_in * a,uint8_t *data,int len,struct sockaddr *from);
int cw_in_radio_generic(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
struct sockaddr *from);
/*
//int cw_out_capwap_local_ip_address(struct conn *conn, struct cw_action_out *action, uint8_t * dst);
*/
int cw_in_check_chng_state_evnt_req(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len,struct sockaddr *from);
/*
//int cw_out_radio_operational_states(struct conn *conn, struct cw_action_out *a, uint8_t * dst);
*/
int cw_in_check_cfg_update_req(struct conn *conn, struct cw_action_in *a, uint8_t * data,
int len,struct sockaddr *from);
int cw_radio_set_admin_state(mbag_t radios,int rid, int state,int cause);
int cw_in_radio_administrative_state_wtp(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len,
struct sockaddr *from);
#endif

View File

@ -5,8 +5,8 @@ struct cw_strlist_elem capwap_strings_elem[] = {
{CAPWAP_ELEM_AC_DESCRIPTOR, "AC Descriptor"},
{CAPWAP_ELEM_AC_IPV4_LIST, "AC IPv4 List"},
{CW_ELEM_AC_IPV6_LIST, "AC IPv6 List"},
{CW_ELEM_AC_NAME, "AC Name"},
{CAPWAP_ELEM_AC_IPV6_LIST, "AC IPv6 List"},
{CAPWAP_ELEM_AC_NAME, "AC Name"},
{CW_ELEM_AC_NAME_WITH_PRIORITY, "AC Name with Priority"},
// {CW_ELEM_AC_NAME_WITH_INDEX, "AC Name with Index"},
{CAPWAP_ELEM_AC_TIMESTAMP, "AC Timestamp"},

View File

@ -74,6 +74,7 @@ struct conn {
mavl_t remote_cfg;
mavl_t local_cfg;
mavl_t global_cfg;

View File

@ -40,7 +40,7 @@ void conn_init(struct conn * conn)
conn->wait_dtls=CAPWAP_WAIT_DTLS;
conn->wait_join=CAPWAP_WAIT_JOIN;
conn->mtu_discovery=1;
conn->capwap_mode = CW_MODE_AUTO;
conn->capwap_mode = 0;
conn->strict_capwap=1;
conn->remote = mbag_create();

View File

@ -116,8 +116,10 @@ void cw_init_data_msg(struct conn *conn)
*/
int cw_send_response(struct conn *conn, uint8_t * rawmsg, int len)
{
int rc;
cw_init_response(conn, rawmsg);
if (cw_put_msg(conn, conn->resp_buffer) == -1)
rc = cw_put_msg(conn, conn->resp_buffer);
if (!cw_result_is_ok(rc))
return 0;
conn_send_msg(conn, conn->resp_buffer);
return 1;
@ -125,7 +127,6 @@ int cw_send_response(struct conn *conn, uint8_t * rawmsg, int len)
/**
* Special case error message, which is sent when an unexpected messages
* was received or something else happened.
@ -330,10 +331,10 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
if (conn->msg_start){
/* if (conn->msg_start){
conn->msg_start(conn, afm, rawmsg, len, from);
}
*/
/* Execute start processor for message */
/*
// if (afm->start) {
@ -353,6 +354,7 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
/* iterate through message elements */
cw_foreach_elem(elem, elems_ptr, elems_len) {
int rc;
struct cw_ElemHandlerParams params;
int elem_len, elem_id, max_len;
@ -377,26 +379,16 @@ static int process_elements(struct conn *conn, uint8_t * rawmsg, int len,
params.msgdata=message;
params.mand_found=mand_found;
result_code = cw_process_element(&params,0,0,elem_id,elem_data,elem_len);
rc = cw_process_element(&params,0,0,elem_id,elem_data,elem_len);
if (cw_result_is_ok(result_code))
if (cw_result_is_ok(rc))
continue;
if (result_code == CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT){
if (rc == CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT){
mlist_append(unrecognized,&elem);
}
continue;
exit(0);
/* if (!check_len(conn, af, cw_get_elem_data(elem), elem_len, from)) {
continue;
}
cw_dbg_elem(DBG_ELEM, conn, as.msg_id, as.elem_id, cw_get_elem_data(elem),
elem_len);
*/
}
@ -426,10 +418,7 @@ exit(0);
}
mavliter_init(&it,mand_found);
mavliter_foreach(&it){
printf("MAnd found: %s", mavliter_get_str(&it));
}
{
mlistelem_t *e;
@ -445,13 +434,10 @@ exit(0);
}
//int result_code = 0;
//int unrecognized =3;
/** int rct = cw_in_check_generic(conn, afm, rawmsg, len, from); */
int rct = cw_in_check_generic(conn, afm, rawmsg, len, from);
if (rct && conn->strict_capwap)
/* if (rct && conn->strict_capwap)
{
result_code = rct;
}
@ -465,11 +451,11 @@ exit(0);
conn->msg_end(conn, afm, rawmsg, len, from);
}
}
if (unrecognized) {
*/
/* if (unrecognized) {
cw_dbg(DBG_RFC, "Message has %d unrecognized message elements.",
unrecognized);
/* set only resultcode for request messages */
// set only resultcode for request messages
if ( (!result_code) && ((afm->msg_id & 1))) {
if (conn->strict_capwap) {
@ -478,14 +464,19 @@ exit(0);
}
}
*/
/* if we've got a request message, we always have to send a response message */
if (as.msg_id & 1) {
if (message->type & 1) {
if (result_code > 0) {
/* the end method gave us an result code>0, so
send an error message */
printf("Here we are, error response %i %s\n", result_code, cw_strerror(result_code));
exit(0);
cw_send_error_response(conn, rawmsg, result_code);
} else if (result_code == 0) {
/* All ok, send regular response message */
cw_send_response(conn, rawmsg, len);
} else {

View File

@ -53,4 +53,5 @@ int cw_in_check_img_data_req_ac(struct conn *conn, struct cw_action_in *a, uint8
return CAPWAP_RESULT_IMAGE_DATA_ERROR;
*/
return 0;
}

View File

@ -20,7 +20,6 @@ const char * cw_ktv_add_from_str(mavl_t kvtstore, const char *key, const struct
return NULL;
}
printf("Want To Add: %s:%s (%s)\n",key,str,type->name);
mresult = type->from_str(&mdata,str);
if (!mresult){
cw_log(LOG_ERR, "Can't create kvstore element for key %s of type %s: %s",

30
src/cw/cw_ktv_dump.c Normal file
View File

@ -0,0 +1,30 @@
#include "ktv.h"
#include "dbg.h"
void cw_ktv_dump(mavl_t ktv, uint32_t dbglevel,
const char *header, const char *prefix, const char *footer )
{
char value[500];
struct cw_KTV * data;
mavliter_t it;
const struct cw_Type * type;
if (header != NULL)
cw_dbg (dbglevel, header);
mavliter_init(&it,ktv);
mavliter_foreach(&it){
data = mavliter_get(&it);
type = data->type;
type->to_str(data,value,0);
cw_dbg(dbglevel,"%s%s (%s): %s",prefix,data->key,type->name, value);
}
if (footer != NULL)
cw_dbg (dbglevel, footer);
}

11
src/cw/cw_ktv_get_byte.c Normal file
View File

@ -0,0 +1,11 @@
#include "ktv.h"
uint8_t cw_ktv_get_byte(mavl_t ktv,const char *key, uint8_t def)
{
cw_KTV_t * k;
k = cw_ktv_get(ktv,key,CW_TYPE_BYTE);
if (k != NULL){
return k->val.byte;
}
return def;
}

11
src/cw/cw_ktv_get_word.c Normal file
View File

@ -0,0 +1,11 @@
#include "ktv.h"
uint16_t cw_ktv_get_word(mavl_t ktv,const char *key, uint16_t def)
{
cw_KTV_t * k;
k = cw_ktv_get(ktv,key,CW_TYPE_WORD);
if (k != NULL){
return k->val.word;
}
return def;
}

View File

@ -27,8 +27,10 @@ int cw_ktv_read_file(FILE * file, mavl_t ktv, mavl_t types)
if (cwtype != NULL){
// printf("Yes! I know the type: %s\n",cwtype->name);
}
else
else {
printf("Unknown type: %s\n",typesearch.name);
continue;
}

View File

@ -0,0 +1,9 @@
#include "ktv.h"
const cw_Type_t * cw_ktv_std_types[] = {
CW_TYPE_BYTE,
CW_TYPE_WORD,
CW_TYPE_DWORD,
CW_TYPE_BSTR16,
NULL
};

View File

@ -1,111 +0,0 @@
#include "log.h"
#include "mbag.h"
#include "conn.h"
#include "mbag.h"
#include "capwap_items.h"
#include "cw.h"
int cw_get_out_item(struct conn * conn, struct cw_action_out *a, void *dst, mbagtype_t type)
{
if (!a->get)
return 0;
/* Get the item */
struct mbag_item *item = a->get(conn, a);
if (!item)
return 0;
if (item->type != type){
return 0;
}
return cw_put_mbag_item(dst,item);
}
int cw_out_wtp_board_data(struct conn *conn, struct cw_action_out *a, uint8_t * dst)
{
mbag_t board_data;
// mbag_get_mbag(conn->config, CW_ITEM_WTP_BOARD_DATA,NULL);
if (!cw_get_out_item(conn,a,&board_data,MBAG_MBAG)){
cw_log(LOG_ERROR,"Can't get item '%s' for msg %d, elem %d",a->item_id,a->msg_id,a->elem_id);
return 0;
}
/* if (!board_data) {
cw_log(LOG_ERR, "Error: Can't send WTP Board Data element. \"%s\" is undefined.",CW_ITEM_WTP_BOARD_DATA);
return 0;
}
*/
struct mbag_item *i;
i = mbag_get(board_data, CW_ITEM_WTP_BOARD_VENDOR);
if (!i) {
cw_log(LOG_ERR,
"Error: Can't send WTP Board Data element - no vendor defined");
return 0;
}
uint8_t *d = dst + 4;
d += cw_put_dword(d, i->u2.dword);
char buf[90];
i = mbag_get(board_data, CW_ITEM_WTP_BOARD_MODELNO);
if (i) {
printf("We have got an i %p\n",i);
printf("len: %d\n",bstr16_len(i->u2.data));
memcpy(buf,bstr16_data(i->u2.data),bstr16_len(i->u2.data));
buf[bstr16_len(i->u2.data)]=0;
printf("Val: %s\n",buf);
d += cw_put_word(d, CW_BOARDDATA_MODELNO);
d += cw_put_word(d, bstr16_len(i->u2.data));
d += cw_put_data(d, bstr16_data(i->u2.data), bstr16_len(i->u2.data));
} else {
cw_log(LOG_ERR,
"Error: Can't set sub-element \"WTP Model Number\" in WTP Board Data.");
}
i = mbag_get(board_data, CW_ITEM_WTP_BOARD_SERIALNO);
if (i) {
d += cw_put_word(d, CW_BOARDDATA_SERIALNO);
d += cw_put_word(d, bstr16_len(i->u2.data));
d += cw_put_data(d, bstr16_data(i->u2.data), bstr16_len(i->u2.data));
}else {
cw_log(LOG_ERR,
"Error: Can't set sub-element \"WTP Serial Number\" in WTP Board Data.");
}
i = mbag_get(board_data, CW_ITEM_WTP_BOARD_ID);
if (i) {
d += cw_put_word(d, CW_BOARDDATA_BOARDID);
d += cw_put_word(d, bstr16_len(i->u2.data));
d += cw_put_data(d, bstr16_data(i->u2.data), bstr16_len(i->u2.data));
}
i = mbag_get(board_data, CW_ITEM_WTP_BOARD_REVISION);
if (i) {
d += cw_put_word(d, CW_BOARDDATA_REVISION);
d += cw_put_word(d, bstr16_len(i->u2.data));
d += cw_put_data(d, bstr16_data(i->u2.data), bstr16_len(i->u2.data));
}
i = mbag_get(board_data, CW_ITEM_WTP_BOARD_MACADDRESS);
if (i) {
d += cw_put_word(d, CW_BOARDDATA_MACADDRESS);
d += cw_put_word(d, bstr_len(i->u2.data));
d += cw_put_data(d, bstr_data(i->u2.data), bstr_len(i->u2.data));
}
int l = d - dst-4;
return l + cw_put_elem_hdr(dst, CAPWAP_ELEM_WTP_BOARD_DATA, l );
}

View File

@ -31,7 +31,7 @@ static int cw_put_encryption_subelems(uint8_t *dst,int capwap_mode)
}
/*
int cw_out_wtp_descriptor(struct conn *conn, struct cw_action_out *a, uint8_t * dst)
{
@ -77,7 +77,8 @@ int cw_out_wtp_descriptor(struct conn *conn, struct cw_action_out *a, uint8_t *
else {
cw_log(LOG_INFO, "Can't send Other Version in WTP descriptor, not set.");
}
*/
int len = d-dst-4;
return len + cw_put_elem_hdr(dst,a->elem_id,len);
*
// int len = d-dst-4;
// return len + cw_put_elem_hdr(dst,a->elem_id,len);
}
*/

View File

@ -10,15 +10,17 @@
*/
int cw_put_ac_status(uint8_t * dst, struct cw_ac_status *s, struct conn * conn)
{
uint8_t *d = dst;
uint8_t *d;
d = dst;
d += cw_put_dword(d, (s->stations << 16) | (s->limit));
d += cw_put_dword(d, (s->active_wtps << 16) | (s->max_wtps));
int security = 0;
security |= conn->dtls_cert_file ? CW_FLAG_AC_SECURITY_X : 0;
security |= conn->dtls_psk ? CW_FLAG_AC_SECURITY_S : 0;
security |= conn->dtls_cert_file ? CAPWAP_FLAG_AC_SECURITY_X : 0;
security |= conn->dtls_psk ? CAPWAP_FLAG_AC_SECURITY_S : 0;
d += cw_put_dword(d,

View File

@ -44,6 +44,8 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout)
struct mlistelem * elem;
int len,l;
\
/* rawout is already initialized, so we can get
* msg type from buffer */
msgptr = rawout + cw_get_hdr_msg_offset(rawout);
@ -53,8 +55,11 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout)
if (msg == NULL){
cw_log(LOG_ERR,"Error: Can't create message of type %d (%s) - no definition found.",
type, cw_strmsg(type));
return CAPWAP_RESULT_MSG_UNRECOGNIZED;
}
printf("Message to send: %s (elems %d)\n",msg->name, msg->elements_list->count);
dst = msgptr+8;
len =0;
mlist_foreach(elem,msg->elements_list){
@ -64,7 +69,7 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout)
data = mlistelem_dataptr(elem);
handler = cw_msgset_get_elemhandler(conn->msgset,data->proto,data->vendor,data->id);
//printf("Elem: %d %d %d %s\n", data->proto, data->vendor, data->id, handler->name);
printf("Elem: %d %d %d %s\n", data->proto, data->vendor, data->id, handler->name);
if (handler->put == NULL){
if (data->mand){
@ -93,7 +98,32 @@ int cw_put_msg(struct conn *conn, uint8_t * rawout)
return len;
printf("Message to send: %s\n",msg->name);

View File

@ -44,13 +44,13 @@ int cw_read_descriptor_subelems(mavl_t cfg, const char * parent_key,
/* search sub-element */
for (i = 0; elems[i].maxlen; i++) {
if (elems[i].type == subtype && elems[i].vendor_id==vendor_id)
if (elems[i].type == subtype /* && elems[i].vendor_id==vendor_id*/)
break;
}
if (!elems[i].maxlen) {
cw_dbg_version_subelem(DBG_ELEM_ERR, "Can't handle sub-elem, vendor or type unknonw",
cw_dbg_version_subelem(DBG_ELEM_ERR, "Can't handle sub-elem, vendor or type unknown",
subtype, vendor_id, data+sub+8, sublen);
errors++;
} else {

View File

@ -4,13 +4,14 @@
#include "capwap_items.h"
#include "dbg.h"
#include "ktv.h"
#include "keys.h"
static struct cw_DescriptorSubelemDef allowed_default[] = {
{0,CW_SUBELEM_WTP_HARDWARE_VERSION, "hardware_version", 1024,1},
{0,CW_SUBELEM_WTP_SOFTWARE_VERSION, "software_version", 1024,1},
{0,CW_SUBELEM_WTP_BOOTLOADER_VERSION, "bootloader_version", 1024,1},
{0,CW_SUBELEM_WTP_OTHERSOFTWARE_VERSION, "other_software_version", 1024,0},
{0,CW_SUBELEM_WTP_HARDWARE_VERSION, CW_SKEY_HARDWARE, 1024,1},
{0,CW_SUBELEM_WTP_SOFTWARE_VERSION, CW_SKEY_SOFTWARE, 1024,1},
{0,CW_SUBELEM_WTP_BOOTLOADER_VERSION, CW_SKEY_BOOTLOADER, 1024,1},
{0,CW_SUBELEM_WTP_OTHERSOFTWARE_VERSION, CW_SKEY_OTHER_SOFTWARE, 1024,0},
{0,0, NULL, 0,0}
};
@ -19,51 +20,44 @@ int cw_read_wtp_descriptor(mavl_t cfg, struct conn *conn,
struct cw_ElemHandler *eh, uint8_t * data, int len,
struct cw_DescriptorSubelemDef *allowed)
{
printf( "toto here cw_read_wtp_descriptor\n");
exit(0);
/*
int ncrypt, pos,i;
mavldata_t md;
char key[64];
sprintf(key,"%s/%s",eh->key, "max_radios");
md.kv.key=strdup(key);
mavl_replace (cfg, cw_type_byte.get(&md,data,1));
sprintf(key,"%s/%s",eh->key, "radios_in_use");
md.kv.key=strdup(key);
mavl_replace (cfg, cw_type_byte.get(&md,data+1,1));
*/
/* Get number of encryption elements */
/*
ncrypt = cw_get_byte(data + 2);
if (ncrypt == 0) {
if (conn->strict_capwap) {
cw_dbg(DBG_ELEM_ERR,
"Bad WTP Descriptor, number of encryption elements is 0.");
return 0;
return CAPWAP_RESULT_UNRECOGNIZED_MESSAGE_ELEMENT;
}
cw_dbg(DBG_RFC,
"Non standard conform WTP Descriptor, number of encryptoin elements is 0.");
}
pos = 3;
*/
//
// for (i = 0; i < ncrypt; i++) {
///* // It's a dummy for now *
// pos += 3;
// }
sprintf(key,"%s/%s",eh->key, CW_SKEY_MAX_RADIOS);
cw_ktv_add(cfg,key,CW_TYPE_BYTE,data,1);
sprintf(key,"%s/%s",eh->key, CW_SKEY_RADIOS_IN_USE);
cw_ktv_add(cfg,key,CW_TYPE_BYTE,data+1,1);
pos = 3;
for (i = 0; i < ncrypt; i++) {
/* It's a dummy for now */
pos += 3;
}
/*
if (!allowed) {
allowed=allowed_default;
}
printf("call read subelems\n");
return cw_read_descriptor_subelems(cfg,eh->key , data + pos, len - pos, allowed);
*/
}

View File

@ -2,15 +2,16 @@
#include "keys.h"
#include "log.h"
#include "cw.h"
#include "dbg.h"
int cw_write_descriptor_subelem (uint8_t *dst, mavl_t ktvstore,
int subelem_id, const char * parent_key)
int subelem_id, const char * parent_key )
{
char key[256];
cw_KTV_t * vendor, *version ;
uint8_t *d;
/* d += cw_put_dword(d, bstrv_get_vendor_id(v));
d += cw_put_dword(d, (subelem_id << 16) | bstrv_len(v));
d += cw_put_data(d, bstrv_data(v), bstrv_len(v));
@ -19,7 +20,7 @@ int cw_write_descriptor_subelem (uint8_t *dst, mavl_t ktvstore,
vendor = cw_ktv_get (ktvstore, key, CW_TYPE_DWORD);
if (vendor == NULL) {
cw_log (LOG_ERR, "Can't put subelem %s, not value found.", key);
cw_log (LOG_ERR, "Can't put subelem %s, no value found.", key);
return 0;
}
@ -28,7 +29,7 @@ int cw_write_descriptor_subelem (uint8_t *dst, mavl_t ktvstore,
version = cw_ktv_get (ktvstore, key, CW_TYPE_BSTR16);
if (version == NULL) {
cw_log (LOG_ERR, "Can't put subelem %s, not value found.", key);
cw_log (LOG_ERR, "Can't put subelem %s, no value found.", key);
return 0;
}

View File

@ -23,7 +23,7 @@
#include "conn.h"
#include "cwmsg.h"
#include <stdio.h> //Tube
#include <stdio.h>
void cwmsg_addelem_mtu_discovery_padding(struct cwmsg * msg, struct conn* conn)
{

View File

@ -1,13 +1,12 @@
#ifndef __KEYS_H
#define __KEYS_H
#define CW_KEY_WTP_DESCRIPTOR "wtp-descriptor"
#define CW_SKEY_HARDWARE "hardware"
#define CW_SKEY_SOFTWARE "software"
#define CW_SKEY_BOOTLOADER "bootloader"
#define CW_SKEY_OTHER_SOFTWARE "other_software"
#define CW_SKEY_OTHER_SOFTWARE "other-software"
#define CW_SKEY_VENDOR "vendor"
#define CW_SKEY_VERSION "version"
@ -19,9 +18,21 @@
#define CW_KEY_WTP_NAME "wtp-name"
#define CW_KEY_DISCOVERY_TYPE "discovery-type"
#define CW_KEY_WTP_MAC_TYPE "wtp-mac-type"
#define CW_KEY_WTP_BOARD_DATA "wtp-board-data"
#define CW_KEY_WTP_FRAME_TUNNEL_MODE "wtp-frame-tunnel-mode"
#define CW_KEY_WTP_BOARD_DATA "wtp-board-data"
#define CW_SKEY_MODELNO "model-no"
#define CW_SKEY_SERIALNO "serial-no"
#define CW_KEY_AC_DESCRIPTOR "ac-descriptor"
#define CW_SKEY_STATION_LIMIT "station-limit"
#define CW_SKEY_STATIONS "stations"
#define CW_SKEY_ACTIVE_WTPS "active-wtps"
#define CW_SKEY_MAX_WTPS "active-wtps"
#define CW_SKEY_SECURITY "security"
#define CW_SKEY_RMAC_FIELD "rmac-field"
#define CW_SKEY_DTLS_POLICY "dtls-policy"
#endif

View File

@ -16,6 +16,7 @@ struct cw_KTV {
uint16_t word;
uint8_t byte;
void *ptr;
int boolean;
} val;
};
typedef struct cw_KTV cw_KTV_t;
@ -65,6 +66,9 @@ void cw_kvstore_mavl_delete(const void *data);
const char *cw_ktv_add(mavl_t kvstore, const char *key, const struct cw_Type *type,
const uint8_t * data, int len);
const char * cw_ktv_add_from_str(mavl_t kvtstore, const char *key, const struct cw_Type *type,
const char * str);
int cw_ktv_mavlcmp(const void *v1, const void *v2);
int cw_ktv_mavlcmp_type_by_name(const void *v1,const void *v2);
@ -79,5 +83,14 @@ void cw_ktv_mavldel(void *data);
int cw_ktv_read_line (FILE *f, char * key, char * type, char *val);
int cw_ktv_read_file(FILE * file, mavl_t ktv, mavl_t types);
cw_KTV_t * cw_ktv_get(mavl_t ktv, const char *key, const cw_Type_t * type);
uint8_t cw_ktv_get_byte(mavl_t ktv,const char *key, uint8_t def);
uint16_t cw_ktv_get_word(mavl_t ktv,const char *key, uint16_t def);
void cw_ktv_dump(mavl_t ktv, uint32_t dbglevel,
const char *header, const char *prefix, const char *footer );
extern const cw_Type_t * cw_ktv_std_types[];
#define CW_KTV_STD_TYPES cw_ktv_std_types
#endif /* __KVT_H */

View File

@ -44,4 +44,61 @@ int lw_put_sockaddr(uint8_t * dst, struct sockaddr_storage *addr)
}
return 0;
}
}/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
/*
This file is part of libcapwap.
libcapwap is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libcapwap is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/

View File

@ -27,7 +27,7 @@ void lwmsg_init(struct lwmsg * lwmsg, uint8_t * buffer, uint8_t * macaddress,int
{
lwmsg->buffer=buffer;
memcpy (lwmsg->buffer,macaddress,6);
lwmsg->trnsprthdr=buffer+0; //+6;
lwmsg->trnsprthdr=buffer+0; /*+6;*/
LWTH_SET_VERSION(lwmsg->trnsprthdr,LW_VERSION);
LWTH_SET_C_FLAG(lwmsg->trnsprthdr,1);
lwmsg->ctrlhdr=buffer+14;

View File

@ -38,7 +38,7 @@ static void mavl_del_all0(struct mavl *t ,struct mavlnode * n)
*/
void mavl_del_all(struct mavl *t)
{
mavl_del_all0(t,t->root);
mavl_del_all0(t,t->root);
t->root=NULL;
}

View File

@ -1,8 +0,0 @@
#include "mavl.h"
#include "mdata.h"
mdata_create(){
return 0;
}

View File

@ -1,57 +0,0 @@
#ifndef __MDATA_H
#define __MDATA_H
#include <stdint.h>
union mdata_ElemData {
void *raw;
uint8_t byte;
uint16_t word;
uint32_t dword;
uint64_t qword;
};
struct mdata_Elem{
const char * key;
const struct mdata_Type * type;
union mdata_ElemData data;
};
struct mdata_Type{
/** A human readable name for this type */
const char *name;
/** A pointer to a function to delete elements of this type */
void (*del)(void*);
/** A method to put this object to a buffer */
int (*put)(struct mdata_Elem *i,uint8_t*dst);
/** The get emthod */
struct mdata_Elem * (*get)(const uint8_t*src, int len);
/** A pointer to a function to convert elements of this type to a string.
This function is mainly used to store elements to an SQL database
or to json strings */
int (*to_str)(const struct mdata_Elem * e,char *dst);
/** Cereate an item of this type from a string, which was previously
created by the #del function. */
struct mdata_Elem * (*from_str)(const char *src);
/*
int (*def)(void *, void *);
*/
};
struct mdata_Elem *mdata_elem_new( const struct mdata_Type * type );
#endif /* __MDATA_H */

View File

@ -1,15 +0,0 @@
#include <stdlib.h>
#include "mdata.h"
struct mdata_Elem *mdata_elem_new( const struct mdata_Type * type )
{
struct mdata_Elem *i= malloc(sizeof(struct mdata_Elem));
if (!i)
return NULL;
i->type = type;
return i;
}

View File

@ -1,51 +0,0 @@
#include <stdlib.h>
#include <string.h>
#include "mlist.h"
struct mlistelem * mlist_prepend(mlist_t l, void *data){
}
struct mlistelem *mlist_find(mlist_t l, struct mlistelem *start, void *data)
{
/*
struct mlistelem *e;
if (start)
e = start;
else
e = l->first;
while (e) {
if (l->cmp(e->data, data) == 0)
return e;
e = e->next;
}
return NULL;
*/
}
struct mlistelem * xmlist_replace(mlist_t l, struct mlistelem *start, void *data)
{
/*
struct mlistelem *e;
if (start)
e = start;
else
e = l->first;
struct mlistelem * f = mlist_find(l,e,data);
if (!f)
return NULL;
f->data = data;
return f;
*/
}

View File

@ -10,6 +10,7 @@ mlist_t mlist_create(int (*cmp) (const void *v1, const void *v2),
/*memset(l, 0, sizeof(struct mlist));*/
l->cmp = cmp;
l->del = del;
l->data_size=data_size;
l->first=NULL;
l->last=NULL;

View File

@ -193,7 +193,7 @@ void cw_mod_set_path(const char * path){
* @param mod_name Name of the module
* @return a pointer to the module interface
*/
struct cw_Mod * cw_mod_load(const char * mod_name){
struct cw_Mod * cw_mod_load(const char * mod_name, mavl_t global_cfg, int role){
struct cw_Mod search;
struct cw_Mod * mod;
char mod_filename[CW_MOD_MAX_MOD_NAME_LEN+5];
@ -266,7 +266,7 @@ struct cw_Mod * cw_mod_load(const char * mod_name){
goto errX;
}
cw_dbg(DBG_MOD, "MOD: %s sucessfull loaded, calling init now.",filename);
mod->init();
mod->init(mod,global_cfg,role);
errX:
free(filename);
return mod;

View File

@ -29,7 +29,7 @@
#include "sock.h"
#include "conn.h"
#include "action.h"
struct cw_actiondef;
@ -39,16 +39,22 @@ enum {
CW_MOD_MODE_BINDINGS
};
enum {
CW_ROLE_AC=1,
CW_ROLE_WTP=2
};
struct cw_Mod {
/** Name of the module */
const char *name;
/** Initializion method */
int (*init) ();
int (*init) (struct cw_Mod *mod, mavl_t global_cfg, int role);
/** init_config */
int (*init_config) (void * /*mbag_t config*/);
/* int (*init_config) (void *);*/
/** Detect capwap
* This function is called after receiving and disassembling a complete
@ -57,14 +63,9 @@ struct cw_Mod {
* @return 0 if notdetected
**/
int (*detect) (struct conn * conn, const uint8_t * rawmsg, int rawlen,
int elems_len, struct sockaddr * from, int mode);
int elems_len, struct sockaddr * from, int mode);
/** used for private data */
void *data;
/** Register actions */
int (*register_actions) (struct cw_actiondef * def,int mode);
struct cw_MsgSet * (*register_messages)(struct cw_MsgSet * set, int mode);
/**
@ -73,6 +74,9 @@ struct cw_Mod {
* linked, dll_handle is NULL.
*/
void * dll_handle;
/** used for private data */
void *data;
};
@ -93,7 +97,7 @@ extern int mod_caching;
#define mod_set_caching(var) (mod_caching=var)
#define mod_get_caching() (mod_caching)
struct cw_Mod * cw_mod_load(const char * mod_name);
struct cw_Mod * cw_mod_load(const char * mod_name, mavl_t global_cfg, int role);
struct cw_Mod * cw_mod_add_to_list(struct cw_Mod * mod );
struct cw_Mod * cw_mod_detect(struct conn *conn,
uint8_t * rawmsg, int len,

View File

@ -22,7 +22,7 @@
*/
/**
* @defgroup CAPWAPVendors
* @defgroup CAPWAPVendors List of known CAPWAP vendors
* @{ */
#ifndef __CW_VENDORS_H

View File

@ -2,7 +2,6 @@ include ../Config.mak
all:
$(MAKE) -C capwap
$(MAKE) -C capwap80211
$(MAKE) -C cipwap
$(MAKE) -C cisco
$(MAKE) -C fortinet
$(CC) -c modload_ac.c -I../
@ -11,7 +10,6 @@ all:
clean:
$(MAKE) -C capwap clean
$(MAKE) -C capwap80211 clean
$(MAKE) -C cipwap clean
$(MAKE) -C cisco clean
$(MAKE) -C fortinet clean
rm *.o

View File

@ -8,6 +8,7 @@ OBJS=\
mod_capwap_ac.o \
capwap_actions_ac.o \
capwap_in_wtp_board_data.o \
capwap_out_wtp_board_data.o \
capwap_out_ac_descriptor.o \
capwap_out_get_session_id.o \
capwap_out_get_idle_timeout.o \

View File

@ -58,7 +58,7 @@ static struct cw_ElemHandler handlers[] = {
NULL, /* type */
CW_KEY_WTP_BOARD_DATA, /* Key */
capwap_in_wtp_board_data, /* get */
NULL /* put */
capwap_out_wtp_board_data /* put */
}
,
{
@ -69,7 +69,7 @@ static struct cw_ElemHandler handlers[] = {
NULL, /* type */
CW_KEY_WTP_DESCRIPTOR, /* Key */
capwap_in_wtp_descriptor, /* get */
NULL /* put */
capwap_out_wtp_descriptor, /* put */
}
,
{
@ -83,7 +83,6 @@ static struct cw_ElemHandler handlers[] = {
cw_out_generic /* put */
}
,
{
"Vendor Specific Payload", /* name */
CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, /* Element ID */
@ -95,7 +94,6 @@ static struct cw_ElemHandler handlers[] = {
NULL /* put */
}
,
{
"MTU Discovery Padding", /* name */
CAPWAP_ELEM_MTU_DISCOVERY_PADDING, /* Element ID */
@ -108,7 +106,20 @@ static struct cw_ElemHandler handlers[] = {
}
,
{
"AC Descriptor", /* name */
CAPWAP_ELEM_AC_DESCRIPTOR, /* Element ID */
0,0, /* Vendor / Proto */
0,0, /* min/max length */
NULL, /* type */
CW_KEY_AC_DESCRIPTOR, /* Key */
NULL, /* get */
capwap_out_ac_descriptor /* put */
}
,
{0,0,0,0,0,0,0,0}
};
@ -127,6 +138,18 @@ static struct cw_ElemDef discovery_request_elements[] ={
};
static int discovery_response_states[] = {CAPWAP_STATE_DISCOVERY,0};
static struct cw_ElemDef discovery_response_elements[] ={
{0,0,CAPWAP_ELEM_AC_DESCRIPTOR, 1, 0},
{0,0,CAPWAP_ELEM_AC_NAME, 1, 0},
{0,0,CAPWAP_ELEM_AC_IPV4_LIST, 1, 0},
{0,0,CAPWAP_ELEM_AC_IPV6_LIST, 1, 0},
{0,0,CAPWAP_ELEM_VENDOR_SPECIFIC_PAYLOAD, 0, CW_IGNORE},
{0,0,0,0,0}
};
static struct cw_MsgDef messages[] = {
{
"Discovery Request",
@ -135,6 +158,19 @@ static struct cw_MsgDef messages[] = {
discovery_request_states,
discovery_request_elements
},
{
"Discovery Response",
CAPWAP_MSG_DISCOVERY_RESPONSE,
CW_RECEIVER_WTP,
discovery_response_states,
discovery_response_elements
},
/* {
"Discovery Request",
CAPWAP_MSG_DISCOVERY_REQUEST,
@ -184,6 +220,11 @@ struct cw_MsgSet * capwap_register_msg_set(struct cw_MsgSet * set, int mode){
if (mode != CW_MOD_MODE_CAPWAP)
return NULL;
cw_msgset_add(set,messages, handlers);
mavl_add_ptr(set->types_tree,CW_TYPE_BSTR16);
mavl_add_ptr(set->types_tree,CW_TYPE_BYTE);
mavl_add_ptr(set->types_tree,CW_TYPE_DWORD);
mavl_add_ptr(set->types_tree,CW_TYPE_WORD);
return set;
}
@ -196,6 +237,8 @@ void test_sets(){
}
cw_msgset_add(set,messages, handlers);
}
/*
cw_msgset_add(set,messages);

View File

@ -33,7 +33,7 @@ static cw_action_in_t actions_in[] = {
{
.capwap_state = CAPWAP_STATE_DISCOVERY,
.msg_id = CAPWAP_MSG_DISCOVERY_RESPONSE,
.elem_id = CW_ELEM_AC_NAME,
.elem_id = CAPWAP_ELEM_AC_NAME,
.item_id = CW_ITEM_AC_NAME,
.start = cw_in_generic2,
.min_len = 1,
@ -137,7 +137,7 @@ static cw_action_in_t actions_in[] = {
{
.capwap_state = CAPWAP_STATE_JOIN,
.msg_id = CAPWAP_MSG_JOIN_RESPONSE,
.elem_id = CW_ELEM_AC_NAME,
.elem_id = CAPWAP_ELEM_AC_NAME,
.item_id = CW_ITEM_AC_NAME,
.start = cw_in_generic2,
.min_len = 1,
@ -628,7 +628,7 @@ static cw_action_out_t actions_out[] = {
/* AC Name - Config Status Request - OUT */
{
.msg_id = CAPWAP_MSG_CONFIGURATION_STATUS_REQUEST,
.elem_id = CW_ELEM_AC_NAME,
.elem_id = CAPWAP_ELEM_AC_NAME,
.item_id = CW_ITEM_AC_NAME,
.out = cw_out_generic,
.get = cw_out_get_local,

View File

@ -41,9 +41,12 @@ static void readsubelems_wtp_board_data(mavl_t cfg, uint8_t * msgelem,
do {
int subtype;
int sublen;
val = ntohl(*((uint32_t *) (msgelem + i)));
int subtype = (val >> 16) & 0xffff;
int sublen = val & 0xffff;
subtype = (val >> 16) & 0xffff;
sublen = val & 0xffff;
i += 4;
if (sublen + i > len) {
cw_dbg(DBG_ELEM_ERR,
@ -96,7 +99,7 @@ static void readsubelems_wtp_board_data(mavl_t cfg, uint8_t * msgelem,
key = NULL;
break;
}
if (key){
if (key != NULL){
char add_key[256];
sprintf(add_key,"wtp_board_data/%s",key);
cw_ktv_add(cfg,add_key,CW_TYPE_BSTR16,msgelem+i,sublen);

View File

@ -26,12 +26,7 @@ int capwap_in_wtp_descriptor(struct cw_ElemHandler *eh, struct cw_ElemHandlerPar
int len)
{
int rc;
//printf("WTP Descriptor reader\n");
/*
// mbag_t mbag = conn->incomming;
*/
rc =cw_read_wtp_descriptor(params->conn->remote_cfg, params->conn, eh, data, len, NULL);
return rc;
}

View File

@ -8,48 +8,70 @@
#include "cw/cw.h"
#include "cw/ktv.h"
#include "cw/keys.h"
int capwap_out_ac_descriptor(struct conn *conn,struct cw_action_out * a,uint8_t *dst)
{
static int put_ac_status(mavl_t global, mavl_t local, uint8_t *dst, const char * parent_key){
uint8_t *d = dst+4;
struct mbag_item * i;
i = mbag_get(conn->local,CW_ITEM_AC_STATUS);
uint8_t *d = dst;
uint8_t security;
if (!i) {
cw_log(LOG_ERR,"Can't send AC Descriptor, no AC Status Item found");
return 0;
}
d+=cw_put_ac_status(d ,(struct cw_ac_status*)(i->u2.data),conn);
/*
i = mbag_get(conn->local,CW_ITEM_AC_HARDWARE_VERSION);
if ( i ) {
d += cw_put_version(d,CW_SUBELEM_AC_HARDWARE_VERSION,i->u2.data);
}
else {
cw_log(LOG_ERR, "Can't send hard version in AC descriptor, not set.");
}
char key[CW_KTV_MAX_KEY_LEN];
i = mbag_get(conn->local,CW_ITEM_AC_SOFTWARE_VERSION);
if ( i ) {
d += cw_put_version(d,CW_SUBELEM_AC_SOFTWARE_VERSION,i->u2.data);
d += cw_put_word(d,cw_ktv_get_word(global,"ac/ac-descriptor/stations",0));
d += cw_put_word(d,cw_ktv_get_word(global,"ac/ac-descriptor/station-limit",0));
d += cw_put_word(d,cw_ktv_get_word(global,"ac/ac-descriptor/active-wtps",0));
d += cw_put_word(d,cw_ktv_get_word(global,"ac/ac-descriptor/max-wtps",0));
security = 0;
if (cw_ktv_get(local,"dtls-cert-file",CW_TYPE_BSTR16))
security |= CAPWAP_FLAG_AC_SECURITY_X;
if (cw_ktv_get(local,"dtls-psk",CW_TYPE_BSTR16))
security |= CAPWAP_FLAG_AC_SECURITY_S;
if (security == 0){
cw_log(LOG_WARNING,"Attention: no AC security selected");
}
else {
cw_log(LOG_ERR, "Can't send software version in AC descriptor, not set.");
}
*/
int len = d-dst-4;
d += cw_put_byte(dst,security);
return len + cw_put_elem_hdr(dst,a->elem_id,len);
sprintf(key,"%s/%s",parent_key,CW_SKEY_RMAC_FIELD);
d += cw_put_byte(d,cw_ktv_get_byte(local,key,0));
d += cw_put_byte(d,0);
sprintf(key,"%s/%s",parent_key,CW_SKEY_DTLS_POLICY);
d += cw_put_byte(d,cw_ktv_get_byte(local,key,0));
return d - dst;
}
int capwap_out_ac_descriptor(struct cw_ElemHandler * eh,
struct cw_ElemHandlerParams * params, uint8_t * dst)
{
int len;
uint8_t *d = dst+4;
char key[CW_KTV_MAX_KEY_LEN];
d+=put_ac_status(params->conn->local_cfg,
params->conn->global_cfg,
d, eh->key);
sprintf(key,"%s/%s",eh->key,CW_SKEY_HARDWARE);
d+=cw_write_descriptor_subelem (d, params->conn->local_cfg,
CW_SUBELEM_AC_HARDWARE_VERSION, key);
sprintf(key,"%s/%s",eh->key,CW_SKEY_SOFTWARE);
d+=cw_write_descriptor_subelem (d, params->conn->local_cfg,
CW_SUBELEM_AC_HARDWARE_VERSION, key);
len = d-dst-4;
return len + cw_put_elem_hdr(dst,eh->id,len);
}

View File

@ -0,0 +1,74 @@
#include "cw/log.h"
#include "cw/ktv.h"
#include "cw/msgset.h"
#include "cw/keys.h"
#include "cw/cw.h"
static int write_boarddata_subelem(uint8_t * dst, mavl_t ktv, const char * parent_key,
const char *skey, int type){
char key[256];
cw_KTV_t * val;
uint8_t *d;
d=dst;
sprintf(key,"%s/%s",parent_key,skey);
val = cw_ktv_get(ktv,key,CW_TYPE_BSTR16);
if (val == NULL) {
cw_log(LOG_ERR,
"Error: Can't set sub-element %d from key %s in WTP Board Data. Key not found",type,key);
return 0;
}
d += cw_put_word(d, type);
d += cw_put_word(d, val->type->len(val));
d += val->type->put(val,d);
return d-dst;
}
int capwap_out_wtp_board_data(struct cw_ElemHandler * eh,
struct cw_ElemHandlerParams * params, uint8_t * dst)
{
cw_KTV_t * val;
mavl_t cfg;
uint8_t * d;
char key[256];
int l;
d=dst+4;
cfg = params->conn->local_cfg;
sprintf(key,"%s/%s",eh->key,CW_SKEY_VENDOR);
val = cw_ktv_get(cfg,key,CW_TYPE_DWORD);
if (val ==NULL) {
cw_log(LOG_ERR,
"Error: Can't send WTP Board Data element - %s not defined.", key);
return 0;
}
d += val->type->put(val,d);
/*cw_ktv_add(cfg,vendor_key,CW_TYPE_DWORD,data,len);*/
d+=write_boarddata_subelem(d,cfg,eh->key,CW_SKEY_MODELNO,CW_BOARDDATA_MODELNO);
d+=write_boarddata_subelem(d,cfg,eh->key,CW_SKEY_SERIALNO,CW_BOARDDATA_SERIALNO);
d+=write_boarddata_subelem(d,cfg,eh->key,"board-id",CW_BOARDDATA_BOARDID);
d+=write_boarddata_subelem(d,cfg,eh->key,"board-revision",CW_BOARDDATA_REVISION);
d+=write_boarddata_subelem(d,cfg,eh->key,"mac-address",CW_BOARDDATA_MACADDRESS);
l = d - dst-4;
return l + cw_put_elem_hdr(dst, CAPWAP_ELEM_WTP_BOARD_DATA, l );
}

View File

@ -1,16 +1,19 @@
#include "cw/mbag.h"
#include "cw/log.h"
#include "cw/conn.h"
#include "cw/capwap_items.h"
#include "cw/cw.h"
#include "cw/ktv.h"
#include "cw/keys.h"
#include "cw/dbg.h"
static int cw_put_encryption_subelems(uint8_t *dst,int capwap_mode)
{
int n=2;
dst+=cw_put_byte(dst,n);
int i;
dst+=cw_put_byte(dst,n);
for (i=0; i<n; i++){
dst+=cw_put_byte(dst,0);
dst+=cw_put_byte(dst,0);
@ -21,59 +24,56 @@ static int cw_put_encryption_subelems(uint8_t *dst,int capwap_mode)
}
int capwap_out_wtp_descriptor(struct conn *conn, struct cw_action_out *a, uint8_t * dst)
int capwap_out_wtp_descriptor(struct cw_ElemHandler * eh,
struct cw_ElemHandlerParams * params, uint8_t * dst)
{
char key[CW_KTV_MAX_KEY_LEN];
int len;
/* // XXX Dummy WTP Descriptor Header */
uint8_t *d;
cw_KTV_t * val;
d = dst+4;
mbag_t mbag = conn->config;
// XXX Dummy WTP Descriptor Header
uint8_t *d = dst+4;
//int n =conn->radios->count;
//printf("radio count %d\n",n);
d+=cw_put_byte(d,conn->radios->count); //max radios
d+=cw_put_byte(d,2); //radios in use
d+=cw_put_encryption_subelems(d,conn->capwap_mode);
mbag_item_t * i;
i = mbag_get(mbag,CW_ITEM_WTP_HARDWARE_VERSION);
/* if ( i ) {
d += cw_put_version(d,CW_SUBELEM_WTP_HARDWARE_VERSION,i->u2.data);
if (bstrv_get_vendor_id(i->u2.data)){
d += cw_put_dword(d, 0);
d += cw_put_word(d, CW_SUBELEM_WTP_HARDWARE_VERSION);
d += cw_put_word(d, bstrv_len(i->u2.data));
d += cw_put_data(d, bstrv_data(i->u2.data), bstrv_len(i->u2.data));
}
sprintf(key,"%s/%s",eh->key,CW_SKEY_MAX_RADIOS);
val = cw_ktv_get(params->conn->local_cfg,key, CW_TYPE_BYTE);
if (val != NULL)
d+=val->type->put(val,d);
else{
cw_dbg(DBG_WARN,"Cannot get value for %s, setting to 0", CW_SKEY_MAX_RADIOS);
d+=cw_put_byte(d,0);
}
else {
cw_log(LOG_ERR, "Can't send Hardware Version in WTP Descriptor, not set.");
sprintf(key,"%s/%s",eh->key,CW_SKEY_RADIOS_IN_USE);
val = cw_ktv_get(params->conn->local_cfg,key, CW_TYPE_BYTE);
if (val != NULL){
d+=val->type->put(val,d);
}
else{
d+=cw_put_byte(d,0); /*radios in use*/
}
*/
i = mbag_get(mbag,CW_ITEM_WTP_SOFTWARE_VERSION);
/* d+=cw_put_encryption_capabilities_7(d,1); */
d+=cw_put_encryption_subelems(d,params->conn->capwap_mode);
/* if ( i ) {
d += cw_put_version(d,CW_SUBELEM_WTP_SOFTWARE_VERSION,i->u2.data);
}
else {
cw_log(LOG_ERR, "Can't send Software Version in WTP descriptor, not set.");
}
i = mbag_get(mbag,CW_ITEM_WTP_BOOTLOADER_VERSION);
if ( i ) {
d += cw_put_version(d,CW_SUBELEM_WTP_BOOTLOADER_VERSION,i->u2.data);
}
else {
cw_log(LOG_ERR, "Can't send Bootloader Version in WTP descriptor, not set.");
}
cw_ktv_dump(params->conn->local_cfg,DBG_INFO,"*** ktv dump ***","","*** end of dump ***");
*/
int len = d-dst-4;
return len + cw_put_elem_hdr(dst,a->elem_id,len);
}
/* hardware version sub element */
sprintf(key,"%s/%s",eh->key,CW_SKEY_HARDWARE);
d+=cw_write_descriptor_subelem (d, params->conn->local_cfg,
CW_SUBELEM_WTP_HARDWARE_VERSION, key);
/* software version sub element */
sprintf(key,"%s/%s",eh->key,CW_SKEY_SOFTWARE);
d+=cw_write_descriptor_subelem (d, params->conn->local_cfg,
CW_SUBELEM_WTP_SOFTWARE_VERSION, key);
/* bootloader version sub element */
sprintf(key,"%s/%s",eh->key,CW_SKEY_BOOTLOADER);
d+=cw_write_descriptor_subelem (d, params->conn->local_cfg,
CW_SUBELEM_WTP_BOOTLOADER_VERSION, key);
len = d-dst-4;
return len + cw_put_elem_hdr(dst,eh->id,len);
}

View File

@ -11,8 +11,22 @@ struct cw_Mod *mod_capwap_wtp();
/*extern int capwap_in_wtp_descriptor(struct conn *conn, struct cw_ElemHandler *eh,
uint8_t * data, int len, struct sockaddr *from);*/
int capwap_in_wtp_descriptor(struct cw_ElemHandler *eh, struct cw_ElemHandlerParams *params, uint8_t * data,
int len);
int capwap_in_wtp_descriptor(struct cw_ElemHandler *eh,
struct cw_ElemHandlerParams *params, uint8_t * data, int len);
int capwap_out_wtp_descriptor(struct cw_ElemHandler * eh,
struct cw_ElemHandlerParams * params, uint8_t * dst);
int capwap_out_ac_descriptor(struct cw_ElemHandler * eh,
struct cw_ElemHandlerParams * params, uint8_t * dst);
/*
extern int capwap_in_wtp_board_data(struct conn *conn, struct cw_ElemHandler *a,
uint8_t * data, int len, struct sockaddr *from);
@ -20,7 +34,10 @@ extern int capwap_in_wtp_board_data(struct conn *conn, struct cw_ElemHandler *a,
int capwap_in_wtp_board_data(struct cw_ElemHandler *eh, struct cw_ElemHandlerParams *params,
uint8_t * data, int len);
int capwap_out_wtp_board_data(struct cw_ElemHandler * eh,
struct cw_ElemHandlerParams * params, uint8_t * dst);
int capwap_in_vendor_specific_payload(struct cw_ElemHandler *handler,
struct cw_ElemHandlerParams *params,
uint8_t * data, int len);

View File

@ -1,23 +1,37 @@
#include "cw/mbag.h"
#include "cw/mod.h"
#include "cw/log.h"
#include "cw/dbg.h"
#include "cw/ktv.h"
#include "cw/keys.h"
#include "cw/action.h"
#include "mod_capwap.h"
//static struct cw_actiondef actions;
extern int capwap_register_actions_ac(struct cw_actiondef *def);
static int init()
static int init(struct cw_Mod * mod, mavl_t global_cfg, int role)
{
cw_dbg(DBG_MOD, "CAPWAP: Initialiazing mod_capwap.");
switch (role){
case CW_ROLE_AC:{
cw_dbg(DBG_MOD, "CAPWAP: Initialiazing mod_capwap in AC mode");
cw_ktv_add_from_str(global_cfg,
"capwap/ac-descriptor/hardware/version",
CW_TYPE_BSTR16,"0.0.0.1");
cw_ktv_add_from_str(global_cfg,
"capwap/ac-descriptor/hardware/vendor",CW_TYPE_DWORD,"0");
cw_ktv_add_from_str(global_cfg,
"capwap/ac-descriptor/software/version",
CW_TYPE_BSTR16,"0.0.0.1");
cw_ktv_add_from_str(global_cfg,
"capwap/ac-descriptor/software/vendor",CW_TYPE_DWORD,"0");
}
break;
}
return 0;
}
@ -31,29 +45,18 @@ static int detect(struct conn *conn, const uint8_t * rawmsg, int rawlen, int ele
return 1;
}
static int register_actions(struct cw_actiondef *def, int mode)
{
if (mode != CW_MOD_MODE_CAPWAP)
return 0;
return 0; //capwap_register_actions_ac(def);
}
static struct cw_Mod capwap_ac = {
.name = "capwap",
.init = init,
.detect = detect,
.register_actions = register_actions,
.register_messages = capwap_register_msg_set
static struct cw_Mod capwap_data = {
"capwap", /* name */
init, /* init */
detect, /* detect */
capwap_register_msg_set, /* register_messages */
NULL, /* dll_handle */
NULL /* data */
};
struct cw_Mod *mod_capwap_ac()
{
return &capwap_ac;
};
struct cw_Mod * mod_capwap(){
return &capwap_ac;
}
return &capwap_data;
}

View File

@ -40,7 +40,7 @@ OBJDIR := ../../../obj/mod_cisco/$(ARCH)
SNAME := $(LIBARCHDIR)/libmod_cisco.a
DNAME := $(LIBARCHDIR)/mod_cisco.so
MODNAME := $(LIBDIR)/mod_cisco.so
SLIBS := -lcw -lmod_cipwap -lmod_capwap -lconfuse
SLIBS := -lcw -lmod_capwap -lconfuse
include ../Mod.mak

View File

@ -33,7 +33,7 @@
#include "include/capwap_actions.h"
#include "mod_cisco.h"
#include "cisco.h"
#include "cisco_items.h"
@ -134,7 +134,7 @@ static cw_action_in_t actions_in[] = {
{
.capwap_state = CAPWAP_STATE_DISCOVERY,
.msg_id = CAPWAP_MSG_DISCOVERY_REQUEST,
.end = cw_in_check_disc_req
/* .end = cw_in_check_disc_req*/
}
,
@ -262,7 +262,7 @@ static cw_action_in_t actions_in[] = {
/* We have to deal with zero-length strings */
.capwap_state = CW_STATE_CONFIGURE,
.msg_id = CAPWAP_MSG_CONFIGURATION_STATUS_REQUEST,
.elem_id = CW_ELEM_AC_NAME,
.elem_id = CAPWAP_ELEM_AC_NAME,
.item_id = CW_ITEM_AC_NAME,
.start = cw_in_generic,
.min_len = 0,
@ -507,7 +507,7 @@ static cw_action_out_t actions_out[]={
.vendor_id = CW_VENDOR_ID_CISCO,
.elem_id = CW_CISCO_RAD_NAME,
.out=cw_out_generic,
.get = cw_out_get_outgoing
/*.get = cw_out_get_outgoing*/
}
,
@ -528,7 +528,7 @@ static cw_action_out_t actions_out[]={
.elem_id = CW_CISCO_AP_LED_STATE_CONFIG,
.item_id = CISCO_ITEM_AP_LED_STATE_CONFIG,
.out = cw_out_generic,
.get = cw_out_get_outgoing,
/*.get = cw_out_get_outgoing,*/
.mand = 0
}
,
@ -541,7 +541,7 @@ static cw_action_out_t actions_out[]={
.elem_id = CW_CISCO_AP_LED_FLASH_CONFIG,
.item_id = CISCO_ITEM_AP_LED_FLASH_CONFIG,
.out = cw_out_generic,
.get = cw_out_get_outgoing,
/*.get = cw_out_get_outgoing,*/
.mand = 0
}
,
@ -553,7 +553,7 @@ static cw_action_out_t actions_out[]={
.elem_id = CW_CISCO_AP_MODE_AND_TYPE,
.item_id = CISCO_ITEM_AP_MODE_AND_TYPE,
.out = cw_out_generic,
.get = cw_out_get_outgoing,
/*.get = cw_out_get_outgoing,*/
}
,
@ -601,7 +601,7 @@ static cw_action_in_t actions80211_in[] = {
.msg_id = CAPWAP_MSG_DISCOVERY_REQUEST,
.elem_id = CW_ELEM80211_WTP_RADIO_INFORMATION,
.item_id = CW_RADIOITEM80211_WTP_RADIO_INFORMATION,
.start = cw_in_radio_generic,
/*.start = cw_in_radio_generic, */
.mand = 0,
.min_len = 5,
.max_len = 5
@ -618,7 +618,7 @@ static cw_action_in_t actions80211_in[] = {
.msg_id = CAPWAP_MSG_CONFIGURATION_STATUS_REQUEST,
.elem_id = CW_CISCO_SUPPORTED_RATES,
.item_id = CW_RADIOITEM80211_SUPPORTED_RATES,
.start = cw_in_radio_generic,
/*.start = cw_in_radio_generic, */
.mand = 0,
.min_len = 5,
.max_len = 5

View File

@ -31,7 +31,7 @@
#include "include/cipwap_items.h"
#include "mod_cisco.h"
/*#include "mod_cisco.h"*/
#include "cisco.h"
#include "cisco80211.h"
@ -284,7 +284,7 @@ static cw_action_out_t actions_out[]={
.elem_id = CW_CISCO_RAD_NAME,
.item_id = CW_ITEM_WTP_NAME,
.out = cw_out_generic,
.get = cw_out_get_config,
/* .get = cw_out_get_config,*/
.mand = 1
}
,
@ -321,7 +321,7 @@ static cw_action_out_t actions_out[]={
.elem_id = CW_CISCO_AP_GROUP_NAME,
.item_id = CIPWAP_ITEM_WTP_GROUP_NAME,
.out = cw_out_generic,
.get = cw_out_get_config,
/*.get = cw_out_get_config,*/
.mand = 1
}
,
@ -333,7 +333,7 @@ static cw_action_out_t actions_out[]={
.elem_id = CW_CISCO_BOARD_DATA_OPTIONS,
.item_id = CW_ITEM_CISCO_BOARD_DATA_OPTIONS,
.out = cisco_out_board_data_options,
.get = cw_out_get_config,
/* .get = cw_out_get_config,*/
.mand = 1
}
,
@ -359,7 +359,7 @@ static cw_action_out_t actions_out[]={
.elem_id = CW_CISCO_AP_MODE_AND_TYPE,
.item_id = CISCO_ITEM_AP_MODE_AND_TYPE,
.out = cw_out_generic,
.get = cw_out_get_config,
/* .get = cw_out_get_config,*/
.mand = 1
}
,
@ -493,7 +493,7 @@ static cw_action_out_t actions80211_out[]={
.elem_id = CW_ELEM80211_WTP_RADIO_INFORMATION,
.item_id = CW_RADIOITEM80211_WTP_RADIO_INFORMATION,
.out = cisco_out_80211_wtp_radio_cfg,
.get = cw_out_get_config,
/*.get = cw_out_get_config,*/
.mand = 1
}
,

View File

@ -1,28 +1,20 @@
#include "cw/log.h"
#include "cw/conn.h"
#include "cw/capwap_items.h"
#include "cw/cw.h"
#include "cisco.h"
#include "cw/ktv.h"
#include "cw/keys.h"
#include "cw/dbg.h"
int cisco_out_wtp_descriptor(struct cw_ElemHandler * eh, struct cw_ElemHandlerParams * params
, uint8_t * dst)
int cisco_out_wtp_descriptor(struct cw_ElemHandler * eh,
struct cw_ElemHandlerParams * params, uint8_t * dst)
{
char key[256];
char key[CW_KTV_MAX_KEY_LEN];
int len;
/* // XXX Dummy WTP Descriptor Header */
uint8_t *d;
cw_KTV_t * val;
d = dst+4;
/*cw_ktv_init_byte(&val,8);*/
sprintf(key,"%s/%s",eh->key,CW_SKEY_MAX_RADIOS);
val = cw_ktv_get(params->conn->local_cfg,key, CW_TYPE_BYTE);
if (val != NULL)
@ -32,7 +24,7 @@ int cisco_out_wtp_descriptor(struct cw_ElemHandler * eh, struct cw_ElemHandlerPa
d+=cw_put_byte(d,0);
}
sprintf(key,"%s/%s",eh->key,CW_SKEY_RADIOS_IN_USE);
sprintf(key,"%s/%s",eh->key,CW_SKEY_RADIOS_IN_USE);
val = cw_ktv_get(params->conn->local_cfg,key, CW_TYPE_BYTE);
if (val != NULL){
d+=val->type->put(val,d);
@ -41,28 +33,8 @@ int cisco_out_wtp_descriptor(struct cw_ElemHandler * eh, struct cw_ElemHandlerPa
d+=cw_put_byte(d,0); /*radios in use*/
}
/*len = handler->type->put(elem,dst+start);*/
d+=cw_put_encryption_capabilities_7(d,1);
/* d += cw_put_dword(d, bstrv_get_vendor_id(v));
d += cw_put_dword(d, (subelem_id << 16) | bstrv_len(v));
d += cw_put_data(d, bstrv_data(v), bstrv_len(v));
*/
/* sprintf(key,"%s/%s/%s",eh->key,CW_SKEY_HARDWARE,CW_SKEY_VENDOR);
vendor = cw_ktv_get(params->conn->local_cfg,key,CW_TYPE_DWORD);
sprintf(key,"%s/%s/%s",eh->key,CW_SKEY_HARDWARE,CW_SKEY_VENDOR);
version = cw_ktv_get(params->conn->local_cfg,key,CW_TYPE_BSTR16);
if (vendor == NULL){
cw_log(LOG_ERR, "Can't send %s, not found.", key);
}
*/
/* hardware version sub element */
sprintf(key,"%s/%s",eh->key,CW_SKEY_HARDWARE);
@ -74,43 +46,11 @@ int cisco_out_wtp_descriptor(struct cw_ElemHandler * eh, struct cw_ElemHandlerPa
d+=cw_write_descriptor_subelem (d, params->conn->local_cfg,
CW_SUBELEM_WTP_SOFTWARE_VERSION, key);
/* bootloader version sub element */
/* bootloader version sub element */
sprintf(key,"%s/%s",eh->key,CW_SKEY_BOOTLOADER);
d+=cw_write_descriptor_subelem (d, params->conn->local_cfg,
CW_SUBELEM_WTP_BOOTLOADER_VERSION, key);
/* mbag_item_t * i;
i = mbag_get(mbag,CW_ITEM_WTP_HARDWARE_VERSION);
*/
/* if ( i ) {
d += cw_put_version(d,CW_SUBELEM_WTP_HARDWARE_VERSION,i->u2.data);
}
else {
cw_log(LOG_ERR, "Can't send Hardware Version in WTP Descriptor, not set.");
}
*/
/*i = mbag_get(mbag,CW_ITEM_WTP_SOFTWARE_VERSION);*/
/*
if ( i ) {
d += cw_put_version(d,CW_SUBELEM_WTP_SOFTWARE_VERSION,i->u2.data);
}
else {
cw_log(LOG_ERR, "Can't send Software Version in WTP descriptor, not set.");
}
i = mbag_get(mbag,CW_ITEM_WTP_BOOTLOADER_VERSION);
if ( i ) {
d += cw_put_version(d,CW_SUBELEM_WTP_BOOTLOADER_VERSION,i->u2.data);
}
else {
cw_log(LOG_ERR, "Can't send Bootloader Version in WTP descriptor, not set.");
}
*/
len = d-dst-4;
return len + cw_put_elem_hdr(dst,eh->id,len);
}
}

View File

@ -1,9 +0,0 @@
#ifndef __MOD_CISCO_H
#define __MOD_CISCO_H
struct cw_Mod * mod_cisco_ac();
struct cw_Mod * mod_cisco_wtp();
struct cw_MsgSet * cisco_register_msg_set(struct cw_MsgSet * set, int mode);
#endif

View File

@ -7,7 +7,7 @@
#include "cw/action.h"
#include "mod_cisco.h"
/*#include "mod_cisco.h"*/
#include "../modload.h"
#include "cw/vendors.h"

View File

@ -154,7 +154,7 @@ static cw_action_in_t actions_in[] = {
/* We have to deal with zero-length strings */
.capwap_state = CW_STATE_CONFIGURE,
.msg_id = CW_MSG_CONFIGURATION_STATUS_REQUEST,
.elem_id = CW_ELEM_AC_NAME,
.elem_id = CAPWAP_ELEM_AC_NAME,
.item_id = CW_ITEM_AC_NAME,
.start = cw_in_generic2,
.min_len = 0,

View File

@ -8,12 +8,12 @@ struct cw_Mod * modload_wtp(const char *name);
#include "cipwap/mod_cipwap.h"
#include "capwap/mod_capwap.h"
#include "cisco/mod_cisco.h"
#include "fortinet/mod_fortinet.h"
#include "zyxel/mod_zyxel.h"
#include "capwap80211/mod_capwap80211.h"
#define MODS_AC { mod_capwap_ac, mod_cipwap_ac, mod_cisco_ac, /*mod_zyxel_ac,*/ mod_capwap80211_ac, mod_fortinet_ac, NULL }
#define MODS_WTP { mod_capwap_wtp, mod_cipwap_wtp, mod_cisco_wtp, mod_capwap80211_wtp, mod_fortinet_wtp, NULL }
#define MODS_AC { mod_capwap_ac, mod_cipwap_ac, /*mod_zyxel_ac,*/ mod_capwap80211_ac, mod_fortinet_ac, NULL }
#define MODS_WTP { mod_capwap_wtp, mod_cipwap_wtp, mod_capwap80211_wtp, mod_fortinet_wtp, NULL }

View File

@ -25,7 +25,7 @@ static int parse_args (int argc, char *argv[], struct bootcfg * bootcfg)
int c;
opterr = 1;
bootcfg->modname = "cisco";
bootcfg->modname = "capwap";
bootcfg->cfgfilename = "config.ktv";
while ( (c = getopt (argc, argv, "p:d:vc:m:h")) != -1) {
@ -73,6 +73,8 @@ int main (int argc, char **argv)
struct cw_MsgSet * msgset;
struct conn * conn;
FILE * file;
mavl_t global_cfg, types_tree;
const cw_Type_t ** ti;
parse_args(argc,argv, &bootcfg);
@ -82,11 +84,30 @@ int main (int argc, char **argv)
cw_log(LOG_ERR, "Error creating msgset: %s", strerror(errno));
exit(EXIT_FAILURE);
}
mod = cw_mod_load(bootcfg.modname);
global_cfg=cw_ktv_create();
/* create types tree with default types */
types_tree = cw_ktv_create_types_tree();
for (ti=CW_KTV_STD_TYPES;*ti;ti++){
mavl_add_ptr(types_tree,*ti);
}
file = fopen(bootcfg.cfgfilename,"r");
if (file == NULL){
cw_log(LOG_ERR,"Cant open file '%s':%s", strerror(errno));
exit(EXIT_FAILURE);
}
cw_ktv_read_file(file,global_cfg,types_tree);
cw_ktv_dump(global_cfg,DBG_INFO,"----- global cfg start -----","","----- global cfg end -----");
mod = cw_mod_load(bootcfg.modname, global_cfg, CW_ROLE_WTP);
if (mod == NULL){
exit (EXIT_FAILURE);
}
/* Build a message set from our loaded modules */
mod->register_messages(msgset, CW_MOD_MODE_CAPWAP);
mod->register_messages(msgset, CW_MOD_MODE_BINDINGS);
@ -102,15 +123,9 @@ int main (int argc, char **argv)
conn->dtls_verify_peer=0;
conn->dtls_mtu = 12000;
conn->msgset=msgset;
conn->local_cfg = cw_ktv_create();
conn->local_cfg = global_cfg;
file = fopen(bootcfg.cfgfilename,"r");
if (file == NULL){
cw_log(LOG_ERR,"Cant open file '%s':%s", strerror(errno));
exit(EXIT_FAILURE);
}
cw_ktv_read_file(file,conn->local_cfg,msgset->types_tree);
cw_run_discovery(conn, "255.255.255.255",NULL);