View | Details | Raw Unified | Return to bug 10721
Collapse All | Expand All

(-)linux-2.6.18-mh7/include/net/bluetooth/hci_core.h (-7 / +26 lines)
Lines 25-30 Link Here
25
#ifndef __HCI_CORE_H
25
#ifndef __HCI_CORE_H
26
#define __HCI_CORE_H
26
#define __HCI_CORE_H
27
27
28
#include <linux/hrtimer.h>
29
28
#include <net/bluetooth/hci.h>
30
#include <net/bluetooth/hci.h>
29
31
30
/* HCI upper protocols */
32
/* HCI upper protocols */
Lines 88-99 Link Here
88
	unsigned long	quirks;
90
	unsigned long	quirks;
89
91
90
	atomic_t	cmd_cnt;
92
	atomic_t	cmd_cnt;
93
	/* Number of available controller buffers for ACL packets */
91
	unsigned int	acl_cnt;
94
	unsigned int	acl_cnt;
92
	unsigned int	sco_cnt;
95
	/* Number of available controller buffers for SCO packets */
96
	atomic_t	sco_cnt;
93
97
98
	/* Maximum transmition unit for ACL packets */
94
	unsigned int	acl_mtu;
99
	unsigned int	acl_mtu;
100
	/* Maximum transmition unit for SCO packets */
95
	unsigned int	sco_mtu;
101
	unsigned int	sco_mtu;
102
	/* Maximum number of ACL packets the controller is able to buffer */
96
	unsigned int	acl_pkts;
103
	unsigned int	acl_pkts;
104
	/* Maximum number of SCO packets the controller is able to buffer */
97
	unsigned int	sco_pkts;
105
	unsigned int	sco_pkts;
98
106
99
	unsigned long	cmd_last_tx;
107
	unsigned long	cmd_last_tx;
Lines 145-151 Link Here
145
	struct list_head list;
153
	struct list_head list;
146
154
147
	atomic_t	 refcnt;
155
	atomic_t	 refcnt;
148
	spinlock_t	 lock;
149
156
150
	bdaddr_t	 dst;
157
	bdaddr_t	 dst;
151
	__u16		 handle;
158
	__u16		 handle;
Lines 162-171 Link Here
162
	__u8             power_save;
169
	__u8             power_save;
163
	unsigned long	 pend;
170
	unsigned long	 pend;
164
171
165
	unsigned int	 sent;
172
	/* sent represents the number of packets this connections
166
173
           has "on the wire" : .... oh f.... there are no wire
167
	struct sk_buff_head data_q;
174
           with bluetooth. By on the wire, i mean packets that have been sent
168
175
	   to the HCI device, and that are still in its buffers */
176
	atomic_t	 sent;
177
178
	struct sk_buff_head out_q;
179
	/* This is only used for SCO for now */
180
	void (*pkt_sent_cb)(struct hci_conn *conn);
181
182
	/* tx timer : used only for SCO */
183
	struct hrtimer tx_timer;
184
	/* Disconnect timer */
169
	struct timer_list disc_timer;
185
	struct timer_list disc_timer;
170
	struct timer_list idle_timer;
186
	struct timer_list idle_timer;
171
187
Lines 614-620 Link Here
614
630
615
int hci_send_cmd(struct hci_dev *hdev, __u16 ogf, __u16 ocf, __u32 plen, void *param);
631
int hci_send_cmd(struct hci_dev *hdev, __u16 ogf, __u16 ocf, __u32 plen, void *param);
616
int hci_send_acl(struct hci_conn *conn, struct sk_buff *skb, __u16 flags);
632
int hci_send_acl(struct hci_conn *conn, struct sk_buff *skb, __u16 flags);
617
int hci_send_sco(struct hci_conn *conn, struct sk_buff *skb);
633
int hci_send_sco(struct hci_conn *conn, 
634
			struct sk_buff *skb, 
635
			int sndbufsize, 
636
			void (*send_complete_cb)(struct hci_conn *conn));
