コード例 #1
0
/**
 * Sends messages to USB OstConnection
 * 
 * @param aMsg Message to be sent.
 * @return KErrNone if send successful
 */
TInt DTraceCoreOstLddIf::Send( TTraceMessage& aMsg )
    {
    TInt ret = KErrArgument;
    if ( aMsg.iData != NULL )
        {
        ret = TTraceCoreMessageUtils::GetMessageLength( aMsg );
        if ( ret > 0 )
            {
            // First send the phone formatted start character
            // Send trace data and end trace
            SendData( aMsg );
            if ( aMsg.iHeader != NULL ) 
                {
                DebugPrintMsg( iSendBuffer );
                }
            else
                {
                DebugPrintMsg( *aMsg.iData );
                }
            }
        else
            {
            ret = KErrArgument;
            }
        }
    
    return ret;
    }
コード例 #2
0
ファイル: DebugPrint.c プロジェクト: Kallameet/TPG2
void DebugPrintVA(int max, const char* format, va_list marker)
{
	char* Msg;
	if( !DebugPrintStarted) return;
	Msg = (char*)ExAllocatePool(NonPagedPool,max);
	if( Msg==NULL)
	{
		DebugPrintMsg("DebugPrint: Could not allocate buffer");
		return;
	}
	DebugSprintf(Msg,max,format,marker);
	DebugPrintMsg(Msg);
	ExFreePool(Msg);
}
コード例 #3
0
ファイル: Dispatch.cpp プロジェクト: Kallameet/TPG2
NTSTATUS Wdm1Close(IN PDEVICE_OBJECT fdo,
	IN PIRP Irp)
{
	DebugPrintMsg("Close");

	// Complete successfully
	return CompleteIrp(Irp, STATUS_SUCCESS, 0);
}
コード例 #4
0
ファイル: Dispatch.cpp プロジェクト: Kallameet/TPG2
NTSTATUS Wdm1SystemControl(IN PDEVICE_OBJECT fdo,
	IN PIRP Irp)
{
	DebugPrintMsg("SystemControl");

	// Just pass to lower driver
	IoSkipCurrentIrpStackLocation(Irp);
	PWDM1_DEVICE_EXTENSION dx = (PWDM1_DEVICE_EXTENSION)fdo->DeviceExtension;
	return IoCallDriver(dx->NextStackDevice, Irp);
}
コード例 #5
0
/**
 * Processes incoming OST messages
 */
void DTraceCoreOstLddIf::ReceiveDfc()
    {
    // Determine the message we received
    if ( iReceiveBuffer.Length() > OstHeader::OstBaseProtocol::KOstHeaderLengthOffset )
        {
        DebugPrintMsg ( iReceiveBuffer );
        if ( iCallback != NULL )
            {
            NotifyCallback();
            }
        }
    }
