308 lines
		
	
	
		
			9.3 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			308 lines
		
	
	
		
			9.3 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 MPDU_HEADER_H
 | 
						|
#define MPDU_HEADER_H
 | 
						|
 | 
						|
/* os shim includes */
 | 
						|
#include "os_types_api.h"
 | 
						|
 | 
						|
#include "mac_data_api.h"
 | 
						|
#include "iot_pkt_api.h"
 | 
						|
#include "hw_war.h"
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
extern "C" {
 | 
						|
#endif
 | 
						|
 | 
						|
/*
 | 
						|
 structure for
 | 
						|
 aquiring different part of FC according to delimiter and proto
 | 
						|
*/
 | 
						|
typedef struct _rx_fc_msg {
 | 
						|
    /* plc & rf use */
 | 
						|
    uint32_t bcast          : 1,
 | 
						|
    /* plc & rf use */
 | 
						|
        retry               : 1,
 | 
						|
    /* plc only */
 | 
						|
        tmi                 : 4,
 | 
						|
    /* plc only */
 | 
						|
        tmi_ext             : 4,
 | 
						|
    /* plc only */
 | 
						|
        numsym              : 9,
 | 
						|
    /* plc only. gp protocol */
 | 
						|
        rtsf                : 1,
 | 
						|
    /* plc only. gp protocol */
 | 
						|
        saf                 : 1,
 | 
						|
    /* plc only */
 | 
						|
        phase               : 2,
 | 
						|
    /* plc & rf use */
 | 
						|
        lid                 : 8,
 | 
						|
    /* reserved */
 | 
						|
        resv0               : 1;
 | 
						|
    /* plc & rf use */
 | 
						|
    uint32_t dst_tei        : 12,
 | 
						|
    /* plc & rf use */
 | 
						|
        src_tei             : 12,
 | 
						|
    /* plc & rf use */
 | 
						|
        sack_ext_deli       : 8;
 | 
						|
    /* plc & rf use. fc crc */
 | 
						|
    uint32_t fccs           : 24,
 | 
						|
    /* plc & rf use */
 | 
						|
        load_in_sack        : 8;
 | 
						|
    /* plc & rf use */
 | 
						|
    uint32_t time_stamp;
 | 
						|
    /* plc & rf use */
 | 
						|
    uint32_t nid            : 24,
 | 
						|
    /* plc only */
 | 
						|
        bitmap_in_sack      : 4,
 | 
						|
    /* plc & rf use */
 | 
						|
        result_in_sack      : 4;
 | 
						|
    /* plc & rf use */
 | 
						|
    int8_t snr_in_sack;
 | 
						|
    /* plc only */
 | 
						|
    uint8_t pb_num          : 4,
 | 
						|
    /* plc & rf use */
 | 
						|
            delimiter       : 4;
 | 
						|
    /* rf only. rf phr pb size index */
 | 
						|
    uint8_t rf_pb_sz_idx    : 4,
 | 
						|
    /* rf only. rf phr mcs index */
 | 
						|
        rf_mcs              : 4;
 | 
						|
    /* reserved */
 | 
						|
    uint8_t resv1;
 | 
						|
} rx_fc_msg_t;
 | 
						|
 | 
						|
typedef struct _nncco_fc_info {
 | 
						|
    uint32_t nid;
 | 
						|
    uint32_t delimiter;
 | 
						|
    uint32_t network_type;
 | 
						|
    union{
 | 
						|
        /* nncco */
 | 
						|
        struct{
 | 
						|
            /* sg: duration
 | 
						|
            * nw: continue time
 | 
						|
            */
 | 
						|
            uint32_t duration : 16,
 | 
						|
            /* sg: next start offset
 | 
						|
            * nw: next start offset
 | 
						|
            */
 | 
						|
                     sbandoffset : 16;
 | 
						|
            uint32_t receive_nid;
 | 
						|
            /* sg: none
 | 
						|
            * nw: last end flag
 | 
						|
            */
 | 
						|
            uint8_t bwth_end_flag : 1,
 | 
						|
                     resv0 : 7;
 | 
						|
            /* sg: none
 | 
						|
            * nw: last end offset
 | 
						|
            */
 | 
						|
            uint16_t bwth_end_shift;
 | 
						|
            /* sg self rf channel */
 | 
						|
            uint32_t self_rf_channel : 8,
 | 
						|
            /* sg self rf option */
 | 
						|
                     self_rf_option  : 2,
 | 
						|
                     resv1 : 22;
 | 
						|
        };
 | 
						|
        /* sw nncco */
 | 
						|
        struct{
 | 
						|
            uint32_t start_ntb_l32;
 | 
						|
            /* sg: receive nid.
 | 
						|
             * nw: receive bitmap.
 | 
						|
             */
 | 
						|
            uint64_t sw_receive_nid : 24,
 | 
						|
                     sw_duration : 16,
 | 
						|
                     start_ntb_h24 : 24;
 | 
						|
            uint32_t last_offset;
 | 
						|
        };
 | 
						|
    };
 | 
						|
}nncco_fc_info_t;
 | 
						|
 | 
						|
/*
 | 
						|
 structure for
 | 
						|
 aquiring different part of FC according to delimiter and proto
 | 
						|
*/
 | 
						|
typedef struct _tx_fc_msg {
 | 
						|
    nid_t nid;
 | 
						|
    uint32_t fccs;
 | 
						|
    tei_t src_tei;
 | 
						|
    uint8_t tmi;
 | 
						|
    uint8_t ext_tmi;
 | 
						|
    uint8_t network_type;
 | 
						|
    uint8_t rf_mcs;
 | 
						|
    uint8_t rf_pb_sz_idx;
 | 
						|
    uint32_t bcn_period_cnt;
 | 
						|
} tx_fc_msg_t;
 | 
						|
 | 
						|
uint32_t mac_get_rx_delimiter_from_fc(uint32_t proto, void *fc);
 | 
						|
 | 
						|
uint32_t mac_get_nid_from_fc(uint32_t proto, void *fc);
 | 
						|
 | 
						|
void mac_get_rx_frm_msg_from_fc(uint32_t proto,
 | 
						|
    void *fc, rx_fc_msg_t *msg);
 | 
						|
 | 
						|
void mac_rf_get_rx_frm_msg_from_fc(uint32_t proto,
 | 
						|
    void *fc, rx_fc_msg_t *msg);
 | 
						|
 | 
						|
void mac_get_nncco_info_from_fc(void *fc, nncco_fc_info_t *nn_fc_info);
 | 
						|
 | 
						|
uint32_t mac_nncco_nid_compare(uint32_t nid_in_nncco, uint32_t nid_to_check);
 | 
						|
 | 
						|
uint32_t mac_debug_nncco_info(void *fc, uint32_t ntb);
 | 
						|
 | 
						|
void mac_set_bcn_st(void *fc, uint32_t ntb);
 | 
						|
 | 
						|
void mac_set_sync_st(void *fc, uint32_t ntb);
 | 
						|
 | 
						|
void mac_get_tx_msg_from_fc(uint32_t proto, uint32_t delimiter, \
 | 
						|
                    void *fc, tx_fc_msg_t *msg);
 | 
						|
uint32_t mac_get_delimi_from_fc(uint32_t proto, \
 | 
						|
                    void *fc);
 | 
						|
uint8_t mac_get_pb_hdr_crc_len(uint32_t delimiter, uint32_t proto);
 | 
						|
uint8_t mac_get_pb_hdr_resv_crc_len(uint32_t delimiter, uint32_t proto);
 | 
						|
uint8_t mac_get_pb_pld_crc_len(uint32_t delimiter, uint32_t proto);
 | 
						|
uint8_t mac_get_pb_crc_len(uint32_t delimiter, uint32_t proto);
 | 
						|
uint8_t mac_get_mpdu_fc_len(uint32_t proto);
 | 
						|
uint8_t mac_get_mpdu_fccs_len(uint32_t proto);
 | 
						|
uint8_t mac_get_pb_hdr_len(uint32_t delimiter, uint32_t proto);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief mac_get_sof_pb_valid_payload_sz
 | 
						|
 *                              get sof pb payload len
 | 
						|
 *@param proto                  sof protocol. see plc_protocol.h
 | 
						|
 *@param pb_size                sof pb size
 | 
						|
 *@return                       0: get failed;
 | 
						|
 *                              others: sof pb payload length
 | 
						|
 */
 | 
						|
uint32_t mac_get_sof_pb_valid_payload_sz(uint32_t proto, uint32_t pb_size);
 | 
						|
 | 
						|
void mac_beacon_rx_fc_info_get(uint8_t proto, mac_rx_info_t *rx_info,
 | 
						|
                                    rx_fc_msg_t *msg);
 | 
						|
 | 
						|
/*
 | 
						|
 * get/set nncco's protect duration part for different kind of protocol
 | 
						|
 * @param   proto - protocol value
 | 
						|
 * @param   fc - pointer for frame control
 | 
						|
 * @param   dur - value to set, unit ms
 | 
						|
 */
 | 
						|
uint32_t mac_get_nncco_protect_dur(uint32_t proto, void *fc);
 | 
						|
 | 
						|
uint32_t mac_get_nncco_protect_region_offset(uint32_t proto, void *fc);
 | 
						|
uint32_t mac_get_nncco_received_nid(uint32_t proto, void *fc);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief mac_get_nncco_self_ch_id
 | 
						|
 *                              get nncco self rf channel id
 | 
						|
 *@param proto                  sof protocol. see PLC_PROTO_TYPE_XXX
 | 
						|
 *@param fc                     fc/hdr pointer
 | 
						|
 *@return                       nncco fc self rf channel id
 | 
						|
 */
 | 
						|
uint8_t mac_get_nncco_self_ch_id(uint32_t proto, void *fc);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief mac_get_nncco_self_option
 | 
						|
 *                              get nncco self rf option id
 | 
						|
 *@param proto                  sof protocol. see PLC_PROTO_TYPE_XXX
 | 
						|
 *@param fc                     fc/hdr pointer
 | 
						|
 *@return                       nncco fc self rf option id
 | 
						|
 */
 | 
						|
uint8_t mac_get_nncco_self_option(uint32_t proto, void *fc);
 | 
						|
 | 
						|
uint32_t mac_is_unicast(uint32_t proto, void *fc, uint8_t is_rf);
 | 
						|
 | 
						|
uint32_t mac_get_sof_frame_len(uint32_t proto, void *fc);
 | 
						|
 | 
						|
uint32_t mac_get_sof_pbnum(uint32_t proto, void *fc);
 | 
						|
 | 
						|
uint32_t mac_mask_input_nid(uint32_t nid);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief mac_get_bcn_st
 | 
						|
 *                              get timestamp from fc
 | 
						|
 *@param proto                  sof protocol. see plc_protocol.h
 | 
						|
 *@param fc                     fc pointer
 | 
						|
 *@return                       0: get failed;
 | 
						|
 *                              others: sof pb payload length
 | 
						|
 */
 | 
						|
uint32_t mac_get_bcn_st(uint32_t proto, void *fc);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief mac_get_fc_dtei        fc dtei
 | 
						|
 *@param proto                  sof protocol. see plc_protocol.h
 | 
						|
 *@param fc                     fc pointer
 | 
						|
 *@return                       dtei;
 | 
						|
 *                              others: sof pb payload length
 | 
						|
 */
 | 
						|
uint32_t mac_get_fc_dtei(uint32_t proto, void *fc);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief mac_get_unicast_sack_ts
 | 
						|
 *                              get unicast tx sack timestamp
 | 
						|
 *@return                       tx sack ntb timestamp
 | 
						|
 */
 | 
						|
uint32_t mac_get_unicast_sack_ts(void);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief mac_fc_i1901_to_sg     convert ieee1901 fc to sg fc
 | 
						|
 *@param proto                  current phy protocol type
 | 
						|
 *@param fc                     ieee1901 protocol fc
 | 
						|
 *@return                       none
 | 
						|
 */
 | 
						|
void mac_fc_i1901_to_sg(uint32_t proto, void *fc);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief mac_fc_sg_to_i1901     convert sg fc to ieee1901 fc
 | 
						|
 *@param proto                  current phy protocol type
 | 
						|
 *@param fc                     sg protocol fc
 | 
						|
 *@return                       none
 | 
						|
 */
 | 
						|
void mac_fc_sg_to_i1901(uint32_t proto, void *fc);
 | 
						|
 | 
						|
#if (ENA_HW_SYNC_PPM_WAR || ENA_SW_SYNC_PPM_WAR)
 | 
						|
/**
 | 
						|
 *@brief mac_get_clear_dbg_pkt_ppm_step
 | 
						|
                                get current packet ppm step and clean
 | 
						|
 *@param fc                     fc address
 | 
						|
 *@return                       ppm step
 | 
						|
 */
 | 
						|
int32_t mac_get_clear_dbg_pkt_ppm_step(void *fc);
 | 
						|
 | 
						|
/**
 | 
						|
 *@brief mac_modify_dbg_pkt_tx_ppm
 | 
						|
                                fix current packet tx ppm
 | 
						|
 *@param step                   ppm shift value
 | 
						|
 *@return                       none
 | 
						|
 */
 | 
						|
void mac_modify_dbg_pkt_tx_ppm(int32_t step);
 | 
						|
 | 
						|
#else /* (ENA_HW_SYNC_PPM_WAR || ENA_SW_SYNC_PPM_WAR) */
 | 
						|
 | 
						|
#define mac_get_clear_dbg_pkt_ppm_step(fc)          \
 | 
						|
    (0); \
 | 
						|
    do { \
 | 
						|
        (void)(fc); \
 | 
						|
    } while(0)
 | 
						|
 | 
						|
#define mac_modify_dbg_pkt_tx_ppm(step)             \
 | 
						|
    do { \
 | 
						|
        (void)(step); \
 | 
						|
    } while(0)
 | 
						|
 | 
						|
#endif /* (ENA_HW_SYNC_PPM_WAR || ENA_SW_SYNC_PPM_WAR) */
 | 
						|
 | 
						|
#ifdef __cplusplus
 | 
						|
}
 | 
						|
#endif
 | 
						|
 | 
						|
#endif
 |