Bluetooth: L2CAP: Add API to register PSM server

Enables API to register PSM server on BREDR transport.
Adds l2cap_br.c file responsible for BREDR specific functionality to
build path based on Kconfig selection.

Change-Id: I92823b0207ab0da96bfb813353de9f95fa5dd0f4
Origin: Original
Signed-off-by: Arkadiusz Lichwa <arkadiusz.lichwa@tieto.com>
This commit is contained in:
Arkadiusz Lichwa 2016-04-25 15:14:24 +02:00
commit 8e34b5869b
3 changed files with 98 additions and 1 deletions

View file

@ -163,6 +163,20 @@ struct bt_l2cap_server {
*/
int bt_l2cap_server_register(struct bt_l2cap_server *server);
#if defined(CONFIG_BLUETOOTH_BREDR)
/** @brief Register L2CAP server on BR/EDR oriented connection.
*
* Register L2CAP server for a PSM, each new connection is authorized using
* the accept() callback which in case of success shall allocate the channel
* structure to be used by the new connection.
*
* @param server Server structure.
*
* @return 0 in case of success or negative value in case of error.
*/
int bt_l2cap_br_server_register(struct bt_l2cap_server *server);
#endif /* CONFIG_BLUETOOTH_BREDR */
/** @brief Connect L2CAP channel
*
* Connect L2CAP channel by PSM, once the connection is completed channel

View file

@ -19,5 +19,5 @@ ifeq ($(CONFIG_BLUETOOTH_CONN),y)
obj-y += smp_null.o
endif
obj-$(CONFIG_BLUETOOTH_BREDR) += keys.o
obj-$(CONFIG_BLUETOOTH_BREDR) += keys.o l2cap_br.o
endif

83
net/bluetooth/l2cap_br.c Normal file
View file

@ -0,0 +1,83 @@
/* l2cap_br.c - L2CAP BREDR oriented handling */
/*
* Copyright (c) 2016 Intel Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <nanokernel.h>
#include <arch/cpu.h>
#include <toolchain.h>
#include <string.h>
#include <errno.h>
#include <atomic.h>
#include <misc/byteorder.h>
#include <misc/util.h>
#include <bluetooth/log.h>
#include <bluetooth/hci.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/conn.h>
#include "hci_core.h"
#include "conn_internal.h"
#include "l2cap_internal.h"
#if !defined(CONFIG_BLUETOOTH_DEBUG_L2CAP)
#undef BT_DBG
#define BT_DBG(fmt, ...)
#endif
#define L2CAP_BR_PSM_START 0x0001
#define L2CAP_BR_PSM_END 0xffff
static struct bt_l2cap_server *br_servers;
static struct bt_l2cap_server *l2cap_br_server_lookup_psm(uint16_t psm)
{
struct bt_l2cap_server *server;
for (server = br_servers; server; server = server->_next) {
if (server->psm == psm) {
return server;
}
}
return NULL;
}
int bt_l2cap_br_server_register(struct bt_l2cap_server *server)
{
if (server->psm < L2CAP_BR_PSM_START || !server->accept) {
return -EINVAL;
}
/* PSM must be odd and lsb of upper byte must be 0 */
if ((server->psm & 0x0101) != 0x0001) {
return -EINVAL;
}
/* Check if given PSM is already in use */
if (l2cap_br_server_lookup_psm(server->psm)) {
BT_DBG("PSM already registered");
return -EADDRINUSE;
}
BT_DBG("PSM 0x%04x", server->psm);
server->_next = br_servers;
br_servers = server;
return 0;
}