714 lines
		
	
	
		
			23 KiB
		
	
	
	
		
			C
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			714 lines
		
	
	
		
			23 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.
 | |
| 
 | |
| ****************************************************************************/
 | |
| #include "tx_test_lib.h"
 | |
| #include "mac_sys_reg.h"
 | |
| #include "hw_reg_api.h"
 | |
| #include "mac_tx_hw.h"
 | |
| #include "iot_errno.h"
 | |
| #include "iot_io.h"
 | |
| #include "mac_pdev.h"
 | |
| #include "iot_bitops.h"
 | |
| #include "hw_phy_init.h"
 | |
| #include "hw_tonemap.h"
 | |
| #include "phy_chn.h"
 | |
| #include "mac_crc.h"
 | |
| #include "mpdu_header.h"
 | |
| #include "mac_desc_engine.h"
 | |
| #include "mac_rx_hw.h"
 | |
| #include "mac_cert_test.h"
 | |
| #include "tx_desc_reg_api.h"
 | |
| #include "rf_tx_test_lib.h"
 | |
| 
 | |
| #if (IOT_FTM_SUPPORT || CPLC_IOT_CERT_SUPPORT)
 | |
| 
 | |
| #if HW_PLATFORM >= HW_PLATFORM_FPGA
 | |
| 
 | |
| uint32_t enq_time = 0;
 | |
| uint8_t close_tx_print = 0;
 | |
| uint8_t mac_ping_enable = 0;
 | |
| 
 | |
| uint32_t mac_sche_set_cfg(void *vdev, hw_sched_cmd_t *cmdlist,
 | |
|     uint16_t cmd_num, uint32_t bcn_pd, uint32_t start_ntb)
 | |
| {
 | |
|     /* disable plc schedule */
 | |
|     mac_sched_enable_bp(vdev, 0);
 | |
|     /* config HW scheduler alert time */
 | |
|     mac_sched_set_bp_ahead_alert(vdev, MAC_BP_AHEAD_ALERT_DUR);
 | |
|     /*set cmd list and cmd num*/
 | |
|     mac_sched_set_bp_cmd_list(vdev, cmdlist, cmd_num);
 | |
|     /*set bcn period*/
 | |
|     mac_sched_set_bp_dur(vdev, bcn_pd);
 | |
| 
 | |
|     /* set plc start ntb */
 | |
|     mac_sched_set_bp_start_ntb(vdev, start_ntb);
 | |
|     /* start plc */
 | |
|     mac_sched_trigger_bp(vdev);
 | |
|     mac_sched_enable_bp(vdev, 1);
 | |
|     return 0;
 | |
| }
 | |
| 
 | |
| //TODO:fill mac msdu header for test
 | |
| bool_t mac_fill_msdu_frame(uint32_t proto, iot_pkt_t *buf, uint16_t data_len)
 | |
| {
 | |
|     uint16_t msdu_len = 0;
 | |
| 
 | |
|     IOT_ASSERT(buf);
 | |
|     //TODO: no mac addr case
 | |
|     switch (proto)
 | |
|     {
 | |
| #if SUPPORT_SMART_GRID
 | |
|     case PLC_PROTO_TYPE_SG:
 | |
|     {
 | |
|         if (iot_pkt_data_len(buf) < (data_len + SG_MAC_MSDU_CRC_LEN))
 | |
|         {
 | |
|             return false;
 | |
|         }
 | |
|         mac_header_t *sg_mac = (mac_header_t *)iot_pkt_data(buf);
 | |
|         if (sg_mac->mac_exist_flag) {
 | |
|             msdu_len = data_len - MAC_HDR_LEN_WITH_ADDR;
 | |
|         } else {
 | |
|             msdu_len = data_len - MAC_HDR_LEN_NO_ADDR;
 | |
|         }
 | |
|         if (sg_mac->msdu_len != msdu_len)
 | |
|         {
 | |
|             iot_printf("warning: msdu len not match,fix from %d to %d\r\n", \
 | |
|                 sg_mac->msdu_len, msdu_len);
 | |
|             sg_mac->msdu_len = msdu_len;
 | |
|         }
 | |
|         break;
 | |
|     }
 | |
| #endif
 | |
| 
 | |
| #if SUPPORT_SOUTHERN_POWER_GRID
 | |
|     case PLC_PROTO_TYPE_SPG:
 | |
|     {
 | |
|         if (iot_pkt_data_len(buf) < (data_len + SPG_MAC_MSDU_CRC_LEN))
 | |
|         {
 | |
|             return false;
 | |
|         }
 | |
|         spg_mac_header_t *spg_mac = (spg_mac_header_t *)iot_pkt_data(buf);
 | |
|         if (spg_mac->mac_hdr_type) {
 | |
|             /* short msdu */
 | |
|             msdu_len = data_len - MAC_SHORT_HDR_LEN_SPG;
 | |
|         } else {
 | |
|             /* long msdu */
 | |
|             msdu_len = data_len - MAC_LONG_HDR_LEN_SPG;
 | |
|         }
 | |
|         if (spg_mac->msdu_len != msdu_len)
 | |
|         {
 | |
|             iot_printf("warning: msdu len not match,fix from %d to %d\r\n", \
 | |
|                 spg_mac->msdu_len, msdu_len);
 | |
|             spg_mac->msdu_len = msdu_len;
 | |
|         }
 | |
|         break;
 | |
|     }
 | |
| #endif
 | |
| 
 | |
| #if SUPPORT_GREEN_PHY
 | |
|         case PLC_PROTO_TYPE_GP:
 | |
|         {
 | |
|             if (iot_pkt_data_len(buf) < (data_len + GP_MAC_MSDU_CRC_LEN))
 | |
|             {
 | |
|                 return false;
 | |
|             }
 | |
|             gp_mac_header_t *gp_mac = (gp_mac_header_t *)iot_pkt_data(buf);
 | |
|             msdu_len = data_len - sizeof(*gp_mac);
 | |
|             if (gp_mac->mfl != msdu_len)
 | |
|             {
 | |
|                 iot_printf("warning: msdu len not match,fix from %d to %d\r\n", \
 | |
|                     gp_mac->mfl, msdu_len);
 | |
|                 gp_mac->mfl = msdu_len;
 | |
|             }
 | |
|             break;
 | |
|         }
 | |
| #endif
 | |
| 
 | |
|     default:
 | |
|         return false;
 | |
|     }
 | |
|     return true;
 | |
| }
 | |
| 
 | |
| iot_pkt_t *ftm_fill_mac_data(uint8_t delimier_type,
 | |
|     uint16_t buf_len, uint8_t *pkt, uint16_t pkt_len)
 | |
| {
 | |
|     iot_pkt_t *buf;
 | |
|     IOT_PKT_GET(buf, buf_len, 0, PLC_MAC_TX_MID);
 | |
|     IOT_ASSERT(buf);
 | |
|     if (pkt_len > buf_len) {
 | |
|         iot_printf("waring drop some data, pb len:%d, data len:%d\n",
 | |
|             buf_len, pkt_len);
 | |
|         pkt_len = buf_len;
 | |
|     }
 | |
|     uint8_t *tmp = iot_pkt_put(buf, buf_len);
 | |
|     switch (delimier_type){
 | |
|     case FC_DELIM_BEACON:
 | |
|     {
 | |
|         IOT_ASSERT(pkt);
 | |
|         os_mem_cpy(tmp, pkt, pkt_len);
 | |
|         os_mem_set((tmp+pkt_len), 0, buf_len-pkt_len);
 | |
|         break;
 | |
|     }
 | |
|     case FC_DELIM_SOF:
 | |
|     {
 | |
|         IOT_ASSERT(pkt);
 | |
|         os_mem_cpy(tmp, pkt, pkt_len);
 | |
|         os_mem_set((tmp+pkt_len), 0, buf_len-pkt_len);
 | |
|         break;
 | |
|     }
 | |
|     case FC_DELIM_NNCCO:
 | |
|         (void)pkt;
 | |
|         (void)pkt_len;
 | |
|         os_mem_set(tmp, 0x55, buf_len);
 | |
|         break;
 | |
|     case FC_DELIM_SOUND:
 | |
|         IOT_ASSERT(pkt);
 | |
|         os_mem_cpy(tmp, pkt, pkt_len);
 | |
|         os_mem_set((tmp+pkt_len), 0, buf_len-pkt_len);
 | |
|         break;
 | |
|     default:
 | |
|         iot_printf("other frame\n");
 | |
|         break;
 | |
|     }
 | |
|     return buf;
 | |
| }
 | |
| 
 | |
| void mpdu_tx_beacon_test(uint32_t proto, mac_queue_ctxt_t *tx_ctxt, uint8_t qid,\
 | |
|        uint8_t bcast, uint8_t delimiter_type, uint32_t nid,\
 | |
|        uint32_t dtei, uint32_t stei, uint8_t tmi, uint8_t ext_tmi,\
 | |
|        uint8_t lid, uint8_t need_encry, tx_mpdu_end *mpdu_end,\
 | |
|        uint16_t pkt_len, uint8_t *pkt, uint8_t phase, uint32_t band_sel)
 | |
