NTSTATUS MacConnect( IN PXENVIF_MAC Mac ) { PXENVIF_FRONTEND Frontend; PCHAR Buffer; ULONG64 Mtu; NTSTATUS status; Frontend = Mac->Frontend; Mac->StoreInterface = FrontendGetStoreInterface(Frontend); STORE(Acquire, Mac->StoreInterface); status = STORE(Read, Mac->StoreInterface, NULL, FrontendGetPath(Frontend), "mtu", &Buffer); if (!NT_SUCCESS(status)) { Mtu = ETHERNET_MTU; } else { Mtu = strtol(Buffer, NULL, 10); STORE(Free, Mac->StoreInterface, Buffer); } status = STATUS_INVALID_PARAMETER; if (Mtu < ETHERNET_MIN) goto fail1; Mac->MaximumFrameSize = (ULONG)Mtu + sizeof (ETHERNET_TAGGED_HEADER); status = __MacSetPermanentAddress(Mac, FrontendGetPermanentMacAddress(Frontend)); if (!NT_SUCCESS(status)) goto fail2; status = __MacSetCurrentAddress(Mac, FrontendGetCurrentMacAddress(Frontend)); if (!NT_SUCCESS(status)) RtlCopyMemory(&Mac->CurrentAddress, &Mac->PermanentAddress, sizeof (ETHERNET_ADDRESS)); RtlFillMemory(Mac->BroadcastAddress.Byte, ETHERNET_ADDRESS_LENGTH, 0xFF); Mac->DebugInterface = FrontendGetDebugInterface(Frontend); DEBUG(Acquire, Mac->DebugInterface); status = DEBUG(Register, Mac->DebugInterface, __MODULE__ "|MAC", MacDebugCallback, Mac, &Mac->DebugCallback); if (!NT_SUCCESS(status)) goto fail3; ASSERT(!Mac->Connected); Mac->Connected = TRUE; return STATUS_SUCCESS; fail3: Error("fail3\n"); DEBUG(Release, Mac->DebugInterface); Mac->DebugInterface = NULL; RtlZeroMemory(Mac->BroadcastAddress.Byte, ETHERNET_ADDRESS_LENGTH); RtlZeroMemory(Mac->CurrentAddress.Byte, ETHERNET_ADDRESS_LENGTH); RtlZeroMemory(Mac->PermanentAddress.Byte, ETHERNET_ADDRESS_LENGTH); fail2: Error("fail2\n"); Mac->MaximumFrameSize = 0; fail1: Error("fail1 (%08x)\n"); STORE(Release, Mac->StoreInterface); Mac->StoreInterface = NULL; return status; }
NTSTATUS NotifierConnect( IN PXENVIF_NOTIFIER Notifier ) { PXENVIF_FRONTEND Frontend = Notifier->Frontend; BOOLEAN Pending; NTSTATUS status; ASSERT3U(KeGetCurrentIrql(), ==, DISPATCH_LEVEL); KeAcquireSpinLockAtDpcLevel(&Notifier->Lock); ASSERT(!Notifier->Connected); Notifier->EvtchnInterface = FrontendGetEvtchnInterface(Frontend); EVTCHN(Acquire, Notifier->EvtchnInterface); Notifier->Evtchn = EVTCHN(Open, Notifier->EvtchnInterface, EVTCHN_UNBOUND, NotifierEvtchnCallback, Notifier, FrontendGetBackendDomain(Frontend), TRUE); status = STATUS_UNSUCCESSFUL; if (Notifier->Evtchn == NULL) goto fail1; Pending = EVTCHN(Unmask, Notifier->EvtchnInterface, Notifier->Evtchn, FALSE); if (Pending) EVTCHN(Trigger, Notifier->EvtchnInterface, Notifier->Evtchn); Notifier->DebugInterface = FrontendGetDebugInterface(Frontend); DEBUG(Acquire, Notifier->DebugInterface); status = DEBUG(Register, Notifier->DebugInterface, __MODULE__ "|NOTIFIER", NotifierDebugCallback, Notifier, &Notifier->DebugCallback); if (!NT_SUCCESS(status)) goto fail2; Notifier->StoreInterface = FrontendGetStoreInterface(Frontend); STORE(Acquire, Notifier->StoreInterface); Notifier->Connected = TRUE; KeReleaseSpinLockFromDpcLevel(&Notifier->Lock); return STATUS_SUCCESS; fail2: Error("fail2\n"); DEBUG(Release, Notifier->DebugInterface); EVTCHN(Close, Notifier->EvtchnInterface, Notifier->Evtchn); Notifier->Evtchn = NULL; Notifier->Events = 0; fail1: Error("fail1 (%08x)\n", status); EVTCHN(Release, Notifier->EvtchnInterface); KeReleaseSpinLockFromDpcLevel(&Notifier->Lock); return status; }