(BTPad) Cleanups

This commit is contained in:
twinaphex 2014-10-05 00:58:47 +02:00
parent a8ef8ff7e4
commit fdbb5af441
8 changed files with 155 additions and 105 deletions

View File

@ -73,8 +73,6 @@ bool btstack_try_load(void)
if (btstack_tested) if (btstack_tested)
return btstack_loaded; return btstack_loaded;
RARCH_LOG("BTstack: Attempting to load\n");
btstack_tested = true; btstack_tested = true;
btstack_loaded = false; btstack_loaded = false;
@ -82,8 +80,7 @@ bool btstack_try_load(void)
if (!btstack) if (!btstack)
{ {
RARCH_LOG("BTstack: /usr/lib/libBTstack.dylib not loadable\n"); RARCH_ERR("[BTstack]: Not loaded\n");
RARCH_LOG("BTstack: Not loaded\n");
return false; return false;
} }
@ -93,9 +90,8 @@ bool btstack_try_load(void)
if (!*grabbers[i].target) if (!*grabbers[i].target)
{ {
RARCH_LOG("BTstack: Symbol %s not found in /usr/lib/libBTstack.dylib\n", grabbers[i].name); RARCH_ERR("[BTstack]: Symbol %s not found, not loaded.\n", grabbers[i].name);
RARCH_LOG("BTstack: Not loaded\n");
dlclose(btstack); dlclose(btstack);
return false; return false;
} }
@ -104,7 +100,7 @@ bool btstack_try_load(void)
run_loop_init_ptr(RUN_LOOP_COCOA); run_loop_init_ptr(RUN_LOOP_COCOA);
bt_register_packet_handler_ptr(btpad_packet_handler); bt_register_packet_handler_ptr(btpad_packet_handler);
RARCH_LOG("BTstack: Loaded\n"); RARCH_LOG("[BTstack]: Loaded.\n");
btstack_loaded = true; btstack_loaded = true;
return true; return true;

View File

