2015-03-20 22:31:09 +01:00
|
|
|
#include <stdlib.h>
|
2014-07-11 22:12:11 +02:00
|
|
|
#include <time.h>
|
|
|
|
#include <errno.h>
|
2015-03-20 22:31:09 +01:00
|
|
|
#include <string.h>
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2022-08-18 08:17:31 +02:00
|
|
|
#include "cw/cw.h"
|
2016-03-03 19:51:42 +01:00
|
|
|
#include "cw/capwap.h"
|
|
|
|
#include "cw/conn.h"
|
|
|
|
#include "cw/radioinfo.h"
|
|
|
|
#include "cw/log.h"
|
|
|
|
#include "cw/dtls.h"
|
|
|
|
#include "cw/sock.h"
|
|
|
|
#include "cw/cw_util.h"
|
2018-04-18 11:00:44 +02:00
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
#include "wtp_conf.h"
|
|
|
|
|
2015-04-19 16:44:20 +02:00
|
|
|
|
2016-03-03 19:51:42 +01:00
|
|
|
#include "cw/timer.h"
|
2022-08-19 22:23:55 +02:00
|
|
|
#include "wtp.h"
|
2015-04-19 16:44:20 +02:00
|
|
|
|
|
|
|
|
2016-03-03 19:51:42 +01:00
|
|
|
#include "cw/capwap.h"
|
|
|
|
#include "cw/conn.h"
|
2015-04-19 16:44:20 +02:00
|
|
|
#include "wtp_interface.h"
|
|
|
|
|
2016-04-12 07:47:55 +02:00
|
|
|
#include "cw/dbg.h"
|
|
|
|
|
2022-07-28 01:36:16 +02:00
|
|
|
int update =1;
|
2016-04-12 07:47:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-08-19 22:23:55 +02:00
|
|
|
static int update_cb(struct cw_ElemHandlerParams * params, uint8_t * elems_ptr, int elems_len)
|
|
|
|
{
|
2022-08-21 00:53:41 +02:00
|
|
|
// cw_dbg(DBG_X," **** Configuration Update Request Received ***");
|
2022-08-19 22:23:55 +02:00
|
|
|
// cw_cfg_dump(params->conn->global_cfg);
|
2022-08-21 00:53:41 +02:00
|
|
|
cw_cfg_copy(params->cfg, params->conn->global_cfg,DBG_CFG_UPDATES,"GlobalCfg");
|
2022-08-19 22:23:55 +02:00
|
|
|
cw_cfg_save(bootcfg.cfgfilename, params->conn->global_cfg,
|
|
|
|
"#\n# This file is igenerated by WAT\n# If you edit this, your cahnges might be overwritten\n#\n");
|
2022-08-21 00:53:41 +02:00
|
|
|
// cw_dbg(DBG_X," **** Configuration Update Request Received Saved ***");
|
2016-04-12 07:47:55 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-08-19 22:23:55 +02:00
|
|
|
|
2016-04-12 07:47:55 +02:00
|
|
|
|
|
|
|
|
2018-04-18 11:00:44 +02:00
|
|
|
/*
|
2022-08-10 02:10:10 +02:00
|
|
|
static void update_radio(struct cw_Conn * conn, int rid, mbag_t radio_upd, mbag_t radio,mbag_t iresult )
|
2016-04-12 07:47:55 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
printf("Updating radio with rid %d\n",rid);
|
|
|
|
}
|
2018-04-18 11:00:44 +02:00
|
|
|
*/
|
|
|
|
|
2016-04-12 07:47:55 +02:00
|
|
|
|
2018-04-18 11:00:44 +02:00
|
|
|
/*
|
2022-08-10 02:10:10 +02:00
|
|
|
static void update_radios(struct cw_Conn * conn, mbag_t result)
|
2016-04-12 07:47:55 +02:00
|
|
|
{
|
|
|
|
MAVLITER_DEFINE (it,conn->radios_upd);
|
|
|
|
mavliter_foreach(&it){
|
|
|
|
struct mbag_item * item = mavliter_get(&it);
|
|
|
|
int rid = item->iid;
|
|
|
|
mbag_t radio = mbag_i_get_mbag(conn->radios,rid,NULL);
|
|
|
|
if (!radio){
|
|
|
|
cw_dbg(DBG_ELEM_ERR,"Can't find radio with id %d",rid);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
mbag_t iresult = mbag_create();
|
|
|
|
mbag_i_set_mbag(result,rid,iresult);
|
|
|
|
update_radio(conn,rid,item->data,radio,iresult);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2018-04-18 11:00:44 +02:00
|
|
|
*/
|
2016-04-12 07:47:55 +02:00
|
|
|
|
2015-04-19 16:44:20 +02:00
|
|
|
|
2022-08-10 02:10:10 +02:00
|
|
|
int run(struct cw_Conn * conn)
|
2015-04-19 16:44:20 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
|
2022-08-19 22:23:55 +02:00
|
|
|
cw_conn_set_msg_cb(conn,CAPWAP_MSG_CONFIGURATION_UPDATE_REQUEST,update_cb);
|
2018-04-18 11:00:44 +02:00
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
conn->capwap_state = CAPWAP_STATE_RUN;
|
2015-04-19 16:44:20 +02:00
|
|
|
|
|
|
|
do {
|
2015-04-21 08:24:59 +02:00
|
|
|
|
2022-08-18 08:17:31 +02:00
|
|
|
int echo_interval = cw_cfg_get_byte(conn->global_cfg,"capwap-timers/echo-interval",CAPWAP_ECHO_INTERVAL);
|
2018-04-18 11:00:44 +02:00
|
|
|
|
|
|
|
/*mbag_get_word(conn->config,CW_ITEM_CAPWAP_TIMERS,CW_TIMERS)&0xff;*/
|
|
|
|
|
2018-05-14 23:30:48 +02:00
|
|
|
time_t timer = cw_timer_start(echo_interval-1);
|
2015-04-19 16:44:20 +02:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
while (!cw_timer_timeout(timer) && conn->capwap_state == CAPWAP_STATE_RUN) {
|
2022-08-20 22:03:06 +02:00
|
|
|
cw_cfg_clear(conn->remote_cfg);
|
2015-04-19 16:44:20 +02:00
|
|
|
rc = cw_read_messages(conn);
|
|
|
|
if (rc < 0 && errno == EAGAIN) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-08-19 22:23:55 +02:00
|
|
|
//printf("--------------------------------------------------------------------------------------\n");
|
2018-04-19 11:03:18 +02:00
|
|
|
|
2022-07-30 19:44:57 +02:00
|
|
|
if ( !cw_result_is_ok(rc)) {
|
2022-08-19 22:23:55 +02:00
|
|
|
//printf("---------------------- cwrsult is not ok\n");
|
2015-04-19 16:44:20 +02:00
|
|
|
break;
|
2022-07-30 19:44:57 +02:00
|
|
|
}
|
|
|
|
|
2022-08-19 22:23:55 +02:00
|
|
|
//printf("lalalala\n");
|
2022-08-18 08:17:31 +02:00
|
|
|
//cw_dbg_ktv_dump(conn->remote_cfg,DBG_INFO,"KTV DUMP ----------------","Remote:", "DUMP done -------");
|
2022-07-28 01:36:16 +02:00
|
|
|
|
2022-08-18 08:17:31 +02:00
|
|
|
// printf("Saving Config\n");
|
|
|
|
// mavl_merge(conn->local_cfg,conn->remote_cfg);
|
|
|
|
// cw_ktv_save(conn->local_cfg,"cisco.ktv");
|
|
|
|
// clean_cfg(conn->remote_cfg);
|
2018-04-19 11:03:18 +02:00
|
|
|
|
2022-08-19 22:23:55 +02:00
|
|
|
// cw_dbg(DBG_X,"We hav a message processed");
|
2015-04-19 16:44:20 +02:00
|
|
|
}
|
2022-07-30 19:44:57 +02:00
|
|
|
|
2015-04-19 16:44:20 +02:00
|
|
|
if (rc<0 && errno == EAGAIN){
|
2018-03-05 09:56:39 +01:00
|
|
|
rc = cw_send_request(conn,CAPWAP_MSG_ECHO_REQUEST);
|
2015-04-19 16:44:20 +02:00
|
|
|
|
2018-03-09 15:38:21 +01:00
|
|
|
if (!cw_result_is_ok(rc)) {
|
2015-04-19 16:44:20 +02:00
|
|
|
cw_log(LOG_ERR,"Error in run state: %d %s",rc,cw_strrc(rc));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-03-09 15:38:21 +01:00
|
|
|
if (!cw_result_is_ok(rc)) {
|
2015-04-19 16:44:20 +02:00
|
|
|
cw_log(LOG_ERR,"Error in run state: %d %s",rc,cw_strrc(rc));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-05-07 10:57:12 +02:00
|
|
|
} while (conn->capwap_state == CAPWAP_STATE_RUN);
|
2015-04-19 16:44:20 +02:00
|
|
|
|
|
|
|
|
2018-04-18 11:00:44 +02:00
|
|
|
/*
|
2015-04-19 16:44:20 +02:00
|
|
|
// int rc = cw_send_request(conn,CW_MSG_CHANGE_STATE_EVENT_REQUEST);
|
|
|
|
|
|
|
|
// if ( !cw_rcok(rc) ) {
|
|
|
|
// cw_strresult(rc);
|
|
|
|
// }
|
2018-04-18 11:00:44 +02:00
|
|
|
*/
|
2015-04-26 12:36:53 +02:00
|
|
|
return 0;
|
2015-04-19 16:44:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|