driver_test: Remove forgotten, unused prototypes
[hostap-gosc2009.git] / src / l2_packet / l2_packet_none.c
blob5e3f6e972384fa663fc3e9f09aa1a2a394f5cc7e
1 /*
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
10 * license.
12 * See README and COPYING for more details.
14 * This file can be used as a starting point for layer2 packet implementation.
17 #include "includes.h"
19 #include "common.h"
20 #include "eloop.h"
21 #include "l2_packet.h"
24 struct l2_packet_data {
25 char ifname[17];
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
31 * buffers */
32 int fd;
36 int l2_packet_get_own_addr(struct l2_packet_data *l2, u8 *addr)
38 os_memcpy(addr, l2->own_addr, ETH_ALEN);
39 return 0;
43 int l2_packet_send(struct l2_packet_data *l2, const u8 *dst_addr, u16 proto,
44 const u8 *buf, size_t len)
46 if (l2 == NULL)
47 return -1;
50 * TODO: Send frame (may need different implementation depending on
51 * whether l2->l2_hdr is set).
54 return 0;
58 static void l2_packet_receive(int sock, void *eloop_ctx, void *sock_ctx)
60 struct l2_packet_data *l2 = eloop_ctx;
61 u8 buf[2300];
62 int res;
64 /* TODO: receive frame (e.g., recv() using sock */
65 buf[0] = 0;
66 res = 0;
68 l2->rx_callback(l2->rx_callback_ctx, NULL /* TODO: src addr */,
69 buf, res);
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));
82 if (l2 == NULL)
83 return NULL;
84 os_strlcpy(l2->ifname, ifname, sizeof(l2->ifname));
85 l2->rx_callback = rx_callback;
86 l2->rx_callback_ctx = rx_callback_ctx;
87 l2->l2_hdr = l2_hdr;
90 * TODO: open connection for receiving frames
92 l2->fd = -1;
93 eloop_register_read_sock(l2->fd, l2_packet_receive, l2, NULL);
95 return l2;
99 void l2_packet_deinit(struct l2_packet_data *l2)
101 if (l2 == NULL)
102 return;
104 if (l2->fd >= 0) {
105 eloop_unregister_read_sock(l2->fd);
106 /* TODO: close connection */
109 os_free(l2);
113 int l2_packet_get_ip_addr(struct l2_packet_data *l2, char *buf, size_t len)
115 /* TODO: get interface IP address */
116 return -1;
120 void l2_packet_notify_auth_start(struct l2_packet_data *l2)
122 /* This function can be left empty */