summaryrefslogtreecommitdiff
path: root/network/wlan/ihvsample/ihvsample.cpp
blob: 2b73a7ed60e32440b4e9a15012a38284f3031b46 (plain)
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
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
/*++

Copyright (c) 2005 Microsoft Corporation

Abstract:

   Sample IHV Extensibility DLL to extend
   802.11 LWF driver for third party protocols.


--*/

#include "precomp.h"



//
// Get Version info.
//
DWORD
WINAPI
Dot11ExtIhvGetVersionInfo
(
   OUT   PDOT11_IHV_VERSION_INFO    pDot11IHVVersionInfo
)
{
   if ( pDot11IHVVersionInfo )
   {
      pDot11IHVVersionInfo->dwVerMin = 0;
      pDot11IHVVersionInfo->dwVerMax = 0;
   }
    return ERROR_SUCCESS;
}


//
// Initialize service.
//

DWORD
WINAPI
Dot11ExtIhvInitService
(
   IN    DWORD                      dwVerNumUsed,
   IN    PDOT11EXT_APIS             pDot11ExtAPI,
   IN    LPVOID                     pvReserved,
   OUT   PDOT11EXT_IHV_HANDLERS     pDot11IHVHandlers
)
{
    DWORD   dwResult    =   ERROR_SUCCESS;
    BOOL    bLocked     =   FALSE;

    UNREFERENCED_PARAMETER( pvReserved );

    if
    (
        ( 0 != dwVerNumUsed )      ||
        ( !pDot11ExtAPI )          ||
        ( !pDot11IHVHandlers )
    )
    {
        dwResult = ERROR_INVALID_PARAMETER;
        BAIL_ON_WIN32_ERROR( dwResult );
    }

    EnterCriticalSection( &g_csSynch );
    bLocked = TRUE;

    InitAdapterDetailsList( );

    g_pDot11ExtApi = (PDOT11EXT_APIS) PrivateMemoryAlloc( sizeof( DOT11EXT_APIS ) );
    if ( !g_pDot11ExtApi )
    {
        dwResult = ERROR_OUTOFMEMORY;
        BAIL_ON_WIN32_ERROR( dwResult );
    }
    (*g_pDot11ExtApi)    =  (*pDot11ExtAPI);

    HandlerInit( pDot11IHVHandlers );


error:
    if ( bLocked )
    {
        LeaveCriticalSection( &g_csSynch );
    }
    return dwResult;
}





//
// Deinitialize service.
//
VOID
WINAPI
IhvDeinitService
(
   VOID
)
{

    EnterCriticalSection( &g_csSynch );

    // disable starting new threads or adding new adapters.
    StartShutdown( );

    LeaveCriticalSection( &g_csSynch );


    WaitOnZeroThreads( );
    DeinitAdapterDetailsList( );

    if ( g_pDot11ExtApi )
    {
        PrivateMemoryFree( g_pDot11ExtApi );
        g_pDot11ExtApi = NULL;
    }

    return;
}



//
// Initialize adapter
//
DWORD
WINAPI
IhvInitAdapter
(
   IN    PDOT11_ADAPTER    pDot11Adapter,
   IN    HANDLE            hDot11SvcHandle,
   OUT   PHANDLE           phIhvExtAdapter
)
{
    DWORD       dwResult            =   ERROR_SUCCESS;
    BOOL        bLocked             =   FALSE;
    HANDLE      hIhvExtAdapter      =   NULL;
    USHORT      usEtherTypeReg[]    =   { 0x888e, 0x8333 };

    if (( !pDot11Adapter ) || (!hDot11SvcHandle) || (!phIhvExtAdapter) )
    {
        dwResult = ERROR_INVALID_PARAMETER;
        BAIL_ON_WIN32_ERROR( dwResult );
    }

    EnterCriticalSection( &g_csSynch );
    bLocked = TRUE;

    dwResult =
    InitAdapterDetails
    (
        hDot11SvcHandle,
        &hIhvExtAdapter
    );
    BAIL_ON_WIN32_ERROR( dwResult );

    dwResult =
    (g_pDot11ExtApi->Dot11ExtSetEtherTypeHandling)
    (
        hDot11SvcHandle,
        3,
        0,
        NULL,
        2,
        usEtherTypeReg
    );
    BAIL_ON_WIN32_ERROR( dwResult );

    (*phIhvExtAdapter)  =   hIhvExtAdapter;
    hIhvExtAdapter      =   NULL;

error:

    if ( hIhvExtAdapter )
    {
        DerefenceAdapterDetails( hIhvExtAdapter );
    }

    if ( bLocked )
    {
        LeaveCriticalSection( &g_csSynch );
    }
    return dwResult;
}



//
// Deinit adapter.
//
VOID
WINAPI
IhvDeinitAdapter
(
   IN    HANDLE   hIhvExtAdapter
)
{
    DerefenceAdapterDetails( hIhvExtAdapter );

    return;
}





//
// Handle session change notification.
//
DWORD
WINAPI
IhvProcessSessionChange
(
   IN    ULONG                         uEventType,
   IN    PWTSSESSION_NOTIFICATION      pSessionNotification
)
{
   UNREFERENCED_PARAMETER( pSessionNotification );

   if ( WTS_CONSOLE_CONNECT == uEventType )
   {
      // The sample does not use this session ID
      // anywhere. In an actual application, IHV
      // developers may want to use this session ID to
      // get/set the user data.
      g_dwSessionID = WTSGetActiveConsoleSessionId( );
   }
   return ERROR_SUCCESS;
}