@ -43,7 +43,9 @@ struct pad_connection
bd_addr_t address; bd_addr_t address;
uint16_t handle; uint16_t handle;
uint16_t channels[2]; /* 0: Control, 1: Interrupt */
/* 0: Control, 1: Interrupt */
uint16_t channels[2];
}; };
static bool inquiry_off; static bool inquiry_off;
@ -149,7 +151,7 @@ void btpad_packet_handler(uint8_t packet_type,
{ {
case BTSTACK_EVENT_STATE: case BTSTACK_EVENT_STATE:
{ {
RARCH_LOG("BTstack: HCI State %d\n", packet[2]); RARCH_LOG("[BTstack]: HCI State %d.\n", packet[2]);
switch (packet[2]) switch (packet[2])
{ {
@ -186,10 +188,10 @@ void btpad_packet_handler(uint8_t packet_type,
{ {
bt_flip_addr_ptr(event_addr, &packet[6]); bt_flip_addr_ptr(event_addr, &packet[6]);
if (!packet[5]) if (!packet[5])
RARCH_LOG("BTpad: Local address is %s\n", RARCH_LOG("[BTpad]: Local address is %s.\n",
bd_addr_to_str_ptr(event_addr)); bd_addr_to_str_ptr(event_addr));
else else
RARCH_LOG("BTpad: Failed to get local address (Status: %02X)\n", RARCH_LOG("[BTpad]: Failed to get local address (Status: %02X).\n",
packet[5]); packet[5]);
} }
} }
@ -207,7 +209,7 @@ void btpad_packet_handler(uint8_t packet_type,
if (!connection) if (!connection)
return; return;
RARCH_LOG("BTpad: Inquiry found device\n"); RARCH_LOG("[BTpad]: Inquiry found device\n");
memset(connection, 0, sizeof(struct pad_connection)); memset(connection, 0, sizeof(struct pad_connection));
memcpy(connection->address, event_addr, sizeof(bd_addr_t)); memcpy(connection->address, event_addr, sizeof(bd_addr_t));
@ -246,11 +248,11 @@ void btpad_packet_handler(uint8_t packet_type,
{ {
if (!connection) if (!connection)
{ {
RARCH_LOG("BTpad: Got L2CAP 'Channel Opened' event for unrecognized device\n"); RARCH_LOG("[BTpad]: Got L2CAP 'Channel Opened' event for unrecognized device.\n");
break; break;
} }
RARCH_LOG("BTpad: L2CAP channel opened: (PSM: %02X)\n", psm); RARCH_LOG("[BTpad]: L2CAP channel opened: (PSM: %02X)\n", psm);
connection->handle = handle; connection->handle = handle;
if (psm == PSM_HID_CONTROL) if (psm == PSM_HID_CONTROL)
@ -258,18 +260,18 @@ void btpad_packet_handler(uint8_t packet_type,
else if (psm == PSM_HID_INTERRUPT) else if (psm == PSM_HID_INTERRUPT)
connection->channels[1] = channel_id; connection->channels[1] = channel_id;
else else
RARCH_LOG("BTpad: Got unknown L2CAP PSM, ignoring (PSM: %02X)\n", psm); RARCH_LOG("[BTpad]: Got unknown L2CAP PSM, ignoring (PSM: %02X).\n", psm);
if (connection->channels[0] if (connection->channels[0]
&& connection->channels[1]) && connection->channels[1])
{ {
RARCH_LOG("BTpad: Got both L2CAP channels, requesting name\n"); RARCH_LOG("[BTpad]: Got both L2CAP channels, requesting name.\n");
btpad_queue_hci_remote_name_request( btpad_queue_hci_remote_name_request(
connection->address, 0, 0, 0); connection->address, 0, 0, 0);
} }
} }
else else
RARCH_LOG("BTpad: Got failed L2CAP 'Channel Opened' event (PSM: %02X, Status: %02X)\n", psm, packet[2]); RARCH_LOG("[BTpad]: Got failed L2CAP 'Channel Opened' event (PSM: %02X, Status: %02X).\n", psm, packet[2]);
} }
break; break;
@ -290,7 +292,7 @@ void btpad_packet_handler(uint8_t packet_type,
if (!connection) if (!connection)
break; break;
RARCH_LOG("BTpad: Got new incoming connection\n"); RARCH_LOG("[BTpad]: Got new incoming connection\n");
memset(connection, 0, memset(connection, 0,
sizeof(struct pad_connection)); sizeof(struct pad_connection));
@ -302,7 +304,7 @@ void btpad_packet_handler(uint8_t packet_type,
connection->state = BTPAD_CONNECTING; connection->state = BTPAD_CONNECTING;
} }
RARCH_LOG("BTpad: Incoming L2CAP connection (PSM: %02X)\n", RARCH_LOG("[BTpad]: Incoming L2CAP connection (PSM: %02X).\n",
psm); psm);
bt_send_cmd_ptr(l2cap_accept_connection_ptr, channel_id); bt_send_cmd_ptr(l2cap_accept_connection_ptr, channel_id);
} }
@ -318,11 +320,11 @@ void btpad_packet_handler(uint8_t packet_type,
if (!connection) if (!connection)
{ {
RARCH_LOG("BTpad: Got unexpected remote name, ignoring\n"); RARCH_LOG("[BTpad]: Got unexpected remote name, ignoring.\n");
break; break;
} }
RARCH_LOG("BTpad: Got %.200s\n", (char*)&packet[9]); RARCH_LOG("[BTpad]: Got %.200s.\n", (char*)&packet[9]);
connection->slot = pad_connection_connect( connection->slot = pad_connection_connect(
(char*)packet + 9, connection, &btpad_connection_send_control); (char*)packet + 9, connection, &btpad_connection_send_control);
@ -331,7 +333,7 @@ void btpad_packet_handler(uint8_t packet_type,
break; break;
case HCI_EVENT_PIN_CODE_REQUEST: case HCI_EVENT_PIN_CODE_REQUEST:
RARCH_LOG("BTpad: Sending WiiMote PIN\n"); RARCH_LOG("[BTpad]: Sending Wiimote PIN.\n");
bt_flip_addr_ptr(event_addr, &packet[2]); bt_flip_addr_ptr(event_addr, &packet[2]);
btpad_queue_hci_pin_code_request_reply(event_addr, &packet[2]); btpad_queue_hci_pin_code_request_reply(event_addr, &packet[2]);
@ -356,13 +358,13 @@ void btpad_packet_handler(uint8_t packet_type,
} }
} }
else else
RARCH_LOG("BTpad: Got failed 'Disconnection Complete' event (Status: %02X)\n", packet[2]); RARCH_LOG("[BTpad]: Got failed 'Disconnection Complete' event (Status: %02X).\n", packet[2]);
} }
break; break;
case L2CAP_EVENT_SERVICE_REGISTERED: case L2CAP_EVENT_SERVICE_REGISTERED:
if (packet[2]) if (packet[2])
RARCH_LOG("BTpad: Got failed 'Service Registered' event (PSM: %02X, Status: %02X)\n", RARCH_LOG("[BTpad]: Got failed 'Service Registered' event (PSM: %02X, Status: %02X).\n",
READ_BT_16(packet, 3), packet[2]); READ_BT_16(packet, 3), packet[2]);
break; break;
} }