コード例 #6
0
ファイル: DebugPrint.c プロジェクト: Kallameet/TPG2
void DebugPrintInit(char* _DriverName)
{
	HANDLE threadHandle;
	NTSTATUS status;

	// Copy the driver's name out of INIT code segment
	DriverNameLen = 1 + ANSIstrlen(_DriverName);
	DriverName = (char*)ExAllocatePool(NonPagedPool,DriverNameLen);
	if( DriverName==NULL) return;
	RtlCopyMemory( DriverName, _DriverName, DriverNameLen);

	/////////////////////////////////////////////////////////////////////////
	// Prepare for thread start

	ExitNow = FALSE;
	KeInitializeEvent(&ThreadEvent, SynchronizationEvent, FALSE);
	KeInitializeEvent(&ThreadExiting, SynchronizationEvent, FALSE);
	// Initialise event list
	KeInitializeSpinLock(&EventListLock);
	InitializeListHead(&EventList);

	/////////////////////////////////////////////////////////////////////////
	// Start system thread to write events to DebugPrint driver

	status = PsCreateSystemThread( &threadHandle, THREAD_ALL_ACCESS, NULL, NULL, NULL,
									DebugPrintSystemThread, NULL);
	if( !NT_SUCCESS(status))
		return;

	/////////////////////////////////////////////////////////////////////////
	// Save a pointer to thread and close handle.

	status = ObReferenceObjectByHandle( threadHandle, THREAD_ALL_ACCESS, NULL, KernelMode,
										&ThreadObjectPointer, NULL);

	if( NT_SUCCESS(status))
		ZwClose(threadHandle);
	else
	{
		// Uh oh... force thread to exit
		ExitNow = TRUE;
		KeSetEvent( &ThreadEvent, 0, FALSE);
		return;
	}

	DebugPrintStarted = TRUE;

	// Send event that we've started logging
	DebugPrintMsg("DebugPrint logging started");
}
コード例 #7
0
ファイル: DeviceIo.cpp プロジェクト: Kallameet/TPG2
VOID StopDevice( IN PUSBKBD_DEVICE_EXTENSION dx)
{
	DebugPrintMsg("StopDevice");
	if( !dx->GotResources)
		return;
	dx->GotResources = false;

/*
	// Disable device
	KeSynchronizeExecution( dx->InterruptObject, (PKSYNCHRONIZE_ROUTINE)DisableDeviceInterrupts, (PVOID)dx); 
	// Disconnect from interrupt
	if( dx->GotInterrupt)
		IoDisconnectInterrupt( dx->InterruptObject);
	dx->InterruptObject = NULL;
	// Unmap memory
	if (dx->PortNeedsMapping)
		MmUnmapIoSpace( (PVOID)dx->PortBase, dx->PortLength);
*/
}
コード例 #8
0
ファイル: DebugPrint.c プロジェクト: Kallameet/TPG2
void DebugPrintClose()
{
	if( !DebugPrintStarted) return;

	DebugPrintMsg("DebugPrint logging ended");
	DebugPrintStarted = FALSE;
	
	// Tell thread to stop, and wait for it to stop
	ExitNow = TRUE;
	KeSetEvent( &ThreadEvent, 0, FALSE);
	KeWaitForSingleObject( &ThreadExiting, Executive, KernelMode, FALSE, NULL);

	// Dereference thread object
	if( ThreadObjectPointer!=NULL)
	{
		ObDereferenceObject(&ThreadObjectPointer);
		ThreadObjectPointer = NULL;
	}
	
	// Release our copy of DriverName
	if( DriverName!=NULL)
		ExFreePool(DriverName);
//	ClearEvents();
}
コード例 #9
0
ファイル: Packet.c プロジェクト: jiangxilong/TDI
NTSTATUS
DefaultDispatchCompletion(
	IN	PDEVICE_OBJECT	pDeviceObject,
	IN	PIRP			Irp,
	IN	PVOID			Context
)
{
   PTDIH_DeviceExtension pTDIH_DeviceExtension;
   BOOLEAN           CanDetachProceed = FALSE;
   PDEVICE_OBJECT    pAssociatedDeviceObject = NULL;
   PIO_STACK_LOCATION		IrpStack;

   ////////////////////////////////////////////////
   //通信参数
   PTDI_REQUEST_KERNEL pTDIRequestKernel;
   PTDI_ADDRESS_IP pIPAddress;
   PTRANSPORT_ADDRESS pTransAddr;

   PUCHAR pByte;
   EVENT event;

   int addr1,addr2,addr3,addr4;

   ULONG ProcessId;
   CHAR       ProcessName[16];
   PEPROCESS   curproc;
   int         i;
   char        *nameptr;

   PFILEOBJECT_NODE pFileObjectNode;
   //////////////////////////////////////////////////

   pTDIH_DeviceExtension = (PTDIH_DeviceExtension )(Context);

   ASSERT( pTDIH_DeviceExtension );

   if (Irp->PendingReturned)
   {
      IoMarkIrpPending(Irp);
	  strcpy(event.SuccOrFail,"PENDING");
   }

   pAssociatedDeviceObject = pTDIH_DeviceExtension->pFilterDeviceObject;

   if (pAssociatedDeviceObject != pDeviceObject)
   {
      DBGPRINT(( "TDIH_DefaultCompletion: Invalid Device Object Pointer\n" ));
      return(STATUS_SUCCESS);
   }

   IrpStack = IoGetCurrentIrpStackLocation(Irp);

   //得到进程号和进程名
   ProcessId=(ULONG)(PsGetCurrentProcessId());
   //DbgPrint("ProcessId: %d",ProcessId);
	
   if( ProcessNameOffset )
   {
	   curproc = PsGetCurrentProcess();
	   nameptr = (PCHAR) curproc + ProcessNameOffset;
	   strncpy( ProcessName, nameptr, 16 );
	   ProcessName[16] = 0;
   }
   else
   {
	   strcpy( ProcessName, "???" );
   }

   //操作是否成功
   if(NT_SUCCESS(Irp->IoStatus.Status))
   {
	   strcpy(event.SuccOrFail,"SUCCESSFUL");
   }
   if(!NT_SUCCESS(Irp->IoStatus.Status))
   {
	   strcpy(event.SuccOrFail,"UNSUCCESSFUL");
   }

   //进程名
   strcpy(event.ProcessName,ProcessName);

   //进程号
   sprintf(event.ProcessID,"%d",ProcessId);

   //IP地址和端口号
   strcpy(event.addr1,"*");
   strcpy(event.addr2,"*");
   strcpy(event.addr3,"*");
   strcpy(event.addr4,"*");
   strcpy(event.port,"*");

   //操作
   strcpy(event.Operation,"TDI_OPERATION");

   switch(IrpStack->MajorFunction)
   {
   case IRP_MJ_CREATE:
	   //TDIH_Create(pTDIH_DeviceExtension, Irp, IrpStack);
	   break;
   case IRP_MJ_CLOSE:
	   //TDIH_Close(pTDIH_DeviceExtension, Irp, IrpStack); 
	   break;
   case IRP_MJ_CLEANUP:
	   //TDIH_CleanUp(pTDIH_DeviceExtension, Irp, IrpStack);
	   break;
   case IRP_MJ_INTERNAL_DEVICE_CONTROL:
	   switch(IrpStack->MinorFunction)
	   {
		   case TDI_CONNECT:
			   pFileObjectNode=TDIH_GetFileObjectFromList(IrpStack->FileObject);
               if(pFileObjectNode==NULL)
			   {
				   DbgPrint("THERE IS SOMETHINT WRONG IN TDI_CONNECT: THERE IS NO RECORD");
			   }
			   else
			   {
				   pTDIRequestKernel=(PTDI_REQUEST_KERNEL )&IrpStack->Parameters;
                   pTransAddr=(pTDIRequestKernel->RequestConnectionInformation)->RemoteAddress;
               
				   if(pTransAddr->Address[0 ].AddressType==TDI_ADDRESS_TYPE_IP)
				   {
				       pIPAddress = (PTDI_ADDRESS_IP )(PUCHAR )&pTransAddr->Address[0 ].Address;
                       pByte = (PUCHAR)&pIPAddress->in_addr;
                   		
			           strcpy(event.Operation,"CONNECT");
			      
			           addr1=(int)pByte[0];
			           addr2=(int)pByte[1];
			           addr3=(int)pByte[2];
			           addr4=(int)pByte[3];
			      
			           sprintf(event.port,"%d",(USHORT)pIPAddress->sin_port);
                       sprintf(event.addr1, "%d" , addr1);
			           sprintf(event.addr2, "%d" , addr2);
			           sprintf(event.addr3, "%d" , addr3);
			           sprintf(event.addr4, "%d" , addr4);

					   //写入文件链表地址和端口号内容
                       pFileObjectNode->IP=pIPAddress;
					   pFileObjectNode->PORT=(USHORT)pIPAddress->sin_port;
					   pFileObjectNode->SET=TRUE;
				   }
			   }
			   
			   //发送信息
			   DebugPrintMsg(&event);

		       break;
		   
		   case TDI_QUERY_INFORMATION:
		 	   pFileObjectNode=TDIH_GetFileObjectFromList(IrpStack->FileObject);
               if(pFileObjectNode==NULL)
			   {
				   DbgPrint("THERE IS SOMETHINT WRONG IN TDI_QUERY_INFORMATION: THERE IS NO RECORD");
			   }
			   else
			   {
                   if(pFileObjectNode->SET==FALSE)
				   {
                       strcpy(event.addr1,"");
					   strcpy(event.addr2,"");
					   strcpy(event.addr3,"");
					   strcpy(event.addr4,"");
					   strcpy(event.port,"");					   
				   }
				   else
				   {
                       pIPAddress=pFileObjectNode->IP;
					   pByte = (PUCHAR)&pIPAddress->in_addr;

					   addr1=(int)pByte[0];
			           addr2=(int)pByte[1];
			           addr3=(int)pByte[2];
			           addr4=(int)pByte[3];

					   //IP地址
					   sprintf(event.addr1, "%d" , addr1);
			           sprintf(event.addr2, "%d" , addr2);
			           sprintf(event.addr3, "%d" , addr3);
			           sprintf(event.addr4, "%d" , addr4);

					   //端口号
					   sprintf(event.port,"%d",(int)pIPAddress->sin_port);
				   }

				   //操作类型
				   if(pTDIH_DeviceExtension->NodeType == TDIH_NODE_TYPE_TCP_FILTER_DEVICE)
				   {
					   strcpy(event.Operation,"TCP---TDI_QUERY_INFORMATION");
				   }
				   else if(pTDIH_DeviceExtension->NodeType == TDIH_NODE_TYPE_TCP_FILTER_DEVICE)
				   {
					   strcpy(event.Operation,"UDP---TDI_QUERY_INFORMATION");
				   }
			   }

			   //发送信息
			   DebugPrintMsg(&event);

			   break;
		  
		   case TDI_SEND:
		 	   pFileObjectNode=TDIH_GetFileObjectFromList(IrpStack->FileObject);
               if(pFileObjectNode==NULL)
			   {
				   DbgPrint("THERE IS SOMETHINT WRONG IN TDI_SEND: THERE IS NO RECORD");
			   }
			   else
			   {
                   if(pFileObjectNode->SET==FALSE)
				   {
                       strcpy(event.addr1,"");
					   strcpy(event.addr2,"");
					   strcpy(event.addr3,"");
					   strcpy(event.addr4,"");
					   strcpy(event.port,"");					   
				   }
				   else
				   {
                       pIPAddress=pFileObjectNode->IP;
					   pByte = (PUCHAR)&pIPAddress->in_addr;

					   addr1=(int)pByte[0];
			           addr2=(int)pByte[1];
			           addr3=(int)pByte[2];
			           addr4=(int)pByte[3];

					   //IP地址
					   sprintf(event.addr1, "%d" , addr1);
			           sprintf(event.addr2, "%d" , addr2);
			           sprintf(event.addr3, "%d" , addr3);
			           sprintf(event.addr4, "%d" , addr4);

					   //端口号
					   sprintf(event.port,"%d",(int)pIPAddress->sin_port);
				   }

				   //操作类型
				   if(pTDIH_DeviceExtension->NodeType == TDIH_NODE_TYPE_TCP_FILTER_DEVICE)
				   {
					   strcpy(event.Operation,"TCP---TDI_SEND");
				   }
				   else if(pTDIH_DeviceExtension->NodeType == TDIH_NODE_TYPE_TCP_FILTER_DEVICE)
				   {
					   strcpy(event.Operation,"UDP---TDI_SEND");
				   }
			   }
			   
			   //发送信息
			   DebugPrintMsg(&event);

		       break;
		  
		   default:

			   //发送信息
			   DebugPrintMsg(&event);

			   break;
	   }
   default:

	   //发送信息
	   DebugPrintMsg(&event);

	   break;
   }

   UTIL_DecrementLargeInteger(
      pTDIH_DeviceExtension->OutstandingIoRequests,
      (unsigned long)1,
      &(pTDIH_DeviceExtension->IoRequestsSpinLock)
      );

   UTIL_IsLargeIntegerZero(
      CanDetachProceed,
      pTDIH_DeviceExtension->OutstandingIoRequests,
      &(pTDIH_DeviceExtension->IoRequestsSpinLock)
      );

   if (CanDetachProceed)
   {
      KeSetEvent(&(pTDIH_DeviceExtension->IoInProgressEvent), IO_NO_INCREMENT, FALSE);
   }

   return(STATUS_SUCCESS);

}
コード例 #10
0
ファイル: DeviceIo.cpp プロジェクト: Kallameet/TPG2
NTSTATUS RetrieveResources( IN PUSBKBD_DEVICE_EXTENSION dx, IN PCM_RESOURCE_LIST AllocatedResourcesTranslated)
{
	if( AllocatedResourcesTranslated==NULL ||
		AllocatedResourcesTranslated->Count==0)
	{
		DebugPrintMsg("RetrieveResources: No allocated translated resources");
		return STATUS_SUCCESS;	// or whatever
	}

	// Get to actual resources
	PCM_PARTIAL_RESOURCE_LIST list = &AllocatedResourcesTranslated->List[0].PartialResourceList;
	PCM_PARTIAL_RESOURCE_DESCRIPTOR resource = list->PartialDescriptors;
	ULONG NumResources = list->Count;

	DebugPrint("RetrieveResources: %d resource lists %d resources", AllocatedResourcesTranslated->Count, NumResources);

	bool GotError = false;

	// Clear dx
	dx->GotInterrupt = false;
	dx->GotPortOrMemory = false;
	dx->PortInIOSpace = false;
	dx->PortNeedsMapping = false;

	// Go through each allocated resource
	for( ULONG i=0; i<NumResources; i++,resource++)
	{
		switch( resource->Type)
		{
		case CmResourceTypePort:
			if( dx->GotPortOrMemory) { GotError = true; break; }
			dx->GotPortOrMemory = true;
			dx->PortStartAddress = resource->u.Port.Start;
			dx->PortLength = resource->u.Port.Length;
			dx->PortNeedsMapping = (resource->Flags & CM_RESOURCE_PORT_IO)==0;
			dx->PortInIOSpace = !dx->PortNeedsMapping;
			DebugPrint("RetrieveResources: Port %L Length %d NeedsMapping %d",
							dx->PortStartAddress,
							dx->PortLength, dx->PortNeedsMapping);
			break;

		case CmResourceTypeInterrupt:
			dx->GotInterrupt = true;
			dx->Irql = (KIRQL)resource->u.Interrupt.Level;
			dx->Vector = resource->u.Interrupt.Vector;
			dx->Affinity = resource->u.Interrupt.Affinity;
			dx->Mode = (resource->Flags == CM_RESOURCE_INTERRUPT_LATCHED)
						? Latched : LevelSensitive;
			DebugPrint("RetrieveResources: Interrupt vector %x IRQL %d Affinity %d Mode %d",
							dx->Vector, dx->Irql, dx->Affinity, dx->Mode);
			break;

		case CmResourceTypeMemory:
			if( dx->GotPortOrMemory) { GotError = true; break; }
			dx->GotPortOrMemory = true;
			dx->PortStartAddress = resource->u.Memory.Start;
			dx->PortLength = resource->u.Memory.Length;
			dx->PortNeedsMapping = true;
			DebugPrint("RetrieveResources: Memory %L Length %d",
							dx->PortStartAddress, dx->PortLength);
			break;

		case CmResourceTypeDma:
		case CmResourceTypeDeviceSpecific:
		case CmResourceTypeBusNumber:
		default:
			DebugPrint("RetrieveResources: Unrecognised resource type %d", resource->Type);
			GotError = true;
			break;
		}
	}

	// Check we've got the resources we need
	if( GotError /*|| !GotPortOrMemory || !GotInterrupt*/)
		return STATUS_DEVICE_CONFIGURATION_ERROR;

	return STATUS_SUCCESS;
}