/// <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> /// Executes a Power Down (disable 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_Down(ref Link_Action_Response laresp, ref NativeWifi.WlanClient.WlanInterface iface) { Console.WriteLine("Disabling 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("Disable", 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 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> /// 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> /// 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; }