From 5c192fbe276e8d5d453302fbb04cde1ea8e8a3d2 Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Mon, 14 Mar 2016 23:33:17 +0000 Subject: [PATCH] Inital commit. FossilOrigin-Name: 1d6337f875fa9ddbb76faaa89294a07bced2d4260d0c501c98869c2f801c64d8 --- src/cw/cw_read_ac_descriptor.c | 40 ++++++++++++++ src/cw/cw_read_descriptor_subelems.c | 80 ++++++++++++++++++++++++++++ 2 files changed, 120 insertions(+) create mode 100644 src/cw/cw_read_ac_descriptor.c create mode 100644 src/cw/cw_read_descriptor_subelems.c diff --git a/src/cw/cw_read_ac_descriptor.c b/src/cw/cw_read_ac_descriptor.c new file mode 100644 index 00000000..f3350e5d --- /dev/null +++ b/src/cw/cw_read_ac_descriptor.c @@ -0,0 +1,40 @@ +#include "cw.h" +#include "capwap_items.h" +#include "dbg.h" +#include "mbag.h" + +int cw_read_ac_descriptor(mbag_t store, uint8_t *data, int len, struct cw_descriptor_subelem_def *allowed) +{ + struct cw_ac_status *status = malloc(sizeof(struct cw_ac_status)); + if (!status) + return 0; + + status->stations = cw_get_word(data); + status->limit = cw_get_word(data + 2); + status->active_wtps = cw_get_word(data + 4); + status->max_wtps = cw_get_word(data + 6); + status->security = cw_get_byte(data + 8); + status->rmac_field = cw_get_byte(data + 9); + status->dtls_policy = cw_get_byte(data + 11); + + cw_dbg(DBG_SUBELEM, + "AC Descriptor: WTPs:%d/%d, Stations:%d/%d, Security:%d, Rmac:%d, DTLS-Policy:%d", + status->active_wtps, status->max_wtps, status->stations, status->limit, + status->security, status->rmac_field, status->dtls_policy); + + mbag_set_ptr(store, CW_ITEM_AC_STATUS, status); + + static struct cw_descriptor_subelem_def allowed_default[] = { + {0,CW_SUBELEM_AC_HARDWARE_VERSION, CW_ITEM_WTP_HARDWARE_VERSION, 1024,1}, + {0,CW_SUBELEM_AC_SOFTWARE_VERSION, CW_ITEM_WTP_SOFTWARE_VERSION, 1024,1}, + {0,0, NULL,0, 0} + }; + + if (!allowed) + allowed=allowed_default; + + return cw_read_descriptor_subelems(store, data + 12, len - 12, allowed); + +} + + diff --git a/src/cw/cw_read_descriptor_subelems.c b/src/cw/cw_read_descriptor_subelems.c new file mode 100644 index 00000000..8fbc61b7 --- /dev/null +++ b/src/cw/cw_read_descriptor_subelems.c @@ -0,0 +1,80 @@ +/* + This file is part of actube. + + actube 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 . + +*/ + +#include "cw.h" +#include "dbg.h" + +int cw_read_descriptor_subelems(mbag_t store, uint8_t * data, int len, + struct cw_descriptor_subelem_def *elems) +{ + int errors = 0; + int success = 0; + int sub = 0; + while (sub < len) { + + if (len - sub < 8) { + return 0; + } + uint32_t vendor_id = cw_get_dword(data + sub); + int sublen = cw_get_word(data + sub + 6); + int subtype = cw_get_word(data + sub + 4); + + bstrv_t vstr = NULL; + int i; + for (i = 0; elems[i].maxlen; i++) { + if (elems[i].type == subtype && elems[i].vendor_id==vendor_id) + break; + } + if (!elems[i].maxlen) { + vstr = bstrv_create(vendor_id, data + sub + 8, sublen); + if (vstr) { + cw_dbg_version_subelem(DBG_ELEM_ERR, "Not allowed", + subtype, vstr); + free(vstr); + } + errors++; + } else { + int l = sublen; + if (elems[i].maxlen < sublen) { + cw_dbg(DBG_ELEM_ERR, + "SubType %d Too long (truncating), len = %d,max. len=%d", + subtype, sublen, elems[i].maxlen); + l = elems[i].maxlen; + } + + vstr = + mbag_set_bstrv(store, elems[i].item_id, vendor_id, + data + sub + 8, l); + + char dbgstr[128]; + sprintf(dbgstr, "Storing '%s'", elems[i].item_id); + cw_dbg_version_subelem(DBG_SUBELEM, dbgstr, subtype, vstr); + success++; + } + + if (sub + sublen > len) + return -1; + + sub += sublen + 8; + + } + + + + return success; +}