mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-02-27 12:39:49 +00:00
log all BTstack command and events
This commit is contained in:
parent
dd487e11d2
commit
e0abb8e76b
15
src/daemon.c
15
src/daemon.c
@ -136,8 +136,6 @@ static void daemon_no_connections_timeout(struct timer *ts){
|
||||
|
||||
static int btstack_command_handler(connection_t *connection, uint8_t *packet, uint16_t size){
|
||||
|
||||
hci_dump_packet( HCI_COMMAND_DATA_PACKET, 1, packet, size);
|
||||
|
||||
bd_addr_t addr;
|
||||
uint16_t cid;
|
||||
uint16_t psm;
|
||||
@ -152,9 +150,11 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
|
||||
// BTstack internal commands - 16 Bit OpCode, 8 Bit ParamLen, Params...
|
||||
switch (READ_CMD_OCF(packet)){
|
||||
case BTSTACK_GET_STATE:
|
||||
log_info("BTSTACK_GET_STATE");
|
||||
hci_emit_state();
|
||||
break;
|
||||
case BTSTACK_SET_POWER_MODE:
|
||||
log_info("BTSTACK_SET_POWER_MODE %u", packet[3]);
|
||||
// track client power requests
|
||||
client = client_for_connection(connection);
|
||||
if (!client) break;
|
||||
@ -168,15 +168,18 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
|
||||
}
|
||||
break;
|
||||
case BTSTACK_GET_VERSION:
|
||||
log_info("BTSTACK_GET_VERSION");
|
||||
hci_emit_btstack_version();
|
||||
break;
|
||||
#ifdef USE_BLUETOOL
|
||||
case BTSTACK_SET_SYSTEM_BLUETOOTH_ENABLED:
|
||||
log_info("BTSTACK_SET_SYSTEM_BLUETOOTH_ENABLED %u", packet[3]);
|
||||
iphone_system_bt_set_enabled(packet[3]);
|
||||
hci_emit_system_bluetooth_enabled(iphone_system_bt_enabled());
|
||||
break;
|
||||
|
||||
case BTSTACK_GET_SYSTEM_BLUETOOTH_ENABLED:
|
||||
log_info("BTSTACK_GET_SYSTEM_BLUETOOTH_ENABLED");
|
||||
hci_emit_system_bluetooth_enabled(iphone_system_bt_enabled());
|
||||
break;
|
||||
#else
|
||||
@ -186,6 +189,7 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
|
||||
break;
|
||||
#endif
|
||||
case BTSTACK_SET_DISCOVERABLE:
|
||||
log_info("BTSTACK_SET_DISCOVERABLE discoverable %u)", packet[3]);
|
||||
// track client discoverable requests
|
||||
client = client_for_connection(connection);
|
||||
if (!client) break;
|
||||
@ -195,7 +199,6 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
|
||||
break;
|
||||
case BTSTACK_SET_BLUETOOTH_ENABLED:
|
||||
log_info("BTSTACK_SET_BLUETOOTH_ENABLED: %u\n", packet[3]);
|
||||
|
||||
if (packet[3]) {
|
||||
// global enable
|
||||
global_enable = 1;
|
||||
@ -294,6 +297,7 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
|
||||
// NOTE: hack for non-iOS platforms
|
||||
rfcomm_channel = rfcomm_channel_generator++;
|
||||
}
|
||||
log_info("RFCOMM_EVENT_PERSISTENT_CHANNEL %u", rfcomm_channel);
|
||||
uint8_t event[4];
|
||||
event[0] = RFCOMM_EVENT_PERSISTENT_CHANNEL;
|
||||
event[1] = sizeof(event) - 2;
|
||||
@ -310,12 +314,17 @@ static int btstack_command_handler(connection_t *connection, uint8_t *packet, ui
|
||||
break;
|
||||
case SDP_UNREGISTER_SERVICE_RECORD:
|
||||
service_record_handle = READ_BT_32(packet, 3);
|
||||
log_info("SDP_UNREGISTER_SERVICE_RECORD handle 0x%x ", service_record_handle);
|
||||
sdp_unregister_service_internal(connection, service_record_handle);
|
||||
break;
|
||||
default:
|
||||
log_error("Error: command %u not implemented\n:", READ_CMD_OCF(packet));
|
||||
break;
|
||||
}
|
||||
|
||||
// verbose log info on command before dumped command unknown to PacketLogger or Wireshark
|
||||
hci_dump_packet( HCI_COMMAND_DATA_PACKET, 1, packet, size);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
19
src/hci.c
19
src/hci.c
@ -1308,6 +1308,7 @@ int hci_send_cmd(const hci_cmd_t *cmd, ...){
|
||||
// TODO: generalize, use table similar to hci_create_command
|
||||
|
||||
void hci_emit_state(){
|
||||
log_info("BTSTACK_EVENT_STATE %u", hci_stack.state);
|
||||
uint8_t event[3];
|
||||
event[0] = BTSTACK_EVENT_STATE;
|
||||
event[1] = sizeof(event) - 2;
|
||||
@ -1341,6 +1342,7 @@ void hci_emit_disconnection_complete(uint16_t handle, uint8_t reason){
|
||||
}
|
||||
|
||||
void hci_emit_l2cap_check_timeout(hci_connection_t *conn){
|
||||
log_info("L2CAP_EVENT_TIMEOUT_CHECK");
|
||||
uint8_t event[4];
|
||||
event[0] = L2CAP_EVENT_TIMEOUT_CHECK;
|
||||
event[1] = sizeof(event) - 2;
|
||||
@ -1350,6 +1352,7 @@ void hci_emit_l2cap_check_timeout(hci_connection_t *conn){
|
||||
}
|
||||
|
||||
void hci_emit_nr_connections_changed(){
|
||||
log_info("BTSTACK_EVENT_NR_CONNECTIONS_CHANGED %u", nr_hci_connections());
|
||||
uint8_t event[3];
|
||||
event[0] = BTSTACK_EVENT_NR_CONNECTIONS_CHANGED;
|
||||
event[1] = sizeof(event) - 2;
|
||||
@ -1359,6 +1362,7 @@ void hci_emit_nr_connections_changed(){
|
||||
}
|
||||
|
||||
void hci_emit_hci_open_failed(){
|
||||
log_info("BTSTACK_EVENT_POWERON_FAILED");
|
||||
uint8_t event[2];
|
||||
event[0] = BTSTACK_EVENT_POWERON_FAILED;
|
||||
event[1] = sizeof(event) - 2;
|
||||
@ -1368,6 +1372,7 @@ void hci_emit_hci_open_failed(){
|
||||
|
||||
#ifndef EMBEDDED
|
||||
void hci_emit_btstack_version() {
|
||||
log_info("BTSTACK_EVENT_VERSION %u.%u", BTSTACK_MAJOR, BTSTACK_MINOR);
|
||||
uint8_t event[6];
|
||||
event[0] = BTSTACK_EVENT_VERSION;
|
||||
event[1] = sizeof(event) - 2;
|
||||
@ -1380,6 +1385,7 @@ void hci_emit_btstack_version() {
|
||||
#endif
|
||||
|
||||
void hci_emit_system_bluetooth_enabled(uint8_t enabled){
|
||||
log_info("BTSTACK_EVENT_SYSTEM_BLUETOOTH_ENABLED %u", enabled);
|
||||
uint8_t event[3];
|
||||
event[0] = BTSTACK_EVENT_SYSTEM_BLUETOOTH_ENABLED;
|
||||
event[1] = sizeof(event) - 2;
|
||||
@ -1389,17 +1395,22 @@ void hci_emit_system_bluetooth_enabled(uint8_t enabled){
|
||||
}
|
||||
|
||||
void hci_emit_remote_name_cached(bd_addr_t *addr, device_name_t *name){
|
||||
uint8_t event[2+1+6+248];
|
||||
uint8_t event[2+1+6+248+1]; // +1 for \0 in log_info
|
||||
event[0] = BTSTACK_EVENT_REMOTE_NAME_CACHED;
|
||||
event[1] = sizeof(event) - 2;
|
||||
event[1] = sizeof(event) - 2 - 1;
|
||||
event[2] = 0; // just to be compatible with HCI_EVENT_REMOTE_NAME_REQUEST_COMPLETE
|
||||
bt_flip_addr(&event[3], *addr);
|
||||
memcpy(&event[9], name, 248);
|
||||
hci_dump_packet(HCI_EVENT_PACKET, 0, event, sizeof(event));
|
||||
hci_stack.packet_handler(HCI_EVENT_PACKET, event, sizeof(event));
|
||||
|
||||
event[9+248] = 0; // assert \0 for log_info
|
||||
log_info("BTSTACK_EVENT_REMOTE_NAME_CACHED %s = '%s'", bd_addr_to_str(*addr), &event[9]);
|
||||
|
||||
hci_dump_packet(HCI_EVENT_PACKET, 0, event, sizeof(event)-1);
|
||||
hci_stack.packet_handler(HCI_EVENT_PACKET, event, sizeof(event)-1);
|
||||
}
|
||||
|
||||
void hci_emit_discoverable_enabled(uint8_t enabled){
|
||||
log_info("BTSTACK_EVENT_DISCOVERABLE_ENABLED %u", enabled);
|
||||
uint8_t event[3];
|
||||
event[0] = BTSTACK_EVENT_DISCOVERABLE_ENABLED;
|
||||
event[1] = sizeof(event) - 2;
|
||||
|
41
src/l2cap.c
41
src/l2cap.c
@ -123,6 +123,9 @@ void l2cap_dispatch(l2cap_channel_t *channel, uint8_t type, uint8_t * data, uint
|
||||
}
|
||||
|
||||
void l2cap_emit_channel_opened(l2cap_channel_t *channel, uint8_t status) {
|
||||
log_info("L2CAP_EVENT_CHANNEL_OPENED status 0x%x addr %s handle 0x%x psm 0x%x local_cid 0x%x remote_cid 0x%x local_mtu %u, remote_mtu %u",
|
||||
status, bd_addr_to_str(channel->address), channel->handle, channel->psm,
|
||||
channel->local_cid, channel->remote_cid, channel->local_mtu, channel->remote_mtu);
|
||||
uint8_t event[21];
|
||||
event[0] = L2CAP_EVENT_CHANNEL_OPENED;
|
||||
event[1] = sizeof(event) - 2;
|
||||
@ -139,6 +142,7 @@ void l2cap_emit_channel_opened(l2cap_channel_t *channel, uint8_t status) {
|
||||
}
|
||||
|
||||
void l2cap_emit_channel_closed(l2cap_channel_t *channel) {
|
||||
log_info("L2CAP_EVENT_CHANNEL_CLOSED local_cid 0x%x", channel->local_cid);
|
||||
uint8_t event[4];
|
||||
event[0] = L2CAP_EVENT_CHANNEL_CLOSED;
|
||||
event[1] = sizeof(event) - 2;
|
||||
@ -148,6 +152,8 @@ void l2cap_emit_channel_closed(l2cap_channel_t *channel) {
|
||||
}
|
||||
|
||||
void l2cap_emit_connection_request(l2cap_channel_t *channel) {
|
||||
log_info("L2CAP_EVENT_INCOMING_CONNECTION addr %s handle 0x%x psm 0x%x local_cid 0x%x remote_cid 0x%x",
|
||||
bd_addr_to_str(channel->address), channel->handle, channel->psm, channel->local_cid, channel->remote_cid);
|
||||
uint8_t event[16];
|
||||
event[0] = L2CAP_EVENT_INCOMING_CONNECTION;
|
||||
event[1] = sizeof(event) - 2;
|
||||
@ -161,6 +167,7 @@ void l2cap_emit_connection_request(l2cap_channel_t *channel) {
|
||||
}
|
||||
|
||||
static void l2cap_emit_service_registered(void *connection, uint8_t status, uint16_t psm){
|
||||
log_info("L2CAP_EVENT_SERVICE_REGISTERED status 0x%x psm 0x%x", status, psm);
|
||||
uint8_t event[5];
|
||||
event[0] = L2CAP_EVENT_SERVICE_REGISTERED;
|
||||
event[1] = sizeof(event) - 2;
|
||||
@ -171,9 +178,10 @@ static void l2cap_emit_service_registered(void *connection, uint8_t status, uint
|
||||
}
|
||||
|
||||
void l2cap_emit_credits(l2cap_channel_t *channel, uint8_t credits) {
|
||||
|
||||
log_info("L2CAP_EVENT_CREDITS local_cid 0x%x credits %u", channel->local_cid, credits);
|
||||
// track credits
|
||||
channel->packets_granted += credits;
|
||||
// log_info("l2cap_emit_credits for cid %u, credits given: %u (+%u)\n", channel->local_cid, channel->packets_granted, credits);
|
||||
|
||||
uint8_t event[5];
|
||||
event[0] = L2CAP_EVENT_CREDITS;
|
||||
@ -253,24 +261,24 @@ uint8_t *l2cap_get_outgoing_buffer(void){
|
||||
int l2cap_send_prepared(uint16_t local_cid, uint16_t len){
|
||||
|
||||
if (!hci_can_send_packet_now(HCI_ACL_DATA_PACKET)){
|
||||
log_info("l2cap_send_internal cid %u, cannot send\n", local_cid);
|
||||
log_info("l2cap_send_internal cid 0x%02x, cannot send\n", local_cid);
|
||||
return BTSTACK_ACL_BUFFERS_FULL;
|
||||
}
|
||||
|
||||
l2cap_channel_t * channel = l2cap_get_channel_for_local_cid(local_cid);
|
||||
if (!channel) {
|
||||
log_error("l2cap_send_internal no channel for cid %u\n", local_cid);
|
||||
log_error("l2cap_send_internal no channel for cid 0x%02x\n", local_cid);
|
||||
return -1; // TODO: define error
|
||||
}
|
||||
|
||||
if (channel->packets_granted == 0){
|
||||
log_error("l2cap_send_internal cid %u, no credits!\n", local_cid);
|
||||
log_error("l2cap_send_internal cid 0x%02x, no credits!\n", local_cid);
|
||||
return -1; // TODO: define error
|
||||
}
|
||||
|
||||
--channel->packets_granted;
|
||||
|
||||
log_debug("l2cap_send_internal cid %u, handle %u, 1 credit used, credits left %u;\n",
|
||||
log_debug("l2cap_send_internal cid 0x%02x, handle %u, 1 credit used, credits left %u;\n",
|
||||
local_cid, channel->handle, channel->packets_granted);
|
||||
|
||||
uint8_t *acl_buffer = hci_get_outgoing_acl_packet_buffer();
|
||||
@ -294,11 +302,11 @@ int l2cap_send_prepared(uint16_t local_cid, uint16_t len){
|
||||
int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t len){
|
||||
|
||||
if (!hci_can_send_packet_now(HCI_ACL_DATA_PACKET)){
|
||||
log_info("l2cap_send_prepared_to_handle cid %u, cannot send\n", cid);
|
||||
log_info("l2cap_send_prepared_to_handle cid 0x%02x, cannot send\n", cid);
|
||||
return BTSTACK_ACL_BUFFERS_FULL;
|
||||
}
|
||||
|
||||
log_debug("l2cap_send_prepared_to_handle cid %u, handle %u\n", cid, handle);
|
||||
log_debug("l2cap_send_prepared_to_handle cid 0x%02x, handle %u\n", cid, handle);
|
||||
|
||||
uint8_t *acl_buffer = hci_get_outgoing_acl_packet_buffer();
|
||||
|
||||
@ -321,7 +329,7 @@ int l2cap_send_prepared_connectionless(uint16_t handle, uint16_t cid, uint16_t l
|
||||
int l2cap_send_internal(uint16_t local_cid, uint8_t *data, uint16_t len){
|
||||
|
||||
if (!hci_can_send_packet_now(HCI_ACL_DATA_PACKET)){
|
||||
log_info("l2cap_send_internal cid %u, cannot send\n", local_cid);
|
||||
log_info("l2cap_send_internal cid 0x%02x, cannot send\n", local_cid);
|
||||
return BTSTACK_ACL_BUFFERS_FULL;
|
||||
}
|
||||
|
||||
@ -335,7 +343,7 @@ int l2cap_send_internal(uint16_t local_cid, uint8_t *data, uint16_t len){
|
||||
int l2cap_send_connectionless(uint16_t handle, uint16_t cid, uint8_t *data, uint16_t len){
|
||||
|
||||
if (!hci_can_send_packet_now(HCI_ACL_DATA_PACKET)){
|
||||
log_info("l2cap_send_internal cid %u, cannot send\n", cid);
|
||||
log_info("l2cap_send_internal cid 0x%02x, cannot send\n", cid);
|
||||
return BTSTACK_ACL_BUFFERS_FULL;
|
||||
}
|
||||
|
||||
@ -489,6 +497,8 @@ uint16_t l2cap_max_mtu(void){
|
||||
void l2cap_create_channel_internal(void * connection, btstack_packet_handler_t packet_handler,
|
||||
bd_addr_t address, uint16_t psm, uint16_t mtu){
|
||||
|
||||
log_info("L2CAP_CREATE_CHANNEL_MTU addr %s psm 0x%x mtu %u", bd_addr_to_str(address), psm, mtu);
|
||||
|
||||
// alloc structure
|
||||
l2cap_channel_t * chan = (l2cap_channel_t*) btstack_memory_l2cap_channel_get();
|
||||
if (!chan) {
|
||||
@ -527,6 +537,7 @@ void l2cap_create_channel_internal(void * connection, btstack_packet_handler_t p
|
||||
}
|
||||
|
||||
void l2cap_disconnect_internal(uint16_t local_cid, uint8_t reason){
|
||||
log_info("L2CAP_DISCONNECT local_cid 0x%x reason 0x%x", local_cid, reason);
|
||||
// find channel for local_cid
|
||||
l2cap_channel_t * channel = l2cap_get_channel_for_local_cid(local_cid);
|
||||
if (channel) {
|
||||
@ -690,7 +701,7 @@ static void l2cap_register_signaling_response(hci_con_handle_t handle, uint8_t c
|
||||
|
||||
static void l2cap_handle_connection_request(hci_con_handle_t handle, uint8_t sig_id, uint16_t psm, uint16_t source_cid){
|
||||
|
||||
// log_info("l2cap_handle_connection_request for handle %u, psm %u cid %u\n", handle, psm, source_cid);
|
||||
// log_info("l2cap_handle_connection_request for handle %u, psm %u cid 0x%02x\n", handle, psm, source_cid);
|
||||
l2cap_service_t *service = l2cap_get_service(psm);
|
||||
if (!service) {
|
||||
// 0x0002 PSM not supported
|
||||
@ -743,6 +754,7 @@ static void l2cap_handle_connection_request(hci_con_handle_t handle, uint8_t sig
|
||||
}
|
||||
|
||||
void l2cap_accept_connection_internal(uint16_t local_cid){
|
||||
log_info("L2CAP_ACCEPT_CONNECTION local_cid 0x%x", local_cid);
|
||||
l2cap_channel_t * channel = l2cap_get_channel_for_local_cid(local_cid);
|
||||
if (!channel) {
|
||||
log_error("l2cap_accept_connection_internal called but local_cid 0x%x not found", local_cid);
|
||||
@ -756,6 +768,7 @@ void l2cap_accept_connection_internal(uint16_t local_cid){
|
||||
}
|
||||
|
||||
void l2cap_decline_connection_internal(uint16_t local_cid, uint8_t reason){
|
||||
log_info("L2CAP_DECLINE_CONNECTION local_cid 0x%x, reason %x", local_cid, reason);
|
||||
l2cap_channel_t * channel = l2cap_get_channel_for_local_cid( local_cid);
|
||||
if (!channel) {
|
||||
log_error( "l2cap_decline_connection_internal called but local_cid 0x%x not found", local_cid);
|
||||
@ -779,7 +792,7 @@ void l2cap_signaling_handle_configure_request(l2cap_channel_t *channel, uint8_t
|
||||
// MTU { type(8): 1, len(8):2, MTU(16) }
|
||||
if ((type & 0x7f) == 1 && length == 2){
|
||||
channel->remote_mtu = READ_BT_16(command, pos);
|
||||
// log_info("l2cap cid %u, remote mtu %u\n", channel->local_cid, channel->remote_mtu);
|
||||
// log_info("l2cap cid 0x%02x, remote mtu %u\n", channel->local_cid, channel->remote_mtu);
|
||||
}
|
||||
pos += length;
|
||||
}
|
||||
@ -1050,6 +1063,9 @@ l2cap_service_t * l2cap_get_service(uint16_t psm){
|
||||
}
|
||||
|
||||
void l2cap_register_service_internal(void *connection, btstack_packet_handler_t packet_handler, uint16_t psm, uint16_t mtu){
|
||||
|
||||
log_info("L2CAP_REGISTER_SERVICE psm 0x%x mtu %u", psm, mtu);
|
||||
|
||||
// check for alread registered psm
|
||||
// TODO: emit error event
|
||||
l2cap_service_t *service = l2cap_get_service(psm);
|
||||
@ -1085,6 +1101,9 @@ void l2cap_register_service_internal(void *connection, btstack_packet_handler_t
|
||||
}
|
||||
|
||||
void l2cap_unregister_service_internal(void *connection, uint16_t psm){
|
||||
|
||||
log_info("L2CAP_UNREGISTER_SERVICE psm 0x%x", psm);
|
||||
|
||||
l2cap_service_t *service = l2cap_get_service(psm);
|
||||
if (!service) return;
|
||||
linked_list_remove(&l2cap_services, (linked_item_t *) service);
|
||||
|
28
src/rfcomm.c
28
src/rfcomm.c
@ -126,6 +126,8 @@ static void rfcomm_multiplexer_state_machine(rfcomm_multiplexer_t * multiplexer,
|
||||
|
||||
// data: event (8), len(8), address(48), channel (8), rfcomm_cid (16)
|
||||
static void rfcomm_emit_connection_request(rfcomm_channel_t *channel) {
|
||||
log_info("RFCOMM_EVENT_INCOMING_CONNECTION addr %s channel #%u cid 0x%02x",
|
||||
bd_addr_to_str(channel->multiplexer->remote_addr), channel->dlci>>1, channel->rfcomm_cid);
|
||||
uint8_t event[11];
|
||||
event[0] = RFCOMM_EVENT_INCOMING_CONNECTION;
|
||||
event[1] = sizeof(event) - 2;
|
||||
@ -141,6 +143,9 @@ static void rfcomm_emit_connection_request(rfcomm_channel_t *channel) {
|
||||
// next Cydia release will use SVN version of this
|
||||
// data: event(8), len(8), status (8), address (48), handle (16), server channel(8), rfcomm_cid(16), max frame size(16)
|
||||
static void rfcomm_emit_channel_opened(rfcomm_channel_t *channel, uint8_t status) {
|
||||
log_info("RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE status 0x%x addr %s handle 0x%x channel #%u cid 0x%02x mtu %u",
|
||||
status, bd_addr_to_str(channel->multiplexer->remote_addr), channel->multiplexer->con_handle,
|
||||
channel->dlci>>1, channel->rfcomm_cid, channel->max_frame_size);
|
||||
uint8_t event[16];
|
||||
uint8_t pos = 0;
|
||||
event[pos++] = RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE;
|
||||
@ -156,6 +161,8 @@ static void rfcomm_emit_channel_opened(rfcomm_channel_t *channel, uint8_t status
|
||||
}
|
||||
|
||||
static void rfcomm_emit_channel_open_failed_outgoing_memory(void * connection, bd_addr_t *addr, uint8_t server_channel){
|
||||
log_info("RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE BTSTACK_MEMORY_ALLOC_FAILED addr %s",
|
||||
bd_addr_to_str(*addr));
|
||||
uint8_t event[16];
|
||||
uint8_t pos = 0;
|
||||
event[pos++] = RFCOMM_EVENT_OPEN_CHANNEL_COMPLETE;
|
||||
@ -173,6 +180,7 @@ static void rfcomm_emit_channel_open_failed_outgoing_memory(void * connection, b
|
||||
// data: event(8), len(8), creidts incoming(8), new credits incoming(8), credits outgoing(8)
|
||||
static inline void rfcomm_emit_credit_status(rfcomm_channel_t * channel) {
|
||||
#ifdef RFCOMM_LOG_CREDITS
|
||||
log_info("RFCOMM_LOG_CREDITS incoming %u new_incoming %u outgoing %u", channel->credits_incoming, channel->new_credits_incoming, channel->credits_outgoing);
|
||||
uint8_t event[5];
|
||||
event[0] = 0x88;
|
||||
event[1] = sizeof(event) - 2;
|
||||
@ -185,6 +193,7 @@ static inline void rfcomm_emit_credit_status(rfcomm_channel_t * channel) {
|
||||
|
||||
// data: event(8), len(8), rfcomm_cid(16)
|
||||
static void rfcomm_emit_channel_closed(rfcomm_channel_t * channel) {
|
||||
log_info("RFCOMM_EVENT_CHANNEL_CLOSED cid 0x%02x", channel->rfcomm_cid);
|
||||
uint8_t event[4];
|
||||
event[0] = RFCOMM_EVENT_CHANNEL_CLOSED;
|
||||
event[1] = sizeof(event) - 2;
|
||||
@ -194,6 +203,7 @@ static void rfcomm_emit_channel_closed(rfcomm_channel_t * channel) {
|
||||
}
|
||||
|
||||
static void rfcomm_emit_credits(rfcomm_channel_t * channel, uint8_t credits) {
|
||||
log_info("RFCOMM_EVENT_CREDITS cid 0x%02x credits %u", channel->rfcomm_cid, credits);
|
||||
uint8_t event[5];
|
||||
event[0] = RFCOMM_EVENT_CREDITS;
|
||||
event[1] = sizeof(event) - 2;
|
||||
@ -204,6 +214,7 @@ static void rfcomm_emit_credits(rfcomm_channel_t * channel, uint8_t credits) {
|
||||
}
|
||||
|
||||
static void rfcomm_emit_service_registered(void *connection, uint8_t status, uint8_t channel){
|
||||
log_info("RFCOMM_EVENT_SERVICE_REGISTERED status 0x%x channel #%u", status, channel);
|
||||
uint8_t event[4];
|
||||
event[0] = RFCOMM_EVENT_SERVICE_REGISTERED;
|
||||
event[1] = sizeof(event) - 2;
|
||||
@ -1667,17 +1678,17 @@ int rfcomm_send_internal(uint16_t rfcomm_cid, uint8_t *data, uint16_t len){
|
||||
|
||||
rfcomm_channel_t * channel = rfcomm_channel_for_rfcomm_cid(rfcomm_cid);
|
||||
if (!channel){
|
||||
log_error("rfcomm_send_internal cid %u doesn't exist!\n", rfcomm_cid);
|
||||
log_error("rfcomm_send_internal cid 0x%02x doesn't exist!\n", rfcomm_cid);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!channel->credits_outgoing){
|
||||
log_info("rfcomm_send_internal cid %u, no rfcomm outgoing credits!\n", rfcomm_cid);
|
||||
log_info("rfcomm_send_internal cid 0x%02x, no rfcomm outgoing credits!\n", rfcomm_cid);
|
||||
return RFCOMM_NO_OUTGOING_CREDITS;
|
||||
}
|
||||
|
||||
if (!channel->packets_granted){
|
||||
log_info("rfcomm_send_internal cid %u, no rfcomm credits granted!\n", rfcomm_cid);
|
||||
log_info("rfcomm_send_internal cid 0x%02x, no rfcomm credits granted!\n", rfcomm_cid);
|
||||
return RFCOMM_NO_OUTGOING_CREDITS;
|
||||
}
|
||||
|
||||
@ -1711,7 +1722,7 @@ int rfcomm_send_internal(uint16_t rfcomm_cid, uint8_t *data, uint16_t len){
|
||||
}
|
||||
|
||||
void rfcomm_create_channel2(void * connection, bd_addr_t *addr, uint8_t server_channel, uint8_t incoming_flow_control, uint8_t initial_credits){
|
||||
log_info("rfcomm_create_channel_internal to %s, at channel #%02x, flow control %u, init credits %u\n", bd_addr_to_str(*addr), server_channel,
|
||||
log_info("RFCOMM_CREATE_CHANNEL addr %s channel #%u flow control %u init credits %u\n", bd_addr_to_str(*addr), server_channel,
|
||||
incoming_flow_control, initial_credits);
|
||||
|
||||
// create new multiplexer if necessary
|
||||
@ -1761,6 +1772,7 @@ void rfcomm_create_channel_internal(void * connection, bd_addr_t *addr, uint8_t
|
||||
}
|
||||
|
||||
void rfcomm_disconnect_internal(uint16_t rfcomm_cid){
|
||||
log_info("RFCOMM_DISCONNECT cid 0x%02x", rfcomm_cid);
|
||||
rfcomm_channel_t * channel = rfcomm_channel_for_rfcomm_cid(rfcomm_cid);
|
||||
if (channel) {
|
||||
channel->state = RFCOMM_CHANNEL_SEND_DISC;
|
||||
@ -1772,6 +1784,8 @@ void rfcomm_disconnect_internal(uint16_t rfcomm_cid){
|
||||
|
||||
|
||||
void rfcomm_register_service2(void * connection, uint8_t channel, uint16_t max_frame_size, uint8_t incoming_flow_control, uint8_t initial_credits){
|
||||
log_info("RFCOMM_REGISTER_SERVICE channel #%u mtu %u flow_control %u credits %u",
|
||||
channel, max_frame_size, incoming_flow_control, initial_credits);
|
||||
// check if already registered
|
||||
rfcomm_service_t * service = rfcomm_service_for_channel(channel);
|
||||
if (service){
|
||||
@ -1814,6 +1828,7 @@ void rfcomm_register_service_internal(void * connection, uint8_t channel, uint16
|
||||
}
|
||||
|
||||
void rfcomm_unregister_service_internal(uint8_t service_channel){
|
||||
log_info("RFCOMM_UNREGISTER_SERVICE #%u", service_channel);
|
||||
rfcomm_service_t *service = rfcomm_service_for_channel(service_channel);
|
||||
if (!service) return;
|
||||
linked_list_remove(&rfcomm_services, (linked_item_t *) service);
|
||||
@ -1827,7 +1842,7 @@ void rfcomm_unregister_service_internal(uint8_t service_channel){
|
||||
}
|
||||
|
||||
void rfcomm_accept_connection_internal(uint16_t rfcomm_cid){
|
||||
log_info("Received Accept Connction\n");
|
||||
log_info("RFCOMM_ACCEPT_CONNECTION cid 0x%02x", rfcomm_cid);
|
||||
rfcomm_channel_t * channel = rfcomm_channel_for_rfcomm_cid(rfcomm_cid);
|
||||
if (!channel) return;
|
||||
switch (channel->state) {
|
||||
@ -1849,7 +1864,7 @@ void rfcomm_accept_connection_internal(uint16_t rfcomm_cid){
|
||||
}
|
||||
|
||||
void rfcomm_decline_connection_internal(uint16_t rfcomm_cid){
|
||||
log_info("Received Decline Connction\n");
|
||||
log_info("RFCOMM_DECLINE_CONNECTION cid 0x%02x", rfcomm_cid);
|
||||
rfcomm_channel_t * channel = rfcomm_channel_for_rfcomm_cid(rfcomm_cid);
|
||||
if (!channel) return;
|
||||
switch (channel->state) {
|
||||
@ -1865,6 +1880,7 @@ void rfcomm_decline_connection_internal(uint16_t rfcomm_cid){
|
||||
}
|
||||
|
||||
void rfcomm_grant_credits(uint16_t rfcomm_cid, uint8_t credits){
|
||||
log_info("RFCOMM_GRANT_CREDITS cid 0x%02x credits %u", rfcomm_cid, credits);
|
||||
rfcomm_channel_t * channel = rfcomm_channel_for_rfcomm_cid(rfcomm_cid);
|
||||
if (!channel) return;
|
||||
if (!channel->incoming_flow_control) return;
|
||||
|
Loading…
x
Reference in New Issue
Block a user