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_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 = (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); }