Add some KTRs in bge(4) to count RX/TX packets per interrupt.
[dragonfly/port-amd64.git] / contrib / hostapd-0.4.9 / l2_packet.h
blobeb966d39ed696eb8fbf59e10c36291a956b3da43
1 /*
2 * WPA Supplicant - Layer2 packet interface definition
3 * Copyright (c) 2003-2005, Jouni Malinen <jkmaline@cc.hut.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
10 * license.
12 * See README and COPYING for more details.
14 * This file defines an interface for layer 2 (link layer) packet sending and
15 * receiving. l2_packet_linux.c is one implementation for such a layer 2
16 * implementation using Linux packet sockets and l2_packet_pcap.c another one
17 * using libpcap and libdnet. When porting %wpa_supplicant to other operating
18 * systems, a new l2_packet implementation may need to be added.
21 #ifndef L2_PACKET_H
22 #define L2_PACKET_H
24 #define MAC2STR(a) (a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5]
25 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
27 #ifndef ETH_P_EAPOL
28 #define ETH_P_EAPOL 0x888e
29 #endif
31 #ifndef ETH_P_RSN_PREAUTH
32 #define ETH_P_RSN_PREAUTH 0x88c7
33 #endif
35 /**
36 * struct l2_packet_data - Internal l2_packet data structure
38 * This structure is used by the l2_packet implementation to store its private
39 * data. Other files use a pointer to this data when calling the l2_packet
40 * functions, but the contents of this structure should not be used directly
41 * outside l2_packet implementation.
43 struct l2_packet_data;
45 struct l2_ethhdr {
46 u8 h_dest[ETH_ALEN];
47 u8 h_source[ETH_ALEN];
48 u16 h_proto;
49 } __attribute__ ((packed));
51 /**
52 * l2_packet_init - Initialize l2_packet interface
53 * @ifname: Interface name
54 * @own_addr: Optional own MAC address if available from driver interface or
55 * %NULL if not available
56 * @protocol: Ethernet protocol number in host byte order
57 * @rx_callback: Callback function that will be called for each received packet
58 * @rx_callback_ctx: Callback data (ctx) for calls to rx_callback()
59 * @l2_hdr: 1 = include layer 2 header, 0 = do not include header
60 * Returns: Pointer to internal data or %NULL on failure
62 * rx_callback function will be called with src_addr pointing to the source
63 * address (MAC address) of the the packet. If l2_hdr is set to 0, buf
64 * points to len bytes of the payload after the layer 2 header and similarly,
65 * TX buffers start with payload. This behavior can be changed by setting
66 * l2_hdr=1 to include the layer 2 header in the data buffer.
68 struct l2_packet_data * l2_packet_init(
69 const char *ifname, const u8 *own_addr, unsigned short protocol,
70 void (*rx_callback)(void *ctx, const u8 *src_addr,
71 const u8 *buf, size_t len),
72 void *rx_callback_ctx, int l2_hdr);
74 /**
75 * l2_packet_deinit - Deinitialize l2_packet interface
76 * @l2: Pointer to internal l2_packet data from l2_packet_init()
78 void l2_packet_deinit(struct l2_packet_data *l2);
80 /**
81 * l2_packet_get_own_addr - Get own layer 2 address
82 * @l2: Pointer to internal l2_packet data from l2_packet_init()
83 * @addr: Buffer for the own address (6 bytes)
84 * Returns: 0 on success, -1 on failure
86 int l2_packet_get_own_addr(struct l2_packet_data *l2, u8 *addr);
88 /**
89 * l2_packet_send - Send a packet
90 * @l2: Pointer to internal l2_packet data from l2_packet_init()
91 * @dst_addr: Destination address for the packet (only used if l2_hdr == 0)
92 * @proto: Protocol/ethertype for the packet in host byte order (only used if
93 * l2_hdr == 0)
94 * @buf: Packet contents to be sent; including layer 2 header if l2_hdr was
95 * set to 1 in l2_packet_init() call. Otherwise, only the payload of the packet
96 * is included.
97 * @len: Length of the buffer (including l2 header only if l2_hdr == 1)
98 * Returns: >=0 on success, <0 on failure
100 int l2_packet_send(struct l2_packet_data *l2, const u8 *dst_addr, u16 proto,
101 const u8 *buf, size_t len);
104 * l2_packet_get_ip_addr - Get the current IP address from the interface
105 * @l2: Pointer to internal l2_packet data from l2_packet_init()
106 * @buf: Buffer for the IP address in text format
107 * @len: Maximum buffer length
108 * Returns: 0 on success, -1 on failure
110 * This function can be used to get the current IP address from the interface
111 * bound to the l2_packet. This is mainly for status information and the IP
112 * address will be stored as an ASCII string. This function is not essential
113 * for %wpa_supplicant operation, so full implementation is not required.
114 * l2_packet implementation will need to define the function, but it can return
115 * -1 if the IP address information is not available.
117 int l2_packet_get_ip_addr(struct l2_packet_data *l2, char *buf, size_t len);
121 * l2_packet_notify_auth_start - Notify l2_packet about start of authentication
122 * @l2: Pointer to internal l2_packet data from l2_packet_init()
124 * This function is called when authentication is expected to start, e.g., when
125 * association has been completed, in order to prepare l2_packet implementation
126 * for EAPOL frames. This function is used mainly if the l2_packet code needs
127 * to do polling in which case it can increasing polling frequency. This can
128 * also be an empty function if the l2_packet implementation does not benefit
129 * from knowing about the starting authentication.
131 void l2_packet_notify_auth_start(struct l2_packet_data *l2);
133 #endif /* L2_PACKET_H */