Python

 

 

 

 

Python - LTE - Decoding DCI

 

NOTE 1 : All the examples in this page are written in Python 3.x. It may not work if you use Pyton 2.x

NOTE 2 : All the examples in this page are assumed to be written/run on Windows 7 unless specifically mentioned. You MAY (or may not) need to modify the syntax a little bit if you are running on other operating system.

 

This code is not a perfect DCI decoder which can decode all the DCI formats by blind coding. This is just unpacking the hex string into each DCI field based on dci structure that you defined. It means you have to provide the correct dci structure yourself.

The structed presented in DCI page is a kind of generic structure of each DCI format. The number of bits for each item in a DCI may be different depending on various factors (e.g, Bandwidth or TDD vs FDD or Resource Allocation Type or the number of Antenna). So even for the same DCI format, you may have to define multiple different structures.

I will keep adding this page with more specific DCI structure later.

 

# DciDecoder.py ================================================================

 

import binascii

   

# Beginning of Main Routine

 

# The first Record (Row)

#       the first field = Total Bit Length of the DCI,

#       the second field = Data Type to be printed.

#       the third field =  the description of the field

# All the other records (Rows)

#       the first field = Bit Length of the specified field,

#       the second field = Data Type to be printed.

#                   If it is "BIN", the field is printed in Binary.

#                   If it is "DEC", the field is printed in Binary and Decimal.

#       the third field =  the description of the field

 

dci0_10M_FDD_NoHop_Rel8 = [

                [25,"DEC","DCI 0 (Rel 8)"],

                [1,"BIN","Format0-A-Flag"],

                [1,"BIN","Frequency Hopping"],

                [11,"DEC","RIV"],

                [5,"DEC","MCS"],

                [1,"BIN","NDI"],

                [2,"DEC","TPC"],

                [3,"DEC","Cyclic Shift"],

                [1,"BIN","CQI Request"]

               ]

 

dci0_10M_FDD_Hop_Rel8 = [

                [25,"DEC","DCI 0 (Rel 8)"],

                [1,"BIN","Format0-A-Flag"],

                [1,"BIN","Frequency Hopping"],

                [2,"DEC","NUL-hop"],

                [9,"DEC","RIV"],

                [5,"DEC","MCS"],

                [1,"BIN","NDI"],

                [2,"DEC","TPC"],

                [3,"DEC","Cyclic Shift"],

                [1,"BIN","CQI Request"]

               ]

 

dci2_20M_FDD_4x4_RA0 = [

                [54,"DEC","DCI 2"],

                [1,"BIN","Resource allocation header"],

                [25,"BIN","Resource block assignment for RA Type 0"],

                [2,"BIN","TPC for PUCCH"],

                [3,"DEC","HARQ Process"],

                [1,"BIN","Transport block to codeword swap flag"],

                [5,"DEC","MCS for Transport Block 1"],

                [1,"BIN","NDI for Transport Block 1"],

                [2,"DEC","RV for Transport Block 1"],

                [5,"DEC","MCS for Transport Block 2"],

                [1,"BIN","NDI for Transport Block 2"],

                [2,"DEC","RV for Transport Block 2"],

                [6,"DEC","Precoding Information"]

               ]

 

 

#dciStructure = dci0_10M_FDD_NoHop_Rel8

dciStructure = dci0_10M_FDD_Hop_Rel8

#dciStructure = dci2_20M_FDD_4x4_RA0

 

#dciStr='2584A800'         #Test for dci0_10M_FDD_NoHop_Rel8

dciStr='48720800'         #Test for dci0_10M_FDD_Hop_Rel8

#dciStr='7FFFFFD0808088'  #dci2_20M_FDD_4x4_RA0

#dciStr='7FFFFFD2808088'  #dci2_20M_FDD_4x4_RA0

#dciStr='7FFFFFC2848400'   #dci2_20M_FDD_4x4_RA0

 

 

LengthInBytes = int(len(dciStr)/2)

dciNumbers = binascii.a2b_hex(dciStr)

PayloadByteArray = bytearray(dciNumbers)

PayloadBytes = PayloadByteArray[0:LengthInBytes]

PayloadInt = int.from_bytes(PayloadBytes, 'big')

PayloadBin = '{0:0{1}b}'.format(PayloadInt,LengthInBytes*8)

    

 

startBit = 0

for i in range(len(dciStructure)):

    [length,pType,description] = dciStructure[i]

    if(i == 0) :

        print("====================================================================================");

        print(description," : Payload Length = ",length);

        print("====================================================================================");

        print(dciStr,"(HEX)")

        print(PayloadBin)

        print("------------------------------------------------------------------------------------");

    else :

        fieldBits = PayloadBin[startBit : startBit + length]

        if(pType == "BIN") :

           print(fieldBits,"(BIN):",description)

        else :

           print(fieldBits,"(BIN) = ",int(fieldBits,2),"(DEC) :",description)

        startBit = startBit + length

        #print('{0:0{1}b}'.format(int(fieldBits,2),startBit),":",pType,":",description)

        #startBit = startBit + length

