Example #1
0
        public void Parse(LogicChannel channelData, int offset, ReceivedData result)
        {
            var protokol = (MLEPduType)TetraUtils.BitsToInt32(channelData.Ptr, offset, 3);

            offset += 3;
            result.Add(GlobalNames.MLE_PDU_Type, (int)protokol);

            //Debug.Write(" " + protokol.ToString());

            switch (protokol)
            {
            case MLEPduType.CMCE:
                ParseCMCEPDU(channelData, offset, result);
                break;

            case MLEPduType.MLE:
                ParseMLEPDU(channelData, offset, result);
                break;

            default:
                //Debug.Write(" Unknow_PDU_Type");
                result.Add(GlobalNames.UnknowData, 1);
                break;
            }
        }
Example #2
0
        public void AccessAsignPDU(LogicChannel channelData)
        {
            var offset = 0;

            var length = _aachLength[AccessAssign.Header];
            var header = TetraUtils.BitsToInt32(channelData.Ptr, offset, length);

            offset += length;

            length = _aachLength[AccessAssign.Field1];
            var field1 = TetraUtils.BitsToInt32(channelData.Ptr, offset, length);

            offset += length;

            length = _aachLength[AccessAssign.Field2];
            var field2 = TetraUtils.BitsToInt32(channelData.Ptr, offset, length);

            Field1 = field1;
            Field2 = field2;

            if (channelData.Frame == 18)
            {
                DownLinkChannelType = ChannelType.Common;
                return;
            }

            switch (header)
            {
            case 0:
                DownLinkChannelType = ChannelType.Common;
                break;

            case 1:
            case 2:
            case 3:
                switch (field1)
                {
                case 0:
                    DownLinkChannelType = ChannelType.Unalloc;
                    break;

                case 1:
                    DownLinkChannelType = ChannelType.Assigned;
                    break;

                case 2:
                    DownLinkChannelType = ChannelType.Common;
                    break;

                case 3:
                    DownLinkChannelType = ChannelType.Reserved;
                    break;

                default:
                    DownLinkChannelType = ChannelType.Traffic;
                    break;
                }
                break;
            }
        }
Example #3
0
        public int ParseTLService(LogicChannel channelData, int offset, ReceivedData result)
        {
            var length      = 4;
            var messageType = TetraUtils.BitsToInt32(channelData.Ptr, offset, length);

            offset += length;
            result.Add(GlobalNames.SDS_TL_MesaggeType, messageType);
            switch (messageType)
            {
            case 0:    //Forward
                offset = Global.ParseParams(channelData, offset, _d_Sds_TL_ForwardRules, result);
                break;

            case 1:    //Report
                offset = Global.ParseParams(channelData, offset, _d_Sds_TL_ReportRules, result);
                break;

            case 2:
            case 3:
                //
                break;
            }

            return(offset);
        }
Example #4
0
        public void DmacEndPDU(LogicChannel channelData, int offset, ReceivedData result)
        {
            offset = Global.ParseParams(channelData, offset, _dmacEndRules, result);

            var realLength = channelData.Length - offset;

            if (result.Value(GlobalNames.Fill_bit) != 0)
            {
                realLength = CalcRealLength(channelData.Ptr, offset, realLength);
            }

            Debug.Write(" END_fragmented_PDU");

            AddFraqmentsToBuffer(channelData, offset, realLength);

            var newBuffer = GetDeFragmentedBuffer(channelData, result);

            offset = 0;

            Debug.Write(" Defragmented_PDU_length=" + newBuffer.Length.ToString());

            if (newBuffer.Length == 0)
            {
                return;
            }

            //_llc.Parse(newBuffer, offset, result);
        }
Example #5
0
        public void MacFraqPDU(LogicChannel channelData, int offset, ReceivedData result)
        {
            var startOffset = offset - 3;

            //Debug.Write(" | Frag_PDU");

            if (FraqmentsBufferIsEmpty(channelData.TimeSlot))
            {
                Debug.Write(" Buffer_is_empty!!!");
                return;
            }

            var fill = (TetraUtils.BitsToInt32(channelData.Ptr, offset, 1) != 0);

            offset++;

            var realLength = channelData.Length - offset;

            if (fill)
            {
                realLength = CalcRealLength(channelData.Ptr, offset, realLength);
            }

            if (realLength < 0)
            {
                result.Add(GlobalNames.UnknowData, 1);
                Debug.Write(" frag_length_err");
                return;
            }

            AddFraqmentsToBuffer(channelData, offset, realLength);
        }
Example #6
0
        public void DmacDataPDU(LogicChannel channelData, int offset, ReceivedData result)
        {
            offset = Global.ParseParams(channelData, offset, _dmacDataRules, result);
            var realLength = channelData.Length - offset;

            if (result.Value(GlobalNames.Fill_bit) != 0)
            {
                realLength = CalcRealLength(channelData.Ptr, offset, realLength);
            }

            HalfSlotStolen = result.Value(GlobalNames.Second_half_slot_stolen) == 1;
            //Debug.WriteIf(HalfSlotStolen, " Second_slot_stolen");

            if (result.Value(GlobalNames.Fragmentation_flag) == 1)
            {
                Debug.Write(" Start_fragmented_PDU");
                CreateFraqmentsBuffer(channelData, offset, realLength, result);
                return;
            }

            if (result.Value(GlobalNames.Null_pdu) == 1)
            {
                Debug.Write(" Null_PDU");
                return;
            }

            //Debug.Write(" DMAC-Data_PDU " + (DMAC_Message_Type)result[GlobalNames.Message_type]);

            //Debug.WriteIf(result[GlobalNames.Air_interface_encryption] != 0, " Encr");

            //_llc.Parse(channelData, offset, result);
        }
