122d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez/*
222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * Ultra Wide Band
322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * Information Element Handling
422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez *
522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * Copyright (C) 2005-2006 Intel Corporation
622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
722d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * Reinette Chatre <reinette.chatre@intel.com>
822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez *
922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * This program is free software; you can redistribute it and/or
1022d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * modify it under the terms of the GNU General Public License version
1122d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * 2 as published by the Free Software Foundation.
1222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez *
1322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * This program is distributed in the hope that it will be useful,
1422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * but WITHOUT ANY WARRANTY; without even the implied warranty of
1522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * GNU General Public License for more details.
1722d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez *
1822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * You should have received a copy of the GNU General Public License
1922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * along with this program; if not, write to the Free Software
2022d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
2122d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * 02110-1301, USA.
2222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez *
2322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez *
2422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * FIXME: docs
2522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez */
2622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
275a0e3ad6af8660be21ca98a971cd00f331318c05Tejun Heo#include <linux/slab.h>
28475c0a6b2cff037ca522d3aff839024ab30ed7ebPaul Gortmaker#include <linux/export.h>
2922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez#include "uwb-internal.h"
3022d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
3122d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez/**
3222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * uwb_ie_next - get the next IE in a buffer
3322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * @ptr: start of the buffer containing the IE data
3422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * @len: length of the buffer
3522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez *
3622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * Both @ptr and @len are updated so subsequent calls to uwb_ie_next()
3722d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * will get the next IE.
3822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez *
3922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * NULL is returned (and @ptr and @len will not be updated) if there
4022d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * are no more IEs in the buffer or the buffer is too short.
4122d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez */
4222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalezstruct uwb_ie_hdr *uwb_ie_next(void **ptr, size_t *len)
4322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez{
4422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	struct uwb_ie_hdr *hdr;
4522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	size_t ie_len;
4622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
4722d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	if (*len < sizeof(struct uwb_ie_hdr))
4822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez		return NULL;
4922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
5022d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	hdr = *ptr;
5122d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	ie_len = sizeof(struct uwb_ie_hdr) + hdr->length;
5222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
5322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	if (*len < ie_len)
5422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez		return NULL;
5522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
5622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	*ptr += ie_len;
5722d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	*len -= ie_len;
5822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
5922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	return hdr;
6022d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez}
6122d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-GonzalezEXPORT_SYMBOL_GPL(uwb_ie_next);
6222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
6322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez/**
641cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * uwb_ie_dump_hex - print IEs to a character buffer
651cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * @ies: the IEs to print.
661cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * @len: length of all the IEs.
671cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * @buf: the destination buffer.
681cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * @size: size of @buf.
691cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel *
701cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * Returns the number of characters written.
711cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel */
721cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabelint uwb_ie_dump_hex(const struct uwb_ie_hdr *ies, size_t len,
731cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		    char *buf, size_t size)
741cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel{
751cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	void *ptr;
761cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	const struct uwb_ie_hdr *ie;
771cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	int r = 0;
781cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	u8 *d;
791cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
801cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	ptr = (void *)ies;
811cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	for (;;) {
821cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		ie = uwb_ie_next(&ptr, &len);
831cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		if (!ie)
841cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel			break;
851cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
861cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		r += scnprintf(buf + r, size - r, "%02x %02x",
871cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel			       (unsigned)ie->element_id,
881cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel			       (unsigned)ie->length);
891cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		d = (uint8_t *)ie + sizeof(struct uwb_ie_hdr);
901cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		while (d != ptr && r < size)
911cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel			r += scnprintf(buf + r, size - r, " %02x", (unsigned)*d++);
921cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		if (r < size)
931cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel			buf[r++] = '\n';
941cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	};
951cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
961cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	return r;
971cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel}
981cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
991cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel/**
10022d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * Get the IEs that a radio controller is sending in its beacon
10122d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez *
10222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * @uwb_rc:  UWB Radio Controller
10322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * @returns: Size read from the system
10422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez *
10522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * We don't need to lock the uwb_rc's mutex because we don't modify
10622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * anything. Once done with the iedata buffer, call
10722d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * uwb_rc_ie_release(iedata). Don't call kfree on it.
10822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez */
1091cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabelstatic
11022d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalezssize_t uwb_rc_get_ie(struct uwb_rc *uwb_rc, struct uwb_rc_evt_get_ie **pget_ie)
11122d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez{
11222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	ssize_t result;
11322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	struct device *dev = &uwb_rc->uwb_dev.dev;
11422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	struct uwb_rccb *cmd = NULL;
11522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	struct uwb_rceb *reply = NULL;
11622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	struct uwb_rc_evt_get_ie *get_ie;
11722d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
11822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
11922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	if (cmd == NULL)
1201cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		return -ENOMEM;
1211cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
12222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	cmd->bCommandType = UWB_RC_CET_GENERAL;
12322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	cmd->wCommand = cpu_to_le16(UWB_RC_CMD_GET_IE);
12422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	result = uwb_rc_vcmd(uwb_rc, "GET_IE", cmd, sizeof(*cmd),
12522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez			     UWB_RC_CET_GENERAL, UWB_RC_CMD_GET_IE,
12622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez			     &reply);
1271cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	kfree(cmd);
12822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	if (result < 0)
1291cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		return result;
1301cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
13122d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	get_ie = container_of(reply, struct uwb_rc_evt_get_ie, rceb);
13222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	if (result < sizeof(*get_ie)) {
13322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez		dev_err(dev, "not enough data returned for decoding GET IE "
13422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez			"(%zu bytes received vs %zu needed)\n",
13522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez			result, sizeof(*get_ie));
1361cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		return -EINVAL;
13722d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	} else if (result < sizeof(*get_ie) + le16_to_cpu(get_ie->wIELength)) {
13822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez		dev_err(dev, "not enough data returned for decoding GET IE "
13922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez			"payload (%zu bytes received vs %zu needed)\n", result,
14022d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez			sizeof(*get_ie) + le16_to_cpu(get_ie->wIELength));
14122d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez		return -EINVAL;
14222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	}
14322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
1441cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	*pget_ie = get_ie;
14522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	return result;
14622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez}
14722d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
14822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
14922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez/**
15022d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * Replace all IEs currently being transmitted by a device
15122d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez *
15222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * @cmd:    pointer to the SET-IE command with the IEs to set
15322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * @size:   size of @buf
15422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez */
15522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalezint uwb_rc_set_ie(struct uwb_rc *rc, struct uwb_rc_cmd_set_ie *cmd)
15622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez{
15722d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	int result;
15822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	struct device *dev = &rc->uwb_dev.dev;
15922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	struct uwb_rc_evt_set_ie reply;
16022d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
16122d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	reply.rceb.bEventType = UWB_RC_CET_GENERAL;
16222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	reply.rceb.wEvent = UWB_RC_CMD_SET_IE;
16322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	result = uwb_rc_cmd(rc, "SET-IE", &cmd->rccb,
16422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez			    sizeof(*cmd) + le16_to_cpu(cmd->wIELength),
16522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez			    &reply.rceb, sizeof(reply));
16622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	if (result < 0)
16722d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez		goto error_cmd;
16822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	else if (result != sizeof(reply)) {
16922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez		dev_err(dev, "SET-IE: not enough data to decode reply "
17022d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez			"(%d bytes received vs %zu needed)\n",
17122d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez			result, sizeof(reply));
17222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez		result = -EIO;
17322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	} else if (reply.bResultCode != UWB_RC_RES_SUCCESS) {
17422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez		dev_err(dev, "SET-IE: command execution failed: %s (%d)\n",
17522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez			uwb_rc_strerror(reply.bResultCode), reply.bResultCode);
17622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez		result = -EIO;
17722d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	} else
17822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez		result = 0;
17922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalezerror_cmd:
18022d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	return result;
18122d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez}
18222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
18322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez/* Cleanup the whole IE management subsystem */
18422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalezvoid uwb_rc_ie_init(struct uwb_rc *uwb_rc)
18522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez{
18622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	mutex_init(&uwb_rc->ies_mutex);
18722d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez}
18822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
18922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
19022d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez/**
1911cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * uwb_rc_ie_setup - setup a radio controller's IE manager
1921cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * @uwb_rc: the radio controller.
19322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez *
1941cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * The current set of IEs are obtained from the hardware with a GET-IE
1951cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * command (since the radio controller is not yet beaconing this will
1961cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * be just the hardware's MAC and PHY Capability IEs).
19722d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez *
1981cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * Returns 0 on success; -ve on an error.
19922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez */
2001cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabelint uwb_rc_ie_setup(struct uwb_rc *uwb_rc)
20122d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez{
2021cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	struct uwb_rc_evt_get_ie *ie_info = NULL;
2031cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	int capacity;
2041cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
2051cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	capacity = uwb_rc_get_ie(uwb_rc, &ie_info);
2061cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	if (capacity < 0)
2071cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		return capacity;
20822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
20922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	mutex_lock(&uwb_rc->ies_mutex);
2101cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
2111cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	uwb_rc->ies = (struct uwb_rc_cmd_set_ie *)ie_info;
21222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	uwb_rc->ies->rccb.bCommandType = UWB_RC_CET_GENERAL;
21322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	uwb_rc->ies->rccb.wCommand = cpu_to_le16(UWB_RC_CMD_SET_IE);
21422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	uwb_rc->ies_capacity = capacity;
2151cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
21622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	mutex_unlock(&uwb_rc->ies_mutex);
2171cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
2181cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	return 0;
21922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez}
22022d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
22122d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
22222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez/* Cleanup the whole IE management subsystem */
22322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalezvoid uwb_rc_ie_release(struct uwb_rc *uwb_rc)
22422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez{
22522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	kfree(uwb_rc->ies);
22622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	uwb_rc->ies = NULL;
22722d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	uwb_rc->ies_capacity = 0;
22822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez}
22922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
23022d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
2311cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabelstatic int uwb_rc_ie_add_one(struct uwb_rc *rc, const struct uwb_ie_hdr *new_ie)
23222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez{
2331cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	struct uwb_rc_cmd_set_ie *new_ies;
2341cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	void *ptr, *prev_ie;
2351cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	struct uwb_ie_hdr *ie;
2361cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	size_t length, new_ie_len, new_capacity, size, prev_size;
2371cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
2381cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	length = le16_to_cpu(rc->ies->wIELength);
2391cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	new_ie_len = sizeof(struct uwb_ie_hdr) + new_ie->length;
2401cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	new_capacity = sizeof(struct uwb_rc_cmd_set_ie) + length + new_ie_len;
2411cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
2421cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	if (new_capacity > rc->ies_capacity) {
2431cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		new_ies = krealloc(rc->ies, new_capacity, GFP_KERNEL);
2441cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		if (!new_ies)
2451cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel			return -ENOMEM;
2461cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		rc->ies = new_ies;
2471cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	}
2481cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
2491cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	ptr = rc->ies->IEData;
2501cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	size = length;
2511cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	for (;;) {
2521cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		prev_ie = ptr;
2531cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		prev_size = size;
2541cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		ie = uwb_ie_next(&ptr, &size);
2551cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		if (!ie || ie->element_id > new_ie->element_id)
2561cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel			break;
2571cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	}
2581cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
2591cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	memmove(prev_ie + new_ie_len, prev_ie, prev_size);
2601cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	memcpy(prev_ie, new_ie, new_ie_len);
2611cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	rc->ies->wIELength = cpu_to_le16(length + new_ie_len);
2621cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
26322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	return 0;
26422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez}
26522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
26622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez/**
2671cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * uwb_rc_ie_add - add new IEs to the radio controller's beacon
2681cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * @uwb_rc: the radio controller.
26922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * @ies: the buffer containing the new IE or IEs to be added to
2701cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel *       the device's beacon.
2711cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * @size: length of all the IEs.
27222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez *
27322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * According to WHCI 0.95 [4.13.6] the driver will only receive the RCEB
27422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * after the device sent the first beacon that includes the IEs specified
27522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * in the SET IE command. We thus cannot send this command if the device is
27622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * not beaconing. Instead, a SET IE command will be sent later right after
27722d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * we start beaconing.
27822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez *
27922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * Setting an IE on the device will overwrite all current IEs in device. So
2801cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * we take the current IEs being transmitted by the device, insert the
28122d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * new one, and call SET IE with all the IEs needed.
28222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez *
2831cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * Returns 0 on success; or -ENOMEM.
28422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez */
28522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalezint uwb_rc_ie_add(struct uwb_rc *uwb_rc,
28622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez		  const struct uwb_ie_hdr *ies, size_t size)
28722d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez{
28822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	int result = 0;
2891cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	void *ptr;
2901cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	const struct uwb_ie_hdr *ie;
2911cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
29222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	mutex_lock(&uwb_rc->ies_mutex);
2931cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
2941cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	ptr = (void *)ies;
2951cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	for (;;) {
2961cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		ie = uwb_ie_next(&ptr, &size);
2971cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		if (!ie)
2981cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel			break;
2991cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
3001cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		result = uwb_rc_ie_add_one(uwb_rc, ie);
3011cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		if (result < 0)
3021cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel			break;
30322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	}
3041cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	if (result >= 0) {
3051cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		if (size == 0) {
3061cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel			if (uwb_rc->beaconing != -1)
3071cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel				result = uwb_rc_set_ie(uwb_rc, uwb_rc->ies);
30822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez		} else
3091cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel			result = -EINVAL;
31022d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	}
3111cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
31222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	mutex_unlock(&uwb_rc->ies_mutex);
3131cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
31422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	return result;
31522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez}
31622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-GonzalezEXPORT_SYMBOL_GPL(uwb_rc_ie_add);
31722d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
31822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
31922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez/*
32022d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * Remove an IE from internal cache
32122d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez *
32222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * We are dealing with our internal IE cache so no need to verify that the
32322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * IEs are valid (it has been done already).
32422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez *
32522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * Should be called with ies_mutex held
32622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez *
32722d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * We do not break out once an IE is found in the cache. It is currently
32822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * possible to have more than one IE with the same ID included in the
32922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez * beacon. We don't reallocate, we just mark the size smaller.
33022d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez */
33122d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalezstatic
3321cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabelvoid uwb_rc_ie_cache_rm(struct uwb_rc *uwb_rc, enum uwb_ie to_remove)
33322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez{
3341cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	struct uwb_ie_hdr *ie;
3351cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	size_t len = le16_to_cpu(uwb_rc->ies->wIELength);
3361cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	void *ptr;
3371cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	size_t size;
3381cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
3391cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	ptr = uwb_rc->ies->IEData;
3401cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	size = len;
3411cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	for (;;) {
3421cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		ie = uwb_ie_next(&ptr, &size);
3431cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		if (!ie)
3441cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel			break;
3451cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel		if (ie->element_id == to_remove) {
3461cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel			len -= sizeof(struct uwb_ie_hdr) + ie->length;
3471cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel			memmove(ie, ptr, size);
3481cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel			ptr = ie;
34922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez		}
35022d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	}
3511cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	uwb_rc->ies->wIELength = cpu_to_le16(len);
35222d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez}
35322d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
35422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
35522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez/**
3561cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * uwb_rc_ie_rm - remove an IE from the radio controller's beacon
3571cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * @uwb_rc: the radio controller.
3581cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * @element_id: the element ID of the IE to remove.
35922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez *
3601cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * Only IEs previously added with uwb_rc_ie_add() may be removed.
3611cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel *
3621cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * Returns 0 on success; or -ve the SET-IE command to the radio
3631cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel * controller failed.
36422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez */
36522d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalezint uwb_rc_ie_rm(struct uwb_rc *uwb_rc, enum uwb_ie element_id)
36622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez{
3671cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	int result = 0;
36822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez
36922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	mutex_lock(&uwb_rc->ies_mutex);
3701cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
3711cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	uwb_rc_ie_cache_rm(uwb_rc, element_id);
3721cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
3731cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel	if (uwb_rc->beaconing != -1)
37422d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez		result = uwb_rc_set_ie(uwb_rc, uwb_rc->ies);
3751cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
37622d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	mutex_unlock(&uwb_rc->ies_mutex);
3771cde7f68ced8d10a20dd2370e9d1d22ab3c1ea5cDavid Vrabel
37822d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez	return result;
37922d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-Gonzalez}
38022d203ecef9b0cc1fa8d8f64c935b451ca7d1022Inaky Perez-GonzalezEXPORT_SYMBOL_GPL(uwb_rc_ie_rm);
381