| 1 |
// License: BSD/LGPL |
| 2 |
// Copyright (C) 2011-2018 Thomas d'Otreppe |
| 3 |
using System; |
| 4 |
using System.Collections.Generic; |
| 5 |
using System.Text; |
| 6 |
|
| 7 |
namespace WirelessPanda |
| 8 |
{ |
| 9 |
public class Station : WirelessDevice, IEquatable<Station> |
| 10 |
{ |
| 11 |
|
| 12 |
private AccessPoint _ap = null; |
| 13 |
|
| 14 |
/// <summary> |
| 15 |
/// Access point |
| 16 |
/// </summary> |
| 17 |
public AccessPoint AP |
| 18 |
{ |
| 19 |
get |
| 20 |
{ |
| 21 |
return this._ap; |
| 22 |
} |
| 23 |
// Only allow to do it inside the lib |
| 24 |
internal set |
| 25 |
{ |
| 26 |
this._ap = value; |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
/// <summary> |
| 31 |
/// Station MAC |
| 32 |
/// </summary> |
| 33 |
public string StationMAC |
| 34 |
{ |
| 35 |
get |
| 36 |
{ |
| 37 |
return (string)this.getDictValue("Station MAC"); |
| 38 |
} |
| 39 |
set |
| 40 |
{ |
| 41 |
if (value != null) |
| 42 |
{ |
| 43 |
this.setDictValue("Station MAC", value.Trim()); |
| 44 |
} |
| 45 |
else |
| 46 |
{ |
| 47 |
this.setDictValue("Station MAC", value); |
| 48 |
} |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
/// <summary> |
| 53 |
/// # Packets |
| 54 |
/// </summary> |
| 55 |
public ulong NbPackets |
| 56 |
{ |
| 57 |
get |
| 58 |
{ |
| 59 |
return (ulong)this.getDictValue("# Packets"); |
| 60 |
} |
| 61 |
set |
| 62 |
{ |
| 63 |
this.setDictValue("# Packets", value); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
/// <summary> |
| 68 |
/// Probed ESSIDs (comma separated) |
| 69 |
/// </summary> |
| 70 |
public string ProbedESSIDs |
| 71 |
{ |
| 72 |
get |
| 73 |
{ |
| 74 |
return (string)this.getDictValue("Probed ESSIDs"); |
| 75 |
} |
| 76 |
set |
| 77 |
{ |
| 78 |
this.setDictValue("Probed ESSIDs", value); |
| 79 |
|
| 80 |
// Update probe ESSID list |
| 81 |
this._probedESSIDsList.Clear(); |
| 82 |
if (string.IsNullOrEmpty(value)) |
| 83 |
{ |
| 84 |
foreach (string s in value.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) |
| 85 |
{ |
| 86 |
if (string.IsNullOrEmpty(s.Trim())) |
| 87 |
{ |
| 88 |
continue; |
| 89 |
} |
| 90 |
|
| 91 |
// Add ESSID |
| 92 |
this._probedESSIDsList.Add(s); |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
private List<string> _probedESSIDsList = new List<string>(); |
| 100 |
/// <summary> |
| 101 |
/// Probed ESSIDs List |
| 102 |
/// </summary> |
| 103 |
public string[] ProbedESSIDsList |
| 104 |
{ |
| 105 |
get |
| 106 |
{ |
| 107 |
return _probedESSIDsList.ToArray().Clone() as string[]; |
| 108 |
} |
| 109 |
set |
| 110 |
{ |
| 111 |
this._probedESSIDsList.Clear(); |
| 112 |
this.setDictValue("Probed ESSIDs", string.Empty); |
| 113 |
if (value != null && value.Length > 0) |
| 114 |
{ |
| 115 |
this._probedESSIDsList.AddRange(value); |
| 116 |
|
| 117 |
// Generate the string list of SSID |
| 118 |
StringBuilder sb = new StringBuilder(string.Empty); |
| 119 |
foreach (string s in value) |
| 120 |
{ |
| 121 |
sb.AppendFormat("{0}, ", s); |
| 122 |
} |
| 123 |
|
| 124 |
string res = sb.ToString(); |
| 125 |
if (res.Length > 0) |
| 126 |
{ |
| 127 |
res = res.Substring(0, res.Length - 2); |
| 128 |
} |
| 129 |
|
| 130 |
// And put it in the Probed ESSIDs dictionary item |
| 131 |
this.setDictValue("Probed ESSIDs", res); |
| 132 |
} |
| 133 |
} |
| 134 |
} |
| 135 |
|
| 136 |
/// <summary> |
| 137 |
/// Implements IEquatable |
| 138 |
/// </summary> |
| 139 |
/// <param name="other">Other Station to compare to</param> |
| 140 |
/// <returns>true if equals, false if not</returns> |
| 141 |
public bool Equals(Station other) |
| 142 |
{ |
| 143 |
try |
| 144 |
{ |
| 145 |
if (this.StationMAC == other.StationMAC) |
| 146 |
{ |
| 147 |
return true; |
| 148 |
} |
| 149 |
} |
| 150 |
catch { } |
| 151 |
|
| 152 |
return false; |
| 153 |
} |
| 154 |
} |
| 155 |
} |