Example #1
1
        public static void HandleLinkDown(Wlan.WlanNotificationData notifyData)
        {
            NativeWifi.WlanClient.WlanInterface wlanIface = null;// = GenericInfo.WlanInterface;
            foreach (NativeWifi.WlanClient.WlanInterface wli in Information.GenericInfo.ClientInstance.Interfaces)
                if (wli.InterfaceGuid == notifyData.interfaceGuid)
                    if (wli.NetworkInterface.GetPhysicalAddress().Equals(PhysicalAddress.Parse(Program.MAC.Replace(":", "-").ToUpper()))) //Event filtering
                        wlanIface = wli;

            if (wlanIface != null)
            {
                ConnectionHelper ch = Program.toMihf;
                ID myLinkID = new ID(new OctetString(GenericInfo.myID));
                ID mihfID = new ID(new OctetString(GenericInfo.mihfID));

                if (Subscriptions.List.Link_Down)
                    ch.Send(MessageBuilders.Link_Down_Indication_802_11_MsgBuilder(myLinkID, mihfID,
                        new String(Encoding.ASCII.GetChars(wlanIface.LatestConnection.wlanAssociationAttributes.dot11Ssid.SSID)),
                        wlanIface.LatestConnection.wlanAssociationAttributes.Dot11Bssid,
                        Link_Dn_Reason.ExplicitDisconnect).ByteValue);//TODO get reasons
            }
        }
Example #2
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 #3
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 #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_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 #6
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 #7
0
 /// <summary>
 /// Constructs a message with the Source ID, Destination ID and one parameter.
 /// </summary>
 /// <param name="source">Source ID</param>
 /// <param name="destination">Destination ID</param>
 /// <param name="param1">Parameter</param>
 public Payload(ID source, ID destination, byte[] param1)
 {
     //Console.WriteLine("Creating payload...\tSrc: " + new String(Encoding.ASCII.GetChars(source.ByteValue.Skip(1).ToArray())) + "\tDst: " + new String(Encoding.ASCII.GetChars(destination.ByteValue.Skip(1).ToArray())));
     PayloadValue = Serialization.Sequence(
         Serialization.SerializeToTLV(TLV_VALUES.TLV_MIHF_ID_SOURCE, source.ByteValue),
         Serialization.SerializeToTLV(TLV_VALUES.TLV_MIHF_ID_DESTINATION, destination.ByteValue),
         param1);
 }
Example #8
0
 /// <summary>
 /// MIHProtocol of Destination Identifier.
 /// </summary>
 /// <param name="id">ID object.</param>
 /// <returns>Destination Indentifier Serialization.</returns>
 public static byte[] TLVDestinationIdentifier(ID id)
 {
     return Serialization.SerializeToTLV(TLV_VALUES.TLV_MIHF_ID_DESTINATION, id.ByteValue);
 }
Example #9
0
 /// <summary>
 /// Constructs a message with only the Source and Destination's ID.
 /// </summary>
 /// <param name="source">Source ID</param>
 /// <param name="destination">Destination ID</param>
 public Payload(ID source, ID destination)
 {
     PayloadValue = Serialization.Sequence(
         Serialization.SerializeToTLV(TLV_VALUES.TLV_MIHF_ID_SOURCE, source.ByteValue),
         Serialization.SerializeToTLV(TLV_VALUES.TLV_MIHF_ID_DESTINATION, destination.ByteValue));
 }
Example #10
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 #11
0
 /// <summary>
 /// MIHProtocol of Source Identifier.
 /// </summary>
 /// <param name="id">ID object.</param>
 /// <returns>Source Identifier serialization.</returns>
 public static byte[] TLVSourceIdentifier(ID id)
 {
     return Serialization.SerializeToTLV(TLV_VALUES.TLV_MIHF_ID_SOURCE, id.ByteValue);
 }
Example #12
0
        public static void LinkActionCallback(Object stateInfo)
        {
            Message m = (Message)stateInfo;
            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_Action_Request lar = new Link_Action_Request(MIHDeserializer.DeserializeLinkAction(it.Next()),
                                                    MIHDeserializer.DeserializeTimeInterval(it.Next()),
                                                    MIHDeserializer.DeserializePoA(it.Next()));

            Link_Action_Response laresp = new Link_Action_Response();
            laresp.Status = STATUS.UNSPECIFIED_FAILURE;
            laresp.Result = Link_Ac_Result.INCAPABLE;

            NativeWifi.WlanClient.WlanInterface iface = null;
            try { iface = Information.GenericInfo.WlanInterfaceInstance; }
            catch (Exception e) { /*nothing*/ }
            switch (lar.LinkAction.LinkAcType)
            {
                case Link_Ac_Type.LINK_DISCONNECT:
                    ActionsInterface.Action_Disconnect(ref laresp, ref iface);
                    break;
                case Link_Ac_Type.NONE:
                    Console.WriteLine("No action performed.");
                    laresp.Status = STATUS.SUCCESS;
                    laresp.Result = Link_Ac_Result.SUCCESS;
                    break;
                case Link_Ac_Type.LINK_POWER_DOWN:
                    ActionsInterface.Action_Power_Down(ref laresp, ref iface);
                    break;
                case Link_Ac_Type.LINK_POWER_UP:
                    ActionsInterface.Action_Power_Up(ref laresp, ref iface);
                    break;
                default:
                    throw new InvalidOperationException("Unsupported Operation");

            }
            laresp.ScanResults = new List<Link_Scan_Rsp>();
            if (lar.LinkAction.LinkAcAttr.Link_Scan)
            {
                ActionsInterface.Action_Scan(laresp, iface, m);//Message is sent inside this  branch, after the scan is complete.
            }
            else
                ch.Send(ResponseBuilders.Link_Action_Response_Builder(srcID, dstID, transactionID, laresp).ByteValue);
        }
Example #13
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 #14
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 #15
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 #16
0
 /// <summary>
 /// Constructs a message with the Source ID, Destination ID and six parameters.
 /// </summary>
 /// <param name="source">Source ID</param>
 /// <param name="destination">Destination ID</param>
 /// <param name="param1">Parameter One</param>
 /// <param name="param2">Parameter Two</param>
 /// <param name="param3">Parameter Three</param>
 /// <param name="param4">Parameter Four</param>
 /// <param name="param5">Parameter Five</param>
 /// <param name="param6">Parameter Six</param>
 public Payload(ID source, ID destination, byte[] param1, byte[] param2, byte[] param3, byte[] param4, byte[] param5, byte[] param6)
 {
     PayloadValue = Serialization.Sequence(
         Serialization.SerializeToTLV(TLV_VALUES.TLV_MIHF_ID_SOURCE, source.ByteValue),
         Serialization.SerializeToTLV(TLV_VALUES.TLV_MIHF_ID_DESTINATION, destination.ByteValue),
         param1,
         param2,
         param3,
         param4,
         param5,
         param6);
 }
Example #17
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 #18
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 #19
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 #20
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 #21
0
        public static void HandleParamsReport(Wlan.WlanNotificationData notifyData)
        {
            NativeWifi.WlanClient.WlanInterface wlanIface = null;// = GenericInfo.WlanInterface;
            foreach (NativeWifi.WlanClient.WlanInterface wli in Information.GenericInfo.ClientInstance.Interfaces)
                if (wli.InterfaceGuid == notifyData.interfaceGuid)
                    if (wli.NetworkInterface.GetPhysicalAddress().Equals(PhysicalAddress.Parse(Program.MAC.Replace(":", "-").ToUpper()))) //Event filtering
                        wlanIface = wli;

            if (wlanIface != null)
            {
                ConnectionHelper ch = Program.toMihf;
                ID myLinkID = new ID(new OctetString(GenericInfo.myID));
                ID mihfID = new ID(new OctetString(GenericInfo.mihfID));

                if (Subscriptions.List.Link_Parameters_Report) //Generic subscription
                    ch.Send(MessageBuilders.Link_Parameters_Report_Indication_MsgBuilder(
                        myLinkID, mihfID,
                        wlanIface.CurrentConnection.wlanAssociationAttributes.Dot11Bssid,
                        wlanIface.CurrentConnection.wlanAssociationAttributes.dot11Ssid.SSID,
                        Link_Param_Abs_Type.GEN_Sig_Strenth,
                        Link_Param_Gen.SignalStrength_1).ByteValue);
                Reports.CheckThresholds(Link_Param_Abs_Type.GEN_Sig_Strenth, (int)wlanIface.RSSI);
            }
        }
