Example #1
0
        /// <summary>
        /// Creates a Link_Detected.Indication message
        /// </summary>
        /// <param name="srcID">The local node ID</param>
        /// <param name="dstID">The destination MIHF ID</param>
        /// <param name="BSSID">The link's BSSID (the MAC of the access point).</param>
        /// <param name="SSID">The link's SSID.</param>
        /// <param name="linkQuality">The link quality for the specified link.</param>
        /// <param name="rssi">The RSSI (Received Signal Strength Indication) for this link.</param>
        /// <param name="maxRate">The max transfer rate on this connection.</param>
        /// <returns>A fully encoded, ready to be sent Message representing a LinkDetected indication</returns>
        public static Message Link_Detected_Indication_MsgBuilder(ID srcID, ID dstID, byte[] BSSID, byte[] SSID, uint linkQuality, int rssi, int maxRate)
        {
            Message m = new Message();
            m.MIHHeader = new MIHHeader();
            m.MIHHeader.MID = new MessageID(MessageID.ServiceIdentifier.EVENT_SERVICE, MessageID.OperationCode.INDICATION, 1);
            m.MIHHeader.VersionValue = 1;

            //byte[] hessid = new byte[entry.dot11Bssid.Length + 1];
            string hessid = Utilities.PhysicalAddressToString(new PhysicalAddress(BSSID));
            //hessid[0] = BitConverter.GetBytes(entry.dot11Bssid.Length)[0];
            //for (int i = 0; i < entry.dot11Bssid.Length; i++)
            //    hessid[1 + i] = entry.dot11Bssid[i];

            Link_Det_Info linkDetInfo = new Link_Det_Info(
                                        new Link_Tuple_Id(
                                            new Link_Id(Link_Type.Wireless_IEEE80211, new Link_Addr(Link_Addr.Address_Type.OTHER_L2_ADDR,
                                                    new string(Encoding.ASCII.GetChars(SSID)))),
                                            new Link_Addr(Link_Addr.Address_Type.MAC_ADDR,
                                                    Utilities.PhysicalAddressToString(new PhysicalAddress(BSSID)))),
                                        new OctetString(new String(Encoding.ASCII.GetChars(SSID))),
                                        new OctetString(hessid),
                                        linkQuality,
                                        rssi,
                                        0,
                                        (int)((double)(maxRate) * 8) / 1024,
                                        new Link_MIHCap_Flag(true, true, true),
                                        new Net_Caps(false, false, false, false, false, false, false, true, false, true));

            m.Payload = new Payload(srcID, dstID, Serialization.SerializeToTLV(TLV_VALUES.TLV_LINK_DET_INFO, linkDetInfo.ByteVal));
            m.MIHHeader.PayloadLength = (ushort)m.Payload.PayloadValue.Length;
            return m;
        }
Example #2
0
 /// <summary>
 /// This method is called to handle a message containing a Link_Capability_Discover, returning to the MIHF the appropriate response.
 /// </summary>
 /// <param name="m">The received Link_Capability_Discover message object</param>
 public static void HandleCapabilityDiscover(Message m)
 {
     Payload.TLVIterator it = m.Payload.GetTLVIterator();
     ID srcID = new ID(new OctetString(it.Next().Value));
     ID dstID = new ID(new OctetString(it.Next().Value));
     Program.toMihf.Send(ResponseBuilders.Link_Capability_Discover_Response_Builder(dstID,srcID, STATUS.SUCCESS,
         Capabilities.CapabilitiesHandler.SupportedEventList,
         Capabilities.CapabilitiesHandler.SupportedCommandsList).ByteValue);
 }
Example #3
0
        /// <summary>
        /// This method is called to handle a message containing a Link_Action_Request, and sets it to be called on a timer according to the delay parameter
        /// </summary>
        /// <param name="m">The Link_Action_Request message object</param>
        public static void HandleCommandLinkActions(Message m)
        {
            Payload.TLVIterator it = m.Payload.GetTLVIterator();
            it.Next();//srcID
            it.Next();//dstID
            it.Next();//eventlist
            int delay = MIHDeserializer.DeserializeTimeInterval(it.Next());

            Timer t = new Timer(LinkActionCallback, m, delay, Timeout.Infinite);
        }
