From 7cfeef1e5898a5cc050ec3e665f4506d6afb9f06 Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Sun, 27 Mar 2016 14:42:41 +0000 Subject: [PATCH] Cisco vendor specific stuff. FossilOrigin-Name: b2a3f210a647a844b0e8ffc8a53e046f3975127f192e9493ca3ffcd544acc83e --- src/cw/lw_in_vendor_specific.c | 48 ++++++++++++++ src/mod/cisco/cisco_in_spam_vendor_specific.c | 13 ++++ src/mod/cisco/cisco_out_telnet_ssh.c | 64 +++++++++++++++++++ 3 files changed, 125 insertions(+) create mode 100644 src/cw/lw_in_vendor_specific.c create mode 100644 src/mod/cisco/cisco_in_spam_vendor_specific.c create mode 100644 src/mod/cisco/cisco_out_telnet_ssh.c diff --git a/src/cw/lw_in_vendor_specific.c b/src/cw/lw_in_vendor_specific.c new file mode 100644 index 00000000..ba772a43 --- /dev/null +++ b/src/cw/lw_in_vendor_specific.c @@ -0,0 +1,48 @@ + +#include "cw.h" +#include "dbg.h" +#include "log.h" +#include "stravltree.h" + +/** + * @file + * @brief Implementation of LWAPP Vendor Specific Payload + */ + +/** + * Default handler for LWAPP Vendor Specific Payload message elements. + */ +int lw_in_vendor_specific(struct conn *conn, struct cw_action_in *a, + uint8_t * data, int len, struct sockaddr *from) +{ + + cw_action_in_t as, *af; + as = *a; + + as.vendor_id = cw_get_dword(data); + as.elem_id = cw_get_word(data + 4); + as.proto = CW_ACTION_PROTO_LWAPP; + + + af = cw_actionlist_in_get(conn->actions->in, &as); + + if (!af) { + cw_dbg(DBG_WARN, + "Can't handle Vendor Specific LWAPP Payload %s/%d, in msg %d (%s) in %s state.", + cw_strvendor(as.vendor_id), as.elem_id, as.msg_id, + cw_strmsg(as.msg_id), cw_strstate(as.capwap_state)); + return 0; + } + + if (af->start) { + int afrc = af->start(conn, af, data + 6, len - 6, from); + if (af->mand && afrc) { + /* add found mandatory message element + to mand list */ + stravltree_add(conn->mand, af->item_id); + } + return afrc; + } + + return 1; +} diff --git a/src/mod/cisco/cisco_in_spam_vendor_specific.c b/src/mod/cisco/cisco_in_spam_vendor_specific.c new file mode 100644 index 00000000..5102cecd --- /dev/null +++ b/src/mod/cisco/cisco_in_spam_vendor_specific.c @@ -0,0 +1,13 @@ + +#include "cw/action.h" +#include "cw/lw.h" +#include "cw/dbg.h" + +int cisco_in_spam_vendor_specific(struct conn *conn, struct cw_action_in *a, uint8_t * data, int len, + struct sockaddr *from) +{ + + return lw_in_vendor_specific(conn,a,data+6,len-6,from); + cw_dbg(DBG_X,"Cwin vendor spam"); + return 0; +} diff --git a/src/mod/cisco/cisco_out_telnet_ssh.c b/src/mod/cisco/cisco_out_telnet_ssh.c new file mode 100644 index 00000000..aeb6144f --- /dev/null +++ b/src/mod/cisco/cisco_out_telnet_ssh.c @@ -0,0 +1,64 @@ + +#include "cisco.h" +#include "cw/capwap_items.h" +#include "cw/lwapp.h" +#include "cw/cw.h" +#include "cw/dbg.h" +#include "cw/vendors.h" +#include "cw/lwapp_cisco.h" +#include "cw/capwap_cisco.h" + + + + + +int lw_cisco_put_telnet_ssh(struct conn *conn, uint8_t type,const char * item_id, uint8_t *dst) +{ + + uint8_t *d = dst+6; + + mbag_item_t * item; + + item = mbag_get(conn->outgoing, item_id); + + cw_dbg(DBG_X,"Getting an Item %p\n",item); + + if (item){ + if (item->type == MBAG_BYTE) { + d+=lw_put_byte(d,item->byte); + d+=lw_put_byte(d,type); + } + } + + int l = d-6-dst; + + cw_dbg(DBG_X," the calculated length is %d",l); + + if (l==0) + return 0; + + + return l + lw_put_vendor(dst, LW_VENDOR_ID_CISCO, LW_CISCO_TELNET_SSH, l); + +} + +int cw_cisco_put_telnet_ssh(struct conn *conn,uint8_t type,const char * item_id, uint8_t *dst) +{ + int l = lw_cisco_put_telnet_ssh(conn,type,item_id,dst+10); + if (l==0) + return 0; + cw_dbg(DBG_X,"CISL = %d",l); + return l + cw_put_elem_vendor_hdr(dst, CW_VENDOR_ID_CISCO, CW_CISCO_SPAM_VENDOR_SPECIFIC, l); + +} + + +int cisco_out_telnet_ssh(struct conn *conn,struct cw_action_out * a,uint8_t *dst) +{ + int l; + l=cw_cisco_put_telnet_ssh(conn,0,CW_ITEM_TELNET_ENABLE,dst); + l+=cw_cisco_put_telnet_ssh(conn,1,CW_ITEM_SSH_ENABLE,dst+l); + return l; + +} +