Annotation of ntddk/src/network/packet/driver/openclos.c, revision 1.1.1.1

1.1       root        1: /*++
                      2: 
                      3: Copyright (c) 1990  Microsoft Corporation
                      4: 
                      5: Module Name:
                      6: 
                      7:     packet.c
                      8: 
                      9: Abstract:
                     10: 
                     11: 
                     12: Author:
                     13: 
                     14: 
                     15: Environment:
                     16: 
                     17:     Kernel mode only.
                     18: 
                     19: Notes:
                     20: 
                     21: 
                     22: Future:
                     23: 
                     24: 
                     25: 
                     26: Revision History:
                     27: 
                     28: --*/
                     29: 
                     30: #include "stdarg.h"
                     31: #include "ntddk.h"
                     32: #include "ntiologc.h"
                     33: #include "ndis.h"
                     34: 
                     35: #include "debug.h"
                     36: #include "packet.h"
                     37: 
                     38: 
                     39: 
                     40: 
                     41: NTSTATUS
                     42: PacketOpen(
                     43:     IN PDEVICE_OBJECT DeviceObject,
                     44:     IN PIRP Irp
                     45:     )
                     46: 
                     47: /*++
                     48: 
                     49: Routine Description:
                     50: 
                     51:     This is the dispatch routine for create/open and close requests.
                     52:     These requests complete successfully.
                     53: 
                     54: Arguments:
                     55: 
                     56:     DeviceObject - Pointer to the device object.
                     57: 
                     58:     Irp - Pointer to the request packet.
                     59: 
                     60: Return Value:
                     61: 
                     62:     Status is returned.
                     63: 
                     64: --*/
                     65: 
                     66: {
                     67: 
                     68:     PDEVICE_EXTENSION DeviceExtension;
                     69: 
                     70:     NDIS_STATUS     Status;
                     71:     NDIS_STATUS     ErrorStatus;
                     72:     UINT            Medium;
                     73:     NDIS_MEDIUM     MediumArray=NdisMedium802_3;
                     74: 
                     75:     IF_LOUD(DbgPrint("Packet: OpenAdapter\n");)
                     76: 
                     77:     DeviceExtension = DeviceObject->DeviceExtension;
                     78: 
                     79:     //
                     80:     //  Save the Irp here. This should be ok as I have opened this
                     81:     //  device as exclusive
                     82:     //
                     83:     DeviceExtension->OpenCloseIrp=Irp;
                     84: 
                     85:     IoMarkIrpPending(Irp);
                     86:     Irp->IoStatus.Status = STATUS_PENDING;
                     87: 
                     88:     //
                     89:     //  Try to open the MAC
                     90:     //
                     91:     NdisOpenAdapter(
                     92:         &Status,
                     93:         &ErrorStatus,
                     94:         &DeviceExtension->AdapterHandle,
                     95:         &Medium,
                     96:         &MediumArray,
                     97:         1,
                     98:         DeviceExtension->NdisProtocolHandle,
                     99:         DeviceExtension,
                    100:         &DeviceExtension->AdapterName,
                    101:         0,
                    102:         NULL);
                    103: 
                    104: 
                    105:     if (Status != NDIS_STATUS_PENDING) {
                    106: 
                    107:         PacketOpenAdapterComplete(
                    108:             DeviceExtension,
                    109:             Status,
                    110:             NDIS_STATUS_SUCCESS
                    111:             );
                    112: 
                    113: 
                    114:     }
                    115: 
                    116: 
                    117: 
                    118:     return(STATUS_PENDING);
                    119: 
                    120: }
                    121: 
                    122: 
                    123: 
                    124: 
                    125: 
                    126: 
                    127: 
                    128: 
                    129: 
                    130: 
                    131: VOID
                    132: PacketOpenAdapterComplete(
                    133:     IN NDIS_HANDLE  ProtocolBindingContext,
                    134:     IN NDIS_STATUS  Status,
                    135:     IN NDIS_STATUS  OpenErrorStatus
                    136:     )
                    137: 
                    138: {
                    139: 
                    140:     PDEVICE_EXTENSION DeviceExtension;
                    141:     PIRP              Irp;
                    142: 
                    143:     IF_LOUD(DbgPrint("Packet: OpenAdapterComplete\n");)
                    144: 
                    145:     DeviceExtension= (PDEVICE_EXTENSION)ProtocolBindingContext;
                    146:     Irp=DeviceExtension->OpenCloseIrp;
                    147: 
                    148:     Irp->IoStatus.Status = Status;
                    149:     IoCompleteRequest(Irp, IO_NO_INCREMENT);
                    150: 
                    151:     return;
                    152: 
                    153: }
                    154: 
                    155: 
                    156: 
                    157: 
                    158: NTSTATUS
                    159: PacketClose(
                    160:     IN PDEVICE_OBJECT DeviceObject,
                    161:     IN PIRP Irp
                    162:     )
                    163: 
                    164: /*++
                    165: 
                    166: Routine Description:
                    167: 
                    168:     This is the dispatch routine for create/open and close requests.
                    169:     These requests complete successfully.
                    170: 
                    171: Arguments:
                    172: 
                    173:     DeviceObject - Pointer to the device object.
                    174: 
                    175:     Irp - Pointer to the request packet.
                    176: 
                    177: Return Value:
                    178: 
                    179:     Status is returned.
                    180: 
                    181: --*/
                    182: 
                    183: {
                    184: 
                    185:     PDEVICE_EXTENSION DeviceExtension;
                    186: 
                    187:     NDIS_STATUS     Status;
                    188: 
                    189:     IF_LOUD(DbgPrint("Packet: CloseAdapter\n");)
                    190: 
                    191:     DeviceExtension = DeviceObject->DeviceExtension;
                    192: 
                    193:     //
                    194:     //  Save the IRP
                    195:     //
                    196:     DeviceExtension->OpenCloseIrp=Irp;
                    197: 
                    198:     IoMarkIrpPending(Irp);
                    199:     Irp->IoStatus.Status = STATUS_PENDING;
                    200: 
                    201:     NdisCloseAdapter(
                    202:         &Status,
                    203:         DeviceExtension->AdapterHandle
                    204:         );
                    205: 
                    206: 
                    207:     if (Status != NDIS_STATUS_PENDING) {
                    208: 
                    209:         PacketCloseAdapterComplete(
                    210:             DeviceExtension,
                    211:             Status
                    212:             );
                    213: 
                    214: 
                    215:     }
                    216: 
                    217: 
                    218: 
                    219:     return(STATUS_PENDING);
                    220: 
                    221: }
                    222: 
                    223: 
                    224: 
                    225: 
                    226: 
                    227: VOID
                    228: PacketCloseAdapterComplete(
                    229:     IN NDIS_HANDLE  ProtocolBindingContext,
                    230:     IN NDIS_STATUS  Status
                    231:     )
                    232: 
                    233: {
                    234:     PDEVICE_EXTENSION DeviceExtension;
                    235:     PIRP              Irp;
                    236: 
                    237:     IF_LOUD(DbgPrint("Packet: CloseAdapterComplete\n");)
                    238: 
                    239:     DeviceExtension= (PDEVICE_EXTENSION)ProtocolBindingContext;
                    240: 
                    241:     Irp=DeviceExtension->OpenCloseIrp;
                    242: 
                    243:     Irp->IoStatus.Status = STATUS_SUCCESS;
                    244:     IoCompleteRequest(Irp, IO_NO_INCREMENT);
                    245: 
                    246:     return;
                    247: 
                    248: }
                    249: 
                    250: 
                    251: 
                    252: 
                    253: 
                    254: 
                    255: 
                    256: 
                    257: 
                    258: 
                    259: 
                    260: NTSTATUS
                    261: PacketCleanup(
                    262:     IN PDEVICE_OBJECT DeviceObject,
                    263:     IN PIRP FlushIrp
                    264:     )
                    265: 
                    266: /*++
                    267: 
                    268: Routine Description:
                    269: 
                    270:     This is the dispatch routine for create/open and close requests.
                    271:     These requests complete successfully.
                    272: 
                    273: Arguments:
                    274: 
                    275:     DeviceObject - Pointer to the device object.
                    276: 
                    277:     Irp - Pointer to the request packet.
                    278: 
                    279: Return Value:
                    280: 
                    281:     Status is returned.
                    282: 
                    283: --*/
                    284: 
                    285: {
                    286: 
                    287:     PDEVICE_EXTENSION   DeviceExtension;
                    288:     PLIST_ENTRY         PacketListEntry;
                    289:     PNDIS_PACKET        pPacket;
                    290:     NDIS_STATUS         Status;
                    291: 
                    292:     IF_LOUD(DbgPrint("Packet: Cleanup\n");)
                    293: 
                    294:     DeviceExtension = DeviceObject->DeviceExtension;
                    295: 
                    296:     //
                    297:     //  The open instance of the device is about to close
                    298:     //  We need to complete all pending Irp's
                    299:     //  First we complete any pending read requests
                    300:     //
                    301:     while ((PacketListEntry=ExInterlockedRemoveHeadList(
                    302:                                 &DeviceExtension->RcvList,
                    303:                                 &DeviceExtension->RcvQSpinLock
                    304:                                 )) != NULL) {
                    305: 
                    306:         IF_LOUD(DbgPrint("Packet: CleanUp - Completeing read\n");)
                    307: 
                    308:         pPacket=CONTAINING_RECORD(PacketListEntry,NDIS_PACKET,ProtocolReserved);
                    309: 
                    310:         //
                    311:         //  complete normally
                    312:         //
                    313:         PacketTransferDataComplete(
                    314:             DeviceExtension,
                    315:             pPacket,
                    316:             NDIS_STATUS_SUCCESS,
                    317:             0
                    318:             );
                    319: 
                    320: 
                    321:     }
                    322: 
                    323:     IoMarkIrpPending(FlushIrp);
                    324:     FlushIrp->IoStatus.Status = STATUS_PENDING;
                    325: 
                    326:     //
                    327:     //  We now place the Irp on the Reset list
                    328:     //
                    329:     ExInterlockedInsertTailList(
                    330:             &DeviceExtension->ResetIrpList,
                    331:             &FlushIrp->Tail.Overlay.ListEntry,
                    332:             &DeviceExtension->DeviceSpinLock);
                    333: 
                    334: 
                    335:     //
                    336:     //  Now reset the adapter, the mac driver will complete any
                    337:     //  pending requests we have made to it.
                    338:     //
                    339:     NdisReset(
                    340:         &Status,
                    341:         DeviceExtension->AdapterHandle
                    342:         );
                    343: 
                    344: 
                    345:     if (Status != NDIS_STATUS_PENDING) {
                    346: 
                    347:         IF_LOUD(DbgPrint("Packet: Cleanup - ResetComplte being called\n");)
                    348: 
                    349:         PacketResetComplete(
                    350:             DeviceExtension,
                    351:             Status
                    352:             );
                    353: 
                    354: 
                    355:     }
                    356: 
                    357: 
                    358: 
                    359:     return(STATUS_PENDING);
                    360: 
                    361: 
                    362: }
                    363: 
                    364: 
                    365: 
                    366: VOID
                    367: PacketResetComplete(
                    368:     IN NDIS_HANDLE  ProtocolBindingContext,
                    369:     IN NDIS_STATUS  Status
                    370:     )
                    371: 
                    372: {
                    373:     PDEVICE_EXTENSION   DeviceExtension;
                    374:     PIRP                Irp;
                    375: 
                    376:     PLIST_ENTRY         ResetListEntry;
                    377: 
                    378:     IF_LOUD(DbgPrint("Packet: PacketResetComplte\n");)
                    379: 
                    380:     DeviceExtension= (PDEVICE_EXTENSION)ProtocolBindingContext;
                    381: 
                    382:     //
                    383:     //  remove the reset IRP from the list
                    384:     //
                    385:     ResetListEntry=ExInterlockedRemoveHeadList(&DeviceExtension->ResetIrpList,
                    386:                                                 &DeviceExtension->DeviceSpinLock);
                    387: 
                    388: #if DBG
                    389:     if (ResetListEntry == NULL) {
                    390:         DbgBreakPoint();
                    391:         return;
                    392:     }
                    393: #endif
                    394: 
                    395:     Irp=CONTAINING_RECORD(ResetListEntry,IRP,Tail.Overlay.ListEntry);
                    396: 
                    397:     Irp->IoStatus.Status = STATUS_SUCCESS;
                    398:     IoCompleteRequest(Irp, IO_NO_INCREMENT);
                    399: 
                    400:     IF_LOUD(DbgPrint("Packet: PacketResetComplte exit\n");)
                    401: 
                    402:     return;
                    403: 
                    404: }
                    405: 
                    406: 
                    407: 
                    408: 
                    409: NTSTATUS
                    410: PacketShutdown(
                    411:     IN PDEVICE_OBJECT DeviceObject,
                    412:     IN PIRP Irp
                    413:     )
                    414: 
                    415: /*++
                    416: 
                    417: Routine Description:
                    418: 
                    419:     This is the dispatch routine for create/open and close requests.
                    420:     These requests complete successfully.
                    421: 
                    422: Arguments:
                    423: 
                    424:     DeviceObject - Pointer to the device object.
                    425: 
                    426:     Irp - Pointer to the request packet.
                    427: 
                    428: Return Value:
                    429: 
                    430:     Status is returned.
                    431: 
                    432: --*/
                    433: 
                    434: {
                    435: 
                    436:     PDEVICE_EXTENSION   DeviceExtension;
                    437: 
                    438:     IF_LOUD(DbgPrint("Packet: Shutdown\n");)
                    439: 
                    440:     DeviceExtension = DeviceObject->DeviceExtension;
                    441: 
                    442:     Irp->IoStatus.Status = STATUS_UNSUCCESSFUL;
                    443:     return STATUS_UNSUCCESSFUL;
                    444: 
                    445: 
                    446: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.