Commit d9d73306 authored by Nick Ho's avatar Nick Ho

MSG4 PDU packed at MAC level done!

parent aaaa5a97
......@@ -424,9 +424,8 @@ typedef struct {
/*!\brief MAC subheader short without length field */
typedef struct {
uint8_t LCID:5;
uint8_t F2:1;
uint8_t E:1;
uint8_t R:1;
uint8_t R:2;
} __attribute__((__packed__))SCH_SUBHEADER_FIXED_NB_IoT;
......@@ -549,7 +548,9 @@ typedef struct RA_TEMPLATE_NB_IoT_s{
boolean_t wait_msg4_ack;
boolean_t wait_msg3_ack;
uint8_t rar_buffer[7];
uint8_t *ccch_buffer;
uint8_t msg4_buffer[16];
uint8_t *msg4_rrc_buffer;
} RA_TEMPLATE_NB_IoT;
typedef struct RA_template_list_s{
......
......@@ -382,7 +382,7 @@ void msg4_do_retransmit_NB_IoT(eNB_MAC_INST_NB_IoT *mac_inst, rnti_t c_rnti){
return ;
}
void receive_msg3_NB_IoT(eNB_MAC_INST_NB_IoT *mac_inst, rnti_t c_rnti, uint32_t phr, uint32_t ul_total_buffer){
void receive_msg3_NB_IoT(eNB_MAC_INST_NB_IoT *mac_inst, rnti_t c_rnti, uint32_t phr, uint32_t ul_total_buffer, uint8_t* ccch_sdu, uint8_t* msg4_rrc_sdu){
// since successful receive msg3, tc-rnti become c-rnti.
RA_TEMPLATE_NB_IoT *msg3_nodes = mac_inst->RA_msg3_list.head;
......@@ -391,9 +391,11 @@ void receive_msg3_NB_IoT(eNB_MAC_INST_NB_IoT *mac_inst, rnti_t c_rnti, uint32_t
if((RA_TEMPLATE_NB_IoT *)0 != msg3_nodes)
while((RA_TEMPLATE_NB_IoT *)0 != msg3_nodes){
if(msg3_nodes->ue_rnti == c_rnti){
LOG_I(MAC,"add ue in\n");
LOG_D(MAC,"add ue in\n");
add_ue_NB_IoT(mac_inst, c_rnti, msg3_nodes->ce_level, phr, ul_total_buffer);// rnti, ce level
LOG_I(MAC,"[%04d][RA scheduler][MSG3][CE%d] Receive MSG3 T-CRNTI %d Preamble Index %d \n", mac_inst->current_subframe, msg3_nodes->ce_level, msg3_nodes->ue_rnti, msg3_nodes->preamble_index);
LOG_D(MAC,"[%04d][RA scheduler][MSG3][CE%d] Receive MSG3 T-CRNTI %d Preamble Index %d \n", mac_inst->current_subframe, msg3_nodes->ce_level, msg3_nodes->ue_rnti, msg3_nodes->preamble_index);
msg3_nodes->ccch_buffer = ccch_sdu;
msg3_nodes->msg4_rrc_buffer = msg4_rrc_sdu;
migrate_node = msg3_nodes;
// maintain list
......@@ -792,6 +794,7 @@ void schedule_msg4_NB_IoT(eNB_MAC_INST_NB_IoT *mac_inst, int abs_subframe){
if(0==fail){
LOG_D(MAC,"[%04d][RA scheduler][MSG4][CE%d] rnti: %d scheduling success\n", abs_subframe-1, msg4_nodes->ce_level, msg4_nodes->ue_rnti);
fill_msg4_NB_IoT(mac_inst,msg4_nodes);
msg4_nodes->wait_msg4_ack = 1;
DCIFormatN1_t *dci_n1_msg4 = (DCIFormatN1_t *)malloc(sizeof(DCIFormatN1_t));
// dci entity
......@@ -840,6 +843,7 @@ void schedule_msg4_NB_IoT(eNB_MAC_INST_NB_IoT *mac_inst, int abs_subframe){
msg4_result->R_harq = 0;
msg4_result->next = (schedule_result_t *)0;
msg4_result->DCI_pdu = (void *)dci_n1_msg4;
msg4_result->DLSCH_pdu = msg4_nodes->msg4_buffer;
harq_result = (schedule_result_t *)malloc(sizeof(schedule_result_t));
harq_result->rnti = msg4_nodes->ue_rnti;
......@@ -857,7 +861,7 @@ void schedule_msg4_NB_IoT(eNB_MAC_INST_NB_IoT *mac_inst, int abs_subframe){
LOG_I(MAC,"[%04d][RA scheduler][MSG4] UE:%x MSG4DCI %d-%d MSG4 %d-%d HARQ %d-%d\n", abs_subframe-1, msg4_nodes->ue_rnti, dci_first_subframe, dci_end_subframe, msg4_first_subframe, msg4_end_subframe, HARQ_info.sf_start, HARQ_info.sf_end);
LOG_I(MAC,"[%04d][RA scheduler][MSG4][CE%d] MSG4 DCI %d-%d MSG4 %d-%d HARQ %d-%d\n", abs_subframe-1, msg4_nodes->ce_level, dci_first_subframe, dci_end_subframe, msg4_first_subframe, msg4_end_subframe, HARQ_info.sf_start, HARQ_info.sf_end);
LOG_D(MAC,"[%04d][RA scheduler][MSG4][CE%d] MSG4 DCI %d-%d MSG4 %d-%d HARQ %d-%d\n", abs_subframe-1, msg4_nodes->ce_level, dci_first_subframe, dci_end_subframe, msg4_first_subframe, msg4_end_subframe, HARQ_info.sf_start, HARQ_info.sf_end);
msg4_nodes->msg4_retransmit_count++;
// fill dci resource
......@@ -941,7 +945,7 @@ void fill_rar_NB_IoT(
uint8_t msg3_repetition = msg3_rep;// 3bit
uint8_t mcs_index = 2;//3bit, msg3 88bits 3'b000
LOG_I(MAC,"Dump UL Grant: subcarrier spacing : %d, subcarrier indication: %d, delay : %d, Rep : %d, MCS : %d\n",subcarrier_spacing,subcarrier_indication,i_delay,msg3_repetition,mcs_index);
LOG_D(MAC,"Dump UL Grant: subcarrier spacing : %d, subcarrier indication: %d, delay : %d, Rep : %d, MCS : %d\n",subcarrier_spacing,subcarrier_indication,i_delay,msg3_repetition,mcs_index);
rar[1] |= (subcarrier_spacing<<3) | (subcarrier_indication>>3);
rar[2] = (uint8_t)(subcarrier_indication<<5) | (i_delay<<3) | msg3_repetition;
......@@ -953,4 +957,50 @@ void fill_rar_NB_IoT(
}
// Generate MSG4 MAC PDU
void fill_msg4_NB_IoT(
eNB_MAC_INST_NB_IoT *inst,
RA_TEMPLATE_NB_IoT *ra_template
)
{
uint8_t *dlsch_buffer = &ra_template->msg4_buffer[0];
// we have three subheader here: 1 for padding, 2 for Control element of Contention resolution, 3 for CCCH
SCH_SUBHEADER_FIXED_NB_IoT *msg4_sub_1 = (SCH_SUBHEADER_FIXED_NB_IoT*)dlsch_buffer;
msg4_sub_1->R = 0;
msg4_sub_1->E = 1;
msg4_sub_1->LCID = PADDING;
SCH_SUBHEADER_FIXED_NB_IoT *msg4_sub_2 = (SCH_SUBHEADER_FIXED_NB_IoT *) (msg4_sub_1 +1);
msg4_sub_2->R = 0;
msg4_sub_2->E = 1;
msg4_sub_2->LCID = UE_CONTENTION_RESOLUTION;
SCH_SUBHEADER_FIXED_NB_IoT *msg4_sub_3 = (SCH_SUBHEADER_FIXED_NB_IoT *) (msg4_sub_2 +1);
msg4_sub_3->R= 0;
msg4_sub_3->E= 0;
msg4_sub_3->LCID = CCCH_NB_IoT;
uint8_t *con_res = (uint8_t *)(dlsch_buffer+3);
con_res[0] = ra_template->ccch_buffer[0];
con_res[1] = ra_template->ccch_buffer[1];
con_res[2] = ra_template->ccch_buffer[2];
con_res[3] = ra_template->ccch_buffer[3];
con_res[4] = ra_template->ccch_buffer[4];
con_res[5] = ra_template->ccch_buffer[5];
uint8_t *msg4_rrc_sdu = (uint8_t *) (dlsch_buffer+9);
msg4_rrc_sdu[0] = ra_template->msg4_rrc_buffer[0];
msg4_rrc_sdu[1] = ra_template->msg4_rrc_buffer[1];
msg4_rrc_sdu[2] = ra_template->msg4_rrc_buffer[2];
msg4_rrc_sdu[3] = ra_template->msg4_rrc_buffer[3];
msg4_rrc_sdu[4] = ra_template->msg4_rrc_buffer[4];
msg4_rrc_sdu[5] = ra_template->msg4_rrc_buffer[5];
msg4_rrc_sdu[6] = ra_template->msg4_rrc_buffer[6];
printf("MSG4 PDU = ");
for(int i=0; i<16;i++)
printf("%02x ",dlsch_buffer[i]);
printf("\n");
}
\ No newline at end of file
......@@ -457,7 +457,7 @@ uint32_t generate_dlsch_header_NB_IoT(uint8_t *pdu, uint32_t num_sdu, logical_ch
{
mac_header->LCID=PADDING;
mac_header->E=1;
mac_header->F2=0;
//mac_header->F2=0;
mac_header->R=0;
mac_header++;
offset++;
......@@ -466,7 +466,7 @@ uint32_t generate_dlsch_header_NB_IoT(uint8_t *pdu, uint32_t num_sdu, logical_ch
{
mac_header->LCID=PADDING;
mac_header->E=1;
mac_header->F2=0;
//mac_header->F2=0;
mac_header->R=0;
mac_header++;
offset++;
......@@ -475,7 +475,7 @@ uint32_t generate_dlsch_header_NB_IoT(uint8_t *pdu, uint32_t num_sdu, logical_ch
{
mac_header->LCID=DRX_COMMAND;
mac_header->E=1;
mac_header->F2=0;
//mac_header->F2=0;
mac_header->R=0;
mac_header++;
num_subheader--;
......@@ -487,7 +487,7 @@ uint32_t generate_dlsch_header_NB_IoT(uint8_t *pdu, uint32_t num_sdu, logical_ch
{
mac_header->E=0;
mac_header->LCID = logical_channel[i];
mac_header->F2=0;
//mac_header->F2=0;
mac_header->R=0;
offset++;
LOG_D(MAC,"last sdu\n");
......@@ -527,7 +527,7 @@ uint32_t generate_dlsch_header_NB_IoT(uint8_t *pdu, uint32_t num_sdu, logical_ch
{
mac_header->LCID=PADDING;
mac_header->E=0;
mac_header->F2=0;
//mac_header->F2=0;
mac_header->R=0;
mac_header++;
offset++;
......
......@@ -220,7 +220,9 @@ void rx_sdu_NB_IoT(module_id_t module_id, int CC_id, frame_t frame, sub_frame_t
int ul_total_buffer = 0;
//mac_NB_IoT_t *mac_inst;
UE_TEMPLATE_NB_IoT *UE_info;
LOG_I(MAC,"RX_SDU_IN\n");
uint8_t* msg4_rrc_pdu = NULL;
LOG_D(MAC,"RX_SDU_IN\n");
//mac_inst = get_mac_inst(module_id);
// note: if lcid < 25 this is sdu, otherwise this is CE
......@@ -261,15 +263,15 @@ void rx_sdu_NB_IoT(module_id_t module_id, int CC_id, frame_t frame, sub_frame_t
LOG_I(MAC,"PHR = %d, ul_total_buffer = %d\n",PHR,ul_total_buffer);
// go to payload
payload_ptr+=1;
// Note that the first 6 byte (48 bits) of this CCCH SDU should be encoded in the MSG4 for contention resolution
// Note that the first 6 byte (48 bits) of this CCCH SDU should be encoded in the MSG4 for contention resolution
printf("CCCH SDU content: ");
for(int a = 0; a<9;a++)
printf("%02x ",payload_ptr[a]);
printf("\n");
rx_lengths[i]-=1;
LOG_D(MAC,"rx_lengths : %d\n", rx_lengths[i]);
mac_rrc_msg3_ind_NB_IoT(payload_ptr,rnti,rx_lengths[i]);
receive_msg3_NB_IoT(mac_inst,rnti,PHR,DVI_index);
msg4_rrc_pdu = mac_rrc_msg3_ind_NB_IoT(payload_ptr,rnti,rx_lengths[i]);
receive_msg3_NB_IoT(mac_inst,rnti,PHR,DVI_index,payload_ptr,msg4_rrc_pdu);
LOG_D(MAC,"recieve msg3 Successfully at MAC!\n");
//NB_IoT_mac_rrc_data_ind(payload_ptr,mac_inst,rnti);
//NB_IoT_receive_msg3(mac_inst,rnti,PHR,ul_total_buffer);
......
......@@ -121,11 +121,12 @@ void msg4_do_retransmit_NB_IoT(eNB_MAC_INST_NB_IoT *mac_inst, rnti_t c_rnti);
void schedule_RA_NB_IoT(eNB_MAC_INST_NB_IoT *mac_inst);
void init_RA_NB_IoT(eNB_MAC_INST_NB_IoT *mac_inst, uint8_t preamble_index, ce_level_t ce_level, uint32_t sfn_id, uint16_t ta);
void schedule_rar_NB_IoT(eNB_MAC_INST_NB_IoT *mac_inst, int abs_subframe);
void receive_msg3_NB_IoT(eNB_MAC_INST_NB_IoT *mac_inst, rnti_t c_rnti, uint32_t phr, uint32_t ul_total_buffer);
void receive_msg3_NB_IoT(eNB_MAC_INST_NB_IoT *mac_inst, rnti_t c_rnti, uint32_t phr, uint32_t ul_total_buffer, uint8_t* ccch_sdu, uint8_t* msg4_rrc_sdu);
void schedule_msg3_retransimission_NB_IoT(eNB_MAC_INST_NB_IoT *mac_inst, int abs_subframe);
void schedule_msg4_NB_IoT(eNB_MAC_INST_NB_IoT *mac_inst, int abs_subframe);
void fill_rar_NB_IoT(eNB_MAC_INST_NB_IoT *inst, RA_TEMPLATE_NB_IoT *ra_template, uint8_t msg3_schedule_delay, uint8_t msg3_rep, sched_temp_UL_NB_IoT_t *schedule_template);
void receive_msg4_ack_NB_IoT(eNB_MAC_INST_NB_IoT *mac_inst, rnti_t rnti);
void fill_msg4_NB_IoT(eNB_MAC_INST_NB_IoT *inst, RA_TEMPLATE_NB_IoT *ra_template);
//USS
void schedule_uss_NB_IoT(module_id_t module_id, eNB_MAC_INST_NB_IoT *mac_inst, uint32_t subframe, uint32_t frame, uint32_t hypersfn, int index_ss);
......
......@@ -37,9 +37,9 @@
#include "LAYER2/MAC/defs_NB_IoT.h"
/*NOTE: no static function should be declared in this header file (e.g. init_SI_NB)*/
void generate_msg4_NB_IoT(rrc_eNB_carrier_data_NB_IoT_t *carrier);
uint8_t* generate_msg4_NB_IoT(rrc_eNB_carrier_data_NB_IoT_t *carrier);
void mac_rrc_msg3_ind_NB_IoT(uint8_t *payload_ptr, uint16_t rnti, uint32_t length);
uint8_t* mac_rrc_msg3_ind_NB_IoT(uint8_t *payload_ptr, uint16_t rnti, uint32_t length);
uint8_t *get_NB_IoT_MIB(
rrc_eNB_carrier_data_NB_IoT_t *carrier,
......
......@@ -121,9 +121,9 @@ extern uint16_t two_tier_hexagonal_cellIds[7];
mui_t rrc_eNB_mui = 0;
void generate_msg4_NB_IoT(rrc_eNB_carrier_data_NB_IoT_t *carrier)
uint8_t* generate_msg4_NB_IoT(rrc_eNB_carrier_data_NB_IoT_t *carrier)
{
LOG_I(RRC,"start the RRC connection setup PDU\n");
LOG_D(RRC,"start the RRC connection setup PDU\n");
rrc_eNB_ue_context_NB_IoT_t* ue_context_pP_NB_IoT;
......@@ -140,7 +140,7 @@ void generate_msg4_NB_IoT(rrc_eNB_carrier_data_NB_IoT_t *carrier)
SRB_configList_NB_IoT,
&ue_context_pP_NB_IoT->ue_context.physicalConfigDedicated_NB_IoT);
LOG_I(RRC,"[MSG] RRC Connection Setup NB-IoT\n");
LOG_I(RRC,"[MSG] RRC Connection Setup NB-IoT: ");
int cnt;
......@@ -149,13 +149,16 @@ void generate_msg4_NB_IoT(rrc_eNB_carrier_data_NB_IoT_t *carrier)
printf("%02x ", carrier[0].Srb0.Tx_buffer.Payload[cnt]);
}
printf("\n");
return carrier[0].Srb0.Tx_buffer.Payload;
}
void mac_rrc_msg3_ind_NB_IoT(uint8_t *payload_ptr, uint16_t rnti, uint32_t length)
uint8_t* mac_rrc_msg3_ind_NB_IoT(uint8_t *payload_ptr, uint16_t rnti, uint32_t length)
{
LOG_I(RRC,"recieve MSG3 CCCH SDU from MAC\n");
asn_dec_rval_t dec_rval;
struct rrc_eNB_ue_context_NB_IoT_s *ue_context_p = NULL;
uint8_t* msg4_rrc_sdu = NULL;
SRB_INFO_NB_IoT *srb_info = NULL;
srb_info = &eNB_rrc_inst_NB_IoT->carrier[0].Srb0;
memcpy(srb_info->Rx_buffer.Payload,payload_ptr,length);
......@@ -208,10 +211,11 @@ void mac_rrc_msg3_ind_NB_IoT(uint8_t *payload_ptr, uint16_t rnti, uint32_t lengt
{
LOG_E(RRC,"unknown TMSI or Random Value format in RRC connection request NB\n");
}
generate_msg4_NB_IoT(&eNB_rrc_inst_NB_IoT->carrier[0]);
msg4_rrc_sdu = generate_msg4_NB_IoT(&eNB_rrc_inst_NB_IoT->carrier[0]);
}
else
LOG_E(RRC,"unknown MSG3 format for NB-IoT for current test\n");
LOG_E(RRC,"unknown MSG3 format for NB-IoT for current test\n");
return msg4_rrc_sdu;
}
uint8_t *get_NB_IoT_MIB(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment