void LumiaNotifier_Removal(object sender, USBEvent e) { if ( (e.DevicePath.IndexOf("VID_0421&PID_0660&MI_04", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("VID_0421&PID_0661", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("VID_0421&PID_06FC", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("VID_0421&PID_066E", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("VID_0421&PID_0714", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("vid_045e&pid_0a00", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("VID_045E&PID_0A02", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("VID_05C6&PID_9008", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf(@"disk&ven_qualcomm&prod_mmc_storage", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf(@"DISK&VEN_MSFT&PROD_PHONE_MMC_STOR", StringComparison.OrdinalIgnoreCase) >= 0) ) { if (CurrentInterface != null) { LastInterface = CurrentInterface; } CurrentInterface = null; if (CurrentModel != null) { CurrentModel.Dispose(); CurrentModel = null; LogFile.Log("Lumia disconnected", LogType.FileAndConsole); } DeviceRemoved(); } }
public void OnCameraDisconnected(object sender, USBEvent e) { CameraReadiness = false; Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, (SendOrPostCallback) delegate { RefreshCameraList(); }, null); }
public void OnCameraConnected(object sender, USBEvent e) { Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Send, (SendOrPostCallback) delegate { Thread.Sleep(30); RefreshCameraList(); }, null); CameraReadiness = true; }
public void OnCameraDisconnected(object sender, USBEvent e) { string[] changedParts = WebcamManager.GetDeviceInfoFromPath(e.DevicePath); string[] selectedParts = WebcamManager.GetDeviceInfoFromPath(selectedCameraPath); if (string.Compare(changedParts[1], selectedParts[1], true) == 0 && string.Compare(changedParts[2], selectedParts[2], true) == 0) { selectedCameraConnected = false; ReleasePreviousBuffers(); WebcamManager.ReleaseInactiveCameras(); Logger.WriteLine("Selected camera disconnected"); ErrorLog.AddError(ErrorType.Warning, "Selected camera has been disconnected"); } }
//Used to detect arrival of usb device with right GUID private void ConnectionNotifier_Arrival(object sender, USBEvent e) { device = USBDevice.GetSingleDevice(deviceGUID); logger.Info("New USB device mounted"); if (device == null) { logger.Warn("No Device found"); } else { logger.Info("Connected to device"); logDeviceiFaceProperties(device); } }
private void USBEventHandler(object sender, USBEvent e) { if (!e.Guid.Equals(this.guid)) { return; } if (e.Type == USBEventType.DeviceRemoval) { DeinitDevice(); } else { InitDevice(); } }
public void OnCameraConnected(object sender, USBEvent e) { if (!selectedCameraConnected) { Thread.Sleep(50); WebcamManager.RestartService(); selectedCameraIndex = LookforSelectedCamera(); if (selectedCameraIndex != -1) { Logger.WriteLine("Selected camera reconnected"); ErrorLog.AddError(ErrorType.Message, "Selected camera has been reconnected"); webcambuffer.RegisterForImages(WebcamManager.GetCamera(selectedCameraIndex)); WebcamManager.ReleaseInactiveCameras(); } } }
//called at init, and each time a system event occurs private void OnDeviceArrival(Object sender, USBEvent e) { lock (interfaceLock) { if (interfaces.Keys.Contains(e.DevicePath.ToLower())) { Logger.Info("Ignoring WINUSB device arrival since device already registered"); return; } try { USBDevice d = new USBDevice(e.DevicePath); DeviceFound(d); } catch (Exception ex) { Logger.Error("Failed to register device: " + ex.Message); return; } } }
void LumiaNotifier_Removal(object sender, USBEvent e) { if (e.DevicePath.IndexOf("VID_05C6&PID_9006", StringComparison.OrdinalIgnoreCase) >= 0) { Qcom9006DevicePath = null; } if ( (e.DevicePath.IndexOf("VID_0421&PID_0660&MI_04", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("VID_0421&PID_0713&MI_04", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("VID_045E&PID_0A01&MI_04", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("VID_0421&PID_0661", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("VID_0421&PID_06FC", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("VID_0421&PID_066E", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("VID_0421&PID_0714", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("VID_0421&PID_05EE", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("VID_045E&PID_0A00", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("VID_045E&PID_0A02", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("VID_05C6&PID_9008", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf(@"DISK&VEN_QUALCOMM&PROD_MMC_STORAGE", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf(@"DISK&VEN_MSFT&PROD_PHONE_MMC_STOR", StringComparison.OrdinalIgnoreCase) >= 0) ) { if (CurrentInterface != null) { LastInterface = CurrentInterface; } CurrentInterface = null; if (CurrentModel != null) { CurrentModel.Dispose(); CurrentModel = null; LogFile.Log("Lumia disconnected", LogType.FileAndConsole); } DeviceRemoved(); } }
public void USBEventCallBack(object usbDeviceReceiver, object device) { USBEvent?.Invoke(usbDeviceReceiver, GetDeviceInfo(device)); }
void LumiaNotifier_Arrival(object sender, USBEvent e) { try { if ((e.DevicePath.IndexOf("VID_0421&", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("VID_045E&", StringComparison.OrdinalIgnoreCase) >= 0)) { if ((e.DevicePath.IndexOf("&PID_0660&MI_04", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("&PID_0713&MI_04", StringComparison.OrdinalIgnoreCase) >= 0) || // for Spec B (e.DevicePath.IndexOf("&PID_0A01&MI_04", StringComparison.OrdinalIgnoreCase) >= 0)) // for Spec B (650) { CurrentInterface = PhoneInterfaces.Lumia_Label; CurrentModel = new NokiaPhoneModel(e.DevicePath); LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly); LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Connected device: Lumia", LogType.FileAndConsole); LogFile.Log("Mode: Label", LogType.FileAndConsole); NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel)); } else if ((e.DevicePath.IndexOf("&PID_0661", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("&PID_06FC", StringComparison.OrdinalIgnoreCase) >= 0) || // VID_0421&PID_06FC is for Lumia 930 (e.DevicePath.IndexOf("&PID_0A00", StringComparison.OrdinalIgnoreCase) >= 0)) // vid_045e & pid_0a00 & mi_03 = Lumia 950 XL normal mode { if (((USBNotifier)sender).Guid == OldCombiInterfaceGuid) { NewInterfaceWaitHandle.Reset(); if (USBDevice.GetDevices(NewCombiInterfaceGuid).Count() > 0) { return; } else { // Old combi-interface was detected, but new combi-interface was not detected. // This could mean 2 things: // - It is a WP80 phone, which has only this old combi-interface to talk to. // - It is a WP81 / W10M phone, which has an unresponsive old combi-interface and we need to wait for the new combi-interface to arrive. // We will wait maximum 1 sec for the new interface. If it doesn't arrive we will start talking on this old interface. // We will start a new thread, because if this thread is blocked, no new devices will arrive. string DevicePath = e.DevicePath; ThreadPool.QueueUserWorkItem(s => { if (!NewInterfaceWaitHandle.WaitOne(1000)) { // Waithandle not set. // So new interface did not arrive. // So we assume we need to talk to this old interface. CurrentInterface = PhoneInterfaces.Lumia_Normal; CurrentModel = new NokiaPhoneModel(DevicePath); LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly); LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Connected device: Lumia", LogType.FileAndConsole); LogFile.Log("Mode: Normal", LogType.FileAndConsole); NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel)); } }); } } else { NewInterfaceWaitHandle.Set(); CurrentInterface = PhoneInterfaces.Lumia_Normal; CurrentModel = new NokiaPhoneModel(e.DevicePath); LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly); LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Connected device: Lumia", LogType.FileAndConsole); LogFile.Log("Mode: Normal", LogType.FileAndConsole); NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel)); } } else if ((e.DevicePath.IndexOf("&PID_066E", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("&PID_0714", StringComparison.OrdinalIgnoreCase) >= 0) || // VID_0421&PID_0714 is for Lumia 930 (e.DevicePath.IndexOf("&PID_0A02", StringComparison.OrdinalIgnoreCase) >= 0) || // VID_045E&PID_0A02 is for Lumia 950 (e.DevicePath.IndexOf("&PID_05EE", StringComparison.OrdinalIgnoreCase) >= 0)) // VID_0421&PID_05EE is for early RX100 { CurrentModel = new NokiaFlashModel(e.DevicePath); ((NokiaFlashModel)CurrentModel).InterfaceChanged += InterfaceChanged; FlashAppType type = FlashAppType.FlashApp; try { type = ((NokiaFlashModel)CurrentModel).GetFlashAppType(); LogFile.Log("Flash App Type: " + type.ToString(), LogType.FileOnly); } catch { LogFile.Log("Flash App Type could not be determined, assuming " + type.ToString(), LogType.FileOnly); } switch (type) { case FlashAppType.BootManager: { CurrentInterface = PhoneInterfaces.Lumia_Bootloader; LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly); LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Connected device: Lumia", LogType.FileAndConsole); LogFile.Log("Mode: Bootloader", LogType.FileAndConsole); NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel)); break; } case FlashAppType.FlashApp: { ((NokiaFlashModel)CurrentModel).DisableRebootTimeOut(); CurrentInterface = PhoneInterfaces.Lumia_Flash; LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly); LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Connected device: Lumia", LogType.FileAndConsole); LogFile.Log("Mode: Flash", LogType.FileAndConsole); NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel)); break; } case FlashAppType.PhoneInfoApp: { CurrentInterface = PhoneInterfaces.Lumia_Bootloader; LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly); LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Connected device: Lumia", LogType.FileAndConsole); LogFile.Log("Mode: Bootloader (Phone Info)", LogType.FileAndConsole); NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel)); break; } } } } else if ((e.DevicePath.IndexOf(@"DISK&VEN_QUALCOMM&PROD_MMC_STORAGE", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf(@"DISK&VEN_MSFT&PROD_PHONE_MMC_STOR", StringComparison.OrdinalIgnoreCase) >= 0) || ((e.DevicePath.Length == @"\\.\E:".Length) && (e.DevicePath.StartsWith(@"\\.\")) && (e.DevicePath.EndsWith(":")))) { #if DEBUG LogFile.Log("Mass storage arrived: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Start new thread for getting metadata.", LogType.FileOnly); #endif // This function is possibly called by an USB notification WndProc. // It is not possible to invoke COM objects from a WndProc. // MassStorage uses ManagementObjectSearcher, which is a COM object. // Therefore we use a new thread. ThreadPool.QueueUserWorkItem(s => { lock (ModelLock) { if (!(CurrentModel is MassStorage)) { // Wait 1 second to make sure MainOS is loaded // In case of multiple drive letters being assigned to the phone by the user // MainOS may take a while to show up and we may accidentally catch up a letter that is // not for MainOS. Task.Delay(1000).Wait(); MassStorage NewModel = new MassStorage(e.DevicePath); if (NewModel.Drive != null) // When logical drive is already known, we use this model. Or else we wait for the logical drive to arrive. { CurrentInterface = PhoneInterfaces.Lumia_MassStorage; CurrentModel = NewModel; LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly); LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Connected device: Lumia", LogType.FileAndConsole); LogFile.Log("Mode: Mass storage mode", LogType.FileAndConsole); if (!string.IsNullOrEmpty(Qcom9006DevicePath)) { LogFile.Log("Found 9006 device previously", LogType.FileOnly); LogFile.Log("Attaching 9006 device", LogType.FileOnly); NewModel.AttachQualcommSerial(Qcom9006DevicePath); } NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel)); } } } }); } else if (e.DevicePath.IndexOf("VID_05C6&", StringComparison.OrdinalIgnoreCase) >= 0) // Qualcomm device { if (e.DevicePath.IndexOf("&PID_9008", StringComparison.OrdinalIgnoreCase) >= 0) { USBDeviceInfo DeviceInfo = USBDevice.GetDevices(((USBNotifier)sender).Guid).Where((d) => string.Compare(d.DevicePath, e.DevicePath, true) == 0).FirstOrDefault(); if ((DeviceInfo.BusName == "QHSUSB_DLOAD") || (DeviceInfo.BusName == "QHSUSB__BULK") || ((DeviceInfo.BusName == "") && (LastInterface != PhoneInterfaces.Qualcomm_Download))) // TODO: Separate for Sahara! { CurrentInterface = PhoneInterfaces.Qualcomm_Download; CurrentModel = new QualcommSerial(e.DevicePath); NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel)); LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly); LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Connected device: Lumia", LogType.FileAndConsole); if (DeviceInfo.BusName == "") { LogFile.Log("Driver does not show busname, assume mode: Qualcomm Emergency Download 9008", LogType.FileAndConsole); } else { LogFile.Log("Mode: Qualcomm Emergency Download 9008", LogType.FileAndConsole); } } else if ((DeviceInfo.BusName == "QHSUSB_ARMPRG") || ((DeviceInfo.BusName == "") && (LastInterface == PhoneInterfaces.Qualcomm_Download))) { CurrentInterface = PhoneInterfaces.Qualcomm_Flash; CurrentModel = new QualcommSerial(e.DevicePath); NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel)); LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly); LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Connected device: Lumia", LogType.FileAndConsole); if (DeviceInfo.BusName == "") { LogFile.Log("Driver does not show busname, assume mode: Qualcomm Emergency Flash 9008", LogType.FileAndConsole); } else { LogFile.Log("Mode: Qualcomm Emergency Flash 9008", LogType.FileAndConsole); } } } else if (e.DevicePath.IndexOf("&PID_9006", StringComparison.OrdinalIgnoreCase) >= 0) { // This is part of the Mass Storage inteface. // It is a slightly different version of the Qualcomm Emergency interface, which is implemented in SBL3. // One important difference is that the base address for sending a loader is not 0x2A000000, but it is 0x82F00000. Qcom9006DevicePath = e.DevicePath; LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly); LogFile.Log("Device path: " + Qcom9006DevicePath, LogType.FileOnly); LogFile.Log("Connected device: Lumia", LogType.FileAndConsole); LogFile.Log("Mode: Qualcomm Emergency 9006", LogType.FileAndConsole); if (CurrentModel is MassStorage) { LogFile.Log("Found Mass Storage device previously", LogType.FileOnly); LogFile.Log("Attaching 9006 device", LogType.FileOnly); ((MassStorage)CurrentModel).AttachQualcommSerial(Qcom9006DevicePath); } } else if (e.DevicePath.IndexOf("&PID_F006", StringComparison.OrdinalIgnoreCase) >= 0) { // This is part of the charging inteface. LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly); LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Connected device: Lumia", LogType.FileAndConsole); LogFile.Log("Mode: Qualcomm Emergency Charging F006", LogType.FileAndConsole); } } } catch (Exception Ex) { LogFile.LogException(Ex); CurrentModel = null; CurrentInterface = null; } }
void LumiaNotifier_Arrival(object sender, USBEvent e) { try { if (e.DevicePath.IndexOf("VID_0421&PID_0660&MI_04", StringComparison.OrdinalIgnoreCase) >= 0) { CurrentInterface = PhoneInterfaces.Lumia_Label; CurrentModel = new NokiaPhoneModel(e.DevicePath); LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly); LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Connected device: Lumia", LogType.FileAndConsole); LogFile.Log("Mode: Label", LogType.FileAndConsole); NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel)); } else if ((e.DevicePath.IndexOf("VID_0421&PID_0661", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("VID_0421&PID_06FC", StringComparison.OrdinalIgnoreCase) >= 0) || // VID_0421&PID_06FC is for Lumia 930 (e.DevicePath.IndexOf("vid_045e&pid_0a00", StringComparison.OrdinalIgnoreCase) >= 0)) // vid_045e & pid_0a00 & mi_03 = Lumia 950 XL normal mode { if (((USBNotifier)sender).Guid == OldCombiInterfaceGuid) { NewInterfaceWaitHandle.Reset(); if (USBDevice.GetDevices(NewCombiInterfaceGuid).Count() > 0) { return; } else { // Old combi-interface was detected, but new combi-interface was not detected. // This could mean 2 things: // - It is a WP80 phone, which has only this old combi-interface to talk to. // - It is a WP81 / W10M phone, which has an unresponsive old combi-interface and we need to wait for the new combi-interface to arrive. // We will wait maximum 1 sec for the new interface. If it doesn't arrive we will start talking on this old interface. // We will start a new thread, because if this thread is blocked, no new devices will arrive. string DevicePath = e.DevicePath; ThreadPool.QueueUserWorkItem(s => { if (!NewInterfaceWaitHandle.WaitOne(1000)) { // Waithandle not set. // So new interface did not arrive. // So we assume we need to talk to this old interface. CurrentInterface = PhoneInterfaces.Lumia_Normal; CurrentModel = new NokiaPhoneModel(DevicePath); LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly); LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Connected device: Lumia", LogType.FileAndConsole); LogFile.Log("Mode: Normal", LogType.FileAndConsole); NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel)); } }); } } else { NewInterfaceWaitHandle.Set(); CurrentInterface = PhoneInterfaces.Lumia_Normal; CurrentModel = new NokiaPhoneModel(e.DevicePath); LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly); LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Connected device: Lumia", LogType.FileAndConsole); LogFile.Log("Mode: Normal", LogType.FileAndConsole); NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel)); } } else if ((e.DevicePath.IndexOf("VID_0421&PID_066E", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf("VID_0421&PID_0714", StringComparison.OrdinalIgnoreCase) >= 0) || // VID_0421&PID_0714 is for Lumia 930 (e.DevicePath.IndexOf("VID_045E&PID_0A02", StringComparison.OrdinalIgnoreCase) >= 0)) // VID_045E&PID_0A02 is for Lumia 950 { CurrentModel = new NokiaFlashModel(e.DevicePath); ((NokiaFlashModel)CurrentModel).InterfaceChanged += InterfaceChanged; // Attempt to request a param. // When it succeeds we have full Flash mode. // When it fails we are in a limited Flash mode, like Bootmanager or Hardreset-screen. // Limited Flash mode only supports boot-commands; not querying info. byte[] QueryResult = ((NokiaFlashModel)CurrentModel).ReadParam("SS"); if (QueryResult == null) { CurrentInterface = PhoneInterfaces.Lumia_Bootloader; LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly); LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Connected device: Lumia", LogType.FileAndConsole); LogFile.Log("Mode: Bootloader", LogType.FileAndConsole); NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel)); } else { ((NokiaFlashModel)CurrentModel).DisableRebootTimeOut(); CurrentInterface = PhoneInterfaces.Lumia_Flash; LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly); LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Connected device: Lumia", LogType.FileAndConsole); LogFile.Log("Mode: Flash", LogType.FileAndConsole); NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel)); } } else if ((e.DevicePath.IndexOf(@"disk&ven_qualcomm&prod_mmc_storage", StringComparison.OrdinalIgnoreCase) >= 0) || (e.DevicePath.IndexOf(@"DISK&VEN_MSFT&PROD_PHONE_MMC_STOR", StringComparison.OrdinalIgnoreCase) >= 0)) { #if DEBUG LogFile.Log("Mass storage arrived: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Start new thread for getting metadata.", LogType.FileOnly); #endif // This function is possibly called by an USB notification WndProc. // It is not possible to invoke COM objects from a WndProc. // MassStorage uses ManagementObjectSearcher, which is a COM object. // Therefore we use a new thread. ThreadPool.QueueUserWorkItem(s => { lock (ModelLock) { if (!(CurrentModel is MassStorage)) { MassStorage NewModel = new MassStorage(e.DevicePath); if (NewModel.Drive != null) // When logical drive is already known, we use this model. Or else we wait for the logical drive to arrive. { CurrentInterface = PhoneInterfaces.Lumia_MassStorage; CurrentModel = NewModel; LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly); LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Connected device: Lumia", LogType.FileAndConsole); LogFile.Log("Mode: Mass storage mode", LogType.FileAndConsole); NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel)); } } } }); } else if ((e.DevicePath.Length == @"\\.\E:".Length) && (e.DevicePath.StartsWith(@"\\.\")) && (e.DevicePath.EndsWith(":"))) { #if DEBUG LogFile.Log("Mass storage arrived: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Start new thread for getting metadata.", LogType.FileOnly); #endif // This function is possibly called by an USB notification WndProc. // It is not possible to invoke COM objects from a WndProc. // MassStorage uses ManagementObjectSearcher, which is a COM object. // Therefore we use a new thread. ThreadPool.QueueUserWorkItem(s => { lock (ModelLock) { if (!(CurrentModel is MassStorage)) { MassStorage NewModel = new MassStorage(e.DevicePath); if (NewModel.Drive != null) // When logical drive is already known, we use this model. Or else we wait for the logical drive to arrive. { CurrentInterface = PhoneInterfaces.Lumia_MassStorage; CurrentModel = NewModel; LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly); LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Connected device: Lumia", LogType.FileAndConsole); LogFile.Log("Mode: Mass storage mode", LogType.FileAndConsole); NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel)); } } } }); } else if (e.DevicePath.IndexOf("VID_05C6&PID_9008", StringComparison.OrdinalIgnoreCase) >= 0) { USBDeviceInfo DeviceInfo = USBDevice.GetDevices(((USBNotifier)sender).Guid).Where((d) => string.Compare(d.DevicePath, e.DevicePath, true) == 0).FirstOrDefault(); if ((DeviceInfo.BusName == "QHSUSB_DLOAD") || (DeviceInfo.BusName == "QHSUSB__BULK") || ((DeviceInfo.BusName == "") && (LastInterface != PhoneInterfaces.Qualcomm_Download))) // TODO: Separate for Sahara! { CurrentInterface = PhoneInterfaces.Qualcomm_Download; CurrentModel = new QualcommSerial(e.DevicePath); NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel)); LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly); LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Connected device: Lumia", LogType.FileAndConsole); if (DeviceInfo.BusName == "") { LogFile.Log("Driver does not show busname, assume mode: Qualcomm Emergency Download 9008", LogType.FileAndConsole); } else { LogFile.Log("Mode: Qualcomm Emergency Download 9008", LogType.FileAndConsole); } } else if ((DeviceInfo.BusName == "QHSUSB_ARMPRG") || ((DeviceInfo.BusName == "") && (LastInterface == PhoneInterfaces.Qualcomm_Download))) { CurrentInterface = PhoneInterfaces.Qualcomm_Flash; CurrentModel = new QualcommSerial(e.DevicePath); NewDeviceArrived(new ArrivalEventArgs((PhoneInterfaces)CurrentInterface, CurrentModel)); LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly); LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Connected device: Lumia", LogType.FileAndConsole); if (DeviceInfo.BusName == "") { LogFile.Log("Driver does not show busname, assume mode: Qualcomm Emergency Flash 9008", LogType.FileAndConsole); } else { LogFile.Log("Mode: Qualcomm Emergency Flash 9008", LogType.FileAndConsole); } } } else if (e.DevicePath.IndexOf("VID_05C6&PID_9006", StringComparison.OrdinalIgnoreCase) >= 0) { // This is part of the Mass Storage inteface. // It is a slightly different version of the Qualcomm Emergency interface, which is implemented in SBL3. // One important difference is that the base address for sending a loader is not 0x2A000000, but it is 0x82F00000. LogFile.Log("Found device on interface: " + ((USBNotifier)sender).Guid.ToString(), LogType.FileOnly); LogFile.Log("Device path: " + e.DevicePath, LogType.FileOnly); LogFile.Log("Connected device: Lumia", LogType.FileAndConsole); LogFile.Log("Mode: Qualcomm Emergency 9006", LogType.FileAndConsole); } } catch (Exception Ex) { LogFile.LogException(Ex); CurrentModel = null; CurrentInterface = null; } }
private void ConnectionNotifier_Removal(object sender, USBEvent e) { logger.Warn("Device Disconnected"); }
private void OnDeviceRemoval(Object sender, USBEvent e) { RemoveDevice(e.DevicePath); }