Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756071Ab2FEL51 (ORCPT ); Tue, 5 Jun 2012 07:57:27 -0400 Received: from mail-lpp01m010-f46.google.com ([209.85.215.46]:40229 "EHLO mail-lpp01m010-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754338Ab2FEL5Z convert rfc822-to-8bit (ORCPT ); Tue, 5 Jun 2012 07:57:25 -0400 MIME-Version: 1.0 In-Reply-To: <1338210316-12299-1-git-send-email-Andrei.Emeltchenko.news@gmail.com> References: <1338210316-12299-1-git-send-email-Andrei.Emeltchenko.news@gmail.com> Date: Tue, 5 Jun 2012 14:57:23 +0300 Message-ID: Subject: Re: [PATCHv3] vsprintf: Add %pMR for Bluetooth MAC address From: Andrei Emeltchenko To: linux-bluetooth@vger.kernel.org, akpm@linux-foundation.org, linux-kernel@vger.kernel.org, adobriyan@gmail.com, andriy.shevchenko@linux.intel.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3458 Lines: 86 ping On Mon, May 28, 2012 at 4:05 PM, Andrei Emeltchenko wrote: > From: Andrei Emeltchenko > > Bluetooth uses mostly LE byte order which is reversed for visual > interpretation. Currently in Bluetooth in use unsafe batostr function. > > This is slightly modified version of Joe Perches > patch (sent Sat, Dec 4, 2010). > > Signed-off-by: Andrei Emeltchenko > --- > ? ? ? ?v3: removed extra variable index > ? ? ? ?v2: changed bluetooth to reversed, syntax fixes > > ?lib/vsprintf.c | ? 23 +++++++++++++++++++---- > ?1 file changed, 19 insertions(+), 4 deletions(-) > > diff --git a/lib/vsprintf.c b/lib/vsprintf.c > index abbabec..55052fa 100644 > --- a/lib/vsprintf.c > +++ b/lib/vsprintf.c > @@ -559,15 +559,28 @@ char *mac_address_string(char *buf, char *end, u8 *addr, > ? ? ? ?char *p = mac_addr; > ? ? ? ?int i; > ? ? ? ?char separator; > + ? ? ? bool reversed = false; > > - ? ? ? if (fmt[1] == 'F') { ? ? ? ? ? ?/* FDDI canonical format */ > + ? ? ? switch (fmt[1]) { > + ? ? ? case 'F': > ? ? ? ? ? ? ? ?separator = '-'; > - ? ? ? } else { > + ? ? ? ? ? ? ? break; > + > + ? ? ? case 'R': > + ? ? ? ? ? ? ? reversed = true; > + ? ? ? ? ? ? ? /* fall through */ > + > + ? ? ? default: > ? ? ? ? ? ? ? ?separator = ':'; > + ? ? ? ? ? ? ? break; > ? ? ? ?} > > ? ? ? ?for (i = 0; i < 6; i++) { > - ? ? ? ? ? ? ? p = hex_byte_pack(p, addr[i]); > + ? ? ? ? ? ? ? if (reversed) > + ? ? ? ? ? ? ? ? ? ? ? p = hex_byte_pack(p, addr[5 - i]); > + ? ? ? ? ? ? ? else > + ? ? ? ? ? ? ? ? ? ? ? p = hex_byte_pack(p, addr[i]); > + > ? ? ? ? ? ? ? ?if (fmt[0] == 'M' && i != 5) > ? ? ? ? ? ? ? ? ? ? ? ?*p++ = separator; > ? ? ? ?} > @@ -830,6 +843,7 @@ int kptr_restrict __read_mostly; > ?* - 'm' For a 6-byte MAC address, it prints the hex address without colons > ?* - 'MF' For a 6-byte MAC FDDI address, it prints the address > ?* ? ? ? with a dash-separated hex notation > + * - '[mM]R For a 6-byte MAC address, Reverse order (Bluetooth) > ?* - 'I' [46] for IPv4/IPv6 addresses printed in the usual way > ?* ? ? ? IPv4 uses dot-separated decimal without leading 0's (1.2.3.4) > ?* ? ? ? IPv6 uses colon separated network-order 16 bit hex with leading 0's > @@ -890,7 +904,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr, > ? ? ? ? ? ? ? ?return resource_string(buf, end, ptr, spec, fmt); > ? ? ? ?case 'M': ? ? ? ? ? ? ? ? ? ? ? /* Colon separated: 00:01:02:03:04:05 */ > ? ? ? ?case 'm': ? ? ? ? ? ? ? ? ? ? ? /* Contiguous: 000102030405 */ > - ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* [mM]F (FDDI, bit reversed) */ > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* [mM]F (FDDI) */ > + ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? /* [mM]R (Reverse order; Bluetooth) */ > ? ? ? ? ? ? ? ?return mac_address_string(buf, end, ptr, spec, fmt); > ? ? ? ?case 'I': ? ? ? ? ? ? ? ? ? ? ? /* Formatted IP supported > ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? * 4: ? 1.2.3.4 > -- > 1.7.9.5 > > -- > To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in > the body of a message to majordomo@vger.kernel.org > More majordomo info at ?http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/