summaryrefslogtreecommitdiff
path: root/network/wwan/cxwmbclass/inc/BusInterface.h
blob: 819f93e5744f4a194a8c67ce8c0d1845f41e88ac (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
/***************************************************************************

Copyright (c) 2010 Microsoft Corporation

Module Name:

    BusInterface.h

Abstract:

    This module defines the interface between the upper NDIS layer and lower
    bus layer of the MBB (Mobile BroadBand) Class driver.

Environment:

    kernel mode only

Notes:

    The upper ndis layer may only communicate with the lower bus layer through
    these interfaces.

Revision History:

    2/7/2010 : created

Authors:

    TriRoy

****************************************************************************/

#ifndef _BusInterface_H_
#define _BusInterface_H_

////////////////////////////////////////////////////////////////////////////////
//
//  INCLUDES
//
////////////////////////////////////////////////////////////////////////////////
#if 0
#include "MbbDebug.h"
#endif
////////////////////////////////////////////////////////////////////////////////
//
//  DEFINES
//
////////////////////////////////////////////////////////////////////////////////

#define MAX_PARAMETER_STRING (128)

#define ALT_DATA_SETTING_0 (0)
#define ALT_DATA_SETTING_1 (1)

#define MAX_PENDING_SENDS (3)

////////////////////////////////////////////////////////////////////////////////
//
//  TYPEDEFS
//
////////////////////////////////////////////////////////////////////////////////
typedef PVOID MBB_BUS_HANDLE;
typedef PVOID MBB_PROTOCOL_HANDLE;
typedef PVOID MBB_REQUEST_HANDLE;
typedef PVOID MBB_RECEIVE_CONTEXT;

typedef struct _MBB_BUS_PARAMETERS
{
    ULONG FragmentSize;

    ULONG MaxSegmentSize;

    BOOLEAN ChainedMdlsSupported;
    BOOLEAN Ntb32BitSupported;
    BOOLEAN CurrentMode32Bit;
    BOOLEAN SelectiveSuspendSupported;

    ULONG MaxOutNtb;
    USHORT MaxOutDatagrams;
    USHORT NdpOutDivisor;
    USHORT NdpOutRemainder;
    USHORT NdpOutAlignment;

    BYTE PowerFiltersSupported;
    BYTE MaxPowerFilterSize;

    WCHAR Manufacturer[MAX_PARAMETER_STRING];
    WCHAR Model[MAX_PARAMETER_STRING];

    BYTE MaxOutstandingCommandMessages;
    USHORT MTU;
    BOOLEAN IsErrataDevice;
    USHORT MbimVersion;
    BOOLEAN RemoteWakeCapable;
    USHORT MbimExtendedVersion;

} MBB_BUS_PARAMETERS, *PMBB_BUS_PARAMETERS;

typedef struct _MBB_CONNECTION_STATE
{

    BOOLEAN ConnectionUp;
    ULONGLONG UpStreamBitRate;
    ULONGLONG DownStreamBitRate;

} MBB_CONNECTION_STATE, *PMBB_CONNECTION_STATE;

typedef __callback VOID (*MBB_BUS_SEND_COMPLETION_CALLBACK)(__in MBB_PROTOCOL_HANDLE ProtocolHandle, __in MBB_REQUEST_HANDLE RequestHandle, __in NTSTATUS Status);

typedef __callback VOID (*MBB_BUS_RECEIVE_COMPLETION_CALLBACK)(
    __in MBB_PROTOCOL_HANDLE ProtocolHandle, __in MBB_REQUEST_HANDLE RequestHandle, __in NTSTATUS Status, __in ULONG_PTR ReceivedLength);

typedef __callback VOID (*MBB_BUS_RESPONSE_AVAILABLE_CALLBACK)(__in MBB_PROTOCOL_HANDLE ProtocolHandle);

typedef __callback VOID (*MBB_BUS_SEND_DATA_COMPLETION_CALLBACK)(
    __in MBB_PROTOCOL_HANDLE ProtocolHandle, __in MBB_REQUEST_HANDLE RequestHandle, __in NTSTATUS Status, __in PMDL Mdl);

typedef __callback VOID (*MBB_BUS_DATA_RECEIVE_CALLBACK)(__in MBB_PROTOCOL_HANDLE ProtocolHandle, __in MBB_RECEIVE_CONTEXT ReceiveContext, __in PMDL Mdl);

typedef __callback VOID (*MBB_BUS_SS_IDLE_CONFIRM_CALLBACK)(__in MBB_PROTOCOL_HANDLE ProtocolHandle, __in DEVICE_POWER_STATE PowerState);

typedef __callback VOID (*MBB_BUS_SS_IDLE_NOTIFICATION_COMPLETE_CALLBACK)(__in MBB_PROTOCOL_HANDLE ProtocolHandle, __in NTSTATUS Status);

////////////////////////////////////////////////////////////////////////////////
//
//  INTERFACE
//
////////////////////////////////////////////////////////////////////////////////
EXTERN_C
NTSTATUS
MbbBusInitialize(
    _In_ PDEVICE_OBJECT Pdo,
    _In_ PDEVICE_OBJECT Fdo,
    _In_ PDEVICE_OBJECT NextDeviceObject,
    _In_ MBB_BUS_RESPONSE_AVAILABLE_CALLBACK ResponseAvailableCallback,
    _In_ MBB_BUS_DATA_RECEIVE_CALLBACK ReceiveDataCallback,
    _In_ MBB_BUS_SS_IDLE_CONFIRM_CALLBACK IdleConfirmCallback,
    _In_ MBB_BUS_SS_IDLE_NOTIFICATION_COMPLETE_CALLBACK IdleNotificationComplete,
    _In_ MBB_PROTOCOL_HANDLE ProtocolHandle,
    _Outptr_ MBB_BUS_HANDLE* BusHandle);
/*
    Description
        This routine initializes the bus layer i.e. the lower layer in the
        MBB Class Driver. All bus layer implementations need to have this
        function. The Protocol Layer i.e. the upper layer in the MBB Class
        Driver will call this function before calling any other function in
        the Bus Layer.

    Parameters
        _In_     PDEVICE_OBJECT      DeviceObject,
            The WDM device representation of the device.

        _In_     MBB_BUS_NOTIFICATION_CALLBACK NotificationCallback,
            The routine the bus layer calls when it needs to notify
            the upper protocol layer.

        _In_     MBB_PROTOCOL_HANDLE ProtocolHandle,
            The handle the bus layer passes back to the protocol layer
            when it calls any callback. The protocol layer uses this handle
            to identify the instance of the MBB device the callback is meant for.

        _Outptr_ MBB_BUS_HANDLE      BusHandle
            The handle returned by the bus layer on successful initialization.
            The protocol layer passes this handle to the bus layer on subsequent
            calls to the bus layer. The bus layer uses this handle to indetify
            the instance of the MBB device.

    Return Value
        NTSTATUS_SUCCESS
            Initialization was successful.

        Other failure code
*/

EXTERN_C
NTSTATUS
MbbBusInitializeByWdf(
    _In_ WDFDEVICE WdfDevice,
    _In_ MBB_BUS_RESPONSE_AVAILABLE_CALLBACK ResponseAvailableCallback,
    _In_ MBB_BUS_DATA_RECEIVE_CALLBACK ReceiveDataCallback,
    _In_ MBB_BUS_SS_IDLE_CONFIRM_CALLBACK IdleConfirmCallback,
    _In_ MBB_BUS_SS_IDLE_NOTIFICATION_COMPLETE_CALLBACK IdleNotificationComplete,
    _In_ MBB_PROTOCOL_HANDLE ProtocolHandle,
    _Outptr_ MBB_BUS_HANDLE* BusHandle,
    _Inout_opt_ MBB_BUS_HANDLE preAllocatedBusObject);

EXTERN_C
VOID MbbBusCleanup(__in MBB_BUS_HANDLE BusHandle);
/*
    Description
        This will be last call from Protocol layer in to Bus Layer
        to cleanup the bus layer. The bus layer should free all
        resources. The BusHandle will not be used for subsequent calls.
        If there are pending requests the Bus Layer should not return
        from this call unless all operations are complete.

    Parameters
        __in    MBB_BUS_HANDLE      BusHandle
            BusHandle identifies the instance of the bus layer.

    Return Value
        None
*/

EXTERN_C
NTSTATUS
MbbBusQueryBusParameters(__in MBB_BUS_HANDLE BusHandle, __out PMBB_BUS_PARAMETERS BusParameters);
/*
    Description
        This routine queries the bus specific parameters like transfer size,
        DMA support etc... This is called when the bus is initialized to format
        requests correctly before sending to the bus.

    Parameters
        __in    MBB_BUS_HANDLE      BusHandle,
            BusHandle identifies the instance of the bus layer.

        __out   PMBB_BUS_PARAMETERS BusParameters
            The buffer where the bus layer returns the information to the caller.


    Return Value

        NTSTATUS_SUCCESS
            Information was successfully returned in the BusParameters structure.

        NTSTATUS_INVALID_PARAMETER
            One of the required parameters is missing or bad.

        Other failure code
*/
EXTERN_C
NTSTATUS
MbbBusSendMessageFragment(
    __in MBB_BUS_HANDLE BusHandle,
    __in MBB_REQUEST_HANDLE RequestHandle,
    __in PVOID MessageFragment,
    __in ULONG FragmentLength,
    __in LPGUID ActivityId,
    __in MBB_BUS_SEND_COMPLETION_CALLBACK SendCompletionCallback);
/*
    Description
        The protocol layer call this routine to request the bus layer to
        send a message fragment. Fragmentation / Reassembly is handled by
        the protocol layer and it will only handle fragments that are within
        the maximum transfer size of the bus.

        This routine is asynchronous and returns immediately after queueing
        the transfer. The caller is notified of the completion through the
        callback.

    Parameters
        __in MBB_BUS_HANDLE BusHandle,
            BusHandle identifies the instance of the bus layer.

        __in MBB_REQUEST_HANDLE RequestHandle,
            Identifies the request.

        __in PVOID MessageFragment,
            The data payload that needs to be sent.

        __in ULONG FragmentLength,
            Length of the data payload. This will not be greater than the
            maximum transfer size supported by the bus.

        __in MBB_BUS_SEND_COMPLETION_CALLBACK SendCompletionCallback
            The completion callback routine that will be called by the bus
            when the transfer is complete.

    Return Value

        NTSTATUS_SUCCESS
            The transfer has completed successfully. SendCompletionCallback will NOT be called.

        NTSTATUS_PENDING
            The transfer was queued. SendCompletionCallback will be called on completion.

        Other failure code
            The transfer could not be queued. SendCompletionCallback will NOT be called.
*/

EXTERN_C
NTSTATUS
MbbBusReceiveMessageFragment(
    _In_ MBB_BUS_HANDLE BusHandle,
    _In_ MBB_REQUEST_HANDLE RequestHandle,
    _In_ __drv_aliasesMem PVOID MessageFragment,
    _In_ ULONG FragmentLength,
    _In_ LPGUID ActivityId,
    _In_ MBB_BUS_RECEIVE_COMPLETION_CALLBACK ReceiveCompletionCallback);
/*
    Description

    Parameters


    Return Value

        NTSTATUS_SUCCESS
            Initialization was successful.

        Other failure code
*/
/*
    Description
        The protocol layer call this routine to request the bus layer to
        receive data from the device. Reassembly is handled by the protocol layer.

        This routine is asynchronous and returns immediately after queueing
        the transfer. The caller is notified of the completion through the
        callback.

    Parameters
        _In_ MBB_BUS_HANDLE BusHandle,
            BusHandle identifies the instance of the bus layer.

        _In_ MBB_REQUEST_HANDLE RequestHandle,
            Identifies the request.

        _InOut_ PVOID MessageFragment,
            The data buffer that would be filled with the received data.

        _In_ ULONG FragmentLength,
            Length of the data requested from the device. This will not be
            greater than the maximum transfer size supported by the bus.

        _In_ MBB_BUS_RECEIVE_COMPLETION_CALLBACK ReceiveCompletionCallback
            The completion callback routine that will be called by the bus
            when the transfer is complete.

    Return Value

        NTSTATUS_SUCCESS
            The transfer has completed successfully. ReceiveCompletionCallback will NOT be called.

        NTSTATUS_PENDING
            The transfer was queued. ReceiveCompletionCallback will be called on completion.

        Other failure code
            The transfer could not be queued. ReceiveCompletionCallback will NOT be called.
*/

EXTERN_C
NTSTATUS
MbbBusSetPacketFilter(__in MBB_BUS_HANDLE BusHandle, __in ULONG PacketFilter);
/*
    Description
        Sets the packet filter on the device.
        For MBB only directed is supported

    Parameters
        __in    MBB_BUS_HANDLE      BusHandle,
            BusHandle identifies the instance of the bus layer.

        __in ULONG               PacketFilter
            the filter to apply


    Return Value

        NTSTATUS_SUCCESS
            Information was successfully returned in the BusParameters structure.

        NTSTATUS_INVALID_PARAMETER
            One of the required parameters is missing or bad.

        Other failure code
*/

EXTERN_C
NTSTATUS
MbbBusGetStat(__in MBB_BUS_HANDLE BusHandle, __in USHORT StatIndex, __out ULONGLONG* Value);
/*
    Description
        Retrieves a status from the device

    Parameters
        __in    MBB_BUS_HANDLE      BusHandle,
            BusHandle identifies the instance of the bus layer.

        __in ULONG               PacketFilter
            the filter to apply


    Return Value

        NTSTATUS_SUCCESS
            Information was successfully returned in the BusParameters structure.

        NTSTATUS_INVALID_PARAMETER
            One of the required parameters is missing or bad.

        Other failure code
*/

EXTERN_C
NTSTATUS
MbbBusStart(_In_ MBB_BUS_HANDLE BusHandle);

EXTERN_C
NTSTATUS
MbbBusStop(__in MBB_BUS_HANDLE BusHandle);

EXTERN_C
BOOLEAN
MbbBusIsStoped(_In_ MBB_BUS_HANDLE BusHandle);

EXTERN_C
NTSTATUS
MbbBusOpen(_In_ MBB_BUS_HANDLE BusHandle, _In_ ULONG TransactionId, _In_opt_ PVOID FastIOSendNetBufferListsComplete, _In_opt_ PVOID FastIOIndicateReceiveNetBufferLists);
/*
    Description

        Opens the session with the device

    Parameters
        __in    MBB_BUS_HANDLE      BusHandle,
            BusHandle identifies the instance of the bus layer.


    Return Value

        NTSTATUS_SUCCESS
            Information was successfully returned in the BusParameters structure.

        NTSTATUS_INVALID_PARAMETER
            One of the required parameters is missing or bad.

        Other failure code
*/

EXTERN_C
NTSTATUS
MbbBusClose(__in MBB_BUS_HANDLE BusHandle, __in ULONG TransactionId, __in BOOLEAN ForceClose);
/*
    Description

        Opens the session with the device

    Parameters
        __in    MBB_BUS_HANDLE      BusHandle,
            BusHandle identifies the instance of the bus layer.


    Return Value

        NTSTATUS_SUCCESS
            Information was successfully returned in the BusParameters structure.

        NTSTATUS_INVALID_PARAMETER
            One of the required parameters is missing or bad.

        Other failure code
*/

EXTERN_C
NTSTATUS
MbbBusStartDataPipes(__in MBB_BUS_HANDLE BusHandle);
/*
    Description

        Selects alt data interface 1 and starts the IoTargets

    Parameters
        __in    MBB_BUS_HANDLE      BusHandle,
            BusHandle identifies the instance of the bus layer.


    Return Value

        NTSTATUS_SUCCESS
            Information was successfully returned in the BusParameters structure.

        NTSTATUS_INVALID_PARAMETER
            One of the required parameters is missing or bad.

        Other failure code
*/

EXTERN_C
VOID MbbBusStopDataPipes(__in MBB_BUS_HANDLE BusHandle);
/*
    Description

        Resets the IoTargets canceling all and waiting for io to compelte
        Selects alt data interface 0 disabling the pipes

    Parameters
        __in    MBB_BUS_HANDLE      BusHandle,
            BusHandle identifies the instance of the bus layer.


    Return Value

        NTSTATUS_SUCCESS
            Information was successfully returned in the BusParameters structure.

        NTSTATUS_INVALID_PARAMETER
            One of the required parameters is missing or bad.

        Other failure code
*/

EXTERN_C
void MbbBusResetDataPipes(_In_ MBB_BUS_HANDLE BusHandle);

EXTERN_C
NTSTATUS
MbbBusWriteData(__in MBB_BUS_HANDLE BusHandle, __in MBB_REQUEST_HANDLE RequestHandle, __in PMDL Mdl, __in MBB_BUS_SEND_DATA_COMPLETION_CALLBACK Callback);
/*
    Description

        Writes data to device bulk out pipe

    Parameters
        __in    MBB_BUS_HANDLE      BusHandle,
            BusHandle identifies the instance of the bus layer.

        __in MBB_REQUEST_HANDLE RequestHandle,
            Identifies the request.

        __in    PMDL                Mdl
            pointer to an MDL identifying the data to send. The bus layer will own this until the completion callback is called.

        __in    MBB_BUS_SEND_DATA_COMPLETION_CALLBACK   Callback
            Callback that will be called when write is complete.

    Return Value

        NTSTATUS_SUCCESS
            Information was successfully returned in the BusParameters structure.

        NTSTATUS_INVALID_PARAMETER
            One of the required parameters is missing or bad.

        Other failure code
*/
EXTERN_C
VOID MbbBusReturnReceiveBuffer(__in MBB_BUS_HANDLE BusHandle, __in MBB_RECEIVE_CONTEXT ReceiveContext, __in PMDL Mdl);

EXTERN_C
NTSTATUS
MbbBusSelectDataAltSetting(__in MBB_BUS_HANDLE BusHandle, __in UCHAR AltSetting);

EXTERN_C
NTSTATUS
MbbBusIdleNotification(__in MBB_BUS_HANDLE BusHandle, __in BOOLEAN ForceIdle);

EXTERN_C
VOID MbbBusCancelIdleNotification(__in MBB_BUS_HANDLE BusHandle);

EXTERN_C
NTSTATUS
MbbBusSetPowerFilterPattern(
    __in MBB_BUS_HANDLE BusHandle,
    __in ULONG PatternId,
    __in_bcount_opt(MaskSize) PCUCHAR Mask,
    __in ULONG MaskSize,
    __in_bcount_opt(PatternSize) PCUCHAR Pattern,
    __in ULONG PatternSize);

EXTERN_C
NTSTATUS
MbbBusResetBulkPipe(__in MBB_BUS_HANDLE BusHandle, __in BOOLEAN Out);

EXTERN_C
VOID MbbBusSetNotificationState(__in MBB_BUS_HANDLE BusHandle, __in BOOLEAN Enabled);

EXTERN_C
BOOLEAN
MbbBusIsUde(_In_ MBB_BUS_HANDLE BusHandle);

#endif