2 #include <linux/etherdevice.h> /* for is_valid_ether_addr */
3 #include <linux/skbuff.h>
4 #include <linux/slab.h>
7 #include "wlp-internal.h"
9 size_t wlp_wss_key_print(char *buf
, size_t bufsize
, u8
*key
)
13 result
= scnprintf(buf
, bufsize
,
14 "%02x %02x %02x %02x %02x %02x "
15 "%02x %02x %02x %02x %02x %02x "
16 "%02x %02x %02x %02x",
17 key
[0], key
[1], key
[2], key
[3],
18 key
[4], key
[5], key
[6], key
[7],
19 key
[8], key
[9], key
[10], key
[11],
20 key
[12], key
[13], key
[14], key
[15]);
26 * WLP Draft 0.99 [7.2.1]
28 * The WSSID hash for a WSSID is the result of an octet-wise exclusive-OR
29 * of all octets in the WSSID.
32 u8
wlp_wss_comp_wssid_hash(struct wlp_uuid
*wssid
)
34 return wssid
->data
[0] ^ wssid
->data
[1] ^ wssid
->data
[2]
35 ^ wssid
->data
[3] ^ wssid
->data
[4] ^ wssid
->data
[5]
36 ^ wssid
->data
[6] ^ wssid
->data
[7] ^ wssid
->data
[8]
37 ^ wssid
->data
[9] ^ wssid
->data
[10] ^ wssid
->data
[11]
38 ^ wssid
->data
[12] ^ wssid
->data
[13] ^ wssid
->data
[14]
43 struct uwb_mac_addr
wlp_wss_sel_bcast_addr(struct wlp_wss
*wss
)
45 struct uwb_mac_addr bcast
= {
46 .data
= { 0x01, 0x13, 0x88, 0x00, 0x01, 0x00 }
52 * Clear the contents of the WSS structure - all except kobj, mutex, virtual
54 * We do not want to reinitialize - the internal kobj should not change as
55 * it still points to the parent received during setup. The mutex should
56 * remain also. We thus just reset values individually.
57 * The virutal address assigned to WSS will remain the same for the
58 * lifetime of the WSS. We only reset the fields that can change during its
61 void wlp_wss_reset(struct wlp_wss
*wss
)
63 memset(&wss
->wssid
, 0, sizeof(wss
->wssid
));
65 memset(&wss
->name
[0], 0, sizeof(wss
->name
));
66 memset(&wss
->bcast
, 0, sizeof(wss
->bcast
));
67 wss
->secure_status
= WLP_WSS_UNSECURE
;
68 memset(&wss
->master_key
[0], 0, sizeof(wss
->master_key
));
70 wss
->state
= WLP_WSS_STATE_NONE
;
74 * Create sysfs infrastructure for WSS
76 * The WSS is configured to have the interface as parent (see wlp_wss_setup())
77 * a new sysfs directory that includes wssid as its name is created in the
78 * interface's sysfs directory. The group of files interacting with WSS are
82 int wlp_wss_sysfs_add(struct wlp_wss
*wss
, char *wssid_str
)
84 struct wlp
*wlp
= container_of(wss
, struct wlp
, wss
);
85 struct device
*dev
= &wlp
->rc
->uwb_dev
.dev
;
88 result
= kobject_set_name(&wss
->kobj
, "wss-%s", wssid_str
);
91 wss
->kobj
.ktype
= &wss_ktype
;
92 result
= kobject_init_and_add(&wss
->kobj
,
93 &wss_ktype
, wss
->kobj
.parent
, "wlp");
95 dev_err(dev
, "WLP: Cannot register WSS kobject.\n");
96 goto error_kobject_register
;
98 result
= sysfs_create_group(&wss
->kobj
, &wss_attr_group
);
100 dev_err(dev
, "WLP: Cannot register WSS attributes: %d\n",
102 goto error_sysfs_create_group
;
105 error_sysfs_create_group
:
107 kobject_put(&wss
->kobj
); /* will free name if needed */
109 error_kobject_register
:
110 kfree(wss
->kobj
.name
);
111 wss
->kobj
.name
= NULL
;
112 wss
->kobj
.ktype
= NULL
;
120 * No more references exist to this WSS. We should undo everything that was
121 * done in wlp_wss_create_activate() except removing the group. The group
122 * is not removed because an object can be unregistered before the group is
123 * created. We also undo any additional operations on the WSS after this
124 * (addition of members).
126 * If memory was allocated for the kobject's name then it will
127 * be freed by the kobject system during this time.
129 * The EDA cache is removed and reinitialized when the WSS is removed. We
130 * thus loose knowledge of members of this WSS at that time and need not do
133 void wlp_wss_release(struct kobject
*kobj
)
135 struct wlp_wss
*wss
= container_of(kobj
, struct wlp_wss
, kobj
);
141 * Enroll into a WSS using provided neighbor as registrar
143 * First search the neighborhood information to learn which neighbor is
144 * referred to, next proceed with enrollment.
146 * &wss->mutex is held
149 int wlp_wss_enroll_target(struct wlp_wss
*wss
, struct wlp_uuid
*wssid
,
150 struct uwb_dev_addr
*dest
)
152 struct wlp
*wlp
= container_of(wss
, struct wlp
, wss
);
153 struct device
*dev
= &wlp
->rc
->uwb_dev
.dev
;
154 struct wlp_neighbor_e
*neighbor
;
156 struct uwb_dev_addr
*dev_addr
;
158 mutex_lock(&wlp
->nbmutex
);
159 list_for_each_entry(neighbor
, &wlp
->neighbors
, node
) {
160 dev_addr
= &neighbor
->uwb_dev
->dev_addr
;
161 if (!memcmp(dest
, dev_addr
, sizeof(*dest
))) {
162 result
= wlp_enroll_neighbor(wlp
, neighbor
, wss
, wssid
);
166 if (result
== -ENXIO
)
167 dev_err(dev
, "WLP: Cannot find neighbor %02x:%02x. \n",
168 dest
->data
[1], dest
->data
[0]);
169 mutex_unlock(&wlp
->nbmutex
);
174 * Enroll into a WSS previously discovered
176 * User provides WSSID of WSS, search for neighbor that has this WSS
177 * activated and attempt to enroll.
179 * &wss->mutex is held
182 int wlp_wss_enroll_discovered(struct wlp_wss
*wss
, struct wlp_uuid
*wssid
)
184 struct wlp
*wlp
= container_of(wss
, struct wlp
, wss
);
185 struct device
*dev
= &wlp
->rc
->uwb_dev
.dev
;
186 struct wlp_neighbor_e
*neighbor
;
187 struct wlp_wssid_e
*wssid_e
;
188 char buf
[WLP_WSS_UUID_STRSIZE
];
192 mutex_lock(&wlp
->nbmutex
);
193 list_for_each_entry(neighbor
, &wlp
->neighbors
, node
) {
194 list_for_each_entry(wssid_e
, &neighbor
->wssid
, node
) {
195 if (!memcmp(wssid
, &wssid_e
->wssid
, sizeof(*wssid
))) {
196 result
= wlp_enroll_neighbor(wlp
, neighbor
,
198 if (result
== 0) /* enrollment success */
205 if (result
== -ENXIO
) {
206 wlp_wss_uuid_print(buf
, sizeof(buf
), wssid
);
207 dev_err(dev
, "WLP: Cannot find WSSID %s in cache. \n", buf
);
209 mutex_unlock(&wlp
->nbmutex
);
214 * Enroll into WSS with provided WSSID, registrar may be provided
216 * @wss: out WSS that will be enrolled
217 * @wssid: wssid of neighboring WSS that we want to enroll in
218 * @devaddr: registrar can be specified, will be broadcast (ff:ff) if any
219 * neighbor can be used as registrar.
221 * &wss->mutex is held
224 int wlp_wss_enroll(struct wlp_wss
*wss
, struct wlp_uuid
*wssid
,
225 struct uwb_dev_addr
*devaddr
)
228 struct wlp
*wlp
= container_of(wss
, struct wlp
, wss
);
229 struct device
*dev
= &wlp
->rc
->uwb_dev
.dev
;
230 char buf
[WLP_WSS_UUID_STRSIZE
];
231 struct uwb_dev_addr bcast
= {.data
= {0xff, 0xff} };
233 wlp_wss_uuid_print(buf
, sizeof(buf
), wssid
);
235 if (wss
->state
!= WLP_WSS_STATE_NONE
) {
236 dev_err(dev
, "WLP: Already enrolled in WSS %s.\n", buf
);
240 if (!memcmp(&bcast
, devaddr
, sizeof(bcast
)))
241 result
= wlp_wss_enroll_discovered(wss
, wssid
);
243 result
= wlp_wss_enroll_target(wss
, wssid
, devaddr
);
245 dev_err(dev
, "WLP: Unable to enroll into WSS %s, result %d \n",
249 dev_dbg(dev
, "Successfully enrolled into WSS %s \n", buf
);
250 result
= wlp_wss_sysfs_add(wss
, buf
);
252 dev_err(dev
, "WLP: Unable to set up sysfs for WSS kobject.\n");
263 * Prior to activation a WSS must be enrolled. To activate a WSS a device
264 * includes the WSS hash in the WLP IE in its beacon in each superframe.
267 * The WSS tag is also computed at this time. We only support one activated
268 * WSS so we can use the hash as a tag - there will never be a conflict.
270 * We currently only support one activated WSS so only one WSS hash is
271 * included in the WLP IE.
274 int wlp_wss_activate(struct wlp_wss
*wss
)
276 struct wlp
*wlp
= container_of(wss
, struct wlp
, wss
);
277 struct device
*dev
= &wlp
->rc
->uwb_dev
.dev
;
278 struct uwb_rc
*uwb_rc
= wlp
->rc
;
281 struct wlp_ie wlp_ie
;
282 u8 hash
; /* only include one hash */
285 BUG_ON(wss
->state
!= WLP_WSS_STATE_ENROLLED
);
286 wss
->hash
= wlp_wss_comp_wssid_hash(&wss
->wssid
);
287 wss
->tag
= wss
->hash
;
288 memset(&ie_data
, 0, sizeof(ie_data
));
289 ie_data
.wlp_ie
.hdr
.element_id
= UWB_IE_WLP
;
290 ie_data
.wlp_ie
.hdr
.length
= sizeof(ie_data
) - sizeof(struct uwb_ie_hdr
);
291 wlp_ie_set_hash_length(&ie_data
.wlp_ie
, sizeof(ie_data
.hash
));
292 ie_data
.hash
= wss
->hash
;
293 result
= uwb_rc_ie_add(uwb_rc
, &ie_data
.wlp_ie
.hdr
,
296 dev_err(dev
, "WLP: Unable to add WLP IE to beacon. "
297 "result = %d.\n", result
);
300 wss
->state
= WLP_WSS_STATE_ACTIVE
;
307 * Enroll in and activate WSS identified by provided WSSID
309 * The neighborhood cache should contain a list of all neighbors and the
310 * WSS they have activated. Based on that cache we search which neighbor we
311 * can perform the association process with. The user also has option to
312 * specify which neighbor it prefers as registrar.
313 * Successful enrollment is followed by activation.
314 * Successful activation will create the sysfs directory containing
315 * specific information regarding this WSS.
317 int wlp_wss_enroll_activate(struct wlp_wss
*wss
, struct wlp_uuid
*wssid
,
318 struct uwb_dev_addr
*devaddr
)
320 struct wlp
*wlp
= container_of(wss
, struct wlp
, wss
);
321 struct device
*dev
= &wlp
->rc
->uwb_dev
.dev
;
323 char buf
[WLP_WSS_UUID_STRSIZE
];
325 mutex_lock(&wss
->mutex
);
326 result
= wlp_wss_enroll(wss
, wssid
, devaddr
);
328 wlp_wss_uuid_print(buf
, sizeof(buf
), &wss
->wssid
);
329 dev_err(dev
, "WLP: Enrollment into WSS %s failed.\n", buf
);
332 result
= wlp_wss_activate(wss
);
334 dev_err(dev
, "WLP: Unable to activate WSS. Undoing enrollment "
335 "result = %d \n", result
);
336 /* Undo enrollment */
342 mutex_unlock(&wss
->mutex
);
347 * Create, enroll, and activate a new WSS
349 * @wssid: new wssid provided by user
350 * @name: WSS name requested by used.
351 * @sec_status: security status requested by user
353 * A user requested the creation of a new WSS. All operations are done
354 * locally. The new WSS will be stored locally, the hash will be included
355 * in the WLP IE, and the sysfs infrastructure for this WSS will be
358 int wlp_wss_create_activate(struct wlp_wss
*wss
, struct wlp_uuid
*wssid
,
359 char *name
, unsigned sec_status
, unsigned accept
)
361 struct wlp
*wlp
= container_of(wss
, struct wlp
, wss
);
362 struct device
*dev
= &wlp
->rc
->uwb_dev
.dev
;
364 char buf
[WLP_WSS_UUID_STRSIZE
];
366 result
= wlp_wss_uuid_print(buf
, sizeof(buf
), wssid
);
368 if (!mutex_trylock(&wss
->mutex
)) {
369 dev_err(dev
, "WLP: WLP association session in progress.\n");
372 if (wss
->state
!= WLP_WSS_STATE_NONE
) {
373 dev_err(dev
, "WLP: WSS already exists. Not creating new.\n");
377 if (wss
->kobj
.parent
== NULL
) {
378 dev_err(dev
, "WLP: WSS parent not ready. Is network interface "
383 if (sec_status
== WLP_WSS_SECURE
) {
384 dev_err(dev
, "WLP: FIXME Creation of secure WSS not "
390 memcpy(wss
->name
, name
, sizeof(wss
->name
));
391 wss
->bcast
= wlp_wss_sel_bcast_addr(wss
);
392 wss
->secure_status
= sec_status
;
393 wss
->accept_enroll
= accept
;
394 /*wss->virtual_addr is initialized in call to wlp_wss_setup*/
395 /* sysfs infrastructure */
396 result
= wlp_wss_sysfs_add(wss
, buf
);
398 dev_err(dev
, "Cannot set up sysfs for WSS kobject.\n");
403 wss
->state
= WLP_WSS_STATE_ENROLLED
;
404 result
= wlp_wss_activate(wss
);
406 dev_err(dev
, "WLP: Unable to activate WSS. Undoing "
413 mutex_unlock(&wss
->mutex
);
418 * Determine if neighbor has WSS activated
420 * @returns: 1 if neighbor has WSS activated, zero otherwise
422 * This can be done in two ways:
423 * - send a C1 frame, parse C2/F0 response
424 * - examine the WLP IE sent by the neighbor
426 * The WLP IE is not fully supported in hardware so we use the C1/C2 frame
427 * exchange to determine if a WSS is activated. Using the WLP IE should be
428 * faster and should be used when it becomes possible.
430 int wlp_wss_is_active(struct wlp
*wlp
, struct wlp_wss
*wss
,
431 struct uwb_dev_addr
*dev_addr
)
434 struct device
*dev
= &wlp
->rc
->uwb_dev
.dev
;
435 DECLARE_COMPLETION_ONSTACK(completion
);
436 struct wlp_session session
;
438 struct wlp_frame_assoc
*resp
;
439 struct wlp_uuid wssid
;
441 mutex_lock(&wlp
->mutex
);
442 /* Send C1 association frame */
443 result
= wlp_send_assoc_frame(wlp
, wss
, dev_addr
, WLP_ASSOC_C1
);
445 dev_err(dev
, "Unable to send C1 frame to neighbor "
446 "%02x:%02x (%d)\n", dev_addr
->data
[1],
447 dev_addr
->data
[0], result
);
451 /* Create session, wait for response */
452 session
.exp_message
= WLP_ASSOC_C2
;
453 session
.cb
= wlp_session_cb
;
454 session
.cb_priv
= &completion
;
455 session
.neighbor_addr
= *dev_addr
;
456 BUG_ON(wlp
->session
!= NULL
);
457 wlp
->session
= &session
;
458 /* Wait for C2/F0 frame */
459 result
= wait_for_completion_interruptible_timeout(&completion
,
460 WLP_PER_MSG_TIMEOUT
* HZ
);
462 dev_err(dev
, "Timeout while sending C1 to neighbor "
463 "%02x:%02x.\n", dev_addr
->data
[1],
468 dev_err(dev
, "Unable to send C1 to neighbor %02x:%02x.\n",
469 dev_addr
->data
[1], dev_addr
->data
[0]);
473 /* Parse message in session->data: it will be either C2 or F0 */
475 resp
= (void *) skb
->data
;
476 if (resp
->type
== WLP_ASSOC_F0
) {
477 result
= wlp_parse_f0(wlp
, skb
);
479 dev_err(dev
, "WLP: unable to parse incoming F0 "
480 "frame from neighbor %02x:%02x.\n",
481 dev_addr
->data
[1], dev_addr
->data
[0]);
483 goto error_resp_parse
;
485 /* WLP version and message type fields have already been parsed */
486 result
= wlp_get_wssid(wlp
, (void *)resp
+ sizeof(*resp
), &wssid
,
487 skb
->len
- sizeof(*resp
));
489 dev_err(dev
, "WLP: unable to obtain WSSID from C2 frame.\n");
491 goto error_resp_parse
;
493 if (!memcmp(&wssid
, &wss
->wssid
, sizeof(wssid
)))
496 dev_err(dev
, "WLP: Received a C2 frame without matching "
504 mutex_unlock(&wlp
->mutex
);
509 * Activate connection with neighbor by updating EDA cache
511 * @wss: local WSS to which neighbor wants to connect
512 * @dev_addr: neighbor's address
513 * @wssid: neighbor's WSSID - must be same as our WSS's WSSID
514 * @tag: neighbor's WSS tag used to identify frames transmitted by it
515 * @virt_addr: neighbor's virtual EUI-48
518 int wlp_wss_activate_connection(struct wlp
*wlp
, struct wlp_wss
*wss
,
519 struct uwb_dev_addr
*dev_addr
,
520 struct wlp_uuid
*wssid
, u8
*tag
,
521 struct uwb_mac_addr
*virt_addr
)
523 struct device
*dev
= &wlp
->rc
->uwb_dev
.dev
;
526 if (!memcmp(wssid
, &wss
->wssid
, sizeof(*wssid
))) {
527 /* Update EDA cache */
528 result
= wlp_eda_update_node(&wlp
->eda
, dev_addr
, wss
,
529 (void *) virt_addr
->data
, *tag
,
532 dev_err(dev
, "WLP: Unable to update EDA cache "
533 "with new connected neighbor information.\n");
535 dev_err(dev
, "WLP: Neighbor does not have matching WSSID.\n");
542 * Connect to WSS neighbor
544 * Use C3/C4 exchange to determine if neighbor has WSS activated and
545 * retrieve the WSS tag and virtual EUI-48 of the neighbor.
548 int wlp_wss_connect_neighbor(struct wlp
*wlp
, struct wlp_wss
*wss
,
549 struct uwb_dev_addr
*dev_addr
)
552 struct device
*dev
= &wlp
->rc
->uwb_dev
.dev
;
553 struct wlp_uuid wssid
;
555 struct uwb_mac_addr virt_addr
;
556 DECLARE_COMPLETION_ONSTACK(completion
);
557 struct wlp_session session
;
558 struct wlp_frame_assoc
*resp
;
561 mutex_lock(&wlp
->mutex
);
562 /* Send C3 association frame */
563 result
= wlp_send_assoc_frame(wlp
, wss
, dev_addr
, WLP_ASSOC_C3
);
565 dev_err(dev
, "Unable to send C3 frame to neighbor "
566 "%02x:%02x (%d)\n", dev_addr
->data
[1],
567 dev_addr
->data
[0], result
);
570 /* Create session, wait for response */
571 session
.exp_message
= WLP_ASSOC_C4
;
572 session
.cb
= wlp_session_cb
;
573 session
.cb_priv
= &completion
;
574 session
.neighbor_addr
= *dev_addr
;
575 BUG_ON(wlp
->session
!= NULL
);
576 wlp
->session
= &session
;
577 /* Wait for C4/F0 frame */
578 result
= wait_for_completion_interruptible_timeout(&completion
,
579 WLP_PER_MSG_TIMEOUT
* HZ
);
581 dev_err(dev
, "Timeout while sending C3 to neighbor "
582 "%02x:%02x.\n", dev_addr
->data
[1],
588 dev_err(dev
, "Unable to send C3 to neighbor %02x:%02x.\n",
589 dev_addr
->data
[1], dev_addr
->data
[0]);
592 /* Parse message in session->data: it will be either C4 or F0 */
594 resp
= (void *) skb
->data
;
595 if (resp
->type
== WLP_ASSOC_F0
) {
596 result
= wlp_parse_f0(wlp
, skb
);
598 dev_err(dev
, "WLP: unable to parse incoming F0 "
599 "frame from neighbor %02x:%02x.\n",
600 dev_addr
->data
[1], dev_addr
->data
[0]);
602 goto error_resp_parse
;
604 result
= wlp_parse_c3c4_frame(wlp
, skb
, &wssid
, &tag
, &virt_addr
);
606 dev_err(dev
, "WLP: Unable to parse C4 frame from neighbor.\n");
607 goto error_resp_parse
;
609 result
= wlp_wss_activate_connection(wlp
, wss
, dev_addr
, &wssid
, &tag
,
612 dev_err(dev
, "WLP: Unable to activate connection to "
613 "neighbor %02x:%02x.\n", dev_addr
->data
[1],
615 goto error_resp_parse
;
620 /* Record that we unsuccessfully tried to connect to this neighbor */
622 wlp_eda_update_node_state(&wlp
->eda
, dev_addr
,
623 WLP_WSS_CONNECT_FAILED
);
625 mutex_unlock(&wlp
->mutex
);
630 * Connect to neighbor with common WSS, send pending frame
632 * This function is scheduled when a frame is destined to a neighbor with
633 * which we do not have a connection. A copy of the EDA cache entry is
634 * provided - not the actual cache entry (because it is protected by a
637 * First determine if neighbor has the same WSS activated, connect if it
638 * does. The C3/C4 exchange is dual purpose to determine if neighbor has
639 * WSS activated and proceed with the connection.
641 * The frame that triggered the connection setup is sent after connection
644 * network queue is stopped - we need to restart when done
648 void wlp_wss_connect_send(struct work_struct
*ws
)
650 struct wlp_assoc_conn_ctx
*conn_ctx
= container_of(ws
,
651 struct wlp_assoc_conn_ctx
,
653 struct wlp
*wlp
= conn_ctx
->wlp
;
654 struct sk_buff
*skb
= conn_ctx
->skb
;
655 struct wlp_eda_node
*eda_entry
= &conn_ctx
->eda_entry
;
656 struct uwb_dev_addr
*dev_addr
= &eda_entry
->dev_addr
;
657 struct wlp_wss
*wss
= &wlp
->wss
;
659 struct device
*dev
= &wlp
->rc
->uwb_dev
.dev
;
661 mutex_lock(&wss
->mutex
);
662 if (wss
->state
< WLP_WSS_STATE_ACTIVE
) {
663 if (printk_ratelimit())
664 dev_err(dev
, "WLP: Attempting to connect with "
665 "WSS that is not active or connected.\n");
669 /* Establish connection - send C3 rcv C4 */
670 result
= wlp_wss_connect_neighbor(wlp
, wss
, dev_addr
);
672 if (printk_ratelimit())
673 dev_err(dev
, "WLP: Unable to establish connection "
674 "with neighbor %02x:%02x.\n",
675 dev_addr
->data
[1], dev_addr
->data
[0]);
679 /* EDA entry changed, update the local copy being used */
680 result
= wlp_copy_eda_node(&wlp
->eda
, dev_addr
, eda_entry
);
682 if (printk_ratelimit())
683 dev_err(dev
, "WLP: Cannot find EDA entry for "
684 "neighbor %02x:%02x \n",
685 dev_addr
->data
[1], dev_addr
->data
[0]);
687 result
= wlp_wss_prep_hdr(wlp
, eda_entry
, skb
);
689 if (printk_ratelimit())
690 dev_err(dev
, "WLP: Unable to prepare frame header for "
691 "transmission (neighbor %02x:%02x). \n",
692 dev_addr
->data
[1], dev_addr
->data
[0]);
696 BUG_ON(wlp
->xmit_frame
== NULL
);
697 result
= wlp
->xmit_frame(wlp
, skb
, dev_addr
);
699 if (printk_ratelimit())
700 dev_err(dev
, "WLP: Unable to transmit frame: %d\n",
702 if (result
== -ENXIO
)
703 dev_err(dev
, "WLP: Is network interface up? \n");
704 /* We could try again ... */
705 dev_kfree_skb(skb
);/*we need to free if tx fails */
709 BUG_ON(wlp
->start_queue
== NULL
);
710 wlp
->start_queue(wlp
);
711 mutex_unlock(&wss
->mutex
);
715 * Add WLP header to outgoing skb
717 * @eda_entry: pointer to neighbor's entry in the EDA cache
718 * @_skb: skb containing data destined to the neighbor
720 int wlp_wss_prep_hdr(struct wlp
*wlp
, struct wlp_eda_node
*eda_entry
,
723 struct device
*dev
= &wlp
->rc
->uwb_dev
.dev
;
725 unsigned char *eth_addr
= eda_entry
->eth_addr
;
726 struct uwb_dev_addr
*dev_addr
= &eda_entry
->dev_addr
;
727 struct sk_buff
*skb
= _skb
;
728 struct wlp_frame_std_abbrv_hdr
*std_hdr
;
730 if (eda_entry
->state
== WLP_WSS_CONNECTED
) {
732 BUG_ON(skb_headroom(skb
) < sizeof(*std_hdr
));
733 std_hdr
= (void *) __skb_push(skb
, sizeof(*std_hdr
));
734 std_hdr
->hdr
.mux_hdr
= cpu_to_le16(WLP_PROTOCOL_ID
);
735 std_hdr
->hdr
.type
= WLP_FRAME_STANDARD
;
736 std_hdr
->tag
= eda_entry
->wss
->tag
;
738 if (printk_ratelimit())
739 dev_err(dev
, "WLP: Destination neighbor (Ethernet: "
740 "%02x:%02x:%02x:%02x:%02x:%02x, Dev: "
741 "%02x:%02x) is not connected. \n", eth_addr
[0],
742 eth_addr
[1], eth_addr
[2], eth_addr
[3],
743 eth_addr
[4], eth_addr
[5], dev_addr
->data
[1],
752 * Prepare skb for neighbor: connect if not already and prep WLP header
754 * This function is called in interrupt context, but it needs to sleep. We
755 * temporarily stop the net queue to establish the WLP connection.
756 * Setup of the WLP connection and restart of queue is scheduled
757 * on the default work queue.
759 * run with eda->lock held (spinlock)
761 int wlp_wss_connect_prep(struct wlp
*wlp
, struct wlp_eda_node
*eda_entry
,
765 struct device
*dev
= &wlp
->rc
->uwb_dev
.dev
;
766 struct sk_buff
*skb
= _skb
;
767 struct wlp_assoc_conn_ctx
*conn_ctx
;
769 if (eda_entry
->state
== WLP_WSS_UNCONNECTED
) {
770 /* We don't want any more packets while we set up connection */
771 BUG_ON(wlp
->stop_queue
== NULL
);
772 wlp
->stop_queue(wlp
);
773 conn_ctx
= kmalloc(sizeof(*conn_ctx
), GFP_ATOMIC
);
774 if (conn_ctx
== NULL
) {
775 if (printk_ratelimit())
776 dev_err(dev
, "WLP: Unable to allocate memory "
777 "for connection handling.\n");
783 conn_ctx
->eda_entry
= *eda_entry
;
784 INIT_WORK(&conn_ctx
->ws
, wlp_wss_connect_send
);
785 schedule_work(&conn_ctx
->ws
);
787 } else if (eda_entry
->state
== WLP_WSS_CONNECT_FAILED
) {
788 /* Previous connection attempts failed, don't retry - see
789 * conditions for connection in WLP 0.99 [7.6.2] */
790 if (printk_ratelimit())
791 dev_err(dev
, "Could not connect to neighbor "
792 "previously. Not retrying. \n");
795 } else /* eda_entry->state == WLP_WSS_CONNECTED */
796 result
= wlp_wss_prep_hdr(wlp
, eda_entry
, skb
);
802 * Emulate broadcast: copy skb, send copy to neighbor (connect if not already)
804 * We need to copy skbs in the case where we emulate broadcast through
805 * unicast. We copy instead of clone because we are modifying the data of
806 * the frame after copying ... clones share data so we cannot emulate
807 * broadcast using clones.
809 * run with eda->lock held (spinlock)
811 int wlp_wss_send_copy(struct wlp
*wlp
, struct wlp_eda_node
*eda_entry
,
814 int result
= -ENOMEM
;
815 struct device
*dev
= &wlp
->rc
->uwb_dev
.dev
;
816 struct sk_buff
*skb
= _skb
;
817 struct sk_buff
*copy
;
818 struct uwb_dev_addr
*dev_addr
= &eda_entry
->dev_addr
;
820 copy
= skb_copy(skb
, GFP_ATOMIC
);
822 if (printk_ratelimit())
823 dev_err(dev
, "WLP: Unable to copy skb for "
827 result
= wlp_wss_connect_prep(wlp
, eda_entry
, copy
);
829 if (printk_ratelimit())
830 dev_err(dev
, "WLP: Unable to connect/send skb "
832 dev_kfree_skb_irq(copy
);
834 } else if (result
== 1)
835 /* Frame will be transmitted separately */
837 BUG_ON(wlp
->xmit_frame
== NULL
);
838 result
= wlp
->xmit_frame(wlp
, copy
, dev_addr
);
840 if (printk_ratelimit())
841 dev_err(dev
, "WLP: Unable to transmit frame: %d\n",
843 if ((result
== -ENXIO
) && printk_ratelimit())
844 dev_err(dev
, "WLP: Is network interface up? \n");
845 /* We could try again ... */
846 dev_kfree_skb_irq(copy
);/*we need to free if tx fails */
856 * Should be called by network driver after the interface has been given a
859 int wlp_wss_setup(struct net_device
*net_dev
, struct wlp_wss
*wss
)
861 struct wlp
*wlp
= container_of(wss
, struct wlp
, wss
);
862 struct device
*dev
= &wlp
->rc
->uwb_dev
.dev
;
865 mutex_lock(&wss
->mutex
);
866 wss
->kobj
.parent
= &net_dev
->dev
.kobj
;
867 if (!is_valid_ether_addr(net_dev
->dev_addr
)) {
868 dev_err(dev
, "WLP: Invalid MAC address. Cannot use for"
873 memcpy(wss
->virtual_addr
.data
, net_dev
->dev_addr
,
874 sizeof(wss
->virtual_addr
.data
));
876 mutex_unlock(&wss
->mutex
);
879 EXPORT_SYMBOL_GPL(wlp_wss_setup
);
884 * Called by client that configured WSS through wlp_wss_setup(). This
885 * function is called when client no longer needs WSS, eg. client shuts
888 * We remove the WLP IE from the beacon before initiating local cleanup.
890 void wlp_wss_remove(struct wlp_wss
*wss
)
892 struct wlp
*wlp
= container_of(wss
, struct wlp
, wss
);
894 mutex_lock(&wss
->mutex
);
895 if (wss
->state
== WLP_WSS_STATE_ACTIVE
)
896 uwb_rc_ie_rm(wlp
->rc
, UWB_IE_WLP
);
897 if (wss
->state
!= WLP_WSS_STATE_NONE
) {
898 sysfs_remove_group(&wss
->kobj
, &wss_attr_group
);
899 kobject_put(&wss
->kobj
);
901 wss
->kobj
.parent
= NULL
;
902 memset(&wss
->virtual_addr
, 0, sizeof(wss
->virtual_addr
));
903 /* Cleanup EDA cache */
904 wlp_eda_release(&wlp
->eda
);
905 wlp_eda_init(&wlp
->eda
);
906 mutex_unlock(&wss
->mutex
);
908 EXPORT_SYMBOL_GPL(wlp_wss_remove
);