Example #4
0
        /// <summary>
        /// This method is called to handle a Threshold configuration request message
        /// </summary>
        /// <param name="m">The serialized Config_Thresholds message</param>
        public static void HandleConfigThresholds(Message m)
        {
            ConnectionHelper ch = Program.toMihf;
            ushort transactionID = m.MIHHeader.TransactionID;
            Payload.TLVIterator it = m.Payload.GetTLVIterator();
            ID srcID = new ID(new OctetString(it.Next().Value));
            ID dstID = new ID(new OctetString(it.Next().Value));
            List<Link_Cfg_Param> lcparams = MIHDeserializer.DeserializeLinkCfgParamList(it.Next());
            List<Link_Cfg_Status> lcstatus = new List<Link_Cfg_Status>();
            foreach (Link_Cfg_Param param in lcparams)
            {
                if (param.Timer_Interval > 0 && param.Th_Action != TH_Action.CANCEL_THRESHOLD)
                {
                    Reports.TimedReports.Add(new TimedReport(param.Link_Param_Type.AbsoluteType, param.Timer_Interval));
                }
                switch (param.Th_Action)
                {
                    case TH_Action.ONE_SHOT_THRESHOLD:
                        foreach (Threshold t in param.ThresholdList)
                        {
                            try
                            {
                                Reports.OneShotThresholds.Add(new ActiveThreshold(t, param.Link_Param_Type.AbsoluteType));
                                lcstatus.Add(new Link_Cfg_Status(param.Link_Param_Type, t, true));
                            }
                            catch (Exception e)
                            { lcstatus.Add(new Link_Cfg_Status(param.Link_Param_Type, t, false)); }
                        }
                        break;
                    case TH_Action.NORMAL_THRESHOLD:
                        foreach (Threshold t in param.ThresholdList)
                        {
                            try
                            {
                                Reports.ActiveThresholds.Add(new ActiveThreshold(t, param.Link_Param_Type.AbsoluteType));
                                lcstatus.Add(new Link_Cfg_Status(param.Link_Param_Type, t, true));
                            }
                            catch (Exception e)
                            { lcstatus.Add(new Link_Cfg_Status(param.Link_Param_Type, t, false)); }
                        }
                        break;
                    case TH_Action.CANCEL_THRESHOLD:
                        Reports.Cancel(param); //TODO MORE
                        break;
                }
            }

            ch.Send(ResponseBuilders.Configure_Thresholds_Response_Builder(dstID, srcID, m.MIHHeader.TransactionID,
                new Link_Configure_Thresholds_Confirm(STATUS.SUCCESS,lcstatus)).ByteValue);
        }
Example #5
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;
        }
Example #6
0
 /// <summary>
 /// This method is called to handle an unsubscribe request message
 /// </summary>
 /// <param name="m">The serialized unsubscribe request message</param>
 public static void HandleUnsubscribe(Message m)
 {
     ConnectionHelper ch = Program.toMihf;
     ushort transactionID = m.MIHHeader.TransactionID;
     Payload.TLVIterator it = m.Payload.GetTLVIterator();
     ID srcID = new ID(new OctetString(it.Next().Value));
     ID dstID = new ID(new OctetString(it.Next().Value));
     Link_Event_Unsubscribe_Request leur = new Link_Event_Unsubscribe_Request(MIHDeserializer.DeserializeLinkEventList(it.Next()));
     Subscriptions.Unsubscribe(leur.EventList);
     Link_Event_Unsubscribe_Confirm leuc = new Link_Event_Unsubscribe_Confirm(STATUS.SUCCESS, leur.EventList);
     ch.Send(ResponseBuilders.Event_Unsubscribe_Response_Builder(dstID, srcID, m.MIHHeader.TransactionID, leuc).ByteValue);
 }
Example #7
0
 /// <summary>
 /// This method processes a message and calls the appropriate method to act on it.
 /// </summary>
 /// <param name="m">The received message.</param>
 public static void HandleMessage(Message m)
 {
     switch (m.MIHHeader.MID.AID)
     {
         case AIDGlobal.SERVICE_MANAGEMENT_MIH_CAPABILITY_DISCOVER:
             HandleCapabilityDiscover(m);
             break;
         case AIDGlobal.COMMAND_SERVICE_MIH_LINK_ACTIONS:
             HandleCommandLinkActions(m);
             break;
         case AIDGlobal.SERVICE_MANAGEMENT_MIH_EVENT_SUBSCRIBE:
             HandleSubscribe(m);
             break;
         case AIDGlobal.SERVICE_MANAGEMENT_MIH_EVENT_UNSUBSCRIBE:
             HandleUnsubscribe(m);
             break;
         case AIDGlobal.COMMAND_SERVICE_MIH_LINK_CONFIGURE_THRESHOLDS:
             HandleConfigThresholds(m);
             break;
         case AIDGlobal.COMMAND_SERVICE_MIH_LINK_GET_PARAMETERS:
             HandleGetParameters(m);
             break;
     }
 }
