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#include <linux/etherdevice.h>
47#include <linux/skbuff.h>
48#include <linux/wlp.h>
49
50#include "wlp-internal.h"
51
52size_t wlp_wss_key_print(char *buf, size_t bufsize, u8 *key)
53{
54 size_t result;
55
56 result = scnprintf(buf, bufsize,
57 "%02x %02x %02x %02x %02x %02x "
58 "%02x %02x %02x %02x %02x %02x "
59 "%02x %02x %02x %02x",
60 key[0], key[1], key[2], key[3],
61 key[4], key[5], key[6], key[7],
62 key[8], key[9], key[10], key[11],
63 key[12], key[13], key[14], key[15]);
64 return result;
65}
66
67
68
69
70
71
72
73
74static
75u8 wlp_wss_comp_wssid_hash(struct wlp_uuid *wssid)
76{
77 return wssid->data[0] ^ wssid->data[1] ^ wssid->data[2]
78 ^ wssid->data[3] ^ wssid->data[4] ^ wssid->data[5]
79 ^ wssid->data[6] ^ wssid->data[7] ^ wssid->data[8]
80 ^ wssid->data[9] ^ wssid->data[10] ^ wssid->data[11]
81 ^ wssid->data[12] ^ wssid->data[13] ^ wssid->data[14]
82 ^ wssid->data[15];
83}
84
85
86
87
88
89
90
91
92
93
94
95static
96struct uwb_mac_addr wlp_wss_sel_bcast_addr(struct wlp_wss *wss)
97{
98 struct uwb_mac_addr bcast = {
99 .data = { 0x01, 0x13, 0x88, 0x00, 0x01, 0x00 }
100 };
101 return bcast;
102}
103
104
105
106
107
108
109
110
111
112
113
114void wlp_wss_reset(struct wlp_wss *wss)
115{
116 memset(&wss->wssid, 0, sizeof(wss->wssid));
117 wss->hash = 0;
118 memset(&wss->name[0], 0, sizeof(wss->name));
119 memset(&wss->bcast, 0, sizeof(wss->bcast));
120 wss->secure_status = WLP_WSS_UNSECURE;
121 memset(&wss->master_key[0], 0, sizeof(wss->master_key));
122 wss->tag = 0;
123 wss->state = WLP_WSS_STATE_NONE;
124}
125
126
127
128
129
130
131
132
133
134static
135int wlp_wss_sysfs_add(struct wlp_wss *wss, char *wssid_str)
136{
137 struct wlp *wlp = container_of(wss, struct wlp, wss);
138 struct device *dev = &wlp->rc->uwb_dev.dev;
139 int result;
140
141 result = kobject_set_name(&wss->kobj, "wss-%s", wssid_str);
142 if (result < 0)
143 return result;
144 wss->kobj.ktype = &wss_ktype;
145 result = kobject_init_and_add(&wss->kobj,
146 &wss_ktype, wss->kobj.parent, "wlp");
147 if (result < 0) {
148 dev_err(dev, "WLP: Cannot register WSS kobject.\n");
149 goto error_kobject_register;
150 }
151 result = sysfs_create_group(&wss->kobj, &wss_attr_group);
152 if (result < 0) {
153 dev_err(dev, "WLP: Cannot register WSS attributes: %d\n",
154 result);
155 goto error_sysfs_create_group;
156 }
157 return 0;
158error_sysfs_create_group:
159
160 kobject_put(&wss->kobj);
161 return result;
162error_kobject_register:
163 kfree(wss->kobj.name);
164 wss->kobj.name = NULL;
165 wss->kobj.ktype = NULL;
166 return result;
167}
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186void wlp_wss_release(struct kobject *kobj)
187{
188 struct wlp_wss *wss = container_of(kobj, struct wlp_wss, kobj);
189
190 wlp_wss_reset(wss);
191}
192
193
194
195
196
197
198
199
200
201static
202int wlp_wss_enroll_target(struct wlp_wss *wss, struct wlp_uuid *wssid,
203 struct uwb_dev_addr *dest)
204{
205 struct wlp *wlp = container_of(wss, struct wlp, wss);
206 struct device *dev = &wlp->rc->uwb_dev.dev;
207 struct wlp_neighbor_e *neighbor;
208 int result = -ENXIO;
209 struct uwb_dev_addr *dev_addr;
210
211 mutex_lock(&wlp->nbmutex);
212 list_for_each_entry(neighbor, &wlp->neighbors, node) {
213 dev_addr = &neighbor->uwb_dev->dev_addr;
214 if (!memcmp(dest, dev_addr, sizeof(*dest))) {
215 result = wlp_enroll_neighbor(wlp, neighbor, wss, wssid);
216 break;
217 }
218 }
219 if (result == -ENXIO)
220 dev_err(dev, "WLP: Cannot find neighbor %02x:%02x. \n",
221 dest->data[1], dest->data[0]);
222 mutex_unlock(&wlp->nbmutex);
223 return result;
224}
225
226
227
228
229
230
231
232
233
234static
235int wlp_wss_enroll_discovered(struct wlp_wss *wss, struct wlp_uuid *wssid)
236{
237 struct wlp *wlp = container_of(wss, struct wlp, wss);
238 struct device *dev = &wlp->rc->uwb_dev.dev;
239 struct wlp_neighbor_e *neighbor;
240 struct wlp_wssid_e *wssid_e;
241 char buf[WLP_WSS_UUID_STRSIZE];
242 int result = -ENXIO;
243
244
245 mutex_lock(&wlp->nbmutex);
246 list_for_each_entry(neighbor, &wlp->neighbors, node) {
247 list_for_each_entry(wssid_e, &neighbor->wssid, node) {
248 if (!memcmp(wssid, &wssid_e->wssid, sizeof(*wssid))) {
249 result = wlp_enroll_neighbor(wlp, neighbor,
250 wss, wssid);
251 if (result == 0)
252 goto out;
253 break;
254 }
255 }
256 }
257out:
258 if (result == -ENXIO) {
259 wlp_wss_uuid_print(buf, sizeof(buf), wssid);
260 dev_err(dev, "WLP: Cannot find WSSID %s in cache. \n", buf);
261 }
262 mutex_unlock(&wlp->nbmutex);
263 return result;
264}
265
266
267
268
269
270
271
272
273
274
275
276static
277int wlp_wss_enroll(struct wlp_wss *wss, struct wlp_uuid *wssid,
278 struct uwb_dev_addr *devaddr)
279{
280 int result;
281 struct wlp *wlp = container_of(wss, struct wlp, wss);
282 struct device *dev = &wlp->rc->uwb_dev.dev;
283 char buf[WLP_WSS_UUID_STRSIZE];
284 struct uwb_dev_addr bcast = {.data = {0xff, 0xff} };
285
286 wlp_wss_uuid_print(buf, sizeof(buf), wssid);
287
288 if (wss->state != WLP_WSS_STATE_NONE) {
289 dev_err(dev, "WLP: Already enrolled in WSS %s.\n", buf);
290 result = -EEXIST;
291 goto error;
292 }
293 if (!memcmp(&bcast, devaddr, sizeof(bcast)))
294 result = wlp_wss_enroll_discovered(wss, wssid);
295 else
296 result = wlp_wss_enroll_target(wss, wssid, devaddr);
297 if (result < 0) {
298 dev_err(dev, "WLP: Unable to enroll into WSS %s, result %d \n",
299 buf, result);
300 goto error;
301 }
302 dev_dbg(dev, "Successfully enrolled into WSS %s \n", buf);
303 result = wlp_wss_sysfs_add(wss, buf);
304 if (result < 0) {
305 dev_err(dev, "WLP: Unable to set up sysfs for WSS kobject.\n");
306 wlp_wss_reset(wss);
307 }
308error:
309 return result;
310
311}
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326static
327int wlp_wss_activate(struct wlp_wss *wss)
328{
329 struct wlp *wlp = container_of(wss, struct wlp, wss);
330 struct device *dev = &wlp->rc->uwb_dev.dev;
331 struct uwb_rc *uwb_rc = wlp->rc;
332 int result;
333 struct {
334 struct wlp_ie wlp_ie;
335 u8 hash;
336 } ie_data;
337
338 BUG_ON(wss->state != WLP_WSS_STATE_ENROLLED);
339 wss->hash = wlp_wss_comp_wssid_hash(&wss->wssid);
340 wss->tag = wss->hash;
341 memset(&ie_data, 0, sizeof(ie_data));
342 ie_data.wlp_ie.hdr.element_id = UWB_IE_WLP;
343 ie_data.wlp_ie.hdr.length = sizeof(ie_data) - sizeof(struct uwb_ie_hdr);
344 wlp_ie_set_hash_length(&ie_data.wlp_ie, sizeof(ie_data.hash));
345 ie_data.hash = wss->hash;
346 result = uwb_rc_ie_add(uwb_rc, &ie_data.wlp_ie.hdr,
347 sizeof(ie_data));
348 if (result < 0) {
349 dev_err(dev, "WLP: Unable to add WLP IE to beacon. "
350 "result = %d.\n", result);
351 goto error_wlp_ie;
352 }
353 wss->state = WLP_WSS_STATE_ACTIVE;
354 result = 0;
355error_wlp_ie:
356 return result;
357}
358
359
360
361
362
363
364
365
366
367
368
369
370int wlp_wss_enroll_activate(struct wlp_wss *wss, struct wlp_uuid *wssid,
371 struct uwb_dev_addr *devaddr)
372{
373 struct wlp *wlp = container_of(wss, struct wlp, wss);
374 struct device *dev = &wlp->rc->uwb_dev.dev;
375 int result = 0;
376 char buf[WLP_WSS_UUID_STRSIZE];
377
378 mutex_lock(&wss->mutex);
379 result = wlp_wss_enroll(wss, wssid, devaddr);
380 if (result < 0) {
381 wlp_wss_uuid_print(buf, sizeof(buf), &wss->wssid);
382 dev_err(dev, "WLP: Enrollment into WSS %s failed.\n", buf);
383 goto error_enroll;
384 }
385 result = wlp_wss_activate(wss);
386 if (result < 0) {
387 dev_err(dev, "WLP: Unable to activate WSS. Undoing enrollment "
388 "result = %d \n", result);
389
390 wlp_wss_reset(wss);
391 goto error_activate;
392 }
393error_activate:
394error_enroll:
395 mutex_unlock(&wss->mutex);
396 return result;
397}
398
399
400
401
402
403
404
405
406
407
408
409
410
411int wlp_wss_create_activate(struct wlp_wss *wss, struct wlp_uuid *wssid,
412 char *name, unsigned sec_status, unsigned accept)
413{
414 struct wlp *wlp = container_of(wss, struct wlp, wss);
415 struct device *dev = &wlp->rc->uwb_dev.dev;
416 int result = 0;
417 char buf[WLP_WSS_UUID_STRSIZE];
418
419 result = wlp_wss_uuid_print(buf, sizeof(buf), wssid);
420
421 if (!mutex_trylock(&wss->mutex)) {
422 dev_err(dev, "WLP: WLP association session in progress.\n");
423 return -EBUSY;
424 }
425 if (wss->state != WLP_WSS_STATE_NONE) {
426 dev_err(dev, "WLP: WSS already exists. Not creating new.\n");
427 result = -EEXIST;
428 goto out;
429 }
430 if (wss->kobj.parent == NULL) {
431 dev_err(dev, "WLP: WSS parent not ready. Is network interface "
432 "up?\n");
433 result = -ENXIO;
434 goto out;
435 }
436 if (sec_status == WLP_WSS_SECURE) {
437 dev_err(dev, "WLP: FIXME Creation of secure WSS not "
438 "supported yet.\n");
439 result = -EINVAL;
440 goto out;
441 }
442 wss->wssid = *wssid;
443 memcpy(wss->name, name, sizeof(wss->name));
444 wss->bcast = wlp_wss_sel_bcast_addr(wss);
445 wss->secure_status = sec_status;
446 wss->accept_enroll = accept;
447
448
449 result = wlp_wss_sysfs_add(wss, buf);
450 if (result < 0) {
451 dev_err(dev, "Cannot set up sysfs for WSS kobject.\n");
452 wlp_wss_reset(wss);
453 goto out;
454 } else
455 result = 0;
456 wss->state = WLP_WSS_STATE_ENROLLED;
457 result = wlp_wss_activate(wss);
458 if (result < 0) {
459 dev_err(dev, "WLP: Unable to activate WSS. Undoing "
460 "enrollment\n");
461 wlp_wss_reset(wss);
462 goto out;
463 }
464 result = 0;
465out:
466 mutex_unlock(&wss->mutex);
467 return result;
468}
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483int wlp_wss_is_active(struct wlp *wlp, struct wlp_wss *wss,
484 struct uwb_dev_addr *dev_addr)
485{
486 int result = 0;
487 struct device *dev = &wlp->rc->uwb_dev.dev;
488 DECLARE_COMPLETION_ONSTACK(completion);
489 struct wlp_session session;
490 struct sk_buff *skb;
491 struct wlp_frame_assoc *resp;
492 struct wlp_uuid wssid;
493
494 mutex_lock(&wlp->mutex);
495
496 result = wlp_send_assoc_frame(wlp, wss, dev_addr, WLP_ASSOC_C1);
497 if (result < 0) {
498 dev_err(dev, "Unable to send C1 frame to neighbor "
499 "%02x:%02x (%d)\n", dev_addr->data[1],
500 dev_addr->data[0], result);
501 result = 0;
502 goto out;
503 }
504
505 session.exp_message = WLP_ASSOC_C2;
506 session.cb = wlp_session_cb;
507 session.cb_priv = &completion;
508 session.neighbor_addr = *dev_addr;
509 BUG_ON(wlp->session != NULL);
510 wlp->session = &session;
511
512 result = wait_for_completion_interruptible_timeout(&completion,
513 WLP_PER_MSG_TIMEOUT * HZ);
514 if (result == 0) {
515 dev_err(dev, "Timeout while sending C1 to neighbor "
516 "%02x:%02x.\n", dev_addr->data[1],
517 dev_addr->data[0]);
518 goto out;
519 }
520 if (result < 0) {
521 dev_err(dev, "Unable to send C1 to neighbor %02x:%02x.\n",
522 dev_addr->data[1], dev_addr->data[0]);
523 result = 0;
524 goto out;
525 }
526
527 skb = session.data;
528 resp = (void *) skb->data;
529 if (resp->type == WLP_ASSOC_F0) {
530 result = wlp_parse_f0(wlp, skb);
531 if (result < 0)
532 dev_err(dev, "WLP: unable to parse incoming F0 "
533 "frame from neighbor %02x:%02x.\n",
534 dev_addr->data[1], dev_addr->data[0]);
535 result = 0;
536 goto error_resp_parse;
537 }
538
539 result = wlp_get_wssid(wlp, (void *)resp + sizeof(*resp), &wssid,
540 skb->len - sizeof(*resp));
541 if (result < 0) {
542 dev_err(dev, "WLP: unable to obtain WSSID from C2 frame.\n");
543 result = 0;
544 goto error_resp_parse;
545 }
546 if (!memcmp(&wssid, &wss->wssid, sizeof(wssid)))
547 result = 1;
548 else {
549 dev_err(dev, "WLP: Received a C2 frame without matching "
550 "WSSID.\n");
551 result = 0;
552 }
553error_resp_parse:
554 kfree_skb(skb);
555out:
556 wlp->session = NULL;
557 mutex_unlock(&wlp->mutex);
558 return result;
559}
560
561
562
563
564
565
566
567
568
569
570static
571int wlp_wss_activate_connection(struct wlp *wlp, struct wlp_wss *wss,
572 struct uwb_dev_addr *dev_addr,
573 struct wlp_uuid *wssid, u8 *tag,
574 struct uwb_mac_addr *virt_addr)
575{
576 struct device *dev = &wlp->rc->uwb_dev.dev;
577 int result = 0;
578
579 if (!memcmp(wssid, &wss->wssid, sizeof(*wssid))) {
580
581 result = wlp_eda_update_node(&wlp->eda, dev_addr, wss,
582 (void *) virt_addr->data, *tag,
583 WLP_WSS_CONNECTED);
584 if (result < 0)
585 dev_err(dev, "WLP: Unable to update EDA cache "
586 "with new connected neighbor information.\n");
587 } else {
588 dev_err(dev, "WLP: Neighbor does not have matching WSSID.\n");
589 result = -EINVAL;
590 }
591 return result;
592}
593
594
595
596
597
598
599
600static
601int wlp_wss_connect_neighbor(struct wlp *wlp, struct wlp_wss *wss,
602 struct uwb_dev_addr *dev_addr)
603{
604 int result;
605 struct device *dev = &wlp->rc->uwb_dev.dev;
606 struct wlp_uuid wssid;
607 u8 tag;
608 struct uwb_mac_addr virt_addr;
609 DECLARE_COMPLETION_ONSTACK(completion);
610 struct wlp_session session;
611 struct wlp_frame_assoc *resp;
612 struct sk_buff *skb;
613
614 mutex_lock(&wlp->mutex);
615
616 result = wlp_send_assoc_frame(wlp, wss, dev_addr, WLP_ASSOC_C3);
617 if (result < 0) {
618 dev_err(dev, "Unable to send C3 frame to neighbor "
619 "%02x:%02x (%d)\n", dev_addr->data[1],
620 dev_addr->data[0], result);
621 goto out;
622 }
623
624 session.exp_message = WLP_ASSOC_C4;
625 session.cb = wlp_session_cb;
626 session.cb_priv = &completion;
627 session.neighbor_addr = *dev_addr;
628 BUG_ON(wlp->session != NULL);
629 wlp->session = &session;
630
631 result = wait_for_completion_interruptible_timeout(&completion,
632 WLP_PER_MSG_TIMEOUT * HZ);
633 if (result == 0) {
634 dev_err(dev, "Timeout while sending C3 to neighbor "
635 "%02x:%02x.\n", dev_addr->data[1],
636 dev_addr->data[0]);
637 result = -ETIMEDOUT;
638 goto out;
639 }
640 if (result < 0) {
641 dev_err(dev, "Unable to send C3 to neighbor %02x:%02x.\n",
642 dev_addr->data[1], dev_addr->data[0]);
643 goto out;
644 }
645
646 skb = session.data;
647 resp = (void *) skb->data;
648 if (resp->type == WLP_ASSOC_F0) {
649 result = wlp_parse_f0(wlp, skb);
650 if (result < 0)
651 dev_err(dev, "WLP: unable to parse incoming F0 "
652 "frame from neighbor %02x:%02x.\n",
653 dev_addr->data[1], dev_addr->data[0]);
654 result = -EINVAL;
655 goto error_resp_parse;
656 }
657 result = wlp_parse_c3c4_frame(wlp, skb, &wssid, &tag, &virt_addr);
658 if (result < 0) {
659 dev_err(dev, "WLP: Unable to parse C4 frame from neighbor.\n");
660 goto error_resp_parse;
661 }
662 result = wlp_wss_activate_connection(wlp, wss, dev_addr, &wssid, &tag,
663 &virt_addr);
664 if (result < 0) {
665 dev_err(dev, "WLP: Unable to activate connection to "
666 "neighbor %02x:%02x.\n", dev_addr->data[1],
667 dev_addr->data[0]);
668 goto error_resp_parse;
669 }
670error_resp_parse:
671 kfree_skb(skb);
672out:
673
674 if (result < 0)
675 wlp_eda_update_node_state(&wlp->eda, dev_addr,
676 WLP_WSS_CONNECT_FAILED);
677 wlp->session = NULL;
678 mutex_unlock(&wlp->mutex);
679 return result;
680}
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700static
701void wlp_wss_connect_send(struct work_struct *ws)
702{
703 struct wlp_assoc_conn_ctx *conn_ctx = container_of(ws,
704 struct wlp_assoc_conn_ctx,
705 ws);
706 struct wlp *wlp = conn_ctx->wlp;
707 struct sk_buff *skb = conn_ctx->skb;
708 struct wlp_eda_node *eda_entry = &conn_ctx->eda_entry;
709 struct uwb_dev_addr *dev_addr = &eda_entry->dev_addr;
710 struct wlp_wss *wss = &wlp->wss;
711 int result;
712 struct device *dev = &wlp->rc->uwb_dev.dev;
713
714 mutex_lock(&wss->mutex);
715 if (wss->state < WLP_WSS_STATE_ACTIVE) {
716 if (printk_ratelimit())
717 dev_err(dev, "WLP: Attempting to connect with "
718 "WSS that is not active or connected.\n");
719 dev_kfree_skb(skb);
720 goto out;
721 }
722
723 result = wlp_wss_connect_neighbor(wlp, wss, dev_addr);
724 if (result < 0) {
725 if (printk_ratelimit())
726 dev_err(dev, "WLP: Unable to establish connection "
727 "with neighbor %02x:%02x.\n",
728 dev_addr->data[1], dev_addr->data[0]);
729 dev_kfree_skb(skb);
730 goto out;
731 }
732
733 result = wlp_copy_eda_node(&wlp->eda, dev_addr, eda_entry);
734 if (result < 0) {
735 if (printk_ratelimit())
736 dev_err(dev, "WLP: Cannot find EDA entry for "
737 "neighbor %02x:%02x \n",
738 dev_addr->data[1], dev_addr->data[0]);
739 }
740 result = wlp_wss_prep_hdr(wlp, eda_entry, skb);
741 if (result < 0) {
742 if (printk_ratelimit())
743 dev_err(dev, "WLP: Unable to prepare frame header for "
744 "transmission (neighbor %02x:%02x). \n",
745 dev_addr->data[1], dev_addr->data[0]);
746 dev_kfree_skb(skb);
747 goto out;
748 }
749 BUG_ON(wlp->xmit_frame == NULL);
750 result = wlp->xmit_frame(wlp, skb, dev_addr);
751 if (result < 0) {
752 if (printk_ratelimit())
753 dev_err(dev, "WLP: Unable to transmit frame: %d\n",
754 result);
755 if (result == -ENXIO)
756 dev_err(dev, "WLP: Is network interface up? \n");
757
758 dev_kfree_skb(skb);
759 }
760out:
761 kfree(conn_ctx);
762 BUG_ON(wlp->start_queue == NULL);
763 wlp->start_queue(wlp);
764 mutex_unlock(&wss->mutex);
765}
766
767
768
769
770
771
772
773int wlp_wss_prep_hdr(struct wlp *wlp, struct wlp_eda_node *eda_entry,
774 void *_skb)
775{
776 struct device *dev = &wlp->rc->uwb_dev.dev;
777 int result = 0;
778 unsigned char *eth_addr = eda_entry->eth_addr;
779 struct uwb_dev_addr *dev_addr = &eda_entry->dev_addr;
780 struct sk_buff *skb = _skb;
781 struct wlp_frame_std_abbrv_hdr *std_hdr;
782
783 if (eda_entry->state == WLP_WSS_CONNECTED) {
784
785 BUG_ON(skb_headroom(skb) < sizeof(*std_hdr));
786 std_hdr = (void *) __skb_push(skb, sizeof(*std_hdr));
787 std_hdr->hdr.mux_hdr = cpu_to_le16(WLP_PROTOCOL_ID);
788 std_hdr->hdr.type = WLP_FRAME_STANDARD;
789 std_hdr->tag = eda_entry->wss->tag;
790 } else {
791 if (printk_ratelimit())
792 dev_err(dev, "WLP: Destination neighbor (Ethernet: "
793 "%02x:%02x:%02x:%02x:%02x:%02x, Dev: "
794 "%02x:%02x) is not connected. \n", eth_addr[0],
795 eth_addr[1], eth_addr[2], eth_addr[3],
796 eth_addr[4], eth_addr[5], dev_addr->data[1],
797 dev_addr->data[0]);
798 result = -EINVAL;
799 }
800 return result;
801}
802
803
804
805
806
807
808
809
810
811
812
813
814int wlp_wss_connect_prep(struct wlp *wlp, struct wlp_eda_node *eda_entry,
815 void *_skb)
816{
817 int result = 0;
818 struct device *dev = &wlp->rc->uwb_dev.dev;
819 struct sk_buff *skb = _skb;
820 struct wlp_assoc_conn_ctx *conn_ctx;
821
822 if (eda_entry->state == WLP_WSS_UNCONNECTED) {
823
824 BUG_ON(wlp->stop_queue == NULL);
825 wlp->stop_queue(wlp);
826 conn_ctx = kmalloc(sizeof(*conn_ctx), GFP_ATOMIC);
827 if (conn_ctx == NULL) {
828 if (printk_ratelimit())
829 dev_err(dev, "WLP: Unable to allocate memory "
830 "for connection handling.\n");
831 result = -ENOMEM;
832 goto out;
833 }
834 conn_ctx->wlp = wlp;
835 conn_ctx->skb = skb;
836 conn_ctx->eda_entry = *eda_entry;
837 INIT_WORK(&conn_ctx->ws, wlp_wss_connect_send);
838 schedule_work(&conn_ctx->ws);
839 result = 1;
840 } else if (eda_entry->state == WLP_WSS_CONNECT_FAILED) {
841
842
843 if (printk_ratelimit())
844 dev_err(dev, "Could not connect to neighbor "
845 "previously. Not retrying. \n");
846 result = -ENONET;
847 goto out;
848 } else
849 result = wlp_wss_prep_hdr(wlp, eda_entry, skb);
850out:
851 return result;
852}
853
854
855
856
857
858
859
860
861
862
863
864int wlp_wss_send_copy(struct wlp *wlp, struct wlp_eda_node *eda_entry,
865 void *_skb)
866{
867 int result = -ENOMEM;
868 struct device *dev = &wlp->rc->uwb_dev.dev;
869 struct sk_buff *skb = _skb;
870 struct sk_buff *copy;
871 struct uwb_dev_addr *dev_addr = &eda_entry->dev_addr;
872
873 copy = skb_copy(skb, GFP_ATOMIC);
874 if (copy == NULL) {
875 if (printk_ratelimit())
876 dev_err(dev, "WLP: Unable to copy skb for "
877 "transmission.\n");
878 goto out;
879 }
880 result = wlp_wss_connect_prep(wlp, eda_entry, copy);
881 if (result < 0) {
882 if (printk_ratelimit())
883 dev_err(dev, "WLP: Unable to connect/send skb "
884 "to neighbor.\n");
885 dev_kfree_skb_irq(copy);
886 goto out;
887 } else if (result == 1)
888
889 goto out;
890 BUG_ON(wlp->xmit_frame == NULL);
891 result = wlp->xmit_frame(wlp, copy, dev_addr);
892 if (result < 0) {
893 if (printk_ratelimit())
894 dev_err(dev, "WLP: Unable to transmit frame: %d\n",
895 result);
896 if ((result == -ENXIO) && printk_ratelimit())
897 dev_err(dev, "WLP: Is network interface up? \n");
898
899 dev_kfree_skb_irq(copy);
900 }
901out:
902 return result;
903}
904
905
906
907
908
909
910
911
912int wlp_wss_setup(struct net_device *net_dev, struct wlp_wss *wss)
913{
914 struct wlp *wlp = container_of(wss, struct wlp, wss);
915 struct device *dev = &wlp->rc->uwb_dev.dev;
916 int result = 0;
917
918 mutex_lock(&wss->mutex);
919 wss->kobj.parent = &net_dev->dev.kobj;
920 if (!is_valid_ether_addr(net_dev->dev_addr)) {
921 dev_err(dev, "WLP: Invalid MAC address. Cannot use for"
922 "virtual.\n");
923 result = -EINVAL;
924 goto out;
925 }
926 memcpy(wss->virtual_addr.data, net_dev->dev_addr,
927 sizeof(wss->virtual_addr.data));
928out:
929 mutex_unlock(&wss->mutex);
930 return result;
931}
932EXPORT_SYMBOL_GPL(wlp_wss_setup);
933
934
935
936
937
938
939
940
941
942
943void wlp_wss_remove(struct wlp_wss *wss)
944{
945 struct wlp *wlp = container_of(wss, struct wlp, wss);
946
947 mutex_lock(&wss->mutex);
948 if (wss->state == WLP_WSS_STATE_ACTIVE)
949 uwb_rc_ie_rm(wlp->rc, UWB_IE_WLP);
950 if (wss->state != WLP_WSS_STATE_NONE) {
951 sysfs_remove_group(&wss->kobj, &wss_attr_group);
952 kobject_put(&wss->kobj);
953 }
954 wss->kobj.parent = NULL;
955 memset(&wss->virtual_addr, 0, sizeof(wss->virtual_addr));
956
957 wlp_eda_release(&wlp->eda);
958 wlp_eda_init(&wlp->eda);
959 mutex_unlock(&wss->mutex);
960}
961EXPORT_SYMBOL_GPL(wlp_wss_remove);
962