//
// Checks if UI request is pending.
//
DWORD
WINAPI
IhvIsUIRequestPending
(
   IN    GUID     guidUIRequest,
   OUT   PBOOL    pbIsRequestPending
)
{
    DWORD                   dwResult        =   ERROR_SUCCESS;
    BOOL                    bLocked         =   FALSE;
    PADAPTER_DETAILS        pAdapterDetails =   NULL;
    HANDLE                  hIhvExtAdapter  =   NULL;


    ASSERT( pbIsRequestPending );

    EnterCriticalSection( &g_csSynch );
    bLocked = TRUE;

    // obtain reference to the adapter using
    // UI request GUID.
    dwResult =
    ReferenceAdapterDetailsByUIRequestGuid
    (
        &guidUIRequest,
        &pAdapterDetails,
        &hIhvExtAdapter
    );
    if ( ERROR_NOT_FOUND == dwResult )
    {
        dwResult = ERROR_SUCCESS;
        (*pbIsRequestPending) = FALSE;
        BAIL( );
    }
    BAIL_ON_WIN32_ERROR( dwResult );
    ASSERT( pAdapterDetails );


    (*pbIsRequestPending) = TRUE;

error:
    if ( pAdapterDetails )
    {
        DerefenceAdapterDetails( hIhvExtAdapter );
    }
    if ( bLocked )
    {
        LeaveCriticalSection( &g_csSynch );
    }
    return dwResult;
}




//
// Handle NIC specific notifications.
//
DWORD
WINAPI
IhvReceiveIndication
(
    IN  HANDLE                          hIhvExtAdapter,
    IN  DOT11EXT_IHV_INDICATION_TYPE    indicationType,
    IN  ULONG                           uBufferLength,
    IN  LPVOID                          pvBuffer
)
{
    DWORD                                   dwResult                    =   ERROR_SUCCESS;
    PDOT11_PMKID_CANDIDATE_LIST_PARAMETERS  pPMKCandidateListParams     =   NULL;
    PDOT11_TKIPMIC_FAILURE_PARAMETERS       pTkipMicFailureParams       =   NULL;
    PDOT11_PHY_STATE_PARAMETERS             pPHYStateChange             =   NULL;
    PDOT11_LINK_QUALITY_PARAMETERS          pDot11LinkQualityParams     =   NULL;

    ASSERT( pvBuffer );

    // Note that sample does not really use the buffer.
    UNREFERENCED_PARAMETER( hIhvExtAdapter );
    UNREFERENCED_PARAMETER( uBufferLength );

    switch ( indicationType )
    {
        case IndicationTypeNicSpecificNotification:
            // The pointer pvBuffer can be interpreted by IHV appropriately. Format
            // is a contract between the miniport driver and the IHV extensibility module.
            break;

        case IndicationTypePmkidCandidateList:
            pPMKCandidateListParams = (PDOT11_PMKID_CANDIDATE_LIST_PARAMETERS) pvBuffer;
            // Ihv extensibility module may choose to use this data appropriately.
            break;

        case IndicationTypeTkipMicFailure:
            pTkipMicFailureParams = (PDOT11_TKIPMIC_FAILURE_PARAMETERS) pvBuffer;
            // Ihv extensibility module may choose to use this data appropriately.
            break;

        case IndicationTypePhyStateChange:
            pPHYStateChange = (PDOT11_PHY_STATE_PARAMETERS) pvBuffer;
            // Ihv extensibility module may choose to use this data appropriately.
            break;

        case IndicationTypeLinkQuality:
            pDot11LinkQualityParams = (PDOT11_LINK_QUALITY_PARAMETERS) pvBuffer;
            // Ihv extensibility module may choose to use this data appropriately.
            break;

        default:
            ASSERTFAILURE();
            dwResult = ERROR_INVALID_PARAMETER;
            BAIL_ON_WIN32_ERROR( dwResult );
            break;
    }

error:
    return dwResult;
}