Example #8
0
        /// <summary>
        /// This method is called to handle a Get_Parameters request
        /// </summary>
        /// <param name="m">The serialized Get_Parameters_Request message.</param>
        public static void HandleGetParameters(Message m)
        {
            ConnectionHelper ch = Program.toMihf;
            ushort transactionID = m.MIHHeader.TransactionID;
            Payload.TLVIterator it = m.Payload.GetTLVIterator();
            ID srcID = new ID(new OctetString(it.Next().Value));
            ID dstID = new ID(new OctetString(it.Next().Value));
            Link_Get_Parameters_Request lgpr = new Link_Get_Parameters_Request(MIHDeserializer.DeserializeLinkParamRequest(it.Next()),
                new System.Collections.BitArray(it.Next().Value.Reverse().ToArray()),
                new System.Collections.BitArray(it.Next().Value.Reverse().ToArray()));

            Link_Get_Parameters_Confirm lgpc = new Link_Get_Parameters_Confirm();
            try
            {
                lgpc.LinkParametersStatusList = new List<Link_Param>(lgpr.LinkParametersRequest.Count);
                lgpc.LinkStatesRspList = new List<Link_Get_Parameters_Confirm.Link_States_Rsp>();
                lgpc.LinkDescRspList = new List<Link_Get_Parameters_Confirm.Link_Desc_Rsp>();
                foreach (Link_Param_Type lpt in lgpr.LinkParametersRequest)
                {
                    switch (lpt.AbsoluteType)
                    {
                        case Link_Param_Abs_Type.P80211_RSSI: lgpc.LinkParametersStatusList.Add(new Link_Param(lpt, Link_Param_802_11.GetRSSI_0)); break;
                        case Link_Param_Abs_Type.GEN_Data_Rate: lgpc.LinkParametersStatusList.Add(new Link_Param(lpt, Link_Param_Gen.DataRate_0)); break;
                        case Link_Param_Abs_Type.GEN_Sig_Strenth: lgpc.LinkParametersStatusList.Add(new Link_Param(lpt, Link_Param_Gen.SignalStrength_1)); break;
                        case Link_Param_Abs_Type.GEN_Packet_Error_Rate: lgpc.LinkParametersStatusList.Add(new Link_Param(lpt, Link_Param_Gen.PacketErrorRate_4)); break;
                    }
                }

                //-------LinkStates
                if (lgpr.LinkStatesRequest[0]) //OP_MODE
                    lgpc.LinkStatesRspList.Add(new Link_Get_Parameters_Confirm.Link_States_Rsp(Link_Get_Parameters_Confirm.Link_States_Rsp.Type.OP_MODE, (ushort)GenericInfo.WlanInterfaceInstance.OP_Mode_802_21));

                if (lgpr.LinkStatesRequest[1])
                    lgpc.LinkStatesRspList.Add(new Link_Get_Parameters_Confirm.Link_States_Rsp(Link_Get_Parameters_Confirm.Link_States_Rsp.Type.CHANNEL_ID, (ushort)GenericInfo.WlanInterfaceInstance.Channel));
                //-----------

                //-------LinkDesc
                if (lgpr.LinkDescriptorsRequest[0])
                    lgpc.LinkDescRspList.Add(new Link_Get_Parameters_Confirm.Link_Desc_Rsp(Link_Get_Parameters_Confirm.Link_Desc_Rsp.Type.NUM_CoS, 0)); //TODO (not supported)

                if (lgpr.LinkDescriptorsRequest[1])
                    lgpc.LinkDescRspList.Add(new Link_Get_Parameters_Confirm.Link_Desc_Rsp(Link_Get_Parameters_Confirm.Link_Desc_Rsp.Type.NUM_QUEUE, 1)); //TODO (not supported)
                //-----------

                lgpc.Status = STATUS.SUCCESS;
            }
            catch (Exception e) { lgpc.Status = STATUS.UNSPECIFIED_FAILURE;}

            Message toSend = ResponseBuilders.Get_Parameters_Response_Builder(dstID, srcID, m.MIHHeader.TransactionID, lgpc);

            if (Program.MESSAGE_DETAILS)
            {
                Console.WriteLine("Sending message: ("+m.MIHHeader.MID.AID+")");
                Connection.MIHProtocol.PacketReader.PrintMessage(toSend);
            }

            ch.Send(toSend.ByteValue);
        }
Example #9
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;
        }
Example #10
0
        /// <summary>
        /// Generates an 802.21-encoded message representing a LinkDown Event.
        /// </summary>
        /// <param name="srcID">The local node ID</param>
        /// <param name="dstID">The destination MIHF ID</param>
        /// <param name="imsi">The IMSI (International Mobile Subscriber Identity) for this network</param>
        /// <param name="PoAMac">The Physical Address for the Point of Access</param>
        /// <param name="reason">The reason for the disconnect</param>
        /// <returns>A fully encoded, ready to be sent Message representing a LinkDown</returns>
        public static Message Link_Down_Indication_3G_MsgBuilder(ID srcID, ID dstID, String imsi, PhysicalAddress PoAMac, Link_Dn_Reason reason)
        {
            Message m = new Message();
            m.MIHHeader = new MIHHeader();
            m.MIHHeader.MID = new MessageID(MessageID.ServiceIdentifier.EVENT_SERVICE, MessageID.OperationCode.INDICATION, 3);
            m.MIHHeader.VersionValue = 1;
            Link_Tuple_Id linkIdentifier = new Link_Tuple_Id(
                        new Link_Id(Link_Type.Wireless_UMTS, new Link_Addr(Link_Addr.Address_Type._3GPP_ADDR, imsi)),
                        new Link_Addr(Link_Addr.Address_Type.MAC_ADDR, Utilities.PhysicalAddressToString(PoAMac)));
            Link_Dn_Reason downReason = reason;

            m.Payload = new Payload(srcID, dstID,
                TLV_HELPERS.TLVLinkIdentifier(linkIdentifier), TLV_HELPERS.TLVLinkDnReason(downReason));
            m.MIHHeader.PayloadLength = (ushort)m.Payload.PayloadValue.Length;
            return m;
        }
Example #11
0
        public static Message Link_Capability_Discover_Response_Builder(ID srcID, ID dstID, STATUS st, Link_Event_List lel, Link_CMD_List lcl)
        {
            Message m = new Message();
            m.MIHHeader = new MIHHeader();
            m.MIHHeader.MID = new MessageID(MessageID.ServiceIdentifier.SERVICE_MANAGEMENT, MessageID.OperationCode.CONFIRM, 1);
            m.MIHHeader.VersionValue = 1;

            //Link_Capability_Discover_Confirm lcdc = new Link_Capability_Discover_Confirm(STATUS.SUCCESS, lcl, lel);
            m.Payload = new Payload(srcID, dstID,
                Serialization.Sequence(
                Serialization.SerializeToTLV(TLV_VALUES.TLV_STATUS, BitConverter.GetBytes((int)st).Take(1).ToArray()),
                Serialization.SerializeToTLV(TLV_VALUES.TLV_LINK_EVENT_LIST, lel.ByteValue),
                Serialization.SerializeToTLV(TLV_VALUES.TLV_LINK_COMMAND_LIST, lcl.ByteValue)));
            m.MIHHeader.PayloadLength = (ushort)m.Payload.PayloadValue.Length;
            return m;
        }
Example #12
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;
 }
Example #13
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;
        }
