2 * WPA Supplicant - Layer2 packet interface definition
3 * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
8 * This file defines an interface for layer 2 (link layer) packet sending and
9 * receiving. l2_packet_linux.c is one implementation for such a layer 2
10 * implementation using Linux packet sockets and l2_packet_pcap.c another one
11 * using libpcap and libdnet. When porting %wpa_supplicant to other operating
12 * systems, a new l2_packet implementation may need to be added.
19 * struct l2_packet_data - Internal l2_packet data structure
21 * This structure is used by the l2_packet implementation to store its private
22 * data. Other files use a pointer to this data when calling the l2_packet
23 * functions, but the contents of this structure should not be used directly
24 * outside l2_packet implementation.
26 struct l2_packet_data;
34 u8 h_source[ETH_ALEN];
42 enum l2_packet_filter_type {
43 L2_PACKET_FILTER_DHCP,
44 L2_PACKET_FILTER_NDISC,
45 L2_PACKET_FILTER_PKTTYPE,
49 * l2_packet_init - Initialize l2_packet interface
50 * @ifname: Interface name
51 * @own_addr: Optional own MAC address if available from driver interface or
52 * %NULL if not available
53 * @protocol: Ethernet protocol number in host byte order
54 * @rx_callback: Callback function that will be called for each received packet
55 * @rx_callback_ctx: Callback data (ctx) for calls to rx_callback()
56 * @l2_hdr: 1 = include layer 2 header, 0 = do not include header
57 * Returns: Pointer to internal data or %NULL on failure
59 * rx_callback function will be called with src_addr pointing to the source
60 * address (MAC address) of the the packet. If l2_hdr is set to 0, buf
61 * points to len bytes of the payload after the layer 2 header and similarly,
62 * TX buffers start with payload. This behavior can be changed by setting
63 * l2_hdr=1 to include the layer 2 header in the data buffer.
65 struct l2_packet_data * l2_packet_init(
66 const char *ifname, const u8 *own_addr, unsigned short protocol,
67 void (*rx_callback)(void *ctx, const u8 *src_addr,
68 const u8 *buf, size_t len),
69 void *rx_callback_ctx, int l2_hdr);
72 * l2_packet_init_bridge - Like l2_packet_init() but with bridge workaround
74 * This version of l2_packet_init() can be used to enable a workaround for Linux
75 * packet socket in case of a station interface in a bridge.
77 struct l2_packet_data * l2_packet_init_bridge(
78 const char *br_ifname, const char *ifname, const u8 *own_addr,
79 unsigned short protocol,
80 void (*rx_callback)(void *ctx, const u8 *src_addr,
81 const u8 *buf, size_t len),
82 void *rx_callback_ctx, int l2_hdr);
85 * l2_packet_deinit - Deinitialize l2_packet interface
86 * @l2: Pointer to internal l2_packet data from l2_packet_init()
88 void l2_packet_deinit(struct l2_packet_data *l2);
91 * l2_packet_get_own_addr - Get own layer 2 address
92 * @l2: Pointer to internal l2_packet data from l2_packet_init()
93 * @addr: Buffer for the own address (6 bytes)
94 * Returns: 0 on success, -1 on failure
96 int l2_packet_get_own_addr(struct l2_packet_data *l2, u8 *addr);
99 * l2_packet_send - Send a packet
100 * @l2: Pointer to internal l2_packet data from l2_packet_init()
101 * @dst_addr: Destination address for the packet (only used if l2_hdr == 0)
102 * @proto: Protocol/ethertype for the packet in host byte order (only used if
104 * @buf: Packet contents to be sent; including layer 2 header if l2_hdr was
105 * set to 1 in l2_packet_init() call. Otherwise, only the payload of the packet
107 * @len: Length of the buffer (including l2 header only if l2_hdr == 1)
108 * Returns: >=0 on success, <0 on failure
110 int l2_packet_send(struct l2_packet_data *l2, const u8 *dst_addr, u16 proto,
111 const u8 *buf, size_t len);
114 * l2_packet_get_ip_addr - Get the current IP address from the interface
115 * @l2: Pointer to internal l2_packet data from l2_packet_init()
116 * @buf: Buffer for the IP address in text format
117 * @len: Maximum buffer length
118 * Returns: 0 on success, -1 on failure
120 * This function can be used to get the current IP address from the interface
121 * bound to the l2_packet. This is mainly for status information and the IP
122 * address will be stored as an ASCII string. This function is not essential
123 * for %wpa_supplicant operation, so full implementation is not required.
124 * l2_packet implementation will need to define the function, but it can return
125 * -1 if the IP address information is not available.
127 int l2_packet_get_ip_addr(struct l2_packet_data *l2, char *buf, size_t len);
131 * l2_packet_notify_auth_start - Notify l2_packet about start of authentication
132 * @l2: Pointer to internal l2_packet data from l2_packet_init()
134 * This function is called when authentication is expected to start, e.g., when
135 * association has been completed, in order to prepare l2_packet implementation
136 * for EAPOL frames. This function is used mainly if the l2_packet code needs
137 * to do polling in which case it can increasing polling frequency. This can
138 * also be an empty function if the l2_packet implementation does not benefit
139 * from knowing about the starting authentication.
141 void l2_packet_notify_auth_start(struct l2_packet_data *l2);
144 * l2_packet_set_packet_filter - Set socket filter for l2_packet
145 * @l2: Pointer to internal l2_packet data from l2_packet_init()
146 * @type: enum l2_packet_filter_type, type of filter
147 * Returns: 0 on success, -1 on failure
149 * This function is used to set the socket filter for l2_packet socket.
152 int l2_packet_set_packet_filter(struct l2_packet_data *l2,
153 enum l2_packet_filter_type type);
155 #endif /* L2_PACKET_H */