Lines Matching refs:l2
49 int l2_packet_get_own_addr(struct l2_packet_data *l2, u8 *addr)
51 os_memcpy(addr, l2->own_addr, ETH_ALEN);
57 static int l2_packet_init_libdnet(struct l2_packet_data *l2)
61 l2->eth = eth_open(l2->ifname);
62 if (!l2->eth) {
63 printf("Failed to open interface '%s'.\n", l2->ifname);
68 if (eth_get(l2->eth, &own_addr) < 0) {
70 l2->ifname);
72 eth_close(l2->eth);
73 l2->eth = NULL;
76 os_memcpy(l2->own_addr, own_addr.data, ETH_ALEN);
83 int l2_packet_send(struct l2_packet_data *l2, const u8 *dst_addr, u16 proto,
89 if (l2 == NULL)
92 if (l2->l2_hdr) {
94 ret = pcap_sendpacket(l2->pcap, buf, len);
96 ret = eth_send(l2->eth, buf, len);
105 os_memcpy(eth->h_source, l2->own_addr, ETH_ALEN);
110 ret = pcap_sendpacket(l2->pcap, (u8 *) eth, mlen);
112 ret = eth_send(l2->eth, (u8 *) eth, mlen);
125 struct l2_packet_data *l2 = eloop_ctx;
139 if (l2->l2_hdr) {
146 l2->rx_callback(l2->rx_callback_ctx, ethhdr->h_source, buf, len);
155 struct l2_packet_data *l2 = (struct l2_packet_data *) user;
164 if (l2->l2_hdr) {
171 l2->rx_callback(l2->rx_callback_ctx, ethhdr->h_source, buf, len);
176 l2->num_fast_poll = 3 * 50;
182 struct l2_packet_data *l2 = eloop_ctx;
186 if (l2->num_fast_poll > 0) {
188 l2->num_fast_poll--;
196 l2, pcap);
197 pcap_dispatch(pcap, 10, l2_packet_receive_cb, (u_char *) l2);
202 static int l2_packet_init_libpcap(struct l2_packet_data *l2,
211 os_snprintf(ifname, sizeof(ifname), "\\Device\\NPF_%s", l2->ifname);
213 l2->pcap = pcap_open_live(ifname, 2500, 0, 10, pcap_err);
214 if (l2->pcap == NULL) {
219 if (pcap_setnonblock(l2->pcap, 1, pcap_err) < 0)
221 pcap_geterr(l2->pcap));
223 pcap_lookupnet(l2->ifname, &pcap_netp, &pcap_maskp, pcap_err);
224 l2->pcap = pcap_open_live(l2->ifname, 2500, 0, 10, pcap_err);
225 if (l2->pcap == NULL) {
227 fprintf(stderr, "ifname='%s'\n", l2->ifname);
230 if (pcap_datalink(l2->pcap) != DLT_EN10MB &&
231 pcap_set_datalink(l2->pcap, DLT_EN10MB) < 0) {
233 pcap_geterr(l2->pcap));
241 MAC2STR(l2->own_addr), /* do not receive own packets */
242 MAC2STR(l2->own_addr), MAC2STR(pae_group_addr),
244 if (pcap_compile(l2->pcap, &pcap_fp, pcap_filter, 1, pcap_netp) < 0) {
245 fprintf(stderr, "pcap_compile: %s\n", pcap_geterr(l2->pcap));
249 if (pcap_setfilter(l2->pcap, &pcap_fp) < 0) {
250 fprintf(stderr, "pcap_setfilter: %s\n", pcap_geterr(l2->pcap));
263 if (ioctl(pcap_fileno(l2->pcap), BIOCIMMEDIATE, &on) < 0) {
266 __func__, l2->ifname, strerror(errno));
274 l2, l2->pcap);
276 eloop_register_read_sock(pcap_get_selectable_fd(l2->pcap),
277 l2_packet_receive, l2, l2->pcap);
290 struct l2_packet_data *l2;
292 l2 = os_zalloc(sizeof(struct l2_packet_data));
293 if (l2 == NULL)
295 os_strncpy(l2->ifname, ifname, sizeof(l2->ifname));
296 l2->rx_callback = rx_callback;
297 l2->rx_callback_ctx = rx_callback_ctx;
298 l2->l2_hdr = l2_hdr;
302 os_memcpy(l2->own_addr, own_addr, ETH_ALEN);
304 if (l2_packet_init_libdnet(l2))
308 if (l2_packet_init_libpcap(l2, protocol)) {
310 eth_close(l2->eth);
312 os_free(l2);
316 return l2;
320 void l2_packet_deinit(struct l2_packet_data *l2)
322 if (l2 == NULL)
326 eloop_cancel_timeout(l2_packet_receive_timeout, l2, l2->pcap);
328 if (l2->eth)
329 eth_close(l2->eth);
330 eloop_unregister_read_sock(pcap_get_selectable_fd(l2->pcap));
332 if (l2->pcap)
333 pcap_close(l2->pcap);
334 os_free(l2);
338 int l2_packet_get_ip_addr(struct l2_packet_data *l2, char *buf, size_t len)
352 if (os_strcmp(dev->name, l2->ifname) != 0)
374 void l2_packet_notify_auth_start(struct l2_packet_data *l2)
381 l2->num_fast_poll = 3 * 50;
382 eloop_cancel_timeout(l2_packet_receive_timeout, l2, l2->pcap);
384 l2, l2->pcap);