Bluetooth: L2CAP: Add initial server support
This adds bt_l2cap_server_register which can be used to register a server to a given PSM. Change-Id: I301dc26a0ed881230568aa0fdd6cc5d0d6dd814a Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
parent
7c7a94ae4e
commit
f98f423381
2 changed files with 45 additions and 0 deletions
|
@ -41,6 +41,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static struct bt_l2cap_chan *channels;
|
static struct bt_l2cap_chan *channels;
|
||||||
|
static struct bt_l2cap_server *servers;
|
||||||
|
|
||||||
static uint8_t get_ident(struct bt_conn *conn)
|
static uint8_t get_ident(struct bt_conn *conn)
|
||||||
{
|
{
|
||||||
|
@ -62,6 +63,39 @@ void bt_l2cap_chan_register(struct bt_l2cap_chan *chan)
|
||||||
channels = chan;
|
channels = chan;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct bt_l2cap_server *l2cap_server_lookup_psm(uint16_t psm)
|
||||||
|
{
|
||||||
|
struct bt_l2cap_server *server;
|
||||||
|
|
||||||
|
for (server = servers; server; server = server->_next) {
|
||||||
|
if (server->psm == psm) {
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int bt_l2cap_server_register(struct bt_l2cap_server *server)
|
||||||
|
{
|
||||||
|
if (server->psm < 0x0080 || server->psm > 0x00ff || !server->accept) {
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check if given PSM is already in use */
|
||||||
|
if (l2cap_server_lookup_psm(server->psm)) {
|
||||||
|
BT_DBG("PSM already registered\n");
|
||||||
|
return -EADDRINUSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
BT_DBG("PSM 0x%04x\n", server->psm);
|
||||||
|
|
||||||
|
server->_next = servers;
|
||||||
|
servers = server;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void bt_l2cap_connected(struct bt_conn *conn)
|
void bt_l2cap_connected(struct bt_conn *conn)
|
||||||
{
|
{
|
||||||
struct bt_l2cap_chan *chan;
|
struct bt_l2cap_chan *chan;
|
||||||
|
|
|
@ -70,9 +70,20 @@ struct bt_l2cap_chan {
|
||||||
struct bt_l2cap_chan *_next;
|
struct bt_l2cap_chan *_next;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct bt_l2cap_server {
|
||||||
|
uint16_t psm;
|
||||||
|
|
||||||
|
int (*accept)(struct bt_conn *conn, struct bt_l2cap_chan **chan);
|
||||||
|
|
||||||
|
struct bt_l2cap_server *_next;
|
||||||
|
};
|
||||||
|
|
||||||
/* Register a fixed L2CAP channel for L2CAP */
|
/* Register a fixed L2CAP channel for L2CAP */
|
||||||
void bt_l2cap_chan_register(struct bt_l2cap_chan *chan);
|
void bt_l2cap_chan_register(struct bt_l2cap_chan *chan);
|
||||||
|
|
||||||
|
/* Register L2CAP Server */
|
||||||
|
int bt_l2cap_server_register(struct bt_l2cap_server *server);
|
||||||
|
|
||||||
/* Notify L2CAP channels of a new connection */
|
/* Notify L2CAP channels of a new connection */
|
||||||
void bt_l2cap_connected(struct bt_conn *conn);
|
void bt_l2cap_connected(struct bt_conn *conn);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue