diff --git a/src/core/cntlr_cmdu_generator.c b/src/core/cntlr_cmdu_generator.c index d08ad8db8227692b1621b5a83af65f2026b22346..88ab330abd0b8b4b462cc9e6888e850f01279f5a 100644 --- a/src/core/cntlr_cmdu_generator.c +++ b/src/core/cntlr_cmdu_generator.c @@ -635,25 +635,20 @@ out: } struct cmdu_buff *cntlr_gen_topology_query(struct controller *c, - uint8_t *origin, char *intf_name) + uint8_t *origin) { - return NULL; -// struct cmdu_cstruct *cmdu; -// -// cmdu = 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_TOPOLOGY_QUERY); -// -// cmdu->num_tlvs = 0; -// -// return cmdu; -// -//fail_cmdu: -// map_free_cmdu(cmdu); -// return NULL; + int ret; + struct cmdu_buff *resp; + uint16_t mid = 0; + + resp = cmdu_alloc_simple(CMDU_TYPE_TOPOLOGY_QUERY, &mid); + if (!resp) { + dbg("%s: -ENOMEM\n", __func__); + return NULL; + } + + memcpy(resp->origin, origin, 6); + cmdu_put_eom(resp); + return resp; } diff --git a/src/core/cntlr_cmdu_generator.h b/src/core/cntlr_cmdu_generator.h index fe6e0d26eddc59e79f4f7c100c46c3f7a7a1ec47..54ea12b6ddc20561c3f2ae01a3cef72c27d11108 100644 --- a/src/core/cntlr_cmdu_generator.h +++ b/src/core/cntlr_cmdu_generator.h @@ -37,5 +37,5 @@ struct cmdu_buff *cntlr_gen_ap_autoconfig_wsc(struct controller *c, struct tlv *basic_cap, struct tlv *wsc, uint16_t mid); struct cmdu_buff *cntlr_gen_topology_query(struct controller *c, - uint8_t *origin, char *intf_name); + uint8_t *origin); #endif diff --git a/src/core/cntlr_map.c b/src/core/cntlr_map.c index 6dfaa0b1a2835720049fb79267b2831d175fe915..077ad38678f883a05d69aa0e5e707575fb25392a 100644 --- a/src/core/cntlr_map.c +++ b/src/core/cntlr_map.c @@ -715,9 +715,11 @@ int cntlr_handle_map_event(void *module, uint16_t cmdutype, uint16_t mid, if (f[idx].handle) ret = f[idx].handle(c, cmdu); - cmdu_free(cmdu); + if (f[idx].debug) + ret = f[idx].debug(c, cmdu); //TODO: check ret + cmdu_free(cmdu); return ret; } diff --git a/src/core/cntlr_map_debug.c b/src/core/cntlr_map_debug.c index 50a8d217303356bb2357780a3fa3470a547a6471..3bc0284a75024439fde4576031ee5dcf00a0c419 100644 --- a/src/core/cntlr_map_debug.c +++ b/src/core/cntlr_map_debug.c @@ -23,6 +23,7 @@ #include <cmdu.h> #include <1905_tlvs.h> #include <map22.h> +#include <map_module.h> #include "cntlr_map_debug.h" @@ -43,6 +44,155 @@ int debug_topology_notification(void *cntlr, struct cmdu_buff *cmdu) int debug_topology_response(void *cntlr, struct cmdu_buff *cmdu) { + /* TODO: TODO: debug base TLVs */ + struct tlv_policy a_policy[] = { + [0] = { .type = MAP_TLV_SUPPORTED_SERVICE, .present = TLV_PRESENT_ONE }, + [1] = { .type = MAP_TLV_AP_OPERATIONAL_BSS, .present = TLV_PRESENT_ONE }, + [2] = { .type = MAP_TLV_ASSOCIATED_CLIENTS, .present = TLV_PRESENT_ONE }, + [3] = { .type = MAP_TLV_MULTIAP_PROFILE, .present = TLV_PRESENT_ONE } + }; + struct tlv *tv[4][16] = {0}; + + cmdu_parse_tlvs(cmdu, tv, a_policy, 4); + + trace("%s: --->\n", __func__); + trace("parsing topology response |" MACFMT "|CMDU: %s\n", + MAC2STR(cmdu->origin), + map_stringify_cmdu_type(cmdu_get_type(cmdu))); + + if (tv[0][0]) { + int i; + uint8_t *tlv = (uint8_t *) tv[0][0]->data; + + trace("TLV: %s\n", map_stringify_tlv_type(tv[0][0]->type)); + + trace("\tsupported_services_list: %d\n", + tlv[0]); + for (i = 0; i < tlv[0]; i++) { + trace("\t\tservice: %s\n", + (tlv[(i+1)] ? + "Multi-AP Agent" : "Multi-AP Controller")); + } + } + + + if (tv[1][0]) { + /* +struct tlv_ap_oper_bss { + uint8_t num_radio; + struct ap_oper_bss_radiolist { + uint8_t radio[6]; + uint8_t num_bss; + struct ap_oper_bss_bss { + uint8_t bssid[6]; + uint8_t ssidlen; + char ssid[32]; + } bss[]; + } radiolist[]; +} __attribute__((packed)); + */ + struct tlv_ap_oper_bss *tlv = (struct tlv_ap_oper_bss *)tv[1][0]->data; + uint8_t *data = (uint8_t *) tlv + 1; + int i; + + trace("TLV: %s\n", map_stringify_tlv_type(tv[1][0]->type)); + + trace("\tradios_nr: %d\n", tlv->num_radio); + for (i = 0; i < tlv->num_radio; i++) { + uint8_t num_bss = 0; + int j; + + trace("\t\tradio_id: " MACFMT "\n", + MAC2STR(data)); + data += 6; + + num_bss = *data; + data += 1; + + trace("\t\tbss_nr: %d\n", + num_bss); + for (j = 0; j < num_bss; j++) { + uint8_t ssidlen = 0; + + trace("\t\t\tbssid: " MACFMT "\n", + MAC2STR(data)); + data += 6; + + ssidlen = *data; + trace("\t\t\tssid_len: %d\n", + ssidlen); + data += 1; + + trace("\t\t\tssid: %.*s\n", + ssidlen, + data); + data += ssidlen; + } + } + } + + if (tv[2][0]) { +/* +struct tlv_assoc_client { + uint8_t num_bss; + struct assoc_client_bss { + uint8_t bssid[6]; + uint16_t num_client; + struct assoc_client_sta { + uint8_t macaddr[6]; + uint16_t conntime; + } sta[]; + } bss[]; +} __attribute__((packed)); +*/ + struct tlv_assoc_client *tlv = (struct tlv_assoc_client *)tv[2][0]->data; + uint8_t *data = (uint8_t *) tlv + 1; + int i; + + trace("TLV: %s\n", map_stringify_tlv_type(tv[2][0]->type)); + + + trace("\tbss_nr: %d\n", tlv->num_bss); + for (i = 0; i < tlv->num_bss; i++) { + uint16_t num_client = 0; + int j; + + trace("\t\tbssid: " MACFMT "\n", + MAC2STR(data)); + data += 6; + + memcpy(&num_client, data, 2); + data += 2; + + trace("\t\tassoc_clients_nr: %u\n", num_client); + for (j = 0; j < num_client; j++) { + uint16_t conntime = 0; + + trace("\t\t\tclient_addr: " MACFMT "\n", + MAC2STR(data)); + data += 6; + + memcpy(&conntime, data, 2); + data += 2; + trace("\t\t\tuptime: 0x%04x\n", conntime); + } + } + } + + if (tv[3][0]) { +/* +struct tlv_map_profile { + uint8_t profile; +} __attribute__((packed)); +*/ + struct tlv_map_profile *tlv = (struct tlv_map_profile *)tv[3][0]->data; + + trace("TLV: %s\n", map_stringify_tlv_type(tv[3][0]->type)); + trace("\tprofile: %d\n", tlv->profile); + } + + dbg("%s %d\n", __func__, __LINE__); + return 0; // uint8_t *tlv; // int i, j, k; diff --git a/src/core/cntlr_ubus.c b/src/core/cntlr_ubus.c index 84b4b84f3823203a856712403fc21a75d8a868f1..57b832488573fce1c94dac94b3c456c0d5262607 100644 --- a/src/core/cntlr_ubus.c +++ b/src/core/cntlr_ubus.c @@ -1644,7 +1644,7 @@ static int cntlr_topology_query(struct ubus_context *ctx, struct ubus_object *ob if (!hwaddr_aton(agent, agent_mac)) return UBUS_STATUS_UNKNOWN_ERROR; - cmdu_data = cntlr_gen_topology_query(c, agent_mac, NULL); + cmdu_data = cntlr_gen_topology_query(c, agent_mac); if (!cmdu_data) return UBUS_STATUS_UNKNOWN_ERROR;