//
// Perform the capabiity match.
//
DWORD
WINAPI
IhvPerformCapabilityMatch
(
    IN  HANDLE                              hIhvExtAdapter,
    IN  PDOT11EXT_IHV_PROFILE_PARAMS        pIhvProfileParams,
    IN  PDOT11EXT_IHV_CONNECTIVITY_PROFILE  pIhvConnProfile,
    IN  PDOT11EXT_IHV_SECURITY_PROFILE      pIhvSecProfile,
    IN  PDOT11_BSS_LIST                     pConnectableBssid,
    OUT PDWORD                              pdwReasonCode
)
{
    DWORD                       dwResult                =   ERROR_SUCCESS;
    BOOL                        bLocked                 =   FALSE;
    PBYTE                       pbCurrPos               =   NULL;
    ULONG                       uRemainBytes            =   0;
    ULONG                       uBssEntryBytes          =   0;
    PULDOT11_BSS_ENTRY          pBssEntry               =   NULL;
    PADAPTER_DETAILS            pAdapterDetails         =   NULL;
    PIHV_CONNECTIVITY_PROFILE   pConnectivityProfile    =   NULL;
    PIHV_SECURITY_PROFILE       pSecurityProfile        =   NULL;

    ASSERT( hIhvExtAdapter );
    ASSERT( pdwReasonCode );

    (*pdwReasonCode) = L2_REASON_CODE_UNKNOWN;

    if ( !pConnectableBssid )
    {
        dwResult =
        IhvValidateProfile
        (
            hIhvExtAdapter,
            pIhvProfileParams,
            pIhvConnProfile,
            pIhvSecProfile,
            pdwReasonCode
        );
        BAIL_ON_WIN32_ERROR( dwResult );

        // Only validate profile if
        // pConnectableBssid is NULL.
        BAIL( );
    }

    // Validating data in pConnectableBssid
    if (( 0 == pConnectableBssid->uNumOfBytes ) || ( NULL == pConnectableBssid->pucBuffer ))
    {
        dwResult = ERROR_NO_MATCH;
        BAIL_ON_WIN32_ERROR( dwResult );
    }

    (*pdwReasonCode) = L2_REASON_CODE_IHV_BAD_PROFILE;

    // parse the connectivity profile.
    dwResult =
    GetIhvConnectivityProfile
    (
        pIhvConnProfile,
        &pConnectivityProfile
    );
    BAIL_ON_WIN32_ERROR( dwResult );
    ASSERT( pConnectivityProfile );

    // parse the security profile.
    dwResult =
    GetIhvSecurityProfile
    (
        pIhvSecProfile,
        &pSecurityProfile
    );
    BAIL_ON_WIN32_ERROR( dwResult );
    ASSERT( pSecurityProfile );

    (*pdwReasonCode) = L2_REASON_CODE_UNKNOWN;

    EnterCriticalSection( &g_csSynch );
    bLocked = TRUE;

    // reference the adapter.
    dwResult =
    ReferenceAdapterDetails
    (
        hIhvExtAdapter,
        &pAdapterDetails
    );
    BAIL_ON_WIN32_ERROR( dwResult );
    ASSERT( pAdapterDetails );


    // try matching each BSS description field with the profile
    // and see if there is a match.
    uRemainBytes   =  pConnectableBssid->uNumOfBytes;
    pbCurrPos      =  pConnectableBssid->pucBuffer;

    // BSS Description might not contain any buffer!
    while (uRemainBytes >= FIELD_OFFSET(DOT11_BSS_ENTRY, ucBuffer))
    {
        pBssEntry = (PULDOT11_BSS_ENTRY)pbCurrPos;
        uBssEntryBytes = pBssEntry->uBufferLength + FIELD_OFFSET(DOT11_BSS_ENTRY, ucBuffer);

        ASSERT (uRemainBytes >= uBssEntryBytes);
        uRemainBytes -= uBssEntryBytes;
        pbCurrPos += uBssEntryBytes;

        if
        (
            MatchBssDescription
            (
                pIhvProfileParams,
                pConnectivityProfile,
                pSecurityProfile,
                pBssEntry
            )
        )
        {
            (*pdwReasonCode) = L2_REASON_CODE_SUCCESS;
            dwResult = ERROR_SUCCESS;
            BAIL( );
        }
    }

    // Since none of the BSS entries matched.
    dwResult = ERROR_NO_MATCH;

error:
    if ( pAdapterDetails )
    {
        DerefenceAdapterDetails( hIhvExtAdapter );
    }
    if ( bLocked )
    {
        LeaveCriticalSection( &g_csSynch );
    }
    FreeIhvConnectivityProfile( &pConnectivityProfile );
    FreeIhvSecurityProfile( &pSecurityProfile );
    return dwResult;
}





//
// Function to validate profile.
//
DWORD
WINAPI
IhvValidateProfile
(
    IN  HANDLE                              hIhvExtAdapter,
    IN  PDOT11EXT_IHV_PROFILE_PARAMS        pIhvProfileParams,
    IN  PDOT11EXT_IHV_CONNECTIVITY_PROFILE  pIhvConnProfile,
    IN  PDOT11EXT_IHV_SECURITY_PROFILE      pIhvSecProfile,
    OUT PDWORD                              pdwReasonCode
)
{
    DWORD                       dwResult                =   ERROR_SUCCESS;
    PIHV_CONNECTIVITY_PROFILE   pConnectivityProfile    =   NULL;
    PIHV_SECURITY_PROFILE       pSecurityProfile        =   NULL;


    ASSERT( hIhvExtAdapter );
    ASSERT( pdwReasonCode );

    UNREFERENCED_PARAMETER( hIhvExtAdapter );
    UNREFERENCED_PARAMETER( pIhvProfileParams );

    (*pdwReasonCode) = L2_REASON_CODE_IHV_BAD_PROFILE;

    // parse ihv connectivity profile.
    dwResult =
    GetIhvConnectivityProfile
    (
        pIhvConnProfile,
        &pConnectivityProfile
    );
    BAIL_ON_WIN32_ERROR( dwResult );
    ASSERT( pConnectivityProfile );

    // parse ihv security profile.
    dwResult =
    GetIhvSecurityProfile
    (
        pIhvSecProfile,
        &pSecurityProfile
    );
    BAIL_ON_WIN32_ERROR( dwResult );
    ASSERT( pSecurityProfile );

    (*pdwReasonCode) = L2_REASON_CODE_SUCCESS;

error:
    FreeIhvConnectivityProfile( &pConnectivityProfile );
    FreeIhvSecurityProfile( &pSecurityProfile );
    return dwResult;
}


//
// This function does the actual preassociation work.
//
DWORD
WINAPI
DoPreAssociate
(
    LPVOID  pvPreAssociate
)
{
    DWORD                       dwResult            =   ERROR_SUCCESS;
    DWORD                       dwStatus            =   ERROR_SUCCESS;
    PADAPTER_DETAILS            pAdapterDetails     =   NULL;
    PRE_ASSOCIATE_FUNCTION      lpfnPreAssociate    =   NULL;
    BOOL                        bLocked             =   FALSE;
    DWORD                       dwReasonCode        =   L2_REASON_CODE_UNKNOWN;


    EnterCriticalSection( &g_csSynch );
    bLocked = TRUE;

    dwResult =
    ReferenceAdapterDetails
    (
        (HANDLE) pvPreAssociate,
        &pAdapterDetails
    );
    BAIL_ON_WIN32_ERROR( dwResult );
    ASSERT( pAdapterDetails );


    dwReasonCode = L2_REASON_CODE_IHV_BAD_PROFILE;

    if ( !(pAdapterDetails->pConnectivityProfile && pAdapterDetails->pSecurityProfile) )
    {
        dwResult = ERROR_INVALID_PARAMETER;
        BAIL_ON_WIN32_ERROR( dwResult );
    }

    // choose pre-association function based on profile content.
    if
    (
        ( pAdapterDetails->pSecurityProfile->bUseFullSecurity ) ||
        ( pAdapterDetails->pSecurityProfile->bUseIhvConnectivityOnly )
    )
    {
        if ( pAdapterDetails->pSecurityProfile->bUseIhvConnectivityOnly )
        {
            lpfnPreAssociate = DoIhvConnPreAssociate;
        }
        else if ( NULL == pAdapterDetails->pConnectivityProfile->pszParam2 )
        {
            lpfnPreAssociate = DoMissingKeyWepPreAssociate;
        }
        else if ( 0 == pAdapterDetails->pConnectivityProfile->pszParam2[0] )
        {
            lpfnPreAssociate = DoMissingKeyWepPreAssociate;
        }
        else
        {
            lpfnPreAssociate = DoWepPreAssociate;
        }
    }
    else if
    (
        ( !(pAdapterDetails->pSecurityProfile->bUseFullSecurity) )     &&
        ( IHVAuthV1 == pAdapterDetails->pSecurityProfile->AuthType )
    )
    {
            lpfnPreAssociate = Do1xPreAssociate;
    }
    else
    {
        dwResult = ERROR_INVALID_PARAMETER;
        BAIL_ON_WIN32_ERROR( dwResult );
    }

    dwReasonCode = L2_REASON_CODE_UNKNOWN;

    LeaveCriticalSection( &g_csSynch );
    bLocked = FALSE;

    ASSERT( lpfnPreAssociate );
    ASSERT( !bLocked );

    dwResult =
    (lpfnPreAssociate)
    (
        pAdapterDetails,
        &dwReasonCode
    );
    BAIL_ON_WIN32_ERROR( dwResult );

error:
    if ( pAdapterDetails )
    {
        DerefenceAdapterDetails( (HANDLE) &(pAdapterDetails->Link) );
    }
    if ( bLocked )
    {
        LeaveCriticalSection( &g_csSynch );
    }
    if ( pAdapterDetails )
    {
        // call the completion function directly in this thread.
        dwStatus =
        (g_pDot11ExtApi->Dot11ExtPreAssociateCompletion)
        (
            pAdapterDetails->hDot11SvcHandle,
            pAdapterDetails->hConnectSession,
            dwReasonCode,
            dwResult
        );
    }
    if ( ERROR_SUCCESS != dwStatus )
    {
        // IHV specific logging can happen here.
    }
    return dwResult;
}



//
// Function to start the preassociation thread.
//
DWORD
WINAPI
IhvPerformPreAssociate
(
   IN    HANDLE                                 hIhvExtAdapter,
   IN    HANDLE                                 hConnectSession,
   IN    PDOT11EXT_IHV_PROFILE_PARAMS           pIhvProfileParams,
   IN    PDOT11EXT_IHV_CONNECTIVITY_PROFILE     pIhvConnProfile,
   IN    PDOT11EXT_IHV_SECURITY_PROFILE         pIhvSecProfile,
   IN    PDOT11_BSS_LIST                        pConnectableBssid,
   OUT   PDWORD                                 pdwReasonCode
)
{
    DWORD               dwResult        =   ERROR_SUCCESS;
    DWORD               dwStatus        =   ERROR_SUCCESS;
    BOOL                bLocked         =   FALSE;
    PADAPTER_DETAILS    pAdapterDetails =   NULL;


    ASSERT ( pIhvProfileParams );
    ASSERT ( pdwReasonCode );

    UNREFERENCED_PARAMETER( pIhvProfileParams );
    UNREFERENCED_PARAMETER( pConnectableBssid );

    (*pdwReasonCode) = L2_REASON_CODE_UNKNOWN;

    EnterCriticalSection( &g_csSynch );
    bLocked = TRUE;

    dwResult =
    ReferenceAdapterDetails
    (
        hIhvExtAdapter,
        &pAdapterDetails
    );
    BAIL_ON_WIN32_ERROR( dwResult );
    ASSERT( pAdapterDetails );

    if ( nic_state_initialized != pAdapterDetails->NicState )
    {
        dwResult = ERROR_INVALID_STATE;
        BAIL_ON_WIN32_ERROR( dwResult );
    }

    // Connection specific parameters should be properly initialized.
    if
    (
        ( pAdapterDetails->pOnexData )                              ||
        ( pAdapterDetails->hConnectSession )                        ||
        ( pAdapterDetails->pPerformPostAssociateCompletionRoutine ) ||
        ( pAdapterDetails->pPerformPostAssociateRoutine )           ||
        ( pAdapterDetails->pStopPostAssociateRoutine )
    )
    {
        dwResult = ERROR_INVALID_STATE;
        BAIL_ON_WIN32_ERROR( dwResult );
    }



    (*pdwReasonCode) = L2_REASON_CODE_IHV_BAD_PROFILE;

    // parse connectivity profile
    dwResult =
    GetIhvConnectivityProfile
    (
        pIhvConnProfile,
        &(pAdapterDetails->pConnectivityProfile)
    );
    BAIL_ON_WIN32_ERROR( dwResult );
    ASSERT( pAdapterDetails->pConnectivityProfile );

    // parse security profile.
    dwResult =
    GetIhvSecurityProfile
    (
        pIhvSecProfile,
        &(pAdapterDetails->pSecurityProfile)
    );
    BAIL_ON_WIN32_ERROR( dwResult );
    ASSERT( pAdapterDetails->pSecurityProfile );

    (*pdwReasonCode) = L2_REASON_CODE_UNKNOWN;

    pAdapterDetails->NicState = nic_state_pre_assoc_started;

    pAdapterDetails->hConnectSession        =   hConnectSession;
    pAdapterDetails->bModifyCurrentProfile  =   FALSE;


    // post a new thread to do the pre-association work.
    dwResult =
    StartNewProtectedThread
    (
        hIhvExtAdapter,
        DoPreAssociate,
        (LPVOID) hIhvExtAdapter
    );
    BAIL_ON_WIN32_ERROR( dwResult );


    (*pdwReasonCode) = L2_REASON_CODE_SUCCESS;


error:
    if ( ERROR_SUCCESS != dwResult )
    {
        dwStatus =
        IhvAdapterReset
        (
            hIhvExtAdapter
        );
        ASSERT( ERROR_SUCCESS == dwStatus );
    }
    if ( pAdapterDetails )
    {
        DerefenceAdapterDetails( hIhvExtAdapter );
    }
    if ( bLocked )
    {
        LeaveCriticalSection( &g_csSynch );
    }
    return dwResult;
}





