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
|
/*++
Copyright (c) Realtek Corporation. All rights reserved.
Module Name:
N62C_AP_Def.h
Abstract:
Contains AP Define and Structure
Revision History:
When What
---------- ----------------------------------------------
04-22-2008 Created
Notes:
--*/
#pragma once
#ifndef _AP_DEFS_H
#define _AP_DEFS_H
#define AP11_MAX_IE_BLOB_SIZE (DOT11_MAX_PDU_SIZE - sizeof(DOT11_MGMT_HEADER) - \
FIELD_OFFSET(DOT11_BEACON_FRAME, InfoElements) - 4)
#ifndef Add2Ptr
#define Add2Ptr(P,I) ((PVOID)((PUCHAR)(P) + (I)))
#endif
/**
* Capabilities
*/
#define AP_SCAN_SSID_LIST_MAX_SIZE 4
#define AP_DESIRED_SSID_LIST_MAX_SIZE 1
#define AP_STRICTLY_ORDERED_SERVICE_CLASS_IMPLEMENTED FALSE
/** ExtAP default configurations (hardware independent) */
#define AP_DEFAULT_ENABLED_AUTO_CONFIG (DOT11_PHY_AUTO_CONFIG_ENABLED_FLAG | DOT11_MAC_AUTO_CONFIG_ENABLED_FLAG)
#define AP_DEFAULT_EXCLUDE_UNENCRYPTED FALSE
#define AP_DEFAULT_AUTHENTICATION_ALGORITHM DOT11_AUTH_ALGO_RSNA_PSK
#define AP_DEFAULT_UNICAST_CIPHER_ALGORITHM DOT11_CIPHER_ALGO_CCMP
#define AP_DEFAULT_MULTICAST_CIPHER_ALGORITHM AP_DEFAULT_UNICAST_CIPHER_ALGORITHM
#define AP_DEFAULT_DESIRED_PHY_ID_COUNT 1
#define AP_DEFAULT_DESIRED_PHY_ID DOT11_PHY_ID_ANY
#define AP_DEFAULT_PHY_ID 0
#define AP_DEFAULT_ADDITIONAL_IE_SIZE 0
#define AP_DEFAULT_ADDITIONAL_IE_DATA NULL
#define AP_DEFAULT_ENABLE_WPS FALSE
/**
* ExtAP default registy info settings, with their ranges
* a default setting is used if the registry is not present or has invalid value
*/
#define AP_DEFAULT_ALLOWED_ASSOCIATION_COUNT 128
#define AP_MIN_ALLOWED_ASSOCIATION_COUNT 0
#define AP_MAX_ALLOWED_ASSOCIATION_COUNT 255
#define AP_DEFAULT_ENABLE_5GHZ FALSE
#define AP_DEFAULT_CHANNEL 11
#define AP_MIN_CHANNEL 0
#define AP_MAX_CHANNEL 11
#define AP_MAX_CHANNEL_FOR_11A 136
#define AP_DEFAULT_FREQUENCY 136
#define AP_DEFAULT_GROUP_KEY_RENEWAL_INTERVAL 3600 // in seconds
#define AP_MIN_GROUP_KEY_RENEWAL_INTERVAL 60
#define AP_MAX_GROUP_KEY_RENEWAL_INTERVAL 86400
#define AP_DEFAULT_ENABLE_CTS_PROTECTION FALSE
#define AP_DEFAULT_ENABLE_FRAME_BURST FALSE
#define AP_DEFAULT_BEACON_PERIOD 100 // in TUs
#define AP_MIN_BEACON_PERIOD 10
#define AP_MAX_BEACON_PERIOD 10000
#define AP_DEFAULT_DTIM_PERIOD 2 // beacon intervals
#define AP_MIN_DTIM_PERIOD 1
#define AP_MAX_DTIM_PERIOD 100
#define AP_DEFAULT_RTS_THRESHOLD 2347
#define AP_MIN_RTS_THRESHOLD 0
#define AP_MAX_RTS_THRESHOLD 2347
#define AP_DEFAULT_FRAGMENTATION_THRSHOLD 2346
#define AP_MIN_FRAGMENTATION_THRESHOLD 256
#define AP_MAX_FRAGMENTATION_THRESHOLD 2346
#define AP_DEFAULT_SHORT_RETRY_LIMIT 7
#define AP_MIN_SHORT_RETRY_LIMIT 1
#define AP_MAX_SHORT_RETRY_LIMIT 255
#define AP_DEFAULT_LONG_RETRY_LIMIT 4
#define AP_MIN_LONG_RETRY_LIMIT 1
#define AP_MAX_LONG_RETRY_LIMIT 255
#define AP_DEFAULT_ENABLE_WMM FALSE
/**
* Define in AP Assoc mgr WIN7 Sample Code
*/
/** Maximum number of stations we will cache state about */
#define AP_STA_MAX_ENTRIES_DEFAULT 32
#define AP_STA_MAX_ENTRIES_MIN 16
#define AP_STA_MAX_ENTRIES_MAX 64
/** Time to wait for association request from station after auth success (in number of milliseconds) */
#define AP_ASSOCIATION_REQUEST_TIMEOUT 100
/** Time in which the station has no activity we assume we have lost connectivity to that station (in number of seconds) */
#define AP_NO_ACTIVITY_TIME 1800
/** The interval of the station inactive timer, in milliseconds */
#define AP_STA_INACTIVE_TIMER_INTERVAL 1000
#define AP_MAX_AID 2007
#define AP_INVALID_AID 0xFFFF
#define AP_AID_TABLE_UNIT_SIZE 8
#define AP_AID_TABLE_UNIT_MASK 0xFF
#define AP_AID_TABLE_SIZE (AP_MAX_AID/AP_AID_TABLE_UNIT_SIZE + 1)
#define AP_AID_HEADER 0xC000
#define AP_DESIRED_PHY_MAX_COUNT 1
#define MAC_HASH_BUCKET_NUMBER 256
/** MAC hash function */
#define HASH_MAC(Mac) (((Mac)[5] ^ (Mac)[4]) % MAC_HASH_BUCKET_NUMBER)
#define DOT11_MAX_MSDU_SIZE (2346U)
/**
* Get access to the MP_EXTSTA_PORT from the MP_PORT
*/
#define MP_GET_AP_PORT(_Port) ((PMP_EXTAP_PORT)(_Port->ChildPort))
#define AP_GET_MP_PORT(_ExtPort) ((PMP_PORT)(_ExtPort->ParentPort))
#define AP_GET_VNIC(_ExtPort) (AP_GET_MP_PORT(_ExtPort)->VNic)
#define AP_GET_ADAPTER(_ExtPort) (AP_GET_MP_PORT(_ExtPort)->Adapter)
#define AP_GET_MP_HANDLE(_ExtPort) (AP_GET_MP_PORT(_ExtPort)->MiniportAdapterHandle)
#define AP_GET_PORT_NUMBER(_ExtPort) (AP_GET_MP_PORT(_ExtPort)->PortNumber)
/**
* Get access to EXTAP components
*/
#define AP_GET_ASSOC_MGR(_ApPort) (&(_ApPort)->AssocMgr)
#define AP_GET_CONFIG(_ApPort) (&(_ApPort)->Config)
#define AP_GET_CAPABILITY(_ApPort) (&(_ApPort)->Capability)
#define AP_GET_REG_INFO(_ApPort) (&(_ApPort)->RegInfo)
/**
* Get access to AP settings
*/
/** Settings maintained by association manager */
#define AP_GET_SSID(_ApPort) (AP_GET_ASSOC_MGR(_ApPort)->Ssid)
#define AP_GET_BSSID(_ApPort) (AP_GET_ASSOC_MGR(_ApPort)->Bssid)
#define AP_GET_CAPABILITY_INFO(_ApPort) (AP_GET_ASSOC_MGR(_ApPort)->Capability)
#define AP_GET_AUTH_ALGO(_ApPort) (AP_GET_ASSOC_MGR(_ApPort)->AuthAlgorithm)
#define AP_GET_UNICAST_CIPHER_ALGO(_ApPort) (AP_GET_ASSOC_MGR(_ApPort)->UnicastCipherAlgorithm)
#define AP_GET_MULTICAST_CIPHER_ALGO(_ApPort) (AP_GET_ASSOC_MGR(_ApPort)->MulticastCipherAlgorithm)
#define AP_GET_OPERATIONAL_RATE_SET(_ApPort) (AP_GET_ASSOC_MGR(_ApPort)->OperationalRateSet)
#define AP_GET_WPS_ENABLED(_ApPort) (AP_GET_ASSOC_MGR(_ApPort)->EnableWps)
/** Settings maintained by config */
#define AP_GET_BEACON_PERIOD(_ApPort) (AP_GET_CONFIG(_ApPort)->BeaconPeriod)
#define AP_GET_DTIM_PERIOD(_ApPort) (AP_GET_CONFIG(_ApPort)->DTimPeriod)
#define AP_GET_BEACON_IE(_ApPort) (AP_GET_CONFIG(_ApPort)->AdditionalBeaconIEData)
#define AP_GET_BEACON_IE_SIZE(_ApPort) (AP_GET_CONFIG(_ApPort)->AdditionalBeaconIESize)
#define AP_GET_PROBE_RESPONSE_IE(_ApPort) (AP_GET_CONFIG(_ApPort)->AdditionalResponseIEData)
#define AP_GET_PROBE_RESPONSE_IE_SIZE(_ApPort) (AP_GET_CONFIG(_ApPort)->AdditionalResponseIESize)
/** commonly used MACROs */
#define VALIDATE_AP_INIT_STATE(pAdapter) \
{ \
if (GetAPState(pAdapter) != AP_STATE_STOPPED) \
{ \
Status = NDIS_STATUS_INVALID_STATE; \
RT_TRACE((COMP_OID_SET | COMP_OID_QUERY | COMP_INIT | COMP_INDIC), DBG_LOUD, ("AP is not in INIT STATE\n"));\
break; \
} \
}
#define VALIDATE_AP_OP_STATE(pAdapter) \
{ \
if (GetAPState(pAdapter) != AP_STATE_STARTED) \
{ \
Status = NDIS_STATUS_INVALID_STATE; \
RT_TRACE((COMP_OID_SET | COMP_OID_QUERY | COMP_INIT | COMP_INDIC), DBG_LOUD, ("AP is not in OP STATE\n"));\
break; \
} \
}
extern DOT11_MAC_ADDRESS Dot11BroadcastAddress;
/** Association Manager state */
typedef enum _AP_ASSOC_MGR_STATE
{
AP_ASSOC_MGR_STATE_NOT_INITIALIZED = 0,
AP_ASSOC_MGR_STATE_STARTING,
AP_ASSOC_MGR_STATE_STARTED,
AP_ASSOC_MGR_STATE_STOPPING,
AP_ASSOC_MGR_STATE_STOPPED
} AP_ASSOC_MGR_STATE, *PAP_ASSOC_MGR_STATE;
//==M==> It might not need define in here
/**
* Station port state
*/
typedef enum _STA_PORT_STATE
{
STA_PORT_STATE_INVALID = 0,
STA_PORT_STATE_OPEN,
STA_PORT_STATE_CLOSED
} STA_PORT_STATE, *PSTA_PORT_STATE;
/**
* DOT11 Frame Class
* See definitions in 802.11 standard.
*/
typedef enum _DOT11_FRAME_CLASS
{
DOT11_FRAME_CLASS_1,
DOT11_FRAME_CLASS_2,
DOT11_FRAME_CLASS_3,
DOT11_FRAME_CLASS_INVALID
} DOT11_FRAME_CLASS, *PDOT11_FRAME_CLASS;
typedef struct _MP_EXTAP_PORT MP_EXTAP_PORT, *PMP_EXTAP_PORT;
//For store Station mac address Link to AP Port
/**
* A hash table based on the MAC address of a station.
* Stations with the same hash value are organized as a linked list.
*/
typedef struct _MAC_HASH_TABLE {
/**
* the table
*/
LIST_ENTRY Buckets[MAC_HASH_BUCKET_NUMBER];
/**
* number of entries
*/
ULONG EntryCount;
} MAC_HASH_TABLE, *PMAC_HASH_TABLE;
typedef const MAC_HASH_TABLE* PCMAC_HASH_TABLE;
/**
* A hash table entry.
*/
typedef struct _MAC_HASH_ENTRY {
LIST_ENTRY Linkage;
/**
* MAC address as the key of an entry
*/
DOT11_MAC_ADDRESS MacKey;
} MAC_HASH_ENTRY, *PMAC_HASH_ENTRY;
/**
* Callback function for APEnumMacEntry.
*
* The callback can return FALSE to terminate the
* enumeration prematurely.
*/
typedef BOOLEAN
(*PENUM_MAC_ENTRY_CALLBACK)(
__in PMAC_HASH_TABLE Table,
__in PMAC_HASH_ENTRY MacEntry,
__in PVOID CallbackCtxt
);
typedef const MAC_HASH_ENTRY* PCMAC_HASH_ENTRY;
// TODO: do we really need this?
/** ExtAP capability */
typedef struct _AP_CAPABIITY
{
/** Maximum number of SSIDs the NIC can support in OID_DOT11_SCAN_REQUEST */
ULONG ScanSsidListSize;
/** Maximum number of desired SSIDs the NIC can support */
ULONG DesiredSsidListSize;
/** Maximum number of Ethertype privacy exemptions the NIC can support */
ULONG PrivacyExemptionListSize;
/** Maximum number of associations the NIC can support */
ULONG AssociationTableSize;
// TODO: add other capabilities
} AP_CAPABIITY, *PAP_CAPABIITY;
/**
* Settings read from the registry
*/
typedef struct _AP_REG_INFO
{
/** number of allowed associations */
ULONG AllowedAssociationCount;
/** default channel/frequency */
ULONG DefaultChannel;
// TODO: AP Mode (mixed)
/** group key renewal interval, in seconds */
ULONG GroupKeyRenewalInterval;
// TODO: transmission rate
/** Beacon period, in TUs */
ULONG BeaconPeriod;
/** DTIM period, in beacon intervals */
ULONG DTimPeriod;
/** RTS threshold */
ULONG RtsThreshold;
/** Fragmentation threshold */
ULONG FragmentationThreshold;
/** Short retry limit */
ULONG ShortRetryLimit;
/** Long retry limit */
ULONG LongRetryLimit;
/** enable 5GHz or not */
BOOLEAN Enable5GHz;
/** enable CTS protection */
BOOLEAN EnableCtsProtection;
/** enable Frame burst */
BOOLEAN EnableFrameBurst;
/** enable WMM */
BOOLEAN EnableWMM;
} AP_REG_INFO, *PAP_REG_INFO;
/**
* ExtAP association manager
*/
typedef struct _AP_ASSOC_MGR
{
/** ExtAP port */
PMP_EXTAP_PORT ApPort;
/** state of Association Manager */
AP_ASSOC_MGR_STATE State;
/**
* Hash table for the stations
*/
MAC_HASH_TABLE MacHashTable;
/**
* Lock we need before we adding/removing entries from the
* hash table. This will be acquired for read by
* routines that are not modifying the table and acquired
* for write by routines that will be removing entries or
* adding entries to the table.
*/
//MP_READ_WRITE_LOCK MacHashTableLock;
/** AID table, a bit for each AID */
UCHAR AidTable[AP_AID_TABLE_SIZE];
/**
* Association related configurations
* A lock is NOT required when updating/querying these configurations
*/
/** SSID that we advertise (we only support one SSID) */
DOT11_SSID Ssid;
/** AP BSSID */
DOT11_MAC_ADDRESS Bssid;
/** Capability information */
DOT11_CAPABILITY Capability;
/** Currently enabled authentication algorithm */
DOT11_AUTH_ALGORITHM AuthAlgorithm;
/** Currently enabled unicast cipher algorithm */
DOT11_CIPHER_ALGORITHM UnicastCipherAlgorithm;
/** Currently enabled multicast cipher algorithm */
DOT11_CIPHER_ALGORITHM MulticastCipherAlgorithm;
/** Use default auth cipher algorithms **/
BOOLEAN bUseDefaultAlgorithms;
/** Operational rate set */
DOT11_RATE_SET OperationalRateSet;
/** Current setting related to acceptance of unencrypted data */
BOOLEAN ExcludeUnencrypted;
PDOT11_PRIVACY_EXEMPTION_LIST PrivacyExemptionList;
/** Enable WPS */
BOOLEAN EnableWps;
/** Scan related data */
/** Scan in process */
LONG ScanInProcess;
/** Local copy of scan request */
PDOT11_SCAN_REQUEST_V2 ScanRequest;
/** Scan request ID */
PVOID ScanRequestId;
/**
* Station inactive timer
* When the timer fires, the inactive time of each
* station is incremented by 1.
*/
NDIS_HANDLE StaInactiveTimer;
/**
* This is actually the count of the associated
* stations because each station is going to
* increase the counter by 1 when it is associated
* and decrement by 1 when it is disassociated.
*/
LONG StaInactiveTimerCounter;
/** For signalling the completion of a synchronous start request */
NDIS_STATUS StartBSSCompletionStatus;
NDIS_EVENT StartBSSCompletionEvent;
NDIS_EVENT StopBSSCompletionEvent;
NDIS_STATUS SetChannelCompletionStatus;
NDIS_EVENT SetChannelCompletionEvent;
} AP_ASSOC_MGR, *PAP_ASSOC_MGR;
/**
* Tracks the state of a station
*/
typedef struct _AP_STA_ENTRY
{
/**
* MAC hash entry.
* This is used for hash table operations.
*/
MAC_HASH_ENTRY MacHashEntry;
/**
* Pointer to the association manager
* where the station is managed.
*/
PAP_ASSOC_MGR AssocMgr;
/** Capability information */
DOT11_CAPABILITY CapabilityInformation;
/** Listen interval */
USHORT ListenInterval;
/** Supported rates */
DOT11_RATE_SET SupportedRateSet;
/** Current association state of the station */
DOT11_ASSOCIATION_STATE AssocState;
/** Current association ID */
USHORT Aid;
/** Power mode */
DOT11_POWER_MODE PowerMode;
/** Auth algorithm */
DOT11_AUTH_ALGORITHM AuthAlgo;
/** Unicast cipher algorithm */
DOT11_CIPHER_ALGORITHM UnicastCipher;
/** Multicast cipher algorithm */
DOT11_CIPHER_ALGORITHM MulticastCipher;
/** WPS enabled */
BOOLEAN WpsEnabled;
/** Association timer */
NDIS_HANDLE AssocTimer;
/** Waiting for association request */
LONG WaitingForAssocReq;
/**
* Association up time, i.e. timestamp at which association is completed with success.
* Timestamp value is returned by NdisGetCurrentSystemTime
*/
LARGE_INTEGER AssocUpTime;
/** Statistics */
DOT11_PEER_STATISTICS Statistics;
/**
* Station reference count.
* Indicate the number of external functions
* that are accessing the station entry.
* The reference count is 1 when an entry is created.
* It is deleted when the reference count reaches zero.
*/
LONG RefCount;
#if 0
/** Buffer for association complete indication */
PDOT11_INCOMING_ASSOC_COMPLETION_PARAMETERS AssocCompletePara;
ULONG AssocCompleteParaSize;
/** Received association request */
PDOT11_MGMT_HEADER AssocReqFrame;
USHORT AssocReqFrameSize;
#endif
/** Association decision */
BOOLEAN AcceptAssoc;
USHORT Reason;
/**
* Inactive time.
* Indicates how long the station has been inactive, in seconds.
*/
LONG InactiveTime;
/**
* Port state
* This is used to decide whether a non-forced scan
* shall be allowed or not.
*/
STA_PORT_STATE PortState;
} AP_STA_ENTRY, *PAP_STA_ENTRY;
/**
* Holds current ExtAP configuration of the miniport that
* are not managed by association manager.
* These configurations can be updated and/or queried via OIDs request from the OS.
* A lock is NOT needed when updating/querying these configurations.
* This data is stateless so we don't need a flag to indicate whether it is initialized or not.
*/
typedef struct _AP_CONFIG
{
/** ExtAP port */
PMP_EXTAP_PORT ApPort;
/** The types of auto configuration for 802.11 parameters that are enabled */
ULONG AutoConfigEnabled;
/** Beacon period, in TUs */
ULONG BeaconPeriod;
/** DTIM period, in beacon intervals */
ULONG DTimPeriod;
#if 0 // remove it after confirmed
/** RTS threshold */
ULONG RtsThreshold;
/** Short retry limit */
ULONG ShortRetryLimit;
/** Long retry limit */
ULONG LongRetryLimit;
/** Fragmentation threshold */
ULONG FragmentationThreshold;
/** Current operating frequency channel list for the DSSS/HRDSSS/ERP PHY */
ULONG CurrentChannel;
/** Current operating frequency channel list for the OFDM PHY */
ULONG CurrentFrequency;
/** Current PHY ID */
ULONG CurrentPhyId;
#endif
/** Default key ID */
ULONG CipherDefaultKeyId;
/** Desired PHY ID list */
ULONG DesiredPhyList[AP_DESIRED_PHY_MAX_COUNT];
ULONG DesiredPhyCount;
}AP_CONFIG, *PAP_CONFIG;
/** ExtAP port */
typedef struct _MP_EXTAP_PORT
{
/** parent port */
PMP_PORT ParentPort;
/** ExtAP capability */
AP_CAPABIITY Capability;
/** Registry settings */
AP_REG_INFO RegInfo;
/**
* AP reference count.
* Indicate the number of external functions
* that are accessing the AP port.
* The AP port cannot be terminated
* until it reaches zero.
*/
LONG RefCount;
/** current AP configuration */
AP_CONFIG Config;
/** association manager */
AP_ASSOC_MGR AssocMgr;
// TODO: statistics
} MP_EXTAP_PORT, *PMP_EXTAP_PORT;
#endif // _AP_DEFS_H
|