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 } } }
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); } }
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); } }
/// <summary> /// Executes a disconnect on the interface and changes the Status of the Link_Action_Response. /// </summary> /// <param name="laresp">The Link_Action_Response for this action.</param> /// <param name="iface">The interface do disconnect the link from.</param> public static void Action_Disconnect(ref Link_Action_Response laresp, ref NativeWifi.WlanClient.WlanInterface iface) { if (iface != null) { iface.Disconnect(); Console.WriteLine("Disconnected b/c a Disconnect Link Action was received."); laresp.Status = STATUS.SUCCESS; laresp.Result = Link_Ac_Result.SUCCESS; } else { Console.WriteLine("Cannot disconnect a disabled interface."); laresp.Status = STATUS.REJECTED; laresp.Result = Link_Ac_Result.REFUSED; } }
/// <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; } }
/// <summary> /// Executes a Power Up (enable interface) on the interface and changes the Status of the Link_Action_Response. /// </summary> /// <param name="laresp">The Link_Action_Response for this action.</param> /// <param name="iface">The interface do disconnect the link from.</param> public static void Action_Power_Up(ref Link_Action_Response laresp, ref NativeWifi.WlanClient.WlanInterface iface) { Console.WriteLine("Enabling interface."); try { using (ManagementObjectSearcher mos = new ManagementObjectSearcher(@"SELECT * FROM Win32_NetworkAdapter WHERE GUID = '" + iface.InterfaceGuid.ToString() + "'")) { ManagementObject objMO = mos.Get().Cast <ManagementObject>().SingleOrDefault(); objMO.InvokeMethod("Enable", null); } laresp.Status = STATUS.SUCCESS; laresp.Result = Link_Ac_Result.SUCCESS; } catch (Exception) { laresp.Status = STATUS.UNSPECIFIED_FAILURE; laresp.Result = Link_Ac_Result.FAILURE; } }
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); } } } } }