//
// This function starts post associate routine
// in a separate thread and returns.
//
DWORD
WINAPI
IhvPerformPostAssociate
(
   IN    HANDLE                                       hIhvExtAdapter,
   IN    HANDLE                                       hSecuritySessionID,
   IN    PDOT11_PORT_STATE                            pPortState,
   IN    ULONG                                        uDot11AssocParamsBytes,
   IN    PDOT11_ASSOCIATION_COMPLETION_PARAMETERS     pDot11AssocParams
)
{
    DWORD               dwResult        =   ERROR_SUCCESS;
    BOOL                bLocked         =   FALSE;
    PPOST_ASSOC_DATA    ppostAssocData  =   NULL;
    PADAPTER_DETAILS    pAdapterDetails =   NULL;


    ASSERT ( pDot11AssocParams );

    EnterCriticalSection( &g_csSynch );
    bLocked = TRUE;

    dwResult =
    ReferenceAdapterDetails
    (
        hIhvExtAdapter,
        &pAdapterDetails
    );
    BAIL_ON_WIN32_ERROR( dwResult );
    ASSERT( pAdapterDetails );


    if ( nic_state_pre_assoc_ended != pAdapterDetails->NicState )
    {
        dwResult = ERROR_INVALID_STATE;
        BAIL_ON_WIN32_ERROR( dwResult );
    }
    pAdapterDetails->NicState = nic_state_post_assoc_started;

    // is any post-association work required ??
    if ( pAdapterDetails->pPerformPostAssociateRoutine )
    {
        dwResult =
        ( pAdapterDetails->pPerformPostAssociateRoutine )
        (
            pAdapterDetails,
            hSecuritySessionID,
            pPortState,
            uDot11AssocParamsBytes,
            pDot11AssocParams
        );
        BAIL_ON_WIN32_ERROR( dwResult );
    }

    // The post association completion thread may have been
    // started by the perform post association routine for
    // the current profile. Check if the completion thread
    // needs to be started and start the routine.
    if ( pAdapterDetails->pPerformPostAssociateCompletionRoutine )
    {
        ppostAssocData = (PPOST_ASSOC_DATA) PrivateMemoryAlloc( sizeof( POST_ASSOC_DATA ) );
        if ( !ppostAssocData )
        {
            dwResult = ERROR_OUTOFMEMORY;
            BAIL_ON_WIN32_ERROR( dwResult );
        }

        ppostAssocData->hIhvExtAdapter      =  hIhvExtAdapter;
        ppostAssocData->hDot11SvcHandle     =  pAdapterDetails->hDot11SvcHandle;
        ppostAssocData->hSecuritySessionId  =  hSecuritySessionID;


        dwResult =
        StartNewProtectedThread
        (
            hIhvExtAdapter,
            pAdapterDetails->pPerformPostAssociateCompletionRoutine,
            ppostAssocData
        );
        BAIL_ON_WIN32_ERROR( dwResult );


        ppostAssocData = NULL;
    }



error:
    if ( pAdapterDetails )
    {
        DerefenceAdapterDetails( hIhvExtAdapter );
    }
    PrivateMemoryFree( ppostAssocData );
    if ( bLocked )
    {
        LeaveCriticalSection( &g_csSynch );
    }
    return dwResult;
}



