wl1251: prevent scan when connected
[pandora-wifi.git] / compat / compat-2.6.33.c
1 /*
2  * Copyright 2009       Hauke Mehrtens <hauke@hauke-m.de>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * Compatibility file for Linux wireless for kernels 2.6.33.
9  */
10
11 #include <linux/compat.h>
12
13 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33))
14
15 #include <linux/autoconf.h>
16
17 #if defined(CONFIG_PCCARD) || defined(CONFIG_PCCARD_MODULE)
18
19 /**
20  * pccard_loop_tuple() - loop over tuples in the CIS
21  * @s:          the struct pcmcia_socket where the card is inserted
22  * @function:   the device function we loop for
23  * @code:       which CIS code shall we look for?
24  * @parse:      buffer where the tuple shall be parsed (or NULL, if no parse)
25  * @priv_data:  private data to be passed to the loop_tuple function.
26  * @loop_tuple: function to call for each CIS entry of type @function. IT
27  *              gets passed the raw tuple, the paresed tuple (if @parse is
28  *              set) and @priv_data.
29  *
30  * pccard_loop_tuple() loops over all CIS entries of type @function, and
31  * calls the @loop_tuple function for each entry. If the call to @loop_tuple
32  * returns 0, the loop exits. Returns 0 on success or errorcode otherwise.
33  */
34 int pccard_loop_tuple(struct pcmcia_socket *s, unsigned int function,
35                       cisdata_t code, cisparse_t *parse, void *priv_data,
36                       int (*loop_tuple) (tuple_t *tuple,
37                                          cisparse_t *parse,
38                                          void *priv_data))
39 {
40         tuple_t tuple;
41         cisdata_t *buf;
42         int ret;
43
44         buf = kzalloc(256, GFP_KERNEL);
45         if (buf == NULL) {
46                 dev_printk(KERN_WARNING, &s->dev, "no memory to read tuple\n");
47                 return -ENOMEM;
48         }
49
50         tuple.TupleData = buf;
51         tuple.TupleDataMax = 255;
52         tuple.TupleOffset = 0;
53         tuple.DesiredTuple = code;
54         tuple.Attributes = 0;
55
56         ret = pccard_get_first_tuple(s, function, &tuple);
57         while (!ret) {
58                 if (pccard_get_tuple_data(s, &tuple))
59                         goto next_entry;
60
61                 if (parse)
62                         if (pcmcia_parse_tuple(&tuple, parse))
63                                 goto next_entry;
64
65                 ret = loop_tuple(&tuple, parse, priv_data);
66                 if (!ret)
67                         break;
68
69 next_entry:
70                 ret = pccard_get_next_tuple(s, function, &tuple);
71         }
72
73         kfree(buf);
74         return ret;
75 }
76 EXPORT_SYMBOL(pccard_loop_tuple);
77 /* Source: drivers/pcmcia/cistpl.c */
78
79 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
80
81 struct pcmcia_loop_mem {
82         struct pcmcia_device *p_dev;
83         void *priv_data;
84         int (*loop_tuple) (struct pcmcia_device *p_dev,
85                            tuple_t *tuple,
86                            void *priv_data);
87 };
88
89 /**
90  * pcmcia_do_loop_tuple() - internal helper for pcmcia_loop_config()
91  *
92  * pcmcia_do_loop_tuple() is the internal callback for the call from
93  * pcmcia_loop_tuple() to pccard_loop_tuple(). Data is transferred
94  * by a struct pcmcia_cfg_mem.
95  */
96 static int pcmcia_do_loop_tuple(tuple_t *tuple, cisparse_t *parse, void *priv)
97 {
98         struct pcmcia_loop_mem *loop = priv;
99
100         return loop->loop_tuple(loop->p_dev, tuple, loop->priv_data);
101 };
102
103 /**
104  * pcmcia_loop_tuple() - loop over tuples in the CIS
105  * @p_dev:      the struct pcmcia_device which we need to loop for.
106  * @code:       which CIS code shall we look for?
107  * @priv_data:  private data to be passed to the loop_tuple function.
108  * @loop_tuple: function to call for each CIS entry of type @function. IT
109  *              gets passed the raw tuple and @priv_data.
110  *
111  * pcmcia_loop_tuple() loops over all CIS entries of type @function, and
112  * calls the @loop_tuple function for each entry. If the call to @loop_tuple
113  * returns 0, the loop exits. Returns 0 on success or errorcode otherwise.
114  */
115 int pcmcia_loop_tuple(struct pcmcia_device *p_dev, cisdata_t code,
116                       int (*loop_tuple) (struct pcmcia_device *p_dev,
117                                          tuple_t *tuple,
118                                          void *priv_data),
119                       void *priv_data)
120 {
121         struct pcmcia_loop_mem loop = {
122                 .p_dev = p_dev,
123                 .loop_tuple = loop_tuple,
124                 .priv_data = priv_data};
125
126         return pccard_loop_tuple(p_dev->socket, p_dev->func, code, NULL,
127                                  &loop, pcmcia_do_loop_tuple);
128 }
129 EXPORT_SYMBOL(pcmcia_loop_tuple);
130 /* Source: drivers/pcmcia/pcmcia_resource.c */
131
132 #endif /* CONFIG_PCMCIA */
133
134 #endif /* CONFIG_PCCARD */
135
136 #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33)) */
137