2 * WPA Supplicant - Layer2 packet handling example with dummy functions
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 can be used as a starting point for layer2 packet implementation.
15 #include "l2_packet.h"
18 struct l2_packet_data {
20 u8 own_addr[ETH_ALEN];
21 void (*rx_callback)(void *ctx, const u8 *src_addr,
22 const u8 *buf, size_t len);
23 void *rx_callback_ctx;
24 int l2_hdr; /* whether to include layer 2 (Ethernet) header data
30 int l2_packet_get_own_addr(struct l2_packet_data *l2, u8 *addr)
32 os_memcpy(addr, l2->own_addr, ETH_ALEN);
37 int l2_packet_send(struct l2_packet_data *l2, const u8 *dst_addr, u16 proto,
38 const u8 *buf, size_t len)
44 * TODO: Send frame (may need different implementation depending on
45 * whether l2->l2_hdr is set).
52 static void l2_packet_receive(int sock, void *eloop_ctx, void *sock_ctx)
54 struct l2_packet_data *l2 = eloop_ctx;
58 /* TODO: receive frame (e.g., recv() using sock */
62 l2->rx_callback(l2->rx_callback_ctx, NULL /* TODO: src addr */,
67 struct l2_packet_data * l2_packet_init(
68 const char *ifname, const u8 *own_addr, unsigned short protocol,
69 void (*rx_callback)(void *ctx, const u8 *src_addr,
70 const u8 *buf, size_t len),
71 void *rx_callback_ctx, int l2_hdr)
73 struct l2_packet_data *l2;
75 l2 = os_zalloc(sizeof(struct l2_packet_data));
78 os_strlcpy(l2->ifname, ifname, sizeof(l2->ifname));
79 l2->rx_callback = rx_callback;
80 l2->rx_callback_ctx = rx_callback_ctx;
84 * TODO: open connection for receiving frames
87 eloop_register_read_sock(l2->fd, l2_packet_receive, l2, NULL);
93 void l2_packet_deinit(struct l2_packet_data *l2)
99 eloop_unregister_read_sock(l2->fd);
100 /* TODO: close connection */
107 int l2_packet_get_ip_addr(struct l2_packet_data *l2, char *buf, size_t len)
109 /* TODO: get interface IP address */
114 void l2_packet_notify_auth_start(struct l2_packet_data *l2)
116 /* This function can be left empty */