618
637
619
void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 ogf, __u16 ocf);
638
void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 ogf, __u16 ocf);
620
639
(-)linux-2.6.18-mh7/include/net/bluetooth/hci_core.h~ (+661 lines)
Line 0 Link Here
1
/* 
2
   BlueZ - Bluetooth protocol stack for Linux
3
   Copyright (C) 2000-2001 Qualcomm Incorporated
4
5
   Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
6
7
   This program is free software; you can redistribute it and/or modify
8
   it under the terms of the GNU General Public License version 2 as
9
   published by the Free Software Foundation;
10
11
   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
12
   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13
   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
14
   IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
15
   CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES 
16
   WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 
17
   ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 
18
   OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19
20
   ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS, 
21
   COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS 
22
   SOFTWARE IS DISCLAIMED.
23
*/
24
25
#ifndef __HCI_CORE_H
26
#define __HCI_CORE_H
27
28
#include <linux/hrtimer.h>
29
30
#include <net/bluetooth/hci.h>
31
32
/* HCI upper protocols */
33
#define HCI_PROTO_L2CAP	0
34
#define HCI_PROTO_SCO	1
35
36
/* HCI Core structures */
37
struct inquiry_data {
38
	bdaddr_t	bdaddr;
39
	__u8		pscan_rep_mode;
40
	__u8		pscan_period_mode;
41
	__u8		pscan_mode;
42
	__u8		dev_class[3];
43
	__le16		clock_offset;
44
	__s8		rssi;
45
};
46
47
struct inquiry_entry {
48
	struct inquiry_entry 	*next;
49
	__u32			timestamp;
50
	struct inquiry_data	data;
51
};
52
53
struct inquiry_cache {
54
	spinlock_t 		lock;
55
	__u32			timestamp;
56
	struct inquiry_entry 	*list;
57
};
58
59
struct hci_conn_hash {
60
	struct list_head list;
61
	spinlock_t       lock;
62
	unsigned int     acl_num;
63
	unsigned int     sco_num;
64
};
65
66
struct hci_dev {
67
	struct list_head list;
68
	spinlock_t	lock;
69
	atomic_t	refcnt;
70
71
	char		name[8];
72
	unsigned long	flags;
73
	__u16		id;
74
	__u8		type;
75
	bdaddr_t	bdaddr;
76
	__u8		features[8];
77
	__u8		hci_ver;
78
	__u16		hci_rev;
79
	__u16		manufacturer;
80
	__u16		voice_setting;
81
82
	__u16		pkt_type;
83
	__u16		link_policy;
84
	__u16		link_mode;
85
86
	__u32		idle_timeout;
87
	__u16		sniff_min_interval;
88
	__u16		sniff_max_interval;
89
90
	unsigned long	quirks;
91
92
	atomic_t	cmd_cnt;
93
	/* Number of available controller buffers for ACL packets */
94
	unsigned int	acl_cnt;
95
	/* Number of available controller buffers for SCO packets */
96
	atomic_t	sco_cnt;
97
98
	/* Maximum transmition unit for ACL packets */
99
	unsigned int	acl_mtu;
100
	/* Maximum transmition unit for SCO packets */
101
	unsigned int	sco_mtu;
102
	/* Maximum number of ACL packets the controller is able to buffer */
103
	unsigned int	acl_pkts;
104
	/* Maximum number of SCO packets the controller is able to buffer */
105
	unsigned int	sco_pkts;
106
107
	unsigned long	cmd_last_tx;
108
	unsigned long	acl_last_tx;
109
	unsigned long	sco_last_tx;
110
111
	struct tasklet_struct	cmd_task;
112
	struct tasklet_struct	rx_task;
113
	struct tasklet_struct	tx_task;
114
115
	struct sk_buff_head	rx_q;
116
	struct sk_buff_head	raw_q;
117
	struct sk_buff_head	cmd_q;
118
119
	struct sk_buff		*sent_cmd;
120
121
	struct semaphore	req_lock;
122
	wait_queue_head_t	req_wait_q;
123
	__u32			req_status;
124
	__u32			req_result;
125
126
	struct inquiry_cache	inq_cache;
127
	struct hci_conn_hash	conn_hash;
128
129
	struct hci_dev_stats	stat;
130
131
	struct sk_buff_head	driver_init;
132
133
	void			*driver_data;
134
	void			*core_data;
135
136
	atomic_t 		promisc;
137
138
	struct device		*parent;
139
	struct device		dev;
140
141
	struct module 		*owner;
142
143
	int (*open)(struct hci_dev *hdev);
144
	int (*close)(struct hci_dev *hdev);
145
	int (*flush)(struct hci_dev *hdev);
146
	int (*send)(struct sk_buff *skb);
147
	void (*destruct)(struct hci_dev *hdev);
148
	void (*notify)(struct hci_dev *hdev, unsigned int evt);
149
	int (*ioctl)(struct hci_dev *hdev, unsigned int cmd, unsigned long arg);
150
};
151
152
struct hci_conn {
153
	struct list_head list;
154
155
	atomic_t	 refcnt;
156
157
	bdaddr_t	 dst;
158
	__u16		 handle;
159
	__u16		 state;
160
	__u8             mode;
161
	__u8		 type;
162
	__u8		 out;
163
	__u8		 attempt;
164
	__u8		 dev_class[3];
165
	__u8             features[8];
166
	__u16            interval;
167
	__u16            link_policy;
168
	__u32		 link_mode;
169
	__u8             power_save;
170
	unsigned long	 pend;
171
172
	struct timer_list disc_timer;
173
	struct timer_list idle_timer;
174
175
	struct work_struct work;
176
177
	struct device	dev;
178
179
	struct hci_dev	*hdev;
180
	void		*l2cap_data;
181
	void		*sco_data;
182
	void		*priv;
183
184
	struct hci_conn	*link;
185
};
186
187
extern struct hci_proto *hci_proto[];
188
extern struct list_head hci_dev_list;
189
extern struct list_head hci_cb_list;
190
extern rwlock_t hci_dev_list_lock;
191
extern rwlock_t hci_cb_list_lock;
192
193
/* ----- Inquiry cache ----- */
194
#define INQUIRY_CACHE_AGE_MAX   (HZ*30)   // 30 seconds
195
#define INQUIRY_ENTRY_AGE_MAX   (HZ*60)   // 60 seconds
196
197
#define inquiry_cache_lock(c)		spin_lock(&c->lock)
198
#define inquiry_cache_unlock(c)		spin_unlock(&c->lock)
199
#define inquiry_cache_lock_bh(c)	spin_lock_bh(&c->lock)
200
#define inquiry_cache_unlock_bh(c)	spin_unlock_bh(&c->lock)
201
202
static inline void inquiry_cache_init(struct hci_dev *hdev)
203
{
204
	struct inquiry_cache *c = &hdev->inq_cache;
205
	spin_lock_init(&c->lock);
206
	c->list = NULL;
207
}
208
209
static inline int inquiry_cache_empty(struct hci_dev *hdev)
210
{
211
	struct inquiry_cache *c = &hdev->inq_cache;
212
	return (c->list == NULL);
213
}
214
215
static inline long inquiry_cache_age(struct hci_dev *hdev)
216
{
217
	struct inquiry_cache *c = &hdev->inq_cache;
218
	return jiffies - c->timestamp;
219
}
220
221
static inline long inquiry_entry_age(struct inquiry_entry *e)
222
{
223
	return jiffies - e->timestamp;
224
}
225
226
struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, bdaddr_t *bdaddr);
227
void hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data);
228
229
/* ----- HCI Connections ----- */
230
enum {
231
	HCI_CONN_AUTH_PEND,
232
	HCI_CONN_ENCRYPT_PEND,
233
	HCI_CONN_RSWITCH_PEND,
234
	HCI_CONN_MODE_CHANGE_PEND,
235
};
236
237
static inline void hci_conn_hash_init(struct hci_dev *hdev)
238
{
239
	struct hci_conn_hash *h = &hdev->conn_hash;
240
	INIT_LIST_HEAD(&h->list);
241
	spin_lock_init(&h->lock);
242
	h->acl_num = 0;
243
	h->sco_num = 0;
244
}
245
246
static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c)
247
{
248
	struct hci_conn_hash *h = &hdev->conn_hash;
249
	list_add(&c->list, &h->list);
250
	if (c->type == ACL_LINK)
251
		h->acl_num++;
252
	else
253
		h->sco_num++;
254
}
255
256
static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c)
257
{
258
	struct hci_conn_hash *h = &hdev->conn_hash;
259
	list_del(&c->list);
260
	if (c->type == ACL_LINK)
261
		h->acl_num--;
262
	else
263
		h->sco_num--;
264
}
265
266
static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev,
267
					__u16 handle)
268
{
269
	struct hci_conn_hash *h = &hdev->conn_hash;
270
	struct list_head *p;
271
	struct hci_conn  *c;
272
273
	list_for_each(p, &h->list) {
274
		c = list_entry(p, struct hci_conn, list);
275
		if (c->handle == handle)
276
			return c;
277
	}
278
	return NULL;
279
}
280
281
static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev,
282
					__u8 type, bdaddr_t *ba)
283
{
284
	struct hci_conn_hash *h = &hdev->conn_hash;
285
	struct list_head *p;
286
	struct hci_conn  *c;
287
288
	list_for_each(p, &h->list) {
289
		c = list_entry(p, struct hci_conn, list);
290
		if (c->type == type && !bacmp(&c->dst, ba))
291
			return c;
292
	}
293
	return NULL;
294
}
295
296
static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev,
297
					__u8 type, __u16 state)
298
{
299
	struct hci_conn_hash *h = &hdev->conn_hash;
300
	struct list_head *p;
301
	struct hci_conn  *c;
302
303
	list_for_each(p, &h->list) {
304
		c = list_entry(p, struct hci_conn, list);
305
		if (c->type == type && c->state == state)
306
			return c;
307
	}
308
	return NULL;
309
}
310
311
void hci_acl_connect(struct hci_conn *conn);
312
void hci_acl_disconn(struct hci_conn *conn, __u8 reason);
313
void hci_add_sco(struct hci_conn *conn, __u16 handle);
314
315
struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst);
316
int    hci_conn_del(struct hci_conn *conn);
317
void   hci_conn_hash_flush(struct hci_dev *hdev);
318
319
struct hci_conn *hci_connect(struct hci_dev *hdev, int type, bdaddr_t *src);
320
int hci_conn_auth(struct hci_conn *conn);
321
int hci_conn_encrypt(struct hci_conn *conn);
322
int hci_conn_change_link_key(struct hci_conn *conn);
323
int hci_conn_switch_role(struct hci_conn *conn, uint8_t role);
324
325
void hci_conn_enter_active_mode(struct hci_conn *conn);
326
void hci_conn_enter_sniff_mode(struct hci_conn *conn);
327
328
static inline void hci_conn_hold(struct hci_conn *conn)
329
{
330
	atomic_inc(&conn->refcnt);
331
	del_timer(&conn->disc_timer);
332
}
333
334
static inline void hci_conn_put(struct hci_conn *conn)
335
{
336
	if (atomic_dec_and_test(&conn->refcnt)) {
337
		unsigned long timeo;
338
		if (conn->type == ACL_LINK) {
339
			del_timer(&conn->idle_timer);
340
			if (conn->state == BT_CONNECTED) {
341
				timeo = msecs_to_jiffies(HCI_DISCONN_TIMEOUT);
342
				if (!conn->out)
343
					timeo *= 2;
344
			} else
345
				timeo = msecs_to_jiffies(10);
346
		} else
347
			timeo = msecs_to_jiffies(10);
348
		mod_timer(&conn->disc_timer, jiffies + timeo);
349
	}
350
}
351
352
/* ----- HCI tasks ----- */
353
static inline void hci_sched_cmd(struct hci_dev *hdev)
354
{
355
	tasklet_schedule(&hdev->cmd_task);
356
}
357
358
static inline void hci_sched_rx(struct hci_dev *hdev)
359
{
360
	tasklet_schedule(&hdev->rx_task);
361
}
362
363
static inline void hci_sched_tx(struct hci_dev *hdev)
364
{
365
	tasklet_schedule(&hdev->tx_task);
366
}
367
368
/* ----- HCI Devices ----- */
369
static inline void __hci_dev_put(struct hci_dev *d)
370
{
371
	if (atomic_dec_and_test(&d->refcnt))
372
		d->destruct(d);
373
}
374
375
static inline void hci_dev_put(struct hci_dev *d)
376
{ 
377
	__hci_dev_put(d);
378
	module_put(d->owner);
379
}
380
381
static inline struct hci_dev *__hci_dev_hold(struct hci_dev *d)
382
{
383
	atomic_inc(&d->refcnt);
384
	return d;
385
}
386
387
static inline struct hci_dev *hci_dev_hold(struct hci_dev *d)
388
{
389
	if (try_module_get(d->owner))
390
		return __hci_dev_hold(d);
391
	return NULL;
392
}
393
394
#define hci_dev_lock(d)		spin_lock(&d->lock)
395
#define hci_dev_unlock(d)	spin_unlock(&d->lock)
396
#define hci_dev_lock_bh(d)	spin_lock_bh(&d->lock)
397
#define hci_dev_unlock_bh(d)	spin_unlock_bh(&d->lock)
398
399
struct hci_dev *hci_dev_get(int index);
400
struct hci_dev *hci_get_route(bdaddr_t *src, bdaddr_t *dst);
401
402
struct hci_dev *hci_alloc_dev(void);
403
void hci_free_dev(struct hci_dev *hdev);
404
int hci_register_dev(struct hci_dev *hdev);
405
int hci_unregister_dev(struct hci_dev *hdev);
406
int hci_suspend_dev(struct hci_dev *hdev);
407
int hci_resume_dev(struct hci_dev *hdev);
408
int hci_dev_open(__u16 dev);
409
int hci_dev_close(__u16 dev);
410
int hci_dev_reset(__u16 dev);
411
int hci_dev_reset_stat(__u16 dev);
412
int hci_dev_cmd(unsigned int cmd, void __user *arg);
413
int hci_get_dev_list(void __user *arg);
414
int hci_get_dev_info(void __user *arg);
415
int hci_get_conn_list(void __user *arg);
416
int hci_get_conn_info(struct hci_dev *hdev, void __user *arg);
417
int hci_inquiry(void __user *arg);
418
419
void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb);
420
421
/* Receive frame from HCI drivers */
422
static inline int hci_recv_frame(struct sk_buff *skb)
423
{
424
	struct hci_dev *hdev = (struct hci_dev *) skb->dev;
425
	if (!hdev || (!test_bit(HCI_UP, &hdev->flags) 
426
			&& !test_bit(HCI_INIT, &hdev->flags))) {
427
		kfree_skb(skb);
428
		return -ENXIO;
429
	}
430
431
	/* Incomming skb */
432
	bt_cb(skb)->incoming = 1;
433
434
	/* Time stamp */
435
	__net_timestamp(skb);
436
437
	/* Queue frame for rx task */
438
	skb_queue_tail(&hdev->rx_q, skb);
439
	hci_sched_rx(hdev);
440
	return 0;
441
}
442
443
int hci_register_sysfs(struct hci_dev *hdev);
444
void hci_unregister_sysfs(struct hci_dev *hdev);
445
void hci_conn_add_sysfs(struct hci_conn *conn);
446
void hci_conn_del_sysfs(struct hci_conn *conn);
447
448
#define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->parent = (pdev))
449
450
/* ----- LMP capabilities ----- */
451
#define lmp_rswitch_capable(dev)   ((dev)->features[0] & LMP_RSWITCH)
452
#define lmp_encrypt_capable(dev)   ((dev)->features[0] & LMP_ENCRYPT)
453
#define lmp_sniff_capable(dev)     ((dev)->features[0] & LMP_SNIFF)
454
#define lmp_sniffsubr_capable(dev) ((dev)->features[5] & LMP_SNIFF_SUBR)
455
456
/* ----- HCI protocols ----- */
457
struct hci_proto {
458
	char 		*name;
459
	unsigned int	id;
460
	unsigned long	flags;
461
462
	void		*priv;
463
464
	int (*connect_ind) 	(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 type);
465
	int (*connect_cfm)	(struct hci_conn *conn, __u8 status);
466
	int (*disconn_ind)	(struct hci_conn *conn, __u8 reason);
467
	int (*recv_acldata)	(struct hci_conn *conn, struct sk_buff *skb, __u16 flags);
468
	int (*recv_scodata)	(struct hci_conn *conn, struct sk_buff *skb);
469
	int (*auth_cfm)		(struct hci_conn *conn, __u8 status);
470
	int (*encrypt_cfm)	(struct hci_conn *conn, __u8 status);
471
};
472
473
static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 type)
474
{
475
	register struct hci_proto *hp;
476
	int mask = 0;
477
	
478
	hp = hci_proto[HCI_PROTO_L2CAP];
479
	if (hp && hp->connect_ind)
480
		mask |= hp->connect_ind(hdev, bdaddr, type);
481
482
	hp = hci_proto[HCI_PROTO_SCO];
483
	if (hp && hp->connect_ind)
484
		mask |= hp->connect_ind(hdev, bdaddr, type);
485
486
	return mask;
487
}
488
489
static inline void hci_proto_connect_cfm(struct hci_conn *conn, __u8 status)
490
{
491
	register struct hci_proto *hp;
492
493
	hp = hci_proto[HCI_PROTO_L2CAP];
494
	if (hp && hp->connect_cfm)
495
		hp->connect_cfm(conn, status);
496
497
	hp = hci_proto[HCI_PROTO_SCO];
498
	if (hp && hp->connect_cfm)
499
		hp->connect_cfm(conn, status);
500
}
501
502
static inline void hci_proto_disconn_ind(struct hci_conn *conn, __u8 reason)
503
{
504
	register struct hci_proto *hp;
505
506
	hp = hci_proto[HCI_PROTO_L2CAP];
507
	if (hp && hp->disconn_ind)
508
		hp->disconn_ind(conn, reason);
509
510
	hp = hci_proto[HCI_PROTO_SCO];
511
	if (hp && hp->disconn_ind)
512
		hp->disconn_ind(conn, reason);
513
}
514
515
static inline void hci_proto_auth_cfm(struct hci_conn *conn, __u8 status)
516
{
517
	register struct hci_proto *hp;
518
519
	hp = hci_proto[HCI_PROTO_L2CAP];
520
	if (hp && hp->auth_cfm)
521
		hp->auth_cfm(conn, status);
522
523
	hp = hci_proto[HCI_PROTO_SCO];
524
	if (hp && hp->auth_cfm)
525
		hp->auth_cfm(conn, status);
526
}
527
528
static inline void hci_proto_encrypt_cfm(struct hci_conn *conn, __u8 status)
529
{
530
	register struct hci_proto *hp;
531
532
	hp = hci_proto[HCI_PROTO_L2CAP];
533
	if (hp && hp->encrypt_cfm)
534
		hp->encrypt_cfm(conn, status);
535
536
	hp = hci_proto[HCI_PROTO_SCO];
537
	if (hp && hp->encrypt_cfm)
538
		hp->encrypt_cfm(conn, status);
539
}
540
541
int hci_register_proto(struct hci_proto *hproto);
542
int hci_unregister_proto(struct hci_proto *hproto);
543
544
/* ----- HCI callbacks ----- */
545
struct hci_cb {
546
	struct list_head list;
547
548
	char *name;
549
550
	void (*auth_cfm)	(struct hci_conn *conn, __u8 status);
551
	void (*encrypt_cfm)	(struct hci_conn *conn, __u8 status, __u8 encrypt);
552
	void (*key_change_cfm)	(struct hci_conn *conn, __u8 status);
553
	void (*role_switch_cfm)	(struct hci_conn *conn, __u8 status, __u8 role);
554
};
555
556
static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status)
557
{
558
	struct list_head *p;
559
560
	hci_proto_auth_cfm(conn, status);
561
562
	read_lock_bh(&hci_cb_list_lock);
563
	list_for_each(p, &hci_cb_list) {
564
		struct hci_cb *cb = list_entry(p, struct hci_cb, list);
565
		if (cb->auth_cfm)
566
			cb->auth_cfm(conn, status);
567
	}
568
	read_unlock_bh(&hci_cb_list_lock);
569
}
570
571
static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status, __u8 encrypt)
572
{
573
	struct list_head *p;
574
575
	hci_proto_encrypt_cfm(conn, status);
576
577
	read_lock_bh(&hci_cb_list_lock);
578
	list_for_each(p, &hci_cb_list) {
579
		struct hci_cb *cb = list_entry(p, struct hci_cb, list);
580
		if (cb->encrypt_cfm)
581
			cb->encrypt_cfm(conn, status, encrypt);
582
	}
583
	read_unlock_bh(&hci_cb_list_lock);
584
}
585
586
static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status)
587
{
588
	struct list_head *p;
589
590
	read_lock_bh(&hci_cb_list_lock);
591
	list_for_each(p, &hci_cb_list) {
592
		struct hci_cb *cb = list_entry(p, struct hci_cb, list);
593
		if (cb->key_change_cfm)
594
			cb->key_change_cfm(conn, status);
595
	}
596
	read_unlock_bh(&hci_cb_list_lock);
597
}
598
599
static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status, __u8 role)
600
{
601
	struct list_head *p;
602
603
	read_lock_bh(&hci_cb_list_lock);
604
	list_for_each(p, &hci_cb_list) {
605
		struct hci_cb *cb = list_entry(p, struct hci_cb, list);
606
		if (cb->role_switch_cfm)
607
			cb->role_switch_cfm(conn, status, role);
608
	}
609
	read_unlock_bh(&hci_cb_list_lock);
610
}
611
612
int hci_register_cb(struct hci_cb *hcb);
613
int hci_unregister_cb(struct hci_cb *hcb);
614
615
int hci_register_notifier(struct notifier_block *nb);
616
int hci_unregister_notifier(struct notifier_block *nb);
617
618
int hci_send_cmd(struct hci_dev *hdev, __u16 ogf, __u16 ocf, __u32 plen, void *param);
619
int hci_send_acl(struct hci_conn *conn, struct sk_buff *skb, __u16 flags);
620
int hci_send_sco(struct hci_conn *conn, 
621
			struct sk_buff *skb, 
622
			int sndbufsize, 
623
			void (*send_complete_cb)(struct hci_conn *conn));
624
625
void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 ogf, __u16 ocf);
626
627
void hci_si_event(struct hci_dev *hdev, int type, int dlen, void *data);
628
629
/* ----- HCI Sockets ----- */
630
void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb);
631
632
/* HCI info for socket */
633
#define hci_pi(sk) ((struct hci_pinfo *) sk)
634
635
struct hci_pinfo {
636
	struct bt_sock    bt;
637
	struct hci_dev    *hdev;
638
	struct hci_filter filter;
639
	__u32             cmsg_mask;
640
};
641
642
/* HCI security filter */
643
#define HCI_SFLT_MAX_OGF  5
644
645
struct hci_sec_filter {
646
	__u32 type_mask;
647
	__u32 event_mask[2];
648
	__u32 ocf_mask[HCI_SFLT_MAX_OGF + 1][4];
649
};
650
651
/* ----- HCI requests ----- */
652
#define HCI_REQ_DONE	  0
653
#define HCI_REQ_PEND	  1
654
#define HCI_REQ_CANCELED  2
655
656
#define hci_req_lock(d)		down(&d->req_lock)
657
#define hci_req_unlock(d)	up(&d->req_lock)
658
659
void hci_req_complete(struct hci_dev *hdev, int result);
660
661
#endif /* __HCI_CORE_H */
(-)linux-2.6.18-mh7/include/net/bluetooth/hci.h (+7 lines)
Lines 767-772 Link Here
767
	__u32 byte_tx;
767
	__u32 byte_tx;
768
};
768
};
769
769
770
/* Fields down there are mostly the same as hci_dev,
771
   as this structure is meant to communicate info
772
   to userspace */
770
struct hci_dev_info {
773
struct hci_dev_info {
771
	__u16 dev_id;
774
	__u16 dev_id;
772
	char  name[8];
775
	char  name[8];
Lines 782-790 Link Here
782
	__u32 link_policy;
785
	__u32 link_policy;
783
	__u32 link_mode;
786
	__u32 link_mode;
784
787
788
	/* Maximum transmition unit for ACL packets */
785
	__u16 acl_mtu;
789
	__u16 acl_mtu;
790
	/* Number of ACL packets the baseband is able to buffer */
786
	__u16 acl_pkts;
791
	__u16 acl_pkts;
792
	/* Maximum transmition unit for SCO packets */
787
	__u16 sco_mtu;
793
	__u16 sco_mtu;
794
	/* Number of SCO packets the baseband is able to buffer */
788
	__u16 sco_pkts;
795
	__u16 sco_pkts;
789
796
790
	struct hci_dev_stats stat;
797
	struct hci_dev_stats stat;
(-)linux-2.6.18-mh7/include/net/bluetooth/sco.h (-5 / +3 lines)
Lines 26-37 Link Here
26
#define __SCO_H
26
#define __SCO_H
27
27
28
/* SCO defaults */
28
/* SCO defaults */
29
#define SCO_DEFAULT_MTU		500
30
#define SCO_DEFAULT_FLUSH_TO	0xFFFF
31
32
#define SCO_CONN_TIMEOUT	(HZ * 40)
29
#define SCO_CONN_TIMEOUT	(HZ * 40)
33
#define SCO_DISCONN_TIMEOUT	(HZ * 2)
34
#define SCO_CONN_IDLE_TIMEOUT	(HZ * 60)
35
30
36
/* SCO socket address */
31
/* SCO socket address */
37
struct sockaddr_sco {
32
struct sockaddr_sco {
Lines 51-56 Link Here
51
	__u8  dev_class[3];
46
	__u8  dev_class[3];
52
};
47
};
53
48
49
#define SCO_TXBUFS	0x03
50
#define SCO_RXBUFS	0x04
51
54
/* ---- SCO connections ---- */
52
/* ---- SCO connections ---- */
55
struct sco_conn {
53
struct sco_conn {
56
	struct hci_conn	*hcon;
54
	struct hci_conn	*hcon;
(-)linux-2.6.18-mh7/net/bluetooth/hci_conn.c (-3 / +9 lines)
Lines 184-190 Link Here
184
184
185
	conn->power_save = 1;
185
	conn->power_save = 1;
186
186
187
	skb_queue_head_init(&conn->data_q);
187
	conn->pkt_sent_cb = NULL;
188
	skb_queue_head_init(&conn->out_q);
189
190
	hrtimer_init(&conn->tx_timer, CLOCK_MONOTONIC, HRTIMER_NORESTART);
188
191
189
	init_timer(&conn->disc_timer);
192
	init_timer(&conn->disc_timer);
190
	conn->disc_timer.function = hci_conn_timeout;
193
	conn->disc_timer.function = hci_conn_timeout;
Lines 195-200 Link Here
195
	conn->idle_timer.data = (unsigned long) conn;
198
	conn->idle_timer.data = (unsigned long) conn;
196
199
197
	atomic_set(&conn->refcnt, 0);
200
	atomic_set(&conn->refcnt, 0);
201
	atomic_set(&conn->sent, 0);
198
202
199
	hci_dev_hold(hdev);
203
	hci_dev_hold(hdev);
200
204
Lines 221-226 Link Here
221
225
222
	del_timer(&conn->disc_timer);
226
	del_timer(&conn->disc_timer);
223
227
228
	hrtimer_cancel(&conn->tx_timer);
229
224
	if (conn->type == SCO_LINK) {
230
	if (conn->type == SCO_LINK) {
225
		struct hci_conn *acl = conn->link;
231
		struct hci_conn *acl = conn->link;
226
		if (acl) {
232
		if (acl) {
Lines 233-239 Link Here
233
			sco->link = NULL;
239
			sco->link = NULL;
234
240
235
		/* Unacked frames */
241
		/* Unacked frames */
236
		hdev->acl_cnt += conn->sent;
242
		hdev->acl_cnt += atomic_read(&conn->sent);
237
	}
243
	}
238
244
239
	tasklet_disable(&hdev->tx_task);
245
	tasklet_disable(&hdev->tx_task);
Lines 246-252 Link Here
246
252
247
	tasklet_enable(&hdev->tx_task);
253
	tasklet_enable(&hdev->tx_task);
248
254
249
	skb_queue_purge(&conn->data_q);
255
	skb_queue_purge(&conn->out_q);
250
256
251
	hci_dev_put(hdev);
257
	hci_dev_put(hdev);
252
258
(-)linux-2.6.18-mh7/net/bluetooth/hci_core.c (-50 / +120 lines)
Lines 619-626 Link Here
619
	if (hdev->flush)
619
	if (hdev->flush)
620
		hdev->flush(hdev);
620
		hdev->flush(hdev);
621
621
622
	atomic_set(&hdev->cmd_cnt, 1); 
622
	atomic_set(&hdev->cmd_cnt, 1);
623
	hdev->acl_cnt = 0; hdev->sco_cnt = 0;
623
	atomic_set(&hdev->sco_cnt, 0); 
624
	hdev->acl_cnt = 0; 
624
625
625
	if (!test_bit(HCI_RAW, &hdev->flags))
626
	if (!test_bit(HCI_RAW, &hdev->flags))
626
		ret = __hci_request(hdev, hci_reset_req, 0,
627
		ret = __hci_request(hdev, hci_reset_req, 0,
Lines 1096-1102 Link Here
1096
		/* Non fragmented */
1097
		/* Non fragmented */
1097
		BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len);
1098
		BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len);
1098
1099
1099
		skb_queue_tail(&conn->data_q, skb);
1100
		skb_queue_tail(&conn->out_q, skb);
1100
	} else {
1101
	} else {
1101
		/* Fragmented */
1102
		/* Fragmented */
1102
		BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len);
1103
		BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len);
Lines 1104-1112 Link Here
1104
		skb_shinfo(skb)->frag_list = NULL;
1105
		skb_shinfo(skb)->frag_list = NULL;
1105
1106
1106
		/* Queue all fragments atomically */
1107
		/* Queue all fragments atomically */
1107
		spin_lock_bh(&conn->data_q.lock);
1108
		spin_lock_bh(&conn->out_q.lock);
1108
1109
1109
		__skb_queue_tail(&conn->data_q, skb);
1110
		__skb_queue_tail(&conn->out_q, skb);
1110
		do {
1111
		do {
1111
			skb = list; list = list->next;
1112
			skb = list; list = list->next;
1112
			
1113
			
Lines 1116-1125 Link Here
1116
1117
1117
			BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len);
1118
			BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len);
1118
1119
1119
			__skb_queue_tail(&conn->data_q, skb);
1120
			__skb_queue_tail(&conn->out_q, skb);
1120
		} while (list);
1121
		} while (list);
1121
1122
1122
		spin_unlock_bh(&conn->data_q.lock);
1123
		spin_unlock_bh(&conn->out_q.lock);
1123
	}
1124
	}
1124
1125
1125
	hci_sched_tx(hdev);
1126
	hci_sched_tx(hdev);
Lines 1127-1167 Link Here
1127
}
1128
}
1128
EXPORT_SYMBOL(hci_send_acl);
1129
EXPORT_SYMBOL(hci_send_acl);
1129
1130
1130
/* Send SCO data */
1131
static inline void __hci_send_sco(struct hci_conn *conn, struct sk_buff *skb)
1131
int hci_send_sco(struct hci_conn *conn, struct sk_buff *skb)
1132
{
1132
{
1133
	struct hci_dev *hdev = conn->hdev;
1134
	struct hci_sco_hdr hdr;
1133
	struct hci_sco_hdr hdr;
1135
1134
1136
	BT_DBG("%s len %d", hdev->name, skb->len);
1135
	BT_DBG("skb %p len %d", skb, skb->len);
1137
1136
	/* preparing frame */
1138
	if (skb->len > hdev->sco_mtu) {
1139
		kfree_skb(skb);
1140
		return -EINVAL;
1141
	}
1142
1143
	hdr.handle = __cpu_to_le16(conn->handle);
1137
	hdr.handle = __cpu_to_le16(conn->handle);
1144
	hdr.dlen   = skb->len;
1138
	hdr.dlen   = skb->len;
1145
1139
1146
	skb->h.raw = skb_push(skb, HCI_SCO_HDR_SIZE);
1140
	skb->h.raw = skb_push(skb, HCI_SCO_HDR_SIZE);
1147
	memcpy(skb->h.raw, &hdr, HCI_SCO_HDR_SIZE);
1141
	memcpy(skb->h.raw, &hdr, HCI_SCO_HDR_SIZE);
1148
1142
1149
	skb->dev = (void *) hdev;
1143
	skb->dev = (void *) conn->hdev;
1150
	bt_cb(skb)->pkt_type = HCI_SCODATA_PKT;
1144
	bt_cb(skb)->pkt_type = HCI_SCODATA_PKT;
1151
	skb_queue_tail(&conn->data_q, skb);
1145
1152
	hci_sched_tx(hdev);
1146
	skb_queue_tail(&conn->out_q, skb);
1153
	return 0;
1147
1148
	hci_sched_tx(conn->hdev);
1149
}
1150
1151
int hci_send_sco(struct hci_conn *conn, struct sk_buff *skb, 
1152
		int sndbufsize, void (*send_complete_cb)(struct hci_conn *conn))
1153
{
1154
	BT_DBG("conn %p skb %p sndbufsize %d", conn, skb, sndbufsize);
1155
	if(skb_queue_len(&conn->out_q) < sndbufsize) {
1156
		__hci_send_sco(conn, skb);
1157
		conn->pkt_sent_cb = send_complete_cb;
1158
		return 0;
1159
	}
1160
	else {
1161
		return -EAGAIN;
1162
	}
1154
}
1163
}
1155
EXPORT_SYMBOL(hci_send_sco);
1164
EXPORT_SYMBOL(hci_send_sco);
1156
1165
1157
/* ---- HCI TX task (outgoing data) ---- */
1166
/* ---- HCI TX task (outgoing data) ---- */
1158
1167
1159
/* HCI Connection scheduler */
1168
/* HCI ACL Connection scheduler */
1160
static inline struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, int *quote)
1169
static inline struct hci_conn *hci_low_sent_acl(struct hci_dev *hdev, int *quote)
1161
{
1170
{
1162
	struct hci_conn_hash *h = &hdev->conn_hash;
1171
	struct hci_conn_hash *h = &hdev->conn_hash;
1163
	struct hci_conn  *conn = NULL;
1172
	struct hci_conn  *conn = NULL;
1164
	int num = 0, min = ~0;
1173
	unsigned int num = 0, min = ~0;
1165
	struct list_head *p;
1174
	struct list_head *p;
1166
1175
1167
	/* We don't have to lock device here. Connections are always 
1176
	/* We don't have to lock device here. Connections are always 
Lines 1170-1189 Link Here
1170
		struct hci_conn *c;
1179
		struct hci_conn *c;
1171
		c = list_entry(p, struct hci_conn, list);
1180
		c = list_entry(p, struct hci_conn, list);
1172
1181
1173
		if (c->type != type || c->state != BT_CONNECTED
1182
		BT_DBG("c->type %d c->state %d len(c->out_q) %d min %d c->sent %d", 
1174
				|| skb_queue_empty(&c->data_q))
1183
			c->type, c->state, skb_queue_len(&c->out_q), min, atomic_read(&c->sent));
1184
1185
		if (c->type != ACL_LINK || c->state != BT_CONNECTED
1186
				|| skb_queue_empty(&c->out_q))
1175
			continue;
1187
			continue;
1176
		num++;
1188
		num++;
1177
1189
1178
		if (c->sent < min) {
1190
		if (atomic_read(&c->sent) < min) {
1179
			min  = c->sent;
1191
			min  = atomic_read(&c->sent);
1180
			conn = c;
1192
			conn = c;
1181
		}
1193
		}
1182
	}
1194
	}
1183
1195
1184
	if (conn) {
1196
	if (conn) {
1185
		int cnt = (type == ACL_LINK ? hdev->acl_cnt : hdev->sco_cnt);
1197
		int q = hdev->acl_cnt / num;
1186
		int q = cnt / num;
1187
		*quote = q ? q : 1;
1198
		*quote = q ? q : 1;
1188
	} else
1199
	} else
1189
		*quote = 0;
1200
		*quote = 0;
Lines 1203-1209 Link Here
1203
	/* Kill stalled connections */
1214
	/* Kill stalled connections */
1204
	list_for_each(p, &h->list) {
1215
	list_for_each(p, &h->list) {
1205
		c = list_entry(p, struct hci_conn, list);
1216
		c = list_entry(p, struct hci_conn, list);
1206
		if (c->type == ACL_LINK && c->sent) {
1217
		if (c->type == ACL_LINK && atomic_read(&c->sent)) {
1207
			BT_ERR("%s killing stalled ACL connection %s",
1218
			BT_ERR("%s killing stalled ACL connection %s",
1208
				hdev->name, batostr(&c->dst));
1219
				hdev->name, batostr(&c->dst));
1209
			hci_acl_disconn(c, 0x13);
1220
			hci_acl_disconn(c, 0x13);
Lines 1226-1233 Link Here
1226
			hci_acl_tx_to(hdev);
1237
			hci_acl_tx_to(hdev);
1227
	}
1238
	}
1228
1239
1229
	while (hdev->acl_cnt && (conn = hci_low_sent(hdev, ACL_LINK, &quote))) {
1240
	while (hdev->acl_cnt && (conn = hci_low_sent_acl(hdev, &quote))) {
1230
		while (quote-- && (skb = skb_dequeue(&conn->data_q))) {
1241
		while (quote-- && (skb = skb_dequeue(&conn->out_q))) {
1231
			BT_DBG("skb %p len %d", skb, skb->len);
1242
			BT_DBG("skb %p len %d", skb, skb->len);
1232
1243
1233
			hci_conn_enter_active_mode(conn);
1244
			hci_conn_enter_active_mode(conn);
Lines 1236-1263 Link Here
1236
			hdev->acl_last_tx = jiffies;
1247
			hdev->acl_last_tx = jiffies;
1237
1248
1238
			hdev->acl_cnt--;
1249
			hdev->acl_cnt--;
1239
			conn->sent++;
1250
			atomic_inc(&conn->sent);
1240
		}
1251
		}
1241
	}
1252
	}
1242
}
1253
}
1243
1254
1244
/* Schedule SCO */
1255
/* HCI SCO tx timer */
1245
static inline void hci_sched_sco(struct hci_dev *hdev)
1256
1257
static int hci_sco_tx_timer(struct hrtimer *timer)
1246
{
1258
{
1247
	struct hci_conn *conn;
1259
	struct hci_conn *conn = container_of(timer, struct hci_conn, tx_timer);
1248
	struct sk_buff *skb;
1260
#ifdef CONFIG_BT_HCI_CORE_DEBUG
1249
	int quote;
1261
	ktime_t now = timer->base->get_time();
1262
#endif
1250
1263
1251
	BT_DBG("%s", hdev->name);
1264
	BT_DBG("%s, conn %p, time %5lu.%06lu", conn->hdev->name, conn,
1265
		(unsigned long) now.tv64, 
1266
		do_div(now.tv64, NSEC_PER_SEC) / 1000);
1252
1267
1253
	while (hdev->sco_cnt && (conn = hci_low_sent(hdev, SCO_LINK, &quote))) {
1268
	if(atomic_read(&conn->sent) > 0) {
1254
		while (quote-- && (skb = skb_dequeue(&conn->data_q))) {
1269
		atomic_dec(&conn->sent);
1255
			BT_DBG("skb %p len %d", skb, skb->len);
1270
		atomic_inc(&conn->hdev->sco_cnt);
1256
			hci_send_frame(skb);
1271
		hci_sched_tx(conn->hdev);
1272
	}
1273
	/* Wake up writers */
1274
	if(conn->pkt_sent_cb) {
1275
		conn->pkt_sent_cb(conn);
1276
	}
1277
	return HRTIMER_NORESTART;
1278
}
1279
 
1280
/* HCI SCO Connection scheduler */
1257
1281
1258
			conn->sent++;
1282
static inline void hci_sched_sco(struct hci_dev *hdev)
1259
			if (conn->sent == ~0)
1283
{
1260
				conn->sent = 0;
1284
	struct hci_conn_hash *h = &hdev->conn_hash;
1285
	struct sk_buff *skb;
1286
	struct list_head *p;
1287
	struct hci_conn *c;
1288
	
1289
	BT_DBG("%s", hdev->name);
1290
  
1291
	/* We don't have to lock device here. Connections are always 
1292
	 * added and removed with TX task disabled. */
1293
	list_for_each(p, &h->list) {
1294
		c = list_entry(p, struct hci_conn, list);
1295
  
1296
		/* SCO scheduling algorithm makes sure there is never more than
1297
		   1 outstanding packet for each connection */
1298
		if (c->type == SCO_LINK && atomic_read(&c->sent) < 1  && c->state == BT_CONNECTED)
1299
		{
1300
			if(atomic_read(&hdev->sco_cnt) > 0) {
1301
				if((skb = skb_dequeue(&c->out_q)) != NULL) {
1302
					ktime_t now, pkt_time;
1303
1304
					hci_send_frame(skb);
1305
 
1306
					atomic_inc(&c->sent);			
1307
					atomic_dec(&hdev->sco_cnt);
1308
1309
					c->tx_timer.function = hci_sco_tx_timer;
1310
					
1311
					pkt_time =
1312
						ktime_set(0, NSEC_PER_SEC / 16000 * (skb->len - HCI_SCO_HDR_SIZE));
1313
					now = c->tx_timer.base->get_time();
1314
1315
					if(c->tx_timer.expires.tv64 == 0) {
1316
						c->tx_timer.expires = now;
1317
					}
1318
1319
					c->tx_timer.expires.tv64 += pkt_time.tv64;
1320
					if(c->tx_timer.expires.tv64 > now.tv64) {
1321
						hrtimer_restart(&c->tx_timer);
1322
					}
1323
					else {
1324
						/* Timer is to expire in the past - this can happen if timer base
1325
						 precision is less than pkt_time. In this case we force timer
1326
						 expiration by calling its expires function */
1327
						c->tx_timer.function(&c->tx_timer);
1328
					}
1329
				}
1330
			}
1261
		}
1331
		}
1262
	}
1332
	}
1263
}
1333
}
Lines 1269-1282 Link Here
1269
1339
1270
	read_lock(&hci_task_lock);
1340
	read_lock(&hci_task_lock);
1271
1341
1272
	BT_DBG("%s acl %d sco %d", hdev->name, hdev->acl_cnt, hdev->sco_cnt);
1342
	BT_DBG("%s acl %d sco %d", hdev->name, hdev->acl_cnt, atomic_read(&hdev->sco_cnt));
1273
1343
1274
	/* Schedule queues and send stuff to HCI driver */
1344
	/* Schedule queues and send stuff to HCI driver */
1275
1345
1276
	hci_sched_acl(hdev);
1277
1278
	hci_sched_sco(hdev);
1346
	hci_sched_sco(hdev);
1279
1347
1348
	hci_sched_acl(hdev);
1349
1280
	/* Send next queued raw (unknown type) packet */
1350
	/* Send next queued raw (unknown type) packet */
1281
	while ((skb = skb_dequeue(&hdev->raw_q)))
1351
	while ((skb = skb_dequeue(&hdev->raw_q)))
1282
		hci_send_frame(skb);
1352
		hci_send_frame(skb);
(-)linux-2.6.18-mh7/net/bluetooth/hci_event.c (-7 / +7 lines)
Lines 310-316 Link Here
310
		lv = (struct hci_rp_read_loc_version *) skb->data;
310
		lv = (struct hci_rp_read_loc_version *) skb->data;
311
311
312
		if (lv->status) {
312
		if (lv->status) {
313
			BT_DBG("%s READ_LOCAL_VERSION failed %d", hdev->name, lf->status);
313
			BT_DBG("%s READ_LOCAL_VERSION failed %d", hdev->name, lv->status);
314
			break;
314
			break;
315
		}
315
		}
316
316
Lines 372-378 Link Here
372
		}
372
		}
