コード例 #1
0
ファイル: usb.c プロジェクト: 340211173/Driver
// This function gets called when the timeout period of debounce timer elapses.
// It reports a switch change by completing a pending request
//
void HidFx2EvtTimerFunction(_In_ WDFTIMER hTimer)
{
    WDFDEVICE           hDevice = NULL;
    WDFREQUEST          hRequest;
    PDEVICE_EXTENSION   pDevContext = NULL;
    NTSTATUS            status = STATUS_SUCCESS;
    size_t              cBytesReturned = 0;
    unsigned char       bToggledSwitch = 0;
    ULONG               cBytesToCopy = 0;
    PHIDFX2_IO_REPORT   pInputReport = NULL;

    TraceVerbose(DBG_IOCTL, "(%!FUNC!) Enter\n");


    hDevice = WdfTimerGetParentObject(hTimer);
    pDevContext = GetDeviceContext(hDevice);

    bToggledSwitch = pDevContext->bLatestToggledSwitch;
    TraceInfo(DBG_IOCTL, "(%!FUNC!) mode %d switch %d\n", pDevContext->driverMode, bToggledSwitch);

    if (!((pDevContext->driverMode == DM_BUTTON || pDevContext->driverMode == DM_BUTTON_AND_LED) && bToggledSwitch == 0))
    {
        // Check if there are any pending requests in the Interrupt Message Queue.
        // If a request is found then complete the pending request.
        status = WdfIoQueueRetrieveNextRequest(pDevContext->hInterruptMsgQueue, &hRequest);
        if (NT_SUCCESS(status))
        {
            cBytesToCopy = sizeof(pInputReport[0]);
            status = WdfRequestRetrieveOutputBuffer(hRequest,
                                                    cBytesToCopy,
                                                    &pInputReport,
                                                    &cBytesReturned); // BufferLength
            if (NT_SUCCESS(status))
            {
                TraceInfo(DBG_IOCTL, "(%!FUNC!) WdfRequestRetrieveOutputBuffer switch %d\n", bToggledSwitch);

                pInputReport->bReportId = GENERIC_DESKTOP_REPORT_ID;
                pInputReport->bData = bToggledSwitch;
                cBytesReturned = cBytesToCopy;
            }
            else // WdfRequestRetrieveOutputBuffer failed
            {
                TraceErr(DBG_IOCTL, "(%!FUNC!) WdfRequestRetrieveOutputBuffer failed with status: %!STATUS!\n", status);
            }

            WdfRequestCompleteWithInformation(hRequest, status, cBytesReturned);

        } 
        else if (status != STATUS_NO_MORE_ENTRIES)
        {
            TraceErr(DBG_IOCTL, "(%!FUNC!) WdfIoQueueRetrieveNextRequest status %!STATUS!\n", status);
        }
    }
    else
    {
        TraceInfo(DBG_IOCTL, "(%!FUNC!) ignore switch");
    }

    TraceVerbose(DBG_IOCTL, "(%!FUNC!) Exit\n");
}
コード例 #2
0
void nRF8001MeteoStation::onACIEvent(aci_evt_t* p_event) {
  switch(p_event->evt_opcode) {
    // if an ACI_EVT_DATA_ACK occurs, it searches the pipe, which has return a ACK
    case ACI_EVT_DATA_ACK:
      if (p_event->params.data_ack.pipe_number == PIPE_METEO_STATION_TEMPERATURE_MEASUREMENT_TX_ACK) {
        // sets to False; a new sending could take place in case of a new temperature (!= m_last_temp)
        m_ack_temperature_measure_pending = false;  
        TraceInfo(F("ACK for temperature measurement received\n"));
      } else if (p_event->params.data_ack.pipe_number == PIPE_METEO_STATION_HUMIDITY_MEASUREMENT_TX_ACK) {
        m_ack_humidity_measure_pending = false;
        TraceInfo(F("ACK for humidity measurement received\n"));
      } /*else if (p_event->params.data_ack.pipe_number == PIPE_METEO_STATION_PRESSURE_MEASUREMENT_TX_ACK) {
        m_ack_pressure_measure_pending = false;
        TraceInfo(F("ACK for pressure measurement received\n"));
      }*/
      notif.notify(YELLOW, 1, false);
      break;
    // if a paired device is disconnected, it sets the stored values to the biggest FLOAT value
    // and the ACKs to false. It avoids problems if the device want to connect again
    case ACI_EVT_DISCONNECTED:
      m_last_temp = FLT_MAX;
      m_last_hum = FLT_MAX;
      //m_last_pres = INT_MAX;
      m_ack_temperature_measure_pending = false;
      m_ack_humidity_measure_pending = false;
      //m_ack_pressure_measure_pending = false;
      break;
    // if a device asks for a connection
    case ACI_EVT_CONNECTED:
      notif.notify(WHITE, 1, false);
      break;
    // if the paired device sends data, it retrieves the data into the min or the max temperature (thermostat)
    case ACI_EVT_DATA_RECEIVED:
      if (p_event->params.data_received.rx_data.pipe_number == PIPE_METEO_STATION_THERMOSTAT_TEMPERATUR_RX) {
        for(uint8_t i = 0; i < p_event->len - 2; i++) {
          m_uart_buffer[i] = convert_hex_to_uint(p_event->params.data_received.rx_data.aci_data[i]);
        }
        if (m_thermo_temp == THERMO_TEMP_MIN) {
          m_thermo_temp_min = m_uart_buffer[0] * 10 + m_uart_buffer[1];
          TraceInfoFormat(F("Thermostat min temperature set to : %u\n"), m_thermo_temp_min);
        } else if (m_thermo_temp == THERMO_TEMP_MAX) {
          m_thermo_temp_max = m_uart_buffer[0] * 10 + m_uart_buffer[1];
          TraceInfoFormat(F("Thermostat max temperature set to : %u\n"), m_thermo_temp_max);
        }
      }
      notif.notify(WHITE, 1, false);
      break;
  }
}
コード例 #3
0
//Installable driver initialization entry point. This entry point is called directly by the I/O system.
//
NTSTATUS DriverEntry (_In_ PDRIVER_OBJECT pDriverObject, _In_ PUNICODE_STRING pszRegistryPath)
{
    NTSTATUS               status = STATUS_SUCCESS;
    WDF_DRIVER_CONFIG      config;
    WDF_OBJECT_ATTRIBUTES  attributes;


    // Initialize WPP Tracing
    WPP_INIT_TRACING(pDriverObject, pszRegistryPath);

    TraceInfo(DBG_INIT, "(%!FUNC!) Enter -Sample Built %s %s\n", __DATE__, __TIME__);

    WDF_DRIVER_CONFIG_INIT(&config, HidFx2EvtDeviceAdd);

    // Register a cleanup callback so that we can call WPP_CLEANUP when  the framework driver object is deleted during driver unload.
    WDF_OBJECT_ATTRIBUTES_INIT(&attributes);
    attributes.EvtCleanupCallback = HidFx2EvtDriverContextCleanup;

    // Create a framework driver object to represent our driver.
    status = WdfDriverCreate(pDriverObject,
                             pszRegistryPath,
                             &attributes,      // Driver Attributes
                             &config,          // Driver Config Info
                             WDF_NO_HANDLE
                            );
    if (!NT_SUCCESS(status)) 
    {
        TraceErr(DBG_INIT, "(%!FUNC!)WdfDriverCreate failed with status %!STATUS!\n", status);
        WPP_CLEANUP(pDriverObject);
    }

    TraceVerbose(DBG_INIT, "(%!FUNC!) Exit\n");
    return status;
}
コード例 #4
0
ファイル: receiver.c プロジェクト: OpenXT/xc-windows
static VOID
ReceiverInitializeConfiguration(PRECEIVER Receiver)
{
    PKEY_VALUE_PARTIAL_INFORMATION pInfo;
    NTSTATUS status;

    status = XenReadRegistryValue(L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Services\\xennet\\Parameters",
                                  L"LowResources",
                                  &pInfo);
    if (!NT_SUCCESS(status)) {
        TraceVerbose(("LowResources switch: not present\n"));
        goto done;
    }

    if (pInfo->Type != REG_DWORD) {
        TraceError(("LowResources switch: wrong type\n"));
        ExFreePool(pInfo);
        goto done;
    }

    Receiver->LowResources = *(DWORD *)pInfo->Data;
    ExFreePool(pInfo);

done:
    TraceInfo(("LowResources: %08x\n", Receiver->LowResources));
}
コード例 #5
0
ファイル: xenlower.cpp プロジェクト: OpenXT/xc-vusb
ULONG
XenLowerInterfaceVersion(
    PXEN_LOWER XenLower)
{
    NTSTATUS status;
    PCHAR vstr;
    int version;

	vstr = XenLowerReadXenstoreValue(XenLower->BackendPath, "version");
    if (vstr == NULL)
    {
        TraceError((__FUNCTION__\
            ": XenLowerReadXenstoreValue() failed to return the vusb version.\n"));
        return 0;
    }

    sscanf_s(vstr, "%d", &version);
    XmFreeMemory(vstr);

    // Need to now write the version we support to the frontend
    status = xenbus_printf(XBT_NIL, XenLower->FrontendPath,
        "version", "%d", XEN_LOWER_INTERFACE_VERSION);
    if (!NT_SUCCESS(status))
    {
        TraceError((__FUNCTION__\
            ": xenbus_printf(frontend/version) failed.\n"));
        return 0;
    }

    TraceInfo((__FUNCTION__
        ": Read backend version: %d  -  Wrote frontend version: %d\n",
        version, XEN_LOWER_INTERFACE_VERSION));

    return (ULONG)version;
}
コード例 #6
0
ファイル: xenlower.cpp プロジェクト: OpenXT/xc-vusb
BOOLEAN
XenLowerBackendInit(
    PXEN_LOWER XenLower)
{
    PCHAR path;
    NTSTATUS status;

    // Note this is split from the XenLowerInit so it can be called on the resume
    // path in case backend values change.

    XXX_TODO("--XT-- All the backend path handling assumes dom0 is the backend, this will change for device domains")
    // XXX TODO all the backend path handling assumes dom0 is the backend. This will
    // not necessarily be true with device domains. The changes to support this go
    // beyond this module though.
    path = XenLowerReadXenstoreValue(XenLower->FrontendPath, "backend");
    if (path == NULL)
    {
        TraceError((__FUNCTION__
            ": XenLowerReadXenstoreValue() failed to return the back end path, fatal.\n"));
        return FALSE;
    }
    status = RtlStringCchCopyA(XenLower->BackendPath,
        sizeof(XenLower->BackendPath),
        path);
    XmFreeMemory(path);
    if (status != STATUS_SUCCESS)
    {
        XenLower->BackendPath[0] = 0;
        TraceError((__FUNCTION__
            ": Failed to copy back end path - status: 0x%x\n", status));
        return FALSE;
    }

    status = xenbus_read_domain_id(XBT_NIL, XenLower->FrontendPath,
        "backend-id", &XenLower->BackendDomid);
    if (!NT_SUCCESS(status))
    {
        TraceWarning((__FUNCTION__
            ": Failed to read backend id from %s (%x), setting to dom0\n",
            XenLower->FrontendPath, status));
        XenLower->BackendDomid = DOMAIN_ID_0();
    }

    // XXX TODO for now we only support a dom0 backend so check that here. Later
    // when we support a device domain for vusb, other domids will be fine.
    XXX_TODO("--XT-- For now we only support a dom0 backend so check that here");
    if (unwrap_DOMAIN_ID(XenLower->BackendDomid) != unwrap_DOMAIN_ID(DOMAIN_ID_0()))
    {
        TraceError((XENTARGET
            ": cannot connect to backend Domid: %d, only dom0 supported currently\n",
            XenLower->BackendDomid));
        return FALSE;
    }

    TraceInfo((__FUNCTION__
        ": XenLower initialized - FrontendPath: %s  BackendPath: %s BackendDomid: %d\n",
        XenLower->FrontendPath, XenLower->BackendPath, unwrap_DOMAIN_ID(XenLower->BackendDomid)));

    return TRUE;
}
コード例 #7
0
ファイル: xenlower.cpp プロジェクト: OpenXT/xc-vusb
static VOID
_XenLowerTraceGref(PCSTR Caller, grant_ref_t greft, GRANT_REF gref)
{
    grant_ref_t greftun = xen_GRANT_REF(gref);

    TraceInfo(("%s: GRANT_REF greft: %d (0x%x) greftun: %d (0x%x) wrapped: %2.2x:%2.2x:%2.2x:%2.2x\n",
        Caller, greft, greft, greftun, greftun,
        gref.__wrapped_data[0], gref.__wrapped_data[1],
        gref.__wrapped_data[2], gref.__wrapped_data[3]));
}
コード例 #8
0
ファイル: http.c プロジェクト: whtc123/mysource
int httproute_call(HttpSession *session)
{
	queue_t *route_queue=&session->server->routes;
	char *path=session->request.path;
	queue_t *q=NULL;
	HttpRoute *route;
	//printf("httproute_call  in !\n");
	if(queue_empty(route_queue))return 404;
	
	for(q = queue_prev(route_queue);
        q != queue_sentinel(route_queue);
        q = queue_last(q) ) {

        route = queue_data(q, HttpRoute, node);
		if(strcmp(path,route->path)==0 )
		{
			TraceInfo("route callback  found!\n");
			return route->func(session,route->arg);
		}
    }
	TraceInfo("route callback not found!\n");
	return 404;
}
コード例 #9
0
//This routine sets the state of the Feature: in this case Segment Display on the USB FX2 board.
NTSTATUS SendVendorCommand(_In_ WDFDEVICE hDevice, _In_ unsigned char bVendorCommand, _In_ unsigned char bCommandData)
{
    NTSTATUS                     status = STATUS_SUCCESS;
    ULONG                        cBytesTransferred = 0;
    PDEVICE_EXTENSION            pDevContext = NULL;
    WDF_MEMORY_DESCRIPTOR        memDesc;
    WDF_USB_CONTROL_SETUP_PACKET controlSetupPacket;
    WDF_REQUEST_SEND_OPTIONS     sendOptions;

    PAGED_CODE();

    TraceVerbose(DBG_IOCTL, "(%!FUNC!) Enter\n");

    pDevContext = GetDeviceContext(hDevice);

    TraceInfo(DBG_IOCTL, "(%!FUNC!): Command:0x%x, data: 0x%x\n", bVendorCommand, bCommandData);

    // Send the I/O with a timeout.
    // We do that because we send the I/O in the context of the user thread and if it gets stuck, it would prevent the user process from existing.
    WDF_REQUEST_SEND_OPTIONS_INIT(&sendOptions, WDF_REQUEST_SEND_OPTION_TIMEOUT);

    WDF_REQUEST_SEND_OPTIONS_SET_TIMEOUT(&sendOptions, WDF_REL_TIMEOUT_IN_SEC(5));

    WDF_USB_CONTROL_SETUP_PACKET_INIT_VENDOR(&controlSetupPacket,
                                             BmRequestHostToDevice,
                                             BmRequestToDevice,
                                             bVendorCommand,    // Request
                                             0,                 // Value
                                             0);                // Index

    WDF_MEMORY_DESCRIPTOR_INIT_BUFFER(&memDesc, &bCommandData, sizeof(bCommandData));

    status = WdfUsbTargetDeviceSendControlTransferSynchronously(pDevContext->hUsbDevice,
                                                                WDF_NO_HANDLE,      // Optional WDFREQUEST
                                                                &sendOptions,       // PWDF_REQUEST_SEND_OPTIONS
                                                                &controlSetupPacket,
                                                                &memDesc,
                                                                &cBytesTransferred);
    if (!NT_SUCCESS(status))
    {
        TraceErr(DBG_IOCTL, "(%!FUNC!): Failed to set Segment Display state - %!STATUS!\n", status);
    }

    TraceVerbose(DBG_IOCTL, "(%!FUNC!) Exit\n");

    return status;
}
コード例 #10
0
ファイル: Subsystem.cpp プロジェクト: anareboucas/nanook
//----------------------------------------------------------------------------------------------------------------------------
VOID Subsystem::Destroy()
{
  Trace0Enter("");

  m_State = 0;

  if (m_pThread)
  {
    TraceInfo(this, "Waiting for subsystem to terminate itself");
    if (!m_pThread->Wait(2000))
    {
      TraceWarning(this, "The subsystem manager timed-out whilst waiting for the subsystem to terminate.  Subsystem will be forcably terminated");
      m_pThread->Terminate();
    }

    m_pThread = 0;
  }
}
コード例 #11
0
ファイル: controlpath.c プロジェクト: barryrandall/xc-windows
/* similar to xenvbd:ProbeBackendCapabiities() */
static void
probe_backend_capabilities(struct scsifilt *sf)
{
    NTSTATUS status;
    ULONG64 order;

    status = xenbus_read_domain_id(XBT_NIL, sf->frontend_path,
                                   "backend-id", &sf->backend_domid);
    if (!NT_SUCCESS(status)) {
        TraceError(("Failed to read backend id from %s (%x)\n",
                    sf->frontend_path, status));
        sf->backend_domid = DOMAIN_ID_0();
    }

    /* check to see if we used a multi-page handshake previously */
    status = xenbus_read_int(XBT_NIL, sf->frontend_path, "ring-page-order",
                             &order);
    if (NT_SUCCESS(status)) {
        XM_ASSERT3U(order, <=, MAX_RING_PAGE_ORDER);

        sf->single_page = FALSE;
        sf->ring_order = (ULONG)order;

        return;
    }

    /* assume single page handshake */
    sf->single_page = TRUE;
    sf->ring_order = 0;

    status = xenbus_read_int(XBT_NIL, sf->backend_path, "max-ring-page-order",
                             &order);
    if (NT_SUCCESS(status)) {
        if (order > MAX_RING_PAGE_ORDER)
            order = MAX_RING_PAGE_ORDER;

        sf->single_page = FALSE;
        sf->ring_order = (ULONG)order;
    }

    TraceInfo(("Using %u sring page(s).\n", 1 << sf->ring_order));
}
コード例 #12
0
ファイル: balloon.c プロジェクト: OpenXT/xc-windows
static ULONG
BalloonGetTopPage(
    VOID
    )
{
    PHYSICAL_MEMORY_RANGE   *Range;
    PHYSICAL_ADDRESS        TopAddress;
    ULONG                   Index;

    Range = MmGetPhysicalMemoryRanges();

    TopAddress.QuadPart = 0ull;
    for (Index = 0; Range[Index].BaseAddress.QuadPart != 0 || Range[Index].NumberOfBytes.QuadPart != 0; Index++) {
        PHYSICAL_ADDRESS EndAddress;
        CHAR Key[32];

        EndAddress.QuadPart = Range[Index].BaseAddress.QuadPart + Range[Index].NumberOfBytes.QuadPart;

        TraceInfo(("PHYSICAL MEMORY: RANGE[%u] %08x.%08x - %08x.%08x\n",
                   Index, Range[Index].BaseAddress.HighPart, Range[Index].BaseAddress.LowPart,
                   EndAddress.HighPart, EndAddress.LowPart));

        (VOID) Xmsnprintf(Key, sizeof (Key), "data/physical-memory/range%u", Index);

        (VOID) xenbus_printf(XBT_NIL, Key, "base", "%08x.%08x", 
                             Range[Index].BaseAddress.HighPart,
                             Range[Index].BaseAddress.LowPart);

        (VOID) xenbus_printf(XBT_NIL, Key, "end", "%08x.%08x",
                             EndAddress.HighPart,
                             EndAddress.LowPart);

        if (EndAddress.QuadPart > TopAddress.QuadPart)
            TopAddress.QuadPart = EndAddress.QuadPart;
    }

    TraceNotice(("PHYSICAL MEMORY: TOP = %08x.%08x\n", TopAddress.HighPart, TopAddress.LowPart));

    return (ULONG)(TopAddress.QuadPart >> PAGE_SHIFT);
}
コード例 #13
0
ファイル: xenv4v.c プロジェクト: meisners/oxt-windows
NTSTATUS NTAPI
DriverEntry(PDRIVER_OBJECT driverObject,
			PUNICODE_STRING registryPath)
{
    UNREFERENCED_PARAMETER(registryPath);	

    TraceVerbose(("====> '%s'.\n", __FUNCTION__));

    PsGetVersion(&g_osMajorVersion, &g_osMinorVersion, NULL, NULL);

    if ((g_osMajorVersion < 5)||((g_osMajorVersion == 5)&&(g_osMinorVersion < 1))) {
        TraceWarning(("Windows XP or later operating systems supported!\n"));
        return STATUS_UNSUCCESSFUL;
    }

    TraceInfo(("Starting driver...\n"));

    driverObject->DriverUnload = V4vDriverUnload;
    driverObject->DriverExtension->AddDevice = V4vAddDevice;
	
    driverObject->MajorFunction[IRP_MJ_CREATE]         = V4vDispatchCreate;
    driverObject->MajorFunction[IRP_MJ_CLEANUP]        = V4vDispatchCleanup;
    driverObject->MajorFunction[IRP_MJ_CLOSE]          = V4vDispatchClose;
    driverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = V4vDispatchDeviceControl;
    driverObject->MajorFunction[IRP_MJ_READ]           = V4vDispatchRead;
    driverObject->MajorFunction[IRP_MJ_WRITE]          = V4vDispatchWrite;
    driverObject->MajorFunction[IRP_MJ_PNP]            = V4vDispatchPnP;
    driverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] = V4vDispatchWmi;
    driverObject->MajorFunction[IRP_MJ_POWER]          = V4vDispatchPower;
    // The rest can be handled by the system not supported routine

    TraceVerbose(("DriverEntry returning successfully\n"));

    TraceVerbose(("<==== '%s'.\n", __FUNCTION__));

    return STATUS_SUCCESS;
}
コード例 #14
0
// This event is called when the framework receives IRP_MJ_INTERNAL DEVICE_CONTROL requests from the system.
//
void HidFx2EvtInternalDeviceControl(
    _In_ WDFQUEUE     hQueue,
    _In_ WDFREQUEST   hRequest,
    _In_ size_t       cOutputBufferLength,
    _In_ size_t       cInputBufferLength,
    _In_ ULONG        ulIoControlCode
   )
{
    NTSTATUS            status = STATUS_SUCCESS;
    WDFDEVICE           hDevice;
    PDEVICE_EXTENSION   pDevContext = NULL;

    UNREFERENCED_PARAMETER(cOutputBufferLength);
    UNREFERENCED_PARAMETER(cInputBufferLength);

    TraceVerbose(DBG_IOCTL, "(%!FUNC!) Enter\n");

    hDevice = WdfIoQueueGetDevice(hQueue);
    pDevContext = GetDeviceContext(hDevice);

    TraceInfo(DBG_IOCTL, "(%!FUNC!) Queue:0x%p, Request:0x%p\n", hQueue, hRequest);

    switch (ulIoControlCode)
    {
    case IOCTL_HID_GET_DEVICE_DESCRIPTOR:
        TraceInfo(DBG_IOCTL, "IOCTL_HID_GET_DEVICE_DESCRIPTOR\n");
        status = HidFx2GetHidDescriptor(hDevice, hRequest);
        WdfRequestComplete(hRequest, status);
        break;

    case IOCTL_HID_GET_DEVICE_ATTRIBUTES:
        TraceInfo(DBG_IOCTL, "IOCTL_HID_GET_DEVICE_ATTRIBUTES\n");
        status = HidFx2GetDeviceAttributes(hRequest);
        WdfRequestComplete(hRequest, status);
        break;

    case IOCTL_HID_GET_REPORT_DESCRIPTOR:
        TraceInfo(DBG_IOCTL, "IOCTL_HID_GET_REPORT_DESCRIPTOR\n");
        status = HidFx2GetReportDescriptor(hDevice, hRequest);
        WdfRequestComplete(hRequest, status);
        break;

    case IOCTL_HID_READ_REPORT:
        TraceInfo(DBG_IOCTL, "IOCTL_HID_READ_REPORT\n");
        status = WdfRequestForwardToIoQueue(hRequest, pDevContext->hInterruptMsgQueue);
        if (!NT_SUCCESS(status))
        {
            TraceErr(DBG_IOCTL, "WdfRequestForwardToIoQueue failed with status: %!STATUS!\n", status);
            WdfRequestComplete(hRequest, status);
        }
        break;

    case IOCTL_HID_SEND_IDLE_NOTIFICATION_REQUEST:
        TraceInfo(DBG_IOCTL, "IOCTL_HID_SEND_IDLE_NOTIFICATION_REQUEST\n");
        status = HidFx2SendIdleNotification(hRequest);
        if (!NT_SUCCESS(status))
        {
            TraceErr(DBG_IOCTL, "SendIdleNotification failed with status: %!STATUS!\n", status);
            WdfRequestComplete(hRequest, status);
        }
        break;

    case IOCTL_HID_GET_INPUT_REPORT:
        TraceInfo(DBG_IOCTL, "IOCTL_HID_GET_INPUT_REPORT\n");
        HidFx2GetInput(hRequest);
        WdfRequestComplete(hRequest, status);
        break;

    case IOCTL_HID_SET_OUTPUT_REPORT:
        TraceInfo(DBG_IOCTL, "IOCTL_HID_SET_OUTPUT_REPORT\n");
        status = HidFx2SetOutput(hRequest);
        WdfRequestComplete(hRequest, status);
        break;

    default:
        TraceInfo(DBG_IOCTL, "IOCTL Not Supported 0x%X\n", ulIoControlCode);
        status = STATUS_NOT_SUPPORTED;
        WdfRequestComplete(hRequest, status);
        break;
    }

    TraceVerbose(DBG_IOCTL, "(%!FUNC!) Exit\n");
    return;
}
コード例 #15
0
ファイル: sendmsg.c プロジェクト: Fike103/Meridian59_103
/* returns the return value of the blakod */
int SendBlakodMessage(int object_id,int message_id,int num_parms,parm_node parms[])
{
	object_node *o;
	class_node *c,*propagate_class;
	message_node *m;
	val_type message_ret;
	
	int prev_interpreting_class;
	char *prev_bkod;

	int propagate_depth = 0;

	prev_bkod = bkod;
	prev_interpreting_class = kod_stat.interpreting_class;
	
	o = GetObjectByID(object_id);
	if (o == NULL)
	{
		bprintf("SendBlakodMessage can't find OBJECT %i\n",object_id);
		return NIL;
	}
	
	c = GetClassByID(o->class_id);
	if (c == NULL)
	{
		eprintf("SendBlakodMessage OBJECT %i can't find CLASS %i\n",
			object_id,o->class_id);
		return NIL;
	}
	
	m = GetMessageByID(c->class_id,message_id,&c);
	
	if (m == NULL)
	{
		bprintf("SendBlakodMessage CLASS %s (%i) OBJECT %i can't find a handler for MESSAGE %s (%i)\n",
			c->class_name,c->class_id,object_id,GetNameByID(message_id),message_id);
		return NIL;
	}
	
	m->called_count++;
	
	kod_stat.num_messages++;
	stack[message_depth].class_id = c->class_id;
	stack[message_depth].message_id = m->message_id;
	stack[message_depth].propagate_depth = 0;
	stack[message_depth].num_parms = num_parms;
	memcpy(stack[message_depth].parms,parms,num_parms*sizeof(parm_node));
	stack[message_depth].bkod_ptr = bkod;
	if (message_depth > 0)
		stack[message_depth-1].bkod_ptr = prev_bkod;
	message_depth++;
	if (message_depth > kod_stat.message_depth_highest)
		kod_stat.message_depth_highest = message_depth;
	
	if (message_depth >= MAX_DEPTH)
	{
		bprintf("SendBlakodMessage sending to CLASS %s (%i), depth is %i, aborted!\n",
			c->class_name,c->class_id,message_depth);
		
		kod_stat.interpreting_class = prev_interpreting_class;
		message_depth--;
		bkod = prev_bkod;
		
		return NIL;
	}
	
	if (m->trace_session_id != INVALID_ID)
	{
		trace_session_id = m->trace_session_id;
		m->trace_session_id = INVALID_ID;
	}
	
	if (trace_session_id != INVALID_ID)
		TraceInfo(trace_session_id,c->class_name,m->message_id,num_parms,parms);
	
	kod_stat.interpreting_class = c->class_id;
	
	bkod = m->handler;
	
	propagate_depth = 1;

	while (InterpretAtMessage(object_id,c,m,num_parms,parms,&message_ret) 
		== RETURN_PROPAGATE)
	{
		propagate_class = m->propagate_class;
		m = m->propagate_message;
		
		if (m == NULL)
		{
			bprintf("SendBlakodMessage can't propagate MESSAGE %s (%i) in CLASS %s (%i)\n",
				GetNameByID(message_id),message_id,c->class_name,c->class_id);
			message_depth -= propagate_depth;
			kod_stat.interpreting_class = prev_interpreting_class;
			bkod = prev_bkod;
			return NIL;
		}
		
		if (propagate_class == NULL)
		{
			bprintf("SendBlakodMessage can't find class to propagate to, from "
				"MESSAGE %s (%i) in CLASS %s (%i)\n",GetNameByID(message_id),message_id,c->class_name,c->class_id);
			message_depth -= propagate_depth;
			kod_stat.interpreting_class = prev_interpreting_class;
			bkod = prev_bkod;
			return NIL;
		}
		
		c = propagate_class;
		
		m->called_count++;
		
		if (m->trace_session_id != INVALID_ID)
		{
			trace_session_id = m->trace_session_id;
			m->trace_session_id = INVALID_ID;
		}
		
		if (trace_session_id != INVALID_ID)
			TraceInfo(trace_session_id,"(propagate)",m->message_id,num_parms,parms);
		
		kod_stat.interpreting_class = c->class_id;
		
		stack[message_depth-1].bkod_ptr = bkod;

		stack[message_depth].class_id = c->class_id;
		stack[message_depth].message_id = m->message_id;
		stack[message_depth].propagate_depth = propagate_depth;
		stack[message_depth].num_parms = num_parms;
		memcpy(stack[message_depth].parms,parms,num_parms*sizeof(parm_node));
		stack[message_depth].bkod_ptr = m->handler;
		message_depth++;
		propagate_depth++;

		bkod = m->handler;

	}
	
	message_depth -= propagate_depth;
	kod_stat.interpreting_class = prev_interpreting_class;
	bkod = prev_bkod;
	
	return message_ret.int_val;
}
コード例 #16
0
ファイル: xenlower.cpp プロジェクト: OpenXT/xc-vusb
static NTSTATUS
XenLowerConnectBackendInternal(
    PXEN_LOWER XenLower,
    SUSPEND_TOKEN Token)
{
    NTSTATUS status = STATUS_SUCCESS;
    XENBUS_STATE state;
    xenbus_transaction_t xbt;
    PCHAR fepath;

    if (is_null_EVTCHN_PORT(XenLower->EvtchnPort))
    {
        TraceError((__FUNCTION__ ": no event channel port, this routine must be called after event channel initialization\n"));
        return STATUS_UNSUCCESSFUL;
    }

    //---------------------------Backend Wait Ready-------------------------------//
    //
    // Wait for backend to get ready for initialization.
    //

    status = xenbus_change_state(XBT_NIL,
        XenLower->FrontendPath,
        "state",
        XENBUS_STATE_INITIALISING);
    if (!NT_SUCCESS(status))
    {
        TraceWarning((__FUNCTION__
            ": Failed to change front end state to XENBUS_STATE_INITIALISING(%d) status: 0x%x\n",
            XENBUS_STATE_INITIALISING, status));
        // Go on, best effort, chin up
    }

    TraceInfo((__FUNCTION__
        ": Front end state set to XENBUS_STATE_INITIALISING(%d)\n",
        XENBUS_STATE_INITIALISING));

    state = null_XENBUS_STATE();
    for ( ; ; )
    {
        // Turns out suspend tokens are not even used.
        state = XenbusWaitForBackendStateChange(XenLower->BackendPath,
            state, NULL, Token);

        if (same_XENBUS_STATE(state, XENBUS_STATE_INITWAIT))
        {
            break;
        }

        if (same_XENBUS_STATE(state, XENBUS_STATE_CLOSING) ||
            is_null_XENBUS_STATE(state))
        {
            TraceError((__FUNCTION__ ": backend '%s' went away before we could connect to it?\n",
                XenLower->BackendPath));

            status = STATUS_UNSUCCESSFUL;
            break;
        }
    }

    if (status != STATUS_SUCCESS)
    {
        return status;
    }

    TraceInfo((__FUNCTION__
        ": Back end state went to XENBUS_STATE_INITWAIT(%d)\n",
        XENBUS_STATE_INITWAIT));
    
    //----------------------------Backend Connect---------------------------------//    

    //
    // Communicate configuration to backend.
    //

    fepath = XenLower->FrontendPath;
    do {
        xenbus_transaction_start(&xbt);
        xenbus_write_grant_ref(xbt, fepath, "ring-ref", XenLower->SringGrantRef);
        xenbus_write_evtchn_port(xbt, fepath, "event-channel", XenLower->EvtchnPort);
        xenbus_change_state(xbt, fepath, "state", XENBUS_STATE_CONNECTED);
        status = xenbus_transaction_end(xbt, 0);
    } while (status == STATUS_RETRY);

    if (status != STATUS_SUCCESS)
    {
        TraceError((__FUNCTION__ ": failed to configure xenstore frontend values.\n"));
        return STATUS_UNSUCCESSFUL;
    }

    TraceInfo((__FUNCTION__
        ": Front end state set to XENBUS_STATE_CONNECTED(%d)\n",
        XENBUS_STATE_CONNECTED));

    //
    // Wait for backend to accept configuration and complete initialization.
    //

    state = null_XENBUS_STATE();
    for ( ; ; )
    {
        state = XenbusWaitForBackendStateChange(XenLower->BackendPath,
            state, NULL, Token);

        if (is_null_XENBUS_STATE(state) ||
            same_XENBUS_STATE(state, XENBUS_STATE_CLOSING) ||
            same_XENBUS_STATE(state, XENBUS_STATE_CLOSED))
        {

            TraceError((__FUNCTION__ ": Failed to connected '%s' <-> '%s' backend state: %d\n",
                XenLower->FrontendPath,
                XenLower->BackendPath,
                state));

            status = STATUS_UNSUCCESSFUL;
            break;
        }

        if (same_XENBUS_STATE(state, XENBUS_STATE_CONNECTED))
        {
            TraceNotice((__FUNCTION__ ": Connected '%s' <-> '%s' \n",
                XenLower->FrontendPath,
                XenLower->BackendPath));
            TraceInfo((__FUNCTION__
                ": Back end final state went to XENBUS_STATE_CONNECTED(%d)\n",
                XENBUS_STATE_CONNECTED));
            break;
        }
    }

    return status;
}
コード例 #17
0
ファイル: misc.c プロジェクト: OpenXT/xc-windows
VOID
XenGfxReadRegistryValues(XENGFX_DEVICE_EXTENSION *pXenGfxExtension,
                         PUNICODE_STRING pDeviceRegistryPath)
{
#define _XENGFX_REGBUF_SPACE 240
    NTSTATUS Status;
    HANDLE   Key = NULL;
    ULONG    Len = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + sizeof(WCHAR)*_XENGFX_REGBUF_SPACE; // room for 240 UNICODE chars
    ULONG    LenOut;
    UNICODE_STRING                 ValueName;
    OBJECT_ATTRIBUTES              ObjectAttrs;
    KEY_VALUE_PARTIAL_INFORMATION *pKvpi = NULL;
    PAGED_CODE();
	
    do {
        TraceVerbose(("%s Reading XENGFX device registry location: %.*ws\n",
                      __FUNCTION__, pDeviceRegistryPath->Length >> 1, pDeviceRegistryPath->Buffer));

        // Make a buffer for registry data
        pKvpi = (KEY_VALUE_PARTIAL_INFORMATION*)ExAllocatePoolWithTag(PagedPool, Len, XENGFX_TAG);
        if (pKvpi == NULL) {
            TraceError(("%s Failed to alloc registry read buffer!!\n", __FUNCTION__));
            break;
        }

        // Open the device key, it should be present.
        InitializeObjectAttributes(&ObjectAttrs, pDeviceRegistryPath, OBJ_CASE_INSENSITIVE, NULL, NULL);
        Status = ZwOpenKey(&Key, KEY_QUERY_VALUE, &ObjectAttrs);
        if (!NT_SUCCESS(Status)) {
            TraceError(("%s Failed to open registry key for driver - error: 0x%x\n", __FUNCTION__, Status));
            break;
        }

        // Get the ChildDeviceCount value - continue if it is not there.
        RtlInitUnicodeString(&ValueName, XENGFX_REG_CHILDDEVICECOUNT);
        RtlZeroMemory(pKvpi, Len);

        Status = ZwQueryValueKey(Key, &ValueName, KeyValuePartialInformation, pKvpi, Len, &LenOut);
        if ((!NT_SUCCESS(Status))||(pKvpi->Type != REG_DWORD)||(pKvpi->DataLength != sizeof(ULONG))) {
            TraceInfo(("%s Could not query ChildDeviceCount (may not be present) - type: %d length: 0x%x status: 0x%x\n", 
                       __FUNCTION__, pKvpi->Type, pKvpi->DataLength, Status));          
        }
        else
            pXenGfxExtension->VCrtcRegistryCount = *((ULONG*)pKvpi->Data);

        // Get the VidPnTracing value - continue if it is not there.
        RtlInitUnicodeString(&ValueName, XENGFX_REG_VIDPNTRACING);
        RtlZeroMemory(pKvpi, Len);

        Status = ZwQueryValueKey(Key, &ValueName, KeyValuePartialInformation, pKvpi, Len, &LenOut);
        if ((!NT_SUCCESS(Status))||(pKvpi->Type != REG_DWORD)||(pKvpi->DataLength != sizeof(ULONG))) {
            TraceInfo(("%s Could not query VidPnTracing (may not be present) - type: %d length: 0x%x status: 0x%x\n", 
                       __FUNCTION__, pKvpi->Type, pKvpi->DataLength, Status));
        }
        else
            pXenGfxExtension->VidPnTracing = (*((ULONG*)pKvpi->Data) != 0) ? TRUE : FALSE;

        // Get the VidPnTracing value - continue if it is not there.
        RtlInitUnicodeString(&ValueName, XENGFX_REG_DEBUGLOGNAME);
        RtlZeroMemory(pKvpi, Len);

        Status = ZwQueryValueKey(Key, &ValueName, KeyValuePartialInformation, pKvpi, Len, &LenOut);
        if ((!NT_SUCCESS(Status))||(pKvpi->Type != REG_SZ)||(pKvpi->DataLength > _XENGFX_REGBUF_SPACE*sizeof(WCHAR))) {
            TraceInfo(("%s Could not query DebugLogName (may not be present) - type: %d length: 0x%x status: 0x%x\n", 
                       __FUNCTION__, pKvpi->Type, pKvpi->DataLength, Status));
        }
        else {
            RtlStringCchCopyW(pXenGfxExtension->DebugLogName,
                              pKvpi->DataLength/sizeof(WCHAR),
                              (CONST WCHAR*)pKvpi->Data);
            TraceInfo(("%s DebugLogName: %S\n", __FUNCTION__, pXenGfxExtension->DebugLogName));
        }

    } while (FALSE);

    if (pKvpi != NULL)
        ExFreePoolWithTag(pKvpi, XENGFX_TAG);
}
コード例 #18
0
ファイル: usb.c プロジェクト: 340211173/Driver
// This the completion routine of the continuous reader. This can called concurrently on multiprocessor system if there are
// more than one readers configured. So make sure to protect access to global resources.
//
void HidFx2EvtUsbInterruptPipeReadComplete(
    WDFUSBPIPE  hPipe,
    WDFMEMORY   hBuffer,
    size_t      cNumBytesTransferred,
    WDFCONTEXT  pContext
   )
{
    PDEVICE_EXTENSION   pDevContext = pContext;
    BOOLEAN             fInTimerQueue;
    unsigned char       *pbSwitchState = NULL;
    unsigned char       bCurrentSwitchState = 0;
    unsigned char       bPrevSwitchState = 0;
    unsigned char       bToggledSwitch = 0;

    UNREFERENCED_PARAMETER(cNumBytesTransferred);
    UNREFERENCED_PARAMETER(hPipe);

    TraceVerbose(DBG_INIT, "(%!FUNC!) Enter\n");

    // Interrupt endpoints sends switch state when first started  or when resuming from suspend.
    // We need to ignore that data since user did not change the switch state.
    if (pDevContext->fIsPowerUpSwitchState)
    {
        pDevContext->fIsPowerUpSwitchState = FALSE;
        TraceInfo(DBG_INIT, "(%!FUNC!) Dropping interrupt message since received during powerup/resume\n");
        return;
    }


    // Make sure that there is data in the read packet. 
    // Depending on the device specification, it is possible for it to return a 0 length read in certain conditions.
    if (cNumBytesTransferred == 0)
    {
        TraceWarning(DBG_INIT, "(%!FUNC!) Zero length read occured on the Interrupt Pipe's Continuous Reader\n");
        return;
    }

    pbSwitchState = WdfMemoryGetBuffer(hBuffer, NULL);
    bCurrentSwitchState = ~(*pbSwitchState);                // switchs are inverted on hardware boards
    bCurrentSwitchState &= RADIO_SWITCH_BUTTONS_BIT_MASK;   //Mask off everything except the actual radio switch bit
    bPrevSwitchState = pDevContext->bCurrentSwitchState;

    if (bPrevSwitchState ^ bCurrentSwitchState) // make sure we toggled the radio switch
    {
        switch(pDevContext->driverMode)
        {
        // If it's a slider switch we want  0->1 and 1->0 transitions.
        case DM_SLIDER_SWITCH:
        case DM_SLIDER_SWITCH_AND_LED:
            bToggledSwitch = bCurrentSwitchState;
            // A timer is started for 10 ms everytime there is a switch toggled
            fInTimerQueue = WdfTimerStart(pDevContext->hDebounceTimer, WDF_REL_TIMEOUT_IN_MS(SWITCHPACK_DEBOUNCE_TIME));
            TraceInfo(DBG_INIT, "(%!FUNC!) Debounce Timer started. Existing -%!bool!\n", fInTimerQueue);
            break;
        //If it's a button so we only report 0->1 transitions
        case DM_BUTTON:
        case DM_BUTTON_AND_LED:
            bToggledSwitch = (bPrevSwitchState ^ bCurrentSwitchState) & bCurrentSwitchState;
            if (bToggledSwitch != 0)
            {
                // A timer is started for 10 ms everytime there is a switch toggled on
                fInTimerQueue = WdfTimerStart(pDevContext->hDebounceTimer, WDF_REL_TIMEOUT_IN_MS(SWITCHPACK_DEBOUNCE_TIME));
                TraceInfo(DBG_INIT, "(%!FUNC!) Debounce Timer started. Existing -%!bool!\n", fInTimerQueue);
            }
            break;
        // Ignore button presses if LED only
        case DM_LED_ONLY:
        default:
            break;
        }

        // Store switch state in device context
        pDevContext->bCurrentSwitchState = bCurrentSwitchState;
        pDevContext->bLatestToggledSwitch = bToggledSwitch;
    }
    else
    {
        TraceInfo(DBG_INIT, "(%!FUNC!) Not a radio switch toggle\n");
    }
    TraceInfo(DBG_INIT, "(%!FUNC!) Switch 0x%x, prevSwitch:0x%x, X0R:0x%x\n", bCurrentSwitchState, bPrevSwitchState, bToggledSwitch);

    TraceVerbose(DBG_INIT, "(%!FUNC!) Exit\n");
}