This source file includes following definitions.
- uwbd_event_handle_urc
- uwbd_event_handle_message
- uwbd_event_handle
- uwbd
- uwbd_start
- uwbd_stop
- uwbd_event_queue
- uwbd_flush
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 #include <linux/kthread.h>
58 #include <linux/slab.h>
59 #include <linux/module.h>
60 #include <linux/freezer.h>
61
62 #include "uwb-internal.h"
63
64
65
66
67
68
69
70
71
72
73
74 typedef int (*uwbd_evt_handler_f)(struct uwb_event *);
75
76
77
78
79
80
81
82 struct uwbd_event {
83 uwbd_evt_handler_f handler;
84 const char *name;
85 };
86
87
88 static struct uwbd_event uwbd_urc_events[] = {
89 [UWB_RC_EVT_IE_RCV] = {
90 .handler = uwbd_evt_handle_rc_ie_rcv,
91 .name = "IE_RECEIVED"
92 },
93 [UWB_RC_EVT_BEACON] = {
94 .handler = uwbd_evt_handle_rc_beacon,
95 .name = "BEACON_RECEIVED"
96 },
97 [UWB_RC_EVT_BEACON_SIZE] = {
98 .handler = uwbd_evt_handle_rc_beacon_size,
99 .name = "BEACON_SIZE_CHANGE"
100 },
101 [UWB_RC_EVT_BPOIE_CHANGE] = {
102 .handler = uwbd_evt_handle_rc_bpoie_change,
103 .name = "BPOIE_CHANGE"
104 },
105 [UWB_RC_EVT_BP_SLOT_CHANGE] = {
106 .handler = uwbd_evt_handle_rc_bp_slot_change,
107 .name = "BP_SLOT_CHANGE"
108 },
109 [UWB_RC_EVT_DRP_AVAIL] = {
110 .handler = uwbd_evt_handle_rc_drp_avail,
111 .name = "DRP_AVAILABILITY_CHANGE"
112 },
113 [UWB_RC_EVT_DRP] = {
114 .handler = uwbd_evt_handle_rc_drp,
115 .name = "DRP"
116 },
117 [UWB_RC_EVT_DEV_ADDR_CONFLICT] = {
118 .handler = uwbd_evt_handle_rc_dev_addr_conflict,
119 .name = "DEV_ADDR_CONFLICT",
120 },
121 };
122
123
124
125 struct uwbd_evt_type_handler {
126 const char *name;
127 struct uwbd_event *uwbd_events;
128 size_t size;
129 };
130
131
132 static struct uwbd_evt_type_handler uwbd_urc_evt_type_handlers[] = {
133 [UWB_RC_CET_GENERAL] = {
134 .name = "URC",
135 .uwbd_events = uwbd_urc_events,
136 .size = ARRAY_SIZE(uwbd_urc_events),
137 },
138 };
139
140 static const struct uwbd_event uwbd_message_handlers[] = {
141 [UWB_EVT_MSG_RESET] = {
142 .handler = uwbd_msg_handle_reset,
143 .name = "reset",
144 },
145 };
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164 static
165 int uwbd_event_handle_urc(struct uwb_event *evt)
166 {
167 int result = -EINVAL;
168 struct uwbd_evt_type_handler *type_table;
169 uwbd_evt_handler_f handler;
170 u8 type, context;
171 u16 event;
172
173 type = evt->notif.rceb->bEventType;
174 event = le16_to_cpu(evt->notif.rceb->wEvent);
175 context = evt->notif.rceb->bEventContext;
176
177 if (type >= ARRAY_SIZE(uwbd_urc_evt_type_handlers))
178 goto out;
179 type_table = &uwbd_urc_evt_type_handlers[type];
180 if (type_table->uwbd_events == NULL)
181 goto out;
182 if (event >= type_table->size)
183 goto out;
184 handler = type_table->uwbd_events[event].handler;
185 if (handler == NULL)
186 goto out;
187
188 result = (*handler)(evt);
189 out:
190 if (result < 0)
191 dev_err(&evt->rc->uwb_dev.dev,
192 "UWBD: event 0x%02x/%04x/%02x, handling failed: %d\n",
193 type, event, context, result);
194 return result;
195 }
196
197 static void uwbd_event_handle_message(struct uwb_event *evt)
198 {
199 struct uwb_rc *rc;
200 int result;
201
202 rc = evt->rc;
203
204 if (evt->message < 0 || evt->message >= ARRAY_SIZE(uwbd_message_handlers)) {
205 dev_err(&rc->uwb_dev.dev, "UWBD: invalid message type %d\n", evt->message);
206 return;
207 }
208
209 result = uwbd_message_handlers[evt->message].handler(evt);
210 if (result < 0)
211 dev_err(&rc->uwb_dev.dev, "UWBD: '%s' message failed: %d\n",
212 uwbd_message_handlers[evt->message].name, result);
213 }
214
215 static void uwbd_event_handle(struct uwb_event *evt)
216 {
217 struct uwb_rc *rc;
218 int should_keep;
219
220 rc = evt->rc;
221
222 if (rc->ready) {
223 switch (evt->type) {
224 case UWB_EVT_TYPE_NOTIF:
225 should_keep = uwbd_event_handle_urc(evt);
226 if (should_keep <= 0)
227 kfree(evt->notif.rceb);
228 break;
229 case UWB_EVT_TYPE_MSG:
230 uwbd_event_handle_message(evt);
231 break;
232 default:
233 dev_err(&rc->uwb_dev.dev, "UWBD: invalid event type %d\n", evt->type);
234 break;
235 }
236 }
237
238 __uwb_rc_put(rc);
239 }
240
241
242
243
244
245
246
247
248
249
250
251
252
253 static int uwbd(void *param)
254 {
255 struct uwb_rc *rc = param;
256 unsigned long flags;
257 struct uwb_event *evt;
258 int should_stop = 0;
259
260 while (1) {
261 wait_event_interruptible_timeout(
262 rc->uwbd.wq,
263 !list_empty(&rc->uwbd.event_list)
264 || (should_stop = kthread_should_stop()),
265 HZ);
266 if (should_stop)
267 break;
268
269 spin_lock_irqsave(&rc->uwbd.event_list_lock, flags);
270 if (!list_empty(&rc->uwbd.event_list)) {
271 evt = list_first_entry(&rc->uwbd.event_list, struct uwb_event, list_node);
272 list_del(&evt->list_node);
273 } else
274 evt = NULL;
275 spin_unlock_irqrestore(&rc->uwbd.event_list_lock, flags);
276
277 if (evt) {
278 uwbd_event_handle(evt);
279 kfree(evt);
280 }
281
282 uwb_beca_purge(rc);
283 }
284 return 0;
285 }
286
287
288
289 void uwbd_start(struct uwb_rc *rc)
290 {
291 struct task_struct *task = kthread_run(uwbd, rc, "uwbd");
292 if (IS_ERR(task)) {
293 rc->uwbd.task = NULL;
294 printk(KERN_ERR "UWB: Cannot start management daemon; "
295 "UWB won't work\n");
296 } else {
297 rc->uwbd.task = task;
298 rc->uwbd.pid = rc->uwbd.task->pid;
299 }
300 }
301
302
303 void uwbd_stop(struct uwb_rc *rc)
304 {
305 if (rc->uwbd.task)
306 kthread_stop(rc->uwbd.task);
307 uwbd_flush(rc);
308 }
309
310
311
312
313
314
315
316
317
318
319
320
321
322 void uwbd_event_queue(struct uwb_event *evt)
323 {
324 struct uwb_rc *rc = evt->rc;
325 unsigned long flags;
326
327 spin_lock_irqsave(&rc->uwbd.event_list_lock, flags);
328 if (rc->uwbd.pid != 0) {
329 list_add(&evt->list_node, &rc->uwbd.event_list);
330 wake_up_all(&rc->uwbd.wq);
331 } else {
332 __uwb_rc_put(evt->rc);
333 if (evt->type == UWB_EVT_TYPE_NOTIF)
334 kfree(evt->notif.rceb);
335 kfree(evt);
336 }
337 spin_unlock_irqrestore(&rc->uwbd.event_list_lock, flags);
338 return;
339 }
340
341 void uwbd_flush(struct uwb_rc *rc)
342 {
343 struct uwb_event *evt, *nxt;
344
345 spin_lock_irq(&rc->uwbd.event_list_lock);
346 list_for_each_entry_safe(evt, nxt, &rc->uwbd.event_list, list_node) {
347 if (evt->rc == rc) {
348 __uwb_rc_put(rc);
349 list_del(&evt->list_node);
350 if (evt->type == UWB_EVT_TYPE_NOTIF)
351 kfree(evt->notif.rceb);
352 kfree(evt);
353 }
354 }
355 spin_unlock_irq(&rc->uwbd.event_list_lock);
356 }