Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

317 lines
7.6 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. error.c
  5. Abstract:
  6. This module contains code which defines the NetBIOS driver's
  7. translation between Netbios error codes and NTSTATUS codes.
  8. Author:
  9. Colin Watson (ColinW) 28-Mar-1991
  10. Environment:
  11. Kernel mode
  12. Revision History:
  13. --*/
  14. #include "nb.h"
  15. struct {
  16. unsigned char NbError;
  17. NTSTATUS NtStatus;
  18. } Nb_Error_Map[] = {
  19. { NRC_GOODRET , STATUS_SUCCESS},
  20. { NRC_PENDING , STATUS_PENDING},
  21. { NRC_ILLCMD , STATUS_INVALID_DEVICE_REQUEST},
  22. { NRC_BUFLEN , STATUS_INVALID_PARAMETER},
  23. { NRC_CMDTMO , STATUS_IO_TIMEOUT},
  24. { NRC_INCOMP , STATUS_BUFFER_OVERFLOW},
  25. { NRC_INCOMP , STATUS_BUFFER_TOO_SMALL},
  26. { NRC_SNUMOUT , STATUS_INVALID_HANDLE},
  27. { NRC_NORES , STATUS_INSUFFICIENT_RESOURCES},
  28. { NRC_CMDCAN , STATUS_CANCELLED},
  29. { NRC_INUSE , STATUS_DUPLICATE_NAME},
  30. { NRC_NAMTFUL , STATUS_TOO_MANY_NAMES},
  31. { NRC_LOCTFUL , STATUS_TOO_MANY_SESSIONS},
  32. { NRC_REMTFUL , STATUS_REMOTE_NOT_LISTENING},
  33. { NRC_NOCALL , STATUS_BAD_NETWORK_PATH},
  34. { NRC_NOCALL , STATUS_HOST_UNREACHABLE},
  35. { NRC_NOCALL , STATUS_CONNECTION_REFUSED},
  36. { NRC_LOCKFAIL , STATUS_WORKING_SET_QUOTA},
  37. { NRC_SABORT , STATUS_REMOTE_DISCONNECT},
  38. { NRC_SABORT , STATUS_CONNECTION_RESET},
  39. { NRC_SCLOSED , STATUS_LOCAL_DISCONNECT},
  40. { NRC_SABORT , STATUS_LINK_FAILED},
  41. { NRC_DUPNAME , STATUS_SHARING_VIOLATION},
  42. { NRC_SYSTEM , STATUS_UNSUCCESSFUL},
  43. { NRC_BUFLEN , STATUS_ACCESS_VIOLATION},
  44. { NRC_ILLCMD , STATUS_NONEXISTENT_EA_ENTRY}
  45. };
  46. #define NUM_NB_ERRORS sizeof(Nb_Error_Map) / sizeof(Nb_Error_Map[0])
  47. unsigned char
  48. NbMakeNbError(
  49. IN NTSTATUS Error
  50. )
  51. /*++
  52. Routine Description:
  53. This routine converts the NTSTATUS to and NBCB error.
  54. Arguments:
  55. Error - Supplies the NTSTATUS to be converted.
  56. Return Value:
  57. The mapped error.
  58. --*/
  59. {
  60. int i;
  61. for (i=0;i<NUM_NB_ERRORS;i++) {
  62. if (Nb_Error_Map[i].NtStatus == Error) {
  63. IF_NBDBG (NB_DEBUG_ERROR_MAP) {
  64. NbPrint( ("NbMakeNbError %X becomes %x\n",
  65. Error,
  66. Nb_Error_Map[i].NbError));
  67. }
  68. return Nb_Error_Map[i].NbError;
  69. }
  70. }
  71. IF_NBDBG (NB_DEBUG_ERROR_MAP) {
  72. NbPrint( ("NbMakeNbError %X becomes %x\n", Error, NRC_SYSTEM ));
  73. }
  74. return NRC_SYSTEM;
  75. }
  76. NTSTATUS
  77. NbLanStatusAlert(
  78. IN PDNCB pdncb,
  79. IN PIRP Irp,
  80. IN PIO_STACK_LOCATION IrpSp
  81. )
  82. /*++
  83. Routine Description:
  84. This routine is used to save a lan_status_alert NCB for a
  85. particular network adapter.
  86. Arguments:
  87. pdncb - Pointer to the NCB.
  88. Irp - Pointer to the request packet representing the I/O request.
  89. IrpSp - Pointer to current IRP stack frame.
  90. Return Value:
  91. The function value is the status of the operation.
  92. --*/
  93. {
  94. PFCB pfcb = IrpSp->FileObject->FsContext2;
  95. PLANA_INFO plana;
  96. KIRQL OldIrql; // Used when SpinLock held.
  97. IF_NBDBG (NB_DEBUG_LANSTATUS) {
  98. NbPrint(( "\n****** Start of NbLanStatusAlert ****** pdncb %lx\n", pdncb ));
  99. }
  100. LOCK( pfcb, OldIrql );
  101. if ( pdncb->ncb_lana_num > pfcb->MaxLana ) {
  102. UNLOCK( pfcb, OldIrql );
  103. NCB_COMPLETE( pdncb, NRC_BRIDGE );
  104. return STATUS_SUCCESS;
  105. }
  106. if (( pfcb->ppLana[pdncb->ncb_lana_num] == (LANA_INFO *) NULL ) ||
  107. ( pfcb->ppLana[pdncb->ncb_lana_num]->Status != NB_INITIALIZED) ) {
  108. UNLOCK( pfcb, OldIrql );
  109. IF_NBDBG (NB_DEBUG_LANSTATUS) {
  110. NbPrint( (" not found\n"));
  111. }
  112. NCB_COMPLETE( pdncb, NRC_SNUMOUT );
  113. return STATUS_SUCCESS;
  114. }
  115. plana = pfcb->ppLana[pdncb->ncb_lana_num];
  116. QueueRequest(&plana->LanAlertList, pdncb, Irp, pfcb, OldIrql, FALSE);
  117. return STATUS_PENDING;
  118. }
  119. VOID
  120. CancelLanAlert(
  121. IN PFCB pfcb,
  122. IN PDNCB pdncb
  123. )
  124. /*++
  125. Routine Description:
  126. This routine is used to cancel a lan_status_alert NCB for a
  127. particular network adapter.
  128. Arguments:
  129. pfcb - Supplies a pointer to the Fcb that the NCB refers to.
  130. pdncb - Pointer to the NCB.
  131. Return Value:
  132. none.
  133. --*/
  134. {
  135. PLANA_INFO plana;
  136. PLIST_ENTRY Entry;
  137. PLIST_ENTRY NextEntry;
  138. IF_NBDBG (NB_DEBUG_LANSTATUS) {
  139. NbPrint(( "\n****** Start of CancelLanAlert ****** pdncb %lx\n", pdncb ));
  140. }
  141. if ( pdncb->ncb_lana_num > pfcb->MaxLana ) {
  142. NCB_COMPLETE( pdncb, NRC_BRIDGE );
  143. return;
  144. }
  145. if (( pfcb->ppLana[pdncb->ncb_lana_num] == NULL ) ||
  146. ( pfcb->ppLana[pdncb->ncb_lana_num]->Status != NB_INITIALIZED) ) {
  147. NCB_COMPLETE( pdncb, NRC_SNUMOUT );
  148. return;
  149. }
  150. plana = pfcb->ppLana[pdncb->ncb_lana_num];
  151. for (Entry = plana->LanAlertList.Flink ;
  152. Entry != &plana->LanAlertList ;
  153. Entry = NextEntry) {
  154. PDNCB pAnotherNcb;
  155. NextEntry = Entry->Flink;
  156. pAnotherNcb = CONTAINING_RECORD( Entry, DNCB, ncb_next);
  157. IF_NBDBG (NB_DEBUG_LANSTATUS) {
  158. NbDisplayNcb( pAnotherNcb );
  159. }
  160. if ( (PUCHAR)pAnotherNcb->users_ncb == pdncb->ncb_buffer) {
  161. // Found the request to cancel
  162. PIRP Irp;
  163. IF_NBDBG (NB_DEBUG_LANSTATUS) {
  164. NbPrint(( "Found request to cancel\n" ));
  165. }
  166. RemoveEntryList( &pAnotherNcb->ncb_next );
  167. Irp = pAnotherNcb->irp;
  168. IoAcquireCancelSpinLock(&Irp->CancelIrql);
  169. //
  170. // Remove the cancel request for this IRP. If its cancelled then its
  171. // ok to just process it because we will be returning it to the caller.
  172. //
  173. Irp->Cancel = FALSE;
  174. IoSetCancelRoutine(Irp, NULL);
  175. IoReleaseCancelSpinLock(Irp->CancelIrql);
  176. NCB_COMPLETE( pAnotherNcb, NRC_CMDCAN );
  177. Irp->IoStatus.Information = FIELD_OFFSET( DNCB, ncb_cmd_cplt );
  178. NbCompleteRequest( Irp, STATUS_SUCCESS );
  179. NCB_COMPLETE( pdncb, NRC_GOODRET );
  180. return;
  181. }
  182. }
  183. NCB_COMPLETE( pdncb, NRC_CANOCCR );
  184. return;
  185. }
  186. NTSTATUS
  187. NbTdiErrorHandler (
  188. IN PVOID Context,
  189. IN NTSTATUS Status
  190. )
  191. /*++
  192. Routine Description:
  193. This routine is called on any error indications passed back from the
  194. transport. It implements LAN_STATUS_ALERT.
  195. Arguments:
  196. IN PVOID Context - Supplies the pfcb for the address.
  197. IN NTSTATUS Status - Supplies the error.
  198. Return Value:
  199. NTSTATUS - Status of event indication
  200. --*/
  201. {
  202. PLANA_INFO plana = (PLANA_INFO) Context;
  203. PDNCB pdncb;
  204. IF_NBDBG (NB_DEBUG_LANSTATUS) {
  205. NbPrint( ("NbTdiErrorHandler PLANA: %lx, Status %X\n", plana, Status));
  206. }
  207. ASSERT( plana->Signature == LANA_INFO_SIGNATURE);
  208. while ( (pdncb = DequeueRequest( &plana->LanAlertList)) != NULL ) {
  209. IF_NBDBG (NB_DEBUG_LANSTATUS) {
  210. NbPrint( ("NbTdiErrorHandler complete pdncb: %lx\n", pdncb ));
  211. }
  212. NCB_COMPLETE( pdncb, NbMakeNbError( Status) );
  213. pdncb->irp->IoStatus.Information = FIELD_OFFSET( DNCB, ncb_cmd_cplt );
  214. NbCheckAndCompleteIrp32(pdncb->irp);
  215. NbCompleteRequest( pdncb->irp, STATUS_SUCCESS );
  216. }
  217. return STATUS_SUCCESS;
  218. }