-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
690 lines (599 loc) · 19.8 KB
/
Program.cs
File metadata and controls
690 lines (599 loc) · 19.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
using System.CommandLine;
using System.CommandLine.Parsing;
using System.ComponentModel;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text.Json;
using System.Text.Json.Serialization;
internal static class Logger
{
public static void Log(string message) => Console.WriteLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss.fff}] {message}");
}
internal sealed class Program
{
private const int MaxBackoffSeconds = 60;
private const int MaxConsecutiveFailures = 10;
private const int MaxBackoffExponent = 6; // 2^6 = 64, prevents overflow
private const double JitterFactor = 0.25;
private static async Task<int> Main(string[] args)
{
using var cts = new CancellationTokenSource();
Console.CancelKeyPress += (_, e) =>
{
e.Cancel = true;
cts.Cancel();
};
try
{
var rootCommand = CreateRootCommand();
var parseResult = rootCommand.Parse(args);
var exitCode = await parseResult.InvokeAsync(null, cts.Token).ConfigureAwait(false);
return exitCode;
}
catch (OperationCanceledException)
{
return 0;
}
}
private static RootCommand CreateRootCommand()
{
var ssidOption = new Option<string?>("--ssid", "-s")
{
Description = "Wi-Fi SSID."
};
var bssidOption = new Option<string?>("--bssid", "-b")
{
Description = "Wi-Fi BSSID (MAC address)."
};
var gatewayOption = new Option<string?>("--gateway", "-g")
{
Description = "Gateway IP address to ping."
};
var intervalOption = new Option<int?>("--interval", "-i")
{
Description = "Ping interval in seconds."
};
var configOption = new Option<string?>("--config", "-c")
{
Description = "Path to JSON config file."
};
var scanModeOption = new Option<ScanMode>("--mode", "-m")
{
Description = "Scan mode: network (summary) or bssid (per-BSSID list).",
DefaultValueFactory = _ => ScanMode.Network
};
var interfaceOption = new Option<string?>("--interface", "-n")
{
Description = "Target Wi-Fi interface (GUID or name substring)."
};
var rootCommand = new RootCommand("WiFiManager - monitor connectivity and scan Wi-Fi networks.");
var connectCommand = new Command("connect", "Monitor connectivity and reconnect to Wi-Fi.")
{
ssidOption,
bssidOption,
gatewayOption,
intervalOption,
configOption,
interfaceOption
};
connectCommand.SetAction(async (parseResult, cancellationToken) =>
{
var options = new ConnectOptions
{
SSID = parseResult.GetValue(ssidOption),
BSSID = parseResult.GetValue(bssidOption),
Gateway = parseResult.GetValue(gatewayOption),
Interval = parseResult.GetValue(intervalOption),
ConfigFile = parseResult.GetValue(configOption),
Interface = parseResult.GetValue(interfaceOption)
};
return await RunConnectAsync(options, cancellationToken).ConfigureAwait(false);
});
var scanCommand = new Command("scan", "Trigger a WLAN scan and list visible networks.")
{
scanModeOption,
interfaceOption
};
scanCommand.SetAction((parseResult, cancellationToken) =>
{
var options = new ScanOptions
{
Mode = parseResult.GetValue(scanModeOption),
Interface = parseResult.GetValue(interfaceOption)
};
return RunScanAsync(options, cancellationToken);
});
rootCommand.Subcommands.Add(connectCommand);
rootCommand.Subcommands.Add(scanCommand);
var showCommand = new Command("show", "Show WLAN information.");
var showInterfaceCommand = new Command("interface", "List available Wi-Fi interfaces.");
showInterfaceCommand.SetAction((_, _) => Task.FromResult(RunShowInterface()));
showCommand.Subcommands.Add(showInterfaceCommand);
rootCommand.Subcommands.Add(showCommand);
return rootCommand;
}
private static async Task<int> RunConnectAsync(ConnectOptions options, CancellationToken cancellationToken)
{
AppConfig config;
try
{
config = await AppConfig.BuildAsync(options, cancellationToken).ConfigureAwait(false);
}
catch (Exception ex) when (ex is ArgumentException or FileNotFoundException or JsonException)
{
Logger.Log($"Configuration error: {ex.Message}");
return 1;
}
using var wlan = new WlanClient();
if (!TryResolveInterface(wlan, options.Interface, out var selectedInterface, out var error))
{
Logger.Log(error!);
return 1;
}
Logger.Log($"Using interface: {selectedInterface.strInterfaceDescription} (State: {selectedInterface.isState}, GUID: {selectedInterface.InterfaceGuid}).");
var useGatewayMode = !string.IsNullOrWhiteSpace(config.Gateway);
if (useGatewayMode)
{
Logger.Log($"Gateway mode: Monitoring gateway {config.Gateway} every {config.Interval}s for SSID '{config.SSID}'. Press Ctrl+C to exit.");
}
else
{
Logger.Log($"BSSID mode: Monitoring connection to SSID '{config.SSID}' (BSSID: {config.BSSID}) every {config.Interval}s. Press Ctrl+C to exit.");
Logger.Log("WARNING: Windows WLAN AutoConfig may automatically roam to a different BSSID with stronger signal.");
Logger.Log(" If you experience frequent reconnections, consider disabling auto-connect for this network profile.");
}
DateTime? successStart = null;
DateTime? lastSuccess = null;
int consecutiveFailures = 0;
while (!cancellationToken.IsCancellationRequested)
{
var (shouldReconnect, disconnectReason) = await CheckConnectivityAsync(
wlan, selectedInterface.InterfaceGuid, config, useGatewayMode, cancellationToken).ConfigureAwait(false);
if (!shouldReconnect)
{
var now = DateTime.Now;
successStart ??= now;
lastSuccess = now;
consecutiveFailures = 0;
}
else
{
if (successStart.HasValue && lastSuccess.HasValue)
{
Logger.Log($"Connection was healthy from {successStart:yyyy-MM-dd HH:mm:ss.fff} to {lastSuccess:yyyy-MM-dd HH:mm:ss.fff}.");
successStart = null;
lastSuccess = null;
}
Logger.Log($"{disconnectReason}. Reconnecting...");
try
{
await wlan.ConnectAsync(selectedInterface.InterfaceGuid, config.SSID, config.BSSID, cancellationToken).ConfigureAwait(false);
}
catch (Win32Exception ex)
{
Logger.Log($"Reconnect failed with Win32 error {ex.NativeErrorCode}: {ex.Message}");
}
catch (Exception ex)
{
Logger.Log($"Reconnect failed: {ex}");
}
consecutiveFailures++;
if (consecutiveFailures >= MaxConsecutiveFailures)
{
Logger.Log($"Reached maximum consecutive failures ({MaxConsecutiveFailures}). Resetting failure count and continuing...");
consecutiveFailures = 0;
}
}
var waitSeconds = CalculateWaitSeconds(config.Interval, consecutiveFailures);
if (consecutiveFailures > 0)
{
Logger.Log($"Waiting {waitSeconds} seconds before next check (backoff due to {consecutiveFailures} consecutive failure(s), jitter applied)...");
}
await Task.Delay(TimeSpan.FromSeconds(waitSeconds), cancellationToken).ConfigureAwait(false);
}
return 0;
}
private static async Task<int> RunScanAsync(ScanOptions options, CancellationToken cancellationToken)
{
using var wlan = new WlanClient();
if (!TryResolveInterface(wlan, options.Interface, out var selectedInterface, out var error))
{
Logger.Log(error!);
return 1;
}
Logger.Log($"Using interface: {selectedInterface.strInterfaceDescription} (State: {selectedInterface.isState}, GUID: {selectedInterface.InterfaceGuid}).");
Logger.Log(options.Mode == ScanMode.Bssid ? "Scanning for BSS entries..." : "Scanning for available Wi-Fi networks...");
try
{
if (options.Mode == ScanMode.Bssid)
{
var bssList = await wlan.ScanBssAsync(selectedInterface.InterfaceGuid, cancellationToken).ConfigureAwait(false);
if (bssList.Count == 0)
{
Logger.Log("No BSS entries found.");
return 0;
}
var ordered = bssList.OrderByDescending(b => b.LinkQuality).ThenByDescending(b => b.Rssi).ToList();
for (var i = 0; i < ordered.Count; i++)
{
var b = ordered[i];
var freqMhz = b.FrequencyKhz / 1000.0;
var band = ScanHelpers.GetBand(b.FrequencyKhz) ?? "Unknown";
Console.WriteLine($"{i + 1}. BSSID: {b.Bssid}, SSID: {b.Ssid}, RSSI: {b.Rssi} dBm, LinkQuality: {b.LinkQuality}%, Freq: {freqMhz:F1} MHz ({band}), Type: {b.BssType}, PHY: {b.PhyType}");
}
}
else
{
var networks = await wlan.ScanAsync(selectedInterface.InterfaceGuid, cancellationToken).ConfigureAwait(false);
if (networks.Count == 0)
{
Logger.Log("No networks found.");
return 0;
}
var grouped = networks
.GroupBy(n => new { n.SSID, n.BssType })
.Select(g =>
{
var strongest = g.OrderByDescending(n => n.SignalQuality).First();
var totalBssids = g.Sum(n => (int)n.BssCount);
return new
{
strongest.SSID,
strongest.BssType,
strongest.SignalQuality,
strongest.SecurityEnabled,
BssCount = (uint)totalBssids,
strongest.AuthAlgorithm,
strongest.CipherAlgorithm
};
})
.OrderByDescending(n => n.SignalQuality)
.ToList();
for (var i = 0; i < grouped.Count; i++)
{
var n = grouped[i];
var authStr = ScanHelpers.GetAuthAlgorithmName(n.AuthAlgorithm);
var cipherStr = ScanHelpers.GetCipherAlgorithmName(n.CipherAlgorithm);
var securityInfo = n.SecurityEnabled ? $"{authStr}/{cipherStr}" : "Open";
Console.WriteLine($"{i + 1}. SSID: {n.SSID}, Signal: {n.SignalQuality}%, Security: {securityInfo}, BSSIDs: {n.BssCount}, Type: {n.BssType}");
}
}
}
catch (Win32Exception ex)
{
Logger.Log($"Scan failed with Win32 error {ex.NativeErrorCode}: {ex.Message}");
return 1;
}
catch (Exception ex)
{
Logger.Log($"Scan failed: {ex}");
return 1;
}
return 0;
}
private static int RunShowInterface()
{
using var wlan = new WlanClient();
var interfaces = wlan.GetInterfaces();
if (interfaces.Count == 0)
{
Logger.Log("No Wi-Fi interfaces found.");
return 1;
}
for (var i = 0; i < interfaces.Count; i++)
{
var iface = interfaces[i];
Console.WriteLine($"{i + 1}. {iface.strInterfaceDescription} (State: {iface.isState}, GUID: {iface.InterfaceGuid})");
}
return 0;
}
private static bool TryResolveInterface(WlanClient wlan, string? selector, out WLAN_INTERFACE_INFO selected, out string? error)
{
var interfaces = wlan.GetInterfaces();
if (interfaces.Count == 0)
{
selected = default;
error = "No Wi-Fi interfaces found.";
return false;
}
if (string.IsNullOrWhiteSpace(selector))
{
selected = interfaces[0];
error = null;
return true;
}
var trimmed = selector.Trim();
var matches = interfaces
.Where(i => i.InterfaceGuid.ToString().Equals(trimmed, StringComparison.OrdinalIgnoreCase)
|| i.strInterfaceDescription.Contains(trimmed, StringComparison.OrdinalIgnoreCase))
.ToArray();
if (matches.Length == 1)
{
selected = matches[0];
error = null;
return true;
}
selected = default;
if (matches.Length > 1)
{
error = $"Multiple interfaces matched '{selector}'. Please specify the full GUID or a more specific name.";
}
else
{
error = $"No interface matched '{selector}'.";
}
return false;
}
/// <summary>
/// Checks current connectivity status and determines if reconnection is needed.
/// </summary>
/// <returns>A tuple indicating whether to reconnect and the reason for disconnection.</returns>
private static async Task<(bool ShouldReconnect, string? Reason)> CheckConnectivityAsync(
WlanClient wlan,
Guid interfaceId,
AppConfig config,
bool useGatewayMode,
CancellationToken cancellationToken)
{
if (useGatewayMode)
{
// Gateway mode: ping to check connectivity
var reachable = await NetworkHelper.PingAsync(config.Gateway!, TimeSpan.FromSeconds(2), cancellationToken).ConfigureAwait(false);
return reachable ? (false, null) : (true, "Gateway unreachable");
}
// BSSID mode: check current connection info
try
{
var connInfo = wlan.GetCurrentConnection(interfaceId);
if (!connInfo.IsConnected)
{
return (true, "Not connected to any network");
}
if (!string.Equals(connInfo.Ssid, config.SSID, StringComparison.Ordinal))
{
return (true, $"Connected to different SSID: '{connInfo.Ssid}' (expected: '{config.SSID}')");
}
if (!NetworkHelper.BssidEquals(connInfo.Bssid, config.BSSID))
{
return (true, $"Connected to different BSSID: '{connInfo.Bssid}' (expected: '{config.BSSID}')");
}
return (false, null);
}
catch (Win32Exception ex)
{
Logger.Log($"Failed to query connection info: {ex.Message}");
return (true, "Failed to query connection info");
}
}
/// <summary>
/// Calculates wait time with exponential backoff and jitter.
/// </summary>
/// <param name="baseInterval">Base interval in seconds.</param>
/// <param name="consecutiveFailures">Number of consecutive failures.</param>
/// <returns>Wait time in seconds.</returns>
private static int CalculateWaitSeconds(int baseInterval, int consecutiveFailures)
{
// Calculate wait time with exponential backoff on failures (capped to prevent overflow)
var cappedFailures = Math.Min(consecutiveFailures, MaxBackoffExponent);
var backoffMultiplier = cappedFailures > 0 ? 1 << (cappedFailures - 1) : 1;
var baseWaitSeconds = Math.Min(baseInterval * backoffMultiplier, MaxBackoffSeconds);
// Add jitter (±25%) to prevent thundering herd when multiple devices reconnect simultaneously
var jitterRange = (int)(baseWaitSeconds * JitterFactor);
var jitter = jitterRange > 0 ? Random.Shared.Next(-jitterRange, jitterRange + 1) : 0;
return Math.Max(1, baseWaitSeconds + jitter);
}
}
internal sealed class ConnectOptions
{
public string? SSID { get; init; }
public string? BSSID { get; init; }
public string? Gateway { get; init; }
public int? Interval { get; init; }
public string? ConfigFile { get; init; }
public string? Interface { get; init; }
}
internal sealed class ScanOptions
{
public ScanMode Mode { get; init; }
public string? Interface { get; init; }
}
internal enum ScanMode
{
Network,
Bssid
}
internal sealed record AppConfig(string SSID, string? BSSID, string? Gateway, int Interval)
{
public static async Task<AppConfig> BuildAsync(ConnectOptions options, CancellationToken cancellationToken)
{
ConfigFilePayload fileConfig = new();
if (!string.IsNullOrWhiteSpace(options.ConfigFile))
{
var path = options.ConfigFile!;
if (!File.Exists(path))
{
throw new FileNotFoundException($"Config file not found: {path}");
}
await using var stream = File.OpenRead(path);
fileConfig = await JsonSerializer.DeserializeAsync(stream, ConfigFileJsonContext.Default.ConfigFilePayload, cancellationToken).ConfigureAwait(false) ?? new ConfigFilePayload();
}
var ssid = options.SSID ?? fileConfig.SSID;
var bssid = options.BSSID ?? fileConfig.BSSID;
var gateway = options.Gateway ?? fileConfig.Gateway;
var interval = options.Interval ?? fileConfig.Interval ?? 5;
if (string.IsNullOrWhiteSpace(ssid))
{
throw new ArgumentException("SSID is required.");
}
var hasGateway = !string.IsNullOrWhiteSpace(gateway);
var hasBssid = !string.IsNullOrWhiteSpace(bssid);
if (hasGateway && !System.Net.IPAddress.TryParse(gateway, out _))
{
throw new ArgumentException($"Invalid gateway IP address format: {gateway}");
}
if (hasBssid && !NetworkHelper.IsValidBssid(bssid!))
{
throw new ArgumentException($"Invalid BSSID format: {bssid}. Expected format: XX:XX:XX:XX:XX:XX or XX-XX-XX-XX-XX-XX");
}
if (hasGateway && hasBssid)
{
throw new ArgumentException("Gateway and BSSID cannot both be specified. Please choose one mode.");
}
if (!hasGateway && !hasBssid)
{
throw new ArgumentException("Either Gateway or BSSID must be specified.");
}
if (interval <= 0)
{
throw new ArgumentException("Interval must be positive.");
}
return new AppConfig(ssid, bssid, gateway, interval);
}
}
[JsonSourceGenerationOptions(
PropertyNameCaseInsensitive = true,
ReadCommentHandling = JsonCommentHandling.Skip,
AllowTrailingCommas = true)]
[JsonSerializable(typeof(ConfigFilePayload))]
internal sealed partial class ConfigFileJsonContext : JsonSerializerContext
{
}
internal sealed class ConfigFilePayload
{
public string? SSID { get; set; }
public string? BSSID { get; set; }
public string? Gateway { get; set; }
public int? Interval { get; set; }
}
internal static class NetworkHelper
{
/// <summary>
/// Validates whether a string is a valid BSSID (MAC address) format.
/// Accepts formats: XX:XX:XX:XX:XX:XX or XX-XX-XX-XX-XX-XX
/// </summary>
public static bool IsValidBssid(ReadOnlySpan<char> bssid)
{
var hexCount = 0;
foreach (var c in bssid)
{
if (c == ':' || c == '-')
{
continue;
}
if (!char.IsAsciiHexDigit(c))
{
return false;
}
hexCount++;
}
return hexCount == 12;
}
public static async Task<bool> PingAsync(string host, TimeSpan timeout, CancellationToken cancellationToken)
{
using var ping = new Ping();
try
{
// SendPingAsync handles the timeout internally; WaitAsync is only for cancellation support
var pingTask = ping.SendPingAsync(host, (int)timeout.TotalMilliseconds);
var reply = await pingTask.WaitAsync(cancellationToken).ConfigureAwait(false);
return reply.Status == IPStatus.Success;
}
catch (PingException)
{
return false;
}
catch (OperationCanceledException) when (!cancellationToken.IsCancellationRequested)
{
// Timeout only, not user cancellation
return false;
}
// Let user cancellation propagate
}
/// <summary>
/// Compares two BSSID strings, ignoring separator differences (colon vs dash).
/// </summary>
public static bool BssidEquals(string? bssid1, string? bssid2)
{
if (bssid1 is null && bssid2 is null)
{
return true;
}
if (bssid1 is null || bssid2 is null)
{
return false;
}
// Use Span<char> to avoid string allocations
Span<char> buffer1 = stackalloc char[12];
Span<char> buffer2 = stackalloc char[12];
if (!TryNormalizeBssid(bssid1, buffer1) || !TryNormalizeBssid(bssid2, buffer2))
{
return false;
}
return buffer1.SequenceEqual(buffer2);
}
private static bool TryNormalizeBssid(ReadOnlySpan<char> bssid, Span<char> destination)
{
if (destination.Length < 12)
{
return false;
}
var destIndex = 0;
foreach (var c in bssid)
{
if (c == ':' || c == '-')
{
continue;
}
if (destIndex >= 12)
{
return false;
}
destination[destIndex++] = char.ToUpperInvariant(c);
}
return destIndex == 12;
}
}
internal static class ScanHelpers
{
public static string? GetBand(uint frequencyKhz) => (frequencyKhz / 1000.0) switch
{
0 => null,
>= 2400 and <= 2500 => "2.4 GHz",
>= 4900 and < 5925 => "5 GHz",
>= 5925 and <= 7125 => "6 GHz",
>= 57000 and <= 71000 => "60 GHz",
_ => null
};
public static string GetAuthAlgorithmName(DOT11_AUTH_ALGORITHM algorithm) => algorithm switch
{
DOT11_AUTH_ALGORITHM.IEEE80211_Open => "Open",
DOT11_AUTH_ALGORITHM.IEEE80211_SharedKey => "WEP-Shared",
DOT11_AUTH_ALGORITHM.WPA => "WPA-Enterprise",
DOT11_AUTH_ALGORITHM.WPA_PSK => "WPA-Personal",
DOT11_AUTH_ALGORITHM.WPA_None => "WPA-None",
DOT11_AUTH_ALGORITHM.RSNA => "WPA2-Enterprise",
DOT11_AUTH_ALGORITHM.RSNA_PSK => "WPA2-Personal",
DOT11_AUTH_ALGORITHM.WPA3 => "WPA3",
DOT11_AUTH_ALGORITHM.WPA3_SAE => "WPA3-Personal",
DOT11_AUTH_ALGORITHM.OWE => "OWE",
DOT11_AUTH_ALGORITHM.WPA3_ENT => "WPA3-Enterprise",
DOT11_AUTH_ALGORITHM.WPA3_ENT_192 => "WPA3-Enterprise-192",
_ => algorithm.ToString()
};
public static string GetCipherAlgorithmName(DOT11_CIPHER_ALGORITHM algorithm) => algorithm switch
{
DOT11_CIPHER_ALGORITHM.None => "None",
DOT11_CIPHER_ALGORITHM.WEP40 => "WEP40",
DOT11_CIPHER_ALGORITHM.WEP104 => "WEP104",
DOT11_CIPHER_ALGORITHM.WEP => "WEP",
DOT11_CIPHER_ALGORITHM.TKIP => "TKIP",
DOT11_CIPHER_ALGORITHM.CCMP => "CCMP",
DOT11_CIPHER_ALGORITHM.GCMP => "GCMP",
DOT11_CIPHER_ALGORITHM.GCMP_256 => "GCMP-256",
DOT11_CIPHER_ALGORITHM.BIP => "BIP",
DOT11_CIPHER_ALGORITHM.BIP_GMAC_128 => "BIP-GMAC-128",
DOT11_CIPHER_ALGORITHM.BIP_GMAC_256 => "BIP-GMAC-256",
DOT11_CIPHER_ALGORITHM.BIP_CMAC_256 => "BIP-CMAC-256",
_ => algorithm.ToString()
};
}