public void ThreadAbleReadFile(String fileName) { string[] lines = System.IO.File.ReadAllLines(@"C:\simulator\_DATA_TO_SEND\input.txt"); AP _connecttoAP = GetAPBySSID(_AccessPoint[0].ToString()); Data dataPack = new Data(CreatePacket()); dataPack.SSID = _connecttoAP.SSID; dataPack.Destination = _connecttoAP.getMACAddress(); dataPack.PacketChannel = this.getOperateChannel(); dataPack.PacketBand = this.getOperateBand(); dataPack.Reciver = fileName; Int32 SQID = 0; foreach (string line in lines) { // Use a tab to indent each line of the file. dataPack = new Data(CreatePacket()); dataPack.SSID = _connecttoAP.SSID; dataPack.Destination = _connecttoAP.getMACAddress(); dataPack.PacketChannel = this.getOperateChannel(); dataPack.PacketBand = this.getOperateBand(); dataPack.Reciver = fileName; SQID++; dataPack.setData(line); dataPack.PacketID = SQID; ackReceived = false; SendData(dataPack); WaitingForAck = true; int retrCounter = 60; Thread.Sleep(6); while (!ackReceived) { retrCounter--; Thread.Sleep(2); if (retrCounter < 0) { retrCounter = 60; SendData(dataPack); _DataRetransmited++; } } WaitingForAck = false; //SpinWait.SpinUntil(() => { return ackReceived; }); // Thread.Sleep(3); //Console.WriteLine("\t" + line); } }
/// <summary> /// Slow Timer /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tbrGUISlow_Tick(object sender, EventArgs e) { lblMAC.Text = _ap.getMACAddress(); lblChannel.Text = _ap.getOperateChannel().ToString(); lblBand.Text = _ap.Freq.ToString() + " " + _ap.Stand80211.ToString(); lblSSID.Text = _ap.SSID; ArrayListCounted devicesList = _ap.GetAssociatedDevices(); listStations.Items.Clear(); foreach (object __o in devicesList) { string s = (string)__o; listStations.Items.Add(s); // loop body } if (_ap._LOG.Length > 0) { cmdShowLog.Enabled = true; } UpdateStandartSupport(); if (!_ap.isEnabled()) { this.Close(); } }
//********************************************************************* private void ThreadableConnectToAP(String SSID, Connect _conn, AP _connecttoAP) { bool connectSuccess = false; _AssociatedWithAPList.Clear(); Int32 tRYStOcONNECT = 0; _conn.SSID = _connecttoAP.SSID; _conn.Destination = _connecttoAP.getMACAddress(); _conn.PacketChannel = _connecttoAP.getOperateChannel(); _conn.PacketBand = _connecttoAP.getOperateBand(); _conn.Reciver = _connecttoAP.getMACAddress(); this.setOperateChannel(_connecttoAP.getOperateChannel()); this.setOperateBand(_connecttoAP.getOperateBand()); while (!connectSuccess) { if (!_AssociatedWithAPList.Contains(SSID)) { if (tRYStOcONNECT < 10) { SendData(_conn); tRYStOcONNECT++; Thread.Sleep(1000); } } else { connectSuccess = true; } } if (connectSuccess && _scanning) { SpinWait.SpinUntil (() => { return((bool)!_scanning); } ); this.setOperateChannel(_connecttoAP.getOperateChannel()); this.setOperateBand(_connecttoAP.getOperateBand()); } // Fix Work Channel under scan }
private void SendKeepAlive() { while (_Enabled) { if (!getAssociatedAP_SSID().Equals("")) { KeepAlive keepAl = new KeepAlive(CreatePacket()); AP _connecttoAP = GetAPBySSID(_AccessPoint[0].ToString()); Data dataPack = new Data(CreatePacket()); keepAl.SSID = _connecttoAP.SSID; keepAl.Destination = _connecttoAP.getMACAddress(); keepAl.PacketChannel = this.getOperateChannel(); keepAl.PacketBand = this.getOperateBand(); keepAl.Reciver = _connecttoAP.getMACAddress(); SendData(keepAl); Thread.Sleep(3000); } else { Thread.Sleep(10000); } } }
private void tbrGUISlow_Tick(object sender, EventArgs e) { lblMAC.Text = _ap.getMACAddress(); lblChannel.Text = _ap.getOperateChannel().ToString(); lblBand.Text = _ap.getOperateBand(); lblSSID.Text = _ap.SSID; ArrayListCounted devicesList = _ap.getAssociatedDevices(); listStations.Items.Clear(); foreach (object __o in devicesList) { string s = (string)__o; listStations.Items.Add(s); // loop body } }
//==================================================================================================== public void refr() { try { gr.Clear(BoardColor); Pen RadiusForApPen = null; Pen RadiusForStaPen = null; int DoubleRadius = _RADIUS * 2; int HalfRadius = _RADIUS; for (int i = 0; i < _objects.Count; i++) { if (_objects[i].GetType() == typeof(STA)) { STA _tsta = (STA)_objects[i]; if (_tsta.RFWorking()) { RadiusForStaPen = new Pen(System.Drawing.Color.SandyBrown); } else { RadiusForStaPen = new Pen(System.Drawing.Color.SpringGreen); } Point ulCorner = new Point((int)_tsta.x - 10, (int)_tsta.y - 10); gr.DrawImage(_tsta.STAImage, ulCorner); gr.DrawPie(RadiusForStaPen, (float)_tsta.x - HalfRadius, (float)_tsta.y - HalfRadius, DoubleRadius, DoubleRadius, 1, 360); string drawString = "STA:" + _tsta.getOperateChannel() + " " + _tsta.getMACAddress(); System.Drawing.Font drawFont = new System.Drawing.Font( "Arial", 7); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.YellowGreen); gr.DrawString(drawString, drawFont, drawBrush, (int)_tsta.x + 10, (int)_tsta.y + 10); drawFont.Dispose(); drawBrush.Dispose(); } else if (_objects[i].GetType() == typeof(AP)) { AP _tap = (AP)_objects[i]; Rectangle myRectangle = new Rectangle((int)_tap.x - 5, (int)_tap.y - 5, 10, 10); if (_tap.RFWorking()) { RadiusForApPen = new Pen(System.Drawing.Color.Coral); } else { RadiusForApPen = new Pen(System.Drawing.Color.Ivory); } gr.DrawPie(RadiusForApPen, (float)_tap.x - HalfRadius, (float)_tap.y - HalfRadius, DoubleRadius, DoubleRadius, 1, 360); Point ulCorner = new Point((int)_tap.x - 10, (int)_tap.y - 10); gr.DrawImage(_tap.APImage, ulCorner); string drawString = "AP:" + _tap.getOperateChannel() + " " + _tap.SSID + " " + _tap.getMACAddress(); System.Drawing.Font drawFont = new System.Drawing.Font( "Arial", 8); System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.White); gr.DrawString(drawString, drawFont, drawBrush, (int)_tap.x + 10, (int)_tap.y - 10); drawFont.Dispose(); drawBrush.Dispose(); } } //gr.DrawPie(new Pen(Color.Yellow), 500/2, 500/2, 1, 1, 1, 360); piB.Image = bm; } catch (Exception ex) { MessageBox.Show("refr:" + ex.Message); } }
//********************************************************************* public void ParseReceivedPacket(IPacket pack) { Type _Pt = pack.GetType(); if (_Pt == typeof(Packets.ConnectionACK)) { Packets.ConnectionACK _ack = (Packets.ConnectionACK)pack; if (!_AssociatedWithAPList.Contains(_ack.SSID)) { _AssociatedWithAPList.Add(_ack.SSID); Thread.Sleep(5); } } else if (_Pt == typeof(Packets.Beacon)) { Packets.Beacon bec = (Packets.Beacon)pack; if (!_AccessPoint.Contains(bec.SSID)) { _AccessPoint.Add(bec.SSID); } _AccessPoint.Increase(bec.SSID); //Thread.Sleep(2); } else if (_Pt == typeof(Packets.Data)) { Packets.Data dat = (Packets.Data)pack; bool recieve = dat.PacketID != PrevDataID; if (recieve) { _DataReceived++; DataAck da = new DataAck(CreatePacket()); PrevDataID = dat.PacketID; AP _connecttoAP = GetAPBySSID(_AccessPoint[0].ToString()); da.Destination = _connecttoAP.getMACAddress(); da.PacketChannel = this.getOperateChannel(); da.PacketBand = this.getOperateBand(); da.Reciver = dat.Source; DataReceivedContainer.Append(dat.getData() + "\r\n"); //Thread.Sleep(2); da.PacketID = dat.PacketID; SendData(da); } else { // ACK Not received AddToLog("ACK Not received :" + dat.PacketID); DataAck da = new DataAck(CreatePacket()); //PrevDataID = dat.PacketID; AP _connecttoAP = GetAPBySSID(_AccessPoint[0].ToString()); da.Destination = _connecttoAP.getMACAddress(); da.PacketChannel = this.getOperateChannel(); da.PacketBand = this.getOperateBand(); da.Reciver = dat.Source; //DataReceivedContainer.Append(dat.getData() + "\r\n"); //Thread.Sleep(2); DataAckRetransmitted++; da.PacketID = dat.PacketID; SendData(da); } } else if (_Pt == typeof(Packets.DataAck)) { Packets.DataAck dat = (Packets.DataAck)pack; if (PrevDataAckID != dat.PacketID) { _DataAckReceived++; ackReceived = true; PrevDataAckID = dat.PacketID; } } else { //Console.WriteLine("[" + getMACAddress() + "]" + " listening."); } }