2 * WPA Supplicant - Layer2 packet handling example with dummy functions
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
12 * See README and COPYING for more details.
14 * This file can be used as a starting point for layer2 packet implementation.
21 #include "l2_packet.h"
24 struct l2_packet_data
{
26 u8 own_addr
[ETH_ALEN
];
27 void (*rx_callback
)(void *ctx
, const u8
*src_addr
,
28 const u8
*buf
, size_t len
);
29 void *rx_callback_ctx
;
30 int l2_hdr
; /* whether to include layer 2 (Ethernet) header data
36 int l2_packet_get_own_addr(struct l2_packet_data
*l2
, u8
*addr
)
38 os_memcpy(addr
, l2
->own_addr
, ETH_ALEN
);
43 int l2_packet_send(struct l2_packet_data
*l2
, const u8
*dst_addr
, u16 proto
,
44 const u8
*buf
, size_t len
)
50 * TODO: Send frame (may need different implementation depending on
51 * whether l2->l2_hdr is set).
58 static void l2_packet_receive(int sock
, void *eloop_ctx
, void *sock_ctx
)
60 struct l2_packet_data
*l2
= eloop_ctx
;
64 /* TODO: receive frame (e.g., recv() using sock */
68 l2
->rx_callback(l2
->rx_callback_ctx
, NULL
/* TODO: src addr */,
73 struct l2_packet_data
* l2_packet_init(
74 const char *ifname
, const u8
*own_addr
, unsigned short protocol
,
75 void (*rx_callback
)(void *ctx
, const u8
*src_addr
,
76 const u8
*buf
, size_t len
),
77 void *rx_callback_ctx
, int l2_hdr
)
79 struct l2_packet_data
*l2
;
81 l2
= os_zalloc(sizeof(struct l2_packet_data
));
84 os_strlcpy(l2
->ifname
, ifname
, sizeof(l2
->ifname
));
85 l2
->rx_callback
= rx_callback
;
86 l2
->rx_callback_ctx
= rx_callback_ctx
;
90 * TODO: open connection for receiving frames
93 eloop_register_read_sock(l2
->fd
, l2_packet_receive
, l2
, NULL
);
99 void l2_packet_deinit(struct l2_packet_data
*l2
)
105 eloop_unregister_read_sock(l2
->fd
);
106 /* TODO: close connection */
113 int l2_packet_get_ip_addr(struct l2_packet_data
*l2
, char *buf
, size_t len
)
115 /* TODO: get interface IP address */
120 void l2_packet_notify_auth_start(struct l2_packet_data
*l2
)
122 /* This function can be left empty */