//
// Reset the adapter to initialized state.
//
DWORD
WINAPI
IhvAdapterReset
(
   IN    HANDLE   hIhvExtAdapter
)
{
    DWORD               dwResult        =   ERROR_SUCCESS;
    PADAPTER_DETAILS    pAdapterDetails =   NULL;
    DWORD               dwRefCount      =   0;
    BOOL                bOk             =   FALSE;
    BOOL                bLocked         =   FALSE;


    EnterCriticalSection( &g_csSynch );
    bLocked = TRUE;

    dwResult =
    ReferenceAdapterDetails
    (
        hIhvExtAdapter,
        &pAdapterDetails
    );
    BAIL_ON_WIN32_ERROR( dwResult );
    ASSERT( pAdapterDetails );


    for ( ;; )
    {
        ASSERT( bLocked );

        dwRefCount = pAdapterDetails->dwRefCount;

        if ( 2 == dwRefCount ) // For adapter init and self call.
        {
            break;
        }

        if ( nic_state_pre_assoc_started == pAdapterDetails->NicState )
        {
            pAdapterDetails->NicState = nic_state_pre_assoc_ended;
            bOk = SetEvent( pAdapterDetails->hUIResponse );
            ASSERT( bOk );
        }

        LeaveCriticalSection( &g_csSynch );
        bLocked = FALSE;

        Sleep( 100 );

        EnterCriticalSection( &g_csSynch );
        bLocked = TRUE;
    }

    ASSERT( bLocked );

    // Resetting adapter.

    pAdapterDetails->NicState                                   =   nic_state_initialized;
    pAdapterDetails->hConnectSession                            =   NULL;
    pAdapterDetails->bModifyCurrentProfile                      =   FALSE;
    pAdapterDetails->pPerformPostAssociateCompletionRoutine     =   NULL;
    pAdapterDetails->pPerformPostAssociateRoutine               =   NULL;
    pAdapterDetails->pStopPostAssociateRoutine                  =   NULL;

    // freeing UI response data.
    pAdapterDetails->dwResponseLen                              =   0;

    PrivateMemoryFree( pAdapterDetails->pbResponse );
    pAdapterDetails->pbResponse                                 =   NULL;

    ZeroMemory( &(pAdapterDetails->currentGuidUIRequest), sizeof( GUID ) );

    // freeing profile and onex data
    FreeOnexData( &(pAdapterDetails->pOnexData) );
    FreeIhvConnectivityProfile( &(pAdapterDetails->pConnectivityProfile) );
    FreeIhvSecurityProfile( &(pAdapterDetails->pSecurityProfile) );

    // unblocking UI thread.
    bOk = ResetEvent( pAdapterDetails->hUIResponse );
    if ( !bOk )
    {
        dwResult = GetLastError( );
        BAIL_ON_WIN32_ERROR( dwResult );
    }

error:
    if ( bLocked )
    {
        LeaveCriticalSection( &g_csSynch );
    }
    if ( pAdapterDetails )
    {
        DerefenceAdapterDetails( hIhvExtAdapter );
    }
    return dwResult;
}




//
// Stop post association. Get back
// to the state before post association started.
//
DWORD
WINAPI
IhvStopPostAssociate
(
   IN    HANDLE               hIhvExtAdapter,
   IN    PDOT11_MAC_ADDRESS   pPeer,
   IN    DOT11_ASSOC_STATUS   dot11AssocStatus
)
{
    DWORD               dwResult        =   ERROR_SUCCESS;
    PADAPTER_DETAILS    pAdapterDetails =   NULL;
    DWORD               dwRefCount      =   0;
    BOOL                bLocked         =   FALSE;

    // The dot11AssocStatus parameter can be compared with
    // values DOT11_ASSOC_STATUS_* defined in the public
    // headers.

    EnterCriticalSection( &g_csSynch );
    bLocked = TRUE;

    dwResult =
    ReferenceAdapterDetails
    (
        hIhvExtAdapter,
        &pAdapterDetails
    );
    BAIL_ON_WIN32_ERROR( dwResult );
    ASSERT( pAdapterDetails );

    for ( ;; )
    {
        ASSERT( bLocked );

        dwRefCount = pAdapterDetails->dwRefCount;

        if ( 2 == dwRefCount ) // For adapter init and self call.
        {
            break;
        }

        LeaveCriticalSection( &g_csSynch );
        bLocked = FALSE;

        Sleep( 100 );

        EnterCriticalSection( &g_csSynch );
        bLocked = TRUE;
    }

    ASSERT( bLocked );

    if ( nic_state_initialized == pAdapterDetails->NicState )
    {
        // NO OP
        // To handle the case when stop post associate
        // call comes after adapter reset.
        BAIL( );
    }

    // Call the post association routine - if there is any.
    if ( pAdapterDetails->pStopPostAssociateRoutine )
    {
        dwResult =
        (pAdapterDetails->pStopPostAssociateRoutine)
        (
            pAdapterDetails,
            pPeer,
            dot11AssocStatus
        );
        BAIL_ON_WIN32_ERROR( dwResult );
    }

    pAdapterDetails->NicState = nic_state_pre_assoc_ended;

error:
    if ( bLocked )
    {
        LeaveCriticalSection( &g_csSynch );
    }
    if ( pAdapterDetails )
    {
        DerefenceAdapterDetails( hIhvExtAdapter );
    }
    return dwResult;
}


//
// Process received packets.
//
DWORD
WINAPI
IhvReceivePacket
(
   IN    HANDLE   hIhvExtAdapter,
   IN    DWORD    dwInBufferSize,
   IN    LPVOID   pvInBuffer
)
{
    DWORD                       dwResult            =   ERROR_SUCCESS;
    BOOL                        bLocked             =   FALSE;
    PADAPTER_DETAILS            pAdapterDetails     =   NULL;
    IHV_RECEIVE_PACKET_HANDLER  lpfnReceivePacket   =   NULL;


    EnterCriticalSection( &g_csSynch );
    bLocked = TRUE;


    dwResult =
    ReferenceAdapterDetails
    (
        hIhvExtAdapter,
        &pAdapterDetails
    );
    BAIL_ON_WIN32_ERROR( dwResult );
    ASSERT( pAdapterDetails );


    if ( pAdapterDetails->pOnexData && pAdapterDetails->pOnexData->lpfnReceivePacket )
    {
        lpfnReceivePacket = pAdapterDetails->pOnexData->lpfnReceivePacket;
    }
    else
    {
        dwResult = ERROR_INVALID_STATE;
        BAIL_ON_WIN32_ERROR( dwResult );
    }

    LeaveCriticalSection( &g_csSynch );
    bLocked = FALSE;

    ASSERT( lpfnReceivePacket );

    // Call the receive packet routine.
    dwResult =
    (lpfnReceivePacket)
    (
        pAdapterDetails,
        dwInBufferSize,
        pvInBuffer
    );
    BAIL_ON_WIN32_ERROR( dwResult );


error:
    if ( pAdapterDetails )
    {
        DerefenceAdapterDetails( hIhvExtAdapter );
    }
    if ( bLocked )
    {
        LeaveCriticalSection( &g_csSynch );
    }
    return dwResult;
}




