diff --git a/src/eapol.c b/src/eapol.c index c7f75b55..e9879cde 100644 --- a/src/eapol.c +++ b/src/eapol.c @@ -25,6 +25,13 @@ #endif #include +#include +#include +#include +#include +#include +#include +#include #include #include "sha1.h" @@ -828,6 +835,43 @@ void __eapol_set_protocol_version(enum eapol_protocol_version version) protocol_version = version; } +struct l_io *eapol_open_pae(uint32_t index) +{ + struct l_io *io; + struct sockaddr_ll sll; + int fd; + + fd = socket(PF_PACKET, SOCK_RAW | SOCK_CLOEXEC, 0); + if (fd < 0) { + l_error("Failed to create PAE socket %s (%d)", + strerror(errno), errno); + return NULL; + } + + memset(&sll, 0, sizeof(sll)); + sll.sll_family = AF_PACKET; + sll.sll_protocol = htons(ETH_P_PAE); + sll.sll_ifindex = index; + + if (bind(fd, (struct sockaddr *) &sll, sizeof(sll)) < 0) { + l_error("Failed to bind PAE socket %s (%d)", + strerror(errno), errno); + close(fd); + return NULL; + } + + io = l_io_new(fd); + if (!io) { + l_error("Failed to create IO handling for PAE socket "); + close(fd); + return NULL; + } + + l_io_set_close_on_destroy(io, true); + + return io; +} + bool eapol_init() { state_machines = l_hashmap_new(); diff --git a/src/eapol.h b/src/eapol.h index 3ef92871..f4ae0dcc 100644 --- a/src/eapol.h +++ b/src/eapol.h @@ -146,6 +146,7 @@ void eapol_sm_set_ap_rsn(struct eapol_sm *sm, const uint8_t *rsn_ie, size_t len); void eapol_sm_set_own_rsn(struct eapol_sm *sm, const uint8_t *rsn_ie, size_t len); +struct l_io *eapol_open_pae(uint32_t index); void eapol_start(int ifindex, struct eapol_sm *sm);