Example #7
0
        public void ParseSDS(LogicChannel channelData, int offset, ReceivedData result)
        {
            var length = 8;
            var type   = (SdsProtocolIdent)TetraUtils.BitsToInt32(channelData.Ptr, offset, length);

            offset += length;
            result.Add(GlobalNames.Protocol_identifier, (int)type);

            Debug.Write(" " + type.ToString());

            if ((int)type > 127)
            {
                offset = ParseTLService(channelData, offset, result);
            }

            switch (type)
            {
            case SdsProtocolIdent.Simple_immediate_text:
            case SdsProtocolIdent.Simple_text_msg:

                offset = Global.ParseParams(channelData, offset, _sds_SimpleTextRules, result);
                ParseTextMessage(channelData, offset, result);
                break;

            case SdsProtocolIdent.Immediate_text_messaging_TL:
            case SdsProtocolIdent.Text_Messaging_TL:
                offset = Global.ParseParams(channelData, offset, _sds_SimpleTextRules, result);
                ParseTextMessage(channelData, offset, result);
                break;

            case SdsProtocolIdent.Location_System_TL:
            case SdsProtocolIdent.Simple_location_system:
                length = 8;
                var locationCodingSheme = TetraUtils.BitsToInt32(channelData.Ptr, offset, length);
                offset += length;
                result.Add(GlobalNames.Location_System_Coding, locationCodingSheme);
                if (locationCodingSheme == 0)
                {
                    result.Add(GlobalNames.Text_coding_scheme, 1);
                    ParseTextMessage(channelData, offset, result);
                }
                else
                {
                    result.Add(GlobalNames.UnknowData, 1);
                }
                break;

            case SdsProtocolIdent.Location_information_protokol:
                ParseLocationInformationProtokol(channelData, offset, result);
                break;

            default:
                offset = Global.ParseParams(channelData, offset, _sds_SimpleTextRules, result);
                ParseTextMessage(channelData, offset, result);
                result.Add(GlobalNames.UnknowData, 1);
                break;
            }
        }
Example #8
0
        public void UsignalPDU(LogicChannel channelData, int offset, ReceivedData result)
        {
            HalfSlotStolen = (TetraUtils.BitsToInt32(channelData.Ptr, offset, 1) != 0);
            offset++;

            //Debug.Write(" Usig_PDU");

            //Possible pdu encrypted
            //_llc.Parse(channelData, offset, result);
        }
Example #9
0
        public void ResourcePDU(LogicChannel channelData, int offset, ReceivedData result)
        {
            var startOffset = offset - 2;

            offset = Global.ParseParams(channelData, offset, _macResourceRules, result);

            //Debug.Write(" | Resource_PDU");

            var encr             = result.Value(GlobalNames.Encryption_mode);
            var lengthIndication = result.Value(GlobalNames.Length_indication); //Only for pi/4 modulation

            HalfSlotStolen = (lengthIndication == 62) || (lengthIndication == 63);

            Debug.WriteIf(HalfSlotStolen, " Second_slot_stolen");
            Debug.WriteIf(((lengthIndication < 62) && (lengthIndication > 58)), " Incorrect_PDU_length");

            if (((lengthIndication > 58) && (lengthIndication < 62)) || (lengthIndication == 0) || result.Value(GlobalNames.Address_type) == 0)
            {
                result.Add(GlobalNames.Null_pdu, 1);
                //Debug.Write(" Null_PDU");
                return;
            }

            if (encr != 0) // All data before channel allocation flag is clear
            {              // after is encrypted
                Debug.Write(" Encr");
                return;
            }

            offset = Global.ParseParams(channelData, offset, _channelAllocationRules, result);

            if (lengthIndication != 63)
            {
                _llc.Parse(channelData, offset, result);
                return;
            }

            var realLength = Math.Min(lengthIndication * 8 - (offset - startOffset), channelData.Length - offset);

            if (result.Value(GlobalNames.Fill_bit) != 0)
            {
                realLength = CalcRealLength(channelData.Ptr, offset, realLength);
            }

            if (realLength < 0)
            {
                result.Add(GlobalNames.UnknowData, 1);
                Debug.Write(" frag_length_err");
                return;
            }

            //Debug.Write(" Start_fragmented_PDU");
            CreateFraqmentsBuffer(channelData, offset, realLength, result);
        }
Example #10
0
        public void MacEndPDU(LogicChannel channelData, int offset, ReceivedData result)
        {
            var startOffset = offset - 3;

            offset = Global.ParseParams(channelData, offset, _macEndRules, result);

            //Debug.Write(" | FragEnd_PDU");

            if (FraqmentsBufferIsEmpty(channelData.TimeSlot))
            {
                Debug.Write(" Buffer_is_empty");
                return;
            }

            offset = Global.ParseParams(channelData, offset, _channelAllocationRules, result);

            var lengthIndication = result.Value(GlobalNames.Length_indication);
            var realLength       = Math.Min(lengthIndication * 8 - (offset - startOffset), channelData.Length - offset);

            if (lengthIndication > 58)
            {
                Debug.Write(" Incorrect_PDU_length");
                result.Add(GlobalNames.Null_pdu, 1);
                return;
            }

            if (result.Value(GlobalNames.Fill_bit) != 0)
            {
                realLength = CalcRealLength(channelData.Ptr, offset, realLength);
            }

            if (realLength < 0)
            {
                result.Add(GlobalNames.UnknowData, 1);
                Debug.Write(" frag_length_err");
                return;
            }

            AddFraqmentsToBuffer(channelData, offset, realLength);

            var newBuffer = GetDeFragmentedBuffer(channelData, result);

            if (newBuffer.Length == 0)
            {
                Debug.Write(" Defrag_PDU_length_err");
                result.Add(GlobalNames.Null_pdu, 1);
                return;
            }

            //Debug.Write(" Defrag_PDU_length=" + newBuffer.Length.ToString());
            offset = 0;
            _llc.Parse(newBuffer, offset, result);
        }