373
373
374
		hdev->acl_cnt = hdev->acl_pkts;
374
		hdev->acl_cnt = hdev->acl_pkts;
375
		hdev->sco_cnt = hdev->sco_pkts;
375
		atomic_set(&hdev->sco_cnt, hdev->sco_pkts);
376
376
377
		BT_DBG("%s mtu: acl %d, sco %d max_pkt: acl %d, sco %d", hdev->name,
377
		BT_DBG("%s mtu: acl %d, sco %d max_pkt: acl %d, sco %d", hdev->name,
378
			hdev->acl_mtu, hdev->sco_mtu, hdev->acl_pkts, hdev->sco_pkts);
378
			hdev->acl_mtu, hdev->sco_mtu, hdev->acl_pkts, hdev->sco_pkts);
Lines 861-875 Link Here
861
861
862
		conn = hci_conn_hash_lookup_handle(hdev, handle);
862
		conn = hci_conn_hash_lookup_handle(hdev, handle);
863
		if (conn) {
863
		if (conn) {
864
			conn->sent -= count;
864
			atomic_sub(count, &conn->sent);
865
865
866
			if (conn->type == SCO_LINK) {
866
			if (conn->type == ACL_LINK) {
867
				if ((hdev->sco_cnt += count) > hdev->sco_pkts)
868
					hdev->sco_cnt = hdev->sco_pkts;
869
			} else {
870
				if ((hdev->acl_cnt += count) > hdev->acl_pkts)
867
				if ((hdev->acl_cnt += count) > hdev->acl_pkts)
871
					hdev->acl_cnt = hdev->acl_pkts;
868
					hdev->acl_cnt = hdev->acl_pkts;
872
			}
869
			}
870
			/* Note : we do not use the "number of completed packets" event
871
			to increment hdev->sco_cnt, as this feature is only optionnally support
872
			by bluetooth controllers. So there is no if branch for SCO_LINK packets */
873
		}
873
		}
874
	}
874
	}
875
	hci_sched_tx(hdev);
875
	hci_sched_tx(hdev);
(-)linux-2.6.18-mh7/net/bluetooth/sco.c (-14 / +149 lines)
Lines 53-59 Link Here
53
#define BT_DBG(D...)
53
#define BT_DBG(D...)
54
#endif
54
#endif
55
55
56
#define VERSION "0.5"
56
#define VERSION "0.6"
57
58
#define MAX_SCO_TXBUFS 200
59
#define MAX_SCO_RXBUFS 200
60
61
#define DEFAULT_SCO_TXBUFS 5
62
#define DEFAULT_SCO_RXBUFS 5
57
63
58
static const struct proto_ops sco_sock_ops;
64
static const struct proto_ops sco_sock_ops;
59
65
Lines 61-66 Link Here
61
	.lock = RW_LOCK_UNLOCKED
67
	.lock = RW_LOCK_UNLOCKED
62
};
68
};
63
69
70
/* Local functions declaration */
71
64
static void __sco_chan_add(struct sco_conn *conn, struct sock *sk, struct sock *parent);
72
static void __sco_chan_add(struct sco_conn *conn, struct sock *sk, struct sock *parent);
65
static void sco_chan_del(struct sock *sk, int err);
73
static void sco_chan_del(struct sock *sk, int err);
66
74
Lines 69-74 Link Here
69
static void sco_sock_close(struct sock *sk);
77
static void sco_sock_close(struct sock *sk);
70
static void sco_sock_kill(struct sock *sk);
78
static void sco_sock_kill(struct sock *sk);
71
79
80
static void sco_sock_rfree(struct sk_buff *skb);
81
82
static int sco_sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb);
83
72
/* ---- SCO timers ---- */
84
/* ---- SCO timers ---- */
73
static void sco_sock_timeout(unsigned long arg)
85
static void sco_sock_timeout(unsigned long arg)
74
{
86
{
Lines 230-260 Link Here
230
	return err;
242
	return err;
231
}
243
}
232
244
245
static void sco_send_complete_cb(struct hci_conn *hcon)
246
{
247
	struct sco_conn *conn = hcon->sco_data;
248
	struct sock *sk = conn->sk;
249
	BT_DBG("conn %p, sock %p", conn, sk);
250
251
	if(sk) {
252
		bh_lock_sock(sk);
253
		read_lock(&sk->sk_callback_lock);
254
255
		if (sk->sk_sleep && waitqueue_active(sk->sk_sleep))
256
			wake_up_interruptible(sk->sk_sleep);
257
258
		sk_wake_async(sk, 2, POLL_OUT);
259
260
		read_unlock(&sk->sk_callback_lock);
261
		bh_unlock_sock(sk);
262
	}
263
}
264
233
static inline int sco_send_frame(struct sock *sk, struct msghdr *msg, int len)
265
static inline int sco_send_frame(struct sock *sk, struct msghdr *msg, int len)
234
{
266
{
235
	struct sco_conn *conn = sco_pi(sk)->conn;
267
	struct sco_conn *conn = sco_pi(sk)->conn;
236
	struct sk_buff *skb;
268
	struct sk_buff *skb;
237
	int err, count;
269
	int err;
238
270
239
	/* Check outgoing MTU */
271
	/* Check outgoing MTU */
240
	if (len > conn->mtu)
272
	if (len > conn->mtu)
241
		return -EINVAL;
273
		return -EMSGSIZE;
242
274
243
	BT_DBG("sk %p len %d", sk, len);
275
	BT_DBG("sk %p len %d", sk, len);
244
276
245
	count = min_t(unsigned int, conn->mtu, len);
277
	if (!(skb = bt_skb_alloc(len, GFP_KERNEL)))
246
	if (!(skb = bt_skb_send_alloc(sk, count, msg->msg_flags & MSG_DONTWAIT, &err)))
278
		return -ENOBUFS;
247
		return err;
248
279
249
	if (memcpy_fromiovec(skb_put(skb, count), msg->msg_iov, count)) {
280
	if (memcpy_fromiovec(skb_put(skb, len), msg->msg_iov, len)) {
250
		err = -EFAULT;
281
		err = -EFAULT;
251
		goto fail;
282
		goto fail;
252
	}
283
	}
253
284
254
	if ((err = hci_send_sco(conn->hcon, skb)) < 0)
285
	if(msg->msg_flags & MSG_DONTWAIT) {
255
		return err;
286
		err = hci_send_sco(conn->hcon, skb, sk->sk_sndbuf, sco_send_complete_cb);
287
	}
288
	else {
289
		err = wait_event_interruptible(*sk->sk_sleep, 
290
			(sk->sk_state != BT_CONNECTED) ||
291
			(hci_send_sco(conn->hcon, skb, sk->sk_sndbuf, sco_send_complete_cb) == 0)
292
			);
293
		/* It is possible that we have been waken up because the peer closed the SCO connection */
294
		if(sk->sk_state != BT_CONNECTED) {
295
			err = -ENOTCONN;
296
		}
297
	}
298
299
	if (err < 0)
300
		goto fail;
256
301
257
	return count;
302
	return len;
258
303
259
fail:
304
fail:
260
	kfree_skb(skb);
305
	kfree_skb(skb);
Lines 273-280 Link Here
273
	if (sk->sk_state != BT_CONNECTED)
318
	if (sk->sk_state != BT_CONNECTED)
274
		goto drop;
319
		goto drop;
275
320
276
	if (!sock_queue_rcv_skb(sk, skb))
321
	if (sco_sock_queue_rcv_skb(sk, skb) == 0) {
277
		return;
322
		return;
323
	}
278
324
279
drop:
325
drop:
280
	kfree_skb(skb);
326
	kfree_skb(skb);
Lines 328-334 Link Here
328
	BT_DBG("sk %p", sk);
374
	BT_DBG("sk %p", sk);
329
375
330
	skb_queue_purge(&sk->sk_receive_queue);
376
	skb_queue_purge(&sk->sk_receive_queue);
331
	skb_queue_purge(&sk->sk_write_queue);
332
}
377
}
333
378
334
static void sco_sock_cleanup_listen(struct sock *parent)
379
static void sco_sock_cleanup_listen(struct sock *parent)
Lines 360-365 Link Here
360
	/* Kill poor orphan */
