blob: 3ba057d935218b73ebcf211261d094be57a71226 [file] [log] [blame]
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00001/*
Sven Eckelmann567db7b2012-01-01 00:41:38 +01002 * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00003 *
4 * Marek Lindner, Simon Wunderlich
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, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA
19 *
20 */
21
22#include "main.h"
23#include "soft-interface.h"
24#include "hard-interface.h"
25#include "routing.h"
26#include "send.h"
27#include "bat_debugfs.h"
28#include "translation-table.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000029#include "hash.h"
30#include "gateway_common.h"
31#include "gateway_client.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000032#include "bat_sysfs.h"
Antonio Quartulli43676ab2011-04-26 21:31:45 +020033#include "originator.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000034#include <linux/slab.h>
35#include <linux/ethtool.h>
36#include <linux/etherdevice.h>
37#include <linux/if_vlan.h>
38#include "unicast.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000039
40
41static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd);
42static void bat_get_drvinfo(struct net_device *dev,
43 struct ethtool_drvinfo *info);
44static u32 bat_get_msglevel(struct net_device *dev);
45static void bat_set_msglevel(struct net_device *dev, u32 value);
46static u32 bat_get_link(struct net_device *dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000047
48static const struct ethtool_ops bat_ethtool_ops = {
49 .get_settings = bat_get_settings,
50 .get_drvinfo = bat_get_drvinfo,
51 .get_msglevel = bat_get_msglevel,
52 .set_msglevel = bat_set_msglevel,
53 .get_link = bat_get_link,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000054};
55
56int my_skb_head_push(struct sk_buff *skb, unsigned int len)
57{
58 int result;
59
60 /**
61 * TODO: We must check if we can release all references to non-payload
62 * data using skb_header_release in our skbs to allow skb_cow_header to
63 * work optimally. This means that those skbs are not allowed to read
64 * or write any data which is before the current position of skb->data
65 * after that call and thus allow other skbs with the same data buffer
66 * to write freely in that area.
67 */
68 result = skb_cow_head(skb, len);
69 if (result < 0)
70 return result;
71
72 skb_push(skb, len);
73 return 0;
74}
75
Marek Lindner7d2b5542011-02-10 14:33:50 +000076static void softif_neigh_free_ref(struct softif_neigh *softif_neigh)
77{
78 if (atomic_dec_and_test(&softif_neigh->refcount))
Paul E. McKenney8e3572c2011-05-02 00:52:23 -070079 kfree_rcu(softif_neigh, rcu);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000080}
81
Marek Lindner61906ae2011-04-21 15:52:17 +020082static void softif_neigh_vid_free_rcu(struct rcu_head *rcu)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000083{
Marek Lindner61906ae2011-04-21 15:52:17 +020084 struct softif_neigh_vid *softif_neigh_vid;
85 struct softif_neigh *softif_neigh;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000086 struct hlist_node *node, *node_tmp;
Marek Lindner61906ae2011-04-21 15:52:17 +020087 struct bat_priv *bat_priv;
Simon Wunderlichba85fac2011-04-17 20:34:27 +020088
Marek Lindner61906ae2011-04-21 15:52:17 +020089 softif_neigh_vid = container_of(rcu, struct softif_neigh_vid, rcu);
90 bat_priv = softif_neigh_vid->bat_priv;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000091
92 spin_lock_bh(&bat_priv->softif_neigh_lock);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000093 hlist_for_each_entry_safe(softif_neigh, node, node_tmp,
Marek Lindner61906ae2011-04-21 15:52:17 +020094 &softif_neigh_vid->softif_neigh_list, list) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000095 hlist_del_rcu(&softif_neigh->list);
Marek Lindner7d2b5542011-02-10 14:33:50 +000096 softif_neigh_free_ref(softif_neigh);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000097 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000098 spin_unlock_bh(&bat_priv->softif_neigh_lock);
Simon Wunderlichba85fac2011-04-17 20:34:27 +020099
Marek Lindner61906ae2011-04-21 15:52:17 +0200100 kfree(softif_neigh_vid);
101}
Simon Wunderlichba85fac2011-04-17 20:34:27 +0200102
Marek Lindner61906ae2011-04-21 15:52:17 +0200103static void softif_neigh_vid_free_ref(struct softif_neigh_vid *softif_neigh_vid)
104{
105 if (atomic_dec_and_test(&softif_neigh_vid->refcount))
106 call_rcu(&softif_neigh_vid->rcu, softif_neigh_vid_free_rcu);
107}
108
109static struct softif_neigh_vid *softif_neigh_vid_get(struct bat_priv *bat_priv,
110 short vid)
111{
112 struct softif_neigh_vid *softif_neigh_vid;
113 struct hlist_node *node;
114
115 rcu_read_lock();
116 hlist_for_each_entry_rcu(softif_neigh_vid, node,
117 &bat_priv->softif_neigh_vids, list) {
118 if (softif_neigh_vid->vid != vid)
119 continue;
120
121 if (!atomic_inc_not_zero(&softif_neigh_vid->refcount))
122 continue;
123
124 goto out;
125 }
126
Sven Eckelmann704509b2011-05-14 23:14:54 +0200127 softif_neigh_vid = kzalloc(sizeof(*softif_neigh_vid), GFP_ATOMIC);
Marek Lindner61906ae2011-04-21 15:52:17 +0200128 if (!softif_neigh_vid)
129 goto out;
130
131 softif_neigh_vid->vid = vid;
132 softif_neigh_vid->bat_priv = bat_priv;
133
134 /* initialize with 2 - caller decrements counter by one */
135 atomic_set(&softif_neigh_vid->refcount, 2);
136 INIT_HLIST_HEAD(&softif_neigh_vid->softif_neigh_list);
137 INIT_HLIST_NODE(&softif_neigh_vid->list);
138 spin_lock_bh(&bat_priv->softif_neigh_vid_lock);
139 hlist_add_head_rcu(&softif_neigh_vid->list,
140 &bat_priv->softif_neigh_vids);
141 spin_unlock_bh(&bat_priv->softif_neigh_vid_lock);
142
143out:
144 rcu_read_unlock();
145 return softif_neigh_vid;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000146}
147
148static struct softif_neigh *softif_neigh_get(struct bat_priv *bat_priv,
Sven Eckelmann747e4222011-05-14 23:14:50 +0200149 const uint8_t *addr, short vid)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000150{
Marek Lindner61906ae2011-04-21 15:52:17 +0200151 struct softif_neigh_vid *softif_neigh_vid;
152 struct softif_neigh *softif_neigh = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000153 struct hlist_node *node;
154
Marek Lindner61906ae2011-04-21 15:52:17 +0200155 softif_neigh_vid = softif_neigh_vid_get(bat_priv, vid);
156 if (!softif_neigh_vid)
157 goto out;
158
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000159 rcu_read_lock();
160 hlist_for_each_entry_rcu(softif_neigh, node,
Marek Lindner61906ae2011-04-21 15:52:17 +0200161 &softif_neigh_vid->softif_neigh_list,
162 list) {
Marek Lindner39901e72011-02-18 12:28:08 +0000163 if (!compare_eth(softif_neigh->addr, addr))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000164 continue;
165
Marek Lindner7d2b5542011-02-10 14:33:50 +0000166 if (!atomic_inc_not_zero(&softif_neigh->refcount))
167 continue;
168
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000169 softif_neigh->last_seen = jiffies;
Marek Lindner61906ae2011-04-21 15:52:17 +0200170 goto unlock;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000171 }
172
Sven Eckelmann704509b2011-05-14 23:14:54 +0200173 softif_neigh = kzalloc(sizeof(*softif_neigh), GFP_ATOMIC);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000174 if (!softif_neigh)
Marek Lindner61906ae2011-04-21 15:52:17 +0200175 goto unlock;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000176
177 memcpy(softif_neigh->addr, addr, ETH_ALEN);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000178 softif_neigh->last_seen = jiffies;
Marek Lindner7d2b5542011-02-10 14:33:50 +0000179 /* initialize with 2 - caller decrements counter by one */
180 atomic_set(&softif_neigh->refcount, 2);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000181
182 INIT_HLIST_NODE(&softif_neigh->list);
183 spin_lock_bh(&bat_priv->softif_neigh_lock);
Marek Lindner61906ae2011-04-21 15:52:17 +0200184 hlist_add_head_rcu(&softif_neigh->list,
185 &softif_neigh_vid->softif_neigh_list);
186 spin_unlock_bh(&bat_priv->softif_neigh_lock);
187
188unlock:
189 rcu_read_unlock();
190out:
191 if (softif_neigh_vid)
192 softif_neigh_vid_free_ref(softif_neigh_vid);
193 return softif_neigh;
194}
195
196static struct softif_neigh *softif_neigh_get_selected(
197 struct softif_neigh_vid *softif_neigh_vid)
198{
199 struct softif_neigh *softif_neigh;
200
201 rcu_read_lock();
202 softif_neigh = rcu_dereference(softif_neigh_vid->softif_neigh);
203
204 if (softif_neigh && !atomic_inc_not_zero(&softif_neigh->refcount))
205 softif_neigh = NULL;
206
207 rcu_read_unlock();
208 return softif_neigh;
209}
210
211static struct softif_neigh *softif_neigh_vid_get_selected(
212 struct bat_priv *bat_priv,
213 short vid)
214{
215 struct softif_neigh_vid *softif_neigh_vid;
216 struct softif_neigh *softif_neigh = NULL;
217
218 softif_neigh_vid = softif_neigh_vid_get(bat_priv, vid);
219 if (!softif_neigh_vid)
220 goto out;
221
222 softif_neigh = softif_neigh_get_selected(softif_neigh_vid);
223out:
224 if (softif_neigh_vid)
225 softif_neigh_vid_free_ref(softif_neigh_vid);
226 return softif_neigh;
227}
228
229static void softif_neigh_vid_select(struct bat_priv *bat_priv,
230 struct softif_neigh *new_neigh,
231 short vid)
232{
233 struct softif_neigh_vid *softif_neigh_vid;
234 struct softif_neigh *curr_neigh;
235
236 softif_neigh_vid = softif_neigh_vid_get(bat_priv, vid);
237 if (!softif_neigh_vid)
238 goto out;
239
240 spin_lock_bh(&bat_priv->softif_neigh_lock);
241
242 if (new_neigh && !atomic_inc_not_zero(&new_neigh->refcount))
243 new_neigh = NULL;
244
Sven Eckelmann728cbc62011-05-15 00:50:21 +0200245 curr_neigh = rcu_dereference_protected(softif_neigh_vid->softif_neigh,
246 1);
Marek Lindner61906ae2011-04-21 15:52:17 +0200247 rcu_assign_pointer(softif_neigh_vid->softif_neigh, new_neigh);
248
249 if ((curr_neigh) && (!new_neigh))
250 bat_dbg(DBG_ROUTES, bat_priv,
251 "Removing mesh exit point on vid: %d (prev: %pM).\n",
252 vid, curr_neigh->addr);
253 else if ((curr_neigh) && (new_neigh))
254 bat_dbg(DBG_ROUTES, bat_priv,
Sven Eckelmann86ceb362012-03-07 09:07:45 +0100255 "Changing mesh exit point on vid: %d from %pM to %pM.\n",
256 vid, curr_neigh->addr, new_neigh->addr);
Marek Lindner61906ae2011-04-21 15:52:17 +0200257 else if ((!curr_neigh) && (new_neigh))
258 bat_dbg(DBG_ROUTES, bat_priv,
259 "Setting mesh exit point on vid: %d to %pM.\n",
260 vid, new_neigh->addr);
261
262 if (curr_neigh)
263 softif_neigh_free_ref(curr_neigh);
264
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000265 spin_unlock_bh(&bat_priv->softif_neigh_lock);
266
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000267out:
Marek Lindner61906ae2011-04-21 15:52:17 +0200268 if (softif_neigh_vid)
269 softif_neigh_vid_free_ref(softif_neigh_vid);
270}
271
272static void softif_neigh_vid_deselect(struct bat_priv *bat_priv,
273 struct softif_neigh_vid *softif_neigh_vid)
274{
275 struct softif_neigh *curr_neigh;
276 struct softif_neigh *softif_neigh = NULL, *softif_neigh_tmp;
277 struct hard_iface *primary_if = NULL;
278 struct hlist_node *node;
279
280 primary_if = primary_if_get_selected(bat_priv);
281 if (!primary_if)
282 goto out;
283
284 /* find new softif_neigh immediately to avoid temporary loops */
285 rcu_read_lock();
286 curr_neigh = rcu_dereference(softif_neigh_vid->softif_neigh);
287
288 hlist_for_each_entry_rcu(softif_neigh_tmp, node,
289 &softif_neigh_vid->softif_neigh_list,
290 list) {
291 if (softif_neigh_tmp == curr_neigh)
292 continue;
293
294 /* we got a neighbor but its mac is 'bigger' than ours */
295 if (memcmp(primary_if->net_dev->dev_addr,
296 softif_neigh_tmp->addr, ETH_ALEN) < 0)
297 continue;
298
299 if (!atomic_inc_not_zero(&softif_neigh_tmp->refcount))
300 continue;
301
302 softif_neigh = softif_neigh_tmp;
303 goto unlock;
304 }
305
306unlock:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000307 rcu_read_unlock();
Marek Lindner61906ae2011-04-21 15:52:17 +0200308out:
309 softif_neigh_vid_select(bat_priv, softif_neigh, softif_neigh_vid->vid);
310
311 if (primary_if)
312 hardif_free_ref(primary_if);
313 if (softif_neigh)
314 softif_neigh_free_ref(softif_neigh);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000315}
316
317int softif_neigh_seq_print_text(struct seq_file *seq, void *offset)
318{
319 struct net_device *net_dev = (struct net_device *)seq->private;
320 struct bat_priv *bat_priv = netdev_priv(net_dev);
Marek Lindner61906ae2011-04-21 15:52:17 +0200321 struct softif_neigh_vid *softif_neigh_vid;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000322 struct softif_neigh *softif_neigh;
Marek Lindner32ae9b22011-04-20 15:40:58 +0200323 struct hard_iface *primary_if;
Marek Lindner61906ae2011-04-21 15:52:17 +0200324 struct hlist_node *node, *node_tmp;
Simon Wunderlichba85fac2011-04-17 20:34:27 +0200325 struct softif_neigh *curr_softif_neigh;
Marek Lindner61906ae2011-04-21 15:52:17 +0200326 int ret = 0, last_seen_secs, last_seen_msecs;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000327
Marek Lindner32ae9b22011-04-20 15:40:58 +0200328 primary_if = primary_if_get_selected(bat_priv);
329 if (!primary_if) {
Sven Eckelmann86ceb362012-03-07 09:07:45 +0100330 ret = seq_printf(seq,
331 "BATMAN mesh %s disabled - please specify interfaces to enable it\n",
Marek Lindner32ae9b22011-04-20 15:40:58 +0200332 net_dev->name);
333 goto out;
334 }
335
336 if (primary_if->if_status != IF_ACTIVE) {
Sven Eckelmann86ceb362012-03-07 09:07:45 +0100337 ret = seq_printf(seq,
338 "BATMAN mesh %s disabled - primary interface not active\n",
Marek Lindner32ae9b22011-04-20 15:40:58 +0200339 net_dev->name);
340 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000341 }
342
343 seq_printf(seq, "Softif neighbor list (%s)\n", net_dev->name);
344
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000345 rcu_read_lock();
Marek Lindner61906ae2011-04-21 15:52:17 +0200346 hlist_for_each_entry_rcu(softif_neigh_vid, node,
347 &bat_priv->softif_neigh_vids, list) {
348 seq_printf(seq, " %-15s %s on vid: %d\n",
349 "Originator", "last-seen", softif_neigh_vid->vid);
350
351 curr_softif_neigh = softif_neigh_get_selected(softif_neigh_vid);
352
353 hlist_for_each_entry_rcu(softif_neigh, node_tmp,
354 &softif_neigh_vid->softif_neigh_list,
355 list) {
356 last_seen_secs = jiffies_to_msecs(jiffies -
357 softif_neigh->last_seen) / 1000;
358 last_seen_msecs = jiffies_to_msecs(jiffies -
359 softif_neigh->last_seen) % 1000;
360 seq_printf(seq, "%s %pM %3i.%03is\n",
361 curr_softif_neigh == softif_neigh
362 ? "=>" : " ", softif_neigh->addr,
363 last_seen_secs, last_seen_msecs);
364 }
365
366 if (curr_softif_neigh)
367 softif_neigh_free_ref(curr_softif_neigh);
368
369 seq_printf(seq, "\n");
370 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000371 rcu_read_unlock();
372
Marek Lindner32ae9b22011-04-20 15:40:58 +0200373out:
374 if (primary_if)
375 hardif_free_ref(primary_if);
376 return ret;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000377}
378
Marek Lindner61906ae2011-04-21 15:52:17 +0200379void softif_neigh_purge(struct bat_priv *bat_priv)
380{
381 struct softif_neigh *softif_neigh, *curr_softif_neigh;
382 struct softif_neigh_vid *softif_neigh_vid;
383 struct hlist_node *node, *node_tmp, *node_tmp2;
Sven Eckelmannb4e17052011-06-15 09:41:37 +0200384 int do_deselect;
Marek Lindner61906ae2011-04-21 15:52:17 +0200385
386 rcu_read_lock();
387 hlist_for_each_entry_rcu(softif_neigh_vid, node,
388 &bat_priv->softif_neigh_vids, list) {
389 if (!atomic_inc_not_zero(&softif_neigh_vid->refcount))
390 continue;
391
392 curr_softif_neigh = softif_neigh_get_selected(softif_neigh_vid);
393 do_deselect = 0;
394
395 spin_lock_bh(&bat_priv->softif_neigh_lock);
396 hlist_for_each_entry_safe(softif_neigh, node_tmp, node_tmp2,
397 &softif_neigh_vid->softif_neigh_list,
398 list) {
Marek Lindner032b7962011-12-20 19:30:40 +0800399 if ((!has_timed_out(softif_neigh->last_seen,
Sven Eckelmann7c64fd92012-02-28 10:55:36 +0100400 SOFTIF_NEIGH_TIMEOUT)) &&
Marek Lindner61906ae2011-04-21 15:52:17 +0200401 (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE))
402 continue;
403
404 if (curr_softif_neigh == softif_neigh) {
405 bat_dbg(DBG_ROUTES, bat_priv,
Sven Eckelmann86ceb362012-03-07 09:07:45 +0100406 "Current mesh exit point on vid: %d '%pM' vanished.\n",
Marek Lindner61906ae2011-04-21 15:52:17 +0200407 softif_neigh_vid->vid,
408 softif_neigh->addr);
409 do_deselect = 1;
410 }
411
412 hlist_del_rcu(&softif_neigh->list);
413 softif_neigh_free_ref(softif_neigh);
414 }
415 spin_unlock_bh(&bat_priv->softif_neigh_lock);
416
417 /* soft_neigh_vid_deselect() needs to acquire the
418 * softif_neigh_lock */
419 if (do_deselect)
420 softif_neigh_vid_deselect(bat_priv, softif_neigh_vid);
421
422 if (curr_softif_neigh)
423 softif_neigh_free_ref(curr_softif_neigh);
424
425 softif_neigh_vid_free_ref(softif_neigh_vid);
426 }
427 rcu_read_unlock();
428
429 spin_lock_bh(&bat_priv->softif_neigh_vid_lock);
430 hlist_for_each_entry_safe(softif_neigh_vid, node, node_tmp,
431 &bat_priv->softif_neigh_vids, list) {
432 if (!hlist_empty(&softif_neigh_vid->softif_neigh_list))
433 continue;
434
435 hlist_del_rcu(&softif_neigh_vid->list);
436 softif_neigh_vid_free_ref(softif_neigh_vid);
437 }
438 spin_unlock_bh(&bat_priv->softif_neigh_vid_lock);
439
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000440}
441
442static void softif_batman_recv(struct sk_buff *skb, struct net_device *dev,
443 short vid)
444{
445 struct bat_priv *bat_priv = netdev_priv(dev);
446 struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
Marek Lindnerb6da4bf2011-07-29 17:31:50 +0200447 struct batman_ogm_packet *batman_ogm_packet;
Marek Lindner32ae9b22011-04-20 15:40:58 +0200448 struct softif_neigh *softif_neigh = NULL;
449 struct hard_iface *primary_if = NULL;
Simon Wunderlichba85fac2011-04-17 20:34:27 +0200450 struct softif_neigh *curr_softif_neigh = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000451
452 if (ntohs(ethhdr->h_proto) == ETH_P_8021Q)
Marek Lindnerb6da4bf2011-07-29 17:31:50 +0200453 batman_ogm_packet = (struct batman_ogm_packet *)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000454 (skb->data + ETH_HLEN + VLAN_HLEN);
455 else
Marek Lindnerb6da4bf2011-07-29 17:31:50 +0200456 batman_ogm_packet = (struct batman_ogm_packet *)
457 (skb->data + ETH_HLEN);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000458
Sven Eckelmann76543d12011-11-20 15:47:38 +0100459 if (batman_ogm_packet->header.version != COMPAT_VERSION)
Marek Lindner32ae9b22011-04-20 15:40:58 +0200460 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000461
Sven Eckelmann76543d12011-11-20 15:47:38 +0100462 if (batman_ogm_packet->header.packet_type != BAT_OGM)
Marek Lindner32ae9b22011-04-20 15:40:58 +0200463 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000464
Marek Lindnerb6da4bf2011-07-29 17:31:50 +0200465 if (!(batman_ogm_packet->flags & PRIMARIES_FIRST_HOP))
Marek Lindner32ae9b22011-04-20 15:40:58 +0200466 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000467
Marek Lindnerb6da4bf2011-07-29 17:31:50 +0200468 if (is_my_mac(batman_ogm_packet->orig))
Marek Lindner32ae9b22011-04-20 15:40:58 +0200469 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000470
Marek Lindnerb6da4bf2011-07-29 17:31:50 +0200471 softif_neigh = softif_neigh_get(bat_priv, batman_ogm_packet->orig, vid);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000472 if (!softif_neigh)
Marek Lindner32ae9b22011-04-20 15:40:58 +0200473 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000474
Marek Lindner61906ae2011-04-21 15:52:17 +0200475 curr_softif_neigh = softif_neigh_vid_get_selected(bat_priv, vid);
Simon Wunderlichba85fac2011-04-17 20:34:27 +0200476 if (curr_softif_neigh == softif_neigh)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000477 goto out;
478
Marek Lindner32ae9b22011-04-20 15:40:58 +0200479 primary_if = primary_if_get_selected(bat_priv);
480 if (!primary_if)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000481 goto out;
482
483 /* we got a neighbor but its mac is 'bigger' than ours */
Marek Lindner32ae9b22011-04-20 15:40:58 +0200484 if (memcmp(primary_if->net_dev->dev_addr,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000485 softif_neigh->addr, ETH_ALEN) < 0)
486 goto out;
487
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000488 /* close own batX device and use softif_neigh as exit node */
Marek Lindner61906ae2011-04-21 15:52:17 +0200489 if (!curr_softif_neigh) {
490 softif_neigh_vid_select(bat_priv, softif_neigh, vid);
Simon Wunderlichba85fac2011-04-17 20:34:27 +0200491 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000492 }
493
Marek Lindner61906ae2011-04-21 15:52:17 +0200494 /* switch to new 'smallest neighbor' */
495 if (memcmp(softif_neigh->addr, curr_softif_neigh->addr, ETH_ALEN) < 0)
496 softif_neigh_vid_select(bat_priv, softif_neigh, vid);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000497
498out:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000499 kfree_skb(skb);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200500 if (softif_neigh)
501 softif_neigh_free_ref(softif_neigh);
Simon Wunderlichba85fac2011-04-17 20:34:27 +0200502 if (curr_softif_neigh)
503 softif_neigh_free_ref(curr_softif_neigh);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200504 if (primary_if)
505 hardif_free_ref(primary_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000506 return;
507}
508
509static int interface_open(struct net_device *dev)
510{
511 netif_start_queue(dev);
512 return 0;
513}
514
515static int interface_release(struct net_device *dev)
516{
517 netif_stop_queue(dev);
518 return 0;
519}
520
521static struct net_device_stats *interface_stats(struct net_device *dev)
522{
523 struct bat_priv *bat_priv = netdev_priv(dev);
524 return &bat_priv->stats;
525}
526
527static int interface_set_mac_addr(struct net_device *dev, void *p)
528{
529 struct bat_priv *bat_priv = netdev_priv(dev);
530 struct sockaddr *addr = p;
531
532 if (!is_valid_ether_addr(addr->sa_data))
533 return -EADDRNOTAVAIL;
534
Antonio Quartulli015758d2011-07-09 17:52:13 +0200535 /* only modify transtable if it has been initialized before */
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000536 if (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE) {
Antonio Quartulli2dafb492011-05-05 08:42:45 +0200537 tt_local_remove(bat_priv, dev->dev_addr,
Antonio Quartullicc47f662011-04-27 14:27:57 +0200538 "mac address changed", false);
Antonio Quartullibc279082011-07-07 15:35:35 +0200539 tt_local_add(dev, addr->sa_data, NULL_IFINDEX);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000540 }
541
542 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
543 return 0;
544}
545
546static int interface_change_mtu(struct net_device *dev, int new_mtu)
547{
548 /* check ranges */
549 if ((new_mtu < 68) || (new_mtu > hardif_min_mtu(dev)))
550 return -EINVAL;
551
552 dev->mtu = new_mtu;
553
554 return 0;
555}
556
Sven Eckelmanndb69ecf2011-06-15 15:17:21 +0200557static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000558{
559 struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
560 struct bat_priv *bat_priv = netdev_priv(soft_iface);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200561 struct hard_iface *primary_if = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000562 struct bcast_packet *bcast_packet;
563 struct vlan_ethhdr *vhdr;
Simon Wunderlichba85fac2011-04-17 20:34:27 +0200564 struct softif_neigh *curr_softif_neigh = NULL;
Marek Lindnerbe7af5c2011-09-08 13:12:53 +0200565 unsigned int header_len = 0;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000566 int data_len = skb->len, ret;
567 short vid = -1;
Marek Lindnerbe7af5c2011-09-08 13:12:53 +0200568 bool do_bcast = false;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000569
570 if (atomic_read(&bat_priv->mesh_state) != MESH_ACTIVE)
571 goto dropped;
572
573 soft_iface->trans_start = jiffies;
574
575 switch (ntohs(ethhdr->h_proto)) {
576 case ETH_P_8021Q:
577 vhdr = (struct vlan_ethhdr *)skb->data;
578 vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
579
580 if (ntohs(vhdr->h_vlan_encapsulated_proto) != ETH_P_BATMAN)
581 break;
582
583 /* fall through */
584 case ETH_P_BATMAN:
585 softif_batman_recv(skb, soft_iface, vid);
586 goto end;
587 }
588
589 /**
590 * if we have a another chosen mesh exit node in range
591 * it will transport the packets to the mesh
592 */
Marek Lindner61906ae2011-04-21 15:52:17 +0200593 curr_softif_neigh = softif_neigh_vid_get_selected(bat_priv, vid);
594 if (curr_softif_neigh)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000595 goto dropped;
596
Antonio Quartullia73105b2011-04-27 14:27:44 +0200597 /* Register the client MAC in the transtable */
Antonio Quartullibc279082011-07-07 15:35:35 +0200598 tt_local_add(soft_iface, ethhdr->h_source, skb->skb_iif);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000599
Marek Lindnerbe7af5c2011-09-08 13:12:53 +0200600 if (is_multicast_ether_addr(ethhdr->h_dest)) {
601 do_bcast = true;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000602
Marek Lindnerbe7af5c2011-09-08 13:12:53 +0200603 switch (atomic_read(&bat_priv->gw_mode)) {
604 case GW_MODE_SERVER:
605 /* gateway servers should not send dhcp
606 * requests into the mesh */
607 ret = gw_is_dhcp_target(skb, &header_len);
608 if (ret)
609 goto dropped;
610 break;
611 case GW_MODE_CLIENT:
612 /* gateway clients should send dhcp requests
613 * via unicast to their gateway */
614 ret = gw_is_dhcp_target(skb, &header_len);
615 if (ret)
616 do_bcast = false;
617 break;
618 case GW_MODE_OFF:
619 default:
620 break;
621 }
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000622 }
623
624 /* ethernet packet should be broadcasted */
625 if (do_bcast) {
Marek Lindner32ae9b22011-04-20 15:40:58 +0200626 primary_if = primary_if_get_selected(bat_priv);
627 if (!primary_if)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000628 goto dropped;
629
Sven Eckelmann704509b2011-05-14 23:14:54 +0200630 if (my_skb_head_push(skb, sizeof(*bcast_packet)) < 0)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000631 goto dropped;
632
633 bcast_packet = (struct bcast_packet *)skb->data;
Sven Eckelmann76543d12011-11-20 15:47:38 +0100634 bcast_packet->header.version = COMPAT_VERSION;
635 bcast_packet->header.ttl = TTL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000636
637 /* batman packet type: broadcast */
Sven Eckelmann76543d12011-11-20 15:47:38 +0100638 bcast_packet->header.packet_type = BAT_BCAST;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000639
640 /* hw address of first interface is the orig mac because only
641 * this mac is known throughout the mesh */
642 memcpy(bcast_packet->orig,
Marek Lindner32ae9b22011-04-20 15:40:58 +0200643 primary_if->net_dev->dev_addr, ETH_ALEN);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000644
645 /* set broadcast sequence number */
646 bcast_packet->seqno =
647 htonl(atomic_inc_return(&bat_priv->bcast_seqno));
648
Antonio Quartulli86985292011-06-25 19:09:12 +0200649 add_bcast_packet_to_list(bat_priv, skb, 1);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000650
651 /* a copy is stored in the bcast list, therefore removing
652 * the original skb. */
653 kfree_skb(skb);
654
655 /* unicast packet */
656 } else {
Marek Lindnerbe7af5c2011-09-08 13:12:53 +0200657 if (atomic_read(&bat_priv->gw_mode) != GW_MODE_OFF) {
658 ret = gw_out_of_range(bat_priv, skb, ethhdr);
659 if (ret)
660 goto dropped;
661 }
662
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000663 ret = unicast_send_skb(skb, bat_priv);
664 if (ret != 0)
665 goto dropped_freed;
666 }
667
668 bat_priv->stats.tx_packets++;
669 bat_priv->stats.tx_bytes += data_len;
670 goto end;
671
672dropped:
673 kfree_skb(skb);
674dropped_freed:
675 bat_priv->stats.tx_dropped++;
676end:
Simon Wunderlichba85fac2011-04-17 20:34:27 +0200677 if (curr_softif_neigh)
678 softif_neigh_free_ref(curr_softif_neigh);
Marek Lindner32ae9b22011-04-20 15:40:58 +0200679 if (primary_if)
680 hardif_free_ref(primary_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000681 return NETDEV_TX_OK;
682}
683
684void interface_rx(struct net_device *soft_iface,
Marek Lindnere6c10f42011-02-18 12:33:20 +0000685 struct sk_buff *skb, struct hard_iface *recv_if,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000686 int hdr_size)
687{
688 struct bat_priv *bat_priv = netdev_priv(soft_iface);
689 struct unicast_packet *unicast_packet;
690 struct ethhdr *ethhdr;
691 struct vlan_ethhdr *vhdr;
Simon Wunderlichba85fac2011-04-17 20:34:27 +0200692 struct softif_neigh *curr_softif_neigh = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000693 short vid = -1;
694 int ret;
695
696 /* check if enough space is available for pulling, and pull */
697 if (!pskb_may_pull(skb, hdr_size))
698 goto dropped;
699
700 skb_pull_rcsum(skb, hdr_size);
701 skb_reset_mac_header(skb);
702
703 ethhdr = (struct ethhdr *)skb_mac_header(skb);
704
705 switch (ntohs(ethhdr->h_proto)) {
706 case ETH_P_8021Q:
707 vhdr = (struct vlan_ethhdr *)skb->data;
708 vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
709
710 if (ntohs(vhdr->h_vlan_encapsulated_proto) != ETH_P_BATMAN)
711 break;
712
713 /* fall through */
714 case ETH_P_BATMAN:
715 goto dropped;
716 }
717
718 /**
719 * if we have a another chosen mesh exit node in range
720 * it will transport the packets to the non-mesh network
721 */
Marek Lindner61906ae2011-04-21 15:52:17 +0200722 curr_softif_neigh = softif_neigh_vid_get_selected(bat_priv, vid);
723 if (curr_softif_neigh) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000724 skb_push(skb, hdr_size);
725 unicast_packet = (struct unicast_packet *)skb->data;
726
Sven Eckelmann76543d12011-11-20 15:47:38 +0100727 if ((unicast_packet->header.packet_type != BAT_UNICAST) &&
728 (unicast_packet->header.packet_type != BAT_UNICAST_FRAG))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000729 goto dropped;
730
731 skb_reset_mac_header(skb);
732
733 memcpy(unicast_packet->dest,
Simon Wunderlichba85fac2011-04-17 20:34:27 +0200734 curr_softif_neigh->addr, ETH_ALEN);
Linus Lüssing7cefb142011-03-02 17:39:31 +0000735 ret = route_unicast_packet(skb, recv_if);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000736 if (ret == NET_RX_DROP)
737 goto dropped;
738
739 goto out;
740 }
741
742 /* skb->dev & skb->pkt_type are set here */
743 if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
744 goto dropped;
745 skb->protocol = eth_type_trans(skb, soft_iface);
746
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300747 /* should not be necessary anymore as we use skb_pull_rcsum()
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000748 * TODO: please verify this and remove this TODO
749 * -- Dec 21st 2009, Simon Wunderlich */
750
751/* skb->ip_summed = CHECKSUM_UNNECESSARY;*/
752
753 bat_priv->stats.rx_packets++;
754 bat_priv->stats.rx_bytes += skb->len + sizeof(struct ethhdr);
755
756 soft_iface->last_rx = jiffies;
757
Antonio Quartulli59b699c2011-07-07 15:35:36 +0200758 if (is_ap_isolated(bat_priv, ethhdr->h_source, ethhdr->h_dest))
759 goto dropped;
760
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000761 netif_rx(skb);
Simon Wunderlichba85fac2011-04-17 20:34:27 +0200762 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000763
764dropped:
765 kfree_skb(skb);
766out:
Simon Wunderlichba85fac2011-04-17 20:34:27 +0200767 if (curr_softif_neigh)
768 softif_neigh_free_ref(curr_softif_neigh);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000769 return;
770}
771
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000772static const struct net_device_ops bat_netdev_ops = {
773 .ndo_open = interface_open,
774 .ndo_stop = interface_release,
775 .ndo_get_stats = interface_stats,
776 .ndo_set_mac_address = interface_set_mac_addr,
777 .ndo_change_mtu = interface_change_mtu,
778 .ndo_start_xmit = interface_tx,
779 .ndo_validate_addr = eth_validate_addr
780};
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000781
782static void interface_setup(struct net_device *dev)
783{
784 struct bat_priv *priv = netdev_priv(dev);
785 char dev_addr[ETH_ALEN];
786
787 ether_setup(dev);
788
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000789 dev->netdev_ops = &bat_netdev_ops;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000790 dev->destructor = free_netdev;
Andrew Lunnaf20b712011-04-17 20:39:07 +0200791 dev->tx_queue_len = 0;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000792
793 /**
794 * can't call min_mtu, because the needed variables
795 * have not been initialized yet
796 */
797 dev->mtu = ETH_DATA_LEN;
Sven Eckelmann6e215fd2011-05-08 12:45:45 +0200798 /* reserve more space in the skbuff for our header */
799 dev->hard_header_len = BAT_HEADER_LEN;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000800
801 /* generate random address */
802 random_ether_addr(dev_addr);
803 memcpy(dev->dev_addr, dev_addr, ETH_ALEN);
804
805 SET_ETHTOOL_OPS(dev, &bat_ethtool_ops);
806
Sven Eckelmann704509b2011-05-14 23:14:54 +0200807 memset(priv, 0, sizeof(*priv));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000808}
809
Sven Eckelmann747e4222011-05-14 23:14:50 +0200810struct net_device *softif_create(const char *name)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000811{
812 struct net_device *soft_iface;
813 struct bat_priv *bat_priv;
814 int ret;
815
Sven Eckelmann704509b2011-05-14 23:14:54 +0200816 soft_iface = alloc_netdev(sizeof(*bat_priv), name, interface_setup);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000817
Joe Perches320f4222011-08-29 14:17:24 -0700818 if (!soft_iface)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000819 goto out;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000820
Sven Eckelmannc3caf512011-05-03 11:51:38 +0200821 ret = register_netdevice(soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000822 if (ret < 0) {
823 pr_err("Unable to register the batman interface '%s': %i\n",
824 name, ret);
825 goto free_soft_iface;
826 }
827
828 bat_priv = netdev_priv(soft_iface);
829
830 atomic_set(&bat_priv->aggregated_ogms, 1);
831 atomic_set(&bat_priv->bonding, 0);
Antonio Quartulli59b699c2011-07-07 15:35:36 +0200832 atomic_set(&bat_priv->ap_isolation, 0);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000833 atomic_set(&bat_priv->vis_mode, VIS_TYPE_CLIENT_UPDATE);
834 atomic_set(&bat_priv->gw_mode, GW_MODE_OFF);
835 atomic_set(&bat_priv->gw_sel_class, 20);
836 atomic_set(&bat_priv->gw_bandwidth, 41);
837 atomic_set(&bat_priv->orig_interval, 1000);
838 atomic_set(&bat_priv->hop_penalty, 10);
839 atomic_set(&bat_priv->log_level, 0);
840 atomic_set(&bat_priv->fragmentation, 1);
841 atomic_set(&bat_priv->bcast_queue_left, BCAST_QUEUE_LEN);
842 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
843
844 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
845 atomic_set(&bat_priv->bcast_seqno, 1);
Antonio Quartullia73105b2011-04-27 14:27:44 +0200846 atomic_set(&bat_priv->ttvn, 0);
847 atomic_set(&bat_priv->tt_local_changes, 0);
848 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
849
850 bat_priv->tt_buff = NULL;
851 bat_priv->tt_buff_len = 0;
Antonio Quartullicc47f662011-04-27 14:27:57 +0200852 bat_priv->tt_poss_change = false;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000853
854 bat_priv->primary_if = NULL;
855 bat_priv->num_ifaces = 0;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000856
Marek Lindner1c280472011-11-28 17:40:17 +0800857 ret = bat_algo_select(bat_priv, bat_routing_algo);
858 if (ret < 0)
859 goto unreg_soft_iface;
860
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000861 ret = sysfs_add_meshif(soft_iface);
862 if (ret < 0)
863 goto unreg_soft_iface;
864
865 ret = debugfs_add_meshif(soft_iface);
866 if (ret < 0)
867 goto unreg_sysfs;
868
869 ret = mesh_init(soft_iface);
870 if (ret < 0)
871 goto unreg_debugfs;
872
873 return soft_iface;
874
875unreg_debugfs:
876 debugfs_del_meshif(soft_iface);
877unreg_sysfs:
878 sysfs_del_meshif(soft_iface);
879unreg_soft_iface:
Simon Wunderlich06ba7ce2011-11-07 13:57:48 +0100880 unregister_netdevice(soft_iface);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000881 return NULL;
882
883free_soft_iface:
884 free_netdev(soft_iface);
885out:
886 return NULL;
887}
888
889void softif_destroy(struct net_device *soft_iface)
890{
891 debugfs_del_meshif(soft_iface);
892 sysfs_del_meshif(soft_iface);
893 mesh_free(soft_iface);
894 unregister_netdevice(soft_iface);
895}
896
Sven Eckelmann747e4222011-05-14 23:14:50 +0200897int softif_is_valid(const struct net_device *net_dev)
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000898{
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000899 if (net_dev->netdev_ops->ndo_start_xmit == interface_tx)
900 return 1;
Sven Eckelmanne44d8fe2011-03-04 21:36:41 +0000901
902 return 0;
903}
904
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000905/* ethtool */
906static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
907{
908 cmd->supported = 0;
909 cmd->advertising = 0;
David Decotigny70739492011-04-27 18:32:40 +0000910 ethtool_cmd_speed_set(cmd, SPEED_10);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000911 cmd->duplex = DUPLEX_FULL;
912 cmd->port = PORT_TP;
913 cmd->phy_address = 0;
914 cmd->transceiver = XCVR_INTERNAL;
915 cmd->autoneg = AUTONEG_DISABLE;
916 cmd->maxtxpkt = 0;
917 cmd->maxrxpkt = 0;
918
919 return 0;
920}
921
922static void bat_get_drvinfo(struct net_device *dev,
923 struct ethtool_drvinfo *info)
924{
925 strcpy(info->driver, "B.A.T.M.A.N. advanced");
926 strcpy(info->version, SOURCE_VERSION);
927 strcpy(info->fw_version, "N/A");
928 strcpy(info->bus_info, "batman");
929}
930
931static u32 bat_get_msglevel(struct net_device *dev)
932{
933 return -EOPNOTSUPP;
934}
935
936static void bat_set_msglevel(struct net_device *dev, u32 value)
937{
938}
939
940static u32 bat_get_link(struct net_device *dev)
941{
942 return 1;
943}