print("------------------------------------------------------------------------------------");       

print("Total Decoded Bits = ",startBit)

print("====================================================================================");

 

 

Result :----------------------------------------------------------------------------

 

====================================================================================

DCI 0 (Rel 8)  : Payload Length =  25

====================================================================================

2584A800 (HEX)

00100101100001001010100000000000

------------------------------------------------------------------------------------

0 (BIN): Format0-A-Flag

0 (BIN): Frequency Hopping

10010110000 (BIN) =  1200 (DEC) : RIV

10010 (BIN) =  18 (DEC) : MCS

1 (BIN): NDI

01 (BIN) =  1 (DEC) : TPC

000 (BIN) =  0 (DEC) : Cyclic Shift

0 (BIN): CQI Request

------------------------------------------------------------------------------------

Total Decoded Bits =  25

====================================================================================

 

 

====================================================================================

DCI 0 (Rel 8)  : Payload Length =  25

====================================================================================

48720800 (HEX)

01001000011100100000100000000000

------------------------------------------------------------------------------------

0 (BIN): Format0-A-Flag

1 (BIN): Frequency Hopping

00 (BIN) =  0 (DEC) : NUL-hop

100001110 (BIN) =  270 (DEC) : RIV

01000 (BIN) =  8 (DEC) : MCS

0 (BIN): NDI

01 (BIN) =  1 (DEC) : TPC

000 (BIN) =  0 (DEC) : Cyclic Shift

0 (BIN): CQI Request

------------------------------------------------------------------------------------

Total Decoded Bits =  25

====================================================================================

 

 

====================================================================================

DCI 2  : Payload Length =  54

====================================================================================

7FFFFFC2848400 (HEX)

01111111111111111111111111000010100001001000010000000000

------------------------------------------------------------------------------------

0 (BIN): Resource allocation header

1111111111111111111111111 (BIN): Resource block assignment for RA Type 0

00 (BIN): TPC for PUCCH

001 (BIN) =  1 (DEC) : HARQ Process

0 (BIN): Transport block to codeword swap flag

10000 (BIN) =  16 (DEC) : MCS for Transport Block 1

1 (BIN): NDI for Transport Block 1

00 (BIN) =  0 (DEC) : RV for Transport Block 1

10000 (BIN) =  16 (DEC) : MCS for Transport Block 2

1 (BIN): NDI for Transport Block 2

00 (BIN) =  0 (DEC) : RV for Transport Block 2

000000 (BIN) =  0 (DEC) : Precoding Information

------------------------------------------------------------------------------------

Total Decoded Bits =  54

====================================================================================

 

 

====================================================================================

DCI 2  : Payload Length =  54

====================================================================================

7FFFFFD0808088 (HEX)

01111111111111111111111111010000100000001000000010001000

------------------------------------------------------------------------------------

0 (BIN): Resource allocation header

1111111111111111111111111 (BIN): Resource block assignment for RA Type 0

01 (BIN): TPC for PUCCH

000 (BIN) =  0 (DEC) : HARQ Process

0 (BIN): Transport block to codeword swap flag

10000 (BIN) =  16 (DEC) : MCS for Transport Block 1

0 (BIN): NDI for Transport Block 1

00 (BIN) =  0 (DEC) : RV for Transport Block 1

10000 (BIN) =  16 (DEC) : MCS for Transport Block 2

0 (BIN): NDI for Transport Block 2

00 (BIN) =  0 (DEC) : RV for Transport Block 2

100010 (BIN) =  34 (DEC) : Precoding Information

------------------------------------------------------------------------------------

Total Decoded Bits =  54

====================================================================================

 

 

====================================================================================

DCI 2  : Payload Length =  54

====================================================================================

7FFFFFD2808088 (HEX)

01111111111111111111111111010010100000001000000010001000

------------------------------------------------------------------------------------

0 (BIN): Resource allocation header

1111111111111111111111111 (BIN): Resource block assignment for RA Type 0

01 (BIN): TPC for PUCCH

001 (BIN) =  1 (DEC) : HARQ Process

0 (BIN): Transport block to codeword swap flag

10000 (BIN) =  16 (DEC) : MCS for Transport Block 1

0 (BIN): NDI for Transport Block 1

00 (BIN) =  0 (DEC) : RV for Transport Block 1

10000 (BIN) =  16 (DEC) : MCS for Transport Block 2

0 (BIN): NDI for Transport Block 2

00 (BIN) =  0 (DEC) : RV for Transport Block 2

100010 (BIN) =  34 (DEC) : Precoding Information

------------------------------------------------------------------------------------

Total Decoded Bits =  54

====================================================================================