l2_packet_none.c
Go to the documentation of this file.
00001 /*
00002  * WPA Supplicant - Layer2 packet handling example with dummy functions
00003  * Copyright (c) 2003-2005, Jouni Malinen <j@w1.fi>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 2 as
00007  * published by the Free Software Foundation.
00008  *
00009  * Alternatively, this software may be distributed under the terms of BSD
00010  * license.
00011  *
00012  * See README and COPYING for more details.
00013  *
00014  * This file can be used as a starting point for layer2 packet implementation.
00015  */
00016 
00017 #include "includes.h"
00018 
00019 #include "common.h"
00020 #include "eloop.h"
00021 #include "l2_packet.h"
00022 
00023 
00024 struct l2_packet_data {
00025         char ifname[17];
00026         u8 own_addr[ETH_ALEN];
00027         void (*rx_callback)(void *ctx, const u8 *src_addr,
00028                             const u8 *buf, size_t len);
00029         void *rx_callback_ctx;
00030         int l2_hdr; /* whether to include layer 2 (Ethernet) header data
00031                      * buffers */
00032         int fd;
00033 };
00034 
00035 
00036 int l2_packet_get_own_addr(struct l2_packet_data *l2, u8 *addr)
00037 {
00038         os_memcpy(addr, l2->own_addr, ETH_ALEN);
00039         return 0;
00040 }
00041 
00042 
00043 int l2_packet_send(struct l2_packet_data *l2, const u8 *dst_addr, u16 proto,
00044                    const u8 *buf, size_t len)
00045 {
00046         if (l2 == NULL)
00047                 return -1;
00048 
00049         /*
00050          * TODO: Send frame (may need different implementation depending on
00051          * whether l2->l2_hdr is set).
00052          */
00053 
00054         return 0;
00055 }
00056 
00057 
00058 static void l2_packet_receive(int sock, void *eloop_ctx, void *sock_ctx)
00059 {
00060         struct l2_packet_data *l2 = eloop_ctx;
00061         u8 buf[2300];
00062         int res;
00063 
00064         /* TODO: receive frame (e.g., recv() using sock */
00065         buf[0] = 0;
00066         res = 0;
00067 
00068         l2->rx_callback(l2->rx_callback_ctx, NULL /* TODO: src addr */,
00069                         buf, res);
00070 }
00071 
00072 
00073 struct l2_packet_data * l2_packet_init(
00074         const char *ifname, const u8 *own_addr, unsigned short protocol,
00075         void (*rx_callback)(void *ctx, const u8 *src_addr,
00076                             const u8 *buf, size_t len),
00077         void *rx_callback_ctx, int l2_hdr)
00078 {
00079         struct l2_packet_data *l2;
00080 
00081         l2 = os_zalloc(sizeof(struct l2_packet_data));
00082         if (l2 == NULL)
00083                 return NULL;
00084         os_strlcpy(l2->ifname, ifname, sizeof(l2->ifname));
00085         l2->rx_callback = rx_callback;
00086         l2->rx_callback_ctx = rx_callback_ctx;
00087         l2->l2_hdr = l2_hdr;
00088 
00089         /*
00090          * TODO: open connection for receiving frames
00091          */
00092         l2->fd = -1;
00093         eloop_register_read_sock(l2->fd, l2_packet_receive, l2, NULL);
00094 
00095         return l2;
00096 }
00097 
00098 
00099 void l2_packet_deinit(struct l2_packet_data *l2)
00100 {
00101         if (l2 == NULL)
00102                 return;
00103 
00104         if (l2->fd >= 0) {
00105                 eloop_unregister_read_sock(l2->fd);
00106                 /* TODO: close connection */
00107         }
00108                 
00109         os_free(l2);
00110 }
00111 
00112 
00113 int l2_packet_get_ip_addr(struct l2_packet_data *l2, char *buf, size_t len)
00114 {
00115         /* TODO: get interface IP address */
00116         return -1;
00117 }
00118 
00119 
00120 void l2_packet_notify_auth_start(struct l2_packet_data *l2)
00121 {
00122         /* This function can be left empty */
00123 }


wpa_supplicant
Author(s): Package maintained by Blaise Gassend
autogenerated on Thu Apr 24 2014 15:34:35