aboutsummaryrefslogtreecommitdiffstats
path: root/lib/vsprintf.c
diff options
context:
space:
mode:
authorAndrei Emeltchenko <andrei.emeltchenko@intel.com>2012-07-30 17:40:23 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2012-07-30 20:25:14 -0400
commit76597ff989a1fbaa9b9a1e54007cd759bf257ab7 (patch)
tree51c5a7e99de7ff2ba88ba73b110a60c623c5d32c /lib/vsprintf.c
parent61e99ab8e35a88b8c4d0f80d3df9ee16df471be5 (diff)
vsprintf: add %pMR for Bluetooth MAC address
Bluetooth uses mostly LE byte order which is reversed for visual interpretation. Currently in Bluetooth in use unsafe batostr function. This is a slightly modified version of Joe's patch (sent Sat, Dec 4, 2010). Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com> Cc: Joe Perches <joe@perches.com> Cc: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/vsprintf.c')
-rw-r--r--lib/vsprintf.c23
1 files changed, 19 insertions, 4 deletions
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index c3f36d415bdf..736974576e2d 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -662,15 +662,28 @@ char *mac_address_string(char *buf, char *end, u8 *addr,
662 char *p = mac_addr; 662 char *p = mac_addr;
663 int i; 663 int i;
664 char separator; 664 char separator;
665 bool reversed = false;
665 666
666 if (fmt[1] == 'F') { /* FDDI canonical format */ 667 switch (fmt[1]) {
668 case 'F':
667 separator = '-'; 669 separator = '-';
668 } else { 670 break;
671
672 case 'R':
673 reversed = true;
674 /* fall through */
675
676 default:
669 separator = ':'; 677 separator = ':';
678 break;
670 } 679 }
671 680
672 for (i = 0; i < 6; i++) { 681 for (i = 0; i < 6; i++) {
673 p = hex_byte_pack(p, addr[i]); 682 if (reversed)
683 p = hex_byte_pack(p, addr[5 - i]);
684 else
685 p = hex_byte_pack(p, addr[i]);
686
674 if (fmt[0] == 'M' && i != 5) 687 if (fmt[0] == 'M' && i != 5)
675 *p++ = separator; 688 *p++ = separator;
676 } 689 }
@@ -933,6 +946,7 @@ int kptr_restrict __read_mostly;
933 * - 'm' For a 6-byte MAC address, it prints the hex address without colons 946 * - 'm' For a 6-byte MAC address, it prints the hex address without colons
934 * - 'MF' For a 6-byte MAC FDDI address, it prints the address 947 * - 'MF' For a 6-byte MAC FDDI address, it prints the address
935 * with a dash-separated hex notation 948 * with a dash-separated hex notation
949 * - '[mM]R For a 6-byte MAC address, Reverse order (Bluetooth)
936 * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way 950 * - 'I' [46] for IPv4/IPv6 addresses printed in the usual way
937 * IPv4 uses dot-separated decimal without leading 0's (1.2.3.4) 951 * IPv4 uses dot-separated decimal without leading 0's (1.2.3.4)
938 * IPv6 uses colon separated network-order 16 bit hex with leading 0's 952 * IPv6 uses colon separated network-order 16 bit hex with leading 0's
@@ -995,7 +1009,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
995 return resource_string(buf, end, ptr, spec, fmt); 1009 return resource_string(buf, end, ptr, spec, fmt);
996 case 'M': /* Colon separated: 00:01:02:03:04:05 */ 1010 case 'M': /* Colon separated: 00:01:02:03:04:05 */
997 case 'm': /* Contiguous: 000102030405 */ 1011 case 'm': /* Contiguous: 000102030405 */
998 /* [mM]F (FDDI, bit reversed) */ 1012 /* [mM]F (FDDI) */
1013 /* [mM]R (Reverse order; Bluetooth) */
999 return mac_address_string(buf, end, ptr, spec, fmt); 1014 return mac_address_string(buf, end, ptr, spec, fmt);
1000 case 'I': /* Formatted IP supported 1015 case 'I': /* Formatted IP supported
1001 * 4: 1.2.3.4 1016 * 4: 1.2.3.4