wpa_supplicant / hostapd
2.5
|
WPA Supplicant - Layer2 packet handling with WinPcap RX thread. More...
#include "includes.h"
#include <pcap.h>
#include "common.h"
#include "eloop.h"
#include "l2_packet.h"
Data Structures | |
struct | l2_packet_data |
Functions | |
int | l2_packet_get_own_addr (struct l2_packet_data *l2, u8 *addr) |
Get own layer 2 address. More... | |
int | l2_packet_send (struct l2_packet_data *l2, const u8 *dst_addr, u16 proto, const u8 *buf, size_t len) |
Send a packet. More... | |
struct l2_packet_data * | l2_packet_init (const char *ifname, const u8 *own_addr, unsigned short protocol, void(*rx_callback)(void *ctx, const u8 *src_addr, const u8 *buf, size_t len), void *rx_callback_ctx, int l2_hdr) |
Initialize l2_packet interface. More... | |
struct l2_packet_data * | l2_packet_init_bridge (const char *br_ifname, const char *ifname, const u8 *own_addr, unsigned short protocol, void(*rx_callback)(void *ctx, const u8 *src_addr, const u8 *buf, size_t len), void *rx_callback_ctx, int l2_hdr) |
Like l2_packet_init() but with bridge workaround. More... | |
void | l2_packet_deinit (struct l2_packet_data *l2) |
Deinitialize l2_packet interface. More... | |
int | l2_packet_get_ip_addr (struct l2_packet_data *l2, char *buf, size_t len) |
Get the current IP address from the interface. More... | |
void | l2_packet_notify_auth_start (struct l2_packet_data *l2) |
Notify l2_packet about start of authentication. More... | |
WPA Supplicant - Layer2 packet handling with WinPcap RX thread.
This l2_packet implementation is explicitly for WinPcap and Windows events. l2_packet_pcap.c has support for WinPcap, but it requires polling to receive frames which means relatively long latency for EAPOL RX processing. The implementation here uses a separate thread to allow WinPcap to be receiving all the time to reduce latency for EAPOL receiving from about 100 ms to 3 ms when comparing l2_packet_pcap.c to l2_packet_winpcap.c. Extra sleep of 50 ms is added in to receive thread whenever no EAPOL frames has been received for a while. Whenever an EAPOL handshake is expected, this sleep is removed.
The RX thread receives a frame and signals main thread through Windows event about the availability of a new frame. Processing the received frame is synchronized with pair of Windows events so that no extra buffer or queuing mechanism is needed. This implementation requires Windows specific event loop implementation, i.e., eloop_win.c.
WinPcap has pcap_getevent() that could, in theory at least, be used to implement this kind of waiting with a simpler single-thread design. However, that event handle is not really signaled immediately when receiving each frame, so it does not really work for this kind of use.
void l2_packet_deinit | ( | struct l2_packet_data * | l2 | ) |
Deinitialize l2_packet interface.
l2 | Pointer to internal l2_packet data from l2_packet_init() |
int l2_packet_get_ip_addr | ( | struct l2_packet_data * | l2, |
char * | buf, | ||
size_t | len | ||
) |
Get the current IP address from the interface.
l2 | Pointer to internal l2_packet data from l2_packet_init() |
buf | Buffer for the IP address in text format |
len | Maximum buffer length |
This function can be used to get the current IP address from the interface bound to the l2_packet. This is mainly for status information and the IP address will be stored as an ASCII string. This function is not essential for wpa_supplicant operation, so full implementation is not required. l2_packet implementation will need to define the function, but it can return -1 if the IP address information is not available.
int l2_packet_get_own_addr | ( | struct l2_packet_data * | l2, |
u8 * | addr | ||
) |
Get own layer 2 address.
l2 | Pointer to internal l2_packet data from l2_packet_init() |
addr | Buffer for the own address (6 bytes) |
struct l2_packet_data* l2_packet_init | ( | const char * | ifname, |
const u8 * | own_addr, | ||
unsigned short | protocol, | ||
void(*)(void *ctx, const u8 *src_addr, const u8 *buf, size_t len) | rx_callback, | ||
void * | rx_callback_ctx, | ||
int | l2_hdr | ||
) |
Initialize l2_packet interface.
ifname | Interface name |
own_addr | Optional own MAC address if available from driver interface or NULL if not available |
protocol | Ethernet protocol number in host byte order |
rx_callback | Callback function that will be called for each received packet |
rx_callback_ctx | Callback data (ctx) for calls to rx_callback() |
l2_hdr | 1 = include layer 2 header, 0 = do not include header |
rx_callback function will be called with src_addr pointing to the source address (MAC address) of the the packet. If l2_hdr is set to 0, buf points to len bytes of the payload after the layer 2 header and similarly, TX buffers start with payload. This behavior can be changed by setting l2_hdr=1 to include the layer 2 header in the data buffer.
struct l2_packet_data* l2_packet_init_bridge | ( | const char * | br_ifname, |
const char * | ifname, | ||
const u8 * | own_addr, | ||
unsigned short | protocol, | ||
void(*)(void *ctx, const u8 *src_addr, const u8 *buf, size_t len) | rx_callback, | ||
void * | rx_callback_ctx, | ||
int | l2_hdr | ||
) |
Like l2_packet_init() but with bridge workaround.
This version of l2_packet_init() can be used to enable a workaround for Linux packet socket in case of a station interface in a bridge.
void l2_packet_notify_auth_start | ( | struct l2_packet_data * | l2 | ) |
Notify l2_packet about start of authentication.
l2 | Pointer to internal l2_packet data from l2_packet_init() |
This function is called when authentication is expected to start, e.g., when association has been completed, in order to prepare l2_packet implementation for EAPOL frames. This function is used mainly if the l2_packet code needs to do polling in which case it can increasing polling frequency. This can also be an empty function if the l2_packet implementation does not benefit from knowing about the starting authentication.
int l2_packet_send | ( | struct l2_packet_data * | l2, |
const u8 * | dst_addr, | ||
u16 | proto, | ||
const u8 * | buf, | ||
size_t | len | ||
) |
Send a packet.
l2 | Pointer to internal l2_packet data from l2_packet_init() |
dst_addr | Destination address for the packet (only used if l2_hdr == 0) |
proto | Protocol/ethertype for the packet in host byte order (only used if l2_hdr == 0) |
buf | Packet contents to be sent; including layer 2 header if l2_hdr was set to 1 in l2_packet_init() call. Otherwise, only the payload of the packet is included. |
len | Length of the buffer (including l2 header only if l2_hdr == 1) |