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:
47 #include <linux/etherdevice.h> /* for is_valid_ether_addr */
48 #include <linux/skbuff.h>
49 #include <linux/wlp.h>
51 #include <linux/uwb/debug.h>
52 #include "wlp-internal.h"
55 size_t wlp_wss_key_print(char *buf, size_t bufsize, u8 *key)
59 result = scnprintf(buf, bufsize,
60 "%02x %02x %02x %02x %02x %02x "
61 "%02x %02x %02x %02x %02x %02x "
62 "%02x %02x %02x %02x",
63 key[0], key[1], key[2], key[3],
64 key[4], key[5], key[6], key[7],
65 key[8], key[9], key[10], key[11],
66 key[12], key[13], key[14], key[15]);
72 * WLP Draft 0.99 [7.2.1]
74 * The WSSID hash for a WSSID is the result of an octet-wise exclusive-OR
75 * of all octets in the WSSID.
78 u8 wlp_wss_comp_wssid_hash(struct wlp_uuid *wssid)
80 return wssid->data[0] ^ wssid->data[1] ^ wssid->data[2]
81 ^ wssid->data[3] ^ wssid->data[4] ^ wssid->data[5]
82 ^ wssid->data[6] ^ wssid->data[7] ^ wssid->data[8]
83 ^ wssid->data[9] ^ wssid->data[10] ^ wssid->data[11]
84 ^ wssid->data[12] ^ wssid->data[13] ^ wssid->data[14]
89 * Select a multicast EUI-48 for the WSS broadcast address.
90 * WLP Draft 0.99 [7.2.1]
92 * Selected based on the WiMedia Alliance OUI, 00-13-88, within the WLP
93 * range, [01-13-88-00-01-00, 01-13-88-00-01-FF] inclusive.
95 * This address is currently hardcoded.
99 struct uwb_mac_addr wlp_wss_sel_bcast_addr(struct wlp_wss *wss)
101 struct uwb_mac_addr bcast = {
102 .data = { 0x01, 0x13, 0x88, 0x00, 0x01, 0x00 }
108 * Clear the contents of the WSS structure - all except kobj, mutex, virtual
110 * We do not want to reinitialize - the internal kobj should not change as
111 * it still points to the parent received during setup. The mutex should
112 * remain also. We thus just reset values individually.
113 * The virutal address assigned to WSS will remain the same for the
114 * lifetime of the WSS. We only reset the fields that can change during its
117 void wlp_wss_reset(struct wlp_wss *wss)
119 struct wlp *wlp = container_of(wss, struct wlp, wss);
120 struct device *dev = &wlp->rc->uwb_dev.dev;
121 d_fnstart(5, dev, "wss (%p) \n", wss);
122 memset(&wss->wssid, 0, sizeof(wss->wssid));
124 memset(&wss->name[0], 0, sizeof(wss->name));
125 memset(&wss->bcast, 0, sizeof(wss->bcast));
126 wss->secure_status = WLP_WSS_UNSECURE;
127 memset(&wss->master_key[0], 0, sizeof(wss->master_key));
129 wss->state = WLP_WSS_STATE_NONE;
130 d_fnend(5, dev, "wss (%p) \n", wss);
134 * Create sysfs infrastructure for WSS
136 * The WSS is configured to have the interface as parent (see wlp_wss_setup())
137 * a new sysfs directory that includes wssid as its name is created in the
138 * interface's sysfs directory. The group of files interacting with WSS are
142 int wlp_wss_sysfs_add(struct wlp_wss *wss, char *wssid_str)
144 struct wlp *wlp = container_of(wss, struct wlp, wss);
145 struct device *dev = &wlp->rc->uwb_dev.dev;
148 d_fnstart(5, dev, "wss (%p), wssid: %s\n", wss, wssid_str);
149 result = kobject_set_name(&wss->kobj, "wss-%s", wssid_str);
152 wss->kobj.ktype = &wss_ktype;
153 result = kobject_init_and_add(&wss->kobj,
154 &wss_ktype, wss->kobj.parent, "wlp");
156 dev_err(dev, "WLP: Cannot register WSS kobject.\n");
157 goto error_kobject_register;
159 result = sysfs_create_group(&wss->kobj, &wss_attr_group);
161 dev_err(dev, "WLP: Cannot register WSS attributes: %d\n",
163 goto error_sysfs_create_group;
165 d_fnend(5, dev, "Completed. result = %d \n", result);
167 error_sysfs_create_group:
169 kobject_put(&wss->kobj); /* will free name if needed */
171 error_kobject_register:
172 kfree(wss->kobj.name);
173 wss->kobj.name = NULL;
174 wss->kobj.ktype = NULL;
182 * No more references exist to this WSS. We should undo everything that was
183 * done in wlp_wss_create_activate() except removing the group. The group
184 * is not removed because an object can be unregistered before the group is
185 * created. We also undo any additional operations on the WSS after this
186 * (addition of members).
188 * If memory was allocated for the kobject's name then it will
189 * be freed by the kobject system during this time.
191 * The EDA cache is removed and reinitilized when the WSS is removed. We
192 * thus loose knowledge of members of this WSS at that time and need not do
195 void wlp_wss_release(struct kobject *kobj)
197 struct wlp_wss *wss = container_of(kobj, struct wlp_wss, kobj);
203 * Enroll into a WSS using provided neighbor as registrar
205 * First search the neighborhood information to learn which neighbor is
206 * referred to, next proceed with enrollment.
208 * &wss->mutex is held
211 int wlp_wss_enroll_target(struct wlp_wss *wss, struct wlp_uuid *wssid,
212 struct uwb_dev_addr *dest)
214 struct wlp *wlp = container_of(wss, struct wlp, wss);
215 struct device *dev = &wlp->rc->uwb_dev.dev;
216 struct wlp_neighbor_e *neighbor;
217 char buf[WLP_WSS_UUID_STRSIZE];
219 struct uwb_dev_addr *dev_addr;
221 wlp_wss_uuid_print(buf, sizeof(buf), wssid);
222 d_fnstart(5, dev, "wss %p, wssid %s, registrar %02x:%02x \n",
223 wss, buf, dest->data[1], dest->data[0]);
224 mutex_lock(&wlp->nbmutex);
225 list_for_each_entry(neighbor, &wlp->neighbors, node) {
226 dev_addr = &neighbor->uwb_dev->dev_addr;
227 if (!memcmp(dest, dev_addr, sizeof(*dest))) {
228 d_printf(5, dev, "Neighbor %02x:%02x is valid, "
230 dev_addr->data[1], dev_addr->data[0]);
231 result = wlp_enroll_neighbor(wlp, neighbor, wss,
236 if (result == -ENXIO)
237 dev_err(dev, "WLP: Cannot find neighbor %02x:%02x. \n",
238 dest->data[1], dest->data[0]);
239 mutex_unlock(&wlp->nbmutex);
240 d_fnend(5, dev, "wss %p, wssid %s, registrar %02x:%02x, result %d \n",
241 wss, buf, dest->data[1], dest->data[0], result);
246 * Enroll into a WSS previously discovered
248 * User provides WSSID of WSS, search for neighbor that has this WSS
249 * activated and attempt to enroll.
251 * &wss->mutex is held
254 int wlp_wss_enroll_discovered(struct wlp_wss *wss, struct wlp_uuid *wssid)
256 struct wlp *wlp = container_of(wss, struct wlp, wss);
257 struct device *dev = &wlp->rc->uwb_dev.dev;
258 struct wlp_neighbor_e *neighbor;
259 struct wlp_wssid_e *wssid_e;
260 char buf[WLP_WSS_UUID_STRSIZE];
263 wlp_wss_uuid_print(buf, sizeof(buf), wssid);
264 d_fnstart(5, dev, "wss %p, wssid %s \n", wss, buf);
265 mutex_lock(&wlp->nbmutex);
266 list_for_each_entry(neighbor, &wlp->neighbors, node) {
267 list_for_each_entry(wssid_e, &neighbor->wssid, node) {
268 if (!memcmp(wssid, &wssid_e->wssid, sizeof(*wssid))) {
269 d_printf(5, dev, "Found WSSID %s in neighbor "
270 "%02x:%02x cache. \n", buf,
271 neighbor->uwb_dev->dev_addr.data[1],
272 neighbor->uwb_dev->dev_addr.data[0]);
273 result = wlp_enroll_neighbor(wlp, neighbor,
275 if (result == 0) /* enrollment success */
282 if (result == -ENXIO)
283 dev_err(dev, "WLP: Cannot find WSSID %s in cache. \n", buf);
284 mutex_unlock(&wlp->nbmutex);
285 d_fnend(5, dev, "wss %p, wssid %s, result %d \n", wss, buf, result);
290 * Enroll into WSS with provided WSSID, registrar may be provided
292 * @wss: out WSS that will be enrolled
293 * @wssid: wssid of neighboring WSS that we want to enroll in
294 * @devaddr: registrar can be specified, will be broadcast (ff:ff) if any
295 * neighbor can be used as registrar.
297 * &wss->mutex is held
300 int wlp_wss_enroll(struct wlp_wss *wss, struct wlp_uuid *wssid,
301 struct uwb_dev_addr *devaddr)
304 struct wlp *wlp = container_of(wss, struct wlp, wss);
305 struct device *dev = &wlp->rc->uwb_dev.dev;
306 char buf[WLP_WSS_UUID_STRSIZE];
307 struct uwb_dev_addr bcast = {.data = {0xff, 0xff} };
309 wlp_wss_uuid_print(buf, sizeof(buf), wssid);
310 if (wss->state != WLP_WSS_STATE_NONE) {
311 dev_err(dev, "WLP: Already enrolled in WSS %s.\n", buf);
315 if (!memcmp(&bcast, devaddr, sizeof(bcast))) {
316 d_printf(5, dev, "Request to enroll in discovered WSS "
317 "with WSSID %s \n", buf);
318 result = wlp_wss_enroll_discovered(wss, wssid);
320 d_printf(5, dev, "Request to enroll in WSSID %s with "
321 "registrar %02x:%02x\n", buf, devaddr->data[1],
323 result = wlp_wss_enroll_target(wss, wssid, devaddr);
326 dev_err(dev, "WLP: Unable to enroll into WSS %s, result %d \n",
330 d_printf(2, dev, "Successfully enrolled into WSS %s \n", buf);
331 result = wlp_wss_sysfs_add(wss, buf);
333 dev_err(dev, "WLP: Unable to set up sysfs for WSS kobject.\n");
344 * Prior to activation a WSS must be enrolled. To activate a WSS a device
345 * includes the WSS hash in the WLP IE in its beacon in each superframe.
348 * The WSS tag is also computed at this time. We only support one activated
349 * WSS so we can use the hash as a tag - there will never be a conflict.
351 * We currently only support one activated WSS so only one WSS hash is
352 * included in the WLP IE.
355 int wlp_wss_activate(struct wlp_wss *wss)
357 struct wlp *wlp = container_of(wss, struct wlp, wss);
358 struct device *dev = &wlp->rc->uwb_dev.dev;
359 struct uwb_rc *uwb_rc = wlp->rc;
362 struct wlp_ie wlp_ie;
363 u8 hash; /* only include one hash */
366 d_fnstart(5, dev, "Activating WSS %p. \n", wss);
367 BUG_ON(wss->state != WLP_WSS_STATE_ENROLLED);
368 wss->hash = wlp_wss_comp_wssid_hash(&wss->wssid);
369 wss->tag = wss->hash;
370 memset(&ie_data, 0, sizeof(ie_data));
371 ie_data.wlp_ie.hdr.element_id = UWB_IE_WLP;
372 ie_data.wlp_ie.hdr.length = sizeof(ie_data) - sizeof(struct uwb_ie_hdr);
373 wlp_ie_set_hash_length(&ie_data.wlp_ie, sizeof(ie_data.hash));
374 ie_data.hash = wss->hash;
375 result = uwb_rc_ie_add(uwb_rc, &ie_data.wlp_ie.hdr,
378 dev_err(dev, "WLP: Unable to add WLP IE to beacon. "
379 "result = %d.\n", result);
382 wss->state = WLP_WSS_STATE_ACTIVE;
385 d_fnend(5, dev, "Activating WSS %p, result = %d \n", wss, result);
390 * Enroll in and activate WSS identified by provided WSSID
392 * The neighborhood cache should contain a list of all neighbors and the
393 * WSS they have activated. Based on that cache we search which neighbor we
394 * can perform the association process with. The user also has option to
395 * specify which neighbor it prefers as registrar.
396 * Successful enrollment is followed by activation.
397 * Successful activation will create the sysfs directory containing
398 * specific information regarding this WSS.
400 int wlp_wss_enroll_activate(struct wlp_wss *wss, struct wlp_uuid *wssid,
401 struct uwb_dev_addr *devaddr)
403 struct wlp *wlp = container_of(wss, struct wlp, wss);
404 struct device *dev = &wlp->rc->uwb_dev.dev;
406 char buf[WLP_WSS_UUID_STRSIZE];
408 d_fnstart(5, dev, "Enrollment and activation requested. \n");
409 mutex_lock(&wss->mutex);
410 result = wlp_wss_enroll(wss, wssid, devaddr);
412 wlp_wss_uuid_print(buf, sizeof(buf), &wss->wssid);
413 dev_err(dev, "WLP: Enrollment into WSS %s failed.\n", buf);
416 result = wlp_wss_activate(wss);
418 dev_err(dev, "WLP: Unable to activate WSS. Undoing enrollment "
419 "result = %d \n", result);
420 /* Undo enrollment */
426 mutex_unlock(&wss->mutex);
427 d_fnend(5, dev, "Completed. result = %d \n", result);
432 * Create, enroll, and activate a new WSS
434 * @wssid: new wssid provided by user
435 * @name: WSS name requested by used.
436 * @sec_status: security status requested by user
438 * A user requested the creation of a new WSS. All operations are done
439 * locally. The new WSS will be stored locally, the hash will be included
440 * in the WLP IE, and the sysfs infrastructure for this WSS will be
443 int wlp_wss_create_activate(struct wlp_wss *wss, struct wlp_uuid *wssid,
444 char *name, unsigned sec_status, unsigned accept)
446 struct wlp *wlp = container_of(wss, struct wlp, wss);
447 struct device *dev = &wlp->rc->uwb_dev.dev;
449 char buf[WLP_WSS_UUID_STRSIZE];
450 d_fnstart(5, dev, "Request to create new WSS.\n");
451 result = wlp_wss_uuid_print(buf, sizeof(buf), wssid);
452 d_printf(5, dev, "Request to create WSS: WSSID=%s, name=%s, "
453 "sec_status=%u, accepting enrollment=%u \n",
454 buf, name, sec_status, accept);
455 if (!mutex_trylock(&wss->mutex)) {
456 dev_err(dev, "WLP: WLP association session in progress.\n");
459 if (wss->state != WLP_WSS_STATE_NONE) {
460 dev_err(dev, "WLP: WSS already exists. Not creating new.\n");
464 if (wss->kobj.parent == NULL) {
465 dev_err(dev, "WLP: WSS parent not ready. Is network interface "
470 if (sec_status == WLP_WSS_SECURE) {
471 dev_err(dev, "WLP: FIXME Creation of secure WSS not "
477 memcpy(wss->name, name, sizeof(wss->name));
478 wss->bcast = wlp_wss_sel_bcast_addr(wss);
479 wss->secure_status = sec_status;
480 wss->accept_enroll = accept;
481 /*wss->virtual_addr is initialized in call to wlp_wss_setup*/
482 /* sysfs infrastructure */
483 result = wlp_wss_sysfs_add(wss, buf);
485 dev_err(dev, "Cannot set up sysfs for WSS kobject.\n");
490 wss->state = WLP_WSS_STATE_ENROLLED;
491 result = wlp_wss_activate(wss);
493 dev_err(dev, "WLP: Unable to activate WSS. Undoing "
500 mutex_unlock(&wss->mutex);
501 d_fnend(5, dev, "Completed. result = %d \n", result);
506 * Determine if neighbor has WSS activated
508 * @returns: 1 if neighbor has WSS activated, zero otherwise
510 * This can be done in two ways:
511 * - send a C1 frame, parse C2/F0 response
512 * - examine the WLP IE sent by the neighbor
514 * The WLP IE is not fully supported in hardware so we use the C1/C2 frame
515 * exchange to determine if a WSS is activated. Using the WLP IE should be
516 * faster and should be used when it becomes possible.
518 int wlp_wss_is_active(struct wlp *wlp, struct wlp_wss *wss,
519 struct uwb_dev_addr *dev_addr)
522 struct device *dev = &wlp->rc->uwb_dev.dev;
523 char buf[WLP_WSS_UUID_STRSIZE];
524 DECLARE_COMPLETION_ONSTACK(completion);
525 struct wlp_session session;
527 struct wlp_frame_assoc *resp;
528 struct wlp_uuid wssid;
530 wlp_wss_uuid_print(buf, sizeof(buf), &wss->wssid);
531 d_fnstart(5, dev, "wlp %p, wss %p (wssid %s), neighbor %02x:%02x \n",
532 wlp, wss, buf, dev_addr->data[1], dev_addr->data[0]);
533 mutex_lock(&wlp->mutex);
534 /* Send C1 association frame */
535 result = wlp_send_assoc_frame(wlp, wss, dev_addr, WLP_ASSOC_C1);
537 dev_err(dev, "Unable to send C1 frame to neighbor "
538 "%02x:%02x (%d)\n", dev_addr->data[1],
539 dev_addr->data[0], result);
543 /* Create session, wait for response */
544 session.exp_message = WLP_ASSOC_C2;
545 session.cb = wlp_session_cb;
546 session.cb_priv = &completion;
547 session.neighbor_addr = *dev_addr;
548 BUG_ON(wlp->session != NULL);
549 wlp->session = &session;
550 /* Wait for C2/F0 frame */
551 result = wait_for_completion_interruptible_timeout(&completion,
552 WLP_PER_MSG_TIMEOUT * HZ);
554 dev_err(dev, "Timeout while sending C1 to neighbor "
555 "%02x:%02x.\n", dev_addr->data[1],
560 dev_err(dev, "Unable to send C1 to neighbor %02x:%02x.\n",
561 dev_addr->data[1], dev_addr->data[0]);
565 /* Parse message in session->data: it will be either C2 or F0 */
567 resp = (void *) skb->data;
568 d_printf(5, dev, "Received response to C1 frame. \n");
569 d_dump(5, dev, skb->data, skb->len > 72 ? 72 : skb->len);
570 if (resp->type == WLP_ASSOC_F0) {
571 result = wlp_parse_f0(wlp, skb);
573 dev_err(dev, "WLP: unable to parse incoming F0 "
574 "frame from neighbor %02x:%02x.\n",
575 dev_addr->data[1], dev_addr->data[0]);
577 goto error_resp_parse;
579 /* WLP version and message type fields have already been parsed */
580 result = wlp_get_wssid(wlp, (void *)resp + sizeof(*resp), &wssid,
581 skb->len - sizeof(*resp));
583 dev_err(dev, "WLP: unable to obtain WSSID from C2 frame.\n");
585 goto error_resp_parse;
587 if (!memcmp(&wssid, &wss->wssid, sizeof(wssid))) {
588 d_printf(5, dev, "WSSID in C2 frame matches local "
592 dev_err(dev, "WLP: Received a C2 frame without matching "
600 mutex_unlock(&wlp->mutex);
601 d_fnend(5, dev, "wlp %p, wss %p (wssid %s), neighbor %02x:%02x \n",
602 wlp, wss, buf, dev_addr->data[1], dev_addr->data[0]);
607 * Activate connection with neighbor by updating EDA cache
609 * @wss: local WSS to which neighbor wants to connect
610 * @dev_addr: neighbor's address
611 * @wssid: neighbor's WSSID - must be same as our WSS's WSSID
612 * @tag: neighbor's WSS tag used to identify frames transmitted by it
613 * @virt_addr: neighbor's virtual EUI-48
616 int wlp_wss_activate_connection(struct wlp *wlp, struct wlp_wss *wss,
617 struct uwb_dev_addr *dev_addr,
618 struct wlp_uuid *wssid, u8 *tag,
619 struct uwb_mac_addr *virt_addr)
621 struct device *dev = &wlp->rc->uwb_dev.dev;
623 char buf[WLP_WSS_UUID_STRSIZE];
624 wlp_wss_uuid_print(buf, sizeof(buf), wssid);
625 d_fnstart(5, dev, "wlp %p, wss %p, wssid %s, tag %u, virtual "
626 "%02x:%02x:%02x:%02x:%02x:%02x \n", wlp, wss, buf, *tag,
627 virt_addr->data[0], virt_addr->data[1], virt_addr->data[2],
628 virt_addr->data[3], virt_addr->data[4], virt_addr->data[5]);
630 if (!memcmp(wssid, &wss->wssid, sizeof(*wssid))) {
631 d_printf(5, dev, "WSSID from neighbor frame matches local "
633 /* Update EDA cache */
634 result = wlp_eda_update_node(&wlp->eda, dev_addr, wss,
635 (void *) virt_addr->data, *tag,
638 dev_err(dev, "WLP: Unable to update EDA cache "
639 "with new connected neighbor information.\n");
641 dev_err(dev, "WLP: Neighbor does not have matching "
646 d_fnend(5, dev, "wlp %p, wss %p, wssid %s, tag %u, virtual "
647 "%02x:%02x:%02x:%02x:%02x:%02x, result = %d \n",
649 virt_addr->data[0], virt_addr->data[1], virt_addr->data[2],
650 virt_addr->data[3], virt_addr->data[4], virt_addr->data[5],
657 * Connect to WSS neighbor
659 * Use C3/C4 exchange to determine if neighbor has WSS activated and
660 * retrieve the WSS tag and virtual EUI-48 of the neighbor.
663 int wlp_wss_connect_neighbor(struct wlp *wlp, struct wlp_wss *wss,
664 struct uwb_dev_addr *dev_addr)
667 struct device *dev = &wlp->rc->uwb_dev.dev;
668 char buf[WLP_WSS_UUID_STRSIZE];
669 struct wlp_uuid wssid;
671 struct uwb_mac_addr virt_addr;
672 DECLARE_COMPLETION_ONSTACK(completion);
673 struct wlp_session session;
674 struct wlp_frame_assoc *resp;
677 wlp_wss_uuid_print(buf, sizeof(buf), &wss->wssid);
678 d_fnstart(5, dev, "wlp %p, wss %p (wssid %s), neighbor %02x:%02x \n",
679 wlp, wss, buf, dev_addr->data[1], dev_addr->data[0]);
680 mutex_lock(&wlp->mutex);
681 /* Send C3 association frame */
682 result = wlp_send_assoc_frame(wlp, wss, dev_addr, WLP_ASSOC_C3);
684 dev_err(dev, "Unable to send C3 frame to neighbor "
685 "%02x:%02x (%d)\n", dev_addr->data[1],
686 dev_addr->data[0], result);
689 /* Create session, wait for response */
690 session.exp_message = WLP_ASSOC_C4;
691 session.cb = wlp_session_cb;
692 session.cb_priv = &completion;
693 session.neighbor_addr = *dev_addr;
694 BUG_ON(wlp->session != NULL);
695 wlp->session = &session;
696 /* Wait for C4/F0 frame */
697 result = wait_for_completion_interruptible_timeout(&completion,
698 WLP_PER_MSG_TIMEOUT * HZ);
700 dev_err(dev, "Timeout while sending C3 to neighbor "
701 "%02x:%02x.\n", dev_addr->data[1],
707 dev_err(dev, "Unable to send C3 to neighbor %02x:%02x.\n",
708 dev_addr->data[1], dev_addr->data[0]);
711 /* Parse message in session->data: it will be either C4 or F0 */
713 resp = (void *) skb->data;
714 d_printf(5, dev, "Received response to C3 frame. \n");
715 d_dump(5, dev, skb->data, skb->len > 72 ? 72 : skb->len);
716 if (resp->type == WLP_ASSOC_F0) {
717 result = wlp_parse_f0(wlp, skb);
719 dev_err(dev, "WLP: unable to parse incoming F0 "
720 "frame from neighbor %02x:%02x.\n",
721 dev_addr->data[1], dev_addr->data[0]);
723 goto error_resp_parse;
725 result = wlp_parse_c3c4_frame(wlp, skb, &wssid, &tag, &virt_addr);
727 dev_err(dev, "WLP: Unable to parse C4 frame from neighbor.\n");
728 goto error_resp_parse;
730 result = wlp_wss_activate_connection(wlp, wss, dev_addr, &wssid, &tag,
733 dev_err(dev, "WLP: Unable to activate connection to "
734 "neighbor %02x:%02x.\n", dev_addr->data[1],
736 goto error_resp_parse;
741 /* Record that we unsuccessfully tried to connect to this neighbor */
743 wlp_eda_update_node_state(&wlp->eda, dev_addr,
744 WLP_WSS_CONNECT_FAILED);
746 mutex_unlock(&wlp->mutex);
747 d_fnend(5, dev, "wlp %p, wss %p (wssid %s), neighbor %02x:%02x \n",
748 wlp, wss, buf, dev_addr->data[1], dev_addr->data[0]);
753 * Connect to neighbor with common WSS, send pending frame
755 * This function is scheduled when a frame is destined to a neighbor with
756 * which we do not have a connection. A copy of the EDA cache entry is
757 * provided - not the actual cache entry (because it is protected by a
760 * First determine if neighbor has the same WSS activated, connect if it
761 * does. The C3/C4 exchange is dual purpose to determine if neighbor has
762 * WSS activated and proceed with the connection.
764 * The frame that triggered the connection setup is sent after connection
767 * network queue is stopped - we need to restart when done
771 void wlp_wss_connect_send(struct work_struct *ws)
773 struct wlp_assoc_conn_ctx *conn_ctx = container_of(ws,
774 struct wlp_assoc_conn_ctx,
776 struct wlp *wlp = conn_ctx->wlp;
777 struct sk_buff *skb = conn_ctx->skb;
778 struct wlp_eda_node *eda_entry = &conn_ctx->eda_entry;
779 struct uwb_dev_addr *dev_addr = &eda_entry->dev_addr;
780 struct wlp_wss *wss = &wlp->wss;
782 struct device *dev = &wlp->rc->uwb_dev.dev;
783 char buf[WLP_WSS_UUID_STRSIZE];
785 mutex_lock(&wss->mutex);
786 wlp_wss_uuid_print(buf, sizeof(buf), &wss->wssid);
787 d_fnstart(5, dev, "wlp %p, wss %p (wssid %s), neighbor %02x:%02x \n",
788 wlp, wss, buf, dev_addr->data[1], dev_addr->data[0]);
789 if (wss->state < WLP_WSS_STATE_ACTIVE) {
790 if (printk_ratelimit())
791 dev_err(dev, "WLP: Attempting to connect with "
792 "WSS that is not active or connected.\n");
796 /* Establish connection - send C3 rcv C4 */
797 result = wlp_wss_connect_neighbor(wlp, wss, dev_addr);
799 if (printk_ratelimit())
800 dev_err(dev, "WLP: Unable to establish connection "
801 "with neighbor %02x:%02x.\n",
802 dev_addr->data[1], dev_addr->data[0]);
806 /* EDA entry changed, update the local copy being used */
807 result = wlp_copy_eda_node(&wlp->eda, dev_addr, eda_entry);
809 if (printk_ratelimit())
810 dev_err(dev, "WLP: Cannot find EDA entry for "
811 "neighbor %02x:%02x \n",
812 dev_addr->data[1], dev_addr->data[0]);
814 result = wlp_wss_prep_hdr(wlp, eda_entry, skb);
816 if (printk_ratelimit())
817 dev_err(dev, "WLP: Unable to prepare frame header for "
818 "transmission (neighbor %02x:%02x). \n",
819 dev_addr->data[1], dev_addr->data[0]);
823 BUG_ON(wlp->xmit_frame == NULL);
824 result = wlp->xmit_frame(wlp, skb, dev_addr);
826 if (printk_ratelimit())
827 dev_err(dev, "WLP: Unable to transmit frame: %d\n",
829 if (result == -ENXIO)
830 dev_err(dev, "WLP: Is network interface up? \n");
831 /* We could try again ... */
832 dev_kfree_skb(skb);/*we need to free if tx fails */
836 BUG_ON(wlp->start_queue == NULL);
837 wlp->start_queue(wlp);
838 mutex_unlock(&wss->mutex);
839 d_fnend(5, dev, "wlp %p, wss %p (wssid %s)\n", wlp, wss, buf);
843 * Add WLP header to outgoing skb
845 * @eda_entry: pointer to neighbor's entry in the EDA cache
846 * @_skb: skb containing data destined to the neighbor
848 int wlp_wss_prep_hdr(struct wlp *wlp, struct wlp_eda_node *eda_entry,
851 struct device *dev = &wlp->rc->uwb_dev.dev;
853 unsigned char *eth_addr = eda_entry->eth_addr;
854 struct uwb_dev_addr *dev_addr = &eda_entry->dev_addr;
855 struct sk_buff *skb = _skb;
856 struct wlp_frame_std_abbrv_hdr *std_hdr;
858 d_fnstart(6, dev, "wlp %p \n", wlp);
859 if (eda_entry->state == WLP_WSS_CONNECTED) {
861 BUG_ON(skb_headroom(skb) < sizeof(*std_hdr));
862 std_hdr = (void *) __skb_push(skb, sizeof(*std_hdr));
863 std_hdr->hdr.mux_hdr = cpu_to_le16(WLP_PROTOCOL_ID);
864 std_hdr->hdr.type = WLP_FRAME_STANDARD;
865 std_hdr->tag = eda_entry->wss->tag;
867 if (printk_ratelimit())
868 dev_err(dev, "WLP: Destination neighbor (Ethernet: "
869 "%02x:%02x:%02x:%02x:%02x:%02x, Dev: "
870 "%02x:%02x) is not connected. \n", eth_addr[0],
871 eth_addr[1], eth_addr[2], eth_addr[3],
872 eth_addr[4], eth_addr[5], dev_addr->data[1],
876 d_fnend(6, dev, "wlp %p \n", wlp);
882 * Prepare skb for neighbor: connect if not already and prep WLP header
884 * This function is called in interrupt context, but it needs to sleep. We
885 * temporarily stop the net queue to establish the WLP connection.
886 * Setup of the WLP connection and restart of queue is scheduled
887 * on the default work queue.
889 * run with eda->lock held (spinlock)
891 int wlp_wss_connect_prep(struct wlp *wlp, struct wlp_eda_node *eda_entry,
895 struct device *dev = &wlp->rc->uwb_dev.dev;
896 struct uwb_dev_addr *dev_addr = &eda_entry->dev_addr;
897 unsigned char *eth_addr = eda_entry->eth_addr;
898 struct sk_buff *skb = _skb;
899 struct wlp_assoc_conn_ctx *conn_ctx;
901 d_fnstart(5, dev, "wlp %p\n", wlp);
902 d_printf(5, dev, "To neighbor %02x:%02x with eth "
903 "%02x:%02x:%02x:%02x:%02x:%02x\n", dev_addr->data[1],
904 dev_addr->data[0], eth_addr[0], eth_addr[1], eth_addr[2],
905 eth_addr[3], eth_addr[4], eth_addr[5]);
906 if (eda_entry->state == WLP_WSS_UNCONNECTED) {
907 /* We don't want any more packets while we set up connection */
908 BUG_ON(wlp->stop_queue == NULL);
909 wlp->stop_queue(wlp);
910 conn_ctx = kmalloc(sizeof(*conn_ctx), GFP_ATOMIC);
911 if (conn_ctx == NULL) {
912 if (printk_ratelimit())
913 dev_err(dev, "WLP: Unable to allocate memory "
914 "for connection handling.\n");
920 conn_ctx->eda_entry = *eda_entry;
921 INIT_WORK(&conn_ctx->ws, wlp_wss_connect_send);
922 schedule_work(&conn_ctx->ws);
924 } else if (eda_entry->state == WLP_WSS_CONNECT_FAILED) {
925 /* Previous connection attempts failed, don't retry - see
926 * conditions for connection in WLP 0.99 [7.6.2] */
927 if (printk_ratelimit())
928 dev_err(dev, "Could not connect to neighbor "
929 "previously. Not retrying. \n");
932 } else { /* eda_entry->state == WLP_WSS_CONNECTED */
933 d_printf(5, dev, "Neighbor is connected, preparing frame.\n");
934 result = wlp_wss_prep_hdr(wlp, eda_entry, skb);
937 d_fnend(5, dev, "wlp %p, result = %d \n", wlp, result);
942 * Emulate broadcast: copy skb, send copy to neighbor (connect if not already)
944 * We need to copy skbs in the case where we emulate broadcast through
945 * unicast. We copy instead of clone because we are modifying the data of
946 * the frame after copying ... clones share data so we cannot emulate
947 * broadcast using clones.
949 * run with eda->lock held (spinlock)
951 int wlp_wss_send_copy(struct wlp *wlp, struct wlp_eda_node *eda_entry,
954 int result = -ENOMEM;
955 struct device *dev = &wlp->rc->uwb_dev.dev;
956 struct sk_buff *skb = _skb;
957 struct sk_buff *copy;
958 struct uwb_dev_addr *dev_addr = &eda_entry->dev_addr;
960 d_fnstart(5, dev, "to neighbor %02x:%02x, skb (%p) \n",
961 dev_addr->data[1], dev_addr->data[0], skb);
962 copy = skb_copy(skb, GFP_ATOMIC);
964 if (printk_ratelimit())
965 dev_err(dev, "WLP: Unable to copy skb for "
969 result = wlp_wss_connect_prep(wlp, eda_entry, copy);
971 if (printk_ratelimit())
972 dev_err(dev, "WLP: Unable to connect/send skb "
974 dev_kfree_skb_irq(copy);
976 } else if (result == 1)
977 /* Frame will be transmitted separately */
979 BUG_ON(wlp->xmit_frame == NULL);
980 result = wlp->xmit_frame(wlp, copy, dev_addr);
982 if (printk_ratelimit())
983 dev_err(dev, "WLP: Unable to transmit frame: %d\n",
985 if ((result == -ENXIO) && printk_ratelimit())
986 dev_err(dev, "WLP: Is network interface up? \n");
987 /* We could try again ... */
988 dev_kfree_skb_irq(copy);/*we need to free if tx fails */
991 d_fnend(5, dev, "to neighbor %02x:%02x \n", dev_addr->data[1],
1000 * Should be called by network driver after the interface has been given a
1003 int wlp_wss_setup(struct net_device *net_dev, struct wlp_wss *wss)
1005 struct wlp *wlp = container_of(wss, struct wlp, wss);
1006 struct device *dev = &wlp->rc->uwb_dev.dev;
1008 d_fnstart(5, dev, "wss (%p) \n", wss);
1009 mutex_lock(&wss->mutex);
1010 wss->kobj.parent = &net_dev->dev.kobj;
1011 if (!is_valid_ether_addr(net_dev->dev_addr)) {
1012 dev_err(dev, "WLP: Invalid MAC address. Cannot use for"
1017 memcpy(wss->virtual_addr.data, net_dev->dev_addr,
1018 sizeof(wss->virtual_addr.data));
1020 mutex_unlock(&wss->mutex);
1021 d_fnend(5, dev, "wss (%p) \n", wss);
1024 EXPORT_SYMBOL_GPL(wlp_wss_setup);
1029 * Called by client that configured WSS through wlp_wss_setup(). This
1030 * function is called when client no longer needs WSS, eg. client shuts
1033 * We remove the WLP IE from the beacon before initiating local cleanup.
1035 void wlp_wss_remove(struct wlp_wss *wss)
1037 struct wlp *wlp = container_of(wss, struct wlp, wss);
1038 struct device *dev = &wlp->rc->uwb_dev.dev;
1039 d_fnstart(5, dev, "wss (%p) \n", wss);
1040 mutex_lock(&wss->mutex);
1041 if (wss->state == WLP_WSS_STATE_ACTIVE)
1042 uwb_rc_ie_rm(wlp->rc, UWB_IE_WLP);
1043 if (wss->state != WLP_WSS_STATE_NONE) {
1044 sysfs_remove_group(&wss->kobj, &wss_attr_group);
1045 kobject_put(&wss->kobj);
1047 wss->kobj.parent = NULL;
1048 memset(&wss->virtual_addr, 0, sizeof(wss->virtual_addr));
1049 /* Cleanup EDA cache */
1050 wlp_eda_release(&wlp->eda);
1051 wlp_eda_init(&wlp->eda);
1052 mutex_unlock(&wss->mutex);
1053 d_fnend(5, dev, "wss (%p) \n", wss);
1055 EXPORT_SYMBOL_GPL(wlp_wss_remove);