Example #11
0
        private void ParseMLEPDU(LogicChannel channelData, int offset, ReceivedData result)
        {
            var length = 3;
            var type   = (MlePrimitivesType)TetraUtils.BitsToInt32(channelData.Ptr, offset, length);

            offset += length;
            result.Add(GlobalNames.MLE_Primitives_Type, (int)type);

            //Debug.Write(" " + type.ToString());

            switch (type)
            {
            case MlePrimitivesType.D_NWRK_BROADCAST:
                offset = Global.ParseParams(channelData, offset, _d_Nwrk_BroadcastRules, result);

                var count = 0;

                if (result.TryGetValue(GlobalNames.Number_of_Neighbour_cells_element, ref count))
                {
                    for (int i = 0; i < count; i++)
                    {
                        var neighbourData = new ReceivedData();
                        offset = Global.ParseParams(channelData, offset, _neighbour_Cell_InfoRules, neighbourData);

                        var cellID = 0;
                        if (neighbourData.TryGetValue(GlobalNames.Cell_identifier, ref cellID))
                        {
                            //////Debug.WriteLine("Neighbour " + Thread.CurrentThread.ManagedThreadId.ToString());

                            if (Global.NeighbourList.Count < 32)
                            {
                                Global.NeighbourList.Add(neighbourData);
                            }
                        }
                    }
                }

                break;

            case MlePrimitivesType.D_NEW_CELL:
            case MlePrimitivesType.D_PREPARE:
            case MlePrimitivesType.D_RESTORE_ACK:
            case MlePrimitivesType.D_RESTORE_FAIL:

            default:
                //Debug.Write(" Unknow_MLE_SDU");
                result.Add(GlobalNames.UnknowData, 1);
                break;
            }
        }
Example #12
0
        private void AddFraqmentsToBuffer(LogicChannel buffer, int offset, int length)
        {
            var ts = buffer.TimeSlot - 1;

            if (_writeAddress[ts] == 0)
            {
                return;
            }

            if (_writeAddress[ts] + length < _tempBuffers[ts].Length)
            {
                Radio.Utils.Memcpy(_tempBuffersPtr[ts] + _writeAddress[ts], buffer.Ptr + offset, length * sizeof(byte));
                _writeAddress[ts] += length;
            }
        }
Example #13
0
        public void DmacFraqPDU(LogicChannel channelData, int offset, ReceivedData result)
        {
            var fill = (TetraUtils.BitsToInt32(channelData.Ptr, offset, 1) != 0);

            offset++;

            var realLength = channelData.Length - offset;

            if (fill)
            {
                realLength = CalcRealLength(channelData.Ptr, offset, realLength);
            }

            AddFraqmentsToBuffer(channelData, offset, realLength);

            Debug.Write("Fragment_PDU");
        }
Example #14
0
        public void DmoParseMacPDU(LogicChannel channelData, List <ReceivedData> result)
        {
            var offset = 0;
            var pdu    = new ReceivedData();

            pdu.Add(GlobalNames.CurrTimeSlot, channelData.TimeSlot);

            var pduType = (MAC_PDU_Type)TetraUtils.BitsToInt32(channelData.Ptr, offset, 2);

            offset += 2;
            pdu.Add(GlobalNames.MAC_PDU_Type, (int)pduType);

            switch (pduType)
            {
            case MAC_PDU_Type.MAC_resource:    //DMAC-DATA
                DmacDataPDU(channelData, offset, pdu);
                break;

            case MAC_PDU_Type.MAC_frag:

                var isTheEnd = TetraUtils.BitsToInt32(channelData.Ptr, offset, 1);
                offset++;

                if (isTheEnd == 0)
                {
                    Debug.Write(" DMAC-Frag_PDU");
                    DmacFraqPDU(channelData, offset, pdu);
                }
                else
                {
                    Debug.Write(" DMAC-End_PDU");
                    DmacEndPDU(channelData, offset, pdu);
                }
                break;

            case MAC_PDU_Type.MAC_U_Signal:
                Debug.Write(" U-signal_DMO_PDU");
                //UsignalPDU(channelData, offset, pdu);
                break;

            case MAC_PDU_Type.Broadcast:    //Not used for dmo
                Debug.Write(" Reserved_DMO_PDU");
                break;
            }
            result.Add(pdu);
        }
Example #15
0
        public void SyncPDU(LogicChannel channelData, ReceivedData result)
        {
            var length     = 4;
            var offset     = 0;
            var systemCode = TetraUtils.BitsToInt32(channelData.Ptr, offset, length);

            offset += length;

            result.SetValue(GlobalNames.SystemCode, systemCode);

            switch (systemCode)
            {
            case 12:
            case 13:
                length = 2;
                var pduType = TetraUtils.BitsToInt32(channelData.Ptr, offset, length);
                offset += length;
                result.SetValue(GlobalNames.SYNC_PDU_type, pduType);

                switch (pduType)
                {
                case 0:
                    //Dmac-Sync
                    Debug.Write(" DMAC-Sync");
                    offset = Global.ParseParams(channelData, offset, _dmacSyncInfoRulesDMO, result);
                    break;

                case 1:
                    //DPRES-SYNC
                    Debug.Write(" Dpres-Sync");
                    offset = Global.ParseParams(channelData, offset, _dpresSyncInfoRules, result);
                    break;

                default:
                    //Reserved;
                    Debug.Write(" Unknow_DMO_SyncPdu_type");
                    result.SetValue(GlobalNames.UnknowData, 1);
                    break;
                }
                break;

            default:
                Global.ParseParams(channelData, offset, _syncInfoRulesTMO, result);
                break;
            }
        }
Example #16
0
        private void ParseLocationInformationProtokol(LogicChannel channelData, int offset, ReceivedData result)
        {
            var length  = 2;
            var pduType = TetraUtils.BitsToInt32(channelData.Ptr, offset, length);

            offset += length;
            result.Add(GlobalNames.Location_PDU_type, pduType);

            switch (pduType)
            {
            case 0:    //Short
                Global.ParseParams(channelData, offset, _sds_LocationShortRules, result);
                break;

            case 1:    //Long
                length = 4;
                var pduSubType = (LocationTypeExtension)TetraUtils.BitsToInt32(channelData.Ptr, offset, length);
                offset += length;
                result.Add(GlobalNames.Location_PDU_type_extension, (int)pduSubType);
                switch (pduSubType)
                {
                case LocationTypeExtension.Immediate_location_report:
                    Global.ParseParams(channelData, offset, _sds_ImmediateLocRepRules, result);
                    break;

                case LocationTypeExtension.Long_location_report:
                case LocationTypeExtension.Remove_trigger:
                case LocationTypeExtension.Location_report_acknowledgement:
                case LocationTypeExtension.Add_modify_trigger:
                case LocationTypeExtension.Backlog:
                case LocationTypeExtension.Basic_location_parameters:
                case LocationTypeExtension.Location_reporting_enable_disable:
                case LocationTypeExtension.Location_reporting_temporary_control:
                case LocationTypeExtension.Report_basic_location_parameters:
                case LocationTypeExtension.Report_trigger:
                default:
                    result.Add(GlobalNames.UnknowData, 1);
                    break;
                }
                break;

            default:
                break;
            }
        }
