l2cap_upper.c revision 1.1.4.2 1 1.1.4.2 chap /* $NetBSD: l2cap_upper.c,v 1.1.4.2 2006/06/22 03:39:50 chap Exp $ */
2 1.1.4.2 chap
3 1.1.4.2 chap /*-
4 1.1.4.2 chap * Copyright (c) 2005 Iain Hibbert.
5 1.1.4.2 chap * Copyright (c) 2006 Itronix Inc.
6 1.1.4.2 chap * All rights reserved.
7 1.1.4.2 chap *
8 1.1.4.2 chap * Redistribution and use in source and binary forms, with or without
9 1.1.4.2 chap * modification, are permitted provided that the following conditions
10 1.1.4.2 chap * are met:
11 1.1.4.2 chap * 1. Redistributions of source code must retain the above copyright
12 1.1.4.2 chap * notice, this list of conditions and the following disclaimer.
13 1.1.4.2 chap * 2. Redistributions in binary form must reproduce the above copyright
14 1.1.4.2 chap * notice, this list of conditions and the following disclaimer in the
15 1.1.4.2 chap * documentation and/or other materials provided with the distribution.
16 1.1.4.2 chap * 3. The name of Itronix Inc. may not be used to endorse
17 1.1.4.2 chap * or promote products derived from this software without specific
18 1.1.4.2 chap * prior written permission.
19 1.1.4.2 chap *
20 1.1.4.2 chap * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
21 1.1.4.2 chap * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.1.4.2 chap * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.1.4.2 chap * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
24 1.1.4.2 chap * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 1.1.4.2 chap * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 1.1.4.2 chap * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 1.1.4.2 chap * ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.1.4.2 chap * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.1.4.2 chap * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.1.4.2 chap * POSSIBILITY OF SUCH DAMAGE.
31 1.1.4.2 chap */
32 1.1.4.2 chap
33 1.1.4.2 chap #include <sys/cdefs.h>
34 1.1.4.2 chap __KERNEL_RCSID(0, "$NetBSD: l2cap_upper.c,v 1.1.4.2 2006/06/22 03:39:50 chap Exp $");
35 1.1.4.2 chap
36 1.1.4.2 chap #include <sys/param.h>
37 1.1.4.2 chap #include <sys/kernel.h>
38 1.1.4.2 chap #include <sys/mbuf.h>
39 1.1.4.2 chap #include <sys/proc.h>
40 1.1.4.2 chap #include <sys/queue.h>
41 1.1.4.2 chap #include <sys/socket.h>
42 1.1.4.2 chap #include <sys/socketvar.h>
43 1.1.4.2 chap #include <sys/systm.h>
44 1.1.4.2 chap
45 1.1.4.2 chap #include <netbt/bluetooth.h>
46 1.1.4.2 chap #include <netbt/hci.h>
47 1.1.4.2 chap #include <netbt/l2cap.h>
48 1.1.4.2 chap
49 1.1.4.2 chap /*******************************************************************************
50 1.1.4.2 chap *
51 1.1.4.2 chap * L2CAP Channel - Upper Protocol API
52 1.1.4.2 chap */
53 1.1.4.2 chap
54 1.1.4.2 chap /*
55 1.1.4.2 chap * l2cap_attach(handle, btproto, upper)
56 1.1.4.2 chap *
57 1.1.4.2 chap * attach new l2cap_channel to handle, populate
58 1.1.4.2 chap * with with reasonable defaults
59 1.1.4.2 chap */
60 1.1.4.2 chap int
61 1.1.4.2 chap l2cap_attach(struct l2cap_channel **handle,
62 1.1.4.2 chap const struct btproto *proto, void *upper)
63 1.1.4.2 chap {
64 1.1.4.2 chap struct l2cap_channel *chan;
65 1.1.4.2 chap
66 1.1.4.2 chap KASSERT(handle);
67 1.1.4.2 chap KASSERT(proto);
68 1.1.4.2 chap KASSERT(upper);
69 1.1.4.2 chap
70 1.1.4.2 chap chan = malloc(sizeof(struct l2cap_channel), M_BLUETOOTH,
71 1.1.4.2 chap M_NOWAIT | M_ZERO);
72 1.1.4.2 chap if (chan == NULL)
73 1.1.4.2 chap return ENOMEM;
74 1.1.4.2 chap
75 1.1.4.2 chap chan->lc_proto = proto;
76 1.1.4.2 chap chan->lc_upper = upper;
77 1.1.4.2 chap
78 1.1.4.2 chap chan->lc_state = L2CAP_CLOSED;
79 1.1.4.2 chap
80 1.1.4.2 chap chan->lc_lcid = L2CAP_NULL_CID;
81 1.1.4.2 chap chan->lc_rcid = L2CAP_NULL_CID;
82 1.1.4.2 chap
83 1.1.4.2 chap chan->lc_laddr.bt_len = sizeof(struct sockaddr_bt);
84 1.1.4.2 chap chan->lc_laddr.bt_family = AF_BLUETOOTH;
85 1.1.4.2 chap chan->lc_laddr.bt_psm = L2CAP_PSM_ANY;
86 1.1.4.2 chap
87 1.1.4.2 chap chan->lc_raddr.bt_len = sizeof(struct sockaddr_bt);
88 1.1.4.2 chap chan->lc_raddr.bt_family = AF_BLUETOOTH;
89 1.1.4.2 chap chan->lc_raddr.bt_psm = L2CAP_PSM_ANY;
90 1.1.4.2 chap
91 1.1.4.2 chap chan->lc_imtu = L2CAP_MTU_DEFAULT;
92 1.1.4.2 chap chan->lc_omtu = L2CAP_MTU_DEFAULT;
93 1.1.4.2 chap chan->lc_flush = L2CAP_FLUSH_TIMO_DEFAULT;
94 1.1.4.2 chap
95 1.1.4.2 chap memcpy(&chan->lc_iqos, &l2cap_default_qos, sizeof(l2cap_qos_t));
96 1.1.4.2 chap memcpy(&chan->lc_oqos, &l2cap_default_qos, sizeof(l2cap_qos_t));
97 1.1.4.2 chap
98 1.1.4.2 chap MBUFQ_INIT(&chan->lc_txq);
99 1.1.4.2 chap
100 1.1.4.2 chap *handle = chan;
101 1.1.4.2 chap return 0;
102 1.1.4.2 chap }
103 1.1.4.2 chap
104 1.1.4.2 chap /*
105 1.1.4.2 chap * l2cap_bind(l2cap_channel, sockaddr)
106 1.1.4.2 chap *
107 1.1.4.2 chap * set local address of channel
108 1.1.4.2 chap */
109 1.1.4.2 chap int
110 1.1.4.2 chap l2cap_bind(struct l2cap_channel *chan, struct sockaddr_bt *addr)
111 1.1.4.2 chap {
112 1.1.4.2 chap
113 1.1.4.2 chap memcpy(&chan->lc_laddr, addr, sizeof(struct sockaddr_bt));
114 1.1.4.2 chap return 0;
115 1.1.4.2 chap }
116 1.1.4.2 chap
117 1.1.4.2 chap /*
118 1.1.4.2 chap * l2cap_sockaddr(l2cap_channel, sockaddr)
119 1.1.4.2 chap *
120 1.1.4.2 chap * get local address of channel
121 1.1.4.2 chap */
122 1.1.4.2 chap int
123 1.1.4.2 chap l2cap_sockaddr(struct l2cap_channel *chan, struct sockaddr_bt *addr)
124 1.1.4.2 chap {
125 1.1.4.2 chap
126 1.1.4.2 chap memcpy(addr, &chan->lc_laddr, sizeof(struct sockaddr_bt));
127 1.1.4.2 chap return 0;
128 1.1.4.2 chap }
129 1.1.4.2 chap
130 1.1.4.2 chap /*
131 1.1.4.2 chap * l2cap_connect(l2cap_channel, sockaddr)
132 1.1.4.2 chap *
133 1.1.4.2 chap * Initiate a connection to destination. This corresponds to
134 1.1.4.2 chap * "Open Channel Request" in the L2CAP specification and will
135 1.1.4.2 chap * result in one of the following:
136 1.1.4.2 chap *
137 1.1.4.2 chap * proto->connected(upper)
138 1.1.4.2 chap * proto->disconnected(upper, error)
139 1.1.4.2 chap *
140 1.1.4.2 chap * and, optionally
141 1.1.4.2 chap * proto->connecting(upper)
142 1.1.4.2 chap */
143 1.1.4.2 chap int
144 1.1.4.2 chap l2cap_connect(struct l2cap_channel *chan, struct sockaddr_bt *dest)
145 1.1.4.2 chap {
146 1.1.4.2 chap struct hci_unit *unit;
147 1.1.4.2 chap int err;
148 1.1.4.2 chap
149 1.1.4.2 chap memcpy(&chan->lc_raddr, dest, sizeof(struct sockaddr_bt));
150 1.1.4.2 chap
151 1.1.4.2 chap if (L2CAP_PSM_INVALID(chan->lc_raddr.bt_psm))
152 1.1.4.2 chap return EINVAL;
153 1.1.4.2 chap
154 1.1.4.2 chap if (bdaddr_any(&chan->lc_raddr.bt_bdaddr))
155 1.1.4.2 chap return EDESTADDRREQ;
156 1.1.4.2 chap
157 1.1.4.2 chap /* set local address if it needs setting */
158 1.1.4.2 chap if (bdaddr_any(&chan->lc_laddr.bt_bdaddr)) {
159 1.1.4.2 chap err = hci_route_lookup(&chan->lc_laddr.bt_bdaddr,
160 1.1.4.2 chap &chan->lc_raddr.bt_bdaddr);
161 1.1.4.2 chap if (err)
162 1.1.4.2 chap return err;
163 1.1.4.2 chap }
164 1.1.4.2 chap
165 1.1.4.2 chap unit = hci_unit_lookup(&chan->lc_laddr.bt_bdaddr);
166 1.1.4.2 chap if (unit == NULL)
167 1.1.4.2 chap return EHOSTUNREACH;
168 1.1.4.2 chap
169 1.1.4.2 chap /* attach to active list */
170 1.1.4.2 chap err = l2cap_cid_alloc(chan);
171 1.1.4.2 chap if (err)
172 1.1.4.2 chap return err;
173 1.1.4.2 chap
174 1.1.4.2 chap /* open link to remote device */
175 1.1.4.2 chap chan->lc_link = hci_acl_open(unit, &chan->lc_raddr.bt_bdaddr);
176 1.1.4.2 chap if (chan->lc_link == NULL)
177 1.1.4.2 chap return EHOSTUNREACH;
178 1.1.4.2 chap
179 1.1.4.2 chap /*
180 1.1.4.2 chap * We queue a connect request right away even though the link
181 1.1.4.2 chap * may not yet be open; the queue will be started automatically
182 1.1.4.2 chap * at the right time.
183 1.1.4.2 chap */
184 1.1.4.2 chap chan->lc_state = L2CAP_WAIT_CONNECT_RSP;
185 1.1.4.2 chap err = l2cap_send_connect_req(chan);
186 1.1.4.2 chap if (err) {
187 1.1.4.2 chap chan->lc_state = L2CAP_CLOSED;
188 1.1.4.2 chap hci_acl_close(chan->lc_link, err);
189 1.1.4.2 chap chan->lc_link = NULL;
190 1.1.4.2 chap return err;
191 1.1.4.2 chap }
192 1.1.4.2 chap
193 1.1.4.2 chap return 0;
194 1.1.4.2 chap }
195 1.1.4.2 chap
196 1.1.4.2 chap /*
197 1.1.4.2 chap * l2cap_peeraddr(l2cap_channel, sockaddr)
198 1.1.4.2 chap *
199 1.1.4.2 chap * get remote address of channel
200 1.1.4.2 chap */
201 1.1.4.2 chap int
202 1.1.4.2 chap l2cap_peeraddr(struct l2cap_channel *chan, struct sockaddr_bt *addr)
203 1.1.4.2 chap {
204 1.1.4.2 chap
205 1.1.4.2 chap memcpy(addr, &chan->lc_raddr, sizeof(struct sockaddr_bt));
206 1.1.4.2 chap return 0;
207 1.1.4.2 chap }
208 1.1.4.2 chap
209 1.1.4.2 chap /*
210 1.1.4.2 chap * l2cap_disconnect(l2cap_channel, linger)
211 1.1.4.2 chap *
212 1.1.4.2 chap * Initiate L2CAP disconnection. This corresponds to
213 1.1.4.2 chap * "Close Channel Request" in the L2CAP specification
214 1.1.4.2 chap * and will result in a call to
215 1.1.4.2 chap *
216 1.1.4.2 chap * proto->disconnected(upper, error)
217 1.1.4.2 chap *
218 1.1.4.2 chap * when the disconnection is complete. If linger is set,
219 1.1.4.2 chap * the call will not be made until data has flushed from
220 1.1.4.2 chap * the queue.
221 1.1.4.2 chap */
222 1.1.4.2 chap int
223 1.1.4.2 chap l2cap_disconnect(struct l2cap_channel *chan, int linger)
224 1.1.4.2 chap {
225 1.1.4.2 chap int err = 0;
226 1.1.4.2 chap
227 1.1.4.2 chap if (chan->lc_state & (L2CAP_CLOSED | L2CAP_WAIT_DISCONNECT))
228 1.1.4.2 chap return EINVAL;
229 1.1.4.2 chap
230 1.1.4.2 chap chan->lc_flags |= L2CAP_SHUTDOWN;
231 1.1.4.2 chap
232 1.1.4.2 chap /*
233 1.1.4.2 chap * no need to do anything unless the queue is empty or
234 1.1.4.2 chap * we are not lingering..
235 1.1.4.2 chap */
236 1.1.4.2 chap if ((MBUFQ_FIRST(&chan->lc_txq) == NULL && chan->lc_pending == 0)
237 1.1.4.2 chap || linger == 0) {
238 1.1.4.2 chap chan->lc_state = L2CAP_WAIT_DISCONNECT;
239 1.1.4.2 chap err = l2cap_send_disconnect_req(chan);
240 1.1.4.2 chap if (err)
241 1.1.4.2 chap l2cap_close(chan, err);
242 1.1.4.2 chap }
243 1.1.4.2 chap return err;
244 1.1.4.2 chap }
245 1.1.4.2 chap
246 1.1.4.2 chap /*
247 1.1.4.2 chap * l2cap_detach(handle)
248 1.1.4.2 chap *
249 1.1.4.2 chap * Detach l2cap channel from handle & close it down
250 1.1.4.2 chap */
251 1.1.4.2 chap int
252 1.1.4.2 chap l2cap_detach(struct l2cap_channel **handle)
253 1.1.4.2 chap {
254 1.1.4.2 chap struct l2cap_channel *chan;
255 1.1.4.2 chap
256 1.1.4.2 chap chan = *handle;
257 1.1.4.2 chap *handle = NULL;
258 1.1.4.2 chap
259 1.1.4.2 chap if (chan->lc_state != L2CAP_CLOSED)
260 1.1.4.2 chap l2cap_close(chan, 0);
261 1.1.4.2 chap
262 1.1.4.2 chap if (chan->lc_lcid != L2CAP_NULL_CID) {
263 1.1.4.2 chap LIST_REMOVE(chan, lc_ncid);
264 1.1.4.2 chap chan->lc_lcid = L2CAP_NULL_CID;
265 1.1.4.2 chap }
266 1.1.4.2 chap
267 1.1.4.2 chap MBUFQ_DRAIN(&chan->lc_txq);
268 1.1.4.2 chap
269 1.1.4.2 chap /*
270 1.1.4.2 chap * Could implement some kind of delayed expunge to make sure that the
271 1.1.4.2 chap * CID is really dead before it becomes available for reuse?
272 1.1.4.2 chap */
273 1.1.4.2 chap
274 1.1.4.2 chap free(chan, M_BLUETOOTH);
275 1.1.4.2 chap return 0;
276 1.1.4.2 chap }
277 1.1.4.2 chap
278 1.1.4.2 chap /*
279 1.1.4.2 chap * l2cap_listen(l2cap_channel)
280 1.1.4.2 chap *
281 1.1.4.2 chap * Use this channel as a listening post (until detached). This will
282 1.1.4.2 chap * result in calls to:
283 1.1.4.2 chap *
284 1.1.4.2 chap * proto->newconn(upper, laddr, raddr)
285 1.1.4.2 chap *
286 1.1.4.2 chap * for incoming connections matching the psm and local address of the
287 1.1.4.2 chap * channel (NULL psm/address are permitted and match any protocol/device).
288 1.1.4.2 chap *
289 1.1.4.2 chap * The upper layer should create and return a new channel.
290 1.1.4.2 chap *
291 1.1.4.2 chap * You cannot use this channel for anything else subsequent to this call
292 1.1.4.2 chap */
293 1.1.4.2 chap int
294 1.1.4.2 chap l2cap_listen(struct l2cap_channel *chan)
295 1.1.4.2 chap {
296 1.1.4.2 chap struct l2cap_channel *used, *prev = NULL;
297 1.1.4.2 chap
298 1.1.4.2 chap if (chan->lc_lcid != L2CAP_NULL_CID)
299 1.1.4.2 chap return EINVAL;
300 1.1.4.2 chap
301 1.1.4.2 chap if (chan->lc_laddr.bt_psm != L2CAP_PSM_ANY
302 1.1.4.2 chap && L2CAP_PSM_INVALID(chan->lc_laddr.bt_psm))
303 1.1.4.2 chap return EADDRNOTAVAIL;
304 1.1.4.2 chap
305 1.1.4.2 chap /*
306 1.1.4.2 chap * This CID is irrelevant, as the channel is not stored on the active
307 1.1.4.2 chap * list and the socket code does not allow operations on listening
308 1.1.4.2 chap * sockets, but we set it so the detach code knows to LIST_REMOVE the
309 1.1.4.2 chap * channel.
310 1.1.4.2 chap */
311 1.1.4.2 chap chan->lc_lcid = L2CAP_SIGNAL_CID;
312 1.1.4.2 chap
313 1.1.4.2 chap /*
314 1.1.4.2 chap * The list of listening channels is stored in an order such that new
315 1.1.4.2 chap * listeners dont usurp current listeners, but that specific listening
316 1.1.4.2 chap * takes precedence over promiscuous, and the connect request code can
317 1.1.4.2 chap * easily use the first matching entry.
318 1.1.4.2 chap */
319 1.1.4.2 chap LIST_FOREACH(used, &l2cap_listen_list, lc_ncid) {
320 1.1.4.2 chap if (used->lc_laddr.bt_psm < chan->lc_laddr.bt_psm)
321 1.1.4.2 chap break;
322 1.1.4.2 chap
323 1.1.4.2 chap if (used->lc_laddr.bt_psm == chan->lc_laddr.bt_psm
324 1.1.4.2 chap && bdaddr_any(&used->lc_laddr.bt_bdaddr)
325 1.1.4.2 chap && !bdaddr_any(&chan->lc_laddr.bt_bdaddr))
326 1.1.4.2 chap break;
327 1.1.4.2 chap
328 1.1.4.2 chap prev = used;
329 1.1.4.2 chap }
330 1.1.4.2 chap
331 1.1.4.2 chap if (prev == NULL)
332 1.1.4.2 chap LIST_INSERT_HEAD(&l2cap_listen_list, chan, lc_ncid);
333 1.1.4.2 chap else
334 1.1.4.2 chap LIST_INSERT_AFTER(prev, chan, lc_ncid);
335 1.1.4.2 chap
336 1.1.4.2 chap return 0;
337 1.1.4.2 chap }
338 1.1.4.2 chap
339 1.1.4.2 chap /*
340 1.1.4.2 chap * l2cap_send(l2cap_channel, mbuf)
341 1.1.4.2 chap *
342 1.1.4.2 chap * Output SDU on channel described by channel. This corresponds
343 1.1.4.2 chap * to "Send Data Request" in the L2CAP specification. The upper
344 1.1.4.2 chap * layer will be notified when SDU's have completed sending by a
345 1.1.4.2 chap * call to:
346 1.1.4.2 chap *
347 1.1.4.2 chap * proto->complete(upper, n)
348 1.1.4.2 chap *
349 1.1.4.2 chap * (currently n == 1)
350 1.1.4.2 chap *
351 1.1.4.2 chap * Note: I'm not sure how this will work out, but I think that
352 1.1.4.2 chap * if outgoing Retransmission Mode or Flow Control Mode is
353 1.1.4.2 chap * negotiated then this call will not be made until the SDU has
354 1.1.4.2 chap * been acknowleged by the peer L2CAP entity. For 'Best Effort'
355 1.1.4.2 chap * it will be made when the packet has cleared the controller
356 1.1.4.2 chap * buffers.
357 1.1.4.2 chap *
358 1.1.4.2 chap * We only support Basic mode so far, so encapsulate with a
359 1.1.4.2 chap * B-Frame header and start sending if we are not already
360 1.1.4.2 chap */
361 1.1.4.2 chap int
362 1.1.4.2 chap l2cap_send(struct l2cap_channel *chan, struct mbuf *m)
363 1.1.4.2 chap {
364 1.1.4.2 chap l2cap_hdr_t *hdr;
365 1.1.4.2 chap int plen;
366 1.1.4.2 chap
367 1.1.4.2 chap if (chan->lc_state == L2CAP_CLOSED) {
368 1.1.4.2 chap m_freem(m);
369 1.1.4.2 chap return ENOTCONN;
370 1.1.4.2 chap }
371 1.1.4.2 chap
372 1.1.4.2 chap plen = m->m_pkthdr.len;
373 1.1.4.2 chap
374 1.1.4.2 chap DPRINTFN(5, "send %d bytes on CID #%d (pending = %d)\n",
375 1.1.4.2 chap plen, chan->lc_lcid, chan->lc_pending);
376 1.1.4.2 chap
377 1.1.4.2 chap /* Encapsulate with B-Frame */
378 1.1.4.2 chap M_PREPEND(m, sizeof(l2cap_hdr_t), M_DONTWAIT);
379 1.1.4.2 chap if (m == NULL)
380 1.1.4.2 chap return ENOMEM;
381 1.1.4.2 chap
382 1.1.4.2 chap hdr = mtod(m, l2cap_hdr_t *);
383 1.1.4.2 chap hdr->length = htole16(plen);
384 1.1.4.2 chap hdr->dcid = htole16(chan->lc_rcid);
385 1.1.4.2 chap
386 1.1.4.2 chap /* Queue it on our list */
387 1.1.4.2 chap MBUFQ_ENQUEUE(&chan->lc_txq, m);
388 1.1.4.2 chap
389 1.1.4.2 chap /* If we are not sending, then start doing so */
390 1.1.4.2 chap if (chan->lc_pending == 0)
391 1.1.4.2 chap return l2cap_start(chan);
392 1.1.4.2 chap
393 1.1.4.2 chap return 0;
394 1.1.4.2 chap }
395 1.1.4.2 chap
396 1.1.4.2 chap /*
397 1.1.4.2 chap * l2cap_setopt(channel, opt, addr)
398 1.1.4.2 chap *
399 1.1.4.2 chap * Apply configuration options to channel. This corresponds to
400 1.1.4.2 chap * "Configure Channel Request" in the L2CAP specification.
401 1.1.4.2 chap */
402 1.1.4.2 chap int
403 1.1.4.2 chap l2cap_setopt(struct l2cap_channel *chan, int opt, void *addr)
404 1.1.4.2 chap {
405 1.1.4.2 chap int err = 0;
406 1.1.4.2 chap uint16_t tmp;
407 1.1.4.2 chap
408 1.1.4.2 chap /*
409 1.1.4.2 chap * currently we dont allow changing any options when channel
410 1.1.4.2 chap * is other than closed. We could allow this (not sure why?)
411 1.1.4.2 chap * but would have to instigate a configure request.
412 1.1.4.2 chap */
413 1.1.4.2 chap if (chan->lc_state != L2CAP_CLOSED)
414 1.1.4.2 chap return EBUSY;
415 1.1.4.2 chap
416 1.1.4.2 chap switch (opt) {
417 1.1.4.2 chap case SO_L2CAP_IMTU: /* set Incoming MTU */
418 1.1.4.2 chap tmp = *(uint16_t *)addr;
419 1.1.4.2 chap if (tmp < L2CAP_MTU_MINIMUM) {
420 1.1.4.2 chap err = EINVAL;
421 1.1.4.2 chap break;
422 1.1.4.2 chap }
423 1.1.4.2 chap
424 1.1.4.2 chap chan->lc_imtu = tmp;
425 1.1.4.2 chap break;
426 1.1.4.2 chap
427 1.1.4.2 chap case SO_L2CAP_OQOS: /* set Outgoing QoS flow spec */
428 1.1.4.2 chap // XXX
429 1.1.4.2 chap // memcpy(&chan->lc_oqos, addr, sizeof(l2cap_qos_t));
430 1.1.4.2 chap //break;
431 1.1.4.2 chap
432 1.1.4.2 chap case SO_L2CAP_FLUSH: /* set Outgoing Flush Timeout */
433 1.1.4.2 chap // XXX
434 1.1.4.2 chap // chan->lc_flush = *(uint16_t *)addr;
435 1.1.4.2 chap //break;
436 1.1.4.2 chap
437 1.1.4.2 chap default:
438 1.1.4.2 chap err = EINVAL;
439 1.1.4.2 chap break;
440 1.1.4.2 chap }
441 1.1.4.2 chap
442 1.1.4.2 chap return err;
443 1.1.4.2 chap }
444 1.1.4.2 chap
445 1.1.4.2 chap int
446 1.1.4.2 chap l2cap_getopt(struct l2cap_channel *chan, int opt, void *addr)
447 1.1.4.2 chap {
448 1.1.4.2 chap
449 1.1.4.2 chap switch (opt) {
450 1.1.4.2 chap case SO_L2CAP_IMTU: /* get Incoming MTU */
451 1.1.4.2 chap *(uint16_t *)addr = chan->lc_imtu;
452 1.1.4.2 chap return sizeof(uint16_t);
453 1.1.4.2 chap
454 1.1.4.2 chap case SO_L2CAP_OMTU: /* get Outgoing MTU */
455 1.1.4.2 chap *(uint16_t *)addr = chan->lc_omtu;
456 1.1.4.2 chap return sizeof(uint16_t);
457 1.1.4.2 chap
458 1.1.4.2 chap case SO_L2CAP_IQOS: /* get Incoming QoS flow spec */
459 1.1.4.2 chap memcpy(addr, &chan->lc_iqos, sizeof(l2cap_qos_t));
460 1.1.4.2 chap return sizeof(l2cap_qos_t);
461 1.1.4.2 chap
462 1.1.4.2 chap case SO_L2CAP_OQOS: /* get Outgoing QoS flow spec */
463 1.1.4.2 chap memcpy(addr, &chan->lc_oqos, sizeof(l2cap_qos_t));
464 1.1.4.2 chap return sizeof(l2cap_qos_t);
465 1.1.4.2 chap
466 1.1.4.2 chap case SO_L2CAP_FLUSH: /* get Flush Timeout */
467 1.1.4.2 chap *(uint16_t *)addr = chan->lc_flush;
468 1.1.4.2 chap return sizeof(uint16_t);
469 1.1.4.2 chap
470 1.1.4.2 chap default:
471 1.1.4.2 chap break;
472 1.1.4.2 chap }
473 1.1.4.2 chap
474 1.1.4.2 chap return 0;
475 1.1.4.2 chap }
476