diff --git a/src/Makefile b/src/Makefile index 3f6ac34c673db84ee5a86402a8d21f35037699c4..4aeb2cc1424813b50f81f56f3c27cb8beca446a7 100644 --- a/src/Makefile +++ b/src/Makefile @@ -28,8 +28,8 @@ CNTLR_OBJS = \ LIBS = -lubus -lubox -ljson-c -lblobmsg_json -luci -pthread LIBS += -rdynamic -ldl -LIBS += -leasy -lmaputils -LIBS += -lwsc +LIBS += -leasy +LIBS += -li1905 -lmaputil plugin_subdirs ?= $(wildcard plugins/*) plugin_sofile = $(wildcard $(d)/*.so) diff --git a/src/core/cntlr.c b/src/core/cntlr.c index 69e27e909dd15ccf3d1647c2da95ba6473592ccc..ed683c94d90183f82bc62eac45717515cd74fac1 100644 --- a/src/core/cntlr.c +++ b/src/core/cntlr.c @@ -29,8 +29,12 @@ #include <easy/easy.h> #include <wifi.h> // FIXME: should not be included -#include <map1905/map2.h> -#include <map1905/maputils.h> +#include <timer_impl.h> +#include <cmdu.h> +#include <1905_tlvs.h> +#include <map22.h> +#include <map_module22.h> + #include "debug.h" #include "utils.h" @@ -72,7 +76,7 @@ static void cntlr_terminate(struct controller *c) { dbg("%s: called.\n", __func__); stop_cntlr(c); - exit_alloctrace(); + //exit_alloctrace(); stop_logging(); //unlink(pidfile); exit(0); @@ -1773,16 +1777,15 @@ static void cntlr_ubusx_event_handler(struct ubus_context *ctx, } } - static void cntlr_ieee1905_cmdu_event_handler(void *cntlr, struct blob_attr *msg) { static const struct blobmsg_policy cmdu_attrs[5] = { - [0] = { .name = "type", .type = BLOBMSG_TYPE_INT32 }, - [1] = { .name = "mid", .type = BLOBMSG_TYPE_INT32 }, - [2] = { .name = "ingress", .type = BLOBMSG_TYPE_STRING }, + [0] = { .name = "type", .type = BLOBMSG_TYPE_INT16 }, + [1] = { .name = "mid", .type = BLOBMSG_TYPE_INT16 }, + [2] = { .name = "ifname", .type = BLOBMSG_TYPE_STRING }, [3] = { .name = "source", .type = BLOBMSG_TYPE_STRING }, - [4] = { .name = "tlvs", .type = BLOBMSG_TYPE_STRING }, + [4] = { .name = "cmdu", .type = BLOBMSG_TYPE_STRING }, }; struct controller *c = (struct controller *)cntlr; char in_ifname[16] = {0}; @@ -1795,21 +1798,19 @@ static void cntlr_ieee1905_cmdu_event_handler(void *cntlr, uint16_t mid = 0; int len = 0; - dbg("%s: --->\n", __func__); - blobmsg_parse(cmdu_attrs, 5, tb, blob_data(msg), blob_len(msg)); if (!tb[0] || !tb[1]) return; if (tb[0]) { - type = (uint16_t)blobmsg_get_u32(tb[0]); + type = (uint16_t)blobmsg_get_u16(tb[0]); if (type < 0 || !is_cmdu_for_us(c, type)) return; } if (tb[1]) - mid = (uint16_t)blobmsg_get_u32(tb[1]); + mid = (uint16_t)blobmsg_get_u16(tb[1]); if (tb[2]) @@ -1821,14 +1822,16 @@ static void cntlr_ieee1905_cmdu_event_handler(void *cntlr, } if (tb[4]) { - len = blobmsg_data_len(tb[4]); - tlvstr = calloc(len + 1, sizeof(char)); + len = blobmsg_data_len(tb[4]) - 16; + + tlvstr = calloc(1, len + 1); + if (!tlvstr) return; - strncpy(tlvstr, blobmsg_data(tb[4]), len); + strncpy(tlvstr, (blobmsg_data(tb[4]) + 16), len); len = (len - 1) / 2; - tlv = calloc(len, sizeof(uint8_t)); + tlv = calloc(1, len); if (!tlv) { free(tlvstr); return; @@ -1844,36 +1847,6 @@ static void cntlr_ieee1905_cmdu_event_handler(void *cntlr, free(tlv); } -static void cntlr_ieee1905_event_handler(struct ubus_context *ctx, - struct ubus_event_handler *ev, - const char *type, - struct blob_attr *msg) -{ - struct controller *c = container_of(ev, struct controller, - ieee1905_evh); - struct ev_handler { - const char *ev_type; - void (*handler)(void *ctx, struct blob_attr *ev_data); - } evs[] = { {"ieee1905.cmdu", cntlr_ieee1905_cmdu_event_handler} }; - char *str; - int i; - - str = blobmsg_format_json(msg, true); - if (!str) - return; - - dbg("[ &cntlr = %p ] Received [event = %s][val = %s]\n", c, type, str); - - for (i = 0; i < ARRAY_SIZE(evs); i++) { - if (!strcmp(type, evs[i].ev_type)) { - evs[i].handler(c, msg); - break; - } - } - - free(str); -} - static int cntlr_register_events(struct controller *c) { #if 0 @@ -1886,14 +1859,10 @@ static int cntlr_register_events(struct controller *c) cntlr_dbg("Setting up bus event handlers...\n"); c->ubusx_ev.cb = cntlr_ubusx_event_handler; - c->ieee1905_evh.cb = cntlr_ieee1905_event_handler; - ubus_register_event_handler(c->ubus_ctx, &c->ubusx_ev, "ubus.object.add"); ubus_register_event_handler(c->ubus_ctx, &c->ubusx_ev, "ubus.object.remove"); - ubus_register_event_handler(c->ubus_ctx, &c->ieee1905_evh, - "ieee1905.*"); return 0; } @@ -2019,14 +1988,14 @@ static void cntlr_signal_periodic_run(struct uloop_timeout *t) diff = cntlr_config_reload(&c->cfg); if (diff & CONFIG_DIFF_CREDENTIALS || diff & CONFIG_DIFF_VLAN) { - struct cmdu_cstruct *cmdu; + struct cmdu_buff *cmdu; uint8_t origin[6] = {0x01, 0x80, 0xc2, 0x00, 0x00, 0x13}; trace("Config changed, triggering renew!\n"); cmdu = cntlr_gen_ap_autoconfig_renew(c, origin, c->cfg.al_bridge, c->almac); if (cmdu) { send_cmdu(c, cmdu); - map_free_cmdu(cmdu); + cmdu_free(cmdu); } } else if (diff & (CONFIG_DIFF_AGENT_POLICY | CONFIG_DIFF_AGENT_POLICY_CNT)) { struct agent_policy *p; @@ -2094,29 +2063,27 @@ static void cntlr_start(struct uloop_timeout *t) if (c->state == CNTLR_INIT) { c->state = CNTLR_START; cntlr_publish_object(c, "map.controller"); - - cntlr_register_module(c); } } static void cntlr_discovery(struct uloop_timeout *t) /* make into periodic uloop */ { struct controller *c = container_of(t, struct controller, discovery_timer); - struct cmdu_cstruct *cmdu; + struct cmdu_buff *cmdu; cmdu = cntlr_gen_ap_autoconfig_search(c, NULL, 0x02, 0x00); if (!cmdu) return; c->mid_2g = send_cmdu(c, cmdu); - map_free_cmdu(cmdu); + cmdu_free(cmdu); cmdu = cntlr_gen_ap_autoconfig_search(c, NULL, 0x02, 0x01); if (!cmdu) return; c->mid_5g = send_cmdu(c, cmdu); - map_free_cmdu(cmdu); + cmdu_free(cmdu); uloop_timeout_set(t, 180 * 1000); } @@ -2140,6 +2107,137 @@ static void parse_almac(struct ubus_request *req, int type, dbg("almac = " MACFMT "\n", MAC2STR(c->almac)); } } +#define map_plugin "i1905.map" + + +static void mapclient_sub_remove_cb(struct ubus_context *ctx, + struct ubus_subscriber *sub, + uint32_t obj) +{ + trace("Object 0x%x no longer present\n", obj); +} + +static int mapclient_sub_cb(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *type, + struct blob_attr *msg) +{ + struct ubus_subscriber *s = container_of(obj, struct ubus_subscriber, obj); + struct controller *priv = container_of(s, struct controller, sub); + char *str; + + str = blobmsg_format_json(msg, true); + trace("Received notification '%s': %s\n", type, str); + + cntlr_ieee1905_cmdu_event_handler(priv, msg); + + free(str); + + return 0; +} + +static int mapclient_subscribe(struct controller *a, uint32_t oid) +{ + int ret; + + /* register mapclient as a subscriber with ubus */ + a->sub.cb = mapclient_sub_cb; + a->sub.remove_cb = mapclient_sub_remove_cb; + + ret = ubus_register_subscriber(a->ubus_ctx, &a->sub); + if (ret) + trace("Failed to register sub: %s\n", ubus_strerror(ret)); + + + /* now subscribe to events from map plugin over passed oid */ + ret = ubus_subscribe(a->ubus_ctx, &a->sub, oid); + if (ret) + trace("Failed to subscribe: %s\n", ubus_strerror(ret)); + + return 0; +} + +typedef uint32_t mapmodule_object_t; + +struct map_module_unish { + mapmodule_object_t id; + uint32_t cmdu_mask; + char process_cmdu_funcname[64]; +}; + + +static void register_cb(struct ubus_request *req, int type, struct blob_attr *msg) +{ + struct controller *priv = (struct controller *)req->priv; + const struct blobmsg_policy pol[1] = { + [0] = { .name = "oid", .type = BLOBMSG_TYPE_INT32 }, + }; + struct blob_attr *tb[1]; + + + blobmsg_parse(pol, 1, tb, blob_data(msg), blob_len(msg)); + + if (tb[0]) { + uint32_t oid = blobmsg_get_u32(tb[0]); + + trace("Response ID: %u\n", oid); + mapclient_subscribe(priv, oid); + } +} + +#ifndef BITx +#define BITx(n) (1U << (n)) +#endif + +static void mapclient_subscribe_for_cmdus(struct controller *c) +{ + char data[2 * sizeof(struct map_module) + 1] = {0}; + int ret; + uint32_t map_id; + struct blob_buf bb = {}; + struct map_module m = { + .id = 0x22222222, + .process_cmdu_funcname = "mapclient_process_cmdu", + }; + + + map_prepare_cmdu_mask(m.cmdu_mask, + CMDU_TYPE_TOPOLOGY_DISCOVERY, + CMDU_TYPE_TOPOLOGY_NOTIFICATION, + CMDU_TYPE_TOPOLOGY_QUERY, + CMDU_TYPE_TOPOLOGY_RESPONSE, + CMDU_TYPE_VENDOR_SPECIFIC, + CMDU_TYPE_AP_AUTOCONFIGURATION_SEARCH, + CMDU_TYPE_AP_AUTOCONFIGURATION_RESPONSE, + CMDU_TYPE_AP_AUTOCONFIGURATION_WSC); + + + trace("<----------------------------------- %s\n", __func__); + + ret = ubus_lookup_id(c->ubus_ctx, map_plugin, &map_id); + if (ret) { + trace("plugin '%s' lookup failed. %s\n", + map_plugin, ubus_strerror(ret)); + return; + } + + c->map_oid = map_id; + + /* register as client to the map module */ + blob_buf_init(&bb, 0); + blobmsg_add_string(&bb, "module", "mapcontroller"); + btostr((unsigned char *)&m, sizeof(struct map_module), data); + blobmsg_add_string(&bb, "data", data); + ret = ubus_invoke(c->ubus_ctx, c->map_oid, "register", bb.head, register_cb, + c, 1000); + if (ret) { + trace("Failed to 'register' with %s (err = %s)\n", + map_plugin, ubus_strerror(ret)); + } + + blob_buf_free(&bb); + + return; +} int start_controller(void) { @@ -2178,10 +2276,6 @@ int start_controller(void) } c->ubus_ctx = ctx; #endif - /* ev = &c->ubus_ev; */ - /* ev->cb = cntlr_event_handler_local; */ - //c->ubusx_ev.cb = cntlr_ubusx_event_handler; - //c->ieee1905_evh.cb = cntlr_ieee1905_event_handler; c->topology = OBJECT_INVALID; INIT_LIST_HEAD(&c->nodelist); INIT_LIST_HEAD(&c->watchlist); @@ -2241,10 +2335,11 @@ int start_controller(void) uloop_timeout_set(&c->signal_handler, 5 * 1000); #if 0 cntlr_publish_object(c, "map.controller"); - - cntlr_register_module(c); #endif + mapclient_subscribe_for_cmdus(c); + + uloop_run(); out_exit: /* ubus_unregister_event_handler(ctx, ev); */ diff --git a/src/core/cntlr.h b/src/core/cntlr.h index f00ad9ed7b317f00d40e97a4fbf2ea1312ff4d81..0928aa4e7be903e2e6d8e89f111e0ca63ee49d2c 100644 --- a/src/core/cntlr.h +++ b/src/core/cntlr.h @@ -149,6 +149,9 @@ struct controller { /* Autoconfig */ uint16_t mid_5g; uint16_t mid_2g; + + uint32_t map_oid; + struct ubus_subscriber sub; }; #define COMM_HANDLE(c) (((struct controller *)(c))->ubus_ctx) diff --git a/src/core/cntlr_cmdu_generator.c b/src/core/cntlr_cmdu_generator.c index da0562564fc56af2d836da87411231bdb27e8618..d790b7386c396e48660bbe96945e4896cc197e19 100644 --- a/src/core/cntlr_cmdu_generator.c +++ b/src/core/cntlr_cmdu_generator.c @@ -26,16 +26,20 @@ #include <libubox/utils.h> #include <libubus.h> -#include <map1905/map2.h> -#include <map1905/maputils.h> -#include <wsc.h> +#include <i1905_wsc.h> #include <uci.h> #include <easy/easy.h> #include <wifi.h> -#include "map_module.h" +#include <timer_impl.h> +#include <cmdu.h> +#include <1905_tlvs.h> +#include <map22.h> +#include <map_module22.h> + +//#include "map_module.h" #include "utils.h" #include "debug.h" #include "liblist.h" @@ -46,492 +50,620 @@ #include "cntlr.h" #include "cntlr_tlv_generator.h" #include "cntlr_cmdu_generator.h" +#include "cntlr_map.h" -static void cmdu_defaults(struct controller *c, struct cmdu_cstruct *cmdu, +static void cmdu_defaults(struct controller *c, struct cmdu_buff *cmdu, uint8_t *origin, char *intf_name, uint16_t type) { - memcpy(cmdu->origin, origin, 6); - if (intf_name) - strncpy(cmdu->intf_name, intf_name, - sizeof(cmdu->intf_name) - 1); - else - strncpy(cmdu->intf_name, c->cfg.al_bridge, sizeof(cmdu->intf_name) - 1); - - cmdu->message_type = type; +// memcpy(cmdu->origin, origin, 6); +// if (intf_name) +// strncpy(cmdu->intf_name, intf_name, +// sizeof(cmdu->intf_name) - 1); +// else +// strncpy(cmdu->intf_name, c->cfg.al_bridge, sizeof(cmdu->intf_name) - 1); +// +// cmdu->message_type = type; } -struct cmdu_cstruct *cntlr_gen_ap_autoconfig_renew(struct controller *c, +struct cmdu_buff *cntlr_gen_ap_autoconfig_renew(struct controller *c, uint8_t *origin, char *intf_name, uint8_t *almac) { - struct cmdu_cstruct *cmdu; - struct tlv_al_mac *p; - struct tlv_supported_freq_band *p1; - struct tlv_supported_role *p2; - int tlv_index = 0; - - cmdu = (struct cmdu_cstruct *)calloc(1, sizeof(struct cmdu_cstruct)); - if (!cmdu) { - fprintf(stderr, "failed to malloc cmdu\n"); - return NULL; - } - - cmdu_defaults(c, cmdu, origin, intf_name, - CMDU_TYPE_AP_AUTOCONFIGURATION_RENEW); - - p = cntlr_gen_al_mac(c, almac); - if (!p) - goto fail_cmdu; - cmdu->num_tlvs++; - - /* Hard-code dummy 5GHz, ignored by agent according to spec */ - p1 = cntlr_gen_supported_freq_band(c, 0x01); - if (!p1) - goto fail_p; - cmdu->num_tlvs++; - - /* Hard-code dummy registrar role, only valid value */ - p2 = cntlr_gen_supported_role(c, 0x00); - if (!p2) - goto fail_p1; - cmdu->num_tlvs++; - - cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, sizeof(uint8_t *)); - if (!cmdu->tlvs) - goto fail_p2; - cmdu->tlvs[tlv_index++] = (uint8_t *)p; - cmdu->tlvs[tlv_index++] = (uint8_t *)p1; - cmdu->tlvs[tlv_index++] = (uint8_t *)p2; - - return cmdu; -fail_p2: - map_free_tlv_cstruct((uint8_t *) p2); -fail_p1: - map_free_tlv_cstruct((uint8_t *) p1); -fail_p: - map_free_tlv_cstruct((uint8_t *) p); -fail_cmdu: - map_free_cmdu(cmdu); return NULL; +// struct cmdu_cstruct *cmdu; +// struct tlv_al_mac *p; +// struct tlv_supported_freq_band *p1; +// struct tlv_supported_role *p2; +// int tlv_index = 0; +// +// cmdu = (struct cmdu_cstruct *)calloc(1, sizeof(struct cmdu_cstruct)); +// if (!cmdu) { +// trace("failed to malloc cmdu\n"); +// return NULL; +// } +// +// cmdu_defaults(c, cmdu, origin, intf_name, +// CMDU_TYPE_AP_AUTOCONFIGURATION_RENEW); +// +// p = cntlr_gen_al_mac(c, almac); +// if (!p) +// goto fail_cmdu; +// cmdu->num_tlvs++; +// +// /* Hard-code dummy 5GHz, ignored by agent according to spec */ +// p1 = cntlr_gen_supported_freq_band(c, 0x01); +// if (!p1) +// goto fail_p; +// cmdu->num_tlvs++; +// +// /* Hard-code dummy registrar role, only valid value */ +// p2 = cntlr_gen_supported_role(c, 0x00); +// if (!p2) +// goto fail_p1; +// cmdu->num_tlvs++; +// +// cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, sizeof(uint8_t *)); +// if (!cmdu->tlvs) +// goto fail_p2; +// cmdu->tlvs[tlv_index++] = (uint8_t *)p; +// cmdu->tlvs[tlv_index++] = (uint8_t *)p1; +// cmdu->tlvs[tlv_index++] = (uint8_t *)p2; +// +// return cmdu; +//fail_p2: +// map_free_tlv_cstruct((uint8_t *) p2); +//fail_p1: +// map_free_tlv_cstruct((uint8_t *) p1); +//fail_p: +// map_free_tlv_cstruct((uint8_t *) p); +//fail_cmdu: +// map_free_cmdu(cmdu); +// return NULL; } -struct cmdu_cstruct *cntlr_gen_ap_capability_query(struct controller *c, +struct cmdu_buff *cntlr_gen_ap_capability_query(struct controller *c, uint8_t *origin, char *intf_name) { - struct cmdu_cstruct *cmdu; - - cmdu = (struct cmdu_cstruct *)calloc(1, sizeof(struct cmdu_cstruct)); - if (!cmdu) { - fprintf(stderr, "failed to malloc cmdu\n"); - return NULL; - } - - cmdu_defaults(c, cmdu, origin, intf_name, CMDU_AP_CAPABILITY_QUERY); - - return cmdu; + return NULL; +// struct cmdu_cstruct *cmdu; +// +// cmdu = (struct cmdu_cstruct *)calloc(1, sizeof(struct cmdu_cstruct)); +// if (!cmdu) { +// trace("failed to malloc cmdu\n"); +// return NULL; +// } +// +// cmdu_defaults(c, cmdu, origin, intf_name, CMDU_AP_CAPABILITY_QUERY); +// +// return cmdu; } -struct cmdu_cstruct *cntlr_gen_client_capability_query(struct controller *c, +struct cmdu_buff *cntlr_gen_client_capability_query(struct controller *c, uint8_t *origin, char *intf_name, uint8_t *sta, uint8_t *bssid) { - struct tlv_client_info *p; - struct cmdu_cstruct *cmdu; - - cmdu = (struct cmdu_cstruct *)calloc(1, - sizeof(struct cmdu_cstruct)); - if (!cmdu) { - fprintf(stderr, "failed to malloc cmdu\n"); - return NULL; - } - - cmdu_defaults(c, cmdu, origin, intf_name, CMDU_CLIENT_CAPABILITY_QUERY); - - p = cntlr_gen_client_info(c, sta, bssid); - if (!p) - goto fail_cmdu; - - cmdu->num_tlvs = 1; - cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, - sizeof(uint8_t *)); - - if (!cmdu->tlvs) - goto fail_p; - - cmdu->tlvs[0] = (uint8_t *)p; - - return cmdu; -fail_p: - map_free_tlv_cstruct((uint8_t *) p); -fail_cmdu: - map_free_cmdu(cmdu); return NULL; +// struct tlv_client_info *p; +// struct cmdu_cstruct *cmdu; +// +// cmdu = (struct cmdu_cstruct *)calloc(1, +// sizeof(struct cmdu_cstruct)); +// if (!cmdu) { +// trace("failed to malloc cmdu\n"); +// return NULL; +// } +// +// cmdu_defaults(c, cmdu, origin, intf_name, CMDU_CLIENT_CAPABILITY_QUERY); +// +// p = cntlr_gen_client_info(c, sta, bssid); +// if (!p) +// goto fail_cmdu; +// +// cmdu->num_tlvs = 1; +// cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, +// sizeof(uint8_t *)); +// +// if (!cmdu->tlvs) +// goto fail_p; +// +// cmdu->tlvs[0] = (uint8_t *)p; +// +// return cmdu; +//fail_p: +// map_free_tlv_cstruct((uint8_t *) p); +//fail_cmdu: +// map_free_cmdu(cmdu); +// return NULL; } -struct cmdu_cstruct *cntlr_gen_backhaul_steer_request(struct controller *c, +struct cmdu_buff *cntlr_gen_backhaul_steer_request(struct controller *c, uint8_t *origin, char *intf_name, uint8_t *bssid, uint8_t *bkhaul, uint8_t op_class, uint8_t channel) { - struct tlv_backhaul_steer_req *p; - struct cmdu_cstruct *cmdu; - - cmdu = (struct cmdu_cstruct *)calloc(1, - sizeof(struct cmdu_cstruct)); - if (!cmdu) { - fprintf(stderr, "failed to malloc cmdu\n"); - return NULL; - } - - cmdu_defaults(c, cmdu, origin, intf_name, CMDU_BACKHAUL_STEER_REQUEST); - - p = cntlr_gen_backhaul_steer_req(c, bkhaul, bssid, op_class, channel); - if (!p) - goto fail_cmdu; - - cmdu->num_tlvs = 1; - cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, - sizeof(uint8_t *)); - - if (!cmdu->tlvs) - goto fail_p; - - cmdu->tlvs[0] = (uint8_t *)p; - - return cmdu; -fail_p: - map_free_tlv_cstruct((uint8_t *) p); -fail_cmdu: - map_free_cmdu(cmdu); return NULL; +// struct tlv_backhaul_steer_req *p; +// struct cmdu_cstruct *cmdu; +// +// cmdu = (struct cmdu_cstruct *)calloc(1, +// sizeof(struct cmdu_cstruct)); +// if (!cmdu) { +// trace("failed to malloc cmdu\n"); +// return NULL; +// } +// +// cmdu_defaults(c, cmdu, origin, intf_name, CMDU_BACKHAUL_STEER_REQUEST); +// +// p = cntlr_gen_backhaul_steer_req(c, bkhaul, bssid, op_class, channel); +// if (!p) +// goto fail_cmdu; +// +// cmdu->num_tlvs = 1; +// cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, +// sizeof(uint8_t *)); +// +// if (!cmdu->tlvs) +// goto fail_p; +// +// cmdu->tlvs[0] = (uint8_t *)p; +// +// return cmdu; +//fail_p: +// map_free_tlv_cstruct((uint8_t *) p); +//fail_cmdu: +// map_free_cmdu(cmdu); +// return NULL; } -struct cmdu_cstruct *cntlr_gen_ap_metrics_query(struct controller *c, +struct cmdu_buff *cntlr_gen_ap_metrics_query(struct controller *c, uint8_t *origin, char *intf_name, int num_bss, uint8_t *bsslist, int num_radio, uint8_t *radiolist) { - int i, tlv_index = 0; - struct cmdu_cstruct *cmdu; - struct tlv_ap_metric_query *p1; -// #ifdef PROFILE2 - struct tlv_ap_radio_identifier *p2; -// #endif - - cmdu = (struct cmdu_cstruct *)calloc(1, sizeof(struct cmdu_cstruct)); - if (!cmdu) { - fprintf(stderr, "failed to malloc cmdu\n"); - return NULL; - } - - cmdu_defaults(c, cmdu, origin, intf_name, CMDU_AP_METRICS_QUERY); - - /* AP Metric Query TLV */ - cmdu->num_tlvs += 1; -// #ifdef PROFILE2 - /* AP Radio Identifier TLV */ - cmdu->num_tlvs += num_radio; -// #endif - - cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, - sizeof(uint8_t *)); - if (!cmdu->tlvs) { - cmdu->num_tlvs = 0; - goto fail_cmdu; - } - - /* AP Metric Query TLV */ - p1 = cntlr_gen_ap_metric_query(c, num_bss, bsslist); - if (!p1) - goto fail_cmdu; - - cmdu->tlvs[tlv_index++] = (uint8_t *)p1; - -// #ifdef PROFILE2 - /* AP Radio Identifier TLV */ - for (i = 0; i < num_radio; i++) { - uint8_t radio_mac[6] = {0}; - - memcpy(radio_mac, &radiolist[i * 6], 6); - p2 = cntlr_gen_ap_radio_identifier(c, cmdu, radio_mac); - if (!p2) - goto fail_cmdu; - - cmdu->tlvs[tlv_index++] = (uint8_t *)p2; - } -// #endif - - return cmdu; - -fail_cmdu: - map_free_cmdu(cmdu); - return NULL; - +// int i, tlv_index = 0; +// struct cmdu_cstruct *cmdu; +// struct tlv_ap_metric_query *p1; +//// #ifdef PROFILE2 +// struct tlv_ap_radio_identifier *p2; +//// #endif +// +// cmdu = (struct cmdu_cstruct *)calloc(1, sizeof(struct cmdu_cstruct)); +// if (!cmdu) { +// trace("failed to malloc cmdu\n"); +// return NULL; +// } +// +// cmdu_defaults(c, cmdu, origin, intf_name, CMDU_AP_METRICS_QUERY); +// +// /* AP Metric Query TLV */ +// cmdu->num_tlvs += 1; +//// #ifdef PROFILE2 +// /* AP Radio Identifier TLV */ +// cmdu->num_tlvs += num_radio; +//// #endif +// +// cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, +// sizeof(uint8_t *)); +// if (!cmdu->tlvs) { +// cmdu->num_tlvs = 0; +// goto fail_cmdu; +// } +// +// /* AP Metric Query TLV */ +// p1 = cntlr_gen_ap_metric_query(c, num_bss, bsslist); +// if (!p1) +// goto fail_cmdu; +// +// cmdu->tlvs[tlv_index++] = (uint8_t *)p1; +// +//// #ifdef PROFILE2 +// /* AP Radio Identifier TLV */ +// for (i = 0; i < num_radio; i++) { +// uint8_t radio_mac[6] = {0}; +// +// memcpy(radio_mac, &radiolist[i * 6], 6); +// p2 = cntlr_gen_ap_radio_identifier(c, cmdu, radio_mac); +// if (!p2) +// goto fail_cmdu; +// +// cmdu->tlvs[tlv_index++] = (uint8_t *)p2; +// } +//// #endif +// +// return cmdu; +// +//fail_cmdu: +// map_free_cmdu(cmdu); +// +// return NULL; } -struct cmdu_cstruct *cntlr_gen_policy_config_req(struct controller *c, +struct cmdu_buff *cntlr_gen_policy_config_req(struct controller *c, char *intf_name, struct agent_policy *found, int num_radio, uint8_t *radiolist, int num_bss, uint8_t *bsslist) { - struct cmdu_cstruct *cmdu; - int tlv_index = 0; - int i; - /* TLVs */ - struct tlv_steering_policy *p1; - struct tlv_metric_report_policy *p2; - /* Map-2 tlvs */ -// #ifdef PROFILE2 - struct tlv_default_8021q_settings *p3; - struct tlv_traffic_sep_policy *p4; - struct tlv_ch_scan_rep_policy *p5; - struct tlv_unsuccess_assoc_policy *p6; - struct tlv_backhaul_bss_config *p7; -// #endif - - cmdu = (struct cmdu_cstruct *)calloc(1, sizeof(struct cmdu_cstruct)); - if (!cmdu) { - fprintf(stderr, "failed to malloc cmdu\n"); - return NULL; - } - - cmdu_defaults(c, cmdu, found->agent_id, intf_name, CMDU_POLICY_CONFIG_REQ); - - cmdu->num_tlvs = 2; -// #ifdef PROFILE2 - cmdu->num_tlvs += 4 + num_bss; -// #endif - - cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, sizeof(uint8_t *)); - if (!cmdu->tlvs) { - cmdu->num_tlvs = 0; - goto fail_cmdu; - } - - /* Steering Policy TLV */ - p1 = cntlr_gen_steering_policy(c, found, cmdu, num_radio, radiolist); - if (!p1) - goto fail_cmdu; - - cmdu->tlvs[tlv_index++] = (uint8_t *)p1; - - /* Metric Reporting Policy TLV */ - p2 = cntlr_gen_metric_report_policy(c, found, cmdu, num_radio, radiolist); - if (!p2) - goto fail_cmdu; - - cmdu->tlvs[tlv_index++] = (uint8_t *)p2; - -// #ifdef PROFILE2 - /* Default 802.1Q setting TLV */ - p3 = cntlr_gen_8021q_settings(c, found); - if (!p3) - goto fail_cmdu; - - cmdu->tlvs[tlv_index++] = (uint8_t *)p3; - - /* Traffic Seperation Policy TLV */ - p4 = cntlr_gen_traffic_sep_policy(c, cmdu); - if (!p4) - goto fail_cmdu; + return NULL; +// struct cmdu_cstruct *cmdu; +// int tlv_index = 0; +// int i; +// /* TLVs */ +// struct tlv_steering_policy *p1; +// struct tlv_metric_report_policy *p2; +// /* Map-2 tlvs */ +//// #ifdef PROFILE2 +// struct tlv_default_8021q_settings *p3; +// struct tlv_traffic_sep_policy *p4; +// struct tlv_ch_scan_rep_policy *p5; +// struct tlv_unsuccess_assoc_policy *p6; +// struct tlv_backhaul_bss_config *p7; +//// #endif +// +// cmdu = (struct cmdu_cstruct *)calloc(1, sizeof(struct cmdu_cstruct)); +// if (!cmdu) { +// trace("failed to malloc cmdu\n"); +// return NULL; +// } +// +// cmdu_defaults(c, cmdu, found->agent_id, intf_name, CMDU_POLICY_CONFIG_REQ); +// +// cmdu->num_tlvs = 2; +//// #ifdef PROFILE2 +// cmdu->num_tlvs += 4 + num_bss; +//// #endif +// +// cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, sizeof(uint8_t *)); +// if (!cmdu->tlvs) { +// cmdu->num_tlvs = 0; +// goto fail_cmdu; +// } +// +// /* Steering Policy TLV */ +// p1 = cntlr_gen_steering_policy(c, found, cmdu, num_radio, radiolist); +// if (!p1) +// goto fail_cmdu; +// +// cmdu->tlvs[tlv_index++] = (uint8_t *)p1; +// +// /* Metric Reporting Policy TLV */ +// p2 = cntlr_gen_metric_report_policy(c, found, cmdu, num_radio, radiolist); +// if (!p2) +// goto fail_cmdu; +// +// cmdu->tlvs[tlv_index++] = (uint8_t *)p2; +// +//// #ifdef PROFILE2 +// /* Default 802.1Q setting TLV */ +// p3 = cntlr_gen_8021q_settings(c, found); +// if (!p3) +// goto fail_cmdu; +// +// cmdu->tlvs[tlv_index++] = (uint8_t *)p3; +// +// /* Traffic Seperation Policy TLV */ +// p4 = cntlr_gen_traffic_sep_policy(c, cmdu); +// if (!p4) +// goto fail_cmdu; +// +// cmdu->tlvs[tlv_index++] = (uint8_t *)p4; +// +// /* Channel Scan Reporting Policy TLV */ +// p5 = cntlr_gen_ch_scan_rep_policy(c, found, cmdu); +// if (!p5) +// goto fail_cmdu; +// +// cmdu->tlvs[tlv_index++] = (uint8_t *)p5; +// +// /* Unsuccessful Association Policy TLV */ +// p6 = cntlr_gen_unsuccess_assoc_policy(c, found, cmdu); +// if (!p6) +// goto fail_cmdu; +// +// cmdu->tlvs[tlv_index++] = (uint8_t *)p6; +// +// /* Backhaul BSS Configuration TLV */ +// for (i = 0; i < num_bss; i++) { +// uint8_t bssid[6] = {0}; +// +// memcpy(bssid, &bsslist[i*6], 6); +// p7 = cntlr_gen_backhaul_bss_config(c, found, cmdu, bssid); +// if (!p7) +// goto fail_cmdu; +// +// cmdu->tlvs[tlv_index++] = (uint8_t *)p7; +// } +//// #endif +// +// return cmdu; +//fail_cmdu: +// map_free_cmdu(cmdu); +// return NULL; +} - cmdu->tlvs[tlv_index++] = (uint8_t *)p4; +struct cmdu_buff *cntlr_gen_sta_metric_query(struct controller *c, + uint8_t *origin, char *intf_name, uint8_t *sta) +{ + return NULL; +// struct cmdu_cstruct *cmdu; +// struct tlv_sta_mac *p1; +// +// cmdu = calloc(1, sizeof(struct cmdu_cstruct)); +// if (!cmdu) { +// trace("failed to malloc cmdu\n"); +// return NULL; +// } +// +// cmdu_defaults(c, cmdu, origin, intf_name, +// CMDU_ASSOC_STA_LINK_METRICS_QUERY); +// +// cmdu->num_tlvs = 1; +// cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, sizeof(uint8_t *)); +// if (!cmdu->tlvs) { +// cmdu->num_tlvs = 0; +// goto fail_cmdu; +// } +// +// p1 = cntlr_gen_sta_mac(c, sta); +// if (!p1) +// goto fail_cmdu; +// +// cmdu->tlvs[0] = (uint8_t *)p1; +// +// return cmdu; +// +//fail_cmdu: +// map_free_cmdu(cmdu); +// return NULL; +} - /* Channel Scan Reporting Policy TLV */ - p5 = cntlr_gen_ch_scan_rep_policy(c, found, cmdu); - if (!p5) - goto fail_cmdu; +struct cmdu_buff *cntlr_gen_bk_caps_query(struct controller *c, + uint8_t *origin, char *intf_name) +{ + return NULL; +// struct cmdu_cstruct *cmdu; +// +// cmdu = calloc(1, sizeof(struct cmdu_cstruct)); +// if (!cmdu) { +// trace("failed to malloc cmdu\n"); +// return NULL; +// } +// +// cmdu_defaults(c, cmdu, origin, intf_name, +// CMDU_BACKHAUL_STA_CAPABILITY_QUERY); +// +// cmdu->num_tlvs = 0; +// +// return cmdu; +// +//fail_cmdu: +// map_free_cmdu(cmdu); +// return NULL; +} - cmdu->tlvs[tlv_index++] = (uint8_t *)p5; +struct cmdu_buff *cntlr_gen_ap_autoconfig_search(struct controller *c, + char *intf_name, uint8_t profile, uint8_t band) +{ + return NULL; +// struct cmdu_cstruct *cmdu; +// struct tlv_supp_service *p = NULL; +// struct tlv_searched_service *p1; +// struct tlv_map_profile *p2; +// struct tlv_al_mac *p3; +// struct tlv_autoconf_freq_band *p4; +// struct tlv_searched_role *p5; +// int i, tlv_index = 0; +// +// cmdu = (struct cmdu_cstruct *)calloc(1, sizeof(struct cmdu_cstruct)); +// if (!cmdu) { +// trace("failed to malloc cmdu\n"); +// return NULL; +// } +// +// memcpy(cmdu->origin, "\x01\x80\xc2\x00\x00\x13", 6); +// if (intf_name) +// strncpy(cmdu->intf_name, intf_name, +// sizeof(cmdu->intf_name) - 1); +// else +// strncpy(cmdu->intf_name, c->cfg.al_bridge, sizeof(cmdu->intf_name) - 1); +// +// cmdu->message_type = CMDU_TYPE_AP_AUTOCONFIGURATION_SEARCH; +// +// p = calloc(1, sizeof(struct tlv_supp_service)); +// if (!p) +// goto fail_cmdu; +// +// cmdu->num_tlvs++; +// p->tlv_type = MAP_TLV_SUPPORTED_SERVICE; +// p->supported_services_list = 1; +// p->supported_services = calloc(p->supported_services_list, +// sizeof(*p->supported_services)); +// if (!p->supported_services) +// goto fail_p; +// +// for (i = 0; i < p->supported_services_list; i++) +// p->supported_services[i].service = +// SUPPORTED_SERVICE_MULTIAP_AGENT; +// +// p1 = calloc(1, sizeof(struct tlv_searched_service)); +// if (!p1) +// goto fail_p; +// +// cmdu->num_tlvs++; +// p1->tlv_type = MAP_TLV_SEARCHED_SERVICE; +// p1->searched_services_list = 1; +// p1->service = calloc(p1->searched_services_list, sizeof(*p1->service)); +// if (!p1->service) +// goto fail_p1; +// +// for (i = 0; i < p->supported_services_list; i++) +// p->supported_services[i].service = +// SEARCHED_SERVICE_MULTIAP_CONTROLLER; +// +// p2 = calloc(1, sizeof(struct tlv_map_profile)); +// if (!p2) +// goto fail_p1; +// +// cmdu->num_tlvs++; +// p2->tlv_type = MAP_TLV_MULTIAP_PROFILE; +// p2->profile = profile; +// +// p3 = cntlr_gen_al_mac(c, c->almac); +// if (!p3) +// goto fail_p2; +// cmdu->num_tlvs++; +// +// p4 = cntlr_gen_autoconf_freq_band(c, band); /* dummy value */ +// if (!p4) +// goto fail_p3; +// cmdu->num_tlvs++; +// +// p5 = cntlr_gen_searched_role(c, 0x00); /* registrar */ +// if (!p5) +// goto fail_p4; +// cmdu->num_tlvs++; +// +// cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, +// sizeof(uint8_t *)); +// if (!cmdu->tlvs) +// goto fail_p5; +// +// cmdu->tlvs[tlv_index++] = (uint8_t *)p; +// cmdu->tlvs[tlv_index++] = (uint8_t *)p1; +// cmdu->tlvs[tlv_index++] = (uint8_t *)p2; +// cmdu->tlvs[tlv_index++] = (uint8_t *)p3; +// cmdu->tlvs[tlv_index++] = (uint8_t *)p4; +// cmdu->tlvs[tlv_index++] = (uint8_t *)p5; +// +// return cmdu; +//fail_p5: +// map_free_tlv_cstruct((uint8_t *) p5); +//fail_p4: +// map_free_tlv_cstruct((uint8_t *) p4); +//fail_p3: +// map_free_tlv_cstruct((uint8_t *) p3); +//fail_p2: +// map_free_tlv_cstruct((uint8_t *) p2); +//fail_p1: +// map_free_tlv_cstruct((uint8_t *) p1); +//fail_p: +// map_free_tlv_cstruct((uint8_t *) p); +//fail_cmdu: +// free(cmdu); +// return NULL; +} - /* Unsuccessful Association Policy TLV */ - p6 = cntlr_gen_unsuccess_assoc_policy(c, found, cmdu); - if (!p6) - goto fail_cmdu; +struct cmdu_buff *cntlr_gen_ap_autoconfig_response(struct controller *c, + uint8_t *dest, uint8_t band, uint16_t mid) +{ + struct cmdu_buff *resp; + struct tlv *t; + int ret; + + resp = cmdu_alloc_simple(CMDU_TYPE_AP_AUTOCONFIGURATION_RESPONSE, &mid); + if (!resp) { + trace("%s: -ENOMEM\n", __func__); + return -1; + } - cmdu->tlvs[tlv_index++] = (uint8_t *)p6; + ret = cntlr_gen_supp_role(c, resp, IEEE80211_ROLE_REGISTRAR); + if (ret) + goto out; - /* Backhaul BSS Configuration TLV */ - for (i = 0; i < num_bss; i++) { - uint8_t bssid[6] = {0}; + ret = cntlr_gen_supported_freq_band(c, resp, band); + if (ret) + goto out; - memcpy(bssid, &bsslist[i*6], 6); - p7 = cntlr_gen_backhaul_bss_config(c, found, cmdu, bssid); - if (!p7) - goto fail_cmdu; + ret = cntlr_gen_supp_service(c, resp, SUPPORTED_SERVICE_MULTIAP_CONTROLLER); + if (ret) + goto out; - cmdu->tlvs[tlv_index++] = (uint8_t *)p7; - } -// #endif + ret = cntlr_gen_map_profile(c, resp, MULTIAP_PROFILE_2); + if (ret) + goto out; - return cmdu; -fail_cmdu: - map_free_cmdu(cmdu); + cmdu_put_eom(resp); + memcpy(resp->origin, dest, 6); + return resp; +out: + cmdu_free(resp); return NULL; } -struct cmdu_cstruct *cntlr_gen_sta_metric_query(struct controller *c, - uint8_t *origin, char *intf_name, uint8_t *sta) +struct cmdu_buff *cntlr_gen_ap_autoconfig_wsc(struct controller *c, + struct agent_policy *a, struct cmdu_buff *rec_cmdu, + struct tlv *basic_cap, struct tlv *wsc, + uint16_t mid) { - struct cmdu_cstruct *cmdu; - struct tlv_sta_mac *p1; - - cmdu = calloc(1, sizeof(struct cmdu_cstruct)); - if (!cmdu) { - fprintf(stderr, "failed to malloc cmdu\n"); - return NULL; + struct iface_credential *cred; + struct cmdu_buff *resp; + struct tlv *t; + uint16_t msglen; + uint8_t *msg; + uint8_t e_macaddr[6] = {0}; + uint8_t e_band = 0; + uint16_t attrlen = 0; + int ret, i = 0; + + resp = cmdu_alloc_frame(3000); + if (!resp) { + trace("%s: -ENOMEM\n", __func__); + return -1; } - cmdu_defaults(c, cmdu, origin, intf_name, - CMDU_ASSOC_STA_LINK_METRICS_QUERY); + cmdu_set_type(resp, CMDU_TYPE_AP_AUTOCONFIGURATION_WSC); + cmdu_set_mid(resp, mid); + + msglen = tlv_length(wsc); + msg = wsc->data; - cmdu->num_tlvs = 1; - cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, sizeof(uint8_t *)); - if (!cmdu->tlvs) { - cmdu->num_tlvs = 0; - goto fail_cmdu; + ret = wsc_msg_get_attr(msg, msglen, ATTR_RF_BANDS, &e_band, &attrlen); + if (ret) { + trace("Error getting band from wsc msg\n"); + return ret; } - p1 = cntlr_gen_sta_mac(c, sta); - if (!p1) - goto fail_cmdu; + ret = wsc_msg_get_attr(msg, msglen, ATTR_MAC_ADDR, e_macaddr, &attrlen); + if (ret) { + trace("Error getting band from wsc msg\n"); + return ret; + } - cmdu->tlvs[0] = (uint8_t *)p1; + ret = cntlr_gen_8021q_settings(c, resp, a); + if (ret) + goto out; - return cmdu; + ret = cntlr_gen_traffic_sep_policy(c, resp); + if (ret) + goto out; -fail_cmdu: - map_free_cmdu(cmdu); - return NULL; -} + ret = cntlr_gen_ap_radio_identifier(c, resp, e_macaddr); /* TODO: send e_macaddr? */ + if (ret) + goto out; -struct cmdu_cstruct *cntlr_gen_bk_caps_query(struct controller *c, - uint8_t *origin, char *intf_name) -{ - struct cmdu_cstruct *cmdu; + /* Generate all fBSS wsc tlvs for this BSS */ + list_for_each_entry(cred, &c->cfg.fhlist, list) { + if (cred->band != e_band) + continue; - cmdu = calloc(1, sizeof(struct cmdu_cstruct)); - if (!cmdu) { - fprintf(stderr, "failed to malloc cmdu\n"); - return NULL; + /* Will return non-zero if band did not match OR on failure */ + ret = cntlr_gen_wsc(c, resp, cred, msg, msglen, e_band); + if (ret) + continue; } - cmdu_defaults(c, cmdu, origin, intf_name, - CMDU_BACKHAUL_STA_CAPABILITY_QUERY); + /* Generate all bBSS wsc tlvs for this BSS */ + list_for_each_entry(cred, &c->cfg.bklist, list) { + if (cred->band != e_band) + continue; - cmdu->num_tlvs = 0; - - return cmdu; - -fail_cmdu: - map_free_cmdu(cmdu); - return NULL; -} - -struct cmdu_cstruct *cntlr_gen_ap_autoconfig_search(struct controller *c, - char *intf_name, uint8_t profile, uint8_t band) -{ - struct cmdu_cstruct *cmdu; - struct tlv_supp_service *p = NULL; - struct tlv_searched_service *p1; - struct tlv_map_profile *p2; - struct tlv_al_mac *p3; - struct tlv_autoconf_freq_band *p4; - struct tlv_searched_role *p5; - int i, tlv_index = 0; - - cmdu = (struct cmdu_cstruct *)calloc(1, sizeof(struct cmdu_cstruct)); - if (!cmdu) { - fprintf(stderr, "failed to malloc cmdu\n"); - return NULL; + /* Will return null if band did not match OR on failure */ + ret = cntlr_gen_wsc(c, resp, cred, msg, msglen, e_band); + if (ret) + continue; } - memcpy(cmdu->origin, "\x01\x80\xc2\x00\x00\x13", 6); - if (intf_name) - strncpy(cmdu->intf_name, intf_name, - sizeof(cmdu->intf_name) - 1); - else - strncpy(cmdu->intf_name, c->cfg.al_bridge, sizeof(cmdu->intf_name) - 1); - - cmdu->message_type = CMDU_TYPE_AP_AUTOCONFIGURATION_SEARCH; - - p = calloc(1, sizeof(struct tlv_supp_service)); - if (!p) - goto fail_cmdu; - - cmdu->num_tlvs++; - p->tlv_type = MAP_TLV_SUPPORTED_SERVICE; - p->supported_services_list = 1; - p->supported_services = calloc(p->supported_services_list, - sizeof(*p->supported_services)); - if (!p->supported_services) - goto fail_p; - - for (i = 0; i < p->supported_services_list; i++) - p->supported_services[i].service = - SUPPORTED_SERVICE_MULTIAP_CONTROLLER; - - p1 = calloc(1, sizeof(struct tlv_searched_service)); - if (!p1) - goto fail_p; - - cmdu->num_tlvs++; - p1->tlv_type = MAP_TLV_SEARCHED_SERVICE; - p1->searched_services_list = 1; - p1->service = calloc(p1->searched_services_list, sizeof(*p1->service)); - if (!p1->service) - goto fail_p1; - - for (i = 0; i < p1->searched_services_list; i++) - p1->service[i] = SEARCHED_SERVICE_MULTIAP_CONTROLLER; - - p2 = calloc(1, sizeof(struct tlv_map_profile)); - if (!p2) - goto fail_p1; - - cmdu->num_tlvs++; - p2->tlv_type = MAP_TLV_MULTIAP_PROFILE; - p2->profile = profile; - - p3 = cntlr_gen_al_mac(c, c->almac); - if (!p3) - goto fail_p2; - cmdu->num_tlvs++; - - p4 = cntlr_gen_autoconf_freq_band(c, band); /* dummy value */ - if (!p4) - goto fail_p3; - cmdu->num_tlvs++; - - p5 = cntlr_gen_searched_role(c, 0x00); /* registrar */ - if (!p5) - goto fail_p4; - cmdu->num_tlvs++; - - cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, - sizeof(uint8_t *)); - if (!cmdu->tlvs) - goto fail_p5; - - cmdu->tlvs[tlv_index++] = (uint8_t *)p; - cmdu->tlvs[tlv_index++] = (uint8_t *)p1; - cmdu->tlvs[tlv_index++] = (uint8_t *)p2; - cmdu->tlvs[tlv_index++] = (uint8_t *)p3; - cmdu->tlvs[tlv_index++] = (uint8_t *)p4; - cmdu->tlvs[tlv_index++] = (uint8_t *)p5; - - return cmdu; -fail_p5: - map_free_tlv_cstruct((uint8_t *) p5); -fail_p4: - map_free_tlv_cstruct((uint8_t *) p4); -fail_p3: - map_free_tlv_cstruct((uint8_t *) p3); -fail_p2: - map_free_tlv_cstruct((uint8_t *) p2); -fail_p1: - map_free_tlv_cstruct((uint8_t *) p1); -fail_p: - map_free_tlv_cstruct((uint8_t *) p); -fail_cmdu: - free(cmdu); + memcpy(resp->origin, rec_cmdu->origin, 6); + cmdu_put_eom(resp); + return resp; +out: + cmdu_free(resp); return NULL; } @@ -556,3 +688,4 @@ fail_cmdu: map_free_cmdu(cmdu); return NULL; } + diff --git a/src/core/cntlr_cmdu_generator.h b/src/core/cntlr_cmdu_generator.h index 23b15fb82709990f1eb8c102674f7382803321ba..9a5f4f8ddf51be20d57a89b5094baa15b5409023 100644 --- a/src/core/cntlr_cmdu_generator.h +++ b/src/core/cntlr_cmdu_generator.h @@ -10,25 +10,30 @@ #ifndef CNTLR_CMDU_GEN_H #define CNTLR_CMDU_GEN_H -struct cmdu_cstruct *cntlr_gen_ap_autoconfig_renew(struct controller *c, +struct cmdu_buff *cntlr_gen_ap_autoconfig_renew(struct controller *c, uint8_t *origin, char *intf_name, uint8_t *almac); -struct cmdu_cstruct *cntlr_gen_ap_capability_query(struct controller *c, +struct cmdu_buff *cntlr_gen_ap_capability_query(struct controller *c, uint8_t *origin, char *intf_name); -struct cmdu_cstruct *cntlr_gen_client_capability_query(struct controller *c, +struct cmdu_buff *cntlr_gen_client_capability_query(struct controller *c, uint8_t *origin, char *intf_name, uint8_t *sta, uint8_t *bssid); -struct cmdu_cstruct *cntlr_gen_backhaul_steer_request(struct controller *c, +struct cmdu_buff *cntlr_gen_backhaul_steer_request(struct controller *c, uint8_t *origin, char *intf_name, uint8_t *bssid, uint8_t *bkhaul, uint8_t op_class, uint8_t channel); -struct cmdu_cstruct *cntlr_gen_ap_metrics_query(struct controller *c, +struct cmdu_buff *cntlr_gen_ap_metrics_query(struct controller *c, uint8_t *origin, char *intf_name, int num_bss, uint8_t *bsslist, int num_radio, uint8_t *radiolist); -struct cmdu_cstruct *cntlr_gen_policy_config_req(struct controller *c, +struct cmdu_buff *cntlr_gen_policy_config_req(struct controller *c, char *intf_name, struct agent_policy *found, int num_radio, uint8_t *radiolist, int num_bss, uint8_t *bsslist); -struct cmdu_cstruct *cntlr_gen_sta_metric_query(struct controller *c, +struct cmdu_buff *cntlr_gen_sta_metric_query(struct controller *c, uint8_t *origin, char *intf_name, uint8_t *sta); - -struct cmdu_cstruct *cntlr_gen_ap_autoconfig_search(struct controller *c, +struct cmdu_buff *cntlr_gen_ap_autoconfig_search(struct controller *c, char *intf_name, uint8_t profile, uint8_t band); +struct cmdu_buff *cntlr_gen_ap_autoconfig_response(struct controller *c, + uint8_t *dest, uint8_t band, uint16_t mid); +struct cmdu_buff *cntlr_gen_ap_autoconfig_wsc(struct controller *c, + struct agent_policy *a, struct cmdu_buff *rec_cmdu, + struct tlv *basic_cap, struct tlv *wsc, + uint16_t mid); #endif diff --git a/src/core/cntlr_map.c b/src/core/cntlr_map.c index 0df958a2b0f77bdb10a0f51cc89aa77707efa188..710c01c95498307c48ec4cf5ba6432d4e6018e0e 100644 --- a/src/core/cntlr_map.c +++ b/src/core/cntlr_map.c @@ -31,11 +31,13 @@ #include <easy/easy.h> #include <wifi.h> // TODO: remove wifi.h -#include <map1905/map2.h> -#include <map1905/maputils.h> -#include <ieee1905/1905_tlvs.h> +#include <timer_impl.h> +#include <cmdu.h> +#include <1905_tlvs.h> +#include <map22.h> +#include <map_module22.h> -#include "map_module.h" +//#include "map_module.h" #include "utils.h" #include "debug.h" #include "liblist.h" @@ -49,155 +51,215 @@ #include "cntlr_map_debug.h" #include "cntlr_tlv_generator.h" -#define for_each_tlv(e, _buf, _len) \ -for ((e) = (struct tlv *)(_buf); \ - (e)->len && (_buf) + (_len) - (uint8_t *)(e) - 3 - (e)->len >= 0; \ - (e) = (struct tlv *)(_buf + 3 + (e)->len)) - -struct tlv { - uint8_t type; - uint16_t len; - uint8_t value[]; -} __attribute__ ((packed)); - int verbose; -typedef int (*map_cmdu_handler_t)(void *cntlr, struct cmdu_cstruct *cmdu); +typedef int (*map_cmdu_handler_t)(void *cntlr, struct cmdu_buff *cmdu); struct map_cmdu_calltable_t { map_cmdu_handler_t handle; map_cmdu_handler_t debug; }; -int handle_topology_notification(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_topology_notification(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int handle_topology_response(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_topology_response(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int handle_ap_autoconfig_search(void *cntlr, struct cmdu_cstruct *rec_cmdu) +void send_cmdu_cb(struct ubus_request *req, int type, struct blob_attr *msg) { - trace("%s: --->\n", __func__); - struct controller *c = (struct controller *) cntlr; - uint16_t tlv_index = 0; - struct cmdu_cstruct *cmdu; - struct tlv_map_profile *p; - struct tlv_supp_service *p1; - struct tlv_supported_freq_band *p2; - struct tlv_al_mac *almac_tlv; - struct tlv_autoconf_freq_band *freq_tlv; - char mac_str[18] = {0}; - int ret; - - almac_tlv = extract_tlv_by_type(rec_cmdu, TLV_TYPE_AL_MAC_ADDRESS_TYPE); - if (!almac_tlv) - return -1; + struct json_object *jobj = NULL; + struct json_object *tmp; + uint16_t *mid; + char *str; + + if (!msg || !req->priv) { + fprintf(stderr, "%s:Message recieved is NULL\n", __func__); + return; + } - freq_tlv = extract_tlv_by_type(rec_cmdu, TLV_TYPE_AUTOCONFIG_FREQ_BAND); - if (!freq_tlv) - return -1; + mid = (uint16_t *)req->priv; - if (freq_tlv->freq_band == 0x00) { - if (!c->cfg.has_registrar_2g) - return -1; - } else if (freq_tlv->freq_band == 0x01) { - if (!c->cfg.has_registrar_5g) - return -1; - } else - return -1; - - if (!hwaddr_ntoa(almac_tlv->al_mac_address, mac_str)) - return -1; + str = (char *)blobmsg_format_json_indent(msg, true, -1); + if (str) { + jobj = json_tokener_parse(str); + free(str); + } - ret = cntlr_config_add_agent(&c->cfg, mac_str); - if (!ret) - cntlr_config_reload(&c->cfg); + if (jobj == NULL) + return; - cmdu = (struct cmdu_cstruct *)calloc(1, - sizeof(struct cmdu_cstruct)); - if (!cmdu) { - fprintf(stderr, "Out of memory!\n"); - return -1; + if (json_object_object_get_ex(jobj, "mid", &tmp)) { + *mid = json_object_get_int(tmp); + fprintf(stdout, "%s:%d cntlr map-mid:%d\n", __func__, __LINE__, *mid); // typo || } - cmdu->message_type = CMDU_TYPE_AP_AUTOCONFIGURATION_RESPONSE; - memcpy(cmdu->origin, rec_cmdu->origin, 6); - cmdu->message_id = rec_cmdu->message_id; - strncpy(cmdu->intf_name, rec_cmdu->intf_name, - sizeof(cmdu->intf_name) - 1); + json_object_put(jobj); +} - p = cntlr_gen_map_profile(c, cmdu); - if (!p) - goto fail_cmdu; - cmdu->num_tlvs++; +uint16_t send_cmdu(struct controller *a, struct cmdu_buff *cmdu) +{ + char *tlv_data = NULL; + uint16_t tlv_data_len = 1; + uint16_t tlv_str_len = 0; + int copy_index; + struct blob_buf b = { 0 }; + char dst_addr[18] = { 0 }; + uint8_t *ss = NULL; + uint16_t msgid = 0; + int ret = 0; + size_t i; + uint32_t id; - p1 = cntlr_gen_supp_service(c, cmdu); - if (!p1) - goto fail_p; - cmdu->num_tlvs++; + trace("|%s:%d| Entry\n", __func__, __LINE__); - p2 = cntlr_gen_supported_freq_band(c, freq_tlv->freq_band); - if (!p2) - goto fail_p1; - cmdu->num_tlvs++; + memset(&b, 0, sizeof(struct blob_buf)); + blob_buf_init(&b, 0); - cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, sizeof(uint8_t *)); - if (!cmdu->tlvs) - goto fail_p2; + blobmsg_add_u32(&b, "type", cmdu_get_type(cmdu)); - cmdu->tlvs[tlv_index++] = (uint8_t *)p; - cmdu->tlvs[tlv_index++] = (uint8_t *)p1; - cmdu->tlvs[tlv_index++] = (uint8_t *)p2; + if (hwaddr_is_zero(cmdu->origin)) + hwaddr_ntoa("\x01\x80\xC2\x00\x00\x13", dst_addr); + else + hwaddr_ntoa(cmdu->origin, dst_addr); + blobmsg_add_string(&b, "dst", dst_addr); + + blobmsg_add_u32(&b, "mid", (uint32_t)cmdu_get_mid(cmdu)); - ret = send_cmdu(c, cmdu); - map_free_cmdu(cmdu); + + trace("|%s:%d|cmdu:%u|egress:%s|dst:%s|mid:%u|fid:%u\n", __func__, __LINE__, + cmdu_get_type(cmdu), + "TODO", dst_addr, cmdu_get_mid(cmdu), cmdu_get_fid(cmdu)); + + if (cmdu->datalen) { + char *tlv_str = NULL; + uint16_t len = 0; + + //char tlv_str[1500] = {0}; + len = (cmdu->datalen * 2) + 1; + dbg("datalen = %d, len = %d\n", cmdu->datalen, len); + tlv_str = (char *)calloc(len, sizeof(char)); + if (!tlv_str) + goto out; + + btostr(cmdu->data, cmdu->datalen, tlv_str); + tlv_str[len-1] = '\0'; + blobmsg_add_string(&b, "data", tlv_str); + trace("|%s:%d|data:%s|\n", __func__, __LINE__, tlv_str); + free(tlv_str); + } + + if (ubus_lookup_id(a->ubus_ctx, "i1905.al.eth1", &id)) { + trace("[%s:%d] not present i1905.al.eth1", __func__, __LINE__); + goto out; + } + + ret = ubus_invoke(a->ubus_ctx, id, "cmdu", + b.head, send_cmdu_cb, + &msgid, + 1000); + if (ret) { + trace("[%s:%d] ubus call failed for |i1905.al.eth1 send|", + __func__, __LINE__); + goto out; + } + + trace("|%s:%d| msgid = %d\n", __func__, __LINE__, msgid); + ret = msgid; +out: + blob_buf_free(&b); return ret; -fail_p2: - map_free_tlv_cstruct((uint8_t *) p2); -fail_p1: - map_free_tlv_cstruct((uint8_t *) p1); -fail_p: - map_free_tlv_cstruct((uint8_t *) p); -fail_cmdu: - free(cmdu); - return -1; } -/* disable and quit on controller response */ -int handle_ap_autoconfig_response(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_ap_autoconfig_search(void *cntlr, struct cmdu_buff *rec_cmdu) { trace("%s: --->\n", __func__); struct controller *c = (struct controller *) cntlr; - struct tlv_supp_service *tlv; - int i; - bool has_cntlr = false; - - tlv = extract_tlv_by_type(cmdu, MAP_TLV_SUPPORTED_SERVICE); - if (!tlv) - return 0; - - /* find if supported services containts controller */ - for (i = 0; i < tlv->supported_services_list; i++) { - if (tlv->supported_services[i].service == SUPPORTED_SERVICE_MULTIAP_CONTROLLER) { - has_cntlr = true; + struct tlv_policy a_policy[] = { + [0] = { .type = TLV_TYPE_AL_MAC_ADDRESS_TYPE, .present = TLV_PRESENT_ONE }, + [1] = { .type = TLV_TYPE_SEARCHED_ROLE, .present = TLV_PRESENT_ONE }, + [2] = { .type = TLV_TYPE_AUTOCONFIG_FREQ_BAND, .present = TLV_PRESENT_ONE }, + [3] = { .type = MAP_TLV_SUPPORTED_SERVICE, .present = TLV_PRESENT_ONE }, + [4] = { .type = MAP_TLV_SEARCHED_SERVICE, .present = TLV_PRESENT_ONE }, + [5] = { .type = MAP_TLV_MULTIAP_PROFILE, .present = TLV_PRESENT_ONE } + }; + struct tlv_autoconfig_band *freq; + struct cmdu_buff *cmdu; + uint8_t aladdr_origin[6] = {0}; + struct tlv *tv[6][16] = {0}; + int ret = 0; + + ret = cmdu_parse_tlvs(rec_cmdu, tv, a_policy, 6); + + if (!tv[0][0] || !tv[1][0] || !tv[2][0] || !tv[3][0] || !tv[4][0] + || !tv[5][0]) + return -1; + + memcpy(aladdr_origin, tv[0][0]->data, tlv_length(tv[0][0])); + if (hwaddr_is_zero(aladdr_origin)) { + trace("%s: Discard ap-autoconfig search from aladdr = 0!\n", + __func__); + + return -1; + } + + if (tv[1][0]->data[0] != IEEE80211_ROLE_REGISTRAR) { + trace("%s: Discard ap-autoconfig search for role != registrar\n", + __func__); + return -1; + } + + freq = (struct tlv_autoconfig_band *)tv[2][0]->data; + if (freq->band > IEEE80211_FREQUENCY_BAND_60_GHZ) { + trace("%s: Discard ap-autoconfig search for invalid WiFi band\n", + __func__); + return -1; + } + + if (freq->band == IEEE80211_FREQUENCY_BAND_2_4_GHZ) { + if (!c->cfg.has_registrar_2g) + return -1; + } else if (freq->band == IEEE80211_FREQUENCY_BAND_5_GHZ) { + if (!c->cfg.has_registrar_5g) + return -1; + } else + return -1; + + /* if supports agent, add to config */ + if (tv[3][0]->data[0] > 0) { + int i; + char mac_str[18] = {0}; + int len = 0; + + if (!hwaddr_ntoa(aladdr_origin, mac_str)) + return -1; + + for (i = 0; i < tv[3][0]->data[0]; i++) { + if (tv[3][0]->data[(i+1)] != SUPPORTED_SERVICE_MULTIAP_AGENT) + continue; + + ret = cntlr_config_add_agent(&c->cfg, mac_str); + if (!ret) + cntlr_config_reload(&c->cfg); break; } } - /* if does not support controller - return */ - if (!has_cntlr) - return 0; - /* discard self response */ - if (!memcmp(cmdu->origin, c->almac, 6)) - return 0; + /* TODO: don't answer if searched service does not include controller */ - trace("Received AP-Autoconfig Response which was not from self\n"); + trace("%s: sending autoconfig response for band = %d\n", + __func__, freq->band); + cmdu = cntlr_gen_ap_autoconfig_response(cntlr, aladdr_origin, + freq->band, + cmdu_get_mid(rec_cmdu)); + if (!cmdu) + return -1; if (c->state == CNTLR_INIT) { @@ -207,263 +269,233 @@ int handle_ap_autoconfig_response(void *cntlr, struct cmdu_cstruct *cmdu) exit(0); } else { char data[128] = {0}; + ret = send_cmdu(c, cmdu); - snprintf(data, sizeof(data), "{\"type\":\"error\", \"reason\":\"multiple controllers\", \"almac\":\""MACFMT"\"}", MAC2STR(cmdu->origin)); - cntlr_notify_event(c, "map.controller", data); - } + cmdu_free(cmdu); + return 0; +} +/* disable and quit on controller response */ +int handle_ap_autoconfig_response(void *cntlr, struct cmdu_buff *cmdu) +{ + trace("%s: --->\n", __func__); return 0; +// struct controller *c = (struct controller *) cntlr; +// struct tlv_supp_service *tlv; +// int i; +// bool has_cntlr = false; +// +// tlv = extract_tlv_by_type(cmdu, MAP_TLV_SUPPORTED_SERVICE); +// if (!tlv) +// return 0; +// +// /* find if supported services containts controller */ +// for (i = 0; i < tlv->supported_services_list; i++) { +// if (tlv->supported_services[i].service == SUPPORTED_SERVICE_MULTIAP_CONTROLLER) { +// has_cntlr = true; +// break; +// } +// } +// /* if does not support controller - return */ +// if (!has_cntlr) +// return 0; +// +// /* discard self response */ +// if (!memcmp(cmdu->origin, c->almac, 6)) +// return 0; +// +// trace("Received AP-Autoconfig Response which was not from self\n"); +// +// if (c->state == CNTLR_INIT) { +// trace("Disable and exit\n"); +// set_value_by_string("mapcontroller", "controller", "enabled", "0", +// UCI_TYPE_STRING); +// exit(0); +// } else { +// char data[128] = {0}; +// +// snprintf(data, sizeof(data), "{\"type\":\"error\", \"reason\":\"multiple controllers\", \"almac\":\""MACFMT"\"}", MAC2STR(cmdu->origin)); +// cntlr_notify_event(c, "map.controller", data); +// } +// +// return 0; } -int handle_ap_autoconfig_wsc(void *cntlr, struct cmdu_cstruct *rec_cmdu) +int handle_ap_autoconfig_wsc(void *cntlr, struct cmdu_buff *rec_cmdu) { trace("%s: --->\n", __func__); struct controller *c = (struct controller *) cntlr; struct agent_policy *a, *found = NULL; - struct tlv_default_8021q_settings *p; - struct tlv_traffic_sep_policy *p1; - struct tlv_ap_radio_identifier *p2; - struct tlv_ap_radio_basic_cap *rec_basic_cap; - struct tlv_wsc *p3; - struct cmdu_cstruct *cmdu; - struct iface_credential *cred; - int tlv_index = 0, ret, i; - uint8_t **tlvs; - - cmdu = (struct cmdu_cstruct *)calloc(1, sizeof(struct cmdu_cstruct)); - if (!cmdu) { - fprintf(stderr, "failed to malloc cmdu\n"); + struct tlv_policy a_policy[] = { + [0] = { .type = MAP_TLV_AP_RADIO_BASIC_CAPABILITIES, .present = TLV_PRESENT_ONE }, + [1] = { .type = MAP_TLV_PROFILE2_AP_CAPABILITY, .present = TLV_PRESENT_ONE }, + [2] = { .type = MAP_TLV_AP_RADIO_ADV_CAPABILITY, .present = TLV_PRESENT_ONE }, + [3] = { .type = TLV_TYPE_WSC, .present = TLV_PRESENT_ONE } + }; + struct cmdu_buff *cmdu; + uint8_t aladdr_origin[6] = {0}; + struct tlv *tv[4][16] = {0}; + bool agent_found; + int ret = 0; + + ret = cmdu_parse_tlvs(rec_cmdu, tv, a_policy, 4); + + if (!tv[0][0] || !tv[1][0] || !tv[2][0] || !tv[3][0]) return -1; - } - memcpy(cmdu->origin, rec_cmdu->origin, 6); - cmdu->message_type = CMDU_TYPE_AP_AUTOCONFIGURATION_WSC; - cmdu->message_id = rec_cmdu->message_id; - strncpy(cmdu->intf_name, rec_cmdu->intf_name, - sizeof(cmdu->intf_name) - 1); + /* TODO: workaround to local address */ + if (hwaddr_is_zero(rec_cmdu->origin)) + memcpy(rec_cmdu->origin, c->almac, 6); list_for_each_entry(a, &c->cfg.policylist, list) { if (!memcmp(rec_cmdu->origin, a->agent_id, 6)) { - found = a; + agent_found = true; break; } } - - if (!found) + if (!agent_found) return -1; - p = cntlr_gen_8021q_settings(c, a); - if (!p) - goto fail_cmdu; - cmdu->num_tlvs++; - - p1 = cntlr_gen_traffic_sep_policy(c, cmdu); - if (!p1) - goto fail_p; - cmdu->num_tlvs++; - - rec_basic_cap = extract_tlv_by_type(rec_cmdu, - MAP_TLV_AP_RADIO_BASIC_CAPABILITIES); - if (!rec_basic_cap) - goto fail_p1; - - p2 = cntlr_gen_ap_radio_identifier(c, cmdu, rec_basic_cap->radio_id); - if (!p2) - goto fail_p1; - cmdu->num_tlvs++; - - cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, sizeof(uint8_t *)); - if (!cmdu->tlvs) - goto fail_p2; - - cmdu->tlvs[tlv_index++] = (uint8_t *)p; - cmdu->tlvs[tlv_index++] = (uint8_t *)p1; - cmdu->tlvs[tlv_index++] = (uint8_t *)p2; - - /* Generate all fBSS wsc tlvs for this BSS */ - list_for_each_entry(cred, &c->cfg.fhlist, list) { - /* Will return null if band did not match OR on failure */ - p3 = cntlr_gen_wsc(c, cmdu, rec_cmdu, cred); - if (!p3) - continue; - cmdu->num_tlvs++; - - tlvs = (uint8_t **)realloc(cmdu->tlvs, cmdu->num_tlvs * sizeof(uint8_t *)); - if (!tlvs) { - cmdu->num_tlvs--; - map_free_tlv_cstruct((uint8_t *) p3); - continue; - } - - cmdu->tlvs = tlvs; - cmdu->tlvs[tlv_index++] = (uint8_t *)p3; - } - - /* Generate all bBSS wsc tlvs for this BSS */ - list_for_each_entry(cred, &c->cfg.bklist, list) { - /* Will return null if band did not match OR on failure */ - p3 = cntlr_gen_wsc(c, cmdu, rec_cmdu, cred); - if (!p3) - continue; - cmdu->num_tlvs++; - - tlvs = (uint8_t **)realloc(cmdu->tlvs, cmdu->num_tlvs * sizeof(uint8_t *)); - if (!tlvs) { - cmdu->num_tlvs--; - map_free_tlv_cstruct((uint8_t *) p3); - continue; - } - - cmdu->tlvs = tlvs; - cmdu->tlvs[tlv_index++] = (uint8_t *)p3; - } - - if (cmdu->num_tlvs < 4) - goto fail_tlvs; + trace("%s: prepare autoconfig wsc response\n", __func__); + cmdu = cntlr_gen_ap_autoconfig_wsc(cntlr, a, rec_cmdu, tv[1][0], tv[3][0], + cmdu_get_mid(rec_cmdu)); + if (!cmdu) + return -1; ret = send_cmdu(c, cmdu); - map_free_cmdu(cmdu); - return ret; -fail_tlvs: - free(cmdu->tlvs); -fail_p2: - map_free_tlv_cstruct((uint8_t *) p2); -fail_p1: - map_free_tlv_cstruct((uint8_t *) p1); -fail_p: - map_free_tlv_cstruct((uint8_t *) p); -fail_cmdu: - free(cmdu); + return 0; +out: + cmdu_free(cmdu); return -1; } -int handle_1905_ack(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_1905_ack(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int handle_ap_caps_report(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_ap_caps_report(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); - trace("parsing AP capabilities of |%s:" MACFMT "|\n", - cmdu->intf_name, MAC2STR(cmdu->origin)); +// trace("parsing AP capabilities of |%s:" MACFMT "|\n", +// cmdu->intf_name, MAC2STR(cmdu->origin)); return 0; } -int handle_channel_pref_report(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_channel_pref_report(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int handle_channel_sel_response(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_channel_sel_response(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int handle_oper_channel_report(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_oper_channel_report(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int handle_sta_caps_report(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_sta_caps_report(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); - trace("parsing AP capabilities of |%s:" MACFMT "|\n", - cmdu->intf_name, MAC2STR(cmdu->origin)); +// trace("parsing AP capabilities of |%s:" MACFMT "|\n", +// cmdu->intf_name, MAC2STR(cmdu->origin)); return 0; } -int handle_ap_metrics_response(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_ap_metrics_response(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int handle_sta_link_metrics_response(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_sta_link_metrics_response(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } int handle_unassoc_sta_link_metrics_response(void *cntlr, - struct cmdu_cstruct *cmdu) + struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int handle_beacon_metrics_response(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_beacon_metrics_response(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int handle_sta_steer_btm_report(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_sta_steer_btm_report(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int handle_sta_steer_complete(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_sta_steer_complete(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int handle_backhaul_sta_steer_response(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_backhaul_sta_steer_response(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int handle_channel_scan_report(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_channel_scan_report(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); - trace("parsing channel scan report of |%s:" MACFMT "|\n", - cmdu->intf_name, MAC2STR(cmdu->origin)); +// trace("parsing channel scan report of |%s:" MACFMT "|\n", +// cmdu->intf_name, MAC2STR(cmdu->origin)); return 0; } -int handle_sta_disassoc_stats(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_sta_disassoc_stats(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int handle_assoc_status_notification(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_assoc_status_notification(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int handle_tunneled_message(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_tunneled_message(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int handle_backhaul_sta_caps_report(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_backhaul_sta_caps_report(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int handle_failed_connection_msg(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_failed_connection_msg(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -#define CMDU_TYPE_1905_START 0x0001 -#define CMDU_TYPE_1905_END 0x0009 +//#define CMDU_TYPE_1905_START 0x0001 +//#define CMDU_TYPE_1905_END 0x0009 #define CMDU_TYPE_MAP_START 0x8000 @@ -493,6 +525,7 @@ static const struct map_cmdu_calltable_t i1905ftable[] = { }, }; + static const struct map_cmdu_calltable_t cntlr_mapftable[] = { [0x00] = { .handle = handle_1905_ack, @@ -570,6 +603,7 @@ static const struct map_cmdu_calltable_t cntlr_mapftable[] = { .handle = handle_failed_connection_msg, .debug = debug_failed_connection_msg }, + }; @@ -604,7 +638,7 @@ int cntlr_handle_map_event(void *module, uint16_t cmdutype, uint16_t mid, { struct controller *c = (struct controller *)module; const struct map_cmdu_calltable_t *f; - struct cmdu_cstruct *cmdu; + struct cmdu_buff *cmdu = NULL; int ret = 0; int idx; @@ -618,21 +652,18 @@ int cntlr_handle_map_event(void *module, uint16_t cmdutype, uint16_t mid, f = i1905ftable; } - cmdu = map_build_cmdu(cmdutype, mid, rxif, src, tlvs); + cmdu = cmdu_alloc_custom(cmdutype, &mid, rxif, src, tlvs, len); if (!cmdu) { - dbg("%s: map_build_cmdu() failed!\n", __func__); + dbg("%s: cmdu_alloc_custom() failed!\n", __func__); return -1; } - fprintf(stderr, " %s -", __func__); test_cmdu(cmdu); + dbg("%s: cmdu_alloc_custom() succeeded! cmdu->cdata->hdr.mid %u\n", __func__, cmdu_get_mid(cmdu)); if (f[idx].handle) ret = f[idx].handle(c, cmdu); - if (verbose >= 4 && f[idx].debug) - f[idx].debug(c, cmdu); - - map_free_cmdu(cmdu); +// map_free_cmdu(cmdu); //TODO: check ret diff --git a/src/core/cntlr_map.h b/src/core/cntlr_map.h index a5689e4440df729e008f265ebda94ef4e80eb74b..8ef9c247eeaf0e8c3f32b210b73128fed0d80cbe 100644 --- a/src/core/cntlr_map.h +++ b/src/core/cntlr_map.h @@ -9,5 +9,9 @@ extern int cntlr_handle_map_event(void *module, uint16_t cmdutype, uint16_t mid, char *rxif, uint8_t *src, uint8_t *tlvs, int len); +void send_cmdu_cb(struct ubus_request *req, int type, struct blob_attr *msg); +uint16_t send_cmdu(struct controller *a, struct cmdu_buff *cmdu); +int cntlr_handle_map_event(void *module, uint16_t cmdutype, uint16_t mid, + char *rxif, uint8_t *src, uint8_t *tlvs, int len); #endif /* CNTLR_MAP_H */ diff --git a/src/core/cntlr_map_debug.c b/src/core/cntlr_map_debug.c index 49adebdf1455e042a31e8306f54e3f58dbdba773..b4e589661533804db5af44750c148fbb98d8259c 100644 --- a/src/core/cntlr_map_debug.c +++ b/src/core/cntlr_map_debug.c @@ -19,26 +19,29 @@ #include "utils.h" #include "debug.h" -#include <map1905/map2.h> -#include <map1905/maputils.h> +#include <timer_impl.h> +#include <cmdu.h> +#include <1905_tlvs.h> +#include <map22.h> #include "cntlr_map_debug.h" -int debug_topology_notification(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_topology_notification(void *cntlr, struct cmdu_buff *cmdu) { - uint8_t *tlv = NULL; - trace("%s: --->\n", __func__); - tlv = (uint8_t *) cmdu->tlvs[0]; - trace("\nCMDU type: %s\n", map_stringify_tlv_type(*tlv)); - struct tlv_client_assoc_event *p = - (struct tlv_client_assoc_event *)tlv; - trace("\tclient_addr: " MACFMT "\n", MAC2STR(p->client_addr)); - trace("\tbssid: " MACFMT "\n", MAC2STR(p->bssid)); - trace("\tassoc_event: %d\n\n", p->assoc_event); return 0; +// uint8_t *tlv = NULL; +// trace("%s: --->\n", __func__); +// tlv = (uint8_t *) cmdu->tlvs[0]; +// trace("\nCMDU type: %s\n", map_stringify_tlv_type(*tlv)); +// struct tlv_client_assoc_event *p = +// (struct tlv_client_assoc_event *)tlv; +// trace("\tclient_addr: " MACFMT "\n", MAC2STR(p->client_addr)); +// trace("\tbssid: " MACFMT "\n", MAC2STR(p->bssid)); +// trace("\tassoc_event: %d\n\n", p->assoc_event); +// return 0; } -int debug_topology_response(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_topology_response(void *cntlr, struct cmdu_buff *cmdu) { uint8_t *tlv; int i, j, k; @@ -210,1074 +213,1089 @@ int debug_topology_response(void *cntlr, struct cmdu_cstruct *cmdu) return 0; } -int debug_ap_autoconfig_search(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_ap_autoconfig_search(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int debug_ap_autoconfig_response(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_ap_autoconfig_response(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int debug_ap_autoconfig_wsc(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_ap_autoconfig_wsc(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int debug_1905_ack(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_1905_ack(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); - trace("parsing 1905 ack of |%s:" MACFMT "|\n", cmdu->intf_name, - MAC2STR(cmdu->origin)); - - int i, j, k; - uint8_t *tlv = NULL; - - for (i = 0; i < cmdu->num_tlvs; i++) { - tlv = (uint8_t *) cmdu->tlvs[i]; - trace("CMDU type: %s\n", map_stringify_tlv_type(*tlv)); - switch (*tlv) { - case MAP_TLV_ERROR_CODE: - { - struct tlv_error_code *p = (struct tlv_error_code *)tlv; - - trace("\treason_code: %d\n", - p->reason_code); - trace("\tsta addr: " MACFMT "\n", - MAC2STR(p->addr)); - break; - } - default: - fprintf(stdout, "unknown TLV in CMDU:|%s|", - map_stringify_cmdu_type(cmdu->message_type)); - break; - } - trace("\n"); - } return 0; +// trace("parsing 1905 ack of |%s:" MACFMT "|\n", cmdu->intf_name, +// MAC2STR(cmdu->origin)); +// +// int i, j, k; +// uint8_t *tlv = NULL; +// +// for (i = 0; i < cmdu->num_tlvs; i++) { +// tlv = (uint8_t *) cmdu->tlvs[i]; +// trace("CMDU type: %s\n", map_stringify_tlv_type(*tlv)); +// switch (*tlv) { +// case MAP_TLV_ERROR_CODE: +// { +// struct tlv_error_code *p = (struct tlv_error_code *)tlv; +// +// trace("\treason_code: %d\n", +// p->reason_code); +// trace("\tsta addr: " MACFMT "\n", +// MAC2STR(p->addr)); +// break; +// } +// default: +// fprintf(stdout, "unknown TLV in CMDU:|%s|", +// map_stringify_cmdu_type(cmdu->message_type)); +// break; +// } +// trace("\n"); +// } +// return 0; } -int debug_ap_caps_report(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_ap_caps_report(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); - trace("parsing AP capabilities of |%s:" MACFMT "|\n", cmdu->intf_name, - MAC2STR(cmdu->origin)); - - int i, j, k; - uint8_t *tlv = NULL; - - for (i = 0; i < cmdu->num_tlvs; i++) { - tlv = (uint8_t *) cmdu->tlvs[i]; - trace("\nCMDU type: %s\n", map_stringify_tlv_type(*tlv)); - switch (*tlv) { - case MAP_TLV_AP_CAPABILITY: - { - struct tlv_ap_cap *p = (struct tlv_ap_cap *)tlv; - - trace("\top_ch_metric_reporting: %d\n", - p->op_ch_metric_reporting); - trace("\tnon_op_ch_metric_reporting: %d\n", - p->non_op_ch_metric_reporting); - trace("\tagent_init_rcpi_steering: %d\n", - p->agent_init_rcpi_steering); - break; - } - case MAP_TLV_AP_RADIO_BASIC_CAPABILITIES: - { - struct tlv_ap_radio_basic_cap *p = - (struct tlv_ap_radio_basic_cap *)tlv; - - trace("\tradio_id: " MACFMT "\n", MAC2STR(p->radio_id)); - trace("\tmax_bss_nr: %d\n", p->max_bss_nr); - trace("\toperating_classes_nr: %d\n", p->operating_classes_nr); - for (j = 0; j < p->operating_classes_nr; j++) { - trace("\t\top_class: %d\n", - p->operating_class[j].op_class); - trace("\t\tmax_tx_power: %d\n", - p->operating_class[j].max_tx_power); - trace("\t\tnon_op_ch_nr: %d\n", - p->operating_class[j].non_op_ch_nr); - - for (k = 0; k < p->operating_class[j].non_op_ch_nr; k++) - trace("\t\t\tchannel: %d\n", - p->operating_class[j].channel[k]); - } - break; - } - case MAP_TLV_AP_HT_CAPABILITIES: - { - struct tlv_ap_ht_cap *p = - (struct tlv_ap_ht_cap *)tlv; - - trace("\tradio_id: " MACFMT "\n", - MAC2STR(p->radio_id)); - trace("\tmax_tx_streams_supported: %d\n", - p->max_tx_streams_supported); - trace("\tmax_tx_streams_supported: "); - print_bits(p->max_tx_streams_supported, 2, 2); - trace("\tmax_rx_streams_supported: "); - print_bits(p->max_rx_streams_supported, 2, 2); - trace("\tgi_20_support: %s\n", - (p->gi_20_support ? "true" : "false")); - trace("\tgi_40_support: %s\n", - (p->gi_40_support ? "true" : "false")); - trace("\tht_40_support: %s\n", - (p->ht_40_support ? "true" : "false")); - break; - } - case MAP_TLV_AP_VHT_CAPABILITIES: - { - struct tlv_ap_vht_cap *p = - (struct tlv_ap_vht_cap *)tlv; - - trace("\tradio_id: " MACFMT "\n", - MAC2STR(p->radio_id)); - trace("\tvht_tx_mcs_supported: "); - print_bits(p->vht_tx_mcs_supported, 16, 2); - trace("\tvht_rx_mcs_supported: "); - print_bits(p->vht_rx_mcs_supported, 16, 2); - trace("\tmax_tx_streams_supported: "); - print_bits(p->max_tx_streams_supported, 3, 3); - trace("\tmax_rx_streams_supported: "); - print_bits(p->max_rx_streams_supported, 3, 3); - trace("\tgi_80_support: %s\n", - (p->gi_80_support ? "true" : "false")); - trace("\tgi_160_support: %s\n", - (p->gi_160_support ? "true" : "false")); - trace("\tvht160_support: %s\n", - (p->vht_160_support ? "true" : "false")); - trace("\tsu_beamformer_capable: %s\n", - (p->su_beamformer_capable ? "true" : "false")); - trace("\tmu_beamformer_capable: %s\n", - (p->mu_beamformer_capable ? "true" : "false")); - break; - } - case MAP_TLV_CHANNEL_SCAN_CAPABILITY: - { - struct tlv_ch_scan_cap *p = - (struct tlv_ch_scan_cap *)tlv; - int j; - - trace("\tnbr_radios: %d\n", p->nbr_radios); - for (j = 0; j < p->nbr_radios; j++) { - int k; - - trace("\t\tradio_id: " MACFMT "\n", - MAC2STR(p->radio[j].radio_id)); - trace("\t\ton_boot: %d\n", p->radio[j].on_boot); - trace("\t\tscan_impact: 0x%02x\n", p->radio[j].scan_impact); - trace("\t\tmin_scan_interval: %d\n", - p->radio[j].min_scan_interval); - trace("\t\tnbr_op_classes: %d\n", - p->radio[j].nbr_op_classes); - - for (k = 0; k < p->radio[j].nbr_op_classes; k++) { - int l; - - trace("\t\t\top_class: %d\n", - p->radio[j].op_class[k].op_class); - trace("\t\t\tnbr_ch: %d\n", - p->radio[j].op_class[k].nbr_ch); - - for (l = 0; l < p->radio[j].op_class[k].nbr_ch; l++) { - trace("\t\t\t\tch: %d\n", - p->radio[j].op_class[k].ch[l]); - } - } - trace("\n"); - } - break; - } - case MAP_TLV_CAC_CAPABILITY: - { - struct tlv_cac_cap *p = - (struct tlv_cac_cap *)tlv; - int j; - - trace("\tcountry_code: %c%c\n", p->country_code[0], p->country_code[1]); - trace("\tnbr_radios: %d\n", p->nbr_radios); - for (j = 0; j < p->nbr_radios; j++) { - int k; - - trace("\t\tradio_id: " MACFMT "\n", - MAC2STR(p->radio_data[j].radio_id)); - trace("\t\tnbr_cac_types: %d\n", - p->radio_data[j].nbr_cac_types); - for (k = 0; k < p->radio_data[j].nbr_cac_types; k++) { - int l; - - trace("\t\t\tcac_method_supported: 0x%02x\n", - p->radio_data[j].cac_data[k].cac_method_supported); - trace("\t\t\tduration: %d\n", - p->radio_data[j].cac_data[k].duration); - trace("\t\t\tnbr_op_classes: %d\n", - p->radio_data[j].cac_data[k].nbr_op_classes); - - for (l = 0; l < p->radio_data[j].cac_data[k].nbr_op_classes; l++) { - int m; - - trace("\t\t\t\top_class: %d\n", - p->radio_data[j].cac_data[k].op_class_data[l].op_class); - trace("\t\t\t\tnbr_ch: %d\n", - p->radio_data[j].cac_data[k].op_class_data[l].nbr_ch); - - for (m = 0; m < p->radio_data[j].cac_data[k].op_class_data[l].nbr_ch; m++) - trace("\t\t\t\t\tch: %d\n", - p->radio_data[j].cac_data[k].op_class_data[l].ch[m]); - } - } - trace("\n"); - } - break; - } - case MAP_TLV_PROFILE2_AP_CAPABILITY: - { - struct tlv_profile2_ap_cap *p = - (struct tlv_profile2_ap_cap *)tlv; - - trace("\tbyte_counter: 0x%02x\n", p->byte_counter); - trace("\tmax_vids: 0x%02x\n", p->max_vids); - break; - } - case MAP_TLV_METRIC_COLLECTION_INTERVAL: - { - struct tlv_metric_collection_interval *p = - (struct tlv_metric_collection_interval *)tlv; - - trace("\tcollection_interval: %d ms\n", p->collection_interval); - break; - } - default: - fprintf(stdout, "unknown TLV in CMDU:|%s|", - map_stringify_cmdu_type(cmdu->message_type)); - break; - } - trace("\n"); - } return 0; +// trace("parsing AP capabilities of |%s:" MACFMT "|\n", cmdu->intf_name, +// MAC2STR(cmdu->origin)); +// +// int i, j, k; +// uint8_t *tlv = NULL; +// +// for (i = 0; i < cmdu->num_tlvs; i++) { +// tlv = (uint8_t *) cmdu->tlvs[i]; +// trace("\nCMDU type: %s\n", map_stringify_tlv_type(*tlv)); +// switch (*tlv) { +// case MAP_TLV_AP_CAPABILITY: +// { +// struct tlv_ap_cap *p = (struct tlv_ap_cap *)tlv; +// +// trace("\top_ch_metric_reporting: %d\n", +// p->op_ch_metric_reporting); +// trace("\tnon_op_ch_metric_reporting: %d\n", +// p->non_op_ch_metric_reporting); +// trace("\tagent_init_rcpi_steering: %d\n", +// p->agent_init_rcpi_steering); +// break; +// } +// case MAP_TLV_AP_RADIO_BASIC_CAPABILITIES: +// { +// struct tlv_ap_radio_basic_cap *p = +// (struct tlv_ap_radio_basic_cap *)tlv; +// +// trace("\tradio_id: " MACFMT "\n", MAC2STR(p->radio_id)); +// trace("\tmax_bss_nr: %d\n", p->max_bss_nr); +// trace("\toperating_classes_nr: %d\n", p->operating_classes_nr); +// for (j = 0; j < p->operating_classes_nr; j++) { +// trace("\t\top_class: %d\n", +// p->operating_class[j].op_class); +// trace("\t\tmax_tx_power: %d\n", +// p->operating_class[j].max_tx_power); +// trace("\t\tnon_op_ch_nr: %d\n", +// p->operating_class[j].non_op_ch_nr); +// +// for (k = 0; k < p->operating_class[j].non_op_ch_nr; k++) +// trace("\t\t\tchannel: %d\n", +// p->operating_class[j].channel[k]); +// } +// break; +// } +// case MAP_TLV_AP_HT_CAPABILITIES: +// { +// struct tlv_ap_ht_cap *p = +// (struct tlv_ap_ht_cap *)tlv; +// +// trace("\tradio_id: " MACFMT "\n", +// MAC2STR(p->radio_id)); +// trace("\tmax_tx_streams_supported: %d\n", +// p->max_tx_streams_supported); +// trace("\tmax_tx_streams_supported: "); +// print_bits(p->max_tx_streams_supported, 2, 2); +// trace("\tmax_rx_streams_supported: "); +// print_bits(p->max_rx_streams_supported, 2, 2); +// trace("\tgi_20_support: %s\n", +// (p->gi_20_support ? "true" : "false")); +// trace("\tgi_40_support: %s\n", +// (p->gi_40_support ? "true" : "false")); +// trace("\tht_40_support: %s\n", +// (p->ht_40_support ? "true" : "false")); +// break; +// } +// case MAP_TLV_AP_VHT_CAPABILITIES: +// { +// struct tlv_ap_vht_cap *p = +// (struct tlv_ap_vht_cap *)tlv; +// +// trace("\tradio_id: " MACFMT "\n", +// MAC2STR(p->radio_id)); +// trace("\tvht_tx_mcs_supported: "); +// print_bits(p->vht_tx_mcs_supported, 16, 2); +// trace("\tvht_rx_mcs_supported: "); +// print_bits(p->vht_rx_mcs_supported, 16, 2); +// trace("\tmax_tx_streams_supported: "); +// print_bits(p->max_tx_streams_supported, 3, 3); +// trace("\tmax_rx_streams_supported: "); +// print_bits(p->max_rx_streams_supported, 3, 3); +// trace("\tgi_80_support: %s\n", +// (p->gi_80_support ? "true" : "false")); +// trace("\tgi_160_support: %s\n", +// (p->gi_160_support ? "true" : "false")); +// trace("\tvht160_support: %s\n", +// (p->vht_160_support ? "true" : "false")); +// trace("\tsu_beamformer_capable: %s\n", +// (p->su_beamformer_capable ? "true" : "false")); +// trace("\tmu_beamformer_capable: %s\n", +// (p->mu_beamformer_capable ? "true" : "false")); +// break; +// } +// case MAP_TLV_CHANNEL_SCAN_CAPABILITY: +// { +// struct tlv_ch_scan_cap *p = +// (struct tlv_ch_scan_cap *)tlv; +// int j; +// +// trace("\tnbr_radios: %d\n", p->nbr_radios); +// for (j = 0; j < p->nbr_radios; j++) { +// int k; +// +// trace("\t\tradio_id: " MACFMT "\n", +// MAC2STR(p->radio[j].radio_id)); +// trace("\t\ton_boot: %d\n", p->radio[j].on_boot); +// trace("\t\tscan_impact: 0x%02x\n", p->radio[j].scan_impact); +// trace("\t\tmin_scan_interval: %d\n", +// p->radio[j].min_scan_interval); +// trace("\t\tnbr_op_classes: %d\n", +// p->radio[j].nbr_op_classes); +// +// for (k = 0; k < p->radio[j].nbr_op_classes; k++) { +// int l; +// +// trace("\t\t\top_class: %d\n", +// p->radio[j].op_class[k].op_class); +// trace("\t\t\tnbr_ch: %d\n", +// p->radio[j].op_class[k].nbr_ch); +// +// for (l = 0; l < p->radio[j].op_class[k].nbr_ch; l++) { +// trace("\t\t\t\tch: %d\n", +// p->radio[j].op_class[k].ch[l]); +// } +// } +// trace("\n"); +// } +// break; +// } +// case MAP_TLV_CAC_CAPABILITY: +// { +// struct tlv_cac_cap *p = +// (struct tlv_cac_cap *)tlv; +// int j; +// +// trace("\tcountry_code: %c%c\n", p->country_code[0], p->country_code[1]); +// trace("\tnbr_radios: %d\n", p->nbr_radios); +// for (j = 0; j < p->nbr_radios; j++) { +// int k; +// +// trace("\t\tradio_id: " MACFMT "\n", +// MAC2STR(p->radio_data[j].radio_id)); +// trace("\t\tnbr_cac_types: %d\n", +// p->radio_data[j].nbr_cac_types); +// for (k = 0; k < p->radio_data[j].nbr_cac_types; k++) { +// int l; +// +// trace("\t\t\tcac_method_supported: 0x%02x\n", +// p->radio_data[j].cac_data[k].cac_method_supported); +// trace("\t\t\tduration: %d\n", +// p->radio_data[j].cac_data[k].duration); +// trace("\t\t\tnbr_op_classes: %d\n", +// p->radio_data[j].cac_data[k].nbr_op_classes); +// +// for (l = 0; l < p->radio_data[j].cac_data[k].nbr_op_classes; l++) { +// int m; +// +// trace("\t\t\t\top_class: %d\n", +// p->radio_data[j].cac_data[k].op_class_data[l].op_class); +// trace("\t\t\t\tnbr_ch: %d\n", +// p->radio_data[j].cac_data[k].op_class_data[l].nbr_ch); +// +// for (m = 0; m < p->radio_data[j].cac_data[k].op_class_data[l].nbr_ch; m++) +// trace("\t\t\t\t\tch: %d\n", +// p->radio_data[j].cac_data[k].op_class_data[l].ch[m]); +// } +// } +// trace("\n"); +// } +// break; +// } +// case MAP_TLV_PROFILE2_AP_CAPABILITY: +// { +// struct tlv_profile2_ap_cap *p = +// (struct tlv_profile2_ap_cap *)tlv; +// +// trace("\tbyte_counter: 0x%02x\n", p->byte_counter); +// trace("\tmax_vids: 0x%02x\n", p->max_vids); +// break; +// } +// case MAP_TLV_METRIC_COLLECTION_INTERVAL: +// { +// struct tlv_metric_collection_interval *p = +// (struct tlv_metric_collection_interval *)tlv; +// +// trace("\tcollection_interval: %d ms\n", p->collection_interval); +// break; +// } +// default: +// fprintf(stdout, "unknown TLV in CMDU:|%s|", +// map_stringify_cmdu_type(cmdu->message_type)); +// break; +// } +// trace("\n"); +// } +// return 0; } -int debug_channel_pref_report(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_channel_pref_report(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); - trace("parsing channel pref of |%s:" MACFMT "|\n", cmdu->intf_name, - MAC2STR(cmdu->origin)); - - int i, j, k; - uint8_t *tlv = NULL; - - for (i = 0; i < cmdu->num_tlvs; i++) { - tlv = (uint8_t *) cmdu->tlvs[i]; - trace("CMDU type: %s\n", map_stringify_tlv_type(*tlv)); - switch (*tlv) { - case MAP_TLV_CHANNEL_PREFERENCE: - { - struct tlv_channel_pref *p = - (struct tlv_channel_pref *)tlv; - - trace("\tradio_id: " MACFMT "\n", - MAC2STR(p->radio_id)); - trace("\tch_preference_op_class_nr: %d\n", - p->ch_preference_op_class_nr); - - for (j = 0; j < p->ch_preference_op_class_nr; j++) { - trace("\t\top_class: %d\n", - p->op_class[j].op_class); - trace("\t\top_channel_nr: %d\n", - p->op_class[j].channel_nr); - - for (k = 0; k < p->op_class[j].channel_nr; k++) { - trace("\t\t\tchannel: %d\n", - p->op_class[j].channel_list[k]); - } - trace("\t\tpreference: %d\n", - p->op_class[j].preference); - trace("\t\tpreference_reason: %d\n", - p->op_class[j].preference_reason); - } - break; - } - case MAP_TLV_RADIO_OPERATION_RESTRICTION: - { - struct tlv_radio_oper_restrict *p = - (struct tlv_radio_oper_restrict *)tlv; - - trace("\tradio_id: " MACFMT "\n", - MAC2STR(p->radio_id)); - trace("\top_restricted_op_class_nr: %d\n", - p->op_restricted_op_class_nr); - - for (j = 0; j < p->op_restricted_op_class_nr; j++) { - trace("\t\top_class: %d\n", - p->restricted_op_class[j].op_class); - trace("\t\top_channel_nr: %d\n", - p->restricted_op_class[j].channel_nr); - - for (k = 0; k < p->restricted_op_class[j].channel_nr; k++) { - trace("\t\t\tchannel: %d\n", - p->restricted_op_class[j].restricted_channels[k].channel); - trace("\t\t\tmin_freq_sep: %d\n", - p->restricted_op_class[j].restricted_channels[k].min_freq_sep); - } - } - break; - } - case MAP_TLV_CAC_COMPLETION_REPORT: - { - struct tlv_cac_comp_report *p = - (struct tlv_cac_comp_report *)tlv; - - trace("\tnbr_radios: %d\n", - p->nbr_radios); - - for (j = 0; j < p->nbr_radios; j++) { - trace("\t\tradio_id: " MACFMT "\n", - MAC2STR(p->radio_data[j].radio_id)); - trace("\t\top_class: %d\n", - p->radio_data[j].op_class); - trace("\t\tchannel: %d\n", - p->radio_data[j].ch); - trace("\t\tcompletion_status %d\n", - p->radio_data[j].completion_status); - trace("\t\tnbr_pairs %d\n", - p->radio_data[j].nbr_pairs); - - for (k = 0; k < p->radio_data[j].nbr_pairs; k++) { - trace("\t\t\top_class_detected: %d\n", - p->radio_data[j].pair_data[k].op_class_detected); - trace("\t\t\tch_detected: %d\n", - p->radio_data[j].pair_data[k].ch_detected); - } - } - break; - } - case MAP_TLV_CAC_STATUS_REPORT: - { - struct tlv_cac_status_report *p = - (struct tlv_cac_status_report *)tlv; - - trace("\tnbr_available_ch: %d\n", - p->nbr_available_ch); - - for (j = 0; j < p->nbr_available_ch; j++) { - trace("\t\top_class: %d\n", - p->ch_data[j].op_class); - trace("\t\tchannel: %d\n", - p->ch_data[j].ch); - trace("\t\ttime: %d\n", - p->ch_data[j].time); - } - - trace("\tnbr_pairs_duration: %d\n", - p->nbr_pairs_duration); - - for (j = 0; j < p->nbr_pairs_duration; j++) { - trace("\t\top_class: %d\n", - p->duration_pair_data[j].op_class); - trace("\t\tchannel: %d\n", - p->duration_pair_data[j].ch); - trace("\t\ttime: %d\n", - p->duration_pair_data[j].time); - } - - trace("\tnbr_pairs_coundown: %d\n", - p->nbr_pairs_coundown); - - for (j = 0; j < p->nbr_pairs_coundown; j++) { - trace("\t\top_class: %d\n", - p->count_pair_data[j].op_class); - trace("\t\tchannel: %d\n", - p->count_pair_data[j].ch); - trace("\t\ttime: %d\n", - p->count_pair_data[j].time); - } - break; - } - default: - fprintf(stdout, "unknown TLV in CMDU:|%s|", - map_stringify_cmdu_type(cmdu->message_type)); - break; - } - trace("\n"); - } return 0; +// trace("parsing channel pref of |%s:" MACFMT "|\n", cmdu->intf_name, +// MAC2STR(cmdu->origin)); +// +// int i, j, k; +// uint8_t *tlv = NULL; +// +// for (i = 0; i < cmdu->num_tlvs; i++) { +// tlv = (uint8_t *) cmdu->tlvs[i]; +// trace("CMDU type: %s\n", map_stringify_tlv_type(*tlv)); +// switch (*tlv) { +// case MAP_TLV_CHANNEL_PREFERENCE: +// { +// struct tlv_channel_pref *p = +// (struct tlv_channel_pref *)tlv; +// +// trace("\tradio_id: " MACFMT "\n", +// MAC2STR(p->radio_id)); +// trace("\tch_preference_op_class_nr: %d\n", +// p->ch_preference_op_class_nr); +// +// for (j = 0; j < p->ch_preference_op_class_nr; j++) { +// trace("\t\top_class: %d\n", +// p->op_class[j].op_class); +// trace("\t\top_channel_nr: %d\n", +// p->op_class[j].channel_nr); +// +// for (k = 0; k < p->op_class[j].channel_nr; k++) { +// trace("\t\t\tchannel: %d\n", +// p->op_class[j].channel_list[k]); +// } +// trace("\t\tpreference: %d\n", +// p->op_class[j].preference); +// trace("\t\tpreference_reason: %d\n", +// p->op_class[j].preference_reason); +// } +// break; +// } +// case MAP_TLV_RADIO_OPERATION_RESTRICTION: +// { +// struct tlv_radio_oper_restrict *p = +// (struct tlv_radio_oper_restrict *)tlv; +// +// trace("\tradio_id: " MACFMT "\n", +// MAC2STR(p->radio_id)); +// trace("\top_restricted_op_class_nr: %d\n", +// p->op_restricted_op_class_nr); +// +// for (j = 0; j < p->op_restricted_op_class_nr; j++) { +// trace("\t\top_class: %d\n", +// p->restricted_op_class[j].op_class); +// trace("\t\top_channel_nr: %d\n", +// p->restricted_op_class[j].channel_nr); +// +// for (k = 0; k < p->restricted_op_class[j].channel_nr; k++) { +// trace("\t\t\tchannel: %d\n", +// p->restricted_op_class[j].restricted_channels[k].channel); +// trace("\t\t\tmin_freq_sep: %d\n", +// p->restricted_op_class[j].restricted_channels[k].min_freq_sep); +// } +// } +// break; +// } +// case MAP_TLV_CAC_COMPLETION_REPORT: +// { +// struct tlv_cac_comp_report *p = +// (struct tlv_cac_comp_report *)tlv; +// +// trace("\tnbr_radios: %d\n", +// p->nbr_radios); +// +// for (j = 0; j < p->nbr_radios; j++) { +// trace("\t\tradio_id: " MACFMT "\n", +// MAC2STR(p->radio_data[j].radio_id)); +// trace("\t\top_class: %d\n", +// p->radio_data[j].op_class); +// trace("\t\tchannel: %d\n", +// p->radio_data[j].ch); +// trace("\t\tcompletion_status %d\n", +// p->radio_data[j].completion_status); +// trace("\t\tnbr_pairs %d\n", +// p->radio_data[j].nbr_pairs); +// +// for (k = 0; k < p->radio_data[j].nbr_pairs; k++) { +// trace("\t\t\top_class_detected: %d\n", +// p->radio_data[j].pair_data[k].op_class_detected); +// trace("\t\t\tch_detected: %d\n", +// p->radio_data[j].pair_data[k].ch_detected); +// } +// } +// break; +// } +// case MAP_TLV_CAC_STATUS_REPORT: +// { +// struct tlv_cac_status_report *p = +// (struct tlv_cac_status_report *)tlv; +// +// trace("\tnbr_available_ch: %d\n", +// p->nbr_available_ch); +// +// for (j = 0; j < p->nbr_available_ch; j++) { +// trace("\t\top_class: %d\n", +// p->ch_data[j].op_class); +// trace("\t\tchannel: %d\n", +// p->ch_data[j].ch); +// trace("\t\ttime: %d\n", +// p->ch_data[j].time); +// } +// +// trace("\tnbr_pairs_duration: %d\n", +// p->nbr_pairs_duration); +// +// for (j = 0; j < p->nbr_pairs_duration; j++) { +// trace("\t\top_class: %d\n", +// p->duration_pair_data[j].op_class); +// trace("\t\tchannel: %d\n", +// p->duration_pair_data[j].ch); +// trace("\t\ttime: %d\n", +// p->duration_pair_data[j].time); +// } +// +// trace("\tnbr_pairs_coundown: %d\n", +// p->nbr_pairs_coundown); +// +// for (j = 0; j < p->nbr_pairs_coundown; j++) { +// trace("\t\top_class: %d\n", +// p->count_pair_data[j].op_class); +// trace("\t\tchannel: %d\n", +// p->count_pair_data[j].ch); +// trace("\t\ttime: %d\n", +// p->count_pair_data[j].time); +// } +// break; +// } +// default: +// fprintf(stdout, "unknown TLV in CMDU:|%s|", +// map_stringify_cmdu_type(cmdu->message_type)); +// break; +// } +// trace("\n"); +// } +// return 0; } -int debug_channel_sel_response(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_channel_sel_response(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); - trace("parsing channel selection response of |%s:" MACFMT "|\n", - cmdu->intf_name, - MAC2STR(cmdu->origin)); - - int i; - uint8_t *tlv = NULL; - - for (i = 0; i < cmdu->num_tlvs; i++) { - tlv = (uint8_t *) cmdu->tlvs[i]; - trace("CMDU type: %s\n", map_stringify_tlv_type(*tlv)); - switch (*tlv) { - case MAP_TLV_CHANNEL_SELECTION_RESPONSE: - { - struct tlv_ch_selection_resp *p = - (struct tlv_ch_selection_resp *)tlv; - - trace("\tradio_id: " MACFMT "\n", - MAC2STR(p->radio_id)); - trace("\tresponse_code: %d\n", - p->response_code); - break; - } - default: - fprintf(stdout, "unknown TLV in CMDU:|%s|", - map_stringify_cmdu_type(cmdu->message_type)); - break; - } - trace("\n"); - } return 0; +// trace("parsing channel selection response of |%s:" MACFMT "|\n", +// cmdu->intf_name, +// MAC2STR(cmdu->origin)); +// +// int i; +// uint8_t *tlv = NULL; +// +// for (i = 0; i < cmdu->num_tlvs; i++) { +// tlv = (uint8_t *) cmdu->tlvs[i]; +// trace("CMDU type: %s\n", map_stringify_tlv_type(*tlv)); +// switch (*tlv) { +// case MAP_TLV_CHANNEL_SELECTION_RESPONSE: +// { +// struct tlv_ch_selection_resp *p = +// (struct tlv_ch_selection_resp *)tlv; +// +// trace("\tradio_id: " MACFMT "\n", +// MAC2STR(p->radio_id)); +// trace("\tresponse_code: %d\n", +// p->response_code); +// break; +// } +// default: +// fprintf(stdout, "unknown TLV in CMDU:|%s|", +// map_stringify_cmdu_type(cmdu->message_type)); +// break; +// } +// trace("\n"); +// } +// return 0; } -int debug_oper_channel_report(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_oper_channel_report(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); - trace("parsing operating channel report of |%s:" MACFMT "|\n", - cmdu->intf_name, - MAC2STR(cmdu->origin)); - - int i, j; - uint8_t *tlv = NULL; - - for (i = 0; i < cmdu->num_tlvs; i++) { - tlv = (uint8_t *) cmdu->tlvs[i]; - trace("CMDU type: %s\n", map_stringify_tlv_type(*tlv)); - switch (*tlv) { - case MAP_TLV_OPERATING_CHANNEL_REPORT: - { - struct tlv_oper_ch_report *p = - (struct tlv_oper_ch_report *)tlv; - - trace("\tradio_id: " MACFMT "\n", - MAC2STR(p->radio_id)); - trace("\tch_preference_op_class_nr: %d\n", - p->op_ch_op_class_nr); - for (j = 0; j < p->op_ch_op_class_nr; j++) { - trace("\t\top_class: %d\n", - p->op_ch_op_class[j].op_class); - trace("\t\top_channel: %d\n", - p->op_ch_op_class[j].channel); - } - trace("\tcurr_tx_power: %d\n", - p->curr_tx_power); - break; - } - default: - fprintf(stdout, "unknown TLV in CMDU:|%s|", - map_stringify_cmdu_type(cmdu->message_type)); - break; - } - trace("\n"); - } return 0; +// trace("parsing operating channel report of |%s:" MACFMT "|\n", +// cmdu->intf_name, +// MAC2STR(cmdu->origin)); +// +// int i, j; +// uint8_t *tlv = NULL; +// +// for (i = 0; i < cmdu->num_tlvs; i++) { +// tlv = (uint8_t *) cmdu->tlvs[i]; +// trace("CMDU type: %s\n", map_stringify_tlv_type(*tlv)); +// switch (*tlv) { +// case MAP_TLV_OPERATING_CHANNEL_REPORT: +// { +// struct tlv_oper_ch_report *p = +// (struct tlv_oper_ch_report *)tlv; +// +// trace("\tradio_id: " MACFMT "\n", +// MAC2STR(p->radio_id)); +// trace("\tch_preference_op_class_nr: %d\n", +// p->op_ch_op_class_nr); +// for (j = 0; j < p->op_ch_op_class_nr; j++) { +// trace("\t\top_class: %d\n", +// p->op_ch_op_class[j].op_class); +// trace("\t\top_channel: %d\n", +// p->op_ch_op_class[j].channel); +// } +// trace("\tcurr_tx_power: %d\n", +// p->curr_tx_power); +// break; +// } +// default: +// fprintf(stdout, "unknown TLV in CMDU:|%s|", +// map_stringify_cmdu_type(cmdu->message_type)); +// break; +// } +// trace("\n"); +// } +// return 0; } -int debug_sta_caps_report(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_sta_caps_report(void *cntlr, struct cmdu_buff *cmdu) { - int i; - uint8_t *tlv = NULL; - - trace("%s: --->\n", __func__); - trace("parsing AP capabilities of |%s:" MACFMT "|\n", - cmdu->intf_name, MAC2STR(cmdu->origin)); - - for (i = 0; i < cmdu->num_tlvs; i++) { - tlv = cmdu->tlvs[i]; - trace("\nCMDU type: %s\n", map_stringify_tlv_type(*tlv)); - switch (*tlv) { - case MAP_TLV_CLIENT_INFO: - { - struct tlv_client_info *p = - (struct tlv_client_info *)tlv; - - trace("\tbssid: " MACFMT "\n", - MAC2STR(p->bssid)); - trace("\tclient_addr: " MACFMT "\n", - MAC2STR(p->client_addr)); - break; - } - case MAP_TLV_CLIENT_CAPABILITY_REPORT: - { - struct tlv_client_cap_report *p = - (struct tlv_client_cap_report *)tlv; - char *frame; - int offset = 1 + 2 + 1; - - trace("\tresult_code: 0x%02x\n", p->result_code); - - /* if tlv is shorter or equal to the offset len, - * then no frame is passed - */ - if (p->tlv_len <= offset) - break; - - frame = calloc(1, - (2 * (p->tlv_len - offset)) + 1); - if (!frame) - break; - - btostr(p->frame_body + offset, - p->tlv_len - offset, frame); - - trace("\tframe: 0x%s\n", frame); - break; - } - case MAP_TLV_ERROR_CODE: - { - struct tlv_error_code *p = - (struct tlv_error_code *)tlv; - - trace("\treason_code: 0x%02x\n", p->reason_code); - if (p->reason_code == 0x02) - trace("\tclient_addr: " MACFMT "\n", - MAC2STR(p->addr)); - - break; - } - default: - fprintf(stdout, "unknown TLV in CMDU:|%s|", - map_stringify_cmdu_type(cmdu->message_type)); - break; - } - trace("\n"); - } - return 0; +// int i; +// uint8_t *tlv = NULL; +// +// trace("%s: --->\n", __func__); +// trace("parsing AP capabilities of |%s:" MACFMT "|\n", +// cmdu->intf_name, MAC2STR(cmdu->origin)); +// +// for (i = 0; i < cmdu->num_tlvs; i++) { +// tlv = cmdu->tlvs[i]; +// trace("\nCMDU type: %s\n", map_stringify_tlv_type(*tlv)); +// switch (*tlv) { +// case MAP_TLV_CLIENT_INFO: +// { +// struct tlv_client_info *p = +// (struct tlv_client_info *)tlv; +// +// trace("\tbssid: " MACFMT "\n", +// MAC2STR(p->bssid)); +// trace("\tclient_addr: " MACFMT "\n", +// MAC2STR(p->client_addr)); +// break; +// } +// case MAP_TLV_CLIENT_CAPABILITY_REPORT: +// { +// struct tlv_client_cap_report *p = +// (struct tlv_client_cap_report *)tlv; +// char *frame; +// int offset = 1 + 2 + 1; +// +// trace("\tresult_code: 0x%02x\n", p->result_code); +// +// /* if tlv is shorter or equal to the offset len, +// * then no frame is passed +// */ +// if (p->tlv_len <= offset) +// break; +// +// frame = calloc(1, +// (2 * (p->tlv_len - offset)) + 1); +// if (!frame) +// break; +// +// btostr(p->frame_body + offset, +// p->tlv_len - offset, frame); +// +// trace("\tframe: 0x%s\n", frame); +// break; +// } +// case MAP_TLV_ERROR_CODE: +// { +// struct tlv_error_code *p = +// (struct tlv_error_code *)tlv; +// +// trace("\treason_code: 0x%02x\n", p->reason_code); +// if (p->reason_code == 0x02) +// trace("\tclient_addr: " MACFMT "\n", +// MAC2STR(p->addr)); +// +// break; +// } +// default: +// fprintf(stdout, "unknown TLV in CMDU:|%s|", +// map_stringify_cmdu_type(cmdu->message_type)); +// break; +// } +// trace("\n"); +// } +// +// return 0; } -int debug_ap_metrics_response(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_ap_metrics_response(void *cntlr, struct cmdu_buff *cmdu) { - int i, j; - uint8_t *tlv; - - trace("%s: --->\n", __func__); - trace("parsing ap metric response |" MACFMT "|CMDU: %s\n", - MAC2STR(cmdu->origin), - map_stringify_cmdu_type(cmdu->message_type)); - - for (i = 0; i < cmdu->num_tlvs; i++) { - tlv = (uint8_t *)cmdu->tlvs[i]; - trace("TLV: %s\n", map_stringify_tlv_type(*tlv)); - switch (*tlv) { - case MAP_TLV_RADIO_METRICS: - { - struct tlv_radio_metrics *p = - (struct tlv_radio_metrics *)tlv; - - trace("\tradio_id: " MACFMT "\n", MAC2STR(p->radio_id)); - trace("\tnoise: %d\n", p->noise); - trace("\ttransmit: %d\n", p->transmit); - trace("\treceive_self: %d\n", p->receive_self); - trace("\treceive_other: %d\n", p->receive_other); - break; - } - case MAP_TLV_AP_METRICS: - { - size_t out_len; - unsigned char est_str[16]; - struct tlv_ap_metrics *p = (struct tlv_ap_metrics *)tlv; - - trace("\tbssid: " MACFMT "\n", MAC2STR(p->bssid)); - trace("\tchannel_utilization: %d\n", - p->channel_utilization); - trace("\ttotal_assoc_stas: %d\n", - p->total_assoc_stas); - trace("\tis_ac_be: %d\n", p->is_ac_be); - trace("\tis_ac_bk: %d\n", p->is_ac_bk); - trace("\tis_ac_vo: %d\n", p->is_ac_vo); - trace("\tis_ac_vi: %d\n", p->is_ac_vi); - if (p->is_ac_be) { - out_len = sizeof(est_str); - memset(est_str, 0, sizeof(est_str)); - base64_encode(p->service_param_info_be, 3, est_str, &out_len); - trace("\tservice_param_info_be:%s\n", (char *)est_str); - } - if (p->is_ac_bk) { - out_len = sizeof(est_str); - memset(est_str, 0, sizeof(est_str)); - base64_encode(p->service_param_info_bk, 3, est_str, &out_len); - trace("\tservice_param_info_bk:%s\n", (char *)est_str); - } - if (p->is_ac_vo) { - out_len = sizeof(est_str); - memset(est_str, 0, sizeof(est_str)); - base64_encode(p->service_param_info_vo, 3, est_str, &out_len); - trace("\tservice_param_info_vo:%s\n", (char *)est_str); - } - if (p->is_ac_vi) { - out_len = sizeof(est_str); - memset(est_str, 0, sizeof(est_str)); - base64_encode(p->service_param_info_vi, 3, est_str, &out_len); - trace("\tservice_param_info_vi:%s\n", (char *)est_str); - } - break; - } - case MAP_TLV_AP_EXTENDED_METRICS: - { - struct tlv_ap_ext_metrics *p = (struct tlv_ap_ext_metrics *)tlv; - - trace("\tbssid: " MACFMT "\n", MAC2STR(p->bssid)); - trace("\tuni_bytes_sent: %lu\n", p->uni_bytes_sent); - trace("\tuni_bytes_recv: %lu\n", p->uni_bytes_recv); - trace("\tmulti_bytes_sent: %lu\n", p->multi_bytes_sent); - trace("\tmulti_bytes_recv: %lu\n", p->multi_bytes_recv); - trace("\tbro_bytes_sent: %lu\n", p->bro_bytes_sent); - trace("\tbro_bytes_recv: %lu\n", p->bro_bytes_recv); - break; - } - case MAP_TLV_ASSOCIATED_STA_TRAFFIC_STATS: - { - struct tlv_assoc_sta_traffic_stats *p = - (struct tlv_assoc_sta_traffic_stats *)tlv; - - trace("\tsta: " MACFMT "\n", MAC2STR(p->addr)); - trace("\tbytes_sent: %lu\n", p->bytes_sent); - trace("\tbytes_received: %lu", p->bytes_received); - trace("\tpackets_sent: %lu\n", p->packets_sent); - trace("\tpackets_received: %lu\n", p->packets_received); - trace("\ttx_packets_err: %lu\n", p->tx_packets_err); - trace("\trx_packets_err: %lu\n", p->rx_packets_err); - trace("\tretransmission_cnt: %lu\n", p->retransmission_cnt); - break; - } - case MAP_TLV_ASSOCIATED_STA_LINK_METRICS: - { - struct tlv_assoc_sta_link_metrics *p = - (struct tlv_assoc_sta_link_metrics *)tlv; - - trace("\tsta: " MACFMT "\n", MAC2STR(p->addr)); - trace("\tbssid_nr: %d\n", p->bssid_nr); - for (j = 0; j < p->bssid_nr; j++) { - trace("\t\tbssid: " MACFMT "\n", - MAC2STR(p->sta_link_metrics_bssid[j].bssid)); - trace("\t\ttime_delta: %lu\n", - p->sta_link_metrics_bssid[j].time_delta); - trace("\t\tdl_mac_data_rate: %lu\n", - p->sta_link_metrics_bssid[j].dl_mac_data_rate); - trace("\t\tul_mac_data_rate: %lu\n", - p->sta_link_metrics_bssid[j].ul_mac_data_rate); - trace("\t\tul_rcpi: %d\n", - p->sta_link_metrics_bssid[j].ul_rcpi); - } - break; - } - case MAP_TLV_ASSOCIATED_STA_EXT_LINK_METRICS: - { - struct tlv_assoc_sta_ext_link_metric *p = - (struct tlv_assoc_sta_ext_link_metric *)tlv; - - trace("\tsta: " MACFMT "\n", MAC2STR(p->mac)); - trace("\tnbr_bssid: %d\n", p->nbr_bssid); - for (j = 0; j < p->nbr_bssid; j++) { - trace("\t\tbssid: " MACFMT "\n", - MAC2STR(p->data[j].bssid)); - trace("\t\tlast_data_dwn_rate: %lu\n", - p->data[j].last_data_dwn_rate); - trace("\t\tlast_data_up_rate: %lu\n", - p->data[j].last_data_up_rate); - trace("\t\tuti_recv: %lu\n", - p->data[j].uti_recv); - trace("\t\tuti_transmit: %lu\n", - p->data[j].uti_transmit); - } - break; - } - default: - { - trace("unknown TLV\n"); - break; - } - } - } return 0; +// int i, j; +// uint8_t *tlv; +// +// trace("%s: --->\n", __func__); +// trace("parsing ap metric response |" MACFMT "|CMDU: %s\n", +// MAC2STR(cmdu->origin), +// map_stringify_cmdu_type(cmdu->message_type)); +// +// for (i = 0; i < cmdu->num_tlvs; i++) { +// tlv = (uint8_t *)cmdu->tlvs[i]; +// trace("TLV: %s\n", map_stringify_tlv_type(*tlv)); +// switch (*tlv) { +// case MAP_TLV_RADIO_METRICS: +// { +// struct tlv_radio_metrics *p = +// (struct tlv_radio_metrics *)tlv; +// +// trace("\tradio_id: " MACFMT "\n", MAC2STR(p->radio_id)); +// trace("\tnoise: %d\n", p->noise); +// trace("\ttransmit: %d\n", p->transmit); +// trace("\treceive_self: %d\n", p->receive_self); +// trace("\treceive_other: %d\n", p->receive_other); +// break; +// } +// case MAP_TLV_AP_METRICS: +// { +// size_t out_len; +// unsigned char est_str[16]; +// struct tlv_ap_metrics *p = (struct tlv_ap_metrics *)tlv; +// +// trace("\tbssid: " MACFMT "\n", MAC2STR(p->bssid)); +// trace("\tchannel_utilization: %d\n", +// p->channel_utilization); +// trace("\ttotal_assoc_stas: %d\n", +// p->total_assoc_stas); +// trace("\tis_ac_be: %d\n", p->is_ac_be); +// trace("\tis_ac_bk: %d\n", p->is_ac_bk); +// trace("\tis_ac_vo: %d\n", p->is_ac_vo); +// trace("\tis_ac_vi: %d\n", p->is_ac_vi); +// if (p->is_ac_be) { +// out_len = sizeof(est_str); +// memset(est_str, 0, sizeof(est_str)); +// base64_encode(p->service_param_info_be, 3, est_str, &out_len); +// trace("\tservice_param_info_be:%s\n", (char *)est_str); +// } +// if (p->is_ac_bk) { +// out_len = sizeof(est_str); +// memset(est_str, 0, sizeof(est_str)); +// base64_encode(p->service_param_info_bk, 3, est_str, &out_len); +// trace("\tservice_param_info_bk:%s\n", (char *)est_str); +// } +// if (p->is_ac_vo) { +// out_len = sizeof(est_str); +// memset(est_str, 0, sizeof(est_str)); +// base64_encode(p->service_param_info_vo, 3, est_str, &out_len); +// trace("\tservice_param_info_vo:%s\n", (char *)est_str); +// } +// if (p->is_ac_vi) { +// out_len = sizeof(est_str); +// memset(est_str, 0, sizeof(est_str)); +// base64_encode(p->service_param_info_vi, 3, est_str, &out_len); +// trace("\tservice_param_info_vi:%s\n", (char *)est_str); +// } +// break; +// } +// case MAP_TLV_AP_EXTENDED_METRICS: +// { +// struct tlv_ap_ext_metrics *p = (struct tlv_ap_ext_metrics *)tlv; +// +// trace("\tbssid: " MACFMT "\n", MAC2STR(p->bssid)); +// trace("\tuni_bytes_sent: %lu\n", p->uni_bytes_sent); +// trace("\tuni_bytes_recv: %lu\n", p->uni_bytes_recv); +// trace("\tmulti_bytes_sent: %lu\n", p->multi_bytes_sent); +// trace("\tmulti_bytes_recv: %lu\n", p->multi_bytes_recv); +// trace("\tbro_bytes_sent: %lu\n", p->bro_bytes_sent); +// trace("\tbro_bytes_recv: %lu\n", p->bro_bytes_recv); +// break; +// } +// case MAP_TLV_ASSOCIATED_STA_TRAFFIC_STATS: +// { +// struct tlv_assoc_sta_traffic_stats *p = +// (struct tlv_assoc_sta_traffic_stats *)tlv; +// +// trace("\tsta: " MACFMT "\n", MAC2STR(p->addr)); +// trace("\tbytes_sent: %lu\n", p->bytes_sent); +// trace("\tbytes_received: %lu", p->bytes_received); +// trace("\tpackets_sent: %lu\n", p->packets_sent); +// trace("\tpackets_received: %lu\n", p->packets_received); +// trace("\ttx_packets_err: %lu\n", p->tx_packets_err); +// trace("\trx_packets_err: %lu\n", p->rx_packets_err); +// trace("\tretransmission_cnt: %lu\n", p->retransmission_cnt); +// break; +// } +// case MAP_TLV_ASSOCIATED_STA_LINK_METRICS: +// { +// struct tlv_assoc_sta_link_metrics *p = +// (struct tlv_assoc_sta_link_metrics *)tlv; +// +// trace("\tsta: " MACFMT "\n", MAC2STR(p->addr)); +// trace("\tbssid_nr: %d\n", p->bssid_nr); +// for (j = 0; j < p->bssid_nr; j++) { +// trace("\t\tbssid: " MACFMT "\n", +// MAC2STR(p->sta_link_metrics_bssid[j].bssid)); +// trace("\t\ttime_delta: %lu\n", +// p->sta_link_metrics_bssid[j].time_delta); +// trace("\t\tdl_mac_data_rate: %lu\n", +// p->sta_link_metrics_bssid[j].dl_mac_data_rate); +// trace("\t\tul_mac_data_rate: %lu\n", +// p->sta_link_metrics_bssid[j].ul_mac_data_rate); +// trace("\t\tul_rcpi: %d\n", +// p->sta_link_metrics_bssid[j].ul_rcpi); +// } +// break; +// } +// case MAP_TLV_ASSOCIATED_STA_EXT_LINK_METRICS: +// { +// struct tlv_assoc_sta_ext_link_metric *p = +// (struct tlv_assoc_sta_ext_link_metric *)tlv; +// +// trace("\tsta: " MACFMT "\n", MAC2STR(p->mac)); +// trace("\tnbr_bssid: %d\n", p->nbr_bssid); +// for (j = 0; j < p->nbr_bssid; j++) { +// trace("\t\tbssid: " MACFMT "\n", +// MAC2STR(p->data[j].bssid)); +// trace("\t\tlast_data_dwn_rate: %lu\n", +// p->data[j].last_data_dwn_rate); +// trace("\t\tlast_data_up_rate: %lu\n", +// p->data[j].last_data_up_rate); +// trace("\t\tuti_recv: %lu\n", +// p->data[j].uti_recv); +// trace("\t\tuti_transmit: %lu\n", +// p->data[j].uti_transmit); +// } +// break; +// } +// default: +// { +// trace("unknown TLV\n"); +// break; +// } +// } +// } +// return 0; } -int debug_sta_link_metrics_response(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_sta_link_metrics_response(void *cntlr, struct cmdu_buff *cmdu) { - int i, j; - uint8_t *tlv; - - trace("%s: --->\n", __func__); - trace("parsing sta link metric response |" MACFMT "|CMDU: %s\n", - MAC2STR(cmdu->origin), - map_stringify_cmdu_type(cmdu->message_type)); - - for (i = 0; i < cmdu->num_tlvs; i++) { - tlv = (uint8_t *)cmdu->tlvs[i]; - trace("TLV: %s\n", map_stringify_tlv_type(*tlv)); - switch (*tlv) { - case MAP_TLV_ASSOCIATED_STA_LINK_METRICS: - { - struct tlv_assoc_sta_link_metrics *p = - (struct tlv_assoc_sta_link_metrics *)tlv; - - trace("\tsta: " MACFMT "\n", MAC2STR(p->addr)); - trace("\tbssid_nr: %d\n", p->bssid_nr); - for (j = 0; j < p->bssid_nr; j++) { - trace("\t\tbssid: " MACFMT "\n", - MAC2STR(p->sta_link_metrics_bssid[j].bssid)); - trace("\t\ttime_delta: %lu\n", - p->sta_link_metrics_bssid[j].time_delta); - trace("\t\tdl_mac_data_rate: %lu\n", - p->sta_link_metrics_bssid[j].dl_mac_data_rate); - trace("\t\tul_mac_data_rate: %lu\n", - p->sta_link_metrics_bssid[j].ul_mac_data_rate); - trace("\t\tul_rcpi: %d\n", - p->sta_link_metrics_bssid[j].ul_rcpi); - } - break; - } - case MAP_TLV_ASSOCIATED_STA_EXT_LINK_METRICS: - { - struct tlv_assoc_sta_ext_link_metric *p = - (struct tlv_assoc_sta_ext_link_metric *)tlv; - - trace("\tsta: " MACFMT "\n", MAC2STR(p->mac)); - trace("\tnbr_bssid: %d\n", p->nbr_bssid); - for (j = 0; j < p->nbr_bssid; j++) { - trace("\t\tbssid: " MACFMT "\n", - MAC2STR(p->data[j].bssid)); - trace("\t\tlast_data_dwn_rate: %lu\n", - p->data[j].last_data_dwn_rate); - trace("\t\tlast_data_up_rate: %lu\n", - p->data[j].last_data_up_rate); - trace("\t\tuti_recv: %lu\n", - p->data[j].uti_recv); - trace("\t\tuti_transmit: %lu\n", - p->data[j].uti_transmit); - } - break; - } - case MAP_TLV_ERROR_CODE: - { - struct tlv_error_code *p = - (struct tlv_error_code *)tlv; - - trace("\treason_code: %d\n", p->reason_code); - trace("\taddr: " MACFMT "\n", MAC2STR(p->addr)); - break; - } - default: - { - trace("unknown TLV\n"); - break; - } - } - } - return 0; +// int i, j; +// uint8_t *tlv; +// +// trace("%s: --->\n", __func__); +// trace("parsing sta link metric response |" MACFMT "|CMDU: %s\n", +// MAC2STR(cmdu->origin), +// map_stringify_cmdu_type(cmdu->message_type)); +// +// for (i = 0; i < cmdu->num_tlvs; i++) { +// tlv = (uint8_t *)cmdu->tlvs[i]; +// trace("TLV: %s\n", map_stringify_tlv_type(*tlv)); +// switch (*tlv) { +// case MAP_TLV_ASSOCIATED_STA_LINK_METRICS: +// { +// struct tlv_assoc_sta_link_metrics *p = +// (struct tlv_assoc_sta_link_metrics *)tlv; +// +// trace("\tsta: " MACFMT "\n", MAC2STR(p->addr)); +// trace("\tbssid_nr: %d\n", p->bssid_nr); +// for (j = 0; j < p->bssid_nr; j++) { +// trace("\t\tbssid: " MACFMT "\n", +// MAC2STR(p->sta_link_metrics_bssid[j].bssid)); +// trace("\t\ttime_delta: %lu\n", +// p->sta_link_metrics_bssid[j].time_delta); +// trace("\t\tdl_mac_data_rate: %lu\n", +// p->sta_link_metrics_bssid[j].dl_mac_data_rate); +// trace("\t\tul_mac_data_rate: %lu\n", +// p->sta_link_metrics_bssid[j].ul_mac_data_rate); +// trace("\t\tul_rcpi: %d\n", +// p->sta_link_metrics_bssid[j].ul_rcpi); +// } +// break; +// } +// case MAP_TLV_ASSOCIATED_STA_EXT_LINK_METRICS: +// { +// struct tlv_assoc_sta_ext_link_metric *p = +// (struct tlv_assoc_sta_ext_link_metric *)tlv; +// +// trace("\tsta: " MACFMT "\n", MAC2STR(p->mac)); +// trace("\tnbr_bssid: %d\n", p->nbr_bssid); +// for (j = 0; j < p->nbr_bssid; j++) { +// trace("\t\tbssid: " MACFMT "\n", +// MAC2STR(p->data[j].bssid)); +// trace("\t\tlast_data_dwn_rate: %lu\n", +// p->data[j].last_data_dwn_rate); +// trace("\t\tlast_data_up_rate: %lu\n", +// p->data[j].last_data_up_rate); +// trace("\t\tuti_recv: %lu\n", +// p->data[j].uti_recv); +// trace("\t\tuti_transmit: %lu\n", +// p->data[j].uti_transmit); +// } +// break; +// } +// case MAP_TLV_ERROR_CODE: +// { +// struct tlv_error_code *p = +// (struct tlv_error_code *)tlv; +// +// trace("\treason_code: %d\n", p->reason_code); +// trace("\taddr: " MACFMT "\n", MAC2STR(p->addr)); +// break; +// } +// default: +// { +// trace("unknown TLV\n"); +// break; +// } +// } +// } +// +// return 0; } int debug_unassoc_sta_link_metrics_response(void *cntlr, - struct cmdu_cstruct *cmdu) + struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int debug_beacon_metrics_response(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_beacon_metrics_response(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int debug_sta_steer_btm_report(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_sta_steer_btm_report(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); - trace("parsing steer btm report of |%s:" MACFMT "|\n", - cmdu->intf_name, MAC2STR(cmdu->origin)); - - int i, j; - uint8_t *tlv = NULL; - - for (i = 0; i < cmdu->num_tlvs; i++) { - tlv = (uint8_t *) cmdu->tlvs[i]; - trace("CMDU type: %s\n", map_stringify_tlv_type(*tlv)); - switch (*tlv) { - case MAP_TLV_STEERING_BTM_REPORT: - { - struct tlv_steer_btm_report *p = - (struct tlv_steer_btm_report *)tlv; - - trace("\tbssid: " MACFMT "\n", - MAC2STR(p->bssid)); - trace("\tsta_macaddr: " MACFMT "\n", - MAC2STR(p->sta_mac_addr)); - trace("\tstatus_code: %d\n", - p->status_code); - if (p->status_code == 0x00) - trace("\ttarget_bbsid: " MACFMT "\n", - MAC2STR(p->target_bssid)); - break; - } - default: - fprintf(stdout, "unknown TLV in CMDU:|%s|", - map_stringify_cmdu_type(cmdu->message_type)); - break; - } - trace("\n"); - } return 0; +// trace("parsing steer btm report of |%s:" MACFMT "|\n", +// cmdu->intf_name, MAC2STR(cmdu->origin)); +// +// int i, j; +// uint8_t *tlv = NULL; +// +// for (i = 0; i < cmdu->num_tlvs; i++) { +// tlv = (uint8_t *) cmdu->tlvs[i]; +// trace("CMDU type: %s\n", map_stringify_tlv_type(*tlv)); +// switch (*tlv) { +// case MAP_TLV_STEERING_BTM_REPORT: +// { +// struct tlv_steer_btm_report *p = +// (struct tlv_steer_btm_report *)tlv; +// +// trace("\tbssid: " MACFMT "\n", +// MAC2STR(p->bssid)); +// trace("\tsta_macaddr: " MACFMT "\n", +// MAC2STR(p->sta_mac_addr)); +// trace("\tstatus_code: %d\n", +// p->status_code); +// if (p->status_code == 0x00) +// trace("\ttarget_bbsid: " MACFMT "\n", +// MAC2STR(p->target_bssid)); +// break; +// } +// default: +// fprintf(stdout, "unknown TLV in CMDU:|%s|", +// map_stringify_cmdu_type(cmdu->message_type)); +// break; +// } +// trace("\n"); +// } +// return 0; } -int debug_sta_steer_complete(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_sta_steer_complete(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); - trace("parsing sta steer complete of |%s:" MACFMT "|\n", - cmdu->intf_name, MAC2STR(cmdu->origin)); +// trace("parsing sta steer complete of |%s:" MACFMT "|\n", +// cmdu->intf_name, MAC2STR(cmdu->origin)); return 0; } -int debug_backhaul_sta_steer_response(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_backhaul_sta_steer_response(void *cntlr, struct cmdu_buff *cmdu) { - int i; - uint8_t *tlv = NULL; - - trace("%s: --->\n", __func__); - trace("parsing backhaul sta steer response of |%s:" MACFMT "|\n", - cmdu->intf_name, MAC2STR(cmdu->origin)); - - for (i = 0; i < cmdu->num_tlvs; i++) { - tlv = cmdu->tlvs[i]; - trace("CMDU type: %s\n", map_stringify_tlv_type(*tlv)); - switch (*tlv) { - case MAP_TLV_BACKHAUL_STEERING_RESPONSE: - { - struct tlv_backhaul_steer_resp *p = - (struct tlv_backhaul_steer_resp *)tlv; - - trace("\tbssid: " MACFMT "\n", - MAC2STR(p->bssid)); - trace("\taddr: " MACFMT "\n", - MAC2STR(p->addr)); - - trace("\tres_code: 0x%02x\n", p->res_code); - - break; - } - case MAP_TLV_ERROR_CODE: - { - struct tlv_error_code *p = - (struct tlv_error_code *)tlv; - - trace("\treason_code: 0x%02x\n", p->reason_code); - break; - } - default: - fprintf(stdout, "unknown TLV in CMDU:|%s|", - map_stringify_cmdu_type(cmdu->message_type)); - break; - } - trace("\n"); - } - return 0; +// int i; +// uint8_t *tlv = NULL; +// +// trace("%s: --->\n", __func__); +// trace("parsing backhaul sta steer response of |%s:" MACFMT "|\n", +// cmdu->intf_name, MAC2STR(cmdu->origin)); +// +// for (i = 0; i < cmdu->num_tlvs; i++) { +// tlv = cmdu->tlvs[i]; +// trace("CMDU type: %s\n", map_stringify_tlv_type(*tlv)); +// switch (*tlv) { +// case MAP_TLV_BACKHAUL_STEERING_RESPONSE: +// { +// struct tlv_backhaul_steer_resp *p = +// (struct tlv_backhaul_steer_resp *)tlv; +// +// trace("\tbssid: " MACFMT "\n", +// MAC2STR(p->bssid)); +// trace("\taddr: " MACFMT "\n", +// MAC2STR(p->addr)); +// +// trace("\tres_code: 0x%02x\n", p->res_code); +// +// break; +// } +// case MAP_TLV_ERROR_CODE: +// { +// struct tlv_error_code *p = +// (struct tlv_error_code *)tlv; +// +// trace("\treason_code: 0x%02x\n", p->reason_code); +// break; +// } +// default: +// fprintf(stdout, "unknown TLV in CMDU:|%s|", +// map_stringify_cmdu_type(cmdu->message_type)); +// break; +// } +// trace("\n"); +// } +// +// return 0; } -int debug_channel_scan_report(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_channel_scan_report(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); - trace("parsing channel scan report of |%s:" MACFMT "|\n", cmdu->intf_name, - MAC2STR(cmdu->origin)); - int i, j; - uint8_t *tlv = NULL; - - for (i = 0; i < cmdu->num_tlvs; i++) { - tlv = (uint8_t *) cmdu->tlvs[i]; - trace("\nCMDU type: %s\n", map_stringify_tlv_type(*tlv)); - switch (*tlv) { - case MAP_TLV_TIMESTAMP: - { - struct tlv_timestamp *p = - (struct tlv_timestamp *)tlv; - trace("\ttime_len: %d\n", p->time_len); - trace("\ttime: %s\n", p->time); - break; - } - case MAP_TLV_CHANNEL_SCAN_RES: - { - struct tlv_ch_scan_res *p1 = - (struct tlv_ch_scan_res *)tlv; - trace("\tradio_id: " MACFMT "\n", MAC2STR(p1->radio_id)); - trace("\top_class: %d\n", p1->op_class); - trace("\tch: %d\n", p1->ch); - trace("\tscan_res: 0x%02x\n", p1->scan_res); - if (p1->scan_res == 0x00) { - trace("\ttime_len: %d\n", p1->time_len); - if (!p1->timestamp) - trace("\ttimestamp: %s\n", p1->timestamp); - trace("\tutilization: %d\n", p1->utilization); - trace("\tnoise: %d\n", p1->noise); - trace("\tnbr_neighbor: %d\n", p1->nbr_neighbors); - for (j = 0; j < p1->nbr_neighbors; j++) { - trace("\n\t\tbssid: " MACFMT "\n", MAC2STR(p1->neighbor_data[j].bssid)); - trace("\t\tssid: %s\n", p1->neighbor_data[j].ssid); - trace("\t\tssid_len: %d\n", p1->neighbor_data[j].ssid_len); - trace("\t\tsignal_strength: %d\n", (signed char)p1->neighbor_data[j].signal_strength); - trace("\t\tbss_load_elm_present: %d\n", p1->neighbor_data[j].bss_load_elm_present); - } - } - break; - } - default: - fprintf(stdout, "unknown TLV in CMDU:|%s|", map_stringify_cmdu_type(cmdu->message_type)); - break; - } - trace("\n"); - } return 0; +// trace("parsing channel scan report of |%s:" MACFMT "|\n", cmdu->intf_name, +// MAC2STR(cmdu->origin)); +// int i, j; +// uint8_t *tlv = NULL; +// +// for (i = 0; i < cmdu->num_tlvs; i++) { +// tlv = (uint8_t *) cmdu->tlvs[i]; +// trace("\nCMDU type: %s\n", map_stringify_tlv_type(*tlv)); +// switch (*tlv) { +// case MAP_TLV_TIMESTAMP: +// { +// struct tlv_timestamp *p = +// (struct tlv_timestamp *)tlv; +// trace("\ttime_len: %d\n", p->time_len); +// trace("\ttime: %s\n", p->time); +// break; +// } +// case MAP_TLV_CHANNEL_SCAN_RES: +// { +// struct tlv_ch_scan_res *p1 = +// (struct tlv_ch_scan_res *)tlv; +// trace("\tradio_id: " MACFMT "\n", MAC2STR(p1->radio_id)); +// trace("\top_class: %d\n", p1->op_class); +// trace("\tch: %d\n", p1->ch); +// trace("\tscan_res: 0x%02x\n", p1->scan_res); +// if (p1->scan_res == 0x00) { +// trace("\ttime_len: %d\n", p1->time_len); +// if (!p1->timestamp) +// trace("\ttimestamp: %s\n", p1->timestamp); +// trace("\tutilization: %d\n", p1->utilization); +// trace("\tnoise: %d\n", p1->noise); +// trace("\tnbr_neighbor: %d\n", p1->nbr_neighbors); +// for (j = 0; j < p1->nbr_neighbors; j++) { +// trace("\n\t\tbssid: " MACFMT "\n", MAC2STR(p1->neighbor_data[j].bssid)); +// trace("\t\tssid: %s\n", p1->neighbor_data[j].ssid); +// trace("\t\tssid_len: %d\n", p1->neighbor_data[j].ssid_len); +// trace("\t\tsignal_strength: %d\n", (signed char)p1->neighbor_data[j].signal_strength); +// trace("\t\tbss_load_elm_present: %d\n", p1->neighbor_data[j].bss_load_elm_present); +// } +// } +// break; +// } +// default: +// fprintf(stdout, "unknown TLV in CMDU:|%s|", map_stringify_cmdu_type(cmdu->message_type)); +// break; +// } +// trace("\n"); +// } +// +// return 0; } -int debug_sta_disassoc_stats(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_sta_disassoc_stats(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); - uint8_t *tlv = NULL; - int i; - - for (i = 0; i < cmdu->num_tlvs; i++) { - tlv = (uint8_t *) cmdu->tlvs[i]; - trace("\nCMDU type: %s\n", map_stringify_tlv_type(*tlv)); - switch (*tlv) { - case MAP_TLV_STA_MAC_ADDRESS: - { - struct tlv_sta_mac *p = - (struct tlv_sta_mac *)tlv; - trace("\taddr: " MACFMT "\n", MAC2STR(p->addr)); - break; - } - case MAP_TLV_REASON_CODE: - { - struct tlv_reason_code *p2 = - (struct tlv_reason_code *)tlv; - trace("\treason_code: %d\n", p2->reason_code); - break; - } - case MAP_TLV_ASSOCIATED_STA_TRAFFIC_STATS: - { - struct tlv_assoc_sta_traffic_stats *p1 = - (struct tlv_assoc_sta_traffic_stats *)tlv; - trace("\taddr: " MACFMT "\n", MAC2STR(p1->addr)); - trace("\tbytes_sent: %d\n", p1->bytes_sent); - trace("\tbytes_received: %d\n", p1->bytes_received); - trace("\tpackets_sent: %d\n", p1->packets_sent); - trace("\tpackets_received: %d\n", p1->packets_received); - trace("\ttx_packets_err: %d\n", p1->tx_packets_err); - trace("\trx_packets_err: %d\n", p1->rx_packets_err); - trace("\tretransmission_cnt: %d\n", p1->retransmission_cnt); - break; - } - default: - fprintf(stdout, "unknown TLV in CMDU:|%s|", map_stringify_cmdu_type(cmdu->message_type)); - break; - } - trace("\n"); - } return 0; +// uint8_t *tlv = NULL; +// int i; +// +// for (i = 0; i < cmdu->num_tlvs; i++) { +// tlv = (uint8_t *) cmdu->tlvs[i]; +// trace("\nCMDU type: %s\n", map_stringify_tlv_type(*tlv)); +// switch (*tlv) { +// case MAP_TLV_STA_MAC_ADDRESS: +// { +// struct tlv_sta_mac *p = +// (struct tlv_sta_mac *)tlv; +// trace("\taddr: " MACFMT "\n", MAC2STR(p->addr)); +// break; +// } +// case MAP_TLV_REASON_CODE: +// { +// struct tlv_reason_code *p2 = +// (struct tlv_reason_code *)tlv; +// trace("\treason_code: %d\n", p2->reason_code); +// break; +// } +// case MAP_TLV_ASSOCIATED_STA_TRAFFIC_STATS: +// { +// struct tlv_assoc_sta_traffic_stats *p1 = +// (struct tlv_assoc_sta_traffic_stats *)tlv; +// trace("\taddr: " MACFMT "\n", MAC2STR(p1->addr)); +// trace("\tbytes_sent: %d\n", p1->bytes_sent); +// trace("\tbytes_received: %d\n", p1->bytes_received); +// trace("\tpackets_sent: %d\n", p1->packets_sent); +// trace("\tpackets_received: %d\n", p1->packets_received); +// trace("\ttx_packets_err: %d\n", p1->tx_packets_err); +// trace("\trx_packets_err: %d\n", p1->rx_packets_err); +// trace("\tretransmission_cnt: %d\n", p1->retransmission_cnt); +// break; +// } +// default: +// fprintf(stdout, "unknown TLV in CMDU:|%s|", map_stringify_cmdu_type(cmdu->message_type)); +// break; +// } +// trace("\n"); +// } +// return 0; } -int debug_assoc_status_notification(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_assoc_status_notification(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; } -int debug_tunneled_message(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_tunneled_message(void *cntlr, struct cmdu_buff *cmdu) { - int i; - uint8_t *tlv; - - trace("%s: --->\n", __func__); - trace("parsing tunnel message |" MACFMT "|CMDU: %s\n", - MAC2STR(cmdu->origin), - map_stringify_cmdu_type(cmdu->message_type)); - - for (i = 0; i < cmdu->num_tlvs; i++) { - tlv = (uint8_t *)cmdu->tlvs[i]; - trace("TLV: %s\n", map_stringify_tlv_type(*tlv)); - switch (*tlv) { - case MAP_TLV_SOURCE_INFO: - { - struct tlv_source_info *p = - (struct tlv_source_info *)tlv; - - trace("\tmac: " MACFMT "\n", MAC2STR(p->mac)); - break; - } - case MAP_TLV_TUNNELED_MSG_TYPE: - { - struct tlv_tunnel_msg_type *p = - (struct tlv_tunnel_msg_type *)tlv; - - trace("\ttunnel_protocol_type: %d\n", - p->tunnel_protocol_type); - break; - } - case MAP_TLV_TUNNELED: - { - char *framestr = NULL; - int frame_len; - struct tlv_tunneled *p = (struct tlv_tunneled *)tlv; - - trace("\ttlv_len: %d\n", p->tlv_len); - if (p->tlv_len > 0) { - frame_len = (2 * p->tlv_len) + 1; - framestr = calloc(frame_len, sizeof(char)); - } - - if (framestr) { - btostr(p->frame_body, p->tlv_len, framestr); - trace("\tframe_body: %s\n", framestr); - free(framestr); - } - break; - } - default: - { - trace("unknown TLV\n"); - break; - } - } - } - return 0; +// int i; +// uint8_t *tlv; +// +// trace("%s: --->\n", __func__); +// trace("parsing tunnel message |" MACFMT "|CMDU: %s\n", +// MAC2STR(cmdu->origin), +// map_stringify_cmdu_type(cmdu->message_type)); +// +// for (i = 0; i < cmdu->num_tlvs; i++) { +// tlv = (uint8_t *)cmdu->tlvs[i]; +// trace("TLV: %s\n", map_stringify_tlv_type(*tlv)); +// switch (*tlv) { +// case MAP_TLV_SOURCE_INFO: +// { +// struct tlv_source_info *p = +// (struct tlv_source_info *)tlv; +// +// trace("\tmac: " MACFMT "\n", MAC2STR(p->mac)); +// break; +// } +// case MAP_TLV_TUNNELED_MSG_TYPE: +// { +// struct tlv_tunnel_msg_type *p = +// (struct tlv_tunnel_msg_type *)tlv; +// +// trace("\ttunnel_protocol_type: %d\n", +// p->tunnel_protocol_type); +// break; +// } +// case MAP_TLV_TUNNELED: +// { +// char *framestr = NULL; +// int frame_len; +// struct tlv_tunneled *p = (struct tlv_tunneled *)tlv; +// +// trace("\ttlv_len: %d\n", p->tlv_len); +// if (p->tlv_len > 0) { +// frame_len = (2 * p->tlv_len) + 1; +// framestr = calloc(frame_len, sizeof(char)); +// } +// +// if (framestr) { +// btostr(p->frame_body, p->tlv_len, framestr); +// trace("\tframe_body: %s\n", framestr); +// free(framestr); +// } +// break; +// } +// default: +// { +// trace("unknown TLV\n"); +// break; +// } +// } +// } +// +// return 0; } -int debug_backhaul_sta_caps_report(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_backhaul_sta_caps_report(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); - uint8_t *tlv; - int i = 0; - - for (i = 0; i < cmdu->num_tlvs; i++) { - tlv = (uint8_t *) cmdu->tlvs[i]; - trace("\nCMDU type: %s\n", map_stringify_tlv_type(*tlv)); - struct tlv_backhaul_sta_radio_cap *p = - (struct tlv_backhaul_sta_radio_cap *)tlv; - trace("\tradio_id: " MACFMT "\n", MAC2STR(p->radio_id)); - trace("\tmac_include: %d\n", p->mac_include); - if (p->mac_include) - trace("\tmac: " MACFMT "\n", MAC2STR(p->mac)); - } return 0; +// uint8_t *tlv; +// int i = 0; +// +// for (i = 0; i < cmdu->num_tlvs; i++) { +// tlv = (uint8_t *) cmdu->tlvs[i]; +// trace("\nCMDU type: %s\n", map_stringify_tlv_type(*tlv)); +// struct tlv_backhaul_sta_radio_cap *p = +// (struct tlv_backhaul_sta_radio_cap *)tlv; +// trace("\tradio_id: " MACFMT "\n", MAC2STR(p->radio_id)); +// trace("\tmac_include: %d\n", p->mac_include); +// if (p->mac_include) +// trace("\tmac: " MACFMT "\n", MAC2STR(p->mac)); +// } +// return 0; } -int debug_failed_connection_msg(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_failed_connection_msg(void *cntlr, struct cmdu_buff *cmdu) { trace("%s: --->\n", __func__); return 0; diff --git a/src/core/cntlr_map_debug.h b/src/core/cntlr_map_debug.h index a1780ea0e2c8659a5a6fab314a27768ee9ca99ad..41e1934f75f5cc2c48e42d2f3d3f8b0d41f67cd6 100644 --- a/src/core/cntlr_map_debug.h +++ b/src/core/cntlr_map_debug.h @@ -10,29 +10,29 @@ #ifndef CNTLR_MAP_DEBUG_H #define CNTLR_MAP_DEBUG_H -int debug_topology_notification(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_topology_response(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_ap_autoconfig_search(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_ap_autoconfig_response(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_ap_autoconfig_wsc(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_1905_ack(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_ap_caps_report(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_channel_pref_report(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_channel_sel_response(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_oper_channel_report(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_sta_caps_report(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_ap_metrics_response(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_sta_link_metrics_response(void *cntlr, struct cmdu_cstruct *cmdu); +int debug_topology_notification(void *cntlr, struct cmdu_buff *cmdu); +int debug_topology_response(void *cntlr, struct cmdu_buff *cmdu); +int debug_ap_autoconfig_search(void *cntlr, struct cmdu_buff *cmdu); +int debug_ap_autoconfig_response(void *cntlr, struct cmdu_buff *cmdu); +int debug_ap_autoconfig_wsc(void *cntlr, struct cmdu_buff *cmdu); +int debug_1905_ack(void *cntlr, struct cmdu_buff *cmdu); +int debug_ap_caps_report(void *cntlr, struct cmdu_buff *cmdu); +int debug_channel_pref_report(void *cntlr, struct cmdu_buff *cmdu); +int debug_channel_sel_response(void *cntlr, struct cmdu_buff *cmdu); +int debug_oper_channel_report(void *cntlr, struct cmdu_buff *cmdu); +int debug_sta_caps_report(void *cntlr, struct cmdu_buff *cmdu); +int debug_ap_metrics_response(void *cntlr, struct cmdu_buff *cmdu); +int debug_sta_link_metrics_response(void *cntlr, struct cmdu_buff *cmdu); int debug_unassoc_sta_link_metrics_response(void *cntlr, - struct cmdu_cstruct *cmdu); -int debug_beacon_metrics_response(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_sta_steer_btm_report(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_sta_steer_complete(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_backhaul_sta_steer_response(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_channel_scan_report(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_sta_disassoc_stats(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_assoc_status_notification(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_tunneled_message(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_backhaul_sta_caps_report(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_failed_connection_msg(void *cntlr, struct cmdu_cstruct *cmdu); + struct cmdu_buff *cmdu); +int debug_beacon_metrics_response(void *cntlr, struct cmdu_buff *cmdu); +int debug_sta_steer_btm_report(void *cntlr, struct cmdu_buff *cmdu); +int debug_sta_steer_complete(void *cntlr, struct cmdu_buff *cmdu); +int debug_backhaul_sta_steer_response(void *cntlr, struct cmdu_buff *cmdu); +int debug_channel_scan_report(void *cntlr, struct cmdu_buff *cmdu); +int debug_sta_disassoc_stats(void *cntlr, struct cmdu_buff *cmdu); +int debug_assoc_status_notification(void *cntlr, struct cmdu_buff *cmdu); +int debug_tunneled_message(void *cntlr, struct cmdu_buff *cmdu); +int debug_backhaul_sta_caps_report(void *cntlr, struct cmdu_buff *cmdu); +int debug_failed_connection_msg(void *cntlr, struct cmdu_buff *cmdu); #endif diff --git a/src/core/cntlr_tlv_generator.c b/src/core/cntlr_tlv_generator.c index 00bb8496c57a1f269a66e6d2c1544518ff13d9fe..2c23dd4870bede9d084cd68f7f9cde6b6a774132 100644 --- a/src/core/cntlr_tlv_generator.c +++ b/src/core/cntlr_tlv_generator.c @@ -29,11 +29,17 @@ #include <easy/easy.h> #include <wifi.h> // TODO: remove wifi.h -#include <map1905/map2.h> -#include <map1905/maputils.h> -#include <wsc.h> +#include <i1905_wsc.h> -#include "map_module.h" +#include <timer_impl.h> +#include <cmdu.h> +#include <1905_tlvs.h> +#include <map22.h> +#include <map_module22.h> + +#include <uci.h> + +//#include "map_module.h" #include "utils.h" #include "debug.h" #include "config.h" @@ -77,728 +83,857 @@ uint16_t wifi_sec_to_auth_types(enum wifi_security sec) } -uint8_t *extract_tlv_by_type(struct cmdu_cstruct *cmdu, uint8_t tlv_type) +uint8_t *extract_tlv_by_type(struct cmdu_buff *cmdu, uint8_t tlv_type) { - uint8_t *tlv; - int i; - - for (i = 0; i < cmdu->num_tlvs; i++) { - tlv = cmdu->tlvs[i]; - if (*tlv == tlv_type) - return tlv; - } - return NULL; - +// uint8_t *tlv; +// int i; +// +// for (i = 0; i < cmdu->num_tlvs; i++) { +// tlv = cmdu->tlvs[i]; +// if (*tlv == tlv_type) +// return tlv; +// } +// +// return NULL; +// } -struct tlv_default_8021q_settings *cntlr_gen_8021q_settings(struct controller *c, +int cntlr_gen_8021q_settings(struct controller *c, struct cmdu_buff *frm, struct agent_policy *a) { - struct tlv_default_8021q_settings *p; + struct tlv *t; + struct tlv_default_8021q_settings *data; + int ret; + + t = cmdu_reserve_tlv(frm, 256); + if (!t) + return -1; - p = (struct tlv_default_8021q_settings *) calloc(1, sizeof(*p)); - if (!p) - return NULL; + t->type = MAP_TLV_DEFAULT_8021Q_SETTINGS; + t->len = 3; - p->tlv_type = MAP_TLV_DEFAULT_8021Q_SETTINGS; - p->primary_vid = a->pvid; - p->pcp = a->pcp_default; + data = (struct tlv_default_8021q_settings *) t->data; + data->pvid = a->pvid; + data->pcp = a->pcp_default; + + ret = cmdu_put_tlv(frm, t); + if (ret) { + err("%s: error: cmdu_put_tlv()\n", __func__); + return -1; + } - return p; + return 0; +// struct tlv_default_8021q_settings *p; +// +// p = (struct tlv_default_8021q_settings *) calloc(1, sizeof(*p)); +// if (!p) +// return NULL; +// +// p->tlv_type = MAP_TLV_DEFAULT_8021Q_SETTINGS; +// p->primary_vid = a->pvid; +// p->pcp = a->pcp_default; +// +// return p; } -struct tlv_traffic_sep_policy *cntlr_gen_traffic_sep_policy(struct controller *c, - struct cmdu_cstruct *cmdu) +int cntlr_gen_traffic_sep_policy(struct controller *c, struct cmdu_buff *frm) { - struct tlv_traffic_sep_policy *p; + struct tlv *t; + struct tlv_traffic_sep_policy *data; + int ret, i = 0; struct iface_credential *cred; - int i = 0; - - p = (struct tlv_traffic_sep_policy *) calloc(1, sizeof(*p)); - if (!p) - return NULL; - - p->tlv_type = MAP_TLV_TRAFFIC_SEPARATION_POLICY; - p->nbr_ssid = c->cfg.num_fh; - p->data = calloc(p->nbr_ssid, sizeof(*(p->data))); - if (!p->data) { - map_free_tlv_cstruct((uint8_t *) p); - return NULL; - } + + t = cmdu_reserve_tlv(frm, 256); + if (!t) + return -1; + + t->type = MAP_TLV_TRAFFIC_SEPARATION_POLICY; + t->len = 1; + + data = (struct tlv_traffic_sep_policy *) t->data; + data->num_ssid = c->cfg.num_fh + c->cfg.num_bk; list_for_each_entry(cred, &c->cfg.fhlist, list) { int len; - len = strlen((char *)cred->ssid); + t->len++; /* vlanid */ + data->ssid[i].vid = cred->vlanid; - p->data[i].ssid_len = len; - p->data[i].vid = cred->vlanid; - p->data[i].ssid = calloc(1, len + 1); - if (!p->data[i].ssid) - continue; + t->len++; /* len */ + len = strlen((char *)cred->ssid); + data->ssid[i].info.len = len; - strncpy(p->data[i].ssid, (char *)cred->ssid, len); + t->len += len; /* ssid */ + memcpy(data->ssid[i].info.ssid, cred->ssid, len); i++; } - return p; -} - -struct tlv_wsc *cntlr_gen_wsc(struct controller *c, - struct cmdu_cstruct *cmdu, struct cmdu_cstruct *rec_cmdu, - struct iface_credential *cred) -{ - struct tlv_ap_radio_basic_cap *ap_caps = NULL; - struct tlv_wsc *m2, *m1; - enum wifi_band band = BAND_UNKNOWN; - struct mdata cfg = {0}; - int i, rv; - - ap_caps = (struct tlv_ap_radio_basic_cap *) extract_tlv_by_type(rec_cmdu, - MAP_TLV_AP_RADIO_BASIC_CAPABILITIES); - if (!ap_caps) - return NULL; - - m1 = (struct tlv_wsc *) extract_tlv_by_type(rec_cmdu, - TLV_TYPE_WSC); - if (!m1) - return NULL; - - /* determine radio frequency */ - for (i = 0; i < ap_caps->operating_classes_nr; i++) { - if (ap_caps->operating_class[i].op_class >= 81 && - ap_caps->operating_class[i].op_class <= 84) - band = BAND_2; - else if (ap_caps->operating_class[i].op_class >= 112 && - ap_caps->operating_class[i].op_class <= 130) - band = BAND_5; + list_for_each_entry(cred, &c->cfg.bklist, list) { + int len; - } + t->len++; /* vlanid */ + data->ssid[i].vid = cred->vlanid; - if (cred->band != band) - return NULL; + t->len++; /* len */ + len = strlen((char *)cred->ssid); + data->ssid[i].info.len = len; - m2 = (struct tlv_wsc *) calloc(1, sizeof(struct tlv_wsc)); - if (!m2) - return NULL; + t->len += len; /* ssid */ + memcpy(data->ssid[i].info.ssid, cred->ssid, len); + i++; + } - m2->tlv_type = TLV_TYPE_WSC; + ret = cmdu_put_tlv(frm, t); + if (ret) { + err("%s: error: cmdu_put_tlv()\n", __func__); + return -1; + } - cfg.input.auth_types = wifi_sec_to_auth_types(cred->sec); + dbg("%s %d\n", __func__, __LINE__); + + return 0; +// struct tlv_traffic_sep_policy *p; +// struct iface_credential *cred; +// int i = 0; +// +// p = (struct tlv_traffic_sep_policy *) calloc(1, sizeof(*p)); +// if (!p) +// return NULL; +// +// p->tlv_type = MAP_TLV_TRAFFIC_SEPARATION_POLICY; +// p->nbr_ssid = c->cfg.num_fh; +// p->data = calloc(p->nbr_ssid, sizeof(*(p->data))); +// if (!p->data) { +// map_free_tlv_cstruct((uint8_t *) p); +// return NULL; +// } +// +// list_for_each_entry(cred, &c->cfg.fhlist, list) { +// int len; +// +// len = strlen((char *)cred->ssid); +// +// p->data[i].ssid_len = len; +// p->data[i].vid = cred->vlanid; +// p->data[i].ssid = calloc(1, len + 1); +// if (!p->data[i].ssid) +// continue; +// +// strncpy(p->data[i].ssid, (char *)cred->ssid, len); +// i++; +// } +// +// return p; +} - /* backhaul STA - DEPRECATED - * cfg.input.mapie |= (cred->mode == WIFI_MODE_STA ? 1 << 7 : 0); - */ - /* backhaul BSS */ - cfg.input.mapie |= (cred->multi_ap & 0x01) << 6; - cfg.input.mapie |= (cred->mode == AP_WIFI_BBSS ? (1 << 6) : 0); +int cntlr_gen_wsc(struct controller *c, struct cmdu_buff *frm, + struct iface_credential *iface_cred, uint8_t *msg, uint16_t msglen, + uint8_t band) +{ + struct tlv *t; + struct tlv_wsc *data; + struct wps_credential cred = {0}; + uint8_t *m2; + uint16_t m2_size; + int i, rv, ret; + + t = cmdu_reserve_tlv(frm, 2000); + if (!t) + return -1; + + t->type = TLV_TYPE_WSC; + cred.band = band; + memcpy(cred.ssid, (char *)iface_cred->ssid, strlen((char *)iface_cred->ssid)); + cred.ssidlen = strlen((char *)iface_cred->ssid); + cred.auth_type = wifi_sec_to_auth_types(iface_cred->sec); // FIXME + cred.enc_type = WPS_ENCR_AES; /* TODO: ? */ + memcpy(cred.key, (char *)iface_cred->key, strlen((char *)iface_cred->key)); + cred.keylen = strlen((char *)iface_cred->key); + + cred.iop_ext = true; + + cred.mapie |= (iface_cred->multi_ap & 0x01) << 6; + cred.mapie |= (iface_cred->mode == AP_WIFI_BBSS ? (1 << 6) : 0); /* fronthaul BSS */ - cfg.input.mapie |= (cred->multi_ap & 0x02) << 4; - cfg.input.mapie |= (cred->mode == AP_WIFI_FBSS ? (1 << 5) : 0); + cred.mapie |= (iface_cred->multi_ap & 0x02) << 4; + cred.mapie |= (iface_cred->mode == AP_WIFI_FBSS ? (1 << 5) : 0); /* backhaul STA */ - cfg.input.mapie |= (cred->disallow_bsta << 2); + cred.mapie |= (iface_cred->disallow_bsta << 2); /* teardown bit */ - //cfg.input.mapie |= 1 << 4; + //cred.mapie |= 1 << 4; - memcpy(cfg.input.ssid, cred->ssid, 32); - memcpy(cfg.input.network_key, cred->key, 64); - - cfg.input.encryption_types = 0; // Will not match any - if (!cred->br) { - memcpy(cfg.input.bridge, c->cfg.al_bridge, sizeof(c->cfg.al_bridge)); + if (!iface_cred->br) { + memcpy(cred.bridge, c->cfg.al_bridge, sizeof(c->cfg.al_bridge)); } else { - cfg.input.vid = cred->br->id; - memcpy(cfg.input.bridge, cred->br->network, - strlen(cred->br->network)); - memcpy(cfg.input.proto, cred->br->proto, - strlen(cred->br->proto)); - - if (!strcmp(cfg.input.proto, "static")) - cfg.input.br_ip = cred->br->ipaddr.addr.ip4.s_addr; + cred.vid = iface_cred->br->id; + memcpy(cred.bridge, iface_cred->br->network, + strlen(iface_cred->br->network)); + memcpy(cred.proto, iface_cred->br->proto, + strlen(iface_cred->br->proto)); + + if (!strcmp(cred.proto, "static")) + cred.br_ip = iface_cred->br->ipaddr.addr.ip4.s_addr; } - memcpy(cfg.input.bk_ssid, cred->bk_ssid, sizeof(cred->bk_ssid)); - memcpy(cfg.input.bk_key, cred->bk_key, sizeof(cred->bk_key)); + memcpy(cred.bk_ssid, iface_cred->bk_ssid, sizeof(iface_cred->bk_ssid)); + memcpy(cred.bk_key, iface_cred->bk_key, sizeof(iface_cred->bk_key)); + ret = wsc_build_m2(msg, msglen, &cred, &m2, &m2_size); + if (ret) { + dbg("Error building m2!\n"); + return ret; + } - rv = wscBuildM2(m1->wsc_frame, m1->wsc_frame_size, &m2->wsc_frame, - &m2->wsc_frame_size, band, NULL, &cfg); - if (!rv) - err("Failed to build m2!\n"); + t->len = m2_size; - return m2; + memcpy(t->data, m2, m2_size); + ret = cmdu_put_tlv(frm, t); + if (ret) { + err("%s: error: cmdu_put_tlv()\n", __func__); + return -1; + } + return 0; } -struct tlv_ap_radio_identifier *cntlr_gen_ap_radio_identifier(struct controller *c, - struct cmdu_cstruct *cmdu, uint8_t *hwaddr) +int cntlr_gen_ap_radio_identifier(struct controller *c, + struct cmdu_buff *frm, uint8_t *hwaddr) { - struct tlv_ap_radio_identifier *p; + struct tlv *t; + struct tlv_ap_radio_identifier *data; + int ret; - p = (struct tlv_ap_radio_identifier *)calloc(1, - sizeof(struct tlv_ap_radio_identifier)); - if (!p) { - fprintf(stderr, "failed to malloc tlv\n"); - return NULL; - } + t = cmdu_reserve_tlv(frm, 256); + if (!t) + return -1; + + t->type = MAP_TLV_AP_RADIO_IDENTIFIER; + t->len = 6; - p->tlv_type = MAP_TLV_AP_RADIO_IDENTIFIER; - memcpy(p->radio_id, hwaddr, 6); + data = (struct tlv_ap_radio_identifier *) t->data; + memcpy(data->radio, hwaddr, 6); - return p; + ret = cmdu_put_tlv(frm, t); + if (ret) { + err("%s: error: cmdu_put_tlv()\n", __func__); + return -1; + } + + return 0; } -struct tlv_supp_service *cntlr_gen_supp_service(struct controller *c, - struct cmdu_cstruct *cmdu) +int cntlr_gen_supp_role(struct controller *c, struct cmdu_buff *frm, + uint8_t role) { - struct tlv_supp_service *p; - int i; - - p = (struct tlv_supp_service *)calloc(1, sizeof(*p)); - if (!p) - return NULL; - - p->tlv_type = MAP_TLV_SUPPORTED_SERVICE; - p->supported_services_list = 1; - p->supported_services = calloc(p->supported_services_list, - sizeof(*p->supported_services)); - if (!p->supported_services) { - map_free_tlv_cstruct((uint8_t *) p); - return NULL; - } + struct tlv *t; + struct tlv_supported_role *data; + int ret; - for (i = 0; i < p->supported_services_list; i++) - p->supported_services[i].service = SUPPORTED_SERVICE_MULTIAP_CONTROLLER; + t = cmdu_reserve_tlv(frm, 256); + if (!t) + return -1; - return p; + t->type = TLV_TYPE_SUPPORTED_ROLE; + t->len = 1; + + data = (struct tlv_supported_role *) t->data; + data->role = role; + + ret = cmdu_put_tlv(frm, t); + if (ret) { + err("%s: error: cmdu_put_tlv()\n", __func__); + return -1; + } + + return 0; } -struct tlv_map_profile *cntlr_gen_map_profile(struct controller *c, - struct cmdu_cstruct *cmdu) +int cntlr_gen_supp_service(struct controller *c, struct cmdu_buff *frm, + uint8_t service) { - struct tlv_map_profile *p; + struct tlv *t; + int ret; + + t = cmdu_reserve_tlv(frm, 256); + if (!t) + return -1; + + t->type = MAP_TLV_SUPPORTED_SERVICE; + t->len = 2; + t->data[0] = 0x1; + t->data[1] = service; + + ret = cmdu_put_tlv(frm, t); + if (ret) { + dbg("%s: error: cmdu_put_tlv()\n", __func__); + return -1; + } - p = calloc(1, sizeof(struct tlv_map_profile)); - if (!p) - return NULL; + return 0; +} - p->tlv_type = MAP_TLV_MULTIAP_PROFILE; - p->profile = 0x02; +int cntlr_gen_map_profile(struct controller *c, struct cmdu_buff *frm, + uint8_t profile) +{ + struct tlv *t; + struct tlv_map_profile *data; + int ret; + + t = cmdu_reserve_tlv(frm, 256); + if (!t) + return -1; + + t->type = MAP_TLV_MULTIAP_PROFILE; + t->len = 1; + data = (struct tlv_map_profile *) t->data; + data->profile = profile; + + ret = cmdu_put_tlv(frm, t); + if (ret) { + dbg("%s: error: cmdu_put_tlv()\n", __func__); + return -1; + } - return p; + return 0; } struct tlv_ch_scan_rep_policy *cntlr_gen_ch_scan_rep_policy( struct controller *c, struct agent_policy *a, - struct cmdu_cstruct *cmdu) + struct cmdu_buff *cmdu) { - struct tlv_ch_scan_rep_policy *p; - - p = calloc(1, sizeof(struct tlv_ch_scan_rep_policy)); - if (!p) - return NULL; - - p->tlv_type = MAP_TLV_CHANNEL_SCAN_REPORTING_POLICY; - p->ch_scans = a->report_scan; - - return p; + return NULL; +// struct tlv_ch_scan_rep_policy *p; +// +// p = calloc(1, sizeof(struct tlv_ch_scan_rep_policy)); +// if (!p) +// return NULL; +// +// p->tlv_type = MAP_TLV_CHANNEL_SCAN_REPORTING_POLICY; +// p->ch_scans = a->report_scan; +// +// return p; } struct tlv_al_mac *cntlr_gen_al_mac(struct controller *c, uint8_t *hwaddr) { - struct tlv_al_mac *p; - - p = calloc(1, sizeof(struct tlv_al_mac)); - if (!p) - return NULL; - - p->tlv_type = TLV_TYPE_AL_MAC_ADDRESS_TYPE; - memcpy(p->al_mac_address, hwaddr, 6); - - return p; + return NULL; +// struct tlv_al_mac *p; +// +// p = calloc(1, sizeof(struct tlv_al_mac)); +// if (!p) +// return NULL; +// +// p->tlv_type = TLV_TYPE_AL_MAC_ADDRESS_TYPE; +// memcpy(p->al_mac_address, hwaddr, 6); +// +// return p; } struct tlv_unsuccess_assoc_policy *cntlr_gen_unsuccess_assoc_policy( struct controller *c, struct agent_policy *a, - struct cmdu_cstruct *cmdu) + struct cmdu_buff *cmdu) { - struct tlv_unsuccess_assoc_policy *p; - - p = calloc(1, sizeof(struct tlv_unsuccess_assoc_policy)); - if (!p) - return NULL; - - p->tlv_type = MAP_TLV_UNSUCCESS_ASSOCIATION_POLICY; - p->report = a->report_sta_assocfails; - p->max_reporting_rate = a->report_sta_assocfails_rate; - - return p; + return NULL; +// struct tlv_unsuccess_assoc_policy *p; +// +// p = calloc(1, sizeof(struct tlv_unsuccess_assoc_policy)); +// if (!p) +// return NULL; +// +// p->tlv_type = MAP_TLV_UNSUCCESS_ASSOCIATION_POLICY; +// p->report = a->report_sta_assocfails; +// p->max_reporting_rate = a->report_sta_assocfails_rate; +// +// return p; } -struct tlv_supported_freq_band *cntlr_gen_supported_freq_band(struct controller *c, +int cntlr_gen_supported_freq_band(struct controller *c, struct cmdu_buff *frm, uint8_t freq_band) { - struct tlv_supported_freq_band *p; - - p = calloc(1, sizeof(struct tlv_supported_freq_band)); - if (!p) - return NULL; - - p->tlv_type = TLV_TYPE_SUPPORTED_FREQ_BAND; - p->freq_band = freq_band; + struct tlv *t; + struct tlv_supported_band *data; + int ret; + + t = cmdu_reserve_tlv(frm, 256); + if (!t) + return -1; + + t->type = TLV_TYPE_SUPPORTED_FREQ_BAND; + t->len = 1; + data = (struct tlv_supported_band *) t->data; + data->band = freq_band; + + ret = cmdu_put_tlv(frm, t); + if (ret) { + dbg("%s: error: cmdu_put_tlv()\n", __func__); + return -1; + } - return p; + return 0; } struct tlv_backhaul_bss_config *cntlr_gen_backhaul_bss_config( struct controller *c, struct agent_policy *a, - struct cmdu_cstruct *cmdu, const uint8_t *bssid) + struct cmdu_buff *cmdu, const uint8_t *bssid) { - struct tlv_backhaul_bss_config *p; - - p = calloc(1, sizeof(struct tlv_backhaul_bss_config)); - if (!p) - return NULL; - - p->tlv_type = MAP_TLV_BACKHAUL_BSS_CONFIG; - memcpy(p->bssid, bssid, 6); - p->p1 = a->disallow_bsta_p1; - p->p2 = a->disallow_bsta_p2; - - return p; + return NULL; +// struct tlv_backhaul_bss_config *p; +// +// p = calloc(1, sizeof(struct tlv_backhaul_bss_config)); +// if (!p) +// return NULL; +// +// p->tlv_type = MAP_TLV_BACKHAUL_BSS_CONFIG; +// memcpy(p->bssid, bssid, 6); +// p->p1 = a->disallow_bsta_p1; +// p->p2 = a->disallow_bsta_p2; +// +// return p; } struct tlv_steering_policy *cntlr_gen_steering_policy( struct controller *c, struct agent_policy *a, - struct cmdu_cstruct *cmdu, int num_radio, uint8_t *radiolist) + struct cmdu_buff *cmdu, int num_radio, uint8_t *radiolist) { - int i = 0, index; - struct tlv_steering_policy *p; - struct stax *x; - uint8_t sta_mac[6] = {0}; - - p = calloc(1, sizeof(struct tlv_steering_policy)); - if (!p) - return NULL; - - p->tlv_type = MAP_TLV_STEERING_POLICY; - - p->local_disallowed_sta_nr = 0; - list_for_each_entry(x, &a->steer_exlist, list) { - p->local_disallowed_sta_nr++; - index = p->local_disallowed_sta_nr - 1; - p->local_disallowed_sta_macs = realloc(p->local_disallowed_sta_macs, - p->local_disallowed_sta_nr * sizeof(*p->local_disallowed_sta_macs)); - if (!p->local_disallowed_sta_macs) - goto fail_alloc; - - hwaddr_aton(x->macstring, sta_mac); - memcpy(p->local_disallowed_sta_macs[index].addr, sta_mac, 6); - } - - p->btm_disallowed_sta_nr = 0; - list_for_each_entry(x, &a->btmsteer_exlist, list) { - p->btm_disallowed_sta_nr++; - index = p->btm_disallowed_sta_nr - 1; - p->btm_disallowed_sta_macs = realloc(p->btm_disallowed_sta_macs, - p->btm_disallowed_sta_nr * sizeof(*p->btm_disallowed_sta_macs)); - if (!p->btm_disallowed_sta_macs) - goto fail_alloc; - - hwaddr_aton(x->macstring, sta_mac); - memcpy(p->btm_disallowed_sta_macs[index].addr, sta_mac, 6); - } - - p->control_policy_radio_nr = num_radio; - p->control_policy = calloc(p->control_policy_radio_nr, - sizeof(*p->control_policy)); - if (!p->control_policy) - goto fail_alloc; - - for (i = 0; i < p->control_policy_radio_nr; i++) { - memcpy(p->control_policy[i].radio_id, &radiolist[i*6], 6); - p->control_policy[i].steering_policy = a->policy; - p->control_policy[i].channel_utilization_thres = - a->util_threshold; - p->control_policy[i].rcpi_steering_thres = - a->rcpi_threshold; - } - - return p; - -fail_alloc: - if (p->local_disallowed_sta_macs) - free(p->local_disallowed_sta_macs); - if (p->btm_disallowed_sta_macs) - free(p->btm_disallowed_sta_macs); - - free(p); - return NULL; +// int i = 0, index; +// struct tlv_steering_policy *p; +// struct stax *x; +// uint8_t sta_mac[6] = {0}; +// +// p = calloc(1, sizeof(struct tlv_steering_policy)); +// if (!p) +// return NULL; +// +// p->tlv_type = MAP_TLV_STEERING_POLICY; +// +// p->local_disallowed_sta_nr = 0; +// list_for_each_entry(x, &a->steer_exlist, list) { +// p->local_disallowed_sta_nr++; +// index = p->local_disallowed_sta_nr - 1; +// p->local_disallowed_sta_macs = realloc(p->local_disallowed_sta_macs, +// p->local_disallowed_sta_nr * sizeof(*p->local_disallowed_sta_macs)); +// if (!p->local_disallowed_sta_macs) +// goto fail_alloc; +// +// hwaddr_aton(x->macstring, sta_mac); +// memcpy(p->local_disallowed_sta_macs[index].addr, sta_mac, 6); +// } +// +// p->btm_disallowed_sta_nr = 0; +// list_for_each_entry(x, &a->btmsteer_exlist, list) { +// p->btm_disallowed_sta_nr++; +// index = p->btm_disallowed_sta_nr - 1; +// p->btm_disallowed_sta_macs = realloc(p->btm_disallowed_sta_macs, +// p->btm_disallowed_sta_nr * sizeof(*p->btm_disallowed_sta_macs)); +// if (!p->btm_disallowed_sta_macs) +// goto fail_alloc; +// +// hwaddr_aton(x->macstring, sta_mac); +// memcpy(p->btm_disallowed_sta_macs[index].addr, sta_mac, 6); +// } +// +// p->control_policy_radio_nr = num_radio; +// p->control_policy = calloc(p->control_policy_radio_nr, +// sizeof(*p->control_policy)); +// if (!p->control_policy) +// goto fail_alloc; +// +// for (i = 0; i < p->control_policy_radio_nr; i++) { +// memcpy(p->control_policy[i].radio_id, &radiolist[i*6], 6); +// p->control_policy[i].steering_policy = a->policy; +// p->control_policy[i].channel_utilization_thres = +// a->util_threshold; +// p->control_policy[i].rcpi_steering_thres = +// a->rcpi_threshold; +// } +// +// return p; +// +//fail_alloc: +// if (p->local_disallowed_sta_macs) +// free(p->local_disallowed_sta_macs); +// if (p->btm_disallowed_sta_macs) +// free(p->btm_disallowed_sta_macs); +// +// free(p); +// +// return NULL; } struct tlv_metric_report_policy *cntlr_gen_metric_report_policy( struct controller *c, struct agent_policy *a, - struct cmdu_cstruct *cmdu, int num_radio, uint8_t *radiolist) + struct cmdu_buff *cmdu, int num_radio, uint8_t *radiolist) { - int i = 0; - struct tlv_metric_report_policy *p; - - p = calloc(1, sizeof(struct tlv_metric_report_policy)); - if (!p) - return NULL; - - p->tlv_type = MAP_TLV_METRIC_REPORTING_POLICY; - p->interval = a->report_metric_periodic; - p->metric_reporting_policy_radio_nr = num_radio; - p->metric_reporting_policy = calloc(p->metric_reporting_policy_radio_nr, - sizeof(*p->metric_reporting_policy)); - - if (!p->metric_reporting_policy) { - free(p); - return NULL; - } - - for (i = 0; i < p->metric_reporting_policy_radio_nr; i++) { - memcpy(p->metric_reporting_policy[i].radio_id, &radiolist[i*6], 6); - p->metric_reporting_policy[i].rcpi_thres = - a->report_rcpi_threshold; - p->metric_reporting_policy[i].rcpi_hysteresis_margin = - a->rcpi_hysteresis_margin; - p->metric_reporting_policy[i].channel_utilization_thres = - a->report_util_threshold; - p->metric_reporting_policy[i].is_assoc_sta_traffic_stats = - a->include_sta_stats; - p->metric_reporting_policy[i].is_assoc_sta_link_metrics = - a->include_sta_metric; - } - - return p; + return NULL; +// int i = 0; +// struct tlv_metric_report_policy *p; +// +// p = calloc(1, sizeof(struct tlv_metric_report_policy)); +// if (!p) +// return NULL; +// +// p->tlv_type = MAP_TLV_METRIC_REPORTING_POLICY; +// p->interval = a->report_metric_periodic; +// p->metric_reporting_policy_radio_nr = num_radio; +// p->metric_reporting_policy = calloc(p->metric_reporting_policy_radio_nr, +// sizeof(*p->metric_reporting_policy)); +// +// if (!p->metric_reporting_policy) { +// free(p); +// return NULL; +// } +// +// for (i = 0; i < p->metric_reporting_policy_radio_nr; i++) { +// memcpy(p->metric_reporting_policy[i].radio_id, &radiolist[i*6], 6); +// p->metric_reporting_policy[i].rcpi_thres = +// a->report_rcpi_threshold; +// p->metric_reporting_policy[i].rcpi_hysteresis_margin = +// a->rcpi_hysteresis_margin; +// p->metric_reporting_policy[i].channel_utilization_thres = +// a->report_util_threshold; +// p->metric_reporting_policy[i].is_assoc_sta_traffic_stats = +// a->include_sta_stats; +// p->metric_reporting_policy[i].is_assoc_sta_link_metrics = +// a->include_sta_metric; +// } +// +// return p; } struct tlv_supported_role *cntlr_gen_supported_role(struct controller *c, uint8_t role) { - struct tlv_supported_role *p; - - p = calloc(1, sizeof(struct tlv_supported_role)); - if (!p) - return NULL; - - p->tlv_type = TLV_TYPE_SUPPORTED_ROLE; - p->role = role; - - return p; + return NULL; +// struct tlv_supported_role *p; +// +// p = calloc(1, sizeof(struct tlv_supported_role)); +// if (!p) +// return NULL; +// +// p->tlv_type = TLV_TYPE_SUPPORTED_ROLE; +// p->role = role; +// +// return p; } struct tlv_client_info *cntlr_gen_client_info(struct controller *c, uint8_t *sta, uint8_t *bssid) { - struct tlv_client_info *p; - - p = calloc(1, sizeof(struct tlv_client_info)); - if (!p) - return NULL; - - p->tlv_type = MAP_TLV_CLIENT_INFO; - memcpy(p->bssid, bssid, 6); - memcpy(p->client_addr, sta, 6); - - return p; + return NULL; +// struct tlv_client_info *p; +// +// p = calloc(1, sizeof(struct tlv_client_info)); +// if (!p) +// return NULL; +// +// p->tlv_type = MAP_TLV_CLIENT_INFO; +// memcpy(p->bssid, bssid, 6); +// memcpy(p->client_addr, sta, 6); +// +// return p; } struct tlv_backhaul_steer_req *cntlr_gen_backhaul_steer_req(struct controller *c, uint8_t *bssid, uint8_t *bkhaul, uint8_t op_class, uint8_t channel) { - struct tlv_backhaul_steer_req *p; - - p = calloc(1, sizeof(struct tlv_backhaul_steer_req)); - if (!p) - return NULL; - - p->tlv_type = MAP_TLV_BACKHAUL_STEERING_REQUEST; - memcpy(p->bssid, bssid, 6); - memcpy(p->addr, bkhaul, 6); - - p->channel = channel; - p->op_class = op_class; - return p; + return NULL; +// struct tlv_backhaul_steer_req *p; +// +// p = calloc(1, sizeof(struct tlv_backhaul_steer_req)); +// if (!p) +// return NULL; +// +// p->tlv_type = MAP_TLV_BACKHAUL_STEERING_REQUEST; +// memcpy(p->bssid, bssid, 6); +// memcpy(p->addr, bkhaul, 6); +// +// p->channel = channel; +// p->op_class = op_class; +// return p; } -struct tlv_steer_Req *cntlr_gen_client_steering_req( +struct tlv_steer_request *cntlr_gen_client_steering_req( char *bss_id, uint32_t steer_timeout, uint32_t sta_nr, char sta_id[][18], uint32_t bssid_nr, char target_bbsid[][18], uint32_t request_mode) { - int j = 0; - struct tlv_steer_Req *p = NULL; - - trace("%s: --->\n", __func__); - p = calloc(1, sizeof(struct tlv_steer_Req)); - if (!p) { - fprintf(stderr, "failed to malloc cmdu\n"); - return NULL; - } - - p->tlv_type = MAP_TLV_STEERING_REQUEST; - hwaddr_aton(bss_id, p->bssid); - - //Here we need to know if the this is for - //STA mandate or a STA opportunity - if (request_mode == 1) { - p->request_mode = 0x01; - p->steer_opp_window = 0x00; - } else if (request_mode == 0) { - p->request_mode = 0x00; - p->steer_opp_window = steer_timeout; - p->target_bssid_list_cnt = 0x00; - p->steering_req_target_bssids = NULL; - } else { - fprintf(stderr, "Unknown request mode\n"); - goto fail_p; - } - - //Here we need to fill the BTM bits - p->btm_disassoc_imminent = 0x00; //TODO default value - p->btm_abridged = 0x00; //TODO default value - p->reserved = 0x00; - p->btm_disassoc_timer = 0x00; //TODO default value - - p->sta_list_cnt = (uint8_t) sta_nr; - - if (p->sta_list_cnt > 0) { - p->steering_req_macs = calloc(p->sta_list_cnt, - sizeof(*p->steering_req_macs)); - if (!p->steering_req_macs) { - fprintf(stderr, "|%s:%d| out of memory!\n", - __func__, __LINE__); - p->sta_list_cnt = 0; - goto fail_p; - } - } - - for (j = 0; j < p->sta_list_cnt; j++) - hwaddr_aton(sta_id[j], p->steering_req_macs[j].addr); - - p->target_bssid_list_cnt = (uint8_t) bssid_nr; - - if (p->target_bssid_list_cnt > 0) { - p->steering_req_target_bssids = calloc( - p->target_bssid_list_cnt, - sizeof(*p->steering_req_target_bssids)); - - if (!p->steering_req_target_bssids) { - fprintf(stderr, "|%s:%d| out of memory!\n", - __func__, __LINE__); - p->target_bssid_list_cnt = 0; - goto fail_p; - } - } - for (j = 0; j < p->target_bssid_list_cnt; j++) { - hwaddr_aton(target_bbsid[j], p->steering_req_target_bssids[j].bssid); - p->steering_req_target_bssids[j].op_class = 0x00; - p->steering_req_target_bssids[j].channel = 0x00; - } - return p; - -fail_p: - if (p != NULL) - map_free_tlv_cstruct((uint8_t *) p); return NULL; +// int j = 0; +// struct tlv_steer_Req *p = NULL; +// +// trace("%s: --->\n", __func__); +// p = calloc(1, sizeof(struct tlv_steer_Req)); +// if (!p) { +// dbg("failed to malloc cmdu\n"); +// return NULL; +// } +// +// p->tlv_type = MAP_TLV_STEERING_REQUEST; +// hwaddr_aton(bss_id, p->bssid); +// +// //Here we need to know if the this is for +// //STA mandate or a STA opportunity +// if (request_mode == 1) { +// p->request_mode = 0x01; +// p->steer_opp_window = 0x00; +// } else if (request_mode == 0) { +// p->request_mode = 0x00; +// p->steer_opp_window = steer_timeout; +// p->target_bssid_list_cnt = 0x00; +// p->steering_req_target_bssids = NULL; +// } else { +// dbg("Unknown request mode\n"); +// goto fail_p; +// } +// +// //Here we need to fill the BTM bits +// p->btm_disassoc_imminent = 0x00; //TODO default value +// p->btm_abridged = 0x00; //TODO default value +// p->reserved = 0x00; +// p->btm_disassoc_timer = 0x00; //TODO default value +// +// p->sta_list_cnt = (uint8_t) sta_nr; +// +// if (p->sta_list_cnt > 0) { +// p->steering_req_macs = calloc(p->sta_list_cnt, +// sizeof(*p->steering_req_macs)); +// if (!p->steering_req_macs) { +// dbg("|%s:%d| out of memory!\n", +// __func__, __LINE__); +// p->sta_list_cnt = 0; +// goto fail_p; +// } +// } +// +// for (j = 0; j < p->sta_list_cnt; j++) +// hwaddr_aton(sta_id[j], p->steering_req_macs[j].addr); +// +// p->target_bssid_list_cnt = (uint8_t) bssid_nr; +// +// if (p->target_bssid_list_cnt > 0) { +// p->steering_req_target_bssids = calloc( +// p->target_bssid_list_cnt, +// sizeof(*p->steering_req_target_bssids)); +// +// if (!p->steering_req_target_bssids) { +// dbg("|%s:%d| out of memory!\n", +// __func__, __LINE__); +// p->target_bssid_list_cnt = 0; +// goto fail_p; +// } +// } +// for (j = 0; j < p->target_bssid_list_cnt; j++) { +// hwaddr_aton(target_bbsid[j], p->steering_req_target_bssids[j].bssid); +// p->steering_req_target_bssids[j].op_class = 0x00; +// p->steering_req_target_bssids[j].channel = 0x00; +// } +// return p; +// +//fail_p: +// if (p != NULL) +// map_free_tlv_cstruct((uint8_t *) p); +// return NULL; } #if PROFILE2 -struct tlv_profile2_steer_req *cntlr_gen_client_steering_req_pr2( +struct tlv_profile2_steer_request *cntlr_gen_client_steering_req_pr2( char *bss_id, uint32_t steer_timeout, uint32_t sta_multi_nr, char sta_multi_id[][18], uint32_t bssid_multi_nr, char target_bbsid_multi[][18], uint32_t request_mode) { - int j = 0; - struct tlv_profile2_steer_req p1 = NULL; - - p1 = calloc(1, sizeof(struct tlv_profile2_steer_req)); - if (!p1) { - fprintf(stderr, "failed to malloc cmdu\n"); - goto fail_cmdu; - } - - p1->tlv_type = MAP_TLV_PROFILE2_STEERING_REQ; - hwaddr_aton(bss_id, p1->bssid); - - //Here we need to know if the this is for - //STA mandate or a STA opportunity - if (request_mode == 1) { - p1->req_mode = 0x01; - p1->steering_opt_win = 0x00; - } else if (request_mode == 0) { - p1->req_mode = 0x00; - p1->steering_opt_win = steer_timeout; - p1->target_bssid_count = 0x00; - p1->target_data = NULL; - } else { - fprintf(stderr, "Unknown request mode\n"); - goto fail_p; - } - - //Here we need to fill the BTM bits - p1->btm_imminent_bit = 0x00; //TODO default value - p1->btm_abridged_bit = 0x00; //TODO default value - p1->btm_dis_timer = 0x00; //TODO default value - p1->sta_list_count = (uint8_t) sta_multi_nr; - - if (p1->sta_list_count > 0) { - p1->sta_mac = calloc(p1->sta_list_count, - sizeof(*p1->sta_mac)); - if (!p1->sta_mac) { - fprintf(stderr, "|%s:%d| out of memory!\n", - __func__, __LINE__); - p1->sta_list_count = 0; - goto fail_p; - } - } - - for (j = 0; j < p1->sta_list_count; j++) - hwaddr_aton(sta_multi_id[j], p1->sta_mac[j].mac); - - p1->target_bssid_count = bssid_multi_nr; - //Here we also need the bssid mapped to the STAs - if (p1->target_bssid_count > 0) { - p1->target_data = calloc(p1->target_bssid_count, - sizeof(*p1->target_data)); - - if (!p1->target_data) { - fprintf(stderr, "|%s:%d| out of memory!\n", - __func__, __LINE__); - p1->target_bssid_count = 0; - goto fail_p; - } - } - - for (j = 0; j < p1->target_bssid_count; j++) { - hwaddr_aton(target_bbsid_multi[j], p1->target_data[j].bssid); - p1->target_data[j].bss_op_class = 0x00; - //TODO filled as a default value now - p1->target_data[j].bss_ch = 0x00; - //TODO filled as a default value now - } - return p1; - -fail_p: - if (p1 != NULL) - map_free_tlv_cstruct((uint8_t *) p1); return NULL; +// int j = 0; +// struct tlv_profile2_steer_req p1 = NULL; +// +// p1 = calloc(1, sizeof(struct tlv_profile2_steer_req)); +// if (!p1) { +// dbg("failed to malloc cmdu\n"); +// goto fail_cmdu; +// } +// +// p1->tlv_type = MAP_TLV_PROFILE2_STEERING_REQ; +// hwaddr_aton(bss_id, p1->bssid); +// +// //Here we need to know if the this is for +// //STA mandate or a STA opportunity +// if (request_mode == 1) { +// p1->req_mode = 0x01; +// p1->steering_opt_win = 0x00; +// } else if (request_mode == 0) { +// p1->req_mode = 0x00; +// p1->steering_opt_win = steer_timeout; +// p1->target_bssid_count = 0x00; +// p1->target_data = NULL; +// } else { +// dbg("Unknown request mode\n"); +// goto fail_p; +// } +// +// //Here we need to fill the BTM bits +// p1->btm_imminent_bit = 0x00; //TODO default value +// p1->btm_abridged_bit = 0x00; //TODO default value +// p1->btm_dis_timer = 0x00; //TODO default value +// p1->sta_list_count = (uint8_t) sta_multi_nr; +// +// if (p1->sta_list_count > 0) { +// p1->sta_mac = calloc(p1->sta_list_count, +// sizeof(*p1->sta_mac)); +// if (!p1->sta_mac) { +// dbg("|%s:%d| out of memory!\n", +// __func__, __LINE__); +// p1->sta_list_count = 0; +// goto fail_p; +// } +// } +// +// for (j = 0; j < p1->sta_list_count; j++) +// hwaddr_aton(sta_multi_id[j], p1->sta_mac[j].mac); +// +// p1->target_bssid_count = bssid_multi_nr; +// //Here we also need the bssid mapped to the STAs +// if (p1->target_bssid_count > 0) { +// p1->target_data = calloc(p1->target_bssid_count, +// sizeof(*p1->target_data)); +// +// if (!p1->target_data) { +// dbg("|%s:%d| out of memory!\n", +// __func__, __LINE__); +// p1->target_bssid_count = 0; +// goto fail_p; +// } +// } +// +// for (j = 0; j < p1->target_bssid_count; j++) { +// hwaddr_aton(target_bbsid_multi[j], p1->target_data[j].bssid); +// p1->target_data[j].bss_op_class = 0x00; +// //TODO filled as a default value now +// p1->target_data[j].bss_ch = 0x00; +// //TODO filled as a default value now +// } +// return p1; +// +//fail_p: +// if (p1 != NULL) +// map_free_tlv_cstruct((uint8_t *) p1); +// return NULL; } #endif -struct tlv_client_assoc_control_req *cntlr_gen_assoc_control_req( +struct tlv_client_assoc_ctrl_request *cntlr_gen_assoc_control_req( uint8_t *bss_id, uint32_t assoc_cntl_mode, uint32_t assoc_timeout, uint32_t sta_nr, uint8_t sta_id[][18]) { - struct tlv_client_assoc_control_req *p = NULL; - int j = 0; - - p = calloc(1, sizeof(struct tlv_client_assoc_control_req)); - if (!p) { - fprintf(stderr, "failed to malloc cmdu\n"); - return NULL; - } - - p->tlv_type = MAP_TLV_CLIENT_ASSOCIATION_CONTROL_REQUEST; - hwaddr_aton(bss_id, p->bssid); - p->validity_period = assoc_timeout; - p->assoc_control = assoc_cntl_mode; - p->sta_list_cnt = sta_nr; - - if (p->sta_list_cnt > 0) { - p->client_assoc_ctrl_req_stas = calloc(p->sta_list_cnt, - sizeof(*p->client_assoc_ctrl_req_stas)); - if (!p->client_assoc_ctrl_req_stas) { - fprintf(stderr, "|%s:%d| out of memory!\n", - __func__, __LINE__); - p->sta_list_cnt = 0; - goto fail_p; - } - } - for (j = 0; j < p->sta_list_cnt; j++) - hwaddr_aton(sta_id[j], p->client_assoc_ctrl_req_stas[j].addr); - - return p; -fail_p: - if (p != NULL) - map_free_tlv_cstruct((uint8_t *) p); return NULL; +// struct tlv_client_assoc_control_req *p = NULL; +// int j = 0; +// +// p = calloc(1, sizeof(struct tlv_client_assoc_control_req)); +// if (!p) { +// dbg("failed to malloc cmdu\n"); +// return NULL; +// } +// +// p->tlv_type = MAP_TLV_CLIENT_ASSOCIATION_CONTROL_REQUEST; +// hwaddr_aton(bss_id, p->bssid); +// p->validity_period = assoc_timeout; +// p->assoc_control = assoc_cntl_mode; +// p->sta_list_cnt = sta_nr; +// +// if (p->sta_list_cnt > 0) { +// p->client_assoc_ctrl_req_stas = calloc(p->sta_list_cnt, +// sizeof(*p->client_assoc_ctrl_req_stas)); +// if (!p->client_assoc_ctrl_req_stas) { +// dbg("|%s:%d| out of memory!\n", +// __func__, __LINE__); +// p->sta_list_cnt = 0; +// goto fail_p; +// } +// } +// for (j = 0; j < p->sta_list_cnt; j++) +// hwaddr_aton(sta_id[j], p->client_assoc_ctrl_req_stas[j].addr); +// +// return p; +//fail_p: +// if (p != NULL) +// map_free_tlv_cstruct((uint8_t *) p); +// return NULL; } struct tlv_ap_metric_query *cntlr_gen_ap_metric_query(struct controller *c, uint8_t num_bss, uint8_t *bsslist) { - uint8_t i; - struct tlv_ap_metric_query *p; - - p = calloc(1, sizeof(*p)); - if (!p) - return NULL; - - p->tlv_type = MAP_TLV_AP_METRIC_QUERY; - p->bssid_nr = num_bss; - if (p->bssid_nr > 0) { - p->ap_metric_query_bssid = calloc(p->bssid_nr, - sizeof(*p->ap_metric_query_bssid)); - if (!p->ap_metric_query_bssid) { - free(p); - return NULL; - } - } - - for (i = 0; i < p->bssid_nr; i++) - memcpy(p->ap_metric_query_bssid[i].bssid, &bsslist[i * 6], 6); - - return p; + return NULL; +// uint8_t i; +// struct tlv_ap_metric_query *p; +// +// p = calloc(1, sizeof(*p)); +// if (!p) +// return NULL; +// +// p->tlv_type = MAP_TLV_AP_METRIC_QUERY; +// p->bssid_nr = num_bss; +// if (p->bssid_nr > 0) { +// p->ap_metric_query_bssid = calloc(p->bssid_nr, +// sizeof(*p->ap_metric_query_bssid)); +// if (!p->ap_metric_query_bssid) { +// free(p); +// return NULL; +// } +// } +// +// for (i = 0; i < p->bssid_nr; i++) +// memcpy(p->ap_metric_query_bssid[i].bssid, &bsslist[i * 6], 6); +// +// return p; } struct tlv_sta_mac *cntlr_gen_sta_mac(struct controller *c, uint8_t *sta) { - struct tlv_sta_mac *p; - - if (!sta) - return NULL; - - p = calloc(1, sizeof(*p)); - if (!p) - return NULL; - - p->tlv_type = MAP_TLV_STA_MAC_ADDRESS; - memcpy(p->addr, sta, 6); - - return p; + return NULL; +// struct tlv_sta_mac *p; +// +// if (!sta) +// return NULL; +// +// p = calloc(1, sizeof(*p)); +// if (!p) +// return NULL; +// +// p->tlv_type = MAP_TLV_STA_MAC_ADDRESS; +// memcpy(p->addr, sta, 6); +// +// return p; } struct tlv_searched_role *cntlr_gen_searched_role(struct controller *c, uint8_t role) { - struct tlv_searched_role *p; - - p = calloc(1, sizeof(struct tlv_searched_role)); - if (!p) - return NULL; - - p->tlv_type = TLV_TYPE_SEARCHED_ROLE; - p->role = role; - - return p; + return NULL; +// struct tlv_searched_role *p; +// +// p = calloc(1, sizeof(struct tlv_searched_role)); +// if (!p) +// return NULL; +// +// p->tlv_type = TLV_TYPE_SEARCHED_ROLE; +// p->role = role; +// +// return p; } struct tlv_autoconf_freq_band *cntlr_gen_autoconf_freq_band(struct controller *c, uint8_t band) { - struct tlv_autoconf_freq_band *p; - - p = calloc(1, sizeof(struct tlv_autoconf_freq_band)); - if (!p) - return NULL; - - p->tlv_type = TLV_TYPE_AUTOCONFIG_FREQ_BAND; - p->freq_band = band; - - return p; + return NULL; +// struct tlv_autoconf_freq_band *p; +// +// p = calloc(1, sizeof(struct tlv_autoconf_freq_band)); +// if (!p) +// return NULL; +// +// p->tlv_type = TLV_TYPE_AUTOCONFIG_FREQ_BAND; +// p->freq_band = band; +// +// return p; } diff --git a/src/core/cntlr_tlv_generator.h b/src/core/cntlr_tlv_generator.h index 06d93714ced3815ba7b30b217a3ae2d606e7a1b6..cca6f7a9cd248930b0db708593cfb20d58757b28 100644 --- a/src/core/cntlr_tlv_generator.h +++ b/src/core/cntlr_tlv_generator.h @@ -10,36 +10,37 @@ #ifndef CNTLR_TLV_GEN_H #define CNTLR_TLV_GEN_H -uint8_t *extract_tlv_by_type(struct cmdu_cstruct *cmdu, uint8_t tlv_type); -struct tlv_default_8021q_settings *cntlr_gen_8021q_settings(struct controller *c, +uint8_t *extract_tlv_by_type(struct cmdu_buff *cmdu, uint8_t tlv_type); +int cntlr_gen_8021q_settings(struct controller *c, struct cmdu_buff *frm, struct agent_policy *a); -struct tlv_traffic_sep_policy *cntlr_gen_traffic_sep_policy(struct controller *c, - struct cmdu_cstruct *cmdu); -struct tlv_wsc *cntlr_gen_wsc(struct controller *c, - struct cmdu_cstruct *cmdu, struct cmdu_cstruct *rec_cmdu, - struct iface_credential *fh); -struct tlv_ap_radio_identifier *cntlr_gen_ap_radio_identifier(struct controller *c, - struct cmdu_cstruct *cmdu, uint8_t *hwaddr); -struct tlv_supp_service *cntlr_gen_supp_service(struct controller *c, - struct cmdu_cstruct *cmdu); -struct tlv_map_profile *cntlr_gen_map_profile(struct controller *c, - struct cmdu_cstruct *cmdu); +int cntlr_gen_traffic_sep_policy(struct controller *c, struct cmdu_buff *frm); +int cntlr_gen_wsc(struct controller *c, struct cmdu_buff *frm, + struct iface_credential *iface_cred, uint8_t *msg, uint16_t msglen, + uint8_t band); +int cntlr_gen_ap_radio_identifier(struct controller *c, struct cmdu_buff *frm, + uint8_t *hwaddr); +int cntlr_gen_supp_role(struct controller *c, struct cmdu_buff *frm, + uint8_t role); +int cntlr_gen_supp_service(struct controller *c, struct cmdu_buff *cmdu, + uint8_t service); +int cntlr_gen_map_profile(struct controller *c, struct cmdu_buff *frm, + uint8_t profile); struct tlv_steering_policy *cntlr_gen_steering_policy(struct controller *c, - struct agent_policy *a, struct cmdu_cstruct *cmdu, + struct agent_policy *a, struct cmdu_buff *cmdu, int num_radio, uint8_t *radiolist); struct tlv_metric_report_policy *cntlr_gen_metric_report_policy(struct controller *c, - struct agent_policy *a, struct cmdu_cstruct *cmdu, + struct agent_policy *a, struct cmdu_buff *cmdu, int num_radio, uint8_t *radiolist); struct tlv_ch_scan_rep_policy *cntlr_gen_ch_scan_rep_policy(struct controller *c, - struct agent_policy *a, struct cmdu_cstruct *cmdu); + struct agent_policy *a, struct cmdu_buff *cmdu); struct tlv_unsuccess_assoc_policy *cntlr_gen_unsuccess_assoc_policy( struct controller *c, struct agent_policy *a, - struct cmdu_cstruct *cmdu); + struct cmdu_buff *cmdu); struct tlv_backhaul_bss_config *cntlr_gen_backhaul_bss_config( struct controller *c, struct agent_policy *a, - struct cmdu_cstruct *cmdu, const uint8_t *bssid); + struct cmdu_buff *cmdu, const uint8_t *bssid); struct tlv_al_mac *cntlr_gen_al_mac(struct controller *c, uint8_t *hwaddr); -struct tlv_supported_freq_band *cntlr_gen_supported_freq_band(struct controller *c, +int cntlr_gen_supported_freq_band(struct controller *c, struct cmdu_buff *frm, uint8_t freq_band); struct tlv_supported_role *cntlr_gen_supported_role(struct controller *c, uint8_t role); @@ -48,7 +49,7 @@ struct tlv_client_info *cntlr_gen_client_info(struct controller *c, struct tlv_backhaul_steer_req *cntlr_gen_backhaul_steer_req(struct controller *c, uint8_t *bssid, uint8_t *bkhaul, uint8_t op_class, uint8_t channel); -struct tlv_steer_Req *cntlr_gen_client_steering_req( +struct tlv_steer_request *cntlr_gen_client_steering_req( char *bss_id, uint32_t steer_timeout, uint32_t sta_nr, char sta_id[][18], uint32_t bssid_nr, char target_bbsid[][18], uint32_t request_mode); @@ -56,7 +57,7 @@ struct tlv_profile2_steer_req *cntlr_gen_client_steering_req_pr2( char *bss_id, uint32_t steer_timeout, uint32_t sta_multi_nr, char sta_multi_id[][18], uint32_t bssid_multi_nr, char target_bbsid_multi[][18], uint32_t request_mode); -struct tlv_client_assoc_control_req *cntlr_gen_assoc_control_req( +struct tlv_client_assoc_ctrl_request *cntlr_gen_assoc_control_req( uint8_t *bss_id, uint32_t assoc_cntl_mode, uint32_t assoc_timeout, uint32_t sta_nr, uint8_t sta_id[][18]); struct tlv_ap_metric_query *cntlr_gen_ap_metric_query(struct controller *c, diff --git a/src/core/cntlr_ubus.c b/src/core/cntlr_ubus.c index bbe37e0133680cf24435cd1ef6b10e872118b4fc..a4717f4001b39a6acd30c341f22c48ac92316c03 100644 --- a/src/core/cntlr_ubus.c +++ b/src/core/cntlr_ubus.c @@ -21,8 +21,11 @@ #include <easy/easy.h> #include <wifi.h> // TODO: remove wifi.h -#include <map1905/map2.h> -#include <map1905/maputils.h> +#include <timer_impl.h> +#include <cmdu.h> +#include <1905_tlvs.h> +#include <map22.h> +#include <map_module22.h> #include "utils.h" #include "debug.h" @@ -33,7 +36,7 @@ #include "cntlr_ubus.h" #include "cntlr_tlv_generator.h" -#include "map_module.h" +//#include "map_module.h" #include "cntlr_tlv_generator.h" #include "cntlr_cmdu_generator.h" @@ -209,8 +212,6 @@ static const struct blobmsg_policy ap_metric_query_params[__AP_METRIC_QUERY_MAX] [AP_METRIC_QUERY_RADIO] = { .name = "radiolist", .type = BLOBMSG_TYPE_ARRAY }, }; -//void send_cmdu_cb(struct ubus_request *req, - enum { SCAN_POLICY_AGENT, SCAN_POLICY_RADIO, @@ -255,132 +256,6 @@ static const struct blobmsg_policy topology_query_params[__TOPOLOGY_QUERY_MAX] = [TOPOLOGY_QUERY_AGENT] = { .name = "agent", .type = BLOBMSG_TYPE_STRING }, }; -void send_cmdu_cb(struct ubus_request *req, - int type, struct blob_attr *msg) -{ - struct json_object *jobj = NULL; - struct json_object *tmp; - uint16_t *mid; - char *str; - - if (!msg || !req->priv) { - fprintf(stderr, "%s:Message recieved is NULL\n", __func__); - return; - } - - mid = (uint16_t *)req->priv; - - str = (char *)blobmsg_format_json_indent(msg, true, -1); - if (str) { - jobj = json_tokener_parse(str); - free(str); - } - - if (jobj == NULL) - return; - - if (json_object_object_get_ex(jobj, "mid", &tmp)) { - *mid = json_object_get_int(tmp); - fprintf(stdout, "%s:%d cntlr map-mid:%d\n", __func__, __LINE__, *mid); // typo || - } - - json_object_put(jobj); -} - -int send_cmdu(struct controller *c, - struct cmdu_cstruct *cmdu_data) -{ - char *tlv_data = NULL; - uint16_t tlv_data_len = 1; - uint16_t tlv_str_len = 0; - int copy_index; - struct blob_buf b = { 0 }; - char dst_addr[18] = { 0 }; - char *tlv_str = NULL; - uint8_t *ss = NULL; - uint16_t msgid = 0; - uint16_t len; - int ret = -1; - size_t i; - uint32_t id; - - fprintf(stdout, "|%s:%d| Entry\n", __func__, __LINE__); - - memset(&b, 0, sizeof(struct blob_buf)); - blob_buf_init(&b, 0); - - blobmsg_add_u32(&b, "type", cmdu_data->message_type); - blobmsg_add_string(&b, "egress", cmdu_data->intf_name); - if (cmdu_data->message_id) - blobmsg_add_u32(&b, "mid", cmdu_data->message_id); - - hwaddr_ntoa(cmdu_data->origin, dst_addr); - blobmsg_add_string(&b, "dst_macaddr", dst_addr); - - fprintf(stdout, "|%s:%d|cmdu:%s|dst:%s|num_tlvs:%d|egress:%s|\n", - __func__, __LINE__, - map_stringify_cmdu_type(cmdu_data->message_type), - dst_addr, cmdu_data->num_tlvs, cmdu_data->intf_name); - - if (cmdu_data->num_tlvs > 0) { - for (i = 0; i < cmdu_data->num_tlvs; i++) { - trace("CMDU type: %s\n", map_stringify_tlv_type(*cmdu_data->tlvs[i])); - - len = 0; - ss = map_put_tlv_cstruct(cmdu_data->tlvs[i], &len); - if (ss) { - tlv_str = (char *)calloc((2 * len) + 1, sizeof(char)); - if (!tlv_str) { - free(ss); - goto out; - } - btostr(ss, len, tlv_str); - tlv_str_len = 2 * len; - tlv_data_len += tlv_str_len; - tlv_data = realloc(tlv_data, tlv_data_len * sizeof(char)); - if (!tlv_data) { - fprintf(stderr, "%s:%d out of memory.!\n", - __func__, __LINE__); - free(ss); - goto out; - } - - copy_index = tlv_data_len - tlv_str_len - 1; - memcpy(tlv_data + copy_index, tlv_str, tlv_str_len); - free(ss); - free(tlv_str); - } - } - tlv_data[tlv_data_len - 1] = '\0'; - blobmsg_add_string(&b, "data", tlv_data); - if (tlv_data) - free(tlv_data); - - } - - if (ubus_lookup_id(c->ubus_ctx, "map.1905", &id)) { - fprintf(stderr, "[%s:%d] not present", __func__, __LINE__); - goto out; - } - - ret = ubus_invoke(c->ubus_ctx, id, "send", - b.head, send_cmdu_cb, - (void *)&msgid, - 1000); - if (ret) { - fprintf(stderr, "[%s:%d] ubus call failed for |map.1905 send|", - __func__, __LINE__); - goto out; - } - - ret = msgid; - - test_cmdu(cmdu_data); -out: - blob_buf_free(&b); - return ret; -} - static int cntlr_status(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) @@ -471,640 +346,647 @@ int cntlr_ap_caps(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - struct blob_attr *tb[__AP_POLICY_MAX]; - struct controller *c = container_of(obj, struct controller, obj); - uint8_t hwaddr[6] = {0}; - struct cmdu_cstruct *cmdu; - - blobmsg_parse(ap_caps_policy_params, __AP_POLICY_MAX, tb, - blob_data(msg), blob_len(msg)); - - if (tb[AP_POLICY_AGENT]) { - char agent[18] = {0}; - - strncpy(agent, blobmsg_data(tb[AP_POLICY_AGENT]), - sizeof(agent) - 1); - if (!hwaddr_aton(agent, hwaddr)) - return UBUS_STATUS_UNKNOWN_ERROR; - } - - - cmdu = cntlr_gen_ap_capability_query(c, hwaddr, NULL); - if (!cmdu) - return UBUS_STATUS_UNKNOWN_ERROR; - - send_cmdu(c, cmdu); - map_free_cmdu(cmdu); - return 0; +// struct blob_attr *tb[__AP_POLICY_MAX]; +// struct controller *c = container_of(obj, struct controller, obj); +// uint8_t hwaddr[6] = {0}; +// struct cmdu_cstruct *cmdu; +// +// blobmsg_parse(ap_caps_policy_params, __AP_POLICY_MAX, tb, +// blob_data(msg), blob_len(msg)); +// +// if (tb[AP_POLICY_AGENT]) { +// char agent[18] = {0}; +// +// strncpy(agent, blobmsg_data(tb[AP_POLICY_AGENT]), +// sizeof(agent) - 1); +// if (!hwaddr_aton(agent, hwaddr)) +// return UBUS_STATUS_UNKNOWN_ERROR; +// } +// +// +// cmdu = cntlr_gen_ap_capability_query(c, hwaddr, NULL); +// if (!cmdu) +// return UBUS_STATUS_UNKNOWN_ERROR; +// +// send_cmdu(c, cmdu); +// map_free_cmdu(cmdu); +// +// return 0; } static int cntlr_channel_pref(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - struct blob_attr *tb[__CHANNEL_PREF_POLICY_MAX]; - struct controller *c = container_of(obj, struct controller, obj); - char agent[18] = {0}; - struct cmdu_cstruct *cmdu_data; - - cmdu_data = (struct cmdu_cstruct *)calloc(1, - sizeof(struct cmdu_cstruct)); - if (!cmdu_data) { - fprintf(stderr, "failed to malloc cmdu\n"); - return UBUS_STATUS_UNKNOWN_ERROR; - } - - blobmsg_parse(channel_pref_policy_params, __CHANNEL_PREF_POLICY_MAX, tb, - blob_data(msg), blob_len(msg)); - - - if (tb[CHANNEL_PREF_POLICY_AGENT]) { - strncpy(agent, blobmsg_data(tb[CHANNEL_PREF_POLICY_AGENT]), - sizeof(agent) - 1); - if (!hwaddr_aton(agent, cmdu_data->origin)) - return UBUS_STATUS_UNKNOWN_ERROR; - } - - // TODO: ff:ff:ff:ff:ff:ff = send to all agents - - cmdu_data->message_type = CMDU_CHANNEL_PREFERENCE_QUERY; - cmdu_data->message_id = 2; - - cmdu_data->num_tlvs = 0; - - send_cmdu(c, cmdu_data); - return 0; +// struct blob_attr *tb[__CHANNEL_PREF_POLICY_MAX]; +// struct controller *c = container_of(obj, struct controller, obj); +// char agent[18] = {0}; +// struct cmdu_cstruct *cmdu_data; +// +// cmdu_data = (struct cmdu_cstruct *)calloc(1, +// sizeof(struct cmdu_cstruct)); +// if (!cmdu_data) { +// fprintf(stderr, "failed to malloc cmdu\n"); +// return UBUS_STATUS_UNKNOWN_ERROR; +// } +// +// blobmsg_parse(channel_pref_policy_params, __CHANNEL_PREF_POLICY_MAX, tb, +// blob_data(msg), blob_len(msg)); +// +// +// if (tb[CHANNEL_PREF_POLICY_AGENT]) { +// strncpy(agent, blobmsg_data(tb[CHANNEL_PREF_POLICY_AGENT]), +// sizeof(agent) - 1); +// if (!hwaddr_aton(agent, cmdu_data->origin)) +// return UBUS_STATUS_UNKNOWN_ERROR; +// } +// +// // TODO: ff:ff:ff:ff:ff:ff = send to all agents +// +// cmdu_data->message_type = CMDU_CHANNEL_PREFERENCE_QUERY; +// cmdu_data->message_id = 2; +// +// cmdu_data->num_tlvs = 0; +// +// send_cmdu(c, cmdu_data); +// +// return 0; } static int cntlr_channel_select(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - struct blob_attr *tb[__CHANNEL_SEL_POLICY_MAX]; - struct controller *c = container_of(obj, struct controller, obj); - struct tlv_channel_pref *p = NULL; - struct tlv_tx_power_limit *p1 = NULL; - uint32_t count = 0, tlv_index = 0, k = 0, j = 0; - char agent[18] = {0}; - char radio_id[18] = {0}; - uint32_t radio_present = 0; - uint32_t class_id = -1; - uint32_t channel_nr = 0, pref = -1, transmit_power = -1; - uint32_t channel[20]; - struct cmdu_cstruct *cmdu_data; - struct blob_attr *cur; - int rem, l = 0; - - cmdu_data = (struct cmdu_cstruct *)calloc(1, - sizeof(struct cmdu_cstruct)); - - if (!cmdu_data) { - fprintf(stderr, "failed to malloc cmdu\n"); - return UBUS_STATUS_UNKNOWN_ERROR; - } - - blobmsg_parse(channel_select_policy_params, __CHANNEL_SEL_POLICY_MAX, - tb, blob_data(msg), blob_len(msg)); - - if (tb[CHANNEL_SEL_POLICY_AGENT]) { - strncpy(agent, blobmsg_data(tb[CHANNEL_SEL_POLICY_AGENT]), - sizeof(agent) - 1); - if (!hwaddr_aton(agent, cmdu_data->origin)) - goto fail_cmdu; - } - - // TODO: ff:ff:ff:ff:ff:ff = send to all agents - if (tb[CHANNEL_SEL_POLICY_RADIO_ID]) { - strncpy(radio_id, blobmsg_data(tb[CHANNEL_SEL_POLICY_RADIO_ID]), - sizeof(radio_id) - 1); - radio_present = 1; - } - - if (tb[CHANNEL_SEL_POLICY_CLASS_ID]) - class_id = (int) blobmsg_get_u32(tb[CHANNEL_SEL_POLICY_CLASS_ID]); - - if (tb[CHANNEL_SEL_POLICY_CHANNEL]) { - channel_nr = blobmsg_check_array(tb[CHANNEL_SEL_POLICY_CHANNEL], - BLOBMSG_TYPE_INT32); - l = 0; - blobmsg_for_each_attr(cur, tb[CHANNEL_SEL_POLICY_CHANNEL], rem) - channel[l++] = blobmsg_get_u32(cur); - } - - if (tb[CHANNEL_SEL_POLICY_PREF]) - pref = (int) blobmsg_get_u32(tb[CHANNEL_SEL_POLICY_PREF]); - - if (tb[CHANNEL_SEL_POLICY_TRANSMIT_POWER]) - transmit_power = (int) blobmsg_get_u32 - (tb[CHANNEL_SEL_POLICY_TRANSMIT_POWER]); - - cmdu_data->message_type = CMDU_CHANNEL_SELECTION_REQ; - - if (radio_present == 1 && class_id != -1 && pref != -1) { - p = calloc(1, sizeof(struct tlv_channel_pref)); - if (!p) { - fprintf(stderr, "failed to malloc cmdu\n"); - goto fail_cmdu; - } - - p->tlv_type = MAP_TLV_CHANNEL_PREFERENCE; - - hwaddr_aton(radio_id, p->radio_id); - p->ch_preference_op_class_nr = 1; - - if (p->ch_preference_op_class_nr > 0) - p->op_class = calloc(p->ch_preference_op_class_nr, - sizeof(*p->op_class)); - - if (!p->op_class) { - fprintf(stderr, "|%s:%d| out of memory!\n", __func__, __LINE__); - p->ch_preference_op_class_nr = 0; - goto fail_p; - } - - for (j = 0; j < p->ch_preference_op_class_nr; j++) { - p->op_class[j].op_class = (uint8_t)class_id; - p->op_class[j].channel_list = NULL; - if (channel_nr != 0) - p->op_class[j].channel_nr = channel_nr; - - if (p->op_class[j].channel_nr > 0) { - - p->op_class[j].channel_list = - calloc(p->op_class[j].channel_nr, - sizeof(uint8_t)); - - if (!p->op_class[j].channel_list) { - fprintf(stderr, "|%s:%d| out of memory!\n", - __func__, __LINE__); - p->op_class[j].channel_nr = 0; - goto fail_p; - } - for (k = 0; k < p->op_class[j].channel_nr; k++) - p->op_class[j].channel_list[k] = (uint8_t) channel[k]; - } - p->op_class[j].preference = (uint8_t) pref; - p->op_class[j].preference_reason = 0x00; - } - count++; - } - - if (radio_present == 1 && transmit_power != -1) { - p1 = calloc(1, sizeof(struct tlv_tx_power_limit)); - if (!p1) { - fprintf(stderr, "failed to malloc cmdu\n"); - goto fail_p; - } - - p1->tlv_type = MAP_TLV_TRANSMIT_POWER_LIMIT; - hwaddr_aton(radio_id, p1->radio_id); - p1->tx_power_limit = (uint8_t)transmit_power; - count++; - } - - cmdu_data->num_tlvs = count; - if (count) - cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, - sizeof(uint8_t *)); - if (cmdu_data->tlvs && p != NULL) - cmdu_data->tlvs[tlv_index++] = (uint8_t *)p; - - if (cmdu_data->tlvs && p1 != NULL) - cmdu_data->tlvs[tlv_index++] = (uint8_t *)p1; - - send_cmdu(c, cmdu_data); - map_free_cmdu(cmdu_data); return 0; -fail_p: - map_free_tlv_cstruct((uint8_t *) p); -fail_cmdu: - map_free_cmdu(cmdu_data); - return UBUS_STATUS_UNKNOWN_ERROR; +// struct blob_attr *tb[__CHANNEL_SEL_POLICY_MAX]; +// struct controller *c = container_of(obj, struct controller, obj); +// struct tlv_channel_pref *p = NULL; +// struct tlv_tx_power_limit *p1 = NULL; +// uint32_t count = 0, tlv_index = 0, k = 0, j = 0; +// char agent[18] = {0}; +// char radio_id[18] = {0}; +// uint32_t radio_present = 0; +// uint32_t class_id = -1; +// uint32_t channel_nr = 0, pref = -1, transmit_power = -1; +// uint32_t channel[20]; +// struct cmdu_cstruct *cmdu_data; +// struct blob_attr *cur; +// int rem, l = 0; +// +// cmdu_data = (struct cmdu_cstruct *)calloc(1, +// sizeof(struct cmdu_cstruct)); +// +// if (!cmdu_data) { +// fprintf(stderr, "failed to malloc cmdu\n"); +// return UBUS_STATUS_UNKNOWN_ERROR; +// } +// +// blobmsg_parse(channel_select_policy_params, __CHANNEL_SEL_POLICY_MAX, +// tb, blob_data(msg), blob_len(msg)); +// +// if (tb[CHANNEL_SEL_POLICY_AGENT]) { +// strncpy(agent, blobmsg_data(tb[CHANNEL_SEL_POLICY_AGENT]), +// sizeof(agent) - 1); +// if (!hwaddr_aton(agent, cmdu_data->origin)) +// goto fail_cmdu; +// } +// +// // TODO: ff:ff:ff:ff:ff:ff = send to all agents +// if (tb[CHANNEL_SEL_POLICY_RADIO_ID]) { +// strncpy(radio_id, blobmsg_data(tb[CHANNEL_SEL_POLICY_RADIO_ID]), +// sizeof(radio_id) - 1); +// radio_present = 1; +// } +// +// if (tb[CHANNEL_SEL_POLICY_CLASS_ID]) +// class_id = (int) blobmsg_get_u32(tb[CHANNEL_SEL_POLICY_CLASS_ID]); +// +// if (tb[CHANNEL_SEL_POLICY_CHANNEL]) { +// channel_nr = blobmsg_check_array(tb[CHANNEL_SEL_POLICY_CHANNEL], +// BLOBMSG_TYPE_INT32); +// l = 0; +// blobmsg_for_each_attr(cur, tb[CHANNEL_SEL_POLICY_CHANNEL], rem) +// channel[l++] = blobmsg_get_u32(cur); +// } +// +// if (tb[CHANNEL_SEL_POLICY_PREF]) +// pref = (int) blobmsg_get_u32(tb[CHANNEL_SEL_POLICY_PREF]); +// +// if (tb[CHANNEL_SEL_POLICY_TRANSMIT_POWER]) +// transmit_power = (int) blobmsg_get_u32 +// (tb[CHANNEL_SEL_POLICY_TRANSMIT_POWER]); +// +// cmdu_data->message_type = CMDU_CHANNEL_SELECTION_REQ; +// +// if (radio_present == 1 && class_id != -1 && pref != -1) { +// p = calloc(1, sizeof(struct tlv_channel_pref)); +// if (!p) { +// fprintf(stderr, "failed to malloc cmdu\n"); +// goto fail_cmdu; +// } +// +// p->tlv_type = MAP_TLV_CHANNEL_PREFERENCE; +// +// hwaddr_aton(radio_id, p->radio_id); +// p->ch_preference_op_class_nr = 1; +// +// if (p->ch_preference_op_class_nr > 0) +// p->op_class = calloc(p->ch_preference_op_class_nr, +// sizeof(*p->op_class)); +// +// if (!p->op_class) { +// fprintf(stderr, "|%s:%d| out of memory!\n", __func__, __LINE__); +// p->ch_preference_op_class_nr = 0; +// goto fail_p; +// } +// +// for (j = 0; j < p->ch_preference_op_class_nr; j++) { +// p->op_class[j].op_class = (uint8_t)class_id; +// p->op_class[j].channel_list = NULL; +// if (channel_nr != 0) +// p->op_class[j].channel_nr = channel_nr; +// +// if (p->op_class[j].channel_nr > 0) { +// +// p->op_class[j].channel_list = +// calloc(p->op_class[j].channel_nr, +// sizeof(uint8_t)); +// +// if (!p->op_class[j].channel_list) { +// fprintf(stderr, "|%s:%d| out of memory!\n", +// __func__, __LINE__); +// p->op_class[j].channel_nr = 0; +// goto fail_p; +// } +// for (k = 0; k < p->op_class[j].channel_nr; k++) +// p->op_class[j].channel_list[k] = (uint8_t) channel[k]; +// } +// p->op_class[j].preference = (uint8_t) pref; +// p->op_class[j].preference_reason = 0x00; +// } +// count++; +// } +// +// if (radio_present == 1 && transmit_power != -1) { +// p1 = calloc(1, sizeof(struct tlv_tx_power_limit)); +// if (!p1) { +// fprintf(stderr, "failed to malloc cmdu\n"); +// goto fail_p; +// } +// +// p1->tlv_type = MAP_TLV_TRANSMIT_POWER_LIMIT; +// hwaddr_aton(radio_id, p1->radio_id); +// p1->tx_power_limit = (uint8_t)transmit_power; +// count++; +// } +// +// cmdu_data->num_tlvs = count; +// if (count) +// cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, +// sizeof(uint8_t *)); +// if (cmdu_data->tlvs && p != NULL) +// cmdu_data->tlvs[tlv_index++] = (uint8_t *)p; +// +// if (cmdu_data->tlvs && p1 != NULL) +// cmdu_data->tlvs[tlv_index++] = (uint8_t *)p1; +// +// send_cmdu(c, cmdu_data); +// map_free_cmdu(cmdu_data); +// return 0; +//fail_p: +// map_free_tlv_cstruct((uint8_t *) p); +//fail_cmdu: +// map_free_cmdu(cmdu_data); +// return UBUS_STATUS_UNKNOWN_ERROR; } static int cntlr_client_steering(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - struct blob_attr *tb[__STEERING_POLICY_MAX]; - struct controller *c = container_of(obj, struct controller, obj); - char agent[18] = {0}; - char bss_id[18] = {0}; - char sta_id[30][18] = {0}; - char sta_multi_id[30][18] = {0}; - char target_bbsid[30][18] = {0}; - char target_bbsid_multi[30][18] = {0}; - char to_id[18] = {0}; - struct cmdu_cstruct *cmdu_data; - uint32_t timeout = 0; - struct tlv_steer_Req *p = NULL; - struct tlv_profile2_steer_req *p1 = NULL; - uint32_t sta_nr = 0, bssid_nr = 0, sta_multi_nr = 0, bssid_multi_nr = 0; - uint32_t request_mode = 0, request_mode_present = -1, tlv_index = 0; - uint32_t sta_present = -1, sta_multi_present = -1, bssid_present = -1; - uint32_t target_bssid_present = -1, target_bssid_multi_present = -1; - struct blob_attr *cur; - int rem, l = 0, j = 0, count = 0; - uint32_t steer_timeout = 0, btm_timeout = 0; - - cmdu_data = (struct cmdu_cstruct *)calloc(1, - sizeof(struct cmdu_cstruct)); - - if (!cmdu_data) { - fprintf(stderr, "failed to malloc cmdu\n"); - return UBUS_STATUS_UNKNOWN_ERROR; - } - - blobmsg_parse(client_steering_policy_params, __STEERING_POLICY_MAX, tb, - blob_data(msg), blob_len(msg)); - - if (tb[STEERING_POLICY_AGENT]) { - strncpy(agent, blobmsg_data(tb[STEERING_POLICY_AGENT]), - sizeof(agent) - 1); - if (!hwaddr_aton(agent, cmdu_data->origin)) - goto fail_cmdu; - } - // TODO: ff:ff:ff:ff:ff:ff = send to all agents - - if (tb[STEERING_POLICY_FROM_BSSID]) { - strncpy(bss_id, blobmsg_data(tb[STEERING_POLICY_FROM_BSSID]), - sizeof(bss_id) - 1); - bssid_present = 1; - } - - if (tb[STEERING_POLICY_STA]) { - sta_present = 1; - sta_nr = blobmsg_check_array(tb[STEERING_POLICY_STA], - BLOBMSG_TYPE_STRING); - l = 0; - blobmsg_for_each_attr(cur, tb[STEERING_POLICY_STA], rem) - strncpy(sta_id[l++], blobmsg_get_string(cur), 18); - } - - if (tb[STEERING_POLICY_TARGET_BSSID]) { - target_bssid_present = 1; - bssid_nr = blobmsg_check_array(tb[STEERING_POLICY_TARGET_BSSID], - BLOBMSG_TYPE_STRING); - l = 0; - blobmsg_for_each_attr(cur, tb[STEERING_POLICY_TARGET_BSSID], rem) - strncpy(target_bbsid[l++], blobmsg_get_string(cur), 18); - } - - if (tb[STEERING_POLICY_STEER_TIMEOUT]) - steer_timeout = (int) blobmsg_get_u32( - tb[STEERING_POLICY_STEER_TIMEOUT]); - - if (tb[STEERING_POLICY_REQUEST_MODE]) { - request_mode = blobmsg_get_bool(tb[STEERING_POLICY_REQUEST_MODE]); - request_mode_present = 1; - } - - if (tb[STEERING_POLICY_BTM_TIMEOUT]) - btm_timeout = (int) blobmsg_get_u32(tb[STEERING_POLICY_BTM_TIMEOUT]); - -#if PROFILE2 - - if (tb[STEERING_POLICY_TARGET_BSSID_MULTIBAND]) { - target_bssid_multi_present = 1; - bssid_multi_nr = blobmsg_check_array( - tb[STEERING_POLICY_TARGET_BSSID_MULTIBAND], - BLOBMSG_TYPE_INT32); - l = 0; - blobmsg_for_each_attr(cur, - tb[STEERING_POLICY_TARGET_BSSID_MULTIBAND], rem) - strncpy(target_bbsid_multi[l++], - blobmsg_get_string(cur), 18); - } - - if (tb[STEERING_POLICY_STA_MULTIBAND]) { - sta_multi_present = 1; - sta_multi_nr = blobmsg_check_array(tb[STEERING_POLICY_STA_MULTIBAND], - BLOBMSG_TYPE_INT32); - l = 0; - blobmsg_for_each_attr(cur, tb[STEERING_POLICY_STA_MULTIBAND], rem) - strncpy(sta__multi_id[l++], blobmsg_get_string(cur), 18); - } - -#endif - - cmdu_data->message_type = CMDU_CLIENT_STEERING_REQUEST; - - if (bssid_present == 1 && request_mode_present == 1) { - trace("values are requestmode %d timeout %d sta_cnt %d bssid_nr %d\n", - request_mode, timeout, sta_nr, - bssid_nr); - - /* Client Steering Request TLV */ - p = cntlr_gen_client_steering_req(bss_id, steer_timeout, - sta_nr, sta_id, bssid_nr, - target_bbsid, request_mode); - if (!p) - goto fail_cmdu; - - count++; - } - -#if PROFILE2 - - //Here we need to add tlv for 17.2.57 - if (bssid_present == 1 && request_mode_present != 1 && - (target_bssid_multi_present != -1 || - sta_multi_present != -1)) { - - /* Client Steering Request TLV 17.2.57 */ - p1 = cntlr_gen_client_steering_req_pr2(bss_id, steer_timeout, - sta_multi_nr, sta_multi_id, bssid_multi_nr, - target_bbsid_multi, request_mode); - if (!p1) - goto fail_cmdu; - - count++; - } - -#endif - cmdu_data->num_tlvs = count; - //strcpy(cmdu_data->intf_name,"lo"); - -#ifndef PROFILE2 - //Here we need to check that in profile 1 atleast 1 tlv - //should be there to send the CMDU - if (cmdu_data->num_tlvs == 0) { - fprintf(stderr, "|%s:%d| No TLvs\n", __func__, __LINE__); - return UBUS_STATUS_UNKNOWN_ERROR; - } -#endif - cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, - sizeof(uint8_t *)); - if (cmdu_data->tlvs && p != NULL) - cmdu_data->tlvs[tlv_index++] = (uint8_t *)p; - if (cmdu_data->tlvs && p1 != NULL) - cmdu_data->tlvs[tlv_index++] = (uint8_t *)p1; - send_cmdu(c, cmdu_data); - map_free_cmdu(cmdu_data); return 0; - -fail_cmdu: - map_free_cmdu(cmdu_data); - return UBUS_STATUS_UNKNOWN_ERROR; +// struct blob_attr *tb[__STEERING_POLICY_MAX]; +// struct controller *c = container_of(obj, struct controller, obj); +// char agent[18] = {0}; +// char bss_id[18] = {0}; +// char sta_id[30][18] = {0}; +// char sta_multi_id[30][18] = {0}; +// char target_bbsid[30][18] = {0}; +// char target_bbsid_multi[30][18] = {0}; +// char to_id[18] = {0}; +// struct cmdu_cstruct *cmdu_data; +// uint32_t timeout = 0; +// struct tlv_steer_Req *p = NULL; +// struct tlv_profile2_steer_req *p1 = NULL; +// uint32_t sta_nr = 0, bssid_nr = 0, sta_multi_nr = 0, bssid_multi_nr = 0; +// uint32_t request_mode = 0, request_mode_present = -1, tlv_index = 0; +// uint32_t sta_present = -1, sta_multi_present = -1, bssid_present = -1; +// uint32_t target_bssid_present = -1, target_bssid_multi_present = -1; +// struct blob_attr *cur; +// int rem, l = 0, j = 0, count = 0; +// uint32_t steer_timeout = 0, btm_timeout = 0; +// +// cmdu_data = (struct cmdu_cstruct *)calloc(1, +// sizeof(struct cmdu_cstruct)); +// +// if (!cmdu_data) { +// fprintf(stderr, "failed to malloc cmdu\n"); +// return UBUS_STATUS_UNKNOWN_ERROR; +// } +// +// blobmsg_parse(client_steering_policy_params, __STEERING_POLICY_MAX, tb, +// blob_data(msg), blob_len(msg)); +// +// if (tb[STEERING_POLICY_AGENT]) { +// strncpy(agent, blobmsg_data(tb[STEERING_POLICY_AGENT]), +// sizeof(agent) - 1); +// if (!hwaddr_aton(agent, cmdu_data->origin)) +// goto fail_cmdu; +// } +// // TODO: ff:ff:ff:ff:ff:ff = send to all agents +// +// if (tb[STEERING_POLICY_FROM_BSSID]) { +// strncpy(bss_id, blobmsg_data(tb[STEERING_POLICY_FROM_BSSID]), +// sizeof(bss_id) - 1); +// bssid_present = 1; +// } +// +// if (tb[STEERING_POLICY_STA]) { +// sta_present = 1; +// sta_nr = blobmsg_check_array(tb[STEERING_POLICY_STA], +// BLOBMSG_TYPE_STRING); +// l = 0; +// blobmsg_for_each_attr(cur, tb[STEERING_POLICY_STA], rem) +// strncpy(sta_id[l++], blobmsg_get_string(cur), 18); +// } +// +// if (tb[STEERING_POLICY_TARGET_BSSID]) { +// target_bssid_present = 1; +// bssid_nr = blobmsg_check_array(tb[STEERING_POLICY_TARGET_BSSID], +// BLOBMSG_TYPE_STRING); +// l = 0; +// blobmsg_for_each_attr(cur, tb[STEERING_POLICY_TARGET_BSSID], rem) +// strncpy(target_bbsid[l++], blobmsg_get_string(cur), 18); +// } +// +// if (tb[STEERING_POLICY_STEER_TIMEOUT]) +// steer_timeout = (int) blobmsg_get_u32( +// tb[STEERING_POLICY_STEER_TIMEOUT]); +// +// if (tb[STEERING_POLICY_REQUEST_MODE]) { +// request_mode = blobmsg_get_bool(tb[STEERING_POLICY_REQUEST_MODE]); +// request_mode_present = 1; +// } +// +// if (tb[STEERING_POLICY_BTM_TIMEOUT]) +// btm_timeout = (int) blobmsg_get_u32(tb[STEERING_POLICY_BTM_TIMEOUT]); +// +//#if PROFILE2 +// +// if (tb[STEERING_POLICY_TARGET_BSSID_MULTIBAND]) { +// target_bssid_multi_present = 1; +// bssid_multi_nr = blobmsg_check_array( +// tb[STEERING_POLICY_TARGET_BSSID_MULTIBAND], +// BLOBMSG_TYPE_INT32); +// l = 0; +// blobmsg_for_each_attr(cur, +// tb[STEERING_POLICY_TARGET_BSSID_MULTIBAND], rem) +// strncpy(target_bbsid_multi[l++], +// blobmsg_get_string(cur), 18); +// } +// +// if (tb[STEERING_POLICY_STA_MULTIBAND]) { +// sta_multi_present = 1; +// sta_multi_nr = blobmsg_check_array(tb[STEERING_POLICY_STA_MULTIBAND], +// BLOBMSG_TYPE_INT32); +// l = 0; +// blobmsg_for_each_attr(cur, tb[STEERING_POLICY_STA_MULTIBAND], rem) +// strncpy(sta__multi_id[l++], blobmsg_get_string(cur), 18); +// } +// +//#endif +// +// cmdu_data->message_type = CMDU_CLIENT_STEERING_REQUEST; +// +// if (bssid_present == 1 && request_mode_present == 1) { +// trace("values are requestmode %d timeout %d sta_cnt %d bssid_nr %d\n", +// request_mode, timeout, sta_nr, +// bssid_nr); +// +// /* Client Steering Request TLV */ +// p = cntlr_gen_client_steering_req(bss_id, steer_timeout, +// sta_nr, sta_id, bssid_nr, +// target_bbsid, request_mode); +// if (!p) +// goto fail_cmdu; +// +// count++; +// } +// +//#if PROFILE2 +// +// //Here we need to add tlv for 17.2.57 +// if (bssid_present == 1 && request_mode_present != 1 && +// (target_bssid_multi_present != -1 || +// sta_multi_present != -1)) { +// +// /* Client Steering Request TLV 17.2.57 */ +// p1 = cntlr_gen_client_steering_req_pr2(bss_id, steer_timeout, +// sta_multi_nr, sta_multi_id, bssid_multi_nr, +// target_bbsid_multi, request_mode); +// if (!p1) +// goto fail_cmdu; +// +// count++; +// } +// +//#endif +// cmdu_data->num_tlvs = count; +// //strcpy(cmdu_data->intf_name,"lo"); +// +//#ifndef PROFILE2 +// //Here we need to check that in profile 1 atleast 1 tlv +// //should be there to send the CMDU +// if (cmdu_data->num_tlvs == 0) { +// fprintf(stderr, "|%s:%d| No TLvs\n", __func__, __LINE__); +// return UBUS_STATUS_UNKNOWN_ERROR; +// } +//#endif +// cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, +// sizeof(uint8_t *)); +// if (cmdu_data->tlvs && p != NULL) +// cmdu_data->tlvs[tlv_index++] = (uint8_t *)p; +// if (cmdu_data->tlvs && p1 != NULL) +// cmdu_data->tlvs[tlv_index++] = (uint8_t *)p1; +// send_cmdu(c, cmdu_data); +// map_free_cmdu(cmdu_data); +// return 0; +// +//fail_cmdu: +// map_free_cmdu(cmdu_data); +// return UBUS_STATUS_UNKNOWN_ERROR; } static int client_assoc_cntlr(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - struct blob_attr *tb[__CLIENT_POLICY_ASSOC_CONTROL_MAX]; - struct controller *c = container_of(obj, struct controller, obj); - char agent[18] = {0}; - char bss_id[18] = {0}; - struct cmdu_cstruct *cmdu_data; - uint32_t assoc_cntl_mode = 0, assoc_timeout = 0, sta_nr = 0; - uint32_t bssid_present = -1, sta_present = -1; - uint32_t assoc_timeout_present = -1, tlv_index = 0; - char sta_id[30][18] = {0}; - struct tlv_client_assoc_control_req *p = NULL; - uint32_t count = 0, j = 0, l = 0; - struct blob_attr *cur; - int rem = 0; - - cmdu_data = (struct cmdu_cstruct *)calloc(1, - sizeof(struct cmdu_cstruct)); - if (!cmdu_data) { - fprintf(stderr, "failed to malloc cmdu\n"); - return UBUS_STATUS_UNKNOWN_ERROR; - } - - blobmsg_parse(client_assoc_cntrl_policy_config_params, - __CLIENT_POLICY_ASSOC_CONTROL_MAX, tb, - blob_data(msg), blob_len(msg)); - - if (tb[CLIENT_POLICY_ASSOC_CONTROL_AGENT]) { - strncpy(agent, blobmsg_data(tb[CLIENT_POLICY_ASSOC_CONTROL_AGENT]), - sizeof(agent) - 1); - if (!hwaddr_aton(agent, cmdu_data->origin)) - return UBUS_STATUS_UNKNOWN_ERROR; - } - // TODO: ff:ff:ff:ff:ff:ff = send to all agents - - if (tb[CLIENT_POLICY_ASSOC_CONTROL_BSSID]) { - strncpy(bss_id, blobmsg_data(tb[CLIENT_POLICY_ASSOC_CONTROL_BSSID]), - sizeof(bss_id) - 1); - bssid_present = 1; - } - - if (tb[CLIENT_POLICY_ASSOC_CONTROL_MODE]) - assoc_cntl_mode = (int) blobmsg_get_u32( - tb[CLIENT_POLICY_ASSOC_CONTROL_MODE]); - - if (tb[CLIENT_POLICY_ASSOC_CONTROL_VALID_TIME]) { - assoc_timeout_present = 1; - assoc_timeout = (int) blobmsg_get_u32( - tb[CLIENT_POLICY_ASSOC_CONTROL_VALID_TIME]); - } - - if (tb[CLIENT_POLICY_ASSOC_CONTROL_STALIST]) { - sta_present = 1; - sta_nr = blobmsg_check_array(tb[CLIENT_POLICY_ASSOC_CONTROL_STALIST], - BLOBMSG_TYPE_STRING); - l = 0; - blobmsg_for_each_attr(cur, tb[CLIENT_POLICY_ASSOC_CONTROL_STALIST], rem) - strncpy(sta_id[l++], blobmsg_get_string(cur), 18); - } - - cmdu_data->message_type = CMDU_CLIENT_ASSOC_CONTROL_REQUEST; - - if (bssid_present == 1 && sta_present == 1 && assoc_timeout_present == 1 - && assoc_cntl_mode >= 0) { - - trace("values are assoc_mode %d assoc_timeout %d sta_cnt %d\n", - assoc_cntl_mode, assoc_timeout, sta_nr); - /* Client ASSOC CONTROL TLV REQUEST 17.2.31 */ - p = cntlr_gen_assoc_control_req(bss_id, assoc_cntl_mode, - assoc_timeout, sta_nr, sta_id); - if (!p) - goto fail_cmdu; - count++; - } - - cmdu_data->num_tlvs = count; - - /*This CMDU has one or more TLVs*/ - if (cmdu_data->num_tlvs == 0) { - fprintf(stderr, "|%s:%d| No TLvs\n", __func__, __LINE__); - goto fail_cmdu; - } - - cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, - sizeof(uint8_t *)); - if (cmdu_data->tlvs && p != NULL) - cmdu_data->tlvs[tlv_index++] = (uint8_t *)p; - send_cmdu(c, cmdu_data); - map_free_cmdu(cmdu_data); return 0; -fail_p: - if (p != NULL) - map_free_tlv_cstruct((uint8_t *) p); -fail_cmdu: - map_free_cmdu(cmdu_data); - return UBUS_STATUS_UNKNOWN_ERROR; +// struct blob_attr *tb[__CLIENT_POLICY_ASSOC_CONTROL_MAX]; +// struct controller *c = container_of(obj, struct controller, obj); +// char agent[18] = {0}; +// char bss_id[18] = {0}; +// struct cmdu_cstruct *cmdu_data; +// uint32_t assoc_cntl_mode = 0, assoc_timeout = 0, sta_nr = 0; +// uint32_t bssid_present = -1, sta_present = -1; +// uint32_t assoc_timeout_present = -1, tlv_index = 0; +// char sta_id[30][18] = {0}; +// struct tlv_client_assoc_control_req *p = NULL; +// uint32_t count = 0, j = 0, l = 0; +// struct blob_attr *cur; +// int rem = 0; +// +// cmdu_data = (struct cmdu_cstruct *)calloc(1, +// sizeof(struct cmdu_cstruct)); +// if (!cmdu_data) { +// fprintf(stderr, "failed to malloc cmdu\n"); +// return UBUS_STATUS_UNKNOWN_ERROR; +// } +// +// blobmsg_parse(client_assoc_cntrl_policy_config_params, +// __CLIENT_POLICY_ASSOC_CONTROL_MAX, tb, +// blob_data(msg), blob_len(msg)); +// +// if (tb[CLIENT_POLICY_ASSOC_CONTROL_AGENT]) { +// strncpy(agent, blobmsg_data(tb[CLIENT_POLICY_ASSOC_CONTROL_AGENT]), +// sizeof(agent) - 1); +// if (!hwaddr_aton(agent, cmdu_data->origin)) +// return UBUS_STATUS_UNKNOWN_ERROR; +// } +// // TODO: ff:ff:ff:ff:ff:ff = send to all agents +// +// if (tb[CLIENT_POLICY_ASSOC_CONTROL_BSSID]) { +// strncpy(bss_id, blobmsg_data(tb[CLIENT_POLICY_ASSOC_CONTROL_BSSID]), +// sizeof(bss_id) - 1); +// bssid_present = 1; +// } +// +// if (tb[CLIENT_POLICY_ASSOC_CONTROL_MODE]) +// assoc_cntl_mode = (int) blobmsg_get_u32( +// tb[CLIENT_POLICY_ASSOC_CONTROL_MODE]); +// +// if (tb[CLIENT_POLICY_ASSOC_CONTROL_VALID_TIME]) { +// assoc_timeout_present = 1; +// assoc_timeout = (int) blobmsg_get_u32( +// tb[CLIENT_POLICY_ASSOC_CONTROL_VALID_TIME]); +// } +// +// if (tb[CLIENT_POLICY_ASSOC_CONTROL_STALIST]) { +// sta_present = 1; +// sta_nr = blobmsg_check_array(tb[CLIENT_POLICY_ASSOC_CONTROL_STALIST], +// BLOBMSG_TYPE_STRING); +// l = 0; +// blobmsg_for_each_attr(cur, tb[CLIENT_POLICY_ASSOC_CONTROL_STALIST], rem) +// strncpy(sta_id[l++], blobmsg_get_string(cur), 18); +// } +// +// cmdu_data->message_type = CMDU_CLIENT_ASSOC_CONTROL_REQUEST; +// +// if (bssid_present == 1 && sta_present == 1 && assoc_timeout_present == 1 +// && assoc_cntl_mode >= 0) { +// +// trace("values are assoc_mode %d assoc_timeout %d sta_cnt %d\n", +// assoc_cntl_mode, assoc_timeout, sta_nr); +// /* Client ASSOC CONTROL TLV REQUEST 17.2.31 */ +// p = cntlr_gen_assoc_control_req(bss_id, assoc_cntl_mode, +// assoc_timeout, sta_nr, sta_id); +// if (!p) +// goto fail_cmdu; +// count++; +// } +// +// cmdu_data->num_tlvs = count; +// +// /*This CMDU has one or more TLVs*/ +// if (cmdu_data->num_tlvs == 0) { +// fprintf(stderr, "|%s:%d| No TLvs\n", __func__, __LINE__); +// goto fail_cmdu; +// } +// +// cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, +// sizeof(uint8_t *)); +// if (cmdu_data->tlvs && p != NULL) +// cmdu_data->tlvs[tlv_index++] = (uint8_t *)p; +// send_cmdu(c, cmdu_data); +// map_free_cmdu(cmdu_data); +// return 0; +//fail_p: +// if (p != NULL) +// map_free_tlv_cstruct((uint8_t *) p); +//fail_cmdu: +// map_free_cmdu(cmdu_data); +// return UBUS_STATUS_UNKNOWN_ERROR; } static int cntlr_ap_metric_query(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - int rem, index; - int num_bss = 0, num_radio = 0; - uint8_t agent_mac[6] = {0}; - uint8_t *bsslist = NULL; - uint8_t *radiolist = NULL; - char agent[18] = {0}; - struct cmdu_cstruct *cmdu; - struct blob_attr *attr = NULL; - struct blob_attr *tb[__AP_METRIC_QUERY_MAX]; - struct controller *c = container_of(obj, struct controller, obj); - - blobmsg_parse(ap_metric_query_params, __AP_METRIC_QUERY_MAX, tb, - blob_data(msg), blob_len(msg)); - - if (!tb[AP_METRIC_QUERY_AGENT] || !tb[AP_METRIC_QUERY_BSS]) { - fprintf(stderr, "Agent policy config: provide Agent and BSS " \ - "address in format 11:22:33...\n"); - return UBUS_STATUS_INVALID_ARGUMENT; - } - - strncpy(agent, blobmsg_data(tb[AP_METRIC_QUERY_AGENT]), - sizeof(agent) - 1); - if (!hwaddr_aton(agent, agent_mac)) - return UBUS_STATUS_UNKNOWN_ERROR; - - /* fetch bsslist */ - blobmsg_for_each_attr(attr, tb[AP_METRIC_QUERY_BSS], rem) { - uint8_t bssid[6] = {0}; - char bss[18] = {0}; - - if (blobmsg_type(attr) != BLOBMSG_TYPE_STRING) - continue; - - strncpy(bss, blobmsg_data(attr), sizeof(bss) - 1); - if (!hwaddr_aton(bss, bssid)) { - fprintf(stderr, "AP metric query: provide bss " \ - "address in format 11:22:33...\n"); - - if (bsslist) - free(bsslist); - - return UBUS_STATUS_UNKNOWN_ERROR; - } - - num_bss++; - bsslist = (uint8_t *)realloc(bsslist, - 6 * num_bss * sizeof(uint8_t)); - if (!bsslist) - return UBUS_STATUS_UNKNOWN_ERROR; - - index = (num_bss - 1) * 6; - memcpy(bsslist + index, bssid, 6); - } - - if (num_bss == 0) - return UBUS_STATUS_UNKNOWN_ERROR; - - /* fetch radio id's */ - blobmsg_for_each_attr(attr, tb[AP_METRIC_QUERY_RADIO], rem) { - uint8_t radioid[6] = {0}; - char radio[18] = {0}; - - if (blobmsg_type(attr) != BLOBMSG_TYPE_STRING) - continue; - - memset(radio, 0, sizeof(radio)); - strncpy(radio, blobmsg_data(attr), sizeof(radio)-1); - if (!hwaddr_aton(radio, radioid)) { - fprintf(stderr, "Agent policy config: provide radio " \ - "address in format 11:22:33...\n"); - goto fail_parsing; - } - - num_radio++; - radiolist = (uint8_t *)realloc(radiolist, - 6 * num_radio * sizeof(uint8_t)); - if (!radiolist) - goto fail_parsing; - - index = (num_radio - 1) * 6; - memcpy(radiolist + index, radioid, 6); - } - - cmdu = cntlr_gen_ap_metrics_query(c, agent_mac, NULL, num_bss, - bsslist, num_radio, radiolist); - if (!cmdu) - goto fail_parsing; - - send_cmdu(c, cmdu); - map_free_cmdu(cmdu); - if (radiolist) - free(radiolist); - - free(bsslist); - - return UBUS_STATUS_OK; - -fail_parsing: - if (radiolist) - free(radiolist); - - free(bsslist); - - return UBUS_STATUS_UNKNOWN_ERROR; + return 0; +// int rem, index; +// int num_bss = 0, num_radio = 0; +// uint8_t agent_mac[6] = {0}; +// uint8_t *bsslist = NULL; +// uint8_t *radiolist = NULL; +// char agent[18] = {0}; +// struct cmdu_cstruct *cmdu; +// struct blob_attr *attr = NULL; +// struct blob_attr *tb[__AP_METRIC_QUERY_MAX]; +// struct controller *c = container_of(obj, struct controller, obj); +// +// blobmsg_parse(ap_metric_query_params, __AP_METRIC_QUERY_MAX, tb, +// blob_data(msg), blob_len(msg)); +// +// if (!tb[AP_METRIC_QUERY_AGENT] || !tb[AP_METRIC_QUERY_BSS]) { +// fprintf(stderr, "Agent policy config: provide Agent and BSS " \ +// "address in format 11:22:33...\n"); +// return UBUS_STATUS_INVALID_ARGUMENT; +// } +// +// strncpy(agent, blobmsg_data(tb[AP_METRIC_QUERY_AGENT]), +// sizeof(agent) - 1); +// if (!hwaddr_aton(agent, agent_mac)) +// return UBUS_STATUS_UNKNOWN_ERROR; +// +// /* fetch bsslist */ +// blobmsg_for_each_attr(attr, tb[AP_METRIC_QUERY_BSS], rem) { +// uint8_t bssid[6] = {0}; +// char bss[18] = {0}; +// +// if (blobmsg_type(attr) != BLOBMSG_TYPE_STRING) +// continue; +// +// strncpy(bss, blobmsg_data(attr), sizeof(bss) - 1); +// if (!hwaddr_aton(bss, bssid)) { +// fprintf(stderr, "AP metric query: provide bss " \ +// "address in format 11:22:33...\n"); +// +// if (bsslist) +// free(bsslist); +// +// return UBUS_STATUS_UNKNOWN_ERROR; +// } +// +// num_bss++; +// bsslist = (uint8_t *)realloc(bsslist, +// 6 * num_bss * sizeof(uint8_t)); +// if (!bsslist) +// return UBUS_STATUS_UNKNOWN_ERROR; +// +// index = (num_bss - 1) * 6; +// memcpy(bsslist + index, bssid, 6); +// } +// +// if (num_bss == 0) +// return UBUS_STATUS_UNKNOWN_ERROR; +// +// /* fetch radio id's */ +// blobmsg_for_each_attr(attr, tb[AP_METRIC_QUERY_RADIO], rem) { +// uint8_t radioid[6] = {0}; +// char radio[18] = {0}; +// +// if (blobmsg_type(attr) != BLOBMSG_TYPE_STRING) +// continue; +// +// memset(radio, 0, sizeof(radio)); +// strncpy(radio, blobmsg_data(attr), sizeof(radio)-1); +// if (!hwaddr_aton(radio, radioid)) { +// fprintf(stderr, "Agent policy config: provide radio " \ +// "address in format 11:22:33...\n"); +// goto fail_parsing; +// } +// +// num_radio++; +// radiolist = (uint8_t *)realloc(radiolist, +// 6 * num_radio * sizeof(uint8_t)); +// if (!radiolist) +// goto fail_parsing; +// +// index = (num_radio - 1) * 6; +// memcpy(radiolist + index, radioid, 6); +// } +// +// cmdu = cntlr_gen_ap_metrics_query(c, agent_mac, NULL, num_bss, +// bsslist, num_radio, radiolist); +// if (!cmdu) +// goto fail_parsing; +// +// send_cmdu(c, cmdu); +// map_free_cmdu(cmdu); +// if (radiolist) +// free(radiolist); +// +// free(bsslist); +// +// return UBUS_STATUS_OK; +// +//fail_parsing: +// if (radiolist) +// free(radiolist); +// +// free(bsslist); +// +// return UBUS_STATUS_UNKNOWN_ERROR; } static int cntlr_sta_caps(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - struct blob_attr *tb[__STA_POLICY_MAX]; - uint8_t hw_bssid[6] = {0}, hw_sta[6] = {0}, hw_agent[6] = {0}; - struct controller *c = container_of(obj, struct controller, obj); - char sta[18] = {0}, bssid[18] = {0}; - struct cmdu_cstruct *cmdu; - - blobmsg_parse(sta_caps_policy_params, __STA_POLICY_MAX, tb, - blob_data(msg), blob_len(msg)); - - if (!tb[STA_POLICY_STA] || !tb[STA_POLICY_BSSID]) { - fprintf(stderr, "STA Capability Query: must provide STA and "\ - "BSSID\n"); - return UBUS_STATUS_INVALID_ARGUMENT; - } - - strncpy(sta, blobmsg_data(tb[STA_POLICY_STA]), sizeof(sta) - 1); - strncpy(bssid, blobmsg_data(tb[STA_POLICY_BSSID]), sizeof(bssid) - 1); - - if (tb[AP_POLICY_AGENT]) { - char agent[18] = {0}; - - strncpy(agent, blobmsg_data(tb[AP_POLICY_AGENT]), - sizeof(agent) - 1); - if (!hwaddr_aton(agent, hw_agent)) - return UBUS_STATUS_UNKNOWN_ERROR; - } - - if (!hwaddr_aton(sta, hw_sta)) - return UBUS_STATUS_UNKNOWN_ERROR; - - if (!hwaddr_aton(bssid, hw_bssid)) - return UBUS_STATUS_UNKNOWN_ERROR; - - cmdu = cntlr_gen_client_capability_query(c, hw_agent, NULL, hw_sta, - hw_bssid); - if (!cmdu) - return UBUS_STATUS_UNKNOWN_ERROR; - - send_cmdu(c, cmdu); - map_free_cmdu(cmdu); return 0; +// struct blob_attr *tb[__STA_POLICY_MAX]; +// uint8_t hw_bssid[6] = {0}, hw_sta[6] = {0}, hw_agent[6] = {0}; +// struct controller *c = container_of(obj, struct controller, obj); +// char sta[18] = {0}, bssid[18] = {0}; +// struct cmdu_cstruct *cmdu; +// +// blobmsg_parse(sta_caps_policy_params, __STA_POLICY_MAX, tb, +// blob_data(msg), blob_len(msg)); +// +// if (!tb[STA_POLICY_STA] || !tb[STA_POLICY_BSSID]) { +// fprintf(stderr, "STA Capability Query: must provide STA and "\ +// "BSSID\n"); +// return UBUS_STATUS_INVALID_ARGUMENT; +// } +// +// strncpy(sta, blobmsg_data(tb[STA_POLICY_STA]), sizeof(sta) - 1); +// strncpy(bssid, blobmsg_data(tb[STA_POLICY_BSSID]), sizeof(bssid) - 1); +// +// if (tb[AP_POLICY_AGENT]) { +// char agent[18] = {0}; +// +// strncpy(agent, blobmsg_data(tb[AP_POLICY_AGENT]), +// sizeof(agent) - 1); +// if (!hwaddr_aton(agent, hw_agent)) +// return UBUS_STATUS_UNKNOWN_ERROR; +// } +// +// if (!hwaddr_aton(sta, hw_sta)) +// return UBUS_STATUS_UNKNOWN_ERROR; +// +// if (!hwaddr_aton(bssid, hw_bssid)) +// return UBUS_STATUS_UNKNOWN_ERROR; +// +// cmdu = cntlr_gen_client_capability_query(c, hw_agent, NULL, hw_sta, +// hw_bssid); +// if (!cmdu) +// return UBUS_STATUS_UNKNOWN_ERROR; +// +// send_cmdu(c, cmdu); +// map_free_cmdu(cmdu); +// return 0; } static int cntlr_teardown_ap(struct ubus_context *ctx, struct ubus_object *obj, @@ -1118,49 +1000,49 @@ static int cntlr_reconfig_ap(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - - struct controller *c = container_of(obj, struct controller, obj); - struct blob_attr *tb[__RECFG_POLICY_MAX]; - char almac[18] = {0}, egress[16] = {0}; - uint8_t hwaddr[6] = {0}, alhwaddr[6] = {0}; - struct cmdu_cstruct *cmdu; - int i, tlv_index = 0; - - blobmsg_parse(reconfig_policy_params, __RECFG_POLICY_MAX, tb, - blob_data(msg), blob_len(msg)); - - if (!tb[RECFG_POLICY_ALMAC]) { - fprintf(stderr, "Provide ALMAC address in format 11:22:33...\n"); - return UBUS_STATUS_INVALID_ARGUMENT; - } - - if (tb[RECFG_POLICY_AGENT]) { - char agent[18] = {0}; - - strncpy(agent, blobmsg_data(tb[RECFG_POLICY_AGENT]), - sizeof(agent) - 1); - if (!hwaddr_aton(agent, hwaddr)) - return UBUS_STATUS_UNKNOWN_ERROR; - } - - if (tb[RECFG_POLICY_EGRESS]) - strncpy(egress, blobmsg_data(tb[RECFG_POLICY_EGRESS]), - sizeof(egress) - 1); - else - strncpy(egress, c->cfg.al_bridge, sizeof(egress) - 1); - - strncpy(almac, blobmsg_data(tb[RECFG_POLICY_ALMAC]), - sizeof(almac) - 1); - if (!hwaddr_aton(almac, alhwaddr)) - return UBUS_STATUS_UNKNOWN_ERROR; - - cmdu = cntlr_gen_ap_autoconfig_renew(c, alhwaddr, egress, alhwaddr); - if (!cmdu) - return UBUS_STATUS_UNKNOWN_ERROR; - - send_cmdu(c, cmdu); - map_free_cmdu(cmdu); - return UBUS_STATUS_OK; + return 0; +// struct controller *c = container_of(obj, struct controller, obj); +// struct blob_attr *tb[__RECFG_POLICY_MAX]; +// char almac[18] = {0}, egress[16] = {0}; +// uint8_t hwaddr[6] = {0}, alhwaddr[6] = {0}; +// struct cmdu_cstruct *cmdu; +// int i, tlv_index = 0; +// +// blobmsg_parse(reconfig_policy_params, __RECFG_POLICY_MAX, tb, +// blob_data(msg), blob_len(msg)); +// +// if (!tb[RECFG_POLICY_ALMAC]) { +// fprintf(stderr, "Provide ALMAC address in format 11:22:33...\n"); +// return UBUS_STATUS_INVALID_ARGUMENT; +// } +// +// if (tb[RECFG_POLICY_AGENT]) { +// char agent[18] = {0}; +// +// strncpy(agent, blobmsg_data(tb[RECFG_POLICY_AGENT]), +// sizeof(agent) - 1); +// if (!hwaddr_aton(agent, hwaddr)) +// return UBUS_STATUS_UNKNOWN_ERROR; +// } +// +// if (tb[RECFG_POLICY_EGRESS]) +// strncpy(egress, blobmsg_data(tb[RECFG_POLICY_EGRESS]), +// sizeof(egress) - 1); +// else +// strncpy(egress, c->cfg.al_bridge, sizeof(egress) - 1); +// +// strncpy(almac, blobmsg_data(tb[RECFG_POLICY_ALMAC]), +// sizeof(almac) - 1); +// if (!hwaddr_aton(almac, alhwaddr)) +// return UBUS_STATUS_UNKNOWN_ERROR; +// +// cmdu = cntlr_gen_ap_autoconfig_renew(c, alhwaddr, egress, alhwaddr); +// if (!cmdu) +// return UBUS_STATUS_UNKNOWN_ERROR; +// +// send_cmdu(c, cmdu); +// map_free_cmdu(cmdu); +// return UBUS_STATUS_OK; } static struct netif_radio *cntlr_radio_to_bssid(struct controller *c, const char *radio) @@ -1337,175 +1219,177 @@ static int cntlr_bk_steer(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - struct blob_attr *tb[__BK_STEER_POLICY_MAX]; - struct controller *c = container_of(obj, struct controller, obj); - char agent_str[18] = {0}, bssid_str[18] = {0}, bkhaul_str[18] = {0}; - uint8_t agent[6] = {0}, bssid[6] = {0}, bkhaul[6] = {0}; - struct cmdu_cstruct *cmdu; - uint8_t op_class, channel; - - blobmsg_parse(bk_steer_policy_params, __BK_STEER_POLICY_MAX, tb, - blob_data(msg), blob_len(msg)); - - if (!tb[BK_STEER_POLICY_BSSID] || !tb[BK_STEER_POLICY_CHANNEL] || - !tb[BK_STEER_POLICY_OP_CLASS] || - !tb[BK_STEER_POLICY_STA_MAC]) { - fprintf(stderr, "BSSID, channel and op class required!\n"); - return UBUS_STATUS_INVALID_ARGUMENT; - } - - strncpy(bssid_str, blobmsg_data(tb[BK_STEER_POLICY_BSSID]), - sizeof(bssid_str) - 1); - strncpy(bkhaul_str, blobmsg_data(tb[BK_STEER_POLICY_STA_MAC]), - sizeof(bkhaul_str) - 1); - - if (!hwaddr_aton(bssid_str, bssid)) { - fprintf(stderr, "BSSID must be in format 11:22:33...\n"); - return UBUS_STATUS_INVALID_ARGUMENT; - } - - if (!hwaddr_aton(bkhaul_str, bkhaul)) { - fprintf(stderr, "Backhaul must be in format 11:22:33...\n"); - return UBUS_STATUS_INVALID_ARGUMENT; - } - - if (tb[AP_POLICY_AGENT]) { - strncpy(agent_str, blobmsg_data(tb[AP_POLICY_AGENT]), - sizeof(agent_str) - 1); - if (!hwaddr_aton(agent_str, agent)) - return UBUS_STATUS_INVALID_ARGUMENT; - } - - channel = blobmsg_get_u8(tb[BK_STEER_POLICY_CHANNEL]); - op_class = blobmsg_get_u8(tb[BK_STEER_POLICY_OP_CLASS]); - - cmdu = cntlr_gen_backhaul_steer_request(c, agent, NULL, bssid, bkhaul, - op_class, channel); - if (!cmdu) - return UBUS_STATUS_UNKNOWN_ERROR; - - send_cmdu(c, cmdu); - map_free_cmdu(cmdu); - return 0; +// struct blob_attr *tb[__BK_STEER_POLICY_MAX]; +// struct controller *c = container_of(obj, struct controller, obj); +// char agent_str[18] = {0}, bssid_str[18] = {0}, bkhaul_str[18] = {0}; +// uint8_t agent[6] = {0}, bssid[6] = {0}, bkhaul[6] = {0}; +// struct cmdu_cstruct *cmdu; +// uint8_t op_class, channel; +// +// blobmsg_parse(bk_steer_policy_params, __BK_STEER_POLICY_MAX, tb, +// blob_data(msg), blob_len(msg)); +// +// if (!tb[BK_STEER_POLICY_BSSID] || !tb[BK_STEER_POLICY_CHANNEL] || +// !tb[BK_STEER_POLICY_OP_CLASS] || +// !tb[BK_STEER_POLICY_STA_MAC]) { +// fprintf(stderr, "BSSID, channel and op class required!\n"); +// return UBUS_STATUS_INVALID_ARGUMENT; +// } +// +// strncpy(bssid_str, blobmsg_data(tb[BK_STEER_POLICY_BSSID]), +// sizeof(bssid_str) - 1); +// strncpy(bkhaul_str, blobmsg_data(tb[BK_STEER_POLICY_STA_MAC]), +// sizeof(bkhaul_str) - 1); +// +// if (!hwaddr_aton(bssid_str, bssid)) { +// fprintf(stderr, "BSSID must be in format 11:22:33...\n"); +// return UBUS_STATUS_INVALID_ARGUMENT; +// } +// +// if (!hwaddr_aton(bkhaul_str, bkhaul)) { +// fprintf(stderr, "Backhaul must be in format 11:22:33...\n"); +// return UBUS_STATUS_INVALID_ARGUMENT; +// } +// +// if (tb[AP_POLICY_AGENT]) { +// strncpy(agent_str, blobmsg_data(tb[AP_POLICY_AGENT]), +// sizeof(agent_str) - 1); +// if (!hwaddr_aton(agent_str, agent)) +// return UBUS_STATUS_INVALID_ARGUMENT; +// } +// +// channel = blobmsg_get_u8(tb[BK_STEER_POLICY_CHANNEL]); +// op_class = blobmsg_get_u8(tb[BK_STEER_POLICY_OP_CLASS]); +// +// cmdu = cntlr_gen_backhaul_steer_request(c, agent, NULL, bssid, bkhaul, +// op_class, channel); +// if (!cmdu) +// return UBUS_STATUS_UNKNOWN_ERROR; +// +// send_cmdu(c, cmdu); +// map_free_cmdu(cmdu); +// +// return 0; } static int cntlr_ap_policy_config(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - char agent[18] = {0}; - char radio[18] = {0}; - char bss[18] = {0}; - uint8_t hwaddr[6] = {0}; - struct cmdu_cstruct *cmdu_data; - struct agent_policy *a, *found = NULL; - struct blob_attr *attr = NULL; - uint8_t *radiolist = NULL; - uint8_t *bsslist = NULL; - int rem, num_radio = 0, num_bss = 0; - struct blob_attr *tb[__AP_POLICY_CONFIG_MAX]; - struct controller *c = container_of(obj, struct controller, obj); - - blobmsg_parse(ap_policy_config_params, __AP_POLICY_CONFIG_MAX, tb, - blob_data(msg), blob_len(msg)); - - if (!tb[AP_POLICY_CONFIG_AGENT] || !tb[AP_POLICY_CONFIG_RADIOS]) { - fprintf(stderr, "Agent policy config: provide Agent or Radio " \ - "address in format 11:22:33...\n"); - return UBUS_STATUS_INVALID_ARGUMENT; - } - - strncpy(agent, blobmsg_data(tb[AP_POLICY_CONFIG_AGENT]), sizeof(agent) - 1); - if (!hwaddr_aton(agent, hwaddr)) - return UBUS_STATUS_UNKNOWN_ERROR; - - list_for_each_entry(a, &c->cfg.policylist, list) { - if (!memcmp(hwaddr, a->agent_id, sizeof(hwaddr))) { - found = a; - break; - } - } - - if (!found) - return UBUS_STATUS_UNKNOWN_ERROR; - - /* fetch radio id's */ - blobmsg_for_each_attr(attr, tb[AP_POLICY_CONFIG_RADIOS], rem) { - uint8_t bssid[6] = {0}; - - if (blobmsg_type(attr) != BLOBMSG_TYPE_STRING) - continue; - - memset(radio, 0, sizeof(radio)); - strncpy(radio, blobmsg_data(attr), sizeof(radio)-1); - if (!hwaddr_aton(radio, bssid)) { - fprintf(stderr, "Agent policy config: provide radio " \ - "address in format 11:22:33...\n"); - if (radiolist) - free(radiolist); - - return UBUS_STATUS_UNKNOWN_ERROR; - } - - num_radio++; - radiolist = (uint8_t *)realloc(radiolist, 6 * num_radio * sizeof(uint8_t)); - if (!radiolist) - return UBUS_STATUS_UNKNOWN_ERROR; - - memcpy(&radiolist[(num_radio-1)*6], bssid, 6); - } - - if (num_radio == 0) - return UBUS_STATUS_UNKNOWN_ERROR; - - /* fetch BSS list */ - blobmsg_for_each_attr(attr, tb[AP_POLICY_CONFIG_BSS], rem) { - uint8_t bssid[6] = {0}; - - if (blobmsg_type(attr) != BLOBMSG_TYPE_STRING) - continue; - - memset(bss, 0, sizeof(bss)); - strncpy(bss, blobmsg_data(attr), sizeof(bss)-1); - if (!hwaddr_aton(bss, bssid)) { - fprintf(stderr, "Agent policy config: provide bssid " \ - "address in format 11:22:33...\n"); - goto fail_parsing; - } - - num_bss++; - bsslist = (uint8_t *)realloc(bsslist, 6 * num_bss * sizeof(uint8_t)); - if (!bsslist) - goto fail_parsing; - - memcpy(&bsslist[(num_bss-1)*6], bssid, 6); - } - - cmdu_data = cntlr_gen_policy_config_req(c, NULL, found, num_radio, - radiolist, num_bss, bsslist); - if (!cmdu_data) - goto fail_parsing; - - // TODO: ff:ff:ff:ff:ff:ff = send to all agents - - send_cmdu(c, cmdu_data); - map_free_cmdu(cmdu_data); - - if (bsslist) - free(bsslist); - - free(radiolist); - - return UBUS_STATUS_OK; - -fail_parsing: - if (bsslist) - free(bsslist); - - free(radiolist); - - return UBUS_STATUS_UNKNOWN_ERROR; + return 0; +// char agent[18] = {0}; +// char radio[18] = {0}; +// char bss[18] = {0}; +// uint8_t hwaddr[6] = {0}; +// struct cmdu_cstruct *cmdu_data; +// struct agent_policy *a, *found = NULL; +// struct blob_attr *attr = NULL; +// uint8_t *radiolist = NULL; +// uint8_t *bsslist = NULL; +// int rem, num_radio = 0, num_bss = 0; +// struct blob_attr *tb[__AP_POLICY_CONFIG_MAX]; +// struct controller *c = container_of(obj, struct controller, obj); +// +// blobmsg_parse(ap_policy_config_params, __AP_POLICY_CONFIG_MAX, tb, +// blob_data(msg), blob_len(msg)); +// +// if (!tb[AP_POLICY_CONFIG_AGENT] || !tb[AP_POLICY_CONFIG_RADIOS]) { +// fprintf(stderr, "Agent policy config: provide Agent or Radio " \ +// "address in format 11:22:33...\n"); +// return UBUS_STATUS_INVALID_ARGUMENT; +// } +// +// strncpy(agent, blobmsg_data(tb[AP_POLICY_CONFIG_AGENT]), sizeof(agent) - 1); +// if (!hwaddr_aton(agent, hwaddr)) +// return UBUS_STATUS_UNKNOWN_ERROR; +// +// list_for_each_entry(a, &c->cfg.policylist, list) { +// if (!memcmp(hwaddr, a->agent_id, sizeof(hwaddr))) { +// found = a; +// break; +// } +// } +// +// if (!found) +// return UBUS_STATUS_UNKNOWN_ERROR; +// +// /* fetch radio id's */ +// blobmsg_for_each_attr(attr, tb[AP_POLICY_CONFIG_RADIOS], rem) { +// uint8_t bssid[6] = {0}; +// +// if (blobmsg_type(attr) != BLOBMSG_TYPE_STRING) +// continue; +// +// memset(radio, 0, sizeof(radio)); +// strncpy(radio, blobmsg_data(attr), sizeof(radio)-1); +// if (!hwaddr_aton(radio, bssid)) { +// fprintf(stderr, "Agent policy config: provide radio " \ +// "address in format 11:22:33...\n"); +// if (radiolist) +// free(radiolist); +// +// return UBUS_STATUS_UNKNOWN_ERROR; +// } +// +// num_radio++; +// radiolist = (uint8_t *)realloc(radiolist, 6 * num_radio * sizeof(uint8_t)); +// if (!radiolist) +// return UBUS_STATUS_UNKNOWN_ERROR; +// +// memcpy(&radiolist[(num_radio-1)*6], bssid, 6); +// } +// +// if (num_radio == 0) +// return UBUS_STATUS_UNKNOWN_ERROR; +// +// /* fetch BSS list */ +// blobmsg_for_each_attr(attr, tb[AP_POLICY_CONFIG_BSS], rem) { +// uint8_t bssid[6] = {0}; +// +// if (blobmsg_type(attr) != BLOBMSG_TYPE_STRING) +// continue; +// +// memset(bss, 0, sizeof(bss)); +// strncpy(bss, blobmsg_data(attr), sizeof(bss)-1); +// if (!hwaddr_aton(bss, bssid)) { +// fprintf(stderr, "Agent policy config: provide bssid " \ +// "address in format 11:22:33...\n"); +// goto fail_parsing; +// } +// +// num_bss++; +// bsslist = (uint8_t *)realloc(bsslist, 6 * num_bss * sizeof(uint8_t)); +// if (!bsslist) +// goto fail_parsing; +// +// memcpy(&bsslist[(num_bss-1)*6], bssid, 6); +// } +// +// cmdu_data = cntlr_gen_policy_config_req(c, NULL, found, num_radio, +// radiolist, num_bss, bsslist); +// if (!cmdu_data) +// goto fail_parsing; +// +// // TODO: ff:ff:ff:ff:ff:ff = send to all agents +// +// send_cmdu(c, cmdu_data); +// map_free_cmdu(cmdu_data); +// +// if (bsslist) +// free(bsslist); +// +// free(radiolist); +// +// return UBUS_STATUS_OK; +// +//fail_parsing: +// if (bsslist) +// free(bsslist); +// +// free(radiolist); +// +// return UBUS_STATUS_UNKNOWN_ERROR; } static int cntlr_scan(struct ubus_context *ctx, struct ubus_object *obj, @@ -1513,246 +1397,249 @@ static int cntlr_scan(struct ubus_context *ctx, struct ubus_object *obj, struct blob_attr *msg) { trace("|%s:%d| Parsing the message\n", __func__, __LINE__); - struct blob_attr *tb[__SCAN_POLICY_MAX]; // array of blob_attr // blob_attr = id, value // tb[id] = value - struct tlv_ch_scan_req *p; //struct def in map2.h - struct controller *c = container_of(obj, struct controller, obj); - char agent[18] = {0}; - char (*radio)[18] = {0}; - // uint32_t op_class; - uint8_t **channel; // array of channels per radio - int *num_ch_to_scan; // array of number of channels per radio - int num_radios; // number of radios - struct cmdu_cstruct *cmdu_data; - - // parce the msg from the ubus method "scan" given by the user - // based on the policy parameters - blobmsg_parse(scan_policy_params, __SCAN_POLICY_MAX, tb, - blob_data(msg), blob_len(msg)); - - // are the ubus method parameter empty? - if (!tb[SCAN_POLICY_AGENT]) { - dbg("Must provide agent mac address\n"); - return UBUS_STATUS_INVALID_ARGUMENT; - } - - if (!tb[SCAN_POLICY_RADIO]) { - dbg("Must provide radio mac address\n"); - return UBUS_STATUS_INVALID_ARGUMENT; - } - - // if (!tb[SCAN_POLICY_OP_CLASS]){ //OP - // dbg("Must provide operating class\n"); - // return UBUS_STATUS_INVALID_ARGUMENT; - // } - - if (!tb[SCAN_POLICY_CHANNEL]) { - dbg("Must provide channel\n"); - return UBUS_STATUS_INVALID_ARGUMENT; - } - // If not, write them to the string "agent" - strncpy(agent, blobmsg_data(tb[SCAN_POLICY_AGENT]), sizeof(agent) - 1); - int rem = 0, rem1 = 0; - int i = 0, j = 0; - struct blob_attr *attr, *cur; - - int num_ch_arrays = blobmsg_check_array(tb[SCAN_POLICY_CHANNEL], BLOBMSG_TYPE_ARRAY); - - num_radios = blobmsg_check_array(tb[SCAN_POLICY_RADIO], BLOBMSG_TYPE_STRING); - if (num_radios != num_ch_arrays) { - dbg("Number of channel arrays has to be the same as number of radios\n"); - return -1; - } - // Allocate the arrays for channel and radio - num_ch_to_scan = calloc(num_radios, sizeof(uint8_t)); - if (!num_ch_to_scan) { - dbg("Out of memory!\n"); - return -1; - } - channel = (uint8_t **)calloc(num_radios, sizeof(uint8_t *)); - if (!channel) { - dbg("Out of memory for channels!\n"); - return -1; - } - radio = calloc(num_radios, 18*sizeof(char)); - if (!radio) { - dbg("Out of memory for radios!\n"); - return -1; - } - // Radio - blobmsg_for_each_attr(attr, tb[SCAN_POLICY_RADIO], rem) { - if (blobmsg_type(attr) != BLOBMSG_TYPE_STRING) { - dbg("|%s:%d| Radios have to be string.\n", __func__, __LINE__); - continue; - } - strncpy(radio[i], blobmsg_data(attr), 17); - i++; - } - i = 0; - // Array of channels (attr - current array) - blobmsg_for_each_attr(attr, tb[SCAN_POLICY_CHANNEL], rem) { - if (blobmsg_type(attr) != BLOBMSG_TYPE_ARRAY) { - dbg("|%s:%d| Channels have to be grouped into arrays.\n", __func__, __LINE__); - continue; - } - num_ch_to_scan[i] = blobmsg_check_array(attr, BLOBMSG_TYPE_INT32); - channel[i] = calloc(num_ch_to_scan[i], sizeof(uint8_t)); - if (!channel[i]) { - dbg("Out of memory!\n"); - return -1; - } - trace("|%s:%d| Radio: %s | Scan request for channels:", __func__, __LINE__, radio[i]); - // Channels (cur - current channel) - blobmsg_for_each_attr(cur, attr, rem1) { - channel[i][j] = (uint8_t)blobmsg_get_u32(cur); - trace(" %d", channel[i][j]); - j++; - } - if (j == 0) // all_ch_scan - trace(" all"); - trace("\n"); - i++; j = 0; - } - // Allocate the cmdu_data structure - cmdu_data = (struct cmdu_cstruct *)calloc(1, - sizeof(struct cmdu_cstruct)); - // is it successfully allocated? - if (!cmdu_data) { - dbg("failed to malloc cmdu\n"); - return UBUS_STATUS_UNKNOWN_ERROR; - } - // this parameter is neccessary for send_cmdu as it gives the origin - if (!hwaddr_aton(agent, cmdu_data->origin)) { - dbg("failed to hwaddr cmdu origin\n"); - return UBUS_STATUS_UNKNOWN_ERROR; - } - // If yes, start creating the cdmu_data - // that will be used to call the method "send" of "map.1905" - // cmdu_data = {type, egress, mid, macaddr, num_tlvs, tlvs[]} - cmdu_data->message_type = CMDU_CHANNEL_SCAN_REQUEST; - // cmdu_data->message_id = 1; - // 17.1.33: One Channel Scan Request TLV (17.2.39) - cmdu_data->num_tlvs = 1; - // Allocate the TLV of the cmdu_data - p = (struct tlv_ch_scan_req *)calloc(1, sizeof(struct tlv_ch_scan_req)); // from map2.h (963 line) - if (!p) { - dbg("failed to malloc tlv\n"); - return UBUS_STATUS_UNKNOWN_ERROR; - } - // Define the TLV - p->tlv_type = MAP_TLV_CHANNEL_SCAN_REQ; // from map2.h (134 line) - p->fresh_scan = 1; // 0000 0000 Bit7=0 - p->nbr_radios = num_radios; - if (p->nbr_radios > 0) - p->radio_data = calloc(p->nbr_radios, sizeof(*p->radio_data)); - if (!p->radio_data) { - free(p); - dbg("failed to malloc radio data\n"); - return UBUS_STATUS_UNKNOWN_ERROR; - } - for (int i = 0; i < p->nbr_radios; i++) { - //(ubus call wifi.ap.wl0 status -> bssid) - if (!hwaddr_aton(radio[i], p->radio_data[i].radio_id)) { - dbg("failed to hwaddr radio_id\n"); - return UBUS_STATUS_UNKNOWN_ERROR; - } - p->radio_data[i].nbr_op_class = 1; //num_ch_to_scan; // TODO - if (p->radio_data[i].nbr_op_class > 0) { - p->radio_data[i].op_class_data = calloc(p->radio_data[i].nbr_op_class, sizeof(*p->radio_data[i].op_class_data)); - } - if (p->radio_data[i].op_class_data) { - for (int j = 0; j < p->radio_data[i].nbr_op_class; j++) { /* j is already defined */ - p->radio_data[i].op_class_data[j].nbr_ch = num_ch_to_scan[i]; - // if (p->radio_data[i].op_class_data[j].nbr_ch==0) {all ch} - // channel list - p->radio_data[i].op_class_data[j].ch = channel[i]; - } - } - } - cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, sizeof(uint8_t *)); - if (cmdu_data->tlvs) - cmdu_data->tlvs[0] = (uint8_t *)p; - strncpy(cmdu_data->intf_name, c->cfg.al_bridge, 15); - send_cmdu(c, cmdu_data); - map_free_cmdu(cmdu_data); return 0; +// struct blob_attr *tb[__SCAN_POLICY_MAX]; // array of blob_attr // blob_attr = id, value // tb[id] = value +// struct tlv_ch_scan_req *p; //struct def in map2.h +// struct controller *c = container_of(obj, struct controller, obj); +// char agent[18] = {0}; +// char (*radio)[18] = {0}; +// // uint32_t op_class; +// uint8_t **channel; // array of channels per radio +// int *num_ch_to_scan; // array of number of channels per radio +// int num_radios; // number of radios +// struct cmdu_cstruct *cmdu_data; +// +// // parce the msg from the ubus method "scan" given by the user +// // based on the policy parameters +// blobmsg_parse(scan_policy_params, __SCAN_POLICY_MAX, tb, +// blob_data(msg), blob_len(msg)); +// +// // are the ubus method parameter empty? +// if (!tb[SCAN_POLICY_AGENT]) { +// dbg("Must provide agent mac address\n"); +// return UBUS_STATUS_INVALID_ARGUMENT; +// } +// +// if (!tb[SCAN_POLICY_RADIO]) { +// dbg("Must provide radio mac address\n"); +// return UBUS_STATUS_INVALID_ARGUMENT; +// } +// +// // if (!tb[SCAN_POLICY_OP_CLASS]){ //OP +// // dbg("Must provide operating class\n"); +// // return UBUS_STATUS_INVALID_ARGUMENT; +// // } +// +// if (!tb[SCAN_POLICY_CHANNEL]) { +// dbg("Must provide channel\n"); +// return UBUS_STATUS_INVALID_ARGUMENT; +// } +// // If not, write them to the string "agent" +// strncpy(agent, blobmsg_data(tb[SCAN_POLICY_AGENT]), sizeof(agent) - 1); +// int rem = 0, rem1 = 0; +// int i = 0, j = 0; +// struct blob_attr *attr, *cur; +// +// int num_ch_arrays = blobmsg_check_array(tb[SCAN_POLICY_CHANNEL], BLOBMSG_TYPE_ARRAY); +// +// num_radios = blobmsg_check_array(tb[SCAN_POLICY_RADIO], BLOBMSG_TYPE_STRING); +// if (num_radios != num_ch_arrays) { +// dbg("Number of channel arrays has to be the same as number of radios\n"); +// return -1; +// } +// // Allocate the arrays for channel and radio +// num_ch_to_scan = calloc(num_radios, sizeof(uint8_t)); +// if (!num_ch_to_scan) { +// dbg("Out of memory!\n"); +// return -1; +// } +// channel = (uint8_t **)calloc(num_radios, sizeof(uint8_t *)); +// if (!channel) { +// dbg("Out of memory for channels!\n"); +// return -1; +// } +// radio = calloc(num_radios, 18*sizeof(char)); +// if (!radio) { +// dbg("Out of memory for radios!\n"); +// return -1; +// } +// // Radio +// blobmsg_for_each_attr(attr, tb[SCAN_POLICY_RADIO], rem) { +// if (blobmsg_type(attr) != BLOBMSG_TYPE_STRING) { +// dbg("|%s:%d| Radios have to be string.\n", __func__, __LINE__); +// continue; +// } +// strncpy(radio[i], blobmsg_data(attr), 17); +// i++; +// } +// i = 0; +// // Array of channels (attr - current array) +// blobmsg_for_each_attr(attr, tb[SCAN_POLICY_CHANNEL], rem) { +// if (blobmsg_type(attr) != BLOBMSG_TYPE_ARRAY) { +// dbg("|%s:%d| Channels have to be grouped into arrays.\n", __func__, __LINE__); +// continue; +// } +// num_ch_to_scan[i] = blobmsg_check_array(attr, BLOBMSG_TYPE_INT32); +// channel[i] = calloc(num_ch_to_scan[i], sizeof(uint8_t)); +// if (!channel[i]) { +// dbg("Out of memory!\n"); +// return -1; +// } +// trace("|%s:%d| Radio: %s | Scan request for channels:", __func__, __LINE__, radio[i]); +// // Channels (cur - current channel) +// blobmsg_for_each_attr(cur, attr, rem1) { +// channel[i][j] = (uint8_t)blobmsg_get_u32(cur); +// trace(" %d", channel[i][j]); +// j++; +// } +// if (j == 0) // all_ch_scan +// trace(" all"); +// trace("\n"); +// i++; j = 0; +// } +// // Allocate the cmdu_data structure +// cmdu_data = (struct cmdu_cstruct *)calloc(1, +// sizeof(struct cmdu_cstruct)); +// // is it successfully allocated? +// if (!cmdu_data) { +// dbg("failed to malloc cmdu\n"); +// return UBUS_STATUS_UNKNOWN_ERROR; +// } +// // this parameter is neccessary for send_cmdu as it gives the origin +// if (!hwaddr_aton(agent, cmdu_data->origin)) { +// dbg("failed to hwaddr cmdu origin\n"); +// return UBUS_STATUS_UNKNOWN_ERROR; +// } +// // If yes, start creating the cdmu_data +// // that will be used to call the method "send" of "map.1905" +// // cmdu_data = {type, egress, mid, macaddr, num_tlvs, tlvs[]} +// cmdu_data->message_type = CMDU_CHANNEL_SCAN_REQUEST; +// // cmdu_data->message_id = 1; +// // 17.1.33: One Channel Scan Request TLV (17.2.39) +// cmdu_data->num_tlvs = 1; +// // Allocate the TLV of the cmdu_data +// p = (struct tlv_ch_scan_req *)calloc(1, sizeof(struct tlv_ch_scan_req)); // from map2.h (963 line) +// if (!p) { +// dbg("failed to malloc tlv\n"); +// return UBUS_STATUS_UNKNOWN_ERROR; +// } +// // Define the TLV +// p->tlv_type = MAP_TLV_CHANNEL_SCAN_REQ; // from map2.h (134 line) +// p->fresh_scan = 1; // 0000 0000 Bit7=0 +// p->nbr_radios = num_radios; +// if (p->nbr_radios > 0) +// p->radio_data = calloc(p->nbr_radios, sizeof(*p->radio_data)); +// if (!p->radio_data) { +// free(p); +// dbg("failed to malloc radio data\n"); +// return UBUS_STATUS_UNKNOWN_ERROR; +// } +// for (int i = 0; i < p->nbr_radios; i++) { +// //(ubus call wifi.ap.wl0 status -> bssid) +// if (!hwaddr_aton(radio[i], p->radio_data[i].radio_id)) { +// dbg("failed to hwaddr radio_id\n"); +// return UBUS_STATUS_UNKNOWN_ERROR; +// } +// p->radio_data[i].nbr_op_class = 1; //num_ch_to_scan; // TODO +// if (p->radio_data[i].nbr_op_class > 0) { +// p->radio_data[i].op_class_data = calloc(p->radio_data[i].nbr_op_class, sizeof(*p->radio_data[i].op_class_data)); +// } +// if (p->radio_data[i].op_class_data) { +// for (int j = 0; j < p->radio_data[i].nbr_op_class; j++) { /* j is already defined */ +// p->radio_data[i].op_class_data[j].nbr_ch = num_ch_to_scan[i]; +// // if (p->radio_data[i].op_class_data[j].nbr_ch==0) {all ch} +// // channel list +// p->radio_data[i].op_class_data[j].ch = channel[i]; +// } +// } +// } +// cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, sizeof(uint8_t *)); +// if (cmdu_data->tlvs) +// cmdu_data->tlvs[0] = (uint8_t *)p; +// strncpy(cmdu_data->intf_name, c->cfg.al_bridge, 15); +// send_cmdu(c, cmdu_data); +// map_free_cmdu(cmdu_data); +// return 0; } static int cntlr_sta_metric_query(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - struct cmdu_cstruct *cmdu; - char mac_str[18]; - uint8_t agent_mac[6] = { 0 }; - uint8_t sta[6] = { 0 }; - struct blob_attr *tb[__STA_METRIC_QUERY_MAX]; - struct controller *c = container_of(obj, struct controller, obj); - - blobmsg_parse(sta_metric_query_params, __STA_METRIC_QUERY_MAX, tb, - blob_data(msg), blob_len(msg)); - - if (!tb[STA_METRIC_QUERY_AGENT] || !tb[STA_METRIC_QUERY_STA]) { - fprintf(stderr, "STA link metric query: provide Agent and STA " \ - "address in format 11:22:33...\n"); - return UBUS_STATUS_INVALID_ARGUMENT; - } - - memset(mac_str, 0, sizeof(mac_str)); - strncpy(mac_str, blobmsg_data(tb[STA_METRIC_QUERY_AGENT]), - sizeof(mac_str) - 1); - if (!hwaddr_aton(mac_str, agent_mac)) - return UBUS_STATUS_UNKNOWN_ERROR; - - memset(mac_str, 0, sizeof(mac_str)); - strncpy(mac_str, blobmsg_data(tb[STA_METRIC_QUERY_STA]), - sizeof(mac_str) - 1); - if (!hwaddr_aton(mac_str, sta)) - return UBUS_STATUS_UNKNOWN_ERROR; - - cmdu = cntlr_gen_sta_metric_query(c, agent_mac, NULL, sta); - if (!cmdu) - return UBUS_STATUS_UNKNOWN_ERROR; - - send_cmdu(c, cmdu); - map_free_cmdu(cmdu); - - return UBUS_STATUS_OK; + return 0; +// struct cmdu_cstruct *cmdu; +// char mac_str[18]; +// uint8_t agent_mac[6] = { 0 }; +// uint8_t sta[6] = { 0 }; +// struct blob_attr *tb[__STA_METRIC_QUERY_MAX]; +// struct controller *c = container_of(obj, struct controller, obj); +// +// blobmsg_parse(sta_metric_query_params, __STA_METRIC_QUERY_MAX, tb, +// blob_data(msg), blob_len(msg)); +// +// if (!tb[STA_METRIC_QUERY_AGENT] || !tb[STA_METRIC_QUERY_STA]) { +// fprintf(stderr, "STA link metric query: provide Agent and STA " \ +// "address in format 11:22:33...\n"); +// return UBUS_STATUS_INVALID_ARGUMENT; +// } +// +// memset(mac_str, 0, sizeof(mac_str)); +// strncpy(mac_str, blobmsg_data(tb[STA_METRIC_QUERY_AGENT]), +// sizeof(mac_str) - 1); +// if (!hwaddr_aton(mac_str, agent_mac)) +// return UBUS_STATUS_UNKNOWN_ERROR; +// +// memset(mac_str, 0, sizeof(mac_str)); +// strncpy(mac_str, blobmsg_data(tb[STA_METRIC_QUERY_STA]), +// sizeof(mac_str) - 1); +// if (!hwaddr_aton(mac_str, sta)) +// return UBUS_STATUS_UNKNOWN_ERROR; +// +// cmdu = cntlr_gen_sta_metric_query(c, agent_mac, NULL, sta); +// if (!cmdu) +// return UBUS_STATUS_UNKNOWN_ERROR; +// +// send_cmdu(c, cmdu); +// map_free_cmdu(cmdu); +// +// return UBUS_STATUS_OK; } static int cntlr_bk_caps(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) { - trace("%s:--->\n", __func__); - struct blob_attr *tb[__BK_CAPS_POLICY_MAX]; - struct controller *c = container_of(obj, struct controller, obj); - char agent[18] = { 0 }; - uint8_t agent_mac[6] = { 0 }; - struct cmdu_cstruct *cmdu_data; - - blobmsg_parse(bk_caps_policy_params, __BK_CAPS_POLICY_MAX, tb, - blob_data(msg), blob_len(msg)); - - // are the ubus method parameter empty? - if (!tb[BK_CAPS_POLICY_AGENT]) { - dbg("Must provide agent mac address\n"); - return UBUS_STATUS_INVALID_ARGUMENT; - } - - memset(agent, 0, sizeof(agent)); - strncpy(agent, blobmsg_data(tb[STA_METRIC_QUERY_AGENT]), - sizeof(agent) - 1); - if (!hwaddr_aton(agent, agent_mac)) - return UBUS_STATUS_UNKNOWN_ERROR; - - cmdu_data = cntlr_gen_bk_caps_query(c, agent_mac, NULL); - if (!cmdu_data) - return UBUS_STATUS_UNKNOWN_ERROR; - - send_cmdu(c, cmdu_data); - map_free_cmdu(cmdu_data); - - return UBUS_STATUS_OK; + return 0; +// trace("%s:--->\n", __func__); +// struct blob_attr *tb[__BK_CAPS_POLICY_MAX]; +// struct controller *c = container_of(obj, struct controller, obj); +// char agent[18] = { 0 }; +// uint8_t agent_mac[6] = { 0 }; +// struct cmdu_cstruct *cmdu_data; +// +// blobmsg_parse(bk_caps_policy_params, __BK_CAPS_POLICY_MAX, tb, +// blob_data(msg), blob_len(msg)); +// +// // are the ubus method parameter empty? +// if (!tb[BK_CAPS_POLICY_AGENT]) { +// dbg("Must provide agent mac address\n"); +// return UBUS_STATUS_INVALID_ARGUMENT; +// } +// +// memset(agent, 0, sizeof(agent)); +// strncpy(agent, blobmsg_data(tb[STA_METRIC_QUERY_AGENT]), +// sizeof(agent) - 1); +// if (!hwaddr_aton(agent, agent_mac)) +// return UBUS_STATUS_UNKNOWN_ERROR; +// +// cmdu_data = cntlr_gen_bk_caps_query(c, agent_mac, NULL); +// if (!cmdu_data) +// return UBUS_STATUS_UNKNOWN_ERROR; +// +// send_cmdu(c, cmdu_data); +// map_free_cmdu(cmdu_data); +// +// return UBUS_STATUS_OK; } static int cntlr_topology_query(struct ubus_context *ctx, struct ubus_object *obj, @@ -1888,68 +1775,3 @@ void cntlr_remove_object(struct controller *c) free((void *)c->obj.methods); } } - -int cntlr_register_module(struct controller *c) -{ -#define cntlr_sign "f6dfa346957f45cb8d82dc6b77e2df61" - uint8_t cntlr_sig[16]; - char data[2 * sizeof(struct map_module) + 1] = {0}; - int ret; - uint32_t map_id; - struct blob_buf bb = {}; - struct map_module m = { - .role = MAP_ROLE_CONTROLLER, - .profile = MAP_PROFILE_2, - }; - const char *map_plugin = "map.1905"; - struct ubus_context *ctx = c->ubus_ctx; - - strtob(cntlr_sign, strlen(cntlr_sign) / 2, cntlr_sig); - memcpy(&m.sign, cntlr_sig, 16); - - /* register with map.1905 plugin */ - ret = ubus_lookup_id(ctx, map_plugin, &map_id); - if (ret) { - /* TODO: if map plugin is not installed, wait for it to appear. - * Retry after some time. - */ - dbg("plugin '%s' lookup failed. %s\n", map_plugin, - ubus_strerror(ret)); - return -1; - } - - blob_buf_init(&bb, 0); - blobmsg_add_u32(&bb, "module", c->obj.id); - btostr((unsigned char *)&m, sizeof(struct map_module), data); - blobmsg_add_string(&bb, "data", data); - ret = ubus_invoke(ctx, map_id, "register", bb.head, NULL, 0, 3000); - if (ret) { - warn("Failed to 'register' with %s (err = %s)\n", - map_plugin, ubus_strerror(ret)); - } - - blob_buf_free(&bb); - -#if 0 // testing notify event - blob_buf_init(&bb, 0); - blobmsg_add_u32(&bb, "module", c->obj.id); - blobmsg_add_string(&bb, "data", "Hello World"); - ret = ubus_notify(ctx, &c->obj, "1905-NOTIFICATION", bb.head, -1); - if (ret) - warn("Failed to notify 1905-NOTIFICATION\n"); - - blob_buf_free(&bb); - - // testing send - blob_buf_init(&bb, 0); - blobmsg_add_u32(&bb, "type", 0x800a); - blobmsg_add_string(&bb, "data", "aabbccddeeff00112233445566778899"); - ret = ubus_invoke(ctx, map_id, "send", bb.head, NULL, 0, 1000); - if (ret) - warn("map.1905 plugin 'send' ret (%s)\n", ubus_strerror(ret)); - - blob_buf_free(&bb); -#endif - - return 0; -} diff --git a/src/core/cntlr_ubus.h b/src/core/cntlr_ubus.h index 25234ad5138ad9e1b10a9f407a70e8c394409d1a..d213378c61085da799a1f3d4146ec202553286e6 100644 --- a/src/core/cntlr_ubus.h +++ b/src/core/cntlr_ubus.h @@ -17,6 +17,5 @@ extern int cntlr_publish_object(struct controller *c, const char *objname); extern void cntlr_remove_object(struct controller *c); extern int cntlr_register_module(struct controller *c); -void send_cmdu_cb(struct ubus_request *req, int type, struct blob_attr *msg); -int send_cmdu(struct controller *c, struct cmdu_cstruct *cmdu_data); +//int send_cmdu(struct controller *c, struct cmdu_cstruct *cmdu_data); #endif /* CNTLR_UBUS_H */ diff --git a/src/core/main.c b/src/core/main.c index 17224f3d1d88e5df5690a36043fa310ba58c1f4f..a389d5441ac46cb2e929139fc640863af2ba7044 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -101,7 +101,7 @@ int main(int argc, char **argv) start_logging(); start_test_logging(); - init_alloctrace("wificntlr"); + //init_alloctrace("wificntlr"); start_controller(); diff --git a/src/utils/debug.c b/src/utils/debug.c index 166e558d69eb1453562c8a6674b1b37e8b9c482b..ea54dc958875b7f208dfe156f7c143aedf6c35df 100644 --- a/src/utils/debug.c +++ b/src/utils/debug.c @@ -21,9 +21,6 @@ #include "utils.h" #include "debug.h" -#include <map1905/map2.h> -#include <map1905/maputils.h> - static int ffd, tfd; static FILE *outfile; static FILE *testfile; @@ -142,82 +139,86 @@ void dump(unsigned char *buf, int len, char *label) // TODO: duplicate of start_logging void start_test_logging(void) { - if (!testfile) { - if (testfile_path) { - if (usefifo) { - struct stat st; - int rfd; - - if (stat(testfile_path, &st)) - unlink(testfile_path); - - mkfifo(testfile_path, 0600); - if (stat(testfile_path, &st) == -1 || - !S_ISFIFO(st.st_mode)) - return; - - rfd = open(testfile_path, - O_RDONLY | O_NONBLOCK); - if (rfd) { - tfd = open(testfile_path, - O_WRONLY | O_NONBLOCK); - close(rfd); - } - } else { - testfile = fopen(testfile_path, "w+"); - } - } else { - testfile = stderr; - } - } + return; +// if (!testfile) { +// if (testfile_path) { +// if (usefifo) { +// struct stat st; +// int rfd; +// +// if (stat(testfile_path, &st)) +// unlink(testfile_path); +// +// mkfifo(testfile_path, 0600); +// if (stat(testfile_path, &st) == -1 || +// !S_ISFIFO(st.st_mode)) +// return; +// +// rfd = open(testfile_path, +// O_RDONLY | O_NONBLOCK); +// if (rfd) { +// tfd = open(testfile_path, +// O_WRONLY | O_NONBLOCK); +// close(rfd); +// } +// } else { +// testfile = fopen(testfile_path, "w+"); +// } +// } else { +// testfile = stderr; +// } +// } } void stop_test_logging(void) { - if (testfile) - fclose(testfile); - - if (tfd) { - close(tfd); - unlink(testfile_path); - } + return; +// if (testfile) +// fclose(testfile); +// +// if (tfd) { +// close(tfd); +// unlink(testfile_path); +// } } void log_test(int level, void *var, int len) { - char *bstr; - - if (level > verbose) - return; - - bstr = calloc(1, (len * 2) + 1); - if (!bstr) - return; - - btostr(var, len, bstr); - - fprintf(testfile, "%s\n", bstr); - fflush(testfile); - free(bstr); + return; +// char *bstr; +// +// if (level > verbose) +// return; +// +// bstr = calloc(1, (len * 2) + 1); +// if (!bstr) +// return; +// +// btostr(var, len, bstr); +// +// fprintf(testfile, "%s\n", bstr); +// fflush(testfile); +// free(bstr); } void log_cmdu(int level, void *var) { - struct cmdu_cstruct *cmdu = (struct cmdu_cstruct *) var; - int i; - - if (level > verbose) - return; - - for (i = 0; i < cmdu->num_tlvs; i++) { - uint16_t len; - uint8_t *btlv; - - btlv = map_put_tlv_cstruct(cmdu->tlvs[i], &len); - if (!btlv) - continue; - - log_test(level, btlv, len); - free(btlv); - } + return; +// struct cmdu_cstruct *cmdu = (struct cmdu_cstruct *) var; +// int i; +// +// if (level > verbose) +// return; +// +// for (i = 0; i < cmdu->num_tlvs; i++) { +// uint16_t len; +// uint8_t *btlv; +// +// btlv = map_put_tlv_cstruct(cmdu->tlvs[i], &len); +// if (!btlv) +// continue; +// +// log_test(level, btlv, len); +// free(btlv); +// } } diff --git a/src/utils/debug.h b/src/utils/debug.h index 2bf8d5d91ff3b03071c5474c8076845bbe42d4e6..76ff423bea6d38e2217982342a399d2e432dd5e6 100644 --- a/src/utils/debug.h +++ b/src/utils/debug.h @@ -10,7 +10,7 @@ #ifndef DEBUG_H #define DEBUG_H -#include "alloctrace.h" +//#include "alloctrace.h" void start_logging(void); void stop_logging(void);