| {
 | |
|     tx_mpdu_start *mpdu;
 | |
|     tx_pb_start *pb;
 | |
|     uint32_t pb_sz;
 | |
|     uint32_t pb_mod;
 | |
|     uint32_t rate_mode = 0;
 | |
|     uint8_t pb_hdr_resv_crc_len;
 | |
|     uint32_t network = (PLC_PROTO_TYPE_SPG == proto)? 1:0;
 | |
|     uint8_t ppdu_mode = (PLC_PROTO_TYPE_GP == proto)? \
 | |
|         HW_DESC_PPDU_MODE_AVONLY_1FCSYM:0;
 | |
| 
 | |
|     mac_desc_get(&g_mac_desc_eng,PLC_TX_MPDU_START_POOL, (void**)&mpdu);
 | |
|     mac_desc_get(&g_mac_desc_eng,PLC_TX_PB_START_POOL, (void**)&pb);
 | |
|     IOT_ASSERT(mpdu && pb);
 | |
| 
 | |
|     phy_get_pb_size(proto, tmi, ext_tmi, &pb_sz);
 | |
|     phy_get_pb_mod(proto, tmi, ext_tmi, &pb_mod);
 | |
| 
 | |
|     /* get pb header + crc length */
 | |
|     pb_hdr_resv_crc_len = mac_get_pb_hdr_resv_crc_len(FC_DELIM_BEACON, \
 | |
|                                         proto);
 | |
|     iot_pkt_t *test_data = \
 | |
|         ftm_fill_mac_data(delimiter_type, (pb_sz - pb_hdr_resv_crc_len), \
 | |
|         pkt, pkt_len);
 | |
| 
 | |
| 
 | |
|     mac_crc_set_bcn_swcrc(proto,iot_pkt_data(test_data), pb_sz);
 | |
|     mac_tx_mpdu_fill_pb_start(pb, NULL, iot_pkt_data(test_data), 0, 1, 1, proto);
 | |
|     mac_crc_set_pb_swcrc(proto, pb, FC_DELIM_BEACON, pb_sz);
 | |
| 
 | |
|     mac_tx_mpdu_fill_macinfo(mpdu, qid, 1, need_encry, 0, \
 | |
|             phy_get_sym_per_pb(proto, 0, tmi, ext_tmi,
 | |
|             phy_get_pss_id(proto, tmi, ext_tmi)),\
 | |
|             phy_get_fl_per_pb(proto, 0, tmi, ext_tmi), 0,\
 | |
|             pb_hdr_resv_crc_len, 0, 1, 1, mpdu_end, pb, NULL, 0, \
 | |
|             (uint32_t)(iot_pkt_data(test_data) - (uint8_t*)test_data), \
 | |
|             0, 0, 0, 0, 0);
 | |
|     mac_tx_mpdu_fill_phyinfo(mpdu, HW_DESC_TX_PORT_PLC, \
 | |
|         128, phase, phy_def_hw_band_id_get(), \
 | |
|         ppdu_mode, 0, pb_mod, rate_mode);
 | |
|     mac_tx_mpdu_fill_fcinfo(mpdu, proto, \
 | |
|         1, phase, delimiter_type, network, nid, 0, \
 | |
|         tmi, ext_tmi, dtei, stei, lid, bcast, 0, 0, 0, 0, NULL);
 | |
|     mac_crc_set_fc_swcrc(proto, mpdu);
 | |
| 
 | |
|     {
 | |
|         /* get tx fc message */
 | |
|         tx_fc_msg_t msg = {0};
 | |
|         void *fc = mac_tx_mpdu_start_get_fc_ptr(mpdu);
 | |
|         mac_get_tx_msg_from_fc(proto, delimiter_type, fc, &msg);
 | |
|         iot_printf("proto = %d,""hwq = %d,"\
 | |
|                    "beacon tx:tmi = %d,"\
 | |
|                    "pb_num = %d\n", \
 | |
|                    proto, qid, msg.tmi, 1);
 | |
|     }
 | |
|     /* send */
 | |
|     mac_tx_hw_mpdu(tx_ctxt, qid, mpdu);
 | |
| }
 | |
| 
 | |
| void mpdu_tx_sof_test(uint32_t proto, mac_queue_ctxt_t *tx_ctxt, uint8_t qid,\
 | |
|        uint8_t bcast, uint8_t delimiter_type,uint32_t nid, uint32_t dtei,\
 | |
|        uint32_t stei,uint8_t tmi, uint8_t ext_tmi, uint8_t lid,\
 | |
|        uint8_t pb_num,uint8_t need_ack, uint8_t need_encry,\
 | |
|        uint8_t need_decrypt, uint32_t avln_idx_in_desc,\
 | |
|        uint32_t key_table_idx_in_desc, uint32_t key_idx_in_desc,\
 | |
|        uint8_t hw_retry_cnt, tx_mpdu_end *mpdu_end, uint16_t pkt_len, \
 | |
|        uint8_t *pkt, uint8_t phase, uint32_t band_sel, \
 | |
|        uint8_t rawdata_mode, uint8_t *fc_rawdata)
 | |
