diff --git a/src/core/allsta.h b/src/core/allsta.h index 7e3aab01ef8d946ddbd4f4980f9f0a31ebd61aaa..054121afd45737861bee512ab04beb1b3b0f9fbc 100644 --- a/src/core/allsta.h +++ b/src/core/allsta.h @@ -22,8 +22,10 @@ struct active_sta { }; void as_init_table(struct hlist_head **as_table); -struct active_sta *as_lookup_first_idx(struct hlist_head *h, unsigned char *hwaddr); -int as_clean_entry(struct hlist_head *h, unsigned char *hwaddr, unsigned char *bssid); +struct active_sta *as_lookup_first_idx(struct hlist_head *h, + unsigned char *hwaddr); +int as_clean_entry(struct hlist_head *h, unsigned char *hwaddr, + unsigned char *bssid); struct active_sta *as_lookup(struct hlist_head *h, unsigned char *hwaddr); struct active_sta *as_insert(struct hlist_head *h, unsigned char *hwaddr, unsigned char *bssid); diff --git a/src/core/cntlr.c b/src/core/cntlr.c index a8eb71f38b66b5261537a9a40f0d0fef3c165a5a..73a32fa39db245834591dfa57daed78fb5d8261b 100644 --- a/src/core/cntlr.c +++ b/src/core/cntlr.c @@ -45,7 +45,8 @@ static void node_getbssinfo(void *cntlr, void *resp, int len, void *cookie); static int enumerate_topology_indirect(struct controller *c); /* find node by macaddress */ -static struct node *find_node_by_mac(struct controller *c, const unsigned char *mac) +static struct node *find_node_by_mac(struct controller *c, + const unsigned char *mac) { struct node *p; @@ -130,7 +131,7 @@ static int forall_node_update_neighbors(struct controller *c) btostr((unsigned char *)nbrmac, sizeof(nbrmac), nbrstr); cntlr_dbg("Sending DEL_NEIGHBOR Async to node (%p:%p)---->\n", - n, n->uobj[4]); + n, n->uobj[4]); CMD(c->comm, c, (void *)(uintptr_t)n->uobj[4], CMD_DEL_NEIGHBOR, nbrstr, sizeof(nbrstr), @@ -157,8 +158,9 @@ static int forall_node_update_neighbors(struct controller *c) nbr.phy = fh->phy; btostr((unsigned char *)&nbr, sizeof(nbr), nbrstr); - cntlr_dbg("Sending ADD_NEIGHBOR to node (%p:%p)---->\n", - n, n->uobj[4]); + cntlr_dbg("Sending ADD_NEIGHBOR to node " \ + " (%p:%p)---->\n", + n, n->uobj[4]); CMD(c->comm, c, (void *)n->uobj[4], CMD_ADD_NEIGHBOR, &nbrstr, 2 * sizeof(nbr) + 1, @@ -252,7 +254,8 @@ static void node_get_monitor_sta(void *cntlr, void *resp, int len, void *cookie) if (!entry) return; - cntlr_dbg("STA " MACFMT " old best nbr-rssi = %d nbr-rssi = %d seen = %d secs ago\n", + cntlr_dbg("STA " MACFMT " old best nbr-rssi = %d nbr-rssi = %d " \ + "seen = %d secs ago\n", MAC2STR(entry->hwaddr), entry->best_nbr_rssi, nbr_rssi, info->seen); @@ -261,7 +264,8 @@ static void node_get_monitor_sta(void *cntlr, void *resp, int len, void *cookie) entry->best_nbr_rssi = nbr_rssi; memcpy(entry->best_nbr, info->bss, 6); - cntlr_dbg("STA " MACFMT " better neighbor is " MACFMT " with rssi %d\n", + cntlr_dbg("STA " MACFMT " better neighbor is " MACFMT \ + " with rssi %d\n", MAC2STR(info->addr), MAC2STR(entry->best_nbr), entry->best_nbr_rssi); @@ -421,7 +425,8 @@ static void forall_node_get_assoclist(struct controller *c) if (list_empty(&n->fronthaul_iflist)) continue; - p = list_first_entry(&n->fronthaul_iflist, struct netif_fhbss, list); + p = list_first_entry(&n->fronthaul_iflist, + struct netif_fhbss, list); if (!p) continue; @@ -440,7 +445,8 @@ static void forall_node_get_assoclist(struct controller *c) } } -int invoke_disconnect_sta(struct node *n, struct netif_fhbss *p, unsigned char *hwaddr) +int invoke_disconnect_sta(struct node *n, struct netif_fhbss *p, + unsigned char *hwaddr) { struct cmd_disconnect_sta ds = {0}; char s[2*sizeof(struct cmd_disconnect_sta) + 1] = {0}; @@ -552,7 +558,8 @@ static int parse_sta_event(struct controller *c, const char *evtype, else n = find_node_by_ip(c, "127.0.0.1"); - rv = blobmsg_parse(sta_policy, __POLICY_MAX, tb, blobmsg_data(msg), blobmsg_len(msg)); + rv = blobmsg_parse(sta_policy, __POLICY_MAX, tb, + blobmsg_data(msg), blobmsg_len(msg)); if (rv < 0) { cntlr_dbg("Error parsing wifi.sta events!\n"); goto fail; @@ -570,7 +577,8 @@ static int parse_sta_event(struct controller *c, const char *evtype, if (tb[LOWRSSI]) { lowrssi = blobmsg_get_u32(tb[LOWRSSI]); if (lowrssi != 0) { - cntlr_dbg("Received wifi.sta 'lowrssi' (%d) event +++++++++++++>\n", lowrssi); + cntlr_dbg("Received wifi.sta 'lowrssi' (%d) event " \ + "+++++++++++++>\n", lowrssi); return cntlr_handle_sta_rssi_low(c, n, sta_macaddr, lowrssi); } } @@ -633,7 +641,8 @@ static int parse_sta_event(struct controller *c, const char *evtype, if (!prev_ap) return -1; - btostr(as->hwaddr, sizeof(as->hwaddr), hwaddrstr); + btostr(as->hwaddr, sizeof(as->hwaddr), + hwaddrstr); CMD(prev_ap->cntlr->comm, prev_ap->cntlr, (void *)prev_ap->uobj[4], CMD_FLUSH_ARP, @@ -717,7 +726,8 @@ static void system_info_resp_handler(struct ubus_request *req, int type, json_object_object_get_ex(val, "uptime", &uptime_obj); if (!uptime_obj && - !json_object_is_type(uptime_obj, json_type_int)) { + !json_object_is_type(uptime_obj, + json_type_int)) { continue; } /* TODO - in node data struct */ @@ -842,11 +852,11 @@ static void forall_node_get_repeater_hwmasks(struct controller *c) struct node *n; list_for_each_entry(n, &c->nodelist, list) { - CMD_ASYNC(c->comm, c, (void *)n->uobj[4], CMD_GET_MOBID, NULL, 0, - node_getmobid, n); + CMD_ASYNC(c->comm, c, (void *)n->uobj[4], CMD_GET_MOBID, NULL, + 0, node_getmobid, n); CMD_ASYNC(c->comm, c, (void *)n->uobj[4], CMD_GET_OUI, NULL, 0, - node_getoui, n); + node_getoui, n); } } @@ -995,7 +1005,6 @@ static int topology_add_node(struct controller *c, char *prefix) { struct node *n; struct in_addr ipn; - char macstr[18] = {0}; if (!prefix) { cntlr_dbg("%s: prefix = NULL!\n", __func__); @@ -1032,7 +1041,7 @@ static int topology_add_node(struct controller *c, char *prefix) /* TODO: get lan bridge name */ hwaddr_from_ip("br-lan", prefix, n->hwaddr); - info("%s: " MACFMT " \n", __func__, MAC2STR(n->hwaddr)); + info("%s: " MACFMT "\n", __func__, MAC2STR(n->hwaddr)); /* TODO * if (node_uplink_wifi(c, n->hwaddr)) @@ -1043,10 +1052,8 @@ static int topology_add_node(struct controller *c, char *prefix) as = as_lookup(c->as_table, n->hwaddr); if (as) as_clean_entry(c->as_table, n->hwaddr, as->bssid); - } else { - info("%s: (local) " MACFMT " \n", __func__, MAC2STR(n->hwaddr)); - } - + } else + info("%s: (local) " MACFMT "\n", __func__, MAC2STR(n->hwaddr)); list_add(&n->list, &c->nodelist); c->num_nodes++; @@ -1152,9 +1159,8 @@ static void watchlist_scanres_node_dump(void *cntlr, void *resp, int len, info("Node " MACFMT " has detected radar\n", MAC2STR(wn->hwaddr)); ret = cntlr_handle_radar_alert(c, wn); - if (!ret) { + if (!ret) free_watchnode_cleanup(c, wn); - } } static void watchlist_scanres_node(struct uloop_timeout *t) @@ -1176,13 +1182,13 @@ static void watchlist_scanres_node(struct uloop_timeout *t) continue; cntlr_dbg("Sending GET_SCANRES to node (%p:%p)---->\n", - n, n->uobj[4]); + n, n->uobj[4]); ret = CMD(c->comm, c, (void *)n->uobj[4], - CMD_GET_SCANRES, - bssidstr, sizeof(bssidstr), - watchlist_scanres_node_dump, - wn); + CMD_GET_SCANRES, + bssidstr, sizeof(bssidstr), + watchlist_scanres_node_dump, + wn); } if (ret && ++wn->scan_retry < WATCHNODE_SCAN_RETRY_MAX) { @@ -1369,7 +1375,8 @@ static int topology_del_node(struct controller *c, const char *prefix) return -1; } -static void build_topology_tree(struct ubus_request *req, int utype, struct blob_attr *msg) +static void build_topology_tree(struct ubus_request *req, int utype, + struct blob_attr *msg) { struct controller *c = (struct controller *)req->priv; struct json_object *json_msg; @@ -1397,6 +1404,7 @@ static void build_topology_tree(struct ubus_request *req, int utype, struct blob struct json_object *n_obj, *n_obj_hwaddr, *n_obj_ipaddr; struct json_object *n_obj_ul, *n_obj_depth, *n_obj_type; const char *hwstr, *ipstr, *ul_str, *type; +#if 0 char *uobj[] = { "router.system", /* info */ "router.graph", /* load */ @@ -1406,7 +1414,6 @@ static void build_topology_tree(struct ubus_request *req, int utype, struct blob char *evmask[] = { "wifi*", "client*", NULL }; char ev[128] = {0}; -#if 0 n = calloc(1, sizeof(struct node)); if (!n) { err("malloc failed!\n"); @@ -1446,9 +1453,11 @@ static void build_topology_tree(struct ubus_request *req, int utype, struct blob hwaddr_aton(hwstr, n->hwaddr); /* inet_aton(ipstr, &n->ipaddr); */ - if (ul_str && !strncasecmp(ul_str, "ethernet", strlen("ethernet") + 1)) + if (ul_str && !strncasecmp(ul_str, "ethernet", + strlen("ethernet") + 1)) n->ul_type = NETIF_LINK_ETH; - else if (ul_str && !strncasecmp(ul_str, "wireless", strlen("wireless") + 1)) + else if (ul_str && !strncasecmp(ul_str, "wireless", + strlen("wireless") + 1)) n->ul_type = NETIF_LINK_WIFI; info("%s: Network Node: " MACFMT " ip = %s\n", @@ -1490,9 +1499,9 @@ static int update_fronthaul_bsslist(struct node *n, struct netif_fhbss *fh) list_for_each_entry(p, &n->fronthaul_iflist, list) { if (!memcmp(p->bssid, fh->bssid, 6)) { - cntlr_dbg("Update fronthaul BSS " MACFMT " for node %s\n", - MAC2STR(p->bssid), - inet_ntoa(n->ipaddr)); + cntlr_dbg("Update fronthaul BSS " MACFMT \ + " for node %s\n", MAC2STR(p->bssid), + inet_ntoa(n->ipaddr)); if (!p->ssid[0]) strncpy(p->ssid, fh->ssid, 33); p->bssid_info = fh->bssid_info; @@ -1541,11 +1550,13 @@ static void node_getbssinfo(void *cntlr, void *resp, int len, void *cookie) info->channel = ntohl(info->channel); info->num_bss = ntohl(info->num_bss); - loud("GET_BSSINFO from %s >>> num_bss = %d channel = %d bss-ifname = %s\n", - inet_ntoa(n->ipaddr), info->num_bss, info->channel, info->bss[0].ifname); + loud("GET_BSSINFO from %s >>> num_bss = %d channel = %d bss-ifname =" \ + " %s\n", inet_ntoa(n->ipaddr), info->num_bss, + info->channel, info->bss[0].ifname); if (info->num_bss > MAX_BSSNUM) { - dbg("GET_BSSINFO num_bss = %d > %d !\n", info->num_bss, MAX_BSSNUM); + dbg("GET_BSSINFO num_bss = %d > %d !\n", + info->num_bss, MAX_BSSNUM); return; } @@ -1558,7 +1569,8 @@ static void node_getbssinfo(void *cntlr, void *resp, int len, void *cookie) } cntlr_dbg("[%d] Agent = %s\n", i, inet_ntoa(n->ipaddr)); cntlr_dbg("[%d] ifname = %s\n", i, info->bss[i].ifname); - cntlr_dbg("[%d] bssid = " MACFMT "\n", i, MAC2STR(info->bss[i].bssid)); + cntlr_dbg("[%d] bssid = " MACFMT "\n", i, + MAC2STR(info->bss[i].bssid)); cntlr_dbg("[%d] ssid = %s\n", i, info->bss[i].ssid); cntlr_dbg("[%d] channel= %d\n", i, info->channel); @@ -1600,13 +1612,15 @@ static void forall_node_exclude_steering(struct controller *c) list_for_each_entry(n, &c->nodelist, list) { if (hwaddr_is_zero(n->hwaddr)) - cntlr_dbg("Cntlr: CMD_STEER_EXCLUDE to agent @[local] --->>\n"); + cntlr_dbg("Cntlr: CMD_STEER_EXCLUDE to agent @[local]" \ + " --->>\n"); else - cntlr_dbg("Cntlr: CMD_STEER_EXCLUDE to agent @["MACFMT"] --->>\n", - MAC2STR(n->hwaddr)); + cntlr_dbg("Cntlr: CMD_STEER_EXCLUDE to agent " \ + " @["MACFMT"] --->>\n", + MAC2STR(n->hwaddr)); CMD(c->comm, c, (void *)n->uobj[4], CMD_STEER_EXCLUDE, - macstr, i*17, NULL, NULL); + macstr, i*17, NULL, NULL); } } /* #endif */ @@ -1618,7 +1632,7 @@ static void forall_node_trigger_scan(struct controller *c) list_for_each_entry(n, &c->nodelist, list) { if (n->scan_supported) { CMD(c->comm, c, (void *)n->uobj[4], - CMD_SCAN, NULL, 0, NULL, NULL); + CMD_SCAN, NULL, 0, NULL, NULL); } } } @@ -1636,8 +1650,8 @@ static void perform_tasks_topology_init(struct controller *c) unsigned char sta[6] = "\xd8\x32\xe3\x4d\x35\xd2"; list_for_each_entry(n, &c->nodelist, list) { - cntlr_dbg("Cntlr: Sending CMD_ASSOC_CONTROL to '" MACFMT "' --->>\n", - MAC2STR(n->hwaddr)); + cntlr_dbg("Cntlr: Sending CMD_ASSOC_CONTROL to '" MACFMT \ + "' --->>\n", MAC2STR(n->hwaddr)); memset(&asc, 0, sizeof(asc)); asc.len = sizeof(asc); asc.enable = 1; @@ -1645,9 +1659,9 @@ static void perform_tasks_topology_init(struct controller *c) asc.num = 1; memcpy(asc.stas, sta, 6); CMD(c->comm, c, (void *)n->uobj[4], CMD_ASSOC_CONTROL, - &asc, - sizeof(asc), - NULL); + &asc, + sizeof(asc), + NULL); } } #endif @@ -1678,7 +1692,6 @@ static void cntlr_ubusx_event_handler(struct ubus_context *ctx, del = !strcmp(type, "ubus.object.remove"); /* wifi_sta = strstr(type, "wifi.sta") != NULL; */ - if (!add && !del) { #if 0 /* 'wifi.sta' events handled through per-node handler */ if (wifi_sta) { @@ -1704,7 +1717,8 @@ static void cntlr_ubusx_event_handler(struct ubus_context *ctx, struct in_addr ipn; int rv; - info("To add: %s/wifi.agent\n", node[0] ? node : "local"); + info("To add: %s/wifi.agent\n", + node[0] ? node : "local"); topology_add_node(c, node); watchlist_del_node(c, node); @@ -1715,7 +1729,8 @@ static void cntlr_ubusx_event_handler(struct ubus_context *ctx, get_node_oui(c, &ipn); get_node_mobid(c, &ipn); } else { - info("To del: %s/wifi.agent\n", node[0] ? node : "local"); + info("To del: %s/wifi.agent\n", + node[0] ? node : "local"); watchlist_add_node(c, node); topology_del_node(c, node); } @@ -1725,7 +1740,8 @@ static void cntlr_ubusx_event_handler(struct ubus_context *ctx, } -static void cntlr_ieee1905_cmdu_event_handler(void *cntlr, struct blob_attr *msg) +static void cntlr_ieee1905_cmdu_event_handler(void *cntlr, + struct blob_attr *msg) { static const struct blobmsg_policy cmdu_attrs[5] = { [0] = { .name = "type", .type = BLOBMSG_TYPE_INT32 }, @@ -1762,14 +1778,12 @@ static void cntlr_ieee1905_cmdu_event_handler(void *cntlr, struct blob_attr *msg mid = (uint16_t)blobmsg_get_u32(tb[1]); - if (tb[2]) { + if (tb[2]) strncpy(in_ifname, blobmsg_data(tb[2]), 15); - } if (tb[3]) { strncpy(src, blobmsg_data(tb[3]), 17); hwaddr_aton(src, srcmac); - } if (tb[4]) { @@ -1801,7 +1815,8 @@ static void cntlr_ieee1905_event_handler(struct ubus_context *ctx, const char *type, struct blob_attr *msg) { - struct controller *c = container_of(ev, struct controller, ieee1905_evh); + struct controller *c = container_of(ev, struct controller, + ieee1905_evh); struct ev_handler { const char *ev_type; void (*handler)(void *ctx, struct blob_attr *ev_data); @@ -1815,7 +1830,7 @@ static void cntlr_ieee1905_event_handler(struct ubus_context *ctx, dbg("[ &cntlr = %p ] Received [event = %s][val = %s]\n", c, type, str); - for (i = 0; i < sizeof(evs)/sizeof(evs[0]); i++) { + for (i = 0; i < ARRAY_SIZE(evs); i++) { if (!strcmp(type, evs[i].ev_type)) { evs[i].handler(c, msg); break; @@ -1830,7 +1845,8 @@ static int cntlr_register_events(struct controller *c) #if 0 if (c->topology != OBJECT_INVALID) { cntlr_dbg("Setting up event handler for 'topology' events\n"); - ubus_register_event_handler(c->ubus_ctx, &c->ubus_ev, "topology.*"); + ubus_register_event_handler(c->ubus_ctx, &c->ubus_ev, + "topology.*"); } #endif cntlr_dbg("Setting up bus event handlers...\n"); @@ -1838,9 +1854,12 @@ static int cntlr_register_events(struct controller *c) c->ubusx_ev.cb = cntlr_ubusx_event_handler; c->ieee1905_evh.cb = cntlr_ieee1905_event_handler; - ubus_register_event_handler(c->ubus_ctx, &c->ubusx_ev, "ubus.object.add"); - ubus_register_event_handler(c->ubus_ctx, &c->ubusx_ev, "ubus.object.remove"); - ubus_register_event_handler(c->ubus_ctx, &c->ieee1905_evh, "ieee1905.*"); + ubus_register_event_handler(c->ubus_ctx, &c->ubusx_ev, + "ubus.object.add"); + ubus_register_event_handler(c->ubus_ctx, &c->ubusx_ev, + "ubus.object.remove"); + ubus_register_event_handler(c->ubus_ctx, &c->ieee1905_evh, + "ieee1905.*"); return 0; } diff --git a/src/core/cntlr.h b/src/core/cntlr.h index 525f9aa504c9d0e50f84b099898cd7d662394942..734b564f0f91f8faed1c46ce26a4ae97d26f4d91 100644 --- a/src/core/cntlr.h +++ b/src/core/cntlr.h @@ -127,7 +127,7 @@ struct controller { struct controller_config cfg; }; -#define COMM_HANDLE(c) ((struct controller *)(c))->ubus_ctx +#define COMM_HANDLE(c) (((struct controller *)(c))->ubus_ctx) extern int start_controller(void); diff --git a/src/core/cntlr_map.c b/src/core/cntlr_map.c index 2619ddab36fa5cc7309678d2ac118639aba9a905..75fa1c7482dd917e532965f03eb8cdf06b7610cd 100644 --- a/src/core/cntlr_map.c +++ b/src/core/cntlr_map.c @@ -61,7 +61,7 @@ int verbose; typedef int (*map_cmdu_handler_t)(void *cntlr, struct cmdu_cstruct *cmdu); struct map_cmdu_calltable_t { - map_cmdu_handler_t handle; + map_cmdu_handler_t handle; map_cmdu_handler_t debug; }; @@ -105,7 +105,8 @@ int handle_1905_ack(void *cntlr, struct cmdu_cstruct *cmdu) int handle_ap_caps_report(void *cntlr, struct cmdu_cstruct *cmdu) { trace("%s: --->\n", __func__); - trace("parsing AP capabilities of |%s:" MACFMT "|\n", cmdu->intf_name, MAC2STR(cmdu->origin)); + trace("parsing AP capabilities of |%s:" MACFMT "|\n", + cmdu->intf_name, MAC2STR(cmdu->origin)); return 0; } @@ -131,7 +132,8 @@ int handle_oper_channel_report(void *cntlr, struct cmdu_cstruct *cmdu) int handle_sta_caps_report(void *cntlr, struct cmdu_cstruct *cmdu) { trace("%s: --->\n", __func__); - trace("parsing AP capabilities of |%s:" MACFMT "|\n", cmdu->intf_name, MAC2STR(cmdu->origin)); + trace("parsing AP capabilities of |%s:" MACFMT "|\n", + cmdu->intf_name, MAC2STR(cmdu->origin)); return 0; } @@ -147,7 +149,8 @@ int handle_sta_link_metrics_response(void *cntlr, struct cmdu_cstruct *cmdu) return 0; } -int handle_unassoc_sta_link_metrics_response(void *cntlr, struct cmdu_cstruct *cmdu) +int handle_unassoc_sta_link_metrics_response(void *cntlr, + struct cmdu_cstruct *cmdu) { trace("%s: --->\n", __func__); return 0; diff --git a/src/core/cntlr_map_debug.c b/src/core/cntlr_map_debug.c index 5a28b6e1b0fa130569d919905b592b06e186cac8..2fe463dd408cea5342f39ff8f0d640466cfb2e52 100644 --- a/src/core/cntlr_map_debug.c +++ b/src/core/cntlr_map_debug.c @@ -64,10 +64,10 @@ int debug_1905_ack(void *cntlr, struct cmdu_cstruct *cmdu) int debug_ap_caps_report(void *cntlr, struct cmdu_cstruct *cmdu) { trace("%s: --->\n", __func__); - trace("parsing AP capabilities of |%s:" MACFMT "|\n", cmdu->intf_name, MAC2STR(cmdu->origin)); + trace("parsing AP capabilities of |%s:" MACFMT "|\n", cmdu->intf_name, + MAC2STR(cmdu->origin)); int i, j, k; - int radio_index, bss_index; uint8_t *tlv = NULL; for (i = 0; i < cmdu->num_tlvs; i++) { @@ -78,48 +78,64 @@ int debug_ap_caps_report(void *cntlr, struct cmdu_cstruct *cmdu) { struct tlv_ap_cap *p = (struct tlv_ap_cap *)tlv; - trace("\top_ch_metric_reporting: %d\n", p->op_ch_metric_reporting); - trace("\tnon_op_ch_metric_reporting: %d\n", p->non_op_ch_metric_reporting); - trace("\tagent_init_rcpi_steering: %d\n", p->agent_init_rcpi_steering); + trace("\top_ch_metric_reporting: %d\n", + p->op_ch_metric_reporting); + trace("\tnon_op_ch_metric_reporting: %d\n", + p->non_op_ch_metric_reporting); + trace("\tagent_init_rcpi_steering: %d\n", + p->agent_init_rcpi_steering); break; } case MAP_TLV_AP_RADIO_BASIC_CAPABILITIES: { - struct tlv_ap_radio_basic_cap *p = (struct tlv_ap_radio_basic_cap *)tlv; + struct tlv_ap_radio_basic_cap *p = + (struct tlv_ap_radio_basic_cap *)tlv; trace("\tradio_id: " MACFMT "\n", MAC2STR(p->radio_id)); trace("\tmax_bss_nr: %d\n", p->max_bss_nr); trace("\toperating_classes_nr: %d\n", p->operating_classes_nr); for (j = 0; j < p->operating_classes_nr; j++) { - trace("\t\top_class: %d\n", p->operating_class[j].op_class); - trace("\t\tmax_tx_power: %d\n", p->operating_class[j].max_tx_power); - trace("\t\tnon_op_ch_nr: %d\n", p->operating_class[j].non_op_ch_nr); + trace("\t\top_class: %d\n", + p->operating_class[j].op_class); + trace("\t\tmax_tx_power: %d\n", + p->operating_class[j].max_tx_power); + trace("\t\tnon_op_ch_nr: %d\n", + p->operating_class[j].non_op_ch_nr); for (k = 0; k < p->operating_class[j].non_op_ch_nr; k++) - trace("\t\t\tchannel: %d\n", p->operating_class[j].channel[k]); + trace("\t\t\tchannel: %d\n", + p->operating_class[j].channel[k]); } break; } case MAP_TLV_AP_HT_CAPABILITIES: { - struct tlv_ap_ht_cap *p = (struct tlv_ap_ht_cap *)tlv; + struct tlv_ap_ht_cap *p = + (struct tlv_ap_ht_cap *)tlv; - trace("\tradio_id: " MACFMT "\n", MAC2STR(p->radio_id)); - trace("\tmax_tx_streams_supported: %d\n", p->max_tx_streams_supported); + trace("\tradio_id: " MACFMT "\n", + MAC2STR(p->radio_id)); + trace("\tmax_tx_streams_supported: %d\n", + p->max_tx_streams_supported); trace("\tmax_tx_streams_supported: "); print_bits(p->max_tx_streams_supported, 2, 2); trace("\tmax_rx_streams_supported: "); print_bits(p->max_rx_streams_supported, 2, 2); - trace("\tgi_20_support: %s\n", (p->gi_20_support ? "true" : "false")); - trace("\tgi_40_support: %s\n", (p->gi_40_support ? "true" : "false")); - trace("\tht_40_support: %s\n", (p->ht_40_support ? "true" : "false")); + trace("\tgi_20_support: %s\n", + (p->gi_20_support ? "true" : "false")); + trace("\tgi_40_support: %s\n", + (p->gi_40_support ? "true" : "false")); + trace("\tht_40_support: %s\n", + (p->ht_40_support ? "true" : "false")); break; } case MAP_TLV_AP_VHT_CAPABILITIES: { - struct tlv_ap_vht_cap *p = (struct tlv_ap_vht_cap *)tlv; + struct tlv_ap_vht_cap *p = + (struct tlv_ap_vht_cap *)tlv; - trace("\tradio_id: " MACFMT "\n", MAC2STR(p->radio_id)); + trace("\tradio_id: " MACFMT "\n", + MAC2STR(p->radio_id)); trace("\tvht_tx_mcs_supported: "); print_bits(p->vht_tx_mcs_supported, 16, 2); trace("\tvht_rx_mcs_supported: "); @@ -128,15 +144,21 @@ int debug_ap_caps_report(void *cntlr, struct cmdu_cstruct *cmdu) print_bits(p->max_tx_streams_supported, 3, 3); trace("\tmax_rx_streams_supported: "); print_bits(p->max_rx_streams_supported, 3, 3); - trace("\tgi_80_support: %s\n", (p->gi_80_support ? "true" : "false")); - trace("\tgi_160_support: %s\n", (p->gi_160_support ? "true" : "false")); - trace("\tvht160_support: %s\n", (p->vht_160_support ? "true" : "false")); - trace("\tsu_beamformer_capable: %s\n", (p->su_beamformer_capable ? "true" : "false")); - trace("\tmu_beamformer_capable: %s\n", (p->mu_beamformer_capable ? "true" : "false")); + trace("\tgi_80_support: %s\n", + (p->gi_80_support ? "true" : "false")); + trace("\tgi_160_support: %s\n", + (p->gi_160_support ? "true" : "false")); + trace("\tvht160_support: %s\n", + (p->vht_160_support ? "true" : "false")); + trace("\tsu_beamformer_capable: %s\n", + (p->su_beamformer_capable ? "true" : "false")); + trace("\tmu_beamformer_capable: %s\n", + (p->mu_beamformer_capable ? "true" : "false")); break; } default: - fprintf(stdout, "unknown TLV in CMDU:|%s|", map_stringify_cmdu_type(cmdu->message_type)); + fprintf(stdout, "unknown TLV in CMDU:|%s|", + map_stringify_cmdu_type(cmdu->message_type)); break; } trace("\n"); @@ -165,12 +187,12 @@ int debug_oper_channel_report(void *cntlr, struct cmdu_cstruct *cmdu) int debug_sta_caps_report(void *cntlr, struct cmdu_cstruct *cmdu) { - int i, j, k; - int radio_index, bss_index; + int i; uint8_t *tlv = NULL; trace("%s: --->\n", __func__); - trace("parsing AP capabilities of |%s:" MACFMT "|\n", cmdu->intf_name, MAC2STR(cmdu->origin)); + trace("parsing AP capabilities of |%s:" MACFMT "|\n", + cmdu->intf_name, MAC2STR(cmdu->origin)); for (i = 0; i < cmdu->num_tlvs; i++) { tlv = cmdu->tlvs[i]; @@ -178,23 +200,29 @@ int debug_sta_caps_report(void *cntlr, struct cmdu_cstruct *cmdu) switch (*tlv) { case MAP_TLV_CLIENT_INFO: { - struct tlv_client_info *p = (struct tlv_client_info *)tlv; + struct tlv_client_info *p = + (struct tlv_client_info *)tlv; - trace("\tbssid: " MACFMT "\n", MAC2STR(p->bssid)); - trace("\tclient_addr: " MACFMT "\n", MAC2STR(p->client_addr)); + trace("\tbssid: " MACFMT "\n", + MAC2STR(p->bssid)); + trace("\tclient_addr: " MACFMT "\n", + MAC2STR(p->client_addr)); break; } case MAP_TLV_CLIENT_CAPABILITY_REPORT: { - struct tlv_client_cap_report *p = (struct tlv_client_cap_report *)tlv; + struct tlv_client_cap_report *p = + (struct tlv_client_cap_report *)tlv; char *frame; int offset = 1 + 2 + 1; - frame = calloc(1, (2 * (p->tlv_len - offset)) + 1); + frame = calloc(1, + (2 * (p->tlv_len - offset)) + 1); if (!frame) continue; - btostr(p->frame_body + offset, p->tlv_len - offset, frame); + btostr(p->frame_body + offset, + p->tlv_len - offset, frame); trace("\tresult_code: 0x%02x\n", p->result_code); trace("\tframe: 0x%s\n", frame); @@ -202,16 +230,19 @@ int debug_sta_caps_report(void *cntlr, struct cmdu_cstruct *cmdu) } case MAP_TLV_ERROR_CODE: { - struct tlv_error_code *p = (struct tlv_error_code *)tlv; + struct tlv_error_code *p = + (struct tlv_error_code *)tlv; trace("\treason_code: 0x%02x\n", p->reason_code); if (p->reason_code == 0x02) - trace("\tclient_addr: " MACFMT "\n", MAC2STR(p->addr)); + trace("\tclient_addr: " MACFMT "\n", + MAC2STR(p->addr)); break; } default: - fprintf(stdout, "unknown TLV in CMDU:|%s|", map_stringify_cmdu_type(cmdu->message_type)); + fprintf(stdout, "unknown TLV in CMDU:|%s|", + map_stringify_cmdu_type(cmdu->message_type)); break; } trace("\n"); @@ -232,7 +263,8 @@ int debug_sta_link_metrics_response(void *cntlr, struct cmdu_cstruct *cmdu) return 0; } -int debug_unassoc_sta_link_metrics_response(void *cntlr, struct cmdu_cstruct *cmdu) +int debug_unassoc_sta_link_metrics_response(void *cntlr, + struct cmdu_cstruct *cmdu) { trace("%s: --->\n", __func__); return 0; @@ -296,4 +328,4 @@ int debug_backhaul_sta_caps_report(void *cntlr, struct cmdu_cstruct *cmdu) int debug_failed_connection_msg(void *cntlr, struct cmdu_cstruct *cmdu) { return 0; -} \ No newline at end of file +} diff --git a/src/core/cntlr_map_debug.h b/src/core/cntlr_map_debug.h index 4b2003d4101ac16bfdd9bd6b7702dfadb6380b12..384886c43efe8ade70b8a1228e092f20c4770c9b 100644 --- a/src/core/cntlr_map_debug.h +++ b/src/core/cntlr_map_debug.h @@ -23,7 +23,8 @@ int debug_oper_channel_report(void *cntlr, struct cmdu_cstruct *cmdu); int debug_sta_caps_report(void *cntlr, struct cmdu_cstruct *cmdu); int debug_ap_metrics_response(void *cntlr, struct cmdu_cstruct *cmdu); int debug_sta_link_metrics_response(void *cntlr, struct cmdu_cstruct *cmdu); -int debug_unassoc_sta_link_metrics_response(void *cntlr, struct cmdu_cstruct *cmdu); +int debug_unassoc_sta_link_metrics_response(void *cntlr, + struct cmdu_cstruct *cmdu); int debug_beacon_metrics_response(void *cntlr, struct cmdu_cstruct *cmdu); int debug_sta_steer_btm_report(void *cntlr, struct cmdu_cstruct *cmdu); int debug_sta_steer_complete(void *cntlr, struct cmdu_cstruct *cmdu); @@ -34,4 +35,4 @@ int debug_assoc_status_notification(void *cntlr, struct cmdu_cstruct *cmdu); int debug_tunneled_message(void *cntlr, struct cmdu_cstruct *cmdu); int debug_backhaul_sta_caps_report(void *cntlr, struct cmdu_cstruct *cmdu); int debug_failed_connection_msg(void *cntlr, struct cmdu_cstruct *cmdu); -#endif \ No newline at end of file +#endif diff --git a/src/core/cntlr_ubus.c b/src/core/cntlr_ubus.c index 6e2b29d21c60b3f15133f601f3cfabb6ae469ead..2ce015f93291927f166f77d72c67e94b8b42d1f3 100644 --- a/src/core/cntlr_ubus.c +++ b/src/core/cntlr_ubus.c @@ -37,13 +37,15 @@ enum { AP_POLICY_AGENT, - //AP_POLICY_BSSID, /* TODO: filter on cntlr side based on bssid */ + /* TODO: filter on cntlr side based on bssid */ + //AP_POLICY_BSSID, __AP_POLICY_MAX, }; static const struct blobmsg_policy ap_caps_policy_params[__AP_POLICY_MAX] = { [AP_POLICY_AGENT] = { .name = "agent", .type = BLOBMSG_TYPE_STRING }, - //[AP_POLICY_BSSID] = { .name = "bssid", .type = BLOBMSG_TYPE_STRING } /* TODO: filter on cntlr side based on bssid */ + /* TODO: filter on cntlr side based on bssid */ + //[AP_POLICY_BSSID] = { .name = "bssid", .type = BLOBMSG_TYPE_STRING } }; @@ -93,7 +95,7 @@ static void send_cmdu_cb(struct ubus_request *req, } static int send_cmdu(struct controller *c, - struct cmdu_cstruct *cmdu_data) + struct cmdu_cstruct *cmdu_data) { char *tlv_data = NULL; uint16_t tlv_data_len = 1; @@ -102,16 +104,14 @@ static int send_cmdu(struct controller *c, struct blob_buf b = { 0 }; char dst_addr[18] = { 0 }; char tlv_str[512] = { 0 }; - uint8_t is_store_mid = 1; uint8_t *ss = NULL; uint16_t msgid = 0; uint16_t len; int ret = -1; size_t i; uint32_t id; - struct ieee1905_cmdu_msg *cmsg = NULL; - fprintf(stdout, "|%s:%d| Entry \n", __func__, __LINE__); + fprintf(stdout, "|%s:%d| Entry\n", __func__, __LINE__); memset(&b, 0, sizeof(struct blob_buf)); blob_buf_init(&b, 0); @@ -125,7 +125,8 @@ static int send_cmdu(struct controller *c, blobmsg_add_string(&b, "dst_macaddr", dst_addr); fprintf(stdout, "|%s:%d|cmdu:%s|dst:%s|num_tlvs:%d|\n", __func__, __LINE__, - map_stringify_cmdu_type(cmdu_data->message_type), dst_addr, cmdu_data->num_tlvs); + map_stringify_cmdu_type(cmdu_data->message_type), + dst_addr, cmdu_data->num_tlvs); if (cmdu_data->num_tlvs > 0) { for (i = 0; i < cmdu_data->num_tlvs; i++) { @@ -137,7 +138,8 @@ static int send_cmdu(struct controller *c, tlv_data_len += tlv_str_len; tlv_data = realloc(tlv_data, tlv_data_len * sizeof(char)); if (!tlv_data) { - fprintf(stderr, "%s:%d out of memory.!\n", __func__, __LINE__); + fprintf(stderr, "%s:%d out of memory.!\n", + __func__, __LINE__); free(ss); goto out; } @@ -263,31 +265,6 @@ static int cntlr_status(struct ubus_context *ctx, struct ubus_object *obj, return UBUS_STATUS_OK; } -static int cntlr_req_cap(struct ubus_context *ctx, struct ubus_object *obj, - struct ubus_request_data *req, const char *method, - struct blob_attr *msg) -{ - struct cmdu_cstruct *cmdu_data; - uint32_t total_bss = 0; - uint32_t k = 0; - uint32_t i, j; - - cmdu_data = (struct cmdu_cstruct *)calloc(1, sizeof(struct cmdu_cstruct)); - if (!cmdu_data) { - fprintf(stderr, "failed to malloc cmdu\n"); - return -1; - } - - cmdu_data->message_type = CMDU_CLIENT_CAPABILITY_QUERY; - cmdu_data->message_id = 1; - - fprintf(stderr, "map.1905 egress interface:|%s|\n", cmdu_data->intf_name); - - send_cmdu(NULL, cmdu_data); - - return 0; -} - static int cntlr_ap_caps(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) @@ -296,21 +273,21 @@ static int cntlr_ap_caps(struct ubus_context *ctx, struct ubus_object *obj, struct controller *c = container_of(obj, struct controller, obj); char agent[18] = {0}; struct cmdu_cstruct *cmdu_data; - uint32_t total_bss = 0; - uint32_t k = 0; - uint32_t i, j; - cmdu_data = (struct cmdu_cstruct *)calloc(1, sizeof(struct cmdu_cstruct)); + cmdu_data = (struct cmdu_cstruct *)calloc(1, + sizeof(struct cmdu_cstruct)); if (!cmdu_data) { fprintf(stderr, "failed to malloc cmdu\n"); return UBUS_STATUS_UNKNOWN_ERROR; } - blobmsg_parse(ap_caps_policy_params, __AP_POLICY_MAX, tb, blob_data(msg), blob_len(msg)); + blobmsg_parse(ap_caps_policy_params, __AP_POLICY_MAX, tb, + blob_data(msg), blob_len(msg)); if (tb[AP_POLICY_AGENT]) { - strncpy(agent, blobmsg_data(tb[AP_POLICY_AGENT]), sizeof(agent) - 1); + strncpy(agent, blobmsg_data(tb[AP_POLICY_AGENT]), + sizeof(agent) - 1); if (!hwaddr_aton(agent, cmdu_data->origin)) return UBUS_STATUS_UNKNOWN_ERROR; } @@ -338,24 +315,28 @@ static int cntlr_sta_caps(struct ubus_context *ctx, struct ubus_object *obj, char sta[18] = {0}, agent[18] = {0}, bssid[18] = {0}; struct cmdu_cstruct *cmdu_data; - blobmsg_parse(sta_caps_policy_params, __STA_POLICY_MAX, tb, blob_data(msg), blob_len(msg)); + blobmsg_parse(sta_caps_policy_params, __STA_POLICY_MAX, tb, + blob_data(msg), blob_len(msg)); if (!tb[STA_POLICY_STA] || !tb[STA_POLICY_BSSID]) { - fprintf(stderr, "STA Capability Query: must provide STA and BSSID\n"); + fprintf(stderr, "STA Capability Query: must provide STA and "\ + "BSSID\n"); return UBUS_STATUS_INVALID_ARGUMENT; } strncpy(sta, blobmsg_data(tb[STA_POLICY_STA]), sizeof(sta) - 1); strncpy(bssid, blobmsg_data(tb[STA_POLICY_BSSID]), sizeof(bssid) - 1); - cmdu_data = (struct cmdu_cstruct *)calloc(1, sizeof(struct cmdu_cstruct)); + cmdu_data = (struct cmdu_cstruct *)calloc(1, + sizeof(struct cmdu_cstruct)); if (!cmdu_data) { fprintf(stderr, "failed to malloc cmdu\n"); return UBUS_STATUS_UNKNOWN_ERROR; } if (tb[AP_POLICY_AGENT]) { - strncpy(agent, blobmsg_data(tb[AP_POLICY_AGENT]), sizeof(agent) - 1); + strncpy(agent, blobmsg_data(tb[AP_POLICY_AGENT]), + sizeof(agent) - 1); if (!hwaddr_aton(agent, cmdu_data->origin)) return UBUS_STATUS_UNKNOWN_ERROR; } @@ -372,14 +353,14 @@ static int cntlr_sta_caps(struct ubus_context *ctx, struct ubus_object *obj, } if (!hwaddr_aton(sta, hw_sta)) { - fprintf(stderr, "STA Capability Query: provide STA address in " \ - "format 11:22:33...\n"); + fprintf(stderr, "STA Capability Query: provide STA " \ + "address in format 11:22:33...\n"); return UBUS_STATUS_INVALID_ARGUMENT; } if (!hwaddr_aton(bssid, hw_bssid)) { - fprintf(stderr, "STA Capability Query: provide BSSID address in " \ - "format 11:22:33...\n"); + fprintf(stderr, "STA Capability Query: provide BSSID " \ + "address in format 11:22:33...\n"); return UBUS_STATUS_INVALID_ARGUMENT; } @@ -388,10 +369,11 @@ static int cntlr_sta_caps(struct ubus_context *ctx, struct ubus_object *obj, memcpy(p->client_addr, hw_sta, 6); cmdu_data->num_tlvs = 1; - cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, sizeof(uint8_t *)); + cmdu_data->tlvs = (uint8_t **)calloc(cmdu_data->num_tlvs, + sizeof(uint8_t *)); if (cmdu_data->tlvs) - cmdu_data->tlvs[0] = (uint8_t *)p; + cmdu_data->tlvs[0] = (uint8_t *)p; send_cmdu(c, cmdu_data); @@ -403,9 +385,8 @@ int cntlr_publish_object(struct controller *c, const char *objname) struct ubus_object *obj; struct ubus_object_type *obj_type; struct ubus_method *obj_methods; - struct ubus_method m[4] = { + struct ubus_method m[3] = { UBUS_METHOD_NOARG("status", cntlr_status), - UBUS_METHOD_NOARG("req_cap", cntlr_req_cap), UBUS_METHOD("ap_caps", cntlr_ap_caps, ap_caps_policy_params), UBUS_METHOD("sta_caps", cntlr_sta_caps, sta_caps_policy_params), }; @@ -437,7 +418,8 @@ int cntlr_publish_object(struct controller *c, const char *objname) ret = ubus_add_object(c->ubus_ctx, obj); if (ret) { - err("Failed to add '%s' err = %s\n", objname, ubus_strerror(ret)); + err("Failed to add '%s' err = %s\n", + objname, ubus_strerror(ret)); free(obj_methods); free(obj_type); return ret; diff --git a/src/core/config.c b/src/core/config.c index b1e736c4ccb83083b3beff4e5411a2f63700fcb0..c996dfa82705d36ca5f43c3d38a792c2a47da137 100644 --- a/src/core/config.c +++ b/src/core/config.c @@ -54,7 +54,7 @@ void cntlr_config_dump(struct controller_config *c) for (i = 0; i < c->num_fh; i++) { dbg(" Band : %d\n", c->fh[i].band); dbg(" Security: 0x%x\n", c->fh[i].sec); - dbg(" Key : \n"); + dbg(" Key :\n"); dbg(" ssid : %s\n", c->fh[i].ssid); dbg(" vlan : %d\n\n", c->fh[i].vlanid); } @@ -63,7 +63,7 @@ void cntlr_config_dump(struct controller_config *c) for (i = 0; i < c->num_bk; i++) { dbg(" Band : %d\n", c->bk[i].band); dbg(" Security: 0x%x\n", c->bk[i].sec); - dbg(" Key : \n"); + dbg(" Key :\n"); dbg(" ssid : %s\n", c->bk[i].ssid); dbg(" vlan : %d\n\n", c->bk[i].vlanid); } @@ -250,7 +250,6 @@ static int cntlr_config_get_agent_policy(struct controller_config *c, uci_parse_section(s, opts, NUM_POLICIES, tb); - if (tb[POL_ID]) { const char *val = tb[POL_ID]->v.string; @@ -274,7 +273,7 @@ static int cntlr_config_get_agent_policy(struct controller_config *c, if (tb[POL_RPT_ASSOC_FAILS]) { c->apolicy.report_sta_assocfails = atoi(tb[POL_RPT_ASSOC_FAILS]->v.string) == 1 ? - true : false; + true : false; } if (tb[POL_RPT_METRIC_PERIODIC]) { @@ -295,13 +294,13 @@ static int cntlr_config_get_agent_policy(struct controller_config *c, if (tb[POL_INC_STA_STATS]) { c->apolicy.include_sta_stats = atoi(tb[POL_INC_STA_STATS]->v.string) == 1 ? - true : false; + true : false; } if (tb[POL_INC_STA_METRIC]) { c->apolicy.include_sta_metric = atoi(tb[POL_INC_STA_METRIC]->v.string) == 1 ? - true : false; + true : false; } if (tb[POL_PVID]) @@ -314,13 +313,13 @@ static int cntlr_config_get_agent_policy(struct controller_config *c, if (tb[POL_DISALLOW_BSTA_P1]) { c->apolicy.disallow_bsta_p1 = atoi(tb[POL_DISALLOW_BSTA_P1]->v.string) == 1 ? - true : false; + true : false; } if (tb[POL_DISALLOW_BSTA_P2]) { c->apolicy.disallow_bsta_p2 = atoi(tb[POL_DISALLOW_BSTA_P2]->v.string) == 1 ? - true : false; + true : false; } diff --git a/src/core/config.h b/src/core/config.h index 0e90e9158ac0ef50bb2c2a3b8a607debd79afb15..c1b752c7ad80ba7a83b3c3921b0461a19a6217a9 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -11,7 +11,7 @@ #define CONFIG_H /* -// TODO: use wifi.h definitions?? + * TODO: use wifi.h definitions?? enum wifi_band { WIFI_BAND_NONE, WIFI_BAND_2 = 1 << 0, @@ -22,7 +22,7 @@ enum wifi_band { */ /* -// TODO: use wifi.h definitions?? + * TODO: use wifi.h definitions?? enum wifi_security { WIFI_SECURITY_NONE, WIFI_SECURITY_WEP64, diff --git a/src/ipc/comm.c b/src/ipc/comm.c index 4bd7b596bac3eb8c5bb04e9664954b55d8d4c431..be8ff48f91d305aef798a2ba8a089989b54674fe 100644 --- a/src/ipc/comm.c +++ b/src/ipc/comm.c @@ -45,7 +45,7 @@ int _comm_cmd(void *comm, void *self, void *dest, cmdi->cookie = cookie; cmdi->ipc = NULL; trace_cmd("Sending CMD %s (&cmd = %p, dest = %p) --->\n", - CMDSTRING(cmd), &cmdi, dest); + CMDSTRING(cmd), &cmdi, dest); ret = is_async ? comm_send_msg_async(comm, dest, cmdi) : diff --git a/src/ipc/comm.h b/src/ipc/comm.h index 9c75bc34f007626fe72d1df1ec31134cf4f67da7..057f867c724d8ad162cc3287d800c53c8d0c0770 100644 --- a/src/ipc/comm.h +++ b/src/ipc/comm.h @@ -111,12 +111,14 @@ static inline int comm_destroy(void *handle) return comm_iface.destroy(handle); } -static inline int comm_send_msg(void *handle, void *dest, struct CMD_struct *cmd) +static inline int comm_send_msg(void *handle, void *dest, + struct CMD_struct *cmd) { return comm_iface.send_msg(handle, dest, cmd); } -static inline int comm_send_msg_async(void *handle, void *dest, struct CMD_struct *cmd) +static inline int comm_send_msg_async(void *handle, void *dest, + struct CMD_struct *cmd) { return comm_iface.send_msg_async(handle, dest, cmd); } @@ -126,8 +128,8 @@ extern int _comm_cmd(void *comm, void *self, void *dest, void (*response)(void *self, void *resp, int rlen, void *cookie), void *cookie, int is_async); -#define CMD(c,s,t,m,d,l,r,k) _comm_cmd(c, s, t, m, d, l, r, k, 0) -#define CMD_ASYNC(c,s,t,m,d,l,r,k) _comm_cmd(c, s, t, m, d, l, r, k, 1) +#define CMD(c, s, t, m, d, l, r, k) _comm_cmd(c, s, t, m, d, l, r, k, 0) +#define CMD_ASYNC(c, s, t, m, d, l, r, k) _comm_cmd(c, s, t, m, d, l, r, k, 1) struct msg { void *ctx; @@ -216,8 +218,7 @@ struct cmd_steer_sta { } __attribute__((packed)); /* CMD to disconnect an STA from iface */ -struct cmd_disconnect_sta -{ +struct cmd_disconnect_sta { unsigned char hwaddr[6]; char iface[16]; } __attribute__((packed)); diff --git a/src/ipc/msgqueue.c b/src/ipc/msgqueue.c index 52c1afbe065afaf9142fedab7cecb4f7aec85e4b..729116fecbee9ecc399f2f78902f6232da688903 100644 --- a/src/ipc/msgqueue.c +++ b/src/ipc/msgqueue.c @@ -95,7 +95,7 @@ void mq_enqueue_msg(struct msg_queue *q, struct msg *m) pthread_mutex_lock(&q->lock); list_add_tail(&m->list, &q->mq); loud("After enqueue msg (%p), qlen =%d\n", - m, __mq_length(q)); + m, __mq_length(q)); pthread_mutex_unlock(&q->lock); } @@ -120,7 +120,7 @@ struct msg *mq_dequeue_msg(struct msg_queue *q) m = __mq_dequeue_msg(q); loud("After dequeue msg (%p), qlen =%d\n", - m, __mq_length(q)); + m, __mq_length(q)); pthread_mutex_unlock(&q->lock); diff --git a/src/utils/alloctrace.c b/src/utils/alloctrace.c index b91b238e2b69c31d92d2621c079ed4d12dcf251b..a4d9b72b93604639c86c76fd298f44b4bc2b8cb8 100644 --- a/src/utils/alloctrace.c +++ b/src/utils/alloctrace.c @@ -50,14 +50,12 @@ void init_alloctrace(const char *prog) } _malloc = dlsym(RTLD_NEXT, "malloc"); - if (NULL == _malloc) { + if (_malloc == NULL) fprintf(tracefile, "Error! dlsym: %s\n", dlerror()); - } _free = dlsym(RTLD_NEXT, "free"); - if (NULL == _free) { + if (_free == NULL) fprintf(tracefile, "Error! dlsym: %s\n", dlerror()); - } if (trace_alloc && tracefile) { fprintf_timestamp_prefix(tracefile); diff --git a/src/utils/alloctrace.h b/src/utils/alloctrace.h index 2480db069df6650affbc8c2ceb332d1a861a5d08..5c89c38b2ada64e217ca5cdab9790f8f07d77898 100644 --- a/src/utils/alloctrace.h +++ b/src/utils/alloctrace.h @@ -19,7 +19,8 @@ extern void init_alloctrace(const char *progname); extern void exit_alloctrace(void); extern void *dbg_malloc(size_t size, const char *by, const int lno); extern void dbg_free(void *ptr, const char *by, const int lno); -extern void *dbg_calloc(size_t nmemb, size_t size, const char *by, const int lno); +extern void *dbg_calloc(size_t nmemb, size_t size, const char *by, + const int lno); #define malloc(s) dbg_malloc(s, __func__, __LINE__) #define calloc(n, s) dbg_calloc(n, s, __func__, __LINE__) diff --git a/src/utils/debug.c b/src/utils/debug.c index 1412ad852043b265e7af310e092bbff585d8e3d0..0c3e26db97a4ee6ace9fd3c99d2879f70433e4dd 100644 --- a/src/utils/debug.c +++ b/src/utils/debug.c @@ -24,12 +24,11 @@ #include <map1905/map2.h> #include <map1905/maputils.h> -static FILE *testfile = NULL; -static FILE *outfile = NULL; static int ffd, tfd; +static FILE *outfile; +static FILE *testfile; extern const char *outfile_path; -extern const char *testfile_path = "/tmp/cntlr.test.log"; - +const char *testfile_path = "/tmp/cntlr.test.log"; extern const char *PROG_NAME; extern int verbose; extern bool syslogging; @@ -54,9 +53,11 @@ void start_logging(void) if (stat(outfile_path, &st) == -1 || !S_ISFIFO(st.st_mode)) return; - rfd = open(outfile_path, O_RDONLY | O_NONBLOCK); + rfd = open(outfile_path, + O_RDONLY | O_NONBLOCK); if (rfd) { - ffd = open(outfile_path, O_WRONLY | O_NONBLOCK); + ffd = open(outfile_path, + O_WRONLY | O_NONBLOCK); close(rfd); } } else { @@ -155,9 +156,11 @@ void start_test_logging(void) !S_ISFIFO(st.st_mode)) return; - rfd = open(testfile_path, O_RDONLY | O_NONBLOCK); + rfd = open(testfile_path, + O_RDONLY | O_NONBLOCK); if (rfd) { - tfd = open(testfile_path, O_WRONLY | O_NONBLOCK); + tfd = open(testfile_path, + O_WRONLY | O_NONBLOCK); close(rfd); } } else { @@ -197,7 +200,6 @@ void log_test(int level, void *var, int len) fprintf(testfile, "%s\n", bstr); fflush(testfile); -out: free(bstr); } diff --git a/src/utils/liblist.c b/src/utils/liblist.c index 5d885e053e256237b9a5e5f4169130a62f01d099..3286e96bb132bb962316765a346a237b47cad77a 100644 --- a/src/utils/liblist.c +++ b/src/utils/liblist.c @@ -43,7 +43,8 @@ int list_split(struct list_head *head, struct list_head *second) } void list_merge(void *priv, struct list_head *a, struct list_head *b, - int (*cmp)(void *priv, struct list_head *x, struct list_head *y)) + int (*cmp)(void *priv, + struct list_head *x, struct list_head *y)) { struct list_head *p; @@ -74,7 +75,8 @@ void list_merge(void *priv, struct list_head *a, struct list_head *b, } void merge_sort(void *priv, struct list_head *head, - int (*cmp)(void *priv, struct list_head *x, struct list_head *y)) + int (*cmp)(void *priv, + struct list_head *x, struct list_head *y)) { struct list_head right; diff --git a/src/utils/liblist.h b/src/utils/liblist.h index facbbffab48523896b3865c918013e7d95b0ed17..d5c9bc4f75e0398b0f9936e71499914f72973294 100644 --- a/src/utils/liblist.h +++ b/src/utils/liblist.h @@ -29,7 +29,8 @@ int list_split(struct list_head *head, struct list_head *second); * between two list elements during the merge */ void list_merge(void *priv, struct list_head *a, struct list_head *b, - int (*cmp)(void *priv, struct list_head *x, struct list_head *y)); + int (*cmp)(void *priv, + struct list_head *x, struct list_head *y)); /** * merge_sort - merge sort a list. @@ -39,7 +40,8 @@ void list_merge(void *priv, struct list_head *a, struct list_head *b, * between two list elements during the sort. */ void merge_sort(void *priv, struct list_head *head, - int (*cmp)(void *priv, struct list_head *x, struct list_head *y)); + int (*cmp)(void *priv, + struct list_head *x, struct list_head *y)); #ifndef list_sort #define list_sort merge_sort diff --git a/src/utils/utils.c b/src/utils/utils.c index 565b8a1f929100d4f3466f400e106c9e5fd128eb..58c29014609eb0c340fffa92112c92f89c8cd7bf 100644 --- a/src/utils/utils.c +++ b/src/utils/utils.c @@ -49,6 +49,7 @@ static int hex2num(char c) int hex2byte(const char *hex) { int a, b; + a = hex2num(*hex++); if (a < 0) return -1; @@ -194,7 +195,8 @@ int timestamp_expired(struct timespec *a, unsigned int tmo_ms) int list_dup(struct list_head *h, struct list_head *new, void *(*alloc_entry)(void), void (*free_entry)(struct list_head *n), - void (*copy_entry)(struct list_head *from, struct list_head *to)) + void (*copy_entry)(struct list_head *from, + struct list_head *to)) { struct list_head *p, *tmp, *n; @@ -233,8 +235,10 @@ rollback_list_dup: */ int list_join_uniq_strict(void *priv, struct list_head *a, struct list_head *b, struct list_head *out, - int (*match)(void *priv, struct list_head *a, struct list_head *b), - struct list_head *(*create_entry)(void *priv, struct list_head *a, struct list_head *b), + int (*match)(void *priv, + struct list_head *a, struct list_head *b), + struct list_head *(*create_entry)(void *priv, + struct list_head *a, struct list_head *b), void (*free_entry)(void *priv, struct list_head *a)) { struct list_head *p, *q, *t1, *t2, *n; @@ -276,17 +280,19 @@ err_list_join_uniq: list_del(p); free_entry(priv, p); } + return -1; } int list_join_uniq(void *priv, struct list_head *a, struct list_head *b, struct list_head *out, - int (*match)(void *priv, struct list_head *a, struct list_head *b), - struct list_head *(*create_jentry)(void *priv, struct list_head *a, struct list_head *b), + int (*match)(void *priv, struct list_head *a, + struct list_head *b), + struct list_head *(*create_jentry)(void *priv, + struct list_head *a, struct list_head *b), void (*free_jentry)(void *priv, struct list_head *), void (*free_entry_a)(struct list_head *), - void (*free_entry_b)(struct list_head *) - ) + void (*free_entry_b)(struct list_head *)) { struct list_head *p, *q, *t1, *t2, *n; diff --git a/src/utils/utils.h b/src/utils/utils.h index 200bf64cea785e4f09c8684b14b75bfeb6dd20b2..9fdc45e2917b7cf369e00c523dc9659af304fded 100644 --- a/src/utils/utils.h +++ b/src/utils/utils.h @@ -25,19 +25,20 @@ #endif #ifndef MAC2STR -#define MAC2STR(_m) (_m)[0], (_m)[1], (_m)[2], (_m)[3], (_m)[4], (_m)[5] +#define MAC2STR(_m) ((_m)[0], (_m)[1], (_m)[2], (_m)[3], (_m)[4], (_m)[5]) #endif #define print_bits(x, len, s) \ do { \ - unsigned long long a__ = (x); \ - size_t bits__ = sizeof(x) * len; \ - while(bits__--) { \ - putchar(a__ & (1 << bits__) ? '1' : '0'); \ - if (!(bits__ % s)) putchar(' '); \ + unsigned long long a__ = (x); \ + size_t bits__ = sizeof(x) * len; \ + while (bits__--) { \ + putchar(a__ & (1 << bits__) ? '1' : '0'); \ + if (!(bits__ % s)) \ + putchar(' '); \ } \ - putchar('\n'); \ -} while(0) + putchar('\n'); \ +} while (0) bool match_oui0(unsigned char *oui, unsigned char *hwaddr, int ouis); unsigned char *hwaddr_aton(const char *macstr, unsigned char *mac); @@ -155,8 +156,10 @@ do { \ int list_join_uniq(void *priv, struct list_head *a, struct list_head *b, struct list_head *out, - int (*match)(void *priv, struct list_head *a, struct list_head *b), - struct list_head *(*create_jentry)(void *priv, struct list_head *a, struct list_head *b), + int (*match)(void *priv, struct list_head *a, + struct list_head *b), + struct list_head *(*create_jentry)(void *priv, + struct list_head *a, struct list_head *b), void (*free_jentry)(void *priv, struct list_head *), void (*free_entry_a)(struct list_head *), void (*free_entry_b)(struct list_head *)); @@ -165,7 +168,8 @@ int list_join_uniq(void *priv, struct list_head *a, struct list_head *b, int list_dup(struct list_head *h, struct list_head *new, void *(*alloc_entry)(void), void (*free_entry)(struct list_head *n), - void (*copy_entry)(struct list_head *from, struct list_head *to)); + void (*copy_entry)(struct list_head *from, + struct list_head *to)); int set_sighandler(int sig, void (*handler)(int)); diff --git a/test/cmocka/test_utils.c b/test/cmocka/test_utils.c index cf41e5926e0eda497464ef722dbe40a980698d02..da0239097dc9720931fd9a489fa6635b720935e3 100644 --- a/test/cmocka/test_utils.c +++ b/test/cmocka/test_utils.c @@ -6,38 +6,38 @@ int compare_files(char *file1, char *file2) { - char ch1, ch2; - int error = 0, pos = 0, line = 1; - FILE *fp1; - FILE *fp2; + char ch1, ch2; + int error = 0, pos = 0, line = 1; + FILE *fp1; + FILE *fp2; - fp1 = fopen(file1, "r"); - if (!fp1) - return -1; + fp1 = fopen(file1, "r"); + if (!fp1) + return -1; - fp2 = fopen(file2, "r"); - if (!fp2) - return -1; + fp2 = fopen(file2, "r"); + if (!fp2) + return -1; - ch1 = getc(fp1); - ch2 = getc(fp2); + ch1 = getc(fp1); + ch2 = getc(fp2); - while (ch1 != EOF && ch2 != EOF) { - pos++; + while (ch1 != EOF && ch2 != EOF) { + pos++; - if (ch1 == '\n' && ch2 == '\n') { - line++; - pos = 0; - } + if (ch1 == '\n' && ch2 == '\n') { + line++; + pos = 0; + } - if (ch1 != ch2) - return -1; + if (ch1 != ch2) + return -1; - ch1 = getc(fp1); - ch2 = getc(fp2); - } + ch1 = getc(fp1); + ch2 = getc(fp2); + } - fclose(file1); - fclose(file2); - return 0; + fclose(file1); + fclose(file2); + return 0; }