public ZB_SEND_DATA_CONFIRM(byte[] framedata) { Handle = framedata[0]; Status = (PacketStatus)framedata[1]; BuildPacket(new DoubleByte(ZToolCMD.ZB_SEND_DATA_CONFIRM), framedata); }
/// <summary> /// /// </summary> /// <param name="packetId"></param> /// <param name="status"></param> /// <param name="frameworkId"></param> public void SetPacketStatus(int frameworkId, PacketStatus status) { lock (locker) { using (var realm = PacketBufferHelper.GetBufferInstance()) { var source = realm.All <Part>().SingleOrDefault(x => x.FrameworkId == frameworkId); if (source == null) { throw new NullReferenceException(); } realm.Write(() => { source.Status = (int)status; if (status == PacketStatus.Transmitted) { source.TransmittedDate = DateTimeOffset.UtcNow; } else { source.TransmittedDate = DateTimeOffset.MinValue; } }); } } }
public ZDO_STATUS_ERROR_RSP(byte[] data) { SrcAddr = new ZToolAddress16(data[1], data[0]); Status = (PacketStatus)data[2]; BuildPacket(new DoubleByte(ZToolCMD.ZDO_STATUS_ERROR_RSP), data); }
public override PacketMainReturnType interiorMain(ref Packet in_packet) { LogEvent le; lock (padlock) { PacketStatus status = PacketStatus.UNDETERMINED; foreach (MacRule r in rules) { status = r.GetStatus(in_packet); if (status == PacketStatus.BLOCKED) { PacketMainReturnType pmr = PacketMainReturnType.Drop; if (r.GetLogMessage() != null) { pmr |= PacketMainReturnType.Log; le = new LogEvent(String.Format(r.GetLogMessage()), this); LogCenter.Instance.LogEvent(le); } if (r.notify) { pmr |= PacketMainReturnType.Popup; } return(pmr); } else if (status == PacketStatus.ALLOWED) { return(PacketMainReturnType.Allow); } } } return(PacketMainReturnType.Allow); }
public static Rule MakeRule(RuleType ruleType, PacketStatus ps, Direction dir, string args, bool log, bool notify) { switch (ruleType) { case RuleType.IP: return(GenIPRule(ps, args, dir, log, notify)); case RuleType.TCPALL: return(new TCPAllRule(ps, dir, log, notify)); case RuleType.TCPIPPORT: return(new TCPIPPortRule(ps, IPAddress.Parse(args.Split(' ')[0]), int.Parse(args.Split(' ')[1]), dir, log, notify)); case RuleType.TCPPORT: return(GenTCPPORT(ps, args, dir, log, notify)); case RuleType.UDPALL: return(new UDPAllRule(ps, dir, log, notify)); case RuleType.UDPPORT: return(GenUDPPORT(ps, args, dir, log, notify)); case RuleType.ALL: return(new AllRule(ps, dir, log, notify)); } return(null); }
public ZDO_BIND_RSP(byte[] data) { SrcAddr = new ZToolAddress16(data[1], data[0]); Status = (PacketStatus)data[2]; BuildPacket(new DoubleByte((ushort)ZToolCMD.ZDO_BIND_RSP), data); }
public override PacketMainReturn interiorMain(ref Packet in_packet) { lock (padlock) { PacketStatus status = PacketStatus.UNDETERMINED; foreach (MacRule r in rules) { status = r.GetStatus(in_packet); if (status == PacketStatus.BLOCKED) { PacketMainReturn pmr = new PacketMainReturn(this); pmr.returnType = PacketMainReturnType.Drop; if (r.GetLogMessage() != null) { pmr.returnType |= PacketMainReturnType.Log; pmr.logMessage = r.GetLogMessage(); } if (r.notify) { pmr.returnType |= PacketMainReturnType.Popup; } return(pmr); } else if (status == PacketStatus.ALLOWED) { return(null); } } } return(null); }
public ZDO_STATUS_ERROR_RSP(byte[] data) { SrcAddr = new ZToolAddress16(data[1], data[0]); Status = (PacketStatus)data[2]; BuildPacket((ushort)ZToolCMD.ZDO_STATUS_ERROR_RSP, data); }
public Packet() : base() { this.m_oData = new Data(); this.m_bType = new Bit(1); this.m_szbtStatus = PacketStatus.NotCopied; this.m_szbtSequence = new Bit[4]; }
public ZDO_MGMT_PERMIT_JOIN_RSP(byte[] data) { SrcAddr = new ZToolAddress16(data[1], data[0]); Status = (PacketStatus)data[2]; BuildPacket((ushort)ZToolCMD.ZDO_MGMT_PERMIT_JOIN_RSP, data); }
public ZB_SEND_DATA_CONFIRM(byte[] framedata) { Handle = framedata[0]; Status = (PacketStatus)framedata[1]; BuildPacket((ushort)ZToolCMD.ZB_SEND_DATA_CONFIRM, framedata); }
public TCPPortRule(PacketStatus ps, List <int> port, Direction direction, bool log, bool notify) { this.ps = ps; this.direction = direction; this.port = port; this.log = log; }
public bool TryAddPackets(int count, PacketStatus packetStatus) { switch (packetStatus) { case PacketStatus.Failure: FailedCount.Value += 1; break; case PacketStatus.Success: SucceededCount.Value += 1; break; } var failedCount = FailedCount.Value != 0 ? FailedCount.Value : 1.0f; if ((SucceededCount.Value / (float)(SucceededCount.Value + FailedCount.Value) <= FailureThreashold) && (FailedCount.Value + SucceededCount.Value >= MinimumPacketsRequired)) { return(false); } else { return(true); } }
public TCPAllRule(PacketStatus ps, Direction direction, bool log, bool notify) { this.ps = ps; this.direction = direction; this.log = log; this.notify = notify; }
public AllRule(PacketStatus ps, Direction direction, bool log, bool notify) { this.ps = ps; this.direction = direction; this.log = log; this.notify = notify; }
/// <summary> /// Used to generate a new IPRule /// </summary> /// <returns></returns> private static IPRule GenIPRule(PacketStatus ps, string args, Direction dir, bool log, bool notify) { List <string> tokens = new List <string>(args.Split(' ')); IPRule rule = new IPRule(); try { // iterate through the tokens and try and parse them into // an IP address foreach (string s in tokens) { IPAddress tmp = IPAddress.Parse(s); rule.ips.Add(tmp); } // set the rest of the fields rule.ps = ps; rule.direction = dir; rule.log = log; rule.notify = notify; } catch (Exception) { // probably a parse error throw new Exception(); } return(rule); }
/// <summary> /// /// </summary> /// <param name="frameworkId"></param> public void SetPacketStatus(string packetId, PacketStatus status, int?frameworkId = null) { lock (locker) { using (var realm = PacketBufferHelper.GetBufferInstance()) { var source = realm.Find <Part>(packetId); if (source == null) { throw new NullReferenceException(); } if (status == PacketStatus.TransferredToDevice && frameworkId == null) { throw new ArgumentException("Framework id must be specified"); } realm.Write(() => { source.Status = (int)status; source.FrameworkId = frameworkId ?? source.FrameworkId; if (status == PacketStatus.Transmitted) { source.TransmittedDate = DateTimeOffset.UtcNow; } else { source.TransmittedDate = DateTimeOffset.MinValue; } }); } } }
public MacRule(PacketStatus ps, PhysicalAddress mac, Direction direction, bool log, bool notify) { this.ps = ps; this.mac = mac.GetAddressBytes(); this.direction = direction; this.log = log; this.notify = notify; }
public IPRule(PacketStatus ps, List <IPAddress> ip, Direction direction, bool log, bool notify) { this.ps = ps; this.direction = direction; this.ips = ip; this.log = log; this.notify = notify; }
public MacRule(PacketStatus ps, Direction direction, bool log, bool notify) { this.ps = ps; this.mac = null; this.direction = direction; this.log = log; this.notify = notify; }
public MacRule(PacketStatus ps, PhysicalAddress mac, Direction direction, bool log, bool notify) { this.ps = ps; this.mac = mac.GetAddressBytes(); this.direction = direction; this.log = log; this.notify = notify; }
private List <NetPacketV1> recvPacketList() { if (!this.isConnected()) { return(null); } List <NetPacketV1> list = new List <NetPacketV1>(); try { NetPacketV1 tv; byte[] buffer = new byte[0x40000]; SocketError success = SocketError.Success; int length = this.socket_.Receive(buffer, 0, buffer.Length, SocketFlags.None, out success); switch (success) { case SocketError.TimedOut: case SocketError.WouldBlock: case SocketError.IOPending: return(list); } if ((success != SocketError.Success) || (length == 0)) { this.socket_.Close(); this.socket_ = null; return(list); } byte[] destinationArray = new byte[0x40000]; Array.Copy(this.left_buf_, 0, destinationArray, 0, this.left_buf_len_); Array.Copy(buffer, 0, destinationArray, this.left_buf_len_, length); int num2 = length + this.left_buf_len_; this.left_buf_len_ = 0; for (int i = num2; i > 0; i -= tv.getPacketLen()) { byte[] buffer3 = new byte[i]; Array.Copy(destinationArray, num2 - i, buffer3, 0, i); tv = new NetPacketV1(); PacketStatus status = tv.deserialize(ref buffer3); if (status != PacketStatus.PACKET_CORRECT) { if (status == PacketStatus.PACKET_NOT_COMPLETE) { this.left_buf_len_ = i; Array.Copy(buffer3, 0, this.left_buf_, 0, this.left_buf_len_); } return(list); } list.Add(tv); } } catch (SystemException) { if (this.isConnected()) { } } return(list); }
private void ResetControlVariables() { _packet.Clear(); _packetLength = 0; _packetLengthOffset = 0; _status = PacketStatus.Empty; _pendingBytes = 4; _completed = true; }
public TCPIPPortRule(PacketStatus ps, IPAddress ip, int port, Direction direction, bool log, bool notify) { this.ps = ps; this.direction = direction; this.port = port; this.ip = ip; this.log = log; this.notify = notify; }
/// <summary> /// Parses out the arguments of a UDPPort rule /// /// We accept single or multiple ports and port ranges /// </summary> /// <param name="args"></param> /// <returns></returns> private static UDPPortRule GenUDPPORT(PacketStatus ps, string args, Direction dir, bool log, bool notify) { // first tokenize the args List <string> tmp = new List <string>(args.Split(' ')); UDPPortRule rule = new UDPPortRule(); try { // iterate through the given arguments foreach (string s in tmp) { string loc = s; // parse the port range if (loc.Contains("-")) { // parse the start/end ports out of the arguments PortRange p = new PortRange(); string[] split = loc.Split('-'); p.start = Convert.ToInt32(split[0]); p.end = Convert.ToInt32(split[1]); // instead of an error message, we can just swap them if (p.start > p.end) { int temp = p.start; p.start = p.end; p.end = temp; } // add it to the rule port ranges list rule.port_ranges.Add(p); } // else it's just a port, add it as usual else { rule.port.Add(Convert.ToInt32(s)); } } // set the other rule stuff rule.ps = ps; rule.direction = dir; rule.log = log; rule.notify = notify; } catch (Exception e) { // probably a parsing error; log it and throw an // exception so the rule isn't touched //LogCenter.WriteErrorLog(e); throw new Exception(); } return(rule); }
/// <summary> /// Parses out the arguments of a TCPPort rule /// /// We accept single or multiple ports and port ranges /// </summary> /// <param name="args"></param> /// <returns></returns> private static TCPPortRule GenTCPPORT(PacketStatus ps, string args, Direction dir, bool log, bool notify) { // first tokenize the args List <string> tmp = new List <string>(args.Split(' ')); TCPPortRule rule = new TCPPortRule(); try { // iterate through the given arguments foreach (string s in tmp) { string loc = s; // parse the port range if (loc.Contains("-")) { // parse the start/end ports out of the arguments PortRange p = new PortRange(); string[] split = loc.Split('-'); p.start = Convert.ToInt32(split[0]); p.end = Convert.ToInt32(split[1]); // someday we'll give more meaningful error messages, but // for now just throw an exception if they're doing something // dumb like range 200-50 if (p.start > p.end) { throw new Exception(); } // add it to the rule port ranges list rule.port_ranges.Add(p); } // else it's just a port, add it as usual else { rule.port.Add(Convert.ToInt32(s)); } } // set the other rule stuff rule.ps = ps; rule.direction = dir; rule.log = log; rule.notify = notify; } catch (Exception) { // probably a parsing error; log it // and throw an exception so the rule isn't changed //LogCenter.WriteErrorLog(e); throw new Exception(); } return(rule); }
/// <summary> /// Parses out the arguments of a UDPPort rule /// /// We accept single or multiple ports and port ranges /// </summary> /// <param name="args"></param> /// <returns></returns> private static UDPPortRule GenUDPPORT(PacketStatus ps, string args, Direction dir, bool log, bool notify) { // first tokenize the args List<string> tmp = new List<string>(args.Split(' ')); UDPPortRule rule = new UDPPortRule(); rule.port_ranges = new List<PortRange>(); try { // iterate through the given arguments foreach (string s in tmp) { string loc = s; // parse the port range if (loc.Contains("-")) { // parse the start/end ports out of the arguments PortRange p = new PortRange(); string[] split = loc.Split('-'); p.start = Convert.ToInt32(split[0]); p.end = Convert.ToInt32(split[1]); // instead of an error message, we can just swap them if (p.start > p.end) { int temp = p.start; p.start = p.end; p.end = temp; } // add it to the rule port ranges list rule.port_ranges.Add(p); } // else it's just a port, add it as usual else { rule.port.Add(Convert.ToInt32(s)); } } // set the other rule stuff rule.ps = ps; rule.direction = dir; rule.log = log; rule.notify = notify; } catch (Exception e) { // probably a parsing error; log it and throw an // exception so the rule isn't touched //LogCenter.WriteErrorLog(e); throw new Exception(); } return rule; }
public static void PacketReceived(PacketStatus packetstatus) { // Make sure someone is listening to event if (OnPacketReceived == null) { return; } WOLEventArgs args = new WOLEventArgs(packetstatus); OnPacketReceived(null, args); }
public void StopListener(PacketStatus _packetstatus) { packetstatus = _packetstatus; if (bgListenforWOL.IsBusy) { bgListenforWOL.CancelAsync(); _wolsock.Close(); } while (bgListenforWOL.IsBusy) { Application.DoEvents(); } }
/// <summary> /// This function contains the actions that will be carried out on the background thread. /// </summary> /// <param name="sender">Object which triggers this event handler, typically a Background Worker</param> /// <param name="e">Arguments pased to the event handler</param> private void bgListenforWOL_DoWork(object sender, DoWorkEventArgs e) { try { int portno = this.portno; _wolsock = new WOL_Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp, portno); Console.WriteLine("Ready to receive..."); _wolsock.ReceiveWOLPacket(); packetstatus = PacketStatus.Received; Console.WriteLine(_wolsock.IEP.Address.ToString()); //print sender IP address } catch (SocketException se) { if (se.SocketErrorCode == SocketError.Interrupted) { e.Cancel = true; //set DoWork result as cancelled } } }
public virtual void ReadXml(XmlReader reader) { XmlSerializer logSerializer = new XmlSerializer(typeof(bool)); XmlSerializer notifySerializer = new XmlSerializer(typeof(bool)); reader.ReadStartElement("macrule"); reader.ReadStartElement("log"); log = (bool)logSerializer.Deserialize(reader); reader.ReadEndElement(); reader.ReadStartElement("notify"); notify = (bool)notifySerializer.Deserialize(reader); reader.ReadEndElement(); XmlSerializer dirSerializer = new XmlSerializer(typeof(Direction)); reader.ReadStartElement("direction"); direction = (Direction)dirSerializer.Deserialize(reader); reader.ReadEndElement(); XmlSerializer statusSerializer = new XmlSerializer(typeof(PacketStatus)); reader.ReadStartElement("status"); ps = (PacketStatus)statusSerializer.Deserialize(reader); reader.ReadEndElement(); XmlSerializer macSerializer = new XmlSerializer(typeof(string)); if (!reader.IsEmptyElement) { reader.ReadStartElement("mac"); mac = Convert.FromBase64String((string)macSerializer.Deserialize(reader)); reader.ReadEndElement(); } else { reader.ReadStartElement("mac"); } reader.ReadEndElement(); }
private void AcceptPacketLength(byte b) { _packetLength |= b << (4 - ++_packetLengthOffset); _status = _packetLengthOffset < 4 ? PacketStatus.ReceivingPacketLength : PacketStatus.ReceivingData; _pendingBytes--; if (_status == PacketStatus.ReceivingData) { if (_packetLength == 0) { EndProcessingData(new byte[0]); } else { _pendingBytes = _packetLength; } } }
public static Rule MakeRule(RuleType ruleType, PacketStatus ps, Direction dir, string args, bool log, bool notify) { switch (ruleType) { case RuleType.IP: return GenIPRule(ps, args, dir, log, notify); case RuleType.TCPALL: return new TCPAllRule(ps, dir, log, notify); case RuleType.TCPIPPORT: return new TCPIPPortRule(ps, IPAddr.Parse(args.Split(' ')[0]), int.Parse(args.Split(' ')[1]), dir, log, notify); case RuleType.TCPPORT: return GenTCPPORT(ps, args, dir, log, notify); case RuleType.UDPALL: return new UDPAllRule(ps, dir, log, notify); case RuleType.UDPPORT: return GenUDPPORT(ps, args, dir, log, notify); case RuleType.ALL: return new AllRule(ps, dir, log, notify); } return null; }
private void AcceptPacketLength(byte b) { _packetLength |= b << (4 - ++_packetLengthOffset); _status = _packetLengthOffset < 4 ? PacketStatus.ReceivingPacketLength : PacketStatus.ReceivingData; _pendingBytes--; if (_status == PacketStatus.ReceivingData) { if (_packetLength == 0) { EndProcessingData(new byte[0]); } else { _pendingBytes = _packetLength; } } }
/// <summary> /// Parses out the arguments of a TCPPort rule /// /// We accept single or multiple ports and port ranges /// </summary> /// <param name="args"></param> /// <returns></returns> private static TCPPortRule GenTCPPORT(PacketStatus ps, string args, Direction dir, bool log, bool notify) { // first tokenize the args List<string> tmp = new List<string>(args.Split(' ')); TCPPortRule rule = new TCPPortRule(); try { // iterate through the given arguments foreach (string s in tmp) { string loc = s; // parse the port range if (loc.Contains("-")) { // parse the start/end ports out of the arguments PortRange p = new PortRange(); string[] split = loc.Split('-'); p.start = Convert.ToInt32(split[0]); p.end = Convert.ToInt32(split[1]); // someday we'll give more meaningful error messages, but // for now just throw an exception if they're doing something // dumb like range 200-50 if (p.start > p.end) throw new Exception(); // add it to the rule port ranges list rule.port_ranges.Add(p); } // else it's just a port, add it as usual else { rule.port.Add(Convert.ToInt32(s)); } } // set the other rule stuff rule.ps = ps; rule.direction = dir; rule.log = log; rule.notify = notify; } catch (Exception) { // probably a parsing error; log it // and throw an exception so the rule isn't changed //LogCenter.WriteErrorLog(e); throw new Exception(); } return rule; }
public IPRule(PacketStatus ps, List<IPAddress> ip, Direction direction, bool log, bool notify) { this.ps = ps; this.direction = direction; this.ips = ip; this.log = log; this.notify = notify; }
public ZDO_BIND_REQ_SRSP(byte[] data) { Status = (PacketStatus)data[0]; BuildPacket((ushort)ZToolCMD.ZDO_BIND_REQ_SRSP, data); }
public TCPIPPortRule(PacketStatus ps, IPAddress ip, int port, Direction direction, bool log, bool notify) { this.ps = ps; this.direction = direction; this.port = port; this.ip = ip; this.log = log; this.notify = notify; }
public TCPPortRule(PacketStatus ps, List<int> port, Direction direction, bool log, bool notify) { this.ps = ps; this.direction = direction; this.port = port; this.log = log; }
public virtual void ReadXml(XmlReader reader) { XmlSerializer logSerializer = new XmlSerializer(typeof(bool)); XmlSerializer notifySerializer = new XmlSerializer(typeof(bool)); reader.ReadStartElement("macrule"); reader.ReadStartElement("log"); log = (bool)logSerializer.Deserialize(reader); reader.ReadEndElement(); reader.ReadStartElement("notify"); notify = (bool)notifySerializer.Deserialize(reader); reader.ReadEndElement(); XmlSerializer dirSerializer = new XmlSerializer(typeof(Direction)); reader.ReadStartElement("direction"); direction = (Direction)dirSerializer.Deserialize(reader); reader.ReadEndElement(); XmlSerializer statusSerializer = new XmlSerializer(typeof(PacketStatus)); reader.ReadStartElement("status"); ps = (PacketStatus)statusSerializer.Deserialize(reader); reader.ReadEndElement(); XmlSerializer macSerializer = new XmlSerializer(typeof(string)); if (!reader.IsEmptyElement) { reader.ReadStartElement("mac"); mac = Convert.FromBase64String((string)macSerializer.Deserialize(reader)); reader.ReadEndElement(); } else reader.ReadStartElement("mac"); reader.ReadEndElement(); }
private void ResetControlVariables() { _packet.Clear(); _packetLength = 0; _packetLengthOffset = 0; _status = PacketStatus.Empty; _pendingBytes = 4; _completed = true; }
/// <summary> /// Used to generate a new IPRule /// </summary> /// <returns></returns> private static IPRule GenIPRule(PacketStatus ps, string args, Direction dir, bool log, bool notify) { List<string> tokens = new List<string>(args.Split(' ')); IPRule rule = new IPRule(); try { // iterate through the tokens and try and parse them into // an IP address foreach ( string s in tokens ) { IPAddress tmp = IPAddress.Parse(s); rule.ips.Add(tmp); } // set the rest of the fields rule.ps = ps; rule.direction = dir; rule.log = log; rule.notify = notify; } catch (Exception) { // probably a parse error throw new Exception(); } return rule; }