Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp510127imw; Wed, 13 Jul 2022 02:50:50 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vm8i4KPjXg9B2oynYJ+yeB05c+LQjZHlJSx7s87zWq96V59M1Nuhh7NYPwUQPERPjS/CyO X-Received: by 2002:a17:902:7c12:b0:16a:11b9:ae9f with SMTP id x18-20020a1709027c1200b0016a11b9ae9fmr2364034pll.82.1657705727306; Wed, 13 Jul 2022 02:48:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657705727; cv=none; d=google.com; s=arc-20160816; b=jlCNPs+G34CSW0fDAcXvMEwbkMzMyS+rLSJhJeIOQ03siKD2d16f/aYhFuI4DhT1ao Z/8y5swCGr1lR4hHqB/oUrr4pQneZpkzWCkR0A7kyeviqvxM0ImvHRez1bnrD153nnhl 3Rlk6lbuTx3hB1bQSEwm83Re+aEV06vPaoti2o5/hIDyTMZ+LHOLgWck4WyYzpRUEOlA p3+Hi5H1cc39XQKvF09APJodKt0EiF0IuZyo2Qhlf0EAtXuMrcVi0MDZ35PwmhHSiq12 EL1l1dzYBIf4dtkRy4rcJwC52JVw35SCKsaY56EgGIXkDjwuD+wH0GHc+YmxoO8KmhIH Q4pA== 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=ncV9gzq2EgtStUiFGkdmLUV8CiMOh3rqv0GcKjryYIo=; b=G1p9WvTxK7rEcg3sfpYGzs8CRyH+ac3yf2tIumwb5YGYtVDNz+l5i7yphyo9wj8Wlm ZASNbzulTH8pGZWUIHfMEcHR5kxh3beqC1soimsmLVC8hlYiJWLFDuRFGdWT3aHjn4fY sTKxnOoUL1693LrUShwaREc34YtlZGKUVMpn90t9l6BdO4yon1kN/E/6yMNz5t9pNwCu 7dZJCL+ojk8L7rlDt+wHIR30qG9oDG32BgL6ADpjpBKV3nZAj2e0QqOSB/p/rjd7P/o4 QrRisILP+w9vR41w1vdEFlnl5lsJWPyBG8Yz8OiymSTV56kjSPa/3g7PnudDV457FjXp xZpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sipsolutions.net header.s=mail header.b="Yu/vXS8e"; 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=REJECT dis=NONE) header.from=sipsolutions.net Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n11-20020a63e04b000000b00411bf370da7si17014535pgj.228.2022.07.13.02.48.39; Wed, 13 Jul 2022 02:48:47 -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=@sipsolutions.net header.s=mail header.b="Yu/vXS8e"; 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=REJECT dis=NONE) header.from=sipsolutions.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234912AbiGMJqs (ORCPT + 65 others); Wed, 13 Jul 2022 05:46:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36576 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236227AbiGMJpi (ORCPT ); Wed, 13 Jul 2022 05:45:38 -0400 Received: from sipsolutions.net (s3.sipsolutions.net [IPv6:2a01:4f8:191:4433::2]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB97BF78A6 for ; Wed, 13 Jul 2022 02:45:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sipsolutions.net; s=mail; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Content-Type:Sender :Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-To: Resent-Cc:Resent-Message-ID; bh=ncV9gzq2EgtStUiFGkdmLUV8CiMOh3rqv0GcKjryYIo=; t=1657705529; x=1658915129; b=Yu/vXS8eFpVb73K5mwJ0bAbtY3lXhUHi5lqYkqICdRuD/Rv DJJnTss1NaGjfCIw8FmyFh3GwNatGi1+DP46pkRY6jzCbYejKNOo7sZ9IAv3DJ/aYduXhfvQbr58y ATFT9HSGXLCvhMMYzT8oR+grhU1j4zZ32GamRVs2nNh7wkGTsxFXBS7qrZYCaBZr5JrH59VpADORZ 9Bm8ffNQl5+njlATrl5kz2UJpmeh2vD+kaHGlffllMTwCB9cRtJIRTHyhq07Jg8sYlNGyEy5iyboO na+RdmH/3xFXCg3PudjdsvUVFSnhhkaoCvCKndRSOzDgx6GM17w5S94VdjeN1BPQ==; Received: by sipsolutions.net with esmtpsa (TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim 4.95) (envelope-from ) id 1oBYvu-00EgvB-Vq; Wed, 13 Jul 2022 11:45:27 +0200 From: Johannes Berg To: linux-wireless@vger.kernel.org Cc: Johannes Berg Subject: [PATCH 64/76] wifi: mac80211: add a helper to fragment an element Date: Wed, 13 Jul 2022 11:44:50 +0200 Message-Id: <20220713114426.30970ab0d08a.Ia4ea941696b9861b58d961dcdca5807a248df75d@changeid> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220713094502.163926-1-johannes@sipsolutions.net> References: <20220713094502.163926-1-johannes@sipsolutions.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE 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: Johannes Berg The way this works is that you add all the element data, keeping a pointer to the length field of the element. Then call this helper function, which will fragment the element if there was more than 255 bytes in the element, memmove()ing the data back if needed. Signed-off-by: Johannes Berg --- net/mac80211/ieee80211_i.h | 1 + net/mac80211/util.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h index 74d5fc5889bb..d17d73e8d19f 100644 --- a/net/mac80211/ieee80211_i.h +++ b/net/mac80211/ieee80211_i.h @@ -2193,6 +2193,7 @@ ieee802_11_parse_elems(const u8 *start, size_t len, bool action, return ieee802_11_parse_elems_crc(start, len, action, 0, 0, bss); } +void ieee80211_fragment_element(struct sk_buff *skb, u8 *len_pos); extern const int ieee802_1d_to_ac[8]; diff --git a/net/mac80211/util.c b/net/mac80211/util.c index 86b6ee7e8156..4b11cf57f4fe 100644 --- a/net/mac80211/util.c +++ b/net/mac80211/util.c @@ -4777,3 +4777,31 @@ u8 *ieee80211_ie_build_eht_cap(u8 *pos, return pos; } + +void ieee80211_fragment_element(struct sk_buff *skb, u8 *len_pos) +{ + unsigned int elem_len; + + if (!len_pos) + return; + + elem_len = skb->data + skb->len - len_pos - 1; + + while (elem_len > 255) { + /* this one is 255 */ + *len_pos = 255; + /* remaining data gets smaller */ + elem_len -= 255; + /* make space for the fragment ID/len in SKB */ + skb_put(skb, 2); + /* shift back the remaining data to place fragment ID/len */ + memmove(len_pos + 255 + 3, len_pos + 255 + 1, elem_len); + /* place the fragment ID */ + len_pos += 255 + 1; + *len_pos = WLAN_EID_FRAGMENT; + /* and point to fragment length to update later */ + len_pos++; + } + + *len_pos = elem_len; +} -- 2.36.1