wl1251: Add support for idle mode
[pandora-wifi.git] / patches / 16-bluetooth.patch
1 These changes are required to backport blueooth. A lot can be optimized
2 here still, but for now we keep this here.
3
4 --- a/drivers/bluetooth/hci_ldisc.c
5 +++ b/drivers/bluetooth/hci_ldisc.c
6 @@ -277,8 +277,13 @@ static int hci_uart_tty_open(struct tty_
7         /* FIXME: why is this needed. Note don't use ldisc_ref here as the
8            open path is before the ldisc is referencable */
9  
10 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,30))
11         if (tty->ldisc->ops->flush_buffer)
12                 tty->ldisc->ops->flush_buffer(tty);
13 +#else
14 +       if (tty->ldisc.ops->flush_buffer)
15 +               tty->ldisc.ops->flush_buffer(tty);
16 +#endif
17         tty_driver_flush_buffer(tty);
18  
19         return 0;
20 @@ -478,7 +483,11 @@ static int hci_uart_tty_ioctl(struct tty
21                 return -EUNATCH;
22  
23         default:
24 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27))
25                 err = n_tty_ioctl_helper(tty, file, cmd, arg);
26 +#else
27 +               err = n_tty_ioctl(tty, file, cmd, arg);
28 +#endif
29                 break;
30         };
31  
32 --- a/net/bluetooth/af_bluetooth.c
33 +++ b/net/bluetooth/af_bluetooth.c
34 @@ -126,8 +126,12 @@ int bt_sock_unregister(int proto)
35  }
36  EXPORT_SYMBOL(bt_sock_unregister);
37  
38 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32))
39  static int bt_sock_create(struct net *net, struct socket *sock, int proto,
40                           int kern)
41 +#else
42 +static int bt_sock_create(struct net *net, struct socket *sock, int proto)
43 +#endif
44  {
45         int err;
46  
47 @@ -145,7 +149,11 @@ static int bt_sock_create(struct net *ne
48         read_lock(&bt_proto_lock);
49  
50         if (bt_proto[proto] && try_module_get(bt_proto[proto]->owner)) {
51 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32))
52                 err = bt_proto[proto]->create(net, sock, proto, kern);
53 +#else
54 +               err = bt_proto[proto]->create(net, sock, proto);
55 +#endif
56                 bt_sock_reclassify_lock(sock, proto);
57                 module_put(bt_proto[proto]->owner);
58         }
59 @@ -258,7 +266,11 @@ int bt_sock_recvmsg(struct kiocb *iocb, 
60         skb_reset_transport_header(skb);
61         err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
62         if (err == 0)
63 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32))
64                 sock_recv_ts_and_drops(msg, sk, skb);
65 +#else
66 +         sock_recv_timestamp(msg, sk, skb);
67 +#endif
68  
69         skb_free_datagram(sk, skb);
70  
71 @@ -338,7 +350,11 @@ int bt_sock_ioctl(struct socket *sock, u
72                 if (sk->sk_state == BT_LISTEN)
73                         return -EINVAL;
74  
75 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,31))
76                 amount = sk->sk_sndbuf - sk_wmem_alloc_get(sk);
77 +#else
78 +    amount = sk->sk_sndbuf - atomic_read(&sk->sk_wmem_alloc);
79 +#endif
80                 if (amount < 0)
81                         amount = 0;
82                 err = put_user(amount, (int __user *) arg);
83 --- a/net/bluetooth/cmtp/capi.c
84 +++ b/net/bluetooth/cmtp/capi.c
85 @@ -383,7 +383,11 @@ static void cmtp_reset_ctr(struct capi_c
86  
87         BT_DBG("ctrl %p", ctrl);
88  
89 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,30))
90         capi_ctr_down(ctrl);
91 +#else
92 +       capi_ctr_reseted(ctrl);
93 +#endif
94  
95         atomic_inc(&session->terminate);
96         cmtp_schedule(session);
97 --- a/net/bluetooth/hci_core.c
98 +++ b/net/bluetooth/hci_core.c
99 @@ -39,7 +39,12 @@
100  #include <linux/skbuff.h>
101  #include <linux/interrupt.h>
102  #include <linux/notifier.h>
103 +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,31))
104  #include <linux/rfkill.h>
105 +#else
106 +#include <linux/rfkill_backport.h>
107 +#endif
108 +
109  #include <net/sock.h>
110  
111  #include <asm/system.h>
112 --- a/net/bluetooth/hci_sock.c
113 +++ b/net/bluetooth/hci_sock.c
114 @@ -471,7 +471,11 @@ drop:
115         goto done;
116  }
117  
118 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,31))
119  static int hci_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int len)
120 +#else
121 +static int hci_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int len)
122 +#endif
123  {
124         struct hci_ufilter uf = { .opcode = 0 };
125         struct sock *sk = sock->sk;
126 @@ -626,8 +630,12 @@ static struct proto hci_sk_proto = {
127         .obj_size       = sizeof(struct hci_pinfo)
128  };
129  
130 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32))
131  static int hci_sock_create(struct net *net, struct socket *sock, int protocol,
132                            int kern)
133 +#else
134 +static int hci_sock_create(struct net *net, struct socket *sock, int protocol)
135 +#endif
136  {
137         struct sock *sk;
138  
139 --- a/net/bluetooth/hci_sysfs.c
140 +++ b/net/bluetooth/hci_sysfs.c
141 @@ -68,7 +68,11 @@ static struct attribute_group bt_link_gr
142         .attrs = bt_link_attrs,
143  };
144  
145 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,31))
146  static const struct attribute_group *bt_link_groups[] = {
147 +#else
148 +static struct attribute_group *bt_link_groups[] = {
149 +#endif
150         &bt_link_group,
151         NULL
152  };
153 @@ -126,7 +130,11 @@ static void del_conn(struct work_struct 
154                 dev = device_find_child(&conn->dev, NULL, __match_tty);
155                 if (!dev)
156                         break;
157 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
158                 device_move(dev, NULL, DPM_ORDER_DEV_LAST);
159 +#else
160 +               device_move(dev, NULL);
161 +#endif
162                 put_device(dev);
163         }
164  
165 @@ -392,7 +400,11 @@ static struct attribute_group bt_host_gr
166         .attrs = bt_host_attrs,
167  };
168  
169 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,31))
170  static const struct attribute_group *bt_host_groups[] = {
171 +#else
172 +static struct attribute_group *bt_host_groups[] = {
173 +#endif
174         &bt_host_group,
175         NULL
176  };
177 --- a/net/bluetooth/hidp/core.c
178 +++ b/net/bluetooth/hidp/core.c
179 @@ -313,6 +313,7 @@ static int hidp_send_report(struct hidp_
180         return hidp_queue_report(session, buf, rsize);
181  }
182  
183 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27))
184  static int hidp_output_raw_report(struct hid_device *hid, unsigned char *data, size_t count,
185                 unsigned char report_type)
186  {
187 @@ -332,6 +333,7 @@ static int hidp_output_raw_report(struct
188                 return -ENOMEM;
189         return count;
190  }
191 +#endif
192  
193  static void hidp_idle_timeout(unsigned long arg)
194  {
195 @@ -596,10 +598,16 @@ static int hidp_session(void *arg)
196                 session->input = NULL;
197         }
198  
199 -       if (session->hid) {
200 -               hid_destroy_device(session->hid);
201 -               session->hid = NULL;
202 -       }
203 +  if (session->hid) {
204 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27))
205 +    hid_destroy_device(session->hid);
206 +    session->hid = NULL;
207 +#else
208 +    if (session->hid->claimed & HID_CLAIMED_INPUT)
209 +      hidinput_disconnect(session->hid);
210 +    hid_free_device(session->hid);
211 +#endif
212 +  }
213  
214         /* Wakeup user-space polling for socket errors */
215         session->intr_sock->sk->sk_err = EUNATCH;
216 @@ -711,6 +719,70 @@ static void hidp_close(struct hid_device
217  {
218  }
219  
220 +#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,27))
221 +static const struct {
222 +       __u16 idVendor;
223 +       __u16 idProduct;
224 +       unsigned quirks;
225 +} hidp_blacklist[] = {
226 +       /* Apple wireless Mighty Mouse */
227 +       { 0x05ac, 0x030c, HID_QUIRK_MIGHTYMOUSE | HID_QUIRK_INVERT_HWHEEL },
228 +
229 +       { }     /* Terminating entry */
230 +};
231 +static void hidp_setup_quirks(struct hid_device *hid)
232 +{
233 +       unsigned int n;
234 +
235 +       for (n = 0; hidp_blacklist[n].idVendor; n++)
236 +               if (hidp_blacklist[n].idVendor == le16_to_cpu(hid->vendor) &&
237 +                               hidp_blacklist[n].idProduct == le16_to_cpu(hid->product))
238 +                       hid->quirks = hidp_blacklist[n].quirks;
239 +}
240 +
241 +static void hidp_setup_hid(struct hidp_session *session,
242 +                               struct hidp_connadd_req *req)
243 +{
244 +       struct hid_device *hid = session->hid;
245 +       struct hid_report *report;
246 +       bdaddr_t src, dst;
247 +
248 +       session->hid = hid;
249 +
250 +       hid->driver_data = session;
251 +
252 +       baswap(&src, &bt_sk(session->ctrl_sock->sk)->src);
253 +       baswap(&dst, &bt_sk(session->ctrl_sock->sk)->dst);
254 +
255 +       hid->bus     = BUS_BLUETOOTH;
256 +       hid->vendor  = req->vendor;
257 +       hid->product = req->product;
258 +       hid->version = req->version;
259 +       hid->country = req->country;
260 +
261 +       strncpy(hid->name, req->name, 128);
262 +       strncpy(hid->phys, batostr(&src), 64);
263 +       strncpy(hid->uniq, batostr(&dst), 64);
264 +
265 +       hid->dev = hidp_get_device(session);
266 +       hid->hid_open  = hidp_open;
267 +       hid->hid_close = hidp_close;
268 +
269 +       hid->hidinput_input_event = hidp_hidinput_event;
270 +
271 +       hidp_setup_quirks(hid);
272 +
273 +       list_for_each_entry(report, &hid->report_enum[HID_INPUT_REPORT].report_list, list)
274 +               hidp_send_report(session, report);
275 +
276 +       list_for_each_entry(report, &hid->report_enum[HID_FEATURE_REPORT].report_list, list)
277 +               hidp_send_report(session, report);
278 +
279 +       if (hidinput_connect(hid) == 0)
280 +               hid->claimed |= HID_CLAIMED_INPUT;
281 +}
282 +#else
283 +
284  static int hidp_parse(struct hid_device *hid)
285  {
286         struct hidp_session *session = hid->driver_data;
287 @@ -815,6 +887,7 @@ fault:
288  
289         return err;
290  }
291 +#endif
292  
293  int hidp_add_connection(struct hidp_connadd_req *req, struct socket *ctrl_sock, struct socket *intr_sock)
294  {
295 @@ -833,6 +906,39 @@ int hidp_add_connection(struct hidp_conn
296  
297         BT_DBG("rd_data %p rd_size %d", req->rd_data, req->rd_size);
298  
299 +#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,27))
300 +       if (req->rd_size > 0) {
301 +               unsigned char *buf = kmalloc(req->rd_size, GFP_KERNEL);
302 +
303 +               if (!buf) {
304 +                       kfree(session);
305 +                       return -ENOMEM;
306 +               }
307 +
308 +               if (copy_from_user(buf, req->rd_data, req->rd_size)) {
309 +                       kfree(buf);
310 +                       kfree(session);
311 +                       return -EFAULT;
312 +               }
313 +
314 +               session->hid = hid_parse_report(buf, req->rd_size);
315 +
316 +               kfree(buf);
317 +
318 +               if (!session->hid) {
319 +                       kfree(session);
320 +                       return -EINVAL;
321 +               }
322 +       }
323 +
324 +       if (!session->hid) {
325 +               session->input = input_allocate_device();
326 +               if (!session->input) {
327 +                       kfree(session);
328 +                       return -ENOMEM;
329 +               }
330 +       }
331 +#endif
332         down_write(&hidp_session_sem);
333  
334         s = __hidp_get_session(&bt_sk(ctrl_sock->sk)->dst);
335 @@ -860,6 +966,7 @@ int hidp_add_connection(struct hidp_conn
336         session->flags   = req->flags & (1 << HIDP_BLUETOOTH_VENDOR_ID);
337         session->idle_to = req->idle_to;
338  
339 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27))
340         if (req->rd_size > 0) {
341                 err = hidp_setup_hid(session, req);
342                 if (err && err != -ENODEV)
343 @@ -871,6 +978,16 @@ int hidp_add_connection(struct hidp_conn
344                 if (err < 0)
345                         goto purge;
346         }
347 +#else
348 +       if (session->input) {
349 +               err = hidp_setup_input(session, req);
350 +               if (err < 0)
351 +                       goto failed;
352 +       }
353 +
354 +       if (session->hid)
355 +               hidp_setup_hid(session, req);
356 +#endif
357  
358         __hidp_link_session(session);
359  
360 @@ -902,6 +1019,7 @@ unlink:
361                 session->input = NULL;
362         }
363  
364 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27))
365         if (session->hid) {
366                 hid_destroy_device(session->hid);
367                 session->hid = NULL;
368 @@ -913,10 +1031,15 @@ unlink:
369  purge:
370         skb_queue_purge(&session->ctrl_transmit);
371         skb_queue_purge(&session->intr_transmit);
372 +#endif
373  
374  failed:
375         up_write(&hidp_session_sem);
376  
377 +#if (LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,27))
378 +       if (session->hid)
379 +               hid_free_device(session->hid);
380 +#endif
381         input_free_device(session->input);
382         kfree(session);
383         return err;
384 @@ -1006,6 +1129,7 @@ int hidp_get_conninfo(struct hidp_connin
385         return err;
386  }
387  
388 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27))
389  static const struct hid_device_id hidp_table[] = {
390         { HID_BLUETOOTH_DEVICE(HID_ANY_ID, HID_ANY_ID) },
391         { }
392 @@ -1015,6 +1139,7 @@ static struct hid_driver hidp_driver = {
393         .name = "generic-bluetooth",
394         .id_table = hidp_table,
395  };
396 +#endif
397  
398  static int __init hidp_init(void)
399  {
400 @@ -1024,11 +1149,14 @@ static int __init hidp_init(void)
401  
402         BT_INFO("HIDP (Human Interface Emulation) ver %s", VERSION);
403  
404 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27))
405         ret = hid_register_driver(&hidp_driver);
406         if (ret)
407                 goto err;
408 +#endif
409  
410         ret = hidp_init_sockets();
411 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27))
412         if (ret)
413                 goto err_drv;
414  
415 @@ -1036,13 +1164,16 @@ static int __init hidp_init(void)
416  err_drv:
417         hid_unregister_driver(&hidp_driver);
418  err:
419 +#endif
420         return ret;
421  }
422  
423  static void __exit hidp_exit(void)
424  {
425         hidp_cleanup_sockets();
426 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,27))
427         hid_unregister_driver(&hidp_driver);
428 +#endif
429  }
430  
431  module_init(hidp_init);
432 --- a/net/bluetooth/rfcomm/sock.c
433 +++ b/net/bluetooth/rfcomm/sock.c
434 @@ -323,8 +323,13 @@ static struct sock *rfcomm_sock_alloc(st
435         return sk;
436  }
437  
438 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32))
439  static int rfcomm_sock_create(struct net *net, struct socket *sock,
440                               int protocol, int kern)
441 +#else
442 +static int rfcomm_sock_create(struct net *net, struct socket *sock,
443 +                             int protocol)
444 +#endif
445  {
446         struct sock *sk;
447  
448 @@ -704,7 +709,11 @@ static int rfcomm_sock_recvmsg(struct ki
449                 copied += chunk;
450                 size   -= chunk;
451  
452 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32))
453                 sock_recv_ts_and_drops(msg, sk, skb);
454 +#else
455 +               sock_recv_timestamp(msg, sk, skb);
456 +#endif
457  
458                 if (!(flags & MSG_PEEK)) {
459                         atomic_sub(chunk, &sk->sk_rmem_alloc);
460 @@ -767,7 +776,11 @@ static int rfcomm_sock_setsockopt_old(st
461         return err;
462  }
463  
464 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,31))
465  static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen)
466 +#else
467 +static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int optlen)
468 +#endif
469  {
470         struct sock *sk = sock->sk;
471         struct bt_security sec;
472 --- a/net/bluetooth/rfcomm/tty.c
473 +++ b/net/bluetooth/rfcomm/tty.c
474 @@ -731,8 +731,12 @@ static int rfcomm_tty_open(struct tty_st
475         remove_wait_queue(&dev->wait, &wait);
476  
477         if (err == 0)
478 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
479                 device_move(dev->tty_dev, rfcomm_get_device(dev),
480                             DPM_ORDER_DEV_AFTER_PARENT);
481 +#else
482 +               device_move(dev->tty_dev, rfcomm_get_device(dev));
483 +#endif
484  
485         rfcomm_tty_copy_pending(dev);
486  
487 @@ -752,7 +756,11 @@ static void rfcomm_tty_close(struct tty_
488  
489         if (atomic_dec_and_test(&dev->opened)) {
490                 if (dev->tty_dev->parent)
491 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,29))
492                         device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
493 +#else
494 +                       device_move(dev->tty_dev, NULL);
495 +#endif
496  
497                 /* Close DLC and dettach TTY */
498                 rfcomm_dlc_close(dev->dlc, 0);
499 --- a/net/bluetooth/sco.c
500 +++ b/net/bluetooth/sco.c
501 @@ -430,8 +430,12 @@ static struct sock *sco_sock_alloc(struc
502         return sk;
503  }
504  
505 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32))
506  static int sco_sock_create(struct net *net, struct socket *sock, int protocol,
507                            int kern)
508 +#else
509 +static int sco_sock_create(struct net *net, struct socket *sock, int protocol)
510 +#endif
511  {
512         struct sock *sk;
513  
514 @@ -645,7 +649,11 @@ static int sco_sock_sendmsg(struct kiocb
515         return err;
516  }
517  
518 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,31))
519  static int sco_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen)
520 +#else
521 +static int sco_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int optlen)
522 +#endif
523  {
524         struct sock *sk = sock->sk;
525         int err = 0;
526 --- a/net/bluetooth/bnep/sock.c
527 +++ b/net/bluetooth/bnep/sock.c
528 @@ -195,8 +195,12 @@ static struct proto bnep_proto = {
529         .obj_size       = sizeof(struct bt_sock)
530  };
531  
532 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32))
533  static int bnep_sock_create(struct net *net, struct socket *sock, int protocol,
534                             int kern)
535 +#else
536 +static int bnep_sock_create(struct net *net, struct socket *sock, int protocol)
537 +#endif
538  {
539         struct sock *sk;
540  
541 --- a/net/bluetooth/cmtp/sock.c
542 +++ b/net/bluetooth/cmtp/sock.c
543 @@ -190,8 +190,12 @@ static struct proto cmtp_proto = {
544         .obj_size       = sizeof(struct bt_sock)
545  };
546  
547 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32))
548  static int cmtp_sock_create(struct net *net, struct socket *sock, int protocol,
549                             int kern)
550 +#else
551 +static int cmtp_sock_create(struct net *net, struct socket *sock, int protocol)
552 +#endif
553  {
554         struct sock *sk;
555  
556 --- a/net/bluetooth/hidp/sock.c
557 +++ b/net/bluetooth/hidp/sock.c
558 @@ -241,8 +241,12 @@ static struct proto hidp_proto = {
559         .obj_size       = sizeof(struct bt_sock)
560  };
561  
562 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32))
563  static int hidp_sock_create(struct net *net, struct socket *sock, int protocol,
564                             int kern)
565 +#else
566 +static int hidp_sock_create(struct net *net, struct socket *sock, int protocol)
567 +#endif
568  {
569         struct sock *sk;
570  
571 --- a/net/bluetooth/l2cap.c
572 +++ b/net/bluetooth/l2cap.c
573 @@ -822,8 +822,12 @@ static struct sock *l2cap_sock_alloc(str
574         return sk;
575  }
576  
577 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32))
578  static int l2cap_sock_create(struct net *net, struct socket *sock, int protocol,
579                              int kern)
580 +#else
581 +static int l2cap_sock_create(struct net *net, struct socket *sock, int protocol)
582 +#endif
583  {
584         struct sock *sk;
585  
586 @@ -835,7 +839,11 @@ static int l2cap_sock_create(struct net 
587                         sock->type != SOCK_DGRAM && sock->type != SOCK_RAW)
588                 return -ESOCKTNOSUPPORT;
589  
590 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,32))
591         if (sock->type == SOCK_RAW && !kern && !capable(CAP_NET_RAW))
592 +#else
593 +       if (sock->type == SOCK_RAW && !capable(CAP_NET_RAW))
594 +#endif
595                 return -EPERM;
596  
597         sock->ops = &l2cap_sock_ops;
598 @@ -1764,7 +1772,11 @@ static int l2cap_sock_setsockopt_old(str
599         return err;
600  }
601  
602 +#if (LINUX_VERSION_CODE > KERNEL_VERSION(2,6,31))
603  static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, unsigned int optlen)
604 +#else
605 +static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, char __user *optval, int optlen)
606 +#endif
607  {
608         struct sock *sk = sock->sk;
609         struct bt_security sec;