//
// Local copy of possible discovery profiles.
//
DOT11EXT_IHV_DISCOVERY_PROFILE
g_IhvDiscoveryProfiles[] =
{
    // discovery profile 1.
    {
        {
            L"<IhvConnectivity xmlns=\"http://www.someihv.com/nwifi/profile\">"
            L"<IHVConnectivityParam1>0</IHVConnectivityParam1>"
            L"<IHVConnectivityParam2></IHVConnectivityParam2>"
            L"</IhvConnectivity>"
        },

        // Use MS Onex.
        {
            L"<IhvSecurity xmlns=\"http://www.someihv.com/nwifi/profile\">"
            L"<IHVUsesFullSecurity>FALSE</IHVUsesFullSecurity>"
            L"<IHVAuthentication>IHVAuthV1</IHVAuthentication>"
            L"<IHVEncryption>IHVCipher1</IHVEncryption>"
            L"<IHVSecurityParam1>0</IHVSecurityParam1>"
            L"<IHVSecurityParam2></IHVSecurityParam2>"
            L"</IhvSecurity>",

            TRUE
        }
    },

    // discovery profile 2
    {
        // Open Wep
        {
            L"<IhvConnectivity xmlns=\"http://www.someihv.com/nwifi/profile\">"
            L"<IHVConnectivityParam1>0</IHVConnectivityParam1>"
            L"<IHVConnectivityParam2></IHVConnectivityParam2>"
            L"</IhvConnectivity>"
        },

        // Full IHV Security
        {
            L"<IhvSecurity xmlns=\"http://www.someihv.com/nwifi/profile\">"
            L"<IHVUsesFullSecurity>TRUE</IHVUsesFullSecurity>"
            L"<IHVAuthentication>IHVAuthV1</IHVAuthentication>"
            L"<IHVEncryption>IHVCipher1</IHVEncryption>"
            L"<IHVSecurityParam1>0</IHVSecurityParam1>"
            L"<IHVSecurityParam2></IHVSecurityParam2>"
            L"</IhvSecurity>",

            FALSE
        }
    }
};







//
// Create discovery profiles.
//
DWORD
WINAPI
IhvCreateDiscoveryProfiles
(
    IN  HANDLE                                      hIhvExtAdapter,
    IN  BOOL                                        bInsecure,
    IN  PDOT11EXT_IHV_PROFILE_PARAMS                pIhvProfileParams,
    IN  PDOT11_BSS_LIST                             pConnectableBssid,
    OUT PDOT11EXT_IHV_DISCOVERY_PROFILE_LIST        pIhvDiscoveryProfileList,
    OUT PDWORD                                      pdwReasonCode
)
{
    DWORD   dwResult            =   ERROR_SUCCESS;
    DWORD   dwIndex             =   0;
    DWORD   dwIHVNumProfiles    =   ARRAY_LENGTH( g_IhvDiscoveryProfiles );

    ASSERT( pIhvDiscoveryProfileList );
    ASSERT( pdwReasonCode );

    UNREFERENCED_PARAMETER( hIhvExtAdapter );
    UNREFERENCED_PARAMETER( bInsecure );
    UNREFERENCED_PARAMETER( pIhvProfileParams );
    UNREFERENCED_PARAMETER( pConnectableBssid );

    (*pdwReasonCode) = L2_REASON_CODE_IHV_OUTOFMEMORY;

    // allocate buffer for the array.
    dwResult =
    (g_pDot11ExtApi->Dot11ExtAllocateBuffer)
    (
        dwIHVNumProfiles * sizeof( DOT11EXT_IHV_DISCOVERY_PROFILE ),
        (LPVOID*) &(pIhvDiscoveryProfileList->pIhvDiscoveryProfiles)
    );
    BAIL_ON_WIN32_ERROR( dwResult );

    ASSERT( pIhvDiscoveryProfileList->pIhvDiscoveryProfiles );
    ZeroMemory
    (
        pIhvDiscoveryProfileList->pIhvDiscoveryProfiles,
        dwIHVNumProfiles * sizeof( DOT11EXT_IHV_DISCOVERY_PROFILE )
    );



    // prepare each discovery profile.
    for ( dwIndex = 0; dwIndex < dwIHVNumProfiles; dwIndex++ )
    {
        dwResult =
        CopyDiscoveryProfile
        (
            g_IhvDiscoveryProfiles + dwIndex,
            pIhvDiscoveryProfileList->pIhvDiscoveryProfiles + dwIndex
        );
        BAIL_ON_WIN32_ERROR( dwResult );

    }

    pIhvDiscoveryProfileList->dwCount = dwIHVNumProfiles;
    (*pdwReasonCode) = L2_REASON_CODE_SUCCESS;

error:
    if ( ERROR_SUCCESS != dwResult )
    {
        if ( pIhvDiscoveryProfileList->pIhvDiscoveryProfiles )
        {
            for ( dwIndex = 0; dwIndex < dwIHVNumProfiles; dwIndex++ )
            {
                FreeDiscoveryProfile( pIhvDiscoveryProfileList->pIhvDiscoveryProfiles + dwIndex );
            }
            (g_pDot11ExtApi->Dot11ExtFreeBuffer)( pIhvDiscoveryProfileList->pIhvDiscoveryProfiles );
        }
        pIhvDiscoveryProfileList->dwCount = 0;
    }
    return dwResult;
}



