Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2191310rwd; Thu, 15 Jun 2023 23:58:35 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7OC4fEo8EclGUpZm2hg6lZUWgp8HblwkLP2ysbi9r83VLU8w4b9fFD1Ht3vQHNqa7zDdzz X-Received: by 2002:a17:902:ecc3:b0:1b3:f6b8:61cf with SMTP id a3-20020a170902ecc300b001b3f6b861cfmr1143904plh.56.1686898715597; Thu, 15 Jun 2023 23:58:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686898715; cv=none; d=google.com; s=arc-20160816; b=LVGhEc1gKiBwXMi6JQDUYZamjf0u55gJ4iQTdsGRvQ+MZ/kPDj5zNoPcGD07Eqbbve 1mBu+XDfzauiuckeBdhKZvx54uWjiLOLBnUTQQz5QKbgqGPBJVbgiAIEub3F6lAfeMwo AOS+27peSD1mwHNOU4JMb5XrQrXAp0j8nZqbcLAvevNuCPwohPgxK2BX5z2MwHbqlmd3 xyurlCm7BCV+MQlF3jpU/vxtdP8PjqP1Ul/JxPce4XMu+LTW1gCAV+oCPHShaDyGpm1r PpzMYbE1URh0usJ37RJarI4Pnn0owjJFV1f7wvYO8v3bOSWTwesp3fXs4CB1cCrYxKMF wM7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=e6rz1NNMZ0nHJxez1Y7sc3rbfoe78W89OrC3uuhq+MU=; b=nol7yIgrJggJ9FEZi4WpMb0WXClOvqdzUforNegM7oUaXmz40mRBCPIHVLIwnZlby7 Me7Drda//0JFU14lWHHJTNRRlxpe6cEC6a0Ol+AFJFM+kgaB4eFbGqR5P8bbOwmPmLMp 5NidYH7kFmiJo0E7OB3piierO2tFk9timfSupLkNq0Cyi90T09Ybp3ypL3YF4wAMee+M JUzpGCNw801s/UraBtS7Q6T+fVlZHahsMim2UrSwutqtJshtKnPLjCnzFMi2zrPEvd53 Pj/WPX0kOPEtIydUqx7witNNdW9R+HWTOu85gv2/sZZPm7tNIvGxfsDa0hY+dVBPOpne vPKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hkt0CFKz; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a10-20020a170902ecca00b001b06fa86b08si14475318plh.412.2023.06.15.23.58.28; Thu, 15 Jun 2023 23:58:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=hkt0CFKz; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243313AbjFPGzP (ORCPT + 61 others); Fri, 16 Jun 2023 02:55:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242529AbjFPGzB (ORCPT ); Fri, 16 Jun 2023 02:55:01 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DFF6F1FE8 for ; Thu, 15 Jun 2023 23:55:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686898500; x=1718434500; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=kmp5EIRQzTCqKBhpTa9jvpn+OZ84Sr4hexgAlaGRKvk=; b=hkt0CFKzb+9TECVXW4dy7clgdH+vcsETGi6p8eYrcFmHXZ9Y/5tOfDeT L1yQLv040v9KLSf4Y45gnaR7NAtEZ9ouJaRRghrh1QA1dEzISdpoUBoH4 lrfR0ZTUGuikdvWEi0bZzvGbYmnleWBNaTcw3pTJ0v2UJIXEDhJ+CKxS/ moDR6LixOiBlFKxL5VxvCxMKo0Xx0VKmr4uhh9fJdQXD/2MEh9oSt/Uq7 ThOFGcocLHjZV1p+tDXRcjjX0/Vk9lyrOCW+sZ8hFUvle6pSNCk/DMMpU tczNFKsUtAvR6VRHhbnaVtT2JYzJfSwe2/P+5vk/j2Uxg2KD1lTnC2n+W Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="425078910" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="425078910" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2023 23:55:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="802720186" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="802720186" Received: from ereznaim-mobl.ger.corp.intel.com (HELO ggreenma-mobl2.intel.com) ([10.214.237.118]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2023 23:54:59 -0700 From: gregory.greenman@intel.com To: johannes@sipsolutions.net Cc: linux-wireless@vger.kernel.org, Benjamin Berg , Gregory Greenman Subject: [PATCH 16/20] wifi: cfg80211: add element defragmentation helper Date: Fri, 16 Jun 2023 09:54:05 +0300 Message-Id: <20230616094949.29c3ebeed10d.I009c049289dd0162c2e858ed8b68d2875a672ed6@changeid> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230616065409.633290-1-gregory.greenman@intel.com> References: <20230616065409.633290-1-gregory.greenman@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Benjamin Berg This is already needed within mac80211 and support is also needed by cfg80211 to parse ML elements. Signed-off-by: Benjamin Berg Signed-off-by: Gregory Greenman --- include/net/cfg80211.h | 22 ++++++++++++++++ net/wireless/scan.c | 60 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h index 94ca5cb340f6..cf14a93e61eb 100644 --- a/include/net/cfg80211.h +++ b/include/net/cfg80211.h @@ -6664,6 +6664,28 @@ cfg80211_find_vendor_ie(unsigned int oui, int oui_type, return (const void *)cfg80211_find_vendor_elem(oui, oui_type, ies, len); } +/** + * cfg80211_defragment_element - Defrag the given element data into a buffer + * + * @elem: the element to defragment + * @ies: elements where @elem is contained + * @ieslen: length of @ies + * @data: buffer to store element data + * @data_len: length of @data + * @frag_id: the element ID of fragments + * + * Return: length of @data, or -EINVAL on error + * + * Copy out all data from an element that may be fragmented into @data, while + * skipping all headers. + * + * The function uses memmove() internally. It is acceptable to defragment an + * element in-place. + */ +ssize_t cfg80211_defragment_element(const struct element *elem, const u8 *ies, + size_t ieslen, u8 *data, size_t data_len, + u8 frag_id); + /** * cfg80211_send_layer2_update - send layer 2 update frame * diff --git a/net/wireless/scan.c b/net/wireless/scan.c index 75e6e032bb3a..dc71c6ac5bf5 100644 --- a/net/wireless/scan.c +++ b/net/wireless/scan.c @@ -2288,6 +2288,66 @@ static void cfg80211_parse_mbssid_data(struct wiphy *wiphy, kfree(profile); } +ssize_t cfg80211_defragment_element(const struct element *elem, const u8 *ies, + size_t ieslen, u8 *data, size_t data_len, + u8 frag_id) +{ + const struct element *next; + ssize_t copied; + u8 elem_datalen; + + if (!elem) + return -EINVAL; + + /* elem might be invalid after the memmove */ + next = (void *)(elem->data + elem->datalen); + + elem_datalen = elem->datalen; + if (elem->id == WLAN_EID_EXTENSION) { + copied = elem->datalen - 1; + if (copied > data_len) + return -ENOSPC; + + memmove(data, elem->data + 1, copied); + } else { + copied = elem->datalen; + if (copied > data_len) + return -ENOSPC; + + memmove(data, elem->data, copied); + } + + /* Fragmented elements must have 255 bytes */ + if (elem_datalen < 255) + return copied; + + for (elem = next; + elem->data < ies + ieslen && + elem->data + elem->datalen < ies + ieslen; + elem = next) { + /* elem might be invalid after the memmove */ + next = (void *)(elem->data + elem->datalen); + + if (elem->id != frag_id) + break; + + elem_datalen = elem->datalen; + + if (copied + elem_datalen > data_len) + return -ENOSPC; + + memmove(data + copied, elem->data, elem_datalen); + copied += elem_datalen; + + /* Only the last fragment may be short */ + if (elem_datalen != 255) + break; + } + + return copied; +} +EXPORT_SYMBOL(cfg80211_defragment_element); + struct cfg80211_bss * cfg80211_inform_bss_data(struct wiphy *wiphy, struct cfg80211_inform_bss *data, -- 2.38.1