Files
kunlun/plc/halmac/inc/mac_crc.h
2024-09-28 14:24:04 +08:00

188 lines
6.4 KiB
C
Executable File

/****************************************************************************
Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED.
This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT
be copied by any method or incorporated into another program without
the express written consent of Aerospace C.Power. This Information or any portion
thereof remains the property of Aerospace C.Power. The Information contained herein
is believed to be accurate and Aerospace C.Power assumes no responsibility or
liability for its use in any way and conveys no license or title under
any patent or copyright and makes no representation or warranty that this
Information is free from patent or copyright infringement.
****************************************************************************/
#ifndef _MAC_CRC_H_
#define _MAC_CRC_H_
#include "iot_crc.h"
#include "rx_pb_reorder.h"
#include "iot_errno.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MAC_CRC_DEBUG_LEVEL
#define MAC_CRC_DEBUG_LEVEL 0
#endif
#define CRC_INIT_VECT_DEFAULT 0xFFFFFFFF
#define CRC24_INIT_VECT_SG 0
#define CRC24_INIT_VECT_SPG 0
#define CRC24_INIT_VECT_GP 0x00FFFFFF
#define CRC32_INIT_VECT_I1901 0
/* CRC check */
#define PAYLOAD_CRC_ERR_MASK (1 << 0) /* crc32 */
#define PB_CRC_ERR_MASK (1 << 1) /* crc24 */
#define FC_CRC_ERR_MASK (1 << 2) /* crc24 */
/*
* mac_crc_get_fc_swcrc() - get fc software crc
* @proto: mpdu data protocol, for example
* PLC_PROTO_TYPE_SG 0
* PLC_PROTO_TYPE_GP 1
* PLC_PROTO_TYPE_AV 2
* PLC_PROTO_TYPE_SPG 3
* @fc mpdu fc feild point
*
* return: crc calculate value
*/
uint32_t mac_crc_get_fc_swcrc(uint32_t proto, void *fc);
/*
* mac_crc_get_pb_swcrc() - get pb software crc
* @proto: mpdu data protocol, for example
* PLC_PROTO_TYPE_SG 0
* PLC_PROTO_TYPE_GP 1
* PLC_PROTO_TYPE_AV 2
* PLC_PROTO_TYPE_SPG 3
* @pb_head if fw set pb_header fill in payload, pb_head = NULL,
* otherwise pb_head = actual pb header buffer point
* @payload pb payload point
* @pb_sz pb size
* @delimiter delimite type
*
* return: crc calculate value,
* if para dont match, return CRC_INIT_VECT_DEFAULT
*/
uint32_t mac_crc_get_pb_swcrc(uint32_t proto, void *pb_head, uint8_t *payload, \
uint32_t pb_sz, uint8_t delimiter);
/*
* mac_crc_get_bcn_swcrc() - get beacon software crc
* @proto: mpdu data protocol, for example
* PLC_PROTO_TYPE_SG 0
* PLC_PROTO_TYPE_GP 1
* PLC_PROTO_TYPE_AV 2
* PLC_PROTO_TYPE_SPG 3
* @payload pb payload point
* @pb_sz pb size
* @delimiter delimite type
*
* return: crc calculate value
*/
uint32_t mac_crc_get_bcn_swcrc(uint32_t proto, void *payload, uint32_t pb_sz,
uint32_t *crc_value);
/*
* mac_crc_set_fc_swcrc() - calculate beacon payload crc and filling
* @proto: mpdu data protocol, eg.
* PLC_PROTO_TYPE_SG 0
* PLC_PROTO_TYPE_GP 1
* PLC_PROTO_TYPE_AV 2
* PLC_PROTO_TYPE_SPG 3
* @payload: beacon payload buffer point
* @pb_sz: pb size(eg. 72/136/264/520...)
*
* return: error num, reference iot_errno.h
*/
uint8_t mac_crc_set_bcn_swcrc(uint32_t proto, void *payload, uint32_t pb_sz);
/*
* mac_crc_get_msdu_swcrc() - get msdu software crc
* @proto: mpdu data protocol, for example
* PLC_PROTO_TYPE_SG 0
* PLC_PROTO_TYPE_GP 1
* PLC_PROTO_TYPE_AV 2
* PLC_PROTO_TYPE_SPG 3
* @msdu mac msdu frame pkt point.
* contains mac_header, msdu_payload, msdu_crc
*
* return: crc calculate value,
* if para dont match, return CRC_INIT_VECT_DEFAULT
*/
uint32_t mac_crc_get_msdu_swcrc(uint32_t proto, iot_pkt_t *msdu);
/*
* mac_crc_get_msdu_srccrc() - get msdu source crc from msdu crc block
* @proto: mpdu data protocol, for example
* PLC_PROTO_TYPE_SG 0
* PLC_PROTO_TYPE_GP 1
* PLC_PROTO_TYPE_AV 2
* PLC_PROTO_TYPE_SPG 3
* @msdu mac msdu frame pkt point.
* contains mac_header, msdu_payload, msdu_crc
*
* return: crc calculate value,
* if para dont match, return CRC_INIT_VECT_DEFAULT
*/
uint32_t mac_crc_get_msdu_srccrc(uint32_t proto, iot_pkt_t *msdu);
/*
* mac_crc_set_fc_swcrc() - calculate beacon payload crc and filling
* @proto: mpdu data protocol, eg.
* PLC_PROTO_TYPE_SG 0
* PLC_PROTO_TYPE_GP 1
* PLC_PROTO_TYPE_AV 2
* PLC_PROTO_TYPE_SPG 3
* @msdu: mac msdu frame pkt point.
* contains mac_header, msdu_payload, msdu_crc
*
* return: error num, reference iot_errno.h
*/
uint8_t mac_crc_set_msdu_swcrc(uint32_t proto, iot_pkt_t *msdu);
/*
* mac_crc_mpdu_swcrc_verify() - verify mpdu(fc/pb_crc/beacon_payload_crc)
* @proto: mpdu data protocol, eg.
* PLC_PROTO_TYPE_SG 0
* PLC_PROTO_TYPE_GP 1
* PLC_PROTO_TYPE_AV 2
* PLC_PROTO_TYPE_SPG 3
* @rx_hdr: rx mpdu description point
* @bit_mask verify bit mask,if this bit = 1,verify corresponding field crc,
* PAYLOAD_CRC_ERR_MASK 1: verify beacon payload crc
* PB_CRC_ERR_MASK 2: verify pb payload crc
* FC_CRC_ERR_MASK 3: verify fc crc
*
* return: verify error bit mask, same as para bit_mask,
* if bit = 1,means corresponding field verify error
*/
uint8_t mac_crc_mpdu_swcrc_verify(uint32_t proto, \
rx_buf_hdr_t *rx_hdr, uint8_t bit_mask);
/*
* mac_crc_msdu_swcrc_verify() - calculate msdu payload crc
* @proto: mpdu data protocol, eg.
* PLC_PROTO_TYPE_SG 0
* PLC_PROTO_TYPE_GP 1
* PLC_PROTO_TYPE_AV 2
* PLC_PROTO_TYPE_SPG 3
* @msdu: mac msdu frame pkt point.
* contains mac_header, msdu_payload, msdu_crc
*
* return: verify result. 0:verify success
*/
uint8_t mac_crc_msdu_swcrc_verify(uint32_t proto, iot_pkt_t *msdu);
#ifdef __cplusplus
}
#endif
#endif