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.c b/src/core/agent.c index f9bc7ea43aaa72ca3b7a4911a9260f488c655275..f2ef12228db57a73d514e941949ca1629db2e9ec 100644 --- a/src/core/agent.c +++ b/src/core/agent.c @@ -2972,11 +2972,14 @@ static void parse_radio(struct ubus_request *req, int type, re->current_txpower_percent = (uint8_t) blobmsg_get_u32(tb[9]); if (tb[10]) { + // TODO: uncomment when radio mac is fixed in wifimngr test suite char macaddr[18] = {0}; - strncpy(macaddr, blobmsg_data(tb[10]), 17); - if (!hwaddr_aton(macaddr, re->macaddr)) - return; + re->macaddr[5] = atoi(re->name+4); + + //strncpy(macaddr, blobmsg_data(tb[10]), 17); + //if (!hwaddr_aton(macaddr, re->macaddr)) + // return; } } diff --git a/src/core/agent_map.c b/src/core/agent_map.c index 1b13dc9e5b5c9fe9bf3ceb3371d94ba7a5e7c41c..4086fbef70b939bcaeb57c0b0aa8a6f1408ac115 100644 --- a/src/core/agent_map.c +++ b/src/core/agent_map.c @@ -56,56 +56,58 @@ #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_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; } return NULL; - } /* lookup netif struct by bssid */ @@ -113,9 +115,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 +127,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; @@ -139,7 +142,8 @@ int build_ap_autoconfig_wsc(void *agent, struct cmdu_cstruct *rec_cmdu, // 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; } @@ -183,13 +187,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; @@ -243,16 +247,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; } @@ -264,16 +269,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; @@ -288,13 +295,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; } @@ -305,7 +313,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 @@ -324,20 +333,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; } @@ -349,18 +359,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; } @@ -371,18 +383,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); @@ -394,14 +408,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); } @@ -426,7 +443,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; } @@ -641,14 +658,17 @@ int handle_ap_autoconfig_response(void *agent, struct cmdu_cstruct *cmdu) 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; } @@ -698,12 +718,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)) @@ -720,7 +741,8 @@ 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; } @@ -761,7 +783,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; @@ -778,7 +801,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; @@ -793,17 +817,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; @@ -815,12 +839,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"))) @@ -828,7 +854,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; @@ -837,16 +864,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; } @@ -873,7 +903,8 @@ 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; @@ -890,7 +921,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; @@ -899,8 +930,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; @@ -922,47 +953,52 @@ int handle_ap_autoconfig_wsc(void *agent, struct cmdu_cstruct *cmdu) 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", @@ -986,7 +1022,7 @@ int handle_ap_autoconfig_wsc(void *agent, struct cmdu_cstruct *cmdu) " for bssid" MACFMT "\n", MAC2STR(bssid)); wifi_teardown_map_ifaces_by_radio(a, - radio->name); + radio->name); goto teardown; } @@ -1020,11 +1056,12 @@ teardown: 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 +1072,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 +1085,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 +1095,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 +1117,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 +1137,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,12 +1169,12 @@ 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; } - p1 = calloc(1, sizeof(*p1)); if (!p1) goto error; @@ -1138,55 +1182,61 @@ 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++; } - } cmdu->tlvs[tlv_index] = (uint8_t *)p1; @@ -1198,7 +1248,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; @@ -1228,7 +1278,6 @@ static int prepare_assoc_sta_metric_response(void *agent, char *ifname) map_free_cmdu(cmdu); return 0; - } int handle_1905_ack(void *agent, struct cmdu_cstruct *cmdu) @@ -1240,7 +1289,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 +1301,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,18 +1315,20 @@ 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]); @@ -1295,7 +1347,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); @@ -1303,12 +1356,12 @@ int handle_ap_caps_query(void *agent, struct cmdu_cstruct *rec_cmdu) continue; //cmdu->num_tlvs++; - cmdu->tlvs[tlv_index++] = (uint8_t *)p3; } /* 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 +1371,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 +1399,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 +1446,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 +1478,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 +1493,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 +1513,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 +1521,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 +1540,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 +1602,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 +1696,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 +1717,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 +1739,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 +1767,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 +1787,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 +1812,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 +1845,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 +1909,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 +1923,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 +1963,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 +1976,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 +2059,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 +2083,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 +2100,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; } @@ -2099,14 +2187,14 @@ int handle_sta_link_metrics_query(void *agent, struct cmdu_cstruct *rec_cmdu) } 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 +2231,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 +2275,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 +2298,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 +2320,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 +2343,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 +2354,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 +2369,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 +2397,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 +2416,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 +2446,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 +2457,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 +2468,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 +2484,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 +2499,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 +2508,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 +2529,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 +2548,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 +2571,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 +2594,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 +2604,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 +2643,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 +2662,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 +2677,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 +2691,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 +2708,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 +2743,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 +2823,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 +2852,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 +2896,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 +2915,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 +2957,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 +2970,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 +2998,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 +3034,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 +3053,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 +3078,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); @@ -3329,7 +3497,6 @@ static const map_cmdu_handler_t agent_mapftable[] = { /* [0x33] = handle_failed_connection_msg, */ }; - const char *tlv_friendlyname[] = { "supported_service", "searched_service", @@ -3399,7 +3566,6 @@ const char *tlv_friendlyname[] = { "backhaul_bss_config", }; - bool is_cmdu_for_us(struct agent *a, uint16_t type) { // TODO: handle only cmdu types relevant for module's role/profile. @@ -3413,10 +3579,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; } @@ -3440,14 +3609,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; } @@ -3455,7 +3625,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); } @@ -3463,7 +3634,8 @@ 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); } @@ -3477,8 +3649,8 @@ uint16_t agent_send_cmdu(struct agent *a, struct cmdu_cstruct *cmdu) 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; @@ -3501,16 +3673,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; } @@ -3519,8 +3695,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); @@ -3530,7 +3707,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); } @@ -3543,18 +3720,20 @@ uint16_t agent_send_cmdu(struct agent *a, struct cmdu_cstruct *cmdu) } } - 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; } - + log_cmdu(cmdu, false); 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; } @@ -3566,7 +3745,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; @@ -3575,21 +3754,28 @@ 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); + if (cmdu) + { + log_cmdu(cmdu, true); 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..30c616ec47afa9f0c3e55f1b2ade91b5deaa44de 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,65 @@ 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); + + json_object_put(main_object); +} \ 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__)