Example #17
0
        private void CreateFraqmentsBuffer(LogicChannel buffer, int offset, int length, ReceivedData header)
        {
            var ts = buffer.TimeSlot - 1;

            Debug.WriteIf(_writeAddress[ts] != 0, " Warning!!! Fraqments buffer is not empty!");
            if (_writeAddress[ts] + length < _tempBuffers[ts].Length)
            {
                Radio.Utils.Memcpy(_tempBuffersPtr[ts], buffer.Ptr + offset, length * sizeof(byte));
                _writeAddress[ts] = length;
                if (header != null)
                {
                    for (int i = 0; i < header.Data.Length; i++)
                    {
                        _fragmentsHeader[ts].Data[i] = header.Data[i];
                    }
                }
            }
        }
Example #18
0
        private bool CalculateFCS(LogicChannel channelData, int offset)
        {
            var lsfr = (UInt32)0xffffffff;
            var bit  = (UInt32)0;

            for (int i = offset; i < channelData.Length; i++)
            {
                bit = channelData.Ptr[i] ^ (lsfr & 0x1);

                lsfr >>= 1;

                if (bit != 0)
                {
                    lsfr ^= Poly;
                }
            }

            Debug.WriteLine(" FCS_" + (lsfr == GoodFCS ? "Ok" : "Err"));

            return(lsfr == GoodFCS);
        }
Example #19
0
        public void SyncPDUHalfSlot(LogicChannel channelData, ReceivedData result)
        {
            var pduType = -1;
            var offset  = 0;

            if (result.TryGetValue(GlobalNames.SYNC_PDU_type, ref pduType))
            {
                switch (pduType)
                {
                case 0:
                    offset = Global.ParseParams(channelData, offset, _dmacSyncInfoHalfSlotRules, result);

                    var realLength = channelData.Length - offset;

                    if (result.Value(GlobalNames.Fill_bit) != 0)
                    {
                        realLength = CalcRealLength(channelData.Ptr, offset, realLength);
                    }


                    if (result.Value(GlobalNames.Fragmentation_flag) == 1)
                    {
                        Debug.Write(" Start_fragmented_PDU");
                        CreateFraqmentsBuffer(channelData, offset, realLength, result);
                    }

                    //Debug.Write(" " + (DMAC_Message_Type)result[GlobalNames.Message_type]);
                    break;

                case 1:
                    Global.ParseParams(channelData, 0, _dpresSyncInfoHalfSlotRules, result);
                    break;

                default:
                    Debug.Write(" Unknow_DMO_SyncPdu_type");
                    result.SetValue(GlobalNames.UnknowData, 1);
                    break;
                }
            }
        }
Example #20
0
        public int SysInfoPDU(LogicChannel channelData, int offset, ReceivedData result)
        {
            var subType = TetraUtils.BitsToByte(channelData.Ptr, offset, 2);

            result.SetValue(GlobalNames.MAC_Broadcast_Type, subType);
            offset += 2;

            switch (subType)
            {
            case 1:
                //Debug.Write(" AcсessDef_PDU");
                offset = Global.ParseParams(channelData, offset, _accessDefineRules, result);
                break;

            case 0:
                //Debug.Write(" Broadcast_PDU");
                offset = Global.ParseParams(channelData, offset, _sysInfoRules, result);
                break;
            }

            return(offset);
        }
Example #21
0
        private LogicChannel GetDeFragmentedBuffer(LogicChannel channelData, ReceivedData header)
        {
            var ts = channelData.TimeSlot - 1;

            Debug.WriteIf(_writeAddress[ts] == 0, " Warning!!! Fraqments  buffer is empty!");

            var result = new LogicChannel
            {
                Ptr      = _tempBuffersPtr[ts],
                Length   = _writeAddress[ts],
                CrcIsOk  = true,
                TimeSlot = channelData.TimeSlot,
                Frame    = channelData.Frame
            };

            var key = GlobalNames.Encryption_mode;

            if (_fragmentsHeader[ts].Contains(key))
            {
                header.Add(key, _fragmentsHeader[ts].Value(key));
            }
            key = GlobalNames.Address_type;
            if (_fragmentsHeader[ts].Contains(key))
            {
                header.Add(key, _fragmentsHeader[ts].Value(key));
            }
            key = GlobalNames.SSI;
            if (_fragmentsHeader[ts].Contains(key))
            {
                header.Add(key, _fragmentsHeader[ts].Value(key));
            }

            _fragmentsHeader[ts].Clear();
            _writeAddress[ts] = 0;

            return(result);
        }
Example #22
0
        private void ParseCMCEPDU(LogicChannel channelData, int offset, ReceivedData result)
        {
            var length = 5;
            var type   = (CmcePrimitivesType)TetraUtils.BitsToInt32(channelData.Ptr, offset, length);

            offset += length;
            result.Add(GlobalNames.CMCE_Primitives_Type, (int)type);

            //Debug.Write(" " + type.ToString());

            switch (type)
            {
            case CmcePrimitivesType.D_Connect:
                Global.ParseParams(channelData, offset, _d_connectRules, result);
                break;

            case CmcePrimitivesType.D_Setup:
                Global.ParseParams(channelData, offset, _d_setupRules, result);
                break;

            case CmcePrimitivesType.D_TX_Granted:
                Global.ParseParams(channelData, offset, _d_TX_GrantedRules, result);
                break;

            case CmcePrimitivesType.D_TX_Ceased:
                Global.ParseParams(channelData, offset, _d_TX_CeasedRules, result);
                break;

            case CmcePrimitivesType.D_Release:
                Global.ParseParams(channelData, offset, _d_ReleaseRules, result);
                break;

            case CmcePrimitivesType.D_Disconnect:

                break;

            case CmcePrimitivesType.D_Connect_Acknowledgea:

                break;

            case CmcePrimitivesType.D_Info:
                Global.ParseParams(channelData, offset, _d_infoRules, result);
                break;

            case CmcePrimitivesType.D_SDS_Data:
                offset = Global.ParseParams(channelData, offset, _d_SdsDataRules, result);

                if (result.Contains(GlobalNames.User_Defined_Data4_Length))
                {
                    var sdsData = new LogicChannel
                    {
                        Ptr    = channelData.Ptr + offset,
                        Length = result.Value(GlobalNames.User_Defined_Data4_Length),
                    };

                    _sds.ParseSDS(sdsData, 0, result);
                }
                break;

            case CmcePrimitivesType.D_Alert:
            case CmcePrimitivesType.D_Call_Proceeding:
            case CmcePrimitivesType.D_Status:
            case CmcePrimitivesType.D_TX_Continue:
            case CmcePrimitivesType.D_TX_Wait:
            case CmcePrimitivesType.D_TX_Interrupt:
            case CmcePrimitivesType.D_Call_Restore:
            case CmcePrimitivesType.D_Facility:
            case CmcePrimitivesType.Reserved17:
            case CmcePrimitivesType.Reserved18:
            case CmcePrimitivesType.Reserved19:
            case CmcePrimitivesType.Reserved20:
            case CmcePrimitivesType.Reserved21:
            case CmcePrimitivesType.Reserved22:
            case CmcePrimitivesType.Reserved23:
            case CmcePrimitivesType.Reserved24:
            case CmcePrimitivesType.Reserved25:
            case CmcePrimitivesType.Reserved26:
            case CmcePrimitivesType.Reserved27:
            case CmcePrimitivesType.Reserved28:
            case CmcePrimitivesType.Reserved29:
            case CmcePrimitivesType.Reserved30:
            case CmcePrimitivesType.CMCE_Function_Not_Supported:

                //Debug.Write(" Unknow_CMCE_SDU");
                result.Add(GlobalNames.UnknowData, 1);

                break;
            }
        }
Example #23
0
        public int Process(Burst burst, float *audioOut)
        {
            var trafficChannel = 0;

            BurstReceived = (burst.Type != BurstType.None);

            _timeCounter++;
            Ber = _averageBer;
            if (_timeCounter > 100)
            {
                Mer = (_badBurstCounter / _timeCounter) * 100.0f;

                _timeCounter     = 0;
                _badBurstCounter = 0;
            }

            _networkTime.AddTimeSlot();

            if (burst.Type == BurstType.None)
            {
                _haveErrors = true;
                if (TetraMode == Mode.TMO)
                {
                    _badBurstCounter++;
                    //Debug.WriteLine("burst err");
                    //Debug.Write(string.Format("ts:{0:0} fr:{1:00} Burst_Err", _networkTime.TimeSlot, _networkTime.Frame));
                }
                return(trafficChannel);
            }

            _haveErrors = false;

            //Debug.WriteLine("");
            //Debug.Write(string.Format("ts:{0:0} fr:{1:00}", _networkTime.TimeSlot, _networkTime.Frame));
            //Debug.Write(" " + burst.Type.ToString());

            _parse.ResetAACH();

            _data.Clear();
            _syncInfo.Clear();

            #region Sync burst

            if (burst.Type == BurstType.SYNC)
            {
                _phyLevel.ExtractSBChannels(burst, _sb1BufferPtr);

                _logicChannel     = _lowerMac.ExtractLogicChannelFromSB(_sb1BufferPtr, _sb1Buffer.Length);
                _badBurstCounter += _logicChannel.CrcIsOk ? 0.0f : 0.5f;
                _haveErrors      |= !_logicChannel.CrcIsOk;
                _averageBer       = _averageBer * 0.5f + _lowerMac.Ber * 0.5f;
                //Debug.Write(" slot 1:" + (_logicChannel.CrcIsOk ? " OK" : " Err"));
                if (_logicChannel.CrcIsOk)
                {
                    _parse.SyncPDU(_logicChannel, _syncInfo);

                    if (_syncInfo.Value(GlobalNames.SystemCode) < 8)
                    {
                        TetraMode = Mode.TMO;
                        _lowerMac.ScramblerCode = TetraUtils.CreateScramblerCode(_syncInfo.Value(GlobalNames.MCC), _syncInfo.Value(GlobalNames.MNC), _syncInfo.Value(GlobalNames.ColorCode));
                        _networkTime.Synchronize(_syncInfo.Value(GlobalNames.TimeSlot), _syncInfo.Value(GlobalNames.Frame), _syncInfo.Value(GlobalNames.MultiFrame));
                    }
                    else
                    {
                        TetraMode = Mode.DMO;

                        if (_syncInfo.Value(GlobalNames.SYNC_PDU_type) == 0)
                        {
                            //Debug.Write(_syncInfo.Value(GlobalNames.Master_slave_link_flag) == 1 ? " Master" : " Slave");

                            if (_syncInfo.Value(GlobalNames.Master_slave_link_flag) == 1 || _syncInfo.Value(GlobalNames.Communication_type) == 0)
                            {
                                _networkTime.SynchronizeMaster(_syncInfo.Value(GlobalNames.TimeSlot), _syncInfo.Value(GlobalNames.Frame));
                            }
                            else
                            {
                                _networkTime.SynchronizeSlave(_syncInfo.Value(GlobalNames.TimeSlot), _syncInfo.Value(GlobalNames.Frame));
                            }
                        }
                    }
                }
                else
                {
                    //Debug.WriteLine("Sync SB crc error");
                }

                _phyLevel.ExtractPhyChannels(TetraMode, burst, _bbBufferPtr, _bkn1BufferPtr, _bkn2BufferPtr);

                if (TetraMode == Mode.TMO)
                {
                    _logicChannel          = _lowerMac.ExtractLogicChannelFromBKN(_bkn2BufferPtr, _bkn2Buffer.Length);
                    _logicChannel.TimeSlot = _networkTime.TimeSlot;
                    _logicChannel.Frame    = _networkTime.Frame;

                    _badBurstCounter += _logicChannel.CrcIsOk ? 0.0f : 0.5f;
                    _haveErrors      |= !_logicChannel.CrcIsOk;
                    _averageBer       = _averageBer * 0.5f + _lowerMac.Ber * 0.5f;
                    //Debug.Write(" slot 2:" + (_logicChannel.CrcIsOk ? " OK" : " Err"));
                    if (_logicChannel.CrcIsOk)
                    {
                        _parse.TmoParseMacPDU(_logicChannel, _data);
                    }
                    else
                    {
                        //Debug.WriteLine("Sync BKN2 crc error");
                    }
                }
                else
                {
                    _logicChannel          = _lowerMac.ExtractLogicChannelFromBKN2(_bkn2BufferPtr, _bkn2Buffer.Length);
                    _logicChannel.TimeSlot = _networkTime.TimeSlot;
                    _logicChannel.Frame    = _networkTime.Frame;

                    _badBurstCounter += _logicChannel.CrcIsOk ? 0.0f : 0.5f;
                    _haveErrors      |= !_logicChannel.CrcIsOk;
                    _averageBer       = _averageBer * 0.5f + _lowerMac.Ber * 0.5f;
                    //Debug.Write(" slot 2:" + (_logicChannel.CrcIsOk ? " OK" : " Err"));
                    if (_logicChannel.CrcIsOk)
                    {
                        _parse.SyncPDUHalfSlot(_logicChannel, _syncInfo);

                        if (_syncInfo.Value(GlobalNames.Communication_type) == 0)
                        {
                            if (_syncInfo.Contains(GlobalNames.MNC) && _syncInfo.Contains(GlobalNames.Source_address))
                            {
                                _lowerMac.ScramblerCode = TetraUtils.CreateScramblerCode(_syncInfo.Value(GlobalNames.MNC), _syncInfo.Value(GlobalNames.Source_address));
                            }
                        }
                        else if (_syncInfo.Value(GlobalNames.Communication_type) == 1)
                        {
                            if (_syncInfo.Contains(GlobalNames.Repeater_address) && _syncInfo.Contains(GlobalNames.Source_address))
                            {
                                _lowerMac.ScramblerCode = TetraUtils.CreateScramblerCode(_syncInfo.Value(GlobalNames.Repeater_address), _syncInfo.Value(GlobalNames.Source_address));
                            }
                        }
                    }
                }

                UpdateSyncInfo(_syncInfo);
            }
            #endregion

            UpdatePublicProp();

            #region Other burst

            if (burst.Type != BurstType.SYNC)
            {
                _phyLevel.ExtractPhyChannels(TetraMode, burst, _bbBufferPtr, _bkn1BufferPtr, _bkn2BufferPtr);

                if (TetraMode == Mode.TMO)
                {
                    _logicChannel          = _lowerMac.ExtractLogicChannelFromBB(_bbBufferPtr, _bbBuffer.Length);
                    _logicChannel.TimeSlot = _networkTime.TimeSlot;
                    _logicChannel.Frame    = _networkTime.Frame;

                    _badBurstCounter += _logicChannel.CrcIsOk ? 0.0f : 0.2f;
                    _haveErrors      |= !_logicChannel.CrcIsOk;
                    //Debug.Write(_logicChannel.CrcIsOk ? " BB OK" : " BB Err");
                    if (_logicChannel.CrcIsOk)
                    {
                        _parse.AccessAsignPDU(_logicChannel);
                    }
                    else
                    {
                        //Debug.WriteLine("BB crc error");
                    }
                }

                switch (burst.Type)
                {
                case BurstType.NDB1:

                    if (((TetraMode == Mode.TMO) && (_parse.DownLinkChannelType == ChannelType.Traffic)) ||
                        ((TetraMode == Mode.DMO) && (!_networkTime.Frame18) && (_networkTime.TimeSlot == 1)) ||
                        ((TetraMode == Mode.DMO) && (!_networkTime.Frame18Slave) && (_networkTime.TimeSlotSlave == 1)))
                    {
                        //Debug.Write(" slot 12:voice");

                        _logicChannel = _lowerMac.ExtractVoiceDataFromBKN1BKN2(_bkn1BufferPtr, _bkn2BufferPtr, _bkn1Buffer.Length);
                        var itsAudio = DecodeAudio(audioOut, _logicChannel.Ptr, _logicChannel.Length, false, _networkTime.TimeSlot);
                        trafficChannel = itsAudio ? _networkTime.TimeSlot : 0;
                        break;
                    }
                    else
                    {
                        _logicChannel          = _lowerMac.ExtractLogicChannelFromBKN1BKN2(_bkn1BufferPtr, _bkn2BufferPtr, _bkn1Buffer.Length);
                        _logicChannel.TimeSlot = _networkTime.TimeSlot;
                        _logicChannel.Frame    = _networkTime.Frame;

                        _badBurstCounter += _logicChannel.CrcIsOk ? 0.0f : 0.8f;
                        _haveErrors      |= !_logicChannel.CrcIsOk;
                        _averageBer       = _averageBer * 0.5f + _lowerMac.Ber * 0.5f;
                        //Debug.Write(" slot 12:" + (_logicChannel.CrcIsOk ? " OK" : " Err"));
                        if (_logicChannel.CrcIsOk)
                        {
                            if (TetraMode == Mode.TMO)
                            {
                                _parse.TmoParseMacPDU(_logicChannel, _data);
                            }
                            else
                            {
                                _parse.DmoParseMacPDU(_logicChannel, _data);
                            }
                        }
                        else
                        {
                            //Debug.WriteLine("BKN1 BKN2 crc error");
                        }
                    }
                    break;

                case BurstType.NDB2:

                    _logicChannel          = _lowerMac.ExtractLogicChannelFromBKN(_bkn1BufferPtr, _bkn1Buffer.Length);
                    _logicChannel.TimeSlot = _networkTime.TimeSlot;
                    _logicChannel.Frame    = _networkTime.Frame;

                    _badBurstCounter += _logicChannel.CrcIsOk ? 0.0f : 0.4f;
                    _haveErrors      |= !_logicChannel.CrcIsOk;
                    _averageBer       = _averageBer * 0.5f + _lowerMac.Ber * 0.5f;
                    //Debug.Write(" slot 1:" + (_logicChannel.CrcIsOk ? " OK" : " Err"));
                    if (_logicChannel.CrcIsOk)
                    {
                        if (TetraMode == Mode.TMO)
                        {
                            _parse.TmoParseMacPDU(_logicChannel, _data);
                        }
                        else
                        {
                            _parse.DmoParseMacPDU(_logicChannel, _data);
                        }
                    }
                    else
                    {
                        //Debug.WriteLine("BKN1 crc error");
                    }

                    if ((_parse.DownLinkChannelType == ChannelType.Traffic && !_parse.HalfSlotStolen) ||
                        ((TetraMode == Mode.DMO) && (!_networkTime.Frame18) && (_networkTime.TimeSlot == 1) && (!_parse.HalfSlotStolen)) ||
                        ((TetraMode == Mode.DMO) && (!_networkTime.Frame18Slave) && (_networkTime.TimeSlotSlave == 1) && (!_parse.HalfSlotStolen)))
                    {
                        //Debug.Write(" slot 2:voice");
                        _logicChannel = _lowerMac.ExtractVoiceDataFromBKN2(_bkn2BufferPtr, _bkn2Buffer.Length);
                        var itsAudio = DecodeAudio(audioOut, _logicChannel.Ptr, _logicChannel.Length, true, _networkTime.TimeSlot);
                        trafficChannel = itsAudio ? _networkTime.TimeSlot : 0;
                        break;
                    }
                    else
                    {
                        _logicChannel          = _lowerMac.ExtractLogicChannelFromBKN(_bkn2BufferPtr, _bkn2Buffer.Length);
                        _logicChannel.TimeSlot = _networkTime.TimeSlot;
                        _logicChannel.Frame    = _networkTime.Frame;

                        _badBurstCounter += _logicChannel.CrcIsOk ? 0.0f : 0.4f;
                        _haveErrors      |= !_logicChannel.CrcIsOk;
                        _averageBer       = _averageBer * 0.5f + _lowerMac.Ber * 0.5f;
                        //Debug.Write(" slot 2:" + (_logicChannel.CrcIsOk ? " OK" : " Err"));
                        if (_logicChannel.CrcIsOk)
                        {
                            if (TetraMode == Mode.TMO)
                            {
                                _parse.TmoParseMacPDU(_logicChannel, _data);
                            }
                            else
                            {
                                _parse.DmoParseMacPDU(_logicChannel, _data);
                            }
                        }
                        else
                        {
                            //Debug.WriteLine("BKN2 crc error");
                        }
                    }
                    break;

                default:
                    break;
                }
            }

            if (_data.Count > 0)
            {
                UpdateData(_data);
            }

            #endregion

            return(trafficChannel);
        }
