2 * WiMedia Logical Link Control Protocol (WLP)
4 * Copyright (C) 2007 Intel Corporation
5 * Reinette Chatre <reinette.chatre@intel.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License version
9 * 2 as published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 * Implementation of the WLP association protocol.
26 * A UWB network interface will configure a WSS through wlp_wss_setup() after
27 * the interface has been assigned a MAC address, typically after
28 * "ifconfig" has been called. When the interface goes down it should call
31 * When the WSS is ready for use the user interacts via sysfs to create,
32 * discover, and activate WSS.
34 * wlp_wss_enroll_activate()
36 * wlp_wss_create_activate()
37 * wlp_wss_set_wssid_hash()
38 * wlp_wss_comp_wssid_hash()
39 * wlp_wss_sel_bcast_addr()
42 * Called when no more references to WSS exist:
46 #include <linux/etherdevice.h> /* for is_valid_ether_addr */
47 #include <linux/skbuff.h>
48 #include <linux/wlp.h>
50 #include "wlp-internal.h"
52 size_t wlp_wss_key_print(char *buf, size_t bufsize, u8 *key)
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]);
69 * WLP Draft 0.99 [7.2.1]
71 * The WSSID hash for a WSSID is the result of an octet-wise exclusive-OR
72 * of all octets in the WSSID.
75 u8 wlp_wss_comp_wssid_hash(struct wlp_uuid *wssid)
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]
86 * Select a multicast EUI-48 for the WSS broadcast address.
87 * WLP Draft 0.99 [7.2.1]
89 * Selected based on the WiMedia Alliance OUI, 00-13-88, within the WLP
90 * range, [01-13-88-00-01-00, 01-13-88-00-01-FF] inclusive.
92 * This address is currently hardcoded.
96 struct uwb_mac_addr wlp_wss_sel_bcast_addr(struct wlp_wss *wss)
98 struct uwb_mac_addr bcast = {
99 .data = { 0x01, 0x13, 0x88, 0x00, 0x01, 0x00 }
105 * Clear the contents of the WSS structure - all except kobj, mutex, virtual
107 * We do not want to reinitialize - the internal kobj should not change as
108 * it still points to the parent received during setup. The mutex should
109 * remain also. We thus just reset values individually.
110 * The virutal address assigned to WSS will remain the same for the
111 * lifetime of the WSS. We only reset the fields that can change during its
114 void wlp_wss_reset(struct wlp_wss *wss)
116 memset(&wss->wssid, 0, sizeof(wss->wssid));
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));
123 wss->state = WLP_WSS_STATE_NONE;
127 * Create sysfs infrastructure for WSS
129 * The WSS is configured to have the interface as parent (see wlp_wss_setup())
130 * a new sysfs directory that includes wssid as its name is created in the
131 * interface's sysfs directory. The group of files interacting with WSS are
135 int wlp_wss_sysfs_add(struct wlp_wss *wss, char *wssid_str)
137 struct wlp *wlp = container_of(wss, struct wlp, wss);
138 struct device *dev = &wlp->rc->uwb_dev.dev;
141 result = kobject_set_name(&wss->kobj, "wss-%s", wssid_str);
144 wss->kobj.ktype = &wss_ktype;
145 result = kobject_init_and_add(&wss->kobj,
146 &wss_ktype, wss->kobj.parent, "wlp");
148 dev_err(dev, "WLP: Cannot register WSS kobject.\n");
149 goto error_kobject_register;
151 result = sysfs_create_group(&wss->kobj, &wss_attr_group);
153 dev_err(dev, "WLP: Cannot register WSS attributes: %d\n",
155 goto error_sysfs_create_group;
158 error_sysfs_create_group:
160 kobject_put(&wss->kobj); /* will free name if needed */
162 error_kobject_register:
163 kfree(wss->kobj.name);
164 wss->kobj.name = NULL;
165 wss->kobj.ktype = NULL;
173 * No more references exist to this WSS. We should undo everything that was
174 * done in wlp_wss_create_activate() except removing the group. The group
175 * is not removed because an object can be unregistered before the group is
176 * created. We also undo any additional operations on the WSS after this
177 * (addition of members).
179 * If memory was allocated for the kobject's name then it will
180 * be freed by the kobject system during this time.
182 * The EDA cache is removed and reinitilized when the WSS is removed. We
183 * thus loose knowledge of members of this WSS at that time and need not do
186 void wlp_wss_release(struct kobject *kobj)
188 struct wlp_wss *wss = container_of(kobj, struct wlp_wss, kobj);
194 * Enroll into a WSS using provided neighbor as registrar
196 * First search the neighborhood information to learn which neighbor is
197 * referred to, next proceed with enrollment.
199 * &wss->mutex is held
202 int wlp_wss_enroll_target(struct wlp_wss *wss, struct wlp_uuid *wssid,
203 struct uwb_dev_addr *dest)
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;
209 struct uwb_dev_addr *dev_addr;
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);
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);
227 * Enroll into a WSS previously discovered
229 * User provides WSSID of WSS, search for neighbor that has this WSS
230 * activated and attempt to enroll.
232 * &wss->mutex is held
235 int wlp_wss_enroll_discovered(struct wlp_wss *wss, struct wlp_uuid *wssid)
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];
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,
251 if (result == 0) /* enrollment success */
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);
262 mutex_unlock(&wlp->nbmutex);
267 * Enroll into WSS with provided WSSID, registrar may be provided
269 * @wss: out WSS that will be enrolled
270 * @wssid: wssid of neighboring WSS that we want to enroll in
271 * @devaddr: registrar can be specified, will be broadcast (ff:ff) if any
272 * neighbor can be used as registrar.
274 * &wss->mutex is held
277 int wlp_wss_enroll(struct wlp_wss *wss, struct wlp_uuid *wssid,
278 struct uwb_dev_addr *devaddr)
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} };
286 wlp_wss_uuid_print(buf, sizeof(buf), wssid);
288 if (wss->state != WLP_WSS_STATE_NONE) {
289 dev_err(dev, "WLP: Already enrolled in WSS %s.\n", buf);
293 if (!memcmp(&bcast, devaddr, sizeof(bcast)))
294 result = wlp_wss_enroll_discovered(wss, wssid);
296 result = wlp_wss_enroll_target(wss, wssid, devaddr);
298 dev_err(dev, "WLP: Unable to enroll into WSS %s, result %d \n",
302 dev_dbg(dev, "Successfully enrolled into WSS %s \n", buf);
303 result = wlp_wss_sysfs_add(wss, buf);
305 dev_err(dev, "WLP: Unable to set up sysfs for WSS kobject.\n");
316 * Prior to activation a WSS must be enrolled. To activate a WSS a device
317 * includes the WSS hash in the WLP IE in its beacon in each superframe.
320 * The WSS tag is also computed at this time. We only support one activated
321 * WSS so we can use the hash as a tag - there will never be a conflict.
323 * We currently only support one activated WSS so only one WSS hash is
324 * included in the WLP IE.
327 int wlp_wss_activate(struct wlp_wss *wss)
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;
334 struct wlp_ie wlp_ie;
335 u8 hash; /* only include one hash */
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,
349 dev_err(dev, "WLP: Unable to add WLP IE to beacon. "
350 "result = %d.\n", result);
353 wss->state = WLP_WSS_STATE_ACTIVE;
360 * Enroll in and activate WSS identified by provided WSSID
362 * The neighborhood cache should contain a list of all neighbors and the
363 * WSS they have activated. Based on that cache we search which neighbor we
364 * can perform the association process with. The user also has option to
365 * specify which neighbor it prefers as registrar.
366 * Successful enrollment is followed by activation.
367 * Successful activation will create the sysfs directory containing
368 * specific information regarding this WSS.
370 int wlp_wss_enroll_activate(struct wlp_wss *wss, struct wlp_uuid *wssid,
371 struct uwb_dev_addr *devaddr)
373 struct wlp *wlp = container_of(wss, struct wlp, wss);
374 struct device *dev = &wlp->rc->uwb_dev.dev;
376 char buf[WLP_WSS_UUID_STRSIZE];
378 mutex_lock(&wss->mutex);
379 result = wlp_wss_enroll(wss, wssid, devaddr);
381 wlp_wss_uuid_print(buf, sizeof(buf), &wss->wssid);
382 dev_err(dev, "WLP: Enrollment into WSS %s failed.\n", buf);
385 result = wlp_wss_activate(wss);
387 dev_err(dev, "WLP: Unable to activate WSS. Undoing enrollment "
388 "result = %d \n", result);
389 /* Undo enrollment */
395 mutex_unlock(&wss->mutex);
400 * Create, enroll, and activate a new WSS
402 * @wssid: new wssid provided by user
403 * @name: WSS name requested by used.
404 * @sec_status: security status requested by user
406 * A user requested the creation of a new WSS. All operations are done
407 * locally. The new WSS will be stored locally, the hash will be included
408 * in the WLP IE, and the sysfs infrastructure for this WSS will be
411 int wlp_wss_create_activate(struct wlp_wss *wss, struct wlp_uuid *wssid,
412 char *name, unsigned sec_status, unsigned accept)
414 struct wlp *wlp = container_of(wss, struct wlp, wss);
415 struct device *dev = &wlp->rc->uwb_dev.dev;
417 char buf[WLP_WSS_UUID_STRSIZE];
419 result = wlp_wss_uuid_print(buf, sizeof(buf), wssid);
421 if (!mutex_trylock(&wss->mutex)) {
422 dev_err(dev, "WLP: WLP association session in progress.\n");
425 if (wss->state != WLP_WSS_STATE_NONE) {
426 dev_err(dev, "WLP: WSS already exists. Not creating new.\n");
430 if (wss->kobj.parent == NULL) {
431 dev_err(dev, "WLP: WSS parent not ready. Is network interface "
436 if (sec_status == WLP_WSS_SECURE) {
437 dev_err(dev, "WLP: FIXME Creation of secure WSS not "
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 /*wss->virtual_addr is initialized in call to wlp_wss_setup*/
448 /* sysfs infrastructure */
449 result = wlp_wss_sysfs_add(wss, buf);
451 dev_err(dev, "Cannot set up sysfs for WSS kobject.\n");
456 wss->state = WLP_WSS_STATE_ENROLLED;
457 result = wlp_wss_activate(wss);
459 dev_err(dev, "WLP: Unable to activate WSS. Undoing "
466 mutex_unlock(&wss->mutex);
471 * Determine if neighbor has WSS activated
473 * @returns: 1 if neighbor has WSS activated, zero otherwise
475 * This can be done in two ways:
476 * - send a C1 frame, parse C2/F0 response
477 * - examine the WLP IE sent by the neighbor
479 * The WLP IE is not fully supported in hardware so we use the C1/C2 frame
480 * exchange to determine if a WSS is activated. Using the WLP IE should be
481 * faster and should be used when it becomes possible.
483 int wlp_wss_is_active(struct wlp *wlp, struct wlp_wss *wss,
484 struct uwb_dev_addr *dev_addr)
487 struct device *dev = &wlp->rc->uwb_dev.dev;
488 DECLARE_COMPLETION_ONSTACK(completion);
489 struct wlp_session session;
491 struct wlp_frame_assoc *resp;
492 struct wlp_uuid wssid;
494 mutex_lock(&wlp->mutex);
495 /* Send C1 association frame */
496 result = wlp_send_assoc_frame(wlp, wss, dev_addr, WLP_ASSOC_C1);
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);
504 /* Create session, wait for response */
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 /* Wait for C2/F0 frame */
512 result = wait_for_completion_interruptible_timeout(&completion,
513 WLP_PER_MSG_TIMEOUT * HZ);
515 dev_err(dev, "Timeout while sending C1 to neighbor "
516 "%02x:%02x.\n", dev_addr->data[1],
521 dev_err(dev, "Unable to send C1 to neighbor %02x:%02x.\n",
522 dev_addr->data[1], dev_addr->data[0]);
526 /* Parse message in session->data: it will be either C2 or F0 */
528 resp = (void *) skb->data;
529 if (resp->type == WLP_ASSOC_F0) {
530 result = wlp_parse_f0(wlp, skb);
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]);
536 goto error_resp_parse;
538 /* WLP version and message type fields have already been parsed */
539 result = wlp_get_wssid(wlp, (void *)resp + sizeof(*resp), &wssid,
540 skb->len - sizeof(*resp));
542 dev_err(dev, "WLP: unable to obtain WSSID from C2 frame.\n");
544 goto error_resp_parse;
546 if (!memcmp(&wssid, &wss->wssid, sizeof(wssid)))
549 dev_err(dev, "WLP: Received a C2 frame without matching "
557 mutex_unlock(&wlp->mutex);
562 * Activate connection with neighbor by updating EDA cache
564 * @wss: local WSS to which neighbor wants to connect
565 * @dev_addr: neighbor's address
566 * @wssid: neighbor's WSSID - must be same as our WSS's WSSID
567 * @tag: neighbor's WSS tag used to identify frames transmitted by it
568 * @virt_addr: neighbor's virtual EUI-48
571 int 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)
576 struct device *dev = &wlp->rc->uwb_dev.dev;
579 if (!memcmp(wssid, &wss->wssid, sizeof(*wssid))) {
580 /* Update EDA cache */
581 result = wlp_eda_update_node(&wlp->eda, dev_addr, wss,
582 (void *) virt_addr->data, *tag,
585 dev_err(dev, "WLP: Unable to update EDA cache "
586 "with new connected neighbor information.\n");
588 dev_err(dev, "WLP: Neighbor does not have matching WSSID.\n");
595 * Connect to WSS neighbor
597 * Use C3/C4 exchange to determine if neighbor has WSS activated and
598 * retrieve the WSS tag and virtual EUI-48 of the neighbor.
601 int wlp_wss_connect_neighbor(struct wlp *wlp, struct wlp_wss *wss,
602 struct uwb_dev_addr *dev_addr)
605 struct device *dev = &wlp->rc->uwb_dev.dev;
606 struct wlp_uuid wssid;
608 struct uwb_mac_addr virt_addr;
609 DECLARE_COMPLETION_ONSTACK(completion);
610 struct wlp_session session;
611 struct wlp_frame_assoc *resp;
614 mutex_lock(&wlp->mutex);
615 /* Send C3 association frame */
616 result = wlp_send_assoc_frame(wlp, wss, dev_addr, WLP_ASSOC_C3);
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);
623 /* Create session, wait for response */
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 /* Wait for C4/F0 frame */
631 result = wait_for_completion_interruptible_timeout(&completion,
632 WLP_PER_MSG_TIMEOUT * HZ);
634 dev_err(dev, "Timeout while sending C3 to neighbor "
635 "%02x:%02x.\n", dev_addr->data[1],
641 dev_err(dev, "Unable to send C3 to neighbor %02x:%02x.\n",
642 dev_addr->data[1], dev_addr->data[0]);
645 /* Parse message in session->data: it will be either C4 or F0 */
647 resp = (void *) skb->data;
648 if (resp->type == WLP_ASSOC_F0) {
649 result = wlp_parse_f0(wlp, skb);
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]);
655 goto error_resp_parse;
657 result = wlp_parse_c3c4_frame(wlp, skb, &wssid, &tag, &virt_addr);
659 dev_err(dev, "WLP: Unable to parse C4 frame from neighbor.\n");
660 goto error_resp_parse;
662 result = wlp_wss_activate_connection(wlp, wss, dev_addr, &wssid, &tag,
665 dev_err(dev, "WLP: Unable to activate connection to "
666 "neighbor %02x:%02x.\n", dev_addr->data[1],
668 goto error_resp_parse;
673 /* Record that we unsuccessfully tried to connect to this neighbor */
675 wlp_eda_update_node_state(&wlp->eda, dev_addr,
676 WLP_WSS_CONNECT_FAILED);
678 mutex_unlock(&wlp->mutex);
683 * Connect to neighbor with common WSS, send pending frame
685 * This function is scheduled when a frame is destined to a neighbor with
686 * which we do not have a connection. A copy of the EDA cache entry is
687 * provided - not the actual cache entry (because it is protected by a
690 * First determine if neighbor has the same WSS activated, connect if it
691 * does. The C3/C4 exchange is dual purpose to determine if neighbor has
692 * WSS activated and proceed with the connection.
694 * The frame that triggered the connection setup is sent after connection
697 * network queue is stopped - we need to restart when done
701 void wlp_wss_connect_send(struct work_struct *ws)
703 struct wlp_assoc_conn_ctx *conn_ctx = container_of(ws,
704 struct wlp_assoc_conn_ctx,
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;
712 struct device *dev = &wlp->rc->uwb_dev.dev;
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");
722 /* Establish connection - send C3 rcv C4 */
723 result = wlp_wss_connect_neighbor(wlp, wss, dev_addr);
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]);
732 /* EDA entry changed, update the local copy being used */
733 result = wlp_copy_eda_node(&wlp->eda, dev_addr, eda_entry);
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]);
740 result = wlp_wss_prep_hdr(wlp, eda_entry, skb);
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]);
749 BUG_ON(wlp->xmit_frame == NULL);
750 result = wlp->xmit_frame(wlp, skb, dev_addr);
752 if (printk_ratelimit())
753 dev_err(dev, "WLP: Unable to transmit frame: %d\n",
755 if (result == -ENXIO)
756 dev_err(dev, "WLP: Is network interface up? \n");
757 /* We could try again ... */
758 dev_kfree_skb(skb);/*we need to free if tx fails */
762 BUG_ON(wlp->start_queue == NULL);
763 wlp->start_queue(wlp);
764 mutex_unlock(&wss->mutex);
768 * Add WLP header to outgoing skb
770 * @eda_entry: pointer to neighbor's entry in the EDA cache
771 * @_skb: skb containing data destined to the neighbor
773 int wlp_wss_prep_hdr(struct wlp *wlp, struct wlp_eda_node *eda_entry,
776 struct device *dev = &wlp->rc->uwb_dev.dev;
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;
783 if (eda_entry->state == WLP_WSS_CONNECTED) {
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;
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],
805 * Prepare skb for neighbor: connect if not already and prep WLP header
807 * This function is called in interrupt context, but it needs to sleep. We
808 * temporarily stop the net queue to establish the WLP connection.
809 * Setup of the WLP connection and restart of queue is scheduled
810 * on the default work queue.
812 * run with eda->lock held (spinlock)
814 int wlp_wss_connect_prep(struct wlp *wlp, struct wlp_eda_node *eda_entry,
818 struct device *dev = &wlp->rc->uwb_dev.dev;
819 struct sk_buff *skb = _skb;
820 struct wlp_assoc_conn_ctx *conn_ctx;
822 if (eda_entry->state == WLP_WSS_UNCONNECTED) {
823 /* We don't want any more packets while we set up connection */
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");
836 conn_ctx->eda_entry = *eda_entry;
837 INIT_WORK(&conn_ctx->ws, wlp_wss_connect_send);
838 schedule_work(&conn_ctx->ws);
840 } else if (eda_entry->state == WLP_WSS_CONNECT_FAILED) {
841 /* Previous connection attempts failed, don't retry - see
842 * conditions for connection in WLP 0.99 [7.6.2] */
843 if (printk_ratelimit())
844 dev_err(dev, "Could not connect to neighbor "
845 "previously. Not retrying. \n");
848 } else /* eda_entry->state == WLP_WSS_CONNECTED */
849 result = wlp_wss_prep_hdr(wlp, eda_entry, skb);
855 * Emulate broadcast: copy skb, send copy to neighbor (connect if not already)
857 * We need to copy skbs in the case where we emulate broadcast through
858 * unicast. We copy instead of clone because we are modifying the data of
859 * the frame after copying ... clones share data so we cannot emulate
860 * broadcast using clones.
862 * run with eda->lock held (spinlock)
864 int wlp_wss_send_copy(struct wlp *wlp, struct wlp_eda_node *eda_entry,
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;
873 copy = skb_copy(skb, GFP_ATOMIC);
875 if (printk_ratelimit())
876 dev_err(dev, "WLP: Unable to copy skb for "
880 result = wlp_wss_connect_prep(wlp, eda_entry, copy);
882 if (printk_ratelimit())
883 dev_err(dev, "WLP: Unable to connect/send skb "
885 dev_kfree_skb_irq(copy);
887 } else if (result == 1)
888 /* Frame will be transmitted separately */
890 BUG_ON(wlp->xmit_frame == NULL);
891 result = wlp->xmit_frame(wlp, copy, dev_addr);
893 if (printk_ratelimit())
894 dev_err(dev, "WLP: Unable to transmit frame: %d\n",
896 if ((result == -ENXIO) && printk_ratelimit())
897 dev_err(dev, "WLP: Is network interface up? \n");
898 /* We could try again ... */
899 dev_kfree_skb_irq(copy);/*we need to free if tx fails */
909 * Should be called by network driver after the interface has been given a
912 int wlp_wss_setup(struct net_device *net_dev, struct wlp_wss *wss)
914 struct wlp *wlp = container_of(wss, struct wlp, wss);
915 struct device *dev = &wlp->rc->uwb_dev.dev;
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"
926 memcpy(wss->virtual_addr.data, net_dev->dev_addr,
927 sizeof(wss->virtual_addr.data));
929 mutex_unlock(&wss->mutex);
932 EXPORT_SYMBOL_GPL(wlp_wss_setup);
937 * Called by client that configured WSS through wlp_wss_setup(). This
938 * function is called when client no longer needs WSS, eg. client shuts
941 * We remove the WLP IE from the beacon before initiating local cleanup.
943 void wlp_wss_remove(struct wlp_wss *wss)
945 struct wlp *wlp = container_of(wss, struct wlp, wss);
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);
954 wss->kobj.parent = NULL;
955 memset(&wss->virtual_addr, 0, sizeof(wss->virtual_addr));
956 /* Cleanup EDA cache */
957 wlp_eda_release(&wlp->eda);
958 wlp_eda_init(&wlp->eda);
959 mutex_unlock(&wss->mutex);
961 EXPORT_SYMBOL_GPL(wlp_wss_remove);