2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
#include <stdio.h>
|
2018-03-12 11:22:06 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
\
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2018-03-12 11:22:06 +01:00
|
|
|
#include "cw/ktv.h"
|
2016-03-03 19:51:42 +01:00
|
|
|
#include "cw/dbg.h"
|
2018-03-12 11:22:06 +01:00
|
|
|
#include "cw/log.h"
|
|
|
|
#include "cw/msgset.h"
|
2018-04-01 08:28:27 +02:00
|
|
|
#include "cw/cw.h"
|
2016-03-11 18:16:13 +01:00
|
|
|
|
2018-04-02 01:39:08 +02:00
|
|
|
#include "cw/dtls.h"
|
2018-03-12 18:01:40 +01:00
|
|
|
#include "wtp.h"
|
|
|
|
|
2018-03-30 19:45:27 +02:00
|
|
|
#define MAX_MODS 32
|
2018-03-12 11:22:06 +01:00
|
|
|
struct bootcfg{
|
2018-03-30 19:45:27 +02:00
|
|
|
const char * modnames[MAX_MODS];
|
2018-03-27 07:07:14 +02:00
|
|
|
int nmods;
|
2018-03-12 11:22:06 +01:00
|
|
|
const char * modpath;
|
|
|
|
const char * cfgfilename;
|
|
|
|
};
|
2016-03-11 18:16:13 +01:00
|
|
|
|
2018-03-12 18:01:40 +01:00
|
|
|
|
2018-04-07 19:28:22 +02:00
|
|
|
bstr_t get_base_rmac()
|
|
|
|
{
|
|
|
|
|
2018-04-27 14:04:03 +02:00
|
|
|
static uint8_t rm[8]={0x00,0x3e,0x99,0x04,0xfa,0xc0};
|
2018-04-07 19:28:22 +02:00
|
|
|
return bstr_create(rm, 6);
|
|
|
|
}
|
|
|
|
|
2018-04-02 18:19:28 +02:00
|
|
|
|
|
|
|
|
2018-03-12 11:22:06 +01:00
|
|
|
static int parse_args (int argc, char *argv[], struct bootcfg * bootcfg)
|
2016-03-11 18:16:13 +01:00
|
|
|
{
|
2018-03-12 11:22:06 +01:00
|
|
|
int c;
|
|
|
|
opterr = 1;
|
|
|
|
|
|
|
|
bootcfg->cfgfilename = "config.ktv";
|
|
|
|
|
|
|
|
while ( (c = getopt (argc, argv, "p:d:vc:m:h")) != -1) {
|
2016-03-11 18:16:13 +01:00
|
|
|
|
2018-03-12 11:22:06 +01:00
|
|
|
switch (c) {
|
|
|
|
case 'v':
|
|
|
|
printf("WFAT version 0.0.1\n");
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
break;
|
|
|
|
case 'd':{
|
2018-03-17 19:32:44 +01:00
|
|
|
if (!cw_dbg_set_level_from_str(optarg)){
|
2018-03-12 11:22:06 +01:00
|
|
|
fprintf(stderr,"Invalid debug option: %s\n",optarg);
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 'm':
|
2018-03-30 19:45:27 +02:00
|
|
|
if (bootcfg->nmods>MAX_MODS){
|
|
|
|
fprintf(stderr,"Too many modules\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2018-03-27 07:07:14 +02:00
|
|
|
bootcfg->modnames[bootcfg->nmods++] = optarg;
|
2018-03-12 11:22:06 +01:00
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
cw_mod_set_path(optarg);
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
bootcfg->cfgfilename = optarg;
|
2018-03-24 07:56:05 +01:00
|
|
|
break;
|
2018-03-12 11:22:06 +01:00
|
|
|
case '?':
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
default:
|
|
|
|
case 'h':
|
|
|
|
printf("%s: -vcmh\n",argv[0]);
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
break;
|
|
|
|
}
|
2016-03-11 18:16:13 +01:00
|
|
|
}
|
2018-03-12 11:22:06 +01:00
|
|
|
return 0;
|
2016-03-11 18:16:13 +01:00
|
|
|
}
|
|
|
|
|
2018-03-30 19:45:27 +02:00
|
|
|
#include "cw/rand.h"
|
2018-03-15 20:07:17 +01:00
|
|
|
|
2018-03-12 11:22:06 +01:00
|
|
|
int main (int argc, char **argv)
|
2014-07-11 22:12:11 +02:00
|
|
|
{
|
2018-03-12 11:22:06 +01:00
|
|
|
struct bootcfg bootcfg;
|
|
|
|
struct cw_Mod * mod;
|
|
|
|
struct cw_MsgSet * msgset;
|
2018-03-12 18:01:40 +01:00
|
|
|
struct conn * conn;
|
2018-03-15 20:07:17 +01:00
|
|
|
FILE * file;
|
2018-03-17 12:32:40 +01:00
|
|
|
mavl_t global_cfg, types_tree;
|
|
|
|
const cw_Type_t ** ti;
|
2018-03-27 07:07:14 +02:00
|
|
|
int i;
|
2018-04-01 12:44:05 +02:00
|
|
|
struct cw_DiscoveryResult dis;
|
2018-03-30 19:45:27 +02:00
|
|
|
|
2018-04-02 18:19:28 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2018-04-14 00:50:58 +02:00
|
|
|
|
|
|
|
|
2018-03-27 07:07:14 +02:00
|
|
|
bootcfg.nmods=0;
|
2018-03-12 11:22:06 +01:00
|
|
|
|
2018-03-17 16:21:23 +01:00
|
|
|
/* read command line args, results are in bootcfg */
|
2018-03-12 11:22:06 +01:00
|
|
|
parse_args(argc,argv, &bootcfg);
|
2018-03-27 07:07:14 +02:00
|
|
|
|
|
|
|
if (bootcfg.nmods==0){
|
|
|
|
bootcfg.modnames[0]="capwap";
|
|
|
|
bootcfg.modnames[1]="capwap80211";
|
|
|
|
bootcfg.nmods=2;
|
|
|
|
}
|
2018-03-12 11:22:06 +01:00
|
|
|
|
2016-03-11 18:16:13 +01:00
|
|
|
|
2018-03-17 16:21:23 +01:00
|
|
|
/* create an empty message set */
|
2018-03-12 11:22:06 +01:00
|
|
|
msgset = cw_msgset_create();
|
|
|
|
if (msgset==NULL){
|
|
|
|
cw_log(LOG_ERR, "Error creating msgset: %s", strerror(errno));
|
|
|
|
exit(EXIT_FAILURE);
|
2016-03-02 19:27:54 +01:00
|
|
|
}
|
2018-03-17 16:21:23 +01:00
|
|
|
|
|
|
|
/* create an empty global config */
|
2018-03-17 12:32:40 +01:00
|
|
|
global_cfg=cw_ktv_create();
|
2018-03-17 16:21:23 +01:00
|
|
|
if (msgset==NULL){
|
|
|
|
cw_log(LOG_ERR, "Error creating global_cfg: %s", strerror(errno));
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2018-03-17 12:32:40 +01:00
|
|
|
|
2018-03-17 16:21:23 +01:00
|
|
|
/* create a types tree with default types */
|
2018-03-17 12:32:40 +01:00
|
|
|
types_tree = cw_ktv_create_types_tree();
|
|
|
|
for (ti=CW_KTV_STD_TYPES;*ti;ti++){
|
|
|
|
mavl_add_ptr(types_tree,*ti);
|
|
|
|
}
|
2018-03-24 07:56:05 +01:00
|
|
|
|
2018-03-17 16:21:23 +01:00
|
|
|
/* read the initial config file */
|
2018-03-17 12:32:40 +01:00
|
|
|
file = fopen(bootcfg.cfgfilename,"r");
|
2018-03-24 07:56:05 +01:00
|
|
|
|
2018-03-17 12:32:40 +01:00
|
|
|
if (file == NULL){
|
2018-03-24 07:56:05 +01:00
|
|
|
cw_log(LOG_ERR,"Can't open file '%s':%s",bootcfg.cfgfilename, strerror(errno));
|
2018-03-17 12:32:40 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2018-03-24 07:56:05 +01:00
|
|
|
|
2018-03-17 12:32:40 +01:00
|
|
|
cw_ktv_read_file(file,global_cfg,types_tree);
|
|
|
|
|
2018-03-17 16:21:23 +01:00
|
|
|
|
2018-03-19 17:26:01 +01:00
|
|
|
cw_dbg_ktv_dump(global_cfg,DBG_CFG_DMP,"----- global cfg start -----","","----- global cfg end -----");
|
2018-04-19 11:03:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
/*clean_cfg(global_cfg);*/
|
|
|
|
|
2018-03-17 12:32:40 +01:00
|
|
|
|
2018-03-12 18:01:40 +01:00
|
|
|
/* create a connection object */
|
|
|
|
conn = conn_create_noq(-1, NULL);
|
|
|
|
if (conn==NULL){
|
|
|
|
cw_log(LOG_ERR, "Connot create conn: %s", strerror(errno));
|
2018-03-12 11:22:06 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2018-04-01 12:44:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* conn->mod=mod;*/
|
2018-03-12 18:01:40 +01:00
|
|
|
conn->detected = 1;
|
|
|
|
conn->dtls_verify_peer=0;
|
|
|
|
conn->dtls_mtu = 12000;
|
|
|
|
conn->msgset=msgset;
|
2018-03-17 12:32:40 +01:00
|
|
|
conn->local_cfg = global_cfg;
|
2018-03-30 19:45:27 +02:00
|
|
|
conn->remote_cfg = NULL;
|
2018-04-01 12:44:05 +02:00
|
|
|
conn->role = CW_ROLE_WTP;
|
2018-03-27 07:07:14 +02:00
|
|
|
conn->wbid=1;
|
2015-04-26 15:48:40 +02:00
|
|
|
|
2018-04-01 12:44:05 +02:00
|
|
|
for (i=0;i<bootcfg.nmods; i++){
|
|
|
|
mod = cw_mod_load(bootcfg.modnames[i], 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);
|
|
|
|
if (mod->setup_cfg)
|
|
|
|
mod->setup_cfg(conn);
|
|
|
|
}
|
2018-04-17 07:46:09 +02:00
|
|
|
/*
|
2018-04-14 00:50:58 +02:00
|
|
|
{
|
|
|
|
int idx;
|
|
|
|
cw_dbg_ktv_dump(conn->local_cfg,DBG_INFO,"head","BREP: ","bot");
|
|
|
|
idx = cw_ktv_idx_get(conn->local_cfg,"tube",0,NULL);
|
|
|
|
printf("IDX: %d\n",idx);
|
2018-03-30 23:58:21 +02:00
|
|
|
|
2018-04-14 00:50:58 +02:00
|
|
|
exit(0);
|
|
|
|
}
|
2018-04-17 07:46:09 +02:00
|
|
|
*/
|
2018-04-02 01:39:08 +02:00
|
|
|
dtls_init();
|
2018-03-31 08:37:18 +02:00
|
|
|
|
2018-04-07 19:28:22 +02:00
|
|
|
conn->base_rmac = get_base_rmac();
|
|
|
|
|
2018-03-31 08:37:18 +02:00
|
|
|
|
2018-04-01 12:44:05 +02:00
|
|
|
cw_discovery_init_results(&dis);
|
2018-04-27 14:04:03 +02:00
|
|
|
/*cw_run_discovery(conn, "255.255.255.255","192.168.56.1", &dis);*/
|
2018-05-07 10:57:12 +02:00
|
|
|
/* cw_run_discovery(conn, "255.255.255.255",NULL, &dis);*/
|
|
|
|
cw_run_discovery(conn, "255.255.255.255","192.168.0.14", &dis);
|
|
|
|
|
2018-04-01 12:44:05 +02:00
|
|
|
cw_dbg_ktv_dump(dis.prio_ip, DBG_INFO, "=== IP list ===", "IP", "=== END IP List ===");
|
2018-04-02 10:11:25 +02:00
|
|
|
|
2018-04-01 12:44:05 +02:00
|
|
|
/*
|
2018-03-30 23:58:21 +02:00
|
|
|
{
|
|
|
|
mavliter_t i;
|
|
|
|
mavliter_init(&i, dis.prio_ip);
|
|
|
|
|
|
|
|
mavliter_foreach(&i) {
|
|
|
|
char ipstr[100];
|
|
|
|
char *rk;
|
|
|
|
cw_KTV_t *val;
|
2018-03-31 08:37:18 +02:00
|
|
|
mavl_t cfg;
|
|
|
|
|
2018-03-30 23:58:21 +02:00
|
|
|
val = mavliter_get(&i);
|
|
|
|
rk = val->key;
|
|
|
|
val = val->val.ptr;
|
|
|
|
val->type->to_str(val, ipstr, 100);
|
|
|
|
printf("PTRVAL(%s): %s - %s\n", rk, val->key, ipstr);
|
2018-03-31 08:37:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
cfg = cw_ktv_get_sysptr(dis.prio_ac,rk,NULL);
|
|
|
|
|
|
|
|
cw_dbg_ktv_dump(cfg,DBG_INFO,"----- dump of remote","dmp","endof of remote -------");
|
|
|
|
|
2018-03-30 23:58:21 +02:00
|
|
|
}
|
|
|
|
}
|
2018-04-01 12:44:05 +02:00
|
|
|
*/
|
2018-04-19 11:03:18 +02:00
|
|
|
mavl_del_all(conn->remote_cfg);
|
2018-04-01 12:44:05 +02:00
|
|
|
join(conn,&dis);
|
2018-04-19 11:03:18 +02:00
|
|
|
clean_cfg(conn->remote_cfg);
|
2018-04-09 09:27:38 +02:00
|
|
|
mavl_merge(conn->local_cfg,conn->remote_cfg);
|
|
|
|
|
2018-04-19 11:03:18 +02:00
|
|
|
mavl_del_all(conn->remote_cfg);
|
2018-04-09 09:27:38 +02:00
|
|
|
configure(conn);
|
2018-04-19 11:03:18 +02:00
|
|
|
clean_cfg(conn->remote_cfg);
|
|
|
|
mavl_merge(conn->local_cfg,conn->remote_cfg);
|
|
|
|
|
2018-04-23 07:51:56 +02:00
|
|
|
|
|
|
|
changestate(conn);
|
|
|
|
|
|
|
|
|
2018-04-18 11:00:44 +02:00
|
|
|
run(conn);
|
2018-04-09 09:27:38 +02:00
|
|
|
|
2018-03-31 08:37:18 +02:00
|
|
|
cw_discovery_free_results(&dis);
|
|
|
|
|
2018-03-12 11:22:06 +01:00
|
|
|
return (EXIT_SUCCESS);
|
2018-03-12 18:01:40 +01:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|