|
| 1 | +diff --git a/net/respondd-module-airtime/src/airtime.c b/net/respondd-module-airtime/src/airtime.c |
| 2 | +index 7e27ee0..9af51ad 100644 |
| 3 | +--- a/net/respondd-module-airtime/src/airtime.c |
| 4 | ++++ b/net/respondd-module-airtime/src/airtime.c |
| 5 | +@@ -57,7 +57,7 @@ |
| 6 | + * @__NL80211_SURVEY_INFO_AFTER_LAST: internal use |
| 7 | + */ |
| 8 | + |
| 9 | +-static const char const* msg_names[NL80211_SURVEY_INFO_MAX + 1] = { |
| 10 | ++static const char *const msg_names[NL80211_SURVEY_INFO_MAX + 1] = { |
| 11 | + [NL80211_SURVEY_INFO_FREQUENCY] = "frequency", |
| 12 | + [NL80211_SURVEY_INFO_CHANNEL_TIME] = "active", |
| 13 | + [NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY] = "busy", |
| 14 | +@@ -67,20 +67,26 @@ static const char const* msg_names[NL80211_SURVEY_INFO_MAX + 1] = { |
| 15 | + }; |
| 16 | + |
| 17 | + static int survey_airtime_handler(struct nl_msg *msg, void *arg) { |
| 18 | +- struct json_object *parent_json = (struct json_object *) arg; |
| 19 | ++ struct json_object **result = arg; |
| 20 | ++ struct json_object *freq_json = NULL; |
| 21 | + |
| 22 | + struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg)); |
| 23 | + struct nlattr *survey_info = nla_find(genlmsg_attrdata(gnlh, 0), genlmsg_attrlen(gnlh, 0), NL80211_ATTR_SURVEY_INFO); |
| 24 | + |
| 25 | ++ if (*result) { |
| 26 | ++ fprintf(stderr, "respondd-module-airtime: callback called again after NL_STOP\n"); |
| 27 | ++ return NL_STOP; |
| 28 | ++ } |
| 29 | ++ |
| 30 | + if (!survey_info) { |
| 31 | + fprintf(stderr, "respondd-module-airtime: survey data missing in netlink message\n"); |
| 32 | +- goto abort; |
| 33 | ++ return NL_STOP; |
| 34 | + } |
| 35 | + |
| 36 | +- struct json_object *freq_json = json_object_new_object(); |
| 37 | ++ freq_json = json_object_new_object(); |
| 38 | + if (!freq_json) { |
| 39 | + fprintf(stderr, "respondd-module-airtime: failed allocating JSON object\n"); |
| 40 | +- goto abort; |
| 41 | ++ return NL_STOP; |
| 42 | + } |
| 43 | + |
| 44 | + // This variable counts the number of required attributes that are |
| 45 | +@@ -129,15 +135,19 @@ static int survey_airtime_handler(struct nl_msg *msg, void *arg) { |
| 46 | + json_object_object_add(freq_json, msg_names[type], data_json); |
| 47 | + } |
| 48 | + |
| 49 | +- if (req_fields == 3) |
| 50 | +- json_object_array_add(parent_json, freq_json); |
| 51 | +- else |
| 52 | ++ /* The kernel didn't report all required fields: continue with next |
| 53 | ++ * record, this entry was off-channel */ |
| 54 | ++ if (req_fields != 3) { |
| 55 | + json_object_put(freq_json); |
| 56 | ++ return NL_OK; |
| 57 | ++ } |
| 58 | + |
| 59 | +-abort: |
| 60 | +- return NL_SKIP; |
| 61 | ++ *result = freq_json; |
| 62 | ++ return NL_STOP; |
| 63 | + } |
| 64 | + |
| 65 | +-bool get_airtime(struct json_object *result, int ifx) { |
| 66 | +- return nl_send_dump(survey_airtime_handler, result, NL80211_CMD_GET_SURVEY, ifx); |
| 67 | ++struct json_object * get_airtime(int ifx) { |
| 68 | ++ struct json_object *result = NULL; |
| 69 | ++ nl_send_dump(survey_airtime_handler, &result, NL80211_CMD_GET_SURVEY, ifx); |
| 70 | ++ return result; |
| 71 | + } |
| 72 | +diff --git a/net/respondd-module-airtime/src/airtime.h b/net/respondd-module-airtime/src/airtime.h |
| 73 | +index 7adc91e..7db21ec 100644 |
| 74 | +--- a/net/respondd-module-airtime/src/airtime.h |
| 75 | ++++ b/net/respondd-module-airtime/src/airtime.h |
| 76 | +@@ -4,4 +4,5 @@ |
| 77 | + #include <stdint.h> |
| 78 | + #include <json-c/json.h> |
| 79 | + |
| 80 | +-__attribute__((visibility("hidden"))) bool get_airtime(struct json_object *result, int ifx); |
| 81 | ++__attribute__((visibility("hidden"))) |
| 82 | ++struct json_object * get_airtime(int ifx); |
| 83 | +diff --git a/net/respondd-module-airtime/src/netlink.c b/net/respondd-module-airtime/src/netlink.c |
| 84 | +index 2030193..4d12833 100644 |
| 85 | +--- a/net/respondd-module-airtime/src/netlink.c |
| 86 | ++++ b/net/respondd-module-airtime/src/netlink.c |
| 87 | +@@ -37,7 +37,7 @@ bool nl_send_dump(nl_recvmsg_msg_cb_t cb, void *cb_arg, int cmd, uint32_t cmd_ar |
| 88 | + ERR("nlmsg_alloc() failed\n"); |
| 89 | + |
| 90 | + if (!genlmsg_put(msg, 0, 0, ctrl, 0, NLM_F_DUMP, cmd, 0)) |
| 91 | +- ERR("genlmsg_put() failed while putting cmd %d\n", ret, cmd); |
| 92 | ++ ERR("genlmsg_put() failed while putting cmd %d\n", cmd); |
| 93 | + |
| 94 | + if (cmd_arg != 0) |
| 95 | + NLA_PUT_U32(msg, NL80211_ATTR_IFINDEX, cmd_arg); |
| 96 | +diff --git a/net/respondd-module-airtime/src/respondd.c b/net/respondd-module-airtime/src/respondd.c |
| 97 | +index eaf8182..8f73d68 100644 |
| 98 | +--- a/net/respondd-module-airtime/src/respondd.c |
| 99 | ++++ b/net/respondd-module-airtime/src/respondd.c |
| 100 | +@@ -7,9 +7,7 @@ |
| 101 | + #include "ifaces.h" |
| 102 | + |
| 103 | + static struct json_object *respondd_provider_statistics(void) { |
| 104 | +- bool ok; |
| 105 | +- int newest_element_index; |
| 106 | +- struct json_object *last, *result, *wireless; |
| 107 | ++ struct json_object *result, *wireless; |
| 108 | + struct iface_list *ifaces; |
| 109 | + |
| 110 | + result = json_object_new_object(); |
| 111 | +@@ -24,13 +22,9 @@ static struct json_object *respondd_provider_statistics(void) { |
| 112 | + |
| 113 | + ifaces = get_ifaces(); |
| 114 | + while (ifaces != NULL) { |
| 115 | +- ok = get_airtime(wireless, ifaces->ifx); |
| 116 | +- if (ok) { |
| 117 | +- newest_element_index = json_object_array_length(wireless) - 1; |
| 118 | +- last = json_object_array_get_idx(wireless, newest_element_index); |
| 119 | +- if (last) |
| 120 | +- json_object_object_add(last, "phy", json_object_new_int(ifaces->wiphy)); |
| 121 | +- } |
| 122 | ++ struct json_object *entry = get_airtime(ifaces->ifx); |
| 123 | ++ if (entry) |
| 124 | ++ json_object_array_add(wireless, entry); |
| 125 | + void *freeptr = ifaces; |
| 126 | + ifaces = ifaces->next; |
| 127 | + free(freeptr); |
0 commit comments