Example #24
0
        public void Parse(LogicChannel channelData, int offset, ReceivedData result)
        {
            var llcType = (LLCPduType)TetraUtils.BitsToInt32(channelData.Ptr, offset, 4);

            offset += 4;
            result.Add(GlobalNames.LLC_Pdu_Type, (int)llcType);

            //Debug.WriteLine(" " + llcType.ToString());

            var fcsIsGood = true;

            switch (llcType)
            {
            case LLCPduType.BL_ADATA:
                offset += 1;     //N(R)
                offset += 1;     //N(S)
                break;

            case LLCPduType.BL_ADATA_FCS:
                offset   += 1;   //N(R)
                offset   += 1;   //N(S)
                fcsIsGood = CalculateFCS(channelData, offset);
                break;

            case LLCPduType.BL_DATA:
                offset += 1;     //N(S)
                break;

            case LLCPduType.BL_DATA_FCS:
                offset   += 1;   //N(S)
                fcsIsGood = CalculateFCS(channelData, offset);
                break;

            case LLCPduType.BL_UDATA:
                //No bits here
                break;

            case LLCPduType.BL_UDATA_FCS:
                //No bits here
                fcsIsGood = CalculateFCS(channelData, offset);
                break;

            case LLCPduType.BL_ACK:
                offset += 1;    //N(R)
                break;

            case LLCPduType.BL_ACK_FCS:
                offset   += 1;  //N(R)
                fcsIsGood = CalculateFCS(channelData, offset);
                break;

            case LLCPduType.AL_SETUP:
            case LLCPduType.AL_DATA_AR_FINAL:
            case LLCPduType.AL_UDATA_UFINAL:
            case LLCPduType.AL_ACK_RNR:
            case LLCPduType.AL_RECONNECT:
            case LLCPduType.Reserved1:
            case LLCPduType.Reserved2:
            case LLCPduType.AL_DISC:
            default:
                Debug.WriteLine(" Unknow_LLC_PDU " + llcType);
                result.Add(GlobalNames.UnknowData, 1);
                return;
            }

            if (fcsIsGood)
            {
                _mle.Parse(channelData, offset, result);
            }
            else
            {
                result.Add(GlobalNames.UnknowData, 1);
            }
        }
Example #25
0
        public static int ParseParams(LogicChannel channelData, int offset, Rules[] rules, ReceivedData result)
        {
            var skipRules = 0;

            for (int i = 0; i < rules.Length; i++)
            {
                if (offset >= channelData.Length)
                {
                    if (!result.Contains(GlobalNames.OutOfBuffer))
                    {
                        result.SetValue(GlobalNames.OutOfBuffer, 1);
                    }
                    return(offset);
                }

                if (skipRules > 0)
                {
                    skipRules--;
                    continue;
                }

                var param = rules[i];
                var value = TetraUtils.BitsToInt32(channelData.Ptr, offset, param.Length);

                switch (param.Type)
                {
                case RulesType.Direct:
                    if (param.GlobalName != GlobalNames.Reserved)
                    {
                        result.SetValue(param.GlobalName, value);
                    }
                    offset += param.Length;
                    continue;

                case RulesType.Options_bit:
                    offset += param.Length;
                    if (value == 0)
                    {
                        return(offset);
                    }
                    break;

                case RulesType.Presence_bit:
                    if (value == 0)
                    {
                        skipRules = param.Ext1;
                    }
                    offset += param.Length;
                    break;

                case RulesType.More_bit:
                    offset += param.Length;
                    return(offset);

                case RulesType.Switch:
                    if (result.Value((GlobalNames)rules[i].Ext1) == rules[i].Ext2)
                    {
                        if (param.GlobalName != GlobalNames.Reserved)
                        {
                            result.SetValue(param.GlobalName, value);
                        }
                        offset += param.Length;
                    }
                    break;

                case RulesType.SwitchNot:
                    if (result.Value((GlobalNames)rules[i].Ext1) != rules[i].Ext2)
                    {
                        if (param.GlobalName != GlobalNames.Reserved)
                        {
                            result.SetValue(param.GlobalName, value);
                        }
                        offset += param.Length;
                    }
                    break;

                case RulesType.Jamp:
                    if (result.Value((GlobalNames)rules[i].Ext1) == rules[i].Ext2)
                    {
                        skipRules = param.Ext3;
                    }
                    break;

                case RulesType.JampNot:
                    if (result.Value((GlobalNames)rules[i].Ext1) != rules[i].Ext2)
                    {
                        skipRules = param.Ext3;
                    }
                    break;

                case RulesType.Reserved:
                {
                    offset += param.Length;
                }
                break;
                }
            }

            return(offset);
        }