View File

@ -1,5 +1,6 @@
/* RetroArch - A frontend for libretro. /* RetroArch - A frontend for libretro.
* Copyright (C) 2013-2014 - Jason Fetters * Copyright (C) 2013-2014 - Jason Fetters
* Copyright (C) 2011-2014 - Daniel De Matteis
* *
* RetroArch is free software: you can redistribute it and/or modify it under the terms * RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found- * of the GNU General Public License as published by the Free Software Found-
@ -93,24 +94,36 @@ void btpad_queue_process(void)
return; return;
if (cmd->command == btstack_set_power_mode_ptr) if (cmd->command == btstack_set_power_mode_ptr)
bt_send_cmd_ptr(cmd->command, cmd->btstack_set_power_mode.on); bt_send_cmd_ptr(
cmd->command,
cmd->btstack_set_power_mode.on);
else if (cmd->command == hci_read_bd_addr_ptr) else if (cmd->command == hci_read_bd_addr_ptr)
bt_send_cmd_ptr(cmd->command); bt_send_cmd_ptr(cmd->command);
else if (cmd->command == hci_disconnect_ptr) else if (cmd->command == hci_disconnect_ptr)
bt_send_cmd_ptr(cmd->command, cmd->hci_disconnect.handle, bt_send_cmd_ptr(
cmd->command,
cmd->hci_disconnect.handle,
cmd->hci_disconnect.reason); cmd->hci_disconnect.reason);
else if (cmd->command == hci_inquiry_ptr) else if (cmd->command == hci_inquiry_ptr)
bt_send_cmd_ptr(cmd->command, cmd->hci_inquiry.lap, bt_send_cmd_ptr(
cmd->hci_inquiry.length, cmd->hci_inquiry.num_responses); cmd->command,
cmd->hci_inquiry.lap,
cmd->hci_inquiry.length,
cmd->hci_inquiry.num_responses);
else if (cmd->command == hci_remote_name_request_ptr) else if (cmd->command == hci_remote_name_request_ptr)
bt_send_cmd_ptr(cmd->command, cmd->hci_remote_name_request.bd_addr, bt_send_cmd_ptr(
cmd->command,
cmd->hci_remote_name_request.bd_addr,
cmd->hci_remote_name_request.page_scan_repetition_mode, cmd->hci_remote_name_request.page_scan_repetition_mode,
cmd->hci_remote_name_request.reserved, cmd->hci_remote_name_request.reserved,
cmd->hci_remote_name_request.clock_offset); cmd->hci_remote_name_request.clock_offset);
else if (cmd->command == hci_pin_code_request_reply_ptr) else if (cmd->command == hci_pin_code_request_reply_ptr)
bt_send_cmd_ptr(cmd->command, cmd->hci_pin_code_request_reply.bd_addr, bt_send_cmd_ptr(
6, cmd->hci_pin_code_request_reply.pin); cmd->command,
cmd->hci_pin_code_request_reply.bd_addr,
6,
cmd->hci_pin_code_request_reply.pin);
INCPOS(read); INCPOS(read);
} }
@ -161,7 +174,8 @@ void btpad_queue_hci_disconnect(uint16_t handle, uint8_t reason)
btpad_queue_process(); btpad_queue_process();
} }
void btpad_queue_hci_inquiry(uint32_t lap, uint8_t length, uint8_t num_responses) void btpad_queue_hci_inquiry(uint32_t lap,
uint8_t length, uint8_t num_responses)
{ {
struct btpad_queue_command* cmd = (struct btpad_queue_command*) struct btpad_queue_command* cmd = (struct btpad_queue_command*)
&commands[insert_position]; &commands[insert_position];
@ -190,7 +204,8 @@ void btpad_queue_hci_remote_name_request(bd_addr_t bd_addr,
cmd->command = hci_remote_name_request_ptr; cmd->command = hci_remote_name_request_ptr;
memcpy(cmd->hci_remote_name_request.bd_addr, bd_addr, sizeof(bd_addr_t)); memcpy(cmd->hci_remote_name_request.bd_addr, bd_addr, sizeof(bd_addr_t));
cmd->hci_remote_name_request.page_scan_repetition_mode = page_scan_repetition_mode; cmd->hci_remote_name_request.page_scan_repetition_mode =
page_scan_repetition_mode;
cmd->hci_remote_name_request.reserved = reserved; cmd->hci_remote_name_request.reserved = reserved;
cmd->hci_remote_name_request.clock_offset = clock_offset; cmd->hci_remote_name_request.clock_offset = clock_offset;

View File

@ -38,7 +38,8 @@
* *
*/ */
#pragma once #ifndef _BTSTACK_HEADER_H
#define _BTSTACK_HEADER_H
#include "hci_cmds.h" #include "hci_cmds.h"
#include "run_loop.h" #include "run_loop.h"
@ -50,31 +51,40 @@
extern "C" { extern "C" {
#endif #endif
// Default TCP port for BTstack daemon /* Default TCP port for BTstack daemon. */
#define BTSTACK_PORT 13333 #define BTSTACK_PORT 13333
// UNIX domain socket for BTstack */ /* UNIX domain socket for BTstack. */
#define BTSTACK_UNIX "/tmp/BTstack" #define BTSTACK_UNIX "/tmp/BTstack"
// packet handler /* Packet handler. */
typedef void (*btstack_packet_handler_t) (uint8_t packet_type, uint16_t channel, uint8_t *packet, uint16_t size); typedef void (*btstack_packet_handler_t) (uint8_t packet_type,
uint16_t channel, uint8_t *packet, uint16_t size);
// optional: if called before bt_open, TCP socket is used instead of local unix socket /* Optional
// note: address is not copied and must be valid during bt_open *
* If called before bt_open, TCP socket is used
* instead of local UNIX socket.
*
* note: Address is not copied and must be
* valid during bt_open.
*/
void bt_use_tcp(const char * address, uint16_t port); void bt_use_tcp(const char * address, uint16_t port);
// init BTstack library /* Init BTstack library. */
int bt_open(void); int bt_open(void);
// stop using BTstack library /* Stop using BTstack library. */
int bt_close(void); int bt_close(void);
// send hci cmd packet /* Send HCI cmd packet. */
int bt_send_cmd(const hci_cmd_t *cmd, ...); int bt_send_cmd(const hci_cmd_t *cmd, ...);
// register packet handler -- channel only valid for l2cap and rfcomm packets /* Register packet handler -- channel only valid
// @returns old packet handler * for L2CAP and RFCOMM packets.
btstack_packet_handler_t bt_register_packet_handler(btstack_packet_handler_t handler); */
btstack_packet_handler_t bt_register_packet_handler(
btstack_packet_handler_t handler);
void bt_send_acl(uint8_t * data, uint16_t len); void bt_send_acl(uint8_t * data, uint16_t len);
@ -84,3 +94,5 @@ void bt_send_rfcomm(uint16_t rfcom_cid, uint8_t *data, uint16_t len);
#if defined __cplusplus #if defined __cplusplus
} }
#endif #endif
#endif

View File

@ -35,7 +35,8 @@
* Created by Matthias Ringwald on 7/13/09. * Created by Matthias Ringwald on 7/13/09.
*/ */
#pragma once #ifndef _BTSTACK_LINKED_LIST_H
#define _BTSTACK_LINKED_LIST_H
#if defined __cplusplus #if defined __cplusplus
extern "C" { extern "C" {
@ -61,3 +62,5 @@ void test_linked_list(void);
#if defined __cplusplus #if defined __cplusplus
} }
#endif #endif
#endif

View File

@ -50,69 +50,88 @@
extern "C" { extern "C" {
#endif #endif
typedef enum { typedef enum
RUN_LOOP_POSIX = 1, {
RUN_LOOP_COCOA, RUN_LOOP_POSIX = 1,
RUN_LOOP_EMBEDDED RUN_LOOP_COCOA,
RUN_LOOP_EMBEDDED
} RUN_LOOP_TYPE; } RUN_LOOP_TYPE;
typedef struct data_source { typedef struct data_source
linked_item_t item; {
int fd; // <-- file descriptor to watch or 0 linked_item_t item;
int (*process)(struct data_source *ds); // <-- do processing
/* File descriptor to watch or 0. */
int fd;
int (*process)(struct data_source *ds);
} data_source_t; } data_source_t;
typedef struct timer { typedef struct timer
linked_item_t item; {
linked_item_t item;
#ifdef HAVE_TIME #ifdef HAVE_TIME
struct timeval timeout; // <-- next timeout /* Next timeout. */
struct timeval timeout;
#endif #endif
#ifdef HAVE_TICK #ifdef HAVE_TICK
uint32_t timeout; // timeout in system ticks /* Timeout in system ticks. */
uint32_t timeout;
#endif #endif
void (*process)(struct timer *ts); // <-- do processing void (*process)(struct timer *ts);
} timer_source_t; } timer_source_t;
// Set timer based on current time in milliseconds. /* Set timer based on current time in milliseconds. */
void run_loop_set_timer(timer_source_t *a, uint32_t timeout_in_ms); void run_loop_set_timer(timer_source_t *a, uint32_t timeout_in_ms);
// Set callback that will be executed when timer expires. /* Set callback that will be executed when timer expires. */
void run_loop_set_timer_handler(timer_source_t *ts, void (*process)(timer_source_t *_ts)); void run_loop_set_timer_handler(timer_source_t *ts,
void (*process)(timer_source_t *_ts));
// Add/Remove timer source. /* Add timer source. */
void run_loop_add_timer(timer_source_t *timer); void run_loop_add_timer(timer_source_t *timer);
/* Remove timer source. */
int run_loop_remove_timer(timer_source_t *timer); int run_loop_remove_timer(timer_source_t *timer);
// Init must be called before any other run_loop call. /* Init must be called before any other run_loop call.
// Use RUN_LOOP_EMBEDDED for embedded devices. * Use RUN_LOOP_EMBEDDED for embedded devices.
*/
void run_loop_init(RUN_LOOP_TYPE type); void run_loop_init(RUN_LOOP_TYPE type);
// Set data source callback. /* Set data source callback. */
void run_loop_set_data_source_handler(data_source_t *ds, int (*process)(data_source_t *_ds)); void run_loop_set_data_source_handler(data_source_t *ds,
int (*process)(data_source_t *_ds));
/* Add data source. */
// Add/Remove data source.
void run_loop_add_data_source(data_source_t *dataSource); void run_loop_add_data_source(data_source_t *dataSource);
/* Remove data source. */
int run_loop_remove_data_source(data_source_t *dataSource); int run_loop_remove_data_source(data_source_t *dataSource);
/* Execute configured run loop.
// Execute configured run loop. This function does not return. * This function does not return. */
void run_loop_execute(void); void run_loop_execute(void);
// hack to fix HCI timer handling /* Hack to fix HCI timer handling. */
#ifdef HAVE_TICK #ifdef HAVE_TICK
// Sets how many miliseconds has one tick. /* Sets how many milliseconds has one tick. */
uint32_t embedded_ticks_for_ms(uint32_t time_in_ms); uint32_t embedded_ticks_for_ms(uint32_t time_in_ms);
// Queries the current time in ticks.
/* Queries the current time in ticks. */
uint32_t embedded_get_ticks(void); uint32_t embedded_get_ticks(void);
#endif #endif
#ifdef EMBEDDED #ifdef EMBEDDED
// Sets an internal flag that is checked in the critical section
// just before entering sleep mode. Has to be called by the interupt /* Sets an internal flag that is checked in the critical section
// handler of a data source to signal the run loop that a new data * just before entering sleep mode. Has to be called by the interupt
// is available. * handler of a data source to signal the run loop that a new data
* is available.
*/
void embedded_trigger(void); void embedded_trigger(void);
#endif #endif
#if defined __cplusplus #if defined __cplusplus
} }

