summaryrefslogtreecommitdiff
path: root/network/wlan/ihvsample/utils.h
blob: d2d4a80c6528d557e29ce289a8a6945ac207ed6e (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


//////////////////
// Macros       //
//////////////////


// Trace Macros


VOID
SampleTraceFn
(
    LPCSTR      pszFormat,
    LPCSTR      pszVal1,
    DWORD       dwVal1
);

#define TRACE_MESSAGE( _x )             SampleTraceFn( "INFO: %s\n",_x, 0 );
#define TRACE_MESSAGE_VAL( _x, _y )     SampleTraceFn( "INFO: %s %lu\n", _x, _y );


//
// Error Handling
//
#define BAIL_ON_WIN32_ERROR( __x )     \
   if ( ERROR_SUCCESS != (__x) )       \
   {                                   \
      goto error;                      \
   }                                   \


//
// COM failure
//
#define BAIL_ON_FAILURE( __hr )     \
   if ( FAILED( __hr ) )            \
   {                                \
      goto error;                   \
   }                                \

//
// combine win32 and com error codes.
//
#define WIN32_FROM_HRESULT(hr)           \
    (SUCCEEDED(hr) ? ERROR_SUCCESS :     \
        (HRESULT_FACILITY(hr) == FACILITY_WIN32 ? HRESULT_CODE(hr) : (hr)))


// Combined Error Macro
#define WIN32_COMBINED_ERROR( _dwError, _hr ) ( (_dwError)?(_dwError):WIN32_FROM_HRESULT((_hr)))

//
// Unconditional bail
//
#define BAIL( ) goto error;


//
// Maximum number of new threads
// to spawn at any given time.
//
#define MAX_THREAD_COUNT 100



//
// Debug Macro.
//
#ifdef DBG
#define ASSERT(exp)                             \
   if (!(exp))                                  \
   {                                            \
      AssertFunc( __FILE__, __LINE__ );         \
   }

#define ASSERTFAILURE()                         \
   AssertFunc( __FILE__, __LINE__ ); 
#else
#define ASSERT(exp)
#define ASSERTFAILURE()
#endif // DBG



// Private Memory alloc function
LPVOID
PrivateMemoryAlloc
(
    size_t  MemSize
);

// Private Memory free function
VOID
PrivateMemoryFree
(
    LPVOID  pvBuffer
);


//
// Array length.
//
#define ARRAY_LENGTH( _x ) (sizeof( (_x) ) / sizeof( (_x)[0] ))

//
// Declarations for service specific global Variables
//
extern  PDOT11EXT_APIS             g_pDot11ExtApi;
extern  CRITICAL_SECTION           g_csSynch;
extern  DWORD                      g_dwThreadCount;
extern  DWORD                      g_dwSessionID;
extern  BOOL                       g_bAllowInit;








// Pre-declaration for the ADAPTER_DETAILS structure.
typedef
struct _ADAPTER_DETAILS
ADAPTER_DETAILS, *PADAPTER_DETAILS;




//
// Handler type for pre-association.
//
typedef
DWORD
(WINAPI *PRE_ASSOCIATE_FUNCTION)
(
    PADAPTER_DETAILS    pAdapterDetails,
    DWORD*              pdwReasonCode
);


//
// Handler type for post-association.
//
typedef
DWORD
(WINAPI *POST_ASSOCIATE_FUNCTION)
(
    PADAPTER_DETAILS                            pAdapterDetails,
    HANDLE                                      hSecuritySessionID,
    PDOT11_PORT_STATE                           pPortState,
    ULONG                                       uDot11AssocParamsBytes,
    PDOT11_ASSOCIATION_COMPLETION_PARAMETERS    pDot11AssocParams
);



//
// Handler type for stop-post-association.
//
typedef
DWORD
(WINAPI *STOP_POST_ASSOCIATE_FUNCTION)
(
    PADAPTER_DETAILS    pAdapterDetails,
    PDOT11_MAC_ADDRESS  pPeer,
    DOT11_ASSOC_STATUS  dot11AssocStatus
);



//
// Handler type for receive packet.
//
typedef
DWORD
(WINAPI *IHV_RECEIVE_PACKET_HANDLER)
(
    PADAPTER_DETAILS    pAdapterDetails,
    DWORD               dwInBufferSize,
    LPVOID              pvInBuffer
);



//
// Handler type for IHV result indication.
//
typedef
DWORD
(WINAPI *IHV_INDICATE_RESULT_HANDLER)
(
    PADAPTER_DETAILS                pAdapterDetails,
    DOT11_MSONEX_RESULT             msOneXResult,
    PDOT11_MSONEX_RESULT_PARAMS     pDot11MsOneXResultParams
);



// Assert function in debug builds.
VOID
AssertFunc
(
    _In_    LPCSTR  pszFile,
            int     nLine
);


//
// Register intention to start shut down.
//
VOID
StartShutdown
(
   VOID
);


//
// Wait for posted thread count to go down to zero.
//
VOID
WaitOnZeroThreads
(
   VOID
);


//
// Populate IHV handler function pointers to IHV Framework.
//
VOID
HandlerInit
(
   OUT   PDOT11EXT_IHV_HANDLERS     pDot11IHVHandlers
);


//
// Call createthread to start a new thread and ensure
// the adapter stays active till the thread finishes
// by putting a refcount increment/decrement around
// the lifetime of the thread.
//
DWORD
StartNewProtectedThread
(
    HANDLE                  hIhvExtAdapter,
    LPTHREAD_START_ROUTINE  pStartRoutine,
    LPVOID                  pvParams
);


// Typedef for unaligned BSS Entry to process beacons.
typedef UNALIGNED DOT11_BSS_ENTRY* PULDOT11_BSS_ENTRY;

//
// Function to match beacon and profile.
//
BOOL
WINAPI
MatchBssDescription
(
    PDOT11EXT_IHV_PROFILE_PARAMS    pIhvProfileParams,
    PIHV_CONNECTIVITY_PROFILE       pConnectivityProfile,
    PIHV_SECURITY_PROFILE           pSecurityProfile,
    PULDOT11_BSS_ENTRY              pBssEntry
);


//
// Functions to copy and free discovery profiles.
//

DWORD
CopyConnectivityProfile
(
    IN      PDOT11EXT_IHV_CONNECTIVITY_PROFILE  pSrc,
    OUT     PDOT11EXT_IHV_CONNECTIVITY_PROFILE  pDst
);


VOID
FreeConnectivityProfile
(
    IN  PDOT11EXT_IHV_CONNECTIVITY_PROFILE  pSrc
);


DWORD
CopySecurityProfile
(
    IN  PDOT11EXT_IHV_SECURITY_PROFILE  pSrc,
    OUT PDOT11EXT_IHV_SECURITY_PROFILE  pDst
);

VOID
FreeSecurityProfile
(
    IN  PDOT11EXT_IHV_SECURITY_PROFILE  pSrc
);



VOID
FreeDiscoveryProfile
(
    IN  PDOT11EXT_IHV_DISCOVERY_PROFILE     pSrc
);



DWORD
CopyDiscoveryProfile
(
    IN  PDOT11EXT_IHV_DISCOVERY_PROFILE     pSrc,
    OUT PDOT11EXT_IHV_DISCOVERY_PROFILE     pDst
);