/** * aniEapolParseKey * * Parses and verifies a complete EAPOL-Key frame. The key descriptor * type is returned and so is a newly allocated key descriptor structure * that is appropriate for the type. * * NOTE: This is a non-destructive read. That is, the packet headers * will be unchanged at the end of this read operation. This is so * that a followup MIC check may be done on the complete packet. If * the packet parsing fails, the packet headers are not guaranteed to * be unchanged. * * @param packet the packet to read from. Note that the frame is not * expected to contain any additional padding at the end other than * the exact number of key bytes. (The aniEapolParse function will * ensure this.) * @param descType is set to the key descriptor type * (ANI_EAPOL_KEY_DESC_TYPE_LEGACY_RC4 or * ANI_EAPOL_KEY_DESC_TYPE_RSN). * @param keyDescData is set to a newly allocated key descriptor * corresponding to the above descType. The signature field is * verified. The key bytes will be returned encrypted. It is the * responsibility of the caller to free this structure and the data * contained therein. * * @return ANI_OK if the operation succeeds */ int aniEapolParseKey(tAniPacket *packet, int *descType, void **keyDescData) { int retVal; v_U8_t *bytes; v_U32_t eapolFrameLen; if (packet == NULL) return ANI_E_NULL_VALUE; do { eapolFrameLen = aniAsfPacketGetLen(packet); VOS_TRACE( VOS_MODULE_ID_BAP, VOS_TRACE_LEVEL_INFO, "Supp parsing EAPOL-Key frame of len %d\n", eapolFrameLen); retVal = aniAsfPacketTruncateFromFront(packet, EAPOL_RX_HEADER_SIZE); if( !ANI_IS_STATUS_SUCCESS(retVal) ) break; retVal = aniAsfPacketGetBytes(packet, &bytes); if( !ANI_IS_STATUS_SUCCESS(retVal) ) break; if (*bytes == ANI_EAPOL_KEY_DESC_TYPE_RSN || *bytes == ANI_EAPOL_KEY_DESC_TYPE_RSN_NEW) { tAniEapolRsnKeyDesc *rsnDesc = NULL; //*descType = ANI_EAPOL_KEY_DESC_TYPE_RSN; *descType = (*bytes == ANI_EAPOL_KEY_DESC_TYPE_RSN_NEW ? ANI_EAPOL_KEY_DESC_TYPE_RSN_NEW : ANI_EAPOL_KEY_DESC_TYPE_RSN) ; retVal = parseRsnKeyDesc(packet, &rsnDesc); if( !ANI_IS_STATUS_SUCCESS(retVal) ) break; *keyDescData = rsnDesc; } else { VOS_TRACE( VOS_MODULE_ID_BAP, VOS_TRACE_LEVEL_ERROR, "Supp received unknown EAPOL-Key descriptor: %d\n", *bytes); retVal = ANI_E_ILLEGAL_ARG; break; } aniAsfPacketMoveLeft(packet, eapolFrameLen); }while( 0 ); return retVal; }
/** * aniAsfPacketPrepend8 * * FUNCTION: * Prepends a ANI_U8 to the start of the packet. * All host to network byte order translation is also taken care of. * * @param packet the packet to read from * @param val the value to prepend * * @return ANI_OK if the operation succeeds */ int aniAsfPacketPrepend8(tAniPacket *packet, v_U8_t val) { if (packet == NULL) return ANI_E_NULL_VALUE; VOS_ASSERT(HEAD_SPACE(packet) >= 1); if (HEAD_SPACE(packet) < 1) return ANI_E_FAILED; aniAsfPacketMoveLeft(packet, 1); *(packet->head) = val; return ANI_OK; }
/** * aniAsfPacketPrepend16 * * FUNCTION: * Prepends a ANI_U16 to the start of the packet. * All host to network byte order translation is also taken care of. * * @param packet the packet to write to * @param val the value to prepend * * @return ANI_OK if the operation succeeds */ int aniAsfPacketPrepend16(tAniPacket *packet, v_U16_t val) { v_U8_t *p8; if (packet == NULL) return ANI_E_NULL_VALUE; if (HEAD_SPACE(packet) < 2) return ANI_E_FAILED; aniAsfPacketMoveLeft(packet, 2); val = vos_cpu_to_be16( val ); p8 = (v_U8_t *)&val; packet->head[0] = p8[0]; packet->head[1] = p8[1]; return ANI_OK; }