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