summaryrefslogtreecommitdiffstats
path: root/private/nw/rdr/callback.c
blob: 7228813ea68ad0b8b1f1f5126244fe8a4f5d0798 (plain) (blame)
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
/*++

Copyright (c) 1993  Microsoft Corporation

Module Name:

    callback.c

Abstract:

    This module implements NCP Response callback routines.

Author:

    Manny Weiser    [MannyW]    3-Mar-1993

Revision History:

--*/

#include "procs.h"

#define Dbg                              (DEBUG_TRACE_EXCHANGE)

#ifdef ALLOC_PRAGMA
#ifndef QFE_BUILD
#pragma alloc_text( PAGE1, SynchronousResponseCallback )
#pragma alloc_text( PAGE1, AsynchResponseCallback )
#endif
#endif

#if 0  // Not pageable

// see ifndef QFE_BUILD above

#endif


NTSTATUS
SynchronousResponseCallback (
    IN PIRP_CONTEXT pIrpContext,
    IN ULONG BytesAvailable,
    IN PUCHAR RspData
    )
/*++

Routine Description:

    This routine is the callback routine for an NCP which has no
    return parameters and the caller blocks waiting for a response.

Arguments:

    pIrpContext - A pointer to the context information for this IRP.

    BytesAvailable - Actual number of bytes in the received message.

    RspData - Points to the receive buffer.

Return Value:

    NTSTATUS - Status of the operation.

--*/

{
    PEPrequest  *pNcpHeader;
    PEPresponse *pNcpResponse;

    DebugTrace( 0, Dbg, "SynchronousResponseCallback\n", 0 );
    ASSERT( pIrpContext->pNpScb->Requests.Flink == &pIrpContext->NextRequest );

    if ( BytesAvailable == 0) {

        //
        //  No response from server. Status is in pIrpContext->
        //  ResponseParameters.Error
        //

#ifdef MSWDBG
        ASSERT( pIrpContext->Event.Header.SignalState == 0 );
        pIrpContext->DebugValue = 0x103;
#endif
        pIrpContext->pOriginalIrp->IoStatus.Status = STATUS_REMOTE_NOT_LISTENING;
        NwSetIrpContextEvent( pIrpContext );

        return STATUS_REMOTE_NOT_LISTENING;
    }

    pIrpContext->ResponseLength = BytesAvailable;

    //
    //  Simply copy the data into the response buffer, if it is not
    //  already there (because we used an IRP to receive the data).
    //

    if ( RspData != pIrpContext->rsp ) {
        CopyBufferToMdl( pIrpContext->RxMdl, 0, RspData, pIrpContext->ResponseLength );
    }

    //
    // Remember the returned error code.
    //

    pNcpHeader = (PEPrequest *)pIrpContext->rsp;
    pNcpResponse = (PEPresponse *)(pNcpHeader + 1);

    pIrpContext->ResponseParameters.Error = pNcpResponse->error;

    //
    //  Tell the caller that the response has been received.
    //

#ifdef MSWDBG
    ASSERT( pIrpContext->Event.Header.SignalState == 0 );
    pIrpContext->DebugValue = 0x104;
#endif

    pIrpContext->pOriginalIrp->IoStatus.Status = STATUS_SUCCESS;
    pIrpContext->pOriginalIrp->IoStatus.Information = BytesAvailable;

    NwSetIrpContextEvent( pIrpContext );
    return STATUS_SUCCESS;
}

NTSTATUS
AsynchResponseCallback (
    IN PIRP_CONTEXT pIrpContext,
    IN ULONG BytesAvailable,
    IN PUCHAR RspData
    )
/*++

Routine Description:

    This routine is the callback routine for an NCP which has no
    return parameters and the caller DOES NOT BLOCK waiting for a
    response.

Arguments:

    pIrpContext - A pointer to the context information for this IRP.

    BytesAvailable - Actual number of bytes in the received message.

    RspData - Points to the receive buffer.

Return Value:

    NTSTATUS - Status of the operation.

--*/

{
    NTSTATUS Status;

    if ( BytesAvailable == 0) {

        //
        //  No response from server. Status is in pIrpContext->
        //  ResponseParameters.Error
        //

        Status = STATUS_REMOTE_NOT_LISTENING;

    } else {

        if ( ((PNCP_RESPONSE)RspData)->Status != 0 ) {

            Status = STATUS_LINK_FAILED;

        } else {

            Status = NwErrorToNtStatus( ((PNCP_RESPONSE)RspData)->Error );

        }
    }

    //
    //  We're done with this request.  Dequeue the IRP context from
    //  SCB and complete the request.
    //

    NwDequeueIrpContext( pIrpContext, FALSE );
    NwCompleteRequest( pIrpContext, Status );

    return STATUS_SUCCESS;
}