@@ -66,8 +66,6 @@ static KernelPatcher::KextInfo IntelBTPatcher_IOUsbHostInfo {
6666 KernelPatcher::KextInfo::Unloaded
6767};
6868
69- void *CIntelBTPatcher::_hookPipeInstance = nullptr ;
70- AsyncOwnerData *CIntelBTPatcher::_interruptPipeAsyncOwner = nullptr ;
7169bool CIntelBTPatcher::_randomAddressInit = false ;
7270
7371bool CIntelBTPatcher::init ()
@@ -130,45 +128,6 @@ void CIntelBTPatcher::processKext(KernelPatcher &patcher, size_t index, mach_vm_
130128 SYSLOG (DRV_NAME, " failed to resolve %s, error = %d" , hostDeviceRequest.symbol , patcher.getError ());
131129 patcher.clearError ();
132130 }
133-
134- KernelPatcher::RouteRequest asyncIORequest {
135- " __ZN13IOUSBHostPipe2ioEP18IOMemoryDescriptorjP19IOUSBHostCompletionj" ,
136- newAsyncIO,
137- oldAsyncIO
138- };
139- patcher.routeMultiple (index, &asyncIORequest, 1 , address, size);
140- if (patcher.getError () == KernelPatcher::Error::NoError) {
141- SYSLOG (DRV_NAME, " routed %s" , asyncIORequest.symbol );
142- } else {
143- SYSLOG (DRV_NAME, " failed to resolve %s, error = %d" , asyncIORequest.symbol , patcher.getError ());
144- patcher.clearError ();
145- }
146-
147- KernelPatcher::RouteRequest initPipeRequest {
148- " __ZN13IOUSBHostPipe28initWithDescriptorsAndOwnersEPKN11StandardUSB18EndpointDescriptorEPKNS0_37SuperSpeedEndpointCompanionDescriptorEP22AppleUSBHostControllerP15IOUSBHostDeviceP18IOUSBHostInterfaceht" ,
149- newInitPipe,
150- oldInitPipe
151- };
152- patcher.routeMultiple (index, &initPipeRequest, 1 , address, size);
153- if (patcher.getError () == KernelPatcher::Error::NoError) {
154- SYSLOG (DRV_NAME, " routed %s" , initPipeRequest.symbol );
155- } else {
156- SYSLOG (DRV_NAME, " failed to resolve %s, error = %d" , initPipeRequest.symbol , patcher.getError ());
157- patcher.clearError ();
158- }
159-
160- KernelPatcher::RouteRequest syncIORequest {
161- " __ZN13IOUSBHostPipe2ioEP18IOMemoryDescriptorjRjj" ,
162- newSyncIO,
163- oldSyncIO
164- };
165- patcher.routeMultiple (index, &syncIORequest, 1 , address, size);
166- if (patcher.getError () == KernelPatcher::Error::NoError) {
167- SYSLOG (DRV_NAME, " routed %s" , syncIORequest.symbol );
168- } else {
169- SYSLOG (DRV_NAME, " failed to resolve %s, error = %d" , syncIORequest.symbol , patcher.getError ());
170- patcher.clearError ();
171- }
172131 }
173132 }
174133}
@@ -233,12 +192,6 @@ IOReturn CIntelBTPatcher::newHostDeviceRequest(void *that, IOService *provider,
233192 SYSLOG (DRV_NAME, " [PATCH] Resend LE SCAN PARAM HCI %lld" , ret);
234193 }
235194 }
236- #if 0 // We don't need to fake Random address request to Public address, and it is not really fix the issue with Intel fatal firmware error after HCI_OP_LE_SET_SCAN_ENABLE.
237- else if (hdr->opcode == HCI_OP_LE_SET_SCAN_ENABLE) {
238- hdr->data[5] = 0x00;
239- SYSLOG(DRV_NAME, "[FAKE REQ]: RANDOM->PUBLIC done\n");
240- }
241- #endif
242195 } else {
243196 hdr = (HciCommandHdr *)data;
244197 hdrLen = request.wLength - 3 ;
@@ -260,80 +213,3 @@ IOReturn CIntelBTPatcher::newHostDeviceRequest(void *that, IOService *provider,
260213 }
261214 return FunctionCast (newHostDeviceRequest, callbackIBTPatcher->oldHostDeviceRequest )(that, provider, request, data, descriptor, length, completion, timeout);
262215}
263-
264- // Succeeded HCI command result of HCI_OP_LE_SET_SCAN_ENABLE, on Monterey+ this will return status 0x12 if we don't set the Random address before
265- const uint8_t fakeLEScanEnableResp[6 ] = {0x0E , 0x04 , 0x02 , 0x0C , 0x20 , 0x00 };
266-
267- static void asyncIOCompletion (void * owner, void * parameter, IOReturn status, uint32_t bytesTransferred)
268- {
269- AsyncOwnerData *asyncOwner = (AsyncOwnerData *)owner;
270- IOMemoryDescriptor* dataBuffer = asyncOwner->dataBuffer ;
271- DBGLOG (DRV_NAME, " [COMPLETE] status: %d bytesTransferred: %d" , status, bytesTransferred);
272- if (dataBuffer && bytesTransferred) {
273- void *buffer = IOMalloc (bytesTransferred);
274- dataBuffer->readBytes (0 , buffer, bytesTransferred);
275- const char *dump = _hexDumpHCIData ((uint8_t *)buffer, bytesTransferred);
276- if (dump) {
277- DBGLOG (DRV_NAME, " [Response]: %s" , dump);
278- IOFree ((void *)dump, bytesTransferred * 3 + 1 );
279- }
280- HciResponse *resp = (HciResponse *)buffer;
281- // This fake is not needed, after configured the Random Address, the firmware may not generate the error code 0x12 anymore. but we still leave it here
282- if (resp->opcode == HCI_OP_LE_SET_SCAN_ENABLE && resp->data [0 ]) {
283- SYSLOG (DRV_NAME, " [FAKE RESP]: done" );
284- dataBuffer->writeBytes (0 , fakeLEScanEnableResp, 6 );
285- }
286- IOFree (buffer, bytesTransferred);
287- }
288- if (asyncOwner->action )
289- asyncOwner->action (asyncOwner->owner , parameter, status, bytesTransferred);
290- }
291-
292- IOReturn CIntelBTPatcher::
293- newAsyncIO (void *that, IOMemoryDescriptor* dataBuffer, uint32_t dataBufferLength, IOUSBHostCompletion* completion, uint32_t completionTimeoutMs)
294- {
295- IOReturn ret = kIOReturnSuccess ;
296- if (that == _hookPipeInstance && completion) {
297- _interruptPipeAsyncOwner->action = completion->action ;
298- _interruptPipeAsyncOwner->owner = completion->owner ;
299- _interruptPipeAsyncOwner->dataBuffer = dataBuffer;
300- completion->action = asyncIOCompletion;
301- completion->owner = _interruptPipeAsyncOwner;
302- ret = FunctionCast (newAsyncIO, callbackIBTPatcher->oldAsyncIO )(that, dataBuffer, dataBufferLength, completion, completionTimeoutMs);
303- if (ret != kIOReturnSuccess )
304- SYSLOG (DRV_NAME, " %s failed ret: %lld" , __FUNCTION__, ret);
305- return ret;
306- }
307- return FunctionCast (newAsyncIO, callbackIBTPatcher->oldAsyncIO )(that, dataBuffer, dataBufferLength, completion, completionTimeoutMs);
308- }
309-
310- IOReturn CIntelBTPatcher::
311- newSyncIO (void *that, IOMemoryDescriptor *dataBuffer, uint32_t dataBufferLength, uint32_t &bytesTransferred, uint32_t completionTimeoutMs)
312- {
313- return FunctionCast (newSyncIO, callbackIBTPatcher->oldSyncIO )(that, dataBuffer, dataBufferLength, bytesTransferred, completionTimeoutMs);
314- }
315-
316- #define VENDOR_USB_INTEL 0x8087
317-
318- int CIntelBTPatcher::
319- newInitPipe (void *that, StandardUSB::EndpointDescriptor const *descriptor, StandardUSB::SuperSpeedEndpointCompanionDescriptor const *superDescriptor, AppleUSBHostController *controller, IOUSBHostDevice *device, IOUSBHostInterface *interface, unsigned char a7, unsigned short a8)
320- {
321- int ret = FunctionCast (newInitPipe, callbackIBTPatcher->oldInitPipe )(that, descriptor, superDescriptor, controller, device, interface, a7, a8);
322- if (device) {
323- const StandardUSB::DeviceDescriptor *deviceDescriptor = device->getDeviceDescriptor ();
324- if (deviceDescriptor &&
325- deviceDescriptor->idVendor == VENDOR_USB_INTEL) {
326- uint8_t epType = StandardUSB::getEndpointType (descriptor);
327- DBGLOG (DRV_NAME, " GOT YOU Intel bluetooth pid: %d ep type: %d" , deviceDescriptor->iProduct , epType);
328- if (epType == kIOUSBEndpointTypeInterrupt ) {
329- SYSLOG (DRV_NAME, " GOT YOU Interrupt PIPE" );
330- CIntelBTPatcher::_hookPipeInstance = that;
331- if (!CIntelBTPatcher::_interruptPipeAsyncOwner)
332- delete CIntelBTPatcher::_interruptPipeAsyncOwner;
333- CIntelBTPatcher::_interruptPipeAsyncOwner = new AsyncOwnerData;
334- CIntelBTPatcher::_randomAddressInit = false ;
335- }
336- }
337- }
338- return ret;
339- }
0 commit comments