static void handle_data(struct hostapd_data *hapd, unsigned char *buf, size_t len) { struct ieee8023_hdr *hdr; u8 *pos, *sa; size_t left; /* must contain at least ieee8023_hdr 6 byte source, 6 byte dest, * 2 byte ethertype */ if (len < 14) { wpa_printf(MSG_MSGDUMP, "handle_data: too short (%lu)", (unsigned long) len); return; } hdr = (struct ieee8023_hdr *) buf; switch (ntohs(hdr->ethertype)) { case ETH_P_PAE: wpa_printf(MSG_MSGDUMP, "Received EAPOL packet"); sa = hdr->src; wired_possible_new_sta(hapd, sa); pos = (u8 *) (hdr + 1); left = len - sizeof(*hdr); ieee802_1x_receive(hapd, sa, pos, left); break; default: wpa_printf(MSG_DEBUG, "Unknown ethertype 0x%04x in data frame", ntohs(hdr->ethertype)); break; } }
static void test_driver_eapol(struct test_driver_data *drv, struct sockaddr_un *from, socklen_t fromlen, u8 *data, size_t datalen) { struct test_client_socket *cli; if (datalen > 14) { /* Skip Ethernet header */ wpa_printf(MSG_DEBUG, "test_driver: dst=" MACSTR " src=" MACSTR " proto=%04x", MAC2STR(data), MAC2STR(data + ETH_ALEN), WPA_GET_BE16(data + 2 * ETH_ALEN)); data += 14; datalen -= 14; } cli = test_driver_get_cli(drv, from, fromlen); if (cli) { struct hostapd_data *hapd; hapd = test_driver_get_hapd(drv, cli->bss); if (hapd == NULL) return; ieee802_1x_receive(hapd, cli->addr, data, datalen); } else { wpa_printf(MSG_DEBUG, "test_socket: EAPOL from unknown " "client"); } }
static void rsn_preauth_receive(void *ctx, const u8 *src_addr, const u8 *buf, size_t len) { struct rsn_preauth_interface *piface = ctx; struct asd_data *wasd = piface->wasd; struct ieee802_1x_hdr *hdr; struct sta_info *sta; struct l2_ethhdr *ethhdr; asd_printf(ASD_DEFAULT,MSG_DEBUG, "RSN: receive pre-auth packet " "from interface '%s'", piface->ifname); if (len < sizeof(*ethhdr) + sizeof(*hdr)) { asd_printf(ASD_DEFAULT,MSG_DEBUG, "RSN: too short pre-auth packet " "(len=%lu)", (unsigned long) len); return; } ethhdr = (struct l2_ethhdr *) buf; hdr = (struct ieee802_1x_hdr *) (ethhdr + 1); if (os_memcmp(ethhdr->h_dest, wasd->own_addr, ETH_ALEN) != 0) { asd_printf(ASD_DEFAULT,MSG_DEBUG, "RSN: pre-auth for foreign address " MACSTR, MAC2STR(ethhdr->h_dest)); return; } sta = ap_get_sta(wasd, ethhdr->h_source); if (sta && (sta->flags & WLAN_STA_ASSOC)) { asd_printf(ASD_DEFAULT,MSG_DEBUG, "RSN: pre-auth for already association " "STA " MACSTR, MAC2STR(sta->addr)); return; } if (!sta && hdr->type == IEEE802_1X_TYPE_EAPOL_START) { sta = ap_sta_add(wasd, ethhdr->h_source ,0); if (sta == NULL) return; sta->flags = WLAN_STA_PREAUTH; ieee802_1x_new_station(wasd, sta); if (sta->eapol_sm == NULL) { //UpdateStaInfoToWSM(wasd, sta->addr, WID_DEL); if(ASD_WLAN[wasd->WlanID]!=NULL&&ASD_WLAN[wasd->WlanID]->balance_switch == 1&&ASD_WLAN[wasd->WlanID]->balance_method==1) ap_free_sta_without_wsm(wasd, sta,1); else ap_free_sta_without_wsm(wasd, sta,0); sta = NULL; } else { sta->eapol_sm->radius_identifier = -1; sta->eapol_sm->portValid = TRUE; sta->eapol_sm->flags |= EAPOL_SM_PREAUTH; } } if (sta == NULL) return; sta->preauth_iface = piface; ieee802_1x_receive(wasd, ethhdr->h_source, (u8 *) (ethhdr + 1), len - sizeof(*ethhdr)); }
static void rsn_preauth_receive(void *ctx, const u8 *src_addr, const u8 *buf, size_t len) { struct rsn_preauth_interface *piface = ctx; struct hostapd_data *hapd = piface->hapd; struct ieee802_1x_hdr *hdr; struct sta_info *sta; struct l2_ethhdr *ethhdr; HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL, "RSN: receive pre-auth packet " "from interface '%s'\n", piface->ifname); if (len < sizeof(*ethhdr) + sizeof(*hdr)) { HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL, "RSN: too short pre-auth " "packet (len=%lu)\n", (unsigned long) len); return; } ethhdr = (struct l2_ethhdr *) buf; hdr = (struct ieee802_1x_hdr *) (ethhdr + 1); if (memcmp(ethhdr->h_dest, hapd->own_addr, ETH_ALEN) != 0) { HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL, "RSN: pre-auth for " "foreign address " MACSTR "\n", MAC2STR(ethhdr->h_dest)); return; } sta = ap_get_sta(hapd, ethhdr->h_source); if (sta && (sta->flags & WLAN_STA_ASSOC)) { HOSTAPD_DEBUG(HOSTAPD_DEBUG_MINIMAL, "RSN: pre-auth for " "already association STA " MACSTR "\n", MAC2STR(sta->addr)); return; } if (!sta && hdr->type == IEEE802_1X_TYPE_EAPOL_START) { sta = ap_sta_add(hapd, ethhdr->h_source); if (sta == NULL) return; sta->flags = WLAN_STA_PREAUTH; ieee802_1x_new_station(hapd, sta); if (sta->eapol_sm == NULL) { ap_free_sta(hapd, sta); sta = NULL; } else { sta->eapol_sm->radius_identifier = -1; sta->eapol_sm->portValid = TRUE; sta->eapol_sm->flags |= EAPOL_SM_PREAUTH; } } if (sta == NULL) return; sta->preauth_iface = piface; ieee802_1x_receive(hapd, ethhdr->h_source, (u8 *) (ethhdr + 1), len - sizeof(*ethhdr)); }
static void hostapd_event_eapol_rx(struct apd_iface *iface, const u8 *src, const u8 *data, size_t data_len) { if(iface->apConf.macAuth){ // MAC 认证: 不需要处理,MAC认证的触发由触发条件进行触发 }else{ ieee802_1x_receive(iface, src, data, data_len); } }
static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src, const u8 *data, size_t data_len) { struct hostapd_iface *iface = hapd->iface; size_t j; for (j = 0; j < iface->num_bss; j++) { if (ap_get_sta(iface->bss[j], src)) { hapd = iface->bss[j]; break; } } ieee802_1x_receive(hapd, src, data, data_len); }
static void handle_read(void *ctx, unsigned char *src_addr, unsigned char *buf, size_t len) { struct bsd_driver_data *drv = ctx; hostapd *hapd = drv->hapd; struct sta_info *sta; sta = ap_get_sta(hapd, src_addr); if (!sta || !(sta->flags & WLAN_STA_ASSOC)) { printf("Data frame from not associated STA %s\n", ether_sprintf(src_addr)); /* XXX cannot happen */ return; } ieee802_1x_receive(hapd, src_addr, buf, len); }
static void rtl871x_handle_read(void *ctx, const u8 *src_addr, const u8 *buf, size_t len) { struct rtl871x_driver_data *drv = ctx; struct hostapd_data *hapd = drv->hapd; struct sta_info *sta; sta = ap_get_sta(hapd, src_addr); if (!sta || !(sta->flags & WLAN_STA_ASSOC)) { printf("Data frame from not associated STA %s\n", ether_sprintf(src_addr)); /* XXX cannot happen */ return; } ieee802_1x_receive(hapd, src_addr, buf + sizeof(struct l2_ethhdr), len - sizeof(struct l2_ethhdr)); }
static void hostapd_event_eapol_rx(struct hostapd_data *hapd, const u8 *src, const u8 *data, size_t data_len) { struct hostapd_iface *iface = hapd->iface; struct sta_info *sta; size_t j; for (j = 0; j < iface->num_bss; j++) { sta = ap_get_sta(iface->bss[j], src); if (sta && sta->flags & WLAN_STA_ASSOC) { hapd = iface->bss[j]; break; } } ieee802_1x_receive(hapd, src, data, data_len); }
void wpa_supplicant_ap_rx_eapol(struct wpa_supplicant *wpa_s, const u8 *src_addr, const u8 *buf, size_t len) { ieee802_1x_receive(wpa_s->ap_iface->bss[0], src_addr, buf, len); }
static void Handle_read(int sock, void *eloop_ctx, void *sock_ctx) { rtapd *rtapd = eloop_ctx; int len; unsigned char buf[3000]; u8 *sa, *da, *pos, *pos_vlan, apidx=0, isVlanTag=0; u16 ethertype,i; priv_rec *rec; size_t left; u8 RalinkIe[9] = {221, 7, 0x00, 0x0c, 0x43, 0x00, 0x00, 0x00, 0x00}; len = recv(sock, buf, sizeof(buf), 0); if (len < 0) { perror("recv"); Handle_term(15,eloop_ctx,sock_ctx); return; } rec = (priv_rec*)buf; left = len -sizeof(*rec)+1; if (left <= 0) { DBGPRINT(RT_DEBUG_ERROR," too short recv\n"); return; } sa = rec->saddr; da = rec->daddr; ethertype = rec->ethtype[0] << 8; ethertype |= rec->ethtype[1]; #ifdef ETH_P_VLAN if(ethertype == ETH_P_VLAN) { pos_vlan = rec->xframe; if(left >= 4) { ethertype = *(pos_vlan+2) << 8; ethertype |= *(pos_vlan+3); } if((ethertype == ETH_P_PRE_AUTH) || (ethertype == ETH_P_PAE)) { isVlanTag = 1; DBGPRINT(RT_DEBUG_TRACE,"Recv vlan tag for 802.1x. (%02x %02x)\n", *(pos_vlan), *(pos_vlan+1)); } } #endif if ((ethertype == ETH_P_PRE_AUTH) || (ethertype == ETH_P_PAE)) { // search this packet is coming from which interface for (i = 0; i < rtapd->conf->SsidNum; i++) { if (memcmp(da, rtapd->own_addr[i], 6) == 0) { apidx = i; break; } } if(i >= rtapd->conf->SsidNum) { DBGPRINT(RT_DEBUG_WARN, "Receive unexpected DA (%02x:%02x:%02x:%02x:%02x:%02x)\n", MAC2STR(da)); return; } if (ethertype == ETH_P_PRE_AUTH) { DBGPRINT(RT_DEBUG_TRACE, "Receive WPA2 pre-auth packet for %s%d\n", rtapd->prefix_wlan_name, apidx); } else { DBGPRINT(RT_DEBUG_TRACE, "Receive EAP packet for %s%d\n", rtapd->prefix_wlan_name, apidx); } } else { DBGPRINT(RT_DEBUG_ERROR, "Receive unexpected ethertype 0x%04X!!!\n", ethertype); return; } pos = rec->xframe; //strip 4 bytes for valn tag if(isVlanTag) { pos += 4; left -= 4; } /* Check if this is a internal command or not */ if (left == sizeof(RalinkIe) && RTMPCompareMemory(pos, RalinkIe, 5) == 0) { u8 icmd = *(pos + 5); switch(icmd) { case DOT1X_DISCONNECT_ENTRY: { struct sta_info *s; s = rtapd->sta_hash[STA_HASH(sa)]; while (s != NULL && memcmp(s->addr, sa, 6) != 0) s = s->hnext; DBGPRINT(RT_DEBUG_TRACE, "Receive discard-notification form wireless driver.\n"); if (s) { DBGPRINT(RT_DEBUG_TRACE,"This station(%02x:%02x:%02x:%02x:%02x:%02x) is removed.\n", MAC2STR(sa)); Ap_free_sta(rtapd, s); } else { DBGPRINT(RT_DEBUG_INFO, "This station(%02x:%02x:%02x:%02x:%02x:%02x) doesn't exist.\n", MAC2STR(sa)); } } break; case DOT1X_RELOAD_CONFIG: Handle_reload_config(rtapd); break; default: DBGPRINT(RT_DEBUG_ERROR, "Unknown internal command(%d)!!!\n", icmd); break; } } else { /* Process the general EAP packet */ ieee802_1x_receive(rtapd, sa, &apidx, pos, left, ethertype, sock); } }
static void Handle_read(int sock, void *eloop_ctx, void *sock_ctx) { rtapd *rtapd = eloop_ctx; int len; unsigned char buf[3000]; u8 *sa, *da, *pos, *pos_vlan, apidx=0, isVlanTag=0; u16 ethertype,i; priv_rec *rec; size_t left; len = recv(sock, buf, sizeof(buf), 0); if (len < 0) { perror("recv"); Handle_term(15,eloop_ctx,sock_ctx); return; } rec = (priv_rec*)buf; left = len -sizeof(*rec)+1; if (left <= 0) { DBGPRINT(RT_DEBUG_ERROR," too short recv\n"); return; } sa = rec->saddr; da = rec->daddr; ethertype = rec->ethtype[0] << 8; ethertype |= rec->ethtype[1]; #ifdef ETH_P_VLAN if(ethertype == ETH_P_VLAN) { pos_vlan = rec->xframe; if(left >= 4) { ethertype = *(pos_vlan+2) << 8; ethertype |= *(pos_vlan+3); } if((ethertype == ETH_P_PRE_AUTH) || (ethertype == ETH_P_PAE)) { isVlanTag = 1; DBGPRINT(RT_DEBUG_TRACE,"Recv vlan tag for 802.1x. (%02x %02x)\n", *(pos_vlan), *(pos_vlan+1)); } } #endif if ((ethertype == ETH_P_PRE_AUTH) || (ethertype == ETH_P_PAE)) { // search this packet is coming from which interface for (i = 0; i < rtapd->conf->SsidNum; i++) { if (memcmp(da, rtapd->own_addr[i], 6) == 0) { apidx = i; break; } } if(i >= rtapd->conf->SsidNum) { DBGPRINT(RT_DEBUG_WARN, "Receive unexpected DA (%02x:%02x:%02x:%02x:%02x:%02x)\n", MAC2STR(da)); return; } if (ethertype == ETH_P_PRE_AUTH) { DBGPRINT(RT_DEBUG_TRACE, "Receive WPA2 pre-auth packet for %s%d\n", rtapd->prefix_wlan_name, apidx); } else { DBGPRINT(RT_DEBUG_TRACE, "Receive EAP packet for %s%d\n", rtapd->prefix_wlan_name, apidx); } } else { DBGPRINT(RT_DEBUG_ERROR, "Receive unexpected ethertype 0x%04X!!!\n", ethertype); return; } pos = rec->xframe; //strip 4 bytes for valn tag if(isVlanTag) { pos += 4; left -= 4; } ieee802_1x_receive(rtapd, sa, &apidx, pos, left, ethertype, sock); }
static void handle_data(struct hostapd_data *hapd, u8 *buf, size_t len, u16 stype) { struct ieee80211_hdr *hdr; u16 fc, ethertype; u8 *pos, *sa; size_t left; struct sta_info *sta; if (len < sizeof(struct ieee80211_hdr)) return; hdr = (struct ieee80211_hdr *) buf; fc = le_to_host16(hdr->frame_control); if ((fc & (WLAN_FC_FROMDS | WLAN_FC_TODS)) != WLAN_FC_TODS) { printf("Not ToDS data frame (fc=0x%04x)\n", fc); return; } sa = hdr->addr2; sta = ap_get_sta(hapd, sa); if (!sta || !(sta->flags & WLAN_STA_ASSOC)) { printf("Data frame from not associated STA " MACSTR "\n", MAC2STR(sa)); if (sta && (sta->flags & WLAN_STA_AUTH)) hostapd_sta_disassoc( hapd, sa, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA); else hostapd_sta_deauth( hapd, sa, WLAN_REASON_CLASS3_FRAME_FROM_NONASSOC_STA); return; } pos = (u8 *) (hdr + 1); left = len - sizeof(*hdr); if (left < sizeof(rfc1042_header)) { printf("Too short data frame\n"); return; } if (memcmp(pos, rfc1042_header, sizeof(rfc1042_header)) != 0) { printf("Data frame with no RFC1042 header\n"); return; } pos += sizeof(rfc1042_header); left -= sizeof(rfc1042_header); if (left < 2) { printf("No ethertype in data frame\n"); return; } ethertype = WPA_GET_BE16(pos); pos += 2; left -= 2; switch (ethertype) { case ETH_P_PAE: ieee802_1x_receive(hapd, sa, pos, left); break; default: printf("Unknown ethertype 0x%04x in data frame\n", ethertype); break; } }
void rsn_preauth_receive_thinap(void *ctx, const u8 *src_addr,const u8 *des_addr, const u8 *buf, size_t len) { struct asd_data *now_wasd = ctx; struct ieee802_1x_hdr *hdr; struct sta_info *sta; struct asd_data * wasd; struct PreAuth_BSSINFO *bss; struct wasd_interfaces *interfaces = (struct wasd_interfaces*) circle.user_data; unsigned int RadioID; unsigned char BSS_L_ID; bss = PreAuth_wlan_get_bss(ASD_WLAN[now_wasd->WlanID],des_addr); if(bss == NULL){ asd_printf(ASD_DEFAULT,MSG_DEBUG,"something wrong in finding bss: "MACSTR, MAC2STR(des_addr)); return; } asd_printf(ASD_DEFAULT,MSG_DEBUG,"we got bss index:%d",bss->BSSIndex); RadioID = bss->BSSIndex/L_BSS_NUM; BSS_L_ID = bss->BSSIndex%L_BSS_NUM; if((interfaces->iface[RadioID]!=NULL)&&(interfaces->iface[RadioID]->bss[BSS_L_ID]!=NULL)) wasd = interfaces->iface[RadioID]->bss[BSS_L_ID]; else return; if (len < sizeof(*hdr)) { asd_printf(ASD_DEFAULT,MSG_DEBUG, "RSN: too short pre-auth packet " "(len=%lu)", (unsigned long) len); asd_printf(ASD_DEFAULT,MSG_DEBUG,"rsn_preauth_receive_thinap RSN: too short pre-auth packet " "(len=%lu)", (unsigned long) len); return; } hdr = (struct ieee802_1x_hdr *) (buf); if (os_memcmp(des_addr, wasd->own_addr, ETH_ALEN) != 0) { asd_printf(ASD_DEFAULT,MSG_DEBUG, "RSN: pre-auth for foreign address " MACSTR, MAC2STR(des_addr)); asd_printf(ASD_DEFAULT,MSG_DEBUG,"rsn_preauth_receive_thinap RSN: pre-auth for foreign address " MACSTR, MAC2STR(des_addr)); return; } sta = ap_get_sta(wasd, src_addr); if (sta && (sta->flags & WLAN_STA_ASSOC)) { asd_printf(ASD_DEFAULT,MSG_DEBUG, "RSN: pre-auth for already association " "STA " MACSTR, MAC2STR(sta->addr)); asd_printf(ASD_DEFAULT,MSG_DEBUG,"rsn_preauth_receive_thinap RSN: pre-auth for already association " "STA " MACSTR, MAC2STR(sta->addr)); return; } if (!sta && hdr->type == IEEE802_1X_TYPE_EAPOL_START) { asd_printf(ASD_DEFAULT,MSG_DEBUG,"IEEE802_1X_TYPE_EAPOL_START\n"); sta = ap_sta_add(wasd, src_addr,0); if (sta == NULL) return; sta->flags = WLAN_STA_PREAUTH; ieee802_1x_new_station(wasd, sta); if (sta->eapol_sm == NULL) { ap_free_sta(wasd, sta,0); sta = NULL; } else { sta->eapol_sm->radius_identifier = -1; sta->eapol_sm->portValid = TRUE; sta->eapol_sm->flags |= EAPOL_SM_PREAUTH; } } if (sta == NULL) return; memcpy(sta->PreAuth_BSSID,now_wasd->own_addr,6); sta->PreAuth_BSSIndex = now_wasd->BSSIndex; asd_printf(ASD_DEFAULT,MSG_DEBUG,"ieee802_1x_receive \n"); ieee802_1x_receive(wasd, src_addr, (u8 *) (buf), len); }
static void Handle_read(int sock, void *eloop_ctx, void *sock_ctx) { //rtapd *rtapd = (rtapd*) eloop_ctx; rtapd *rtapd = eloop_ctx; int len; unsigned char buf[3000]; u8 *sa, *pos, apidx=0; u16 ethertype,i; priv_rec *rec; size_t left; len = recv(sock, buf, sizeof(buf), 0); if (len < 0) { perror("recv"); Handle_term(15,eloop_ctx,sock_ctx); return; } rec = (priv_rec*)buf; left = len -sizeof(*rec)+1; if (left <= 0) { DBGPRINT(RT_DEBUG_ERROR," too short recv\n"); return; } sa = rec->saddr; ethertype = rec->ethtype[0] << 8; ethertype |= rec->ethtype[1]; if(ethertype != ETH_P_PAE) { return; } // search this packet is coming from which interface for (i = 0; i < rtapd->conf->SsidNum; i++) { if(sock == rtapd->sock[i]) { apidx = i; break; } } if(apidx >= rtapd->conf->SsidNum) { DBGPRINT(RT_DEBUG_ERROR,"sock not found!!!\n"); return; } pos = rec->xframe; if (len < 52 ) { DBGPRINT(RT_DEBUG_INFO,"Handle_read :: handle_short_frame: (len=%d, left=%d \n", len,left); for(i = 0; i < left; i++) DBGPRINT(RT_DEBUG_INFO," %x", *(pos+i)); DBGPRINT(RT_DEBUG_INFO,"\n"); } ieee802_1x_receive(rtapd, sa, &apidx, pos, left); }