soft-interface.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  1. /* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors:
  2. *
  3. * Marek Lindner, Simon Wunderlich
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of version 2 of the GNU General Public
  7. * License as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include "soft-interface.h"
  18. #include "main.h"
  19. #include <linux/atomic.h>
  20. #include <linux/byteorder/generic.h>
  21. #include <linux/cache.h>
  22. #include <linux/compiler.h>
  23. #include <linux/cpumask.h>
  24. #include <linux/errno.h>
  25. #include <linux/etherdevice.h>
  26. #include <linux/ethtool.h>
  27. #include <linux/fs.h>
  28. #include <linux/if_ether.h>
  29. #include <linux/if_vlan.h>
  30. #include <linux/jiffies.h>
  31. #include <linux/kernel.h>
  32. #include <linux/kref.h>
  33. #include <linux/list.h>
  34. #include <linux/lockdep.h>
  35. #include <linux/netdevice.h>
  36. #include <linux/percpu.h>
  37. #include <linux/printk.h>
  38. #include <linux/random.h>
  39. #include <linux/rculist.h>
  40. #include <linux/rcupdate.h>
  41. #include <linux/rtnetlink.h>
  42. #include <linux/skbuff.h>
  43. #include <linux/slab.h>
  44. #include <linux/socket.h>
  45. #include <linux/spinlock.h>
  46. #include <linux/stddef.h>
  47. #include <linux/string.h>
  48. #include <linux/types.h>
  49. #include "bat_algo.h"
  50. #include "bridge_loop_avoidance.h"
  51. #include "debugfs.h"
  52. #include "distributed-arp-table.h"
  53. #include "gateway_client.h"
  54. #include "gateway_common.h"
  55. #include "hard-interface.h"
  56. #include "multicast.h"
  57. #include "network-coding.h"
  58. #include "originator.h"
  59. #include "packet.h"
  60. #include "send.h"
  61. #include "sysfs.h"
  62. #include "translation-table.h"
  63. static int batadv_get_settings(struct net_device *dev, struct ethtool_cmd *cmd);
  64. static void batadv_get_drvinfo(struct net_device *dev,
  65. struct ethtool_drvinfo *info);
  66. static u32 batadv_get_msglevel(struct net_device *dev);
  67. static void batadv_set_msglevel(struct net_device *dev, u32 value);
  68. static u32 batadv_get_link(struct net_device *dev);
  69. static void batadv_get_strings(struct net_device *dev, u32 stringset, u8 *data);
  70. static void batadv_get_ethtool_stats(struct net_device *dev,
  71. struct ethtool_stats *stats, u64 *data);
  72. static int batadv_get_sset_count(struct net_device *dev, int stringset);
  73. static const struct ethtool_ops batadv_ethtool_ops = {
  74. .get_settings = batadv_get_settings,
  75. .get_drvinfo = batadv_get_drvinfo,
  76. .get_msglevel = batadv_get_msglevel,
  77. .set_msglevel = batadv_set_msglevel,
  78. .get_link = batadv_get_link,
  79. .get_strings = batadv_get_strings,
  80. .get_ethtool_stats = batadv_get_ethtool_stats,
  81. .get_sset_count = batadv_get_sset_count,
  82. };
  83. int batadv_skb_head_push(struct sk_buff *skb, unsigned int len)
  84. {
  85. int result;
  86. /* TODO: We must check if we can release all references to non-payload
  87. * data using skb_header_release in our skbs to allow skb_cow_header to
  88. * work optimally. This means that those skbs are not allowed to read
  89. * or write any data which is before the current position of skb->data
  90. * after that call and thus allow other skbs with the same data buffer
  91. * to write freely in that area.
  92. */
  93. result = skb_cow_head(skb, len);
  94. if (result < 0)
  95. return result;
  96. skb_push(skb, len);
  97. return 0;
  98. }
  99. static int batadv_interface_open(struct net_device *dev)
  100. {
  101. netif_start_queue(dev);
  102. return 0;
  103. }
  104. static int batadv_interface_release(struct net_device *dev)
  105. {
  106. netif_stop_queue(dev);
  107. return 0;
  108. }
  109. /**
  110. * batadv_sum_counter - Sum the cpu-local counters for index 'idx'
  111. * @bat_priv: the bat priv with all the soft interface information
  112. * @idx: index of counter to sum up
  113. *
  114. * Return: sum of all cpu-local counters
  115. */
  116. static u64 batadv_sum_counter(struct batadv_priv *bat_priv, size_t idx)
  117. {
  118. u64 *counters, sum = 0;
  119. int cpu;
  120. for_each_possible_cpu(cpu) {
  121. counters = per_cpu_ptr(bat_priv->bat_counters, cpu);
  122. sum += counters[idx];
  123. }
  124. return sum;
  125. }
  126. static struct net_device_stats *batadv_interface_stats(struct net_device *dev)
  127. {
  128. struct batadv_priv *bat_priv = netdev_priv(dev);
  129. struct net_device_stats *stats = &bat_priv->stats;
  130. stats->tx_packets = batadv_sum_counter(bat_priv, BATADV_CNT_TX);
  131. stats->tx_bytes = batadv_sum_counter(bat_priv, BATADV_CNT_TX_BYTES);
  132. stats->tx_dropped = batadv_sum_counter(bat_priv, BATADV_CNT_TX_DROPPED);
  133. stats->rx_packets = batadv_sum_counter(bat_priv, BATADV_CNT_RX);
  134. stats->rx_bytes = batadv_sum_counter(bat_priv, BATADV_CNT_RX_BYTES);
  135. return stats;
  136. }
  137. static int batadv_interface_set_mac_addr(struct net_device *dev, void *p)
  138. {
  139. struct batadv_priv *bat_priv = netdev_priv(dev);
  140. struct batadv_softif_vlan *vlan;
  141. struct sockaddr *addr = p;
  142. u8 old_addr[ETH_ALEN];
  143. if (!is_valid_ether_addr(addr->sa_data))
  144. return -EADDRNOTAVAIL;
  145. ether_addr_copy(old_addr, dev->dev_addr);
  146. ether_addr_copy(dev->dev_addr, addr->sa_data);
  147. /* only modify transtable if it has been initialized before */
  148. if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE)
  149. return 0;
  150. rcu_read_lock();
  151. hlist_for_each_entry_rcu(vlan, &bat_priv->softif_vlan_list, list) {
  152. batadv_tt_local_remove(bat_priv, old_addr, vlan->vid,
  153. "mac address changed", false);
  154. batadv_tt_local_add(dev, addr->sa_data, vlan->vid,
  155. BATADV_NULL_IFINDEX, BATADV_NO_MARK);
  156. }
  157. rcu_read_unlock();
  158. return 0;
  159. }
  160. static int batadv_interface_change_mtu(struct net_device *dev, int new_mtu)
  161. {
  162. /* check ranges */
  163. if ((new_mtu < 68) || (new_mtu > batadv_hardif_min_mtu(dev)))
  164. return -EINVAL;
  165. dev->mtu = new_mtu;
  166. return 0;
  167. }
  168. /**
  169. * batadv_interface_set_rx_mode - set the rx mode of a device
  170. * @dev: registered network device to modify
  171. *
  172. * We do not actually need to set any rx filters for the virtual batman
  173. * soft interface. However a dummy handler enables a user to set static
  174. * multicast listeners for instance.
  175. */
  176. static void batadv_interface_set_rx_mode(struct net_device *dev)
  177. {
  178. }
  179. static int batadv_interface_tx(struct sk_buff *skb,
  180. struct net_device *soft_iface)
  181. {
  182. struct ethhdr *ethhdr;
  183. struct batadv_priv *bat_priv = netdev_priv(soft_iface);
  184. struct batadv_hard_iface *primary_if = NULL;
  185. struct batadv_bcast_packet *bcast_packet;
  186. static const u8 stp_addr[ETH_ALEN] = {0x01, 0x80, 0xC2, 0x00,
  187. 0x00, 0x00};
  188. static const u8 ectp_addr[ETH_ALEN] = {0xCF, 0x00, 0x00, 0x00,
  189. 0x00, 0x00};
  190. enum batadv_dhcp_recipient dhcp_rcp = BATADV_DHCP_NO;
  191. u8 *dst_hint = NULL, chaddr[ETH_ALEN];
  192. struct vlan_ethhdr *vhdr;
  193. unsigned int header_len = 0;
  194. int data_len = skb->len, ret;
  195. unsigned long brd_delay = 1;
  196. bool do_bcast = false, client_added;
  197. unsigned short vid;
  198. u32 seqno;
  199. int gw_mode;
  200. enum batadv_forw_mode forw_mode;
  201. struct batadv_orig_node *mcast_single_orig = NULL;
  202. int network_offset = ETH_HLEN;
  203. if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE)
  204. goto dropped;
  205. netif_trans_update(soft_iface);
  206. vid = batadv_get_vid(skb, 0);
  207. ethhdr = eth_hdr(skb);
  208. switch (ntohs(ethhdr->h_proto)) {
  209. case ETH_P_8021Q:
  210. vhdr = vlan_eth_hdr(skb);
  211. /* drop batman-in-batman packets to prevent loops */
  212. if (vhdr->h_vlan_encapsulated_proto != htons(ETH_P_BATMAN)) {
  213. network_offset += VLAN_HLEN;
  214. break;
  215. }
  216. /* fall through */
  217. case ETH_P_BATMAN:
  218. goto dropped;
  219. }
  220. skb_set_network_header(skb, network_offset);
  221. if (batadv_bla_tx(bat_priv, skb, vid))
  222. goto dropped;
  223. /* skb->data might have been reallocated by batadv_bla_tx() */
  224. ethhdr = eth_hdr(skb);
  225. /* Register the client MAC in the transtable */
  226. if (!is_multicast_ether_addr(ethhdr->h_source)) {
  227. client_added = batadv_tt_local_add(soft_iface, ethhdr->h_source,
  228. vid, skb->skb_iif,
  229. skb->mark);
  230. if (!client_added)
  231. goto dropped;
  232. }
  233. /* don't accept stp packets. STP does not help in meshes.
  234. * better use the bridge loop avoidance ...
  235. *
  236. * The same goes for ECTP sent at least by some Cisco Switches,
  237. * it might confuse the mesh when used with bridge loop avoidance.
  238. */
  239. if (batadv_compare_eth(ethhdr->h_dest, stp_addr))
  240. goto dropped;
  241. if (batadv_compare_eth(ethhdr->h_dest, ectp_addr))
  242. goto dropped;
  243. gw_mode = atomic_read(&bat_priv->gw.mode);
  244. if (is_multicast_ether_addr(ethhdr->h_dest)) {
  245. /* if gw mode is off, broadcast every packet */
  246. if (gw_mode == BATADV_GW_MODE_OFF) {
  247. do_bcast = true;
  248. goto send;
  249. }
  250. dhcp_rcp = batadv_gw_dhcp_recipient_get(skb, &header_len,
  251. chaddr);
  252. /* skb->data may have been modified by
  253. * batadv_gw_dhcp_recipient_get()
  254. */
  255. ethhdr = eth_hdr(skb);
  256. /* if gw_mode is on, broadcast any non-DHCP message.
  257. * All the DHCP packets are going to be sent as unicast
  258. */
  259. if (dhcp_rcp == BATADV_DHCP_NO) {
  260. do_bcast = true;
  261. goto send;
  262. }
  263. if (dhcp_rcp == BATADV_DHCP_TO_CLIENT)
  264. dst_hint = chaddr;
  265. else if ((gw_mode == BATADV_GW_MODE_SERVER) &&
  266. (dhcp_rcp == BATADV_DHCP_TO_SERVER))
  267. /* gateways should not forward any DHCP message if
  268. * directed to a DHCP server
  269. */
  270. goto dropped;
  271. send:
  272. if (do_bcast && !is_broadcast_ether_addr(ethhdr->h_dest)) {
  273. forw_mode = batadv_mcast_forw_mode(bat_priv, skb,
  274. &mcast_single_orig);
  275. if (forw_mode == BATADV_FORW_NONE)
  276. goto dropped;
  277. if (forw_mode == BATADV_FORW_SINGLE)
  278. do_bcast = false;
  279. }
  280. }
  281. batadv_skb_set_priority(skb, 0);
  282. /* ethernet packet should be broadcasted */
  283. if (do_bcast) {
  284. primary_if = batadv_primary_if_get_selected(bat_priv);
  285. if (!primary_if)
  286. goto dropped;
  287. /* in case of ARP request, we do not immediately broadcasti the
  288. * packet, instead we first wait for DAT to try to retrieve the
  289. * correct ARP entry
  290. */
  291. if (batadv_dat_snoop_outgoing_arp_request(bat_priv, skb))
  292. brd_delay = msecs_to_jiffies(ARP_REQ_DELAY);
  293. if (batadv_skb_head_push(skb, sizeof(*bcast_packet)) < 0)
  294. goto dropped;
  295. bcast_packet = (struct batadv_bcast_packet *)skb->data;
  296. bcast_packet->version = BATADV_COMPAT_VERSION;
  297. bcast_packet->ttl = BATADV_TTL;
  298. /* batman packet type: broadcast */
  299. bcast_packet->packet_type = BATADV_BCAST;
  300. bcast_packet->reserved = 0;
  301. /* hw address of first interface is the orig mac because only
  302. * this mac is known throughout the mesh
  303. */
  304. ether_addr_copy(bcast_packet->orig,
  305. primary_if->net_dev->dev_addr);
  306. /* set broadcast sequence number */
  307. seqno = atomic_inc_return(&bat_priv->bcast_seqno);
  308. bcast_packet->seqno = htonl(seqno);
  309. batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay, true);
  310. /* a copy is stored in the bcast list, therefore removing
  311. * the original skb.
  312. */
  313. consume_skb(skb);
  314. /* unicast packet */
  315. } else {
  316. /* DHCP packets going to a server will use the GW feature */
  317. if (dhcp_rcp == BATADV_DHCP_TO_SERVER) {
  318. ret = batadv_gw_out_of_range(bat_priv, skb);
  319. if (ret)
  320. goto dropped;
  321. ret = batadv_send_skb_via_gw(bat_priv, skb, vid);
  322. } else if (mcast_single_orig) {
  323. ret = batadv_send_skb_unicast(bat_priv, skb,
  324. BATADV_UNICAST, 0,
  325. mcast_single_orig, vid);
  326. } else {
  327. if (batadv_dat_snoop_outgoing_arp_request(bat_priv,
  328. skb))
  329. goto dropped;
  330. batadv_dat_snoop_outgoing_arp_reply(bat_priv, skb);
  331. ret = batadv_send_skb_via_tt(bat_priv, skb, dst_hint,
  332. vid);
  333. }
  334. if (ret != NET_XMIT_SUCCESS)
  335. goto dropped_freed;
  336. }
  337. batadv_inc_counter(bat_priv, BATADV_CNT_TX);
  338. batadv_add_counter(bat_priv, BATADV_CNT_TX_BYTES, data_len);
  339. goto end;
  340. dropped:
  341. kfree_skb(skb);
  342. dropped_freed:
  343. batadv_inc_counter(bat_priv, BATADV_CNT_TX_DROPPED);
  344. end:
  345. if (mcast_single_orig)
  346. batadv_orig_node_put(mcast_single_orig);
  347. if (primary_if)
  348. batadv_hardif_put(primary_if);
  349. return NETDEV_TX_OK;
  350. }
  351. /**
  352. * batadv_interface_rx - receive ethernet frame on local batman-adv interface
  353. * @soft_iface: local interface which will receive the ethernet frame
  354. * @skb: ethernet frame for @soft_iface
  355. * @hdr_size: size of already parsed batman-adv header
  356. * @orig_node: originator from which the batman-adv packet was sent
  357. *
  358. * Sends a ethernet frame to the receive path of the local @soft_iface.
  359. * skb->data has still point to the batman-adv header with the size @hdr_size.
  360. * The caller has to have parsed this header already and made sure that at least
  361. * @hdr_size bytes are still available for pull in @skb.
  362. *
  363. * The packet may still get dropped. This can happen when the encapsulated
  364. * ethernet frame is invalid or contains again an batman-adv packet. Also
  365. * unicast packets will be dropped directly when it was sent between two
  366. * isolated clients.
  367. */
  368. void batadv_interface_rx(struct net_device *soft_iface,
  369. struct sk_buff *skb, int hdr_size,
  370. struct batadv_orig_node *orig_node)
  371. {
  372. struct batadv_bcast_packet *batadv_bcast_packet;
  373. struct batadv_priv *bat_priv = netdev_priv(soft_iface);
  374. struct vlan_ethhdr *vhdr;
  375. struct ethhdr *ethhdr;
  376. unsigned short vid;
  377. bool is_bcast;
  378. batadv_bcast_packet = (struct batadv_bcast_packet *)skb->data;
  379. is_bcast = (batadv_bcast_packet->packet_type == BATADV_BCAST);
  380. skb_pull_rcsum(skb, hdr_size);
  381. skb_reset_mac_header(skb);
  382. /* clean the netfilter state now that the batman-adv header has been
  383. * removed
  384. */
  385. nf_reset(skb);
  386. if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
  387. goto dropped;
  388. vid = batadv_get_vid(skb, 0);
  389. ethhdr = eth_hdr(skb);
  390. switch (ntohs(ethhdr->h_proto)) {
  391. case ETH_P_8021Q:
  392. if (!pskb_may_pull(skb, VLAN_ETH_HLEN))
  393. goto dropped;
  394. vhdr = (struct vlan_ethhdr *)skb->data;
  395. /* drop batman-in-batman packets to prevent loops */
  396. if (vhdr->h_vlan_encapsulated_proto != htons(ETH_P_BATMAN))
  397. break;
  398. /* fall through */
  399. case ETH_P_BATMAN:
  400. goto dropped;
  401. }
  402. /* skb->dev & skb->pkt_type are set here */
  403. skb->protocol = eth_type_trans(skb, soft_iface);
  404. /* should not be necessary anymore as we use skb_pull_rcsum()
  405. * TODO: please verify this and remove this TODO
  406. * -- Dec 21st 2009, Simon Wunderlich
  407. */
  408. /* skb->ip_summed = CHECKSUM_UNNECESSARY; */
  409. batadv_inc_counter(bat_priv, BATADV_CNT_RX);
  410. batadv_add_counter(bat_priv, BATADV_CNT_RX_BYTES,
  411. skb->len + ETH_HLEN);
  412. soft_iface->last_rx = jiffies;
  413. /* Let the bridge loop avoidance check the packet. If will
  414. * not handle it, we can safely push it up.
  415. */
  416. if (batadv_bla_rx(bat_priv, skb, vid, is_bcast))
  417. goto out;
  418. if (orig_node)
  419. batadv_tt_add_temporary_global_entry(bat_priv, orig_node,
  420. ethhdr->h_source, vid);
  421. if (is_multicast_ether_addr(ethhdr->h_dest)) {
  422. /* set the mark on broadcast packets if AP isolation is ON and
  423. * the packet is coming from an "isolated" client
  424. */
  425. if (batadv_vlan_ap_isola_get(bat_priv, vid) &&
  426. batadv_tt_global_is_isolated(bat_priv, ethhdr->h_source,
  427. vid)) {
  428. /* save bits in skb->mark not covered by the mask and
  429. * apply the mark on the rest
  430. */
  431. skb->mark &= ~bat_priv->isolation_mark_mask;
  432. skb->mark |= bat_priv->isolation_mark;
  433. }
  434. } else if (batadv_is_ap_isolated(bat_priv, ethhdr->h_source,
  435. ethhdr->h_dest, vid)) {
  436. goto dropped;
  437. }
  438. netif_rx(skb);
  439. goto out;
  440. dropped:
  441. kfree_skb(skb);
  442. out:
  443. return;
  444. }
  445. /**
  446. * batadv_softif_vlan_release - release vlan from lists and queue for free after
  447. * rcu grace period
  448. * @ref: kref pointer of the vlan object
  449. */
  450. static void batadv_softif_vlan_release(struct kref *ref)
  451. {
  452. struct batadv_softif_vlan *vlan;
  453. vlan = container_of(ref, struct batadv_softif_vlan, refcount);
  454. spin_lock_bh(&vlan->bat_priv->softif_vlan_list_lock);
  455. hlist_del_rcu(&vlan->list);
  456. spin_unlock_bh(&vlan->bat_priv->softif_vlan_list_lock);
  457. kfree_rcu(vlan, rcu);
  458. }
  459. /**
  460. * batadv_softif_vlan_put - decrease the vlan object refcounter and
  461. * possibly release it
  462. * @vlan: the vlan object to release
  463. */
  464. void batadv_softif_vlan_put(struct batadv_softif_vlan *vlan)
  465. {
  466. if (!vlan)
  467. return;
  468. kref_put(&vlan->refcount, batadv_softif_vlan_release);
  469. }
  470. /**
  471. * batadv_softif_vlan_get - get the vlan object for a specific vid
  472. * @bat_priv: the bat priv with all the soft interface information
  473. * @vid: the identifier of the vlan object to retrieve
  474. *
  475. * Return: the private data of the vlan matching the vid passed as argument or
  476. * NULL otherwise. The refcounter of the returned object is incremented by 1.
  477. */
  478. struct batadv_softif_vlan *batadv_softif_vlan_get(struct batadv_priv *bat_priv,
  479. unsigned short vid)
  480. {
  481. struct batadv_softif_vlan *vlan_tmp, *vlan = NULL;
  482. rcu_read_lock();
  483. hlist_for_each_entry_rcu(vlan_tmp, &bat_priv->softif_vlan_list, list) {
  484. if (vlan_tmp->vid != vid)
  485. continue;
  486. if (!kref_get_unless_zero(&vlan_tmp->refcount))
  487. continue;
  488. vlan = vlan_tmp;
  489. break;
  490. }
  491. rcu_read_unlock();
  492. return vlan;
  493. }
  494. /**
  495. * batadv_softif_create_vlan - allocate the needed resources for a new vlan
  496. * @bat_priv: the bat priv with all the soft interface information
  497. * @vid: the VLAN identifier
  498. *
  499. * Return: 0 on success, a negative error otherwise.
  500. */
  501. int batadv_softif_create_vlan(struct batadv_priv *bat_priv, unsigned short vid)
  502. {
  503. struct batadv_softif_vlan *vlan;
  504. int err;
  505. vlan = batadv_softif_vlan_get(bat_priv, vid);
  506. if (vlan) {
  507. batadv_softif_vlan_put(vlan);
  508. return -EEXIST;
  509. }
  510. vlan = kzalloc(sizeof(*vlan), GFP_ATOMIC);
  511. if (!vlan)
  512. return -ENOMEM;
  513. vlan->bat_priv = bat_priv;
  514. vlan->vid = vid;
  515. kref_init(&vlan->refcount);
  516. atomic_set(&vlan->ap_isolation, 0);
  517. err = batadv_sysfs_add_vlan(bat_priv->soft_iface, vlan);
  518. if (err) {
  519. kfree(vlan);
  520. return err;
  521. }
  522. spin_lock_bh(&bat_priv->softif_vlan_list_lock);
  523. kref_get(&vlan->refcount);
  524. hlist_add_head_rcu(&vlan->list, &bat_priv->softif_vlan_list);
  525. spin_unlock_bh(&bat_priv->softif_vlan_list_lock);
  526. /* add a new TT local entry. This one will be marked with the NOPURGE
  527. * flag
  528. */
  529. batadv_tt_local_add(bat_priv->soft_iface,
  530. bat_priv->soft_iface->dev_addr, vid,
  531. BATADV_NULL_IFINDEX, BATADV_NO_MARK);
  532. /* don't return reference to new softif_vlan */
  533. batadv_softif_vlan_put(vlan);
  534. return 0;
  535. }
  536. /**
  537. * batadv_softif_destroy_vlan - remove and destroy a softif_vlan object
  538. * @bat_priv: the bat priv with all the soft interface information
  539. * @vlan: the object to remove
  540. */
  541. static void batadv_softif_destroy_vlan(struct batadv_priv *bat_priv,
  542. struct batadv_softif_vlan *vlan)
  543. {
  544. /* explicitly remove the associated TT local entry because it is marked
  545. * with the NOPURGE flag
  546. */
  547. batadv_tt_local_remove(bat_priv, bat_priv->soft_iface->dev_addr,
  548. vlan->vid, "vlan interface destroyed", false);
  549. batadv_sysfs_del_vlan(bat_priv, vlan);
  550. batadv_softif_vlan_put(vlan);
  551. }
  552. /**
  553. * batadv_interface_add_vid - ndo_add_vid API implementation
  554. * @dev: the netdev of the mesh interface
  555. * @proto: protocol of the the vlan id
  556. * @vid: identifier of the new vlan
  557. *
  558. * Set up all the internal structures for handling the new vlan on top of the
  559. * mesh interface
  560. *
  561. * Return: 0 on success or a negative error code in case of failure.
  562. */
  563. static int batadv_interface_add_vid(struct net_device *dev, __be16 proto,
  564. unsigned short vid)
  565. {
  566. struct batadv_priv *bat_priv = netdev_priv(dev);
  567. struct batadv_softif_vlan *vlan;
  568. int ret;
  569. /* only 802.1Q vlans are supported.
  570. * batman-adv does not know how to handle other types
  571. */
  572. if (proto != htons(ETH_P_8021Q))
  573. return -EINVAL;
  574. vid |= BATADV_VLAN_HAS_TAG;
  575. /* if a new vlan is getting created and it already exists, it means that
  576. * it was not deleted yet. batadv_softif_vlan_get() increases the
  577. * refcount in order to revive the object.
  578. *
  579. * if it does not exist then create it.
  580. */
  581. vlan = batadv_softif_vlan_get(bat_priv, vid);
  582. if (!vlan)
  583. return batadv_softif_create_vlan(bat_priv, vid);
  584. /* recreate the sysfs object if it was already destroyed (and it should
  585. * be since we received a kill_vid() for this vlan
  586. */
  587. if (!vlan->kobj) {
  588. ret = batadv_sysfs_add_vlan(bat_priv->soft_iface, vlan);
  589. if (ret) {
  590. batadv_softif_vlan_put(vlan);
  591. return ret;
  592. }
  593. }
  594. /* add a new TT local entry. This one will be marked with the NOPURGE
  595. * flag. This must be added again, even if the vlan object already
  596. * exists, because the entry was deleted by kill_vid()
  597. */
  598. batadv_tt_local_add(bat_priv->soft_iface,
  599. bat_priv->soft_iface->dev_addr, vid,
  600. BATADV_NULL_IFINDEX, BATADV_NO_MARK);
  601. return 0;
  602. }
  603. /**
  604. * batadv_interface_kill_vid - ndo_kill_vid API implementation
  605. * @dev: the netdev of the mesh interface
  606. * @proto: protocol of the the vlan id
  607. * @vid: identifier of the deleted vlan
  608. *
  609. * Destroy all the internal structures used to handle the vlan identified by vid
  610. * on top of the mesh interface
  611. *
  612. * Return: 0 on success, -EINVAL if the specified prototype is not ETH_P_8021Q
  613. * or -ENOENT if the specified vlan id wasn't registered.
  614. */
  615. static int batadv_interface_kill_vid(struct net_device *dev, __be16 proto,
  616. unsigned short vid)
  617. {
  618. struct batadv_priv *bat_priv = netdev_priv(dev);
  619. struct batadv_softif_vlan *vlan;
  620. /* only 802.1Q vlans are supported. batman-adv does not know how to
  621. * handle other types
  622. */
  623. if (proto != htons(ETH_P_8021Q))
  624. return -EINVAL;
  625. vlan = batadv_softif_vlan_get(bat_priv, vid | BATADV_VLAN_HAS_TAG);
  626. if (!vlan)
  627. return -ENOENT;
  628. batadv_softif_destroy_vlan(bat_priv, vlan);
  629. /* finally free the vlan object */
  630. batadv_softif_vlan_put(vlan);
  631. return 0;
  632. }
  633. /* batman-adv network devices have devices nesting below it and are a special
  634. * "super class" of normal network devices; split their locks off into a
  635. * separate class since they always nest.
  636. */
  637. static struct lock_class_key batadv_netdev_xmit_lock_key;
  638. static struct lock_class_key batadv_netdev_addr_lock_key;
  639. /**
  640. * batadv_set_lockdep_class_one - Set lockdep class for a single tx queue
  641. * @dev: device which owns the tx queue
  642. * @txq: tx queue to modify
  643. * @_unused: always NULL
  644. */
  645. static void batadv_set_lockdep_class_one(struct net_device *dev,
  646. struct netdev_queue *txq,
  647. void *_unused)
  648. {
  649. lockdep_set_class(&txq->_xmit_lock, &batadv_netdev_xmit_lock_key);
  650. }
  651. /**
  652. * batadv_set_lockdep_class - Set txq and addr_list lockdep class
  653. * @dev: network device to modify
  654. */
  655. static void batadv_set_lockdep_class(struct net_device *dev)
  656. {
  657. lockdep_set_class(&dev->addr_list_lock, &batadv_netdev_addr_lock_key);
  658. netdev_for_each_tx_queue(dev, batadv_set_lockdep_class_one, NULL);
  659. }
  660. /**
  661. * batadv_softif_init_late - late stage initialization of soft interface
  662. * @dev: registered network device to modify
  663. *
  664. * Return: error code on failures
  665. */
  666. static int batadv_softif_init_late(struct net_device *dev)
  667. {
  668. struct batadv_priv *bat_priv;
  669. u32 random_seqno;
  670. int ret;
  671. size_t cnt_len = sizeof(u64) * BATADV_CNT_NUM;
  672. batadv_set_lockdep_class(dev);
  673. bat_priv = netdev_priv(dev);
  674. bat_priv->soft_iface = dev;
  675. /* batadv_interface_stats() needs to be available as soon as
  676. * register_netdevice() has been called
  677. */
  678. bat_priv->bat_counters = __alloc_percpu(cnt_len, __alignof__(u64));
  679. if (!bat_priv->bat_counters)
  680. return -ENOMEM;
  681. atomic_set(&bat_priv->aggregated_ogms, 1);
  682. atomic_set(&bat_priv->bonding, 0);
  683. #ifdef CONFIG_BATMAN_ADV_BLA
  684. atomic_set(&bat_priv->bridge_loop_avoidance, 1);
  685. #endif
  686. #ifdef CONFIG_BATMAN_ADV_DAT
  687. atomic_set(&bat_priv->distributed_arp_table, 1);
  688. #endif
  689. #ifdef CONFIG_BATMAN_ADV_MCAST
  690. bat_priv->mcast.querier_ipv4.exists = false;
  691. bat_priv->mcast.querier_ipv4.shadowing = false;
  692. bat_priv->mcast.querier_ipv6.exists = false;
  693. bat_priv->mcast.querier_ipv6.shadowing = false;
  694. bat_priv->mcast.flags = BATADV_NO_FLAGS;
  695. atomic_set(&bat_priv->multicast_mode, 1);
  696. atomic_set(&bat_priv->mcast.num_disabled, 0);
  697. atomic_set(&bat_priv->mcast.num_want_all_unsnoopables, 0);
  698. atomic_set(&bat_priv->mcast.num_want_all_ipv4, 0);
  699. atomic_set(&bat_priv->mcast.num_want_all_ipv6, 0);
  700. #endif
  701. atomic_set(&bat_priv->gw.mode, BATADV_GW_MODE_OFF);
  702. atomic_set(&bat_priv->gw.sel_class, 20);
  703. atomic_set(&bat_priv->gw.bandwidth_down, 100);
  704. atomic_set(&bat_priv->gw.bandwidth_up, 20);
  705. atomic_set(&bat_priv->orig_interval, 1000);
  706. atomic_set(&bat_priv->hop_penalty, 30);
  707. #ifdef CONFIG_BATMAN_ADV_DEBUG
  708. atomic_set(&bat_priv->log_level, 0);
  709. #endif
  710. atomic_set(&bat_priv->fragmentation, 1);
  711. atomic_set(&bat_priv->packet_size_max, ETH_DATA_LEN);
  712. atomic_set(&bat_priv->bcast_queue_left, BATADV_BCAST_QUEUE_LEN);
  713. atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
  714. atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
  715. atomic_set(&bat_priv->bcast_seqno, 1);
  716. atomic_set(&bat_priv->tt.vn, 0);
  717. atomic_set(&bat_priv->tt.local_changes, 0);
  718. atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
  719. #ifdef CONFIG_BATMAN_ADV_BLA
  720. atomic_set(&bat_priv->bla.num_requests, 0);
  721. #endif
  722. atomic_set(&bat_priv->tp_num, 0);
  723. bat_priv->tt.last_changeset = NULL;
  724. bat_priv->tt.last_changeset_len = 0;
  725. bat_priv->isolation_mark = 0;
  726. bat_priv->isolation_mark_mask = 0;
  727. /* randomize initial seqno to avoid collision */
  728. get_random_bytes(&random_seqno, sizeof(random_seqno));
  729. atomic_set(&bat_priv->frag_seqno, random_seqno);
  730. bat_priv->primary_if = NULL;
  731. bat_priv->num_ifaces = 0;
  732. batadv_nc_init_bat_priv(bat_priv);
  733. ret = batadv_algo_select(bat_priv, batadv_routing_algo);
  734. if (ret < 0)
  735. goto free_bat_counters;
  736. ret = batadv_debugfs_add_meshif(dev);
  737. if (ret < 0)
  738. goto free_bat_counters;
  739. ret = batadv_mesh_init(dev);
  740. if (ret < 0)
  741. goto unreg_debugfs;
  742. return 0;
  743. unreg_debugfs:
  744. batadv_debugfs_del_meshif(dev);
  745. free_bat_counters:
  746. free_percpu(bat_priv->bat_counters);
  747. bat_priv->bat_counters = NULL;
  748. return ret;
  749. }
  750. /**
  751. * batadv_softif_slave_add - Add a slave interface to a batadv_soft_interface
  752. * @dev: batadv_soft_interface used as master interface
  753. * @slave_dev: net_device which should become the slave interface
  754. *
  755. * Return: 0 if successful or error otherwise.
  756. */
  757. static int batadv_softif_slave_add(struct net_device *dev,
  758. struct net_device *slave_dev)
  759. {
  760. struct batadv_hard_iface *hard_iface;
  761. struct net *net = dev_net(dev);
  762. int ret = -EINVAL;
  763. hard_iface = batadv_hardif_get_by_netdev(slave_dev);
  764. if (!hard_iface || hard_iface->soft_iface)
  765. goto out;
  766. ret = batadv_hardif_enable_interface(hard_iface, net, dev->name);
  767. out:
  768. if (hard_iface)
  769. batadv_hardif_put(hard_iface);
  770. return ret;
  771. }
  772. /**
  773. * batadv_softif_slave_del - Delete a slave iface from a batadv_soft_interface
  774. * @dev: batadv_soft_interface used as master interface
  775. * @slave_dev: net_device which should be removed from the master interface
  776. *
  777. * Return: 0 if successful or error otherwise.
  778. */
  779. static int batadv_softif_slave_del(struct net_device *dev,
  780. struct net_device *slave_dev)
  781. {
  782. struct batadv_hard_iface *hard_iface;
  783. int ret = -EINVAL;
  784. hard_iface = batadv_hardif_get_by_netdev(slave_dev);
  785. if (!hard_iface || hard_iface->soft_iface != dev)
  786. goto out;
  787. batadv_hardif_disable_interface(hard_iface, BATADV_IF_CLEANUP_KEEP);
  788. ret = 0;
  789. out:
  790. if (hard_iface)
  791. batadv_hardif_put(hard_iface);
  792. return ret;
  793. }
  794. static const struct net_device_ops batadv_netdev_ops = {
  795. .ndo_init = batadv_softif_init_late,
  796. .ndo_open = batadv_interface_open,
  797. .ndo_stop = batadv_interface_release,
  798. .ndo_get_stats = batadv_interface_stats,
  799. .ndo_vlan_rx_add_vid = batadv_interface_add_vid,
  800. .ndo_vlan_rx_kill_vid = batadv_interface_kill_vid,
  801. .ndo_set_mac_address = batadv_interface_set_mac_addr,
  802. .ndo_change_mtu = batadv_interface_change_mtu,
  803. .ndo_set_rx_mode = batadv_interface_set_rx_mode,
  804. .ndo_start_xmit = batadv_interface_tx,
  805. .ndo_validate_addr = eth_validate_addr,
  806. .ndo_add_slave = batadv_softif_slave_add,
  807. .ndo_del_slave = batadv_softif_slave_del,
  808. };
  809. /**
  810. * batadv_softif_free - Deconstructor of batadv_soft_interface
  811. * @dev: Device to cleanup and remove
  812. */
  813. static void batadv_softif_free(struct net_device *dev)
  814. {
  815. batadv_debugfs_del_meshif(dev);
  816. batadv_mesh_free(dev);
  817. /* some scheduled RCU callbacks need the bat_priv struct to accomplish
  818. * their tasks. Wait for them all to be finished before freeing the
  819. * netdev and its private data (bat_priv)
  820. */
  821. rcu_barrier();
  822. free_netdev(dev);
  823. }
  824. /**
  825. * batadv_softif_init_early - early stage initialization of soft interface
  826. * @dev: registered network device to modify
  827. */
  828. static void batadv_softif_init_early(struct net_device *dev)
  829. {
  830. struct batadv_priv *priv = netdev_priv(dev);
  831. ether_setup(dev);
  832. dev->netdev_ops = &batadv_netdev_ops;
  833. dev->destructor = batadv_softif_free;
  834. dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER | NETIF_F_NETNS_LOCAL;
  835. dev->priv_flags |= IFF_NO_QUEUE;
  836. /* can't call min_mtu, because the needed variables
  837. * have not been initialized yet
  838. */
  839. dev->mtu = ETH_DATA_LEN;
  840. /* generate random address */
  841. eth_hw_addr_random(dev);
  842. dev->ethtool_ops = &batadv_ethtool_ops;
  843. memset(priv, 0, sizeof(*priv));
  844. }
  845. struct net_device *batadv_softif_create(struct net *net, const char *name)
  846. {
  847. struct net_device *soft_iface;
  848. int ret;
  849. soft_iface = alloc_netdev(sizeof(struct batadv_priv), name,
  850. NET_NAME_UNKNOWN, batadv_softif_init_early);
  851. if (!soft_iface)
  852. return NULL;
  853. dev_net_set(soft_iface, net);
  854. soft_iface->rtnl_link_ops = &batadv_link_ops;
  855. ret = register_netdevice(soft_iface);
  856. if (ret < 0) {
  857. pr_err("Unable to register the batman interface '%s': %i\n",
  858. name, ret);
  859. free_netdev(soft_iface);
  860. return NULL;
  861. }
  862. return soft_iface;
  863. }
  864. /**
  865. * batadv_softif_destroy_sysfs - deletion of batadv_soft_interface via sysfs
  866. * @soft_iface: the to-be-removed batman-adv interface
  867. */
  868. void batadv_softif_destroy_sysfs(struct net_device *soft_iface)
  869. {
  870. struct batadv_priv *bat_priv = netdev_priv(soft_iface);
  871. struct batadv_softif_vlan *vlan;
  872. ASSERT_RTNL();
  873. /* destroy the "untagged" VLAN */
  874. vlan = batadv_softif_vlan_get(bat_priv, BATADV_NO_FLAGS);
  875. if (vlan) {
  876. batadv_softif_destroy_vlan(bat_priv, vlan);
  877. batadv_softif_vlan_put(vlan);
  878. }
  879. batadv_sysfs_del_meshif(soft_iface);
  880. unregister_netdevice(soft_iface);
  881. }
  882. /**
  883. * batadv_softif_destroy_netlink - deletion of batadv_soft_interface via netlink
  884. * @soft_iface: the to-be-removed batman-adv interface
  885. * @head: list pointer
  886. */
  887. static void batadv_softif_destroy_netlink(struct net_device *soft_iface,
  888. struct list_head *head)
  889. {
  890. struct batadv_priv *bat_priv = netdev_priv(soft_iface);
  891. struct batadv_hard_iface *hard_iface;
  892. struct batadv_softif_vlan *vlan;
  893. list_for_each_entry(hard_iface, &batadv_hardif_list, list) {
  894. if (hard_iface->soft_iface == soft_iface)
  895. batadv_hardif_disable_interface(hard_iface,
  896. BATADV_IF_CLEANUP_KEEP);
  897. }
  898. /* destroy the "untagged" VLAN */
  899. vlan = batadv_softif_vlan_get(bat_priv, BATADV_NO_FLAGS);
  900. if (vlan) {
  901. batadv_softif_destroy_vlan(bat_priv, vlan);
  902. batadv_softif_vlan_put(vlan);
  903. }
  904. batadv_sysfs_del_meshif(soft_iface);
  905. unregister_netdevice_queue(soft_iface, head);
  906. }
  907. bool batadv_softif_is_valid(const struct net_device *net_dev)
  908. {
  909. if (net_dev->netdev_ops->ndo_start_xmit == batadv_interface_tx)
  910. return true;
  911. return false;
  912. }
  913. struct rtnl_link_ops batadv_link_ops __read_mostly = {
  914. .kind = "batadv",
  915. .priv_size = sizeof(struct batadv_priv),
  916. .setup = batadv_softif_init_early,
  917. .dellink = batadv_softif_destroy_netlink,
  918. };
  919. /* ethtool */
  920. static int batadv_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
  921. {
  922. cmd->supported = 0;
  923. cmd->advertising = 0;
  924. ethtool_cmd_speed_set(cmd, SPEED_10);
  925. cmd->duplex = DUPLEX_FULL;
  926. cmd->port = PORT_TP;
  927. cmd->phy_address = 0;
  928. cmd->transceiver = XCVR_INTERNAL;
  929. cmd->autoneg = AUTONEG_DISABLE;
  930. cmd->maxtxpkt = 0;
  931. cmd->maxrxpkt = 0;
  932. return 0;
  933. }
  934. static void batadv_get_drvinfo(struct net_device *dev,
  935. struct ethtool_drvinfo *info)
  936. {
  937. strlcpy(info->driver, "B.A.T.M.A.N. advanced", sizeof(info->driver));
  938. strlcpy(info->version, BATADV_SOURCE_VERSION, sizeof(info->version));
  939. strlcpy(info->fw_version, "N/A", sizeof(info->fw_version));
  940. strlcpy(info->bus_info, "batman", sizeof(info->bus_info));
  941. }
  942. static u32 batadv_get_msglevel(struct net_device *dev)
  943. {
  944. return -EOPNOTSUPP;
  945. }
  946. static void batadv_set_msglevel(struct net_device *dev, u32 value)
  947. {
  948. }
  949. static u32 batadv_get_link(struct net_device *dev)
  950. {
  951. return 1;
  952. }
  953. /* Inspired by drivers/net/ethernet/dlink/sundance.c:1702
  954. * Declare each description string in struct.name[] to get fixed sized buffer
  955. * and compile time checking for strings longer than ETH_GSTRING_LEN.
  956. */
  957. static const struct {
  958. const char name[ETH_GSTRING_LEN];
  959. } batadv_counters_strings[] = {
  960. { "tx" },
  961. { "tx_bytes" },
  962. { "tx_dropped" },
  963. { "rx" },
  964. { "rx_bytes" },
  965. { "forward" },
  966. { "forward_bytes" },
  967. { "mgmt_tx" },
  968. { "mgmt_tx_bytes" },
  969. { "mgmt_rx" },
  970. { "mgmt_rx_bytes" },
  971. { "frag_tx" },
  972. { "frag_tx_bytes" },
  973. { "frag_rx" },
  974. { "frag_rx_bytes" },
  975. { "frag_fwd" },
  976. { "frag_fwd_bytes" },
  977. { "tt_request_tx" },
  978. { "tt_request_rx" },
  979. { "tt_response_tx" },
  980. { "tt_response_rx" },
  981. { "tt_roam_adv_tx" },
  982. { "tt_roam_adv_rx" },
  983. #ifdef CONFIG_BATMAN_ADV_DAT
  984. { "dat_get_tx" },
  985. { "dat_get_rx" },
  986. { "dat_put_tx" },
  987. { "dat_put_rx" },
  988. { "dat_cached_reply_tx" },
  989. #endif
  990. #ifdef CONFIG_BATMAN_ADV_NC
  991. { "nc_code" },
  992. { "nc_code_bytes" },
  993. { "nc_recode" },
  994. { "nc_recode_bytes" },
  995. { "nc_buffer" },
  996. { "nc_decode" },
  997. { "nc_decode_bytes" },
  998. { "nc_decode_failed" },
  999. { "nc_sniffed" },
  1000. #endif
  1001. };
  1002. static void batadv_get_strings(struct net_device *dev, u32 stringset, u8 *data)
  1003. {
  1004. if (stringset == ETH_SS_STATS)
  1005. memcpy(data, batadv_counters_strings,
  1006. sizeof(batadv_counters_strings));
  1007. }
  1008. static void batadv_get_ethtool_stats(struct net_device *dev,
  1009. struct ethtool_stats *stats, u64 *data)
  1010. {
  1011. struct batadv_priv *bat_priv = netdev_priv(dev);
  1012. int i;
  1013. for (i = 0; i < BATADV_CNT_NUM; i++)
  1014. data[i] = batadv_sum_counter(bat_priv, i);
  1015. }
  1016. static int batadv_get_sset_count(struct net_device *dev, int stringset)
  1017. {
  1018. if (stringset == ETH_SS_STATS)
  1019. return BATADV_CNT_NUM;
  1020. return -EOPNOTSUPP;
  1021. }