l2cap: Fix x86_64 build and refactor trace

This commit is contained in:
Alexander von Gluck IV
2016-04-10 00:49:32 -05:00
parent e1e291b063
commit c58e1d7feb
6 changed files with 188 additions and 214 deletions
-1
View File
@@ -6,7 +6,6 @@
#ifndef _BTDEBUG_H #ifndef _BTDEBUG_H
#define _BTDEBUG_H #define _BTDEBUG_H
// XXX: Remove once things get "better" // XXX: Remove once things get "better"
#define DEBUG #define DEBUG
#ifdef DEBUG #ifdef DEBUG
@@ -14,10 +14,6 @@
#include <bluetooth/bdaddrUtils.h> #include <bluetooth/bdaddrUtils.h>
#include <bluetooth/L2CAP/btL2CAP.h> #include <bluetooth/L2CAP/btL2CAP.h>
#define BT_DEBUG_THIS_MODULE
#define MODULE_NAME "l2cap"
#define SUBMODULE_NAME "Endpoint"
#define SUBMODULE_COLOR 32
#include <btDebug.h> #include <btDebug.h>
@@ -40,7 +36,7 @@ L2capEndpoint::L2capEndpoint(net_socket* socket)
fPeerEndpoint(NULL), fPeerEndpoint(NULL),
fChannel(NULL) fChannel(NULL)
{ {
debugf("[%ld] %p\n", find_thread(NULL), this); CALLED();
/* Set MTU and flow control settings to defaults */ /* Set MTU and flow control settings to defaults */
fConfiguration.imtu = L2CAP_MTU_DEFAULT; fConfiguration.imtu = L2CAP_MTU_DEFAULT;
@@ -59,7 +55,7 @@ L2capEndpoint::L2capEndpoint(net_socket* socket)
L2capEndpoint::~L2capEndpoint() L2capEndpoint::~L2capEndpoint()
{ {
debugf("[%ld] %p\n", find_thread(NULL), this); CALLED();
gStackModule->uninit_fifo(&fReceivingFifo); gStackModule->uninit_fifo(&fReceivingFifo);
} }
@@ -68,7 +64,7 @@ L2capEndpoint::~L2capEndpoint()
status_t status_t
L2capEndpoint::Init() L2capEndpoint::Init()
{ {
debugf("[%ld] %p\n", find_thread(NULL), this); CALLED();
return B_OK; return B_OK;
} }
@@ -77,7 +73,7 @@ L2capEndpoint::Init()
void void
L2capEndpoint::Uninit() L2capEndpoint::Uninit()
{ {
debugf("[%ld] %p\n", find_thread(NULL), this); CALLED();
} }
@@ -85,7 +81,7 @@ L2capEndpoint::Uninit()
status_t status_t
L2capEndpoint::Open() L2capEndpoint::Open()
{ {
debugf("[%ld] %p\n", find_thread(NULL), this); CALLED();
status_t error = ProtocolSocket::Open(); status_t error = ProtocolSocket::Open();
if (error != B_OK) if (error != B_OK)
@@ -98,7 +94,7 @@ L2capEndpoint::Open()
status_t status_t
L2capEndpoint::Close() L2capEndpoint::Close()
{ {
debugf("[%ld] %p\n", find_thread(NULL), this); CALLED();
if (fChannel == NULL) { if (fChannel == NULL) {
// TODO: Parent socket // TODO: Parent socket
@@ -106,7 +102,6 @@ L2capEndpoint::Close()
} else { } else {
// Child Socket // Child Socket
if (fState == CLOSED) { if (fState == CLOSED) {
debugf("Already closed by peer %p\n", this);
// TODO: Clean needed stuff // TODO: Clean needed stuff
return B_OK; return B_OK;
} else { } else {
@@ -136,7 +131,7 @@ L2capEndpoint::Close()
status_t status_t
L2capEndpoint::Free() L2capEndpoint::Free()
{ {
debugf("[%ld] %p\n", find_thread(NULL), this); CALLED();
return B_OK; return B_OK;
} }
@@ -172,9 +167,6 @@ L2capEndpoint::Bind(const struct sockaddr* _address)
memcpy(&socket->address, _address, sizeof(struct sockaddr_l2cap)); memcpy(&socket->address, _address, sizeof(struct sockaddr_l2cap));
socket->address.ss_len = sizeof(struct sockaddr_l2cap); socket->address.ss_len = sizeof(struct sockaddr_l2cap);
debugf("for %s psm=%d\n", bdaddrUtils::ToString(address->l2cap_bdaddr),
address->l2cap_psm);
fState = BOUND; fState = BOUND;
return B_OK; return B_OK;
@@ -184,7 +176,7 @@ L2capEndpoint::Bind(const struct sockaddr* _address)
status_t status_t
L2capEndpoint::Unbind() L2capEndpoint::Unbind()
{ {
debugf("[%ld] %p\n", find_thread(NULL), this); CALLED();
return B_OK; return B_OK;
} }
@@ -193,16 +185,16 @@ L2capEndpoint::Unbind()
status_t status_t
L2capEndpoint::Listen(int backlog) L2capEndpoint::Listen(int backlog)
{ {
debugf("[%ld] %p\n", find_thread(NULL), this); CALLED();
if (fState != BOUND) { if (fState != BOUND) {
debugf("Invalid State %p\n", this); ERROR("%s: Invalid State\n", __func__);
return B_BAD_VALUE; return B_BAD_VALUE;
} }
fEstablishSemaphore = create_sem(0, "l2cap serv accept"); fEstablishSemaphore = create_sem(0, "l2cap serv accept");
if (fEstablishSemaphore < B_OK) { if (fEstablishSemaphore < B_OK) {
flowf("Semaphore could not be created\n"); ERROR("%s: Semaphore could not be created\n", __func__);
return ENOBUFS; return ENOBUFS;
} }
@@ -224,23 +216,27 @@ L2capEndpoint::Connect(const struct sockaddr* _address)
return EINVAL; return EINVAL;
// Check for any specific status? // Check for any specific status?
if (fState == CONNECTING) { if (fState == CONNECTING)
return EINPROGRESS; return EINPROGRESS;
}
// TODO: should not be in the BOUND status first? // TODO: should not be in the BOUND status first?
debugf("[%ld] %p->L2capEndpoint::Connect(\"%s\")\n", find_thread(NULL), #if 0
this, ConstSocketAddress(&gL2cap4AddressModule, _address) TRACE("%s: [%ld] %p->L2capEndpoint::Connect(\"%s\")\n", __func__,
find_thread(NULL), this,
ConstSocketAddress(&gL2cap4AddressModule, _address)
.AsString().Data()); .AsString().Data());
#endif
// TODO: If we were bound to a specific source address // TODO: If we were bound to a specific source address
// Route, we must find a Connection descriptor with address->l2cap_address // Route, we must find a Connection descriptor with address->l2cap_address
hci_id hid = btCoreData->RouteConnection(address->l2cap_bdaddr); hci_id hid = btCoreData->RouteConnection(address->l2cap_bdaddr);
debugf("%lx for route %s\n", hid, #if 0
bdaddrUtils::ToString(address->l2cap_bdaddr)); TRACE("%s: %" B_PRId32 " for route %s\n", __func__, hid,
bdaddrUtils::ToString(address->l2cap_bdaddr).String());
#endif
if (hid > 0) { if (hid > 0) {
HciConnection* connection = btCoreData->ConnectionByDestination( HciConnection* connection = btCoreData->ConnectionByDestination(
@@ -260,7 +256,7 @@ L2capEndpoint::Connect(const struct sockaddr* _address)
fEstablishSemaphore = create_sem(0, "l2cap client"); fEstablishSemaphore = create_sem(0, "l2cap client");
if (fEstablishSemaphore < B_OK) { if (fEstablishSemaphore < B_OK) {
flowf("Semaphore could not be created\n"); ERROR("%s: Semaphore could not be created\n", __func__);
return ENOBUFS; return ENOBUFS;
} }
@@ -281,7 +277,7 @@ L2capEndpoint::Connect(const struct sockaddr* _address)
status_t status_t
L2capEndpoint::Accept(net_socket** _acceptedSocket) L2capEndpoint::Accept(net_socket** _acceptedSocket)
{ {
debugf("[%ld]\n", find_thread(NULL)); CALLED();
// MutexLocker locker(fLock); // MutexLocker locker(fLock);
@@ -301,7 +297,8 @@ L2capEndpoint::Accept(net_socket** _acceptedSocket)
status = gSocketModule->dequeue_connected(socket, _acceptedSocket); status = gSocketModule->dequeue_connected(socket, _acceptedSocket);
if (status != B_OK) { if (status != B_OK) {
debugf("Could not dequeue socket %s\n", strerror(status)); ERROR("%s: Could not dequeue socket %s\n", __func__,
strerror(status));
} else { } else {
((L2capEndpoint*)((*_acceptedSocket)->first_protocol))->fState = ESTABLISHED; ((L2capEndpoint*)((*_acceptedSocket)->first_protocol))->fState = ESTABLISHED;
@@ -321,8 +318,7 @@ ssize_t
L2capEndpoint::Send(const iovec* vecs, size_t vecCount, L2capEndpoint::Send(const iovec* vecs, size_t vecCount,
ancillary_data_container* ancillaryData) ancillary_data_container* ancillaryData)
{ {
debugf("[%ld] %p Send(%p, %ld, %p)\n", find_thread(NULL), CALLED();
this, vecs, vecCount, ancillaryData);
return B_OK; return B_OK;
} }
@@ -333,11 +329,10 @@ L2capEndpoint::Receive(const iovec* vecs, size_t vecCount,
ancillary_data_container** _ancillaryData, struct sockaddr* _address, ancillary_data_container** _ancillaryData, struct sockaddr* _address,
socklen_t* _addressLength) socklen_t* _addressLength)
{ {
debugf("[%ld] %p Receive(%p, %ld)\n", find_thread(NULL), CALLED();
this, vecs, vecCount);
if (fState != ESTABLISHED) { if (fState != ESTABLISHED) {
debugf("Invalid State %p\n", this); ERROR("%s: Invalid State %p\n", __func__, this);
return B_BAD_VALUE; return B_BAD_VALUE;
} }
@@ -348,10 +343,10 @@ L2capEndpoint::Receive(const iovec* vecs, size_t vecCount,
ssize_t ssize_t
L2capEndpoint::ReadData(size_t numBytes, uint32 flags, net_buffer** _buffer) L2capEndpoint::ReadData(size_t numBytes, uint32 flags, net_buffer** _buffer)
{ {
debugf("e->%p num=%ld, f=%ld)\n", this, numBytes, flags); CALLED();
if (fState != ESTABLISHED) { if (fState != ESTABLISHED) {
debugf("Invalid State %p\n", this); ERROR("%s: Invalid State %p\n", __func__, this);
return B_BAD_VALUE; return B_BAD_VALUE;
} }
@@ -363,10 +358,10 @@ L2capEndpoint::ReadData(size_t numBytes, uint32 flags, net_buffer** _buffer)
ssize_t ssize_t
L2capEndpoint::SendData(net_buffer* buffer) L2capEndpoint::SendData(net_buffer* buffer)
{ {
debugf("size=%ld\n", buffer->size); CALLED();
if (fState != ESTABLISHED) { if (fState != ESTABLISHED) {
debugf("Invalid State %p\n", this); ERROR("%s: Invalid State %p\n", __func__, this);
return B_BAD_VALUE; return B_BAD_VALUE;
} }
@@ -382,8 +377,7 @@ L2capEndpoint::SendData(net_buffer* buffer)
ssize_t ssize_t
L2capEndpoint::Sendable() L2capEndpoint::Sendable()
{ {
debugf("[%ld] %p\n", find_thread(NULL), this); CALLED();
return B_OK; return B_OK;
} }
@@ -391,8 +385,7 @@ L2capEndpoint::Sendable()
ssize_t ssize_t
L2capEndpoint::Receivable() L2capEndpoint::Receivable()
{ {
debugf("[%ld] %p\n", find_thread(NULL), this); CALLED();
return 0; return 0;
} }
@@ -425,7 +418,7 @@ L2capEndpoint::BindNewEnpointToChannel(L2capChannel* channel)
net_socket* newSocket; net_socket* newSocket;
status_t error = gSocketModule->spawn_pending_socket(socket, &newSocket); status_t error = gSocketModule->spawn_pending_socket(socket, &newSocket);
if (error != B_OK) { if (error != B_OK) {
debugf("Could not spawn child for Endpoint %p\n", this); ERROR("%s: Could not spawn child for Endpoint %p\n", __func__, this);
// TODO: Handle situation // TODO: Handle situation
return; return;
} }
@@ -437,8 +430,8 @@ L2capEndpoint::BindNewEnpointToChannel(L2capChannel* channel)
channel->endpoint = endpoint; channel->endpoint = endpoint;
debugf("new socket %p/e->%p from parent %p/e->%p\n", //debugf("new socket %p/e->%p from parent %p/e->%p\n",
newSocket, endpoint, socket, this); // newSocket, endpoint, socket, this);
// Provide the channel the configuration set by the user socket // Provide the channel the configuration set by the user socket
channel->configuration = &fConfiguration; channel->configuration = &fConfiguration;
@@ -446,8 +439,8 @@ L2capEndpoint::BindNewEnpointToChannel(L2capChannel* channel)
// It might be used keep the last negotiated channel // It might be used keep the last negotiated channel
// fChannel = channel; // fChannel = channel;
debugf("New endpoint %p for psm %d, schannel %x dchannel %x\n", endpoint, //debugf("New endpoint %p for psm %d, schannel %x dchannel %x\n", endpoint,
channel->psm, channel->scid, channel->dcid); // channel->psm, channel->scid, channel->dcid);
} }
@@ -468,10 +461,9 @@ L2capEndpoint::BindToChannel(L2capChannel* channel)
status_t status_t
L2capEndpoint::MarkEstablished() L2capEndpoint::MarkEstablished()
{ {
status_t error = B_OK; CALLED();
debugf("Endpoint %p for psm %d, schannel %x dchannel %x\n", this,
fChannel->psm, fChannel->scid, fChannel->dcid);
status_t error = B_OK;
fChannel->state = L2CAP_CHAN_OPEN; fChannel->state = L2CAP_CHAN_OPEN;
fState = ESTABLISHED; fState = ESTABLISHED;
@@ -481,7 +473,8 @@ L2capEndpoint::MarkEstablished()
if (error == B_OK) { if (error == B_OK) {
release_sem(fPeerEndpoint->fEstablishSemaphore); release_sem(fPeerEndpoint->fEstablishSemaphore);
} else { } else {
debugf("Could not set child Endpoint %p %s\n", this, strerror(error)); ERROR("%s: Could not set child Endpoint %p %s\n", __func__, this,
strerror(error));
} }
} else } else
release_sem(fEstablishSemaphore); release_sem(fEstablishSemaphore);
@@ -493,10 +486,10 @@ L2capEndpoint::MarkEstablished()
status_t status_t
L2capEndpoint::MarkClosed() L2capEndpoint::MarkClosed()
{ {
flowf("\n"); CALLED();
if (fState == CLOSED) {
if (fState == CLOSED)
release_sem(fEstablishSemaphore); release_sem(fEstablishSemaphore);
}
fState = CLOSED; fState = CLOSED;
@@ -41,9 +41,6 @@
#include <btModules.h> #include <btModules.h>
#define BT_DEBUG_THIS_MODULE
#define SUBMODULE_NAME "L2cap"
#define SUBMODULE_COLOR 32
#include <btDebug.h> #include <btDebug.h>
@@ -64,12 +61,13 @@ static struct net_domain* sDomain;
net_protocol* net_protocol*
l2cap_init_protocol(net_socket* socket) l2cap_init_protocol(net_socket* socket)
{ {
CALLED();
L2capEndpoint* protocol = new(std::nothrow) L2capEndpoint(socket); L2capEndpoint* protocol = new(std::nothrow) L2capEndpoint(socket);
if (protocol == NULL) if (protocol == NULL)
return NULL; return NULL;
EndpointList.Add(protocol); EndpointList.Add(protocol);
debugf("Prococol created %p\n", protocol);
return protocol; return protocol;
} }
@@ -78,7 +76,7 @@ l2cap_init_protocol(net_socket* socket)
status_t status_t
l2cap_uninit_protocol(net_protocol* protocol) l2cap_uninit_protocol(net_protocol* protocol)
{ {
flowf("\n"); CALLED();
L2capEndpoint* endpoint = static_cast<L2capEndpoint*>(protocol); L2capEndpoint* endpoint = static_cast<L2capEndpoint*>(protocol);
@@ -94,7 +92,7 @@ l2cap_uninit_protocol(net_protocol* protocol)
status_t status_t
l2cap_open(net_protocol* protocol) l2cap_open(net_protocol* protocol)
{ {
flowf("\n"); CALLED();
return B_OK; return B_OK;
} }
@@ -105,7 +103,7 @@ l2cap_close(net_protocol* protocol)
{ {
L2capEndpoint* endpoint = static_cast<L2capEndpoint*>(protocol); L2capEndpoint* endpoint = static_cast<L2capEndpoint*>(protocol);
flowf("\n"); CALLED();
endpoint->Close(); endpoint->Close();
@@ -116,7 +114,7 @@ l2cap_close(net_protocol* protocol)
status_t status_t
l2cap_free(net_protocol* protocol) l2cap_free(net_protocol* protocol)
{ {
flowf("\n"); CALLED();
return B_OK; return B_OK;
} }
@@ -125,7 +123,7 @@ l2cap_free(net_protocol* protocol)
status_t status_t
l2cap_connect(net_protocol* protocol, const struct sockaddr* address) l2cap_connect(net_protocol* protocol, const struct sockaddr* address)
{ {
debugf("from %p, with %p\n", protocol, address); CALLED();
if (address == NULL) if (address == NULL)
return EINVAL; return EINVAL;
@@ -133,7 +131,6 @@ l2cap_connect(net_protocol* protocol, const struct sockaddr* address)
if (address->sa_family != AF_BLUETOOTH) if (address->sa_family != AF_BLUETOOTH)
return EAFNOSUPPORT; return EAFNOSUPPORT;
return ((L2capEndpoint*)protocol)->Connect(address);; return ((L2capEndpoint*)protocol)->Connect(address);;
} }
@@ -141,6 +138,7 @@ l2cap_connect(net_protocol* protocol, const struct sockaddr* address)
status_t status_t
l2cap_accept(net_protocol* protocol, struct net_socket** _acceptedSocket) l2cap_accept(net_protocol* protocol, struct net_socket** _acceptedSocket)
{ {
CALLED();
return ((L2capEndpoint*)protocol)->Accept(_acceptedSocket); return ((L2capEndpoint*)protocol)->Accept(_acceptedSocket);
} }
@@ -149,8 +147,7 @@ status_t
l2cap_control(net_protocol* protocol, int level, int option, void* value, l2cap_control(net_protocol* protocol, int level, int option, void* value,
size_t* _length) size_t* _length)
{ {
flowf("\n"); CALLED();
return EOPNOTSUPP; return EOPNOTSUPP;
} }
@@ -159,8 +156,7 @@ status_t
l2cap_getsockopt(net_protocol* protocol, int level, int option, l2cap_getsockopt(net_protocol* protocol, int level, int option,
void* value, int* length) void* value, int* length)
{ {
flowf("\n"); CALLED();
return B_OK; return B_OK;
} }
@@ -169,10 +165,8 @@ status_t
l2cap_setsockopt(net_protocol* protocol, int level, int option, l2cap_setsockopt(net_protocol* protocol, int level, int option,
const void* value, int length) const void* value, int length)
{ {
flowf("\n"); CALLED();
((L2capEndpoint*)protocol)->fConfigurationSet = true; ((L2capEndpoint*)protocol)->fConfigurationSet = true;
return B_OK; return B_OK;
} }
@@ -180,8 +174,7 @@ l2cap_setsockopt(net_protocol* protocol, int level, int option,
status_t status_t
l2cap_bind(net_protocol* protocol, const struct sockaddr* address) l2cap_bind(net_protocol* protocol, const struct sockaddr* address)
{ {
debugf("from %p, with %p\n", protocol, address); CALLED();
return ((L2capEndpoint*)protocol)->Bind(address); return ((L2capEndpoint*)protocol)->Bind(address);
} }
@@ -189,8 +182,7 @@ l2cap_bind(net_protocol* protocol, const struct sockaddr* address)
status_t status_t
l2cap_unbind(net_protocol* protocol, struct sockaddr* address) l2cap_unbind(net_protocol* protocol, struct sockaddr* address)
{ {
flowf("\n"); CALLED();
return B_ERROR; return B_ERROR;
} }
@@ -198,6 +190,7 @@ l2cap_unbind(net_protocol* protocol, struct sockaddr* address)
status_t status_t
l2cap_listen(net_protocol* protocol, int count) l2cap_listen(net_protocol* protocol, int count)
{ {
CALLED();
return ((L2capEndpoint*)protocol)->Listen(count); return ((L2capEndpoint*)protocol)->Listen(count);
} }
@@ -205,8 +198,7 @@ l2cap_listen(net_protocol* protocol, int count)
status_t status_t
l2cap_shutdown(net_protocol* protocol, int direction) l2cap_shutdown(net_protocol* protocol, int direction)
{ {
flowf("\n"); CALLED();
return EOPNOTSUPP; return EOPNOTSUPP;
} }
@@ -214,7 +206,7 @@ l2cap_shutdown(net_protocol* protocol, int direction)
status_t status_t
l2cap_send_data(net_protocol* protocol, net_buffer* buffer) l2cap_send_data(net_protocol* protocol, net_buffer* buffer)
{ {
flowf("\n"); CALLED();
if (buffer == NULL) if (buffer == NULL)
return ENOBUFS; return ENOBUFS;
@@ -227,8 +219,7 @@ status_t
l2cap_send_routed_data(net_protocol* protocol, struct net_route* route, l2cap_send_routed_data(net_protocol* protocol, struct net_route* route,
net_buffer* buffer) net_buffer* buffer)
{ {
flowf("\n"); CALLED();
return EOPNOTSUPP; return EOPNOTSUPP;
} }
@@ -236,8 +227,7 @@ l2cap_send_routed_data(net_protocol* protocol, struct net_route* route,
ssize_t ssize_t
l2cap_send_avail(net_protocol* protocol) l2cap_send_avail(net_protocol* protocol)
{ {
flowf("\n"); CALLED();
return B_ERROR; return B_ERROR;
} }
@@ -246,8 +236,7 @@ status_t
l2cap_read_data(net_protocol* protocol, size_t numBytes, uint32 flags, l2cap_read_data(net_protocol* protocol, size_t numBytes, uint32 flags,
net_buffer** _buffer) net_buffer** _buffer)
{ {
flowf("\n"); CALLED();
return ((L2capEndpoint*)protocol)->ReadData(numBytes, flags, _buffer); return ((L2capEndpoint*)protocol)->ReadData(numBytes, flags, _buffer);
} }
@@ -255,8 +244,7 @@ l2cap_read_data(net_protocol* protocol, size_t numBytes, uint32 flags,
ssize_t ssize_t
l2cap_read_avail(net_protocol* protocol) l2cap_read_avail(net_protocol* protocol)
{ {
flowf("\n"); CALLED();
return B_ERROR; return B_ERROR;
} }
@@ -264,8 +252,7 @@ l2cap_read_avail(net_protocol* protocol)
struct net_domain* struct net_domain*
l2cap_get_domain(net_protocol* protocol) l2cap_get_domain(net_protocol* protocol)
{ {
flowf("\n"); CALLED();
return sDomain; return sDomain;
} }
@@ -273,8 +260,7 @@ l2cap_get_domain(net_protocol* protocol)
size_t size_t
l2cap_get_mtu(net_protocol* protocol, const struct sockaddr* address) l2cap_get_mtu(net_protocol* protocol, const struct sockaddr* address)
{ {
flowf("\n"); CALLED();
return protocol->next->module->get_mtu(protocol->next, address); return protocol->next->module->get_mtu(protocol->next, address);
} }
@@ -283,7 +269,7 @@ status_t
l2cap_receive_data(net_buffer* buffer) l2cap_receive_data(net_buffer* buffer)
{ {
HciConnection* conn = (HciConnection*)buffer; HciConnection* conn = (HciConnection*)buffer;
debugf("received some data, buffer length %lu\n", TRACE("%s: received some data, buffer length %" B_PRIu32 "\n", __func__,
conn->currentRxPacket->size); conn->currentRxPacket->size);
l2cap_receive(conn, conn->currentRxPacket); l2cap_receive(conn, conn->currentRxPacket);
@@ -295,7 +281,7 @@ l2cap_receive_data(net_buffer* buffer)
status_t status_t
l2cap_error_received(net_error error, net_buffer* data) l2cap_error_received(net_error error, net_buffer* data)
{ {
flowf("\n"); CALLED();
return B_ERROR; return B_ERROR;
} }
@@ -305,7 +291,7 @@ status_t
l2cap_error_reply(net_protocol* protocol, net_buffer* cause, net_error error, l2cap_error_reply(net_protocol* protocol, net_buffer* cause, net_error error,
net_error_data* errorData) net_error_data* errorData)
{ {
flowf("\n"); CALLED();
return B_ERROR; return B_ERROR;
} }
@@ -319,7 +305,7 @@ l2cap_std_ops(int32 op, ...)
{ {
status_t error; status_t error;
flowf("\n"); CALLED();
switch (op) { switch (op) {
case B_MODULE_INIT: case B_MODULE_INIT:
@@ -31,11 +31,9 @@
#include "l2cap_signal.h" #include "l2cap_signal.h"
#include "l2cap_upper.h" #include "l2cap_upper.h"
#define BT_DEBUG_THIS_MODULE
#define SUBMODULE_NAME "lower"
#define SUBMODULE_COLOR 36
#include <btDebug.h> #include <btDebug.h>
status_t status_t
l2cap_receive(HciConnection* conn, net_buffer* buffer) l2cap_receive(HciConnection* conn, net_buffer* buffer)
{ {
@@ -44,7 +42,7 @@ l2cap_receive(HciConnection* conn, net_buffer* buffer)
uint16 length; uint16 length;
#ifdef DUMP_L2CAP_FRAME #ifdef DUMP_L2CAP_FRAME
flowf("DUMP:"); dprintf("DUMP:");
for (uint i = 0; i < buffer->size; i++) { for (uint i = 0; i < buffer->size; i++) {
uint8 c = 0; uint8 c = 0;
gBufferModule->read(buffer, i, &c, 1); gBufferModule->read(buffer, i, &c, 1);
@@ -54,7 +52,8 @@ l2cap_receive(HciConnection* conn, net_buffer* buffer)
#endif #endif
// Check packet // Check packet
if (buffer->size < sizeof(l2cap_hdr_t)) { if (buffer->size < sizeof(l2cap_hdr_t)) {
debugf("invalid L2CAP packet. Packet too small, len=%ld\n", buffer->size); ERROR("%s: invalid L2CAP packet. Packet too small, len=%" B_PRIu32 "\n",
__func__, buffer->size);
gBufferModule->free(buffer); gBufferModule->free(buffer);
return EMSGSIZE; return EMSGSIZE;
@@ -70,14 +69,14 @@ l2cap_receive(HciConnection* conn, net_buffer* buffer)
length = bufferHeader->length = le16toh(bufferHeader->length); length = bufferHeader->length = le16toh(bufferHeader->length);
dcid = bufferHeader->dcid = le16toh(bufferHeader->dcid); dcid = bufferHeader->dcid = le16toh(bufferHeader->dcid);
debugf("len=%d cid=%x\n", length, dcid); TRACE("%s: len=%d cid=%x\n", __func__, length, dcid);
bufferHeader.Remove(); // pulling bufferHeader.Remove(); // pulling
// Check payload size // Check payload size
if (length != buffer->size ) { if (length != buffer->size ) {
debugf("Payload length mismatch, packetlen=%d, bufferlen=%ld\n", ERROR("%s: Payload length mismatch, packetlen=%d, bufferlen=%" B_PRIu32
length, buffer->size); "\n", __func__, length, buffer->size);
gBufferModule->free(buffer); gBufferModule->free(buffer);
return EMSGSIZE; return EMSGSIZE;
} }
@@ -90,7 +89,7 @@ l2cap_receive(HciConnection* conn, net_buffer* buffer)
case L2CAP_CLT_CID: // Connectionless packet case L2CAP_CLT_CID: // Connectionless packet
// error = l2cap_cl_receive(buffer); // error = l2cap_cl_receive(buffer);
flowf("CL FRAME!!\n"); TRACE("%s: CL FRAME!!\n", __func__);
break; break;
default: // Data packet default: // Data packet
@@ -119,7 +118,8 @@ AddL2capHeader(L2capFrame* frame)
status_t status = bufferHeader.Status(); status_t status = bufferHeader.Status();
if (status < B_OK) { if (status < B_OK) {
debugf("header could not be prepended! code=%d\n", frame->code); ERROR("%s: header could not be prepended! code=%d\n", __func__,
frame->code);
return; return;
} }
@@ -142,11 +142,10 @@ AddL2capHeader(L2capFrame* frame)
void void
purge_connection(HciConnection* conn) purge_connection(HciConnection* conn)
{ {
CALLED();
L2capFrame* frame; L2capFrame* frame;
bool containerCanBeDestroyed; bool containerCanBeDestroyed;
debugf("handle=%d\n", conn->handle);
mutex_lock(&conn->fLock); mutex_lock(&conn->fLock);
frame = conn->OutGoingFrames.RemoveHead(); frame = conn->OutGoingFrames.RemoveHead();
@@ -176,8 +175,8 @@ purge_connection(HciConnection* conn)
} // TODO: someone put it } // TODO: someone put it
debugf("type=%d, code=%d frame %p tolower\n", frame->type, frame->code, TRACE("%s: type=%d, code=%d frame %p tolower\n", __func__, frame->type,
frame->buffer); frame->code, frame->buffer);
frame->buffer->type = conn->handle; frame->buffer->type = conn->handle;
btDevices->PostACL(conn->ndevice->index, frame->buffer); btDevices->PostACL(conn->ndevice->index, frame->buffer);
@@ -213,13 +212,13 @@ connection_thread(void*)
while ((ssizePort = port_buffer_size(fPort)) != B_BAD_PORT_ID) { while ((ssizePort = port_buffer_size(fPort)) != B_BAD_PORT_ID) {
if (ssizePort <= 0) { if (ssizePort <= 0) {
debugf("Error %s\n", strerror(ssizePort)); ERROR("%s: Error %s\n", __func__, strerror(ssizePort));
snooze(500 * 1000); snooze(500 * 1000);
continue; continue;
} }
if (ssizePort > (ssize_t) sizeof(conn)) { if (ssizePort > (ssize_t) sizeof(conn)) {
debugf("Message too big %ld\n", ssizePort); ERROR("%s: Message too big %ld\n", __func__, ssizePort);
snooze(500 * 1000); snooze(500 * 1000);
continue; continue;
} }
@@ -227,7 +226,8 @@ connection_thread(void*)
ssizeRead = read_port(fPort, &code, &conn, ssizePort); ssizeRead = read_port(fPort, &code, &conn, ssizePort);
if (ssizeRead != ssizePort) { if (ssizeRead != ssizePort) {
debugf("Missmatch size port=%ld read=%ld\n", ssizePort, ssizeRead); ERROR("%s: Mismatch size port=%ld read=%ld\n", __func__,
ssizePort, ssizeRead);
snooze(500 * 1000); snooze(500 * 1000);
continue; continue;
} }
@@ -242,12 +242,10 @@ connection_thread(void*)
status_t status_t
InitializeConnectionPurgeThread() InitializeConnectionPurgeThread()
{ {
port_id fPort = find_port(BLUETOOTH_CONNECTION_SCHED_PORT); port_id fPort = find_port(BLUETOOTH_CONNECTION_SCHED_PORT);
if (fPort == B_NAME_NOT_FOUND) if (fPort == B_NAME_NOT_FOUND) {
{ TRACE("%s: Creating connection purge port\n", __func__);
fPort = create_port(16, BLUETOOTH_CONNECTION_SCHED_PORT); fPort = create_port(16, BLUETOOTH_CONNECTION_SCHED_PORT);
debugf("Connection purge port created %ld\n",fPort);
} }
// This thread has to catch up connections before first package is sent. // This thread has to catch up connections before first package is sent.
@@ -264,13 +262,13 @@ InitializeConnectionPurgeThread()
status_t status_t
QuitConnectionPurgeThread() QuitConnectionPurgeThread()
{ {
CALLED();
status_t status; status_t status;
port_id fPort = find_port(BLUETOOTH_CONNECTION_SCHED_PORT); port_id fPort = find_port(BLUETOOTH_CONNECTION_SCHED_PORT);
if (fPort != B_NAME_NOT_FOUND) if (fPort != B_NAME_NOT_FOUND)
close_port(fPort); close_port(fPort);
flowf("Connection port deleted\n");
wait_for_thread(sConnectionThread, &status); wait_for_thread(sConnectionThread, &status);
return status; return status;
} }
@@ -286,7 +284,7 @@ SchedConnectionPurgeThread(HciConnection* conn)
if (port == B_NAME_NOT_FOUND) if (port == B_NAME_NOT_FOUND)
panic("BT Connection Port Deleted"); panic("BT Connection Port Deleted");
status_t error = write_port(port, (uint32) conn, &temp, sizeof(conn)); status_t error = write_port(port, (addr_t)conn, &temp, sizeof(conn));
if (error != B_OK) if (error != B_OK)
panic("BT Connection sched failed"); panic("BT Connection sched failed");
@@ -28,9 +28,6 @@
#include "l2cap_upper.h" #include "l2cap_upper.h"
#include "l2cap_lower.h" #include "l2cap_lower.h"
#define BT_DEBUG_THIS_MODULE
#define SUBMODULE_NAME "signal"
#define SUBMODULE_COLOR 36
#include <btDebug.h> #include <btDebug.h>
#include <bluetooth/HCI/btHCI_command.h> #include <bluetooth/HCI/btHCI_command.h>
@@ -102,13 +99,14 @@ l2cap_process_signal_cmd(HciConnection* conn, net_buffer* buffer)
{ {
net_buffer* m = buffer; net_buffer* m = buffer;
debugf("Signal size=%ld\n", buffer->size); TRACE("%s: Signal size=%" B_PRIu32 "\n", __func__, buffer->size);
while (m != NULL) { while (m != NULL) {
/* Verify packet length */ /* Verify packet length */
if (buffer->size < sizeof(l2cap_cmd_hdr_t)) { if (buffer->size < sizeof(l2cap_cmd_hdr_t)) {
debugf("small L2CAP signaling command len=%ld\n", buffer->size); TRACE("%s: small L2CAP signaling command len=%" B_PRIu32 "\n",
__func__, buffer->size);
gBufferModule->free(buffer); gBufferModule->free(buffer);
return EMSGSIZE; return EMSGSIZE;
} }
@@ -126,9 +124,10 @@ l2cap_process_signal_cmd(HciConnection* conn, net_buffer* buffer)
/* Verify command length */ /* Verify command length */
if (buffer->size < processingLength) { if (buffer->size < processingLength) {
debugf("invalid L2CAP signaling command, code=%#x, ident=%d," ERROR("%s: invalid L2CAP signaling command, code=%#x, "
" length=%d, buffer size=%ld\n", processingCode, "ident=%d, length=%d, buffer size=%" B_PRIu32 "\n", __func__,
processingIdent, processingLength, buffer->size); processingCode, processingIdent, processingLength,
buffer->size);
gBufferModule->free(buffer); gBufferModule->free(buffer);
return (EMSGSIZE); return (EMSGSIZE);
} }
@@ -183,8 +182,9 @@ l2cap_process_signal_cmd(HciConnection* conn, net_buffer* buffer)
break; break;
default: default:
debugf("unknown L2CAP signaling command, code=%#x, ident=%d\n", ERROR("%s: unknown L2CAP signaling command, "
processingCode, processingIdent); "code=%#x, ident=%d\n", __func__, processingCode,
processingIdent);
// Send L2CAP_CommandRej. Do not really care about the result // Send L2CAP_CommandRej. Do not really care about the result
// ORD: Remiaining commands in the same packet are also to // ORD: Remiaining commands in the same packet are also to
@@ -235,10 +235,10 @@ l2cap_process_con_req(HciConnection* conn, uint8 ident, net_buffer* buffer)
// notification to the upper layer protocol. // notification to the upper layer protocol.
channel = btCoreData->AddChannel(conn, psm /*, dcid, ident*/); channel = btCoreData->AddChannel(conn, psm /*, dcid, ident*/);
if (channel == NULL) { if (channel == NULL) {
flowf("No resources to create channel\n"); TRACE("%s: No resources to create channel\n", __func__);
return (send_l2cap_con_rej(conn, ident, 0, dcid, L2CAP_NO_RESOURCES)); return (send_l2cap_con_rej(conn, ident, 0, dcid, L2CAP_NO_RESOURCES));
} else { } else {
debugf("New channel created scid=%d\n", channel->scid); TRACE("%s: New channel created scid=%d\n", __func__, channel->scid);
} }
channel->dcid = dcid; channel->dcid = dcid;
@@ -282,27 +282,28 @@ l2cap_process_con_rsp(HciConnection* conn, uint8 ident, net_buffer* buffer)
command.Remove(); // pull the command body command.Remove(); // pull the command body
debugf("dcid=%d scid=%d result=%d status%d\n", dcid, scid, result, status); TRACE("%s: dcid=%d scid=%d result=%d status%d\n", __func__, dcid, scid,
result, status);
/* Check if we have pending command descriptor */ /* Check if we have pending command descriptor */
cmd = btCoreData->SignalByIdent(conn, ident); cmd = btCoreData->SignalByIdent(conn, ident);
if (cmd == NULL) { if (cmd == NULL) {
debugf("unexpected L2CAP_ConnectRsp command. ident=%d, " ERROR("%s: unexpected L2CAP_ConnectRsp command. ident=%d, "
"con_handle=%d\n", ident, conn->handle); "con_handle=%d\n", __func__, ident, conn->handle);
return ENOENT; return ENOENT;
} }
/* Verify channel state, if invalid - do nothing */ /* Verify channel state, if invalid - do nothing */
if (cmd->channel->state != L2CAP_CHAN_W4_L2CAP_CON_RSP) { if (cmd->channel->state != L2CAP_CHAN_W4_L2CAP_CON_RSP) {
debugf("unexpected L2CAP_ConnectRsp. Invalid channel state, " ERROR("%s: unexpected L2CAP_ConnectRsp. Invalid channel state, "
"cid=%d, state=%d\n", scid, cmd->channel->state); "cid=%d, state=%d\n", __func__, scid, cmd->channel->state);
goto reject; goto reject;
} }
/* Verify CIDs and send reject if does not match */ /* Verify CIDs and send reject if does not match */
if (cmd->channel->scid != scid) { if (cmd->channel->scid != scid) {
debugf("unexpected L2CAP_ConnectRsp. Channel IDs do not match, " ERROR("%s: unexpected L2CAP_ConnectRsp. Channel IDs do not match, "
"scid=%d(%d)\n", cmd->channel->scid, scid); "scid=%d(%d)\n", __func__, cmd->channel->scid, scid);
goto reject; goto reject;
} }
@@ -349,8 +350,8 @@ l2cap_process_con_rsp(HciConnection* conn, uint8 ident, net_buffer* buffer)
/* XXX do we have to remove the channel on error? */ /* XXX do we have to remove the channel on error? */
if (error != 0 || result != L2CAP_SUCCESS) { if (error != 0 || result != L2CAP_SUCCESS) {
debugf("failed to open L2CAP channel, result=%d, status=%d\n", ERROR("%s: failed to open L2CAP channel, result=%d, status=%d\n",
result, status); __func__, result, status);
btCoreData->RemoveChannel(conn, cmd->channel->scid); btCoreData->RemoveChannel(conn, cmd->channel->scid);
} }
@@ -394,7 +395,7 @@ getNextSignalOption(net_buffer* nbuf, size_t* off, l2cap_cfg_opt_t* hdr,
gBufferModule->read(nbuf, *off, val, L2CAP_OPT_MTU_SIZE); gBufferModule->read(nbuf, *off, val, L2CAP_OPT_MTU_SIZE);
val->mtu = le16toh(val->mtu); val->mtu = le16toh(val->mtu);
*off += L2CAP_OPT_MTU_SIZE; *off += L2CAP_OPT_MTU_SIZE;
debugf("mtu %d specified\n", val->mtu); TRACE("%s: mtu %d specified\n", __func__, val->mtu);
break; break;
case L2CAP_OPT_FLUSH_TIMO: case L2CAP_OPT_FLUSH_TIMO:
@@ -403,7 +404,7 @@ getNextSignalOption(net_buffer* nbuf, size_t* off, l2cap_cfg_opt_t* hdr,
gBufferModule->read(nbuf, *off, val, L2CAP_OPT_FLUSH_TIMO_SIZE); gBufferModule->read(nbuf, *off, val, L2CAP_OPT_FLUSH_TIMO_SIZE);
val->flush_timo = le16toh(val->flush_timo); val->flush_timo = le16toh(val->flush_timo);
flowf("flush specified\n"); TRACE("%s: flush specified\n", __func__);
*off += L2CAP_OPT_FLUSH_TIMO_SIZE; *off += L2CAP_OPT_FLUSH_TIMO_SIZE;
break; break;
@@ -418,7 +419,7 @@ getNextSignalOption(net_buffer* nbuf, size_t* off, l2cap_cfg_opt_t* hdr,
val->flow.latency = le32toh(val->flow.latency); val->flow.latency = le32toh(val->flow.latency);
val->flow.delay_variation = le32toh(val->flow.delay_variation); val->flow.delay_variation = le32toh(val->flow.delay_variation);
*off += L2CAP_OPT_QOS_SIZE; *off += L2CAP_OPT_QOS_SIZE;
flowf("qos specified\n"); TRACE("%s: qos specified\n", __func__);
break; break;
default: default:
@@ -447,8 +448,6 @@ l2cap_process_cfg_req(HciConnection* conn, uint8 ident, net_buffer* buffer)
size_t off; size_t off;
status_t error = 0; status_t error = 0;
debugf("configuration=%ld\n", buffer->size);
/* Get command parameters */ /* Get command parameters */
NetBufferHeaderReader<l2cap_cfg_req_cp> command(buffer); NetBufferHeaderReader<l2cap_cfg_req_cp> command(buffer);
status_t status = command.Status(); status_t status = command.Status();
@@ -464,16 +463,16 @@ l2cap_process_cfg_req(HciConnection* conn, uint8 ident, net_buffer* buffer)
/* Check if we have this channel and it is in valid state */ /* Check if we have this channel and it is in valid state */
channel = btCoreData->ChannelBySourceID(conn, dcid); channel = btCoreData->ChannelBySourceID(conn, dcid);
if (channel == NULL) { if (channel == NULL) {
debugf("unexpected L2CAP_ConfigReq command. " ERROR("%s: unexpected L2CAP_ConfigReq command. "
"Channel does not exist, cid=%d\n", dcid); "Channel does not exist, cid=%d\n", __func__, dcid);
goto reject; goto reject;
} }
/* Verify channel state */ /* Verify channel state */
if (channel->state != L2CAP_CHAN_CONFIG if (channel->state != L2CAP_CHAN_CONFIG
&& channel->state != L2CAP_CHAN_OPEN) { && channel->state != L2CAP_CHAN_OPEN) {
debugf("unexpected L2CAP_ConfigReq. Invalid channel state, " ERROR("%s: unexpected L2CAP_ConfigReq. Invalid channel state, "
"cid=%d, state=%d\n", dcid, channel->state); "cid=%d, state=%d\n", __func__, dcid, channel->state);
goto reject; goto reject;
} }
@@ -521,8 +520,8 @@ l2cap_process_cfg_req(HciConnection* conn, uint8 ident, net_buffer* buffer)
} }
} }
debugf("Pulled %ld of configuration fields respond=%d remaining=%ld\n", TRACE("%s: Pulled %ld of configuration fields respond=%d "
off, respond, buffer->size); "remaining=%" B_PRIu32 "\n", __func__, off, respond, buffer->size);
gBufferModule->remove_header(buffer, off); gBufferModule->remove_header(buffer, off);
@@ -539,7 +538,6 @@ l2cap_process_cfg_req(HciConnection* conn, uint8 ident, net_buffer* buffer)
*/ */
if (respond) { if (respond) {
flowf("Refusing cfg\n");
error = send_l2cap_cfg_rsp(conn, ident, channel->dcid, result, buffer); error = send_l2cap_cfg_rsp(conn, ident, channel->dcid, result, buffer);
if (error != 0) { if (error != 0) {
// TODO: // TODO:
@@ -592,28 +590,28 @@ l2cap_process_cfg_rsp(HciConnection* conn, uint8 ident, net_buffer* buffer)
command.Remove(); command.Remove();
debugf("scid=%d cflag=%d result=%d\n", scid, cflag, result); TRACE("%s: scid=%d cflag=%d result=%d\n", __func__, scid, cflag, result);
/* Check if we have this command */ /* Check if we have this command */
cmd = btCoreData->SignalByIdent(conn, ident); cmd = btCoreData->SignalByIdent(conn, ident);
if (cmd == NULL) { if (cmd == NULL) {
debugf("unexpected L2CAP_ConfigRsp command. ident=%d, con_handle=%d\n", ERROR("%s: unexpected L2CAP_ConfigRsp command. "
ident, conn->handle); "ident=%d, con_handle=%d\n", __func__, ident, conn->handle);
gBufferModule->free(buffer); gBufferModule->free(buffer);
return ENOENT; return ENOENT;
} }
/* Verify CIDs and send reject if does not match */ /* Verify CIDs and send reject if does not match */
if (cmd->channel->scid != scid) { if (cmd->channel->scid != scid) {
debugf("unexpected L2CAP_ConfigRsp.Channel ID does not match, " ERROR("%s: unexpected L2CAP_ConfigRsp.Channel ID does not match, "
"scid=%d(%d)\n", cmd->channel->scid, scid); "scid=%d(%d)\n", __func__, cmd->channel->scid, scid);
goto reject; goto reject;
} }
/* Verify channel state and reject if invalid */ /* Verify channel state and reject if invalid */
if (cmd->channel->state != L2CAP_CHAN_CONFIG) { if (cmd->channel->state != L2CAP_CHAN_CONFIG) {
debugf("unexpected L2CAP_ConfigRsp. Invalid channel state, scid=%d, " ERROR("%s: unexpected L2CAP_ConfigRsp. Invalid channel state, scid=%d, "
"state=%d\n", cmd->channel->scid, cmd->channel->state); "state=%d\n", __func__, cmd->channel->scid, cmd->channel->state);
goto reject; goto reject;
} }
@@ -664,7 +662,8 @@ l2cap_process_cfg_rsp(HciConnection* conn, uint8 ident, net_buffer* buffer)
* upper layer know and do not wait for more options. * upper layer know and do not wait for more options.
*/ */
debugf("fail parsing configuration options, error=%ld\n", error); ERROR("%s: fail parsing configuration options\n", __func__);
// INDICATION // INDICATION
result = L2CAP_UNKNOWN; result = L2CAP_UNKNOWN;
cflag = 0; cflag = 0;
@@ -686,7 +685,7 @@ l2cap_process_cfg_rsp(HciConnection* conn, uint8 ident, net_buffer* buffer)
* remote peer? * remote peer?
*/ */
debugf("failed to send L2CA_Config response, error=%ld\n", error); ERROR("%s: failed to send L2CA_Config response\n", __func__);
btCoreData->RemoveChannel(conn, cmd->channel->scid); btCoreData->RemoveChannel(conn, cmd->channel->scid);
} }
@@ -729,8 +728,8 @@ l2cap_process_discon_req(HciConnection* conn, uint8 ident, net_buffer* buffer)
/* Check if we have this channel and it is in valid state */ /* Check if we have this channel and it is in valid state */
channel = btCoreData->ChannelBySourceID(conn, dcid); channel = btCoreData->ChannelBySourceID(conn, dcid);
if (channel == NULL) { if (channel == NULL) {
debugf("unexpected L2CAP_DisconnectReq message.Channel does not exist, " ERROR("%s: unexpected L2CAP_DisconnectReq message. "
"cid=%x\n", dcid); "Channel does not exist, cid=%x\n", __func__, dcid);
goto reject; goto reject;
} }
@@ -738,15 +737,15 @@ l2cap_process_discon_req(HciConnection* conn, uint8 ident, net_buffer* buffer)
if (channel->state != L2CAP_CHAN_OPEN if (channel->state != L2CAP_CHAN_OPEN
&& channel->state != L2CAP_CHAN_CONFIG && channel->state != L2CAP_CHAN_CONFIG
&& channel->state != L2CAP_CHAN_W4_L2CAP_DISCON_RSP) { && channel->state != L2CAP_CHAN_W4_L2CAP_DISCON_RSP) {
debugf("unexpected L2CAP_DisconnectReq. Invalid channel state, cid=%d, " ERROR("%s: unexpected L2CAP_DisconnectReq. Invalid channel state, "
"state=%d\n", dcid, channel->state); "cid=%d, state=%d\n", __func__, dcid, channel->state);
goto reject; goto reject;
} }
/* Match destination channel ID */ /* Match destination channel ID */
if (channel->dcid != scid || channel->scid != dcid) { if (channel->dcid != scid || channel->scid != dcid) {
debugf("unexpected L2CAP_DisconnectReq. Channel IDs does not match, " ERROR("%s: unexpected L2CAP_DisconnectReq. Channel IDs does not match, "
"channel: scid=%d, dcid=%d, request: scid=%d, dcid=%d\n", "channel: scid=%d, dcid=%d, request: scid=%d, dcid=%d\n", __func__,
channel->scid, channel->dcid, scid, dcid); channel->scid, channel->dcid, scid, dcid);
goto reject; goto reject;
} }
@@ -757,8 +756,6 @@ l2cap_process_discon_req(HciConnection* conn, uint8 ident, net_buffer* buffer)
* with L2CAP_DisconnectRsp. * with L2CAP_DisconnectRsp.
*/ */
flowf("Responding\n");
// inform upper if we were not actually already waiting // inform upper if we were not actually already waiting
if (channel->state != L2CAP_CHAN_W4_L2CAP_DISCON_RSP) { if (channel->state != L2CAP_CHAN_W4_L2CAP_DISCON_RSP) {
l2cap_discon_req_ind(channel); // do not care about result l2cap_discon_req_ind(channel); // do not care about result
@@ -776,7 +773,6 @@ l2cap_process_discon_req(HciConnection* conn, uint8 ident, net_buffer* buffer)
return B_OK; return B_OK;
reject: reject:
flowf("Rejecting\n");
/* Send reject. Do not really care about the result */ /* Send reject. Do not really care about the result */
send_l2cap_reject(conn, ident, L2CAP_REJ_INVALID_CID, 0, scid, dcid); send_l2cap_reject(conn, ident, L2CAP_REJ_INVALID_CID, 0, scid, dcid);
@@ -808,22 +804,22 @@ l2cap_process_discon_rsp(HciConnection* conn, uint8 ident, net_buffer* buffer)
/* Check if we have pending command descriptor */ /* Check if we have pending command descriptor */
cmd = btCoreData->SignalByIdent(conn, ident); cmd = btCoreData->SignalByIdent(conn, ident);
if (cmd == NULL) { if (cmd == NULL) {
debugf("unexpected L2CAP_DisconnectRsp command. ident=%d, " ERROR("%s: unexpected L2CAP_DisconnectRsp command. ident=%d, "
"con_handle=%d\n", ident, conn->handle); "con_handle=%d\n", __func__, ident, conn->handle);
goto out; goto out;
} }
/* Verify channel state, do nothing if invalid */ /* Verify channel state, do nothing if invalid */
if (cmd->channel->state != L2CAP_CHAN_W4_L2CA_DISCON_RSP) { if (cmd->channel->state != L2CAP_CHAN_W4_L2CA_DISCON_RSP) {
debugf("unexpected L2CAP_DisconnectRsp. Invalid state, cid=%d, " ERROR("%s: unexpected L2CAP_DisconnectRsp. Invalid state, cid=%d, "
"state=%d\n", scid, cmd->channel->state); "state=%d\n", __func__, scid, cmd->channel->state);
goto out; goto out;
} }
/* Verify CIDs and send reject if does not match */ /* Verify CIDs and send reject if does not match */
if (cmd->channel->scid != scid || cmd->channel->dcid != dcid) { if (cmd->channel->scid != scid || cmd->channel->dcid != dcid) {
debugf("unexpected L2CAP_DisconnectRsp. Channel IDs do not match, " ERROR("%s: unexpected L2CAP_DisconnectRsp. Channel IDs do not match, "
"scid=%d(%d), dcid=%d(%d)\n", cmd->channel->scid, scid, "scid=%d(%d), dcid=%d(%d)\n", __func__, cmd->channel->scid, scid,
cmd->channel->dcid, dcid); cmd->channel->dcid, dcid);
goto out; goto out;
} }
@@ -884,8 +880,8 @@ l2cap_process_echo_rsp(HciConnection* conn, uint8 ident, net_buffer* buffer)
btCoreData->AcknowledgeSignal(cmd); btCoreData->AcknowledgeSignal(cmd);
} else { } else {
debugf("unexpected L2CAP_EchoRsp command. ident does not exist, " ERROR("%s: unexpected L2CAP_EchoRsp command. ident does not exist, "
"ident=%d\n", ident); "ident=%d\n", __func__, ident);
gBufferModule->free(buffer); gBufferModule->free(buffer);
error = B_ERROR; error = B_ERROR;
} }
@@ -961,8 +957,8 @@ l2cap_process_info_rsp(HciConnection* conn, uint8 ident, net_buffer* buffer)
/* Check if we have pending command descriptor */ /* Check if we have pending command descriptor */
cmd = btCoreData->SignalByIdent(conn, ident); cmd = btCoreData->SignalByIdent(conn, ident);
if (cmd == NULL) { if (cmd == NULL) {
debugf("unexpected L2CAP_InfoRsp command. Requested ident does not " ERROR("%s: unexpected L2CAP_InfoRsp command. Requested ident does not "
"exist, ident=%d\n", ident); "exist, ident=%d\n", __func__, ident);
gBufferModule->free(buffer); gBufferModule->free(buffer);
return ENOENT; return ENOENT;
} }
@@ -975,19 +971,24 @@ l2cap_process_info_rsp(HciConnection* conn, uint8 ident, net_buffer* buffer)
if (command->result == L2CAP_SUCCESS) { if (command->result == L2CAP_SUCCESS) {
switch (command->type) { switch (command->type) {
case L2CAP_CONNLESS_MTU: case L2CAP_CONNLESS_MTU:
/* TODO: Check specs ?? #if 0
/* TODO: Check specs ?? */
if (conn->rx_pkt->m_pkthdr.len == sizeof(uint16)) { if (conn->rx_pkt->m_pkthdr.len == sizeof(uint16)) {
*mtod(conn->rx_pkt, uint16 *) = le16toh(*mtod(conn->rx_pkt,uint16 *)); *mtod(conn->rx_pkt, uint16 *)
= le16toh(*mtod(conn->rx_pkt, uint16 *));
} else { } else {
cp->result = L2CAP_UNKNOWN; XXX cp->result = L2CAP_UNKNOWN; XXX
debugf("invalid L2CAP_InfoRsp command. Bad connectionless MTU parameter, len=%d\n", conn->rx_pkt->m_pkthdr.len); ERROR("%s: invalid L2CAP_InfoRsp command. "
}*/ "Bad connectionless MTU parameter, len=%d\n", __func__,
conn->rx_pkt->m_pkthdr.len);
}
#endif
break; break;
default: default:
debugf("invalid L2CAP_InfoRsp command. Unknown info type=%d\n", cp->type); ERROR("%s: invalid L2CAP_InfoRsp command. "
"Unknown info type=%d\n", __func__, cp->type);
break; break;
} }
} }
@@ -1013,7 +1014,7 @@ l2cap_process_cmd_rej(HciConnection* conn, uint8 ident, net_buffer* buffer)
command->reason = le16toh(command->reason); command->reason = le16toh(command->reason);
debugf("reason=%d\n", command->reason); TRACE("%s: reason=%d\n", __func__, command->reason);
command.Remove(); command.Remove();
@@ -1051,14 +1052,17 @@ l2cap_process_cmd_rej(HciConnection* conn, uint8 ident, net_buffer* buffer)
break; break;
default: default:
debugf("unexpected L2CAP_CommandRej. Unexpected opcode=%d\n", cmd->code); ERROR("%s: unexpected L2CAP_CommandRej. Unexpected opcode=%d\n",
__func__, cmd->code);
break; break;
} }
btCoreData->AcknowledgeSignal(cmd); btCoreData->AcknowledgeSignal(cmd);
} else } else {
debugf("unexpected L2CAP_CommandRej command. Requested ident does not exist, ident=%d\n", ident); ERROR("%s: unexpected L2CAP_CommandRej command. "
"Requested ident does not exist, ident=%d\n", __func__, ident);
}
return B_OK; return B_OK;
} }
@@ -30,7 +30,7 @@ l2cap_l2ca_con_ind(L2capChannel* channel)
L2capEndpoint* endpoint = L2capEndpoint::ForPsm(channel->psm); L2capEndpoint* endpoint = L2capEndpoint::ForPsm(channel->psm);
if (endpoint == NULL) { // TODO: refuse connection no endpoint bound if (endpoint == NULL) { // TODO: refuse connection no endpoint bound
debugf("No endpoint bound for psm %d\n", channel->psm); ERROR("%s: No endpoint bound for psm %d\n", __func__, channel->psm);
return B_ERROR; return B_ERROR;
} }
@@ -62,15 +62,16 @@ l2cap_con_rsp_ind(HciConnection* conn, L2capChannel* channel)
uint16* mtu = NULL; uint16* mtu = NULL;
l2cap_flow_t* flow = NULL; l2cap_flow_t* flow = NULL;
flowf("\n"); CALLED();
// We received a configuration response, connection process // We received a configuration response, connection process
// is a step further but still configuration pending // is a step further but still configuration pending
// Check channel state // Check channel state
if (channel->state != L2CAP_CHAN_OPEN && channel->state != L2CAP_CHAN_CONFIG) { if (channel->state != L2CAP_CHAN_OPEN
debugf("unexpected L2CA_Config request message. Invalid channel" \ && channel->state != L2CAP_CHAN_CONFIG) {
" state, state=%d, lcid=%d\n", channel->state, channel->scid); ERROR("%s: unexpected L2CA_Config request message. Invalid channel"
" state, state=%d, lcid=%d\n", __func__, channel->state, channel->scid);
return EINVAL; return EINVAL;
} }
@@ -122,7 +123,7 @@ l2cap_con_rsp_ind(HciConnection* conn, L2capChannel* channel)
channel->cfgState = 0; channel->cfgState = 0;
} }
flowf("Sending cfg req\n"); TRACE("%s: Sending cfg req\n", __func__);
// Link command to the queue // Link command to the queue
SchedConnectionPurgeThread(channel->conn); SchedConnectionPurgeThread(channel->conn);
@@ -161,19 +162,14 @@ l2cap_cfg_req_ind(L2capChannel* channel)
return ENOMEM; return ENOMEM;
} }
flowf("Sending cfg resp\n");
// Link command to the queue // Link command to the queue
SchedConnectionPurgeThread(channel->conn); SchedConnectionPurgeThread(channel->conn);
// set status // set status
channel->cfgState |= L2CAP_CFG_OUT_SENT; channel->cfgState |= L2CAP_CFG_OUT_SENT;
} else {
} }
if ((channel->cfgState & L2CAP_CFG_BOTH) == L2CAP_CFG_BOTH) { if ((channel->cfgState & L2CAP_CFG_BOTH) == L2CAP_CFG_BOTH) {
// Channel can be declared open // Channel can be declared open
channel->endpoint->MarkEstablished(); channel->endpoint->MarkEstablished();
@@ -195,8 +191,6 @@ l2cap_cfg_req_ind(L2capChannel* channel)
return ENOMEM; return ENOMEM;
} }
flowf("Sending cfg req\n");
// Link command to the queue // Link command to the queue
SchedConnectionPurgeThread(channel->conn); SchedConnectionPurgeThread(channel->conn);
@@ -287,17 +281,18 @@ l2cap_upper_dis_req(L2capChannel* channel)
status_t status_t
l2cap_co_receive(HciConnection* conn, net_buffer* buffer, uint16 dcid) l2cap_co_receive(HciConnection* conn, net_buffer* buffer, uint16 dcid)
{ {
debugf("Handle %d To dcid %x size=%ld\n", conn->handle, dcid, buffer->size); CALLED();
L2capChannel* channel = btCoreData->ChannelBySourceID(conn, dcid); L2capChannel* channel = btCoreData->ChannelBySourceID(conn, dcid);
if (channel == NULL) { if (channel == NULL) {
debugf("dcid %d does not exist for handle %d\n", dcid, conn->handle); ERROR("%s: dcid %d does not exist for handle %d\n", __func__,
dcid, conn->handle);
return B_ERROR; return B_ERROR;
} }
if (channel->endpoint == NULL) { if (channel->endpoint == NULL) {
debugf("dcid %d not bound to endpoint\n", dcid); ERROR("%s: dcid %d not bound to endpoint\n", __func__, dcid);
return B_ERROR; return B_ERROR;
} }
@@ -312,11 +307,10 @@ l2cap_cl_receive(HciConnection* conn, net_buffer* buffer, uint16 psm)
L2capEndpoint* endpoint = L2capEndpoint::ForPsm(psm); L2capEndpoint* endpoint = L2capEndpoint::ForPsm(psm);
if (endpoint == NULL) { if (endpoint == NULL) {
debugf("no enpoint bound with psm %d\n", psm); ERROR("%s: no endpoint bound with psm %d\n", __func__, psm);
return B_ERROR; return B_ERROR;
} }
flowf("Enqueue to fifo\n");
return gStackModule->fifo_enqueue_buffer( return gStackModule->fifo_enqueue_buffer(
&endpoint->fReceivingFifo, buffer); &endpoint->fReceivingFifo, buffer);
} }