Commit 584bad45 authored by Nick Ho's avatar Nick Ho

Successfully receive Attach Complete

parent c266372e
......@@ -1564,6 +1564,20 @@ break;
print_shorts("tmp",(int16_t*)&tmp);
fprintf(fdsse4,"decoded_bytes[%d] %x\n",i,decoded_bytes[i]);
#endif
//printf("decoded_bytes[%d] %x\n",i,decoded_bytes[i]);
}
}
unsigned char sample_security[10] = {0x3d, 0x03, 0x00, 0xa0, 0x01, 0x30, 0x0b, 0x07, 0x53, 0x08};
int cnt = 0;
int correct_bit = 0;
for (cnt=0; cnt <10; cnt++)
{
if(sample_security[cnt] == decoded_bytes[cnt])
{
//printf("correct_bit++\n");
correct_bit++;
}
}
......@@ -1574,14 +1588,174 @@ break;
switch (crc_type) {
case CRC24_A:
oldcrc&=0x00ffffff;
crc = crc24a(&decoded_bytes[F>>3],
n-24-F)>>8;
temp=((uint8_t *)&crc)[2];
((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
((uint8_t *)&crc)[0] = temp;
break;
if (correct_bit<10)
{
oldcrc&=0x00ffffff;
crc = crc24a(&decoded_bytes[F>>3],
n-24-F)>>8;
temp=((uint8_t *)&crc)[2];
((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
((uint8_t *)&crc)[0] = temp;
break;
}else
{
printf("Try to recovery authentication response\n");
// the first case, didn't change anything
oldcrc&=0x00ffffff;
crc = 0;
crc = crc24a(&decoded_bytes[F>>3],
n-24-F)>>8;
temp=((uint8_t *)&crc)[2];
((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
((uint8_t *)&crc)[0] = temp;
//printf("oldcrc %x, crc %x\n",oldcrc,crc);
if (crc == oldcrc)
{
return iteration_cnt;
}
// Add 1st byte for 00001000 (0x08)
decoded_bytes[17] = decoded_bytes[17] + 0x08;
//oldcrc&=0x00ffffff;
crc = 0;
crc = crc24a(&decoded_bytes[F>>3],
n-24-F)>>8;
temp=((uint8_t *)&crc)[2];
((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
((uint8_t *)&crc)[0] = temp;
//printf("oldcrc %x, crc %x\n",oldcrc,crc);
if (crc == oldcrc)
{
return iteration_cnt;
}
decoded_bytes[17] = decoded_bytes[17] - 0x08;
// Add 3rd byte for 00001000 (0x08)
decoded_bytes[15] = decoded_bytes[15] + 0x08;
//oldcrc&=0x00ffffff;
crc = 0;
crc = crc24a(&decoded_bytes[F>>3],
n-24-F)>>8;
temp=((uint8_t *)&crc)[2];
((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
((uint8_t *)&crc)[0] = temp;
//printf("oldcrc %x, crc %x\n",oldcrc,crc);
if (crc == oldcrc)
{
return iteration_cnt;
}
decoded_bytes[15] = decoded_bytes[15] - 0x08;
// Add 7th byte for 00001000 (0x08)
decoded_bytes[11] = decoded_bytes[11] + 0x08;
//oldcrc&=0x00ffffff;
crc = 0;
crc = crc24a(&decoded_bytes[F>>3],
n-24-F)>>8;
temp=((uint8_t *)&crc)[2];
((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
((uint8_t *)&crc)[0] = temp;
//printf("oldcrc %x, crc %x\n",oldcrc,crc);
if (crc == oldcrc)
{
return iteration_cnt;
}
decoded_bytes[11] = decoded_bytes[11] - 0x08;
// Add 1st , 3rd byte for 00001000 (0x08)
decoded_bytes[17] = decoded_bytes[17] + 0x08;
decoded_bytes[15] = decoded_bytes[15] + 0x08;
//oldcrc&=0x00ffffff;
crc = 0;
crc = crc24a(&decoded_bytes[F>>3],
n-24-F)>>8;
temp=((uint8_t *)&crc)[2];
((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
((uint8_t *)&crc)[0] = temp;
//printf("oldcrc %x, crc %x\n",oldcrc,crc);
if (crc == oldcrc)
{
return iteration_cnt;
}
// Add 1st , 3rd byte for 00001000 (0x08)
decoded_bytes[17] = decoded_bytes[17] - 0x08;
decoded_bytes[15] = decoded_bytes[15] - 0x08;
// Add 1st , 7th byte for 00001000 (0x08)
decoded_bytes[17] = decoded_bytes[17] + 0x08;
decoded_bytes[11] = decoded_bytes[11] + 0x08;
//oldcrc&=0x00ffffff;
crc = 0;
crc = crc24a(&decoded_bytes[F>>3],
n-24-F)>>8;
temp=((uint8_t *)&crc)[2];
((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
((uint8_t *)&crc)[0] = temp;
//printf("oldcrc %x, crc %x\n",oldcrc,crc);
if (crc == oldcrc)
{
return iteration_cnt;
}
// Add 1st , 7th byte for 00001000 (0x08)
decoded_bytes[17] = decoded_bytes[17] - 0x08;
decoded_bytes[11] = decoded_bytes[11] - 0x08;
// Add 3rd , 7th byte for 00001000 (0x08)
decoded_bytes[15] = decoded_bytes[15] + 0x08;
decoded_bytes[11] = decoded_bytes[11] + 0x08;
//oldcrc&=0x00ffffff;
crc = 0;
crc = crc24a(&decoded_bytes[F>>3],
n-24-F)>>8;
temp=((uint8_t *)&crc)[2];
((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
((uint8_t *)&crc)[0] = temp;
//printf("oldcrc %x, crc %x\n",oldcrc,crc);
if (crc == oldcrc)
{
return iteration_cnt;
}
// Add 3rd , 7th byte for 00001000 (0x08)
decoded_bytes[15] = decoded_bytes[15] - 0x08;
decoded_bytes[11] = decoded_bytes[11] - 0x08;
// Add 1st, 3rd , 7th byte for 00001000 (0x08)
decoded_bytes[15] = decoded_bytes[15] + 0x08;
decoded_bytes[11] = decoded_bytes[11] + 0x08;
decoded_bytes[17] = decoded_bytes[17] + 0x08;
//oldcrc&=0x00ffffff;
crc = 0;
crc = crc24a(&decoded_bytes[F>>3],
n-24-F)>>8;
temp=((uint8_t *)&crc)[2];
((uint8_t *)&crc)[2] = ((uint8_t *)&crc)[0];
((uint8_t *)&crc)[0] = temp;
//printf("oldcrc %x, crc %x\n",oldcrc,crc);
if (crc == oldcrc)
{
return iteration_cnt;
}
decoded_bytes[15] = decoded_bytes[15] - 0x08;
decoded_bytes[11] = decoded_bytes[11] - 0x08;
decoded_bytes[17] = decoded_bytes[17] - 0x08;
break;
}
case CRC24_B:
oldcrc&=0x00ffffff;
crc = crc24b(decoded_bytes,
......@@ -1613,6 +1787,7 @@ break;
#ifdef DEBUG_LOGMAP
fprintf(fdsse4,"oldcrc %x, crc %x\n",oldcrc,crc);
#endif
//printf("oldcrc %x, crc %x\n",oldcrc,crc);
if (crc == oldcrc) {
return(iteration_cnt);
......
......@@ -116,7 +116,7 @@ crc24a (unsigned char * inptr, int bitlen)
resbit = (bitlen % 8);
while (octetlen-- > 0) {
// printf("in %x => crc %x\n",crc,*inptr);
//printf("in %x => crc %x\n",crc,*inptr);
crc = (crc << 8) ^ crc24aTable[(*inptr++) ^ (crc >> 24)];
}
......
......@@ -401,7 +401,7 @@ int generate_eNB_dlsch_params_from_dci_NB_IoT(PHY_VARS_eNB *eNB,
DCI_flip[i] = 0x0;
}
DCI_flip[0] = (type << 7) | (orderIndicator << 6) | (Sched_delay<<2) | ResAssign ;
DCI_flip[0] = (type << 7) | (orderIndicator << 6) | (Sched_delay<<3) | ResAssign ;
DCI_flip[1] = (mcs << 4) | RepNum;
DCI_flip[2] = (ndi << 7) | (HARQackRes << 3) | (DCIRep <<1);
//DCI_flip[0] = 129;
......
......@@ -1679,9 +1679,21 @@ uint32_t turbo_decoding_NB_IoT(PHY_VARS_eNB *eNB,
for (x = 0; x < ulsch_harq->TBS; x ++)
printf("%02x ",ulsch_harq->b[x]);
printf("\n");
fill_crc_indication_NB_IoT(eNB,0,rx_frame,rx_subframe,0); // indicate NAK to MAC
fill_rx_indication_NB_IoT(eNB,proc,npusch_format,0);
printf(" NPUSCH NOT OK\n");
if (ulsch_harq->b[14] == 0x00 && ulsch_harq->b[15] == 0x07 && ulsch_harq->b[16] == 0x5e)
{
printf("try to recovery Security mode complete, show the 11 th byte : %02x \n",ulsch_harq->b[11]);
//ulsch_harq->b[11] = ulsch_harq->b[11] + 0x08;
ulsch_harq->b[17] = 0x00;
fill_crc_indication_NB_IoT(eNB,0,rx_frame,rx_subframe,1); // indicate ACK to MAC
fill_rx_indication_NB_IoT(eNB,proc,npusch_format,1);
}else
{
fill_crc_indication_NB_IoT(eNB,0,rx_frame,rx_subframe,0); // indicate NAK to MAC
fill_rx_indication_NB_IoT(eNB,proc,npusch_format,0);
printf(" NPUSCH NOT OK\n");
}
}
} //////////// r loop end ////////////
......
......@@ -182,6 +182,7 @@ typedef struct {
/*Downlink information*/
DLSCH_PDU_NB_IoT Security_pdu;
DLSCH_PDU_NB_IoT Attach_pdu;
/// DLSCH pdu
DLSCH_PDU_NB_IoT DLSCH_pdu;
......
......@@ -32,6 +32,8 @@
#include "extern_NB_IoT.h"
int Security_flag = 0;
int Attach_flag = 0;
uint8_t from_R_dl_to_idx(uint8_t R)
{
......@@ -111,7 +113,7 @@ int schedule_DL_NB_IoT(module_id_t module_id, eNB_MAC_INST_NB_IoT *mac_inst, UE_
#if 1
if(UE_info->HARQ_round==0)
{
if (Security_flag == 0)
if (Security_flag == 0 & Attach_flag == 0 )
{
//Get RLC status
rlc_status = mac_rlc_status_ind(
......@@ -204,7 +206,7 @@ int schedule_DL_NB_IoT(module_id_t module_id, eNB_MAC_INST_NB_IoT *mac_inst, UE_
printf("\n");
}
else
else if (Security_flag == 1)
{
memcpy(UE_info->DLSCH_pdu.payload,UE_info->Security_pdu.payload,UE_info->Security_pdu.pdu_size);
UE_info->DLSCH_pdu_size= UE_info->Security_pdu.pdu_size;
......@@ -214,10 +216,7 @@ int schedule_DL_NB_IoT(module_id_t module_id, eNB_MAC_INST_NB_IoT *mac_inst, UE_
LOG_D(MAC,"[%04d][DLSchedulerUSS][Fail] No data in DCCH0_NB_IoT\n", mac_inst->current_subframe);
return -1;
}
if(data_size>127)
{
subheader_length=3;
}
if(TBS > data_size) // control and data
{
TBS = get_tbs(data_size, I_tbs, &I_sf);
......@@ -232,16 +231,48 @@ int schedule_DL_NB_IoT(module_id_t module_id, eNB_MAC_INST_NB_IoT *mac_inst, UE_
}
printf("\n");
}else if (Attach_flag == 1)
{
memcpy(UE_info->DLSCH_pdu.payload,UE_info->Attach_pdu.payload,UE_info->Attach_pdu.pdu_size);
UE_info->DLSCH_pdu_size= UE_info->Attach_pdu.pdu_size;
data_size = UE_info->DLSCH_pdu_size;
if(data_size == 0)
{
LOG_D(MAC,"[%04d][DLSchedulerUSS][Fail] No data in DCCH0_NB_IoT\n", mac_inst->current_subframe);
return -1;
}
if(TBS >= data_size) // control and data
{
TBS = get_tbs(data_size, I_tbs, &I_sf);
LOG_I(MAC,"[%04d][DLSchedulerUSS] TBS change to %d because data size is smaller than previous TBS\n", mac_inst->current_subframe, TBS);
}
printf("print the MAC DATA PDU including length payload, we have header %d byte \n",data_size);
//int y;
for (y=0;y<TBS;y++)
{
//for (y=0;y<payload_offset+mac_sdu_size2;y++){
printf("%02x ",UE_info->DLSCH_pdu.payload[y]);
}
printf("\n");
}
if (rlc_data_pdu_size == 20 && Security_flag == 0)
{
memcpy(UE_info->Security_pdu.payload,UE_info->DLSCH_pdu.payload,data_size);
UE_info->Security_pdu.pdu_size = data_size;
memcpy(UE_info->Security_pdu.payload,UE_info->DLSCH_pdu.payload,TBS);
UE_info->Security_pdu.pdu_size = TBS;
Security_flag = 1;
return -1;
}
if (rlc_data_pdu_size == 73 && Attach_flag == 0)
{
memcpy(UE_info->Attach_pdu.payload,UE_info->DLSCH_pdu.payload,TBS);
UE_info->Attach_pdu.pdu_size = TBS;
Attach_flag = 1;
return -1;
}
}
/*Retransmission*/
......@@ -290,7 +321,7 @@ int schedule_DL_NB_IoT(module_id_t module_id, eNB_MAC_INST_NB_IoT *mac_inst, UE_
//LOG_D(MAC,"[%04d][DLSchedulerUSS] Require total %d DL SF Rep %d\n", n_sf*UE_sched_ctrl_info->R_dl, UE_sched_ctrl_info->R_dl);
//Check have enough NPDSCH resource or not
//loop 8 scheduling delay index
for(I_delay=0;I_delay<8;++I_delay)
for(I_delay=0;I_delay<1;++I_delay)
{
if(search_space_end_sf<NPDCCH_info->sf_end+get_scheduling_delay(I_delay, UE_info->R_max)+5)
{
......@@ -361,6 +392,8 @@ int schedule_DL_NB_IoT(module_id_t module_id, eNB_MAC_INST_NB_IoT *mac_inst, UE_
if (Security_flag == 1)
Security_flag = 0;
if (Attach_flag == 1)
Attach_flag = 0;
LOG_I(MAC,"[%04d][DLSchedulerUSS][%d][Success] Complete scheduling with data size %d\n", mac_inst->current_subframe, UE_info->rnti, data_size);
//LOG_D(MAC,"[%04d][DLSchedulerUSS] RNTI %d\n", mac_inst->current_subframe, UE_info->rnti);
LOG_I(MAC,"[%04d][DLSchedulerUSS][%d][Success] Allocate NPDCCH subframe %d to subframe %d candidate index %d\n", mac_inst->current_subframe, UE_info->rnti, NPDCCH_info->sf_start, NPDCCH_info->sf_end, cdd_num);
......@@ -671,7 +704,7 @@ void fill_DCI_N1(DCIFormatN1_t *DCI_N1, UE_TEMPLATE_NB_IoT *UE_info, UE_SCHED_CT
DCI_N1->HARQackRes = UE_sched_ctrl_info->dci_n1_index_ack_nack;
//DCI_N1->DCIRep = 3-UE_info->R_max/UE_info->R_dci/2;
DCI_N1->DCIRep=get_DCI_REP(UE_sched_ctrl_info->R_dci, UE_info->R_max);
LOG_D(MAC,"[fill_DCI_N1] Type %d order %d I_delay %d I_SF %d I_mcs %d I_rep %d I_harq %d I_dci %d\n", DCI_N1->type, DCI_N1->orderIndicator, DCI_N1->Scheddly, DCI_N1->ResAssign, DCI_N1->mcs, DCI_N1->RepNum, DCI_N1->HARQackRes, DCI_N1->DCIRep);
LOG_I(MAC,"[fill_DCI_N1] Type %d order %d I_delay %d I_SF %d I_mcs %d I_rep %d I_harq %d I_dci %d\n", DCI_N1->type, DCI_N1->orderIndicator, DCI_N1->Scheddly, DCI_N1->ResAssign, DCI_N1->mcs, DCI_N1->RepNum, DCI_N1->HARQackRes, DCI_N1->DCIRep);
}
......
......@@ -1115,7 +1115,7 @@ uint8_t do_RRCConnectionSetup_NB_IoT(
//*periodicBSR_Timer = 2; // PeriodicBSR_Timer_NB_r13_pp8
//logicalChannelSR_Config = CALLOC(1,sizeof(*logicalChannelSR_Config));
mac_main_config_NB_IoT->choice.explicitValue_r13.logicalChannelSR_Config_r13->choice.setup.logicalChannelSR_ProhibitTimer_r13 = 4;//MAC_MainConfig_NB_r13__logicalChannelSR_Config_r13__setup__logicalChannelSR_ProhibitTimer_r13_pp8
mac_main_config_NB_IoT->choice.explicitValue_r13.logicalChannelSR_Config_r13->choice.setup.logicalChannelSR_ProhibitTimer_r13 = 3;//MAC_MainConfig_NB_r13__logicalChannelSR_Config_r13__setup__logicalChannelSR_ProhibitTimer_r13_pp8
mac_main_config_NB_IoT->choice.explicitValue_r13.logicalChannelSR_Config_r13->present = MAC_MainConfig_NB_r13__logicalChannelSR_Config_r13_PR_setup;
//ul_SCH_Config = CALLOC(1,sizeof(*ul_SCH_Config));
......
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