New msg_callbacks implemented and tested

This commit is contained in:
7u83 2022-08-13 11:48:49 +02:00
parent a3f7a4fc1a
commit ff8d520972
5 changed files with 108 additions and 4 deletions

View File

@ -622,9 +622,7 @@ void wtpman_destroy(struct wtpman *wtpman)
static void discovery_cb(struct cw_ElemHandlerParams * params, uint8_t * elems_ptr, int elems_len)
{
struct wtpman * wtpman = (struct wtpman *)params->conn->data;
cw_dbg(DBG_X,"Discovery->Callback");
wtpman->pdiscovery(params,elems_ptr,elems_len);
}
static void join_cb(struct cw_ElemHandlerParams * params, uint8_t * elems_ptr, int elems_len)
@ -648,7 +646,6 @@ static void update_cb(struct cw_ElemHandlerParams * params, uint8_t * elems_ptr,
static setup_complete(struct cw_Conn *conn)
{
struct wtpman * wtpman = (struct wtpman *)conn->data;
wtpman->pdiscovery = cw_msgset_set_postprocess(conn->msgset,CAPWAP_MSG_DISCOVERY_REQUEST,discovery_cb);
wtpman->pjoin = cw_msgset_set_postprocess(conn->msgset,CAPWAP_MSG_JOIN_REQUEST,join_cb);
wtpman->pupdate = cw_msgset_set_postprocess(conn->msgset,CAPWAP_MSG_CONFIGURATION_STATUS_REQUEST,update_cb);
cw_dbg(DBG_X,"SETUP COMPLETE");
@ -715,6 +712,9 @@ struct wtpman *wtpman_create(int socklistindex, struct sockaddr *srcaddr,
sock_copyaddr(&wtpman->conn->data_addr,
(struct sockaddr *) &wtpman->conn->addr);
cw_conn_set_msg_cb(wtpman->conn,
CAPWAP_MSG_DISCOVERY_REQUEST,
discovery_cb);
// wtpman->conn->mods = conf_mods;

View File

@ -163,7 +163,7 @@ int cw_assemble_message(struct cw_Conn *conn, uint8_t * rawout)
struct msg_callback{
int type; /**< message type */
int (*fun)();
cw_MsgCallbackFun fun;
};
int msg_callback_cmp(const void *v1,const void *v2)
@ -194,6 +194,26 @@ void cw_conn_init(struct cw_Conn * conn)
conn->msg_callbacks = mavl_create(msg_callback_cmp,NULL,sizeof(struct msg_callback));
}
int cw_conn_set_msg_cb(struct cw_Conn *conn, int type, cw_MsgCallbackFun fun)
{
struct msg_callback cb;
int exists;
cb.type = type;
cb.fun = fun;
mavl_insert(conn->msg_callbacks,&cb,&exists);
}
cw_MsgCallbackFun cw_conn_get_msg_cb(struct cw_Conn *conn, int type)
{
struct msg_callback cb,*result;
cb.type=type;
result = mavl_get(conn->msg_callbacks,&cb);
if (result == NULL)
return NULL;
return result->fun;
}
/**
* Create a conn object
* @param sock a socket

View File

@ -313,4 +313,9 @@ int conn_send_msg(struct cw_Conn *conn, uint8_t * rawmsg);
void conn_clear_upd(struct cw_Conn*conn, int merge);
int cw_conn_set_msg_cb(struct cw_Conn *conn, int type, cw_MsgCallbackFun fun);
cw_MsgCallbackFun cw_conn_get_msg_cb(struct cw_Conn *conn, int type);
#endif /* __CONN_H */

74
src/cw/conn_init.c Normal file
View File

@ -0,0 +1,74 @@
/*
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/>.
*/
/**
* @file
* @brief conn_init
*/
#include <string.h>
#include "conn.h"
#include "capwap.h"
#include "cw.h"
/*
static int write_header(struct cw_ElemHandler * handler, uint8_t * dst, int len)
{
if (handler->vendor)
return len + cw_put_elem_vendor_hdr(dst, handler->vendor, handler->id, len);
return len + cw_put_elem_hdr(dst, handler->id, len);
}
static int header_len(struct cw_ElemHandler * handler)
{
return handler->vendor ? 10 : 4;
}
*/
/**
* Basic initialization of a conn object
* @param conn conn object to initialize
*/
void conn_init(struct cw_Conn * conn)
{
memset(conn,0,sizeof(struct cw_Conn ));
conn->retransmit_interval=CAPWAP_RETRANSMIT_INTERVAL;
conn->max_retransmit=CAPWAP_MAX_RETRANSMIT;
conn->wait_dtls=CAPWAP_WAIT_DTLS;
conn->wait_join=CAPWAP_WAIT_JOIN;
conn->mtu_discovery=1;
// conn->capwap_mode = 0;
conn->strict_capwap=1;
conn->process_packet=conn_process_packet;
conn->process_message=process_message;
/*
conn->write_header = write_header;
conn->header_len = header_len;
*/
}

View File

@ -405,6 +405,11 @@ static int process_elements(struct cw_Conn *conn, uint8_t * rawmsg, int len,
" *** Remote CFG dump ***", "CFG:", " *** End of remote CFG dump");
*/
cw_MsgCallbackFun cb_fun = cw_conn_get_msg_cb(conn,message->type);
if (cb_fun != NULL){
cb_fun(&params,elems_ptr, elems_len);
}
if (message->postprocess) {
// message->postprocess(conn);