View File

@ -33,7 +33,8 @@
* sdp_util.h * sdp_util.h
*/ */
#pragma once #ifndef _BTSTACK_SDP_UTIL_H
#define _BTSTACK_SDP_UTIL_H
#include <stdint.h> #include <stdint.h>
@ -136,3 +137,5 @@ void sdp_create_spp_service(uint8_t *service, int service_id, const char *n
#if defined __cplusplus #if defined __cplusplus
} }
#endif #endif
#endif

View File

@ -37,8 +37,8 @@
* Created by Matthias Ringwald on 7/23/09. * Created by Matthias Ringwald on 7/23/09.
*/ */
#pragma once #ifndef _BT_UTILS_H
#define _BT_UTILS_H
#if defined __cplusplus #if defined __cplusplus
extern "C" { extern "C" {
@ -46,76 +46,75 @@ extern "C" {
#include <stdint.h> #include <stdint.h>
/** /* Connection handle type. */
* @brief hci connection handle type
*/
typedef uint16_t hci_con_handle_t; typedef uint16_t hci_con_handle_t;
/** /* Length of a Bluetooth device address. */
* @brief Length of a bluetooth device address.
*/
#define BD_ADDR_LEN 6 #define BD_ADDR_LEN 6
typedef uint8_t bd_addr_t[BD_ADDR_LEN]; typedef uint8_t bd_addr_t[BD_ADDR_LEN];
/** /* The link key type. */
* @brief The link key type
*/
#define LINK_KEY_LEN 16 #define LINK_KEY_LEN 16
typedef uint8_t link_key_t[LINK_KEY_LEN]; typedef uint8_t link_key_t[LINK_KEY_LEN];
/** /* The device name type. */
* @brief The device name type
*/
#define DEVICE_NAME_LEN 248 #define DEVICE_NAME_LEN 248
typedef uint8_t device_name_t[DEVICE_NAME_LEN+1]; typedef uint8_t device_name_t[DEVICE_NAME_LEN+1];
/* helper for BT little endian format. */
// helper for BT little endian format
#define READ_BT_16( buffer, pos) ( ((uint16_t) buffer[pos]) | (((uint16_t)buffer[pos+1]) << 8)) #define READ_BT_16( buffer, pos) ( ((uint16_t) buffer[pos]) | (((uint16_t)buffer[pos+1]) << 8))
#define READ_BT_24( buffer, pos) ( ((uint32_t) buffer[pos]) | (((uint32_t)buffer[pos+1]) << 8) | (((uint32_t)buffer[pos+2]) << 16)) #define READ_BT_24( buffer, pos) ( ((uint32_t) buffer[pos]) | (((uint32_t)buffer[pos+1]) << 8) | (((uint32_t)buffer[pos+2]) << 16))
#define READ_BT_32( buffer, pos) ( ((uint32_t) buffer[pos]) | (((uint32_t)buffer[pos+1]) << 8) | (((uint32_t)buffer[pos+2]) << 16) | (((uint32_t) buffer[pos+3])) << 24) #define READ_BT_32( buffer, pos) ( ((uint32_t) buffer[pos]) | (((uint32_t)buffer[pos+1]) << 8) | (((uint32_t)buffer[pos+2]) << 16) | (((uint32_t) buffer[pos+3])) << 24)
// helper for SDP big endian format /* helper for SDP big endian format. */
#define READ_NET_16( buffer, pos) ( ((uint16_t) buffer[pos+1]) | (((uint16_t)buffer[pos ]) << 8)) #define READ_NET_16( buffer, pos) ( ((uint16_t) buffer[pos+1]) | (((uint16_t)buffer[pos ]) << 8))
#define READ_NET_32( buffer, pos) ( ((uint32_t) buffer[pos+3]) | (((uint32_t)buffer[pos+2]) << 8) | (((uint32_t)buffer[pos+1]) << 16) | (((uint32_t) buffer[pos])) << 24) #define READ_NET_32( buffer, pos) ( ((uint32_t) buffer[pos+3]) | (((uint32_t)buffer[pos+2]) << 8) | (((uint32_t)buffer[pos+1]) << 16) | (((uint32_t) buffer[pos])) << 24)
// HCI CMD OGF/OCF /* HCI CMD OGF/OCF. */
#define READ_CMD_OGF(buffer) (buffer[1] >> 2) #define READ_CMD_OGF(buffer) (buffer[1] >> 2)
#define READ_CMD_OCF(buffer) ((buffer[1] & 0x03) << 8 | buffer[0]) #define READ_CMD_OCF(buffer) ((buffer[1] & 0x03) << 8 | buffer[0])
// check if command complete event for given command /* Check if command complete event for given command. */
#define COMMAND_COMPLETE_EVENT(event,cmd) ( event[0] == HCI_EVENT_COMMAND_COMPLETE && READ_BT_16(event,3) == cmd.opcode) #define COMMAND_COMPLETE_EVENT(event,cmd) ( event[0] == HCI_EVENT_COMMAND_COMPLETE && READ_BT_16(event,3) == cmd.opcode)
#define COMMAND_STATUS_EVENT(event,cmd) ( event[0] == HCI_EVENT_COMMAND_STATUS && READ_BT_16(event,4) == cmd.opcode) #define COMMAND_STATUS_EVENT(event,cmd) ( event[0] == HCI_EVENT_COMMAND_STATUS && READ_BT_16(event,4) == cmd.opcode)
// Code+Len=2, Pkts+Opcode=3; total=5 /* Code+Len=2, Pkts+Opcode=3; total=5 */
#define OFFSET_OF_DATA_IN_COMMAND_COMPLETE 5 #define OFFSET_OF_DATA_IN_COMMAND_COMPLETE 5
// ACL Packet /* ACL Packet. */
#define READ_ACL_CONNECTION_HANDLE( buffer ) ( READ_BT_16(buffer,0) & 0x0fff) #define READ_ACL_CONNECTION_HANDLE( buffer ) ( READ_BT_16(buffer,0) & 0x0fff)
#define READ_ACL_FLAGS( buffer ) ( buffer[1] >> 4 ) #define READ_ACL_FLAGS( buffer ) ( buffer[1] >> 4 )
#define READ_ACL_LENGTH( buffer ) (READ_BT_16(buffer, 2)) #define READ_ACL_LENGTH( buffer ) (READ_BT_16(buffer, 2))
// L2CAP Packet /* L2CAP Packet. */
#define READ_L2CAP_LENGTH(buffer) ( READ_BT_16(buffer, 4)) #define READ_L2CAP_LENGTH(buffer) ( READ_BT_16(buffer, 4))
#define READ_L2CAP_CHANNEL_ID(buffer) ( READ_BT_16(buffer, 6)) #define READ_L2CAP_CHANNEL_ID(buffer) ( READ_BT_16(buffer, 6))
void bt_store_16(uint8_t *buffer, uint16_t pos, uint16_t value); void bt_store_16(uint8_t *buffer, uint16_t pos, uint16_t value);
void bt_store_32(uint8_t *buffer, uint16_t pos, uint32_t value); void bt_store_32(uint8_t *buffer, uint16_t pos, uint32_t value);
void bt_flip_addr(bd_addr_t dest, bd_addr_t src); void bt_flip_addr(bd_addr_t dest, bd_addr_t src);
void net_store_16(uint8_t *buffer, uint16_t pos, uint16_t value); void net_store_16(uint8_t *buffer, uint16_t pos, uint16_t value);
void net_store_32(uint8_t *buffer, uint16_t pos, uint32_t value); void net_store_32(uint8_t *buffer, uint16_t pos, uint32_t value);
void hexdump(void *data, int size); void hexdump(void *data, int size);
void printUUID(uint8_t *uuid); void printUUID(uint8_t *uuid);
// @deprecated please use more convenient bd_addr_to_str /* Deprecated - please use more convenient bd_addr_to_str. */
void print_bd_addr( bd_addr_t addr); void print_bd_addr( bd_addr_t addr);
char * bd_addr_to_str(bd_addr_t addr); char * bd_addr_to_str(bd_addr_t addr);
int sscan_bd_addr(uint8_t * addr_string, bd_addr_t addr); int sscan_bd_addr(uint8_t * addr_string, bd_addr_t addr);
uint8_t crc8_check(uint8_t *data, uint16_t len, uint8_t check_sum); uint8_t crc8_check(uint8_t *data, uint16_t len, uint8_t check_sum);
uint8_t crc8_calc(uint8_t *data, uint16_t len); uint8_t crc8_calc(uint8_t *data, uint16_t len);
#define BD_ADDR_CMP(a,b) memcmp(a,b, BD_ADDR_LEN) #define BD_ADDR_CMP(a,b) memcmp(a,b, BD_ADDR_LEN)
@ -124,4 +123,5 @@ uint8_t crc8_calc(uint8_t *data, uint16_t len);
#if defined __cplusplus #if defined __cplusplus
} }
#endif #endif
#endif