diff --git a/src/core/cntlr_map.c b/src/core/cntlr_map.c index 5b01bcaedc5b1653a8c5ff733c27373419bfbbe1..6a39d2430680f14788cf68c62892cf58479bb203 100644 --- a/src/core/cntlr_map.c +++ b/src/core/cntlr_map.c @@ -178,7 +178,7 @@ out: return ret; } -int handle_ap_autoconfig_search(void *cntlr, struct cmdu_buff *rec_cmdu) +int handle_ap_autoconfig_search(void *cntlr, struct cmdu_buff *rx_cmdu) { trace("%s: --->\n", __func__); struct controller *c = (struct controller *) cntlr; @@ -196,7 +196,7 @@ int handle_ap_autoconfig_search(void *cntlr, struct cmdu_buff *rec_cmdu) struct tlv *tv[6][16] = {0}; int ret = 0; - ret = cmdu_parse_tlvs(rec_cmdu, tv, a_policy, 6); + ret = cmdu_parse_tlvs(rx_cmdu, tv, a_policy, 6); if (!tv[0][0] || !tv[1][0] || !tv[2][0] || !tv[3][0] || !tv[4][0] || !tv[5][0]) @@ -260,7 +260,7 @@ int handle_ap_autoconfig_search(void *cntlr, struct cmdu_buff *rec_cmdu) } else { char data[128] = {0}; - snprintf(data, sizeof(data), "{\"type\":\"error\", \"reason\":\"multiple controllers\", \"almac\":\""MACFMT"\"}", MAC2STR(rec_cmdu->origin)); + snprintf(data, sizeof(data), "{\"type\":\"error\", \"reason\":\"multiple controllers\", \"almac\":\""MACFMT"\"}", MAC2STR(rx_cmdu->origin)); cntlr_notify_event(c, "map.controller", data); } @@ -270,7 +270,7 @@ int handle_ap_autoconfig_search(void *cntlr, struct cmdu_buff *rec_cmdu) __func__, freq->band); cmdu = cntlr_gen_ap_autoconfig_response(cntlr, aladdr_origin, freq->band, - cmdu_get_mid(rec_cmdu)); + cmdu_get_mid(rx_cmdu)); if (!cmdu) return -1; @@ -281,9 +281,61 @@ int handle_ap_autoconfig_search(void *cntlr, struct cmdu_buff *rec_cmdu) } /* disable and quit on controller response */ -int handle_ap_autoconfig_response(void *cntlr, struct cmdu_buff *cmdu) +int handle_ap_autoconfig_response(void *cntlr, struct cmdu_buff *rx_cmdu) { trace("%s: --->\n", __func__); + struct controller *c = (struct controller *) cntlr; + bool has_cntlr = false; + struct tlv_policy a_policy[] = { + [0] = { .type = TLV_TYPE_SUPPORTED_ROLE, .present = TLV_PRESENT_ONE }, + [1] = { .type = MAP_TLV_SUPPORTED_SERVICE, .present = TLV_PRESENT_ONE }, + [2] = { .type = MAP_TLV_MULTIAP_PROFILE, .present = TLV_PRESENT_ONE }, + [3] = { .type = TLV_TYPE_SUPPORTED_FREQ_BAND, .present = TLV_PRESENT_ONE } + }; + struct tlv *tv[4][16] = {0}; + int i; + + cmdu_parse_tlvs(rx_cmdu, tv, a_policy, 4); + + if (!tv[0][0] || !tv[1][0] || !tv[2][0] || !tv[3][0]) + return -1; + + /* find if supported services containts controller */ + if (tv[1][0]->data[0] > 0) { + int i; + + for (i = 0; i < tv[1][0]->data[0]; i++) { + if (tv[1][0]->data[(i+1)] == + SUPPORTED_SERVICE_MULTIAP_CONTROLLER) { + has_cntlr = true; + break; + } + } + } + /* if does not support controller - return */ + if (!has_cntlr) { + dbg("autoconfig response does not support controller!\n"); + return -1; + } + + /* discard self response */ + if (!memcmp(rx_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(rx_cmdu->origin)); + cntlr_notify_event(c, "map.controller", data); + } + return 0; // struct controller *c = (struct controller *) cntlr; // struct tlv_supp_service *tlv;