void Wireless360Controller::SetRumbleMotors(unsigned char large, unsigned char small) { unsigned char buf[] = {0x00, 0x01, 0x0f, 0xc0, 0x00, large, small, 0x00, 0x00, 0x00, 0x00, 0x00}; WirelessDevice *device = OSDynamicCast(WirelessDevice, getProvider()); if (device != NULL) device->SendPacket(buf, sizeof(buf)); }
// Get a location ID for this device, as some games require it OSNumber* WirelessHIDDevice::newLocationIDNumber() const { WirelessDevice *device; device = OSDynamicCast(WirelessDevice, getProvider()); if (device == NULL) return NULL; return device->newLocationIDNumber(); }
// Shut down the driver void WirelessHIDDevice::handleStop(IOService *provider) { WirelessDevice *device; device = OSDynamicCast(WirelessDevice, provider); if (device != NULL) device->RegisterWatcher(NULL, NULL, NULL); super::handleStop(provider); }
void WirelessHIDDevice::PowerOff(void) { static const unsigned char buf[] = {0x00, 0x00, 0x08, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; WirelessDevice *device = OSDynamicCast(WirelessDevice, getProvider()); if (device != NULL) { device->SendPacket(buf, sizeof(buf)); // device->SendPacket(weirdStart, sizeof(weirdStart)); } }
// Sets the LED with the same format as the wired controller void WirelessHIDDevice::SetLEDs(int mode) { unsigned char buf[] = {0x00, 0x00, 0x08, (unsigned char)(0x40 + (mode % 0x0e)), 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; WirelessDevice *device = OSDynamicCast(WirelessDevice, getProvider()); if (device != NULL) { device->SendPacket(buf, sizeof(buf)); device->SendPacket(weirdStart, sizeof(weirdStart)); } }
// Handle new data from the device void WirelessHIDDevice::receivedData(void) { IOMemoryDescriptor *data; WirelessDevice *device = OSDynamicCast(WirelessDevice, getProvider()); if (device == NULL) return; while ((data = device->NextPacket()) != NULL) { receivedMessage(data); data->release(); } }
int main() { qDBusRegisterMetaType<NMVariantMapMap>(); QTextStream qout(stdout, QIODevice::WriteOnly); QTextStream qin(stdin, QIODevice::ReadOnly); Settings::ConnectionSettings *settings = new Settings::ConnectionSettings(Settings::ConnectionSettings::Wireless); DeviceList deviceList = NetworkManager::networkInterfaces(); WirelessDevice *wifiDevice = 0; // We have to find some wireless device foreach (Device *dev, deviceList) { if (dev->type() == Device::Wifi) { wifiDevice = qobject_cast<WirelessDevice *>(dev); break; } } if (!wifiDevice) { return 1; } QStringList accessPointList = wifiDevice->accessPoints(); QString ssid; QString result; QString accessPointPath; // Check for available accesspoint foreach (const QString &ap, accessPointList) { AccessPoint accessPoint(ap); // For simplification we use APs only with Wep security or without any security if (accessPoint.wpaFlags().testFlag(AccessPoint::PairWep40) || accessPoint.wpaFlags().testFlag(AccessPoint::PairWep104) || accessPoint.wpaFlags().testFlag(AccessPoint::GroupWep40) || accessPoint.wpaFlags().testFlag(AccessPoint::GroupWep104) || !accessPoint.wpaFlags()) { qout << "Do you want to connect to " << accessPoint.ssid() << "?" << endl; qout << "Yes/No: " << flush; qin >> result; if (result.toLower() == "yes" || result == "y") { ssid = accessPoint.ssid(); accessPointPath = ap; break; } }
// Start up the driver bool WirelessHIDDevice::handleStart(IOService *provider) { WirelessDevice *device; if (!super::handleStart(provider)) return false; device = OSDynamicCast(WirelessDevice, provider); if (device == NULL) return false; device->RegisterWatcher(this, _receivedData, NULL); device->SendPacket(weirdStart, sizeof(weirdStart)); return true; }
// Shut down the driver void WirelessHIDDevice::handleStop(IOService *provider) { WirelessDevice *device = OSDynamicCast(WirelessDevice, provider); if (device != NULL) device->RegisterWatcher(NULL, NULL, NULL); if (serialTimer != NULL) { serialTimer->cancelTimeout(); IOWorkLoop *workloop = getWorkLoop(); if (workloop != NULL) workloop->removeEventSource(serialTimer); serialTimer->release(); serialTimer = NULL; } super::handleStop(provider); }
// Start up the driver bool WirelessHIDDevice::handleStart(IOService *provider) { WirelessDevice *device; IOWorkLoop *workloop; if (!super::handleStart(provider)) goto fail; device = OSDynamicCast(WirelessDevice, provider); if (device == NULL) goto fail; serialTimerCount = 0; serialTimer = IOTimerEventSource::timerEventSource(this, ChatPadTimerActionWrapper); if (serialTimer == NULL) { IOLog("start - failed to create timer for chatpad\n"); goto fail; } workloop = getWorkLoop(); if ((workloop == NULL) || (workloop->addEventSource(serialTimer) != kIOReturnSuccess)) { IOLog("start - failed to connect timer for chatpad\n"); goto fail; } device->RegisterWatcher(this, _receivedData, NULL); device->SendPacket(weirdStart, sizeof(weirdStart)); serialTimer->setTimeoutMS(1000); return true; fail: return false; }