Example #22
0
        public static void HandleScanComplete(Wlan.WlanNotificationData notifyData)
        {
            NativeWifi.WlanClient.WlanInterface wlanIface = null;// = GenericInfo.WlanInterface;
            foreach (NativeWifi.WlanClient.WlanInterface wli in Information.GenericInfo.ClientInstance.Interfaces)
                if (wli.InterfaceGuid == notifyData.interfaceGuid)
                    if (wli.NetworkInterface.GetPhysicalAddress().Equals(PhysicalAddress.Parse(Program.MAC.Replace(":", "-").ToUpper()))) //Event filtering
                        wlanIface = wli;

            if (wlanIface != null)
            {
                ConnectionHelper ch = Program.toMihf;
                ID myLinkID = new ID(new OctetString(GenericInfo.myID));
                ID mihfID = new ID(new OctetString(GenericInfo.mihfID));

                bool newLinks = wlanIface.UpdateSSIDs(wlanIface.GetNetworkBssList());
                if (wlanIface.ScanRequested)
                    LINK_SAP_CS_80211.Common.Actions.ActionsInterface.FinishScanAction(); //Scan Actions from Link_Action.Requests are replied here.
                wlanIface.ScanRequested = false;
                //LINK DETECTED INDICATION
                if (Subscriptions.List.Link_Detected)
                    if (newLinks)
                        foreach (Wlan.WlanBssEntry entry in wlanIface.newConns)
                            ch.Send(MessageBuilders.Link_Detected_Indication_MsgBuilder(myLinkID, mihfID,
                                entry.dot11Bssid, entry.dot11Ssid.SSID, entry.linkQuality, entry.rssi, Utilities.getMax(entry.wlanRateSet.Rates)).ByteValue);
            }
        }
Example #23
0
        /// <summary>
        /// To be called when a requested scan was complete. This method sends all pending Link_Action_Responses that were waiting for a scan result.
        /// </summary>
        public static void FinishScanAction()
        {
            List<Link_Scan_Rsp> scanResults = new List<Link_Scan_Rsp>();
            foreach (NativeWifi.Wlan.WlanBssEntry entry in Information.GenericInfo.WlanInterfaceInstance.Connections)
            {
                PhysicalAddress pa = new PhysicalAddress(entry.dot11Bssid);
                scanResults.Add(new Link_Scan_Rsp(new Link_Addr(Link_Addr.Address_Type.MAC_ADDR, Utilities.PhysicalAddressToString(pa)),
                    new OctetString(new String(Encoding.ASCII.GetChars(entry.dot11Ssid.SSID))),
                    (ushort)entry.linkQuality));
            }

            foreach (Message m in Information.MiscData.PendingLinkActionResponses.Keys)
            {
                Link_Action_Response laresp;
                Information.MiscData.PendingLinkActionResponses.TryGetValue(m, out laresp);
                laresp.ScanResults = scanResults;
                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_Action_Response_Builder(srcID, dstID, m.MIHHeader.TransactionID, laresp).ByteValue);
            }
            Information.MiscData.PendingLinkActionResponses.Clear();
        }
Example #24
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);
            }
        }