//
// Process UI Response function.
//
DWORD
WINAPI
IhvProcessUIResponse
(
   IN    GUID        guidUIRequest,
   IN    DWORD       dwByteCount,
   IN    LPVOID      pvResponseBuffer
)
{
    DWORD                   dwResult        =   ERROR_SUCCESS;
    BOOL                    bLocked         =   FALSE;
    PADAPTER_DETAILS        pAdapterDetails =   NULL;
    HANDLE                  hIhvExtAdapter  =   NULL;

    if ( !( dwByteCount && pvResponseBuffer ) )
    {
        dwResult = ERROR_INVALID_PARAMETER;
        BAIL_ON_WIN32_ERROR( dwResult );
    }

    EnterCriticalSection( &g_csSynch );
    bLocked = TRUE;

    // find the adapter from the UI response guid.
    dwResult =
    ReferenceAdapterDetailsByUIRequestGuid
    (
        &guidUIRequest,
        &pAdapterDetails,
        &hIhvExtAdapter
    );
    BAIL_ON_WIN32_ERROR( dwResult );
    ASSERT( pAdapterDetails );

    ZeroMemory( &(pAdapterDetails->currentGuidUIRequest), sizeof( GUID ) );

    // Copy the UI response to the adapter data structure.
    PrivateMemoryFree( pAdapterDetails->pbResponse );

    pAdapterDetails->pbResponse = (BYTE*) PrivateMemoryAlloc( dwByteCount );
    if ( !(pAdapterDetails->pbResponse) )
    {
        dwResult = ERROR_OUTOFMEMORY;
        BAIL_ON_WIN32_ERROR(dwResult);
    }
    CopyMemory( pAdapterDetails->pbResponse, pvResponseBuffer, dwByteCount );

    (pAdapterDetails->dwResponseLen) = dwByteCount;

    // Waiting thread can pick up the response now.
    SetEvent( pAdapterDetails->hUIResponse );

error:
    if ( pAdapterDetails )
    {
        DerefenceAdapterDetails( hIhvExtAdapter );
    }
    if ( bLocked )
    {
        LeaveCriticalSection( &g_csSynch );
    }
    return dwResult;
}




//
// Handler to clear memory after sending packet.
//
DWORD
WINAPI
IhvSendPacketCompletion
(
   IN    HANDLE   hSendCompletion
)
{
    // The sample is not sending any packets.
    // So send packet completion should
    // not be called.
    ASSERTFAILURE();

    // The freeing function used here
    // should be the reverse of the function
    // used to allocate memory before calling
    // Send Packet.
    PrivateMemoryFree( (LPVOID) hSendCompletion );
    return ERROR_SUCCESS;
}




//
// Function to return UI Request on OS query.
//
DWORD
WINAPI
IhvQueryUIRequest
(
   IN    HANDLE                        hIhvExtAdapter,
   IN    DOT11EXT_IHV_CONNECTION_PHASE connectionPhase,
   OUT   PDOT11EXT_IHV_UI_REQUEST*     ppIhvUIRequest
)
{
    // This IHV handler is a post Vista extensibility point.
    // It is currently unused.
    ASSERTFAILURE();

    UNREFERENCED_PARAMETER( hIhvExtAdapter );
    UNREFERENCED_PARAMETER( connectionPhase );
    UNREFERENCED_PARAMETER( ppIhvUIRequest );

    return ERROR_CALL_NOT_IMPLEMENTED;
}




//
// Handler to receive the Onex Result.
//
DWORD
WINAPI
IhvOnexIndicateResult
(
   IN    HANDLE                           hIhvExtAdapter,
   IN    DOT11_MSONEX_RESULT              msOneXResult,
   IN    PDOT11_MSONEX_RESULT_PARAMS      pDot11MsOneXResultParams
)
{
    DWORD               dwResult        =   ERROR_SUCCESS;
    BOOL                bLocked         =   FALSE;
    PADAPTER_DETAILS    pAdapterDetails =   NULL;


    EnterCriticalSection( &g_csSynch );
    bLocked = TRUE;


    dwResult =
    ReferenceAdapterDetails
    (
        hIhvExtAdapter,
        &pAdapterDetails
    );
    BAIL_ON_WIN32_ERROR( dwResult );
    ASSERT( pAdapterDetails );


    // If indication of result is required.
    if ( pAdapterDetails->pOnexData && pAdapterDetails->pOnexData->lpfnIndicateResult )
    {
        dwResult =
        (pAdapterDetails->pOnexData->lpfnIndicateResult)
        (
            pAdapterDetails,
            msOneXResult,
            pDot11MsOneXResultParams
        );
        BAIL_ON_WIN32_ERROR( dwResult );

    }
    else
    {
        dwResult = ERROR_INVALID_STATE;
        BAIL_ON_WIN32_ERROR( dwResult );
    }

error:
    if ( pAdapterDetails )
    {
        DerefenceAdapterDetails( hIhvExtAdapter );
    }
    if ( bLocked )
    {
        LeaveCriticalSection( &g_csSynch );
    }
    return dwResult;
}





//
// Handler to receive Control.
//
DWORD
WINAPI
IhvControl
(
   IN    HANDLE    hIhvExtAdapter,
   IN    DWORD     dwInBufferSize,
   IN    PBYTE     pInBuffer,
   IN    DWORD     dwOutBufferSize,
   OUT   PBYTE     pOutBuffer,
   OUT   PDWORD    pdwBytesReturned
)
{
    // Sample does not demonstrate use of IHV control.

    UNREFERENCED_PARAMETER( hIhvExtAdapter );
    UNREFERENCED_PARAMETER( dwInBufferSize );
    UNREFERENCED_PARAMETER( pInBuffer );
    UNREFERENCED_PARAMETER( dwOutBufferSize );
    UNREFERENCED_PARAMETER( pOutBuffer );
    UNREFERENCED_PARAMETER( pdwBytesReturned );

    return ERROR_SUCCESS;
}