src/patch.c
__attribute__((at(0x00210700, "", CHIP_VER_BCM4375B1_BT, FW_VER_S20)))
__attribute__((optimize("O0")))
__attribute__((naked))
void rx_callback(int* func) {
   	__asm__("push {r4-r11,lr}\n\t");
	if (rx_enabled != 0) {

		if ((*((int*)0x318bac) & 256) && (rx_done == 0)){
			memsetbt(raw_buffer,0,255);
			memcpybt_8(raw_buffer,(void*)(0x372400),255);

			if (rx_enabled == 1) {
				decode(buffer_decoded,&buffer_decoded_size,raw_buffer);
				if (buffer_decoded_size > 0 && buffer_decoded_size < 60) {
					char* buffer = bthci_event_AllocateEventAndFillHeader(buffer_decoded_size+2+2, 0xff, buffer_decoded_size+2);
					buffer[10]  =(uint8_t)rx_enabled;
					buffer[11]  =(uint8_t)rx_frequency;
					memcpybt(&buffer[12],buffer_decoded,buffer_decoded_size);
					// Forge HCI response and send it to host
					bthci_event_AttemptToEnqueueEventToTransport(buffer);
				}
			}
			else if (rx_enabled == 2 ) {
				decode_mosart(buffer_decoded,&buffer_decoded_size,raw_buffer);

				if (check_frame(buffer_decoded,buffer_decoded_size,&start_mosart_frame)) {
					char* buffer = bthci_event_AllocateEventAndFillHeader(buffer_decoded_size-start_mosart_frame+4+2+2, 0xff, buffer_decoded_size-start_mosart_frame+4+2);
					buffer[10]  =(uint8_t)rx_enabled;
					buffer[11]  =(uint8_t)rx_frequency;
					memcpybt(&buffer[12],buffer_decoded+start_mosart_frame-4,buffer_decoded_size-start_mosart_frame+4);
					// Forge HCI response and send it to host
					bthci_event_AttemptToEnqueueEventToTransport(buffer);		
				}
			}
			else if (rx_enabled == 3) {
				decode_mosart(buffer_decoded,&buffer_decoded_size,raw_buffer+1);
				char* buffer = bthci_event_AllocateEventAndFillHeader(1+2+2, 0xff, 1+2);
				buffer[10]  =(uint8_t)rx_enabled;
				buffer[11]  =(uint8_t)rx_frequency;			
				memcpybt(&buffer[12],buffer_decoded,1);
				// Forge HCI response and send it to host
				bthci_event_AttemptToEnqueueEventToTransport(buffer);
				
			}
			else if (rx_enabled == 4) {
				decode_mosart(buffer_decoded,&buffer_decoded_size,raw_buffer);

				if (check_frame(buffer_decoded,buffer_decoded_size,&start_mosart_frame)) {
					if ((buffer_decoded[start_mosart_frame-4+0] == (preamble & 0xFF) && buffer_decoded[start_mosart_frame-4+1] == ((preamble & 0xFF00) >> 8) && buffer_decoded[start_mosart_frame-4+2] == ((preamble & 0xFF0000) >> 16) && buffer_decoded[start_mosart_frame-4+3] == ((preamble & 0xFF000000) >> 24))) {
						char* buffer = bthci_event_AllocateEventAndFillHeader(buffer_decoded_size-start_mosart_frame+4+2+2, 0xff, buffer_decoded_size-start_mosart_frame+4+2);
						buffer[10]  =(uint8_t)rx_enabled;
						buffer[11]  =(uint8_t)rx_frequency;
						memcpybt(&buffer[12],buffer_decoded+start_mosart_frame-4,buffer_decoded_size-start_mosart_frame+4);
						// Forge HCI response and send it to host
						bthci_event_AttemptToEnqueueEventToTransport(buffer);		
					}
				}
			}
			else if (rx_enabled == 5) {
				for (int i=0;i<200;i++) raw_buffer[i] = swap_bits(raw_buffer[i]);

				char* buffer = bthci_event_AllocateEventAndFillHeader(5+2+2, 0xff,5+2);
				buffer[10]  =(uint8_t)rx_enabled;
				buffer[11]  =(uint8_t)rx_frequency;
				buffer[12] = swap_bits((rx_header & 0xFF));
				buffer[13] = swap_bits((rx_header & 0xFF00) >> 8);
				memcpybt(&buffer[14],raw_buffer,3);	
				// Forge HCI response and send it to host
				bthci_event_AttemptToEnqueueEventToTransport(buffer);								
			}
			else if (rx_enabled == 6) {
				for (int i=0;i<200;i++) raw_buffer[i] = swap_bits(raw_buffer[i]);

				buffer_decoded_size = extract_payload_esb(raw_buffer,buffer_decoded);

				char* buffer = bthci_event_AllocateEventAndFillHeader(buffer_decoded_size+2+2, 0xff,buffer_decoded_size+2);
				buffer[10]  =(uint8_t)rx_enabled;
				buffer[11]  =(uint8_t)rx_frequency;
				
				
				memcpybt(&buffer[12],buffer_decoded,buffer_decoded_size);	
				// Forge HCI response and send it to host
				bthci_event_AttemptToEnqueueEventToTransport(buffer);								
			}
			rx_done = 1;
		}
		else {
			rx_done = 0; 
		}
	}
   	__asm__("pop {r4-r11,lr}\n\t"
		"push.w {r4-r8,lr}\n\t"
		"b 0x7C890\n\t"
	);
}
/*
Main RX callback : handles every RX mode, applies the different operations allowing to decode / convert the received frames, tranmits to the Host
*/
Main RX callback : handles every RX mode, applies the different operations allowing to decode / convert the received frames, tranmits to the Host
Main RX callback : handles every RX mode applies the different operations allowing to decode / convert the received frames tranmits to the Host
__attribute__((at(0x00210700, "", CHIP_VER_BCM4375B1_BT, FW_VER_S20)))
__attribute__((optimize("O0")))
__attribute__((naked))
void rx_callback(int* func) {
   	__asm__("push {r4-r11,lr}\n\t");
	if (rx_enabled != 0) {
		if ((*((int*)0x318bac) & 256) && (rx_done == 0)){
			memsetbt(raw_buffer,0,255);
			memcpybt_8(raw_buffer,(void*)(0x372400),255);
			if (rx_enabled == 1) {
				decode(buffer_decoded,&buffer_decoded_size,raw_buffer);
				if (buffer_decoded_size > 0 && buffer_decoded_size < 60) {
					char* buffer = bthci_event_AllocateEventAndFillHeader(buffer_decoded_size+2+2, 0xff, buffer_decoded_size+2);
					buffer[10]  =(uint8_t)rx_enabled;
					buffer[11]  =(uint8_t)rx_frequency;
					memcpybt(&buffer[12],buffer_decoded,buffer_decoded_size);
					bthci_event_AttemptToEnqueueEventToTransport(buffer);
				}
			}
			else if (rx_enabled == 2 ) {
				decode_mosart(buffer_decoded,&buffer_decoded_size,raw_buffer);
				if (check_frame(buffer_decoded,buffer_decoded_size,&start_mosart_frame)) {
					char* buffer = bthci_event_AllocateEventAndFillHeader(buffer_decoded_size-start_mosart_frame+4+2+2, 0xff, buffer_decoded_size-start_mosart_frame+4+2);
					buffer[10]  =(uint8_t)rx_enabled;
					buffer[11]  =(uint8_t)rx_frequency;
					memcpybt(&buffer[12],buffer_decoded+start_mosart_frame-4,buffer_decoded_size-start_mosart_frame+4);
					bthci_event_AttemptToEnqueueEventToTransport(buffer);		
				}
			}
			else if (rx_enabled == 3) {
				decode_mosart(buffer_decoded,&buffer_decoded_size,raw_buffer+1);
				char* buffer = bthci_event_AllocateEventAndFillHeader(1+2+2, 0xff, 1+2);
				buffer[10]  =(uint8_t)rx_enabled;
				buffer[11]  =(uint8_t)rx_frequency;			
				memcpybt(&buffer[12],buffer_decoded,1);
				bthci_event_AttemptToEnqueueEventToTransport(buffer);
			}
			else if (rx_enabled == 4) {
				decode_mosart(buffer_decoded,&buffer_decoded_size,raw_buffer);
				if (check_frame(buffer_decoded,buffer_decoded_size,&start_mosart_frame)) {
					if ((buffer_decoded[start_mosart_frame-4+0] == (preamble & 0xFF) && buffer_decoded[start_mosart_frame-4+1] == ((preamble & 0xFF00) >> 8) && buffer_decoded[start_mosart_frame-4+2] == ((preamble & 0xFF0000) >> 16) && buffer_decoded[start_mosart_frame-4+3] == ((preamble & 0xFF000000) >> 24))) {
						char* buffer = bthci_event_AllocateEventAndFillHeader(buffer_decoded_size-start_mosart_frame+4+2+2, 0xff, buffer_decoded_size-start_mosart_frame+4+2);
						buffer[10]  =(uint8_t)rx_enabled;
						buffer[11]  =(uint8_t)rx_frequency;
						memcpybt(&buffer[12],buffer_decoded+start_mosart_frame-4,buffer_decoded_size-start_mosart_frame+4);
						bthci_event_AttemptToEnqueueEventToTransport(buffer);		
					}
				}
			}
			else if (rx_enabled == 5) {
				for (int i=0;i<200;i++) raw_buffer[i] = swap_bits(raw_buffer[i]);
				char* buffer = bthci_event_AllocateEventAndFillHeader(5+2+2, 0xff,5+2);
				buffer[10]  =(uint8_t)rx_enabled;
				buffer[11]  =(uint8_t)rx_frequency;
				buffer[12] = swap_bits((rx_header & 0xFF));
				buffer[13] = swap_bits((rx_header & 0xFF00) >> 8);
				memcpybt(&buffer[14],raw_buffer,3);	
				bthci_event_AttemptToEnqueueEventToTransport(buffer);								
			}
			else if (rx_enabled == 6) {
				for (int i=0;i<200;i++) raw_buffer[i] = swap_bits(raw_buffer[i]);
				buffer_decoded_size = extract_payload_esb(raw_buffer,buffer_decoded);
				char* buffer = bthci_event_AllocateEventAndFillHeader(buffer_decoded_size+2+2, 0xff,buffer_decoded_size+2);
				buffer[10]  =(uint8_t)rx_enabled;
				buffer[11]  =(uint8_t)rx_frequency;
				memcpybt(&buffer[12],buffer_decoded,buffer_decoded_size);	
				bthci_event_AttemptToEnqueueEventToTransport(buffer);								
			}
			rx_done = 1;
		}
		else {
			rx_done = 0; 
		}
	}
   	__asm__("pop {r4-r11,lr}\n\t"
		"push.w {r4-r8,lr}\n\t"
		"b 0x7C890\n\t"
	);
}
__attribute__ ( ( at ( 0x00210700 , " " , CHIP_VER_BCM4375B1_BT , FW_VER_S20 ) ) ) __attribute__ ( ( optimize ( " " ) ) ) __attribute__ ( ( naked ) ) void rx_callback ( int * func ) { __asm__ ( " \n \t " ) ; if ( rx_enabled != 0 ) { if ( ( * ( ( int * ) 0x318bac ) & 256 ) && ( rx_done == 0 ) ) { memsetbt ( raw_buffer , 0 , 255 ) ; memcpybt_8 ( raw_buffer , ( void * ) ( 0x372400 ) , 255 ) ; if ( rx_enabled == 1 ) { decode ( buffer_decoded , & buffer_decoded_size , raw_buffer ) ; if ( buffer_decoded_size > 0 && buffer_decoded_size < 60 ) { char * buffer = bthci_event_AllocateEventAndFillHeader ( buffer_decoded_size + 2 + 2 , 0xff , buffer_decoded_size + 2 ) ; buffer [ 10 ] = ( uint8_t ) rx_enabled ; buffer [ 11 ] = ( uint8_t ) rx_frequency ; memcpybt ( & buffer [ 12 ] , buffer_decoded , buffer_decoded_size ) ; bthci_event_AttemptToEnqueueEventToTransport ( buffer ) ; } } else if ( rx_enabled == 2 ) { decode_mosart ( buffer_decoded , & buffer_decoded_size , raw_buffer ) ; if ( check_frame ( buffer_decoded , buffer_decoded_size , & start_mosart_frame ) ) { char * buffer = bthci_event_AllocateEventAndFillHeader ( buffer_decoded_size - start_mosart_frame + 4 + 2 + 2 , 0xff , buffer_decoded_size - start_mosart_frame + 4 + 2 ) ; buffer [ 10 ] = ( uint8_t ) rx_enabled ; buffer [ 11 ] = ( uint8_t ) rx_frequency ; memcpybt ( & buffer [ 12 ] , buffer_decoded + start_mosart_frame - 4 , buffer_decoded_size - start_mosart_frame + 4 ) ; bthci_event_AttemptToEnqueueEventToTransport ( buffer ) ; } } else if ( rx_enabled == 3 ) { decode_mosart ( buffer_decoded , & buffer_decoded_size , raw_buffer + 1 ) ; char * buffer = bthci_event_AllocateEventAndFillHeader ( 1 + 2 + 2 , 0xff , 1 + 2 ) ; buffer [ 10 ] = ( uint8_t ) rx_enabled ; buffer [ 11 ] = ( uint8_t ) rx_frequency ; memcpybt ( & buffer [ 12 ] , buffer_decoded , 1 ) ; bthci_event_AttemptToEnqueueEventToTransport ( buffer ) ; } else if ( rx_enabled == 4 ) { decode_mosart ( buffer_decoded , & buffer_decoded_size , raw_buffer ) ; if ( check_frame ( buffer_decoded , buffer_decoded_size , & start_mosart_frame ) ) { if ( ( buffer_decoded [ start_mosart_frame - 4 + 0 ] == ( preamble & 0xFF ) && buffer_decoded [ start_mosart_frame - 4 + 1 ] == ( ( preamble & 0xFF00 ) >> 8 ) && buffer_decoded [ start_mosart_frame - 4 + 2 ] == ( ( preamble & 0xFF0000 ) >> 16 ) && buffer_decoded [ start_mosart_frame - 4 + 3 ] == ( ( preamble & 0xFF000000 ) >> 24 ) ) ) { char * buffer = bthci_event_AllocateEventAndFillHeader ( buffer_decoded_size - start_mosart_frame + 4 + 2 + 2 , 0xff , buffer_decoded_size - start_mosart_frame + 4 + 2 ) ; buffer [ 10 ] = ( uint8_t ) rx_enabled ; buffer [ 11 ] = ( uint8_t ) rx_frequency ; memcpybt ( & buffer [ 12 ] , buffer_decoded + start_mosart_frame - 4 , buffer_decoded_size - start_mosart_frame + 4 ) ; bthci_event_AttemptToEnqueueEventToTransport ( buffer ) ; } } } else if ( rx_enabled == 5 ) { for ( int i = 0 ; i < 200 ; i ++ ) raw_buffer [ i ] = swap_bits ( raw_buffer [ i ] ) ; char * buffer = bthci_event_AllocateEventAndFillHeader ( 5 + 2 + 2 , 0xff , 5 + 2 ) ; buffer [ 10 ] = ( uint8_t ) rx_enabled ; buffer [ 11 ] = ( uint8_t ) rx_frequency ; buffer [ 12 ] = swap_bits ( ( rx_header & 0xFF ) ) ; buffer [ 13 ] = swap_bits ( ( rx_header & 0xFF00 ) >> 8 ) ; memcpybt ( & buffer [ 14 ] , raw_buffer , 3 ) ; bthci_event_AttemptToEnqueueEventToTransport ( buffer ) ; } else if ( rx_enabled == 6 ) { for ( int i = 0 ; i < 200 ; i ++ ) raw_buffer [ i ] = swap_bits ( raw_buffer [ i ] ) ; buffer_decoded_size = extract_payload_esb ( raw_buffer , buffer_decoded ) ; char * buffer = bthci_event_AllocateEventAndFillHeader ( buffer_decoded_size + 2 + 2 , 0xff , buffer_decoded_size + 2 ) ; buffer [ 10 ] = ( uint8_t ) rx_enabled ; buffer [ 11 ] = ( uint8_t ) rx_frequency ; memcpybt ( & buffer [ 12 ] , buffer_decoded , buffer_decoded_size ) ; bthci_event_AttemptToEnqueueEventToTransport ( buffer ) ; } rx_done = 1 ; } else { rx_done = 0 ; } } __asm__ ( " \n \t " " \n \t " " \n \t " ) ; }
Main RX callback : handles every RX mode, applies the different operations allowing to decode / convert the received frames, tranmits to the Host
Main RX callback : handles every RX mode applies the different operations allowing to decode / convert the received frames tranmits to the Host
// Forge HCI response and send it to host // Forge HCI response and send it to host // Forge HCI response and send it to host // Forge HCI response and send it to host // Forge HCI response and send it to host // Forge HCI response and send it to host