Skip to content

Commit

Permalink
Continue working on wireless support
Browse files Browse the repository at this point in the history
  • Loading branch information
Drewbadour committed Apr 30, 2019
1 parent 9b296f5 commit 9f6c0e4
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 55 deletions.
12 changes: 5 additions & 7 deletions 360Controller/_60Controller.cpp
Expand Up @@ -373,8 +373,6 @@ bool Xbox360Peripheral::start(IOService* provider)
IOWorkLoop* workloop = nullptr;
XBOX360_OUT_LED led = {};

kprintf("Hello world.\n");

if (!super::start(provider))
{
kprintf("start - Failed super start method.\n");
Expand Down Expand Up @@ -459,7 +457,7 @@ bool Xbox360Peripheral::start(IOService* provider)
if (interfaceCandidate != nullptr)
{
const StandardUSB::InterfaceDescriptor* id = interfaceCandidate->getInterfaceDescriptor();
// kprintf("%d, %d, %d\n", id->bInterfaceClass, id->bInterfaceSubClass, id->bInterfaceProtocol);
// kprintf("%d, %d, %d\n", id->bInterfaceClass, id->bInterfaceSubClass, id->bInterfaceProtocol); // TODO(Drew): Delete me
if (id->bInterfaceSubClass == 93)
{
if (id->bInterfaceProtocol == 1)
Expand Down Expand Up @@ -525,7 +523,7 @@ bool Xbox360Peripheral::start(IOService* provider)
UInt8 pipeDirection = StandardUSB::getEndpointDirection(pipe);
UInt8 pipeType = StandardUSB::getEndpointType(pipe);

kprintf("Pipe type: %d, pipe direction: %d\n", pipeDirection, pipeType);
kprintf("Pipe type: %d, pipe direction: %d\n", pipeDirection, pipeType); // TODO(Drew): Delete me

if ((pipeDirection == kEndpointDirectionIn) && (pipeType == kEndpointTypeInterrupt))
{
Expand Down Expand Up @@ -588,7 +586,7 @@ bool Xbox360Peripheral::start(IOService* provider)
UInt8 pipeDirection = StandardUSB::getEndpointDirection(pipe);
UInt8 pipeType = StandardUSB::getEndpointType(pipe);

kprintf("Chatpad pipe type: %d, pipe direction: %d\n", pipeDirection, pipeType);
kprintf("Chatpad pipe type: %d, pipe direction: %d\n", pipeDirection, pipeType); // TODO(Drew): Delete me

if ((pipeDirection == kEndpointDirectionIn) && (pipeType == kEndpointTypeInterrupt))
{
Expand Down Expand Up @@ -683,13 +681,13 @@ bool Xbox360Peripheral::start(IOService* provider)
}

// Done
kprintf("Pass.\n");
kprintf("Pass.\n"); // TODO(Drew):
PadConnect();
registerService();
return true;

fail:
kprintf("Fail.\n");
kprintf("Fail.\n"); // TODO(Drew):
ReleaseAll();
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion Install360Controller/Text/Welcome.rtf
Expand Up @@ -41,7 +41,7 @@
\f0\b\fs42 \cf0 Xbox 360 Controller Driver\
\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\pardirnatural\partightenfactor0
\f1\b0\fs24 \cf0 Version 0.16.11\
\f1\b0\fs24 \cf0 Version 1.0.0\
Copyright \'a9 2005\'962013 Colin Munro\
Copyright \'a9 2013\'962019 {\field{\*\fldinst{HYPERLINK "https://github.com/360Controller/360Controller/graphs/contributors"}}{\fldrslt 360Controller contributors}}\
\
Expand Down
94 changes: 49 additions & 45 deletions WirelessGamingReceiver/WirelessGamingReceiver.cpp
Expand Up @@ -60,25 +60,26 @@ bool WirelessGamingReceiver::start(IOService* provider)
int iConnection, iOther, i;
OSIterator* iterator = nullptr;
OSObject* candidate = nullptr;
IOReturn error = kIOReturnError;

if (!IOService::start(provider))
{
// IOLog("start - superclass failed\n");
kprintf("start - superclass failed\n");
return false;
}

device = OSDynamicCast(IOUSBHostDevice, provider);
if (device == nullptr)
{
// IOLog("start - invalid provider\n");
kprintf("start - invalid provider\n");
goto fail;
}

// Check for configurations
if (device->getDeviceDescriptor()->bNumConfigurations < 1)
{
device = nullptr;
// IOLog("start - device has no configurations!\n");
kprintf("start - device has no configurations!\n");
goto fail;
}

Expand All @@ -87,19 +88,23 @@ bool WirelessGamingReceiver::start(IOService* provider)
if (cd == nullptr)
{
device = nullptr;
// IOLog("start - couldn't get configuration descriptor\n");
kprintf("start - couldn't get configuration descriptor\n");
goto fail;
}

if (!device->open(this))
{
device = nullptr;
// IOLog("start - failed to open device\n");
kprintf("start - failed to open device\n");
goto fail;
}
if (device->setConfiguration(cd->bConfigurationValue, true) != kIOReturnSuccess)

// if (device->setConfiguration(cd->bConfigurationValue, true) != kIOReturnSuccess)
error = device->setConfiguration(cd->bConfigurationValue, true);
if (error != kIOReturnSuccess)
{
// IOLog("start - unable to set configuration\n");
// kprintf("start - unable to set configuration\n");
kprintf("start - unable to set configuration with error: %x\n", error);
goto fail;
}

Expand All @@ -124,6 +129,7 @@ bool WirelessGamingReceiver::start(IOService* provider)
IOUSBHostInterface* interfaceCandidate = OSDynamicCast(IOUSBHostInterface, candidate);
if (interfaceCandidate != nullptr)
{
// TODO(Drew): There's a bunch of duplicated code in here. Can we pull it out? What makes these two different?
switch (interfaceCandidate->getInterfaceDescriptor()->bInterfaceProtocol)
{
case 129: // Controller
Expand All @@ -132,51 +138,49 @@ bool WirelessGamingReceiver::start(IOService* provider)

if (!interfaceCandidate->open(this))
{
// IOLog("start: Failed to open control interface\n");
kprintf("start - failed to open control interface\n");
goto fail;
}
connections[iConnection].controller = interfaceCandidate;

cd = interfaceCandidate->getConfigurationDescriptor();
intf = interfaceCandidate->getInterfaceDescriptor();

if (!cd || !intf)
{
kprintf("start - Can't get configuration descriptor and interface descriptor.\n");
goto fail;
}

while ((pipe = StandardUSB::getNextEndpointDescriptor(cd, intf, pipe)))
{
UInt8 pipeDirection = StandardUSB::getEndpointDirection(pipe);
UInt8 pipeType = StandardUSB::getEndpointType(pipe);

kprintf("Pipe type: %d, pipe direction: %d\n", pipeDirection, pipeType); // TODO(Drew): Delete me

if (pipeDirection == kEndpointDirectionIn)
if ((pipeDirection == kEndpointDirectionIn) && (pipeType == kEndpointTypeInterrupt))
{
connections[iConnection].controllerIn = interfaceCandidate->copyPipe(StandardUSB::getEndpointAddress(pipe));
}
else if (pipeDirection == kEndpointDirectionOut)
else if ((pipeDirection == kEndpointDirectionOut) && (pipeType == kEndpointTypeInterrupt))
{
connections[iConnection].controllerOut = interfaceCandidate->copyPipe(StandardUSB::getEndpointAddress(pipe));
}
}

if (connections[iConnection].controllerIn == nullptr)
{
// IOLog("start: Failed to open control input pipe\n");
kprintf("start - Failed to open control input pipe\n");
goto fail;
}
else
{
connections[iConnection].controllerIn->retain();
}
connections[iConnection].controllerIn->retain();

if (connections[iConnection].controllerOut == nullptr)
{
// IOLog("start: Failed to open control output pipe\n");
kprintf("start - Failed to open control output pipe\n");
goto fail;
}
else
{
connections[iConnection].controllerOut->retain();
}
connections[iConnection].controllerOut->retain();

iConnection++;
} break;
Expand All @@ -186,59 +190,56 @@ bool WirelessGamingReceiver::start(IOService* provider)
pipe = nullptr;
if (!interfaceCandidate->open(this))
{
// IOLog("start: Failed to open mystery interface\n");
kprintf("start - Failed to open mystery interface\n");
goto fail;
}
connections[iOther].other = interfaceCandidate;

cd = interfaceCandidate ->getConfigurationDescriptor();
intf = interfaceCandidate->getInterfaceDescriptor();

if (!cd || !intf)
{
kprintf("start - Can't get configuration descriptor and interface descriptor.\n");
goto fail;
}

while ((pipe = StandardUSB::getNextEndpointDescriptor(cd, intf, pipe)))
{
UInt8 pipeDirection = StandardUSB::getEndpointDirection(pipe);

if (pipeDirection == kEndpointDirectionIn)
UInt8 pipeType = StandardUSB::getEndpointType(pipe);

kprintf("Pipe type: %d, pipe direction: %d\n", pipeDirection, pipeType); // TODO(Drew): Delete me

if ((pipeDirection == kEndpointDirectionIn) && (pipeType == kEndpointTypeInterrupt))
{
connections[iConnection].otherIn = interfaceCandidate->copyPipe(StandardUSB::getEndpointAddress(pipe));
connections[iOther].controllerIn = interfaceCandidate->copyPipe(StandardUSB::getEndpointAddress(pipe));
}
else if (pipeDirection == kEndpointDirectionOut)
else if ((pipeDirection == kEndpointDirectionOut) && (pipeType == kEndpointTypeInterrupt))
{
connections[iConnection].otherOut = interfaceCandidate->copyPipe(StandardUSB::getEndpointAddress(pipe));
connections[iOther].controllerOut = interfaceCandidate->copyPipe(StandardUSB::getEndpointAddress(pipe));
}
}

if (connections[iConnection].controllerIn == nullptr)
if (connections[iOther].controllerIn == nullptr)
{
// IOLog("start: Failed to open control input pipe\n");
kprintf("start: Failed to open control input pipe\n");
goto fail;
}
else
{
connections[iConnection].controllerIn->retain();
}
connections[iOther].controllerIn->retain();

if (connections[iConnection].controllerOut == nullptr)
if (connections[iOther].controllerOut == nullptr)
{
// IOLog("start: Failed to open control output pipe\n");
kprintf("start: Failed to open control output pipe\n");
goto fail;
}
else
{
connections[iConnection].controllerOut->retain();
}
connections[iOther].controllerOut->retain();

iOther++;
} break;

default:
{
// IOLog("start: Ignoring interface (protocol %d)\n", interface->GetInterfaceProtocol());
kprintf("start: Ignoring interface (protocol %d)\n", interfaceCandidate->getInterfaceDescriptor()->bInterfaceProtocol);
} break;
}
}
Expand All @@ -247,7 +248,7 @@ bool WirelessGamingReceiver::start(IOService* provider)

if (iConnection != iOther)
{
IOLog("start - interface mismatch?\n");
kprintf("start - interface mismatch?\n");
}
connectionCount = iConnection;

Expand All @@ -256,17 +257,17 @@ bool WirelessGamingReceiver::start(IOService* provider)
connections[i].inputArray = OSArray::withCapacity(5);
if (connections[i].inputArray == nullptr)
{
// IOLog("start: Failed to allocate packet buffer %d\n", i);
kprintf("start - Failed to allocate packet buffer %d\n", i);
goto fail;
}
if (!QueueRead(i))
{
// IOLog("start: Failed to start read %d\n", i);
kprintf("start - Failed to start read %d\n", i);
goto fail;
}
}

// IOLog("start: Transform and roll out (%d interfaces)\n", connectionCount);
kprintf("start - Transform and roll out (%d interfaces)\n", connectionCount);
return true;

fail:
Expand Down Expand Up @@ -631,11 +632,13 @@ void WirelessGamingReceiver::InstantiateService(int index)
OSNumber::withNumber((unsigned long long)0, 32),
};
OSDictionary* dictionary = OSDictionary::withObjects(objects, keys, 1, 0);
kprintf("InstantiateService - attempting to init device.\n");
if (connections[index].service->init(dictionary))
{
connections[index].service->attach(this);
connections[index].service->SetIndex(index);
// connections[index].service->registerService();
kprintf("InstantiateService - attahed device.\n");
// IOLog("process: Device attached\n");
if (IsDataQueued(index))
{
Expand All @@ -647,6 +650,7 @@ void WirelessGamingReceiver::InstantiateService(int index)
{
connections[index].service->release();
connections[index].service = nullptr;
kprintf("InstantiateService - device attach failure.\n");
// IOLog("process: Device attach failure\n");
}
}
Expand Down
6 changes: 4 additions & 2 deletions WirelessGamingReceiver/WirelessHIDDevice.cpp
Expand Up @@ -127,12 +127,14 @@ bool WirelessHIDDevice::handleStart(IOService* provider)

if (!super::handleStart(provider))
{
kprintf("handleStart - super failed to handle start.\n");
goto fail;
}

device = OSDynamicCast(WirelessDevice, provider);
if (device == nullptr)
{
kprintf("handleStart - device was null.\n");
goto fail;
}

Expand All @@ -141,14 +143,14 @@ bool WirelessHIDDevice::handleStart(IOService* provider)
serialTimer = IOTimerEventSource::timerEventSource(this, ChatPadTimerActionWrapper);
if (serialTimer == nullptr)
{
IOLog("start - failed to create timer for chatpad\n");
IOLog("handleStart - failed to create timer for chatpad\n");
goto fail;
}

workloop = getWorkLoop();
if ((workloop == nullptr) || (workloop->addEventSource(serialTimer) != kIOReturnSuccess))
{
IOLog("start - failed to connect timer for chatpad\n");
IOLog("handleStart - failed to connect timer for chatpad\n");
goto fail;
}

Expand Down

0 comments on commit 9f6c0e4

Please sign in to comment.