405
	/* Kill poor orphan */
361
	bt_sock_unlink(&sco_sk_list, sk);
406
	bt_sock_unlink(&sco_sk_list, sk);
362
	sock_set_flag(sk, SOCK_DEAD);
407
	sock_set_flag(sk, SOCK_DEAD);
408
	
409
	/* release socket */
363
	sock_put(sk);
410
	sock_put(sk);
364
}
411
}
365
412
Lines 376-382 Link Here
376
423
377
	conn = sco_pi(sk)->conn;
424
	conn = sco_pi(sk)->conn;
378
425
379
	BT_DBG("sk %p state %d conn %p socket %p", sk, sk->sk_state, conn, sk->sk_socket);
426
	BT_DBG("sk %p state %d conn %p socket %p refcnt %d", sk, sk->sk_state, conn, sk->sk_socket, atomic_read(&sk->sk_refcnt));
380
427
381
	switch (sk->sk_state) {
428
	switch (sk->sk_state) {
382
	case BT_LISTEN:
429
	case BT_LISTEN:
Lines 426-431 Link Here
426
	INIT_LIST_HEAD(&bt_sk(sk)->accept_q);
473
	INIT_LIST_HEAD(&bt_sk(sk)->accept_q);
427
474
428
	sk->sk_destruct = sco_sock_destruct;
475
	sk->sk_destruct = sco_sock_destruct;
476
477
       /* Put sensible values for a voice link (i.e. not too big),
478
          as sysctl_rmem_default & sysctl_wmem_default are
479
           really not designed for that -- In our case we use sk_**buf to
480
           store a count of SCO packets, not a number of bytes as most of other type of
481
           sockets do */
482
	sk->sk_sndbuf = DEFAULT_SCO_TXBUFS;
483
	sk->sk_rcvbuf = DEFAULT_SCO_RXBUFS;
429
	sk->sk_sndtimeo = SCO_CONN_TIMEOUT;
484
	sk->sk_sndtimeo = SCO_CONN_TIMEOUT;
430
485
431
	sock_reset_flag(sk, SOCK_ZAPPED);
486
	sock_reset_flag(sk, SOCK_ZAPPED);
Lines 656-661 Link Here
656
static int sco_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int optlen)
711
static int sco_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int optlen)
657
{
712
{
658
	struct sock *sk = sock->sk;
713
	struct sock *sk = sock->sk;
714
	u32 opt;
659
	int err = 0;
715
	int err = 0;
660
716
661
	BT_DBG("sk %p", sk);
717
	BT_DBG("sk %p", sk);
Lines 663-668 Link Here
663
	lock_sock(sk);
719
	lock_sock(sk);
664
720
665
	switch (optname) {
721
	switch (optname) {
722
	case SCO_TXBUFS:
723
		if (get_user(opt, (u32 __user *) optval)) {
724
			err = -EFAULT;
725
			break;
726
		}
727
		if(opt > MAX_SCO_TXBUFS) {
728
			err = -EINVAL;
729
			break;
730
		}
731
732
		sk->sk_sndbuf = opt;
733
		break;
734
	case SCO_RXBUFS:
735
		if (get_user(opt, (u32 __user *) optval)) {
736
			err = -EFAULT;
737
			break;
738
		}
739
		if(opt > MAX_SCO_RXBUFS) {
740
			err = -EINVAL;
741
			break;
742
		}
743
744
		sk->sk_rcvbuf = opt;
745
		break;
666
	default:
746
	default:
667
		err = -ENOPROTOOPT;
747
		err = -ENOPROTOOPT;
668
		break;
748
		break;
Lines 677-683 Link Here
677
	struct sock *sk = sock->sk;
757
	struct sock *sk = sock->sk;
678
	struct sco_options opts;
758
	struct sco_options opts;
679
	struct sco_conninfo cinfo;
759
	struct sco_conninfo cinfo;
680
	int len, err = 0; 
760
	int len, err = 0;
761
	int val;
681
762
682
	BT_DBG("sk %p", sk);
763
	BT_DBG("sk %p", sk);
683
764
Lines 687-692 Link Here
687
	lock_sock(sk);
768
	lock_sock(sk);
688
769
689
	switch (optname) {
770
	switch (optname) {
771
	case SCO_RXBUFS:
772
		val = sk->sk_rcvbuf;
773
774
		len = min_t(unsigned int, len, sizeof(val));
775
		if (copy_to_user(optval, (char *)&val, len))
776
			err = -EFAULT;
777
778
		break;
779
780
	case SCO_TXBUFS:
781
		val = sk->sk_sndbuf;
782
783
		len = min_t(unsigned int, len, sizeof(val));
784
		if (copy_to_user(optval, (char *)&val, len))
785
			err = -EFAULT;
786
787
		break;
788
690
	case SCO_OPTIONS:
789
	case SCO_OPTIONS:
691
		if (sk->sk_state != BT_CONNECTED) {
790
		if (sk->sk_state != BT_CONNECTED) {
692
			err = -ENOTCONN;
791
			err = -ENOTCONN;
Lines 891-896 Link Here
891
	return 0;
990
	return 0;
892
}
991
}
893
992
993
static int sco_sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
994
{
995
       int err = 0;
996
997
       /* Cast skb->rcvbuf to unsigned... It's pointless, but reduces
998
          number of warnings when compiling with -W --ANK
999
        */
1000
       if (atomic_read(&sk->sk_rmem_alloc) + 1 >
1001
           (unsigned)sk->sk_rcvbuf) {
1002
               err = -ENOMEM;
1003
               goto out;
1004
       }
1005
1006
       skb->dev = NULL;
1007
       skb->sk = sk;
1008
       skb->destructor = sco_sock_rfree;
1009
       atomic_add(1, &sk->sk_rmem_alloc);
1010
1011
       skb_queue_tail(&sk->sk_receive_queue, skb);
1012
1013
       if (!sock_flag(sk, SOCK_DEAD))
1014
               sk->sk_data_ready(sk, 1);
1015
out:
1016
       return err;
1017
}
1018
1019
static void sco_sock_rfree(struct sk_buff *skb)
1020
{
1021
       struct sock *sk = skb->sk;
1022
1023
       atomic_sub(1, &sk->sk_rmem_alloc);
1024
}
1025
1026
1027
/* ------- Others ------- */
1028
894
static ssize_t sco_sysfs_show(struct class *dev, char *buf)
1029
static ssize_t sco_sysfs_show(struct class *dev, char *buf)
895
{
1030
{
896
	struct sock *sk;
1031
	struct sock *sk;

Return to bug 10721