Example #14
0
 /// <summary>
 /// Prints a serialized message.
 /// </summary>
 /// <param name="m">The serialized message to print.</param>
 public static void PrintMessage(Message m)
 {
     Payload.TLVIterator it =  m.Payload.GetTLVIterator();
     Console.Write("\t(");
     Console.Write(new ID(new OctetString(it.Next().Value)));
     Console.Write(" -> "+ new ID(new OctetString(it.Next().Value)));
     Console.Write(")");
     Console.WriteLine();
     switch (m.MIHHeader.MID.AID)
     {
         case AIDGlobal.COMMAND_SERVICE_MIH_LINK_ACTIONS:
             if (m.MIHHeader.MID.OpCode == MessageID.OperationCode.REQUEST)
             {
                 //LINK ACTION REQUEST
                 Console.WriteLine(new Link_Action_Request(MIHDeserializer.DeserializeLinkAction(it.Next()),
                                             MIHDeserializer.DeserializeTimeInterval(it.Next()),
                                             MIHDeserializer.DeserializePoA(it.Next())).ToString());
             }
             else
             {
                 //LINK ACTION RESPONSE
                 if (it.Count == 5)
                     Console.WriteLine(new Link_Action_Response(MIHDeserializer.DeserializeStatus(it.Next()),
                                             MIHDeserializer.DeserializeLinkScanRspList(it.Next()),
                                             MIHDeserializer.DeserializeLinkAcResult(it.Next())));
                 else
                     Console.WriteLine(new Link_Action_Response(MIHDeserializer.DeserializeStatus(it.Next()),
                                             new List<byte[]>(),
                                             MIHDeserializer.DeserializeLinkAcResult(it.Next())));
             }
             break;
         case AIDGlobal.EVENT_SERVICE_MIH_LINK_UP:
             Console.WriteLine(new Link_Up(MIHDeserializer.DeserializeLinkTupleId(it.Next()), null, null));
             break;
         case AIDGlobal.EVENT_SERVICE_MIH_LINK_DOWN:
             Console.WriteLine(
                 it.Count<5?
                 new Link_Down(MIHDeserializer.DeserializeLinkTupleId(it.Next()),
                     null,
                     MIHDeserializer.DeserializeLinkDnReason(it.Next()))
                     :
                 new Link_Down(MIHDeserializer.DeserializeLinkTupleId(it.Next()),
                     MIHDeserializer.DeserializeOldAccessRouter(it.Next()),
                     MIHDeserializer.DeserializeLinkDnReason(it.Next()))
                     );
             break;
         case AIDGlobal.EVENT_SERVICE_MIH_LINK_DETECTED:
             Console.WriteLine(new Link_Detected(MIHDeserializer.DeserializeLinkDetInfo(it.Next())));
             break;
         case AIDGlobal.COMMAND_SERVICE_MIH_LINK_GET_PARAMETERS:
             if (m.MIHHeader.MID.OpCode == MessageID.OperationCode.REQUEST)
                 Console.WriteLine(new Link_Get_Parameters_Request(MIHDeserializer.DeserializeLinkParamRequest(it.Next()),
                     it.Next().Value, it.Next().Value));
             else
                 Console.WriteLine(new Link_Get_Parameters_Confirm(MIHDeserializer.DeserializeStatus(it.Next()),
                     MIHDeserializer.DeserializeLinkParamStatusList(it.Next()),
                     MIHDeserializer.DeserializeLinkStatesResponse(it.Next()),
                     MIHDeserializer.DeserializeLinkDescriptorsResponse(it.Next())));
         break;
         default: Console.WriteLine("N/A"); break;
     }
 }
Example #15
0
 /// <summary>
 /// Generates an 802.21-encoded message representing a LinkUp Event.
 /// </summary>
 /// <param name="srcID">The local node ID</param>
 /// <param name="dstID">The destination MIHF ID</param>
 /// <param name="ssid">The SSID of the established connection</param>
 /// <param name="PoAMac">The Physical Address for the Point of Access</param>
 /// <returns>A fully encoded, ready to be sent Message representing a LinkUp</returns>
 public static Message Link_Up_Indication_MsgBuilder(ID srcID, ID dstID, String ssid, PhysicalAddress PoAMac)
 {
     Message m = new Message();
     m.MIHHeader = new MIHHeader();
     m.MIHHeader.MID = new MessageID(MessageID.ServiceIdentifier.EVENT_SERVICE, MessageID.OperationCode.INDICATION, 2);
     m.MIHHeader.VersionValue = 1;
     Link_Tuple_Id linkIdentifier = new Link_Tuple_Id(
                 new Link_Id(Link_Type.Wireless_IEEE80211, new Link_Addr(Link_Addr.Address_Type.OTHER_L2_ADDR, ssid)),
                 new Link_Addr(Link_Addr.Address_Type.MAC_ADDR, Utilities.PhysicalAddressToString(PoAMac)));
     m.Payload = new Payload(srcID,
                             dstID,
                             TLV_HELPERS.TLVLinkIdentifier(linkIdentifier));
     m.MIHHeader.PayloadLength = (ushort)m.Payload.PayloadValue.Length;
     return m;
 }
