diff --git a/3rdparty/LogExtension.mm b/3rdparty/LogExtension.mm deleted file mode 100644 index 905c8c0ff..000000000 --- a/3rdparty/LogExtension.mm +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Copyright (C) 2009 by Matthias Ringwald - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holders nor the names of - * contributors may be used to endorse or promote products derived - * from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS - * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF - * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - */ -#import -#include -#include -#include -#include -#include -#include -#include - -// hooking part -#include "3rdparty/substrate.h" - -// hci_dump.h -typedef enum { - HCI_DUMP_BLUEZ = 0, - HCI_DUMP_PACKETLOGGER, - HCI_DUMP_RAW, - HCI_DUMP_STDOUT -} hci_dump_format_t; - -static void hci_dump_open(char *filename, hci_dump_format_t format); -static void hci_dump_packet(uint8_t packet_type, uint8_t in, uint8_t *packet, uint16_t len); -static void hci_dump_close(); - -// H5 Slip Decoder - -// h5 slip state machine -typedef enum { - unknown = 1, - decoding, - x_c0, - x_db -} state_t; - -typedef struct h5_slip { - state_t state; - uint16_t length; - uint8_t data[1000]; -} h5_slip_t; - -// Global State -static h5_slip_t read_sm; -static h5_slip_t write_sm; -static int bt_filedesc = 0; - -void h5_slip_init( h5_slip_t * sm){ - sm->state = unknown; -} - -void h5_slip_process( h5_slip_t * sm, uint8_t input, uint8_t in){ - uint8_t type; - switch (sm->state) { - case unknown: - if (input == 0xc0){ - sm->length = 0; - sm->state = x_c0; - } - break; - case x_c0: - switch (input ){ - case 0xc0: - break; - case 0xdb: - sm->state = x_db; - break; - default: - sm->data[sm->length] = input; - ++sm->length; - sm->state = decoding; - break; - } - break; - case decoding: - switch (input ){ - case 0xc0: - sm->state = unknown; - // packet done - check if valid HCI packet - if (sm->length < 6) break; - type = sm->data[1] & 0x0f; - if (type < 1 || type > 4) break; - hci_dump_packet( type, in, &sm->data[4], sm->length-4-2); // -4 header, -2 crc for reliable - break; - case 0xdb: - sm->state = x_db; - break; - default: - sm->data[sm->length] = input; - ++sm->length; - break; - } - break; - case x_db: - switch (input) { - case 0xdc: - sm->data[sm->length] = 0xc0; - ++sm->length; - sm->state = decoding; - break; - case 0xdd: - sm->data[sm->length] = 0xdb; - ++sm->length; - sm->state = decoding; - break; - default: - sm->state = unknown; - break; - } - break; - default: - break; - } -} - -MSHook(int, socket, int domain, int type, int protocol){ - // call orig - int res = _socket(domain, type, protocol); - - // socket(0x20, 0x1, 0x2); - if (domain == 0x20 && type == 0x01 && protocol == 0x02){ - printf("Opening BT device\n"); - bt_filedesc = res; - hci_dump_open( "/tmp/BTServer.pklg", HCI_DUMP_PACKETLOGGER); - h5_slip_init(&read_sm); - h5_slip_init(&write_sm); - } - return res; -} - -MSHook( ssize_t, write, int fildes, const void *buf, size_t nbyte){ - if (fildes && fildes == bt_filedesc && nbyte > 0){ - int16_t i; - for (i=0;i 0){ - int16_t i; - for (i=0;i> 8; -} - -static void bt_store_32(uint8_t *buffer, uint16_t pos, uint32_t value){ - buffer[pos++] = value; - buffer[pos++] = value >> 8; - buffer[pos++] = value >> 16; - buffer[pos++] = value >> 24; -} - -static void hexdump(void *data, int size){ - int i; - for (i=0; i "); - break; - case HCI_EVENT_PACKET: - printf("EVT <= "); - break; - case HCI_ACL_DATA_PACKET: - if (in) { - printf("ACL <= "); - } else { - printf("ACL => "); - } - break; - } - hexdump(packet, len); - break; - - case HCI_DUMP_BLUEZ: - bt_store_16( (uint8_t *) &header_bluez.len, 0, 1 + len); - header_bluez.in = in; - header_bluez.pad = 0; - bt_store_32( (uint8_t *) &header_bluez.ts_sec, 0, curr_time.tv_sec); - bt_store_32( (uint8_t *) &header_bluez.ts_usec, 0, curr_time.tv_usec); - header_bluez.packet_type = packet_type; - _write (dump_file, &header_bluez, sizeof(hcidump_hdr) ); - _write (dump_file, packet, len ); - break; - - case HCI_DUMP_PACKETLOGGER: - header_packetlogger.len = htonl( sizeof(pktlog_hdr) - 4 + len); - header_packetlogger.ts_sec = htonl(curr_time.tv_sec); - header_packetlogger.ts_usec = htonl(curr_time.tv_usec); - switch (packet_type){ - case HCI_COMMAND_DATA_PACKET: - header_packetlogger.type = 0x00; - break; - case HCI_ACL_DATA_PACKET: - if (in) { - header_packetlogger.type = 0x03; - } else { - header_packetlogger.type = 0x02; - } - break; - case HCI_EVENT_PACKET: - header_packetlogger.type = 0x01; - break; - default: - return; - } - _write (dump_file, &header_packetlogger, sizeof(pktlog_hdr) ); - _write (dump_file, packet, len ); - } -} - -static void hci_dump_close(){ - _close(dump_file); - dump_file = -1; -}