示例#1
0
        /// <summary>
        /// Generates an MIH Message based on a Link_Configure_Thresholds_Confirm_Confirm object.
        /// </summary>
        /// <param name="srcID">The source MIH ID.</param>
        /// <param name="dstID">The destination MIH ID</param>
        /// <param name="tid">The transaction ID, use the same as the request message.</param>
        /// <param name="lctconfirm">The Link_Configure_Thresholds_Confirm object to be the content of the message.</param>
        /// <returns>The MIH message to be sent to the MIHF.</returns>
        public static Message Configure_Thresholds_Response_Builder(ID srcID, ID dstID, ushort tid, Link_Configure_Thresholds_Confirm lctconfirm)
        {
            Message m = new Message();
            m.MIHHeader = new MIHHeader();
            MessageID mID = new MessageID(MessageID.ServiceIdentifier.COMMAND_SERVICE, MessageID.OperationCode.CONFIRM, (ushort)AIDCommandService.MIH_LINK_CONFIGURE_THRESHOLDS);
            m.MIHHeader.MID = mID;
            m.MIHHeader.TransactionID = tid;
            m.MIHHeader.VersionValue = 1;

            byte[] st = new byte[1];
            st[0] = BitConverter.GetBytes((int)lctconfirm.Status)[0];

            m.Payload = new Payload(srcID, dstID,
                Serialization.SerializeToTLV(TLV_VALUES.TLV_STATUS, st),
                Serialization.SerializeToTLV(TLV_VALUES.TLV_CONFIGURE_RESPONSE_LIST, Serialization.EncodingList(lctconfirm.cfgStatusAsByteArrayList().ToArray())));

            m.MIHHeader.PayloadLength = (ushort)m.Payload.PayloadValue.Length;
            return m;
        }
示例#2
0
        /// <summary>
        /// This constructor allows the build of a MIHHeader object based on a byte array which contains a MIHMessage.
        /// </summary>
        /// <param name="mihHeader"></param>
        public MIHHeader(byte[] mihHeader)
        {
            // TODO melhorar a obtenção dos campos, ver implementação do construtor do Message ID.

            //OCTET1 -> Version (4bits), AckResp (1bit), AckRsp (1bit), UIR (1bit), M (1bit)

            byte[] aux = new byte[1];
            aux[0] = mihHeader[0];
            BitArray OCTET1 = new BitArray(aux);
            //Utilities.Utilities.ReverseBitArray(OCTET1);
            if (OCTET1.Count != 0)
            {
                BitArray version = new BitArray(8);
                for (int i = 0; i < 4; i++)
                {
                    version.Set(7-i, OCTET1.Get(4+i));
                }
                VersionValue = (byte)GetIntFromBitArray(version);
                AckReq = OCTET1.Get(3);
                AckResp = OCTET1.Get(2);
                UIR = OCTET1.Get(1);
                M = OCTET1.Get(0);

                //LOGHERE
                //if (Program.RECEIVED_LOG)
                //{
                //    Console.WriteLine("Version: " + VersionValue);
                //    Console.WriteLine("AckReq: " + AckReq);
                //    Console.WriteLine("AckResp: " + AckResp);
                //    Console.WriteLine("UIR: " + UIR);
                //    Console.WriteLine("M: " + M);
                //}
            }

            //OCTECT2 -> FN (7 bits), Reserved 1 (1bit, Filled with 0 by default)

            aux[0] = mihHeader[1];
            BitArray OCTET2 = new BitArray(aux);
            Utilities.Utilities.ReverseBitArray(OCTET2);

            if (OCTET2.Count != 0)
            {

                BitArray fragmentNumber = new BitArray(7);

                for (int i = 0; i < 7; i++)
                {
                    fragmentNumber[i] = OCTET2[i];
                }
                FN = (byte)GetUshortFromBitArray(fragmentNumber);
            }
            else
            {
                FN = 0;
            }

            //LOGHERE
            //if (Program.RECEIVED_LOG)
            //    Console.WriteLine("Fragment no.: " + FN);

            //OCTET3 AND OCTECT4 -> MIH Message ID

            MID = new MessageID(mihHeader.Skip(2).Take(2).ToArray());

            //OCTECT5 and OCTECT6 -> Reserved2 (4 bits, filled with 0's by default), Transaction ID (12 bits).

            BitArray OCTECT5and6 = new BitArray(mihHeader.Skip(4).Take(2).ToArray());
            Utilities.Utilities.ReverseBitArray(OCTECT5and6);
            if (OCTECT5and6.Count != 0)
            {

                BitArray transactionID = new BitArray(12);

                for (int i = 0, j = 4; i < 12; i++, j++)
                {
                    transactionID[i] = OCTECT5and6[j];
                }

                Utilities.Utilities.ReverseBitArray(transactionID);
                TransactionID = Convert.ToUInt16(GetIntFromBitArray(transactionID));
            }
            else
            {
                TransactionID = 0;
            }

            //LOGHERE
            //if (Program.RECEIVED_LOG)
            //    Console.WriteLine("Transaction ID: " + TransactionID);

            //OCTECT7 and OCTECT8 -> Variable Payload Length

            BitArray payloadLength = new BitArray(mihHeader.Skip(6).Take(2).ToArray());
            Utilities.Utilities.ReverseBitArray(payloadLength);

            PayloadLength = Convert.ToUInt16(GetIntFromBitArray(payloadLength));

            //LOGHERE
            //if (Program.RECEIVED_LOG)
            //    Console.WriteLine("Payload Length: "+PayloadLength);
        }