Example #16
0
        /// <summary>
        /// Generates a Link_Parameters_Report.Indication message, reporting the specified value of the specified parameter type.
        /// </summary>
        /// <param name="src">The source MIHF ID</param>
        /// <param name="dst">The destination MIHF ID</param>
        /// <param name="APMac">The Physical Address of the Access Point (corresponding to the active link)</param>
        /// <param name="networkSSID">The SSID for the active link</param>
        /// <param name="paramType">The type of parameter to report</param>
        /// <param name="value">The value of the parameter</param>
        /// <returns>A Link_Parameters_Report.Indication message ready to be sent.</returns>
        public static Message Link_Parameters_Report_Indication_MsgBuilder(ID src, ID dst, PhysicalAddress APMac, byte[] networkSSID, Link_Param_Abs_Type paramType, ushort value )
        {
            Message m = new Message();
            m.MIHHeader = new MIHHeader();
            m.MIHHeader.MID = new MessageID(MessageID.ServiceIdentifier.EVENT_SERVICE, MessageID.OperationCode.INDICATION, 5);
            m.MIHHeader.VersionValue = 1;
            Link_Tuple_Id linkIdentifier = new Link_Tuple_Id(
                        new Link_Id(Link_Type.Wireless_IEEE80211, new Link_Addr(Link_Addr.Address_Type.MAC_ADDR, Utilities.PhysicalAddressToString(APMac))),
                        new Link_Addr(Link_Addr.Address_Type.OTHER_L2_ADDR, new String(Encoding.ASCII.GetChars(networkSSID))));

            Link_Param_Rpt lpr = new Link_Param_Rpt(
                                    new Link_Param(
                                        Link_Param_Type.FromAbsType(paramType),
                                        (ushort)value,
                                        0 /*TODO 0=LinkParamVal (choice)*/),
                                    null);
            List<byte[]> lprList = new List<byte[]>();
            lprList.Add(lpr.ByteValue);

            m.Payload = new Payload(src,
                                    dst,
                                    Serialization.SerializeToTLV(TLV_VALUES.TLV_LINK_IDENTIFIER, linkIdentifier.ByteValue),
                                    Serialization.SerializeToTLV(TLV_VALUES.TLV_LINK_PARAM_REPORT_LIST, Serialization.EncodingList(lprList.ToArray())));
            m.MIHHeader.PayloadLength = (ushort)m.Payload.PayloadValue.Length;
            return m;
        }
Example #17
0
 /// <summary>
 /// Issues a scan order on the interface and processes (and sends) the rest of the message when the scan is completed.
 /// </summary>
 /// <param name="laresp">The Link_Action_Response for this action.</param>
 /// <param name="iface">The interface to scan.</param>
 /// <param name="m">The message to be processed and sent when the scan is complete.</param>
 public static void Action_Scan(Link_Action_Response laresp, NativeWifi.WlanClient.WlanInterface iface, Message m)
 {
     if (iface != null)
     {
         if(!iface.ScanRequested)
             iface.Scan();
         iface.ScanRequested = true;
         Console.Write("Waiting for scan results...");
         Information.MiscData.PendingLinkActionResponses.Add(m, laresp); //Message sent at the WlanApi class, when a scan event occurs.
     }
     else
     {
         Console.WriteLine("Cannot scan a disabled interface.");
         laresp.Status = STATUS.REJECTED;
     }
 }
Example #18
0
File: Main.cs Project: ATNoG/ODTONE
        private void Init(ushort rcvPort, System.Net.IPAddress mihAddr)
        {
            Link_Register_Indication lri = new Link_Register_Indication(
                Link_Type.Wireless_IEEE80211, //LinkType
                Link_Addr.Address_Type.MAC_ADDR, //LinkAdrressType
                Information.GenericInfo.Interface.GetPhysicalAddress().ToString()); //LinkAddressValue

            //Console.WriteLine(lri);

            connHelper = new ConnectionHelper(rcvPort, mihAddr);
            //connHelper.Send(lri.GetMessage());
            ID myLinkID = new ID(new OctetString(Information.GenericInfo.myID));
            ID mihfID = new ID(new OctetString(Information.GenericInfo.mihfID));

            while (true)
            {
                //TODO colocar a recepção das mensagens aqui.
                //messageHandler.HandleMessage(m);

                byte[] messageAsBytes = connHelper.Receive();

                //Console.WriteLine("!Received: " + messageAsBytes.Length + " bytes from local MIHF.");

                Message m = new Message(messageAsBytes);
                if (Program.MESSAGE_DETAILS)
                {
                    Console.WriteLine("Received message: ("+m.MIHHeader.MID.AID+")");
                    Connection.MIHProtocol.PacketReader.PrintMessage(m);
                }
                //Console.WriteLine("AID: "+m.MIHHeader.MID.AID);
                //Console.WriteLine("Opcode: " + m.MIHHeader.MID.OpCode);
                //Console.WriteLine("SID: " + m.MIHHeader.MID.SID);
                MessageHandler.HandleMessage(m);
            }
        }