1 /* 2 * Copyright (c) 2017-2018, The Linux Foundation. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions are 6 * met: 7 * * Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * * Redistributions in binary form must reproduce the above 10 * copyright notice, this list of conditions and the following 11 * disclaimer in the documentation and/or other materials provided 12 * with the distribution. 13 * * Neither the name of The Linux Foundation nor the names of its 14 * contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #include <stdint.h> 31 #include <fcntl.h> 32 #include <inttypes.h> 33 #include <sys/socket.h> 34 #include <netlink/genl/genl.h> 35 #include <netlink/genl/family.h> 36 #include <netlink/genl/ctrl.h> 37 #include <linux/rtnetlink.h> 38 #include <netpacket/packet.h> 39 #include <linux/filter.h> 40 #include <linux/errqueue.h> 41 42 #include <linux/pkt_sched.h> 43 #include <netlink/object-api.h> 44 #include <netlink/netlink.h> 45 #include <netlink/socket.h> 46 #include <hardware_legacy/wifi_hal.h> 47 #include <bits/in_addr.h> 48 49 #define INET6_ADDRSTRLEN 46 50 51 extern "C" { 52 const char* inet_ntop(int __af, const void* __src, char* __dst, socklen_t __size); 53 } 54 55 typedef struct { 56 uint16_t arp_req_count_from_netdev; 57 uint16_t arp_req_count_to_lower_mac; 58 uint16_t arp_req_rx_count_by_lower_mac; 59 uint16_t arp_req_count_tx_success; 60 uint16_t arp_rsp_rx_count_by_lower_mac; 61 uint16_t arp_rsp_rx_count_by_upper_mac; 62 uint16_t arp_rsp_count_to_netdev; 63 uint16_t arp_rsp_count_out_of_order_drop; 64 uint8_t ap_link_active; 65 uint8_t is_duplicate_addr_detection; 66 } nud_stats; 67 68 typedef struct { 69 uint16_t pkt_req_count_from_netdev; 70 uint16_t pkt_req_count_to_lower_mac; 71 uint16_t pkt_req_rx_count_by_lower_mac; 72 uint16_t pkt_req_count_tx_success; 73 uint16_t pkt_rsp_rx_count_by_lower_mac; 74 uint16_t pkt_rsp_rx_count_by_upper_mac; 75 uint16_t pkt_rsp_count_to_netdev; 76 uint16_t pkt_rsp_count_out_of_order_drop; 77 } pkt_stats; 78 79 typedef struct{ 80 u32 pkt_Type; 81 char* domain_name; 82 u32 src_port; 83 u32 dst_port; 84 struct in_addr ipv4_addr; 85 u8 ipv6_addr[16]; 86 pkt_stats stats; 87 } cmdData; 88 89 /* callback for get NUD stats */ 90 typedef struct { 91 void (*on_pkt_stats_results) (nud_stats *stats, 92 int mnumStats, cmdData *pkt_stats); 93 } pkt_stats_result_handler; 94 95 wifi_error wifi_set_nud_stats(wifi_interface_handle iface, u32 gw_addr, 96 cmdData set_data); 97 wifi_error wifi_get_nud_stats(wifi_interface_handle iface, 98 pkt_stats_result_handler handler); 99 wifi_error wifi_clear_nud_stats(wifi_interface_handle iface, 100 cmdData set_data); 101