示例#3
0
 /// <summary>
 /// MIH Header Main Constructor.
 /// </summary>
 /// <param name="version">MIH Protocol Version</param>
 /// <param name="ackReq">Acknowledgement Request</param>
 /// <param name="ackResp">Acknowledgement Response</param>
 /// <param name="uir">Unauthenticated Information Request</param>
 /// <param name="m">More Fragment</param>
 /// <param name="fn">Fragment Number</param>
 /// <param name="mid">Message ID</param>
 /// <param name="rsvd2">Reserved 2</param>
 /// <param name="payloadLength">Payload Length</param>
 /// <param name="transactionId">Transaction ID</param>
 public MIHHeader(byte version, bool ackReq, bool ackResp, bool uir, bool m, byte fn, MessageID mid, byte rsvd2, UInt16 payloadLength, UInt16 transactionId )
 {
     VersionValue = version;
     AckReq = ackReq;
     AckResp = ackResp;
     UIR = uir;
     M = m;
     FN = fn;
     MID = mid;
     RSVD2 = rsvd2;
     PayloadLength = payloadLength;
     TransactionID = transactionId;
 }
示例#4
0
        /// <summary>
        /// Generates an MIH Message based on a Link_Event_Subscribe_Confirm object.
        /// </summary>
        /// <param name="srcID">The source MIH ID.</param>
        /// <param name="dstID">The destination MIH ID</param>
        /// <param name="tid">The transaction ID, use the same as the request message.</param>
        /// <param name="leconfirm">The Link_Event_Subscribe_Confirm object to be the content of the message.</param>
        /// <returns>The MIH message to be sent to the MIHF.</returns>
        public static Message Event_Subscribe_Response_Builder(ID srcID, ID dstID, ushort tid, Link_Event_Subscribe_Confirm leconfirm)
        {
            Message m = new Message();
            m.MIHHeader = new MIHHeader();
            MessageID mID = new MessageID(MessageID.ServiceIdentifier.SERVICE_MANAGEMENT, MessageID.OperationCode.CONFIRM, (ushort)AIDServiceManagement.MIH_EVENT_SUBSCRIBE);
            m.MIHHeader.MID = mID;
            m.MIHHeader.TransactionID = tid;
            m.MIHHeader.VersionValue = 1;

            byte[] status = new byte[1];
            status[0]= BitConverter.GetBytes((int)leconfirm.Status)[0];

            m.Payload = new Payload(srcID, dstID,
                Serialization.SerializeToTLV(TLV_VALUES.TLV_STATUS, status),
                Serialization.SerializeToTLV(TLV_VALUES.TLV_LINK_EVENT_LIST, leconfirm.LinkEventList.ByteValue));
            m.MIHHeader.PayloadLength = (ushort)m.Payload.PayloadValue.Length;
            return m;
        }
