diff --git a/src/Makefile b/src/Makefile index dc001c4fc8868681db04b8db9443cc126a69e633..493859a09f8edca3c2d3aa1f77d1f315b76908fa 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,6 @@ EXECS = mapagent CFLAGS+=-I. -Iinclude -Iutils -Icore -Iipc -D_GNU_SOURCE +CFLAGS+="-I/usr/include/libnl3" CFLAGS+= -g -Wall OBJS = \ diff --git a/src/core/agent_map.c b/src/core/agent_map.c index 18deca796fc6e313b5f7e8867a84536e314544a6..6f456af5659dcc1a0c205571cce1b31de02bdd0d 100644 --- a/src/core/agent_map.c +++ b/src/core/agent_map.c @@ -7,7 +7,7 @@ * */ -#include <time.h> + #include <stdio.h> #include <stdlib.h> #include <unistd.h> @@ -56,49 +56,52 @@ #include "agent_tlv_generator.h" #include "agent_cmdu_generator.h" -#define UBUS_TIMEOUT 1000 +#define UBUS_TIMEOUT 1000 /* TODO/FIXME: hardcoded 5 sec */ -#define UTIL_THRESHOLD_TIMER (5 * 1000) -#define RCPI_THRESHOLD_TIMER (5 * 1000) +#define UTIL_THRESHOLD_TIMER (5 * 1000) +#define RCPI_THRESHOLD_TIMER (5 * 1000) #define MAX_RADIO 20 -struct channel_response { +struct channel_response +{ uint8_t radio_id[6]; uint8_t response; }; -struct sta_error_response { +struct sta_error_response +{ uint8_t sta_mac[6]; uint8_t response; }; -#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)) +#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 { +struct tlv +{ uint8_t type; uint16_t len; uint8_t value[]; -} __attribute__ ((packed)); - +} __attribute__((packed)); typedef int (*map_cmdu_handler_t)(void *agent, struct cmdu_cstruct *cmdu); typedef int (*map_cmdu_sendfunc_t)(void *agent, struct cmdu_cstruct *cmdu); -uint16_t agent_send_cmdu(struct agent *a, struct cmdu_cstruct *cmdu); +int agent_send_cmdu(struct agent *a, struct cmdu_cstruct *cmdu); int agent_transition_sta(struct agent *a, struct tlv_steer_Req *p, struct netif_fh *fh, - int l, int m); + int l, int m); uint8_t *extract_tlv_by_type(struct cmdu_cstruct *cmdu, uint8_t tlv_type) { uint8_t *tlv; int i; - for (i = 0; i < cmdu->num_tlvs; i++) { + for (i = 0; i < cmdu->num_tlvs; i++) + { tlv = cmdu->tlvs[i]; if (*tlv == tlv_type) return tlv; @@ -113,9 +116,10 @@ static struct netif_fh *get_netif_by_bssid(struct agent *a, uint8_t *bssid) { struct netif_fh *p; - list_for_each_entry(p, &a->fhlist, list) { + list_for_each_entry(p, &a->fhlist, list) + { trace("bssid = " MACFMT " pbssid = " MACFMT "\n", - MAC2STR(bssid), MAC2STR(p->bssid)); + MAC2STR(bssid), MAC2STR(p->bssid)); if (!memcmp(bssid, p->bssid, 6)) return p; } @@ -124,9 +128,9 @@ static struct netif_fh *get_netif_by_bssid(struct agent *a, uint8_t *bssid) } int build_ap_autoconfig_wsc(void *agent, struct cmdu_cstruct *rec_cmdu, - struct wifi_radio_element *radio, int idx) + struct wifi_radio_element *radio, int idx) { - struct agent *a = (struct agent *) agent; + struct agent *a = (struct agent *)agent; struct cmdu_cstruct *cmdu; struct tlv_ap_radio_basic_cap *p; struct tlv_profile2_ap_cap *p1; @@ -135,11 +139,12 @@ int build_ap_autoconfig_wsc(void *agent, struct cmdu_cstruct *rec_cmdu, int tlv_index = 0; /* don't trigger autoconfig for bSTA radios */ - //if (radio->onboarded) - // return -1; + if (radio->onboarded) + return -1; cmdu = (struct cmdu_cstruct *)calloc(1, sizeof(struct cmdu_cstruct)); - if (!cmdu) { + if (!cmdu) + { fprintf(stderr, "failed to malloc cmdu\n"); return -1; } @@ -150,7 +155,7 @@ int build_ap_autoconfig_wsc(void *agent, struct cmdu_cstruct *rec_cmdu, strncpy(cmdu->intf_name, rec_cmdu->intf_name, sizeof(cmdu->intf_name) - 1); - p = agent_gen_ap_radio_basic_cap(a, cmdu, radio); + p = agent_gen_ap_radio_basic_cap(a, cmdu, idx); if (!p) goto fail_cmdu; cmdu->num_tlvs++; @@ -184,13 +189,13 @@ int build_ap_autoconfig_wsc(void *agent, struct cmdu_cstruct *rec_cmdu, map_free_cmdu(cmdu); return 0; fail_p3: - map_free_tlv_cstruct((uint8_t *) p3); + map_free_tlv_cstruct((uint8_t *)p3); fail_p2: - map_free_tlv_cstruct((uint8_t *) p2); + map_free_tlv_cstruct((uint8_t *)p2); fail_p1: - map_free_tlv_cstruct((uint8_t *) p1); + map_free_tlv_cstruct((uint8_t *)p1); fail_p: - map_free_tlv_cstruct((uint8_t *) p); + map_free_tlv_cstruct((uint8_t *)p); fail_cmdu: free(cmdu); return -1; @@ -244,16 +249,17 @@ int send_channel_pref_report(void *agent, struct cmdu_cstruct *cmdu) int send_oper_channel_report(void *agent, struct cmdu_cstruct *rec_cmdu) { trace("agent: %s: --->\n", __func__); - struct agent *a = (struct agent *) agent; + struct agent *a = (struct agent *)agent; uint16_t tlv_index = 0; uint32_t j; struct cmdu_cstruct *cmdu_data; int ret = 0; cmdu_data = (struct cmdu_cstruct *)calloc(1, - sizeof(struct cmdu_cstruct)); + sizeof(struct cmdu_cstruct)); - if (!cmdu_data) { + if (!cmdu_data) + { fprintf(stderr, "Out of memory!\n"); return -1; } @@ -265,16 +271,18 @@ int send_oper_channel_report(void *agent, struct cmdu_cstruct *rec_cmdu) cmdu_data->num_tlvs = 1 * a->num_radios; /* (Operating Channel report) */ cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, - sizeof(uint8_t *)); - if (!cmdu_data->tlvs) { + sizeof(uint8_t *)); + if (!cmdu_data->tlvs) + { map_free_cmdu(cmdu_data); return -1; } /* Operating Channel Report TLV 17.2.17 */ - for (j = 0; j < a->num_radios; j++) { + for (j = 0; j < a->num_radios; j++) + { struct tlv_oper_ch_report *p = - p = agent_gen_operate_channel_report(a, rec_cmdu, j); + p = agent_gen_operate_channel_report(a, rec_cmdu, j); if (!p) continue; cmdu_data->tlvs[tlv_index++] = (uint8_t *)p; @@ -289,13 +297,14 @@ int send_oper_channel_report(void *agent, struct cmdu_cstruct *rec_cmdu) int send_sta_steer_complete(void *agent, uint8_t *origin, const char *intf_name) { trace("agent: %s: --->\n", __func__); - struct agent *a = (struct agent *) agent; + struct agent *a = (struct agent *)agent; struct cmdu_cstruct *cmdu_data; int ret = 0; cmdu_data = (struct cmdu_cstruct *)calloc(1, - sizeof(struct cmdu_cstruct)); - if (!cmdu_data) { + sizeof(struct cmdu_cstruct)); + if (!cmdu_data) + { fprintf(stderr, "Out of memory!\n"); return -1; } @@ -306,7 +315,8 @@ int send_sta_steer_complete(void *agent, uint8_t *origin, const char *intf_name) strcpy(cmdu_data->intf_name, intf_name); cmdu_data->num_tlvs = 0; /* (No TLVs) */ - if (a->is_sta_steer_start) { + if (a->is_sta_steer_start) + { /** * Here we are sending the steering completed message * so we need to reset all the values of the @@ -325,20 +335,21 @@ int send_sta_steer_complete(void *agent, uint8_t *origin, const char *intf_name) } int send_steer_btm_report(void *agent, uint8_t *origin, const char *intf_name, - uint8_t *target_bssid, uint8_t *src_bssid, - uint8_t *sta, uint8_t status_code) + uint8_t *target_bssid, uint8_t *src_bssid, + uint8_t *sta, uint8_t status_code) { trace("agent: %s: --->\n", __func__); - struct agent *a = (struct agent *) agent; + struct agent *a = (struct agent *)agent; uint16_t tlv_index = 0; struct cmdu_cstruct *cmdu_data; int ret = 0, all_complete = 1; cmdu_data = (struct cmdu_cstruct *)calloc(1, - sizeof(struct cmdu_cstruct)); + sizeof(struct cmdu_cstruct)); - if (!cmdu_data) { + if (!cmdu_data) + { fprintf(stderr, "Out of memory!\n"); return -1; } @@ -350,18 +361,20 @@ int send_steer_btm_report(void *agent, uint8_t *origin, const char *intf_name, cmdu_data->num_tlvs = 1; /* (Steering BTM report) */ cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, - sizeof(uint8_t *)); + sizeof(uint8_t *)); - if (!cmdu_data->tlvs) { + if (!cmdu_data->tlvs) + { map_free_cmdu(cmdu_data); return -1; } /* Clent Steering BTM Report TLV 17.2.30 */ struct tlv_steer_btm_report *p = - p = agent_gen_steer_btm_report(a, target_bssid, - src_bssid, sta, status_code); - if (!p) { + p = agent_gen_steer_btm_report(a, target_bssid, + src_bssid, sta, status_code); + if (!p) + { map_free_cmdu(cmdu_data); return -1; } @@ -372,18 +385,20 @@ int send_steer_btm_report(void *agent, uint8_t *origin, const char *intf_name, map_free_cmdu(cmdu_data); trace("is_steer is %d steer count %d\n", - a->is_sta_steer_start, a->sta_steerlist_count); + a->is_sta_steer_start, a->sta_steerlist_count); /** * Check that the report is sent for a steering opportunity. * Here we store the status in the sta list and check * if the steering completed message can be sent */ - if (a->is_sta_steer_start) { + if (a->is_sta_steer_start) + { int i; /* iterate list of clients attempted to be steered */ - for (i = 0; i < a->sta_steerlist_count; i++) { + for (i = 0; i < a->sta_steerlist_count; i++) + { /* mark all steered clients as completed */ ret = memcmp(sta, a->sta_steer_list[i].sta_mac, 6); @@ -395,14 +410,17 @@ int send_steer_btm_report(void *agent, uint8_t *origin, const char *intf_name, * Now we need to check if the steering completed * message can be sent */ - for (i = 0; i < a->sta_steerlist_count; i++) { - if (a->sta_steer_list[i].complete != 1) { + for (i = 0; i < a->sta_steerlist_count; i++) + { + if (a->sta_steer_list[i].complete != 1) + { all_complete = 0; break; } } - if (all_complete) { + if (all_complete) + { /* Here we need to send the steering completed CMDU */ send_sta_steer_complete(agent, origin, intf_name); } @@ -427,7 +445,7 @@ int send_sta_link_metrics_response(void *agent, struct cmdu_cstruct *cmdu) } int send_unassoc_sta_link_metrics_response(void *agent, - struct cmdu_cstruct *cmdu) + struct cmdu_cstruct *cmdu) { return 0; } @@ -503,24 +521,6 @@ static const map_cmdu_sendfunc_t agent_maptxftable[] = { [0x33] = send_failed_connection_msg, }; - -int handle_topology_discovery(void *agent, struct cmdu_cstruct *cmdu) -{ - trace("%s: --->\n", __func__); - struct agent *a = (struct agent *) agent; - - if (!memcmp(cmdu->origin, a->cntlr_almac, 6)) { - if (!memcmp(a->cntlr_almac, a->almac, 6)) - a->depth = 0; - else - a->depth = 1; - } - - dbg("|%s:%d| depth %d\n", __func__, __LINE__, a->depth); - - return 0; -} - int handle_topology_notification(void *agent, struct cmdu_cstruct *cmdu) { trace("%s: --->\n", __func__); @@ -539,72 +539,6 @@ int handle_topology_response(void *agent, struct cmdu_cstruct *cmdu) return 0; } - -int handle_vendor_specific(void *agent, struct cmdu_cstruct *rec_cmdu) -{ - trace("%s: --->\n", __func__); - struct agent *a = (struct agent *) agent; - struct tlv_vendor_specific *p; - time_t now; - uint8_t depth = 2; - - time(&now); - p = extract_tlv_by_type(rec_cmdu, TLV_TYPE_VENDOR_SPECIFIC); - if (!p) - return -1; - - trace("|%s:%d| num_tlvs = %d, type = %02x, len = %04x%04x, value = %d\n", __func__, __LINE__, (uint8_t) p->m[0], (uint8_t)p->m[1], (uint16_t)p->m[2], p->m[3], (uint8_t)p->m[4]); - - depth = p->m[4]; - - /* no action if it is not IOPSYS oui */ - if (memcmp(p->vendor_oui, "\x00\x22\x07", 3)) - return -1; - - trace("|%s:%d| iopsys vendor oui CMDU received %02x%02x%02x\n", __func__, __LINE__, p->vendor_oui[0], p->vendor_oui[1], p->vendor_oui[2]); - - /* no action if it is local rec_cmdu */ - if (!memcmp(a->almac, rec_cmdu->origin, 6)) - return -1; - - trace("|%s:%d| rec_cmdu->id = %d, rx_id = %d, tx_id = %d\n", __func__, __LINE__, rec_cmdu->message_id, a->loop_detection.rx_mid, a->loop_detection.tx_mid); - if (rec_cmdu->message_id == a->loop_detection.rx_mid && depth > a->depth) { - trace("|%s:%d| LOOP DETECTED\n", __func__, __LINE__); - if (difftime(now, a->loop_detection.rx_time) < 3) { - trace("|%s:%d| LOOP DETECTED WITHIN TIME FRAME LIMIT OF 3(s)\n", __func__, __LINE__); - struct cmdu_cstruct *cmdu; - - cmdu = agent_gen_vendor_specific_cmdu(a, rec_cmdu->origin, a->depth); - if (cmdu) { - trace("|%s:%d| TRIGGERED LOOP DETECTION RESPONSE\n", __func__, __LINE__); - cmdu->message_id = rec_cmdu->message_id; - agent_send_cmdu(a, cmdu); - map_free_cmdu(cmdu); - } - - } - } else if (rec_cmdu->message_id == a->loop_detection.tx_mid) { - struct netif_bk *bk; - bool reload = false; - - trace("|%s:%d| Received response, loop has been detected! Disable bSTAs\n", __func__, __LINE__); - - list_for_each_entry(bk, &a->bklist, list) { - if (!config_disable_bsta(bk->cfg)) - reload = true; - - wifi_mod_bridge(a, bk->name, "remove"); - } - - if (reload) - uci_reload_services("wireless"); - } - - a->loop_detection.rx_time = now; - a->loop_detection.rx_mid = rec_cmdu->message_id; - return 0; -} - int handle_ap_autoconfig_search(void *agent, struct cmdu_cstruct *cmdu) { trace("agent: %s: --->\n", __func__); @@ -614,84 +548,56 @@ int handle_ap_autoconfig_search(void *agent, struct cmdu_cstruct *cmdu) int handle_ap_autoconfig_response(void *agent, struct cmdu_cstruct *cmdu) { trace("agent: %s: --->\n", __func__); - struct agent *a = (struct agent *) agent; - struct wifi_radio_element *radio = NULL; + struct agent *a = (struct agent *)agent; + struct wifi_radio_element *radio; struct tlv_supp_service *supp_serv; struct tlv_supported_freq_band *supp_freq; char mac_str[18] = {0}; bool cntlr = false; - uint8_t band; int i; - trace("%s %d mid = %d\n", __func__, __LINE__, cmdu->message_id); - - /* If MID is not the one we sent, discard response */ - for (i = 0; i < a->num_radios; i++) { - trace("radio %s has mid %d\n", a->radios[i].name, a->radios[i].mid); - if (a->radios[i].mid != cmdu->message_id) - continue; - - radio = &a->radios[i]; - break; - } - if (!radio) - return -1; - - supp_serv = (struct tlv_supp_service *) extract_tlv_by_type(cmdu, - MAP_TLV_SUPPORTED_SERVICE); + supp_serv = (struct tlv_supp_service *)extract_tlv_by_type(cmdu, + MAP_TLV_SUPPORTED_SERVICE); if (!supp_serv) return -1; - for (i = 0; i < supp_serv->supported_services_list; i++) { - if (supp_serv->supported_services[i].service == SUPPORTED_SERVICE_MULTIAP_CONTROLLER) { + for (i = 0; i < supp_serv->supported_services_list; i++) + { + if (supp_serv->supported_services[i].service == SUPPORTED_SERVICE_MULTIAP_CONTROLLER) + { cntlr = true; break; } } - if (!cntlr) { + if (!cntlr) + { trace("agent: Autoconfig response was not from controller\n"); return -1; } - dbg("cntlr_almac " MACFMT " origin " MACFMT "\n", - MAC2STR(a->cntlr_almac), MAC2STR(cmdu->origin)); - - /* if it is a new controller, update cntlr_almac and uci */ - if (memcmp(a->cntlr_almac, cmdu->origin, 6)) { - memcpy(a->cntlr_almac, cmdu->origin, 6); - if (!hwaddr_ntoa(a->cntlr_almac, mac_str)) - return -1; + memcpy(a->cntlr_almac, cmdu->origin, 6); + if (!hwaddr_ntoa(a->cntlr_almac, mac_str)) + return -1; - /* set self as root node, used for loop detection */ - if (!memcmp(a->cntlr_almac, a->almac, 6)) - a->depth = 0; + set_value_by_string("mapagent", "agent", "controller_mac", mac_str, + UCI_TYPE_STRING); + uloop_timeout_cancel(&a->autocfg_dispatcher); - set_value_by_string("mapagent", "agent", "controller_mac", mac_str, - UCI_TYPE_STRING); - dbg("|%s:%d| new controller found! Activate ACS configuration"\ - " for all radios\n", __func__, __LINE__); - for (i = 0; i < a->num_radios; i++) - a->radios[i].state = ACS_ACTIVE; - } + supp_freq = (struct tlv_supported_freq_band *)extract_tlv_by_type(cmdu, + TLV_TYPE_SUPPORTED_FREQ_BAND); + if (!supp_freq) + return -1; - /* return if it was just heartbeat and no activity */ - if (radio->state == ACS_HEARTBEAT) { - /** TODO: active own controller if no controller has been - * observed for certain time period - */ - } else if (radio->state == ACS_ACTIVE) { - supp_freq = (struct tlv_supported_freq_band *) extract_tlv_by_type(cmdu, - TLV_TYPE_SUPPORTED_FREQ_BAND); - if (!supp_freq) - return -1; + for (i = 0; i < a->num_radios; i++) + { + uint8_t band; + radio = a->radios + i; band = wifi_band_to_ieee1905band(radio->band); if (band != supp_freq->freq_band) - return -1; + continue; - dbg("|%s:%d| generate wsc for radio %s\n", __func__, __LINE__, - radio->name); build_ap_autoconfig_wsc(a, cmdu, radio, i); } @@ -699,12 +605,13 @@ int handle_ap_autoconfig_response(void *agent, struct cmdu_cstruct *cmdu) } static struct wifi_radio_element *wifi_get_radio_by_mac(struct agent *a, - uint8_t *hwaddr) + uint8_t *hwaddr) { struct wifi_radio_element *radio; int i; - for (i = 0; i < a->num_radios; i++) { + for (i = 0; i < a->num_radios; i++) + { radio = a->radios + i; if (memcmp(radio->macaddr, hwaddr, 6)) @@ -721,15 +628,13 @@ struct netif_fh *wifi_get_netif_by_bssid(struct agent *a, uint8_t *bssid) { struct netif_fh *fh; - list_for_each_entry(fh, &a->fhlist, list) { + list_for_each_entry(fh, &a->fhlist, list) + { if (hwaddr_equal(fh->bssid, bssid)) return fh; } - return NULL; -} - -static struct wifi_radio_element *wifi_get_radio_index_by_mac(struct agent *a, +int wifi_get_radio_index_by_mac(struct agent *a, uint8_t *hwaddr) { struct wifi_radio_element *radio; @@ -744,7 +649,7 @@ static struct wifi_radio_element *wifi_get_radio_index_by_mac(struct agent *a, return i; } - return NULL; + return -1; } int wifi_teardown_iface(const char *ifname) @@ -762,7 +667,8 @@ int wifi_teardown_map_ifaces_by_radio(struct agent *a, char *device) struct netif_fhcfg *fh, *fh_tmp; struct netif_bkcfg *bk, *bk_tmp; - list_for_each_entry_safe(fh, fh_tmp, &a->cfg.fhlist, list) { + list_for_each_entry_safe(fh, fh_tmp, &a->cfg.fhlist, list) + { if (strncmp(fh->device, device, sizeof(fh->device) - 1)) continue; @@ -770,6 +676,15 @@ int wifi_teardown_map_ifaces_by_radio(struct agent *a, char *device) clean_fh(fh); } + list_for_each_entry_safe(bk, bk_tmp, &a->cfg.bklist, list) + { + if (strncmp(bk->device, device, sizeof(bk->device) - 1)) + continue; + + wifi_teardown_iface(bk->name); + clean_bk(bk); + } + agent_config_reload(&a->cfg); return 0; } @@ -779,7 +694,8 @@ int wifi_teardown_map_ifaces_by_band(struct agent *a, enum wifi_band band) struct netif_fhcfg *fh, *fh_tmp; struct netif_bkcfg *bk, *bk_tmp; - list_for_each_entry_safe(fh, fh_tmp, &a->cfg.fhlist, list) { + list_for_each_entry_safe(fh, fh_tmp, &a->cfg.fhlist, list) + { if (fh->band != band) continue; @@ -787,6 +703,15 @@ int wifi_teardown_map_ifaces_by_band(struct agent *a, enum wifi_band band) clean_fh(fh); } + list_for_each_entry_safe(bk, bk_tmp, &a->cfg.bklist, list) + { + if (bk->band != band) + continue; + + wifi_teardown_iface(bk->name); + clean_bk(bk); + } + agent_config_reload(&a->cfg); return 0; @@ -794,17 +719,17 @@ int wifi_teardown_map_ifaces_by_band(struct agent *a, enum wifi_band band) /* return true if valid ifname is available */ int check_wireless_ifname(struct agent *a, const char *device, - const char *ifname) + const char *ifname) { - enum { + enum + { W_IFNAME, W_DEV, NUM_POLICIES }; const struct uci_parse_option opts[] = { - { .name = "ifname", .type = UCI_TYPE_STRING }, - { .name = "device", .type = UCI_TYPE_STRING } - }; + {.name = "ifname", .type = UCI_TYPE_STRING}, + {.name = "device", .type = UCI_TYPE_STRING}}; struct uci_option *tb[NUM_POLICIES]; struct uci_context *ctx; struct uci_package *pkg; @@ -816,12 +741,14 @@ int check_wireless_ifname(struct agent *a, const char *device, if (!ctx) return -1; - if (uci_load(ctx, "wireless", &pkg)) { + if (uci_load(ctx, "wireless", &pkg)) + { uci_free_context(ctx); return -1; } - uci_foreach_element(&pkg->sections, e) { + uci_foreach_element(&pkg->sections, e) + { struct uci_section *s = uci_to_section(e); if (strncmp(s->type, "wifi-iface", strlen("wifi-iface"))) @@ -829,7 +756,8 @@ int check_wireless_ifname(struct agent *a, const char *device, uci_parse_section(s, opts, NUM_POLICIES, tb); - if (tb[W_DEV]) { + if (tb[W_DEV]) + { const char *cfg_dev; cfg_dev = tb[W_DEV]->v.string; @@ -838,16 +766,19 @@ int check_wireless_ifname(struct agent *a, const char *device, } /* TODO: should work with 16 instead of 4 */ - if (num_ifs >= TMP_WIFI_IFACE_MAX_NUM) { + if (num_ifs >= TMP_WIFI_IFACE_MAX_NUM) + { rv = true; break; } - if (tb[W_IFNAME]) { + if (tb[W_IFNAME]) + { char *cfg_ifname; cfg_ifname = tb[W_IFNAME]->v.string; - if (!strncmp(cfg_ifname, ifname, IFNAMSIZ)) { + if (!strncmp(cfg_ifname, ifname, IFNAMSIZ)) + { rv = true; break; } @@ -862,11 +793,8 @@ int check_wireless_ifname(struct agent *a, const char *device, char *wifi_gen_first_ifname(struct agent *a, char *device, char *ifname) { int i; - int devnum = get_device_num_from_name(device); - snprintf(ifname, IFNAMSIZ, "%s%d", - a->cfg.netdev, - devnum); + strncpy(ifname, device, IFNAMSIZ); /* maximum number of interface per BSSID is currently 4 * setting a higher number may cause segfault within libwsc.so, @@ -874,16 +802,16 @@ char *wifi_gen_first_ifname(struct agent *a, char *device, char *ifname) * PLATFORM_COMPUTE_DH_SHARED_SECRET() (verified with i <= 8) */ /* TODO: should work with 16 instead of 4 */ - for (i = 1; i <= TMP_WIFI_IFACE_MAX_NUM; i++) { + for (i = 1; i <= TMP_WIFI_IFACE_MAX_NUM; i++) + { if (!check_wireless_ifname(a, device, ifname)) return ifname; - snprintf(ifname, IFNAMSIZ, "%s%d%s%d", - a->cfg.netdev, - devnum, - (a->cfg.brcm_setup ? "." : "_"), - i); + snprintf(ifname, IFNAMSIZ, "%s%s%d", + device, + (a->cfg.brcm_setup ? "." : "_"), + i); } return NULL; @@ -891,7 +819,7 @@ char *wifi_gen_first_ifname(struct agent *a, char *device, char *ifname) int handle_ap_autoconfig_wsc(void *agent, struct cmdu_cstruct *cmdu) { - struct agent *a = (struct agent *) agent; + struct agent *a = (struct agent *)agent; uint8_t bssid[6]; int i; uint8_t *tlv = NULL; @@ -900,8 +828,8 @@ int handle_ap_autoconfig_wsc(void *agent, struct cmdu_cstruct *cmdu) trace("%s: --->\n", __func__); - id_tlv = (struct tlv_ap_radio_identifier *) extract_tlv_by_type(cmdu, - MAP_TLV_AP_RADIO_IDENTIFIER); + id_tlv = (struct tlv_ap_radio_identifier *)extract_tlv_by_type(cmdu, + MAP_TLV_AP_RADIO_IDENTIFIER); if (!id_tlv) return -1; @@ -914,117 +842,108 @@ int handle_ap_autoconfig_wsc(void *agent, struct cmdu_cstruct *cmdu) dbg("|%s:%d| found radio = %s\n", __func__, __LINE__, radio->name); wifi_teardown_map_ifaces_by_radio(a, radio->name); - - if (radio->onboarded) { - dbg("|%s:%d| radio (%s) was onboarded, do not apply m2, apply heartbeat for this radio\n", - __func__, __LINE__, radio->name); - radio->configured = 1; /* not necessarily true */ - radio->state = ACS_HEARTBEAT; - goto teardown; - } /* iterate every TLV_TYPE_WSC, may be multiple */ - for (i = 0; i < cmdu->num_tlvs; i++) { + for (i = 0; i < cmdu->num_tlvs; i++) + { tlv = cmdu->tlvs[i]; - switch (*tlv) { - case TLV_TYPE_WSC: { + switch (*tlv) + { + case TLV_TYPE_WSC: + { struct mdata out; struct tlv_wsc *m2; char ifname[IFNAMSIZ] = {0}; int rv; - m2 = (struct tlv_wsc *) tlv; + m2 = (struct tlv_wsc *)tlv; - if (!wifi_gen_first_ifname(a, radio->name, ifname)) { - err("Failed to find valid interface name, "\ - "probably maximum number of "\ - "interfaces have been reached\n", - MACFMT "!\n", MAC2STR(bssid)); + if (!wifi_gen_first_ifname(a, radio->name, ifname)) + { + err("Failed to find valid interface name, " + "probably maximum number of " + "interfaces have been reached\n", + MACFMT "!\n", MAC2STR(bssid)); return -1; } - rv = wscProcessM2((void *) radio->autconfig.key, - radio->autconfig.m1_frame, - radio->autconfig.m1_size, - m2->wsc_frame, - m2->wsc_frame_size, &out, ifname); - if (!rv) { - err("Failed to process M2 target for interface "\ - MACFMT "!\n", MAC2STR(bssid)); + rv = wscProcessM2((void *)radio->autconfig.key, + radio->autconfig.m1_frame, + radio->autconfig.m1_size, + m2->wsc_frame, + m2->wsc_frame_size, &out, ifname); + if (!rv) + { + err("Failed to process M2 target for interface " MACFMT "!\n", MAC2STR(bssid)); wifi_teardown_map_ifaces_by_radio(a, - radio->name); + radio->name); /* Return rather than freeing because it may * belong to an updated frame */ return -1; } - if (BIT(3, out.output.mapie)) { - err("MAP Extension had teardown bit set, "\ - "tearing down all MAP interfaces"\ - " for bssid" MACFMT "\n", - MAC2STR(bssid)); + if (BIT(3, out.output.mapie)) + { + err("MAP Extension had teardown bit set, " + "tearing down all MAP interfaces" + " for bssid" MACFMT "\n", + MAC2STR(bssid)); wifi_teardown_map_ifaces_by_radio(a, - radio->name); - uci_set_wireless_interface_option("mapagent", - "wifi-radio", "device", - radio->name, "configured", "0"); + radio->name); goto teardown; } - rv = uci_apply_m2(&a->cfg, ifname, radio->name, - out.output.ssid, out.output.auth_types, - out.output.encryption_types, - out.output.network_key, - out.output.mapie, radio->band, - out.output.bridge, out.output.proto, - out.output.vid, out.output.br_ip, - out.output.bk_ssid, out.output.bk_key, - radio->onboarded); - if (rv) { - err("Failure to process M2, tearing down all "\ - " MAP interfaces"\ - " for bssid" MACFMT "\n", - MAC2STR(bssid)); + rv = uci_apply_m2(ifname, radio->name, out.output.ssid, + out.output.auth_types, + out.output.encryption_types, + out.output.network_key, + out.output.mapie, radio->band, + out.output.bridge, out.output.proto, + out.output.vid, out.output.br_ip, + out.output.bk_ssid, out.output.bk_key); + if (rv) + { + err("Failure to process M2, tearing down all " + " MAP interfaces" + " for bssid" MACFMT "\n", + MAC2STR(bssid)); wifi_teardown_map_ifaces_by_radio(a, - radio->name); + radio->name); goto teardown; } - break; } default: break; + } } - uci_set_wireless_interface_option("mapagent", "wifi-radio", "device", - radio->name, "configured", "1"); - dbg("|%s:%d| radio (%s) was configured! Apply heartbeat for this radio\n", - __func__, __LINE__, radio->name); + radio->name, "configured", "1"); radio->configured = 1; + //a->configured = true; wifi_reorder_interfaces(&a->cfg); agent_config_reload(&a->cfg); - radio->state = ACS_HEARTBEAT; //uci_apply_wps_credentials(&a->cfg, radio->band); teardown: // TODO: freeing from here risks freeing an updated frame agent_free_wsc_data(&radio->autconfig); radio->autconfig.key = NULL; radio->autconfig.m1_frame = NULL; - uci_reload_services("wireless"); - //uci_reload_services("dhcp"); + uci_reload_services(); return 0; } int handle_ap_autoconfig_renew(void *agent, struct cmdu_cstruct *cmdu) { trace("agent: %s: --->\n", __func__); - struct agent *a = (struct agent *) agent; + struct agent *a = (struct agent *)agent; struct wifi_radio_element *radio; int i; - for (i = 0; i < a->num_radios; i++) { + for (i = 0; i < a->num_radios; i++) + { radio = a->radios + i; build_ap_autoconfig_wsc(a, cmdu, radio, i); } @@ -1035,7 +954,8 @@ int get_radio_index(struct agent *a, uint8_t *mac) { int i; - for (i = 0; i < a->num_radios; i++) { + for (i = 0; i < a->num_radios; i++) + { if (hwaddr_equal(a->radios[i].macaddr, mac)) return i; } @@ -1047,7 +967,8 @@ int get_bss_index(struct wifi_radio_element *radio, uint8_t *bssid) { int i; - for (i = 0; i < radio->num_bss; i++) { + for (i = 0; i < radio->num_bss; i++) + { if (hwaddr_equal(radio->bsslist[i].bssid, bssid)) return i; } @@ -1056,14 +977,16 @@ int get_bss_index(struct wifi_radio_element *radio, uint8_t *bssid) } int get_radio_and_bss_index(struct agent *a, uint8_t *bssid, - int *radio_index) + int *radio_index) { int i; int bss_index; - for (i = 0; i < a->num_radios; i++) { + for (i = 0; i < a->num_radios; i++) + { bss_index = get_bss_index(&a->radios[i], bssid); - if (bss_index != -1) { + if (bss_index != -1) + { *radio_index = i; return bss_index; } @@ -1076,7 +999,7 @@ int get_radio_and_bss_index(struct agent *a, uint8_t *bssid, * ifname: NULL, include all the interface. */ static struct cmdu_cstruct *prepare_ap_metrics_query( - void *agent, char *ifname) + void *agent, char *ifname) { trace("%s --->\n", __func__); int total_bss = 0; @@ -1096,27 +1019,30 @@ static struct cmdu_cstruct *prepare_ap_metrics_query( memcpy(cmdu->origin, a->cntlr_almac, 6); strncpy(cmdu->intf_name, "br-lan", IFNAMESIZE - 1); - if (ifname == NULL) { + if (ifname == NULL) + { /* AP Metrics Query TLV */ cmdu->num_tlvs++; -// #ifdef PROFILE2 + // #ifdef PROFILE2 /* AP Radio Identifier TLV */ cmdu->num_tlvs += a->num_radios; -// #endif + // #endif for (i = 0; i < a->num_radios; i++) total_bss += a->radios[i].num_bss; - - } else if (ifname && (ifname[0] != '\0')) { + } + else if (ifname && (ifname[0] != '\0')) + { /* AP Metrics Query TLV */ cmdu->num_tlvs++; -// #ifdef PROFILE2 + // #ifdef PROFILE2 /* AP Radio Identifier TLV */ cmdu->num_tlvs++; -// #endif + // #endif radio = wifi_ifname_to_radio_element(a, ifname); - if (!radio) { + if (!radio) + { cmdu->num_tlvs = 0; goto error; } @@ -1125,7 +1051,8 @@ static struct cmdu_cstruct *prepare_ap_metrics_query( } cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, sizeof(uint8_t *)); - if (!cmdu->tlvs) { + if (!cmdu->tlvs) + { cmdu->num_tlvs = 0; goto error; } @@ -1138,52 +1065,59 @@ static struct cmdu_cstruct *prepare_ap_metrics_query( p1->tlv_type = MAP_TLV_AP_METRIC_QUERY; p1->bssid_nr = total_bss; p1->ap_metric_query_bssid = calloc(p1->bssid_nr, - sizeof(*p1->ap_metric_query_bssid)); - if (!p1->ap_metric_query_bssid) { + sizeof(*p1->ap_metric_query_bssid)); + if (!p1->ap_metric_query_bssid) + { free(p1); goto error; } - if (ifname == NULL) { + if (ifname == NULL) + { struct tlv_ap_radio_identifier *p2; k = 0; - for (i = 0; i < a->num_radios; i++) { + for (i = 0; i < a->num_radios; i++) + { radio = a->radios + i; -// #ifdef PROFILE2 + // #ifdef PROFILE2 p2 = agent_gen_ap_radio_identifier(a, radio->macaddr); if (p2) cmdu->tlvs[tlv_index++] = (uint8_t *)p2; -// #endif + // #endif - for (j = 0; j < radio->num_bss; j++) { + for (j = 0; j < radio->num_bss; j++) + { bss = radio->bsslist + j; memcpy(p1->ap_metric_query_bssid[k].bssid, - bss->bssid, 6); + bss->bssid, 6); k++; } } - - } else if (ifname && (ifname[0] != '\0')) { + } + else if (ifname && (ifname[0] != '\0')) + { struct tlv_ap_radio_identifier *p2; k = 0; radio = wifi_ifname_to_radio_element(a, ifname); - if (!radio) { + if (!radio) + { map_free_tlv_cstruct((uint8_t *)p1); goto error; } -// #ifdef PROFILE2 + // #ifdef PROFILE2 p2 = agent_gen_ap_radio_identifier(a, radio->macaddr); if (p2) cmdu->tlvs[tlv_index++] = (uint8_t *)p2; -// #endif + // #endif - for (i = 0; i < radio->num_bss; i++) { + for (i = 0; i < radio->num_bss; i++) + { bss = radio->bsslist + i; memcpy(p1->ap_metric_query_bssid[k].bssid, - bss->bssid, 6); + bss->bssid, 6); k++; } @@ -1198,7 +1132,7 @@ error: } static int prepare_ap_metrics_response(void *agent, - struct cmdu_cstruct *rec_cmdu) + struct cmdu_cstruct *rec_cmdu) { trace("%s: --->\n", __func__); struct cmdu_cstruct *cmdu; @@ -1220,7 +1154,7 @@ static int prepare_assoc_sta_metric_response(void *agent, char *ifname) struct cmdu_cstruct *cmdu; struct agent *a = (struct agent *)agent; - cmdu = agent_gen_assoc_sta_metric_response_per_intf(a, ifname); + cmdu = agent_gen_assoc_sta_metric_response(a, ifname); if (!cmdu) return -1; @@ -1240,7 +1174,7 @@ int handle_1905_ack(void *agent, struct cmdu_cstruct *cmdu) int handle_ap_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu) { trace("agent: %s: --->\n", __func__); - struct agent *a = (struct agent *) agent; + struct agent *a = (struct agent *)agent; uint16_t tlv_index = 0; uint32_t i; struct cmdu_cstruct *cmdu; @@ -1252,8 +1186,9 @@ int handle_ap_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu) int ret; cmdu = (struct cmdu_cstruct *)calloc(1, - sizeof(struct cmdu_cstruct)); - if (!cmdu) { + sizeof(struct cmdu_cstruct)); + if (!cmdu) + { fprintf(stderr, "Out of memory!\n"); return -1; } @@ -1265,21 +1200,23 @@ int handle_ap_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu) cmdu->num_tlvs = 3 * a->num_radios + 1; /* (Radio basic, HT, VHT capability per radio) */ -//#ifdef PROFILE2 + //#ifdef PROFILE2 cmdu->num_tlvs += 1 + 1 + 1 + 1; /* Channel scan, CAC, profile-2 AP capabilities and metric collection interval TLV */ -//#endif PROFILE2 + //#endif PROFILE2 cmdu->tlvs = (uint8_t **)calloc(cmdu->num_tlvs, sizeof(uint8_t *)); - if (!cmdu->tlvs) { + if (!cmdu->tlvs) + { map_free_cmdu(cmdu); return -1; } /* AP basic Radio Capability TLV*/ - for (i = 0; i < a->num_radios; i++) { + for (i = 0; i < a->num_radios; i++) + { struct tlv_ap_radio_basic_cap *p; - p = agent_gen_ap_radio_basic_cap(a, cmdu, &a->radios[i]); + p = agent_gen_ap_radio_basic_cap(a, cmdu, i); if (!p) continue; //cmdu->num_tlvs++; @@ -1295,7 +1232,8 @@ int handle_ap_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu) cmdu->tlvs[tlv_index++] = (uint8_t *)p2; /* HT Capability */ - for (i = 0; i < a->num_radios; i++) { + for (i = 0; i < a->num_radios; i++) + { struct tlv_ap_ht_cap *p3; p3 = agent_gen_ap_ht_caps(a, cmdu, i); @@ -1308,7 +1246,8 @@ int handle_ap_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu) } /* VHT Capability */ - for (i = 0; i < a->num_radios; i++) { + for (i = 0; i < a->num_radios; i++) + { struct tlv_ap_vht_cap *p4; p4 = agent_gen_ap_vht_caps(a, cmdu, i); @@ -1318,7 +1257,7 @@ int handle_ap_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu) cmdu->tlvs[tlv_index++] = (uint8_t *)p4; } -//#ifdef PROFILE2 + //#ifdef PROFILE2 /* Channel Scan Capability */ p5 = agent_gen_ch_scan_cap(a); if (!p5) @@ -1346,7 +1285,7 @@ int handle_ap_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu) goto fail; cmdu->tlvs[tlv_index++] = (uint8_t *)p8; -//#endif PROFILE2 + //#endif PROFILE2 ret = agent_send_cmdu(a, cmdu); map_free_cmdu(cmdu); @@ -1393,9 +1332,11 @@ static uint8_t calculate_radio_rcpi(struct agent *a, char *ifname) if (!radio) return 0; - for (j = 0; j < radio->num_bss; j++) { + for (j = 0; j < radio->num_bss; j++) + { bss = radio->bsslist + j; - for (k = 0; k < bss->num_stations; k++) { + for (k = 0; k < bss->num_stations; k++) + { sta = bss->stalist + k; rssi += sta->rssi; } @@ -1423,13 +1364,13 @@ static void agent_metric_report_timer_cb(struct uloop_timeout *t) refresh_interval: uloop_timeout_set(&cfg->metric_report_timer, - cfg->pcfg->report_interval * 1000); + cfg->pcfg->report_interval * 1000); } static void agent_util_threshold_timer_cb(struct uloop_timeout *t) { struct netif_fh *p = container_of(t, struct netif_fh, - util_threshold_timer); + util_threshold_timer); struct agent *a = p->agent; struct cmdu_cstruct *cmdu; uint8_t curr_util = 0; @@ -1438,9 +1379,9 @@ static void agent_util_threshold_timer_cb(struct uloop_timeout *t) curr_util = calculate_radio_util(a, p->name); prev_util = p->prev_util; if (((prev_util > p->cfg->util_threshold) && - (curr_util > p->cfg->util_threshold)) || - ((prev_util < p->cfg->util_threshold) && - (curr_util < p->cfg->util_threshold))) + (curr_util > p->cfg->util_threshold)) || + ((prev_util < p->cfg->util_threshold) && + (curr_util < p->cfg->util_threshold))) goto refresh_interval; cmdu = prepare_ap_metrics_query((void *)a, p->name); @@ -1458,7 +1399,7 @@ refresh_interval: static void agent_rcpi_thresold_timer_cb(struct uloop_timeout *t) { struct netif_fh *p = container_of(t, struct netif_fh, - rcpi_threshold_timer); + rcpi_threshold_timer); struct agent *a = p->agent; uint8_t curr_rcpi = 0; uint8_t prev_rcpi; @@ -1466,9 +1407,9 @@ static void agent_rcpi_thresold_timer_cb(struct uloop_timeout *t) curr_rcpi = calculate_radio_rcpi(a, p->name); prev_rcpi = p->prev_rcpi; if (((prev_rcpi > p->cfg->rcpi_threshold) && - (curr_rcpi > p->cfg->rcpi_threshold)) || - ((prev_rcpi < p->cfg->rcpi_threshold) && - (curr_rcpi < p->cfg->rcpi_threshold))) + (curr_rcpi > p->cfg->rcpi_threshold)) || + ((prev_rcpi < p->cfg->rcpi_threshold) && + (curr_rcpi < p->cfg->rcpi_threshold))) goto refresh_interval; prepare_assoc_sta_metric_response(a, p->name); @@ -1485,31 +1426,35 @@ static int agent_process_policy_config(struct agent *a) struct agent_config *cfg = &a->cfg; struct policy_cfg *c = cfg->pcfg; - if (c && (c->report_interval > 0)) { + if (c && (c->report_interval > 0)) + { cfg->metric_report_timer.cb = agent_metric_report_timer_cb; uloop_timeout_set(&cfg->metric_report_timer, - c->report_interval * 1000); + c->report_interval * 1000); } - for (i = 0; i < a->num_radios; i++) { + for (i = 0; i < a->num_radios; i++) + { struct netif_fh *p; p = wifi_radio_to_ap(a, a->radios[i].name); if (!p) continue; - if (p->cfg->util_threshold > 0) { + if (p->cfg->util_threshold > 0) + { p->util_threshold_timer.cb = agent_util_threshold_timer_cb; uloop_timeout_set(&p->util_threshold_timer, - UTIL_THRESHOLD_TIMER); + UTIL_THRESHOLD_TIMER); } - if (p->cfg->rcpi_threshold > 0) { + if (p->cfg->rcpi_threshold > 0) + { p->rcpi_threshold_timer.cb = agent_rcpi_thresold_timer_cb; uloop_timeout_set(&p->rcpi_threshold_timer, - RCPI_THRESHOLD_TIMER); + RCPI_THRESHOLD_TIMER); } } @@ -1543,78 +1488,81 @@ int handle_map_policy_config(void *agent, struct cmdu_cstruct *cmdu) if (!ctx) return -1; - if (uci_load(ctx, "mapagent", &pkg)) { + if (uci_load(ctx, "mapagent", &pkg)) + { uci_free_context(ctx); return -1; } - for (i = 0; i < cmdu->num_tlvs; i++) { + for (i = 0; i < cmdu->num_tlvs; i++) + { tlv = (uint8_t *)cmdu->tlvs[i]; fprintf(stderr, "TLV: %s\n", map_stringify_tlv_type(*tlv)); - switch (*tlv) { + switch (*tlv) + { case MAP_TLV_STEERING_POLICY: - { - struct tlv_steering_policy *p = - (struct tlv_steering_policy *)tlv; + { + struct tlv_steering_policy *p = + (struct tlv_steering_policy *)tlv; - agent_fill_steering_policy(a, p, ctx, pkg); - break; - } + agent_fill_steering_policy(a, p, ctx, pkg); + break; + } case MAP_TLV_METRIC_REPORTING_POLICY: - { - struct tlv_metric_report_policy *p = - (struct tlv_metric_report_policy *)tlv; + { + struct tlv_metric_report_policy *p = + (struct tlv_metric_report_policy *)tlv; - agent_fill_metric_report_policy(a, p, ctx, pkg); - break; - } + agent_fill_metric_report_policy(a, p, ctx, pkg); + break; + } case MAP_TLV_DEFAULT_8021Q_SETTINGS: - { - struct tlv_default_8021q_settings *p = - (struct tlv_default_8021q_settings *)tlv; + { + struct tlv_default_8021q_settings *p = + (struct tlv_default_8021q_settings *)tlv; - agent_fill_8021q_setting(a, p, ctx, pkg); - break; - } + agent_fill_8021q_setting(a, p, ctx, pkg); + break; + } case MAP_TLV_TRAFFIC_SEPARATION_POLICY: - { - struct tlv_traffic_sep_policy *p = - (struct tlv_traffic_sep_policy *)tlv; + { + struct tlv_traffic_sep_policy *p = + (struct tlv_traffic_sep_policy *)tlv; - agent_fill_traffic_sep_policy(a, p, ctx, pkg); - break; - } + agent_fill_traffic_sep_policy(a, p, ctx, pkg); + break; + } case MAP_TLV_CHANNEL_SCAN_REPORTING_POLICY: - { - struct tlv_ch_scan_rep_policy *p = - (struct tlv_ch_scan_rep_policy *)tlv; + { + struct tlv_ch_scan_rep_policy *p = + (struct tlv_ch_scan_rep_policy *)tlv; - agent_fill_ch_scan_rep_policy(a, p, ctx, pkg); - break; - } + agent_fill_ch_scan_rep_policy(a, p, ctx, pkg); + break; + } case MAP_TLV_UNSUCCESS_ASSOCIATION_POLICY: - { - struct tlv_unsuccess_assoc_policy *p = - (struct tlv_unsuccess_assoc_policy *)tlv; + { + struct tlv_unsuccess_assoc_policy *p = + (struct tlv_unsuccess_assoc_policy *)tlv; - agent_fill_unsuccess_assoc_policy(a, p, ctx, pkg); - break; - } + agent_fill_unsuccess_assoc_policy(a, p, ctx, pkg); + break; + } case MAP_TLV_BACKHAUL_BSS_CONFIG: - { - struct tlv_backhaul_bss_config *p = - (struct tlv_backhaul_bss_config *)tlv; + { + struct tlv_backhaul_bss_config *p = + (struct tlv_backhaul_bss_config *)tlv; - agent_fill_backhaul_bss_config(a, p, ctx, pkg); - break; - } + agent_fill_backhaul_bss_config(a, p, ctx, pkg); + break; + } } } @@ -1634,15 +1582,16 @@ int handle_map_policy_config(void *agent, struct cmdu_cstruct *cmdu) int handle_channel_pref_query(void *agent, struct cmdu_cstruct *rec_cmdu) { trace("%s: --->\n", __func__); - struct agent *a = (struct agent *) agent; + struct agent *a = (struct agent *)agent; uint16_t tlv_index = 0; uint32_t j; struct cmdu_cstruct *cmdu_data; int ret = 0; cmdu_data = (struct cmdu_cstruct *)calloc(1, - sizeof(struct cmdu_cstruct)); - if (!cmdu_data) { + sizeof(struct cmdu_cstruct)); + if (!cmdu_data) + { fprintf(stderr, "Out of memory!\n"); return -1; } @@ -1654,18 +1603,21 @@ int handle_channel_pref_query(void *agent, struct cmdu_cstruct *rec_cmdu) cmdu_data->num_tlvs = 2 * a->num_radios + 1 + 1; /* (Preference TLV + Restriction TLV)+(CAC status + CAC_report) */ cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, - sizeof(uint8_t *)); - if (!cmdu_data->tlvs) { + sizeof(uint8_t *)); + if (!cmdu_data->tlvs) + { map_free_cmdu(cmdu_data); return -1; } /* Channel Preference TLV 17.2.13 */ - for (j = 0; j < a->num_radios; j++) { + for (j = 0; j < a->num_radios; j++) + { struct tlv_channel_pref *p = (struct tlv_channel_pref *)calloc(1, - sizeof(struct tlv_channel_pref)); - if (p) { + sizeof(struct tlv_channel_pref)); + if (p) + { p->tlv_type = MAP_TLV_CHANNEL_PREFERENCE; agent_gen_radio_channel_preference(a, p, j); cmdu_data->tlvs[tlv_index++] = (uint8_t *)p; @@ -1673,24 +1625,26 @@ int handle_channel_pref_query(void *agent, struct cmdu_cstruct *rec_cmdu) } /* Radio Operation Restriction TLV 17.2.14*/ - for (j = 0; j < a->num_radios; j++) { + for (j = 0; j < a->num_radios; j++) + { struct tlv_radio_oper_restrict *p1 = (struct tlv_radio_oper_restrict *)calloc(1, - sizeof(struct tlv_radio_oper_restrict)); - if (p1) { + sizeof(struct tlv_radio_oper_restrict)); + if (p1) + { p1->tlv_type = MAP_TLV_RADIO_OPERATION_RESTRICTION; agent_gen_radio_restrict_channel(a, p1, j); cmdu_data->tlvs[tlv_index++] = (uint8_t *)p1; } } - -//#ifdef profile2 + //#ifdef profile2 /*TODO CAC Completion Report TLV (section 17.2.44). [Profile-2]*/ struct tlv_cac_comp_report *p2 = (struct tlv_cac_comp_report *)calloc(1, - sizeof(struct tlv_cac_comp_report)); - if (p2) { + sizeof(struct tlv_cac_comp_report)); + if (p2) + { p2->tlv_type = MAP_TLV_CAC_COMPLETION_REPORT; agent_gen_cac_comp_report(a, p2); cmdu_data->tlvs[tlv_index++] = (uint8_t *)p2; @@ -1699,18 +1653,19 @@ int handle_channel_pref_query(void *agent, struct cmdu_cstruct *rec_cmdu) /*TODO CAC Status Report TLV (section 17.2.45). [Profile-2]*/ struct tlv_cac_status_report *p3 = (struct tlv_cac_status_report *)calloc(1, - sizeof(struct tlv_cac_status_report)); - if (p3) { + sizeof(struct tlv_cac_status_report)); + if (p3) + { p3->tlv_type = MAP_TLV_CAC_STATUS_REPORT; - p3->nbr_available_ch = 0; //TODO dummy value - p3->ch_data = NULL; //TODO dummy value - p3->nbr_pairs_duration = 0; //TODO dummy value - p3->duration_pair_data = NULL; //TODO dummy value - p3->nbr_pairs_coundown = 0; //TODO dummy value - p3->count_pair_data = NULL; //TODO dummy value + p3->nbr_available_ch = 0; //TODO dummy value + p3->ch_data = NULL; //TODO dummy value + p3->nbr_pairs_duration = 0; //TODO dummy value + p3->duration_pair_data = NULL; //TODO dummy value + p3->nbr_pairs_coundown = 0; //TODO dummy value + p3->count_pair_data = NULL; //TODO dummy value cmdu_data->tlvs[tlv_index++] = (uint8_t *)p3; } -//#endif + //#endif ret = agent_send_cmdu(a, cmdu_data); map_free_cmdu(cmdu_data); @@ -1718,19 +1673,20 @@ int handle_channel_pref_query(void *agent, struct cmdu_cstruct *rec_cmdu) } int send_channel_sel_response(void *agent, struct cmdu_cstruct *rec_cmdu, - struct channel_response *channel_resp, - uint32_t channel_response_nr) + struct channel_response *channel_resp, + uint32_t channel_response_nr) { trace("agent: %s: --->\n", __func__); - struct agent *a = (struct agent *) agent; + struct agent *a = (struct agent *)agent; uint16_t tlv_index = 0; uint32_t j, ret = 0; struct cmdu_cstruct *cmdu_data; cmdu_data = (struct cmdu_cstruct *)calloc(1, - sizeof(struct cmdu_cstruct)); + sizeof(struct cmdu_cstruct)); - if (!cmdu_data) { + if (!cmdu_data) + { fprintf(stderr, "Out of memory!\n"); return -1; } @@ -1742,21 +1698,23 @@ int send_channel_sel_response(void *agent, struct cmdu_cstruct *rec_cmdu, cmdu_data->num_tlvs = 1 * channel_response_nr; /* (channel selection response) */ cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, - sizeof(uint8_t *)); + sizeof(uint8_t *)); - if (!cmdu_data->tlvs) { + if (!cmdu_data->tlvs) + { map_free_cmdu(cmdu_data); return -1; } /* Operating Channel Response TLV 17.2.16 */ - for (j = 0; j < channel_response_nr; j++) { + for (j = 0; j < channel_response_nr; j++) + { struct tlv_ch_selection_resp *p = NULL; /* Here we need to check that the radio *response is for the radio for which we get request */ p = agent_gen_operate_channel_response(a, rec_cmdu, - channel_resp[j].radio_id, channel_resp[j].response); + channel_resp[j].radio_id, channel_resp[j].response); if (!p) continue; cmdu_data->tlvs[tlv_index++] = (uint8_t *)p; @@ -1773,57 +1731,61 @@ int send_channel_sel_response(void *agent, struct cmdu_cstruct *rec_cmdu, } int agent_fill_radio_max_preference(void *agent, - struct channel_response *channel_resp, - uint32_t *channel_response_nr) + struct channel_response *channel_resp, + uint32_t *channel_response_nr) { trace("agent: %s: --->\n", __func__); - struct agent *a = (struct agent *) agent; + struct agent *a = (struct agent *)agent; uint32_t j = 0, k = 0, l = 0; struct wifi_radio_element *radio = NULL; *channel_response_nr = a->num_radios; - for (j = 0; j < a->num_radios; j++) { + for (j = 0; j < a->num_radios; j++) + { radio = a->radios + j; memcpy(channel_resp[j].radio_id, radio->macaddr, 6); - for (k = 0; k < radio->num_supp_opclass; k++) { - for (l = 0; l < radio->supp_opclass[k]. - num_supported_channels; l++) + for (k = 0; k < radio->num_supp_opclass; k++) + { + for (l = 0; l < radio->supp_opclass[k].num_supported_channels; l++) radio->supp_opclass[k].supp_chanlist[l].pref = - 0xff; + 0xff; } channel_resp[j].response = 0x00; } return 0; } -int agent_process_channel_pref_tlv(void *agent, struct tlv_channel_pref *p, - struct channel_response *channel_resp, - uint32_t *channel_resp_nr) +int agent_process_channel_pref_tlv(void *agent, struct tlv_channel_pref *p, + struct channel_response *channel_resp, + uint32_t *channel_resp_nr) { trace("agent: %s: --->\n", __func__); - struct agent *a = (struct agent *) agent; + struct agent *a = (struct agent *)agent; int ret = 0; - uint32_t match = 0, found = 0; + uint32_t match = 0, found = 0; int j, l; struct wifi_radio_element *radio; trace("\tradio_id: " MACFMT "\n", MAC2STR(p->radio_id)); - for (l = 0; l < a->num_radios; l++) { + for (l = 0; l < a->num_radios; l++) + { radio = a->radios + l; match = memcmp(radio->macaddr, p->radio_id, 6); - if (match == 0) { + if (match == 0) + { found = 1; memcpy(channel_resp[*channel_resp_nr].radio_id, - radio->macaddr, 6); + radio->macaddr, 6); channel_resp[*channel_resp_nr].response = 0x00; break; } } - if (found == 0) { + if (found == 0) + { memcpy(channel_resp[*channel_resp_nr].radio_id, - p->radio_id, 6); + p->radio_id, 6); /* Here response code is a Reserved code * to decline the request */ @@ -1833,10 +1795,13 @@ int agent_process_channel_pref_tlv(void *agent, struct tlv_channel_pref *p, } trace("ch_preference_op_class_nr: %d\n", p->ch_preference_op_class_nr); - for (j = 0; j < p->ch_preference_op_class_nr; j++) { + for (j = 0; j < p->ch_preference_op_class_nr; j++) + { /* Here we need to search the operating class in the radio */ - for (l = 0; l < radio->num_supp_opclass; l++) { - if (radio->supp_opclass[l].id == p->op_class[j].op_class) { + for (l = 0; l < radio->num_supp_opclass; l++) + { + if (radio->supp_opclass[l].id == p->op_class[j].op_class) + { int k; /* Here we reset all the channels preferences @@ -1844,32 +1809,32 @@ int agent_process_channel_pref_tlv(void *agent, struct tlv_channel_pref *p, * preference */ trace("op_class : %d channel_nr %d\n", - p->op_class[j].op_class, - p->op_class[j].channel_nr); + p->op_class[j].op_class, + p->op_class[j].channel_nr); for (k = 0; k < - radio->supp_opclass[l].num_supported_channels; - k++) - radio->supp_opclass[l]. - supp_chanlist[k].pref = 0xff; + radio->supp_opclass[l].num_supported_channels; + k++) + radio->supp_opclass[l].supp_chanlist[k].pref = 0xff; - for (k = 0; k < p->op_class[j].channel_nr; k++) { + for (k = 0; k < p->op_class[j].channel_nr; k++) + { int m; for (m = 0; m < - radio->supp_opclass[l]. - num_supported_channels ; m++) { + radio->supp_opclass[l].num_supported_channels; + m++) + { trace("channel %d\n", - p->op_class[j].channel_list[k]); + p->op_class[j].channel_list[k]); if (p->op_class[j].channel_list[k] == - radio->supp_opclass[l]. - supp_chanlist[m].channel) { - radio->supp_opclass[l]. - supp_chanlist[m].pref = + radio->supp_opclass[l].supp_chanlist[m].channel) + { + radio->supp_opclass[l].supp_chanlist[m].pref = p->op_class[j].preference; trace("channel pref is %d\n", - p->op_class[j].preference); + p->op_class[j].preference); } } } @@ -1884,7 +1849,7 @@ int agent_process_channel_pref_tlv(void *agent, struct tlv_channel_pref *p, int handle_channel_sel_request(void *agent, struct cmdu_cstruct *cmdu) { trace("agent: %s: --->\n", __func__); - struct agent *a = (struct agent *) agent; + struct agent *a = (struct agent *)agent; int ret = 0; struct channel_response channel_resp[MAX_RADIO]; uint32_t channel_resp_nr = 0, match = 0; @@ -1897,68 +1862,73 @@ int handle_channel_sel_request(void *agent, struct cmdu_cstruct *cmdu) * from the channel selection request * then send the CMDU for channel selection response */ - if (cmdu->num_tlvs != 0) { - for (i = 0; i < cmdu->num_tlvs; i++) { - tlv = (uint8_t *) cmdu->tlvs[i]; - switch (*tlv) { + if (cmdu->num_tlvs != 0) + { + for (i = 0; i < cmdu->num_tlvs; i++) + { + tlv = (uint8_t *)cmdu->tlvs[i]; + switch (*tlv) + { case MAP_TLV_CHANNEL_PREFERENCE: - { - struct tlv_channel_pref *p = - (struct tlv_channel_pref *)tlv; - pref_tlv_present = 1; + { + struct tlv_channel_pref *p = + (struct tlv_channel_pref *)tlv; + pref_tlv_present = 1; - ret = agent_process_channel_pref_tlv - (agent, p, channel_resp, - &channel_resp_nr); - } + ret = agent_process_channel_pref_tlv(agent, p, channel_resp, + &channel_resp_nr); + } case MAP_TLV_TRANSMIT_POWER_LIMIT: + { + struct tlv_tx_power_limit *p = + (struct tlv_tx_power_limit *)tlv; + int l; + + trace("tlv radio_id: " MACFMT "\n", + MAC2STR(p->radio_id)); + for (l = 0; l < a->num_radios; l++) { - struct tlv_tx_power_limit *p = - (struct tlv_tx_power_limit *)tlv; - int l; - - trace("tlv radio_id: " MACFMT "\n", - MAC2STR(p->radio_id)); - for (l = 0; l < a->num_radios; l++) { - radio = a->radios + l; - match = memcmp(radio->macaddr, p->radio_id, 6); - if (match == 0) { - /* Here we set the + radio = a->radios + l; + match = memcmp(radio->macaddr, p->radio_id, 6); + if (match == 0) + { + /* Here we set the * transmit_power_limit * of the radio */ - radio->transmit_power_limit = - p->tx_power_limit; - trace("transmit power %d\n", - p->tx_power_limit); - break; - } + radio->transmit_power_limit = + p->tx_power_limit; + trace("transmit power %d\n", + p->tx_power_limit); + break; } } + } default: break; } } } - if (cmdu->num_tlvs == 0 || pref_tlv_present == 0) { + if (cmdu->num_tlvs == 0 || pref_tlv_present == 0) + { /* Here the condition is that the * channel selection request have no tlvs or only transmit power tlv * so we need to set all the prefernce in all radios to max 15 */ agent_fill_radio_max_preference(agent, - channel_resp, &channel_resp_nr); + channel_resp, &channel_resp_nr); } ret = send_channel_sel_response(agent, cmdu, - channel_resp, channel_resp_nr); + channel_resp, channel_resp_nr); return ret; } int handle_sta_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu) { - struct agent *a = (struct agent *) agent; + struct agent *a = (struct agent *)agent; struct cmdu_cstruct *cmdu; struct tlv_client_info *p = NULL, *query; struct tlv_client_cap_report *p1 = NULL; @@ -1975,12 +1945,13 @@ int handle_sta_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu) if (rec_cmdu->num_tlvs == 0) return -1; - query = (struct tlv_client_info *) rec_cmdu->tlvs[0]; + query = (struct tlv_client_info *)rec_cmdu->tlvs[0]; if (query->tlv_type != MAP_TLV_CLIENT_INFO) return -1; cmdu = (struct cmdu_cstruct *)calloc(1, sizeof(struct cmdu_cstruct)); - if (!cmdu) { + if (!cmdu) + { dbg("Out of memory!\n"); return -1; } @@ -1998,15 +1969,15 @@ int handle_sta_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu) p->tlv_type = MAP_TLV_CLIENT_INFO; memcpy(p->bssid, query->bssid, 6); memcpy(p->client_addr, query->client_addr, 6); - p1 = (struct tlv_client_cap_report *) calloc(1, - sizeof(struct tlv_client_cap_report)); + p1 = (struct tlv_client_cap_report *)calloc(1, + sizeof(struct tlv_client_cap_report)); if (!p1) goto fail_cmdu; p1->result_code = 0x01; p1->tlv_type = MAP_TLV_CLIENT_CAPABILITY_REPORT; - p2 = (struct tlv_error_code *) calloc(1, sizeof(struct tlv_error_code)); + p2 = (struct tlv_error_code *)calloc(1, sizeof(struct tlv_error_code)); if (!p2) goto fail_cmdu; @@ -2015,23 +1986,26 @@ int handle_sta_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu) memcpy(p2->addr, query->client_addr, 6); fh = get_netif_by_bssid(a, query->bssid); - if (!fh) { + if (!fh) + { dbg("BSS not found!\n"); goto send_cmdu; } - list_for_each_entry(s, &fh->stalist, list) - if (!memcmp(s->macaddr, query->client_addr, 6)) { - found = true; - break; - } - if (!found || !s) { + list_for_each_entry(s, &fh->stalist, list) if (!memcmp(s->macaddr, query->client_addr, 6)) + { + found = true; + break; + } + if (!found || !s) + { p2->reason_code = 0x02; dbg("Missing client!\n"); goto send_cmdu; } - if (!s->assoc_frame) { + if (!s->assoc_frame) + { dbg("Missing assoc frame!\n"); goto send_cmdu; } @@ -2082,31 +2056,21 @@ int handle_ap_metrics_query(void *agent, struct cmdu_cstruct *cmdu) return 0; } -int handle_sta_link_metrics_query(void *agent, struct cmdu_cstruct *rec_cmdu) +int handle_sta_link_metrics_query(void *agent, struct cmdu_cstruct *cmdu) { trace("%s: --->\n", __func__); - struct cmdu_cstruct *cmdu; - struct agent *a = (struct agent *)agent; - - cmdu = agent_gen_assoc_sta_metric_response(a, rec_cmdu); - if (!cmdu) - return -1; - - agent_send_cmdu(a, cmdu); - map_free_cmdu(cmdu); - return 0; } int handle_unassoc_sta_link_metrics_query(void *agent, - struct cmdu_cstruct *cmdu) + struct cmdu_cstruct *cmdu) { trace("%s: --->\n", __func__); return 0; } int handle_unassoc_sta_link_metrics_response(void *agent, - struct cmdu_cstruct *cmdu) + struct cmdu_cstruct *cmdu) { trace("%s: --->\n", __func__); return 0; @@ -2143,34 +2107,39 @@ bool agent_rcpi_steer(void) } int validate_sta_bssid_assoc(struct netif_fh *fh, struct tlv_steer_Req *p, - struct sta_error_response *sta_resp, uint32_t *cnt, - struct agent *a) + struct sta_error_response *sta_resp, uint32_t *cnt, + struct agent *a) { int l = 0; struct sta *s; uint32_t count = 0; uint32_t res = 0, found = 0; - for (l = 0; l < p->sta_list_cnt; l++) { - list_for_each_entry(s, &fh->stalist, list) { + for (l = 0; l < p->sta_list_cnt; l++) + { + list_for_each_entry(s, &fh->stalist, list) + { trace("stalist :" MACFMT "\n", - MAC2STR(s->macaddr)); + MAC2STR(s->macaddr)); res = memcmp(s->macaddr, p->steering_req_macs[l].addr, 6); - if (res == 0) { + if (res == 0) + { found = 1; /** * Here as the sta is present check that in this case * for steering opportunity put that in the array */ - if (p->request_mode == 0x00) { + if (p->request_mode == 0x00) + { memcpy(a->sta_steer_list[a->sta_steerlist_count].sta_mac, - p->steering_req_macs[l].addr, 6); + p->steering_req_macs[l].addr, 6); a->sta_steerlist_count = a->sta_steerlist_count + 1; } break; } } - if (found == 0 || !s) { + if (found == 0 || !s) + { dbg("Missing STA client!\n"); memcpy(sta_resp[count].sta_mac, p->steering_req_macs[l].addr, 6); sta_resp[count].response = 0x02; @@ -2182,12 +2151,12 @@ int validate_sta_bssid_assoc(struct netif_fh *fh, struct tlv_steer_Req *p, } int agent_send_request_transition(void *agent, uint8_t *client_sta, - struct netif_fh *fh, uint8_t *bssid, uint32_t timeout) + struct netif_fh *fh, uint8_t *bssid, uint32_t timeout) { - struct agent *a = (struct agent *) agent; - char client_macstr[18] = { 0 }; - char bssid_str[18] = { 0 }; - struct blob_buf bb = { 0 }; + struct agent *a = (struct agent *)agent; + char client_macstr[18] = {0}; + char bssid_str[18] = {0}; + struct blob_buf bb = {0}; int ret = 0; void *tbl; @@ -2205,15 +2174,17 @@ int agent_send_request_transition(void *agent, uint8_t *client_sta, blobmsg_add_string(&bb, NULL, bssid_str); blobmsg_close_table(&bb, tbl); - if (timeout) { + if (timeout) + { //fill the timeout } ret = ubus_invoke(a->ubus_ctx, fh->wifi, "request_transition", bb.head, - NULL, NULL, UBUS_TIMEOUT); - if (ret) { + NULL, NULL, UBUS_TIMEOUT); + if (ret) + { trace("[%s:%d] ubus call failed for |wifi.ap. send|", - __func__, __LINE__); + __func__, __LINE__); goto out; } @@ -2225,18 +2196,20 @@ out: //TODO search BSSID incase of wildcard or in case need to get the //implementation specific policy section 11.4 int agent_search_bssid_for_sta(struct agent *a, uint8_t *sta, uint8_t *bssid, - uint8_t *src_bssid) + uint8_t *src_bssid) { struct netif_fh *p; int ret = 0; trace("agent: %s: --->\n", __func__); - list_for_each_entry(p, &a->fhlist, list) { + list_for_each_entry(p, &a->fhlist, list) + { trace("bssid = " MACFMT " pbssid = " MACFMT "\n", - MAC2STR(bssid), MAC2STR(p->bssid)); + MAC2STR(bssid), MAC2STR(p->bssid)); ret = memcmp(src_bssid, p->bssid, 6); - if (ret != 0) { + if (ret != 0) + { memcpy(bssid, p->bssid, 6); return 0; } @@ -2246,10 +2219,10 @@ int agent_search_bssid_for_sta(struct agent *a, uint8_t *sta, uint8_t *bssid, } int send_1905_acknowledge(void *agent, - struct cmdu_cstruct *rec_cmdu, - struct sta_error_response *sta_resp, uint32_t sta_count) + struct cmdu_cstruct *rec_cmdu, + struct sta_error_response *sta_resp, uint32_t sta_count) { - struct agent *a = (struct agent *) agent; + struct agent *a = (struct agent *)agent; uint16_t tlv_index = 0; uint32_t j; struct cmdu_cstruct *cmdu_data; @@ -2257,9 +2230,10 @@ int send_1905_acknowledge(void *agent, trace("agent: %s: --->\n", __func__); cmdu_data = (struct cmdu_cstruct *)calloc(1, - sizeof(struct cmdu_cstruct)); + sizeof(struct cmdu_cstruct)); - if (!cmdu_data) { + if (!cmdu_data) + { fprintf(stderr, "Out of memory!\n"); return -1; } @@ -2271,22 +2245,24 @@ int send_1905_acknowledge(void *agent, cmdu_data->num_tlvs = sta_count; /* (TLV for error) */ cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, - sizeof(uint8_t *)); + sizeof(uint8_t *)); - if (!cmdu_data->tlvs) { + if (!cmdu_data->tlvs) + { map_free_cmdu(cmdu_data); return -1; } /* Error Code TLV 17.2.36 */ - for (j = 0; j < sta_count; j++) { + for (j = 0; j < sta_count; j++) + { struct tlv_error_code *p = NULL; /** * Here we need to check that the sta error * response */ p = agent_gen_tlv_error_code(a, rec_cmdu, - sta_resp[j].sta_mac, sta_resp[j].response); + sta_resp[j].sta_mac, sta_resp[j].response); if (!p) continue; cmdu_data->tlvs[tlv_index++] = (uint8_t *)p; @@ -2297,16 +2273,16 @@ int send_1905_acknowledge(void *agent, } int agent_send_restrict_sta(void *agent, uint32_t count_sta, - uint8_t client_sta[][6], struct netif_fh *fh, - uint8_t enable) + uint8_t client_sta[][6], struct netif_fh *fh, + uint8_t enable) { - struct agent *a = (struct agent *) agent; - char client_macstr[18] = { 0 }; - char bssid_str[18] = { 0 }; - struct blob_buf bb = { 0 }; + struct agent *a = (struct agent *)agent; + char client_macstr[18] = {0}; + char bssid_str[18] = {0}; + struct blob_buf bb = {0}; int ret = 0, i = 0; uint32_t id; - char ap_ifname[30] = { 0 }; + char ap_ifname[30] = {0}; void *tbl; trace("agent: %s: --->\n", __func__); @@ -2316,20 +2292,22 @@ int agent_send_restrict_sta(void *agent, uint32_t count_sta, blob_buf_init(&bb, 0); tbl = blobmsg_open_array(&bb, "client"); - for (i = 0; i < count_sta; i++) { + for (i = 0; i < count_sta; i++) + { hwaddr_ntoa(client_sta[i], client_macstr); trace("agent: stalist :" MACFMT "\n", - MAC2STR(client_sta[i])); + MAC2STR(client_sta[i])); blobmsg_add_string(&bb, NULL, client_macstr); } blobmsg_close_table(&bb, tbl); blobmsg_add_u32(&bb, "enable", enable); trace("Enable value is %d\n", enable); ret = ubus_invoke(a->ubus_ctx, fh->wifi, "assoc_control", bb.head, - NULL, NULL, UBUS_TIMEOUT); - if (ret) { + NULL, NULL, UBUS_TIMEOUT); + if (ret) + { trace("[%s:%d] ubus call failed for assoc_control", - __func__, __LINE__); + __func__, __LINE__); } out: blob_buf_free(&bb); @@ -2344,7 +2322,8 @@ static void wifi_restrict_sta_timeout(struct uloop_timeout *t) trace("agent: %s: --->\n", __func__); fh = s->vif; - if (!fh) { + if (!fh) + { trace("[%s:%d] Error BSSID not present", __func__, __LINE__); return -1; } @@ -2354,8 +2333,8 @@ static void wifi_restrict_sta_timeout(struct uloop_timeout *t) } int agent_check_start_validity_tmr(uint16_t validity_period, - uint32_t sta_count, uint8_t stalist[][6], - struct netif_fh *fh) + uint32_t sta_count, uint8_t stalist[][6], + struct netif_fh *fh) { uint32_t i = 0; struct restrict_sta_entry *s, *tmp; @@ -2365,11 +2344,14 @@ int agent_check_start_validity_tmr(uint16_t validity_period, if (stalist == NULL) return -1; - for (i = 0; i < sta_count; i++) { + for (i = 0; i < sta_count; i++) + { // check if the sta is already running a timer // delete the timer - list_for_each_entry_safe(s, tmp, &fh->restrict_stalist, list) { - if (!memcmp(s->sta, stalist[i], 6)) { + list_for_each_entry_safe(s, tmp, &fh->restrict_stalist, list) + { + if (!memcmp(s->sta, stalist[i], 6)) + { uloop_timeout_cancel(&s->restrict_timer); list_del(&s->list); free(s); @@ -2378,13 +2360,14 @@ int agent_check_start_validity_tmr(uint16_t validity_period, // If the timer is not already running ss = calloc(1, sizeof(struct restrict_sta_entry)); - if (ss) { + if (ss) + { memcpy(ss->sta, stalist[i], 6); //memcpy(ss->bssid, fh->bssid, 6); ss->vif = fh; ss->restrict_timer.cb = wifi_restrict_sta_timeout; uloop_timeout_set(&ss->restrict_timer, - validity_period * 1000); + validity_period * 1000); list_add_tail(&ss->list, &fh->restrict_stalist); } } @@ -2392,7 +2375,7 @@ int agent_check_start_validity_tmr(uint16_t validity_period, } int agent_check_stop_validity_tmr(uint32_t sta_count, uint8_t stalist[][6], - struct netif_fh *fh) + struct netif_fh *fh) { uint32_t i = 0; struct restrict_sta_entry *s = NULL, *tmp = NULL; @@ -2401,12 +2384,16 @@ int agent_check_stop_validity_tmr(uint32_t sta_count, uint8_t stalist[][6], if (stalist == NULL) return -1; - for (i = 0; i < sta_count; i++) { + for (i = 0; i < sta_count; i++) + { // check if the sta is already running a timer // delete the timer - list_for_each_entry_safe(s, tmp, &fh->restrict_stalist, list) { - if (s != NULL) { - if (!memcmp(s->sta, stalist[i], 6)) { + list_for_each_entry_safe(s, tmp, &fh->restrict_stalist, list) + { + if (s != NULL) + { + if (!memcmp(s->sta, stalist[i], 6)) + { uloop_timeout_cancel(&s->restrict_timer); list_del(&s->list); free(s); @@ -2418,17 +2405,17 @@ int agent_check_stop_validity_tmr(uint32_t sta_count, uint8_t stalist[][6], } int agent_process_assoc_cntl_tlv(void *agent, - struct tlv_client_assoc_control_req *p, - struct cmdu_cstruct *cmdu) + struct tlv_client_assoc_control_req *p, + struct cmdu_cstruct *cmdu) { trace("agent: %s: --->\n", __func__); - struct agent *a = (struct agent *) agent; + struct agent *a = (struct agent *)agent; int ret = 0, result = 0; - uint32_t match = 0, found = 0; + uint32_t match = 0, found = 0; int i, j, k, l, m; struct netif_fh *fh; struct sta *s; - struct sta_error_response sta_resp[MAX_STA]; + struct sta_error_response sta_resp[MAX_STA]; uint32_t count = 0; uint32_t res = 0, present = 0; uint8_t sta_list[30][6]; @@ -2437,17 +2424,20 @@ int agent_process_assoc_cntl_tlv(void *agent, memcpy(sta_list[m], p->client_assoc_ctrl_req_stas[m].addr, 6); fh = get_netif_by_bssid(a, p->bssid); - if (!fh) { + if (!fh) + { trace("[%s:%d] Error BSSID not present", __func__, __LINE__); return -1; } /*Here we first validate that the STA has been sent for * blocking */ - if (p->assoc_control == 0x00) { + if (p->assoc_control == 0x00) + { /*Check if the validity timer value is not zero*/ - if (p->validity_period == 0) { + if (p->validity_period == 0) + { trace("[%s:%d] Error validity period is invalid\n", __func__, __LINE__); return -1; } @@ -2457,17 +2447,21 @@ int agent_process_assoc_cntl_tlv(void *agent, * be associated with the bssid for which the blocking mode is * set */ - for (l = 0; l < p->sta_list_cnt; l++) { - list_for_each_entry(s, &fh->stalist, list) { + for (l = 0; l < p->sta_list_cnt; l++) + { + list_for_each_entry(s, &fh->stalist, list) + { trace("stalist :" MACFMT "\n", - MAC2STR(s->macaddr)); + MAC2STR(s->macaddr)); res = memcmp(s->macaddr, p->client_assoc_ctrl_req_stas[l].addr, 6); - if (res == 0) { + if (res == 0) + { found = 1; break; } } - if (found == 1) { + if (found == 1) + { dbg("STA client already associated with the bssid!\n"); memcpy(sta_resp[count].sta_mac, p->client_assoc_ctrl_req_stas[l].addr, 6); sta_resp[count].response = 0x01; @@ -2476,8 +2470,9 @@ int agent_process_assoc_cntl_tlv(void *agent, } /*Here we need the logic to block the STA*/ ret = agent_send_restrict_sta(agent, p->sta_list_cnt, - sta_list, fh, p->assoc_control); - if (ret != 0) { + sta_list, fh, p->assoc_control); + if (ret != 0) + { trace("[%s:%d] Error in agent_send_restrict_sta\n", __func__, __LINE__); return -1; } @@ -2485,29 +2480,36 @@ int agent_process_assoc_cntl_tlv(void *agent, * per the validity period also need to check if the sta is all * in the blocking list */ ret = agent_check_start_validity_tmr(p->validity_period, p->sta_list_cnt, sta_list, fh); - if (ret != 0) { + if (ret != 0) + { trace("[%s:%d] Error in start validity tmr\n", __func__, __LINE__); return -1; } - } else if (p->assoc_control == 0x01) { + } + else if (p->assoc_control == 0x01) + { /*Here we will ignore the validity timer value in the request * as the validity timer value is ignored in the unblock case */ /*Here we need to check if the validity timer is already running * in that case we need to stop the validity timer */ ret = agent_check_stop_validity_tmr(p->sta_list_cnt, sta_list, fh); - if (ret != 0) { + if (ret != 0) + { trace("[%s:%d] Error in stop validity tmr\n", __func__, __LINE__); return -1; } /*Here we need the logic to unblock the STA */ ret = agent_send_restrict_sta(agent, p->sta_list_cnt, - sta_list, fh, p->assoc_control); - if (ret != 0) { + sta_list, fh, p->assoc_control); + if (ret != 0) + { trace("[%s:%d] Error in agent_send_restrict_sta\n", __func__, __LINE__); return -1; } - } else { + } + else + { trace("[%s:%d] Reserved mode is called", __func__, __LINE__); } @@ -2517,17 +2519,17 @@ send_ack: } int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, - struct cmdu_cstruct *cmdu) + struct cmdu_cstruct *cmdu) { trace("agent: %s: --->\n", __func__); - struct agent *a = (struct agent *) agent; + struct agent *a = (struct agent *)agent; int ret = 0, result = 0; int l, m; struct netif_fh *fh; struct sta *s; - struct sta_error_response sta_resp[MAX_STA]; + struct sta_error_response sta_resp[MAX_STA]; uint32_t count = 0; - char wildcard_str[18] = { 0x0 }; + char wildcard_str[18] = {0x0}; uint8_t wildcard[6]; uint8_t wildcard_bssid[6]; uint32_t res = 0, present = 0; @@ -2536,11 +2538,13 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, hwaddr_aton(wildcard_str, wildcard); trace("request_mode: %d\n", - p->request_mode); + p->request_mode); - if (p->request_mode == 0x00) { + if (p->request_mode == 0x00) + { /* Here we start the steer opportunity timer */ - if (a->is_sta_steer_start == 1) { + if (a->is_sta_steer_start == 1) + { trace("Error steering opportunity timer already running\n"); return 1; } @@ -2549,7 +2553,8 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, * Here we need to check the three conditions that needs to be * satisfied according to section 11.2 */ - if (p->steer_opp_window == 0) { + if (p->steer_opp_window == 0) + { trace("Error steering opportunity timer value is zero\n"); return 1; } @@ -2562,8 +2567,9 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, a->is_sta_steer_start = 1; a->sta_steerlist_count = 0; uloop_timeout_set(&a->sta_steer_req_timer, p->steer_opp_window * 1000); - - } else if (p->request_mode != 0x01) { + } + else if (p->request_mode != 0x01) + { trace("Invalid request mode"); return 1; } @@ -2578,27 +2584,29 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, * Here we trace the values */ trace("btm_disassoc_imminent: %d\n", - p->btm_disassoc_imminent); + p->btm_disassoc_imminent); trace("btm_abridged: %d\n", - p->btm_abridged); + p->btm_abridged); trace("reserved: %d\n", - p->reserved); + p->reserved); trace("steer_opp_window: %d\n", - p->steer_opp_window); + p->steer_opp_window); trace("btm_disassoc_timer: %d\n", - p->btm_disassoc_timer); + p->btm_disassoc_timer); trace("sta_list_cnt: %d\n", - p->sta_list_cnt); + p->sta_list_cnt); trace("target_bssid_list_cnt: %d\n", - p->target_bssid_list_cnt); + p->target_bssid_list_cnt); trace("src_bssid: " MACFMT "\n", - MAC2STR(p->bssid)); + MAC2STR(p->bssid)); /* Here we validate if the sta is associated with the src bssid */ fh = get_netif_by_bssid(a, p->bssid); - if (!fh) { + if (!fh) + { trace("[%s:%d] Error BSSID not present", __func__, __LINE__); - for (l = 0; l < p->sta_list_cnt; l++) { + for (l = 0; l < p->sta_list_cnt; l++) + { memcpy(sta_resp[count].sta_mac, p->steering_req_macs[l].addr, 6); sta_resp[count].response = 0x02; count++; @@ -2611,67 +2619,77 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, goto send_ack; /* Number of STAs and BSSIDs are equal, map STA to BSSID */ - if (p->sta_list_cnt > 0 && p->sta_list_cnt == p->target_bssid_list_cnt) { - for (l = 0; l < p->sta_list_cnt; l++) { + if (p->sta_list_cnt > 0 && p->sta_list_cnt == p->target_bssid_list_cnt) + { + for (l = 0; l < p->sta_list_cnt; l++) + { trace("sta_addr: " MACFMT "\n", - MAC2STR(p->steering_req_macs[l].addr)); + MAC2STR(p->steering_req_macs[l].addr)); trace("target bssid: " MACFMT "\n", - MAC2STR(p->steering_req_target_bssids[l].bssid)); + MAC2STR(p->steering_req_target_bssids[l].bssid)); trace("op_class: %d\n", - p->steering_req_target_bssids[l].op_class); + p->steering_req_target_bssids[l].op_class); trace("channel: %d\n", - p->steering_req_target_bssids[l].channel); + p->steering_req_target_bssids[l].channel); /** * Here we need to check that the STA is associated with the * src bssid or not */ present = 0; trace("count of error code sta %d\n", count); - for (m = 0; m < count; m++) { + for (m = 0; m < count; m++) + { trace("steer mac: " MACFMT "\n", - MAC2STR(p->steering_req_macs[l].addr)); + MAC2STR(p->steering_req_macs[l].addr)); trace("sta error mac: " MACFMT "\n", - MAC2STR(sta_resp[m].sta_mac)); + MAC2STR(sta_resp[m].sta_mac)); res = memcmp(p->steering_req_macs[l].addr, - sta_resp[m].sta_mac, 6); - if (res == 0) { + sta_resp[m].sta_mac, 6); + if (res == 0) + { present = 1; break; } } - if (present != 1) { + if (present != 1) + { /*Here we call for transition of sta*/ ret = agent_transition_sta(a, p, fh, l, l); } } } /* Multiple STAs and single BSSID, send all STAs to same BSSID */ - else if (p->sta_list_cnt > 0 && p->target_bssid_list_cnt == 1) { + else if (p->sta_list_cnt > 0 && p->target_bssid_list_cnt == 1) + { trace("target bssid: " MACFMT "\n", - MAC2STR(p->steering_req_target_bssids[0].bssid)); + MAC2STR(p->steering_req_target_bssids[0].bssid)); trace("op_class: %d\n", - p->steering_req_target_bssids[0].op_class); + p->steering_req_target_bssids[0].op_class); trace("channel: %d\n", - p->steering_req_target_bssids[0].channel); + p->steering_req_target_bssids[0].channel); - for (l = 0; l < p->sta_list_cnt; l++) { + for (l = 0; l < p->sta_list_cnt; l++) + { /* Here we need to call the ubus method */ trace("sta_addr: " MACFMT "\n", - MAC2STR(p->steering_req_macs[l].addr)); + MAC2STR(p->steering_req_macs[l].addr)); /** * Here we need to check that the STA is associated with * the src bssid or not */ present = 0; - for (m = 0; m < count; m++) { - res = memcmp(p->steering_req_macs[l].addr, - sta_resp[m].sta_mac, 6); - if (res == 0) { + for (m = 0; m < count; m++) + { + res = memcmp(p->steering_req_macs[l].addr, + sta_resp[m].sta_mac, 6); + if (res == 0) + { present = 1; break; } } - if (present != 1) { + if (present != 1) + { /*Here we call for transition of sta*/ ret = agent_transition_sta(a, p, fh, l, 0); } @@ -2681,21 +2699,28 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, * No STA provided, Steering request applies to all associated STAs * in the BSS, per policy setting. */ - else if (p->sta_list_cnt == 0 && p->target_bssid_list_cnt == 1) { + else if (p->sta_list_cnt == 0 && p->target_bssid_list_cnt == 1) + { result = memcmp(p->steering_req_target_bssids[0].bssid, wildcard, 6); - if (result == 0) { + if (result == 0) + { trace("[%s:%d] bssid id wildcard", __func__, __LINE__); ret = agent_search_bssid_for_sta(a, - p->steering_req_macs[l].addr, wildcard_bssid, p->bssid); - if (ret != 0) { - list_for_each_entry(s, &fh->stalist, list) { + p->steering_req_macs[l].addr, wildcard_bssid, p->bssid); + if (ret != 0) + { + list_for_each_entry(s, &fh->stalist, list) + { ret = agent_send_request_transition( agent, s->macaddr, fh, wildcard_bssid, 0); } } - } else { - list_for_each_entry(s, &fh->stalist, list) { + } + else + { + list_for_each_entry(s, &fh->stalist, list) + { ret = agent_send_request_transition( agent, s->macaddr, fh, p->steering_req_target_bssids[0].bssid, 0); @@ -2703,36 +2728,42 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, } } /* No BSSID specified for the STAs */ - else if (p->sta_list_cnt > 0 && p->target_bssid_list_cnt == 0) { - if (p->request_mode != 0x00) { + else if (p->sta_list_cnt > 0 && p->target_bssid_list_cnt == 0) + { + if (p->request_mode != 0x00) + { trace("[%s:%d]Error steer mandate target BSSID not present\n", - __func__, __LINE__); + __func__, __LINE__); return 1; } trace("[%s:%d] target BSSID not present\n", __func__, __LINE__); - for (l = 0; l < p->sta_list_cnt; l++) { + for (l = 0; l < p->sta_list_cnt; l++) + { trace("sta_addr: " MACFMT "\n", - MAC2STR(p->steering_req_macs[l].addr)); + MAC2STR(p->steering_req_macs[l].addr)); /** * Here we need to check that the STA is associated with the * src bssid or not */ present = 0; - for (m = 0; m < count; m++) { - res = memcmp(p->steering_req_macs[l].addr, sta_resp[m].sta_mac, 6); - if (res == 0) { + for (m = 0; m < count; m++) + { + res = memcmp(p->steering_req_macs[l].addr, sta_resp[m].sta_mac, 6); + if (res == 0) + { present = 1; break; } } - if (present != 1) { + if (present != 1) + { /** * Here we need to get the bssids that are best * for the STAs in case of steering opportunity */ ret = agent_search_bssid_for_sta(a, - p->steering_req_macs[l].addr, - wildcard_bssid, p->bssid); + p->steering_req_macs[l].addr, + wildcard_bssid, p->bssid); if (ret != 0) ret = agent_send_request_transition( agent, p->steering_req_macs[l].addr, @@ -2741,10 +2772,13 @@ int agent_process_steer_request_tlv(void *agent, struct tlv_steer_Req *p, } } /* No BSSID or STAs */ - else if (p->sta_list_cnt == 0 && p->target_bssid_list_cnt == 0) { + else if (p->sta_list_cnt == 0 && p->target_bssid_list_cnt == 0) + { trace("[%s:%d] Error No STA and target BSSID present\n", __func__, __LINE__); return 1; - } else { + } + else + { trace("[%s:%d] Error condition\n", __func__, __LINE__); return 1; } @@ -2757,36 +2791,39 @@ send_ack: int handle_sta_steer_request(void *agent, struct cmdu_cstruct *cmdu) { trace("%s: --->\n", __func__); - struct agent *a = (struct agent *) agent; + struct agent *a = (struct agent *)agent; int ret = 0; int i; uint8_t *tlv = NULL; /* Here we first parse the steer request */ - if (cmdu->num_tlvs != 0) { - for (i = 0; i < cmdu->num_tlvs; i++) { - tlv = (uint8_t *) cmdu->tlvs[i]; - switch (*tlv) { + if (cmdu->num_tlvs != 0) + { + for (i = 0; i < cmdu->num_tlvs; i++) + { + tlv = (uint8_t *)cmdu->tlvs[i]; + switch (*tlv) + { case MAP_TLV_STEERING_REQUEST: - { - struct tlv_steer_Req *p = - (struct tlv_steer_Req *)tlv; + { + struct tlv_steer_Req *p = + (struct tlv_steer_Req *)tlv; - ret = agent_process_steer_request_tlv(agent, - p, cmdu); - break; - } -//#ifdef profile2 + ret = agent_process_steer_request_tlv(agent, + p, cmdu); + break; + } + //#ifdef profile2 case MAP_TLV_PROFILE2_STEERING_REQ: - { - //TODO here we need to call the request transmission for the - //STAs are Agile Multiband capable - struct tlv_profile2_steer_req *p = - (struct tlv_profile2_steer_req *)tlv; + { + //TODO here we need to call the request transmission for the + //STAs are Agile Multiband capable + struct tlv_profile2_steer_req *p = + (struct tlv_profile2_steer_req *)tlv; - break; - } -//#endif + break; + } + //#endif default: break; } @@ -2796,12 +2833,12 @@ int handle_sta_steer_request(void *agent, struct cmdu_cstruct *cmdu) } int agent_transition_sta(struct agent *a, struct tlv_steer_Req *p, struct netif_fh *fh, - int l, int m) + int l, int m) { uint8_t wildcard[6]; uint8_t wildcard_bssid[6]; int result = 0; - char wildcard_str[18] = { 0x0 }; + char wildcard_str[18] = {0x0}; int ret = 0; trace("agent: %s: --->\n", __func__); @@ -2809,24 +2846,27 @@ int agent_transition_sta(struct agent *a, struct tlv_steer_Req *p, struct netif_ hwaddr_aton(wildcard_str, wildcard); result = memcmp(p->steering_req_target_bssids[l].bssid, wildcard, 6); - if (result == 0) { + if (result == 0) + { /** * code to search bssid as the bssid is a * wildcard */ trace("[%s:%d] bssid id wildcard\n", - __func__, __LINE__); + __func__, __LINE__); ret = agent_search_bssid_for_sta(a, - p->steering_req_macs[l].addr, - wildcard_bssid, p->bssid); + p->steering_req_macs[l].addr, + wildcard_bssid, p->bssid); if (ret == 0) ret = agent_send_request_transition(a, - p->steering_req_macs[l].addr, - fh, wildcard_bssid, 0); - } else { + p->steering_req_macs[l].addr, + fh, wildcard_bssid, 0); + } + else + { ret = agent_send_request_transition(a, - p->steering_req_macs[l].addr, - fh, p->steering_req_target_bssids[m].bssid, 0); + p->steering_req_macs[l].addr, + fh, p->steering_req_target_bssids[m].bssid, 0); } return 0; } @@ -2834,24 +2874,27 @@ int agent_transition_sta(struct agent *a, struct tlv_steer_Req *p, struct netif_ int handle_sta_assoc_control_request(void *agent, struct cmdu_cstruct *cmdu) { trace("%s: --->\n", __func__); - struct agent *a = (struct agent *) agent; + struct agent *a = (struct agent *)agent; int ret = 0; int i; uint8_t *tlv = NULL; /* Here we first parse the steer request */ - if (cmdu->num_tlvs != 0) { - for (i = 0; i < cmdu->num_tlvs; i++) { - tlv = (uint8_t *) cmdu->tlvs[i]; - switch (*tlv) { + if (cmdu->num_tlvs != 0) + { + for (i = 0; i < cmdu->num_tlvs; i++) + { + tlv = (uint8_t *)cmdu->tlvs[i]; + switch (*tlv) + { case MAP_TLV_CLIENT_ASSOCIATION_CONTROL_REQUEST: - { - struct tlv_client_assoc_control_req *p = - (struct tlv_client_assoc_control_req *)tlv; + { + struct tlv_client_assoc_control_req *p = + (struct tlv_client_assoc_control_req *)tlv; - ret = agent_process_assoc_cntl_tlv(agent, - p, cmdu); - } + ret = agent_process_assoc_cntl_tlv(agent, + p, cmdu); + } default: break; } @@ -2867,17 +2910,17 @@ int handle_hld_message(void *agent, struct cmdu_cstruct *cmdu) } int handle_backhaul_sta_steer_request(void *agent, - struct cmdu_cstruct *rec_cmdu) + struct cmdu_cstruct *rec_cmdu) { trace("%s: --->\n", __func__); - struct agent *a = (struct agent *) agent; + struct agent *a = (struct agent *)agent; struct tlv_backhaul_steer_resp *p; struct tlv_backhaul_steer_req *req; struct cmdu_cstruct *cmdu; struct netif_bk *bk; - req = (struct tlv_backhaul_steer_req *) extract_tlv_by_type(rec_cmdu, - MAP_TLV_BACKHAUL_STEERING_REQUEST); + req = (struct tlv_backhaul_steer_req *)extract_tlv_by_type(rec_cmdu, + MAP_TLV_BACKHAUL_STEERING_REQUEST); if (!req) return -1; @@ -2886,8 +2929,9 @@ int handle_backhaul_sta_steer_request(void *agent, return -1; cmdu = (struct cmdu_cstruct *)calloc(1, - sizeof(struct cmdu_cstruct)); - if (!cmdu) { + sizeof(struct cmdu_cstruct)); + if (!cmdu) + { fprintf(stderr, "Out of memory!\n"); return -1; } @@ -2910,7 +2954,7 @@ int handle_backhaul_sta_steer_request(void *agent, if (!cmdu->tlvs) goto out_p; - cmdu->tlvs[0] = (uint8_t *) p; + cmdu->tlvs[0] = (uint8_t *)p; if (bk->bsta_steer.cmdu) map_free_cmdu(bk->bsta_steer.cmdu); @@ -2926,88 +2970,12 @@ out_cmdu: return -1; } -char *get_timestamp(time_t *t, char **tbuf) -{ - char tmpbuf[64] = {0}; - struct tm res; - char sign; - long toff, toff_hour, toff_min; - const time_t now = time(t); - - //if (!tbuf) - // return NULL; - - /* E.g. "2019-02-11T06:42:31.23039-08:00" */ - - localtime_r(&now, &res); - tzset(); - toff = timezone; - sign = toff > 0 ? '-' : '+'; - toff *= -1L; - - toff_hour = toff / 3600; - toff_min = (toff % 3600) / 60; - - snprintf(tmpbuf, 63, "%04d-%02d-%02dT%02d:%02d:%02d%c%02ld:%02ld", - res.tm_year + 1900, res.tm_mon, res.tm_mday, res.tm_hour, res.tm_min, res.tm_sec, sign, toff_hour, toff_min); - if (!*tbuf) { - *tbuf = calloc(1, strlen(tmpbuf) + 1); - if (!*tbuf) - return NULL; - } - - sprintf(*tbuf, "%s", tmpbuf); - return *tbuf; -} - -static void scan_results(struct agent *a, struct tlv_ch_scan_res *p, uint32_t radio_index, uint32_t opclass_index, uint32_t channel_index) -{ - struct wifi_radio_element *radio = a->radios + radio_index; - struct wifi_scanres_opclass_element *op = radio->scanlist[0].opclass_scanlist + opclass_index; - struct wifi_scanres_channel_element *ch = op->channel_scanlist + channel_index; - int i; - char bw_str[16] = {0}; - - memcpy(p->radio_id, radio->macaddr, 6); - p->op_class = op->opclass; - p->ch = ch->channel; - p->scan_res = CH_SCAN_STATUS_SUCCESS; - if (p->scan_res == CH_SCAN_STATUS_SUCCESS) { - get_timestamp(NULL, &p->timestamp); - p->time_len = strlen(p->timestamp); - p->utilization = ch->utilization; - p->noise = ch->anpi; - p->nbr_neighbors = ch->num_neighbors; - p->neighbor_data = calloc(p->nbr_neighbors, sizeof(*(p->neighbor_data))); - if (p->neighbor_data) { - for (i = 0; i < p->nbr_neighbors; i++) { - struct wifi_scanres_neighbor_element *nbr = ch->nbrlist + i; - - memcpy(p->neighbor_data[i].bssid, nbr->bssid, 6); - p->neighbor_data[i].ssid = strdup(nbr->ssid); - p->neighbor_data[i].ssid_len = strlen(p->neighbor_data[i].ssid); - p->neighbor_data[i].signal_strength = nbr->rssi; - p->neighbor_data[i].bss_load_elm_present = 1; - - snprintf(bw_str, 15, "%d", nbr->bw); - p->neighbor_data[i].ch_bandwidth = strdup(bw_str); - p->neighbor_data[i].ch_band_len = strlen(p->neighbor_data[i].ch_bandwidth); - - if (p->neighbor_data[i].bss_load_elm_present == 1) { - p->neighbor_data[i].ch_util = nbr->utilization; - p->neighbor_data[i].sta_count = nbr->num_stations; - } - } - } - } -} - int handle_channel_scan_request(void *agent, struct cmdu_cstruct *cmdu) { trace("%s: --->\n", __func__); struct agent *a = (struct agent *) agent; uint16_t tlv_index = 0; - uint32_t i, j, k; + uint32_t i, j, k, m; int radio_index; int opclass_index; @@ -3035,8 +3003,10 @@ int handle_channel_scan_request(void *agent, struct cmdu_cstruct *cmdu) cmdu_data->message_id = cmdu->message_id; strcpy(cmdu_data->intf_name, cmdu->intf_name); memcpy(cmdu_data->origin, cmdu->origin, 6); - cmdu_data->num_tlvs = 1 + query->radio_data->op_class_data->nbr_ch; - + cmdu_data->num_tlvs = 1; // timestamp tlv + for (m = 0; m < query->nbr_radios; m++) { // for each radio + cmdu_data->num_tlvs += query->radio_data[m].op_class_data->nbr_ch; // ch scan res tlvs + } // Allocate the TLVs cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, sizeof(uint8_t *)); if (!cmdu_data->tlvs) { @@ -3057,31 +3027,40 @@ int handle_channel_scan_request(void *agent, struct cmdu_cstruct *cmdu) /* Channel scan result */ struct wifi_radio_element *radio = a->radios; - /* Assuming one radio */ - radio_index = wifi_get_radio_index_by_mac(a, query->radio_data->radio_id); - // Go through the channel list from the query - for (int k = 0; k < query->radio_data->op_class_data->nbr_ch; k++) { - uint8_t query_channel = query->radio_data->op_class_data->ch[k]; - - for (int i = 0; i < radio->scanlist->num_opclass_scanned; i++) { - for (int j = 0; j < radio->scanlist->opclass_scanlist[i].num_channels_scanned; j++) { - if (radio->scanlist->opclass_scanlist[i].channel_scanlist[j].channel == query_channel) { - opclass_index = i; - channel_index = j; - struct tlv_ch_scan_res *p1 = (struct tlv_ch_scan_res *)calloc(1, sizeof(struct tlv_ch_scan_res)); - - if (p1) { - p1->tlv_type = MAP_TLV_CHANNEL_SCAN_RES; - scan_results(a, p1, radio_index, opclass_index, channel_index); - cmdu_data->tlvs[tlv_index++] = (uint8_t *)p1; - trace("|%s:%d| Added %s for channel %d\n", __func__, __LINE__, map_stringify_tlv_type(*cmdu_data->tlvs[tlv_index-1]), query_channel); - goto found; + /* Multi radio */ + for (m = 0; m < query->nbr_radios; m++) { + //fprintf(stdout, "\tNumber of radios = %d", query->nbr_radios); + //fprintf(stdout, "\tradio_id in %d(m) iteration: " MACFMT "\n", m, MAC2STR(query->radio_data[m].radio_id)); + radio_index = wifi_get_radio_index_by_mac(a, query->radio_data[m].radio_id); + //fprintf(stdout, "\n\t\tRADIO INDEX: %d for " MACFMT "\n\n", radio_index, MAC2STR(query->radio_data[m].radio_id)); + // Go through the channel list from the query + for (k = 0; k < query->radio_data[m].op_class_data->nbr_ch; k++) { + uint8_t query_channel = query->radio_data[m].op_class_data->ch[k]; + //fprintf(stdout,"query channel %d\n", query_channel); + + for (i = 0; i < radio[radio_index].scanlist->num_opclass_scanned; i++) { + //fprintf(stdout, "In the device list we are looking at radio " MACFMT " in %d(m) iteration\n", MAC2STR(radio[radio_index].macaddr), m); + for (j = 0; j < radio[radio_index].scanlist->opclass_scanlist[i].num_channels_scanned; j++) { + //fprintf(stdout,"current channel %d\n", radio[radio_index].scanlist->opclass_scanlist[i].channel_scanlist[j].channel); + if (radio[radio_index].scanlist->opclass_scanlist[i].channel_scanlist[j].channel == query_channel) { + //fprintf(stdout,"GO!\n"); + opclass_index = i; + channel_index = j; + struct tlv_ch_scan_res *p1 = (struct tlv_ch_scan_res *)calloc(1, sizeof(struct tlv_ch_scan_res)); + + if (p1) { + p1->tlv_type = MAP_TLV_CHANNEL_SCAN_RES; + scan_results(a, p1, radio_index, opclass_index, channel_index); + cmdu_data->tlvs[tlv_index++] = (uint8_t *)p1; + trace("|%s:%d| Added %s for channel %d, tlv_index %d\n", __func__, __LINE__, map_stringify_tlv_type(*cmdu_data->tlvs[tlv_index-1]), query_channel, tlv_index-1); + goto found; + } } } } - } found: - continue; + continue; + } } // Send cmdu ret = agent_send_cmdu(a, cmdu_data); @@ -3107,85 +3086,25 @@ int handle_error_response(void *agent, struct cmdu_cstruct *cmdu) return 0; } -int prepare_tunneled_message(void *agent, - uint8_t protocol, const char *framestr) -{ - trace("%s: --->\n", __func__); - struct agent *a = (struct agent *)agent; - struct cmdu_cstruct *cmdu; - uint8_t *frame; - uint8_t sta_mac[6] = { 0 }; - int len; - int index; - - if (!framestr) - return -1; - - /* TODO/FIXME: add other protocol - * checking (BTM/WNM/ANQP) - * as of now checking assoc/reassoc - * type only. - */ - if ((protocol != 0x00) && (protocol != 0x01)) - return -1; - - len = strlen(framestr); - len = (len - 1) / 2; - frame = calloc(len, sizeof(uint8_t)); - if (!frame) - return -1; - - if (!strtob((char *)framestr, len, frame)) - goto error; - - index = 2 + 2 + 6; /* sta mac index */ - memcpy(sta_mac, frame + index, 6); - - cmdu = agent_gen_tunneled_msg(a, protocol, sta_mac, - len, frame); - if (!cmdu) - goto error; - - agent_send_cmdu(a, cmdu); - map_free_cmdu(cmdu); - free(frame); - - return 0; - -error: - free(frame); - - return -1; -} - int handle_backhaul_sta_caps_query(void *agent, struct cmdu_cstruct *cmdu) { trace("%s: --->\n", __func__); return 0; } -int handle_backhaul_sta_caps_report(void *agent, struct cmdu_cstruct *cmdu) -{ - trace("%s: --->\n", __func__); - return 0; -} - - /* Cmdu handlers commented out in the following two tables should be * handled in the controller. * Agent must implement the send cmdu functions corresponding to the * same. */ -#define CMDU_TYPE_1905_START 0x0000 +#define CMDU_TYPE_1905_START 0x0001 #define CMDU_TYPE_1905_END 0x000a static const map_cmdu_handler_t i1905ftable[] = { - [0x00] = handle_topology_discovery, [0x01] = handle_topology_notification, [0x02] = handle_topology_query, [0x03] = handle_topology_response, - [0x04] = handle_vendor_specific, /* hole */ /* [0x07] = handle_ap_autoconfig_search, */ [0x08] = handle_ap_autoconfig_response, @@ -3195,7 +3114,7 @@ static const map_cmdu_handler_t i1905ftable[] = { #define CMDU_TYPE_MAP_START 0x8000 -#define CMDU_TYPE_MAP_END 0x8027 +#define CMDU_TYPE_MAP_END 0x8033 static const map_cmdu_handler_t agent_mapftable[] = { [0x00] = handle_1905_ack, @@ -3236,7 +3155,7 @@ static const map_cmdu_handler_t agent_mapftable[] = { /* [0x25] = handle_assoc_status_notification, */ /* [0x26] = handle_tunneled_message, */ [0x27] = handle_backhaul_sta_caps_query, - [0x28] = handle_backhaul_sta_caps_report, + /* [0x28] = handle_backhaul_sta_caps_report, */ /* hole */ /* [0x33] = handle_failed_connection_msg, */ }; @@ -3325,10 +3244,13 @@ bool is_cmdu_for_us(struct agent *a, uint16_t type) /* until then, the following should be okay.. */ - if (type >= CMDU_TYPE_1905_START && type <= CMDU_TYPE_1905_END) { + if (type >= CMDU_TYPE_1905_START && type <= CMDU_TYPE_1905_END) + { if (i1905ftable[type]) return true; - } else if (type >= CMDU_TYPE_MAP_START && type <= CMDU_TYPE_MAP_END) { + } + else if (type >= CMDU_TYPE_MAP_START && type <= CMDU_TYPE_MAP_END) + { if (agent_mapftable[type - CMDU_TYPE_MAP_START]) return true; } @@ -3352,14 +3274,15 @@ int agent_handle_map_cmd(struct agent *a, char *data, int len) } static void send_cmdu_cb(struct ubus_request *req, - int type, struct blob_attr *msg) + int type, struct blob_attr *msg) { struct json_object *jobj = NULL; struct json_object *tmp; uint16_t *mid; char *str; - if (!msg || !req->priv) { + if (!msg || !req->priv) + { fprintf(stderr, "%s:Message recieved is NULL\n", __func__); return; } @@ -3367,7 +3290,8 @@ static void send_cmdu_cb(struct ubus_request *req, mid = (uint16_t *)req->priv; str = (char *)blobmsg_format_json_indent(msg, true, -1); - if (str) { + if (str) + { jobj = json_tokener_parse(str); free(str); } @@ -3375,22 +3299,23 @@ static void send_cmdu_cb(struct ubus_request *req, if (jobj == NULL) return; - if (json_object_object_get_ex(jobj, "mid", &tmp)) { + if (json_object_object_get_ex(jobj, "mid", &tmp)) + { *mid = json_object_get_int(tmp); - fprintf(stdout, "%s:%d agent map-mid:%d\n", __func__, __LINE__, *mid); + fprintf(stdout, "%s:%d map-mid:%d\n", __func__, __LINE__, *mid); } json_object_put(jobj); } -uint16_t agent_send_cmdu(struct agent *a, struct cmdu_cstruct *cmdu) +int agent_send_cmdu(struct agent *a, struct cmdu_cstruct *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 }; + struct blob_buf b = {0}; + char dst_addr[18] = {0}; char *tlv_str = NULL; uint8_t *ss = NULL; uint16_t msgid = 0; @@ -3398,6 +3323,8 @@ uint16_t agent_send_cmdu(struct agent *a, struct cmdu_cstruct *cmdu) int ret = 0; size_t i; uint32_t id; + //uint8_t is_store_mid = 1; + //struct ieee1905_cmdu_msg *cmsg = NULL; trace("|%s:%d| Entry\n", __func__, __LINE__); @@ -3413,16 +3340,20 @@ uint16_t agent_send_cmdu(struct agent *a, struct cmdu_cstruct *cmdu) blobmsg_add_string(&b, "dst_macaddr", dst_addr); trace("|%s:%d|cmdu:%s|egress:%s|dst:%s|\n", __func__, __LINE__, - map_stringify_cmdu_type(cmdu->message_type), - cmdu->intf_name, dst_addr); - if (cmdu->num_tlvs > 0) { - for (i = 0; i < cmdu->num_tlvs; i++) { + map_stringify_cmdu_type(cmdu->message_type), + cmdu->intf_name, dst_addr); + if (cmdu->num_tlvs > 0) + { + for (i = 0; i < cmdu->num_tlvs; i++) + { len = 0; ss = map_put_tlv_cstruct(cmdu->tlvs[i], &len); - if (ss) { + if (ss) + { tlv_str = (char *)calloc((2 * len) + 1, - sizeof(char)); - if (!tlv_str) { + sizeof(char)); + if (!tlv_str) + { free(ss); goto out; } @@ -3431,8 +3362,9 @@ uint16_t agent_send_cmdu(struct agent *a, struct cmdu_cstruct *cmdu) tlv_str_len = 2 * len; tlv_data_len += tlv_str_len; tlv_data = realloc(tlv_data, - tlv_data_len * sizeof(char)); - if (!tlv_data) { + tlv_data_len * sizeof(char)); + if (!tlv_data) + { fprintf(stderr, "%s:%d out of memory.!\n", __func__, __LINE__); free(ss); @@ -3442,7 +3374,7 @@ uint16_t agent_send_cmdu(struct agent *a, struct cmdu_cstruct *cmdu) copy_index = tlv_data_len - tlv_str_len - 1; memcpy(tlv_data + copy_index, tlv_str, - tlv_str_len); + tlv_str_len); free(ss); free(tlv_str); } @@ -3454,22 +3386,36 @@ uint16_t agent_send_cmdu(struct agent *a, struct cmdu_cstruct *cmdu) free(tlv_data); } - if (ubus_lookup_id(a->ubus_ctx, "map.1905", &id)) { + if (ubus_lookup_id(a->ubus_ctx, "map.1905", &id)) + { trace("[%s:%d] not present", __func__, __LINE__); goto out; } - + fprintf(stderr, " %s -", __func__); test_cmdu(cmdu); ret = ubus_invoke(a->ubus_ctx, id, "send", - b.head, send_cmdu_cb, - (void *)&msgid, - UBUS_TIMEOUT); - if (ret) { + b.head, send_cmdu_cb, + (void *)&msgid, + UBUS_TIMEOUT); + if (ret) + { trace("[%s:%d] ubus call failed for |map.1905 send|", - __func__, __LINE__); + __func__, __LINE__); goto out; } - ret = msgid; + //TODO: improve ///////////////////////// + //if (is_store_mid) { + // cmsg = &priv->cmsg; + // for (i = 0; i < MAX_CMDU_MSG; i++) { + // if (cmsg->msg_id[i] == -1) { + // cmsg->msg_id[i] = msgid; + // cmsg->msg_ts[i] = time(NULL); + // break; + // } + // } + //} + ///////////////////////////////////////// + out: blob_buf_free(&b); @@ -3477,7 +3423,7 @@ out: } int agent_handle_map_event(struct agent *a, uint16_t cmdutype, uint16_t mid, - char *rxif, uint8_t *src, uint8_t *tlvs, int len) + char *rxif, uint8_t *src, uint8_t *tlvs, int len) { const map_cmdu_handler_t *f; struct cmdu_cstruct *cmdu = NULL; @@ -3486,21 +3432,27 @@ int agent_handle_map_event(struct agent *a, uint16_t cmdutype, uint16_t mid, trace("%s: ---> cmdu = %d\n", __func__, cmdutype); - if (cmdutype >= CMDU_TYPE_MAP_START) { + if (cmdutype >= CMDU_TYPE_MAP_START) + { idx = cmdutype - CMDU_TYPE_MAP_START; f = agent_mapftable; - } else { + } + else + { idx = cmdutype; f = i1905ftable; } - if (f[idx]) { + if (f[idx]) + { cmdu = map_build_cmdu(cmdutype, mid, rxif, src, tlvs); if (cmdu) { - test_cmdu(cmdu); + fprintf(stderr, " %s -", __func__); test_cmdu(cmdu); ret = f[idx](a, cmdu); map_free_cmdu(cmdu); - } else { + } + else + { dbg("agent: %s: map_build_cmdu() failed!\n", __func__); } } diff --git a/src/utils/debug.c b/src/utils/debug.c index 061df0a5785187ce36f6c08849b1318874349ebc..fc51f5ef2678226e059561fab73a636ec528e856 100644 --- a/src/utils/debug.c +++ b/src/utils/debug.c @@ -33,16 +33,19 @@ extern const char *PROG_NAME; extern int verbose; extern bool syslogging; extern bool usefifo; -static const int syslog_level[] = { LOG_ERR, LOG_WARNING, LOG_INFO, LOG_DEBUG }; +static const int syslog_level[] = {LOG_ERR, LOG_WARNING, LOG_INFO, LOG_DEBUG}; void start_logging(void) { if (syslogging) openlog(PROG_NAME, 0, LOG_DAEMON); - if (!outfile) { - if (outfile_path) { - if (usefifo) { + if (!outfile) + { + if (outfile_path) + { + if (usefifo) + { struct stat st; int rfd; @@ -51,19 +54,24 @@ void start_logging(void) mkfifo(outfile_path, 0600); if (stat(outfile_path, &st) == -1 || - !S_ISFIFO(st.st_mode)) + !S_ISFIFO(st.st_mode)) return; rfd = open(outfile_path, - O_RDONLY | O_NONBLOCK); - if (rfd) { + O_RDONLY | O_NONBLOCK); + if (rfd) + { ffd = open(outfile_path, - O_WRONLY | O_NONBLOCK); + O_WRONLY | O_NONBLOCK); close(rfd); } - } else { + } + else + { outfile = fopen(outfile_path, "w+"); } - } else { + } + else + { outfile = stderr; } } @@ -77,7 +85,8 @@ void stop_logging(void) if (outfile) fclose(outfile); - if (ffd) { + if (ffd) + { close(ffd); unlink(outfile_path); } @@ -87,20 +96,22 @@ void log_message(int level, const char *fmt, ...) { va_list args; - if (level > verbose) { - if (usefifo && ffd) { + if (level > verbose) + { + if (usefifo && ffd) + { time_t now = time(NULL); struct tm *tm_now = localtime(&now); const char *tm_fmt = "[%d-%02d-%02d %02d:%02d:%02d] "; va_start(args, fmt); dprintf(ffd, tm_fmt, - tm_now->tm_year + 1900, - tm_now->tm_mon + 1, - tm_now->tm_mday, - tm_now->tm_hour, - tm_now->tm_min, - tm_now->tm_sec); + tm_now->tm_year + 1900, + tm_now->tm_mon + 1, + tm_now->tm_mday, + tm_now->tm_hour, + tm_now->tm_min, + tm_now->tm_sec); vdprintf(ffd, fmt, args); va_end(args); } @@ -127,7 +138,8 @@ void dump(unsigned char *buf, int len, char *label) if (label) printf("---- %s ----", label); - for (i = 0; i < len; i++) { + for (i = 0; i < len; i++) + { if (!(i % 4)) printf(" "); if (!(i % 16)) @@ -142,9 +154,12 @@ 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) { + if (!testfile) + { + if (testfile_path) + { + if (usefifo) + { struct stat st; int rfd; @@ -153,20 +168,25 @@ void start_test_logging(void) mkfifo(testfile_path, 0600); if (stat(testfile_path, &st) == -1 || - !S_ISFIFO(st.st_mode)) + !S_ISFIFO(st.st_mode)) return; rfd = open(testfile_path, - O_RDONLY | O_NONBLOCK); - if (rfd) { + O_RDONLY | O_NONBLOCK); + if (rfd) + { tfd = open(testfile_path, - O_WRONLY | O_NONBLOCK); + O_WRONLY | O_NONBLOCK); close(rfd); } - } else { + } + else + { testfile = fopen(testfile_path, "w+"); } - } else { + } + else + { testfile = stderr; } } @@ -177,7 +197,8 @@ void stop_test_logging(void) if (testfile) fclose(testfile); - if (tfd) { + if (tfd) + { close(tfd); unlink(testfile_path); } @@ -201,23 +222,63 @@ void log_test(int level, void *var, int len) free(bstr); } -void log_cmdu(int level, void *var) +void _log_cmdu(int level, void *var, bool flag) { - struct cmdu_cstruct *cmdu = (struct cmdu_cstruct *) var; + struct cmdu_cstruct *cmdu = (struct cmdu_cstruct *)var; + struct json_object *msgversion, *msgtype, *msgid, *msg; + struct json_object *intfname, *tlvarray, *direction; + struct json_object *main_object; + char *bstr; int i; + main_object = json_object_new_object(); + + tlvarray = json_object_new_array(); if (level > verbose) return; - for (i = 0; i < cmdu->num_tlvs; i++) { + for (i = 0; i < cmdu->num_tlvs; i++) + { uint16_t len; uint8_t *btlv; + struct json_object *tlv; + struct json_object *tlv_type; + struct json_object *tlv_object; + tlv_object = json_object_new_object(); + uint8_t *type; btlv = map_put_tlv_cstruct(cmdu->tlvs[i], &len); + type = cmdu->tlvs[i]; if (!btlv) continue; - - log_test(level, btlv, len); + bstr = calloc(1, (len * 2) + 1); + if (!bstr) + return; + btostr(btlv, len, bstr); + tlv = json_object_new_string(bstr); + tlv_type = json_object_new_string(map_stringify_tlv_type(*type)); + json_object_object_add(tlv_object, "DATA", tlv); + json_object_object_add(tlv_object, "TYPE", tlv_type); + json_object_array_add(tlvarray, tlv_object); free(btlv); + free(bstr); } -} + msgversion = json_object_new_int(cmdu->message_version); + msgtype = json_object_new_int(cmdu->message_type); + direction = json_object_new_boolean(flag); + msgid = json_object_new_int(cmdu->message_id); + intfname = json_object_new_string(cmdu->intf_name); + msg = json_object_new_string(map_stringify_cmdu_type(cmdu->message_type)); + + json_object_object_add(main_object, "MESSAGE VERSION", msgversion); + json_object_object_add(main_object, "MESSAGE TYPE", msgtype); + json_object_object_add(main_object, "MESSAGE ID", msgid); + json_object_object_add(main_object, "INTERFACE NAME", intfname); + json_object_object_add(main_object, "MESSAGE", msg); + json_object_object_add(main_object, "DIRECTION", direction); + json_object_object_add(main_object, "TLVS", tlvarray); + + fprintf(testfile, "%s\n", json_object_to_json_string(main_object)); + + fflush(testfile); +} \ No newline at end of file diff --git a/src/utils/debug.h b/src/utils/debug.h index 51f757876d2e84ccac37a1e2d9671beec824e01c..62f19c0520b7b3e9a7edf0267385141dc3d71c43 100644 --- a/src/utils/debug.h +++ b/src/utils/debug.h @@ -18,7 +18,7 @@ void start_test_logging(void); void stop_test_logging(void); void log_message(int level, const char *fmt, ...); void log_test(int level, void *var, int len); -void log_cmdu(int level, void *var); +void _log_cmdu(int level, void *var, bool flag); #define DEBUG_COLOR 1 @@ -45,7 +45,7 @@ void log_cmdu(int level, void *var); #define loud(fmt, ...) log_message(5, fmt, ## __VA_ARGS__) //#define test(fmt, ...) log_test(6, fmt, ## __VA_ARGS__) #define test(var, len) log_test(6, var, len) -#define test_cmdu(var) log_cmdu(6, var) +#define log_cmdu(var, flag) _log_cmdu(6, var, flag) #else #define logrec(...) log_message(-1, __VA_ARGS__)