Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp6022570rwb; Tue, 17 Jan 2023 23:30:01 -0800 (PST) X-Google-Smtp-Source: AMrXdXt5YTyuG31fYIsqYJ6aqbch2JpSOzEA+7CHy2t1qTS6+WRgMn3mcFuBjY03FdUw9/zcNVXV X-Received: by 2002:a17:90b:808:b0:228:dec4:afaf with SMTP id bk8-20020a17090b080800b00228dec4afafmr6522731pjb.34.1674027001407; Tue, 17 Jan 2023 23:30:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674027001; cv=none; d=google.com; s=arc-20160816; b=UQFMF1Bxz3w/Wjn9dtX8BcaPL3H54/NEqtSh2jPZ5udEYbWYWIyzdJL+sHaBCxzNMX NlWv5XtJlHCVXuB0lvQ7RZYwZEIR8T2H60KTKTEApKpUpfAcefGzAQeOayoOk/GW/EIJ LAiajskwT+It3bBggVZgcsO3I5D/HfTLCwYX4X0DCiq6kkKSuuf1usDPv4DTIum4o4j1 BB/8T9sqv9O8OahCnHPljYKMdjOjWa6lZbsTgiGoijpo/3TpPu7OXIJ2Sf0cPROtF8D7 xQOFvFy0HaO+QSbkiHa9J9N1UV4dW8SN57jCwXSb4jtW4qLchuUQ1Gt4LUfyAlmrIyoX vqGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:subject :from:references:cc:to:content-language:user-agent:mime-version:date :message-id:dkim-signature; bh=kRFp5AWJPMrNjS6WWcHZS4kh0nZgqucYWR/EWiO9Wh0=; b=GbX4ugXmww7KmOkQJPA3AKpzJeAIqGm61QkC+8lqRjFI9hfJo8z6OAG9EKvXRPUwRT 7ft+HvEqsLrq4R9gpRmFLuapaltIkOAE8idxNm57rKNMOBVMzQvEh9Ga05kXuLf40gRX oM2S/CgnLvZKrWLsjWYLfLwQlNFer5n4zezHaDiNzxesit74eHsXDJ0DI9dB9HD5TBT5 gckRbpAlWmVLMJPcufBxaBujryUven16UX/5SaaVtcNOfKDVNXSS0E7cDmVYi+3iLWep pvidLi8y/vs6GGdXkjAHI2D3WhD0nRsZXxTv7KjKkeOFTv/IX5KthRMi6OQG2FiWzDQo QRJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@schmorgal.com header.s=google header.b=dL+3n0TZ; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=schmorgal.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y23-20020a17090aca9700b00208606154f7si1353247pjt.117.2023.01.17.23.29.53; Tue, 17 Jan 2023 23:30:01 -0800 (PST) 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=@schmorgal.com header.s=google header.b=dL+3n0TZ; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=schmorgal.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230019AbjARHJw (ORCPT + 63 others); Wed, 18 Jan 2023 02:09:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229830AbjARHJK (ORCPT ); Wed, 18 Jan 2023 02:09:10 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 355416D34E for ; Tue, 17 Jan 2023 22:36:00 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id z1-20020a17090a66c100b00226f05b9595so1237707pjl.0 for ; Tue, 17 Jan 2023 22:36:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=schmorgal.com; s=google; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=kRFp5AWJPMrNjS6WWcHZS4kh0nZgqucYWR/EWiO9Wh0=; b=dL+3n0TZ/oAOepMJegas1wcTtlGhlfRuWvHdye+0OS8jENy8+eKbElpr8eBYm+pcuO VzT+xNQnmpxCdRS8oWTyOBL5qzjGxNiDApKwXSaTw7XYMtLEzhPOew+7YyHYJpQMs029 vqWJMSdeSG8V8xUKbIemfm8US4H8IlW87L5Oo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=kRFp5AWJPMrNjS6WWcHZS4kh0nZgqucYWR/EWiO9Wh0=; b=qFlpqo5fsiGOgGiBL0cd/PBDIKF/5x5Qy9FnYgj+PMQHMT+H2/idXoGsan9oQ/WuwZ 5WTrEWpFffBXlpsDeqdpHNs/r5DPgLzj3flBsBVMhyiJE+8YiDOuMlnw+cnRZWWq4oGw Vcn1KCD6NT+TyTA2dCY58CU8sx3TkV5cTrLCiqat7sYz2NPeJsC6f7FFgnJatgOCJpMj Miv8QJ8u0jlCUlCZhUt3Mq1h0EETmu5gFzakEKl+KzFRGK/pGAUb+n9vbTJ7JYLJ+Apb P59szVoRZjVlWBVoj3wG5AiFfg8gG2tc6qsWYTHbIzp1Chuu2T0gEvsH/A8oKDLOMzF2 g4wA== X-Gm-Message-State: AFqh2krjAIwOghBtyUh2+sWfey4J1fCTJfkCg8In9P2VwtgUjgGFGyyi N3wjDpDIkQScoMbeKEQ0atN3gWdzeaMXXhdWp8WmFQ== X-Received: by 2002:a17:903:25c4:b0:194:5a6f:75b6 with SMTP id jc4-20020a17090325c400b001945a6f75b6mr6713097plb.59.1674023759059; Tue, 17 Jan 2023 22:35:59 -0800 (PST) Received: from [192.168.1.33] ([192.183.212.197]) by smtp.googlemail.com with ESMTPSA id j14-20020a170903024e00b00189667acf19sm22263420plh.95.2023.01.17.22.35.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Jan 2023 22:35:57 -0800 (PST) Message-ID: <85128345-4924-c1c9-85f0-7aebc4e40f93@schmorgal.com> Date: Tue, 17 Jan 2023 22:35:56 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Content-Language: en-US To: Simon Horman Cc: Kalle Valo , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Dan Williams , libertas-dev@lists.infradead.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org References: <20230116202126.50400-1-doug@schmorgal.com> <20230116202126.50400-3-doug@schmorgal.com> From: Doug Brown Subject: Re: [PATCH v3 2/4] wifi: libertas: only add RSN/WPA IE in lbs_add_wpa_tlv In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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 On 1/17/2023 12:59 AM, Simon Horman wrote: > On Mon, Jan 16, 2023 at 12:21:24PM -0800, Doug Brown wrote: >> [You don't often get email from doug@schmorgal.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ] >> >> The existing code only converts the first IE to a TLV, but it returns a >> value that takes the length of all IEs into account. When there is more >> than one IE (which happens with modern wpa_supplicant versions for >> example), the returned length is too long and extra junk TLVs get sent >> to the firmware, resulting in an association failure. >> >> Fix this by finding the first RSN or WPA IE and only adding that. This >> has the extra benefit of working properly if the RSN/WPA IE isn't the >> first one in the IE buffer. >> >> While we're at it, clean up the code to use the available structs like >> the other lbs_add_* functions instead of directly manipulating the TLV >> buffer. >> >> Signed-off-by: Doug Brown >> --- >> drivers/net/wireless/marvell/libertas/cfg.c | 28 +++++++++++++-------- >> 1 file changed, 18 insertions(+), 10 deletions(-) >> >> diff --git a/drivers/net/wireless/marvell/libertas/cfg.c b/drivers/net/wireless/marvell/libertas/cfg.c >> index 3e065cbb0af9..3f35dc7a1d7d 100644 >> --- a/drivers/net/wireless/marvell/libertas/cfg.c >> +++ b/drivers/net/wireless/marvell/libertas/cfg.c > > ... > >> @@ -428,14 +438,12 @@ static int lbs_add_wpa_tlv(u8 *tlv, const u8 *ie, u8 ie_len) >> * __le16 len >> * u8[] data >> */ >> - *tlv++ = *ie++; >> - *tlv++ = 0; >> - tlv_len = *tlv++ = *ie++; >> - *tlv++ = 0; >> - while (tlv_len--) >> - *tlv++ = *ie++; >> - /* the TLV is two bytes larger than the IE */ >> - return ie_len + 2; >> + wpatlv->header.type = cpu_to_le16(wpaie->id); >> + wpatlv->header.len = cpu_to_le16(wpaie->datalen); >> + memcpy(wpatlv->data, wpaie->data, wpaie->datalen); > > Hi Doug, > > Thanks for fixing the endiness issues with cpu_to_le16() > This part looks good to me now. Likewise for patch 4/4. > > One suggestion I have, which is probably taking things to far, > is a helper for what seems to be repeated code-pattern. > But I don't feel strongly about that. Thanks Simon. Is this basically what you're suggesting for a helper? static int lbs_add_ie_tlv(u8 *tlvbuf, const struct element *ie, u16 tlvtype) { struct mrvl_ie_data *tlv = (struct mrvl_ie_data *)tlvbuf; tlv->header.type = cpu_to_le16(tlvtype); tlv->header.len = cpu_to_le16(ie->datalen); memcpy(tlv->data, ie->data, ie->datalen); return sizeof(struct mrvl_ie_header) + ie->datalen; } And then in the two functions where I'm doing that, at the bottom: return lbs_add_ie_tlv(tlv, wpaie, wpaie->id); return lbs_add_ie_tlv(tlv, wpsie, TLV_TYPE_WPS_ENROLLEE); I could definitely do that to avoid repeating the chunk of code that fills out the struct in the two functions. A lot of the other lbs_add_*_tlv functions follow a similar pattern of setting up a struct pointer and filling out the header, so I don't think it's too crazy to just repeat the code twice. On the other hand, the example above does look pretty darn clean. I don't feel strongly either way myself. > >> + >> + /* Return the total number of bytes added to the TLV buffer */ >> + return sizeof(struct mrvl_ie_header) + wpaie->datalen; >> } >> >> /* >> -- >> 2.34.1 >>