Lines Matching refs:l2

43 int l2_packet_get_own_addr(struct l2_packet_data *l2, u8 *addr)
45 os_memcpy(addr, l2->own_addr, ETH_ALEN);
51 static int l2_packet_init_libdnet(struct l2_packet_data *l2)
55 l2->eth = eth_open(l2->ifname);
56 if (!l2->eth) {
59 l2->ifname, strerror(errno));
63 if (eth_get(l2->eth, &own_addr) < 0) {
66 l2->ifname, strerror(errno));
67 eth_close(l2->eth);
68 l2->eth = NULL;
71 os_memcpy(l2->own_addr, own_addr.data, ETH_ALEN);
78 int l2_packet_send(struct l2_packet_data *l2, const u8 *dst_addr, u16 proto,
84 if (l2 == NULL)
87 if (l2->l2_hdr) {
89 ret = pcap_sendpacket(l2->pcap, buf, len);
91 ret = eth_send(l2->eth, buf, len);
100 os_memcpy(eth->h_source, l2->own_addr, ETH_ALEN);
105 ret = pcap_sendpacket(l2->pcap, (u8 *) eth, mlen);
107 ret = eth_send(l2->eth, (u8 *) eth, mlen);
120 struct l2_packet_data *l2 = eloop_ctx;
134 if (l2->l2_hdr) {
141 l2->rx_callback(l2->rx_callback_ctx, ethhdr->h_source, buf, len);
150 struct l2_packet_data *l2 = (struct l2_packet_data *) user;
159 if (l2->l2_hdr) {
166 l2->rx_callback(l2->rx_callback_ctx, ethhdr->h_source, buf, len);
171 l2->num_fast_poll = 3 * 50;
177 struct l2_packet_data *l2 = eloop_ctx;
181 if (l2->num_fast_poll > 0) {
183 l2->num_fast_poll--;
191 l2, pcap);
192 pcap_dispatch(pcap, 10, l2_packet_receive_cb, (u_char *) l2);
197 static int l2_packet_init_libpcap(struct l2_packet_data *l2,
206 os_snprintf(ifname, sizeof(ifname), "\\Device\\NPF_%s", l2->ifname);
208 l2->pcap = pcap_open_live(ifname, 2500, 0, 10, pcap_err);
209 if (l2->pcap == NULL) {
214 if (pcap_setnonblock(l2->pcap, 1, pcap_err) < 0)
216 pcap_geterr(l2->pcap));
218 pcap_lookupnet(l2->ifname, &pcap_netp, &pcap_maskp, pcap_err);
219 l2->pcap = pcap_open_live(l2->ifname, 2500, 0, 10, pcap_err);
220 if (l2->pcap == NULL) {
222 fprintf(stderr, "ifname='%s'\n", l2->ifname);
225 if (pcap_datalink(l2->pcap) != DLT_EN10MB &&
226 pcap_set_datalink(l2->pcap, DLT_EN10MB) < 0) {
228 pcap_geterr(l2->pcap));
236 MAC2STR(l2->own_addr), /* do not receive own packets */
237 MAC2STR(l2->own_addr), MAC2STR(pae_group_addr),
239 if (pcap_compile(l2->pcap, &pcap_fp, pcap_filter, 1, pcap_netp) < 0) {
240 fprintf(stderr, "pcap_compile: %s\n", pcap_geterr(l2->pcap));
244 if (pcap_setfilter(l2->pcap, &pcap_fp) < 0) {
245 fprintf(stderr, "pcap_setfilter: %s\n", pcap_geterr(l2->pcap));
258 if (ioctl(pcap_fileno(l2->pcap), BIOCIMMEDIATE, &on) < 0) {
261 __func__, l2->ifname, strerror(errno));
269 l2, l2->pcap);
271 eloop_register_read_sock(pcap_get_selectable_fd(l2->pcap),
272 l2_packet_receive, l2, l2->pcap);
285 struct l2_packet_data *l2;
287 l2 = os_zalloc(sizeof(struct l2_packet_data));
288 if (l2 == NULL)
290 os_strlcpy(l2->ifname, ifname, sizeof(l2->ifname));
291 l2->rx_callback = rx_callback;
292 l2->rx_callback_ctx = rx_callback_ctx;
293 l2->l2_hdr = l2_hdr;
297 os_memcpy(l2->own_addr, own_addr, ETH_ALEN);
299 if (l2_packet_init_libdnet(l2))
303 if (l2_packet_init_libpcap(l2, protocol)) {
305 eth_close(l2->eth);
307 os_free(l2);
311 return l2;
327 void l2_packet_deinit(struct l2_packet_data *l2)
329 if (l2 == NULL)
333 eloop_cancel_timeout(l2_packet_receive_timeout, l2, l2->pcap);
335 if (l2->eth)
336 eth_close(l2->eth);
337 eloop_unregister_read_sock(pcap_get_selectable_fd(l2->pcap));
339 if (l2->pcap)
340 pcap_close(l2->pcap);
341 os_free(l2);
345 int l2_packet_get_ip_addr(struct l2_packet_data *l2, char *buf, size_t len)
359 if (os_strcmp(dev->name, l2->ifname) != 0)
381 void l2_packet_notify_auth_start(struct l2_packet_data *l2)
388 l2->num_fast_poll = 3 * 50;
389 eloop_cancel_timeout(l2_packet_receive_timeout, l2, l2->pcap);
391 l2, l2->pcap);
396 int l2_packet_set_packet_filter(struct l2_packet_data *l2,