Andrei Emeltchenko | 466f800 | 2012-05-29 13:59:01 +0300 | [diff] [blame^] | 1 | /* |
| 2 | Copyright (c) 2010,2011 Code Aurora Forum. All rights reserved. |
| 3 | Copyright (c) 2011,2012 Intel Corp. |
| 4 | |
| 5 | This program is free software; you can redistribute it and/or modify |
| 6 | it under the terms of the GNU General Public License version 2 and |
| 7 | only version 2 as published by the Free Software Foundation. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | GNU General Public License for more details. |
| 13 | */ |
| 14 | |
| 15 | #include <net/bluetooth/bluetooth.h> |
| 16 | #include <net/bluetooth/hci_core.h> |
| 17 | #include <net/bluetooth/l2cap.h> |
| 18 | |
| 19 | static struct l2cap_ops a2mp_chan_ops = { |
| 20 | .name = "L2CAP A2MP channel", |
| 21 | }; |
| 22 | |
| 23 | static struct l2cap_chan *a2mp_chan_open(struct l2cap_conn *conn) |
| 24 | { |
| 25 | struct l2cap_chan *chan; |
| 26 | int err; |
| 27 | |
| 28 | chan = l2cap_chan_create(); |
| 29 | if (!chan) |
| 30 | return NULL; |
| 31 | |
| 32 | BT_DBG("chan %p", chan); |
| 33 | |
| 34 | hci_conn_hold(conn->hcon); |
| 35 | |
| 36 | chan->omtu = L2CAP_A2MP_DEFAULT_MTU; |
| 37 | chan->imtu = L2CAP_A2MP_DEFAULT_MTU; |
| 38 | chan->flush_to = L2CAP_DEFAULT_FLUSH_TO; |
| 39 | |
| 40 | chan->ops = &a2mp_chan_ops; |
| 41 | |
| 42 | l2cap_chan_set_defaults(chan); |
| 43 | chan->remote_max_tx = chan->max_tx; |
| 44 | chan->remote_tx_win = chan->tx_win; |
| 45 | |
| 46 | chan->retrans_timeout = L2CAP_DEFAULT_RETRANS_TO; |
| 47 | chan->monitor_timeout = L2CAP_DEFAULT_MONITOR_TO; |
| 48 | |
| 49 | skb_queue_head_init(&chan->tx_q); |
| 50 | |
| 51 | chan->mode = L2CAP_MODE_ERTM; |
| 52 | |
| 53 | err = l2cap_ertm_init(chan); |
| 54 | if (err < 0) { |
| 55 | l2cap_chan_del(chan, 0); |
| 56 | return NULL; |
| 57 | } |
| 58 | |
| 59 | chan->conf_state = 0; |
| 60 | |
| 61 | l2cap_chan_add(conn, chan); |
| 62 | |
| 63 | chan->remote_mps = chan->omtu; |
| 64 | chan->mps = chan->omtu; |
| 65 | |
| 66 | chan->state = BT_CONNECTED; |
| 67 | |
| 68 | return chan; |
| 69 | } |