| .. | .. |
|---|
| 1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
|---|
| 2 | | -/* Copyright (C) 2011-2018 B.A.T.M.A.N. contributors: |
|---|
| 2 | +/* Copyright (C) 2011-2020 B.A.T.M.A.N. contributors: |
|---|
| 3 | 3 | * |
|---|
| 4 | 4 | * Linus Lüssing, Marek Lindner |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or |
|---|
| 7 | | - * modify it under the terms of version 2 of the GNU General Public |
|---|
| 8 | | - * License as published by the Free Software Foundation. |
|---|
| 9 | | - * |
|---|
| 10 | | - * This program is distributed in the hope that it will be useful, but |
|---|
| 11 | | - * WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|---|
| 13 | | - * General Public License for more details. |
|---|
| 14 | | - * |
|---|
| 15 | | - * You should have received a copy of the GNU General Public License |
|---|
| 16 | | - * along with this program; if not, see <http://www.gnu.org/licenses/>. |
|---|
| 17 | 5 | */ |
|---|
| 18 | 6 | |
|---|
| 19 | 7 | #include "bat_v_elp.h" |
|---|
| .. | .. |
|---|
| 32 | 20 | #include <linux/kref.h> |
|---|
| 33 | 21 | #include <linux/netdevice.h> |
|---|
| 34 | 22 | #include <linux/nl80211.h> |
|---|
| 23 | +#include <linux/prandom.h> |
|---|
| 35 | 24 | #include <linux/random.h> |
|---|
| 36 | 25 | #include <linux/rculist.h> |
|---|
| 37 | 26 | #include <linux/rcupdate.h> |
|---|
| .. | .. |
|---|
| 61 | 50 | unsigned int msecs; |
|---|
| 62 | 51 | |
|---|
| 63 | 52 | msecs = atomic_read(&hard_iface->bat_v.elp_interval) - BATADV_JITTER; |
|---|
| 64 | | - msecs += prandom_u32() % (2 * BATADV_JITTER); |
|---|
| 53 | + msecs += prandom_u32_max(2 * BATADV_JITTER); |
|---|
| 65 | 54 | |
|---|
| 66 | 55 | queue_delayed_work(batadv_event_workqueue, &hard_iface->bat_v.elp_wq, |
|---|
| 67 | 56 | msecs_to_jiffies(msecs)); |
|---|
| .. | .. |
|---|
| 72 | 61 | * @neigh: the neighbour for which the throughput has to be obtained |
|---|
| 73 | 62 | * |
|---|
| 74 | 63 | * Return: The throughput towards the given neighbour in multiples of 100kpbs |
|---|
| 75 | | - * (a value of '1' equals to 0.1Mbps, '10' equals 1Mbps, etc). |
|---|
| 64 | + * (a value of '1' equals 0.1Mbps, '10' equals 1Mbps, etc). |
|---|
| 76 | 65 | */ |
|---|
| 77 | 66 | static u32 batadv_v_elp_get_throughput(struct batadv_hardif_neigh_node *neigh) |
|---|
| 78 | 67 | { |
|---|
| .. | .. |
|---|
| 119 | 108 | } |
|---|
| 120 | 109 | if (ret) |
|---|
| 121 | 110 | goto default_throughput; |
|---|
| 122 | | - if (!(sinfo.filled & BIT(NL80211_STA_INFO_EXPECTED_THROUGHPUT))) |
|---|
| 123 | | - goto default_throughput; |
|---|
| 124 | 111 | |
|---|
| 125 | | - return sinfo.expected_throughput / 100; |
|---|
| 112 | + if (sinfo.filled & BIT(NL80211_STA_INFO_EXPECTED_THROUGHPUT)) |
|---|
| 113 | + return sinfo.expected_throughput / 100; |
|---|
| 114 | + |
|---|
| 115 | + /* try to estimate the expected throughput based on reported tx |
|---|
| 116 | + * rates |
|---|
| 117 | + */ |
|---|
| 118 | + if (sinfo.filled & BIT(NL80211_STA_INFO_TX_BITRATE)) |
|---|
| 119 | + return cfg80211_calculate_bitrate(&sinfo.txrate) / 3; |
|---|
| 120 | + |
|---|
| 121 | + goto default_throughput; |
|---|
| 126 | 122 | } |
|---|
| 127 | 123 | |
|---|
| 128 | 124 | /* if not a wifi interface, check if this device provides data via |
|---|
| .. | .. |
|---|
| 188 | 184 | * |
|---|
| 189 | 185 | * Sends a predefined number of unicast wifi packets to a given neighbour in |
|---|
| 190 | 186 | * order to trigger the throughput estimation on this link by the RC algorithm. |
|---|
| 191 | | - * Packets are sent only if there there is not enough payload unicast traffic |
|---|
| 192 | | - * towards this neighbour.. |
|---|
| 187 | + * Packets are sent only if there is not enough payload unicast traffic towards |
|---|
| 188 | + * this neighbour.. |
|---|
| 193 | 189 | * |
|---|
| 194 | 190 | * Return: True on success and false in case of error during skb preparation. |
|---|
| 195 | 191 | */ |
|---|
| .. | .. |
|---|
| 249 | 245 | * batadv_v_elp_periodic_work() - ELP periodic task per interface |
|---|
| 250 | 246 | * @work: work queue item |
|---|
| 251 | 247 | * |
|---|
| 252 | | - * Emits broadcast ELP message in regular intervals. |
|---|
| 248 | + * Emits broadcast ELP messages in regular intervals. |
|---|
| 253 | 249 | */ |
|---|
| 254 | 250 | static void batadv_v_elp_periodic_work(struct work_struct *work) |
|---|
| 255 | 251 | { |
|---|
| .. | .. |
|---|
| 504 | 500 | * @skb: the received packet |
|---|
| 505 | 501 | * @if_incoming: the interface this packet was received through |
|---|
| 506 | 502 | * |
|---|
| 507 | | - * Return: NET_RX_SUCCESS and consumes the skb if the packet was peoperly |
|---|
| 503 | + * Return: NET_RX_SUCCESS and consumes the skb if the packet was properly |
|---|
| 508 | 504 | * processed or NET_RX_DROP in case of failure. |
|---|
| 509 | 505 | */ |
|---|
| 510 | 506 | int batadv_v_elp_packet_recv(struct sk_buff *skb, |
|---|