1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63#include <net/wimax.h>
64#include <net/genetlink.h>
65#include <linux/wimax.h>
66#include <linux/security.h>
67#include <linux/rfkill.h>
68#include "wimax-internal.h"
69
70#define D_SUBMODULE op_rfkill
71#include "debug-levels.h"
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92void wimax_report_rfkill_hw(struct wimax_dev *wimax_dev,
93 enum wimax_rf_state state)
94{
95 int result;
96 struct device *dev = wimax_dev_to_dev(wimax_dev);
97 enum wimax_st wimax_state;
98
99 d_fnstart(3, dev, "(wimax_dev %p state %u)\n", wimax_dev, state);
100 BUG_ON(state == WIMAX_RF_QUERY);
101 BUG_ON(state != WIMAX_RF_ON && state != WIMAX_RF_OFF);
102
103 mutex_lock(&wimax_dev->mutex);
104 result = wimax_dev_is_ready(wimax_dev);
105 if (result < 0)
106 goto error_not_ready;
107
108 if (state != wimax_dev->rf_hw) {
109 wimax_dev->rf_hw = state;
110 if (wimax_dev->rf_hw == WIMAX_RF_ON
111 && wimax_dev->rf_sw == WIMAX_RF_ON)
112 wimax_state = WIMAX_ST_READY;
113 else
114 wimax_state = WIMAX_ST_RADIO_OFF;
115
116 result = rfkill_set_hw_state(wimax_dev->rfkill,
117 state == WIMAX_RF_OFF);
118
119 __wimax_state_change(wimax_dev, wimax_state);
120 }
121error_not_ready:
122 mutex_unlock(&wimax_dev->mutex);
123 d_fnend(3, dev, "(wimax_dev %p state %u) = void [%d]\n",
124 wimax_dev, state, result);
125}
126EXPORT_SYMBOL_GPL(wimax_report_rfkill_hw);
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148void wimax_report_rfkill_sw(struct wimax_dev *wimax_dev,
149 enum wimax_rf_state state)
150{
151 int result;
152 struct device *dev = wimax_dev_to_dev(wimax_dev);
153 enum wimax_st wimax_state;
154
155 d_fnstart(3, dev, "(wimax_dev %p state %u)\n", wimax_dev, state);
156 BUG_ON(state == WIMAX_RF_QUERY);
157 BUG_ON(state != WIMAX_RF_ON && state != WIMAX_RF_OFF);
158
159 mutex_lock(&wimax_dev->mutex);
160 result = wimax_dev_is_ready(wimax_dev);
161 if (result < 0)
162 goto error_not_ready;
163
164 if (state != wimax_dev->rf_sw) {
165 wimax_dev->rf_sw = state;
166 if (wimax_dev->rf_hw == WIMAX_RF_ON
167 && wimax_dev->rf_sw == WIMAX_RF_ON)
168 wimax_state = WIMAX_ST_READY;
169 else
170 wimax_state = WIMAX_ST_RADIO_OFF;
171 __wimax_state_change(wimax_dev, wimax_state);
172 rfkill_set_sw_state(wimax_dev->rfkill, state == WIMAX_RF_OFF);
173 }
174error_not_ready:
175 mutex_unlock(&wimax_dev->mutex);
176 d_fnend(3, dev, "(wimax_dev %p state %u) = void [%d]\n",
177 wimax_dev, state, result);
178}
179EXPORT_SYMBOL_GPL(wimax_report_rfkill_sw);
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204static
205int __wimax_rf_toggle_radio(struct wimax_dev *wimax_dev,
206 enum wimax_rf_state state)
207{
208 int result = 0;
209 struct device *dev = wimax_dev_to_dev(wimax_dev);
210 enum wimax_st wimax_state;
211
212 might_sleep();
213 d_fnstart(3, dev, "(wimax_dev %p state %u)\n", wimax_dev, state);
214 if (wimax_dev->rf_sw == state)
215 goto out_no_change;
216 if (wimax_dev->op_rfkill_sw_toggle != NULL)
217 result = wimax_dev->op_rfkill_sw_toggle(wimax_dev, state);
218 else if (state == WIMAX_RF_OFF)
219 result = -ENXIO;
220 else
221 result = 0;
222 if (result >= 0) {
223 result = 0;
224 wimax_dev->rf_sw = state;
225 wimax_state = state == WIMAX_RF_ON ?
226 WIMAX_ST_READY : WIMAX_ST_RADIO_OFF;
227 __wimax_state_change(wimax_dev, wimax_state);
228 }
229out_no_change:
230 d_fnend(3, dev, "(wimax_dev %p state %u) = %d\n",
231 wimax_dev, state, result);
232 return result;
233}
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248static int wimax_rfkill_set_radio_block(void *data, bool blocked)
249{
250 int result;
251 struct wimax_dev *wimax_dev = data;
252 struct device *dev = wimax_dev_to_dev(wimax_dev);
253 enum wimax_rf_state rf_state;
254
255 d_fnstart(3, dev, "(wimax_dev %p blocked %u)\n", wimax_dev, blocked);
256 rf_state = WIMAX_RF_ON;
257 if (blocked)
258 rf_state = WIMAX_RF_OFF;
259 mutex_lock(&wimax_dev->mutex);
260 if (wimax_dev->state <= __WIMAX_ST_QUIESCING)
261 result = 0;
262 else
263 result = __wimax_rf_toggle_radio(wimax_dev, rf_state);
264 mutex_unlock(&wimax_dev->mutex);
265 d_fnend(3, dev, "(wimax_dev %p blocked %u) = %d\n",
266 wimax_dev, blocked, result);
267 return result;
268}
269
270static const struct rfkill_ops wimax_rfkill_ops = {
271 .set_block = wimax_rfkill_set_radio_block,
272};
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300int wimax_rfkill(struct wimax_dev *wimax_dev, enum wimax_rf_state state)
301{
302 int result;
303 struct device *dev = wimax_dev_to_dev(wimax_dev);
304
305 d_fnstart(3, dev, "(wimax_dev %p state %u)\n", wimax_dev, state);
306 mutex_lock(&wimax_dev->mutex);
307 result = wimax_dev_is_ready(wimax_dev);
308 if (result < 0)
309 goto error_not_ready;
310 switch (state) {
311 case WIMAX_RF_ON:
312 case WIMAX_RF_OFF:
313 result = __wimax_rf_toggle_radio(wimax_dev, state);
314 if (result < 0)
315 goto error;
316 rfkill_set_sw_state(wimax_dev->rfkill, state == WIMAX_RF_OFF);
317 break;
318 case WIMAX_RF_QUERY:
319 break;
320 default:
321 result = -EINVAL;
322 goto error;
323 }
324 result = wimax_dev->rf_sw << 1 | wimax_dev->rf_hw;
325error:
326error_not_ready:
327 mutex_unlock(&wimax_dev->mutex);
328 d_fnend(3, dev, "(wimax_dev %p state %u) = %d\n",
329 wimax_dev, state, result);
330 return result;
331}
332EXPORT_SYMBOL(wimax_rfkill);
333
334
335
336
337
338
339
340int wimax_rfkill_add(struct wimax_dev *wimax_dev)
341{
342 int result;
343 struct rfkill *rfkill;
344 struct device *dev = wimax_dev_to_dev(wimax_dev);
345
346 d_fnstart(3, dev, "(wimax_dev %p)\n", wimax_dev);
347
348 result = -ENOMEM;
349 rfkill = rfkill_alloc(wimax_dev->name, dev, RFKILL_TYPE_WIMAX,
350 &wimax_rfkill_ops, wimax_dev);
351 if (rfkill == NULL)
352 goto error_rfkill_allocate;
353
354 d_printf(1, dev, "rfkill %p\n", rfkill);
355
356 wimax_dev->rfkill = rfkill;
357
358 result = rfkill_register(wimax_dev->rfkill);
359 if (result < 0)
360 goto error_rfkill_register;
361
362
363 if (wimax_dev->op_rfkill_sw_toggle == NULL)
364 wimax_dev->rf_sw = WIMAX_RF_ON;
365
366 d_fnend(3, dev, "(wimax_dev %p) = 0\n", wimax_dev);
367 return 0;
368
369error_rfkill_register:
370 rfkill_destroy(wimax_dev->rfkill);
371error_rfkill_allocate:
372 d_fnend(3, dev, "(wimax_dev %p) = %d\n", wimax_dev, result);
373 return result;
374}
375
376
377
378
379
380
381
382
383
384
385void wimax_rfkill_rm(struct wimax_dev *wimax_dev)
386{
387 struct device *dev = wimax_dev_to_dev(wimax_dev);
388 d_fnstart(3, dev, "(wimax_dev %p)\n", wimax_dev);
389 rfkill_unregister(wimax_dev->rfkill);
390 rfkill_destroy(wimax_dev->rfkill);
391 d_fnend(3, dev, "(wimax_dev %p)\n", wimax_dev);
392}
393
394
395
396
397
398
399
400
401
402
403
404
405static const
406struct nla_policy wimax_gnl_rfkill_policy[WIMAX_GNL_ATTR_MAX + 1] = {
407 [WIMAX_GNL_RFKILL_IFIDX] = {
408 .type = NLA_U32,
409 },
410 [WIMAX_GNL_RFKILL_STATE] = {
411 .type = NLA_U32
412 },
413};
414
415
416static
417int wimax_gnl_doit_rfkill(struct sk_buff *skb, struct genl_info *info)
418{
419 int result, ifindex;
420 struct wimax_dev *wimax_dev;
421 struct device *dev;
422 enum wimax_rf_state new_state;
423
424 d_fnstart(3, NULL, "(skb %p info %p)\n", skb, info);
425 result = -ENODEV;
426 if (info->attrs[WIMAX_GNL_RFKILL_IFIDX] == NULL) {
427 printk(KERN_ERR "WIMAX_GNL_OP_RFKILL: can't find IFIDX "
428 "attribute\n");
429 goto error_no_wimax_dev;
430 }
431 ifindex = nla_get_u32(info->attrs[WIMAX_GNL_RFKILL_IFIDX]);
432 wimax_dev = wimax_dev_get_by_genl_info(info, ifindex);
433 if (wimax_dev == NULL)
434 goto error_no_wimax_dev;
435 dev = wimax_dev_to_dev(wimax_dev);
436 result = -EINVAL;
437 if (info->attrs[WIMAX_GNL_RFKILL_STATE] == NULL) {
438 dev_err(dev, "WIMAX_GNL_RFKILL: can't find RFKILL_STATE "
439 "attribute\n");
440 goto error_no_pid;
441 }
442 new_state = nla_get_u32(info->attrs[WIMAX_GNL_RFKILL_STATE]);
443
444
445 result = wimax_rfkill(wimax_dev, new_state);
446error_no_pid:
447 dev_put(wimax_dev->net_dev);
448error_no_wimax_dev:
449 d_fnend(3, NULL, "(skb %p info %p) = %d\n", skb, info, result);
450 return result;
451}
452
453
454struct genl_ops wimax_gnl_rfkill = {
455 .cmd = WIMAX_GNL_OP_RFKILL,
456 .flags = GENL_ADMIN_PERM,
457 .policy = wimax_gnl_rfkill_policy,
458 .doit = wimax_gnl_doit_rfkill,
459 .dumpit = NULL,
460};
461
462