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
|
|
|
|
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"
|
|
|
|
#include "cw/capwap_items.h"
|
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"
|
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"
|
|
|
|
#include "cfg.h"
|
|
|
|
|
|
|
|
int update =0;
|
|
|
|
|
|
|
|
int handle_update_req(struct conn *conn, struct cw_action_in *a, uint8_t * data,
|
|
|
|
int len, struct sockaddr *from)
|
|
|
|
{
|
2018-03-05 07:24:48 +01:00
|
|
|
if (a->msg_id == CAPWAP_MSG_CONFIGURATION_UPDATE_REQUEST){
|
2016-04-12 07:47:55 +02:00
|
|
|
update =1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
MAVLITER_DEFINE(it, conn->incomming);
|
|
|
|
|
|
|
|
mavliter_foreach(&it) {
|
|
|
|
mbag_item_t *item = mavliter_get(&it);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2016-04-18 07:40:30 +02:00
|
|
|
cw_dbg(DBG_X,"Saving configuration ...");
|
2016-04-12 07:47:55 +02:00
|
|
|
cfg_to_json();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void update_radio(struct conn * conn, int rid, mbag_t radio_upd, mbag_t radio,mbag_t iresult )
|
|
|
|
{
|
|
|
|
|
|
|
|
printf("Updating radio with rid %d\n",rid);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_radios(struct conn * conn, mbag_t result)
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void do_update(struct conn * conn)
|
|
|
|
{
|
|
|
|
if (!update)
|
|
|
|
return;
|
|
|
|
update=0;
|
|
|
|
|
|
|
|
mbag_t result = mbag_create();
|
|
|
|
update_radios(conn,result);
|
|
|
|
cw_dbg(DBG_INFO, "Saving configuration ...");
|
|
|
|
cfg_to_json();
|
2016-04-18 07:40:30 +02:00
|
|
|
/* Change State ... */
|
2018-03-05 10:06:18 +01:00
|
|
|
int rc = cw_send_request(conn,CAPWAP_MSG_CHANGE_STATE_EVENT_REQUEST);
|
2018-03-09 15:38:21 +01:00
|
|
|
if ( !cw_result_is_ok(rc) ) {
|
2016-04-18 07:40:30 +02:00
|
|
|
cw_strresult(rc);
|
|
|
|
return ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-12 07:47:55 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-19 16:44:20 +02:00
|
|
|
|
|
|
|
int run()
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
struct conn *conn = get_conn();
|
|
|
|
conn->capwap_state = CW_STATE_RUN;
|
|
|
|
|
2016-04-12 07:47:55 +02:00
|
|
|
conn->msg_end=handle_update_req;
|
|
|
|
|
2015-04-19 16:44:20 +02:00
|
|
|
do {
|
2015-04-21 08:24:59 +02:00
|
|
|
|
2018-02-23 01:42:37 +01:00
|
|
|
int echo_interval = mbag_get_word(conn->config,CW_ITEM_CAPWAP_TIMERS,CW_TIMERS)&0xff;
|
2015-04-21 08:24:59 +02:00
|
|
|
time_t timer = cw_timer_start(echo_interval);
|
2015-04-19 16:44:20 +02:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (!cw_timer_timeout(timer) && conn->capwap_state == CW_STATE_RUN) {
|
|
|
|
rc = cw_read_messages(conn);
|
|
|
|
if (rc < 0 && errno == EAGAIN) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-03-09 15:38:21 +01:00
|
|
|
if ( !cw_result_is_ok(rc))
|
2015-04-19 16:44:20 +02:00
|
|
|
break;
|
|
|
|
|
2016-04-12 07:47:55 +02:00
|
|
|
|
|
|
|
cw_dbg(DBG_X,"We hav a message processed");
|
|
|
|
|
|
|
|
do_update(conn);
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} while (conn->capwap_state == CW_STATE_RUN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// int rc = cw_send_request(conn,CW_MSG_CHANGE_STATE_EVENT_REQUEST);
|
|
|
|
|
|
|
|
// if ( !cw_rcok(rc) ) {
|
|
|
|
// cw_strresult(rc);
|
|
|
|
// }
|
|
|
|
|
2015-04-26 12:36:53 +02:00
|
|
|
return 0;
|
2015-04-19 16:44:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
/*
|
2014-07-11 22:12:11 +02:00
|
|
|
static int echo_interval_timer;
|
|
|
|
|
|
|
|
struct cwrmsg * get_response(struct conn * conn, int type,int seqnum)
|
|
|
|
{
|
|
|
|
struct cwrmsg * cwrmsg;
|
|
|
|
int i;
|
|
|
|
for(i=0; i<conf_retransmit_interval; i++){
|
|
|
|
cwrmsg = conn_get_message(conn);
|
|
|
|
if ( cwrmsg==0){
|
|
|
|
//printf("null message \n");
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cwrmsg->type==type && cwrmsg->seqnum==seqnum)
|
|
|
|
return cwrmsg;
|
|
|
|
printf("another message was detected %i %i\n",cwrmsg->type,cwrmsg->seqnum);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
2015-04-07 07:42:36 +02:00
|
|
|
*/
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
/*
|
2014-07-11 22:12:11 +02:00
|
|
|
struct cwrmsg * send_request(struct conn * conn,struct cwmsg *cwmsg)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i=0; i<conf_max_retransmit; i++){
|
|
|
|
|
|
|
|
#ifdef WITH_CW_LOG_DEBUG
|
|
|
|
if (i>0){
|
2015-02-08 21:07:55 +01:00
|
|
|
// cw_log_debug1("Retransmitting request, type=%i,seqnum=%i",cwmsg->type,cwmsg->seqnum);
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int rc = conn_send_cwmsg(conn,cwmsg);
|
|
|
|
if (rc<0){
|
2015-02-08 21:07:55 +01:00
|
|
|
// cw_log_debug1("Error sending request, type=%i, seqnum %i, %s",cwmsg->type,cwmsg->seqnum,strerror(errno));
|
2014-07-11 22:12:11 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
struct cwrmsg * r = get_response(conn,cwmsg->type+1,cwmsg->seqnum);
|
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
*/
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
//extern struct conn * get_conn();
|
2014-07-11 22:12:11 +02:00
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
/*
|
2014-07-11 22:12:11 +02:00
|
|
|
int run(struct conn * conn)
|
|
|
|
{
|
2015-03-20 22:31:09 +01:00
|
|
|
|
|
|
|
conn = get_conn();
|
|
|
|
printf("Running with conn %p\n");
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
struct radioinfo radioinfo;
|
|
|
|
memset(&radioinfo,0,sizeof(radioinfo));
|
|
|
|
|
2015-03-29 01:55:06 +01:00
|
|
|
|
|
|
|
struct cwrmsg * cwrmsg;
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
echo_interval_timer=time(NULL);
|
|
|
|
while (1){
|
|
|
|
if (time(NULL)-echo_interval_timer >= conf_echo_interval)
|
|
|
|
{
|
2015-03-20 22:31:09 +01:00
|
|
|
// struct cwmsg cwmsg;
|
|
|
|
// uint8_t buffer[CWMSG_MAX_SIZE];
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
// cwsend_echo_request(conn,&radioinfo);
|
|
|
|
|
2015-02-08 21:07:55 +01:00
|
|
|
// cw_log_debug1("Sending echo request");
|
2015-03-20 22:31:09 +01:00
|
|
|
struct cwmsg *cwmsg=&conn->req_msg;
|
|
|
|
uint8_t * buffer = conn->req_buffer;
|
2015-03-29 01:55:06 +01:00
|
|
|
|
|
|
|
|
|
|
|
struct wtpinfo * wtpinfo = get_wtpinfo();
|
|
|
|
struct radioinfo *rip = &(wtpinfo->radioinfo[0]);
|
|
|
|
|
|
|
|
cwmsg_init_echo_request(cwmsg,buffer,conn,rip);
|
|
|
|
|
|
|
|
printf("Echo ->>>>>>>>>>>>>>>>>>>>> Seqnum %d\n",conn->req_msg.seqnum);
|
2015-03-20 22:31:09 +01:00
|
|
|
|
|
|
|
|
|
|
|
printf("Conn target is %s",sock_addr2str(&conn->addr));
|
|
|
|
printf("Calling conn send req\n");
|
|
|
|
printf("conn max retrans: %d\n",conn->max_retransmit);
|
|
|
|
struct cwrmsg * rc = conn_send_request(conn);
|
|
|
|
printf("Back from conn send req\n");
|
2014-07-11 22:12:11 +02:00
|
|
|
|
|
|
|
// printf("conn->seqnum %i\n",conn->seqnum);
|
|
|
|
// struct cwrmsg * rc = get_response(conn,CWMSG_ECHO_RESPONSE,conn->seqnum);
|
|
|
|
if (rc==0){
|
|
|
|
|
2015-03-20 22:31:09 +01:00
|
|
|
printf("Error !\n");
|
|
|
|
|
2015-03-23 07:48:27 +01:00
|
|
|
// dtls_shutdown(conn);
|
2015-02-08 21:07:55 +01:00
|
|
|
// cw_log_debug1("Connection lost, no echo response");
|
2015-03-23 07:48:27 +01:00
|
|
|
// return 0;
|
2014-07-11 22:12:11 +02:00
|
|
|
}
|
|
|
|
echo_interval_timer=time(NULL);
|
|
|
|
}
|
2015-03-29 01:55:06 +01:00
|
|
|
|
|
|
|
time_t rt = cw_timer_start(5);
|
|
|
|
cwrmsg = conn_wait_for_request(conn,0,rt);
|
|
|
|
struct wtpinfo * wtpinfo = get_wtpinfo();
|
|
|
|
struct radioinfo *rip = &(wtpinfo->radioinfo[0]);
|
|
|
|
|
|
|
|
if(cwrmsg){
|
|
|
|
cw_readmsg_configuration_update_request(cwrmsg->msgelems,cwrmsg->msgelems_len);
|
|
|
|
cw_send_configuration_update_response(conn,cwrmsg->seqnum,rip);
|
|
|
|
}
|
|
|
|
|
2014-07-11 22:12:11 +02:00
|
|
|
sleep(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-07 07:42:36 +02:00
|
|
|
*/
|