Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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;
00031
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
00051
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
00065 buf[0] = 0;
00066 res = 0;
00067
00068 l2->rx_callback(l2->rx_callback_ctx, NULL ,
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
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
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
00116 return -1;
00117 }
00118
00119
00120 void l2_packet_notify_auth_start(struct l2_packet_data *l2)
00121 {
00122
00123 }