int aniEapolParse(tAniPacket *packet, v_U8_t **dstMac, v_U8_t **srcMac, v_U8_t **type) { v_U16_t frameType; v_U8_t *ptr; int retVal; int tmp; if (aniAsfPacketGetLen(packet) < EAPOL_BODY_POS) return ANI_E_ILLEGAL_ARG; retVal = aniAsfPacketGetBytes(packet, &ptr); if( !ANI_IS_STATUS_SUCCESS( retVal ) ) { return retVal; } VOS_TRACE( VOS_MODULE_ID_BAP, VOS_TRACE_LEVEL_INFO, "Supp parsing EAPOL packet of len %d: \n", retVal); frameType = (ptr[ETHER_PROTO_POS] << 8) + ptr[ETHER_PROTO_POS+1]; if (frameType != ANI_ETH_P_EAPOL) return ANI_E_ILLEGAL_ARG; *dstMac = ptr + DST_MAC_POS; *srcMac = ptr + SRC_MAC_POS; *type = ptr + ANI_EAPOL_TYPE_POS; retVal = (ptr[EAPOL_BODY_LEN_POS] << 8) + ptr[EAPOL_BODY_LEN_POS + 1]; tmp = aniAsfPacketGetLen(packet) - EAPOL_RX_HEADER_SIZE; if (retVal > tmp) { retVal = ANI_E_ILLEGAL_ARG; } else { if (retVal < tmp) { retVal = aniAsfPacketTruncateFromRear(packet, tmp - retVal); } } return retVal; }
/** * aniEapolParse * * FUNCTION: * Parses an EAPoL frame to the first level of headers (no EAP * headers are parsed). * * NOTE: This is a non-destructive read, that is the * headers are not stripped off the packet. However, any additional * data at the end of the packet, beyond what the EAPoL headers encode * will be stripped off. * * @param packet the packet containing the EAPoL frame to parse * @param dstMac a pointer to set to the location of the destination * MAC address * @param srcMac a pointer to set to the location of the source * MAC address * @param type a pointer to set to the location of the EAPOL type * field. * * @return the non-negative length of the EAPOL payload if the operation * succeeds */ int aniEapolParse(tAniPacket *packet, v_U8_t **dstMac, v_U8_t **srcMac, v_U8_t **type) { v_U16_t frameType; v_U8_t *ptr; int retVal; int tmp; if (aniAsfPacketGetLen(packet) < EAPOL_BODY_POS) return ANI_E_ILLEGAL_ARG; retVal = aniAsfPacketGetBytes(packet, &ptr); if( !ANI_IS_STATUS_SUCCESS( retVal ) ) { return retVal; } VOS_TRACE( VOS_MODULE_ID_BAP, VOS_TRACE_LEVEL_INFO, "Supp parsing EAPOL packet of len %d: \n", retVal); frameType = (ptr[ETHER_PROTO_POS] << 8) + ptr[ETHER_PROTO_POS+1]; /* * Validate the EAPOL-FRAME */ if (frameType != ANI_ETH_P_EAPOL) return ANI_E_ILLEGAL_ARG; *dstMac = ptr + DST_MAC_POS; *srcMac = ptr + SRC_MAC_POS; // if (ptr[EAPOL_VERSION_POS] != EAPOL_VERSION_1) // return ANI_E_ILLEGAL_ARG; *type = ptr + ANI_EAPOL_TYPE_POS; retVal = (ptr[EAPOL_BODY_LEN_POS] << 8) + ptr[EAPOL_BODY_LEN_POS + 1]; /* * Validate the length of the body. Allow for longer * packets than encoded, but encoding should not be larger than * packet. * Note: EAPOL body len does not include headers */ tmp = aniAsfPacketGetLen(packet) - EAPOL_RX_HEADER_SIZE; if (retVal > tmp) { retVal = ANI_E_ILLEGAL_ARG; } else { if (retVal < tmp) { retVal = aniAsfPacketTruncateFromRear(packet, tmp - retVal); } } return retVal; }