2015-04-05 19:40:01 +02:00
|
|
|
/*
|
|
|
|
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 implementation of cw_put_msg.
|
|
|
|
*/
|
|
|
|
|
2016-03-11 22:23:00 +01:00
|
|
|
#include "cw.h"
|
2015-04-05 19:40:01 +02:00
|
|
|
#include "capwap_items.h"
|
|
|
|
#include "conn.h"
|
|
|
|
|
2015-04-10 17:52:01 +02:00
|
|
|
#include "log.h"
|
2015-04-11 19:00:51 +02:00
|
|
|
#include "dbg.h"
|
2015-04-07 07:42:36 +02:00
|
|
|
|
2015-04-05 19:40:01 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Put a message to a buffer
|
2016-03-05 00:23:33 +01:00
|
|
|
* This functions assumes, that a message header is
|
2015-04-05 19:40:01 +02:00
|
|
|
* alread initilaized in buffer
|
|
|
|
* Message alements are taken fom actiondef in #conn->action
|
|
|
|
*/
|
|
|
|
int cw_put_msg(struct conn *conn, uint8_t * rawout)
|
|
|
|
{
|
|
|
|
|
2015-04-10 21:44:05 +02:00
|
|
|
|
2015-04-05 19:40:01 +02:00
|
|
|
/* rawout is already initialized, so we can get
|
|
|
|
msg type from buffer */
|
|
|
|
uint8_t *msgptr = rawout + cw_get_hdr_msg_offset(rawout);
|
|
|
|
|
|
|
|
|
|
|
|
/* create search paramaters */
|
|
|
|
cw_action_out_t as;
|
|
|
|
|
|
|
|
as.msg_id = cw_get_msg_type(msgptr);
|
|
|
|
as.item_id = CW_ITEM_NONE;
|
|
|
|
as.vendor_id = 0;
|
|
|
|
|
2015-04-10 09:50:59 +02:00
|
|
|
uint8_t *dst = msgptr+8;
|
2015-04-05 19:40:01 +02:00
|
|
|
|
2016-02-28 15:13:10 +01:00
|
|
|
mlist_t *m = cw_actionlist_out_get(conn->actions->out,cw_get_msg_type(msgptr));
|
2016-02-28 13:41:45 +01:00
|
|
|
|
2016-02-28 15:13:10 +01:00
|
|
|
if (!m){
|
|
|
|
cw_log(LOG_ERR,"Error: Can't create message of type %d (%s) - no definition found.",
|
|
|
|
as.msg_id,cw_strmsg(as.msg_id));
|
2016-03-05 00:23:33 +01:00
|
|
|
|
|
|
|
/* invalidate the cache */
|
|
|
|
cw_set_msg_type(msgptr,0);
|
2016-02-28 13:41:45 +01:00
|
|
|
return -1;
|
2016-02-28 15:13:10 +01:00
|
|
|
}
|
|
|
|
|
2016-02-28 13:41:45 +01:00
|
|
|
|
|
|
|
struct mlist_elem *e;
|
|
|
|
|
|
|
|
int len = 0;
|
|
|
|
|
|
|
|
for (e=m->list; e; e=e->next) {
|
|
|
|
cw_action_out_t *ae=(cw_action_out_t*)e->data;
|
|
|
|
|
|
|
|
DBGX("Put %d %i %p\n",ae->msg_id,ae->elem_id,ae->item_id);
|
2016-03-11 23:45:35 +01:00
|
|
|
//printf("Put %d %i %s\n",ae->msg_id,ae->elem_id,ae->item_id);
|
2016-02-28 13:41:45 +01:00
|
|
|
DBGX("Elem ID %s",ae->item_id);
|
|
|
|
if ( ae->item_id ) {
|
|
|
|
DBGX("Item ID: %s %p",ae->item_id,CW_ITEM_NONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ae->msg_id != as.msg_id) {
|
|
|
|
/* Element is from next msg, close action */
|
|
|
|
break;
|
|
|
|
}
|
2016-03-13 18:55:42 +01:00
|
|
|
int l=0;
|
2016-02-28 13:41:45 +01:00
|
|
|
if (ae->out) {
|
2016-03-11 22:23:00 +01:00
|
|
|
|
2016-03-11 23:45:35 +01:00
|
|
|
// printf("Out Call with len =%d\n",len);
|
2016-03-11 22:23:00 +01:00
|
|
|
|
2016-02-28 13:41:45 +01:00
|
|
|
l= ae->out(conn, ae, dst+len);
|
2016-03-13 18:55:42 +01:00
|
|
|
// cw_dbg_elem(DBG_ELEM, conn, ae->msg_id, ae->elem_id, dst+len,l);
|
2016-02-28 13:41:45 +01:00
|
|
|
|
2016-03-11 23:45:35 +01:00
|
|
|
// printf("Returned len = %d\n",l);
|
2016-03-11 22:23:00 +01:00
|
|
|
|
2016-02-28 13:41:45 +01:00
|
|
|
|
|
|
|
len +=l;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cw_set_msg_elems_len(msgptr, len);
|
|
|
|
|
|
|
|
if (as.msg_id & 1) {
|
|
|
|
/* It's a request, so we have to set seqnum */
|
|
|
|
int s = conn_get_next_seqnum(conn);
|
|
|
|
cw_set_msg_seqnum(msgptr,s);
|
|
|
|
}
|
|
|
|
|
|
|
|
return len;
|
|
|
|
|
2015-05-01 20:34:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Put a message to a buffer
|
|
|
|
* This functions assumes, that a message header with is
|
|
|
|
* alread initilaized in buffer
|
|
|
|
* Message alements are taken fom actiondef in #conn->action
|
|
|
|
*/
|
2015-05-02 02:02:06 +02:00
|
|
|
int cw_put_custom_msg(struct conn *conn, uint8_t * rawout, mavl_conststr_t elems)
|
2015-05-01 20:34:50 +02:00
|
|
|
{
|
|
|
|
/* rawout is already initialized, so we can get
|
|
|
|
msg type from buffer */
|
|
|
|
uint8_t *msgptr = rawout + cw_get_hdr_msg_offset(rawout);
|
|
|
|
int msg_id = cw_get_msg_type(msgptr);
|
|
|
|
|
|
|
|
MAVLITER_DEFINE(it,elems);
|
|
|
|
mavliter_foreach(&it){
|
2015-05-02 02:02:06 +02:00
|
|
|
const char *i= mavliter_get(&it);
|
|
|
|
/* preapare action search */
|
|
|
|
cw_action_out_t as;
|
|
|
|
as.msg_id=msg_id;
|
|
|
|
as.item_id=i;
|
|
|
|
as.vendor_id=0;
|
2015-05-01 20:34:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* create search paramaters */
|
|
|
|
cw_action_out_t as;
|
|
|
|
|
|
|
|
as.item_id = CW_ITEM_NONE;
|
|
|
|
as.vendor_id = 0;
|
|
|
|
|
|
|
|
uint8_t *dst = msgptr+8;
|
|
|
|
|
|
|
|
DEFINE_AVLITER(i,conn->actions->out);
|
|
|
|
|
|
|
|
cw_action_out_t *am;
|
|
|
|
|
|
|
|
if (! (am=avliter_seek(&i,&as))){
|
|
|
|
cw_log(LOG_ERR,"Error: Can't create message of type %d (%s) - no definition found.",
|
|
|
|
as.msg_id,cw_strmsg(as.msg_id));
|
|
|
|
return -1;
|
|
|
|
}
|
2015-05-01 13:55:02 +02:00
|
|
|
|
2015-04-10 09:50:59 +02:00
|
|
|
cw_action_out_t *ae;
|
|
|
|
int len = 0;
|
|
|
|
while(NULL != (ae=avliter_next(&i))) {
|
2015-04-07 07:42:36 +02:00
|
|
|
|
2015-05-01 13:55:02 +02:00
|
|
|
DBGX("Put %d %i %p\n",ae->msg_id,ae->elem_id,ae->item_id);
|
|
|
|
DBGX("Elem ID %s",ae->item_id);
|
2016-03-13 18:55:42 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-05-01 13:55:02 +02:00
|
|
|
if ( ae->item_id ) {
|
|
|
|
DBGX("Item ID: %s %p",ae->item_id,CW_ITEM_NONE);
|
|
|
|
}
|
2015-04-10 09:50:59 +02:00
|
|
|
|
|
|
|
if (ae->msg_id != as.msg_id) {
|
|
|
|
/* Element is from next msg, close action */
|
|
|
|
break;
|
|
|
|
}
|
2016-03-13 18:55:42 +01:00
|
|
|
int l=0;
|
2015-04-10 09:50:59 +02:00
|
|
|
if (ae->out) {
|
2015-04-11 19:00:51 +02:00
|
|
|
l= ae->out(conn, ae, dst+len);
|
|
|
|
len +=l;
|
|
|
|
// cw_dbg_elem_colored(DBG_ELEM, conn, ae->msg_id, ae->elem_id,
|
|
|
|
// dst+len-l,l);
|
|
|
|
|
2015-04-10 09:50:59 +02:00
|
|
|
}
|
2016-03-13 18:55:42 +01:00
|
|
|
|
|
|
|
// printf("DEBUGGER\n");
|
|
|
|
// cw_dbg_elem(DBG_ELEM, conn, ae->msg_id, ae->elem_id, 0,l);
|
|
|
|
|
2015-04-11 19:00:51 +02:00
|
|
|
|
|
|
|
//cw_dbg_elem_colored(DBG_ELEM,"Adding element %d to msg %d, len = %d",ae->msg_id,ae->elem_id,l);
|
2015-04-10 09:50:59 +02:00
|
|
|
|
|
|
|
};
|
2015-04-07 07:42:36 +02:00
|
|
|
|
|
|
|
|
2015-04-10 09:50:59 +02:00
|
|
|
cw_set_msg_elems_len(msgptr, len);
|
2015-04-11 19:00:51 +02:00
|
|
|
|
2015-04-13 11:00:46 +02:00
|
|
|
if (as.msg_id & 1) {
|
2015-04-11 19:00:51 +02:00
|
|
|
/* It's a request, so we have to set seqnum */
|
|
|
|
int s = conn_get_next_seqnum(conn);
|
|
|
|
cw_set_msg_seqnum(msgptr,s);
|
|
|
|
// printf("Set seqnum to : %d\n",s);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-10 09:50:59 +02:00
|
|
|
return len;
|
2015-04-05 19:40:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|