Example #26
0
 private unsafe void ParseLongSDS(LogicChannel channelData, int offset, ReceivedData result)
 {
     throw new NotImplementedException();
 }
Example #27
0
        private unsafe void ParseTextMessage(LogicChannel channelData, int offset, ReceivedData result)
        {
            if (result.Contains(GlobalNames.OutOfBuffer))
            {
                return;
            }

            var codingSheme = result.Value(GlobalNames.Text_coding_scheme);

            Encoding encTable   = Encoding.GetEncoding("iso-8859-1");
            int      symbLength = 8;

            switch (codingSheme)
            {
            case 1:
                encTable = Encoding.GetEncoding("iso-8859-1");
                break;

            case 2:
                encTable = Encoding.GetEncoding("iso-8859-2");
                break;

            case 3:
                encTable = Encoding.GetEncoding("iso-8859-3");
                break;

            case 4:
                encTable = Encoding.GetEncoding("iso-8859-4");
                break;

            case 5:
                encTable = Encoding.GetEncoding("iso-8859-5");
                break;

            case 6:
                encTable = Encoding.GetEncoding("iso-8859-6");
                break;

            case 7:
                encTable = Encoding.GetEncoding("iso-8859-7");
                break;

            case 8:
                encTable = Encoding.GetEncoding("iso-8859-8");
                break;

            case 9:
                encTable = Encoding.GetEncoding("iso-8859-9");
                break;

            case 10:
                encTable = Encoding.GetEncoding("iso-8859-10");
                break;

            case 11:
                encTable = Encoding.GetEncoding("iso-8859-13");
                break;

            case 12:
                encTable = Encoding.GetEncoding("iso-8859-14");
                break;

            case 13:
                encTable = Encoding.GetEncoding("iso-8859-15");
                break;

            case 14:
                encTable = Encoding.GetEncoding(437);
                break;

            case 15:
                encTable = Encoding.GetEncoding(737);
                break;

            case 16:
                encTable = Encoding.GetEncoding(850);
                break;

            case 17:
                encTable = Encoding.GetEncoding(852);
                break;

            case 18:
                encTable = Encoding.GetEncoding(855);
                break;

            case 19:
                encTable = Encoding.GetEncoding(857);
                break;

            case 20:
                encTable = Encoding.GetEncoding(860);
                break;

            case 21:
                encTable = Encoding.GetEncoding(861);
                break;

            case 22:
                encTable = Encoding.GetEncoding(863);
                break;

            case 23:
                encTable = Encoding.GetEncoding(865);
                break;

            case 24:
                encTable = Encoding.GetEncoding(866);
                break;

            case 25:
                encTable = Encoding.GetEncoding(869);
                break;

            default:
                break;
                result.Add(GlobalNames.UnknowData, 1);
                return;
            }

            Decoder dec           = encTable.GetDecoder();
            var     messageLength = (channelData.Length - offset) / symbLength;

            if (messageLength < 0)
            {
                return;
            }

            string message;

            byte[] symbolsArray = new byte[messageLength];
            int    index        = 0;

            while (messageLength > 0)
            {
                symbolsArray[index++] = TetraUtils.BitsToByte(channelData.Ptr, offset, symbLength);
                offset += symbLength;
                messageLength--;
            }

            message = encTable.GetString(symbolsArray);

            Debug.WriteLine(" data:" + message);
        }
Example #28
0
        public void TmoParseMacPDU(LogicChannel channelData, List <ReceivedData> result)
        {
            var nullPduLength = 16; // only for receive pi/4 modulation ;
            var blockOffset   = 0;
            var nullPdu       = false;
            var pduEnd        = false;

            for (int i = 0; i < 5; i++)
            {
                var offset = blockOffset;
                var pdu    = new ReceivedData();

                pdu.Add(GlobalNames.CurrTimeSlot, channelData.TimeSlot);

                var resourceType = (MAC_PDU_Type)TetraUtils.BitsToInt32(channelData.Ptr, offset, 2);
                offset += 2;
                pdu.Add(GlobalNames.MAC_PDU_Type, (int)resourceType);

                switch (resourceType)
                {
                case MAC_PDU_Type.Broadcast:
                    blockOffset = SysInfoPDU(channelData, offset, pdu);
                    break;

                case MAC_PDU_Type.MAC_resource:
                    ResourcePDU(channelData, offset, pdu);
                    blockOffset += (pdu.Value(GlobalNames.Length_indication) * 8);
                    break;

                case MAC_PDU_Type.MAC_U_Signal:
                    if (channelData.Length == 124)
                    {
                        UsignalPDU(channelData, offset, pdu);
                        pduEnd = true;
                    }
                    else
                    {
                        Debug.Write(" MAC-D-BLCK_PDU");
                        pduEnd = true;
                    }
                    break;

                case MAC_PDU_Type.MAC_frag:

                    var isTheEnd = TetraUtils.BitsToInt32(channelData.Ptr, offset, 1);
                    offset++;

                    if (isTheEnd == 0)
                    {
                        MacFraqPDU(channelData, offset, pdu);
                        pduEnd = true;
                    }
                    else
                    {
                        MacEndPDU(channelData, offset, pdu);
                        blockOffset += (pdu.Value(GlobalNames.Length_indication) * 8);
                    }
                    break;
                }

                nullPdu = pdu.Contains(GlobalNames.Null_pdu) || pdu.Contains(GlobalNames.OutOfBuffer);

                if (nullPdu)
                {
                    pduEnd = true;
                }

                //if (pdu.ContainsKey(GlobalNames.UnknowData)) nullPdu = true;

                if (!nullPdu)
                {
                    result.Add(pdu);
                }

                if ((blockOffset >= (channelData.Length - nullPduLength)) || pduEnd)
                {
                    break;
                }
            }
        }