| {
 | |
|     tx_mpdu_start *mpdu;
 | |
|     tx_pb_start *pb;
 | |
|     uint32_t pb_sz;
 | |
|     uint32_t bitmap;
 | |
|     uint32_t pb_mod;
 | |
|     uint32_t rate_mode = 0;
 | |
|     uint32_t network = (PLC_PROTO_TYPE_SPG == proto)? 1:0;
 | |
|     uint8_t ppdu_mode = (PLC_PROTO_TYPE_GP == proto)? \
 | |
|         HW_DESC_PPDU_MODE_AVONLY_1FCSYM:0;
 | |
| 
 | |
|     phy_get_pb_size(proto, tmi, ext_tmi,&pb_sz);
 | |
|     phy_get_pb_mod(proto, tmi, ext_tmi, &pb_mod);
 | |
| 
 | |
|     /* get header + crc length */
 | |
|     uint8_t pb_hdr_resv_crc_len = mac_get_pb_hdr_resv_crc_len(delimiter_type, proto);
 | |
| 
 | |
|     iot_pkt_t *test_data = \
 | |
|         ftm_fill_mac_data(delimiter_type, \
 | |
|             ((pb_sz - pb_hdr_resv_crc_len) * pb_num), pkt, pkt_len);
 | |
| 
 | |
|     bitmap = 0xffffffff >> (32 - pb_num);
 | |
| 
 | |
|     if(!rawdata_mode)
 | |
|     {
 | |
|         mac_fill_msdu_frame(proto, test_data, pkt_len);
 | |
|         mac_crc_set_msdu_swcrc(proto, test_data);
 | |
|     }
 | |
| 
 | |
|     mac_desc_get(&g_mac_desc_eng,PLC_TX_MPDU_START_POOL, (void**)&mpdu);
 | |
|     IOT_ASSERT(mpdu);
 | |
|     mac_tx_mpdu_form_pb_list(&pb, test_data, pb_num, bitmap, pb_sz, proto);
 | |
| 
 | |
|     if(rawdata_mode)
 | |
|     {
 | |
|         /* if raw data mode, sw fill pb header and pb crc */
 | |
| #if CPLC_IOT_CERT_SUPPORT
 | |
|         fill_pb_hdr_crc_rawdata(pb, g_mt_ctxt->pb_header, g_mt_ctxt->pb_crc);
 | |
| #endif
 | |
|     }
 | |
| 
 | |
|     mac_tx_mpdu_fill_macinfo(mpdu, qid, pb_num, need_encry, need_ack,\
 | |
|         phy_get_sym_per_pb(proto, phy_def_hw_band_id_get(), tmi, ext_tmi,
 | |
|             phy_get_pss_id(proto, tmi, ext_tmi)),\
 | |
|         phy_get_fl_per_pb(proto, \
 | |
|             phy_def_hw_band_id_get(), tmi, ext_tmi), 0,\
 | |
|         pb_hdr_resv_crc_len, hw_retry_cnt, 1, 1, mpdu_end, pb, NULL, 0, \
 | |
|         (uint32_t)(iot_pkt_data(test_data) - (uint8_t*)test_data), 0, \
 | |
|         avln_idx_in_desc, key_table_idx_in_desc, key_idx_in_desc, 0);
 | |
|     mac_tx_mpdu_fill_phyinfo(mpdu, HW_DESC_TX_PORT_PLC, \
 | |
|         128, phase, phy_def_hw_band_id_get(), \
 | |
|         ppdu_mode, 0, pb_mod, rate_mode);
 | |
| 
 | |
|     uint8_t proto_org = 0;
 | |
|     if(rawdata_mode)
 | |
|     {
 | |
|         /* if raw data mode, save original proto */
 | |
|         proto_org = proto;
 | |
|         proto = PLC_PROTO_TYPE_RAWDATA;
 | |
|     }
 | |
|     mac_tx_mpdu_fill_fcinfo(mpdu, proto, \
 | |
|         pb_num, phase, delimiter_type, network, nid, 0,\
 | |
|         tmi, ext_tmi, dtei, stei, lid, bcast, 0,need_encry,\
 | |
|         key_table_idx_in_desc ,key_idx_in_desc, fc_rawdata);
 | |
| 
 | |
|     void *fcv = mac_tx_mpdu_start_get_fc_ptr(mpdu);
 | |
| 
 | |
|     if(rawdata_mode)
 | |
|     {
 | |
|         proto = proto_org;
 | |
|     }
 | |
|     if(!need_decrypt)
 | |
|     {
 | |
|         switch (proto) {
 | |
| #if SUPPORT_SMART_GRID
 | |
|         case PLC_PROTO_TYPE_SG:
 | |
|         {
 | |
|             frame_control_t *fc = \
 | |
|                 (frame_control_t *)fcv;
 | |
|             fc->vf.sof.decrypt_mode = 0;
 | |
|             break;
 | |
|         }
 | |
| #endif
 | |
| #if SUPPORT_SOUTHERN_POWER_GRID
 | |
|         case PLC_PROTO_TYPE_SPG:
 | |
|         {
 | |
|             spg_frame_control_t *fc = \
 | |
|                 (spg_frame_control_t *)fcv;
 | |
|             fc->vf.sof.decrypt_mode = 0;
 | |
|             break;
 | |
|         }
 | |
| #endif
 | |
| #if SUPPORT_GREEN_PHY
 | |
|         case PLC_PROTO_TYPE_GP:
 | |
|         {
 | |
|             hpav_frame_control *fc = (hpav_frame_control *)fcv;
 | |
|             fc->vf_av.sof.eks = 0x0f;
 | |
|             break;
 | |
|         }
 | |
| #endif
 | |
|         default:
 | |
|             IOT_ASSERT(0);
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     mac_crc_set_fc_swcrc(proto, mpdu);
 | |
|     if(rawdata_mode)
 | |
|     {
 | |
|         /* if rawdata mode, copy fcs and don't use hw fcs */
 | |
| #if SUPPORT_SMART_GRID
 | |
|         frame_control_t *fc = (frame_control_t *) fcv;
 | |
|         frame_control_t *fc_rawdata_p = (frame_control_t *) fc_rawdata;
 | |
|         fc->vf.sof.fccs = fc_rawdata_p->vf.sof.fccs;
 | |
| #elif SUPPORT_SOUTHERN_POWER_GRID
 | |
|         spg_frame_control_t *fc = (spg_frame_control_t*)fcv;
 | |
|         spg_frame_control_t *fc_rawdata_p = (spg_frame_control_t *) fc_rawdata;
 | |
|         fc->vf.sof.fccs = fc_rawdata_p->vf.sof.fccs;
 | |
| #endif
 | |
|     }
 | |
|     if(!close_tx_print)
 | |
|     {
 | |
|         tx_fc_msg_t msg = {0};
 | |
|         mac_get_tx_msg_from_fc(proto, delimiter_type, fcv, &msg);
 | |
| 
 | |
|         {
 | |
|             iot_printf("proto = %d," \
 | |
|                        "hwq = %d," \
 | |
|                        "sof tx:tmi = %d," \
 | |
|                        "sof tx:ext_tmi = %d," \
 | |
|                        "pb_num = %d\n", \
 | |
|                        proto, qid, tmi, ext_tmi, pb_num);
 | |
|         }
 | |
|     }
 | |
|     /* send */
 | |
|     mac_tx_hw_mpdu(tx_ctxt, qid, mpdu);
 | |
| }
 | |
| 
 | |
| uint32_t mac_tx_mpdu_fill_ack_fcinfo(tx_mpdu_start *mpdu_start,\
 | |
|     uint32_t proto, uint32_t delimter, uint32_t network, uint32_t nid,\
 | |
|     uint32_t rx_result, uint32_t rx_status, \
 | |
|     uint32_t stei, uint32_t dtei, uint32_t rx_pb, uint32_t snr, \
 | |
|     uint32_t load, uint32_t ext_deli)
 | |
| {
 | |
|     IOT_ASSERT(mpdu_start);
 | |
|     mpdu_start->proto_type = proto;
 | |
| #if SUPPORT_SMART_GRID
 | |
|     frame_control_t *fc =  (frame_control_t *)mac_tx_mpdu_start_get_fc_ptr(mpdu_start);
 | |
|     fc->delimiter_type = delimter;
 | |
|     fc->network_type = network;
 | |
|     fc->nid = nid;
 | |
|     fc->vf.sack.rx_result = rx_result;
 | |
|     fc->vf.sack.rx_status = rx_status;
 | |
|     fc->vf.sack.stei = stei;
 | |
|     fc->vf.sack.dtei = dtei;
 | |
|     fc->vf.sack.rx_pb = rx_pb;
 | |
|     fc->vf.sack.resv0 = 0;
 | |
|     fc->vf.sack.snr = snr;
 | |
|     fc->vf.sack.load = load;
 | |
|     fc->vf.sack.resv1 = 0;
 | |
|     fc->vf.sack.ext_deli = ext_deli;
 | |
|     fc->vf.sack.version = 0;
 | |
| #else
 | |
|     IOT_ASSERT(0);
 | |
| #endif
 | |
|     return 0;
 | |
| }
 | |
| 
 | |
| void mpdu_tx_ack_test(uint32_t proto, mac_queue_ctxt_t *tx_ctxt,\
 | |
|        uint8_t qid, tx_mpdu_end *mpdu_end, uint32_t band_sel, \
 | |
|        uint8_t rawdata_mode, uint8_t *fc_rawdata, uint8_t phase,\
 | |
|        uint8_t delimiter_type, uint32_t nid,
 | |
|        uint32_t rx_result, uint32_t rx_status, uint32_t stei, \
 | |
|        uint32_t dtei, uint32_t rx_pb, uint32_t snr, uint32_t load, \
 | |
|        uint32_t ext_deli)
 | |
| {
 | |
|     tx_mpdu_start *mpdu;
 | |
|     uint32_t network = (PLC_PROTO_TYPE_SPG == proto)? 1:0;
 | |
|     uint8_t ppdu_mode = (PLC_PROTO_TYPE_GP == proto)? \
 | |
|         HW_DESC_PPDU_MODE_AVONLY_1FCSYM:0;
 | |
| 
 | |
|     mac_desc_get(&g_mac_desc_eng,PLC_TX_MPDU_START_POOL, (void**)&mpdu);
 | |
|     IOT_ASSERT(mpdu);
 | |
| 
 | |
|     mac_tx_mpdu_fill_macinfo(mpdu, qid, 0, 0, 0,\
 | |
|         0, 0, 0, 0, 0, 1, 1, mpdu_end, NULL, NULL, 0, \
 | |
|         0, 0, 0, 0, 0, 0);
 | |
|     mac_tx_mpdu_fill_phyinfo(mpdu, HW_DESC_TX_PORT_PLC, \
 | |
|         128, phase, phy_def_hw_band_id_get(), ppdu_mode, 0, 1, 0);
 | |
| 
 | |
|     uint8_t proto_tmp = 0;
 | |
|     if(rawdata_mode)  //if mtmode goto rawdata mode
 | |
|     {
 | |
|         proto_tmp = proto;
 | |
|         proto = PLC_PROTO_TYPE_RAWDATA;
 | |
|     }
 | |
|     mac_tx_mpdu_fill_ack_fcinfo(mpdu, proto, delimiter_type, network, nid,\
 | |
|     rx_result, rx_status, stei, dtei, rx_pb, snr, load, ext_deli);
 | |
|     if(rawdata_mode)
 | |
|     {
 | |
|         proto = proto_tmp;
 | |
|     }
 | |
| 
 | |
|     mac_crc_set_fc_swcrc(proto, mpdu);
 | |
| 
 | |
|     {
 | |
|         iot_printf("hwq = %d ack tx_done\n",qid);
 | |
|     }
 | |
|     /* send */
 | |
|     mac_tx_hw_mpdu(tx_ctxt, qid, mpdu);
 | |
| 
 | |
| }
 | |
| void mpdu_tx_nncco_or_rtscts_test(uint32_t proto, mac_queue_ctxt_t *tx_ctxt,
 | |
|        uint8_t qid, uint8_t bcast, uint8_t delimiter_type,uint32_t nid,
 | |
|        uint32_t dtei, uint32_t stei,uint8_t lid,uint8_t need_encry,
 | |
|        tx_mpdu_end *mpdu_end)
 | |
| {
 | |
|     tx_mpdu_start *mpdu;
 | |
|     uint32_t network = (PLC_PROTO_TYPE_SPG == proto)? 1:0;
 | |
|     uint8_t ppdu_mode = (PLC_PROTO_TYPE_GP == proto)?
 | |
|         HW_DESC_PPDU_MODE_AVONLY_1FCSYM:0;
 | |
| 
 | |
|     mac_desc_get(&g_mac_desc_eng,PLC_TX_MPDU_START_POOL, (void**)&mpdu);
 | |
|     IOT_ASSERT(mpdu);
 | |
| 
 | |
|     mac_tx_mpdu_fill_macinfo(mpdu, qid, 0, 0, 0,
 | |
|         0, 0, 0, 0, 0, 1, 1, mpdu_end, NULL, NULL, 0,
 | |
|         0, 0, 0, 0, 0, 0);
 | |
|     mac_tx_mpdu_fill_phyinfo(mpdu, HW_DESC_TX_PORT_PLC,
 | |
|         128, HW_DESC_TX_PHASE_ALL, 0, ppdu_mode, 0, 1, 0);
 | |
|     mac_tx_mpdu_fill_fcinfo(mpdu, proto,
 | |
|         0, HW_DESC_TX_PHASE_ALL, delimiter_type, network, nid, 0,
 | |
|         0, 0, dtei, stei, lid, bcast, 0, 0, 0, 0, NULL);
 | |
|     mac_crc_set_fc_swcrc(proto, mpdu);
 | |
| 
 | |
|     iot_printf("hwq = %d deli:%d tx_done\n", qid, delimiter_type);
 | |
| 
 | |
|     /* send */
 | |
|     mac_tx_hw_mpdu(tx_ctxt, qid, mpdu);
 | |
| }
 | |
| 
 | |
| void mpdu_tx_sound_test(uint32_t proto, mac_queue_ctxt_t *tx_ctxt, uint8_t qid,\
 | |
|        uint8_t bcast, uint8_t delimiter_type,uint32_t nid,\
 | |
|        uint32_t dtei, uint32_t stei,uint8_t tmi, uint8_t ext_tmi,\
 | |
|        uint8_t lid,uint8_t need_ack, uint8_t need_encry,\
 | |
|        uint8_t hw_retry_cnt, tx_mpdu_end *mpdu_end,\
 | |
|        uint16_t pkt_len, uint8_t *pkt)
 | |
| {
 | |
|     tx_mpdu_start *mpdu;
 | |
|     tx_pb_start *pb;
 | |
|     uint32_t pb_sz;
 | |
|     uint32_t pb_mod;
 | |
|     uint32_t rate_mode = 0;
 | |
|     uint8_t ppdu_mode = (PLC_PROTO_TYPE_GP == proto)? \
 | |
|         HW_DESC_PPDU_MODE_AVONLY_1FCSYM:0;
 | |
|     if(proto == PLC_PROTO_TYPE_SPG)
 | |
|     {
 | |
|         iot_printf("NW do not supprot sound!");
 | |
|         return;
 | |
|     }
 | |
| 
 | |
|     phy_get_pb_size(proto, tmi, ext_tmi, &pb_sz);
 | |
|     phy_get_pb_mod(proto, tmi, ext_tmi, &pb_mod);
 | |
| 
 | |
|     uint8_t pb_hdr_resv_crc_len = mac_get_pb_hdr_resv_crc_len(delimiter_type, proto);
 | |
| 
 | |
|     iot_pkt_t *test_data = \
 | |
|         ftm_fill_mac_data(delimiter_type, (pb_sz - pb_hdr_resv_crc_len), \
 | |
|         pkt, pkt_len);
 | |
| 
 | |
| 
 | |
|     mac_desc_get(&g_mac_desc_eng,PLC_TX_PB_START_POOL, (void**)&pb);
 | |
|     mac_desc_get(&g_mac_desc_eng,PLC_TX_MPDU_START_POOL, (void**)&mpdu);
 | |
|     IOT_ASSERT(mpdu && pb);
 | |
| 
 | |
|     mac_tx_mpdu_fill_pb_start(pb, NULL, iot_pkt_data(test_data), 0, 1, 1, proto);
 | |
| 
 | |
|     mac_tx_mpdu_fill_macinfo(mpdu, qid, 1, 0, need_ack,\
 | |
|         phy_get_sym_per_pb(proto, 0, tmi, ext_tmi,
 | |
|         phy_get_pss_id(proto, tmi, ext_tmi)),\
 | |
|         phy_get_fl_per_pb(proto, 0, tmi, ext_tmi), 0,\
 | |
|         pb_hdr_resv_crc_len, 0, 1, 1, mpdu_end, pb, NULL, 0, \
 | |
|         (uint32_t)(iot_pkt_data(test_data) - (uint8_t*)test_data), 0, 0, 0, 0, 0);
 | |
| 
 | |
|     mac_tx_mpdu_fill_phyinfo(mpdu, HW_DESC_TX_PORT_PLC, \
 | |
|         128, HW_DESC_TX_PHASE_ALL, 0, ppdu_mode, 0, pb_mod, rate_mode);
 | |
|     mac_tx_mpdu_fill_fcinfo(mpdu, proto, \
 | |
|         1, HW_DESC_TX_PHASE_ALL, delimiter_type, 0, nid, 0,\
 | |
|         tmi, ext_tmi, dtei, stei, lid, bcast, 0, 0, 0, 0, NULL);
 | |
|     mac_crc_set_fc_swcrc(proto, mpdu);
 | |
| 
 | |
|     {
 | |
|         tx_fc_msg_t msg = {0};
 | |
|         void *fc = mac_tx_mpdu_start_get_fc_ptr(mpdu);
 | |
|         mac_get_tx_msg_from_fc(proto, delimiter_type, fc, &msg);
 | |
| 
 | |
|         {
 | |
|             iot_printf("proto = %d," \
 | |
|                        "hwq = %d," \
 | |
|                        "sof tx:tmi = %d," \
 | |
|                        "sof tx:ext_tmi = %d," \
 | |
|                        "pb_num = %d\n", \
 | |
|                        proto, qid, msg.tmi, msg.ext_tmi, 1);
 | |
|         }
 | |
|     }
 | |
|     /* send */
 | |
|     mac_tx_hw_mpdu(tx_ctxt, qid, mpdu);
 | |
| }
 | |
| 
 | |
| void mpdu_send_test(mac_queue_ctxt_t *tx_ctxt, uint8_t qid,
 | |
|        uint8_t bcast, uint8_t delimiter_type,uint32_t nid,
 | |
|        uint32_t dtei, uint32_t stei,uint8_t tmi, uint8_t ext_tmi,
 | |
|        uint8_t lid, uint8_t pb_num, uint8_t need_ack,
 | |
|        uint8_t need_encry, uint8_t need_decrypt,
 | |
|        uint32_t avln_idx_in_desc, uint32_t key_table_idx_in_desc,
 | |
|        uint32_t key_idx_in_desc,
 | |
|        uint8_t hw_retry_cnt, uint16_t pkt_len, uint8_t *pkt, uint8_t phase,
 | |
|        uint32_t band_sel, uint8_t rawdata_mode, uint8_t *fc_rawdata)
 | |
| {
 | |
|     tx_mpdu_end *end;
 | |
|     /* mac protocol */
 | |
|     uint32_t proto = PHY_PROTO_TYPE_GET();
 | |
| 
 | |
|     mac_desc_get(&g_mac_desc_eng, PLC_TX_MPDU_END_POOL, (void**)&end);
 | |
|     IOT_ASSERT(end);
 | |
|     end->tx_done = 0;
 | |
|     end->tx_ok = 0;
 | |
|     (proto != PLC_PROTO_TYPE_GP)? (bcast = bcast):
 | |
|         (bcast = 0);
 | |
| 
 | |
|     switch(delimiter_type){
 | |
|     case FC_DELIM_BEACON:
 | |
|     {
 | |
|         (void)pb_num;
 | |
|         (void)need_ack;
 | |
|         (void)need_decrypt;
 | |
|         (void)hw_retry_cnt;
 | |
|         (void)avln_idx_in_desc;
 | |
|         (void)key_table_idx_in_desc;
 | |
|         (void)key_idx_in_desc;
 | |
|         mpdu_tx_beacon_test(proto,tx_ctxt, qid, bcast, FC_DELIM_BEACON, nid,
 | |
|             dtei,  stei, tmi, ext_tmi,lid, need_encry, end, pkt_len, pkt, phase,
 | |
|             band_sel);
 | |
|         break;
 | |
|     }
 | |
|     case FC_DELIM_SOF:
 | |
|     {
 | |
|         mpdu_tx_sof_test(proto, tx_ctxt, qid, bcast, FC_DELIM_SOF, nid,
 | |
|             dtei, stei, tmi, ext_tmi,lid, pb_num, need_ack, need_encry,
 | |
|             need_decrypt, avln_idx_in_desc, key_table_idx_in_desc,
 | |
|             key_idx_in_desc, hw_retry_cnt, end, pkt_len, pkt, phase,
 | |
|             band_sel, rawdata_mode, fc_rawdata);
 | |
|         break;
 | |
|     }
 | |
|     case FC_DELIM_SACK:
 | |
|     {
 | |
|         mpdu_tx_ack_test(proto, tx_ctxt, qid, end, band_sel,
 | |
|             rawdata_mode, fc_rawdata, phase, FC_DELIM_SACK, nid,
 | |
|             0, 1, 1, 0xfff, 1, 0xff, 0, 0);
 | |
|         break;
 | |
|     }
 | |
|     case FC_DELIM_NNCCO:
 | |
|     {
 | |
|         (void)tmi;
 | |
|         (void)ext_tmi;
 | |
|         (void)pb_num;
 | |
|         (void)need_ack;
 | |
|         (void)need_decrypt;
 | |
|         (void)hw_retry_cnt;
 | |
|         (void)avln_idx_in_desc;
 | |
|         (void)key_table_idx_in_desc;
 | |
|         (void)key_idx_in_desc;
 | |
|         (void)pkt;
 | |
|         (void)pkt_len;
 | |
|         (void)band_sel;
 | |
|         mpdu_tx_nncco_or_rtscts_test(proto, tx_ctxt, qid, bcast,
 | |
|             FC_DELIM_NNCCO, nid, dtei, stei, lid, need_encry, end);
 | |
|         break;
 | |
|     }
 | |
|     case I1901_RTS_CTS:
 | |
|     {
 | |
|         (void)pb_num;
 | |
|         (void)need_encry;
 | |
|         (void)need_decrypt;
 | |
|         (void)avln_idx_in_desc;
 | |
|         (void)key_table_idx_in_desc;
 | |
|         (void)key_idx_in_desc;
 | |
|         mpdu_tx_nncco_or_rtscts_test(proto, tx_ctxt, qid, bcast,
 | |
|             I1901_RTS_CTS, nid, dtei, stei, lid, need_encry, end);
 | |
|         break;
 | |
|     }
 | |
|     default:
 | |
|         IOT_ASSERT(0);
 | |
|     }
 | |
| #if 0
 | |
|     uint32_t enq_time = RGF_MAC_READ_REG(CFG_RD_NTB_ADDR);
 | |
|     uint32_t cur_time, time_span;
 | |
| #define NTB_MS_TICK 25000 // 0.04us * 25 = 1us, 1us * 1000 = 1ms
 | |
| #define TX_TIMEOUT_TICK (NTB_MS_TICK << 5) // 32 ms
 | |
| 
 | |
|     mac_rx_ring_ctxt_t *ring_ctxt = &g_mac_pdev[0]->ring_hdl;
 | |
|     do {
 | |
|         cur_time = RGF_MAC_READ_REG(CFG_RD_NTB_ADDR);
 | |
|         time_span = cur_time - enq_time;
 | |
|         if (time_span < 0) { // wrap around
 | |
|              time_span = (0x100000000LL) - enq_time + cur_time;
 | |
|         }
 | |
|         if (time_span > TX_TIMEOUT_TICK) {
 | |
|             iot_printf("tx timeout: %dms > %dms\n", \
 | |
|                 time_span / NTB_MS_TICK, \
 | |
|                 TX_TIMEOUT_TICK / NTB_MS_TICK);
 | |
|             IOT_ASSERT(0);
 | |
|         }
 | |
|         for(uint8_t i=0;i<MAX_PLC_RX_RING_NUM;i++){
 | |
|             if(ring_ctxt->ring[i].enabled){
 | |
|                 mac_rx_hw_mpdu(g_mac_pdev[0], i);
 | |
|             }
 | |
|         }
 | |
|     } while (!end->tx_done);
 | |
|     mac_tx_hw_mpdu_comp(qid);
 | |
| #endif
 | |
| }
 | |
| 
 | |
| /* used for ping under ftm mode,
 | |
|  * TODO: to be removed later
 | |
|  */
 | |
| uint32_t test_send_sof(mac_queue_ctxt_t *tx_ctxt,
 | |
|     uint32_t stei, uint32_t dtei, uint32_t nid,\
 | |
|     uint8_t tmi, uint8_t ext_tmi,\
 | |
|     uint8_t pb_num, uint8_t *pkt,uint8_t need_ack)
 | |
| {
 | |
|     /* mac protocol */
 | |
|     uint32_t proto = PHY_PROTO_TYPE_GET();
 | |
|     tx_mpdu_end *end;
 | |
|     mac_desc_get(&g_mac_desc_eng, PLC_TX_MPDU_END_POOL, (void**)&end);
 | |
|     IOT_ASSERT(end);
 | |
|     end->tx_done = 0;
 | |
|     end->tx_ok = 0;
 | |
|     uint8_t qid = 0;
 | |
|     mpdu_tx_sof_test(proto,tx_ctxt, qid, 0, FC_DELIM_SOF, nid,\
 | |
|         dtei, stei, tmi, ext_tmi,0, pb_num, need_ack, 0, 0,\
 | |
|         0, 0, 0, 0, end,100, pkt, 0, 0, 0, NULL);
 | |
|     if(mac_ping_enable)
 | |
|     {
 | |
|         enq_time = RGF_MAC_READ_REG(CFG_RD_NTB_ADDR);
 | |
|     }
 | |
|     do {
 | |
|         mac_rx_hw_mpdu_internal(g_mac_pdev[0], 0, 1000);
 | |
|     } while (!end->tx_done);
 | |
|     mac_tx_hw_mpdu_comp(qid, 1);
 | |
|     return 0;
 | |
| }
 | |
| #endif
 | |
| #endif
 |