示例#5
0
 /// <summary>
 /// Generates an MIH Message based on a Link_Action_Response object.
 /// </summary>
 /// <param name="srcID">The source MIH ID.</param>
 /// <param name="dstID">The destination MIH ID</param>
 /// <param name="tid">The transaction ID, use the same as the request message.</param>
 /// <param name="laresp">The Link_Action_Response object to be the content of the message.</param>
 /// <returns>The MIH message to be sent to the MIHF.</returns>
 public static Message Link_Action_Response_Builder(ID srcID, ID dstID, ushort tid, Link_Action_Response laresp)
 {
     Message m = new Message();
     m.MIHHeader = new MIHHeader();
     MessageID mID = new MessageID(MessageID.ServiceIdentifier.COMMAND_SERVICE, MessageID.OperationCode.CONFIRM, (ushort)AIDCommandService.MIH_LINK_ACTIONS);
     m.MIHHeader.MID = mID;
     m.MIHHeader.TransactionID = tid;
     m.MIHHeader.VersionValue = 1;
     if (laresp.ScanResults.Count > 0)
         m.Payload = new Payload(dstID,
                             srcID,
                             Serialization.SerializeToTLV(TLV_VALUES.TLV_STATUS, BitConverter.GetBytes((int)laresp.Status).Take(1).ToArray()),
                             Serialization.SerializeToTLV(TLV_VALUES.TLV_LINK_SCAN_RSP_LIST, Serialization.EncodingList(laresp.scanResultsAsByteArrayList().ToArray())),
                             Serialization.SerializeToTLV(TLV_VALUES.TLV_LINK_AC_RESULT, BitConverter.GetBytes((int)laresp.Result).Take(1).ToArray()));
     else
         m.Payload = new Payload(dstID,
                             srcID,
                             Serialization.SerializeToTLV(TLV_VALUES.TLV_STATUS, BitConverter.GetBytes((int)laresp.Status).Take(1).ToArray()),
                             Serialization.SerializeToTLV(TLV_VALUES.TLV_LINK_AC_RESULT, BitConverter.GetBytes((int)laresp.Result).Take(1).ToArray()));
     m.MIHHeader.PayloadLength = (ushort)m.Payload.PayloadValue.Length;
     return m;
 }
示例#6
0
        /// <summary>
        /// Generates an MIH Message based on a Link_Get_Parameters_Confirm object.
        /// </summary>
        /// <param name="srcID">The source MIH ID.</param>
        /// <param name="dstID">The destination MIH ID</param>
        /// <param name="tid">The transaction ID, use the same as the request message.</param>
        /// <param name="lgpconfirm">The Link_Event_SubscribeConfirm object to be the content of the message.</param>
        /// <returns>The MIH message to be sent to the MIHF.</returns>
        public static Message Get_Parameters_Response_Builder(ID srcID, ID dstID, ushort tid, Link_Get_Parameters_Confirm lgpconfirm)
        {
            Message m = new Message();
            m.MIHHeader = new MIHHeader();
            MessageID mID = new MessageID(MessageID.ServiceIdentifier.COMMAND_SERVICE, MessageID.OperationCode.CONFIRM, (ushort)AIDCommandService.MIH_LINK_GET_PARAMETERS);
            m.MIHHeader.MID = mID;
            m.MIHHeader.TransactionID = tid;
            m.MIHHeader.VersionValue = 1;

            byte[] st = new byte[1];
            st[0] = BitConverter.GetBytes((int)lgpconfirm.Status)[0];

            m.Payload = new Payload(srcID, dstID,
                Serialization.SerializeToTLV(TLV_VALUES.TLV_STATUS, st),
                Serialization.SerializeToTLV(TLV_VALUES.TLV_LINK_PARAMETERS_STATUS_LIST, Serialization.EncodingList(lgpconfirm.LinkParamListAsByteArray())),
                Serialization.SerializeToTLV(TLV_VALUES.TLV_LINK_STATES_RSP, Serialization.EncodingList(lgpconfirm.LinkStatesListAsByteArray())),
                Serialization.SerializeToTLV(TLV_VALUES.TLV_LINK_DESCRIPTOR_RSP, Serialization.EncodingList(lgpconfirm.LinkDescListAsByteArray())));

            m.MIHHeader.PayloadLength = (ushort)m.Payload.PayloadValue.Length;
            return m;
        }