Add a reference for /usr/share/examples/rconfig to the rconfig manual page.
[dragonfly.git] / contrib / hostapd-0.5.8 / l2_packet.h
blob540f0a116b5686b23bb153a33bc46f9da01a0cf6
1 /*
2 * WPA Supplicant - Layer2 packet interface definition
3 * Copyright (c) 2003-2005, Jouni Malinen <j@w1.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 #ifdef _MSC_VER
46 #pragma pack(push, 1)
47 #endif /* _MSC_VER */
49 struct l2_ethhdr {
50 u8 h_dest[ETH_ALEN];
51 u8 h_source[ETH_ALEN];
52 u16 h_proto;
53 } STRUCT_PACKED;
55 #ifdef _MSC_VER
56 #pragma pack(pop)
57 #endif /* _MSC_VER */
59 /**
60 * l2_packet_init - Initialize l2_packet interface
61 * @ifname: Interface name
62 * @own_addr: Optional own MAC address if available from driver interface or
63 * %NULL if not available
64 * @protocol: Ethernet protocol number in host byte order
65 * @rx_callback: Callback function that will be called for each received packet
66 * @rx_callback_ctx: Callback data (ctx) for calls to rx_callback()
67 * @l2_hdr: 1 = include layer 2 header, 0 = do not include header
68 * Returns: Pointer to internal data or %NULL on failure
70 * rx_callback function will be called with src_addr pointing to the source
71 * address (MAC address) of the the packet. If l2_hdr is set to 0, buf
72 * points to len bytes of the payload after the layer 2 header and similarly,
73 * TX buffers start with payload. This behavior can be changed by setting
74 * l2_hdr=1 to include the layer 2 header in the data buffer.
76 struct l2_packet_data * l2_packet_init(
77 const char *ifname, const u8 *own_addr, unsigned short protocol,
78 void (*rx_callback)(void *ctx, const u8 *src_addr,
79 const u8 *buf, size_t len),
80 void *rx_callback_ctx, int l2_hdr);
82 /**
83 * l2_packet_deinit - Deinitialize l2_packet interface
84 * @l2: Pointer to internal l2_packet data from l2_packet_init()
86 void l2_packet_deinit(struct l2_packet_data *l2);
88 /**
89 * l2_packet_get_own_addr - Get own layer 2 address
90 * @l2: Pointer to internal l2_packet data from l2_packet_init()
91 * @addr: Buffer for the own address (6 bytes)
92 * Returns: 0 on success, -1 on failure
94 int l2_packet_get_own_addr(struct l2_packet_data *l2, u8 *addr);
96 /**
97 * l2_packet_send - Send a packet
98 * @l2: Pointer to internal l2_packet data from l2_packet_init()
99 * @dst_addr: Destination address for the packet (only used if l2_hdr == 0)
100 * @proto: Protocol/ethertype for the packet in host byte order (only used if
101 * l2_hdr == 0)
102 * @buf: Packet contents to be sent; including layer 2 header if l2_hdr was
103 * set to 1 in l2_packet_init() call. Otherwise, only the payload of the packet
104 * is included.
105 * @len: Length of the buffer (including l2 header only if l2_hdr == 1)
106 * Returns: >=0 on success, <0 on failure
108 int l2_packet_send(struct l2_packet_data *l2, const u8 *dst_addr, u16 proto,
109 const u8 *buf, size_t len);
112 * l2_packet_get_ip_addr - Get the current IP address from the interface
113 * @l2: Pointer to internal l2_packet data from l2_packet_init()
114 * @buf: Buffer for the IP address in text format
115 * @len: Maximum buffer length
116 * Returns: 0 on success, -1 on failure
118 * This function can be used to get the current IP address from the interface
119 * bound to the l2_packet. This is mainly for status information and the IP
120 * address will be stored as an ASCII string. This function is not essential
121 * for %wpa_supplicant operation, so full implementation is not required.
122 * l2_packet implementation will need to define the function, but it can return
123 * -1 if the IP address information is not available.
125 int l2_packet_get_ip_addr(struct l2_packet_data *l2, char *buf, size_t len);
129 * l2_packet_notify_auth_start - Notify l2_packet about start of authentication
130 * @l2: Pointer to internal l2_packet data from l2_packet_init()
132 * This function is called when authentication is expected to start, e.g., when
133 * association has been completed, in order to prepare l2_packet implementation
134 * for EAPOL frames. This function is used mainly if the l2_packet code needs
135 * to do polling in which case it can increasing polling frequency. This can
136 * also be an empty function if the l2_packet implementation does not benefit
137 * from knowing about the starting authentication.
139 void l2_packet_notify_auth_start(struct l2_packet_data *l2);
141 #endif /* L2_PACKET_H */