Last active
August 29, 2015 14:03
-
-
Save tomac/5e903c563eef7ca0985b to your computer and use it in GitHub Desktop.
Suspender
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* Para poder intentar suspender un dispositivo USB, tenemos que hacer varias cosas siendo lo primero crear un diccionario con el vendorId y productId concreto al que queremos mandar la orden de suspender, y después de usar IOServiceGetMatchingServices para encontrarlo, entonces ya podemos abrir el dispositivo y lanzar la orden */ | |
| err = IOCreatePlugInInterfaceForService(usbService, kIOUSBDeviceUserClientTypeID, kIOCFPlugInInterfaceID, | |
| &pluginInterface, &score); | |
| CHECKRETURN(err, "No se he podido crear el plugin"); | |
| if(!pluginInterface) { | |
| fprintf(stderr, "No hay interfaz de plugin\n"); | |
| return -1; | |
| } | |
| /* Busquemos ahora a ver si encontramos el interfaz USB que necesitamos */ | |
| err = (*pluginInterface)->QueryInterface(pluginInterface, | |
| CFUUIDGetUUIDBytes(kIOUSBDeviceInterfaceID245), (LPVOID)&deviceInterface); | |
| IODestroyPlugInInterface(pluginInterface); | |
| /* Abrimos el dispositivo */ | |
| err = (*deviceInterface)->USBDeviceOpen(deviceInterface); | |
| CHECKRETURN(err, "Error abriendo el dispositivo"); | |
| /* Lanzamos la orden de suspender. USBDeviceSuspend también se utiliza para mandar la orden contraria de resume | |
| */ | |
| err = (*deviceInterface)->USBDeviceSuspend(deviceInterface, suspend); | |
| CHECKRETURN(err, "Error al suspender el dispositivo"); | |
| /* Cerramos el dispositivo */ | |
| err = (*deviceInterface)->USBDeviceClose(deviceInterface); | |
| CHECKRETURN(err, "Error cerrando el dispositivo"); | |
| err = (*deviceInterface)->Release(deviceInterface); | |
| CHECKRETURN(err, "Error haciendo el release"); | |
| /* Hacemos el release del servicio */ | |
| IOObjectRelease(usbService); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment